@povio/ui 3.4.0-rc.1 → 3.4.0-rc.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.
Files changed (78) hide show
  1. package/dist/components/inputs/Checkbox/Checkbox.d.ts +2 -1
  2. package/dist/components/inputs/Checkbox/Checkbox.js +100 -93
  3. package/dist/components/inputs/Checkbox/CheckboxGroup.d.ts +2 -1
  4. package/dist/components/inputs/Checkbox/CheckboxGroup.js +113 -109
  5. package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +2 -1
  6. package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +21 -14
  7. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +2 -1
  8. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +22 -14
  9. package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +2 -1
  10. package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +21 -14
  11. package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +2 -1
  12. package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +294 -275
  13. package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +2 -1
  14. package/dist/components/inputs/DateTime/shared/DatePickerInput.js +10 -1
  15. package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +2 -1
  16. package/dist/components/inputs/DateTime/shared/TimePickerInput.js +46 -43
  17. package/dist/components/inputs/File/FileUpload.d.ts +1 -1
  18. package/dist/components/inputs/File/FileUpload.js +17 -17
  19. package/dist/components/inputs/File/InputUpload.d.ts +1 -1
  20. package/dist/components/inputs/File/InputUpload.js +17 -17
  21. package/dist/components/inputs/File/fileUpload.types.d.ts +1 -1
  22. package/dist/components/inputs/File/inputUpload.types.d.ts +1 -1
  23. package/dist/components/inputs/Input/NumberInput/NumberInput.d.ts +1 -1
  24. package/dist/components/inputs/Input/NumberInput/NumberInput.js +19 -19
  25. package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.d.ts +1 -1
  26. package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +18 -18
  27. package/dist/components/inputs/Input/PasswordInput/PasswordInput.d.ts +1 -1
  28. package/dist/components/inputs/Input/TextArea/TextArea.d.ts +1 -1
  29. package/dist/components/inputs/Input/TextArea/TextArea.js +18 -18
  30. package/dist/components/inputs/Input/TextInput/TextInput.d.ts +2 -2
  31. package/dist/components/inputs/Input/TextInput/TextInput.js +38 -36
  32. package/dist/components/inputs/Inputs/Form.d.ts +4 -4
  33. package/dist/components/inputs/Inputs/InputItem.d.ts +22 -22
  34. package/dist/components/inputs/Inputs/InputItem.js +36 -35
  35. package/dist/components/inputs/Inputs/Inputs.d.ts +2 -2
  36. package/dist/components/inputs/RadioGroup/RadioGroup.d.ts +2 -1
  37. package/dist/components/inputs/RadioGroup/RadioGroup.js +111 -107
  38. package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +1 -1
  39. package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +13 -13
  40. package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +1 -1
  41. package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +19 -19
  42. package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +1 -1
  43. package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +1 -1
  44. package/dist/components/inputs/Selection/Select/QuerySelect.js +19 -19
  45. package/dist/components/inputs/Selection/Select/Select.d.ts +1 -1
  46. package/dist/components/inputs/Selection/Select/Select.js +19 -19
  47. package/dist/components/inputs/Selection/shared/SelectBase.d.ts +1 -0
  48. package/dist/components/inputs/Selection/shared/SelectBase.js +37 -34
  49. package/dist/components/inputs/Selection/shared/select.context.d.ts +2 -2
  50. package/dist/components/inputs/Selection/shared/select.context.js +8 -4
  51. package/dist/components/inputs/Selection/shared/select.types.d.ts +1 -1
  52. package/dist/components/inputs/Slider/Slider.d.ts +1 -1
  53. package/dist/components/inputs/Slider/Slider.js +18 -18
  54. package/dist/components/inputs/TextEditor/TextEditor.d.ts +1 -1
  55. package/dist/components/inputs/TextEditor/TextEditor.js +18 -18
  56. package/dist/components/inputs/Toggle/Toggle.d.ts +2 -1
  57. package/dist/components/inputs/Toggle/Toggle.js +63 -59
  58. package/dist/components/inputs/shared/form.types.d.ts +8 -9
  59. package/dist/components/segment/Segment.d.ts +1 -1
  60. package/dist/components/segment/Segment.js +17 -17
  61. package/dist/components/segment/segment.types.d.ts +1 -1
  62. package/dist/config/uiConfig.context.d.ts +5 -5
  63. package/dist/config/uiConfig.context.js +12 -3
  64. package/dist/helpers/dynamicColumns.d.ts +1 -1
  65. package/dist/helpers/dynamicInputs.d.ts +7 -7
  66. package/dist/hooks/useAutosave.d.ts +4 -4
  67. package/dist/hooks/useAutosave.js +49 -64
  68. package/dist/hooks/useAutosave.spec.d.ts +1 -0
  69. package/dist/hooks/useForm.d.ts +15 -39
  70. package/dist/hooks/useForm.js +43 -96
  71. package/dist/hooks/useFormAutosave.d.ts +9 -8
  72. package/dist/hooks/useFormAutosave.js +9 -23
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.js +3 -3
  75. package/package.json +3 -2
  76. package/dist/components/inputs/shared/form.binding.d.ts +0 -27
  77. package/dist/components/inputs/shared/form.binding.js +0 -57
  78. package/dist/components/inputs/shared/form.types.js +0 -8
