@aemforms/af-core 0.22.102 → 0.22.103
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-runtime.js +61 -46
- 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 +2 -6
- 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 +2 -6
- package/lib/rules/FunctionRuntime.js +4 -0
- 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/afb-runtime.js
CHANGED
|
@@ -1157,6 +1157,7 @@ class BaseNode {
|
|
|
1157
1157
|
_jsonModel;
|
|
1158
1158
|
_tokens = [];
|
|
1159
1159
|
_eventSource = EventSource.CODE;
|
|
1160
|
+
_fragment = '$form';
|
|
1160
1161
|
get isContainer() {
|
|
1161
1162
|
return false;
|
|
1162
1163
|
}
|
|
@@ -1167,6 +1168,15 @@ class BaseNode {
|
|
|
1167
1168
|
...params,
|
|
1168
1169
|
id: 'id' in params ? params.id : this.form.getUniqueId()
|
|
1169
1170
|
};
|
|
1171
|
+
if (this.parent?.isFragment) {
|
|
1172
|
+
this._fragment = this.parent.qualifiedName;
|
|
1173
|
+
}
|
|
1174
|
+
else if (this.parent?.fragment) {
|
|
1175
|
+
this._fragment = this.parent.fragment;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
get fragment() {
|
|
1179
|
+
return this._fragment;
|
|
1170
1180
|
}
|
|
1171
1181
|
setupRuleNode() {
|
|
1172
1182
|
const self = this;
|
|
@@ -1588,7 +1598,11 @@ class Scriptable extends BaseNode {
|
|
|
1588
1598
|
const eString = rule || this.getRules()[eName];
|
|
1589
1599
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
1590
1600
|
try {
|
|
1591
|
-
|
|
1601
|
+
let updatedRule = eString;
|
|
1602
|
+
if (this.fragment !== '$form') {
|
|
1603
|
+
updatedRule = eString.replaceAll('$form', this.fragment);
|
|
1604
|
+
}
|
|
1605
|
+
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
1592
1606
|
}
|
|
1593
1607
|
catch (e) {
|
|
1594
1608
|
this.form.logger.error(`Unable to compile rule \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -1609,7 +1623,11 @@ class Scriptable extends BaseNode {
|
|
|
1609
1623
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
1610
1624
|
this._events[eName] = eString.map(x => {
|
|
1611
1625
|
try {
|
|
1612
|
-
|
|
1626
|
+
let updatedExpr = x;
|
|
1627
|
+
if (this.fragment !== '$form') {
|
|
1628
|
+
updatedExpr = x.replaceAll('$form', this.fragment);
|
|
1629
|
+
}
|
|
1630
|
+
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
1613
1631
|
}
|
|
1614
1632
|
catch (e) {
|
|
1615
1633
|
this.form.logger.error(`Unable to compile expression \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -1646,7 +1664,7 @@ class Scriptable extends BaseNode {
|
|
|
1646
1664
|
entries.forEach(([prop, rule]) => {
|
|
1647
1665
|
const node = this.getCompiledRule(prop, rule);
|
|
1648
1666
|
if (node) {
|
|
1649
|
-
const newVal = this.ruleEngine.execute(node, scope, context, true);
|
|
1667
|
+
const newVal = this.ruleEngine.execute(node, scope, context, true, rule);
|
|
1650
1668
|
if (editableProperties.indexOf(prop) > -1) {
|
|
1651
1669
|
const oldAndNewValueAreEmpty = this.isEmpty() && this.isEmpty(newVal) && prop === 'value';
|
|
1652
1670
|
if (!oldAndNewValueAreEmpty) {
|
|
@@ -1701,10 +1719,10 @@ class Scriptable extends BaseNode {
|
|
|
1701
1719
|
});
|
|
1702
1720
|
return scope;
|
|
1703
1721
|
}
|
|
1704
|
-
executeEvent(context, node) {
|
|
1722
|
+
executeEvent(context, node, eString) {
|
|
1705
1723
|
let updates;
|
|
1706
1724
|
if (node) {
|
|
1707
|
-
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
|
|
1725
|
+
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context, false, eString);
|
|
1708
1726
|
}
|
|
1709
1727
|
if (typeof updates !== 'undefined' && updates != null) {
|
|
1710
1728
|
this.applyUpdates(updates);
|
|
@@ -1723,7 +1741,7 @@ class Scriptable extends BaseNode {
|
|
|
1723
1741
|
'field': this
|
|
1724
1742
|
};
|
|
1725
1743
|
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
1726
|
-
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
1744
|
+
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext, false, expr);
|
|
1727
1745
|
}
|
|
1728
1746
|
change(event, context) {
|
|
1729
1747
|
if (this.form.changeEventBehaviour === 'deps') {
|
|
@@ -1745,10 +1763,20 @@ class Scriptable extends BaseNode {
|
|
|
1745
1763
|
const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
|
|
1746
1764
|
const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
|
|
1747
1765
|
const node = this.getCompiledEvent(eventName);
|
|
1766
|
+
const events = this._jsonModel.events?.[eventName];
|
|
1748
1767
|
if (funcName in this && typeof this[funcName] === 'function') {
|
|
1749
1768
|
this[funcName](action, context);
|
|
1750
1769
|
}
|
|
1751
|
-
node.forEach((n) =>
|
|
1770
|
+
node.forEach((n, index) => {
|
|
1771
|
+
let eString = '';
|
|
1772
|
+
if (Array.isArray(events)) {
|
|
1773
|
+
eString = events[index];
|
|
1774
|
+
}
|
|
1775
|
+
else if (typeof events === 'string') {
|
|
1776
|
+
eString = events;
|
|
1777
|
+
}
|
|
1778
|
+
this.executeEvent(context, n, eString);
|
|
1779
|
+
});
|
|
1752
1780
|
if (action.target === this) {
|
|
1753
1781
|
this.notifyDependents(action);
|
|
1754
1782
|
}
|
|
@@ -1763,8 +1791,11 @@ class Container extends Scriptable {
|
|
|
1763
1791
|
_childrenReference;
|
|
1764
1792
|
_itemTemplate = null;
|
|
1765
1793
|
fieldFactory;
|
|
1794
|
+
_isFragment = false;
|
|
1795
|
+
_insideFragment = false;
|
|
1766
1796
|
constructor(json, _options) {
|
|
1767
1797
|
super(json, { form: _options.form, parent: _options.parent, mode: _options.mode });
|
|
1798
|
+
this._isFragment = this._jsonModel?.properties?.['fd:fragment'] === true;
|
|
1768
1799
|
this.fieldFactory = _options.fieldFactory;
|
|
1769
1800
|
}
|
|
1770
1801
|
_getDefaults() {
|
|
@@ -1969,6 +2000,9 @@ class Container extends Scriptable {
|
|
|
1969
2000
|
return this._jsonModel.type == 'array' && this.getDataNode() != null &&
|
|
1970
2001
|
(items.length === 1 || (items.length > 0 && items[0].repeatable == true && mode === 'restore'));
|
|
1971
2002
|
}
|
|
2003
|
+
get isFragment() {
|
|
2004
|
+
return this._isFragment || this._jsonModel?.properties?.['fd:fragment'];
|
|
2005
|
+
}
|
|
1972
2006
|
_initialize(mode) {
|
|
1973
2007
|
super._initialize(mode);
|
|
1974
2008
|
const items = this._jsonModel.items || [];
|
|
@@ -2043,19 +2077,7 @@ class Container extends Scriptable {
|
|
|
2043
2077
|
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
2044
2078
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
2045
2079
|
const dataNode = this.getDataNode();
|
|
2046
|
-
let instanceIndex =
|
|
2047
|
-
let instanceData = null;
|
|
2048
|
-
if (typeof action.payload === 'number') {
|
|
2049
|
-
instanceIndex = action.payload;
|
|
2050
|
-
}
|
|
2051
|
-
else if (typeof action.payload === 'object') {
|
|
2052
|
-
if ('index' in action.payload) {
|
|
2053
|
-
instanceIndex = action.payload.index;
|
|
2054
|
-
}
|
|
2055
|
-
if ('data' in action.payload) {
|
|
2056
|
-
instanceData = action.payload.data;
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2080
|
+
let instanceIndex = action.payload;
|
|
2059
2081
|
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
2060
2082
|
if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
|
|
2061
2083
|
instanceIndex = this._children.length;
|
|
@@ -2071,9 +2093,6 @@ class Container extends Scriptable {
|
|
|
2071
2093
|
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
2072
2094
|
this._children[i].dispatch(new ExecuteRule());
|
|
2073
2095
|
}
|
|
2074
|
-
if (instanceData) {
|
|
2075
|
-
retVal.importData(instanceData);
|
|
2076
|
-
}
|
|
2077
2096
|
}
|
|
2078
2097
|
}
|
|
2079
2098
|
}
|
|
@@ -2127,21 +2146,14 @@ class Container extends Scriptable {
|
|
|
2127
2146
|
dispatch(action) {
|
|
2128
2147
|
super.dispatch(action);
|
|
2129
2148
|
}
|
|
2130
|
-
createDataGroup(dataModel) {
|
|
2131
|
-
const dataGroup = new DataGroup(this._data.$name, dataModel, this._data.$type, this._data.parent);
|
|
2132
|
-
try {
|
|
2133
|
-
this._data.parent?.$addDataNode(dataGroup.$name, dataGroup, true);
|
|
2134
|
-
}
|
|
2135
|
-
catch (e) {
|
|
2136
|
-
this.form.logger.error(`Unable to set items for container '${this.qualifiedName}' with data model '${dataModel}': ${e.message}`);
|
|
2137
|
-
return null;
|
|
2138
|
-
}
|
|
2139
|
-
return dataGroup;
|
|
2140
|
-
}
|
|
2141
2149
|
importData(dataModel) {
|
|
2142
2150
|
if (typeof this._data !== 'undefined' && this.type === 'array' && Array.isArray(dataModel)) {
|
|
2143
|
-
const dataGroup = this.
|
|
2144
|
-
|
|
2151
|
+
const dataGroup = new DataGroup(this._data.$name, dataModel, this._data.$type, this._data.parent);
|
|
2152
|
+
try {
|
|
2153
|
+
this._data.parent?.$addDataNode(dataGroup.$name, dataGroup, true);
|
|
2154
|
+
}
|
|
2155
|
+
catch (e) {
|
|
2156
|
+
this.form.logger.error(`unable to setItems for ${this.qualifiedName} : ${e}`);
|
|
2145
2157
|
return;
|
|
2146
2158
|
}
|
|
2147
2159
|
this._data = dataGroup;
|
|
@@ -2158,13 +2170,6 @@ class Container extends Scriptable {
|
|
|
2158
2170
|
this.notifyDependents(propertyChange('items', null, item.getState()));
|
|
2159
2171
|
});
|
|
2160
2172
|
}
|
|
2161
|
-
if (typeof this._data !== 'undefined' && this.type === 'object') {
|
|
2162
|
-
const dataGroup = this.createDataGroup(dataModel);
|
|
2163
|
-
if (!dataGroup) {
|
|
2164
|
-
return;
|
|
2165
|
-
}
|
|
2166
|
-
this.syncDataAndFormModel(dataGroup);
|
|
2167
|
-
}
|
|
2168
2173
|
}
|
|
2169
2174
|
syncDataAndFormModel(contextualDataModel) {
|
|
2170
2175
|
const result = {
|
|
@@ -2963,6 +2968,10 @@ class FunctionRuntimeImpl {
|
|
|
2963
2968
|
dispatchEvent: {
|
|
2964
2969
|
_func: (args, data, interpreter) => {
|
|
2965
2970
|
const element = args[0];
|
|
2971
|
+
if (element === null && typeof interpreter !== 'string') {
|
|
2972
|
+
interpreter.debug.push('Invalid argument passed in dispatchEvent. An element is expected');
|
|
2973
|
+
return {};
|
|
2974
|
+
}
|
|
2966
2975
|
let eventName = valueOf(args[1]);
|
|
2967
2976
|
let payload = args.length > 2 ? valueOf(args[2]) : undefined;
|
|
2968
2977
|
let dispatch = false;
|
|
@@ -3105,6 +3114,9 @@ class Form extends Container {
|
|
|
3105
3114
|
get action() {
|
|
3106
3115
|
return this._jsonModel.action;
|
|
3107
3116
|
}
|
|
3117
|
+
get isFragment() {
|
|
3118
|
+
return false;
|
|
3119
|
+
}
|
|
3108
3120
|
importData(dataModel) {
|
|
3109
3121
|
this.bindToDataModel(new DataGroup('$form', dataModel));
|
|
3110
3122
|
this.syncDataAndFormModel(this.getDataNode());
|
|
@@ -3432,7 +3444,7 @@ class RuleEngine {
|
|
|
3432
3444
|
const formula = new Formula(this.customFunctions, getStringToNumberFn(locale), this.debugInfo);
|
|
3433
3445
|
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
3434
3446
|
}
|
|
3435
|
-
execute(node, data, globals, useValueOf = false) {
|
|
3447
|
+
execute(node, data, globals, useValueOf = false, eString) {
|
|
3436
3448
|
const { formula, ast } = node;
|
|
3437
3449
|
const oldContext = this._context;
|
|
3438
3450
|
this._context = globals;
|
|
@@ -3443,8 +3455,11 @@ class RuleEngine {
|
|
|
3443
3455
|
catch (err) {
|
|
3444
3456
|
this._context?.form?.logger?.error(err);
|
|
3445
3457
|
}
|
|
3446
|
-
|
|
3447
|
-
this._context?.form?.logger?.
|
|
3458
|
+
if (this.debugInfo.length) {
|
|
3459
|
+
this._context?.form?.logger?.warn(`Form rule expression string: ${eString}`);
|
|
3460
|
+
while (this.debugInfo.length > 0) {
|
|
3461
|
+
this._context?.form?.logger?.warn(this.debugInfo.pop());
|
|
3462
|
+
}
|
|
3448
3463
|
}
|
|
3449
3464
|
let finalRes = res;
|
|
3450
3465
|
if (useValueOf) {
|
|
@@ -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;
|
|
@@ -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/esm/types/src/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;
|
|
@@ -32,10 +32,6 @@ export type UIChangePayload = {
|
|
|
32
32
|
value?: any;
|
|
33
33
|
checked?: boolean;
|
|
34
34
|
};
|
|
35
|
-
export type AddItemPayload = {
|
|
36
|
-
index: number;
|
|
37
|
-
data: Record<string, any>;
|
|
38
|
-
};
|
|
39
35
|
export declare class Change extends ActionImpl {
|
|
40
36
|
constructor(payload: ChangePayload, dispatch?: boolean);
|
|
41
37
|
withAdditionalChange(change: Change): Change;
|
|
@@ -97,13 +93,13 @@ export declare class CustomEvent extends ActionImpl {
|
|
|
97
93
|
get isCustomEvent(): boolean;
|
|
98
94
|
}
|
|
99
95
|
export declare class AddItem extends ActionImpl {
|
|
100
|
-
constructor(payload?: number
|
|
96
|
+
constructor(payload?: number);
|
|
101
97
|
}
|
|
102
98
|
export declare class RemoveItem extends ActionImpl {
|
|
103
99
|
constructor(payload?: number);
|
|
104
100
|
}
|
|
105
101
|
export declare class AddInstance extends ActionImpl {
|
|
106
|
-
constructor(payload?: number
|
|
102
|
+
constructor(payload?: number);
|
|
107
103
|
}
|
|
108
104
|
export declare class RemoveInstance extends ActionImpl {
|
|
109
105
|
constructor(payload?: number);
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -32,10 +32,6 @@ export declare type UIChangePayload = {
|
|
|
32
32
|
value?: any;
|
|
33
33
|
checked?: boolean;
|
|
34
34
|
};
|
|
35
|
-
export declare type AddItemPayload = {
|
|
36
|
-
index: number;
|
|
37
|
-
data: Record<string, any>;
|
|
38
|
-
};
|
|
39
35
|
export declare class Change extends ActionImpl {
|
|
40
36
|
constructor(payload: ChangePayload, dispatch?: boolean);
|
|
41
37
|
withAdditionalChange(change: Change): Change;
|
|
@@ -97,13 +93,13 @@ export declare class CustomEvent extends ActionImpl {
|
|
|
97
93
|
get isCustomEvent(): boolean;
|
|
98
94
|
}
|
|
99
95
|
export declare class AddItem extends ActionImpl {
|
|
100
|
-
constructor(payload?: number
|
|
96
|
+
constructor(payload?: number);
|
|
101
97
|
}
|
|
102
98
|
export declare class RemoveItem extends ActionImpl {
|
|
103
99
|
constructor(payload?: number);
|
|
104
100
|
}
|
|
105
101
|
export declare class AddInstance extends ActionImpl {
|
|
106
|
-
constructor(payload?: number
|
|
102
|
+
constructor(payload?: number);
|
|
107
103
|
}
|
|
108
104
|
export declare class RemoveInstance extends ActionImpl {
|
|
109
105
|
constructor(payload?: number);
|
|
@@ -497,6 +497,10 @@ class FunctionRuntimeImpl {
|
|
|
497
497
|
dispatchEvent: {
|
|
498
498
|
_func: (args, data, interpreter) => {
|
|
499
499
|
const element = args[0];
|
|
500
|
+
if (element === null && typeof interpreter !== 'string') {
|
|
501
|
+
interpreter.debug.push('Invalid argument passed in dispatchEvent. An element is expected');
|
|
502
|
+
return {};
|
|
503
|
+
}
|
|
500
504
|
let eventName = valueOf(args[1]);
|
|
501
505
|
let payload = args.length > 2 ? valueOf(args[2]) : undefined;
|
|
502
506
|
let dispatch = false;
|
|
@@ -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.103",
|
|
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.103"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|