@react-typed-forms/schemas 1.0.0-dev.2 → 1.0.0-dev.20
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/package-deps_build.json +7 -7
- package/.rush/temp/shrinkwrap-deps.json +458 -7
- package/lib/controlRender.d.ts +81 -64
- package/lib/hooks.d.ts +11 -9
- package/lib/index.d.ts +3 -0
- package/lib/index.js +1621 -19
- package/lib/index.js.map +1 -0
- package/lib/renderers.d.ts +154 -0
- package/lib/schemaBuilder.d.ts +38 -34
- package/lib/tailwind.d.ts +2 -0
- package/lib/types.d.ts +101 -36
- package/lib/util.d.ts +22 -0
- package/package.json +13 -8
- package/src/controlRender.tsx +229 -321
- package/src/hooks.tsx +441 -0
- package/src/index.ts +3 -0
- package/src/renderers.tsx +870 -0
- package/src/schemaBuilder.ts +7 -4
- package/src/tailwind.tsx +21 -0
- package/src/types.ts +173 -39
- package/src/util.ts +212 -0
- package/tsconfig.json +4 -3
- package/lib/controlRender.js +0 -230
- package/lib/hooks.js +0 -93
- package/lib/schemaBuilder.js +0 -67
- package/lib/types.js +0 -68
- package/schemas.build.log +0 -2
- package/src/hooks.ts +0 -164
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
import { ActionControlDefinition,
|
|
2
|
-
import React, { Key, ReactElement } from "react";
|
|
1
|
+
import { ActionControlDefinition, AdornmentPlacement, CompoundField, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayControlDefinition, EntityExpression, FieldOption, GroupedControlsDefinition, RenderOptions, SchemaField, SchemaValidator } from "./types";
|
|
2
|
+
import React, { Key, ReactElement, ReactNode } from "react";
|
|
3
3
|
import { Control } from "@react-typed-forms/core";
|
|
4
|
+
export interface SchemaHooks {
|
|
5
|
+
useExpression(expr: EntityExpression, formState: FormEditState): Control<any | undefined>;
|
|
6
|
+
useValidators(formState: FormEditState, isVisible: boolean, control: Control<any>, required: boolean, validations?: SchemaValidator[] | null): void;
|
|
7
|
+
}
|
|
4
8
|
export interface FormEditHooks {
|
|
5
|
-
useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: SchemaField):
|
|
6
|
-
useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition, currentHooks: FormEditHooks):
|
|
7
|
-
useDisplayProperties(formState: FormEditState, definition: DisplayControlDefinition):
|
|
8
|
-
useActionProperties(formState: FormEditState, definition: ActionControlDefinition):
|
|
9
|
+
useDataProperties(formState: FormEditState, definition: DataControlDefinition, field: SchemaField, renderers: FormRenderer): DataRendererProps;
|
|
10
|
+
useGroupProperties(formState: FormEditState, definition: GroupedControlsDefinition, currentHooks: FormEditHooks, renderers: FormRenderer): GroupRendererProps;
|
|
11
|
+
useDisplayProperties(formState: FormEditState, definition: DisplayControlDefinition): DisplayRendererProps;
|
|
12
|
+
useActionProperties(formState: FormEditState, definition: ActionControlDefinition): ActionRendererProps;
|
|
13
|
+
schemaHooks: SchemaHooks;
|
|
9
14
|
}
|
|
10
|
-
export interface
|
|
15
|
+
export interface DataRendererProps {
|
|
16
|
+
definition: DataControlDefinition;
|
|
17
|
+
renderOptions: RenderOptions;
|
|
18
|
+
visible: Visibility;
|
|
19
|
+
control: Control<any>;
|
|
20
|
+
field: SchemaField;
|
|
21
|
+
array?: ArrayRendererProps;
|
|
11
22
|
readonly: boolean;
|
|
12
|
-
visible: boolean;
|
|
13
|
-
options: FieldOption[] | undefined;
|
|
14
23
|
defaultValue: any;
|
|
15
24
|
required: boolean;
|
|
16
|
-
|
|
25
|
+
options: FieldOption[] | undefined | null;
|
|
26
|
+
customRender?: (props: DataRendererProps) => ReactElement;
|
|
27
|
+
formState: FormEditState;
|
|
17
28
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
29
|
+
export interface GroupRendererProps {
|
|
30
|
+
definition: Omit<GroupedControlsDefinition, "children">;
|
|
31
|
+
visible: Visibility;
|
|
32
|
+
field?: CompoundField;
|
|
33
|
+
array?: ArrayRendererProps;
|
|
34
|
+
hideTitle: boolean;
|
|
20
35
|
hooks: FormEditHooks;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
visible: boolean;
|
|
24
|
-
}
|
|
25
|
-
export interface ActionControlProperties {
|
|
26
|
-
visible: boolean;
|
|
27
|
-
onClick: () => void;
|
|
36
|
+
childCount: number;
|
|
37
|
+
renderChild: (child: number) => ReactElement;
|
|
28
38
|
}
|
|
29
39
|
export interface ControlData {
|
|
30
40
|
[field: string]: any;
|
|
@@ -33,63 +43,70 @@ export interface FormEditState {
|
|
|
33
43
|
fields: SchemaField[];
|
|
34
44
|
data: Control<ControlData>;
|
|
35
45
|
readonly?: boolean;
|
|
46
|
+
invisible?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface ArrayRendererProps {
|
|
49
|
+
definition: DataControlDefinition | GroupedControlsDefinition;
|
|
50
|
+
control: Control<any[]>;
|
|
51
|
+
field: SchemaField;
|
|
52
|
+
addAction?: ActionRendererProps;
|
|
53
|
+
removeAction?: (childCount: number) => ActionRendererProps;
|
|
54
|
+
childCount: number;
|
|
55
|
+
renderChild: (childCount: number) => ReactElement;
|
|
56
|
+
childKey: (childCount: number) => Key;
|
|
57
|
+
}
|
|
58
|
+
export interface AdornmentProps {
|
|
59
|
+
key: Key;
|
|
60
|
+
definition: ControlAdornment;
|
|
36
61
|
}
|
|
37
|
-
export interface
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
export interface AdornmentRenderer {
|
|
63
|
+
wrap?: (children: ReactElement) => ReactElement;
|
|
64
|
+
child?: [AdornmentPlacement, ReactNode];
|
|
65
|
+
}
|
|
66
|
+
export interface FormRenderer {
|
|
67
|
+
renderData: (props: DataRendererProps) => ReactElement;
|
|
40
68
|
renderGroup: (props: GroupRendererProps) => ReactElement;
|
|
41
69
|
renderDisplay: (props: DisplayRendererProps) => ReactElement;
|
|
42
70
|
renderAction: (props: ActionRendererProps) => ReactElement;
|
|
71
|
+
renderArray: (props: ArrayRendererProps) => ReactElement;
|
|
72
|
+
renderLabel: (props: LabelRendererProps, elem: ReactElement) => ReactElement;
|
|
73
|
+
renderVisibility: (visible: Visibility, elem: ReactElement) => ReactElement;
|
|
74
|
+
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
75
|
+
}
|
|
76
|
+
export declare function FormRendererProvider({ value, children, }: {
|
|
77
|
+
value: FormRenderer;
|
|
78
|
+
children: ReactNode;
|
|
79
|
+
}): React.JSX.Element;
|
|
80
|
+
export declare function useFormRendererComponents(): FormRenderer;
|
|
81
|
+
export interface Visibility {
|
|
82
|
+
value: boolean;
|
|
83
|
+
canChange: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface LabelRendererProps {
|
|
86
|
+
visible: Visibility;
|
|
87
|
+
title?: ReactNode;
|
|
88
|
+
forId?: string;
|
|
89
|
+
required: boolean;
|
|
90
|
+
control?: Control<any>;
|
|
91
|
+
group?: boolean;
|
|
92
|
+
renderAdornment: (placement: AdornmentPlacement) => ReactElement;
|
|
43
93
|
}
|
|
44
|
-
export declare const FormRendererComponentsContext: React.Context<FormRendererComponents | undefined>;
|
|
45
|
-
export declare function useFormRendererComponents(): FormRendererComponents;
|
|
46
94
|
export interface DisplayRendererProps {
|
|
47
95
|
definition: DisplayControlDefinition;
|
|
48
|
-
|
|
96
|
+
visible: Visibility;
|
|
49
97
|
}
|
|
50
98
|
export interface ActionRendererProps {
|
|
51
99
|
definition: ActionControlDefinition;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export interface DataRendererProps {
|
|
55
|
-
definition: DataControlDefinition;
|
|
56
|
-
properties: DataControlProperties;
|
|
57
|
-
field: SchemaField;
|
|
58
|
-
formEditState?: FormEditState;
|
|
59
|
-
}
|
|
60
|
-
export interface GroupRendererProps {
|
|
61
|
-
definition: Omit<GroupedControlsDefinition, "children">;
|
|
62
|
-
properties: GroupControlProperties;
|
|
63
|
-
childCount: number;
|
|
64
|
-
renderChild: (child: number, wrapChild: (key: Key, childElem: ReactElement) => ReactElement) => ReactElement;
|
|
65
|
-
}
|
|
66
|
-
export interface CompoundGroupRendererProps {
|
|
67
|
-
definition: GroupedControlsDefinition;
|
|
68
|
-
field: CompoundField;
|
|
69
|
-
properties: GroupControlProperties;
|
|
70
|
-
renderChild: (key: Key, control: ControlDefinition, data: Control<{
|
|
71
|
-
[field: string]: any;
|
|
72
|
-
}>, wrapChild: (key: Key, childElem: ReactElement) => ReactElement) => ReactElement;
|
|
100
|
+
visible: Visibility;
|
|
101
|
+
onClick: () => void;
|
|
73
102
|
}
|
|
74
|
-
export declare function isScalarField(sf: SchemaField): sf is SchemaField;
|
|
75
|
-
export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
|
|
76
103
|
export type AnySchemaFields = SchemaField | (Omit<CompoundField, "children"> & {
|
|
77
104
|
children: AnySchemaFields[];
|
|
78
105
|
});
|
|
79
|
-
export declare function
|
|
80
|
-
|
|
81
|
-
} | undefined, fields: SchemaField[]): any;
|
|
82
|
-
export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean): any;
|
|
83
|
-
export declare function defaultValueForFields(fields: SchemaField[]): any;
|
|
84
|
-
export declare function defaultValueForField(sf: SchemaField): any;
|
|
85
|
-
export declare function elementValueForField(sf: SchemaField): any;
|
|
86
|
-
export declare function findScalarField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
87
|
-
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
88
|
-
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
89
|
-
export declare function fieldDisplayName(sf: SchemaField): string;
|
|
90
|
-
export declare function controlTitle(title: string | undefined, field: SchemaField): string;
|
|
91
|
-
export declare function renderControl(definition: AnyControlDefinition, formState: FormEditState, hooks: FormEditHooks, key: Key, wrapChild?: (key: Key, db: ReactElement) => ReactElement): ReactElement;
|
|
106
|
+
export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
|
|
107
|
+
export declare function renderControl<S extends ControlDefinition>(definition: S, formState: FormEditState, hooks: FormEditHooks, key: Key): ReactElement;
|
|
92
108
|
export declare function controlForField(field: string, formState: FormEditState): Control<any>;
|
|
93
|
-
export declare function fieldForControl(c: ControlDefinition): string | undefined;
|
|
94
|
-
export declare
|
|
95
|
-
export declare function
|
|
109
|
+
export declare function fieldForControl(c: ControlDefinition): string | null | undefined;
|
|
110
|
+
export declare const AlwaysVisible: Visibility;
|
|
111
|
+
export declare function createAction(label: string, onClick: () => void, actionId?: string): ActionRendererProps;
|
|
112
|
+
export declare function visitControlData<S extends ControlDefinition, A>(definition: S, { fields, data }: FormEditState, cb: (definition: DataControlDefinition, control: Control<any>) => A | undefined): A | undefined;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function useDefaultValue(definition: DataControlDefinition, field: SchemaField, formState: FormEditState,
|
|
5
|
-
export declare function useIsControlVisible(definition: ControlDefinition, formState: FormEditState,
|
|
6
|
-
export declare function getDefaultScalarControlProperties(
|
|
7
|
-
export declare function getOptionsForScalarField(field: SchemaField): FieldOption[] | undefined;
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
1
|
+
import { ControlDefinition, DataControlDefinition, FieldOption, GroupedControlsDefinition, SchemaField } from "./types";
|
|
2
|
+
import { DataRendererProps, FormEditHooks, FormEditState, SchemaHooks, Visibility } from "./controlRender";
|
|
3
|
+
import { Control } from "@react-typed-forms/core";
|
|
4
|
+
export declare function useDefaultValue(definition: DataControlDefinition, field: SchemaField, formState: FormEditState, hooks: SchemaHooks): any;
|
|
5
|
+
export declare function useIsControlVisible(definition: ControlDefinition, formState: FormEditState, hooks: SchemaHooks): Visibility;
|
|
6
|
+
export declare function getDefaultScalarControlProperties(definition: DataControlDefinition, field: SchemaField, visible: Visibility, defaultValue: any, control: Control<any>, formState: FormEditState): DataRendererProps;
|
|
7
|
+
export declare function getOptionsForScalarField(field: SchemaField): FieldOption[] | undefined | null;
|
|
8
|
+
export declare function createDefaultSchemaHooks(): SchemaHooks;
|
|
9
|
+
export declare const defaultFormEditHooks: FormEditHooks;
|
|
10
|
+
export declare function createFormEditHooks(schemaHooks: SchemaHooks): FormEditHooks;
|
|
11
|
+
export declare function useControlsWithDefaults(definition: GroupedControlsDefinition, sf: SchemaField[]): GroupedControlsDefinition;
|