@astroapps/forms-core 1.2.2 → 2.0.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/TODO.txt +6 -1
- package/jest.config.js +8 -0
- package/lib/controlBuilder.d.ts +60 -0
- package/lib/controlDefinition.d.ts +32 -8
- package/lib/evalExpression.d.ts +3 -2
- package/lib/formNode.d.ts +0 -7
- package/lib/formStateNode.d.ts +134 -0
- package/lib/index.cjs +1023 -325
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +853 -284
- package/lib/index.js.map +1 -1
- package/lib/overrideProxy.d.ts +7 -0
- package/lib/resolveChildren.d.ts +19 -0
- package/lib/schemaDataNode.d.ts +3 -0
- package/lib/schemaNode.d.ts +8 -1
- package/lib/schemaValidator.d.ts +3 -0
- package/lib/validators.d.ts +4 -5
- package/package.json +5 -5
- package/src/controlBuilder.ts +218 -0
- package/src/controlDefinition.ts +38 -8
- package/src/defaultSchemaInterface.ts +4 -3
- package/src/evalExpression.ts +38 -8
- package/src/formNode.ts +14 -54
- package/src/formStateNode.ts +807 -0
- package/src/index.ts +5 -1
- package/src/overrideProxy.ts +40 -0
- package/src/resolveChildren.ts +141 -0
- package/src/schemaBuilder.ts +3 -0
- package/src/schemaDataNode.ts +13 -1
- package/src/schemaNode.ts +59 -1
- package/src/schemaValidator.ts +19 -0
- package/src/validators.ts +20 -26
- package/tsconfig.test.json +21 -0
- package/lib/formState.d.ts +0 -48
- package/src/formState.ts +0 -529
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ensureMetaValue, newControl, updateComputedValue, addDependent, createSyncEffect,
|
|
1
|
+
import { ensureMetaValue, newControl, updateComputedValue, addDependent, createAsyncEffect, createSyncEffect, trackedValue, collectChanges, getCurrentFields, createCleanupScope, createEffect, trackControlChange, ControlChange, createScopedEffect, updateElements } from '@astroapps/controls';
|
|
2
2
|
import jsonata from 'jsonata';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
|
|
@@ -21,6 +21,7 @@ var DynamicPropertyType;
|
|
|
21
21
|
DynamicPropertyType["AllowedOptions"] = "AllowedOptions";
|
|
22
22
|
DynamicPropertyType["Label"] = "Label";
|
|
23
23
|
DynamicPropertyType["ActionData"] = "ActionData";
|
|
24
|
+
DynamicPropertyType["GridColumns"] = "GridColumns";
|
|
24
25
|
})(DynamicPropertyType || (DynamicPropertyType = {}));
|
|
25
26
|
var AdornmentPlacement;
|
|
26
27
|
(function (AdornmentPlacement) {
|
|
@@ -66,6 +67,7 @@ var DataRenderType;
|
|
|
66
67
|
DataRenderType["Array"] = "Array";
|
|
67
68
|
DataRenderType["ArrayElement"] = "ArrayElement";
|
|
68
69
|
DataRenderType["ElementSelected"] = "ElementSelected";
|
|
70
|
+
DataRenderType["ScrollList"] = "ScrollList";
|
|
69
71
|
})(DataRenderType || (DataRenderType = {}));
|
|
70
72
|
var SyncTextType;
|
|
71
73
|
(function (SyncTextType) {
|
|
@@ -85,6 +87,7 @@ var GroupRenderType;
|
|
|
85
87
|
GroupRenderType["Wizard"] = "Wizard";
|
|
86
88
|
GroupRenderType["Dialog"] = "Dialog";
|
|
87
89
|
GroupRenderType["Contents"] = "Contents";
|
|
90
|
+
GroupRenderType["Accordion"] = "Accordion";
|
|
88
91
|
})(GroupRenderType || (GroupRenderType = {}));
|
|
89
92
|
var DisplayDataType;
|
|
90
93
|
(function (DisplayDataType) {
|
|
@@ -93,6 +96,12 @@ var DisplayDataType;
|
|
|
93
96
|
DisplayDataType["Icon"] = "Icon";
|
|
94
97
|
DisplayDataType["Custom"] = "Custom";
|
|
95
98
|
})(DisplayDataType || (DisplayDataType = {}));
|
|
99
|
+
var ControlDisableType;
|
|
100
|
+
(function (ControlDisableType) {
|
|
101
|
+
ControlDisableType["None"] = "None";
|
|
102
|
+
ControlDisableType["Self"] = "Self";
|
|
103
|
+
ControlDisableType["Global"] = "Global";
|
|
104
|
+
})(ControlDisableType || (ControlDisableType = {}));
|
|
96
105
|
var ActionStyle;
|
|
97
106
|
(function (ActionStyle) {
|
|
98
107
|
ActionStyle["Button"] = "Button";
|
|
@@ -129,6 +138,9 @@ function isWizardRenderer(options) {
|
|
|
129
138
|
function isDialogRenderer(options) {
|
|
130
139
|
return options.type === GroupRenderType.Dialog;
|
|
131
140
|
}
|
|
141
|
+
function isAccordionRenderer(options) {
|
|
142
|
+
return options.type === GroupRenderType.Accordion;
|
|
143
|
+
}
|
|
132
144
|
function isInlineRenderer(options) {
|
|
133
145
|
return options.type === GroupRenderType.Inline;
|
|
134
146
|
}
|
|
@@ -229,7 +241,7 @@ function fontAwesomeIcon(icon) {
|
|
|
229
241
|
* @returns True if the control definition is readonly, false otherwise.
|
|
230
242
|
*/
|
|
231
243
|
function isControlReadonly(c) {
|
|
232
|
-
return
|
|
244
|
+
return !!c.readonly;
|
|
233
245
|
}
|
|
234
246
|
/**
|
|
235
247
|
* Checks if a control definition is disabled.
|
|
@@ -237,7 +249,7 @@ function isControlReadonly(c) {
|
|
|
237
249
|
* @returns True if the control definition is disabled, false otherwise.
|
|
238
250
|
*/
|
|
239
251
|
function isControlDisabled(c) {
|
|
240
|
-
return
|
|
252
|
+
return !!c.disabled;
|
|
241
253
|
}
|
|
242
254
|
/**
|
|
243
255
|
* Returns the group renderer options for a control definition.
|
|
@@ -265,6 +277,49 @@ function getDisplayOnlyOptions(d) {
|
|
|
265
277
|
return isDataControl(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
|
|
266
278
|
}
|
|
267
279
|
|
|
280
|
+
function _extends() {
|
|
281
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
282
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
283
|
+
var t = arguments[e];
|
|
284
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
285
|
+
}
|
|
286
|
+
return n;
|
|
287
|
+
}, _extends.apply(null, arguments);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var ValidatorType;
|
|
291
|
+
(function (ValidatorType) {
|
|
292
|
+
ValidatorType["Jsonata"] = "Jsonata";
|
|
293
|
+
ValidatorType["Date"] = "Date";
|
|
294
|
+
ValidatorType["Length"] = "Length";
|
|
295
|
+
})(ValidatorType || (ValidatorType = {}));
|
|
296
|
+
var DateComparison;
|
|
297
|
+
(function (DateComparison) {
|
|
298
|
+
DateComparison["NotBefore"] = "NotBefore";
|
|
299
|
+
DateComparison["NotAfter"] = "NotAfter";
|
|
300
|
+
})(DateComparison || (DateComparison = {}));
|
|
301
|
+
function jsonataValidator$1(expr) {
|
|
302
|
+
return {
|
|
303
|
+
type: ValidatorType.Jsonata,
|
|
304
|
+
expression: expr
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function dateValidator$1(comparison, fixedDate, daysFromCurrent) {
|
|
308
|
+
return {
|
|
309
|
+
type: ValidatorType.Date,
|
|
310
|
+
comparison,
|
|
311
|
+
fixedDate,
|
|
312
|
+
daysFromCurrent
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function lengthValidator$1(min, max) {
|
|
316
|
+
return {
|
|
317
|
+
type: ValidatorType.Length,
|
|
318
|
+
min,
|
|
319
|
+
max
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
268
323
|
var ExpressionType;
|
|
269
324
|
(function (ExpressionType) {
|
|
270
325
|
ExpressionType["Jsonata"] = "Jsonata";
|
|
@@ -275,6 +330,157 @@ var ExpressionType;
|
|
|
275
330
|
ExpressionType["UUID"] = "UUID";
|
|
276
331
|
})(ExpressionType || (ExpressionType = {}));
|
|
277
332
|
|
|
333
|
+
function dataControl(field, title, options) {
|
|
334
|
+
return _extends({
|
|
335
|
+
type: ControlDefinitionType.Data,
|
|
336
|
+
field,
|
|
337
|
+
title
|
|
338
|
+
}, options);
|
|
339
|
+
}
|
|
340
|
+
function validatorOptions(type) {
|
|
341
|
+
return o => _extends({
|
|
342
|
+
type
|
|
343
|
+
}, o);
|
|
344
|
+
}
|
|
345
|
+
function adornmentOptions(type) {
|
|
346
|
+
return o => _extends({
|
|
347
|
+
type
|
|
348
|
+
}, o);
|
|
349
|
+
}
|
|
350
|
+
function renderOptionsFor(type) {
|
|
351
|
+
return o => ({
|
|
352
|
+
renderOptions: _extends({
|
|
353
|
+
type
|
|
354
|
+
}, o)
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
const autocompleteOptions = renderOptionsFor(DataRenderType.Autocomplete);
|
|
358
|
+
const checkListOptions = renderOptionsFor(DataRenderType.CheckList);
|
|
359
|
+
const radioButtonOptions = renderOptionsFor(DataRenderType.Radio);
|
|
360
|
+
const lengthValidatorOptions = validatorOptions(ValidatorType.Length);
|
|
361
|
+
const jsonataValidatorOptions = validatorOptions(ValidatorType.Jsonata);
|
|
362
|
+
const dateValidatorOptions = validatorOptions(ValidatorType.Date);
|
|
363
|
+
const accordionOptions = adornmentOptions(ControlAdornmentType.Accordion);
|
|
364
|
+
const textfieldOptions = renderOptionsFor(DataRenderType.Textfield);
|
|
365
|
+
const displayOnlyOptions = renderOptionsFor(DataRenderType.DisplayOnly);
|
|
366
|
+
const jsonataOptions = renderOptionsFor(DataRenderType.Jsonata);
|
|
367
|
+
function textDisplayControl(text, options) {
|
|
368
|
+
return _extends({
|
|
369
|
+
type: ControlDefinitionType.Display,
|
|
370
|
+
displayData: {
|
|
371
|
+
type: DisplayDataType.Text,
|
|
372
|
+
text
|
|
373
|
+
}
|
|
374
|
+
}, options);
|
|
375
|
+
}
|
|
376
|
+
function htmlDisplayControl(html, options) {
|
|
377
|
+
return _extends({
|
|
378
|
+
type: ControlDefinitionType.Display,
|
|
379
|
+
displayData: {
|
|
380
|
+
type: DisplayDataType.Html,
|
|
381
|
+
html
|
|
382
|
+
}
|
|
383
|
+
}, options);
|
|
384
|
+
}
|
|
385
|
+
function dynamicDefaultValue(expr) {
|
|
386
|
+
return {
|
|
387
|
+
type: DynamicPropertyType.DefaultValue,
|
|
388
|
+
expr
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function dynamicReadonly(expr) {
|
|
392
|
+
return {
|
|
393
|
+
type: DynamicPropertyType.Readonly,
|
|
394
|
+
expr
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function dynamicVisibility(expr) {
|
|
398
|
+
return {
|
|
399
|
+
type: DynamicPropertyType.Visible,
|
|
400
|
+
expr
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function dynamicDisabled(expr) {
|
|
404
|
+
return {
|
|
405
|
+
type: DynamicPropertyType.Disabled,
|
|
406
|
+
expr
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function dataExpr(field) {
|
|
410
|
+
return {
|
|
411
|
+
type: ExpressionType.Data,
|
|
412
|
+
field
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated Use dataExpr
|
|
417
|
+
*/
|
|
418
|
+
const fieldExpr = dataExpr;
|
|
419
|
+
/**
|
|
420
|
+
* @deprecated Use dataMatchExpr
|
|
421
|
+
*/
|
|
422
|
+
const fieldEqExpr = dataMatchExpr;
|
|
423
|
+
const uuidExpr = {
|
|
424
|
+
type: ExpressionType.UUID
|
|
425
|
+
};
|
|
426
|
+
function dataMatchExpr(field, value) {
|
|
427
|
+
return {
|
|
428
|
+
type: ExpressionType.DataMatch,
|
|
429
|
+
field,
|
|
430
|
+
value
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function notEmptyExpr(field, empty) {
|
|
434
|
+
return {
|
|
435
|
+
type: ExpressionType.NotEmpty,
|
|
436
|
+
field,
|
|
437
|
+
empty
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function jsonataExpr(expression) {
|
|
441
|
+
return {
|
|
442
|
+
type: ExpressionType.Jsonata,
|
|
443
|
+
expression
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function groupedControl(children, title, options) {
|
|
447
|
+
return _extends({
|
|
448
|
+
type: ControlDefinitionType.Group,
|
|
449
|
+
children,
|
|
450
|
+
title,
|
|
451
|
+
groupOptions: {
|
|
452
|
+
type: "Standard",
|
|
453
|
+
hideTitle: !title
|
|
454
|
+
}
|
|
455
|
+
}, options);
|
|
456
|
+
}
|
|
457
|
+
function compoundControl(field, title, children, options) {
|
|
458
|
+
return _extends({
|
|
459
|
+
type: ControlDefinitionType.Data,
|
|
460
|
+
field,
|
|
461
|
+
children,
|
|
462
|
+
title,
|
|
463
|
+
renderOptions: {
|
|
464
|
+
type: "Standard"
|
|
465
|
+
}
|
|
466
|
+
}, options);
|
|
467
|
+
}
|
|
468
|
+
function actionControl(actionText, actionId, options) {
|
|
469
|
+
return _extends({
|
|
470
|
+
type: ControlDefinitionType.Action,
|
|
471
|
+
title: actionText,
|
|
472
|
+
actionId
|
|
473
|
+
}, options);
|
|
474
|
+
}
|
|
475
|
+
const emptyGroupDefinition = {
|
|
476
|
+
type: ControlDefinitionType.Group,
|
|
477
|
+
children: [],
|
|
478
|
+
groupOptions: {
|
|
479
|
+
type: GroupRenderType.Standard,
|
|
480
|
+
hideTitle: true
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
278
484
|
/**
|
|
279
485
|
* Enum representing the various field types.
|
|
280
486
|
*/
|
|
@@ -366,20 +572,23 @@ function createSchemaTree(rootFields, lookup) {
|
|
|
366
572
|
return new SchemaTreeImpl(rootFields, lookup);
|
|
367
573
|
}
|
|
368
574
|
class SchemaNode {
|
|
369
|
-
constructor(id, field, tree, parent) {
|
|
575
|
+
constructor(id, field, tree, parent, getChildFields) {
|
|
370
576
|
this.id = void 0;
|
|
371
577
|
this.field = void 0;
|
|
372
578
|
this.tree = void 0;
|
|
373
579
|
this.parent = void 0;
|
|
580
|
+
this.getChildFields = void 0;
|
|
374
581
|
this.id = id;
|
|
375
582
|
this.field = field;
|
|
376
583
|
this.tree = tree;
|
|
377
584
|
this.parent = parent;
|
|
585
|
+
this.getChildFields = getChildFields;
|
|
378
586
|
}
|
|
379
587
|
getSchema(schemaId) {
|
|
380
588
|
return this.tree.getSchema(schemaId);
|
|
381
589
|
}
|
|
382
590
|
getUnresolvedFields() {
|
|
591
|
+
if (this.getChildFields) return this.getChildFields();
|
|
383
592
|
return isCompoundField(this.field) ? this.field.children : [];
|
|
384
593
|
}
|
|
385
594
|
getResolvedParent(noRecurse) {
|
|
@@ -468,6 +677,52 @@ function schemaForFieldPath(fieldPath, schema) {
|
|
|
468
677
|
}
|
|
469
678
|
return schema;
|
|
470
679
|
}
|
|
680
|
+
function schemaForDataPath(fieldPath, schema) {
|
|
681
|
+
let i = 0;
|
|
682
|
+
let element = schema.field.collection;
|
|
683
|
+
while (i < fieldPath.length) {
|
|
684
|
+
const nextField = fieldPath[i];
|
|
685
|
+
let childNode;
|
|
686
|
+
if (nextField == ".") {
|
|
687
|
+
i++;
|
|
688
|
+
continue;
|
|
689
|
+
} else if (nextField == "..") {
|
|
690
|
+
if (element) {
|
|
691
|
+
element = false;
|
|
692
|
+
i++;
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
childNode = schema.parent;
|
|
696
|
+
} else {
|
|
697
|
+
childNode = schema.getChildNode(nextField);
|
|
698
|
+
}
|
|
699
|
+
if (!childNode) {
|
|
700
|
+
childNode = createSchemaNode(missingField(nextField), schema.tree, schema);
|
|
701
|
+
} else {
|
|
702
|
+
element = childNode.field.collection;
|
|
703
|
+
}
|
|
704
|
+
schema = childNode;
|
|
705
|
+
i++;
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
node: schema,
|
|
709
|
+
element: !!element
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function getParentDataPath({
|
|
713
|
+
node,
|
|
714
|
+
element
|
|
715
|
+
}) {
|
|
716
|
+
if (element) return {
|
|
717
|
+
node,
|
|
718
|
+
element: false
|
|
719
|
+
};
|
|
720
|
+
const parent = node.parent;
|
|
721
|
+
return parent ? {
|
|
722
|
+
node: parent,
|
|
723
|
+
element: !!parent.field.collection
|
|
724
|
+
} : undefined;
|
|
725
|
+
}
|
|
471
726
|
function getSchemaNodePath(node) {
|
|
472
727
|
const paths = [];
|
|
473
728
|
let curNode = node;
|
|
@@ -510,16 +765,6 @@ function relativeSegmentPath(parentPath, childPath) {
|
|
|
510
765
|
return "../".repeat(upLevels) + downPath;
|
|
511
766
|
}
|
|
512
767
|
|
|
513
|
-
function _extends() {
|
|
514
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
515
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
516
|
-
var t = arguments[e];
|
|
517
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
518
|
-
}
|
|
519
|
-
return n;
|
|
520
|
-
}, _extends.apply(null, arguments);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
768
|
function buildSchema(def) {
|
|
524
769
|
return Object.entries(def).map(x => x[1](x[0]));
|
|
525
770
|
}
|
|
@@ -621,6 +866,9 @@ function mergeOption(fields, name, value, fieldName) {
|
|
|
621
866
|
return fields.map(x => x.field === fieldName ? addFieldOption(x, name, value) : x);
|
|
622
867
|
}
|
|
623
868
|
function mergeFields(fields, name, value, newFields) {
|
|
869
|
+
if (name === "*") {
|
|
870
|
+
return newFields.reduce((af, x) => mergeField(x, af), fields);
|
|
871
|
+
}
|
|
624
872
|
const withType = fields.map(x => x.isTypeField ? addFieldOption(x, name, value) : x);
|
|
625
873
|
return newFields.map(x => _extends({}, x, {
|
|
626
874
|
onlyForTypes: [value]
|
|
@@ -660,18 +908,6 @@ function resolveSchemas(schemaMap) {
|
|
|
660
908
|
return out;
|
|
661
909
|
}
|
|
662
910
|
|
|
663
|
-
var ValidatorType;
|
|
664
|
-
(function (ValidatorType) {
|
|
665
|
-
ValidatorType["Jsonata"] = "Jsonata";
|
|
666
|
-
ValidatorType["Date"] = "Date";
|
|
667
|
-
ValidatorType["Length"] = "Length";
|
|
668
|
-
})(ValidatorType || (ValidatorType = {}));
|
|
669
|
-
var DateComparison;
|
|
670
|
-
(function (DateComparison) {
|
|
671
|
-
DateComparison["NotBefore"] = "NotBefore";
|
|
672
|
-
DateComparison["NotAfter"] = "NotAfter";
|
|
673
|
-
})(DateComparison || (DateComparison = {}));
|
|
674
|
-
|
|
675
911
|
class SchemaDataTree {}
|
|
676
912
|
class SchemaDataNode {
|
|
677
913
|
constructor(id, schema, elementIndex, control, tree, parent) {
|
|
@@ -715,7 +951,7 @@ class SchemaDataTreeImpl extends SchemaDataTree {
|
|
|
715
951
|
getChildElement(parent, elementIndex) {
|
|
716
952
|
const elemControl = parent.control;
|
|
717
953
|
const elemChild = elemControl.elements[elementIndex];
|
|
718
|
-
return new SchemaDataNode(elemChild.uniqueId.toString(), parent.schema, elementIndex, elemChild, this, parent);
|
|
954
|
+
return new SchemaDataNode(elemChild.uniqueId.toString() + "_" + elementIndex, parent.schema, elementIndex, elemChild, this, parent);
|
|
719
955
|
}
|
|
720
956
|
}
|
|
721
957
|
/**
|
|
@@ -774,6 +1010,15 @@ function hideDisplayOnly(context, schemaInterface, definition) {
|
|
|
774
1010
|
const displayOptions = getDisplayOnlyOptions(definition);
|
|
775
1011
|
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(context.schema.field, (_context$control = context.control) == null ? void 0 : _context$control.value);
|
|
776
1012
|
}
|
|
1013
|
+
function getLoadingControl(data) {
|
|
1014
|
+
return ensureMetaValue(data, "loading", () => newControl(false));
|
|
1015
|
+
}
|
|
1016
|
+
function getRefreshingControl(data) {
|
|
1017
|
+
return ensureMetaValue(data, "refreshing", () => newControl(false));
|
|
1018
|
+
}
|
|
1019
|
+
function getHasMoreControl(data) {
|
|
1020
|
+
return ensureMetaValue(data, "hasMore", () => newControl(false));
|
|
1021
|
+
}
|
|
777
1022
|
|
|
778
1023
|
class DefaultSchemaInterface {
|
|
779
1024
|
constructor(boolStrings = ["No", "Yes"], parseDateTime = s => Date.parse(s)) {
|
|
@@ -847,7 +1092,7 @@ class DefaultSchemaInterface {
|
|
|
847
1092
|
case FieldType.Time:
|
|
848
1093
|
return value ? new Date("1970-01-01T" + value).toLocaleTimeString() : undefined;
|
|
849
1094
|
case FieldType.Bool:
|
|
850
|
-
return this.boolStrings[value ? 1 : 0];
|
|
1095
|
+
return value != null ? this.boolStrings[value ? 1 : 0] : undefined;
|
|
851
1096
|
default:
|
|
852
1097
|
return value != null ? value.toString() : undefined;
|
|
853
1098
|
}
|
|
@@ -857,8 +1102,8 @@ class DefaultSchemaInterface {
|
|
|
857
1102
|
return f.collection ? (_control$elements$len = (_control$elements = control.elements) == null ? void 0 : _control$elements.length) != null ? _control$elements$len : 0 : this.valueLength(f, control.value);
|
|
858
1103
|
}
|
|
859
1104
|
valueLength(field, value) {
|
|
860
|
-
|
|
861
|
-
return
|
|
1105
|
+
const len = value == null ? void 0 : value.length;
|
|
1106
|
+
return typeof len === "number" ? len : 0;
|
|
862
1107
|
}
|
|
863
1108
|
compareValue(field, v1, v2) {
|
|
864
1109
|
if (v1 == null) return v2 == null ? 0 : 1;
|
|
@@ -870,7 +1115,7 @@ class DefaultSchemaInterface {
|
|
|
870
1115
|
case FieldType.String:
|
|
871
1116
|
return v1.localeCompare(v2);
|
|
872
1117
|
case FieldType.Bool:
|
|
873
|
-
return v1
|
|
1118
|
+
return v1 === v2 ? 0 : !v1 ? -1 : 1;
|
|
874
1119
|
case FieldType.Int:
|
|
875
1120
|
case FieldType.Double:
|
|
876
1121
|
return v1 - v2;
|
|
@@ -1002,12 +1247,12 @@ class FormTreeImpl extends FormTree {
|
|
|
1002
1247
|
}
|
|
1003
1248
|
}
|
|
1004
1249
|
function legacyFormNode(definition) {
|
|
1005
|
-
return createFormTree([definition]).rootNode
|
|
1250
|
+
return createFormTree([definition]).rootNode;
|
|
1006
1251
|
}
|
|
1007
1252
|
function createFormTree(controls, getForm = {
|
|
1008
1253
|
getForm: () => undefined
|
|
1009
1254
|
}) {
|
|
1010
|
-
return new FormTreeImpl(getForm, {
|
|
1255
|
+
return new FormTreeImpl(getForm, controls.length === 1 ? controls[0] : {
|
|
1011
1256
|
type: ControlDefinitionType.Group,
|
|
1012
1257
|
children: controls,
|
|
1013
1258
|
groupOptions: {
|
|
@@ -1077,35 +1322,6 @@ function visitFormDataInContext(parentContext, node, cb) {
|
|
|
1077
1322
|
const dataNode = lookupDataNode(node.definition, parentContext);
|
|
1078
1323
|
return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
|
|
1079
1324
|
}
|
|
1080
|
-
function visitFormDataNode(node, visitFn) {
|
|
1081
|
-
const dataNode = lookupDataNode(node.formNode.definition, node.parentData);
|
|
1082
|
-
const v = visitFn(node, dataNode);
|
|
1083
|
-
if (v !== undefined) return v;
|
|
1084
|
-
const parentData = dataNode != null ? dataNode : node.parentData;
|
|
1085
|
-
if (parentData.schema.field.collection && parentData.elementIndex == null) {
|
|
1086
|
-
const elemCount = parentData.control.elements.length;
|
|
1087
|
-
for (let i = 0; i < elemCount; i++) {
|
|
1088
|
-
const _v = visitChildren(parentData.getChildElement(i));
|
|
1089
|
-
if (_v !== undefined) return _v;
|
|
1090
|
-
}
|
|
1091
|
-
return undefined;
|
|
1092
|
-
} else {
|
|
1093
|
-
return visitChildren(parentData);
|
|
1094
|
-
}
|
|
1095
|
-
function visitChildren(parentData) {
|
|
1096
|
-
const children = node.formNode.getChildNodes();
|
|
1097
|
-
for (let i = 0; i < children.length; i++) {
|
|
1098
|
-
const child = children[i];
|
|
1099
|
-
const res = visitFormDataNode({
|
|
1100
|
-
formNode: child,
|
|
1101
|
-
parent: node,
|
|
1102
|
-
parentData,
|
|
1103
|
-
childIndex: i
|
|
1104
|
-
}, visitFn);
|
|
1105
|
-
if (res !== undefined) return res;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
1325
|
|
|
1110
1326
|
/**
|
|
1111
1327
|
* Converts a JSON path array to a string.
|
|
@@ -1202,9 +1418,14 @@ const jsonataEval = (expr, {
|
|
|
1202
1418
|
}
|
|
1203
1419
|
});
|
|
1204
1420
|
async function runJsonata(effect, signal) {
|
|
1205
|
-
const
|
|
1206
|
-
const evalResult = await parsedJsonata.fields.expr.value.evaluate(trackedValue(rootData, effect.collectUsage),
|
|
1207
|
-
// console.log(
|
|
1421
|
+
const trackedVars = variables == null ? void 0 : variables(effect.collectUsage);
|
|
1422
|
+
const evalResult = await parsedJsonata.fields.expr.value.evaluate(trackedValue(rootData, effect.collectUsage), trackedVars);
|
|
1423
|
+
// console.log(
|
|
1424
|
+
// rootData,
|
|
1425
|
+
// parsedJsonata.fields.fullExpr.current.value,
|
|
1426
|
+
// evalResult,
|
|
1427
|
+
// trackedVars,
|
|
1428
|
+
// );
|
|
1208
1429
|
collectChanges(effect.collectUsage, () => returnResult(evalResult));
|
|
1209
1430
|
}
|
|
1210
1431
|
const asyncEffect = createAsyncEffect(runJsonata, scope);
|
|
@@ -1220,6 +1441,54 @@ const defaultEvaluators = {
|
|
|
1220
1441
|
[ExpressionType.Jsonata]: jsonataEval,
|
|
1221
1442
|
[ExpressionType.UUID]: uuidEval
|
|
1222
1443
|
};
|
|
1444
|
+
function createEvalExpr(evalExpression, context) {
|
|
1445
|
+
function evalExpr(scope, init, nk, e, coerce) {
|
|
1446
|
+
nk.value = init;
|
|
1447
|
+
if (e != null && e.type) {
|
|
1448
|
+
evalExpression(e, _extends({
|
|
1449
|
+
returnResult: r => {
|
|
1450
|
+
nk.value = coerce(r);
|
|
1451
|
+
},
|
|
1452
|
+
scope
|
|
1453
|
+
}, context));
|
|
1454
|
+
return true;
|
|
1455
|
+
}
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
return evalExpr;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function createOverrideProxy(proxyFor, handlers) {
|
|
1462
|
+
const overrides = getCurrentFields(handlers);
|
|
1463
|
+
const allOwn = Reflect.ownKeys(proxyFor);
|
|
1464
|
+
Reflect.ownKeys(overrides).forEach(k => {
|
|
1465
|
+
if (!allOwn.includes(k)) allOwn.push(k);
|
|
1466
|
+
});
|
|
1467
|
+
return new Proxy(proxyFor, {
|
|
1468
|
+
get(target, p, receiver) {
|
|
1469
|
+
if (Object.hasOwn(overrides, p)) {
|
|
1470
|
+
const nv = overrides[p].value;
|
|
1471
|
+
if (nv !== NoOverride) return nv;
|
|
1472
|
+
}
|
|
1473
|
+
return Reflect.get(target, p, receiver);
|
|
1474
|
+
},
|
|
1475
|
+
ownKeys(target) {
|
|
1476
|
+
return allOwn;
|
|
1477
|
+
},
|
|
1478
|
+
has(target, p) {
|
|
1479
|
+
return Reflect.has(proxyFor, p) || Reflect.has(overrides, p);
|
|
1480
|
+
},
|
|
1481
|
+
getOwnPropertyDescriptor(target, k) {
|
|
1482
|
+
if (Object.hasOwn(overrides, k)) return {
|
|
1483
|
+
enumerable: true,
|
|
1484
|
+
configurable: true
|
|
1485
|
+
};
|
|
1486
|
+
return Reflect.getOwnPropertyDescriptor(target, k);
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
class NoValue {}
|
|
1491
|
+
const NoOverride = new NoValue();
|
|
1223
1492
|
|
|
1224
1493
|
const jsonataValidator = (validation, context) => {
|
|
1225
1494
|
const error = createScopedComputed(context, () => undefined);
|
|
@@ -1235,7 +1504,7 @@ const jsonataValidator = (validation, context) => {
|
|
|
1235
1504
|
context.data.control.setError("jsonata", v == null ? void 0 : v.toString());
|
|
1236
1505
|
},
|
|
1237
1506
|
schemaInterface: context.schemaInterface,
|
|
1238
|
-
variables: context.
|
|
1507
|
+
variables: context.variables,
|
|
1239
1508
|
runAsync: context.runAsync
|
|
1240
1509
|
});
|
|
1241
1510
|
};
|
|
@@ -1303,7 +1572,7 @@ function createValidators(def, context) {
|
|
|
1303
1572
|
if (def.required) {
|
|
1304
1573
|
context.addSync(v => {
|
|
1305
1574
|
const field = context.data.schema.field;
|
|
1306
|
-
return schemaInterface.isEmptyValue(field, v) ? schemaInterface.validationMessageText(field, ValidationMessageType.NotEmpty, false, true) : null;
|
|
1575
|
+
return schemaInterface.isEmptyValue(field, v) ? def.requiredErrorText ? def.requiredErrorText : schemaInterface.validationMessageText(field, ValidationMessageType.NotEmpty, false, true) : null;
|
|
1307
1576
|
});
|
|
1308
1577
|
}
|
|
1309
1578
|
(_def$validators = def.validators) == null || _def$validators.forEach(x => {
|
|
@@ -1312,15 +1581,15 @@ function createValidators(def, context) {
|
|
|
1312
1581
|
});
|
|
1313
1582
|
}
|
|
1314
1583
|
}
|
|
1315
|
-
function setupValidation(
|
|
1316
|
-
const validationEnabled = createScopedComputed(
|
|
1584
|
+
function setupValidation(scope, variables, definition, dataNode, schemaInterface, parent, visible, runAsync) {
|
|
1585
|
+
const validationEnabled = createScopedComputed(scope, () => !!visible.value);
|
|
1317
1586
|
const validatorsScope = createCleanupScope();
|
|
1318
1587
|
createEffect(() => {
|
|
1319
1588
|
validatorsScope.cleanup();
|
|
1320
1589
|
const dn = dataNode.value;
|
|
1321
1590
|
if (dn) {
|
|
1322
1591
|
let syncValidations = [];
|
|
1323
|
-
createValidators(
|
|
1592
|
+
createValidators(definition, {
|
|
1324
1593
|
data: dn,
|
|
1325
1594
|
parentData: parent,
|
|
1326
1595
|
validationEnabled,
|
|
@@ -1331,7 +1600,7 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
|
|
|
1331
1600
|
addCleanup(cleanup) {
|
|
1332
1601
|
validatorsScope.addCleanup(cleanup);
|
|
1333
1602
|
},
|
|
1334
|
-
|
|
1603
|
+
variables,
|
|
1335
1604
|
runAsync
|
|
1336
1605
|
});
|
|
1337
1606
|
createEffect(() => {
|
|
@@ -1348,234 +1617,534 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
|
|
|
1348
1617
|
dn.control.setError("default", e);
|
|
1349
1618
|
}, validatorsScope);
|
|
1350
1619
|
}
|
|
1351
|
-
}, c => {},
|
|
1620
|
+
}, c => {}, scope);
|
|
1352
1621
|
}
|
|
1353
1622
|
|
|
1354
|
-
function
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1623
|
+
function createEvaluatedDefinition(def, evalExpr, scope, display) {
|
|
1624
|
+
const definitionOverrides = createScoped(scope, {});
|
|
1625
|
+
const displayOverrides = createScoped(scope, {});
|
|
1626
|
+
const groupOptionsOverrides = createScoped(scope, {});
|
|
1627
|
+
const renderOptionsOverrides = createScoped(scope, {});
|
|
1628
|
+
const {
|
|
1629
|
+
hidden,
|
|
1630
|
+
displayData,
|
|
1631
|
+
readonly,
|
|
1632
|
+
disabled,
|
|
1633
|
+
defaultValue,
|
|
1634
|
+
actionData,
|
|
1635
|
+
title,
|
|
1636
|
+
groupOptions,
|
|
1637
|
+
renderOptions
|
|
1638
|
+
} = definitionOverrides.fields;
|
|
1639
|
+
const {
|
|
1640
|
+
columns
|
|
1641
|
+
} = groupOptionsOverrides.fields;
|
|
1642
|
+
const {
|
|
1643
|
+
groupOptions: dataGroupRenderOptions
|
|
1644
|
+
} = renderOptionsOverrides.fields;
|
|
1645
|
+
const {
|
|
1646
|
+
html,
|
|
1647
|
+
text
|
|
1648
|
+
} = displayOverrides.fields;
|
|
1649
|
+
updateComputedValue(dataGroupRenderOptions, () => {
|
|
1650
|
+
var _def$renderOptions$gr;
|
|
1651
|
+
return isDataControl(def) && isDataGroupRenderer(def.renderOptions) ? createOverrideProxy((_def$renderOptions$gr = def.renderOptions.groupOptions) != null ? _def$renderOptions$gr : {}, groupOptionsOverrides) : undefined;
|
|
1652
|
+
});
|
|
1653
|
+
updateComputedValue(displayData, () => isDisplayControl(def) ? createOverrideProxy(def.displayData, displayOverrides) : undefined);
|
|
1654
|
+
updateComputedValue(groupOptions, () => {
|
|
1655
|
+
const groupOptions = getGroupRendererOptions(def);
|
|
1656
|
+
return groupOptions ? createOverrideProxy(groupOptions, groupOptionsOverrides) : undefined;
|
|
1657
|
+
});
|
|
1658
|
+
updateComputedValue(renderOptions, () => {
|
|
1659
|
+
var _def$renderOptions;
|
|
1660
|
+
return isDataControl(def) ? createOverrideProxy((_def$renderOptions = def.renderOptions) != null ? _def$renderOptions : {}, renderOptionsOverrides) : undefined;
|
|
1661
|
+
});
|
|
1662
|
+
evalDynamic(hidden, DynamicPropertyType.Visible,
|
|
1663
|
+
// Make sure it's not null if no scripting
|
|
1664
|
+
x => x ? def.hidden : !!def.hidden, r => !r);
|
|
1665
|
+
evalDynamic(readonly, DynamicPropertyType.Readonly, () => isControlReadonly(def), r => !!r);
|
|
1666
|
+
createScopedEffect(c => {
|
|
1667
|
+
evalExpr(c, isControlDisabled(def), disabled, firstExpr(DynamicPropertyType.Disabled), r => !!r);
|
|
1668
|
+
}, definitionOverrides);
|
|
1669
|
+
createScopedEffect(c => {
|
|
1670
|
+
const groupOptions = getGroupRendererOptions(def);
|
|
1671
|
+
evalExpr(c, groupOptions == null ? void 0 : groupOptions.columns, columns, groupOptions ? firstExpr(DynamicPropertyType.GridColumns) : undefined, r => typeof r === "number" ? r : undefined);
|
|
1672
|
+
}, groupOptionsOverrides);
|
|
1673
|
+
createScopedEffect(c => {
|
|
1674
|
+
evalExpr(c, isDataControl(def) ? def.defaultValue : undefined, defaultValue, isDataControl(def) ? firstExpr(DynamicPropertyType.DefaultValue) : undefined, r => r);
|
|
1675
|
+
}, definitionOverrides);
|
|
1676
|
+
createScopedEffect(c => {
|
|
1677
|
+
evalExpr(c, isActionControl(def) ? def.actionData : undefined, actionData, isActionControl(def) ? firstExpr(DynamicPropertyType.ActionData) : undefined, r => r);
|
|
1678
|
+
}, definitionOverrides);
|
|
1679
|
+
createScopedEffect(c => {
|
|
1680
|
+
evalExpr(c, def.title, title, firstExpr(DynamicPropertyType.Label), coerceString);
|
|
1681
|
+
}, definitionOverrides);
|
|
1682
|
+
createSyncEffect(() => {
|
|
1683
|
+
if (isDisplayControl(def)) {
|
|
1684
|
+
if (display.value !== undefined) {
|
|
1685
|
+
text.value = isTextDisplay(def.displayData) ? display.value : NoOverride;
|
|
1686
|
+
html.value = isHtmlDisplay(def.displayData) ? display.value : NoOverride;
|
|
1687
|
+
} else {
|
|
1688
|
+
text.value = NoOverride;
|
|
1689
|
+
html.value = NoOverride;
|
|
1399
1690
|
}
|
|
1400
|
-
return createScopedMetaValue(formNode, controlImpl, "impl", scope => {
|
|
1401
|
-
var _controlImpl$fields$v;
|
|
1402
|
-
const cf = controlImpl.fields;
|
|
1403
|
-
const definitionOverrides = createScoped(controlImpl, {});
|
|
1404
|
-
createScoped(controlImpl, undefined);
|
|
1405
|
-
const displayOverrides = createScoped(controlImpl, {});
|
|
1406
|
-
const def = formNode.definition;
|
|
1407
|
-
const definition = createOverrideProxy(def, definitionOverrides);
|
|
1408
|
-
const of = definitionOverrides.fields;
|
|
1409
|
-
const {
|
|
1410
|
-
text,
|
|
1411
|
-
html
|
|
1412
|
-
} = displayOverrides.fields;
|
|
1413
|
-
updateComputedValue(of.displayData, () => isDisplayControl(def) ? createOverrideProxy(def.displayData, displayOverrides) : undefined);
|
|
1414
|
-
createScopedEffect(c => {
|
|
1415
|
-
evalExpr(c, def.hidden, of.hidden, firstExpr(formNode, DynamicPropertyType.Visible), r => !r);
|
|
1416
|
-
}, definitionOverrides);
|
|
1417
|
-
createScopedEffect(c => {
|
|
1418
|
-
evalExpr(c, isControlReadonly(def), of.readonly, firstExpr(formNode, DynamicPropertyType.Readonly), r => !!r);
|
|
1419
|
-
}, definitionOverrides);
|
|
1420
|
-
createScopedEffect(c => {
|
|
1421
|
-
evalExpr(c, isControlDisabled(def), of.disabled, firstExpr(formNode, DynamicPropertyType.Disabled), r => !!r);
|
|
1422
|
-
}, definitionOverrides);
|
|
1423
|
-
createScopedEffect(c => {
|
|
1424
|
-
evalExpr(c, isDataControl(def) ? def.defaultValue : undefined, of.defaultValue, isDataControl(def) ? firstExpr(formNode, DynamicPropertyType.DefaultValue) : undefined, r => r);
|
|
1425
|
-
}, definitionOverrides);
|
|
1426
|
-
createScopedEffect(c => {
|
|
1427
|
-
evalExpr(c, isActionControl(def) ? def.actionData : undefined, of.actionData, isActionControl(def) ? firstExpr(formNode, DynamicPropertyType.ActionData) : undefined, r => r);
|
|
1428
|
-
}, definitionOverrides);
|
|
1429
|
-
createScopedEffect(c => {
|
|
1430
|
-
evalExpr(c, def.title, of.title, firstExpr(formNode, DynamicPropertyType.Label), coerceString);
|
|
1431
|
-
}, definitionOverrides);
|
|
1432
|
-
const control = createScoped(controlImpl, {
|
|
1433
|
-
definition,
|
|
1434
|
-
dataNode: undefined,
|
|
1435
|
-
schemaInterface,
|
|
1436
|
-
disabled: false,
|
|
1437
|
-
readonly: false,
|
|
1438
|
-
clearHidden: false,
|
|
1439
|
-
hidden: false,
|
|
1440
|
-
variables: (_controlImpl$fields$v = controlImpl.fields.variables.current.value) != null ? _controlImpl$fields$v : {},
|
|
1441
|
-
stateId,
|
|
1442
|
-
meta: newControl({})
|
|
1443
|
-
});
|
|
1444
|
-
const {
|
|
1445
|
-
dataNode,
|
|
1446
|
-
hidden,
|
|
1447
|
-
readonly,
|
|
1448
|
-
style,
|
|
1449
|
-
layoutStyle,
|
|
1450
|
-
allowedOptions,
|
|
1451
|
-
disabled,
|
|
1452
|
-
variables,
|
|
1453
|
-
display
|
|
1454
|
-
} = control.fields;
|
|
1455
|
-
createScopedEffect(c => evalExpr(c, undefined, style, firstExpr(formNode, DynamicPropertyType.Style), coerceStyle), scope);
|
|
1456
|
-
createScopedEffect(c => evalExpr(c, undefined, layoutStyle, firstExpr(formNode, DynamicPropertyType.LayoutStyle), coerceStyle), scope);
|
|
1457
|
-
createScopedEffect(c => evalExpr(c, undefined, allowedOptions, firstExpr(formNode, DynamicPropertyType.AllowedOptions), x => x), scope);
|
|
1458
|
-
createScopedEffect(c => evalExpr(c, undefined, display, firstExpr(formNode, DynamicPropertyType.Display), coerceString), scope);
|
|
1459
|
-
updateComputedValue(dataNode, () => lookupDataNode(definition, parent));
|
|
1460
|
-
updateComputedValue(hidden, () => !!cf.hidden.value || definition.hidden || dataNode.value && (!validDataNode(dataNode.value) || hideDisplayOnly(dataNode.value, schemaInterface, definition)));
|
|
1461
|
-
updateComputedValue(readonly, () => !!cf.readonly.value || isControlReadonly(definition));
|
|
1462
|
-
updateComputedValue(disabled, () => !!cf.disabled.value || of.disabled.value);
|
|
1463
|
-
updateComputedValue(variables, () => {
|
|
1464
|
-
var _controlImpl$fields$v2;
|
|
1465
|
-
return (_controlImpl$fields$v2 = controlImpl.fields.variables.value) != null ? _controlImpl$fields$v2 : {};
|
|
1466
|
-
});
|
|
1467
|
-
createSyncEffect(() => {
|
|
1468
|
-
const dn = dataNode.value;
|
|
1469
|
-
if (dn) {
|
|
1470
|
-
dn.control.disabled = disabled.value;
|
|
1471
|
-
}
|
|
1472
|
-
}, scope);
|
|
1473
|
-
createSyncEffect(() => {
|
|
1474
|
-
if (isDisplayControl(def)) {
|
|
1475
|
-
if (display.value !== undefined) {
|
|
1476
|
-
text.value = isTextDisplay(def.displayData) ? display.value : NoOverride;
|
|
1477
|
-
html.value = isHtmlDisplay(def.displayData) ? display.value : NoOverride;
|
|
1478
|
-
} else {
|
|
1479
|
-
text.value = NoOverride;
|
|
1480
|
-
html.value = NoOverride;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
}, displayOverrides);
|
|
1484
|
-
setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode, hidden, runAsync);
|
|
1485
|
-
createSyncEffect(() => {
|
|
1486
|
-
var _dataNode$value;
|
|
1487
|
-
const dn = (_dataNode$value = dataNode.value) == null ? void 0 : _dataNode$value.control;
|
|
1488
|
-
if (dn && isDataControl(definition)) {
|
|
1489
|
-
var _definition$adornment, _definition$renderOpt;
|
|
1490
|
-
if (definition.hidden) {
|
|
1491
|
-
if (controlImpl.fields.clearHidden.value && !definition.dontClearHidden) {
|
|
1492
|
-
// console.log("Clearing hidden");
|
|
1493
|
-
dn.value = undefined;
|
|
1494
|
-
}
|
|
1495
|
-
} else if (dn.value === undefined && definition.defaultValue != null && !((_definition$adornment = definition.adornments) != null && _definition$adornment.some(x => x.type === ControlAdornmentType.Optional)) && ((_definition$renderOpt = definition.renderOptions) == null ? void 0 : _definition$renderOpt.type) != DataRenderType.NullToggle) {
|
|
1496
|
-
// console.log(
|
|
1497
|
-
// "Setting to default",
|
|
1498
|
-
// definition.defaultValue,
|
|
1499
|
-
// definition.field,
|
|
1500
|
-
// );
|
|
1501
|
-
// const [required, dcv] = isDataControl(definition)
|
|
1502
|
-
// ? [definition.required, definition.defaultValue]
|
|
1503
|
-
// : [false, undefined];
|
|
1504
|
-
// const field = ctx.dataNode?.schema.field;
|
|
1505
|
-
// return (
|
|
1506
|
-
// dcv ??
|
|
1507
|
-
// (field
|
|
1508
|
-
// ? ctx.dataNode!.elementIndex != null
|
|
1509
|
-
// ? elementValueForField(field)
|
|
1510
|
-
// : defaultValueForField(field, required)
|
|
1511
|
-
// : undefined)
|
|
1512
|
-
// );
|
|
1513
|
-
dn.value = definition.defaultValue;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
}, scope);
|
|
1517
|
-
return createOverrideProxy(control.current.value, control);
|
|
1518
|
-
});
|
|
1519
1691
|
}
|
|
1520
|
-
};
|
|
1521
|
-
|
|
1522
|
-
function firstExpr(
|
|
1523
|
-
|
|
1524
|
-
|
|
1692
|
+
}, displayOverrides);
|
|
1693
|
+
return createOverrideProxy(def, definitionOverrides);
|
|
1694
|
+
function firstExpr(property) {
|
|
1695
|
+
var _def$dynamic;
|
|
1696
|
+
return (_def$dynamic = def.dynamic) == null || (_def$dynamic = _def$dynamic.find(x => x.type === property && x.expr.type)) == null ? void 0 : _def$dynamic.expr;
|
|
1697
|
+
}
|
|
1698
|
+
function evalDynamic(control, property, init, coerce) {
|
|
1699
|
+
createScopedEffect(c => {
|
|
1700
|
+
const x = firstExpr(property);
|
|
1701
|
+
evalExpr(c, init(x), control, x, coerce);
|
|
1702
|
+
}, scope);
|
|
1703
|
+
}
|
|
1525
1704
|
}
|
|
1526
1705
|
function coerceStyle(v) {
|
|
1527
1706
|
return typeof v === "object" ? v : undefined;
|
|
1528
1707
|
}
|
|
1529
1708
|
function coerceString(v) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1709
|
+
if (typeof v === "string") return v;
|
|
1710
|
+
if (v == null) return "";
|
|
1711
|
+
switch (typeof v) {
|
|
1712
|
+
case "number":
|
|
1713
|
+
case "boolean":
|
|
1714
|
+
return v.toString();
|
|
1715
|
+
default:
|
|
1716
|
+
return JSON.stringify(v);
|
|
1717
|
+
}
|
|
1532
1718
|
}
|
|
1533
|
-
function
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1719
|
+
function createFormStateNode(formNode, parent, options, nodeOptions) {
|
|
1720
|
+
const globals = newControl({
|
|
1721
|
+
schemaInterface: options.schemaInterface,
|
|
1722
|
+
evalExpression: options.evalExpression,
|
|
1723
|
+
runAsync: options.runAsync,
|
|
1724
|
+
resolveChildren: options.resolveChildren,
|
|
1725
|
+
clearHidden: options.clearHidden
|
|
1726
|
+
});
|
|
1727
|
+
return new FormStateNodeImpl("ROOT", {}, formNode.definition, formNode, nodeOptions, globals, parent, undefined, 0, options.resolveChildren);
|
|
1728
|
+
}
|
|
1729
|
+
const noopUi = {
|
|
1730
|
+
ensureChildVisible(childIndex) {},
|
|
1731
|
+
ensureVisible() {},
|
|
1732
|
+
getDisabler(type) {
|
|
1733
|
+
return () => () => {};
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
class FormStateNodeImpl {
|
|
1737
|
+
constructor(childKey, meta, definition, form, nodeOptions, globals, parent, parentNode, childIndex, resolveChildren) {
|
|
1738
|
+
this.childKey = void 0;
|
|
1739
|
+
this.meta = void 0;
|
|
1740
|
+
this.form = void 0;
|
|
1741
|
+
this.globals = void 0;
|
|
1742
|
+
this.parent = void 0;
|
|
1743
|
+
this.parentNode = void 0;
|
|
1744
|
+
this.base = void 0;
|
|
1745
|
+
this.options = void 0;
|
|
1746
|
+
this.resolveChildren = void 0;
|
|
1747
|
+
this.ui = noopUi;
|
|
1748
|
+
this.childKey = childKey;
|
|
1749
|
+
this.meta = meta;
|
|
1750
|
+
this.form = form;
|
|
1751
|
+
this.globals = globals;
|
|
1752
|
+
this.parent = parent;
|
|
1753
|
+
this.parentNode = parentNode;
|
|
1754
|
+
const base = newControl({
|
|
1755
|
+
readonly: false,
|
|
1756
|
+
visible: null,
|
|
1757
|
+
disabled: false,
|
|
1758
|
+
children: [],
|
|
1759
|
+
resolved: {
|
|
1760
|
+
definition
|
|
1761
|
+
},
|
|
1762
|
+
parent,
|
|
1763
|
+
allowedOptions: undefined,
|
|
1764
|
+
childIndex,
|
|
1765
|
+
nodeOptions,
|
|
1766
|
+
busy: false
|
|
1767
|
+
}, {
|
|
1768
|
+
dontClearError: true
|
|
1537
1769
|
});
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
return
|
|
1546
|
-
}
|
|
1770
|
+
this.base = base;
|
|
1771
|
+
this.options = base.fields.nodeOptions;
|
|
1772
|
+
base.meta["$FormState"] = this;
|
|
1773
|
+
this.resolveChildren = resolveChildren != null ? resolveChildren : globals.fields.resolveChildren.value;
|
|
1774
|
+
initFormState(definition, this, parentNode);
|
|
1775
|
+
}
|
|
1776
|
+
get busy() {
|
|
1777
|
+
return this.base.fields.busy.value;
|
|
1778
|
+
}
|
|
1779
|
+
setBusy(busy) {
|
|
1780
|
+
this.base.fields.busy.value = busy;
|
|
1781
|
+
}
|
|
1782
|
+
get evalExpression() {
|
|
1783
|
+
return this.globals.fields.evalExpression.value;
|
|
1784
|
+
}
|
|
1785
|
+
get runAsync() {
|
|
1786
|
+
return this.globals.fields.runAsync.value;
|
|
1787
|
+
}
|
|
1788
|
+
get schemaInterface() {
|
|
1789
|
+
return this.globals.fields.schemaInterface.value;
|
|
1790
|
+
}
|
|
1791
|
+
get forceDisabled() {
|
|
1792
|
+
return this.options.fields.forceDisabled.value;
|
|
1793
|
+
}
|
|
1794
|
+
setForceDisabled(value) {
|
|
1795
|
+
return this.options.fields.forceDisabled.value = value;
|
|
1796
|
+
}
|
|
1797
|
+
get forceReadonly() {
|
|
1798
|
+
return this.options.fields.forceReadonly.value;
|
|
1799
|
+
}
|
|
1800
|
+
get forceHidden() {
|
|
1801
|
+
return this.options.fields.forceHidden.value;
|
|
1802
|
+
}
|
|
1803
|
+
attachUi(f) {
|
|
1804
|
+
this.ui = f;
|
|
1805
|
+
}
|
|
1806
|
+
get childIndex() {
|
|
1807
|
+
return this.base.fields.childIndex.value;
|
|
1808
|
+
}
|
|
1809
|
+
get children() {
|
|
1810
|
+
return this.base.fields.children.elements.map(x => x.meta["$FormState"]);
|
|
1811
|
+
}
|
|
1812
|
+
get uniqueId() {
|
|
1813
|
+
return this.base.uniqueId.toString();
|
|
1814
|
+
}
|
|
1815
|
+
get valid() {
|
|
1816
|
+
return this.base.valid;
|
|
1817
|
+
}
|
|
1818
|
+
get touched() {
|
|
1819
|
+
return this.base.touched;
|
|
1820
|
+
}
|
|
1821
|
+
setTouched(touched, notChildren) {
|
|
1822
|
+
this.base.setTouched(touched, notChildren);
|
|
1823
|
+
}
|
|
1824
|
+
validate() {
|
|
1825
|
+
this.children.forEach(child => {
|
|
1826
|
+
child.validate();
|
|
1827
|
+
});
|
|
1828
|
+
if (this.dataNode) {
|
|
1829
|
+
this.dataNode.control.validate();
|
|
1830
|
+
}
|
|
1831
|
+
return this.valid;
|
|
1832
|
+
}
|
|
1833
|
+
get readonly() {
|
|
1834
|
+
return this.base.fields.readonly.value;
|
|
1835
|
+
}
|
|
1836
|
+
get visible() {
|
|
1837
|
+
return this.base.fields.visible.value;
|
|
1838
|
+
}
|
|
1839
|
+
get disabled() {
|
|
1840
|
+
return this.base.fields.disabled.value;
|
|
1841
|
+
}
|
|
1842
|
+
get clearHidden() {
|
|
1843
|
+
return this.globals.fields.clearHidden.value;
|
|
1844
|
+
}
|
|
1845
|
+
get variables() {
|
|
1846
|
+
return this.options.fields.variables.value;
|
|
1847
|
+
}
|
|
1848
|
+
get definition() {
|
|
1849
|
+
return this.resolved.definition;
|
|
1850
|
+
}
|
|
1851
|
+
getChild(index) {
|
|
1852
|
+
var _this$base$fields$chi;
|
|
1853
|
+
return (_this$base$fields$chi = this.base.fields.children.elements[index]) == null ? void 0 : _this$base$fields$chi.meta["$FormState"];
|
|
1854
|
+
}
|
|
1855
|
+
getChildCount() {
|
|
1856
|
+
return this.base.fields.children.elements.length;
|
|
1857
|
+
}
|
|
1858
|
+
cleanup() {
|
|
1859
|
+
this.base.cleanup();
|
|
1860
|
+
}
|
|
1861
|
+
get resolved() {
|
|
1862
|
+
return this.base.fields.resolved.value;
|
|
1863
|
+
}
|
|
1864
|
+
get dataNode() {
|
|
1865
|
+
return this.base.fields.dataNode.value;
|
|
1866
|
+
}
|
|
1867
|
+
ensureMeta(key, init) {
|
|
1868
|
+
if (key in this.meta) return this.meta[key];
|
|
1869
|
+
const res = init(this.base);
|
|
1870
|
+
this.meta[key] = res;
|
|
1871
|
+
return res;
|
|
1872
|
+
}
|
|
1547
1873
|
}
|
|
1548
|
-
function
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1874
|
+
function initFormState(def, impl, parentNode) {
|
|
1875
|
+
const {
|
|
1876
|
+
base,
|
|
1877
|
+
options,
|
|
1878
|
+
schemaInterface,
|
|
1879
|
+
runAsync,
|
|
1880
|
+
evalExpression,
|
|
1881
|
+
parent,
|
|
1882
|
+
variables
|
|
1883
|
+
} = impl;
|
|
1884
|
+
const evalExpr = createEvalExpr(evalExpression, {
|
|
1885
|
+
schemaInterface,
|
|
1886
|
+
variables,
|
|
1887
|
+
dataNode: parent,
|
|
1888
|
+
runAsync
|
|
1553
1889
|
});
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1890
|
+
const scope = base;
|
|
1891
|
+
const {
|
|
1892
|
+
forceReadonly,
|
|
1893
|
+
forceDisabled,
|
|
1894
|
+
forceHidden
|
|
1895
|
+
} = options.fields;
|
|
1896
|
+
const resolved = base.fields.resolved.as();
|
|
1897
|
+
const {
|
|
1898
|
+
style,
|
|
1899
|
+
layoutStyle,
|
|
1900
|
+
fieldOptions,
|
|
1901
|
+
display,
|
|
1902
|
+
definition: rd
|
|
1903
|
+
} = resolved.fields;
|
|
1904
|
+
evalDynamic(display, DynamicPropertyType.Display, undefined, coerceString);
|
|
1905
|
+
const {
|
|
1906
|
+
dataNode,
|
|
1907
|
+
readonly,
|
|
1908
|
+
disabled,
|
|
1909
|
+
visible,
|
|
1910
|
+
children,
|
|
1911
|
+
allowedOptions
|
|
1912
|
+
} = base.fields;
|
|
1913
|
+
const definition = createEvaluatedDefinition(def, evalExpr, scope, display);
|
|
1914
|
+
rd.value = definition;
|
|
1915
|
+
evalDynamic(style, DynamicPropertyType.Style, undefined, coerceStyle);
|
|
1916
|
+
evalDynamic(layoutStyle, DynamicPropertyType.LayoutStyle, undefined, coerceStyle);
|
|
1917
|
+
evalDynamic(allowedOptions, DynamicPropertyType.AllowedOptions, undefined, x => x);
|
|
1918
|
+
updateComputedValue(dataNode, () => lookupDataNode(definition, parent));
|
|
1919
|
+
updateComputedValue(visible, () => {
|
|
1920
|
+
if (forceHidden.value) return false;
|
|
1921
|
+
if (parentNode && !parentNode.visible) return parentNode.visible;
|
|
1922
|
+
const dn = dataNode.value;
|
|
1923
|
+
if (dn && (!validDataNode(dn) || hideDisplayOnly(dn, schemaInterface, definition))) return false;
|
|
1924
|
+
return definition.hidden == null ? null : !definition.hidden;
|
|
1925
|
+
});
|
|
1926
|
+
updateComputedValue(readonly, () => (parentNode == null ? void 0 : parentNode.readonly) || forceReadonly.value || isControlReadonly(definition));
|
|
1927
|
+
updateComputedValue(disabled, () => (parentNode == null ? void 0 : parentNode.disabled) || forceDisabled.value || isControlDisabled(definition));
|
|
1928
|
+
updateComputedValue(fieldOptions, () => {
|
|
1929
|
+
var _allowedOptions$value;
|
|
1930
|
+
const dn = dataNode.value;
|
|
1931
|
+
if (!dn) return undefined;
|
|
1932
|
+
const fieldOptions = schemaInterface.getDataOptions(dn);
|
|
1933
|
+
const _allowed = (_allowedOptions$value = allowedOptions.value) != null ? _allowedOptions$value : [];
|
|
1934
|
+
const allowed = Array.isArray(_allowed) ? _allowed : [_allowed];
|
|
1935
|
+
return allowed.length > 0 ? allowed.map(x => {
|
|
1936
|
+
var _fieldOptions$find;
|
|
1937
|
+
return typeof x === "object" ? x : (_fieldOptions$find = fieldOptions == null ? void 0 : fieldOptions.find(y => y.value == x)) != null ? _fieldOptions$find : {
|
|
1938
|
+
name: x.toString(),
|
|
1939
|
+
value: x
|
|
1572
1940
|
};
|
|
1573
|
-
|
|
1574
|
-
}
|
|
1941
|
+
}).filter(x => x != null) : fieldOptions;
|
|
1575
1942
|
});
|
|
1943
|
+
createSyncEffect(() => {
|
|
1944
|
+
const dn = dataNode.value;
|
|
1945
|
+
if (dn) {
|
|
1946
|
+
dn.control.disabled = disabled.value;
|
|
1947
|
+
}
|
|
1948
|
+
}, scope);
|
|
1949
|
+
createSyncEffect(() => {
|
|
1950
|
+
const dn = dataNode.value;
|
|
1951
|
+
if (dn) {
|
|
1952
|
+
dn.control.touched = base.touched;
|
|
1953
|
+
}
|
|
1954
|
+
}, scope);
|
|
1955
|
+
createSyncEffect(() => {
|
|
1956
|
+
const dn = dataNode.value;
|
|
1957
|
+
if (dn) {
|
|
1958
|
+
base.touched = dn.control.touched;
|
|
1959
|
+
}
|
|
1960
|
+
}, scope);
|
|
1961
|
+
createSyncEffect(() => {
|
|
1962
|
+
const dn = dataNode.value;
|
|
1963
|
+
base.setErrors(dn == null ? void 0 : dn.control.errors);
|
|
1964
|
+
}, scope);
|
|
1965
|
+
setupValidation(scope, impl.variables, definition, dataNode, schemaInterface, parent, visible, runAsync);
|
|
1966
|
+
createSyncEffect(() => {
|
|
1967
|
+
var _dataNode$value;
|
|
1968
|
+
const dn = (_dataNode$value = dataNode.value) == null ? void 0 : _dataNode$value.control;
|
|
1969
|
+
if (dn && isDataControl(definition)) {
|
|
1970
|
+
var _definition$adornment, _definition$renderOpt;
|
|
1971
|
+
if (impl.visible == false) {
|
|
1972
|
+
if (impl.clearHidden && !definition.dontClearHidden) {
|
|
1973
|
+
// console.log("Clearing hidden");
|
|
1974
|
+
dn.value = undefined;
|
|
1975
|
+
}
|
|
1976
|
+
} else if (impl.visible && dn.value === undefined && definition.defaultValue != null && !((_definition$adornment = definition.adornments) != null && _definition$adornment.some(x => x.type === ControlAdornmentType.Optional)) && ((_definition$renderOpt = definition.renderOptions) == null ? void 0 : _definition$renderOpt.type) != DataRenderType.NullToggle) {
|
|
1977
|
+
// console.log(
|
|
1978
|
+
// "Setting to default",
|
|
1979
|
+
// definition.defaultValue,
|
|
1980
|
+
// definition.field,
|
|
1981
|
+
// );
|
|
1982
|
+
// const [required, dcv] = isDataControl(definition)
|
|
1983
|
+
// ? [definition.required, definition.defaultValue]
|
|
1984
|
+
// : [false, undefined];
|
|
1985
|
+
// const field = ctx.dataNode?.schema.field;
|
|
1986
|
+
// return (
|
|
1987
|
+
// dcv ??
|
|
1988
|
+
// (field
|
|
1989
|
+
// ? ctx.dataNode!.elementIndex != null
|
|
1990
|
+
// ? elementValueForField(field)
|
|
1991
|
+
// : defaultValueForField(field, required)
|
|
1992
|
+
// : undefined)
|
|
1993
|
+
// );
|
|
1994
|
+
dn.value = definition.defaultValue;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}, scope);
|
|
1998
|
+
initChildren(impl);
|
|
1999
|
+
function firstExpr(property) {
|
|
2000
|
+
var _def$dynamic2;
|
|
2001
|
+
return (_def$dynamic2 = def.dynamic) == null || (_def$dynamic2 = _def$dynamic2.find(x => x.type === property && x.expr.type)) == null ? void 0 : _def$dynamic2.expr;
|
|
2002
|
+
}
|
|
2003
|
+
function evalDynamic(control, property, init, coerce) {
|
|
2004
|
+
createScopedEffect(c => evalExpr(c, init, control, firstExpr(property), coerce), scope);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
function combineVariables(v1, v2) {
|
|
2008
|
+
if (!v1) return v2;
|
|
2009
|
+
if (!v2) return v1;
|
|
2010
|
+
return c => _extends({}, v1(c), v2(c));
|
|
2011
|
+
}
|
|
2012
|
+
function initChildren(formImpl) {
|
|
2013
|
+
const childMap = new Map();
|
|
2014
|
+
createSyncEffect(() => {
|
|
2015
|
+
const {
|
|
2016
|
+
base,
|
|
2017
|
+
resolveChildren
|
|
2018
|
+
} = formImpl;
|
|
2019
|
+
const children = base.fields.children;
|
|
2020
|
+
const kids = resolveChildren(formImpl);
|
|
2021
|
+
const scope = base;
|
|
2022
|
+
const detached = updateElements(children, () => kids.map(({
|
|
2023
|
+
childKey,
|
|
2024
|
+
create
|
|
2025
|
+
}, childIndex) => {
|
|
2026
|
+
let child = childMap.get(childKey);
|
|
2027
|
+
if (child) {
|
|
2028
|
+
child.fields.childIndex.value = childIndex;
|
|
2029
|
+
} else {
|
|
2030
|
+
var _cc$definition, _cc$parent;
|
|
2031
|
+
const meta = {};
|
|
2032
|
+
const cc = create(scope, meta);
|
|
2033
|
+
const newOptions = {
|
|
2034
|
+
forceHidden: false,
|
|
2035
|
+
forceDisabled: false,
|
|
2036
|
+
forceReadonly: false,
|
|
2037
|
+
variables: combineVariables(formImpl.variables, cc.variables)
|
|
2038
|
+
};
|
|
2039
|
+
const fsChild = new FormStateNodeImpl(childKey, meta, (_cc$definition = cc.definition) != null ? _cc$definition : groupedControl([]), cc.node === undefined ? formImpl.form : cc.node, newOptions, formImpl.globals, (_cc$parent = cc.parent) != null ? _cc$parent : formImpl.parent, formImpl, childIndex, cc.resolveChildren);
|
|
2040
|
+
child = fsChild.base;
|
|
2041
|
+
childMap.set(childKey, child);
|
|
2042
|
+
}
|
|
2043
|
+
return child;
|
|
2044
|
+
}));
|
|
2045
|
+
detached.forEach(child => child.cleanup());
|
|
2046
|
+
}, formImpl.base);
|
|
2047
|
+
}
|
|
2048
|
+
function visitFormState(node, visitFn) {
|
|
2049
|
+
const v = visitFn(node);
|
|
2050
|
+
if (v !== undefined) return v;
|
|
2051
|
+
const childCount = node.getChildCount();
|
|
2052
|
+
for (let i = 0; i < childCount; i++) {
|
|
2053
|
+
const res = visitFormState(node.getChild(i), visitFn);
|
|
2054
|
+
if (res !== undefined) return res;
|
|
2055
|
+
}
|
|
2056
|
+
return undefined;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
function defaultResolveChildNodes(formStateNode) {
|
|
2060
|
+
const {
|
|
2061
|
+
resolved,
|
|
2062
|
+
dataNode: data,
|
|
2063
|
+
schemaInterface,
|
|
2064
|
+
parent,
|
|
2065
|
+
form: node
|
|
2066
|
+
} = formStateNode;
|
|
2067
|
+
if (!node) return [];
|
|
2068
|
+
const def = resolved.definition;
|
|
2069
|
+
if (isDataControl(def)) {
|
|
2070
|
+
var _def$renderOptions;
|
|
2071
|
+
if (!data) return [];
|
|
2072
|
+
const type = (_def$renderOptions = def.renderOptions) == null ? void 0 : _def$renderOptions.type;
|
|
2073
|
+
if (type === DataRenderType.CheckList || type === DataRenderType.Radio) {
|
|
2074
|
+
const n = node.getChildNodes();
|
|
2075
|
+
if (n.length > 0 && resolved.fieldOptions) {
|
|
2076
|
+
return resolved.fieldOptions.map(x => {
|
|
2077
|
+
var _x$value;
|
|
2078
|
+
return {
|
|
2079
|
+
childKey: (_x$value = x.value) == null ? void 0 : _x$value.toString(),
|
|
2080
|
+
create: (scope, meta) => {
|
|
2081
|
+
meta["fieldOptionValue"] = x.value;
|
|
2082
|
+
const vars = createScopedComputed(scope, () => {
|
|
2083
|
+
return {
|
|
2084
|
+
option: x,
|
|
2085
|
+
optionSelected: isOptionSelected(schemaInterface, x, data)
|
|
2086
|
+
};
|
|
2087
|
+
});
|
|
2088
|
+
return {
|
|
2089
|
+
definition: {
|
|
2090
|
+
type: ControlDefinitionType.Group,
|
|
2091
|
+
groupOptions: {
|
|
2092
|
+
type: GroupRenderType.Contents
|
|
2093
|
+
}
|
|
2094
|
+
},
|
|
2095
|
+
parent,
|
|
2096
|
+
node,
|
|
2097
|
+
variables: changes => ({
|
|
2098
|
+
formData: trackedValue(vars, changes)
|
|
2099
|
+
})
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
return [];
|
|
2106
|
+
}
|
|
2107
|
+
if (data.schema.field.collection && data.elementIndex == null) return resolveArrayChildren(data, node);
|
|
2108
|
+
}
|
|
2109
|
+
return node.getChildNodes().map(x => ({
|
|
2110
|
+
childKey: x.id,
|
|
2111
|
+
create: () => ({
|
|
2112
|
+
node: x,
|
|
2113
|
+
parent: data != null ? data : parent,
|
|
2114
|
+
definition: x.definition
|
|
2115
|
+
})
|
|
2116
|
+
}));
|
|
2117
|
+
}
|
|
2118
|
+
function resolveArrayChildren(data, node, adjustChild) {
|
|
2119
|
+
const childNodes = node.getChildNodes();
|
|
2120
|
+
const childCount = childNodes.length;
|
|
2121
|
+
const singleChild = childCount === 1 ? childNodes[0] : null;
|
|
2122
|
+
return data.control.as().elements.map((x, i) => ({
|
|
2123
|
+
childKey: x.uniqueId,
|
|
2124
|
+
create: () => {
|
|
2125
|
+
var _adjustChild;
|
|
2126
|
+
return _extends({
|
|
2127
|
+
definition: !childCount ? {
|
|
2128
|
+
type: ControlDefinitionType.Data,
|
|
2129
|
+
field: ".",
|
|
2130
|
+
hideTitle: true,
|
|
2131
|
+
renderOptions: {
|
|
2132
|
+
type: DataRenderType.Standard
|
|
2133
|
+
}
|
|
2134
|
+
} : singleChild ? singleChild.definition : groupedControl([]),
|
|
2135
|
+
node: singleChild != null ? singleChild : node,
|
|
2136
|
+
parent: data.getChildElement(i)
|
|
2137
|
+
}, (_adjustChild = adjustChild == null ? void 0 : adjustChild(x, i)) != null ? _adjustChild : {});
|
|
2138
|
+
}
|
|
2139
|
+
}));
|
|
2140
|
+
}
|
|
2141
|
+
function isOptionSelected(schemaInterface, option, data) {
|
|
2142
|
+
if (data.schema.field.collection) {
|
|
2143
|
+
var _data$control$as$valu;
|
|
2144
|
+
return !!((_data$control$as$valu = data.control.as().value) != null && _data$control$as$valu.includes(option.value));
|
|
2145
|
+
}
|
|
2146
|
+
return schemaInterface.compareValue(data.schema.field, data.control.value, option.value) === 0;
|
|
1576
2147
|
}
|
|
1577
|
-
class NoValue {}
|
|
1578
|
-
const NoOverride = new NoValue();
|
|
1579
2148
|
|
|
1580
|
-
export { ActionStyle, AdornmentPlacement, ControlAdornmentType, ControlDefinitionType, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, FormNode, FormTree, GroupRenderType, IconLibrary, IconPlacement, SchemaDataNode, SchemaDataTree, SchemaDataTreeImpl, SchemaNode, SchemaTags, SchemaTree, SyncTextType, ValidationMessageType, ValidatorType, addFieldOption, boolField, buildSchema, compoundField, createControlMap, createFormLookup,
|
|
2149
|
+
export { ActionStyle, AdornmentPlacement, ControlAdornmentType, ControlDefinitionType, ControlDisableType, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, FormNode, FormTree, GroupRenderType, IconLibrary, IconPlacement, NoOverride, SchemaDataNode, SchemaDataTree, SchemaDataTreeImpl, SchemaNode, SchemaTags, SchemaTree, SyncTextType, ValidationMessageType, ValidatorType, accordionOptions, actionControl, addFieldOption, adornmentOptions, autocompleteOptions, boolField, buildSchema, checkListOptions, coerceString, coerceStyle, combineVariables, compoundControl, compoundField, createControlMap, createEvalExpr, createEvaluatedDefinition, createFormLookup, createFormStateNode, createFormTree, createOverrideProxy, createSchemaDataNode, createSchemaLookup, createSchemaNode, createSchemaTree, createScoped, createScopedComputed, dataControl, dataExpr, dataMatchExpr, dateField, dateTimeField, dateValidator$1 as dateValidator, dateValidatorOptions, defaultCompoundField, defaultEvaluators, defaultResolveChildNodes, defaultScalarField, defaultSchemaInterface, displayOnlyOptions, doubleField, dynamicDefaultValue, dynamicDisabled, dynamicReadonly, dynamicVisibility, emptyGroupDefinition, fieldEqExpr, fieldExpr, fieldPathForDefinition, findField, fontAwesomeIcon, getDisplayOnlyOptions, getGroupRendererOptions, getHasMoreControl, getJsonPath, getLoadingControl, getMetaFields, getParentDataPath, getRefreshingControl, getRootDataNode, getSchemaFieldList, getSchemaNodePath, getSchemaNodePathString, getSchemaPath, getTagParam, groupedControl, hideDisplayOnly, htmlDisplayControl, intField, isAccordionRenderer, isActionControl, isArrayRenderer, isAutoCompleteClasses, isAutocompleteRenderer, isCheckEntryClasses, isCompoundField, isCompoundNode, isControlDisabled, isControlDisplayOnly, isControlReadonly, isDataControl, isDataGroupRenderer, isDateTimeRenderer, isDialogRenderer, isDisplayControl, isDisplayOnlyRenderer, isFlexRenderer, isGridRenderer, isGroupControl, isHtmlDisplay, isInlineRenderer, isScalarField, isSelectChildRenderer, isTabsRenderer, isTextDisplay, isTextfieldRenderer, isWizardRenderer, jsonPathString, jsonataEval, jsonataExpr, jsonataOptions, jsonataValidator$1 as jsonataValidator, jsonataValidatorOptions, legacyFormNode, lengthValidator$1 as lengthValidator, lengthValidatorOptions, lookupDataNode, makeCompoundField, makeParamTag, makeScalarField, makeSchemaDataNode, mergeField, mergeFields, mergeOption, missingField, noopUi, notEmptyExpr, radioButtonOptions, relativePath, relativeSegmentPath, renderOptionsFor, resolveArrayChildren, resolveSchemaNode, resolveSchemas, schemaDataForFieldPath, schemaDataForFieldRef, schemaForDataPath, schemaForFieldPath, schemaForFieldRef, stringField, stringOptionsField, textDisplayControl, textfieldOptions, timeField, traverseData, traverseParents, traverseSchemaPath, uuidEval, uuidExpr, validDataNode, validatorOptions, visitControlData, visitControlDataArray, visitControlDefinition, visitFormData, visitFormDataInContext, visitFormState, withScalarOptions };
|
|
1581
2150
|
//# sourceMappingURL=index.js.map
|