@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.
- package/dist/components/inputs/Checkbox/Checkbox.d.ts +2 -1
- package/dist/components/inputs/Checkbox/Checkbox.js +100 -93
- package/dist/components/inputs/Checkbox/CheckboxGroup.d.ts +2 -1
- package/dist/components/inputs/Checkbox/CheckboxGroup.js +113 -109
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +2 -1
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +21 -14
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +2 -1
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +22 -14
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +2 -1
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +21 -14
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +2 -1
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +294 -275
- package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +10 -1
- package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +46 -43
- package/dist/components/inputs/File/FileUpload.d.ts +1 -1
- package/dist/components/inputs/File/FileUpload.js +17 -17
- package/dist/components/inputs/File/InputUpload.d.ts +1 -1
- package/dist/components/inputs/File/InputUpload.js +17 -17
- package/dist/components/inputs/File/fileUpload.types.d.ts +1 -1
- package/dist/components/inputs/File/inputUpload.types.d.ts +1 -1
- package/dist/components/inputs/Input/NumberInput/NumberInput.d.ts +1 -1
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +19 -19
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.d.ts +1 -1
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +18 -18
- package/dist/components/inputs/Input/PasswordInput/PasswordInput.d.ts +1 -1
- package/dist/components/inputs/Input/TextArea/TextArea.d.ts +1 -1
- package/dist/components/inputs/Input/TextArea/TextArea.js +18 -18
- package/dist/components/inputs/Input/TextInput/TextInput.d.ts +2 -2
- package/dist/components/inputs/Input/TextInput/TextInput.js +38 -36
- package/dist/components/inputs/Inputs/Form.d.ts +4 -4
- package/dist/components/inputs/Inputs/InputItem.d.ts +22 -22
- package/dist/components/inputs/Inputs/InputItem.js +36 -35
- package/dist/components/inputs/Inputs/Inputs.d.ts +2 -2
- package/dist/components/inputs/RadioGroup/RadioGroup.d.ts +2 -1
- package/dist/components/inputs/RadioGroup/RadioGroup.js +111 -107
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +1 -1
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +13 -13
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +1 -1
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +19 -19
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +1 -1
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +1 -1
- package/dist/components/inputs/Selection/Select/QuerySelect.js +19 -19
- package/dist/components/inputs/Selection/Select/Select.d.ts +1 -1
- package/dist/components/inputs/Selection/Select/Select.js +19 -19
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +1 -0
- package/dist/components/inputs/Selection/shared/SelectBase.js +37 -34
- package/dist/components/inputs/Selection/shared/select.context.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/select.context.js +8 -4
- package/dist/components/inputs/Selection/shared/select.types.d.ts +1 -1
- package/dist/components/inputs/Slider/Slider.d.ts +1 -1
- package/dist/components/inputs/Slider/Slider.js +18 -18
- package/dist/components/inputs/TextEditor/TextEditor.d.ts +1 -1
- package/dist/components/inputs/TextEditor/TextEditor.js +18 -18
- package/dist/components/inputs/Toggle/Toggle.d.ts +2 -1
- package/dist/components/inputs/Toggle/Toggle.js +63 -59
- package/dist/components/inputs/shared/form.types.d.ts +8 -9
- package/dist/components/segment/Segment.d.ts +1 -1
- package/dist/components/segment/Segment.js +17 -17
- package/dist/components/segment/segment.types.d.ts +1 -1
- package/dist/config/uiConfig.context.d.ts +5 -5
- package/dist/config/uiConfig.context.js +12 -3
- package/dist/helpers/dynamicColumns.d.ts +1 -1
- package/dist/helpers/dynamicInputs.d.ts +7 -7
- package/dist/hooks/useAutosave.d.ts +4 -4
- package/dist/hooks/useAutosave.js +49 -64
- package/dist/hooks/useAutosave.spec.d.ts +1 -0
- package/dist/hooks/useForm.d.ts +15 -39
- package/dist/hooks/useForm.js +43 -96
- package/dist/hooks/useFormAutosave.d.ts +9 -8
- package/dist/hooks/useFormAutosave.js +9 -23
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +3 -2
- package/dist/components/inputs/shared/form.binding.d.ts +0 -27
- package/dist/components/inputs/shared/form.binding.js +0 -57
- 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(
|
|
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] =
|
|
54
|
-
$[23] =
|
|
55
|
-
|
|
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 ($[
|
|
69
|
+
if ($[26] !== className || $[27] !== t13) {
|
|
66
70
|
t8 = clsx("group flex items-center gap-2", t13, className);
|
|
67
|
-
$[
|
|
68
|
-
$[
|
|
69
|
-
$[
|
|
70
|
-
} else t8 = $[
|
|
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 ($[
|
|
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
|
-
$[
|
|
127
|
-
$[
|
|
128
|
-
$[
|
|
129
|
-
$[
|
|
130
|
-
$[
|
|
131
|
-
} else t10 = $[
|
|
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 ($[
|
|
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
|
-
$[
|
|
145
|
-
$[
|
|
146
|
-
$[
|
|
147
|
-
$[
|
|
148
|
-
$[
|
|
149
|
-
$[
|
|
150
|
-
$[
|
|
151
|
-
$[
|
|
152
|
-
$[
|
|
153
|
-
$[
|
|
154
|
-
$[
|
|
155
|
-
} else t11 = $[
|
|
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 ($[
|
|
161
|
+
if ($[45] !== formFieldErrorProps) {
|
|
158
162
|
t12 = /* @__PURE__ */ jsx(FormFieldError, { ...formFieldErrorProps });
|
|
159
|
-
$[
|
|
160
|
-
$[
|
|
161
|
-
} else t12 = $[
|
|
163
|
+
$[45] = formFieldErrorProps;
|
|
164
|
+
$[46] = t12;
|
|
165
|
+
} else t12 = $[46];
|
|
162
166
|
let t13;
|
|
163
|
-
if ($[
|
|
167
|
+
if ($[47] !== t11 || $[48] !== t12) {
|
|
164
168
|
t13 = /* @__PURE__ */ jsxs(Fragment, { children: [t11, t12] });
|
|
165
|
-
$[
|
|
166
|
-
$[
|
|
167
|
-
$[
|
|
168
|
-
} else t13 = $[
|
|
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 ("
|
|
174
|
-
let
|
|
177
|
+
if ("formControl" in props && props.formControl) {
|
|
178
|
+
let formControl;
|
|
175
179
|
let innerProps;
|
|
176
180
|
let ref;
|
|
177
181
|
if ($[0] !== props) {
|
|
178
|
-
({
|
|
182
|
+
({formControl, ref, ...innerProps} = props);
|
|
179
183
|
$[0] = props;
|
|
180
|
-
$[1] =
|
|
184
|
+
$[1] = formControl;
|
|
181
185
|
$[2] = innerProps;
|
|
182
186
|
$[3] = ref;
|
|
183
187
|
} else {
|
|
184
|
-
|
|
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
|
|
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,
|
|
196
|
-
isSelected:
|
|
197
|
-
onChange:
|
|
198
|
-
onBlur:
|
|
199
|
-
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:
|
|
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] !==
|
|
213
|
-
t1 = /* @__PURE__ */ jsx(
|
|
214
|
-
control:
|
|
215
|
-
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] =
|
|
219
|
-
$[10] =
|
|
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 {
|
|
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
|
|
4
|
-
|
|
3
|
+
export interface FormControl<TFieldValues extends FieldValues, TType> {
|
|
4
|
+
control: Control<TFieldValues>;
|
|
5
5
|
name: {
|
|
6
|
-
[K in
|
|
7
|
-
}[
|
|
6
|
+
[K in FieldPath<TFieldValues>]: FieldPathValue<TFieldValues, K> extends TType ? K : never;
|
|
7
|
+
}[FieldPath<TFieldValues>];
|
|
8
8
|
}
|
|
9
|
-
export type FormControlProps<TProps, TFieldValues extends
|
|
10
|
-
|
|
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
|
|
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 '
|
|
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 ("
|
|
185
|
-
let
|
|
184
|
+
if ("formControl" in props && props.formControl) {
|
|
185
|
+
let formControl;
|
|
186
186
|
let innerProps;
|
|
187
187
|
let ref;
|
|
188
188
|
if ($[0] !== props) {
|
|
189
|
-
({
|
|
189
|
+
({formControl, ref, ...innerProps} = props);
|
|
190
190
|
$[0] = props;
|
|
191
|
-
$[1] =
|
|
191
|
+
$[1] = formControl;
|
|
192
192
|
$[2] = innerProps;
|
|
193
193
|
$[3] = ref;
|
|
194
194
|
} else {
|
|
195
|
-
|
|
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
|
|
202
|
+
const { field, fieldState: t2 } = t1;
|
|
203
203
|
const { error } = t2;
|
|
204
204
|
return /* @__PURE__ */ jsx(SegmentBase, {
|
|
205
205
|
...innerProps,
|
|
206
|
-
ref: mergeRefs(ref,
|
|
207
|
-
value:
|
|
208
|
-
onChange:
|
|
209
|
-
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] !==
|
|
221
|
-
t1 = /* @__PURE__ */ jsx(
|
|
222
|
-
control:
|
|
223
|
-
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] =
|
|
227
|
-
$[10] =
|
|
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 '
|
|
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: {
|
|
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 '
|
|
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 {
|
|
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: (
|
|
51
|
-
|
|
50
|
+
render: (formControl: {
|
|
51
|
+
control: Control<z.infer<TSchema>>;
|
|
52
52
|
name: K;
|
|
53
|
-
}, form:
|
|
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> | ((
|
|
58
|
-
|
|
57
|
+
[K in keyof z.infer<TSchema>]?: DynamicInputDef<TSchema, K> | ((formControl: {
|
|
58
|
+
control: Control<z.infer<TSchema>>;
|
|
59
59
|
name: K;
|
|
60
|
-
}, form:
|
|
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 {
|
|
2
|
-
export interface UseAutosaveProps<TFieldValues extends
|
|
3
|
-
form:
|
|
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
|
|
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
|
|
6
|
-
if (
|
|
7
|
-
|
|
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
|
|
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
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
+
reset,
|
|
83
68
|
trigger
|
|
84
69
|
]);
|
|
85
70
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|