@react-typed-forms/schemas 8.2.0 → 9.0.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/lib/controlBuilder.d.ts +9 -2
- package/lib/controlRender.d.ts +12 -11
- package/lib/hooks.d.ts +8 -8
- package/lib/index.js +323 -215
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +1 -0
- package/lib/schemaBuilder.d.ts +5 -2
- package/lib/types.d.ts +9 -1
- package/lib/util.d.ts +12 -0
- package/package.json +2 -2
- package/.babelrc +0 -4
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/operation/update-readme/state.json +0 -3
- package/.rush/temp/package-deps_build.json +0 -13
- package/.rush/temp/shrinkwrap-deps.json +0 -612
- package/src/controlBuilder.ts +0 -175
- package/src/controlRender.tsx +0 -790
- package/src/hooks.tsx +0 -373
- package/src/index.ts +0 -10
- package/src/internal.ts +0 -48
- package/src/renderers.tsx +0 -996
- package/src/schemaBuilder.ts +0 -171
- package/src/schemaInterface.ts +0 -31
- package/src/tailwind.tsx +0 -29
- package/src/types.ts +0 -423
- package/src/util.ts +0 -453
- package/src/validators.ts +0 -116
package/src/controlBuilder.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CompoundField,
|
|
3
|
-
ControlDefinition,
|
|
4
|
-
ControlDefinitionType,
|
|
5
|
-
DataControlDefinition,
|
|
6
|
-
DataMatchExpression,
|
|
7
|
-
DisplayControlDefinition,
|
|
8
|
-
DisplayDataType,
|
|
9
|
-
DynamicProperty,
|
|
10
|
-
DynamicPropertyType,
|
|
11
|
-
EntityExpression,
|
|
12
|
-
ExpressionType,
|
|
13
|
-
GroupedControlsDefinition,
|
|
14
|
-
GroupRenderType,
|
|
15
|
-
HtmlDisplay,
|
|
16
|
-
JsonataExpression,
|
|
17
|
-
SchemaField,
|
|
18
|
-
TextDisplay,
|
|
19
|
-
} from "./types";
|
|
20
|
-
import { ActionRendererProps } from "./controlRender";
|
|
21
|
-
import { useMemo } from "react";
|
|
22
|
-
import { addMissingControls, isCompoundField } from "./util";
|
|
23
|
-
import { mergeField } from "./schemaBuilder";
|
|
24
|
-
|
|
25
|
-
export function dataControl(
|
|
26
|
-
field: string,
|
|
27
|
-
title?: string | null,
|
|
28
|
-
options?: Partial<DataControlDefinition>,
|
|
29
|
-
): DataControlDefinition {
|
|
30
|
-
return { type: ControlDefinitionType.Data, field, title, ...options };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function textDisplayControl(
|
|
34
|
-
text: string,
|
|
35
|
-
options?: Partial<DisplayControlDefinition>,
|
|
36
|
-
): DisplayControlDefinition {
|
|
37
|
-
return {
|
|
38
|
-
type: ControlDefinitionType.Display,
|
|
39
|
-
displayData: { type: DisplayDataType.Text, text } as TextDisplay,
|
|
40
|
-
...options,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function htmlDisplayControl(
|
|
45
|
-
html: string,
|
|
46
|
-
options?: Partial<DisplayControlDefinition>,
|
|
47
|
-
): DisplayControlDefinition {
|
|
48
|
-
return {
|
|
49
|
-
type: ControlDefinitionType.Display,
|
|
50
|
-
displayData: { type: DisplayDataType.Html, html } as HtmlDisplay,
|
|
51
|
-
...options,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function dynamicDefaultValue(expr: EntityExpression): DynamicProperty {
|
|
56
|
-
return { type: DynamicPropertyType.DefaultValue, expr };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function dynamicReadonly(expr: EntityExpression): DynamicProperty {
|
|
60
|
-
return { type: DynamicPropertyType.Readonly, expr };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function dynamicVisibility(expr: EntityExpression): DynamicProperty {
|
|
64
|
-
return { type: DynamicPropertyType.Visible, expr };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function dynamicDisabled(expr: EntityExpression): DynamicProperty {
|
|
68
|
-
return { type: DynamicPropertyType.Disabled, expr };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function fieldEqExpr(field: string, value: any): DataMatchExpression {
|
|
72
|
-
return { type: ExpressionType.DataMatch, field, value };
|
|
73
|
-
}
|
|
74
|
-
export function jsonataExpr(expression: string): JsonataExpression {
|
|
75
|
-
return { type: ExpressionType.Jsonata, expression };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function groupedControl(
|
|
79
|
-
children: ControlDefinition[],
|
|
80
|
-
title?: string,
|
|
81
|
-
options?: Partial<GroupedControlsDefinition>,
|
|
82
|
-
): GroupedControlsDefinition {
|
|
83
|
-
return {
|
|
84
|
-
type: ControlDefinitionType.Group,
|
|
85
|
-
children,
|
|
86
|
-
title,
|
|
87
|
-
groupOptions: { type: "Standard", hideTitle: !title },
|
|
88
|
-
...options,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export function compoundControl(
|
|
92
|
-
field: string,
|
|
93
|
-
title: string | undefined,
|
|
94
|
-
children: ControlDefinition[],
|
|
95
|
-
options?: Partial<DataControlDefinition>,
|
|
96
|
-
): DataControlDefinition {
|
|
97
|
-
return {
|
|
98
|
-
type: ControlDefinitionType.Data,
|
|
99
|
-
field,
|
|
100
|
-
children,
|
|
101
|
-
title,
|
|
102
|
-
renderOptions: { type: "Standard" },
|
|
103
|
-
...options,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function createAction(
|
|
108
|
-
actionId: string,
|
|
109
|
-
onClick: () => void,
|
|
110
|
-
actionText?: string,
|
|
111
|
-
): ActionRendererProps {
|
|
112
|
-
return { actionId, onClick, actionText: actionText ?? actionId };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const emptyGroupDefinition: GroupedControlsDefinition = {
|
|
116
|
-
type: ControlDefinitionType.Group,
|
|
117
|
-
children: [],
|
|
118
|
-
groupOptions: { type: GroupRenderType.Standard, hideTitle: true },
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export function useControlDefinitionForSchema(
|
|
122
|
-
sf: SchemaField[],
|
|
123
|
-
definition: GroupedControlsDefinition = emptyGroupDefinition,
|
|
124
|
-
): GroupedControlsDefinition {
|
|
125
|
-
return useMemo<GroupedControlsDefinition>(
|
|
126
|
-
() => ({
|
|
127
|
-
...definition,
|
|
128
|
-
children: addMissingControls(sf, definition.children ?? []),
|
|
129
|
-
}),
|
|
130
|
-
[sf, definition],
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface CustomRenderOptions {
|
|
135
|
-
value: string;
|
|
136
|
-
name: string;
|
|
137
|
-
fields: SchemaField[];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function addCustomDataRenderOptions(
|
|
141
|
-
controlFields: SchemaField[],
|
|
142
|
-
customRenderOptions: CustomRenderOptions[],
|
|
143
|
-
): SchemaField[] {
|
|
144
|
-
return controlFields.map((x) =>
|
|
145
|
-
x.field === "renderOptions" && isCompoundField(x) ? addRenderOptions(x) : x,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
function addRenderOptions(roField: CompoundField): CompoundField {
|
|
149
|
-
const children = roField.children;
|
|
150
|
-
const withTypes = children.map((x) =>
|
|
151
|
-
x.field === "type" ? addRenderOptionType(x) : x,
|
|
152
|
-
);
|
|
153
|
-
return {
|
|
154
|
-
...roField,
|
|
155
|
-
children: customRenderOptions.reduce(
|
|
156
|
-
(renderOptionFields, ro) =>
|
|
157
|
-
ro.fields
|
|
158
|
-
.map((x) => ({ ...x, onlyForTypes: [ro.value] }))
|
|
159
|
-
.reduce((af, x) => mergeField(x, af), renderOptionFields),
|
|
160
|
-
withTypes,
|
|
161
|
-
),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function addRenderOptionType(typeField: SchemaField): SchemaField {
|
|
166
|
-
const options = typeField.options ?? [];
|
|
167
|
-
return {
|
|
168
|
-
...typeField,
|
|
169
|
-
options: [
|
|
170
|
-
...options,
|
|
171
|
-
...customRenderOptions.map(({ name, value }) => ({ name, value })),
|
|
172
|
-
],
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|