@aemforms/af-core 0.22.18 → 0.22.19
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.d.ts +2 -0
- package/lib/BaseNode.js +4 -0
- package/lib/Container.d.ts +8 -107
- package/lib/Container.js +28 -14
- package/lib/Field.d.ts +11 -0
- package/lib/Field.js +48 -16
- package/lib/Fieldset.d.ts +0 -10
- package/lib/Fieldset.js +3 -42
- package/lib/Form.d.ts +25 -108
- package/lib/Form.js +25 -3
- package/lib/FormInstance.js +14 -6
- package/lib/InstanceManager.d.ts +16 -0
- package/lib/InstanceManager.js +53 -0
- package/lib/Scriptable.js +3 -3
- package/lib/controller/Controller.d.ts +32 -0
- package/lib/controller/Controller.js +42 -1
- package/lib/data/DataGroup.js +5 -1
- package/lib/data/DataValue.d.ts +1 -1
- package/lib/data/DataValue.js +4 -0
- package/lib/rules/FunctionRuntime.js +6 -0
- package/lib/types/Json.d.ts +3 -0
- package/lib/types/Model.d.ts +15 -1
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +67 -9
- package/lib/utils/FormCreationUtils.d.ts +11 -0
- package/lib/utils/FormCreationUtils.js +83 -0
- package/lib/utils/JsonUtils.d.ts +1 -0
- package/lib/utils/JsonUtils.js +15 -1
- package/package.json +2 -2
package/lib/Form.js
CHANGED
|
@@ -12,10 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
const Container_1 = __importDefault(require("./Container"));
|
|
14
14
|
const FormMetaData_1 = __importDefault(require("./FormMetaData"));
|
|
15
|
-
const Fieldset_1 = require("./Fieldset");
|
|
16
15
|
const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
|
|
17
16
|
const Logger_1 = require("./controller/Logger");
|
|
18
17
|
const FormUtils_1 = require("./utils/FormUtils");
|
|
18
|
+
const FormCreationUtils_1 = require("./utils/FormCreationUtils");
|
|
19
19
|
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
20
20
|
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
21
21
|
const controller_1 = require("./controller");
|
|
@@ -63,7 +63,7 @@ class Form extends Container_1.default {
|
|
|
63
63
|
return this._jsonModel.action;
|
|
64
64
|
}
|
|
65
65
|
_createChild(child) {
|
|
66
|
-
return (0,
|
|
66
|
+
return (0, FormCreationUtils_1.createChild)(child, { form: this, parent: this });
|
|
67
67
|
}
|
|
68
68
|
importData(dataModel) {
|
|
69
69
|
this._bindToDataModel(new DataGroup_1.default('$form', dataModel));
|
|
@@ -152,6 +152,28 @@ class Form extends Container_1.default {
|
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
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
|
+
}
|
|
155
177
|
validate() {
|
|
156
178
|
const validationErrors = super.validate();
|
|
157
179
|
// trigger event on form so that user's can customize their application
|
|
@@ -183,7 +205,7 @@ class Form extends Container_1.default {
|
|
|
183
205
|
* @private
|
|
184
206
|
*/
|
|
185
207
|
executeAction(action) {
|
|
186
|
-
if (action.type !== 'submit' || this._invalidFields.length === 0) {
|
|
208
|
+
if ((action.type !== 'submit') || this._invalidFields.length === 0) {
|
|
187
209
|
super.executeAction(action);
|
|
188
210
|
}
|
|
189
211
|
}
|
package/lib/FormInstance.js
CHANGED
|
@@ -108,12 +108,20 @@ const fetchForm = (url, headers = {}) => {
|
|
|
108
108
|
Object.entries(headers).forEach(([key, value]) => {
|
|
109
109
|
headerObj.append(key, value);
|
|
110
110
|
});
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
(0, Fetch_1.request)(`${url}.model.json`, null, { headers }).then((response) => {
|
|
113
|
+
if (response.status !== 200) {
|
|
114
|
+
reject('Not Found');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
let formObj = response.body;
|
|
118
|
+
if ('model' in formObj) {
|
|
119
|
+
const { model } = formObj;
|
|
120
|
+
formObj = model;
|
|
121
|
+
}
|
|
122
|
+
resolve((0, JsonUtils_1.jsonString)(formObj));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
117
125
|
});
|
|
118
126
|
};
|
|
119
127
|
exports.fetchForm = fetchForm;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Action, FieldJson, FieldModel, FieldsetJson, FieldsetModel } from './types';
|
|
2
|
+
import { Fieldset } from './Fieldset';
|
|
3
|
+
export declare class InstanceManager extends Fieldset implements FieldsetModel {
|
|
4
|
+
get maxOccur(): number;
|
|
5
|
+
set maxOccur(m: number);
|
|
6
|
+
get minOccur(): number;
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
addInstance(action: Action): void;
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
removeInstance(action: Action): void;
|
|
15
|
+
protected _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.InstanceManager = void 0;
|
|
17
|
+
const Fieldset_1 = require("./Fieldset");
|
|
18
|
+
const BaseNode_1 = require("./BaseNode");
|
|
19
|
+
const FormCreationUtils_1 = require("./utils/FormCreationUtils");
|
|
20
|
+
class InstanceManager extends Fieldset_1.Fieldset {
|
|
21
|
+
get maxOccur() {
|
|
22
|
+
return this._jsonModel.maxItems;
|
|
23
|
+
}
|
|
24
|
+
set maxOccur(m) {
|
|
25
|
+
this.maxItems = m;
|
|
26
|
+
}
|
|
27
|
+
get minOccur() {
|
|
28
|
+
return this.minItems;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
addInstance(action) {
|
|
34
|
+
return this.addItem(action);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
removeInstance(action) {
|
|
40
|
+
return this.removeItem(action);
|
|
41
|
+
}
|
|
42
|
+
_createChild(child, options) {
|
|
43
|
+
const { parent = this } = options;
|
|
44
|
+
return (0, FormCreationUtils_1.createChild)(child, { form: this.form, parent: parent }, true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, BaseNode_1.dependencyTracked)()
|
|
49
|
+
], InstanceManager.prototype, "maxOccur", null);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, BaseNode_1.dependencyTracked)()
|
|
52
|
+
], InstanceManager.prototype, "minOccur", null);
|
|
53
|
+
exports.InstanceManager = InstanceManager;
|
package/lib/Scriptable.js
CHANGED
|
@@ -192,14 +192,14 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
192
192
|
const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
|
|
193
193
|
const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
|
|
194
194
|
const node = this.getCompiledEvent(eventName);
|
|
195
|
-
//todo: apply all the updates at the end or
|
|
196
|
-
// not trigger the change event until the execution is finished
|
|
197
|
-
node.forEach((n) => this.executeEvent(context, n));
|
|
198
195
|
// @ts-ignore
|
|
199
196
|
if (funcName in this && typeof this[funcName] === 'function') {
|
|
200
197
|
//@ts-ignore
|
|
201
198
|
this[funcName](action, context);
|
|
202
199
|
}
|
|
200
|
+
//todo: apply all the updates at the end or
|
|
201
|
+
// not trigger the change event until the execution is finished
|
|
202
|
+
node.forEach((n) => this.executeEvent(context, n));
|
|
203
203
|
this.notifyDependents(action);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -179,6 +179,18 @@ export declare class Submit extends ActionImpl {
|
|
|
179
179
|
*/
|
|
180
180
|
constructor(payload?: any, dispatch?: boolean);
|
|
181
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Implementation of `reset` event. The reset event is triggered on the Form.
|
|
184
|
+
* To trigger the reset event, reset function needs to be invoked or one can invoke dispatchEvent API.
|
|
185
|
+
*/
|
|
186
|
+
export declare class Reset extends ActionImpl {
|
|
187
|
+
/**
|
|
188
|
+
* @constructor
|
|
189
|
+
* @param [payload] event payload
|
|
190
|
+
* @param [dispatch] true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
constructor(payload?: any, dispatch?: boolean);
|
|
193
|
+
}
|
|
182
194
|
/**
|
|
183
195
|
* Implementation of `fieldChanged` event. The field changed event is triggered on the field which it has changed.
|
|
184
196
|
*/
|
|
@@ -221,3 +233,23 @@ export declare class RemoveItem extends ActionImpl {
|
|
|
221
233
|
*/
|
|
222
234
|
constructor(payload?: number);
|
|
223
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Implementation of `addInstance` event. The event is triggered on a field to add an instance of it.
|
|
238
|
+
*/
|
|
239
|
+
export declare class AddInstance extends ActionImpl {
|
|
240
|
+
/**
|
|
241
|
+
* @constructor
|
|
242
|
+
* @param [payload] event payload
|
|
243
|
+
*/
|
|
244
|
+
constructor(payload?: number);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Implementation of `removeInstance` event. The event is triggered on a field to remove an instance of it.
|
|
248
|
+
*/
|
|
249
|
+
export declare class RemoveInstance extends ActionImpl {
|
|
250
|
+
/**
|
|
251
|
+
* @constructor
|
|
252
|
+
* @param [payload] event payload
|
|
253
|
+
*/
|
|
254
|
+
constructor(payload?: number);
|
|
255
|
+
}
|
|
@@ -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.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;
|
|
10
|
+
exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = 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
|
|
@@ -226,6 +226,21 @@ class Submit extends ActionImpl {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
exports.Submit = Submit;
|
|
229
|
+
/**
|
|
230
|
+
* Implementation of `reset` event. The reset event is triggered on the Form.
|
|
231
|
+
* To trigger the reset event, reset function needs to be invoked or one can invoke dispatchEvent API.
|
|
232
|
+
*/
|
|
233
|
+
class Reset extends ActionImpl {
|
|
234
|
+
/**
|
|
235
|
+
* @constructor
|
|
236
|
+
* @param [payload] event payload
|
|
237
|
+
* @param [dispatch] true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
|
|
238
|
+
*/
|
|
239
|
+
constructor(payload, dispatch = false) {
|
|
240
|
+
super(payload, 'reset', { dispatch });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Reset = Reset;
|
|
229
244
|
/**
|
|
230
245
|
* Implementation of `fieldChanged` event. The field changed event is triggered on the field which it has changed.
|
|
231
246
|
*/
|
|
@@ -285,3 +300,29 @@ class RemoveItem extends ActionImpl {
|
|
|
285
300
|
}
|
|
286
301
|
}
|
|
287
302
|
exports.RemoveItem = RemoveItem;
|
|
303
|
+
/**
|
|
304
|
+
* Implementation of `addInstance` event. The event is triggered on a field to add an instance of it.
|
|
305
|
+
*/
|
|
306
|
+
class AddInstance extends ActionImpl {
|
|
307
|
+
/**
|
|
308
|
+
* @constructor
|
|
309
|
+
* @param [payload] event payload
|
|
310
|
+
*/
|
|
311
|
+
constructor(payload) {
|
|
312
|
+
super(payload, 'addInstance');
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.AddInstance = AddInstance;
|
|
316
|
+
/**
|
|
317
|
+
* Implementation of `removeInstance` event. The event is triggered on a field to remove an instance of it.
|
|
318
|
+
*/
|
|
319
|
+
class RemoveInstance extends ActionImpl {
|
|
320
|
+
/**
|
|
321
|
+
* @constructor
|
|
322
|
+
* @param [payload] event payload
|
|
323
|
+
*/
|
|
324
|
+
constructor(payload) {
|
|
325
|
+
super(payload, 'removeInstance');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.RemoveInstance = RemoveInstance;
|
package/lib/data/DataGroup.js
CHANGED
|
@@ -42,7 +42,11 @@ class DataGroup extends DataValue_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
get $value() {
|
|
45
|
-
|
|
45
|
+
const enabled = this.$_fields.find(x => x.enabled !== false);
|
|
46
|
+
if (!enabled && this.$_fields.length) {
|
|
47
|
+
return this.$type === 'array' ? [] : {};
|
|
48
|
+
}
|
|
49
|
+
else if (this.$type === 'array') {
|
|
46
50
|
return Object.values(this.$_items).filter(x => typeof x !== 'undefined').map(x => x.$value);
|
|
47
51
|
}
|
|
48
52
|
else {
|
package/lib/data/DataValue.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export default class DataValue {
|
|
|
9
9
|
private $_name;
|
|
10
10
|
private $_value;
|
|
11
11
|
private $_type;
|
|
12
|
-
|
|
12
|
+
$_fields: Array<FieldModel>;
|
|
13
13
|
constructor($_name: string | number, $_value: any, $_type?: string);
|
|
14
14
|
valueOf(): any;
|
|
15
15
|
get $name(): string | number;
|
package/lib/data/DataValue.js
CHANGED
|
@@ -24,6 +24,10 @@ class DataValue {
|
|
|
24
24
|
return this.$_name;
|
|
25
25
|
}
|
|
26
26
|
get $value() {
|
|
27
|
+
const enabled = this.$_fields.find(x => x.enabled !== false);
|
|
28
|
+
if (!enabled && this.$_fields.length) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
27
31
|
return this.$_value;
|
|
28
32
|
}
|
|
29
33
|
setValue(typedValue, originalValue, fromField) {
|
|
@@ -191,6 +191,12 @@ const createAction = (name, payload = {}) => {
|
|
|
191
191
|
return new Controller_1.AddItem(payload);
|
|
192
192
|
case 'removeItem':
|
|
193
193
|
return new Controller_1.RemoveItem(payload);
|
|
194
|
+
case 'reset':
|
|
195
|
+
return new Controller_1.Reset(payload);
|
|
196
|
+
case 'addInstance':
|
|
197
|
+
return new Controller_1.AddInstance(payload);
|
|
198
|
+
case 'removeInstance':
|
|
199
|
+
return new Controller_1.RemoveInstance(payload);
|
|
194
200
|
default:
|
|
195
201
|
console.error('invalid action');
|
|
196
202
|
}
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
|
29
29
|
maxLength?: number;
|
|
30
30
|
maximum?: number;
|
|
31
31
|
maxItems?: number;
|
|
32
|
+
minOccur?: number;
|
|
33
|
+
maxOccur?: number;
|
|
32
34
|
minLength?: number;
|
|
33
35
|
minimum?: number;
|
|
34
36
|
minItems?: number;
|
|
@@ -82,6 +84,7 @@ export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson
|
|
|
82
84
|
properties?: {
|
|
83
85
|
[key: string]: any;
|
|
84
86
|
};
|
|
87
|
+
repeatable?: boolean;
|
|
85
88
|
screenReaderText?: string;
|
|
86
89
|
tooltip?: string;
|
|
87
90
|
altText?: string;
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface WithState<T> {
|
|
|
37
37
|
/**
|
|
38
38
|
* {@link State | state} of the form object
|
|
39
39
|
*/
|
|
40
|
-
getState: () =>
|
|
40
|
+
getState: () => any;
|
|
41
41
|
}
|
|
42
42
|
declare type stateProps = {
|
|
43
43
|
id: string;
|
|
@@ -191,11 +191,19 @@ export interface BaseModel extends ConstraintsJson, WithController {
|
|
|
191
191
|
* Default value of the Field.
|
|
192
192
|
*/
|
|
193
193
|
readonly default?: any;
|
|
194
|
+
/**
|
|
195
|
+
* Field is repeatable or not
|
|
196
|
+
*/
|
|
197
|
+
readonly repeatable?: boolean;
|
|
194
198
|
/**
|
|
195
199
|
* Validates the given form field
|
|
196
200
|
* @returns list of {@link ValidationError | validation errors}
|
|
197
201
|
*/
|
|
198
202
|
validate(): Array<ValidationError>;
|
|
203
|
+
/**
|
|
204
|
+
* Resets the form model
|
|
205
|
+
*/
|
|
206
|
+
reset(): any;
|
|
199
207
|
/**
|
|
200
208
|
* Imports data to the form field
|
|
201
209
|
* @private
|
|
@@ -333,6 +341,12 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
|
|
|
333
341
|
* @private
|
|
334
342
|
*/
|
|
335
343
|
getEventQueue(): EventQueue;
|
|
344
|
+
/**
|
|
345
|
+
* visits each element in the form
|
|
346
|
+
* @param callBack a function which is invoked on each form element
|
|
347
|
+
* (including container type elements) visited
|
|
348
|
+
*/
|
|
349
|
+
visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
|
|
336
350
|
}
|
|
337
351
|
/**
|
|
338
352
|
* Defines file object interface.
|
package/lib/utils/Fetch.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param url
|
|
4
|
+
* @param data
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
1
7
|
export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
|
|
2
8
|
export declare type RequestOptions = {
|
|
3
9
|
contentType?: string;
|
|
@@ -5,3 +11,4 @@ export declare type RequestOptions = {
|
|
|
5
11
|
headers?: any;
|
|
6
12
|
mode?: string;
|
|
7
13
|
};
|
|
14
|
+
export declare const convertQueryString: (endpoint: string, payload: string | null) => string;
|
package/lib/utils/Fetch.js
CHANGED
|
@@ -6,24 +6,82 @@
|
|
|
6
6
|
*
|
|
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
|
+
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
|
+
};
|
|
9
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.request = void 0;
|
|
19
|
+
exports.convertQueryString = exports.request = void 0;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param url
|
|
23
|
+
* @param data
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
11
26
|
const request = (url, data = null, options = {}) => {
|
|
12
27
|
const opts = Object.assign(Object.assign({}, defaultRequestOptions), options);
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
const updatedUrl = opts.method === 'GET' && data ? (0, exports.convertQueryString)(url, data) : url;
|
|
29
|
+
if (opts.method !== 'GET') {
|
|
30
|
+
opts.body = data;
|
|
31
|
+
}
|
|
32
|
+
return fetch(updatedUrl, Object.assign({}, opts)).then((response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
let body;
|
|
15
35
|
if (!response.ok) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if ((_a = response === null || response === void 0 ? void 0 : response.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
|
|
19
|
-
return response.json();
|
|
36
|
+
console.error(`Error fetching response from ${url} : ${response.statusText}`);
|
|
37
|
+
body = response.statusText;
|
|
20
38
|
}
|
|
21
39
|
else {
|
|
22
|
-
|
|
40
|
+
if ((_b = (_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) {
|
|
41
|
+
body = yield response.json();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
body = yield response.text();
|
|
45
|
+
}
|
|
23
46
|
}
|
|
24
|
-
|
|
47
|
+
const headers = {};
|
|
48
|
+
(_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c.forEach((value, key) => {
|
|
49
|
+
headers[key] = value;
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
status: response.status,
|
|
53
|
+
body,
|
|
54
|
+
headers
|
|
55
|
+
};
|
|
56
|
+
}));
|
|
25
57
|
};
|
|
26
58
|
exports.request = request;
|
|
27
59
|
const defaultRequestOptions = {
|
|
28
60
|
method: 'GET'
|
|
29
61
|
};
|
|
62
|
+
const convertQueryString = (endpoint, payload) => {
|
|
63
|
+
if (!payload) {
|
|
64
|
+
return endpoint;
|
|
65
|
+
}
|
|
66
|
+
let updatedPayload = {};
|
|
67
|
+
try {
|
|
68
|
+
updatedPayload = JSON.parse(payload);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.log('Query params invalid');
|
|
72
|
+
}
|
|
73
|
+
const params = [];
|
|
74
|
+
Object.keys(updatedPayload).forEach((key) => {
|
|
75
|
+
if (Array.isArray(updatedPayload[key])) {
|
|
76
|
+
params.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(updatedPayload[key]))}`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
params.push(`${encodeURIComponent(key)}=${encodeURIComponent(updatedPayload[key])}`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (!params.length) {
|
|
83
|
+
return endpoint;
|
|
84
|
+
}
|
|
85
|
+
return endpoint.includes('?') ? `${endpoint}&${params.join('&')}` : `${endpoint}?${params.join('&')}`;
|
|
86
|
+
};
|
|
87
|
+
exports.convertQueryString = convertQueryString;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a child model inside the given parent
|
|
4
|
+
* @param child
|
|
5
|
+
* @param options
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare const createChild: (child: FieldsetJson | FieldJson, options: {
|
|
9
|
+
form: FormModel;
|
|
10
|
+
parent: ContainerModel;
|
|
11
|
+
}, repeatableInstance?: boolean) => FieldModel | FieldsetModel;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
10
|
+
var t = {};
|
|
11
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
12
|
+
t[p] = s[p];
|
|
13
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
14
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
15
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
16
|
+
t[p[i]] = s[p[i]];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.createChild = void 0;
|
|
25
|
+
const InstanceManager_1 = require("../InstanceManager");
|
|
26
|
+
const Fieldset_1 = require("../Fieldset");
|
|
27
|
+
const JsonUtils_1 = require("./JsonUtils");
|
|
28
|
+
const FileUpload_1 = __importDefault(require("../FileUpload"));
|
|
29
|
+
const Checkbox_1 = __importDefault(require("../Checkbox"));
|
|
30
|
+
const CheckboxGroup_1 = __importDefault(require("../CheckboxGroup"));
|
|
31
|
+
const DateField_1 = __importDefault(require("../DateField"));
|
|
32
|
+
const Field_1 = __importDefault(require("../Field"));
|
|
33
|
+
/**
|
|
34
|
+
* Creates a child model inside the given parent
|
|
35
|
+
* @param child
|
|
36
|
+
* @param options
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
const createChild = (child, options, repeatableInstance = false) => {
|
|
40
|
+
let retVal;
|
|
41
|
+
// if repeatable is set
|
|
42
|
+
if ((0, JsonUtils_1.isRepeatable)(child) && !repeatableInstance) {
|
|
43
|
+
const childItemsWithMinAndMaxOccur = Object.assign(Object.assign({}, child), ('items' in child && { 'type': 'object' }));
|
|
44
|
+
// remove minOccur and maxOccur from child items
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
|
+
const { minOccur, maxOccur } = childItemsWithMinAndMaxOccur, childItems = __rest(childItemsWithMinAndMaxOccur, ["minOccur", "maxOccur"]);
|
|
47
|
+
const newJson = Object.assign({
|
|
48
|
+
minItems: child.minOccur || 0,
|
|
49
|
+
maxItems: child.maxOccur || -1,
|
|
50
|
+
fieldType: child.fieldType,
|
|
51
|
+
type: 'array',
|
|
52
|
+
name: child.name,
|
|
53
|
+
dataRef: child.dataRef // can't destructure entire child here
|
|
54
|
+
}, {
|
|
55
|
+
'items': [childItems]
|
|
56
|
+
});
|
|
57
|
+
retVal = new InstanceManager_1.InstanceManager(newJson, options);
|
|
58
|
+
}
|
|
59
|
+
else if ('items' in child) {
|
|
60
|
+
retVal = new Fieldset_1.Fieldset(child, options);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
retVal = new FileUpload_1.default(child, options);
|
|
66
|
+
}
|
|
67
|
+
else if ((0, JsonUtils_1.isCheckbox)(child)) {
|
|
68
|
+
retVal = new Checkbox_1.default(child, options);
|
|
69
|
+
}
|
|
70
|
+
else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
|
|
71
|
+
retVal = new CheckboxGroup_1.default(child, options);
|
|
72
|
+
}
|
|
73
|
+
else if ((0, JsonUtils_1.isDateField)(child)) {
|
|
74
|
+
retVal = new DateField_1.default(child, options);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
retVal = new Field_1.default(child, options);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
options.form.fieldAdded(retVal);
|
|
81
|
+
return retVal;
|
|
82
|
+
};
|
|
83
|
+
exports.createChild = createChild;
|
package/lib/utils/JsonUtils.d.ts
CHANGED
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.isDateField = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
|
|
10
|
+
exports.isRepeatable = 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
|
*/
|
|
@@ -141,3 +141,17 @@ const jsonString = (obj) => {
|
|
|
141
141
|
return JSON.stringify(obj, null, 2);
|
|
142
142
|
};
|
|
143
143
|
exports.jsonString = jsonString;
|
|
144
|
+
const isRepeatable = (obj) => {
|
|
145
|
+
return ((obj.repeatable &&
|
|
146
|
+
// case0: both are undefined
|
|
147
|
+
((obj.minOccur === undefined && obj.maxOccur === undefined) ||
|
|
148
|
+
// case1: if minOccur is specified and maxOccur specified is not equal to zero, then it is repeatable
|
|
149
|
+
(obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
|
|
150
|
+
// case2: if both specified and both equal to zero, then it is not repeatable
|
|
151
|
+
(obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.minOccur !== 0 && obj.maxOccur !== 0) ||
|
|
152
|
+
// case3: only if minOccur is specified, then it should be greater than zero for repeatable
|
|
153
|
+
(obj.minOccur !== undefined && obj.minOccur >= 0) ||
|
|
154
|
+
// case4: only if maxOccur is specified, then it should be non-zero for repeatable
|
|
155
|
+
(obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
|
|
156
|
+
};
|
|
157
|
+
exports.isRepeatable = isRepeatable;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.19",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/json-formula": "^0.1.44",
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
38
|
+
"@aemforms/af-formatters": "^0.22.19"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^27.5.1",
|