@aemforms/af-core 0.22.102 → 0.22.104
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 +186 -1
- package/esm/afb-runtime.js +167 -57
- package/esm/types/src/BaseNode.d.ts +2 -0
- package/esm/types/src/Container.d.ts +3 -1
- package/esm/types/src/Form.d.ts +1 -0
- package/esm/types/src/controller/Events.d.ts +7 -7
- package/esm/types/src/rules/RuleEngine.d.ts +1 -1
- package/esm/types/src/types/Model.d.ts +2 -0
- package/lib/BaseNode.d.ts +2 -0
- package/lib/BaseNode.js +11 -0
- package/lib/Container.d.ts +3 -1
- package/lib/Container.js +16 -37
- package/lib/Form.d.ts +1 -0
- package/lib/Form.js +3 -0
- package/lib/Scriptable.js +26 -7
- package/lib/controller/Events.d.ts +7 -7
- package/lib/controller/Events.js +6 -2
- package/lib/rules/FunctionRuntime.js +20 -10
- package/lib/rules/RuleEngine.d.ts +1 -1
- package/lib/rules/RuleEngine.js +7 -4
- package/lib/types/Model.d.ts +2 -0
- package/package.json +2 -2
- package/esm/Events-f062426b.js +0 -270
|
@@ -81,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
|
|
|
81
81
|
_initialize(mode?: FormCreationMode): any;
|
|
82
82
|
_addDependent(dependent: BaseModel): any;
|
|
83
83
|
_eventSource: EventSource;
|
|
84
|
+
readonly fragment: string;
|
|
84
85
|
}
|
|
85
86
|
export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJson> {
|
|
86
87
|
parent: ContainerModel;
|
|
@@ -110,6 +111,7 @@ export interface ContainerModel extends BaseModel, ScriptableField {
|
|
|
110
111
|
importData(data: any): any;
|
|
111
112
|
isTransparent(): boolean;
|
|
112
113
|
activeChild: BaseModel | null;
|
|
114
|
+
isFragment: boolean;
|
|
113
115
|
}
|
|
114
116
|
export interface FieldsetModel extends ContainerModel, WithState<FieldsetJson> {
|
|
115
117
|
type?: 'array' | 'object';
|
package/lib/BaseNode.d.ts
CHANGED
|
@@ -20,12 +20,14 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
20
20
|
};
|
|
21
21
|
private _tokens;
|
|
22
22
|
_eventSource: EventSource;
|
|
23
|
+
protected _fragment: string;
|
|
23
24
|
get isContainer(): boolean;
|
|
24
25
|
constructor(params: T, _options: {
|
|
25
26
|
form: FormModel;
|
|
26
27
|
parent: ContainerModel;
|
|
27
28
|
mode?: 'create' | 'restore';
|
|
28
29
|
});
|
|
30
|
+
get fragment(): string;
|
|
29
31
|
abstract value: Primitives;
|
|
30
32
|
abstract reset(): any;
|
|
31
33
|
protected setupRuleNode(): void;
|
package/lib/BaseNode.js
CHANGED
|
@@ -116,18 +116,29 @@ exports.include = addOnly(true);
|
|
|
116
116
|
exports.exclude = addOnly(false);
|
|
117
117
|
class BaseNode {
|
|
118
118
|
constructor(params, _options) {
|
|
119
|
+
var _a, _b;
|
|
119
120
|
this._options = _options;
|
|
120
121
|
this._lang = '';
|
|
121
122
|
this._callbacks = {};
|
|
122
123
|
this._dependents = [];
|
|
123
124
|
this._tokens = [];
|
|
124
125
|
this._eventSource = index_1.EventSource.CODE;
|
|
126
|
+
this._fragment = '$form';
|
|
125
127
|
this[exports.qualifiedName] = null;
|
|
126
128
|
this._jsonModel = Object.assign(Object.assign({}, params), { id: 'id' in params ? params.id : this.form.getUniqueId() });
|
|
129
|
+
if ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isFragment) {
|
|
130
|
+
this._fragment = this.parent.qualifiedName;
|
|
131
|
+
}
|
|
132
|
+
else if ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.fragment) {
|
|
133
|
+
this._fragment = this.parent.fragment;
|
|
134
|
+
}
|
|
127
135
|
}
|
|
128
136
|
get isContainer() {
|
|
129
137
|
return false;
|
|
130
138
|
}
|
|
139
|
+
get fragment() {
|
|
140
|
+
return this._fragment;
|
|
141
|
+
}
|
|
131
142
|
setupRuleNode() {
|
|
132
143
|
const self = this;
|
|
133
144
|
this._ruleNode = new Proxy(this.ruleNodeReference(), {
|
package/lib/Container.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
6
6
|
protected _childrenReference: any;
|
|
7
7
|
private _itemTemplate;
|
|
8
8
|
private fieldFactory;
|
|
9
|
+
private _isFragment;
|
|
10
|
+
private _insideFragment;
|
|
9
11
|
constructor(json: T, _options: {
|
|
10
12
|
form: FormModel;
|
|
11
13
|
parent: ContainerModel;
|
|
@@ -56,6 +58,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
56
58
|
indexOf(f: FieldModel | FieldsetModel): number;
|
|
57
59
|
defaultDataModel(name: string): DataGroup | undefined;
|
|
58
60
|
_canHaveRepeatingChildren(mode?: FormCreationMode): boolean;
|
|
61
|
+
get isFragment(): any;
|
|
59
62
|
_initialize(mode?: FormCreationMode): void;
|
|
60
63
|
private _initializeSiteContainer;
|
|
61
64
|
addItem(action: Action): void;
|
|
@@ -64,7 +67,6 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
64
67
|
reset(): void;
|
|
65
68
|
validate(): import("./types/Model").ValidationError[];
|
|
66
69
|
dispatch(action: Action): void;
|
|
67
|
-
createDataGroup(dataModel: any): DataGroup | null;
|
|
68
70
|
importData(dataModel: any): void;
|
|
69
71
|
syncDataAndFormModel(contextualDataModel?: DataGroup): any;
|
|
70
72
|
get activeChild(): BaseModel | null;
|
package/lib/Container.js
CHANGED
|
@@ -19,10 +19,14 @@ const notifyChildrenAttributes = [
|
|
|
19
19
|
];
|
|
20
20
|
class Container extends Scriptable_1.default {
|
|
21
21
|
constructor(json, _options) {
|
|
22
|
+
var _a, _b;
|
|
22
23
|
super(json, { form: _options.form, parent: _options.parent, mode: _options.mode });
|
|
23
24
|
this._children = [];
|
|
24
25
|
this._itemTemplate = null;
|
|
26
|
+
this._isFragment = false;
|
|
27
|
+
this._insideFragment = false;
|
|
25
28
|
this._activeChild = null;
|
|
29
|
+
this._isFragment = ((_b = (_a = this._jsonModel) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b['fd:fragment']) === true;
|
|
26
30
|
this.fieldFactory = _options.fieldFactory;
|
|
27
31
|
}
|
|
28
32
|
_getDefaults() {
|
|
@@ -201,6 +205,10 @@ class Container extends Scriptable_1.default {
|
|
|
201
205
|
return this._jsonModel.type == 'array' && this.getDataNode() != null &&
|
|
202
206
|
(items.length === 1 || (items.length > 0 && items[0].repeatable == true && mode === 'restore'));
|
|
203
207
|
}
|
|
208
|
+
get isFragment() {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
return this._isFragment || ((_b = (_a = this._jsonModel) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b['fd:fragment']);
|
|
211
|
+
}
|
|
204
212
|
_initialize(mode) {
|
|
205
213
|
super._initialize(mode);
|
|
206
214
|
const items = this._jsonModel.items || [];
|
|
@@ -275,19 +283,7 @@ class Container extends Scriptable_1.default {
|
|
|
275
283
|
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
276
284
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
277
285
|
const dataNode = this.getDataNode();
|
|
278
|
-
let instanceIndex =
|
|
279
|
-
let instanceData = null;
|
|
280
|
-
if (typeof action.payload === 'number') {
|
|
281
|
-
instanceIndex = action.payload;
|
|
282
|
-
}
|
|
283
|
-
else if (typeof action.payload === 'object') {
|
|
284
|
-
if ('index' in action.payload) {
|
|
285
|
-
instanceIndex = action.payload.index;
|
|
286
|
-
}
|
|
287
|
-
if ('data' in action.payload) {
|
|
288
|
-
instanceData = action.payload.data;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
286
|
+
let instanceIndex = action.payload;
|
|
291
287
|
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
292
288
|
if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
|
|
293
289
|
instanceIndex = this._children.length;
|
|
@@ -303,9 +299,6 @@ class Container extends Scriptable_1.default {
|
|
|
303
299
|
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
304
300
|
this._children[i].dispatch(new Events_1.ExecuteRule());
|
|
305
301
|
}
|
|
306
|
-
if (instanceData) {
|
|
307
|
-
retVal.importData(instanceData);
|
|
308
|
-
}
|
|
309
302
|
}
|
|
310
303
|
}
|
|
311
304
|
}
|
|
@@ -360,22 +353,15 @@ class Container extends Scriptable_1.default {
|
|
|
360
353
|
dispatch(action) {
|
|
361
354
|
super.dispatch(action);
|
|
362
355
|
}
|
|
363
|
-
createDataGroup(dataModel) {
|
|
364
|
-
var _a;
|
|
365
|
-
const dataGroup = new DataGroup_1.default(this._data.$name, dataModel, this._data.$type, this._data.parent);
|
|
366
|
-
try {
|
|
367
|
-
(_a = this._data.parent) === null || _a === void 0 ? void 0 : _a.$addDataNode(dataGroup.$name, dataGroup, true);
|
|
368
|
-
}
|
|
369
|
-
catch (e) {
|
|
370
|
-
this.form.logger.error(`Unable to set items for container '${this.qualifiedName}' with data model '${dataModel}': ${e.message}`);
|
|
371
|
-
return null;
|
|
372
|
-
}
|
|
373
|
-
return dataGroup;
|
|
374
|
-
}
|
|
375
356
|
importData(dataModel) {
|
|
357
|
+
var _a;
|
|
376
358
|
if (typeof this._data !== 'undefined' && this.type === 'array' && Array.isArray(dataModel)) {
|
|
377
|
-
const dataGroup = this.
|
|
378
|
-
|
|
359
|
+
const dataGroup = new DataGroup_1.default(this._data.$name, dataModel, this._data.$type, this._data.parent);
|
|
360
|
+
try {
|
|
361
|
+
(_a = this._data.parent) === null || _a === void 0 ? void 0 : _a.$addDataNode(dataGroup.$name, dataGroup, true);
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
this.form.logger.error(`unable to setItems for ${this.qualifiedName} : ${e}`);
|
|
379
365
|
return;
|
|
380
366
|
}
|
|
381
367
|
this._data = dataGroup;
|
|
@@ -392,13 +378,6 @@ class Container extends Scriptable_1.default {
|
|
|
392
378
|
this.notifyDependents((0, Events_1.propertyChange)('items', null, item.getState()));
|
|
393
379
|
});
|
|
394
380
|
}
|
|
395
|
-
if (typeof this._data !== 'undefined' && this.type === 'object') {
|
|
396
|
-
const dataGroup = this.createDataGroup(dataModel);
|
|
397
|
-
if (!dataGroup) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
this.syncDataAndFormModel(dataGroup);
|
|
401
|
-
}
|
|
402
381
|
}
|
|
403
382
|
syncDataAndFormModel(contextualDataModel) {
|
|
404
383
|
const result = {
|
package/lib/Form.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
26
26
|
private dataRefRegex;
|
|
27
27
|
get metaData(): FormMetaData;
|
|
28
28
|
get action(): string | undefined;
|
|
29
|
+
get isFragment(): boolean;
|
|
29
30
|
importData(dataModel: any): void;
|
|
30
31
|
exportData(): any;
|
|
31
32
|
setAdditionalSubmitMetadata(metadata: Record<string, any>): void;
|
package/lib/Form.js
CHANGED
|
@@ -83,6 +83,9 @@ class Form extends Container_1.default {
|
|
|
83
83
|
get action() {
|
|
84
84
|
return this._jsonModel.action;
|
|
85
85
|
}
|
|
86
|
+
get isFragment() {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
86
89
|
importData(dataModel) {
|
|
87
90
|
this.bindToDataModel(new DataGroup_1.default('$form', dataModel));
|
|
88
91
|
this.syncDataAndFormModel(this.getDataNode());
|
package/lib/Scriptable.js
CHANGED
|
@@ -15,7 +15,11 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
15
15
|
const eString = rule || this.getRules()[eName];
|
|
16
16
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
let updatedRule = eString;
|
|
19
|
+
if (this.fragment !== '$form') {
|
|
20
|
+
updatedRule = eString.replaceAll('$form', this.fragment);
|
|
21
|
+
}
|
|
22
|
+
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
19
23
|
}
|
|
20
24
|
catch (e) {
|
|
21
25
|
this.form.logger.error(`Unable to compile rule \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -37,7 +41,11 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
37
41
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
38
42
|
this._events[eName] = eString.map(x => {
|
|
39
43
|
try {
|
|
40
|
-
|
|
44
|
+
let updatedExpr = x;
|
|
45
|
+
if (this.fragment !== '$form') {
|
|
46
|
+
updatedExpr = x.replaceAll('$form', this.fragment);
|
|
47
|
+
}
|
|
48
|
+
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
41
49
|
}
|
|
42
50
|
catch (e) {
|
|
43
51
|
this.form.logger.error(`Unable to compile expression \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -74,7 +82,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
74
82
|
entries.forEach(([prop, rule]) => {
|
|
75
83
|
const node = this.getCompiledRule(prop, rule);
|
|
76
84
|
if (node) {
|
|
77
|
-
const newVal = this.ruleEngine.execute(node, scope, context, true);
|
|
85
|
+
const newVal = this.ruleEngine.execute(node, scope, context, true, rule);
|
|
78
86
|
if (BaseNode_1.editableProperties.indexOf(prop) > -1) {
|
|
79
87
|
const oldAndNewValueAreEmpty = this.isEmpty() && this.isEmpty(newVal) && prop === 'value';
|
|
80
88
|
if (!oldAndNewValueAreEmpty) {
|
|
@@ -129,10 +137,10 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
129
137
|
});
|
|
130
138
|
return scope;
|
|
131
139
|
}
|
|
132
|
-
executeEvent(context, node) {
|
|
140
|
+
executeEvent(context, node, eString) {
|
|
133
141
|
let updates;
|
|
134
142
|
if (node) {
|
|
135
|
-
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
|
|
143
|
+
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context, false, eString);
|
|
136
144
|
}
|
|
137
145
|
if (typeof updates !== 'undefined' && updates != null) {
|
|
138
146
|
this.applyUpdates(updates);
|
|
@@ -151,7 +159,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
151
159
|
'field': this
|
|
152
160
|
};
|
|
153
161
|
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
154
|
-
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
162
|
+
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext, false, expr);
|
|
155
163
|
}
|
|
156
164
|
change(event, context) {
|
|
157
165
|
if (this.form.changeEventBehaviour === 'deps') {
|
|
@@ -159,6 +167,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
159
167
|
}
|
|
160
168
|
}
|
|
161
169
|
executeAction(action) {
|
|
170
|
+
var _a;
|
|
162
171
|
const context = {
|
|
163
172
|
'form': this.form,
|
|
164
173
|
'$form': this.form.getRuleNode(),
|
|
@@ -173,10 +182,20 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
173
182
|
const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
|
|
174
183
|
const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
|
|
175
184
|
const node = this.getCompiledEvent(eventName);
|
|
185
|
+
const events = (_a = this._jsonModel.events) === null || _a === void 0 ? void 0 : _a[eventName];
|
|
176
186
|
if (funcName in this && typeof this[funcName] === 'function') {
|
|
177
187
|
this[funcName](action, context);
|
|
178
188
|
}
|
|
179
|
-
node.forEach((n) =>
|
|
189
|
+
node.forEach((n, index) => {
|
|
190
|
+
let eString = '';
|
|
191
|
+
if (Array.isArray(events)) {
|
|
192
|
+
eString = events[index];
|
|
193
|
+
}
|
|
194
|
+
else if (typeof events === 'string') {
|
|
195
|
+
eString = events;
|
|
196
|
+
}
|
|
197
|
+
this.executeEvent(context, n, eString);
|
|
198
|
+
});
|
|
180
199
|
if (action.target === this) {
|
|
181
200
|
this.notifyDependents(action);
|
|
182
201
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Action, BaseJson, FieldModel, FieldsetModel, FormModel, ValidationError
|
|
1
|
+
import { Action, BaseJson, FieldModel, FieldsetModel, FormModel, ValidationError } from '../types/index';
|
|
2
|
+
declare enum EventSource {
|
|
3
|
+
CODE = "code",
|
|
4
|
+
UI = "ui"
|
|
5
|
+
}
|
|
2
6
|
declare class ActionImpl implements Action {
|
|
3
7
|
private _metadata?;
|
|
4
8
|
protected _type: string;
|
|
@@ -32,10 +36,6 @@ export declare type UIChangePayload = {
|
|
|
32
36
|
value?: any;
|
|
33
37
|
checked?: boolean;
|
|
34
38
|
};
|
|
35
|
-
export declare type AddItemPayload = {
|
|
36
|
-
index: number;
|
|
37
|
-
data: Record<string, any>;
|
|
38
|
-
};
|
|
39
39
|
export declare class Change extends ActionImpl {
|
|
40
40
|
constructor(payload: ChangePayload, dispatch?: boolean);
|
|
41
41
|
withAdditionalChange(change: Change): Change;
|
|
@@ -97,13 +97,13 @@ export declare class CustomEvent extends ActionImpl {
|
|
|
97
97
|
get isCustomEvent(): boolean;
|
|
98
98
|
}
|
|
99
99
|
export declare class AddItem extends ActionImpl {
|
|
100
|
-
constructor(payload?: number
|
|
100
|
+
constructor(payload?: number);
|
|
101
101
|
}
|
|
102
102
|
export declare class RemoveItem extends ActionImpl {
|
|
103
103
|
constructor(payload?: number);
|
|
104
104
|
}
|
|
105
105
|
export declare class AddInstance extends ActionImpl {
|
|
106
|
-
constructor(payload?: number
|
|
106
|
+
constructor(payload?: number);
|
|
107
107
|
}
|
|
108
108
|
export declare class RemoveInstance extends ActionImpl {
|
|
109
109
|
constructor(payload?: number);
|
package/lib/controller/Events.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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.UIChange = exports.Change = void 0;
|
|
4
|
-
|
|
4
|
+
var EventSource;
|
|
5
|
+
(function (EventSource) {
|
|
6
|
+
EventSource["CODE"] = "code";
|
|
7
|
+
EventSource["UI"] = "ui";
|
|
8
|
+
})(EventSource || (EventSource = {}));
|
|
5
9
|
class ActionImpl {
|
|
6
10
|
constructor(payload, type, _metadata) {
|
|
7
11
|
this._metadata = _metadata;
|
|
@@ -158,7 +162,7 @@ class Reset extends ActionImpl {
|
|
|
158
162
|
}
|
|
159
163
|
exports.Reset = Reset;
|
|
160
164
|
class FieldChanged extends ActionImpl {
|
|
161
|
-
constructor(changes, field, eventSource =
|
|
165
|
+
constructor(changes, field, eventSource = EventSource.CODE) {
|
|
162
166
|
super({
|
|
163
167
|
field,
|
|
164
168
|
changes,
|
|
@@ -143,26 +143,32 @@ const multipartFormData = (data, attachments) => {
|
|
|
143
143
|
}
|
|
144
144
|
return formData;
|
|
145
145
|
};
|
|
146
|
-
const createAction = (name, payload = {}) => {
|
|
146
|
+
const createAction = (name, payload = {}, dispatch = false) => {
|
|
147
147
|
switch (name) {
|
|
148
148
|
case 'change':
|
|
149
|
-
return new Events_1.Change(payload);
|
|
149
|
+
return new Events_1.Change(payload, dispatch);
|
|
150
150
|
case 'submit':
|
|
151
|
-
return new Events_1.Submit(payload);
|
|
151
|
+
return new Events_1.Submit(payload, dispatch);
|
|
152
152
|
case 'save':
|
|
153
|
-
return new Events_1.Save(payload);
|
|
153
|
+
return new Events_1.Save(payload, dispatch);
|
|
154
154
|
case 'click':
|
|
155
|
-
return new Events_1.Click(payload);
|
|
155
|
+
return new Events_1.Click(payload, dispatch);
|
|
156
156
|
case 'addItem':
|
|
157
157
|
return new Events_1.AddItem(payload);
|
|
158
158
|
case 'removeItem':
|
|
159
159
|
return new Events_1.RemoveItem(payload);
|
|
160
160
|
case 'reset':
|
|
161
|
-
return new Events_1.Reset(payload);
|
|
161
|
+
return new Events_1.Reset(payload, dispatch);
|
|
162
162
|
case 'addInstance':
|
|
163
163
|
return new Events_1.AddInstance(payload);
|
|
164
164
|
case 'removeInstance':
|
|
165
165
|
return new Events_1.RemoveInstance(payload);
|
|
166
|
+
case 'invalid':
|
|
167
|
+
return new Events_1.Invalid(payload);
|
|
168
|
+
case 'valid':
|
|
169
|
+
return new Events_1.Valid(payload);
|
|
170
|
+
case 'initialize':
|
|
171
|
+
return new Events_1.Initialize(payload, dispatch);
|
|
166
172
|
default:
|
|
167
173
|
console.error('invalid action');
|
|
168
174
|
}
|
|
@@ -236,8 +242,8 @@ class FunctionRuntimeImpl {
|
|
|
236
242
|
const args = [target, flag];
|
|
237
243
|
return FunctionRuntimeImpl.getInstance().getFunctions().setFocus._func.call(undefined, args, data, interpreter);
|
|
238
244
|
},
|
|
239
|
-
dispatchEvent: (target, eventName, payload) => {
|
|
240
|
-
const args = [target, eventName, payload];
|
|
245
|
+
dispatchEvent: (target, eventName, payload, dispatch) => {
|
|
246
|
+
const args = [target, eventName, payload, dispatch];
|
|
241
247
|
return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
|
|
242
248
|
},
|
|
243
249
|
getFiles: (qualifiedName) => {
|
|
@@ -497,9 +503,13 @@ class FunctionRuntimeImpl {
|
|
|
497
503
|
dispatchEvent: {
|
|
498
504
|
_func: (args, data, interpreter) => {
|
|
499
505
|
const element = args[0];
|
|
506
|
+
if (element === null && typeof interpreter !== 'string') {
|
|
507
|
+
interpreter.debug.push('Invalid argument passed in dispatchEvent. An element is expected');
|
|
508
|
+
return {};
|
|
509
|
+
}
|
|
500
510
|
let eventName = valueOf(args[1]);
|
|
501
511
|
let payload = args.length > 2 ? valueOf(args[2]) : undefined;
|
|
502
|
-
let dispatch = false;
|
|
512
|
+
let dispatch = args.length > 3 ? valueOf(args[3]) : false;
|
|
503
513
|
if (typeof element === 'string') {
|
|
504
514
|
payload = eventName;
|
|
505
515
|
eventName = element;
|
|
@@ -510,7 +520,7 @@ class FunctionRuntimeImpl {
|
|
|
510
520
|
event = new Events_1.CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
|
|
511
521
|
}
|
|
512
522
|
else {
|
|
513
|
-
event = createAction(eventName, payload);
|
|
523
|
+
event = createAction(eventName, payload, dispatch);
|
|
514
524
|
}
|
|
515
525
|
if (event != null) {
|
|
516
526
|
if (typeof element === 'string') {
|
|
@@ -10,7 +10,7 @@ declare class RuleEngine {
|
|
|
10
10
|
formula: Formula;
|
|
11
11
|
ast: any;
|
|
12
12
|
};
|
|
13
|
-
execute(node: any, data: any, globals: any, useValueOf
|
|
13
|
+
execute(node: any, data: any, globals: any, useValueOf: boolean | undefined, eString: string): any;
|
|
14
14
|
trackDependency(subscriber: BaseModel): void;
|
|
15
15
|
}
|
|
16
16
|
export default RuleEngine;
|
package/lib/rules/RuleEngine.js
CHANGED
|
@@ -27,8 +27,8 @@ class RuleEngine {
|
|
|
27
27
|
const formula = new json_formula_1.default(this.customFunctions, getStringToNumberFn(locale), this.debugInfo);
|
|
28
28
|
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
29
29
|
}
|
|
30
|
-
execute(node, data, globals, useValueOf = false) {
|
|
31
|
-
var _a, _b, _c, _d, _e, _f;
|
|
30
|
+
execute(node, data, globals, useValueOf = false, eString) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
32
32
|
const { formula, ast } = node;
|
|
33
33
|
const oldContext = this._context;
|
|
34
34
|
this._context = globals;
|
|
@@ -39,8 +39,11 @@ class RuleEngine {
|
|
|
39
39
|
catch (err) {
|
|
40
40
|
(_c = (_b = (_a = this._context) === null || _a === void 0 ? void 0 : _a.form) === null || _b === void 0 ? void 0 : _b.logger) === null || _c === void 0 ? void 0 : _c.error(err);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
(_f = (_e = (_d = this._context) === null || _d === void 0 ? void 0 : _d.form) === null || _e === void 0 ? void 0 : _e.logger) === null || _f === void 0 ? void 0 : _f.
|
|
42
|
+
if (this.debugInfo.length) {
|
|
43
|
+
(_f = (_e = (_d = this._context) === null || _d === void 0 ? void 0 : _d.form) === null || _e === void 0 ? void 0 : _e.logger) === null || _f === void 0 ? void 0 : _f.warn(`Form rule expression string: ${eString}`);
|
|
44
|
+
while (this.debugInfo.length > 0) {
|
|
45
|
+
(_j = (_h = (_g = this._context) === null || _g === void 0 ? void 0 : _g.form) === null || _h === void 0 ? void 0 : _h.logger) === null || _j === void 0 ? void 0 : _j.warn(this.debugInfo.pop());
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
let finalRes = res;
|
|
46
49
|
if (useValueOf) {
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
|
|
|
81
81
|
_initialize(mode?: FormCreationMode): any;
|
|
82
82
|
_addDependent(dependent: BaseModel): any;
|
|
83
83
|
_eventSource: EventSource;
|
|
84
|
+
readonly fragment: string;
|
|
84
85
|
}
|
|
85
86
|
export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJson> {
|
|
86
87
|
parent: ContainerModel;
|
|
@@ -110,6 +111,7 @@ export interface ContainerModel extends BaseModel, ScriptableField {
|
|
|
110
111
|
importData(data: any): any;
|
|
111
112
|
isTransparent(): boolean;
|
|
112
113
|
activeChild: BaseModel | null;
|
|
114
|
+
isFragment: boolean;
|
|
113
115
|
}
|
|
114
116
|
export interface FieldsetModel extends ContainerModel, WithState<FieldsetJson> {
|
|
115
117
|
type?: 'array' | 'object';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.104",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@adobe/json-formula": "0.1.50",
|
|
40
|
-
"@aemforms/af-formatters": "^0.22.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.104"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|