@aemforms/af-core 0.22.19 → 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 (122) 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} +10 -69
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
  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/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +54 -116
  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} +39 -104
  15. package/lib/{Field.js → esm/Field.js} +142 -208
  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/{Form.d.ts → esm/Form.d.ts} +19 -85
  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} +11 -54
  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 +15 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  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 +41 -117
  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 +3 -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 +0 -6
  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/DateField.js +0 -35
  81. package/lib/Fieldset.d.ts +0 -24
  82. package/lib/Fieldset.js +0 -74
  83. package/lib/FileObject.js +0 -39
  84. package/lib/FileUpload.js +0 -155
  85. package/lib/Form.js +0 -252
  86. package/lib/FormInstance.d.ts +0 -38
  87. package/lib/FormInstance.js +0 -127
  88. package/lib/FormMetaData.d.ts +0 -11
  89. package/lib/FormMetaData.js +0 -28
  90. package/lib/InstanceManager.d.ts +0 -16
  91. package/lib/InstanceManager.js +0 -53
  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 -255
  96. package/lib/controller/Controller.js +0 -328
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -56
  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 -393
  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 -87
  111. package/lib/utils/FormCreationUtils.d.ts +0 -11
  112. package/lib/utils/FormCreationUtils.js +0 -83
  113. package/lib/utils/FormUtils.d.ts +0 -47
  114. package/lib/utils/FormUtils.js +0 -257
  115. package/lib/utils/JsonUtils.d.ts +0 -63
  116. package/lib/utils/JsonUtils.js +0 -157
  117. package/lib/utils/LogUtils.js +0 -17
  118. package/lib/utils/SchemaUtils.d.ts +0 -16
  119. package/lib/utils/SchemaUtils.js +0 -92
  120. package/lib/utils/TranslationUtils.d.ts +0 -41
  121. package/lib/utils/TranslationUtils.js +0 -185
  122. 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.isNotEmpty(this.value) && 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.isNotEmpty(this.value) && 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;
@@ -290,8 +272,7 @@ class Field extends Scriptable_1.default {
290
272
  }
