@aemforms/af-core 0.22.17 → 0.22.19
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/lib/BaseNode.d.ts +13 -0
- package/lib/BaseNode.js +40 -8
- package/lib/CheckboxGroup.js +3 -0
- package/lib/Container.d.ts +16 -308
- package/lib/Container.js +34 -17
- package/lib/Field.d.ts +35 -8
- package/lib/Field.js +224 -26
- package/lib/Fieldset.d.ts +0 -10
- package/lib/Fieldset.js +3 -42
- package/lib/FileObject.d.ts +3 -2
- package/lib/FileObject.js +6 -3
- package/lib/FileUpload.d.ts +2 -1
- package/lib/FileUpload.js +4 -1
- package/lib/Form.d.ts +36 -280
- package/lib/Form.js +25 -3
- package/lib/FormInstance.js +14 -6
- package/lib/InstanceManager.d.ts +16 -0
- package/lib/InstanceManager.js +53 -0
- package/lib/Scriptable.d.ts +1 -1
- package/lib/Scriptable.js +7 -7
- package/lib/controller/Controller.d.ts +32 -0
- package/lib/controller/Controller.js +42 -1
- package/lib/data/DataGroup.js +5 -1
- package/lib/data/DataValue.d.ts +1 -1
- package/lib/data/DataValue.js +4 -0
- package/lib/rules/FunctionRuntime.js +6 -0
- package/lib/types/Json.d.ts +6 -0
- package/lib/types/Model.d.ts +22 -7
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +67 -9
- package/lib/utils/FormCreationUtils.d.ts +11 -0
- package/lib/utils/FormCreationUtils.js +83 -0
- package/lib/utils/FormUtils.js +8 -5
- package/lib/utils/JsonUtils.d.ts +1 -0
- package/lib/utils/JsonUtils.js +15 -1
- package/lib/utils/ValidationUtils.js +14 -0
- package/package.json +2 -2
package/lib/BaseNode.d.ts
CHANGED
|
@@ -9,9 +9,12 @@ export declare const editableProperties: string[];
|
|
|
9
9
|
* Defines props that are dynamic and can be changed at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export declare const dynamicProps: string[];
|
|
12
|
+
export declare const staticFields: string[];
|
|
12
13
|
export declare const target: unique symbol;
|
|
13
14
|
export declare const qualifiedName: unique symbol;
|
|
14
15
|
export declare function dependencyTracked(): (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
16
|
+
export declare const include: (...fieldTypes: string[]) => (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
17
|
+
export declare const exclude: (...fieldTypes: string[]) => (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
15
18
|
/**
|
|
16
19
|
* Defines a generic base class which all objects of form runtime model should extend from.
|
|
17
20
|
* @typeparam T type of the form object which extends from {@link BaseJson | base type}
|
|
@@ -37,6 +40,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
37
40
|
parent: ContainerModel;
|
|
38
41
|
});
|
|
39
42
|
abstract value: Primitives;
|
|
43
|
+
abstract reset(): any;
|
|
40
44
|
protected setupRuleNode(): void;
|
|
41
45
|
/**
|
|
42
46
|
* @private
|
|
@@ -51,6 +55,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
51
55
|
get index(): number;
|
|
52
56
|
get parent(): ContainerModel;
|
|
53
57
|
get type(): string | undefined;
|
|
58
|
+
get repeatable(): boolean;
|
|
54
59
|
get fieldType(): string;
|
|
55
60
|
get ':type'(): string;
|
|
56
61
|
get name(): string | undefined;
|
|
@@ -69,6 +74,14 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
69
74
|
*/
|
|
70
75
|
isTransparent(): boolean;
|
|
71
76
|
getState(): T & {
|
|
77
|
+
properties: {
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
};
|
|
80
|
+
index: number;
|
|
81
|
+
parent: undefined;
|
|
82
|
+
qualifiedName: any;
|
|
83
|
+
events: {};
|
|
84
|
+
rules: {};
|
|
72
85
|
':type': string;
|
|
73
86
|
id: string;
|
|
74
87
|
};
|
package/lib/BaseNode.js
CHANGED
|
@@ -16,10 +16,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.BaseNode = exports.dependencyTracked = exports.qualifiedName = exports.target = exports.dynamicProps = exports.editableProperties = void 0;
|
|
19
|
+
exports.BaseNode = exports.exclude = exports.include = exports.dependencyTracked = exports.qualifiedName = exports.target = exports.staticFields = exports.dynamicProps = exports.editableProperties = void 0;
|
|
20
20
|
const controller_1 = require("./controller");
|
|
21
21
|
const DataRefParser_1 = require("./utils/DataRefParser");
|
|
22
22
|
const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
|
|
23
|
+
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
23
24
|
/**
|
|
24
25
|
* Defines the properties that are editable. These properties can be modified during rule execution.
|
|
25
26
|
*/
|
|
@@ -37,13 +38,13 @@ exports.editableProperties = [
|
|
|
37
38
|
// 'enforceEnum', // not exposed for now
|
|
38
39
|
'exclusiveMinimum',
|
|
39
40
|
'exclusiveMaximum',
|
|
40
|
-
'maxLength',
|
|
41
|
+
// 'maxLength',
|
|
41
42
|
'maximum',
|
|
42
43
|
'maxItems',
|
|
43
|
-
'minLength',
|
|
44
|
+
// 'minLength',
|
|
44
45
|
'minimum',
|
|
45
|
-
'minItems'
|
|
46
|
-
'step'
|
|
46
|
+
'minItems'
|
|
47
|
+
// 'step'
|
|
47
48
|
// 'placeholder' // not exposed for now.
|
|
48
49
|
];
|
|
49
50
|
/**
|
|
@@ -55,6 +56,7 @@ exports.dynamicProps = [
|
|
|
55
56
|
'index',
|
|
56
57
|
'activeChild'
|
|
57
58
|
];
|
|
59
|
+
exports.staticFields = ['plain-text', 'image'];
|
|
58
60
|
/**
|
|
59
61
|
* Implementation of action with target
|
|
60
62
|
* @private
|
|
@@ -107,6 +109,29 @@ function dependencyTracked() {
|
|
|
107
109
|
};
|
|
108
110
|
}
|
|
109
111
|
exports.dependencyTracked = dependencyTracked;
|
|
112
|
+
const addOnly = (includeOrExclude) => (...fieldTypes) => (target, propertyKey, descriptor) => {
|
|
113
|
+
const get = descriptor.get;
|
|
114
|
+
if (get != undefined) {
|
|
115
|
+
descriptor.get = function () {
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
|
|
118
|
+
return get.call(this);
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const set = descriptor.set;
|
|
124
|
+
if (set != undefined) {
|
|
125
|
+
descriptor.set = function (value) {
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
|
|
128
|
+
set.call(this, value);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.include = addOnly(true);
|
|
134
|
+
exports.exclude = addOnly(false);
|
|
110
135
|
/**
|
|
111
136
|
* Defines a generic base class which all objects of form runtime model should extend from.
|
|
112
137
|
* @typeparam T type of the form object which extends from {@link BaseJson | base type}
|
|
@@ -202,7 +227,10 @@ class BaseNode {
|
|
|
202
227
|
return this._jsonModel.id;
|
|
203
228
|
}
|
|
204
229
|
get index() {
|
|
205
|
-
|
|
230
|
+
if (this.parent) {
|
|
231
|
+
return this.parent.indexOf(this);
|
|
232
|
+
}
|
|
233
|
+
return 0;
|
|
206
234
|
}
|
|
207
235
|
get parent() {
|
|
208
236
|
return this._options.parent;
|
|
@@ -210,6 +238,9 @@ class BaseNode {
|
|
|
210
238
|
get type() {
|
|
211
239
|
return this._jsonModel.type;
|
|
212
240
|
}
|
|
241
|
+
get repeatable() {
|
|
242
|
+
return (0, JsonUtils_1.isRepeatable)(this._jsonModel);
|
|
243
|
+
}
|
|
213
244
|
get fieldType() {
|
|
214
245
|
return this._jsonModel.fieldType || 'text-input';
|
|
215
246
|
}
|
|
@@ -269,7 +300,7 @@ class BaseNode {
|
|
|
269
300
|
return !this._jsonModel.name && !isNonTransparent;
|
|
270
301
|
}
|
|
271
302
|
getState() {
|
|
272
|
-
return Object.assign(Object.assign({}, this._jsonModel), { ':type': this[':type'] });
|
|
303
|
+
return Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName, events: {}, rules: {}, ':type': this[':type'] });
|
|
273
304
|
}
|
|
274
305
|
/**
|
|
275
306
|
* @private
|
|
@@ -393,8 +424,9 @@ class BaseNode {
|
|
|
393
424
|
}
|
|
394
425
|
}
|
|
395
426
|
else { // name data binding
|
|
427
|
+
// static fields do not have name bindings
|
|
396
428
|
if ( //@ts-ignore
|
|
397
|
-
contextualDataModel !== EmptyDataValue_1.default) {
|
|
429
|
+
contextualDataModel !== EmptyDataValue_1.default && exports.staticFields.indexOf(this.fieldType) === -1) {
|
|
398
430
|
_parent = contextualDataModel;
|
|
399
431
|
const name = this._jsonModel.name || '';
|
|
400
432
|
const key = contextualDataModel.$type === 'array' ? this.index : name;
|
package/lib/CheckboxGroup.js
CHANGED
|
@@ -32,6 +32,9 @@ class CheckboxGroup extends Field_1.default {
|
|
|
32
32
|
if (typeof fallbackType === 'string') {
|
|
33
33
|
return `${fallbackType}[]`;
|
|
34
34
|
}
|
|
35
|
+
else {
|
|
36
|
+
return 'string[]';
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
_getDefaults() {
|
|
37
40
|
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true, enum: [] });
|
package/lib/Container.d.ts
CHANGED
|
@@ -35,317 +35,19 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
35
35
|
* Returns the current container state
|
|
36
36
|
*/
|
|
37
37
|
getState(): T & {
|
|
38
|
+
items: any[];
|
|
39
|
+
properties: {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
};
|
|
42
|
+
index: number;
|
|
43
|
+
parent: undefined;
|
|
44
|
+
qualifiedName: any;
|
|
45
|
+
events: {};
|
|
46
|
+
rules: {};
|
|
38
47
|
':type': string;
|
|
39
|
-
items: ({
|
|
40
|
-
description?: string | undefined;
|
|
41
|
-
rules?: import("./types").Items<string> | undefined;
|
|
42
|
-
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
43
|
-
enumNames?: string[] | undefined;
|
|
44
|
-
enum?: any[] | undefined;
|
|
45
|
-
accept?: string[] | undefined;
|
|
46
|
-
enforceEnum?: boolean | undefined;
|
|
47
|
-
exclusiveMinimum?: number | undefined;
|
|
48
|
-
exclusiveMaximum?: number | undefined;
|
|
49
|
-
format?: string | undefined;
|
|
50
|
-
maxFileSize?: string | number | undefined;
|
|
51
|
-
maxLength?: number | undefined;
|
|
52
|
-
maximum?: number | undefined;
|
|
53
|
-
maxItems?: number | undefined;
|
|
54
|
-
minLength?: number | undefined;
|
|
55
|
-
minimum?: number | undefined;
|
|
56
|
-
minItems?: number | undefined;
|
|
57
|
-
pattern?: string | undefined;
|
|
58
|
-
required?: boolean | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
62
|
-
step?: number | undefined;
|
|
63
|
-
type?: string | undefined;
|
|
64
|
-
validationExpression?: string | undefined;
|
|
65
|
-
uniqueItems?: boolean | undefined;
|
|
66
|
-
dataRef?: string | null | undefined;
|
|
67
|
-
':type': string;
|
|
68
|
-
label?: import("./types").Label | undefined;
|
|
69
|
-
enabled?: boolean | undefined;
|
|
70
|
-
visible?: boolean | undefined;
|
|
71
|
-
name?: string | undefined;
|
|
72
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
73
|
-
fieldType?: string | undefined; /**
|
|
74
|
-
* Returns the current container state
|
|
75
|
-
*/
|
|
76
|
-
errorMessage?: string | undefined;
|
|
77
|
-
properties?: {
|
|
78
|
-
[key: string]: any;
|
|
79
|
-
} | undefined;
|
|
80
|
-
placeholder?: string | undefined;
|
|
81
|
-
readOnly?: boolean | undefined;
|
|
82
|
-
valid?: boolean | undefined;
|
|
83
|
-
default?: any;
|
|
84
|
-
value?: any;
|
|
85
|
-
displayFormat?: string | undefined;
|
|
86
|
-
editFormat?: string | undefined;
|
|
87
|
-
editValue?: string | undefined;
|
|
88
|
-
displayValue?: string | undefined;
|
|
89
|
-
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
90
|
-
id: string;
|
|
91
|
-
} | {
|
|
92
|
-
description?: string | undefined;
|
|
93
|
-
rules?: import("./types").Items<string> | undefined;
|
|
94
|
-
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
95
|
-
enumNames?: string[] | undefined;
|
|
96
|
-
enum?: any[] | undefined;
|
|
97
|
-
accept?: string[] | undefined;
|
|
98
|
-
enforceEnum?: boolean | undefined;
|
|
99
|
-
exclusiveMinimum?: number | undefined;
|
|
100
|
-
exclusiveMaximum?: number | undefined;
|
|
101
|
-
format?: string | undefined;
|
|
102
|
-
maxFileSize?: string | number | undefined;
|
|
103
|
-
maxLength?: number | undefined;
|
|
104
|
-
maximum?: number | undefined;
|
|
105
|
-
maxItems?: number | undefined;
|
|
106
|
-
minLength?: number | undefined;
|
|
107
|
-
minimum?: number | undefined;
|
|
108
|
-
minItems?: number | undefined;
|
|
109
|
-
pattern?: string | undefined;
|
|
110
|
-
required?: boolean | undefined;
|
|
111
|
-
/**
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
step?: number | undefined;
|
|
115
|
-
type?: "object" | "array" | undefined;
|
|
116
|
-
validationExpression?: string | undefined;
|
|
117
|
-
uniqueItems?: boolean | undefined;
|
|
118
|
-
dataRef?: string | null | undefined;
|
|
119
|
-
':type'?: string | undefined;
|
|
120
|
-
label?: import("./types").Label | undefined;
|
|
121
|
-
enabled?: boolean | undefined;
|
|
122
|
-
visible?: boolean | undefined;
|
|
123
|
-
name?: string | undefined;
|
|
124
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
125
|
-
fieldType?: string | undefined; /**
|
|
126
|
-
* Returns the current container state
|
|
127
|
-
*/
|
|
128
|
-
errorMessage?: string | undefined;
|
|
129
|
-
properties?: {
|
|
130
|
-
[key: string]: any;
|
|
131
|
-
} | undefined;
|
|
132
|
-
items: (FieldJson | ContainerJson)[] & (({
|
|
133
|
-
description?: string | undefined;
|
|
134
|
-
} & RulesJson & {
|
|
135
|
-
enumNames?: string[] | undefined;
|
|
136
|
-
enum?: any[] | undefined;
|
|
137
|
-
} & {
|
|
138
|
-
accept?: string[] | undefined;
|
|
139
|
-
enforceEnum?: boolean | undefined;
|
|
140
|
-
exclusiveMinimum?: number | undefined;
|
|
141
|
-
exclusiveMaximum?: number | undefined;
|
|
142
|
-
format?: string | undefined;
|
|
143
|
-
maxFileSize?: string | number | undefined;
|
|
144
|
-
maxLength?: number | undefined;
|
|
145
|
-
maximum?: number | undefined;
|
|
146
|
-
maxItems?: number | undefined;
|
|
147
|
-
minLength?: number | undefined;
|
|
148
|
-
minimum?: number | undefined;
|
|
149
|
-
minItems?: number | undefined;
|
|
150
|
-
pattern?: string | undefined;
|
|
151
|
-
required?: boolean | undefined;
|
|
152
|
-
/**
|
|
153
|
-
* @private
|
|
154
|
-
*/
|
|
155
|
-
step?: number | undefined;
|
|
156
|
-
type?: string | undefined;
|
|
157
|
-
validationExpression?: string | undefined;
|
|
158
|
-
uniqueItems?: boolean | undefined;
|
|
159
|
-
} & {
|
|
160
|
-
dataRef?: string | null | undefined;
|
|
161
|
-
':type'?: string | undefined;
|
|
162
|
-
label?: import("./types").Label | undefined;
|
|
163
|
-
enabled?: boolean | undefined;
|
|
164
|
-
visible?: boolean | undefined;
|
|
165
|
-
name?: string | undefined;
|
|
166
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
167
|
-
fieldType?: string | undefined; /**
|
|
168
|
-
* Returns the current container state
|
|
169
|
-
*/
|
|
170
|
-
errorMessage?: string | undefined;
|
|
171
|
-
properties?: {
|
|
172
|
-
[key: string]: any;
|
|
173
|
-
} | undefined;
|
|
174
|
-
} & {
|
|
175
|
-
placeholder?: string | undefined;
|
|
176
|
-
} & {
|
|
177
|
-
readOnly?: boolean | undefined;
|
|
178
|
-
valid?: boolean | undefined;
|
|
179
|
-
default?: any;
|
|
180
|
-
value?: any;
|
|
181
|
-
displayFormat?: string | undefined;
|
|
182
|
-
editFormat?: string | undefined;
|
|
183
|
-
editValue?: string | undefined;
|
|
184
|
-
displayValue?: string | undefined;
|
|
185
|
-
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
186
|
-
} & {
|
|
187
|
-
id: string;
|
|
188
|
-
':type': string;
|
|
189
|
-
}) | ({
|
|
190
|
-
description?: string | undefined;
|
|
191
|
-
} & RulesJson & {
|
|
192
|
-
enumNames?: string[] | undefined;
|
|
193
|
-
enum?: any[] | undefined;
|
|
194
|
-
} & {
|
|
195
|
-
accept?: string[] | undefined;
|
|
196
|
-
enforceEnum?: boolean | undefined;
|
|
197
|
-
exclusiveMinimum?: number | undefined;
|
|
198
|
-
exclusiveMaximum?: number | undefined;
|
|
199
|
-
format?: string | undefined;
|
|
200
|
-
maxFileSize?: string | number | undefined;
|
|
201
|
-
maxLength?: number | undefined;
|
|
202
|
-
maximum?: number | undefined;
|
|
203
|
-
maxItems?: number | undefined;
|
|
204
|
-
minLength?: number | undefined;
|
|
205
|
-
minimum?: number | undefined;
|
|
206
|
-
minItems?: number | undefined;
|
|
207
|
-
pattern?: string | undefined;
|
|
208
|
-
required?: boolean | undefined;
|
|
209
|
-
/**
|
|
210
|
-
* @private
|
|
211
|
-
*/
|
|
212
|
-
step?: number | undefined;
|
|
213
|
-
type?: string | undefined;
|
|
214
|
-
validationExpression?: string | undefined;
|
|
215
|
-
uniqueItems?: boolean | undefined;
|
|
216
|
-
} & {
|
|
217
|
-
dataRef?: string | null | undefined;
|
|
218
|
-
':type'?: string | undefined;
|
|
219
|
-
label?: import("./types").Label | undefined;
|
|
220
|
-
enabled?: boolean | undefined;
|
|
221
|
-
visible?: boolean | undefined;
|
|
222
|
-
name?: string | undefined;
|
|
223
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
224
|
-
fieldType?: string | undefined; /**
|
|
225
|
-
* Returns the current container state
|
|
226
|
-
*/
|
|
227
|
-
errorMessage?: string | undefined;
|
|
228
|
-
properties?: {
|
|
229
|
-
[key: string]: any;
|
|
230
|
-
} | undefined;
|
|
231
|
-
} & {
|
|
232
|
-
items: (FieldJson | ContainerJson)[];
|
|
233
|
-
initialItems?: number | undefined;
|
|
234
|
-
activeChild?: string | undefined;
|
|
235
|
-
} & {
|
|
236
|
-
id: string;
|
|
237
|
-
items: (({
|
|
238
|
-
description?: string | undefined;
|
|
239
|
-
} & 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
|
-
/**
|
|
258
|
-
* @private
|
|
259
|
-
*/
|
|
260
|
-
step?: number | undefined;
|
|
261
|
-
type?: string | undefined;
|
|
262
|
-
validationExpression?: string | undefined;
|
|
263
|
-
uniqueItems?: boolean | undefined;
|
|
264
|
-
} & {
|
|
265
|
-
dataRef?: string | null | undefined;
|
|
266
|
-
':type'?: string | undefined;
|
|
267
|
-
label?: import("./types").Label | undefined;
|
|
268
|
-
enabled?: boolean | undefined;
|
|
269
|
-
visible?: boolean | undefined;
|
|
270
|
-
name?: string | undefined;
|
|
271
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
272
|
-
fieldType?: string | undefined; /**
|
|
273
|
-
* Returns the current container state
|
|
274
|
-
*/
|
|
275
|
-
errorMessage?: string | undefined;
|
|
276
|
-
properties?: {
|
|
277
|
-
[key: string]: any;
|
|
278
|
-
} | undefined;
|
|
279
|
-
} & {
|
|
280
|
-
placeholder?: string | undefined;
|
|
281
|
-
} & {
|
|
282
|
-
readOnly?: boolean | undefined;
|
|
283
|
-
valid?: boolean | undefined;
|
|
284
|
-
default?: any;
|
|
285
|
-
value?: any;
|
|
286
|
-
displayFormat?: string | undefined;
|
|
287
|
-
editFormat?: string | undefined;
|
|
288
|
-
editValue?: string | undefined;
|
|
289
|
-
displayValue?: string | undefined;
|
|
290
|
-
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
291
|
-
} & {
|
|
292
|
-
id: string;
|
|
293
|
-
':type': string;
|
|
294
|
-
}) | ({
|
|
295
|
-
description?: string | undefined;
|
|
296
|
-
} & RulesJson & {
|
|
297
|
-
enumNames?: string[] | undefined;
|
|
298
|
-
enum?: any[] | undefined;
|
|
299
|
-
} & {
|
|
300
|
-
accept?: string[] | undefined;
|
|
301
|
-
enforceEnum?: boolean | undefined;
|
|
302
|
-
exclusiveMinimum?: number | undefined;
|
|
303
|
-
exclusiveMaximum?: number | undefined;
|
|
304
|
-
format?: string | undefined;
|
|
305
|
-
maxFileSize?: string | number | undefined;
|
|
306
|
-
maxLength?: number | undefined;
|
|
307
|
-
maximum?: number | undefined;
|
|
308
|
-
maxItems?: number | undefined;
|
|
309
|
-
minLength?: number | undefined;
|
|
310
|
-
minimum?: number | undefined;
|
|
311
|
-
minItems?: number | undefined;
|
|
312
|
-
pattern?: string | undefined;
|
|
313
|
-
required?: boolean | undefined;
|
|
314
|
-
/**
|
|
315
|
-
* @private
|
|
316
|
-
*/
|
|
317
|
-
step?: number | undefined;
|
|
318
|
-
type?: string | undefined;
|
|
319
|
-
validationExpression?: string | undefined;
|
|
320
|
-
uniqueItems?: boolean | undefined;
|
|
321
|
-
} & {
|
|
322
|
-
dataRef?: string | null | undefined;
|
|
323
|
-
':type'?: string | undefined;
|
|
324
|
-
label?: import("./types").Label | undefined;
|
|
325
|
-
enabled?: boolean | undefined;
|
|
326
|
-
visible?: boolean | undefined;
|
|
327
|
-
name?: string | undefined;
|
|
328
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
329
|
-
fieldType?: string | undefined; /**
|
|
330
|
-
* Returns the current container state
|
|
331
|
-
*/
|
|
332
|
-
errorMessage?: string | undefined;
|
|
333
|
-
properties?: {
|
|
334
|
-
[key: string]: any;
|
|
335
|
-
} | undefined;
|
|
336
|
-
} & {
|
|
337
|
-
items: (FieldJson | ContainerJson)[];
|
|
338
|
-
initialItems?: number | undefined;
|
|
339
|
-
activeChild?: string | undefined;
|
|
340
|
-
} & any))[];
|
|
341
|
-
}))[];
|
|
342
|
-
initialItems?: number | undefined;
|
|
343
|
-
activeChild?: string | undefined;
|
|
344
|
-
id: string;
|
|
345
|
-
})[];
|
|
346
48
|
id: string;
|
|
347
49
|
};
|
|
348
|
-
protected abstract _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
|
|
50
|
+
protected abstract _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
|
|
349
51
|
private _addChildToRuleNode;
|
|
350
52
|
private _addChild;
|
|
351
53
|
indexOf(f: FieldModel | FieldsetModel): number;
|
|
@@ -369,6 +71,12 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
369
71
|
* @private
|
|
370
72
|
*/
|
|
371
73
|
queueEvent(action: Action): void;
|
|
74
|
+
/**
|
|
75
|
+
* @summary reset the data of all the Fields present inside this container
|
|
76
|
+
* @method reset
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
reset(): void;
|
|
372
80
|
validate(): import("./types").ValidationError[];
|
|
373
81
|
/**
|
|
374
82
|
* @private
|
package/lib/Container.js
CHANGED
|
@@ -75,7 +75,7 @@ class Container extends Scriptable_1.default {
|
|
|
75
75
|
* Returns the current container state
|
|
76
76
|
*/
|
|
77
77
|
getState() {
|
|
78
|
-
return Object.assign(Object.assign({},
|
|
78
|
+
return Object.assign(Object.assign({}, super.getState()), { items: this._children.map(x => {
|
|
79
79
|
return Object.assign({}, x.getState());
|
|
80
80
|
}) });
|
|
81
81
|
}
|
|
@@ -154,7 +154,7 @@ class Container extends Scriptable_1.default {
|
|
|
154
154
|
*/
|
|
155
155
|
_initialize() {
|
|
156
156
|
super._initialize();
|
|
157
|
-
const items = this._jsonModel.items;
|
|
157
|
+
const items = this._jsonModel.items || [];
|
|
158
158
|
this._jsonModel.items = [];
|
|
159
159
|
this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
|
|
160
160
|
if (this._jsonModel.type == 'array' && items.length === 1 && this.getDataNode() != null) {
|
|
@@ -183,30 +183,33 @@ class Container extends Scriptable_1.default {
|
|
|
183
183
|
this._jsonModel.maxItems = this._children.length;
|
|
184
184
|
this._jsonModel.initialItems = this._children.length;
|
|
185
185
|
}
|
|
186
|
+
else {
|
|
187
|
+
this.form.logger.warn('A container exists with no items.');
|
|
188
|
+
}
|
|
186
189
|
this.setupRuleNode();
|
|
187
190
|
}
|
|
188
191
|
/**
|
|
189
192
|
* @private
|
|
190
193
|
*/
|
|
191
194
|
addItem(action) {
|
|
192
|
-
if (action.type === 'addItem' && this._itemTemplate != null) {
|
|
195
|
+
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
193
196
|
//@ts-ignore
|
|
194
197
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
195
198
|
const dataNode = this.getDataNode();
|
|
196
|
-
let
|
|
197
|
-
if (typeof index !== 'number' || index > this._children.length) {
|
|
198
|
-
index = this._children.length;
|
|
199
|
-
}
|
|
199
|
+
let instanceIndex = action.payload;
|
|
200
200
|
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
201
|
-
|
|
201
|
+
if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
|
|
202
|
+
instanceIndex = this._children.length;
|
|
203
|
+
}
|
|
204
|
+
const _data = retVal.defaultDataModel(instanceIndex);
|
|
202
205
|
if (_data) {
|
|
203
|
-
dataNode.$addDataNode(
|
|
206
|
+
dataNode.$addDataNode(instanceIndex, _data);
|
|
204
207
|
}
|
|
205
208
|
retVal._initialize();
|
|
206
|
-
this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState, null));
|
|
209
|
+
this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState(), null));
|
|
207
210
|
retVal.dispatch(new controller_1.Initialize());
|
|
208
211
|
retVal.dispatch(new controller_1.ExecuteRule());
|
|
209
|
-
for (let i =
|
|
212
|
+
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
210
213
|
this._children[i].dispatch(new controller_1.ExecuteRule());
|
|
211
214
|
}
|
|
212
215
|
}
|
|
@@ -216,21 +219,24 @@ class Container extends Scriptable_1.default {
|
|
|
216
219
|
* @private
|
|
217
220
|
*/
|
|
218
221
|
removeItem(action) {
|
|
219
|
-
if (action.type === 'removeItem' && this._itemTemplate != null) {
|
|
222
|
+
if ((action.type === 'removeItem' || action.type == 'removeInstance') && this._itemTemplate != null) {
|
|
220
223
|
if (this._children.length == 0) {
|
|
221
224
|
//can't remove item if there isn't any
|
|
222
225
|
return;
|
|
223
226
|
}
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
let instanceIndex = action.payload;
|
|
228
|
+
if (typeof instanceIndex !== 'number') {
|
|
229
|
+
instanceIndex = this._children.length - 1;
|
|
230
|
+
}
|
|
231
|
+
const state = this._children[instanceIndex].getState();
|
|
226
232
|
//@ts-ignore
|
|
227
233
|
if (this._children.length > this._jsonModel.minItems) {
|
|
228
234
|
// clear child
|
|
229
235
|
//remove field
|
|
230
236
|
this._childrenReference.pop();
|
|
231
|
-
this._children.splice(
|
|
232
|
-
this.getDataNode().$removeDataNode(
|
|
233
|
-
for (let i =
|
|
237
|
+
this._children.splice(instanceIndex, 1);
|
|
238
|
+
this.getDataNode().$removeDataNode(instanceIndex);
|
|
239
|
+
for (let i = instanceIndex; i < this._children.length; i++) {
|
|
234
240
|
this._children[i].dispatch(new controller_1.ExecuteRule());
|
|
235
241
|
}
|
|
236
242
|
this.notifyDependents((0, controller_1.propertyChange)('items', null, state));
|
|
@@ -250,6 +256,17 @@ class Container extends Scriptable_1.default {
|
|
|
250
256
|
});
|
|
251
257
|
}
|
|
252
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* @summary reset the data of all the Fields present inside this container
|
|
261
|
+
* @method reset
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
reset() {
|
|
265
|
+
this.items.forEach(x => {
|
|
266
|
+
//@ts-ignore
|
|
267
|
+
x.reset();
|
|
268
|
+
});
|
|
269
|
+
}
|
|
253
270
|
validate() {
|
|
254
271
|
return this.items.flatMap(x => {
|
|
255
272
|
return x.validate();
|