@aemforms/af-core 0.22.68 → 0.22.70

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 (60) hide show
  1. package/esm/afb-events.js +161 -0
  2. package/esm/afb-runtime.js +4304 -0
  3. package/esm/types/src/BaseNode.d.ts +100 -0
  4. package/esm/types/src/Captcha.d.ts +5 -0
  5. package/esm/types/src/Checkbox.d.ts +84 -0
  6. package/esm/types/src/CheckboxGroup.d.ts +24 -0
  7. package/esm/types/src/Container.d.ts +75 -0
  8. package/esm/types/src/DateField.d.ts +9 -0
  9. package/esm/types/src/EmailInput.d.ts +16 -0
  10. package/esm/types/src/Field.d.ts +224 -0
  11. package/esm/types/src/Fieldset.d.ts +16 -0
  12. package/esm/types/src/FileObject.d.ts +16 -0
  13. package/esm/types/src/FileUpload.d.ts +27 -0
  14. package/esm/types/src/Form.d.ts +125 -0
  15. package/esm/types/src/FormInstance.d.ts +16 -0
  16. package/esm/types/src/FormMetaData.d.ts +7 -0
  17. package/esm/types/src/InstanceManager.d.ts +9 -0
  18. package/esm/types/src/Node.d.ts +7 -0
  19. package/esm/types/src/Scriptable.d.ts +17 -0
  20. package/esm/types/src/SubmitMetaData.d.ts +7 -0
  21. package/esm/types/src/controller/EventQueue.d.ts +18 -0
  22. package/esm/types/src/controller/Events.d.ts +91 -0
  23. package/esm/types/src/controller/Logger.d.ts +11 -0
  24. package/esm/types/src/data/DataGroup.d.ts +20 -0
  25. package/esm/types/src/data/DataValue.d.ts +16 -0
  26. package/esm/types/src/data/EmptyDataValue.d.ts +14 -0
  27. package/esm/types/src/index.d.ts +24 -0
  28. package/esm/types/src/rules/FunctionRuntime.d.ts +62 -0
  29. package/esm/types/src/rules/RuleEngine.d.ts +16 -0
  30. package/esm/types/src/types/Json.d.ts +180 -0
  31. package/esm/types/src/types/Model.d.ts +141 -0
  32. package/esm/types/src/types/index.d.ts +2 -0
  33. package/esm/types/src/utils/CoercionUtils.d.ts +1 -0
  34. package/esm/types/src/utils/DataRefParser.d.ts +33 -0
  35. package/esm/types/src/utils/Fetch.d.ts +8 -0
  36. package/esm/types/src/utils/FormCreationUtils.d.ts +10 -0
  37. package/esm/types/src/utils/FormUtils.d.ts +14 -0
  38. package/esm/types/src/utils/JsonUtils.d.ts +13 -0
  39. package/esm/types/src/utils/LogUtils.d.ts +4 -0
  40. package/esm/types/src/utils/SchemaUtils.d.ts +3 -0
  41. package/esm/types/src/utils/TranslationUtils.d.ts +11 -0
  42. package/esm/types/src/utils/ValidationUtils.d.ts +20 -0
  43. package/lib/BaseNode.d.ts +9 -5
  44. package/lib/BaseNode.js +19 -3
  45. package/lib/CheckboxGroup.d.ts +2 -1
  46. package/lib/Container.d.ts +12 -5
  47. package/lib/Container.js +48 -28
  48. package/lib/Field.d.ts +9 -3
  49. package/lib/Field.js +17 -15
  50. package/lib/Fieldset.d.ts +2 -1
  51. package/lib/Fieldset.js +5 -3
  52. package/lib/Form.d.ts +10 -6
  53. package/lib/Form.js +15 -11
  54. package/lib/FormInstance.d.ts +3 -0
  55. package/lib/FormInstance.js +16 -1
  56. package/lib/controller/EventQueue.d.ts +1 -0
  57. package/lib/controller/EventQueue.js +3 -0
  58. package/lib/types/Model.d.ts +2 -1
  59. package/lib/utils/FormCreationUtils.d.ts +2 -1
  60. package/package.json +5 -3
