@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/renderers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from "react";
|
|
2
|
-
import { ActionRendererProps, AdornmentProps, AdornmentRenderer, ArrayRendererProps, ControlLayoutProps, DataRendererProps, DisplayRendererProps, FormRenderer, GroupRendererProps, LabelRendererProps, LabelType, RenderedControl, VisibilityRendererProps } from "./controlRender";
|
|
2
|
+
import { ActionRendererProps, AdornmentProps, AdornmentRenderer, ArrayRendererProps, ControlLayoutProps, DataRendererProps, DisplayRendererProps, FormRenderer, GroupRendererProps, HtmlComponents, LabelRendererProps, LabelType, RenderedControl, VisibilityRendererProps } from "./controlRender";
|
|
3
3
|
import { AccordionAdornment, ControlAdornment, IconAdornment, OptionalAdornment, RenderOptions, SetFieldAdornment } from "./controlDefinition";
|
|
4
4
|
export interface DefaultRenderers {
|
|
5
5
|
data: DataRendererRegistration;
|
|
@@ -11,8 +11,9 @@ export interface DefaultRenderers {
|
|
|
11
11
|
adornment: AdornmentRendererRegistration;
|
|
12
12
|
renderLayout: LayoutRendererRegistration;
|
|
13
13
|
visibility: VisibilityRendererRegistration;
|
|
14
|
+
extraRenderers: RendererRegistration[];
|
|
14
15
|
renderText: (props: ReactNode) => ReactNode;
|
|
15
|
-
|
|
16
|
+
html: HtmlComponents;
|
|
16
17
|
}
|
|
17
18
|
export interface LayoutRendererRegistration {
|
|
18
19
|
type: "layout";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
},
|
|
61
61
|
"gitHead": "698e16cd3ab31b7dd0528fc76536f4d3205ce8c6",
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "rimraf ./lib/ node_modules/.cache && microbundle -f modern,cjs --no-compress --
|
|
64
|
-
"watch": "microbundle -w -f modern,cjs --no-compress --
|
|
63
|
+
"build": "rimraf ./lib/ node_modules/.cache && microbundle -f modern,cjs --no-compress --jsxImportSource=react",
|
|
64
|
+
"watch": "microbundle -w -f modern,cjs --no-compress --jsxImportSource=react",
|
|
65
65
|
"test": "jest --coverage",
|
|
66
66
|
"play": "tsx test/play.ts",
|
|
67
67
|
"update-readme": "md-magic --path README.md",
|
package/src/controlRender.tsx
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React, {
|
|
2
|
+
ButtonHTMLAttributes,
|
|
3
|
+
ElementType,
|
|
2
4
|
FC,
|
|
3
5
|
Fragment,
|
|
6
|
+
HTMLAttributes,
|
|
7
|
+
InputHTMLAttributes,
|
|
4
8
|
Key,
|
|
9
|
+
LabelHTMLAttributes,
|
|
5
10
|
ReactElement,
|
|
6
11
|
ReactNode,
|
|
7
12
|
useCallback,
|
|
@@ -89,6 +94,16 @@ import {
|
|
|
89
94
|
SchemaInterface,
|
|
90
95
|
} from "./schemaField";
|
|
91
96
|
|
|
97
|
+
export interface HtmlComponents {
|
|
98
|
+
Div: ElementType<HTMLAttributes<HTMLDivElement>, "div">;
|
|
99
|
+
Span: ElementType<HTMLAttributes<HTMLSpanElement>>;
|
|
100
|
+
Button: ElementType<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
101
|
+
I: ElementType<HTMLAttributes<HTMLElement>>;
|
|
102
|
+
Label: ElementType<LabelHTMLAttributes<HTMLLabelElement>>;
|
|
103
|
+
B: ElementType<HTMLAttributes<HTMLElement>>;
|
|
104
|
+
H1: ElementType<HTMLAttributes<HTMLElement>>;
|
|
105
|
+
Input: ElementType<InputHTMLAttributes<HTMLInputElement>, "input">;
|
|
106
|
+
}
|
|
92
107
|
/**
|
|
93
108
|
* Interface for rendering different types of form controls.
|
|
94
109
|
*/
|
|
@@ -172,9 +187,9 @@ export interface FormRenderer {
|
|
|
172
187
|
* @returns A React node.
|
|
173
188
|
*/
|
|
174
189
|
renderLabelText: (props: ReactNode) => ReactNode;
|
|
175
|
-
renderText: (props: ReactNode) => ReactNode;
|
|
190
|
+
renderText: (props: ReactNode, className?: string) => ReactNode;
|
|
176
191
|
|
|
177
|
-
|
|
192
|
+
html: HtmlComponents;
|
|
178
193
|
}
|
|
179
194
|
|
|
180
195
|
export interface AdornmentProps {
|
|
@@ -618,11 +633,12 @@ export function useControlRendererComponent(
|
|
|
618
633
|
hiddenControl: myOptionsControl.fields.hidden,
|
|
619
634
|
dataContext,
|
|
620
635
|
});
|
|
636
|
+
const { styleClass, labelClass, layoutClass, ...inheritableOptions } =
|
|
637
|
+
options;
|
|
621
638
|
const childOptions: ControlRenderOptions = {
|
|
622
|
-
...
|
|
639
|
+
...inheritableOptions,
|
|
623
640
|
...myOptions,
|
|
624
641
|
elementIndex: undefined,
|
|
625
|
-
formData,
|
|
626
642
|
};
|
|
627
643
|
|
|
628
644
|
useEffect(() => {
|
|
@@ -663,18 +679,19 @@ export function useControlRendererComponent(
|
|
|
663
679
|
const { parentDataNode, ...renderOptions } = options ?? {};
|
|
664
680
|
const dContext =
|
|
665
681
|
parentDataNode ?? dataContext.dataNode ?? dataContext.parentNode;
|
|
666
|
-
|
|
682
|
+
const allChildOptions = {
|
|
683
|
+
...childOptions,
|
|
684
|
+
...overrideClasses,
|
|
685
|
+
...renderOptions,
|
|
686
|
+
};
|
|
687
|
+
console.log(allChildOptions, overrideClasses);
|
|
667
688
|
return (
|
|
668
689
|
<NewControlRenderer
|
|
669
690
|
key={k}
|
|
670
691
|
definition={child}
|
|
671
692
|
renderer={renderer}
|
|
672
693
|
parentDataNode={dContext}
|
|
673
|
-
options={
|
|
674
|
-
...childOptions,
|
|
675
|
-
...overrideClasses,
|
|
676
|
-
...renderOptions,
|
|
677
|
-
}}
|
|
694
|
+
options={allChildOptions}
|
|
678
695
|
/>
|
|
679
696
|
);
|
|
680
697
|
},
|
|
@@ -33,19 +33,20 @@ export function createFormRenderer(
|
|
|
33
33
|
customRenderers: RendererRegistration[] = [],
|
|
34
34
|
defaultRenderers: DefaultRenderers,
|
|
35
35
|
): FormRenderer {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
36
|
+
const allRenderers = [
|
|
37
|
+
...customRenderers,
|
|
38
|
+
...(defaultRenderers.extraRenderers ?? []),
|
|
39
|
+
];
|
|
40
|
+
const dataRegistrations = allRenderers.filter(isDataRegistration);
|
|
41
|
+
const groupRegistrations = allRenderers.filter(isGroupRegistration);
|
|
42
|
+
const adornmentRegistrations = allRenderers.filter(isAdornmentRegistration);
|
|
43
|
+
const displayRegistrations = allRenderers.filter(isDisplayRegistration);
|
|
44
|
+
const labelRenderers = allRenderers.filter(isLabelRegistration);
|
|
45
|
+
const arrayRenderers = allRenderers.filter(isArrayRegistration);
|
|
46
|
+
const actionRenderers = allRenderers.filter(isActionRegistration);
|
|
47
|
+
const layoutRenderers = allRenderers.filter(isLayoutRegistration);
|
|
46
48
|
const visibilityRenderer =
|
|
47
|
-
|
|
48
|
-
defaultRenderers.visibility;
|
|
49
|
+
allRenderers.find(isVisibilityRegistration) ?? defaultRenderers.visibility;
|
|
49
50
|
|
|
50
51
|
const formRenderers: FormRenderer = {
|
|
51
52
|
renderAction,
|
|
@@ -59,7 +60,7 @@ export function createFormRenderer(
|
|
|
59
60
|
renderVisibility,
|
|
60
61
|
renderLabelText,
|
|
61
62
|
renderText: defaultRenderers.renderText,
|
|
62
|
-
|
|
63
|
+
html: defaultRenderers.html,
|
|
63
64
|
};
|
|
64
65
|
|
|
65
66
|
function renderVisibility(props: VisibilityRendererProps) {
|
package/src/renderers.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
DisplayRendererProps,
|
|
10
10
|
FormRenderer,
|
|
11
11
|
GroupRendererProps,
|
|
12
|
+
HtmlComponents,
|
|
12
13
|
LabelRendererProps,
|
|
13
14
|
LabelType,
|
|
14
15
|
RenderedControl,
|
|
@@ -34,8 +35,9 @@ export interface DefaultRenderers {
|
|
|
34
35
|
adornment: AdornmentRendererRegistration;
|
|
35
36
|
renderLayout: LayoutRendererRegistration;
|
|
36
37
|
visibility: VisibilityRendererRegistration;
|
|
38
|
+
extraRenderers: RendererRegistration[];
|
|
37
39
|
renderText: (props: ReactNode) => ReactNode;
|
|
38
|
-
|
|
40
|
+
html: HtmlComponents;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export interface LayoutRendererRegistration {
|