@aemforms/af-core 0.22.136 → 0.22.138
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 +255 -73
- package/esm/types/src/BaseNode.d.ts +12 -3
- package/esm/types/src/Checkbox.d.ts +6 -1
- package/esm/types/src/Container.d.ts +117 -3
- package/esm/types/src/Field.d.ts +6 -1
- package/esm/types/src/Form.d.ts +117 -3
- package/esm/types/src/controller/Logger.d.ts +1 -0
- package/esm/types/src/rules/FunctionRuntime.d.ts +13 -1
- package/esm/types/src/rules/RuleEngine.d.ts +1 -1
- package/esm/types/src/types/Model.d.ts +1 -1
- package/lib/BaseNode.d.ts +12 -3
- package/lib/BaseNode.js +33 -24
- package/lib/Checkbox.d.ts +6 -1
- package/lib/Container.d.ts +117 -3
- package/lib/Container.js +18 -18
- package/lib/Field.d.ts +6 -1
- package/lib/Field.js +1 -1
- package/lib/Form.d.ts +117 -3
- package/lib/PropertiesManager.d.ts +14 -0
- package/lib/PropertiesManager.js +102 -0
- package/lib/controller/EventQueue.js +13 -1
- package/lib/controller/Logger.d.ts +1 -0
- package/lib/controller/Logger.js +3 -0
- package/lib/rules/FunctionRuntime.d.ts +13 -1
- package/lib/rules/FunctionRuntime.js +73 -12
- package/lib/rules/RuleEngine.d.ts +1 -1
- package/lib/rules/RuleEngine.js +2 -2
- package/lib/types/Model.d.ts +1 -1
- package/package.json +2 -2
package/esm/afb-runtime.js
CHANGED
|
@@ -205,6 +205,103 @@ const isRepeatable$1 = (obj) => {
|
|
|
205
205
|
(obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
class PropertiesManager {
|
|
209
|
+
constructor(host) {
|
|
210
|
+
this.host = host;
|
|
211
|
+
this._definedProperties = new Set();
|
|
212
|
+
this._propertiesWrapper = {};
|
|
213
|
+
this._initialized = false;
|
|
214
|
+
}
|
|
215
|
+
get properties() {
|
|
216
|
+
if (!this._initialized) {
|
|
217
|
+
this._setupInitialProperties();
|
|
218
|
+
this._initialized = true;
|
|
219
|
+
}
|
|
220
|
+
return this._propertiesWrapper;
|
|
221
|
+
}
|
|
222
|
+
set properties(p) {
|
|
223
|
+
const oldProperties = this.host._jsonModel.properties || {};
|
|
224
|
+
const newProperties = { ...p };
|
|
225
|
+
this.host._jsonModel.properties = newProperties;
|
|
226
|
+
Object.keys(newProperties).forEach(prop => {
|
|
227
|
+
this._ensurePropertyDescriptor(prop);
|
|
228
|
+
});
|
|
229
|
+
Object.keys({ ...oldProperties, ...newProperties }).forEach(prop => {
|
|
230
|
+
if (oldProperties[prop] !== newProperties[prop]) {
|
|
231
|
+
const changeAction = propertyChange(`properties.${prop}`, newProperties[prop], oldProperties[prop]);
|
|
232
|
+
this.host.notifyDependents(changeAction);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
ensurePropertyDescriptor(propertyName) {
|
|
237
|
+
this._ensurePropertyDescriptor(propertyName);
|
|
238
|
+
}
|
|
239
|
+
_setupInitialProperties() {
|
|
240
|
+
const properties = this.host._jsonModel.properties || {};
|
|
241
|
+
Object.keys(properties).forEach(prop => {
|
|
242
|
+
this._ensurePropertyDescriptor(prop);
|
|
243
|
+
});
|
|
244
|
+
if (!this.host._jsonModel.properties) {
|
|
245
|
+
this.host._jsonModel.properties = {};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
_ensurePropertyDescriptor(prop) {
|
|
249
|
+
if (this._definedProperties.has(prop)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
Object.defineProperty(this._propertiesWrapper, prop, {
|
|
253
|
+
get: () => {
|
|
254
|
+
if (!prop.startsWith('fd:')) {
|
|
255
|
+
this.host.ruleEngine.trackDependency(this.host, `properties.${prop}`);
|
|
256
|
+
}
|
|
257
|
+
const properties = this.host._jsonModel.properties || {};
|
|
258
|
+
return properties[prop];
|
|
259
|
+
},
|
|
260
|
+
set: (value) => {
|
|
261
|
+
const properties = this.host._jsonModel.properties || {};
|
|
262
|
+
const oldValue = properties[prop];
|
|
263
|
+
if (oldValue !== value) {
|
|
264
|
+
const updatedProperties = { ...properties, [prop]: value };
|
|
265
|
+
this.host._jsonModel.properties = updatedProperties;
|
|
266
|
+
const changeAction = propertyChange(`properties.${prop}`, value, oldValue);
|
|
267
|
+
this.host.notifyDependents(changeAction);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
enumerable: true,
|
|
271
|
+
configurable: true
|
|
272
|
+
});
|
|
273
|
+
this._definedProperties.add(prop);
|
|
274
|
+
}
|
|
275
|
+
updateNestedProperty(propertyPath, value) {
|
|
276
|
+
const parts = propertyPath.split('.');
|
|
277
|
+
const topLevelProp = parts[0];
|
|
278
|
+
this._ensurePropertyDescriptor(topLevelProp);
|
|
279
|
+
const properties = this.host._jsonModel.properties || {};
|
|
280
|
+
const updatedProperties = JSON.parse(JSON.stringify(properties));
|
|
281
|
+
const currentObj = updatedProperties[topLevelProp] || {};
|
|
282
|
+
updatedProperties[topLevelProp] = currentObj;
|
|
283
|
+
let parentObj = currentObj;
|
|
284
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
285
|
+
if (!parentObj[parts[i]]) {
|
|
286
|
+
parentObj[parts[i]] = {};
|
|
287
|
+
} else if (typeof parentObj[parts[i]] !== 'object') {
|
|
288
|
+
parentObj[parts[i]] = {};
|
|
289
|
+
}
|
|
290
|
+
parentObj = parentObj[parts[i]];
|
|
291
|
+
}
|
|
292
|
+
const finalProp = parts[parts.length - 1];
|
|
293
|
+
const oldValue = parentObj[finalProp];
|
|
294
|
+
parentObj[finalProp] = value;
|
|
295
|
+
this.host._jsonModel.properties = updatedProperties;
|
|
296
|
+
const changeAction = propertyChange(`properties.${propertyPath}`, value, oldValue);
|
|
297
|
+
this.host.notifyDependents(changeAction);
|
|
298
|
+
}
|
|
299
|
+
updateSimpleProperty(propertyName, value) {
|
|
300
|
+
this._ensurePropertyDescriptor(propertyName);
|
|
301
|
+
this._propertiesWrapper[propertyName] = value;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
208
305
|
class DataValue {
|
|
209
306
|
$_name;
|
|
210
307
|
$_value;
|
|
@@ -1277,7 +1374,7 @@ function dependencyTracked() {
|
|
|
1277
1374
|
const get = descriptor.get;
|
|
1278
1375
|
if (get != undefined) {
|
|
1279
1376
|
descriptor.get = function () {
|
|
1280
|
-
this.ruleEngine.trackDependency(this);
|
|
1377
|
+
this.ruleEngine.trackDependency(this, propertyKey);
|
|
1281
1378
|
return get.call(this);
|
|
1282
1379
|
};
|
|
1283
1380
|
}
|
|
@@ -1315,6 +1412,7 @@ class BaseNode {
|
|
|
1315
1412
|
_eventSource = EventSource.CODE;
|
|
1316
1413
|
_fragment = '$form';
|
|
1317
1414
|
_idSet;
|
|
1415
|
+
_propertiesManager;
|
|
1318
1416
|
createIdSet() {
|
|
1319
1417
|
return new Set();
|
|
1320
1418
|
}
|
|
@@ -1335,6 +1433,7 @@ class BaseNode {
|
|
|
1335
1433
|
else if (this.parent?.fragment) {
|
|
1336
1434
|
this._fragment = this.parent.fragment;
|
|
1337
1435
|
}
|
|
1436
|
+
this._propertiesManager = new PropertiesManager(this);
|
|
1338
1437
|
}
|
|
1339
1438
|
get fragment() {
|
|
1340
1439
|
return this._fragment;
|
|
@@ -1450,7 +1549,11 @@ class BaseNode {
|
|
|
1450
1549
|
return this._jsonModel.label;
|
|
1451
1550
|
}
|
|
1452
1551
|
set label(l) {
|
|
1453
|
-
|
|
1552
|
+
const isLabelSame = (l !== null && this._jsonModel.label !== null &&
|
|
1553
|
+
typeof l === 'object' && typeof this._jsonModel.label === 'object') ?
|
|
1554
|
+
JSON.stringify(l) === JSON.stringify(this._jsonModel.label) :
|
|
1555
|
+
l === this._jsonModel.label;
|
|
1556
|
+
if (!isLabelSame) {
|
|
1454
1557
|
const changeAction = propertyChange('label', l, this._jsonModel.label);
|
|
1455
1558
|
this._jsonModel = {
|
|
1456
1559
|
...this._jsonModel,
|
|
@@ -1467,29 +1570,31 @@ class BaseNode {
|
|
|
1467
1570
|
return !this._jsonModel.name && !isNonTransparent;
|
|
1468
1571
|
}
|
|
1469
1572
|
getDependents() {
|
|
1470
|
-
return this._dependents.map(x => x.node.id);
|
|
1573
|
+
return this._dependents.map(x => ({ id: x.node.id, propertyName: x.propertyName }));
|
|
1471
1574
|
}
|
|
1472
1575
|
getState(forRestore = false) {
|
|
1473
|
-
return {
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
repeatable
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1576
|
+
return this.withDependencyTrackingControl(true, () => {
|
|
1577
|
+
return {
|
|
1578
|
+
...this._jsonModel,
|
|
1579
|
+
properties: this.properties,
|
|
1580
|
+
index: this.index,
|
|
1581
|
+
parent: undefined,
|
|
1582
|
+
qualifiedName: this.qualifiedName,
|
|
1583
|
+
...(this.repeatable === true ? {
|
|
1584
|
+
repeatable: true,
|
|
1585
|
+
minOccur: this.parent.minItems,
|
|
1586
|
+
maxOccur: this.parent.maxItems
|
|
1587
|
+
} : {}),
|
|
1588
|
+
':type': this[':type'],
|
|
1589
|
+
...(forRestore ? {
|
|
1590
|
+
_dependents: this._dependents.length ? this.getDependents() : undefined,
|
|
1591
|
+
allowedComponents: undefined,
|
|
1592
|
+
columnClassNames: undefined,
|
|
1593
|
+
columnCount: undefined,
|
|
1594
|
+
gridClassNames: undefined
|
|
1595
|
+
} : {})
|
|
1596
|
+
};
|
|
1597
|
+
});
|
|
1493
1598
|
}
|
|
1494
1599
|
subscribe(callback, eventName = 'change') {
|
|
1495
1600
|
this._callbacks[eventName] = this._callbacks[eventName] || [];
|
|
@@ -1500,13 +1605,14 @@ class BaseNode {
|
|
|
1500
1605
|
}
|
|
1501
1606
|
};
|
|
1502
1607
|
}
|
|
1503
|
-
_addDependent(dependent) {
|
|
1608
|
+
_addDependent(dependent, propertyName) {
|
|
1504
1609
|
if (this._dependents.find(({ node }) => node === dependent) === undefined) {
|
|
1505
1610
|
const subscription = this.subscribe((change) => {
|
|
1506
1611
|
const changes = change.payload.changes;
|
|
1507
1612
|
const propsToLook = [...dynamicProps, 'items'];
|
|
1508
1613
|
const isPropChanged = changes.findIndex(x => {
|
|
1509
|
-
|
|
1614
|
+
const changedPropertyName = x.propertyName;
|
|
1615
|
+
return propsToLook.includes(changedPropertyName) || (changedPropertyName.startsWith('properties.') && propertyName === changedPropertyName);
|
|
1510
1616
|
}) > -1;
|
|
1511
1617
|
if (isPropChanged) {
|
|
1512
1618
|
if (this.form.changeEventBehaviour === 'deps') {
|
|
@@ -1517,7 +1623,7 @@ class BaseNode {
|
|
|
1517
1623
|
}
|
|
1518
1624
|
}
|
|
1519
1625
|
});
|
|
1520
|
-
this._dependents.push({ node: dependent, subscription });
|
|
1626
|
+
this._dependents.push({ node: dependent, propertyName, subscription });
|
|
1521
1627
|
}
|
|
1522
1628
|
}
|
|
1523
1629
|
removeDependent(dependent) {
|
|
@@ -1553,9 +1659,9 @@ class BaseNode {
|
|
|
1553
1659
|
const depsToRestore = this._jsonModel._dependents;
|
|
1554
1660
|
if (depsToRestore) {
|
|
1555
1661
|
depsToRestore.forEach((x) => {
|
|
1556
|
-
const node = this.form.getElement(x);
|
|
1662
|
+
const node = this.form.getElement(x.id);
|
|
1557
1663
|
if (node) {
|
|
1558
|
-
this._addDependent(node);
|
|
1664
|
+
this._addDependent(node, x.propertyName);
|
|
1559
1665
|
}
|
|
1560
1666
|
});
|
|
1561
1667
|
this._jsonModel._dependents = undefined;
|
|
@@ -1682,10 +1788,13 @@ class BaseNode {
|
|
|
1682
1788
|
return this._lang;
|
|
1683
1789
|
}
|
|
1684
1790
|
get properties() {
|
|
1685
|
-
return this.
|
|
1791
|
+
return this._propertiesManager.properties;
|
|
1686
1792
|
}
|
|
1687
1793
|
set properties(p) {
|
|
1688
|
-
this.
|
|
1794
|
+
this._propertiesManager.properties = p;
|
|
1795
|
+
}
|
|
1796
|
+
getPropertiesManager() {
|
|
1797
|
+
return this._propertiesManager;
|
|
1689
1798
|
}
|
|
1690
1799
|
getNonTransparentParent() {
|
|
1691
1800
|
let nonTransparentParent = this.parent;
|
|
@@ -1776,9 +1885,6 @@ __decorate([
|
|
|
1776
1885
|
__decorate([
|
|
1777
1886
|
dependencyTracked()
|
|
1778
1887
|
], BaseNode.prototype, "label", null);
|
|
1779
|
-
__decorate([
|
|
1780
|
-
dependencyTracked()
|
|
1781
|
-
], BaseNode.prototype, "properties", null);
|
|
1782
1888
|
|
|
1783
1889
|
class Scriptable extends BaseNode {
|
|
1784
1890
|
_events = {};
|
|
@@ -2075,31 +2181,32 @@ class Container extends Scriptable {
|
|
|
2075
2181
|
}) : [];
|
|
2076
2182
|
}
|
|
2077
2183
|
getItemsState(isRepeatableChild = false, forRestore = false) {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
return this._children.map(x => {
|
|
2084
|
-
return { ...x.getState(true, forRestore) };
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2184
|
+
const isThisContainerRepeatable = this._jsonModel.type === 'array' || isRepeatable$1(this._jsonModel);
|
|
2185
|
+
if (isThisContainerRepeatable) {
|
|
2186
|
+
return this._children.map(x => {
|
|
2187
|
+
return { ...x.getState(true, forRestore) };
|
|
2188
|
+
});
|
|
2087
2189
|
}
|
|
2088
2190
|
else {
|
|
2089
2191
|
return this._getFormAndSitesState(isRepeatableChild, forRestore);
|
|
2090
2192
|
}
|
|
2091
2193
|
}
|
|
2092
2194
|
getState(isRepeatableChild = false, forRestore = false) {
|
|
2093
|
-
return {
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2195
|
+
return this.withDependencyTrackingControl(true, () => {
|
|
2196
|
+
return {
|
|
2197
|
+
...super.getState(forRestore),
|
|
2198
|
+
...(forRestore ? {
|
|
2199
|
+
':items': undefined,
|
|
2200
|
+
':itemsOrder': undefined
|
|
2201
|
+
} : {}),
|
|
2202
|
+
items: this.getItemsState(isRepeatableChild, forRestore),
|
|
2203
|
+
...((this._jsonModel.type === 'array' || isRepeatable$1(this._jsonModel)) && this._itemTemplate ? {
|
|
2204
|
+
_itemTemplate: { ...this._itemTemplate }
|
|
2205
|
+
} : {}),
|
|
2206
|
+
enabled: this.enabled,
|
|
2207
|
+
readOnly: this.readOnly
|
|
2208
|
+
};
|
|
2209
|
+
});
|
|
2103
2210
|
}
|
|
2104
2211
|
_createChild(child, options) {
|
|
2105
2212
|
return this.fieldFactory.createField(child, options);
|
|
@@ -2137,10 +2244,10 @@ class Container extends Scriptable {
|
|
|
2137
2244
|
Object.defineProperty(parent._childrenReference, name, {
|
|
2138
2245
|
get: () => {
|
|
2139
2246
|
if (child.isContainer && child.hasDynamicItems()) {
|
|
2140
|
-
self.ruleEngine.trackDependency(child);
|
|
2247
|
+
self.ruleEngine.trackDependency(child, 'items');
|
|
2141
2248
|
}
|
|
2142
2249
|
if (self.hasDynamicItems()) {
|
|
2143
|
-
self.ruleEngine.trackDependency(self);
|
|
2250
|
+
self.ruleEngine.trackDependency(self, 'items');
|
|
2144
2251
|
if (this._children[name] !== undefined) {
|
|
2145
2252
|
return this._children[name].getRuleNode();
|
|
2146
2253
|
}
|
|
@@ -2205,7 +2312,8 @@ class Container extends Scriptable {
|
|
|
2205
2312
|
const items = this._jsonModel.items || [];
|
|
2206
2313
|
this._childrenReference = this._jsonModel.type == 'array' ? [] : {};
|
|
2207
2314
|
if (this._canHaveRepeatingChildren(mode)) {
|
|
2208
|
-
this._itemTemplate = deepClone(items[0]);
|
|
2315
|
+
this._itemTemplate = this._jsonModel._itemTemplate || deepClone(items[0]);
|
|
2316
|
+
this._jsonModel._itemTemplate = undefined;
|
|
2209
2317
|
if (mode === 'restore') {
|
|
2210
2318
|
this._itemTemplate.repeatable = undefined;
|
|
2211
2319
|
}
|
|
@@ -2390,9 +2498,8 @@ class Container extends Scriptable {
|
|
|
2390
2498
|
if (items2Remove > 0) {
|
|
2391
2499
|
for (let i = 0; i < items2Remove; i++) {
|
|
2392
2500
|
this._childrenReference.pop();
|
|
2393
|
-
this._children.pop();
|
|
2501
|
+
result.removed.push(this._children.pop());
|
|
2394
2502
|
}
|
|
2395
|
-
result.removed.push(...this._children);
|
|
2396
2503
|
}
|
|
2397
2504
|
}
|
|
2398
2505
|
this._children.forEach(x => {
|
|
@@ -2536,6 +2643,9 @@ class Logger {
|
|
|
2536
2643
|
console[level](msg);
|
|
2537
2644
|
}
|
|
2538
2645
|
}
|
|
2646
|
+
isLevelEnabled(level) {
|
|
2647
|
+
return this.logLevel !== 0 && this.logLevel <= levels[level];
|
|
2648
|
+
}
|
|
2539
2649
|
logLevel;
|
|
2540
2650
|
constructor(logLevel = 'off') {
|
|
2541
2651
|
this.logLevel = levels[logLevel];
|
|
@@ -2596,7 +2706,18 @@ class EventQueue {
|
|
|
2596
2706
|
const evntNode = new EventNode(node, e);
|
|
2597
2707
|
const counter = this._runningEventCount[evntNode.valueOf()] || 0;
|
|
2598
2708
|
if (counter < EventQueue.MAX_EVENT_CYCLE_COUNT) {
|
|
2599
|
-
|
|
2709
|
+
let payloadAsStr = '';
|
|
2710
|
+
if (e?.type === 'change' && !e?.payload?.changes.map(_ => _.propertyName).includes('activeChild')) {
|
|
2711
|
+
payloadAsStr = JSON.stringify(e.payload.changes, null, 2);
|
|
2712
|
+
}
|
|
2713
|
+
else if (e?.type.includes('setProperty')) {
|
|
2714
|
+
payloadAsStr = JSON.stringify(e.payload, null, 2);
|
|
2715
|
+
}
|
|
2716
|
+
if (this.logger.isLevelEnabled('info')) {
|
|
2717
|
+
node.withDependencyTrackingControl(true, () => {
|
|
2718
|
+
this.logger.info(`Queued event : ${e.type} node: ${node.id} - ${node.qualifiedName} - ${payloadAsStr}`);
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2600
2721
|
if (priority) {
|
|
2601
2722
|
const index = this._isProcessing ? 1 : 0;
|
|
2602
2723
|
this._pendingEvents.splice(index, 0, evntNode);
|
|
@@ -2689,6 +2810,13 @@ const convertQueryString = (endpoint, payload) => {
|
|
|
2689
2810
|
return endpoint.includes('?') ? `${endpoint}&${params.join('&')}` : `${endpoint}?${params.join('&')}`;
|
|
2690
2811
|
};
|
|
2691
2812
|
|
|
2813
|
+
function parsePropertyPath(keyStr) {
|
|
2814
|
+
return keyStr
|
|
2815
|
+
.replace(/\[/g, '.')
|
|
2816
|
+
.replace(/\]/g, '')
|
|
2817
|
+
.split('.')
|
|
2818
|
+
.filter(Boolean);
|
|
2819
|
+
}
|
|
2692
2820
|
const getCustomEventName = (name) => {
|
|
2693
2821
|
const eName = name;
|
|
2694
2822
|
if (eName.length > 0 && eName.startsWith('custom:')) {
|
|
@@ -3074,21 +3202,23 @@ class FunctionRuntimeImpl {
|
|
|
3074
3202
|
},
|
|
3075
3203
|
importData: {
|
|
3076
3204
|
_func: (args, data, interpreter) => {
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
else {
|
|
3083
|
-
const field = interpreter.globals.form.resolveQualifiedName(qualifiedName);
|
|
3084
|
-
if (field?.isContainer) {
|
|
3085
|
-
field.importData(inputData, qualifiedName);
|
|
3205
|
+
return interpreter.globals.form.withDependencyTrackingControl(true, () => {
|
|
3206
|
+
const inputData = args[0];
|
|
3207
|
+
const qualifiedName = args[1];
|
|
3208
|
+
if (typeof inputData === 'object' && inputData !== null && !qualifiedName) {
|
|
3209
|
+
interpreter.globals.form.importData(inputData);
|
|
3086
3210
|
}
|
|
3087
3211
|
else {
|
|
3088
|
-
interpreter.globals.form.
|
|
3212
|
+
const field = interpreter.globals.form.resolveQualifiedName(qualifiedName);
|
|
3213
|
+
if (field?.isContainer) {
|
|
3214
|
+
field.importData(inputData, qualifiedName);
|
|
3215
|
+
}
|
|
3216
|
+
else {
|
|
3217
|
+
interpreter.globals.form.logger.error('Invalid argument passed in importData. A container is expected');
|
|
3218
|
+
}
|
|
3089
3219
|
}
|
|
3090
|
-
|
|
3091
|
-
|
|
3220
|
+
return {};
|
|
3221
|
+
});
|
|
3092
3222
|
},
|
|
3093
3223
|
_signature: []
|
|
3094
3224
|
},
|
|
@@ -3153,6 +3283,49 @@ class FunctionRuntimeImpl {
|
|
|
3153
3283
|
},
|
|
3154
3284
|
_signature: []
|
|
3155
3285
|
},
|
|
3286
|
+
setVariable: {
|
|
3287
|
+
_func: (args, data, interpreter) => {
|
|
3288
|
+
const variableName = toString(args[0]);
|
|
3289
|
+
let variableValue = args[1];
|
|
3290
|
+
const normalFieldOrPanel = args[2] || interpreter.globals.form;
|
|
3291
|
+
if (variableValue && typeof variableValue === 'object' && '$qualifiedName' in variableValue) {
|
|
3292
|
+
const variableValueElement = interpreter.globals.form.getElement(variableValue.$id);
|
|
3293
|
+
variableValue = variableValueElement._jsonModel.value;
|
|
3294
|
+
}
|
|
3295
|
+
const target = interpreter.globals.form.getElement(normalFieldOrPanel.$id);
|
|
3296
|
+
const propertiesManager = target.getPropertiesManager();
|
|
3297
|
+
propertiesManager.updateSimpleProperty(variableName, variableValue);
|
|
3298
|
+
return {};
|
|
3299
|
+
},
|
|
3300
|
+
_signature: []
|
|
3301
|
+
},
|
|
3302
|
+
getVariable: {
|
|
3303
|
+
_func: (args, data, interpreter) => {
|
|
3304
|
+
const variableName = toString(args[0]);
|
|
3305
|
+
const normalFieldOrPanel = args[1] || interpreter.globals.form;
|
|
3306
|
+
if (!variableName) {
|
|
3307
|
+
return undefined;
|
|
3308
|
+
}
|
|
3309
|
+
const target = interpreter.globals.form.getElement(normalFieldOrPanel.$id);
|
|
3310
|
+
const propertiesManager = target.getPropertiesManager();
|
|
3311
|
+
if (variableName.includes('.')) {
|
|
3312
|
+
const properties = parsePropertyPath(variableName);
|
|
3313
|
+
let value = propertiesManager.properties;
|
|
3314
|
+
for (const prop of properties) {
|
|
3315
|
+
if (value === undefined || value === null) {
|
|
3316
|
+
return undefined;
|
|
3317
|
+
}
|
|
3318
|
+
value = value[prop];
|
|
3319
|
+
}
|
|
3320
|
+
return value;
|
|
3321
|
+
}
|
|
3322
|
+
else {
|
|
3323
|
+
propertiesManager.ensurePropertyDescriptor(variableName);
|
|
3324
|
+
return propertiesManager.properties[variableName];
|
|
3325
|
+
}
|
|
3326
|
+
},
|
|
3327
|
+
_signature: []
|
|
3328
|
+
},
|
|
3156
3329
|
request: {
|
|
3157
3330
|
_func: (args, data, interpreter) => {
|
|
3158
3331
|
const uri = toString(args[0]);
|
|
@@ -3445,6 +3618,15 @@ class FunctionRuntimeImpl {
|
|
|
3445
3618
|
return instanceManager.length - 1;
|
|
3446
3619
|
},
|
|
3447
3620
|
_signature: []
|
|
3621
|
+
},
|
|
3622
|
+
today: {
|
|
3623
|
+
_func: () => {
|
|
3624
|
+
const MS_IN_DAY = 24 * 60 * 60 * 1000;
|
|
3625
|
+
const now = new Date(Date.now());
|
|
3626
|
+
const _today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
3627
|
+
return _today / MS_IN_DAY;
|
|
3628
|
+
},
|
|
3629
|
+
_signature: []
|
|
3448
3630
|
}
|
|
3449
3631
|
};
|
|
3450
3632
|
return { ...defaultFunctions, ...FunctionRuntimeImpl.getInstance().customFunctions };
|
|
@@ -3973,9 +4155,9 @@ class RuleEngine {
|
|
|
3973
4155
|
this._context = oldContext;
|
|
3974
4156
|
return finalRes;
|
|
3975
4157
|
}
|
|
3976
|
-
trackDependency(subscriber) {
|
|
4158
|
+
trackDependency(subscriber, propertyName) {
|
|
3977
4159
|
if (this.dependencyTracking && this._context && this._context.field !== undefined && this._context.field !== subscriber) {
|
|
3978
|
-
subscriber._addDependent(this._context.field);
|
|
4160
|
+
subscriber._addDependent(this._context.field, propertyName);
|
|
3979
4161
|
}
|
|
3980
4162
|
}
|
|
3981
4163
|
setDependencyTracking(track) {
|
|
@@ -4474,7 +4656,7 @@ class Field extends Scriptable {
|
|
|
4474
4656
|
valueOf() {
|
|
4475
4657
|
const obj = this[target];
|
|
4476
4658
|
const actualField = obj === undefined ? this : obj;
|
|
4477
|
-
actualField.ruleEngine.trackDependency(actualField);
|
|
4659
|
+
actualField.ruleEngine.trackDependency(actualField, 'value');
|
|
4478
4660
|
return actualField._jsonModel.value || null;
|
|
4479
4661
|
}
|
|
4480
4662
|
toString() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
|
|
2
|
+
import { PropertiesManager } from './PropertiesManager.js';
|
|
2
3
|
import DataGroup from './data/DataGroup';
|
|
3
4
|
import DataValue from './data/DataValue';
|
|
4
5
|
export declare const editableProperties: string[];
|
|
@@ -22,6 +23,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
22
23
|
_eventSource: EventSource;
|
|
23
24
|
protected _fragment: string;
|
|
24
25
|
protected _idSet: Set<string> | undefined;
|
|
26
|
+
private _propertiesManager;
|
|
25
27
|
protected createIdSet(): Set<string> | undefined;
|
|
26
28
|
get isContainer(): boolean;
|
|
27
29
|
constructor(params: T, _options: {
|
|
@@ -56,9 +58,15 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
56
58
|
set label(l: import("./types/Json").Label | undefined);
|
|
57
59
|
get uniqueItems(): boolean | undefined;
|
|
58
60
|
isTransparent(): boolean;
|
|
59
|
-
getDependents():
|
|
61
|
+
getDependents(): {
|
|
62
|
+
id: string;
|
|
63
|
+
propertyName: string | undefined;
|
|
64
|
+
}[];
|
|
60
65
|
getState(forRestore?: boolean): T & {
|
|
61
|
-
_dependents?:
|
|
66
|
+
_dependents?: {
|
|
67
|
+
id: string;
|
|
68
|
+
propertyName: string | undefined;
|
|
69
|
+
}[] | undefined;
|
|
62
70
|
allowedComponents?: undefined;
|
|
63
71
|
columnClassNames?: undefined;
|
|
64
72
|
columnCount?: undefined;
|
|
@@ -78,7 +86,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
78
86
|
subscribe(callback: callbackFn, eventName?: string): {
|
|
79
87
|
unsubscribe: () => void;
|
|
80
88
|
};
|
|
81
|
-
_addDependent(dependent: BaseModel): void;
|
|
89
|
+
_addDependent(dependent: BaseModel, propertyName?: string): void;
|
|
82
90
|
removeDependent(dependent: BaseModel): void;
|
|
83
91
|
abstract validate(): Array<ValidationError>;
|
|
84
92
|
abstract executeAction(action: Action): any;
|
|
@@ -98,6 +106,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
98
106
|
set properties(p: {
|
|
99
107
|
[key: string]: any;
|
|
100
108
|
});
|
|
109
|
+
getPropertiesManager(): PropertiesManager;
|
|
101
110
|
abstract defaultDataModel(name: string | number): DataValue | undefined;
|
|
102
111
|
abstract syncDataAndFormModel(a?: DataValue | DataGroup): any;
|
|
103
112
|
getNonTransparentParent(): ContainerModel;
|
|
@@ -129,6 +129,8 @@ declare class Checkbox extends Field {
|
|
|
129
129
|
errorMessage?: string | undefined;
|
|
130
130
|
properties: {
|
|
131
131
|
[key: string]: any;
|
|
132
|
+
} & {
|
|
133
|
+
[key: string]: any;
|
|
132
134
|
};
|
|
133
135
|
repeatable?: boolean | undefined;
|
|
134
136
|
screenReaderText?: string | undefined;
|
|
@@ -144,7 +146,10 @@ declare class Checkbox extends Field {
|
|
|
144
146
|
value?: any;
|
|
145
147
|
displayValueExpression?: string | undefined;
|
|
146
148
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
147
|
-
_dependents?:
|
|
149
|
+
_dependents?: {
|
|
150
|
+
id: string;
|
|
151
|
+
propertyName: string | undefined;
|
|
152
|
+
}[] | undefined;
|
|
148
153
|
allowedComponents?: undefined;
|
|
149
154
|
columnClassNames?: undefined;
|
|
150
155
|
columnCount?: undefined;
|