@react-typed-forms/schemas 3.0.0-dev.99 → 4.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/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;
@@ -1,95 +1,112 @@
1
- import { ActionControlDefinition, AnyControlDefinition, CompoundField, ControlDefinition, DataControlDefinition, DisplayControlDefinition, FieldOption, GroupedControlsDefinition, ScalarField, SchemaField } from "./types";
2
- import React, { Key, ReactElement } from "react";
1
+ import { FC, Key, ReactNode } from "react";
3
2
  import { Control } from "@react-typed-forms/core";
4
- export interface FormEditHooks {
5
- useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: ScalarField): DataControlProperties;
6
- useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition, currentHooks: FormEditHooks): GroupControlProperties;
7
- useDisplayProperties(formState: FormEditState, definition: DisplayControlDefinition): DisplayControlProperties;
8
- useActionProperties(formState: FormEditState, definition: ActionControlDefinition): ActionControlProperties;
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 DataControlProperties {
11
- readonly: boolean;
12
- visible: boolean;
13
- options: FieldOption[] | undefined;
14
- defaultValue: any;
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
- customRender?: (props: DataRendererProps, control: Control<any>) => ReactElement;
32
+ removeAction?: (childIndex: number) => ActionRendererProps;
33
+ childCount: number;
34
+ renderChild: (childIndex: number) => ReactNode;
35
+ childKey: (childIndex: number) => Key;
36
+ arrayControl?: Control<any[] | undefined | null>;
17
37
  }
