@aemforms/af-core 0.22.18 → 0.22.20

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 (120) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +11 -68
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +86 -182
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/{Container.js → esm/Container.js} +76 -124
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +44 -98
  15. package/lib/{Field.js → esm/Field.js} +172 -206
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +12 -55
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +10 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
  39. package/lib/{controller → esm/controller}/Logger.js +5 -11
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +20 -35
  42. package/lib/{data → esm/data}/DataValue.d.ts +2 -8
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +44 -114
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/{types → esm/types}/Json.d.ts +6 -22
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
  59. package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -0
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
  76. package/package.json +17 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/Container.d.ts +0 -199
  81. package/lib/DateField.js +0 -35
  82. package/lib/Fieldset.d.ts +0 -34
  83. package/lib/Fieldset.js +0 -113
  84. package/lib/FileObject.js +0 -39
  85. package/lib/FileUpload.js +0 -155
  86. package/lib/Form.d.ts +0 -262
  87. package/lib/Form.js +0 -230
  88. package/lib/FormInstance.d.ts +0 -38
  89. package/lib/FormInstance.js +0 -119
  90. package/lib/FormMetaData.d.ts +0 -11
  91. package/lib/FormMetaData.js +0 -28
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -223
  96. package/lib/controller/Controller.js +0 -287
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -52
  100. package/lib/data/EmptyDataValue.js +0 -46
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -63
  103. package/lib/rules/RuleEngine.d.ts +0 -23
  104. package/lib/rules/RuleEngine.js +0 -62
  105. package/lib/types/Json.js +0 -19
  106. package/lib/types/Model.d.ts +0 -379
  107. package/lib/types/Model.js +0 -20
  108. package/lib/types/index.d.ts +0 -2
  109. package/lib/types/index.js +0 -25
  110. package/lib/utils/Fetch.js +0 -29
  111. package/lib/utils/FormUtils.d.ts +0 -47
  112. package/lib/utils/FormUtils.js +0 -257
  113. package/lib/utils/JsonUtils.d.ts +0 -62
  114. package/lib/utils/JsonUtils.js +0 -143
  115. package/lib/utils/LogUtils.js +0 -17
  116. package/lib/utils/SchemaUtils.d.ts +0 -16
  117. package/lib/utils/SchemaUtils.js +0 -92
  118. package/lib/utils/TranslationUtils.d.ts +0 -41
  119. package/lib/utils/TranslationUtils.js +0 -185
  120. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -1,57 +1,33 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
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
- */
9
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
4
  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;
13
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
6
  };
