@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-typed-forms/schemas",
3
- "version": "1.0.0-dev.24",
3
+ "version": "1.0.0-dev.25",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
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 { typeControl, compoundField } = useMemo(() => {
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
- const typeControl = ((typeField &&
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 onlyForTypes = (
110
- fieldName ? findField(schemaFields, fieldName) : undefined
111
- )?.onlyForTypes;
112
- const canChange = Boolean(compoundField || (onlyForTypes?.length ?? 0) > 0);
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
- (!compoundField || compoundField.value != null) &&
115
- (!onlyForTypes ||
116
- onlyForTypes.length === 0 ||
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)