@aemforms/af-core 0.15.0 → 0.18.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/README.md +9 -1
- package/lib/BaseNode.d.ts +2 -1
- package/lib/BaseNode.js +33 -18
- package/lib/Checkbox.d.ts +2 -2
- package/lib/Container.d.ts +1 -1
- package/lib/Container.js +21 -11
- package/lib/Field.d.ts +8 -2
- package/lib/FileUpload.d.ts +1 -1
- package/lib/Scriptable.js +2 -2
- package/lib/data/DataGroup.d.ts +6 -5
- package/lib/data/DataGroup.js +26 -13
- package/lib/rules/FunctionRuntime.d.ts +2 -2
- package/lib/rules/FunctionRuntime.js +48 -38
- package/lib/types/Json.js +1 -1
- package/lib/types/Model.d.ts +1 -0
- package/lib/utils/TranslationUtils.d.ts +7 -0
- package/lib/utils/TranslationUtils.js +29 -8
- package/lib/utils/ValidationUtils.d.ts +2 -2
- package/lib/utils/ValidationUtils.js +4 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -31,4 +31,12 @@ import {validateFormInstance} from '@aemforms/af-core';
|
|
|
31
31
|
const formJson = {..}
|
|
32
32
|
const data = {...}
|
|
33
33
|
const valid = validateFormInstance(formJson, data)
|
|
34
|
-
```
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
Copyright 2022 Adobe, Inc.
|
|
39
|
+
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
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.
|
package/lib/BaseNode.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
95
95
|
/**
|
|
96
96
|
* @private
|
|
97
97
|
*/
|
|
98
|
-
_bindToDataModel(contextualDataModel
|
|
98
|
+
_bindToDataModel(contextualDataModel: DataGroup): void;
|
|
99
99
|
private _data?;
|
|
100
100
|
/**
|
|
101
101
|
* @private
|
|
@@ -109,6 +109,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
109
109
|
});
|
|
110
110
|
abstract defaultDataModel(name: string | number): DataValue | undefined;
|
|
111
111
|
abstract importData(a: DataGroup): any;
|
|
112
|
+
getNonTransparentParent(): ContainerModel;
|
|
112
113
|
/**
|
|
113
114
|
* called after the node is inserted in the parent
|
|
114
115
|
* @private
|
package/lib/BaseNode.js
CHANGED
|
@@ -189,11 +189,11 @@ class BaseNode {
|
|
|
189
189
|
* Transparent form fields are meant only for creation of view. They are also not part of data
|
|
190
190
|
*/
|
|
191
191
|
isTransparent() {
|
|
192
|
-
var _a
|
|
192
|
+
var _a;
|
|
193
193
|
// named form fields are not transparent
|
|
194
194
|
// @ts-ignore
|
|
195
|
-
// handling
|
|
196
|
-
const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array'
|
|
195
|
+
// handling array use-case as items of array can be unnamed
|
|
196
|
+
const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array';
|
|
197
197
|
return !this._jsonModel.name && !isNonTransparent;
|
|
198
198
|
}
|
|
199
199
|
getState() {
|
|
@@ -300,10 +300,10 @@ class BaseNode {
|
|
|
300
300
|
}
|
|
301
301
|
const dataRef = this._jsonModel.dataRef;
|
|
302
302
|
let _data;
|
|
303
|
-
if (dataRef === null) {
|
|
303
|
+
if (dataRef === null) { // null data binding
|
|
304
304
|
_data = EmptyDataValue_1.default;
|
|
305
305
|
}
|
|
306
|
-
else if (dataRef !== undefined) {
|
|
306
|
+
else if (dataRef !== undefined) { // explicit data binding
|
|
307
307
|
if (this._tokens.length === 0) {
|
|
308
308
|
this._tokens = (0, DataRefParser_1.tokenize)(dataRef);
|
|
309
309
|
}
|
|
@@ -317,35 +317,38 @@ class BaseNode {
|
|
|
317
317
|
_data = (0, DataRefParser_1.resolveData)(searchData, this._tokens, create);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
else {
|
|
321
|
-
if (
|
|
320
|
+
else { // name data binding
|
|
321
|
+
if ( //@ts-ignore
|
|
322
|
+
contextualDataModel !== EmptyDataValue_1.default) {
|
|
322
323
|
const name = this._jsonModel.name || '';
|
|
323
324
|
const key = contextualDataModel.$type === 'array' ? this.index : name;
|
|
324
325
|
if (key !== '') {
|
|
325
326
|
const create = this.defaultDataModel(key);
|
|
326
327
|
if (create !== undefined) {
|
|
327
|
-
_data = contextualDataModel.$getDataNode(key)
|
|
328
|
-
|
|
328
|
+
_data = contextualDataModel.$getDataNode(key);
|
|
329
|
+
if (_data === undefined) {
|
|
330
|
+
_data = create;
|
|
331
|
+
contextualDataModel.$addDataNode(key, _data);
|
|
332
|
+
}
|
|
329
333
|
}
|
|
330
334
|
}
|
|
331
335
|
else {
|
|
332
|
-
_data =
|
|
336
|
+
_data = undefined;
|
|
333
337
|
}
|
|
334
338
|
}
|
|
335
339
|
}
|
|
336
|
-
if (
|
|
337
|
-
|
|
340
|
+
if (_data) {
|
|
341
|
+
if (!this.isContainer) {
|
|
342
|
+
_data = _data === null || _data === void 0 ? void 0 : _data.$convertToDataValue();
|
|
343
|
+
}
|
|
344
|
+
_data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
|
|
345
|
+
this._data = _data;
|
|
338
346
|
}
|
|
339
|
-
_data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
|
|
340
|
-
this._data = _data;
|
|
341
347
|
}
|
|
342
348
|
/**
|
|
343
349
|
* @private
|
|
344
350
|
*/
|
|
345
351
|
getDataNode() {
|
|
346
|
-
if (this._data === undefined) {
|
|
347
|
-
return this.parent.getDataNode();
|
|
348
|
-
}
|
|
349
352
|
return this._data;
|
|
350
353
|
}
|
|
351
354
|
get properties() {
|
|
@@ -354,13 +357,25 @@ class BaseNode {
|
|
|
354
357
|
set properties(p) {
|
|
355
358
|
this._setProperty('properties', Object.assign({}, p));
|
|
356
359
|
}
|
|
360
|
+
getNonTransparentParent() {
|
|
361
|
+
let nonTransparentParent = this.parent;
|
|
362
|
+
while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
|
|
363
|
+
nonTransparentParent = nonTransparentParent.parent;
|
|
364
|
+
}
|
|
365
|
+
return nonTransparentParent;
|
|
366
|
+
}
|
|
357
367
|
/**
|
|
358
368
|
* called after the node is inserted in the parent
|
|
359
369
|
* @private
|
|
360
370
|
*/
|
|
361
371
|
_initialize() {
|
|
362
372
|
if (typeof this._data === 'undefined') {
|
|
363
|
-
|
|
373
|
+
let dataNode, parent = this.parent;
|
|
374
|
+
do {
|
|
375
|
+
//@ts-ignore
|
|
376
|
+
dataNode = parent.getDataNode();
|
|
377
|
+
parent = parent.parent;
|
|
378
|
+
} while (dataNode === undefined);
|
|
364
379
|
this._bindToDataModel(dataNode);
|
|
365
380
|
}
|
|
366
381
|
}
|
package/lib/Checkbox.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ declare class Checkbox extends Field {
|
|
|
12
12
|
valid: boolean;
|
|
13
13
|
value: any;
|
|
14
14
|
};
|
|
15
|
-
format: (constraint: string, input: string) => {
|
|
15
|
+
format: (constraint: string, input: string | null) => {
|
|
16
|
+
value: string | null;
|
|
16
17
|
valid: boolean;
|
|
17
|
-
value: string;
|
|
18
18
|
};
|
|
19
19
|
minimum: (constraint: number, value: number) => {
|
|
20
20
|
valid: boolean;
|
package/lib/Container.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
323
323
|
/**
|
|
324
324
|
* @private
|
|
325
325
|
*/
|
|
326
|
-
importData(contextualDataModel
|
|
326
|
+
importData(contextualDataModel: DataGroup): void;
|
|
327
327
|
/**
|
|
328
328
|
* prefill the form with data on the given element
|
|
329
329
|
* @param dataModel
|
package/lib/Container.js
CHANGED
|
@@ -103,22 +103,19 @@ class Container extends Scriptable_1.default {
|
|
|
103
103
|
nonTransparentParent = nonTransparentParent.parent;
|
|
104
104
|
}
|
|
105
105
|
if (typeof index !== 'number' || index > nonTransparentParent._children.length) {
|
|
106
|
-
index =
|
|
106
|
+
index = this._children.length;
|
|
107
107
|
}
|
|
108
108
|
const itemTemplate = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson));
|
|
109
109
|
//@ts-ignore
|
|
110
|
-
const retVal = this._createChild(itemTemplate, { parent:
|
|
110
|
+
const retVal = this._createChild(itemTemplate, { parent: this, index });
|
|
111
111
|
this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
|
|
112
|
-
if (index ===
|
|
113
|
-
|
|
114
|
-
//(this.getDataNode() as DataGroup).$addDataNode(index);
|
|
112
|
+
if (index === this._children.length) {
|
|
113
|
+
this._children.push(retVal);
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
116
|
// @ts-ignore
|
|
118
|
-
|
|
119
|
-
//(this.getDataNode() as DataGroup).$addDataNode();
|
|
117
|
+
this._children.splice(index, 0, retVal);
|
|
120
118
|
}
|
|
121
|
-
retVal._initialize();
|
|
122
119
|
return retVal;
|
|
123
120
|
}
|
|
124
121
|
indexOf(f) {
|
|
@@ -158,12 +155,14 @@ class Container extends Scriptable_1.default {
|
|
|
158
155
|
}
|
|
159
156
|
for (let i = 0; i < this._jsonModel.initialItems; i++) {
|
|
160
157
|
//@ts-ignore
|
|
161
|
-
this._addChild(this._itemTemplate);
|
|
158
|
+
const child = this._addChild(this._itemTemplate);
|
|
159
|
+
child._initialize();
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
else if (items.length > 0) {
|
|
165
163
|
items.forEach((item) => {
|
|
166
|
-
this._addChild(item);
|
|
164
|
+
const child = this._addChild(item);
|
|
165
|
+
child._initialize();
|
|
167
166
|
});
|
|
168
167
|
this._jsonModel.minItems = this._children.length;
|
|
169
168
|
this._jsonModel.maxItems = this._children.length;
|
|
@@ -178,7 +177,17 @@ class Container extends Scriptable_1.default {
|
|
|
178
177
|
if (action.type === 'addItem' && this._itemTemplate != null) {
|
|
179
178
|
//@ts-ignore
|
|
180
179
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
180
|
+
const dataNode = this.getDataNode();
|
|
181
|
+
let index = action.payload;
|
|
182
|
+
if (typeof index !== 'number' || index > this._children.length) {
|
|
183
|
+
index = this._children.length;
|
|
184
|
+
}
|
|
181
185
|
const retVal = this._addChild(this._itemTemplate, action.payload);
|
|
186
|
+
const _data = retVal.defaultDataModel(index);
|
|
187
|
+
if (_data) {
|
|
188
|
+
dataNode.$addDataNode(index, _data);
|
|
189
|
+
}
|
|
190
|
+
retVal._initialize();
|
|
182
191
|
this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState, null));
|
|
183
192
|
retVal.dispatch(new controller_1.Initialize());
|
|
184
193
|
retVal.dispatch(new controller_1.ExecuteRule());
|
|
@@ -262,7 +271,8 @@ class Container extends Scriptable_1.default {
|
|
|
262
271
|
const items2Remove = Math.min(itemsLength - dataLength, itemsLength - minItems);
|
|
263
272
|
while (items2Add > 0) {
|
|
264
273
|
items2Add--;
|
|
265
|
-
this._addChild(this._itemTemplate);
|
|
274
|
+
const child = this._addChild(this._itemTemplate);
|
|
275
|
+
child._initialize();
|
|
266
276
|
}
|
|
267
277
|
if (items2Remove > 0) {
|
|
268
278
|
this._children.splice(dataLength, items2Remove);
|
package/lib/Field.d.ts
CHANGED
|
@@ -71,14 +71,20 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
71
71
|
valid: boolean;
|
|
72
72
|
value: any;
|
|
73
73
|
};
|
|
74
|
-
format: (constraint: string, input: string) => {
|
|
74
|
+
format: (constraint: string, input: string | null) => {
|
|
75
|
+
value: string | null;
|
|
75
76
|
valid: boolean;
|
|
76
|
-
value: string;
|
|
77
77
|
};
|
|
78
78
|
minimum: (constraint: number, value: number) => {
|
|
79
79
|
valid: boolean;
|
|
80
80
|
value: number;
|
|
81
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param value
|
|
85
|
+
* @param constraints
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
82
88
|
maximum: (constraint: number, value: number) => {
|
|
83
89
|
valid: boolean;
|
|
84
90
|
value: number;
|
package/lib/FileUpload.d.ts
CHANGED
package/lib/Scriptable.js
CHANGED
|
@@ -116,10 +116,10 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
getExpressionScope() {
|
|
119
|
-
|
|
119
|
+
const parent = this.getNonTransparentParent();
|
|
120
120
|
const target = {
|
|
121
121
|
self: this.getRuleNode(),
|
|
122
|
-
siblings: (
|
|
122
|
+
siblings: (parent === null || parent === void 0 ? void 0 : parent.ruleNodeReference()) || {}
|
|
123
123
|
};
|
|
124
124
|
const scope = new Proxy(target, {
|
|
125
125
|
get: (target, prop) => {
|
package/lib/data/DataGroup.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ import DataValue from './DataValue';
|
|
|
7
7
|
*/
|
|
8
8
|
export default class DataGroup extends DataValue {
|
|
9
9
|
$_items: {
|
|
10
|
-
[key: string
|
|
11
|
-
};
|
|
10
|
+
[key: string]: DataValue | DataGroup;
|
|
11
|
+
} | DataValue[] | DataGroup[];
|
|
12
|
+
private createEntry;
|
|
12
13
|
constructor(_name: string | number, _value: {
|
|
13
|
-
[key: string
|
|
14
|
-
}, _type?: string);
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
} | any[], _type?: string);
|
|
15
16
|
get $value(): Array<any> | {
|
|
16
17
|
[key: string]: any;
|
|
17
18
|
};
|
|
@@ -19,7 +20,7 @@ export default class DataGroup extends DataValue {
|
|
|
19
20
|
$convertToDataValue(): DataValue;
|
|
20
21
|
$addDataNode(name: string | number, value: DataGroup | DataValue): void;
|
|
21
22
|
$removeDataNode(name: string | number): void;
|
|
22
|
-
$getDataNode(name: string | number):
|
|
23
|
+
$getDataNode(name: string | number): any;
|
|
23
24
|
$containsDataNode(name: string | number): boolean;
|
|
24
25
|
get $isDataGroup(): boolean;
|
|
25
26
|
}
|
package/lib/data/DataGroup.js
CHANGED
|
@@ -21,18 +21,25 @@ const EmptyDataValue_1 = __importDefault(require("./EmptyDataValue"));
|
|
|
21
21
|
class DataGroup extends DataValue_1.default {
|
|
22
22
|
constructor(_name, _value, _type = typeof _value) {
|
|
23
23
|
super(_name, _value, _type);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
if (_value instanceof Array) {
|
|
25
|
+
this.$_items = _value.map((value, index) => {
|
|
26
|
+
return this.createEntry(index, value);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.$_items = Object.fromEntries(Object.entries(_value).map(([key, value]) => {
|
|
31
|
+
return [key, this.createEntry(key, value)];
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
createEntry(key, value) {
|
|
36
|
+
const t = value instanceof Array ? 'array' : typeof value;
|
|
37
|
+
if (typeof value === 'object' && value != null) {
|
|
38
|
+
return new DataGroup(key, value, t);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return new DataValue_1.default(key, value, t);
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
44
|
get $value() {
|
|
38
45
|
if (this.$type === 'array') {
|
|
@@ -52,7 +59,13 @@ class DataGroup extends DataValue_1.default {
|
|
|
52
59
|
}
|
|
53
60
|
$addDataNode(name, value) {
|
|
54
61
|
if (value !== EmptyDataValue_1.default) {
|
|
55
|
-
this.$
|
|
62
|
+
if (this.$type === 'array') {
|
|
63
|
+
const index = name;
|
|
64
|
+
this.$_items.splice(index, 0, value);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.$_items[name] = value;
|
|
68
|
+
}
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
$removeDataNode(name) {
|
|
@@ -10,8 +10,8 @@ declare type HTTP_VERB = 'GET' | 'POST';
|
|
|
10
10
|
* @param payloadContentType content type of the request
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType
|
|
14
|
-
export declare const submit: (context: any, success: string, error: string, submitAs?: 'json' | 'multipart', input_data?: any) => Promise<void>;
|
|
13
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType: string) => Promise<void>;
|
|
14
|
+
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Implementation of function runtime
|
|
17
17
|
* @private
|
|
@@ -20,11 +20,12 @@ exports.submit = exports.request = void 0;
|
|
|
20
20
|
/**
|
|
21
21
|
* Implementation of function runtime in rule engine
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
//import {jsonString} from '../utils/JsonUtils';
|
|
24
24
|
const Controller_1 = require("../controller/Controller");
|
|
25
25
|
const Fetch_1 = require("../utils/Fetch");
|
|
26
26
|
const FileObject_1 = require("../FileObject");
|
|
27
27
|
const FormUtils_1 = require("../utils/FormUtils");
|
|
28
|
+
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
28
29
|
/**
|
|
29
30
|
* Implementation of generic request API. This API can be used to make external web request
|
|
30
31
|
* @param context expression execution context(consists of current form, current field, current event)
|
|
@@ -36,7 +37,7 @@ const FormUtils_1 = require("../utils/FormUtils");
|
|
|
36
37
|
* @param payloadContentType content type of the request
|
|
37
38
|
* @private
|
|
38
39
|
*/
|
|
39
|
-
const request = (context, uri, httpVerb, payload, success, error, payloadContentType
|
|
40
|
+
const request = (context, uri, httpVerb, payload, success, error, payloadContentType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
const endpoint = uri;
|
|
41
42
|
const requestOptions = {
|
|
42
43
|
method: httpVerb
|
|
@@ -50,6 +51,9 @@ const request = (context, uri, httpVerb, payload, success, error, payloadContent
|
|
|
50
51
|
formData.append(payload.name, payload.data);
|
|
51
52
|
inputPayload = formData;
|
|
52
53
|
}
|
|
54
|
+
else if (payload instanceof FormData) {
|
|
55
|
+
inputPayload = payload;
|
|
56
|
+
}
|
|
53
57
|
else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
|
|
54
58
|
if (payloadContentType.length > 0) {
|
|
55
59
|
requestOptions.headers = {
|
|
@@ -78,41 +82,46 @@ exports.request = request;
|
|
|
78
82
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
83
|
const multipartFormData = (data, attachments) => {
|
|
80
84
|
const formData = new FormData();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const newValue = {
|
|
85
|
-
':name': objValue.name,
|
|
86
|
-
':contentType': objValue.mediaType,
|
|
87
|
-
':data': objValue.data,
|
|
88
|
-
':bindRef': objValue.dataRef
|
|
89
|
-
};
|
|
90
|
-
if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
|
|
91
|
-
let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
|
|
92
|
-
if (!attIdentifier.startsWith('/')) {
|
|
93
|
-
attIdentifier = `/${attIdentifier}`;
|
|
94
|
-
}
|
|
95
|
-
formData.append(attIdentifier, objValue.data);
|
|
96
|
-
newValue[':data'] = `#${attIdentifier}`;
|
|
85
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
86
|
+
if (value != null && typeof value === 'object') {
|
|
87
|
+
formData.append(key, (0, JsonUtils_1.jsonString)(value));
|
|
97
88
|
}
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
else {
|
|
90
|
+
formData.append(key, value);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// const transformAttachment = (objValue: any, formData: any) : any => {
|
|
94
|
+
// const newValue = {
|
|
95
|
+
// ':name' : objValue.name,
|
|
96
|
+
// ':contentType' : objValue.mediaType,
|
|
97
|
+
// ':data' : objValue.data,
|
|
98
|
+
// ':bindRef' : objValue.dataRef
|
|
99
|
+
// };
|
|
100
|
+
// if (objValue?.data instanceof File) {
|
|
101
|
+
// let attIdentifier = `${objValue?.dataRef}/${objValue?.name}`;
|
|
102
|
+
// if (!attIdentifier.startsWith('/')) {
|
|
103
|
+
// attIdentifier = `/${attIdentifier}`;
|
|
104
|
+
// }
|
|
105
|
+
// formData.append(attIdentifier, objValue.data);
|
|
106
|
+
// newValue[':data'] = `#${attIdentifier}`;
|
|
107
|
+
// }
|
|
108
|
+
// return newValue;
|
|
109
|
+
// };
|
|
100
110
|
// @ts-ignore
|
|
101
|
-
const submitAttachments = Object.keys(attachments).reduce((acc, curr) => {
|
|
111
|
+
/*const submitAttachments = Object.keys(attachments).reduce((acc, curr) => {
|
|
102
112
|
const objValue = attachments[curr];
|
|
103
|
-
if
|
|
104
|
-
return [...acc, ...objValue.map((x)
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
113
|
+
if(objValue && objValue instanceof Array) {
|
|
114
|
+
return [...acc, ...objValue.map((x)=>transformAttachment(x, formData))];
|
|
115
|
+
} else {
|
|
107
116
|
return [...acc, transformAttachment(objValue, formData)];
|
|
108
117
|
}
|
|
109
118
|
}, []);
|
|
110
|
-
if (
|
|
111
|
-
formData.append(':attachments',
|
|
112
|
-
}
|
|
119
|
+
if (submitAttachments?.length > 0) {
|
|
120
|
+
formData.append(':attachments', jsonString(submitAttachments));
|
|
121
|
+
}*/
|
|
113
122
|
return formData;
|
|
114
123
|
};
|
|
115
|
-
const submit = (context, success, error, submitAs = '
|
|
124
|
+
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
125
|
const endpoint = context.form.action;
|
|
117
126
|
let data = input_data;
|
|
118
127
|
if (typeof data != 'object' || data == null) {
|
|
@@ -122,14 +131,15 @@ const submit = (context, success, error, submitAs = 'json', input_data = null) =
|
|
|
122
131
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
123
132
|
const attachments = (0, FormUtils_1.getAttachments)(context.$form);
|
|
124
133
|
let submitContentType = submitAs;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
let formData;
|
|
135
|
+
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
136
|
+
formData = multipartFormData({ 'data': data }, attachments);
|
|
137
|
+
submitContentType = 'multipart/form-data';
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
formData = { 'data': data };
|
|
141
|
+
}
|
|
142
|
+
// submitContentType = submitAs;
|
|
133
143
|
// note: don't send multipart/form-data let browser decide on the content type
|
|
134
144
|
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, submitContentType);
|
|
135
145
|
});
|
|
@@ -209,7 +219,7 @@ class FunctionRuntimeImpl {
|
|
|
209
219
|
// success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
|
|
210
220
|
const success = toString(args[0]);
|
|
211
221
|
const error = toString(args[1]);
|
|
212
|
-
const submit_as = args.length > 2 ? toString(args[2]) : '
|
|
222
|
+
const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
|
|
213
223
|
const submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
214
224
|
interpreter.globals.form.dispatch(new Controller_1.Submit({
|
|
215
225
|
success,
|
package/lib/types/Json.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.constraintProps = exports.translationProps = void 0;
|
|
11
11
|
/** Constant for all properties which can be translated based on `adaptive form specification` */
|
|
12
|
-
exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames'];
|
|
12
|
+
exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value'];
|
|
13
13
|
/** Constant for all properties which are constraints based on `adaptive form specification` */
|
|
14
14
|
exports.constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
|
|
15
15
|
'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -16,6 +16,13 @@ export declare const invalidateTranslation: (input: formElementJson, updates: an
|
|
|
16
16
|
* @private
|
|
17
17
|
*/
|
|
18
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, defaultValue?: any) => any;
|
|
19
26
|
/**
|
|
20
27
|
* @param input
|
|
21
28
|
* @param additionalTranslationProps
|
|
@@ -7,7 +7,7 @@
|
|
|
7
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
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.createTranslationObject = exports.createTranslationObj = exports.addTranslationId = exports.invalidateTranslation = exports.CUSTOM_PROPS_KEY = exports.TRANSLATION_ID = exports.TRANSLATION_TOKEN = void 0;
|
|
10
|
+
exports.createTranslationObject = exports.createTranslationObj = exports.getOrElse = exports.addTranslationId = exports.invalidateTranslation = exports.CUSTOM_PROPS_KEY = exports.TRANSLATION_ID = exports.TRANSLATION_TOKEN = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Defines generic utilities to translated form model definition
|
|
13
13
|
*/
|
|
@@ -63,11 +63,12 @@ const _createTranslationId = (input, path, transProps) => {
|
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
// set it only if either of type or fieldType properties is present
|
|
66
|
-
if ('type' in input ||
|
|
66
|
+
if (':type' in input ||
|
|
67
|
+
'type' in input ||
|
|
67
68
|
'fieldType' in input) {
|
|
68
69
|
for (const transProp of transProps) {
|
|
69
70
|
// if property exist add it
|
|
70
|
-
if (input
|
|
71
|
+
if ((0, exports.getOrElse)(input, transProp) != null) {
|
|
71
72
|
// if translation id is not yet set, set it
|
|
72
73
|
if (!(exports.CUSTOM_PROPS_KEY in input)) {
|
|
73
74
|
input[exports.CUSTOM_PROPS_KEY] = {};
|
|
@@ -100,10 +101,11 @@ const _createTranslationObj = (input, translationObj, translationProps) => {
|
|
|
100
101
|
}
|
|
101
102
|
else {
|
|
102
103
|
for (const translationProp of translationProps) {
|
|
103
|
-
|
|
104
|
+
const objValue = (0, exports.getOrElse)(input, translationProp);
|
|
105
|
+
if (objValue && ((_b = (_a = input === null || input === void 0 ? void 0 : input[exports.CUSTOM_PROPS_KEY]) === null || _a === void 0 ? void 0 : _a[exports.TRANSLATION_ID]) === null || _b === void 0 ? void 0 : _b[translationProp])) {
|
|
104
106
|
// todo: right now we create only for english
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
+
if (objValue instanceof Array) {
|
|
108
|
+
objValue.forEach((item, index) => {
|
|
107
109
|
if (typeof item === 'string') { // only if string, then convert, since values can also be boolean
|
|
108
110
|
// @ts-ignore
|
|
109
111
|
translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}${exports.TRANSLATION_TOKEN}${index}`] = item;
|
|
@@ -112,13 +114,32 @@ const _createTranslationObj = (input, translationObj, translationProps) => {
|
|
|
112
114
|
}
|
|
113
115
|
else {
|
|
114
116
|
// @ts-ignore
|
|
115
|
-
translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}`] =
|
|
117
|
+
translationObj[`${input[exports.CUSTOM_PROPS_KEY][exports.TRANSLATION_ID][translationProp]}`] = objValue;
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
});
|
|
121
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* Gets the value for the given key from the input, in case of no value, default is returned
|
|
126
|
+
* @param input input object
|
|
127
|
+
* @param key key to return from input object (key could be comma separated, example, label.value)
|
|
128
|
+
* @param defaultValue default value
|
|
129
|
+
*/
|
|
130
|
+
const getOrElse = (input, key, defaultValue = null) => {
|
|
131
|
+
if (!key) {
|
|
132
|
+
return defaultValue;
|
|
133
|
+
}
|
|
134
|
+
const arr = key.split('.');
|
|
135
|
+
let objValue = input, index = 0;
|
|
136
|
+
while (index < arr.length && objValue.hasOwnProperty(arr[index])) {
|
|
137
|
+
objValue = objValue[arr[index]];
|
|
138
|
+
index++;
|
|
139
|
+
}
|
|
140
|
+
return index == arr.length ? objValue : defaultValue;
|
|
141
|
+
};
|
|
142
|
+
exports.getOrElse = getOrElse;
|
|
122
143
|
/**
|
|
123
144
|
* @param input
|
|
124
145
|
* @param additionalTranslationProps
|
|
@@ -143,7 +164,7 @@ const createTranslationObject = (input, additionalTranslationProps = [], bcp47La
|
|
|
143
164
|
const transProps = [...types_1.translationProps, ...additionalTranslationProps];
|
|
144
165
|
// create a copy of the input
|
|
145
166
|
const inputCopy = JSON.parse(JSON.stringify(input));
|
|
146
|
-
const obj = (0, exports.createTranslationObj)((0, exports.addTranslationId)(inputCopy), transProps);
|
|
167
|
+
const obj = (0, exports.createTranslationObj)((0, exports.addTranslationId)(inputCopy, additionalTranslationProps), transProps);
|
|
147
168
|
const langTags = [...defaultBcp47LangTags, ...bcp47LangTags];
|
|
148
169
|
const allLangs = {};
|
|
149
170
|
for (const langTag of langTags) {
|
|
@@ -28,9 +28,9 @@ export declare const Constraints: {
|
|
|
28
28
|
* @param input value of the form object
|
|
29
29
|
* @return {@link ValidationResult | validation result}
|
|
30
30
|
*/
|
|
31
|
-
format: (constraint: string, input: string) => {
|
|
31
|
+
format: (constraint: string, input: string | null) => {
|
|
32
|
+
value: string | null;
|
|
32
33
|
valid: boolean;
|
|
33
|
-
value: string;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Implementation of minimum constraint
|
|
@@ -192,10 +192,13 @@ exports.Constraints = {
|
|
|
192
192
|
format: (constraint, input) => {
|
|
193
193
|
let valid = true;
|
|
194
194
|
const value = input;
|
|
195
|
+
if (input === null) {
|
|
196
|
+
return { value, valid };
|
|
197
|
+
}
|
|
195
198
|
let res;
|
|
196
199
|
switch (constraint) {
|
|
197
200
|
case 'date':
|
|
198
|
-
res = dateRegex.exec(input.trim());
|
|
201
|
+
res = dateRegex.exec((input || '').trim());
|
|
199
202
|
if (res != null) {
|
|
200
203
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
201
204
|
const [match, year, month, date] = res;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Adobe Proprietary",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"directories": {
|
|
9
9
|
"lib": "lib",
|
|
@@ -57,4 +57,4 @@
|
|
|
57
57
|
"typedoc-plugin-markdown": "3.11.13",
|
|
58
58
|
"typescript": "^4.3.5"
|
|
59
59
|
}
|
|
60
|
-
}
|
|
60
|
+
}
|