@aemforms/af-core 0.22.19 → 0.22.22

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 (124) hide show
  1. package/LICENSE +18 -4
  2. package/lib/cjs/index.cjs +7277 -0
  3. package/lib/{BaseNode.js → esm/BaseNode-dc59ab07.js} +108 -184
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
  5. package/lib/esm/BaseNode.js +26 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +63 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +60 -0
  10. package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +81 -122
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +57 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +41 -106
  15. package/lib/{Field.js → esm/Field.js} +186 -216
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +78 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +48 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +141 -0
  22. package/lib/{Form.d.ts → esm/Form.d.ts} +20 -86
  23. package/lib/esm/Form.js +208 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +129 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +35 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +58 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +40 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +38 -54
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +32 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +171 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +2 -8
  39. package/lib/esm/controller/Logger.js +52 -0
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +38 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  43. package/lib/esm/data/DataValue.js +68 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +51 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +55 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +3 -25
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +66 -117
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +76 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  53. package/lib/esm/types/Json.js +29 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +30 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +22 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +4 -7
  59. package/lib/{utils → esm/utils}/DataRefParser.js +42 -44
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -7
  61. package/lib/esm/utils/Fetch.js +83 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +112 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +212 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +99 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +28 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +93 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +138 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +55 -187
  76. package/package.json +18 -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/DateField.js +0 -35
  81. package/lib/Fieldset.d.ts +0 -24
  82. package/lib/Fieldset.js +0 -74
  83. package/lib/FileObject.js +0 -39
  84. package/lib/FileUpload.js +0 -155
  85. package/lib/Form.js +0 -252
  86. package/lib/FormInstance.d.ts +0 -38
  87. package/lib/FormInstance.js +0 -127
  88. package/lib/FormMetaData.d.ts +0 -11
  89. package/lib/FormMetaData.js +0 -28
  90. package/lib/InstanceManager.d.ts +0 -16
  91. package/lib/InstanceManager.js +0 -53
  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 -255
  96. package/lib/controller/Controller.js +0 -328
  97. package/lib/controller/Logger.js +0 -36
  98. package/lib/controller/index.d.ts +0 -1
  99. package/lib/controller/index.js +0 -24
  100. package/lib/data/DataValue.js +0 -56
  101. package/lib/data/EmptyDataValue.js +0 -46
  102. package/lib/index.d.ts +0 -28
  103. package/lib/index.js +0 -63
  104. package/lib/rules/RuleEngine.d.ts +0 -23
  105. package/lib/rules/RuleEngine.js +0 -62
  106. package/lib/types/Json.d.ts +0 -138
  107. package/lib/types/Json.js +0 -19
  108. package/lib/types/Model.d.ts +0 -393
  109. package/lib/types/Model.js +0 -20
  110. package/lib/types/index.d.ts +0 -2
  111. package/lib/types/index.js +0 -25
  112. package/lib/utils/Fetch.js +0 -87
  113. package/lib/utils/FormCreationUtils.d.ts +0 -11
  114. package/lib/utils/FormCreationUtils.js +0 -83
  115. package/lib/utils/FormUtils.d.ts +0 -47
  116. package/lib/utils/FormUtils.js +0 -257
  117. package/lib/utils/JsonUtils.d.ts +0 -63
  118. package/lib/utils/JsonUtils.js +0 -157
  119. package/lib/utils/LogUtils.js +0 -17
  120. package/lib/utils/SchemaUtils.d.ts +0 -16
  121. package/lib/utils/SchemaUtils.js +0 -92
  122. package/lib/utils/TranslationUtils.d.ts +0 -41
  123. package/lib/utils/TranslationUtils.js +0 -185
  124. package/lib/utils/ValidationUtils.d.ts +0 -170
