@aemforms/af-core 0.22.78 → 0.22.80
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/esm/afb-events.js +10 -1
- package/esm/afb-runtime.js +188 -27
- package/esm/types/src/BaseNode.d.ts +1 -0
- package/esm/types/src/Form.d.ts +8 -1
- package/esm/types/src/FormInstance.d.ts +4 -1
- package/esm/types/src/Scriptable.d.ts +1 -0
- package/esm/types/src/controller/Events.d.ts +5 -0
- package/esm/types/src/rules/FunctionRuntime.d.ts +5 -1
- package/esm/types/src/types/Json.d.ts +1 -1
- package/esm/types/src/types/Model.d.ts +6 -2
- package/esm/types/src/utils/Version.d.ts +11 -0
- package/lib/BaseNode.d.ts +1 -0
- package/lib/BaseNode.js +23 -5
- package/lib/Field.js +6 -1
- package/lib/Fieldset.js +1 -1
- package/lib/Form.d.ts +8 -1
- package/lib/Form.js +69 -3
- package/lib/FormInstance.d.ts +4 -1
- package/lib/FormInstance.js +30 -4
- package/lib/Scriptable.d.ts +1 -0
- package/lib/Scriptable.js +24 -10
- package/lib/controller/Events.d.ts +5 -0
- package/lib/controller/Events.js +10 -1
- package/lib/rules/FunctionRuntime.d.ts +5 -1
- package/lib/rules/FunctionRuntime.js +17 -3
- package/lib/types/Json.d.ts +1 -1
- package/lib/types/Model.d.ts +6 -2
- package/lib/utils/FormCreationUtils.js +1 -1
- package/lib/utils/Version.d.ts +11 -0
- package/lib/utils/Version.js +60 -0
- package/package.json +2 -2
package/esm/afb-events.js
CHANGED
|
@@ -3,6 +3,7 @@ class ActionImpl {
|
|
|
3
3
|
_type;
|
|
4
4
|
_payload;
|
|
5
5
|
_target;
|
|
6
|
+
_currentTarget;
|
|
6
7
|
constructor(payload, type, _metadata) {
|
|
7
8
|
this._metadata = _metadata;
|
|
8
9
|
this._payload = payload;
|
|
@@ -20,6 +21,9 @@ class ActionImpl {
|
|
|
20
21
|
get target() {
|
|
21
22
|
return this._target;
|
|
22
23
|
}
|
|
24
|
+
get currentTarget() {
|
|
25
|
+
return this._currentTarget;
|
|
26
|
+
}
|
|
23
27
|
get isCustomEvent() {
|
|
24
28
|
return false;
|
|
25
29
|
}
|
|
@@ -106,6 +110,11 @@ class Submit extends ActionImpl {
|
|
|
106
110
|
super(payload, 'submit', { dispatch });
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
class Save extends ActionImpl {
|
|
114
|
+
constructor(payload, dispatch = false) {
|
|
115
|
+
super(payload, 'save', { dispatch });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
109
118
|
class SubmitSuccess extends ActionImpl {
|
|
110
119
|
constructor(payload, dispatch = false) {
|
|
111
120
|
super(payload, 'submitSuccess', { dispatch });
|
|
@@ -163,4 +172,4 @@ class RemoveInstance extends ActionImpl {
|
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
174
|
|
|
166
|
-
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Submit, SubmitError, SubmitFailure, SubmitSuccess, Valid, ValidationComplete, propertyChange };
|
|
175
|
+
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Save, Submit, SubmitError, SubmitFailure, SubmitSuccess, Valid, ValidationComplete, propertyChange };
|
package/esm/afb-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitError, SubmitFailure, Submit, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete, Valid, Invalid } from './afb-events.js';
|
|
1
|
+
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitError, SubmitFailure, Submit, Save, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete, Valid, Invalid } from './afb-events.js';
|
|
2
2
|
import Formula from '@adobe/json-formula';
|
|
3
3
|
import { parseDefaultDate, datetimeToNumber, format, parseDateSkeleton, formatDate, numberToDatetime } from '@aemforms/af-formatters';
|
|
4
4
|
|
|
@@ -1131,9 +1131,17 @@ const staticFields = ['plain-text', 'image'];
|
|
|
1131
1131
|
class ActionImplWithTarget {
|
|
1132
1132
|
_action;
|
|
1133
1133
|
_target;
|
|
1134
|
+
_currentTarget;
|
|
1134
1135
|
constructor(_action, _target) {
|
|
1135
1136
|
this._action = _action;
|
|
1136
|
-
|
|
1137
|
+
if (_action.target) {
|
|
1138
|
+
this._currentTarget = _target;
|
|
1139
|
+
this._target = _action.target;
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
this._target = _target;
|
|
1143
|
+
this._currentTarget = _target;
|
|
1144
|
+
}
|
|
1137
1145
|
}
|
|
1138
1146
|
get type() {
|
|
1139
1147
|
return this._action.type;
|
|
@@ -1147,6 +1155,9 @@ class ActionImplWithTarget {
|
|
|
1147
1155
|
get target() {
|
|
1148
1156
|
return this._target;
|
|
1149
1157
|
}
|
|
1158
|
+
get currentTarget() {
|
|
1159
|
+
return this._currentTarget;
|
|
1160
|
+
}
|
|
1150
1161
|
get isCustomEvent() {
|
|
1151
1162
|
return this._action.isCustomEvent;
|
|
1152
1163
|
}
|
|
@@ -1331,9 +1342,12 @@ class BaseNode {
|
|
|
1331
1342
|
return this._jsonModel.uniqueItems;
|
|
1332
1343
|
}
|
|
1333
1344
|
isTransparent() {
|
|
1334
|
-
const isNonTransparent = this.parent?._jsonModel
|
|
1345
|
+
const isNonTransparent = this.parent?._jsonModel?.type === 'array';
|
|
1335
1346
|
return !this._jsonModel.name && !isNonTransparent;
|
|
1336
1347
|
}
|
|
1348
|
+
getDependents() {
|
|
1349
|
+
return this._dependents.map(x => x.node.id);
|
|
1350
|
+
}
|
|
1337
1351
|
getState(forRestore = false) {
|
|
1338
1352
|
return {
|
|
1339
1353
|
...this._jsonModel,
|
|
@@ -1348,7 +1362,7 @@ class BaseNode {
|
|
|
1348
1362
|
} : {}),
|
|
1349
1363
|
':type': this[':type'],
|
|
1350
1364
|
...(forRestore ? {
|
|
1351
|
-
_dependents: this._dependents.length ? this.
|
|
1365
|
+
_dependents: this._dependents.length ? this.getDependents() : undefined,
|
|
1352
1366
|
allowedComponents: undefined,
|
|
1353
1367
|
columnClassNames: undefined,
|
|
1354
1368
|
columnCount: undefined,
|
|
@@ -1374,7 +1388,12 @@ class BaseNode {
|
|
|
1374
1388
|
return propsToLook.indexOf(x.propertyName) > -1;
|
|
1375
1389
|
}) > -1;
|
|
1376
1390
|
if (isPropChanged) {
|
|
1377
|
-
|
|
1391
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
1392
|
+
dependent.dispatch(change);
|
|
1393
|
+
}
|
|
1394
|
+
else {
|
|
1395
|
+
dependent.dispatch(new ExecuteRule());
|
|
1396
|
+
}
|
|
1378
1397
|
}
|
|
1379
1398
|
});
|
|
1380
1399
|
this._dependents.push({ node: dependent, subscription });
|
|
@@ -1651,16 +1670,23 @@ class Scriptable extends BaseNode {
|
|
|
1651
1670
|
return this._events[eName] || [];
|
|
1652
1671
|
}
|
|
1653
1672
|
applyUpdates(updates) {
|
|
1654
|
-
|
|
1655
|
-
if (
|
|
1656
|
-
|
|
1657
|
-
this[key]
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1673
|
+
if (typeof updates === 'object') {
|
|
1674
|
+
if (updates !== null) {
|
|
1675
|
+
Object.entries(updates).forEach(([key, value]) => {
|
|
1676
|
+
if (key in editableProperties || (key in this && typeof this[key] !== 'function')) {
|
|
1677
|
+
try {
|
|
1678
|
+
this[key] = value;
|
|
1679
|
+
}
|
|
1680
|
+
catch (e) {
|
|
1681
|
+
console.error(e);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1662
1685
|
}
|
|
1663
|
-
}
|
|
1686
|
+
}
|
|
1687
|
+
else if (typeof updates !== 'undefined') {
|
|
1688
|
+
this.value = updates;
|
|
1689
|
+
}
|
|
1664
1690
|
}
|
|
1665
1691
|
executeAllRules(context) {
|
|
1666
1692
|
const entries = Object.entries(this.getRules());
|
|
@@ -1748,6 +1774,11 @@ class Scriptable extends BaseNode {
|
|
|
1748
1774
|
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
1749
1775
|
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
1750
1776
|
}
|
|
1777
|
+
change(event, context) {
|
|
1778
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
1779
|
+
this.executeAllRules(context);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1751
1782
|
executeAction(action) {
|
|
1752
1783
|
const context = {
|
|
1753
1784
|
'form': this.form,
|
|
@@ -1767,7 +1798,9 @@ class Scriptable extends BaseNode {
|
|
|
1767
1798
|
this[funcName](action, context);
|
|
1768
1799
|
}
|
|
1769
1800
|
node.forEach((n) => this.executeEvent(context, n));
|
|
1770
|
-
|
|
1801
|
+
if (action.target === this) {
|
|
1802
|
+
this.notifyDependents(action);
|
|
1803
|
+
}
|
|
1771
1804
|
}
|
|
1772
1805
|
}
|
|
1773
1806
|
|
|
@@ -2544,15 +2577,15 @@ const multipartFormData = (data, attachments) => {
|
|
|
2544
2577
|
}
|
|
2545
2578
|
return formData;
|
|
2546
2579
|
};
|
|
2547
|
-
const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null) => {
|
|
2548
|
-
const endpoint = context.form.action;
|
|
2580
|
+
const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => {
|
|
2581
|
+
const endpoint = action || context.form.action;
|
|
2549
2582
|
let data = input_data;
|
|
2550
2583
|
if (typeof data != 'object' || data == null) {
|
|
2551
2584
|
data = context.form.exportData();
|
|
2552
2585
|
}
|
|
2553
2586
|
const attachments = getAttachments(context.form, true);
|
|
2554
2587
|
let submitContentType = submitAs;
|
|
2555
|
-
const submitDataAndMetaData = { 'data': data,
|
|
2588
|
+
const submitDataAndMetaData = { 'data': data, ...metadata };
|
|
2556
2589
|
let formData = submitDataAndMetaData;
|
|
2557
2590
|
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
2558
2591
|
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
@@ -2568,6 +2601,8 @@ const createAction = (name, payload = {}) => {
|
|
|
2568
2601
|
return new Change(payload);
|
|
2569
2602
|
case 'submit':
|
|
2570
2603
|
return new Submit(payload);
|
|
2604
|
+
case 'save':
|
|
2605
|
+
return new Save(payload);
|
|
2571
2606
|
case 'click':
|
|
2572
2607
|
return new Click(payload);
|
|
2573
2608
|
case 'addItem':
|
|
@@ -2773,6 +2808,18 @@ class FunctionRuntimeImpl {
|
|
|
2773
2808
|
},
|
|
2774
2809
|
_signature: []
|
|
2775
2810
|
},
|
|
2811
|
+
saveForm: {
|
|
2812
|
+
_func: (args, data, interpreter) => {
|
|
2813
|
+
const action = toString(args[0]);
|
|
2814
|
+
const validate_form = args[2] || false;
|
|
2815
|
+
interpreter.globals.form.dispatch(new Save({
|
|
2816
|
+
action,
|
|
2817
|
+
validate_form
|
|
2818
|
+
}));
|
|
2819
|
+
return {};
|
|
2820
|
+
},
|
|
2821
|
+
_signature: []
|
|
2822
|
+
},
|
|
2776
2823
|
request: {
|
|
2777
2824
|
_func: (args, data, interpreter) => {
|
|
2778
2825
|
const uri = toString(args[0]);
|
|
@@ -2860,6 +2907,52 @@ class FunctionRuntimeImpl {
|
|
|
2860
2907
|
}
|
|
2861
2908
|
const FunctionRuntime = FunctionRuntimeImpl.getInstance();
|
|
2862
2909
|
|
|
2910
|
+
class Version {
|
|
2911
|
+
#minor;
|
|
2912
|
+
#major;
|
|
2913
|
+
#subVersion;
|
|
2914
|
+
#invalid = true;
|
|
2915
|
+
constructor(n) {
|
|
2916
|
+
const match = n.match(/([^.]+)\.([^.]+)(?:\.(.+))?/);
|
|
2917
|
+
if (match) {
|
|
2918
|
+
this.#major = +match[1];
|
|
2919
|
+
this.#minor = +match[2];
|
|
2920
|
+
this.#subVersion = match[3] ? +match[3] : 0;
|
|
2921
|
+
if (isNaN(this.#major) || isNaN(this.#minor) || isNaN(this.#subVersion)) {
|
|
2922
|
+
throw new Error('Invalid version string ' + n);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
else {
|
|
2926
|
+
throw new Error('Invalid version string ' + n);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
get major() {
|
|
2930
|
+
return this.#major;
|
|
2931
|
+
}
|
|
2932
|
+
get minor() {
|
|
2933
|
+
return this.#minor;
|
|
2934
|
+
}
|
|
2935
|
+
get subversion() {
|
|
2936
|
+
return this.#subVersion;
|
|
2937
|
+
}
|
|
2938
|
+
completeMatch(v) {
|
|
2939
|
+
return this.major === v.major &&
|
|
2940
|
+
this.minor === v.minor &&
|
|
2941
|
+
this.#subVersion === v.subversion;
|
|
2942
|
+
}
|
|
2943
|
+
lessThan(v) {
|
|
2944
|
+
return this.major < v.major || (this.major === v.major && (this.minor < v.minor)) || (this.major === v.major && this.minor === v.minor && this.#subVersion < v.subversion);
|
|
2945
|
+
}
|
|
2946
|
+
toString() {
|
|
2947
|
+
return `${this.major}.${this.minor}.${this.subversion}`;
|
|
2948
|
+
}
|
|
2949
|
+
valueOf() {
|
|
2950
|
+
return this.toString();
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
const currentVersion = new Version('0.13');
|
|
2955
|
+
const changeEventVersion = new Version('0.13');
|
|
2863
2956
|
class Form extends Container {
|
|
2864
2957
|
_ruleEngine;
|
|
2865
2958
|
_eventQueue;
|
|
@@ -2871,9 +2964,15 @@ class Form extends Container {
|
|
|
2871
2964
|
this._ruleEngine = _ruleEngine;
|
|
2872
2965
|
this._eventQueue = _eventQueue;
|
|
2873
2966
|
this._logger = new Logger(logLevel);
|
|
2967
|
+
this._applyDefaultsInModel();
|
|
2874
2968
|
if (mode === 'create') {
|
|
2875
2969
|
this.queueEvent(new Initialize());
|
|
2876
|
-
this.
|
|
2970
|
+
if (this.changeEventBehaviour === 'deps') {
|
|
2971
|
+
this.queueEvent(new Change({ changes: [] }));
|
|
2972
|
+
}
|
|
2973
|
+
else {
|
|
2974
|
+
this.queueEvent(new ExecuteRule());
|
|
2975
|
+
}
|
|
2877
2976
|
}
|
|
2878
2977
|
this._ids = IdGenerator();
|
|
2879
2978
|
this._bindToDataModel(new DataGroup('$form', {}));
|
|
@@ -2882,10 +2981,21 @@ class Form extends Container {
|
|
|
2882
2981
|
this.queueEvent(new FormLoad());
|
|
2883
2982
|
}
|
|
2884
2983
|
}
|
|
2984
|
+
_applyDefaultsInModel() {
|
|
2985
|
+
const current = this.specVersion;
|
|
2986
|
+
this._jsonModel.properties = this._jsonModel.properties || {};
|
|
2987
|
+
if (current.lessThan(changeEventVersion) ||
|
|
2988
|
+
typeof this._jsonModel.properties['fd:changeEventBehaviour'] !== 'string') {
|
|
2989
|
+
this._jsonModel.properties['fd:changeEventBehaviour'] = 'self';
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2885
2992
|
_logger;
|
|
2886
2993
|
get logger() {
|
|
2887
2994
|
return this._logger;
|
|
2888
2995
|
}
|
|
2996
|
+
get changeEventBehaviour() {
|
|
2997
|
+
return this.properties['fd:changeEventBehaviour'] === 'deps' ? 'deps' : 'self';
|
|
2998
|
+
}
|
|
2889
2999
|
dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
2890
3000
|
get metaData() {
|
|
2891
3001
|
const metaData = this._jsonModel.metadata || {};
|
|
@@ -2902,6 +3012,21 @@ class Form extends Container {
|
|
|
2902
3012
|
exportData() {
|
|
2903
3013
|
return this.getDataNode()?.$value;
|
|
2904
3014
|
}
|
|
3015
|
+
get specVersion() {
|
|
3016
|
+
if (typeof this._jsonModel.adaptiveform === 'string') {
|
|
3017
|
+
try {
|
|
3018
|
+
return new Version(this._jsonModel.adaptiveform);
|
|
3019
|
+
}
|
|
3020
|
+
catch (e) {
|
|
3021
|
+
console.log(e);
|
|
3022
|
+
console.log('Falling back to default version' + currentVersion.toString());
|
|
3023
|
+
return currentVersion;
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
else {
|
|
3027
|
+
return currentVersion;
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
2905
3030
|
resolveQualifiedName(qualifiedName) {
|
|
2906
3031
|
let foundFormElement = null;
|
|
2907
3032
|
this.visit(formElement => {
|
|
@@ -3041,7 +3166,7 @@ class Form extends Container {
|
|
|
3041
3166
|
}, 'valid');
|
|
3042
3167
|
field.subscribe((action) => {
|
|
3043
3168
|
const field = action.target.getState();
|
|
3044
|
-
if (field) {
|
|
3169
|
+
if (action.payload.changes.length > 0 && field) {
|
|
3045
3170
|
const shallowClone = (obj) => {
|
|
3046
3171
|
if (obj && typeof obj === 'object') {
|
|
3047
3172
|
if (Array.isArray(obj)) {
|
|
@@ -3099,7 +3224,35 @@ class Form extends Container {
|
|
|
3099
3224
|
const payload = action?.payload || {};
|
|
3100
3225
|
const successEventName = payload?.success ? payload?.success : 'submitSuccess';
|
|
3101
3226
|
const failureEventName = payload?.error ? payload?.error : 'submitError';
|
|
3102
|
-
|
|
3227
|
+
const formAction = payload.action || this.action;
|
|
3228
|
+
const metadata = payload.metadata || {
|
|
3229
|
+
'submitMetadata': this.exportSubmitMetaData()
|
|
3230
|
+
};
|
|
3231
|
+
const contentType = payload?.save_as || payload?.submit_as;
|
|
3232
|
+
submit(context, successEventName, failureEventName, contentType, payload?.data, formAction, metadata);
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
save(action, context) {
|
|
3236
|
+
const payload = action?.payload || {};
|
|
3237
|
+
payload.save_as = 'multipart/form-data';
|
|
3238
|
+
payload.metadata = {
|
|
3239
|
+
'draftMetadata': {
|
|
3240
|
+
'lang': this.lang,
|
|
3241
|
+
'draftId': this.properties?.draftId || ''
|
|
3242
|
+
}
|
|
3243
|
+
};
|
|
3244
|
+
payload.success = 'custom:saveSuccess';
|
|
3245
|
+
payload.error = 'custom:saveError';
|
|
3246
|
+
this.submit(action, context);
|
|
3247
|
+
this.subscribe((action) => {
|
|
3248
|
+
this._saveSuccess(action);
|
|
3249
|
+
}, 'saveSuccess');
|
|
3250
|
+
}
|
|
3251
|
+
_saveSuccess(action) {
|
|
3252
|
+
const draftId = action?.payload?.body?.draftId || '';
|
|
3253
|
+
const properties = this.properties;
|
|
3254
|
+
if (draftId && properties) {
|
|
3255
|
+
properties.draftId = draftId;
|
|
3103
3256
|
}
|
|
3104
3257
|
}
|
|
3105
3258
|
reset() {
|
|
@@ -3236,7 +3389,7 @@ class Fieldset extends Container {
|
|
|
3236
3389
|
return undefined;
|
|
3237
3390
|
}
|
|
3238
3391
|
get items() {
|
|
3239
|
-
return super.items;
|
|
3392
|
+
return super.items ? super.items : [];
|
|
3240
3393
|
}
|
|
3241
3394
|
get value() {
|
|
3242
3395
|
return null;
|
|
@@ -3277,7 +3430,12 @@ class Field extends Scriptable {
|
|
|
3277
3430
|
if (_options.mode !== 'restore') {
|
|
3278
3431
|
this._applyDefaults();
|
|
3279
3432
|
this.queueEvent(new Initialize());
|
|
3280
|
-
this.
|
|
3433
|
+
if (this.form.changeEventBehaviour === 'deps') {
|
|
3434
|
+
this.queueEvent(new Change({ changes: [] }));
|
|
3435
|
+
}
|
|
3436
|
+
else {
|
|
3437
|
+
this.queueEvent(new ExecuteRule());
|
|
3438
|
+
}
|
|
3281
3439
|
}
|
|
3282
3440
|
}
|
|
3283
3441
|
_ruleNodeReference = [];
|
|
@@ -4302,7 +4460,7 @@ class FormFieldFactoryImpl {
|
|
|
4302
4460
|
};
|
|
4303
4461
|
retVal = new InstanceManager(newJson, options);
|
|
4304
4462
|
}
|
|
4305
|
-
else if ('items' in child) {
|
|
4463
|
+
else if ('items' in child || child.fieldType === 'panel') {
|
|
4306
4464
|
retVal = new Fieldset(child, options);
|
|
4307
4465
|
}
|
|
4308
4466
|
else {
|
|
@@ -4336,9 +4494,11 @@ const FormFieldFactory = new FormFieldFactoryImpl();
|
|
|
4336
4494
|
const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
|
|
4337
4495
|
try {
|
|
4338
4496
|
let f = fModel;
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4497
|
+
{
|
|
4498
|
+
if (f == null) {
|
|
4499
|
+
formModel = sitesModelToFormModel(formModel);
|
|
4500
|
+
f = new Form({ ...formModel }, FormFieldFactory, new RuleEngine(), new EventQueue(new Logger(logLevel)), logLevel);
|
|
4501
|
+
}
|
|
4342
4502
|
}
|
|
4343
4503
|
const formData = formModel?.data;
|
|
4344
4504
|
if (formData) {
|
|
@@ -4355,6 +4515,7 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
|
|
|
4355
4515
|
throw new Error(e);
|
|
4356
4516
|
}
|
|
4357
4517
|
};
|
|
4518
|
+
createFormInstance.currentVersion = currentVersion;
|
|
4358
4519
|
const defaultOptions = {
|
|
4359
4520
|
logLevel: 'error'
|
|
4360
4521
|
};
|
|
@@ -50,6 +50,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
50
50
|
set label(l: import("./types/Json").Label | undefined);
|
|
51
51
|
get uniqueItems(): boolean | undefined;
|
|
52
52
|
isTransparent(): boolean;
|
|
53
|
+
getDependents(): string[];
|
|
53
54
|
getState(forRestore?: boolean): T & {
|
|
54
55
|
_dependents?: string[] | undefined;
|
|
55
56
|
allowedComponents?: undefined;
|
package/esm/types/src/Form.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import SubmitMetaData from './SubmitMetaData';
|
|
|
5
5
|
import EventQueue from './controller/EventQueue';
|
|
6
6
|
import { Logger, LogLevel } from './controller/Logger';
|
|
7
7
|
import RuleEngine from './rules/RuleEngine';
|
|
8
|
+
import { Version } from './utils/Version';
|
|
9
|
+
export declare const currentVersion: Version;
|
|
8
10
|
declare class Form extends Container<FormJson> implements FormModel {
|
|
9
11
|
#private;
|
|
10
12
|
private _ruleEngine;
|
|
@@ -13,13 +15,16 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
13
15
|
_ids: Generator<string, void, string>;
|
|
14
16
|
private _invalidFields;
|
|
15
17
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
18
|
+
protected _applyDefaultsInModel(): void;
|
|
16
19
|
private _logger;
|
|
17
20
|
get logger(): Logger;
|
|
21
|
+
get changeEventBehaviour(): "deps" | "self";
|
|
18
22
|
private dataRefRegex;
|
|
19
23
|
get metaData(): FormMetaData;
|
|
20
24
|
get action(): string | undefined;
|
|
21
25
|
importData(dataModel: any): void;
|
|
22
26
|
exportData(): any;
|
|
27
|
+
get specVersion(): Version;
|
|
23
28
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
|
24
29
|
exportSubmitMetaData(): SubmitMetaData;
|
|
25
30
|
setFocus(field: BaseModel, focusOption: FocusOption): void;
|
|
@@ -78,7 +83,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
78
83
|
data?: any;
|
|
79
84
|
title?: string | undefined;
|
|
80
85
|
action?: string | undefined;
|
|
81
|
-
|
|
86
|
+
adaptiveform?: string | undefined;
|
|
82
87
|
lang?: string | undefined;
|
|
83
88
|
} & {
|
|
84
89
|
items: any[];
|
|
@@ -115,6 +120,8 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
115
120
|
isValid(): boolean;
|
|
116
121
|
dispatch(action: Action): void;
|
|
117
122
|
submit(action: Action, context: any): void;
|
|
123
|
+
save(action: Action, context: any): void;
|
|
124
|
+
_saveSuccess(action: Action): void;
|
|
118
125
|
reset(): void;
|
|
119
126
|
getElement(id: string): FieldModel | FieldsetModel | this;
|
|
120
127
|
get qualifiedName(): string;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FormModel } from './types/index';
|
|
2
2
|
import { LogLevel } from './controller/Logger';
|
|
3
3
|
import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
|
|
4
|
-
export declare const createFormInstance:
|
|
4
|
+
export declare const createFormInstance: {
|
|
5
|
+
(formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any): FormModel;
|
|
6
|
+
currentVersion: import("./utils/Version").Version;
|
|
7
|
+
};
|
|
5
8
|
export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
|
|
6
9
|
logLevel: LogLevel;
|
|
7
10
|
}) => FormModel;
|
|
@@ -12,6 +12,7 @@ declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> imple
|
|
|
12
12
|
private executeEvent;
|
|
13
13
|
executeRule(event: Action, context: any): void;
|
|
14
14
|
executeExpression(expr: string): any;
|
|
15
|
+
change(event: Action, context: any): void;
|
|
15
16
|
executeAction(action: Action): void;
|
|
16
17
|
}
|
|
17
18
|
export default Scriptable;
|
|
@@ -4,11 +4,13 @@ declare class ActionImpl implements Action {
|
|
|
4
4
|
protected _type: string;
|
|
5
5
|
private _payload?;
|
|
6
6
|
private _target;
|
|
7
|
+
private _currentTarget;
|
|
7
8
|
constructor(payload: any, type: string, _metadata?: any);
|
|
8
9
|
get type(): string;
|
|
9
10
|
get payload(): any;
|
|
10
11
|
get metadata(): any;
|
|
11
12
|
get target(): FormModel | FieldModel | FieldsetModel;
|
|
13
|
+
get currentTarget(): FormModel | FieldModel | FieldsetModel;
|
|
12
14
|
get isCustomEvent(): boolean;
|
|
13
15
|
protected payloadToJson(): any;
|
|
14
16
|
toJson(): {
|
|
@@ -60,6 +62,9 @@ export declare class Focus extends ActionImpl {
|
|
|
60
62
|
export declare class Submit extends ActionImpl {
|
|
61
63
|
constructor(payload?: any, dispatch?: boolean);
|
|
62
64
|
}
|
|
65
|
+
export declare class Save extends ActionImpl {
|
|
66
|
+
constructor(payload?: any, dispatch?: boolean);
|
|
67
|
+
}
|
|
63
68
|
export declare class SubmitSuccess extends ActionImpl {
|
|
64
69
|
constructor(payload?: any, dispatch?: boolean);
|
|
65
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type HTTP_VERB = 'GET' | 'POST';
|
|
2
2
|
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<void>;
|
|
3
|
-
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any) => Promise<void>;
|
|
3
|
+
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any, action?: string, metadata?: any) => Promise<void>;
|
|
4
4
|
export type CustomFunction = Function;
|
|
5
5
|
export type FunctionDefinition = {
|
|
6
6
|
_func: CustomFunction;
|
|
@@ -40,6 +40,10 @@ declare class FunctionRuntimeImpl {
|
|
|
40
40
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
41
41
|
_signature: never[];
|
|
42
42
|
};
|
|
43
|
+
saveForm: {
|
|
44
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
45
|
+
_signature: never[];
|
|
46
|
+
};
|
|
43
47
|
request: {
|
|
44
48
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
45
49
|
_signature: never[];
|
|
@@ -117,7 +117,7 @@ export type FormJson = ContainerJson & {
|
|
|
117
117
|
data?: any;
|
|
118
118
|
title?: string;
|
|
119
119
|
action?: string;
|
|
120
|
-
|
|
120
|
+
adaptiveform?: string;
|
|
121
121
|
lang?: string;
|
|
122
122
|
};
|
|
123
123
|
export type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
|
|
@@ -3,6 +3,7 @@ import RuleEngine from '../rules/RuleEngine';
|
|
|
3
3
|
import EventQueue from '../controller/EventQueue';
|
|
4
4
|
import DataGroup from '../data/DataGroup';
|
|
5
5
|
import { Logger } from '../controller/Logger';
|
|
6
|
+
import { Version } from '../utils/Version';
|
|
6
7
|
export interface ScriptableField {
|
|
7
8
|
rules?: {
|
|
8
9
|
[key: string]: string;
|
|
@@ -10,7 +11,7 @@ export interface ScriptableField {
|
|
|
10
11
|
events?: {
|
|
11
12
|
[key: string]: string;
|
|
12
13
|
};
|
|
13
|
-
ruleEngine: RuleEngine;
|
|
14
|
+
readonly ruleEngine: RuleEngine;
|
|
14
15
|
}
|
|
15
16
|
interface WithState<T> {
|
|
16
17
|
getState: () => any;
|
|
@@ -33,6 +34,7 @@ export interface Action {
|
|
|
33
34
|
readonly isCustomEvent: boolean;
|
|
34
35
|
readonly target: FormModel | FieldModel | FieldsetModel;
|
|
35
36
|
readonly originalAction?: Action;
|
|
37
|
+
readonly currentTarget: FormModel | FieldModel | FieldsetModel;
|
|
36
38
|
}
|
|
37
39
|
export type callbackFn = (action: Action) => void;
|
|
38
40
|
export interface WithController {
|
|
@@ -82,7 +84,7 @@ export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJ
|
|
|
82
84
|
readonly editValue?: string;
|
|
83
85
|
}
|
|
84
86
|
export interface FormMetaDataModel {
|
|
85
|
-
readonly version
|
|
87
|
+
readonly version?: string;
|
|
86
88
|
readonly grammar: string;
|
|
87
89
|
}
|
|
88
90
|
export interface SubmitMetaDataModel {
|
|
@@ -105,6 +107,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
|
|
|
105
107
|
readonly metadata?: MetaDataJson;
|
|
106
108
|
readonly title: string;
|
|
107
109
|
readonly logger: Logger;
|
|
110
|
+
readonly specVersion: Version;
|
|
108
111
|
importData(data: any): any;
|
|
109
112
|
exportData(): any;
|
|
110
113
|
getElement(id: string): FieldModel | FormModel | FieldsetModel;
|
|
@@ -113,6 +116,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
|
|
|
113
116
|
visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
|
|
114
117
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
|
115
118
|
fieldAdded(field: FieldModel | FieldsetModel): void;
|
|
119
|
+
readonly changeEventBehaviour: 'deps' | 'self';
|
|
116
120
|
}
|
|
117
121
|
export interface IFormFieldFactory {
|
|
118
122
|
createField(child: FieldsetJson | FieldJson, options: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Version {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(n: string);
|
|
4
|
+
get major(): number;
|
|
5
|
+
get minor(): number;
|
|
6
|
+
get subversion(): number;
|
|
7
|
+
completeMatch(v: Version): boolean;
|
|
8
|
+
lessThan(v: Version): boolean;
|
|
9
|
+
toString(): string;
|
|
10
|
+
valueOf(): string;
|
|
11
|
+
}
|
package/lib/BaseNode.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
50
50
|
set label(l: import("./types/Json").Label | undefined);
|
|
51
51
|
get uniqueItems(): boolean | undefined;
|
|
52
52
|
isTransparent(): boolean;
|
|
53
|
+
getDependents(): string[];
|
|
53
54
|
getState(forRestore?: boolean): T & {
|
|
54
55
|
_dependents?: string[] | undefined;
|
|
55
56
|
allowedComponents?: undefined;
|