@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
@@ -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[];
@@ -23,6 +23,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
23
23
  constructor(params: T, _options: {
24
24
  form: FormModel;
25
25
  parent: ContainerModel;
26
+ mode?: 'create' | 'restore';
26
27
  });
27
28
  abstract value: Primitives;
28
29
  abstract reset(): any;
@@ -49,15 +50,18 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
49
50
  set label(l: import("./types/Json").Label | undefined);
50
51
  get uniqueItems(): boolean | undefined;
51
52
  isTransparent(): boolean;
52
- getState(isRepeatableChild?: boolean): T & {
53
+ getState(forRestore?: boolean): T & {
54
+ _dependents?: string[] | undefined;
55
+ allowedComponents?: undefined;
56
+ columnClassNames?: undefined;
57
+ columnCount?: undefined;
58
+ gridClassNames?: undefined;
53
59
  properties: {
54
60
  [key: string]: any;
55
61
  };
56
62
  index: number;
57
63
  parent: undefined;
58
64
  qualifiedName: any;
59
- events: {};
60
- rules: {};
61
65
  repeatable: boolean | undefined;
62
66
  ':type': string;
63
67
  id: string;
@@ -87,7 +91,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
87
91
  abstract defaultDataModel(name: string | number): DataValue | undefined;
88
92
  abstract importData(a: DataGroup): any;
89
93
  getNonTransparentParent(): ContainerModel;
90
- _initialize(): void;
94
+ _initialize(mode?: FormCreationMode): void;
91
95
  protected _applyUpdates(propNames: string[], updates: any): any;
92
96
  get qualifiedName(): any;
93
97
  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,9 +1,10 @@
1
1
  import Field from './Field';
2
- import { ContainerModel, FieldJson, FormModel } from './types/index';
2
+ import { ContainerModel, FieldJson, FormCreationMode, FormModel } from './types/index';
3
3
  declare class CheckboxGroup extends Field {
4
4
  constructor(params: FieldJson, _options: {
5
5
  form: FormModel;
6
6
  parent: ContainerModel;
7
+ mode: FormCreationMode;
7
8
  });
8
9
  protected _getFallbackType(): string | undefined;
9
10
  protected _getDefaults(): {
@@ -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
@@ -19,7 +19,7 @@ const notifyChildrenAttributes = [
19
19
  ];
20
20
  class Container extends Scriptable_1.default {
21
21
  constructor(json, _options) {
22
- super(json, { form: _options.form, parent: _options.parent });
22
+ super(json, { form: _options.form, parent: _options.parent, mode: _options.mode });
23
23
  this._children = [];
24
24
  this._itemTemplate = null;
25
25
  this._activeChild = null;
@@ -79,44 +79,43 @@ 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
- const { parent = this } = options;
116
- return this.fieldFactory.createField(child, {
117
- form: options.form,
118
- parent
119
- });
118
+ return this.fieldFactory.createField(child, options);
120
119
  }
121
120
  walkSiteContainerItems(x) {
122
121
  return Object.fromEntries(Object.entries(x[':items']).map(([key, value]) => {
@@ -128,7 +127,7 @@ class Container extends Scriptable_1.default {
128
127
  }
129
128
  else {
130
129
  if (typeof value === 'object') {
131
- const newObjWithId = Object.assign({}, ((value === null || value === void 0 ? void 0 : value.id) ? { 'id': this.form.getUniqueId() } : {}));
130
+ const newObjWithId = Object.assign({}, ((value === null || value === void 0 ? void 0 : value.id) ? { id: this.form.getUniqueId() } : {}));
132
131
  return [key, Object.assign(Object.assign({}, value), newObjWithId)];
133
132
  }
134
133
  else {
@@ -162,7 +161,7 @@ class Container extends Scriptable_1.default {
162
161
  });
163
162
  }
164
163
  }
165
- _addChild(itemJson, index, cloneIds = false) {
164
+ _addChild(itemJson, index, cloneIds = false, mode = 'create') {
166
165
  let nonTransparentParent = this;
167
166
  while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
168
167
  nonTransparentParent = nonTransparentParent.parent;
@@ -172,7 +171,7 @@ class Container extends Scriptable_1.default {
172
171
  }
173
172
  const form = this.form;
174
173
  const itemTemplate = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson, cloneIds ? () => { return form.getUniqueId(); } : undefined));
175
- const retVal = this._createChild(itemTemplate, { parent: this, form: this.form });
174
+ const retVal = this._createChild(itemTemplate, { parent: this, form: this.form, mode });
176
175
  itemJson.id = retVal.id;
177
176
  this.form.fieldAdded(retVal);
178
177
  this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
@@ -197,12 +196,20 @@ class Container extends Scriptable_1.default {
197
196
  return new DataGroup_1.default(name, instance, type);
198
197
  }
199
198
  }
200
- _initialize() {
201
- super._initialize();
199
+ _canHaveRepeatingChildren(mode = 'create') {
200
+ const items = this._jsonModel.items;
201
+ return this._jsonModel.type == 'array' && this.getDataNode() != null &&
202
+ (items.length === 1 || (items[0].repeatable == true && mode === 'restore'));
203
+ }
204
+ _initialize(mode) {
205
+ super._initialize(mode);
202
206
  const items = this._jsonModel.items || [];
203
207
  this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
204
- if (this._jsonModel.type == 'array' && items.length === 1 && this.getDataNode() != null) {
208
+ if (this._canHaveRepeatingChildren(mode)) {
205
209
  this._itemTemplate = (0, JsonUtils_1.deepClone)(items[0]);
210
+ if (mode === 'restore') {
211
+ this._itemTemplate.repeatable = undefined;
212
+ }
206
213
  if (typeof (this._jsonModel.minItems) !== 'number') {
207
214
  this._jsonModel.minItems = 0;
208
215
  }
@@ -213,9 +220,22 @@ class Container extends Scriptable_1.default {
213
220
  this._jsonModel.initialItems = Math.max(1, this._jsonModel.minItems);
214
221
  }
215
222
  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();
223
+ let child;
224
+ if (mode === 'restore') {
225
+ let itemTemplate = this._itemTemplate;
226
+ if (i < this._jsonModel.items.length) {
227
+ itemTemplate = (0, JsonUtils_1.deepClone)(items[i]);
228
+ itemTemplate.repeatable = undefined;
229
+ }
230
+ child = this._addChild(itemTemplate, undefined, i > this._jsonModel.items.length - 1, mode);
231
+ }
232
+ else {
233
+ child = this._addChild(this._itemTemplate, undefined, i > this._jsonModel.items.length - 1);
234
+ }
235
+ if (mode === 'create') {
236
+ items[0].id = child.id;
237
+ }
238
+ child._initialize(mode);
219
239
  }
220
240
  }
221
241
  else if (items.length > 0) {
@@ -224,11 +244,11 @@ class Container extends Scriptable_1.default {
224
244
  this._initializeSiteContainer(item);
225
245
  }
226
246
  else if (this.isAFormField(item)) {
227
- const child = this._addChild(item);
228
- child._initialize();
247
+ const child = this._addChild(item, undefined, false, mode);
248
+ child._initialize(mode);
229
249
  }
230
250
  else {
231
- this.form.logger.warn('A container item was not initialized.');
251
+ this.form.logger.warn(`A container item was not initialized. ${item}`);
232
252
  }
233
253
  });
234
254
  this._jsonModel.minItems = this._children.length;
@@ -264,7 +284,7 @@ class Container extends Scriptable_1.default {
264
284
  if (_data) {
265
285
  dataNode.$addDataNode(instanceIndex, _data);
266
286
  }
267
- retVal._initialize();
287
+ retVal._initialize('create');
268
288
  this.notifyDependents((0, Events_1.propertyChange)('items', retVal.getState(), null));
269
289
  retVal.dispatch(new Events_1.Initialize());
270
290
  retVal.dispatch(new Events_1.ExecuteRule());
@@ -341,7 +361,7 @@ class Container extends Scriptable_1.default {
341
361
  while (items2Add > 0) {
342
362
  items2Add--;
343
363
  const child = this._addChild(this._itemTemplate);
344
- child._initialize();
364
+ child._initialize('create');
345
365
  }
346
366
  if (items2Remove > 0) {
347
367
  this._children.splice(dataLength, items2Remove);
package/lib/Field.d.ts CHANGED
@@ -6,6 +6,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
6
6
  constructor(params: FieldJson, _options: {
7
7
  form: FormModel;
8
8
  parent: ContainerModel;
9
+ mode?: 'create' | 'restore';
9
10
  });
10
11
  private _ruleNodeReference;
11
12
  _initialize(): any;
@@ -151,7 +152,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
151
152
  validate(): ValidationError[];
152
153
  importData(contextualDataModel: DataGroup): void;
153
154
  defaultDataModel(name: string | number): DataValue;
154
- getState(): {
155
+ getState(isRepeatableChild?: boolean, forRestore?: boolean): {
155
156
  editFormat: string | undefined;
156
157
  displayFormat: string | undefined;
157
158
  editValue: any;
@@ -159,8 +160,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
159
160
  enabled: boolean | undefined;
160
161
  readOnly: boolean | undefined;
161
162
  description?: string | undefined;
162
- rules: import("./types").Items<string> & {};
163
- events: import("./types").Items<string | string[] | undefined> & {};
163
+ rules?: import("./types").Items<string> | undefined;
164
+ events?: import("./types").Items<string | string[] | undefined> | undefined;
164
165
  enumNames?: string[] | import("./types").EnumName[] | undefined;
165
166
  enum?: any[] | undefined;
166
167
  accept?: string[] | undefined;
@@ -208,6 +209,11 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
208
209
  default?: any;
209
210
  value?: any;
210
211
  emptyValue?: "" | "undefined" | "null" | undefined;
212
+ _dependents?: string[] | undefined;
213
+ allowedComponents?: undefined;
214
+ columnClassNames?: undefined;
215
+ columnCount?: undefined;
216
+ gridClassNames?: undefined;
211
217
  index: number;
212
218
  parent: undefined;
213
219
  qualifiedName: any;