@react-typed-forms/schemas 1.0.0-dev.4 → 1.0.0-dev.5
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/package-deps_build.json +3 -3
- package/lib/controlRender.d.ts +2 -2
- package/lib/controlRender.js +9 -14
- package/lib/types.d.ts +12 -1
- package/lib/types.js +32 -1
- package/package.json +2 -2
- package/src/controlRender.tsx +34 -34
- package/src/types.ts +53 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"packages/schemas/.rush/temp/shrinkwrap-deps.json": "5ce6417fae765db5c61e400f851ecafe0ce756f0",
|
|
4
|
-
"packages/schemas/package.json": "
|
|
5
|
-
"packages/schemas/src/controlRender.tsx": "
|
|
4
|
+
"packages/schemas/package.json": "5202ff608c6285e7e95527d5d9fe442452e8a227",
|
|
5
|
+
"packages/schemas/src/controlRender.tsx": "3a1df1f3ade46594dbc15bca1228dc0d57e55da0",
|
|
6
6
|
"packages/schemas/src/hooks.ts": "4eb4946f7b1c685e0b51cd011b4d39a1fdd6aa2e",
|
|
7
7
|
"packages/schemas/src/index.ts": "67f656f1d7f717bce7e933b9f4d7dc5dc50274dc",
|
|
8
8
|
"packages/schemas/src/schemaBuilder.ts": "bfe74d3fb1cc2a4d5226051a58e025e107c32b11",
|
|
9
|
-
"packages/schemas/src/types.ts": "
|
|
9
|
+
"packages/schemas/src/types.ts": "69013139f9905b1c995c88b0cd58bba71ccc85d6",
|
|
10
10
|
"packages/schemas/tsconfig.json": "52e4f044fa580f4e0ad5830f3cfca574e2788372"
|
|
11
11
|
},
|
|
12
12
|
"arguments": "rimraf ./lib/ && tsc "
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionControlDefinition,
|
|
1
|
+
import { ActionControlDefinition, CompoundField, ControlDefinition, DataControlDefinition, DisplayControlDefinition, FieldOption, GroupedControlsDefinition, SchemaField } from "./types";
|
|
2
2
|
import React, { Key, ReactElement } from "react";
|
|
3
3
|
import { Control } from "@react-typed-forms/core";
|
|
4
4
|
export interface FormEditHooks {
|
|
@@ -88,7 +88,7 @@ export declare function findScalarField(fields: SchemaField[], field: string): S
|
|
|
88
88
|
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
89
89
|
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
90
90
|
export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
|
|
91
|
-
export declare function renderControl(definition:
|
|
91
|
+
export declare function renderControl<S extends ControlDefinition>(definition: S, formState: FormEditState, hooks: FormEditHooks, key: Key, wrapChild?: (key: Key, db: ReactElement) => ReactElement): ReactElement;
|
|
92
92
|
export declare function controlForField(field: string, formState: FormEditState): Control<any>;
|
|
93
93
|
export declare function fieldForControl(c: ControlDefinition): string | null | undefined;
|
|
94
94
|
export declare function isDataControl(c: ControlDefinition): c is DataControlDefinition;
|
package/lib/controlRender.js
CHANGED
|
@@ -116,26 +116,21 @@ function controlTitle(title, field) {
|
|
|
116
116
|
exports.controlTitle = controlTitle;
|
|
117
117
|
function renderControl(definition, formState, hooks, key, wrapChild) {
|
|
118
118
|
const { fields } = formState;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const def = definition;
|
|
119
|
+
return (0, types_1.visitControlDefinition)(definition, {
|
|
120
|
+
data: (def) => {
|
|
122
121
|
const fieldData = findScalarField(fields, def.field);
|
|
123
122
|
if (!fieldData)
|
|
124
123
|
return react_1.default.createElement("h1", null,
|
|
125
124
|
"No schema field for: ",
|
|
126
125
|
def.field);
|
|
127
126
|
return (react_1.default.createElement(DataRenderer, { key: key, wrapElem: wrapElem, formState: formState, hooks: hooks, controlDef: def, fieldData: fieldData }));
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return react_1.default.createElement("h1", null,
|
|
136
|
-
"Unknown control: ",
|
|
137
|
-
definition.type);
|
|
138
|
-
}
|
|
127
|
+
},
|
|
128
|
+
group: (d) => (react_1.default.createElement(GroupRenderer, { key: key, hooks: hooks, groupDef: d, formState: formState, wrapElem: wrapElem })),
|
|
129
|
+
action: (d) => (react_1.default.createElement(ActionRenderer, { key: key, hooks: hooks, formState: formState, wrapElem: wrapElem, actionDef: d })),
|
|
130
|
+
display: (d) => (react_1.default.createElement(DisplayRenderer, { key: key, hooks: hooks, formState: formState, wrapElem: wrapElem, displayDef: d })),
|
|
131
|
+
}, () => react_1.default.createElement("h1", null,
|
|
132
|
+
"Unknown control: ",
|
|
133
|
+
definition.type));
|
|
139
134
|
function wrapElem(e) {
|
|
140
135
|
var _a;
|
|
141
136
|
return (_a = wrapChild === null || wrapChild === void 0 ? void 0 : wrapChild(key, e)) !== null && _a !== void 0 ? _a : e;
|
package/lib/types.d.ts
CHANGED
|
@@ -156,7 +156,7 @@ export interface IconSelectionRenderOptions extends RenderOptions {
|
|
|
156
156
|
}
|
|
157
157
|
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
158
158
|
type: ControlDefinitionType.Group;
|
|
159
|
-
children:
|
|
159
|
+
children: ControlDefinition[];
|
|
160
160
|
compoundField?: string | null;
|
|
161
161
|
groupOptions: GroupRenderOptions;
|
|
162
162
|
}
|
|
@@ -198,3 +198,14 @@ export interface ActionControlDefinition extends ControlDefinition {
|
|
|
198
198
|
type: ControlDefinitionType.Action;
|
|
199
199
|
actionId: string;
|
|
200
200
|
}
|
|
201
|
+
export declare function isDataControlDefinition(x: ControlDefinition): x is DataControlDefinition;
|
|
202
|
+
export declare function isGroupControlsDefinition(x: ControlDefinition): x is GroupedControlsDefinition;
|
|
203
|
+
export declare function isDisplayControlsDefinition(x: ControlDefinition): x is DisplayControlDefinition;
|
|
204
|
+
export declare function isActionControlsDefinition(x: ControlDefinition): x is ActionControlDefinition;
|
|
205
|
+
export interface ControlVisitor<A> {
|
|
206
|
+
data(d: DataControlDefinition): A;
|
|
207
|
+
group(d: GroupedControlsDefinition): A;
|
|
208
|
+
display(d: DisplayControlDefinition): A;
|
|
209
|
+
action(d: ActionControlDefinition): A;
|
|
210
|
+
}
|
|
211
|
+
export declare function visitControlDefinition<A>(x: ControlDefinition, visitor: ControlVisitor<A>, defaultValue: (c: ControlDefinition) => A): A;
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DisplayDataType = exports.GroupRenderType = exports.SyncTextType = exports.DataRenderType = exports.ControlAdornmentType = exports.ExpressionType = exports.DynamicPropertyType = exports.ControlDefinitionType = exports.FieldType = void 0;
|
|
3
|
+
exports.visitControlDefinition = exports.isActionControlsDefinition = exports.isDisplayControlsDefinition = exports.isGroupControlsDefinition = exports.isDataControlDefinition = exports.DisplayDataType = exports.GroupRenderType = exports.SyncTextType = exports.DataRenderType = exports.ControlAdornmentType = exports.ExpressionType = exports.DynamicPropertyType = exports.ControlDefinitionType = exports.FieldType = void 0;
|
|
4
4
|
var FieldType;
|
|
5
5
|
(function (FieldType) {
|
|
6
6
|
FieldType["String"] = "String";
|
|
@@ -66,3 +66,34 @@ var DisplayDataType;
|
|
|
66
66
|
DisplayDataType["Text"] = "Text";
|
|
67
67
|
DisplayDataType["Html"] = "Html";
|
|
68
68
|
})(DisplayDataType = exports.DisplayDataType || (exports.DisplayDataType = {}));
|
|
69
|
+
function isDataControlDefinition(x) {
|
|
70
|
+
return x.type === ControlDefinitionType.Data;
|
|
71
|
+
}
|
|
72
|
+
exports.isDataControlDefinition = isDataControlDefinition;
|
|
73
|
+
function isGroupControlsDefinition(x) {
|
|
74
|
+
return x.type === ControlDefinitionType.Group;
|
|
75
|
+
}
|
|
76
|
+
exports.isGroupControlsDefinition = isGroupControlsDefinition;
|
|
77
|
+
function isDisplayControlsDefinition(x) {
|
|
78
|
+
return x.type === ControlDefinitionType.Display;
|
|
79
|
+
}
|
|
80
|
+
exports.isDisplayControlsDefinition = isDisplayControlsDefinition;
|
|
81
|
+
function isActionControlsDefinition(x) {
|
|
82
|
+
return x.type === ControlDefinitionType.Action;
|
|
83
|
+
}
|
|
84
|
+
exports.isActionControlsDefinition = isActionControlsDefinition;
|
|
85
|
+
function visitControlDefinition(x, visitor, defaultValue) {
|
|
86
|
+
switch (x.type) {
|
|
87
|
+
case ControlDefinitionType.Action:
|
|
88
|
+
return visitor.action(x);
|
|
89
|
+
case ControlDefinitionType.Data:
|
|
90
|
+
return visitor.data(x);
|
|
91
|
+
case ControlDefinitionType.Display:
|
|
92
|
+
return visitor.display(x);
|
|
93
|
+
case ControlDefinitionType.Group:
|
|
94
|
+
return visitor.group(x);
|
|
95
|
+
default:
|
|
96
|
+
return defaultValue(x);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.visitControlDefinition = visitControlDefinition;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
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.102"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.0.22",
|
package/src/controlRender.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
FieldType,
|
|
11
11
|
GroupedControlsDefinition,
|
|
12
12
|
SchemaField,
|
|
13
|
+
visitControlDefinition,
|
|
13
14
|
} from "./types";
|
|
14
15
|
import React, { createContext, Key, ReactElement, useContext } from "react";
|
|
15
16
|
import { Control, newControl } from "@react-typed-forms/core";
|
|
@@ -241,62 +242,61 @@ export function controlTitle(
|
|
|
241
242
|
return title ? title : fieldDisplayName(field);
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
export function renderControl(
|
|
245
|
-
definition:
|
|
245
|
+
export function renderControl<S extends ControlDefinition>(
|
|
246
|
+
definition: S,
|
|
246
247
|
formState: FormEditState,
|
|
247
248
|
hooks: FormEditHooks,
|
|
248
249
|
key: Key,
|
|
249
250
|
wrapChild?: (key: Key, db: ReactElement) => ReactElement
|
|
250
251
|
): ReactElement {
|
|
251
252
|
const { fields } = formState;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
253
|
+
return visitControlDefinition(
|
|
254
|
+
definition,
|
|
255
|
+
{
|
|
256
|
+
data: (def) => {
|
|
257
|
+
const fieldData = findScalarField(fields, def.field);
|
|
258
|
+
if (!fieldData) return <h1>No schema field for: {def.field}</h1>;
|
|
259
|
+
return (
|
|
260
|
+
<DataRenderer
|
|
261
|
+
key={key}
|
|
262
|
+
wrapElem={wrapElem}
|
|
263
|
+
formState={formState}
|
|
264
|
+
hooks={hooks}
|
|
265
|
+
controlDef={def}
|
|
266
|
+
fieldData={fieldData}
|
|
267
|
+
/>
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
group: (d: GroupedControlsDefinition) => (
|
|
269
271
|
<GroupRenderer
|
|
270
272
|
key={key}
|
|
271
273
|
hooks={hooks}
|
|
272
|
-
groupDef={
|
|
274
|
+
groupDef={d}
|
|
273
275
|
formState={formState}
|
|
274
276
|
wrapElem={wrapElem}
|
|
275
277
|
/>
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
<DisplayRenderer
|
|
278
|
+
),
|
|
279
|
+
action: (d: ActionControlDefinition) => (
|
|
280
|
+
<ActionRenderer
|
|
280
281
|
key={key}
|
|
281
282
|
hooks={hooks}
|
|
282
283
|
formState={formState}
|
|
283
284
|
wrapElem={wrapElem}
|
|
284
|
-
|
|
285
|
+
actionDef={d}
|
|
285
286
|
/>
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
<ActionRenderer
|
|
287
|
+
),
|
|
288
|
+
display: (d: DisplayControlDefinition) => (
|
|
289
|
+
<DisplayRenderer
|
|
290
290
|
key={key}
|
|
291
291
|
hooks={hooks}
|
|
292
292
|
formState={formState}
|
|
293
293
|
wrapElem={wrapElem}
|
|
294
|
-
|
|
294
|
+
displayDef={d}
|
|
295
295
|
/>
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
),
|
|
297
|
+
},
|
|
298
|
+
() => <h1>Unknown control: {(definition as any).type}</h1>
|
|
299
|
+
);
|
|
300
300
|
|
|
301
301
|
function wrapElem(e: ReactElement): ReactElement {
|
|
302
302
|
return wrapChild?.(key, e) ?? e;
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DataControlProperties } from "./controlRender";
|
|
2
|
+
|
|
1
3
|
export interface SchemaField {
|
|
2
4
|
type: string;
|
|
3
5
|
field: string;
|
|
@@ -190,7 +192,7 @@ export interface IconSelectionRenderOptions extends RenderOptions {}
|
|
|
190
192
|
|
|
191
193
|
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
192
194
|
type: ControlDefinitionType.Group;
|
|
193
|
-
children:
|
|
195
|
+
children: ControlDefinition[];
|
|
194
196
|
compoundField?: string | null;
|
|
195
197
|
groupOptions: GroupRenderOptions;
|
|
196
198
|
}
|
|
@@ -242,3 +244,53 @@ export interface ActionControlDefinition extends ControlDefinition {
|
|
|
242
244
|
type: ControlDefinitionType.Action;
|
|
243
245
|
actionId: string;
|
|
244
246
|
}
|
|
247
|
+
|
|
248
|
+
export function isDataControlDefinition(
|
|
249
|
+
x: ControlDefinition
|
|
250
|
+
): x is DataControlDefinition {
|
|
251
|
+
return x.type === ControlDefinitionType.Data;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function isGroupControlsDefinition(
|
|
255
|
+
x: ControlDefinition
|
|
256
|
+
): x is GroupedControlsDefinition {
|
|
257
|
+
return x.type === ControlDefinitionType.Group;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function isDisplayControlsDefinition(
|
|
261
|
+
x: ControlDefinition
|
|
262
|
+
): x is DisplayControlDefinition {
|
|
263
|
+
return x.type === ControlDefinitionType.Display;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function isActionControlsDefinition(
|
|
267
|
+
x: ControlDefinition
|
|
268
|
+
): x is ActionControlDefinition {
|
|
269
|
+
return x.type === ControlDefinitionType.Action;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface ControlVisitor<A> {
|
|
273
|
+
data(d: DataControlDefinition): A;
|
|
274
|
+
group(d: GroupedControlsDefinition): A;
|
|
275
|
+
display(d: DisplayControlDefinition): A;
|
|
276
|
+
action(d: ActionControlDefinition): A;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function visitControlDefinition<A>(
|
|
280
|
+
x: ControlDefinition,
|
|
281
|
+
visitor: ControlVisitor<A>,
|
|
282
|
+
defaultValue: (c: ControlDefinition) => A
|
|
283
|
+
): A {
|
|
284
|
+
switch (x.type) {
|
|
285
|
+
case ControlDefinitionType.Action:
|
|
286
|
+
return visitor.action(x as ActionControlDefinition);
|
|
287
|
+
case ControlDefinitionType.Data:
|
|
288
|
+
return visitor.data(x as DataControlDefinition);
|
|
289
|
+
case ControlDefinitionType.Display:
|
|
290
|
+
return visitor.display(x as DisplayControlDefinition);
|
|
291
|
+
case ControlDefinitionType.Group:
|
|
292
|
+
return visitor.group(x as GroupedControlsDefinition);
|
|
293
|
+
default:
|
|
294
|
+
return defaultValue(x);
|
|
295
|
+
}
|
|
296
|
+
}
|