@aemforms/af-core 0.22.9 → 0.22.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BaseNode.js +9 -2
- package/lib/FileUpload.js +6 -5
- package/lib/data/DataGroup.d.ts +1 -1
- package/lib/data/DataGroup.js +7 -2
- package/lib/rules/FunctionRuntime.js +16 -26
- package/lib/utils/FormUtils.d.ts +3 -2
- package/lib/utils/FormUtils.js +3 -2
- package/package.json +2 -2
package/lib/BaseNode.js
CHANGED
|
@@ -314,7 +314,7 @@ class BaseNode {
|
|
|
314
314
|
return;
|
|
315
315
|
}
|
|
316
316
|
const dataRef = this._jsonModel.dataRef;
|
|
317
|
-
let _data;
|
|
317
|
+
let _data, _parent = contextualDataModel, _key = '';
|
|
318
318
|
if (dataRef === null) { // null data binding
|
|
319
319
|
_data = EmptyDataValue_1.default;
|
|
320
320
|
}
|
|
@@ -330,13 +330,18 @@ class BaseNode {
|
|
|
330
330
|
const name = this._tokens[this._tokens.length - 1].value;
|
|
331
331
|
const create = this.defaultDataModel(name);
|
|
332
332
|
_data = (0, DataRefParser_1.resolveData)(searchData, this._tokens, create);
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
_parent = (0, DataRefParser_1.resolveData)(searchData, this._tokens.slice(0, -1));
|
|
335
|
+
_key = name;
|
|
333
336
|
}
|
|
334
337
|
}
|
|
335
338
|
else { // name data binding
|
|
336
339
|
if ( //@ts-ignore
|
|
337
340
|
contextualDataModel !== EmptyDataValue_1.default) {
|
|
341
|
+
_parent = contextualDataModel;
|
|
338
342
|
const name = this._jsonModel.name || '';
|
|
339
343
|
const key = contextualDataModel.$type === 'array' ? this.index : name;
|
|
344
|
+
_key = key;
|
|
340
345
|
if (key !== '') {
|
|
341
346
|
const create = this.defaultDataModel(key);
|
|
342
347
|
if (create !== undefined) {
|
|
@@ -353,8 +358,10 @@ class BaseNode {
|
|
|
353
358
|
}
|
|
354
359
|
}
|
|
355
360
|
if (_data) {
|
|
356
|
-
|
|
361
|
+
//@ts-ignore
|
|
362
|
+
if (!this.isContainer && _parent !== EmptyDataValue_1.default && _data !== EmptyDataValue_1.default) {
|
|
357
363
|
_data = _data === null || _data === void 0 ? void 0 : _data.$convertToDataValue();
|
|
364
|
+
_parent.$addDataNode(_key, _data, true);
|
|
358
365
|
}
|
|
359
366
|
_data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
|
|
360
367
|
this._data = _data;
|
package/lib/FileUpload.js
CHANGED
|
@@ -116,11 +116,12 @@ class FileUpload extends Field_1.default {
|
|
|
116
116
|
}
|
|
117
117
|
accepts = Array.isArray(accepts) ? accepts : accepts.split(',');
|
|
118
118
|
accepts.forEach((accept) => {
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
119
|
+
const trimmedAccept = accept.trim();
|
|
120
|
+
const prefixAccept = trimmedAccept.split('/')[0];
|
|
121
|
+
const suffixAccept = trimmedAccept.split('.')[1];
|
|
122
|
+
if ((trimmedAccept.includes('*') && type.startsWith(prefixAccept)) ||
|
|
123
|
+
(trimmedAccept.includes('.') && type.endsWith(suffixAccept)) ||
|
|
124
|
+
(trimmedAccept === type)) {
|
|
124
125
|
validFileType = true;
|
|
125
126
|
}
|
|
126
127
|
});
|
package/lib/data/DataGroup.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default class DataGroup extends DataValue {
|
|
|
18
18
|
};
|
|
19
19
|
get $length(): number;
|
|
20
20
|
$convertToDataValue(): DataValue;
|
|
21
|
-
$addDataNode(name: string | number, value: DataGroup | DataValue): void;
|
|
21
|
+
$addDataNode(name: string | number, value: DataGroup | DataValue, override?: boolean): void;
|
|
22
22
|
$removeDataNode(name: string | number): void;
|
|
23
23
|
$getDataNode(name: string | number): any;
|
|
24
24
|
$containsDataNode(name: string | number): boolean;
|
package/lib/data/DataGroup.js
CHANGED
|
@@ -57,11 +57,16 @@ class DataGroup extends DataValue_1.default {
|
|
|
57
57
|
$convertToDataValue() {
|
|
58
58
|
return new DataValue_1.default(this.$name, this.$value, this.$type);
|
|
59
59
|
}
|
|
60
|
-
$addDataNode(name, value) {
|
|
60
|
+
$addDataNode(name, value, override = false) {
|
|
61
61
|
if (value !== EmptyDataValue_1.default) {
|
|
62
62
|
if (this.$type === 'array') {
|
|
63
63
|
const index = name;
|
|
64
|
-
|
|
64
|
+
if (!override) {
|
|
65
|
+
this.$_items.splice(index, 0, value);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.$_items[name] = value;
|
|
69
|
+
}
|
|
65
70
|
}
|
|
66
71
|
else {
|
|
67
72
|
this.$_items[name] = value;
|
|
@@ -90,35 +90,25 @@ const multipartFormData = (data, attachments) => {
|
|
|
90
90
|
formData.append(key, value);
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// if (!attIdentifier.startsWith('/')) {
|
|
103
|
-
// attIdentifier = `/${attIdentifier}`;
|
|
104
|
-
// }
|
|
105
|
-
// formData.append(attIdentifier, objValue.data);
|
|
106
|
-
// newValue[':data'] = `#${attIdentifier}`;
|
|
107
|
-
// }
|
|
108
|
-
// return newValue;
|
|
109
|
-
// };
|
|
93
|
+
const addAttachmentToFormData = (objValue, formData) => {
|
|
94
|
+
if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
|
|
95
|
+
let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
|
|
96
|
+
if (!attIdentifier.startsWith('/')) {
|
|
97
|
+
attIdentifier = `/${attIdentifier}`;
|
|
98
|
+
}
|
|
99
|
+
formData.append(attIdentifier, objValue.data);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
110
102
|
// @ts-ignore
|
|
111
|
-
|
|
103
|
+
Object.keys(attachments).reduce((acc, curr) => {
|
|
112
104
|
const objValue = attachments[curr];
|
|
113
|
-
if(objValue && objValue instanceof Array) {
|
|
114
|
-
return [...acc, ...objValue.map((x)=>
|
|
115
|
-
}
|
|
116
|
-
|
|
105
|
+
if (objValue && objValue instanceof Array) {
|
|
106
|
+
return [...acc, ...objValue.map((x) => addAttachmentToFormData(x, formData))];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return [...acc, addAttachmentToFormData(objValue, formData)];
|
|
117
110
|
}
|
|
118
111
|
}, []);
|
|
119
|
-
if (submitAttachments?.length > 0) {
|
|
120
|
-
formData.append(':attachments', jsonString(submitAttachments));
|
|
121
|
-
}*/
|
|
122
112
|
return formData;
|
|
123
113
|
};
|
|
124
114
|
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -129,7 +119,7 @@ const submit = (context, success, error, submitAs = 'multipart/form-data', input
|
|
|
129
119
|
}
|
|
130
120
|
// todo: have to implement sending of attachments here
|
|
131
121
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
132
|
-
const attachments = (0, FormUtils_1.getAttachments)(context
|
|
122
|
+
const attachments = (0, FormUtils_1.getAttachments)(context.form);
|
|
133
123
|
let submitContentType = submitAs;
|
|
134
124
|
let formData;
|
|
135
125
|
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
package/lib/utils/FormUtils.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export declare const randomWord: (l: number) => string;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const isEmpty: (value: any) => boolean;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
16
|
+
* Returns the list of attachments with its data reference
|
|
17
|
+
* @param input form model
|
|
18
|
+
* @returns list of file attachments {@link FileObject} present in the form
|
|
18
19
|
*/
|
|
19
20
|
export declare const getAttachments: (input: ContainerModel) => any;
|
|
20
21
|
/**
|
package/lib/utils/FormUtils.js
CHANGED
|
@@ -40,8 +40,9 @@ const isEmpty = (value) => {
|
|
|
40
40
|
};
|
|
41
41
|
exports.isEmpty = isEmpty;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @
|
|
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
|
|
45
46
|
*/
|
|
46
47
|
const getAttachments = (input) => {
|
|
47
48
|
const items = input.items || [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.12",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/json-formula": "^0.1.44",
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
38
|
+
"@aemforms/af-formatters": "^0.22.12"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^27.5.1",
|