package/lib/Fieldset.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import Container from './Container';
2
- import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from './types';
3
- /**
4
- * Defines a field set class which extends from {@link Container | container}
5
- */
6
- export declare class Fieldset extends Container<FieldsetJson> implements FieldsetModel {
7
- /**
8
- * @param params
9
- * @param _options
10
- * @private
11
- */
12
- constructor(params: FieldsetJson, _options: {
13
- form: FormModel;
14
- parent: ContainerModel;
15
- });
16
- private _applyDefaults;
17
- get type(): "array" | "object" | undefined;
18
- protected _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
19
- get items(): (FieldModel | FieldsetModel)[];
20
- get value(): null;
21
- get fieldType(): string;
22
- get enabled(): boolean | undefined;
23
- set enabled(e: boolean | undefined);
24
- }
package/lib/Fieldset.js DELETED
@@ -1,74 +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 = void 0;
14
- const Container_1 = __importDefault(require("./Container"));
15
- const controller_1 = require("./controller");
16
- const FormCreationUtils_1 = require("./utils/FormCreationUtils");
17
- const defaults = {
18
- visible: true
19
- };
20
- /**
21
- * Defines a field set class which extends from {@link Container | container}
22
- */
23
- class Fieldset extends Container_1.default {
24
- /**
25
- * @param params
26
- * @param _options
27
- * @private
28
- */
29
- constructor(params, _options) {
30
- super(params, _options);
31
- this._applyDefaults();
32
- this.queueEvent(new controller_1.Initialize());
33
- this.queueEvent(new controller_1.ExecuteRule());
34
- }
35
- _applyDefaults() {
36
- Object.entries(defaults).map(([key, value]) => {
37
- //@ts-ignore
38
- if (this._jsonModel[key] === undefined) {
39
- //@ts-ignore
40
- this._jsonModel[key] = value;
41
- }
42
- });
43
- if (this._jsonModel.dataRef && this._jsonModel.type === undefined) {
44
- this._jsonModel.type = 'object';
45
- }
46
- }
47
- get type() {
48
- const ret = super.type;
49
- if (ret === 'array' || ret === 'object') {
50
- return ret;
51
- }
52
- return undefined;
53
- }
54
- _createChild(child, options) {
55
- const { parent = this } = options;
56
- return (0, FormCreationUtils_1.createChild)(child, { form: this.form, parent: parent });
57
- }
58
- get items() {
59
- return super.items;
60
- }
61
- get value() {
62
- return null;
63
- }
64
- get fieldType() {
65
- return 'panel';
66
- }
67
- get enabled() {
68
- return this._jsonModel.enabled;
69
- }
70
- set enabled(e) {
71
- this._setProperty('enabled', e);
72
- }
73
- }
74
- 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;
package/lib/Form.js DELETED
@@ -1,252 +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
- const Container_1 = __importDefault(require("./Container"));
14
- const FormMetaData_1 = __importDefault(require("./FormMetaData"));
15
- const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
16
- const Logger_1 = require("./controller/Logger");
17
- const FormUtils_1 = require("./utils/FormUtils");
18
- const FormCreationUtils_1 = require("./utils/FormCreationUtils");
19
- const DataGroup_1 = __importDefault(require("./data/DataGroup"));
20
- const FunctionRuntime_1 = require("./rules/FunctionRuntime");
21
- const controller_1 = require("./controller");
22
- /**
23
- * Defines `form model` which implements {@link FormModel | form model}
24
- */
25
- class Form extends Container_1.default {
26
- /**
27
- * @param n
28
- * @param _ruleEngine
29
- * @param _eventQueue
30
- * @param logLevel
31
- * @private
32
- */
33
- constructor(n, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off') {
34
- //@ts-ignore
35
- super(n, {});
36
- this._ruleEngine = _ruleEngine;
37
- this._eventQueue = _eventQueue;
38
- /**
39
- * @private
40
- */
41
- this._fields = {};
42
- /**
43
- * @private
44
- */
45
- this._invalidFields = [];
46
- this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
47
- this._logger = new Logger_1.Logger(logLevel);
48
- this.queueEvent(new controller_1.Initialize());
49
- this.queueEvent(new controller_1.ExecuteRule());
50
- this._ids = (0, FormUtils_1.IdGenerator)();
51
- this._bindToDataModel(new DataGroup_1.default('$form', {}));
52
- this._initialize();
53
- this.queueEvent(new controller_1.FormLoad());
54
- }
55
- get logger() {
56
- return this._logger;
57
- }
58
- get metaData() {
59
- const metaData = this._jsonModel.metadata || {};
60
- return new FormMetaData_1.default(metaData);
61
- }
62
- get action() {
63
- return this._jsonModel.action;
64
- }
65
- _createChild(child) {
66
- return (0, FormCreationUtils_1.createChild)(child, { form: this, parent: this });
67
- }
68
- importData(dataModel) {
69
- this._bindToDataModel(new DataGroup_1.default('$form', dataModel));
70
- this.syncDataAndFormModel(this.getDataNode());
71
- this._eventQueue.runPendingQueue();
72
- }
73
- exportData() {
74
- var _a;
75
- return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
76
- }
77
- setFocus(field) {
78
- const parent = field.parent;
79
- const currentField = field;
80
- while (parent != null && parent.activeChild != currentField) {
81
- parent.activeChild = currentField;
82
- }
83
- }
84
- /**
85
- * Returns the current state of the form
86
- *
87
- * To access the form data and attachments, one needs to use the `data` and `attachments` property.
88
- * For example,
89
- * ```
90
- * const data = form.getState().data
91
- * const attachments = form.getState().attachments
92
- * ```
93
- */
94
- getState() {
95
- // eslint-disable-next-line @typescript-eslint/no-this-alias
96
- const self = this;
97
- const res = super.getState();
98
- res.id = '$form';
99
- Object.defineProperty(res, 'data', {
100
- get: function () {
101
- return self.exportData();
102
- }
103
- });
104
- Object.defineProperty(res, 'attachments', {
105
- get: function () {
106
- return (0, FormUtils_1.getAttachments)(self);
107
- }
108
- });
109
- return res;
110
- }
111
- get type() {
112
- return 'object';
113
- }
114
- isTransparent() {
115
- return false;
116
- }
117
- get form() {
118
- return this;
119
- }
120
- get ruleEngine() {
121
- return this._ruleEngine;
122
- }
123
- getUniqueId() {
124
- if (this._ids == null) {
125
- return '';
126
- }
127
- return this._ids.next().value;
128
- }
129
- /**
130
- * @param field
131
- * @private
132
- */
133
- fieldAdded(field) {
134
- this._fields[field.id] = field;
135
- field.subscribe((action) => {
136
- if (this._invalidFields.indexOf(action.target.id) === -1) {
137
- this._invalidFields.push(action.target.id);
138
- }
139
- }, 'invalid');
140
- field.subscribe((action) => {
141
- const index = this._invalidFields.indexOf(action.target.id);
142
- if (index > -1) {
143
- this._invalidFields.splice(index, 1);
144
- }
145
- }, 'valid');
146
- field.subscribe((action) => {
147
- //@ts-ignore
148
- const field = action.target.getState();
149
- if (field) {
150
- const fieldChangedAction = new controller_1.FieldChanged(action.payload.changes, field);
151
- this.dispatch(fieldChangedAction);
152
- }
153
- });
154
- }
155
- /**
156
- * visits each element in the form
157
- * @param callBack a function which is invoked on each form element
158
- * (including container type elements) visited
159
- */
160
- visit(callBack) {
161
- this.traverseChild(this, callBack);
162
- }
163
- /**
164
- *
165
- * @param container
166
- * @param callBack
167
- * @private
168
- */
169
- traverseChild(container, callBack) {
170
- container.items.forEach((field) => {
171
- if (field.isContainer) {
172
- this.traverseChild(field, callBack);
173
- }
174
- callBack(field);
175
- });
176
- }
177
- validate() {
178
- const validationErrors = super.validate();
179
- // trigger event on form so that user's can customize their application
180
- this.dispatch(new controller_1.ValidationComplete(validationErrors));
181
- return validationErrors;
182
- }
183
- /**
184
- * Checks if the given form is valid or not
185
- * @returns `true`, if form is valid, `false` otherwise
186
- */
187
- isValid() {
188
- return this._invalidFields.length === 0;
189
- }
190
- /**
191
- * @param field
192
- * @private
193
- */
194
- dispatch(action) {
195
- if (action.type === 'submit') {
196
- super.queueEvent(action);
197
- this._eventQueue.runPendingQueue();
198
- }
199
- else {
200
- super.dispatch(action);
201
- }
202
- }
203
- /**
204
- * @param action
205
- * @private
206
- */
207
- executeAction(action) {
208
- if ((action.type !== 'submit') || this._invalidFields.length === 0) {
209
- super.executeAction(action);
210
- }
211
- }
212
- /**
213
- * @param action
214
- * @param context
215
- * @private
216
- */
217
- submit(action, context) {
218
- // if no errors, only then submit
219
- if (this.validate().length === 0) {
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);
222
- }
223
- }
224
- getElement(id) {
225
- if (id == this.id) {
226
- return this;
227
- }
228
- return this._fields[id];
229
- }
230
- get qualifiedName() {
231
- return '$form';
232
- }
233
- /**
234
- * @private
235
- */
236
- getEventQueue() {
237
- return this._eventQueue;
238
- }
239
- get name() {
240
- return '$form';
241
- }
242
- get value() {
243
- return null;
244
- }
245
- get id() {
246
- return '$form';
247
- }
248
- get title() {
249
- return this._jsonModel.title || '';
250
- }
251
- }
252
- exports.default = Form;
@@ -1,38 +0,0 @@
1
- import { FormModel } from './types';
2
- import { LogLevel } from './controller/Logger';
3
- /**
4
- * Creates form instance using form model definition as per `adaptive form specification`
5
- * @param formModel form model definition
6
- * @param callback a callback that recieves the FormModel instance that gets executed before any event in the Form
7
- * is executed
8
- * @param logLevel Logging Level for the form. Setting it off will disable the logging
9
- * @param fModel existing form model, this is additional optimization to prevent creation of form instance
10
- * @returns {@link FormModel | form model}
11
- */
12
- export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
13
- /**
14
- * Validates Form model definition with the given data
15
- * @param formModel form model definition
16
- * @param data form data
17
- * @deprecated use validateFormData
18
- * @returns `true`, if form is valid against the given form data, `false` otherwise
19
- */
20
- export declare const validateFormInstance: (formModel: any, data: any) => boolean;
21
- /**
22
- * Validates Form model definition with the given data
23
- * @param formModel form model definition
24
- * @param data form data
25
- * @deprecated use validateFormData
26
- * @returns {messages: [], valid: boolean}
27
- */
28
- export declare const validateFormData: (formModel: any, data: any) => {
29
- messages: any[];
30
- valid: boolean;
31
- };
32
- /**
33
- * Helper API to fetch form model definition from an AEM instance
34
- * @param url URL of the instance
35
- * @param headers HTTP headers to pass to the aem instance
36
- * @returns promise which resolves to the form model definition
37
- */
38
- export declare const fetchForm: (url: string, headers?: any) => Promise<string>;