@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
package/esm/afb-events.js
CHANGED
|
@@ -1 +1,186 @@
|
|
|
1
|
-
|
|
1
|
+
var EventSource;
|
|
2
|
+
(function (EventSource) {
|
|
3
|
+
EventSource["CODE"] = "code";
|
|
4
|
+
EventSource["UI"] = "ui";
|
|
5
|
+
})(EventSource || (EventSource = {}));
|
|
6
|
+
class ActionImpl {
|
|
7
|
+
_metadata;
|
|
8
|
+
_type;
|
|
9
|
+
_payload;
|
|
10
|
+
_target;
|
|
11
|
+
_currentTarget;
|
|
12
|
+
constructor(payload, type, _metadata) {
|
|
13
|
+
this._metadata = _metadata;
|
|
14
|
+
this._payload = payload;
|
|
15
|
+
this._type = type;
|
|
16
|
+
}
|
|
17
|
+
get type() {
|
|
18
|
+
return this._type;
|
|
19
|
+
}
|
|
20
|
+
get payload() {
|
|
21
|
+
return this._payload;
|
|
22
|
+
}
|
|
23
|
+
get metadata() {
|
|
24
|
+
return this._metadata;
|
|
25
|
+
}
|
|
26
|
+
get target() {
|
|
27
|
+
return this._target;
|
|
28
|
+
}
|
|
29
|
+
get currentTarget() {
|
|
30
|
+
return this._currentTarget;
|
|
31
|
+
}
|
|
32
|
+
get isCustomEvent() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
payloadToJson() {
|
|
36
|
+
return this.payload;
|
|
37
|
+
}
|
|
38
|
+
toJson() {
|
|
39
|
+
return {
|
|
40
|
+
payload: this.payloadToJson(),
|
|
41
|
+
type: this.type,
|
|
42
|
+
isCustomEvent: this.isCustomEvent
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
toString() {
|
|
46
|
+
return JSON.stringify(this.toJson());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class Change extends ActionImpl {
|
|
50
|
+
constructor(payload, dispatch = false) {
|
|
51
|
+
super(payload, 'change', { dispatch });
|
|
52
|
+
}
|
|
53
|
+
withAdditionalChange(change) {
|
|
54
|
+
return new Change(this.payload.changes.concat(change.payload.changes), this.metadata);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class UIChange extends ActionImpl {
|
|
58
|
+
constructor(payload, dispatch = false) {
|
|
59
|
+
super(payload, 'uiChange', { dispatch });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class Invalid extends ActionImpl {
|
|
63
|
+
constructor(payload = {}) {
|
|
64
|
+
super(payload, 'invalid', {});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class Valid extends ActionImpl {
|
|
68
|
+
constructor(payload = {}) {
|
|
69
|
+
super(payload, 'valid', {});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class ExecuteRule extends ActionImpl {
|
|
73
|
+
constructor(payload = {}, dispatch = false) {
|
|
74
|
+
super(payload, 'executeRule', { dispatch });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const propertyChange = (propertyName, currentValue, prevValue) => {
|
|
78
|
+
return new Change({
|
|
79
|
+
changes: [
|
|
80
|
+
{
|
|
81
|
+
propertyName,
|
|
82
|
+
currentValue,
|
|
83
|
+
prevValue
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
class Initialize extends ActionImpl {
|
|
89
|
+
constructor(payload, dispatch = false) {
|
|
90
|
+
super(payload, 'initialize', { dispatch });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
class FormLoad extends ActionImpl {
|
|
94
|
+
constructor() {
|
|
95
|
+
super({}, 'load', { dispatch: false });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class Click extends ActionImpl {
|
|
99
|
+
constructor(payload, dispatch = false) {
|
|
100
|
+
super(payload, 'click', { dispatch });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class Blur extends ActionImpl {
|
|
104
|
+
constructor(payload, dispatch = false) {
|
|
105
|
+
super(payload, 'blur', { dispatch });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class ValidationComplete extends ActionImpl {
|
|
109
|
+
constructor(payload, dispatch = false) {
|
|
110
|
+
super(payload, 'validationComplete', { dispatch });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class Focus extends ActionImpl {
|
|
114
|
+
constructor() {
|
|
115
|
+
super({}, 'focus', { dispatch: false });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
class Submit extends ActionImpl {
|
|
119
|
+
constructor(payload, dispatch = false) {
|
|
120
|
+
super(payload, 'submit', { dispatch });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
class Save extends ActionImpl {
|
|
124
|
+
constructor(payload, dispatch = false) {
|
|
125
|
+
super(payload, 'save', { dispatch });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class SubmitSuccess extends ActionImpl {
|
|
129
|
+
constructor(payload, dispatch = false) {
|
|
130
|
+
super(payload, 'submitSuccess', { dispatch });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
class SubmitFailure extends ActionImpl {
|
|
134
|
+
constructor(payload, dispatch = false) {
|
|
135
|
+
super(payload, 'submitFailure', { dispatch });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
class SubmitError extends ActionImpl {
|
|
139
|
+
constructor(payload, dispatch = false) {
|
|
140
|
+
super(payload, 'submitError', { dispatch });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
class Reset extends ActionImpl {
|
|
144
|
+
constructor(payload, dispatch = false) {
|
|
145
|
+
super(payload, 'reset', { dispatch });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class FieldChanged extends ActionImpl {
|
|
149
|
+
constructor(changes, field, eventSource = EventSource.CODE) {
|
|
150
|
+
super({
|
|
151
|
+
field,
|
|
152
|
+
changes,
|
|
153
|
+
eventSource
|
|
154
|
+
}, 'fieldChanged');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
class CustomEvent extends ActionImpl {
|
|
158
|
+
constructor(eventName, payload = {}, dispatch = false) {
|
|
159
|
+
super(payload, eventName, { dispatch });
|
|
160
|
+
}
|
|
161
|
+
get isCustomEvent() {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
class AddItem extends ActionImpl {
|
|
166
|
+
constructor(payload) {
|
|
167
|
+
super(payload, 'addItem');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
class RemoveItem extends ActionImpl {
|
|
171
|
+
constructor(payload) {
|
|
172
|
+
super(payload, 'removeItem');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
class AddInstance extends ActionImpl {
|
|
176
|
+
constructor(payload) {
|
|
177
|
+
super(payload, 'addInstance');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
class RemoveInstance extends ActionImpl {
|
|
181
|
+
constructor(payload) {
|
|
182
|
+
super(payload, 'removeInstance');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Save, Submit, SubmitError, SubmitFailure, SubmitSuccess, UIChange, Valid, ValidationComplete, propertyChange };
|
package/esm/afb-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitError, SubmitFailure, Submit, Save, Valid, Invalid, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete } from './afb-events.js';
|
|
2
2
|
import Formula from '@adobe/json-formula';
|
|
3
3
|
import { parseDefaultDate, datetimeToNumber, format, parseDateSkeleton, numberToDatetime, formatDate, parseDate } from '@aemforms/af-formatters';
|
|
4
4
|
|
|
@@ -9,6 +9,95 @@ function __decorate(decorators, target, key, desc) {
|
|
|
9
9
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const ConstraintType = Object.freeze({
|
|
13
|
+
PATTERN_MISMATCH: 'patternMismatch',
|
|
14
|
+
TOO_SHORT: 'tooShort',
|
|
15
|
+
TOO_LONG: 'tooLong',
|
|
16
|
+
RANGE_OVERFLOW: 'rangeOverflow',
|
|
17
|
+
RANGE_UNDERFLOW: 'rangeUnderflow',
|
|
18
|
+
TYPE_MISMATCH: 'typeMismatch',
|
|
19
|
+
VALUE_MISSING: 'valueMissing',
|
|
20
|
+
STEP_MISMATCH: 'stepMismatch',
|
|
21
|
+
FORMAT_MISMATCH: 'formatMismatch',
|
|
22
|
+
ACCEPT_MISMATCH: 'acceptMismatch',
|
|
23
|
+
FILE_SIZE_MISMATCH: 'fileSizeMismatch',
|
|
24
|
+
UNIQUE_ITEMS_MISMATCH: 'uniqueItemsMismatch',
|
|
25
|
+
MIN_ITEMS_MISMATCH: 'minItemsMismatch',
|
|
26
|
+
MAX_ITEMS_MISMATCH: 'maxItemsMismatch',
|
|
27
|
+
EXPRESSION_MISMATCH: 'expressionMismatch',
|
|
28
|
+
EXCLUSIVE_MAXIMUM_MISMATCH: 'exclusiveMaximumMismatch',
|
|
29
|
+
EXCLUSIVE_MINIMUM_MISMATCH: 'exclusiveMinimumMismatch'
|
|
30
|
+
});
|
|
31
|
+
const constraintKeys = Object.freeze({
|
|
32
|
+
pattern: ConstraintType.PATTERN_MISMATCH,
|
|
33
|
+
minLength: ConstraintType.TOO_SHORT,
|
|
34
|
+
maxLength: ConstraintType.TOO_LONG,
|
|
35
|
+
maximum: ConstraintType.RANGE_OVERFLOW,
|
|
36
|
+
minimum: ConstraintType.RANGE_UNDERFLOW,
|
|
37
|
+
type: ConstraintType.TYPE_MISMATCH,
|
|
38
|
+
required: ConstraintType.VALUE_MISSING,
|
|
39
|
+
step: ConstraintType.STEP_MISMATCH,
|
|
40
|
+
format: ConstraintType.FORMAT_MISMATCH,
|
|
41
|
+
accept: ConstraintType.ACCEPT_MISMATCH,
|
|
42
|
+
maxFileSize: ConstraintType.FILE_SIZE_MISMATCH,
|
|
43
|
+
uniqueItems: ConstraintType.UNIQUE_ITEMS_MISMATCH,
|
|
44
|
+
minItems: ConstraintType.MIN_ITEMS_MISMATCH,
|
|
45
|
+
maxItems: ConstraintType.MAX_ITEMS_MISMATCH,
|
|
46
|
+
validationExpression: ConstraintType.EXPRESSION_MISMATCH,
|
|
47
|
+
exclusiveMinimum: ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH,
|
|
48
|
+
exclusiveMaximum: ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH
|
|
49
|
+
});
|
|
50
|
+
const defaultConstraintTypeMessages = Object.freeze({
|
|
51
|
+
[ConstraintType.PATTERN_MISMATCH]: 'Please match the format requested.',
|
|
52
|
+
[ConstraintType.TOO_SHORT]: 'Please lengthen this text to ${0} characters or more.',
|
|
53
|
+
[ConstraintType.TOO_LONG]: 'Please shorten this text to ${0} characters or less.',
|
|
54
|
+
[ConstraintType.RANGE_OVERFLOW]: 'Value must be less than or equal to ${0}.',
|
|
55
|
+
[ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
|
|
56
|
+
[ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
|
|
57
|
+
[ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
|
|
58
|
+
[ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
|
|
59
|
+
[ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
|
|
60
|
+
[ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
|
|
61
|
+
[ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
|
|
62
|
+
[ConstraintType.UNIQUE_ITEMS_MISMATCH]: 'All the items must be unique.',
|
|
63
|
+
[ConstraintType.MIN_ITEMS_MISMATCH]: 'Specify a number of items equal to or greater than ${0}.',
|
|
64
|
+
[ConstraintType.MAX_ITEMS_MISMATCH]: 'Specify a number of items equal to or less than ${0}.',
|
|
65
|
+
[ConstraintType.EXPRESSION_MISMATCH]: 'Please enter a valid value.',
|
|
66
|
+
[ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH]: 'Value must be greater than ${0}.',
|
|
67
|
+
[ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH]: 'Value must be less than ${0}.'
|
|
68
|
+
});
|
|
69
|
+
let customConstraintTypeMessages = {};
|
|
70
|
+
const getConstraintTypeMessages = () => {
|
|
71
|
+
return {
|
|
72
|
+
...defaultConstraintTypeMessages,
|
|
73
|
+
...customConstraintTypeMessages
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var EventSource;
|
|
78
|
+
(function (EventSource) {
|
|
79
|
+
EventSource["CODE"] = "code";
|
|
80
|
+
EventSource["UI"] = "ui";
|
|
81
|
+
})(EventSource || (EventSource = {}));
|
|
82
|
+
class ValidationError {
|
|
83
|
+
fieldName;
|
|
84
|
+
errorMessages;
|
|
85
|
+
constructor(fieldName = '', errorMessages = []) {
|
|
86
|
+
this.errorMessages = errorMessages;
|
|
87
|
+
this.fieldName = fieldName;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var FocusOption;
|
|
91
|
+
(function (FocusOption) {
|
|
92
|
+
FocusOption["NEXT_ITEM"] = "nextItem";
|
|
93
|
+
FocusOption["PREVIOUS_ITEM"] = "previousItem";
|
|
94
|
+
})(FocusOption || (FocusOption = {}));
|
|
95
|
+
var CaptchaDisplayMode;
|
|
96
|
+
(function (CaptchaDisplayMode) {
|
|
97
|
+
CaptchaDisplayMode["INVISIBLE"] = "invisible";
|
|
98
|
+
CaptchaDisplayMode["VISIBLE"] = "visible";
|
|
99
|
+
})(CaptchaDisplayMode || (CaptchaDisplayMode = {}));
|
|
100
|
+
|
|
12
101
|
const objToMap = (o) => new Map(Object.entries(o));
|
|
13
102
|
const stringViewTypes = objToMap({ 'date': 'date-input', 'data-url': 'file-input', 'binary': 'file-input' });
|
|
14
103
|
const typeToViewTypes = objToMap({
|
|
@@ -1157,6 +1246,7 @@ class BaseNode {
|
|
|
1157
1246
|
_jsonModel;
|
|
1158
1247
|
_tokens = [];
|
|
1159
1248
|
_eventSource = EventSource.CODE;
|
|
1249
|
+
_fragment = '$form';
|
|
1160
1250
|
get isContainer() {
|
|
1161
1251
|
return false;
|
|
1162
1252
|
}
|
|
@@ -1167,6 +1257,15 @@ class BaseNode {
|
|
|
1167
1257
|
...params,
|
|
1168
1258
|
id: 'id' in params ? params.id : this.form.getUniqueId()
|
|
1169
1259
|
};
|
|
1260
|
+
if (this.parent?.isFragment) {
|
|
1261
|
+
this._fragment = this.parent.qualifiedName;
|
|
1262
|
+
}
|
|
1263
|
+
else if (this.parent?.fragment) {
|
|
1264
|
+
this._fragment = this.parent.fragment;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
get fragment() {
|
|
1268
|
+
return this._fragment;
|
|
1170
1269
|
}
|
|
1171
1270
|
setupRuleNode() {
|
|
1172
1271
|
const self = this;
|
|
@@ -1588,7 +1687,11 @@ class Scriptable extends BaseNode {
|
|
|
1588
1687
|
const eString = rule || this.getRules()[eName];
|
|
1589
1688
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
1590
1689
|
try {
|
|
1591
|
-
|
|
1690
|
+
let updatedRule = eString;
|
|
1691
|
+
if (this.fragment !== '$form') {
|
|
1692
|
+
updatedRule = eString.replaceAll('$form', this.fragment);
|
|
1693
|
+
}
|
|
1694
|
+
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
1592
1695
|
}
|
|
1593
1696
|
catch (e) {
|
|
1594
1697
|
this.form.logger.error(`Unable to compile rule \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -1609,7 +1712,11 @@ class Scriptable extends BaseNode {
|
|
|
1609
1712
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
1610
1713
|
this._events[eName] = eString.map(x => {
|
|
1611
1714
|
try {
|
|
1612
|
-
|
|
1715
|
+
let updatedExpr = x;
|
|
1716
|
+
if (this.fragment !== '$form') {
|
|
1717
|
+
updatedExpr = x.replaceAll('$form', this.fragment);
|
|
1718
|
+
}
|
|
1719
|
+
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
1613
1720
|
}
|
|
1614
1721
|
catch (e) {
|
|
1615
1722
|
this.form.logger.error(`Unable to compile expression \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -1646,7 +1753,7 @@ class Scriptable extends BaseNode {
|
|
|
1646
1753
|
entries.forEach(([prop, rule]) => {
|
|
1647
1754
|
const node = this.getCompiledRule(prop, rule);
|
|
1648
1755
|
if (node) {
|
|
1649
|
-
const newVal = this.ruleEngine.execute(node, scope, context, true);
|
|
1756
|
+
const newVal = this.ruleEngine.execute(node, scope, context, true, rule);
|
|
1650
1757
|
if (editableProperties.indexOf(prop) > -1) {
|
|
1651
1758
|
const oldAndNewValueAreEmpty = this.isEmpty() && this.isEmpty(newVal) && prop === 'value';
|
|
1652
1759
|
if (!oldAndNewValueAreEmpty) {
|
|
@@ -1701,10 +1808,10 @@ class Scriptable extends BaseNode {
|
|
|
1701
1808
|
});
|
|
1702
1809
|
return scope;
|
|
1703
1810
|
}
|
|
1704
|
-
executeEvent(context, node) {
|
|
1811
|
+
executeEvent(context, node, eString) {
|
|
1705
1812
|
let updates;
|
|
1706
1813
|
if (node) {
|
|
1707
|
-
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
|
|
1814
|
+
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context, false, eString);
|
|
1708
1815
|
}
|
|
1709
1816
|
if (typeof updates !== 'undefined' && updates != null) {
|
|
1710
1817
|
this.applyUpdates(updates);
|
|
@@ -1723,7 +1830,7 @@ class Scriptable extends BaseNode {
|
|
|
1723
1830
|
'field': this
|
|
1724
1831
|
};
|
|
1725
1832
|
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
1726
|
-
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
1833
|
+
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext, false, expr);
|
|
1727
1834
|
}
|
|
1728
1835
|
change(event, context) {
|
|
1729
1836
|
if (this.form.changeEventBehaviour === 'deps') {
|
|
@@ -1745,10 +1852,20 @@ class Scriptable extends BaseNode {
|
|
|
1745
1852
|
const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
|
|
1746
1853
|
const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
|
|
1747
1854
|
const node = this.getCompiledEvent(eventName);
|
|
1855
|
+
const events = this._jsonModel.events?.[eventName];
|
|
1748
1856
|
if (funcName in this && typeof this[funcName] === 'function') {
|
|
1749
1857
|
this[funcName](action, context);
|
|
1750
1858
|
}
|
|
1751
|
-
node.forEach((n) =>
|
|
1859
|
+
node.forEach((n, index) => {
|
|
1860
|
+
let eString = '';
|
|
1861
|
+
if (Array.isArray(events)) {
|
|
1862
|
+
eString = events[index];
|
|
1863
|
+
}
|
|
1864
|
+
else if (typeof events === 'string') {
|
|
1865
|
+
eString = events;
|
|
1866
|
+
}
|
|
1867
|
+
this.executeEvent(context, n, eString);
|
|
1868
|
+
});
|
|
1752
1869
|
if (action.target === this) {
|
|
1753
1870
|
this.notifyDependents(action);
|
|
1754
1871
|
}
|
|
@@ -1763,8 +1880,11 @@ class Container extends Scriptable {
|
|
|
1763
1880
|
_childrenReference;
|
|
1764
1881
|
_itemTemplate = null;
|
|
1765
1882
|
fieldFactory;
|
|
1883
|
+
_isFragment = false;
|
|
1884
|
+
_insideFragment = false;
|
|
1766
1885
|
constructor(json, _options) {
|
|
1767
1886
|
super(json, { form: _options.form, parent: _options.parent, mode: _options.mode });
|
|
1887
|
+
this._isFragment = this._jsonModel?.properties?.['fd:fragment'] === true;
|
|
1768
1888
|
this.fieldFactory = _options.fieldFactory;
|
|
1769
1889
|
}
|
|
1770
1890
|
_getDefaults() {
|
|
@@ -1969,6 +2089,9 @@ class Container extends Scriptable {
|
|
|
1969
2089
|
return this._jsonModel.type == 'array' && this.getDataNode() != null &&
|
|
1970
2090
|
(items.length === 1 || (items.length > 0 && items[0].repeatable == true && mode === 'restore'));
|
|
1971
2091
|
}
|
|
2092
|
+
get isFragment() {
|
|
2093
|
+
return this._isFragment || this._jsonModel?.properties?.['fd:fragment'];
|
|
2094
|
+
}
|
|
1972
2095
|
_initialize(mode) {
|
|
1973
2096
|
super._initialize(mode);
|
|
1974
2097
|
const items = this._jsonModel.items || [];
|
|
@@ -2043,19 +2166,7 @@ class Container extends Scriptable {
|
|
|
2043
2166
|
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
2044
2167
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
2045
2168
|
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
|
-
}
|
|
2169
|
+
let instanceIndex = action.payload;
|
|
2059
2170
|
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
2060
2171
|
if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
|
|
2061
2172
|
instanceIndex = this._children.length;
|
|
@@ -2071,9 +2182,6 @@ class Container extends Scriptable {
|
|
|
2071
2182
|
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
2072
2183
|
this._children[i].dispatch(new ExecuteRule());
|
|
2073
2184
|
}
|
|
2074
|
-
if (instanceData) {
|
|
2075
|
-
retVal.importData(instanceData);
|
|
2076
|
-
}
|
|
2077
2185
|
}
|
|
2078
2186
|
}
|
|
2079
2187
|
}
|
|
@@ -2127,21 +2235,14 @@ class Container extends Scriptable {
|
|
|
2127
2235
|
dispatch(action) {
|
|
2128
2236
|
super.dispatch(action);
|
|
2129
2237
|
}
|
|
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
2238
|
importData(dataModel) {
|
|
2142
2239
|
if (typeof this._data !== 'undefined' && this.type === 'array' && Array.isArray(dataModel)) {
|
|
2143
|
-
const dataGroup = this.
|
|
2144
|
-
|
|
2240
|
+
const dataGroup = new DataGroup(this._data.$name, dataModel, this._data.$type, this._data.parent);
|
|
2241
|
+
try {
|
|
2242
|
+
this._data.parent?.$addDataNode(dataGroup.$name, dataGroup, true);
|
|
2243
|
+
}
|
|
2244
|
+
catch (e) {
|
|
2245
|
+
this.form.logger.error(`unable to setItems for ${this.qualifiedName} : ${e}`);
|
|
2145
2246
|
return;
|
|
2146
2247
|
}
|
|
2147
2248
|
this._data = dataGroup;
|
|
@@ -2158,13 +2259,6 @@ class Container extends Scriptable {
|
|
|
2158
2259
|
this.notifyDependents(propertyChange('items', null, item.getState()));
|
|
2159
2260
|
});
|
|
2160
2261
|
}
|
|
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
2262
|
}
|
|
2169
2263
|
syncDataAndFormModel(contextualDataModel) {
|
|
2170
2264
|
const result = {
|
|
@@ -2610,26 +2704,32 @@ const multipartFormData = (data, attachments) => {
|
|
|
2610
2704
|
}
|
|
2611
2705
|
return formData;
|
|
2612
2706
|
};
|
|
2613
|
-
const createAction = (name, payload = {}) => {
|
|
2707
|
+
const createAction = (name, payload = {}, dispatch = false) => {
|
|
2614
2708
|
switch (name) {
|
|
2615
2709
|
case 'change':
|
|
2616
|
-
return new Change(payload);
|
|
2710
|
+
return new Change(payload, dispatch);
|
|
2617
2711
|
case 'submit':
|
|
2618
|
-
return new Submit(payload);
|
|
2712
|
+
return new Submit(payload, dispatch);
|
|
2619
2713
|
case 'save':
|
|
2620
|
-
return new Save(payload);
|
|
2714
|
+
return new Save(payload, dispatch);
|
|
2621
2715
|
case 'click':
|
|
2622
|
-
return new Click(payload);
|
|
2716
|
+
return new Click(payload, dispatch);
|
|
2623
2717
|
case 'addItem':
|
|
2624
2718
|
return new AddItem(payload);
|
|
2625
2719
|
case 'removeItem':
|
|
2626
2720
|
return new RemoveItem(payload);
|
|
2627
2721
|
case 'reset':
|
|
2628
|
-
return new Reset(payload);
|
|
2722
|
+
return new Reset(payload, dispatch);
|
|
2629
2723
|
case 'addInstance':
|
|
2630
2724
|
return new AddInstance(payload);
|
|
2631
2725
|
case 'removeInstance':
|
|
2632
2726
|
return new RemoveInstance(payload);
|
|
2727
|
+
case 'invalid':
|
|
2728
|
+
return new Invalid(payload);
|
|
2729
|
+
case 'valid':
|
|
2730
|
+
return new Valid(payload);
|
|
2731
|
+
case 'initialize':
|
|
2732
|
+
return new Initialize(payload, dispatch);
|
|
2633
2733
|
default:
|
|
2634
2734
|
console.error('invalid action');
|
|
2635
2735
|
}
|
|
@@ -2703,8 +2803,8 @@ class FunctionRuntimeImpl {
|
|
|
2703
2803
|
const args = [target, flag];
|
|
2704
2804
|
return FunctionRuntimeImpl.getInstance().getFunctions().setFocus._func.call(undefined, args, data, interpreter);
|
|
2705
2805
|
},
|
|
2706
|
-
dispatchEvent: (target, eventName, payload) => {
|
|
2707
|
-
const args = [target, eventName, payload];
|
|
2806
|
+
dispatchEvent: (target, eventName, payload, dispatch) => {
|
|
2807
|
+
const args = [target, eventName, payload, dispatch];
|
|
2708
2808
|
return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
|
|
2709
2809
|
},
|
|
2710
2810
|
getFiles: (qualifiedName) => {
|
|
@@ -2963,9 +3063,13 @@ class FunctionRuntimeImpl {
|
|
|
2963
3063
|
dispatchEvent: {
|
|
2964
3064
|
_func: (args, data, interpreter) => {
|
|
2965
3065
|
const element = args[0];
|
|
3066
|
+
if (element === null && typeof interpreter !== 'string') {
|
|
3067
|
+
interpreter.debug.push('Invalid argument passed in dispatchEvent. An element is expected');
|
|
3068
|
+
return {};
|
|
3069
|
+
}
|
|
2966
3070
|
let eventName = valueOf(args[1]);
|
|
2967
3071
|
let payload = args.length > 2 ? valueOf(args[2]) : undefined;
|
|
2968
|
-
let dispatch = false;
|
|
3072
|
+
let dispatch = args.length > 3 ? valueOf(args[3]) : false;
|
|
2969
3073
|
if (typeof element === 'string') {
|
|
2970
3074
|
payload = eventName;
|
|
2971
3075
|
eventName = element;
|
|
@@ -2976,7 +3080,7 @@ class FunctionRuntimeImpl {
|
|
|
2976
3080
|
event = new CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
|
|
2977
3081
|
}
|
|
2978
3082
|
else {
|
|
2979
|
-
event = createAction(eventName, payload);
|
|
3083
|
+
event = createAction(eventName, payload, dispatch);
|
|
2980
3084
|
}
|
|
2981
3085
|
if (event != null) {
|
|
2982
3086
|
if (typeof element === 'string') {
|
|
@@ -3105,6 +3209,9 @@ class Form extends Container {
|
|
|
3105
3209
|
get action() {
|
|
3106
3210
|
return this._jsonModel.action;
|
|
3107
3211
|
}
|
|
3212
|
+
get isFragment() {
|
|
3213
|
+
return false;
|
|
3214
|
+
}
|
|
3108
3215
|
importData(dataModel) {
|
|
3109
3216
|
this.bindToDataModel(new DataGroup('$form', dataModel));
|
|
3110
3217
|
this.syncDataAndFormModel(this.getDataNode());
|
|
@@ -3432,7 +3539,7 @@ class RuleEngine {
|
|
|
3432
3539
|
const formula = new Formula(this.customFunctions, getStringToNumberFn(locale), this.debugInfo);
|
|
3433
3540
|
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
3434
3541
|
}
|
|
3435
|
-
execute(node, data, globals, useValueOf = false) {
|
|
3542
|
+
execute(node, data, globals, useValueOf = false, eString) {
|
|
3436
3543
|
const { formula, ast } = node;
|
|
3437
3544
|
const oldContext = this._context;
|
|
3438
3545
|
this._context = globals;
|
|
@@ -3443,8 +3550,11 @@ class RuleEngine {
|
|
|
3443
3550
|
catch (err) {
|
|
3444
3551
|
this._context?.form?.logger?.error(err);
|
|
3445
3552
|
}
|
|
3446
|
-
|
|
3447
|
-
this._context?.form?.logger?.
|
|
3553
|
+
if (this.debugInfo.length) {
|
|
3554
|
+
this._context?.form?.logger?.warn(`Form rule expression string: ${eString}`);
|
|
3555
|
+
while (this.debugInfo.length > 0) {
|
|
3556
|
+
this._context?.form?.logger?.warn(this.debugInfo.pop());
|
|
3557
|
+
}
|
|
3448
3558
|
}
|
|
3449
3559
|
let finalRes = res;
|
|
3450
3560
|
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;
|
|
@@ -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 type UIChangePayload = {
|
|
|
32
36
|
value?: any;
|
|
33
37
|
checked?: boolean;
|
|
34
38
|
};
|
|
35
|
-
export 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);
|
|
@@ -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;
|