@basic-ui/core 0.0.53 → 0.0.56
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/build/cjs/index.js +278 -505
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.js +20 -29
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.js +18 -32
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.js +37 -74
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.js +19 -22
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.js +16 -13
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.js +15 -25
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +7 -7
- package/build/esm/ComboBox/Combobox.js +52 -59
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.js +23 -28
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.js +67 -70
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.js +15 -17
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.js +19 -20
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.js +41 -45
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.js +22 -21
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.js +5 -6
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +2 -2
- package/build/esm/ComboBox/hooks.js +175 -148
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.js +3 -6
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.js +26 -32
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.js +5 -7
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.js +14 -19
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.js +9 -11
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.js +9 -11
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.js +6 -6
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +4 -4
- package/build/esm/Menu/ContextMenuTrigger.js +32 -37
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
- package/build/esm/Menu/Menu.js +33 -49
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +4 -4
- package/build/esm/Menu/MenuButton.js +28 -44
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.js +29 -38
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.js +61 -116
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.js +16 -19
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +1 -1
- package/build/esm/Menu/context.js +14 -12
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.js +1 -1
- package/build/esm/Menu/fixtures/countryList.js.map +1 -1
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.js +13 -18
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.js +24 -33
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +3 -3
- package/build/esm/Popper/Popper.js +44 -61
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.js +11 -16
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.js +3 -5
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.js +9 -11
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/PortalSelectorProvider.d.ts +3 -3
- package/build/esm/Portal/PortalSelectorProvider.js +6 -4
- package/build/esm/Portal/PortalSelectorProvider.js.map +1 -1
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.js +17 -23
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.js +19 -28
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +1 -1
- package/build/esm/RadioButton/context.js +8 -6
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.js +9 -11
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +7 -7
- package/build/esm/Slider/Slider.js +340 -407
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Spinner/Spinner.js +31 -59
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.js +14 -19
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.js +8 -7
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.js +32 -50
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.js +24 -34
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.js +16 -23
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.js +15 -20
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.js +17 -33
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.js +16 -13
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +2 -2
- package/build/esm/Tooltip/Tooltip.js +20 -30
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +2 -2
- package/build/esm/Tooltip/stateMachine.js +95 -81
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +2 -2
- package/build/esm/Tooltip/useTooltip.js +38 -50
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.js +3 -3
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.js +6 -8
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.js +6 -16
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.js +8 -12
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +2 -2
- package/build/esm/hooks/useFocusState.js +9 -15
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +1 -1
- package/build/esm/hooks/useGestureHandlers.js +80 -100
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.js +7 -15
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.js +4 -6
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.js +3 -4
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +1 -1
- package/build/esm/hooks/useReducerMachine.js +15 -26
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +9 -14
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +2 -2
- package/build/esm/hooks/useScope.js +12 -14
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.js +5 -10
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.js +4 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/styles.d.js +2 -0
- package/build/esm/styles.d.js.map +1 -0
- package/build/esm/utils/assign-ref.js +3 -5
- package/build/esm/utils/assign-ref.js.map +1 -1
- package/build/esm/utils/can-use-dom.js.map +1 -1
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +1 -1
- package/build/esm/utils/context.js +13 -20
- package/build/esm/utils/context.js.map +1 -1
- package/build/esm/utils/create-subscription.js +5 -10
- package/build/esm/utils/create-subscription.js.map +1 -1
- package/build/esm/utils/get-circular-index.js +0 -1
- package/build/esm/utils/get-circular-index.js.map +1 -1
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.js.map +1 -1
- package/build/esm/utils/owner-document.js +1 -1
- package/build/esm/utils/owner-document.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +10 -10
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/esm/utils/rubber-band-clamp.js +2 -5
- package/build/esm/utils/rubber-band-clamp.js.map +1 -1
- package/build/esm/utils/use-stable-callback.js +8 -10
- package/build/esm/utils/use-stable-callback.js.map +1 -1
- package/build/esm/utils/wrap-event.d.ts +1 -1
- package/build/esm/utils/wrap-event.js +2 -5
- package/build/esm/utils/wrap-event.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/Accordion/Accordion.tsx +1 -1
- package/src/Accordion/AccordionBody.tsx +1 -1
- package/src/Accordion/AccordionHeader.tsx +1 -2
- package/src/ComboBox/Combobox.tsx +2 -2
- package/src/ComboBox/ComboboxList.tsx +1 -1
- package/src/ComboBox/ComboboxOption.tsx +0 -1
- package/src/ComboBox/hooks.tsx +0 -3
- package/src/FocusLock/useFocusLock.ts +0 -1
- package/src/Menu/Menu.tsx +2 -3
- package/src/Menu/MenuItem.tsx +1 -2
- package/src/Menu/MenuList.tsx +4 -4
- package/src/Modal/Modal.story.tsx +11 -7
- package/src/Modal/ModalBackdrop.tsx +1 -1
- package/src/Modal/NavDrawer.story.tsx +9 -6
- package/src/Popper/Popper.story.tsx +23 -7
- package/src/Popper/Popper.tsx +2 -2
- package/src/RadioButton/RadioButton.story.tsx +2 -1
- package/src/Slider/Slider.tsx +6 -11
- package/src/Spinner/Spinner.tsx +1 -1
- package/src/Tabs/TabList.tsx +1 -1
- package/src/Tooltip/Tooltip.tsx +8 -5
- package/src/Tooltip/useTooltip.ts +1 -1
- package/src/hooks/useControlledState.ts +1 -6
- package/src/hooks/useGestureHandlers.ts +0 -4
- package/src/hooks/useRemoveBodyScroll.ts +0 -1
- package/src/hooks/useScope.ts +1 -1
- package/src/styles.d.ts +1 -0
- package/src/utils/polymorphic.ts +14 -10
- package/src/utils/use-stable-callback.ts +0 -1
- package/build/esm/Carousel/Carousel.d.ts +0 -9
- package/build/esm/Carousel/Carousel.js +0 -38
- package/build/esm/Carousel/Carousel.js.map +0 -1
- package/build/esm/Carousel/Fader.d.ts +0 -14
- package/build/esm/Carousel/Fader.js +0 -76
- package/build/esm/Carousel/Fader.js.map +0 -1
- package/build/esm/Carousel/FaderItem.d.ts +0 -5
- package/build/esm/Carousel/FaderItem.js +0 -16
- package/build/esm/Carousel/FaderItem.js.map +0 -1
- package/build/esm/Carousel/Preloader.d.ts +0 -7
- package/build/esm/Carousel/Preloader.js +0 -70
- package/build/esm/Carousel/Preloader.js.map +0 -1
- package/build/esm/Carousel/Slider.d.ts +0 -14
- package/build/esm/Carousel/Slider.js +0 -212
- package/build/esm/Carousel/Slider.js.map +0 -1
- package/build/esm/Carousel/SliderItem.d.ts +0 -12
- package/build/esm/Carousel/SliderItem.js +0 -41
- package/build/esm/Carousel/SliderItem.js.map +0 -1
- package/build/esm/Carousel/context.d.ts +0 -10
- package/build/esm/Carousel/context.js +0 -8
- package/build/esm/Carousel/context.js.map +0 -1
- package/build/esm/Carousel/getSliderParams.d.ts +0 -9
- package/build/esm/Carousel/getSliderParams.js +0 -85
- package/build/esm/Carousel/getSliderParams.js.map +0 -1
- package/build/esm/Carousel/index.d.ts +0 -7
- package/build/esm/Carousel/index.js +0 -8
- package/build/esm/Carousel/index.js.map +0 -1
- package/build/esm/Carousel/useCarouselGestures.d.ts +0 -30
- package/build/esm/Carousel/useCarouselGestures.js +0 -33
- package/build/esm/Carousel/useCarouselGestures.js.map +0 -1
- package/build/esm/DatePicker/DatePicker.d.ts +0 -24
- package/build/esm/DatePicker/DatePicker.js +0 -101
- package/build/esm/DatePicker/DatePicker.js.map +0 -1
- package/build/esm/DatePicker/DatePickerSelect.d.ts +0 -8
- package/build/esm/DatePicker/DatePickerSelect.js +0 -201
- package/build/esm/DatePicker/DatePickerSelect.js.map +0 -1
- package/build/esm/DatePicker/RangeDatePicker.d.ts +0 -28
- package/build/esm/DatePicker/RangeDatePicker.js +0 -94
- package/build/esm/DatePicker/RangeDatePicker.js.map +0 -1
- package/build/esm/DatePicker/adjustDates.d.ts +0 -4
- package/build/esm/DatePicker/adjustDates.js +0 -18
- package/build/esm/DatePicker/adjustDates.js.map +0 -1
- package/build/esm/DatePicker/contexts.d.ts +0 -31
- package/build/esm/DatePicker/contexts.js +0 -15
- package/build/esm/DatePicker/contexts.js.map +0 -1
- package/build/esm/DatePicker/dateTypes.d.ts +0 -2
- package/build/esm/DatePicker/dateTypes.js +0 -2
- package/build/esm/DatePicker/dateTypes.js.map +0 -1
- package/build/esm/DatePicker/hooks.d.ts +0 -36
- package/build/esm/DatePicker/hooks.js +0 -98
- package/build/esm/DatePicker/hooks.js.map +0 -1
- package/build/esm/DatePicker/index.d.ts +0 -5
- package/build/esm/DatePicker/index.js +0 -6
- package/build/esm/DatePicker/index.js.map +0 -1
- package/build/esm/hooks/useId.d.ts +0 -1
- package/build/esm/hooks/useId.js +0 -25
- package/build/esm/hooks/useId.js.map +0 -1
- package/build/esm/utils/assignRef.d.ts +0 -3
- package/build/esm/utils/assignRef.js +0 -25
- package/build/esm/utils/assignRef.js.map +0 -1
- package/build/esm/utils/getCircularIndex.d.ts +0 -1
- package/build/esm/utils/getCircularIndex.js +0 -8
- package/build/esm/utils/getCircularIndex.js.map +0 -1
- package/build/esm/utils/rubberBandClamp.d.ts +0 -2
- package/build/esm/utils/rubberBandClamp.js +0 -20
- package/build/esm/utils/rubberBandClamp.js.map +0 -1
- package/build/esm/utils/wrapEvent.d.ts +0 -3
- package/build/esm/utils/wrapEvent.js +0 -16
- package/build/esm/utils/wrapEvent.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -7270
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { focusOnChildNode } from '../FocusLock/tabUtils';
|
|
3
3
|
export function useAutoFocus(open, elementRef) {
|
|
4
|
-
useEffect(
|
|
4
|
+
useEffect(() => {
|
|
5
5
|
if (open) {
|
|
6
6
|
// We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal
|
|
7
7
|
if (elementRef.current && !elementRef.current.contains(document.activeElement)) {
|
|
8
8
|
focusOnChildNode(elementRef.current, 0);
|
|
9
9
|
}
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12
12
|
}, [open]);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=useAutoFocus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoFocus.js","names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"sources":["../../../src/hooks/useAutoFocus.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nimport { focusOnChildNode } from '../FocusLock/tabUtils';\n\nexport function useAutoFocus(\n open: boolean,\n elementRef: MutableRefObject<HTMLElement | null>\n) {\n useEffect(() => {\n if (open) {\n // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal\n if (\n elementRef.current &&\n !elementRef.current.contains(document.activeElement)\n ) {\n focusOnChildNode(elementRef.current, 0);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n}\n"],"mappings":"AACA,SAASA,
|
|
1
|
+
{"version":3,"file":"useAutoFocus.js","names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"sources":["../../../src/hooks/useAutoFocus.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nimport { focusOnChildNode } from '../FocusLock/tabUtils';\n\nexport function useAutoFocus(\n open: boolean,\n elementRef: MutableRefObject<HTMLElement | null>\n) {\n useEffect(() => {\n if (open) {\n // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal\n if (\n elementRef.current &&\n !elementRef.current.contains(document.activeElement)\n ) {\n focusOnChildNode(elementRef.current, 0);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n}\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAO,SAASC,YAAYA,CAC1BC,IAAa,EACbC,UAAgD,EAChD;EACAJ,SAAS,CAAC,MAAM;IACd,IAAIG,IAAI,EAAE;MACR;MACA,IACEC,UAAU,CAACC,OAAO,IAClB,CAACD,UAAU,CAACC,OAAO,CAACC,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC,EACpD;QACAP,gBAAgB,CAACG,UAAU,CAACC,OAAO,EAAE,CAAC,CAAC;MACzC;IACF;IACA;EACF,CAAC,EAAE,CAACF,IAAI,CAAC,CAAC;AACZ","ignoreList":[]}
|
|
@@ -6,32 +6,30 @@ export function useChildrenCounterParent(itemsRef) {
|
|
|
6
6
|
// the array
|
|
7
7
|
itemsRef.current = [];
|
|
8
8
|
itemsRef.current.isNewRender = true;
|
|
9
|
-
useEffect(
|
|
9
|
+
useEffect(() => {
|
|
10
10
|
// Rendering is finished. Meaning any children can now rerender,
|
|
11
11
|
// and they should not push any new items to our array, because
|
|
12
12
|
// it is not a new render
|
|
13
13
|
itemsRef.current.isNewRender = false;
|
|
14
14
|
});
|
|
15
|
-
useEffect(
|
|
15
|
+
useEffect(() => {
|
|
16
16
|
// When we are unmounting, it means there are no children anymore.
|
|
17
17
|
// Clear out our items array
|
|
18
|
-
return
|
|
18
|
+
return () => {
|
|
19
19
|
itemsRef.current = [];
|
|
20
20
|
};
|
|
21
21
|
}, [itemsRef]);
|
|
22
22
|
}
|
|
23
23
|
export function useChildrenCounterChild(itemsRef, itemIndexRef, obj) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let disabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
26
25
|
if (itemsRef && itemsRef.current.isNewRender) {
|
|
27
26
|
if (disabled) {
|
|
28
27
|
itemIndexRef.current = -1;
|
|
29
28
|
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
29
|
+
}
|
|
32
30
|
|
|
31
|
+
// push this option to the optionsRef array
|
|
33
32
|
itemIndexRef.current = itemsRef.current.length;
|
|
34
|
-
|
|
35
33
|
if (obj instanceof Function) {
|
|
36
34
|
itemsRef.current.push(obj(itemIndexRef.current));
|
|
37
35
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChildrenCounter.js","names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","length","Function","push"],"sources":["../../../src/hooks/useChildrenCounter.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nexport function useChildrenCounterParent<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>\n) {\n // Reset the options ref every render so that they are always\n // accurate and ready for keyboard navigation handlers. Using layout\n // effect to schedule this effect before the ComboboxOptions push into\n // the array\n itemsRef.current = [];\n itemsRef.current.isNewRender = true;\n\n useEffect(() => {\n // Rendering is finished. Meaning any children can now rerender,\n // and they should not push any new items to our array, because\n // it is not a new render\n itemsRef.current.isNewRender = false;\n });\n\n useEffect(() => {\n // When we are unmounting, it means there are no children anymore.\n // Clear out our items array\n return () => {\n itemsRef.current = [];\n };\n }, [itemsRef]);\n}\n\nexport function useChildrenCounterChild<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,\n itemIndexRef: MutableRefObject<number>,\n obj: T | ((idx: number) => T),\n disabled = false\n) {\n if (itemsRef && itemsRef.current.isNewRender) {\n if (disabled) {\n itemIndexRef.current = -1;\n return;\n }\n\n // push this option to the optionsRef array\n itemIndexRef.current = itemsRef.current.length;\n\n if (obj instanceof Function) {\n itemsRef.current.push(obj(itemIndexRef.current));\n } else {\n itemsRef.current.push(obj);\n }\n }\n}\n"],"mappings":"AACA,SAASA,
|
|
1
|
+
{"version":3,"file":"useChildrenCounter.js","names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","arguments","length","undefined","Function","push"],"sources":["../../../src/hooks/useChildrenCounter.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nexport function useChildrenCounterParent<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>\n) {\n // Reset the options ref every render so that they are always\n // accurate and ready for keyboard navigation handlers. Using layout\n // effect to schedule this effect before the ComboboxOptions push into\n // the array\n itemsRef.current = [];\n itemsRef.current.isNewRender = true;\n\n useEffect(() => {\n // Rendering is finished. Meaning any children can now rerender,\n // and they should not push any new items to our array, because\n // it is not a new render\n itemsRef.current.isNewRender = false;\n });\n\n useEffect(() => {\n // When we are unmounting, it means there are no children anymore.\n // Clear out our items array\n return () => {\n itemsRef.current = [];\n };\n }, [itemsRef]);\n}\n\nexport function useChildrenCounterChild<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,\n itemIndexRef: MutableRefObject<number>,\n obj: T | ((idx: number) => T),\n disabled = false\n) {\n if (itemsRef && itemsRef.current.isNewRender) {\n if (disabled) {\n itemIndexRef.current = -1;\n return;\n }\n\n // push this option to the optionsRef array\n itemIndexRef.current = itemsRef.current.length;\n\n if (obj instanceof Function) {\n itemsRef.current.push(obj(itemIndexRef.current));\n } else {\n itemsRef.current.push(obj);\n }\n }\n}\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,OAAO;AAEjC,OAAO,SAASC,wBAAwBA,CACtCC,QAA2D,EAC3D;EACA;EACA;EACA;EACA;EACAA,QAAQ,CAACC,OAAO,GAAG,EAAE;EACrBD,QAAQ,CAACC,OAAO,CAACC,WAAW,GAAG,IAAI;EAEnCJ,SAAS,CAAC,MAAM;IACd;IACA;IACA;IACAE,QAAQ,CAACC,OAAO,CAACC,WAAW,GAAG,KAAK;EACtC,CAAC,CAAC;EAEFJ,SAAS,CAAC,MAAM;IACd;IACA;IACA,OAAO,MAAM;MACXE,QAAQ,CAACC,OAAO,GAAG,EAAE;IACvB,CAAC;EACH,CAAC,EAAE,CAACD,QAAQ,CAAC,CAAC;AAChB;AAEA,OAAO,SAASG,uBAAuBA,CACrCH,QAAuE,EACvEI,YAAsC,EACtCC,GAA6B,EAE7B;EAAA,IADAC,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAEhB,IAAIP,QAAQ,IAAIA,QAAQ,CAACC,OAAO,CAACC,WAAW,EAAE;IAC5C,IAAII,QAAQ,EAAE;MACZF,YAAY,CAACH,OAAO,GAAG,CAAC,CAAC;MACzB;IACF;;IAEA;IACAG,YAAY,CAACH,OAAO,GAAGD,QAAQ,CAACC,OAAO,CAACO,MAAM;IAE9C,IAAIH,GAAG,YAAYK,QAAQ,EAAE;MAC3BV,QAAQ,CAACC,OAAO,CAACU,IAAI,CAACN,GAAG,CAACD,YAAY,CAACH,OAAO,CAAC,CAAC;IAClD,CAAC,MAAM;MACLD,QAAQ,CAACC,OAAO,CAACU,IAAI,CAACN,GAAG,CAAC;IAC5B;EACF;AACF","ignoreList":[]}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import { useRef, useState } from 'react';
|
|
3
2
|
import { wrapEvent } from '../utils';
|
|
4
3
|
export function useControlledState(valueProp, onChangeProp, defaultValue, defaultOnChange) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _useState = useState(defaultValue),
|
|
10
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
-
valueState = _useState2[0],
|
|
12
|
-
setValueState = _useState2[1];
|
|
13
|
-
|
|
4
|
+
const isControlled = valueProp !== undefined;
|
|
5
|
+
const wasControlled = useRef(isControlled);
|
|
6
|
+
const hasWarned = useRef(false);
|
|
7
|
+
const [valueState, setValueState] = useState(defaultValue);
|
|
14
8
|
if (isControlled) {
|
|
15
9
|
if (!wasControlled.current && !hasWarned.current && process.env.NODE_ENV !== 'production') {
|
|
16
10
|
console.warn('Trying to change from controlled to uncontrolled.');
|
|
17
11
|
hasWarned.current = true;
|
|
18
12
|
}
|
|
19
|
-
|
|
20
|
-
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
21
|
-
valueProp, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
13
|
+
return [valueProp, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
22
14
|
}
|
|
23
|
-
|
|
24
|
-
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
|
-
valueState, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
15
|
+
return [valueState, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
26
16
|
}
|
|
27
17
|
//# sourceMappingURL=useControlledState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n !wasControlled.current &&\n !hasWarned.current &&\n process.env.NODE_ENV !== 'production'\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n
|
|
1
|
+
{"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n !wasControlled.current &&\n !hasWarned.current &&\n process.env.NODE_ENV !== 'production'\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [valueState!, wrapEvent(onChangeProp, defaultOnChange(setValueState))];\n}\n"],"mappings":"AACA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGxC,SAASC,SAAS,QAAQ,UAAU;AAEpC,OAAO,SAASC,kBAAkBA,CAKhCC,SAAwB,EACxBC,YAAkD,EAClDC,YAA2B,EAC3BC,eAE6B,EACE;EAC/B,MAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAS;EAC5C,MAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAY,CAAC;EAC1C,MAAMG,SAAS,GAAGX,MAAM,CAAC,KAAK,CAAC;EAC/B,MAAM,CAACY,UAAU,EAAEC,aAAa,CAAC,GAAGZ,QAAQ,CAAIK,YAAY,CAAC;EAE7D,IAAIE,YAAY,EAAE;IAChB,IACE,CAACE,aAAa,CAACI,OAAO,IACtB,CAACH,SAAS,CAACG,OAAO,IAClBC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EACrC;MACAC,OAAO,CAACC,IAAI,CAAC,mDAAmD,CAAC;MACjER,SAAS,CAACG,OAAO,GAAG,IAAI;IAC1B;IACA,OAAO,CACLV,SAAS,EACTF,SAAS,CAACG,YAAY,EAAEE,eAAe,CAACM,aAAa,CAAC,CAAC,CACxD;EACH;EAEA,OAAO,CAACD,UAAU,EAAGV,SAAS,CAACG,YAAY,EAAEE,eAAe,CAACM,aAAa,CAAC,CAAC,CAAC;AAC/E","ignoreList":[]}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
export function useFocusReturn(open, rootEl) {
|
|
3
|
-
|
|
3
|
+
const previousFocusRef = useRef((() => {
|
|
4
4
|
if (open && typeof document !== 'undefined' && document.activeElement instanceof HTMLElement) {
|
|
5
5
|
return document.activeElement;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
7
|
return null;
|
|
9
|
-
}());
|
|
10
|
-
useEffect(
|
|
8
|
+
})());
|
|
9
|
+
useEffect(() => {
|
|
11
10
|
if (open) {
|
|
12
|
-
var _rootEl$current;
|
|
13
|
-
|
|
14
11
|
// once opened, keep track of the element that triggered
|
|
15
12
|
// the Modal opening
|
|
16
|
-
if (!previousFocusRef.current && document.activeElement instanceof HTMLElement && !
|
|
13
|
+
if (!previousFocusRef.current && document.activeElement instanceof HTMLElement && !rootEl.current?.contains(document.activeElement)) {
|
|
17
14
|
previousFocusRef.current = document.activeElement;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return function () {
|
|
16
|
+
const rootElement = rootEl.current;
|
|
17
|
+
const previousElement = previousFocusRef.current;
|
|
18
|
+
return () => {
|
|
23
19
|
// on unmount, return focus to that element
|
|
24
|
-
if (previousElement && !
|
|
20
|
+
if (previousElement && !rootElement?.contains(document.activeElement)) {
|
|
25
21
|
previousElement.focus({
|
|
26
22
|
preventScroll: true
|
|
27
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusReturn.js","names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"sources":["../../../src/hooks/useFocusReturn.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport function useFocusReturn(\n open: boolean,\n rootEl: MutableRefObject<HTMLElement | null>\n) {\n const previousFocusRef = useRef<HTMLElement | null>(\n (() => {\n if (\n open &&\n typeof document !== 'undefined' &&\n document.activeElement instanceof HTMLElement\n ) {\n return document.activeElement;\n }\n return null;\n })()\n );\n\n useEffect(() => {\n if (open) {\n // once opened, keep track of the element that triggered\n // the Modal opening\n if (\n !previousFocusRef.current &&\n document.activeElement instanceof HTMLElement &&\n !rootEl.current?.contains(document.activeElement)\n ) {\n previousFocusRef.current = document.activeElement;\n }\n\n const rootElement = rootEl.current;\n const previousElement = previousFocusRef.current;\n return () => {\n // on unmount, return focus to that element\n if (previousElement && !rootElement?.contains(document.activeElement)) {\n previousElement.focus({ preventScroll: true });\n }\n };\n }\n }, [open, rootEl]);\n}\n"],"mappings":"AACA,SAASA,
|
|
1
|
+
{"version":3,"file":"useFocusReturn.js","names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"sources":["../../../src/hooks/useFocusReturn.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport function useFocusReturn(\n open: boolean,\n rootEl: MutableRefObject<HTMLElement | null>\n) {\n const previousFocusRef = useRef<HTMLElement | null>(\n (() => {\n if (\n open &&\n typeof document !== 'undefined' &&\n document.activeElement instanceof HTMLElement\n ) {\n return document.activeElement;\n }\n return null;\n })()\n );\n\n useEffect(() => {\n if (open) {\n // once opened, keep track of the element that triggered\n // the Modal opening\n if (\n !previousFocusRef.current &&\n document.activeElement instanceof HTMLElement &&\n !rootEl.current?.contains(document.activeElement)\n ) {\n previousFocusRef.current = document.activeElement;\n }\n\n const rootElement = rootEl.current;\n const previousElement = previousFocusRef.current;\n return () => {\n // on unmount, return focus to that element\n if (previousElement && !rootElement?.contains(document.activeElement)) {\n previousElement.focus({ preventScroll: true });\n }\n };\n }\n }, [open, rootEl]);\n}\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEzC,OAAO,SAASC,cAAcA,CAC5BC,IAAa,EACbC,MAA4C,EAC5C;EACA,MAAMC,gBAAgB,GAAGJ,MAAM,CAC7B,CAAC,MAAM;IACL,IACEE,IAAI,IACJ,OAAOG,QAAQ,KAAK,WAAW,IAC/BA,QAAQ,CAACC,aAAa,YAAYC,WAAW,EAC7C;MACA,OAAOF,QAAQ,CAACC,aAAa;IAC/B;IACA,OAAO,IAAI;EACb,CAAC,EAAE,CACL,CAAC;EAEDP,SAAS,CAAC,MAAM;IACd,IAAIG,IAAI,EAAE;MACR;MACA;MACA,IACE,CAACE,gBAAgB,CAACI,OAAO,IACzBH,QAAQ,CAACC,aAAa,YAAYC,WAAW,IAC7C,CAACJ,MAAM,CAACK,OAAO,EAAEC,QAAQ,CAACJ,QAAQ,CAACC,aAAa,CAAC,EACjD;QACAF,gBAAgB,CAACI,OAAO,GAAGH,QAAQ,CAACC,aAAa;MACnD;MAEA,MAAMI,WAAW,GAAGP,MAAM,CAACK,OAAO;MAClC,MAAMG,eAAe,GAAGP,gBAAgB,CAACI,OAAO;MAChD,OAAO,MAAM;QACX;QACA,IAAIG,eAAe,IAAI,CAACD,WAAW,EAAED,QAAQ,CAACJ,QAAQ,CAACC,aAAa,CAAC,EAAE;UACrEK,eAAe,CAACC,KAAK,CAAC;YAAEC,aAAa,EAAE;UAAK,CAAC,CAAC;QAChD;MACF,CAAC;IACH;EACF,CAAC,EAAE,CAACX,IAAI,EAAEC,MAAM,CAAC,CAAC;AACpB","ignoreList":[]}
|
|
@@ -4,8 +4,8 @@ export declare function useFocusState<T>(props?: {
|
|
|
4
4
|
onBlur?: FocusEventHandler<T>;
|
|
5
5
|
}): {
|
|
6
6
|
bind: {
|
|
7
|
-
onFocus: import("
|
|
8
|
-
onBlur: import("
|
|
7
|
+
onFocus: import("..").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
|
|
8
|
+
onBlur: import("..").CustomEventHandler<import("react").FocusEvent<T, Element>, []>;
|
|
9
9
|
};
|
|
10
10
|
hasFocus: boolean;
|
|
11
11
|
};
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import { useState } from 'react';
|
|
3
2
|
import { wrapEvent } from '../utils/wrap-event';
|
|
4
3
|
export function useFocusState() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
setHasFocus = _useState2[1];
|
|
13
|
-
|
|
14
|
-
var handleFocus = function handleFocus() {
|
|
4
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
const {
|
|
6
|
+
onFocus,
|
|
7
|
+
onBlur
|
|
8
|
+
} = props;
|
|
9
|
+
const [hasFocus, setHasFocus] = useState(false);
|
|
10
|
+
const handleFocus = () => {
|
|
15
11
|
setHasFocus(true);
|
|
16
12
|
};
|
|
17
|
-
|
|
18
|
-
var handleBlur = function handleBlur() {
|
|
13
|
+
const handleBlur = () => {
|
|
19
14
|
setHasFocus(false);
|
|
20
15
|
};
|
|
21
|
-
|
|
22
16
|
return {
|
|
23
17
|
bind: {
|
|
24
18
|
onFocus: wrapEvent(onFocus, handleFocus),
|
|
25
19
|
onBlur: wrapEvent(onBlur, handleBlur)
|
|
26
20
|
},
|
|
27
|
-
hasFocus
|
|
21
|
+
hasFocus
|
|
28
22
|
};
|
|
29
23
|
}
|
|
30
24
|
//# sourceMappingURL=useFocusState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusState.js","names":["useState","wrapEvent","useFocusState","props","onFocus","onBlur","hasFocus","setHasFocus","handleFocus","handleBlur","bind"],"sources":["../../../src/hooks/useFocusState.ts"],"sourcesContent":["import type { FocusEventHandler } from 'react';\nimport { useState } from 'react';\n\nimport { wrapEvent } from '../utils/wrap-event';\n\nexport function useFocusState<T>(\n props: {\n onFocus?: FocusEventHandler<T>;\n onBlur?: FocusEventHandler<T>;\n } = {}\n) {\n const { onFocus, onBlur } = props;\n const [hasFocus, setHasFocus] = useState(false);\n\n const handleFocus = () => {\n setHasFocus(true);\n };\n\n const handleBlur = () => {\n setHasFocus(false);\n };\n\n return {\n bind: {\n onFocus: wrapEvent(onFocus, handleFocus),\n onBlur: wrapEvent(onBlur, handleBlur),\n },\n hasFocus,\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFocusState.js","names":["useState","wrapEvent","useFocusState","props","arguments","length","undefined","onFocus","onBlur","hasFocus","setHasFocus","handleFocus","handleBlur","bind"],"sources":["../../../src/hooks/useFocusState.ts"],"sourcesContent":["import type { FocusEventHandler } from 'react';\nimport { useState } from 'react';\n\nimport { wrapEvent } from '../utils/wrap-event';\n\nexport function useFocusState<T>(\n props: {\n onFocus?: FocusEventHandler<T>;\n onBlur?: FocusEventHandler<T>;\n } = {}\n) {\n const { onFocus, onBlur } = props;\n const [hasFocus, setHasFocus] = useState(false);\n\n const handleFocus = () => {\n setHasFocus(true);\n };\n\n const handleBlur = () => {\n setHasFocus(false);\n };\n\n return {\n bind: {\n onFocus: wrapEvent(onFocus, handleFocus),\n onBlur: wrapEvent(onBlur, handleBlur),\n },\n hasFocus,\n };\n}\n"],"mappings":"AACA,SAASA,QAAQ,QAAQ,OAAO;AAEhC,SAASC,SAAS,QAAQ,qBAAqB;AAE/C,OAAO,SAASC,aAAaA,CAAA,EAK3B;EAAA,IAJAC,KAGC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEN,MAAM;IAAEG,OAAO;IAAEC;EAAO,CAAC,GAAGL,KAAK;EACjC,MAAM,CAACM,QAAQ,EAAEC,WAAW,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC;EAE/C,MAAMW,WAAW,GAAGA,CAAA,KAAM;IACxBD,WAAW,CAAC,IAAI,CAAC;EACnB,CAAC;EAED,MAAME,UAAU,GAAGA,CAAA,KAAM;IACvBF,WAAW,CAAC,KAAK,CAAC;EACpB,CAAC;EAED,OAAO;IACLG,IAAI,EAAE;MACJN,OAAO,EAAEN,SAAS,CAACM,OAAO,EAAEI,WAAW,CAAC;MACxCH,MAAM,EAAEP,SAAS,CAACO,MAAM,EAAEI,UAAU;IACtC,CAAC;IACDH;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -17,7 +17,7 @@ export interface GestureHandlersState {
|
|
|
17
17
|
down: boolean;
|
|
18
18
|
scrollLocked: boolean;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
type SetStateFunc<S> = (state: (prevState: Readonly<S>) => S, callback?: () => void) => void;
|
|
21
21
|
export interface GestureHandlersReturn {
|
|
22
22
|
onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;
|
|
23
23
|
onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import { useRef } from 'react';
|
|
3
2
|
import { getOwnerDocument } from '../utils';
|
|
4
|
-
export
|
|
3
|
+
export const initialGestureHandlersState = {
|
|
5
4
|
target: null,
|
|
6
5
|
x: 0,
|
|
7
6
|
xDelta: 0,
|
|
@@ -19,42 +18,43 @@ export var initialGestureHandlersState = {
|
|
|
19
18
|
down: false,
|
|
20
19
|
scrollLocked: false
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;
|
|
21
|
+
const FRAMERATE_CONST = 1000 / 60; // 60 fps
|
|
22
|
+
const VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;
|
|
25
23
|
export function gestureHandlers(set, containerRef) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25
|
+
const {
|
|
26
|
+
ensureTargetIsContainer = false,
|
|
27
|
+
minTouchDelta = 0
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
// Common handlers
|
|
31
|
+
const handleUp = () => {
|
|
32
|
+
set(state => {
|
|
33
|
+
const deltaTime = Date.now() - state.startTime;
|
|
34
|
+
const xDelta = state.x - state.xInitial;
|
|
35
|
+
const yDelta = state.y - state.yInitial;
|
|
36
|
+
const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);
|
|
37
|
+
const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);
|
|
38
|
+
const newState = {
|
|
39
|
+
...state,
|
|
40
|
+
xVelocity,
|
|
41
|
+
yVelocity,
|
|
43
42
|
target: null,
|
|
44
43
|
down: false
|
|
45
|
-
}
|
|
46
|
-
|
|
44
|
+
};
|
|
47
45
|
return newState;
|
|
48
46
|
});
|
|
49
47
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
const handleDown = e => {
|
|
49
|
+
const {
|
|
50
|
+
target,
|
|
51
|
+
pageX,
|
|
52
|
+
pageY
|
|
53
|
+
} = e;
|
|
54
|
+
set(state => {
|
|
55
|
+
const newState = {
|
|
56
|
+
...state,
|
|
57
|
+
target,
|
|
58
58
|
x: pageX,
|
|
59
59
|
xDelta: 0,
|
|
60
60
|
xDeltaPercent: 0,
|
|
@@ -70,96 +70,84 @@ export function gestureHandlers(set, containerRef) {
|
|
|
70
70
|
startTime: Date.now(),
|
|
71
71
|
down: true,
|
|
72
72
|
scrollLocked: false
|
|
73
|
-
}
|
|
74
|
-
|
|
73
|
+
};
|
|
75
74
|
return newState;
|
|
76
75
|
});
|
|
77
76
|
};
|
|
78
|
-
|
|
79
77
|
function calcVelocity(deltaSpace, deltaTime, prevVelocity) {
|
|
80
78
|
if (deltaTime < 1) {
|
|
81
79
|
deltaTime = 1;
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var depr = 0.5 + Math.min(deltaTime / VELOCITY_DEPR_FACTOR, 0.5);
|
|
81
|
+
const speed = deltaSpace / deltaTime;
|
|
82
|
+
const depr = 0.5 + Math.min(deltaTime / VELOCITY_DEPR_FACTOR, 0.5);
|
|
86
83
|
return speed * depr + prevVelocity * (1 - depr);
|
|
87
84
|
}
|
|
88
|
-
|
|
89
85
|
function handleMove(e) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const {
|
|
87
|
+
pageX,
|
|
88
|
+
pageY
|
|
89
|
+
} = e;
|
|
93
90
|
if (e.cancelable) {
|
|
94
91
|
// prevent drag & drop behaviour from browser
|
|
95
92
|
e.preventDefault && e.preventDefault();
|
|
96
93
|
}
|
|
97
|
-
|
|
98
|
-
set(function (state) {
|
|
94
|
+
set(state => {
|
|
99
95
|
function getDeltaSum(currentPos, initialPos, prevPos) {
|
|
100
96
|
if (state.scrollLocked || Math.abs(currentPos - initialPos) >= minTouchDelta) {
|
|
101
97
|
state.scrollLocked = true;
|
|
102
98
|
return currentPos - prevPos;
|
|
103
99
|
}
|
|
104
|
-
|
|
105
100
|
return 0;
|
|
106
101
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
xDeltaPercent: xDeltaPercent,
|
|
102
|
+
const target = containerRef && containerRef.current || e.target;
|
|
103
|
+
const deltaTime = Date.now() - state.startTime;
|
|
104
|
+
const width = target ? target.offsetWidth : NaN;
|
|
105
|
+
const xDelta = state.xDelta + getDeltaSum(pageX, state.xInitial, state.x);
|
|
106
|
+
const xDeltaPercent = xDelta * 100 / width;
|
|
107
|
+
const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);
|
|
108
|
+
const height = target ? target.offsetHeight : NaN;
|
|
109
|
+
const yDelta = state.yDelta + getDeltaSum(pageY, state.yInitial, state.y);
|
|
110
|
+
const yDeltaPercent = yDelta * 100 / height;
|
|
111
|
+
const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);
|
|
112
|
+
const newState = {
|
|
113
|
+
...state,
|
|
114
|
+
xDelta,
|
|
115
|
+
xDeltaPercent,
|
|
122
116
|
x: pageX,
|
|
123
117
|
xPrev: state.x,
|
|
124
|
-
xVelocity
|
|
125
|
-
yDelta
|
|
126
|
-
yDeltaPercent
|
|
118
|
+
xVelocity,
|
|
119
|
+
yDelta,
|
|
120
|
+
yDeltaPercent,
|
|
127
121
|
y: pageY,
|
|
128
122
|
yPrev: state.y,
|
|
129
|
-
yVelocity
|
|
130
|
-
}
|
|
131
|
-
|
|
123
|
+
yVelocity
|
|
124
|
+
};
|
|
132
125
|
return newState;
|
|
133
126
|
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
127
|
+
}
|
|
137
128
|
|
|
129
|
+
// Touch handlers
|
|
138
130
|
|
|
139
131
|
function handleTouchMove(e) {
|
|
140
132
|
if (e.cancelable) {
|
|
141
133
|
// prevent drag & drop behaviour from browser
|
|
142
134
|
e.preventDefault();
|
|
143
135
|
}
|
|
144
|
-
|
|
145
136
|
handleMove(e.touches.item(0));
|
|
146
137
|
}
|
|
147
|
-
|
|
148
138
|
function handleTouchStart(e) {
|
|
149
139
|
// making sure we're not dragging the element when more than one finger press the screen
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
const {
|
|
141
|
+
touches
|
|
142
|
+
} = e;
|
|
152
143
|
if (touches.length > 1) {
|
|
153
144
|
return;
|
|
154
145
|
}
|
|
155
|
-
|
|
156
146
|
if (ensureTargetIsContainer && containerRef && e.target !== containerRef.current) {
|
|
157
147
|
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var ownerDocument = getOwnerDocument(e.currentTarget);
|
|
162
|
-
var ownerWindow = ownerDocument.defaultView || window;
|
|
148
|
+
}
|
|
149
|
+
const ownerDocument = getOwnerDocument(e.currentTarget);
|
|
150
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
163
151
|
ownerWindow.addEventListener('touchmove', handleTouchMove, {
|
|
164
152
|
passive: false
|
|
165
153
|
});
|
|
@@ -167,58 +155,50 @@ export function gestureHandlers(set, containerRef) {
|
|
|
167
155
|
ownerWindow.addEventListener('touchcancel', handleTouchEnd);
|
|
168
156
|
handleDown(e.touches.item(0));
|
|
169
157
|
}
|
|
170
|
-
|
|
171
158
|
function handleTouchEnd() {
|
|
172
159
|
this.removeEventListener('touchmove', handleTouchMove);
|
|
173
160
|
this.removeEventListener('touchend', handleTouchEnd);
|
|
174
161
|
this.removeEventListener('touchcancel', handleTouchEnd);
|
|
175
162
|
handleUp();
|
|
176
|
-
}
|
|
177
|
-
|
|
163
|
+
}
|
|
178
164
|
|
|
165
|
+
// Mouse handlers
|
|
179
166
|
function handleMouseDown(e) {
|
|
180
167
|
if (ensureTargetIsContainer && containerRef && e.target !== containerRef.current) {
|
|
181
168
|
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var ownerDocument = getOwnerDocument(e.currentTarget);
|
|
186
|
-
var ownerWindow = ownerDocument.defaultView || window;
|
|
187
|
-
|
|
169
|
+
}
|
|
170
|
+
const ownerDocument = getOwnerDocument(e.currentTarget);
|
|
171
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
188
172
|
if (e.button === 0) {
|
|
189
173
|
ownerWindow.addEventListener('mousemove', handleMove);
|
|
190
174
|
ownerWindow.addEventListener('mouseup', handleMouseUp);
|
|
191
175
|
handleDown(e);
|
|
192
176
|
}
|
|
193
177
|
}
|
|
194
|
-
|
|
195
178
|
function handleMouseUp() {
|
|
196
179
|
this.removeEventListener('mousemove', handleMove);
|
|
197
180
|
this.removeEventListener('mouseup', handleMouseUp);
|
|
198
181
|
handleUp();
|
|
199
182
|
}
|
|
200
|
-
/* eslint-enable @typescript-eslint/no-use-before-define */
|
|
201
|
-
|
|
202
|
-
|
|
203
183
|
return {
|
|
204
184
|
onMouseDown: handleMouseDown,
|
|
205
185
|
onTouchStart: handleTouchStart
|
|
206
186
|
};
|
|
207
187
|
}
|
|
208
|
-
export
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
188
|
+
export const useGestureHandlers = function (containerRef, onGesture) {
|
|
189
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
190
|
+
const state = useRef({
|
|
191
|
+
...initialGestureHandlersState
|
|
192
|
+
});
|
|
193
|
+
const set = cb => {
|
|
213
194
|
state.current = cb(state.current);
|
|
214
195
|
onGesture && onGesture(state.current);
|
|
215
196
|
return state.current;
|
|
216
197
|
};
|
|
217
|
-
|
|
218
|
-
var handlers = gestureHandlers(set, containerRef, options);
|
|
198
|
+
const handlers = gestureHandlers(set, containerRef, options);
|
|
219
199
|
return {
|
|
220
200
|
state: state.current,
|
|
221
|
-
handlers
|
|
201
|
+
handlers
|
|
222
202
|
};
|
|
223
203
|
};
|
|
224
204
|
//# sourceMappingURL=useGestureHandlers.js.map
|