@aemforms/af-core 0.22.16 → 0.22.17

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 CHANGED
@@ -10,6 +10,7 @@ export declare const editableProperties: string[];
10
10
  */
11
11
  export declare const dynamicProps: string[];
12
12
  export declare const target: unique symbol;
13
+ export declare const qualifiedName: unique symbol;
13
14
  export declare function dependencyTracked(): (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
14
15
  /**
15
16
  * Defines a generic base class which all objects of form runtime model should extend from.
@@ -125,4 +126,14 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
125
126
  * @private
126
127
  */
127
128
  _initialize(): void;
129
+ /**
130
+ * Checks whether there are any updates in the properties. If there are applies them to the
131
+ * json model as well.
132
+ * @param propNames
133
+ * @param updates
134
+ * @private
135
+ */
136
+ protected _applyUpdates(propNames: string[], updates: any): any;
137
+ get qualifiedName(): any;
138
+ focus(): void;
128
139
  }
package/lib/BaseNode.js CHANGED
@@ -16,7 +16,7 @@ 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.target = exports.dynamicProps = exports.editableProperties = void 0;
19
+ exports.BaseNode = exports.dependencyTracked = exports.qualifiedName = exports.target = 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"));
@@ -52,7 +52,8 @@ exports.editableProperties = [
52
52
  exports.dynamicProps = [
53
53
  ...exports.editableProperties,
54
54
  'valid',
55
- 'index'
55
+ 'index',
56
+ 'activeChild'
56
57
  ];
57
58
  /**
58
59
  * Implementation of action with target
@@ -92,6 +93,7 @@ class ActionImplWithTarget {
92
93
  }
93
94
  }
94
95
  exports.target = Symbol('target');
96
+ exports.qualifiedName = Symbol('qualifiedName');
95
97
  function dependencyTracked() {
96
98
  return function (target, propertyKey, descriptor) {
97
99
  const get = descriptor.get;
@@ -123,6 +125,8 @@ class BaseNode {
123
125
  this._callbacks = {};
124
126
  this._dependents = [];
125
127
  this._tokens = [];
128
+ //@ts-ignore
129
+ this[exports.qualifiedName] = null;
126
130
  this._jsonModel = Object.assign(Object.assign({}, params), {
127
131
  //@ts-ignore
128
132
  id: 'id' in params ? params.id : this.form.getUniqueId() });
@@ -454,6 +458,51 @@ class BaseNode {
454
458
  this._bindToDataModel(dataNode);
455
459
  }
456
460
  }
461
+ /**
462
+ * Checks whether there are any updates in the properties. If there are applies them to the
463
+ * json model as well.
464
+ * @param propNames
465
+ * @param updates
466
+ * @private
467
+ */
468
+ _applyUpdates(propNames, updates) {
469
+ return propNames.reduce((acc, propertyName) => {
470
+ //@ts-ignore
471
+ const currentValue = updates[propertyName];
472
+ const changes = this._setProperty(propertyName, currentValue, false);
473
+ if (changes.length > 0) {
474
+ acc[propertyName] = changes[0];
475
+ }
476
+ return acc;
477
+ }, {});
478
+ }
479
+ get qualifiedName() {
480
+ if (this.isTransparent()) {
481
+ return null;
482
+ }
483
+ // @ts-ignore
484
+ if (this[exports.qualifiedName] !== null) {
485
+ // @ts-ignore
486
+ return this[exports.qualifiedName];
487
+ }
488
+ // use qualified name
489
+ const parent = this.getNonTransparentParent();
490
+ if (parent && parent.type === 'array') {
491
+ //@ts-ignore
492
+ this[exports.qualifiedName] = `${parent.qualifiedName}[${this.index}]`;
493
+ }
494
+ else {
495
+ //@ts-ignore
496
+ this[exports.qualifiedName] = `${parent.qualifiedName}.${this.name}`;
497
+ }
498
+ //@ts-ignore
499
+ return this[exports.qualifiedName];
500
+ }
501
+ focus() {
502
+ if (this.parent) {
503
+ this.parent.activeChild = this;
504
+ }
505
+ }
457
506
  }
