@aemforms/af-core 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -0
- package/README.md +34 -0
- package/lib/BaseNode.d.ts +117 -0
- package/lib/BaseNode.js +368 -0
- package/lib/Checkbox.d.ts +80 -0
- package/lib/Checkbox.js +49 -0
- package/lib/CheckboxGroup.d.ts +30 -0
- package/lib/CheckboxGroup.js +40 -0
- package/lib/Container.d.ts +336 -0
- package/lib/Container.js +279 -0
- package/lib/Field.d.ts +185 -0
- package/lib/Field.js +432 -0
- package/lib/Fieldset.d.ts +31 -0
- package/lib/Fieldset.js +97 -0
- package/lib/FileObject.d.ts +17 -0
- package/lib/FileObject.js +30 -0
- package/lib/FileUpload.d.ts +42 -0
- package/lib/FileUpload.js +299 -0
- package/lib/Form.d.ts +413 -0
- package/lib/Form.js +247 -0
- package/lib/FormInstance.d.ts +26 -0
- package/lib/FormInstance.js +116 -0
- package/lib/FormMetaData.d.ts +11 -0
- package/lib/FormMetaData.js +28 -0
- package/lib/Node.d.ts +12 -0
- package/lib/Node.js +27 -0
- package/lib/Scriptable.d.ts +27 -0
- package/lib/Scriptable.js +216 -0
- package/lib/controller/Controller.d.ts +207 -0
- package/lib/controller/Controller.js +263 -0
- package/lib/controller/EventQueue.d.ts +24 -0
- package/lib/controller/EventQueue.js +99 -0
- package/lib/controller/index.d.ts +1 -0
- package/lib/controller/index.js +24 -0
- package/lib/data/DataGroup.d.ts +25 -0
- package/lib/data/DataGroup.js +74 -0
- package/lib/data/DataValue.d.ts +22 -0
- package/lib/data/DataValue.js +50 -0
- package/lib/data/EmptyDataValue.d.ts +14 -0
- package/lib/data/EmptyDataValue.js +46 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +59 -0
- package/lib/rules/FunctionRuntime.d.ts +44 -0
- package/lib/rules/FunctionRuntime.js +271 -0
- package/lib/rules/RuleEngine.d.ts +23 -0
- package/lib/rules/RuleEngine.js +67 -0
- package/lib/types/Json.d.ts +126 -0
- package/lib/types/Json.js +16 -0
- package/lib/types/Model.d.ts +352 -0
- package/lib/types/Model.js +20 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +25 -0
- package/lib/utils/DataRefParser.d.ts +30 -0
- package/lib/utils/DataRefParser.js +249 -0
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +29 -0
- package/lib/utils/FormUtils.d.ts +47 -0
- package/lib/utils/FormUtils.js +172 -0
- package/lib/utils/JsonUtils.d.ts +55 -0
- package/lib/utils/JsonUtils.js +128 -0
- package/lib/utils/LogUtils.d.ts +7 -0
- package/lib/utils/LogUtils.js +17 -0
- package/lib/utils/SchemaUtils.d.ts +16 -0
- package/lib/utils/SchemaUtils.js +92 -0
- package/lib/utils/TranslationUtils.d.ts +34 -0
- package/lib/utils/TranslationUtils.js +156 -0
- package/lib/utils/ValidationUtils.d.ts +153 -0
- package/lib/utils/ValidationUtils.js +339 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2022 Adobe, Inc.
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
The core module containing the model to interpret Adaptive Form JSON Definition and execute rules/expressions
|
|
4
|
+
specified in that.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
Save it as a dependency
|
|
9
|
+
```
|
|
10
|
+
npm i --save @aemforms/af-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Create a new Form from JSON
|
|
14
|
+
```
|
|
15
|
+
import {createFormInstance} from '@aemforms/af-core';
|
|
16
|
+
const formJson = {..}
|
|
17
|
+
const form = createFormInstance(formJson)
|
|
18
|
+
|
|
19
|
+
//import data in the form
|
|
20
|
+
form.importData({})
|
|
21
|
+
|
|
22
|
+
//export data after form is being filled by the user
|
|
23
|
+
const data = form.exportData()
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Validate form Data
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
import {validateFormInstance} from '@aemforms/af-core';
|
|
31
|
+
const formJson = {..}
|
|
32
|
+
const data = {...}
|
|
33
|
+
const valid = validateFormInstance(formJson, data)
|
|
34
|
+
```
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormModel, Primitives, ValidationError } from './types';
|
|
2
|
+
import DataGroup from './data/DataGroup';
|
|
3
|
+
import DataValue from './data/DataValue';
|
|
4
|
+
export declare const target: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Defines a generic base class which all objects of form runtime model should extend from.
|
|
7
|
+
* @typeparam T type of the form object which extends from {@link BaseJson | base type}
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class BaseNode<T extends BaseJson> implements BaseModel {
|
|
10
|
+
private _options;
|
|
11
|
+
private _ruleNode;
|
|
12
|
+
private _callbacks;
|
|
13
|
+
private _dependents;
|
|
14
|
+
protected _jsonModel: T & {
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
private _tokens;
|
|
18
|
+
get isContainer(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @constructor
|
|
21
|
+
* @param params
|
|
22
|
+
* @param _options
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
constructor(params: T, _options: {
|
|
26
|
+
form: FormModel;
|
|
27
|
+
parent: ContainerModel;
|
|
28
|
+
});
|
|
29
|
+
abstract value: Primitives;
|
|
30
|
+
protected setupRuleNode(): void;
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
ruleNodeReference(): this;
|
|
35
|
+
/**
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
getRuleNode(): any;
|
|
39
|
+
private getFromRule;
|
|
40
|
+
get id(): string;
|
|
41
|
+
get index(): number;
|
|
42
|
+
get parent(): ContainerModel;
|
|
43
|
+
get type(): string | undefined;
|
|
44
|
+
get fieldType(): string;
|
|
45
|
+
get ':type'(): string;
|
|
46
|
+
get name(): string | undefined;
|
|
47
|
+
get description(): string | undefined;
|
|
48
|
+
set description(d: string | undefined);
|
|
49
|
+
get dataRef(): string | null | undefined;
|
|
50
|
+
get visible(): boolean | undefined;
|
|
51
|
+
set visible(v: boolean | undefined);
|
|
52
|
+
get form(): FormModel;
|
|
53
|
+
get ruleEngine(): import("./rules/RuleEngine").default;
|
|
54
|
+
get label(): import("./types").Label | undefined;
|
|
55
|
+
set label(l: import("./types").Label | undefined);
|
|
56
|
+
/**
|
|
57
|
+
* Transparent form fields are meant only for creation of view. They are also not part of data
|
|
58
|
+
*/
|
|
59
|
+
isTransparent(): boolean;
|
|
60
|
+
getState(): T & {
|
|
61
|
+
':type': string;
|
|
62
|
+
id: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
subscribe(callback: callbackFn, eventName?: string): {
|
|
68
|
+
unsubscribe: () => void;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
addDependent(action: Action): void;
|
|
74
|
+
/**
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
removeDependent(action: Action): void;
|
|
78
|
+
abstract validate(): Array<ValidationError>;
|
|
79
|
+
abstract executeAction(action: Action): any;
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
queueEvent(action: Action): void;
|
|
84
|
+
dispatch(action: Action): void;
|
|
85
|
+
/**
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
notifyDependents(action: Action): void;
|
|
89
|
+
/**
|
|
90
|
+
* @param prop
|
|
91
|
+
* @param newValue
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
_setProperty<T>(prop: string, newValue: T, notify?: boolean): any;
|
|
95
|
+
/**
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
_bindToDataModel(contextualDataModel?: DataGroup): void;
|
|
99
|
+
private _data?;
|
|
100
|
+
/**
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
getDataNode(): DataValue | undefined;
|
|
104
|
+
get properties(): {
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
};
|
|
107
|
+
set properties(p: {
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
});
|
|
110
|
+
abstract defaultDataModel(name: string | number): DataValue | undefined;
|
|
111
|
+
abstract importData(a: DataGroup): any;
|
|
112
|
+
/**
|
|
113
|
+
* called after the node is inserted in the parent
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
_initialize(): void;
|
|
117
|
+
}
|
package/lib/BaseNode.js
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
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.BaseNode = exports.target = void 0;
|
|
14
|
+
const controller_1 = require("./controller");
|
|
15
|
+
const DataRefParser_1 = require("./utils/DataRefParser");
|
|
16
|
+
const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
|
|
17
|
+
/**
|
|
18
|
+
* Implementation of action with target
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
class ActionImplWithTarget {
|
|
22
|
+
/**
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param _action
|
|
25
|
+
* @param _target
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
constructor(_action, _target) {
|
|
29
|
+
this._action = _action;
|
|
30
|
+
this._target = _target;
|
|
31
|
+
}
|
|
32
|
+
get type() {
|
|
33
|
+
return this._action.type;
|
|
34
|
+
}
|
|
35
|
+
get payload() {
|
|
36
|
+
return this._action.payload;
|
|
37
|
+
}
|
|
38
|
+
get metadata() {
|
|
39
|
+
return this._action.metadata;
|
|
40
|
+
}
|
|
41
|
+
get target() {
|
|
42
|
+
return this._target;
|
|
43
|
+
}
|
|
44
|
+
get isCustomEvent() {
|
|
45
|
+
return this._action.isCustomEvent;
|
|
46
|
+
}
|
|
47
|
+
get originalAction() {
|
|
48
|
+
return this._action.originalAction;
|
|
49
|
+
}
|
|
50
|
+
toString() {
|
|
51
|
+
return this._action.toString();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.target = Symbol('target');
|
|
55
|
+
/**
|
|
56
|
+
* Defines a generic base class which all objects of form runtime model should extend from.
|
|
57
|
+
* @typeparam T type of the form object which extends from {@link BaseJson | base type}
|
|
58
|
+
*/
|
|
59
|
+
class BaseNode {
|
|
60
|
+
/**
|
|
61
|
+
* @constructor
|
|
62
|
+
* @param params
|
|
63
|
+
* @param _options
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
constructor(params,
|
|
67
|
+
//@ts_ignore
|
|
68
|
+
_options) {
|
|
69
|
+
this._options = _options;
|
|
70
|
+
this._callbacks = {};
|
|
71
|
+
this._dependents = [];
|
|
72
|
+
this._tokens = [];
|
|
73
|
+
this._jsonModel = Object.assign(Object.assign({}, params), {
|
|
74
|
+
//@ts-ignore
|
|
75
|
+
id: 'id' in params ? params.id : this.form.getUniqueId() });
|
|
76
|
+
}
|
|
77
|
+
get isContainer() {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
setupRuleNode() {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
82
|
+
const self = this;
|
|
83
|
+
this._ruleNode = new Proxy(this.ruleNodeReference(), {
|
|
84
|
+
get: (ruleNodeReference, prop) => {
|
|
85
|
+
return self.getFromRule(ruleNodeReference, prop);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
ruleNodeReference() {
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
getRuleNode() {
|
|
99
|
+
return this._ruleNode;
|
|
100
|
+
}
|
|
101
|
+
getFromRule(ruleNodeReference, prop) {
|
|
102
|
+
if (prop === Symbol.toPrimitive || (prop === 'valueOf' && !ruleNodeReference.hasOwnProperty('valueOf'))) {
|
|
103
|
+
return this.valueOf;
|
|
104
|
+
}
|
|
105
|
+
else if (prop === exports.target) {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
else if (typeof (prop) === 'string') {
|
|
109
|
+
//look for property
|
|
110
|
+
if (prop.startsWith('$')) {
|
|
111
|
+
prop = prop.substr(1);
|
|
112
|
+
//@todo: create a list of properties that are allowed
|
|
113
|
+
//@ts-ignore
|
|
114
|
+
// return only non functional properties in this object
|
|
115
|
+
if (typeof this[prop] !== 'function') {
|
|
116
|
+
//@ts-ignore
|
|
117
|
+
return this[prop];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
//look in the items
|
|
122
|
+
if (ruleNodeReference.hasOwnProperty(prop)) {
|
|
123
|
+
return ruleNodeReference[prop];
|
|
124
|
+
}
|
|
125
|
+
else if (typeof ruleNodeReference[prop] === 'function') { //todo : create allow list of functions
|
|
126
|
+
//to support panel instanceof Array panel1.map(..)
|
|
127
|
+
return ruleNodeReference[prop];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
get id() {
|
|
133
|
+
return this._jsonModel.id;
|
|
134
|
+
}
|
|
135
|
+
get index() {
|
|
136
|
+
return this.parent.indexOf(this);
|
|
137
|
+
}
|
|
138
|
+
get parent() {
|
|
139
|
+
return this._options.parent;
|
|
140
|
+
}
|
|
141
|
+
get type() {
|
|
142
|
+
return this._jsonModel.type;
|
|
143
|
+
}
|
|
144
|
+
get fieldType() {
|
|
145
|
+
return this._jsonModel.fieldType || 'text-input';
|
|
146
|
+
}
|
|
147
|
+
get ':type'() {
|
|
148
|
+
return this._jsonModel[':type'] || this.fieldType;
|
|
149
|
+
}
|
|
150
|
+
get name() {
|
|
151
|
+
return this._jsonModel.name;
|
|
152
|
+
}
|
|
153
|
+
get description() {
|
|
154
|
+
return this._jsonModel.description;
|
|
155
|
+
}
|
|
156
|
+
set description(d) {
|
|
157
|
+
this._setProperty('description', d);
|
|
158
|
+
}
|
|
159
|
+
get dataRef() {
|
|
160
|
+
return this._jsonModel.dataRef;
|
|
161
|
+
}
|
|
162
|
+
get visible() {
|
|
163
|
+
return this._jsonModel.visible;
|
|
164
|
+
}
|
|
165
|
+
set visible(v) {
|
|
166
|
+
if (v !== this._jsonModel.visible) {
|
|
167
|
+
const changeAction = (0, controller_1.propertyChange)('visible', v, this._jsonModel.visible);
|
|
168
|
+
this._jsonModel.visible = v;
|
|
169
|
+
this.notifyDependents(changeAction);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
get form() {
|
|
173
|
+
return this._options.form;
|
|
174
|
+
}
|
|
175
|
+
get ruleEngine() {
|
|
176
|
+
return this.form.ruleEngine;
|
|
177
|
+
}
|
|
178
|
+
get label() {
|
|
179
|
+
return this._jsonModel.label;
|
|
180
|
+
}
|
|
181
|
+
set label(l) {
|
|
182
|
+
if (l !== this._jsonModel.label) {
|
|
183
|
+
const changeAction = (0, controller_1.propertyChange)('label', l, this._jsonModel.label);
|
|
184
|
+
this._jsonModel = Object.assign(Object.assign({}, this._jsonModel), { label: l });
|
|
185
|
+
this.notifyDependents(changeAction);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Transparent form fields are meant only for creation of view. They are also not part of data
|
|
190
|
+
*/
|
|
191
|
+
isTransparent() {
|
|
192
|
+
var _a, _b;
|
|
193
|
+
// named form fields are not transparent
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
// handling repeatable use-case where first item of array can be unnamed
|
|
196
|
+
const isNonTransparent = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a._jsonModel.type) === 'array' && ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.items.length) === 1;
|
|
197
|
+
return !this._jsonModel.name && !isNonTransparent;
|
|
198
|
+
}
|
|
199
|
+
getState() {
|
|
200
|
+
return Object.assign(Object.assign({}, this._jsonModel), { ':type': this[':type'] });
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
subscribe(callback, eventName = 'change') {
|
|
206
|
+
this._callbacks[eventName] = this._callbacks[eventName] || [];
|
|
207
|
+
this._callbacks[eventName].push(callback);
|
|
208
|
+
//console.log(`subscription added : ${this._elem.id}, count : ${this._callbacks[eventName].length}`);
|
|
209
|
+
return {
|
|
210
|
+
unsubscribe: () => {
|
|
211
|
+
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
|
|
212
|
+
//console.log(`subscription removed : ${this._elem.id}, count : ${this._callbacks[eventName].length}`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
addDependent(action) {
|
|
220
|
+
if (this._dependents.find(({ node }) => node === action.payload) === undefined) {
|
|
221
|
+
const subscription = this.subscribe((change) => {
|
|
222
|
+
const changes = change.payload.changes;
|
|
223
|
+
const propsToLook = ['value', 'items'];
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
const isPropChanged = changes.findIndex(x => {
|
|
226
|
+
return propsToLook.indexOf(x.propertyName) > -1;
|
|
227
|
+
}) > -1;
|
|
228
|
+
if (isPropChanged) {
|
|
229
|
+
action.payload.dispatch(new controller_1.ExecuteRule());
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
this._dependents.push({ node: action.payload, subscription });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* @private
|
|
237
|
+
*/
|
|
238
|
+
removeDependent(action) {
|
|
239
|
+
const index = this._dependents.findIndex(({ node }) => node === action.payload);
|
|
240
|
+
if (index > -1) {
|
|
241
|
+
this._dependents[index].subscription.unsubscribe();
|
|
242
|
+
this._dependents.splice(index, 1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
queueEvent(action) {
|
|
249
|
+
const actionWithTarget = new ActionImplWithTarget(action, this);
|
|
250
|
+
this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
|
|
251
|
+
}
|
|
252
|
+
dispatch(action) {
|
|
253
|
+
this.queueEvent(action);
|
|
254
|
+
this.form.getEventQueue().runPendingQueue();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* @private
|
|
258
|
+
*/
|
|
259
|
+
notifyDependents(action) {
|
|
260
|
+
const handlers = this._callbacks[action.type] || [];
|
|
261
|
+
handlers.forEach(x => {
|
|
262
|
+
x(new ActionImplWithTarget(action, this));
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @param prop
|
|
267
|
+
* @param newValue
|
|
268
|
+
* @private
|
|
269
|
+
*/
|
|
270
|
+
_setProperty(prop, newValue, notify = true) {
|
|
271
|
+
//@ts-ignore
|
|
272
|
+
const oldValue = this._jsonModel[prop];
|
|
273
|
+
let isValueSame = false;
|
|
274
|
+
if (newValue !== null && oldValue !== null &&
|
|
275
|
+
typeof newValue === 'object' && typeof oldValue === 'object') {
|
|
276
|
+
isValueSame = JSON.stringify(newValue) === JSON.stringify(oldValue);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// @ts-ignore
|
|
280
|
+
isValueSame = oldValue === newValue;
|
|
281
|
+
}
|
|
282
|
+
if (!isValueSame) {
|
|
283
|
+
//@ts-ignore
|
|
284
|
+
this._jsonModel[prop] = newValue;
|
|
285
|
+
const changeAction = (0, controller_1.propertyChange)(prop, newValue, oldValue);
|
|
286
|
+
if (notify) {
|
|
287
|
+
this.notifyDependents(changeAction);
|
|
288
|
+
}
|
|
289
|
+
return changeAction.payload.changes;
|
|
290
|
+
}
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
_bindToDataModel(contextualDataModel) {
|
|
297
|
+
if (this.id === '$form') {
|
|
298
|
+
this._data = contextualDataModel;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const dataRef = this._jsonModel.dataRef;
|
|
302
|
+
let _data;
|
|
303
|
+
if (dataRef === null) {
|
|
304
|
+
_data = EmptyDataValue_1.default;
|
|
305
|
+
}
|
|
306
|
+
else if (dataRef !== undefined) {
|
|
307
|
+
if (this._tokens.length === 0) {
|
|
308
|
+
this._tokens = (0, DataRefParser_1.tokenize)(dataRef);
|
|
309
|
+
}
|
|
310
|
+
let searchData = contextualDataModel;
|
|
311
|
+
if (this._tokens[0].type === DataRefParser_1.TOK_GLOBAL) {
|
|
312
|
+
searchData = this.form.getDataNode();
|
|
313
|
+
}
|
|
314
|
+
if (typeof searchData !== 'undefined') {
|
|
315
|
+
const name = this._tokens[this._tokens.length - 1].value;
|
|
316
|
+
const create = this.defaultDataModel(name);
|
|
317
|
+
_data = (0, DataRefParser_1.resolveData)(searchData, this._tokens, create);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
if (contextualDataModel != null) {
|
|
322
|
+
const name = this._jsonModel.name || '';
|
|
323
|
+
const key = contextualDataModel.$type === 'array' ? this.index : name;
|
|
324
|
+
if (key !== '') {
|
|
325
|
+
const create = this.defaultDataModel(key);
|
|
326
|
+
if (create !== undefined) {
|
|
327
|
+
_data = contextualDataModel.$getDataNode(key) || create;
|
|
328
|
+
contextualDataModel.$addDataNode(key, _data);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
_data = EmptyDataValue_1.default;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!this.isContainer) {
|
|
337
|
+
_data = _data === null || _data === void 0 ? void 0 : _data.$convertToDataValue();
|
|
338
|
+
}
|
|
339
|
+
_data === null || _data === void 0 ? void 0 : _data.$bindToField(this);
|
|
340
|
+
this._data = _data;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* @private
|
|
344
|
+
*/
|
|
345
|
+
getDataNode() {
|
|
346
|
+
if (this._data === undefined) {
|
|
347
|
+
return this.parent.getDataNode();
|
|
348
|
+
}
|
|
349
|
+
return this._data;
|
|
350
|
+
}
|
|
351
|
+
get properties() {
|
|
352
|
+
return this._jsonModel.properties || {};
|
|
353
|
+
}
|
|
354
|
+
set properties(p) {
|
|
355
|
+
this._setProperty('properties', Object.assign({}, p));
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* called after the node is inserted in the parent
|
|
359
|
+
* @private
|
|
360
|
+
*/
|
|
361
|
+
_initialize() {
|
|
362
|
+
if (typeof this._data === 'undefined') {
|
|
363
|
+
const dataNode = this.parent.getDataNode();
|
|
364
|
+
this._bindToDataModel(dataNode);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
exports.BaseNode = BaseNode;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import Field from './Field';
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
4
|
+
*/
|
|
5
|
+
declare class Checkbox extends Field {
|
|
6
|
+
private offValue;
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
_getConstraintObject(): {
|
|
11
|
+
type: (constraint: string, inputVal: any) => {
|
|
12
|
+
valid: boolean;
|
|
13
|
+
value: any;
|
|
14
|
+
};
|
|
15
|
+
format: (constraint: string, input: string) => {
|
|
16
|
+
valid: boolean;
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
minimum: (constraint: number, value: number) => {
|
|
20
|
+
valid: boolean;
|
|
21
|
+
value: number;
|
|
22
|
+
};
|
|
23
|
+
maximum: (constraint: number, value: number) => {
|
|
24
|
+
valid: boolean;
|
|
25
|
+
value: number;
|
|
26
|
+
};
|
|
27
|
+
exclusiveMinimum: (constraint: number, value: number) => {
|
|
28
|
+
valid: boolean;
|
|
29
|
+
value: number;
|
|
30
|
+
};
|
|
31
|
+
exclusiveMaximum: (constraint: number, value: number) => {
|
|
32
|
+
valid: boolean;
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
minItems: <T>(constraint: number, value: T[]) => {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
value: T[];
|
|
38
|
+
};
|
|
39
|
+
maxItems: <T_1>(constraint: number, value: T_1[]) => {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
value: T_1[];
|
|
42
|
+
};
|
|
43
|
+
uniqueItems: <T_2>(constraint: boolean, value: T_2[]) => {
|
|
44
|
+
valid: boolean;
|
|
45
|
+
value: T_2[];
|
|
46
|
+
};
|
|
47
|
+
minLength: (constraint: number, value: string) => {
|
|
48
|
+
value: string;
|
|
49
|
+
valid: boolean;
|
|
50
|
+
};
|
|
51
|
+
maxLength: (constraint: number, value: string) => {
|
|
52
|
+
value: string;
|
|
53
|
+
valid: boolean;
|
|
54
|
+
};
|
|
55
|
+
pattern: (constraint: string | RegExp, value: string) => {
|
|
56
|
+
valid: boolean;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
required: (constraint: boolean, value: any) => {
|
|
60
|
+
valid: boolean;
|
|
61
|
+
value: any;
|
|
62
|
+
};
|
|
63
|
+
enum: (constraint: any[], value: any) => {
|
|
64
|
+
valid: boolean;
|
|
65
|
+
value: any;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
protected _getDefaults(): {
|
|
69
|
+
enforceEnum: boolean;
|
|
70
|
+
readOnly: boolean;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
visible: boolean;
|
|
73
|
+
type: string | undefined;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Returns the `enum` constraints from the json
|
|
77
|
+
*/
|
|
78
|
+
get enum(): any[];
|
|
79
|
+
}
|
|
80
|
+
export default Checkbox;
|
package/lib/Checkbox.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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 Field_1 = __importDefault(require("./Field"));
|
|
14
|
+
const ValidationUtils_1 = require("./utils/ValidationUtils");
|
|
15
|
+
/**
|
|
16
|
+
* @param offValue
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
const requiredConstraint = (offValue) => (constraint, value) => {
|
|
20
|
+
const valid = ValidationUtils_1.Constraints.required(constraint, value) && (!constraint || value != offValue);
|
|
21
|
+
return { valid, value };
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
25
|
+
*/
|
|
26
|
+
class Checkbox extends Field_1.default {
|
|
27
|
+
offValue() {
|
|
28
|
+
const opts = this.enum;
|
|
29
|
+
return opts.length > 1 ? opts[1] : null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
_getConstraintObject() {
|
|
35
|
+
const baseConstraints = Object.assign({}, super._getConstraintObject());
|
|
36
|
+
baseConstraints.required = requiredConstraint(this.offValue());
|
|
37
|
+
return baseConstraints;
|
|
38
|
+
}
|
|
39
|
+
_getDefaults() {
|
|
40
|
+
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the `enum` constraints from the json
|
|
44
|
+
*/
|
|
45
|
+
get enum() {
|
|
46
|
+
return this._jsonModel.enum || [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = Checkbox;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Field from './Field';
|
|
2
|
+
import { ContainerModel, FieldJson, FormModel } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of CheckBoxGroup runtime model which extends from {@link Field | field}
|
|
5
|
+
*/
|
|
6
|
+
declare class CheckboxGroup extends Field {
|
|
7
|
+
/**
|
|
8
|
+
* @param params
|
|
9
|
+
* @param _options
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
constructor(params: FieldJson, _options: {
|
|
13
|
+
form: FormModel;
|
|
14
|
+
parent: ContainerModel;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* converts the fallback type, if required, to an array. Since checkbox-group has an array type
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
protected _getFallbackType(): string | undefined;
|
|
21
|
+
protected _getDefaults(): {
|
|
22
|
+
enforceEnum: boolean;
|
|
23
|
+
enum: never[];
|
|
24
|
+
readOnly: boolean;
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
visible: boolean;
|
|
27
|
+
type: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export default CheckboxGroup;
|