@aemforms/af-core 0.22.26 → 0.22.30

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 (54) hide show
  1. package/lib/cjs/index.cjs +345 -1886
  2. package/lib/esm/BaseNode-d78cc1b0.js +478 -0
  3. package/lib/esm/BaseNode.d.ts +1 -1
  4. package/lib/esm/BaseNode.js +26 -454
  5. package/lib/esm/Checkbox.js +37 -1
  6. package/lib/esm/CheckboxGroup.js +38 -1
  7. package/lib/esm/Container.d.ts +6 -1
  8. package/lib/esm/Container.js +108 -19
  9. package/lib/esm/DateField.js +38 -2
  10. package/lib/esm/Field.d.ts +2 -2
  11. package/lib/esm/Field.js +62 -26
  12. package/lib/esm/Fieldset.js +36 -3
  13. package/lib/esm/FileObject.js +23 -1
  14. package/lib/esm/FileUpload.js +34 -1
  15. package/lib/esm/Form.d.ts +1 -1
  16. package/lib/esm/Form.js +40 -8
  17. package/lib/esm/FormInstance.js +53 -5
  18. package/lib/esm/FormMetaData.js +26 -1
  19. package/lib/esm/InstanceManager.js +35 -8
  20. package/lib/esm/Node.js +25 -1
  21. package/lib/esm/Scriptable.js +29 -2
  22. package/lib/esm/controller/EventQueue.js +23 -1
  23. package/lib/esm/controller/Events.d.ts +1 -1
  24. package/lib/esm/controller/Events.js +41 -19
  25. package/lib/esm/controller/Logger.d.ts +2 -2
  26. package/lib/esm/controller/Logger.js +23 -1
  27. package/lib/esm/data/DataGroup.js +24 -1
  28. package/lib/esm/data/DataValue.js +23 -1
  29. package/lib/esm/data/EmptyDataValue.js +23 -1
  30. package/lib/esm/index.js +55 -21
  31. package/lib/esm/rules/FunctionRuntime.d.ts +3 -3
  32. package/lib/esm/rules/FunctionRuntime.js +31 -6
  33. package/lib/esm/rules/RuleEngine.js +30 -1
  34. package/lib/esm/types/Json.d.ts +16 -16
  35. package/lib/esm/types/Json.js +24 -2
  36. package/lib/esm/types/Model.d.ts +4 -4
  37. package/lib/esm/types/Model.js +23 -1
  38. package/lib/esm/types/index.js +22 -2
  39. package/lib/esm/utils/DataRefParser.d.ts +2 -2
  40. package/lib/esm/utils/DataRefParser.js +31 -6
  41. package/lib/esm/utils/Fetch.d.ts +1 -1
  42. package/lib/esm/utils/Fetch.js +24 -2
  43. package/lib/esm/utils/FormCreationUtils.js +40 -2
  44. package/lib/esm/utils/FormUtils.js +33 -8
  45. package/lib/esm/utils/JsonUtils.js +34 -11
  46. package/lib/esm/utils/LogUtils.js +23 -1
  47. package/lib/esm/utils/SchemaUtils.js +24 -2
  48. package/lib/esm/utils/TranslationUtils.d.ts +1 -1
  49. package/lib/esm/utils/TranslationUtils.js +32 -9
  50. package/lib/esm/utils/ValidationUtils.d.ts +4 -4
  51. package/lib/esm/utils/ValidationUtils.js +30 -4
  52. package/package.json +14 -2
  53. package/lib/browser/afb-events.js +0 -151
  54. package/lib/browser/afb-runtime.js +0 -3620