458
507
  __decorate([
459
508
  dependencyTracked()
package/lib/Checkbox.d.ts CHANGED
@@ -64,6 +64,14 @@ declare class Checkbox extends Field {
64
64
  valid: boolean;
65
65
  value: any;
66
66
  };
67
+ accept: (constraint: string[], value: any) => {
68
+ valid: boolean;
69
+ value: any;
70
+ };
71
+ maxFileSize: (constraint: string | number, value: any) => {
72
+ valid: boolean;
73
+ value: any;
74
+ };
67
75
  };
68
76
  protected _getDefaults(): {
69
77
  enforceEnum: boolean;
@@ -1,4 +1,4 @@
1
- import { Action, ContainerJson, ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, RulesJson } from './types';
1
+ import { Action, BaseModel, ContainerJson, ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, RulesJson } from './types';
2
2
  import Scriptable from './Scriptable';
3
3
  import DataGroup from './data/DataGroup';
4
4
  /**
@@ -30,6 +30,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
30
30
  */
31
31
  hasDynamicItems(): boolean;
32
32
  get isContainer(): boolean;
33
+ private _activeChild;
33
34
  /**
34
35
  * Returns the current container state
35
36
  */
@@ -55,6 +56,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
55
56
  minItems?: number | undefined;
56
57
  pattern?: string | undefined;
57
58
  required?: boolean | undefined;
59
+ /**
60
+ * @private
61
+ */
58
62
  step?: number | undefined;
59
63
  type?: string | undefined;
60
64
  validationExpression?: string | undefined;
@@ -66,7 +70,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
66
70
  visible?: boolean | undefined;
67
71
  name?: string | undefined;
68
72
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
69
- fieldType?: string | undefined;
73
+ fieldType?: string | undefined; /**
74
+ * Returns the current container state
75
+ */
70
76
  errorMessage?: string | undefined;
71
77
  properties?: {
72
78
  [key: string]: any;
@@ -102,6 +108,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
102
108
  minItems?: number | undefined;
103
109
  pattern?: string | undefined;
104
110
  required?: boolean | undefined;
111
+ /**
112
+ * @private
113
+ */
105
114
  step?: number | undefined;
106
115
  type?: "object" | "array" | undefined;
107
116
  validationExpression?: string | undefined;
@@ -113,7 +122,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
113
122
  visible?: boolean | undefined;
114
123
  name?: string | undefined;
115
124
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
116
- fieldType?: string | undefined;
125
+ fieldType?: string | undefined; /**
126
+ * Returns the current container state
127
+ */
117
128
  errorMessage?: string | undefined;
118
129
  properties?: {
119
130
  [key: string]: any;
@@ -138,6 +149,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
138
149
  minItems?: number | undefined;
139
150
  pattern?: string | undefined;
140
151
  required?: boolean | undefined;
152
+ /**
153
+ * @private
154
+ */
141
155
  step?: number | undefined;
142
156
  type?: string | undefined;
143
157
  validationExpression?: string | undefined;
@@ -150,7 +164,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
150
164
  visible?: boolean | undefined;
151
165
  name?: string | undefined;
152
166
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
153
- fieldType?: string | undefined;
167
+ fieldType?: string | undefined; /**
168
+ * Returns the current container state
169
+ */
154
170
  errorMessage?: string | undefined;
155
171
  properties?: {
156
172
  [key: string]: any;
@@ -190,6 +206,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
190
206
  minItems?: number | undefined;
191
207
  pattern?: string | undefined;
192
208
  required?: boolean | undefined;
209
+ /**
210
+ * @private
211
+ */
193
212
  step?: number | undefined;
194
213
  type?: string | undefined;
195
214
  validationExpression?: string | undefined;
@@ -202,7 +221,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
202
221
  visible?: boolean | undefined;
203
222
  name?: string | undefined;
204
223
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
205
- fieldType?: string | undefined;
224
+ fieldType?: string | undefined; /**
225
+ * Returns the current container state
226
+ */
206
227
  errorMessage?: string | undefined;
207
228
  properties?: {
208
229
  [key: string]: any;
@@ -210,6 +231,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
210
231
  } & {
211
232
  items: (FieldJson | ContainerJson)[];
212
233
  initialItems?: number | undefined;
234
+ activeChild?: string | undefined;
213
235
  } & {
214
236
  id: string;
215
237
  items: (({
@@ -232,6 +254,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
232
254
  minItems?: number | undefined;
233
255
  pattern?: string | undefined;
234
256
  required?: boolean | undefined;
257
+ /**
258
+ * @private
259
+ */
235
260
  step?: number | undefined;
236
261
  type?: string | undefined;
237
262
  validationExpression?: string | undefined;
@@ -244,7 +269,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
244
269
  visible?: boolean | undefined;
245
270
  name?: string | undefined;
246
271
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
247
- fieldType?: string | undefined;
272
+ fieldType?: string | undefined; /**
273
+ * Returns the current container state
274
+ */
248
275
  errorMessage?: string | undefined;
249
276
  properties?: {
250
277
  [key: string]: any;
@@ -284,6 +311,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
284
311
  minItems?: number | undefined;
285
312
  pattern?: string | undefined;
286
313
  required?: boolean | undefined;
314
+ /**
315
+ * @private
316
+ */
287
317
  step?: number | undefined;
288
318
  type?: string | undefined;
289
319
  validationExpression?: string | undefined;
@@ -296,7 +326,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
296
326
  visible?: boolean | undefined;
297
327
  name?: string | undefined;
298
328
  constraintMessages?: import("./types").ConstraintsMessages | undefined;
299
- fieldType?: string | undefined;
329
+ fieldType?: string | undefined; /**
330
+ * Returns the current container state
331
+ */
300
332
  errorMessage?: string | undefined;
301
333
  properties?: {
302
334
  [key: string]: any;
@@ -304,9 +336,11 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
304
336
  } & {
305
337
  items: (FieldJson | ContainerJson)[];
306
338
  initialItems?: number | undefined;
339
+ activeChild?: string | undefined;
307
340
  } & any))[];
308
341
  }))[];
309
342
  initialItems?: number | undefined;
343
+ activeChild?: string | undefined;
310
344
  id: string;
311
345
  })[];
312
346
  id: string;
@@ -352,5 +386,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
352
386
  * @private
353
387
  */
354
388
  syncDataAndFormModel(contextualDataModel?: DataGroup): void;
389
+ get activeChild(): BaseModel | null;
390
+ set activeChild(c: BaseModel | null);
355
391
  }
356
392
  export default Container;
package/lib/Container.js CHANGED
@@ -30,6 +30,7 @@ class Container extends Scriptable_1.default {
30
30
  super(...arguments);
31
31
  this._children = [];
32
32
  this._itemTemplate = null;
33
+ this._activeChild = null;
33
34
  }
34
35
  /**
35
36
  * @private
@@ -301,6 +302,26 @@ class Container extends Scriptable_1.default {
301
302
  x.importData(contextualDataModel);
302
303
  });
303
304
  }
305
+ get activeChild() {
306
+ return this._activeChild;
307
+ }
308
+ set activeChild(c) {
309
+ if (c !== this._activeChild) {
310
+ let activeChild = this._activeChild;
311
+ while (activeChild instanceof Container) {
312
+ const temp = activeChild.activeChild;
313
+ activeChild.activeChild = null;
314
+ activeChild = temp;
315
+ }
316
+ const change = (0, controller_1.propertyChange)('activeChild', c, this._activeChild);
317
+ this._activeChild = c;
318
+ if (this.parent && c !== null) {
319
+ this.parent.activeChild = this;
320
+ }
321
+ this._jsonModel.activeChild = c === null || c === void 0 ? void 0 : c.id;
322
+ this.notifyDependents(change);
323
+ }
324
+ }
304
325
  }
305
326
  __decorate([
306
327
  (0, BaseNode_1.dependencyTracked)()
@@ -308,4 +329,7 @@ __decorate([
308
329
  __decorate([
309
330
  (0, BaseNode_1.dependencyTracked)()
310
331
  ], Container.prototype, "minItems", null);
332
+ __decorate([
333
+ (0, BaseNode_1.dependencyTracked)()
334
+ ], Container.prototype, "activeChild", null);
311
335
  exports.default = Container;
package/lib/Field.d.ts CHANGED
@@ -61,8 +61,11 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
61
61
  private isEmpty;
62
62
  get editValue(): any;
63
63
  get displayValue(): any;
64
+ protected getDataNodeValue(typedValue: any): any;
64
65
  get value(): any;
65
66
  set value(v: any);
67
+ protected _updateRuleNodeReference(value: any): void;
68
+ protected getInternalType(): string | undefined;
66
69
  valueOf(): any;
67
70
  toString(): any;
68
71
  /**
@@ -105,10 +108,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
105
108
  };
106
109
  maxItems: <T_1>(constraint: number, value: T_1[]) => {
107
110
  valid: boolean;
108
- value: T_1[]; /**
109
- * Returns the error message for a given constraint
110
- * @param constraint
111
- */
111
+ value: T_1[];
112
112
  };
113
113
  uniqueItems: <T_2>(constraint: boolean, value: T_2[]) => {
114
114
  valid: boolean;
@@ -134,6 +134,14 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
134
134
  valid: boolean;
135
135
  value: any;
136
136
  };
137
+ accept: (constraint: string[], value: any) => {
138
+ valid: boolean;
139
+ value: any;
140
+ };
141
+ maxFileSize: (constraint: string | number, value: any) => {
142
+ valid: boolean;
143
+ value: any;
144
+ };
137
145
  };
