@aemforms/af-core 0.22.163 → 0.22.164

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.
@@ -1457,6 +1457,7 @@ class BaseNode {
1457
1457
  _ruleNode;
1458
1458
  _lang = '';
1459
1459
  _callbacks = {};
1460
+ _onlyViewNotify;
1460
1461
  _dependents = [];
1461
1462
  _jsonModel;
1462
1463
  _tokens = [];
@@ -1647,12 +1648,13 @@ class BaseNode {
1647
1648
  };
1648
1649
  });
1649
1650
  }
1650
- subscribe(callback, eventName = 'change') {
1651
+ subscribe(callback, eventName = 'change', dependentType = 'view') {
1651
1652
  this._callbacks[eventName] = this._callbacks[eventName] || [];
1652
- this._callbacks[eventName].push(callback);
1653
+ const entry = { callback, dependentType };
1654
+ this._callbacks[eventName].push(entry);
1653
1655
  return {
1654
1656
  unsubscribe: () => {
1655
- this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
1657
+ this._callbacks[eventName] = this._callbacks[eventName].filter(x => x.callback !== callback);
1656
1658
  }
1657
1659
  };
1658
1660
  }
@@ -1680,7 +1682,7 @@ class BaseNode {
1680
1682
  dependent.dispatch(new ExecuteRule());
1681
1683
  }
1682
1684
  }
1683
- });
1685
+ }, 'change', 'model');
1684
1686
  this._dependents.push({ node: dependent, propertyName, subscription });
1685
1687
  }
1686
1688
  }
@@ -1692,10 +1694,17 @@ class BaseNode {
1692
1694
  }
1693
1695
  }
1694
1696
  queueEvent(action) {
1697
+ if (this._onlyViewNotify) {
1698
+ return;
1699
+ }
1695
1700
  const actionWithTarget = new ActionImplWithTarget(action, this);
1696
1701
  this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
1697
1702
  }
1698
1703
  dispatch(action) {
1704
+ if (this._onlyViewNotify) {
1705
+ this.notifyDependents(new ActionImplWithTarget(action, this));
1706
+ return;
1707
+ }
1699
1708
  this.queueEvent(action);
1700
1709
  this.form.getEventQueue().runPendingQueue();
1701
1710
  }
@@ -1724,10 +1733,14 @@ class BaseNode {
1724
1733
  });
1725
1734
  this._jsonModel._dependents = undefined;
1726
1735
  }
1727
- const handlers = this._callbacks[action.type] || [];
1728
- handlers.forEach(x => {
1736
+ const onlyView = this._onlyViewNotify;
1737
+ const entries = this._callbacks[action.type] || [];
1738
+ const toRun = onlyView
1739
+ ? entries.filter(e => e.dependentType === 'view' || e.dependentType === undefined)
1740
+ : entries;
1741
+ toRun.forEach(({ callback }) => {
1729
1742
  this.withDependencyTrackingControl(true, () => {
1730
- x(new ActionImplWithTarget(action, this));
1743
+ callback(new ActionImplWithTarget(action, this));
1731
1744
  });
1732
1745
  });
1733
1746
  }
@@ -4202,13 +4215,13 @@ class Form extends Container {
4202
4215
  if (this._invalidFields.indexOf(action.target.id) === -1) {
4203
4216
  this._invalidFields.push(action.target.id);
4204
4217
  }
4205
- }, 'invalid');
4218
+ }, 'invalid', 'model');
4206
4219
  field.subscribe((action) => {
4207
4220
  const index = this._invalidFields.indexOf(action.target.id);
4208
4221
  if (index > -1) {
4209
4222
  this._invalidFields.splice(index, 1);
4210
4223
  }
4211
- }, 'valid');
4224
+ }, 'valid', 'model');
4212
4225
  field.subscribe((action) => {
4213
4226
  const field = action.target.getState();
4214
4227
  if (action.payload.changes.length > 0 && field) {
@@ -4233,7 +4246,7 @@ class Form extends Container {
4233
4246
  const fieldChangedAction = new FieldChanged(changes, field, action.payload.eventSource);
4234
4247
  this.notifyDependents(fieldChangedAction);
4235
4248
  }
4236
- });
4249
+ }, 'change', 'model');
4237
4250
  }