package/lib/Field.js CHANGED
@@ -24,9 +24,11 @@ class Field extends Scriptable_1.default {
24
24
  constructor(params, _options) {
25
25
  super(params, _options);
26
26
  this._ruleNodeReference = [];
27
- this._applyDefaults();
28
- this.queueEvent(new Events_1.Initialize());
29
- this.queueEvent(new Events_1.ExecuteRule());
27
+ if (_options.mode !== 'restore') {
28
+ this._applyDefaults();
29
+ this.queueEvent(new Events_1.Initialize());
30
+ this.queueEvent(new Events_1.ExecuteRule());
31
+ }
30
32
  }
31
33
  _initialize() {
32
34
  super._initialize();
@@ -143,11 +145,11 @@ class Field extends Scriptable_1.default {
143
145
  }
144
146
  this.coerceParam('minLength', 'number');
145
147
  this.coerceParam('maxLength', 'number');
146
- if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date') {
148
+ if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.type !== 'integer') {
147
149
  this.unset('step', ...props);
148
150
  }
149
151
  props.forEach(c => {
150
- this.coerceParam(c, this._jsonModel.type);
152
+ this.coerceParam(c, this._jsonModel.type === 'integer' ? 'number' : this._jsonModel.type);
151
153
  });
152
154
  if (typeof this._jsonModel.step !== 'number') {
153
155
  this.coerceParam('step', 'number');
@@ -244,22 +246,22 @@ class Field extends Scriptable_1.default {
244
246
  this._setProperty('required', r);
245
247
  }
246
248
  get maximum() {
247
- if (this.type === 'number' || this.format === 'date') {
249
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
248
250
  return this._jsonModel.maximum;
249
251
  }
250
252
  }
251
253
  set maximum(m) {
252
- if (this.type === 'number' || this.format === 'date') {
254
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
253
255
  this._setProperty('maximum', m);
254
256
  }
255
257
  }
256
258
  get minimum() {
257
- if (this.type === 'number' || this.format === 'date') {
259
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
258
260
  return this._jsonModel.minimum;
259
261
  }
260
262
  }
261
263
  set minimum(m) {
262
- if (this.type === 'number' || this.format === 'date') {
264
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
263
265
  this._setProperty('minimum', m);
264
266
  }
265
267
  }
@@ -545,22 +547,22 @@ class Field extends Scriptable_1.default {
545
547
  }
546
548
  }
547
549
  get exclusiveMinimum() {
548
- if (this.type === 'number' || this.format === 'date') {
550
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
549
551
  return this._jsonModel.exclusiveMinimum;
550
552
  }
551
553
  }
552
554
  set exclusiveMinimum(eM) {
553
- if (this.type === 'number' || this.format === 'date') {
555
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
554
556
  this._jsonModel.exclusiveMinimum = eM;
555
557
  }
556
558
  }
557
559
  get exclusiveMaximum() {
558
- if (this.type === 'number' || this.format === 'date') {
560
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
559
561
  return this._jsonModel.exclusiveMaximum;
560
562
  }
561
563
  }
562
564
  set exclusiveMaximum(eM) {
563
- if (this.type === 'number' || this.format === 'date') {
565
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
564
566
  this._jsonModel.exclusiveMaximum = eM;
565
567
  }
566
568
  }
@@ -666,8 +668,8 @@ class Field extends Scriptable_1.default {
666
668
  const value = BaseNode_1.staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
667
669
  return new DataValue_1.default(name, value, this.type || 'string');
668
670
  }
669
- getState() {
670
- 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 });
671
+ getState(isRepeatableChild = false, forRestore = false) {
672
+ return Object.assign(Object.assign({}, super.getState(forRestore)), { editFormat: this.editFormat, displayFormat: this.displayFormat, editValue: this.editValue, displayValue: this.displayValue, enabled: this.enabled, readOnly: this.readOnly });
671
673
  }
