@aemforms/af-core 0.22.67 → 0.22.69

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 (58) 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 +99 -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 +23 -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 +223 -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 +8 -5
  44. package/lib/BaseNode.js +19 -3
  45. package/lib/Container.d.ts +12 -5
  46. package/lib/Container.js +43 -19
  47. package/lib/Field.d.ts +8 -3
  48. package/lib/Field.js +12 -12
  49. package/lib/Fieldset.d.ts +2 -1
  50. package/lib/Form.d.ts +10 -6
  51. package/lib/Form.js +34 -12
  52. package/lib/FormInstance.d.ts +3 -0
  53. package/lib/FormInstance.js +16 -1
  54. package/lib/controller/EventQueue.d.ts +1 -0
  55. package/lib/controller/EventQueue.js +3 -0
  56. package/lib/types/Model.d.ts +2 -1
  57. package/lib/utils/FormCreationUtils.d.ts +2 -1
  58. package/package.json +5 -3
@@ -0,0 +1,141 @@
1
+ import { ConstraintsJson, ContainerJson, FieldJson, FieldsetJson, FormJson, Label, MetaDataJson } from './Json';
2
+ import RuleEngine from '../rules/RuleEngine';
3
+ import EventQueue from '../controller/EventQueue';
4
+ import DataGroup from '../data/DataGroup';
5
+ import { Logger } from '../controller/Logger';
6
+ export interface ScriptableField {
7
+ rules?: {
8
+ [key: string]: string;
9
+ };
10
+ events?: {
11
+ [key: string]: string;
12
+ };
13
+ ruleEngine: RuleEngine;
14
+ }
15
+ interface WithState<T> {
16
+ getState: () => any;
17
+ }
18
+ type stateProps = {
19
+ id: string;
20
+ index: number;
21
+ ':type': string;
22
+ };
23
+ export type State<T> = stateProps & (T extends ContainerJson ? T & {
24
+ items: Array<State<FieldJson | ContainerJson>>;
25
+ } : T);
26
+ export type Subscription = {
27
+ unsubscribe(): void;
28
+ };
29
+ export interface Action {
30
+ type: string;
31
+ payload: any;
32
+ metadata: any;
33
+ readonly isCustomEvent: boolean;
34
+ readonly target: FormModel | FieldModel | FieldsetModel;
35
+ readonly originalAction?: Action;
36
+ }
37
+ export type callbackFn = (action: Action) => void;
38
+ export interface WithController {
39
+ subscribe(callback: callbackFn, eventName?: string): Subscription;
40
+ dispatch(action: Action): void;
41
+ }
42
+ export type FormCreationMode = 'create' | 'restore';
43
+ export interface BaseModel extends ConstraintsJson, WithController {
44
+ readonly lang?: string;
45
+ readonly name?: string;
46
+ readonly dataRef?: string | null;
47
+ readonly id: string;
48
+ readonly index: number;
49
+ readonly qualifiedName: string;
50
+ label?: Label;
51
+ description?: string;
52
+ readOnly?: boolean;
53
+ enabled?: boolean;
54
+ visible?: boolean;
55
+ placeholder?: string;
56
+ valid?: boolean;
57
+ readonly ':type': string;
58
+ readonly 'fieldType': string;
59
+ properties: {
60
+ [key: string]: any;
61
+ };
62
+ readonly isContainer: boolean;
63
+ readonly parent: ContainerModel | null;
64
+ readonly items?: Array<FieldsetModel | FieldModel>;
65
+ value: any;
66
+ readonly default?: any;
67
+ readonly repeatable?: boolean;
68
+ validate(): Array<ValidationError>;
69
+ reset(): any;
70
+ importData(a?: DataGroup): any;
71
+ getRuleNode(): any;
72
+ ruleNodeReference(): any;
73
+ _initialize(mode?: FormCreationMode): any;
74
+ _addDependent(dependent: BaseModel): any;
75
+ }
76
+ export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJson> {
77
+ parent: ContainerModel;
78
+ readonly editFormat?: string;
79
+ readonly displayFormat?: string;
80
+ readonly displayValue?: string;
81
+ readonly editValue?: string;
82
+ }
83
+ export interface FormMetaDataModel {
84
+ readonly version: string;
85
+ readonly grammar: string;
86
+ }
87
+ export interface SubmitMetaDataModel {
88
+ lang: string;
89
+ captchaInfo: Record<string, any>;
90
+ }
91
+ export interface ContainerModel extends BaseModel, ScriptableField {
92
+ items: Array<FieldsetModel | FieldModel>;
93
+ parent: ContainerModel;
94
+ indexOf(f: FieldModel | FieldsetModel): number;
95
+ isTransparent(): boolean;
96
+ activeChild: BaseModel | null;
97
+ }
98
+ export interface FieldsetModel extends ContainerModel, WithState<FieldsetJson> {
99
+ type?: 'array' | 'object';
100
+ }
101
+ export interface FormModel extends ContainerModel, WithState<FormJson> {
102
+ readonly id: string;
103
+ readonly data?: any;
104
+ readonly metadata?: MetaDataJson;
105
+ readonly title: string;
106
+ readonly logger: Logger;
107
+ importData(data: any): any;
108
+ exportData(): any;
109
+ getElement(id: string): FieldModel | FormModel | FieldsetModel;
110
+ getUniqueId(): string;
111
+ getEventQueue(): EventQueue;
112
+ visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
113
+ resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
114
+ fieldAdded(field: FieldModel | FieldsetModel): void;
115
+ }
116
+ export interface IFormFieldFactory {
117
+ createField(child: FieldsetJson | FieldJson, options: {
118
+ form: FormModel;
119
+ parent: ContainerModel;
120
+ }): FieldModel | FieldsetModel;
121
+ }
122
+ export interface IFileObject {
123
+ name: string;
124
+ mediaType: string;
125
+ data?: any;
126
+ size?: number;
127
+ }
128
+ export interface IValidationError {
129
+ fieldName: string;
130
+ errorMessages: Array<string>;
131
+ }
132
+ export declare class ValidationError implements IValidationError {
133
+ fieldName: string;
134
+ errorMessages: Array<string>;
135
+ constructor(fieldName?: string, errorMessages?: Array<any>);
136
+ }
137
+ export declare enum FocusOption {
138
+ NEXT_ITEM = "nextItem",
139
+ PREVIOUS_ITEM = "previousItem"
140
+ }
141
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './Json';
2
+ export * from './Model';
@@ -0,0 +1 @@
1
+ export declare function stringToNumber(str: string, language: string): number;
@@ -0,0 +1,33 @@
1
+ import DataGroup from '../data/DataGroup';
2
+ import DataValue from '../data/DataValue';
3
+ type TokenType = string;
4
+ export declare const TOK_GLOBAL: TokenType;
5
+ export declare const TOK_REPEATABLE: TokenType;
6
+ export type Token = {
7
+ type: TokenType;
8
+ value: string | number;
9
+ start: number;
10
+ };
11
+ export declare const identifier: (value: string, start: number) => {
12
+ type: string;
13
+ value: string;
14
+ start: number;
15
+ };
16
+ export declare const bracket: (value: number, start: number) => {
17
+ type: string;
18
+ value: number;
19
+ start: number;
20
+ };
21
+ export declare const global$: () => {
22
+ type: string;
23
+ start: number;
24
+ value: string;
25
+ };
26
+ export declare const repeatable: () => {
27
+ type: string;
28
+ start: number;
29
+ value: string;
30
+ };
31
+ export declare const tokenize: (stream: string) => Token[];
32
+ export declare const resolveData: <T extends DataValue>(data: DataGroup, input: Token[] | string, create?: T | undefined) => DataGroup | DataValue | undefined;
33
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
2
+ export type RequestOptions = {
3
+ contentType?: string;
4
+ method?: 'POST' | 'GET';
5
+ headers?: any;
6
+ mode?: string;
7
+ };
8
+ export declare const convertQueryString: (endpoint: string, payload: string | null) => string;
@@ -0,0 +1,10 @@
1
+ import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormCreationMode, FormModel, IFormFieldFactory } from '../types/index';
2
+ declare class FormFieldFactoryImpl implements IFormFieldFactory {
3
+ createField(child: FieldsetJson | FieldJson, _options: {
4
+ form: FormModel;
5
+ parent: ContainerModel;
6
+ mode: FormCreationMode;
7
+ }): FieldModel | FieldsetModel;
8
+ }
9
+ export declare const FormFieldFactory: FormFieldFactoryImpl;
10
+ export {};
@@ -0,0 +1,14 @@
1
+ import { ContainerModel } from '../types/index';
2
+ export declare const randomWord: (l: number) => string;
3
+ export declare const isEmpty: (value: any) => boolean;
4
+ export declare const getAttachments: (input: ContainerModel, excludeUnbound?: boolean) => any;
5
+ export declare const getFileSizeInBytes: (str: any) => number;
6
+ export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
7
+ export declare const isDataUrl: (str: string) => boolean;
8
+ export declare const extractFileInfo: (file: any) => any;
9
+ export declare const dataURItoBlob: (dataURI: string) => {
10
+ name: string;
11
+ blob: Blob;
12
+ } | null;
13
+ export declare const sitesModelToFormModel: (sitesModel: any) => any;
14
+ export declare const replaceTemplatePlaceholders: (str: string, values?: any[]) => string;
@@ -0,0 +1,13 @@
1
+ import { FieldsetJson, FieldJson } from '../types/index';
2
+ export declare const getProperty: <P>(data: any, key: string, def: P) => P;
3
+ export declare const isFile: (item: FieldsetJson | FieldJson) => boolean;
4
+ export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJson) => boolean;
5
+ export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
6
+ export declare const isCheckboxGroup: (item: FieldsetJson | FieldJson) => boolean;
7
+ export declare const isEmailInput: (item: FieldsetJson | FieldJson) => boolean;
8
+ export declare const isDateField: (item: FieldsetJson | FieldJson) => boolean;
9
+ export declare const isCaptcha: (item: FieldsetJson | FieldJson) => boolean;
10
+ export declare function deepClone(obj: any, idGenerator?: () => string): any;
11
+ export declare function checkIfKeyAdded(currentObj: any, prevObj: any, objKey: string): boolean;
12
+ export declare const jsonString: (obj: any) => string;
13
+ export declare const isRepeatable: (obj: FieldsetJson | FieldJson) => boolean;
@@ -0,0 +1,4 @@
1
+ import { callbackFn } from '../types/index';
2
+ export declare const logFormCallbacks: (callbacks: {
3
+ [key: string]: callbackFn[];
4
+ }) => void;
@@ -0,0 +1,3 @@
1
+ import { FormJson } from '../types/index';
2
+ export declare const defaultFieldTypes: (schema: any) => string;
3
+ export declare const exportDataSchema: (form: FormJson) => any;
@@ -0,0 +1,11 @@
1
+ import { FieldJson, FieldsetJson, FormJson } from '../types/index';
2
+ export declare const TRANSLATION_TOKEN = "##";
3
+ export declare const TRANSLATION_ID = "afs:translationIds";
4
+ export declare const CUSTOM_PROPS_KEY = "properties";
5
+ type formElementJson = FieldJson | FieldsetJson | FormJson | any;
6
+ export declare const invalidateTranslation: (input: formElementJson, updates: any) => void;
7
+ export declare const addTranslationId: (input: formElementJson, additionalTranslationProps?: string[]) => formElementJson;
8
+ export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
9
+ export declare const createTranslationObj: (input: formElementJson, additionalTranslationProps?: string[]) => any;
10
+ export declare const createTranslationObject: (input: formElementJson, additionalTranslationProps?: string[], bcp47LangTags?: string[]) => any;
11
+ export {};
@@ -0,0 +1,20 @@
1
+ type ValidationResult = {
2
+ valid: boolean;
3
+ value: any;
4
+ };
5
+ export declare const coerceType: (param: any, type: 'string' | 'number' | 'boolean') => string | number | boolean;
6
+ type ValidConstraintsType = {
7
+ date: ValidationConstraints[];
8
+ string: ValidationConstraints[];
9
+ number: ValidationConstraints[];
10
+ array: ValidationConstraints[];
11
+ file: ValidationConstraints[];
12
+ email: ValidationConstraints[];
13
+ };
14
+ export declare const ValidConstraints: ValidConstraintsType;
15
+ export type ValidationConstraints = 'type' | 'format' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minItems' | 'maxItems' | 'uniqueItems' | 'minLength' | 'maxLength' | 'pattern' | 'required' | 'enum' | 'accept' | 'maxFileSize';
16
+ type ConstraintsObject = {
17
+ [key in ValidationConstraints]: (constraint: any, inputVal: any) => ValidationResult;
18
+ };
19
+ export declare const Constraints: ConstraintsObject;
20
+ export {};
package/lib/BaseNode.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormModel, Primitives, ValidationError } from './types/index';
1
+ import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError } from './types/index';
2
2
  import DataGroup from './data/DataGroup';
