@aemforms/af-core 0.15.0
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 +5 -0
- package/README.md +34 -0
- package/lib/BaseNode.d.ts +117 -0
- package/lib/BaseNode.js +368 -0
- package/lib/Checkbox.d.ts +80 -0
- package/lib/Checkbox.js +49 -0
- package/lib/CheckboxGroup.d.ts +30 -0
- package/lib/CheckboxGroup.js +40 -0
- package/lib/Container.d.ts +336 -0
- package/lib/Container.js +279 -0
- package/lib/Field.d.ts +185 -0
- package/lib/Field.js +432 -0
- package/lib/Fieldset.d.ts +31 -0
- package/lib/Fieldset.js +97 -0
- package/lib/FileObject.d.ts +17 -0
- package/lib/FileObject.js +30 -0
- package/lib/FileUpload.d.ts +42 -0
- package/lib/FileUpload.js +299 -0
- package/lib/Form.d.ts +413 -0
- package/lib/Form.js +247 -0
- package/lib/FormInstance.d.ts +26 -0
- package/lib/FormInstance.js +116 -0
- package/lib/FormMetaData.d.ts +11 -0
- package/lib/FormMetaData.js +28 -0
- package/lib/Node.d.ts +12 -0
- package/lib/Node.js +27 -0
- package/lib/Scriptable.d.ts +27 -0
- package/lib/Scriptable.js +216 -0
- package/lib/controller/Controller.d.ts +207 -0
- package/lib/controller/Controller.js +263 -0
- package/lib/controller/EventQueue.d.ts +24 -0
- package/lib/controller/EventQueue.js +99 -0
- package/lib/controller/index.d.ts +1 -0
- package/lib/controller/index.js +24 -0
- package/lib/data/DataGroup.d.ts +25 -0
- package/lib/data/DataGroup.js +74 -0
- package/lib/data/DataValue.d.ts +22 -0
- package/lib/data/DataValue.js +50 -0
- package/lib/data/EmptyDataValue.d.ts +14 -0
- package/lib/data/EmptyDataValue.js +46 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +59 -0
- package/lib/rules/FunctionRuntime.d.ts +44 -0
- package/lib/rules/FunctionRuntime.js +271 -0
- package/lib/rules/RuleEngine.d.ts +23 -0
- package/lib/rules/RuleEngine.js +67 -0
- package/lib/types/Json.d.ts +126 -0
- package/lib/types/Json.js +16 -0
- package/lib/types/Model.d.ts +352 -0
- package/lib/types/Model.js +20 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +25 -0
- package/lib/utils/DataRefParser.d.ts +30 -0
- package/lib/utils/DataRefParser.js +249 -0
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +29 -0
- package/lib/utils/FormUtils.d.ts +47 -0
- package/lib/utils/FormUtils.js +172 -0
- package/lib/utils/JsonUtils.d.ts +55 -0
- package/lib/utils/JsonUtils.js +128 -0
- package/lib/utils/LogUtils.d.ts +7 -0
- package/lib/utils/LogUtils.js +17 -0
- package/lib/utils/SchemaUtils.d.ts +16 -0
- package/lib/utils/SchemaUtils.js +92 -0
- package/lib/utils/TranslationUtils.d.ts +34 -0
- package/lib/utils/TranslationUtils.js +156 -0
- package/lib/utils/ValidationUtils.d.ts +153 -0
- package/lib/utils/ValidationUtils.js +339 -0
- package/package.json +60 -0
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.request = void 0;
|
|
11
|
+
const request = (url, data = null, options = {}) => {
|
|
12
|
+
const opts = Object.assign(Object.assign({}, defaultRequestOptions), options);
|
|
13
|
+
return fetch(url, Object.assign(Object.assign({}, opts), { body: data })).then((response) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(response.statusText);
|
|
17
|
+
}
|
|
18
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
|
|
19
|
+
return response.json();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return response.text();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.request = request;
|
|
27
|
+
const defaultRequestOptions = {
|
|
28
|
+
method: 'GET'
|
|
29
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ContainerModel } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Utility to generate a random word from seed
|
|
4
|
+
* @param l seed value
|
|
5
|
+
* @returns random word
|
|
6
|
+
*/
|
|
7
|
+
export declare const randomWord: (l: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Utility to check if the value is empty
|
|
10
|
+
* @param value value
|
|
11
|
+
* @returns `true` if value is empty, `false` otherwise
|
|
12
|
+
*/
|
|
13
|
+
export declare const isEmpty: (value: any) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* @param input
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const getAttachments: (input: ContainerModel) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Converts file size in string to bytes based on IEC specification
|
|
21
|
+
* @param str file size
|
|
22
|
+
* @returns file size as bytes (in kb) based on IEC specification
|
|
23
|
+
*/
|
|
24
|
+
export declare const getFileSizeInBytes: (str: any) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Converts number to bytes based on the symbol as per IEC specification
|
|
27
|
+
* @param size size as number
|
|
28
|
+
* @param symbol symbol to use (for example, kb, mb, gb or tb)
|
|
29
|
+
* @returns number as bytes based on the symbol
|
|
30
|
+
*/
|
|
31
|
+
export declare const sizeToBytes: (size: number, symbol: string) => number;
|
|
32
|
+
/**
|
|
33
|
+
* ID Generator
|
|
34
|
+
* @param initial
|
|
35
|
+
* @constructor
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Utility to convert data URI to a `blob` object
|
|
41
|
+
* @param dataURI uri to convert to blob
|
|
42
|
+
* @returns `Blob` object for the data URI
|
|
43
|
+
*/
|
|
44
|
+
export declare const dataURItoBlob: (dataURI: string) => {
|
|
45
|
+
blob: Blob;
|
|
46
|
+
name: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.dataURItoBlob = exports.IdGenerator = exports.sizeToBytes = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Defines generic utilities to interact with form runtime model
|
|
13
|
+
*/
|
|
14
|
+
const JsonUtils_1 = require("./JsonUtils");
|
|
15
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
|
|
16
|
+
const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
|
|
17
|
+
/**
|
|
18
|
+
* Utility to generate a random word from seed
|
|
19
|
+
* @param l seed value
|
|
20
|
+
* @returns random word
|
|
21
|
+
*/
|
|
22
|
+
const randomWord = (l) => {
|
|
23
|
+
const ret = [];
|
|
24
|
+
for (let i = 0; i <= l; i++) {
|
|
25
|
+
const randIndex = Math.floor(Math.random() * (chars.length));
|
|
26
|
+
ret.push(chars[randIndex]);
|
|
27
|
+
}
|
|
28
|
+
return ret.join('');
|
|
29
|
+
};
|
|
30
|
+
exports.randomWord = randomWord;
|
|
31
|
+
/**
|
|
32
|
+
* Utility to check if the value is empty
|
|
33
|
+
* @param value value
|
|
34
|
+
* @returns `true` if value is empty, `false` otherwise
|
|
35
|
+
*/
|
|
36
|
+
const isEmpty = (value) => {
|
|
37
|
+
return value === '' || value === null || value === undefined;
|
|
38
|
+
};
|
|
39
|
+
exports.isEmpty = isEmpty;
|
|
40
|
+
/**
|
|
41
|
+
* @param input
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
const getAttachments = (input) => {
|
|
45
|
+
const items = input.items || [];
|
|
46
|
+
return items === null || items === void 0 ? void 0 : items.reduce((acc, item) => {
|
|
47
|
+
let ret = null;
|
|
48
|
+
if (item.isContainer) {
|
|
49
|
+
ret = (0, exports.getAttachments)(item);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if ((0, JsonUtils_1.isFile)(item.getState())) {
|
|
53
|
+
ret = {}; // @ts-ignore
|
|
54
|
+
const name = item.name || '';
|
|
55
|
+
const dataRef = (item.dataRef != null)
|
|
56
|
+
? item.dataRef
|
|
57
|
+
: (name.length > 0 ? item.name : undefined);
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
if (item.value instanceof Array) {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
ret[item.id] = item.value.map((x) => {
|
|
62
|
+
return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (item.value != null) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
ret[item.id] = Object.assign(Object.assign({}, item.value), { 'dataRef': dataRef });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Object.assign(acc, ret);
|
|
72
|
+
}, {});
|
|
73
|
+
};
|
|
74
|
+
exports.getAttachments = getAttachments;
|
|
75
|
+
/**
|
|
76
|
+
* Converts file size in string to bytes based on IEC specification
|
|
77
|
+
* @param str file size
|
|
78
|
+
* @returns file size as bytes (in kb) based on IEC specification
|
|
79
|
+
*/
|
|
80
|
+
const getFileSizeInBytes = (str) => {
|
|
81
|
+
let retVal = 0;
|
|
82
|
+
if (typeof str === 'string') {
|
|
83
|
+
const matches = fileSizeRegex.exec(str.trim());
|
|
84
|
+
if (matches != null) {
|
|
85
|
+
retVal = (0, exports.sizeToBytes)(parseFloat(matches[1]), (matches[2] || 'kb').toUpperCase());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return retVal;
|
|
89
|
+
};
|
|
90
|
+
exports.getFileSizeInBytes = getFileSizeInBytes;
|
|
91
|
+
/**
|
|
92
|
+
* Converts number to bytes based on the symbol as per IEC specification
|
|
93
|
+
* @param size size as number
|
|
94
|
+
* @param symbol symbol to use (for example, kb, mb, gb or tb)
|
|
95
|
+
* @returns number as bytes based on the symbol
|
|
96
|
+
*/
|
|
97
|
+
const sizeToBytes = (size, symbol) => {
|
|
98
|
+
const sizes = { 'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4 };
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
const i = Math.pow(1024, sizes[symbol]);
|
|
101
|
+
return Math.round(size * i);
|
|
102
|
+
};
|
|
103
|
+
exports.sizeToBytes = sizeToBytes;
|
|
104
|
+
/**
|
|
105
|
+
* ID Generator
|
|
106
|
+
* @param initial
|
|
107
|
+
* @constructor
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
const IdGenerator = function* (initial = 50) {
|
|
111
|
+
const initialize = function () {
|
|
112
|
+
const arr = [];
|
|
113
|
+
for (let i = 0; i < initial; i++) {
|
|
114
|
+
arr.push((0, exports.randomWord)(10));
|
|
115
|
+
}
|
|
116
|
+
return arr;
|
|
117
|
+
};
|
|
118
|
+
const passedIds = {};
|
|
119
|
+
let ids = initialize();
|
|
120
|
+
do {
|
|
121
|
+
let x = ids.pop();
|
|
122
|
+
while (x in passedIds) {
|
|
123
|
+
if (ids.length === 0) {
|
|
124
|
+
ids = initialize();
|
|
125
|
+
}
|
|
126
|
+
x = ids.pop();
|
|
127
|
+
}
|
|
128
|
+
passedIds[x] = true;
|
|
129
|
+
yield ids.pop();
|
|
130
|
+
if (ids.length === 0) {
|
|
131
|
+
ids = initialize();
|
|
132
|
+
}
|
|
133
|
+
} while (ids.length > 0);
|
|
134
|
+
};
|
|
135
|
+
exports.IdGenerator = IdGenerator;
|
|
136
|
+
/**
|
|
137
|
+
* Utility to convert data URI to a `blob` object
|
|
138
|
+
* @param dataURI uri to convert to blob
|
|
139
|
+
* @returns `Blob` object for the data URI
|
|
140
|
+
*/
|
|
141
|
+
const dataURItoBlob = (dataURI) => {
|
|
142
|
+
// Split metadata from data
|
|
143
|
+
const splitted = dataURI.split(',');
|
|
144
|
+
// Split params
|
|
145
|
+
const params = splitted[0].split(';');
|
|
146
|
+
// Get mime-type from params
|
|
147
|
+
const type = params[0].replace('data:', '');
|
|
148
|
+
// Filter the name property from params
|
|
149
|
+
const properties = params.filter(param => {
|
|
150
|
+
return param.split('=')[0] === 'name';
|
|
151
|
+
});
|
|
152
|
+
// Look for the name and use unknown if no name property.
|
|
153
|
+
let name;
|
|
154
|
+
if (properties.length !== 1) {
|
|
155
|
+
name = 'unknown';
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// Because we filtered out the other property,
|
|
159
|
+
// we only have the name case here.
|
|
160
|
+
name = properties[0].split('=')[1];
|
|
161
|
+
}
|
|
162
|
+
// Built the Uint8Array Blob parameter from the base64 string.
|
|
163
|
+
const binary = atob(splitted[1]);
|
|
164
|
+
const array = [];
|
|
165
|
+
for (let i = 0; i < binary.length; i++) {
|
|
166
|
+
array.push(binary.charCodeAt(i));
|
|
167
|
+
}
|
|
168
|
+
// Create the blob object
|
|
169
|
+
const blob = new window.Blob([new Uint8Array(array)], { type });
|
|
170
|
+
return { blob, name };
|
|
171
|
+
};
|
|
172
|
+
exports.dataURItoBlob = dataURItoBlob;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines generic utilities to interact with form model definition which is represented as json
|
|
3
|
+
*/
|
|
4
|
+
import { FieldsetJson, FieldJson } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Get the property value form the json
|
|
7
|
+
* @param data object as json
|
|
8
|
+
* @param key name of the key
|
|
9
|
+
* @param def default value
|
|
10
|
+
* @typeParam P type for the default value
|
|
11
|
+
*/
|
|
12
|
+
export declare const getProperty: <P>(data: any, key: string, def: P) => P;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the input item provided is a form file attachment field
|
|
15
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
16
|
+
* @returns `true` if `item` is a form file attachment, `false` otherwise
|
|
17
|
+
*/
|
|
18
|
+
export declare const isFile: (item: FieldsetJson | FieldJson) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Utility to check if the given form field has any data constraints
|
|
21
|
+
* @param item form field to check
|
|
22
|
+
* @returns `true` if `item` has data constraints, `false` otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJson) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the input item provided is a form check box field
|
|
27
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
28
|
+
* @returns `true` if `item` is a form check box, `false` otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the input item provided is a form check box group field
|
|
33
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
34
|
+
* @returns `true` if `item` is a form check box group, `false` otherwise
|
|
35
|
+
*/
|
|
36
|
+
export declare const isCheckboxGroup: (item: FieldsetJson | FieldJson) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Clones an object completely including any nested objects or arrays
|
|
39
|
+
* @param obj
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
export declare function deepClone(obj: any): any;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the key got added in current object
|
|
45
|
+
* @param currentObj
|
|
46
|
+
* @param prevObj
|
|
47
|
+
* @param objKey
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkIfKeyAdded(currentObj: any, prevObj: any, objKey: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Prettifies obj as json string
|
|
52
|
+
* @param obj object to prettify
|
|
53
|
+
* @return json string
|
|
54
|
+
*/
|
|
55
|
+
export declare const jsonString: (obj: any) => string;
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Defines generic utilities to interact with form model definition which is represented as json
|
|
13
|
+
*/
|
|
14
|
+
const types_1 = require("../types");
|
|
15
|
+
const SchemaUtils_1 = require("./SchemaUtils");
|
|
16
|
+
/**
|
|
17
|
+
* Get the property value form the json
|
|
18
|
+
* @param data object as json
|
|
19
|
+
* @param key name of the key
|
|
20
|
+
* @param def default value
|
|
21
|
+
* @typeParam P type for the default value
|
|
22
|
+
*/
|
|
23
|
+
const getProperty = (data, key, def) => {
|
|
24
|
+
if (key in data) {
|
|
25
|
+
return data[key];
|
|
26
|
+
}
|
|
27
|
+
else if (!key.startsWith(':')) {
|
|
28
|
+
const prefixedKey = `:${key}`;
|
|
29
|
+
if (prefixedKey in data) {
|
|
30
|
+
return data[prefixedKey];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return def;
|
|
34
|
+
};
|
|
35
|
+
exports.getProperty = getProperty;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the input item provided is a form file attachment field
|
|
38
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
39
|
+
* @returns `true` if `item` is a form file attachment, `false` otherwise
|
|
40
|
+
*/
|
|
41
|
+
const isFile = function (item) {
|
|
42
|
+
return ((item === null || item === void 0 ? void 0 : item.type) === 'file' || (item === null || item === void 0 ? void 0 : item.type) === 'file[]') ||
|
|
43
|
+
(((item === null || item === void 0 ? void 0 : item.type) === 'string' || (item === null || item === void 0 ? void 0 : item.type) === 'string[]') &&
|
|
44
|
+
((item === null || item === void 0 ? void 0 : item.format) === 'binary' || (item === null || item === void 0 ? void 0 : item.format) === 'data-url'));
|
|
45
|
+
};
|
|
46
|
+
exports.isFile = isFile;
|
|
47
|
+
/**
|
|
48
|
+
* Utility to check if the given form field has any data constraints
|
|
49
|
+
* @param item form field to check
|
|
50
|
+
* @returns `true` if `item` has data constraints, `false` otherwise
|
|
51
|
+
*/
|
|
52
|
+
const checkIfConstraintsArePresent = function (item) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
return types_1.constraintProps.some(cp => item[cp] !== undefined);
|
|
55
|
+
};
|
|
56
|
+
exports.checkIfConstraintsArePresent = checkIfConstraintsArePresent;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the input item provided is a form check box field
|
|
59
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
60
|
+
* @returns `true` if `item` is a form check box, `false` otherwise
|
|
61
|
+
*/
|
|
62
|
+
const isCheckbox = function (item) {
|
|
63
|
+
const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
|
|
64
|
+
return fieldType === 'checkbox';
|
|
65
|
+
};
|
|
66
|
+
exports.isCheckbox = isCheckbox;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the input item provided is a form check box group field
|
|
69
|
+
* @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
|
|
70
|
+
* @returns `true` if `item` is a form check box group, `false` otherwise
|
|
71
|
+
*/
|
|
72
|
+
const isCheckboxGroup = function (item) {
|
|
73
|
+
const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
|
|
74
|
+
return fieldType === 'checkbox-group';
|
|
75
|
+
};
|
|
76
|
+
exports.isCheckboxGroup = isCheckboxGroup;
|
|
77
|
+
/**
|
|
78
|
+
* Clones an object completely including any nested objects or arrays
|
|
79
|
+
* @param obj
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
function deepClone(obj) {
|
|
83
|
+
let result;
|
|
84
|
+
if (obj instanceof Array) {
|
|
85
|
+
result = [];
|
|
86
|
+
result = obj.map(x => deepClone(x));
|
|
87
|
+
}
|
|
88
|
+
else if (typeof obj === 'object' && obj !== null) {
|
|
89
|
+
result = {};
|
|
90
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
91
|
+
result[key] = deepClone(value);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
result = obj;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
exports.deepClone = deepClone;
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the key got added in current object
|
|
102
|
+
* @param currentObj
|
|
103
|
+
* @param prevObj
|
|
104
|
+
* @param objKey
|
|
105
|
+
*/
|
|
106
|
+
function checkIfKeyAdded(currentObj, prevObj, objKey) {
|
|
107
|
+
if (currentObj != null && prevObj != null) {
|
|
108
|
+
// add the new key
|
|
109
|
+
const newPrvObj = Object.assign({}, prevObj);
|
|
110
|
+
newPrvObj[objKey] = currentObj[objKey];
|
|
111
|
+
// do compare using json stringify
|
|
112
|
+
const newJsonStr = (0, exports.jsonString)(currentObj).replace((0, exports.jsonString)(newPrvObj), '');
|
|
113
|
+
return newJsonStr === '';
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.checkIfKeyAdded = checkIfKeyAdded;
|
|
120
|
+
/**
|
|
121
|
+
* Prettifies obj as json string
|
|
122
|
+
* @param obj object to prettify
|
|
123
|
+
* @return json string
|
|
124
|
+
*/
|
|
125
|
+
const jsonString = (obj) => {
|
|
126
|
+
return JSON.stringify(obj, null, 2);
|
|
127
|
+
};
|
|
128
|
+
exports.jsonString = jsonString;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.logFormCallbacks = void 0;
|
|
11
|
+
const logFormCallbacks = (callbacks) => {
|
|
12
|
+
const s = Object.entries(callbacks).map(([id, fn]) => {
|
|
13
|
+
return `${id} : ${fn.length}`;
|
|
14
|
+
}).join(' ');
|
|
15
|
+
console.log(s);
|
|
16
|
+
};
|
|
17
|
+
exports.logFormCallbacks = logFormCallbacks;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines generic utilities to convert form model definition to json schema
|
|
3
|
+
*/
|
|
4
|
+
import { FormJson } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the default view type for a given form field object based on `adaptive form specification`
|
|
7
|
+
* @param schema schema item for which default view type is to found
|
|
8
|
+
* @returns default view type
|
|
9
|
+
*/
|
|
10
|
+
export declare const defaultFieldTypes: (schema: any) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a json schema from form model definition
|
|
13
|
+
* @param form {@link FormJson | form model definition}
|
|
14
|
+
* @returns json schema of form model definition
|
|
15
|
+
*/
|
|
16
|
+
export declare const exportDataSchema: (form: FormJson) => any;
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.exportDataSchema = exports.defaultFieldTypes = void 0;
|
|
11
|
+
// const primitives = ['string', 'boolean', 'number'];
|
|
12
|
+
// const containers = ['object', 'array', 'number'];
|
|
13
|
+
const objToMap = (o) => new Map(Object.entries(o));
|
|
14
|
+
const stringViewTypes = objToMap({ 'date': 'date-input', 'data-url': 'file-input', 'binary': 'file-input' });
|
|
15
|
+
const typeToViewTypes = objToMap({
|
|
16
|
+
'number': 'number-input',
|
|
17
|
+
'boolean': 'checkbox',
|
|
18
|
+
'object': 'panel',
|
|
19
|
+
'array': 'panel',
|
|
20
|
+
'file': 'file-input',
|
|
21
|
+
'file[]': 'file-input'
|
|
22
|
+
});
|
|
23
|
+
const arrayTypes = ['string[]', 'boolean[]', 'number[]', 'array'];
|
|
24
|
+
/**
|
|
25
|
+
* Returns the default view type for a given form field object based on `adaptive form specification`
|
|
26
|
+
* @param schema schema item for which default view type is to found
|
|
27
|
+
* @returns default view type
|
|
28
|
+
*/
|
|
29
|
+
const defaultFieldTypes = (schema) => {
|
|
30
|
+
const type = schema.type || 'string';
|
|
31
|
+
if ('enum' in schema) {
|
|
32
|
+
const enums = schema.enum;
|
|
33
|
+
if (enums.length > 2 || arrayTypes.indexOf(type) > -1) {
|
|
34
|
+
return 'drop-down';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return 'checkbox';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (type === 'string' || type === 'string[]') {
|
|
41
|
+
return stringViewTypes.get(schema.format) || 'text-input';
|
|
42
|
+
}
|
|
43
|
+
return typeToViewTypes.get(type) || 'text-input';
|
|
44
|
+
};
|
|
45
|
+
exports.defaultFieldTypes = defaultFieldTypes;
|
|
46
|
+
const fieldSchema = (input) => {
|
|
47
|
+
var _a;
|
|
48
|
+
if ('items' in input) {
|
|
49
|
+
const fieldset = input;
|
|
50
|
+
const items = fieldset.items;
|
|
51
|
+
if (fieldset.type === 'array') {
|
|
52
|
+
return {
|
|
53
|
+
type: 'array',
|
|
54
|
+
items: fieldSchema(items[0]),
|
|
55
|
+
minItems: fieldset === null || fieldset === void 0 ? void 0 : fieldset.minItems,
|
|
56
|
+
maxItems: fieldset === null || fieldset === void 0 ? void 0 : fieldset.maxItems
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const iter = items.filter(x => x.name != null);
|
|
61
|
+
return {
|
|
62
|
+
type: 'object',
|
|
63
|
+
properties: Object.fromEntries(iter.map(item => [item.name, fieldSchema(item)])),
|
|
64
|
+
required: iter.filter(x => x.required).map(x => x.name)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const field = input;
|
|
70
|
+
const schemaProps = ['type', 'maxLength', 'minLength', 'minimum', 'maximum', 'format', 'pattern', 'step', 'enum'];
|
|
71
|
+
const schema = schemaProps.reduce((acc, prop) => {
|
|
72
|
+
const p = prop;
|
|
73
|
+
if (prop in field && field[p] != undefined) {
|
|
74
|
+
acc[prop] = field[p];
|
|
75
|
+
}
|
|
76
|
+
return acc;
|
|
77
|
+
}, {});
|
|
78
|
+
if (field.dataRef === 'none' || Object.keys(schema).length == 0) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return Object.assign({ title: (_a = field.label) === null || _a === void 0 ? void 0 : _a.value, description: field.description }, schema);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Creates a json schema from form model definition
|
|
86
|
+
* @param form {@link FormJson | form model definition}
|
|
87
|
+
* @returns json schema of form model definition
|
|
88
|
+
*/
|
|
89
|
+
const exportDataSchema = (form) => {
|
|
90
|
+
return fieldSchema(form);
|
|
91
|
+
};
|
|
92
|
+
exports.exportDataSchema = exportDataSchema;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines generic utilities to translated form model definition
|
|
3
|
+
*/
|
|
4
|
+
import { FieldJson, FieldsetJson, FormJson } from '../types';
|
|
5
|
+
/** Token used while creating translation specific properties from `adaptive form specification` */
|
|
6
|
+
export declare const TRANSLATION_TOKEN = "##";
|
|
7
|
+
/** Name of the object which holds all translation specific properties */
|
|
8
|
+
export declare const TRANSLATION_ID = "afs:translationIds";
|
|
9
|
+
export declare const CUSTOM_PROPS_KEY = "properties";
|
|
10
|
+
declare type formElementJson = FieldJson | FieldsetJson | FormJson | any;
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export declare const invalidateTranslation: (input: formElementJson, updates: any) => void;
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const addTranslationId: (input: formElementJson, additionalTranslationProps?: string[]) => formElementJson;
|
|
19
|
+
/**
|
|
20
|
+
* @param input
|
|
21
|
+
* @param additionalTranslationProps
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
export declare const createTranslationObj: (input: formElementJson, additionalTranslationProps?: string[]) => any;
|
|
25
|
+
/**
|
|
26
|
+
* Creates translation object with [BCP 47](https://tools.ietf.org/search/bcp47) language tags as key and value is a translation object. Key of translation object is
|
|
27
|
+
* generated based on the form hierarchy and it is separated by "##" token to signify that the id is machine generated (ie its not a human generated string)
|
|
28
|
+
* @param input form model definition
|
|
29
|
+
* @param additionalTranslationProps optional properties which needs to be translated, by default, only OOTB properties of form model definition is translated
|
|
30
|
+
* @param bcp47LangTags optional additional language tags
|
|
31
|
+
* @returns translation object for each bcp 47 language tag
|
|
32
|
+
*/
|
|
33
|
+
export declare const createTranslationObject: (input: formElementJson, additionalTranslationProps?: string[], bcp47LangTags?: string[]) => any;
|
|
34
|
+
export {};
|