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