@aemforms/af-core 0.22.18 → 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.
Files changed (120) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +11 -68
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +86 -182
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/{Container.js → esm/Container.js} +76 -124
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +44 -98
  15. package/lib/{Field.js → esm/Field.js} +172 -206
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +12 -55
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +10 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
  39. package/lib/{controller → esm/controller}/Logger.js +5 -11
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +20 -35
  42. package/lib/{data → esm/data}/DataValue.d.ts +2 -8
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +44 -114
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/{types → esm/types}/Json.d.ts +6 -22
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
  59. package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -0
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
  76. package/package.json +17 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/Container.d.ts +0 -199
  81. package/lib/DateField.js +0 -35
  82. package/lib/Fieldset.d.ts +0 -34
  83. package/lib/Fieldset.js +0 -113
  84. package/lib/FileObject.js +0 -39
  85. package/lib/FileUpload.js +0 -155
  86. package/lib/Form.d.ts +0 -262
  87. package/lib/Form.js +0 -230
  88. package/lib/FormInstance.d.ts +0 -38
  89. package/lib/FormInstance.js +0 -119
  90. package/lib/FormMetaData.d.ts +0 -11
  91. package/lib/FormMetaData.js +0 -28
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -223
  96. package/lib/controller/Controller.js +0 -287
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -52
  100. package/lib/data/EmptyDataValue.js +0 -46
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -63
  103. package/lib/rules/RuleEngine.d.ts +0 -23
  104. package/lib/rules/RuleEngine.js +0 -62
  105. package/lib/types/Json.js +0 -19
  106. package/lib/types/Model.d.ts +0 -379
  107. package/lib/types/Model.js +0 -20
  108. package/lib/types/index.d.ts +0 -2
  109. package/lib/types/index.js +0 -25
  110. package/lib/utils/Fetch.js +0 -29
  111. package/lib/utils/FormUtils.d.ts +0 -47
  112. package/lib/utils/FormUtils.js +0 -257
  113. package/lib/utils/JsonUtils.d.ts +0 -62
  114. package/lib/utils/JsonUtils.js +0 -143
  115. package/lib/utils/LogUtils.js +0 -17
  116. package/lib/utils/SchemaUtils.d.ts +0 -16
  117. package/lib/utils/SchemaUtils.js +0 -92
  118. package/lib/utils/TranslationUtils.d.ts +0 -41
  119. package/lib/utils/TranslationUtils.js +0 -185
  120. 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;
