@saas-ui/forms 3.0.0-next.0 → 3.0.0-next.10

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,78 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 3.0.0-next.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @saas-ui/react@3.0.0-next.10
9
+
10
+ ## 3.0.0-next.9
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+ - @saas-ui/react@3.0.0-next.9
16
+
17
+ ## 3.0.0-next.8
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - @saas-ui/react@3.0.0-next.8
23
+
24
+ ## 3.0.0-next.7
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies
29
+ - @saas-ui/react@3.0.0-next.7
30
+
31
+ ## 3.0.0-next.6
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies
36
+ - @saas-ui/react@3.0.0-next.6
37
+
38
+ ## 3.0.0-next.5
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies
43
+ - @saas-ui/react@3.0.0-next.5
44
+
45
+ ## 3.0.0-next.4
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [e86d242]
50
+ - @saas-ui/react@3.0.0-next.4
51
+
52
+ ## 3.0.0-next.3
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [860649d]
57
+ - @saas-ui/react@3.0.0-next.3
58
+ - @saas-ui/core@3.0.0-next.1
59
+
60
+ ## 3.0.0-next.2
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies [ec22a57]
65
+ - Updated dependencies [928abff]
66
+ - Updated dependencies [26f5452]
67
+ - @saas-ui/react@3.0.0-next.2
68
+
69
+ ## 3.0.0-next.1
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [f13c1ce]
74
+ - @saas-ui/react@3.0.0-next.1
75
+
3
76
  ## 3.0.0-next.0
4
77
 
5
78
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -9,7 +9,7 @@ import { CheckboxProps } from '@saas-ui/react/checkbox';
9
9
  import { NumberInputProps } from '@saas-ui/react/number-input';
10
10
  import { PasswordInputProps } from '@saas-ui/react/password-input';
11
11
  import { PinInputProps } from '@saas-ui/react/pin-input';
12
- import { RadioGroupProps } from '@saas-ui/react/radio';
12
+ import { RadioGroup } from '@saas-ui/react/radio-group';
13
13
  import { Select } from '@saas-ui/react/select';
14
14
  import { SwitchProps } from '@saas-ui/react/switch';
15
15
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -61,7 +61,7 @@ interface CheckboxFieldProps extends CheckboxProps {
61
61
  type: 'checkbox';
62
62
  label?: string;
63
63
  }
