@aemforms/af-core 0.22.18 → 0.22.20

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 (120) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +11 -68
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +86 -182
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/{Container.js → esm/Container.js} +76 -124
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +44 -98
  15. package/lib/{Field.js → esm/Field.js} +172 -206
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +12 -55
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +10 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
  39. package/lib/{controller → esm/controller}/Logger.js +5 -11
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +20 -35
  42. package/lib/{data → esm/data}/DataValue.d.ts +2 -8
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +44 -114
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/{types → esm/types}/Json.d.ts +6 -22
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
  59. package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -0
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
  76. package/package.json +17 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/Container.d.ts +0 -199
  81. package/lib/DateField.js +0 -35
  82. package/lib/Fieldset.d.ts +0 -34
  83. package/lib/Fieldset.js +0 -113
  84. package/lib/FileObject.js +0 -39
  85. package/lib/FileUpload.js +0 -155
  86. package/lib/Form.d.ts +0 -262
  87. package/lib/Form.js +0 -230
  88. package/lib/FormInstance.d.ts +0 -38
  89. package/lib/FormInstance.js +0 -119
  90. package/lib/FormMetaData.d.ts +0 -11
  91. package/lib/FormMetaData.js +0 -28
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -223
  96. package/lib/controller/Controller.js +0 -287
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -52
  100. package/lib/data/EmptyDataValue.js +0 -46
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -63
  103. package/lib/rules/RuleEngine.d.ts +0 -23
  104. package/lib/rules/RuleEngine.js +0 -62
  105. package/lib/types/Json.js +0 -19
  106. package/lib/types/Model.d.ts +0 -379
  107. package/lib/types/Model.js +0 -20
  108. package/lib/types/index.d.ts +0 -2
  109. package/lib/types/index.js +0 -25
  110. package/lib/utils/Fetch.js +0 -29
  111. package/lib/utils/FormUtils.d.ts +0 -47
  112. package/lib/utils/FormUtils.js +0 -257
  113. package/lib/utils/JsonUtils.d.ts +0 -62
  114. package/lib/utils/JsonUtils.js +0 -143
  115. package/lib/utils/LogUtils.js +0 -17
  116. package/lib/utils/SchemaUtils.d.ts +0 -16
  117. package/lib/utils/SchemaUtils.js +0 -92
  118. package/lib/utils/TranslationUtils.d.ts +0 -41
  119. package/lib/utils/TranslationUtils.js +0 -185
  120. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -1,199 +0,0 @@