@@ -0,0 +1,53 @@
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';
4
+ declare abstract class Container<T extends ContainerJson & RulesJson> extends Scriptable<T> implements ContainerModel {
5
+ protected _children: Array<FieldModel | FieldsetModel>;
6
+ protected _childrenReference: any;
7
+ private _itemTemplate;
8
+ private fieldFactory;
9
+ constructor(json: T, _options: {
10
+ form: FormModel;
11
+ parent: ContainerModel;
12
+ fieldFactory: IFormFieldFactory;
13
+ });
14
+ ruleNodeReference(): any;
15
+ get items(): (FieldModel | FieldsetModel)[];
16
+ get maxItems(): number;
17
+ set maxItems(m: number);
18
+ get minItems(): number;
19
+ hasDynamicItems(): boolean;
20
+ get isContainer(): boolean;
21
+ private _activeChild;
22
+ getState(): T & {
23
+ items: any[];
24
+ properties: {
25
+ [key: string]: any;
26
+ };
27
+ index: number;
28
+ parent: undefined;
29
+ qualifiedName: any;
30
+ events: {};
31
+ rules: {};
32
+ repeatable: boolean | undefined;
33
+ ':type': string;
34
+ id: string;
35
+ };
36
+ private _createChild;
37
+ private _addChildToRuleNode;
38
+ private _addChild;
39
+ indexOf(f: FieldModel | FieldsetModel): number;
40
+ defaultDataModel(name: string): DataGroup | undefined;
41
+ _initialize(): void;
42
+ addItem(action: Action): void;
43
+ removeItem(action: Action): void;
44
+ queueEvent(action: Action): void;
45
+ reset(): void;
46
+ validate(): import("./types/Model.js").ValidationError[];
47
+ dispatch(action: Action): void;
48
+ importData(contextualDataModel: DataGroup): void;
49
+ syncDataAndFormModel(contextualDataModel?: DataGroup): void;
50
+ get activeChild(): BaseModel | null;
51
+ set activeChild(c: BaseModel | null);
52
+ }
53
+ export default Container;
@@ -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
- var __importDefault = (this && this.__importDefault) || function (mod) {
16
- return (mod && mod.__esModule) ? mod : { "default": mod };
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- const JsonUtils_1 = require("./utils/JsonUtils");
20
- const Scriptable_1 = __importDefault(require("./Scriptable"));
21
- const controller_1 = require("./controller");
22
- const DataGroup_1 = __importDefault(require("./data/DataGroup"));
23
- const BaseNode_1 = require("./BaseNode");
24
- /**
25
- * Defines a generic container class which any form container should extend from.
26
- * @typeparam T type of the node which extends {@link ContainerJson} and {@link RulesJson}
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((0, controller_1.propertyChange)('items', elems, null));
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 Object.assign(Object.assign({}, super.getState()), { items: this._children.map(x => {
79
- return Object.assign({}, x.getState());
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); //accessing dynamic panel directly
77
+ self.ruleEngine.trackDependency(child);
95
78
  }
96
79
  if (self.hasDynamicItems()) {
97
- self.ruleEngine.trackDependency(self); //accessing a child of dynamic panel
98
- if (this._children[name] !== undefined) { // pop function calls this getter in order to return the item
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 = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson, cloneIds ? () => { return form.getUniqueId(); } : undefined));
124
- //@ts-ignore
125
- const retVal = this._createChild(itemTemplate, { parent: this, index });
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 DataGroup_1.default(name, instance, type);
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 = (0, JsonUtils_1.deepClone)(items[0]);
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,106 +163,83 @@ class Container extends Scriptable_1.default {
188
163
  }
189
164
  this.setupRuleNode();
190
165
  }
191
- /**
192
- * @private
193
- */
194
166
  addItem(action) {
195
- if (action.type === 'addItem' && this._itemTemplate != null) {
196
- //@ts-ignore
167
+ if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
197
168
  if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
198
169
  const dataNode = this.getDataNode();
199
- let index = action.payload;
200
- if (typeof index !== 'number' || index > this._children.length) {
201
- index = this._children.length;
202
- }
170
+ let instanceIndex = action.payload;
203
171
  const retVal = this._addChild(this._itemTemplate, action.payload, true);
204
- const _data = retVal.defaultDataModel(index);
172
+ if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
173
+ instanceIndex = this._children.length;
174
+ }
175
+ const _data = retVal.defaultDataModel(instanceIndex);
205
176
  if (_data) {
206
- dataNode.$addDataNode(index, _data);
177
+ dataNode.$addDataNode(instanceIndex, _data);
207
178
  }
208
179
  retVal._initialize();
209
- this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState(), null));
210
- retVal.dispatch(new controller_1.Initialize());
211
- retVal.dispatch(new controller_1.ExecuteRule());
212
- for (let i = index + 1; i < this._children.length; i++) {
213
- this._children[i].dispatch(new controller_1.ExecuteRule());
180
+ this.notifyDependents(propertyChange('items', retVal.getState(), null));
181
+ retVal.dispatch(new Initialize());
182
+ retVal.dispatch(new ExecuteRule());
183
+ for (let i = instanceIndex + 1; i < this._children.length; i++) {
184
+ this._children[i].dispatch(new ExecuteRule());
214
185
  }
215
186
  }
216
187
  }
217
188
  }