64
- interface RadioFieldProps extends RadioGroupProps {
64
+ interface RadioFieldProps extends RadioGroup.RootProps {
65
65
  type: 'radio';
66
66
  options: FieldOptions;
67
67
  flexDirection?: SystemStyleObject['flexDirection'];
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import { CheckboxProps } from '@saas-ui/react/checkbox';
9
9
  import { NumberInputProps } from '@saas-ui/react/number-input';
10
10
  import { PasswordInputProps } from '@saas-ui/react/password-input';
11
11
  import { PinInputProps } from '@saas-ui/react/pin-input';
12
- import { RadioGroupProps } from '@saas-ui/react/radio';
12
+ import { RadioGroup } from '@saas-ui/react/radio-group';
13
13
  import { Select } from '@saas-ui/react/select';
14
14
  import { SwitchProps } from '@saas-ui/react/switch';
15
15
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -61,7 +61,7 @@ interface CheckboxFieldProps extends CheckboxProps {
61
61
  type: 'checkbox';
62
62
  label?: string;
63
63
  }
64
- interface RadioFieldProps extends RadioGroupProps {
64
+ interface RadioFieldProps extends RadioGroup.RootProps {
65
65
  type: 'radio';
66
66
  options: FieldOptions;
67
67
  flexDirection?: SystemStyleObject['flexDirection'];
package/dist/index.js CHANGED
@@ -89,11 +89,12 @@ var import_react14 = require("react");
89
89
  var import_react4 = require("react");
90
90
  var import_react5 = require("@chakra-ui/react");
91
91
  var import_checkbox = require("@saas-ui/react/checkbox");
92
- var import_input_group = require("@saas-ui/react/input-group");
92
+ var import_input = require("@saas-ui/react/input");
93
93
  var import_number_input = require("@saas-ui/react/number-input");
94
94
  var import_password_input = require("@saas-ui/react/password-input");
95
95
  var import_pin_input = require("@saas-ui/react/pin-input");
96
96
  var import_radio = require("@saas-ui/react/radio");
97
+ var import_radio_group = require("@saas-ui/react/radio-group");
97
98
  var import_select = require("@saas-ui/react/select");
98
99
  var import_switch = require("@saas-ui/react/switch");
99
100
 
@@ -121,10 +122,9 @@ var useFormContext = () => {
121
122
  };
122
123
  };
123
124
  var useFieldProps = (name) => {
124
- var _a;
125
- const parsedName = name == null ? void 0 : name.replace(/\.[0-9]/g, ".$");
125
+ const parsedName = name?.replace(/\.[0-9]/g, ".$");
126
126
  const context = useFormContext();
127
- return ((_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[parsedName]) || {};
127
+ return context?.fields?.[parsedName] || {};
128
128
  };
129
129
  var FormProvider = (props) => {
130
130
  const { children, fieldResolver, schema, fields, ...rest } = props;
@@ -170,8 +170,8 @@ var BaseField = (props) => {
170
170
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.RequiredIndicator, {})
171
171
  ] }) : null,
172
172
  props.children,
173
- help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.HelperText, { children: help }) : null,
174
- (error == null ? void 0 : error.message) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.ErrorText, { children: error == null ? void 0 : error.message })
173
+ help && !error?.message ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.HelperText, { children: help }) : null,
174
+ error?.message && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Field.ErrorText, { children: error?.message })
175
175
  ] });
176
176
  };
177
177
  BaseField.displayName = "BaseField";
@@ -187,23 +187,21 @@ var useFieldsContext = () => {
187
187
  return import_react2.default.useContext(FieldsContext);
188
188
  };
