@aemforms/af-core 0.22.41 → 0.22.43

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.js CHANGED
@@ -198,7 +198,13 @@ class BaseNode {
198
198
  return this._jsonModel.dataRef;
199
199
  }
200
200
  get visible() {
201
- return this._jsonModel.visible;
201
+ var _a, _b;
202
+ if (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.visible) !== undefined) {
203
+ return ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.visible) ? this._jsonModel.visible : false;
204
+ }
205
+ else {
206
+ return this._jsonModel.visible;
207
+ }
202
208
  }
203
209
  set visible(v) {
204
210
  if (v !== this._jsonModel.visible) {
@@ -11,6 +11,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
11
11
  parent: ContainerModel;
12
12
  fieldFactory: IFormFieldFactory;
13
13
  });
14
+ protected _getDefaults(): any;
14
15
  ruleNodeReference(): any;
15
16
  get items(): (FieldModel | FieldsetModel)[];
16
17
  get maxItems(): number;
@@ -24,6 +25,8 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
24
25
  private getItemsState;
25
26
  getState(isRepeatableChild?: boolean): T & {
26
27
  items: any[];
28
+ enabled: boolean | undefined;
29
+ readOnly: any;
27
30
  properties: {
28
31
  [key: string]: any;
29
32
  };
@@ -54,5 +57,10 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
54
57
  syncDataAndFormModel(contextualDataModel?: DataGroup): void;
55
58
  get activeChild(): BaseModel | null;
56
59
  set activeChild(c: BaseModel | null);
60
+ get enabled(): boolean | undefined;
61
+ set enabled(e: boolean | undefined);
62
+ get readOnly(): any;
63
+ set readOnly(e: any);
64
+ notifyChildren(action: Action): void;
57
65
  }
58
66
  export default Container;
package/lib/Container.js CHANGED
@@ -14,6 +14,9 @@ const Scriptable_1 = __importDefault(require("./Scriptable"));
14
14
  const Events_1 = require("./controller/Events");
15
15
  const DataGroup_1 = __importDefault(require("./data/DataGroup"));
16
16
  const BaseNode_1 = require("./BaseNode");
17
+ const notifyChildrenAttributes = [
18
+ 'readOnly', 'enabled'
19
+ ];
17
20
  class Container extends Scriptable_1.default {
18
21
  constructor(json, _options) {
19
22
  super(json, { form: _options.form, parent: _options.parent });
@@ -22,6 +25,9 @@ class Container extends Scriptable_1.default {
22
25
  this._activeChild = null;
23
26
  this.fieldFactory = _options.fieldFactory;
24
27
  }
28
+ _getDefaults() {
29
+ return Object.assign(Object.assign({}, super._getDefaults()), { enabled: true, readOnly: false });
30
+ }
25
31
  ruleNodeReference() {
26
32
  return this._childrenReference;
27
33
  }
@@ -81,7 +87,7 @@ class Container extends Scriptable_1.default {
81
87
  }
82
88
  }
83
89
  getState(isRepeatableChild = false) {
84
- return Object.assign(Object.assign({}, super.getState(isRepeatableChild)), { items: this.getItemsState(isRepeatableChild) });
90
+ return Object.assign(Object.assign({}, super.getState(isRepeatableChild)), { items: this.getItemsState(isRepeatableChild), enabled: this.enabled, readOnly: this.readOnly });
85
91
  }
86
92
  _createChild(child, options) {
87
93
  const { parent = this } = options;
@@ -340,6 +346,44 @@ class Container extends Scriptable_1.default {
340
346
  this.notifyDependents(change);
341
347
  }
342
348
  }
349
+ get enabled() {
350
+ var _a, _b;
351
+ if (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.enabled) !== undefined) {
352
+ return !((_b = this.parent) === null || _b === void 0 ? void 0 : _b.enabled) ? false : this._jsonModel.enabled;
353
+ }
354
+ else {
355
+ return this._jsonModel.enabled;
356
+ }
357
+ }
358
+ set enabled(e) {
359
+ this._setProperty('enabled', e, true, this.notifyChildren);
360
+ }
361
+ get readOnly() {
362
+ var _a;
363
+ if (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.readOnly) !== undefined) {
364
+ return this.parent.readOnly ? true : this._jsonModel.readOnly;
365
+ }
366
+ else {
367
+ return this._jsonModel.readOnly;
368
+ }
369
+ }
370
+ set readOnly(e) {
371
+ this._setProperty('readOnly', e, true, this.notifyChildren);
372
+ }
373
+ notifyChildren(action) {
374
+ if (action.payload !== undefined && action.payload.changes !== undefined) {
375
+ for (const change of action.payload.changes) {
376
+ if (change.propertyName !== undefined && notifyChildrenAttributes.includes(change.propertyName)) {
377
+ this.items.forEach((child) => {
378
+ this.notifyDependents.call(child, (0, Events_1.propertyChange)(change.propertyName, child.getState()[change.propertyName], null));
379
+ if (child.fieldType === 'panel') {
380
+ this.notifyChildren.call(child, action);
381
+ }
382
+ });
383
+ }
384
+ }
385
+ }
386
+ }
343
387
  }
