@saas-ui/forms 3.0.0-alpha.12 → 3.0.0-alpha.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 3.0.0-alpha.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0067207]
8
+ - Updated dependencies [0067207]
9
+ - @saas-ui/react@3.0.0-alpha.14
10
+
11
+ ## 3.0.0-alpha.13
12
+
13
+ ### Major Changes
14
+
15
+ - b51aff9: BREAKING: getBaseField should now return props and Component
16
+
17
+ ### Patch Changes
18
+
19
+ - b51aff9: Improved prop handling of base field
20
+ - Updated dependencies [b51aff9]
21
+ - Updated dependencies [b51aff9]
22
+ - @saas-ui/react@3.0.0-alpha.13
23
+
3
24
  ## 3.0.0-alpha.12
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -46,7 +46,10 @@ declare const TextareaField: React__default.FC<Omit<BaseFieldProps<react_hook_fo
46
46
  interface SwitchFieldProps extends SwitchProps {
47
47
  type: 'switch';
48
48
  }
49
- interface SelectFieldProps extends Omit<Select.RootProps<FieldOption>, 'collection'> {
49
+ interface SelectFieldProps<Multiple extends boolean = boolean> extends Omit<Select.RootProps<FieldOption>, 'collection' | 'value' | 'multiple' | 'onChange' | 'onValueChange'> {
50
+ multiple?: Multiple;
51
+ value?: Multiple extends true ? Array<string> : string;
52
+ onChange?: (value: Multiple extends true ? Array<string> : string) => void;
50
53
  options: FieldOptions;
51
54
  placeholder?: string;
52
55
  triggerProps?: Select.TriggerProps;
@@ -80,7 +83,7 @@ declare const defaultFieldTypes: {
80
83
  checkbox: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof CheckboxFieldProps> & CheckboxFieldProps>;
81
84
  radio: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof RadioFieldProps> & RadioFieldProps>;
82
85
  password: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof PasswordInputProps> & PasswordInputProps>;
83
- select: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SelectFieldProps> & SelectFieldProps>;
86
+ select: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SelectFieldProps<boolean>> & SelectFieldProps<boolean>>;
84
87
  switch: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SwitchFieldProps> & SwitchFieldProps>;
85
88
  textarea: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof TextareaFieldProps> & TextareaFieldProps>;
86
89
  };
@@ -336,8 +339,14 @@ interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName e
336
339
  children?: React.ReactNode;
337
340
  }
338
341
  type GetBaseField<TProps extends object = object> = () => {
339
- extraProps: string[];
340
- BaseField: React.FC<Omit<BaseFieldProps, 'name'> & {
342
+ /**
343
+ * Extra props to pass to the component
344
+ */
345
+ props: Array<Extract<keyof TProps, string>>;
346
+ /**
347
+ * The component to render
348
+ */
349
+ Component: React.FC<Omit<BaseFieldProps, 'name'> & {
341
350
  name: string;
342
351
  children: React.ReactNode;
343
352
  } & TProps>;
@@ -529,9 +538,9 @@ interface FieldsProps<TSchema = any> {
529
538
  }
530
539
  declare const AutoFields: React$1.FC<FieldsProps>;
531
540
 
532
- interface FieldsContextValue {
533
- fields: Record<string, React__default.FC<any>>;
534
- getBaseField?: GetBaseField<any>;
541
+ interface FieldsContextValue<TFields = any, TBaseFieldProps extends object = object> {
542
+ fields: Record<string, React__default.FC<TFields>>;
543
+ getBaseField?: GetBaseField<TBaseFieldProps>;
535
544
  }
536
545
  declare const FieldsProvider: React__default.FC<{
537
546
  value: FieldsContextValue;
@@ -581,17 +590,21 @@ interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = Fi
581
590
  declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object>(props: WatchFieldProps<Value, TFieldValues, TContext>) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
582
591
 
583
592
  declare const useBaseField: (props: BaseFieldProps) => {
584
- controlProps: Pick<BaseFieldProps<react_hook_form.FieldValues, string>, never>;
593
+ rootProps: Omit<BaseFieldProps<react_hook_form.FieldValues, string>, "name" | "label" | "hideLabel" | "help" | "rules" | "type" | "placeholder" | "children">;
585
594
  error: any;
586
595
  touched: any;
587
596
  name: string;
588
597
  label?: string | undefined;
589
598
  hideLabel?: boolean | undefined;
590
599
  help?: string | undefined;
600
+ rules?: Omit<react_hook_form.RegisterOptions<react_hook_form.FieldValues, string>, "disabled" | "setValueAs" | "valueAsNumber" | "valueAsDate"> | undefined;
601
+ type?: string | undefined;
602
+ placeholder?: string | undefined;
603
+ children?: React$1.ReactNode;
591
604
  };
592
605
  /**
593
606
  * The default BaseField component
594
- * Composes the Chakra UI FormControl component, with FormLabel, FormHelperText and FormErrorMessage.
607
+ * Composes the Chakra UI Field component, with Label, HelperText and ErrorText.
595
608
  */
596
609
  declare const BaseField: React$1.FC<BaseFieldProps>;
597
610
 
package/dist/index.d.ts CHANGED
@@ -46,7 +46,10 @@ declare const TextareaField: React__default.FC<Omit<BaseFieldProps<react_hook_fo
46
46
  interface SwitchFieldProps extends SwitchProps {
47
47
  type: 'switch';
48
48
  }
49
- interface SelectFieldProps extends Omit<Select.RootProps<FieldOption>, 'collection'> {
49
+ interface SelectFieldProps<Multiple extends boolean = boolean> extends Omit<Select.RootProps<FieldOption>, 'collection' | 'value' | 'multiple' | 'onChange' | 'onValueChange'> {
50
+ multiple?: Multiple;
51
+ value?: Multiple extends true ? Array<string> : string;
52
+ onChange?: (value: Multiple extends true ? Array<string> : string) => void;
50
53
  options: FieldOptions;
51
54
  placeholder?: string;
52
55
  triggerProps?: Select.TriggerProps;
@@ -80,7 +83,7 @@ declare const defaultFieldTypes: {
80
83
  checkbox: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof CheckboxFieldProps> & CheckboxFieldProps>;
81
84
  radio: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof RadioFieldProps> & RadioFieldProps>;
82
85
  password: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof PasswordInputProps> & PasswordInputProps>;
83
- select: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SelectFieldProps> & SelectFieldProps>;
86
+ select: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SelectFieldProps<boolean>> & SelectFieldProps<boolean>>;
84
87
  switch: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof SwitchFieldProps> & SwitchFieldProps>;
85
88
  textarea: React__default.FC<Omit<BaseFieldProps<react_hook_form.FieldValues, string>, keyof TextareaFieldProps> & TextareaFieldProps>;
86
89
  };
@@ -336,8 +339,14 @@ interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName e
336
339
  children?: React.ReactNode;
337
340
  }
338
341
  type GetBaseField<TProps extends object = object> = () => {
339
- extraProps: string[];
340
- BaseField: React.FC<Omit<BaseFieldProps, 'name'> & {
342
+ /**
343
+ * Extra props to pass to the component
344
+ */
345
+ props: Array<Extract<keyof TProps, string>>;
346
+ /**
347
+ * The component to render
348
+ */
349
+ Component: React.FC<Omit<BaseFieldProps, 'name'> & {
341
350
  name: string;
342
351
  children: React.ReactNode;
343
352
  } & TProps>;
@@ -529,9 +538,9 @@ interface FieldsProps<TSchema = any> {
529
538
  }
530
539
  declare const AutoFields: React$1.FC<FieldsProps>;
531
540
 
532
- interface FieldsContextValue {
533
- fields: Record<string, React__default.FC<any>>;
534
- getBaseField?: GetBaseField<any>;
541
+ interface FieldsContextValue<TFields = any, TBaseFieldProps extends object = object> {
542
+ fields: Record<string, React__default.FC<TFields>>;
543
+ getBaseField?: GetBaseField<TBaseFieldProps>;
535
544
  }
536
545
  declare const FieldsProvider: React__default.FC<{
537
546
  value: FieldsContextValue;
@@ -581,17 +590,21 @@ interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = Fi
581
590
  declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object>(props: WatchFieldProps<Value, TFieldValues, TContext>) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>> | null;
582
591
 
583
592
  declare const useBaseField: (props: BaseFieldProps) => {
584
- controlProps: Pick<BaseFieldProps<react_hook_form.FieldValues, string>, never>;
593
+ rootProps: Omit<BaseFieldProps<react_hook_form.FieldValues, string>, "name" | "label" | "hideLabel" | "help" | "rules" | "type" | "placeholder" | "children">;
585
594
  error: any;
586
595
  touched: any;
587
596
  name: string;
588
597
  label?: string | undefined;
589
598
  hideLabel?: boolean | undefined;
590
599
  help?: string | undefined;
600
+ rules?: Omit<react_hook_form.RegisterOptions<react_hook_form.FieldValues, string>, "disabled" | "setValueAs" | "valueAsNumber" | "valueAsDate"> | undefined;
601
+ type?: string | undefined;
602
+ placeholder?: string | undefined;
603
+ children?: React$1.ReactNode;
591
604
  };
592
605
  /**
593
606
  * The default BaseField component
594
- * Composes the Chakra UI FormControl component, with FormLabel, FormHelperText and FormErrorMessage.
607
+ * Composes the Chakra UI Field component, with Label, HelperText and ErrorText.
595
608
  */
596
609
  declare const BaseField: React$1.FC<BaseFieldProps>;
597
610
 
package/dist/index.js CHANGED
@@ -82,10 +82,11 @@ __export(src_exports, {
82
82
  module.exports = __toCommonJS(src_exports);
83
83
 
84
84
  // src/create-form.tsx
85
- var import_react13 = require("react");
85
+ var import_react14 = require("react");
86
86
 
87
87
  // src/default-fields.tsx
88
- var import_react4 = require("@chakra-ui/react");
88
+ var import_react4 = require("react");
89
+ var import_react5 = require("@chakra-ui/react");
89
90
  var import_checkbox = require("@saas-ui/react/checkbox");
90
91
  var import_input_group = require("@saas-ui/react/input-group");
91
92
  var import_number_input = require("@saas-ui/react/number-input");
@@ -138,30 +139,35 @@ var isTouched = (name, formState) => {
138
139
  return (0, import_react_hook_form2.get)(formState.touchedFields, name);
139
140
  };
140
141
  var useBaseField = (props) => {
141
- const [fieldProps] = (0, import_utils.splitProps)(props, ["name", "label", "help", "hideLabel"]);
142
- const [controlProps] = (0, import_utils.splitProps)(props, [
143
- // 'id',
144
- // 'orientation',
145
- // 'disabled',
146
- // 'invalid',
147
- // 'readOnly',
148
- // 'required',
142
+ const [fieldProps, rootProps] = (0, import_utils.splitProps)(props, [
143
+ "name",
144
+ "label",
145
+ "help",
146
+ "hideLabel",
147
+ "placeholder",
148
+ "rules",
149
+ "type",
150
+ "children"
149
151
  ]);
150
152
  const { formState } = useFormContext();
151
153
  const error = getError(fieldProps.name, formState);
152
154
  const touched = isTouched(fieldProps.name, formState);
153
155
  return {
154
156
  ...fieldProps,
155
- controlProps,
157
+ rootProps,
156
158
  error,
157
159
  touched
158
160
  };
159
161
  };
160
162
  var BaseField = (props) => {
161
- const { label, help, hideLabel, error } = useBaseField(props);
163
+ const { rootProps, label, hideLabel, help, error } = useBaseField(props);
162
164
  const isInvalid = !!error;
163
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react.Field.Root, { invalid: isInvalid, ...props, children: [
164
- label && !hideLabel ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.Label, { children: label }) : null,
165
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react.Field.Root, { invalid: isInvalid, ...rootProps, children: [
166
+ label && !hideLabel ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react.Field.Label, { children: [
167
+ label,
168
+ " ",
169
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.RequiredIndicator, {})
170
+ ] }) : null,
165
171
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react.Box, { width: "full", children: [
166
172
  props.children,
167
173
  help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.HelperText, { children: help }) : null,
@@ -192,37 +198,34 @@ var import_jsx_runtime4 = require("react/jsx-runtime");
192
198
  var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getBaseFieldProp }) => {
193
199
  const Field3 = (0, import_react3.forwardRef)((props, ref) => {
194
200
  var _a;
195
- const { id, name, label, isRequired, rules } = props;
201
+ const { id, label, required, rules } = props;
196
202
  const inputRules = {
197
- required: isRequired,
203
+ required,
198
204
  ...rules
199
205
  };
200
206
  const fieldContext = useFieldsContext();
201
207
  const getBaseField = (_a = fieldContext == null ? void 0 : fieldContext.getBaseField) != null ? _a : getBaseFieldProp;
202
- const { extraProps, BaseField: BaseField2 } = import_react3.default.useMemo(
208
+ const { props: extraProps, Component } = import_react3.default.useMemo(
203
209
  () => getBaseField(),
204
210
  [getBaseField]
205
211
  );
206
- const [, inputProps] = (0, import_utils2.splitProps)(
212
+ const rootProps = {
213
+ name: props.name,
214
+ label: props.label,
215
+ disabled: props.disabled,
216
+ invalid: props.invalid,
217
+ readOnly: props.readOnly,
218
+ required: props.required
219
+ };
220
+ const [baseFieldProps, inputProps] = (0, import_utils2.splitProps)(
207
221
  props,
208
- [
209
- "children",
210
- "name",
211
- "label",
212
- "required",
213
- "disabled",
214
- "invalid",
215
- "readOnly",
216
- "help",
217
- "hideLabel"
218
- ].concat(extraProps)
222
+ ["orientation", "help", "hideLabel"].concat(extraProps)
219
223
  );
220
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BaseField2, { name, hideLabel, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
224
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component, { ...rootProps, ...baseFieldProps, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
221
225
  InputComponent,
222
226
  {
223
227
  ref,
224
228
  id,
225
- name,
226
229
  label: hideLabel ? label : void 0,
227
230
  ...inputProps,
228
231
  rules: inputRules
@@ -288,8 +291,8 @@ var createField = (component, options) => {
288
291
  displayName: `${(_a = component.displayName) != null ? _a : "Custom"}Field`,
289
292
  hideLabel: options == null ? void 0 : options.hideLabel,
290
293
  getBaseField: () => ({
291
- extraProps: [],
292
- BaseField
294
+ props: [],
295
+ Component: BaseField
293
296
  })
294
297
  });
295
298
  return Field3;
@@ -299,14 +302,14 @@ var createField = (component, options) => {
299
302
  var import_jsx_runtime5 = require("react/jsx-runtime");
300
303
  var InputField = createField(
301
304
  ({ type = "text", startElement, endElement, size, ...rest }, ref) => {
302
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_input_group.InputGroup, { startElement, endElement, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react4.Input, { type, size, ...rest, ref }) });
305
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_input_group.InputGroup, { startElement, endElement, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react5.Input, { type, size, ...rest, ref }) });
303
306
  }
304
307
  );
305
308
  var NumberInputField = createField((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_number_input.NumberInput, { ...props, ref }), {
306
309
  isControlled: true
307
310
  });
308
311
  var PasswordInputField = createField(({ type = "password", ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_password_input.PasswordInput, { ref, ...props }));
309
- var TextareaField = createField((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react4.Textarea, { ...props, ref }));
312
+ var TextareaField = createField((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react5.Textarea, { ...props, ref }));
310
313
  var SwitchField = createField(
311
314
  ({ type, value, ...rest }, ref) => {
312
315
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_switch.Switch, { checked: !!value, ...rest, ref });
@@ -323,22 +326,28 @@ var SelectField = createField(
323
326
  options,
324
327
  placeholder,
325
328
  onChange,
326
- onValueChange,
327
329
  onBlur,
330
+ multiple = false,
331
+ value: valueProp,
328
332
  ...rest
329
333
  } = props;
330
- const collection = (0, import_react4.createListCollection)({
331
- items: options
332
- });
334
+ const collection = (0, import_react4.useMemo)(
335
+ () => (0, import_react5.createListCollection)({
336
+ items: options
337
+ }),
338
+ [options]
339
+ );
340
+ const value = multiple ? [...valueProp != null ? valueProp : []] : valueProp ? [valueProp] : [];
333
341
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
334
342
  import_select.Select.Root,
335
343
  {
336
344
  ref,
337
345
  collection,
338
346
  onValueChange: (details) => {
339
- onChange(details.value);
347
+ onChange(multiple ? details.value : details.value[0]);
340
348
  },
341
349
  onInteractOutside: () => onBlur(),
350
+ value,
342
351
  ...rest,
343
352
  children: [
344
353
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_select.Select.Trigger, { ...triggerProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_select.Select.ValueText, { placeholder }) }),
@@ -370,7 +379,7 @@ var RadioField = createField(
370
379
  onChange == null ? void 0 : onChange(value);
371
380
  },
372
381
  ...rest,
373
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react4.Stack, { flexDirection, gap, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_radio.Radio, { value: option.value, children: option.label || option.value }, option.value)) })
382
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react5.Stack, { flexDirection, gap, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_radio.Radio, { value: option.value, children: option.label || option.value }, option.value)) })
374
383
  }
375
384
  );
376
385
  },
@@ -445,37 +454,37 @@ var objectFieldResolver = (schema) => {
445
454
  };
446
455
 
447
456
  // src/form.tsx
448
- var import_react11 = __toESM(require("react"));
449
- var import_react12 = require("@chakra-ui/react");
457
+ var import_react12 = __toESM(require("react"));
458
+ var import_react13 = require("@chakra-ui/react");
450
459
  var import_utils9 = require("@saas-ui/core/utils");
451
460
  var import_react_hook_form7 = require("react-hook-form");
452
461
 
453
462
  // src/array-field.tsx
454
- var import_react7 = __toESM(require("react"));
455
- var import_react8 = require("@chakra-ui/react");
463
+ var import_react8 = __toESM(require("react"));
464
+ var import_react9 = require("@chakra-ui/react");
456
465
  var import_icons = require("@saas-ui/react/icons");
457
466
 
458
467
  // src/form-layout.tsx
459
- var import_react5 = require("react");
460
- var import_react6 = require("@chakra-ui/react");
468
+ var import_react6 = require("react");
469
+ var import_react7 = require("@chakra-ui/react");
461
470
  var import_utils4 = require("@saas-ui/core/utils");
462
471
  var import_jsx_runtime6 = require("react/jsx-runtime");
463
- var FormLayout = (0, import_react5.forwardRef)(
464
- ({ children, rowGap = 4, ...props }, ref) => {
465
- const recipe = (0, import_react6.useRecipe)({
472
+ var FormLayout = (0, import_react6.forwardRef)(
473
+ ({ children, gap = 4, ...props }, ref) => {
474
+ const recipe = (0, import_react7.useRecipe)({
466
475
  key: "formLayout"
467
476
  });
468
477
  const [variantProps, gridProps] = recipe.splitVariantProps(props);
469
478
  const styles = recipe(variantProps);
470
479
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
471
- import_react6.SimpleGrid,
480
+ import_react7.SimpleGrid,
472
481
  {
473
482
  ref,
474
483
  ...gridProps,
475
484
  className: (0, import_utils4.cx)("sui-form-layout", props.className),
476
485
  css: [
477
486
  {
478
- rowGap
487
+ gap
479
488
  },
480
489
  styles,
481
490
  props.css
@@ -488,7 +497,7 @@ var FormLayout = (0, import_react5.forwardRef)(
488
497
  FormLayout.displayName = "FormLayout";
489
498
 
490
499
  // src/use-array-field.tsx
491
- var React4 = __toESM(require("react"));
500
+ var React5 = __toESM(require("react"));
492
501
  var import_utils5 = require("@saas-ui/core/utils");
493
502
  var import_react_hook_form4 = require("react-hook-form");
494
503
  var [ArrayFieldProvider, useArrayFieldContext] = (0, import_utils5.createContext)({
@@ -521,7 +530,7 @@ var useArrayField = ({
521
530
  var useArrayFieldRow = ({ index }) => {
522
531
  const { clearErrors } = useFormContext();
523
532
  const { name, remove, fields } = useArrayFieldContext();
524
- React4.useEffect(() => {
533
+ React5.useEffect(() => {
525
534
  clearErrors(name);
526
535
  }, []);
527
536
  return {
@@ -529,7 +538,7 @@ var useArrayFieldRow = ({ index }) => {
529
538
  isFirst: index === 0,
530
539
  isLast: index === fields.length - 1,
531
540
  name: `${name}.${index}`,
532
- remove: React4.useCallback(() => {
541
+ remove: React5.useCallback(() => {
533
542
  clearErrors(name);
534
543
  remove(index);
535
544
  }, [index])
@@ -556,17 +565,17 @@ var useArrayFieldAddButton = () => {
556
565
  };
557
566
 
558
567
  // src/utils.ts
559
- var React5 = __toESM(require("react"));
568
+ var React6 = __toESM(require("react"));
560
569
  var mapNestedFields = (name, children) => {
561
- return React5.Children.map(children, (child) => {
562
- if (React5.isValidElement(child) && child.props.name) {
570
+ return React6.Children.map(children, (child) => {
571
+ if (React6.isValidElement(child) && child.props.name) {
563
572
  let childName = child.props.name;
564
573
  if (childName.includes(".")) {
565
574
  childName = childName.replace(/^.*\.(.*)/, "$1");
566
575
  } else if (childName.includes(".$")) {
567
576
  childName = childName.replace(/^.*\.\$(.*)/, "$1");
568
577
  }
569
- return React5.cloneElement(child, {
578
+ return React6.cloneElement(child, {
570
579
  ...child.props,
571
580
  name: `${name}.${childName}`
572
581
  });
@@ -609,16 +618,16 @@ var ArrayFieldRowContainer = ({
609
618
  width: "100%",
610
619
  mb: 4
611
620
  };
612
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react8.chakra.div, { ...rest, css: styles, children }) });
621
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react9.chakra.div, { ...rest, css: styles, children }) });
613
622
  };
614
623
  ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
615
624
  var ArrayFieldRemoveButton = (props) => {
616
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react8.Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons.MinusIcon, {}) });
625
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react9.Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons.MinusIcon, {}) });
617
626
  };
618
627
  ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
619
628
  var ArrayFieldAddButton = (props) => {
620
629
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
621
- import_react8.Button,
630
+ import_react9.Button,
622
631
  {
623
632
  "aria-label": "Add row",
624
633
  float: "right",
@@ -629,7 +638,7 @@ var ArrayFieldAddButton = (props) => {
629
638
  );
630
639
  };
631
640
  ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
632
- var ArrayField = (0, import_react7.forwardRef)(
641
+ var ArrayField = (0, import_react8.forwardRef)(
633
642
  (props, ref) => {
634
643
  const { children, ...containerProps } = props;
635
644
  const rowFn = typeof children === "function" ? children : (fields) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArrayFieldRow, { index, children }, id)) || null });
@@ -647,7 +656,7 @@ var ArrayFieldRows = ({
647
656
  return children(fields);
648
657
  };
649
658
  ArrayFieldRows.displayName = "ArrayFieldRows";
650
- var ArrayFieldContainer = import_react7.default.forwardRef(
659
+ var ArrayFieldContainer = import_react8.default.forwardRef(
651
660
  ({
652
661
  name,
653
662
  defaultValue,
@@ -665,14 +674,14 @@ var ArrayFieldContainer = import_react7.default.forwardRef(
665
674
  min: min || (overrides == null ? void 0 : overrides.min),
666
675
  max: max || (overrides == null ? void 0 : overrides.max)
667
676
  });
668
- import_react7.default.useImperativeHandle(ref, () => context, [ref, context]);
677
+ import_react8.default.useImperativeHandle(ref, () => context, [ref, context]);
669
678
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BaseField, { name, ...fieldProps, ...overrides, children }) });
670
679
  }
671
680
  );
672
681
  ArrayFieldContainer.displayName = "ArrayFieldContainer";
673
682
 
674
683
  // src/display-if.tsx
675
- var React7 = __toESM(require("react"));
684
+ var React8 = __toESM(require("react"));
676
685
  var import_react_hook_form5 = require("react-hook-form");
677
686
  var DisplayIf = ({
678
687
  children,
@@ -683,8 +692,8 @@ var DisplayIf = ({
683
692
  condition = (value) => !!value,
684
693
  onToggle
685
694
  }) => {
686
- const initializedRef = React7.useRef(false);
687
- const matchesRef = React7.useRef(false);
695
+ const initializedRef = React8.useRef(false);
696
+ const matchesRef = React8.useRef(false);
688
697
  const value = (0, import_react_hook_form5.useWatch)({
689
698
  name,
690
699
  defaultValue,
@@ -693,7 +702,7 @@ var DisplayIf = ({
693
702
  });
694
703
  const context = useFormContext();
695
704
  const matches = condition(value, context);
696
- React7.useEffect(() => {
705
+ React8.useEffect(() => {
697
706
  if (!initializedRef.current) {
698
707
  initializedRef.current = true;
699
708
  return;
@@ -707,10 +716,10 @@ var DisplayIf = ({
707
716
  DisplayIf.displayName = "DisplayIf";
708
717
 
709
718
  // src/field.tsx
710
- var React8 = __toESM(require("react"));
719
+ var React9 = __toESM(require("react"));
711
720
  var import_jsx_runtime8 = require("react/jsx-runtime");
712
721
  var defaultInputType = "text";
713
- var Field2 = React8.forwardRef(
722
+ var Field2 = React9.forwardRef(
714
723
  (props, ref) => {
715
724
  const { type = defaultInputType, name } = props;
716
725
  const overrides = useFieldProps(name);
@@ -720,14 +729,14 @@ var Field2 = React8.forwardRef(
720
729
  );
721
730
 
722
731
  // src/fields.tsx
723
- var React9 = __toESM(require("react"));
732
+ var React10 = __toESM(require("react"));
724
733
 
725
734
  // src/object-field.tsx
726
- var import_react9 = require("@chakra-ui/react");
735
+ var import_react10 = require("@chakra-ui/react");
727
736
  var import_utils7 = require("@saas-ui/core/utils");
728
737
  var import_jsx_runtime9 = require("react/jsx-runtime");
729
738
  var FormLegend = (props) => {
730
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react9.Field.Label, { as: "legend", ...props });
739
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react10.Field.Label, { as: "legend", ...props });
731
740
  };
732
741
  var ObjectField = (props) => {
733
742
  const {
@@ -741,7 +750,7 @@ var ObjectField = (props) => {
741
750
  } = props;
742
751
  const { hideLabel, columns, gap, ...overrides } = useFieldProps(name);
743
752
  const hidden = hideLabelProp || hideLabel;
744
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react9.Field.Root, { as: "fieldset", ...fieldProps, ...overrides, children: [
753
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react10.Field.Root, { as: "fieldset", ...fieldProps, ...overrides, children: [
745
754
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FormLegend, { "data-hidden": (0, import_utils7.dataAttr)(hidden), children: label }),
746
755
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FormLayout, { columns: columnsProp || columns, gridGap: gapProp || gap, children: mapNestedFields(name, children) })
747
756
  ] });
@@ -773,10 +782,10 @@ var AutoFields = ({
773
782
  const context = useFormContext();
774
783
  const schema = schemaProp || context.schema;
775
784
  const fieldResolver = fieldResolverProp || context.fieldResolver;
776
- const resolver = React9.useMemo(() => fieldResolver, [schema, fieldResolver]);
777
- const fields = React9.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
785
+ const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
786
+ const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
778
787
  const form = useFormContext();
779
- React9.useEffect(() => {
788
+ React10.useEffect(() => {
780
789
  var _a;
781
790
  if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
782
791
  form.setFocus(fields[0].name);
@@ -807,11 +816,11 @@ var AutoFields = ({
807
816
  AutoFields.displayName = "Fields";
808
817
 
809
818
  // src/submit-button.tsx
810
- var import_react10 = require("react");
819
+ var import_react11 = require("react");
811
820
  var import_button = require("@saas-ui/react/button");
812
821
  var import_react_hook_form6 = require("react-hook-form");
813
822
  var import_jsx_runtime11 = require("react/jsx-runtime");
814
- var SubmitButton = (0, import_react10.forwardRef)(
823
+ var SubmitButton = (0, import_react11.forwardRef)(
815
824
  (props, ref) => {
816
825
  const {
817
826
  variant = "glass",
@@ -853,7 +862,7 @@ SubmitButton.displayName = "SubmitButton";
853
862
 
854
863
  // src/form.tsx
855
864
  var import_jsx_runtime12 = require("react/jsx-runtime");
856
- var Form = (0, import_react11.forwardRef)(
865
+ var Form = (0, import_react12.forwardRef)(
857
866
  (props, ref) => {
858
867
  const {
859
868
  mode = "all",
@@ -894,8 +903,8 @@ var Form = (0, import_react11.forwardRef)(
894
903
  };
895
904
  const methods = (0, import_react_hook_form7.useForm)(form);
896
905
  const { handleSubmit } = methods;
897
- import_react11.default.useImperativeHandle(formRef, () => methods, [formRef, methods]);
898
- import_react11.default.useEffect(() => {
906
+ import_react12.default.useImperativeHandle(formRef, () => methods, [formRef, methods]);
907
+ import_react12.default.useEffect(() => {
899
908
  let subscription;
900
909
  if (onChange) {
901
910
  subscription = methods.watch(onChange);
@@ -917,7 +926,7 @@ var Form = (0, import_react11.forwardRef)(
917
926
  fieldResolver,
918
927
  fields,
919
928
  children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
920
- import_react12.chakra.form,
929
+ import_react13.chakra.form,
921
930
  {
922
931
  ref,
923
932
  onSubmit: handleSubmit(onSubmit, onError),
@@ -946,7 +955,7 @@ function createForm({
946
955
  fields,
947
956
  getBaseField
948
957
  } = {}) {
949
- const DefaultForm = (0, import_react13.forwardRef)(
958
+ const DefaultForm = (0, import_react14.forwardRef)(
950
959
  (props, ref) => {
951
960
  const {
952
961
  schema,
@@ -954,7 +963,7 @@ function createForm({
954
963
  fieldResolver: fieldResolverProp,
955
964
  ...rest
956
965
  } = props;
957
- const fieldsContext = (0, import_react13.useMemo)(
966
+ const fieldsContext = (0, import_react14.useMemo)(
958
967
  () => ({
959
968
  fields: { ...defaultFieldTypes, ...fields },
960
969
  getBaseField
@@ -978,16 +987,16 @@ function createForm({
978
987
  }
979
988
 
980
989
  // src/display-field.tsx
981
- var import_react14 = require("@chakra-ui/react");
990
+ var import_react15 = require("@chakra-ui/react");
982
991
  var import_jsx_runtime14 = require("react/jsx-runtime");
983
992
  var DisplayField = ({
984
993
  name,
985
994
  label,
986
995
  ...props
987
996
  }) => {
988
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react14.Field.Root, { ...props, children: [
989
- label ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react14.Field.Label, { htmlFor: name, children: label }) : null,
990
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react14.Text, { fontSize: "md", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FormValue, { name }) })
997
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react15.Field.Root, { ...props, children: [
998
+ label ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react15.Field.Label, { htmlFor: name, children: label }) : null,
999
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react15.Text, { fontSize: "md", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FormValue, { name }) })
991
1000
  ] });
992
1001
  };
993
1002
  DisplayField.displayName = "DisplayField";