@aemforms/af-core 0.22.19 → 0.22.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +54 -116
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +39 -104
  15. package/lib/{Field.js → esm/Field.js} +142 -208
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/{Form.d.ts → esm/Form.d.ts} +19 -85
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +11 -54
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +10 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
  39. package/lib/{controller → esm/controller}/Logger.js +5 -11
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +15 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +41 -117
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/{types → esm/types}/Json.d.ts +3 -22
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
  59. package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +0 -6
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
  76. package/package.json +17 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/DateField.js +0 -35
  81. package/lib/Fieldset.d.ts +0 -24
  82. package/lib/Fieldset.js +0 -74
  83. package/lib/FileObject.js +0 -39
  84. package/lib/FileUpload.js +0 -155
  85. package/lib/Form.js +0 -252
  86. package/lib/FormInstance.d.ts +0 -38
  87. package/lib/FormInstance.js +0 -127
  88. package/lib/FormMetaData.d.ts +0 -11
  89. package/lib/FormMetaData.js +0 -28
  90. package/lib/InstanceManager.d.ts +0 -16
  91. package/lib/InstanceManager.js +0 -53
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -255
  96. package/lib/controller/Controller.js +0 -328
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -56
  100. package/lib/data/EmptyDataValue.js +0 -46
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -63
  103. package/lib/rules/RuleEngine.d.ts +0 -23
  104. package/lib/rules/RuleEngine.js +0 -62
  105. package/lib/types/Json.js +0 -19
  106. package/lib/types/Model.d.ts +0 -393
  107. package/lib/types/Model.js +0 -20
  108. package/lib/types/index.d.ts +0 -2
  109. package/lib/types/index.js +0 -25
  110. package/lib/utils/Fetch.js +0 -87
  111. package/lib/utils/FormCreationUtils.d.ts +0 -11
  112. package/lib/utils/FormCreationUtils.js +0 -83
  113. package/lib/utils/FormUtils.d.ts +0 -47
  114. package/lib/utils/FormUtils.js +0 -257
  115. package/lib/utils/JsonUtils.d.ts +0 -63
  116. package/lib/utils/JsonUtils.js +0 -157
  117. package/lib/utils/LogUtils.js +0 -17
  118. package/lib/utils/SchemaUtils.d.ts +0 -16
  119. package/lib/utils/SchemaUtils.js +0 -92
  120. package/lib/utils/TranslationUtils.d.ts +0 -41
  121. package/lib/utils/TranslationUtils.js +0 -185
  122. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -1,257 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.dataURItoBlob = exports.extractFileInfo = exports.IdGenerator = 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 FileObject_1 = require("../FileObject");
