@saas-ui/forms 2.6.9 → 2.6.11

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 2.6.11
4
+
5
+ ### Patch Changes
6
+
7
+ - @saas-ui/core@2.5.6
8
+
9
+ ## 2.6.10
10
+
11
+ ### Patch Changes
12
+
13
+ - fc2203a: Fixed issue where custom base field would trigger additional re-render and loose field focus
14
+
3
15
  ## 2.6.9
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -153,7 +153,7 @@ var FormValue = ({ name }) => {
153
153
  FormValue.displayName = "FormValue";
154
154
 
155
155
  // src/field.tsx
156
- var React6 = __toESM(require("react"));
156
+ var React7 = __toESM(require("react"));
157
157
 
158
158
  // src/fields-context.tsx
159
159
  var import_react2 = __toESM(require("react"));
@@ -541,6 +541,7 @@ var NativeSelect = (0, import_react11.forwardRef)(
541
541
  NativeSelect.displayName = "NativeSelect";
542
542
 
543
543
  // src/create-field.tsx
544
+ var React6 = __toESM(require("react"));
544
545
  var import_react_hook_form3 = require("react-hook-form");
545
546
  var import_react13 = require("@chakra-ui/react");
546
547
  var import_utils4 = require("@chakra-ui/utils");
@@ -612,7 +613,10 @@ var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getB
612
613
  };
613
614
  const fieldContext = useFieldsContext();
614
615
  const getBaseField = (_a = fieldContext == null ? void 0 : fieldContext.getBaseField) != null ? _a : getBaseFieldProp;
615
- const { extraProps, BaseField: BaseField2 } = getBaseField();
616
+ const { extraProps, BaseField: BaseField2 } = React6.useMemo(
617
+ () => getBaseField(),
618
+ [getBaseField]
619
+ );
616
620
  const [, inputProps] = (0, import_core4.splitProps)(
617
621
  props,
618
622
  [
@@ -801,7 +805,7 @@ var defaultFieldTypes = {
801
805
  // src/field.tsx
802
806
  var import_jsx_runtime13 = require("react/jsx-runtime");
803
807
  var defaultInputType = "text";
804
- var Field = React6.forwardRef(
808
+ var Field = React7.forwardRef(
805
809
  (props, ref) => {
806
810
  const { type = defaultInputType, name } = props;
807
811
  const overrides = useFieldProps(name);
@@ -811,7 +815,7 @@ var Field = React6.forwardRef(
811
815
  );
812
816
 
813
817
  // src/fields.tsx
814
- var React9 = __toESM(require("react"));
818
+ var React10 = __toESM(require("react"));
815
819
 
816
820
  // src/layout.tsx
817
821
  var import_react15 = require("@chakra-ui/react");
@@ -848,12 +852,12 @@ var FormLayout = ({ children, ...props }) => {
848
852
  FormLayout.displayName = "FormLayout";
849
853
 
850
854
  // src/array-field.tsx
851
- var React8 = __toESM(require("react"));
855
+ var React9 = __toESM(require("react"));
852
856
  var import_react16 = require("@chakra-ui/react");
853
857
  var import_icons2 = require("@saas-ui/core/icons");
854
858
 
855
859
  // src/use-array-field.tsx
856
- var React7 = __toESM(require("react"));
860
+ var React8 = __toESM(require("react"));
857
861
  var import_react_hook_form4 = require("react-hook-form");
858
862
  var import_react_utils2 = require("@chakra-ui/react-utils");
859
863
  var [ArrayFieldProvider, useArrayFieldContext] = (0, import_react_utils2.createContext)({
@@ -886,7 +890,7 @@ var useArrayField = ({
886
890
  var useArrayFieldRow = ({ index }) => {
887
891
  const { clearErrors } = useFormContext();
888
892
  const { name, remove, fields } = useArrayFieldContext();
889
- React7.useEffect(() => {
893
+ React8.useEffect(() => {
890
894
  clearErrors(name);
891
895
  }, []);
892
896
  return {
@@ -894,7 +898,7 @@ var useArrayFieldRow = ({ index }) => {
894
898
  isFirst: index === 0,
895
899
  isLast: index === fields.length - 1,
896
900
  name: `${name}.${index}`,
897
- remove: React7.useCallback(() => {
901
+ remove: React8.useCallback(() => {
898
902
  clearErrors(name);
899
903
  remove(index);
900
904
  }, [index])
@@ -993,7 +997,7 @@ var ArrayFieldRows = ({
993
997
  return children(fields);
994
998
  };
995
999
  ArrayFieldRows.displayName = "ArrayFieldRows";
996
- var ArrayFieldContainer = React8.forwardRef(
1000
+ var ArrayFieldContainer = React9.forwardRef(
997
1001
  ({
998
1002
  name,
999
1003
  defaultValue,
@@ -1011,7 +1015,7 @@ var ArrayFieldContainer = React8.forwardRef(
1011
1015
  min: min || (overrides == null ? void 0 : overrides.min),
1012
1016
  max: max || (overrides == null ? void 0 : overrides.max)
1013
1017
  });
1014
- React8.useImperativeHandle(ref, () => context, [ref, context]);
1018
+ React9.useImperativeHandle(ref, () => context, [ref, context]);
1015
1019
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BaseField, { name, ...fieldProps, ...overrides, children }) });
1016
1020
  }
1017
1021
  );
@@ -1076,10 +1080,10 @@ var AutoFields = ({
1076
1080
  const context = useFormContext();
1077
1081
  const schema = schemaProp || context.schema;
1078
1082
  const fieldResolver = fieldResolverProp || context.fieldResolver;
1079
- const resolver = React9.useMemo(() => fieldResolver, [schema, fieldResolver]);
1080
- const fields = React9.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
1083
+ const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
1084
+ const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
1081
1085
  const form = useFormContext();
1082
- React9.useEffect(() => {
1086
+ React10.useEffect(() => {
1083
1087
  var _a;
1084
1088
  if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
1085
1089
  form.setFocus(fields[0].name);
@@ -1158,7 +1162,7 @@ var SubmitButton = (0, import_react18.forwardRef)(
1158
1162
  SubmitButton.displayName = "SubmitButton";
1159
1163
 
1160
1164
  // src/display-if.tsx
1161
- var React10 = __toESM(require("react"));
1165
+ var React11 = __toESM(require("react"));
1162
1166
  var import_react_hook_form6 = require("react-hook-form");
1163
1167
  var DisplayIf = ({
1164
1168
  children,
@@ -1169,8 +1173,8 @@ var DisplayIf = ({
1169
1173
  condition = (value) => !!value,
1170
1174
  onToggle
1171
1175
  }) => {
1172
- const initializedRef = React10.useRef(false);
1173
- const matchesRef = React10.useRef(false);
1176
+ const initializedRef = React11.useRef(false);
1177
+ const matchesRef = React11.useRef(false);
1174
1178
  const value = (0, import_react_hook_form6.useWatch)({
1175
1179
  name,
1176
1180
  defaultValue,
@@ -1179,7 +1183,7 @@ var DisplayIf = ({
1179
1183
  });
1180
1184
  const context = useFormContext();
1181
1185
  const matches = condition(value, context);
1182
- React10.useEffect(() => {
1186
+ React11.useEffect(() => {
1183
1187
  if (!initializedRef.current) {
1184
1188
  initializedRef.current = true;
1185
1189
  return;
@@ -1193,13 +1197,13 @@ var DisplayIf = ({
1193
1197
  DisplayIf.displayName = "DisplayIf";
1194
1198
 
1195
1199
  // src/step-form.tsx
1196
- var React12 = __toESM(require("react"));
1200
+ var React13 = __toESM(require("react"));
1197
1201
  var import_react19 = require("@chakra-ui/react");
1198
1202
  var import_utils9 = require("@chakra-ui/utils");
1199
1203
  var import_core6 = require("@saas-ui/core");
1200
1204
 
1201
1205
  // src/use-step-form.tsx
1202
- var React11 = __toESM(require("react"));
1206
+ var React12 = __toESM(require("react"));
1203
1207
  var import_react_utils3 = require("@chakra-ui/react-utils");
1204
1208
  var import_core5 = require("@saas-ui/core");
1205
1209
  var [StepFormProvider, useStepFormContext] = (0, import_react_utils3.createContext)({
@@ -1215,11 +1219,11 @@ function useStepForm(props) {
1215
1219
  ...rest
1216
1220
  } = props;
1217
1221
  const stepper = (0, import_core5.useStepper)(rest);
1218
- const [options, setOptions] = React11.useState(stepsOptions);
1222
+ const [options, setOptions] = React12.useState(stepsOptions);
1219
1223
  const { activeStep, isLastStep, nextStep } = stepper;
1220
- const [steps, updateSteps] = React11.useState({});
1221
- const mergedData = React11.useRef({});
1222
- const onSubmitStep = React11.useCallback(
1224
+ const [steps, updateSteps] = React12.useState({});
1225
+ const mergedData = React12.useRef({});
1226
+ const onSubmitStep = React12.useCallback(
1223
1227
  async (data) => {
1224
1228
  var _a, _b;
1225
1229
  try {
@@ -1244,7 +1248,7 @@ function useStepForm(props) {
1244
1248
  },
1245
1249
  [steps, activeStep, isLastStep, mergedData]
1246
1250
  );
1247
- const getFormProps = React11.useCallback(() => {
1251
+ const getFormProps = React12.useCallback(() => {
1248
1252
  const step = steps[activeStep];
1249
1253
  return {
1250
1254
  onSubmit: onSubmitStep,
@@ -1256,7 +1260,7 @@ function useStepForm(props) {
1256
1260
  fieldResolver: (step == null ? void 0 : step.schema) ? fieldResolver == null ? void 0 : fieldResolver(step.schema) : void 0
1257
1261
  };
1258
1262
  }, [steps, onSubmitStep, activeStep, resolver, fieldResolver]);
1259
- const updateStep = React11.useCallback(
1263
+ const updateStep = React12.useCallback(
1260
1264
  (step) => {
1261
1265
  const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
1262
1266
  updateSteps((steps2) => {
@@ -1282,7 +1286,7 @@ function useFormStep(props) {
1282
1286
  const { name, schema, resolver, onSubmit } = props;
1283
1287
  const step = (0, import_core5.useStep)({ name });
1284
1288
  const { steps, updateStep } = useStepFormContext();
1285
- React11.useEffect(() => {
1289
+ React12.useEffect(() => {
1286
1290
  updateStep({ name, schema, resolver, onSubmit });
1287
1291
  }, [name, schema]);
1288
1292
  return {
@@ -1305,8 +1309,8 @@ var FormStepper = (props) => {
1305
1309
  render,
1306
1310
  ...rest
1307
1311
  } = props;
1308
- const elements = React12.Children.map(children, (child) => {
1309
- if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1312
+ const elements = React13.Children.map(children, (child) => {
1313
+ if (React13.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1310
1314
  const { isCompleted } = useFormStep(child.props);
1311
1315
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1312
1316
  import_core6.StepsItem,
@@ -1322,7 +1326,7 @@ var FormStepper = (props) => {
1322
1326
  }
1323
1327
  return child;
1324
1328
  });
1325
- const onChange = React12.useCallback((i) => {
1329
+ const onChange = React13.useCallback((i) => {
1326
1330
  setIndex(i);
1327
1331
  onChangeProp == null ? void 0 : onChangeProp(i);
1328
1332
  }, []);
@@ -1419,10 +1423,11 @@ var WatchField = (props) => {
1419
1423
  };
1420
1424
 
1421
1425
  // src/create-form.tsx
1422
- var import_react21 = require("@chakra-ui/react");
1426
+ var import_react21 = require("react");
1427
+ var import_react22 = require("@chakra-ui/react");
1423
1428
 
1424
1429
  // src/form.tsx
1425
- var React13 = __toESM(require("react"));
1430
+ var React14 = __toESM(require("react"));
1426
1431
  var import_react20 = require("@chakra-ui/react");
1427
1432
  var import_utils11 = require("@chakra-ui/utils");
1428
1433
  var import_react_hook_form8 = require("react-hook-form");
@@ -1468,8 +1473,8 @@ var Form = (0, import_react20.forwardRef)(
1468
1473
  };
1469
1474
  const methods = (0, import_react_hook_form8.useForm)(form);
1470
1475
  const { handleSubmit } = methods;
1471
- React13.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1472
- React13.useEffect(() => {
1476
+ React14.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1477
+ React14.useEffect(() => {
1473
1478
  let subscription;
1474
1479
  if (onChange) {
1475
1480
  subscription = methods.watch(onChange);
@@ -1520,7 +1525,7 @@ function createForm({
1520
1525
  fields,
1521
1526
  getBaseField
1522
1527
  } = {}) {
1523
- const DefaultForm = (0, import_react21.forwardRef)(
1528
+ const DefaultForm = (0, import_react22.forwardRef)(
1524
1529
  (props, ref) => {
1525
1530
  const {
1526
1531
  schema,
@@ -1528,10 +1533,13 @@ function createForm({
1528
1533
  fieldResolver: fieldResolverProp,
1529
1534
  ...rest
1530
1535
  } = props;
1531
- const fieldsContext = {
1532
- fields: { ...defaultFieldTypes, ...fields },
1533
- getBaseField
1534
- };
1536
+ const fieldsContext = (0, import_react21.useMemo)(
1537
+ () => ({
1538
+ fields: { ...defaultFieldTypes, ...fields },
1539
+ getBaseField
1540
+ }),
1541
+ [fields, getBaseField]
1542
+ );
1535
1543
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldsProvider, { value: fieldsContext, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1536
1544
  Form,
1537
1545
  {
@@ -1549,8 +1557,8 @@ function createForm({
1549
1557
  }
1550
1558
 
1551
1559
  // src/create-step-form.tsx
1552
- var import_react22 = require("react");
1553
- var import_react23 = require("@chakra-ui/react");
1560
+ var import_react23 = require("react");
1561
+ var import_react24 = require("@chakra-ui/react");
1554
1562
  var import_core7 = require("@saas-ui/core");
1555
1563
  var import_utils12 = require("@chakra-ui/utils");
1556
1564
  var import_jsx_runtime22 = require("react/jsx-runtime");
@@ -1560,7 +1568,7 @@ function createStepForm({
1560
1568
  fieldResolver,
1561
1569
  getBaseField
1562
1570
  } = {}) {
1563
- const StepForm2 = (0, import_react23.forwardRef)((props, ref) => {
1571
+ const StepForm2 = (0, import_react24.forwardRef)((props, ref) => {
1564
1572
  const { children, steps, ...rest } = props;
1565
1573
  const stepper = useStepForm({
1566
1574
  resolver,
@@ -1568,7 +1576,7 @@ function createStepForm({
1568
1576
  ...props
1569
1577
  });
1570
1578
  const { getFormProps, ...ctx } = stepper;
1571
- const context = (0, import_react22.useMemo)(() => ctx, [ctx]);
1579
+ const context = (0, import_react23.useMemo)(() => ctx, [ctx]);
1572
1580
  const fieldsContext = {
1573
1581
  fields: {
1574
1582
  ...defaultFieldTypes,