@react-typed-forms/schemas 7.1.0 → 7.2.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/.rush/temp/shrinkwrap-deps.json +229 -215
- package/lib/controlRender.d.ts +1 -0
- package/lib/hooks.d.ts +1 -1
- package/lib/index.js +23 -19
- package/lib/index.js.map +1 -1
- package/lib/schemaBuilder.d.ts +1 -1
- package/lib/util.d.ts +1 -0
- package/package.json +48 -48
- package/src/controlRender.tsx +4 -1
- package/src/hooks.tsx +16 -14
- package/src/schemaBuilder.ts +20 -20
- package/src/util.ts +2 -1
- package/src/validators.ts +5 -1
package/lib/schemaBuilder.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function stringOptionsField(displayName: string, ...options: Fiel
|
|
|
41
41
|
displayName: string;
|
|
42
42
|
options: FieldOption[];
|
|
43
43
|
};
|
|
44
|
-
export declare function withScalarOptions<S extends SchemaField
|
|
44
|
+
export declare function withScalarOptions<S extends SchemaField, S2 extends Partial<SchemaField>>(options: S2, v: (name: string) => S): (name: string) => S & S2;
|
|
45
45
|
export declare function makeScalarField<S extends Partial<SchemaField>>(options: S): (name: string) => SchemaField & S;
|
|
46
46
|
export declare function makeCompoundField<S extends Partial<CompoundField>>(options: S): (name: string) => CompoundField & {
|
|
47
47
|
type: FieldType.Compound;
|
package/lib/util.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
2
|
+
"name": "@react-typed-forms/schemas",
|
|
3
|
+
"version": "7.2.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/doolse/react-typed-forms.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Jolse Maginnis",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/doolse/react-typed-forms/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/doolse/react-typed-forms#readme",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"react",
|
|
22
|
+
"typescript",
|
|
23
|
+
"forms",
|
|
24
|
+
"material-ui"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@react-typed-forms/core": "^3.0.0",
|
|
28
|
+
"clsx": "^1 || ^2",
|
|
29
|
+
"jsonata": "^2.0.4",
|
|
30
|
+
"react": "^18.2.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@react-typed-forms/transform": "^0.2.0",
|
|
34
|
+
"@types/react": "^18.2.28",
|
|
35
|
+
"markdown-magic": "^2.6.1",
|
|
36
|
+
"microbundle": "^0.15.1",
|
|
37
|
+
"nswag": "^13.18.2",
|
|
38
|
+
"prettier": "^3.0.3",
|
|
39
|
+
"rimraf": "^3.0.2",
|
|
40
|
+
"typescript": "^5.2.2"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "698e16cd3ab31b7dd0528fc76536f4d3205ce8c6",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rimraf ./lib/ && microbundle -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
|
|
45
|
+
"watch": "microbundle -w -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
|
|
46
|
+
"update-readme": "md-magic --path README.md",
|
|
47
|
+
"gencode": "nswag swagger2tsclient /input:http://localhost:5216/swagger/v1/swagger.json /runtime:Net60 /output:src/types.ts /GenerateClientClasses:false /MarkOptionalProperties:false /Template:Fetch /TypeStyle:Interface /DateTimeType:string"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/controlRender.tsx
CHANGED
|
@@ -221,6 +221,7 @@ export interface ControlRenderOptions extends FormContextOptions {
|
|
|
221
221
|
useEvalExpressionHook?: UseEvalExpressionHook;
|
|
222
222
|
clearHidden?: boolean;
|
|
223
223
|
schemaInterface?: SchemaInterface;
|
|
224
|
+
dataRoot?: Control<any>;
|
|
224
225
|
}
|
|
225
226
|
export function useControlRenderer(
|
|
226
227
|
definition: ControlDefinition,
|
|
@@ -265,6 +266,7 @@ export function useControlRenderer(
|
|
|
265
266
|
groupControl: parentControl,
|
|
266
267
|
fields,
|
|
267
268
|
schemaInterface,
|
|
269
|
+
root: options.dataRoot ?? parentControl,
|
|
268
270
|
};
|
|
269
271
|
const readonlyControl = useIsReadonly(dataContext);
|
|
270
272
|
const disabledControl = useIsDisabled(dataContext);
|
|
@@ -331,6 +333,7 @@ export function useControlRenderer(
|
|
|
331
333
|
useControlRenderer(cd, childContext.fields, renderer, {
|
|
332
334
|
...options,
|
|
333
335
|
...myOptions,
|
|
336
|
+
dataRoot: dataContext.root,
|
|
334
337
|
}),
|
|
335
338
|
) ?? [];
|
|
336
339
|
useEffect(() => {
|
|
@@ -411,9 +414,9 @@ export function getControlData(
|
|
|
411
414
|
childControl,
|
|
412
415
|
schemaField && isCompoundField(schemaField)
|
|
413
416
|
? {
|
|
417
|
+
...parentContext,
|
|
414
418
|
groupControl: childControl!,
|
|
415
419
|
fields: schemaField.children,
|
|
416
|
-
schemaInterface: parentContext.schemaInterface,
|
|
417
420
|
}
|
|
418
421
|
: parentContext,
|
|
419
422
|
];
|
package/src/hooks.tsx
CHANGED
|
@@ -106,20 +106,20 @@ export function useEvalStyleHook(
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
export function useEvalAllowedOptionsHook(
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
useEvalExpressionHook: UseEvalExpressionHook,
|
|
110
|
+
definition: ControlDefinition,
|
|
111
111
|
): EvalExpressionHook<any[]> {
|
|
112
112
|
const dynamicAllowed = useEvalDynamicHook(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
definition,
|
|
114
|
+
DynamicPropertyType.AllowedOptions,
|
|
115
|
+
useEvalExpressionHook,
|
|
116
116
|
);
|
|
117
117
|
return useCallback(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
(ctx) => {
|
|
119
|
+
if (dynamicAllowed) return dynamicAllowed(ctx);
|
|
120
|
+
return useControl([]);
|
|
121
|
+
},
|
|
122
|
+
[dynamicAllowed],
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -221,6 +221,7 @@ export function defaultEvalHooks(
|
|
|
221
221
|
return useJsonataExpression(
|
|
222
222
|
(expr as JsonataExpression).expression,
|
|
223
223
|
context.groupControl,
|
|
224
|
+
context.root,
|
|
224
225
|
);
|
|
225
226
|
case ExpressionType.Data:
|
|
226
227
|
return useDataExpression(
|
|
@@ -298,20 +299,21 @@ export function hideDisplayOnly(
|
|
|
298
299
|
export function useJsonataExpression(
|
|
299
300
|
jExpr: string,
|
|
300
301
|
data: Control<any>,
|
|
302
|
+
root: Control<any>,
|
|
301
303
|
): Control<any> {
|
|
302
304
|
const compiledExpr = useMemo(() => {
|
|
303
305
|
try {
|
|
304
306
|
return jsonata(jExpr);
|
|
305
307
|
} catch (e) {
|
|
306
308
|
console.error(e);
|
|
307
|
-
return jsonata("");
|
|
309
|
+
return jsonata("null");
|
|
308
310
|
}
|
|
309
311
|
}, [jExpr]);
|
|
310
312
|
const control = useControl();
|
|
311
313
|
useControlEffect(
|
|
312
|
-
() => data.value,
|
|
313
|
-
async (v) => {
|
|
314
|
-
control.value = await compiledExpr.evaluate(v);
|
|
314
|
+
() => [data.value, root.value],
|
|
315
|
+
async ([v, rv]) => {
|
|
316
|
+
control.value = await compiledExpr.evaluate(v, { root: rv });
|
|
315
317
|
},
|
|
316
318
|
true,
|
|
317
319
|
);
|
package/src/schemaBuilder.ts
CHANGED
|
@@ -5,22 +5,22 @@ type AllowedSchema<T> = T extends string
|
|
|
5
5
|
type: FieldType.String | FieldType.Date | FieldType.DateTime;
|
|
6
6
|
}
|
|
7
7
|
: T extends number
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
? SchemaField & {
|
|
9
|
+
type: FieldType.Int | FieldType.Double;
|
|
10
|
+
}
|
|
11
|
+
: T extends boolean
|
|
12
|
+
? SchemaField & {
|
|
13
|
+
type: FieldType.Bool;
|
|
14
|
+
}
|
|
15
|
+
: T extends Array<infer E>
|
|
16
|
+
? AllowedSchema<E> & {
|
|
17
|
+
collection: true;
|
|
18
|
+
}
|
|
19
|
+
: T extends { [key: string]: any }
|
|
20
|
+
? CompoundField & {
|
|
21
|
+
type: FieldType.Compound;
|
|
22
|
+
}
|
|
23
|
+
: SchemaField & { type: FieldType.Any };
|
|
24
24
|
|
|
25
25
|
type AllowedField<T, K> = (
|
|
26
26
|
name: string,
|
|
@@ -56,10 +56,10 @@ export function stringOptionsField(
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export function withScalarOptions<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
): (name: string) => S {
|
|
59
|
+
export function withScalarOptions<
|
|
60
|
+
S extends SchemaField,
|
|
61
|
+
S2 extends Partial<SchemaField>,
|
|
62
|
+
>(options: S2, v: (name: string) => S): (name: string) => S & S2 {
|
|
63
63
|
return (n) => ({ ...v(n), ...options });
|
|
64
64
|
}
|
|
65
65
|
|
package/src/util.ts
CHANGED
|
@@ -22,6 +22,7 @@ import clsx from "clsx";
|
|
|
22
22
|
|
|
23
23
|
export interface ControlDataContext {
|
|
24
24
|
groupControl: Control<any>;
|
|
25
|
+
root: Control<any>;
|
|
25
26
|
fields: SchemaField[];
|
|
26
27
|
schemaInterface: SchemaInterface;
|
|
27
28
|
}
|
|
@@ -318,9 +319,9 @@ export function visitControlData<A>(
|
|
|
318
319
|
const cfResult = visitControlDataArray(
|
|
319
320
|
children,
|
|
320
321
|
{
|
|
322
|
+
...ctx,
|
|
321
323
|
fields: fieldData.children,
|
|
322
324
|
groupControl: c,
|
|
323
|
-
schemaInterface: ctx.schemaInterface,
|
|
324
325
|
},
|
|
325
326
|
cb,
|
|
326
327
|
);
|
package/src/validators.ts
CHANGED
|
@@ -70,7 +70,11 @@ function useJsonataValidator(
|
|
|
70
70
|
hidden: boolean,
|
|
71
71
|
i: number,
|
|
72
72
|
) {
|
|
73
|
-
const errorMsg = useJsonataExpression(
|
|
73
|
+
const errorMsg = useJsonataExpression(
|
|
74
|
+
expr.expression,
|
|
75
|
+
context.groupControl,
|
|
76
|
+
context.root,
|
|
77
|
+
);
|
|
74
78
|
useControlEffect(
|
|
75
79
|
() => [hidden, errorMsg.value],
|
|
76
80
|
([hidden, msg]) => control.setError("jsonata" + i, !hidden ? msg : null),
|