@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.
- package/LICENSE +18 -4
- package/lib/cjs/index.cjs +7277 -0
- package/lib/{BaseNode.js → esm/BaseNode-dc59ab07.js} +108 -184
- package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
- package/lib/esm/BaseNode.js +26 -0
- package/lib/esm/Checkbox.d.ts +79 -0
- package/lib/esm/Checkbox.js +63 -0
- package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
- package/lib/esm/CheckboxGroup.js +60 -0
- package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
- package/lib/{Container.js → esm/Container.js} +81 -122
- package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
- package/lib/esm/DateField.js +57 -0
- package/lib/{Field.d.ts → esm/Field.d.ts} +41 -106
- package/lib/{Field.js → esm/Field.js} +186 -216
- package/lib/esm/Fieldset.d.ts +16 -0
- package/lib/esm/Fieldset.js +78 -0
- package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
- package/lib/esm/FileObject.js +48 -0
- package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
- package/lib/esm/FileUpload.js +141 -0
- package/lib/{Form.d.ts → esm/Form.d.ts} +20 -86
- package/lib/esm/Form.js +208 -0
- package/lib/esm/FormInstance.d.ts +13 -0
- package/lib/esm/FormInstance.js +129 -0
- package/lib/esm/FormMetaData.d.ts +7 -0
- package/lib/esm/FormMetaData.js +35 -0
- package/lib/esm/InstanceManager.d.ts +9 -0
- package/lib/esm/InstanceManager.js +58 -0
- package/lib/esm/Node.d.ts +7 -0
- package/lib/esm/Node.js +40 -0
- package/lib/esm/Scriptable.d.ts +17 -0
- package/lib/{Scriptable.js → esm/Scriptable.js} +38 -54
- package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
- package/lib/{controller → esm/controller}/EventQueue.js +32 -26
- package/lib/esm/controller/Events.d.ts +85 -0
- package/lib/esm/controller/Events.js +171 -0
- package/lib/{controller → esm/controller}/Logger.d.ts +2 -8
- package/lib/esm/controller/Logger.js +52 -0
- package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
- package/lib/{data → esm/data}/DataGroup.js +38 -34
- package/lib/{data → esm/data}/DataValue.d.ts +1 -7
- package/lib/esm/data/DataValue.js +68 -0
- package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
- package/lib/esm/data/EmptyDataValue.js +51 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +55 -0
- package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +3 -25
- package/lib/{rules → esm/rules}/FunctionRuntime.js +66 -117
- package/lib/esm/rules/RuleEngine.d.ts +12 -0
- package/lib/esm/rules/RuleEngine.js +76 -0
- package/lib/esm/types/Json.d.ts +119 -0
- package/lib/esm/types/Json.js +29 -0
- package/lib/esm/types/Model.d.ts +131 -0
- package/lib/esm/types/Model.js +30 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +22 -0
- package/lib/{utils → esm/utils}/DataRefParser.d.ts +4 -7
- package/lib/{utils → esm/utils}/DataRefParser.js +42 -44
- package/lib/{utils → esm/utils}/Fetch.d.ts +1 -7
- package/lib/esm/utils/Fetch.js +83 -0
- package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
- package/lib/esm/utils/FormCreationUtils.js +112 -0
- package/lib/esm/utils/FormUtils.d.ts +12 -0
- package/lib/esm/utils/FormUtils.js +212 -0
- package/lib/esm/utils/JsonUtils.d.ts +11 -0
- package/lib/esm/utils/JsonUtils.js +99 -0
- package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
- package/lib/esm/utils/LogUtils.js +28 -0
- package/lib/esm/utils/SchemaUtils.d.ts +3 -0
- package/lib/esm/utils/SchemaUtils.js +93 -0
- package/lib/esm/utils/TranslationUtils.d.ts +11 -0
- package/lib/esm/utils/TranslationUtils.js +138 -0
- package/lib/esm/utils/ValidationUtils.d.ts +19 -0
- package/lib/{utils → esm/utils}/ValidationUtils.js +55 -187
- package/package.json +18 -10
- package/lib/Checkbox.d.ts +0 -88
- package/lib/Checkbox.js +0 -49
- package/lib/CheckboxGroup.js +0 -43
- package/lib/DateField.js +0 -35
- package/lib/Fieldset.d.ts +0 -24
- package/lib/Fieldset.js +0 -74
- package/lib/FileObject.js +0 -39
- package/lib/FileUpload.js +0 -155
- package/lib/Form.js +0 -252
- package/lib/FormInstance.d.ts +0 -38
- package/lib/FormInstance.js +0 -127
- package/lib/FormMetaData.d.ts +0 -11
- package/lib/FormMetaData.js +0 -28
- package/lib/InstanceManager.d.ts +0 -16
- package/lib/InstanceManager.js +0 -53
- package/lib/Node.d.ts +0 -12
- package/lib/Node.js +0 -27
- package/lib/Scriptable.d.ts +0 -31
- package/lib/controller/Controller.d.ts +0 -255
- package/lib/controller/Controller.js +0 -328
- package/lib/controller/Logger.js +0 -36
- package/lib/controller/index.d.ts +0 -1
- package/lib/controller/index.js +0 -24
- package/lib/data/DataValue.js +0 -56
- package/lib/data/EmptyDataValue.js +0 -46
- package/lib/index.d.ts +0 -28
- package/lib/index.js +0 -63
- package/lib/rules/RuleEngine.d.ts +0 -23
- package/lib/rules/RuleEngine.js +0 -62
- package/lib/types/Json.d.ts +0 -138
- package/lib/types/Json.js +0 -19
- package/lib/types/Model.d.ts +0 -393
- package/lib/types/Model.js +0 -20
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -25
- package/lib/utils/Fetch.js +0 -87
- package/lib/utils/FormCreationUtils.d.ts +0 -11
- package/lib/utils/FormCreationUtils.js +0 -83
- package/lib/utils/FormUtils.d.ts +0 -47
- package/lib/utils/FormUtils.js +0 -257
- package/lib/utils/JsonUtils.d.ts +0 -63
- package/lib/utils/JsonUtils.js +0 -157
- package/lib/utils/LogUtils.js +0 -17
- package/lib/utils/SchemaUtils.d.ts +0 -16
- package/lib/utils/SchemaUtils.js +0 -92
- package/lib/utils/TranslationUtils.d.ts +0 -41
- package/lib/utils/TranslationUtils.js +0 -185
- package/lib/utils/ValidationUtils.d.ts +0 -170
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 { getFileSizeInBytes, extractFileInfo } from './FormUtils.js';
|
|
22
|
+
import { FileObject } from '../FileObject.js';
|
|
23
|
+
import './JsonUtils.js';
|
|
24
|
+
import '../types/Json.js';
|
|
25
|
+
import './SchemaUtils.js';
|
|
26
|
+
|
|
19
27
|
const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
|
|
20
|
-
const dataUrlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
21
28
|
const days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
22
29
|
const daysInMonth = (leapYear, month) => {
|
|
23
30
|
if (leapYear && month == 2) {
|
|
@@ -28,26 +35,27 @@ const daysInMonth = (leapYear, month) => {
|
|
|
28
35
|
const isLeapYear = (year) => {
|
|
29
36
|
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
30
37
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
38
|
+
const coerceType = (param, type) => {
|
|
39
|
+
let num;
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'string':
|
|
42
|
+
return param + '';
|
|
43
|
+
case 'number':
|
|
44
|
+
num = +param;
|
|
45
|
+
if (!isNaN(num)) {
|
|
46
|
+
return num;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'boolean':
|
|
50
|
+
if (typeof param === 'string') {
|
|
51
|
+
return param === 'true';
|
|
52
|
+
}
|
|
53
|
+
else if (typeof param === 'number') {
|
|
54
|
+
return param !== 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw `${param} has invalid type. Expected : ${type}, Actual ${typeof param}`;
|
|
33
58
|
};
|
|
34
|
-
exports.isDataUrl = isDataUrl;
|
|
35
|
-
/**
|
|
36
|
-
* Checks whether inputVal is valid number value or not
|
|
37
|
-
*
|
|
38
|
-
* ```
|
|
39
|
-
* const x = checkNumber('12')
|
|
40
|
-
* ```
|
|
41
|
-
* would return
|
|
42
|
-
* ```
|
|
43
|
-
* {
|
|
44
|
-
* value : 12,
|
|
45
|
-
* valid : true
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
* @param inputVal input value
|
|
49
|
-
* @returns {@link ValidationResult | Validation result}
|
|
50
|
-
*/
|
|
51
59
|
const checkNumber = (inputVal) => {
|
|
52
60
|
if (inputVal === '' || inputVal == null) {
|
|
53
61
|
return {
|
|
@@ -63,10 +71,6 @@ const checkNumber = (inputVal) => {
|
|
|
63
71
|
value, valid
|
|
64
72
|
};
|
|
65
73
|
};
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
* @param inputVal
|
|
69
|
-
*/
|
|
70
74
|
const checkInteger = (inputVal) => {
|
|
71
75
|
if (inputVal == '' || inputVal == null) {
|
|
72
76
|
return {
|
|
@@ -82,55 +86,25 @@ const checkInteger = (inputVal) => {
|
|
|
82
86
|
value, valid
|
|
83
87
|
};
|
|
84
88
|
};
|
|
85
|
-
/**
|
|
86
|
-
* Wraps a non-null value and not an array value into an array
|
|
87
|
-
* @param inputVal input value
|
|
88
|
-
* @returns wraps the input value into an array
|
|
89
|
-
*/
|
|
90
89
|
const toArray = (inputVal) => {
|
|
91
90
|
if (inputVal != null && !(inputVal instanceof Array)) {
|
|
92
91
|
return [inputVal];
|
|
93
92
|
}
|
|
94
93
|
return inputVal;
|
|
95
94
|
};
|
|
96
|
-
/**
|
|
97
|
-
* Checks whether inputVal is valid boolean value or not
|
|
98
|
-
*
|
|
99
|
-
* ```
|
|
100
|
-
* const x = checkBool('false')
|
|
101
|
-
* ```
|
|
102
|
-
* would return
|
|
103
|
-
* ```
|
|
104
|
-
* {
|
|
105
|
-
* value : false,
|
|
106
|
-
* valid : true
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
* @param inputVal input value
|
|
110
|
-
* @returns {@link ValidationResult | Validation result}
|
|
111
|
-
*/
|
|
112
95
|
const checkBool = (inputVal) => {
|
|
113
96
|
const valid = typeof inputVal === 'boolean' || inputVal === 'true' || inputVal === 'false';
|
|
114
97
|
const value = typeof inputVal === 'boolean' ? inputVal : (valid ? inputVal === 'true' : inputVal);
|
|
115
98
|
return { valid, value };
|
|
116
99
|
};
|
|
117
|
-
/**
|
|
118
|
-
*
|
|
119
|
-
* @param inputVal
|
|
120
|
-
*/
|
|
121
100
|
const checkFile = (inputVal) => {
|
|
122
|
-
const value =
|
|
101
|
+
const value = extractFileInfo(inputVal);
|
|
123
102
|
const valid = value !== null;
|
|
124
103
|
return {
|
|
125
104
|
value: valid ? value : inputVal,
|
|
126
105
|
valid
|
|
127
106
|
};
|
|
128
107
|
};
|
|
129
|
-
/**
|
|
130
|
-
* validates whether the mediaType is one present in the accepts list
|
|
131
|
-
* @param mediaType
|
|
132
|
-
* @param accepts
|
|
133
|
-
*/
|
|
134
108
|
const matchMediaType = (mediaType, accepts) => {
|
|
135
109
|
return !mediaType || accepts.some((accept) => {
|
|
136
110
|
const trimmedAccept = accept.trim();
|
|
@@ -141,13 +115,6 @@ const matchMediaType = (mediaType, accepts) => {
|
|
|
141
115
|
(trimmedAccept === mediaType));
|
|
142
116
|
});
|
|
143
117
|
};
|
|
144
|
-
/**
|
|
145
|
-
* Validates an array of values using a validator function.
|
|
146
|
-
* @param inputVal
|
|
147
|
-
* @param validatorFn
|
|
148
|
-
* @return an array containing two arrays, the first one with all the valid values and the second one with one invalid
|
|
149
|
-
* value (if there is).
|
|
150
|
-
*/
|
|
151
118
|
const partitionArray = (inputVal, validatorFn) => {
|
|
152
119
|
const value = toArray(inputVal);
|
|
153
120
|
if (value == null) {
|
|
@@ -162,23 +129,14 @@ const partitionArray = (inputVal, validatorFn) => {
|
|
|
162
129
|
return acc;
|
|
163
130
|
}, [[], []]);
|
|
164
131
|
};
|
|
165
|
-
|
|
132
|
+
const ValidConstraints = {
|
|
166
133
|
date: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'format'],
|
|
167
134
|
string: ['minLength', 'maxLength', 'pattern'],
|
|
168
135
|
number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
|
|
169
136
|
array: ['minItems', 'maxItems', 'uniqueItems'],
|
|
170
137
|
file: ['accept', 'maxFileSize']
|
|
171
138
|
};
|
|
172
|
-
|
|
173
|
-
* Implementation of all constraints defined by `adaptive form specification`
|
|
174
|
-
*/
|
|
175
|
-
exports.Constraints = {
|
|
176
|
-
/**
|
|
177
|
-
* Implementation of type constraint
|
|
178
|
-
* @param constraint `type` property of the form object
|
|
179
|
-
* @param inputVal value of the form object
|
|
180
|
-
* @return {@link ValidationResult | validation result}
|
|
181
|
-
*/
|
|
139
|
+
const Constraints = {
|
|
182
140
|
type: (constraint, inputVal) => {
|
|
183
141
|
let value = inputVal;
|
|
184
142
|
if (inputVal == undefined) {
|
|
@@ -217,7 +175,6 @@ exports.Constraints = {
|
|
|
217
175
|
value = valid ? res[0] : inputVal;
|
|
218
176
|
break;
|
|
219
177
|
case 'file':
|
|
220
|
-
// for file types only, we support setting value via an array
|
|
221
178
|
res = checkFile(inputVal instanceof Array ? inputVal[0] : inputVal);
|
|
222
179
|
valid = res.valid;
|
|
223
180
|
value = res.value;
|
|
@@ -243,12 +200,6 @@ exports.Constraints = {
|
|
|
243
200
|
value
|
|
244
201
|
};
|
|
245
202
|
},
|
|
246
|
-
/**
|
|
247
|
-
* Implementation of format constraint
|
|
248
|
-
* @param constraint `format` property of the form object
|
|
249
|
-
* @param input value of the form object
|
|
250
|
-
* @return {@link ValidationResult | validation result}
|
|
251
|
-
*/
|
|
252
203
|
format: (constraint, input) => {
|
|
253
204
|
let valid = true;
|
|
254
205
|
const value = input;
|
|
@@ -260,7 +211,6 @@ exports.Constraints = {
|
|
|
260
211
|
case 'date':
|
|
261
212
|
res = dateRegex.exec((input || '').trim());
|
|
262
213
|
if (res != null) {
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
264
214
|
const [match, year, month, date] = res;
|
|
265
215
|
const [nMonth, nDate] = [+month, +date];
|
|
266
216
|
const leapYear = isLeapYear(+year);
|
|
@@ -272,101 +222,38 @@ exports.Constraints = {
|
|
|
272
222
|
}
|
|
273
223
|
break;
|
|
274
224
|
case 'data-url':
|
|
275
|
-
// todo: input is of type file, do we need this format ? since value is always of type file object
|
|
276
|
-
//res = dataUrlRegex.exec(input.trim());
|
|
277
|
-
//valid = res != null;
|
|
278
225
|
valid = true;
|
|
279
226
|
break;
|
|
280
227
|
}
|
|
281
228
|
return { valid, value };
|
|
282
229
|
},
|
|
283
|
-
//todo : add support for date
|
|
284
|
-
/**
|
|
285
|
-
* Implementation of minimum constraint
|
|
286
|
-
* @param constraint `minimum` property of the form object
|
|
287
|
-
* @param value value of the form object
|
|
288
|
-
* @return {@link ValidationResult | validation result}
|
|
289
|
-
*/
|
|
290
230
|
minimum: (constraint, value) => {
|
|
291
231
|
return { valid: value >= constraint, value };
|
|
292
232
|
},
|
|
293
|
-
//todo : add support for date
|
|
294
|
-
/**
|
|
295
|
-
* Implementation of maximum constraint
|
|
296
|
-
* @param constraint `maximum` property of the form object
|
|
297
|
-
* @param value value of the form object
|
|
298
|
-
* @return {@link ValidationResult | validation result}
|
|
299
|
-
*/
|
|
300
233
|
maximum: (constraint, value) => {
|
|
301
234
|
return { valid: value <= constraint, value };
|
|
302
235
|
},
|
|
303
|
-
/**
|
|
304
|
-
* Implementation of exclusiveMinimum constraint
|
|
305
|
-
* @param constraint `minimum` property of the form object
|
|
306
|
-
* @param value value of the form object
|
|
307
|
-
* @return {@link ValidationResult | validation result}
|
|
308
|
-
*/
|
|
309
236
|
exclusiveMinimum: (constraint, value) => {
|
|
310
237
|
return { valid: value > constraint, value };
|
|
311
238
|
},
|
|
312
|
-
//todo : add support for date
|
|
313
|
-
/**
|
|
314
|
-
* Implementation of exclusiveMaximum constraint
|
|
315
|
-
* @param constraint `maximum` property of the form object
|
|
316
|
-
* @param value value of the form object
|
|
317
|
-
* @return {@link ValidationResult | validation result}
|
|
318
|
-
*/
|
|
319
239
|
exclusiveMaximum: (constraint, value) => {
|
|
320
240
|
return { valid: value < constraint, value };
|
|
321
241
|
},
|
|
322
|
-
/**
|
|
323
|
-
* Implementation of the minItems constraint
|
|
324
|
-
* @param constraint `minItems` constraint from object
|
|
325
|
-
* @param value value of the form object
|
|
326
|
-
*/
|
|
327
242
|
minItems: (constraint, value) => {
|
|
328
243
|
return { valid: (value instanceof Array) && value.length >= constraint, value };
|
|
329
244
|
},
|
|
330
|
-
/**
|
|
331
|
-
* Implementation of the maxItems constraint
|
|
332
|
-
* @param constraint `maxItems` constraint from object
|
|
333
|
-
* @param value value of the form object
|
|
334
|
-
*/
|
|
335
245
|
maxItems: (constraint, value) => {
|
|
336
246
|
return { valid: (value instanceof Array) && value.length <= constraint, value };
|
|
337
247
|
},
|
|
338
|
-
/**
|
|
339
|
-
* Implementation of the uniqueItems constraint
|
|
340
|
-
* @param constraint `uniqueItems` constraint from object
|
|
341
|
-
* @param value value of the form object
|
|
342
|
-
*/
|
|
343
248
|
uniqueItems: (constraint, value) => {
|
|
344
249
|
return { valid: !constraint || ((value instanceof Array) && value.length === new Set(value).size), value };
|
|
345
250
|
},
|
|
346
|
-
/**
|
|
347
|
-
* Implementation of minLength constraint
|
|
348
|
-
* @param constraint `minLength` property of the form object
|
|
349
|
-
* @param value value of the form object
|
|
350
|
-
* @return {@link ValidationResult | validation result}
|
|
351
|
-
*/
|
|
352
251
|
minLength: (constraint, value) => {
|
|
353
|
-
return
|
|
252
|
+
return { ...Constraints.minimum(constraint, typeof value === 'string' ? value.length : 0), value };
|
|
354
253
|
},
|
|
355
|
-
/**
|
|
356
|
-
* Implementation of maxLength constraint
|
|
357
|
-
* @param constraint `maxLength` property of the form object
|
|
358
|
-
* @param value value of the form object
|
|
359
|
-
* @return {@link ValidationResult | validation result}
|
|
360
|
-
*/
|
|
361
254
|
maxLength: (constraint, value) => {
|
|
362
|
-
return
|
|
255
|
+
return { ...Constraints.maximum(constraint, typeof value === 'string' ? value.length : 0), value };
|
|
363
256
|
},
|
|
364
|
-
/**
|
|
365
|
-
* Implementation of pattern constraint
|
|
366
|
-
* @param constraint `pattern` property of the form object
|
|
367
|
-
* @param value value of the form object
|
|
368
|
-
* @return {@link ValidationResult | validation result}
|
|
369
|
-
*/
|
|
370
257
|
pattern: (constraint, value) => {
|
|
371
258
|
let regex;
|
|
372
259
|
if (typeof constraint === 'string') {
|
|
@@ -377,33 +264,16 @@ exports.Constraints = {
|
|
|
377
264
|
}
|
|
378
265
|
return { valid: regex.test(value), value };
|
|
379
266
|
},
|
|
380
|
-
/**
|
|
381
|
-
* Implementation of required constraint
|
|
382
|
-
* @param constraint `required` property of the form object
|
|
383
|
-
* @param value value of the form object
|
|
384
|
-
* @return {@link ValidationResult | validation result}
|
|
385
|
-
*/
|
|
386
267
|
required: (constraint, value) => {
|
|
387
268
|
const valid = constraint ? value != null && value !== '' : true;
|
|
388
269
|
return { valid, value };
|
|
389
270
|
},
|
|
390
|
-
/**
|
|
391
|
-
* Implementation of enum constraint
|
|
392
|
-
* @param constraint `enum` property of the form object
|
|
393
|
-
* @param value value of the form object
|
|
394
|
-
* @return {@link ValidationResult | validation result}
|
|
395
|
-
*/
|
|
396
271
|
enum: (constraint, value) => {
|
|
397
272
|
return {
|
|
398
273
|
valid: constraint.indexOf(value) > -1,
|
|
399
274
|
value
|
|
400
275
|
};
|
|
401
276
|
},
|
|
402
|
-
/**
|
|
403
|
-
*
|
|
404
|
-
* @param constraint
|
|
405
|
-
* @param value
|
|
406
|
-
*/
|
|
407
277
|
accept: (constraint, value) => {
|
|
408
278
|
if (!constraint || constraint.length === 0 || value === null || value === undefined) {
|
|
409
279
|
return {
|
|
@@ -418,15 +288,13 @@ exports.Constraints = {
|
|
|
418
288
|
value
|
|
419
289
|
};
|
|
420
290
|
},
|
|
421
|
-
/**
|
|
422
|
-
* @param constraint
|
|
423
|
-
* @param value
|
|
424
|
-
*/
|
|
425
291
|
maxFileSize: (constraint, value) => {
|
|
426
|
-
const sizeLimit = typeof constraint === 'string' ?
|
|
292
|
+
const sizeLimit = typeof constraint === 'string' ? getFileSizeInBytes(constraint) : constraint;
|
|
427
293
|
return {
|
|
428
|
-
valid: !(value instanceof
|
|
294
|
+
valid: !(value instanceof FileObject) || value.size <= sizeLimit,
|
|
429
295
|
value
|
|
430
296
|
};
|
|
431
297
|
}
|
|
432
298
|
};
|
|
299
|
+
|
|
300
|
+
export { Constraints, ValidConstraints, coerceType };
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.22",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
7
|
-
"
|
|
7
|
+
"type": "module",
|
|
8
|
+
"module": "lib/esm/index.js",
|
|
9
|
+
"types": "lib/esm/index.d.ts",
|
|
10
|
+
"main": "lib/cjs/index.cjs",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./lib/esm/index.js"
|
|
13
|
+
},
|
|
8
14
|
"directories": {
|
|
9
15
|
"lib": "lib",
|
|
10
16
|
"source": "src",
|
|
@@ -24,21 +30,22 @@
|
|
|
24
30
|
"access": "public"
|
|
25
31
|
},
|
|
26
32
|
"scripts": {
|
|
27
|
-
"test": "jest --silent",
|
|
33
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --silent",
|
|
28
34
|
"eslint": "npx eslint src/**",
|
|
29
35
|
"eslint:fix": "npx eslint --fix src/**",
|
|
30
|
-
"test:ci": "jest --silent --coverage",
|
|
31
|
-
"
|
|
36
|
+
"test:ci": "NODE_OPTIONS=--experimental-vm-modules jest --silent --coverage",
|
|
37
|
+
"prebuild": "npm run clean && npm run eslint",
|
|
38
|
+
"build": "rollup -c rollup.config.js",
|
|
32
39
|
"clean": "rm -rf lib target",
|
|
33
40
|
"prepublishOnly": "npm run build && npm run test",
|
|
34
41
|
"docs": "npx typedoc --options .typedoc.cjs"
|
|
35
42
|
},
|
|
36
43
|
"dependencies": {
|
|
37
|
-
"@adobe/json-formula": "
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
44
|
+
"@adobe/json-formula": "0.1.50",
|
|
45
|
+
"@aemforms/af-formatters": "^0.22.22"
|
|
39
46
|
},
|
|
40
47
|
"devDependencies": {
|
|
41
|
-
"@types/jest": "
|
|
48
|
+
"@types/jest": "29.2.4",
|
|
42
49
|
"@types/lodash": "^4.14.171",
|
|
43
50
|
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
|
44
51
|
"@typescript-eslint/parser": "^4.28.2",
|
|
@@ -50,11 +57,12 @@
|
|
|
50
57
|
"eslint-plugin-node": "^11.1.0",
|
|
51
58
|
"eslint-plugin-promise": "^5.1.0",
|
|
52
59
|
"form-data": "^4.0.0",
|
|
53
|
-
"jest": "
|
|
60
|
+
"jest": "29.3",
|
|
61
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
54
62
|
"jest-junit": "^12.2.0",
|
|
55
63
|
"nock": "^13.1.3",
|
|
56
64
|
"node-fetch": "^2.6.1",
|
|
57
|
-
"ts-jest": "
|
|
65
|
+
"ts-jest": "29.0",
|
|
58
66
|
"typedoc": "0.22.11",
|
|
59
67
|
"typedoc-plugin-markdown": "3.11.13",
|
|
60
68
|
"typescript": "^4.3.5"
|
package/lib/Checkbox.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import Field from './Field';
|
|
2
|
-
/**
|
|
3
|
-
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
4
|
-
*/
|
|
5
|
-
declare class Checkbox extends Field {
|
|
6
|
-
private offValue;
|
|
7
|
-
/**
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
_getConstraintObject(): {
|
|
11
|
-
type: (constraint: string, inputVal: any) => {
|
|
12
|
-
valid: boolean;
|
|
13
|
-
value: any;
|
|
14
|
-
};
|
|
15
|
-
format: (constraint: string, input: string | null) => {
|
|
16
|
-
value: string | null;
|
|
17
|
-
valid: boolean;
|
|
18
|
-
};
|
|
19
|
-
minimum: (constraint: number, value: number) => {
|
|
20
|
-
valid: boolean;
|
|
21
|
-
value: number;
|
|
22
|
-
};
|
|
23
|
-
maximum: (constraint: number, value: number) => {
|
|
24
|
-
valid: boolean;
|
|
25
|
-
value: number;
|
|
26
|
-
};
|
|
27
|
-
exclusiveMinimum: (constraint: number, value: number) => {
|
|
28
|
-
valid: boolean;
|
|
29
|
-
value: number;
|
|
30
|
-
};
|
|
31
|
-
exclusiveMaximum: (constraint: number, value: number) => {
|
|
32
|
-
valid: boolean;
|
|
33
|
-
value: number;
|
|
34
|
-
};
|
|
35
|
-
minItems: <T>(constraint: number, value: T[]) => {
|
|
36
|
-
valid: boolean;
|
|
37
|
-
value: T[];
|
|
38
|
-
};
|
|
39
|
-
maxItems: <T_1>(constraint: number, value: T_1[]) => {
|
|
40
|
-
valid: boolean;
|
|
41
|
-
value: T_1[];
|
|
42
|
-
};
|
|
43
|
-
uniqueItems: <T_2>(constraint: boolean, value: T_2[]) => {
|
|
44
|
-
valid: boolean;
|
|
45
|
-
value: T_2[];
|
|
46
|
-
};
|
|
47
|
-
minLength: (constraint: number, value: string) => {
|
|
48
|
-
value: string;
|
|
49
|
-
valid: boolean;
|
|
50
|
-
};
|
|
51
|
-
maxLength: (constraint: number, value: string) => {
|
|
52
|
-
value: string;
|
|
53
|
-
valid: boolean;
|
|
54
|
-
};
|
|
55
|
-
pattern: (constraint: string | RegExp, value: string) => {
|
|
56
|
-
valid: boolean;
|
|
57
|
-
value: string;
|
|
58
|
-
};
|
|
59
|
-
required: (constraint: boolean, value: any) => {
|
|
60
|
-
valid: boolean;
|
|
61
|
-
value: any;
|
|
62
|
-
};
|
|
63
|
-
enum: (constraint: any[], value: any) => {
|
|
64
|
-
valid: boolean;
|
|
65
|
-
value: any;
|
|
66
|
-
};
|
|
67
|
-
accept: (constraint: string[], value: any) => {
|
|
68
|
-
valid: boolean;
|
|
69
|
-
value: any;
|
|
70
|
-
};
|
|
71
|
-
maxFileSize: (constraint: string | number, value: any) => {
|
|
72
|
-
valid: boolean;
|
|
73
|
-
value: any;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
protected _getDefaults(): {
|
|
77
|
-
enforceEnum: boolean;
|
|
78
|
-
readOnly: boolean;
|
|
79
|
-
enabled: boolean;
|
|
80
|
-
visible: boolean;
|
|
81
|
-
type: string | undefined;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Returns the `enum` constraints from the json
|
|
85
|
-
*/
|
|
86
|
-
get enum(): any[];
|
|
87
|
-
}
|
|
88
|
-
export default Checkbox;
|
package/lib/Checkbox.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
14
|
-
const ValidationUtils_1 = require("./utils/ValidationUtils");
|
|
15
|
-
/**
|
|
16
|
-
* @param offValue
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
const requiredConstraint = (offValue) => (constraint, value) => {
|
|
20
|
-
const valid = ValidationUtils_1.Constraints.required(constraint, value).valid && (!constraint || value != offValue);
|
|
21
|
-
return { valid, value };
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
25
|
-
*/
|
|
26
|
-
class Checkbox extends Field_1.default {
|
|
27
|
-
offValue() {
|
|
28
|
-
const opts = this.enum;
|
|
29
|
-
return opts.length > 1 ? opts[1] : null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
_getConstraintObject() {
|
|
35
|
-
const baseConstraints = Object.assign({}, super._getConstraintObject());
|
|
36
|
-
baseConstraints.required = requiredConstraint(this.offValue());
|
|
37
|
-
return baseConstraints;
|
|
38
|
-
}
|
|
39
|
-
_getDefaults() {
|
|
40
|
-
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true });
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the `enum` constraints from the json
|
|
44
|
-
*/
|
|
45
|
-
get enum() {
|
|
46
|
-
return this._jsonModel.enum || [];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.default = Checkbox;
|
package/lib/CheckboxGroup.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
14
|
-
/**
|
|
15
|
-
* Implementation of CheckBoxGroup runtime model which extends from {@link Field | field}
|
|
16
|
-
*/
|
|
17
|
-
class CheckboxGroup extends Field_1.default {
|
|
18
|
-
/**
|
|
19
|
-
* @param params
|
|
20
|
-
* @param _options
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
constructor(params, _options) {
|
|
24
|
-
super(params, _options);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* converts the fallback type, if required, to an array. Since checkbox-group has an array type
|
|
28
|
-
* @protected
|
|
29
|
-
*/
|
|
30
|
-
_getFallbackType() {
|
|
31
|
-
const fallbackType = super._getFallbackType();
|
|
32
|
-
if (typeof fallbackType === 'string') {
|
|
33
|
-
return `${fallbackType}[]`;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return 'string[]';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
_getDefaults() {
|
|
40
|
-
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true, enum: [] });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.default = CheckboxGroup;
|
package/lib/DateField.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
*
|
|
4
|
-
* * Copyright 2022 Adobe, Inc.
|
|
5
|
-
* *
|
|
6
|
-
* * 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.
|
|
7
|
-
* *
|
|
8
|
-
* * 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.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
16
|
-
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
17
|
-
class DateField extends Field_1.default {
|
|
18
|
-
_applyDefaults() {
|
|
19
|
-
super._applyDefaults();
|
|
20
|
-
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
21
|
-
if (!this._jsonModel.editFormat) {
|
|
22
|
-
this._jsonModel.editFormat = 'short';
|
|
23
|
-
}
|
|
24
|
-
if (!this._jsonModel.displayFormat) {
|
|
25
|
-
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
26
|
-
}
|
|
27
|
-
if (!this._jsonModel.placeholder) {
|
|
28
|
-
this._jsonModel.placeholder = (0, af_formatters_1.getSkeleton)(this._jsonModel.editFormat, locale);
|
|
29
|
-
}
|
|
30
|
-
if (!this._jsonModel.description) {
|
|
31
|
-
this._jsonModel.description = `To enter today's date use ${(0, af_formatters_1.formatDate)(new Date(), locale, this._jsonModel.editFormat)}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = DateField;
|