672
674
  markAsInvalid(message, constraint = null) {
673
675
  const changes = {
package/lib/Fieldset.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import Container from './Container';
2
- import { ContainerModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from './types/index';
2
+ import { ContainerModel, FieldsetJson, FieldsetModel, FormCreationMode, 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
+ mode?: FormCreationMode;
8
9
  });
9
10
  protected _getDefaults(): any;
10
11
  private _applyDefaults;
package/lib/Fieldset.js CHANGED
@@ -9,9 +9,11 @@ const Events_1 = require("./controller/Events");
9
9
  class Fieldset extends Container_1.default {
10
10
  constructor(params, _options) {
11
11
  super(params, _options);
12
- this._applyDefaults();
13
- this.queueEvent(new Events_1.Initialize());
14
- this.queueEvent(new Events_1.ExecuteRule());
12
+ if (_options.mode !== 'restore') {
13
+ this._applyDefaults();
14
+ this.queueEvent(new Events_1.Initialize());
15
+ this.queueEvent(new Events_1.ExecuteRule());
16
+ }
15
17
  }
16
18
  _getDefaults() {
17
19
  return Object.assign(Object.assign({}, super._getDefaults()), { visible: true, required: false, label: {
package/lib/Form.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import Container from './Container';
2
- import { Action, BaseModel, FieldModel, FieldsetModel, FormJson, FormModel, IFormFieldFactory } from './types/index';
2
+ import { Action, BaseModel, FieldModel, FieldsetModel, FormCreationMode, FormJson, FocusOption, FormModel, IFormFieldFactory } from './types/index';
3
3
  import FormMetaData from './FormMetaData';
4
4
  import SubmitMetaData from './SubmitMetaData';
5
5
  import EventQueue from './controller/EventQueue';
6
6
  import { Logger, LogLevel } from './controller/Logger';
7
7
  import RuleEngine from './rules/RuleEngine';
8
- import { FocusOption } from './types/Model';
9
8
  declare class Form extends Container<FormJson> implements FormModel {
10
9
  #private;
11
10
  private _ruleEngine;
@@ -13,8 +12,8 @@ declare class Form extends Container<FormJson> implements FormModel {
13
12
  private _fields;
14
13
  _ids: Generator<string, void, string>;
15
14
  private _invalidFields;
15
+ constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
16
16
  private _logger;
17
- constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel);
18
17
  get logger(): Logger;
19
18
  private dataRefRegex;
20
19
  get metaData(): FormMetaData;
@@ -24,7 +23,7 @@ declare class Form extends Container<FormJson> implements FormModel {
24
23
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
25
24
  exportSubmitMetaData(): SubmitMetaData;
26
25
  setFocus(field: BaseModel, focusOption: FocusOption): void;
27
- getState(): {
26
+ getState(forRestore?: boolean): {
28
27
  description?: string | undefined;
29
28
  } & import("./types/Json").RulesJson & {
30
29
  enumNames?: string[] | import("./types/Json").EnumName[] | undefined;
@@ -85,14 +84,19 @@ declare class Form extends Container<FormJson> implements FormModel {
85
84
  items: any[];
86
85
  enabled: boolean | undefined;
87
86
  readOnly: any;
87
+ ':items'?: undefined;
88
+ ':itemsOrder'?: undefined;
89
+ _dependents?: string[] | undefined;
90
+ allowedComponents?: undefined;
91
+ columnClassNames?: undefined;
92
+ columnCount?: undefined;
93
+ gridClassNames?: undefined;
88
94
  properties: {
89
95
  [key: string]: any;
90
96
  };
91
97
  index: number;
92
98
  parent: undefined;
93
99
  qualifiedName: any;
94
- events: {};
95
- rules: {};
96
100
  repeatable: boolean | undefined;
97
101
  ':type': string;
98
102
  id: string;
package/lib/Form.js CHANGED
@@ -10,6 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  var _Form_instances, _Form_getNavigableChildren, _Form_getFirstNavigableChild, _Form_setActiveFirstDeepChild, _Form_getNextItem, _Form_getPreviousItem, _Form_clearCurrentFocus;
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const Container_1 = __importDefault(require("./Container"));
13
+ const index_1 = require("./types/index");
13
14
  const FormMetaData_1 = __importDefault(require("./FormMetaData"));
14
15
  const SubmitMetaData_1 = __importDefault(require("./SubmitMetaData"));
15
16
  const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
@@ -18,10 +19,9 @@ const FormUtils_1 = require("./utils/FormUtils");
18
19
  const DataGroup_1 = __importDefault(require("./data/DataGroup"));
19
20
  const FunctionRuntime_1 = require("./rules/FunctionRuntime");
20
21
  const Events_1 = require("./controller/Events");
21
- const Model_1 = require("./types/Model");
22
22
  class Form extends Container_1.default {
23
- constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off') {
24
- super(n, { fieldFactory: fieldFactory });
23
+ constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off', mode = 'create') {
24
+ super(n, { fieldFactory: fieldFactory, mode });
25
25
  this._ruleEngine = _ruleEngine;
26
26
  this._eventQueue = _eventQueue;
27
27
  _Form_instances.add(this);
@@ -29,12 +29,16 @@ class Form extends Container_1.default {
29
29
  this._invalidFields = [];
30
30
  this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
31
31
  this._logger = new Logger_1.Logger(logLevel);
32
- this.queueEvent(new Events_1.Initialize());
33
- this.queueEvent(new Events_1.ExecuteRule());
32
+ if (mode === 'create') {
33
+ this.queueEvent(new Events_1.Initialize());
34
+ this.queueEvent(new Events_1.ExecuteRule());
35
+ }
34
36
  this._ids = (0, FormUtils_1.IdGenerator)();
35
37
  this._bindToDataModel(new DataGroup_1.default('$form', {}));
36
- this._initialize();
37
- this.queueEvent(new Events_1.FormLoad());
38
+ this._initialize(mode);
39
+ if (mode === 'create') {
40
+ this.queueEvent(new Events_1.FormLoad());
41
+ }
38
42
  }
39
43
  get logger() {
40
44
  return this._logger;
@@ -96,19 +100,19 @@ class Form extends Container_1.default {
96
100
  currActiveChildIndex = 0;
97
101
  return;
98
102
  }
99
- if (focusOption === Model_1.FocusOption.NEXT_ITEM) {
103
+ if (focusOption === index_1.FocusOption.NEXT_ITEM) {
100
104
  activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNextItem).call(this, currActiveChildIndex, navigableChidren);
101
105
  }
102
- else if (focusOption === Model_1.FocusOption.PREVIOUS_ITEM) {
106
+ else if (focusOption === index_1.FocusOption.PREVIOUS_ITEM) {
103
107
  activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getPreviousItem).call(this, currActiveChildIndex, navigableChidren);
104
108
  }
105
109
  if (activeChild !== null) {
106
110
  __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, activeChild);
107
111
  }
108
112
  }
109
- getState() {
113
+ getState(forRestore = false) {
110
114
  const self = this;
111
- const res = super.getState();
115
+ const res = super.getState(false, forRestore);
112
116
  res.id = '$form';
113
117
  Object.defineProperty(res, 'data', {
114
118
  get: function () {
@@ -2,6 +2,9 @@ import { FormModel } from './types/index';
2
2
  import { LogLevel } from './controller/Logger';
3
3
  import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
4
4
  export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
5
+ export declare const restoreFormInstance: (formModel: any, { logLevel }?: {
6
+ logLevel: LogLevel;
7
+ }) => FormModel;
5
8
  export declare const validateFormInstance: (formModel: any, data: any) => boolean;
6
9
  export declare const validateFormData: (formModel: any, data: any) => {
7
10
  messages: any[];
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.createFormInstance = void 0;
6
+ exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.restoreFormInstance = exports.createFormInstance = void 0;
7
7
  const Form_1 = __importDefault(require("./Form"));
8
8
  const JsonUtils_1 = require("./utils/JsonUtils");
9
9
  const Fetch_1 = require("./utils/Fetch");
@@ -36,6 +36,21 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
36
36
  }
37
37
  };
38
38
  exports.createFormInstance = createFormInstance;
39
+ const defaultOptions = {
40
+ logLevel: 'error'
41
+ };
42
+ const restoreFormInstance = (formModel, { logLevel } = defaultOptions) => {
43
+ try {
44
+ const form = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel, 'restore');
45
+ form.getEventQueue().empty();
46
+ return form;
47
+ }
48
+ catch (e) {
49
+ console.error(`Unable to restore an instance of the Form ${e}`);
50
+ throw new Error(e);
51
+ }
52
+ };
53
+ exports.restoreFormInstance = restoreFormInstance;
39
54
  const validateFormInstance = (formModel, data) => {
40
55
  try {
41
56
  const f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default());
@@ -12,6 +12,7 @@ declare class EventQueue {
12
12
  get isProcessing(): boolean;
13
13
  isQueued<T extends BaseJson>(node: BaseNode<T>, event: Action): boolean;
14
14
  queue<T extends BaseJson>(node: BaseNode<T>, events: Action | Action[], priority?: boolean): void;
15
+ empty(): void;
15
16
  runPendingQueue(): void;
16
17
  }
17
18
  export default EventQueue;
@@ -65,6 +65,9 @@ class EventQueue {
65
65
  }
66
66
  });
67
67
  }
68
+ empty() {
69
+ this._pendingEvents = [];
70
+ }
68
71
  runPendingQueue() {
69
72
  if (this._isProcessing) {
70
73
  return;
@@ -39,6 +39,7 @@ export interface WithController {
39
39
  subscribe(callback: callbackFn, eventName?: string): Subscription;
40
40
  dispatch(action: Action): void;
41
41
  }
42
+ export declare type FormCreationMode = 'create' | 'restore';
42
43
  export interface BaseModel extends ConstraintsJson, WithController {
43
44
  readonly lang?: string;
44
45
  readonly name?: string;
@@ -69,7 +70,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
69
70
  importData(a?: DataGroup): any;
70
71
  getRuleNode(): any;
71
72
  ruleNodeReference(): any;
72
- _initialize(): any;
73
+ _initialize(mode?: FormCreationMode): any;
73
74
  _addDependent(dependent: BaseModel): any;
74
75
  }
75
76
  export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJson> {
@@ -1,8 +1,9 @@
1
- import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from '../types/index';
1
+ import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormCreationMode, FormModel, IFormFieldFactory } from '../types/index';
2
2
  declare class FormFieldFactoryImpl implements IFormFieldFactory {
3
3
  createField(child: FieldsetJson | FieldJson, _options: {
4
4
  form: FormModel;
5
5
  parent: ContainerModel;
6
+ mode: FormCreationMode;
6
7
  }): FieldModel | FieldsetModel;
7
8
  }
8
9
  export declare const FormFieldFactory: FormFieldFactoryImpl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.68",
3
+ "version": "0.22.70",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -17,6 +17,7 @@
17
17
  "outputDirectory": "./target/test-reports"
18
18
  },
19
19
  "files": [
20
+ "esm",
20
21
  "lib",
21
22
  "LICENSE"
22
23
  ],
@@ -28,14 +29,15 @@
28
29
  "eslint": "npx eslint src/**",
29
30
  "eslint:fix": "npx eslint --fix src/**",
30
31
  "test:ci": "jest --silent --coverage",
31
- "build": "npm run eslint && npx tsc",
32
+ "build": "npm run eslint && npx tsc && npm run build:esm",
33
+ "build:esm": "rollup -c rollup.config.mjs",
32
34
  "clean": "rm -rf lib target",
33
35
  "prepublishOnly": "npm run build && npm run test",
34
36
  "docs": "npx typedoc --options .typedoc.cjs"
35
37
  },
36
38
  "dependencies": {
37
39
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.68"
40
+ "@aemforms/af-formatters": "^0.22.70"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@babel/preset-env": "^7.20.2",