@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.
@@ -16,6 +16,13 @@ const FileObject_1 = require("../FileObject");
16
16
  const FormUtils_1 = require("../utils/FormUtils");
17
17
  const JsonUtils_1 = require("../utils/JsonUtils");
18
18
  const types_1 = require("../types");
19
+ function parsePropertyPath(keyStr) {
20
+ return keyStr
21
+ .replace(/\[/g, '.')
22
+ .replace(/\]/g, '')
23
+ .split('.')
24
+ .filter(Boolean);
25
+ }
19
26
  const getCustomEventName = (name) => {
20
27
  const eName = name;
21
28
  if (eName.length > 0 && eName.startsWith('custom:')) {
@@ -397,21 +404,23 @@ class FunctionRuntimeImpl {
397
404
  },
398
405
  importData: {
399
406
  _func: (args, data, interpreter) => {
400
- const inputData = args[0];
401
- const qualifiedName = args[1];
402
- if (typeof inputData === 'object' && inputData !== null && !qualifiedName) {
403
- interpreter.globals.form.importData(inputData);
404
- }
405
- else {
406
- const field = interpreter.globals.form.resolveQualifiedName(qualifiedName);
407
- if (field === null || field === void 0 ? void 0 : field.isContainer) {
408
- field.importData(inputData, qualifiedName);
407
+ return interpreter.globals.form.withDependencyTrackingControl(true, () => {
408
+ const inputData = args[0];
409
+ const qualifiedName = args[1];
410
+ if (typeof inputData === 'object' && inputData !== null && !qualifiedName) {
411
+ interpreter.globals.form.importData(inputData);
409
412
  }
410
413
  else {
411
- interpreter.globals.form.logger.error('Invalid argument passed in importData. A container is expected');
414
+ const field = interpreter.globals.form.resolveQualifiedName(qualifiedName);
415
+ if (field === null || field === void 0 ? void 0 : field.isContainer) {
416
+ field.importData(inputData, qualifiedName);
417
+ }
418
+ else {
419
+ interpreter.globals.form.logger.error('Invalid argument passed in importData. A container is expected');
420
+ }
412
421
  }
413
- }
414
- return {};
422
+ return {};
423
+ });
415
424
  },
416
425
  _signature: []
417
426
  },
@@ -477,6 +486,49 @@ class FunctionRuntimeImpl {
477
486
  },
478
487
  _signature: []
479
488
  },
489
+ setVariable: {
490
+ _func: (args, data, interpreter) => {
491
+ const variableName = toString(args[0]);
492
+ let variableValue = args[1];
493
+ const normalFieldOrPanel = args[2] || interpreter.globals.form;
494
+ if (variableValue && typeof variableValue === 'object' && '$qualifiedName' in variableValue) {
495
+ const variableValueElement = interpreter.globals.form.getElement(variableValue.$id);
496
+ variableValue = variableValueElement._jsonModel.value;
497
+ }
498
+ const target = interpreter.globals.form.getElement(normalFieldOrPanel.$id);
499
+ const propertiesManager = target.getPropertiesManager();
500
+ propertiesManager.updateSimpleProperty(variableName, variableValue);
501
+ return {};
502
+ },
503
+ _signature: []
504
+ },
505
+ getVariable: {
506
+ _func: (args, data, interpreter) => {
507
+ const variableName = toString(args[0]);
508
+ const normalFieldOrPanel = args[1] || interpreter.globals.form;
509
+ if (!variableName) {
510
+ return undefined;
511
+ }
512
+ const target = interpreter.globals.form.getElement(normalFieldOrPanel.$id);
513
+ const propertiesManager = target.getPropertiesManager();
514
+ if (variableName.includes('.')) {
515
+ const properties = parsePropertyPath(variableName);
516
+ let value = propertiesManager.properties;
517
+ for (const prop of properties) {
518
+ if (value === undefined || value === null) {
519
+ return undefined;
520
+ }
521
+ value = value[prop];
522
+ }
523
+ return value;
524
+ }
525
+ else {
526
+ propertiesManager.ensurePropertyDescriptor(variableName);
527
+ return propertiesManager.properties[variableName];
528
+ }
529
+ },
530
+ _signature: []
531
+ },
480
532
  request: {
481
533
  _func: (args, data, interpreter) => {
482
534
  const uri = toString(args[0]);
@@ -766,6 +818,15 @@ class FunctionRuntimeImpl {
766
818
  return instanceManager.length - 1;
767
819
  },
768
820
  _signature: []
821
+ },
822
+ today: {
823
+ _func: () => {
824
+ const MS_IN_DAY = 24 * 60 * 60 * 1000;
825
+ const now = new Date(Date.now());
826
+ const _today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
827
+ return _today / MS_IN_DAY;
828
+ },
829
+ _signature: []
769
830
  }
770
831
  };
771
832
  return Object.assign(Object.assign({}, defaultFunctions), FunctionRuntimeImpl.getInstance().customFunctions);
@@ -12,7 +12,7 @@ declare class RuleEngine {
12
12
  ast: any;
13
13
  };
14
14
  execute(node: any, data: any, globals: any, useValueOf: boolean | undefined, eString: string): any;
15
- trackDependency(subscriber: BaseModel): void;
15
+ trackDependency(subscriber: BaseModel, propertyName?: string): void;
16
16
  setDependencyTracking(track: boolean): void;
17
17
  getDependencyTracking(): boolean;
18
18
  }
@@ -55,9 +55,9 @@ class RuleEngine {
55
55
  this._context = oldContext;
56
56
  return finalRes;
57
57
  }
58
- trackDependency(subscriber) {
58
+ trackDependency(subscriber, propertyName) {
59
59
  if (this.dependencyTracking && this._context && this._context.field !== undefined && this._context.field !== subscriber) {
60
- subscriber._addDependent(this._context.field);
60
+ subscriber._addDependent(this._context.field, propertyName);
61
61
  }
62
62
  }
63
63
  setDependencyTracking(track) {
@@ -79,7 +79,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
79
79
  getRuleNode(): any;
80
80
  ruleNodeReference(): any;
81
81
  _initialize(mode?: FormCreationMode): any;
82
- _addDependent(dependent: BaseModel): any;
82
+ _addDependent(dependent: BaseModel, propertyName?: string): any;
83
83
  _eventSource: EventSource;
84
84
  readonly fragment: string;
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.136",
3
+ "version": "0.22.138",
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.136"
40
+ "@aemforms/af-formatters": "^0.22.138"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",