18
- export interface GroupControlProperties {
38
+ export interface Visibility {
19
39
  visible: boolean;
20
- hooks: FormEditHooks;
40
+ showing: boolean;
21
41
  }
22
- export interface DisplayControlProperties {
23
- visible: boolean;
42
+ export interface RenderedLayout {
43
+ labelStart?: ReactNode;
44
+ labelEnd?: ReactNode;
45
+ controlStart?: ReactNode;
46
+ controlEnd?: ReactNode;
47
+ label?: ReactNode;
48
+ children?: ReactNode;
24
49
  }
25
- export interface ActionControlProperties {
26
- visible: boolean;
27
- onClick: () => void;
50
+ export interface ControlLayoutProps {
51
+ label?: LabelRendererProps;
52
+ errorControl?: Control<any>;
53
+ adornments?: AdornmentRenderer[];
54
+ children?: ReactNode;
55
+ processLayout?: (props: ControlLayoutProps) => ControlLayoutProps;
28
56
  }
29
- export interface ControlData {
30
- [field: string]: any;
57
+ export declare enum LabelType {
58
+ Control = 0,
59
+ Group = 1
31
60
  }
32
- export interface FormEditState {
33
- fields: SchemaField[];
34
- data: Control<ControlData>;
35
- readonly?: boolean;
61
+ export interface LabelRendererProps {
62
+ type: LabelType;
63
+ hide?: boolean | null;
64
+ label: ReactNode;
65
+ required?: boolean | null;
66
+ forId?: string;
36
67
  }
37
- export interface FormRendererComponents {
38
- renderData: (props: DataRendererProps, control: Control<any>, element: boolean, renderers: FormRendererComponents) => ReactElement;
39
- renderCompound: (props: CompoundGroupRendererProps, control: Control<any>, renderers: FormRendererComponents) => ReactElement;
40
- renderGroup: (props: GroupRendererProps) => ReactElement;
41
- renderDisplay: (props: DisplayRendererProps) => ReactElement;
42
- renderAction: (props: ActionRendererProps) => ReactElement;
68
+ export interface GroupRendererProps {
69
+ renderOptions: GroupRenderOptions;
70
+ childCount: number;
71
+ renderChild: (child: number) => ReactNode;
43
72
  }
44
- export declare const FormRendererComponentsContext: React.Context<FormRendererComponents | undefined>;
45
- export declare function useFormRendererComponents(): FormRendererComponents;
46
- export interface DisplayRendererProps {
47
- definition: DisplayControlDefinition;
48
- properties: DisplayControlProperties;
73
+ export interface DataRendererProps {
74
+ renderOptions: RenderOptions;
75
+ field: SchemaField;
76
+ id: string;
77
+ control: Control<any>;
78
+ readonly: boolean;
79
+ required: boolean;
80
+ options: FieldOption[] | undefined | null;
81
+ hidden: boolean;
49
82
  }
50
83
  export interface ActionRendererProps {
51
- definition: ActionControlDefinition;
52
- properties: ActionControlProperties;
84
+ actionId: string;
85
+ actionText: string;
86
+ onClick: () => void;
53
87
  }
54
- export interface DataRendererProps {
55
- definition: DataControlDefinition;
56
- properties: DataControlProperties;
57
- field: ScalarField;
58
- formEditState?: FormEditState;
88
+ export interface ControlRenderProps {
89
+ control: Control<any>;
59
90
  }
60
- export interface GroupRendererProps {
61
- definition: Omit<GroupedControlsDefinition, "children">;
62
- properties: GroupControlProperties;
63
- childCount: number;
64
- renderChild: (child: number, wrapChild: (key: Key, childElem: ReactElement) => ReactElement) => ReactElement;
65
- }
66
- export interface CompoundGroupRendererProps {
67
- definition: GroupedControlsDefinition;
68
- field: CompoundField;
69
- properties: GroupControlProperties;
70
- renderChild: (key: Key, control: ControlDefinition, data: Control<{
71
- [field: string]: any;
72
- }>, wrapChild: (key: Key, childElem: ReactElement) => ReactElement) => ReactElement;
73
- }
74
- export declare function isScalarField(sf: SchemaField): sf is ScalarField;
75
- export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
76
- export type AnySchemaFields = SchemaField | ScalarField | (Omit<CompoundField, "children"> & {
77
- children: AnySchemaFields[];
78
- });
79
- export declare function applyDefaultValues(v: {
80
- [k: string]: any;
81
- } | undefined, fields: SchemaField[]): any;
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;
91
+ export interface FormContextOptions {
92
+ readonly?: boolean | null;
93
+ hidden?: boolean;
94
+ }
95
+ export type CreateDataProps = (definition: DataControlDefinition, field: SchemaField, groupContext: ControlGroupContext, control: Control<any>, options: FormContextOptions) => DataRendererProps;
96
+ export interface ControlRenderOptions extends FormContextOptions {
97
+ useDataHook?: (c: ControlDefinition) => CreateDataProps;
98
+ clearHidden?: boolean;
99
+ }
100
+ export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
101
+ export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField | undefined;
102
+ export declare function getControlData(schemaField: SchemaField | undefined, parentContext: ControlGroupContext): [Control<any> | undefined, ControlGroupContext];
103
+ export declare const defaultDataProps: CreateDataProps;
104
+ export type ChildRenderer = (k: Key, childIndex: number, props: ControlRenderProps) => ReactNode;
105
+ export declare function renderControlLayout(c: ControlDefinition, renderer: FormRenderer, childCount: number, childRenderer: ChildRenderer, dataProps: CreateDataProps, dataOptions: FormContextOptions, groupContext: ControlGroupContext, childControl?: Control<any>, schemaField?: SchemaField): ControlLayoutProps;
106
+ export declare function appendMarkup(k: keyof RenderedLayout, markup: ReactNode): (layout: RenderedLayout) => void;
107
+ export declare function wrapMarkup(k: keyof RenderedLayout, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
108
+ export declare function layoutKeyForPlacement(pos: AdornmentPlacement): keyof RenderedLayout;
109
+ export declare function appendMarkupAt(pos: AdornmentPlacement, markup: ReactNode): (layout: RenderedLayout) => void;
110
+ export declare function wrapMarkupAt(pos: AdornmentPlacement, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
111
+ export declare function renderLayoutParts(props: ControlLayoutProps, renderer: FormRenderer): RenderedLayout;
112
+ export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
package/lib/hooks.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { DataControlDefinition, EntityExpression, FieldOption, ScalarField, ControlDefinition } from "./types";
2
- import { DataControlProperties, FormEditHooks, FormEditState } from "./controlRender";
3
- export type ExpressionHook = (expr: EntityExpression, formState: FormEditState) => any;
4
- export declare function useDefaultValue(definition: DataControlDefinition, field: ScalarField, formState: FormEditState, useExpression: ExpressionHook): any;
5
- export declare function useIsControlVisible(definition: ControlDefinition, formState: FormEditState, useExpression: ExpressionHook): boolean;
6
- export declare function getDefaultScalarControlProperties(control: DataControlDefinition, field: ScalarField, visible: boolean, defaultValue: any, readonly?: boolean): DataControlProperties;
7
- export declare function getOptionsForScalarField(field: ScalarField): FieldOption[] | undefined;
8
- export declare const defaultExpressionHook: ExpressionHook;
9
- export declare function createFormEditHooks(useExpression: ExpressionHook): FormEditHooks;
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 "./hooks";
5
+ export * from "./util";
6
+ export * from "./renderers";
7
+ export * from "./tailwind";
8
+ export * from "./validators";