4238
4251
  visit(callBack) {
4239
4252
  this.traverseChild(this, callBack);
@@ -4380,6 +4393,13 @@ class RuleEngine {
4380
4393
  this._context = globals;
4381
4394
  let res = undefined;
4382
4395
  try {
4396
+ this._context?.form?.logger?.info({
4397
+ message: 'Executing rule',
4398
+ expression: eString,
4399
+ fieldName: this._context.field?.name,
4400
+ fieldId: this._context.field?.id,
4401
+ eventType: this._context?.$event?.type
4402
+ });
4383
4403
  res = formula.run(ast, data, 'en-US', globals);
4384
4404
  }
4385
4405
  catch (err) {
@@ -4876,7 +4896,12 @@ class Field extends Scriptable {
4876
4896
  if (updates.valid) {
4877
4897
  this.triggerValidationEvent(updates);
4878
4898
  }
4879
- const changeAction = new Change({ changes: changes.concat(Object.values(updates)), eventSource: this._eventSource });
4899
+ const allChanges = changes.concat(Object.values(updates));
4900
+ const changesWithCurrentState = allChanges.map((change) => {
4901
+ const valueToUse = change.propertyName === 'value' ? this._jsonModel.value : change.currentValue;
4902
+ return { ...change, currentValue: valueToUse };
4903
+ });
4904
+ const changeAction = new Change({ changes: changesWithCurrentState, eventSource: this._eventSource });
4880
4905
  this.dispatch(changeAction);
4881
4906
  }
4882
4907
  }
@@ -1,4 +1,4 @@
1
- import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
1
+ import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, DependentType, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
2
2
  import { PropertiesManager } from './PropertiesManager.js';
3
3
  import DataGroup from './data/DataGroup';
4
4
  import DataValue from './data/DataValue';
@@ -15,6 +15,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
15
15
  private _ruleNode;
16
16
  private _lang?;
17
17
  private _callbacks;
18
+ _onlyViewNotify?: boolean;
18
19
  private _dependents;
19
20
  protected _jsonModel: T & {
20
21
  id: string;
@@ -83,7 +84,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
83
84
  qualifiedName: any;
84
85
  id: string;
85
86
  };
86
- subscribe(callback: callbackFn, eventName?: string): {
87
+ subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): {
87
88
  unsubscribe: () => void;
88
89
  };
89
90
  _addDependent(dependent: BaseModel, propertyName?: string): void;
@@ -38,8 +38,9 @@ export interface Action {
38
38
  readonly currentTarget: FormModel | FieldModel | FieldsetModel;
39
39
  }
40
40
  export type callbackFn = (action: Action) => void;
41
+ export type DependentType = 'view' | 'model';
41
42
  export interface WithController {
42
- subscribe(callback: callbackFn, eventName?: string): Subscription;
43
+ subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): Subscription;
43
44
  dispatch(action: Action): void;
44
45
  }
45
46
  export type FormCreationMode = 'create' | 'restore';
@@ -80,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
80
81
  ruleNodeReference(): any;
81
82
  _initialize(mode?: FormCreationMode): any;
82
83
  _addDependent(dependent: BaseModel, propertyName?: string): any;
84
+ _onlyViewNotify?: boolean;
83
85
  _eventSource: EventSource;
84
86
  readonly fragment: string;
85
87
  }
package/lib/BaseNode.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
1
+ import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, DependentType, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
2
2
  import { PropertiesManager } from './PropertiesManager.js';
3
3
  import DataGroup from './data/DataGroup';
4
4
  import DataValue from './data/DataValue';
@@ -15,6 +15,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
15
15
  private _ruleNode;
16
16
  private _lang?;
17
17
  private _callbacks;
18
+ _onlyViewNotify?: boolean;
18
19
  private _dependents;
19
20
  protected _jsonModel: T & {
20
21
  id: string;
@@ -83,7 +84,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
83
84
  qualifiedName: any;
84
85
  id: string;
85
86
  };
86
- subscribe(callback: callbackFn, eventName?: string): {
87
+ subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): {
87
88
  unsubscribe: () => void;
88
89
  };
89
90
  _addDependent(dependent: BaseModel, propertyName?: string): void;
package/lib/BaseNode.js CHANGED
@@ -298,12 +298,13 @@ class BaseNode {
298
298
  } : {}));
299
299
  });
300
300
  }
