@aemforms/af-core 0.22.23 → 0.22.25

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 (75) hide show
  1. package/package.json +2 -14
  2. package/lib/cjs/index.cjs +0 -7277
  3. package/lib/esm/BaseNode-dc59ab07.js +0 -478
  4. package/lib/esm/BaseNode.d.ts +0 -93
  5. package/lib/esm/BaseNode.js +0 -26
  6. package/lib/esm/Checkbox.d.ts +0 -79
  7. package/lib/esm/Checkbox.js +0 -63
  8. package/lib/esm/CheckboxGroup.d.ts +0 -18
  9. package/lib/esm/CheckboxGroup.js +0 -60
  10. package/lib/esm/Container.d.ts +0 -53
  11. package/lib/esm/Container.js +0 -311
  12. package/lib/esm/DateField.d.ts +0 -5
  13. package/lib/esm/DateField.js +0 -57
  14. package/lib/esm/Field.d.ts +0 -206
  15. package/lib/esm/Field.js +0 -692
  16. package/lib/esm/Fieldset.d.ts +0 -16
  17. package/lib/esm/Fieldset.js +0 -78
  18. package/lib/esm/FileObject.d.ts +0 -16
  19. package/lib/esm/FileObject.js +0 -48
  20. package/lib/esm/FileUpload.d.ts +0 -22
  21. package/lib/esm/FileUpload.js +0 -141
  22. package/lib/esm/Form.d.ts +0 -113
  23. package/lib/esm/Form.js +0 -208
  24. package/lib/esm/FormInstance.d.ts +0 -13
  25. package/lib/esm/FormInstance.js +0 -129
  26. package/lib/esm/FormMetaData.d.ts +0 -7
  27. package/lib/esm/FormMetaData.js +0 -35
  28. package/lib/esm/InstanceManager.d.ts +0 -9
  29. package/lib/esm/InstanceManager.js +0 -58
  30. package/lib/esm/Node.d.ts +0 -7
  31. package/lib/esm/Node.js +0 -40
  32. package/lib/esm/Scriptable.d.ts +0 -17
  33. package/lib/esm/Scriptable.js +0 -190
  34. package/lib/esm/controller/EventQueue.d.ts +0 -17
  35. package/lib/esm/controller/EventQueue.js +0 -108
  36. package/lib/esm/controller/Events.d.ts +0 -85
  37. package/lib/esm/controller/Events.js +0 -171
  38. package/lib/esm/controller/Logger.d.ts +0 -11
  39. package/lib/esm/controller/Logger.js +0 -52
  40. package/lib/esm/data/DataGroup.d.ts +0 -20
  41. package/lib/esm/data/DataGroup.js +0 -100
  42. package/lib/esm/data/DataValue.d.ts +0 -16
  43. package/lib/esm/data/DataValue.js +0 -68
  44. package/lib/esm/data/EmptyDataValue.d.ts +0 -14
  45. package/lib/esm/data/EmptyDataValue.js +0 -51
  46. package/lib/esm/index.d.ts +0 -21
  47. package/lib/esm/index.js +0 -55
  48. package/lib/esm/rules/FunctionRuntime.d.ts +0 -51
  49. package/lib/esm/rules/FunctionRuntime.js +0 -345
  50. package/lib/esm/rules/RuleEngine.d.ts +0 -12
  51. package/lib/esm/rules/RuleEngine.js +0 -76
  52. package/lib/esm/types/Json.d.ts +0 -119
  53. package/lib/esm/types/Json.js +0 -29
  54. package/lib/esm/types/Model.d.ts +0 -131
  55. package/lib/esm/types/Model.js +0 -30
  56. package/lib/esm/types/index.d.ts +0 -2
  57. package/lib/esm/types/index.js +0 -22
  58. package/lib/esm/utils/DataRefParser.d.ts +0 -27
  59. package/lib/esm/utils/DataRefParser.js +0 -247
  60. package/lib/esm/utils/Fetch.d.ts +0 -8
  61. package/lib/esm/utils/Fetch.js +0 -83
  62. package/lib/esm/utils/FormCreationUtils.d.ts +0 -9
  63. package/lib/esm/utils/FormCreationUtils.js +0 -112
  64. package/lib/esm/utils/FormUtils.d.ts +0 -12
  65. package/lib/esm/utils/FormUtils.js +0 -212
  66. package/lib/esm/utils/JsonUtils.d.ts +0 -11
  67. package/lib/esm/utils/JsonUtils.js +0 -99
  68. package/lib/esm/utils/LogUtils.d.ts +0 -4
  69. package/lib/esm/utils/LogUtils.js +0 -28
  70. package/lib/esm/utils/SchemaUtils.d.ts +0 -3
  71. package/lib/esm/utils/SchemaUtils.js +0 -93
  72. package/lib/esm/utils/TranslationUtils.d.ts +0 -11
  73. package/lib/esm/utils/TranslationUtils.js +0 -138
  74. package/lib/esm/utils/ValidationUtils.d.ts +0 -19
  75. package/lib/esm/utils/ValidationUtils.js +0 -300
