@react-typed-forms/schemas 1.0.0-dev.22 → 1.0.0-dev.24
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/shrinkwrap-deps.json +173 -163
- package/README.md +70 -1
- package/lib/controlBuilder.d.ts +7 -0
- package/lib/controlRender.d.ts +2 -2
- package/lib/hooks.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +113 -83
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +0 -3
- package/package.json +3 -3
- package/src/controlBuilder.ts +55 -0
- package/src/controlRender.tsx +2 -2
- package/src/hooks.tsx +15 -12
- package/src/index.ts +1 -0
- package/src/types.ts +0 -19
package/lib/types.d.ts
CHANGED
|
@@ -259,7 +259,4 @@ export interface ControlVisitor<A> {
|
|
|
259
259
|
action(d: ActionControlDefinition): A;
|
|
260
260
|
}
|
|
261
261
|
export declare function visitControlDefinition<A>(x: ControlDefinition, visitor: ControlVisitor<A>, defaultValue: (c: ControlDefinition) => A): A;
|
|
262
|
-
export declare function dataControl(field: string, options?: Partial<DataControlDefinition>): DataControlDefinition;
|
|
263
|
-
export declare function fieldValueExpr(field: string, value: any): FieldValueExpression;
|
|
264
|
-
export declare function visibility(expr: EntityExpression): DynamicProperty;
|
|
265
262
|
export declare function isGridRenderer(options: GroupRenderOptions): options is GridRenderer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"material-ui"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@react-typed-forms/core": "^3.0.0-dev.
|
|
27
|
+
"@react-typed-forms/core": "^3.0.0-dev.117",
|
|
28
28
|
"clsx": "^1 || ^2",
|
|
29
29
|
"jsonata": "^2.0.3",
|
|
30
30
|
"react": "^18.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@react-typed-forms/transform": "^0.
|
|
33
|
+
"@react-typed-forms/transform": "^0.2.0",
|
|
34
34
|
"@types/react": "^18.2.28",
|
|
35
35
|
"markdown-magic": "^2.6.1",
|
|
36
36
|
"microbundle": "^0.15.1",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ControlDefinitionType,
|
|
3
|
+
DataControlDefinition,
|
|
4
|
+
DisplayControlDefinition,
|
|
5
|
+
DisplayDataType,
|
|
6
|
+
DynamicProperty,
|
|
7
|
+
DynamicPropertyType,
|
|
8
|
+
EntityExpression,
|
|
9
|
+
ExpressionType,
|
|
10
|
+
FieldValueExpression,
|
|
11
|
+
HtmlDisplay,
|
|
12
|
+
JsonataExpression,
|
|
13
|
+
TextDisplay,
|
|
14
|
+
} from "./types";
|
|
15
|
+
|
|
16
|
+
export function dataControl(
|
|
17
|
+
field: string,
|
|
18
|
+
title?: string | null,
|
|
19
|
+
options?: Partial<DataControlDefinition>,
|
|
20
|
+
): DataControlDefinition {
|
|
21
|
+
return { type: ControlDefinitionType.Data, field, title, ...options };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function textDisplayControl(
|
|
25
|
+
text: string,
|
|
26
|
+
options?: Partial<DisplayControlDefinition>,
|
|
27
|
+
): DisplayControlDefinition {
|
|
28
|
+
return {
|
|
29
|
+
type: ControlDefinitionType.Display,
|
|
30
|
+
displayData: { type: DisplayDataType.Text, text } as TextDisplay,
|
|
31
|
+
...options,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function htmlDisplayControl(
|
|
36
|
+
html: string,
|
|
37
|
+
options?: Partial<DisplayControlDefinition>,
|
|
38
|
+
): DisplayControlDefinition {
|
|
39
|
+
return {
|
|
40
|
+
type: ControlDefinitionType.Display,
|
|
41
|
+
displayData: { type: DisplayDataType.Html, html } as HtmlDisplay,
|
|
42
|
+
...options,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function visibility(expr: EntityExpression): DynamicProperty {
|
|
47
|
+
return { type: DynamicPropertyType.Visible, expr };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function fieldEqExpr(field: string, value: any): FieldValueExpression {
|
|
51
|
+
return { type: ExpressionType.FieldValue, field, value };
|
|
52
|
+
}
|
|
53
|
+
export function jsonataExpr(expression: string): JsonataExpression {
|
|
54
|
+
return { type: ExpressionType.Jsonata, expression };
|
|
55
|
+
}
|
package/src/controlRender.tsx
CHANGED
|
@@ -33,7 +33,7 @@ export interface SchemaHooks {
|
|
|
33
33
|
): Control<any | undefined>;
|
|
34
34
|
useValidators(
|
|
35
35
|
formState: FormEditState,
|
|
36
|
-
isVisible: boolean,
|
|
36
|
+
isVisible: boolean | undefined,
|
|
37
37
|
control: Control<any>,
|
|
38
38
|
required: boolean,
|
|
39
39
|
validations?: SchemaValidator[] | null,
|
|
@@ -137,7 +137,7 @@ export interface FormRenderer {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
export interface Visibility {
|
|
140
|
-
value: boolean;
|
|
140
|
+
value: boolean | undefined;
|
|
141
141
|
canChange: boolean;
|
|
142
142
|
}
|
|
143
143
|
export interface LabelRendererProps {
|
package/src/hooks.tsx
CHANGED
|
@@ -84,7 +84,7 @@ export function useIsControlVisible(
|
|
|
84
84
|
formState,
|
|
85
85
|
).value;
|
|
86
86
|
return {
|
|
87
|
-
value:
|
|
87
|
+
value: exprValue,
|
|
88
88
|
canChange: true,
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -170,6 +170,7 @@ export function createDefaultSchemaHooks(): SchemaHooks {
|
|
|
170
170
|
async (v) => {
|
|
171
171
|
control.value = await compiledExpr.evaluate(v);
|
|
172
172
|
},
|
|
173
|
+
true,
|
|
173
174
|
);
|
|
174
175
|
return control;
|
|
175
176
|
case ExpressionType.FieldValue:
|
|
@@ -187,7 +188,7 @@ export function createDefaultSchemaHooks(): SchemaHooks {
|
|
|
187
188
|
|
|
188
189
|
function useValidators(
|
|
189
190
|
formState: FormEditState,
|
|
190
|
-
isVisible: boolean,
|
|
191
|
+
isVisible: boolean | undefined,
|
|
191
192
|
control: Control<any>,
|
|
192
193
|
required: boolean,
|
|
193
194
|
validators?: SchemaValidator[] | null,
|
|
@@ -196,7 +197,9 @@ export function createDefaultSchemaHooks(): SchemaHooks {
|
|
|
196
197
|
useValidator(
|
|
197
198
|
control,
|
|
198
199
|
(v) =>
|
|
199
|
-
isVisible && (v == null || v
|
|
200
|
+
isVisible === true && (v == null || v === "")
|
|
201
|
+
? "Please enter a value"
|
|
202
|
+
: null,
|
|
200
203
|
"required",
|
|
201
204
|
);
|
|
202
205
|
validators?.forEach((v, i) => {
|
|
@@ -276,7 +279,7 @@ export function createFormEditHooks(schemaHooks: SchemaHooks): FormEditHooks {
|
|
|
276
279
|
const scalarControl = formState.data.fields[field.field];
|
|
277
280
|
|
|
278
281
|
useEffect(() => {
|
|
279
|
-
if (
|
|
282
|
+
if (isVisible === false) scalarControl.value = null;
|
|
280
283
|
else if (scalarControl.current.value == null) {
|
|
281
284
|
scalarControl.value = defaultValue;
|
|
282
285
|
}
|
|
@@ -331,7 +334,7 @@ export function createFormEditHooks(schemaHooks: SchemaHooks): FormEditHooks {
|
|
|
331
334
|
const newFs: RenderControlOptions = {
|
|
332
335
|
...fs,
|
|
333
336
|
fields: field ? field.children : fs.fields,
|
|
334
|
-
invisible:
|
|
337
|
+
invisible: visible.value === false || fs.invisible,
|
|
335
338
|
};
|
|
336
339
|
const data = field ? fs.data.fields[field.field] : fs.data;
|
|
337
340
|
const groupProps = {
|
|
@@ -419,7 +422,7 @@ function defaultArrayRendererProps(
|
|
|
419
422
|
};
|
|
420
423
|
}
|
|
421
424
|
|
|
422
|
-
const emptyGroupDefinition: GroupedControlsDefinition = {
|
|
425
|
+
export const emptyGroupDefinition: GroupedControlsDefinition = {
|
|
423
426
|
type: ControlDefinitionType.Group,
|
|
424
427
|
children: [],
|
|
425
428
|
groupOptions: { type: GroupRenderType.Standard, hideTitle: true },
|
|
@@ -428,12 +431,12 @@ const emptyGroupDefinition: GroupedControlsDefinition = {
|
|
|
428
431
|
export function useControlDefinitionForSchema(
|
|
429
432
|
sf: SchemaField[],
|
|
430
433
|
definition: GroupedControlsDefinition = emptyGroupDefinition,
|
|
431
|
-
) {
|
|
432
|
-
return useMemo(
|
|
433
|
-
() =>
|
|
434
|
-
definition
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
): GroupedControlsDefinition {
|
|
435
|
+
return useMemo<GroupedControlsDefinition>(
|
|
436
|
+
() => ({
|
|
437
|
+
...definition,
|
|
438
|
+
children: addMissingControls(sf, definition.children),
|
|
439
|
+
}),
|
|
437
440
|
[sf, definition],
|
|
438
441
|
);
|
|
439
442
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -352,25 +352,6 @@ export function visitControlDefinition<A>(
|
|
|
352
352
|
return defaultValue(x);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
|
-
|
|
356
|
-
export function dataControl(
|
|
357
|
-
field: string,
|
|
358
|
-
options?: Partial<DataControlDefinition>,
|
|
359
|
-
): DataControlDefinition {
|
|
360
|
-
return { type: ControlDefinitionType.Data, field, ...options };
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export function fieldValueExpr(
|
|
364
|
-
field: string,
|
|
365
|
-
value: any,
|
|
366
|
-
): FieldValueExpression {
|
|
367
|
-
return { type: ExpressionType.FieldValue, field, value };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
export function visibility(expr: EntityExpression): DynamicProperty {
|
|
371
|
-
return { type: DynamicPropertyType.Visible, expr };
|
|
372
|
-
}
|
|
373
|
-
|
|
374
355
|
export function isGridRenderer(
|
|
375
356
|
options: GroupRenderOptions,
|
|
376
357
|
): options is GridRenderer {
|