@povio/ui 3.0.0-rc.3 → 3.1.0
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/README.md +39 -0
- package/dist/assets/icons/AlignCenter.js +11 -26
- package/dist/assets/icons/AlignLeft.js +11 -26
- package/dist/assets/icons/AlignLeftRight.js +11 -26
- package/dist/assets/icons/AlignRight.js +11 -26
- package/dist/assets/icons/ArrowDropDown.js +11 -26
- package/dist/assets/icons/ArrowDropUp.js +11 -26
- package/dist/assets/icons/ArrowLeft.js +11 -26
- package/dist/assets/icons/ArrowRight.js +11 -26
- package/dist/assets/icons/Bold.js +11 -26
- package/dist/assets/icons/BulletedList.js +11 -26
- package/dist/assets/icons/Calendar.js +13 -28
- package/dist/assets/icons/Check.js +13 -28
- package/dist/assets/icons/CheckCircle.js +11 -26
- package/dist/assets/icons/CheckboxCheckmark.js +14 -29
- package/dist/assets/icons/CheckboxIndeterminate.js +14 -29
- package/dist/assets/icons/ChevronDown.js +13 -28
- package/dist/assets/icons/ChevronLeft.js +13 -28
- package/dist/assets/icons/ChevronRight.js +13 -28
- package/dist/assets/icons/ChevronUp.js +13 -28
- package/dist/assets/icons/ChevronsLeft.js +13 -28
- package/dist/assets/icons/ChevronsRight.js +13 -28
- package/dist/assets/icons/Clock.js +11 -26
- package/dist/assets/icons/Close.js +11 -26
- package/dist/assets/icons/DateTime.js +14 -35
- package/dist/assets/icons/DragIndicator.js +11 -26
- package/dist/assets/icons/File.js +13 -28
- package/dist/assets/icons/Highlight.js +11 -26
- package/dist/assets/icons/HighlightOn.js +15 -49
- package/dist/assets/icons/Home.js +11 -26
- package/dist/assets/icons/Info.js +16 -37
- package/dist/assets/icons/Italic.js +11 -26
- package/dist/assets/icons/Link.js +11 -26
- package/dist/assets/icons/Menu.js +11 -26
- package/dist/assets/icons/NumberedList.js +11 -26
- package/dist/assets/icons/PointerHorizontal.js +11 -26
- package/dist/assets/icons/PointerVertical.js +11 -26
- package/dist/assets/icons/Search.js +11 -26
- package/dist/assets/icons/Send.js +13 -28
- package/dist/assets/icons/Strikethrough.js +11 -26
- package/dist/assets/icons/TextColor.js +14 -48
- package/dist/assets/icons/Today.js +11 -26
- package/dist/assets/icons/Underlined.js +13 -28
- package/dist/assets/icons/Upload.js +14 -35
- package/dist/assets/icons/Visibility.js +11 -26
- package/dist/assets/icons/VisibilityOff.js +11 -26
- package/dist/assets/icons/WarningFilled.js +13 -28
- package/dist/components/Breadcrumbs/Breadcrumbs.js +56 -207
- package/dist/components/Menu/Menu.d.ts +4 -0
- package/dist/components/Menu/Menu.js +2 -18
- package/dist/components/Menu/MenuDesktop.js +7 -41
- package/dist/components/Menu/MenuItem.js +9 -32
- package/dist/components/Menu/MenuMobile.d.ts +1 -1
- package/dist/components/Menu/MenuMobile.js +39 -97
- package/dist/components/Menu/MenuPopover.js +29 -105
- package/dist/components/buttons/IconButton/IconButton.js +8 -40
- package/dist/components/buttons/InlineIconButton/InlineIconButton.d.ts +1 -2
- package/dist/components/buttons/InlineIconButton/InlineIconButton.js +9 -34
- package/dist/components/buttons/PillButton/PillButton.js +17 -55
- package/dist/components/buttons/SplitButton/SplitButton.js +18 -103
- package/dist/components/buttons/TextButton/TextButton.js +8 -30
- package/dist/components/buttons/ToggleButton/ToggleButton.js +8 -28
- package/dist/components/buttons/shared/ButtonContent.js +22 -80
- package/dist/components/inputs/Checkbox/Checkbox.d.ts +0 -1
- package/dist/components/inputs/Checkbox/Checkbox.js +35 -201
- package/dist/components/inputs/Checkbox/CheckboxCheckmark.js +10 -24
- package/dist/components/inputs/Checkbox/checkbox.cva.d.ts +0 -3
- package/dist/components/inputs/Checkbox/checkbox.cva.js +1 -2
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +5 -12
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +75 -373
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +5 -12
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +186 -492
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +5 -14
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +47 -273
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +3 -7
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +121 -611
- package/dist/components/inputs/DateTime/shared/Calendar.d.ts +3 -5
- package/dist/components/inputs/DateTime/shared/Calendar.js +120 -338
- package/dist/components/inputs/DateTime/shared/CalendarCell.d.ts +2 -4
- package/dist/components/inputs/DateTime/shared/CalendarCell.js +103 -310
- package/dist/components/inputs/DateTime/shared/CalendarGrid.d.ts +2 -4
- package/dist/components/inputs/DateTime/shared/CalendarGrid.js +33 -150
- package/dist/components/inputs/DateTime/shared/CalendarHeader.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/CalendarHeader.js +98 -249
- package/dist/components/inputs/DateTime/shared/CalendarSelectHeader.js +137 -318
- package/dist/components/inputs/DateTime/shared/DateField.js +112 -286
- package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +3 -14
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +129 -356
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.d.ts +0 -15
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.js +11 -96
- package/dist/components/inputs/DateTime/shared/DateTimeDialog.d.ts +4 -1
- package/dist/components/inputs/DateTime/shared/DateTimeDialog.js +28 -81
- package/dist/components/inputs/DateTime/shared/DateTimeDialogFooter.js +10 -59
- package/dist/components/inputs/DateTime/shared/MonthPicker.js +58 -103
- package/dist/components/inputs/DateTime/shared/RangeCalendar.js +82 -193
- package/dist/components/inputs/DateTime/shared/TimeField.js +8 -27
- package/dist/components/inputs/DateTime/shared/TimePickerForm.js +110 -279
- package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +1 -4
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +65 -210
- package/dist/components/inputs/DateTime/shared/YearPicker.js +68 -119
- package/dist/components/inputs/File/FileUpload.js +45 -88
- package/dist/components/inputs/File/FileUploadContainer.js +7 -15
- package/dist/components/inputs/File/InputUpload.js +79 -317
- package/dist/components/inputs/File/shared/FileCard.js +41 -104
- package/dist/components/inputs/File/shared/FileCardList.js +12 -47
- package/dist/components/inputs/File/shared/FileUploadContent.js +44 -175
- package/dist/components/inputs/File/shared/FileUploadContentEmpty.js +46 -149
- package/dist/components/inputs/File/shared/FileUploadContentError.js +93 -234
- package/dist/components/inputs/File/shared/FileUploadContentFilled.js +97 -230
- package/dist/components/inputs/File/shared/FileUploadContentLoading.js +55 -199
- package/dist/components/inputs/File/shared/InputUploadContent.js +34 -148
- package/dist/components/inputs/File/shared/InputUploadFilled.js +8 -49
- package/dist/components/inputs/File/shared/ProgressBar.d.ts +2 -2
- package/dist/components/inputs/File/shared/ProgressBar.js +20 -53
- package/dist/components/inputs/File/shared/fileUpload.cva.d.ts +1 -1
- package/dist/components/inputs/File/shared/fileUpload.cva.js +1 -1
- package/dist/components/inputs/File/shared/progressBar.cva.d.ts +38 -0
- package/dist/components/inputs/File/shared/progressBar.cva.js +28 -0
- package/dist/components/inputs/FormField/FormField.d.ts +3 -3
- package/dist/components/inputs/FormField/FormField.js +37 -119
- package/dist/components/inputs/FormField/FormFieldError.js +5 -25
- package/dist/components/inputs/FormField/FormFieldHeader.d.ts +2 -2
- package/dist/components/inputs/FormField/FormFieldHeader.js +22 -81
- package/dist/components/inputs/FormField/FormFieldHeaderClose.js +7 -31
- package/dist/components/inputs/FormField/FormFieldHelper.js +6 -26
- package/dist/components/inputs/FormField/FormFieldLabel.d.ts +2 -2
- package/dist/components/inputs/FormField/FormFieldLabel.js +9 -40
- package/dist/components/inputs/Input/NumberInput/NumberInput.d.ts +2 -5
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +97 -447
- package/dist/components/inputs/Input/PasswordInput/PasswordInput.js +9 -48
- package/dist/components/inputs/Input/TextArea/TextArea.js +90 -305
- package/dist/components/inputs/Input/TextInput/TextInput.d.ts +1 -3
- package/dist/components/inputs/Input/TextInput/TextInput.js +90 -419
- package/dist/components/inputs/Input/shared/InputContent.js +59 -192
- package/dist/components/inputs/Inputs/Form.js +11 -40
- package/dist/components/inputs/Inputs/InputItem.d.ts +21 -15
- package/dist/components/inputs/Inputs/InputItem.js +14 -69
- package/dist/components/inputs/Inputs/Inputs.js +11 -37
- package/dist/components/inputs/RadioGroup/RadioGroup.d.ts +1 -3
- package/dist/components/inputs/RadioGroup/RadioGroup.js +61 -353
- package/dist/components/inputs/RadioGroup/radio.cva.d.ts +0 -45
- package/dist/components/inputs/RadioGroup/radio.cva.js +1 -48
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +2 -6
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +22 -217
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +18 -3
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +8 -107
- package/dist/components/inputs/Selection/Select/Select.d.ts +3 -7
- package/dist/components/inputs/Selection/Select/Select.js +18 -227
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +3 -8
- package/dist/components/inputs/Selection/shared/SelectBase.js +18 -69
- package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +138 -393
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +116 -397
- package/dist/components/inputs/Selection/shared/SelectInputTags.js +25 -99
- package/dist/components/inputs/Selection/shared/SelectListBox.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.js +52 -164
- package/dist/components/inputs/Selection/shared/SelectListBoxItem.js +35 -85
- package/dist/components/inputs/Selection/shared/SelectListBoxItemSelectAll.js +16 -69
- package/dist/components/inputs/Selection/shared/SelectListBoxLoadingItem.js +21 -70
- package/dist/components/inputs/Selection/shared/SelectListBoxSelectionBar.js +9 -58
- package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +6 -11
- package/dist/components/inputs/Selection/shared/select.context.d.ts +2 -3
- package/dist/components/inputs/Selection/shared/select.context.js +36 -67
- package/dist/components/inputs/Selection/shared/select.types.d.ts +2 -3
- package/dist/components/inputs/Selection/shared/useSelectItems.js +49 -109
- package/dist/components/inputs/Slider/Slider.d.ts +1 -2
- package/dist/components/inputs/Slider/Slider.js +76 -265
- package/dist/components/inputs/TextEditor/TextEditor.d.ts +0 -1
- package/dist/components/inputs/TextEditor/TextEditor.js +98 -447
- package/dist/components/inputs/TextEditor/Toolbar/ColorPicker.js +11 -37
- package/dist/components/inputs/TextEditor/Toolbar/ColorPickerDropdown.js +30 -102
- package/dist/components/inputs/TextEditor/Toolbar/HyperlinkAction.js +45 -194
- package/dist/components/inputs/TextEditor/Toolbar/TextAlignSelect.js +28 -88
- package/dist/components/inputs/TextEditor/Toolbar/TextColorSelect.js +14 -48
- package/dist/components/inputs/TextEditor/Toolbar/TextEditorToolbar.js +19 -66
- package/dist/components/inputs/TextEditor/Toolbar/TextHighlightSelect.js +15 -49
- package/dist/components/inputs/TextEditor/Toolbar/TextListActions.js +32 -92
- package/dist/components/inputs/TextEditor/Toolbar/TextMarksActions.js +54 -126
- package/dist/components/inputs/TextEditor/Toolbar/TextStyleSelect.js +38 -141
- package/dist/components/inputs/Toggle/Toggle.d.ts +0 -1
- package/dist/components/inputs/Toggle/Toggle.js +37 -214
- package/dist/components/inputs/Toggle/toggle.cva.d.ts +0 -3
- package/dist/components/inputs/Toggle/toggle.cva.js +1 -2
- package/dist/components/inputs/shared/CheckContent.d.ts +1 -2
- package/dist/components/inputs/shared/CheckContent.js +11 -21
- package/dist/components/inputs/shared/InputClear.d.ts +1 -2
- package/dist/components/inputs/shared/InputClear.js +12 -88
- package/dist/components/inputs/shared/TooltipWrapper.js +11 -50
- package/dist/components/inputs/shared/input.cva.d.ts +0 -28
- package/dist/components/inputs/shared/input.cva.js +4 -38
- package/dist/components/navigation/Accordion/Accordion.js +22 -69
- package/dist/components/navigation/Accordion/AccordionItem.js +41 -86
- package/dist/components/navigation/Stepper/Stepper.js +22 -67
- package/dist/components/navigation/Stepper/StepperItem.js +31 -104
- package/dist/components/navigation/Stepper/StepperSeparator.js +5 -23
- package/dist/components/overlays/ActionModal/ActionModal.js +35 -169
- package/dist/components/overlays/BottomSheet/BottomSheet.js +25 -98
- package/dist/components/overlays/BottomSheet/BottomSheetHeader.js +8 -48
- package/dist/components/overlays/Drawer/Drawer.js +22 -64
- package/dist/components/overlays/Modal/modal.cva.js +1 -1
- package/dist/components/overlays/ResponsivePopover/ResponsivePopover.d.ts +5 -1
- package/dist/components/overlays/ResponsivePopover/ResponsivePopover.js +28 -83
- package/dist/components/overlays/Tooltip/Tooltip.js +28 -137
- package/dist/components/overlays/Tooltip/TooltipEllipsis.js +12 -37
- package/dist/components/segment/Segment.js +57 -218
- package/dist/components/segment/SegmentItem.js +10 -67
- package/dist/components/shared/pagination/Pagination.js +22 -108
- package/dist/components/shared/pagination/PaginationList.js +64 -167
- package/dist/components/status/Alert/Alert.js +30 -97
- package/dist/components/status/Loader/Loader.js +22 -77
- package/dist/components/status/Toast/Toast.js +17 -22
- package/dist/components/status/Toast/toast.cva.d.ts +14 -3
- package/dist/components/status/Toast/toast.cva.js +12 -10
- package/dist/components/status/Toast/useToast.js +57 -62
- package/dist/components/table/ColumnConfig.js +54 -158
- package/dist/components/table/InfiniteTable.js +16 -67
- package/dist/components/table/PaginatedTable.js +18 -84
- package/dist/components/table/Table.js +30 -30
- package/dist/components/table/table.cva.d.ts +7 -0
- package/dist/components/table/table.cva.js +2 -1
- package/dist/components/text/Link/Link.js +7 -19
- package/dist/components/text/Pill/Pill.d.ts +15 -0
- package/dist/components/text/Pill/Pill.js +44 -0
- package/dist/components/text/Typography/Typography.js +8 -23
- package/dist/config/confirmation.context.js +1 -1
- package/dist/config/link.context.js +9 -23
- package/dist/config/router.context.js +16 -42
- package/dist/config/theme.context.js +45 -98
- package/dist/config/uiConfig.context.d.ts +10 -21
- package/dist/config/uiConfig.context.js +18 -69
- package/dist/config/uiOverrides.context.d.ts +10 -20
- package/dist/config/uiOverrides.context.js +14 -54
- package/dist/helpers/dynamicInputs.d.ts +5 -5
- package/dist/helpers/dynamicInputs.js +0 -3
- package/dist/hooks/useAutosave.d.ts +1 -2
- package/dist/hooks/useAutosave.js +4 -12
- package/dist/hooks/useBreakpoint.js +3 -16
- package/dist/hooks/useDebounceCallback.js +17 -51
- package/dist/hooks/useFilters.js +64 -125
- package/dist/hooks/useForm.js +8 -42
- package/dist/hooks/useFormAutosave.d.ts +1 -3
- package/dist/hooks/useFormAutosave.js +30 -122
- package/dist/hooks/useIntersectionObserver.d.ts +1 -1
- package/dist/hooks/useIntersectionObserver.js +24 -91
- package/dist/hooks/useLocalStorage.js +10 -43
- package/dist/hooks/useLongPressRepeat.js +20 -55
- package/dist/hooks/usePagination.js +19 -49
- package/dist/hooks/useScrollableListBox.js +16 -37
- package/dist/hooks/useSorting.js +28 -69
- package/dist/hooks/useStateAndRef.js +7 -21
- package/dist/hooks/useTableColumnConfig.js +31 -124
- package/dist/hooks/useTranslationMemo.js +5 -25
- package/dist/index.d.ts +7 -16
- package/dist/index.js +6 -13
- package/dist/tw-ui-plugin.js +0 -6
- package/dist/utils/date-time.utils.d.ts +10 -38
- package/dist/utils/date-time.utils.js +22 -136
- package/package.json +1 -1
- package/dist/components/inputs/DateTime/shared/datePicker.types.d.ts +0 -5
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.d.ts +0 -16
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.js +0 -16
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.d.ts +0 -15
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.js +0 -32
- package/dist/components/inputs/DateTime/shared/dateSegment.utils.d.ts +0 -2
- package/dist/components/inputs/DateTime/shared/dateSegment.utils.spec.d.ts +0 -1
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.d.ts +0 -40
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.js +0 -85
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.spec.d.ts +0 -1
- package/dist/components/inputs/FormField/formFieldHeader.cva.d.ts +0 -13
- package/dist/components/inputs/FormField/formFieldHeader.cva.js +0 -14
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeField.d.ts +0 -45
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeField.js +0 -571
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.d.ts +0 -35
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +0 -575
- package/dist/components/inputs/Input/TextArea/TextArea.cva.d.ts +0 -8
- package/dist/components/inputs/Input/TextArea/TextArea.cva.js +0 -5
- package/dist/components/inputs/Input/shared/numberStatic.utils.d.ts +0 -1
- package/dist/components/inputs/Input/shared/numberStatic.utils.js +0 -7
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +0 -37
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +0 -14
- package/dist/components/inputs/Selection/Select/QuerySelect.js +0 -178
- package/dist/components/inputs/Selection/shared/StaticSelectTrailingContent.d.ts +0 -9
- package/dist/components/inputs/Selection/shared/StaticSelectTrailingContent.js +0 -47
- package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +0 -14
- package/dist/components/inputs/Selection/shared/querySelect.utils.js +0 -43
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.d.ts +0 -6
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.js +0 -5
- package/dist/components/inputs/Selection/shared/selectInput.cva.d.ts +0 -12
- package/dist/components/inputs/Selection/shared/selectInput.cva.js +0 -8
- package/dist/components/inputs/Selection/shared/staticSelect.utils.d.ts +0 -23
- package/dist/components/inputs/Selection/shared/staticSelect.utils.js +0 -54
- package/dist/components/inputs/Selection/shared/staticSelect.utils.spec.d.ts +0 -1
- package/dist/components/inputs/Skeleton/InputFrame.d.ts +0 -82
- package/dist/components/inputs/Skeleton/InputFrame.js +0 -548
- package/dist/components/inputs/shared/tooltipWrapper.cva.d.ts +0 -8
- package/dist/components/inputs/shared/tooltipWrapper.cva.js +0 -5
- package/dist/components/inputs/shared/useStaticInputHandoff.d.ts +0 -14
- package/dist/components/inputs/shared/useStaticInputHandoff.js +0 -100
- package/dist/hooks/useAutosave.spec.d.ts +0 -1
- package/dist/hooks/useFormAutosave.spec.d.ts +0 -1
- package/dist/hooks/useKeyInteractions.d.ts +0 -20
- package/dist/hooks/useKeyInteractions.js +0 -54
- package/dist/hooks/useKeyInteractions.spec.d.ts +0 -1
- package/dist/hooks/useQueryAutocomplete.d.ts +0 -14
- package/dist/hooks/useQueryAutocomplete.js +0 -72
- package/dist/utils/query.utils.d.ts +0 -4
- package/dist/utils/query.utils.js +0 -8
package/dist/hooks/useFilters.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { UIRouter } from "../config/router.context.js";
|
|
2
2
|
import { RoutingUtils } from "../utils/routing.utils.js";
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
//#region src/hooks/useFilters.ts
|
|
7
6
|
function getFieldType(schema, fieldKey) {
|
|
@@ -51,138 +50,78 @@ var parseFilterFromQuery = (searchParams, schema) => {
|
|
|
51
50
|
}
|
|
52
51
|
return filter;
|
|
53
52
|
};
|
|
54
|
-
var useFilters = (defaultFilterValues,
|
|
55
|
-
const $ = c(33);
|
|
56
|
-
const prefix = t0 === void 0 ? "" : t0;
|
|
53
|
+
var useFilters = (defaultFilterValues, prefix = "", schema) => {
|
|
57
54
|
const { searchParams, replace } = UIRouter.useUIRouter();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$[1] = searchParams;
|
|
63
|
-
$[2] = t1;
|
|
64
|
-
} else t1 = $[2];
|
|
65
|
-
const [filterData, setFilterData] = useState(t1);
|
|
66
|
-
let t2;
|
|
67
|
-
if ($[3] !== defaultFilterValues || $[4] !== prefix || $[5] !== replace || $[6] !== schema || $[7] !== searchParams) {
|
|
68
|
-
t2 = () => {
|
|
69
|
-
const setUrlToDefaultFilters = () => {
|
|
70
|
-
const flatFilterQuery = serializeFiltersToQuery(defaultFilterValues, prefix);
|
|
71
|
-
replace(".", {
|
|
72
|
-
...RoutingUtils.toRouterSearch(searchParams),
|
|
73
|
-
...flatFilterQuery
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
const currentFilters = parseFilterFromQuery(searchParams, schema);
|
|
77
|
-
const hasFiltersSet = Object.keys(currentFilters).length > 0;
|
|
78
|
-
if (defaultFilterValues && !hasFiltersSet) setUrlToDefaultFilters();
|
|
79
|
-
};
|
|
80
|
-
$[3] = defaultFilterValues;
|
|
81
|
-
$[4] = prefix;
|
|
82
|
-
$[5] = replace;
|
|
83
|
-
$[6] = schema;
|
|
84
|
-
$[7] = searchParams;
|
|
85
|
-
$[8] = t2;
|
|
86
|
-
} else t2 = $[8];
|
|
87
|
-
let t3;
|
|
88
|
-
if ($[9] !== defaultFilterValues || $[10] !== prefix || $[11] !== schema) {
|
|
89
|
-
t3 = [
|
|
90
|
-
defaultFilterValues,
|
|
91
|
-
prefix,
|
|
92
|
-
schema
|
|
93
|
-
];
|
|
94
|
-
$[9] = defaultFilterValues;
|
|
95
|
-
$[10] = prefix;
|
|
96
|
-
$[11] = schema;
|
|
97
|
-
$[12] = t3;
|
|
98
|
-
} else t3 = $[12];
|
|
99
|
-
useEffect(t2, t3);
|
|
100
|
-
let t4;
|
|
101
|
-
let t5;
|
|
102
|
-
if ($[13] !== schema || $[14] !== searchParams) {
|
|
103
|
-
t4 = () => {
|
|
104
|
-
setFilterData(parseFilterFromQuery(searchParams, schema));
|
|
105
|
-
};
|
|
106
|
-
t5 = [searchParams, schema];
|
|
107
|
-
$[13] = schema;
|
|
108
|
-
$[14] = searchParams;
|
|
109
|
-
$[15] = t4;
|
|
110
|
-
$[16] = t5;
|
|
111
|
-
} else {
|
|
112
|
-
t4 = $[15];
|
|
113
|
-
t5 = $[16];
|
|
114
|
-
}
|
|
115
|
-
useEffect(t4, t5);
|
|
116
|
-
let t6;
|
|
117
|
-
if ($[17] !== defaultFilterValues || $[18] !== filterData || $[19] !== prefix || $[20] !== replace || $[21] !== searchParams) {
|
|
118
|
-
t6 = (data) => {
|
|
119
|
-
let newFilters = { ...filterData };
|
|
120
|
-
const isReset = Object.keys(data).length === 0;
|
|
121
|
-
if (data === defaultFilterValues) newFilters = { ...defaultFilterValues };
|
|
122
|
-
else if (isReset) newFilters = {};
|
|
123
|
-
else Object.entries(data).forEach((t7) => {
|
|
124
|
-
const [key, value] = t7;
|
|
125
|
-
if (value === void 0) delete newFilters[key];
|
|
126
|
-
else newFilters[key] = value;
|
|
127
|
-
});
|
|
128
|
-
const prefixPart = prefix ? `${prefix}-` : "";
|
|
129
|
-
const cleanedQuery = RoutingUtils.toRouterSearch(searchParams);
|
|
130
|
-
Object.keys(cleanedQuery).forEach((key_0) => {
|
|
131
|
-
if (key_0.startsWith(`filter[${prefixPart}`)) delete cleanedQuery[key_0];
|
|
132
|
-
});
|
|
133
|
-
const flatFilterQuery_0 = serializeFiltersToQuery(newFilters, prefix);
|
|
55
|
+
const [filterData, setFilterData] = useState(() => parseFilterFromQuery(searchParams, schema));
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const setUrlToDefaultFilters = () => {
|
|
58
|
+
const flatFilterQuery = serializeFiltersToQuery(defaultFilterValues, prefix);
|
|
134
59
|
replace(".", {
|
|
135
|
-
...
|
|
136
|
-
...
|
|
137
|
-
});
|
|
138
|
-
setFilterData(newFilters);
|
|
139
|
-
};
|
|
140
|
-
$[17] = defaultFilterValues;
|
|
141
|
-
$[18] = filterData;
|
|
142
|
-
$[19] = prefix;
|
|
143
|
-
$[20] = replace;
|
|
144
|
-
$[21] = searchParams;
|
|
145
|
-
$[22] = t6;
|
|
146
|
-
} else t6 = $[22];
|
|
147
|
-
const setFilterValue = t6;
|
|
148
|
-
let t7;
|
|
149
|
-
if ($[23] !== filterData) {
|
|
150
|
-
t7 = (keys) => {
|
|
151
|
-
const result = {};
|
|
152
|
-
keys.forEach((key_1) => {
|
|
153
|
-
result[key_1] = filterData[key_1];
|
|
60
|
+
...RoutingUtils.toRouterSearch(searchParams),
|
|
61
|
+
...flatFilterQuery
|
|
154
62
|
});
|
|
155
|
-
return result;
|
|
156
|
-
};
|
|
157
|
-
$[23] = filterData;
|
|
158
|
-
$[24] = t7;
|
|
159
|
-
} else t7 = $[24];
|
|
160
|
-
const getFilterValue = t7;
|
|
161
|
-
let t8;
|
|
162
|
-
if ($[25] !== defaultFilterValues || $[26] !== setFilterValue) {
|
|
163
|
-
t8 = () => {
|
|
164
|
-
setFilterValue(defaultFilterValues ?? {});
|
|
165
63
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
64
|
+
const currentFilters = parseFilterFromQuery(searchParams, schema);
|
|
65
|
+
const hasFiltersSet = Object.keys(currentFilters).length > 0;
|
|
66
|
+
if (defaultFilterValues && !hasFiltersSet) setUrlToDefaultFilters();
|
|
67
|
+
}, [
|
|
68
|
+
defaultFilterValues,
|
|
69
|
+
prefix,
|
|
70
|
+
schema
|
|
71
|
+
]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
setFilterData(parseFilterFromQuery(searchParams, schema));
|
|
74
|
+
}, [searchParams, schema]);
|
|
75
|
+
const setFilterValue = useCallback((data) => {
|
|
76
|
+
let newFilters = { ...filterData };
|
|
77
|
+
const isReset = Object.keys(data).length === 0;
|
|
78
|
+
if (data === defaultFilterValues) newFilters = { ...defaultFilterValues };
|
|
79
|
+
else if (isReset) newFilters = {};
|
|
80
|
+
else Object.entries(data).forEach(([key, value]) => {
|
|
81
|
+
if (value === void 0) delete newFilters[key];
|
|
82
|
+
else newFilters[key] = value;
|
|
83
|
+
});
|
|
84
|
+
const prefixPart = prefix ? `${prefix}-` : "";
|
|
85
|
+
const cleanedQuery = RoutingUtils.toRouterSearch(searchParams);
|
|
86
|
+
Object.keys(cleanedQuery).forEach((key) => {
|
|
87
|
+
if (key.startsWith(`filter[${prefixPart}`)) delete cleanedQuery[key];
|
|
88
|
+
});
|
|
89
|
+
const flatFilterQuery = serializeFiltersToQuery(newFilters, prefix);
|
|
90
|
+
replace(".", {
|
|
91
|
+
...cleanedQuery,
|
|
92
|
+
...flatFilterQuery
|
|
93
|
+
});
|
|
94
|
+
setFilterData(newFilters);
|
|
95
|
+
}, [
|
|
96
|
+
filterData,
|
|
97
|
+
prefix,
|
|
98
|
+
replace,
|
|
99
|
+
defaultFilterValues,
|
|
100
|
+
searchParams
|
|
101
|
+
]);
|
|
102
|
+
const getFilterValue = useCallback((keys) => {
|
|
103
|
+
const result = {};
|
|
104
|
+
keys.forEach((key) => {
|
|
105
|
+
result[key] = filterData[key];
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
108
|
+
}, [filterData]);
|
|
109
|
+
const clearAllFilters = useCallback(() => {
|
|
110
|
+
setFilterValue(defaultFilterValues ?? {});
|
|
111
|
+
}, [defaultFilterValues, setFilterValue]);
|
|
112
|
+
return useMemo(() => {
|
|
113
|
+
return {
|
|
174
114
|
filterData,
|
|
175
115
|
setFilterValue,
|
|
176
116
|
getFilterValue,
|
|
177
117
|
clearAllFilters
|
|
178
118
|
};
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return t9;
|
|
119
|
+
}, [
|
|
120
|
+
filterData,
|
|
121
|
+
setFilterValue,
|
|
122
|
+
getFilterValue,
|
|
123
|
+
clearAllFilters
|
|
124
|
+
]);
|
|
186
125
|
};
|
|
187
126
|
//#endregion
|
|
188
127
|
export { useFilters };
|
package/dist/hooks/useForm.js
CHANGED
|
@@ -1,48 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
2
|
import { useForm } from "react-hook-form";
|
|
3
3
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
4
|
//#region src/hooks/useForm.ts
|
|
5
|
-
function useForm$1(
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
({resolver, zodSchema, defaultValues, ...props} = t0);
|
|
13
|
-
$[0] = t0;
|
|
14
|
-
$[1] = defaultValues;
|
|
15
|
-
$[2] = props;
|
|
16
|
-
$[3] = resolver;
|
|
17
|
-
$[4] = zodSchema;
|
|
18
|
-
} else {
|
|
19
|
-
defaultValues = $[1];
|
|
20
|
-
props = $[2];
|
|
21
|
-
resolver = $[3];
|
|
22
|
-
zodSchema = $[4];
|
|
23
|
-
}
|
|
24
|
-
let t1;
|
|
25
|
-
if ($[5] !== resolver || $[6] !== zodSchema) {
|
|
26
|
-
t1 = resolver ?? (zodSchema ? zodResolver(zodSchema) : void 0);
|
|
27
|
-
$[5] = resolver;
|
|
28
|
-
$[6] = zodSchema;
|
|
29
|
-
$[7] = t1;
|
|
30
|
-
} else t1 = $[7];
|
|
31
|
-
const formResolver = t1;
|
|
32
|
-
const t2 = defaultValues;
|
|
33
|
-
let t3;
|
|
34
|
-
if ($[8] !== formResolver || $[9] !== props || $[10] !== t2) {
|
|
35
|
-
t3 = {
|
|
36
|
-
...props,
|
|
37
|
-
resolver: formResolver,
|
|
38
|
-
defaultValues: t2
|
|
39
|
-
};
|
|
40
|
-
$[8] = formResolver;
|
|
41
|
-
$[9] = props;
|
|
42
|
-
$[10] = t2;
|
|
43
|
-
$[11] = t3;
|
|
44
|
-
} else t3 = $[11];
|
|
45
|
-
return useForm(t3);
|
|
5
|
+
function useForm$1({ resolver, zodSchema, defaultValues, ...props }) {
|
|
6
|
+
const formResolver = useMemo(() => resolver ?? (zodSchema ? zodResolver(zodSchema) : void 0), [resolver, zodSchema]);
|
|
7
|
+
return useForm({
|
|
8
|
+
...props,
|
|
9
|
+
resolver: formResolver,
|
|
10
|
+
defaultValues
|
|
11
|
+
});
|
|
46
12
|
}
|
|
47
13
|
//#endregion
|
|
48
14
|
export { useForm$1 as useForm };
|
|
@@ -5,11 +5,9 @@ import { UseFormProps, UseFormResolverProps } from './useForm';
|
|
|
5
5
|
export type UseFormAutosaveProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TResponse = unknown> = Omit<UseFormProps<TFieldValues, TContext, TTransformedValues>, "defaultValues"> & UseFormResolverProps<TFieldValues, TTransformedValues> & {
|
|
6
6
|
autosaveDelay?: UseAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>["delay"];
|
|
7
7
|
enableAutosave?: UseAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>["enabled"];
|
|
8
|
-
autosaveOn?: UseAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>["trigger"];
|
|
9
|
-
normalizeAutosaveData?: (data: Partial<TTransformedValues>) => Partial<TTransformedValues> | undefined;
|
|
10
8
|
onAutosave: UseAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>["onSave"];
|
|
11
9
|
getResetValues: () => UseFormProps<TFieldValues, TContext, TTransformedValues>["defaultValues"];
|
|
12
10
|
resetDeps: DependencyList;
|
|
13
11
|
resetTimeout?: number;
|
|
14
12
|
};
|
|
15
|
-
export declare function useFormAutosave<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TResponse = any>({ autosaveDelay, enableAutosave,
|
|
13
|
+
export declare function useFormAutosave<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TResponse = any>({ autosaveDelay, enableAutosave, onAutosave, getResetValues, resetDeps, resetTimeout, ...props }: UseFormAutosaveProps<TFieldValues, TContext, TTransformedValues, TResponse>): import('react-hook-form').UseFormReturn<TFieldValues, TContext, TTransformedValues>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ObjectUtils } from "../utils/object.utils.js";
|
|
2
2
|
import { useAutosave } from "./useAutosave.js";
|
|
3
3
|
import { useForm } from "./useForm.js";
|
|
4
|
-
import { c } from "react/compiler-runtime";
|
|
5
4
|
import { useEffect, useRef } from "react";
|
|
6
5
|
//#region src/hooks/useFormAutosave.ts
|
|
7
6
|
var getResetTimeoutErrorMessage = (resetTimeout) => `Form Reset Timeout (${resetTimeout}ms) - Action Required
|
|
@@ -16,130 +15,39 @@ Solutions:
|
|
|
16
15
|
1. Ensure reset dependencies include all relevant state variables
|
|
17
16
|
2. Confirm your submission handler updates state properly (check query invalidation)
|
|
18
17
|
3. For slower operations, consider increasing the timeout threshold`;
|
|
19
|
-
function useFormAutosave(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let normalizeAutosaveData;
|
|
25
|
-
let onAutosave;
|
|
26
|
-
let props;
|
|
27
|
-
let resetDeps;
|
|
28
|
-
let t1;
|
|
29
|
-
let t2;
|
|
30
|
-
if ($[0] !== t0) {
|
|
31
|
-
({autosaveDelay, enableAutosave, autosaveOn: t1, normalizeAutosaveData, onAutosave, getResetValues, resetDeps, resetTimeout: t2, ...props} = t0);
|
|
32
|
-
$[0] = t0;
|
|
33
|
-
$[1] = autosaveDelay;
|
|
34
|
-
$[2] = enableAutosave;
|
|
35
|
-
$[3] = getResetValues;
|
|
36
|
-
$[4] = normalizeAutosaveData;
|
|
37
|
-
$[5] = onAutosave;
|
|
38
|
-
$[6] = props;
|
|
39
|
-
$[7] = resetDeps;
|
|
40
|
-
$[8] = t1;
|
|
41
|
-
$[9] = t2;
|
|
42
|
-
} else {
|
|
43
|
-
autosaveDelay = $[1];
|
|
44
|
-
enableAutosave = $[2];
|
|
45
|
-
getResetValues = $[3];
|
|
46
|
-
normalizeAutosaveData = $[4];
|
|
47
|
-
onAutosave = $[5];
|
|
48
|
-
props = $[6];
|
|
49
|
-
resetDeps = $[7];
|
|
50
|
-
t1 = $[8];
|
|
51
|
-
t2 = $[9];
|
|
52
|
-
}
|
|
53
|
-
const autosaveOn = t1 === void 0 ? "change" : t1;
|
|
54
|
-
const resetTimeout = t2 === void 0 ? 5e3 : t2;
|
|
55
|
-
let t3;
|
|
56
|
-
if ($[10] !== getResetValues) {
|
|
57
|
-
t3 = getResetValues();
|
|
58
|
-
$[10] = getResetValues;
|
|
59
|
-
$[11] = t3;
|
|
60
|
-
} else t3 = $[11];
|
|
61
|
-
let t4;
|
|
62
|
-
if ($[12] !== props || $[13] !== t3) {
|
|
63
|
-
t4 = {
|
|
64
|
-
...props,
|
|
65
|
-
defaultValues: t3
|
|
66
|
-
};
|
|
67
|
-
$[12] = props;
|
|
68
|
-
$[13] = t3;
|
|
69
|
-
$[14] = t4;
|
|
70
|
-
} else t4 = $[14];
|
|
71
|
-
const form = useForm(t4);
|
|
18
|
+
function useFormAutosave({ autosaveDelay, enableAutosave, onAutosave, getResetValues, resetDeps, resetTimeout = 5e3, ...props }) {
|
|
19
|
+
const form = useForm({
|
|
20
|
+
...props,
|
|
21
|
+
defaultValues: getResetValues()
|
|
22
|
+
});
|
|
72
23
|
const shouldResetFormValuesRef = useRef(false);
|
|
73
24
|
const resetFormValuesTimeoutRef = useRef(void 0);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (ObjectUtils.isFunction(resetValues)) values = await resetValues();
|
|
84
|
-
form.reset(values, keepStateOptions);
|
|
85
|
-
};
|
|
86
|
-
resetFormValues();
|
|
87
|
-
};
|
|
88
|
-
$[15] = form;
|
|
89
|
-
$[16] = getResetValues;
|
|
90
|
-
$[17] = t5;
|
|
91
|
-
} else t5 = $[17];
|
|
92
|
-
let t6;
|
|
93
|
-
if ($[18] !== resetDeps) {
|
|
94
|
-
t6 = [...resetDeps];
|
|
95
|
-
$[18] = resetDeps;
|
|
96
|
-
$[19] = t6;
|
|
97
|
-
} else t6 = $[19];
|
|
98
|
-
useEffect(t5, t6);
|
|
99
|
-
let t7;
|
|
100
|
-
if ($[20] !== resetTimeout) {
|
|
101
|
-
t7 = () => {
|
|
102
|
-
shouldResetFormValuesRef.current = true;
|
|
103
|
-
if (resetFormValuesTimeoutRef.current) clearTimeout(resetFormValuesTimeoutRef.current);
|
|
104
|
-
resetFormValuesTimeoutRef.current = setTimeout(() => {
|
|
105
|
-
if (shouldResetFormValuesRef.current) throw new Error(getResetTimeoutErrorMessage(resetTimeout));
|
|
106
|
-
}, resetTimeout);
|
|
107
|
-
};
|
|
108
|
-
$[20] = resetTimeout;
|
|
109
|
-
$[21] = t7;
|
|
110
|
-
} else t7 = $[21];
|
|
111
|
-
const onSaveSuccess = t7;
|
|
112
|
-
let t8;
|
|
113
|
-
if ($[22] !== normalizeAutosaveData || $[23] !== onAutosave) {
|
|
114
|
-
t8 = (data) => {
|
|
115
|
-
const normalizedData = normalizeAutosaveData ? normalizeAutosaveData(data) : data;
|
|
116
|
-
if (!normalizedData || ObjectUtils.isEmpty(normalizedData)) return Promise.resolve(void 0);
|
|
117
|
-
return onAutosave(normalizedData);
|
|
118
|
-
};
|
|
119
|
-
$[22] = normalizeAutosaveData;
|
|
120
|
-
$[23] = onAutosave;
|
|
121
|
-
$[24] = t8;
|
|
122
|
-
} else t8 = $[24];
|
|
123
|
-
const onSave = t8;
|
|
124
|
-
let t9;
|
|
125
|
-
if ($[25] !== autosaveDelay || $[26] !== autosaveOn || $[27] !== enableAutosave || $[28] !== form || $[29] !== onSave || $[30] !== onSaveSuccess) {
|
|
126
|
-
t9 = {
|
|
127
|
-
form,
|
|
128
|
-
delay: autosaveDelay,
|
|
129
|
-
enabled: enableAutosave,
|
|
130
|
-
trigger: autosaveOn,
|
|
131
|
-
onSave,
|
|
132
|
-
onSaveSuccess
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const resetValues = getResetValues();
|
|
27
|
+
if (resetValues === void 0) return;
|
|
28
|
+
const resetFormValues = async () => {
|
|
29
|
+
const keepStateOptions = shouldResetFormValuesRef.current ? { keepDirtyValues: true } : void 0;
|
|
30
|
+
shouldResetFormValuesRef.current = false;
|
|
31
|
+
let values = resetValues;
|
|
32
|
+
if (ObjectUtils.isFunction(resetValues)) values = await resetValues();
|
|
33
|
+
form.reset(values, keepStateOptions);
|
|
133
34
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
35
|
+
resetFormValues();
|
|
36
|
+
}, [...resetDeps]);
|
|
37
|
+
const onSaveSuccess = () => {
|
|
38
|
+
shouldResetFormValuesRef.current = true;
|
|
39
|
+
if (resetFormValuesTimeoutRef.current) clearTimeout(resetFormValuesTimeoutRef.current);
|
|
40
|
+
resetFormValuesTimeoutRef.current = setTimeout(() => {
|
|
41
|
+
if (shouldResetFormValuesRef.current) throw new Error(getResetTimeoutErrorMessage(resetTimeout));
|
|
42
|
+
}, resetTimeout);
|
|
43
|
+
};
|
|
44
|
+
useAutosave({
|
|
45
|
+
form,
|
|
46
|
+
delay: autosaveDelay,
|
|
47
|
+
enabled: enableAutosave,
|
|
48
|
+
onSave: onAutosave,
|
|
49
|
+
onSaveSuccess
|
|
50
|
+
});
|
|
143
51
|
return form;
|
|
144
52
|
}
|
|
145
53
|
//#endregion
|
|
@@ -3,6 +3,6 @@ type UseIntersectionObserverProps = {
|
|
|
3
3
|
onIntersectionChange?: (entry: IntersectionObserverEntry) => void;
|
|
4
4
|
} & IntersectionObserverInit;
|
|
5
5
|
export declare const useIntersectionObserver: <T extends HTMLElement>({ onIntersection, onIntersectionChange, root, rootMargin, threshold, }: UseIntersectionObserverProps) => {
|
|
6
|
-
ref: (
|
|
6
|
+
ref: (node: T | null) => void;
|
|
7
7
|
};
|
|
8
8
|
export {};
|
|
@@ -1,98 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
2
|
//#region src/hooks/useIntersectionObserver.ts
|
|
4
|
-
var useIntersectionObserver = (
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onIntersectionRef.current = onIntersection;
|
|
16
|
-
};
|
|
17
|
-
t2 = [onIntersection];
|
|
18
|
-
$[0] = onIntersection;
|
|
19
|
-
$[1] = t1;
|
|
20
|
-
$[2] = t2;
|
|
21
|
-
} else {
|
|
22
|
-
t1 = $[1];
|
|
23
|
-
t2 = $[2];
|
|
24
|
-
}
|
|
25
|
-
useEffect(t1, t2);
|
|
26
|
-
let t3;
|
|
27
|
-
let t4;
|
|
28
|
-
if ($[3] !== onIntersectionChange) {
|
|
29
|
-
t3 = () => {
|
|
30
|
-
onIntersectionChangeRef.current = onIntersectionChange;
|
|
31
|
-
};
|
|
32
|
-
t4 = [onIntersectionChange];
|
|
33
|
-
$[3] = onIntersectionChange;
|
|
34
|
-
$[4] = t3;
|
|
35
|
-
$[5] = t4;
|
|
36
|
-
} else {
|
|
37
|
-
t3 = $[4];
|
|
38
|
-
t4 = $[5];
|
|
39
|
-
}
|
|
40
|
-
useEffect(t3, t4);
|
|
41
|
-
let t5;
|
|
42
|
-
let t6;
|
|
43
|
-
if ($[6] !== root || $[7] !== rootMargin || $[8] !== threshold) {
|
|
44
|
-
t5 = () => {
|
|
45
|
-
const observer = new IntersectionObserver((entries) => {
|
|
46
|
-
if (entries.some(_temp)) onIntersectionRef.current?.();
|
|
47
|
-
onIntersectionChangeRef.current?.(entries[0]);
|
|
48
|
-
}, {
|
|
49
|
-
root,
|
|
50
|
-
rootMargin,
|
|
51
|
-
threshold
|
|
52
|
-
});
|
|
53
|
-
observerRef.current = observer;
|
|
54
|
-
if (elementRef.current) observer.observe(elementRef.current);
|
|
55
|
-
return () => {
|
|
56
|
-
if (elementRef.current) observer.unobserve(elementRef.current);
|
|
57
|
-
observer.disconnect();
|
|
58
|
-
observerRef.current = null;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
t6 = [
|
|
3
|
+
var useIntersectionObserver = ({ onIntersection, onIntersectionChange, root, rootMargin, threshold }) => {
|
|
4
|
+
const [element, setElement] = useState(null);
|
|
5
|
+
const ref = useCallback((node) => {
|
|
6
|
+
setElement(node);
|
|
7
|
+
}, []);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!element) return;
|
|
10
|
+
const observer = new IntersectionObserver((entries) => {
|
|
11
|
+
if (entries.some((entry) => entry.isIntersecting)) onIntersection?.();
|
|
12
|
+
onIntersectionChange?.(entries[0]);
|
|
13
|
+
}, {
|
|
62
14
|
root,
|
|
63
15
|
rootMargin,
|
|
64
16
|
threshold
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
|
|
78
|
-
t7 = (element) => {
|
|
79
|
-
if (elementRef.current === element) return;
|
|
80
|
-
if (observerRef.current && elementRef.current) observerRef.current.unobserve(elementRef.current);
|
|
81
|
-
elementRef.current = element;
|
|
82
|
-
if (observerRef.current && elementRef.current) observerRef.current.observe(elementRef.current);
|
|
83
|
-
};
|
|
84
|
-
$[11] = t7;
|
|
85
|
-
} else t7 = $[11];
|
|
86
|
-
const ref = t7;
|
|
87
|
-
let t8;
|
|
88
|
-
if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
|
|
89
|
-
t8 = { ref };
|
|
90
|
-
$[12] = t8;
|
|
91
|
-
} else t8 = $[12];
|
|
92
|
-
return t8;
|
|
17
|
+
});
|
|
18
|
+
observer.observe(element);
|
|
19
|
+
return () => observer.disconnect();
|
|
20
|
+
}, [
|
|
21
|
+
element,
|
|
22
|
+
root,
|
|
23
|
+
onIntersection,
|
|
24
|
+
onIntersectionChange,
|
|
25
|
+
rootMargin,
|
|
26
|
+
threshold
|
|
27
|
+
]);
|
|
28
|
+
return { ref };
|
|
93
29
|
};
|
|
94
|
-
function _temp(entry) {
|
|
95
|
-
return entry.isIntersecting;
|
|
96
|
-
}
|
|
97
30
|
//#endregion
|
|
98
31
|
export { useIntersectionObserver };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState } from "react";
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
3
2
|
//#region src/hooks/useLocalStorage.ts
|
|
4
3
|
var getValue = (key, schema) => {
|
|
5
4
|
if (!localStorage) return null;
|
|
@@ -15,56 +14,24 @@ var getValue = (key, schema) => {
|
|
|
15
14
|
if (parsedValue.success) return parsedValue.data;
|
|
16
15
|
else return null;
|
|
17
16
|
};
|
|
18
|
-
var useLocalStorage = (
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
t1 = () => getValue(key, schema);
|
|
24
|
-
$[0] = key;
|
|
25
|
-
$[1] = schema;
|
|
26
|
-
$[2] = t1;
|
|
27
|
-
} else t1 = $[2];
|
|
28
|
-
const [value, setValue] = useState(t1);
|
|
29
|
-
let t2;
|
|
30
|
-
if ($[3] !== key || $[4] !== schema) {
|
|
31
|
-
t2 = (newValue) => {
|
|
17
|
+
var useLocalStorage = ({ key, schema }) => {
|
|
18
|
+
const [value, setValue] = useState(() => getValue(key, schema));
|
|
19
|
+
return {
|
|
20
|
+
value,
|
|
21
|
+
set: useCallback((newValue) => {
|
|
32
22
|
if (!localStorage) return;
|
|
33
23
|
const parsedValue = schema.safeParse(newValue);
|
|
34
24
|
if (!parsedValue.success) return;
|
|
35
25
|
if (typeof parsedValue.data === "string") localStorage.setItem(key, parsedValue.data);
|
|
36
26
|
else localStorage.setItem(key, JSON.stringify(parsedValue.data));
|
|
37
27
|
setValue(parsedValue.data);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
$[4] = schema;
|
|
41
|
-
$[5] = t2;
|
|
42
|
-
} else t2 = $[5];
|
|
43
|
-
const set = t2;
|
|
44
|
-
let t3;
|
|
45
|
-
if ($[6] !== key) {
|
|
46
|
-
t3 = () => {
|
|
28
|
+
}, [key, schema]),
|
|
29
|
+
remove: useCallback(() => {
|
|
47
30
|
if (!localStorage) return;
|
|
48
31
|
localStorage.removeItem(key);
|
|
49
32
|
setValue(null);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
$[7] = t3;
|
|
53
|
-
} else t3 = $[7];
|
|
54
|
-
const remove = t3;
|
|
55
|
-
let t4;
|
|
56
|
-
if ($[8] !== remove || $[9] !== set || $[10] !== value) {
|
|
57
|
-
t4 = {
|
|
58
|
-
value,
|
|
59
|
-
set,
|
|
60
|
-
remove
|
|
61
|
-
};
|
|
62
|
-
$[8] = remove;
|
|
63
|
-
$[9] = set;
|
|
64
|
-
$[10] = value;
|
|
65
|
-
$[11] = t4;
|
|
66
|
-
} else t4 = $[11];
|
|
67
|
-
return t4;
|
|
33
|
+
}, [key])
|
|
34
|
+
};
|
|
68
35
|
};
|
|
69
36
|
//#endregion
|
|
70
37
|
export { useLocalStorage };
|