@react-typed-forms/schemas 14.3.0 → 14.4.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/lib/controlDefinition.d.ts +16 -12
- package/lib/controlRender.d.ts +3 -1
- package/lib/index.cjs +111 -79
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +98 -79
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +3 -1
- package/package.json +1 -1
- package/src/controlDefinition.ts +74 -57
- package/src/controlRender.tsx +6 -3
- package/src/createFormRenderer.tsx +25 -13
- package/src/renderers.tsx +5 -2
- package/tsconfig.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4,6 +4,25 @@ import clsx from 'clsx';
|
|
|
4
4
|
import jsonata from 'jsonata';
|
|
5
5
|
import { v4 } from 'uuid';
|
|
6
6
|
|
|
7
|
+
function _extends() {
|
|
8
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
9
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
10
|
+
var t = arguments[e];
|
|
11
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}, _extends.apply(null, arguments);
|
|
15
|
+
}
|
|
16
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
17
|
+
if (null == r) return {};
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
20
|
+
if (e.includes(n)) continue;
|
|
21
|
+
t[n] = r[n];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
|
|
7
26
|
/**
|
|
8
27
|
* Enum representing the various field types.
|
|
9
28
|
*/
|
|
@@ -382,37 +401,29 @@ function isCheckEntryClasses(options) {
|
|
|
382
401
|
return false;
|
|
383
402
|
}
|
|
384
403
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
this.definition = definition;
|
|
394
|
-
this.tree = tree;
|
|
395
|
-
this.parent = parent;
|
|
396
|
-
this.overrideChildren = overrideChildren;
|
|
397
|
-
this.id = id;
|
|
398
|
-
this.definition = definition;
|
|
399
|
-
}
|
|
400
|
-
getChildNodes() {
|
|
401
|
-
var _children$map, _children;
|
|
402
|
-
if (this.overrideChildren) return this.overrideChildren;
|
|
403
|
-
let children = this.definition.children;
|
|
404
|
-
if (this.definition.childRefId) {
|
|
405
|
-
const ref = this.tree.controlMap[this.definition.childRefId];
|
|
406
|
-
children = ref == null ? void 0 : ref.children;
|
|
407
|
-
}
|
|
408
|
-
return (_children$map = (_children = children) == null ? void 0 : _children.map((x, i) => new FormNode(this.id + "/" + i, x, this.tree, this))) != null ? _children$map : [];
|
|
409
|
-
}
|
|
410
|
-
withOverrideChildren(children) {
|
|
411
|
-
return new FormNode(this.id, this.definition, this.tree, this.parent, children.map(x => nodeForControl(x, this.tree)));
|
|
412
|
-
}
|
|
404
|
+
function defaultGetChildNodes(parent, children) {
|
|
405
|
+
var _children$map;
|
|
406
|
+
return (_children$map = children == null ? void 0 : children.map((x, i) => nodeForControl(x, parent.tree, i, parent))) != null ? _children$map : [];
|
|
407
|
+
}
|
|
408
|
+
function wrapFormNode(node, getChildren) {
|
|
409
|
+
return _extends({}, node, {
|
|
410
|
+
getChildNodes: getChildren != null ? getChildren : dfr => node.getChildNodes(dfr)
|
|
411
|
+
});
|
|
413
412
|
}
|
|
414
413
|
function nodeForControl(definition, tree, indexOrId, parent) {
|
|
415
|
-
return
|
|
414
|
+
return {
|
|
415
|
+
id: parent ? parent.id + "/" + indexOrId : "",
|
|
416
|
+
definition,
|
|
417
|
+
tree,
|
|
418
|
+
parent,
|
|
419
|
+
getChildNodes(dontFollowRef) {
|
|
420
|
+
let children = this.definition.children;
|
|
421
|
+
if (!dontFollowRef && this.definition.childRefId) {
|
|
422
|
+
return this.tree.getChildrenForId(this.definition.childRefId, this);
|
|
423
|
+
}
|
|
424
|
+
return defaultGetChildNodes(this, children);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
416
427
|
}
|
|
417
428
|
function legacyFormNode(definition) {
|
|
418
429
|
return createFormLookup({
|
|
@@ -424,22 +435,33 @@ function getControlIds(definition) {
|
|
|
424
435
|
const childEntries = (_definition$children$ = (_definition$children = definition.children) == null ? void 0 : _definition$children.flatMap(getControlIds)) != null ? _definition$children$ : [];
|
|
425
436
|
return !definition.id ? childEntries : [[definition.id, definition], ...childEntries];
|
|
426
437
|
}
|
|
427
|
-
function
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
438
|
+
function createFormTreeWithRoot(createRootNode, getChildrenForId, getForm = {
|
|
439
|
+
getForm: () => undefined
|
|
440
|
+
}) {
|
|
441
|
+
const tree = _extends({}, getForm, {
|
|
442
|
+
getChildrenForId,
|
|
443
|
+
rootNode: undefined
|
|
444
|
+
});
|
|
445
|
+
tree.rootNode = createRootNode(tree);
|
|
446
|
+
return tree;
|
|
447
|
+
}
|
|
448
|
+
function createFormTree(controls, getForm = {
|
|
449
|
+
getForm: () => undefined
|
|
450
|
+
}) {
|
|
451
|
+
const controlMap = Object.fromEntries(controls.flatMap(getControlIds));
|
|
452
|
+
return createFormTreeWithRoot(tree => nodeForControl({
|
|
433
453
|
children: controls,
|
|
434
454
|
type: ControlDefinitionType.Group
|
|
435
|
-
}, tree)
|
|
436
|
-
|
|
455
|
+
}, tree), (id, parent) => {
|
|
456
|
+
var _controlMap$id$childr, _controlMap$id;
|
|
457
|
+
return (_controlMap$id$childr = (_controlMap$id = controlMap[id]) == null || (_controlMap$id = _controlMap$id.children) == null ? void 0 : _controlMap$id.map((x, i) => nodeForControl(x, parent.tree, i, parent))) != null ? _controlMap$id$childr : [];
|
|
458
|
+
}, getForm);
|
|
437
459
|
}
|
|
438
460
|
function createFormLookup(formMap) {
|
|
439
461
|
const lookup = {
|
|
440
462
|
getForm
|
|
441
463
|
};
|
|
442
|
-
const forms = Object.fromEntries(Object.entries(formMap).map(([k, v]) => [k,
|
|
464
|
+
const forms = Object.fromEntries(Object.entries(formMap).map(([k, v]) => [k, createFormTree(v, lookup)]));
|
|
443
465
|
return lookup;
|
|
444
466
|
function getForm(formId) {
|
|
445
467
|
return forms[formId];
|
|
@@ -520,25 +542,6 @@ function visitFormDataInContext(parentContext, node, cb) {
|
|
|
520
542
|
return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
|
|
521
543
|
}
|
|
522
544
|
|
|
523
|
-
function _extends() {
|
|
524
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
525
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
526
|
-
var t = arguments[e];
|
|
527
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
528
|
-
}
|
|
529
|
-
return n;
|
|
530
|
-
}, _extends.apply(null, arguments);
|
|
531
|
-
}
|
|
532
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
533
|
-
if (null == r) return {};
|
|
534
|
-
var t = {};
|
|
535
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
536
|
-
if (e.includes(n)) continue;
|
|
537
|
-
t[n] = r[n];
|
|
538
|
-
}
|
|
539
|
-
return t;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
545
|
function buildSchema(def) {
|
|
543
546
|
return Object.entries(def).map(x => x[1](x[0]));
|
|
544
547
|
}
|
|
@@ -2129,7 +2132,7 @@ function useControlRenderer(definition, fields, renderer, options = {}) {
|
|
|
2129
2132
|
control,
|
|
2130
2133
|
parentPath
|
|
2131
2134
|
}) => {
|
|
2132
|
-
return React.createElement(ControlRenderer, _extends({}, r.current, {
|
|
2135
|
+
return /*#__PURE__*/React.createElement(ControlRenderer, _extends({}, r.current, {
|
|
2133
2136
|
control: control,
|
|
2134
2137
|
parentPath: parentPath
|
|
2135
2138
|
}));
|
|
@@ -2137,7 +2140,7 @@ function useControlRenderer(definition, fields, renderer, options = {}) {
|
|
|
2137
2140
|
}
|
|
2138
2141
|
function useControlRendererComponent(controlOrFormNode, renderer, options = {}, parentDataNode) {
|
|
2139
2142
|
var _options$useDataHook, _options$schemaInterf, _options$useEvalExpre;
|
|
2140
|
-
const [definition, formNode] =
|
|
2143
|
+
const [definition, formNode] = "definition" in controlOrFormNode ? [controlOrFormNode.definition, controlOrFormNode] : [controlOrFormNode, legacyFormNode(controlOrFormNode)];
|
|
2141
2144
|
const dataProps = (_options$useDataHook = options.useDataHook == null ? void 0 : options.useDataHook(definition)) != null ? _options$useDataHook : defaultDataProps;
|
|
2142
2145
|
const elementIndex = options.elementIndex;
|
|
2143
2146
|
const schemaInterface = (_options$schemaInterf = options.schemaInterface) != null ? _options$schemaInterf : defaultSchemaInterface;
|
|
@@ -2251,7 +2254,7 @@ function useControlRendererComponent(controlOrFormNode, renderer, options = {},
|
|
|
2251
2254
|
useEffect(() => {
|
|
2252
2255
|
if (control && typeof myOptions.disabled === "boolean" && control.disabled != myOptions.disabled) control.disabled = myOptions.disabled;
|
|
2253
2256
|
}, [control, myOptions.disabled]);
|
|
2254
|
-
if (parentControl.isNull) return React.createElement(React.Fragment, null);
|
|
2257
|
+
if (parentControl.isNull) return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
2255
2258
|
const adornments = (_definition$adornment2 = (_definition$adornment3 = definition.adornments) == null ? void 0 : _definition$adornment3.map(x => renderer.renderAdornment({
|
|
2256
2259
|
adornment: x,
|
|
2257
2260
|
dataContext,
|
|
@@ -2271,7 +2274,7 @@ function useControlRendererComponent(controlOrFormNode, renderer, options = {},
|
|
|
2271
2274
|
} = _ref,
|
|
2272
2275
|
renderOptions = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
2273
2276
|
const dContext = (_ref2 = parentDataNode != null ? parentDataNode : dataContext.dataNode) != null ? _ref2 : dataContext.parentNode;
|
|
2274
|
-
return React.createElement(NewControlRenderer, {
|
|
2277
|
+
return /*#__PURE__*/React.createElement(NewControlRenderer, {
|
|
2275
2278
|
key: k,
|
|
2276
2279
|
definition: child,
|
|
2277
2280
|
renderer: renderer,
|
|
@@ -2324,11 +2327,16 @@ function ControlRenderer({
|
|
|
2324
2327
|
control,
|
|
2325
2328
|
parentPath
|
|
2326
2329
|
}) {
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2330
|
+
var _effect = useComponentTracking();
|
|
2331
|
+
try {
|
|
2332
|
+
const schemaDataNode = makeSchemaDataNode(createSchemaLookup({
|
|
2333
|
+
"": fields
|
|
2334
|
+
}).getSchema(""), control);
|
|
2335
|
+
const Render = useControlRendererComponent(definition, renderer, options, schemaDataNode);
|
|
2336
|
+
return /*#__PURE__*/React.createElement(Render, null);
|
|
2337
|
+
} finally {
|
|
2338
|
+
_effect();
|
|
2339
|
+
}
|
|
2332
2340
|
}
|
|
2333
2341
|
function NewControlRenderer({
|
|
2334
2342
|
definition,
|
|
@@ -2336,8 +2344,13 @@ function NewControlRenderer({
|
|
|
2336
2344
|
options,
|
|
2337
2345
|
parentDataNode
|
|
2338
2346
|
}) {
|
|
2339
|
-
|
|
2340
|
-
|
|
2347
|
+
var _effect2 = useComponentTracking();
|
|
2348
|
+
try {
|
|
2349
|
+
const Render = useControlRendererComponent(definition, renderer, options, parentDataNode);
|
|
2350
|
+
return /*#__PURE__*/React.createElement(Render, null);
|
|
2351
|
+
} finally {
|
|
2352
|
+
_effect2();
|
|
2353
|
+
}
|
|
2341
2354
|
}
|
|
2342
2355
|
function defaultDataProps(_ref4) {
|
|
2343
2356
|
var _allowedOptions$value, _definition$renderOpt2;
|
|
@@ -2493,7 +2506,7 @@ function renderControlLayout(props) {
|
|
|
2493
2506
|
}
|
|
2494
2507
|
}
|
|
2495
2508
|
function appendMarkup(k, markup) {
|
|
2496
|
-
return layout => layout[k] = React.createElement(React.Fragment, null, layout[k], markup);
|
|
2509
|
+
return layout => layout[k] = /*#__PURE__*/React.createElement(React.Fragment, null, layout[k], markup);
|
|
2497
2510
|
}
|
|
2498
2511
|
function wrapMarkup(k, wrap) {
|
|
2499
2512
|
return layout => layout[k] = wrap(layout[k]);
|
|
@@ -2662,7 +2675,7 @@ function applyArrayLengthRestrictions({
|
|
|
2662
2675
|
};
|
|
2663
2676
|
}
|
|
2664
2677
|
function fieldOptionAdornment(p) {
|
|
2665
|
-
return (o, i, selected) => React.createElement(RenderArrayElements, {
|
|
2678
|
+
return (o, i, selected) => /*#__PURE__*/React.createElement(RenderArrayElements, {
|
|
2666
2679
|
array: p.formNode.getChildNodes()
|
|
2667
2680
|
}, (cd, i) => p.renderChild(i, cd, {
|
|
2668
2681
|
parentDataNode: p.dataContext.parentNode,
|
|
@@ -2762,9 +2775,14 @@ function createFormRenderer(customRenderers = [], defaultRenderers) {
|
|
|
2762
2775
|
renderArray,
|
|
2763
2776
|
renderAdornment,
|
|
2764
2777
|
renderLayout,
|
|
2765
|
-
renderVisibility
|
|
2766
|
-
renderLabelText
|
|
2778
|
+
renderVisibility,
|
|
2779
|
+
renderLabelText,
|
|
2780
|
+
renderText: defaultRenderers.renderText,
|
|
2781
|
+
h: defaultRenderers.h
|
|
2767
2782
|
};
|
|
2783
|
+
function renderVisibility(props) {
|
|
2784
|
+
return visibilityRenderer.render(props, formRenderers);
|
|
2785
|
+
}
|
|
2768
2786
|
function renderLabelText(label) {
|
|
2769
2787
|
return renderLabel({
|
|
2770
2788
|
label,
|
|
@@ -2791,25 +2809,26 @@ function createFormRenderer(customRenderers = [], defaultRenderers) {
|
|
|
2791
2809
|
return renderer.render(props, labelStart, labelEnd, formRenderers);
|
|
2792
2810
|
}
|
|
2793
2811
|
function renderData(props) {
|
|
2794
|
-
var _dataRegistrations$fi;
|
|
2795
2812
|
const {
|
|
2796
2813
|
renderOptions,
|
|
2797
2814
|
field
|
|
2798
2815
|
} = props;
|
|
2799
2816
|
const options = hasOptions(props);
|
|
2800
2817
|
const renderType = renderOptions.type;
|
|
2801
|
-
const renderer =
|
|
2802
|
-
const result = renderer.render(props, formRenderers);
|
|
2818
|
+
const renderer = dataRegistrations.find(matchesRenderer);
|
|
2819
|
+
const result = (renderer != null ? renderer : defaultRenderers.data).render(props, formRenderers);
|
|
2803
2820
|
if (typeof result === "function") return result;
|
|
2804
2821
|
return l => _extends({}, l, {
|
|
2805
2822
|
children: result
|
|
2806
2823
|
});
|
|
2807
2824
|
function matchesRenderer(x) {
|
|
2808
2825
|
var _x$collection, _field$collection, _x$options;
|
|
2826
|
+
const noMatch = x.match ? !x.match(props, renderOptions) : undefined;
|
|
2827
|
+
if (noMatch === true) return false;
|
|
2809
2828
|
const matchCollection = ((_x$collection = x.collection) != null ? _x$collection : false) === (props.elementIndex == null && ((_field$collection = field.collection) != null ? _field$collection : false));
|
|
2810
|
-
const
|
|
2811
|
-
const
|
|
2812
|
-
return matchCollection && ((_x$options = x.options) != null ? _x$options : false) === options && (
|
|
2829
|
+
const isSchemaAllowed = !!x.schemaType && renderType == DataRenderType.Standard ? isOneOf(x.schemaType, field.type) : undefined;
|
|
2830
|
+
const isRendererAllowed = !!x.renderType && isOneOf(x.renderType, renderType);
|
|
2831
|
+
return matchCollection && ((_x$options = x.options) != null ? _x$options : false) === options && (isSchemaAllowed || isRendererAllowed || !x.renderType && !x.schemaType && noMatch === false);
|
|
2813
2832
|
}
|
|
2814
2833
|
}
|
|
2815
2834
|
function renderGroup(props) {
|
|
@@ -2866,5 +2885,5 @@ function isArrayRegistration(x) {
|
|
|
2866
2885
|
return x.type === "array";
|
|
2867
2886
|
}
|
|
2868
2887
|
|
|
2869
|
-
export { AdornmentPlacement, AppendAdornmentPriority, ControlAdornmentType, ControlDefinitionType, ControlRenderer, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType,
|
|
2888
|
+
export { AdornmentPlacement, AppendAdornmentPriority, ControlAdornmentType, ControlDefinitionType, ControlRenderer, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, GroupRenderType, LabelType, NewControlRenderer, SchemaTags, SyncTextType, ValidationMessageType, ValidatorType, WrapAdornmentPriority, accordionOptions, actionControl, actionHandlers, addFieldOption, addMissingControls, addMissingControlsForSchema, adornmentOptions, appendMarkup, appendMarkupAt, applyArrayLengthRestrictions, applyDefaultForField, applyDefaultValues, applyExtensionToSchema, applyExtensionsToSchema, applyLengthRestrictions, applyValues, autocompleteOptions, boolField, buildSchema, checkListOptions, cleanDataForSchema, coerceToString, collectDifferences, compoundControl, compoundField, controlTitle, createAction, createActionRenderer, createAdornmentRenderer, createArrayActions, createArrayRenderer, createDataRenderer, createDisplayRenderer, createFormLookup, createFormRenderer, createFormTree, createFormTreeWithRoot, createGroupRenderer, createLabelRenderer, createLayoutRenderer, createSchemaLookup, createVisibilityRenderer, dataControl, dateField, dateTimeField, dateValidatorOptions, defaultCompoundField, defaultControlForField, defaultDataProps, defaultEvalHooks, defaultGetChildNodes, defaultScalarField, defaultSchemaInterface, defaultUseEvalExpressionHook, defaultValueForField, defaultValueForFields, displayOnlyOptions, doubleField, dynamicDefaultValue, dynamicDisabled, dynamicReadonly, dynamicVisibility, elementValueForField, emptyGroupDefinition, fieldDisplayName, fieldEqExpr, fieldExpr, fieldHasTag, fieldOptionAdornment, fieldPathForDefinition, findChildDefinition, findCompoundField, findControlsForCompound, findField, findFieldPath, findNonDataGroups, findScalarField, getAllReferencedClasses, getAllValues, getDiffObject, getDisplayOnlyOptions, getExternalEditData, getGroupClassOverrides, getGroupRendererOptions, getIsEditing, getJsonPath, getLastDefinedValue, getLengthRestrictions, getNullToggler, getOverrideClass, getRootDataNode, getSchemaFieldList, getSchemaNodePath, getSchemaPath, getTagParam, groupedControl, hasOptions, hideDisplayOnly, htmlDisplayControl, intField, isAccordionAdornment, isActionControl, isArrayRenderer, isAutoCompleteClasses, isAutocompleteRenderer, isCheckEntryClasses, isCompoundField, isCompoundNode, isControlDisabled, isControlDisplayOnly, isControlReadonly, isDataControl, isDataGroupRenderer, isDateTimeRenderer, isDisplayControl, isDisplayOnlyRenderer, isFlexRenderer, isGridRenderer, isGroupControl, isIconAdornment, isOptionalAdornment, isScalarField, isSelectChildRenderer, isSetFieldAdornment, isTabsRenderer, isTextfieldRenderer, jsonPathString, jsonataExpr, jsonataOptions, jsonataValidatorOptions, layoutKeyForPlacement, legacyFormNode, lengthValidatorOptions, lookupDataNode, makeCompoundField, makeEvalExpressionHook, makeHook, makeHookDepString, makeParamTag, makeScalarField, makeSchemaDataNode, matchesType, mergeField, mergeFields, mergeObjects, nodeForControl, radioButtonOptions, relativePath, renderControlLayout, renderLayoutParts, renderOptionsFor, rendererClass, resolveSchemas, rootSchemaNode, schemaDataForFieldPath, schemaDataForFieldRef, schemaForFieldPath, schemaForFieldRef, stringField, stringOptionsField, textDisplayControl, textfieldOptions, timeField, toDepString, traverseData, traverseParents, traverseSchemaPath, useControlDefinitionForSchema, useControlRenderer, useControlRendererComponent, useDateValidator, useDynamicHooks, useEvalActionHook, useEvalAllowedOptionsHook, useEvalDefaultValueHook, useEvalDisabledHook, useEvalDisplayHook, useEvalDynamicBoolHook, useEvalDynamicHook, useEvalLabelText, useEvalReadonlyHook, useEvalStyleHook, useEvalVisibilityHook, useJsonataExpression, useJsonataValidator, useLengthValidator, useMakeValidationHook, useUpdatedRef, useUuidExpression, validationVisitor, validatorOptions, visitControlData, visitControlDataArray, visitControlDefinition, visitFormData, visitFormDataInContext, withScalarOptions, wrapFormNode, wrapLayout, wrapMarkup, wrapMarkupAt };
|
|
2870
2889
|
//# sourceMappingURL=index.js.map
|