@aemforms/af-core 0.22.4 → 0.22.8
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 +12 -4
- package/lib/Container.d.ts +12 -0
- package/lib/Container.js +8 -3
- package/lib/DateField.d.ts +5 -0
- package/lib/DateField.js +35 -0
- package/lib/Field.d.ts +57 -3
- package/lib/Field.js +37 -2
- package/lib/Fieldset.js +7 -3
- package/lib/FileUpload.d.ts +0 -1
- package/lib/FileUpload.js +3 -73
- package/lib/Form.d.ts +12 -0
- package/lib/Form.js +2 -1
- package/lib/Scriptable.js +12 -1
- package/lib/controller/Controller.d.ts +6 -0
- package/lib/controller/Controller.js +10 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/rules/FunctionRuntime.d.ts +7 -0
- package/lib/rules/FunctionRuntime.js +14 -2
- package/lib/types/Json.d.ts +4 -0
- package/lib/types/Model.d.ts +16 -0
- package/lib/utils/FormUtils.d.ts +7 -0
- package/lib/utils/FormUtils.js +78 -1
- package/lib/utils/JsonUtils.d.ts +8 -1
- package/lib/utils/JsonUtils.js +19 -4
- package/package.json +6 -5
package/lib/BaseNode.js
CHANGED
|
@@ -109,16 +109,24 @@ class BaseNode {
|
|
|
109
109
|
//look for property
|
|
110
110
|
if (prop.startsWith('$')) {
|
|
111
111
|
prop = prop.substr(1);
|
|
112
|
-
if (prop === 'parent') {
|
|
113
|
-
return this[prop].getRuleNode();
|
|
114
|
-
}
|
|
115
112
|
//@ts-ignore
|
|
116
113
|
//@todo: create a list of properties that are allowed
|
|
117
114
|
//@ts-ignore
|
|
118
115
|
// return only non functional properties in this object
|
|
119
116
|
if (typeof this[prop] !== 'function') {
|
|
120
117
|
//@ts-ignore
|
|
121
|
-
|
|
118
|
+
const retValue = this[prop];
|
|
119
|
+
if (retValue instanceof BaseNode) {
|
|
120
|
+
//$parent
|
|
121
|
+
return retValue.getRuleNode();
|
|
122
|
+
}
|
|
123
|
+
else if (retValue instanceof Array) {
|
|
124
|
+
//$items
|
|
125
|
+
return retValue.map(r => r instanceof BaseNode ? r.getRuleNode() : r);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return retValue;
|
|
129
|
+
}
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
else {
|
package/lib/Container.d.ts
CHANGED
|
@@ -74,6 +74,10 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
74
74
|
valid?: boolean | undefined;
|
|
75
75
|
default?: any;
|
|
76
76
|
value?: any;
|
|
77
|
+
displayFormat?: string | undefined;
|
|
78
|
+
editFormat?: string | undefined;
|
|
79
|
+
editValue?: string | undefined;
|
|
80
|
+
displayValue?: string | undefined;
|
|
77
81
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
78
82
|
id: string;
|
|
79
83
|
} | {
|
|
@@ -156,6 +160,10 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
156
160
|
valid?: boolean | undefined;
|
|
157
161
|
default?: any;
|
|
158
162
|
value?: any;
|
|
163
|
+
displayFormat?: string | undefined;
|
|
164
|
+
editFormat?: string | undefined;
|
|
165
|
+
editValue?: string | undefined;
|
|
166
|
+
displayValue?: string | undefined;
|
|
159
167
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
160
168
|
} & {
|
|
161
169
|
id: string;
|
|
@@ -246,6 +254,10 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
246
254
|
valid?: boolean | undefined;
|
|
247
255
|
default?: any;
|
|
248
256
|
value?: any;
|
|
257
|
+
displayFormat?: string | undefined;
|
|
258
|
+
editFormat?: string | undefined;
|
|
259
|
+
editValue?: string | undefined;
|
|
260
|
+
displayValue?: string | undefined;
|
|
249
261
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
250
262
|
} & {
|
|
251
263
|
id: string;
|
package/lib/Container.js
CHANGED
|
@@ -94,7 +94,7 @@ class Container extends Scriptable_1.default {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
_addChild(itemJson, index) {
|
|
97
|
+
_addChild(itemJson, index, cloneIds = false) {
|
|
98
98
|
// get first non transparent parent
|
|
99
99
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
100
100
|
let nonTransparentParent = this;
|
|
@@ -105,7 +105,8 @@ class Container extends Scriptable_1.default {
|
|
|
105
105
|
if (typeof index !== 'number' || index > nonTransparentParent._children.length) {
|
|
106
106
|
index = this._children.length;
|
|
107
107
|
}
|
|
108
|
-
const
|
|
108
|
+
const form = this.form;
|
|
109
|
+
const itemTemplate = Object.assign({ index }, (0, JsonUtils_1.deepClone)(itemJson, cloneIds ? () => { return form.getUniqueId(); } : undefined));
|
|
109
110
|
//@ts-ignore
|
|
110
111
|
const retVal = this._createChild(itemTemplate, { parent: this, index });
|
|
111
112
|
this._addChildToRuleNode(retVal, { parent: nonTransparentParent });
|
|
@@ -182,7 +183,7 @@ class Container extends Scriptable_1.default {
|
|
|
182
183
|
if (typeof index !== 'number' || index > this._children.length) {
|
|
183
184
|
index = this._children.length;
|
|
184
185
|
}
|
|
185
|
-
const retVal = this._addChild(this._itemTemplate, action.payload);
|
|
186
|
+
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
186
187
|
const _data = retVal.defaultDataModel(index);
|
|
187
188
|
if (_data) {
|
|
188
189
|
dataNode.$addDataNode(index, _data);
|
|
@@ -199,6 +200,10 @@ class Container extends Scriptable_1.default {
|
|
|
199
200
|
*/
|
|
200
201
|
removeItem(action) {
|
|
201
202
|
if (action.type === 'removeItem' && this._itemTemplate != null) {
|
|
203
|
+
if (this._children.length == 0) {
|
|
204
|
+
//can't remove item if there isn't any
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
202
207
|
const index = typeof action.payload === 'number' ? action.payload : this._children.length - 1;
|
|
203
208
|
const state = this._children[index].getState();
|
|
204
209
|
//@ts-ignore
|
package/lib/DateField.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
*
|
|
4
|
+
* * Copyright 2022 Adobe, Inc.
|
|
5
|
+
* *
|
|
6
|
+
* * 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.
|
|
7
|
+
* *
|
|
8
|
+
* * 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.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const Field_1 = __importDefault(require("./Field"));
|
|
16
|
+
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
17
|
+
class DateField extends Field_1.default {
|
|
18
|
+
_applyDefaults() {
|
|
19
|
+
super._applyDefaults();
|
|
20
|
+
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
21
|
+
if (!this._jsonModel.editFormat) {
|
|
22
|
+
this._jsonModel.editFormat = 'short';
|
|
23
|
+
}
|
|
24
|
+
if (!this._jsonModel.displayFormat) {
|
|
25
|
+
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
26
|
+
}
|
|
27
|
+
if (!this._jsonModel.placeholder) {
|
|
28
|
+
this._jsonModel.placeholder = (0, af_formatters_1.getSkeleton)(this._jsonModel.editFormat, locale);
|
|
29
|
+
}
|
|
30
|
+
if (!this._jsonModel.description) {
|
|
31
|
+
this._jsonModel.description = `To enter today's date use ${(0, af_formatters_1.formatDate)(new Date(), locale, this._jsonModel.editFormat)}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = DateField;
|
package/lib/Field.d.ts
CHANGED
|
@@ -32,8 +32,12 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
32
32
|
*/
|
|
33
33
|
protected _getFallbackType(): string | undefined;
|
|
34
34
|
protected _applyDefaults(): void;
|
|
35
|
+
get editFormat(): string | undefined;
|
|
36
|
+
get displayFormat(): string | undefined;
|
|
37
|
+
get placeholder(): string | undefined;
|
|
35
38
|
get readOnly(): boolean | undefined;
|
|
36
39
|
set readOnly(e: boolean | undefined);
|
|
40
|
+
get language(): string;
|
|
37
41
|
get enabled(): boolean | undefined;
|
|
38
42
|
set enabled(e: boolean | undefined);
|
|
39
43
|
get valid(): boolean | undefined;
|
|
@@ -53,6 +57,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
53
57
|
* @private
|
|
54
58
|
*/
|
|
55
59
|
private isEmpty;
|
|
60
|
+
get editValue(): any;
|
|
61
|
+
get displayValue(): any;
|
|
56
62
|
get value(): any;
|
|
57
63
|
set value(v: any);
|
|
58
64
|
valueOf(): any;
|
|
@@ -104,9 +110,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
104
110
|
value: T_2[];
|
|
105
111
|
};
|
|
106
112
|
minLength: (constraint: number, value: string) => {
|
|
107
|
-
value: string;
|
|
108
|
-
* returns the format constraint
|
|
109
|
-
*/
|
|
113
|
+
value: string;
|
|
110
114
|
valid: boolean;
|
|
111
115
|
};
|
|
112
116
|
maxLength: (constraint: number, value: string) => {
|
|
@@ -183,5 +187,55 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
183
187
|
* @private
|
|
184
188
|
*/
|
|
185
189
|
defaultDataModel(name: string | number): DataValue;
|
|
190
|
+
getState(): {
|
|
191
|
+
editValue: any;
|
|
192
|
+
displayValue: any;
|
|
193
|
+
description?: string | undefined;
|
|
194
|
+
rules?: import("./types").Items<string> | undefined;
|
|
195
|
+
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
196
|
+
enumNames?: string[] | undefined;
|
|
197
|
+
enum?: any[] | undefined;
|
|
198
|
+
accept?: string[] | undefined;
|
|
199
|
+
enforceEnum?: boolean | undefined;
|
|
200
|
+
exclusiveMinimum?: number | undefined;
|
|
201
|
+
exclusiveMaximum?: number | undefined;
|
|
202
|
+
format?: string | undefined;
|
|
203
|
+
maxFileSize?: string | number | undefined;
|
|
204
|
+
maxLength?: number | undefined;
|
|
205
|
+
maximum?: number | undefined;
|
|
206
|
+
maxItems?: number | undefined;
|
|
207
|
+
minLength?: number | undefined;
|
|
208
|
+
minimum?: number | undefined;
|
|
209
|
+
minItems?: number | undefined;
|
|
210
|
+
pattern?: string | undefined;
|
|
211
|
+
required?: boolean | undefined; /**
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
step?: number | undefined;
|
|
215
|
+
type?: string | undefined;
|
|
216
|
+
validationExpression?: string | undefined;
|
|
217
|
+
uniqueItems?: boolean | undefined;
|
|
218
|
+
dataRef?: string | null | undefined;
|
|
219
|
+
':type': string;
|
|
220
|
+
label?: import("./types").Label | undefined;
|
|
221
|
+
enabled?: boolean | undefined;
|
|
222
|
+
visible?: boolean | undefined;
|
|
223
|
+
name?: string | undefined;
|
|
224
|
+
constraintMessages?: ConstraintsMessages | undefined;
|
|
225
|
+
fieldType?: string | undefined;
|
|
226
|
+
errorMessage?: string | undefined;
|
|
227
|
+
properties?: {
|
|
228
|
+
[key: string]: any;
|
|
229
|
+
} | undefined;
|
|
230
|
+
placeholder?: string | undefined;
|
|
231
|
+
readOnly?: boolean | undefined;
|
|
232
|
+
valid?: boolean | undefined;
|
|
233
|
+
default?: any;
|
|
234
|
+
value?: any;
|
|
235
|
+
displayFormat?: string | undefined;
|
|
236
|
+
editFormat?: string | undefined;
|
|
237
|
+
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
238
|
+
id: string;
|
|
239
|
+
};
|
|
186
240
|
}
|
|
187
241
|
export default Field;
|
package/lib/Field.js
CHANGED
|
@@ -18,6 +18,7 @@ const SchemaUtils_1 = require("./utils/SchemaUtils");
|
|
|
18
18
|
const DataValue_1 = __importDefault(require("./data/DataValue"));
|
|
19
19
|
const BaseNode_1 = require("./BaseNode");
|
|
20
20
|
const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
|
|
21
|
+
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
21
22
|
/**
|
|
22
23
|
* Defines a form object field which implements {@link FieldModel | field model} interface
|
|
23
24
|
*/
|
|
@@ -99,12 +100,25 @@ class Field extends Scriptable_1.default {
|
|
|
99
100
|
this._jsonModel.step = undefined;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
103
|
+
get editFormat() {
|
|
104
|
+
return this._jsonModel.editFormat;
|
|
105
|
+
}
|
|
106
|
+
get displayFormat() {
|
|
107
|
+
return this._jsonModel.displayFormat;
|
|
108
|
+
}
|
|
109
|
+
get placeholder() {
|
|
110
|
+
return this._jsonModel.placeholder;
|
|
111
|
+
}
|
|
102
112
|
get readOnly() {
|
|
103
113
|
return this._jsonModel.readOnly;
|
|
104
114
|
}
|
|
105
115
|
set readOnly(e) {
|
|
106
116
|
this._setProperty('readOnly', e);
|
|
107
117
|
}
|
|
118
|
+
get language() {
|
|
119
|
+
//todo: add this in the specification and take it as a property
|
|
120
|
+
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
121
|
+
}
|
|
108
122
|
get enabled() {
|
|
109
123
|
return this._jsonModel.enabled;
|
|
110
124
|
}
|
|
@@ -162,6 +176,24 @@ class Field extends Scriptable_1.default {
|
|
|
162
176
|
isEmpty() {
|
|
163
177
|
return this._jsonModel.value === undefined || this._jsonModel.value === null || this._jsonModel.value === '';
|
|
164
178
|
}
|
|
179
|
+
get editValue() {
|
|
180
|
+
const format = this.editFormat;
|
|
181
|
+
if (this.format == 'date' && this.value != null && this.valid !== false) {
|
|
182
|
+
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return this.value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
get displayValue() {
|
|
189
|
+
const format = this.displayFormat;
|
|
190
|
+
if (this.format == 'date' && this.value != null && this.valid !== false) {
|
|
191
|
+
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return this.value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
165
197
|
get value() {
|
|
166
198
|
//@ts-ignore
|
|
167
199
|
this.ruleEngine.trackDependency(this);
|
|
@@ -329,7 +361,7 @@ class Field extends Scriptable_1.default {
|
|
|
329
361
|
(this.isArrayType() && this.required ? value.length > 0 : true);
|
|
330
362
|
constraint = 'required';
|
|
331
363
|
}
|
|
332
|
-
if (valid) {
|
|
364
|
+
if (valid && value != this.emptyValue) {
|
|
333
365
|
const invalidConstraint = supportedConstraints.find(key => {
|
|
334
366
|
if (key in elem) {
|
|
335
367
|
// @ts-ignore
|
|
@@ -419,7 +451,7 @@ class Field extends Scriptable_1.default {
|
|
|
419
451
|
this.triggerValidationEvent(changes);
|
|
420
452
|
this.notifyDependents(new controller_1.Change({ changes: Object.values(changes) }));
|
|
421
453
|
}
|
|
422
|
-
return this.valid ? [
|
|
454
|
+
return this.valid ? [] : [new types_1.ValidationError(this.id, [this._jsonModel.errorMessage])];
|
|
423
455
|
}
|
|
424
456
|
importData(contextualDataModel) {
|
|
425
457
|
this._bindToDataModel(contextualDataModel);
|
|
@@ -438,5 +470,8 @@ class Field extends Scriptable_1.default {
|
|
|
438
470
|
defaultDataModel(name) {
|
|
439
471
|
return new DataValue_1.default(name, this.isEmpty() ? this.emptyValue : this._jsonModel.value, this.type || 'string');
|
|
440
472
|
}
|
|
473
|
+
getState() {
|
|
474
|
+
return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
|
|
475
|
+
}
|
|
441
476
|
}
|
|
442
477
|
exports.default = Field;
|
package/lib/Fieldset.js
CHANGED
|
@@ -15,9 +15,10 @@ const Container_1 = __importDefault(require("./Container"));
|
|
|
15
15
|
const Field_1 = __importDefault(require("./Field"));
|
|
16
16
|
const FileUpload_1 = __importDefault(require("./FileUpload"));
|
|
17
17
|
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
18
|
-
const
|
|
18
|
+
const controller_1 = require("./controller");
|
|
19
19
|
const Checkbox_1 = __importDefault(require("./Checkbox"));
|
|
20
20
|
const CheckboxGroup_1 = __importDefault(require("./CheckboxGroup"));
|
|
21
|
+
const DateField_1 = __importDefault(require("./DateField"));
|
|
21
22
|
/**
|
|
22
23
|
* Creates a child model inside the given parent
|
|
23
24
|
* @param child
|
|
@@ -40,6 +41,9 @@ const createChild = (child, options) => {
|
|
|
40
41
|
else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
|
|
41
42
|
retVal = new CheckboxGroup_1.default(child, options);
|
|
42
43
|
}
|
|
44
|
+
else if ((0, JsonUtils_1.isDateField)(child)) {
|
|
45
|
+
retVal = new DateField_1.default(child, options);
|
|
46
|
+
}
|
|
43
47
|
else {
|
|
44
48
|
retVal = new Field_1.default(child, options);
|
|
45
49
|
}
|
|
@@ -63,8 +67,8 @@ class Fieldset extends Container_1.default {
|
|
|
63
67
|
constructor(params, _options) {
|
|
64
68
|
super(params, _options);
|
|
65
69
|
this._applyDefaults();
|
|
66
|
-
this.queueEvent(new
|
|
67
|
-
this.queueEvent(new
|
|
70
|
+
this.queueEvent(new controller_1.Initialize());
|
|
71
|
+
this.queueEvent(new controller_1.ExecuteRule());
|
|
68
72
|
}
|
|
69
73
|
_applyDefaults() {
|
|
70
74
|
Object.entries(defaults).map(([key, value]) => {
|
package/lib/FileUpload.d.ts
CHANGED
package/lib/FileUpload.js
CHANGED
|
@@ -58,75 +58,6 @@ class FileUpload extends Field_1.default {
|
|
|
58
58
|
_getDefaults() {
|
|
59
59
|
return Object.assign(Object.assign({}, super._getDefaults()), { accept: ['audio/*', 'video/*', 'image/*', 'text/*', 'application/pdf'], maxFileSize: '2MB', type: 'file' });
|
|
60
60
|
}
|
|
61
|
-
static extractFileInfo(files) {
|
|
62
|
-
return (files instanceof Array ? files : [files])
|
|
63
|
-
.map((file) => {
|
|
64
|
-
let retVal = null;
|
|
65
|
-
if (file instanceof FileObject_1.FileObject) {
|
|
66
|
-
retVal = file;
|
|
67
|
-
}
|
|
68
|
-
else if (typeof File !== 'undefined' && file instanceof File) {
|
|
69
|
-
// case: file object
|
|
70
|
-
retVal = {
|
|
71
|
-
name: file.name,
|
|
72
|
-
mediaType: file.type,
|
|
73
|
-
size: file.size,
|
|
74
|
-
data: file
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
else if (typeof file === 'string' && (0, ValidationUtils_1.isDataUrl)(file)) {
|
|
78
|
-
// case: data URL
|
|
79
|
-
const { blob, name } = (0, FormUtils_1.dataURItoBlob)(file);
|
|
80
|
-
retVal = {
|
|
81
|
-
name: name,
|
|
82
|
-
mediaType: blob.type,
|
|
83
|
-
size: blob.size,
|
|
84
|
-
data: blob
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// case: string as file object
|
|
89
|
-
let jFile = file;
|
|
90
|
-
try {
|
|
91
|
-
jFile = JSON.parse(file);
|
|
92
|
-
retVal = jFile;
|
|
93
|
-
}
|
|
94
|
-
catch (ex) {
|
|
95
|
-
// do nothing
|
|
96
|
-
}
|
|
97
|
-
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)) {
|
|
98
|
-
// case: data URL
|
|
99
|
-
const { blob } = (0, FormUtils_1.dataURItoBlob)(jFile === null || jFile === void 0 ? void 0 : jFile.data);
|
|
100
|
-
retVal = {
|
|
101
|
-
name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
|
|
102
|
-
mediaType: jFile === null || jFile === void 0 ? void 0 : jFile.type,
|
|
103
|
-
size: blob.size,
|
|
104
|
-
data: blob
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else if (typeof jFile === 'string') {
|
|
108
|
-
// case: data as external url
|
|
109
|
-
const fileName = jFile.split('/').pop();
|
|
110
|
-
retVal = {
|
|
111
|
-
name: fileName,
|
|
112
|
-
mediaType: 'application/octet-stream',
|
|
113
|
-
size: 0,
|
|
114
|
-
data: jFile
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
else if (jFile instanceof Object) {
|
|
118
|
-
// todo: just added for ease of integration for the view layer
|
|
119
|
-
retVal = {
|
|
120
|
-
name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
|
|
121
|
-
mediaType: jFile === null || jFile === void 0 ? void 0 : jFile.type,
|
|
122
|
-
size: jFile === null || jFile === void 0 ? void 0 : jFile.size,
|
|
123
|
-
data: jFile === null || jFile === void 0 ? void 0 : jFile.data
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return new FileObject_1.FileObject(retVal);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
61
|
/**
|
|
131
62
|
* Returns the max file size in bytes as per IEC specification
|
|
132
63
|
*/
|
|
@@ -246,10 +177,9 @@ class FileUpload extends Field_1.default {
|
|
|
246
177
|
// store file list here
|
|
247
178
|
const typeRes = this.typeCheck(value);
|
|
248
179
|
const acceptRes = this.acceptCheck(value);
|
|
249
|
-
|
|
250
|
-
let fileInfoPayload = FileUpload.extractFileInfo(value);
|
|
180
|
+
let fileInfoPayload = (0, FormUtils_1.extractFileInfo)(value);
|
|
251
181
|
fileInfoPayload = this.coerce(fileInfoPayload);
|
|
252
|
-
this._setProperty('value', fileInfoPayload, false);
|
|
182
|
+
const changes = this._setProperty('value', fileInfoPayload, false);
|
|
253
183
|
if (changes.length > 0) {
|
|
254
184
|
const dataNode = this.getDataNode();
|
|
255
185
|
if (typeof dataNode !== 'undefined') {
|
|
@@ -314,7 +244,7 @@ class FileUpload extends Field_1.default {
|
|
|
314
244
|
let newValue = value;
|
|
315
245
|
// only if not undefined, proceed further
|
|
316
246
|
if (value != null) {
|
|
317
|
-
const fileObj =
|
|
247
|
+
const fileObj = (0, FormUtils_1.extractFileInfo)(value);
|
|
318
248
|
newValue = this.coerce(fileObj);
|
|
319
249
|
// is this needed ?
|
|
320
250
|
this.form.getEventQueue().queue(this, (0, Controller_1.propertyChange)('value', newValue, this._jsonModel.value));
|
package/lib/Form.d.ts
CHANGED
|
@@ -158,6 +158,10 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
158
158
|
valid?: boolean | undefined;
|
|
159
159
|
default?: any;
|
|
160
160
|
value?: any;
|
|
161
|
+
displayFormat?: string | undefined;
|
|
162
|
+
editFormat?: string | undefined;
|
|
163
|
+
editValue?: string | undefined;
|
|
164
|
+
displayValue?: string | undefined;
|
|
161
165
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
162
166
|
id: string;
|
|
163
167
|
} | {
|
|
@@ -246,6 +250,10 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
246
250
|
valid?: boolean | undefined;
|
|
247
251
|
default?: any;
|
|
248
252
|
value?: any;
|
|
253
|
+
displayFormat?: string | undefined;
|
|
254
|
+
editFormat?: string | undefined;
|
|
255
|
+
editValue?: string | undefined;
|
|
256
|
+
displayValue?: string | undefined;
|
|
249
257
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
250
258
|
} & {
|
|
251
259
|
id: string;
|
|
@@ -342,6 +350,10 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
342
350
|
valid?: boolean | undefined;
|
|
343
351
|
default?: any;
|
|
344
352
|
value?: any;
|
|
353
|
+
displayFormat?: string | undefined;
|
|
354
|
+
editFormat?: string | undefined;
|
|
355
|
+
editValue?: string | undefined;
|
|
356
|
+
displayValue?: string | undefined;
|
|
345
357
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
346
358
|
} & {
|
|
347
359
|
id: string;
|
package/lib/Form.js
CHANGED
|
@@ -217,7 +217,8 @@ class Form extends Container_1.default {
|
|
|
217
217
|
submit(action, context) {
|
|
218
218
|
// if no errors, only then submit
|
|
219
219
|
if (this.validate().length === 0) {
|
|
220
|
-
|
|
220
|
+
const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
|
|
221
|
+
(0, FunctionRuntime_1.submit)(context, payload === null || payload === void 0 ? void 0 : payload.success, payload === null || payload === void 0 ? void 0 : payload.error, payload === null || payload === void 0 ? void 0 : payload.submit_as, payload === null || payload === void 0 ? void 0 : payload.data);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
getElement(id) {
|
package/lib/Scriptable.js
CHANGED
|
@@ -133,7 +133,18 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
133
133
|
// 3. child
|
|
134
134
|
if (prop.startsWith('$')) {
|
|
135
135
|
//this returns children as well, so adding an explicit check for property name
|
|
136
|
-
|
|
136
|
+
const retValue = target.self[prop];
|
|
137
|
+
if (retValue instanceof BaseNode_1.BaseNode) {
|
|
138
|
+
//$parent
|
|
139
|
+
return retValue.getRuleNode();
|
|
140
|
+
}
|
|
141
|
+
else if (retValue instanceof Array) {
|
|
142
|
+
//$items
|
|
143
|
+
return retValue.map(r => r instanceof BaseNode_1.BaseNode ? r.getRuleNode() : r);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return retValue;
|
|
147
|
+
}
|
|
137
148
|
}
|
|
138
149
|
else {
|
|
139
150
|
if (prop in target.siblings) {
|
|
@@ -160,6 +160,12 @@ export declare class ValidationComplete extends ActionImpl {
|
|
|
160
160
|
*/
|
|
161
161
|
constructor(payload?: Array<ValidationError>, dispatch?: boolean);
|
|
162
162
|
}
|
|
163
|
+
export declare class Focus extends ActionImpl {
|
|
164
|
+
/**
|
|
165
|
+
* @constructor
|
|
166
|
+
*/
|
|
167
|
+
constructor();
|
|
168
|
+
}
|
|
163
169
|
/**
|
|
164
170
|
* Implementation of `submit` event. The submit event is triggered on the Form.
|
|
165
171
|
* To trigger the submit event, submit function needs to be invoked or one can invoke dispatchEvent API.
|
|
@@ -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.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Submit = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = exports.ActionImpl = void 0;
|
|
10
|
+
exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = exports.ActionImpl = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Implementation of generic event
|
|
13
13
|
* @private
|
|
@@ -199,6 +199,15 @@ class ValidationComplete extends ActionImpl {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
exports.ValidationComplete = ValidationComplete;
|
|
202
|
+
class Focus extends ActionImpl {
|
|
203
|
+
/**
|
|
204
|
+
* @constructor
|
|
205
|
+
*/
|
|
206
|
+
constructor() {
|
|
207
|
+
super({}, 'focus', { dispatch: false });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.Focus = Focus;
|
|
202
211
|
/**
|
|
203
212
|
* Implementation of `submit` event. The submit event is triggered on the Form.
|
|
204
213
|
* To trigger the submit event, submit function needs to be invoked or one can invoke dispatchEvent API.
|
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export * from './controller/index';
|
|
|
11
11
|
export * from './utils/TranslationUtils';
|
|
12
12
|
export * from './utils/JsonUtils';
|
|
13
13
|
export * from './utils/SchemaUtils';
|
|
14
|
-
import { getFileSizeInBytes } from './utils/FormUtils';
|
|
14
|
+
import { getFileSizeInBytes, extractFileInfo } from './utils/FormUtils';
|
|
15
15
|
import { BaseNode } from './BaseNode';
|
|
16
16
|
import Checkbox from './Checkbox';
|
|
17
17
|
import CheckboxGroup from './CheckboxGroup';
|
|
@@ -24,4 +24,4 @@ import FormMetaData from './FormMetaData';
|
|
|
24
24
|
import Node from './Node';
|
|
25
25
|
import Scriptable from './Scriptable';
|
|
26
26
|
import Form from './Form';
|
|
27
|
-
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes };
|
|
27
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo };
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
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;
|
|
27
|
+
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;
|
|
28
28
|
__exportStar(require("./FormInstance"), exports);
|
|
29
29
|
__exportStar(require("./types/index"), exports);
|
|
30
30
|
__exportStar(require("./controller/index"), exports);
|
|
@@ -33,6 +33,7 @@ __exportStar(require("./utils/JsonUtils"), exports);
|
|
|
33
33
|
__exportStar(require("./utils/SchemaUtils"), exports);
|
|
34
34
|
const FormUtils_1 = require("./utils/FormUtils");
|
|
35
35
|
Object.defineProperty(exports, "getFileSizeInBytes", { enumerable: true, get: function () { return FormUtils_1.getFileSizeInBytes; } });
|
|
36
|
+
Object.defineProperty(exports, "extractFileInfo", { enumerable: true, get: function () { return FormUtils_1.extractFileInfo; } });
|
|
36
37
|
const BaseNode_1 = require("./BaseNode");
|
|
37
38
|
Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return BaseNode_1.BaseNode; } });
|
|
38
39
|
const Checkbox_1 = __importDefault(require("./Checkbox"));
|
|
@@ -42,6 +42,13 @@ declare class FunctionRuntimeImpl {
|
|
|
42
42
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
43
43
|
_signature: never[];
|
|
44
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @name dispatchEvent
|
|
48
|
+
* @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
|
|
49
|
+
* @param eventName name of the event to trigger
|
|
50
|
+
* @param payload payload to pass in the event
|
|
51
|
+
*/
|
|
45
52
|
dispatchEvent: {
|
|
46
53
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
47
54
|
_signature: never[];
|
|
@@ -199,12 +199,17 @@ class FunctionRuntimeImpl {
|
|
|
199
199
|
validate: {
|
|
200
200
|
_func: (args, data, interpreter) => {
|
|
201
201
|
const element = args[0];
|
|
202
|
+
let validation;
|
|
202
203
|
if (typeof element === 'string' || typeof element === 'undefined') {
|
|
203
|
-
|
|
204
|
+
validation = interpreter.globals.form.validate();
|
|
204
205
|
}
|
|
205
206
|
else {
|
|
206
|
-
|
|
207
|
+
validation = interpreter.globals.form.getElement(element.$id).validate();
|
|
207
208
|
}
|
|
209
|
+
if (Array.isArray(validation) && validation.length) {
|
|
210
|
+
interpreter.globals.form.logger.error('Form Validation Error');
|
|
211
|
+
}
|
|
212
|
+
return validation;
|
|
208
213
|
},
|
|
209
214
|
_signature: []
|
|
210
215
|
},
|
|
@@ -262,6 +267,13 @@ class FunctionRuntimeImpl {
|
|
|
262
267
|
},
|
|
263
268
|
_signature: []
|
|
264
269
|
},
|
|
270
|
+
/**
|
|
271
|
+
*
|
|
272
|
+
* @name dispatchEvent
|
|
273
|
+
* @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
|
|
274
|
+
* @param eventName name of the event to trigger
|
|
275
|
+
* @param payload payload to pass in the event
|
|
276
|
+
*/
|
|
265
277
|
dispatchEvent: {
|
|
266
278
|
_func: (args, data, interpreter) => {
|
|
267
279
|
const element = args[0];
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -93,6 +93,10 @@ export declare type FieldJson = BaseJson & TranslationFieldJson & {
|
|
|
93
93
|
valid?: boolean;
|
|
94
94
|
default?: any;
|
|
95
95
|
value?: any;
|
|
96
|
+
displayFormat?: string;
|
|
97
|
+
editFormat?: string;
|
|
98
|
+
editValue?: string;
|
|
99
|
+
displayValue?: string;
|
|
96
100
|
emptyValue?: 'null' | 'undefined' | '';
|
|
97
101
|
};
|
|
98
102
|
/** Type for `form container properties` based on `adaptive form specification` */
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -222,6 +222,22 @@ export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJ
|
|
|
222
222
|
* Parent of the current field
|
|
223
223
|
*/
|
|
224
224
|
parent: ContainerModel;
|
|
225
|
+
/**
|
|
226
|
+
* format in which user will edit the value
|
|
227
|
+
*/
|
|
228
|
+
readonly editFormat?: string;
|
|
229
|
+
/**
|
|
230
|
+
* format in which user will see the value after update
|
|
231
|
+
*/
|
|
232
|
+
readonly displayFormat?: string;
|
|
233
|
+
/**
|
|
234
|
+
* value to be displayed to the user after update
|
|
235
|
+
*/
|
|
236
|
+
readonly displayValue?: string;
|
|
237
|
+
/**
|
|
238
|
+
* value to be displayed to the user for edit
|
|
239
|
+
*/
|
|
240
|
+
readonly editValue?: string;
|
|
225
241
|
}
|
|
226
242
|
/**
|
|
227
243
|
* Defines form meta data properties
|
package/lib/utils/FormUtils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ContainerModel } from '../types';
|
|
2
|
+
import { FileObject } from '../FileObject';
|
|
2
3
|
/**
|
|
3
4
|
* Utility to generate a random word from seed
|
|
4
5
|
* @param l seed value
|
|
@@ -36,6 +37,12 @@ export declare const sizeToBytes: (size: number, symbol: string) => number;
|
|
|
36
37
|
* @private
|
|
37
38
|
*/
|
|
38
39
|
export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Utility to extract {@link FileObject} from string or HTML File data type
|
|
42
|
+
* @param files list of files as string , string [] of file[]
|
|
43
|
+
* @returns list of {@link FileObject}
|
|
44
|
+
*/
|
|
45
|
+
export declare const extractFileInfo: (files: string[] | string | File[]) => FileObject[];
|
|
39
46
|
/**
|
|
40
47
|
* Utility to convert data URI to a `blob` object
|
|
41
48
|
* @param dataURI uri to convert to blob
|
package/lib/utils/FormUtils.js
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
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.dataURItoBlob = exports.IdGenerator = exports.sizeToBytes = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
|
|
10
|
+
exports.dataURItoBlob = exports.extractFileInfo = exports.IdGenerator = exports.sizeToBytes = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Defines generic utilities to interact with form runtime model
|
|
13
13
|
*/
|
|
14
14
|
const JsonUtils_1 = require("./JsonUtils");
|
|
15
|
+
const FileObject_1 = require("../FileObject");
|
|
16
|
+
const ValidationUtils_1 = require("./ValidationUtils");
|
|
15
17
|
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
|
|
16
18
|
const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
|
|
17
19
|
/**
|
|
@@ -133,6 +135,81 @@ const IdGenerator = function* (initial = 50) {
|
|
|
133
135
|
} while (ids.length > 0);
|
|
134
136
|
};
|
|
135
137
|
exports.IdGenerator = IdGenerator;
|
|
138
|
+
/**
|
|
139
|
+
* Utility to extract {@link FileObject} from string or HTML File data type
|
|
140
|
+
* @param files list of files as string , string [] of file[]
|
|
141
|
+
* @returns list of {@link FileObject}
|
|
142
|
+
*/
|
|
143
|
+
const extractFileInfo = (files) => {
|
|
144
|
+
return (files instanceof Array ? files : [files])
|
|
145
|
+
.map((file) => {
|
|
146
|
+
let retVal = null;
|
|
147
|
+
if (file instanceof FileObject_1.FileObject) {
|
|
148
|
+
retVal = file;
|
|
149
|
+
}
|
|
150
|
+
else if (typeof File !== 'undefined' && file instanceof File) {
|
|
151
|
+
// case: file object
|
|
152
|
+
retVal = {
|
|
153
|
+
name: file.name,
|
|
154
|
+
mediaType: file.type,
|
|
155
|
+
size: file.size,
|
|
156
|
+
data: file
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
else if (typeof file === 'string' && (0, ValidationUtils_1.isDataUrl)(file)) {
|
|
160
|
+
// case: data URL
|
|
161
|
+
const { blob, name } = (0, exports.dataURItoBlob)(file);
|
|
162
|
+
retVal = {
|
|
163
|
+
name: name,
|
|
164
|
+
mediaType: blob.type,
|
|
165
|
+
size: blob.size,
|
|
166
|
+
data: blob
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// case: string as file object
|
|
171
|
+
let jFile = file;
|
|
172
|
+
try {
|
|
173
|
+
jFile = JSON.parse(file);
|
|
174
|
+
retVal = jFile;
|
|
175
|
+
}
|
|
176
|
+
catch (ex) {
|
|
177
|
+
// do nothing
|
|
178
|
+
}
|
|
179
|
+
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)) {
|
|
180
|
+
// case: data URL
|
|
181
|
+
const { blob } = (0, exports.dataURItoBlob)(jFile === null || jFile === void 0 ? void 0 : jFile.data);
|
|
182
|
+
retVal = {
|
|
183
|
+
name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
|
|
184
|
+
mediaType: jFile === null || jFile === void 0 ? void 0 : jFile.type,
|
|
185
|
+
size: blob.size,
|
|
186
|
+
data: blob
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
else if (typeof jFile === 'string') {
|
|
190
|
+
// case: data as external url
|
|
191
|
+
const fileName = jFile.split('/').pop();
|
|
192
|
+
retVal = {
|
|
193
|
+
name: fileName,
|
|
194
|
+
mediaType: 'application/octet-stream',
|
|
195
|
+
size: 0,
|
|
196
|
+
data: jFile
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
else if (typeof jFile === 'object') {
|
|
200
|
+
// todo: just added for ease of integration for the view layer
|
|
201
|
+
retVal = {
|
|
202
|
+
name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
|
|
203
|
+
mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
|
|
204
|
+
size: jFile === null || jFile === void 0 ? void 0 : jFile.size,
|
|
205
|
+
data: jFile === null || jFile === void 0 ? void 0 : jFile.data
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return new FileObject_1.FileObject(retVal);
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
exports.extractFileInfo = extractFileInfo;
|
|
136
213
|
/**
|
|
137
214
|
* Utility to convert data URI to a `blob` object
|
|
138
215
|
* @param dataURI uri to convert to blob
|
package/lib/utils/JsonUtils.d.ts
CHANGED
|
@@ -34,12 +34,19 @@ export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
|
|
|
34
34
|
* @returns `true` if `item` is a form check box group, `false` otherwise
|
|
35
35
|
*/
|
|
36
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;
|
|
37
43
|
/**
|
|
38
44
|
* Clones an object completely including any nested objects or arrays
|
|
39
45
|
* @param obj
|
|
46
|
+
* @param idGenerator
|
|
40
47
|
* @private
|
|
41
48
|
*/
|
|
42
|
-
export declare function deepClone(obj: any): any;
|
|
49
|
+
export declare function deepClone(obj: any, idGenerator?: () => string): any;
|
|
43
50
|
/**
|
|
44
51
|
* Checks if the key got added in current object
|
|
45
52
|
* @param currentObj
|
package/lib/utils/JsonUtils.js
CHANGED
|
@@ -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.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
|
|
10
|
+
exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isDateField = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Defines generic utilities to interact with form model definition which is represented as json
|
|
13
13
|
*/
|
|
@@ -74,26 +74,41 @@ const isCheckboxGroup = function (item) {
|
|
|
74
74
|
return fieldType === 'checkbox-group';
|
|
75
75
|
};
|
|
76
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;
|
|
77
87
|
/**
|
|
78
88
|
* Clones an object completely including any nested objects or arrays
|
|
79
89
|
* @param obj
|
|
90
|
+
* @param idGenerator
|
|
80
91
|
* @private
|
|
81
92
|
*/
|
|
82
|
-
function deepClone(obj) {
|
|
93
|
+
function deepClone(obj, idGenerator) {
|
|
83
94
|
let result;
|
|
84
95
|
if (obj instanceof Array) {
|
|
85
96
|
result = [];
|
|
86
|
-
result = obj.map(x => deepClone(x));
|
|
97
|
+
result = obj.map(x => deepClone(x, idGenerator));
|
|
87
98
|
}
|
|
88
99
|
else if (typeof obj === 'object' && obj !== null) {
|
|
89
100
|
result = {};
|
|
90
101
|
Object.entries(obj).forEach(([key, value]) => {
|
|
91
|
-
result[key] = deepClone(value);
|
|
102
|
+
result[key] = deepClone(value, idGenerator);
|
|
92
103
|
});
|
|
93
104
|
}
|
|
94
105
|
else {
|
|
95
106
|
result = obj;
|
|
96
107
|
}
|
|
108
|
+
//if idGenerator is specified, and id exists in the object
|
|
109
|
+
if (idGenerator && result && result.id) {
|
|
110
|
+
result.id = idGenerator();
|
|
111
|
+
}
|
|
97
112
|
return result;
|
|
98
113
|
}
|
|
99
114
|
exports.deepClone = deepClone;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.8",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"docs": "npx typedoc --options .typedoc.cjs"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@adobe/json-formula": "
|
|
37
|
+
"@adobe/json-formula": "^0.1.44",
|
|
38
|
+
"@aemforms/af-formatters": "^0.22.8"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "
|
|
41
|
+
"@types/jest": "^27.5.1",
|
|
41
42
|
"@types/lodash": "^4.14.171",
|
|
42
43
|
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
|
43
44
|
"@typescript-eslint/parser": "^4.28.2",
|
|
@@ -48,11 +49,11 @@
|
|
|
48
49
|
"eslint-plugin-node": "^11.1.0",
|
|
49
50
|
"eslint-plugin-promise": "^5.1.0",
|
|
50
51
|
"form-data": "^4.0.0",
|
|
51
|
-
"jest": "
|
|
52
|
+
"jest": "^27.5.1",
|
|
52
53
|
"jest-junit": "^12.2.0",
|
|
53
54
|
"nock": "^13.1.3",
|
|
54
55
|
"node-fetch": "^2.6.1",
|
|
55
|
-
"ts-jest": "
|
|
56
|
+
"ts-jest": "^27.1.4",
|
|
56
57
|
"typedoc": "0.22.11",
|
|
57
58
|
"typedoc-plugin-markdown": "3.11.13",
|
|
58
59
|
"typescript": "^4.3.5"
|