@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.
- package/package.json +2 -14
- package/lib/cjs/index.cjs +0 -7277
- package/lib/esm/BaseNode-dc59ab07.js +0 -478
- package/lib/esm/BaseNode.d.ts +0 -93
- package/lib/esm/BaseNode.js +0 -26
- package/lib/esm/Checkbox.d.ts +0 -79
- package/lib/esm/Checkbox.js +0 -63
- package/lib/esm/CheckboxGroup.d.ts +0 -18
- package/lib/esm/CheckboxGroup.js +0 -60
- package/lib/esm/Container.d.ts +0 -53
- package/lib/esm/Container.js +0 -311
- package/lib/esm/DateField.d.ts +0 -5
- package/lib/esm/DateField.js +0 -57
- package/lib/esm/Field.d.ts +0 -206
- package/lib/esm/Field.js +0 -692
- package/lib/esm/Fieldset.d.ts +0 -16
- package/lib/esm/Fieldset.js +0 -78
- package/lib/esm/FileObject.d.ts +0 -16
- package/lib/esm/FileObject.js +0 -48
- package/lib/esm/FileUpload.d.ts +0 -22
- package/lib/esm/FileUpload.js +0 -141
- package/lib/esm/Form.d.ts +0 -113
- package/lib/esm/Form.js +0 -208
- package/lib/esm/FormInstance.d.ts +0 -13
- package/lib/esm/FormInstance.js +0 -129
- package/lib/esm/FormMetaData.d.ts +0 -7
- package/lib/esm/FormMetaData.js +0 -35
- package/lib/esm/InstanceManager.d.ts +0 -9
- package/lib/esm/InstanceManager.js +0 -58
- package/lib/esm/Node.d.ts +0 -7
- package/lib/esm/Node.js +0 -40
- package/lib/esm/Scriptable.d.ts +0 -17
- package/lib/esm/Scriptable.js +0 -190
- package/lib/esm/controller/EventQueue.d.ts +0 -17
- package/lib/esm/controller/EventQueue.js +0 -108
- package/lib/esm/controller/Events.d.ts +0 -85
- package/lib/esm/controller/Events.js +0 -171
- package/lib/esm/controller/Logger.d.ts +0 -11
- package/lib/esm/controller/Logger.js +0 -52
- package/lib/esm/data/DataGroup.d.ts +0 -20
- package/lib/esm/data/DataGroup.js +0 -100
- package/lib/esm/data/DataValue.d.ts +0 -16
- package/lib/esm/data/DataValue.js +0 -68
- package/lib/esm/data/EmptyDataValue.d.ts +0 -14
- package/lib/esm/data/EmptyDataValue.js +0 -51
- package/lib/esm/index.d.ts +0 -21
- package/lib/esm/index.js +0 -55
- package/lib/esm/rules/FunctionRuntime.d.ts +0 -51
- package/lib/esm/rules/FunctionRuntime.js +0 -345
- package/lib/esm/rules/RuleEngine.d.ts +0 -12
- package/lib/esm/rules/RuleEngine.js +0 -76
- package/lib/esm/types/Json.d.ts +0 -119
- package/lib/esm/types/Json.js +0 -29
- package/lib/esm/types/Model.d.ts +0 -131
- package/lib/esm/types/Model.js +0 -30
- package/lib/esm/types/index.d.ts +0 -2
- package/lib/esm/types/index.js +0 -22
- package/lib/esm/utils/DataRefParser.d.ts +0 -27
- package/lib/esm/utils/DataRefParser.js +0 -247
- package/lib/esm/utils/Fetch.d.ts +0 -8
- package/lib/esm/utils/Fetch.js +0 -83
- package/lib/esm/utils/FormCreationUtils.d.ts +0 -9
- package/lib/esm/utils/FormCreationUtils.js +0 -112
- package/lib/esm/utils/FormUtils.d.ts +0 -12
- package/lib/esm/utils/FormUtils.js +0 -212
- package/lib/esm/utils/JsonUtils.d.ts +0 -11
- package/lib/esm/utils/JsonUtils.js +0 -99
- package/lib/esm/utils/LogUtils.d.ts +0 -4
- package/lib/esm/utils/LogUtils.js +0 -28
- package/lib/esm/utils/SchemaUtils.d.ts +0 -3
- package/lib/esm/utils/SchemaUtils.js +0 -93
- package/lib/esm/utils/TranslationUtils.d.ts +0 -11
- package/lib/esm/utils/TranslationUtils.js +0 -138
- package/lib/esm/utils/ValidationUtils.d.ts +0 -19
- package/lib/esm/utils/ValidationUtils.js +0 -300
|
@@ -1,212 +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 { isFile } from './JsonUtils.js';
|
|
22
|
-
import { FileObject } from '../FileObject.js';
|
|
23
|
-
import '../types/Json.js';
|
|
24
|
-
import './SchemaUtils.js';
|
|
25
|
-
|
|
26
|
-
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
|
|
27
|
-
const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
|
|
28
|
-
const randomWord = (l) => {
|
|
29
|
-
const ret = [];
|
|
30
|
-
for (let i = 0; i <= l; i++) {
|
|
31
|
-
const randIndex = Math.floor(Math.random() * (chars.length));
|
|
32
|
-
ret.push(chars[randIndex]);
|
|
33
|
-
}
|
|
34
|
-
return ret.join('');
|
|
35
|
-
};
|
|
36
|
-
const isEmpty = (value) => {
|
|
37
|
-
return value === '' || value === null || value === undefined;
|
|
38
|
-
};
|
|
39
|
-
const getAttachments = (input) => {
|
|
40
|
-
const items = input.items || [];
|
|
41
|
-
return items?.reduce((acc, item) => {
|
|
42
|
-
let ret = null;
|
|
43
|
-
if (item.isContainer) {
|
|
44
|
-
ret = getAttachments(item);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
if (isFile(item.getState())) {
|
|
48
|
-
ret = {};
|
|
49
|
-
const name = item.name || '';
|
|
50
|
-
const dataRef = (item.dataRef != null)
|
|
51
|
-
? item.dataRef
|
|
52
|
-
: (name.length > 0 ? item.name : undefined);
|
|
53
|
-
if (item.value instanceof Array) {
|
|
54
|
-
ret[item.id] = item.value.map((x) => {
|
|
55
|
-
return { ...x, 'dataRef': dataRef };
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else if (item.value != null) {
|
|
59
|
-
ret[item.id] = { ...item.value, 'dataRef': dataRef };
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return Object.assign(acc, ret);
|
|
64
|
-
}, {});
|
|
65
|
-
};
|
|
66
|
-
const getFileSizeInBytes = (str) => {
|
|
67
|
-
let retVal = 0;
|
|
68
|
-
if (typeof str === 'string') {
|
|
69
|
-
const matches = fileSizeRegex.exec(str.trim());
|
|
70
|
-
if (matches != null) {
|
|
71
|
-
retVal = sizeToBytes(parseFloat(matches[1]), (matches[2] || 'kb').toUpperCase());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return retVal;
|
|
75
|
-
};
|
|
76
|
-
const sizeToBytes = (size, symbol) => {
|
|
77
|
-
const sizes = { 'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4 };
|
|
78
|
-
const i = Math.pow(1024, sizes[symbol]);
|
|
79
|
-
return Math.round(size * i);
|
|
80
|
-
};
|
|
81
|
-
const IdGenerator = function* (initial = 50) {
|
|
82
|
-
const initialize = function () {
|
|
83
|
-
const arr = [];
|
|
84
|
-
for (let i = 0; i < initial; i++) {
|
|
85
|
-
arr.push(randomWord(10));
|
|
86
|
-
}
|
|
87
|
-
return arr;
|
|
88
|
-
};
|
|
89
|
-
const passedIds = {};
|
|
90
|
-
let ids = initialize();
|
|
91
|
-
do {
|
|
92
|
-
let x = ids.pop();
|
|
93
|
-
while (x in passedIds) {
|
|
94
|
-
if (ids.length === 0) {
|
|
95
|
-
ids = initialize();
|
|
96
|
-
}
|
|
97
|
-
x = ids.pop();
|
|
98
|
-
}
|
|
99
|
-
passedIds[x] = true;
|
|
100
|
-
yield ids.pop();
|
|
101
|
-
if (ids.length === 0) {
|
|
102
|
-
ids = initialize();
|
|
103
|
-
}
|
|
104
|
-
} while (ids.length > 0);
|
|
105
|
-
};
|
|
106
|
-
const isDataUrl = (str) => {
|
|
107
|
-
const dataUrlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
108
|
-
return dataUrlRegex.exec(str.trim()) != null;
|
|
109
|
-
};
|
|
110
|
-
const extractFileInfo = (file) => {
|
|
111
|
-
if (file !== null) {
|
|
112
|
-
let retVal = null;
|
|
113
|
-
if (file instanceof FileObject) {
|
|
114
|
-
retVal = file;
|
|
115
|
-
}
|
|
116
|
-
else if (typeof File !== 'undefined' && file instanceof File) {
|
|
117
|
-
retVal = {
|
|
118
|
-
name: file.name,
|
|
119
|
-
mediaType: file.type,
|
|
120
|
-
size: file.size,
|
|
121
|
-
data: file
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
else if (typeof file === 'string' && isDataUrl(file)) {
|
|
125
|
-
const result = dataURItoBlob(file);
|
|
126
|
-
if (result !== null) {
|
|
127
|
-
const { blob, name } = result;
|
|
128
|
-
retVal = {
|
|
129
|
-
name: name,
|
|
130
|
-
mediaType: blob.type,
|
|
131
|
-
size: blob.size,
|
|
132
|
-
data: blob
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
let jFile = file;
|
|
138
|
-
try {
|
|
139
|
-
jFile = JSON.parse(file);
|
|
140
|
-
retVal = jFile;
|
|
141
|
-
if (!retVal.mediaType) {
|
|
142
|
-
retVal.mediaType = retVal.type;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (ex) {
|
|
146
|
-
}
|
|
147
|
-
if (typeof jFile?.data === 'string' && isDataUrl(jFile?.data)) {
|
|
148
|
-
const result = dataURItoBlob(jFile?.data);
|
|
149
|
-
if (result !== null) {
|
|
150
|
-
const blob = result.blob;
|
|
151
|
-
retVal = {
|
|
152
|
-
name: jFile?.name,
|
|
153
|
-
mediaType: jFile?.type || jFile?.mediaType,
|
|
154
|
-
size: blob.size,
|
|
155
|
-
data: blob
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
else if (typeof jFile === 'string') {
|
|
160
|
-
const fileName = jFile.split('/').pop();
|
|
161
|
-
retVal = {
|
|
162
|
-
name: fileName,
|
|
163
|
-
mediaType: 'application/octet-stream',
|
|
164
|
-
size: 0,
|
|
165
|
-
data: jFile
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
else if (typeof jFile === 'object') {
|
|
169
|
-
retVal = {
|
|
170
|
-
name: jFile?.name,
|
|
171
|
-
mediaType: jFile?.type || jFile?.mediaType,
|
|
172
|
-
size: jFile?.size,
|
|
173
|
-
data: jFile?.data
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (retVal !== null && retVal.data != null) {
|
|
178
|
-
return new FileObject(retVal);
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
const dataURItoBlob = (dataURI) => {
|
|
187
|
-
const regex = /^data:([a-z]+\/[a-z0-9-+.]+)?(?:;name=([^;]+))?(;base64)?,(.+)$/;
|
|
188
|
-
const groups = regex.exec(dataURI);
|
|
189
|
-
if (groups !== null) {
|
|
190
|
-
const type = groups[1] || '';
|
|
191
|
-
const name = groups[2] || 'unknown';
|
|
192
|
-
const isBase64 = typeof groups[3] === 'string';
|
|
193
|
-
if (isBase64) {
|
|
194
|
-
const binary = atob(groups[4]);
|
|
195
|
-
const array = [];
|
|
196
|
-
for (let i = 0; i < binary.length; i++) {
|
|
197
|
-
array.push(binary.charCodeAt(i));
|
|
198
|
-
}
|
|
199
|
-
const blob = new window.Blob([new Uint8Array(array)], { type });
|
|
200
|
-
return { name, blob };
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
const blob = new window.Blob([groups[4]], { type });
|
|
204
|
-
return { name, blob };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
export { IdGenerator, dataURItoBlob, extractFileInfo, getAttachments, getFileSizeInBytes, isDataUrl, isEmpty, randomWord };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FieldsetJson, FieldJson } from '../types/index.js';
|
|
2
|
-
export declare const getProperty: <P>(data: any, key: string, def: P) => P;
|
|
3
|
-
export declare const isFile: (item: FieldsetJson | FieldJson) => boolean;
|
|
4
|
-
export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJson) => boolean;
|
|
5
|
-
export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
|
|
6
|
-
export declare const isCheckboxGroup: (item: FieldsetJson | FieldJson) => boolean;
|
|
7
|
-
export declare const isDateField: (item: FieldsetJson | FieldJson) => boolean;
|
|
8
|
-
export declare function deepClone(obj: any, idGenerator?: () => string): any;
|
|
9
|
-
export declare function checkIfKeyAdded(currentObj: any, prevObj: any, objKey: string): boolean;
|
|
10
|
-
export declare const jsonString: (obj: any) => string;
|
|
11
|
-
export declare const isRepeatable: (obj: FieldsetJson | FieldJson) => boolean;
|
|
@@ -1,99 +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 { constraintProps } from '../types/Json.js';
|
|
22
|
-
import { defaultFieldTypes } from './SchemaUtils.js';
|
|
23
|
-
|
|
24
|
-
const getProperty = (data, key, def) => {
|
|
25
|
-
if (key in data) {
|
|
26
|
-
return data[key];
|
|
27
|
-
}
|
|
28
|
-
else if (!key.startsWith(':')) {
|
|
29
|
-
const prefixedKey = `:${key}`;
|
|
30
|
-
if (prefixedKey in data) {
|
|
31
|
-
return data[prefixedKey];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return def;
|
|
35
|
-
};
|
|
36
|
-
const isFile = function (item) {
|
|
37
|
-
return (item?.type === 'file' || item?.type === 'file[]') ||
|
|
38
|
-
((item?.type === 'string' || item?.type === 'string[]') &&
|
|
39
|
-
(item?.format === 'binary' || item?.format === 'data-url'));
|
|
40
|
-
};
|
|
41
|
-
const checkIfConstraintsArePresent = function (item) {
|
|
42
|
-
return constraintProps.some(cp => item[cp] !== undefined);
|
|
43
|
-
};
|
|
44
|
-
const isCheckbox = function (item) {
|
|
45
|
-
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
46
|
-
return fieldType === 'checkbox';
|
|
47
|
-
};
|
|
48
|
-
const isCheckboxGroup = function (item) {
|
|
49
|
-
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
50
|
-
return fieldType === 'checkbox-group';
|
|
51
|
-
};
|
|
52
|
-
const isDateField = function (item) {
|
|
53
|
-
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
54
|
-
return (fieldType === 'text-input' && item?.format === 'date') || fieldType === 'date-input';
|
|
55
|
-
};
|
|
56
|
-
function deepClone(obj, idGenerator) {
|
|
57
|
-
let result;
|
|
58
|
-
if (obj instanceof Array) {
|
|
59
|
-
result = [];
|
|
60
|
-
result = obj.map(x => deepClone(x, idGenerator));
|
|
61
|
-
}
|
|
62
|
-
else if (typeof obj === 'object' && obj !== null) {
|
|
63
|
-
result = {};
|
|
64
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
65
|
-
result[key] = deepClone(value, idGenerator);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
result = obj;
|
|
70
|
-
}
|
|
71
|
-
if (idGenerator && result && result.id) {
|
|
72
|
-
result.id = idGenerator();
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
function checkIfKeyAdded(currentObj, prevObj, objKey) {
|
|
77
|
-
if (currentObj != null && prevObj != null) {
|
|
78
|
-
const newPrvObj = { ...prevObj };
|
|
79
|
-
newPrvObj[objKey] = currentObj[objKey];
|
|
80
|
-
const newJsonStr = jsonString(currentObj).replace(jsonString(newPrvObj), '');
|
|
81
|
-
return newJsonStr === '';
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const jsonString = (obj) => {
|
|
88
|
-
return JSON.stringify(obj, null, 2);
|
|
89
|
-
};
|
|
90
|
-
const isRepeatable = (obj) => {
|
|
91
|
-
return ((obj.repeatable &&
|
|
92
|
-
((obj.minOccur === undefined && obj.maxOccur === undefined) ||
|
|
93
|
-
(obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
|
|
94
|
-
(obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.minOccur !== 0 && obj.maxOccur !== 0) ||
|
|
95
|
-
(obj.minOccur !== undefined && obj.minOccur >= 0) ||
|
|
96
|
-
(obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export { checkIfConstraintsArePresent, checkIfKeyAdded, deepClone, getProperty, isCheckbox, isCheckboxGroup, isDateField, isFile, isRepeatable, jsonString };
|
|
@@ -1,28 +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
|
-
const logFormCallbacks = (callbacks) => {
|
|
22
|
-
const s = Object.entries(callbacks).map(([id, fn]) => {
|
|
23
|
-
return `${id} : ${fn.length}`;
|
|
24
|
-
}).join(' ');
|
|
25
|
-
console.log(s);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { logFormCallbacks };
|
|
@@ -1,93 +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
|
-
const objToMap = (o) => new Map(Object.entries(o));
|
|
22
|
-
const stringViewTypes = objToMap({ 'date': 'date-input', 'data-url': 'file-input', 'binary': 'file-input' });
|
|
23
|
-
const typeToViewTypes = objToMap({
|
|
24
|
-
'number': 'number-input',
|
|
25
|
-
'boolean': 'checkbox',
|
|
26
|
-
'object': 'panel',
|
|
27
|
-
'array': 'panel',
|
|
28
|
-
'file': 'file-input',
|
|
29
|
-
'file[]': 'file-input'
|
|
30
|
-
});
|
|
31
|
-
const arrayTypes = ['string[]', 'boolean[]', 'number[]', 'array'];
|
|
32
|
-
const defaultFieldTypes = (schema) => {
|
|
33
|
-
const type = schema.type || 'string';
|
|
34
|
-
if ('enum' in schema) {
|
|
35
|
-
const enums = schema.enum;
|
|
36
|
-
if (enums.length > 2 || arrayTypes.indexOf(type) > -1) {
|
|
37
|
-
return 'drop-down';
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return 'checkbox';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (type === 'string' || type === 'string[]') {
|
|
44
|
-
return stringViewTypes.get(schema.format) || 'text-input';
|
|
45
|
-
}
|
|
46
|
-
return typeToViewTypes.get(type) || 'text-input';
|
|
47
|
-
};
|
|
48
|
-
const fieldSchema = (input) => {
|
|
49
|
-
if ('items' in input) {
|
|
50
|
-
const fieldset = input;
|
|
51
|
-
const items = fieldset.items;
|
|
52
|
-
if (fieldset.type === 'array') {
|
|
53
|
-
return {
|
|
54
|
-
type: 'array',
|
|
55
|
-
items: fieldSchema(items[0]),
|
|
56
|
-
minItems: fieldset?.minItems,
|
|
57
|
-
maxItems: fieldset?.maxItems
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const iter = items.filter(x => x.name != null);
|
|
62
|
-
return {
|
|
63
|
-
type: 'object',
|
|
64
|
-
properties: Object.fromEntries(iter.map(item => [item.name, fieldSchema(item)])),
|
|
65
|
-
required: iter.filter(x => x.required).map(x => x.name)
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const field = input;
|
|
71
|
-
const schemaProps = ['type', 'maxLength', 'minLength', 'minimum', 'maximum', 'format', 'pattern', 'step', 'enum'];
|
|
72
|
-
const schema = schemaProps.reduce((acc, prop) => {
|
|
73
|
-
const p = prop;
|
|
74
|
-
if (prop in field && field[p] != undefined) {
|
|
75
|
-
acc[prop] = field[p];
|
|
76
|
-
}
|
|
77
|
-
return acc;
|
|
78
|
-
}, {});
|
|
79
|
-
if (field.dataRef === 'none' || Object.keys(schema).length == 0) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
title: field.label?.value,
|
|
84
|
-
description: field.description,
|
|
85
|
-
...schema
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const exportDataSchema = (form) => {
|
|
90
|
-
return fieldSchema(form);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { defaultFieldTypes, exportDataSchema };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FieldJson, FieldsetJson, FormJson } from '../types/index.js';
|
|
2
|
-
export declare const TRANSLATION_TOKEN = "##";
|
|
3
|
-
export declare const TRANSLATION_ID = "afs:translationIds";
|
|
4
|
-
export declare const CUSTOM_PROPS_KEY = "properties";
|
|
5
|
-
type formElementJson = FieldJson | FieldsetJson | FormJson | any;
|
|
6
|
-
export declare const invalidateTranslation: (input: formElementJson, updates: any) => void;
|
|
7
|
-
export declare const addTranslationId: (input: formElementJson, additionalTranslationProps?: string[]) => formElementJson;
|
|
8
|
-
export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
|
|
9
|
-
export declare const createTranslationObj: (input: formElementJson, additionalTranslationProps?: string[]) => any;
|
|
10
|
-
export declare const createTranslationObject: (input: formElementJson, additionalTranslationProps?: string[], bcp47LangTags?: string[]) => any;
|
|
11
|
-
export {};
|
|
@@ -1,138 +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 { translationProps } from '../types/Json.js';
|
|
22
|
-
|
|
23
|
-
const TRANSLATION_TOKEN = '##';
|
|
24
|
-
const TRANSLATION_ID = 'afs:translationIds';
|
|
25
|
-
const CUSTOM_PROPS_KEY = 'properties';
|
|
26
|
-
const defaultBcp47LangTags = [
|
|
27
|
-
'de-DE',
|
|
28
|
-
'en-US',
|
|
29
|
-
'es-ES',
|
|
30
|
-
'fr-FR',
|
|
31
|
-
'it-IT',
|
|
32
|
-
'ja-JP',
|
|
33
|
-
'ko-KR',
|
|
34
|
-
'pt-BR',
|
|
35
|
-
'zh-CN',
|
|
36
|
-
'zh-TW'
|
|
37
|
-
];
|
|
38
|
-
const invalidateTranslation = (input, updates) => {
|
|
39
|
-
translationProps.forEach((prop) => {
|
|
40
|
-
if (prop in updates && input?.[CUSTOM_PROPS_KEY]?.[TRANSLATION_ID]?.[prop]) {
|
|
41
|
-
delete input?.[CUSTOM_PROPS_KEY]?.[TRANSLATION_ID]?.[prop];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const addTranslationId = (input, additionalTranslationProps = []) => {
|
|
46
|
-
const model = input;
|
|
47
|
-
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
48
|
-
_createTranslationId(model, '', transProps);
|
|
49
|
-
return model;
|
|
50
|
-
};
|
|
51
|
-
const _createTranslationId = (input, path, transProps) => {
|
|
52
|
-
Object.entries(input).forEach(([key, value]) => {
|
|
53
|
-
if (typeof value == 'object') {
|
|
54
|
-
if (input instanceof Array) {
|
|
55
|
-
if (value && 'name' in value) {
|
|
56
|
-
_createTranslationId(value, `${path === '' ? path : path + TRANSLATION_TOKEN}${value.name}`, transProps);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
_createTranslationId(value, ((key === 'items') ? path : `${path === '' ? path : path + TRANSLATION_TOKEN}${key}`), transProps);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
if (':type' in input ||
|
|
65
|
-
'type' in input ||
|
|
66
|
-
'fieldType' in input) {
|
|
67
|
-
for (const transProp of transProps) {
|
|
68
|
-
if (getOrElse(input, transProp) != null) {
|
|
69
|
-
if (!(CUSTOM_PROPS_KEY in input)) {
|
|
70
|
-
input[CUSTOM_PROPS_KEY] = {};
|
|
71
|
-
}
|
|
72
|
-
if (!(TRANSLATION_ID in input[CUSTOM_PROPS_KEY])) {
|
|
73
|
-
input[CUSTOM_PROPS_KEY][TRANSLATION_ID] = {};
|
|
74
|
-
}
|
|
75
|
-
if (!(transProp in input[CUSTOM_PROPS_KEY][TRANSLATION_ID])) {
|
|
76
|
-
input[CUSTOM_PROPS_KEY][TRANSLATION_ID][transProp] = `${path}${TRANSLATION_TOKEN}${transProp}${TRANSLATION_TOKEN}${Math.floor(Math.random() * 10000) + 1}`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
const _createTranslationObj = (input, translationObj, translationProps) => {
|
|
85
|
-
Object.values(input).forEach((value) => {
|
|
86
|
-
if (typeof value == 'object') {
|
|
87
|
-
_createTranslationObj(value, translationObj, translationProps);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
for (const translationProp of translationProps) {
|
|
91
|
-
const objValue = getOrElse(input, translationProp);
|
|
92
|
-
if (objValue && input?.[CUSTOM_PROPS_KEY]?.[TRANSLATION_ID]?.[translationProp]) {
|
|
93
|
-
if (objValue instanceof Array) {
|
|
94
|
-
objValue.forEach((item, index) => {
|
|
95
|
-
if (typeof item === 'string') {
|
|
96
|
-
translationObj[`${input[CUSTOM_PROPS_KEY][TRANSLATION_ID][translationProp]}${TRANSLATION_TOKEN}${index}`] = item;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
translationObj[`${input[CUSTOM_PROPS_KEY][TRANSLATION_ID][translationProp]}`] = objValue;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
const getOrElse = (input, key, defaultValue = null) => {
|
|
109
|
-
if (!key) {
|
|
110
|
-
return defaultValue;
|
|
111
|
-
}
|
|
112
|
-
const arr = Array.isArray(key) ? key : key.split('.');
|
|
113
|
-
let objValue = input, index = 0;
|
|
114
|
-
while (index < arr.length && objValue.hasOwnProperty(arr[index])) {
|
|
115
|
-
objValue = objValue[arr[index]];
|
|
116
|
-
index++;
|
|
117
|
-
}
|
|
118
|
-
return index == arr.length ? objValue : defaultValue;
|
|
119
|
-
};
|
|
120
|
-
const createTranslationObj = (input, additionalTranslationProps = []) => {
|
|
121
|
-
const obj = {};
|
|
122
|
-
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
123
|
-
_createTranslationObj(input, obj, transProps);
|
|
124
|
-
return obj;
|
|
125
|
-
};
|
|
126
|
-
const createTranslationObject = (input, additionalTranslationProps = [], bcp47LangTags = []) => {
|
|
127
|
-
const transProps = [...translationProps, ...additionalTranslationProps];
|
|
128
|
-
const inputCopy = JSON.parse(JSON.stringify(input));
|
|
129
|
-
const obj = createTranslationObj(addTranslationId(inputCopy, additionalTranslationProps), transProps);
|
|
130
|
-
const langTags = [...defaultBcp47LangTags, ...bcp47LangTags];
|
|
131
|
-
const allLangs = {};
|
|
132
|
-
for (const langTag of langTags) {
|
|
133
|
-
allLangs[langTag] = JSON.parse(JSON.stringify(obj));
|
|
134
|
-
}
|
|
135
|
-
return [inputCopy, allLangs];
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export { CUSTOM_PROPS_KEY, TRANSLATION_ID, TRANSLATION_TOKEN, addTranslationId, createTranslationObj, createTranslationObject, getOrElse, invalidateTranslation };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
type ValidationResult = {
|
|
2
|
-
valid: boolean;
|
|
3
|
-
value: any;
|
|
4
|
-
};
|
|
5
|
-
export declare const coerceType: (param: any, type: 'string' | 'number' | 'boolean') => string | number | boolean;
|
|
6
|
-
type ValidConstraintsType = {
|
|
7
|
-
date: ValidationConstraints[];
|
|
8
|
-
string: ValidationConstraints[];
|
|
9
|
-
number: ValidationConstraints[];
|
|
10
|
-
array: ValidationConstraints[];
|
|
11
|
-
file: ValidationConstraints[];
|
|
12
|
-
};
|
|
13
|
-
export declare const ValidConstraints: ValidConstraintsType;
|
|
14
|
-
export type ValidationConstraints = 'type' | 'format' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minItems' | 'maxItems' | 'uniqueItems' | 'minLength' | 'maxLength' | 'pattern' | 'required' | 'enum' | 'accept' | 'maxFileSize';
|
|
15
|
-
type ConstraintsObject = {
|
|
16
|
-
[key in ValidationConstraints]: (constraint: any, inputVal: any) => ValidationResult;
|
|
17
|
-
};
|
|
18
|
-
export declare const Constraints: ConstraintsObject;
|
|
19
|
-
export {};
|