@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.
- package/esm/afb-events.js +161 -0
- package/esm/afb-runtime.js +4304 -0
- package/esm/types/src/BaseNode.d.ts +99 -0
- package/esm/types/src/Captcha.d.ts +5 -0
- package/esm/types/src/Checkbox.d.ts +84 -0
- package/esm/types/src/CheckboxGroup.d.ts +23 -0
- package/esm/types/src/Container.d.ts +75 -0
- package/esm/types/src/DateField.d.ts +9 -0
- package/esm/types/src/EmailInput.d.ts +16 -0
- package/esm/types/src/Field.d.ts +223 -0
- package/esm/types/src/Fieldset.d.ts +16 -0
- package/esm/types/src/FileObject.d.ts +16 -0
- package/esm/types/src/FileUpload.d.ts +27 -0
- package/esm/types/src/Form.d.ts +125 -0
- package/esm/types/src/FormInstance.d.ts +16 -0
- package/esm/types/src/FormMetaData.d.ts +7 -0
- package/esm/types/src/InstanceManager.d.ts +9 -0
- package/esm/types/src/Node.d.ts +7 -0
- package/esm/types/src/Scriptable.d.ts +17 -0
- package/esm/types/src/SubmitMetaData.d.ts +7 -0
- package/esm/types/src/controller/EventQueue.d.ts +18 -0
- package/esm/types/src/controller/Events.d.ts +91 -0
- package/esm/types/src/controller/Logger.d.ts +11 -0
- package/esm/types/src/data/DataGroup.d.ts +20 -0
- package/esm/types/src/data/DataValue.d.ts +16 -0
- package/esm/types/src/data/EmptyDataValue.d.ts +14 -0
- package/esm/types/src/index.d.ts +24 -0
- package/esm/types/src/rules/FunctionRuntime.d.ts +62 -0
- package/esm/types/src/rules/RuleEngine.d.ts +16 -0
- package/esm/types/src/types/Json.d.ts +180 -0
- package/esm/types/src/types/Model.d.ts +141 -0
- package/esm/types/src/types/index.d.ts +2 -0
- package/esm/types/src/utils/CoercionUtils.d.ts +1 -0
- package/esm/types/src/utils/DataRefParser.d.ts +33 -0
- package/esm/types/src/utils/Fetch.d.ts +8 -0
- package/esm/types/src/utils/FormCreationUtils.d.ts +10 -0
- package/esm/types/src/utils/FormUtils.d.ts +14 -0
- package/esm/types/src/utils/JsonUtils.d.ts +13 -0
- package/esm/types/src/utils/LogUtils.d.ts +4 -0
- package/esm/types/src/utils/SchemaUtils.d.ts +3 -0
- package/esm/types/src/utils/TranslationUtils.d.ts +11 -0
- package/esm/types/src/utils/ValidationUtils.d.ts +20 -0
- package/lib/BaseNode.d.ts +8 -5
- package/lib/BaseNode.js +19 -3
- package/lib/Container.d.ts +12 -5
- package/lib/Container.js +43 -19
- package/lib/Field.d.ts +8 -3
- package/lib/Field.js +12 -12
- package/lib/Fieldset.d.ts +2 -1
- package/lib/Form.d.ts +10 -6
- package/lib/Form.js +34 -12
- package/lib/FormInstance.d.ts +3 -0
- package/lib/FormInstance.js +16 -1
- package/lib/controller/EventQueue.d.ts +1 -0
- package/lib/controller/EventQueue.js +3 -0
- package/lib/types/Model.d.ts +2 -1
- package/lib/utils/FormCreationUtils.d.ts +2 -1
- package/package.json +5 -3
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/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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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 ===
|
|
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 ===
|
|
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 () {
|
|
@@ -156,7 +160,25 @@ class Form extends Container_1.default {
|
|
|
156
160
|
field.subscribe((action) => {
|
|
157
161
|
const field = action.target.getState();
|
|
158
162
|
if (field) {
|
|
159
|
-
const
|
|
163
|
+
const shallowClone = (obj) => {
|
|
164
|
+
if (obj && typeof obj === 'object') {
|
|
165
|
+
if (Array.isArray(obj)) {
|
|
166
|
+
return obj.map(shallowClone);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return Object.assign({}, obj);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return obj;
|
|
173
|
+
};
|
|
174
|
+
const changes = action.payload.changes.map(({ propertyName, currentValue, prevValue }) => {
|
|
175
|
+
return {
|
|
176
|
+
propertyName,
|
|
177
|
+
currentValue: shallowClone(currentValue),
|
|
178
|
+
prevValue: shallowClone(prevValue)
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
const fieldChangedAction = new Events_1.FieldChanged(changes, field);
|
|
160
182
|
this.dispatch(fieldChangedAction);
|
|
161
183
|
}
|
|
162
184
|
});
|
package/lib/FormInstance.d.ts
CHANGED
|
@@ -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[];
|
package/lib/FormInstance.js
CHANGED
|
@@ -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;
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.22.69",
|
|
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.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.69"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@babel/preset-env": "^7.20.2",
|