package/lib/esm/Field.js DELETED
@@ -1,692 +0,0 @@
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
-
37
- const validTypes = ['string', 'number', 'boolean', 'file', 'string[]', 'number[]', 'boolean[]', 'file[]', 'array', 'object'];
38
- class Field extends Scriptable {
39
- constructor(params, _options) {
40
- super(params, _options);
41
- this._applyDefaults();
42
- this.queueEvent(new Initialize());
43
- this.queueEvent(new ExecuteRule());
44
- }
45
- _ruleNodeReference = [];
46
- _initialize() {
47
- super._initialize();
48
- this.setupRuleNode();
49
- }
50
- ruleNodeReference() {
51
- if (this.type?.endsWith('[]')) {
52
- this._ruleNodeReference = [];
53
- }
54
- else {
55
- this._ruleNodeReference = this;
56
- }
57
- return this._ruleNodeReference;
58
- }
59
- _getDefaults() {
60
- return {
61
- readOnly: false,
62
- enabled: true,
63
- visible: true,
64
- type: this._getFallbackType()
65
- };
66
- }
67
- _getFallbackType() {
68
- const type = this._jsonModel.type;
69
- let finalType = type;
70
- if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
71
- const _enum = this.enum;
72
- finalType = typeof (_enum?.[0]);
73
- if (finalType === 'undefined' && typeof this._jsonModel.default !== 'undefined') {
74
- if (this._jsonModel.default instanceof Array && this._jsonModel.default.length > 0) {
75
- finalType = `${typeof (this._jsonModel.default[0])}[]`;
76
- }
77
- else {
78
- finalType = typeof (this._jsonModel.default);
79
- }
80
- }
81
- if (finalType.indexOf('undefined') === 0) {
82
- const typeMappings = {
83
- 'text-input': 'string',
84
- 'multiline-input': 'string',
85
- 'number-input': 'number',
86
- 'date-input': 'string',
87
- 'plain-text': 'string',
88
- 'image': 'string',
89
- 'checkbox': 'boolean'
90
- };
91
- finalType = typeMappings[this.fieldType];
92
- }
93
- }
94
- return finalType;
95
- }
96
- _applyDefaults() {
97
- Object.entries(this._getDefaults()).map(([key, value]) => {
98
- if (this._jsonModel[key] === undefined && value !== undefined) {
99
- this._jsonModel[key] = value;
100
- }
101
- });
102
- this.coerceParam('required', 'boolean');
103
- this.coerceParam('readOnly', 'boolean');
104
- this.coerceParam('enabled', 'boolean');
105
- const type = this._jsonModel.type;
106
- if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
107
- this._jsonModel.type = this._getFallbackType();
108
- }
109
- if (['plain-text', 'image'].indexOf(this.fieldType) === -1) {
110
- this._jsonModel.value = undefined;
111
- }
112
- const value = this._jsonModel.value;
113
- if (value === undefined) {
114
- const typedRes = Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
115
- this._jsonModel.value = typedRes.value;
116
- }
117
- if (this._jsonModel.type !== 'string') {
118
- this.unset('emptyValue');
119
- }
120
- if (this._jsonModel.fieldType === undefined) {
121
- this.form.logger.error('fieldType property is mandatory. Please ensure all the fields have a fieldType');
122
- if (this._jsonModel.viewType) {
123
- if (this._jsonModel.viewType.startsWith('custom:')) {
124
- this.form.logger.error('viewType property has been removed. For custom types, use :type property');
125
- }
126
- else {
127
- this.form.logger.error('viewType property has been removed. Use fieldType property');
128
- }
129
- this._jsonModel.fieldType = this._jsonModel.viewType;
130
- }
131
- else {
132
- this._jsonModel.fieldType = defaultFieldTypes(this._jsonModel);
133
- }
134
- }
135
- if (this._jsonModel.enum === undefined) {
136
- const type = this._jsonModel.type;
137
- if (type === 'boolean') {
138
- this._jsonModel.enum = [true, false];
139
- }
140
- }
141
- else {
142
- if (typeof this._jsonModel.enumNames === 'undefined') {
143
- this._jsonModel.enumNames = this._jsonModel.enum.map(_ => _.toString());
144
- }
145
- while (this._jsonModel.enumNames.length < this._jsonModel.enum.length) {
146
- this._jsonModel.enumNames.push(this._jsonModel.enum[this._jsonModel.enumNames.length].toString());
147
- }
148
- }
149
- const props = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'];
150
- if (this._jsonModel.type !== 'string') {
151
- this.unset('format', 'pattern', 'minLength', 'maxLength');
152
- }
153
- else if (this._jsonModel.fieldType === 'date-input') {
154
- this._jsonModel.format = 'date';
155
- }
156
- this.coerceParam('minLength', 'number');
157
- this.coerceParam('maxLength', 'number');
158
- if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date') {
159
- this.unset('step', ...props);
160
- }
161
- props.forEach(c => {
162
- this.coerceParam(c, this._jsonModel.type);
163
- });
164
- if (typeof this._jsonModel.step !== 'number') {
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
- }
182
- }
183
- }
184
- get editFormat() {
185
- return this.withCategory(this._jsonModel.editFormat);
186
- }
187
- get displayFormat() {
188
- return this.withCategory(this._jsonModel.displayFormat);
189
- }
190
- get placeholder() {
191
- return this._jsonModel.placeholder;
192
- }
193
- get readOnly() {
194
- return this._jsonModel.readOnly;
195
- }
196
- set readOnly(e) {
197
- this._setProperty('readOnly', e);
198
- }
199
- get enabled() {
200
- return this._jsonModel.enabled;
201
- }
202
- set enabled(e) {
203
- this._setProperty('enabled', e);
204
- }
205
- get valid() {
206
- return this._jsonModel.valid;
207
- }
208
- get emptyValue() {
209
- if (this._jsonModel.emptyValue === 'null') {
210
- return null;
211
- }
212
- else if (this._jsonModel.emptyValue === '' && this.type === 'string') {
213
- return '';
214
- }
215
- else {
216
- return undefined;
217
- }
218
- }
219
- get enum() {
220
- return this._jsonModel.enum;
221
- }
222
- set enum(e) {
223
- this._setProperty('enum', e);
224
- }
225
- get enumNames() {
226
- return this._jsonModel.enumNames;
227
- }
228
- set enumNames(e) {
229
- this._setProperty('enumNames', e);
230
- }
231
- get required() {
232
- return this._jsonModel.required || false;
233
- }
234
- set required(r) {
235
- this._setProperty('required', r);
236
- }
237
- get maximum() {
238
- if (this.type === 'number' || this.format === 'date') {
239
- return this._jsonModel.maximum;
240
- }
241
- }
242
- set maximum(m) {
243
- if (this.type === 'number' || this.format === 'date') {
244
- this._setProperty('maximum', m);
245
- }
246
- }
247
- get minimum() {
248
- if (this.type === 'number' || this.format === 'date') {
249
- return this._jsonModel.minimum;
250
- }
251
- }
252
- set minimum(m) {
253
- if (this.type === 'number' || this.format === 'date') {
254
- this._setProperty('minimum', m);
255
- }
256
- }
257
- isEmpty() {
258
- return this._jsonModel.value === undefined || this._jsonModel.value === null || this._jsonModel.value === '';
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
- }
275
- get editValue() {
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
- }
284
- }
285
- else {
286
- return this.value;
287
- }
288
- }
289
- get displayValue() {
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
- }
298
- }
299
- else {
300
- return this.value;
301
- }
302
- }
303
- getDataNodeValue(typedValue) {
304
- return this.isEmpty() ? this.emptyValue : typedValue;
305
- }
306
- updateDataNodeAndTypedValue(val) {
307
- const dataNode = this.getDataNode();
308
- if (staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
309
- return;
310
- }
311
- const Constraints = this._getConstraintObject();
312
- const typeRes = Constraints.type(this.getInternalType() || 'string', val);
313
- const changes = this._setProperty('value', typeRes.value, false);
314
- if (changes.length > 0) {
315
- this._updateRuleNodeReference(typeRes.value);
316
- if (typeof dataNode !== 'undefined') {
317
- dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
318
- }
319
- }
320
- return changes;
321
- }
322
- get value() {
323
- if (this._jsonModel.value === undefined) {
324
- return null;
325
- }
326
- else {
327
- return this._jsonModel.value;
328
- }
329
- }
330
- set value(v) {
331
- const changes = this.updateDataNodeAndTypedValue(v);
332
- let uniqueRes = { valid: true };
333
- if (changes?.length > 0) {
334
- let updates = {};
335
- const typeRes = Constraints.type(this.getInternalType() || 'string', v);
336
- if (this.parent.uniqueItems && this.parent.type === 'array') {
337
- uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
338
- }
339
- if (typeRes.valid && uniqueRes.valid) {
340
- updates = this.evaluateConstraints();
341
- }
342
- else {
343
- const changes = {
344
- 'valid': typeRes.valid && uniqueRes.valid,
345
- 'errorMessage': typeRes.valid && uniqueRes.valid ? '' : this.getErrorMessage('type')
346
- };
347
- updates = this._applyUpdates(['valid', 'errorMessage'], changes);
348
- }
349
- if (updates.valid) {
350
- this.triggerValidationEvent(updates);
351
- }
352
- const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
353
- this.dispatch(changeAction);
354
- }
355
- }
356
- reset() {
357
- const changes = this.updateDataNodeAndTypedValue(this.default);
358
- if (changes.length > 0) {
359
- const validationStateChanges = {
360
- 'valid': undefined,
361
- 'errorMessage': ''
362
- };
363
- const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
364
- const changeAction = new Change({ changes: changes.concat(Object.values(updates)) });
365
- this.dispatch(changeAction);
366
- }
367
- }
368
- _updateRuleNodeReference(value) {
369
- if (this.type?.endsWith('[]')) {
370
- if (value != null) {
371
- value.forEach((val, index) => {
372
- this._ruleNodeReference[index] = val;
373
- });
374
- while (value.length !== this._ruleNodeReference.length) {
375
- this._ruleNodeReference.pop();
376
- }
377
- }
378
- else {
379
- while (this._ruleNodeReference.length !== 0) {
380
- this._ruleNodeReference.pop();
381
- }
382
- }
383
- }
384
- }
385
- getInternalType() {
386
- return this.type;
387
- }
388
- valueOf() {
389
- const obj = this[target];
390
- const actualField = obj === undefined ? this : obj;
391
- actualField.ruleEngine.trackDependency(actualField);
392
- return actualField._jsonModel.value || null;
393
- }
394
- toString() {
395
- const obj = this[target];
396
- const actualField = obj === undefined ? this : obj;
397
- return actualField._jsonModel.value?.toString() || '';
398
- }
399
- getErrorMessage(constraint) {
400
- return this._jsonModel.constraintMessages?.[constraint] || '';
401
- }
402
- get errorMessage() {
403
- return this._jsonModel.errorMessage;
404
- }
405
- get screenReaderText() {
406
- return this._jsonModel.screenReaderText;
407
- }
408
- _getConstraintObject() {
409
- return Constraints;
410
- }
411
- isArrayType() {
412
- return this.type ? this.type.indexOf('[]') > -1 : false;
413
- }
414
- checkEnum(value, constraints) {
415
- if (this._jsonModel.enforceEnum === true && value != null) {
416
- const fn = constraints.enum;
417
- if (value instanceof Array && this.isArrayType()) {
418
- return value.every(x => fn(this.enum || [], x).valid);
419
- }
420
- else {
421
- return fn(this.enum || [], value).valid;
422
- }
423
- }
424
- return true;
425
- }
426
- checkStep() {
427
- const value = this._jsonModel.value;
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
- };
448
- }
449
- return {
450
- valid: true
451
- };
452
- }
453
- checkValidationExpression() {
454
- if (typeof this._jsonModel.validationExpression === 'string') {
455
- return this.executeExpression(this._jsonModel.validationExpression);
456
- }
457
- return true;
458
- }
459
- getConstraints() {
460
- switch (this.type) {
461
- case 'string':
462
- switch (this.format) {
463
- case 'date':
464
- return ValidConstraints.date;
465
- case 'binary':
466
- return ValidConstraints.file;
467
- case 'data-url':
468
- return ValidConstraints.file;
469
- default:
470
- return ValidConstraints.string;
471
- }
472
- case 'file':
473
- return ValidConstraints.file;
474
- case 'number':
475
- case 'integer':
476
- return ValidConstraints.number;
477
- }
478
- if (this.isArrayType()) {
479
- return ValidConstraints.array;
480
- }
481
- return [];
482
- }
483
- get format() {
484
- if (typeof this._jsonModel.format === 'undefined') {
485
- if (this.type === 'string') {
486
- switch (this.fieldType) {
487
- case 'date-input':
488
- this._jsonModel.format = 'date';
489
- break;
490
- case 'file-input':
491
- this._jsonModel.format = 'data-url';
492
- break;
493
- }
494
- }
495
- }
496
- return this._jsonModel.format;
497
- }
498
- get enforceEnum() {
499
- return this._jsonModel.enforceEnum;
500
- }
501
- get tooltip() {
502
- return this._jsonModel.tooltip;
503
- }
504
- get maxLength() {
505
- return this._jsonModel.maxLength;
506
- }
507
- get minLength() {
508
- return this._jsonModel.minLength;
509
- }
510
- get pattern() {
511
- return this._jsonModel.pattern;
512
- }
513
- get step() {
514
- if (this.type === 'number' || this.format === 'date') {
515
- return this._jsonModel.step;
516
- }
517
- }
518
- get exclusiveMinimum() {
519
- if (this.type === 'number' || this.format === 'date') {
520
- return this._jsonModel.exclusiveMinimum;
521
- }
522
- }
523
- set exclusiveMinimum(eM) {
524
- if (this.type === 'number' || this.format === 'date') {
525
- this._jsonModel.exclusiveMinimum = eM;
526
- }
527
- }
528
- get exclusiveMaximum() {
529
- if (this.type === 'number' || this.format === 'date') {
530
- return this._jsonModel.exclusiveMaximum;
531
- }
532
- }
533
- set exclusiveMaximum(eM) {
534
- if (this.type === 'number' || this.format === 'date') {
535
- this._jsonModel.exclusiveMaximum = eM;
536
- }
537
- }
538
- get default() {
539
- return this._jsonModel.default;
540
- }
541
- isNotEmpty(value) {
542
- return value != null && value !== '';
543
- }
544
- evaluateConstraints() {
545
- let constraint = 'type';
546
- const elem = this._jsonModel;
547
- const value = this._jsonModel.value;
548
- const Constraints = this._getConstraintObject();
549
- const supportedConstraints = this.getConstraints();
550
- let valid = true;
551
- if (valid) {
552
- valid = Constraints.required(this.required, value).valid &&
553
- (this.isArrayType() && this.required ? value.length > 0 : true);
554
- constraint = 'required';
555
- }
556
- if (valid && this.isNotEmpty(value)) {
557
- const invalidConstraint = supportedConstraints.find(key => {
558
- if (key in elem && elem[key] !== undefined) {
559
- const restriction = elem[key];
560
- const fn = Constraints[key];
561
- if (value instanceof Array && this.isArrayType()) {
562
- if (ValidConstraints.array.indexOf(key) !== -1) {
563
- return !fn(restriction, value).valid;
564
- }
565
- else {
566
- return value.some(x => !(fn(restriction, x).valid));
567
- }
568
- }
569
- else if (typeof fn === 'function') {
570
- return !fn(restriction, value).valid;
571
- }
572
- else {
573
- return false;
574
- }
575
- }
576
- else {
577
- return false;
578
- }
579
- });
580
- if (invalidConstraint != null) {
581
- valid = false;
582
- constraint = invalidConstraint;
583
- }
584
- else {
585
- valid = this.checkEnum(value, Constraints);
586
- constraint = 'enum';
587
- if (valid && this.type === 'number') {
588
- valid = this.checkStep().valid;
589
- constraint = 'step';
590
- }
591
- if (valid) {
592
- valid = this.checkValidationExpression();
593
- constraint = 'validationExpression';
594
- }
595
- }
596
- }
597
- if (!valid) {
598
- this.form.logger.info(`${constraint} constraint evaluation failed ${this._jsonModel[constraint]}. Received ${this._jsonModel.value}`);
599
- }
600
- const changes = {
601
- 'valid': valid,
602
- 'errorMessage': valid ? '' : this.getErrorMessage(constraint)
603
- };
604
- return this._applyUpdates(['valid', 'errorMessage'], changes);
605
- }
606
- triggerValidationEvent(changes) {
607
- if (changes.valid) {
608
- if (this.valid) {
609
- this.dispatch(new Valid());
610
- }
611
- else {
612
- this.dispatch(new Invalid());
613
- }
614
- }
615
- }
616
- validate() {
617
- const changes = this.evaluateConstraints();
618
- if (changes.valid) {
619
- this.triggerValidationEvent(changes);
620
- this.notifyDependents(new Change({ changes: Object.values(changes) }));
621
- }
622
- return this.valid ? [] : [new ValidationError(this.id, [this._jsonModel.errorMessage])];
623
- }
624
- importData(contextualDataModel) {
625
- this._bindToDataModel(contextualDataModel);
626
- const dataNode = this.getDataNode();
627
- if (dataNode !== undefined && dataNode !== NullDataValue && dataNode.$value !== this._jsonModel.value) {
628
- const changeAction = propertyChange('value', dataNode.$value, this._jsonModel.value);
629
- this._jsonModel.value = dataNode.$value;
630
- this.queueEvent(changeAction);
631
- }
632
- }
633
- defaultDataModel(name) {
634
- const value = staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
635
- return new DataValue(name, value, this.type || 'string');
636
- }
637
- getState() {
638
- return {
639
- ...super.getState(),
640
- editFormat: this.editFormat,
641
- displayFormat: this.displayFormat,
642
- editValue: this.editValue,
643
- displayValue: this.displayValue
644
- };
645
- }
646
- }
647
- __decorate([
648
- dependencyTracked(),
649
- exclude('button', 'image', 'plain-text')
650
- ], Field.prototype, "readOnly", null);
651
- __decorate([
652
- dependencyTracked(),
653
- exclude('image', 'plain-text')
654
- ], Field.prototype, "enabled", null);
655
- __decorate([
656
- dependencyTracked()
657
- ], Field.prototype, "valid", null);
658
- __decorate([
659
- dependencyTracked()
660
- ], Field.prototype, "enum", null);
661
- __decorate([
662
- dependencyTracked()
663
- ], Field.prototype, "enumNames", null);
664
- __decorate([
665
- dependencyTracked()
666
- ], Field.prototype, "required", null);
667
- __decorate([
668
- include('date-input', 'number-input')
669
- ], Field.prototype, "editValue", null);
670
- __decorate([
671
- dependencyTracked()
672
- ], Field.prototype, "value", null);
673
- __decorate([
674
- include('text-input', 'date-input', 'file-input')
675
- ], Field.prototype, "format", null);
676
- __decorate([
677
- include('text-input')
678
- ], Field.prototype, "maxLength", null);
679
- __decorate([
680
- include('text-input')
681
- ], Field.prototype, "minLength", null);
682
- __decorate([
683
- include('text-input')
684
- ], Field.prototype, "pattern", null);
685
- __decorate([
686
- dependencyTracked()
687
- ], Field.prototype, "exclusiveMinimum", null);
688
- __decorate([
689
- dependencyTracked()
690
- ], Field.prototype, "exclusiveMaximum", null);
691
-
692
- export { Field as default };
@@ -1,16 +0,0 @@
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
- }