-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjsonToForm.d.ts
More file actions
263 lines (215 loc) · 8.06 KB
/
Copy pathjsonToForm.d.ts
File metadata and controls
263 lines (215 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
* JsonToForm v2.0.0 TypeScript Definitions
*
* Provides type safety and IntelliSense support for JsonToForm plugin
*/
declare namespace JsonToForm {
// ===== INTERFACES =====
interface JsonSchema {
type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'spacer' | 'email' | 'tel' | 'url' | 'date' | 'color';
title?: string;
description?: string;
// String/Number constraints
minLength?: number;
maxLength?: number;
minimum?: number;
maximum?: number;
pattern?: string;
// Array constraints
items?: JsonSchema;
// Object constraints
properties?: { [key: string]: JsonSchema };
required?: string[];
// Enum values
enum?: any[];
// Reference to definitions
$ref?: string;
// UI configuration
ui?: UIConfiguration;
// Schema definitions
definitions?: { [key: string]: JsonSchema };
}
interface UIConfiguration {
editor?: 'text' | 'textarea' | 'number' | 'email' | 'tel' | 'url' | 'date' | 'color' | 'checkbox' | 'radio' | 'select' | 'html';
class?: string;
disabled?: boolean;
placeholder?: string;
placeholderHint?: string;
hoverHint?: string;
inlineHint?: string;
validationHint?: string;
validationRule?: string;
rows?: number; // For textarea
[key: string]: any; // Allow additional custom properties
}
interface ValidationRule {
pattern?: RegExp;
validate?: (value: any, element?: JQuery) => boolean;
message: string;
}
interface ValidationResult {
isValid: boolean;
errors: string[];
element: JQuery;
}
interface ValidationConfiguration {
realTime?: boolean;
showHints?: boolean;
customRules?: { [ruleName: string]: ValidationRule };
}
interface CallbackConfiguration {
afterValueChanged?: (value: any, schema: JsonSchema) => void;
afterWidgetCreated?: (value: any, schema: JsonSchema) => void;
beforeValidation?: (element: JQuery, result: ValidationResult) => void;
afterValidation?: (element: JQuery, result: ValidationResult) => void;
}
interface Configuration {
// Core settings
schema?: JsonSchema;
value?: any;
// Display settings
expandingLevel?: number;
renderFirstLevel?: boolean;
indenting?: number;
treeExpandCollapseButton?: boolean;
// Form behavior
autoTrimValues?: boolean;
radioNullCaption?: string;
selectNullCaption?: string;
// Theme and responsiveness
theme?: 'default' | 'dark' | string;
responsive?: boolean;
// Validation
validation?: ValidationConfiguration;
// Callbacks
callbacks?: CallbackConfiguration;
}
interface ArrayTemplate {
htmlTemplate: string;
dataTemplate: any;
}
interface ValidationError {
field: string;
message: string;
element: JQuery;
}
// ===== CLASSES =====
class JsonFormUtils {
constructor(jsonToForm: JsonToFormInstance);
deepMerge(target: object, source: object): object;
isObject(value: any): boolean;
generatePath(element: JQuery): string;
getIdBasedDataPath(dataPath: string, containerId: string): string;
getNestedValue(obj: object, path: string): any;
setNestedValue(obj: object, path: string, value: any): void;
ensureDataPath(obj: object, dataPath: string): void;
jsonEscape(str: string): string;
replaceAll(source: string, find: string, replace: string): string;
escapeRegExp(string: string): string;
fixNullUndefined(value: any, defaultValue: any): any;
getUISetting(schemaNode: JsonSchema, settingName: string, defaultValue: any): any;
getArrayType(schemaNode: JsonSchema): string;
generateSpacer(level: number): string;
generateExpandCollapseButton(type: string): string;
generateTitle(schemaNode: JsonSchema, schemaName: string): string;
escapeHtml(text: string): string;
debounce(func: Function, wait: number): Function;
isEmpty(value: any): boolean;
}
class JsonFormValidator {
validationRules: { [ruleName: string]: ValidationRule };
constructor(jsonToForm: JsonToFormInstance);
validateAll(): void;
validateInput(element: JQuery): ValidationResult;
isFormValid(): boolean;
getAllErrors(): ValidationError[];
clearValidationMessages(): void;
addCustomRule(name: string, rule: ValidationRule): void;
}
class JsonFormEventHandler {
constructor(jsonToForm: JsonToFormInstance);
initialize(): void;
destroy(): void;
triggerChange(element: JQuery): void;
on(eventName: string, handler: Function): void;
off(eventName: string, handler?: Function): void;
trigger(eventName: string, data?: any[]): void;
}
class JsonFormRenderer {
constructor(jsonToForm: JsonToFormInstance);
renderSchemaNode(schemaNode: JsonSchema, schemaName: string, requiredItems?: string[]): string;
addArrayItem(addButton: JQuery, needsReinitialization: boolean, itemIndex: number | null): void;
}
class JsonToFormInstance {
element: JQuery;
config: Configuration;
level: number;
arrayTemplates: { [templateId: string]: ArrayTemplate };
renderer: JsonFormRenderer;
validator: JsonFormValidator;
eventHandler: JsonFormEventHandler;
utils: JsonFormUtils;
constructor(element: JQuery, options?: Configuration);
// Public API
isValid(): boolean;
getSchema(): JsonSchema;
getValue(): any;
setValue(value: any): void;
updateSchema(schema: JsonSchema): void;
destroy(): void;
}
}
// ===== JQUERY PLUGIN INTERFACE =====
interface JQuery {
/**
* Initialize JsonToForm plugin on selected elements
* @param options Configuration options
* @returns JsonToForm instance or jQuery object for chaining
*/
jsonToForm(options?: JsonToForm.Configuration): JsonToForm.JsonToFormInstance | JQuery;
}
interface JQueryStatic {
fn: {
jsonToForm: {
/**
* Plugin version
*/
version: string;
/**
* Default configuration options
*/
defaults: JsonToForm.Configuration;
/**
* Add global validation rule
* @param name Rule name
* @param rule Rule definition
*/
addValidationRule(name: string, rule: JsonToForm.ValidationRule): void;
/**
* Set global theme
* @param themeName Theme name
*/
setTheme(themeName: string): void;
}
}
}
// ===== GLOBAL CLASSES (for direct usage) =====
declare global {
interface Window {
JsonToForm: typeof JsonToForm.JsonToFormInstance;
JsonFormRenderer: typeof JsonToForm.JsonFormRenderer;
JsonFormValidator: typeof JsonToForm.JsonFormValidator;
JsonFormEventHandler: typeof JsonToForm.JsonFormEventHandler;
JsonFormUtils: typeof JsonToForm.JsonFormUtils;
JsonToFormClasses: {
JsonToForm: typeof JsonToForm.JsonToFormInstance;
JsonFormRenderer: typeof JsonToForm.JsonFormRenderer;
JsonFormValidator: typeof JsonToForm.JsonFormValidator;
JsonFormEventHandler: typeof JsonToForm.JsonFormEventHandler;
JsonFormUtils: typeof JsonToForm.JsonFormUtils;
};
}
}
// ===== MODULE EXPORTS (for ES6/CommonJS) =====
export = JsonToForm;
export as namespace JsonToForm;