344
388
  __decorate([
345
389
  (0, BaseNode_1.dependencyTracked)()
package/lib/Field.d.ts CHANGED
@@ -36,8 +36,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
36
36
  get emptyValue(): "" | null | undefined;
37
37
  get enum(): any[] | undefined;
38
38
  set enum(e: any[] | undefined);
39
- get enumNames(): string[] | undefined;
40
- set enumNames(e: string[] | undefined);
39
+ get enumNames(): string[] | import("./types").EnumName[] | undefined;
40
+ set enumNames(e: string[] | import("./types").EnumName[] | undefined);
41
41
  get required(): boolean;
42
42
  set required(r: boolean);
43
43
  get maximum(): number | undefined;
@@ -158,7 +158,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
158
158
  description?: string | undefined;
159
159
  rules: import("./types").Items<string> & {};
160
160
  events: import("./types").Items<string | string[] | undefined> & {};
161
- enumNames?: string[] | undefined;
161
+ enumNames?: string[] | import("./types").EnumName[] | undefined;
162
162
  enum?: any[] | undefined;
163
163
  accept?: string[] | undefined;
164
164
  enforceEnum?: boolean | undefined;
@@ -207,5 +207,6 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
207
207
  qualifiedName: any;
208
208
  id: string;
209
209
  };
210
+ markAsInvalid(message: string): void;
210
211
  }
211
212
  export default Field;
package/lib/Field.js CHANGED
@@ -18,7 +18,7 @@ const DataValue_1 = __importDefault(require("./data/DataValue"));
18
18
  const BaseNode_1 = require("./BaseNode");
19
19
  const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
20
20
  const af_formatters_1 = require("@aemforms/af-formatters");
