@react-typed-forms/schemas 1.0.0-dev.2
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 +13 -0
- package/.rush/temp/shrinkwrap-deps.json +25 -0
- package/lib/controlRender.d.ts +95 -0
- package/lib/controlRender.js +230 -0
- package/lib/hooks.d.ts +9 -0
- package/lib/hooks.js +93 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +20 -0
- package/lib/schemaBuilder.d.ts +83 -0
- package/lib/schemaBuilder.js +67 -0
- package/lib/types.d.ts +200 -0
- package/lib/types.js +68 -0
- package/package.json +42 -0
- package/schemas.build.log +2 -0
- package/src/controlRender.tsx +491 -0
- package/src/hooks.ts +164 -0
- package/src/index.ts +4 -0
- package/src/schemaBuilder.ts +148 -0
- package/src/types.ts +244 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { CompoundField, FieldOption, FieldType, SchemaField } from "./types";
|
|
2
|
+
|
|
3
|
+
type AllowedSchema<T> = T extends string
|
|
4
|
+
? SchemaField & {
|
|
5
|
+
type: FieldType.String | FieldType.Date | FieldType.DateTime;
|
|
6
|
+
}
|
|
7
|
+
: T extends number
|
|
8
|
+
? SchemaField & {
|
|
9
|
+
type: FieldType.Int | FieldType.Double;
|
|
10
|
+
}
|
|
11
|
+
: T extends boolean
|
|
12
|
+
? SchemaField & {
|
|
13
|
+
type: FieldType.Bool;
|
|
14
|
+
}
|
|
15
|
+
: T extends Array<infer E>
|
|
16
|
+
? AllowedSchema<E> & {
|
|
17
|
+
collection: true;
|
|
18
|
+
}
|
|
19
|
+
: T extends { [key: string]: any }
|
|
20
|
+
? CompoundField & {
|
|
21
|
+
type: FieldType.Compound;
|
|
22
|
+
}
|
|
23
|
+
: never;
|
|
24
|
+
type AllowedField<T> = (name: string) => AllowedSchema<T>;
|
|
25
|
+
|
|
26
|
+
export function buildSchema<T>(def: {
|
|
27
|
+
[K in keyof T]-?: AllowedField<T[K]>;
|
|
28
|
+
}): SchemaField[] {
|
|
29
|
+
return Object.entries(def).map((x) =>
|
|
30
|
+
(x[1] as (n: string) => SchemaField)(x[0])
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function stringField(
|
|
35
|
+
displayName: string,
|
|
36
|
+
options?: Partial<Omit<SchemaField, "type">>
|
|
37
|
+
) {
|
|
38
|
+
return makeScalarField({
|
|
39
|
+
type: FieldType.String as const,
|
|
40
|
+
displayName,
|
|
41
|
+
...options,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function stringOptionsField(
|
|
46
|
+
displayName: string,
|
|
47
|
+
...options: FieldOption[]
|
|
48
|
+
) {
|
|
49
|
+
return makeScalarField({
|
|
50
|
+
type: FieldType.String as const,
|
|
51
|
+
displayName,
|
|
52
|
+
options,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function withScalarOptions<S extends SchemaField>(
|
|
57
|
+
options: Partial<SchemaField>,
|
|
58
|
+
v: (name: string) => S
|
|
59
|
+
): (name: string) => S {
|
|
60
|
+
return (n) => ({ ...v(n), ...options });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function makeScalarField<S extends Partial<SchemaField>>(
|
|
64
|
+
options: S
|
|
65
|
+
): (name: string) => SchemaField & S {
|
|
66
|
+
return (n) => ({ ...defaultScalarField(n, n), ...options });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function makeCompoundField<S extends Partial<CompoundField>>(
|
|
70
|
+
options: S
|
|
71
|
+
): (name: string) => CompoundField & {
|
|
72
|
+
type: FieldType.Compound;
|
|
73
|
+
} & S {
|
|
74
|
+
return (n) => ({ ...defaultCompoundField(n, n, false), ...options });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function intField(
|
|
78
|
+
displayName: string,
|
|
79
|
+
options?: Partial<Omit<SchemaField, "type">>
|
|
80
|
+
) {
|
|
81
|
+
return makeScalarField({
|
|
82
|
+
type: FieldType.Int as const,
|
|
83
|
+
displayName,
|
|
84
|
+
...options,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function boolField(
|
|
89
|
+
displayName: string,
|
|
90
|
+
options?: Partial<Omit<SchemaField, "type">>
|
|
91
|
+
) {
|
|
92
|
+
return makeScalarField({
|
|
93
|
+
type: FieldType.Bool as const,
|
|
94
|
+
displayName,
|
|
95
|
+
...options,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function compoundField<
|
|
100
|
+
Other extends Partial<Omit<CompoundField, "type" | "schemaType">>
|
|
101
|
+
>(
|
|
102
|
+
displayName: string,
|
|
103
|
+
fields: SchemaField[],
|
|
104
|
+
other: Other
|
|
105
|
+
): (name: string) => CompoundField & {
|
|
106
|
+
collection: Other["collection"];
|
|
107
|
+
} {
|
|
108
|
+
return (field) =>
|
|
109
|
+
({
|
|
110
|
+
...defaultCompoundField(field, displayName, false),
|
|
111
|
+
...other,
|
|
112
|
+
children: fields,
|
|
113
|
+
} as any);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function defaultScalarField(
|
|
117
|
+
field: string,
|
|
118
|
+
displayName: string
|
|
119
|
+
): Omit<SchemaField, "type"> & {
|
|
120
|
+
type: FieldType.String;
|
|
121
|
+
} {
|
|
122
|
+
return {
|
|
123
|
+
field,
|
|
124
|
+
displayName,
|
|
125
|
+
type: FieldType.String,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function defaultCompoundField(
|
|
130
|
+
field: string,
|
|
131
|
+
displayName: string,
|
|
132
|
+
collection: boolean
|
|
133
|
+
): CompoundField & {
|
|
134
|
+
type: FieldType.Compound;
|
|
135
|
+
} {
|
|
136
|
+
return {
|
|
137
|
+
tags: [],
|
|
138
|
+
field,
|
|
139
|
+
displayName,
|
|
140
|
+
type: FieldType.Compound,
|
|
141
|
+
collection,
|
|
142
|
+
system: false,
|
|
143
|
+
treeChildren: false,
|
|
144
|
+
children: [],
|
|
145
|
+
onlyForTypes: [],
|
|
146
|
+
required: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
export interface SchemaField {
|
|
2
|
+
type: string;
|
|
3
|
+
field: string;
|
|
4
|
+
displayName?: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
system?: boolean;
|
|
7
|
+
collection?: boolean;
|
|
8
|
+
onlyForTypes?: string[];
|
|
9
|
+
required?: boolean;
|
|
10
|
+
defaultValue?: any;
|
|
11
|
+
isTypeField?: boolean;
|
|
12
|
+
searchable?: boolean;
|
|
13
|
+
options?: FieldOption[];
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use options directly
|
|
16
|
+
*/
|
|
17
|
+
restrictions?: SchemaRestrictions | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum FieldType {
|
|
21
|
+
String = "String",
|
|
22
|
+
Bool = "Bool",
|
|
23
|
+
Int = "Int",
|
|
24
|
+
Date = "Date",
|
|
25
|
+
DateTime = "DateTime",
|
|
26
|
+
Double = "Double",
|
|
27
|
+
EntityRef = "EntityRef",
|
|
28
|
+
Compound = "Compound",
|
|
29
|
+
AutoId = "AutoId",
|
|
30
|
+
Image = "Image",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface EntityRefField extends SchemaField {
|
|
34
|
+
type: FieldType.EntityRef;
|
|
35
|
+
entityRefType: string;
|
|
36
|
+
parentField: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SchemaRestrictions {
|
|
40
|
+
options: FieldOption[] | undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FieldOption {
|
|
44
|
+
name: string;
|
|
45
|
+
value: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface CompoundField extends SchemaField {
|
|
49
|
+
type: FieldType.Compound;
|
|
50
|
+
children: SchemaField[];
|
|
51
|
+
treeChildren?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type AnyControlDefinition =
|
|
55
|
+
| DataControlDefinition
|
|
56
|
+
| GroupedControlsDefinition
|
|
57
|
+
| ActionControlDefinition
|
|
58
|
+
| DisplayControlDefinition;
|
|
59
|
+
|
|
60
|
+
export interface ControlDefinition {
|
|
61
|
+
type: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
dynamic?: DynamicProperty[];
|
|
64
|
+
adornments?: ControlAdornment[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export enum ControlDefinitionType {
|
|
68
|
+
Data = "Data",
|
|
69
|
+
Group = "Group",
|
|
70
|
+
Display = "Display",
|
|
71
|
+
Action = "Action",
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface DynamicProperty {
|
|
75
|
+
type: DynamicPropertyType;
|
|
76
|
+
expr: EntityExpression;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export enum DynamicPropertyType {
|
|
80
|
+
Visible = "Visible",
|
|
81
|
+
DefaultValue = "DefaultValue",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface EntityExpression {
|
|
85
|
+
type: ExpressionType;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export enum ExpressionType {
|
|
89
|
+
Jsonata = "Jsonata",
|
|
90
|
+
FieldValue = "FieldValue",
|
|
91
|
+
UserMatch = "UserMatch",
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface JsonataExpression extends EntityExpression {
|
|
95
|
+
expression: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface FieldValueExpression extends EntityExpression {
|
|
99
|
+
field: string;
|
|
100
|
+
value: any;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface UserMatchExpression extends EntityExpression {
|
|
104
|
+
userMatch: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ControlAdornment {
|
|
108
|
+
type: ControlAdornmentType;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export enum ControlAdornmentType {
|
|
112
|
+
Tooltip = "Tooltip",
|
|
113
|
+
Accordion = "Accordion",
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface TooltipAdornment extends ControlAdornment {
|
|
117
|
+
tooltip: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface AccordionAdornment extends ControlAdornment {
|
|
121
|
+
title: string;
|
|
122
|
+
defaultExpanded: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface DataControlDefinition extends ControlDefinition {
|
|
126
|
+
type: ControlDefinitionType.Data;
|
|
127
|
+
field: string;
|
|
128
|
+
required?: boolean;
|
|
129
|
+
renderOptions?: RenderOptions;
|
|
130
|
+
defaultValue?: any;
|
|
131
|
+
readonly?: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface RenderOptions {
|
|
135
|
+
type: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export enum DataRenderType {
|
|
139
|
+
Standard = "Standard",
|
|
140
|
+
Radio = "Radio",
|
|
141
|
+
HtmlEditor = "HtmlEditor",
|
|
142
|
+
IconList = "IconList",
|
|
143
|
+
CheckList = "CheckList",
|
|
144
|
+
UserSelection = "UserSelection",
|
|
145
|
+
Synchronised = "Synchronised",
|
|
146
|
+
IconSelector = "IconSelector",
|
|
147
|
+
DateTime = "DateTime",
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface RadioButtonRenderOptions extends RenderOptions {}
|
|
151
|
+
|
|
152
|
+
export interface StandardRenderer extends RenderOptions {}
|
|
153
|
+
|
|
154
|
+
export interface HtmlEditorRenderOptions extends RenderOptions {
|
|
155
|
+
allowImages: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface DateTimeRenderOptions extends RenderOptions {
|
|
159
|
+
format?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface IconListRenderOptions extends RenderOptions {
|
|
163
|
+
iconMappings: IconMapping[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface IconMapping {
|
|
167
|
+
value: string;
|
|
168
|
+
materialIcon: string | undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface CheckListRenderOptions extends RenderOptions {}
|
|
172
|
+
|
|
173
|
+
export interface SynchronisedRenderOptions extends RenderOptions {
|
|
174
|
+
fieldToSync: string;
|
|
175
|
+
syncType: SyncTextType;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export enum SyncTextType {
|
|
179
|
+
Camel = "Camel",
|
|
180
|
+
Snake = "Snake",
|
|
181
|
+
Pascal = "Pascal",
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface UserSelectionRenderOptions extends RenderOptions {
|
|
185
|
+
noGroups: boolean;
|
|
186
|
+
noUsers: boolean;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface IconSelectionRenderOptions extends RenderOptions {}
|
|
190
|
+
|
|
191
|
+
export interface GroupedControlsDefinition extends ControlDefinition {
|
|
192
|
+
type: ControlDefinitionType.Group;
|
|
193
|
+
children: AnyControlDefinition[];
|
|
194
|
+
compoundField?: string;
|
|
195
|
+
groupOptions: GroupRenderOptions;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface GroupRenderOptions {
|
|
199
|
+
type: GroupRenderType;
|
|
200
|
+
hideTitle?: boolean;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export enum GroupRenderType {
|
|
204
|
+
Standard = "Standard",
|
|
205
|
+
Grid = "Grid",
|
|
206
|
+
GroupElement = "GroupElement",
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface StandardGroupRenderer extends GroupRenderOptions {}
|
|
210
|
+
|
|
211
|
+
export interface GroupElementRenderer extends GroupRenderOptions {
|
|
212
|
+
value: any;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface GridRenderer extends GroupRenderOptions {
|
|
216
|
+
columns: number | undefined;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface DisplayControlDefinition extends ControlDefinition {
|
|
220
|
+
type: ControlDefinitionType.Display;
|
|
221
|
+
displayData: DisplayData;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface DisplayData {
|
|
225
|
+
type: DisplayDataType;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export enum DisplayDataType {
|
|
229
|
+
Text = "Text",
|
|
230
|
+
Html = "Html",
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface TextDisplay extends DisplayData {
|
|
234
|
+
text: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface HtmlDisplay extends DisplayData {
|
|
238
|
+
html: string;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface ActionControlDefinition extends ControlDefinition {
|
|
242
|
+
type: ControlDefinitionType.Action;
|
|
243
|
+
actionId: string;
|
|
244
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2015",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"module": "CommonJS",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"jsx": "react",
|
|
16
|
+
"outDir": "lib"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
19
|
+
"exclude": ["node_modules", "lib"]
|
|
20
|
+
}
|