@aemforms/af-core 0.22.19 → 0.22.22

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 (124) hide show
  1. package/LICENSE +18 -4
  2. package/lib/cjs/index.cjs +7277 -0
  3. package/lib/{BaseNode.js → esm/BaseNode-dc59ab07.js} +108 -184
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
  5. package/lib/esm/BaseNode.js +26 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +63 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +60 -0
  10. package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +81 -122
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +57 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +41 -106
  15. package/lib/{Field.js → esm/Field.js} +186 -216
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +78 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +48 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +141 -0
  22. package/lib/{Form.d.ts → esm/Form.d.ts} +20 -86
  23. package/lib/esm/Form.js +208 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +129 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +35 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +58 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +40 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +38 -54
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +32 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +171 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +2 -8
  39. package/lib/esm/controller/Logger.js +52 -0
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +38 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  43. package/lib/esm/data/DataValue.js +68 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +51 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +55 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +3 -25
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +66 -117
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +76 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  53. package/lib/esm/types/Json.js +29 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +30 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +22 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +4 -7
  59. package/lib/{utils → esm/utils}/DataRefParser.js +42 -44
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -7
  61. package/lib/esm/utils/Fetch.js +83 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +112 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +212 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +99 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +28 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +93 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +138 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +55 -187
  76. package/package.json +18 -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/Logger.js +0 -36
  98. package/lib/controller/index.d.ts +0 -1
  99. package/lib/controller/index.js +0 -24
  100. package/lib/data/DataValue.js +0 -56
  101. package/lib/data/EmptyDataValue.js +0 -46
  102. package/lib/index.d.ts +0 -28
  103. package/lib/index.js +0 -63
  104. package/lib/rules/RuleEngine.d.ts +0 -23
  105. package/lib/rules/RuleEngine.js +0 -62
  106. package/lib/types/Json.d.ts +0 -138
  107. package/lib/types/Json.js +0 -19
  108. package/lib/types/Model.d.ts +0 -393
  109. package/lib/types/Model.js +0 -20
  110. package/lib/types/index.d.ts +0 -2
  111. package/lib/types/index.js +0 -25
  112. package/lib/utils/Fetch.js +0 -87
  113. package/lib/utils/FormCreationUtils.d.ts +0 -11
  114. package/lib/utils/FormCreationUtils.js +0 -83
  115. package/lib/utils/FormUtils.d.ts +0 -47
  116. package/lib/utils/FormUtils.js +0 -257
  117. package/lib/utils/JsonUtils.d.ts +0 -63
  118. package/lib/utils/JsonUtils.js +0 -157
  119. package/lib/utils/LogUtils.js +0 -17
  120. package/lib/utils/SchemaUtils.d.ts +0 -16
  121. package/lib/utils/SchemaUtils.js +0 -92
  122. package/lib/utils/TranslationUtils.d.ts +0 -41
  123. package/lib/utils/TranslationUtils.js +0 -185
  124. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -1,57 +1,54 @@
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
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
- 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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
14
- };
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
- */
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 { _ as __decorate, s as staticFields, t as target, d as dependencyTracked, e as exclude, i as include } from './BaseNode-dc59ab07.js';
22
+ import { ValidationError } from './types/Model.js';
23
+ import { Constraints, coerceType, ValidConstraints } from './utils/ValidationUtils.js';
24
+ import { Initialize, ExecuteRule, Change, Valid, Invalid, propertyChange } from './controller/Events.js';
25
+ import Scriptable from './Scriptable.js';
26
+ import { defaultFieldTypes } from './utils/SchemaUtils.js';
27
+ import DataValue from './data/DataValue.js';
28
+ import NullDataValue from './data/EmptyDataValue.js';
29
+ import { format } from '@aemforms/af-formatters';
30
+ import './utils/DataRefParser.js';
31
+ import './data/DataGroup.js';
32
+ import './utils/FormUtils.js';
33
+ import './utils/JsonUtils.js';
34
+ import './types/Json.js';
35
+ import './FileObject.js';
36
+
31
37
  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
