@aemforms/af-core 0.22.78 → 0.22.80
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 +10 -1
- package/esm/afb-runtime.js +188 -27
- package/esm/types/src/BaseNode.d.ts +1 -0
- package/esm/types/src/Form.d.ts +8 -1
- package/esm/types/src/FormInstance.d.ts +4 -1
- package/esm/types/src/Scriptable.d.ts +1 -0
- package/esm/types/src/controller/Events.d.ts +5 -0
- package/esm/types/src/rules/FunctionRuntime.d.ts +5 -1
- package/esm/types/src/types/Json.d.ts +1 -1
- package/esm/types/src/types/Model.d.ts +6 -2
- package/esm/types/src/utils/Version.d.ts +11 -0
- package/lib/BaseNode.d.ts +1 -0
- package/lib/BaseNode.js +23 -5
- package/lib/Field.js +6 -1
- package/lib/Fieldset.js +1 -1
- package/lib/Form.d.ts +8 -1
- package/lib/Form.js +69 -3
- package/lib/FormInstance.d.ts +4 -1
- package/lib/FormInstance.js +30 -4
- package/lib/Scriptable.d.ts +1 -0
- package/lib/Scriptable.js +24 -10
- package/lib/controller/Events.d.ts +5 -0
- package/lib/controller/Events.js +10 -1
- package/lib/rules/FunctionRuntime.d.ts +5 -1
- package/lib/rules/FunctionRuntime.js +17 -3
- package/lib/types/Json.d.ts +1 -1
- package/lib/types/Model.d.ts +6 -2
- package/lib/utils/FormCreationUtils.js +1 -1
- package/lib/utils/Version.d.ts +11 -0
- package/lib/utils/Version.js +60 -0
- package/package.json +2 -2
package/lib/BaseNode.js
CHANGED
|
@@ -44,7 +44,14 @@ exports.staticFields = ['plain-text', 'image'];
|
|
|
44
44
|
class ActionImplWithTarget {
|
|
45
45
|
constructor(_action, _target) {
|
|
46
46
|
this._action = _action;
|
|
47
|
-
|
|
47
|
+
if (_action.target) {
|
|
48
|
+
this._currentTarget = _target;
|
|
49
|
+
this._target = _action.target;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._target = _target;
|
|
53
|
+
this._currentTarget = _target;
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
get type() {
|
|
50
57
|
return this._action.type;
|
|
@@ -58,6 +65,9 @@ class ActionImplWithTarget {
|
|
|
58
65
|
get target() {
|
|
59
66
|
return this._target;
|
|
60
67
|
}
|
|
68
|
+
get currentTarget() {
|
|
69
|
+
return this._currentTarget;
|
|
70
|
+
}
|
|
61
71
|
get isCustomEvent() {
|
|
62
72
|
return this._action.isCustomEvent;
|
|
63
73
|
}
|
|
@@ -236,17 +246,20 @@ class BaseNode {
|
|
|
236
246
|
return this._jsonModel.uniqueItems;
|
|
237
247
|
}
|
|
238
248
|
isTransparent() {
|
|
239
|
-
var _a;
|
|
240
|
-
const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array';
|
|
249
|
+
var _a, _b;
|
|
250
|
+
const isNonTransparent = ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel) === null || _b === void 0 ? void 0 : _b.type) === 'array';
|
|
241
251
|
return !this._jsonModel.name && !isNonTransparent;
|
|
242
252
|
}
|
|
253
|
+
getDependents() {
|
|
254
|
+
return this._dependents.map(x => x.node.id);
|
|
255
|
+
}
|
|
243
256
|
getState(forRestore = false) {
|
|
244
257
|
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName }), (this.repeatable === true ? {
|
|
245
258
|
repeatable: true,
|
|
246
259
|
minOccur: this.parent.minItems,
|
|
247
260
|
maxOccur: this.parent.maxItems
|
|
248
261
|
} : {})), { ':type': this[':type'] }), (forRestore ? {
|
|
249
|
-
_dependents: this._dependents.length ? this.
|
|
262
|
+
_dependents: this._dependents.length ? this.getDependents() : undefined,
|
|
250
263
|
allowedComponents: undefined,
|
|
251
264
|
columnClassNames: undefined,
|
|
252
265
|
columnCount: undefined,
|
|
@@ -271,7 +284,12 @@ class BaseNode {
|
|
|
271
284
|
return propsToLook.indexOf(x.propertyName) > -1;
|
|
272
285
|
}) > -1;
|
|
273
286
|
if (isPropChanged) {
|
|
274
|
-
|
|
287
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
288
|
+
dependent.dispatch(change);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
dependent.dispatch(new Events_1.ExecuteRule());
|
|
292
|
+
}
|
|
275
293
|
}
|
|
276
294
|
});
|
|
277
295
|
this._dependents.push({ node: dependent, subscription });
|
package/lib/Field.js
CHANGED
|
@@ -34,7 +34,12 @@ class Field extends Scriptable_1.default {
|
|
|
34
34
|
if (_options.mode !== 'restore') {
|
|
35
35
|
this._applyDefaults();
|
|
36
36
|
this.queueEvent(new Events_1.Initialize());
|
|
37
|
-
this.
|
|
37
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
38
|
+
this.queueEvent(new Events_1.Change({ changes: [] }));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.queueEvent(new Events_1.ExecuteRule());
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
_initialize() {
|
package/lib/Fieldset.js
CHANGED
package/lib/Form.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ 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 { Version } from './utils/Version';
|
|
9
|
+
export declare const currentVersion: Version;
|
|
8
10
|
declare class Form extends Container<FormJson> implements FormModel {
|
|
9
11
|
#private;
|
|
10
12
|
private _ruleEngine;
|
|
@@ -13,13 +15,16 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
13
15
|
_ids: Generator<string, void, string>;
|
|
14
16
|
private _invalidFields;
|
|
15
17
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
18
|
+
protected _applyDefaultsInModel(): void;
|
|
16
19
|
private _logger;
|
|
17
20
|
get logger(): Logger;
|
|
21
|
+
get changeEventBehaviour(): "deps" | "self";
|
|
18
22
|
private dataRefRegex;
|
|
19
23
|
get metaData(): FormMetaData;
|
|
20
24
|
get action(): string | undefined;
|
|
21
25
|
importData(dataModel: any): void;
|
|
22
26
|
exportData(): any;
|
|
27
|
+
get specVersion(): Version;
|
|
23
28
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
|
24
29
|
exportSubmitMetaData(): SubmitMetaData;
|
|
25
30
|
setFocus(field: BaseModel, focusOption: FocusOption): void;
|
|
@@ -78,7 +83,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
78
83
|
data?: any;
|
|
79
84
|
title?: string | undefined;
|
|
80
85
|
action?: string | undefined;
|
|
81
|
-
|
|
86
|
+
adaptiveform?: string | undefined;
|
|
82
87
|
lang?: string | undefined;
|
|
83
88
|
} & {
|
|
84
89
|
items: any[];
|
|
@@ -115,6 +120,8 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
115
120
|
isValid(): boolean;
|
|
116
121
|
dispatch(action: Action): void;
|
|
117
122
|
submit(action: Action, context: any): void;
|
|
123
|
+
save(action: Action, context: any): void;
|
|
124
|
+
_saveSuccess(action: Action): void;
|
|
118
125
|
reset(): void;
|
|
119
126
|
getElement(id: string): FieldModel | FieldsetModel | this;
|
|
120
127
|
get qualifiedName(): string;
|
package/lib/Form.js
CHANGED
|
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
};
|
|
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
|
+
exports.currentVersion = void 0;
|
|
12
13
|
const Container_1 = __importDefault(require("./Container"));
|
|
13
14
|
const index_1 = require("./types/index");
|
|
14
15
|
const FormMetaData_1 = __importDefault(require("./FormMetaData"));
|
|
@@ -19,6 +20,9 @@ const FormUtils_1 = require("./utils/FormUtils");
|
|
|
19
20
|
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
20
21
|
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
21
22
|
const Events_1 = require("./controller/Events");
|
|
23
|
+
const Version_1 = require("./utils/Version");
|
|
24
|
+
exports.currentVersion = new Version_1.Version('0.13');
|
|
25
|
+
const changeEventVersion = new Version_1.Version('0.13');
|
|
22
26
|
class Form extends Container_1.default {
|
|
23
27
|
constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off', mode = 'create') {
|
|
24
28
|
super(n, { fieldFactory: fieldFactory, mode });
|
|
@@ -29,9 +33,15 @@ class Form extends Container_1.default {
|
|
|
29
33
|
this._invalidFields = [];
|
|
30
34
|
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
31
35
|
this._logger = new Logger_1.Logger(logLevel);
|
|
36
|
+
this._applyDefaultsInModel();
|
|
32
37
|
if (mode === 'create') {
|
|
33
38
|
this.queueEvent(new Events_1.Initialize());
|
|
34
|
-
this.
|
|
39
|
+
if (this.changeEventBehaviour === 'deps') {
|
|
40
|
+
this.queueEvent(new Events_1.Change({ changes: [] }));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.queueEvent(new Events_1.ExecuteRule());
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
this._ids = (0, FormUtils_1.IdGenerator)();
|
|
37
47
|
this._bindToDataModel(new DataGroup_1.default('$form', {}));
|
|
@@ -40,9 +50,20 @@ class Form extends Container_1.default {
|
|
|
40
50
|
this.queueEvent(new Events_1.FormLoad());
|
|
41
51
|
}
|
|
42
52
|
}
|
|
53
|
+
_applyDefaultsInModel() {
|
|
54
|
+
const current = this.specVersion;
|
|
55
|
+
this._jsonModel.properties = this._jsonModel.properties || {};
|
|
56
|
+
if (current.lessThan(changeEventVersion) ||
|
|
57
|
+
typeof this._jsonModel.properties['fd:changeEventBehaviour'] !== 'string') {
|
|
58
|
+
this._jsonModel.properties['fd:changeEventBehaviour'] = 'self';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
43
61
|
get logger() {
|
|
44
62
|
return this._logger;
|
|
45
63
|
}
|
|
64
|
+
get changeEventBehaviour() {
|
|
65
|
+
return this.properties['fd:changeEventBehaviour'] === 'deps' ? 'deps' : 'self';
|
|
66
|
+
}
|
|
46
67
|
get metaData() {
|
|
47
68
|
const metaData = this._jsonModel.metadata || {};
|
|
48
69
|
return new FormMetaData_1.default(metaData);
|
|
@@ -59,6 +80,21 @@ class Form extends Container_1.default {
|
|
|
59
80
|
var _a;
|
|
60
81
|
return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
|
|
61
82
|
}
|
|
83
|
+
get specVersion() {
|
|
84
|
+
if (typeof this._jsonModel.adaptiveform === 'string') {
|
|
85
|
+
try {
|
|
86
|
+
return new Version_1.Version(this._jsonModel.adaptiveform);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
console.log(e);
|
|
90
|
+
console.log('Falling back to default version' + exports.currentVersion.toString());
|
|
91
|
+
return exports.currentVersion;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return exports.currentVersion;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
62
98
|
resolveQualifiedName(qualifiedName) {
|
|
63
99
|
let foundFormElement = null;
|
|
64
100
|
this.visit(formElement => {
|
|
@@ -159,7 +195,7 @@ class Form extends Container_1.default {
|
|
|
159
195
|
}, 'valid');
|
|
160
196
|
field.subscribe((action) => {
|
|
161
197
|
const field = action.target.getState();
|
|
162
|
-
if (field) {
|
|
198
|
+
if (action.payload.changes.length > 0 && field) {
|
|
163
199
|
const shallowClone = (obj) => {
|
|
164
200
|
if (obj && typeof obj === 'object') {
|
|
165
201
|
if (Array.isArray(obj)) {
|
|
@@ -218,7 +254,37 @@ class Form extends Container_1.default {
|
|
|
218
254
|
const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
|
|
219
255
|
const successEventName = (payload === null || payload === void 0 ? void 0 : payload.success) ? payload === null || payload === void 0 ? void 0 : payload.success : 'submitSuccess';
|
|
220
256
|
const failureEventName = (payload === null || payload === void 0 ? void 0 : payload.error) ? payload === null || payload === void 0 ? void 0 : payload.error : 'submitError';
|
|
221
|
-
|
|
257
|
+
const formAction = payload.action || this.action;
|
|
258
|
+
const metadata = payload.metadata || {
|
|
259
|
+
'submitMetadata': this.exportSubmitMetaData()
|
|
260
|
+
};
|
|
261
|
+
const contentType = (payload === null || payload === void 0 ? void 0 : payload.save_as) || (payload === null || payload === void 0 ? void 0 : payload.submit_as);
|
|
262
|
+
(0, FunctionRuntime_1.submit)(context, successEventName, failureEventName, contentType, payload === null || payload === void 0 ? void 0 : payload.data, formAction, metadata);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
save(action, context) {
|
|
266
|
+
var _a;
|
|
267
|
+
const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
|
|
268
|
+
payload.save_as = 'multipart/form-data';
|
|
269
|
+
payload.metadata = {
|
|
270
|
+
'draftMetadata': {
|
|
271
|
+
'lang': this.lang,
|
|
272
|
+
'draftId': ((_a = this.properties) === null || _a === void 0 ? void 0 : _a.draftId) || ''
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
payload.success = 'custom:saveSuccess';
|
|
276
|
+
payload.error = 'custom:saveError';
|
|
277
|
+
this.submit(action, context);
|
|
278
|
+
this.subscribe((action) => {
|
|
279
|
+
this._saveSuccess(action);
|
|
280
|
+
}, 'saveSuccess');
|
|
281
|
+
}
|
|
282
|
+
_saveSuccess(action) {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
const draftId = ((_b = (_a = action === null || action === void 0 ? void 0 : action.payload) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.draftId) || '';
|
|
285
|
+
const properties = this.properties;
|
|
286
|
+
if (draftId && properties) {
|
|
287
|
+
properties.draftId = draftId;
|
|
222
288
|
}
|
|
223
289
|
}
|
|
224
290
|
reset() {
|
package/lib/FormInstance.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FormModel } from './types/index';
|
|
2
2
|
import { LogLevel } from './controller/Logger';
|
|
3
3
|
import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
|
|
4
|
-
export declare const createFormInstance:
|
|
4
|
+
export declare const createFormInstance: {
|
|
5
|
+
(formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any): FormModel;
|
|
6
|
+
currentVersion: import("./utils/Version").Version;
|
|
7
|
+
};
|
|
5
8
|
export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
|
|
6
9
|
logLevel: LogLevel;
|
|
7
10
|
}) => FormModel;
|
package/lib/FormInstance.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.restoreFormInstance = exports.createFormInstance = void 0;
|
|
7
|
-
const Form_1 =
|
|
30
|
+
const Form_1 = __importStar(require("./Form"));
|
|
8
31
|
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
9
32
|
const Fetch_1 = require("./utils/Fetch");
|
|
10
33
|
const RuleEngine_1 = __importDefault(require("./rules/RuleEngine"));
|
|
@@ -17,9 +40,11 @@ const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
|
17
40
|
const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
|
|
18
41
|
try {
|
|
19
42
|
let f = fModel;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
{
|
|
44
|
+
if (f == null) {
|
|
45
|
+
formModel = (0, FormUtils_1.sitesModelToFormModel)(formModel);
|
|
46
|
+
f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel);
|
|
47
|
+
}
|
|
23
48
|
}
|
|
24
49
|
const formData = formModel === null || formModel === void 0 ? void 0 : formModel.data;
|
|
25
50
|
if (formData) {
|
|
@@ -37,6 +62,7 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
|
|
|
37
62
|
}
|
|
38
63
|
};
|
|
39
64
|
exports.createFormInstance = createFormInstance;
|
|
65
|
+
exports.createFormInstance.currentVersion = Form_1.currentVersion;
|
|
40
66
|
const defaultOptions = {
|
|
41
67
|
logLevel: 'error'
|
|
42
68
|
};
|
package/lib/Scriptable.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> imple
|
|
|
12
12
|
private executeEvent;
|
|
13
13
|
executeRule(event: Action, context: any): void;
|
|
14
14
|
executeExpression(expr: string): any;
|
|
15
|
+
change(event: Action, context: any): void;
|
|
15
16
|
executeAction(action: Action): void;
|
|
16
17
|
}
|
|
17
18
|
export default Scriptable;
|
package/lib/Scriptable.js
CHANGED
|
@@ -49,16 +49,23 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
49
49
|
return this._events[eName] || [];
|
|
50
50
|
}
|
|
51
51
|
applyUpdates(updates) {
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
this[key]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
if (typeof updates === 'object') {
|
|
53
|
+
if (updates !== null) {
|
|
54
|
+
Object.entries(updates).forEach(([key, value]) => {
|
|
55
|
+
if (key in BaseNode_1.editableProperties || (key in this && typeof this[key] !== 'function')) {
|
|
56
|
+
try {
|
|
57
|
+
this[key] = value;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.error(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
60
64
|
}
|
|
61
|
-
}
|
|
65
|
+
}
|
|
66
|
+
else if (typeof updates !== 'undefined') {
|
|
67
|
+
this.value = updates;
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
executeAllRules(context) {
|
|
64
71
|
const entries = Object.entries(this.getRules());
|
|
@@ -146,6 +153,11 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
146
153
|
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
147
154
|
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
148
155
|
}
|
|
156
|
+
change(event, context) {
|
|
157
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
158
|
+
this.executeAllRules(context);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
149
161
|
executeAction(action) {
|
|
150
162
|
const context = {
|
|
151
163
|
'form': this.form,
|
|
@@ -165,7 +177,9 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
165
177
|
this[funcName](action, context);
|
|
166
178
|
}
|
|
167
179
|
node.forEach((n) => this.executeEvent(context, n));
|
|
168
|
-
|
|
180
|
+
if (action.target === this) {
|
|
181
|
+
this.notifyDependents(action);
|
|
182
|
+
}
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
185
|
exports.default = Scriptable;
|
|
@@ -4,11 +4,13 @@ declare class ActionImpl implements Action {
|
|
|
4
4
|
protected _type: string;
|
|
5
5
|
private _payload?;
|
|
6
6
|
private _target;
|
|
7
|
+
private _currentTarget;
|
|
7
8
|
constructor(payload: any, type: string, _metadata?: any);
|
|
8
9
|
get type(): string;
|
|
9
10
|
get payload(): any;
|
|
10
11
|
get metadata(): any;
|
|
11
12
|
get target(): FormModel | FieldModel | FieldsetModel;
|
|
13
|
+
get currentTarget(): FormModel | FieldModel | FieldsetModel;
|
|
12
14
|
get isCustomEvent(): boolean;
|
|
13
15
|
protected payloadToJson(): any;
|
|
14
16
|
toJson(): {
|
|
@@ -60,6 +62,9 @@ export declare class Focus extends ActionImpl {
|
|
|
60
62
|
export declare class Submit extends ActionImpl {
|
|
61
63
|
constructor(payload?: any, dispatch?: boolean);
|
|
62
64
|
}
|
|
65
|
+
export declare class Save extends ActionImpl {
|
|
66
|
+
constructor(payload?: any, dispatch?: boolean);
|
|
67
|
+
}
|
|
63
68
|
export declare class SubmitSuccess extends ActionImpl {
|
|
64
69
|
constructor(payload?: any, dispatch?: boolean);
|
|
65
70
|
}
|
package/lib/controller/Events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = void 0;
|
|
3
|
+
exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Save = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = void 0;
|
|
4
4
|
class ActionImpl {
|
|
5
5
|
constructor(payload, type, _metadata) {
|
|
6
6
|
this._metadata = _metadata;
|
|
@@ -19,6 +19,9 @@ class ActionImpl {
|
|
|
19
19
|
get target() {
|
|
20
20
|
return this._target;
|
|
21
21
|
}
|
|
22
|
+
get currentTarget() {
|
|
23
|
+
return this._currentTarget;
|
|
24
|
+
}
|
|
22
25
|
get isCustomEvent() {
|
|
23
26
|
return false;
|
|
24
27
|
}
|
|
@@ -117,6 +120,12 @@ class Submit extends ActionImpl {
|
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
exports.Submit = Submit;
|
|
123
|
+
class Save extends ActionImpl {
|
|
124
|
+
constructor(payload, dispatch = false) {
|
|
125
|
+
super(payload, 'save', { dispatch });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Save = Save;
|
|
120
129
|
class SubmitSuccess extends ActionImpl {
|
|
121
130
|
constructor(payload, dispatch = false) {
|
|
122
131
|
super(payload, 'submitSuccess', { dispatch });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare type HTTP_VERB = 'GET' | 'POST';
|
|
2
2
|
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<void>;
|
|
3
|
-
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any) => Promise<void>;
|
|
3
|
+
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any, action?: string, metadata?: any) => Promise<void>;
|
|
4
4
|
export declare type CustomFunction = Function;
|
|
5
5
|
export declare type FunctionDefinition = {
|
|
6
6
|
_func: CustomFunction;
|
|
@@ -40,6 +40,10 @@ declare class FunctionRuntimeImpl {
|
|
|
40
40
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
41
41
|
_signature: never[];
|
|
42
42
|
};
|
|
43
|
+
saveForm: {
|
|
44
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
45
|
+
_signature: never[];
|
|
46
|
+
};
|
|
43
47
|
request: {
|
|
44
48
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
45
49
|
_signature: never[];
|
|
@@ -123,15 +123,15 @@ const multipartFormData = (data, attachments) => {
|
|
|
123
123
|
}
|
|
124
124
|
return formData;
|
|
125
125
|
};
|
|
126
|
-
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
const endpoint = context.form.action;
|
|
126
|
+
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const endpoint = action || context.form.action;
|
|
128
128
|
let data = input_data;
|
|
129
129
|
if (typeof data != 'object' || data == null) {
|
|
130
130
|
data = context.form.exportData();
|
|
131
131
|
}
|
|
132
132
|
const attachments = (0, FormUtils_1.getAttachments)(context.form, true);
|
|
133
133
|
let submitContentType = submitAs;
|
|
134
|
-
const submitDataAndMetaData = { 'data': data,
|
|
134
|
+
const submitDataAndMetaData = Object.assign({ 'data': data }, metadata);
|
|
135
135
|
let formData = submitDataAndMetaData;
|
|
136
136
|
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
137
137
|
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
@@ -148,6 +148,8 @@ const createAction = (name, payload = {}) => {
|
|
|
148
148
|
return new Events_1.Change(payload);
|
|
149
149
|
case 'submit':
|
|
150
150
|
return new Events_1.Submit(payload);
|
|
151
|
+
case 'save':
|
|
152
|
+
return new Events_1.Save(payload);
|
|
151
153
|
case 'click':
|
|
152
154
|
return new Events_1.Click(payload);
|
|
153
155
|
case 'addItem':
|
|
@@ -353,6 +355,18 @@ class FunctionRuntimeImpl {
|
|
|
353
355
|
},
|
|
354
356
|
_signature: []
|
|
355
357
|
},
|
|
358
|
+
saveForm: {
|
|
359
|
+
_func: (args, data, interpreter) => {
|
|
360
|
+
const action = toString(args[0]);
|
|
361
|
+
const validate_form = args[2] || false;
|
|
362
|
+
interpreter.globals.form.dispatch(new Events_1.Save({
|
|
363
|
+
action,
|
|
364
|
+
validate_form
|
|
365
|
+
}));
|
|
366
|
+
return {};
|
|
367
|
+
},
|
|
368
|
+
_signature: []
|
|
369
|
+
},
|
|
356
370
|
request: {
|
|
357
371
|
_func: (args, data, interpreter) => {
|
|
358
372
|
const uri = toString(args[0]);
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export declare type FormJson = ContainerJson & {
|
|
|
117
117
|
data?: any;
|
|
118
118
|
title?: string;
|
|
119
119
|
action?: string;
|
|
120
|
-
|
|
120
|
+
adaptiveform?: string;
|
|
121
121
|
lang?: string;
|
|
122
122
|
};
|
|
123
123
|
export declare type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import RuleEngine from '../rules/RuleEngine';
|
|
|
3
3
|
import EventQueue from '../controller/EventQueue';
|
|
4
4
|
import DataGroup from '../data/DataGroup';
|
|
5
5
|
import { Logger } from '../controller/Logger';
|
|
6
|
+
import { Version } from '../utils/Version';
|
|
6
7
|
export interface ScriptableField {
|
|
7
8
|
rules?: {
|
|
8
9
|
[key: string]: string;
|
|
@@ -10,7 +11,7 @@ export interface ScriptableField {
|
|
|
10
11
|
events?: {
|
|
11
12
|
[key: string]: string;
|
|
12
13
|
};
|
|
13
|
-
ruleEngine: RuleEngine;
|
|
14
|
+
readonly ruleEngine: RuleEngine;
|
|
14
15
|
}
|
|
15
16
|
interface WithState<T> {
|
|
16
17
|
getState: () => any;
|
|
@@ -33,6 +34,7 @@ export interface Action {
|
|
|
33
34
|
readonly isCustomEvent: boolean;
|
|
34
35
|
readonly target: FormModel | FieldModel | FieldsetModel;
|
|
35
36
|
readonly originalAction?: Action;
|
|
37
|
+
readonly currentTarget: FormModel | FieldModel | FieldsetModel;
|
|
36
38
|
}
|
|
37
39
|
export declare type callbackFn = (action: Action) => void;
|
|
38
40
|
export interface WithController {
|
|
@@ -82,7 +84,7 @@ export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJ
|
|
|
82
84
|
readonly editValue?: string;
|
|
83
85
|
}
|
|
84
86
|
export interface FormMetaDataModel {
|
|
85
|
-
readonly version
|
|
87
|
+
readonly version?: string;
|
|
86
88
|
readonly grammar: string;
|
|
87
89
|
}
|
|
88
90
|
export interface SubmitMetaDataModel {
|
|
@@ -105,6 +107,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
|
|
|
105
107
|
readonly metadata?: MetaDataJson;
|
|
106
108
|
readonly title: string;
|
|
107
109
|
readonly logger: Logger;
|
|
110
|
+
readonly specVersion: Version;
|
|
108
111
|
importData(data: any): any;
|
|
109
112
|
exportData(): any;
|
|
110
113
|
getElement(id: string): FieldModel | FormModel | FieldsetModel;
|
|
@@ -113,6 +116,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
|
|
|
113
116
|
visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
|
|
114
117
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
|
115
118
|
fieldAdded(field: FieldModel | FieldsetModel): void;
|
|
119
|
+
readonly changeEventBehaviour: 'deps' | 'self';
|
|
116
120
|
}
|
|
117
121
|
export interface IFormFieldFactory {
|
|
118
122
|
createField(child: FieldsetJson | FieldJson, options: {
|
|
@@ -43,7 +43,7 @@ class FormFieldFactoryImpl {
|
|
|
43
43
|
});
|
|
44
44
|
retVal = new InstanceManager_1.InstanceManager(newJson, options);
|
|
45
45
|
}
|
|
46
|
-
else if ('items' in child) {
|
|
46
|
+
else if ('items' in child || child.fieldType === 'panel') {
|
|
47
47
|
retVal = new Fieldset_1.Fieldset(child, options);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Version {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(n: string);
|
|
4
|
+
get major(): number;
|
|
5
|
+
get minor(): number;
|
|
6
|
+
get subversion(): number;
|
|
7
|
+
completeMatch(v: Version): boolean;
|
|
8
|
+
lessThan(v: Version): boolean;
|
|
9
|
+
toString(): string;
|
|
10
|
+
valueOf(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Version_minor, _Version_major, _Version_subVersion, _Version_invalid;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Version = void 0;
|
|
16
|
+
class Version {
|
|
17
|
+
constructor(n) {
|
|
18
|
+
_Version_minor.set(this, void 0);
|
|
19
|
+
_Version_major.set(this, void 0);
|
|
20
|
+
_Version_subVersion.set(this, void 0);
|
|
21
|
+
_Version_invalid.set(this, true);
|
|
22
|
+
const match = n.match(/([^.]+)\.([^.]+)(?:\.(.+))?/);
|
|
23
|
+
if (match) {
|
|
24
|
+
__classPrivateFieldSet(this, _Version_major, +match[1], "f");
|
|
25
|
+
__classPrivateFieldSet(this, _Version_minor, +match[2], "f");
|
|
26
|
+
__classPrivateFieldSet(this, _Version_subVersion, match[3] ? +match[3] : 0, "f");
|
|
27
|
+
if (isNaN(__classPrivateFieldGet(this, _Version_major, "f")) || isNaN(__classPrivateFieldGet(this, _Version_minor, "f")) || isNaN(__classPrivateFieldGet(this, _Version_subVersion, "f"))) {
|
|
28
|
+
throw new Error('Invalid version string ' + n);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error('Invalid version string ' + n);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get major() {
|
|
36
|
+
return __classPrivateFieldGet(this, _Version_major, "f");
|
|
37
|
+
}
|
|
38
|
+
get minor() {
|
|
39
|
+
return __classPrivateFieldGet(this, _Version_minor, "f");
|
|
40
|
+
}
|
|
41
|
+
get subversion() {
|
|
42
|
+
return __classPrivateFieldGet(this, _Version_subVersion, "f");
|
|
43
|
+
}
|
|
44
|
+
completeMatch(v) {
|
|
45
|
+
return this.major === v.major &&
|
|
46
|
+
this.minor === v.minor &&
|
|
47
|
+
__classPrivateFieldGet(this, _Version_subVersion, "f") === v.subversion;
|
|
48
|
+
}
|
|
49
|
+
lessThan(v) {
|
|
50
|
+
return this.major < v.major || (this.major === v.major && (this.minor < v.minor)) || (this.major === v.major && this.minor === v.minor && __classPrivateFieldGet(this, _Version_subVersion, "f") < v.subversion);
|
|
51
|
+
}
|
|
52
|
+
toString() {
|
|
53
|
+
return `${this.major}.${this.minor}.${this.subversion}`;
|
|
54
|
+
}
|
|
55
|
+
valueOf() {
|
|
56
|
+
return this.toString();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Version = Version;
|
|
60
|
+
_Version_minor = new WeakMap(), _Version_major = new WeakMap(), _Version_subVersion = new WeakMap(), _Version_invalid = new WeakMap();
|