@astroapps/forms-core 1.0.1

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/index.cjs ADDED
@@ -0,0 +1,1813 @@
1
+ var controls = require('@astroapps/controls');
2
+ var jsonata = require('jsonata');
3
+ var uuid = require('uuid');
4
+
5
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
+
7
+ var jsonata__default = /*#__PURE__*/_interopDefaultLegacy(jsonata);
8
+
9
+ exports.ControlDefinitionType = void 0;
10
+ (function (ControlDefinitionType) {
11
+ ControlDefinitionType["Data"] = "Data";
12
+ ControlDefinitionType["Group"] = "Group";
13
+ ControlDefinitionType["Display"] = "Display";
14
+ ControlDefinitionType["Action"] = "Action";
15
+ })(exports.ControlDefinitionType || (exports.ControlDefinitionType = {}));
16
+ exports.DynamicPropertyType = void 0;
17
+ (function (DynamicPropertyType) {
18
+ DynamicPropertyType["Visible"] = "Visible";
19
+ DynamicPropertyType["DefaultValue"] = "DefaultValue";
20
+ DynamicPropertyType["Readonly"] = "Readonly";
21
+ DynamicPropertyType["Disabled"] = "Disabled";
22
+ DynamicPropertyType["Display"] = "Display";
23
+ DynamicPropertyType["Style"] = "Style";
24
+ DynamicPropertyType["LayoutStyle"] = "LayoutStyle";
25
+ DynamicPropertyType["AllowedOptions"] = "AllowedOptions";
26
+ DynamicPropertyType["Label"] = "Label";
27
+ DynamicPropertyType["ActionData"] = "ActionData";
28
+ })(exports.DynamicPropertyType || (exports.DynamicPropertyType = {}));
29
+ exports.AdornmentPlacement = void 0;
30
+ (function (AdornmentPlacement) {
31
+ AdornmentPlacement["ControlStart"] = "ControlStart";
32
+ AdornmentPlacement["ControlEnd"] = "ControlEnd";
33
+ AdornmentPlacement["LabelStart"] = "LabelStart";
34
+ AdornmentPlacement["LabelEnd"] = "LabelEnd";
35
+ })(exports.AdornmentPlacement || (exports.AdornmentPlacement = {}));
36
+ exports.ControlAdornmentType = void 0;
37
+ (function (ControlAdornmentType) {
38
+ ControlAdornmentType["Tooltip"] = "Tooltip";
39
+ ControlAdornmentType["Accordion"] = "Accordion";
40
+ ControlAdornmentType["HelpText"] = "HelpText";
41
+ ControlAdornmentType["Icon"] = "Icon";
42
+ ControlAdornmentType["SetField"] = "SetField";
43
+ ControlAdornmentType["Optional"] = "Optional";
44
+ })(exports.ControlAdornmentType || (exports.ControlAdornmentType = {}));
45
+ exports.IconLibrary = void 0;
46
+ (function (IconLibrary) {
47
+ IconLibrary["FontAwesome"] = "FontAwesome";
48
+ IconLibrary["Material"] = "Material";
49
+ IconLibrary["CssClass"] = "CssClass";
50
+ })(exports.IconLibrary || (exports.IconLibrary = {}));
51
+ exports.DataRenderType = void 0;
52
+ (function (DataRenderType) {
53
+ DataRenderType["Standard"] = "Standard";
54
+ DataRenderType["Textfield"] = "Textfield";
55
+ DataRenderType["Radio"] = "Radio";
56
+ DataRenderType["HtmlEditor"] = "HtmlEditor";
57
+ DataRenderType["IconList"] = "IconList";
58
+ DataRenderType["CheckList"] = "CheckList";
59
+ DataRenderType["UserSelection"] = "UserSelection";
60
+ DataRenderType["Synchronised"] = "Synchronised";
61
+ DataRenderType["IconSelector"] = "IconSelector";
62
+ DataRenderType["DateTime"] = "DateTime";
63
+ DataRenderType["Checkbox"] = "Checkbox";
64
+ DataRenderType["Dropdown"] = "Dropdown";
65
+ DataRenderType["DisplayOnly"] = "DisplayOnly";
66
+ DataRenderType["Group"] = "Group";
67
+ DataRenderType["NullToggle"] = "NullToggle";
68
+ DataRenderType["Autocomplete"] = "Autocomplete";
69
+ DataRenderType["Jsonata"] = "Jsonata";
70
+ DataRenderType["Array"] = "Array";
71
+ DataRenderType["ArrayElement"] = "ArrayElement";
72
+ DataRenderType["ElementSelected"] = "ElementSelected";
73
+ })(exports.DataRenderType || (exports.DataRenderType = {}));
74
+ exports.SyncTextType = void 0;
75
+ (function (SyncTextType) {
76
+ SyncTextType["Camel"] = "Camel";
77
+ SyncTextType["Snake"] = "Snake";
78
+ SyncTextType["Pascal"] = "Pascal";
79
+ })(exports.SyncTextType || (exports.SyncTextType = {}));
80
+ exports.GroupRenderType = void 0;
81
+ (function (GroupRenderType) {
82
+ GroupRenderType["Standard"] = "Standard";
83
+ GroupRenderType["Grid"] = "Grid";
84
+ GroupRenderType["Flex"] = "Flex";
85
+ GroupRenderType["Tabs"] = "Tabs";
86
+ GroupRenderType["GroupElement"] = "GroupElement";
87
+ GroupRenderType["SelectChild"] = "SelectChild";
88
+ GroupRenderType["Inline"] = "Inline";
89
+ GroupRenderType["Wizard"] = "Wizard";
90
+ GroupRenderType["Dialog"] = "Dialog";
91
+ GroupRenderType["Contents"] = "Contents";
92
+ })(exports.GroupRenderType || (exports.GroupRenderType = {}));
93
+ exports.DisplayDataType = void 0;
94
+ (function (DisplayDataType) {
95
+ DisplayDataType["Text"] = "Text";
96
+ DisplayDataType["Html"] = "Html";
97
+ DisplayDataType["Icon"] = "Icon";
98
+ DisplayDataType["Custom"] = "Custom";
99
+ })(exports.DisplayDataType || (exports.DisplayDataType = {}));
100
+ exports.ActionStyle = void 0;
101
+ (function (ActionStyle) {
102
+ ActionStyle["Button"] = "Button";
103
+ ActionStyle["Secondary"] = "Secondary";
104
+ ActionStyle["Link"] = "Link";
105
+ ActionStyle["Group"] = "Group";
106
+ })(exports.ActionStyle || (exports.ActionStyle = {}));
107
+ exports.IconPlacement = void 0;
108
+ (function (IconPlacement) {
109
+ IconPlacement["BeforeText"] = "BeforeText";
110
+ IconPlacement["AfterText"] = "AfterText";
111
+ IconPlacement["ReplaceText"] = "ReplaceText";
112
+ })(exports.IconPlacement || (exports.IconPlacement = {}));
113
+ function visitControlDefinition(x, visitor, defaultValue) {
114
+ switch (x.type) {
115
+ case exports.ControlDefinitionType.Action:
116
+ return visitor.action(x);
117
+ case exports.ControlDefinitionType.Data:
118
+ return visitor.data(x);
119
+ case exports.ControlDefinitionType.Display:
120
+ return visitor.display(x);
121
+ case exports.ControlDefinitionType.Group:
122
+ return visitor.group(x);
123
+ default:
124
+ return defaultValue(x);
125
+ }
126
+ }
127
+ function isGridRenderer(options) {
128
+ return options.type === exports.GroupRenderType.Grid;
129
+ }
130
+ function isWizardRenderer(options) {
131
+ return options.type === exports.GroupRenderType.Wizard;
132
+ }
133
+ function isDialogRenderer(options) {
134
+ return options.type === exports.GroupRenderType.Dialog;
135
+ }
136
+ function isInlineRenderer(options) {
137
+ return options.type === exports.GroupRenderType.Inline;
138
+ }
139
+ function isSelectChildRenderer(options) {
140
+ return options.type === exports.GroupRenderType.SelectChild;
141
+ }
142
+ function isTabsRenderer(options) {
143
+ return options.type === exports.GroupRenderType.Tabs;
144
+ }
145
+ function isFlexRenderer(options) {
146
+ return options.type === exports.GroupRenderType.Flex;
147
+ }
148
+ function isDisplayOnlyRenderer(options) {
149
+ return options.type === exports.DataRenderType.DisplayOnly;
150
+ }
151
+ function isTextfieldRenderer(options) {
152
+ return options.type === exports.DataRenderType.Textfield;
153
+ }
154
+ function isDateTimeRenderer(options) {
155
+ return options.type === exports.DataRenderType.DateTime;
156
+ }
157
+ function isAutocompleteRenderer(options) {
158
+ return options.type === exports.DataRenderType.Autocomplete;
159
+ }
160
+ function isAutoCompleteClasses(options) {
161
+ switch (options == null ? void 0 : options.type) {
162
+ case exports.DataRenderType.Autocomplete:
163
+ return true;
164
+ default:
165
+ return false;
166
+ }
167
+ }
168
+ function isDataGroupRenderer(options) {
169
+ return (options == null ? void 0 : options.type) === exports.DataRenderType.Group;
170
+ }
171
+ function isArrayRenderer(options) {
172
+ return options.type === exports.DataRenderType.Array;
173
+ }
174
+ function isDataControl(c) {
175
+ return c.type === exports.ControlDefinitionType.Data;
176
+ }
177
+ function isGroupControl(c) {
178
+ return c.type === exports.ControlDefinitionType.Group;
179
+ }
180
+ function isActionControl(c) {
181
+ return c.type === exports.ControlDefinitionType.Action;
182
+ }
183
+ function isDisplayControl(c) {
184
+ return c.type === exports.ControlDefinitionType.Display;
185
+ }
186
+ function isTextDisplay(d) {
187
+ return d.type === exports.DisplayDataType.Text;
188
+ }
189
+ function isHtmlDisplay(d) {
190
+ return d.type === exports.DisplayDataType.Html;
191
+ }
192
+ function isCheckEntryClasses(options) {
193
+ switch (options == null ? void 0 : options.type) {
194
+ case exports.DataRenderType.Radio:
195
+ case exports.DataRenderType.CheckList:
196
+ return true;
197
+ default:
198
+ return false;
199
+ }
200
+ }
201
+ function traverseParents(current, get, until) {
202
+ var outArray = [];
203
+ while (current && !(until != null && until(current))) {
204
+ outArray.push(get(current));
205
+ current = current.parent;
206
+ }
207
+ return outArray.reverse();
208
+ }
209
+ function getRootDataNode(dataNode) {
210
+ while (dataNode.parent) {
211
+ dataNode = dataNode.parent;
212
+ }
213
+ return dataNode;
214
+ }
215
+ function getJsonPath(dataNode) {
216
+ return traverseParents(dataNode, function (d) {
217
+ return d.elementIndex == null ? d.schema.field.field : d.elementIndex;
218
+ }, function (x) {
219
+ return !x.parent;
220
+ });
221
+ }
222
+ function getSchemaPath(schemaNode) {
223
+ return traverseParents(schemaNode, function (d) {
224
+ return d.field;
225
+ }, function (x) {
226
+ return !x.parent;
227
+ });
228
+ }
229
+ function getSchemaFieldList(schema) {
230
+ return schema.getChildNodes().map(function (x) {
231
+ return x.field;
232
+ });
233
+ }
234
+ function fontAwesomeIcon(icon) {
235
+ return {
236
+ library: exports.IconLibrary.FontAwesome,
237
+ name: icon
238
+ };
239
+ }
240
+ /**
241
+ * Checks if a control definition is readonly.
242
+ * @param c - The control definition to check.
243
+ * @returns True if the control definition is readonly, false otherwise.
244
+ */
245
+ function isControlReadonly(c) {
246
+ return isDataControl(c) && !!c.readonly;
247
+ }
248
+ /**
249
+ * Checks if a control definition is disabled.
250
+ * @param c - The control definition to check.
251
+ * @returns True if the control definition is disabled, false otherwise.
252
+ */
253
+ function isControlDisabled(c) {
254
+ return isDataControl(c) && !!c.disabled;
255
+ }
256
+ /**
257
+ * Returns the group renderer options for a control definition.
258
+ * @param {ControlDefinition} def - The control definition to get the group renderer options for.
259
+ * @returns {GroupRenderOptions | undefined} - The group renderer options, or undefined if not applicable.
260
+ */
261
+ function getGroupRendererOptions(def) {
262
+ return isGroupControl(def) ? def.groupOptions : isDataControl(def) && isDataGroupRenderer(def.renderOptions) ? def.renderOptions.groupOptions : undefined;
263
+ }
264
+ /**
265
+ * Checks if a control definition is display-only.
266
+ * @param {ControlDefinition} def - The control definition to check.
267
+ * @returns {boolean} - True if the control definition is display-only, false otherwise.
268
+ */
269
+ function isControlDisplayOnly(def) {
270
+ var _getGroupRendererOpti;
271
+ return Boolean((_getGroupRendererOpti = getGroupRendererOptions(def)) == null ? void 0 : _getGroupRendererOpti.displayOnly);
272
+ }
273
+ /**
274
+ * Returns the display-only render options for a control definition.
275
+ * @param d - The control definition to get the display-only render options for.
276
+ * @returns The display-only render options, or undefined if not applicable.
277
+ */
278
+ function getDisplayOnlyOptions(d) {
279
+ return isDataControl(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
280
+ }
281
+
282
+ exports.ExpressionType = void 0;
283
+ (function (ExpressionType) {
284
+ ExpressionType["Jsonata"] = "Jsonata";
285
+ ExpressionType["Data"] = "Data";
286
+ ExpressionType["DataMatch"] = "FieldValue";
287
+ ExpressionType["UserMatch"] = "UserMatch";
288
+ ExpressionType["NotEmpty"] = "NotEmpty";
289
+ ExpressionType["UUID"] = "UUID";
290
+ })(exports.ExpressionType || (exports.ExpressionType = {}));
291
+
292
+ function _arrayLikeToArray(r, a) {
293
+ (null == a || a > r.length) && (a = r.length);
294
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
295
+ return n;
296
+ }
297
+ function _createForOfIteratorHelperLoose(r, e) {
298
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
299
+ if (t) return (t = t.call(r)).next.bind(t);
300
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
301
+ t && (r = t);
302
+ var o = 0;
303
+ return function () {
304
+ return o >= r.length ? {
305
+ done: !0
306
+ } : {
307
+ done: !1,
308
+ value: r[o++]
309
+ };
310
+ };
311
+ }
312
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
313
+ }
314
+ function _extends() {
315
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
316
+ for (var e = 1; e < arguments.length; e++) {
317
+ var t = arguments[e];
318
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
319
+ }
320
+ return n;
321
+ }, _extends.apply(null, arguments);
322
+ }
323
+ function _inheritsLoose(t, o) {
324
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
325
+ }
326
+ function _setPrototypeOf(t, e) {
327
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
328
+ return t.__proto__ = e, t;
329
+ }, _setPrototypeOf(t, e);
330
+ }
331
+ function _unsupportedIterableToArray(r, a) {
332
+ if (r) {
333
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
334
+ var t = {}.toString.call(r).slice(8, -1);
335
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Enum representing the various field types.
341
+ */
342
+ exports.FieldType = void 0;
343
+ (function (FieldType) {
344
+ FieldType["String"] = "String";
345
+ FieldType["Bool"] = "Bool";
346
+ FieldType["Int"] = "Int";
347
+ FieldType["Date"] = "Date";
348
+ FieldType["DateTime"] = "DateTime";
349
+ FieldType["Time"] = "Time";
350
+ FieldType["Double"] = "Double";
351
+ FieldType["EntityRef"] = "EntityRef";
352
+ FieldType["Compound"] = "Compound";
353
+ FieldType["AutoId"] = "AutoId";
354
+ FieldType["Image"] = "Image";
355
+ FieldType["Any"] = "Any";
356
+ })(exports.FieldType || (exports.FieldType = {}));
357
+ /**
358
+ * Enum representing the various validation message types.
359
+ */
360
+ exports.ValidationMessageType = void 0;
361
+ (function (ValidationMessageType) {
362
+ ValidationMessageType["NotEmpty"] = "NotEmpty";
363
+ ValidationMessageType["MinLength"] = "MinLength";
364
+ ValidationMessageType["MaxLength"] = "MaxLength";
365
+ ValidationMessageType["NotAfterDate"] = "NotAfterDate";
366
+ ValidationMessageType["NotBeforeDate"] = "NotBeforeDate";
367
+ })(exports.ValidationMessageType || (exports.ValidationMessageType = {}));
368
+ function findField(fields, field) {
369
+ return fields.find(function (x) {
370
+ return x.field === field;
371
+ });
372
+ }
373
+ function isScalarField(sf) {
374
+ return !isCompoundField(sf);
375
+ }
376
+ function isCompoundField(sf) {
377
+ return sf.type === exports.FieldType.Compound;
378
+ }
379
+ function missingField(field) {
380
+ return {
381
+ field: "__missing",
382
+ type: exports.FieldType.Any,
383
+ displayName: field
384
+ };
385
+ }
386
+ exports.SchemaTags = void 0;
387
+ (function (SchemaTags) {
388
+ SchemaTags["NoControl"] = "_NoControl";
389
+ SchemaTags["HtmlEditor"] = "_HtmlEditor";
390
+ SchemaTags["ControlGroup"] = "_ControlGroup:";
391
+ SchemaTags["ControlRef"] = "_ControlRef:";
392
+ SchemaTags["IdField"] = "_IdField:";
393
+ })(exports.SchemaTags || (exports.SchemaTags = {}));
394
+ function getTagParam(field, tag) {
395
+ var _field$tags;
396
+ return (_field$tags = field.tags) == null || (_field$tags = _field$tags.find(function (x) {
397
+ return x.startsWith(tag);
398
+ })) == null ? void 0 : _field$tags.substring(tag.length);
399
+ }
400
+ function makeParamTag(tag, value) {
401
+ return "" + tag + value;
402
+ }
403
+
404
+ var SchemaTree = /*#__PURE__*/function () {
405
+ function SchemaTree() {}
406
+ var _proto = SchemaTree.prototype;
407
+ _proto.createChildNode = function createChildNode(parent, field) {
408
+ return new SchemaNode(parent.id + "/" + field.field, field, this, parent);
409
+ };
410
+ _proto.getSchema = function getSchema(schemaId) {
411
+ var _this$getSchemaTree;
412
+ return (_this$getSchemaTree = this.getSchemaTree(schemaId)) == null ? void 0 : _this$getSchemaTree.rootNode;
413
+ };
414
+ return SchemaTree;
415
+ }();
416
+ var SchemaTreeImpl = /*#__PURE__*/function (_SchemaTree) {
417
+ function SchemaTreeImpl(rootFields, lookup) {
418
+ var _this;
419
+ _this = _SchemaTree.call(this) || this;
420
+ _this.lookup = void 0;
421
+ _this.rootNode = void 0;
422
+ _this.lookup = lookup;
423
+ _this.rootNode = new SchemaNode("", {
424
+ type: exports.FieldType.Compound,
425
+ field: "",
426
+ children: rootFields
427
+ }, _this);
428
+ return _this;
429
+ }
430
+ _inheritsLoose(SchemaTreeImpl, _SchemaTree);
431
+ var _proto2 = SchemaTreeImpl.prototype;
432
+ _proto2.getSchemaTree = function getSchemaTree(schemaId) {
433
+ var _this$lookup;
434
+ return (_this$lookup = this.lookup) == null ? void 0 : _this$lookup.getSchemaTree(schemaId);
435
+ };
436
+ return SchemaTreeImpl;
437
+ }(SchemaTree);
438
+ function createSchemaTree(rootFields, lookup) {
439
+ return new SchemaTreeImpl(rootFields, lookup);
440
+ }
441
+ var SchemaNode = /*#__PURE__*/function () {
442
+ function SchemaNode(id, field, tree, parent) {
443
+ this.id = void 0;
444
+ this.field = void 0;
445
+ this.tree = void 0;
446
+ this.parent = void 0;
447
+ this.id = id;
448
+ this.field = field;
449
+ this.tree = tree;
450
+ this.parent = parent;
451
+ }
452
+ var _proto3 = SchemaNode.prototype;
453
+ _proto3.getSchema = function getSchema(schemaId) {
454
+ return this.tree.getSchema(schemaId);
455
+ };
456
+ _proto3.getUnresolvedFields = function getUnresolvedFields() {
457
+ return isCompoundField(this.field) ? this.field.children : [];
458
+ };
459
+ _proto3.getResolvedParent = function getResolvedParent(noRecurse) {
460
+ var _this$parent;
461
+ var f = this.field;
462
+ if (!isCompoundField(f)) return undefined;
463
+ var parentNode = f.schemaRef ? this.tree.getSchema(f.schemaRef) : !noRecurse && f.treeChildren ? (_this$parent = this.parent) == null ? void 0 : _this$parent.getResolvedParent() : undefined;
464
+ return parentNode != null ? parentNode : this;
465
+ };
466
+ _proto3.getResolvedFields = function getResolvedFields() {
467
+ var _resolvedParent$getUn;
468
+ var resolvedParent = this.getResolvedParent();
469
+ return (_resolvedParent$getUn = resolvedParent == null ? void 0 : resolvedParent.getUnresolvedFields()) != null ? _resolvedParent$getUn : [];
470
+ };
471
+ _proto3.getChildNodes = function getChildNodes() {
472
+ var node = this;
473
+ return node.getResolvedFields().map(function (x) {
474
+ return node.createChildNode(x);
475
+ });
476
+ };
477
+ _proto3.getChildField = function getChildField(field) {
478
+ var _this$getResolvedFiel;
479
+ return (_this$getResolvedFiel = this.getResolvedFields().find(function (x) {
480
+ return x.field === field;
481
+ })) != null ? _this$getResolvedFiel : missingField(field);
482
+ };
483
+ _proto3.createChildNode = function createChildNode(field) {
484
+ return this.tree.createChildNode(this, field);
485
+ };
486
+ _proto3.getChildNode = function getChildNode(field) {
487
+ return this.createChildNode(this.getChildField(field));
488
+ };
489
+ return SchemaNode;
490
+ }();
491
+ function resolveSchemaNode(node, fieldSegment) {
492
+ if (fieldSegment == ".") return node;
493
+ if (fieldSegment == "..") return node.parent;
494
+ return node.getChildNode(fieldSegment);
495
+ }
496
+ function createSchemaNode(field, lookup, parent) {
497
+ return new SchemaNode(parent ? parent.id + "/" + field.field : field.field, field, lookup, parent);
498
+ }
499
+ function createSchemaLookup(schemaMap) {
500
+ var lookup = {
501
+ getSchemaTree: getSchemaTree,
502
+ getSchema: getSchema
503
+ };
504
+ return lookup;
505
+ function getSchema(schemaId) {
506
+ return getSchemaTree(schemaId).rootNode;
507
+ }
508
+ function getSchemaTree(schemaId, additional) {
509
+ var fields = schemaMap[schemaId];
510
+ if (fields) {
511
+ return new SchemaTreeImpl(additional ? [].concat(fields, additional) : fields, lookup);
512
+ }
513
+ return undefined;
514
+ }
515
+ }
516
+ function schemaForFieldRef(fieldRef, schema) {
517
+ var _fieldRef$split;
518
+ return schemaForFieldPath((_fieldRef$split = fieldRef == null ? void 0 : fieldRef.split("/")) != null ? _fieldRef$split : [], schema);
519
+ }
520
+ function traverseSchemaPath(fieldPath, schema, acc, next) {
521
+ var i = 0;
522
+ while (i < fieldPath.length) {
523
+ var nextField = fieldPath[i];
524
+ var childNode = resolveSchemaNode(schema, nextField);
525
+ if (!childNode) {
526
+ childNode = createSchemaNode(missingField(nextField), schema.tree, schema);
527
+ }
528
+ acc = next(acc, childNode);
529
+ schema = childNode;
530
+ i++;
531
+ }
532
+ return acc;
533
+ }
534
+ function traverseData(fieldPath, root, data) {
535
+ return traverseSchemaPath(fieldPath, root, data, function (acc, n) {
536
+ return acc == null ? void 0 : acc[n.field.field];
537
+ });
538
+ }
539
+ function schemaForFieldPath(fieldPath, schema) {
540
+ var i = 0;
541
+ while (i < fieldPath.length) {
542
+ var nextField = fieldPath[i];
543
+ var childNode = resolveSchemaNode(schema, nextField);
544
+ if (!childNode) {
545
+ childNode = createSchemaNode(missingField(nextField), schema.tree, schema);
546
+ }
547
+ schema = childNode;
548
+ i++;
549
+ }
550
+ return schema;
551
+ }
552
+ function getSchemaNodePath(node) {
553
+ var paths = [];
554
+ var curNode = node;
555
+ while (curNode) {
556
+ paths.push(curNode.field.field);
557
+ curNode = curNode.parent;
558
+ }
559
+ return paths.reverse();
560
+ }
561
+ function getSchemaNodePathString(node) {
562
+ return getSchemaNodePath(node).join("/");
563
+ }
564
+ function isCompoundNode(node) {
565
+ return isCompoundField(node.field);
566
+ }
567
+ /**
568
+ * Returns the relative path from a parent node to a child node.
569
+ * @param parent
570
+ * @param child
571
+ */
572
+ function relativePath(parent, child) {
573
+ // return the path from child to parent
574
+ if (parent.id === child.id) return ".";
575
+ var parentPath = getSchemaNodePath(parent);
576
+ var childPath = getSchemaNodePath(child);
577
+ return relativeSegmentPath(parentPath, childPath);
578
+ }
579
+ /**
580
+ * Returns the relative path from a parent node to a child node.
581
+ * @param parentPath
582
+ * @param childPath
583
+ */
584
+ function relativeSegmentPath(parentPath, childPath) {
585
+ var i = 0;
586
+ while (i < parentPath.length && i < childPath.length && parentPath[i] === childPath[i]) {
587
+ i++;
588
+ }
589
+ var upLevels = parentPath.length - i;
590
+ var downPath = childPath.slice(i).join("/");
591
+ return "../".repeat(upLevels) + downPath;
592
+ }
593
+
594
+ function buildSchema(def) {
595
+ return Object.entries(def).map(function (x) {
596
+ return x[1](x[0]);
597
+ });
598
+ }
599
+ function stringField(displayName, options) {
600
+ return makeScalarField(_extends({
601
+ type: exports.FieldType.String,
602
+ displayName: displayName
603
+ }, options));
604
+ }
605
+ function stringOptionsField(displayName) {
606
+ return makeScalarField({
607
+ type: exports.FieldType.String,
608
+ displayName: displayName,
609
+ options: [].slice.call(arguments, 1)
610
+ });
611
+ }
612
+ function withScalarOptions(options, v) {
613
+ return function (n) {
614
+ return _extends({}, v(n), options);
615
+ };
616
+ }
617
+ function makeScalarField(options) {
618
+ return function (n) {
619
+ return _extends({}, defaultScalarField(n, n), options);
620
+ };
621
+ }
622
+ function makeCompoundField(options) {
623
+ return function (n) {
624
+ return _extends({}, defaultCompoundField(n, n, false), options);
625
+ };
626
+ }
627
+ function intField(displayName, options) {
628
+ return makeScalarField(_extends({
629
+ type: exports.FieldType.Int,
630
+ displayName: displayName
631
+ }, options));
632
+ }
633
+ function doubleField(displayName, options) {
634
+ return makeScalarField(_extends({
635
+ type: exports.FieldType.Double,
636
+ displayName: displayName
637
+ }, options));
638
+ }
639
+ function dateField(displayName, options) {
640
+ return makeScalarField(_extends({
641
+ type: exports.FieldType.Date,
642
+ displayName: displayName
643
+ }, options));
644
+ }
645
+ function timeField(displayName, options) {
646
+ return makeScalarField(_extends({
647
+ type: exports.FieldType.Time,
648
+ displayName: displayName
649
+ }, options));
650
+ }
651
+ function dateTimeField(displayName, options) {
652
+ return makeScalarField(_extends({
653
+ type: exports.FieldType.DateTime,
654
+ displayName: displayName
655
+ }, options));
656
+ }
657
+ function boolField(displayName, options) {
658
+ return makeScalarField(_extends({
659
+ type: exports.FieldType.Bool,
660
+ displayName: displayName
661
+ }, options));
662
+ }
663
+ function compoundField(displayName, fields, other) {
664
+ return function (field) {
665
+ return _extends({}, defaultCompoundField(field, displayName, false), other, {
666
+ children: fields
667
+ });
668
+ };
669
+ }
670
+ function defaultScalarField(field, displayName) {
671
+ return {
672
+ field: field,
673
+ displayName: displayName,
674
+ type: exports.FieldType.String
675
+ };
676
+ }
677
+ function defaultCompoundField(field, displayName, collection) {
678
+ return {
679
+ field: field,
680
+ displayName: displayName,
681
+ type: exports.FieldType.Compound,
682
+ collection: collection,
683
+ children: []
684
+ };
685
+ }
686
+ function mergeField(field, mergeInto) {
687
+ var existing = mergeInto.find(function (x) {
688
+ return x.field === field.field;
689
+ });
690
+ if (existing) {
691
+ return mergeInto.map(function (x) {
692
+ return x !== existing ? x : _extends({}, x, {
693
+ onlyForTypes: mergeTypes(x.onlyForTypes, field.onlyForTypes)
694
+ });
695
+ });
696
+ }
697
+ return [].concat(mergeInto, [field]);
698
+ function mergeTypes(f, s) {
699
+ if (!f) return s;
700
+ if (!s) return f;
701
+ var extras = s.filter(function (x) {
702
+ return !f.includes(x);
703
+ });
704
+ return extras.length ? [].concat(f, extras) : f;
705
+ }
706
+ }
707
+ function mergeFields(fields, name, value, newFields) {
708
+ var withType = fields.map(function (x) {
709
+ return x.isTypeField ? addFieldOption(x, name, value) : x;
710
+ });
711
+ return newFields.map(function (x) {
712
+ return _extends({}, x, {
713
+ onlyForTypes: [value]
714
+ });
715
+ }).reduce(function (af, x) {
716
+ return mergeField(x, af);
717
+ }, withType);
718
+ }
719
+ function addFieldOption(typeField, name, value) {
720
+ var _typeField$options;
721
+ var options = (_typeField$options = typeField.options) != null ? _typeField$options : [];
722
+ if (options.some(function (x) {
723
+ return x.value === value;
724
+ })) return typeField;
725
+ return _extends({}, typeField, {
726
+ options: [].concat(options, [{
727
+ name: name,
728
+ value: value
729
+ }])
730
+ });
731
+ }
732
+ function resolveSchemas(schemaMap) {
733
+ var out = {};
734
+ function resolveSchemaType(type) {
735
+ if (type in out) {
736
+ return out[type];
737
+ }
738
+ var resolvedFields = [];
739
+ out[type] = resolvedFields;
740
+ schemaMap[type].forEach(function (x) {
741
+ if (isCompoundField(x) && x.schemaRef) {
742
+ resolvedFields.push(_extends({}, x, {
743
+ children: resolveSchemaType(x.schemaRef)
744
+ }));
745
+ } else {
746
+ resolvedFields.push(x);
747
+ }
748
+ });
749
+ return resolvedFields;
750
+ }
751
+ Object.keys(schemaMap).forEach(resolveSchemaType);
752
+ return out;
753
+ }
754
+
755
+ exports.ValidatorType = void 0;
756
+ (function (ValidatorType) {
757
+ ValidatorType["Jsonata"] = "Jsonata";
758
+ ValidatorType["Date"] = "Date";
759
+ ValidatorType["Length"] = "Length";
760
+ })(exports.ValidatorType || (exports.ValidatorType = {}));
761
+ exports.DateComparison = void 0;
762
+ (function (DateComparison) {
763
+ DateComparison["NotBefore"] = "NotBefore";
764
+ DateComparison["NotAfter"] = "NotAfter";
765
+ })(exports.DateComparison || (exports.DateComparison = {}));
766
+
767
+ var SchemaDataTree = function SchemaDataTree() {};
768
+ var SchemaDataNode = /*#__PURE__*/function () {
769
+ function SchemaDataNode(id, schema, elementIndex, control, tree, parent) {
770
+ this.id = void 0;
771
+ this.schema = void 0;
772
+ this.elementIndex = void 0;
773
+ this.control = void 0;
774
+ this.tree = void 0;
775
+ this.parent = void 0;
776
+ this.id = id;
777
+ this.schema = schema;
778
+ this.elementIndex = elementIndex;
779
+ this.control = control;
780
+ this.tree = tree;
781
+ this.parent = parent;
782
+ }
783
+ var _proto = SchemaDataNode.prototype;
784
+ _proto.getChild = function getChild(childNode) {
785
+ return this.tree.getChild(this, childNode);
786
+ };
787
+ _proto.getChildElement = function getChildElement(elementIndex) {
788
+ return this.tree.getChildElement(this, elementIndex);
789
+ };
790
+ return SchemaDataNode;
791
+ }();
792
+ function getMetaFields(control) {
793
+ return controls.ensureMetaValue(control, "metaFields", function () {
794
+ return controls.newControl({});
795
+ });
796
+ }
797
+ var SchemaDataTreeImpl = /*#__PURE__*/function (_SchemaDataTree) {
798
+ function SchemaDataTreeImpl(rootSchema, rootControl) {
799
+ var _this;
800
+ _this = _SchemaDataTree.call(this) || this;
801
+ _this.rootNode = void 0;
802
+ _this.rootNode = new SchemaDataNode("", rootSchema, undefined, rootControl, _this);
803
+ return _this;
804
+ }
805
+ _inheritsLoose(SchemaDataTreeImpl, _SchemaDataTree);
806
+ var _proto2 = SchemaDataTreeImpl.prototype;
807
+ _proto2.getChild = function getChild(parent, childNode) {
808
+ var objControl = parent.control;
809
+ if (childNode.field.meta) {
810
+ objControl = getMetaFields(objControl);
811
+ }
812
+ var child = objControl.fields[childNode.field.field];
813
+ return new SchemaDataNode(child.uniqueId.toString(), childNode, undefined, child, this, parent);
814
+ };
815
+ _proto2.getChildElement = function getChildElement(parent, elementIndex) {
816
+ var elemControl = parent.control;
817
+ var elemChild = elemControl.elements[elementIndex];
818
+ return new SchemaDataNode(elemChild.uniqueId.toString(), parent.schema, elementIndex, elemChild, this, parent);
819
+ };
820
+ return SchemaDataTreeImpl;
821
+ }(SchemaDataTree);
822
+ /**
823
+ * @deprecated Use createSchemaDataNode instead.
824
+ */
825
+ var makeSchemaDataNode = createSchemaDataNode;
826
+ function createSchemaDataNode(schema, control) {
827
+ return new SchemaDataTreeImpl(schema, control).rootNode;
828
+ }
829
+ function schemaDataForFieldRef(fieldRef, schema) {
830
+ var _fieldRef$split;
831
+ return schemaDataForFieldPath((_fieldRef$split = fieldRef == null ? void 0 : fieldRef.split("/")) != null ? _fieldRef$split : [], schema);
832
+ }
833
+ function schemaDataForFieldPath(fieldPath, dataNode) {
834
+ var i = 0;
835
+ while (i < fieldPath.length) {
836
+ var _nextNode;
837
+ var nextField = fieldPath[i];
838
+ var nextNode = nextField === ".." ? dataNode.parent : nextField === "." ? dataNode : lookupField(nextField);
839
+ (_nextNode = nextNode) != null ? _nextNode : nextNode = createSchemaDataNode(createSchemaNode(missingField(nextField), dataNode.schema.tree, dataNode.schema), controls.newControl(undefined));
840
+ dataNode = nextNode;
841
+ i++;
842
+ }
843
+ return dataNode;
844
+ function lookupField(field) {
845
+ var childNode = resolveSchemaNode(dataNode.schema, field);
846
+ if (childNode) {
847
+ return dataNode.getChild(childNode);
848
+ }
849
+ return undefined;
850
+ }
851
+ }
852
+ function validDataNode(context) {
853
+ var parent = context.parent;
854
+ if (!parent) return true;
855
+ if (parent.schema.field.collection && parent.elementIndex == null) return validDataNode(parent);
856
+ return controls.ensureMetaValue(context.control, "validForSchema", function () {
857
+ var c = controls.newControl(true);
858
+ controls.updateComputedValue(c, function () {
859
+ if (!validDataNode(parent)) return false;
860
+ var types = context.schema.field.onlyForTypes;
861
+ if (types == null || types.length === 0) return true;
862
+ var typeNode = parent.schema.getChildNodes().find(function (x) {
863
+ return x.field.isTypeField;
864
+ });
865
+ if (typeNode == null) {
866
+ console.warn("No type field found for", parent.schema);
867
+ return false;
868
+ }
869
+ var typeField = parent.getChild(typeNode).control;
870
+ return typeField && types.includes(typeField.value);
871
+ });
872
+ return c;
873
+ }).value;
874
+ }
875
+ function hideDisplayOnly(context, schemaInterface, definition) {
876
+ var _context$control;
877
+ var displayOptions = getDisplayOnlyOptions(definition);
878
+ return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(context.schema.field, (_context$control = context.control) == null ? void 0 : _context$control.value);
879
+ }
880
+
881
+ var DefaultSchemaInterface = /*#__PURE__*/function () {
882
+ function DefaultSchemaInterface(boolStrings, parseDateTime) {
883
+ if (boolStrings === void 0) {
884
+ boolStrings = ["No", "Yes"];
885
+ }
886
+ if (parseDateTime === void 0) {
887
+ parseDateTime = function parseDateTime(s) {
888
+ return Date.parse(s);
889
+ };
890
+ }
891
+ this.boolStrings = void 0;
892
+ this.parseDateTime = void 0;
893
+ this.boolStrings = boolStrings;
894
+ this.parseDateTime = parseDateTime;
895
+ }
896
+ var _proto = DefaultSchemaInterface.prototype;
897
+ _proto.parseToMillis = function parseToMillis(field, v) {
898
+ return this.parseDateTime(v);
899
+ };
900
+ _proto.validationMessageText = function validationMessageText(field, messageType, actual, expected) {
901
+ switch (messageType) {
902
+ case exports.ValidationMessageType.NotEmpty:
903
+ return "Please enter a value";
904
+ case exports.ValidationMessageType.MinLength:
905
+ return "Length must be at least " + expected;
906
+ case exports.ValidationMessageType.MaxLength:
907
+ return "Length must be less than " + expected;
908
+ case exports.ValidationMessageType.NotBeforeDate:
909
+ return "Date must not be before " + new Date(expected).toDateString();
910
+ case exports.ValidationMessageType.NotAfterDate:
911
+ return "Date must not be after " + new Date(expected).toDateString();
912
+ default:
913
+ return "Unknown error";
914
+ }
915
+ };
916
+ _proto.getDataOptions = function getDataOptions(node) {
917
+ return this.getNodeOptions(node.schema);
918
+ };
919
+ _proto.getNodeOptions = function getNodeOptions(node) {
920
+ return this.getOptions(node.field);
921
+ };
922
+ _proto.getOptions = function getOptions(_ref) {
923
+ var options = _ref.options;
924
+ return options && options.length > 0 ? options : null;
925
+ };
926
+ _proto.getFilterOptions = function getFilterOptions(array, field) {
927
+ return this.getNodeOptions(field);
928
+ };
929
+ _proto.isEmptyValue = function isEmptyValue(f, value) {
930
+ if (f.collection) return Array.isArray(value) ? value.length === 0 : value == null;
931
+ switch (f.type) {
932
+ case exports.FieldType.String:
933
+ case exports.FieldType.DateTime:
934
+ case exports.FieldType.Date:
935
+ case exports.FieldType.Time:
936
+ return !value;
937
+ default:
938
+ return value == null;
939
+ }
940
+ };
941
+ _proto.searchText = function searchText(field, value) {
942
+ var _this$textValue$toLow, _this$textValue;
943
+ return (_this$textValue$toLow = (_this$textValue = this.textValue(field, value)) == null ? void 0 : _this$textValue.toLowerCase()) != null ? _this$textValue$toLow : "";
944
+ };
945
+ _proto.textValueForData = function textValueForData(dataNode) {
946
+ var options = this.getDataOptions(dataNode);
947
+ return this.textValue(dataNode.schema.field, dataNode.control.value, dataNode.elementIndex != null, options);
948
+ };
949
+ _proto.textValue = function textValue(field, value, element, options) {
950
+ var actualOptions = options != null ? options : this.getOptions(field);
951
+ var option = actualOptions == null ? void 0 : actualOptions.find(function (x) {
952
+ return x.value === value;
953
+ });
954
+ if (option) return option.name;
955
+ switch (field.type) {
956
+ case exports.FieldType.Date:
957
+ return value ? new Date(value).toLocaleDateString() : undefined;
958
+ case exports.FieldType.DateTime:
959
+ return value ? new Date(this.parseToMillis(field, value)).toLocaleString() : undefined;
960
+ case exports.FieldType.Time:
961
+ return value ? new Date("1970-01-01T" + value).toLocaleTimeString() : undefined;
962
+ case exports.FieldType.Bool:
963
+ return this.boolStrings[value ? 1 : 0];
964
+ default:
965
+ return value != null ? value.toString() : undefined;
966
+ }
967
+ };
968
+ _proto.controlLength = function controlLength(f, control) {
969
+ var _control$elements$len, _control$elements;
970
+ 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);
971
+ };
972
+ _proto.valueLength = function valueLength(field, value) {
973
+ var _ref2;
974
+ return (_ref2 = value && (value == null ? void 0 : value.length)) != null ? _ref2 : 0;
975
+ };
976
+ _proto.compareValue = function compareValue(field, v1, v2) {
977
+ if (v1 == null) return v2 == null ? 0 : 1;
978
+ if (v2 == null) return -1;
979
+ switch (field.type) {
980
+ case exports.FieldType.Date:
981
+ case exports.FieldType.DateTime:
982
+ case exports.FieldType.Time:
983
+ case exports.FieldType.String:
984
+ return v1.localeCompare(v2);
985
+ case exports.FieldType.Bool:
986
+ return v1 ? v2 ? 0 : 1 : -1;
987
+ case exports.FieldType.Int:
988
+ case exports.FieldType.Double:
989
+ return v1 - v2;
990
+ default:
991
+ return 0;
992
+ }
993
+ };
994
+ _proto.compoundFieldSetup = function compoundFieldSetup(f) {
995
+ var _this = this;
996
+ return f.getChildNodes().map(function (x) {
997
+ var field = x.field.field;
998
+ return [field, _this.makeControlSetup(x)];
999
+ });
1000
+ };
1001
+ _proto.compoundFieldEquality = function compoundFieldEquality(f) {
1002
+ var _this2 = this;
1003
+ return f.getChildNodes().map(function (x) {
1004
+ var field = x.field.field;
1005
+ return [field, function (a, b) {
1006
+ return _this2.makeEqualityFunc(x)(a[field], b[field]);
1007
+ }];
1008
+ });
1009
+ };
1010
+ _proto.makeEqualityFunc = function makeEqualityFunc(field, element) {
1011
+ if (field.field.collection && !element) {
1012
+ var elemEqual = this.makeEqualityFunc(field, true);
1013
+ return function (a, b) {
1014
+ if (a === b) return true;
1015
+ if (a == null || b == null) return false;
1016
+ if (a.length !== b.length) return false;
1017
+ for (var i = 0; i < a.length; i++) {
1018
+ if (!elemEqual(a[i], b[i])) return false;
1019
+ }
1020
+ return true;
1021
+ };
1022
+ }
1023
+ switch (field.field.type) {
1024
+ case exports.FieldType.Compound:
1025
+ var allChecks = this.compoundFieldEquality(field);
1026
+ return function (a, b) {
1027
+ return a === b || a != null && b != null && allChecks.every(function (x) {
1028
+ return x[1](a, b);
1029
+ });
1030
+ };
1031
+ default:
1032
+ return function (a, b) {
1033
+ return a === b;
1034
+ };
1035
+ }
1036
+ };
1037
+ _proto.makeControlSetup = function makeControlSetup(field, element) {
1038
+ var setup = {
1039
+ equals: this.makeEqualityFunc(field, element)
1040
+ };
1041
+ if (field.field.collection && !element) {
1042
+ setup.elems = this.makeControlSetup(field, true);
1043
+ return setup;
1044
+ }
1045
+ switch (field.field.type) {
1046
+ case exports.FieldType.Compound:
1047
+ setup.fields = Object.fromEntries(this.compoundFieldSetup(field));
1048
+ }
1049
+ return setup;
1050
+ };
1051
+ return DefaultSchemaInterface;
1052
+ }();
1053
+ var defaultSchemaInterface = new DefaultSchemaInterface();
1054
+
1055
+ var FormNode = /*#__PURE__*/function () {
1056
+ function FormNode(id, definition, tree, parent) {
1057
+ this.id = void 0;
1058
+ this.definition = void 0;
1059
+ this.tree = void 0;
1060
+ this.parent = void 0;
1061
+ this.id = id;
1062
+ this.definition = definition;
1063
+ this.tree = tree;
1064
+ this.parent = parent;
1065
+ }
1066
+ var _proto = FormNode.prototype;
1067
+ _proto.visit = function visit(visitFn) {
1068
+ var res = visitFn(this);
1069
+ if (res !== undefined) return res;
1070
+ var children = this.getUnresolvedChildNodes();
1071
+ for (var _iterator = _createForOfIteratorHelperLoose(children), _step; !(_step = _iterator()).done;) {
1072
+ var child = _step.value;
1073
+ var _res = child.visit(visitFn);
1074
+ if (_res !== undefined) return _res;
1075
+ }
1076
+ return undefined;
1077
+ };
1078
+ _proto.getResolvedChildren = function getResolvedChildren() {
1079
+ var _children, _ref;
1080
+ var childRefId = this.definition.childRefId;
1081
+ var parent = childRefId ? this.tree.getByRefId(childRefId) : undefined;
1082
+ return (_children = (_ref = parent != null ? parent : this.definition) == null ? void 0 : _ref.children) != null ? _children : [];
1083
+ };
1084
+ _proto.createChildNode = function createChildNode(childId, childDef) {
1085
+ return new FormNode(this.tree.getChildId(this.id, childId, childDef), childDef, this.tree, this);
1086
+ };
1087
+ _proto.getChildNodes = function getChildNodes() {
1088
+ var _this = this;
1089
+ var resolved = this.getResolvedChildren();
1090
+ return resolved.map(function (x, i) {
1091
+ return _this.createChildNode(i.toString(), x);
1092
+ });
1093
+ };
1094
+ _proto.getUnresolvedChildNodes = function getUnresolvedChildNodes() {
1095
+ var _this$definition$chil,
1096
+ _this$definition$chil2,
1097
+ _this2 = this;
1098
+ return (_this$definition$chil = (_this$definition$chil2 = this.definition.children) == null ? void 0 : _this$definition$chil2.map(function (x, i) {
1099
+ return _this2.createChildNode(i.toString(), x);
1100
+ })) != null ? _this$definition$chil : [];
1101
+ };
1102
+ return FormNode;
1103
+ }();
1104
+ var FormTree = /*#__PURE__*/function () {
1105
+ function FormTree() {}
1106
+ var _proto2 = FormTree.prototype;
1107
+ _proto2.getChildId = function getChildId(parentId, childId, control) {
1108
+ return parentId + "/" + childId;
1109
+ };
1110
+ return FormTree;
1111
+ }();
1112
+ function getControlIds(definition) {
1113
+ var _definition$children$, _definition$children;
1114
+ var childEntries = (_definition$children$ = (_definition$children = definition.children) == null ? void 0 : _definition$children.flatMap(getControlIds)) != null ? _definition$children$ : [];
1115
+ return !definition.id ? childEntries : [[definition.id, definition]].concat(childEntries);
1116
+ }
1117
+ function createControlMap(control) {
1118
+ return Object.fromEntries(getControlIds(control));
1119
+ }
1120
+ var FormTreeImpl = /*#__PURE__*/function (_FormTree) {
1121
+ function FormTreeImpl(forms, root) {
1122
+ var _this3;
1123
+ _this3 = _FormTree.call(this) || this;
1124
+ _this3.forms = void 0;
1125
+ _this3.controlMap = void 0;
1126
+ _this3.rootNode = void 0;
1127
+ _this3.forms = forms;
1128
+ _this3.rootNode = new FormNode("", root, _this3);
1129
+ _this3.controlMap = createControlMap(root);
1130
+ return _this3;
1131
+ }
1132
+ _inheritsLoose(FormTreeImpl, _FormTree);
1133
+ var _proto3 = FormTreeImpl.prototype;
1134
+ _proto3.getByRefId = function getByRefId(id) {
1135
+ return this.controlMap[id];
1136
+ };
1137
+ _proto3.getForm = function getForm(formId) {
1138
+ return this.forms.getForm(formId);
1139
+ };
1140
+ return FormTreeImpl;
1141
+ }(FormTree);
1142
+ function legacyFormNode(definition) {
1143
+ return createFormTree([definition]).rootNode.getChildNodes()[0];
1144
+ }
1145
+ function createFormTree(controls, getForm) {
1146
+ if (getForm === void 0) {
1147
+ getForm = {
1148
+ getForm: function getForm() {
1149
+ return undefined;
1150
+ }
1151
+ };
1152
+ }
1153
+ return new FormTreeImpl(getForm, {
1154
+ type: exports.ControlDefinitionType.Group,
1155
+ children: controls,
1156
+ groupOptions: {
1157
+ type: exports.GroupRenderType.Standard,
1158
+ hideTitle: true
1159
+ }
1160
+ });
1161
+ }
1162
+ function createFormLookup(formMap) {
1163
+ var lookup = {
1164
+ getForm: getForm
1165
+ };
1166
+ var forms = Object.fromEntries(Object.entries(formMap).map(function (_ref2) {
1167
+ var k = _ref2[0],
1168
+ v = _ref2[1];
1169
+ return [k, createFormTree(v, lookup)];
1170
+ }));
1171
+ return lookup;
1172
+ function getForm(formId) {
1173
+ return forms[formId];
1174
+ }
1175
+ }
1176
+ function fieldPathForDefinition(c) {
1177
+ var fieldName = isGroupControl(c) ? c.compoundField : isDataControl(c) ? c.field : undefined;
1178
+ return fieldName == null ? void 0 : fieldName.split("/");
1179
+ }
1180
+ function lookupDataNode(c, parentNode) {
1181
+ var fieldNamePath = fieldPathForDefinition(c);
1182
+ return fieldNamePath ? schemaDataForFieldPath(fieldNamePath, parentNode) : undefined;
1183
+ }
1184
+ /**
1185
+ * @deprecated use visitFormNodeData instead
1186
+ */
1187
+ function visitControlDataArray(controls, context, cb) {
1188
+ if (!controls) return undefined;
1189
+ for (var _iterator2 = _createForOfIteratorHelperLoose(controls), _step2; !(_step2 = _iterator2()).done;) {
1190
+ var c = _step2.value;
1191
+ var r = visitControlData(c, context, cb);
1192
+ if (r !== undefined) return r;
1193
+ }
1194
+ return undefined;
1195
+ }
1196
+ /**
1197
+ * @deprecated use visitFormDataInContext instead
1198
+ */
1199
+ function visitControlData(definition, ctx, cb) {
1200
+ return visitFormDataInContext(ctx, legacyFormNode(definition), function (n, d) {
1201
+ return cb(d, n);
1202
+ });
1203
+ }
1204
+ function visitFormData(node, dataNode, cb, notSelf) {
1205
+ var def = node.definition;
1206
+ var result = !notSelf && isDataControl(def) ? cb(dataNode, def) : undefined;
1207
+ if (result !== undefined) return result;
1208
+ if (dataNode.elementIndex == null && dataNode.schema.field.collection) {
1209
+ var _l = dataNode.control.elements.length;
1210
+ for (var i = 0; i < _l; i++) {
1211
+ var elemChild = dataNode.getChildElement(i);
1212
+ var elemResult = visitFormData(node, elemChild, cb);
1213
+ if (elemResult !== undefined) return elemResult;
1214
+ }
1215
+ return undefined;
1216
+ }
1217
+ if (dataNode.control.isNull) return undefined;
1218
+ var children = node.getChildNodes();
1219
+ var l = children.length;
1220
+ for (var _i = 0; _i < l; _i++) {
1221
+ var _elemResult = visitFormDataInContext(dataNode, children[_i], cb);
1222
+ if (_elemResult !== undefined) return _elemResult;
1223
+ }
1224
+ return undefined;
1225
+ }
1226
+ function visitFormDataInContext(parentContext, node, cb) {
1227
+ var dataNode = lookupDataNode(node.definition, parentContext);
1228
+ return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
1229
+ }
1230
+
1231
+ /**
1232
+ * Converts a JSON path array to a string.
1233
+ * @param jsonPath - The JSON path array to convert.
1234
+ * @param customIndex - Optional function to customize the index format.
1235
+ * @returns The JSON path string.
1236
+ */
1237
+ function jsonPathString(jsonPath, customIndex) {
1238
+ var out = "";
1239
+ jsonPath.forEach(function (v, i) {
1240
+ if (typeof v === "number") {
1241
+ var _customIndex;
1242
+ out += (_customIndex = customIndex == null ? void 0 : customIndex(v)) != null ? _customIndex : "[" + v + "]";
1243
+ } else {
1244
+ if (i > 0) out += ".";
1245
+ out += v;
1246
+ }
1247
+ });
1248
+ return out;
1249
+ }
1250
+ function createScopedComputed(parent, compute) {
1251
+ var c = controls.newControl(undefined);
1252
+ controls.updateComputedValue(c, compute);
1253
+ controls.addDependent(parent, c);
1254
+ return c.as();
1255
+ }
1256
+ function createScoped(parent, value, setup) {
1257
+ var c = controls.newControl(value, setup);
1258
+ controls.addDependent(parent, c);
1259
+ return c;
1260
+ }
1261
+
1262
+ var _defaultEvaluators;
1263
+ var dataEval = function dataEval(fvExpr, _ref) {
1264
+ var node = _ref.dataNode,
1265
+ returnResult = _ref.returnResult,
1266
+ scope = _ref.scope;
1267
+ controls.createSyncEffect(function () {
1268
+ var _otherField$control;
1269
+ var otherField = schemaDataForFieldRef(fvExpr.field, node);
1270
+ returnResult((_otherField$control = otherField.control) == null ? void 0 : _otherField$control.value);
1271
+ }, scope);
1272
+ };
1273
+ var dataMatchEval = function dataMatchEval(matchExpr, _ref2) {
1274
+ var dataNode = _ref2.dataNode,
1275
+ returnResult = _ref2.returnResult,
1276
+ scope = _ref2.scope;
1277
+ controls.createSyncEffect(function () {
1278
+ var otherField = schemaDataForFieldRef(matchExpr.field, dataNode);
1279
+ var fv = otherField == null ? void 0 : otherField.control.value;
1280
+ returnResult(Array.isArray(fv) ? fv.includes(matchExpr.value) : fv === matchExpr.value);
1281
+ }, scope);
1282
+ };
1283
+ var notEmptyEval = function notEmptyEval(expr, _ref3) {
1284
+ var returnResult = _ref3.returnResult,
1285
+ dataNode = _ref3.dataNode,
1286
+ scope = _ref3.scope,
1287
+ schemaInterface = _ref3.schemaInterface;
1288
+ controls.createSyncEffect(function () {
1289
+ var _otherField$control2;
1290
+ var otherField = schemaDataForFieldRef(expr.field, dataNode);
1291
+ var fv = (_otherField$control2 = otherField.control) == null ? void 0 : _otherField$control2.value;
1292
+ var field = otherField.schema.field;
1293
+ var empty = !!expr.empty;
1294
+ returnResult(field && empty === schemaInterface.isEmptyValue(field, fv));
1295
+ }, scope);
1296
+ };
1297
+ var jsonataEval = function jsonataEval(expr, _ref4) {
1298
+ var runJsonata = function runJsonata(effect, signal) {
1299
+ try {
1300
+ var bindings = controls.collectChanges(effect.collectUsage, function () {
1301
+ return variables == null ? void 0 : variables.value;
1302
+ });
1303
+ return Promise.resolve(parsedJsonata.fields.expr.value.evaluate(controls.trackedValue(rootData, effect.collectUsage), bindings)).then(function (evalResult) {
1304
+ // console.log(parsedJsonata.fields.fullExpr.value, evalResult, bindings);
1305
+ controls.collectChanges(effect.collectUsage, function () {
1306
+ return returnResult(evalResult);
1307
+ });
1308
+ });
1309
+ } catch (e) {
1310
+ return Promise.reject(e);
1311
+ }
1312
+ };
1313
+ var scope = _ref4.scope,
1314
+ returnResult = _ref4.returnResult,
1315
+ dataNode = _ref4.dataNode,
1316
+ variables = _ref4.variables;
1317
+ var path = getJsonPath(dataNode);
1318
+ var pathString = jsonPathString(path, function (x) {
1319
+ return "#$i[" + x + "]";
1320
+ });
1321
+ var rootData = getRootDataNode(dataNode).control;
1322
+ var parsedJsonata = createScopedComputed(scope, function () {
1323
+ var jExpr = expr.expression;
1324
+ var fullExpr = pathString ? pathString + ".(" + jExpr + ")" : jExpr;
1325
+ try {
1326
+ return {
1327
+ expr: jsonata__default["default"](fullExpr ? fullExpr : "null"),
1328
+ fullExpr: fullExpr
1329
+ };
1330
+ } catch (e) {
1331
+ console.error(e);
1332
+ return {
1333
+ expr: jsonata__default["default"]("null"),
1334
+ fullExpr: fullExpr
1335
+ };
1336
+ }
1337
+ });
1338
+ controls.createAsyncEffect(runJsonata, scope);
1339
+ };
1340
+ var uuidEval = function uuidEval(_, ctx) {
1341
+ ctx.returnResult(uuid.v4());
1342
+ };
1343
+ var defaultEvaluators = (_defaultEvaluators = {}, _defaultEvaluators[exports.ExpressionType.DataMatch] = dataMatchEval, _defaultEvaluators[exports.ExpressionType.Data] = dataEval, _defaultEvaluators[exports.ExpressionType.NotEmpty] = notEmptyEval, _defaultEvaluators[exports.ExpressionType.Jsonata] = jsonataEval, _defaultEvaluators[exports.ExpressionType.UUID] = uuidEval, _defaultEvaluators);
1344
+
1345
+ var _defaultValidators;
1346
+ var jsonataValidator = function jsonataValidator(validation, context) {
1347
+ var error = createScopedComputed(context, function () {
1348
+ return undefined;
1349
+ });
1350
+ jsonataEval({
1351
+ type: exports.ExpressionType.Jsonata,
1352
+ expression: validation.expression
1353
+ }, {
1354
+ scope: error,
1355
+ dataNode: context.parentData,
1356
+ returnResult: function returnResult(v) {
1357
+ controls.trackControlChange(context.data.control, controls.ControlChange.Validate);
1358
+ console.log("Setting jsonata error", v);
1359
+ context.data.control.setError("jsonata", v == null ? void 0 : v.toString());
1360
+ },
1361
+ schemaInterface: context.schemaInterface,
1362
+ variables: context.formContext.fields.variables
1363
+ });
1364
+ };
1365
+ var lengthValidator = function lengthValidator(lv, context) {
1366
+ var schemaInterface = context.schemaInterface;
1367
+ context.addSync(function () {
1368
+ var field = context.data.schema.field;
1369
+ var control = context.data.control;
1370
+ var len = schemaInterface.controlLength(field, control);
1371
+ if (lv.min != null && len < lv.min) {
1372
+ if (field != null && field.collection) {
1373
+ control.setValue(function (v) {
1374
+ return Array.isArray(v) ? v.concat(Array.from({
1375
+ length: lv.min - v.length
1376
+ })) : Array.from({
1377
+ length: lv.min
1378
+ });
1379
+ });
1380
+ } else {
1381
+ return schemaInterface.validationMessageText(field, exports.ValidationMessageType.MinLength, len, lv.min);
1382
+ }
1383
+ } else if (lv.max != null && len > lv.max) {
1384
+ return schemaInterface.validationMessageText(field, exports.ValidationMessageType.MaxLength, len, lv.max);
1385
+ }
1386
+ return undefined;
1387
+ });
1388
+ };
1389
+ var dateValidator = function dateValidator(dv, context) {
1390
+ var schemaInterface = context.schemaInterface;
1391
+ var field = context.data.schema.field;
1392
+ var comparisonDate;
1393
+ if (dv.fixedDate) {
1394
+ comparisonDate = schemaInterface.parseToMillis(field, dv.fixedDate);
1395
+ } else {
1396
+ var nowDate = new Date();
1397
+ comparisonDate = Date.UTC(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate());
1398
+ if (dv.daysFromCurrent) {
1399
+ comparisonDate += dv.daysFromCurrent * 86400000;
1400
+ }
1401
+ }
1402
+ context.addSync(function (v) {
1403
+ if (v) {
1404
+ var selDate = schemaInterface.parseToMillis(field, v);
1405
+ var notAfter = dv.comparison === exports.DateComparison.NotAfter;
1406
+ if (notAfter ? selDate > comparisonDate : selDate < comparisonDate) {
1407
+ return schemaInterface.validationMessageText(field, notAfter ? exports.ValidationMessageType.NotAfterDate : exports.ValidationMessageType.NotBeforeDate, selDate, comparisonDate);
1408
+ }
1409
+ }
1410
+ return null;
1411
+ });
1412
+ };
1413
+ var defaultValidators = (_defaultValidators = {}, _defaultValidators[exports.ValidatorType.Jsonata] = jsonataValidator, _defaultValidators[exports.ValidatorType.Length] = lengthValidator, _defaultValidators[exports.ValidatorType.Date] = dateValidator, _defaultValidators);
1414
+ function createValidators(def, context) {
1415
+ if (isDataControl(def)) {
1416
+ var _def$validators;
1417
+ var schemaInterface = context.schemaInterface;
1418
+ if (def.required) {
1419
+ context.addSync(function (v) {
1420
+ var field = context.data.schema.field;
1421
+ return schemaInterface.isEmptyValue(field, v) ? schemaInterface.validationMessageText(field, exports.ValidationMessageType.NotEmpty, false, true) : null;
1422
+ });
1423
+ }
1424
+ (_def$validators = def.validators) == null || _def$validators.forEach(function (x) {
1425
+ var _defaultValidators$x$;
1426
+ return (_defaultValidators$x$ = defaultValidators[x.type]) == null ? void 0 : _defaultValidators$x$.call(defaultValidators, x, context);
1427
+ });
1428
+ }
1429
+ }
1430
+ function setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode) {
1431
+ var validationEnabled = createScopedComputed(controlImpl, function () {
1432
+ return !definition.hidden;
1433
+ });
1434
+ var validatorsScope = controls.createCleanupScope();
1435
+ controls.createEffect(function () {
1436
+ validatorsScope.cleanup();
1437
+ var dn = dataNode.value;
1438
+ if (dn) {
1439
+ var syncValidations = [];
1440
+ createValidators(formNode.definition, {
1441
+ data: dn,
1442
+ parentData: parent,
1443
+ validationEnabled: validationEnabled,
1444
+ schemaInterface: schemaInterface,
1445
+ addSync: function addSync(validate) {
1446
+ syncValidations.push(validate);
1447
+ },
1448
+ addCleanup: function addCleanup(cleanup) {
1449
+ validatorsScope.addCleanup(cleanup);
1450
+ },
1451
+ formContext: controlImpl
1452
+ });
1453
+ controls.createEffect(function () {
1454
+ if (!validationEnabled.value) return undefined;
1455
+ controls.trackControlChange(dn.control, controls.ControlChange.Validate);
1456
+ var value = dn.control.value;
1457
+ var error = null;
1458
+ for (var _i = 0, _syncValidations = syncValidations; _i < _syncValidations.length; _i++) {
1459
+ var syncValidation = _syncValidations[_i];
1460
+ error = syncValidation(value);
1461
+ if (error) break;
1462
+ }
1463
+ return error;
1464
+ }, function (e) {
1465
+ dn.control.setError("default", e);
1466
+ }, validatorsScope);
1467
+ }
1468
+ }, function (c) {}, controlImpl);
1469
+ }
1470
+
1471
+ function createFormState(schemaInterface, evaluators) {
1472
+ if (evaluators === void 0) {
1473
+ evaluators = defaultEvaluators;
1474
+ }
1475
+ // console.log("createFormState");
1476
+ var controlStates = controls.newControl({});
1477
+ function evalExpression(e, context) {
1478
+ var x = evaluators[e.type];
1479
+ x == null || x(e, context);
1480
+ }
1481
+ return {
1482
+ evalExpression: evalExpression,
1483
+ cleanup: function cleanup() {
1484
+ // console.log("Cleanup form state");
1485
+ controlStates.cleanup();
1486
+ },
1487
+ getControlState: function getControlState(parent, formNode, context) {
1488
+ var _context$stateKey;
1489
+ var stateId = parent.id + "$" + formNode.id + ((_context$stateKey = context.stateKey) != null ? _context$stateKey : "");
1490
+ var controlImpl = controlStates.fields[stateId];
1491
+ controlImpl.value = context;
1492
+ function evalExpr(scope, init, nk, e, coerce) {
1493
+ nk.value = init;
1494
+ if (e != null && e.type) {
1495
+ evalExpression(e, {
1496
+ returnResult: function returnResult(r) {
1497
+ nk.value = coerce(r);
1498
+ },
1499
+ scope: scope,
1500
+ dataNode: parent,
1501
+ variables: controlImpl.fields.variables,
1502
+ schemaInterface: schemaInterface
1503
+ });
1504
+ return true;
1505
+ }
1506
+ return false;
1507
+ }
1508
+ return createScopedMetaValue(formNode, controlImpl, "impl", function (scope) {
1509
+ var _controlImpl$fields$v;
1510
+ var cf = controlImpl.fields;
1511
+ var definitionOverrides = createScoped(controlImpl, {});
1512
+ createScoped(controlImpl, undefined);
1513
+ var displayOverrides = createScoped(controlImpl, {});
1514
+ var def = formNode.definition;
1515
+ var definition = createOverrideProxy(def, definitionOverrides);
1516
+ var of = definitionOverrides.fields;
1517
+ var df = displayOverrides.fields;
1518
+ controls.createScopedEffect(function (c) {
1519
+ var textDisplay = isDisplayControl(def) && isTextDisplay(def.displayData) ? def.displayData : undefined;
1520
+ evalExpr(c, textDisplay == null ? void 0 : textDisplay.text, df.text, textDisplay && firstExpr(formNode, exports.DynamicPropertyType.Display), coerceString);
1521
+ }, displayOverrides);
1522
+ controls.createScopedEffect(function (c) {
1523
+ var htmlDisplay = isDisplayControl(def) && isHtmlDisplay(def.displayData) ? def.displayData : undefined;
1524
+ evalExpr(c, htmlDisplay == null ? void 0 : htmlDisplay.html, df.html, htmlDisplay && firstExpr(formNode, exports.DynamicPropertyType.Display), coerceString);
1525
+ }, displayOverrides);
1526
+ controls.updateComputedValue(of.displayData, function () {
1527
+ return isDisplayControl(def) ? createOverrideProxy(def.displayData, displayOverrides) : undefined;
1528
+ });
1529
+ controls.createScopedEffect(function (c) {
1530
+ evalExpr(c, def.hidden, of.hidden, firstExpr(formNode, exports.DynamicPropertyType.Visible), function (r) {
1531
+ return !r;
1532
+ });
1533
+ }, definitionOverrides);
1534
+ controls.createScopedEffect(function (c) {
1535
+ evalExpr(c, isControlReadonly(def), of.readonly, firstExpr(formNode, exports.DynamicPropertyType.Readonly), function (r) {
1536
+ return !!r;
1537
+ });
1538
+ }, definitionOverrides);
1539
+ controls.createScopedEffect(function (c) {
1540
+ evalExpr(c, isControlDisabled(def), of.disabled, firstExpr(formNode, exports.DynamicPropertyType.Disabled), function (r) {
1541
+ return !!r;
1542
+ });
1543
+ }, definitionOverrides);
1544
+ controls.createScopedEffect(function (c) {
1545
+ evalExpr(c, isDataControl(def) ? def.defaultValue : undefined, of.defaultValue, isDataControl(def) ? firstExpr(formNode, exports.DynamicPropertyType.DefaultValue) : undefined, function (r) {
1546
+ return r;
1547
+ });
1548
+ }, definitionOverrides);
1549
+ controls.createScopedEffect(function (c) {
1550
+ evalExpr(c, isActionControl(def) ? def.actionData : undefined, of.actionData, isActionControl(def) ? firstExpr(formNode, exports.DynamicPropertyType.ActionData) : undefined, function (r) {
1551
+ return r;
1552
+ });
1553
+ }, definitionOverrides);
1554
+ controls.createScopedEffect(function (c) {
1555
+ evalExpr(c, def.title, of.title, firstExpr(formNode, exports.DynamicPropertyType.Label), coerceString);
1556
+ }, definitionOverrides);
1557
+ var control = createScoped(controlImpl, {
1558
+ definition: definition,
1559
+ dataNode: undefined,
1560
+ schemaInterface: schemaInterface,
1561
+ disabled: false,
1562
+ readonly: false,
1563
+ clearHidden: false,
1564
+ hidden: false,
1565
+ variables: (_controlImpl$fields$v = controlImpl.fields.variables.current.value) != null ? _controlImpl$fields$v : {},
1566
+ stateId: stateId
1567
+ });
1568
+ var _control$fields = control.fields,
1569
+ dataNode = _control$fields.dataNode,
1570
+ hidden = _control$fields.hidden,
1571
+ readonly = _control$fields.readonly,
1572
+ style = _control$fields.style,
1573
+ layoutStyle = _control$fields.layoutStyle,
1574
+ allowedOptions = _control$fields.allowedOptions,
1575
+ disabled = _control$fields.disabled,
1576
+ variables = _control$fields.variables;
1577
+ controls.createScopedEffect(function (c) {
1578
+ return evalExpr(c, undefined, style, firstExpr(formNode, exports.DynamicPropertyType.Style), coerceStyle);
1579
+ }, scope);
1580
+ controls.createScopedEffect(function (c) {
1581
+ return evalExpr(c, undefined, layoutStyle, firstExpr(formNode, exports.DynamicPropertyType.LayoutStyle), coerceStyle);
1582
+ }, scope);
1583
+ controls.createScopedEffect(function (c) {
1584
+ return evalExpr(c, undefined, allowedOptions, firstExpr(formNode, exports.DynamicPropertyType.AllowedOptions), function (x) {
1585
+ return x;
1586
+ });
1587
+ }, scope);
1588
+ controls.updateComputedValue(dataNode, function () {
1589
+ return lookupDataNode(definition, parent);
1590
+ });
1591
+ controls.updateComputedValue(hidden, function () {
1592
+ return !!cf.hidden.value || definition.hidden || dataNode.value && (!validDataNode(dataNode.value) || hideDisplayOnly(dataNode.value, schemaInterface, definition));
1593
+ });
1594
+ controls.updateComputedValue(readonly, function () {
1595
+ return !!cf.readonly.value || isControlReadonly(definition);
1596
+ });
1597
+ controls.updateComputedValue(disabled, function () {
1598
+ return !!cf.disabled.value || isControlDisabled(definition);
1599
+ });
1600
+ controls.updateComputedValue(variables, function () {
1601
+ var _controlImpl$fields$v2;
1602
+ return (_controlImpl$fields$v2 = controlImpl.fields.variables.value) != null ? _controlImpl$fields$v2 : {};
1603
+ });
1604
+ controls.createSyncEffect(function () {
1605
+ var dn = dataNode.value;
1606
+ if (dn) {
1607
+ dn.control.disabled = disabled.value;
1608
+ }
1609
+ }, scope);
1610
+ setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode);
1611
+ controls.createSyncEffect(function () {
1612
+ var _dataNode$value;
1613
+ var dn = (_dataNode$value = dataNode.value) == null ? void 0 : _dataNode$value.control;
1614
+ if (dn && isDataControl(definition)) {
1615
+ var _definition$adornment, _definition$renderOpt;
1616
+ if (definition.hidden) {
1617
+ if (controlImpl.fields.clearHidden.value && !definition.dontClearHidden) {
1618
+ // console.log("Clearing hidden");
1619
+ dn.value = undefined;
1620
+ }
1621
+ } else if (dn.value === undefined && definition.defaultValue != null && !((_definition$adornment = definition.adornments) != null && _definition$adornment.some(function (x) {
1622
+ return x.type === exports.ControlAdornmentType.Optional;
1623
+ })) && ((_definition$renderOpt = definition.renderOptions) == null ? void 0 : _definition$renderOpt.type) != exports.DataRenderType.NullToggle) {
1624
+ // console.log(
1625
+ // "Setting to default",
1626
+ // definition.defaultValue,
1627
+ // definition.field,
1628
+ // );
1629
+ // const [required, dcv] = isDataControl(definition)
1630
+ // ? [definition.required, definition.defaultValue]
1631
+ // : [false, undefined];
1632
+ // const field = ctx.dataNode?.schema.field;
1633
+ // return (
1634
+ // dcv ??
1635
+ // (field
1636
+ // ? ctx.dataNode!.elementIndex != null
1637
+ // ? elementValueForField(field)
1638
+ // : defaultValueForField(field, required)
1639
+ // : undefined)
1640
+ // );
1641
+ dn.value = definition.defaultValue;
1642
+ }
1643
+ }
1644
+ }, scope);
1645
+ return createOverrideProxy(control.current.value, control);
1646
+ });
1647
+ }
1648
+ };
1649
+ }
1650
+ function firstExpr(formNode, property) {
1651
+ var _formNode$definition$;
1652
+ return (_formNode$definition$ = formNode.definition.dynamic) == null || (_formNode$definition$ = _formNode$definition$.find(function (x) {
1653
+ return x.type === property && x.expr.type;
1654
+ })) == null ? void 0 : _formNode$definition$.expr;
1655
+ }
1656
+ function coerceStyle(v) {
1657
+ return typeof v === "object" ? v : undefined;
1658
+ }
1659
+ function coerceString(v) {
1660
+ var _v$toString;
1661
+ return typeof v === "string" ? v : (_v$toString = v == null ? void 0 : v.toString()) != null ? _v$toString : "";
1662
+ }
1663
+ function createScopedMetaValue(formNode, c, key, init) {
1664
+ return controls.ensureMetaValue(c, key, function () {
1665
+ var holder = createScoped(c, undefined, {
1666
+ equals: function equals(a, b) {
1667
+ return a === b;
1668
+ }
1669
+ });
1670
+ var effect = controls.createScopedEffect(function (c) {
1671
+ return holder.value = init(c);
1672
+ }, holder);
1673
+ effect.run = function () {
1674
+ console.log("ControlState being recreated:", effect.subscriptions.map(function (x) {
1675
+ var _x$;
1676
+ return ((_x$ = x[1]) == null ? void 0 : _x$.mask) + " " + jsonPathString(controls.getControlPath(x[0], controls.unsafeRestoreControl(formNode.definition)));
1677
+ }));
1678
+ };
1679
+ return holder;
1680
+ }).value;
1681
+ }
1682
+ function createOverrideProxy(proxyFor, handlers) {
1683
+ var overrides = controls.getCurrentFields(handlers);
1684
+ var allOwn = Reflect.ownKeys(proxyFor);
1685
+ Reflect.ownKeys(overrides).forEach(function (k) {
1686
+ if (!allOwn.includes(k)) allOwn.push(k);
1687
+ });
1688
+ return new Proxy(proxyFor, {
1689
+ get: function get(target, p, receiver) {
1690
+ if (Object.hasOwn(overrides, p)) {
1691
+ return overrides[p].value;
1692
+ }
1693
+ return Reflect.get(target, p, receiver);
1694
+ },
1695
+ ownKeys: function ownKeys(target) {
1696
+ return allOwn;
1697
+ },
1698
+ has: function has(target, p) {
1699
+ return Reflect.has(proxyFor, p) || Reflect.has(overrides, p);
1700
+ },
1701
+ getOwnPropertyDescriptor: function getOwnPropertyDescriptor(target, k) {
1702
+ if (Object.hasOwn(overrides, k)) return {
1703
+ enumerable: true,
1704
+ configurable: true
1705
+ };
1706
+ return Reflect.getOwnPropertyDescriptor(target, k);
1707
+ }
1708
+ });
1709
+ }
1710
+
1711
+ exports.DefaultSchemaInterface = DefaultSchemaInterface;
1712
+ exports.FormNode = FormNode;
1713
+ exports.FormTree = FormTree;
1714
+ exports.SchemaDataNode = SchemaDataNode;
1715
+ exports.SchemaDataTree = SchemaDataTree;
1716
+ exports.SchemaDataTreeImpl = SchemaDataTreeImpl;
1717
+ exports.SchemaNode = SchemaNode;
1718
+ exports.SchemaTree = SchemaTree;
1719
+ exports.addFieldOption = addFieldOption;
1720
+ exports.boolField = boolField;
1721
+ exports.buildSchema = buildSchema;
1722
+ exports.compoundField = compoundField;
1723
+ exports.createControlMap = createControlMap;
1724
+ exports.createFormLookup = createFormLookup;
1725
+ exports.createFormState = createFormState;
1726
+ exports.createFormTree = createFormTree;
1727
+ exports.createOverrideProxy = createOverrideProxy;
1728
+ exports.createSchemaDataNode = createSchemaDataNode;
1729
+ exports.createSchemaLookup = createSchemaLookup;
1730
+ exports.createSchemaNode = createSchemaNode;
1731
+ exports.createSchemaTree = createSchemaTree;
1732
+ exports.createScoped = createScoped;
1733
+ exports.createScopedComputed = createScopedComputed;
1734
+ exports.dateField = dateField;
1735
+ exports.dateTimeField = dateTimeField;
1736
+ exports.defaultCompoundField = defaultCompoundField;
1737
+ exports.defaultScalarField = defaultScalarField;
1738
+ exports.defaultSchemaInterface = defaultSchemaInterface;
1739
+ exports.doubleField = doubleField;
1740
+ exports.fieldPathForDefinition = fieldPathForDefinition;
1741
+ exports.findField = findField;
1742
+ exports.fontAwesomeIcon = fontAwesomeIcon;
1743
+ exports.getDisplayOnlyOptions = getDisplayOnlyOptions;
1744
+ exports.getGroupRendererOptions = getGroupRendererOptions;
1745
+ exports.getJsonPath = getJsonPath;
1746
+ exports.getMetaFields = getMetaFields;
1747
+ exports.getRootDataNode = getRootDataNode;
1748
+ exports.getSchemaFieldList = getSchemaFieldList;
1749
+ exports.getSchemaNodePath = getSchemaNodePath;
1750
+ exports.getSchemaNodePathString = getSchemaNodePathString;
1751
+ exports.getSchemaPath = getSchemaPath;
1752
+ exports.getTagParam = getTagParam;
1753
+ exports.hideDisplayOnly = hideDisplayOnly;
1754
+ exports.intField = intField;
1755
+ exports.isActionControl = isActionControl;
1756
+ exports.isArrayRenderer = isArrayRenderer;
1757
+ exports.isAutoCompleteClasses = isAutoCompleteClasses;
1758
+ exports.isAutocompleteRenderer = isAutocompleteRenderer;
1759
+ exports.isCheckEntryClasses = isCheckEntryClasses;
1760
+ exports.isCompoundField = isCompoundField;
1761
+ exports.isCompoundNode = isCompoundNode;
1762
+ exports.isControlDisabled = isControlDisabled;
1763
+ exports.isControlDisplayOnly = isControlDisplayOnly;
1764
+ exports.isControlReadonly = isControlReadonly;
1765
+ exports.isDataControl = isDataControl;
1766
+ exports.isDataGroupRenderer = isDataGroupRenderer;
1767
+ exports.isDateTimeRenderer = isDateTimeRenderer;
1768
+ exports.isDialogRenderer = isDialogRenderer;
1769
+ exports.isDisplayControl = isDisplayControl;
1770
+ exports.isDisplayOnlyRenderer = isDisplayOnlyRenderer;
1771
+ exports.isFlexRenderer = isFlexRenderer;
1772
+ exports.isGridRenderer = isGridRenderer;
1773
+ exports.isGroupControl = isGroupControl;
1774
+ exports.isHtmlDisplay = isHtmlDisplay;
1775
+ exports.isInlineRenderer = isInlineRenderer;
1776
+ exports.isScalarField = isScalarField;
1777
+ exports.isSelectChildRenderer = isSelectChildRenderer;
1778
+ exports.isTabsRenderer = isTabsRenderer;
1779
+ exports.isTextDisplay = isTextDisplay;
1780
+ exports.isTextfieldRenderer = isTextfieldRenderer;
1781
+ exports.isWizardRenderer = isWizardRenderer;
1782
+ exports.jsonPathString = jsonPathString;
1783
+ exports.legacyFormNode = legacyFormNode;
1784
+ exports.lookupDataNode = lookupDataNode;
1785
+ exports.makeCompoundField = makeCompoundField;
1786
+ exports.makeParamTag = makeParamTag;
1787
+ exports.makeScalarField = makeScalarField;
1788
+ exports.makeSchemaDataNode = makeSchemaDataNode;
1789
+ exports.mergeField = mergeField;
1790
+ exports.mergeFields = mergeFields;
1791
+ exports.missingField = missingField;
1792
+ exports.relativePath = relativePath;
1793
+ exports.relativeSegmentPath = relativeSegmentPath;
1794
+ exports.resolveSchemaNode = resolveSchemaNode;
1795
+ exports.resolveSchemas = resolveSchemas;
1796
+ exports.schemaDataForFieldPath = schemaDataForFieldPath;
1797
+ exports.schemaDataForFieldRef = schemaDataForFieldRef;
1798
+ exports.schemaForFieldPath = schemaForFieldPath;
1799
+ exports.schemaForFieldRef = schemaForFieldRef;
1800
+ exports.stringField = stringField;
1801
+ exports.stringOptionsField = stringOptionsField;
1802
+ exports.timeField = timeField;
1803
+ exports.traverseData = traverseData;
1804
+ exports.traverseParents = traverseParents;
1805
+ exports.traverseSchemaPath = traverseSchemaPath;
1806
+ exports.validDataNode = validDataNode;
1807
+ exports.visitControlData = visitControlData;
1808
+ exports.visitControlDataArray = visitControlDataArray;
1809
+ exports.visitControlDefinition = visitControlDefinition;
1810
+ exports.visitFormData = visitFormData;
1811
+ exports.visitFormDataInContext = visitFormDataInContext;
1812
+ exports.withScalarOptions = withScalarOptions;
1813
+ //# sourceMappingURL=index.cjs.map