@aemforms/af-core 0.22.19 → 0.22.20
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/browser/afb-events.js +151 -0
- package/lib/browser/afb-runtime.js +3620 -0
- package/lib/cjs/index.cjs +8886 -0
- package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
- package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
- package/lib/esm/Checkbox.d.ts +79 -0
- package/lib/esm/Checkbox.js +27 -0
- package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
- package/lib/esm/CheckboxGroup.js +23 -0
- package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
- package/lib/{Container.js → esm/Container.js} +54 -116
- package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
- package/lib/esm/DateField.js +21 -0
- package/lib/{Field.d.ts → esm/Field.d.ts} +39 -104
- package/lib/{Field.js → esm/Field.js} +142 -208
- package/lib/esm/Fieldset.d.ts +16 -0
- package/lib/esm/Fieldset.js +45 -0
- package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
- package/lib/esm/FileObject.js +26 -0
- package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
- package/lib/esm/FileUpload.js +108 -0
- package/lib/{Form.d.ts → esm/Form.d.ts} +19 -85
- package/lib/esm/Form.js +176 -0
- package/lib/esm/FormInstance.d.ts +13 -0
- package/lib/esm/FormInstance.js +81 -0
- package/lib/esm/FormMetaData.d.ts +7 -0
- package/lib/esm/FormMetaData.js +10 -0
- package/lib/esm/InstanceManager.d.ts +9 -0
- package/lib/esm/InstanceManager.js +31 -0
- package/lib/esm/Node.d.ts +7 -0
- package/lib/esm/Node.js +16 -0
- package/lib/esm/Scriptable.d.ts +17 -0
- package/lib/{Scriptable.js → esm/Scriptable.js} +11 -54
- package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
- package/lib/{controller → esm/controller}/EventQueue.js +10 -26
- package/lib/esm/controller/Events.d.ts +85 -0
- package/lib/esm/controller/Events.js +149 -0
- package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
- package/lib/{controller → esm/controller}/Logger.js +5 -11
- package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
- package/lib/{data → esm/data}/DataGroup.js +15 -34
- package/lib/{data → esm/data}/DataValue.d.ts +1 -7
- package/lib/esm/data/DataValue.js +46 -0
- package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
- package/lib/esm/data/EmptyDataValue.js +29 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
- package/lib/{rules → esm/rules}/FunctionRuntime.js +41 -117
- package/lib/esm/rules/RuleEngine.d.ts +12 -0
- package/lib/esm/rules/RuleEngine.js +47 -0
- package/lib/{types → esm/types}/Json.d.ts +3 -22
- package/lib/esm/types/Json.js +7 -0
- package/lib/esm/types/Model.d.ts +131 -0
- package/lib/esm/types/Model.js +8 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
- package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
- package/lib/{utils → esm/utils}/Fetch.d.ts +0 -6
- package/lib/esm/utils/Fetch.js +61 -0
- package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
- package/lib/esm/utils/FormCreationUtils.js +74 -0
- package/lib/esm/utils/FormUtils.d.ts +12 -0
- package/lib/esm/utils/FormUtils.js +187 -0
- package/lib/esm/utils/JsonUtils.d.ts +11 -0
- package/lib/esm/utils/JsonUtils.js +76 -0
- package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
- package/lib/esm/utils/LogUtils.js +6 -0
- package/lib/esm/utils/SchemaUtils.d.ts +3 -0
- package/lib/esm/utils/SchemaUtils.js +71 -0
- package/lib/esm/utils/TranslationUtils.d.ts +11 -0
- package/lib/esm/utils/TranslationUtils.js +115 -0
- package/lib/esm/utils/ValidationUtils.d.ts +19 -0
- package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
- package/package.json +17 -10
- package/lib/Checkbox.d.ts +0 -88
- package/lib/Checkbox.js +0 -49
- package/lib/CheckboxGroup.js +0 -43
- package/lib/DateField.js +0 -35
- package/lib/Fieldset.d.ts +0 -24
- package/lib/Fieldset.js +0 -74
- package/lib/FileObject.js +0 -39
- package/lib/FileUpload.js +0 -155
- package/lib/Form.js +0 -252
- package/lib/FormInstance.d.ts +0 -38
- package/lib/FormInstance.js +0 -127
- package/lib/FormMetaData.d.ts +0 -11
- package/lib/FormMetaData.js +0 -28
- package/lib/InstanceManager.d.ts +0 -16
- package/lib/InstanceManager.js +0 -53
- package/lib/Node.d.ts +0 -12
- package/lib/Node.js +0 -27
- package/lib/Scriptable.d.ts +0 -31
- package/lib/controller/Controller.d.ts +0 -255
- package/lib/controller/Controller.js +0 -328
- package/lib/controller/index.d.ts +0 -1
- package/lib/controller/index.js +0 -24
- package/lib/data/DataValue.js +0 -56
- package/lib/data/EmptyDataValue.js +0 -46
- package/lib/index.d.ts +0 -28
- package/lib/index.js +0 -63
- package/lib/rules/RuleEngine.d.ts +0 -23
- package/lib/rules/RuleEngine.js +0 -62
- package/lib/types/Json.js +0 -19
- package/lib/types/Model.d.ts +0 -393
- package/lib/types/Model.js +0 -20
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -25
- package/lib/utils/Fetch.js +0 -87
- package/lib/utils/FormCreationUtils.d.ts +0 -11
- package/lib/utils/FormCreationUtils.js +0 -83
- package/lib/utils/FormUtils.d.ts +0 -47
- package/lib/utils/FormUtils.js +0 -257
- package/lib/utils/JsonUtils.d.ts +0 -63
- package/lib/utils/JsonUtils.js +0 -157
- package/lib/utils/LogUtils.js +0 -17
- package/lib/utils/SchemaUtils.d.ts +0 -16
- package/lib/utils/SchemaUtils.js +0 -92
- package/lib/utils/TranslationUtils.d.ts +0 -41
- package/lib/utils/TranslationUtils.js +0 -185
- package/lib/utils/ValidationUtils.d.ts +0 -170
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
declare class Checkbox extends Field {
|
|
3
|
+
private offValue;
|
|
4
|
+
_getConstraintObject(): {
|
|
5
|
+
enum: (constraint: any, inputVal: any) => {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
value: any;
|
|
8
|
+
};
|
|
9
|
+
accept: (constraint: any, inputVal: any) => {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
value: any;
|
|
12
|
+
};
|
|
13
|
+
exclusiveMinimum: (constraint: any, inputVal: any) => {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
value: any;
|
|
16
|
+
};
|
|
17
|
+
exclusiveMaximum: (constraint: any, inputVal: any) => {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
value: any;
|
|
20
|
+
};
|
|
21
|
+
format: (constraint: any, inputVal: any) => {
|
|
22
|
+
valid: boolean;
|
|
23
|
+
value: any;
|
|
24
|
+
};
|
|
25
|
+
maxFileSize: (constraint: any, inputVal: any) => {
|
|
26
|
+
valid: boolean;
|
|
27
|
+
value: any;
|
|
28
|
+
};
|
|
29
|
+
maxLength: (constraint: any, inputVal: any) => {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
value: any;
|
|
32
|
+
};
|
|
33
|
+
maximum: (constraint: any, inputVal: any) => {
|
|
34
|
+
valid: boolean;
|
|
35
|
+
value: any;
|
|
36
|
+
};
|
|
37
|
+
maxItems: (constraint: any, inputVal: any) => {
|
|
38
|
+
valid: boolean;
|
|
39
|
+
value: any;
|
|
40
|
+
};
|
|
41
|
+
minLength: (constraint: any, inputVal: any) => {
|
|
42
|
+
valid: boolean;
|
|
43
|
+
value: any;
|
|
44
|
+
};
|
|
45
|
+
minimum: (constraint: any, inputVal: any) => {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
value: any;
|
|
48
|
+
};
|
|
49
|
+
minItems: (constraint: any, inputVal: any) => {
|
|
50
|
+
valid: boolean;
|
|
51
|
+
value: any;
|
|
52
|
+
};
|
|
53
|
+
pattern: (constraint: any, inputVal: any) => {
|
|
54
|
+
valid: boolean;
|
|
55
|
+
value: any;
|
|
56
|
+
};
|
|
57
|
+
required: (constraint: any, inputVal: any) => {
|
|
58
|
+
valid: boolean;
|
|
59
|
+
value: any;
|
|
60
|
+
};
|
|
61
|
+
type: (constraint: any, inputVal: any) => {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
value: any;
|
|
64
|
+
};
|
|
65
|
+
uniqueItems: (constraint: any, inputVal: any) => {
|
|
66
|
+
valid: boolean;
|
|
67
|
+
value: any;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
protected _getDefaults(): {
|
|
71
|
+
enforceEnum: boolean;
|
|
72
|
+
readOnly: boolean;
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
visible: boolean;
|
|
75
|
+
type: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
get enum(): any[];
|
|
78
|
+
}
|
|
79
|
+
export default Checkbox;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
import { Constraints } from './utils/ValidationUtils.js';
|
|
3
|
+
const requiredConstraint = (offValue) => (constraint, value) => {
|
|
4
|
+
const valid = Constraints.required(constraint, value).valid && (!constraint || value != offValue);
|
|
5
|
+
return { valid, value };
|
|
6
|
+
};
|
|
7
|
+
class Checkbox extends Field {
|
|
8
|
+
offValue() {
|
|
9
|
+
const opts = this.enum;
|
|
10
|
+
return opts.length > 1 ? opts[1] : null;
|
|
11
|
+
}
|
|
12
|
+
_getConstraintObject() {
|
|
13
|
+
const baseConstraints = { ...super._getConstraintObject() };
|
|
14
|
+
baseConstraints.required = requiredConstraint(this.offValue());
|
|
15
|
+
return baseConstraints;
|
|
16
|
+
}
|
|
17
|
+
_getDefaults() {
|
|
18
|
+
return {
|
|
19
|
+
...super._getDefaults(),
|
|
20
|
+
enforceEnum: true
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
get enum() {
|
|
24
|
+
return this._jsonModel.enum || [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default Checkbox;
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
import Field from './Field';
|
|
2
|
-
import { ContainerModel, FieldJson, FormModel } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Implementation of CheckBoxGroup runtime model which extends from {@link Field | field}
|
|
5
|
-
*/
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
import { ContainerModel, FieldJson, FormModel } from './types/index.js';
|
|
6
3
|
declare class CheckboxGroup extends Field {
|
|
7
|
-
/**
|
|
8
|
-
* @param params
|
|
9
|
-
* @param _options
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
4
|
constructor(params: FieldJson, _options: {
|
|
13
5
|
form: FormModel;
|
|
14
6
|
parent: ContainerModel;
|
|
15
7
|
});
|
|
16
|
-
/**
|
|
17
|
-
* converts the fallback type, if required, to an array. Since checkbox-group has an array type
|
|
18
|
-
* @protected
|
|
19
|
-
*/
|
|
20
8
|
protected _getFallbackType(): string | undefined;
|
|
21
9
|
protected _getDefaults(): {
|
|
22
10
|
enforceEnum: boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
class CheckboxGroup extends Field {
|
|
3
|
+
constructor(params, _options) {
|
|
4
|
+
super(params, _options);
|
|
5
|
+
}
|
|
6
|
+
_getFallbackType() {
|
|
7
|
+
const fallbackType = super._getFallbackType();
|
|
8
|
+
if (typeof fallbackType === 'string') {
|
|
9
|
+
return `${fallbackType}[]`;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return 'string[]';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
_getDefaults() {
|
|
16
|
+
return {
|
|
17
|
+
...super._getDefaults(),
|
|
18
|
+
enforceEnum: true,
|
|
19
|
+
enum: []
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export default CheckboxGroup;
|
|
@@ -1,39 +1,24 @@
|
|
|
1
|
-
import { Action, BaseModel, ContainerJson, ContainerModel,
|
|
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
|
-
*/
|
|
1
|
+
import { Action, BaseModel, ContainerJson, ContainerModel, FieldModel, FieldsetModel, FormModel, IFormFieldFactory, RulesJson } from './types/index.js';
|
|
2
|
+
import Scriptable from './Scriptable.js';
|
|
3
|
+
import DataGroup from './data/DataGroup.js';
|
|
8
4
|
declare abstract class Container<T extends ContainerJson & RulesJson> extends Scriptable<T> implements ContainerModel {
|
|
9
5
|
protected _children: Array<FieldModel | FieldsetModel>;
|
|
10
6
|
protected _childrenReference: any;
|
|
11
7
|
private _itemTemplate;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
8
|
+
private fieldFactory;
|
|
9
|
+
constructor(json: T, _options: {
|
|
10
|
+
form: FormModel;
|
|
11
|
+
parent: ContainerModel;
|
|
12
|
+
fieldFactory: IFormFieldFactory;
|
|
13
|
+
});
|
|
23
14
|
ruleNodeReference(): any;
|
|
24
15
|
get items(): (FieldModel | FieldsetModel)[];
|
|
25
16
|
get maxItems(): number;
|
|
26
17
|
set maxItems(m: number);
|
|
27
18
|
get minItems(): number;
|
|
28
|
-
/**
|
|
29
|
-
* returns whether the items in the Panel can repeat or not
|
|
30
|
-
*/
|
|
31
19
|
hasDynamicItems(): boolean;
|
|
32
20
|
get isContainer(): boolean;
|
|
33
21
|
private _activeChild;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the current container state
|
|
36
|
-
*/
|
|
37
22
|
getState(): T & {
|
|
38
23
|
items: any[];
|
|
39
24
|
properties: {
|
|
@@ -44,55 +29,23 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
44
29
|
qualifiedName: any;
|
|
45
30
|
events: {};
|
|
46
31
|
rules: {};
|
|
32
|
+
repeatable: boolean | undefined;
|
|
47
33
|
':type': string;
|
|
48
34
|
id: string;
|
|
49
35
|
};
|
|
50
|
-
|
|
36
|
+
private _createChild;
|
|
51
37
|
private _addChildToRuleNode;
|
|
52
38
|
private _addChild;
|
|
53
39
|
indexOf(f: FieldModel | FieldsetModel): number;
|
|
54
|
-
/**
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
40
|
defaultDataModel(name: string): DataGroup | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
41
|
_initialize(): void;
|
|
62
|
-
/**
|
|
63
|
-
* @private
|
|
64
|
-
*/
|
|
65
42
|
addItem(action: Action): void;
|
|
66
|
-
/**
|
|
67
|
-
* @private
|
|
68
|
-
*/
|
|
69
43
|
removeItem(action: Action): void;
|
|
70
|
-
/**
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
44
|
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
45
|
reset(): void;
|
|
80
|
-
validate(): import("./types").ValidationError[];
|
|
81
|
-
/**
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
46
|
+
validate(): import("./types/Model.js").ValidationError[];
|
|
84
47
|
dispatch(action: Action): void;
|
|
85
|
-
/**
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
48
|
importData(contextualDataModel: DataGroup): void;
|
|
89
|
-
/**
|
|
90
|
-
* prefill the form with data on the given element
|
|
91
|
-
* @param dataModel
|
|
92
|
-
* @param contextualDataModel
|
|
93
|
-
* @param operation
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
96
49
|
syncDataAndFormModel(contextualDataModel?: DataGroup): void;
|
|
97
50
|
get activeChild(): BaseModel | null;
|
|
98
51
|
set activeChild(c: BaseModel | null);
|
|
@@ -1,44 +1,26 @@
|
|
|
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
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
6
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class Container extends Scriptable_1.default {
|
|
29
|
-
constructor() {
|
|
30
|
-
super(...arguments);
|
|
31
|
-
this._children = [];
|
|
32
|
-
this._itemTemplate = null;
|
|
33
|
-
this._activeChild = null;
|
|
7
|
+
import { deepClone } from './utils/JsonUtils.js';
|
|
8
|
+
import Scriptable from './Scriptable.js';
|
|
9
|
+
import { ExecuteRule, Initialize, propertyChange } from './controller/Events.js';
|
|
10
|
+
import DataGroup from './data/DataGroup.js';
|
|
11
|
+
import { dependencyTracked } from './BaseNode.js';
|
|
12
|
+
class Container extends Scriptable {
|
|
13
|
+
_children = [];
|
|
14
|
+
_childrenReference;
|
|
15
|
+
_itemTemplate = null;
|
|
16
|
+
fieldFactory;
|
|
17
|
+
constructor(json, _options) {
|
|
18
|
+
super(json, { form: _options.form, parent: _options.parent });
|
|
19
|
+
this.fieldFactory = _options.fieldFactory;
|
|
34
20
|
}
|
|
35
|
-
/**
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
21
|
ruleNodeReference() {
|
|
39
22
|
return this._childrenReference;
|
|
40
23
|
}
|
|
41
|
-
//todo : this should not be public
|
|
42
24
|
get items() {
|
|
43
25
|
return this._children;
|
|
44
26
|
}
|
|
@@ -56,46 +38,47 @@ class Container extends Scriptable_1.default {
|
|
|
56
38
|
this._childrenReference.pop();
|
|
57
39
|
}
|
|
58
40
|
const elems = this._children.splice(m, items2Remove);
|
|
59
|
-
this.notifyDependents(
|
|
41
|
+
this.notifyDependents(propertyChange('items', elems, null));
|
|
60
42
|
}
|
|
61
43
|
}
|
|
62
44
|
get minItems() {
|
|
63
45
|
return this._jsonModel.minItems;
|
|
64
46
|
}
|
|
65
|
-
/**
|
|
66
|
-
* returns whether the items in the Panel can repeat or not
|
|
67
|
-
*/
|
|
68
47
|
hasDynamicItems() {
|
|
69
48
|
return this._itemTemplate != null;
|
|
70
49
|
}
|
|
71
50
|
get isContainer() {
|
|
72
51
|
return true;
|
|
73
52
|
}
|
|
74
|
-
|
|
75
|
-
* Returns the current container state
|
|
76
|
-
*/
|
|
53
|
+
_activeChild = null;
|
|
77
54
|
getState() {
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
55
|
+
return {
|
|
56
|
+
...super.getState(),
|
|
57
|
+
items: this._children.map(x => {
|
|
58
|
+
return { ...x.getState() };
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
_createChild(child, options) {
|
|
63
|
+
const { parent = this } = options;
|
|
64
|
+
return this.fieldFactory.createField(child, {
|
|
65
|
+
form: options.form,
|
|
66
|
+
parent
|
|
67
|
+
});
|
|
81
68
|
}
|
|
82
69
|
_addChildToRuleNode(child, options) {
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
84
70
|
const self = this;
|
|
85
71
|
const { parent = this } = options;
|
|
86
|
-
//the child has not been added to the array, hence using the length as new index
|
|
87
|
-
// this means unnamed panel inside repeatable named parent // this is an edge case, handling it gracefully
|
|
88
|
-
// todo: rules don't work inside repeatable array
|
|
89
72
|
const name = parent.type == 'array' ? parent._children.length + '' : child.name || '';
|
|
90
73
|
if (name.length > 0) {
|
|
91
74
|
Object.defineProperty(parent._childrenReference, name, {
|
|
92
75
|
get: () => {
|
|
93
76
|
if (child.isContainer && child.hasDynamicItems()) {
|
|
94
|
-
self.ruleEngine.trackDependency(child);
|
|
77
|
+
self.ruleEngine.trackDependency(child);
|
|
95
78
|
}
|
|
96
79
|
if (self.hasDynamicItems()) {
|
|
97
|
-
self.ruleEngine.trackDependency(self);
|
|
98
|
-
if (this._children[name] !== undefined) {
|
|
80
|
+
self.ruleEngine.trackDependency(self);
|
|
81
|
+
if (this._children[name] !== undefined) {
|
|
99
82
|
return this._children[name].getRuleNode();
|
|
100
83
|
}
|
|
101
84
|
}
|
|
@@ -109,26 +92,25 @@ class Container extends Scriptable_1.default {
|
|
|
109
92
|
}
|
|
110
93
|
}
|
|
111
94
|
_addChild(itemJson, index, cloneIds = false) {
|
|
112
|
-
// get first non transparent parent
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
114
95
|
let nonTransparentParent = this;
|
|
115
96
|
while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
|
|
116
|
-
// @ts-ignore
|
|
117
97
|
nonTransparentParent = nonTransparentParent.parent;
|
|
118
98
|
}
|
|
119
99
|
if (typeof index !== 'number' || index > nonTransparentParent._children.length) {
|
|
120
100
|
index = this._children.length;
|
|
121
101
|
}
|
|
122
102
|
const form = this.form;
|
|
123
|
-
const itemTemplate =
|
|
124
|
-
|
|
125
|
-
|
|
103
|
+
const itemTemplate = {
|
|
104
|
+
index,
|
|
105
|
+
...deepClone(itemJson, cloneIds ? () => { return form.getUniqueId(); } : undefined)
|
|
106
|
+
};
|
|
107
|
+
const retVal = this._createChild(itemTemplate, { parent: this, form: this.form });
|
|
108
|
+
this.form.fieldAdded(retVal);
|
|
126
109
|
this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
|
|
127
110
|
if (index === this._children.length) {
|
|
128
111
|
this._children.push(retVal);
|
|
129
112
|
}
|
|
130
113
|
else {
|
|
131
|
-
// @ts-ignore
|
|
132
114
|
this._children.splice(index, 0, retVal);
|
|
133
115
|
}
|
|
134
116
|
return retVal;
|
|
@@ -136,9 +118,6 @@ class Container extends Scriptable_1.default {
|
|
|
136
118
|
indexOf(f) {
|
|
137
119
|
return this._children.indexOf(f);
|
|
138
120
|
}
|
|
139
|
-
/**
|
|
140
|
-
* @private
|
|
141
|
-
*/
|
|
142
121
|
defaultDataModel(name) {
|
|
143
122
|
const type = this._jsonModel.type || undefined;
|
|
144
123
|
if (type === undefined) {
|
|
@@ -146,19 +125,16 @@ class Container extends Scriptable_1.default {
|
|
|
146
125
|
}
|
|
147
126
|
else {
|
|
148
127
|
const instance = type === 'array' ? [] : {};
|
|
149
|
-
return new
|
|
128
|
+
return new DataGroup(name, instance, type);
|
|
150
129
|
}
|
|
151
130
|
}
|
|
152
|
-
/**
|
|
153
|
-
* @private
|
|
154
|
-
*/
|
|
155
131
|
_initialize() {
|
|
156
132
|
super._initialize();
|
|
157
133
|
const items = this._jsonModel.items || [];
|
|
158
134
|
this._jsonModel.items = [];
|
|
159
135
|
this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
|
|
160
136
|
if (this._jsonModel.type == 'array' && items.length === 1 && this.getDataNode() != null) {
|
|
161
|
-
this._itemTemplate =
|
|
137
|
+
this._itemTemplate = deepClone(items[0]);
|
|
162
138
|
if (typeof (this._jsonModel.minItems) !== 'number') {
|
|
163
139
|
this._jsonModel.minItems = 0;
|
|
164
140
|
}
|
|
@@ -169,7 +145,6 @@ class Container extends Scriptable_1.default {
|
|
|
169
145
|
this._jsonModel.initialItems = Math.max(1, this._jsonModel.minItems);
|
|
170
146
|
}
|
|
171
147
|
for (let i = 0; i < this._jsonModel.initialItems; i++) {
|
|
172
|
-
//@ts-ignore
|
|
173
148
|
const child = this._addChild(this._itemTemplate);
|
|
174
149
|
child._initialize();
|
|
175
150
|
}
|
|
@@ -188,12 +163,8 @@ class Container extends Scriptable_1.default {
|
|
|
188
163
|
}
|
|
189
164
|
this.setupRuleNode();
|
|
190
165
|
}
|
|
191
|
-
/**
|
|
192
|
-
* @private
|
|
193
|
-
*/
|
|
194
166
|
addItem(action) {
|
|
195
167
|
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
196
|
-
//@ts-ignore
|
|
197
168
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
198
169
|
const dataNode = this.getDataNode();
|
|
199
170
|
let instanceIndex = action.payload;
|
|
@@ -206,22 +177,18 @@ class Container extends Scriptable_1.default {
|
|
|
206
177
|
dataNode.$addDataNode(instanceIndex, _data);
|
|
207
178
|
}
|
|
208
179
|
retVal._initialize();
|
|
209
|
-
this.notifyDependents(
|
|
210
|
-
retVal.dispatch(new
|
|
211
|
-
retVal.dispatch(new
|
|
180
|
+
this.notifyDependents(propertyChange('items', retVal.getState(), null));
|
|
181
|
+
retVal.dispatch(new Initialize());
|
|
182
|
+
retVal.dispatch(new ExecuteRule());
|
|
212
183
|
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
213
|
-
this._children[i].dispatch(new
|
|
184
|
+
this._children[i].dispatch(new ExecuteRule());
|
|
214
185
|
}
|
|
215
186
|
}
|
|
216
187
|
}
|
|
217
188
|
}
|
|
218
|
-
/**
|
|
219
|
-
* @private
|
|
220
|
-
*/
|
|
221
189
|
removeItem(action) {
|
|
222
190
|
if ((action.type === 'removeItem' || action.type == 'removeInstance') && this._itemTemplate != null) {
|
|
223
191
|
if (this._children.length == 0) {
|
|
224
|
-
//can't remove item if there isn't any
|
|
225
192
|
return;
|
|
226
193
|
}
|
|
227
194
|
let instanceIndex = action.payload;
|
|
@@ -229,41 +196,27 @@ class Container extends Scriptable_1.default {
|
|
|
229
196
|
instanceIndex = this._children.length - 1;
|
|
230
197
|
}
|
|
231
198
|
const state = this._children[instanceIndex].getState();
|
|
232
|
-
//@ts-ignore
|
|
233
199
|
if (this._children.length > this._jsonModel.minItems) {
|
|
234
|
-
// clear child
|
|
235
|
-
//remove field
|
|
236
200
|
this._childrenReference.pop();
|
|
237
201
|
this._children.splice(instanceIndex, 1);
|
|
238
202
|
this.getDataNode().$removeDataNode(instanceIndex);
|
|
239
203
|
for (let i = instanceIndex; i < this._children.length; i++) {
|
|
240
|
-
this._children[i].dispatch(new
|
|
204
|
+
this._children[i].dispatch(new ExecuteRule());
|
|
241
205
|
}
|
|
242
|
-
this.notifyDependents(
|
|
206
|
+
this.notifyDependents(propertyChange('items', null, state));
|
|
243
207
|
}
|
|
244
208
|
}
|
|
245
209
|
}
|
|
246
|
-
/**
|
|
247
|
-
* @private
|
|
248
|
-
*/
|
|
249
210
|
queueEvent(action) {
|
|
250
|
-
var _a;
|
|
251
211
|
super.queueEvent(action);
|
|
252
|
-
if (
|
|
212
|
+
if (action.metadata?.dispatch) {
|
|
253
213
|
this.items.forEach(x => {
|
|
254
|
-
//@ts-ignore
|
|
255
214
|
x.queueEvent(action);
|
|
256
215
|
});
|
|
257
216
|
}
|
|
258
217
|
}
|
|
259
|
-
/**
|
|
260
|
-
* @summary reset the data of all the Fields present inside this container
|
|
261
|
-
* @method reset
|
|
262
|
-
* @private
|
|
263
|
-
*/
|
|
264
218
|
reset() {
|
|
265
219
|
this.items.forEach(x => {
|
|
266
|
-
//@ts-ignore
|
|
267
220
|
x.reset();
|
|
268
221
|
});
|
|
269
222
|
}
|
|
@@ -272,36 +225,21 @@ class Container extends Scriptable_1.default {
|
|
|
272
225
|
return x.validate();
|
|
273
226
|
}).filter(x => x.fieldName !== '');
|
|
274
227
|
}
|
|
275
|
-
/**
|
|
276
|
-
* @private
|
|
277
|
-
*/
|
|
278
228
|
dispatch(action) {
|
|
279
229
|
super.dispatch(action);
|
|
280
230
|
}
|
|
281
|
-
/**
|
|
282
|
-
* @private
|
|
283
|
-
*/
|
|
284
231
|
importData(contextualDataModel) {
|
|
285
232
|
this._bindToDataModel(contextualDataModel);
|
|
286
233
|
const dataNode = this.getDataNode() || contextualDataModel;
|
|
287
234
|
this.syncDataAndFormModel(dataNode);
|
|
288
235
|
}
|
|
289
|
-
/**
|
|
290
|
-
* prefill the form with data on the given element
|
|
291
|
-
* @param dataModel
|
|
292
|
-
* @param contextualDataModel
|
|
293
|
-
* @param operation
|
|
294
|
-
* @private
|
|
295
|
-
*/
|
|
296
236
|
syncDataAndFormModel(contextualDataModel) {
|
|
297
|
-
if (
|
|
298
|
-
const dataLength = contextualDataModel
|
|
237
|
+
if (contextualDataModel?.$type === 'array' && this._itemTemplate != null) {
|
|
238
|
+
const dataLength = contextualDataModel?.$value.length;
|
|
299
239
|
const itemsLength = this._children.length;
|
|
300
240
|
const maxItems = this._jsonModel.maxItems === -1 ? dataLength : this._jsonModel.maxItems;
|
|
301
241
|
const minItems = this._jsonModel.minItems;
|
|
302
|
-
//@ts-ignore
|
|
303
242
|
let items2Add = Math.min(dataLength - itemsLength, maxItems - itemsLength);
|
|
304
|
-
//@ts-ignore
|
|
305
243
|
const items2Remove = Math.min(itemsLength - dataLength, itemsLength - minItems);
|
|
306
244
|
while (items2Add > 0) {
|
|
307
245
|
items2Add--;
|
|
@@ -330,23 +268,23 @@ class Container extends Scriptable_1.default {
|
|
|
330
268
|
activeChild.activeChild = null;
|
|
331
269
|
activeChild = temp;
|
|
332
270
|
}
|
|
333
|
-
const change =
|
|
271
|
+
const change = propertyChange('activeChild', c, this._activeChild);
|
|
334
272
|
this._activeChild = c;
|
|
335
273
|
if (this.parent && c !== null) {
|
|
336
274
|
this.parent.activeChild = this;
|
|
337
275
|
}
|
|
338
|
-
this._jsonModel.activeChild = c
|
|
276
|
+
this._jsonModel.activeChild = c?.id;
|
|
339
277
|
this.notifyDependents(change);
|
|
340
278
|
}
|
|
341
279
|
}
|
|
342
280
|
}
|
|
343
281
|
__decorate([
|
|
344
|
-
|
|
282
|
+
dependencyTracked()
|
|
345
283
|
], Container.prototype, "maxItems", null);
|
|
346
284
|
__decorate([
|
|
347
|
-
|
|
285
|
+
dependencyTracked()
|
|
348
286
|
], Container.prototype, "minItems", null);
|
|
349
287
|
__decorate([
|
|
350
|
-
|
|
288
|
+
dependencyTracked()
|
|
351
289
|
], Container.prototype, "activeChild", null);
|
|
352
|
-
|
|
290
|
+
export default Container;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
import { formatDate, parseDateSkeleton } from '@aemforms/af-formatters';
|
|
3
|
+
class DateField extends Field {
|
|
4
|
+
_applyDefaults() {
|
|
5
|
+
super._applyDefaults();
|
|
6
|
+
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
7
|
+
if (!this._jsonModel.editFormat) {
|
|
8
|
+
this._jsonModel.editFormat = 'short';
|
|
9
|
+
}
|
|
10
|
+
if (!this._jsonModel.displayFormat) {
|
|
11
|
+
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
12
|
+
}
|
|
13
|
+
if (!this._jsonModel.placeholder) {
|
|
14
|
+
this._jsonModel.placeholder = parseDateSkeleton(this._jsonModel.editFormat, locale);
|
|
15
|
+
}
|
|
16
|
+
if (!this._jsonModel.description) {
|
|
17
|
+
this._jsonModel.description = `To enter today's date use ${formatDate(new Date(), locale, this._jsonModel.editFormat)}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default DateField;
|