@aemforms/af-core 0.15.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.
Files changed (69) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +34 -0
  3. package/lib/BaseNode.d.ts +117 -0
  4. package/lib/BaseNode.js +368 -0
  5. package/lib/Checkbox.d.ts +80 -0
  6. package/lib/Checkbox.js +49 -0
  7. package/lib/CheckboxGroup.d.ts +30 -0
  8. package/lib/CheckboxGroup.js +40 -0
  9. package/lib/Container.d.ts +336 -0
  10. package/lib/Container.js +279 -0
  11. package/lib/Field.d.ts +185 -0
  12. package/lib/Field.js +432 -0
  13. package/lib/Fieldset.d.ts +31 -0
  14. package/lib/Fieldset.js +97 -0
  15. package/lib/FileObject.d.ts +17 -0
  16. package/lib/FileObject.js +30 -0
  17. package/lib/FileUpload.d.ts +42 -0
  18. package/lib/FileUpload.js +299 -0
  19. package/lib/Form.d.ts +413 -0
  20. package/lib/Form.js +247 -0
  21. package/lib/FormInstance.d.ts +26 -0
  22. package/lib/FormInstance.js +116 -0
  23. package/lib/FormMetaData.d.ts +11 -0
  24. package/lib/FormMetaData.js +28 -0
  25. package/lib/Node.d.ts +12 -0
  26. package/lib/Node.js +27 -0
  27. package/lib/Scriptable.d.ts +27 -0
  28. package/lib/Scriptable.js +216 -0
  29. package/lib/controller/Controller.d.ts +207 -0
  30. package/lib/controller/Controller.js +263 -0
  31. package/lib/controller/EventQueue.d.ts +24 -0
  32. package/lib/controller/EventQueue.js +99 -0
  33. package/lib/controller/index.d.ts +1 -0
  34. package/lib/controller/index.js +24 -0
  35. package/lib/data/DataGroup.d.ts +25 -0
  36. package/lib/data/DataGroup.js +74 -0
  37. package/lib/data/DataValue.d.ts +22 -0
  38. package/lib/data/DataValue.js +50 -0
  39. package/lib/data/EmptyDataValue.d.ts +14 -0
  40. package/lib/data/EmptyDataValue.js +46 -0
  41. package/lib/index.d.ts +27 -0
  42. package/lib/index.js +59 -0
  43. package/lib/rules/FunctionRuntime.d.ts +44 -0
  44. package/lib/rules/FunctionRuntime.js +271 -0
  45. package/lib/rules/RuleEngine.d.ts +23 -0
  46. package/lib/rules/RuleEngine.js +67 -0
  47. package/lib/types/Json.d.ts +126 -0
  48. package/lib/types/Json.js +16 -0
  49. package/lib/types/Model.d.ts +352 -0
  50. package/lib/types/Model.js +20 -0
  51. package/lib/types/index.d.ts +2 -0
  52. package/lib/types/index.js +25 -0
  53. package/lib/utils/DataRefParser.d.ts +30 -0
  54. package/lib/utils/DataRefParser.js +249 -0
  55. package/lib/utils/Fetch.d.ts +7 -0
  56. package/lib/utils/Fetch.js +29 -0
  57. package/lib/utils/FormUtils.d.ts +47 -0
  58. package/lib/utils/FormUtils.js +172 -0
  59. package/lib/utils/JsonUtils.d.ts +55 -0
  60. package/lib/utils/JsonUtils.js +128 -0
  61. package/lib/utils/LogUtils.d.ts +7 -0
  62. package/lib/utils/LogUtils.js +17 -0
  63. package/lib/utils/SchemaUtils.d.ts +16 -0
  64. package/lib/utils/SchemaUtils.js +92 -0
  65. package/lib/utils/TranslationUtils.d.ts +34 -0
  66. package/lib/utils/TranslationUtils.js +156 -0
  67. package/lib/utils/ValidationUtils.d.ts +153 -0
  68. package/lib/utils/ValidationUtils.js +339 -0
  69. package/package.json +60 -0
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2022 Adobe, Inc.
4
+ *
5
+ * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Fieldset = exports.createChild = void 0;
14
+ const Container_1 = __importDefault(require("./Container"));
15
+ const Field_1 = __importDefault(require("./Field"));
16
+ const FileUpload_1 = __importDefault(require("./FileUpload"));
17
+ const JsonUtils_1 = require("./utils/JsonUtils");
18
+ const Controller_1 = require("./controller/Controller");
19
+ const Checkbox_1 = __importDefault(require("./Checkbox"));
20
+ const CheckboxGroup_1 = __importDefault(require("./CheckboxGroup"));
21
+ /**
22
+ * Creates a child model inside the given parent
23
+ * @param child
24
+ * @param options
25
+ * @private
26
+ */
27
+ const createChild = (child, options) => {
28
+ let retVal;
29
+ if ('items' in child) {
30
+ retVal = new Fieldset(child, options);
31
+ }
32
+ else {
33
+ if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
34
+ // @ts-ignore
35
+ retVal = new FileUpload_1.default(child, options);
36
+ }
37
+ else if ((0, JsonUtils_1.isCheckbox)(child)) {
38
+ retVal = new Checkbox_1.default(child, options);
39
+ }
40
+ else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
41
+ retVal = new CheckboxGroup_1.default(child, options);
42
+ }
43
+ else {
44
+ retVal = new Field_1.default(child, options);
45
+ }
46
+ }
47
+ options.form.fieldAdded(retVal);
48
+ return retVal;
49
+ };
50
+ exports.createChild = createChild;
51
+ const defaults = {
52
+ visible: true
53
+ };
54
+ /**
55
+ * Defines a field set class which extends from {@link Container | container}
56
+ */
57
+ class Fieldset extends Container_1.default {
58
+ /**
59
+ * @param params
60
+ * @param _options
61
+ * @private
62
+ */
63
+ constructor(params, _options) {
64
+ super(params, _options);
65
+ this._applyDefaults();
66
+ this.queueEvent(new Controller_1.Initialize());
67
+ this.queueEvent(new Controller_1.ExecuteRule());
68
+ }
69
+ _applyDefaults() {
70
+ Object.entries(defaults).map(([key, value]) => {
71
+ //@ts-ignore
72
+ if (this._jsonModel[key] === undefined) {
73
+ //@ts-ignore
74
+ this._jsonModel[key] = value;
75
+ }
76
+ });
77
+ }
78
+ get type() {
79
+ const ret = super.type;
80
+ if (ret === 'array' || ret === 'object') {
81
+ return ret;
82
+ }
83
+ return undefined;
84
+ }
85
+ // @ts-ignore
86
+ _createChild(child, options) {
87
+ const { parent = this } = options;
88
+ return (0, exports.createChild)(child, { form: this.form, parent: parent });
89
+ }
90
+ get items() {
91
+ return super.items;
92
+ }
93
+ get value() {
94
+ return null;
95
+ }
96
+ }
97
+ exports.Fieldset = Fieldset;
@@ -0,0 +1,17 @@
1
+ import { IFileObject } from './types';
2
+ /**
3
+ * Defines a file object which implements the {@link IFileObject | file object interface}
4
+ */
5
+ export declare class FileObject implements IFileObject {
6
+ data: any;
7
+ mediaType: string;
8
+ name: string;
9
+ size: number;
10
+ constructor(init?: Partial<FileObject>);
11
+ toJSON(): {
12
+ name: string;
13
+ size: number;
14
+ mediaType: string;
15
+ data: any;
16
+ };
17
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2022 Adobe, Inc.
4
+ *
5
+ * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FileObject = void 0;
11
+ /**
12
+ * Defines a file object which implements the {@link IFileObject | file object interface}
13
+ */
14
+ class FileObject {
15
+ constructor(init) {
16
+ this.mediaType = 'application/octet-stream';
17
+ this.name = 'unknown';
18
+ this.size = 0;
19
+ Object.assign(this, init);
20
+ }
21
+ toJSON() {
22
+ return {
23
+ 'name': this.name,
24
+ 'size': this.size,
25
+ 'mediaType': this.mediaType,
26
+ 'data': this.data.toString()
27
+ };
28
+ }
29
+ }
30
+ exports.FileObject = FileObject;
@@ -0,0 +1,42 @@
1
+ import Field from './Field';
2
+ import { FieldModel } from './types';
3
+ import DataGroup from './data/DataGroup';
4
+ /**
5
+ * Implementation of FileUpload runtime model which extends from {@link Field | field}
6
+ */
7
+ declare class FileUpload extends Field implements FieldModel {
8
+ protected _getDefaults(): {
9
+ accept: string[];
10
+ maxFileSize: string;
11
+ type: string;
12
+ readOnly: boolean;
13
+ enabled: boolean;
14
+ visible: boolean;
15
+ };
16
+ private static extractFileInfo;
17
+ /**
18
+ * Returns the max file size in bytes as per IEC specification
19
+ */
20
+ get maxFileSize(): number;
21
+ /**
22
+ * Returns the list of mime types which file attachment can accept
23
+ */
24
+ get accept(): string[] | undefined;
25
+ /**
26
+ * Checks whether there are any updates in the properties
27
+ * @param propNames
28
+ * @param updates
29
+ * @private
30
+ */
31
+ protected _applyUpdates(propNames: string[], updates: any): any;
32
+ typeCheck(value: any): {
33
+ valid: boolean;
34
+ value: any;
35
+ };
36
+ get value(): any;
37
+ set value(value: any);
38
+ private _serialize;
39
+ private coerce;
40
+ importData(dataModel?: DataGroup): void;
41
+ }
42
+ export default FileUpload;
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2022 Adobe, Inc.
4
+ *
5
+ * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ */
9
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16
+ });
17
+ };
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const Controller_1 = require("./controller/Controller");
23
+ const Field_1 = __importDefault(require("./Field"));
24
+ const FormUtils_1 = require("./utils/FormUtils");
25
+ const ValidationUtils_1 = require("./utils/ValidationUtils");
26
+ const FileObject_1 = require("./FileObject");
27
+ function addNameToDataURL(dataURL, name) {
28
+ return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
29
+ }
30
+ function processFiles(files) {
31
+ return Promise.all([].map.call(files, processFile));
32
+ }
33
+ function processFile(file) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { name, size, mediaType } = file;
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
+ const fileObj = yield new Promise((resolve, reject) => {
38
+ const reader = new FileReader();
39
+ reader.onload = event => {
40
+ resolve(new FileObject_1.FileObject({
41
+ // @ts-ignore
42
+ data: addNameToDataURL(event.target.result, name),
43
+ mediaType: mediaType,
44
+ name,
45
+ size
46
+ }));
47
+ };
48
+ reader.readAsDataURL(file.data);
49
+ });
50
+ return fileObj;
51
+ });
52
+ }
53
+ /**
54
+ * Implementation of FileUpload runtime model which extends from {@link Field | field}
55
+ */
56
+ class FileUpload extends Field_1.default {
57
+ //private _files: FileObject[];
58
+ _getDefaults() {
59
+ return Object.assign(Object.assign({}, super._getDefaults()), { accept: ['audio/*', 'video/*', 'image/*', 'text/*', 'application/pdf'], maxFileSize: '2MB', type: 'file' });
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
+ /**
131
+ * Returns the max file size in bytes as per IEC specification
132
+ */
133
+ get maxFileSize() {
134
+ return (0, FormUtils_1.getFileSizeInBytes)(this._jsonModel.maxFileSize);
135
+ }
136
+ /**
137
+ * Returns the list of mime types which file attachment can accept
138
+ */
139
+ get accept() {
140
+ return this._jsonModel.accept;
141
+ }
142
+ /**
143
+ * Checks whether there are any updates in the properties
144
+ * @param propNames
145
+ * @param updates
146
+ * @private
147
+ */
148
+ _applyUpdates(propNames, updates) {
149
+ return propNames.reduce((acc, propertyName) => {
150
+ //@ts-ignore
151
+ const prevValue = this._jsonModel[propertyName];
152
+ const currentValue = updates[propertyName];
153
+ if (currentValue !== prevValue) {
154
+ acc[propertyName] = {
155
+ propertyName,
156
+ currentValue,
157
+ prevValue
158
+ };
159
+ if (prevValue instanceof FileObject_1.FileObject && typeof currentValue === 'object' && propertyName === 'value') {
160
+ // @ts-ignore
161
+ this._jsonModel[propertyName] = new FileObject_1.FileObject(Object.assign(Object.assign({}, prevValue), { 'data': currentValue.data }));
162
+ }
163
+ else {
164
+ // @ts-ignore
165
+ this._jsonModel[propertyName] = currentValue;
166
+ }
167
+ }
168
+ return acc;
169
+ }, {});
170
+ }
171
+ typeCheck(value) {
172
+ const type = this._jsonModel.type || 'file';
173
+ switch (type) {
174
+ case 'string':
175
+ return { valid: true, value: value };
176
+ default:
177
+ return ValidationUtils_1.Constraints.type(type, value);
178
+ }
179
+ }
180
+ get value() {
181
+ // @ts-ignore
182
+ this.ruleEngine.trackDependency(this);
183
+ if (this._jsonModel.value === undefined) {
184
+ return null;
185
+ }
186
+ let val = this._jsonModel.value;
187
+ // always return file object irrespective of data schema
188
+ if (val != null) {
189
+ // @ts-ignore
190
+ val = this.coerce((val instanceof Array ? val : [val])
191
+ .map(file => {
192
+ let retVal = file;
193
+ if (!(retVal instanceof FileObject_1.FileObject)) {
194
+ retVal = new FileObject_1.FileObject({
195
+ 'name': file.name,
196
+ 'mediaType': file.mediaType,
197
+ 'size': file.size,
198
+ 'data': file.data
199
+ });
200
+ }
201
+ // define serialization here
202
+ /*
203
+ Object.defineProperty(retVal, 'data', {
204
+ get: async function() {
205
+ if (file.data instanceof File) {
206
+ return processFile(file);
207
+ } else {
208
+ return file.data;
209
+ }
210
+ }
211
+ });
212
+ */
213
+ return retVal;
214
+ }));
215
+ }
216
+ return val;
217
+ }
218
+ set value(value) {
219
+ if (value !== undefined) {
220
+ // store file list here
221
+ const typeRes = this.typeCheck(value);
222
+ const changes = this._setProperty('value', typeRes.value, false);
223
+ let fileInfoPayload = FileUpload.extractFileInfo(value);
224
+ fileInfoPayload = this.coerce(fileInfoPayload);
225
+ this._setProperty('value', fileInfoPayload, false);
226
+ if (changes.length > 0) {
227
+ const dataNode = this.getDataNode();
228
+ if (typeof dataNode !== 'undefined') {
229
+ let val = this._jsonModel.value;
230
+ const retVal = (val instanceof Array ? val : [val]).map(file => {
231
+ if (this.type === 'file' || this.type === 'file[]') {
232
+ return file;
233
+ }
234
+ else if (this.type === 'string' || this.type === 'string[]') {
235
+ // @ts-ignore
236
+ return file.data.toString();
237
+ }
238
+ });
239
+ val = this.coerce(retVal);
240
+ if (dataNode !== undefined) {
241
+ dataNode.setValue(val, this._jsonModel.value);
242
+ }
243
+ }
244
+ let updates;
245
+ if (typeRes.valid) {
246
+ updates = this.evaluateConstraints();
247
+ }
248
+ else {
249
+ const changes = {
250
+ 'valid': typeRes.valid,
251
+ 'errorMessage': typeRes.valid ? '' : this.getErrorMessage('type')
252
+ };
253
+ updates = this._applyUpdates(['valid', 'errorMessage'], changes);
254
+ }
255
+ if (updates.valid) {
256
+ this.triggerValidationEvent(updates);
257
+ }
258
+ const changeAction = new Controller_1.Change({ changes: changes.concat(Object.values(updates)) });
259
+ this.dispatch(changeAction);
260
+ }
261
+ }
262
+ }
263
+ _serialize() {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ const val = this._jsonModel.value;
266
+ if (val === undefined) {
267
+ return null;
268
+ }
269
+ // @ts-ignore
270
+ const filesInfo = yield processFiles(val instanceof Array ? val : [val]);
271
+ return filesInfo;
272
+ });
273
+ }
274
+ coerce(val) {
275
+ let retVal = val;
276
+ if ((this.type === 'string' || this.type === 'file') && retVal instanceof Array) {
277
+ // @ts-ignore
278
+ retVal = val[0];
279
+ }
280
+ return retVal;
281
+ }
282
+ importData(dataModel) {
283
+ this._bindToDataModel(dataModel);
284
+ const dataNode = this.getDataNode();
285
+ if (dataNode !== undefined) {
286
+ const value = dataNode === null || dataNode === void 0 ? void 0 : dataNode.$value;
287
+ let newValue = value;
288
+ // only if not undefined, proceed further
289
+ if (value != null) {
290
+ const fileObj = FileUpload.extractFileInfo(value);
291
+ newValue = this.coerce(fileObj);
292
+ // is this needed ?
293
+ this.form.getEventQueue().queue(this, (0, Controller_1.propertyChange)('value', newValue, this._jsonModel.value));
294
+ }
295
+ this._jsonModel.value = newValue;
296
+ }
297
+ }
298
+ }
299
+ exports.default = FileUpload;