@saas-ui/forms 2.6.9 → 2.6.11

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/dist/index.mjs CHANGED
@@ -53,7 +53,7 @@ var FormValue = ({ name }) => {
53
53
  FormValue.displayName = "FormValue";
54
54
 
55
55
  // src/field.tsx
56
- import * as React6 from "react";
56
+ import * as React7 from "react";
57
57
 
58
58
  // src/fields-context.tsx
59
59
  import React2 from "react";
@@ -487,6 +487,7 @@ var NativeSelect = forwardRef6(
487
487
  NativeSelect.displayName = "NativeSelect";
488
488
 
489
489
  // src/create-field.tsx
490
+ import * as React6 from "react";
490
491
  import { Controller } from "react-hook-form";
491
492
  import { forwardRef as forwardRef7, useMergeRefs } from "@chakra-ui/react";
492
493
  import { callAllHandlers } from "@chakra-ui/utils";
@@ -564,7 +565,10 @@ var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getB
564
565
  };
565
566
  const fieldContext = useFieldsContext();
566
567
  const getBaseField = (_a = fieldContext == null ? void 0 : fieldContext.getBaseField) != null ? _a : getBaseFieldProp;
567
- const { extraProps, BaseField: BaseField2 } = getBaseField();
568
+ const { extraProps, BaseField: BaseField2 } = React6.useMemo(
569
+ () => getBaseField(),
570
+ [getBaseField]
571
+ );
568
572
  const [, inputProps] = splitProps2(
569
573
  props,
570
574
  [
@@ -753,7 +757,7 @@ var defaultFieldTypes = {
753
757
  // src/field.tsx
754
758
  import { jsx as jsx13 } from "react/jsx-runtime";
755
759
  var defaultInputType = "text";
756
- var Field = React6.forwardRef(
760
+ var Field = React7.forwardRef(
757
761
  (props, ref) => {
758
762
  const { type = defaultInputType, name } = props;
759
763
  const overrides = useFieldProps(name);
@@ -763,7 +767,7 @@ var Field = React6.forwardRef(
763
767
  );
764
768
 
765
769
  // src/fields.tsx
766
- import * as React9 from "react";
770
+ import * as React10 from "react";
767
771
 
768
772
  // src/layout.tsx
769
773
  import {
@@ -806,7 +810,7 @@ var FormLayout = ({ children, ...props }) => {
806
810
  FormLayout.displayName = "FormLayout";
807
811
 
808
812
  // src/array-field.tsx
809
- import * as React8 from "react";
813
+ import * as React9 from "react";
810
814
  import {
811
815
  chakra as chakra3,
812
816
  forwardRef as forwardRef11,
@@ -815,7 +819,7 @@ import {
815
819
  import { PlusIcon, MinusIcon } from "@saas-ui/core/icons";
816
820
 
817
821
  // src/use-array-field.tsx
818
- import * as React7 from "react";
822
+ import * as React8 from "react";
819
823
  import {
820
824
  useFieldArray
821
825
  } from "react-hook-form";
@@ -850,7 +854,7 @@ var useArrayField = ({
850
854
  var useArrayFieldRow = ({ index }) => {
851
855
  const { clearErrors } = useFormContext();
852
856
  const { name, remove, fields } = useArrayFieldContext();
853
- React7.useEffect(() => {
857
+ React8.useEffect(() => {
854
858
  clearErrors(name);
855
859
  }, []);
856
860
  return {
@@ -858,7 +862,7 @@ var useArrayFieldRow = ({ index }) => {
858
862
  isFirst: index === 0,
859
863
  isLast: index === fields.length - 1,
860
864
  name: `${name}.${index}`,
861
- remove: React7.useCallback(() => {
865
+ remove: React8.useCallback(() => {
862
866
  clearErrors(name);
863
867
  remove(index);
864
868
  }, [index])
@@ -957,7 +961,7 @@ var ArrayFieldRows = ({
957
961
  return children(fields);
958
962
  };
959
963
  ArrayFieldRows.displayName = "ArrayFieldRows";
960
- var ArrayFieldContainer = React8.forwardRef(
964
+ var ArrayFieldContainer = React9.forwardRef(
961
965
  ({
962
966
  name,
963
967
  defaultValue,
@@ -975,7 +979,7 @@ var ArrayFieldContainer = React8.forwardRef(
975
979
  min: min || (overrides == null ? void 0 : overrides.min),
976
980
  max: max || (overrides == null ? void 0 : overrides.max)
977
981
  });
978
- React8.useImperativeHandle(ref, () => context, [ref, context]);
982
+ React9.useImperativeHandle(ref, () => context, [ref, context]);
979
983
  return /* @__PURE__ */ jsx15(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx15(BaseField, { name, ...fieldProps, ...overrides, children }) });
980
984
  }
981
985
  );
@@ -1044,10 +1048,10 @@ var AutoFields = ({
1044
1048
  const context = useFormContext();
1045
1049
  const schema = schemaProp || context.schema;
1046
1050
  const fieldResolver = fieldResolverProp || context.fieldResolver;
1047
- const resolver = React9.useMemo(() => fieldResolver, [schema, fieldResolver]);
1048
- const fields = React9.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
1051
+ const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
1052
+ const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
1049
1053
  const form = useFormContext();
1050
- React9.useEffect(() => {
1054
+ React10.useEffect(() => {
1051
1055
  var _a;
1052
1056
  if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
1053
1057
  form.setFocus(fields[0].name);
@@ -1126,7 +1130,7 @@ var SubmitButton = forwardRef12(
1126
1130
  SubmitButton.displayName = "SubmitButton";
1127
1131
 
1128
1132
  // src/display-if.tsx
1129
- import * as React10 from "react";
1133
+ import * as React11 from "react";
1130
1134
  import {
1131
1135
  useWatch
1132
1136
  } from "react-hook-form";
@@ -1139,8 +1143,8 @@ var DisplayIf = ({
1139
1143
  condition = (value) => !!value,
1140
1144
  onToggle
1141
1145
  }) => {
1142
- const initializedRef = React10.useRef(false);
1143
- const matchesRef = React10.useRef(false);
1146
+ const initializedRef = React11.useRef(false);
1147
+ const matchesRef = React11.useRef(false);
1144
1148
  const value = useWatch({
1145
1149
  name,
1146
1150
  defaultValue,
@@ -1149,7 +1153,7 @@ var DisplayIf = ({
1149
1153
  });
1150
1154
  const context = useFormContext();
1151
1155
  const matches = condition(value, context);
1152
- React10.useEffect(() => {
1156
+ React11.useEffect(() => {
1153
1157
  if (!initializedRef.current) {
1154
1158
  initializedRef.current = true;
1155
1159
  return;
@@ -1163,7 +1167,7 @@ var DisplayIf = ({
1163
1167
  DisplayIf.displayName = "DisplayIf";
1164
1168
 
1165
1169
  // src/step-form.tsx
1166
- import * as React12 from "react";
1170
+ import * as React13 from "react";
1167
1171
  import {
1168
1172
  chakra as chakra4,
1169
1173
  Button as Button5
@@ -1176,7 +1180,7 @@ import {
1176
1180
  } from "@saas-ui/core";
1177
1181
 
1178
1182
  // src/use-step-form.tsx
1179
- import * as React11 from "react";
1183
+ import * as React12 from "react";
1180
1184
  import { createContext as createContext4 } from "@chakra-ui/react-utils";
1181
1185
  import {
1182
1186
  useStepper,
@@ -1195,11 +1199,11 @@ function useStepForm(props) {
1195
1199
  ...rest
1196
1200
  } = props;
1197
1201
  const stepper = useStepper(rest);
1198
- const [options, setOptions] = React11.useState(stepsOptions);
1202
+ const [options, setOptions] = React12.useState(stepsOptions);
1199
1203
  const { activeStep, isLastStep, nextStep } = stepper;
1200
- const [steps, updateSteps] = React11.useState({});
1201
- const mergedData = React11.useRef({});
1202
- const onSubmitStep = React11.useCallback(
1204
+ const [steps, updateSteps] = React12.useState({});
1205
+ const mergedData = React12.useRef({});
1206
+ const onSubmitStep = React12.useCallback(
1203
1207
  async (data) => {
1204
1208
  var _a, _b;
1205
1209
  try {
@@ -1224,7 +1228,7 @@ function useStepForm(props) {
1224
1228
  },
1225
1229
  [steps, activeStep, isLastStep, mergedData]
1226
1230
  );
1227
- const getFormProps = React11.useCallback(() => {
1231
+ const getFormProps = React12.useCallback(() => {
1228
1232
  const step = steps[activeStep];
1229
1233
  return {
1230
1234
  onSubmit: onSubmitStep,
@@ -1236,7 +1240,7 @@ function useStepForm(props) {
1236
1240
  fieldResolver: (step == null ? void 0 : step.schema) ? fieldResolver == null ? void 0 : fieldResolver(step.schema) : void 0
1237
1241
  };
1238
1242
  }, [steps, onSubmitStep, activeStep, resolver, fieldResolver]);
1239
- const updateStep = React11.useCallback(
1243
+ const updateStep = React12.useCallback(
1240
1244
  (step) => {
1241
1245
  const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
1242
1246
  updateSteps((steps2) => {
@@ -1262,7 +1266,7 @@ function useFormStep(props) {
1262
1266
  const { name, schema, resolver, onSubmit } = props;
1263
1267
  const step = useStep({ name });
1264
1268
  const { steps, updateStep } = useStepFormContext();
1265
- React11.useEffect(() => {
1269
+ React12.useEffect(() => {
1266
1270
  updateStep({ name, schema, resolver, onSubmit });
1267
1271
  }, [name, schema]);
1268
1272
  return {
@@ -1285,8 +1289,8 @@ var FormStepper = (props) => {
1285
1289
  render,
1286
1290
  ...rest
1287
1291
  } = props;
1288
- const elements = React12.Children.map(children, (child) => {
1289
- if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1292
+ const elements = React13.Children.map(children, (child) => {
1293
+ if (React13.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1290
1294
  const { isCompleted } = useFormStep(child.props);
1291
1295
  return /* @__PURE__ */ jsx19(
1292
1296
  StepsItem,
@@ -1302,7 +1306,7 @@ var FormStepper = (props) => {
1302
1306
  }
1303
1307
  return child;
1304
1308
  });
1305
- const onChange = React12.useCallback((i) => {
1309
+ const onChange = React13.useCallback((i) => {
1306
1310
  setIndex(i);
1307
1311
  onChangeProp == null ? void 0 : onChangeProp(i);
1308
1312
  }, []);
@@ -1399,10 +1403,11 @@ var WatchField = (props) => {
1399
1403
  };
1400
1404
 
1401
1405
  // src/create-form.tsx
1406
+ import { useMemo as useMemo3 } from "react";
1402
1407
  import { forwardRef as forwardRef14 } from "@chakra-ui/react";
1403
1408
 
1404
1409
  // src/form.tsx
1405
- import * as React13 from "react";
1410
+ import * as React14 from "react";
1406
1411
  import { chakra as chakra5, forwardRef as forwardRef13 } from "@chakra-ui/react";
1407
1412
  import { cx as cx4, runIfFn } from "@chakra-ui/utils";
1408
1413
  import {
@@ -1450,8 +1455,8 @@ var Form = forwardRef13(
1450
1455
  };
1451
1456
  const methods = useForm(form);
1452
1457
  const { handleSubmit } = methods;
1453
- React13.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1454
- React13.useEffect(() => {
1458
+ React14.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1459
+ React14.useEffect(() => {
1455
1460
  let subscription;
1456
1461
  if (onChange) {
1457
1462
  subscription = methods.watch(onChange);
@@ -1510,10 +1515,13 @@ function createForm({
1510
1515
  fieldResolver: fieldResolverProp,
1511
1516
  ...rest
1512
1517
  } = props;
1513
- const fieldsContext = {
1514
- fields: { ...defaultFieldTypes, ...fields },
1515
- getBaseField
1516
- };
1518
+ const fieldsContext = useMemo3(
1519
+ () => ({
1520
+ fields: { ...defaultFieldTypes, ...fields },
1521
+ getBaseField
1522
+ }),
1523
+ [fields, getBaseField]
1524
+ );
1517
1525
  return /* @__PURE__ */ jsx21(FieldsProvider, { value: fieldsContext, children: /* @__PURE__ */ jsx21(
1518
1526
  Form,
1519
1527
  {
@@ -1531,7 +1539,7 @@ function createForm({
1531
1539
  }
1532
1540
 
1533
1541
  // src/create-step-form.tsx
1534
- import { useMemo as useMemo2 } from "react";
1542
+ import { useMemo as useMemo4 } from "react";
1535
1543
  import { forwardRef as forwardRef15 } from "@chakra-ui/react";
1536
1544
  import { StepperProvider } from "@saas-ui/core";
1537
1545
  import { runIfFn as runIfFn2 } from "@chakra-ui/utils";
@@ -1550,7 +1558,7 @@ function createStepForm({
1550
1558
  ...props
1551
1559
  });
1552
1560
  const { getFormProps, ...ctx } = stepper;
1553
- const context = useMemo2(() => ctx, [ctx]);
1561
+ const context = useMemo4(() => ctx, [ctx]);
1554
1562
  const fieldsContext = {
1555
1563
  fields: {
1556
1564
  ...defaultFieldTypes,