@aemforms/af-core 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -0
- package/README.md +34 -0
- package/lib/BaseNode.d.ts +117 -0
- package/lib/BaseNode.js +368 -0
- package/lib/Checkbox.d.ts +80 -0
- package/lib/Checkbox.js +49 -0
- package/lib/CheckboxGroup.d.ts +30 -0
- package/lib/CheckboxGroup.js +40 -0
- package/lib/Container.d.ts +336 -0
- package/lib/Container.js +279 -0
- package/lib/Field.d.ts +185 -0
- package/lib/Field.js +432 -0
- package/lib/Fieldset.d.ts +31 -0
- package/lib/Fieldset.js +97 -0
- package/lib/FileObject.d.ts +17 -0
- package/lib/FileObject.js +30 -0
- package/lib/FileUpload.d.ts +42 -0
- package/lib/FileUpload.js +299 -0
- package/lib/Form.d.ts +413 -0
- package/lib/Form.js +247 -0
- package/lib/FormInstance.d.ts +26 -0
- package/lib/FormInstance.js +116 -0
- package/lib/FormMetaData.d.ts +11 -0
- package/lib/FormMetaData.js +28 -0
- package/lib/Node.d.ts +12 -0
- package/lib/Node.js +27 -0
- package/lib/Scriptable.d.ts +27 -0
- package/lib/Scriptable.js +216 -0
- package/lib/controller/Controller.d.ts +207 -0
- package/lib/controller/Controller.js +263 -0
- package/lib/controller/EventQueue.d.ts +24 -0
- package/lib/controller/EventQueue.js +99 -0
- package/lib/controller/index.d.ts +1 -0
- package/lib/controller/index.js +24 -0
- package/lib/data/DataGroup.d.ts +25 -0
- package/lib/data/DataGroup.js +74 -0
- package/lib/data/DataValue.d.ts +22 -0
- package/lib/data/DataValue.js +50 -0
- package/lib/data/EmptyDataValue.d.ts +14 -0
- package/lib/data/EmptyDataValue.js +46 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +59 -0
- package/lib/rules/FunctionRuntime.d.ts +44 -0
- package/lib/rules/FunctionRuntime.js +271 -0
- package/lib/rules/RuleEngine.d.ts +23 -0
- package/lib/rules/RuleEngine.js +67 -0
- package/lib/types/Json.d.ts +126 -0
- package/lib/types/Json.js +16 -0
- package/lib/types/Model.d.ts +352 -0
- package/lib/types/Model.js +20 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +25 -0
- package/lib/utils/DataRefParser.d.ts +30 -0
- package/lib/utils/DataRefParser.js +249 -0
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +29 -0
- package/lib/utils/FormUtils.d.ts +47 -0
- package/lib/utils/FormUtils.js +172 -0
- package/lib/utils/JsonUtils.d.ts +55 -0
- package/lib/utils/JsonUtils.js +128 -0
- package/lib/utils/LogUtils.d.ts +7 -0
- package/lib/utils/LogUtils.js +17 -0
- package/lib/utils/SchemaUtils.d.ts +16 -0
- package/lib/utils/SchemaUtils.js +92 -0
- package/lib/utils/TranslationUtils.d.ts +34 -0
- package/lib/utils/TranslationUtils.js +156 -0
- package/lib/utils/ValidationUtils.d.ts +153 -0
- package/lib/utils/ValidationUtils.js +339 -0
- package/package.json +60 -0
package/lib/Form.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import Container from './Container';
|
|
2
|
+
import { Action, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, FormModel, Items } from './types';
|
|
3
|
+
import FormMetaData from './FormMetaData';
|
|
4
|
+
import EventQueue from './controller/EventQueue';
|
|
5
|
+
import RuleEngine from './rules/RuleEngine';
|
|
6
|
+
declare type LogFunction = 'info' | 'warn' | 'error';
|
|
7
|
+
/**
|
|
8
|
+
* Logging levels.
|
|
9
|
+
*/
|
|
10
|
+
export declare type LogLevel = 'off' | LogFunction;
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export declare class Logger {
|
|
15
|
+
info(msg: string): void;
|
|
16
|
+
warn(msg: string): void;
|
|
17
|
+
error(msg: string): void;
|
|
18
|
+
log(msg: string, level: LogFunction): void;
|
|
19
|
+
private logLevel;
|
|
20
|
+
constructor(logLevel?: LogLevel);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Defines `form model` which implements {@link FormModel | form model}
|
|
24
|
+
*/
|
|
25
|
+
declare class Form extends Container<FormJson> implements FormModel {
|
|
26
|
+
private _ruleEngine;
|
|
27
|
+
private _eventQueue;
|
|
28
|
+
/**
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private _fields;
|
|
32
|
+
/**
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
_ids: Generator<string, void, string>;
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private _invalidFields;
|
|
40
|
+
private _logger;
|
|
41
|
+
/**
|
|
42
|
+
* @param n
|
|
43
|
+
* @param _ruleEngine
|
|
44
|
+
* @param _eventQueue
|
|
45
|
+
* @param logLevel
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
constructor(n: FormJson, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel);
|
|
49
|
+
get logger(): Logger;
|
|
50
|
+
private dataRefRegex;
|
|
51
|
+
get metaData(): FormMetaData;
|
|
52
|
+
get action(): string | undefined;
|
|
53
|
+
protected _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
|
|
54
|
+
importData(dataModel: any): void;
|
|
55
|
+
exportData(): any;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the current state of the form
|
|
58
|
+
*
|
|
59
|
+
* To access the form data and attachments, one needs to use the `data` and `attachments` property.
|
|
60
|
+
* For example,
|
|
61
|
+
* ```
|
|
62
|
+
* const data = form.getState().data
|
|
63
|
+
* const attachments = form.getState().attachments
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
getState(): {
|
|
67
|
+
description?: string | undefined;
|
|
68
|
+
} & import("./types").RulesJson & {
|
|
69
|
+
enumNames?: string[] | undefined;
|
|
70
|
+
enum?: any[] | undefined;
|
|
71
|
+
} & {
|
|
72
|
+
accept?: string[] | undefined;
|
|
73
|
+
enforceEnum?: boolean | undefined;
|
|
74
|
+
exclusiveMinimum?: number | undefined;
|
|
75
|
+
exclusiveMaximum?: number | undefined;
|
|
76
|
+
format?: string | undefined;
|
|
77
|
+
maxFileSize?: string | number | undefined;
|
|
78
|
+
maxLength?: number | undefined;
|
|
79
|
+
maximum?: number | undefined;
|
|
80
|
+
maxItems?: number | undefined;
|
|
81
|
+
minLength?: number | undefined;
|
|
82
|
+
minimum?: number | undefined;
|
|
83
|
+
minItems?: number | undefined;
|
|
84
|
+
pattern?: string | undefined;
|
|
85
|
+
required?: boolean | undefined;
|
|
86
|
+
step?: number | undefined;
|
|
87
|
+
type?: string | undefined;
|
|
88
|
+
validationExpression?: string | undefined;
|
|
89
|
+
} & {
|
|
90
|
+
dataRef?: string | null | undefined;
|
|
91
|
+
':type'?: string | undefined;
|
|
92
|
+
label?: import("./types").Label | undefined;
|
|
93
|
+
enabled?: boolean | undefined;
|
|
94
|
+
visible?: boolean | undefined;
|
|
95
|
+
name?: string | undefined;
|
|
96
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
97
|
+
fieldType?: string | undefined;
|
|
98
|
+
errorMessage?: string | undefined;
|
|
99
|
+
properties?: {
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
} | undefined;
|
|
102
|
+
} & {
|
|
103
|
+
items: (FieldJson | import("./types").ContainerJson)[];
|
|
104
|
+
initialItems?: number | undefined;
|
|
105
|
+
} & {
|
|
106
|
+
metadata?: import("./types").MetaDataJson | undefined;
|
|
107
|
+
data?: any;
|
|
108
|
+
title?: string | undefined;
|
|
109
|
+
action?: string | undefined;
|
|
110
|
+
adaptiveForm?: string | undefined;
|
|
111
|
+
} & {
|
|
112
|
+
':type': string;
|
|
113
|
+
items: ({
|
|
114
|
+
description?: string | undefined;
|
|
115
|
+
rules?: Items<string> | undefined;
|
|
116
|
+
events?: Items<string | string[] | undefined> | undefined;
|
|
117
|
+
enumNames?: string[] | undefined;
|
|
118
|
+
enum?: any[] | undefined;
|
|
119
|
+
accept?: string[] | undefined;
|
|
120
|
+
enforceEnum?: boolean | undefined;
|
|
121
|
+
exclusiveMinimum?: number | undefined;
|
|
122
|
+
exclusiveMaximum?: number | undefined;
|
|
123
|
+
format?: string | undefined;
|
|
124
|
+
maxFileSize?: string | number | undefined;
|
|
125
|
+
maxLength?: number | undefined;
|
|
126
|
+
maximum?: number | undefined;
|
|
127
|
+
maxItems?: number | undefined;
|
|
128
|
+
minLength?: number | undefined;
|
|
129
|
+
minimum?: number | undefined;
|
|
130
|
+
minItems?: number | undefined;
|
|
131
|
+
pattern?: string | undefined;
|
|
132
|
+
required?: boolean | undefined;
|
|
133
|
+
step?: number | undefined;
|
|
134
|
+
type?: string | undefined;
|
|
135
|
+
validationExpression?: string | undefined;
|
|
136
|
+
dataRef?: string | null | undefined;
|
|
137
|
+
':type': string;
|
|
138
|
+
label?: import("./types").Label | undefined;
|
|
139
|
+
enabled?: boolean | undefined;
|
|
140
|
+
visible?: boolean | undefined;
|
|
141
|
+
name?: string | undefined;
|
|
142
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
143
|
+
fieldType?: string | undefined;
|
|
144
|
+
errorMessage?: string | undefined;
|
|
145
|
+
properties?: {
|
|
146
|
+
[key: string]: any;
|
|
147
|
+
} | undefined;
|
|
148
|
+
placeholder?: string | undefined;
|
|
149
|
+
readOnly?: boolean | undefined;
|
|
150
|
+
valid?: boolean | undefined;
|
|
151
|
+
default?: any;
|
|
152
|
+
value?: any;
|
|
153
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
154
|
+
id: string;
|
|
155
|
+
} | {
|
|
156
|
+
description?: string | undefined;
|
|
157
|
+
rules?: Items<string> | undefined;
|
|
158
|
+
events?: Items<string | string[] | undefined> | undefined;
|
|
159
|
+
enumNames?: string[] | undefined;
|
|
160
|
+
enum?: any[] | undefined;
|
|
161
|
+
accept?: string[] | undefined;
|
|
162
|
+
enforceEnum?: boolean | undefined;
|
|
163
|
+
exclusiveMinimum?: number | undefined;
|
|
164
|
+
exclusiveMaximum?: number | undefined;
|
|
165
|
+
format?: string | undefined;
|
|
166
|
+
maxFileSize?: string | number | undefined;
|
|
167
|
+
maxLength?: number | undefined;
|
|
168
|
+
maximum?: number | undefined;
|
|
169
|
+
maxItems?: number | undefined;
|
|
170
|
+
minLength?: number | undefined;
|
|
171
|
+
minimum?: number | undefined;
|
|
172
|
+
minItems?: number | undefined;
|
|
173
|
+
pattern?: string | undefined;
|
|
174
|
+
required?: boolean | undefined;
|
|
175
|
+
step?: number | undefined;
|
|
176
|
+
type?: "object" | "array" | undefined;
|
|
177
|
+
validationExpression?: string | undefined;
|
|
178
|
+
dataRef?: string | null | undefined;
|
|
179
|
+
':type'?: string | undefined;
|
|
180
|
+
label?: import("./types").Label | undefined;
|
|
181
|
+
enabled?: boolean | undefined;
|
|
182
|
+
visible?: boolean | undefined;
|
|
183
|
+
name?: string | undefined;
|
|
184
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
185
|
+
fieldType?: string | undefined;
|
|
186
|
+
errorMessage?: string | undefined;
|
|
187
|
+
properties?: {
|
|
188
|
+
[key: string]: any;
|
|
189
|
+
} | undefined;
|
|
190
|
+
items: (FieldJson | import("./types").ContainerJson)[] & (({
|
|
191
|
+
description?: string | undefined;
|
|
192
|
+
} & import("./types").RulesJson & {
|
|
193
|
+
enumNames?: string[] | undefined;
|
|
194
|
+
enum?: any[] | undefined;
|
|
195
|
+
} & {
|
|
196
|
+
accept?: string[] | undefined;
|
|
197
|
+
enforceEnum?: boolean | undefined;
|
|
198
|
+
exclusiveMinimum?: number | undefined;
|
|
199
|
+
exclusiveMaximum?: number | undefined;
|
|
200
|
+
format?: string | undefined;
|
|
201
|
+
maxFileSize?: string | number | undefined;
|
|
202
|
+
maxLength?: number | undefined;
|
|
203
|
+
maximum?: number | undefined;
|
|
204
|
+
maxItems?: number | undefined;
|
|
205
|
+
minLength?: number | undefined;
|
|
206
|
+
minimum?: number | undefined;
|
|
207
|
+
minItems?: number | undefined;
|
|
208
|
+
pattern?: string | undefined;
|
|
209
|
+
required?: boolean | undefined;
|
|
210
|
+
step?: number | undefined;
|
|
211
|
+
type?: string | undefined;
|
|
212
|
+
validationExpression?: string | undefined;
|
|
213
|
+
} & {
|
|
214
|
+
dataRef?: string | null | undefined;
|
|
215
|
+
':type'?: string | undefined;
|
|
216
|
+
label?: import("./types").Label | undefined;
|
|
217
|
+
enabled?: boolean | undefined;
|
|
218
|
+
visible?: boolean | undefined;
|
|
219
|
+
name?: string | undefined;
|
|
220
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
221
|
+
fieldType?: string | undefined;
|
|
222
|
+
errorMessage?: string | undefined;
|
|
223
|
+
properties?: {
|
|
224
|
+
[key: string]: any;
|
|
225
|
+
} | undefined;
|
|
226
|
+
} & {
|
|
227
|
+
placeholder?: string | undefined;
|
|
228
|
+
} & {
|
|
229
|
+
readOnly?: boolean | undefined;
|
|
230
|
+
valid?: boolean | undefined;
|
|
231
|
+
default?: any;
|
|
232
|
+
value?: any;
|
|
233
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
234
|
+
} & {
|
|
235
|
+
id: string;
|
|
236
|
+
':type': string;
|
|
237
|
+
}) | ({
|
|
238
|
+
description?: string | undefined;
|
|
239
|
+
} & import("./types").RulesJson & {
|
|
240
|
+
enumNames?: string[] | undefined;
|
|
241
|
+
enum?: any[] | undefined;
|
|
242
|
+
} & {
|
|
243
|
+
accept?: string[] | undefined;
|
|
244
|
+
enforceEnum?: boolean | undefined;
|
|
245
|
+
exclusiveMinimum?: number | undefined;
|
|
246
|
+
exclusiveMaximum?: number | undefined;
|
|
247
|
+
format?: string | undefined;
|
|
248
|
+
maxFileSize?: string | number | undefined;
|
|
249
|
+
maxLength?: number | undefined;
|
|
250
|
+
maximum?: number | undefined;
|
|
251
|
+
maxItems?: number | undefined;
|
|
252
|
+
minLength?: number | undefined;
|
|
253
|
+
minimum?: number | undefined;
|
|
254
|
+
minItems?: number | undefined;
|
|
255
|
+
pattern?: string | undefined;
|
|
256
|
+
required?: boolean | undefined;
|
|
257
|
+
step?: number | undefined;
|
|
258
|
+
type?: string | undefined;
|
|
259
|
+
validationExpression?: string | undefined;
|
|
260
|
+
} & {
|
|
261
|
+
dataRef?: string | null | undefined;
|
|
262
|
+
':type'?: string | undefined;
|
|
263
|
+
label?: import("./types").Label | undefined;
|
|
264
|
+
enabled?: boolean | undefined;
|
|
265
|
+
visible?: boolean | undefined;
|
|
266
|
+
name?: string | undefined;
|
|
267
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
268
|
+
fieldType?: string | undefined;
|
|
269
|
+
errorMessage?: string | undefined;
|
|
270
|
+
properties?: {
|
|
271
|
+
[key: string]: any;
|
|
272
|
+
} | undefined;
|
|
273
|
+
} & {
|
|
274
|
+
items: (FieldJson | import("./types").ContainerJson)[];
|
|
275
|
+
initialItems?: number | undefined;
|
|
276
|
+
} & {
|
|
277
|
+
id: string;
|
|
278
|
+
items: (({
|
|
279
|
+
description?: string | undefined;
|
|
280
|
+
} & import("./types").RulesJson & {
|
|
281
|
+
enumNames?: string[] | undefined;
|
|
282
|
+
enum?: any[] | undefined;
|
|
283
|
+
} & {
|
|
284
|
+
accept?: string[] | undefined;
|
|
285
|
+
enforceEnum?: boolean | undefined;
|
|
286
|
+
exclusiveMinimum?: number | undefined;
|
|
287
|
+
exclusiveMaximum?: number | undefined;
|
|
288
|
+
format?: string | undefined;
|
|
289
|
+
maxFileSize?: string | number | undefined;
|
|
290
|
+
maxLength?: number | undefined;
|
|
291
|
+
maximum?: number | undefined;
|
|
292
|
+
maxItems?: number | undefined;
|
|
293
|
+
minLength?: number | undefined;
|
|
294
|
+
minimum?: number | undefined;
|
|
295
|
+
minItems?: number | undefined;
|
|
296
|
+
pattern?: string | undefined;
|
|
297
|
+
required?: boolean | undefined;
|
|
298
|
+
step?: number | undefined;
|
|
299
|
+
type?: string | undefined;
|
|
300
|
+
validationExpression?: string | undefined;
|
|
301
|
+
} & {
|
|
302
|
+
dataRef?: string | null | undefined;
|
|
303
|
+
':type'?: string | undefined;
|
|
304
|
+
label?: import("./types").Label | undefined;
|
|
305
|
+
enabled?: boolean | undefined;
|
|
306
|
+
visible?: boolean | undefined;
|
|
307
|
+
name?: string | undefined;
|
|
308
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
309
|
+
fieldType?: string | undefined;
|
|
310
|
+
errorMessage?: string | undefined;
|
|
311
|
+
properties?: {
|
|
312
|
+
[key: string]: any;
|
|
313
|
+
} | undefined;
|
|
314
|
+
} & {
|
|
315
|
+
placeholder?: string | undefined;
|
|
316
|
+
} & {
|
|
317
|
+
readOnly?: boolean | undefined;
|
|
318
|
+
valid?: boolean | undefined;
|
|
319
|
+
default?: any;
|
|
320
|
+
value?: any;
|
|
321
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
322
|
+
} & {
|
|
323
|
+
id: string;
|
|
324
|
+
':type': string;
|
|
325
|
+
}) | ({
|
|
326
|
+
description?: string | undefined;
|
|
327
|
+
} & import("./types").RulesJson & {
|
|
328
|
+
enumNames?: string[] | undefined;
|
|
329
|
+
enum?: any[] | undefined;
|
|
330
|
+
} & {
|
|
331
|
+
accept?: string[] | undefined;
|
|
332
|
+
enforceEnum?: boolean | undefined;
|
|
333
|
+
exclusiveMinimum?: number | undefined;
|
|
334
|
+
exclusiveMaximum?: number | undefined;
|
|
335
|
+
format?: string | undefined;
|
|
336
|
+
maxFileSize?: string | number | undefined;
|
|
337
|
+
maxLength?: number | undefined;
|
|
338
|
+
maximum?: number | undefined;
|
|
339
|
+
maxItems?: number | undefined;
|
|
340
|
+
minLength?: number | undefined;
|
|
341
|
+
minimum?: number | undefined;
|
|
342
|
+
minItems?: number | undefined;
|
|
343
|
+
pattern?: string | undefined;
|
|
344
|
+
required?: boolean | undefined;
|
|
345
|
+
step?: number | undefined;
|
|
346
|
+
type?: string | undefined;
|
|
347
|
+
validationExpression?: string | undefined;
|
|
348
|
+
} & {
|
|
349
|
+
dataRef?: string | null | undefined;
|
|
350
|
+
':type'?: string | undefined;
|
|
351
|
+
label?: import("./types").Label | undefined;
|
|
352
|
+
enabled?: boolean | undefined;
|
|
353
|
+
visible?: boolean | undefined;
|
|
354
|
+
name?: string | undefined;
|
|
355
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
356
|
+
fieldType?: string | undefined;
|
|
357
|
+
errorMessage?: string | undefined;
|
|
358
|
+
properties?: {
|
|
359
|
+
[key: string]: any;
|
|
360
|
+
} | undefined;
|
|
361
|
+
} & {
|
|
362
|
+
items: (FieldJson | import("./types").ContainerJson)[];
|
|
363
|
+
initialItems?: number | undefined;
|
|
364
|
+
} & any))[];
|
|
365
|
+
}))[];
|
|
366
|
+
initialItems?: number | undefined;
|
|
367
|
+
id: string;
|
|
368
|
+
})[];
|
|
369
|
+
id: string;
|
|
370
|
+
};
|
|
371
|
+
get type(): string;
|
|
372
|
+
isTransparent(): boolean;
|
|
373
|
+
get form(): FormModel;
|
|
374
|
+
get ruleEngine(): RuleEngine;
|
|
375
|
+
getUniqueId(): string;
|
|
376
|
+
/**
|
|
377
|
+
* @param field
|
|
378
|
+
* @private
|
|
379
|
+
*/
|
|
380
|
+
fieldAdded(field: FieldModel | FieldsetModel): void;
|
|
381
|
+
validate(): import("./types").ValidationError[];
|
|
382
|
+
/**
|
|
383
|
+
* Checks if the given form is valid or not
|
|
384
|
+
* @returns `true`, if form is valid, `false` otherwise
|
|
385
|
+
*/
|
|
386
|
+
isValid(): boolean;
|
|
387
|
+
/**
|
|
388
|
+
* @param field
|
|
389
|
+
* @private
|
|
390
|
+
*/
|
|
391
|
+
dispatch(action: Action): void;
|
|
392
|
+
/**
|
|
393
|
+
* @param action
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
396
|
+
executeAction(action: Action): void;
|
|
397
|
+
/**
|
|
398
|
+
* @param action
|
|
399
|
+
* @param context
|
|
400
|
+
* @private
|
|
401
|
+
*/
|
|
402
|
+
submit(action: Action, context: any): void;
|
|
403
|
+
getElement(id: string): FieldModel | FieldsetModel | this;
|
|
404
|
+
/**
|
|
405
|
+
* @private
|
|
406
|
+
*/
|
|
407
|
+
getEventQueue(): EventQueue;
|
|
408
|
+
get name(): string;
|
|
409
|
+
get value(): null;
|
|
410
|
+
get id(): string;
|
|
411
|
+
get title(): string;
|
|
412
|
+
}
|
|
413
|
+
export default Form;
|
package/lib/Form.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2022 Adobe, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
|
|
6
|
+
*
|
|
7
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Logger = void 0;
|
|
14
|
+
const Container_1 = __importDefault(require("./Container"));
|
|
15
|
+
const FormMetaData_1 = __importDefault(require("./FormMetaData"));
|
|
16
|
+
const Fieldset_1 = require("./Fieldset");
|
|
17
|
+
const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
|
|
18
|
+
const FormUtils_1 = require("./utils/FormUtils");
|
|
19
|
+
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
20
|
+
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
21
|
+
const controller_1 = require("./controller");
|
|
22
|
+
const levels = {
|
|
23
|
+
off: 0,
|
|
24
|
+
info: 1,
|
|
25
|
+
warn: 2,
|
|
26
|
+
error: 3
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
class Logger {
|
|
32
|
+
constructor(logLevel = 'off') {
|
|
33
|
+
this.logLevel = levels[logLevel];
|
|
34
|
+
}
|
|
35
|
+
info(msg) {
|
|
36
|
+
this.log(msg, 'info');
|
|
37
|
+
}
|
|
38
|
+
warn(msg) {
|
|
39
|
+
this.log(msg, 'warn');
|
|
40
|
+
}
|
|
41
|
+
error(msg) {
|
|
42
|
+
this.log(msg, 'error');
|
|
43
|
+
}
|
|
44
|
+
log(msg, level) {
|
|
45
|
+
if (this.logLevel !== 0 && this.logLevel <= levels[level]) {
|
|
46
|
+
console[level](msg);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Logger = Logger;
|
|
51
|
+
/**
|
|
52
|
+
* Defines `form model` which implements {@link FormModel | form model}
|
|
53
|
+
*/
|
|
54
|
+
class Form extends Container_1.default {
|
|
55
|
+
/**
|
|
56
|
+
* @param n
|
|
57
|
+
* @param _ruleEngine
|
|
58
|
+
* @param _eventQueue
|
|
59
|
+
* @param logLevel
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
constructor(n, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off') {
|
|
63
|
+
//@ts-ignore
|
|
64
|
+
super(n, {});
|
|
65
|
+
this._ruleEngine = _ruleEngine;
|
|
66
|
+
this._eventQueue = _eventQueue;
|
|
67
|
+
/**
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
this._fields = {};
|
|
71
|
+
/**
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
this._invalidFields = [];
|
|
75
|
+
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
76
|
+
this._logger = new Logger(logLevel);
|
|
77
|
+
this.queueEvent(new controller_1.Initialize());
|
|
78
|
+
this.queueEvent(new controller_1.ExecuteRule());
|
|
79
|
+
this._ids = (0, FormUtils_1.IdGenerator)();
|
|
80
|
+
this._bindToDataModel(new DataGroup_1.default('$form', {}));
|
|
81
|
+
this._initialize();
|
|
82
|
+
}
|
|
83
|
+
get logger() {
|
|
84
|
+
return this._logger;
|
|
85
|
+
}
|
|
86
|
+
get metaData() {
|
|
87
|
+
const metaData = this._jsonModel.metadata || {};
|
|
88
|
+
return new FormMetaData_1.default(metaData);
|
|
89
|
+
}
|
|
90
|
+
get action() {
|
|
91
|
+
return this._jsonModel.action;
|
|
92
|
+
}
|
|
93
|
+
_createChild(child) {
|
|
94
|
+
return (0, Fieldset_1.createChild)(child, { form: this, parent: this });
|
|
95
|
+
}
|
|
96
|
+
importData(dataModel) {
|
|
97
|
+
this._bindToDataModel(new DataGroup_1.default('$form', dataModel));
|
|
98
|
+
this.syncDataAndFormModel(this.getDataNode());
|
|
99
|
+
this._eventQueue.runPendingQueue();
|
|
100
|
+
}
|
|
101
|
+
exportData() {
|
|
102
|
+
var _a;
|
|
103
|
+
return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns the current state of the form
|
|
107
|
+
*
|
|
108
|
+
* To access the form data and attachments, one needs to use the `data` and `attachments` property.
|
|
109
|
+
* For example,
|
|
110
|
+
* ```
|
|
111
|
+
* const data = form.getState().data
|
|
112
|
+
* const attachments = form.getState().attachments
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
getState() {
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
117
|
+
const self = this;
|
|
118
|
+
const res = super.getState();
|
|
119
|
+
res.id = '$form';
|
|
120
|
+
Object.defineProperty(res, 'data', {
|
|
121
|
+
get: function () {
|
|
122
|
+
return self.exportData();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(res, 'attachments', {
|
|
126
|
+
get: function () {
|
|
127
|
+
return (0, FormUtils_1.getAttachments)(self);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
132
|
+
get type() {
|
|
133
|
+
return 'object';
|
|
134
|
+
}
|
|
135
|
+
isTransparent() {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
get form() {
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
get ruleEngine() {
|
|
142
|
+
return this._ruleEngine;
|
|
143
|
+
}
|
|
144
|
+
getUniqueId() {
|
|
145
|
+
if (this._ids == null) {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
return this._ids.next().value;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @param field
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
fieldAdded(field) {
|
|
155
|
+
this._fields[field.id] = field;
|
|
156
|
+
field.subscribe((action) => {
|
|
157
|
+
if (this._invalidFields.indexOf(action.target.id) === -1) {
|
|
158
|
+
this._invalidFields.push(action.target.id);
|
|
159
|
+
}
|
|
160
|
+
}, 'invalid');
|
|
161
|
+
field.subscribe((action) => {
|
|
162
|
+
const index = this._invalidFields.indexOf(action.target.id);
|
|
163
|
+
if (index > -1) {
|
|
164
|
+
this._invalidFields.splice(index, 1);
|
|
165
|
+
}
|
|
166
|
+
}, 'valid');
|
|
167
|
+
field.subscribe((action) => {
|
|
168
|
+
//@ts-ignore
|
|
169
|
+
const field = action.target.getState();
|
|
170
|
+
if (field) {
|
|
171
|
+
const fieldChangedAction = new controller_1.FieldChanged(action.payload.changes, field);
|
|
172
|
+
this.dispatch(fieldChangedAction);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
validate() {
|
|
177
|
+
const validationErrors = super.validate();
|
|
178
|
+
// trigger event on form so that user's can customize their application
|
|
179
|
+
this.dispatch(new controller_1.ValidationComplete(validationErrors));
|
|
180
|
+
return validationErrors;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Checks if the given form is valid or not
|
|
184
|
+
* @returns `true`, if form is valid, `false` otherwise
|
|
185
|
+
*/
|
|
186
|
+
isValid() {
|
|
187
|
+
return this._invalidFields.length === 0;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @param field
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
193
|
+
dispatch(action) {
|
|
194
|
+
if (action.type === 'submit') {
|
|
195
|
+
super.queueEvent(action);
|
|
196
|
+
this._eventQueue.runPendingQueue();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
super.dispatch(action);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @param action
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
executeAction(action) {
|
|
207
|
+
if (action.type !== 'submit' || this._invalidFields.length === 0) {
|
|
208
|
+
super.executeAction(action);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @param action
|
|
213
|
+
* @param context
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
submit(action, context) {
|
|
217
|
+
// if no errors, only then submit
|
|
218
|
+
if (this.validate().length === 0) {
|
|
219
|
+
(0, FunctionRuntime_1.submit)(context, action.payload.success, action.payload.error, action.payload.submit_as, action.payload.data);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
getElement(id) {
|
|
223
|
+
if (id == this.id) {
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
return this._fields[id];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
getEventQueue() {
|
|
232
|
+
return this._eventQueue;
|
|
233
|
+
}
|
|
234
|
+
get name() {
|
|
235
|
+
return '$form';
|
|
236
|
+
}
|
|
237
|
+
get value() {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
get id() {
|
|
241
|
+
return '$form';
|
|
242
|
+
}
|
|
243
|
+
get title() {
|
|
244
|
+
return this._jsonModel.title || '';
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.default = Form;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LogLevel } from './Form';
|
|
2
|
+
import { FormModel } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates form instance using form model definition as per `adaptive form specification`
|
|
5
|
+
* @param formModel form model definition
|
|
6
|
+
* @param callback a callback that recieves the FormModel instance that gets executed before any event in the Form
|
|
7
|
+
* is executed
|
|
8
|
+
* @param logLevel Logging Level for the form. Setting it off will disable the logging
|
|
9
|
+
* @param fModel existing form model, this is additional optimization to prevent creation of form instance
|
|
10
|
+
* @returns {@link FormModel | form model}
|
|
11
|
+
*/
|
|
12
|
+
export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
|
|
13
|
+
/**
|
|
14
|
+
* Validates Form model definition with the given data
|
|
15
|
+
* @param formModel form model definition
|
|
16
|
+
* @param data form data
|
|
17
|
+
* @returns `true`, if form is valid against the given form data, `false` otherwise
|
|
18
|
+
*/
|
|
19
|
+
export declare const validateFormInstance: (formModel: any, data: any) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Helper API to fetch form model definition from an AEM instance
|
|
22
|
+
* @param url URL of the instance
|
|
23
|
+
* @param headers HTTP headers to pass to the aem instance
|
|
24
|
+
* @returns promise which resolves to the form model definition
|
|
25
|
+
*/
|
|
26
|
+
export declare const fetchForm: (url: string, headers?: any) => Promise<string>;
|