@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/lib/index.js CHANGED
@@ -617,7 +617,7 @@ function useDefaultValue(definition, field, formState, hooks) {
617
617
  return field.defaultValue;
618
618
  }
619
619
  function useIsControlVisible(definition, formState, hooks) {
620
- var _definition$dynamic2, _ref2, _onlyForTypes$length;
620
+ var _definition$dynamic2, _schemaField$onlyForT;
621
621
  var visibleExpression = (_definition$dynamic2 = definition.dynamic) == null ? void 0 : _definition$dynamic2.find(function (x) {
622
622
  return x.type === exports.DynamicPropertyType.Visible;
623
623
  });
@@ -629,31 +629,26 @@ function useIsControlVisible(definition, formState, hooks) {
629
629
  };
630
630
  }
631
631
  var schemaFields = formState.fields;
632
- var _useMemo = React.useMemo(function () {
633
- var _ref, _formState$data$field;
634
- var typeField = schemaFields.find(function (x) {
635
- return isScalarField(x) && x.isTypeField;
636
- });
637
- var typeControl = (_ref = typeField && ((_formState$data$field = formState.data.fields) == null ? void 0 : _formState$data$field[typeField.field])) != null ? _ref : core.newControl(undefined);
638
- var compoundField = isGroupControl(definition) && definition.compoundField ? formState.data.fields[definition.compoundField] : undefined;
639
- return {
640
- typeControl: typeControl,
641
- compoundField: compoundField
642
- };
643
- }, [schemaFields, formState.data]),
644
- typeControl = _useMemo.typeControl,
645
- compoundField = _useMemo.compoundField;
632
+ var typeControl = React.useMemo(function () {
633
+ var _ref, _formState$data$field;
634
+ var typeField = schemaFields.find(function (x) {
635
+ return isScalarField(x) && x.isTypeField;
636
+ });
637
+ return (_ref = typeField && ((_formState$data$field = formState.data.fields) == null ? void 0 : _formState$data$field[typeField.field])) != null ? _ref : core.newControl(undefined);
638
+ }, [schemaFields, formState.data]);
646
639
  var fieldName = fieldForControl(definition);
647
- var onlyForTypes = (_ref2 = fieldName ? findField(schemaFields, fieldName) : undefined) == null ? void 0 : _ref2.onlyForTypes;
648
- var canChange = Boolean(compoundField || ((_onlyForTypes$length = onlyForTypes == null ? void 0 : onlyForTypes.length) != null ? _onlyForTypes$length : 0) > 0);
649
- var value = (!compoundField || compoundField.value != null) && (!onlyForTypes || onlyForTypes.length === 0 || Boolean(typeControl.value && onlyForTypes.includes(typeControl.value)));
640
+ var schemaField = fieldName ? findField(schemaFields, fieldName) : undefined;
641
+ var isSingleCompoundField = schemaField && schemaField.type === exports.FieldType.Compound && !schemaField.collection;
642
+ var onlyForTypes = (_schemaField$onlyForT = schemaField == null ? void 0 : schemaField.onlyForTypes) != null ? _schemaField$onlyForT : [];
643
+ var canChange = Boolean(isSingleCompoundField || onlyForTypes.length);
644
+ var value = (!isSingleCompoundField || formState.data.fields[fieldName].value != null) && (!onlyForTypes.length || Boolean(typeControl.value && onlyForTypes.includes(typeControl.value)));
650
645
  return {
651
646
  value: value,
652
647
  canChange: canChange
653
648
  };
654
649
  }
655
650
  function getDefaultScalarControlProperties(definition, field, visible, defaultValue, control, formState) {
656
- var _definition$renderOpt, _definition$required, _ref3, _formState$readonly;
651
+ var _definition$renderOpt, _definition$required, _ref2, _formState$readonly;
657
652
  return {
658
653
  definition: definition,
659
654
  field: field,
@@ -664,7 +659,7 @@ function getDefaultScalarControlProperties(definition, field, visible, defaultVa
664
659
  },
665
660
  required: (_definition$required = definition.required) != null ? _definition$required : false,
666
661
  visible: visible,
667
- readonly: (_ref3 = (_formState$readonly = formState.readonly) != null ? _formState$readonly : definition.readonly) != null ? _ref3 : false,
662
+ readonly: (_ref2 = (_formState$readonly = formState.readonly) != null ? _formState$readonly : definition.readonly) != null ? _ref2 : false,
668
663
  control: control,
669
664
  formState: formState
670
665
  };
@@ -701,6 +696,7 @@ function createDefaultSchemaHooks() {
701
696
  case exports.ExpressionType.FieldValue:
702
697
  var fvExpr = expr;
703
698
  return core.useComputed(function () {
699
+ console.log(fvExpr);
704
700
  var fv = controlForField(fvExpr.field, formState).value;
705
701
  return Array.isArray(fv) ? fv.includes(fvExpr.value) : fv === fvExpr.value;
706
702
  });
@@ -721,9 +717,9 @@ function createDefaultSchemaHooks() {
721
717
  var errorMsg = useExpression(v, formState);
722
718
  core.useControlEffect(function () {
723
719
  return [isVisible, errorMsg.value];
724
- }, function (_ref4) {
725
- var isVisible = _ref4[0],
726
- msg = _ref4[1];
720
+ }, function (_ref3) {
721
+ var isVisible = _ref3[0],
722
+ msg = _ref3[1];
727
723
  return control.setError(v.type + i, isVisible ? msg : null);
728
724
  }, true);
729
725
  break;