@aemforms/af-core 0.22.25 → 0.22.26
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/browser/afb-events.js +151 -0
- package/lib/browser/afb-runtime.js +3620 -0
- package/lib/cjs/index.cjs +8886 -0
- package/lib/esm/BaseNode.d.ts +93 -0
- package/lib/esm/BaseNode.js +454 -0
- package/lib/esm/Checkbox.d.ts +79 -0
- package/lib/esm/Checkbox.js +27 -0
- package/lib/esm/CheckboxGroup.d.ts +18 -0
- package/lib/esm/CheckboxGroup.js +23 -0
- package/lib/esm/Container.d.ts +53 -0
- package/lib/esm/Container.js +290 -0
- package/lib/esm/DateField.d.ts +5 -0
- package/lib/esm/DateField.js +21 -0
- package/lib/esm/Field.d.ts +206 -0
- package/lib/esm/Field.js +656 -0
- package/lib/esm/Fieldset.d.ts +16 -0
- package/lib/esm/Fieldset.js +45 -0
- package/lib/esm/FileObject.d.ts +16 -0
- package/lib/esm/FileObject.js +26 -0
- package/lib/esm/FileUpload.d.ts +22 -0
- package/lib/esm/FileUpload.js +108 -0
- package/lib/esm/Form.d.ts +113 -0
- package/lib/esm/Form.js +176 -0
- package/lib/esm/FormInstance.d.ts +13 -0
- package/lib/esm/FormInstance.js +81 -0
- package/lib/esm/FormMetaData.d.ts +7 -0
- package/lib/esm/FormMetaData.js +10 -0
- package/lib/esm/InstanceManager.d.ts +9 -0
- package/lib/esm/InstanceManager.js +31 -0
- package/lib/esm/Node.d.ts +7 -0
- package/lib/esm/Node.js +16 -0
- package/lib/esm/Scriptable.d.ts +17 -0
- package/lib/esm/Scriptable.js +163 -0
- package/lib/esm/controller/EventQueue.d.ts +17 -0
- package/lib/esm/controller/EventQueue.js +86 -0
- package/lib/esm/controller/Events.d.ts +85 -0
- package/lib/esm/controller/Events.js +149 -0
- package/lib/esm/controller/Logger.d.ts +11 -0
- package/lib/esm/controller/Logger.js +30 -0
- package/lib/esm/data/DataGroup.d.ts +20 -0
- package/lib/esm/data/DataGroup.js +77 -0
- package/lib/esm/data/DataValue.d.ts +16 -0
- package/lib/esm/data/DataValue.js +46 -0
- package/lib/esm/data/EmptyDataValue.d.ts +14 -0
- package/lib/esm/data/EmptyDataValue.js +29 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/esm/rules/FunctionRuntime.d.ts +51 -0
- package/lib/esm/rules/FunctionRuntime.js +320 -0
- package/lib/esm/rules/RuleEngine.d.ts +12 -0
- package/lib/esm/rules/RuleEngine.js +47 -0
- package/lib/esm/types/Json.d.ts +119 -0
- package/lib/esm/types/Json.js +7 -0
- package/lib/esm/types/Model.d.ts +131 -0
- package/lib/esm/types/Model.js +8 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/esm/utils/DataRefParser.d.ts +27 -0
- package/lib/esm/utils/DataRefParser.js +222 -0
- package/lib/esm/utils/Fetch.d.ts +8 -0
- package/lib/esm/utils/Fetch.js +61 -0
- package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
- package/lib/esm/utils/FormCreationUtils.js +74 -0
- package/lib/esm/utils/FormUtils.d.ts +12 -0
- package/lib/esm/utils/FormUtils.js +187 -0
- package/lib/esm/utils/JsonUtils.d.ts +11 -0
- package/lib/esm/utils/JsonUtils.js +76 -0
- package/lib/esm/utils/LogUtils.d.ts +4 -0
- package/lib/esm/utils/LogUtils.js +6 -0
- package/lib/esm/utils/SchemaUtils.d.ts +3 -0
- package/lib/esm/utils/SchemaUtils.js +71 -0
- package/lib/esm/utils/TranslationUtils.d.ts +11 -0
- package/lib/esm/utils/TranslationUtils.js +115 -0
- package/lib/esm/utils/ValidationUtils.d.ts +19 -0
- package/lib/esm/utils/ValidationUtils.js +274 -0
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormModel, Primitives, ValidationError } from './types/index.js';
|
|
2
|
+
import DataGroup from './data/DataGroup.js';
|
|
3
|
+
import DataValue from './data/DataValue.js';
|
|
4
|
+
export declare const editableProperties: string[];
|
|
5
|
+
export declare const dynamicProps: string[];
|
|
6
|
+
export declare const staticFields: string[];
|
|
7
|
+
export declare const target: unique symbol;
|
|
8
|
+
export declare const qualifiedName: unique symbol;
|
|
9
|
+
export declare function dependencyTracked(): (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
10
|
+
export declare const include: (...fieldTypes: string[]) => (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
11
|
+
export declare const exclude: (...fieldTypes: string[]) => (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
12
|
+
export declare abstract class BaseNode<T extends BaseJson> implements BaseModel {
|
|
13
|
+
private _options;
|
|
14
|
+
private _ruleNode;
|
|
15
|
+
private _lang?;
|
|
16
|
+
private _callbacks;
|
|
17
|
+
private _dependents;
|
|
18
|
+
protected _jsonModel: T & {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
private _tokens;
|
|
22
|
+
get isContainer(): boolean;
|
|
23
|
+
constructor(params: T, _options: {
|
|
24
|
+
form: FormModel;
|
|
25
|
+
parent: ContainerModel;
|
|
26
|
+
});
|
|
27
|
+
abstract value: Primitives;
|
|
28
|
+
abstract reset(): any;
|
|
29
|
+
protected setupRuleNode(): void;
|
|
30
|
+
ruleNodeReference(): this;
|
|
31
|
+
getRuleNode(): any;
|
|
32
|
+
private getFromRule;
|
|
33
|
+
get id(): string;
|
|
34
|
+
get index(): number;
|
|
35
|
+
get parent(): ContainerModel;
|
|
36
|
+
get type(): string | undefined;
|
|
37
|
+
get repeatable(): any;
|
|
38
|
+
get fieldType(): string;
|
|
39
|
+
get ':type'(): string;
|
|
40
|
+
get name(): string | undefined;
|
|
41
|
+
get description(): string | undefined;
|
|
42
|
+
set description(d: string | undefined);
|
|
43
|
+
get dataRef(): string | null | undefined;
|
|
44
|
+
get visible(): boolean | undefined;
|
|
45
|
+
set visible(v: boolean | undefined);
|
|
46
|
+
get form(): FormModel;
|
|
47
|
+
get ruleEngine(): import("./rules/RuleEngine.js").default;
|
|
48
|
+
get label(): import("./types/Json.js").Label | undefined;
|
|
49
|
+
set label(l: import("./types/Json.js").Label | undefined);
|
|
50
|
+
get uniqueItems(): boolean | undefined;
|
|
51
|
+
isTransparent(): boolean;
|
|
52
|
+
getState(): T & {
|
|
53
|
+
properties: {
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
};
|
|
56
|
+
index: number;
|
|
57
|
+
parent: undefined;
|
|
58
|
+
qualifiedName: any;
|
|
59
|
+
events: {};
|
|
60
|
+
rules: {};
|
|
61
|
+
repeatable: boolean | undefined;
|
|
62
|
+
':type': string;
|
|
63
|
+
id: string;
|
|
64
|
+
};
|
|
65
|
+
subscribe(callback: callbackFn, eventName?: string): {
|
|
66
|
+
unsubscribe: () => void;
|
|
67
|
+
};
|
|
68
|
+
_addDependent(dependent: BaseModel): void;
|
|
69
|
+
removeDependent(dependent: BaseModel): void;
|
|
70
|
+
abstract validate(): Array<ValidationError>;
|
|
71
|
+
abstract executeAction(action: Action): any;
|
|
72
|
+
queueEvent(action: Action): void;
|
|
73
|
+
dispatch(action: Action): void;
|
|
74
|
+
notifyDependents(action: Action): void;
|
|
75
|
+
_setProperty<T>(prop: string, newValue: T, notify?: boolean): any;
|
|
76
|
+
_bindToDataModel(contextualDataModel: DataGroup): void;
|
|
77
|
+
private _data?;
|
|
78
|
+
getDataNode(): DataValue | undefined;
|
|
79
|
+
get language(): string | undefined;
|
|
80
|
+
get properties(): {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
};
|
|
83
|
+
set properties(p: {
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
});
|
|
86
|
+
abstract defaultDataModel(name: string | number): DataValue | undefined;
|
|
87
|
+
abstract importData(a: DataGroup): any;
|
|
88
|
+
getNonTransparentParent(): ContainerModel;
|
|
89
|
+
_initialize(): void;
|
|
90
|
+
protected _applyUpdates(propNames: string[], updates: any): any;
|
|
91
|
+
get qualifiedName(): any;
|
|
92
|
+
focus(): void;
|
|
93
|
+
}
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { ExecuteRule, propertyChange } from './controller/Events.js';
|
|
8
|
+
import { resolveData, TOK_GLOBAL, tokenize } from './utils/DataRefParser.js';
|
|
9
|
+
import NullDataValue from './data/EmptyDataValue.js';
|
|
10
|
+
export const editableProperties = [
|
|
11
|
+
'value',
|
|
12
|
+
'label',
|
|
13
|
+
'description',
|
|
14
|
+
'visible',
|
|
15
|
+
'enabled',
|
|
16
|
+
'readOnly',
|
|
17
|
+
'enum',
|
|
18
|
+
'enumNames',
|
|
19
|
+
'required',
|
|
20
|
+
'properties',
|
|
21
|
+
'exclusiveMinimum',
|
|
22
|
+
'exclusiveMaximum',
|
|
23
|
+
'maximum',
|
|
24
|
+
'maxItems',
|
|
25
|
+
'minimum',
|
|
26
|
+
'minItems'
|
|
27
|
+
];
|
|
28
|
+
export const dynamicProps = [
|
|
29
|
+
...editableProperties,
|
|
30
|
+
'valid',
|
|
31
|
+
'index',
|
|
32
|
+
'activeChild'
|
|
33
|
+
];
|
|
34
|
+
export const staticFields = ['plain-text', 'image'];
|
|
35
|
+
class ActionImplWithTarget {
|
|
36
|
+
_action;
|
|
37
|
+
_target;
|
|
38
|
+
constructor(_action, _target) {
|
|
39
|
+
this._action = _action;
|
|
40
|
+
this._target = _target;
|
|
41
|
+
}
|
|
42
|
+
get type() {
|
|
43
|
+
return this._action.type;
|
|
44
|
+
}
|
|
45
|
+
get payload() {
|
|
46
|
+
return this._action.payload;
|
|
47
|
+
}
|
|
48
|
+
get metadata() {
|
|
49
|
+
return this._action.metadata;
|
|
50
|
+
}
|
|
51
|
+
get target() {
|
|
52
|
+
return this._target;
|
|
53
|
+
}
|
|
54
|
+
get isCustomEvent() {
|
|
55
|
+
return this._action.isCustomEvent;
|
|
56
|
+
}
|
|
57
|
+
get originalAction() {
|
|
58
|
+
return this._action.originalAction;
|
|
59
|
+
}
|
|
60
|
+
toString() {
|
|
61
|
+
return this._action.toString();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export const target = Symbol('target');
|
|
65
|
+
export const qualifiedName = Symbol('qualifiedName');
|
|
66
|
+
export function dependencyTracked() {
|
|
67
|
+
return function (target, propertyKey, descriptor) {
|
|
68
|
+
const get = descriptor.get;
|
|
69
|
+
if (get != undefined) {
|
|
70
|
+
descriptor.get = function () {
|
|
71
|
+
this.ruleEngine.trackDependency(this);
|
|
72
|
+
return get.call(this);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const addOnly = (includeOrExclude) => (...fieldTypes) => (target, propertyKey, descriptor) => {
|
|
78
|
+
const get = descriptor.get;
|
|
79
|
+
if (get != undefined) {
|
|
80
|
+
descriptor.get = function () {
|
|
81
|
+
if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
|
|
82
|
+
return get.call(this);
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const set = descriptor.set;
|
|
88
|
+
if (set != undefined) {
|
|
89
|
+
descriptor.set = function (value) {
|
|
90
|
+
if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
|
|
91
|
+
set.call(this, value);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
export const include = addOnly(true);
|
|
97
|
+
export const exclude = addOnly(false);
|
|
98
|
+
export class BaseNode {
|
|
99
|
+
_options;
|
|
100
|
+
_ruleNode;
|
|
101
|
+
_lang = '';
|
|
102
|
+
_callbacks = {};
|
|
103
|
+
_dependents = [];
|
|
104
|
+
_jsonModel;
|
|
105
|
+
_tokens = [];
|
|
106
|
+
get isContainer() {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
constructor(params, _options) {
|
|
110
|
+
this._options = _options;
|
|
111
|
+
this[qualifiedName] = null;
|
|
112
|
+
this._jsonModel = {
|
|
113
|
+
...params,
|
|
114
|
+
id: 'id' in params ? params.id : this.form.getUniqueId()
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
setupRuleNode() {
|
|
118
|
+
const self = this;
|
|
119
|
+
this._ruleNode = new Proxy(this.ruleNodeReference(), {
|
|
120
|
+
get: (ruleNodeReference, prop) => {
|
|
121
|
+
return self.getFromRule(ruleNodeReference, prop);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
ruleNodeReference() {
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
getRuleNode() {
|
|
129
|
+
return this._ruleNode;
|
|
130
|
+
}
|
|
131
|
+
getFromRule(ruleNodeReference, prop) {
|
|
132
|
+
if (prop === Symbol.toPrimitive || (prop === 'valueOf' && !ruleNodeReference.hasOwnProperty('valueOf'))) {
|
|
133
|
+
return this.valueOf;
|
|
134
|
+
}
|
|
135
|
+
else if (prop === target) {
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
else if (typeof (prop) === 'string') {
|
|
139
|
+
if (prop.startsWith('$')) {
|
|
140
|
+
prop = prop.substr(1);
|
|
141
|
+
if (typeof this[prop] !== 'function') {
|
|
142
|
+
const retValue = this[prop];
|
|
143
|
+
if (retValue instanceof BaseNode) {
|
|
144
|
+
return retValue.getRuleNode();
|
|
145
|
+
}
|
|
146
|
+
else if (retValue instanceof Array) {
|
|
147
|
+
return retValue.map(r => r instanceof BaseNode ? r.getRuleNode() : r);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return retValue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (ruleNodeReference.hasOwnProperty(prop)) {
|
|
156
|
+
return ruleNodeReference[prop];
|
|
157
|
+
}
|
|
158
|
+
else if (typeof ruleNodeReference[prop] === 'function') {
|
|
159
|
+
return ruleNodeReference[prop];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
get id() {
|
|
165
|
+
return this._jsonModel.id;
|
|
166
|
+
}
|
|
167
|
+
get index() {
|
|
168
|
+
if (this.parent) {
|
|
169
|
+
return this.parent.indexOf(this);
|
|
170
|
+
}
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
get parent() {
|
|
174
|
+
return this._options.parent;
|
|
175
|
+
}
|
|
176
|
+
get type() {
|
|
177
|
+
return this._jsonModel.type;
|
|
178
|
+
}
|
|
179
|
+
get repeatable() {
|
|
180
|
+
return this.parent?.hasDynamicItems();
|
|
181
|
+
}
|
|
182
|
+
get fieldType() {
|
|
183
|
+
return this._jsonModel.fieldType || 'text-input';
|
|
184
|
+
}
|
|
185
|
+
get ':type'() {
|
|
186
|
+
return this._jsonModel[':type'] || this.fieldType;
|
|
187
|
+
}
|
|
188
|
+
get name() {
|
|
189
|
+
return this._jsonModel.name;
|
|
190
|
+
}
|
|
191
|
+
get description() {
|
|
192
|
+
return this._jsonModel.description;
|
|
193
|
+
}
|
|
194
|
+
set description(d) {
|
|
195
|
+
this._setProperty('description', d);
|
|
196
|
+
}
|
|
197
|
+
get dataRef() {
|
|
198
|
+
return this._jsonModel.dataRef;
|
|
199
|
+
}
|
|
200
|
+
get visible() {
|
|
201
|
+
return this._jsonModel.visible;
|
|
202
|
+
}
|
|
203
|
+
set visible(v) {
|
|
204
|
+
if (v !== this._jsonModel.visible) {
|
|
205
|
+
const changeAction = propertyChange('visible', v, this._jsonModel.visible);
|
|
206
|
+
this._jsonModel.visible = v;
|
|
207
|
+
this.notifyDependents(changeAction);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
get form() {
|
|
211
|
+
return this._options.form;
|
|
212
|
+
}
|
|
213
|
+
get ruleEngine() {
|
|
214
|
+
return this.form.ruleEngine;
|
|
215
|
+
}
|
|
216
|
+
get label() {
|
|
217
|
+
return this._jsonModel.label;
|
|
218
|
+
}
|
|
219
|
+
set label(l) {
|
|
220
|
+
if (l !== this._jsonModel.label) {
|
|
221
|
+
const changeAction = propertyChange('label', l, this._jsonModel.label);
|
|
222
|
+
this._jsonModel = {
|
|
223
|
+
...this._jsonModel,
|
|
224
|
+
label: l
|
|
225
|
+
};
|
|
226
|
+
this.notifyDependents(changeAction);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
get uniqueItems() {
|
|
230
|
+
return this._jsonModel.uniqueItems;
|
|
231
|
+
}
|
|
232
|
+
isTransparent() {
|
|
233
|
+
const isNonTransparent = this.parent?._jsonModel.type === 'array';
|
|
234
|
+
return !this._jsonModel.name && !isNonTransparent;
|
|
235
|
+
}
|
|
236
|
+
getState() {
|
|
237
|
+
return {
|
|
238
|
+
...this._jsonModel,
|
|
239
|
+
properties: this.properties,
|
|
240
|
+
index: this.index,
|
|
241
|
+
parent: undefined,
|
|
242
|
+
qualifiedName: this.qualifiedName,
|
|
243
|
+
events: {},
|
|
244
|
+
rules: {},
|
|
245
|
+
repeatable: this.repeatable === true ? true : undefined,
|
|
246
|
+
':type': this[':type']
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
subscribe(callback, eventName = 'change') {
|
|
250
|
+
this._callbacks[eventName] = this._callbacks[eventName] || [];
|
|
251
|
+
this._callbacks[eventName].push(callback);
|
|
252
|
+
return {
|
|
253
|
+
unsubscribe: () => {
|
|
254
|
+
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
_addDependent(dependent) {
|
|
259
|
+
if (this._dependents.find(({ node }) => node === dependent) === undefined) {
|
|
260
|
+
const subscription = this.subscribe((change) => {
|
|
261
|
+
const changes = change.payload.changes;
|
|
262
|
+
const propsToLook = [...dynamicProps, 'items'];
|
|
263
|
+
const isPropChanged = changes.findIndex(x => {
|
|
264
|
+
return propsToLook.indexOf(x.propertyName) > -1;
|
|
265
|
+
}) > -1;
|
|
266
|
+
if (isPropChanged) {
|
|
267
|
+
dependent.dispatch(new ExecuteRule());
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
this._dependents.push({ node: dependent, subscription });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
removeDependent(dependent) {
|
|
274
|
+
const index = this._dependents.findIndex(({ node }) => node === dependent);
|
|
275
|
+
if (index > -1) {
|
|
276
|
+
this._dependents[index].subscription.unsubscribe();
|
|
277
|
+
this._dependents.splice(index, 1);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
queueEvent(action) {
|
|
281
|
+
const actionWithTarget = new ActionImplWithTarget(action, this);
|
|
282
|
+
this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
|
|
283
|
+
}
|
|
284
|
+
dispatch(action) {
|
|
285
|
+
this.queueEvent(action);
|
|
286
|
+
this.form.getEventQueue().runPendingQueue();
|
|
287
|
+
}
|
|
288
|
+
notifyDependents(action) {
|
|
289
|
+
const handlers = this._callbacks[action.type] || [];
|
|
290
|
+
handlers.forEach(x => {
|
|
291
|
+
x(new ActionImplWithTarget(action, this));
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
_setProperty(prop, newValue, notify = true) {
|
|
295
|
+
const oldValue = this._jsonModel[prop];
|
|
296
|
+
let isValueSame = false;
|
|
297
|
+
if (newValue !== null && oldValue !== null &&
|
|
298
|
+
typeof newValue === 'object' && typeof oldValue === 'object') {
|
|
299
|
+
isValueSame = JSON.stringify(newValue) === JSON.stringify(oldValue);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
isValueSame = oldValue === newValue;
|
|
303
|
+
}
|
|
304
|
+
if (!isValueSame) {
|
|
305
|
+
this._jsonModel[prop] = newValue;
|
|
306
|
+
const changeAction = propertyChange(prop, newValue, oldValue);
|
|
307
|
+
if (notify) {
|
|
308
|
+
this.notifyDependents(changeAction);
|
|
309
|
+
}
|
|
310
|
+
return changeAction.payload.changes;
|
|
311
|
+
}
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
_bindToDataModel(contextualDataModel) {
|
|
315
|
+
if (this.id === '$form') {
|
|
316
|
+
this._data = contextualDataModel;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const dataRef = this._jsonModel.dataRef;
|
|
320
|
+
let _data, _parent = contextualDataModel, _key = '';
|
|
321
|
+
if (dataRef === null) {
|
|
322
|
+
_data = NullDataValue;
|
|
323
|
+
}
|
|
324
|
+
else if (dataRef !== undefined) {
|
|
325
|
+
if (this._tokens.length === 0) {
|
|
326
|
+
this._tokens = tokenize(dataRef);
|
|
327
|
+
}
|
|
328
|
+
let searchData = contextualDataModel;
|
|
329
|
+
if (this._tokens[0].type === TOK_GLOBAL) {
|
|
330
|
+
searchData = this.form.getDataNode();
|
|
331
|
+
}
|
|
332
|
+
if (typeof searchData !== 'undefined') {
|
|
333
|
+
const name = this._tokens[this._tokens.length - 1].value;
|
|
334
|
+
const create = this.defaultDataModel(name);
|
|
335
|
+
_data = resolveData(searchData, this._tokens, create);
|
|
336
|
+
_parent = resolveData(searchData, this._tokens.slice(0, -1));
|
|
337
|
+
_key = name;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
if (contextualDataModel !== NullDataValue && staticFields.indexOf(this.fieldType) === -1) {
|
|
342
|
+
_parent = contextualDataModel;
|
|
343
|
+
const name = this._jsonModel.name || '';
|
|
344
|
+
const key = contextualDataModel.$type === 'array' ? this.index : name;
|
|
345
|
+
_key = key;
|
|
346
|
+
if (key !== '') {
|
|
347
|
+
const create = this.defaultDataModel(key);
|
|
348
|
+
if (create !== undefined) {
|
|
349
|
+
_data = contextualDataModel.$getDataNode(key);
|
|
350
|
+
if (_data === undefined) {
|
|
351
|
+
_data = create;
|
|
352
|
+
contextualDataModel.$addDataNode(key, _data);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
_data = undefined;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (_data) {
|
|
362
|
+
if (!this.isContainer && _parent !== NullDataValue && _data !== NullDataValue) {
|
|
363
|
+
_data = _data?.$convertToDataValue();
|
|
364
|
+
_parent.$addDataNode(_key, _data, true);
|
|
365
|
+
}
|
|
366
|
+
_data?.$bindToField(this);
|
|
367
|
+
this._data = _data;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
_data;
|
|
371
|
+
getDataNode() {
|
|
372
|
+
return this._data;
|
|
373
|
+
}
|
|
374
|
+
get language() {
|
|
375
|
+
if (!this._lang) {
|
|
376
|
+
if (this.parent) {
|
|
377
|
+
this._lang = this.parent.language;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
this._lang = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return this._lang;
|
|
384
|
+
}
|
|
385
|
+
get properties() {
|
|
386
|
+
return this._jsonModel.properties || {};
|
|
387
|
+
}
|
|
388
|
+
set properties(p) {
|
|
389
|
+
this._setProperty('properties', { ...p });
|
|
390
|
+
}
|
|
391
|
+
getNonTransparentParent() {
|
|
392
|
+
let nonTransparentParent = this.parent;
|
|
393
|
+
while (nonTransparentParent != null && nonTransparentParent.isTransparent()) {
|
|
394
|
+
nonTransparentParent = nonTransparentParent.parent;
|
|
395
|
+
}
|
|
396
|
+
return nonTransparentParent;
|
|
397
|
+
}
|
|
398
|
+
_initialize() {
|
|
399
|
+
if (typeof this._data === 'undefined') {
|
|
400
|
+
let dataNode, parent = this.parent;
|
|
401
|
+
do {
|
|
402
|
+
dataNode = parent.getDataNode();
|
|
403
|
+
parent = parent.parent;
|
|
404
|
+
} while (dataNode === undefined);
|
|
405
|
+
this._bindToDataModel(dataNode);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
_applyUpdates(propNames, updates) {
|
|
409
|
+
return propNames.reduce((acc, propertyName) => {
|
|
410
|
+
const currentValue = updates[propertyName];
|
|
411
|
+
const changes = this._setProperty(propertyName, currentValue, false);
|
|
412
|
+
if (changes.length > 0) {
|
|
413
|
+
acc[propertyName] = changes[0];
|
|
414
|
+
}
|
|
415
|
+
return acc;
|
|
416
|
+
}, {});
|
|
417
|
+
}
|
|
418
|
+
get qualifiedName() {
|
|
419
|
+
if (this.isTransparent()) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
if (this[qualifiedName] !== null) {
|
|
423
|
+
return this[qualifiedName];
|
|
424
|
+
}
|
|
425
|
+
const parent = this.getNonTransparentParent();
|
|
426
|
+
if (parent && parent.type === 'array') {
|
|
427
|
+
this[qualifiedName] = `${parent.qualifiedName}[${this.index}]`;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
this[qualifiedName] = `${parent.qualifiedName}.${this.name}`;
|
|
431
|
+
}
|
|
432
|
+
return this[qualifiedName];
|
|
433
|
+
}
|
|
434
|
+
focus() {
|
|
435
|
+
if (this.parent) {
|
|
436
|
+
this.parent.activeChild = this;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
__decorate([
|
|
441
|
+
dependencyTracked()
|
|
442
|
+
], BaseNode.prototype, "index", null);
|
|
443
|
+
__decorate([
|
|
444
|
+
dependencyTracked()
|
|
445
|
+
], BaseNode.prototype, "description", null);
|
|
446
|
+
__decorate([
|
|
447
|
+
dependencyTracked()
|
|
448
|
+
], BaseNode.prototype, "visible", null);
|
|
449
|
+
__decorate([
|
|
450
|
+
dependencyTracked()
|
|
451
|
+
], BaseNode.prototype, "label", null);
|
|
452
|
+
__decorate([
|
|
453
|
+
dependencyTracked()
|
|
454
|
+
], BaseNode.prototype, "properties", null);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
declare class Checkbox extends Field {
|
|
3
|
+
private offValue;
|
|
4
|
+
_getConstraintObject(): {
|
|
5
|
+
enum: (constraint: any, inputVal: any) => {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
value: any;
|
|
8
|
+
};
|
|
9
|
+
accept: (constraint: any, inputVal: any) => {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
value: any;
|
|
12
|
+
};
|
|
13
|
+
exclusiveMinimum: (constraint: any, inputVal: any) => {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
value: any;
|
|
16
|
+
};
|
|
17
|
+
exclusiveMaximum: (constraint: any, inputVal: any) => {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
value: any;
|
|
20
|
+
};
|
|
21
|
+
format: (constraint: any, inputVal: any) => {
|
|
22
|
+
valid: boolean;
|
|
23
|
+
value: any;
|
|
24
|
+
};
|
|
25
|
+
maxFileSize: (constraint: any, inputVal: any) => {
|
|
26
|
+
valid: boolean;
|
|
27
|
+
value: any;
|
|
28
|
+
};
|
|
29
|
+
maxLength: (constraint: any, inputVal: any) => {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
value: any;
|
|
32
|
+
};
|
|
33
|
+
maximum: (constraint: any, inputVal: any) => {
|
|
34
|
+
valid: boolean;
|
|
35
|
+
value: any;
|
|
36
|
+
};
|
|
37
|
+
maxItems: (constraint: any, inputVal: any) => {
|
|
38
|
+
valid: boolean;
|
|
39
|
+
value: any;
|
|
40
|
+
};
|
|
41
|
+
minLength: (constraint: any, inputVal: any) => {
|
|
42
|
+
valid: boolean;
|
|
43
|
+
value: any;
|
|
44
|
+
};
|
|
45
|
+
minimum: (constraint: any, inputVal: any) => {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
value: any;
|
|
48
|
+
};
|
|
49
|
+
minItems: (constraint: any, inputVal: any) => {
|
|
50
|
+
valid: boolean;
|
|
51
|
+
value: any;
|
|
52
|
+
};
|
|
53
|
+
pattern: (constraint: any, inputVal: any) => {
|
|
54
|
+
valid: boolean;
|
|
55
|
+
value: any;
|
|
56
|
+
};
|
|
57
|
+
required: (constraint: any, inputVal: any) => {
|
|
58
|
+
valid: boolean;
|
|
59
|
+
value: any;
|
|
60
|
+
};
|
|
61
|
+
type: (constraint: any, inputVal: any) => {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
value: any;
|
|
64
|
+
};
|
|
65
|
+
uniqueItems: (constraint: any, inputVal: any) => {
|
|
66
|
+
valid: boolean;
|
|
67
|
+
value: any;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
protected _getDefaults(): {
|
|
71
|
+
enforceEnum: boolean;
|
|
72
|
+
readOnly: boolean;
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
visible: boolean;
|
|
75
|
+
type: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
get enum(): any[];
|
|
78
|
+
}
|
|
79
|
+
export default Checkbox;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
import { Constraints } from './utils/ValidationUtils.js';
|
|
3
|
+
const requiredConstraint = (offValue) => (constraint, value) => {
|
|
4
|
+
const valid = Constraints.required(constraint, value).valid && (!constraint || value != offValue);
|
|
5
|
+
return { valid, value };
|
|
6
|
+
};
|
|
7
|
+
class Checkbox extends Field {
|
|
8
|
+
offValue() {
|
|
9
|
+
const opts = this.enum;
|
|
10
|
+
return opts.length > 1 ? opts[1] : null;
|
|
11
|
+
}
|
|
12
|
+
_getConstraintObject() {
|
|
13
|
+
const baseConstraints = { ...super._getConstraintObject() };
|
|
14
|
+
baseConstraints.required = requiredConstraint(this.offValue());
|
|
15
|
+
return baseConstraints;
|
|
16
|
+
}
|
|
17
|
+
_getDefaults() {
|
|
18
|
+
return {
|
|
19
|
+
...super._getDefaults(),
|
|
20
|
+
enforceEnum: true
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
get enum() {
|
|
24
|
+
return this._jsonModel.enum || [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default Checkbox;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
import { ContainerModel, FieldJson, FormModel } from './types/index.js';
|
|
3
|
+
declare class CheckboxGroup extends Field {
|
|
4
|
+
constructor(params: FieldJson, _options: {
|
|
5
|
+
form: FormModel;
|
|
6
|
+
parent: ContainerModel;
|
|
7
|
+
});
|
|
8
|
+
protected _getFallbackType(): string | undefined;
|
|
9
|
+
protected _getDefaults(): {
|
|
10
|
+
enforceEnum: boolean;
|
|
11
|
+
enum: never[];
|
|
12
|
+
readOnly: boolean;
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
visible: boolean;
|
|
15
|
+
type: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export default CheckboxGroup;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Field from './Field.js';
|
|
2
|
+
class CheckboxGroup extends Field {
|
|
3
|
+
constructor(params, _options) {
|
|
4
|
+
super(params, _options);
|
|
5
|
+
}
|
|
6
|
+
_getFallbackType() {
|
|
7
|
+
const fallbackType = super._getFallbackType();
|
|
8
|
+
if (typeof fallbackType === 'string') {
|
|
9
|
+
return `${fallbackType}[]`;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return 'string[]';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
_getDefaults() {
|
|
16
|
+
return {
|
|
17
|
+
...super._getDefaults(),
|
|
18
|
+
enforceEnum: true,
|
|
19
|
+
enum: []
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export default CheckboxGroup;
|