@aemforms/af-core 0.22.106 → 0.22.108
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/esm/afb-runtime.js +103 -27
- package/esm/types/src/Form.d.ts +2 -1
- package/esm/types/src/index.d.ts +2 -2
- package/esm/types/src/utils/FormUtils.d.ts +1 -0
- package/lib/Button.js +1 -1
- package/lib/Form.d.ts +2 -1
- package/lib/Form.js +7 -3
- package/lib/data/DataValue.js +18 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/rules/FunctionRuntime.js +13 -3
- package/lib/utils/FormUtils.d.ts +1 -0
- package/lib/utils/FormUtils.js +74 -20
- package/lib/utils/JsonUtils.js +2 -1
- package/package.json +2 -2
package/esm/afb-runtime.js
CHANGED
|
@@ -141,7 +141,8 @@ const getProperty = (data, key, def) => {
|
|
|
141
141
|
const isFile = function (item) {
|
|
142
142
|
return (item?.type === 'file' || item?.type === 'file[]') ||
|
|
143
143
|
((item?.type === 'string' || item?.type === 'string[]') &&
|
|
144
|
-
(item?.format === 'binary' || item?.format === 'data-url'))
|
|
144
|
+
(item?.format === 'binary' || item?.format === 'data-url')) ||
|
|
145
|
+
item?.fieldType === 'file-input';
|
|
145
146
|
};
|
|
146
147
|
const isCheckbox = function (item) {
|
|
147
148
|
const fieldType = item?.fieldType || defaultFieldTypes(item);
|
|
@@ -223,6 +224,23 @@ class DataValue {
|
|
|
223
224
|
return (!enabled && this.$_fields.length);
|
|
224
225
|
}
|
|
225
226
|
get $value() {
|
|
227
|
+
const formInFileInput = this.$_fields.find(x => {
|
|
228
|
+
if (isFile(x)) {
|
|
229
|
+
return x;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (formInFileInput && (this.$_type === 'string' || this.$_type === 'string[]' || this.$_type === 'array')) {
|
|
233
|
+
const attachmentMap = formInFileInput.form._exportDataAttachmentMap;
|
|
234
|
+
if (attachmentMap && attachmentMap[formInFileInput.id]) {
|
|
235
|
+
const attachment = attachmentMap[formInFileInput.id];
|
|
236
|
+
if (Array.isArray(attachment)) {
|
|
237
|
+
return attachment.map(item => item.data);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return attachment.data;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
226
244
|
return this.$_value;
|
|
227
245
|
}
|
|
228
246
|
setValue(typedValue, originalValue, fromField) {
|
|
@@ -656,33 +674,77 @@ const randomWord = (l) => {
|
|
|
656
674
|
}
|
|
657
675
|
return ret.join('');
|
|
658
676
|
};
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
+
const processItem = (item, excludeUnbound, isAsync) => {
|
|
678
|
+
if (excludeUnbound && item.dataRef === null) {
|
|
679
|
+
return isAsync ? Promise.resolve(null) : null;
|
|
680
|
+
}
|
|
681
|
+
let ret = null;
|
|
682
|
+
if (item.isContainer) {
|
|
683
|
+
return isAsync
|
|
684
|
+
? readAttachments(item, excludeUnbound).then(res => res)
|
|
685
|
+
: getAttachments(item, excludeUnbound);
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
if (isFile(item.getState())) {
|
|
689
|
+
ret = {};
|
|
690
|
+
const name = item.name || '';
|
|
691
|
+
const dataRef = (item.dataRef != null)
|
|
692
|
+
? item.dataRef
|
|
693
|
+
: (name.length > 0 ? item.name : undefined);
|
|
694
|
+
if (item.value instanceof Array) {
|
|
695
|
+
if (item.type === 'string[]') {
|
|
696
|
+
if (isAsync) {
|
|
697
|
+
return item.serialize().then(serializedFiles => {
|
|
698
|
+
ret[item.id] = serializedFiles.map((x) => {
|
|
699
|
+
return { ...x, 'dataRef': dataRef };
|
|
700
|
+
});
|
|
701
|
+
return ret;
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
ret[item.id] = item.value.map((x) => {
|
|
706
|
+
return { ...x, 'dataRef': dataRef };
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
677
711
|
ret[item.id] = item.value.map((x) => {
|
|
678
712
|
return { ...x, 'dataRef': dataRef };
|
|
679
713
|
});
|
|
680
714
|
}
|
|
681
|
-
|
|
715
|
+
}
|
|
716
|
+
else if (item.value != null) {
|
|
717
|
+
if (item.type === 'string') {
|
|
718
|
+
if (isAsync) {
|
|
719
|
+
return item.serialize().then(serializedFile => {
|
|
720
|
+
ret[item.id] = { ...serializedFile[0], 'dataRef': dataRef };
|
|
721
|
+
return ret;
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
ret[item.id] = { ...item.value, 'dataRef': dataRef };
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
682
729
|
ret[item.id] = { ...item.value, 'dataRef': dataRef };
|
|
683
730
|
}
|
|
684
731
|
}
|
|
685
732
|
}
|
|
733
|
+
}
|
|
734
|
+
return isAsync ? Promise.resolve(ret) : ret;
|
|
735
|
+
};
|
|
736
|
+
const readAttachments = async (input, excludeUnbound = false) => {
|
|
737
|
+
const items = input.items || [];
|
|
738
|
+
return items.reduce(async (accPromise, item) => {
|
|
739
|
+
const acc = await accPromise;
|
|
740
|
+
const ret = await processItem(item, excludeUnbound, true);
|
|
741
|
+
return Object.assign(acc, ret);
|
|
742
|
+
}, Promise.resolve({}));
|
|
743
|
+
};
|
|
744
|
+
const getAttachments = (input, excludeUnbound = false) => {
|
|
745
|
+
const items = input.items || [];
|
|
746
|
+
return items.reduce((acc, item) => {
|
|
747
|
+
const ret = processItem(item, excludeUnbound, false);
|
|
686
748
|
return Object.assign(acc, ret);
|
|
687
749
|
}, {});
|
|
688
750
|
};
|
|
@@ -2657,10 +2719,10 @@ const urlEncoded = (data) => {
|
|
|
2657
2719
|
const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => {
|
|
2658
2720
|
const endpoint = action || context.form.action;
|
|
2659
2721
|
let data = input_data;
|
|
2722
|
+
const attachments = await readAttachments(context.form, true);
|
|
2660
2723
|
if (typeof data != 'object' || data == null) {
|
|
2661
|
-
data = context.form.exportData();
|
|
2724
|
+
data = context.form.exportData(attachments);
|
|
2662
2725
|
}
|
|
2663
|
-
const attachments = getAttachments(context.form, true);
|
|
2664
2726
|
let submitContentType = submitAs;
|
|
2665
2727
|
const submitDataAndMetaData = { 'data': data, ...metadata };
|
|
2666
2728
|
let formData = submitDataAndMetaData;
|
|
@@ -3087,7 +3149,17 @@ class FunctionRuntimeImpl {
|
|
|
3087
3149
|
interpreter.globals.form.dispatch(event);
|
|
3088
3150
|
}
|
|
3089
3151
|
else {
|
|
3090
|
-
|
|
3152
|
+
const dispatchEventOnElement = (element, event, interpreter) => {
|
|
3153
|
+
interpreter.globals.form.getElement(element.$id).dispatch(event);
|
|
3154
|
+
};
|
|
3155
|
+
if (Array.isArray(element) && element.length > 0 && typeof element.$id === 'undefined') {
|
|
3156
|
+
element.forEach(el => {
|
|
3157
|
+
dispatchEventOnElement(el, event, interpreter);
|
|
3158
|
+
});
|
|
3159
|
+
}
|
|
3160
|
+
else {
|
|
3161
|
+
dispatchEventOnElement(element, event, interpreter);
|
|
3162
|
+
}
|
|
3091
3163
|
}
|
|
3092
3164
|
}
|
|
3093
3165
|
return {};
|
|
@@ -3153,6 +3225,7 @@ class Form extends Container {
|
|
|
3153
3225
|
_fields = {};
|
|
3154
3226
|
_ids;
|
|
3155
3227
|
_invalidFields = [];
|
|
3228
|
+
_exportDataAttachmentMap = {};
|
|
3156
3229
|
_captcha = null;
|
|
3157
3230
|
constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue(), logLevel = 'off', mode = 'create') {
|
|
3158
3231
|
super(n, { fieldFactory: fieldFactory, mode });
|
|
@@ -3217,8 +3290,11 @@ class Form extends Container {
|
|
|
3217
3290
|
this.syncDataAndFormModel(this.getDataNode());
|
|
3218
3291
|
this._eventQueue.runPendingQueue();
|
|
3219
3292
|
}
|
|
3220
|
-
exportData() {
|
|
3221
|
-
|
|
3293
|
+
exportData(attachmentSerializedMap = {}) {
|
|
3294
|
+
this._exportDataAttachmentMap = attachmentSerializedMap;
|
|
3295
|
+
const finalData = this.getDataNode()?.$value;
|
|
3296
|
+
this._exportDataAttachmentMap = {};
|
|
3297
|
+
return finalData;
|
|
3222
3298
|
}
|
|
3223
3299
|
setAdditionalSubmitMetadata(metadata) {
|
|
3224
3300
|
this.additionalSubmitMetadata = { ...this.additionalSubmitMetadata, ...metadata };
|
|
@@ -3431,7 +3507,7 @@ class Form extends Container {
|
|
|
3431
3507
|
}
|
|
3432
3508
|
submit(action, context) {
|
|
3433
3509
|
const validate_form = action?.payload?.validate_form;
|
|
3434
|
-
if (
|
|
3510
|
+
if (validate_form === false || this.validate().length === 0) {
|
|
3435
3511
|
const payload = action?.payload || {};
|
|
3436
3512
|
const successEventName = payload?.success ? payload?.success : 'submitSuccess';
|
|
3437
3513
|
const failureEventName = payload?.error ? payload?.error : 'submitError';
|
|
@@ -4684,7 +4760,7 @@ class Button extends Field {
|
|
|
4684
4760
|
return;
|
|
4685
4761
|
}
|
|
4686
4762
|
if (this._jsonModel.buttonType === 'submit') {
|
|
4687
|
-
return this.form.dispatch(new Submit());
|
|
4763
|
+
return this.form.dispatch(new Submit({ validate_form: true }));
|
|
4688
4764
|
}
|
|
4689
4765
|
if (this._jsonModel.buttonType === 'reset') {
|
|
4690
4766
|
return this.form.dispatch(new Reset());
|
package/esm/types/src/Form.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
15
15
|
private _fields;
|
|
16
16
|
_ids: Generator<string, void, string>;
|
|
17
17
|
private _invalidFields;
|
|
18
|
+
_exportDataAttachmentMap: Record<string, any>;
|
|
18
19
|
private _captcha;
|
|
19
20
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
20
21
|
protected _applyDefaultsInModel(): void;
|
|
@@ -28,7 +29,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
28
29
|
get action(): string | undefined;
|
|
29
30
|
get isFragment(): boolean;
|
|
30
31
|
importData(dataModel: any): void;
|
|
31
|
-
exportData(): any;
|
|
32
|
+
exportData(attachmentSerializedMap?: {}): any;
|
|
32
33
|
setAdditionalSubmitMetadata(metadata: Record<string, any>): void;
|
|
33
34
|
get specVersion(): Version;
|
|
34
35
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
package/esm/types/src/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './controller/Events';
|
|
|
4
4
|
export * from './utils/TranslationUtils';
|
|
5
5
|
export * from './utils/JsonUtils';
|
|
6
6
|
export * from './utils/SchemaUtils';
|
|
7
|
-
import { getFileSizeInBytes, extractFileInfo, isEmpty } from './utils/FormUtils';
|
|
7
|
+
import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
|
|
8
8
|
import { BaseNode } from './BaseNode';
|
|
9
9
|
import Checkbox from './Checkbox';
|
|
10
10
|
import CheckboxGroup from './CheckboxGroup';
|
|
@@ -21,4 +21,4 @@ import Node from './Node';
|
|
|
21
21
|
import Scriptable from './Scriptable';
|
|
22
22
|
import Form from './Form';
|
|
23
23
|
import { FunctionRuntime, request } from './rules/FunctionRuntime';
|
|
24
|
-
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
|
|
24
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContainerModel } from '../types/index';
|
|
2
2
|
export declare const randomWord: (l: number) => string;
|
|
3
3
|
export declare const isEmpty: (value: any) => boolean;
|
|
4
|
+
export declare const readAttachments: (input: ContainerModel, excludeUnbound?: boolean) => Promise<any>;
|
|
4
5
|
export declare const getAttachments: (input: ContainerModel, excludeUnbound?: boolean) => any;
|
|
5
6
|
export declare const getFileSizeInBytes: (str: any) => number;
|
|
6
7
|
export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
|
package/lib/Button.js
CHANGED
|
@@ -12,7 +12,7 @@ class Button extends Field_1.default {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
if (this._jsonModel.buttonType === 'submit') {
|
|
15
|
-
return this.form.dispatch(new Events_1.Submit());
|
|
15
|
+
return this.form.dispatch(new Events_1.Submit({ validate_form: true }));
|
|
16
16
|
}
|
|
17
17
|
if (this._jsonModel.buttonType === 'reset') {
|
|
18
18
|
return this.form.dispatch(new Events_1.Reset());
|
package/lib/Form.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
15
15
|
private _fields;
|
|
16
16
|
_ids: Generator<string, void, string>;
|
|
17
17
|
private _invalidFields;
|
|
18
|
+
_exportDataAttachmentMap: Record<string, any>;
|
|
18
19
|
private _captcha;
|
|
19
20
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
20
21
|
protected _applyDefaultsInModel(): void;
|
|
@@ -28,7 +29,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
28
29
|
get action(): string | undefined;
|
|
29
30
|
get isFragment(): boolean;
|
|
30
31
|
importData(dataModel: any): void;
|
|
31
|
-
exportData(): any;
|
|
32
|
+
exportData(attachmentSerializedMap?: {}): any;
|
|
32
33
|
setAdditionalSubmitMetadata(metadata: Record<string, any>): void;
|
|
33
34
|
get specVersion(): Version;
|
|
34
35
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
package/lib/Form.js
CHANGED
|
@@ -32,6 +32,7 @@ class Form extends Container_1.default {
|
|
|
32
32
|
this.additionalSubmitMetadata = {};
|
|
33
33
|
this._fields = {};
|
|
34
34
|
this._invalidFields = [];
|
|
35
|
+
this._exportDataAttachmentMap = {};
|
|
35
36
|
this._captcha = null;
|
|
36
37
|
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
37
38
|
this._logger = new Logger_1.Logger(logLevel);
|
|
@@ -91,9 +92,12 @@ class Form extends Container_1.default {
|
|
|
91
92
|
this.syncDataAndFormModel(this.getDataNode());
|
|
92
93
|
this._eventQueue.runPendingQueue();
|
|
93
94
|
}
|
|
94
|
-
exportData() {
|
|
95
|
+
exportData(attachmentSerializedMap = {}) {
|
|
95
96
|
var _a;
|
|
96
|
-
|
|
97
|
+
this._exportDataAttachmentMap = attachmentSerializedMap;
|
|
98
|
+
const finalData = (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
|
|
99
|
+
this._exportDataAttachmentMap = {};
|
|
100
|
+
return finalData;
|
|
97
101
|
}
|
|
98
102
|
setAdditionalSubmitMetadata(metadata) {
|
|
99
103
|
this.additionalSubmitMetadata = Object.assign(Object.assign({}, this.additionalSubmitMetadata), metadata);
|
|
@@ -264,7 +268,7 @@ class Form extends Container_1.default {
|
|
|
264
268
|
submit(action, context) {
|
|
265
269
|
var _a;
|
|
266
270
|
const validate_form = (_a = action === null || action === void 0 ? void 0 : action.payload) === null || _a === void 0 ? void 0 : _a.validate_form;
|
|
267
|
-
if (
|
|
271
|
+
if (validate_form === false || this.validate().length === 0) {
|
|
268
272
|
const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
|
|
269
273
|
const successEventName = (payload === null || payload === void 0 ? void 0 : payload.success) ? payload === null || payload === void 0 ? void 0 : payload.success : 'submitSuccess';
|
|
270
274
|
const failureEventName = (payload === null || payload === void 0 ? void 0 : payload.error) ? payload === null || payload === void 0 ? void 0 : payload.error : 'submitError';
|
package/lib/data/DataValue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
3
4
|
class DataValue {
|
|
4
5
|
constructor($_name, $_value, $_type = typeof $_value, parent) {
|
|
5
6
|
this.$_name = $_name;
|
|
@@ -19,6 +20,23 @@ class DataValue {
|
|
|
19
20
|
return (!enabled && this.$_fields.length);
|
|
20
21
|
}
|
|
21
22
|
get $value() {
|
|
23
|
+
const formInFileInput = this.$_fields.find(x => {
|
|
24
|
+
if ((0, JsonUtils_1.isFile)(x)) {
|
|
25
|
+
return x;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (formInFileInput && (this.$_type === 'string' || this.$_type === 'string[]' || this.$_type === 'array')) {
|
|
29
|
+
const attachmentMap = formInFileInput.form._exportDataAttachmentMap;
|
|
30
|
+
if (attachmentMap && attachmentMap[formInFileInput.id]) {
|
|
31
|
+
const attachment = attachmentMap[formInFileInput.id];
|
|
32
|
+
if (Array.isArray(attachment)) {
|
|
33
|
+
return attachment.map(item => item.data);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return attachment.data;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
return this.$_value;
|
|
23
41
|
}
|
|
24
42
|
setValue(typedValue, originalValue, fromField) {
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './controller/Events';
|
|
|
4
4
|
export * from './utils/TranslationUtils';
|
|
5
5
|
export * from './utils/JsonUtils';
|
|
6
6
|
export * from './utils/SchemaUtils';
|
|
7
|
-
import { getFileSizeInBytes, extractFileInfo, isEmpty } from './utils/FormUtils';
|
|
7
|
+
import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
|
|
8
8
|
import { BaseNode } from './BaseNode';
|
|
9
9
|
import Checkbox from './Checkbox';
|
|
10
10
|
import CheckboxGroup from './CheckboxGroup';
|
|
@@ -21,4 +21,4 @@ import Node from './Node';
|
|
|
21
21
|
import Scriptable from './Scriptable';
|
|
22
22
|
import Form from './Form';
|
|
23
23
|
import { FunctionRuntime, request } from './rules/FunctionRuntime';
|
|
24
|
-
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
|
|
24
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Captcha = exports.EmailInput = exports.SubmitMetaData = exports.isEmpty = exports.request = exports.FunctionRuntime = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
20
|
+
exports.Captcha = exports.EmailInput = exports.SubmitMetaData = exports.isEmpty = exports.request = exports.FunctionRuntime = exports.readAttachments = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
21
21
|
__exportStar(require("./FormInstance"), exports);
|
|
22
22
|
__exportStar(require("./types/index"), exports);
|
|
23
23
|
__exportStar(require("./controller/Events"), exports);
|
|
@@ -28,6 +28,7 @@ const FormUtils_1 = require("./utils/FormUtils");
|
|
|
28
28
|
Object.defineProperty(exports, "getFileSizeInBytes", { enumerable: true, get: function () { return FormUtils_1.getFileSizeInBytes; } });
|
|
29
29
|
Object.defineProperty(exports, "extractFileInfo", { enumerable: true, get: function () { return FormUtils_1.extractFileInfo; } });
|
|
30
30
|
Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return FormUtils_1.isEmpty; } });
|
|
31
|
+
Object.defineProperty(exports, "readAttachments", { enumerable: true, get: function () { return FormUtils_1.readAttachments; } });
|
|
31
32
|
const BaseNode_1 = require("./BaseNode");
|
|
32
33
|
Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return BaseNode_1.BaseNode; } });
|
|
33
34
|
const Checkbox_1 = __importDefault(require("./Checkbox"));
|
|
@@ -95,10 +95,10 @@ const urlEncoded = (data) => {
|
|
|
95
95
|
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
96
|
const endpoint = action || context.form.action;
|
|
97
97
|
let data = input_data;
|
|
98
|
+
const attachments = yield (0, FormUtils_1.readAttachments)(context.form, true);
|
|
98
99
|
if (typeof data != 'object' || data == null) {
|
|
99
|
-
data = context.form.exportData();
|
|
100
|
+
data = context.form.exportData(attachments);
|
|
100
101
|
}
|
|
101
|
-
const attachments = (0, FormUtils_1.getAttachments)(context.form, true);
|
|
102
102
|
let submitContentType = submitAs;
|
|
103
103
|
const submitDataAndMetaData = Object.assign({ 'data': data }, metadata);
|
|
104
104
|
let formData = submitDataAndMetaData;
|
|
@@ -527,7 +527,17 @@ class FunctionRuntimeImpl {
|
|
|
527
527
|
interpreter.globals.form.dispatch(event);
|
|
528
528
|
}
|
|
529
529
|
else {
|
|
530
|
-
|
|
530
|
+
const dispatchEventOnElement = (element, event, interpreter) => {
|
|
531
|
+
interpreter.globals.form.getElement(element.$id).dispatch(event);
|
|
532
|
+
};
|
|
533
|
+
if (Array.isArray(element) && element.length > 0 && typeof element.$id === 'undefined') {
|
|
534
|
+
element.forEach(el => {
|
|
535
|
+
dispatchEventOnElement(el, event, interpreter);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
dispatchEventOnElement(element, event, interpreter);
|
|
540
|
+
}
|
|
531
541
|
}
|
|
532
542
|
}
|
|
533
543
|
return {};
|
package/lib/utils/FormUtils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContainerModel } from '../types/index';
|
|
2
2
|
export declare const randomWord: (l: number) => string;
|
|
3
3
|
export declare const isEmpty: (value: any) => boolean;
|
|
4
|
+
export declare const readAttachments: (input: ContainerModel, excludeUnbound?: boolean) => Promise<any>;
|
|
4
5
|
export declare const getAttachments: (input: ContainerModel, excludeUnbound?: boolean) => any;
|
|
5
6
|
export declare const getFileSizeInBytes: (str: any) => number;
|
|
6
7
|
export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
|
package/lib/utils/FormUtils.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceTemplatePlaceholders = exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
|
|
12
|
+
exports.replaceTemplatePlaceholders = exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.readAttachments = exports.isEmpty = exports.randomWord = void 0;
|
|
4
13
|
const JsonUtils_1 = require("./JsonUtils");
|
|
5
14
|
const FileObject_1 = require("../FileObject");
|
|
6
15
|
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
|
|
@@ -24,33 +33,78 @@ const isEmpty = (value) => {
|
|
|
24
33
|
return value === '' || value === null || value === undefined;
|
|
25
34
|
};
|
|
26
35
|
exports.isEmpty = isEmpty;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
const processItem = (item, excludeUnbound, isAsync) => {
|
|
37
|
+
if (excludeUnbound && item.dataRef === null) {
|
|
38
|
+
return isAsync ? Promise.resolve(null) : null;
|
|
39
|
+
}
|
|
40
|
+
let ret = null;
|
|
41
|
+
if (item.isContainer) {
|
|
42
|
+
return isAsync
|
|
43
|
+
? (0, exports.readAttachments)(item, excludeUnbound).then(res => res)
|
|
44
|
+
: (0, exports.getAttachments)(item, excludeUnbound);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if ((0, JsonUtils_1.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
|
+
if (item.type === 'string[]') {
|
|
55
|
+
if (isAsync) {
|
|
56
|
+
return item.serialize().then(serializedFiles => {
|
|
57
|
+
ret[item.id] = serializedFiles.map((x) => {
|
|
58
|
+
return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
|
|
59
|
+
});
|
|
60
|
+
return ret;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
ret[item.id] = item.value.map((x) => {
|
|
65
|
+
return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
45
70
|
ret[item.id] = item.value.map((x) => {
|
|
46
71
|
return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
|
|
47
72
|
});
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
}
|
|
75
|
+
else if (item.value != null) {
|
|
76
|
+
if (item.type === 'string') {
|
|
77
|
+
if (isAsync) {
|
|
78
|
+
return item.serialize().then(serializedFile => {
|
|
79
|
+
ret[item.id] = Object.assign(Object.assign({}, serializedFile[0]), { 'dataRef': dataRef });
|
|
80
|
+
return ret;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
ret[item.id] = Object.assign(Object.assign({}, item.value), { 'dataRef': dataRef });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
50
88
|
ret[item.id] = Object.assign(Object.assign({}, item.value), { 'dataRef': dataRef });
|
|
51
89
|
}
|
|
52
90
|
}
|
|
53
91
|
}
|
|
92
|
+
}
|
|
93
|
+
return isAsync ? Promise.resolve(ret) : ret;
|
|
94
|
+
};
|
|
95
|
+
const readAttachments = (input, excludeUnbound = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
const items = input.items || [];
|
|
97
|
+
return items.reduce((accPromise, item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const acc = yield accPromise;
|
|
99
|
+
const ret = yield processItem(item, excludeUnbound, true);
|
|
100
|
+
return Object.assign(acc, ret);
|
|
101
|
+
}), Promise.resolve({}));
|
|
102
|
+
});
|
|
103
|
+
exports.readAttachments = readAttachments;
|
|
104
|
+
const getAttachments = (input, excludeUnbound = false) => {
|
|
105
|
+
const items = input.items || [];
|
|
106
|
+
return items.reduce((acc, item) => {
|
|
107
|
+
const ret = processItem(item, excludeUnbound, false);
|
|
54
108
|
return Object.assign(acc, ret);
|
|
55
109
|
}, {});
|
|
56
110
|
};
|
package/lib/utils/JsonUtils.js
CHANGED
|
@@ -19,7 +19,8 @@ exports.getProperty = getProperty;
|
|
|
19
19
|
const isFile = function (item) {
|
|
20
20
|
return ((item === null || item === void 0 ? void 0 : item.type) === 'file' || (item === null || item === void 0 ? void 0 : item.type) === 'file[]') ||
|
|
21
21
|
(((item === null || item === void 0 ? void 0 : item.type) === 'string' || (item === null || item === void 0 ? void 0 : item.type) === 'string[]') &&
|
|
22
|
-
((item === null || item === void 0 ? void 0 : item.format) === 'binary' || (item === null || item === void 0 ? void 0 : item.format) === 'data-url'))
|
|
22
|
+
((item === null || item === void 0 ? void 0 : item.format) === 'binary' || (item === null || item === void 0 ? void 0 : item.format) === 'data-url')) ||
|
|
23
|
+
(item === null || item === void 0 ? void 0 : item.fieldType) === 'file-input';
|
|
23
24
|
};
|
|
24
25
|
exports.isFile = isFile;
|
|
25
26
|
const checkIfConstraintsArePresent = function (item) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.108",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@adobe/json-formula": "0.1.50",
|
|
40
|
-
"@aemforms/af-formatters": "^0.22.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.108"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|