189
189
  var useField = (type, fallback) => {
190
- var _a;
191
190
  const context = import_react2.default.useContext(FieldsContext);
192
- return ((_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[type]) || fallback;
191
+ return context?.fields?.[type] || fallback;
193
192
  };
194
193
 
195
194
  // src/create-field.tsx
196
195
  var import_jsx_runtime4 = require("react/jsx-runtime");
197
196
  var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getBaseFieldProp }) => {
198
197
  const Field3 = (0, import_react3.forwardRef)((props, ref) => {
199
- var _a;
200
198
  const { id, label, required, rules } = props;
201
199
  const inputRules = {
202
200
  required,
203
201
  ...rules
204
202
  };
205
203
  const fieldContext = useFieldsContext();
206
- const getBaseField = (_a = fieldContext == null ? void 0 : fieldContext.getBaseField) != null ? _a : getBaseFieldProp;
204
+ const getBaseField = fieldContext?.getBaseField ?? getBaseFieldProp;
207
205
  const { props: extraProps, Component } = import_react3.default.useMemo(
208
206
  () => getBaseField(),
209
207
  [getBaseField]
@@ -279,16 +277,15 @@ var withUncontrolledInput = (InputComponent) => {
279
277
  );
280
278
  };
281
279
  var createField = (component, options) => {
282
- var _a;
283
280
  let InputComponent;
284
- if (options == null ? void 0 : options.isControlled) {
281
+ if (options?.isControlled) {
285
282
  InputComponent = withControlledInput((0, import_react3.forwardRef)(component));
286
283
  } else {
287
284
  InputComponent = withUncontrolledInput((0, import_react3.forwardRef)(component));
288
285
  }
289
286
  const Field3 = _createField(InputComponent, {
290
- displayName: `${(_a = component.displayName) != null ? _a : "Custom"}Field`,
291
- hideLabel: options == null ? void 0 : options.hideLabel,
287
+ displayName: `${component.displayName ?? "Custom"}Field`,
288
+ hideLabel: options?.hideLabel,
292
289
  getBaseField: () => ({
293
290
  props: [],
294
291
  Component: BaseField
@@ -302,7 +299,7 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
302
299
  var InputField = createField(
303
300
  ({ type = "text", startElement, endElement, size, ...rest }, ref) => {
304
301
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
305
- import_input_group.InputGroup,
302
+ import_input.InputGroup,
306
303
  {
307
304
  startElement,
308
305
  endElement,
@@ -344,7 +341,7 @@ var SelectField = createField(
344
341
  }),
345
342
  [options]
346
343
  );
347
- const value = multiple ? [...valueProp != null ? valueProp : []] : valueProp ? [valueProp] : [];
344
+ const value = multiple ? [...valueProp ?? []] : valueProp ? [valueProp] : [];
348
345
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
349
346
  import_select.Select.Root,
350
347
  {
@@ -379,11 +376,11 @@ var RadioField = createField(
379
376
  (props, ref) => {
380
377
  const { options, onChange, flexDirection = "column", gap, ...rest } = props;
381
378
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
382
- import_radio.RadioGroup,
379
+ import_radio_group.RadioGroup.Root,
383
380
  {
384
381
  ref,
385
382
  onValueChange: ({ value }) => {
386
- onChange == null ? void 0 : onChange(value);
383
+ onChange?.(value);
387
384
  },
388
385
  ...rest,
389
386
  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)) })
@@ -397,7 +394,7 @@ var RadioField = createField(
397
394
  var PinField = createField(
398
395
  (props, ref) => {
399
396
  const { pinType, value: valueProp, onChange, ...inputProps } = props;
400
- const value = (valueProp == null ? void 0 : valueProp.split("")) || [];
397
+ const value = valueProp?.split("") || [];
401
398
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
402
399
  import_pin_input.PinInput,
403
400
  {
@@ -447,10 +444,9 @@ var objectFieldResolver = (schema) => {
447
444
  return mapFields(schema);
448
445
  };
449
446
  const getNestedFields = (name) => {
450
- var _a;
451
447
  const field = (0, import_utils3.get)(schema, name);
452
448
  if (!field) return [];
453
- if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
449
+ if (field.items?.type === "object") {
454
450
  return mapFields(field.items.properties);
455
451
  } else if (field.type === "object") {
456
452
  return mapFields(field.properties);
@@ -575,15 +571,19 @@ var useArrayFieldAddButton = () => {
575
571
  var React6 = __toESM(require("react"));
576
572
  var mapNestedFields = (name, children) => {
577
573
  return React6.Children.map(children, (child) => {
578
- if (React6.isValidElement(child) && child.props.name) {
579
- let childName = child.props.name;
574
+ if (React6.isValidElement(child)) {
575
+ const props = child.props;
576
+ if (!props.name) {
577
+ return child;
578
+ }
579
+ let childName = props.name;
580
580
  if (childName.includes(".")) {
581
581
  childName = childName.replace(/^.*\.(.*)/, "$1");
582
582
  } else if (childName.includes(".$")) {
583
583
  childName = childName.replace(/^.*\.\$(.*)/, "$1");
584
584
  }
585
585
  return React6.cloneElement(child, {
586
- ...child.props,
586
+ ...props,
587
587
  name: `${name}.${childName}`
588
588
  });
589
589
  }
@@ -678,8 +678,8 @@ var ArrayFieldContainer = import_react8.default.forwardRef(
678
678
  name,
679
679
  defaultValue,
680
680
  keyName,
681
- min: min || (overrides == null ? void 0 : overrides.min),
682
- max: max || (overrides == null ? void 0 : overrides.max)
681
+ min: min || overrides?.min,
682
+ max: max || overrides?.max
683
683
  });
684
684
  import_react8.default.useImperativeHandle(ref, () => context, [ref, context]);
685
685
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BaseField, { name, ...fieldProps, ...overrides, children }) });
@@ -716,7 +716,7 @@ var DisplayIf = ({
716
716
  }
717
717
  if (matchesRef.current === matches) return;
718
718
  matchesRef.current = matches;
719
- onToggle == null ? void 0 : onToggle(matches, context);
719
+ onToggle?.(matches, context);
720
720
  }, [value]);
721
721
  return matches ? children : null;
722
722
  };
@@ -730,7 +730,7 @@ var Field2 = React9.forwardRef(
730
730
  (props, ref) => {
731
731
  const { type = defaultInputType, name } = props;
732
732
  const overrides = useFieldProps(name);
733
- const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type, InputField);
733
+ const InputComponent = useField(overrides?.type || type, InputField);
734
734
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InputComponent, { ref, ...props, ...overrides });
735
735
  }
736
736
  );
@@ -767,8 +767,7 @@ ObjectField.displayName = "ObjectField";
767
767
  // src/fields.tsx
768
768
  var import_jsx_runtime10 = require("react/jsx-runtime");
769
769
  var mapNestedFields2 = (resolver, name) => {
770
- var _a;
771
- return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
770
+ return resolver.getNestedFields(name)?.map(
772
771
  ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
773
772
  Field2,
774
773
  {
@@ -790,18 +789,17 @@ var AutoFields = ({
790
789
  const schema = schemaProp || context.schema;
791
790
  const fieldResolver = fieldResolverProp || context.fieldResolver;
792
791
  const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
793
- const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
792
+ const fields = React10.useMemo(() => resolver?.getFields(), [resolver]);
794
793
  const form = useFormContext();
795
794
  React10.useEffect(() => {
796
- var _a;
797
- if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
795
+ if (focusFirstField && fields?.[0]?.name) {
798
796
  form.setFocus(fields[0].name);
799
797
  }
800
798
  }, [schema, fieldResolver, focusFirstField]);
801
799
  if (!resolver) {
802
800
  return null;
803
801
  }
804
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
802
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FormLayout, { ...props, children: fields?.map(
805
803
  ({ name, type, ...fieldProps }) => {
806
804
  if (type === "array") {
807
805
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
@@ -846,8 +844,8 @@ var SubmitButton = (0, import_react11.forwardRef)(
846
844
  disableIfInvalid: disableIfInvalidOverride,
847
845
  ...fieldProps
848
846
  } = field;
849
- const disableIfUntouched = disableIfUntouchedOverride != null ? disableIfUntouchedOverride : disableIfUntouchedProp;
850
- const disableIfInvalid = disableIfInvalidOverride != null ? disableIfInvalidOverride : disableIfInvalidProp;
847
+ const disableIfUntouched = disableIfUntouchedOverride ?? disableIfUntouchedProp;
848
+ const disableIfInvalid = disableIfInvalidOverride ?? disableIfInvalidProp;
851
849
  const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || disabledProp;
852
850
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
853
851
  import_button.Button,
@@ -916,13 +914,13 @@ var Form = (0, import_react12.forwardRef)(
916
914
  if (onChange) {
917
915
  subscription = methods.watch(onChange);
918
916
  }
919
- return () => subscription == null ? void 0 : subscription.unsubscribe();
917
+ return () => subscription?.unsubscribe();
920
918
  }, [methods, onChange]);
921
919
  let _children = children;
922
920
  if (!_children && fieldResolver) {
923
921
  _children = /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(FormLayout, { children: [
924
922
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(AutoFields, {}),
925
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SubmitButton, { ...fields == null ? void 0 : fields.submit })
923
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SubmitButton, { ...fields?.submit })
926
924
  ] });
927
925
  }
928
926
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -981,8 +979,8 @@ function createForm({
981
979
  Form,
982
980
  {
983
981
  ref,
984
- resolver: resolverProp != null ? resolverProp : resolver == null ? void 0 : resolver(props.schema),
985
- fieldResolver: fieldResolverProp != null ? fieldResolverProp : fieldResolver == null ? void 0 : fieldResolver(schema),
982
+ resolver: resolverProp ?? resolver?.(props.schema),
983
+ fieldResolver: fieldResolverProp ?? fieldResolver?.(schema),
986
984
  ...rest
987
985
  }
988
986
  ) });