@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
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
const Field_1 = __importDefault(require("./Field"));
|
|
14
|
+
/**
|
|
15
|
+
* Implementation of CheckBoxGroup runtime model which extends from {@link Field | field}
|
|
16
|
+
*/
|
|
17
|
+
class CheckboxGroup extends Field_1.default {
|
|
18
|
+
/**
|
|
19
|
+
* @param params
|
|
20
|
+
* @param _options
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
constructor(params, _options) {
|
|
24
|
+
super(params, _options);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* converts the fallback type, if required, to an array. Since checkbox-group has an array type
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
_getFallbackType() {
|
|
31
|
+
const fallbackType = super._getFallbackType();
|
|
32
|
+
if (typeof fallbackType === 'string') {
|
|
33
|
+
return `${fallbackType}[]`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
_getDefaults() {
|
|
37
|
+
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true, enum: [] });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = CheckboxGroup;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { Action, ContainerJson, ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, RulesJson } from './types';
|
|
2
|
+
import Scriptable from './Scriptable';
|
|
3
|
+
import DataGroup from './data/DataGroup';
|
|
4
|
+
/**
|
|
5
|
+
* Defines a generic container class which any form container should extend from.
|
|
6
|
+
* @typeparam T type of the node which extends {@link ContainerJson} and {@link RulesJson}
|
|
7
|
+
*/
|
|
8
|
+
declare abstract class Container<T extends ContainerJson & RulesJson> extends Scriptable<T> implements ContainerModel {
|
|
9
|
+
protected _children: Array<FieldModel | FieldsetModel>;
|
|
10
|
+
protected _childrenReference: any;
|
|
11
|
+
private _itemTemplate;
|
|
12
|
+
protected _jsonModel: T & {
|
|
13
|
+
id: string;
|
|
14
|
+
items: Array<FieldJson & {
|
|
15
|
+
id: string;
|
|
16
|
+
} | ContainerJson & {
|
|
17
|
+
id: string;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
ruleNodeReference(): any;
|
|
24
|
+
get items(): (FieldModel | FieldsetModel)[];
|
|
25
|
+
set maxItems(m: number);
|
|
26
|
+
/**
|
|
27
|
+
* returns whether the items in the Panel can repeat or not
|
|
28
|
+
*/
|
|
29
|
+
hasDynamicItems(): boolean;
|
|
30
|
+
get isContainer(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the current container state
|
|
33
|
+
*/
|
|
34
|
+
getState(): T & {
|
|
35
|
+
':type': string;
|
|
36
|
+
items: ({
|
|
37
|
+
description?: string | undefined;
|
|
38
|
+
rules?: import("./types").Items<string> | undefined;
|
|
39
|
+
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
40
|
+
enumNames?: string[] | undefined;
|
|
41
|
+
enum?: any[] | undefined;
|
|
42
|
+
accept?: string[] | undefined;
|
|
43
|
+
enforceEnum?: boolean | undefined;
|
|
44
|
+
exclusiveMinimum?: number | undefined;
|
|
45
|
+
exclusiveMaximum?: number | undefined;
|
|
46
|
+
format?: string | undefined;
|
|
47
|
+
maxFileSize?: string | number | undefined;
|
|
48
|
+
maxLength?: number | undefined;
|
|
49
|
+
maximum?: number | undefined;
|
|
50
|
+
maxItems?: number | undefined;
|
|
51
|
+
minLength?: number | undefined;
|
|
52
|
+
minimum?: number | undefined;
|
|
53
|
+
minItems?: number | undefined;
|
|
54
|
+
pattern?: string | undefined;
|
|
55
|
+
required?: boolean | undefined;
|
|
56
|
+
step?: number | undefined;
|
|
57
|
+
type?: string | undefined;
|
|
58
|
+
validationExpression?: string | undefined;
|
|
59
|
+
dataRef?: string | null | undefined;
|
|
60
|
+
':type': string;
|
|
61
|
+
label?: import("./types").Label | undefined;
|
|
62
|
+
enabled?: boolean | undefined;
|
|
63
|
+
visible?: boolean | undefined;
|
|
64
|
+
name?: string | undefined;
|
|
65
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
66
|
+
fieldType?: string | undefined;
|
|
67
|
+
errorMessage?: string | undefined;
|
|
68
|
+
properties?: {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
} | undefined;
|
|
71
|
+
placeholder?: string | undefined;
|
|
72
|
+
readOnly?: boolean | undefined;
|
|
73
|
+
valid?: boolean | undefined;
|
|
74
|
+
default?: any;
|
|
75
|
+
value?: any;
|
|
76
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
77
|
+
id: string;
|
|
78
|
+
} | {
|
|
79
|
+
description?: string | undefined;
|
|
80
|
+
rules?: import("./types").Items<string> | undefined;
|
|
81
|
+
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
82
|
+
enumNames?: string[] | undefined;
|
|
83
|
+
enum?: any[] | undefined;
|
|
84
|
+
accept?: string[] | undefined;
|
|
85
|
+
enforceEnum?: boolean | undefined;
|
|
86
|
+
exclusiveMinimum?: number | undefined;
|
|
87
|
+
exclusiveMaximum?: number | undefined;
|
|
88
|
+
format?: string | undefined;
|
|
89
|
+
maxFileSize?: string | number | undefined;
|
|
90
|
+
maxLength?: number | undefined;
|
|
91
|
+
maximum?: number | undefined;
|
|
92
|
+
maxItems?: number | undefined;
|
|
93
|
+
minLength?: number | undefined;
|
|
94
|
+
minimum?: number | undefined;
|
|
95
|
+
minItems?: number | undefined;
|
|
96
|
+
pattern?: string | undefined;
|
|
97
|
+
required?: boolean | undefined;
|
|
98
|
+
step?: number | undefined;
|
|
99
|
+
type?: "object" | "array" | undefined;
|
|
100
|
+
validationExpression?: string | undefined;
|
|
101
|
+
dataRef?: string | null | undefined;
|
|
102
|
+
':type'?: string | undefined;
|
|
103
|
+
label?: import("./types").Label | undefined;
|
|
104
|
+
enabled?: boolean | undefined;
|
|
105
|
+
visible?: boolean | undefined;
|
|
106
|
+
name?: string | undefined;
|
|
107
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
108
|
+
fieldType?: string | undefined;
|
|
109
|
+
errorMessage?: string | undefined;
|
|
110
|
+
properties?: {
|
|
111
|
+
[key: string]: any;
|
|
112
|
+
} | undefined;
|
|
113
|
+
items: (FieldJson | ContainerJson)[] & (({
|
|
114
|
+
description?: string | undefined;
|
|
115
|
+
} & RulesJson & {
|
|
116
|
+
enumNames?: string[] | undefined;
|
|
117
|
+
enum?: any[] | undefined;
|
|
118
|
+
} & {
|
|
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
|
+
} & {
|
|
137
|
+
dataRef?: string | null | undefined;
|
|
138
|
+
':type'?: string | undefined;
|
|
139
|
+
label?: import("./types").Label | undefined;
|
|
140
|
+
enabled?: boolean | undefined;
|
|
141
|
+
visible?: boolean | undefined;
|
|
142
|
+
name?: string | undefined;
|
|
143
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
144
|
+
fieldType?: string | undefined;
|
|
145
|
+
errorMessage?: string | undefined;
|
|
146
|
+
properties?: {
|
|
147
|
+
[key: string]: any;
|
|
148
|
+
} | undefined;
|
|
149
|
+
} & {
|
|
150
|
+
placeholder?: string | undefined;
|
|
151
|
+
} & {
|
|
152
|
+
readOnly?: boolean | undefined;
|
|
153
|
+
valid?: boolean | undefined;
|
|
154
|
+
default?: any;
|
|
155
|
+
value?: any;
|
|
156
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
157
|
+
} & {
|
|
158
|
+
id: string;
|
|
159
|
+
':type': string;
|
|
160
|
+
}) | ({
|
|
161
|
+
description?: string | undefined;
|
|
162
|
+
} & RulesJson & {
|
|
163
|
+
enumNames?: string[] | undefined;
|
|
164
|
+
enum?: any[] | undefined;
|
|
165
|
+
} & {
|
|
166
|
+
accept?: string[] | undefined;
|
|
167
|
+
enforceEnum?: boolean | undefined;
|
|
168
|
+
exclusiveMinimum?: number | undefined;
|
|
169
|
+
exclusiveMaximum?: number | undefined;
|
|
170
|
+
format?: string | undefined;
|
|
171
|
+
maxFileSize?: string | number | undefined;
|
|
172
|
+
maxLength?: number | undefined;
|
|
173
|
+
maximum?: number | undefined;
|
|
174
|
+
maxItems?: number | undefined;
|
|
175
|
+
minLength?: number | undefined;
|
|
176
|
+
minimum?: number | undefined;
|
|
177
|
+
minItems?: number | undefined;
|
|
178
|
+
pattern?: string | undefined;
|
|
179
|
+
required?: boolean | undefined;
|
|
180
|
+
step?: number | undefined;
|
|
181
|
+
type?: string | undefined;
|
|
182
|
+
validationExpression?: string | undefined;
|
|
183
|
+
} & {
|
|
184
|
+
dataRef?: string | null | undefined;
|
|
185
|
+
':type'?: string | undefined;
|
|
186
|
+
label?: import("./types").Label | undefined;
|
|
187
|
+
enabled?: boolean | undefined;
|
|
188
|
+
visible?: boolean | undefined;
|
|
189
|
+
name?: string | undefined;
|
|
190
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
191
|
+
fieldType?: string | undefined;
|
|
192
|
+
errorMessage?: string | undefined;
|
|
193
|
+
properties?: {
|
|
194
|
+
[key: string]: any;
|
|
195
|
+
} | undefined;
|
|
196
|
+
} & {
|
|
197
|
+
items: (FieldJson | ContainerJson)[];
|
|
198
|
+
initialItems?: number | undefined;
|
|
199
|
+
} & {
|
|
200
|
+
id: string;
|
|
201
|
+
items: (({
|
|
202
|
+
description?: string | undefined;
|
|
203
|
+
} & RulesJson & {
|
|
204
|
+
enumNames?: string[] | undefined;
|
|
205
|
+
enum?: any[] | undefined;
|
|
206
|
+
} & {
|
|
207
|
+
accept?: string[] | undefined;
|
|
208
|
+
enforceEnum?: boolean | undefined;
|
|
209
|
+
exclusiveMinimum?: number | undefined;
|
|
210
|
+
exclusiveMaximum?: number | undefined;
|
|
211
|
+
format?: string | undefined;
|
|
212
|
+
maxFileSize?: string | number | undefined;
|
|
213
|
+
maxLength?: number | undefined;
|
|
214
|
+
maximum?: number | undefined;
|
|
215
|
+
maxItems?: number | undefined;
|
|
216
|
+
minLength?: number | undefined;
|
|
217
|
+
minimum?: number | undefined;
|
|
218
|
+
minItems?: number | undefined;
|
|
219
|
+
pattern?: string | undefined;
|
|
220
|
+
required?: boolean | undefined;
|
|
221
|
+
step?: number | undefined;
|
|
222
|
+
type?: string | undefined;
|
|
223
|
+
validationExpression?: string | undefined;
|
|
224
|
+
} & {
|
|
225
|
+
dataRef?: string | null | undefined;
|
|
226
|
+
':type'?: string | undefined;
|
|
227
|
+
label?: import("./types").Label | undefined;
|
|
228
|
+
enabled?: boolean | undefined;
|
|
229
|
+
visible?: boolean | undefined;
|
|
230
|
+
name?: string | undefined;
|
|
231
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
232
|
+
fieldType?: string | undefined;
|
|
233
|
+
errorMessage?: string | undefined;
|
|
234
|
+
properties?: {
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
} | undefined;
|
|
237
|
+
} & {
|
|
238
|
+
placeholder?: string | undefined;
|
|
239
|
+
} & {
|
|
240
|
+
readOnly?: boolean | undefined;
|
|
241
|
+
valid?: boolean | undefined;
|
|
242
|
+
default?: any;
|
|
243
|
+
value?: any;
|
|
244
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
245
|
+
} & {
|
|
246
|
+
id: string;
|
|
247
|
+
':type': string;
|
|
248
|
+
}) | ({
|
|
249
|
+
description?: string | undefined;
|
|
250
|
+
} & RulesJson & {
|
|
251
|
+
enumNames?: string[] | undefined;
|
|
252
|
+
enum?: any[] | undefined;
|
|
253
|
+
} & {
|
|
254
|
+
accept?: string[] | undefined;
|
|
255
|
+
enforceEnum?: boolean | undefined;
|
|
256
|
+
exclusiveMinimum?: number | undefined;
|
|
257
|
+
exclusiveMaximum?: number | undefined;
|
|
258
|
+
format?: string | undefined;
|
|
259
|
+
maxFileSize?: string | number | undefined;
|
|
260
|
+
maxLength?: number | undefined;
|
|
261
|
+
maximum?: number | undefined;
|
|
262
|
+
maxItems?: number | undefined;
|
|
263
|
+
minLength?: number | undefined;
|
|
264
|
+
minimum?: number | undefined;
|
|
265
|
+
minItems?: number | undefined;
|
|
266
|
+
pattern?: string | undefined;
|
|
267
|
+
required?: boolean | undefined;
|
|
268
|
+
step?: number | undefined;
|
|
269
|
+
type?: string | undefined;
|
|
270
|
+
validationExpression?: string | undefined;
|
|
271
|
+
} & {
|
|
272
|
+
dataRef?: string | null | undefined;
|
|
273
|
+
':type'?: string | undefined;
|
|
274
|
+
label?: import("./types").Label | undefined;
|
|
275
|
+
enabled?: boolean | undefined;
|
|
276
|
+
visible?: boolean | undefined;
|
|
277
|
+
name?: string | undefined;
|
|
278
|
+
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
279
|
+
fieldType?: string | undefined;
|
|
280
|
+
errorMessage?: string | undefined;
|
|
281
|
+
properties?: {
|
|
282
|
+
[key: string]: any;
|
|
283
|
+
} | undefined;
|
|
284
|
+
} & {
|
|
285
|
+
items: (FieldJson | ContainerJson)[];
|
|
286
|
+
initialItems?: number | undefined;
|
|
287
|
+
} & any))[];
|
|
288
|
+
}))[];
|
|
289
|
+
initialItems?: number | undefined;
|
|
290
|
+
id: string;
|
|
291
|
+
})[];
|
|
292
|
+
id: string;
|
|
293
|
+
};
|
|
294
|
+
protected abstract _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
|
|
295
|
+
private _addChildToRuleNode;
|
|
296
|
+
private _addChild;
|
|
297
|
+
indexOf(f: FieldModel | FieldsetModel): number;
|
|
298
|
+
/**
|
|
299
|
+
* @private
|
|
300
|
+
*/
|
|
301
|
+
defaultDataModel(name: string): DataGroup | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
_initialize(): void;
|
|
306
|
+
/**
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
addItem(action: Action): void;
|
|
310
|
+
/**
|
|
311
|
+
* @private
|
|
312
|
+
*/
|
|
313
|
+
removeItem(action: Action): void;
|
|
314
|
+
/**
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
queueEvent(action: Action): void;
|
|
318
|
+
validate(): import("./types").ValidationError[];
|
|
319
|
+
/**
|
|
320
|
+
* @private
|
|
321
|
+
*/
|
|
322
|
+
dispatch(action: Action): void;
|
|
323
|
+
/**
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
importData(contextualDataModel?: DataGroup): void;
|
|
327
|
+
/**
|
|
328
|
+
* prefill the form with data on the given element
|
|
329
|
+
* @param dataModel
|
|
330
|
+
* @param contextualDataModel
|
|
331
|
+
* @param operation
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
syncDataAndFormModel(contextualDataModel?: DataGroup): void;
|
|
335
|
+
}
|
|
336
|
+
export default Container;
|
package/lib/Container.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
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
|
+
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
14
|
+
const Scriptable_1 = __importDefault(require("./Scriptable"));
|
|
15
|
+
const controller_1 = require("./controller");
|
|
16
|
+
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
17
|
+
/**
|
|
18
|
+
* Defines a generic container class which any form container should extend from.
|
|
19
|
+
* @typeparam T type of the node which extends {@link ContainerJson} and {@link RulesJson}
|
|
20
|
+
*/
|
|
21
|
+
class Container extends Scriptable_1.default {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this._children = [];
|
|
25
|
+
this._itemTemplate = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
ruleNodeReference() {
|
|
31
|
+
return this._childrenReference;
|
|
32
|
+
}
|
|
33
|
+
//todo : this should not be public
|
|
34
|
+
get items() {
|
|
35
|
+
return this._children;
|
|
36
|
+
}
|
|
37
|
+
set maxItems(m) {
|
|
38
|
+
this._jsonModel.maxItems = m;
|
|
39
|
+
const minItems = this._jsonModel.minItems || 1;
|
|
40
|
+
const itemsLength = this._children.length;
|
|
41
|
+
const items2Remove = Math.min(itemsLength - m, itemsLength - minItems);
|
|
42
|
+
if (items2Remove > 0) {
|
|
43
|
+
for (let i = 0; i < items2Remove; i++) {
|
|
44
|
+
this.getDataNode().$removeDataNode(m + i);
|
|
45
|
+
this._childrenReference.pop();
|
|
46
|
+
}
|
|
47
|
+
const elems = this._children.splice(m, items2Remove);
|
|
48
|
+
this.notifyDependents((0, controller_1.propertyChange)('items', elems, null));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* returns whether the items in the Panel can repeat or not
|
|
53
|
+
*/
|
|
54
|
+
hasDynamicItems() {
|
|
55
|
+
return this._itemTemplate != null;
|
|
56
|
+
}
|
|
57
|
+
get isContainer() {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the current container state
|
|
62
|
+
*/
|
|
63
|
+
getState() {
|
|
64
|
+
return Object.assign(Object.assign({}, this._jsonModel), { ':type': this[':type'], items: this._children.map(x => {
|
|
65
|
+
return Object.assign({}, x.getState());
|
|
66
|
+
}) });
|
|
67
|
+
}
|
|
68
|
+
_addChildToRuleNode(child, options) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
70
|
+
const self = this;
|
|
71
|
+
const { parent = this } = options;
|
|
72
|
+
//the child has not been added to the array, hence using the length as new index
|
|
73
|
+
// this means unnamed panel inside repeatable named parent // this is an edge case, handling it gracefully
|
|
74
|
+
// todo: rules don't work inside repeatable array
|
|
75
|
+
const name = parent.type == 'array' ? parent._children.length + '' : child.name || '';
|
|
76
|
+
if (name.length > 0) {
|
|
77
|
+
Object.defineProperty(parent._childrenReference, name, {
|
|
78
|
+
get: () => {
|
|
79
|
+
if (child.isContainer && child.hasDynamicItems()) {
|
|
80
|
+
self.ruleEngine.trackDependency(child); //accessing dynamic panel directly
|
|
81
|
+
}
|
|
82
|
+
if (self.hasDynamicItems()) {
|
|
83
|
+
self.ruleEngine.trackDependency(self); //accessing a child of dynamic panel
|
|
84
|
+
if (this._children[name] !== undefined) { // pop function calls this getter in order to return the item
|
|
85
|
+
return this._children[name].getRuleNode();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return child.getRuleNode();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
configurable: true,
|
|
93
|
+
enumerable: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
_addChild(itemJson, index) {
|
|
98
|
+
// get first non transparent parent
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
100
|
+
let nonTransparentParent = this;
|
|
101
|
+
while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
nonTransparentParent = nonTransparentParent.parent;
|
|
104
|
+
}
|
|
105
|
+
if (typeof index !== 'number' || index > nonTransparentParent._children.length) {
|
|
106
|
+
index = nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.length;
|
|
107
|
+
}
|
|
108
|
+
const itemTemplate = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson));
|
|
109
|
+
//@ts-ignore
|
|
110
|
+
const retVal = this._createChild(itemTemplate, { parent: nonTransparentParent, index: index });
|
|
111
|
+
this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
|
|
112
|
+
if (index === (nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.length)) {
|
|
113
|
+
nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.push(retVal);
|
|
114
|
+
//(this.getDataNode() as DataGroup).$addDataNode(index);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.splice(index, 0, retVal);
|
|
119
|
+
//(this.getDataNode() as DataGroup).$addDataNode();
|
|
120
|
+
}
|
|
121
|
+
retVal._initialize();
|
|
122
|
+
return retVal;
|
|
123
|
+
}
|
|
124
|
+
indexOf(f) {
|
|
125
|
+
return this._children.indexOf(f);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
defaultDataModel(name) {
|
|
131
|
+
const type = this._jsonModel.type || undefined;
|
|
132
|
+
if (type === undefined) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const instance = type === 'array' ? [] : {};
|
|
137
|
+
return new DataGroup_1.default(name, instance, type);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @private
|
|
142
|
+
*/
|
|
143
|
+
_initialize() {
|
|
144
|
+
super._initialize();
|
|
145
|
+
const items = this._jsonModel.items;
|
|
146
|
+
this._jsonModel.items = [];
|
|
147
|
+
this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
|
|
148
|
+
if (this._jsonModel.type == 'array' && items.length === 1 && this.getDataNode() != null) {
|
|
149
|
+
this._itemTemplate = (0, JsonUtils_1.deepClone)(items[0]);
|
|
150
|
+
if (typeof (this._jsonModel.minItems) !== 'number') {
|
|
151
|
+
this._jsonModel.minItems = 0;
|
|
152
|
+
}
|
|
153
|
+
if (typeof (this._jsonModel.maxItems) !== 'number') {
|
|
154
|
+
this._jsonModel.maxItems = -1;
|
|
155
|
+
}
|
|
156
|
+
if (typeof (this._jsonModel.initialItems) !== 'number') {
|
|
157
|
+
this._jsonModel.initialItems = Math.max(1, this._jsonModel.minItems);
|
|
158
|
+
}
|
|
159
|
+
for (let i = 0; i < this._jsonModel.initialItems; i++) {
|
|
160
|
+
//@ts-ignore
|
|
161
|
+
this._addChild(this._itemTemplate);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (items.length > 0) {
|
|
165
|
+
items.forEach((item) => {
|
|
166
|
+
this._addChild(item);
|
|
167
|
+
});
|
|
168
|
+
this._jsonModel.minItems = this._children.length;
|
|
169
|
+
this._jsonModel.maxItems = this._children.length;
|
|
170
|
+
this._jsonModel.initialItems = this._children.length;
|
|
171
|
+
}
|
|
172
|
+
this.setupRuleNode();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
addItem(action) {
|
|
178
|
+
if (action.type === 'addItem' && this._itemTemplate != null) {
|
|
179
|
+
//@ts-ignore
|
|
180
|
+
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
181
|
+
const retVal = this._addChild(this._itemTemplate, action.payload);
|
|
182
|
+
this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState, null));
|
|
183
|
+
retVal.dispatch(new controller_1.Initialize());
|
|
184
|
+
retVal.dispatch(new controller_1.ExecuteRule());
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
removeItem(action) {
|
|
192
|
+
if (action.type === 'removeItem' && this._itemTemplate != null) {
|
|
193
|
+
const index = action.payload || this._children.length - 1;
|
|
194
|
+
const state = this._children[index].getState();
|
|
195
|
+
//@ts-ignore
|
|
196
|
+
if (this._children.length > this._jsonModel.minItems) {
|
|
197
|
+
// clear child
|
|
198
|
+
//remove field
|
|
199
|
+
this._childrenReference.pop();
|
|
200
|
+
this._children.splice(index, 1);
|
|
201
|
+
this.getDataNode().$removeDataNode(index);
|
|
202
|
+
for (let i = index; i < this._children.length; i++) {
|
|
203
|
+
this._children[i].dispatch(new controller_1.ExecuteRule());
|
|
204
|
+
}
|
|
205
|
+
this.notifyDependents((0, controller_1.propertyChange)('items', null, state));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
queueEvent(action) {
|
|
213
|
+
var _a;
|
|
214
|
+
super.queueEvent(action);
|
|
215
|
+
if ((_a = action.metadata) === null || _a === void 0 ? void 0 : _a.dispatch) {
|
|
216
|
+
this.items.forEach(x => {
|
|
217
|
+
//@ts-ignore
|
|
218
|
+
x.queueEvent(action);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
validate() {
|
|
223
|
+
return this.items.flatMap(x => {
|
|
224
|
+
return x.validate();
|
|
225
|
+
}).filter(x => x.fieldName !== '');
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
dispatch(action) {
|
|
231
|
+
var _a;
|
|
232
|
+
super.dispatch(action);
|
|
233
|
+
if ((_a = action.metadata) === null || _a === void 0 ? void 0 : _a.dispatch) {
|
|
234
|
+
this.items.forEach(x => {
|
|
235
|
+
x.dispatch(action);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
importData(contextualDataModel) {
|
|
243
|
+
this._bindToDataModel(contextualDataModel);
|
|
244
|
+
this.syncDataAndFormModel(this.getDataNode());
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* prefill the form with data on the given element
|
|
248
|
+
* @param dataModel
|
|
249
|
+
* @param contextualDataModel
|
|
250
|
+
* @param operation
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
syncDataAndFormModel(contextualDataModel) {
|
|
254
|
+
if ((contextualDataModel === null || contextualDataModel === void 0 ? void 0 : contextualDataModel.$type) === 'array' && this._itemTemplate != null) {
|
|
255
|
+
const dataLength = contextualDataModel === null || contextualDataModel === void 0 ? void 0 : contextualDataModel.$value.length;
|
|
256
|
+
const itemsLength = this._children.length;
|
|
257
|
+
const maxItems = this._jsonModel.maxItems === -1 ? dataLength : this._jsonModel.maxItems;
|
|
258
|
+
const minItems = this._jsonModel.minItems;
|
|
259
|
+
//@ts-ignore
|
|
260
|
+
let items2Add = Math.min(dataLength - itemsLength, maxItems - itemsLength);
|
|
261
|
+
//@ts-ignore
|
|
262
|
+
const items2Remove = Math.min(itemsLength - dataLength, itemsLength - minItems);
|
|
263
|
+
while (items2Add > 0) {
|
|
264
|
+
items2Add--;
|
|
265
|
+
this._addChild(this._itemTemplate);
|
|
266
|
+
}
|
|
267
|
+
if (items2Remove > 0) {
|
|
268
|
+
this._children.splice(dataLength, items2Remove);
|
|
269
|
+
for (let i = 0; i < items2Remove; i++) {
|
|
270
|
+
this._childrenReference.pop();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
this._children.forEach(x => {
|
|
275
|
+
x.importData(contextualDataModel);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.default = Container;
|