@react-typed-forms/schemas 15.0.0 → 15.1.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/controlRender.d.ts +16 -6
- package/lib/index.cjs +61 -52
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +44 -37
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +3 -2
- package/package.json +3 -3
- package/src/controlRender.tsx +27 -10
- package/src/createFormRenderer.tsx +14 -13
- package/src/renderers.tsx +3 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, Key, ReactElement, ReactNode } from "react";
|
|
1
|
+
import React, { ButtonHTMLAttributes, ElementType, FC, HTMLAttributes, InputHTMLAttributes, Key, LabelHTMLAttributes, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { Control } from "@react-typed-forms/core";
|
|
3
3
|
import { AdornmentPlacement, ArrayActionOptions, ControlActionHandler, ControlAdornment, ControlDataContext, ControlDefinition, DataControlDefinition, DisplayData, FormContextData, FormNode, GroupRenderOptions, RenderOptions } from "./controlDefinition";
|
|
4
4
|
import { ControlClasses, JsonPath } from "./util";
|
|
@@ -6,6 +6,16 @@ import { EvalExpressionHook, UseEvalExpressionHook } from "./hooks";
|
|
|
6
6
|
import { ValidationContext } from "./validators";
|
|
7
7
|
import { SchemaValidator } from "./schemaValidator";
|
|
8
8
|
import { FieldOption, SchemaDataNode, SchemaField, SchemaInterface } from "./schemaField";
|
|
9
|
+
export interface HtmlComponents {
|
|
10
|
+
Div: ElementType<HTMLAttributes<HTMLDivElement>, "div">;
|
|
11
|
+
Span: ElementType<HTMLAttributes<HTMLSpanElement>>;
|
|
12
|
+
Button: ElementType<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
13
|
+
I: ElementType<HTMLAttributes<HTMLElement>>;
|
|
14
|
+
Label: ElementType<LabelHTMLAttributes<HTMLLabelElement>>;
|
|
15
|
+
B: ElementType<HTMLAttributes<HTMLElement>>;
|
|
16
|
+
H1: ElementType<HTMLAttributes<HTMLElement>>;
|
|
17
|
+
Input: ElementType<InputHTMLAttributes<HTMLInputElement>, "input">;
|
|
18
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* Interface for rendering different types of form controls.
|
|
11
21
|
*/
|
|
@@ -72,8 +82,8 @@ export interface FormRenderer {
|
|
|
72
82
|
* @returns A React node.
|
|
73
83
|
*/
|
|
74
84
|
renderLabelText: (props: ReactNode) => ReactNode;
|
|
75
|
-
renderText: (props: ReactNode) => ReactNode;
|
|
76
|
-
|
|
85
|
+
renderText: (props: ReactNode, className?: string) => ReactNode;
|
|
86
|
+
html: HtmlComponents;
|
|
77
87
|
}
|
|
78
88
|
export interface AdornmentProps {
|
|
79
89
|
adornment: ControlAdornment;
|
|
@@ -295,13 +305,13 @@ export declare function ControlRenderer({ definition, fields, renderer, options,
|
|
|
295
305
|
options?: ControlRenderOptions;
|
|
296
306
|
control: Control<any>;
|
|
297
307
|
parentPath?: JsonPath[];
|
|
298
|
-
}):
|
|
308
|
+
}): JSX.Element;
|
|
299
309
|
export declare function NewControlRenderer({ definition, renderer, options, parentDataNode, }: {
|
|
300
310
|
definition: ControlDefinition | FormNode;
|
|
301
311
|
renderer: FormRenderer;
|
|
302
312
|
options?: ControlRenderOptions;
|
|
303
313
|
parentDataNode: SchemaDataNode;
|
|
304
|
-
}):
|
|
314
|
+
}): JSX.Element;
|
|
305
315
|
export declare function defaultDataProps({ definition, control, formOptions, style, allowedOptions, schemaInterface, styleClass, ...props }: DataControlProps): DataRendererProps;
|
|
306
316
|
export interface ChildRendererOptions {
|
|
307
317
|
elementIndex?: number;
|
|
@@ -356,5 +366,5 @@ export declare function applyArrayLengthRestrictions({ arrayControl, min, max, e
|
|
|
356
366
|
addDisabled: boolean;
|
|
357
367
|
removeDisabled: boolean;
|
|
358
368
|
};
|
|
359
|
-
export declare function fieldOptionAdornment(p: DataRendererProps): (o: FieldOption, i: number, selected: boolean) =>
|
|
369
|
+
export declare function fieldOptionAdornment(p: DataRendererProps): (o: FieldOption, i: number, selected: boolean) => JSX.Element;
|
|
360
370
|
export {};
|
package/lib/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var core = require('@react-typed-forms/core');
|
|
2
|
-
var
|
|
2
|
+
var react = require('react');
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var jsonata = require('jsonata');
|
|
5
5
|
var uuid = require('uuid');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
9
|
|
|
9
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
10
|
var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
|
|
11
11
|
var jsonata__default = /*#__PURE__*/_interopDefaultLegacy(jsonata);
|
|
12
12
|
|
|
@@ -1140,7 +1140,7 @@ function addMissingControlsToForm(schema, tree, warning) {
|
|
|
1140
1140
|
* @returns A mutable reference object.
|
|
1141
1141
|
*/
|
|
1142
1142
|
function useUpdatedRef(a) {
|
|
1143
|
-
var r =
|
|
1143
|
+
var r = react.useRef(a);
|
|
1144
1144
|
r.current = a;
|
|
1145
1145
|
return r;
|
|
1146
1146
|
}
|
|
@@ -1746,7 +1746,7 @@ function useControlDefinitionForSchema(sf, definition) {
|
|
|
1746
1746
|
if (definition === void 0) {
|
|
1747
1747
|
definition = emptyGroupDefinition;
|
|
1748
1748
|
}
|
|
1749
|
-
return
|
|
1749
|
+
return react.useMemo(function () {
|
|
1750
1750
|
var _definition$children;
|
|
1751
1751
|
return _extends({}, definition, {
|
|
1752
1752
|
children: addMissingControls(sf, (_definition$children = definition.children) != null ? _definition$children : [])
|
|
@@ -1810,12 +1810,12 @@ function useDynamicHooks(hooks) {
|
|
|
1810
1810
|
var deps = makeHookDepString(hookEntries, function (x) {
|
|
1811
1811
|
return x[1].deps;
|
|
1812
1812
|
});
|
|
1813
|
-
var ref =
|
|
1813
|
+
var ref = react.useRef({});
|
|
1814
1814
|
var s = ref.current;
|
|
1815
1815
|
hookEntries.forEach(function (x) {
|
|
1816
1816
|
return s[x[0]] = x[1].state;
|
|
1817
1817
|
});
|
|
1818
|
-
return
|
|
1818
|
+
return react.useCallback(function (p) {
|
|
1819
1819
|
return Object.fromEntries(hookEntries.map(function (_ref) {
|
|
1820
1820
|
var f = _ref[0],
|
|
1821
1821
|
hg = _ref[1];
|
|
@@ -2041,7 +2041,7 @@ function useJsonataExpression(jExpr, data, path, bindings, coerce) {
|
|
|
2041
2041
|
return "#$i[" + x + "]";
|
|
2042
2042
|
});
|
|
2043
2043
|
var fullExpr = pathString ? pathString + ".(" + jExpr + ")" : jExpr;
|
|
2044
|
-
var compiledExpr =
|
|
2044
|
+
var compiledExpr = react.useMemo(function () {
|
|
2045
2045
|
try {
|
|
2046
2046
|
return jsonata__default["default"](jExpr ? fullExpr : "null");
|
|
2047
2047
|
} catch (e) {
|
|
@@ -2050,8 +2050,8 @@ function useJsonataExpression(jExpr, data, path, bindings, coerce) {
|
|
|
2050
2050
|
}
|
|
2051
2051
|
}, [fullExpr]);
|
|
2052
2052
|
var control = core.useControl();
|
|
2053
|
-
var listenerRef =
|
|
2054
|
-
var updateRef =
|
|
2053
|
+
var listenerRef = react.useRef();
|
|
2054
|
+
var updateRef = react.useRef(0);
|
|
2055
2055
|
var _useRefState = core.useRefState(function () {
|
|
2056
2056
|
return new core.SubscriptionTracker(function () {
|
|
2057
2057
|
var l = listenerRef.current;
|
|
@@ -2065,7 +2065,7 @@ function useJsonataExpression(jExpr, data, path, bindings, coerce) {
|
|
|
2065
2065
|
});
|
|
2066
2066
|
}),
|
|
2067
2067
|
ref = _useRefState[0];
|
|
2068
|
-
|
|
2068
|
+
react.useEffect(function () {
|
|
2069
2069
|
var apply = function apply() {
|
|
2070
2070
|
try {
|
|
2071
2071
|
var tracker = ref.current;
|
|
@@ -2090,7 +2090,7 @@ function useJsonataExpression(jExpr, data, path, bindings, coerce) {
|
|
|
2090
2090
|
listenerRef.current = apply;
|
|
2091
2091
|
apply();
|
|
2092
2092
|
}, [compiledExpr]);
|
|
2093
|
-
|
|
2093
|
+
react.useEffect(function () {
|
|
2094
2094
|
return function () {
|
|
2095
2095
|
listenerRef.current = undefined;
|
|
2096
2096
|
ref.current.cleanup();
|
|
@@ -2134,7 +2134,7 @@ function useMakeValidationHook(definition, useValidatorFor) {
|
|
|
2134
2134
|
var depString = dd ? makeHookDepString((_dd$validators = dd.validators) != null ? _dd$validators : [], function (x) {
|
|
2135
2135
|
return x.type;
|
|
2136
2136
|
}) : "~";
|
|
2137
|
-
return
|
|
2137
|
+
return react.useCallback(function (ctx) {
|
|
2138
2138
|
var _ctx$dataContext$data, _ctx$dataContext$data2, _dd$validators2;
|
|
2139
2139
|
var dd = refData.current.dd;
|
|
2140
2140
|
if (!dd) return;
|
|
@@ -2408,8 +2408,9 @@ var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
|
2408
2408
|
}();
|
|
2409
2409
|
var defaultSchemaInterface = new DefaultSchemaInterface();
|
|
2410
2410
|
|
|
2411
|
-
var _excluded = ["
|
|
2412
|
-
_excluded2 = ["
|
|
2411
|
+
var _excluded = ["styleClass", "labelClass", "layoutClass"],
|
|
2412
|
+
_excluded2 = ["parentDataNode"],
|
|
2413
|
+
_excluded3 = ["definition", "control", "formOptions", "style", "allowedOptions", "schemaInterface", "styleClass"];
|
|
2413
2414
|
var AppendAdornmentPriority = 0;
|
|
2414
2415
|
var WrapAdornmentPriority = 1000;
|
|
2415
2416
|
/**
|
|
@@ -2440,10 +2441,10 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
2440
2441
|
renderer: renderer,
|
|
2441
2442
|
options: options
|
|
2442
2443
|
});
|
|
2443
|
-
return
|
|
2444
|
+
return react.useCallback(function (_ref) {
|
|
2444
2445
|
var control = _ref.control,
|
|
2445
2446
|
parentPath = _ref.parentPath;
|
|
2446
|
-
return /*#__PURE__*/
|
|
2447
|
+
return /*#__PURE__*/jsxRuntime.jsx(ControlRenderer, _extends({}, r.current, {
|
|
2447
2448
|
control: control,
|
|
2448
2449
|
parentPath: parentPath
|
|
2449
2450
|
}));
|
|
@@ -2489,7 +2490,7 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2489
2490
|
formNode: formNode
|
|
2490
2491
|
});
|
|
2491
2492
|
if (formNode == null) debugger;
|
|
2492
|
-
var Component =
|
|
2493
|
+
var Component = react.useCallback(function () {
|
|
2493
2494
|
var stopTracking = core.useComponentTracking();
|
|
2494
2495
|
try {
|
|
2495
2496
|
var _options$formData, _dataNode, _definition$adornment2, _definition$adornment3, _formNode$tree$getByR, _options$adjustLayout;
|
|
@@ -2584,14 +2585,17 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2584
2585
|
hiddenControl: myOptionsControl.fields.hidden,
|
|
2585
2586
|
dataContext: dataContext
|
|
2586
2587
|
});
|
|
2587
|
-
var
|
|
2588
|
-
|
|
2589
|
-
|
|
2588
|
+
var styleClass = _options.styleClass,
|
|
2589
|
+
labelClass = _options.labelClass,
|
|
2590
|
+
layoutClass = _options.layoutClass,
|
|
2591
|
+
inheritableOptions = _objectWithoutPropertiesLoose(_options, _excluded);
|
|
2592
|
+
var childOptions = _extends({}, inheritableOptions, myOptions, {
|
|
2593
|
+
elementIndex: undefined
|
|
2590
2594
|
});
|
|
2591
|
-
|
|
2595
|
+
react.useEffect(function () {
|
|
2592
2596
|
if (control && typeof myOptions.disabled === "boolean" && control.disabled != myOptions.disabled) control.disabled = myOptions.disabled;
|
|
2593
2597
|
}, [control, myOptions.disabled]);
|
|
2594
|
-
if (parentControl.isNull) return /*#__PURE__*/
|
|
2598
|
+
if (parentControl.isNull) return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
2595
2599
|
var adornments = (_definition$adornment2 = (_definition$adornment3 = definition.adornments) == null ? void 0 : _definition$adornment3.map(function (x) {
|
|
2596
2600
|
return renderer.renderAdornment({
|
|
2597
2601
|
adornment: x,
|
|
@@ -2610,15 +2614,16 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2610
2614
|
var overrideClasses = getGroupClassOverrides(c);
|
|
2611
2615
|
var _ref4 = options != null ? options : {},
|
|
2612
2616
|
parentDataNode = _ref4.parentDataNode,
|
|
2613
|
-
renderOptions = _objectWithoutPropertiesLoose(_ref4,
|
|
2617
|
+
renderOptions = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
2614
2618
|
var dContext = (_ref5 = parentDataNode != null ? parentDataNode : dataContext.dataNode) != null ? _ref5 : dataContext.parentNode;
|
|
2615
|
-
|
|
2616
|
-
|
|
2619
|
+
var allChildOptions = _extends({}, childOptions, overrideClasses, renderOptions);
|
|
2620
|
+
console.log(allChildOptions, overrideClasses);
|
|
2621
|
+
return /*#__PURE__*/jsxRuntime.jsx(NewControlRenderer, {
|
|
2617
2622
|
definition: child,
|
|
2618
2623
|
renderer: renderer,
|
|
2619
2624
|
parentDataNode: dContext,
|
|
2620
|
-
options:
|
|
2621
|
-
});
|
|
2625
|
+
options: allChildOptions
|
|
2626
|
+
}, k);
|
|
2622
2627
|
},
|
|
2623
2628
|
createDataProps: dataProps,
|
|
2624
2629
|
formOptions: myOptions,
|
|
@@ -2670,7 +2675,7 @@ function ControlRenderer(_ref7) {
|
|
|
2670
2675
|
"": fields
|
|
2671
2676
|
}).getSchema(""), control);
|
|
2672
2677
|
var Render = useControlRendererComponent(definition, renderer, options, schemaDataNode);
|
|
2673
|
-
return /*#__PURE__*/
|
|
2678
|
+
return /*#__PURE__*/jsxRuntime.jsx(Render, {});
|
|
2674
2679
|
} finally {
|
|
2675
2680
|
_effect();
|
|
2676
2681
|
}
|
|
@@ -2683,7 +2688,7 @@ function NewControlRenderer(_ref8) {
|
|
|
2683
2688
|
options = _ref8.options,
|
|
2684
2689
|
parentDataNode = _ref8.parentDataNode;
|
|
2685
2690
|
var Render = useControlRendererComponent(definition, renderer, options, parentDataNode);
|
|
2686
|
-
return /*#__PURE__*/
|
|
2691
|
+
return /*#__PURE__*/jsxRuntime.jsx(Render, {});
|
|
2687
2692
|
} finally {
|
|
2688
2693
|
_effect2();
|
|
2689
2694
|
}
|
|
@@ -2698,7 +2703,7 @@ function defaultDataProps(_ref9) {
|
|
|
2698
2703
|
_ref9$schemaInterface = _ref9.schemaInterface,
|
|
2699
2704
|
schemaInterface = _ref9$schemaInterface === void 0 ? defaultSchemaInterface : _ref9$schemaInterface,
|
|
2700
2705
|
styleClass = _ref9.styleClass,
|
|
2701
|
-
props = _objectWithoutPropertiesLoose(_ref9,
|
|
2706
|
+
props = _objectWithoutPropertiesLoose(_ref9, _excluded3);
|
|
2702
2707
|
var dataNode = props.dataContext.dataNode;
|
|
2703
2708
|
var field = dataNode.schema.field;
|
|
2704
2709
|
var className = rendererClass(styleClass, definition.styleClass);
|
|
@@ -2844,7 +2849,9 @@ function renderControlLayout(props) {
|
|
|
2844
2849
|
}
|
|
2845
2850
|
function appendMarkup(k, markup) {
|
|
2846
2851
|
return function (layout) {
|
|
2847
|
-
return layout[k] = /*#__PURE__*/
|
|
2852
|
+
return layout[k] = /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2853
|
+
children: [layout[k], markup]
|
|
2854
|
+
});
|
|
2848
2855
|
};
|
|
2849
2856
|
}
|
|
2850
2857
|
function wrapMarkup(k, wrap) {
|
|
@@ -3030,16 +3037,17 @@ function applyArrayLengthRestrictions(_ref13, disable) {
|
|
|
3030
3037
|
}
|
|
3031
3038
|
function fieldOptionAdornment(p) {
|
|
3032
3039
|
return function (o, i, selected) {
|
|
3033
|
-
return /*#__PURE__*/
|
|
3034
|
-
array: p.formNode.getChildNodes()
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3040
|
+
return /*#__PURE__*/jsxRuntime.jsx(core.RenderArrayElements, {
|
|
3041
|
+
array: p.formNode.getChildNodes(),
|
|
3042
|
+
children: function children(cd, i) {
|
|
3043
|
+
return p.renderChild(i, cd, {
|
|
3044
|
+
parentDataNode: p.dataContext.parentNode,
|
|
3045
|
+
formData: {
|
|
3046
|
+
option: o,
|
|
3047
|
+
optionSelected: selected
|
|
3048
|
+
}
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3043
3051
|
});
|
|
3044
3052
|
};
|
|
3045
3053
|
}
|
|
@@ -3114,19 +3122,20 @@ function createAdornmentRenderer(render, options) {
|
|
|
3114
3122
|
}
|
|
3115
3123
|
|
|
3116
3124
|
function createFormRenderer(customRenderers, defaultRenderers) {
|
|
3117
|
-
var
|
|
3125
|
+
var _defaultRenderers$ext, _allRenderers$find;
|
|
3118
3126
|
if (customRenderers === void 0) {
|
|
3119
3127
|
customRenderers = [];
|
|
3120
3128
|
}
|
|
3121
|
-
var
|
|
3122
|
-
var
|
|
3123
|
-
var
|
|
3124
|
-
var
|
|
3125
|
-
var
|
|
3126
|
-
var
|
|
3127
|
-
var
|
|
3128
|
-
var
|
|
3129
|
-
var
|
|
3129
|
+
var allRenderers = [].concat(customRenderers, (_defaultRenderers$ext = defaultRenderers.extraRenderers) != null ? _defaultRenderers$ext : []);
|
|
3130
|
+
var dataRegistrations = allRenderers.filter(isDataRegistration);
|
|
3131
|
+
var groupRegistrations = allRenderers.filter(isGroupRegistration);
|
|
3132
|
+
var adornmentRegistrations = allRenderers.filter(isAdornmentRegistration);
|
|
3133
|
+
var displayRegistrations = allRenderers.filter(isDisplayRegistration);
|
|
3134
|
+
var labelRenderers = allRenderers.filter(isLabelRegistration);
|
|
3135
|
+
var arrayRenderers = allRenderers.filter(isArrayRegistration);
|
|
3136
|
+
var actionRenderers = allRenderers.filter(isActionRegistration);
|
|
3137
|
+
var layoutRenderers = allRenderers.filter(isLayoutRegistration);
|
|
3138
|
+
var visibilityRenderer = (_allRenderers$find = allRenderers.find(isVisibilityRegistration)) != null ? _allRenderers$find : defaultRenderers.visibility;
|
|
3130
3139
|
var formRenderers = {
|
|
3131
3140
|
renderAction: renderAction,
|
|
3132
3141
|
renderData: renderData,
|
|
@@ -3139,7 +3148,7 @@ function createFormRenderer(customRenderers, defaultRenderers) {
|
|
|
3139
3148
|
renderVisibility: renderVisibility,
|
|
3140
3149
|
renderLabelText: renderLabelText,
|
|
3141
3150
|
renderText: defaultRenderers.renderText,
|
|
3142
|
-
|
|
3151
|
+
html: defaultRenderers.html
|
|
3143
3152
|
};
|
|
3144
3153
|
function renderVisibility(props) {
|
|
3145
3154
|
return visibilityRenderer.render(props, formRenderers);
|