138
146
  /**
139
147
  * returns whether the field is array type or not
@@ -174,14 +182,6 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
174
182
  */
175
183
  protected evaluateConstraints(): any;
176
184
  triggerValidationEvent(changes: any): void;
177
- /**
178
- * Checks whether there are any updates in the properties. If there are applies them to the
179
- * json model as well.
180
- * @param propNames
181
- * @param updates
182
- * @private
183
- */
184
- protected _applyUpdates(propNames: string[], updates: any): any;
185
185
  /**
186
186
  * Validates the current form object
187
187
  */
package/lib/Field.js CHANGED
@@ -88,7 +88,8 @@ class Field extends Scriptable_1.default {
88
88
  });
89
89
  const value = this._jsonModel.value;
90
90
  if (value === undefined) {
91
- this._jsonModel.value = this._jsonModel.default;
91
+ const typedRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
92
+ this._jsonModel.value = typedRes.value;
92
93
  }
93
94
  if (this._jsonModel.fieldType === undefined) {
94
95
  //@ts-ignore
@@ -211,6 +212,9 @@ class Field extends Scriptable_1.default {
211
212
  return this.value;
212
213
  }
213
214
  }
215
+ getDataNodeValue(typedValue) {
216
+ return this.isEmpty() ? this.emptyValue : typedValue;
217
+ }
214
218
  get value() {
215
219
  if (this._jsonModel.value === undefined) {
216
220
  return null;
@@ -220,30 +224,15 @@ class Field extends Scriptable_1.default {
220
224
  }
221
225
  }
222
226
  set value(v) {
223
- var _a;
224
227
  const Constraints = this._getConstraintObject();
225
- const typeRes = Constraints.type(this._jsonModel.type || 'string', v);
228
+ const typeRes = Constraints.type(this.getInternalType() || 'string', v);
226
229
  const changes = this._setProperty('value', typeRes.value, false);
227
230
  let uniqueRes = { valid: true };
228
231
  if (changes.length > 0) {
229
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
230
- if (typeRes.value != null) {
231
- typeRes.value.forEach((val, index) => {
232
- this._ruleNodeReference[index] = val;
233
- });
234
- while (typeRes.value.length !== this._ruleNodeReference.length) {
235
- this._ruleNodeReference.pop();
236
- }
237
- }
238
- else {
239
- while (this._ruleNodeReference.length !== 0) {
240
- this._ruleNodeReference.pop();
241
- }
242
- }
243
- }
232
+ this._updateRuleNodeReference(typeRes.value);
244
233
  const dataNode = this.getDataNode();
245
234
  if (typeof dataNode !== 'undefined') {
246
- dataNode.setValue(this.isEmpty() ? this.emptyValue : this._jsonModel.value, this._jsonModel.value);
235
+ dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
247
236
  }
248
237
  if (this.parent.uniqueItems && this.parent.type === 'array') {
249
238
  // @ts-ignore
@@ -267,6 +256,27 @@ class Field extends Scriptable_1.default {
267
256
  this.dispatch(changeAction);
268
257
  }
269
258
  }
259
+ _updateRuleNodeReference(value) {
260
+ var _a;
261
+ if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
262
+ if (value != null) {
263
+ value.forEach((val, index) => {
264
+ this._ruleNodeReference[index] = val;
265
+ });
266
+ while (value.length !== this._ruleNodeReference.length) {
267
+ this._ruleNodeReference.pop();
268
+ }
269
+ }
270
+ else {
271
+ while (this._ruleNodeReference.length !== 0) {
272
+ this._ruleNodeReference.pop();
273
+ }
274
+ }
275
+ }
276
+ }
277
+ getInternalType() {
278
+ return this.type;
279
+ }
270
280
  valueOf() {
271
281
  // @ts-ignore
272
282
  const obj = this[BaseNode_1.target];
@@ -363,7 +373,10 @@ class Field extends Scriptable_1.default {
363
373
  default:
364
374
  return ValidationUtils_1.ValidConstraints.string;
365
375
  }
376
+ case 'file':
377
+ return ValidationUtils_1.ValidConstraints.file;
366
378
  case 'number':
379
+ case 'integer':
367
380
  return ValidationUtils_1.ValidConstraints.number;
368
381
  }
369
382
  if (this.isArrayType()) {
@@ -455,24 +468,6 @@ class Field extends Scriptable_1.default {
455
468
  }
456
469
  }
457
470
  }
