@react-typed-forms/schemas 1.0.0-dev.20 → 1.0.0-dev.21
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/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/operation/update-readme/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +124 -2
- package/README.md +223 -0
- package/lib/controlRender.d.ts +11 -11
- package/lib/hooks.d.ts +1 -1
- package/lib/index.js +61 -94
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +2 -2
- package/package.json +4 -2
- package/src/controlRender.tsx +37 -88
- package/src/hooks.tsx +20 -22
- package/src/renderers.tsx +8 -8
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
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
|
+
TODO - buildSchema, FieldOptions, extending FieldType
|
|
99
|
+
|
|
100
|
+
### `ControlDefinition`
|
|
101
|
+
A `ControlDefinition` is a JSON object which describes what should be rendered in a UI. Each `ControlDefinition` can be one of 4 distinct types:
|
|
102
|
+
|
|
103
|
+
* `DataControlDefinition` - Points to a `SchemaField` in order to render a control for editing of data.
|
|
104
|
+
* `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.
|
|
105
|
+
* `DisplayControlDefinition` - Render readonly content, current text and HTML variants are defined.
|
|
106
|
+
* `ActionControlDefinition` - Renders an action button, useful for hooking forms up with outside functionality.
|
|
107
|
+
|
|
108
|
+
If you don't care about the layout of the form that much you can generate the definition automatically by using `useControlDefinitionForSchema()`.
|
|
109
|
+
|
|
110
|
+
TODO renderOptions, DataRenderType for choosing render style.
|
|
111
|
+
|
|
112
|
+
## Form Renderer
|
|
113
|
+
|
|
114
|
+
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:
|
|
115
|
+
|
|
116
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/controlRender.tsx&lines=128-138) -->
|
|
117
|
+
<!-- The below code snippet is automatically added from ./src/controlRender.tsx -->
|
|
118
|
+
```tsx
|
|
119
|
+
export interface FormRenderer {
|
|
120
|
+
renderData: (props: DataRendererProps) => ReactElement;
|
|
121
|
+
renderGroup: (props: GroupRendererProps) => ReactElement;
|
|
122
|
+
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
123
|
+
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
124
|
+
renderArray: (props: ArrayRendererProps) => ReactElement;
|
|
125
|
+
renderLabel: (props: LabelRendererProps, elem: ReactElement) => ReactElement;
|
|
126
|
+
renderVisibility: (visible: Visibility, elem: ReactElement) => ReactElement;
|
|
127
|
+
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
131
|
+
|
|
132
|
+
The `createFormRenderer` function takes an array of `RendererRegistration` which allows for customising the rendering.
|
|
133
|
+
|
|
134
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/renderers.tsx&lines=109-118) -->
|
|
135
|
+
<!-- The below code snippet is automatically added from ./src/renderers.tsx -->
|
|
136
|
+
```tsx
|
|
137
|
+
export type RendererRegistration =
|
|
138
|
+
| DataRendererRegistration
|
|
139
|
+
| GroupRendererRegistration
|
|
140
|
+
| DisplayRendererRegistration
|
|
141
|
+
| ActionRendererRegistration
|
|
142
|
+
| LabelRendererRegistration
|
|
143
|
+
| ArrayRendererRegistration
|
|
144
|
+
| AdornmentRendererRegistration
|
|
145
|
+
| VisibilityRendererRegistration;
|
|
146
|
+
```
|
|
147
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
148
|
+
|
|
149
|
+
Probably the most common customisation would be to add a `DataRendererRegistration` which will change the way a `DataControlDefinition` is rendered for a particular FieldType:
|
|
150
|
+
|
|
151
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./src/renderers.tsx&lines=48-61) -->
|
|
152
|
+
<!-- The below code snippet is automatically added from ./src/renderers.tsx -->
|
|
153
|
+
```tsx
|
|
154
|
+
export interface DataRendererRegistration {
|
|
155
|
+
type: "data";
|
|
156
|
+
schemaType?: string | string[];
|
|
157
|
+
renderType?: string | string[];
|
|
158
|
+
options?: boolean;
|
|
159
|
+
collection?: boolean;
|
|
160
|
+
match?: (props: DataRendererProps) => boolean;
|
|
161
|
+
render: (
|
|
162
|
+
props: DataRendererProps,
|
|
163
|
+
defaultLabel: (label?: Partial<LabelRendererProps>) => LabelRendererProps,
|
|
164
|
+
renderers: FormRenderer,
|
|
165
|
+
) => ReactElement;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
169
|
+
* The `schemaType` field specifies which `FieldType`(s) should use this `DataRendererRegistration`, unspecified means allow any.
|
|
170
|
+
* The `renderType` field specifies which `DataRenderType` this registration applies to.
|
|
171
|
+
* The `match` function can be used if the matching logic is more complicated than provided by the other.
|
|
172
|
+
* The `render` function does the actual rendering if the ControlDefinition/SchemaField matches the registration.
|
|
173
|
+
|
|
174
|
+
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:
|
|
175
|
+
|
|
176
|
+
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=../schemas-mui/src/index.tsx&lines=12-35) -->
|
|
177
|
+
<!-- The below code snippet is automatically added from ../schemas-mui/src/index.tsx -->
|
|
178
|
+
```tsx
|
|
179
|
+
export function muiTextfieldRenderer(
|
|
180
|
+
variant?: "standard" | "outlined" | "filled",
|
|
181
|
+
): DataRendererRegistration {
|
|
182
|
+
return {
|
|
183
|
+
type: "data",
|
|
184
|
+
schemaType: FieldType.String,
|
|
185
|
+
renderType: DataRenderType.Standard,
|
|
186
|
+
render: (r, makeLabel, { renderVisibility }) => {
|
|
187
|
+
const { title, required } = makeLabel();
|
|
188
|
+
return renderVisibility(
|
|
189
|
+
r.visible,
|
|
190
|
+
<FTextField
|
|
191
|
+
variant={variant}
|
|
192
|
+
required={required}
|
|
193
|
+
fullWidth
|
|
194
|
+
size="small"
|
|
195
|
+
state={r.control}
|
|
196
|
+
label={title}
|
|
197
|
+
/>,
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
204
|
+
|
|
205
|
+
Changing the simple example above to use the following:
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
const renderer: FormRenderer = createFormRenderer(
|
|
209
|
+
[muiTextFieldRenderer()],
|
|
210
|
+
createDefaultRenderer (defaultTailwindTheme));
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
This will produce this UI:
|
|
214
|
+
|
|
215
|
+
<img src="../../images/schemas-muifield.png">
|
|
216
|
+
|
|
217
|
+
## TODO
|
|
218
|
+
|
|
219
|
+
* Label rendering
|
|
220
|
+
* Visibility
|
|
221
|
+
* Arrays
|
|
222
|
+
* Display controls
|
|
223
|
+
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ActionControlDefinition, AdornmentPlacement, CompoundField, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayControlDefinition, EntityExpression, FieldOption, GroupedControlsDefinition, RenderOptions, SchemaField, SchemaValidator } from "./types";
|
|
2
|
-
import
|
|
2
|
+
import { Key, ReactElement, ReactNode } from "react";
|
|
3
3
|
import { Control } from "@react-typed-forms/core";
|
|
4
4
|
export interface SchemaHooks {
|
|
5
5
|
useExpression(expr: EntityExpression, formState: FormEditState): Control<any | undefined>;
|
|
6
6
|
useValidators(formState: FormEditState, isVisible: boolean, control: Control<any>, required: boolean, validations?: SchemaValidator[] | null): void;
|
|
7
7
|
}
|
|
8
8
|
export interface FormEditHooks {
|
|
9
|
-
useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: SchemaField
|
|
10
|
-
useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition
|
|
9
|
+
useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: SchemaField): DataRendererProps;
|
|
10
|
+
useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition): GroupRendererProps;
|
|
11
11
|
useDisplayProperties(formState: FormEditState, definition: DisplayControlDefinition): DisplayRendererProps;
|
|
12
12
|
useActionProperties(formState: FormEditState, definition: ActionControlDefinition): ActionRendererProps;
|
|
13
13
|
schemaHooks: SchemaHooks;
|
|
@@ -39,12 +39,17 @@ export interface GroupRendererProps {
|
|
|
39
39
|
export interface ControlData {
|
|
40
40
|
[field: string]: any;
|
|
41
41
|
}
|
|
42
|
-
export interface
|
|
42
|
+
export interface FormDataContext {
|
|
43
43
|
fields: SchemaField[];
|
|
44
44
|
data: Control<ControlData>;
|
|
45
|
+
}
|
|
46
|
+
export interface FormEditState extends FormDataContext {
|
|
47
|
+
hooks: FormEditHooks;
|
|
48
|
+
renderer: FormRenderer;
|
|
45
49
|
readonly?: boolean;
|
|
46
50
|
invisible?: boolean;
|
|
47
51
|
}
|
|
52
|
+
export type RenderControlOptions = Omit<FormEditState, "data">;
|
|
48
53
|
export interface ArrayRendererProps {
|
|
49
54
|
definition: DataControlDefinition | GroupedControlsDefinition;
|
|
50
55
|
control: Control<any[]>;
|
|
@@ -73,11 +78,6 @@ export interface FormRenderer {
|
|
|
73
78
|
renderVisibility: (visible: Visibility, elem: ReactElement) => ReactElement;
|
|
74
79
|
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
75
80
|
}
|
|
76
|
-
export declare function FormRendererProvider({ value, children, }: {
|
|
77
|
-
value: FormRenderer;
|
|
78
|
-
children: ReactNode;
|
|
79
|
-
}): React.JSX.Element;
|
|
80
|
-
export declare function useFormRendererComponents(): FormRenderer;
|
|
81
81
|
export interface Visibility {
|
|
82
82
|
value: boolean;
|
|
83
83
|
canChange: boolean;
|
|
@@ -104,9 +104,9 @@ export type AnySchemaFields = SchemaField | (Omit<CompoundField, "children"> & {
|
|
|
104
104
|
children: AnySchemaFields[];
|
|
105
105
|
});
|
|
106
106
|
export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
|
|
107
|
-
export declare function renderControl<S extends ControlDefinition>(definition: S,
|
|
107
|
+
export declare function renderControl<S extends ControlDefinition>(definition: S, data: Control<any>, options: RenderControlOptions, key?: Key): ReactElement;
|
|
108
108
|
export declare function controlForField(field: string, formState: FormEditState): Control<any>;
|
|
109
109
|
export declare function fieldForControl(c: ControlDefinition): string | null | undefined;
|
|
110
110
|
export declare const AlwaysVisible: Visibility;
|
|
111
111
|
export declare function createAction(label: string, onClick: () => void, actionId?: string): ActionRendererProps;
|
|
112
|
-
export declare function visitControlData<S extends ControlDefinition, A>(definition: S, { fields, data }:
|
|
112
|
+
export declare function visitControlData<S extends ControlDefinition, A>(definition: S, { fields, data }: FormDataContext, cb: (definition: DataControlDefinition, control: Control<any>) => A | undefined): A | undefined;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare function getOptionsForScalarField(field: SchemaField): FieldOptio
|
|
|
8
8
|
export declare function createDefaultSchemaHooks(): SchemaHooks;
|
|
9
9
|
export declare const defaultFormEditHooks: FormEditHooks;
|
|
10
10
|
export declare function createFormEditHooks(schemaHooks: SchemaHooks): FormEditHooks;
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function useControlDefinitionForSchema(sf: SchemaField[], definition?: GroupedControlsDefinition): GroupedControlsDefinition;
|
package/lib/index.js
CHANGED
|
@@ -423,40 +423,14 @@ function addMissingControls(fields, controls) {
|
|
|
423
423
|
}));
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
var _FormRendererComponentsContext = null;
|
|
427
|
-
function FormRendererComponentsContext() {
|
|
428
|
-
if (!_FormRendererComponentsContext) {
|
|
429
|
-
_FormRendererComponentsContext = React.createContext(undefined);
|
|
430
|
-
}
|
|
431
|
-
return _FormRendererComponentsContext;
|
|
432
|
-
}
|
|
433
|
-
function FormRendererProvider(_ref) {
|
|
434
|
-
var _effect = core.useComponentTracking();
|
|
435
|
-
try {
|
|
436
|
-
var value = _ref.value,
|
|
437
|
-
children = _ref.children;
|
|
438
|
-
var _FormRendererComponen = FormRendererComponentsContext(),
|
|
439
|
-
Provider = _FormRendererComponen.Provider;
|
|
440
|
-
return /*#__PURE__*/React__default["default"].createElement(Provider, {
|
|
441
|
-
value: value,
|
|
442
|
-
children: children
|
|
443
|
-
});
|
|
444
|
-
} finally {
|
|
445
|
-
_effect();
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function useFormRendererComponents() {
|
|
449
|
-
var c = React.useContext(FormRendererComponentsContext());
|
|
450
|
-
if (!c) {
|
|
451
|
-
throw "Need to use FormRendererComponentContext.Provider";
|
|
452
|
-
}
|
|
453
|
-
return c;
|
|
454
|
-
}
|
|
455
426
|
function controlTitle(title, field) {
|
|
456
427
|
return title ? title : fieldDisplayName(field);
|
|
457
428
|
}
|
|
458
|
-
function renderControl(definition,
|
|
459
|
-
var fields =
|
|
429
|
+
function renderControl(definition, data, options, key) {
|
|
430
|
+
var fields = options.fields;
|
|
431
|
+
var formState = _extends({}, options, {
|
|
432
|
+
data: data
|
|
433
|
+
});
|
|
460
434
|
return visitControlDefinition(definition, {
|
|
461
435
|
data: function data(def) {
|
|
462
436
|
var fieldData = findScalarField(fields, def.field);
|
|
@@ -466,7 +440,6 @@ function renderControl(definition, formState, hooks, key) {
|
|
|
466
440
|
return /*#__PURE__*/React__default["default"].createElement(DataRenderer, {
|
|
467
441
|
key: key,
|
|
468
442
|
formState: formState,
|
|
469
|
-
hooks: hooks,
|
|
470
443
|
controlDef: def,
|
|
471
444
|
fieldData: fieldData
|
|
472
445
|
});
|
|
@@ -474,7 +447,6 @@ function renderControl(definition, formState, hooks, key) {
|
|
|
474
447
|
group: function group(d) {
|
|
475
448
|
return /*#__PURE__*/React__default["default"].createElement(GroupRenderer, {
|
|
476
449
|
key: key,
|
|
477
|
-
hooks: hooks,
|
|
478
450
|
groupDef: d,
|
|
479
451
|
formState: formState
|
|
480
452
|
});
|
|
@@ -482,7 +454,6 @@ function renderControl(definition, formState, hooks, key) {
|
|
|
482
454
|
action: function action(d) {
|
|
483
455
|
return /*#__PURE__*/React__default["default"].createElement(ActionRenderer, {
|
|
484
456
|
key: key,
|
|
485
|
-
hooks: hooks,
|
|
486
457
|
formState: formState,
|
|
487
458
|
actionDef: d
|
|
488
459
|
});
|
|
@@ -490,7 +461,6 @@ function renderControl(definition, formState, hooks, key) {
|
|
|
490
461
|
display: function display(d) {
|
|
491
462
|
return /*#__PURE__*/React__default["default"].createElement(DisplayRenderer, {
|
|
492
463
|
key: key,
|
|
493
|
-
hooks: hooks,
|
|
494
464
|
formState: formState,
|
|
495
465
|
displayDef: d
|
|
496
466
|
});
|
|
@@ -500,69 +470,59 @@ function renderControl(definition, formState, hooks, key) {
|
|
|
500
470
|
});
|
|
501
471
|
}
|
|
502
472
|
/** @trackControls */
|
|
503
|
-
function DataRenderer(
|
|
504
|
-
var
|
|
473
|
+
function DataRenderer(_ref) {
|
|
474
|
+
var _effect = core.useComponentTracking();
|
|
505
475
|
try {
|
|
506
476
|
var _props$customRender;
|
|
507
|
-
var
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
var props = hooks.useDataProperties(formState, controlDef, fieldData, renderer);
|
|
513
|
-
return ((_props$customRender = props.customRender) != null ? _props$customRender : renderer.renderData)(props);
|
|
477
|
+
var formState = _ref.formState,
|
|
478
|
+
controlDef = _ref.controlDef,
|
|
479
|
+
fieldData = _ref.fieldData;
|
|
480
|
+
var props = formState.hooks.useDataProperties(formState, controlDef, fieldData);
|
|
481
|
+
return ((_props$customRender = props.customRender) != null ? _props$customRender : formState.renderer.renderData)(props);
|
|
514
482
|
} finally {
|
|
515
|
-
|
|
483
|
+
_effect();
|
|
516
484
|
}
|
|
517
485
|
}
|
|
518
486
|
/** @trackControls */ /** @trackControls */
|
|
519
|
-
function ActionRenderer(
|
|
520
|
-
var
|
|
487
|
+
function ActionRenderer(_ref2) {
|
|
488
|
+
var _effect2 = core.useComponentTracking();
|
|
521
489
|
try {
|
|
522
|
-
var
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
renderAction = _useFormRendererCompo.renderAction;
|
|
527
|
-
var actionControlProperties = hooks.useActionProperties(formState, actionDef);
|
|
528
|
-
return renderAction(actionControlProperties);
|
|
490
|
+
var formState = _ref2.formState,
|
|
491
|
+
actionDef = _ref2.actionDef;
|
|
492
|
+
var actionControlProperties = formState.hooks.useActionProperties(formState, actionDef);
|
|
493
|
+
return formState.renderer.renderAction(actionControlProperties);
|
|
529
494
|
} finally {
|
|
530
|
-
|
|
495
|
+
_effect2();
|
|
531
496
|
}
|
|
532
497
|
}
|
|
533
498
|
/** @trackControls */ /** @trackControls */
|
|
534
|
-
function GroupRenderer(
|
|
535
|
-
var
|
|
499
|
+
function GroupRenderer(_ref3) {
|
|
500
|
+
var _effect3 = core.useComponentTracking();
|
|
536
501
|
try {
|
|
537
|
-
var
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
var groupProps = hooks.useGroupProperties(formState, groupDef, hooks, renderers);
|
|
542
|
-
return renderers.renderGroup(groupProps);
|
|
502
|
+
var formState = _ref3.formState,
|
|
503
|
+
groupDef = _ref3.groupDef;
|
|
504
|
+
var groupProps = formState.hooks.useGroupProperties(formState, groupDef);
|
|
505
|
+
return formState.renderer.renderGroup(groupProps);
|
|
543
506
|
} finally {
|
|
544
|
-
|
|
507
|
+
_effect3();
|
|
545
508
|
}
|
|
546
509
|
}
|
|
547
510
|
/** @trackControls */ /** @trackControls */
|
|
548
|
-
function DisplayRenderer(
|
|
549
|
-
var
|
|
511
|
+
function DisplayRenderer(_ref4) {
|
|
512
|
+
var _effect4 = core.useComponentTracking();
|
|
550
513
|
try {
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
renderDisplay = _useFormRendererCompo2.renderDisplay;
|
|
556
|
-
var displayProps = hooks.useDisplayProperties(formState, displayDef);
|
|
557
|
-
return renderDisplay(displayProps);
|
|
514
|
+
var formState = _ref4.formState,
|
|
515
|
+
displayDef = _ref4.displayDef;
|
|
516
|
+
var displayProps = formState.hooks.useDisplayProperties(formState, displayDef);
|
|
517
|
+
return formState.renderer.renderDisplay(displayProps);
|
|
558
518
|
} finally {
|
|
559
|
-
|
|
519
|
+
_effect4();
|
|
560
520
|
}
|
|
561
521
|
}
|
|
562
522
|
function controlForField(field, formState) {
|
|
563
|
-
var
|
|
523
|
+
var _ref5;
|
|
564
524
|
var refField = findField(formState.fields, field);
|
|
565
|
-
return (
|
|
525
|
+
return (_ref5 = refField && formState.data.fields[refField.field]) != null ? _ref5 : core.newControl(undefined);
|
|
566
526
|
}
|
|
567
527
|
function fieldForControl(c) {
|
|
568
528
|
return isDataControl(c) ? c.field : isGroupControl(c) ? c.compoundField : undefined;
|
|
@@ -582,9 +542,9 @@ function createAction(label, onClick, actionId) {
|
|
|
582
542
|
onClick: onClick
|
|
583
543
|
};
|
|
584
544
|
}
|
|
585
|
-
function visitControlData(definition,
|
|
586
|
-
var fields =
|
|
587
|
-
_data =
|
|
545
|
+
function visitControlData(definition, _ref6, cb) {
|
|
546
|
+
var fields = _ref6.fields,
|
|
547
|
+
_data = _ref6.data;
|
|
588
548
|
return visitControlDefinition(definition, {
|
|
589
549
|
data: function data(def) {
|
|
590
550
|
var fieldData = findScalarField(fields, def.field);
|
|
@@ -775,7 +735,7 @@ var defaultFormEditHooks = createFormEditHooks(createDefaultSchemaHooks());
|
|
|
775
735
|
function createFormEditHooks(schemaHooks) {
|
|
776
736
|
return {
|
|
777
737
|
schemaHooks: schemaHooks,
|
|
778
|
-
useDataProperties: function useDataProperties(formState, definition, field
|
|
738
|
+
useDataProperties: function useDataProperties(formState, definition, field) {
|
|
779
739
|
var visible = useIsControlVisible(definition, formState, schemaHooks);
|
|
780
740
|
var isVisible = visible.value && !formState.invisible;
|
|
781
741
|
var defaultValue = useDefaultValue(definition, field, formState, schemaHooks);
|
|
@@ -798,7 +758,7 @@ function createFormEditHooks(schemaHooks) {
|
|
|
798
758
|
if (!field.collection) return dataProps;
|
|
799
759
|
return _extends({}, dataProps, {
|
|
800
760
|
array: defaultArrayRendererProps(scalarControl, field, definition, dataProps.readonly, function (c) {
|
|
801
|
-
return renderer.renderData(_extends({}, dataProps, {
|
|
761
|
+
return formState.renderer.renderData(_extends({}, dataProps, {
|
|
802
762
|
control: c
|
|
803
763
|
}));
|
|
804
764
|
})
|
|
@@ -811,34 +771,32 @@ function createFormEditHooks(schemaHooks) {
|
|
|
811
771
|
definition: definition
|
|
812
772
|
};
|
|
813
773
|
},
|
|
814
|
-
useGroupProperties: function useGroupProperties(fs, definition
|
|
774
|
+
useGroupProperties: function useGroupProperties(fs, definition) {
|
|
815
775
|
var _definition$groupOpti;
|
|
816
776
|
var visible = useIsControlVisible(definition, fs, schemaHooks);
|
|
817
777
|
var field = definition.compoundField ? findCompoundField(fs.fields, definition.compoundField) : undefined;
|
|
818
778
|
var newFs = _extends({}, fs, {
|
|
819
779
|
fields: field ? field.children : fs.fields,
|
|
820
|
-
data: field ? fs.data.fields[field.field] : fs.data,
|
|
821
780
|
invisible: !visible.value || fs.invisible
|
|
822
781
|
});
|
|
782
|
+
var data = field ? fs.data.fields[field.field] : fs.data;
|
|
823
783
|
var groupProps = {
|
|
824
784
|
visible: visible,
|
|
825
|
-
hooks: hooks,
|
|
785
|
+
hooks: fs.hooks,
|
|
826
786
|
hideTitle: (_definition$groupOpti = definition.groupOptions.hideTitle) != null ? _definition$groupOpti : false,
|
|
827
787
|
childCount: definition.children.length,
|
|
828
788
|
renderChild: function renderChild(i) {
|
|
829
|
-
return renderControl(definition.children[i],
|
|
789
|
+
return renderControl(definition.children[i], data, newFs, i);
|
|
830
790
|
},
|
|
831
791
|
definition: definition
|
|
832
792
|
};
|
|
833
793
|
if (field != null && field.collection) {
|
|
834
794
|
return _extends({}, groupProps, {
|
|
835
|
-
array: defaultArrayRendererProps(
|
|
836
|
-
return
|
|
795
|
+
array: defaultArrayRendererProps(data, field, definition, fs.readonly, function (e) {
|
|
796
|
+
return fs.renderer.renderGroup(_extends({}, groupProps, {
|
|
837
797
|
hideTitle: true,
|
|
838
798
|
renderChild: function renderChild(i) {
|
|
839
|
-
return renderControl(definition.children[i],
|
|
840
|
-
data: e
|
|
841
|
-
}), hooks, i);
|
|
799
|
+
return renderControl(definition.children[i], e, newFs, i);
|
|
842
800
|
}
|
|
843
801
|
}));
|
|
844
802
|
})
|
|
@@ -904,7 +862,18 @@ function defaultArrayRendererProps(control, field, definition, readonly, renderE
|
|
|
904
862
|
}
|
|
905
863
|
};
|
|
906
864
|
}
|
|
907
|
-
|
|
865
|
+
var emptyGroupDefinition = {
|
|
866
|
+
type: exports.ControlDefinitionType.Group,
|
|
867
|
+
children: [],
|
|
868
|
+
groupOptions: {
|
|
869
|
+
type: exports.GroupRenderType.Standard,
|
|
870
|
+
hideTitle: true
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
function useControlDefinitionForSchema(sf, definition) {
|
|
874
|
+
if (definition === void 0) {
|
|
875
|
+
definition = emptyGroupDefinition;
|
|
876
|
+
}
|
|
908
877
|
return React.useMemo(function () {
|
|
909
878
|
return definition.children.length ? definition : _extends({}, definition, {
|
|
910
879
|
children: addMissingControls(sf, [])
|
|
@@ -1546,7 +1515,6 @@ exports.AlwaysVisible = AlwaysVisible;
|
|
|
1546
1515
|
exports.ControlInput = ControlInput;
|
|
1547
1516
|
exports.DefaultBoolOptions = DefaultBoolOptions;
|
|
1548
1517
|
exports.DefaultLabelRenderer = DefaultLabelRenderer;
|
|
1549
|
-
exports.FormRendererProvider = FormRendererProvider;
|
|
1550
1518
|
exports.SelectDataRenderer = SelectDataRenderer;
|
|
1551
1519
|
exports.addMissingControls = addMissingControls;
|
|
1552
1520
|
exports.applyDefaultForField = applyDefaultForField;
|
|
@@ -1611,9 +1579,8 @@ exports.makeScalarField = makeScalarField;
|
|
|
1611
1579
|
exports.renderControl = renderControl;
|
|
1612
1580
|
exports.stringField = stringField;
|
|
1613
1581
|
exports.stringOptionsField = stringOptionsField;
|
|
1614
|
-
exports.
|
|
1582
|
+
exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
|
|
1615
1583
|
exports.useDefaultValue = useDefaultValue;
|
|
1616
|
-
exports.useFormRendererComponents = useFormRendererComponents;
|
|
1617
1584
|
exports.useIsControlVisible = useIsControlVisible;
|
|
1618
1585
|
exports.visibility = visibility;
|
|
1619
1586
|
exports.visitControlData = visitControlData;
|