1
- import { Action, BaseModel, ContainerJson, ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, RulesJson } from './types';
2
- import Scriptable from './Scriptable';
3
- import DataGroup from './data/DataGroup';
4
- /**
5
- * Defines a generic container class which any form container should extend from.
6
- * @typeparam T type of the node which extends {@link ContainerJson} and {@link RulesJson}
7
- */
8
- declare abstract class Container<T extends ContainerJson & RulesJson> extends Scriptable<T> implements ContainerModel {
9
- protected _children: Array<FieldModel | FieldsetModel>;
10
- protected _childrenReference: any;
11
- private _itemTemplate;
12
- protected _jsonModel: T & {
13
- id: string;
14
- items: Array<FieldJson & {
15
- id: string;
16
- } | ContainerJson & {
17
- id: string;
18
- }>;
19
- };
20
- /**
21
- * @private
22
- */
23
- ruleNodeReference(): any;
24
- get items(): (FieldModel | FieldsetModel)[];
25
- get maxItems(): number;
26
- set maxItems(m: number);
27
- get minItems(): number;
28
- /**
29
- * returns whether the items in the Panel can repeat or not
30
- */
31
- hasDynamicItems(): boolean;
32
- get isContainer(): boolean;
33
- private _activeChild;
34
- /**
35
- * Returns the current container state
36
- */
37
- getState(): T & {
38
- items: ({
39
- id: string;
40
- index: number;
41
- ':type': string;
42
- description?: string | undefined;
43
- rules?: import("./types").Items<string> | undefined;
44
- events?: import("./types").Items<string | string[] | undefined> | undefined;
45
- enumNames?: string[] | undefined;
46
- enum?: any[] | undefined;
47
- accept?: string[] | undefined;
48
- enforceEnum?: boolean | undefined;
49
- exclusiveMinimum?: number | undefined;
50
- exclusiveMaximum?: number | undefined;
51
- format?: string | undefined;
52
- maxFileSize?: string | number | undefined;
53
- maxLength?: number | undefined;
54
- maximum?: number | undefined;
55
- maxItems?: number | undefined;
56
- minLength?: number | undefined;
57
- minimum?: number | undefined;
58
- minItems?: number | undefined;
59
- pattern?: string | undefined;
60
- required?: boolean | undefined;
61
- /**
62
- * @private
63
- */
64
- step?: number | undefined;
65
- type?: string | undefined;
66
- validationExpression?: string | undefined;
67
- uniqueItems?: boolean | undefined;
68
- dataRef?: string | null | undefined;
69
- label?: import("./types").Label | undefined;
70
- enabled?: boolean | undefined;
71
- visible?: boolean | undefined;
72
- name?: string | undefined;
73
- constraintMessages?: import("./types").ConstraintsMessages | undefined;
74
- fieldType?: string | undefined; /**
75
- * Returns the current container state
76
- */
77
- errorMessage?: string | undefined;
78
- properties?: {
79
- [key: string]: any;
80
- } | undefined;
81
- screenReaderText?: string | undefined;
82
- tooltip?: string | undefined;
83
- altText?: string | undefined;
84
- placeholder?: string | undefined;
85
- readOnly?: boolean | undefined;
86
- valid?: boolean | undefined;
87
- default?: any;
88
- value?: any;
89
- displayFormat?: string | undefined;
90
- editFormat?: string | undefined;
91
- editValue?: string | undefined;
92
- displayValue?: string | undefined;
93
- emptyValue?: "" | "undefined" | "null" | undefined;
94
- } | {
95
- id: string;
96
- index: number;
97
- ':type': string;
98
- description?: string | undefined;
99
- rules?: import("./types").Items<string> | undefined;
100
- events?: import("./types").Items<string | string[] | undefined> | undefined;
101
- enumNames?: string[] | undefined;
102
- enum?: any[] | undefined;
103
- accept?: string[] | undefined;
104
- enforceEnum?: boolean | undefined;
105
- exclusiveMinimum?: number | undefined;
106
- exclusiveMaximum?: number | undefined;
107
- format?: string | undefined;
108
- maxFileSize?: string | number | undefined;
109
- maxLength?: number | undefined;
110
- maximum?: number | undefined;
111
- maxItems?: number | undefined;
112
- minLength?: number | undefined;
113
- minimum?: number | undefined;
114
- minItems?: number | undefined;
115
- pattern?: string | undefined;
116
- required?: boolean | undefined;
117
- /**
118
- * @private
119
- */
120
- step?: number | undefined;
121
- type?: "object" | "array" | undefined;
122
- validationExpression?: string | undefined;
123
- uniqueItems?: boolean | undefined;
124
- dataRef?: string | null | undefined;
125
- label?: import("./types").Label | undefined;
126
- enabled?: boolean | undefined;
127
- visible?: boolean | undefined;
128
- name?: string | undefined;
129
- constraintMessages?: import("./types").ConstraintsMessages | undefined;
130
- fieldType?: string | undefined; /**
131
- * Returns the current container state
132
- */
133
- errorMessage?: string | undefined;
134
- properties?: {
135
- [key: string]: any;
136
- } | undefined;
137
- screenReaderText?: string | undefined;
138
- tooltip?: string | undefined;
139
- altText?: string | undefined;
140
- items: (FieldJson | ContainerJson)[] & import("./types").State<FieldJson | ContainerJson>[];
141
- initialItems?: number | undefined;
142
- activeChild?: string | undefined;
143
- })[];
144
- properties: {
145
- [key: string]: any;
146
- };
147
- index: number;
148
- parent: undefined;
149
- qualifiedName: any;
150
- events: {};
151
- rules: {};
152
- ':type': string;
153
- id: string;
154
- };
155
- protected abstract _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
156
- private _addChildToRuleNode;
157
- private _addChild;
158
- indexOf(f: FieldModel | FieldsetModel): number;
159
- /**
160
- * @private
161
- */
162
- defaultDataModel(name: string): DataGroup | undefined;
163
- /**
164
- * @private
165
- */
166
- _initialize(): void;
167
- /**
168
- * @private
169
- */
170
- addItem(action: Action): void;
171
- /**
172
- * @private
173
- */
174
- removeItem(action: Action): void;
175
- /**
176
- * @private
177
- */
178
- queueEvent(action: Action): void;
179
- validate(): import("./types").ValidationError[];
180
- /**
181
- * @private
182
- */
183
- dispatch(action: Action): void;
184
- /**
185
- * @private
186
- */
187
- importData(contextualDataModel: DataGroup): void;
188
- /**
189
- * prefill the form with data on the given element
190
- * @param dataModel
191
- * @param contextualDataModel
192
- * @param operation
193
- * @private
194
- */
195
- syncDataAndFormModel(contextualDataModel?: DataGroup): void;
196
- get activeChild(): BaseModel | null;
197
- set activeChild(c: BaseModel | null);
198
- }
199
- export default Container;
package/lib/DateField.js DELETED
@@ -1,35 +0,0 @@
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/Fieldset.d.ts DELETED
@@ -1,34 +0,0 @@
1
- import Container from './Container';
2
- import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from './types';
3
- /**
4
- * Creates a child model inside the given parent
5
- * @param child
6
- * @param options
7
- * @private
8
- */
9
- export declare const createChild: (child: FieldsetJson | FieldJson, options: {
10
- form: FormModel;
11
- parent: ContainerModel;
12
- }) => FieldModel | FieldsetModel;
13
- /**
14
- * Defines a field set class which extends from {@link Container | container}
15
- */
16
- export declare class Fieldset extends Container<FieldsetJson> implements FieldsetModel {
17
- /**
18
- * @param params
19
- * @param _options
20
- * @private
21
- */
22
- constructor(params: FieldsetJson, _options: {
23
- form: FormModel;
24
- parent: ContainerModel;
25
- });
26
- private _applyDefaults;
27
- get type(): "array" | "object" | undefined;
28
- protected _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
29
- get items(): (FieldModel | FieldsetModel)[];
30
- get value(): null;
31
- get fieldType(): string;
32
- get enabled(): boolean | undefined;
33
- set enabled(e: boolean | undefined);
34
- }
package/lib/Fieldset.js DELETED
@@ -1,113 +0,0 @@
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");
19
- const Checkbox_1 = __importDefault(require("./Checkbox"));
20
- const CheckboxGroup_1 = __importDefault(require("./CheckboxGroup"));
21
- const DateField_1 = __importDefault(require("./DateField"));
22
- /**
23
- * Creates a child model inside the given parent
24
- * @param child
25
- * @param options
26
- * @private
27
- */
28
- const createChild = (child, options) => {
29
- let retVal;
30
- if ('items' in child) {
31
- retVal = new Fieldset(child, options);
32
- }
33
- else {
34
- if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
35
- // @ts-ignore
36
- retVal = new FileUpload_1.default(child, options);
37
- }
38
- else if ((0, JsonUtils_1.isCheckbox)(child)) {
39
- retVal = new Checkbox_1.default(child, options);
40
- }
41
- else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
42
- retVal = new CheckboxGroup_1.default(child, options);
43
- }
44
- else if ((0, JsonUtils_1.isDateField)(child)) {
45
- retVal = new DateField_1.default(child, options);
46
- }
47
- else {
48
- retVal = new Field_1.default(child, options);
49
- }
50
- }
51
- options.form.fieldAdded(retVal);
52
- return retVal;
53
- };
54
- exports.createChild = createChild;
55
- const defaults = {
56
- visible: true
57
- };
58
- /**
59
- * Defines a field set class which extends from {@link Container | container}
60
- */
61
- class Fieldset extends Container_1.default {
62
- /**
63
- * @param params
64
- * @param _options
65
- * @private
66
- */
67
- constructor(params, _options) {
68
- super(params, _options);
69
- this._applyDefaults();
70
- this.queueEvent(new controller_1.Initialize());
71
- this.queueEvent(new controller_1.ExecuteRule());
72
- }
73
- _applyDefaults() {
74
- Object.entries(defaults).map(([key, value]) => {
75
- //@ts-ignore
76
- if (this._jsonModel[key] === undefined) {
77
- //@ts-ignore
78
- this._jsonModel[key] = value;
79
- }
80
- });
81
- if (this._jsonModel.dataRef && this._jsonModel.type === undefined) {
82
- this._jsonModel.type = 'object';
83
- }
84
- }
85
- get type() {
86
- const ret = super.type;
87
- if (ret === 'array' || ret === 'object') {
88
- return ret;
89
- }
90
- return undefined;
91
- }
92
- // @ts-ignore
93
- _createChild(child, options) {
94
- const { parent = this } = options;
95
- return (0, exports.createChild)(child, { form: this.form, parent: parent });
96
- }
97
- get items() {
98
- return super.items;
99
- }
100
- get value() {
101
- return null;
102
- }
103
- get fieldType() {
104
- return 'panel';
105
- }
106
- get enabled() {
107
- return this._jsonModel.enabled;
108
- }
109
- set enabled(e) {
110
- this._setProperty('enabled', e);
111
- }
112
- }
113
- exports.Fieldset = Fieldset;
package/lib/FileObject.js DELETED
@@ -1,39 +0,0 @@
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
- get type() {
22
- return this.mediaType;
23
- }
24
- toJSON() {
25
- return {
26
- 'name': this.name,
27
- 'size': this.size,
28
- 'mediaType': this.mediaType,
29
- 'data': this.data.toString()
30
- };
31
- }
32
- equals(obj) {
33
- return (this.data === obj.data &&
34
- this.mediaType === obj.mediaType &&
35
- this.name === obj.name &&
36
- this.size === obj.size);
37
- }
38
- }
39
- exports.FileObject = FileObject;
package/lib/FileUpload.js DELETED
@@ -1,155 +0,0 @@
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 FileObject_1 = require("./FileObject");
26
- const ValidationUtils_1 = require("./utils/ValidationUtils");
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, type } = 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
- type,
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' });
60
- }
61
- _getFallbackType() {
62
- return 'file';
63
- }
64
- /**
65
- * Returns the max file size in bytes as per IEC specification
66
- */
67
- get maxFileSize() {
68
- return (0, FormUtils_1.getFileSizeInBytes)(this._jsonModel.maxFileSize);
69
- }
70
- /**
71
- * Returns the list of mime types which file attachment can accept
72
- */
73
- get accept() {
74
- return this._jsonModel.accept;
75
- }
76
- /**
77
- * Checks whether there are any updates in the properties
78
- * @param propNames
79
- * @param updates
80
- * @private
81
- */
82
- _applyUpdates(propNames, updates) {
83
- return propNames.reduce((acc, propertyName) => {
84
- //@ts-ignore
85
- const prevValue = this._jsonModel[propertyName];
86
- const currentValue = updates[propertyName];
87
- if (currentValue !== prevValue) {
88
- acc[propertyName] = {
89
- propertyName,
90
- currentValue,
91
- prevValue
92
- };
93
- if (prevValue instanceof FileObject_1.FileObject && typeof currentValue === 'object' && propertyName === 'value') {
94
- // @ts-ignore
95
- this._jsonModel[propertyName] = new FileObject_1.FileObject(Object.assign(Object.assign({}, prevValue), { 'data': currentValue.data }));
96
- }
97
- else {
98
- // @ts-ignore
99
- this._jsonModel[propertyName] = currentValue;
100
- }
101
- }
102
- return acc;
103
- }, {});
104
- }
105
- getInternalType() {
106
- var _a;
107
- return ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) ? 'file[]' : 'file';
108
- }
109
- getDataNodeValue(typedValue) {
110
- var _a;
111
- let dataNodeValue = typedValue;
112
- if (dataNodeValue != null) {
113
- if (this.type === 'string') {
114
- dataNodeValue = (_a = dataNodeValue.data) === null || _a === void 0 ? void 0 : _a.toString();
115
- }
116
- else if (this.type === 'string[]') {
117
- dataNodeValue = dataNodeValue instanceof Array ? dataNodeValue : [dataNodeValue];
118
- dataNodeValue = dataNodeValue.map((_) => { var _a; return (_a = _ === null || _ === void 0 ? void 0 : _.data) === null || _a === void 0 ? void 0 : _a.toString(); });
119
- }
120
- }
121
- return dataNodeValue;
122
- }
123
- _serialize() {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const val = this._jsonModel.value;
126
- if (val === undefined) {
127
- return null;
128
- }
129
- // @ts-ignore
130
- const filesInfo = yield processFiles(val instanceof Array ? val : [val]);
131
- return filesInfo;
132
- });
133
- }
134
- importData(dataModel) {
135
- this._bindToDataModel(dataModel);
136
- const dataNode = this.getDataNode();
137
- if (dataNode !== undefined) {
138
- const value = dataNode === null || dataNode === void 0 ? void 0 : dataNode.$value;
139
- // only if not undefined, proceed further
140
- if (value != null) {
141
- const res = ValidationUtils_1.Constraints.type(this.getInternalType(), value);
142
- if (!res.valid) {
143
- this.form.logger.error(`unable to bind ${this.name} to data`);
144
- }
145
- // is this needed ?
146
- this.form.getEventQueue().queue(this, (0, Controller_1.propertyChange)('value', res.value, this._jsonModel.value));
147
- this._jsonModel.value = res.value;
148
- }
149
- else {
150
- this._jsonModel.value = null;
151
- }
152
- }
153
- }
154
- }
155
- exports.default = FileUpload;