@aemforms/af-core 0.17.0 → 0.22.0

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/lib/BaseNode.d.ts CHANGED
@@ -70,11 +70,11 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
70
70
  /**
71
71
  * @private
72
72
  */
73
- addDependent(action: Action): void;
73
+ _addDependent(dependent: BaseModel): void;
74
74
  /**
75
75
  * @private
76
76
  */
77
- removeDependent(action: Action): void;
77
+ removeDependent(dependent: BaseModel): void;
78
78
  abstract validate(): Array<ValidationError>;
79
79
  abstract executeAction(action: Action): any;
80
80
  /**
@@ -95,7 +95,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
95
95
  /**
96
96
  * @private
97
97
  */
98
- _bindToDataModel(contextualDataModel?: DataGroup): void;
98
+ _bindToDataModel(contextualDataModel: DataGroup): void;
99
99
  private _data?;
100
100
  /**
101
101
  * @private
@@ -109,6 +109,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
109
109
  });
110
110
  abstract defaultDataModel(name: string | number): DataValue | undefined;
111
111
  abstract importData(a: DataGroup): any;
112
+ getNonTransparentParent(): ContainerModel;
112
113
  /**
113
114
  * called after the node is inserted in the parent
114
115
  * @private
package/lib/BaseNode.js CHANGED
@@ -189,11 +189,11 @@ class BaseNode {
189
189
  * Transparent form fields are meant only for creation of view. They are also not part of data
190
190
  */
191
191
  isTransparent() {
192
- var _a, _b;
192
+ var _a;
193
193
  // named form fields are not transparent
194
194
  // @ts-ignore
195
- // handling repeatable use-case where first item of array can be unnamed
196
- const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array' && ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.items.length) === 1;
195
+ // handling array use-case as items of array can be unnamed
196
+ const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array';
197
197
  return !this._jsonModel.name && !isNonTransparent;
198
198
  }