@@ -1,6 +1,5 @@
1
1
  import { UIOverrides } from "../../../config/uiOverrides.context.js";
2
2
  import { UIConfig } from "../../../config/uiConfig.context.js";
3
- import { FieldController } from "../shared/form.binding.js";
4
3
  import { FormFieldError } from "../FormField/FormFieldError.js";
5
4
  import { CheckContent } from "../shared/CheckContent.js";
6
5
  import { toggleContentClassName, toggleDefinition, toggleTypography } from "./toggle.cva.js";
@@ -9,9 +8,10 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
8
  import { clsx } from "clsx";
10
9
  import { Switch } from "react-aria-components";
11
10
  import { mergeRefs } from "@react-aria/utils";
11
+ import { Controller } from "react-hook-form";
12
12
  //#region src/components/inputs/Toggle/Toggle.tsx
13
13
  var ToggleBase = (props) => {
14
- const $ = c(48);
14
+ const $ = c(50);
15
15
  const ui = UIConfig.useConfig();
16
16
  const toggleCva = UIOverrides.useCva("toggle.cva", toggleDefinition);
17
17
  const toggleTypographyMap = UIOverrides.useMapper("toggle.typography", toggleTypography);
@@ -31,9 +31,10 @@ var ToggleBase = (props) => {
31
31
  let t8;
32
32
  let t9;
33
33
  if ($[0] !== props || $[1] !== toggleContentClassNameMap || $[2] !== toggleCva || $[3] !== toggleTypographyMap || $[4] !== ui) {
34
- const { className, children: t10, isDisabled, error, variant: variantProp, onChange, onBlur, ...rest } = props;
34
+ const { className, children: t10, isDisabled, error, variant: variantProp, fireBlurOnChange: fireBlurOnChangeProp, onChange, onBlur, ...rest } = props;
35
35
  children = t10;
36
36
  const variant = variantProp ?? ui.toggle.variant;
37
+ const fireBlurOnChange = fireBlurOnChangeProp ?? ui.toggle.fireBlurOnChange;
37
38
  let t11;
38
39
  if ($[19] !== error || $[20] !== isDisabled) {
39
40
  t11 = {
@@ -46,13 +47,16 @@ var ToggleBase = (props) => {
46
47
  } else t11 = $[21];
47
48
  formFieldErrorProps = t11;
48
49
  let t12;
49
- if ($[22] !== onChange) {
50
+ if ($[22] !== fireBlurOnChange || $[23] !== onBlur || $[24] !== onChange) {
50
51
  t12 = (isSelected) => {
51
52
  onChange?.(isSelected);
53
+ if (fireBlurOnChange) onBlur?.({});
52
54
  };
53
- $[22] = onChange;
54
- $[23] = t12;
55
- } else t12 = $[23];
55
+ $[22] = fireBlurOnChange;
56
+ $[23] = onBlur;
57
+ $[24] = onChange;
58
+ $[25] = t12;
59
+ } else t12 = $[25];
56
60
  const handleChange = t12;
57
61
  T1 = Switch;
58
62
  t2 = rest;
@@ -62,12 +66,12 @@ var ToggleBase = (props) => {
62
66
  t6 = handleChange;
63
67
  t7 = onBlur;
64
68
  const t13 = !isDisabled && "cursor-pointer";
65
- if ($[24] !== className || $[25] !== t13) {
69
+ if ($[26] !== className || $[27] !== t13) {
66
70
  t8 = clsx("group flex items-center gap-2", t13, className);
67
- $[24] = className;
68
- $[25] = t13;
69
- $[26] = t8;
70
- } else t8 = $[26];
71
+ $[26] = className;
72
+ $[27] = t13;
73
+ $[28] = t8;
74
+ } else t8 = $[28];
71
75
  t9 = /* @__PURE__ */ jsx("div", { className: toggleCva({
72
76
  variant,
73
77
  ...rest
@@ -117,20 +121,20 @@ var ToggleBase = (props) => {
117
121
  t9 = $[18];
118
122
  }
119
123
  let t10;
120
- if ($[27] !== T0 || $[28] !== children || $[29] !== t0 || $[30] !== t1) {
124
+ if ($[29] !== T0 || $[30] !== children || $[31] !== t0 || $[32] !== t1) {
121
125
  t10 = /* @__PURE__ */ jsx(T0, {
122
126
  typography: t0,
123
127
  contentClassName: t1,
124
128
  children
125
129
  });
126
- $[27] = T0;
127
- $[28] = children;
128
- $[29] = t0;
129
- $[30] = t1;
130
- $[31] = t10;
131
- } else t10 = $[31];
130
+ $[29] = T0;
131
+ $[30] = children;
132
+ $[31] = t0;
133
+ $[32] = t1;
134
+ $[33] = t10;
135
+ } else t10 = $[33];
132
136
  let t11;
133
- if ($[32] !== T1 || $[33] !== t10 || $[34] !== t2 || $[35] !== t3 || $[36] !== t4 || $[37] !== t5 || $[38] !== t6 || $[39] !== t7 || $[40] !== t8 || $[41] !== t9) {
137
+ if ($[34] !== T1 || $[35] !== t10 || $[36] !== t2 || $[37] !== t3 || $[38] !== t4 || $[39] !== t5 || $[40] !== t6 || $[41] !== t7 || $[42] !== t8 || $[43] !== t9) {
134
138
  t11 = /* @__PURE__ */ jsxs(T1, {
135
139
  ...t2,
136
140
  "data-is-dirty": t3,
@@ -141,64 +145,64 @@ var ToggleBase = (props) => {
141
145
  className: t8,
142
146
  children: [t9, t10]
143
147
  });
144
- $[32] = T1;
145
- $[33] = t10;
146
- $[34] = t2;
147
- $[35] = t3;
148
- $[36] = t4;
149
- $[37] = t5;
150
- $[38] = t6;
151
- $[39] = t7;
152
- $[40] = t8;
153
- $[41] = t9;
154
- $[42] = t11;
155
- } else t11 = $[42];
148
+ $[34] = T1;
149
+ $[35] = t10;
150
+ $[36] = t2;
151
+ $[37] = t3;
152
+ $[38] = t4;
153
+ $[39] = t5;
154
+ $[40] = t6;
155
+ $[41] = t7;
156
+ $[42] = t8;
157
+ $[43] = t9;
158
+ $[44] = t11;
159
+ } else t11 = $[44];
156
160
  let t12;
157
- if ($[43] !== formFieldErrorProps) {
161
+ if ($[45] !== formFieldErrorProps) {
158
162
  t12 = /* @__PURE__ */ jsx(FormFieldError, { ...formFieldErrorProps });
159
- $[43] = formFieldErrorProps;
160
- $[44] = t12;
161
- } else t12 = $[44];
163
+ $[45] = formFieldErrorProps;
164
+ $[46] = t12;
165
+ } else t12 = $[46];
162
166
  let t13;
163
- if ($[45] !== t11 || $[46] !== t12) {
167
+ if ($[47] !== t11 || $[48] !== t12) {
164
168
  t13 = /* @__PURE__ */ jsxs(Fragment, { children: [t11, t12] });
165
- $[45] = t11;
166
- $[46] = t12;
167
- $[47] = t13;
168
- } else t13 = $[47];
169
+ $[47] = t11;
170
+ $[48] = t12;
171
+ $[49] = t13;
172
+ } else t13 = $[49];
169
173
  return t13;
170
174
  };
171
175
  var Toggle = (props) => {
172
176
  const $ = c(15);
173
- if ("field" in props && props.field) {
174
- let field;
177
+ if ("formControl" in props && props.formControl) {
178
+ let formControl;
175
179
  let innerProps;
176
180
  let ref;
177
181
  if ($[0] !== props) {
178
- ({field, ref, ...innerProps} = props);
182
+ ({formControl, ref, ...innerProps} = props);
179
183
  $[0] = props;
180
- $[1] = field;
184
+ $[1] = formControl;
181
185
  $[2] = innerProps;
182
186
  $[3] = ref;
183
187
  } else {
184
- field = $[1];
188
+ formControl = $[1];
185
189
  innerProps = $[2];
186
190
  ref = $[3];
187
191
  }
188
192
  let t0;
189
193
  if ($[4] !== innerProps || $[5] !== props.error || $[6] !== props.isDisabled || $[7] !== ref) {
190
194
  t0 = (t1) => {
191
- const { field: field_0, fieldState: t2 } = t1;
195
+ const { field, fieldState: t2 } = t1;
192
196
  const { error, isDirty } = t2;
193
197
  return /* @__PURE__ */ jsx(ToggleBase, {
194
198
  ...innerProps,
195
- ref: mergeRefs(ref, field_0.ref),
196
- isSelected: field_0.value,
197
- onChange: field_0.onChange,
198
- onBlur: field_0.onBlur,
199
- name: field_0.name,
199
+ ref: mergeRefs(ref, field.ref),
200
+ isSelected: field.value,
201
+ onChange: field.onChange,
202
+ onBlur: field.onBlur,
203
+ name: field.name,
200
204
  isDirty,
201
- isDisabled: field_0.disabled || props.isDisabled,
205
+ isDisabled: field.disabled || props.isDisabled,
202
206
  error: props.error ?? error?.message
203
207
  });
204
208
  };
@@ -209,14 +213,14 @@ var Toggle = (props) => {
209
213
  $[8] = t0;
210
214
  } else t0 = $[8];
211
215
  let t1;
212
- if ($[9] !== field.form || $[10] !== field.name || $[11] !== t0) {
213
- t1 = /* @__PURE__ */ jsx(FieldController, {
214
- control: field.form,
215
- name: field.name,
216
+ if ($[9] !== formControl.control || $[10] !== formControl.name || $[11] !== t0) {
217
+ t1 = /* @__PURE__ */ jsx(Controller, {
218
+ control: formControl.control,
219
+ name: formControl.name,
216
220
  render: t0
217
221
  });
218
- $[9] = field.form;
219
- $[10] = field.name;
222
+ $[9] = formControl.control;
223
+ $[10] = formControl.name;
220
224
  $[11] = t0;
221
225
  $[12] = t1;
222
226
  } else t1 = $[12];
@@ -1,13 +1,12 @@
1
- import { DeepKeys, DeepValue, UIForm } from '../../../hooks/useForm';
1
+ import { Control, FieldPath, FieldPathValue, FieldValues } from 'react-hook-form';
2
2
  export type ControlKeys<TProps, TValueProp extends keyof TProps = "value" extends keyof TProps ? "value" : never> = TValueProp | "onChange" | "onBlur";
3
- export interface FormControl<TFieldValues extends Record<string, unknown>, TType> {
4
- form: UIForm<TFieldValues>;
3
+ export interface FormControl<TFieldValues extends FieldValues, TType> {
4
+ control: Control<TFieldValues>;
5
5
  name: {
6
- [K in DeepKeys<TFieldValues>]: DeepValue<TFieldValues, K> extends TType ? K : never;
7
- }[DeepKeys<TFieldValues>];
6
+ [K in FieldPath<TFieldValues>]: FieldPathValue<TFieldValues, K> extends TType ? K : never;
7
+ }[FieldPath<TFieldValues>];
8
8
  }
9
- export type FormControlProps<TProps, TFieldValues extends Record<string, unknown>, TValueProp extends keyof TProps = "value" extends keyof TProps ? "value" : never> = {
10
- field: FormControl<TFieldValues, TProps[TValueProp] | null>;
9
+ export type FormControlProps<TProps, TFieldValues extends FieldValues, TValueProp extends keyof TProps = "value" extends keyof TProps ? "value" : never> = {
10
+ formControl: FormControl<TFieldValues, TProps[TValueProp] | null>;
11
11
  } & Omit<TProps, ControlKeys<TProps, TValueProp>> & Partial<Record<ControlKeys<TProps, TValueProp>, never>>;
12
- export type ControlProps<TProps, TFieldValues extends Record<string, unknown>, TValueProp extends keyof TProps = "value" extends keyof TProps ? "value" : never> = FormControlProps<TProps, TFieldValues, TValueProp> | TProps;
13
- export declare const getFieldError: (errors: unknown[]) => string | undefined;
12
+ export type ControlProps<TProps, TFieldValues extends FieldValues, TValueProp extends keyof TProps = "value" extends keyof TProps ? "value" : never> = FormControlProps<TProps, TFieldValues, TValueProp> | TProps;
@@ -1,4 +1,4 @@
1
1
  import { Key } from 'react-aria-components';
2
- import { FieldValues } from '../inputs/shared/form.binding';
2
+ import { FieldValues } from 'react-hook-form';
3
3
  import { ControlledSegmentProps } from './segment.types';
4
4
  export declare const Segment: <TFieldValues extends FieldValues, TKey extends Key = Key>(props: ControlledSegmentProps<TFieldValues, TKey>) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,4 @@
1
1
  import { UIOverrides } from "../../config/uiOverrides.context.js";
2
- import { FieldController } from "../inputs/shared/form.binding.js";
3
2
  import { FormField } from "../inputs/FormField/FormField.js";
4
3
  import { segmentDefinition } from "./segment.cva.js";
5
4
  import { SegmentItem } from "./SegmentItem.js";
@@ -10,6 +9,7 @@ import { Fragment as Fragment$1, useRef } from "react";
10
9
  import { ToggleButtonGroup } from "react-aria-components";
11
10
  import { useToggleButtonGroup } from "react-aria";
12
11
  import { mergeRefs } from "@react-aria/utils";
12
+ import { Controller } from "react-hook-form";
13
13
  import { useToggleGroupState } from "react-stately";
14
14
  //#region src/components/segment/Segment.tsx
15
15
  var SegmentBase = (t0) => {
@@ -181,32 +181,32 @@ var SegmentBase = (t0) => {
181
181
  };
182
182
  var Segment = (props) => {
183
183
  const $ = c(15);
184
- if ("field" in props && props.field) {
185
- let field;
184
+ if ("formControl" in props && props.formControl) {
185
+ let formControl;
186
186
  let innerProps;
187
187
  let ref;
188
188
  if ($[0] !== props) {
189
- ({field, ref, ...innerProps} = props);
189
+ ({formControl, ref, ...innerProps} = props);
190
190
  $[0] = props;
191
- $[1] = field;
191
+ $[1] = formControl;
192
192
  $[2] = innerProps;
193
193
  $[3] = ref;
194
194
  } else {
195
- field = $[1];
195
+ formControl = $[1];
196
196
  innerProps = $[2];
197
197
  ref = $[3];
198
198
  }
199
199
  let t0;
200
200
  if ($[4] !== innerProps || $[5] !== props.error || $[6] !== props.isDisabled || $[7] !== ref) {
201
201
  t0 = (t1) => {
202
- const { field: field_0, fieldState: t2 } = t1;
202
+ const { field, fieldState: t2 } = t1;
203
203
  const { error } = t2;
204
204
  return /* @__PURE__ */ jsx(SegmentBase, {
205
205
  ...innerProps,
206
- ref: mergeRefs(ref, field_0.ref),
207
- value: field_0.value,
208
- onChange: field_0.onChange,
209
- isDisabled: field_0.disabled || props.isDisabled,
206
+ ref: mergeRefs(ref, field.ref),
207
+ value: field.value,
208
+ onChange: field.onChange,
209
+ isDisabled: field.disabled || props.isDisabled,
210
210
  error: props.error ?? error?.message
211
211
  });
212
212
  };
@@ -217,14 +217,14 @@ var Segment = (props) => {
217
217
  $[8] = t0;
218
218
  } else t0 = $[8];
219
219
  let t1;
220
- if ($[9] !== field.form || $[10] !== field.name || $[11] !== t0) {
221
- t1 = /* @__PURE__ */ jsx(FieldController, {
222
- control: field.form,
223
- name: field.name,
220
+ if ($[9] !== formControl.control || $[10] !== formControl.name || $[11] !== t0) {
221
+ t1 = /* @__PURE__ */ jsx(Controller, {
222
+ control: formControl.control,
223
+ name: formControl.name,
224
224
  render: t0
225
225
  });
226
- $[9] = field.form;
227
- $[10] = field.name;
226
+ $[9] = formControl.control;
227
+ $[10] = formControl.name;
228
228
  $[11] = t0;
229
229
  $[12] = t1;
230
230
  } else t1 = $[12];
@@ -1,6 +1,6 @@
1
1
  import { FC, ReactElement, Ref, SVGProps } from 'react';
2
2
  import { Key, ToggleButtonGroupProps, ToggleButtonProps } from 'react-aria-components';
3
- import { FieldValues } from '../inputs/shared/form.binding';
3
+ import { FieldValues } from 'react-hook-form';
4
4
  import { ControlProps } from '../inputs/shared/form.types';
5
5
  import { SegmentItemVariantProps, SegmentVariantProps } from './segment.cva';
6
6
  export interface SegmentItem<TKey extends Key = Key> extends ToggleButtonProps, SegmentItemVariantProps {
@@ -26,9 +26,9 @@ export declare namespace UIConfig {
26
26
  };
27
27
  button: Pick<ButtonProps, "variant" | "size">;
28
28
  numberInput: Pick<NumberInputProps, "formatOptions">;
29
- radioGroup: Pick<RadioGroupProps, "variant" | "hideLabel">;
30
- checkbox: Pick<CheckboxProps, "variant">;
31
- select: Pick<SelectBaseProps, "selectionMode" | "isSearchable" | "collapseAfter" | "selectedTagsType" | "hideSearchIcon" | "multiSelectAutoConfirm">;
29
+ radioGroup: Pick<RadioGroupProps, "variant" | "hideLabel" | "fireBlurOnChange">;
30
+ checkbox: Pick<CheckboxProps, "variant" | "fireBlurOnChange">;
31
+ select: Pick<SelectBaseProps, "selectionMode" | "isSearchable" | "collapseAfter" | "selectedTagsType" | "hideSearchIcon" | "fireBlurOnChange" | "multiSelectAutoConfirm">;
32
32
  queryAutocomplete: {
33
33
  isInitialQueryDisabled?: boolean;
34
34
  resolveSelectedItemsWithIds?: boolean;
@@ -39,9 +39,9 @@ export declare namespace UIConfig {
39
39
  resolveSelectedItemsWithIds?: boolean;
40
40
  searchDebounceDelay?: number;
41
41
  };
42
- toggle: Pick<ToggleProps, "variant">;
42
+ toggle: Pick<ToggleProps, "variant" | "fireBlurOnChange">;
43
43
  slider: Pick<SliderProps, "minValue" | "maxValue">;
44
- dateInput: Pick<DatePickerProps, "todayIcon" | "todayIconButtonSize" | "todayIconPlacement" | "shouldForceLeadingZeros" | "disableManualEntry" | "shouldUpdateDateOnMonthYearChange" | "granularity" | "autoFixYear"> & {
44
+ dateInput: Pick<DatePickerProps, "todayIcon" | "todayIconButtonSize" | "todayIconPlacement" | "shouldForceLeadingZeros" | "disableManualEntry" | "shouldUpdateDateOnMonthYearChange" | "granularity" | "autoFixYear" | "fireBlurOnChange"> & {
45
45
  calendarIcon?: ReactElement;
46
46
  dateTimeIcon?: ReactElement;
47
47
  timeIcon?: ReactElement;
@@ -28,15 +28,20 @@ var UIConfig;
28
28
  } },
29
29
  radioGroup: {
30
30
  variant: "default",
31
- hideLabel: false
31
+ hideLabel: false,
32
+ fireBlurOnChange: false
33
+ },
34
+ checkbox: {
35
+ variant: "default",
36
+ fireBlurOnChange: false
32
37
  },
33
- checkbox: { variant: "default" },
34
38
  select: {
35
39
  selectionMode: "single",
36
40
  isSearchable: false,
37
41
  selectedTagsType: "list",
38
42
  collapseAfter: 3,
39
43
  hideSearchIcon: false,
44
+ fireBlurOnChange: false,
40
45
  multiSelectAutoConfirm: false
41
46
  },
42
47
  queryAutocomplete: {
@@ -49,7 +54,10 @@ var UIConfig;
49
54
  resolveSelectedItemsWithIds: false,
50
55
  searchDebounceDelay: 500
51
56
  },
52
- toggle: { variant: "default" },
57
+ toggle: {
58
+ variant: "default",
59
+ fireBlurOnChange: false
60
+ },
53
61
  slider: {
54
62
  minValue: 0,
55
63
  maxValue: 100
@@ -62,6 +70,7 @@ var UIConfig;
62
70
  shouldForceLeadingZeros: false,
63
71
  disableManualEntry: false,
64
72
  autoFixYear: false,
73
+ fireBlurOnChange: false,
65
74
  calendarIcon: /* @__PURE__ */ jsx(CalendarIcon, { className: "size-5" }),
66
75
  dateTimeIcon: /* @__PURE__ */ jsx(DateTimeIcon, { className: "size-5" }),
67
76
  timeIcon: /* @__PURE__ */ jsx(ClockIcon, { className: "size-6 text-interactive-text-secondary-idle" }),
@@ -1,6 +1,6 @@
1
1
  import { CellContext, ColumnDef, ColumnMeta } from '@tanstack/react-table';
2
2
  import { ReactNode } from 'react';
3
- import { FieldPath } from '../components/inputs/shared/form.binding';
3
+ import { FieldPath } from 'react-hook-form';
4
4
  import { z } from 'zod';
5
5
  type NestedTypeFromKey<T, K extends string> = K extends keyof T ? T[K] : K extends `${infer First}.${infer Rest}` ? First extends keyof T ? NestedTypeFromKey<T[First], Rest> : never : never;
6
6
  type SchemaType<TSchema extends z.ZodObject<any>> = z.infer<TSchema>;
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { FormInstance } from '../components/inputs/shared/form.binding';
2
+ import { Control, UseFormReturn } from 'react-hook-form';
3
3
  import { z } from 'zod';
4
4
  import { InputComponentProps, InputComponentType, InputDef, InputDefBaseProps, InputWrapperType } from '../components/inputs/Inputs/InputItem';
5
5
  import { ZodUtils } from '../utils/zod.utils';
@@ -47,17 +47,17 @@ type UnknownInputDef<TSchema extends z.ZodObject<any>, K extends keyof z.infer<T
47
47
  } & DynamicInputDefBase<InputDefBaseProps<InputComponentProps<T>>>;
48
48
  }[DefaultComponentType<TSchema["shape"][K]>];
49
49
  type RenderInputDef<TSchema extends z.ZodObject<any>, K extends keyof z.infer<TSchema>> = {
50
- render: (field: {
51
- form: FormInstance<z.infer<TSchema>>;
50
+ render: (formControl: {
51
+ control: Control<z.infer<TSchema>>;
52
52
  name: K;
53
- }, form: FormInstance<z.infer<TSchema>>) => ReactElement;
53
+ }, form: UseFormReturn<z.infer<TSchema>>) => ReactElement;
54
54
  } & DynamicInputDefBase<Record<string, never>>;
55
55
  type DynamicInputDef<TSchema extends z.ZodObject<any>, K extends keyof z.infer<TSchema>> = ConfigInputDef<TSchema, K> | UnknownInputDef<TSchema, K> | RenderInputDef<TSchema, K>;
56
56
  type InputsConfig<TSchema extends z.ZodObject<any>> = {
57
- [K in keyof z.infer<TSchema>]?: DynamicInputDef<TSchema, K> | ((field: {
58
- form: FormInstance<z.infer<TSchema>>;
57
+ [K in keyof z.infer<TSchema>]?: DynamicInputDef<TSchema, K> | ((formControl: {
58
+ control: Control<z.infer<TSchema>>;
59
59
  name: K;
60
- }, form: FormInstance<z.infer<TSchema>>) => ReactElement) | boolean;
60
+ }, form: UseFormReturn<z.infer<TSchema>>) => ReactElement) | boolean;
61
61
  };
62
62
  type GlobalProps = {
63
63
  [T in Exclude<InputComponentType, "unknown">]: InputDefBaseProps<InputComponentProps<T>>;
@@ -1,10 +1,10 @@
1
- import { UIForm } from './useForm';
2
- export interface UseAutosaveProps<TFieldValues extends Record<string, unknown>, TTransformedValues = TFieldValues, TResponse = unknown> {
3
- form: UIForm<TFieldValues>;
1
+ import { FieldValues, UseFormReturn } from 'react-hook-form';
2
+ export interface UseAutosaveProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TResponse = unknown> {
3
+ form: UseFormReturn<TFieldValues, TContext, TTransformedValues>;
4
4
  delay?: number;
5
5
  enabled?: boolean;
6
6
  trigger?: "change" | "blur";
7
7
  onSave: (data: Partial<TTransformedValues>) => Promise<TResponse>;
8
8
  onSaveSuccess?: () => void;
9
9
  }
10
- export declare function useAutosave<TFieldValues extends Record<string, unknown>, TTransformedValues = TFieldValues, TResponse = unknown>({ form, delay, enabled, trigger, onSave, onSaveSuccess, }: UseAutosaveProps<TFieldValues, TTransformedValues, TResponse>): void;
10
+ export declare function useAutosave<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TResponse = unknown>({ form, delay, enabled, trigger, onSave, onSaveSuccess, }: UseAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>): void;
@@ -1,85 +1,70 @@
1
1
  import { ObjectUtils } from "../utils/object.utils.js";
2
2
  import { isEqual } from "../utils/isEqual.js";
3
3
  import { useEffect, useRef } from "react";
4
+ import { useFormState, useWatch } from "react-hook-form";
4
5
  //#region src/hooks/useAutosave.ts
5
- function diffLeftOnly(left, right) {
6
- if (!ObjectUtils.isObject(left) || ObjectUtils.isDate(left) || ObjectUtils.isRegExp(left)) return isEqual(left, right) ? void 0 : left;
7
- if (Array.isArray(left)) return isEqual(left, right) ? void 0 : left;
6
+ function isNilOrEqual(left, right) {
7
+ if (ObjectUtils.isNil(left) && ObjectUtils.isNil(right)) return true;
8
+ return isEqual(left, right);
9
+ }
10
+ function diffLeftOnly(left, right, shallowKeys) {
11
+ if (!ObjectUtils.isObject(left) || ObjectUtils.isDate(left) || ObjectUtils.isRegExp(left)) return !isNilOrEqual(left, right) ? left : void 0;
12
+ if (Array.isArray(left)) return !isNilOrEqual(left, right) ? left : void 0;
8
13
  const result = Object.entries(left).reduce((acc, [key, value]) => {
9
- const diff = diffLeftOnly(value, right?.[key]);
14
+ const shallowSubtree = shallowKeys?.[key];
15
+ if (shallowSubtree === true) {
16
+ if (!isNilOrEqual(value, right?.[key])) acc[key] = value;
17
+ return acc;
18
+ }
19
+ const diff = diffLeftOnly(value, right?.[key], shallowSubtree);
10
20
  if (diff !== void 0 && (!ObjectUtils.isObject(diff) || !ObjectUtils.isEmpty(diff))) acc[key] = diff;
11
21
  return acc;
12
22
  }, {});
13
23
  return ObjectUtils.isEmpty(result) ? void 0 : result;
14
24
  }
15
- var snapshot = (value) => structuredClone(value);
16
- function pickChangedValues(source, changes) {
17
- if (!ObjectUtils.isObject(changes) || Array.isArray(changes)) return source;
18
- return Object.entries(changes).reduce((result, [key, value]) => {
19
- result[key] = pickChangedValues(source?.[key], value);
20
- return result;
21
- }, {});
22
- }
23
25
  function useAutosave({ form, delay = 500, enabled = true, trigger = "change", onSave, onSaveSuccess }) {
24
26
  const timeoutRef = useRef(void 0);
25
- const savedSnapshotRef = useRef(snapshot(form.state.values));
26
- const saveQueueRef = useRef(Promise.resolve());
27
- const latestSaveRef = useRef({
28
- onSave,
29
- onSaveSuccess
30
- });
31
- latestSaveRef.current = {
32
- onSave,
33
- onSaveSuccess
34
- };
27
+ const previousBlurTriggerFieldsRef = useRef(void 0);
28
+ const { control, reset, handleSubmit } = form;
29
+ const { dirtyFields, touchedFields, defaultValues } = useFormState({ control });
30
+ const formData = useWatch({ control });
35
31
  useEffect(() => {
36
- const clearPending = () => {
37
- if (timeoutRef.current) {
38
- clearTimeout(timeoutRef.current);
39
- timeoutRef.current = void 0;
40
- }
41
- };
42
- const queueSave = () => {
43
- if (!enabled) return;
44
- clearPending();
45
- timeoutRef.current = setTimeout(() => {
46
- saveQueueRef.current = saveQueueRef.current.then(async () => {
47
- const valuesAtSaveTime = snapshot(form.state.values);
48
- const changedValues = diffLeftOnly(valuesAtSaveTime, savedSnapshotRef.current);
49
- if (!changedValues) return;
50
- let transformedValues;
51
- try {
52
- transformedValues = form.parseValues(valuesAtSaveTime);
53
- } catch {
54
- return;
55
- }
56
- const payload = pickChangedValues(transformedValues, changedValues);
57
- if (ObjectUtils.isEmpty(payload)) return;
58
- try {
59
- await latestSaveRef.current.onSave(payload);
60
- savedSnapshotRef.current = valuesAtSaveTime;
61
- for (const name of Object.keys(payload)) form.setFieldMeta(name, (meta) => ({
62
- ...meta,
63
- isDirty: false
64
- }));
65
- latestSaveRef.current.onSaveSuccess?.();
66
- } catch {}
67
- });
68
- }, delay);
69
- };
70
- const unsubscribeStore = trigger === "change" ? form.store.subscribe(() => {
71
- if (!isEqual(form.state.values, savedSnapshotRef.current)) queueSave();
72
- }) : void 0;
73
- const unsubscribeBlur = trigger === "blur" ? form.subscribeBlur(queueSave) : void 0;
32
+ if (!enabled || Object.keys(dirtyFields).length === 0) return;
33
+ if (trigger === "blur") {
34
+ const blurTriggerFields = JSON.stringify(touchedFields);
35
+ if (Object.keys(touchedFields).length === 0 || previousBlurTriggerFieldsRef.current === blurTriggerFields) return;
36
+ previousBlurTriggerFieldsRef.current = blurTriggerFields;
37
+ }
38
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
39
+ timeoutRef.current = setTimeout(() => {
40
+ handleSubmit(async (data) => {
41
+ const changedData = diffLeftOnly(Object.entries(dirtyFields).filter(([, value]) => value).reduce((acc, [key]) => {
42
+ acc[key] = data[key];
43
+ return acc;
44
+ }, {}), defaultValues, dirtyFields) ?? {};
45
+ if (Object.keys(changedData).length === 0) return;
46
+ try {
47
+ reset(void 0, { keepValues: true });
48
+ await onSave(changedData);
49
+ onSaveSuccess?.();
50
+ } catch {
51
+ reset(defaultValues);
52
+ return;
53
+ }
54
+ })();
55
+ }, delay);
74
56
  return () => {
75
- clearPending();
76
- unsubscribeStore?.unsubscribe();
77
- unsubscribeBlur?.();
57
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
78
58
  };
79
59
  }, [
60
+ defaultValues,
61
+ dirtyFields,
62
+ trigger === "change" ? formData : touchedFields,
80
63
  delay,
64
+ onSave,
65
+ handleSubmit,
81
66
  enabled,
82
- form,
67
+ reset,
83
68
  trigger
84
69
  ]);
85
70
  }
@@ -0,0 +1 @@
1
+ export {};