@@ -0,0 +1,478 @@
1
+ /*************************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * ___________________
4
+ *
5
+ * Copyright 2022 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+
17
+ * Adobe permits you to use and modify this file solely in accordance with
18
+ * the terms of the Adobe license agreement accompanying it.
19
+ *************************************************************************/
20
+
21
+ import { propertyChange, ExecuteRule } from './controller/Events.js';
22
+ import { tokenize, TOK_GLOBAL, resolveData } from './utils/DataRefParser.js';
23
+ import NullDataValue from './data/EmptyDataValue.js';
24
+
25
+ function __decorate(decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ }
31
+
32
+ const editableProperties = [
33
+ 'value',
34
+ 'label',
35
+ 'description',
36
+ 'visible',
37
+ 'enabled',
38
+ 'readOnly',
39
+ 'enum',
40
+ 'enumNames',
41
+ 'required',
42
+ 'properties',
43
+ 'exclusiveMinimum',
44
+ 'exclusiveMaximum',
45
+ 'maximum',
46
+ 'maxItems',
47
+ 'minimum',
48
+ 'minItems'
49
+ ];
50
+ const dynamicProps = [
51
+ ...editableProperties,
52
+ 'valid',
53
+ 'index',
54
+ 'activeChild'
55
+ ];
56
+ const staticFields = ['plain-text', 'image'];
57
+ class ActionImplWithTarget {
58
+ _action;
59
+ _target;
60
+ constructor(_action, _target) {
61
+ this._action = _action;
62
+ this._target = _target;
63
+ }
64
+ get type() {
65
+ return this._action.type;
66
+ }
67
+ get payload() {
68
+ return this._action.payload;
69
+ }
70
+ get metadata() {
71
+ return this._action.metadata;
72
+ }
73
+ get target() {
74
+ return this._target;
75
+ }
76
+ get isCustomEvent() {
77
+ return this._action.isCustomEvent;
78
+ }
79
+ get originalAction() {
80
+ return this._action.originalAction;
81
+ }
82
+ toString() {
83
+ return this._action.toString();
84
+ }
85
+ }
86
+ const target = Symbol('target');
87
+ const qualifiedName = Symbol('qualifiedName');
88
+ function dependencyTracked() {
89
+ return function (target, propertyKey, descriptor) {
90
+ const get = descriptor.get;
91
+ if (get != undefined) {
92
+ descriptor.get = function () {
93
+ this.ruleEngine.trackDependency(this);
94
+ return get.call(this);
95
+ };
96
+ }
97
+ };
98
+ }
99
+ const addOnly = (includeOrExclude) => (...fieldTypes) => (target, propertyKey, descriptor) => {
100
+ const get = descriptor.get;
101
+ if (get != undefined) {
102
+ descriptor.get = function () {
103
+ if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
104
+ return get.call(this);
105
+ }
106
+ return undefined;
107
+ };
108
+ }
109
+ const set = descriptor.set;
110
+ if (set != undefined) {
111
+ descriptor.set = function (value) {
112
+ if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
113
+ set.call(this, value);
114
+ }
115
+ };
116
+ }
117
+ };
118
+ const include = addOnly(true);
119
+ const exclude = addOnly(false);
120
+ class BaseNode {
121
+ _options;
122
+ _ruleNode;
123
+ _lang = '';
124
+ _callbacks = {};
125
+ _dependents = [];
126
+ _jsonModel;
127
+ _tokens = [];
128
+ get isContainer() {
129
+ return false;
130
+ }
131
+ constructor(params, _options) {
132
+ this._options = _options;
133
+ this[qualifiedName] = null;
134
+ this._jsonModel = {
135
+ ...params,
136
+ id: 'id' in params ? params.id : this.form.getUniqueId()
137
+ };
138
+ }
139
+ setupRuleNode() {
140
+ const self = this;
141
+ this._ruleNode = new Proxy(this.ruleNodeReference(), {
142
+ get: (ruleNodeReference, prop) => {
143
+ return self.getFromRule(ruleNodeReference, prop);
144
+ }
145
+ });
146
+ }
147
+ ruleNodeReference() {
148
+ return this;
149
+ }
150
+ getRuleNode() {
151
+ return this._ruleNode;
152
+ }
153
+ getFromRule(ruleNodeReference, prop) {
154
+ if (prop === Symbol.toPrimitive || (prop === 'valueOf' && !ruleNodeReference.hasOwnProperty('valueOf'))) {
155
+ return this.valueOf;
156
+ }
157
+ else if (prop === target) {
158
+ return this;
159
+ }
160
+ else if (typeof (prop) === 'string') {
161
+ if (prop.startsWith('$')) {
162
+ prop = prop.substr(1);
163
+ if (typeof this[prop] !== 'function') {
164
+ const retValue = this[prop];
165
+ if (retValue instanceof BaseNode) {
166
+ return retValue.getRuleNode();
167
+ }
168
+ else if (retValue instanceof Array) {
169
+ return retValue.map(r => r instanceof BaseNode ? r.getRuleNode() : r);
170
+ }
171
+ else {
172
+ return retValue;
173
+ }
174
+ }
175
+ }
176
+ else {
177
+ if (ruleNodeReference.hasOwnProperty(prop)) {
178
+ return ruleNodeReference[prop];
179
+ }
180
+ else if (typeof ruleNodeReference[prop] === 'function') {
181
+ return ruleNodeReference[prop];
182
+ }
183
+ }
184
+ }
185
+ }
186
+ get id() {
187
+ return this._jsonModel.id;
188
+ }
189
+ get index() {
190
+ if (this.parent) {
191
+ return this.parent.indexOf(this);
192
+ }
193
+ return 0;
194
+ }
195
+ get parent() {
196
+ return this._options.parent;
197
+ }
198
+ get type() {
199
+ return this._jsonModel.type;
200
+ }
201
+ get repeatable() {
202
+ return this.parent?.hasDynamicItems();
203
+ }
204
+ get fieldType() {
205
+ return this._jsonModel.fieldType || 'text-input';
206
+ }
207
+ get ':type'() {
208
+ return this._jsonModel[':type'] || this.fieldType;
209
+ }
210
+ get name() {
211
+ return this._jsonModel.name;
212
+ }
213
+ get description() {
214
+ return this._jsonModel.description;
215
+ }
216
+ set description(d) {
217
+ this._setProperty('description', d);
218
+ }
219
+ get dataRef() {
220
+ return this._jsonModel.dataRef;
221
+ }
222
+ get visible() {
223
+ return this._jsonModel.visible;
224
+ }
225
+ set visible(v) {
226
+ if (v !== this._jsonModel.visible) {
227
+ const changeAction = propertyChange('visible', v, this._jsonModel.visible);
228
+ this._jsonModel.visible = v;
229
+ this.notifyDependents(changeAction);
230
+ }
231
+ }
232
+ get form() {
233
+ return this._options.form;
234
+ }
235
+ get ruleEngine() {
236
+ return this.form.ruleEngine;
237
+ }
238
+ get label() {
239
+ return this._jsonModel.label;
240
+ }
241
+ set label(l) {
242
+ if (l !== this._jsonModel.label) {
243
+ const changeAction = propertyChange('label', l, this._jsonModel.label);
244
+ this._jsonModel = {
245
+ ...this._jsonModel,
246
+ label: l
247
+ };
248
+ this.notifyDependents(changeAction);
249
+ }
250
+ }
251
+ get uniqueItems() {
252
+ return this._jsonModel.uniqueItems;
253
+ }
254
+ isTransparent() {
255
+ const isNonTransparent = this.parent?._jsonModel.type === 'array';
256
+ return !this._jsonModel.name && !isNonTransparent;
257
+ }
258
+ getState(isRepeatableChild = false) {
259
+ return {
260
+ ...this._jsonModel,
261
+ properties: this.properties,
262
+ index: this.index,
263
+ parent: undefined,
264
+ qualifiedName: this.qualifiedName,
265
+ events: {},
266
+ rules: {},
267
+ repeatable: this.repeatable === true ? true : undefined,
268
+ ':type': this[':type']
269
+ };
270
+ }
271
+ subscribe(callback, eventName = 'change') {
272
+ this._callbacks[eventName] = this._callbacks[eventName] || [];
273
+ this._callbacks[eventName].push(callback);
274
+ return {
275
+ unsubscribe: () => {
276
+ this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
277
+ }
278
+ };
279
+ }
280
+ _addDependent(dependent) {
281
+ if (this._dependents.find(({ node }) => node === dependent) === undefined) {
282
+ const subscription = this.subscribe((change) => {
283
+ const changes = change.payload.changes;
284
+ const propsToLook = [...dynamicProps, 'items'];
285
+ const isPropChanged = changes.findIndex(x => {
286
+ return propsToLook.indexOf(x.propertyName) > -1;
287
+ }) > -1;
288
+ if (isPropChanged) {
289
+ dependent.dispatch(new ExecuteRule());
290
+ }
291
+ });
292
+ this._dependents.push({ node: dependent, subscription });
293
+ }
294
+ }
295
+ removeDependent(dependent) {
296
+ const index = this._dependents.findIndex(({ node }) => node === dependent);
297
+ if (index > -1) {
298
+ this._dependents[index].subscription.unsubscribe();
299
+ this._dependents.splice(index, 1);
300
+ }
301
+ }
302
+ queueEvent(action) {
303
+ const actionWithTarget = new ActionImplWithTarget(action, this);
304
+ this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
305
+ }
306
+ dispatch(action) {
307
+ this.queueEvent(action);
308
+ this.form.getEventQueue().runPendingQueue();
309
+ }
310
+ notifyDependents(action) {
311
+ const handlers = this._callbacks[action.type] || [];
312
+ handlers.forEach(x => {
313
+ x(new ActionImplWithTarget(action, this));
314
+ });
315
+ }
316
+ _setProperty(prop, newValue, notify = true) {
317
+ const oldValue = this._jsonModel[prop];
318
+ let isValueSame = false;
319
+ if (newValue !== null && oldValue !== null &&
320
+ typeof newValue === 'object' && typeof oldValue === 'object') {
321
+ isValueSame = JSON.stringify(newValue) === JSON.stringify(oldValue);
322
+ }
323
+ else {
324
+ isValueSame = oldValue === newValue;
325
+ }
326
+ if (!isValueSame) {
327
+ this._jsonModel[prop] = newValue;
328
+ const changeAction = propertyChange(prop, newValue, oldValue);
329
+ if (notify) {
330
+ this.notifyDependents(changeAction);
331
+ }
332
+ return changeAction.payload.changes;
333
+ }
334
+ return [];
335
+ }
336
+ _bindToDataModel(contextualDataModel) {
337
+ if (this.id === '$form') {
338
+ this._data = contextualDataModel;
339
+ return;
340
+ }
341
+ const dataRef = this._jsonModel.dataRef;
342
+ let _data, _parent = contextualDataModel, _key = '';
343
+ if (dataRef === null) {
344
+ _data = NullDataValue;
345
+ }
346
+ else if (dataRef !== undefined) {
347
+ if (this._tokens.length === 0) {
348
+ this._tokens = tokenize(dataRef);
349
+ }
350
+ let searchData = contextualDataModel;
351
+ if (this._tokens[0].type === TOK_GLOBAL) {
352
+ searchData = this.form.getDataNode();
353
+ }
354
+ if (typeof searchData !== 'undefined') {
355
+ const name = this._tokens[this._tokens.length - 1].value;
356
+ const create = this.defaultDataModel(name);
357
+ _data = resolveData(searchData, this._tokens, create);
358
+ _parent = resolveData(searchData, this._tokens.slice(0, -1));
359
+ _key = name;
360
+ }
361
+ }
362
+ else {
363
+ if (contextualDataModel !== NullDataValue && staticFields.indexOf(this.fieldType) === -1) {
364
+ _parent = contextualDataModel;
365
+ const name = this._jsonModel.name || '';
366
+ const key = contextualDataModel.$type === 'array' ? this.index : name;
367
+ _key = key;
368
+ if (key !== '') {
369
+ const create = this.defaultDataModel(key);
370
+ if (create !== undefined) {
371
+ _data = contextualDataModel.$getDataNode(key);
372
+ if (_data === undefined) {
373
+ _data = create;
374
+ contextualDataModel.$addDataNode(key, _data);
375
+ }
376
+ }
377
+ }
378
+ else {
379
+ _data = undefined;
380
+ }
381
+ }
382
+ }
383
+ if (_data) {
384
+ if (!this.isContainer && _parent !== NullDataValue && _data !== NullDataValue) {
385
+ _data = _data?.$convertToDataValue();
386
+ _parent.$addDataNode(_key, _data, true);
387
+ }
388
+ _data?.$bindToField(this);
389
+ this._data = _data;
390
+ }
391
+ }
392
+ _data;
393
+ getDataNode() {
394
+ return this._data;
395
+ }
396
+ get language() {
397
+ if (!this._lang) {
398
+ if (this.parent) {
399
+ this._lang = this.parent.language;
400
+ }
401
+ else {
402
+ this._lang = Intl.DateTimeFormat().resolvedOptions().locale;
403
+ }
404
+ }
405
+ return this._lang;
406
+ }
407
+ get properties() {
408
+ return this._jsonModel.properties || {};
409
+ }
410
+ set properties(p) {
411
+ this._setProperty('properties', { ...p });
412
+ }
413
+ getNonTransparentParent() {
414
+ let nonTransparentParent = this.parent;
415
+ while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
416
+ nonTransparentParent = nonTransparentParent.parent;
417
+ }
418
+ return nonTransparentParent;
419
+ }
420
+ _initialize() {
421
+ if (typeof this._data === 'undefined') {
422
+ let dataNode, parent = this.parent;
423
+ do {
424
+ dataNode = parent.getDataNode();
425
+ parent = parent.parent;
426
+ } while (dataNode === undefined);
427
+ this._bindToDataModel(dataNode);
428
+ }
429
+ }
430
+ _applyUpdates(propNames, updates) {
431
+ return propNames.reduce((acc, propertyName) => {
432
+ const currentValue = updates[propertyName];
433
+ const changes = this._setProperty(propertyName, currentValue, false);
434
+ if (changes.length > 0) {
435
+ acc[propertyName] = changes[0];
436
+ }
437
+ return acc;
438
+ }, {});
439
+ }
440
+ get qualifiedName() {
441
+ if (this.isTransparent()) {
442
+ return null;
443
+ }
444
+ if (this[qualifiedName] !== null) {
445
+ return this[qualifiedName];
446
+ }
447
+ const parent = this.getNonTransparentParent();
448
+ if (parent && parent.type === 'array') {
449
+ this[qualifiedName] = `${parent.qualifiedName}[${this.index}]`;
450
+ }
451
+ else {
452
+ this[qualifiedName] = `${parent.qualifiedName}.${this.name}`;
453
+ }
454
+ return this[qualifiedName];
455
+ }
456
+ focus() {
457
+ if (this.parent) {
458
+ this.parent.activeChild = this;
459
+ }
460
+ }
461
+ }
462
+ __decorate([
463
+ dependencyTracked()
464
+ ], BaseNode.prototype, "index", null);
465
+ __decorate([
466
+ dependencyTracked()
467
+ ], BaseNode.prototype, "description", null);
468
+ __decorate([
469
+ dependencyTracked()
470
+ ], BaseNode.prototype, "visible", null);
471
+ __decorate([
472
+ dependencyTracked()
473
+ ], BaseNode.prototype, "label", null);
474
+ __decorate([
475
+ dependencyTracked()
476
+ ], BaseNode.prototype, "properties", null);
477
+
478
+ export { BaseNode as B, __decorate as _, editableProperties as a, dynamicProps as b, dependencyTracked as d, exclude as e, include as i, qualifiedName as q, staticFields as s, target as t };
@@ -49,7 +49,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
49
49
  set label(l: import("./types/Json.js").Label | undefined);
50
50
  get uniqueItems(): boolean | undefined;
51
51
  isTransparent(): boolean;
52
- getState(): T & {
52
+ getState(isRepeatableChild?: boolean): T & {
53
53
  properties: {
54
54
  [key: string]: any;
55
55
  };