@react-typed-forms/schemas 3.0.0-dev.73 → 3.0.0-dev.75
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"packages/schemas/.rush/temp/shrinkwrap-deps.json": "6ad43bbf71e5f191d9f571da269a25bb4d9e8909",
|
|
4
|
-
"packages/schemas/package.json": "
|
|
5
|
-
"packages/schemas/src/controlRender.tsx": "
|
|
4
|
+
"packages/schemas/package.json": "e9159622e23f1520fa450cdaec83f7c98d5e856f",
|
|
5
|
+
"packages/schemas/src/controlRender.tsx": "24db6564d9793bb7236bbf19aea759e26391ffff",
|
|
6
6
|
"packages/schemas/src/hooks.ts": "64cf3ef2b5151231c9ffbc26da34002a3cab867d",
|
|
7
7
|
"packages/schemas/src/index.ts": "b15fbb6de132cd912cf8141d5c4d2329e947546e",
|
|
8
8
|
"packages/schemas/src/schemaBuilder.ts": "3a36cbc35f70fca2b561f6d4ddc1bd1030eeb3f6",
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionControlDefinition, AnyControlDefinition, CompoundField, ControlDefinition, DataControlDefinition, DisplayControlDefinition, FieldOption, GroupedControlsDefinition, ScalarField, SchemaField } from "./types";
|
|
2
2
|
import React, { Key, ReactElement } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { Control } from "@react-typed-forms/core";
|
|
4
4
|
export interface FormEditHooks {
|
|
5
5
|
useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: ScalarField): DataControlProperties;
|
|
6
6
|
useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition, currentHooks: FormEditHooks): GroupControlProperties;
|
|
@@ -12,7 +12,7 @@ export interface DataControlProperties {
|
|
|
12
12
|
options: FieldOption[] | undefined;
|
|
13
13
|
defaultValue: any;
|
|
14
14
|
required: boolean;
|
|
15
|
-
customRender?: (props: DataRendererProps) => ReactElement;
|
|
15
|
+
customRender?: (props: DataRendererProps, control: Control<any>) => ReactElement;
|
|
16
16
|
}
|
|
17
17
|
export interface GroupControlProperties {
|
|
18
18
|
visible: boolean;
|
|
@@ -33,9 +33,9 @@ export interface FormEditState {
|
|
|
33
33
|
data: Control<ControlData>;
|
|
34
34
|
}
|
|
35
35
|
export interface FormRendererComponents {
|
|
36
|
-
renderData: (props: DataRendererProps) => ReactElement;
|
|
36
|
+
renderData: (props: DataRendererProps, control: Control<any>, element: boolean, renderers: FormRendererComponents) => ReactElement;
|
|
37
|
+
renderCompound: (props: CompoundGroupRendererProps, control: Control<any>, renderers: FormRendererComponents) => ReactElement;
|
|
37
38
|
renderGroup: (props: GroupRendererProps) => ReactElement;
|
|
38
|
-
renderCompound: (props: CompoundGroupRendererProps) => ReactElement;
|
|
39
39
|
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
40
40
|
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
41
41
|
}
|
|
@@ -53,7 +53,6 @@ export interface DataRendererProps {
|
|
|
53
53
|
definition: DataControlDefinition;
|
|
54
54
|
properties: DataControlProperties;
|
|
55
55
|
field: ScalarField;
|
|
56
|
-
control: AnyControl;
|
|
57
56
|
formEditState?: FormEditState;
|
|
58
57
|
}
|
|
59
58
|
export interface GroupRendererProps {
|
|
@@ -65,7 +64,6 @@ export interface GroupRendererProps {
|
|
|
65
64
|
export interface CompoundGroupRendererProps {
|
|
66
65
|
definition: GroupedControlsDefinition;
|
|
67
66
|
field: CompoundField;
|
|
68
|
-
control: AnyControl;
|
|
69
67
|
properties: GroupControlProperties;
|
|
70
68
|
renderChild: (key: Key, control: ControlDefinition, data: Control<{
|
|
71
69
|
[field: string]: any;
|
package/lib/controlRender.js
CHANGED
|
@@ -134,7 +134,7 @@ function renderControl(definition, formState, hooks, key, wrapChild) {
|
|
|
134
134
|
exports.renderControl = renderControl;
|
|
135
135
|
function DataRenderer({ hooks, formState, controlDef, wrapElem, fieldData, }) {
|
|
136
136
|
var _a, _b;
|
|
137
|
-
const
|
|
137
|
+
const renderer = useFormRendererComponents();
|
|
138
138
|
const props = hooks.useDataProperties(formState, controlDef, fieldData);
|
|
139
139
|
const scalarControl = (_a = formState.data.fields[fieldData.field]) !== null && _a !== void 0 ? _a : (0, core_1.newControl)(undefined);
|
|
140
140
|
(0, core_1.useControlChangeEffect)(scalarControl, (c) => {
|
|
@@ -148,11 +148,10 @@ function DataRenderer({ hooks, formState, controlDef, wrapElem, fieldData, }) {
|
|
|
148
148
|
const scalarProps = {
|
|
149
149
|
formEditState: formState,
|
|
150
150
|
field: fieldData,
|
|
151
|
-
control: scalarControl,
|
|
152
151
|
definition: controlDef,
|
|
153
152
|
properties: props,
|
|
154
153
|
};
|
|
155
|
-
return wrapElem(((_b = props.customRender) !== null && _b !== void 0 ? _b : renderData)(scalarProps));
|
|
154
|
+
return wrapElem(((_b = props.customRender) !== null && _b !== void 0 ? _b : renderer.renderData)(scalarProps, scalarControl, false, renderer));
|
|
156
155
|
}
|
|
157
156
|
function ActionRenderer({ hooks, formState, wrapElem, actionDef, }) {
|
|
158
157
|
const { renderAction } = useFormRendererComponents();
|
|
@@ -163,7 +162,7 @@ function ActionRenderer({ hooks, formState, wrapElem, actionDef, }) {
|
|
|
163
162
|
return wrapElem(renderAction({ definition: actionDef, properties: actionControlProperties }));
|
|
164
163
|
}
|
|
165
164
|
function GroupRenderer({ hooks, formState, groupDef, wrapElem, }) {
|
|
166
|
-
const
|
|
165
|
+
const renderers = useFormRendererComponents();
|
|
167
166
|
const groupProps = hooks.useGroupProperties(formState, groupDef, hooks);
|
|
168
167
|
if (!groupProps.visible) {
|
|
169
168
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
@@ -172,15 +171,14 @@ function GroupRenderer({ hooks, formState, groupDef, wrapElem, }) {
|
|
|
172
171
|
? findCompoundField(formState.fields, groupDef.compoundField)
|
|
173
172
|
: undefined;
|
|
174
173
|
if (compoundField) {
|
|
175
|
-
return wrapElem(renderCompound({
|
|
174
|
+
return wrapElem(renderers.renderCompound({
|
|
176
175
|
definition: groupDef,
|
|
177
176
|
field: compoundField,
|
|
178
|
-
control: formState.data.fields[compoundField.field],
|
|
179
177
|
properties: groupProps,
|
|
180
178
|
renderChild: (k, c, data, wrapChild) => renderControl(c, Object.assign(Object.assign({}, formState), { fields: compoundField.children, data }), groupProps.hooks, k, wrapChild),
|
|
181
|
-
}));
|
|
179
|
+
}, formState.data.fields[compoundField.field], renderers));
|
|
182
180
|
}
|
|
183
|
-
return wrapElem(renderGroup({
|
|
181
|
+
return wrapElem(renderers.renderGroup({
|
|
184
182
|
definition: groupDef,
|
|
185
183
|
childCount: groupDef.children.length,
|
|
186
184
|
properties: groupProps,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.75",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"material-ui"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@react-typed-forms/core": "3.0.0-dev.
|
|
27
|
+
"@react-typed-forms/core": "3.0.0-dev.75"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.0.22",
|
|
31
|
+
"nswag": "^13.18.2",
|
|
31
32
|
"react": "^18.2.0",
|
|
32
33
|
"react-dom": "^18.2.0",
|
|
33
|
-
"rimraf": "^3.0.2"
|
|
34
|
-
"nswag": "^13.18.2"
|
|
34
|
+
"rimraf": "^3.0.2"
|
|
35
35
|
},
|
|
36
36
|
"gitHead": "698e16cd3ab31b7dd0528fc76536f4d3205ce8c6",
|
|
37
37
|
"scripts": {
|
package/src/controlRender.tsx
CHANGED
|
@@ -47,7 +47,10 @@ export interface DataControlProperties {
|
|
|
47
47
|
options: FieldOption[] | undefined;
|
|
48
48
|
defaultValue: any;
|
|
49
49
|
required: boolean;
|
|
50
|
-
customRender?: (
|
|
50
|
+
customRender?: (
|
|
51
|
+
props: DataRendererProps,
|
|
52
|
+
control: Control<any>
|
|
53
|
+
) => ReactElement;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
export interface GroupControlProperties {
|
|
@@ -74,9 +77,18 @@ export interface FormEditState {
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
export interface FormRendererComponents {
|
|
77
|
-
renderData: (
|
|
80
|
+
renderData: (
|
|
81
|
+
props: DataRendererProps,
|
|
82
|
+
control: Control<any>,
|
|
83
|
+
element: boolean,
|
|
84
|
+
renderers: FormRendererComponents
|
|
85
|
+
) => ReactElement;
|
|
86
|
+
renderCompound: (
|
|
87
|
+
props: CompoundGroupRendererProps,
|
|
88
|
+
control: Control<any>,
|
|
89
|
+
renderers: FormRendererComponents
|
|
90
|
+
) => ReactElement;
|
|
78
91
|
renderGroup: (props: GroupRendererProps) => ReactElement;
|
|
79
|
-
renderCompound: (props: CompoundGroupRendererProps) => ReactElement;
|
|
80
92
|
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
81
93
|
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
82
94
|
}
|
|
@@ -107,7 +119,6 @@ export interface DataRendererProps {
|
|
|
107
119
|
definition: DataControlDefinition;
|
|
108
120
|
properties: DataControlProperties;
|
|
109
121
|
field: ScalarField;
|
|
110
|
-
control: AnyControl;
|
|
111
122
|
formEditState?: FormEditState;
|
|
112
123
|
}
|
|
113
124
|
|
|
@@ -124,7 +135,6 @@ export interface GroupRendererProps {
|
|
|
124
135
|
export interface CompoundGroupRendererProps {
|
|
125
136
|
definition: GroupedControlsDefinition;
|
|
126
137
|
field: CompoundField;
|
|
127
|
-
control: AnyControl;
|
|
128
138
|
properties: GroupControlProperties;
|
|
129
139
|
renderChild: (
|
|
130
140
|
key: Key,
|
|
@@ -306,7 +316,7 @@ function DataRenderer({
|
|
|
306
316
|
fieldData: ScalarField;
|
|
307
317
|
wrapElem: (db: ReactElement) => ReactElement;
|
|
308
318
|
}) {
|
|
309
|
-
const
|
|
319
|
+
const renderer = useFormRendererComponents();
|
|
310
320
|
const props = hooks.useDataProperties(formState, controlDef, fieldData);
|
|
311
321
|
const scalarControl =
|
|
312
322
|
formState.data.fields[fieldData.field] ?? newControl(undefined);
|
|
@@ -327,11 +337,17 @@ function DataRenderer({
|
|
|
327
337
|
const scalarProps: DataRendererProps = {
|
|
328
338
|
formEditState: formState,
|
|
329
339
|
field: fieldData,
|
|
330
|
-
control: scalarControl,
|
|
331
340
|
definition: controlDef,
|
|
332
341
|
properties: props,
|
|
333
342
|
};
|
|
334
|
-
return wrapElem(
|
|
343
|
+
return wrapElem(
|
|
344
|
+
(props.customRender ?? renderer.renderData)(
|
|
345
|
+
scalarProps,
|
|
346
|
+
scalarControl,
|
|
347
|
+
false,
|
|
348
|
+
renderer
|
|
349
|
+
)
|
|
350
|
+
);
|
|
335
351
|
}
|
|
336
352
|
|
|
337
353
|
function ActionRenderer({
|
|
@@ -370,7 +386,7 @@ function GroupRenderer({
|
|
|
370
386
|
formState: FormEditState;
|
|
371
387
|
wrapElem: (db: ReactElement) => ReactElement;
|
|
372
388
|
}) {
|
|
373
|
-
const
|
|
389
|
+
const renderers = useFormRendererComponents();
|
|
374
390
|
|
|
375
391
|
const groupProps = hooks.useGroupProperties(formState, groupDef, hooks);
|
|
376
392
|
if (!groupProps.visible) {
|
|
@@ -381,28 +397,31 @@ function GroupRenderer({
|
|
|
381
397
|
: undefined;
|
|
382
398
|
if (compoundField) {
|
|
383
399
|
return wrapElem(
|
|
384
|
-
renderCompound(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
renderers.renderCompound(
|
|
401
|
+
{
|
|
402
|
+
definition: groupDef,
|
|
403
|
+
field: compoundField,
|
|
404
|
+
properties: groupProps,
|
|
405
|
+
renderChild: (k, c, data, wrapChild) =>
|
|
406
|
+
renderControl(
|
|
407
|
+
c,
|
|
408
|
+
{
|
|
409
|
+
...formState,
|
|
410
|
+
fields: compoundField!.children,
|
|
411
|
+
data,
|
|
412
|
+
},
|
|
413
|
+
groupProps.hooks,
|
|
414
|
+
k,
|
|
415
|
+
wrapChild
|
|
416
|
+
),
|
|
417
|
+
},
|
|
418
|
+
formState.data.fields[compoundField.field],
|
|
419
|
+
renderers
|
|
420
|
+
)
|
|
402
421
|
);
|
|
403
422
|
}
|
|
404
423
|
return wrapElem(
|
|
405
|
-
renderGroup({
|
|
424
|
+
renderers.renderGroup({
|
|
406
425
|
definition: groupDef,
|
|
407
426
|
childCount: groupDef.children.length,
|
|
408
427
|
properties: groupProps,
|