199
199
  getState() {
@@ -216,8 +216,8 @@ class BaseNode {
216
216
  /**
217
217
  * @private
218
218
  */
219
- addDependent(action) {
220
- if (this._dependents.find(({ node }) => node === action.payload) === undefined) {
219
+ _addDependent(dependent) {
220
+ if (this._dependents.find(({ node }) => node === dependent) === undefined) {
221
221
  const subscription = this.subscribe((change) => {
222
222
  const changes = change.payload.changes;
223
223
  const propsToLook = ['value', 'items'];
@@ -226,17 +226,17 @@ class BaseNode {
226
226
  return propsToLook.indexOf(x.propertyName) > -1;
227
227
  }) > -1;
228
228
  if (isPropChanged) {
229
- action.payload.dispatch(new controller_1.ExecuteRule());
229
+ dependent.dispatch(new controller_1.ExecuteRule());
230
230
  }
231
231
  });
232
- this._dependents.push({ node: action.payload, subscription });
232
+ this._dependents.push({ node: dependent, subscription });
233
233
  }
234
234
  }
235
235
  /**
236
236
  * @private
237
237
  */
238
- removeDependent(action) {
239
- const index = this._dependents.findIndex(({ node }) => node === action.payload);
238
+ removeDependent(dependent) {
239
+ const index = this._dependents.findIndex(({ node }) => node === dependent);
240
240
  if (index > -1) {
241
241
  this._dependents[index].subscription.unsubscribe();
242
242
  this._dependents.splice(index, 1);
@@ -300,10 +300,10 @@ class BaseNode {
300
300
  }
301
301
  const dataRef = this._jsonModel.dataRef;
302
302
  let _data;
303
- if (dataRef === null) {
303
+ if (dataRef === null) { // null data binding
304
304
  _data = EmptyDataValue_1.default;
305
305
  }
306
- else if (dataRef !== undefined) {
306
+ else if (dataRef !== undefined) { // explicit data binding
307
307
  if (this._tokens.length === 0) {
308
308
  this._tokens = (0, DataRefParser_1.tokenize)(dataRef);
309
309
  }
@@ -317,35 +317,38 @@ class BaseNode {
317
317
  _data = (0, DataRefParser_1.resolveData)(searchData, this._tokens, create);
318
318
  }
319
319
  }
320
- else {
321
- if (contextualDataModel != null) {
320
+ else { // name data binding
321
+ if ( //@ts-ignore
322
+ contextualDataModel !== EmptyDataValue_1.default) {
322
323
  const name = this._jsonModel.name || '';
323
324
  const key = contextualDataModel.$type === 'array' ? this.index : name;
324
325
  if (key !== '') {
325
326
  const create = this.defaultDataModel(key);
326
327
  if (create !== undefined) {
327
- _data = contextualDataModel.$getDataNode(key) || create;
328
- contextualDataModel.$addDataNode(key, _data);
328
+ _data = contextualDataModel.$getDataNode(key);
329
+ if (_data === undefined) {
330
+ _data = create;
331
+ contextualDataModel.$addDataNode(key, _data);
332
+ }
329
333
  }
330
334
  }
331
335
  else {
332
- _data = EmptyDataValue_1.default;
336
+ _data = undefined;
333
337
  }
334
338
  }
335
339
  }
336
- if (!this.isContainer) {
337
- _data = _data === null || _data === void 0 ? void 0 : _data.$convertToDataValue();
340
+ if (_data) {
341
+ if (!this.isContainer) {
342
+ _data = _data === null || _data === void 0 ? void 0 : _data.$convertToDataValue();
343
+ }
344
+ _data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
345
+ this._data = _data;
338
346
  }
339
- _data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
340
- this._data = _data;
341
347
  }
342
348
  /**
343
349
  * @private
344
350
  */
345
351
  getDataNode() {
346
- if (this._data === undefined) {
347
- return this.parent.getDataNode();
348
- }
349
352
  return this._data;
350
353
  }
351
354
  get properties() {
@@ -354,13 +357,25 @@ class BaseNode {
354
357
  set properties(p) {
355
358
  this._setProperty('properties', Object.assign({}, p));
356
359
  }
360
+ getNonTransparentParent() {
361
+ let nonTransparentParent = this.parent;
362
+ while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
363
+ nonTransparentParent = nonTransparentParent.parent;
364
+ }
365
+ return nonTransparentParent;
366
+ }
357
367
  /**
358
368
  * called after the node is inserted in the parent
359
369
  * @private
360
370
  */
361
371
  _initialize() {
362
372
  if (typeof this._data === 'undefined') {
363
- const dataNode = this.parent.getDataNode();
373
+ let dataNode, parent = this.parent;
374
+ do {
375
+ //@ts-ignore
376
+ dataNode = parent.getDataNode();
377
+ parent = parent.parent;
378
+ } while (dataNode === undefined);
364
379
  this._bindToDataModel(dataNode);
365
380
  }
366
381
  }
package/lib/Checkbox.js CHANGED
@@ -17,7 +17,7 @@ const ValidationUtils_1 = require("./utils/ValidationUtils");
17
17
  * @private
18
18
  */
19
19
  const requiredConstraint = (offValue) => (constraint, value) => {
20
- const valid = ValidationUtils_1.Constraints.required(constraint, value) && (!constraint || value != offValue);
20
+ const valid = ValidationUtils_1.Constraints.required(constraint, value).valid && (!constraint || value != offValue);
21
21
  return { valid, value };
22
22
  };
23
23
  /**
@@ -323,7 +323,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
323
323
  /**
324
324
  * @private
325
325
  */
326
- importData(contextualDataModel?: DataGroup): void;
326
+ importData(contextualDataModel: DataGroup): void;
327
327
  /**
328
328
  * prefill the form with data on the given element
329
329
  * @param dataModel
package/lib/Container.js CHANGED
@@ -103,22 +103,19 @@ class Container extends Scriptable_1.default {
103
103
  nonTransparentParent = nonTransparentParent.parent;
104
104
  }
105
105
  if (typeof index !== 'number' || index > nonTransparentParent._children.length) {
106
- index = nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.length;
106
+ index = this._children.length;
107
107
  }
108
108
  const itemTemplate = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson));
109
109
  //@ts-ignore
110
- const retVal = this._createChild(itemTemplate, { parent: nonTransparentParent, index: index });
110
+ const retVal = this._createChild(itemTemplate, { parent: this, index });
111
111
  this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
112
- if (index === (nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.length)) {
113
- nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.push(retVal);
114
- //(this.getDataNode() as DataGroup).$addDataNode(index);
112
+ if (index === this._children.length) {
113
+ this._children.push(retVal);
115
114
  }
116
115
  else {
117
116
  // @ts-ignore
118
- nonTransparentParent === null || nonTransparentParent === void 0 ? void 0 : nonTransparentParent._children.splice(index, 0, retVal);
119
- //(this.getDataNode() as DataGroup).$addDataNode();
117
+ this._children.splice(index, 0, retVal);
120
118
  }
121
- retVal._initialize();
122
119
  return retVal;
123
120
  }
124
121
  indexOf(f) {
@@ -158,12 +155,14 @@ class Container extends Scriptable_1.default {
158
155
  }
159
156
  for (let i = 0; i < this._jsonModel.initialItems; i++) {
160
157
  //@ts-ignore
161
- this._addChild(this._itemTemplate);
158
+ const child = this._addChild(this._itemTemplate);
159
+ child._initialize();
162
160
  }
163
161
  }
164
162
  else if (items.length > 0) {
165
163
  items.forEach((item) => {
166
- this._addChild(item);
164
+ const child = this._addChild(item);
165
+ child._initialize();
167
166
  });
168
167
  this._jsonModel.minItems = this._children.length;
169
168
  this._jsonModel.maxItems = this._children.length;
@@ -178,7 +177,17 @@ class Container extends Scriptable_1.default {
178
177
  if (action.type === 'addItem' && this._itemTemplate != null) {
179
178
  //@ts-ignore
180
179
  if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
180
+ const dataNode = this.getDataNode();
181
+ let index = action.payload;
182
+ if (typeof index !== 'number' || index > this._children.length) {
183
+ index = this._children.length;
184
+ }
181
185
  const retVal = this._addChild(this._itemTemplate, action.payload);
186
+ const _data = retVal.defaultDataModel(index);
187
+ if (_data) {
188
+ dataNode.$addDataNode(index, _data);
189
+ }
190
+ retVal._initialize();
182
191
  this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState, null));
183
192
  retVal.dispatch(new controller_1.Initialize());
184
193
  retVal.dispatch(new controller_1.ExecuteRule());
@@ -241,7 +250,8 @@ class Container extends Scriptable_1.default {
241
250
  */
242
251
  importData(contextualDataModel) {
243
252
  this._bindToDataModel(contextualDataModel);
244
- this.syncDataAndFormModel(this.getDataNode());
253
+ const dataNode = this.getDataNode() || contextualDataModel;
254
+ this.syncDataAndFormModel(dataNode);
245
255
  }
246
256
  /**
247
257
  * prefill the form with data on the given element
@@ -262,7 +272,8 @@ class Container extends Scriptable_1.default {
262
272
  const items2Remove = Math.min(itemsLength - dataLength, itemsLength - minItems);
263
273
  while (items2Add > 0) {
264
274
  items2Add--;
265
- this._addChild(this._itemTemplate);
275
+ const child = this._addChild(this._itemTemplate);
276
+ child._initialize();
266
277
  }
267
278
  if (items2Remove > 0) {
268
279
  this._children.splice(dataLength, items2Remove);
@@ -37,6 +37,6 @@ declare class FileUpload extends Field implements FieldModel {
37
37
  set value(value: any);
38
38
  private _serialize;
39
39
  private coerce;
40
- importData(dataModel?: DataGroup): void;
40
+ importData(dataModel: DataGroup): void;
41
41
  }
42
42
  export default FileUpload;
package/lib/Scriptable.js CHANGED
@@ -116,10 +116,10 @@ class Scriptable extends BaseNode_1.BaseNode {
116
116
  }
117
117
  }
118
118
  getExpressionScope() {
119
- var _a;
119
+ const parent = this.getNonTransparentParent();
120
120
  const target = {
121
121
  self: this.getRuleNode(),
122
- siblings: ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.ruleNodeReference()) || {}
122
+ siblings: (parent === null || parent === void 0 ? void 0 : parent.ruleNodeReference()) || {}
123
123
  };
124
124
  const scope = new Proxy(target, {
125
125
  get: (target, prop) => {
@@ -11,6 +11,7 @@ import { Logger } from '../Form';
11
11
  */
12
12
  declare class EventQueue {
13
13
  private logger;
14
+ static readonly MAX_EVENT_CYCLE_COUNT = 10;
14
15
  private _runningEventCount;
15
16
  private _isProcessing;
16
17
  private _pendingEvents;
@@ -66,7 +66,7 @@ class EventQueue {
66
66
  const evntNode = new EventNode(node, e);
67
67
  const counter = this._runningEventCount[evntNode.valueOf()] || 0;
68
68
  const alreadyExists = this.isQueued(node, e);
69
- if (!alreadyExists || counter < 10) {
69
+ if (!alreadyExists || counter < EventQueue.MAX_EVENT_CYCLE_COUNT) {
70
70
  this.logger.info(`Queued event : ${e.type} node: ${node.id} - ${node.name}`);
71
71
  //console.log(`Event Details ${e.toString()}`)
72
72
  if (priority) {
@@ -78,6 +78,9 @@ class EventQueue {
78
78
  }
79
79
  this._runningEventCount[evntNode.valueOf()] = counter + 1;
80
80
  }
81
+ else {
82
+ this.logger.info(`Skipped queueing event : ${e.type} node: ${node.id} - ${node.name} with count=${counter}`);
83
+ }
81
84
  });
82
85
  }
83
86
  runPendingQueue() {
@@ -96,4 +99,5 @@ class EventQueue {
96
99
  this._isProcessing = false;
97
100
  }
98
101
  }
102
+ EventQueue.MAX_EVENT_CYCLE_COUNT = 10;
99
103
  exports.default = EventQueue;
@@ -7,11 +7,12 @@ import DataValue from './DataValue';
7
7
  */
8
8
  export default class DataGroup extends DataValue {
9
9
  $_items: {
10
- [key: string | number]: DataValue | DataGroup;
11
- };
10
+ [key: string]: DataValue | DataGroup;
11
+ } | DataValue[] | DataGroup[];
12
+ private createEntry;
12
13
  constructor(_name: string | number, _value: {
13
- [key: string | number]: any;
14
- }, _type?: string);
14
+ [key: string]: any;
15
+ } | any[], _type?: string);
15
16
  get $value(): Array<any> | {
16
17
  [key: string]: any;
17
18
  };
@@ -19,7 +20,7 @@ export default class DataGroup extends DataValue {
19
20
  $convertToDataValue(): DataValue;
20
21
  $addDataNode(name: string | number, value: DataGroup | DataValue): void;
21
22
  $removeDataNode(name: string | number): void;
22
- $getDataNode(name: string | number): DataValue | undefined;
23
+ $getDataNode(name: string | number): any;
23
24
  $containsDataNode(name: string | number): boolean;
24
25
  get $isDataGroup(): boolean;
25
26
  }
@@ -21,18 +21,25 @@ const EmptyDataValue_1 = __importDefault(require("./EmptyDataValue"));
21
21
  class DataGroup extends DataValue_1.default {
22
22
  constructor(_name, _value, _type = typeof _value) {
23
23
  super(_name, _value, _type);
24
- this.$_items = {};
25
- Object.entries(_value).forEach(([key, value]) => {
26
- let x;
27
- const t = value instanceof Array ? 'array' : typeof value;
28
- if (typeof value === 'object' && value != null) {
29
- x = new DataGroup(key, value, t);
30
- }
31
- else {
32
- x = new DataValue_1.default(key, value, t);
33
- }
34
- this.$_items[key] = x;
35
- });
24
+ if (_value instanceof Array) {
25
+ this.$_items = _value.map((value, index) => {
26
+ return this.createEntry(index, value);
27
+ });
28
+ }
29
+ else {
30
+ this.$_items = Object.fromEntries(Object.entries(_value).map(([key, value]) => {
31
+ return [key, this.createEntry(key, value)];
32
+ }));
33
+ }
34
+ }
35
+ createEntry(key, value) {
36
+ const t = value instanceof Array ? 'array' : typeof value;
37
+ if (typeof value === 'object' && value != null) {
38
+ return new DataGroup(key, value, t);
39
+ }
40
+ else {
41
+ return new DataValue_1.default(key, value, t);
42
+ }
36
43
  }
37
44
  get $value() {
38
45
  if (this.$type === 'array') {
@@ -52,7 +59,13 @@ class DataGroup extends DataValue_1.default {
52
59
  }
53
60
  $addDataNode(name, value) {
54
61
  if (value !== EmptyDataValue_1.default) {
55
- this.$_items[name] = value;
62
+ if (this.$type === 'array') {
63
+ const index = name;
64
+ this.$_items.splice(index, 0, value);
65
+ }
66
+ else {
67
+ this.$_items[name] = value;
68
+ }
56
69
  }
57
70
  }
58
71
  $removeDataNode(name) {
@@ -10,21 +10,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- const Controller_1 = require("../controller/Controller");
14
13
  const json_formula_1 = require("@adobe/json-formula");
15
14
  const FunctionRuntime_1 = __importDefault(require("./FunctionRuntime"));
16
- /**
17
- * Implementation of AddDependant event
18
- * @private
19
- */
20
- class AddDependent extends Controller_1.ActionImpl {
21
- constructor(payload) {
22
- super(payload, 'addDependent');
23
- }
24
- payloadToJson() {
25
- return this.payload.getState();
26
- }
27
- }
28
15
  /**
29
16
  * Implementation of rule engine
30
17
  * @private
@@ -60,7 +47,7 @@ class RuleEngine {
60
47
  */
61
48
  trackDependency(subscriber) {
62
49
  if (this._context && this._context.field !== undefined && this._context.field !== subscriber) {
63
- subscriber.dispatch(new AddDependent(this._context.field));
50
+ subscriber._addDependent(this._context.field);
64
51
  }
65
52
  }
66
53
  }
package/lib/types/Json.js CHANGED
@@ -9,7 +9,7 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.constraintProps = exports.translationProps = void 0;
11
11
  /** Constant for all properties which can be translated based on `adaptive form specification` */
12
- exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames'];
12
+ exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value'];
13
13
  /** Constant for all properties which are constraints based on `adaptive form specification` */
14
14
  exports.constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
15
15
  'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
@@ -208,6 +208,10 @@ export interface BaseModel extends ConstraintsJson, WithController {
208
208
  * @private
209
209
  */
210
210
  _initialize(): any;
211
+ /**
212
+ * @private
213
+ */
214
+ _addDependent(dependent: BaseModel): any;
211
215
  }
212
216
  /**
213
217
  * Generic field model interface.
@@ -255,6 +259,7 @@ export interface ContainerModel extends BaseModel, ScriptableField {
255
259
  * @returns `index` of the item
256
260
  */
257
261
  indexOf(f: FieldModel | FieldsetModel): number;
262
+ isTransparent(): boolean;
258
263
  }
259
264
  /**
260
265
  * Generic field set model interface.
@@ -16,6 +16,13 @@ export declare const invalidateTranslation: (input: formElementJson, updates: an
16
16
  * @private
17
17
  */
18
18
  export declare const addTranslationId: (input: formElementJson, additionalTranslationProps?: string[]) => formElementJson;
19
+ /**
20
+ * Gets the value for the given key from the input, in case of no value, default is returned
21
+ * @param input input object
22
+ * @param key key to return from input object (key could be comma separated, example, label.value)
23
+ * @param defaultValue default value
24
+ */
25
+ export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
19
26
  /**
20
27
  * @param input
21
28
  * @param additionalTranslationProps
@@ -7,7 +7,7 @@
7
7
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.createTranslationObject = exports.createTranslationObj = exports.addTranslationId = exports.invalidateTranslation = exports.CUSTOM_PROPS_KEY = exports.TRANSLATION_ID = exports.TRANSLATION_TOKEN = void 0;
10
+ exports.createTranslationObject = exports.createTranslationObj = exports.getOrElse = exports.addTranslationId = exports.invalidateTranslation = exports.CUSTOM_PROPS_KEY = exports.TRANSLATION_ID = exports.TRANSLATION_TOKEN = void 0;
11
11
  /**
12
12
  * Defines generic utilities to translated form model definition
13
13
  */
@@ -63,11 +63,12 @@ const _createTranslationId = (input, path, transProps) => {
63
63
  }
64
64
  else {
65
65
  // set it only if either of type or fieldType properties is present
66
- if ('type' in input ||
66
+ if (':type' in input ||
67
+ 'type' in input ||
67
68
  'fieldType' in input) {
68
69
  for (const transProp of transProps) {
69
70
  // if property exist add it
70
- if (input[transProp] != null) {
71
+ if ((0, exports.getOrElse)(input, transProp) != null) {
71
72
  // if translation id is not yet set, set it
72
73
  if (!(exports.CUSTOM_PROPS_KEY in input)) {
73
74
  input[exports.CUSTOM_PROPS_KEY] = {};
@@ -100,10 +101,11 @@ const _createTranslationObj = (input, translationObj, translationProps) => {
100
101
  }
101
102
  else {
102
103
  for (const translationProp of translationProps) {
103
- if (translationProp in input && ((_b = (_a = input === null || input === void 0 ? void 0 : input[exports.CUSTOM_PROPS_KEY]) === null || _a === void 0 ? void 0 : _a[exports.TRANSLATION_ID]) === null || _b === void 0 ? void 0 : _b[translationProp])) {
104
+ const objValue = (0, exports.getOrElse)(input, translationProp);
105
+ if (objValue && ((_b = (_a = input === null || input === void 0 ? void 0 : input[exports.CUSTOM_PROPS_KEY]) === null || _a === void 0 ? void 0 : _a[exports.TRANSLATION_ID]) === null || _b === void 0 ? void 0 : _b[translationProp])) {
104
106
  // todo: right now we create only for english
105
- if (input[translationProp] instanceof Array) {
106
- input[translationProp].forEach((item, index) => {
107
+ if (objValue instanceof Array) {
108
+ objValue.forEach((item, index) => {
107
109
  if (typeof item === 'string') { // only if string, then convert, since values can also be boolean
108
110
  // @ts-ignore
109
111
  translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}${exports.TRANSLATION_TOKEN}${index}`] = item;
@@ -112,13 +114,32 @@ const _createTranslationObj = (input, translationObj, translationProps) => {
112
114
  }
113
115
  else {
114
116
  // @ts-ignore
115
- translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}`] = input[translationProp];
117
+ translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}`] = objValue;
116
118
  }
117
119
  }
118
120
  }
119
121
  }
120
122
  });
121
123
  };
124
+ /**
125
+ * Gets the value for the given key from the input, in case of no value, default is returned
126
+ * @param input input object
127
+ * @param key key to return from input object (key could be comma separated, example, label.value)
128
+ * @param defaultValue default value
129
+ */
130
+ const getOrElse = (input, key, defaultValue = null) => {
131
+ if (!key) {
132
+ return defaultValue;
133
+ }
134
+ const arr = Array.isArray(key) ? key : key.split('.');
135
+ let objValue = input, index = 0;
136
+ while (index < arr.length && objValue.hasOwnProperty(arr[index])) {
137
+ objValue = objValue[arr[index]];
138
+ index++;
139
+ }
140
+ return index == arr.length ? objValue : defaultValue;
141
+ };
142
+ exports.getOrElse = getOrElse;
122
143
  /**
123
144
  * @param input
124
145
  * @param additionalTranslationProps
@@ -143,7 +164,7 @@ const createTranslationObject = (input, additionalTranslationProps = [], bcp47La
143
164
  const transProps = [...types_1.translationProps, ...additionalTranslationProps];
144
165
  // create a copy of the input
145
166
  const inputCopy = JSON.parse(JSON.stringify(input));
146
- const obj = (0, exports.createTranslationObj)((0, exports.addTranslationId)(inputCopy), transProps);
167
+ const obj = (0, exports.createTranslationObj)((0, exports.addTranslationId)(inputCopy, additionalTranslationProps), transProps);
147
168
  const langTags = [...defaultBcp47LangTags, ...bcp47LangTags];
148
169
  const allLangs = {};
149
170
  for (const langTag of langTags) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.17.0",
3
+ "version": "0.22.0",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",