3
3
  import DataValue from './data/DataValue';
4
4
  export declare const editableProperties: string[];
@@ -49,15 +49,18 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
49
49
  set label(l: import("./types/Json").Label | undefined);
50
50
  get uniqueItems(): boolean | undefined;
51
51
  isTransparent(): boolean;
52
- getState(isRepeatableChild?: boolean): T & {
52
+ getState(forRestore?: boolean): T & {
53
+ _dependents?: string[] | undefined;
54
+ allowedComponents?: undefined;
55
+ columnClassNames?: undefined;
56
+ columnCount?: undefined;
57
+ gridClassNames?: undefined;
53
58
  properties: {
54
59
  [key: string]: any;
55
60
  };
56
61
  index: number;
57
62
  parent: undefined;
58
63
  qualifiedName: any;
59
- events: {};
60
- rules: {};
61
64
  repeatable: boolean | undefined;
62
65
  ':type': string;
63
66
  id: string;
@@ -87,7 +90,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
87
90
  abstract defaultDataModel(name: string | number): DataValue | undefined;
88
91
  abstract importData(a: DataGroup): any;
89
92
  getNonTransparentParent(): ContainerModel;
90
- _initialize(): void;
93
+ _initialize(mode?: FormCreationMode): void;
91
94
  protected _applyUpdates(propNames: string[], updates: any): any;
92
95
  get qualifiedName(): any;
93
96
  focus(): void;
package/lib/BaseNode.js CHANGED
@@ -238,8 +238,14 @@ class BaseNode {
238
238
  const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array';
239
239
  return !this._jsonModel.name && !isNonTransparent;
240
240
  }
241
- getState(isRepeatableChild = false) {
242
- return Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName, events: {}, rules: {}, repeatable: this.repeatable === true ? true : undefined, ':type': this[':type'] });
241
+ getState(forRestore = false) {
242
+ return Object.assign(Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName, repeatable: this.repeatable === true ? true : undefined, ':type': this[':type'] }), (forRestore ? {
243
+ _dependents: this._dependents.length ? this._dependents.map(x => x.node.id) : undefined,
244
+ allowedComponents: undefined,
245
+ columnClassNames: undefined,
246
+ columnCount: undefined,
247
+ gridClassNames: undefined
248
+ } : {}));
243
249
  }
