@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/.babelrc +4 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/operation/update-readme/state.json +3 -0
- package/.rush/temp/package-deps_build.json +7 -7
- package/.rush/temp/shrinkwrap-deps.json +581 -7
- package/README.md +292 -0
- package/lib/controlBuilder.d.ts +14 -0
- package/lib/controlRender.d.ts +97 -80
- package/lib/hooks.d.ts +9 -9
- package/lib/index.d.ts +5 -1
- package/lib/index.js +1836 -19
- package/lib/index.js.map +1 -0
- package/lib/renderers.d.ts +171 -0
- package/lib/schemaBuilder.d.ts +53 -70
- package/lib/tailwind.d.ts +2 -0
- package/lib/types.d.ts +108 -43
- package/lib/util.d.ts +35 -0
- package/lib/validators.d.ts +4 -0
- package/package.json +15 -8
- package/src/controlBuilder.ts +121 -0
- package/src/controlRender.tsx +535 -437
- package/src/hooks.tsx +153 -0
- package/src/index.ts +5 -1
- package/src/renderers.tsx +846 -0
- package/src/schemaBuilder.ts +45 -66
- package/src/tailwind.tsx +25 -0
- package/src/types.ts +164 -48
- package/src/util.ts +360 -0
- package/src/validators.ts +116 -0
- package/tsconfig.json +4 -3
- package/lib/controlRender.js +0 -230
- package/lib/hooks.js +0 -93
- package/lib/schemaBuilder.js +0 -82
- package/lib/types.js +0 -73
- package/schemas.build.log +0 -2
- package/src/hooks.ts +0 -167
package/lib/schemaBuilder.d.ts
CHANGED
|
@@ -1,107 +1,90 @@
|
|
|
1
|
-
import { CompoundField, FieldOption, FieldType,
|
|
2
|
-
type AllowedSchema<T> = T extends string ?
|
|
3
|
-
schemaType: SchemaFieldType.Scalar;
|
|
1
|
+
import { CompoundField, FieldOption, FieldType, SchemaField } from "./types";
|
|
2
|
+
type AllowedSchema<T> = T extends string ? SchemaField & {
|
|
4
3
|
type: FieldType.String | FieldType.Date | FieldType.DateTime;
|
|
5
|
-
} : T extends number ?
|
|
6
|
-
schemaType: SchemaFieldType.Scalar;
|
|
4
|
+
} : T extends number ? SchemaField & {
|
|
7
5
|
type: FieldType.Int | FieldType.Double;
|
|
8
|
-
} : T extends boolean ?
|
|
9
|
-
schemaType: SchemaFieldType.Scalar;
|
|
6
|
+
} : T extends boolean ? SchemaField & {
|
|
10
7
|
type: FieldType.Bool;
|
|
11
8
|
} : T extends Array<infer E> ? AllowedSchema<E> & {
|
|
12
9
|
collection: true;
|
|
13
10
|
} : T extends {
|
|
14
11
|
[key: string]: any;
|
|
15
12
|
} ? CompoundField & {
|
|
16
|
-
schemaType: SchemaFieldType.Compound;
|
|
17
13
|
type: FieldType.Compound;
|
|
18
|
-
} :
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
} : SchemaField & {
|
|
15
|
+
type: FieldType.Any;
|
|
16
|
+
};
|
|
17
|
+
type AllowedField<T, K> = (name: string) => (SchemaField & {
|
|
18
|
+
type: K;
|
|
19
|
+
}) | AllowedSchema<T>;
|
|
20
|
+
export declare function buildSchema<T, Custom = "">(def: {
|
|
21
|
+
[K in keyof T]-?: AllowedField<T[K], Custom>;
|
|
22
22
|
}): SchemaField[];
|
|
23
|
-
export declare function stringField(displayName: string, options?: Partial<Omit<
|
|
24
|
-
schemaType: SchemaFieldType.Scalar;
|
|
25
|
-
} & {
|
|
23
|
+
export declare function stringField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
26
24
|
field?: string | undefined;
|
|
27
|
-
displayName: string;
|
|
28
|
-
tags?: string[] | undefined;
|
|
29
|
-
system?: boolean | undefined;
|
|
30
|
-
collection?: boolean | undefined;
|
|
31
|
-
onlyForTypes?: string[] | undefined;
|
|
32
|
-
required?: boolean | undefined;
|
|
33
|
-
|
|
34
|
-
parentField?: string | undefined;
|
|
35
|
-
searchable?: boolean | undefined;
|
|
25
|
+
displayName: string | null;
|
|
26
|
+
tags?: string[] | null | undefined;
|
|
27
|
+
system?: boolean | null | undefined;
|
|
28
|
+
collection?: boolean | null | undefined;
|
|
29
|
+
onlyForTypes?: string[] | null | undefined;
|
|
30
|
+
required?: boolean | null | undefined;
|
|
31
|
+
notNullable?: boolean | null | undefined;
|
|
36
32
|
defaultValue?: any;
|
|
37
|
-
isTypeField?: boolean | undefined;
|
|
38
|
-
|
|
33
|
+
isTypeField?: boolean | null | undefined;
|
|
34
|
+
searchable?: boolean | null | undefined;
|
|
35
|
+
options?: FieldOption[] | null | undefined;
|
|
36
|
+
validators?: import("./types").SchemaValidator[] | null | undefined;
|
|
39
37
|
type: FieldType.String;
|
|
40
38
|
};
|
|
41
|
-
export declare function stringOptionsField(displayName: string, ...options: FieldOption[]): (name: string) =>
|
|
42
|
-
schemaType: SchemaFieldType.Scalar;
|
|
43
|
-
} & {
|
|
39
|
+
export declare function stringOptionsField(displayName: string, ...options: FieldOption[]): (name: string) => SchemaField & {
|
|
44
40
|
type: FieldType.String;
|
|
45
41
|
displayName: string;
|
|
46
|
-
|
|
47
|
-
options: FieldOption[];
|
|
48
|
-
};
|
|
42
|
+
options: FieldOption[];
|
|
49
43
|
};
|
|
50
|
-
export declare function withScalarOptions<S extends
|
|
51
|
-
export declare function makeScalarField<S extends Partial<
|
|
52
|
-
schemaType: SchemaFieldType.Scalar;
|
|
53
|
-
} & S;
|
|
44
|
+
export declare function withScalarOptions<S extends SchemaField>(options: Partial<SchemaField>, v: (name: string) => S): (name: string) => S;
|
|
45
|
+
export declare function makeScalarField<S extends Partial<SchemaField>>(options: S): (name: string) => SchemaField & S;
|
|
54
46
|
export declare function makeCompoundField<S extends Partial<CompoundField>>(options: S): (name: string) => CompoundField & {
|
|
55
|
-
schemaType: SchemaFieldType.Compound;
|
|
56
47
|
type: FieldType.Compound;
|
|
57
48
|
} & S;
|
|
58
|
-
export declare function intField(displayName: string, options?: Partial<Omit<
|
|
59
|
-
schemaType: SchemaFieldType.Scalar;
|
|
60
|
-
} & {
|
|
49
|
+
export declare function intField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
61
50
|
field?: string | undefined;
|
|
62
|
-
displayName: string;
|
|
63
|
-
tags?: string[] | undefined;
|
|
64
|
-
system?: boolean | undefined;
|
|
65
|
-
collection?: boolean | undefined;
|
|
66
|
-
onlyForTypes?: string[] | undefined;
|
|
67
|
-
required?: boolean | undefined;
|
|
68
|
-
|
|
69
|
-
parentField?: string | undefined;
|
|
70
|
-
searchable?: boolean | undefined;
|
|
51
|
+
displayName: string | null;
|
|
52
|
+
tags?: string[] | null | undefined;
|
|
53
|
+
system?: boolean | null | undefined;
|
|
54
|
+
collection?: boolean | null | undefined;
|
|
55
|
+
onlyForTypes?: string[] | null | undefined;
|
|
56
|
+
required?: boolean | null | undefined;
|
|
57
|
+
notNullable?: boolean | null | undefined;
|
|
71
58
|
defaultValue?: any;
|
|
72
|
-
isTypeField?: boolean | undefined;
|
|
73
|
-
|
|
59
|
+
isTypeField?: boolean | null | undefined;
|
|
60
|
+
searchable?: boolean | null | undefined;
|
|
61
|
+
options?: FieldOption[] | null | undefined;
|
|
62
|
+
validators?: import("./types").SchemaValidator[] | null | undefined;
|
|
74
63
|
type: FieldType.Int;
|
|
75
64
|
};
|
|
76
|
-
export declare function boolField(displayName: string, options?: Partial<Omit<
|
|
77
|
-
schemaType: SchemaFieldType.Scalar;
|
|
78
|
-
} & {
|
|
65
|
+
export declare function boolField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
79
66
|
field?: string | undefined;
|
|
80
|
-
displayName: string;
|
|
81
|
-
tags?: string[] | undefined;
|
|
82
|
-
system?: boolean | undefined;
|
|
83
|
-
collection?: boolean | undefined;
|
|
84
|
-
onlyForTypes?: string[] | undefined;
|
|
85
|
-
required?: boolean | undefined;
|
|
86
|
-
|
|
87
|
-
parentField?: string | undefined;
|
|
88
|
-
searchable?: boolean | undefined;
|
|
67
|
+
displayName: string | null;
|
|
68
|
+
tags?: string[] | null | undefined;
|
|
69
|
+
system?: boolean | null | undefined;
|
|
70
|
+
collection?: boolean | null | undefined;
|
|
71
|
+
onlyForTypes?: string[] | null | undefined;
|
|
72
|
+
required?: boolean | null | undefined;
|
|
73
|
+
notNullable?: boolean | null | undefined;
|
|
89
74
|
defaultValue?: any;
|
|
90
|
-
isTypeField?: boolean | undefined;
|
|
91
|
-
|
|
75
|
+
isTypeField?: boolean | null | undefined;
|
|
76
|
+
searchable?: boolean | null | undefined;
|
|
77
|
+
options?: FieldOption[] | null | undefined;
|
|
78
|
+
validators?: import("./types").SchemaValidator[] | null | undefined;
|
|
92
79
|
type: FieldType.Bool;
|
|
93
80
|
};
|
|
94
81
|
export declare function compoundField<Other extends Partial<Omit<CompoundField, "type" | "schemaType">>>(displayName: string, fields: SchemaField[], other: Other): (name: string) => CompoundField & {
|
|
95
|
-
schemaType: SchemaFieldType.Compound;
|
|
96
|
-
type: FieldType.Compound;
|
|
97
82
|
collection: Other["collection"];
|
|
98
83
|
};
|
|
99
|
-
export declare function defaultScalarField(field: string, displayName: string):
|
|
100
|
-
schemaType: SchemaFieldType.Scalar;
|
|
84
|
+
export declare function defaultScalarField(field: string, displayName: string): Omit<SchemaField, "type"> & {
|
|
101
85
|
type: FieldType.String;
|
|
102
86
|
};
|
|
103
87
|
export declare function defaultCompoundField(field: string, displayName: string, collection: boolean): CompoundField & {
|
|
104
88
|
type: FieldType.Compound;
|
|
105
|
-
schemaType: SchemaFieldType.Compound;
|
|
106
89
|
};
|
|
107
90
|
export {};
|
package/lib/types.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
export interface SchemaField {
|
|
2
|
-
|
|
2
|
+
type: string;
|
|
3
3
|
field: string;
|
|
4
|
-
displayName
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
displayName?: string | null;
|
|
5
|
+
tags?: string[] | null;
|
|
6
|
+
system?: boolean | null;
|
|
7
|
+
collection?: boolean | null;
|
|
8
|
+
onlyForTypes?: string[] | null;
|
|
9
|
+
required?: boolean | null;
|
|
10
|
+
notNullable?: boolean | null;
|
|
11
|
+
defaultValue?: any;
|
|
12
|
+
isTypeField?: boolean | null;
|
|
13
|
+
searchable?: boolean | null;
|
|
14
|
+
options?: FieldOption[] | null;
|
|
15
|
+
validators?: SchemaValidator[] | null;
|
|
15
16
|
}
|
|
16
17
|
export declare enum FieldType {
|
|
17
18
|
String = "String",
|
|
@@ -23,33 +24,30 @@ export declare enum FieldType {
|
|
|
23
24
|
EntityRef = "EntityRef",
|
|
24
25
|
Compound = "Compound",
|
|
25
26
|
AutoId = "AutoId",
|
|
26
|
-
Image = "Image"
|
|
27
|
+
Image = "Image",
|
|
28
|
+
Any = "Any"
|
|
27
29
|
}
|
|
28
|
-
export interface
|
|
30
|
+
export interface EntityRefField extends SchemaField {
|
|
31
|
+
type: FieldType.EntityRef;
|
|
29
32
|
entityRefType: string;
|
|
30
33
|
parentField: string;
|
|
31
|
-
searchable: boolean;
|
|
32
|
-
defaultValue: any;
|
|
33
|
-
isTypeField: boolean;
|
|
34
|
-
restrictions: SchemaRestrictions | undefined;
|
|
35
|
-
}
|
|
36
|
-
export interface SchemaRestrictions {
|
|
37
|
-
options: FieldOption[] | undefined;
|
|
38
34
|
}
|
|
39
35
|
export interface FieldOption {
|
|
40
36
|
name: string;
|
|
41
37
|
value: any;
|
|
42
38
|
}
|
|
43
39
|
export interface CompoundField extends SchemaField {
|
|
40
|
+
type: FieldType.Compound;
|
|
44
41
|
children: SchemaField[];
|
|
45
|
-
treeChildren
|
|
42
|
+
treeChildren?: boolean;
|
|
46
43
|
}
|
|
47
44
|
export type AnyControlDefinition = DataControlDefinition | GroupedControlsDefinition | ActionControlDefinition | DisplayControlDefinition;
|
|
48
45
|
export interface ControlDefinition {
|
|
49
46
|
type: string;
|
|
50
|
-
title?: string;
|
|
51
|
-
dynamic?: DynamicProperty[];
|
|
52
|
-
adornments?: ControlAdornment[];
|
|
47
|
+
title?: string | null;
|
|
48
|
+
dynamic?: DynamicProperty[] | null;
|
|
49
|
+
adornments?: ControlAdornment[] | null;
|
|
50
|
+
children?: ControlDefinition[] | null;
|
|
53
51
|
}
|
|
54
52
|
export declare enum ControlDefinitionType {
|
|
55
53
|
Data = "Data",
|
|
@@ -58,7 +56,7 @@ export declare enum ControlDefinitionType {
|
|
|
58
56
|
Action = "Action"
|
|
59
57
|
}
|
|
60
58
|
export interface DynamicProperty {
|
|
61
|
-
type:
|
|
59
|
+
type: string;
|
|
62
60
|
expr: EntityExpression;
|
|
63
61
|
}
|
|
64
62
|
export declare enum DynamicPropertyType {
|
|
@@ -66,7 +64,7 @@ export declare enum DynamicPropertyType {
|
|
|
66
64
|
DefaultValue = "DefaultValue"
|
|
67
65
|
}
|
|
68
66
|
export interface EntityExpression {
|
|
69
|
-
type:
|
|
67
|
+
type: string;
|
|
70
68
|
}
|
|
71
69
|
export declare enum ExpressionType {
|
|
72
70
|
Jsonata = "Jsonata",
|
|
@@ -74,39 +72,58 @@ export declare enum ExpressionType {
|
|
|
74
72
|
UserMatch = "UserMatch"
|
|
75
73
|
}
|
|
76
74
|
export interface JsonataExpression extends EntityExpression {
|
|
75
|
+
type: ExpressionType.Jsonata;
|
|
77
76
|
expression: string;
|
|
78
77
|
}
|
|
79
78
|
export interface FieldValueExpression extends EntityExpression {
|
|
79
|
+
type: ExpressionType.FieldValue;
|
|
80
80
|
field: string;
|
|
81
81
|
value: any;
|
|
82
82
|
}
|
|
83
83
|
export interface UserMatchExpression extends EntityExpression {
|
|
84
|
+
type: ExpressionType.UserMatch;
|
|
84
85
|
userMatch: string;
|
|
85
86
|
}
|
|
86
87
|
export interface ControlAdornment {
|
|
87
|
-
type:
|
|
88
|
+
type: string;
|
|
89
|
+
}
|
|
90
|
+
export declare enum AdornmentPlacement {
|
|
91
|
+
ControlStart = "ControlStart",
|
|
92
|
+
ControlEnd = "ControlEnd",
|
|
93
|
+
LabelStart = "LabelStart",
|
|
94
|
+
LabelEnd = "LabelEnd"
|
|
88
95
|
}
|
|
89
96
|
export declare enum ControlAdornmentType {
|
|
90
97
|
Tooltip = "Tooltip",
|
|
91
|
-
Accordion = "Accordion"
|
|
98
|
+
Accordion = "Accordion",
|
|
99
|
+
HelpText = "HelpText"
|
|
92
100
|
}
|
|
93
101
|
export interface TooltipAdornment extends ControlAdornment {
|
|
102
|
+
type: ControlAdornmentType.Tooltip;
|
|
94
103
|
tooltip: string;
|
|
95
104
|
}
|
|
96
105
|
export interface AccordionAdornment extends ControlAdornment {
|
|
106
|
+
type: ControlAdornmentType.Accordion;
|
|
97
107
|
title: string;
|
|
98
108
|
defaultExpanded: boolean;
|
|
99
109
|
}
|
|
110
|
+
export interface HelpTextAdornment extends ControlAdornment {
|
|
111
|
+
type: ControlAdornmentType.HelpText;
|
|
112
|
+
helpText: string;
|
|
113
|
+
placement: AdornmentPlacement;
|
|
114
|
+
}
|
|
100
115
|
export interface DataControlDefinition extends ControlDefinition {
|
|
101
116
|
type: ControlDefinitionType.Data;
|
|
102
117
|
field: string;
|
|
103
|
-
required?: boolean;
|
|
104
|
-
renderOptions
|
|
118
|
+
required?: boolean | null;
|
|
119
|
+
renderOptions?: RenderOptions | null;
|
|
105
120
|
defaultValue?: any;
|
|
106
|
-
readonly?: boolean;
|
|
121
|
+
readonly?: boolean | null;
|
|
122
|
+
validators?: SchemaValidator[] | null;
|
|
123
|
+
hideTitle?: boolean | null;
|
|
107
124
|
}
|
|
108
125
|
export interface RenderOptions {
|
|
109
|
-
type:
|
|
126
|
+
type: string;
|
|
110
127
|
}
|
|
111
128
|
export declare enum DataRenderType {
|
|
112
129
|
Standard = "Standard",
|
|
@@ -117,28 +134,37 @@ export declare enum DataRenderType {
|
|
|
117
134
|
UserSelection = "UserSelection",
|
|
118
135
|
Synchronised = "Synchronised",
|
|
119
136
|
IconSelector = "IconSelector",
|
|
120
|
-
DateTime = "DateTime"
|
|
137
|
+
DateTime = "DateTime",
|
|
138
|
+
Checkbox = "Checkbox",
|
|
139
|
+
Dropdown = "Dropdown"
|
|
121
140
|
}
|
|
122
141
|
export interface RadioButtonRenderOptions extends RenderOptions {
|
|
142
|
+
type: DataRenderType.Radio;
|
|
123
143
|
}
|
|
124
144
|
export interface StandardRenderer extends RenderOptions {
|
|
145
|
+
type: DataRenderType.Standard;
|
|
125
146
|
}
|
|
126
147
|
export interface HtmlEditorRenderOptions extends RenderOptions {
|
|
148
|
+
type: DataRenderType.HtmlEditor;
|
|
127
149
|
allowImages: boolean;
|
|
128
150
|
}
|
|
129
151
|
export interface DateTimeRenderOptions extends RenderOptions {
|
|
130
|
-
|
|
152
|
+
type: DataRenderType.DateTime;
|
|
153
|
+
format?: string | null;
|
|
131
154
|
}
|
|
132
155
|
export interface IconListRenderOptions extends RenderOptions {
|
|
156
|
+
type: DataRenderType.IconList;
|
|
133
157
|
iconMappings: IconMapping[];
|
|
134
158
|
}
|
|
135
159
|
export interface IconMapping {
|
|
136
160
|
value: string;
|
|
137
|
-
materialIcon
|
|
161
|
+
materialIcon?: string | null;
|
|
138
162
|
}
|
|
139
163
|
export interface CheckListRenderOptions extends RenderOptions {
|
|
164
|
+
type: DataRenderType.CheckList;
|
|
140
165
|
}
|
|
141
166
|
export interface SynchronisedRenderOptions extends RenderOptions {
|
|
167
|
+
type: DataRenderType.Synchronised;
|
|
142
168
|
fieldToSync: string;
|
|
143
169
|
syncType: SyncTextType;
|
|
144
170
|
}
|
|
@@ -148,20 +174,21 @@ export declare enum SyncTextType {
|
|
|
148
174
|
Pascal = "Pascal"
|
|
149
175
|
}
|
|
150
176
|
export interface UserSelectionRenderOptions extends RenderOptions {
|
|
177
|
+
type: DataRenderType.UserSelection;
|
|
151
178
|
noGroups: boolean;
|
|
152
179
|
noUsers: boolean;
|
|
153
180
|
}
|
|
154
181
|
export interface IconSelectionRenderOptions extends RenderOptions {
|
|
182
|
+
type: DataRenderType.IconSelector;
|
|
155
183
|
}
|
|
156
184
|
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
157
185
|
type: ControlDefinitionType.Group;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
groupOptions: GroupRenderOptions;
|
|
186
|
+
compoundField?: string | null;
|
|
187
|
+
groupOptions?: GroupRenderOptions;
|
|
161
188
|
}
|
|
162
189
|
export interface GroupRenderOptions {
|
|
163
|
-
type:
|
|
164
|
-
hideTitle?: boolean;
|
|
190
|
+
type: string;
|
|
191
|
+
hideTitle?: boolean | null;
|
|
165
192
|
}
|
|
166
193
|
export declare enum GroupRenderType {
|
|
167
194
|
Standard = "Standard",
|
|
@@ -169,31 +196,69 @@ export declare enum GroupRenderType {
|
|
|
169
196
|
GroupElement = "GroupElement"
|
|
170
197
|
}
|
|
171
198
|
export interface StandardGroupRenderer extends GroupRenderOptions {
|
|
199
|
+
type: GroupRenderType.Standard;
|
|
172
200
|
}
|
|
173
201
|
export interface GroupElementRenderer extends GroupRenderOptions {
|
|
202
|
+
type: GroupRenderType.GroupElement;
|
|
174
203
|
value: any;
|
|
175
204
|
}
|
|
176
205
|
export interface GridRenderer extends GroupRenderOptions {
|
|
177
|
-
|
|
206
|
+
type: GroupRenderType.Grid;
|
|
207
|
+
columns?: number | null;
|
|
178
208
|
}
|
|
179
209
|
export interface DisplayControlDefinition extends ControlDefinition {
|
|
180
210
|
type: ControlDefinitionType.Display;
|
|
181
211
|
displayData: DisplayData;
|
|
182
212
|
}
|
|
183
213
|
export interface DisplayData {
|
|
184
|
-
type:
|
|
214
|
+
type: string;
|
|
185
215
|
}
|
|
186
216
|
export declare enum DisplayDataType {
|
|
187
217
|
Text = "Text",
|
|
188
218
|
Html = "Html"
|
|
189
219
|
}
|
|
190
220
|
export interface TextDisplay extends DisplayData {
|
|
221
|
+
type: DisplayDataType.Text;
|
|
191
222
|
text: string;
|
|
192
223
|
}
|
|
193
224
|
export interface HtmlDisplay extends DisplayData {
|
|
225
|
+
type: DisplayDataType.Html;
|
|
194
226
|
html: string;
|
|
195
227
|
}
|
|
196
228
|
export interface ActionControlDefinition extends ControlDefinition {
|
|
197
229
|
type: ControlDefinitionType.Action;
|
|
198
230
|
actionId: string;
|
|
199
231
|
}
|
|
232
|
+
export declare enum ValidatorType {
|
|
233
|
+
Jsonata = "Jsonata",
|
|
234
|
+
Date = "Date"
|
|
235
|
+
}
|
|
236
|
+
export interface SchemaValidator {
|
|
237
|
+
type: string;
|
|
238
|
+
}
|
|
239
|
+
export interface JsonataValidator extends SchemaValidator {
|
|
240
|
+
type: ValidatorType.Jsonata;
|
|
241
|
+
expression: string;
|
|
242
|
+
}
|
|
243
|
+
export declare enum DateComparison {
|
|
244
|
+
NotBefore = "NotBefore",
|
|
245
|
+
NotAfter = "NotAfter"
|
|
246
|
+
}
|
|
247
|
+
export interface DateValidator extends SchemaValidator {
|
|
248
|
+
type: ValidatorType.Date;
|
|
249
|
+
comparison: DateComparison;
|
|
250
|
+
fixedDate?: string | null;
|
|
251
|
+
daysFromCurrent?: number | null;
|
|
252
|
+
}
|
|
253
|
+
export declare function isDataControlDefinition(x: ControlDefinition): x is DataControlDefinition;
|
|
254
|
+
export declare function isGroupControlsDefinition(x: ControlDefinition): x is GroupedControlsDefinition;
|
|
255
|
+
export declare function isDisplayControlsDefinition(x: ControlDefinition): x is DisplayControlDefinition;
|
|
256
|
+
export declare function isActionControlsDefinition(x: ControlDefinition): x is ActionControlDefinition;
|
|
257
|
+
export interface ControlVisitor<A> {
|
|
258
|
+
data(d: DataControlDefinition): A;
|
|
259
|
+
group(d: GroupedControlsDefinition): A;
|
|
260
|
+
display(d: DisplayControlDefinition): A;
|
|
261
|
+
action(d: ActionControlDefinition): A;
|
|
262
|
+
}
|
|
263
|
+
export declare function visitControlDefinition<A>(x: ControlDefinition, visitor: ControlVisitor<A>, defaultValue: (c: ControlDefinition) => A): A;
|
|
264
|
+
export declare function isGridRenderer(options: GroupRenderOptions): options is GridRenderer;
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CompoundField, ControlDefinition, DataControlDefinition, FieldOption, GroupedControlsDefinition, SchemaField } from "./types";
|
|
2
|
+
import { MutableRefObject } from "react";
|
|
3
|
+
import { Control } from "@react-typed-forms/core";
|
|
4
|
+
export interface ControlGroupContext {
|
|
5
|
+
groupControl: Control<any>;
|
|
6
|
+
fields: SchemaField[];
|
|
7
|
+
}
|
|
8
|
+
export declare function applyDefaultValues(v: {
|
|
9
|
+
[k: string]: any;
|
|
10
|
+
} | undefined, fields: SchemaField[]): any;
|
|
11
|
+
export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean): any;
|
|
12
|
+
export declare function defaultValueForFields(fields: SchemaField[]): any;
|
|
13
|
+
export declare function defaultValueForField(sf: SchemaField, required?: boolean | null): any;
|
|
14
|
+
export declare function elementValueForField(sf: SchemaField): any;
|
|
15
|
+
export declare function findScalarField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
16
|
+
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
17
|
+
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
18
|
+
export declare function isScalarField(sf: SchemaField): sf is SchemaField;
|
|
19
|
+
export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
|
|
20
|
+
export declare function isDataControl(c: ControlDefinition): c is DataControlDefinition;
|
|
21
|
+
export declare function isGroupControl(c: ControlDefinition): c is GroupedControlsDefinition;
|
|
22
|
+
export declare function fieldHasTag(field: SchemaField, tag: string): boolean;
|
|
23
|
+
export declare function fieldDisplayName(field: SchemaField): string;
|
|
24
|
+
export declare function hasOptions(o: {
|
|
25
|
+
options: FieldOption[] | undefined | null;
|
|
26
|
+
}): boolean;
|
|
27
|
+
export declare function defaultControlForField(sf: SchemaField): DataControlDefinition | GroupedControlsDefinition;
|
|
28
|
+
export declare function addMissingControls(fields: SchemaField[], controls: ControlDefinition[]): ControlDefinition[];
|
|
29
|
+
export declare function useUpdatedRef<A>(a: A): MutableRefObject<A>;
|
|
30
|
+
export declare function getTypeField(context: ControlGroupContext): Control<string> | undefined;
|
|
31
|
+
export declare function visitControlDataArray<A>(controls: ControlDefinition[] | undefined | null, context: ControlGroupContext, cb: (definition: DataControlDefinition, field: SchemaField, control: Control<any>, element: boolean) => A | undefined): A | undefined;
|
|
32
|
+
export declare function visitControlData<A>(definition: ControlDefinition, ctx: ControlGroupContext, cb: (definition: DataControlDefinition, field: SchemaField, control: Control<any>, element: boolean) => A | undefined): A | undefined;
|
|
33
|
+
export declare function cleanDataForSchema(v: {
|
|
34
|
+
[k: string]: any;
|
|
35
|
+
} | undefined, fields: SchemaField[]): any;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ControlDefinition } from "./types";
|
|
2
|
+
import { Control } from "@react-typed-forms/core";
|
|
3
|
+
import { ControlGroupContext } from "./util";
|
|
4
|
+
export declare function useValidationHook(definition: ControlDefinition): (control: Control<any>, hidden: boolean, groupContext: ControlGroupContext) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,19 +24,26 @@
|
|
|
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.117",
|
|
28
|
+
"clsx": "^1 || ^2",
|
|
29
|
+
"jsonata": "^2.0.4",
|
|
30
|
+
"react": "^18.2.0"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@
|
|
33
|
+
"@react-typed-forms/transform": "^0.2.0",
|
|
34
|
+
"@types/react": "^18.2.28",
|
|
35
|
+
"markdown-magic": "^2.6.1",
|
|
36
|
+
"microbundle": "^0.15.1",
|
|
31
37
|
"nswag": "^13.18.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
38
|
+
"prettier": "^3.0.3",
|
|
39
|
+
"rimraf": "^3.0.2",
|
|
40
|
+
"typescript": "^5.2.2"
|
|
35
41
|
},
|
|
36
42
|
"gitHead": "698e16cd3ab31b7dd0528fc76536f4d3205ce8c6",
|
|
37
43
|
"scripts": {
|
|
38
|
-
"build": "rimraf ./lib/ &&
|
|
39
|
-
"watch": "
|
|
44
|
+
"build": "rimraf ./lib/ && microbundle -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
|
|
45
|
+
"watch": "microbundle -w -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
|
|
46
|
+
"update-readme": "md-magic --path README.md",
|
|
40
47
|
"gencode": "nswag swagger2tsclient /input:http://localhost:5216/swagger/v1/swagger.json /runtime:Net60 /output:src/types.ts /GenerateClientClasses:false /MarkOptionalProperties:false /Template:Fetch /TypeStyle:Interface /DateTimeType:string"
|
|
41
48
|
}
|
|
42
49
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ControlDefinition,
|
|
3
|
+
ControlDefinitionType,
|
|
4
|
+
DataControlDefinition,
|
|
5
|
+
DisplayControlDefinition,
|
|
6
|
+
DisplayDataType,
|
|
7
|
+
DynamicProperty,
|
|
8
|
+
DynamicPropertyType,
|
|
9
|
+
EntityExpression,
|
|
10
|
+
ExpressionType,
|
|
11
|
+
FieldValueExpression,
|
|
12
|
+
GroupedControlsDefinition,
|
|
13
|
+
GroupRenderType,
|
|
14
|
+
HtmlDisplay,
|
|
15
|
+
JsonataExpression,
|
|
16
|
+
SchemaField,
|
|
17
|
+
TextDisplay,
|
|
18
|
+
} from "./types";
|
|
19
|
+
import { ActionRendererProps } from "./controlRender";
|
|
20
|
+
import { useMemo } from "react";
|
|
21
|
+
import { addMissingControls } from "./util";
|
|
22
|
+
|
|
23
|
+
export function dataControl(
|
|
24
|
+
field: string,
|
|
25
|
+
title?: string | null,
|
|
26
|
+
options?: Partial<DataControlDefinition>,
|
|
27
|
+
): DataControlDefinition {
|
|
28
|
+
return { type: ControlDefinitionType.Data, field, title, ...options };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function textDisplayControl(
|
|
32
|
+
text: string,
|
|
33
|
+
options?: Partial<DisplayControlDefinition>,
|
|
34
|
+
): DisplayControlDefinition {
|
|
35
|
+
return {
|
|
36
|
+
type: ControlDefinitionType.Display,
|
|
37
|
+
displayData: { type: DisplayDataType.Text, text } as TextDisplay,
|
|
38
|
+
...options,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function htmlDisplayControl(
|
|
43
|
+
html: string,
|
|
44
|
+
options?: Partial<DisplayControlDefinition>,
|
|
45
|
+
): DisplayControlDefinition {
|
|
46
|
+
return {
|
|
47
|
+
type: ControlDefinitionType.Display,
|
|
48
|
+
displayData: { type: DisplayDataType.Html, html } as HtmlDisplay,
|
|
49
|
+
...options,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function dynamicDefaultValue(expr: EntityExpression): DynamicProperty {
|
|
54
|
+
return { type: DynamicPropertyType.DefaultValue, expr };
|
|
55
|
+
}
|
|
56
|
+
export function visibility(expr: EntityExpression): DynamicProperty {
|
|
57
|
+
return { type: DynamicPropertyType.Visible, expr };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function fieldEqExpr(field: string, value: any): FieldValueExpression {
|
|
61
|
+
return { type: ExpressionType.FieldValue, field, value };
|
|
62
|
+
}
|
|
63
|
+
export function jsonataExpr(expression: string): JsonataExpression {
|
|
64
|
+
return { type: ExpressionType.Jsonata, expression };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function groupedControl(
|
|
68
|
+
children: ControlDefinition[],
|
|
69
|
+
title?: string,
|
|
70
|
+
options?: Partial<GroupedControlsDefinition>,
|
|
71
|
+
): GroupedControlsDefinition {
|
|
72
|
+
return {
|
|
73
|
+
type: ControlDefinitionType.Group,
|
|
74
|
+
children,
|
|
75
|
+
title,
|
|
76
|
+
groupOptions: { type: "Standard", hideTitle: !title },
|
|
77
|
+
...options,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function compoundControl(
|
|
81
|
+
field: string,
|
|
82
|
+
title: string | undefined,
|
|
83
|
+
children: ControlDefinition[],
|
|
84
|
+
options?: Partial<DataControlDefinition>,
|
|
85
|
+
): DataControlDefinition {
|
|
86
|
+
return {
|
|
87
|
+
type: ControlDefinitionType.Data,
|
|
88
|
+
field,
|
|
89
|
+
children,
|
|
90
|
+
title,
|
|
91
|
+
renderOptions: { type: "Standard" },
|
|
92
|
+
...options,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function createAction(
|
|
97
|
+
actionId: string,
|
|
98
|
+
onClick: () => void,
|
|
99
|
+
actionText?: string,
|
|
100
|
+
): ActionRendererProps {
|
|
101
|
+
return { actionId, onClick, actionText: actionText ?? actionId };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const emptyGroupDefinition: GroupedControlsDefinition = {
|
|
105
|
+
type: ControlDefinitionType.Group,
|
|
106
|
+
children: [],
|
|
107
|
+
groupOptions: { type: GroupRenderType.Standard, hideTitle: true },
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function useControlDefinitionForSchema(
|
|
111
|
+
sf: SchemaField[],
|
|
112
|
+
definition: GroupedControlsDefinition = emptyGroupDefinition,
|
|
113
|
+
): GroupedControlsDefinition {
|
|
114
|
+
return useMemo<GroupedControlsDefinition>(
|
|
115
|
+
() => ({
|
|
116
|
+
...definition,
|
|
117
|
+
children: addMissingControls(sf, definition.children ?? []),
|
|
118
|
+
}),
|
|
119
|
+
[sf, definition],
|
|
120
|
+
);
|
|
121
|
+
}
|