21
- const validTypes = ['string', 'number', 'boolean', 'file', 'string[]', 'number[]', 'boolean[]', 'file[]', 'array', 'object'];
21
+ const validTypes = ['string', 'number', 'integer', 'boolean', 'file', 'string[]', 'number[]', 'integer[]', 'boolean[]', 'file[]', 'array', 'object'];
22
22
  class Field extends Scriptable_1.default {
23
23
  constructor(params, _options) {
24
24
  super(params, _options);
@@ -258,7 +258,7 @@ class Field extends Scriptable_1.default {
258
258
  if (this.format === 'date') {
259
259
  df = `date|${df}`;
260
260
  }
261
- else if (this.type === 'number') {
261
+ else if (this.type === 'number' || this.type === 'integer') {
262
262
  df = `num|${df}`;
263
263
  }
264
264
  return df;
@@ -612,6 +612,9 @@ class Field extends Scriptable_1.default {
612
612
  }
613
613
  }
614
614
  validate() {
615
+ if (this.visible === false) {
616
+ return [];
617
+ }
615
618
  const changes = this.evaluateConstraints();
616
619
  if (changes.valid) {
617
620
  this.triggerValidationEvent(changes);
@@ -635,6 +638,16 @@ class Field extends Scriptable_1.default {
635
638
  getState() {
636
639
  return Object.assign(Object.assign({}, super.getState()), { editFormat: this.editFormat, displayFormat: this.displayFormat, editValue: this.editValue, displayValue: this.displayValue, enabled: this.enabled, readOnly: this.readOnly });
637
640
  }
641
+ markAsInvalid(message) {
642
+ const changes = {
643
+ 'valid': false,
644
+ 'errorMessage': message
645
+ };
646
+ const updates = this._applyUpdates(['valid', 'errorMessage'], changes);
647
+ this.triggerValidationEvent(updates);
648
+ const changeAction = new Events_1.Change({ changes: [].concat(Object.values(updates)) });
649
+ this.dispatch(changeAction);
650
+ }
638
651
  }
639
652
  __decorate([
640
653
  (0, BaseNode_1.dependencyTracked)(),
package/lib/Fieldset.d.ts CHANGED
@@ -1,82 +1,15 @@
1
1
  import Container from './Container';
2
- import { Action, ContainerModel, FieldModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from './types/index';
2
+ import { ContainerModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from './types/index';
3
3
  export declare class Fieldset extends Container<FieldsetJson> implements FieldsetModel {
4
4
  constructor(params: FieldsetJson, _options: {
5
5
  form: FormModel;
6
6
  parent: ContainerModel;
7
7
  fieldFactory: IFormFieldFactory;
8
8
  });
9
- protected _getDefaults(): {
10
- visible: boolean;
11
- enabled: boolean;
12
- readOnly: boolean;
13
- required: boolean;
14
- label: {
15
- visible: boolean;
16
- richText: boolean;
17
- };
18
- };
9
+ protected _getDefaults(): any;
19
10
  private _applyDefaults;
20
11
  get type(): "array" | "object" | undefined;
21
- get items(): (FieldModel | FieldsetModel)[];
12
+ get items(): (import("./types/Model").FieldModel | FieldsetModel)[];
22
13
  get value(): null;
23
14
  get fieldType(): string;
24
- get enabled(): boolean | undefined;
25
- set enabled(e: boolean | undefined);
26
- get readOnly(): boolean | undefined;
27
- set readOnly(e: boolean | undefined);
28
- notifyChildren(action: Action): void;
29
- getState(): {
30
- enabled: boolean | undefined;
31
- readOnly: boolean | undefined;
32
- description?: string | undefined;
33
- rules: import("./types/Json").Items<string> & {};
34
- events: import("./types/Json").Items<string | string[] | undefined> & {};
35
- enumNames?: string[] | undefined;
36
- enum?: any[] | undefined;
37
- accept?: string[] | undefined;
38
- enforceEnum?: boolean | undefined;
39
- exclusiveMinimum?: number | undefined;
40
- exclusiveMaximum?: number | undefined;
41
- format?: string | undefined;
42
- maxFileSize?: string | number | undefined;
43
- maxLength?: number | undefined;
44
- maximum?: number | undefined;
45
- maxItems?: number | undefined;
46
- minOccur?: number | undefined;
47
- maxOccur?: number | undefined;
48
- minLength?: number | undefined;
49
- minimum?: number | undefined;
50
- minItems?: number | undefined;
51
- pattern?: string | undefined;
52
- required?: boolean | undefined;
53
- step?: number | undefined;
54
- type?: "object" | "array" | undefined;
55
- validationExpression?: string | undefined;
56
- uniqueItems?: boolean | undefined;
57
- dataRef?: string | null | undefined;
58
- lang?: string | undefined;
59
- ':type': string;
60
- label?: import("./types/Json").Label | undefined;
61
- visible?: boolean | undefined;
62
- name?: string | undefined;
63
- constraintMessages?: import("./types/Json").ConstraintsMessages | undefined;
64
- fieldType?: string | undefined;
65
- errorMessage?: string | undefined;
66
- properties: {
67
- [key: string]: any;
68
- };
69
- repeatable: boolean | undefined;
70
- screenReaderText?: string | undefined;
71
- tooltip?: string | undefined;
72
- altText?: string | undefined;
73
- viewType?: string | undefined;
74
- items: (import("./types/Json").FieldJson | import("./types/Json").ContainerJson)[] & any[];
75
- initialItems?: number | undefined;
76
- activeChild?: string | undefined;
77
- index: number;
78
- parent: undefined;
79
- qualifiedName: any;
80
- id: string;
81
- };
82
15
  }
package/lib/Fieldset.js CHANGED
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Fieldset = void 0;
7
7
  const Container_1 = __importDefault(require("./Container"));
8
8
  const Events_1 = require("./controller/Events");
9
- const notifyChildrenAttributes = [
10
- 'readOnly', 'enabled'
11
- ];
12
9
  class Fieldset extends Container_1.default {
13
10
  constructor(params, _options) {
14
11
  super(params, _options);
@@ -17,16 +14,10 @@ class Fieldset extends Container_1.default {
17
14
  this.queueEvent(new Events_1.ExecuteRule());
18
15
  }
19
16
  _getDefaults() {
20
- return {
21
- visible: true,
22
- enabled: true,
23
- readOnly: false,
24
- required: false,
25
- label: {
17
+ return Object.assign(Object.assign({}, super._getDefaults()), { visible: true, required: false, label: {
26
18
  visible: true,
27
19
  richText: false
28
- }
29
- };
20
+ } });
30
21
  }
31
22
  _applyDefaults() {
32
23
  super._applyDefaultsInModel();
@@ -50,44 +41,5 @@ class Fieldset extends Container_1.default {
50
41
  get fieldType() {
51
42
  return 'panel';
52
43
  }
53
- get enabled() {
54
- if (this.parent.enabled !== undefined) {
55
- return this.parent.enabled === false ? false : this._jsonModel.enabled;
56
- }
57
- else {
58
- return this._jsonModel.enabled;
59
- }
60
- }
61
- set enabled(e) {
62
- this._setProperty('enabled', e, true, this.notifyChildren);
63
- }
64
- get readOnly() {
65
- if (this.parent.readOnly !== undefined) {
66
- return this.parent.readOnly === true ? true : this._jsonModel.readOnly;
67
- }
68
- else {
69
- return this._jsonModel.readOnly;
70
- }
71
- }
72
- set readOnly(e) {
73
- this._setProperty('readOnly', e, true, this.notifyChildren);
74
- }
75
- notifyChildren(action) {
76
- if (action.payload !== undefined && action.payload.changes !== undefined) {
77
- for (const change of action.payload.changes) {
78
- if (change.propertyName !== undefined && notifyChildrenAttributes.includes(change.propertyName)) {
79
- this.items.forEach((child) => {
80
- this.notifyDependents.call(child, (0, Events_1.propertyChange)(change.propertyName, child.getState()[change.propertyName], null));
81
- if (child.fieldType === 'panel') {
82
- this.notifyChildren.call(child, action);
83
- }
84
- });
85
- }
86
- }
87
- }
88
- }
89
- getState() {
90
- return Object.assign(Object.assign({}, super.getState()), { enabled: this.enabled, readOnly: this.readOnly });
91
- }
92
44
  }
93
45
  exports.Fieldset = Fieldset;
package/lib/Form.d.ts CHANGED
@@ -22,7 +22,7 @@ declare class Form extends Container<FormJson> implements FormModel {
22
22
  getState(): {
23
23
  description?: string | undefined;
24
24
  } & import("./types/Json").RulesJson & {
25
- enumNames?: string[] | undefined;
25
+ enumNames?: string[] | import("./types/Json").EnumName[] | undefined;
26
26
  enum?: any[] | undefined;
27
27
  } & {
28
28
  accept?: string[] | undefined;
@@ -77,6 +77,8 @@ declare class Form extends Container<FormJson> implements FormModel {
77
77
  lang?: string | undefined;
78
78
  } & {
79
79
  items: any[];
80
+ enabled: boolean | undefined;
81
+ readOnly: any;
80
82
  properties: {
81
83
  [key: string]: any;
82
84
  };
@@ -41,6 +41,14 @@ declare class FunctionRuntimeImpl {
41
41
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
42
42
  _signature: never[];
43
43
  };
44
+ addInstance: {
45
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => void;
46
+ _signature: never[];
47
+ };
48
+ removeInstance: {
49
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => void;
50
+ _signature: never[];
51
+ };
44
52
  dispatchEvent: {
45
53
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
46
54
  _signature: never[];
@@ -162,8 +162,14 @@ class FunctionRuntimeImpl {
162
162
  let finalFunction = funcDef;
163
163
  if (typeof funcDef === 'function') {
164
164
  finalFunction = {
165
- _func: (args) => {
166
- return funcDef(...args);
165
+ _func: (args, data, interpreter) => {
166
+ const globals = {
167
+ form: interpreter.globals.form,
168
+ invoke: (funcName, ...args) => {
169
+ return this.customFunctions[funcName]._func.call(undefined, args, data, interpreter);
170
+ }
171
+ };
172
+ return funcDef(...args, globals);
167
173
  },
168
174
  _signature: []
169
175
  };
@@ -295,6 +301,36 @@ class FunctionRuntimeImpl {
295
301
  },
296
302
  _signature: []
297
303
  },
304
+ addInstance: {
305
+ _func: (args, data, interpreter) => {
306
+ const element = args[0];
307
+ const payload = args.length > 2 ? valueOf(args[2]) : undefined;
308
+ try {
309
+ const formElement = interpreter.globals.form.getElement(element.$id);
310
+ const action = createAction('addInstance', payload);
311
+ formElement.addItem(action);
312
+ }
313
+ catch (e) {
314
+ interpreter.globals.form.logger.error('Invalid argument passed in addInstance. An element is expected');
315
+ }
316
+ },
317
+ _signature: []
318
+ },
319
+ removeInstance: {
320
+ _func: (args, data, interpreter) => {
321
+ const element = args[0];
322
+ const payload = args.length > 2 ? valueOf(args[2]) : undefined;
323
+ try {
324
+ const formElement = interpreter.globals.form.getElement(element.$id);
325
+ const action = createAction('removeInstance', payload);
326
+ formElement.removeItem(action);
327
+ }
328
+ catch (e) {
329
+ interpreter.globals.form.logger.error('Invalid argument passed in removeInstance. An element is expected');
330
+ }
331
+ },
332
+ _signature: []
333
+ },
298
334
  dispatchEvent: {
299
335
  _func: (args, data, interpreter) => {
300
336
  const element = args[0];
@@ -7,8 +7,12 @@ export declare type Label = {
7
7
  richText?: boolean;
8
8
  visible?: boolean;
9
9
  };
10
+ export declare type EnumName = {
11
+ value: string;
12
+ richText?: boolean;
13
+ };
10
14
  declare type TranslationConstraintsJson = {
11
- enumNames?: string[];
15
+ enumNames?: string[] | EnumName[];
12
16
  enum?: any[];
13
17
  };
14
18
  export declare type ConstraintsJson = TranslationConstraintsJson & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.41",
3
+ "version": "0.22.43",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.41"
38
+ "@aemforms/af-formatters": "^0.22.43"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",