301
- subscribe(callback, eventName = 'change') {
301
+ subscribe(callback, eventName = 'change', dependentType = 'view') {
302
302
  this._callbacks[eventName] = this._callbacks[eventName] || [];
303
- this._callbacks[eventName].push(callback);
303
+ const entry = { callback, dependentType };
304
+ this._callbacks[eventName].push(entry);
304
305
  return {
305
306
  unsubscribe: () => {
306
- this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
307
+ this._callbacks[eventName] = this._callbacks[eventName].filter(x => x.callback !== callback);
307
308
  }
308
309
  };
309
310
  }
@@ -331,7 +332,7 @@ class BaseNode {
331
332
  dependent.dispatch(new Events_1.ExecuteRule());
332
333
  }
333
334
  }
334
- });
335
+ }, 'change', 'model');
335
336
  this._dependents.push({ node: dependent, propertyName, subscription });
336
337
  }
337
338
  }
@@ -343,10 +344,17 @@ class BaseNode {
343
344
  }
344
345
  }
345
346
  queueEvent(action) {
347
+ if (this._onlyViewNotify) {
348
+ return;
349
+ }
346
350
  const actionWithTarget = new ActionImplWithTarget(action, this);
347
351
  this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
348
352
  }
349
353
  dispatch(action) {
354
+ if (this._onlyViewNotify) {
355
+ this.notifyDependents(new ActionImplWithTarget(action, this));
356
+ return;
357
+ }
350
358
  this.queueEvent(action);
351
359
  this.form.getEventQueue().runPendingQueue();
352
360
  }
@@ -376,10 +384,14 @@ class BaseNode {
376
384
  });
377
385
  this._jsonModel._dependents = undefined;
378
386
  }
379
- const handlers = this._callbacks[action.type] || [];
380
- handlers.forEach(x => {
387
+ const onlyView = this._onlyViewNotify;
388
+ const entries = this._callbacks[action.type] || [];
389
+ const toRun = onlyView
390
+ ? entries.filter(e => e.dependentType === 'view' || e.dependentType === undefined)
391
+ : entries;
392
+ toRun.forEach(({ callback }) => {
381
393
  this.withDependencyTrackingControl(true, () => {
382
- x(new ActionImplWithTarget(action, this));
394
+ callback(new ActionImplWithTarget(action, this));
383
395
  });
384
396
  });
385
397
  }
package/lib/Field.js CHANGED
@@ -404,7 +404,12 @@ class Field extends Scriptable_1.default {
404
404
  if (updates.valid) {
405
405
  this.triggerValidationEvent(updates);
406
406
  }
407
- const changeAction = new Events_1.Change({ changes: changes.concat(Object.values(updates)), eventSource: this._eventSource });
407
+ const allChanges = changes.concat(Object.values(updates));
408
+ const changesWithCurrentState = allChanges.map((change) => {
409
+ const valueToUse = change.propertyName === 'value' ? this._jsonModel.value : change.currentValue;
410
+ return Object.assign(Object.assign({}, change), { currentValue: valueToUse });
411
+ });
412
+ const changeAction = new Events_1.Change({ changes: changesWithCurrentState, eventSource: this._eventSource });
408
413
  this.dispatch(changeAction);
409
414
  }
410
415
  }
package/lib/Form.js CHANGED
@@ -270,13 +270,13 @@ class Form extends Container_1.default {
270
270
  if (this._invalidFields.indexOf(action.target.id) === -1) {
271
271
  this._invalidFields.push(action.target.id);
272
272
  }
273
- }, 'invalid');
273
+ }, 'invalid', 'model');
274
274
  field.subscribe((action) => {
275
275
  const index = this._invalidFields.indexOf(action.target.id);
276
276
  if (index > -1) {
277
277
  this._invalidFields.splice(index, 1);
278
278
  }
279
- }, 'valid');
279
+ }, 'valid', 'model');
280
280
  field.subscribe((action) => {
281
281
  const field = action.target.getState();
282
282
  if (action.payload.changes.length > 0 && field) {
@@ -301,7 +301,7 @@ class Form extends Container_1.default {
301
301
  const fieldChangedAction = new Events_1.FieldChanged(changes, field, action.payload.eventSource);
302
302
  this.notifyDependents(fieldChangedAction);
303
303
  }
304
- });
304
+ }, 'change', 'model');
305
305
  }
