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