@react-typed-forms/schemas 15.0.0 → 15.1.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/controlRender.d.ts +16 -6
- package/lib/index.cjs +47 -44
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +33 -29
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +3 -2
- package/package.json +3 -3
- package/src/controlRender.tsx +17 -2
- 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;
|
|
@@ -2440,10 +2440,10 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
2440
2440
|
renderer: renderer,
|
|
2441
2441
|
options: options
|
|
2442
2442
|
});
|
|
2443
|
-
return
|
|
2443
|
+
return react.useCallback(function (_ref) {
|
|
2444
2444
|
var control = _ref.control,
|
|
2445
2445
|
parentPath = _ref.parentPath;
|
|
2446
|
-
return /*#__PURE__*/
|
|
2446
|
+
return /*#__PURE__*/jsxRuntime.jsx(ControlRenderer, _extends({}, r.current, {
|
|
2447
2447
|
control: control,
|
|
2448
2448
|
parentPath: parentPath
|
|
2449
2449
|
}));
|
|
@@ -2489,7 +2489,7 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2489
2489
|
formNode: formNode
|
|
2490
2490
|
});
|
|
2491
2491
|
if (formNode == null) debugger;
|
|
2492
|
-
var Component =
|
|
2492
|
+
var Component = react.useCallback(function () {
|
|
2493
2493
|
var stopTracking = core.useComponentTracking();
|
|
2494
2494
|
try {
|
|
2495
2495
|
var _options$formData, _dataNode, _definition$adornment2, _definition$adornment3, _formNode$tree$getByR, _options$adjustLayout;
|
|
@@ -2588,10 +2588,10 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2588
2588
|
elementIndex: undefined,
|
|
2589
2589
|
formData: formData
|
|
2590
2590
|
});
|
|
2591
|
-
|
|
2591
|
+
react.useEffect(function () {
|
|
2592
2592
|
if (control && typeof myOptions.disabled === "boolean" && control.disabled != myOptions.disabled) control.disabled = myOptions.disabled;
|
|
2593
2593
|
}, [control, myOptions.disabled]);
|
|
2594
|
-
if (parentControl.isNull) return /*#__PURE__*/
|
|
2594
|
+
if (parentControl.isNull) return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
2595
2595
|
var adornments = (_definition$adornment2 = (_definition$adornment3 = definition.adornments) == null ? void 0 : _definition$adornment3.map(function (x) {
|
|
2596
2596
|
return renderer.renderAdornment({
|
|
2597
2597
|
adornment: x,
|
|
@@ -2612,13 +2612,12 @@ function useControlRendererComponent(controlOrFormNode, renderer, options, paren
|
|
|
2612
2612
|
parentDataNode = _ref4.parentDataNode,
|
|
2613
2613
|
renderOptions = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
2614
2614
|
var dContext = (_ref5 = parentDataNode != null ? parentDataNode : dataContext.dataNode) != null ? _ref5 : dataContext.parentNode;
|
|
2615
|
-
return /*#__PURE__*/
|
|
2616
|
-
key: k,
|
|
2615
|
+
return /*#__PURE__*/jsxRuntime.jsx(NewControlRenderer, {
|
|
2617
2616
|
definition: child,
|
|
2618
2617
|
renderer: renderer,
|
|
2619
2618
|
parentDataNode: dContext,
|
|
2620
2619
|
options: _extends({}, childOptions, overrideClasses, renderOptions)
|
|
2621
|
-
});
|
|
2620
|
+
}, k);
|
|
2622
2621
|
},
|
|
2623
2622
|
createDataProps: dataProps,
|
|
2624
2623
|
formOptions: myOptions,
|
|
@@ -2670,7 +2669,7 @@ function ControlRenderer(_ref7) {
|
|
|
2670
2669
|
"": fields
|
|
2671
2670
|
}).getSchema(""), control);
|
|
2672
2671
|
var Render = useControlRendererComponent(definition, renderer, options, schemaDataNode);
|
|
2673
|
-
return /*#__PURE__*/
|
|
2672
|
+
return /*#__PURE__*/jsxRuntime.jsx(Render, {});
|
|
2674
2673
|
} finally {
|
|
2675
2674
|
_effect();
|
|
2676
2675
|
}
|
|
@@ -2683,7 +2682,7 @@ function NewControlRenderer(_ref8) {
|
|
|
2683
2682
|
options = _ref8.options,
|
|
2684
2683
|
parentDataNode = _ref8.parentDataNode;
|
|
2685
2684
|
var Render = useControlRendererComponent(definition, renderer, options, parentDataNode);
|
|
2686
|
-
return /*#__PURE__*/
|
|
2685
|
+
return /*#__PURE__*/jsxRuntime.jsx(Render, {});
|
|
2687
2686
|
} finally {
|
|
2688
2687
|
_effect2();
|
|
2689
2688
|
}
|
|
@@ -2844,7 +2843,9 @@ function renderControlLayout(props) {
|
|
|
2844
2843
|
}
|
|
2845
2844
|
function appendMarkup(k, markup) {
|
|
2846
2845
|
return function (layout) {
|
|
2847
|
-
return layout[k] = /*#__PURE__*/
|
|
2846
|
+
return layout[k] = /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2847
|
+
children: [layout[k], markup]
|
|
2848
|
+
});
|
|
2848
2849
|
};
|
|
2849
2850
|
}
|
|
2850
2851
|
function wrapMarkup(k, wrap) {
|
|
@@ -3030,16 +3031,17 @@ function applyArrayLengthRestrictions(_ref13, disable) {
|
|
|
3030
3031
|
}
|
|
3031
3032
|
function fieldOptionAdornment(p) {
|
|
3032
3033
|
return function (o, i, selected) {
|
|
3033
|
-
return /*#__PURE__*/
|
|
3034
|
-
array: p.formNode.getChildNodes()
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3034
|
+
return /*#__PURE__*/jsxRuntime.jsx(core.RenderArrayElements, {
|
|
3035
|
+
array: p.formNode.getChildNodes(),
|
|
3036
|
+
children: function children(cd, i) {
|
|
3037
|
+
return p.renderChild(i, cd, {
|
|
3038
|
+
parentDataNode: p.dataContext.parentNode,
|
|
3039
|
+
formData: {
|
|
3040
|
+
option: o,
|
|
3041
|
+
optionSelected: selected
|
|
3042
|
+
}
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3043
3045
|
});
|
|
3044
3046
|
};
|
|
3045
3047
|
}
|
|
@@ -3114,19 +3116,20 @@ function createAdornmentRenderer(render, options) {
|
|
|
3114
3116
|
}
|
|
3115
3117
|
|
|
3116
3118
|
function createFormRenderer(customRenderers, defaultRenderers) {
|
|
3117
|
-
var
|
|
3119
|
+
var _defaultRenderers$ext, _allRenderers$find;
|
|
3118
3120
|
if (customRenderers === void 0) {
|
|
3119
3121
|
customRenderers = [];
|
|
3120
3122
|
}
|
|
3121
|
-
var
|
|
3122
|
-
var
|
|
3123
|
-
var
|
|
3124
|
-
var
|
|
3125
|
-
var
|
|
3126
|
-
var
|
|
3127
|
-
var
|
|
3128
|
-
var
|
|
3129
|
-
var
|
|
3123
|
+
var allRenderers = [].concat(customRenderers, (_defaultRenderers$ext = defaultRenderers.extraRenderers) != null ? _defaultRenderers$ext : []);
|
|
3124
|
+
var dataRegistrations = allRenderers.filter(isDataRegistration);
|
|
3125
|
+
var groupRegistrations = allRenderers.filter(isGroupRegistration);
|
|
3126
|
+
var adornmentRegistrations = allRenderers.filter(isAdornmentRegistration);
|
|
3127
|
+
var displayRegistrations = allRenderers.filter(isDisplayRegistration);
|
|
3128
|
+
var labelRenderers = allRenderers.filter(isLabelRegistration);
|
|
3129
|
+
var arrayRenderers = allRenderers.filter(isArrayRegistration);
|
|
3130
|
+
var actionRenderers = allRenderers.filter(isActionRegistration);
|
|
3131
|
+
var layoutRenderers = allRenderers.filter(isLayoutRegistration);
|
|
3132
|
+
var visibilityRenderer = (_allRenderers$find = allRenderers.find(isVisibilityRegistration)) != null ? _allRenderers$find : defaultRenderers.visibility;
|
|
3130
3133
|
var formRenderers = {
|
|
3131
3134
|
renderAction: renderAction,
|
|
3132
3135
|
renderData: renderData,
|
|
@@ -3139,7 +3142,7 @@ function createFormRenderer(customRenderers, defaultRenderers) {
|
|
|
3139
3142
|
renderVisibility: renderVisibility,
|
|
3140
3143
|
renderLabelText: renderLabelText,
|
|
3141
3144
|
renderText: defaultRenderers.renderText,
|
|
3142
|
-
|
|
3145
|
+
html: defaultRenderers.html
|
|
3143
3146
|
};
|
|
3144
3147
|
function renderVisibility(props) {
|
|
3145
3148
|
return visibilityRenderer.render(props, formRenderers);
|