@aemforms/af-core 0.22.66 → 0.22.68

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.
Files changed (2) hide show
  1. package/lib/Form.js +47 -27
  2. package/package.json +2 -2
package/lib/Form.js CHANGED
@@ -7,7 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
7
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
- var _Form_instances, _Form_getNavigableChildren, _Form_getFirstNavigableChild, _Form_setActiveFirstDeepChild, _Form_getNextItem, _Form_getPreviousItem;
10
+ var _Form_instances, _Form_getNavigableChildren, _Form_getFirstNavigableChild, _Form_setActiveFirstDeepChild, _Form_getNextItem, _Form_getPreviousItem, _Form_clearCurrentFocus;
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const Container_1 = __importDefault(require("./Container"));
13
13
  const FormMetaData_1 = __importDefault(require("./FormMetaData"));
@@ -82,32 +82,28 @@ class Form extends Container_1.default {
82
82
  return submitMetaInstance;
83
83
  }
84
84
  setFocus(field, focusOption) {
85
- if (focusOption) {
86
- const parent = ((field === null || field === void 0 ? void 0 : field.isContainer) ? field : field.parent);
87
- const navigableChidren = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNavigableChildren).call(this, parent.items);
88
- let activeChild = parent.activeChild;
89
- let currActiveChildIndex = activeChild !== null ? navigableChidren.indexOf(activeChild) : -1;
90
- if (parent.activeChild === null) {
91
- __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, navigableChidren[0]);
92
- currActiveChildIndex = 0;
93
- return;
94
- }
95
- if (focusOption === Model_1.FocusOption.NEXT_ITEM) {
96
- activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNextItem).call(this, currActiveChildIndex, navigableChidren);
97
- }
98
- else if (focusOption === Model_1.FocusOption.PREVIOUS_ITEM) {
99
- activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getPreviousItem).call(this, currActiveChildIndex, navigableChidren);
100
- }
101
- if (activeChild !== null) {
102
- __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, activeChild);
103
- }
85
+ if (!focusOption) {
86
+ __classPrivateFieldGet(this, _Form_instances, "m", _Form_clearCurrentFocus).call(this, field);
87
+ __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, field);
88
+ return;
104
89
  }
105
- else {
106
- const parent = field.parent;
107
- const currentField = field;
108
- while (parent != null && parent.activeChild != currentField) {
109
- parent.activeChild = currentField;
110
- }
90
+ const parent = ((field === null || field === void 0 ? void 0 : field.isContainer) ? field : field.parent);
91
+ const navigableChidren = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNavigableChildren).call(this, parent.items);
92
+ let activeChild = parent.activeChild;
93
+ let currActiveChildIndex = activeChild !== null ? navigableChidren.indexOf(activeChild) : -1;
94
+ if (parent.activeChild === null) {
95
+ __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, navigableChidren[0]);
96
+ currActiveChildIndex = 0;
97
+ return;
98
+ }
99
+ if (focusOption === Model_1.FocusOption.NEXT_ITEM) {
100
+ activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNextItem).call(this, currActiveChildIndex, navigableChidren);
101
+ }
102
+ else if (focusOption === Model_1.FocusOption.PREVIOUS_ITEM) {
103
+ activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getPreviousItem).call(this, currActiveChildIndex, navigableChidren);
104
+ }
105
+ if (activeChild !== null) {
106
+ __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, activeChild);
111
107
  }
112
108
  }
113
109
  getState() {
@@ -160,7 +156,25 @@ class Form extends Container_1.default {
160
156
  field.subscribe((action) => {
161
157
  const field = action.target.getState();
162
158
  if (field) {
163
- const fieldChangedAction = new Events_1.FieldChanged(action.payload.changes, field);
159
+ const shallowClone = (obj) => {
160
+ if (obj && typeof obj === 'object') {
161
+ if (Array.isArray(obj)) {
162
+ return obj.map(shallowClone);
163
+ }
164
+ else {
165
+ return Object.assign({}, obj);
166
+ }
167
+ }
168
+ return obj;
169
+ };
170
+ const changes = action.payload.changes.map(({ propertyName, currentValue, prevValue }) => {
171
+ return {
172
+ propertyName,
173
+ currentValue: shallowClone(currentValue),
174
+ prevValue: shallowClone(prevValue)
175
+ };
176
+ });
177
+ const fieldChangedAction = new Events_1.FieldChanged(changes, field);
164
178
  this.dispatch(fieldChangedAction);
165
179
  }
166
180
  });
@@ -244,6 +258,7 @@ _Form_instances = new WeakSet(), _Form_getNavigableChildren = function _Form_get
244
258
  parent.activeChild = currentField;
245
259
  return;
246
260
  }
261
+ __classPrivateFieldGet(this, _Form_instances, "m", _Form_clearCurrentFocus).call(this, currentField);
247
262
  let currentActiveChild = currentField.activeChild;
248
263
  currentActiveChild = (currentActiveChild === null) ? __classPrivateFieldGet(this, _Form_instances, "m", _Form_getFirstNavigableChild).call(this, currentField) : currentField.activeChild;
249
264
  __classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, currentActiveChild);
@@ -257,5 +272,10 @@ _Form_instances = new WeakSet(), _Form_getNavigableChildren = function _Form_get
257
272
  return navigableChidren[currIndex - 1];
258
273
  }
259
274
  return null;
275
+ }, _Form_clearCurrentFocus = function _Form_clearCurrentFocus(field) {
276
+ const parent = field.parent;
277
+ if (parent != null && parent.activeChild != null) {
278
+ parent.activeChild = null;
279
+ }
260
280
  };
261
281
  exports.default = Form;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.66",
3
+ "version": "0.22.68",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.66"
38
+ "@aemforms/af-formatters": "^0.22.68"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",