306
306
  visit(callBack) {
307
307
  this.traverseChild(this, callBack);
@@ -30,18 +30,25 @@ class RuleEngine {
30
30
  return { formula, ast: formula.compile(rule, this._globalNames) };
31
31
  }
32
32
  execute(node, data, globals, useValueOf = false, eString) {
33
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
34
34
  const { formula, ast } = node;
35
35
  const oldContext = this._context;
36
36
  this._context = globals;
37
37
  let res = undefined;
38
38
  try {
39
+ (_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.info({
40
+ message: 'Executing rule',
41
+ expression: eString,
42
+ fieldName: (_d = this._context.field) === null || _d === void 0 ? void 0 : _d.name,
43
+ fieldId: (_e = this._context.field) === null || _e === void 0 ? void 0 : _e.id,
44
+ eventType: (_g = (_f = this._context) === null || _f === void 0 ? void 0 : _f.$event) === null || _g === void 0 ? void 0 : _g.type
45
+ });
39
46
  res = formula.run(ast, data, 'en-US', globals);
40
47
  }
41
48
  catch (err) {
42
- (_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);
43
- if ((_d = this._context) === null || _d === void 0 ? void 0 : _d.form) {
44
- const field = (_e = this._context) === null || _e === void 0 ? void 0 : _e.field;
49
+ (_k = (_j = (_h = this._context) === null || _h === void 0 ? void 0 : _h.form) === null || _j === void 0 ? void 0 : _j.logger) === null || _k === void 0 ? void 0 : _k.error(err);
50
+ if ((_l = this._context) === null || _l === void 0 ? void 0 : _l.form) {
51
+ const field = (_m = this._context) === null || _m === void 0 ? void 0 : _m.field;
45
52
  const fieldName = field === null || field === void 0 ? void 0 : field.name;
46
53
  const errorMsg = err instanceof Error ? err.message : String(err);
47
54
  const fullError = fieldName
@@ -50,7 +57,7 @@ class RuleEngine {
50
57
  const errorPayload = {
51
58
  name: fieldName,
52
59
  error: fullError,
53
- event: (_g = (_f = this._context) === null || _f === void 0 ? void 0 : _f.$event) === null || _g === void 0 ? void 0 : _g.type,
60
+ event: (_p = (_o = this._context) === null || _o === void 0 ? void 0 : _o.$event) === null || _p === void 0 ? void 0 : _p.type,
54
61
  rule: eString,
55
62
  stack: err instanceof Error ? err.stack : undefined
56
63
  };
@@ -58,9 +65,9 @@ class RuleEngine {
58
65
  }
59
66
  }
60
67
  if (this.debugInfo.length) {
61
- (_k = (_j = (_h = this._context) === null || _h === void 0 ? void 0 : _h.form) === null || _j === void 0 ? void 0 : _j.logger) === null || _k === void 0 ? void 0 : _k.warn(`Form rule expression string: ${eString}`);
68
+ (_s = (_r = (_q = this._context) === null || _q === void 0 ? void 0 : _q.form) === null || _r === void 0 ? void 0 : _r.logger) === null || _s === void 0 ? void 0 : _s.warn(`Form rule expression string: ${eString}`);
62
69
  while (this.debugInfo.length > 0) {
63
- (_o = (_m = (_l = this._context) === null || _l === void 0 ? void 0 : _l.form) === null || _m === void 0 ? void 0 : _m.logger) === null || _o === void 0 ? void 0 : _o.warn(this.debugInfo.pop());
70
+ (_v = (_u = (_t = this._context) === null || _t === void 0 ? void 0 : _t.form) === null || _u === void 0 ? void 0 : _u.logger) === null || _v === void 0 ? void 0 : _v.warn(this.debugInfo.pop());
64
71
  }
65
72
  }
66
73
  let finalRes = res;
@@ -38,8 +38,9 @@ export interface Action {
38
38
  readonly currentTarget: FormModel | FieldModel | FieldsetModel;
39
39
  }
40
40
  export declare type callbackFn = (action: Action) => void;
41
+ export declare type DependentType = 'view' | 'model';
41
42
  export interface WithController {
42
- subscribe(callback: callbackFn, eventName?: string): Subscription;
43
+ subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): Subscription;
43
44
  dispatch(action: Action): void;
44
45
  }
45
46
  export declare type FormCreationMode = 'create' | 'restore';
@@ -80,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
80
81
  ruleNodeReference(): any;
81
82
  _initialize(mode?: FormCreationMode): any;
82
83
  _addDependent(dependent: BaseModel, propertyName?: string): any;
84
+ _onlyViewNotify?: boolean;
83
85
  _eventSource: EventSource;
84
86
  readonly fragment: string;
85
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.163",
3
+ "version": "0.22.164",
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.163"
40
+ "@aemforms/af-formatters": "^0.22.164"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",