- */
38
+ class Field extends Scriptable {
38
39
  constructor(params, _options) {
39
40
  super(params, _options);
40
- this._ruleNodeReference = [];
41
41
  this._applyDefaults();
42
- this.queueEvent(new controller_1.Initialize());
43
- this.queueEvent(new controller_1.ExecuteRule());
42
+ this.queueEvent(new Initialize());
43
+ this.queueEvent(new ExecuteRule());
44
44
  }
45
- /**
46
- * @private
47
- */
45
+ _ruleNodeReference = [];
48
46
  _initialize() {
49
47
  super._initialize();
50
48
  this.setupRuleNode();
51
49
  }
52
50
  ruleNodeReference() {
53
- var _a;
54
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
51
+ if (this.type?.endsWith('[]')) {
55
52
  this._ruleNodeReference = [];
56
53
  }
57
54
  else {
@@ -67,17 +64,12 @@ class Field extends Scriptable_1.default {
67
64
  type: this._getFallbackType()
68
65
  };
69
66
  }
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
67
  _getFallbackType() {
76
68
  const type = this._jsonModel.type;
77
69
  let finalType = type;
78
70
  if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
79
71
  const _enum = this.enum;
80
- finalType = typeof (_enum === null || _enum === void 0 ? void 0 : _enum[0]);
72
+ finalType = typeof (_enum?.[0]);
81
73
  if (finalType === 'undefined' && typeof this._jsonModel.default !== 'undefined') {
82
74
  if (this._jsonModel.default instanceof Array && this._jsonModel.default.length > 0) {
83
75
  finalType = `${typeof (this._jsonModel.default[0])}[]`;
@@ -89,6 +81,7 @@ class Field extends Scriptable_1.default {
89
81
  if (finalType.indexOf('undefined') === 0) {
90
82
  const typeMappings = {
91
83
  'text-input': 'string',
84
+ 'multiline-input': 'string',
92
85
  'number-input': 'number',
93
86
  'date-input': 'string',
94
87
  'plain-text': 'string',
@@ -102,12 +95,13 @@ class Field extends Scriptable_1.default {
102
95
  }
103
96
  _applyDefaults() {
104
97
  Object.entries(this._getDefaults()).map(([key, value]) => {
105
- //@ts-ignore
106
98
  if (this._jsonModel[key] === undefined && value !== undefined) {
107
- //@ts-ignore
108
99
  this._jsonModel[key] = value;
109
100
  }
110
101
  });
102
+ this.coerceParam('required', 'boolean');
103
+ this.coerceParam('readOnly', 'boolean');
104
+ this.coerceParam('enabled', 'boolean');
111
105
  const type = this._jsonModel.type;
112
106
  if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
113
107
  this._jsonModel.type = this._getFallbackType();
@@ -117,28 +111,25 @@ class Field extends Scriptable_1.default {
117
111
  }
118
112
  const value = this._jsonModel.value;
119
113
  if (value === undefined) {
120
- const typedRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
114
+ const typedRes = Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
121
115
  this._jsonModel.value = typedRes.value;
122
116
  }
123
117
  if (this._jsonModel.type !== 'string') {
124
- this._jsonModel.emptyValue = undefined;
118
+ this.unset('emptyValue');
125
119
  }
126
120
  if (this._jsonModel.fieldType === undefined) {
127
121
  this.form.logger.error('fieldType property is mandatory. Please ensure all the fields have a fieldType');
128
- //@ts-ignore
129
122
  if (this._jsonModel.viewType) {
130
- //@ts-ignore
131
123
  if (this._jsonModel.viewType.startsWith('custom:')) {
132
124
  this.form.logger.error('viewType property has been removed. For custom types, use :type property');
133
125
  }
134
126
  else {
135
127
  this.form.logger.error('viewType property has been removed. Use fieldType property');
136
128
  }
137
- //@ts-ignore
138
129
  this._jsonModel.fieldType = this._jsonModel.viewType;
139
130
  }
140
131
  else {
141
- this._jsonModel.fieldType = (0, SchemaUtils_1.defaultFieldTypes)(this._jsonModel);
132
+ this._jsonModel.fieldType = defaultFieldTypes(this._jsonModel);
142
133
  }
143
134
  }
144
135
  if (this._jsonModel.enum === undefined) {
@@ -152,42 +143,49 @@ class Field extends Scriptable_1.default {
152
143
  this._jsonModel.enumNames = this._jsonModel.enum.map(_ => _.toString());
153
144
  }
154
145
  while (this._jsonModel.enumNames.length < this._jsonModel.enum.length) {
155
- //@ts-ignore
156
146
  this._jsonModel.enumNames.push(this._jsonModel.enum[this._jsonModel.enumNames.length].toString());
157
147
  }
158
148
  }
149
+ const props = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'];
159
150
  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;
151
+ this.unset('format', 'pattern', 'minLength', 'maxLength');
164
152
  }
165
153
  else if (this._jsonModel.fieldType === 'date-input') {
166
154
  this._jsonModel.format = 'date';
167
155
  }
156
+ this.coerceParam('minLength', 'number');
157
+ this.coerceParam('maxLength', 'number');
168
158
  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
- }
159
+ this.unset('step', ...props);
160
+ }
161
+ props.forEach(c => {
162
+ this.coerceParam(c, this._jsonModel.type);
181
163
  });
182
164
  if (typeof this._jsonModel.step !== 'number') {
183
- this._jsonModel.step = undefined;
165
+ this.coerceParam('step', 'number');
166
+ }
167
+ }
168
+ unset(...props) {
169
+ props.forEach(p => this._jsonModel[p] = undefined);
170
+ }
171
+ coerceParam(param, type) {
172
+ const val = this._jsonModel[param];
173
+ if (typeof val !== 'undefined' && typeof val !== type) {
174
+ this.form.logger.info(`${param} is not of type ${type}. Trying to coerce.`);
175
+ try {
176
+ this._jsonModel[param] = coerceType(val, type);
177
+ }
178
+ catch (e) {
179
+ this.form.logger.warn(e);
180
+ this.unset(param);
181
+ }
184
182
  }
185
183
  }
186
184
  get editFormat() {
187
- return this._jsonModel.editFormat;
185
+ return this.withCategory(this._jsonModel.editFormat);
188
186
  }
189
187
  get displayFormat() {
190
- return this._jsonModel.displayFormat;
188
+ return this.withCategory(this._jsonModel.displayFormat);
191
189
  }
192
190
  get placeholder() {
193
191
  return this._jsonModel.placeholder;
@@ -198,10 +196,6 @@ class Field extends Scriptable_1.default {
198
196
  set readOnly(e) {
199
197
  this._setProperty('readOnly', e);
200
198
  }
201
- get language() {
202
- //todo: add this in the specification and take it as a property
203
- return Intl.DateTimeFormat().resolvedOptions().locale;
204
- }
205
199
  get enabled() {
206
200
  return this._jsonModel.enabled;
207
201
  }
@@ -260,26 +254,47 @@ class Field extends Scriptable_1.default {
260
254
  this._setProperty('minimum', m);
261
255
  }
262
256
  }
263
- /**
264
- * returns whether the value is empty. Empty value is either a '', undefined or null
265
- * @private
266
- */
267
257
  isEmpty() {
268
258
  return this._jsonModel.value === undefined || this._jsonModel.value === null || this._jsonModel.value === '';
269
259
  }
260
+ withCategory(df) {
261
+ if (df) {
262
+ const hasCategory = df?.match(/^(?:date|num)\|/);
263
+ if (hasCategory === null) {
264
+ if (this.format === 'date') {
265
+ df = `date|${df}`;
266
+ }
267
+ else if (this.type === 'number') {
268
+ df = `num|${df}`;
269
+ }
270
+ return df;
271
+ }
272
+ }
273
+ return df;
274
+ }
270
275
  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);
276
+ const df = this.editFormat;
277
+ if (df && this.isNotEmpty(this.value) && this.valid !== false) {
278
+ try {
279
+ return format(this.value, this.language, df);
280
+ }
281
+ catch (e) {
282
+ return this.value;
283
+ }
274
284
  }
275
285
  else {
276
286
  return this.value;
277
287
  }
278
288
  }
279
289
  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);
290
+ const df = this.displayFormat;
291
+ if (df && this.isNotEmpty(this.value) && this.valid !== false) {
292
+ try {
293
+ return format(this.value, this.language, df);
294
+ }
295
+ catch (e) {
296
+ return this.value;
297
+ }
283
298
  }
284
299
  else {
285
300
  return this.value;
@@ -290,8 +305,7 @@ class Field extends Scriptable_1.default {
290
305
  }
291
306
  updateDataNodeAndTypedValue(val) {
292
307
  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.
308
+ if (staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
295
309
  return;
296
310
  }
297
311
  const Constraints = this._getConstraintObject();
@@ -316,12 +330,11 @@ class Field extends Scriptable_1.default {
316
330
  set value(v) {
317
331
  const changes = this.updateDataNodeAndTypedValue(v);
318
332
  let uniqueRes = { valid: true };
319
- if ((changes === null || changes === void 0 ? void 0 : changes.length) > 0) {
333
+ if (changes?.length > 0) {
320
334
  let updates = {};
321
- const typeRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', v);
335
+ const typeRes = Constraints.type(this.getInternalType() || 'string', v);
322
336
  if (this.parent.uniqueItems && this.parent.type === 'array') {
323
- // @ts-ignore
324
- uniqueRes = ValidationUtils_1.Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
337
+ uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
325
338
  }
326
339
  if (typeRes.valid && uniqueRes.valid) {
327
340
  updates = this.evaluateConstraints();
@@ -336,35 +349,24 @@ class Field extends Scriptable_1.default {
336
349
  if (updates.valid) {
337
350
  this.triggerValidationEvent(updates);
338
351
  }
339
- const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
352
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
340
353
  this.dispatch(changeAction);
341
354
  }
342
355
  }
343
- /**
344
- * @summary reset the value of the current field to its default
345
- * @method reset
346
- * @private
347
- */
348
356
  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)
357
+ const changes = this.updateDataNodeAndTypedValue(this.default);
352
358
  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
359
  const validationStateChanges = {
356
360
  'valid': undefined,
357
361
  'errorMessage': ''
358
362
  };
359
- // only if there are changes, update would contain valid and errorMessage
360
363
  const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
361
- const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
364
+ const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
362
365
  this.dispatch(changeAction);
363
366
  }
364
367
  }
365
368
  _updateRuleNodeReference(value) {
366
- var _a;
367
- if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
369
+ if (this.type?.endsWith('[]')) {
368
370
  if (value != null) {
369
371
  value.forEach((val, index) => {
370
372
  this._ruleNodeReference[index] = val;
@@ -384,26 +386,18 @@ class Field extends Scriptable_1.default {
384
386
  return this.type;
385
387
  }
386
388
  valueOf() {
387
- // @ts-ignore
388
- const obj = this[BaseNode_1.target];
389
+ const obj = this[target];
389
390
  const actualField = obj === undefined ? this : obj;
390
391
  actualField.ruleEngine.trackDependency(actualField);
391
392
  return actualField._jsonModel.value || null;
392
393
  }
393
394
  toString() {
394
- var _a;
395
- // @ts-ignore
396
- const obj = this[BaseNode_1.target];
395
+ const obj = this[target];
397
396
  const actualField = obj === undefined ? this : obj;
398
- return ((_a = actualField._jsonModel.value) === null || _a === void 0 ? void 0 : _a.toString()) || '';
397
+ return actualField._jsonModel.value?.toString() || '';
399
398
  }
400
- /**
401
- * Returns the error message for a given constraint
402
- * @param constraint
403
- */
404
399
  getErrorMessage(constraint) {
405
- var _a;
406
- return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[constraint]) || '';
400
+ return this._jsonModel.constraintMessages?.[constraint] || '';
407
401
  }
408
402
  get errorMessage() {
409
403
  return this._jsonModel.errorMessage;
@@ -411,26 +405,12 @@ class Field extends Scriptable_1.default {
411
405
  get screenReaderText() {
412
406
  return this._jsonModel.screenReaderText;
413
407
  }
414
- /**
415
- *
416
- * @private
417
- */
418
408
  _getConstraintObject() {
419
- return ValidationUtils_1.Constraints;
409
+ return Constraints;
420
410
  }
421
- /**
422
- * returns whether the field is array type or not
423
- * @private
424
- */
425
411
  isArrayType() {
426
412
  return this.type ? this.type.indexOf('[]') > -1 : false;
427
413
  }
428
- /**
429
- *
430
- * @param value
431
- * @param constraints
432
- * @private
433
- */
434
414
  checkEnum(value, constraints) {
435
415
  if (this._jsonModel.enforceEnum === true && value != null) {
436
416
  const fn = constraints.enum;
@@ -443,62 +423,63 @@ class Field extends Scriptable_1.default {
443
423
  }
444
424
  return true;
445
425
  }
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
426
  checkStep() {
454
427
  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;
428
+ const step = this._jsonModel.step;
429
+ if (typeof step === 'number') {
430
+ const prec = step.toString().split('.')?.[1]?.length || 0;
431
+ const factor = Math.pow(10, prec);
432
+ const fStep = step * factor;
433
+ const fVal = value * factor;
434
+ const iv = this._jsonModel.minimum || this._jsonModel.default || 0;
435
+ const fIVal = iv * factor;
436
+ const qt = (fVal - fIVal) / fStep;
437
+ const valid = Math.abs(fVal - fIVal) % fStep < .001;
438
+ let next, prev;
439
+ if (!valid) {
440
+ next = (Math.ceil(qt) * fStep + fIVal) / factor;
441
+ prev = (next - fStep) / factor;
442
+ }
443
+ return {
444
+ valid,
445
+ next,
446
+ prev
447
+ };
458
448
  }
459
- return true;
449
+ return {
450
+ valid: true
451
+ };
460
452
  }
461
- /**
462
- * checks whether the validation expression returns a boolean value or not
463
- * @private
464
- */
465
453
  checkValidationExpression() {
466
454
  if (typeof this._jsonModel.validationExpression === 'string') {
467
455
  return this.executeExpression(this._jsonModel.validationExpression);
468
456
  }
469
457
  return true;
470
458
  }
471
- /**
472
- * Returns the applicable constraints for a given type
473
- * @private
474
- */
475
459
  getConstraints() {
476
460
  switch (this.type) {
477
461
  case 'string':
478
462
  switch (this.format) {
479
463
  case 'date':
480
- return ValidationUtils_1.ValidConstraints.date;
464
+ return ValidConstraints.date;
481
465
  case 'binary':
482
- return ValidationUtils_1.ValidConstraints.file;
466
+ return ValidConstraints.file;
483
467
  case 'data-url':
484
- return ValidationUtils_1.ValidConstraints.file;
468
+ return ValidConstraints.file;
485
469
  default:
486
- return ValidationUtils_1.ValidConstraints.string;
470
+ return ValidConstraints.string;
487
471
  }
488
472
  case 'file':
489
- return ValidationUtils_1.ValidConstraints.file;
473
+ return ValidConstraints.file;
490
474
  case 'number':
491
475
  case 'integer':
492
- return ValidationUtils_1.ValidConstraints.number;
476
+ return ValidConstraints.number;
493
477
  }
494
478
  if (this.isArrayType()) {
495
- return ValidationUtils_1.ValidConstraints.array;
479
+ return ValidConstraints.array;
496
480
  }
497
481
  return [];
498
482
  }
499
- /**
500
- * returns the format constraint
501
- */
502
483
  get format() {
503
484
  if (typeof this._jsonModel.format === 'undefined') {
504
485
  if (this.type === 'string') {
@@ -560,9 +541,6 @@ class Field extends Scriptable_1.default {
560
541
  isNotEmpty(value) {
561
542
  return value != null && value !== '';
562
543
  }
563
- /**
564
- * @private
565
- */
566
544
  evaluateConstraints() {
567
545
  let constraint = 'type';
568
546
  const elem = this._jsonModel;
@@ -577,14 +555,11 @@ class Field extends Scriptable_1.default {
577
555
  }
578
556
  if (valid && this.isNotEmpty(value)) {
579
557
  const invalidConstraint = supportedConstraints.find(key => {
580
- // @ts-ignore
581
558
  if (key in elem && elem[key] !== undefined) {
582
- // @ts-ignore
583
559
  const restriction = elem[key];
584
- // @ts-ignore
585
560
  const fn = Constraints[key];
586
561
  if (value instanceof Array && this.isArrayType()) {
587
- if (ValidationUtils_1.ValidConstraints.array.indexOf(key) !== -1) {
562
+ if (ValidConstraints.array.indexOf(key) !== -1) {
588
563
  return !fn(restriction, value).valid;
589
564
  }
590
565
  else {
@@ -610,7 +585,7 @@ class Field extends Scriptable_1.default {
610
585
  valid = this.checkEnum(value, Constraints);
611
586
  constraint = 'enum';
612
587
  if (valid && this.type === 'number') {
613
- valid = this.checkStep();
588
+ valid = this.checkStep().valid;
614
589
  constraint = 'step';
615
590
  }
616
591
  if (valid) {
@@ -620,8 +595,7 @@ class Field extends Scriptable_1.default {
620
595
  }
621
596
  }
622
597
  if (!valid) {
623
- //@ts-ignore
624
- this.form.logger.log(`${constraint} constraint evaluation failed ${this[constraint]}. Received ${this._jsonModel.value}`);
598
+ this.form.logger.info(`${constraint} constraint evaluation failed ${this._jsonModel[constraint]}. Received ${this._jsonModel.value}`);
625
599
  }
626
600
  const changes = {
627
601
  'valid': valid,
@@ -632,91 +606,87 @@ class Field extends Scriptable_1.default {
632
606
  triggerValidationEvent(changes) {
633
607
  if (changes.valid) {
634
608
  if (this.valid) {
635
- this.dispatch(new controller_1.Valid());
609
+ this.dispatch(new Valid());
636
610
  }
637
611
  else {
638
- this.dispatch(new controller_1.Invalid());
612
+ this.dispatch(new Invalid());
639
613
  }
640
614
  }
641
615
  }
642
- /**
643
- * Validates the current form object
644
- */
645
616
  validate() {
646
617
  const changes = this.evaluateConstraints();
647
618
  if (changes.valid) {
648
619
  this.triggerValidationEvent(changes);
649
- this.notifyDependents(new controller_1.Change({ changes: Object.values(changes) }));
620
+ this.notifyDependents(new Change({ changes: Object.values(changes) }));
650
621
  }
651
- return this.valid ? [] : [new types_1.ValidationError(this.id, [this._jsonModel.errorMessage])];
622
+ return this.valid ? [] : [new ValidationError(this.id, [this._jsonModel.errorMessage])];
652
623
  }
653
624
  importData(contextualDataModel) {
654
625
  this._bindToDataModel(contextualDataModel);
655
626
  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);
627
+ if (dataNode !== undefined && dataNode !== NullDataValue && dataNode.$value !== this._jsonModel.value) {
628
+ const changeAction = propertyChange('value', dataNode.$value, this._jsonModel.value);
659
629
  this._jsonModel.value = dataNode.$value;
660
630
  this.queueEvent(changeAction);
661
631
  }
662
632
  }
663
- /**
664
- * @param name
665
- * @private
666
- */
667
633
  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');
634
+ const value = staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
635
+ return new DataValue(name, value, this.type || 'string');
670
636
  }
671
637
  getState() {
672
- return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
638
+ return {
639
+ ...super.getState(),
640
+ editFormat: this.editFormat,
641
+ displayFormat: this.displayFormat,
642
+ editValue: this.editValue,
643
+ displayValue: this.displayValue
644
+ };
673
645
  }
674
646
  }
675
647
  __decorate([
676
- (0, BaseNode_1.dependencyTracked)(),
677
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
648
+ dependencyTracked(),
649
+ exclude('button', 'image', 'plain-text')
678
650
  ], Field.prototype, "readOnly", null);
679
651
  __decorate([
680
- (0, BaseNode_1.dependencyTracked)(),
681
- (0, BaseNode_1.exclude)('button', 'image', 'plain-text')
652
+ dependencyTracked(),
653
+ exclude('image', 'plain-text')
682
654
  ], Field.prototype, "enabled", null);
683
655
  __decorate([
684
- (0, BaseNode_1.dependencyTracked)()
656
+ dependencyTracked()
685
657
  ], Field.prototype, "valid", null);
686
658
  __decorate([
687
- (0, BaseNode_1.dependencyTracked)()
659
+ dependencyTracked()
688
660
  ], Field.prototype, "enum", null);
689
661
  __decorate([
690
- (0, BaseNode_1.dependencyTracked)()
662
+ dependencyTracked()
691
663
  ], Field.prototype, "enumNames", null);
692
664
  __decorate([
693
- (0, BaseNode_1.dependencyTracked)()
665
+ dependencyTracked()
694
666
  ], Field.prototype, "required", null);
695
667
  __decorate([
696
- (0, BaseNode_1.include)('date-input', 'number-input')
668
+ include('date-input', 'number-input')
697
669
  ], Field.prototype, "editValue", null);
698
670
  __decorate([
699
- (0, BaseNode_1.include)('date-input', 'number-input')
700
- ], Field.prototype, "displayValue", null);
701
- __decorate([
702
- (0, BaseNode_1.dependencyTracked)()
671
+ dependencyTracked()
703
672
  ], Field.prototype, "value", null);
704
673
  __decorate([
705
- (0, BaseNode_1.include)('text-input', 'date-input', 'file-input')
674
+ include('text-input', 'date-input', 'file-input')
706
675
  ], Field.prototype, "format", null);
707
676
  __decorate([
708
- (0, BaseNode_1.include)('text-input')
677
+ include('text-input')
709
678
  ], Field.prototype, "maxLength", null);
710
679
  __decorate([
711
- (0, BaseNode_1.include)('text-input')
680
+ include('text-input')
712
681
  ], Field.prototype, "minLength", null);
713
682
  __decorate([
714
- (0, BaseNode_1.include)('text-input')
683
+ include('text-input')
715
684
  ], Field.prototype, "pattern", null);
716
685
  __decorate([
717
- (0, BaseNode_1.dependencyTracked)()
686
+ dependencyTracked()
718
687
  ], Field.prototype, "exclusiveMinimum", null);
719
688
  __decorate([
720
- (0, BaseNode_1.dependencyTracked)()
689
+ dependencyTracked()
721
690
  ], Field.prototype, "exclusiveMaximum", null);
722
- exports.default = Field;
691
+
692
+ export { Field as default };