@react-typed-forms/schemas 3.0.0-dev.99 → 4.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/.babelrc +4 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/operation/update-readme/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +581 -7
- package/README.md +292 -0
- package/lib/controlBuilder.d.ts +14 -0
- package/lib/controlRender.d.ts +96 -80
- package/lib/hooks.d.ts +9 -9
- package/lib/index.d.ts +5 -1
- package/lib/index.js +1835 -19
- package/lib/index.js.map +1 -0
- package/lib/renderers.d.ts +171 -0
- package/lib/schemaBuilder.d.ts +53 -70
- package/lib/tailwind.d.ts +2 -0
- package/lib/types.d.ts +108 -43
- package/lib/util.d.ts +35 -0
- package/lib/validators.d.ts +4 -0
- package/package.json +15 -8
- package/src/controlBuilder.ts +121 -0
- package/src/controlRender.tsx +533 -437
- package/src/hooks.tsx +153 -0
- package/src/index.ts +5 -1
- package/src/renderers.tsx +846 -0
- package/src/schemaBuilder.ts +45 -66
- package/src/tailwind.tsx +25 -0
- package/src/types.ts +164 -48
- package/src/util.ts +360 -0
- package/src/validators.ts +116 -0
- package/tsconfig.json +4 -3
- package/.rush/temp/package-deps_build.json +0 -13
- package/lib/controlRender.js +0 -230
- package/lib/hooks.js +0 -93
- package/lib/schemaBuilder.js +0 -82
- package/lib/types.js +0 -73
- package/schemas.build.log +0 -2
- package/src/hooks.ts +0 -167
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
|
|
2
|
+
# React typed forms schemas
|
|
3
|
+
|
|
4
|
+
A simple abstraction on top of `@react-typed-forms/core` for defining JSON compatible schemas and
|
|
5
|
+
rendering UIs for users to enter that data.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```npm
|
|
10
|
+
npm install @react-typed-forms/schemas
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=../examples/src/docs/schemas-example.tsx) -->
|
|
16
|
+
<!-- The below code snippet is automatically added from ../examples/src/docs/schemas-example.tsx -->
|
|
17
|
+
```tsx
|
|
18
|
+
import { useControl } from "@react-typed-forms/core";
|
|
19
|
+
import React from "react";
|
|
20
|
+
import {
|
|
21
|
+
buildSchema,
|
|
22
|
+
createDefaultRenderers,
|
|
23
|
+
createFormRenderer,
|
|
24
|
+
defaultFormEditHooks,
|
|
25
|
+
defaultTailwindTheme,
|
|
26
|
+
defaultValueForFields,
|
|
27
|
+
FormRenderer,
|
|
28
|
+
intField,
|
|
29
|
+
renderControl,
|
|
30
|
+
stringField,
|
|
31
|
+
useControlDefinitionForSchema,
|
|
32
|
+
} from "@react-typed-forms/schemas";
|
|
33
|
+
|
|
34
|
+
/** Define your form */
|
|
35
|
+
interface SimpleForm {
|
|
36
|
+
firstName: string;
|
|
37
|
+
lastName: string;
|
|
38
|
+
yearOfBirth: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Build your schema fields. Importantly giving them Display Names for showing in a UI */
|
|
42
|
+
const simpleSchema = buildSchema<SimpleForm>({
|
|
43
|
+
firstName: stringField("First Name"),
|
|
44
|
+
lastName: stringField("Last Name", { required: true }),
|
|
45
|
+
yearOfBirth: intField("Year of birth", { defaultValue: 1980 }),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/* Create a form renderer based on a simple tailwind css based theme */
|
|
49
|
+
const renderer: FormRenderer = createFormRenderer(
|
|
50
|
+
[],
|
|
51
|
+
createDefaultRenderers(defaultTailwindTheme),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export default function SimpleSchemasExample() {
|
|
55
|
+
/* Create a `Control` for collecting the data, the schema fields can be used to get a default value */
|
|
56
|
+
const data = useControl<SimpleForm>(() =>
|
|
57
|
+
defaultValueForFields(simpleSchema),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
/* Generate a ControlDefinition automatically from the schema */
|
|
61
|
+
const controlDefinition = useControlDefinitionForSchema(simpleSchema);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div className="container my-4 max-w-2xl">
|
|
65
|
+
{/* Render the ControlDefinition using `data` for the form state */}
|
|
66
|
+
{renderControl(controlDefinition, data, {
|
|
67
|
+
fields: simpleSchema,
|
|
68
|
+
renderer,
|
|
69
|
+
hooks: defaultFormEditHooks,
|
|
70
|
+
})}
|
|
71
|
+
<pre>{JSON.stringify(data.value, null, 2)}</pre>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
77
|
+
|
|
78
|
+
This will produce this UI:
|
|
79
|
+
|
|
80
|
+
<img src="../../images/schemas.png">
|
|
81
|
+
|
|
82
|
+
## Schema Fields and Control Definitions
|
|
83
|
+
|
|
84
|
+
### `SchemaField`
|
|
85
|
+
|
|
86
|
+
A `SchemaField` is a JSON object which describes the definition of a field inside the context of a JSON object. Each `SchemaField` must have a field name and a `FieldType` which will map to JSON. The following built in types are defined with these JSON mappings:
|
|
87
|
+
|
|
88
|
+
* `String` - A JSON string
|
|
89
|
+
* `Bool` - A JSON boolean
|
|
90
|
+
* `Int` - A JSON number
|
|
91
|
+
* `Double` - A JSON number
|
|
92
|
+
* `Date` - A date stored as 'yyyy-MM-dd' in a JSON string
|
|
93
|
+
* `DateTime` - A date and time stored in ISO8601 format in a JSON string
|
|
94
|
+
* `Compound` - A JSON object with a list of `SchemaField` children
|
|
95
|
+
|
|
96
|
+
Each `SchemaField` can also be marked as a `collection` which means that it will be mapped to a JSON array of the defined `FieldType`.
|
|
97
|
+
|
|
98
|
+
### Defining fields
|
|
99
|
+
|
|
100
|
+
While you can define a `SchemaField` as plain JSON, e.g.
|
|
101
|
+
```json
|
|
102
|
+
[
|
|
103
|
+
{
|
|
104
|
+
"type": "String",
|
|
105
|
+
"field": "firstName",
|
|
106
|
+
"displayName": "First Name"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"type": "String",
|
|
110
|
+
"field": "lastName",
|
|
111
|
+
"displayName": "Last Name",
|
|
112
|
+
"required": true
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"type": "Int",
|
|
116
|
+
"field": "yearOfBirth",
|
|
117
|
+
"displayName": "Year of birth",
|
|
118
|
+
"defaultValue": 1980
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
However if you have existing types which you would like to define `SchemaField`s for the library contains a function called `buildSchema` a type safe way of generating fields for a type:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
interface SimpleForm {
|
|
127
|
+
firstName: string;
|
|
128
|
+
lastName: string;
|
|
129
|
+
yearOfBirth: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const simpleSchema = buildSchema<SimpleForm>({
|
|
133
|
+
firstName: stringField("First Name"),
|
|
134
|
+
lastName: stringField("Last Name", { required: true }),
|
|
135
|
+
yearOfBirth: intField("Year of birth", { defaultValue: 1980 }),
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Field options
|
|
140
|
+
|
|
141
|
+
Often a field only has a set of allowed values, e.g. a enum. `SchemaField` allows this to be modeled by
|
|
142
|
+
providing an array of `FieldOption`:
|
|
143
|
+
|
|
144
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/types.ts&lines=37-41) -->
|
|
145
|
+
<!-- The below code snippet is automatically added from ./src/types.ts -->
|
|
146
|
+
```ts
|
|
147
|
+
export interface FieldOption {
|
|
148
|
+
name: string;
|
|
149
|
+
value: any;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
153
|
+
|
|
154
|
+
For example you could only allow certain last names:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
stringField('Last Name', {
|
|
158
|
+
required: true,
|
|
159
|
+
options:[
|
|
160
|
+
{ name: "Smith", value: "smith" },
|
|
161
|
+
{ name: "Jones", value: "jones" }
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
<img src="../../images/schemas-option.png">
|
|
167
|
+
|
|
168
|
+
### `ControlDefinition`
|
|
169
|
+
|
|
170
|
+
A `ControlDefinition` is a JSON object which describes what should be rendered in a UI. Each `ControlDefinition` can be one of 4 distinct types:
|
|
171
|
+
|
|
172
|
+
* `DataControlDefinition` - Points to a `SchemaField` in order to render a control for editing of data.
|
|
173
|
+
* `GroupedControlsDefinition` - Contains an optional title and a list of `ControlDefinition` children which should be rendered as a group. Optionally can refer to a `SchemaField` with type `Compound` in order to capture nested data.
|
|
174
|
+
* `DisplayControlDefinition` - Render readonly content, current text and HTML variants are defined.
|
|
175
|
+
* `ActionControlDefinition` - Renders an action button, useful for hooking forms up with outside functionality.
|
|
176
|
+
|
|
177
|
+
If you don't care about the layout of the form that much you can generate the definition automatically by using `useControlDefinitionForSchema()`.
|
|
178
|
+
|
|
179
|
+
TODO renderOptions, DataRenderType for choosing render style.
|
|
180
|
+
|
|
181
|
+
## Form Renderer
|
|
182
|
+
|
|
183
|
+
The actual rendering of the UI is abstracted into an object which contains functions for rendering the various `ControlDefinition`s and various parts of the UI:
|
|
184
|
+
|
|
185
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/controlRender.tsx&lines=128-138) -->
|
|
186
|
+
<!-- The below code snippet is automatically added from ./src/controlRender.tsx -->
|
|
187
|
+
```tsx
|
|
188
|
+
export interface FormRenderer {
|
|
189
|
+
renderData: (props: DataRendererProps) => ReactElement;
|
|
190
|
+
renderGroup: (props: GroupRendererProps) => ReactElement;
|
|
191
|
+
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
192
|
+
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
193
|
+
renderArray: (props: ArrayRendererProps) => ReactElement;
|
|
194
|
+
renderLabel: (props: LabelRendererProps, elem: ReactElement) => ReactElement;
|
|
195
|
+
renderVisibility: (visible: Visibility, elem: ReactElement) => ReactElement;
|
|
196
|
+
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
200
|
+
|
|
201
|
+
The `createFormRenderer` function takes an array of `RendererRegistration` which allows for customising the rendering.
|
|
202
|
+
|
|
203
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/renderers.tsx&lines=109-118) -->
|
|
204
|
+
<!-- The below code snippet is automatically added from ./src/renderers.tsx -->
|
|
205
|
+
```tsx
|
|
206
|
+
export type RendererRegistration =
|
|
207
|
+
| DataRendererRegistration
|
|
208
|
+
| GroupRendererRegistration
|
|
209
|
+
| DisplayRendererRegistration
|
|
210
|
+
| ActionRendererRegistration
|
|
211
|
+
| LabelRendererRegistration
|
|
212
|
+
| ArrayRendererRegistration
|
|
213
|
+
| AdornmentRendererRegistration
|
|
214
|
+
| VisibilityRendererRegistration;
|
|
215
|
+
```
|
|
216
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
217
|
+
|
|
218
|
+
Probably the most common customisation would be to add a `DataRendererRegistration` which will change the way a `DataControlDefinition` is rendered for a particular FieldType:
|
|
219
|
+
|
|
220
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/renderers.tsx&lines=48-61) -->
|
|
221
|
+
<!-- The below code snippet is automatically added from ./src/renderers.tsx -->
|
|
222
|
+
```tsx
|
|
223
|
+
export interface DataRendererRegistration {
|
|
224
|
+
type: "data";
|
|
225
|
+
schemaType?: string | string[];
|
|
226
|
+
renderType?: string | string[];
|
|
227
|
+
options?: boolean;
|
|
228
|
+
collection?: boolean;
|
|
229
|
+
match?: (props: DataRendererProps) => boolean;
|
|
230
|
+
render: (
|
|
231
|
+
props: DataRendererProps,
|
|
232
|
+
defaultLabel: (label?: Partial<LabelRendererProps>) => LabelRendererProps,
|
|
233
|
+
renderers: FormRenderer,
|
|
234
|
+
) => ReactElement;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
238
|
+
* The `schemaType` field specifies which `FieldType`(s) should use this `DataRendererRegistration`, unspecified means allow any.
|
|
239
|
+
* The `renderType` field specifies which `DataRenderType` this registration applies to.
|
|
240
|
+
* The `match` function can be used if the matching logic is more complicated than provided by the other.
|
|
241
|
+
* The `render` function does the actual rendering if the ControlDefinition/SchemaField matches the registration.
|
|
242
|
+
|
|
243
|
+
A good example of a custom DataRendererRegistration is the `muiTextField` which renders `String` fields using the `FTextField` wrapper of the `@react-typed-forms/mui` library:
|
|
244
|
+
|
|
245
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=../schemas-mui/src/index.tsx&lines=12-35) -->
|
|
246
|
+
<!-- The below code snippet is automatically added from ../schemas-mui/src/index.tsx -->
|
|
247
|
+
```tsx
|
|
248
|
+
export function muiTextfieldRenderer(
|
|
249
|
+
variant?: "standard" | "outlined" | "filled",
|
|
250
|
+
): DataRendererRegistration {
|
|
251
|
+
return {
|
|
252
|
+
type: "data",
|
|
253
|
+
schemaType: FieldType.String,
|
|
254
|
+
renderType: DataRenderType.Standard,
|
|
255
|
+
render: (r, makeLabel, { renderVisibility }) => {
|
|
256
|
+
const { title, required } = makeLabel();
|
|
257
|
+
return renderVisibility(
|
|
258
|
+
r.visible,
|
|
259
|
+
<FTextField
|
|
260
|
+
variant={variant}
|
|
261
|
+
required={required}
|
|
262
|
+
fullWidth
|
|
263
|
+
size="small"
|
|
264
|
+
state={r.control}
|
|
265
|
+
label={title}
|
|
266
|
+
/>,
|
|
267
|
+
);
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
273
|
+
|
|
274
|
+
Changing the simple example above to use the following:
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
const renderer: FormRenderer = createFormRenderer(
|
|
278
|
+
[muiTextFieldRenderer()],
|
|
279
|
+
createDefaultRenderer (defaultTailwindTheme));
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
This will produce this UI:
|
|
283
|
+
|
|
284
|
+
<img src="../../images/schemas-muifield.png">
|
|
285
|
+
|
|
286
|
+
## TODO
|
|
287
|
+
|
|
288
|
+
* Label rendering
|
|
289
|
+
* Visibility
|
|
290
|
+
* Arrays
|
|
291
|
+
* Display controls
|
|
292
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ControlDefinition, DataControlDefinition, DisplayControlDefinition, DynamicProperty, EntityExpression, FieldValueExpression, GroupedControlsDefinition, JsonataExpression, SchemaField } from "./types";
|
|
2
|
+
import { ActionRendererProps } from "./controlRender";
|
|
3
|
+
export declare function dataControl(field: string, title?: string | null, options?: Partial<DataControlDefinition>): DataControlDefinition;
|
|
4
|
+
export declare function textDisplayControl(text: string, options?: Partial<DisplayControlDefinition>): DisplayControlDefinition;
|
|
5
|
+
export declare function htmlDisplayControl(html: string, options?: Partial<DisplayControlDefinition>): DisplayControlDefinition;
|
|
6
|
+
export declare function dynamicDefaultValue(expr: EntityExpression): DynamicProperty;
|
|
7
|
+
export declare function visibility(expr: EntityExpression): DynamicProperty;
|
|
8
|
+
export declare function fieldEqExpr(field: string, value: any): FieldValueExpression;
|
|
9
|
+
export declare function jsonataExpr(expression: string): JsonataExpression;
|
|
10
|
+
export declare function groupedControl(children: ControlDefinition[], title?: string, options?: Partial<GroupedControlsDefinition>): GroupedControlsDefinition;
|
|
11
|
+
export declare function compoundControl(field: string, title: string | undefined, children: ControlDefinition[], options?: Partial<DataControlDefinition>): DataControlDefinition;
|
|
12
|
+
export declare function createAction(actionId: string, onClick: () => void, actionText?: string): ActionRendererProps;
|
|
13
|
+
export declare const emptyGroupDefinition: GroupedControlsDefinition;
|
|
14
|
+
export declare function useControlDefinitionForSchema(sf: SchemaField[], definition?: GroupedControlsDefinition): GroupedControlsDefinition;
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,95 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { Key, ReactElement } from "react";
|
|
1
|
+
import { FC, Key, ReactNode } from "react";
|
|
3
2
|
import { Control } from "@react-typed-forms/core";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { AdornmentPlacement, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayData, FieldOption, GroupRenderOptions, RenderOptions, SchemaField } from "./types";
|
|
4
|
+
import { ControlGroupContext } from "./util";
|
|
5
|
+
export interface FormRenderer {
|
|
6
|
+
renderData: (props: DataRendererProps, asArray: (() => ReactNode) | undefined) => (layout: ControlLayoutProps) => ControlLayoutProps;
|
|
7
|
+
renderGroup: (props: GroupRendererProps) => ReactNode;
|
|
8
|
+
renderDisplay: (props: DisplayRendererProps) => ReactNode;
|
|
9
|
+
renderAction: (props: ActionRendererProps) => ReactNode;
|
|
10
|
+
renderArray: (props: ArrayRendererProps) => ReactNode;
|
|
11
|
+
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
12
|
+
renderLabel: (props: LabelRendererProps, labelStart: ReactNode, labelEnd: ReactNode) => ReactNode;
|
|
13
|
+
renderLayout: (props: ControlLayoutProps) => ReactNode;
|
|
14
|
+
renderVisibility: (control: Control<Visibility | undefined>, children: () => ReactNode) => ReactNode;
|
|
9
15
|
}
|
|
10
|
-
export interface
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
export interface DisplayRendererProps {
|
|
17
|
+
data: DisplayData;
|
|
18
|
+
}
|
|
19
|
+
export interface AdornmentProps {
|
|
20
|
+
adornment: ControlAdornment;
|
|
21
|
+
}
|
|
22
|
+
export declare const AppendAdornmentPriority = 0;
|
|
23
|
+
export declare const WrapAdornmentPriority = 1000;
|
|
24
|
+
export interface AdornmentRenderer {
|
|
25
|
+
apply(children: RenderedLayout): void;
|
|
26
|
+
adornment?: ControlAdornment;
|
|
27
|
+
priority: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ArrayRendererProps {
|
|
30
|
+
addAction?: ActionRendererProps;
|
|
15
31
|
required: boolean;
|
|
16
|
-
|
|
32
|
+
removeAction?: (childIndex: number) => ActionRendererProps;
|
|
33
|
+
childCount: number;
|
|
34
|
+
renderChild: (childIndex: number) => ReactNode;
|
|
35
|
+
childKey: (childIndex: number) => Key;
|
|
17
36
|
}
|
|
18
|
-
export interface
|
|
37
|
+
export interface Visibility {
|
|
19
38
|
visible: boolean;
|
|
20
|
-
|
|
39
|
+
showing: boolean;
|
|
21
40
|
}
|
|
22
|
-
export interface
|
|
23
|
-
|
|
41
|
+
export interface RenderedLayout {
|
|
42
|
+
labelStart?: ReactNode;
|
|
43
|
+
labelEnd?: ReactNode;
|
|
44
|
+
controlStart?: ReactNode;
|
|
45
|
+
controlEnd?: ReactNode;
|
|
46
|
+
label?: ReactNode;
|
|
47
|
+
children?: ReactNode;
|
|
24
48
|
}
|
|
25
|
-
export interface
|
|
26
|
-
|
|
27
|
-
|
|
49
|
+
export interface ControlLayoutProps {
|
|
50
|
+
label?: LabelRendererProps;
|
|
51
|
+
errorControl?: Control<any>;
|
|
52
|
+
adornments?: AdornmentRenderer[];
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
processLayout?: (props: ControlLayoutProps) => ControlLayoutProps;
|
|
28
55
|
}
|
|
29
|
-
export
|
|
30
|
-
|
|
56
|
+
export declare enum LabelType {
|
|
57
|
+
Control = 0,
|
|
58
|
+
Group = 1
|
|
31
59
|
}
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
60
|
+
export interface LabelRendererProps {
|
|
61
|
+
type: LabelType;
|
|
62
|
+
hide?: boolean | null;
|
|
63
|
+
label: ReactNode;
|
|
64
|
+
required?: boolean | null;
|
|
65
|
+
forId?: string;
|
|
36
66
|
}
|
|
37
|
-
export interface
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
42
|
-
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
67
|
+
export interface GroupRendererProps {
|
|
68
|
+
renderOptions: GroupRenderOptions;
|
|
69
|
+
childCount: number;
|
|
70
|
+
renderChild: (child: number) => ReactNode;
|
|
43
71
|
}
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
export interface DataRendererProps {
|
|
73
|
+
renderOptions: RenderOptions;
|
|
74
|
+
field: SchemaField;
|
|
75
|
+
id: string;
|
|
76
|
+
control: Control<any>;
|
|
77
|
+
readonly: boolean;
|
|
78
|
+
required: boolean;
|
|
79
|
+
options: FieldOption[] | undefined | null;
|
|
80
|
+
hidden: boolean;
|
|
49
81
|
}
|
|
50
82
|
export interface ActionRendererProps {
|
|
51
|
-
|
|
52
|
-
|
|
83
|
+
actionId: string;
|
|
84
|
+
actionText: string;
|
|
85
|
+
onClick: () => void;
|
|
53
86
|
}
|
|
54
|
-
export interface
|
|
55
|
-
|
|
56
|
-
properties: DataControlProperties;
|
|
57
|
-
field: ScalarField;
|
|
58
|
-
formEditState?: FormEditState;
|
|
87
|
+
export interface ControlRenderProps {
|
|
88
|
+
control: Control<any>;
|
|
59
89
|
}
|
|
60
|
-
export interface
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export declare function
|
|
75
|
-
export declare function
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export declare function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean): any;
|
|
83
|
-
export declare function defaultValueForFields(fields: SchemaField[]): any;
|
|
84
|
-
export declare function defaultValueForField(sf: SchemaField): any;
|
|
85
|
-
export declare function elementValueForField(sf: SchemaField): any;
|
|
86
|
-
export declare function findScalarField(fields: SchemaField[], field: string): ScalarField | undefined;
|
|
87
|
-
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
88
|
-
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
89
|
-
export declare function fieldDisplayName(sf: SchemaField): string;
|
|
90
|
-
export declare function controlTitle(title: string | undefined, field: SchemaField): string;
|
|
91
|
-
export declare function renderControl(definition: AnyControlDefinition, formState: FormEditState, hooks: FormEditHooks, key: Key, wrapChild?: (key: Key, db: ReactElement) => ReactElement): ReactElement;
|
|
92
|
-
export declare function controlForField(field: string, formState: FormEditState): Control<any>;
|
|
93
|
-
export declare function fieldForControl(c: ControlDefinition): string | undefined;
|
|
94
|
-
export declare function isSchemaControl(c: ControlDefinition): c is DataControlDefinition;
|
|
95
|
-
export declare function isGroupControl(c: ControlDefinition): c is GroupedControlsDefinition;
|
|
90
|
+
export interface FormContextOptions {
|
|
91
|
+
readonly?: boolean | null;
|
|
92
|
+
hidden?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export type CreateDataProps = (definition: DataControlDefinition, field: SchemaField, groupContext: ControlGroupContext, control: Control<any>, options: FormContextOptions) => DataRendererProps;
|
|
95
|
+
export interface ControlRenderOptions extends FormContextOptions {
|
|
96
|
+
useDataHook?: (c: ControlDefinition) => CreateDataProps;
|
|
97
|
+
clearHidden?: boolean;
|
|
98
|
+
}
|
|
99
|
+
export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
|
|
100
|
+
export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField | undefined;
|
|
101
|
+
export declare function getControlData(schemaField: SchemaField | undefined, parentContext: ControlGroupContext): [Control<any> | undefined, ControlGroupContext];
|
|
102
|
+
export declare const defaultDataProps: CreateDataProps;
|
|
103
|
+
export type ChildRenderer = (k: Key, childIndex: number, props: ControlRenderProps) => ReactNode;
|
|
104
|
+
export declare function renderControlLayout(c: ControlDefinition, renderer: FormRenderer, childCount: number, childRenderer: ChildRenderer, dataProps: CreateDataProps, dataOptions: FormContextOptions, groupContext: ControlGroupContext, childControl?: Control<any>, schemaField?: SchemaField): ControlLayoutProps;
|
|
105
|
+
export declare function appendMarkup(k: keyof RenderedLayout, markup: ReactNode): (layout: RenderedLayout) => void;
|
|
106
|
+
export declare function wrapMarkup(k: keyof RenderedLayout, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
|
|
107
|
+
export declare function layoutKeyForPlacement(pos: AdornmentPlacement): keyof RenderedLayout;
|
|
108
|
+
export declare function appendMarkupAt(pos: AdornmentPlacement, markup: ReactNode): (layout: RenderedLayout) => void;
|
|
109
|
+
export declare function wrapMarkupAt(pos: AdornmentPlacement, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
|
|
110
|
+
export declare function renderLayoutParts(props: ControlLayoutProps, renderer: FormRenderer): RenderedLayout;
|
|
111
|
+
export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export
|
|
7
|
-
export declare function
|
|
8
|
-
export declare
|
|
9
|
-
export declare function
|
|
1
|
+
import { ControlDefinition, DynamicPropertyType, SchemaField } from "./types";
|
|
2
|
+
import { Control } from "@react-typed-forms/core";
|
|
3
|
+
import { ControlGroupContext } from "./util";
|
|
4
|
+
export declare function useEvalVisibilityHook(definition: ControlDefinition, schemaField?: SchemaField): EvalExpressionHook<boolean>;
|
|
5
|
+
export declare function useEvalDefaultValueHook(definition: ControlDefinition, schemaField?: SchemaField): EvalExpressionHook;
|
|
6
|
+
export type EvalExpressionHook<A = any> = (groupContext: ControlGroupContext) => Control<A | undefined>;
|
|
7
|
+
export declare function useEvalDynamicHook(definition: ControlDefinition, type: DynamicPropertyType): EvalExpressionHook | undefined;
|
|
8
|
+
export declare function matchesType(context: ControlGroupContext, types?: string[] | null): boolean | undefined;
|
|
9
|
+
export declare function useJsonataExpression(jExpr: string, data: Control<any>): Control<any>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export * from "./schemaBuilder";
|
|
3
|
+
export * from "./controlBuilder";
|
|
3
4
|
export * from "./controlRender";
|
|
4
|
-
export * from "./
|
|
5
|
+
export * from "./util";
|
|
6
|
+
export * from "./renderers";
|
|
7
|
+
export * from "./tailwind";
|
|
8
|
+
export * from "./validators";
|