@aemforms/af-core 0.22.26 → 0.22.30
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/lib/cjs/index.cjs +345 -1886
- package/lib/esm/BaseNode-d78cc1b0.js +478 -0
- package/lib/esm/BaseNode.d.ts +1 -1
- package/lib/esm/BaseNode.js +26 -454
- package/lib/esm/Checkbox.js +37 -1
- package/lib/esm/CheckboxGroup.js +38 -1
- package/lib/esm/Container.d.ts +6 -1
- package/lib/esm/Container.js +108 -19
- package/lib/esm/DateField.js +38 -2
- package/lib/esm/Field.d.ts +2 -2
- package/lib/esm/Field.js +62 -26
- package/lib/esm/Fieldset.js +36 -3
- package/lib/esm/FileObject.js +23 -1
- package/lib/esm/FileUpload.js +34 -1
- package/lib/esm/Form.d.ts +1 -1
- package/lib/esm/Form.js +40 -8
- package/lib/esm/FormInstance.js +53 -5
- package/lib/esm/FormMetaData.js +26 -1
- package/lib/esm/InstanceManager.js +35 -8
- package/lib/esm/Node.js +25 -1
- package/lib/esm/Scriptable.js +29 -2
- package/lib/esm/controller/EventQueue.js +23 -1
- package/lib/esm/controller/Events.d.ts +1 -1
- package/lib/esm/controller/Events.js +41 -19
- package/lib/esm/controller/Logger.d.ts +2 -2
- package/lib/esm/controller/Logger.js +23 -1
- package/lib/esm/data/DataGroup.js +24 -1
- package/lib/esm/data/DataValue.js +23 -1
- package/lib/esm/data/EmptyDataValue.js +23 -1
- package/lib/esm/index.js +55 -21
- package/lib/esm/rules/FunctionRuntime.d.ts +3 -3
- package/lib/esm/rules/FunctionRuntime.js +31 -6
- package/lib/esm/rules/RuleEngine.js +30 -1
- package/lib/esm/types/Json.d.ts +16 -16
- package/lib/esm/types/Json.js +24 -2
- package/lib/esm/types/Model.d.ts +4 -4
- package/lib/esm/types/Model.js +23 -1
- package/lib/esm/types/index.js +22 -2
- package/lib/esm/utils/DataRefParser.d.ts +2 -2
- package/lib/esm/utils/DataRefParser.js +31 -6
- package/lib/esm/utils/Fetch.d.ts +1 -1
- package/lib/esm/utils/Fetch.js +24 -2
- package/lib/esm/utils/FormCreationUtils.js +40 -2
- package/lib/esm/utils/FormUtils.js +33 -8
- package/lib/esm/utils/JsonUtils.js +34 -11
- package/lib/esm/utils/LogUtils.js +23 -1
- package/lib/esm/utils/SchemaUtils.js +24 -2
- package/lib/esm/utils/TranslationUtils.d.ts +1 -1
- package/lib/esm/utils/TranslationUtils.js +32 -9
- package/lib/esm/utils/ValidationUtils.d.ts +4 -4
- package/lib/esm/utils/ValidationUtils.js +30 -4
- package/package.json +14 -2
- package/lib/browser/afb-events.js +0 -151
- package/lib/browser/afb-runtime.js +0 -3620
|
@@ -1,8 +1,31 @@
|
|
|
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
|
+
|
|
1
21
|
import { isFile } from './JsonUtils.js';
|
|
2
22
|
import { FileObject } from '../FileObject.js';
|
|
23
|
+
import '../types/Json.js';
|
|
24
|
+
import './SchemaUtils.js';
|
|
25
|
+
|
|
3
26
|
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
|
|
4
27
|
const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
|
|
5
|
-
|
|
28
|
+
const randomWord = (l) => {
|
|
6
29
|
const ret = [];
|
|
7
30
|
for (let i = 0; i <= l; i++) {
|
|
8
31
|
const randIndex = Math.floor(Math.random() * (chars.length));
|
|
@@ -10,10 +33,10 @@ export const randomWord = (l) => {
|
|
|
10
33
|
}
|
|
11
34
|
return ret.join('');
|
|
12
35
|
};
|
|
13
|
-
|
|
36
|
+
const isEmpty = (value) => {
|
|
14
37
|
return value === '' || value === null || value === undefined;
|
|
15
38
|
};
|
|
16
|
-
|
|
39
|
+
const getAttachments = (input) => {
|
|
17
40
|
const items = input.items || [];
|
|
18
41
|
return items?.reduce((acc, item) => {
|
|
19
42
|
let ret = null;
|
|
@@ -40,7 +63,7 @@ export const getAttachments = (input) => {
|
|
|
40
63
|
return Object.assign(acc, ret);
|
|
41
64
|
}, {});
|
|
42
65
|
};
|
|
43
|
-
|
|
66
|
+
const getFileSizeInBytes = (str) => {
|
|
44
67
|
let retVal = 0;
|
|
45
68
|
if (typeof str === 'string') {
|
|
46
69
|
const matches = fileSizeRegex.exec(str.trim());
|
|
@@ -55,7 +78,7 @@ const sizeToBytes = (size, symbol) => {
|
|
|
55
78
|
const i = Math.pow(1024, sizes[symbol]);
|
|
56
79
|
return Math.round(size * i);
|
|
57
80
|
};
|
|
58
|
-
|
|
81
|
+
const IdGenerator = function* (initial = 50) {
|
|
59
82
|
const initialize = function () {
|
|
60
83
|
const arr = [];
|
|
61
84
|
for (let i = 0; i < initial; i++) {
|
|
@@ -80,11 +103,11 @@ export const IdGenerator = function* (initial = 50) {
|
|
|
80
103
|
}
|
|
81
104
|
} while (ids.length > 0);
|
|
82
105
|
};
|
|
83
|
-
|
|
106
|
+
const isDataUrl = (str) => {
|
|
84
107
|
const dataUrlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
85
108
|
return dataUrlRegex.exec(str.trim()) != null;
|
|
86
109
|
};
|
|
87
|
-
|
|
110
|
+
const extractFileInfo = (file) => {
|
|
88
111
|
if (file !== null) {
|
|
89
112
|
let retVal = null;
|
|
90
113
|
if (file instanceof FileObject) {
|
|
@@ -160,7 +183,7 @@ export const extractFileInfo = (file) => {
|
|
|
160
183
|
return null;
|
|
161
184
|
}
|
|
162
185
|
};
|
|
163
|
-
|
|
186
|
+
const dataURItoBlob = (dataURI) => {
|
|
164
187
|
const regex = /^data:([a-z]+\/[a-z0-9-+.]+)?(?:;name=([^;]+))?(;base64)?,(.+)$/;
|
|
165
188
|
const groups = regex.exec(dataURI);
|
|
166
189
|
if (groups !== null) {
|
|
@@ -185,3 +208,5 @@ export const dataURItoBlob = (dataURI) => {
|
|
|
185
208
|
return null;
|
|
186
209
|
}
|
|
187
210
|
};
|
|
211
|
+
|
|
212
|
+
export { IdGenerator, dataURItoBlob, extractFileInfo, getAttachments, getFileSizeInBytes, isDataUrl, isEmpty, randomWord };
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
|
|
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 { constraintProps } from '../types/Json.js';
|
|
2
22
|
import { defaultFieldTypes } from './SchemaUtils.js';
|
|
3
|
-
|
|
23
|
+
|
|
24
|
+
const getProperty = (data, key, def) => {
|
|
4
25
|
if (key in data) {
|
|
5
26
|
return data[key];
|
|
6
27
|
}
|
|
@@ -12,27 +33,27 @@ export const getProperty = (data, key, def) => {
|
|
|
12
33
|
}
|
|
13
34
|
return def;
|
|
14
35
|
};
|
|
15
|
-
|
|
36
|
+
const isFile = function (item) {
|
|
16
37
|
return (item?.type === 'file' || item?.type === 'file[]') ||
|
|
17
38
|
((item?.type === 'string' || item?.type === 'string[]') &&
|
|
18
39
|
(item?.format === 'binary' || item?.format === 'data-url'));
|
|
19
40
|
};
|
|
20
|
-
|
|
41
|
+
const checkIfConstraintsArePresent = function (item) {
|
|
21
42
|
return constraintProps.some(cp => item[cp] !== undefined);
|
|
22
43
|
};
|
|
23
|
-
|
|
44
|
+
const isCheckbox = function (item) {
|
|
24
45
|
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
25
46
|
return fieldType === 'checkbox';
|
|
26
47
|
};
|
|
27
|
-
|
|
48
|
+
const isCheckboxGroup = function (item) {
|
|
28
49
|
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
29
50
|
return fieldType === 'checkbox-group';
|
|
30
51
|
};
|
|
31
|
-
|
|
52
|
+
const isDateField = function (item) {
|
|
32
53
|
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
33
54
|
return (fieldType === 'text-input' && item?.format === 'date') || fieldType === 'date-input';
|
|
34
55
|
};
|
|
35
|
-
|
|
56
|
+
function deepClone(obj, idGenerator) {
|
|
36
57
|
let result;
|
|
37
58
|
if (obj instanceof Array) {
|
|
38
59
|
result = [];
|
|
@@ -52,7 +73,7 @@ export function deepClone(obj, idGenerator) {
|
|
|
52
73
|
}
|
|
53
74
|
return result;
|
|
54
75
|
}
|
|
55
|
-
|
|
76
|
+
function checkIfKeyAdded(currentObj, prevObj, objKey) {
|
|
56
77
|
if (currentObj != null && prevObj != null) {
|
|
57
78
|
const newPrvObj = { ...prevObj };
|
|
58
79
|
newPrvObj[objKey] = currentObj[objKey];
|
|
@@ -63,10 +84,10 @@ export function checkIfKeyAdded(currentObj, prevObj, objKey) {
|
|
|
63
84
|
return false;
|
|
64
85
|
}
|
|
65
86
|
}
|
|
66
|
-
|
|
87
|
+
const jsonString = (obj) => {
|
|
67
88
|
return JSON.stringify(obj, null, 2);
|
|
68
89
|
};
|
|
69
|
-
|
|
90
|
+
const isRepeatable = (obj) => {
|
|
70
91
|
return ((obj.repeatable &&
|
|
71
92
|
((obj.minOccur === undefined && obj.maxOccur === undefined) ||
|
|
72
93
|
(obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
|
|
@@ -74,3 +95,5 @@ export const isRepeatable = (obj) => {
|
|
|
74
95
|
(obj.minOccur !== undefined && obj.minOccur >= 0) ||
|
|
75
96
|
(obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
|
|
76
97
|
};
|
|
98
|
+
|
|
99
|
+
export { checkIfConstraintsArePresent, checkIfKeyAdded, deepClone, getProperty, isCheckbox, isCheckboxGroup, isDateField, isFile, isRepeatable, jsonString };
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
|
|
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
|
+
const logFormCallbacks = (callbacks) => {
|
|
2
22
|
const s = Object.entries(callbacks).map(([id, fn]) => {
|
|
3
23
|
return `${id} : ${fn.length}`;
|
|
4
24
|
}).join(' ');
|
|
5
25
|
console.log(s);
|
|
6
26
|
};
|
|
27
|
+
|
|
28
|
+
export { logFormCallbacks };
|
|
@@ -1,3 +1,23 @@
|
|
|
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
|
+
|
|
1
21
|
const objToMap = (o) => new Map(Object.entries(o));
|
|
2
22
|
const stringViewTypes = objToMap({ 'date': 'date-input', 'data-url': 'file-input', 'binary': 'file-input' });
|
|
3
23
|
const typeToViewTypes = objToMap({
|
|
@@ -9,7 +29,7 @@ const typeToViewTypes = objToMap({
|
|
|
9
29
|
'file[]': 'file-input'
|
|
10
30
|
});
|
|
11
31
|
const arrayTypes = ['string[]', 'boolean[]', 'number[]', 'array'];
|
|
12
|
-
|
|
32
|
+
const defaultFieldTypes = (schema) => {
|
|
13
33
|
const type = schema.type || 'string';
|
|
14
34
|
if ('enum' in schema) {
|
|
15
35
|
const enums = schema.enum;
|
|
@@ -66,6 +86,8 @@ const fieldSchema = (input) => {
|
|
|
66
86
|
};
|
|
67
87
|
}
|
|
68
88
|
};
|
|
69
|
-
|
|
89
|
+
const exportDataSchema = (form) => {
|
|
70
90
|
return fieldSchema(form);
|
|
71
91
|
};
|
|
92
|
+
|
|
93
|
+
export { defaultFieldTypes, exportDataSchema };
|
|
@@ -2,7 +2,7 @@ import { FieldJson, FieldsetJson, FormJson } from '../types/index.js';
|
|
|
2
2
|
export declare const TRANSLATION_TOKEN = "##";
|
|
3
3
|
export declare const TRANSLATION_ID = "afs:translationIds";
|
|
4
4
|
export declare const CUSTOM_PROPS_KEY = "properties";
|
|
5
|
-
|
|
5
|
+
type formElementJson = FieldJson | FieldsetJson | FormJson | any;
|
|
6
6
|
export declare const invalidateTranslation: (input: formElementJson, updates: any) => void;
|
|
7
7
|
export declare const addTranslationId: (input: formElementJson, additionalTranslationProps?: string[]) => formElementJson;
|
|
8
8
|
export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 { translationProps } from '../types/Json.js';
|
|
22
|
+
|
|
23
|
+
const TRANSLATION_TOKEN = '##';
|
|
24
|
+
const TRANSLATION_ID = 'afs:translationIds';
|
|
25
|
+
const CUSTOM_PROPS_KEY = 'properties';
|
|
5
26
|
const defaultBcp47LangTags = [
|
|
6
27
|
'de-DE',
|
|
7
28
|
'en-US',
|
|
@@ -14,14 +35,14 @@ const defaultBcp47LangTags = [
|
|
|
14
35
|
'zh-CN',
|
|
15
36
|
'zh-TW'
|
|
16
37
|
];
|
|
17
|
-
|
|
38
|
+
const invalidateTranslation = (input, updates) => {
|
|
18
39
|
translationProps.forEach((prop) => {
|
|
19
40
|
if (prop in updates && input?.[CUSTOM_PROPS_KEY]?.[TRANSLATION_ID]?.[prop]) {
|
|
20
41
|
delete input?.[CUSTOM_PROPS_KEY]?.[TRANSLATION_ID]?.[prop];
|
|
21
42
|
}
|
|
22
43
|
});
|
|
23
44
|
};
|
|
24
|
-
|
|
45
|
+
const addTranslationId = (input, additionalTranslationProps = []) => {
|
|
25
46
|
const model = input;
|
|
26
47
|
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
27
48
|
_createTranslationId(model, '', transProps);
|
|
@@ -84,7 +105,7 @@ const _createTranslationObj = (input, translationObj, translationProps) => {
|
|
|
84
105
|
}
|
|
85
106
|
});
|
|
86
107
|
};
|
|
87
|
-
|
|
108
|
+
const getOrElse = (input, key, defaultValue = null) => {
|
|
88
109
|
if (!key) {
|
|
89
110
|
return defaultValue;
|
|
90
111
|
}
|
|
@@ -96,13 +117,13 @@ export const getOrElse = (input, key, defaultValue = null) => {
|
|
|
96
117
|
}
|
|
97
118
|
return index == arr.length ? objValue : defaultValue;
|
|
98
119
|
};
|
|
99
|
-
|
|
120
|
+
const createTranslationObj = (input, additionalTranslationProps = []) => {
|
|
100
121
|
const obj = {};
|
|
101
122
|
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
102
123
|
_createTranslationObj(input, obj, transProps);
|
|
103
124
|
return obj;
|
|
104
125
|
};
|
|
105
|
-
|
|
126
|
+
const createTranslationObject = (input, additionalTranslationProps = [], bcp47LangTags = []) => {
|
|
106
127
|
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
107
128
|
const inputCopy = JSON.parse(JSON.stringify(input));
|
|
108
129
|
const obj = createTranslationObj(addTranslationId(inputCopy, additionalTranslationProps), transProps);
|
|
@@ -113,3 +134,5 @@ export const createTranslationObject = (input, additionalTranslationProps = [],
|
|
|
113
134
|
}
|
|
114
135
|
return [inputCopy, allLangs];
|
|
115
136
|
};
|
|
137
|
+
|
|
138
|
+
export { CUSTOM_PROPS_KEY, TRANSLATION_ID, TRANSLATION_TOKEN, addTranslationId, createTranslationObj, createTranslationObject, getOrElse, invalidateTranslation };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
type ValidationResult = {
|
|
2
2
|
valid: boolean;
|
|
3
3
|
value: any;
|
|
4
4
|
};
|
|
5
5
|
export declare const coerceType: (param: any, type: 'string' | 'number' | 'boolean') => string | number | boolean;
|
|
6
|
-
|
|
6
|
+
type ValidConstraintsType = {
|
|
7
7
|
date: ValidationConstraints[];
|
|
8
8
|
string: ValidationConstraints[];
|
|
9
9
|
number: ValidationConstraints[];
|
|
@@ -11,8 +11,8 @@ declare type ValidConstraintsType = {
|
|
|
11
11
|
file: ValidationConstraints[];
|
|
12
12
|
};
|
|
13
13
|
export declare const ValidConstraints: ValidConstraintsType;
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export type ValidationConstraints = 'type' | 'format' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minItems' | 'maxItems' | 'uniqueItems' | 'minLength' | 'maxLength' | 'pattern' | 'required' | 'enum' | 'accept' | 'maxFileSize';
|
|
15
|
+
type ConstraintsObject = {
|
|
16
16
|
[key in ValidationConstraints]: (constraint: any, inputVal: any) => ValidationResult;
|
|
17
17
|
};
|
|
18
18
|
export declare const Constraints: ConstraintsObject;
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
|
|
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';
|
|
2
22
|
import { FileObject } from '../FileObject.js';
|
|
23
|
+
import './JsonUtils.js';
|
|
24
|
+
import '../types/Json.js';
|
|
25
|
+
import './SchemaUtils.js';
|
|
26
|
+
|
|
3
27
|
const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
|
|
4
28
|
const days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
5
29
|
const daysInMonth = (leapYear, month) => {
|
|
@@ -11,7 +35,7 @@ const daysInMonth = (leapYear, month) => {
|
|
|
11
35
|
const isLeapYear = (year) => {
|
|
12
36
|
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
13
37
|
};
|
|
14
|
-
|
|
38
|
+
const coerceType = (param, type) => {
|
|
15
39
|
let num;
|
|
16
40
|
switch (type) {
|
|
17
41
|
case 'string':
|
|
@@ -105,14 +129,14 @@ const partitionArray = (inputVal, validatorFn) => {
|
|
|
105
129
|
return acc;
|
|
106
130
|
}, [[], []]);
|
|
107
131
|
};
|
|
108
|
-
|
|
132
|
+
const ValidConstraints = {
|
|
109
133
|
date: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'format'],
|
|
110
134
|
string: ['minLength', 'maxLength', 'pattern'],
|
|
111
135
|
number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
|
|
112
136
|
array: ['minItems', 'maxItems', 'uniqueItems'],
|
|
113
137
|
file: ['accept', 'maxFileSize']
|
|
114
138
|
};
|
|
115
|
-
|
|
139
|
+
const Constraints = {
|
|
116
140
|
type: (constraint, inputVal) => {
|
|
117
141
|
let value = inputVal;
|
|
118
142
|
if (inputVal == undefined) {
|
|
@@ -272,3 +296,5 @@ export const Constraints = {
|
|
|
272
296
|
};
|
|
273
297
|
}
|
|
274
298
|
};
|
|
299
|
+
|
|
300
|
+
export { Constraints, ValidConstraints, coerceType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.30",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -29,8 +29,20 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --silent",
|
|
34
|
+
"eslint": "npx eslint src/**",
|
|
35
|
+
"eslint:fix": "npx eslint --fix src/**",
|
|
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",
|
|
39
|
+
"clean": "rm -rf lib target",
|
|
40
|
+
"prepublishOnly": "npm run build && npm run test",
|
|
41
|
+
"docs": "npx typedoc --options .typedoc.cjs"
|
|
42
|
+
},
|
|
32
43
|
"dependencies": {
|
|
33
|
-
"@adobe/json-formula": "0.1.50"
|
|
44
|
+
"@adobe/json-formula": "0.1.50",
|
|
45
|
+
"@aemforms/af-formatters": "^0.22.30"
|
|
34
46
|
},
|
|
35
47
|
"devDependencies": {
|
|
36
48
|
"@types/jest": "29.2.4",
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
class ActionImpl {
|
|
2
|
-
_metadata;
|
|
3
|
-
_type;
|
|
4
|
-
_payload;
|
|
5
|
-
_target;
|
|
6
|
-
constructor(payload, type, _metadata) {
|
|
7
|
-
this._metadata = _metadata;
|
|
8
|
-
this._payload = payload;
|
|
9
|
-
this._type = type;
|
|
10
|
-
}
|
|
11
|
-
get type() {
|
|
12
|
-
return this._type;
|
|
13
|
-
}
|
|
14
|
-
get payload() {
|
|
15
|
-
return this._payload;
|
|
16
|
-
}
|
|
17
|
-
get metadata() {
|
|
18
|
-
return this._metadata;
|
|
19
|
-
}
|
|
20
|
-
get target() {
|
|
21
|
-
return this._target;
|
|
22
|
-
}
|
|
23
|
-
get isCustomEvent() {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
payloadToJson() {
|
|
27
|
-
return this.payload;
|
|
28
|
-
}
|
|
29
|
-
toJson() {
|
|
30
|
-
return {
|
|
31
|
-
payload: this.payloadToJson(),
|
|
32
|
-
type: this.type,
|
|
33
|
-
isCustomEvent: this.isCustomEvent
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
toString() {
|
|
37
|
-
return JSON.stringify(this.toJson());
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
class Change extends ActionImpl {
|
|
41
|
-
constructor(payload, dispatch = false) {
|
|
42
|
-
super(payload, 'change', { dispatch });
|
|
43
|
-
}
|
|
44
|
-
withAdditionalChange(change) {
|
|
45
|
-
return new Change(this.payload.changes.concat(change.payload.changes), this.metadata);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class Invalid extends ActionImpl {
|
|
49
|
-
constructor(payload = {}) {
|
|
50
|
-
super(payload, 'invalid', {});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class Valid extends ActionImpl {
|
|
54
|
-
constructor(payload = {}) {
|
|
55
|
-
super(payload, 'valid', {});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
class ExecuteRule extends ActionImpl {
|
|
59
|
-
constructor(payload = {}, dispatch = false) {
|
|
60
|
-
super(payload, 'executeRule', { dispatch });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const propertyChange = (propertyName, currentValue, prevValue) => {
|
|
64
|
-
return new Change({
|
|
65
|
-
changes: [
|
|
66
|
-
{
|
|
67
|
-
propertyName,
|
|
68
|
-
currentValue,
|
|
69
|
-
prevValue
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
class Initialize extends ActionImpl {
|
|
75
|
-
constructor(payload, dispatch = false) {
|
|
76
|
-
super(payload, 'initialize', { dispatch });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
class FormLoad extends ActionImpl {
|
|
80
|
-
constructor() {
|
|
81
|
-
super({}, 'load', { dispatch: false });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class Click extends ActionImpl {
|
|
85
|
-
constructor(payload, dispatch = false) {
|
|
86
|
-
super(payload, 'click', { dispatch });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
class Blur extends ActionImpl {
|
|
90
|
-
constructor(payload, dispatch = false) {
|
|
91
|
-
super(payload, 'blur', { dispatch });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class ValidationComplete extends ActionImpl {
|
|
95
|
-
constructor(payload, dispatch = false) {
|
|
96
|
-
super(payload, 'validationComplete', { dispatch });
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
class Focus extends ActionImpl {
|
|
100
|
-
constructor() {
|
|
101
|
-
super({}, 'focus', { dispatch: false });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
class Submit extends ActionImpl {
|
|
105
|
-
constructor(payload, dispatch = false) {
|
|
106
|
-
super(payload, 'submit', { dispatch });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
class Reset extends ActionImpl {
|
|
110
|
-
constructor(payload, dispatch = false) {
|
|
111
|
-
super(payload, 'reset', { dispatch });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
class FieldChanged extends ActionImpl {
|
|
115
|
-
constructor(changes, field) {
|
|
116
|
-
super({
|
|
117
|
-
field,
|
|
118
|
-
changes
|
|
119
|
-
}, 'fieldChanged');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
class CustomEvent extends ActionImpl {
|
|
123
|
-
constructor(eventName, payload = {}, dispatch = false) {
|
|
124
|
-
super(payload, eventName, { dispatch });
|
|
125
|
-
}
|
|
126
|
-
get isCustomEvent() {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
class AddItem extends ActionImpl {
|
|
131
|
-
constructor(payload) {
|
|
132
|
-
super(payload, 'addItem');
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
class RemoveItem extends ActionImpl {
|
|
136
|
-
constructor(payload) {
|
|
137
|
-
super(payload, 'removeItem');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
class AddInstance extends ActionImpl {
|
|
141
|
-
constructor(payload) {
|
|
142
|
-
super(payload, 'addInstance');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
class RemoveInstance extends ActionImpl {
|
|
146
|
-
constructor(payload) {
|
|
147
|
-
super(payload, 'removeInstance');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Submit, Valid, ValidationComplete, propertyChange };
|