15
- var __importDefault = (this && this.__importDefault) || function (mod) {
16
- return (mod && mod.__esModule) ? mod : { "default": mod };
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- const types_1 = require("./types");
20
- const ValidationUtils_1 = require("./utils/ValidationUtils");
21
- const controller_1 = require("./controller");
22
- const Scriptable_1 = __importDefault(require("./Scriptable"));
23
- const SchemaUtils_1 = require("./utils/SchemaUtils");
24
- const DataValue_1 = __importDefault(require("./data/DataValue"));
25
- const BaseNode_1 = require("./BaseNode");
26
- const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
27
- const af_formatters_1 = require("@aemforms/af-formatters");
28
- /**
29
- * Defines a form object field which implements {@link FieldModel | field model} interface
30
- */
7
+ import { ValidationError } from './types/index.js';
8
+ import { coerceType, Constraints, ValidConstraints } from './utils/ValidationUtils.js';
9
+ import { Change, ExecuteRule, Initialize, Invalid, propertyChange, Valid } from './controller/Events.js';
10
+ import Scriptable from './Scriptable.js';
11
+ import { defaultFieldTypes } from './utils/SchemaUtils.js';
12
+ import DataValue from './data/DataValue.js';
13
+ import { dependencyTracked, include, exclude, target, staticFields } from './BaseNode.js';
14
+ import NullDataValue from './data/EmptyDataValue.js';
15
+ import { format } from '@aemforms/af-formatters';
31
16
  const validTypes = ['string', 'number', 'boolean', 'file', 'string[]', 'number[]', 'boolean[]', 'file[]', 'array', 'object'];
32
- class Field extends Scriptable_1.default {
33
- /**
34
- * @param params
35
- * @param _options
36
- * @private
37
- */
17
+ class Field extends Scriptable {
38
18
  constructor(params, _options) {
39
19
  super(params, _options);
40
- this._ruleNodeReference = [];
41
20
  this._applyDefaults();
42
- this.queueEvent(new controller_1.Initialize());
43
- this.queueEvent(new controller_1.ExecuteRule());
21
+ this.queueEvent(new Initialize());
22
+ this.queueEvent(new ExecuteRule());
44
23
  }
45
- /**
46
- * @private
47
- */
24
+ _ruleNodeReference = [];
48
25
  _initialize() {
49
26
  super._initialize();
50
27
  this.setupRuleNode();
51
28
  }
52
29
  ruleNodeReference() {
53
- var _a;
54
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
30
+ if (this.type?.endsWith('[]')) {
55
31
  this._ruleNodeReference = [];
56
32
  }
57
33
  else {
@@ -67,17 +43,12 @@ class Field extends Scriptable_1.default {
67
43
  type: this._getFallbackType()
68
44
  };
69
45
  }
70
- /**
71
- * Returns the fallback type to be used for this field, in case type is not defined. Otherwise returns
72
- * undefined
73
- * @protected
74
- */
75
46
  _getFallbackType() {
76
47
  const type = this._jsonModel.type;
77
48
  let finalType = type;
78
49
  if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
79
50
  const _enum = this.enum;
80
- finalType = typeof (_enum === null || _enum === void 0 ? void 0 : _enum[0]);
51
+ finalType = typeof (_enum?.[0]);
81
52
  if (finalType === 'undefined' && typeof this._jsonModel.default !== 'undefined') {
82
53
  if (this._jsonModel.default instanceof Array && this._jsonModel.default.length > 0) {
83
54
  finalType = `${typeof (this._jsonModel.default[0])}[]`;
@@ -89,6 +60,7 @@ class Field extends Scriptable_1.default {
89
60
  if (finalType.indexOf('undefined') === 0) {
90
61
  const typeMappings = {
91
62
  'text-input': 'string',
63
+ 'multiline-input': 'string',
92
64
  'number-input': 'number',
93
65
  'date-input': 'string',
94
66
  'plain-text': 'string',
@@ -102,12 +74,13 @@ class Field extends Scriptable_1.default {
102
74
  }
103
75
  _applyDefaults() {
104
76
  Object.entries(this._getDefaults()).map(([key, value]) => {
105
- //@ts-ignore
106
77
  if (this._jsonModel[key] === undefined && value !== undefined) {
107
- //@ts-ignore
108
78
  this._jsonModel[key] = value;
109
79
  }
110
80
  });
81
+ this.coerceParam('required', 'boolean');
82
+ this.coerceParam('readOnly', 'boolean');
83
+ this.coerceParam('enabled', 'boolean');
111
84
  const type = this._jsonModel.type;
112
85
  if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
113
86
  this._jsonModel.type = this._getFallbackType();
@@ -117,28 +90,25 @@ class Field extends Scriptable_1.default {
117
90
  }
118
91
  const value = this._jsonModel.value;
119
92
  if (value === undefined) {
120
- const typedRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
93
+ const typedRes = Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
121
94
  this._jsonModel.value = typedRes.value;
122
95
  }
123
96
  if (this._jsonModel.type !== 'string') {
124
- this._jsonModel.emptyValue = undefined;
97
+ this.unset('emptyValue');
125
98
  }
126
99
  if (this._jsonModel.fieldType === undefined) {
127
100
  this.form.logger.error('fieldType property is mandatory. Please ensure all the fields have a fieldType');
128
- //@ts-ignore
129
101
  if (this._jsonModel.viewType) {
130
- //@ts-ignore
131
102
  if (this._jsonModel.viewType.startsWith('custom:')) {
132
103
  this.form.logger.error('viewType property has been removed. For custom types, use :type property');
133
104
  }
134
105
  else {
135
106
  this.form.logger.error('viewType property has been removed. Use fieldType property');
136
107
  }
137
- //@ts-ignore
138
108
  this._jsonModel.fieldType = this._jsonModel.viewType;
139
109
  }
140
110
  else {
141
- this._jsonModel.fieldType = (0, SchemaUtils_1.defaultFieldTypes)(this._jsonModel);
111
+ this._jsonModel.fieldType = defaultFieldTypes(this._jsonModel);
142
112
  }
143
113
  }
144
114
  if (this._jsonModel.enum === undefined) {
@@ -152,35 +122,42 @@ class Field extends Scriptable_1.default {
152
122
  this._jsonModel.enumNames = this._jsonModel.enum.map(_ => _.toString());
153
123
  }
154
124
  while (this._jsonModel.enumNames.length < this._jsonModel.enum.length) {
155
- //@ts-ignore
156
125
  this._jsonModel.enumNames.push(this._jsonModel.enum[this._jsonModel.enumNames.length].toString());
157
126
  }
158
127
  }
128
+ const props = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'];
159
129
  if (this._jsonModel.type !== 'string') {
160
- this._jsonModel.format = undefined;
161
- this._jsonModel.pattern = undefined;
162
- this._jsonModel.minLength = undefined;
163
- this._jsonModel.maxLength = undefined;
130
+ this.unset('format', 'pattern', 'minLength', 'maxLength');
164
131
  }
165
132
  else if (this._jsonModel.fieldType === 'date-input') {
166
133
  this._jsonModel.format = 'date';
167
134
  }
135
+ this.coerceParam('minLength', 'number');
136
+ this.coerceParam('maxLength', 'number');
168
137
  if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date') {
169
- this._jsonModel.step = undefined;
170
- this._jsonModel.minimum = undefined;
171
- this._jsonModel.maximum = undefined;
172
- this._jsonModel.exclusiveMinimum = undefined;
173
- this._jsonModel.exclusiveMaximum = undefined;
174
- }
175
- ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'].forEach(c => {
176
- //@ts-ignore
177
- if (typeof this._jsonModel[c] !== this._jsonModel.type) {
178
- //@ts-ignore
179
- this._jsonModel[c] = undefined;
180
- }
138
+ this.unset('step', ...props);
139
+ }
140
+ props.forEach(c => {
141
+ this.coerceParam(c, this._jsonModel.type);
181
142
  });
182
143
  if (typeof this._jsonModel.step !== 'number') {
183
- this._jsonModel.step = undefined;
144
+ this.coerceParam('step', 'number');
145
+ }
146
+ }
147
+ unset(...props) {
148
+ props.forEach(p => this._jsonModel[p] = undefined);
149
+ }
150
+ coerceParam(param, type) {
151
+ const val = this._jsonModel[param];
152
+ if (typeof val !== 'undefined' && typeof val !== type) {
153
+ this.form.logger.info(`${param} is not of type ${type}. Trying to coerce.`);
154
+ try {
155
+ this._jsonModel[param] = coerceType(val, type);
156
+ }
157
+ catch (e) {
158
+ this.form.logger.warn(e);
159
+ this.unset(param);
160
+ }
184
161
  }
185
162
  }
186
163
  get editFormat() {
@@ -198,10 +175,6 @@ class Field extends Scriptable_1.default {
198
175
  set readOnly(e) {
199
176
  this._setProperty('readOnly', e);
200
177
  }
201
- get language() {
202
- //todo: add this in the specification and take it as a property
203
- return Intl.DateTimeFormat().resolvedOptions().locale;
204
- }
205
178
  get enabled() {
206
179
  return this._jsonModel.enabled;
207
180
  }
@@ -260,26 +233,35 @@ class Field extends Scriptable_1.default {
260
233
  this._setProperty('minimum', m);
261
234
  }
262
235
  }
263
- /**
264
- * returns whether the value is empty. Empty value is either a '', undefined or null
265
- * @private
266
- */
267
236
  isEmpty() {
268
237
  return this._jsonModel.value === undefined || this._jsonModel.value === null || this._jsonModel.value === '';
269
238
  }
239
+ withCategory(df) {
240
+ const hasCategory = df?.match(/^(?:date|num)\|/);
241
+ if (hasCategory == null) {
242
+ if (this.format === 'date') {
243
+ df = `date|${df}`;
244
+ }
245
+ else if (this.type === 'number') {
246
+ df = `num|${df}`;
247
+ }
248
+ return df;
249
+ }
250
+ return df;
251
+ }
270
252
  get editValue() {
271
- const format = this.editFormat;
272
- if (this.format == 'date' && this.value != null && this.valid !== false) {
273
- return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
253
+ const df = this.withCategory(this.editFormat);
254
+ if (df && this.isNotEmpty(this.value) && this.valid !== false) {
255
+ return format(this.value, this.language, df);
274
256
  }
275
257
  else {
276
258
  return this.value;
277
259
  }
278
260
  }
279
261
  get displayValue() {
280
- const format = this.displayFormat;
281
- if (this.format == 'date' && this.value != null && this.valid !== false) {
282
- return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
262
+ const df = this.withCategory(this.displayFormat);
263
+ if (df && this.isNotEmpty(this.value) && this.valid !== false) {
264
+ return format(this.value, this.language, df);
283
265
  }
284
266
  else {
285
267
  return this.value;
@@ -288,34 +270,39 @@ class Field extends Scriptable_1.default {
288
270
  getDataNodeValue(typedValue) {
289
271
  return this.isEmpty() ? this.emptyValue : typedValue;
290
272
  }
291
- get value() {
292
- if (this._jsonModel.value === undefined) {
293
- return null;
294
- }
295
- else {
296
- return this._jsonModel.value;
297
- }
298
- }
299
- set value(v) {
273
+ updateDataNodeAndTypedValue(val) {
300
274
  const dataNode = this.getDataNode();
301
- if (BaseNode_1.staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
302
- // if a static field is bound to data node it can not be updated.
275
+ if (staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
303
276
  return;
304
277
  }
305
278
  const Constraints = this._getConstraintObject();
306
- const typeRes = Constraints.type(this.getInternalType() || 'string', v);
279
+ const typeRes = Constraints.type(this.getInternalType() || 'string', val);
307
280
  const changes = this._setProperty('value', typeRes.value, false);
308
- let uniqueRes = { valid: true };
309
281
  if (changes.length > 0) {
310
282
  this._updateRuleNodeReference(typeRes.value);
311
283
  if (typeof dataNode !== 'undefined') {
312
284
  dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
313
285
  }
286
+ }
287
+ return changes;
288
+ }
289
+ get value() {
290
+ if (this._jsonModel.value === undefined) {
291
+ return null;
292
+ }
293
+ else {
294
+ return this._jsonModel.value;
295
+ }
296
+ }
297
+ set value(v) {
298
+ const changes = this.updateDataNodeAndTypedValue(v);
299
+ let uniqueRes = { valid: true };
300
+ if (changes?.length > 0) {
301
+ let updates = {};
302
+ const typeRes = Constraints.type(this.getInternalType() || 'string', v);
314
303
  if (this.parent.uniqueItems && this.parent.type === 'array') {
315
- // @ts-ignore
316
304
  uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
317
305
  }
318
- let updates;
319
306
  if (typeRes.valid && uniqueRes.valid) {
320
307
  updates = this.evaluateConstraints();
321
308
  }
@@ -329,13 +316,24 @@ class Field extends Scriptable_1.default {
329
316
  if (updates.valid) {
330
317
  this.triggerValidationEvent(updates);
331
318
  }
332
- const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
319
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
320
+ this.dispatch(changeAction);
321
+ }
322
+ }
323
+ reset() {
324
+ const changes = this.updateDataNodeAndTypedValue(this.default);
325
+ if (changes.length > 0) {
326
+ const validationStateChanges = {
327
+ 'valid': undefined,
328
+ 'errorMessage': ''
329
+ };
330
+ const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
331
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
333
332
  this.dispatch(changeAction);
334
333
  }
335
334
  }
336
335
  _updateRuleNodeReference(value) {
337
- var _a;
338
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
336
+ if (this.type?.endsWith('[]')) {
339
337
  if (value != null) {
340
338
  value.forEach((val, index) => {
341
339
  this._ruleNodeReference[index] = val;
@@ -355,26 +353,18 @@ class Field extends Scriptable_1.default {
355
353
  return this.type;
356
354
  }
357
355
  valueOf() {
358
- // @ts-ignore
359
- const obj = this[BaseNode_1.target];
356
+ const obj = this[target];
360
357
  const actualField = obj === undefined ? this : obj;
361
358
  actualField.ruleEngine.trackDependency(actualField);
362
359
  return actualField._jsonModel.value || null;
363
360
  }
364
361
  toString() {
365
- var _a;
366
- // @ts-ignore
367
- const obj = this[BaseNode_1.target];
362
+ const obj = this[target];
368
363
  const actualField = obj === undefined ? this : obj;
369
- return ((_a = actualField._jsonModel.value) === null || _a === void 0 ? void 0 : _a.toString()) || '';
364
+ return actualField._jsonModel.value?.toString() || '';
370
365
  }
371
- /**
372
- * Returns the error message for a given constraint
373
- * @param constraint
374
- */
375
366
  getErrorMessage(constraint) {
376
- var _a;
377
- return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[constraint]) || '';
367
+ return this._jsonModel.constraintMessages?.[constraint] || '';
378
368
  }
379
369
  get errorMessage() {
380
370
  return this._jsonModel.errorMessage;
@@ -382,26 +372,12 @@ class Field extends Scriptable_1.default {
382
372
  get screenReaderText() {
383
373
  return this._jsonModel.screenReaderText;
384
374
  }
385
- /**
386
- *
387
- * @private
388
- */
389
375
  _getConstraintObject() {
390
- return ValidationUtils_1.Constraints;
376
+ return Constraints;
391
377
  }
392
- /**
393
- * returns whether the field is array type or not
394
- * @private
395
- */
396
378
  isArrayType() {
397
379
  return this.type ? this.type.indexOf('[]') > -1 : false;
398
380
  }
399
- /**
400
- *
401
- * @param value
402
- * @param constraints
403
- * @private
404
- */
405
381
  checkEnum(value, constraints) {
406
382
  if (this._jsonModel.enforceEnum === true && value != null) {
407
383
  const fn = constraints.enum;
@@ -414,62 +390,63 @@ class Field extends Scriptable_1.default {
414
390
  }
415
391
  return true;
416
392
  }
417
- /**
418
- * checks whether the value can be achieved by stepping the min/default value by the step constraint.
419
- * Basically to find a integer solution for n in the equation
420
- * initialValue + n * step = value
421
- * @param constraints
422
- * @private
423
- */
424
393
  checkStep() {
425
394
  const value = this._jsonModel.value;
426
- if (typeof this._jsonModel.step === 'number') {
427
- const initialValue = this._jsonModel.minimum || this._jsonModel.default || 0;
428
- return (value - initialValue) % this._jsonModel.step === 0;
395
+ const step = this._jsonModel.step;
396
+ if (typeof step === 'number') {
397
+ const prec = step.toString().split('.')?.[1]?.length || 0;
398
+ const factor = Math.pow(10, prec);
399
+ const fStep = step * factor;
400
+ const fVal = value * factor;
401
+ const iv = this._jsonModel.minimum || this._jsonModel.default || 0;
402
+ const fIVal = iv * factor;
403
+ const qt = (fVal - fIVal) / fStep;
404
+ const valid = (fVal - fIVal) % fStep < .001;
405
+ let next, prev;
406
+ if (!valid) {
407
+ next = (Math.ceil(qt) * fStep + fIVal) / factor;
408
+ prev = (next - fStep) / factor;
409
+ }
410
+ return {
411
+ valid,
412
+ next,
413
+ prev
414
+ };
429
415
  }
430
- return true;
416
+ return {
417
+ valid: true
418
+ };
431
419
  }
432
- /**
433
- * checks whether the validation expression returns a boolean value or not
434
- * @private
435
- */
436
420
  checkValidationExpression() {
437
421
  if (typeof this._jsonModel.validationExpression === 'string') {
438
422
  return this.executeExpression(this._jsonModel.validationExpression);
439
423
  }
440
424
  return true;
441
425
  }
442
- /**
443
- * Returns the applicable constraints for a given type
444
- * @private
445
- */
446
426
  getConstraints() {
447
427
  switch (this.type) {
448
428
  case 'string':
449
429
  switch (this.format) {
450
430
  case 'date':
451
- return ValidationUtils_1.ValidConstraints.date;
431
+ return ValidConstraints.date;
452
432
  case 'binary':
453
- return ValidationUtils_1.ValidConstraints.file;
433
+ return ValidConstraints.file;
454
434
  case 'data-url':
455
- return ValidationUtils_1.ValidConstraints.file;
435
+ return ValidConstraints.file;
456
436
  default:
457
- return ValidationUtils_1.ValidConstraints.string;
437
+ return ValidConstraints.string;
458
438
  }
459
439
  case 'file':
460
- return ValidationUtils_1.ValidConstraints.file;
440
+ return ValidConstraints.file;
461
441
  case 'number':
462
442
  case 'integer':
463
- return ValidationUtils_1.ValidConstraints.number;
443
+ return ValidConstraints.number;
464
444
  }
465
445
  if (this.isArrayType()) {
466
- return ValidationUtils_1.ValidConstraints.array;
446
+ return ValidConstraints.array;
467
447
  }
468
448
  return [];
469
449
  }
470
- /**
471
- * returns the format constraint
472
- */
473
450
  get format() {
474
451
  if (typeof this._jsonModel.format === 'undefined') {
475
452
  if (this.type === 'string') {
@@ -528,9 +505,9 @@ class Field extends Scriptable_1.default {
528
505
  get default() {
529
506
  return this._jsonModel.default;
530
507
  }
531
- /**
532
- * @private
533
- */
508
+ isNotEmpty(value) {
509
+ return value != null && value !== '';
510
+ }
534
511
  evaluateConstraints() {
535
512
  let constraint = 'type';
536
513
  const elem = this._jsonModel;
@@ -543,16 +520,13 @@ class Field extends Scriptable_1.default {
543
520
  (this.isArrayType() && this.required ? value.length > 0 : true);
544
521
  constraint = 'required';
545
522
  }
546
- if (valid && value != this.emptyValue) {
523
+ if (valid && this.isNotEmpty(value)) {
547
524
  const invalidConstraint = supportedConstraints.find(key => {
548
- // @ts-ignore
549
525
  if (key in elem && elem[key] !== undefined) {
550
- // @ts-ignore
551
526
  const restriction = elem[key];
552
- // @ts-ignore
553
527
  const fn = Constraints[key];
554
528
  if (value instanceof Array && this.isArrayType()) {
555
- if (ValidationUtils_1.ValidConstraints.array.indexOf(key) !== -1) {
529
+ if (ValidConstraints.array.indexOf(key) !== -1) {
556
530
  return !fn(restriction, value).valid;
557
531
  }
558
532
  else {
@@ -578,7 +552,7 @@ class Field extends Scriptable_1.default {
578
552
  valid = this.checkEnum(value, Constraints);
579
553
  constraint = 'enum';
580
554
  if (valid && this.type === 'number') {
581
- valid = this.checkStep();
555
+ valid = this.checkStep().valid;
582
556
  constraint = 'step';
583
557
  }
584
558
  if (valid) {
@@ -588,8 +562,7 @@ class Field extends Scriptable_1.default {
588
562
  }
589
563
  }
590
564
  if (!valid) {
591
- //@ts-ignore
592
- this.form.logger.log(`${constraint} constraint evaluation failed ${this[constraint]}. Received ${this._jsonModel.value}`);
565
+ this.form.logger.info(`${constraint} constraint evaluation failed ${this._jsonModel[constraint]}. Received ${this._jsonModel.value}`);
593
566
  }
594
567
  const changes = {
595
568
  'valid': valid,
@@ -600,91 +573,84 @@ class Field extends Scriptable_1.default {
600
573
  triggerValidationEvent(changes) {
601
574
  if (changes.valid) {
602
575
  if (this.valid) {
603
- this.dispatch(new controller_1.Valid());
576
+ this.dispatch(new Valid());
604
577
  }
605
578
  else {
606
- this.dispatch(new controller_1.Invalid());
579
+ this.dispatch(new Invalid());
607
580
  }
608
581
  }
609
582
  }
610
- /**
611
- * Validates the current form object
612
- */
613
583
  validate() {
614
584
  const changes = this.evaluateConstraints();
615
585
  if (changes.valid) {
616
586
  this.triggerValidationEvent(changes);
617
- this.notifyDependents(new controller_1.Change({ changes: Object.values(changes) }));
587
+ this.notifyDependents(new Change({ changes: Object.values(changes) }));
618
588
  }
619
- return this.valid ? [] : [new types_1.ValidationError(this.id, [this._jsonModel.errorMessage])];
589
+ return this.valid ? [] : [new ValidationError(this.id, [this._jsonModel.errorMessage])];
620
590
  }
621
591
  importData(contextualDataModel) {
622
592
  this._bindToDataModel(contextualDataModel);
623
593
  const dataNode = this.getDataNode();
624
- // only if the value has changed, queue change event
625
- if (dataNode !== undefined && dataNode !== EmptyDataValue_1.default && dataNode.$value !== this._jsonModel.value) {
626
- const changeAction = (0, controller_1.propertyChange)('value', dataNode.$value, this._jsonModel.value);
594
+ if (dataNode !== undefined && dataNode !== NullDataValue && dataNode.$value !== this._jsonModel.value) {
595
+ const changeAction = propertyChange('value', dataNode.$value, this._jsonModel.value);
627
596
  this._jsonModel.value = dataNode.$value;
628
597
  this.queueEvent(changeAction);
629
598
  }
630
599
  }
631
- /**
632
- * @param name
633
- * @private
634
- */
635
600
  defaultDataModel(name) {
636
- const value = BaseNode_1.staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
637
- return new DataValue_1.default(name, value, this.type || 'string');
601
+ const value = staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
602
+ return new DataValue(name, value, this.type || 'string');
638
603
  }
639
604
  getState() {
640
- return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
605
+ return {
606
+ ...super.getState(),
607
+ editValue: this.editValue,
608
+ displayValue: this.displayValue
609
+ };
641
610
  }
642
611
  }
643
612
  __decorate([
644
- (0, BaseNode_1.dependencyTracked)(),
645
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
613
+ dependencyTracked(),
614
+ exclude('button', 'image', 'plain-text')
646
615
  ], Field.prototype, "readOnly", null);
647
616
  __decorate([
648
- (0, BaseNode_1.dependencyTracked)(),
649
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
617
+ dependencyTracked(),
618
+ exclude('image', 'plain-text')
650
619
  ], Field.prototype, "enabled", null);
651
620
  __decorate([
652
- (0, BaseNode_1.dependencyTracked)()
621
+ dependencyTracked()
653
622
  ], Field.prototype, "valid", null);
654
623
  __decorate([
655
- (0, BaseNode_1.dependencyTracked)()
624
+ dependencyTracked()
656
625
  ], Field.prototype, "enum", null);
657
626
  __decorate([
658
- (0, BaseNode_1.dependencyTracked)()
627
+ dependencyTracked()
659
628
  ], Field.prototype, "enumNames", null);
660
629
  __decorate([
661
- (0, BaseNode_1.dependencyTracked)()
630
+ dependencyTracked()
662
631
  ], Field.prototype, "required", null);
663
632
  __decorate([
664
- (0, BaseNode_1.include)('date-input', 'number-input')
633
+ include('date-input', 'number-input')
665
634
  ], Field.prototype, "editValue", null);
666
635
  __decorate([
667
- (0, BaseNode_1.include)('date-input', 'number-input')
668
- ], Field.prototype, "displayValue", null);
669
- __decorate([
670
- (0, BaseNode_1.dependencyTracked)()
636
+ dependencyTracked()
671
637
  ], Field.prototype, "value", null);
672
638
  __decorate([
673
- (0, BaseNode_1.include)('text-input', 'date-input', 'file-input')
639
+ include('text-input', 'date-input', 'file-input')
674
640
  ], Field.prototype, "format", null);
675
641
  __decorate([
676
- (0, BaseNode_1.include)('text-input')
642
+ include('text-input')
677
643
  ], Field.prototype, "maxLength", null);
678
644
  __decorate([
679
- (0, BaseNode_1.include)('text-input')
645
+ include('text-input')
680
646
  ], Field.prototype, "minLength", null);
681
647
  __decorate([
682
- (0, BaseNode_1.include)('text-input')
648
+ include('text-input')
683
649
  ], Field.prototype, "pattern", null);
684
650
  __decorate([
685
- (0, BaseNode_1.dependencyTracked)()
651
+ dependencyTracked()
686
652
  ], Field.prototype, "exclusiveMinimum", null);
687
653
  __decorate([
688
- (0, BaseNode_1.dependencyTracked)()
654
+ dependencyTracked()
689
655
  ], Field.prototype, "exclusiveMaximum", null);
690
- exports.default = Field;
656
+ export default Field;