244
250
  subscribe(callback, eventName = 'change') {
245
251
  this._callbacks[eventName] = this._callbacks[eventName] || [];
@@ -281,6 +287,16 @@ class BaseNode {
281
287
  this.form.getEventQueue().runPendingQueue();
282
288
  }
283
289
  notifyDependents(action) {
290
+ const depsToRestore = this._jsonModel._dependents;
291
+ if (depsToRestore) {
292
+ depsToRestore.forEach((x) => {
293
+ const node = this.form.getElement(x);
294
+ if (node) {
295
+ this._addDependent(node);
296
+ }
297
+ });
298
+ this._jsonModel._dependents = undefined;
299
+ }
284
300
  const handlers = this._callbacks[action.type] || [];
285
301
  handlers.forEach(x => {
286
302
  x(new ActionImplWithTarget(action, this));
@@ -403,7 +419,7 @@ class BaseNode {
403
419
  }
404
420
  return nonTransparentParent;
405
421
  }
406
- _initialize() {
422
+ _initialize(mode) {
407
423
  if (typeof this._data === 'undefined') {
408
424
  let dataNode, parent = this.parent;
409
425
  do {
@@ -1,4 +1,4 @@
1
- import { Action, BaseModel, ContainerJson, ContainerModel, FieldModel, FieldsetModel, FormModel, IFormFieldFactory, RulesJson } from './types/index';
1
+ import { Action, BaseModel, ContainerJson, ContainerModel, FieldModel, FieldsetModel, FormCreationMode, FormModel, IFormFieldFactory, RulesJson } from './types/index';
2
2
  import Scriptable from './Scriptable';
3
3
  import DataGroup from './data/DataGroup';
4
4
  declare abstract class Container<T extends ContainerJson & RulesJson> extends Scriptable<T> implements ContainerModel {
@@ -10,6 +10,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
10
10
  form: FormModel;
11
11
  parent: ContainerModel;
12
12
  fieldFactory: IFormFieldFactory;
13
+ mode: 'create' | 'restore';
13
14
  });
14
15
  protected _getDefaults(): any;
15
16
  ruleNodeReference(): any;
@@ -25,18 +26,23 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
25
26
  private isAFormField;
26
27
  private _getFormAndSitesState;
27
28
  private getItemsState;
28
- getState(isRepeatableChild?: boolean): T & {
29
+ getState(isRepeatableChild?: boolean, forRestore?: boolean): T & {
29
30
  items: any[];
30
31
  enabled: boolean | undefined;
31
32
  readOnly: any;
33
+ ':items'?: undefined;
34
+ ':itemsOrder'?: undefined;
35
+ _dependents?: string[] | undefined;
36
+ allowedComponents?: undefined;
37
+ columnClassNames?: undefined;
38
+ columnCount?: undefined;
39
+ gridClassNames?: undefined;
32
40
  properties: {
33
41
  [key: string]: any;
34
42
  };
35
43
  index: number;
36
44
  parent: undefined;
37
45
  qualifiedName: any;
38
- events: {};
39
- rules: {};
40
46
  repeatable: boolean | undefined;
41
47
  ':type': string;
42
48
  id: string;
@@ -47,7 +53,8 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
47
53
  private _addChild;
48
54
  indexOf(f: FieldModel | FieldsetModel): number;
49
55
  defaultDataModel(name: string): DataGroup | undefined;
50
- _initialize(): void;
56
+ _canHaveRepeatingChildren(mode?: FormCreationMode): boolean;
57
+ _initialize(mode?: FormCreationMode): void;
51
58
  private _initializeSiteContainer;
52
59
  addItem(action: Action): void;
53
60
  removeItem(action: Action): void;
package/lib/Container.js CHANGED
@@ -79,37 +79,40 @@ class Container extends Scriptable_1.default {
79
79
  isAFormField(item) {
80
80
  return ('fieldType' in item || 'id' in item || 'name' in item || 'dataRef' in item || 'type' in item);
81
81
  }
82
- _getFormAndSitesState(isRepeatableChild = false) {
82
+ _getFormAndSitesState(isRepeatableChild = false, forRestore = false) {
83
83
  return this._jsonModel.items ? this._jsonModel.items.map((x) => {
84
84
  if (this.isSiteContainer(x)) {
85
85
  const newObjWithId = Object.assign({}, ((x === null || x === void 0 ? void 0 : x.id) ? { id: this.form.getUniqueId() } : {}));
86
86
  return Object.assign(Object.assign(Object.assign({}, x), newObjWithId), { ':items': this.walkSiteContainerItems(x) });
87
87
  }
88
88
  else if (this.isAFormField(x)) {
89
- return Object.assign({}, this.form.getElement(x === null || x === void 0 ? void 0 : x.id).getState(isRepeatableChild));
89
+ return Object.assign({}, this.form.getElement(x === null || x === void 0 ? void 0 : x.id).getState(isRepeatableChild, forRestore));
90
90
  }
91
91
  else {
92
92
  return x;
93
93
  }
94
94
  }) : [];
95
95
  }
96
- getItemsState(isRepeatableChild = false) {
96
+ getItemsState(isRepeatableChild = false, forRestore = false) {
97
97
  if (this._jsonModel.type === 'array' || (0, JsonUtils_1.isRepeatable)(this._jsonModel) || isRepeatableChild) {
98
98
  if (isRepeatableChild) {
99
- return this._getFormAndSitesState(isRepeatableChild);
99
+ return this._getFormAndSitesState(isRepeatableChild, forRestore);
100
100
  }
101
101
  else {
102
102
  return this._children.map(x => {
103
- return Object.assign({}, x.getState(true));
103
+ return Object.assign({}, x.getState(true, forRestore));
104
104
  });
105
105
  }
106
106
  }
107
107
  else {
108
- return this._getFormAndSitesState(isRepeatableChild);
108
+ return this._getFormAndSitesState(isRepeatableChild, forRestore);
109
109
  }
110
110
  }
111
- getState(isRepeatableChild = false) {
112
- return Object.assign(Object.assign({}, super.getState(isRepeatableChild)), { items: this.getItemsState(isRepeatableChild), enabled: this.enabled, readOnly: this.readOnly });
111
+ getState(isRepeatableChild = false, forRestore = false) {
112
+ return Object.assign(Object.assign(Object.assign({}, super.getState(forRestore)), (forRestore ? {
113
+ ':items': undefined,
114
+ ':itemsOrder': undefined
115
+ } : {})), { items: this.getItemsState(isRepeatableChild, forRestore), enabled: this.enabled, readOnly: this.readOnly });
113
116
  }
114
117
  _createChild(child, options) {
115
118
  const { parent = this } = options;
@@ -128,7 +131,7 @@ class Container extends Scriptable_1.default {
128
131
  }
129
132
  else {
130
133
  if (typeof value === 'object') {
131
- const newObjWithId = Object.assign({}, ((value === null || value === void 0 ? void 0 : value.id) ? { 'id': this.form.getUniqueId() } : {}));
134
+ const newObjWithId = Object.assign({}, ((value === null || value === void 0 ? void 0 : value.id) ? { id: this.form.getUniqueId() } : {}));
132
135
  return [key, Object.assign(Object.assign({}, value), newObjWithId)];
133
136
  }
134
137
  else {
@@ -197,12 +200,20 @@ class Container extends Scriptable_1.default {
197
200
  return new DataGroup_1.default(name, instance, type);
198
201
  }
199
202
  }
200
- _initialize() {
201
- super._initialize();
203
+ _canHaveRepeatingChildren(mode = 'create') {
204
+ const items = this._jsonModel.items;
205
+ return this._jsonModel.type == 'array' && this.getDataNode() != null &&
206
+ (items.length === 1 || (items[0].repeatable == true && mode === 'restore'));
207
+ }
208
+ _initialize(mode) {
209
+ super._initialize(mode);
202
210
  const items = this._jsonModel.items || [];
203
211
  this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
204
- if (this._jsonModel.type == 'array' && items.length === 1 && this.getDataNode() != null) {
212
+ if (this._canHaveRepeatingChildren(mode)) {
205
213
  this._itemTemplate = (0, JsonUtils_1.deepClone)(items[0]);
214
+ if (mode === 'restore') {
215
+ this._itemTemplate.repeatable = undefined;
216
+ }
206
217
  if (typeof (this._jsonModel.minItems) !== 'number') {
207
218
  this._jsonModel.minItems = 0;
208
219
  }
@@ -213,9 +224,22 @@ class Container extends Scriptable_1.default {
213
224
  this._jsonModel.initialItems = Math.max(1, this._jsonModel.minItems);
214
225
  }
215
226
  for (let i = 0; i < this._jsonModel.initialItems; i++) {
216
- const child = this._addChild(this._itemTemplate, null, i > 0);
217
- items[0].id = child.id;
218
- child._initialize();
227
+ let child;
228
+ if (mode === 'restore') {
229
+ let itemTemplate = this._itemTemplate;
230
+ if (i < this._jsonModel.items.length) {
231
+ itemTemplate = (0, JsonUtils_1.deepClone)(items[i]);
232
+ itemTemplate.repeatable = undefined;
233
+ }
234
+ child = this._addChild(itemTemplate, undefined, i > this._jsonModel.items.length - 1);
235
+ }
236
+ else {
237
+ child = this._addChild(this._itemTemplate, undefined, i > this._jsonModel.items.length - 1);
238
+ }
239
+ if (mode === 'create') {
240
+ items[0].id = child.id;
241
+ }
242
+ child._initialize(mode);
219
243
  }
220
244
  }
221
245
  else if (items.length > 0) {
@@ -225,10 +249,10 @@ class Container extends Scriptable_1.default {
225
249
  }
226
250
  else if (this.isAFormField(item)) {
227
251
  const child = this._addChild(item);
228
- child._initialize();
252
+ child._initialize(mode);
229
253
  }
230
254
  else {
231
- this.form.logger.warn('A container item was not initialized.');
255
+ this.form.logger.warn(`A container item was not initialized. ${item}`);
232
256
  }
233
257
  });
234
258
  this._jsonModel.minItems = this._children.length;
@@ -264,7 +288,7 @@ class Container extends Scriptable_1.default {
264
288
  if (_data) {
265
289
  dataNode.$addDataNode(instanceIndex, _data);
266
290
  }
267
- retVal._initialize();
291
+ retVal._initialize('create');
268
292
  this.notifyDependents((0, Events_1.propertyChange)('items', retVal.getState(), null));
269
293
  retVal.dispatch(new Events_1.Initialize());
270
294
  retVal.dispatch(new Events_1.ExecuteRule());
@@ -341,7 +365,7 @@ class Container extends Scriptable_1.default {
341
365
  while (items2Add > 0) {
342
366
  items2Add--;
343
367
  const child = this._addChild(this._itemTemplate);
344
- child._initialize();
368
+ child._initialize('create');
345
369
  }
346
370
  if (items2Remove > 0) {
347
371
  this._children.splice(dataLength, items2Remove);
package/lib/Field.d.ts CHANGED
@@ -151,7 +151,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
151
151
  validate(): ValidationError[];
152
152
  importData(contextualDataModel: DataGroup): void;
153
153
  defaultDataModel(name: string | number): DataValue;
154
- getState(): {
154
+ getState(isRepeatableChild?: boolean, forRestore?: boolean): {
155
155
  editFormat: string | undefined;
156
156
  displayFormat: string | undefined;
157
157
  editValue: any;
@@ -159,8 +159,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
159
159
  enabled: boolean | undefined;
160
160
  readOnly: boolean | undefined;
161
161
  description?: string | undefined;
162
- rules: import("./types").Items<string> & {};
163
- events: import("./types").Items<string | string[] | undefined> & {};
162
+ rules?: import("./types").Items<string> | undefined;
163
+ events?: import("./types").Items<string | string[] | undefined> | undefined;
164
164
  enumNames?: string[] | import("./types").EnumName[] | undefined;
165
165
  enum?: any[] | undefined;
166
166
  accept?: string[] | undefined;
@@ -208,6 +208,11 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
208
208
  default?: any;
209
209
  value?: any;
210
210
  emptyValue?: "" | "undefined" | "null" | undefined;
211
+ _dependents?: string[] | undefined;
212
+ allowedComponents?: undefined;
213
+ columnClassNames?: undefined;
214
+ columnCount?: undefined;
215
+ gridClassNames?: undefined;
211
216
  index: number;
212
217
  parent: undefined;
213
218
  qualifiedName: any;
package/lib/Field.js CHANGED
@@ -143,11 +143,11 @@ class Field extends Scriptable_1.default {
143
143
  }
144
144
  this.coerceParam('minLength', 'number');
145
145
  this.coerceParam('maxLength', 'number');
146
- if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date') {
146
+ if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.type !== 'integer') {
147
147
  this.unset('step', ...props);
148
148
  }
149
149
  props.forEach(c => {
150
- this.coerceParam(c, this._jsonModel.type);
150
+ this.coerceParam(c, this._jsonModel.type === 'integer' ? 'number' : this._jsonModel.type);
151
151
  });
152
152
  if (typeof this._jsonModel.step !== 'number') {
153
153
  this.coerceParam('step', 'number');
@@ -244,22 +244,22 @@ class Field extends Scriptable_1.default {
244
244
  this._setProperty('required', r);
245
245
  }
246
246
  get maximum() {
247
- if (this.type === 'number' || this.format === 'date') {
247
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
248
248
  return this._jsonModel.maximum;
249
249
  }
250
250
  }
251
251
  set maximum(m) {
252
- if (this.type === 'number' || this.format === 'date') {
252
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
253
253
  this._setProperty('maximum', m);
254
254
  }
255
255
  }
256
256
  get minimum() {
257
- if (this.type === 'number' || this.format === 'date') {
257
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
258
258
  return this._jsonModel.minimum;
259
259
  }
260
260
  }
261
261
  set minimum(m) {
262
- if (this.type === 'number' || this.format === 'date') {
262
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
263
263
  this._setProperty('minimum', m);
264
264
  }
265
265
  }
@@ -545,22 +545,22 @@ class Field extends Scriptable_1.default {
545
545
  }
546
546
  }
547
547
  get exclusiveMinimum() {
548
- if (this.type === 'number' || this.format === 'date') {
548
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
549
549
  return this._jsonModel.exclusiveMinimum;
550
550
  }
551
551
  }
552
552
  set exclusiveMinimum(eM) {
553
- if (this.type === 'number' || this.format === 'date') {
553
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
554
554
  this._jsonModel.exclusiveMinimum = eM;
555
555
  }
556
556
  }
557
557
  get exclusiveMaximum() {
558
- if (this.type === 'number' || this.format === 'date') {
558
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
559
559
  return this._jsonModel.exclusiveMaximum;
560
560
  }
561
561
  }
562
562
  set exclusiveMaximum(eM) {
563
- if (this.type === 'number' || this.format === 'date') {
563
+ if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
564
564
  this._jsonModel.exclusiveMaximum = eM;
565
565
  }
566
566
  }
@@ -666,8 +666,8 @@ class Field extends Scriptable_1.default {
666
666
  const value = BaseNode_1.staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
667
667
  return new DataValue_1.default(name, value, this.type || 'string');
668
668
  }
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 });
669
+ getState(isRepeatableChild = false, forRestore = false) {
670
+ 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
671
  }
672
672
  markAsInvalid(message, constraint = null) {
673
673
  const changes = {