458
- /**
459
- * Checks whether there are any updates in the properties. If there are applies them to the
460
- * json model as well.
461
- * @param propNames
462
- * @param updates
463
- * @private
464
- */
465
- _applyUpdates(propNames, updates) {
466
- return propNames.reduce((acc, propertyName) => {
467
- //@ts-ignore
468
- const currentValue = updates[propertyName];
469
- const changes = this._setProperty(propertyName, currentValue, false);
470
- if (changes.length > 0) {
471
- acc[propertyName] = changes[0];
472
- }
473
- return acc;
474
- }, {});
475
- }
476
471
  /**
477
472
  * Validates the current form object
478
473
  */
@@ -499,7 +494,7 @@ class Field extends Scriptable_1.default {
499
494
  * @private
500
495
  */
501
496
  defaultDataModel(name) {
502
- return new DataValue_1.default(name, this.isEmpty() ? this.emptyValue : this._jsonModel.value, this.type || 'string');
497
+ return new DataValue_1.default(name, this.getDataNodeValue(this._jsonModel.value), this.type || 'string');
503
498
  }
504
499
  getState() {
505
500
  return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
@@ -4,14 +4,15 @@ import { IFileObject } from './types';
4
4
  */
5
5
  export declare class FileObject implements IFileObject {
6
6
  data: any;
7
- mediaType: string;
7
+ type: string;
8
8
  name: string;
9
9
  size: number;
10
10
  constructor(init?: Partial<FileObject>);
11
11
  toJSON(): {
12
12
  name: string;
13
13
  size: number;
14
- mediaType: string;
14
+ type: string;
15
15
  data: any;
16
16
  };
17
+ equals(obj: IFileObject): boolean;
17
18
  }
package/lib/FileObject.js CHANGED
@@ -13,7 +13,7 @@ exports.FileObject = void 0;
13
13
  */
14
14
  class FileObject {
15
15
  constructor(init) {
16
- this.mediaType = 'application/octet-stream';
16
+ this.type = 'application/octet-stream';
17
17
  this.name = 'unknown';
18
18
  this.size = 0;
19
19
  Object.assign(this, init);
@@ -22,9 +22,15 @@ class FileObject {
22
22
  return {
23
23
  'name': this.name,
24
24
  'size': this.size,
25
- 'mediaType': this.mediaType,
25
+ 'type': this.type,
26
26
  'data': this.data.toString()
27
27
  };
28
28
  }
29
+ equals(obj) {
30
+ return (this.data === obj.data &&
31
+ this.type === obj.type &&
32
+ this.name === obj.name &&
33
+ this.size === obj.size);
34
+ }
29
35
  }
30
36
  exports.FileObject = FileObject;
@@ -28,19 +28,9 @@ declare class FileUpload extends Field implements FieldModel {
28
28
  * @private
29
29
  */
30
30
  protected _applyUpdates(propNames: string[], updates: any): any;
31
- typeCheck(value: any): {
32
- valid: boolean;
33
- value: any;
34
- };
35
- checkFileType(type: any): boolean;
36
- acceptCheck(value: any): {
37
- valid: boolean;
38
- value: any;
39
- };
40
- get value(): any;
41
- set value(value: any);
31
+ protected getInternalType(): "file" | "file[]";
32
+ protected getDataNodeValue(typedValue: any): any;
42
33
  private _serialize;
43
- private coerce;
44
34
  importData(dataModel: DataGroup): void;
45
35
  }
46
36
  export default FileUpload;