@react-typed-forms/schemas 1.0.0-dev.16 → 1.0.0-dev.18
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/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +2 -2
- package/.rush/temp/shrinkwrap-deps.json +5 -3
- package/lib/controlRender.d.ts +126 -100
- package/lib/hooks.d.ts +10 -9
- package/lib/index.d.ts +7 -5
- package/lib/index.js +1169 -3044
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +153 -0
- package/lib/schemaBuilder.d.ts +87 -87
- package/lib/tailwind.d.ts +2 -0
- package/lib/types.d.ts +272 -234
- package/lib/util.d.ts +6 -3
- package/package.json +10 -7
- package/src/controlRender.tsx +187 -176
- package/src/hooks.tsx +425 -0
- package/src/index.ts +2 -0
- package/src/renderers.tsx +855 -0
- package/src/tailwind.tsx +21 -0
- package/src/types.ts +56 -9
- package/src/util.ts +5 -1
- package/src/hooks.ts +0 -173
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, { CSSProperties, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { ActionRendererProps, AdornmentProps, AdornmentRenderer, ArrayRendererProps, DataRendererProps, DisplayRendererProps, FormRenderer, GroupRendererProps, LabelRendererProps, Visibility } from "./controlRender";
|
|
3
|
+
import { FieldOption, GridRenderer } from "./types";
|
|
4
|
+
import { Control } from "@react-typed-forms/core";
|
|
5
|
+
export interface DefaultRenderers {
|
|
6
|
+
data: DataRendererRegistration;
|
|
7
|
+
label: LabelRendererRegistration;
|
|
8
|
+
action: ActionRendererRegistration;
|
|
9
|
+
array: ArrayRendererRegistration;
|
|
10
|
+
group: GroupRendererRegistration;
|
|
11
|
+
display: DisplayRendererRegistration;
|
|
12
|
+
visibility: VisibilityRendererRegistration;
|
|
13
|
+
adornment: AdornmentRendererRegistration;
|
|
14
|
+
}
|
|
15
|
+
export interface DataRendererRegistration {
|
|
16
|
+
type: "data";
|
|
17
|
+
schemaType?: string | string[];
|
|
18
|
+
renderType?: string | string[];
|
|
19
|
+
options?: boolean;
|
|
20
|
+
collection?: boolean;
|
|
21
|
+
match?: (props: DataRendererProps) => boolean;
|
|
22
|
+
render: (props: DataRendererProps, defaultLabel: (label?: Partial<LabelRendererProps>) => LabelRendererProps, renderers: FormRenderer) => ReactElement;
|
|
23
|
+
}
|
|
24
|
+
export interface LabelRendererRegistration {
|
|
25
|
+
type: "label";
|
|
26
|
+
render: (labelProps: LabelRendererProps, elem: ReactElement, renderers: FormRenderer) => ReactElement;
|
|
27
|
+
}
|
|
28
|
+
export interface ActionRendererRegistration {
|
|
29
|
+
type: "action";
|
|
30
|
+
render: (props: ActionRendererProps, renderers: FormRenderer) => ReactElement;
|
|
31
|
+
}
|
|
32
|
+
export interface ArrayRendererRegistration {
|
|
33
|
+
type: "array";
|
|
34
|
+
render: (props: ArrayRendererProps, renderers: FormRenderer) => ReactElement;
|
|
35
|
+
}
|
|
36
|
+
export interface GroupRendererRegistration {
|
|
37
|
+
type: "group";
|
|
38
|
+
render: (props: GroupRendererProps, defaultLabel: (label?: Partial<LabelRendererProps>) => LabelRendererProps, renderers: FormRenderer) => ReactElement;
|
|
39
|
+
}
|
|
40
|
+
export interface DisplayRendererRegistration {
|
|
41
|
+
type: "display";
|
|
42
|
+
render: (props: DisplayRendererProps, renderers: FormRenderer) => ReactElement;
|
|
43
|
+
}
|
|
44
|
+
export interface VisibilityRendererRegistration {
|
|
45
|
+
type: "visibility";
|
|
46
|
+
render: (visible: Visibility, elem: ReactElement) => ReactElement;
|
|
47
|
+
}
|
|
48
|
+
export interface AdornmentRendererRegistration {
|
|
49
|
+
type: "adornment";
|
|
50
|
+
adornmentType?: string | string[];
|
|
51
|
+
render: (props: AdornmentProps) => AdornmentRenderer;
|
|
52
|
+
}
|
|
53
|
+
export type AnyRendererRegistration = DataRendererRegistration | GroupRendererRegistration | DisplayRendererRegistration | ActionRendererRegistration | LabelRendererRegistration | ArrayRendererRegistration | AdornmentRendererRegistration | VisibilityRendererRegistration;
|
|
54
|
+
export declare function createFormRenderer(customRenderers?: AnyRendererRegistration[], defaultRenderers?: DefaultRenderers): FormRenderer;
|
|
55
|
+
interface DefaultLabelRendererOptions {
|
|
56
|
+
className?: string;
|
|
57
|
+
groupLabelClass?: string;
|
|
58
|
+
requiredElement?: ReactNode;
|
|
59
|
+
labelClass?: string;
|
|
60
|
+
}
|
|
61
|
+
interface DefaultActionRendererOptions {
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare function createDefaultActionRenderer(options?: DefaultActionRendererOptions): ActionRendererRegistration;
|
|
65
|
+
export declare function createDefaultLabelRenderer(options?: DefaultLabelRendererOptions): LabelRendererRegistration;
|
|
66
|
+
export declare function DefaultLabelRenderer({ className, labelClass, title, forId, required, children, group, groupLabelClass, renderAdornment, requiredElement, }: LabelRendererProps & DefaultLabelRendererOptions & {
|
|
67
|
+
children: ReactElement;
|
|
68
|
+
}): React.JSX.Element;
|
|
69
|
+
interface DefaultArrayRendererOptions {
|
|
70
|
+
className?: string;
|
|
71
|
+
removableClass?: string;
|
|
72
|
+
childClass?: string;
|
|
73
|
+
removableChildClass?: string;
|
|
74
|
+
removeActionClass?: string;
|
|
75
|
+
addActionClass?: string;
|
|
76
|
+
}
|
|
77
|
+
export declare function createDefaultArrayRenderer(options?: DefaultArrayRendererOptions): ArrayRendererRegistration;
|
|
78
|
+
interface StyleProps {
|
|
79
|
+
className?: string;
|
|
80
|
+
style?: CSSProperties;
|
|
81
|
+
}
|
|
82
|
+
interface DefaultGroupRendererOptions {
|
|
83
|
+
className?: string;
|
|
84
|
+
standardClassName?: string;
|
|
85
|
+
gridStyles?: (columns: GridRenderer) => StyleProps;
|
|
86
|
+
gridClassName?: string;
|
|
87
|
+
defaultGridColumns?: number;
|
|
88
|
+
}
|
|
89
|
+
export declare function createDefaultGroupRenderer(options?: DefaultGroupRendererOptions): GroupRendererRegistration;
|
|
90
|
+
export interface DefaultDisplayRendererOptions {
|
|
91
|
+
textClassName?: string;
|
|
92
|
+
htmlClassName?: string;
|
|
93
|
+
}
|
|
94
|
+
export declare function createDefaultDisplayRenderer(options?: DefaultDisplayRendererOptions): DisplayRendererRegistration;
|
|
95
|
+
export declare const DefaultBoolOptions: FieldOption[];
|
|
96
|
+
interface DefaultDataRendererOptions {
|
|
97
|
+
inputClass?: string;
|
|
98
|
+
selectOptions?: SelectRendererOptions;
|
|
99
|
+
booleanOptions?: FieldOption[];
|
|
100
|
+
optionRenderer?: DataRendererRegistration;
|
|
101
|
+
}
|
|
102
|
+
export declare function createDefaultDataRenderer(options?: DefaultDataRendererOptions): DataRendererRegistration;
|
|
103
|
+
export declare function ControlInput({ control, convert, ...props }: React.InputHTMLAttributes<HTMLInputElement> & {
|
|
104
|
+
control: Control<any>;
|
|
105
|
+
convert: InputConversion;
|
|
106
|
+
}): React.JSX.Element;
|
|
107
|
+
export interface DefaultVisibilityRendererOptions {
|
|
108
|
+
}
|
|
109
|
+
export interface DefaultAdornmentRendererOptions {
|
|
110
|
+
}
|
|
111
|
+
export declare function createDefaultAdornmentRenderer(options?: DefaultAdornmentRendererOptions): AdornmentRendererRegistration;
|
|
112
|
+
export declare function createDefaultVisibilityRenderer(options?: DefaultVisibilityRendererOptions): VisibilityRendererRegistration;
|
|
113
|
+
export interface DefaultRendererOptions {
|
|
114
|
+
data?: DefaultDataRendererOptions;
|
|
115
|
+
display?: DefaultDisplayRendererOptions;
|
|
116
|
+
action?: DefaultActionRendererOptions;
|
|
117
|
+
array?: DefaultArrayRendererOptions;
|
|
118
|
+
group?: DefaultGroupRendererOptions;
|
|
119
|
+
label?: DefaultLabelRendererOptions;
|
|
120
|
+
visibility?: DefaultVisibilityRendererOptions;
|
|
121
|
+
adornment?: DefaultAdornmentRendererOptions;
|
|
122
|
+
}
|
|
123
|
+
export declare function createDefaultRenderers(options?: DefaultRendererOptions): DefaultRenderers;
|
|
124
|
+
export declare function createDataRenderer(render: DataRendererRegistration["render"], options?: Partial<DataRendererRegistration>): DataRendererRegistration;
|
|
125
|
+
export declare function createDataRendererLabelled(render: (props: DataRendererProps, id: string, renderers: FormRenderer) => ReactElement, options?: Partial<DataRendererRegistration>): DataRendererRegistration;
|
|
126
|
+
export declare function createLabelRenderer(options: Omit<LabelRendererRegistration, "type">): LabelRendererRegistration;
|
|
127
|
+
export declare function createAdornmentRenderer(render: (props: AdornmentProps) => AdornmentRenderer, options?: Omit<AdornmentRendererRegistration, "type">): AdornmentRendererRegistration;
|
|
128
|
+
export interface SelectRendererOptions {
|
|
129
|
+
className?: string;
|
|
130
|
+
emptyText?: string;
|
|
131
|
+
requiredText?: string;
|
|
132
|
+
}
|
|
133
|
+
export declare function createSelectRenderer(options?: SelectRendererOptions): DataRendererRegistration;
|
|
134
|
+
type SelectConversion = (a: any) => string | number;
|
|
135
|
+
interface SelectDataRendererProps {
|
|
136
|
+
id?: string;
|
|
137
|
+
className?: string;
|
|
138
|
+
options: {
|
|
139
|
+
name: string;
|
|
140
|
+
value: any;
|
|
141
|
+
disabled?: boolean;
|
|
142
|
+
}[];
|
|
143
|
+
emptyText?: string;
|
|
144
|
+
requiredText?: string;
|
|
145
|
+
required: boolean;
|
|
146
|
+
state: Control<any>;
|
|
147
|
+
convert: SelectConversion;
|
|
148
|
+
}
|
|
149
|
+
export declare function SelectDataRenderer({ state, options, className, convert, required, emptyText, requiredText, ...props }: SelectDataRendererProps): React.JSX.Element;
|
|
150
|
+
export declare function createSelectConversion(ft: string): SelectConversion;
|
|
151
|
+
type InputConversion = [string, (s: any) => any, (a: any) => string | number];
|
|
152
|
+
export declare function createInputConversion(ft: string): InputConversion;
|
|
153
|
+
export {};
|
package/lib/schemaBuilder.d.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { CompoundField, FieldOption, FieldType, SchemaField } from "./types";
|
|
2
|
-
type AllowedSchema<T> = T extends string ? SchemaField & {
|
|
3
|
-
type: FieldType.String | FieldType.Date | FieldType.DateTime;
|
|
4
|
-
} : T extends number ? SchemaField & {
|
|
5
|
-
type: FieldType.Int | FieldType.Double;
|
|
6
|
-
} : T extends boolean ? SchemaField & {
|
|
7
|
-
type: FieldType.Bool;
|
|
8
|
-
} : T extends Array<infer E> ? AllowedSchema<E> & {
|
|
9
|
-
collection: true;
|
|
10
|
-
} : T extends {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
} ? CompoundField & {
|
|
13
|
-
type: FieldType.Compound;
|
|
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
|
-
}): SchemaField[];
|
|
23
|
-
export declare function stringField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
24
|
-
field?: string | 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
|
-
defaultValue?: any;
|
|
32
|
-
isTypeField?: boolean | null | undefined;
|
|
33
|
-
searchable?: boolean | null | undefined;
|
|
34
|
-
options?: FieldOption[] | null | undefined;
|
|
35
|
-
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
36
|
-
type: FieldType.String;
|
|
37
|
-
};
|
|
38
|
-
export declare function stringOptionsField(displayName: string, ...options: FieldOption[]): (name: string) => SchemaField & {
|
|
39
|
-
type: FieldType.String;
|
|
40
|
-
displayName: string;
|
|
41
|
-
options: FieldOption[];
|
|
42
|
-
};
|
|
43
|
-
export declare function withScalarOptions<S extends SchemaField>(options: Partial<SchemaField>, v: (name: string) => S): (name: string) => S;
|
|
44
|
-
export declare function makeScalarField<S extends Partial<SchemaField>>(options: S): (name: string) => SchemaField & S;
|
|
45
|
-
export declare function makeCompoundField<S extends Partial<CompoundField>>(options: S): (name: string) => CompoundField & {
|
|
46
|
-
type: FieldType.Compound;
|
|
47
|
-
} & S;
|
|
48
|
-
export declare function intField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
49
|
-
field?: string | undefined;
|
|
50
|
-
displayName: string | null;
|
|
51
|
-
tags?: string[] | null | undefined;
|
|
52
|
-
system?: boolean | null | undefined;
|
|
53
|
-
collection?: boolean | null | undefined;
|
|
54
|
-
onlyForTypes?: string[] | null | undefined;
|
|
55
|
-
required?: boolean | null | undefined;
|
|
56
|
-
defaultValue?: any;
|
|
57
|
-
isTypeField?: boolean | null | undefined;
|
|
58
|
-
searchable?: boolean | null | undefined;
|
|
59
|
-
options?: FieldOption[] | null | undefined;
|
|
60
|
-
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
61
|
-
type: FieldType.Int;
|
|
62
|
-
};
|
|
63
|
-
export declare function boolField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
64
|
-
field?: string | undefined;
|
|
65
|
-
displayName: string | null;
|
|
66
|
-
tags?: string[] | null | undefined;
|
|
67
|
-
system?: boolean | null | undefined;
|
|
68
|
-
collection?: boolean | null | undefined;
|
|
69
|
-
onlyForTypes?: string[] | null | undefined;
|
|
70
|
-
required?: boolean | null | undefined;
|
|
71
|
-
defaultValue?: any;
|
|
72
|
-
isTypeField?: boolean | null | undefined;
|
|
73
|
-
searchable?: boolean | null | undefined;
|
|
74
|
-
options?: FieldOption[] | null | undefined;
|
|
75
|
-
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
76
|
-
type: FieldType.Bool;
|
|
77
|
-
};
|
|
78
|
-
export declare function compoundField<Other extends Partial<Omit<CompoundField, "type" | "schemaType">>>(displayName: string, fields: SchemaField[], other: Other): (name: string) => CompoundField & {
|
|
79
|
-
collection: Other["collection"];
|
|
80
|
-
};
|
|
81
|
-
export declare function defaultScalarField(field: string, displayName: string): Omit<SchemaField, "type"> & {
|
|
82
|
-
type: FieldType.String;
|
|
83
|
-
};
|
|
84
|
-
export declare function defaultCompoundField(field: string, displayName: string, collection: boolean): CompoundField & {
|
|
85
|
-
type: FieldType.Compound;
|
|
86
|
-
};
|
|
87
|
-
export {};
|
|
1
|
+
import { CompoundField, FieldOption, FieldType, SchemaField } from "./types";
|
|
2
|
+
type AllowedSchema<T> = T extends string ? SchemaField & {
|
|
3
|
+
type: FieldType.String | FieldType.Date | FieldType.DateTime;
|
|
4
|
+
} : T extends number ? SchemaField & {
|
|
5
|
+
type: FieldType.Int | FieldType.Double;
|
|
6
|
+
} : T extends boolean ? SchemaField & {
|
|
7
|
+
type: FieldType.Bool;
|
|
8
|
+
} : T extends Array<infer E> ? AllowedSchema<E> & {
|
|
9
|
+
collection: true;
|
|
10
|
+
} : T extends {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
} ? CompoundField & {
|
|
13
|
+
type: FieldType.Compound;
|
|
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
|
+
}): SchemaField[];
|
|
23
|
+
export declare function stringField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
24
|
+
field?: string | 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
|
+
defaultValue?: any;
|
|
32
|
+
isTypeField?: boolean | null | undefined;
|
|
33
|
+
searchable?: boolean | null | undefined;
|
|
34
|
+
options?: FieldOption[] | null | undefined;
|
|
35
|
+
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
36
|
+
type: FieldType.String;
|
|
37
|
+
};
|
|
38
|
+
export declare function stringOptionsField(displayName: string, ...options: FieldOption[]): (name: string) => SchemaField & {
|
|
39
|
+
type: FieldType.String;
|
|
40
|
+
displayName: string;
|
|
41
|
+
options: FieldOption[];
|
|
42
|
+
};
|
|
43
|
+
export declare function withScalarOptions<S extends SchemaField>(options: Partial<SchemaField>, v: (name: string) => S): (name: string) => S;
|
|
44
|
+
export declare function makeScalarField<S extends Partial<SchemaField>>(options: S): (name: string) => SchemaField & S;
|
|
45
|
+
export declare function makeCompoundField<S extends Partial<CompoundField>>(options: S): (name: string) => CompoundField & {
|
|
46
|
+
type: FieldType.Compound;
|
|
47
|
+
} & S;
|
|
48
|
+
export declare function intField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
49
|
+
field?: string | undefined;
|
|
50
|
+
displayName: string | null;
|
|
51
|
+
tags?: string[] | null | undefined;
|
|
52
|
+
system?: boolean | null | undefined;
|
|
53
|
+
collection?: boolean | null | undefined;
|
|
54
|
+
onlyForTypes?: string[] | null | undefined;
|
|
55
|
+
required?: boolean | null | undefined;
|
|
56
|
+
defaultValue?: any;
|
|
57
|
+
isTypeField?: boolean | null | undefined;
|
|
58
|
+
searchable?: boolean | null | undefined;
|
|
59
|
+
options?: FieldOption[] | null | undefined;
|
|
60
|
+
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
61
|
+
type: FieldType.Int;
|
|
62
|
+
};
|
|
63
|
+
export declare function boolField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
64
|
+
field?: string | undefined;
|
|
65
|
+
displayName: string | null;
|
|
66
|
+
tags?: string[] | null | undefined;
|
|
67
|
+
system?: boolean | null | undefined;
|
|
68
|
+
collection?: boolean | null | undefined;
|
|
69
|
+
onlyForTypes?: string[] | null | undefined;
|
|
70
|
+
required?: boolean | null | undefined;
|
|
71
|
+
defaultValue?: any;
|
|
72
|
+
isTypeField?: boolean | null | undefined;
|
|
73
|
+
searchable?: boolean | null | undefined;
|
|
74
|
+
options?: FieldOption[] | null | undefined;
|
|
75
|
+
restrictions?: import("./types").SchemaRestrictions | null | undefined;
|
|
76
|
+
type: FieldType.Bool;
|
|
77
|
+
};
|
|
78
|
+
export declare function compoundField<Other extends Partial<Omit<CompoundField, "type" | "schemaType">>>(displayName: string, fields: SchemaField[], other: Other): (name: string) => CompoundField & {
|
|
79
|
+
collection: Other["collection"];
|
|
80
|
+
};
|
|
81
|
+
export declare function defaultScalarField(field: string, displayName: string): Omit<SchemaField, "type"> & {
|
|
82
|
+
type: FieldType.String;
|
|
83
|
+
};
|
|
84
|
+
export declare function defaultCompoundField(field: string, displayName: string, collection: boolean): CompoundField & {
|
|
85
|
+
type: FieldType.Compound;
|
|
86
|
+
};
|
|
87
|
+
export {};
|