218
- /**
219
- * @private
220
- */
221
189
  removeItem(action) {
222
- if (action.type === 'removeItem' && this._itemTemplate != null) {
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
- const index = typeof action.payload === 'number' ? action.payload : this._children.length - 1;
228
- const state = this._children[index].getState();
229
- //@ts-ignore
194
+ let instanceIndex = action.payload;
195
+ if (typeof instanceIndex !== 'number') {
196
+ instanceIndex = this._children.length - 1;
197
+ }
198
+ const state = this._children[instanceIndex].getState();
230
199
  if (this._children.length > this._jsonModel.minItems) {
231
- // clear child
232
- //remove field
233
200
  this._childrenReference.pop();
234
- this._children.splice(index, 1);
235
- this.getDataNode().$removeDataNode(index);
236
- for (let i = index; i < this._children.length; i++) {
237
- this._children[i].dispatch(new controller_1.ExecuteRule());
201
+ this._children.splice(instanceIndex, 1);
202
+ this.getDataNode().$removeDataNode(instanceIndex);
203
+ for (let i = instanceIndex; i < this._children.length; i++) {
204
+ this._children[i].dispatch(new ExecuteRule());
238
205
  }
239
- this.notifyDependents((0, controller_1.propertyChange)('items', null, state));
206
+ this.notifyDependents(propertyChange('items', null, state));
240
207
  }
241
208
  }
242
209
  }
243
- /**
244
- * @private
245
- */
246
210
  queueEvent(action) {
247
- var _a;
248
211
  super.queueEvent(action);
249
- if ((_a = action.metadata) === null || _a === void 0 ? void 0 : _a.dispatch) {
212
+ if (action.metadata?.dispatch) {
250
213
  this.items.forEach(x => {
251
- //@ts-ignore
252
214
  x.queueEvent(action);
253
215
  });
254
216
  }
255
217
  }
218
+ reset() {
219
+ this.items.forEach(x => {
220
+ x.reset();
221
+ });
222
+ }
256
223
  validate() {
257
224
  return this.items.flatMap(x => {
258
225
  return x.validate();
259
226
  }).filter(x => x.fieldName !== '');
260
227
  }
261
- /**
262
- * @private
263
- */
264
228
  dispatch(action) {
265
229
  super.dispatch(action);
266
230
  }
267
- /**
268
- * @private
269
- */
270
231
  importData(contextualDataModel) {
271
232
  this._bindToDataModel(contextualDataModel);
272
233
  const dataNode = this.getDataNode() || contextualDataModel;
273
234
  this.syncDataAndFormModel(dataNode);
274
235
  }
275
- /**
276
- * prefill the form with data on the given element
277
- * @param dataModel
278
- * @param contextualDataModel
279
- * @param operation
280
- * @private
281
- */
282
236
  syncDataAndFormModel(contextualDataModel) {
283
- if ((contextualDataModel === null || contextualDataModel === void 0 ? void 0 : contextualDataModel.$type) === 'array' && this._itemTemplate != null) {
284
- const dataLength = contextualDataModel === null || contextualDataModel === void 0 ? void 0 : contextualDataModel.$value.length;
237
+ if (contextualDataModel?.$type === 'array' && this._itemTemplate != null) {
238
+ const dataLength = contextualDataModel?.$value.length;
285
239
  const itemsLength = this._children.length;
286
240
  const maxItems = this._jsonModel.maxItems === -1 ? dataLength : this._jsonModel.maxItems;
287
241
  const minItems = this._jsonModel.minItems;
288
- //@ts-ignore
289
242
  let items2Add = Math.min(dataLength - itemsLength, maxItems - itemsLength);
290
- //@ts-ignore
291
243
  const items2Remove = Math.min(itemsLength - dataLength, itemsLength - minItems);
292
244
  while (items2Add > 0) {
293
245
  items2Add--;
@@ -316,23 +268,23 @@ class Container extends Scriptable_1.default {
316
268
  activeChild.activeChild = null;
317
269
  activeChild = temp;
318
270
  }
319
- const change = (0, controller_1.propertyChange)('activeChild', c, this._activeChild);
271
+ const change = propertyChange('activeChild', c, this._activeChild);
320
272
  this._activeChild = c;
321
273
  if (this.parent && c !== null) {
322
274
  this.parent.activeChild = this;
323
275
  }
324
- this._jsonModel.activeChild = c === null || c === void 0 ? void 0 : c.id;
276
+ this._jsonModel.activeChild = c?.id;
325
277
  this.notifyDependents(change);
326
278
  }
327
279
  }
328
280
  }
329
281
  __decorate([
330
- (0, BaseNode_1.dependencyTracked)()
282
+ dependencyTracked()
331
283
  ], Container.prototype, "maxItems", null);
332
284
  __decorate([
333
- (0, BaseNode_1.dependencyTracked)()
285
+ dependencyTracked()
334
286
  ], Container.prototype, "minItems", null);
335
287
  __decorate([
336
- (0, BaseNode_1.dependencyTracked)()
288
+ dependencyTracked()
337
289
  ], Container.prototype, "activeChild", null);
338
- exports.default = Container;
290
+ export default Container;
@@ -1,4 +1,4 @@
1
- import Field from './Field';
1
+ import Field from './Field.js';
2
2
  declare class DateField extends Field {
3
3
  protected _applyDefaults(): void;
4
4
  }
@@ -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;