@react-typed-forms/schemas 3.0.0-dev.81 → 3.0.0-dev.82
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 +5 -5
- package/lib/controlRender.d.ts +2 -1
- package/lib/controlRender.js +20 -7
- package/lib/hooks.js +11 -5
- package/lib/schemaBuilder.d.ts +3 -3
- package/lib/schemaBuilder.js +1 -0
- package/lib/types.d.ts +4 -4
- package/package.json +2 -2
- package/schemas.build.log +0 -2
- package/src/controlRender.tsx +19 -10
- package/src/hooks.ts +15 -6
- package/src/schemaBuilder.ts +1 -0
- package/src/types.ts +5 -7
|
@@ -1,12 +1,12 @@
|
|
|
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": "
|
|
6
|
-
"packages/schemas/src/hooks.ts": "
|
|
4
|
+
"packages/schemas/package.json": "30089b42ee97d4ff79f147c02a8ddf0592ab48e3",
|
|
5
|
+
"packages/schemas/src/controlRender.tsx": "4bd6de1b15f9b75163358ef2b91d2e2fb9ca6f6b",
|
|
6
|
+
"packages/schemas/src/hooks.ts": "a34545b7c63dc78ea77974f6c2fc386daaee80ea",
|
|
7
7
|
"packages/schemas/src/index.ts": "b15fbb6de132cd912cf8141d5c4d2329e947546e",
|
|
8
|
-
"packages/schemas/src/schemaBuilder.ts": "
|
|
9
|
-
"packages/schemas/src/types.ts": "
|
|
8
|
+
"packages/schemas/src/schemaBuilder.ts": "4662698fd46ac14459f429ce24d919ef91992de2",
|
|
9
|
+
"packages/schemas/src/types.ts": "0f55d35f7e4b052a01bc433799647d8288e237ab",
|
|
10
10
|
"packages/schemas/tsconfig.json": "52e4f044fa580f4e0ad5830f3cfca574e2788372"
|
|
11
11
|
},
|
|
12
12
|
"arguments": "rimraf ./lib/ && tsc "
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -81,7 +81,8 @@ export declare function applyDefaultValues(v: {
|
|
|
81
81
|
} | undefined, fields: SchemaField[]): any;
|
|
82
82
|
export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean): any;
|
|
83
83
|
export declare function defaultValueForFields(fields: SchemaField[]): any;
|
|
84
|
-
export declare function defaultValueForField(sf: SchemaField
|
|
84
|
+
export declare function defaultValueForField(sf: SchemaField): any;
|
|
85
|
+
export declare function elementValueForField(sf: SchemaField): any;
|
|
85
86
|
export declare function findScalarField(fields: SchemaField[], field: string): ScalarField | undefined;
|
|
86
87
|
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
87
88
|
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
package/lib/controlRender.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isGroupControl = exports.isSchemaControl = exports.fieldForControl = exports.controlForField = exports.renderControl = exports.controlTitle = exports.fieldDisplayName = exports.findField = exports.findCompoundField = exports.findScalarField = exports.defaultValueForField = exports.defaultValueForFields = exports.applyDefaultForField = exports.applyDefaultValues = exports.isCompoundField = exports.isScalarField = exports.useFormRendererComponents = exports.FormRendererComponentsContext = void 0;
|
|
26
|
+
exports.isGroupControl = exports.isSchemaControl = exports.fieldForControl = exports.controlForField = exports.renderControl = exports.controlTitle = exports.fieldDisplayName = exports.findField = exports.findCompoundField = exports.findScalarField = exports.elementValueForField = exports.defaultValueForField = exports.defaultValueForFields = exports.applyDefaultForField = exports.applyDefaultValues = exports.isCompoundField = exports.isScalarField = exports.useFormRendererComponents = exports.FormRendererComponentsContext = void 0;
|
|
27
27
|
const types_1 = require("./types");
|
|
28
28
|
const react_1 = __importStar(require("react"));
|
|
29
29
|
const core_1 = require("@react-typed-forms/core");
|
|
@@ -55,7 +55,7 @@ function applyDefaultValues(v, fields) {
|
|
|
55
55
|
out[x.field] =
|
|
56
56
|
x.field in v
|
|
57
57
|
? applyDefaultForField(v[x.field], x, fields)
|
|
58
|
-
: defaultValueForField(x
|
|
58
|
+
: defaultValueForField(x);
|
|
59
59
|
});
|
|
60
60
|
return out;
|
|
61
61
|
}
|
|
@@ -66,24 +66,37 @@ function applyDefaultForField(v, field, parent, notElement) {
|
|
|
66
66
|
return ((_a = v) !== null && _a !== void 0 ? _a : []).map((x) => applyDefaultForField(x, field, parent, true));
|
|
67
67
|
}
|
|
68
68
|
if (isCompoundField(field)) {
|
|
69
|
+
if (!v && !field.required)
|
|
70
|
+
return v;
|
|
69
71
|
return applyDefaultValues(v, field.treeChildren ? parent : field.children);
|
|
70
72
|
}
|
|
71
|
-
return defaultValueForField(field
|
|
73
|
+
return defaultValueForField(field);
|
|
72
74
|
}
|
|
73
75
|
exports.applyDefaultForField = applyDefaultForField;
|
|
74
76
|
function defaultValueForFields(fields) {
|
|
75
|
-
return Object.fromEntries(fields.map((x) => [x.field, defaultValueForField(x
|
|
77
|
+
return Object.fromEntries(fields.map((x) => [x.field, defaultValueForField(x)]));
|
|
76
78
|
}
|
|
77
79
|
exports.defaultValueForFields = defaultValueForFields;
|
|
78
|
-
function defaultValueForField(sf
|
|
79
|
-
if (
|
|
80
|
+
function defaultValueForField(sf) {
|
|
81
|
+
if (isCompoundField(sf)) {
|
|
82
|
+
return sf.required
|
|
83
|
+
? sf.collection
|
|
84
|
+
? []
|
|
85
|
+
: defaultValueForFields(sf.children)
|
|
86
|
+
: undefined;
|
|
87
|
+
}
|
|
88
|
+
if (sf.collection)
|
|
80
89
|
return [];
|
|
90
|
+
return sf.defaultValue;
|
|
91
|
+
}
|
|
92
|
+
exports.defaultValueForField = defaultValueForField;
|
|
93
|
+
function elementValueForField(sf) {
|
|
81
94
|
if (isCompoundField(sf)) {
|
|
82
95
|
return defaultValueForFields(sf.children);
|
|
83
96
|
}
|
|
84
97
|
return sf.defaultValue;
|
|
85
98
|
}
|
|
86
|
-
exports.
|
|
99
|
+
exports.elementValueForField = elementValueForField;
|
|
87
100
|
function findScalarField(fields, field) {
|
|
88
101
|
return findField(fields, field);
|
|
89
102
|
}
|
package/lib/hooks.js
CHANGED
|
@@ -21,16 +21,22 @@ function useIsControlVisible(definition, formState, useExpression) {
|
|
|
21
21
|
return Boolean(useExpression(visibleExpression.expr, formState));
|
|
22
22
|
}
|
|
23
23
|
const schemaFields = formState.fields;
|
|
24
|
-
const typeControl = (0, react_1.useMemo)(() => {
|
|
24
|
+
const { typeControl, compoundField } = (0, react_1.useMemo)(() => {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const typeField = schemaFields.find((x) => (0, controlRender_1.isScalarField)(x) && x.isTypeField);
|
|
27
|
-
|
|
27
|
+
const typeControl = ((_b = (typeField &&
|
|
28
|
+
((_a = formState.data.fields) === null || _a === void 0 ? void 0 : _a[typeField.field]))) !== null && _b !== void 0 ? _b : (0, core_1.newControl)(undefined));
|
|
29
|
+
const compoundField = (0, controlRender_1.isGroupControl)(definition) && definition.compoundField
|
|
30
|
+
? formState.data.fields[definition.compoundField]
|
|
31
|
+
: undefined;
|
|
32
|
+
return { typeControl, compoundField };
|
|
28
33
|
}, [schemaFields, formState.data]);
|
|
29
34
|
const fieldName = (0, controlRender_1.fieldForControl)(definition);
|
|
30
35
|
const onlyForTypes = (_b = (fieldName ? (0, controlRender_1.findField)(schemaFields, fieldName) : undefined)) === null || _b === void 0 ? void 0 : _b.onlyForTypes;
|
|
31
|
-
return (0, core_1.useControlValue)(() => !
|
|
32
|
-
onlyForTypes
|
|
33
|
-
|
|
36
|
+
return (0, core_1.useControlValue)(() => (!compoundField || compoundField.value != null) &&
|
|
37
|
+
(!onlyForTypes ||
|
|
38
|
+
onlyForTypes.length === 0 ||
|
|
39
|
+
Boolean(typeControl.value && onlyForTypes.includes(typeControl.value))));
|
|
34
40
|
}
|
|
35
41
|
exports.useIsControlVisible = useIsControlVisible;
|
|
36
42
|
function getDefaultScalarControlProperties(control, field, visible, defaultValue, readonly) {
|
package/lib/schemaBuilder.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export declare function stringField(displayName: string, options?: Partial<Omit<
|
|
|
29
29
|
system?: boolean | undefined;
|
|
30
30
|
collection?: boolean | undefined;
|
|
31
31
|
onlyForTypes?: string[] | undefined;
|
|
32
|
-
entityRefType?: string | undefined;
|
|
33
32
|
required?: boolean | undefined;
|
|
33
|
+
entityRefType?: string | undefined;
|
|
34
34
|
parentField?: string | undefined;
|
|
35
35
|
searchable?: boolean | undefined;
|
|
36
36
|
defaultValue?: any;
|
|
@@ -64,8 +64,8 @@ export declare function intField(displayName: string, options?: Partial<Omit<Sca
|
|
|
64
64
|
system?: boolean | undefined;
|
|
65
65
|
collection?: boolean | undefined;
|
|
66
66
|
onlyForTypes?: string[] | undefined;
|
|
67
|
-
entityRefType?: string | undefined;
|
|
68
67
|
required?: boolean | undefined;
|
|
68
|
+
entityRefType?: string | undefined;
|
|
69
69
|
parentField?: string | undefined;
|
|
70
70
|
searchable?: boolean | undefined;
|
|
71
71
|
defaultValue?: any;
|
|
@@ -82,8 +82,8 @@ export declare function boolField(displayName: string, options?: Partial<Omit<Sc
|
|
|
82
82
|
system?: boolean | undefined;
|
|
83
83
|
collection?: boolean | undefined;
|
|
84
84
|
onlyForTypes?: string[] | undefined;
|
|
85
|
-
entityRefType?: string | undefined;
|
|
86
85
|
required?: boolean | undefined;
|
|
86
|
+
entityRefType?: string | undefined;
|
|
87
87
|
parentField?: string | undefined;
|
|
88
88
|
searchable?: boolean | undefined;
|
|
89
89
|
defaultValue?: any;
|
package/lib/schemaBuilder.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface SchemaField {
|
|
|
7
7
|
system: boolean;
|
|
8
8
|
collection: boolean;
|
|
9
9
|
onlyForTypes: string[];
|
|
10
|
+
required: boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare enum SchemaFieldType {
|
|
12
13
|
Scalar = "Scalar",
|
|
@@ -26,7 +27,6 @@ export declare enum FieldType {
|
|
|
26
27
|
}
|
|
27
28
|
export interface ScalarField extends SchemaField {
|
|
28
29
|
entityRefType: string;
|
|
29
|
-
required: boolean;
|
|
30
30
|
parentField: string;
|
|
31
31
|
searchable: boolean;
|
|
32
32
|
defaultValue: any;
|
|
@@ -44,7 +44,7 @@ export interface CompoundField extends SchemaField {
|
|
|
44
44
|
children: SchemaField[];
|
|
45
45
|
treeChildren: boolean;
|
|
46
46
|
}
|
|
47
|
-
export type AnyControlDefinition =
|
|
47
|
+
export type AnyControlDefinition = DataControlDefinition | GroupedControlsDefinition | ActionControlDefinition | DisplayControlDefinition;
|
|
48
48
|
export interface ControlDefinition {
|
|
49
49
|
type: string;
|
|
50
50
|
title?: string;
|
|
@@ -156,12 +156,12 @@ export interface IconSelectionRenderOptions extends RenderOptions {
|
|
|
156
156
|
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
157
157
|
type: ControlDefinitionType.Group;
|
|
158
158
|
children: AnyControlDefinition[];
|
|
159
|
-
compoundField
|
|
159
|
+
compoundField?: string;
|
|
160
160
|
groupOptions: GroupRenderOptions;
|
|
161
161
|
}
|
|
162
162
|
export interface GroupRenderOptions {
|
|
163
163
|
type: GroupRenderType;
|
|
164
|
-
hideTitle
|
|
164
|
+
hideTitle?: boolean;
|
|
165
165
|
}
|
|
166
166
|
export declare enum GroupRenderType {
|
|
167
167
|
Standard = "Standard",
|
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.82",
|
|
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.82"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.0.22",
|
package/schemas.build.log
CHANGED
package/src/controlRender.tsx
CHANGED
|
@@ -175,7 +175,7 @@ export function applyDefaultValues(
|
|
|
175
175
|
out[x.field] =
|
|
176
176
|
x.field in v
|
|
177
177
|
? applyDefaultForField(v[x.field], x, fields)
|
|
178
|
-
: defaultValueForField(x
|
|
178
|
+
: defaultValueForField(x);
|
|
179
179
|
});
|
|
180
180
|
return out;
|
|
181
181
|
}
|
|
@@ -192,22 +192,31 @@ export function applyDefaultForField(
|
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
if (isCompoundField(field)) {
|
|
195
|
+
if (!v && !field.required) return v;
|
|
195
196
|
return applyDefaultValues(v, field.treeChildren ? parent : field.children);
|
|
196
197
|
}
|
|
197
|
-
return defaultValueForField(field
|
|
198
|
+
return defaultValueForField(field);
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
export function defaultValueForFields(fields: SchemaField[]): any {
|
|
201
202
|
return Object.fromEntries(
|
|
202
|
-
fields.map((x) => [x.field, defaultValueForField(x
|
|
203
|
+
fields.map((x) => [x.field, defaultValueForField(x)])
|
|
203
204
|
);
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
export function defaultValueForField(
|
|
207
|
-
sf
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
export function defaultValueForField(sf: SchemaField): any {
|
|
208
|
+
if (isCompoundField(sf)) {
|
|
209
|
+
return sf.required
|
|
210
|
+
? sf.collection
|
|
211
|
+
? []
|
|
212
|
+
: defaultValueForFields(sf.children)
|
|
213
|
+
: undefined;
|
|
214
|
+
}
|
|
215
|
+
if (sf.collection) return [];
|
|
216
|
+
return (sf as ScalarField).defaultValue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function elementValueForField(sf: SchemaField): any {
|
|
211
220
|
if (isCompoundField(sf)) {
|
|
212
221
|
return defaultValueForFields(sf.children);
|
|
213
222
|
}
|
|
@@ -297,7 +306,7 @@ export function renderControl(
|
|
|
297
306
|
/>
|
|
298
307
|
);
|
|
299
308
|
default:
|
|
300
|
-
return <h1>Unknown control: {definition.type}</h1>;
|
|
309
|
+
return <h1>Unknown control: {(definition as any).type}</h1>;
|
|
301
310
|
}
|
|
302
311
|
|
|
303
312
|
function wrapElem(e: ReactElement): ReactElement {
|
|
@@ -406,7 +415,7 @@ function GroupRenderer({
|
|
|
406
415
|
properties: groupProps,
|
|
407
416
|
renderChild: (k, c, data, wrapChild) =>
|
|
408
417
|
renderControl(
|
|
409
|
-
c,
|
|
418
|
+
c as AnyControlDefinition,
|
|
410
419
|
{
|
|
411
420
|
...formState,
|
|
412
421
|
fields: compoundField!.children,
|
package/src/hooks.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
findField,
|
|
18
18
|
FormEditHooks,
|
|
19
19
|
FormEditState,
|
|
20
|
+
isGroupControl,
|
|
20
21
|
isScalarField,
|
|
21
22
|
} from "./controlRender";
|
|
22
23
|
import { useMemo } from "react";
|
|
@@ -54,26 +55,34 @@ export function useIsControlVisible(
|
|
|
54
55
|
}
|
|
55
56
|
const schemaFields = formState.fields;
|
|
56
57
|
|
|
57
|
-
const typeControl = useMemo(() => {
|
|
58
|
+
const { typeControl, compoundField } = useMemo(() => {
|
|
58
59
|
const typeField = schemaFields.find(
|
|
59
60
|
(x) => isScalarField(x) && x.isTypeField
|
|
60
61
|
) as ScalarField | undefined;
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
const typeControl = ((typeField &&
|
|
64
|
+
formState.data.fields?.[typeField.field]) ??
|
|
62
65
|
newControl(undefined)) as Control<string | undefined>;
|
|
66
|
+
const compoundField =
|
|
67
|
+
isGroupControl(definition) && definition.compoundField
|
|
68
|
+
? formState.data.fields[definition.compoundField]
|
|
69
|
+
: undefined;
|
|
70
|
+
return { typeControl, compoundField };
|
|
63
71
|
}, [schemaFields, formState.data]);
|
|
64
72
|
|
|
65
73
|
const fieldName = fieldForControl(definition);
|
|
66
74
|
const onlyForTypes = (
|
|
67
75
|
fieldName ? findField(schemaFields, fieldName) : undefined
|
|
68
76
|
)?.onlyForTypes;
|
|
77
|
+
|
|
69
78
|
return useControlValue(
|
|
70
79
|
() =>
|
|
71
|
-
!
|
|
72
|
-
onlyForTypes
|
|
73
|
-
|
|
80
|
+
(!compoundField || compoundField.value != null) &&
|
|
81
|
+
(!onlyForTypes ||
|
|
82
|
+
onlyForTypes.length === 0 ||
|
|
83
|
+
Boolean(typeControl.value && onlyForTypes.includes(typeControl.value)))
|
|
74
84
|
);
|
|
75
85
|
}
|
|
76
|
-
|
|
77
86
|
export function getDefaultScalarControlProperties(
|
|
78
87
|
control: DataControlDefinition,
|
|
79
88
|
field: ScalarField,
|
package/src/schemaBuilder.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface SchemaField {
|
|
|
7
7
|
system: boolean;
|
|
8
8
|
collection: boolean;
|
|
9
9
|
onlyForTypes: string[];
|
|
10
|
+
required: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export enum SchemaFieldType {
|
|
@@ -29,7 +30,6 @@ export enum FieldType {
|
|
|
29
30
|
|
|
30
31
|
export interface ScalarField extends SchemaField {
|
|
31
32
|
entityRefType: string;
|
|
32
|
-
required: boolean;
|
|
33
33
|
parentField: string;
|
|
34
34
|
searchable: boolean;
|
|
35
35
|
defaultValue: any;
|
|
@@ -52,7 +52,6 @@ export interface CompoundField extends SchemaField {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export type AnyControlDefinition =
|
|
55
|
-
| ControlDefinition
|
|
56
55
|
| DataControlDefinition
|
|
57
56
|
| GroupedControlsDefinition
|
|
58
57
|
| ActionControlDefinition
|
|
@@ -145,8 +144,8 @@ export enum DataRenderType {
|
|
|
145
144
|
UserSelection = "UserSelection",
|
|
146
145
|
Synchronised = "Synchronised",
|
|
147
146
|
IconSelector = "IconSelector",
|
|
148
|
-
|
|
149
|
-
DateTime = "DateTime"
|
|
147
|
+
|
|
148
|
+
DateTime = "DateTime",
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
export interface RadioButtonRenderOptions extends RenderOptions {}
|
|
@@ -172,7 +171,6 @@ export interface IconMapping {
|
|
|
172
171
|
|
|
173
172
|
export interface CheckListRenderOptions extends RenderOptions {}
|
|
174
173
|
|
|
175
|
-
|
|
176
174
|
export interface SynchronisedRenderOptions extends RenderOptions {
|
|
177
175
|
fieldToSync: string;
|
|
178
176
|
syncType: SyncTextType;
|
|
@@ -194,13 +192,13 @@ export interface IconSelectionRenderOptions extends RenderOptions {}
|
|
|
194
192
|
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
195
193
|
type: ControlDefinitionType.Group;
|
|
196
194
|
children: AnyControlDefinition[];
|
|
197
|
-
compoundField
|
|
195
|
+
compoundField?: string;
|
|
198
196
|
groupOptions: GroupRenderOptions;
|
|
199
197
|
}
|
|
200
198
|
|
|
201
199
|
export interface GroupRenderOptions {
|
|
202
200
|
type: GroupRenderType;
|
|
203
|
-
hideTitle
|
|
201
|
+
hideTitle?: boolean;
|
|
204
202
|
}
|
|
205
203
|
|
|
206
204
|
export enum GroupRenderType {
|