@react-typed-forms/schemas 1.0.0-dev.24 → 1.0.0-dev.25
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 +163 -172
- package/lib/index.js +19 -23
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks.tsx +16 -16
package/package.json
CHANGED
package/src/hooks.tsx
CHANGED
|
@@ -51,9 +51,9 @@ import {
|
|
|
51
51
|
elementValueForField,
|
|
52
52
|
findCompoundField,
|
|
53
53
|
findField,
|
|
54
|
-
isGroupControl,
|
|
55
54
|
isScalarField,
|
|
56
55
|
} from "./util";
|
|
56
|
+
import { FieldType } from "./types";
|
|
57
57
|
|
|
58
58
|
export function useDefaultValue(
|
|
59
59
|
definition: DataControlDefinition,
|
|
@@ -90,30 +90,29 @@ export function useIsControlVisible(
|
|
|
90
90
|
}
|
|
91
91
|
const schemaFields = formState.fields;
|
|
92
92
|
|
|
93
|
-
const
|
|
93
|
+
const typeControl = useMemo(() => {
|
|
94
94
|
const typeField = schemaFields.find(
|
|
95
95
|
(x) => isScalarField(x) && x.isTypeField,
|
|
96
96
|
) as SchemaField | undefined;
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
formState.data.fields?.[typeField.field]) ??
|
|
98
|
+
return ((typeField && formState.data.fields?.[typeField.field]) ??
|
|
100
99
|
newControl(undefined)) as Control<string | undefined>;
|
|
101
|
-
const compoundField =
|
|
102
|
-
isGroupControl(definition) && definition.compoundField
|
|
103
|
-
? formState.data.fields[definition.compoundField]
|
|
104
|
-
: undefined;
|
|
105
|
-
return { typeControl, compoundField };
|
|
106
100
|
}, [schemaFields, formState.data]);
|
|
107
101
|
|
|
108
102
|
const fieldName = fieldForControl(definition);
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
103
|
+
const schemaField = fieldName
|
|
104
|
+
? findField(schemaFields, fieldName)
|
|
105
|
+
: undefined;
|
|
106
|
+
const isSingleCompoundField =
|
|
107
|
+
schemaField &&
|
|
108
|
+
schemaField.type === FieldType.Compound &&
|
|
109
|
+
!schemaField.collection;
|
|
110
|
+
const onlyForTypes = schemaField?.onlyForTypes ?? [];
|
|
111
|
+
const canChange = Boolean(isSingleCompoundField || onlyForTypes.length);
|
|
113
112
|
const value =
|
|
114
|
-
(!
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
(!isSingleCompoundField ||
|
|
114
|
+
formState.data.fields[fieldName!].value != null) &&
|
|
115
|
+
(!onlyForTypes.length ||
|
|
117
116
|
Boolean(typeControl.value && onlyForTypes.includes(typeControl.value)));
|
|
118
117
|
return { value, canChange };
|
|
119
118
|
}
|
|
@@ -176,6 +175,7 @@ export function createDefaultSchemaHooks(): SchemaHooks {
|
|
|
176
175
|
case ExpressionType.FieldValue:
|
|
177
176
|
const fvExpr = expr as FieldValueExpression;
|
|
178
177
|
return useComputed(() => {
|
|
178
|
+
console.log(fvExpr);
|
|
179
179
|
const fv = controlForField(fvExpr.field, formState).value;
|
|
180
180
|
return Array.isArray(fv)
|
|
181
181
|
? fv.includes(fvExpr.value)
|