16
- const ValidationUtils_1 = require("./ValidationUtils");
17
- const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
18
- const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
19
- /**
20
- * Utility to generate a random word from seed
21
- * @param l seed value
22
- * @returns random word
23
- */
24
- const randomWord = (l) => {
25
- const ret = [];
26
- for (let i = 0; i <= l; i++) {
27
- const randIndex = Math.floor(Math.random() * (chars.length));
28
- ret.push(chars[randIndex]);
29
- }
30
- return ret.join('');
31
- };
32
- exports.randomWord = randomWord;
33
- /**
34
- * Utility to check if the value is empty
35
- * @param value value
36
- * @returns `true` if value is empty, `false` otherwise
37
- */
38
- const isEmpty = (value) => {
39
- return value === '' || value === null || value === undefined;
40
- };
41
- exports.isEmpty = isEmpty;
42
- /**
43
- * Returns the list of attachments with its data reference
44
- * @param input form model
45
- * @returns list of file attachments {@link FileObject} present in the form
46
- */
47
- const getAttachments = (input) => {
48
- const items = input.items || [];
49
- return items === null || items === void 0 ? void 0 : items.reduce((acc, item) => {
50
- let ret = null;
51
- if (item.isContainer) {
52
- ret = (0, exports.getAttachments)(item);
53
- }
54
- else {
55
- if ((0, JsonUtils_1.isFile)(item.getState())) {
56
- ret = {}; // @ts-ignore
57
- const name = item.name || '';
58
- const dataRef = (item.dataRef != null)
59
- ? item.dataRef
60
- : (name.length > 0 ? item.name : undefined);
61
- //@ts-ignore
62
- if (item.value instanceof Array) {
63
- // @ts-ignore
64
- ret[item.id] = item.value.map((x) => {
65
- return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
66
- });
67
- }
68
- else if (item.value != null) {
69
- // @ts-ignore
70
- ret[item.id] = Object.assign(Object.assign({}, item.value), { 'dataRef': dataRef });
71
- }
72
- }
73
- }
74
- return Object.assign(acc, ret);
75
- }, {});
76
- };
77
- exports.getAttachments = getAttachments;
78
- /**
79
- * Converts file size in string to bytes based on IEC specification
80
- * @param str file size
81
- * @returns file size as bytes (in kb) based on IEC specification
82
- */
83
- const getFileSizeInBytes = (str) => {
84
- let retVal = 0;
85
- if (typeof str === 'string') {
86
- const matches = fileSizeRegex.exec(str.trim());
87
- if (matches != null) {
88
- retVal = sizeToBytes(parseFloat(matches[1]), (matches[2] || 'kb').toUpperCase());
89
- }
90
- }
91
- return retVal;
92
- };
93
- exports.getFileSizeInBytes = getFileSizeInBytes;
94
- /**
95
- * Converts number to bytes based on the symbol as per IEC specification
96
- * @param size size as number
97
- * @param symbol symbol to use (for example, kb, mb, gb or tb)
98
- * @returns number as bytes based on the symbol
99
- */
100
- const sizeToBytes = (size, symbol) => {
101
- const sizes = { 'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4 };
102
- // @ts-ignore
103
- const i = Math.pow(1024, sizes[symbol]);
104
- return Math.round(size * i);
105
- };
106
- /**
107
- * ID Generator
108
- * @param initial
109
- * @constructor
110
- * @private
111
- */
112
- const IdGenerator = function* (initial = 50) {
113
- const initialize = function () {
114
- const arr = [];
115
- for (let i = 0; i < initial; i++) {
116
- arr.push((0, exports.randomWord)(10));
117
- }
118
- return arr;
119
- };
120
- const passedIds = {};
121
- let ids = initialize();
122
- do {
123
- let x = ids.pop();
124
- while (x in passedIds) {
125
- if (ids.length === 0) {
126
- ids = initialize();
127
- }
128
- x = ids.pop();
129
- }
130
- passedIds[x] = true;
131
- yield ids.pop();
132
- if (ids.length === 0) {
133
- ids = initialize();
134
- }
135
- } while (ids.length > 0);
136
- };
137
- exports.IdGenerator = IdGenerator;
138
- /**
139
- * Utility to extract {@link FileObject} from string or HTML File data type
140
- * @param file
141
- * @returns list of {@link FileObject}
142
- */
143
- const extractFileInfo = (file) => {
144
- if (file !== null) {
145
- let retVal = null;
146
- if (file instanceof FileObject_1.FileObject) {
147
- retVal = file;
148
- }
149
- else if (typeof File !== 'undefined' && file instanceof File) {
150
- // case: file object
151
- retVal = {
152
- name: file.name,
153
- mediaType: file.type,
154
- size: file.size,
155
- data: file
156
- };
157
- }
158
- else if (typeof file === 'string' && (0, ValidationUtils_1.isDataUrl)(file)) {
159
- // case: data URL
160
- const result = (0, exports.dataURItoBlob)(file);
161
- if (result !== null) {
162
- const { blob, name } = result;
163
- retVal = {
164
- name: name,
165
- mediaType: blob.type,
166
- size: blob.size,
167
- data: blob
168
- };
169
- }
170
- }
171
- else {
172
- // case: string as file object
173
- let jFile = file;
174
- try {
175
- jFile = JSON.parse(file);
176
- retVal = jFile;
177
- if (!retVal.mediaType) {
178
- retVal.mediaType = retVal.type;
179
- }
180
- }
181
- catch (ex) {
182
- // do nothing
183
- }
184
- if (typeof (jFile === null || jFile === void 0 ? void 0 : jFile.data) === 'string' && (0, ValidationUtils_1.isDataUrl)(jFile === null || jFile === void 0 ? void 0 : jFile.data)) {
185
- // case: data URL
186
- const result = (0, exports.dataURItoBlob)(jFile === null || jFile === void 0 ? void 0 : jFile.data);
187
- if (result !== null) {
188
- const blob = result.blob;
189
- retVal = {
190
- name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
191
- mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
192
- size: blob.size,
193
- data: blob
194
- };
195
- }
196
- }
197
- else if (typeof jFile === 'string') {
198
- // case: data as external url
199
- const fileName = jFile.split('/').pop();
200
- retVal = {
201
- name: fileName,
202
- mediaType: 'application/octet-stream',
203
- size: 0,
204
- data: jFile
205
- };
206
- }
207
- else if (typeof jFile === 'object') {
208
- // todo: just added for ease of integration for the view layer
209
- retVal = {
210
- name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
211
- mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
212
- size: jFile === null || jFile === void 0 ? void 0 : jFile.size,
213
- data: jFile === null || jFile === void 0 ? void 0 : jFile.data
214
- };
215
- }
216
- }
217
- if (retVal !== null && retVal.data != null) {
218
- return new FileObject_1.FileObject(retVal);
219
- }
220
- return null;
221
- }
222
- else {
223
- return null;
224
- }
225
- };
226
- exports.extractFileInfo = extractFileInfo;
227
- /**
228
- * Utility to convert data URI to a `blob` object
229
- * @param dataURI uri to convert to blob
230
- * @returns `Blob` object for the data URI
231
- */
232
- const dataURItoBlob = (dataURI) => {
233
- const regex = /^data:([a-z]+\/[a-z0-9-+.]+)?(?:;name=([^;]+))?(;base64)?,(.+)$/;
234
- const groups = regex.exec(dataURI);
235
- if (groups !== null) {
236
- const type = groups[1] || '';
237
- const name = groups[2] || 'unknown';
238
- const isBase64 = typeof groups[3] === 'string';
239
- if (isBase64) {
240
- const binary = atob(groups[4]);
241
- const array = [];
242
- for (let i = 0; i < binary.length; i++) {
243
- array.push(binary.charCodeAt(i));
244
- }
245
- const blob = new window.Blob([new Uint8Array(array)], { type });
246
- return { name, blob };
247
- }
248
- else {
249
- const blob = new window.Blob([groups[4]], { type });
250
- return { name, blob };
251
- }
252
- }
253
- else {
254
- return null;
255
- }
256
- };
257
- exports.dataURItoBlob = dataURItoBlob;
@@ -1,63 +0,0 @@
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
- * Checks if the input item provided is a date field
39
- * @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
40
- * @returns `true` if `item` is a form check box group, `false` otherwise
41
- */
42
- export declare const isDateField: (item: FieldsetJson | FieldJson) => boolean;
43
- /**
44
- * Clones an object completely including any nested objects or arrays
45
- * @param obj
46
- * @param idGenerator
47
- * @private
48
- */
49
- export declare function deepClone(obj: any, idGenerator?: () => string): any;
50
- /**
51
- * Checks if the key got added in current object
52
- * @param currentObj
53
- * @param prevObj
54
- * @param objKey
55
- */
56
- export declare function checkIfKeyAdded(currentObj: any, prevObj: any, objKey: string): boolean;
57
- /**
58
- * Prettifies obj as json string
59
- * @param obj object to prettify
60
- * @return json string
61
- */
62
- export declare const jsonString: (obj: any) => string;
63
- export declare const isRepeatable: (obj: FieldsetJson | FieldJson) => boolean;
@@ -1,157 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.isRepeatable = exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isDateField = 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
- * Checks if the input item provided is a date field
79
- * @param item input item it could be {@link FieldsetJson | Fieldset} or {@link FieldJson | Field}
80
- * @returns `true` if `item` is a form check box group, `false` otherwise
81
- */
82
- const isDateField = function (item) {
83
- const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
84
- return (fieldType === 'text-input' && (item === null || item === void 0 ? void 0 : item.format) === 'date') || fieldType === 'date-input';
85
- };
86
- exports.isDateField = isDateField;
87
- /**
88
- * Clones an object completely including any nested objects or arrays
89
- * @param obj
90
- * @param idGenerator
91
- * @private
92
- */
93
- function deepClone(obj, idGenerator) {
94
- let result;
95
- if (obj instanceof Array) {
96
- result = [];
97
- result = obj.map(x => deepClone(x, idGenerator));
98
- }
99
- else if (typeof obj === 'object' && obj !== null) {
100
- result = {};
101
- Object.entries(obj).forEach(([key, value]) => {
102
- result[key] = deepClone(value, idGenerator);
103
- });
104
- }
105
- else {
106
- result = obj;
107
- }
108
- //if idGenerator is specified, and id exists in the object
109
- if (idGenerator && result && result.id) {
110
- result.id = idGenerator();
111
- }
112
- return result;
113
- }
114
- exports.deepClone = deepClone;
115
- /**
116
- * Checks if the key got added in current object
117
- * @param currentObj
118
- * @param prevObj
119
- * @param objKey
120
- */
121
- function checkIfKeyAdded(currentObj, prevObj, objKey) {
122
- if (currentObj != null && prevObj != null) {
123
- // add the new key
124
- const newPrvObj = Object.assign({}, prevObj);
125
- newPrvObj[objKey] = currentObj[objKey];
126
- // do compare using json stringify
127
- const newJsonStr = (0, exports.jsonString)(currentObj).replace((0, exports.jsonString)(newPrvObj), '');
128
- return newJsonStr === '';
129
- }
130
- else {
131
- return false;
132
- }
133
- }
134
- exports.checkIfKeyAdded = checkIfKeyAdded;
135
- /**
136
- * Prettifies obj as json string
137
- * @param obj object to prettify
138
- * @return json string
139
- */
140
- const jsonString = (obj) => {
141
- return JSON.stringify(obj, null, 2);
142
- };
143
- exports.jsonString = jsonString;
144
- const isRepeatable = (obj) => {
145
- return ((obj.repeatable &&
146
- // case0: both are undefined
147
- ((obj.minOccur === undefined && obj.maxOccur === undefined) ||
148
- // case1: if minOccur is specified and maxOccur specified is not equal to zero, then it is repeatable
149
- (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
150
- // case2: if both specified and both equal to zero, then it is not repeatable
151
- (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.minOccur !== 0 && obj.maxOccur !== 0) ||
152
- // case3: only if minOccur is specified, then it should be greater than zero for repeatable
153
- (obj.minOccur !== undefined && obj.minOccur >= 0) ||
154
- // case4: only if maxOccur is specified, then it should be non-zero for repeatable
155
- (obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
156
- };
157
- exports.isRepeatable = isRepeatable;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- 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;
@@ -1,16 +0,0 @@
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;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- 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;
@@ -1,41 +0,0 @@
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
- * Gets the value for the given key from the input, in case of no value, default is returned
21
- * @param input input object
22
- * @param key key to return from input object (key could be comma separated, example, label.value)
23
- * @param defaultValue default value
24
- */
25
- export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
26
- /**
27
- * @param input
28
- * @param additionalTranslationProps
29
- * @private
30
- */
31
- export declare const createTranslationObj: (input: formElementJson, additionalTranslationProps?: string[]) => any;
32
- /**
33
- * 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
34
- * 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)
35
- * @param input form model definition
36
- * @param additionalTranslationProps optional properties which needs to be translated, by default, only OOTB properties of form model definition is translated
37
- * @param bcp47LangTags optional additional language tags
38
- * @returns translation object for each bcp 47 language tag
39
- */
40
- export declare const createTranslationObject: (input: formElementJson, additionalTranslationProps?: string[], bcp47LangTags?: string[]) => any;
41
- export {};