291
273
  updateDataNodeAndTypedValue(val) {
292
274
  const dataNode = this.getDataNode();
293
- if (BaseNode_1.staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
294
- // if a static field is bound to data node it can not be updated.
275
+ if (staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
295
276
  return;
296
277
  }
297
278
  const Constraints = this._getConstraintObject();
@@ -316,12 +297,11 @@ class Field extends Scriptable_1.default {
316
297
  set value(v) {
317
298
  const changes = this.updateDataNodeAndTypedValue(v);
318
299
  let uniqueRes = { valid: true };
319
- if ((changes === null || changes === void 0 ? void 0 : changes.length) > 0) {
300
+ if (changes?.length > 0) {
320
301
  let updates = {};
321
- const typeRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', v);
302
+ const typeRes = Constraints.type(this.getInternalType() || 'string', v);
322
303
  if (this.parent.uniqueItems && this.parent.type === 'array') {
323
- // @ts-ignore
324
- uniqueRes = ValidationUtils_1.Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
304
+ uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
325
305
  }
326
306
  if (typeRes.valid && uniqueRes.valid) {
327
307
  updates = this.evaluateConstraints();
@@ -336,35 +316,24 @@ class Field extends Scriptable_1.default {
336
316
  if (updates.valid) {
337
317
  this.triggerValidationEvent(updates);
338
318
  }
339
- const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
319
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
340
320
  this.dispatch(changeAction);
341
321
  }
342
322
  }
343
- /**
344
- * @summary reset the value of the current field to its default
345
- * @method reset
346
- * @private
347
- */
348
323
  reset() {
349
- // update the default value as typed value and also its data node
350
- const changes = this.updateDataNodeAndTypedValue(this.default); // set the value to default value during reset
351
- // if there are changes, trigger change event and reset the validation state (ie errorMessage and valid state)
324
+ const changes = this.updateDataNodeAndTypedValue(this.default);
352
325
  if (changes.length > 0) {
353
- // disable all field validations during field reset.
354
- // reset to default state (ie) field is valid and error message set as empty
355
326
  const validationStateChanges = {
356
327
  'valid': undefined,
357
328
  'errorMessage': ''
358
329
  };
359
- // only if there are changes, update would contain valid and errorMessage
360
330
  const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
361
- const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
331
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
362
332
  this.dispatch(changeAction);
363
333
  }
364
334
  }
365
335
  _updateRuleNodeReference(value) {
366
- var _a;
367
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
336
+ if (this.type?.endsWith('[]')) {
368
337
  if (value != null) {
369
338
  value.forEach((val, index) => {
370
339
  this._ruleNodeReference[index] = val;
@@ -384,26 +353,18 @@ class Field extends Scriptable_1.default {
384
353
  return this.type;
385
354
  }
386
355
  valueOf() {
387
- // @ts-ignore
388
- const obj = this[BaseNode_1.target];
356
+ const obj = this[target];
389
357
  const actualField = obj === undefined ? this : obj;
390
358
  actualField.ruleEngine.trackDependency(actualField);
391
359
  return actualField._jsonModel.value || null;
392
360
  }
393
361
  toString() {
394
- var _a;
395
- // @ts-ignore
396
- const obj = this[BaseNode_1.target];
362
+ const obj = this[target];
397
363
  const actualField = obj === undefined ? this : obj;
398
- return ((_a = actualField._jsonModel.value) === null || _a === void 0 ? void 0 : _a.toString()) || '';
364
+ return actualField._jsonModel.value?.toString() || '';
399
365
  }
400
- /**
401
- * Returns the error message for a given constraint
402
- * @param constraint
403
- */
404
366
  getErrorMessage(constraint) {
405
- var _a;
406
- return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[constraint]) || '';
367
+ return this._jsonModel.constraintMessages?.[constraint] || '';
407
368
  }
408
369
  get errorMessage() {
409
370
  return this._jsonModel.errorMessage;
@@ -411,26 +372,12 @@ class Field extends Scriptable_1.default {
411
372
  get screenReaderText() {
412
373
  return this._jsonModel.screenReaderText;
413
374
  }
414
- /**
415
- *
416
- * @private
417
- */
418
375
  _getConstraintObject() {
419
- return ValidationUtils_1.Constraints;
376
+ return Constraints;
420
377
  }
421
- /**
422
- * returns whether the field is array type or not
423
- * @private
424
- */
425
378
  isArrayType() {
426
379
  return this.type ? this.type.indexOf('[]') > -1 : false;
427
380
  }
428
- /**
429
- *
430
- * @param value
431
- * @param constraints
432
- * @private
433
- */
434
381
  checkEnum(value, constraints) {
435
382
  if (this._jsonModel.enforceEnum === true && value != null) {
436
383
  const fn = constraints.enum;
@@ -443,62 +390,63 @@ class Field extends Scriptable_1.default {
443
390
  }
444
391
  return true;
445
392
  }
446
- /**
447
- * checks whether the value can be achieved by stepping the min/default value by the step constraint.
448
- * Basically to find a integer solution for n in the equation
449
- * initialValue + n * step = value
450
- * @param constraints
451
- * @private
452
- */
453
393
  checkStep() {
454
394
  const value = this._jsonModel.value;
455
- if (typeof this._jsonModel.step === 'number') {
456
- const initialValue = this._jsonModel.minimum || this._jsonModel.default || 0;
457
- 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
+ };
458
415
  }
459
- return true;
416
+ return {
417
+ valid: true
418
+ };
460
419
  }
461
- /**
462
- * checks whether the validation expression returns a boolean value or not
463
- * @private
464
- */
465
420
  checkValidationExpression() {
466
421
  if (typeof this._jsonModel.validationExpression === 'string') {
467
422
  return this.executeExpression(this._jsonModel.validationExpression);
468
423
  }
469
424
  return true;
470
425
  }
471
- /**
472
- * Returns the applicable constraints for a given type
473
- * @private
474
- */
475
426
  getConstraints() {
476
427
  switch (this.type) {
477
428
  case 'string':
478
429
  switch (this.format) {
479
430
  case 'date':
480
- return ValidationUtils_1.ValidConstraints.date;
431
+ return ValidConstraints.date;
481
432
  case 'binary':
482
- return ValidationUtils_1.ValidConstraints.file;
433
+ return ValidConstraints.file;
483
434
  case 'data-url':
484
- return ValidationUtils_1.ValidConstraints.file;
435
+ return ValidConstraints.file;
485
436
  default:
486
- return ValidationUtils_1.ValidConstraints.string;
437
+ return ValidConstraints.string;
487
438
  }
488
439
  case 'file':
489
- return ValidationUtils_1.ValidConstraints.file;
440
+ return ValidConstraints.file;
490
441
  case 'number':
491
442
  case 'integer':
492
- return ValidationUtils_1.ValidConstraints.number;
443
+ return ValidConstraints.number;
493
444
  }
494
445
  if (this.isArrayType()) {
495
- return ValidationUtils_1.ValidConstraints.array;
446
+ return ValidConstraints.array;
496
447
  }
497
448
  return [];
498
449
  }
499
- /**
500
- * returns the format constraint
501
- */
502
450
  get format() {
503
451
  if (typeof this._jsonModel.format === 'undefined') {
504
452
  if (this.type === 'string') {
@@ -560,9 +508,6 @@ class Field extends Scriptable_1.default {
560
508
  isNotEmpty(value) {
561
509
  return value != null && value !== '';
562
510
  }
563
- /**
564
- * @private
565
- */
566
511
  evaluateConstraints() {
567
512
  let constraint = 'type';
568
513
  const elem = this._jsonModel;
@@ -577,14 +522,11 @@ class Field extends Scriptable_1.default {
577
522
  }
578
523
  if (valid && this.isNotEmpty(value)) {
579
524
  const invalidConstraint = supportedConstraints.find(key => {
580
- // @ts-ignore
581
525
  if (key in elem && elem[key] !== undefined) {
582
- // @ts-ignore
583
526
  const restriction = elem[key];
584
- // @ts-ignore
585
527
  const fn = Constraints[key];
586
528
  if (value instanceof Array && this.isArrayType()) {
587
- if (ValidationUtils_1.ValidConstraints.array.indexOf(key) !== -1) {
529
+ if (ValidConstraints.array.indexOf(key) !== -1) {
588
530
  return !fn(restriction, value).valid;
589
531
  }
590
532
  else {
@@ -610,7 +552,7 @@ class Field extends Scriptable_1.default {
610
552
  valid = this.checkEnum(value, Constraints);
611
553
  constraint = 'enum';
612
554
  if (valid && this.type === 'number') {
613
- valid = this.checkStep();
555
+ valid = this.checkStep().valid;
614
556
  constraint = 'step';
615
557
  }
616
558
  if (valid) {
@@ -620,8 +562,7 @@ class Field extends Scriptable_1.default {
620
562
  }
621
563
  }
622
564
  if (!valid) {
623
- //@ts-ignore
624
- 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}`);
625
566
  }
626
567
  const changes = {
627
568
  'valid': valid,
@@ -632,91 +573,84 @@ class Field extends Scriptable_1.default {
632
573
  triggerValidationEvent(changes) {
633
574
  if (changes.valid) {
634
575
  if (this.valid) {
635
- this.dispatch(new controller_1.Valid());
576
+ this.dispatch(new Valid());
636
577
  }
637
578
  else {
638
- this.dispatch(new controller_1.Invalid());
579
+ this.dispatch(new Invalid());
639
580
  }
640
581
  }
641
582
  }
642
- /**
643
- * Validates the current form object
644
- */
645
583
  validate() {
646
584
  const changes = this.evaluateConstraints();
647
585
  if (changes.valid) {
648
586
  this.triggerValidationEvent(changes);
649
- this.notifyDependents(new controller_1.Change({ changes: Object.values(changes) }));
587
+ this.notifyDependents(new Change({ changes: Object.values(changes) }));
650
588
  }
651
- return this.valid ? [] : [new types_1.ValidationError(this.id, [this._jsonModel.errorMessage])];
589
+ return this.valid ? [] : [new ValidationError(this.id, [this._jsonModel.errorMessage])];
652
590
  }
653
591
  importData(contextualDataModel) {
654
592
  this._bindToDataModel(contextualDataModel);
655
593
  const dataNode = this.getDataNode();
656
- // only if the value has changed, queue change event
657
- if (dataNode !== undefined && dataNode !== EmptyDataValue_1.default && dataNode.$value !== this._jsonModel.value) {
658
- 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);
659
596
  this._jsonModel.value = dataNode.$value;
660
597
  this.queueEvent(changeAction);
661
598
  }
662
599
  }
663
- /**
664
- * @param name
665
- * @private
666
- */
667
600
  defaultDataModel(name) {
668
- const value = BaseNode_1.staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
669
- 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');
670
603
  }
671
604
  getState() {
672
- 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
+ };
673
610
  }
674
611
  }
675
612
  __decorate([
676
- (0, BaseNode_1.dependencyTracked)(),
677
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
613
+ dependencyTracked(),
614
+ exclude('button', 'image', 'plain-text')
678
615
  ], Field.prototype, "readOnly", null);
679
616
  __decorate([
680
- (0, BaseNode_1.dependencyTracked)(),
681
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
617
+ dependencyTracked(),
618
+ exclude('image', 'plain-text')
682
619
  ], Field.prototype, "enabled", null);
683
620
  __decorate([
684
- (0, BaseNode_1.dependencyTracked)()
621
+ dependencyTracked()
685
622
  ], Field.prototype, "valid", null);
686
623
  __decorate([
687
- (0, BaseNode_1.dependencyTracked)()
624
+ dependencyTracked()
688
625
  ], Field.prototype, "enum", null);
689
626
  __decorate([
690
- (0, BaseNode_1.dependencyTracked)()
627
+ dependencyTracked()
691
628
  ], Field.prototype, "enumNames", null);
692
629
  __decorate([
693
- (0, BaseNode_1.dependencyTracked)()
630
+ dependencyTracked()
694
631
  ], Field.prototype, "required", null);
695
632
  __decorate([
696
- (0, BaseNode_1.include)('date-input', 'number-input')
633
+ include('date-input', 'number-input')
697
634
  ], Field.prototype, "editValue", null);
698
635
  __decorate([
699
- (0, BaseNode_1.include)('date-input', 'number-input')
700
- ], Field.prototype, "displayValue", null);
701
- __decorate([
702
- (0, BaseNode_1.dependencyTracked)()
636
+ dependencyTracked()
703
637
  ], Field.prototype, "value", null);
704
638
  __decorate([
705
- (0, BaseNode_1.include)('text-input', 'date-input', 'file-input')
639
+ include('text-input', 'date-input', 'file-input')
706
640
  ], Field.prototype, "format", null);
707
641
  __decorate([
708
- (0, BaseNode_1.include)('text-input')
642
+ include('text-input')
709
643
  ], Field.prototype, "maxLength", null);
710
644
  __decorate([
711
- (0, BaseNode_1.include)('text-input')
645
+ include('text-input')
712
646
  ], Field.prototype, "minLength", null);
713
647
  __decorate([
714
- (0, BaseNode_1.include)('text-input')
648
+ include('text-input')
715
649
  ], Field.prototype, "pattern", null);
716
650
  __decorate([
717
- (0, BaseNode_1.dependencyTracked)()
651
+ dependencyTracked()
718
652
  ], Field.prototype, "exclusiveMinimum", null);
719
653
  __decorate([
720
- (0, BaseNode_1.dependencyTracked)()
654
+ dependencyTracked()
721
655
  ], Field.prototype, "exclusiveMaximum", null);
722
- exports.default = Field;
656
+ export default Field;
@@ -0,0 +1,16 @@
1
+ import Container from './Container.js';
2
+ import { ContainerModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from './types/index.js';
3
+ export declare class Fieldset extends Container<FieldsetJson> implements FieldsetModel {
4
+ constructor(params: FieldsetJson, _options: {
5
+ form: FormModel;
6
+ parent: ContainerModel;
7
+ fieldFactory: IFormFieldFactory;
8
+ });
9
+ private _applyDefaults;
10
+ get type(): "array" | "object" | undefined;
11
+ get items(): (import("./types/Model.js").FieldModel | FieldsetModel)[];
12
+ get value(): null;
13
+ get fieldType(): string;
14
+ get enabled(): boolean | undefined;
15
+ set enabled(e: boolean | undefined);
16
+ }