@basic-ui/core 0.0.39 → 0.0.42
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 +1312 -464
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +7 -7
- package/build/esm/Accordion/Accordion.js +4 -4
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +5 -5
- package/build/esm/Accordion/AccordionBody.js +4 -4
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +6 -6
- package/build/esm/Accordion/AccordionHeader.js +4 -4
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +7 -7
- package/build/esm/Accordion/AccordionItem.js +2 -2
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +3 -3
- package/build/esm/Accordion/context.js +0 -0
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.d.ts +0 -0
- package/build/esm/Accordion/index.js +0 -0
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.d.ts +0 -0
- package/build/esm/Accordion/scopeQuery.js +0 -0
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +6 -6
- package/build/esm/CheckBox/CheckBox.js +2 -2
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.d.ts +0 -0
- package/build/esm/CheckBox/index.js +0 -0
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +10 -10
- package/build/esm/ComboBox/Combobox.js +3 -3
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxButton.js +4 -4
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +10 -10
- package/build/esm/ComboBox/ComboboxInput.js +3 -3
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +5 -5
- package/build/esm/ComboBox/ComboboxLabel.js +2 -2
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +6 -6
- package/build/esm/ComboBox/ComboboxList.js +3 -3
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +7 -7
- package/build/esm/ComboBox/ComboboxOption.js +4 -4
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxPopover.js +5 -5
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.d.ts +0 -0
- package/build/esm/ComboBox/cities.js +0 -0
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +10 -10
- package/build/esm/ComboBox/context.js +0 -0
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +3 -3
- package/build/esm/ComboBox/hooks.js +11 -11
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.d.ts +0 -0
- package/build/esm/ComboBox/index.js +0 -0
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.d.ts +0 -0
- package/build/esm/ComboBox/makeHash.js +0 -0
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.d.ts +0 -0
- package/build/esm/ComboBox/scopeQuery.js +0 -0
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +7 -7
- package/build/esm/FocusLock/FocusLock.js +2 -2
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.d.ts +0 -0
- package/build/esm/FocusLock/index.js +0 -0
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.d.ts +0 -0
- package/build/esm/FocusLock/tabUtils.js +0 -0
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.d.ts +4 -4
- package/build/esm/FocusLock/useFocusLock.js +0 -0
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +6 -6
- package/build/esm/List/List.js +2 -2
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +6 -6
- package/build/esm/List/ListItem.js +2 -2
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.d.ts +0 -0
- package/build/esm/List/context.js +0 -0
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.d.ts +0 -0
- package/build/esm/List/index.js +0 -0
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +6 -6
- package/build/esm/Menu/Menu.js +2 -2
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +10 -10
- package/build/esm/Menu/MenuButton.js +3 -3
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +6 -6
- package/build/esm/Menu/MenuItem.js +4 -4
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +5 -5
- package/build/esm/Menu/MenuList.js +6 -6
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +5 -5
- package/build/esm/Menu/MenuPopover.js +2 -2
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +2 -2
- package/build/esm/Menu/context.js +0 -0
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/index.d.ts +0 -0
- package/build/esm/Menu/index.js +0 -0
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.d.ts +0 -0
- package/build/esm/Menu/scope.js +0 -0
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +6 -7
- package/build/esm/Modal/Modal.js +5 -5
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +6 -6
- package/build/esm/Modal/ModalBackdrop.js +6 -6
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.d.ts +0 -0
- package/build/esm/Modal/index.js +0 -0
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +7 -7
- package/build/esm/Popper/Popper.js +6 -6
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +5 -5
- package/build/esm/Popper/PopperArrow.js +5 -6
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +0 -0
- package/build/esm/Popper/context.js +0 -0
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.d.ts +0 -0
- package/build/esm/Popper/index.js +0 -0
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +0 -0
- package/build/esm/Portal/Portal.js +0 -0
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/index.d.ts +0 -0
- package/build/esm/Portal/index.js +0 -0
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +6 -6
- package/build/esm/RadioButton/RadioButton.js +5 -3
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +7 -7
- package/build/esm/RadioButton/RadioGroup.js +2 -2
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +2 -2
- package/build/esm/RadioButton/context.js +0 -0
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.d.ts +0 -0
- package/build/esm/RadioButton/index.js +0 -0
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +6 -6
- package/build/esm/SkipNav/SkipNav.js +2 -2
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.d.ts +0 -0
- package/build/esm/SkipNav/index.js +0 -0
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +218 -0
- package/build/esm/Slider/Slider.js +842 -0
- package/build/esm/Slider/Slider.js.map +1 -0
- package/build/esm/Slider/index.d.ts +1 -0
- package/build/esm/Slider/index.js +2 -0
- package/build/esm/Slider/index.js.map +1 -0
- package/build/esm/Spinner/Spinner.d.ts +7 -7
- package/build/esm/Spinner/Spinner.js +2 -2
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +6 -6
- package/build/esm/Spinner/SpinnerButton.js +3 -3
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.d.ts +2 -2
- package/build/esm/Spinner/context.js +0 -0
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.d.ts +0 -0
- package/build/esm/Spinner/index.js +0 -0
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +6 -6
- package/build/esm/Tabs/Tab.js +3 -3
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +6 -6
- package/build/esm/Tabs/TabList.js +4 -4
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +6 -6
- package/build/esm/Tabs/TabPanel.js +4 -4
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +5 -5
- package/build/esm/Tabs/TabPanels.js +4 -4
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +6 -6
- package/build/esm/Tabs/Tabs.js +2 -2
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +2 -2
- package/build/esm/Tabs/context.js +0 -0
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.d.ts +0 -0
- package/build/esm/Tabs/index.js +0 -0
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.d.ts +0 -0
- package/build/esm/Tabs/scopeQuery.js +0 -0
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +7 -8
- package/build/esm/Tooltip/Tooltip.js +5 -3
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.d.ts +0 -0
- package/build/esm/Tooltip/index.js +0 -0
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +0 -0
- package/build/esm/Tooltip/stateMachine.js +9 -9
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +7 -7
- package/build/esm/Tooltip/useTooltip.js +7 -6
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.d.ts +0 -0
- package/build/esm/hooks/index.js +0 -0
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.d.ts +2 -2
- package/build/esm/hooks/useAutoFocus.js +0 -0
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +0 -0
- package/build/esm/hooks/useChildrenCounter.js +0 -0
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +2 -6
- package/build/esm/hooks/useControlledState.js +8 -7
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +0 -0
- package/build/esm/hooks/useFocusReturn.js +2 -2
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +5 -5
- package/build/esm/hooks/useFocusState.js +1 -1
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +5 -5
- package/build/esm/hooks/useGestureHandlers.js +23 -15
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.d.ts +2 -2
- package/build/esm/hooks/useMeasure.js +0 -1
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
- package/build/esm/hooks/useOnClickOutside.js +0 -0
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
- package/build/esm/hooks/useOnKeyDown.js +5 -5
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +0 -0
- package/build/esm/hooks/useReducerMachine.js +2 -1
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +12 -8
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +0 -0
- package/build/esm/hooks/useScope.js +0 -0
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.d.ts +0 -0
- package/build/esm/hooks/useThrottle.js +0 -0
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils/assign-ref.d.ts +3 -0
- package/build/esm/utils/{assignRef.js → assign-ref.js} +1 -1
- package/build/esm/utils/assign-ref.js.map +1 -0
- package/build/esm/utils/can-use-dom.d.ts +1 -0
- package/build/esm/utils/can-use-dom.js +4 -0
- package/build/esm/utils/can-use-dom.js.map +1 -0
- package/build/esm/utils/clamp.d.ts +0 -0
- package/build/esm/utils/clamp.js +0 -0
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +7 -0
- package/build/esm/utils/context.js +41 -0
- package/build/esm/utils/context.js.map +1 -0
- package/build/esm/utils/{createSubscription.d.ts → create-subscription.d.ts} +0 -0
- package/build/esm/utils/{createSubscription.js → create-subscription.js} +1 -1
- package/build/esm/utils/create-subscription.js.map +1 -0
- package/build/esm/utils/{getCircularIndex.d.ts → get-circular-index.d.ts} +0 -0
- package/build/esm/utils/{getCircularIndex.js → get-circular-index.js} +1 -1
- package/build/esm/utils/get-circular-index.js.map +1 -0
- package/build/esm/utils/index.d.ts +10 -4
- package/build/esm/utils/index.js +10 -4
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.d.ts +6 -0
- package/build/esm/utils/is-right-click.js +9 -0
- package/build/esm/utils/is-right-click.js.map +1 -0
- package/build/esm/utils/owner-document.d.ts +7 -0
- package/build/esm/utils/owner-document.js +12 -0
- package/build/esm/utils/owner-document.js.map +1 -0
- package/build/esm/utils/polymorphic.d.ts +32 -0
- package/build/esm/utils/polymorphic.js +2 -0
- package/build/esm/utils/polymorphic.js.map +1 -0
- package/build/esm/utils/{rubberBandClamp.d.ts → rubber-band-clamp.d.ts} +0 -0
- package/build/esm/utils/{rubberBandClamp.js → rubber-band-clamp.js} +1 -1
- package/build/esm/utils/rubber-band-clamp.js.map +1 -0
- package/build/esm/utils/use-stable-callback.d.ts +16 -0
- package/build/esm/utils/use-stable-callback.js +43 -0
- package/build/esm/utils/use-stable-callback.js.map +1 -0
- package/build/esm/utils/wrap-event.d.ts +3 -0
- package/build/esm/utils/{wrapEvent.js → wrap-event.js} +1 -1
- package/build/esm/utils/wrap-event.js.map +1 -0
- package/build/tsconfig-build.tsbuildinfo +1 -0
- package/package.json +4 -5
- package/src/Accordion/Accordion.tsx +12 -6
- package/src/Accordion/AccordionBody.tsx +4 -5
- package/src/Accordion/AccordionHeader.tsx +30 -27
- package/src/Accordion/AccordionItem.tsx +12 -6
- package/src/Accordion/context.ts +3 -2
- package/src/CheckBox/CheckBox.tsx +5 -6
- package/src/ComboBox/ComboBox.story.tsx +3 -3
- package/src/ComboBox/Combobox.tsx +5 -8
- package/src/ComboBox/ComboboxButton.tsx +15 -9
- package/src/ComboBox/ComboboxInput.tsx +18 -10
- package/src/ComboBox/ComboboxLabel.tsx +4 -4
- package/src/ComboBox/ComboboxList.tsx +5 -6
- package/src/ComboBox/ComboboxOption.tsx +12 -8
- package/src/ComboBox/ComboboxPopover.tsx +15 -10
- package/src/ComboBox/context.ts +10 -9
- package/src/ComboBox/hooks.tsx +4 -3
- package/src/FocusLock/FocusLock.tsx +13 -7
- package/src/FocusLock/useFocusLock.ts +4 -3
- package/src/List/List.tsx +5 -5
- package/src/List/ListItem.tsx +5 -5
- package/src/Menu/Menu.story.tsx +2 -2
- package/src/Menu/Menu.tsx +13 -7
- package/src/Menu/MenuButton.tsx +13 -10
- package/src/Menu/MenuItem.tsx +15 -11
- package/src/Menu/MenuList.tsx +6 -6
- package/src/Menu/MenuPopover.tsx +4 -4
- package/src/Menu/context.ts +9 -4
- package/src/Modal/Modal.tsx +11 -7
- package/src/Modal/ModalBackdrop.tsx +16 -11
- package/src/Popper/Popper.tsx +7 -7
- package/src/Popper/PopperArrow.tsx +6 -8
- package/src/RadioButton/RadioButton.tsx +11 -6
- package/src/RadioButton/RadioGroup.tsx +11 -9
- package/src/RadioButton/context.ts +2 -4
- package/src/SkipNav/SkipNav.tsx +5 -5
- package/src/Slider/Slider.story.tsx +45 -0
- package/src/Slider/Slider.tsx +1106 -0
- package/src/Slider/index.ts +1 -0
- package/src/Slider/styles.css +131 -0
- package/src/Spinner/Spinner.tsx +13 -9
- package/src/Spinner/SpinnerButton.tsx +11 -6
- package/src/Spinner/context.ts +2 -3
- package/src/Tabs/Tab.tsx +13 -8
- package/src/Tabs/TabList.tsx +5 -5
- package/src/Tabs/TabPanel.tsx +5 -5
- package/src/Tabs/TabPanels.tsx +4 -4
- package/src/Tabs/Tabs.tsx +5 -7
- package/src/Tabs/context.ts +2 -3
- package/src/Tooltip/Tooltip.story.tsx +3 -3
- package/src/Tooltip/Tooltip.tsx +13 -7
- package/src/Tooltip/stateMachine.ts +9 -13
- package/src/Tooltip/useTooltip.ts +19 -12
- package/src/hooks/useAutoFocus.ts +2 -1
- package/src/hooks/useControlledState.ts +14 -14
- package/src/hooks/useFocusState.ts +4 -3
- package/src/hooks/useGestureHandlers.ts +33 -19
- package/src/hooks/useMeasure.ts +2 -2
- package/src/hooks/useOnClickOutside.ts +2 -2
- package/src/hooks/useOnKeyDown.ts +4 -3
- package/src/hooks/useRemoveBodyScroll.ts +18 -8
- package/src/index.ts +1 -0
- package/src/utils/{assignRef.ts → assign-ref.ts} +4 -4
- package/src/utils/can-use-dom.ts +7 -0
- package/src/utils/context.tsx +48 -0
- package/src/utils/{createSubscription.ts → create-subscription.ts} +0 -0
- package/src/utils/{getCircularIndex.ts → get-circular-index.ts} +0 -0
- package/src/utils/index.ts +10 -4
- package/src/utils/is-right-click.ts +14 -0
- package/src/utils/owner-document.ts +13 -0
- package/src/utils/polymorphic.ts +72 -0
- package/src/utils/{rubberBandClamp.ts → rubber-band-clamp.ts} +0 -0
- package/src/utils/use-stable-callback.ts +58 -0
- package/src/utils/wrap-event.ts +22 -0
- package/build/esm/utils/assignRef.d.ts +0 -3
- package/build/esm/utils/assignRef.js.map +0 -1
- package/build/esm/utils/createSubscription.js.map +0 -1
- package/build/esm/utils/getCircularIndex.js.map +0 -1
- package/build/esm/utils/rubberBandClamp.js.map +0 -1
- package/build/esm/utils/wrapEvent.d.ts +0 -3
- package/build/esm/utils/wrapEvent.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/utils/wrapEvent.ts +0 -20
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MutableRefObject,
|
|
3
|
+
MouseEvent as ReactMouseEvent,
|
|
4
|
+
TouchEvent as ReactTouchEvent,
|
|
5
|
+
} from 'react';
|
|
1
6
|
import { useRef } from 'react';
|
|
2
|
-
|
|
7
|
+
|
|
8
|
+
import { getOwnerDocument } from '../utils';
|
|
3
9
|
|
|
4
10
|
export interface GestureHandlersState {
|
|
5
11
|
target: null | EventTarget;
|
|
@@ -26,8 +32,8 @@ type SetStateFunc<S> = (
|
|
|
26
32
|
) => void;
|
|
27
33
|
|
|
28
34
|
export interface GestureHandlersReturn {
|
|
29
|
-
onMouseDown: (e:
|
|
30
|
-
onTouchStart: (e:
|
|
35
|
+
onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;
|
|
36
|
+
onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export interface GestureHandlerOptions {
|
|
@@ -59,7 +65,7 @@ const VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;
|
|
|
59
65
|
|
|
60
66
|
export function gestureHandlers(
|
|
61
67
|
set: SetStateFunc<GestureHandlersState>,
|
|
62
|
-
containerRef?:
|
|
68
|
+
containerRef?: MutableRefObject<HTMLElement | null>,
|
|
63
69
|
options: GestureHandlerOptions = {}
|
|
64
70
|
): GestureHandlersReturn {
|
|
65
71
|
const { ensureTargetIsContainer = false, minTouchDelta = 0 } = options;
|
|
@@ -192,7 +198,7 @@ export function gestureHandlers(
|
|
|
192
198
|
handleMove(e.touches.item(0) as any);
|
|
193
199
|
}
|
|
194
200
|
|
|
195
|
-
function handleTouchStart(e:
|
|
201
|
+
function handleTouchStart(e: ReactTouchEvent<HTMLElement>) {
|
|
196
202
|
// making sure we're not dragging the element when more than one finger press the screen
|
|
197
203
|
const { touches } = e;
|
|
198
204
|
if (touches.length > 1) {
|
|
@@ -207,21 +213,26 @@ export function gestureHandlers(
|
|
|
207
213
|
return;
|
|
208
214
|
}
|
|
209
215
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
217
|
+
const ownerDocument = getOwnerDocument(e.currentTarget)!;
|
|
218
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
219
|
+
ownerWindow.addEventListener('touchmove', handleTouchMove, {
|
|
220
|
+
passive: false,
|
|
221
|
+
});
|
|
222
|
+
ownerWindow.addEventListener('touchend', handleTouchEnd);
|
|
223
|
+
ownerWindow.addEventListener('touchcancel', handleTouchEnd);
|
|
213
224
|
handleDown(e.touches.item(0) as any);
|
|
214
225
|
}
|
|
215
226
|
|
|
216
|
-
function handleTouchEnd() {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
function handleTouchEnd(this: Window) {
|
|
228
|
+
this.removeEventListener('touchmove', handleTouchMove);
|
|
229
|
+
this.removeEventListener('touchend', handleTouchEnd);
|
|
230
|
+
this.removeEventListener('touchcancel', handleTouchEnd);
|
|
220
231
|
handleUp();
|
|
221
232
|
}
|
|
222
233
|
|
|
223
234
|
// Mouse handlers
|
|
224
|
-
function handleMouseDown(e:
|
|
235
|
+
function handleMouseDown(e: ReactMouseEvent<HTMLElement>) {
|
|
225
236
|
if (
|
|
226
237
|
ensureTargetIsContainer &&
|
|
227
238
|
containerRef &&
|
|
@@ -230,16 +241,19 @@ export function gestureHandlers(
|
|
|
230
241
|
return;
|
|
231
242
|
}
|
|
232
243
|
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
245
|
+
const ownerDocument = getOwnerDocument(e.currentTarget)!;
|
|
246
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
233
247
|
if (e.button === 0) {
|
|
234
|
-
|
|
235
|
-
|
|
248
|
+
ownerWindow.addEventListener('mousemove', handleMove);
|
|
249
|
+
ownerWindow.addEventListener('mouseup', handleMouseUp);
|
|
236
250
|
handleDown(e as any);
|
|
237
251
|
}
|
|
238
252
|
}
|
|
239
253
|
|
|
240
|
-
function handleMouseUp() {
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
function handleMouseUp(this: Window) {
|
|
255
|
+
this.removeEventListener('mousemove', handleMove);
|
|
256
|
+
this.removeEventListener('mouseup', handleMouseUp);
|
|
243
257
|
handleUp();
|
|
244
258
|
}
|
|
245
259
|
/* eslint-enable @typescript-eslint/no-use-before-define */
|
|
@@ -251,7 +265,7 @@ export function gestureHandlers(
|
|
|
251
265
|
}
|
|
252
266
|
|
|
253
267
|
export const useGestureHandlers = (
|
|
254
|
-
containerRef:
|
|
268
|
+
containerRef: MutableRefObject<HTMLElement | null> | undefined,
|
|
255
269
|
onGesture: (e: GestureHandlersState) => void,
|
|
256
270
|
options: GestureHandlerOptions = {}
|
|
257
271
|
) => {
|
package/src/hooks/useMeasure.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
1
2
|
import { useRef, useState, useEffect } from 'react';
|
|
2
|
-
import ResizeObserver from 'resize-observer-polyfill';
|
|
3
3
|
|
|
4
|
-
export function useMeasure(ref:
|
|
4
|
+
export function useMeasure(ref: MutableRefObject<HTMLElement | null>) {
|
|
5
5
|
const ro = useRef<ResizeObserver | null>(null);
|
|
6
6
|
const [bounds, setBounds] = useState({
|
|
7
7
|
left: 0,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
1
2
|
import { useEffect, useCallback } from 'react';
|
|
2
|
-
import type * as React from 'react';
|
|
3
3
|
|
|
4
4
|
export function useOnClickOutside(
|
|
5
|
-
ref:
|
|
5
|
+
ref: RefObject<any>,
|
|
6
6
|
handler: (e: PointerEvent) => void,
|
|
7
7
|
active = true
|
|
8
8
|
) {
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
export function useOnKeyDown(
|
|
4
|
+
ownerWindow: Window,
|
|
4
5
|
handler: (e: KeyboardEvent) => void,
|
|
5
6
|
active = true
|
|
6
7
|
) {
|
|
7
8
|
useEffect(() => {
|
|
8
9
|
if (active) {
|
|
9
|
-
|
|
10
|
+
ownerWindow.addEventListener('keydown', handler);
|
|
10
11
|
|
|
11
12
|
return () => {
|
|
12
|
-
|
|
13
|
+
ownerWindow.removeEventListener('keydown', handler);
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
return;
|
|
17
|
-
}, [active, handler]);
|
|
18
|
+
}, [ownerWindow, active, handler]);
|
|
18
19
|
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
1
2
|
import { useEffect } from 'react';
|
|
2
3
|
|
|
4
|
+
import { getOwnerDocument } from '../utils';
|
|
5
|
+
|
|
3
6
|
let scrollBodyCount = 0;
|
|
4
|
-
export function useRemoveBodyScroll(
|
|
7
|
+
export function useRemoveBodyScroll(
|
|
8
|
+
open: boolean,
|
|
9
|
+
elementRef: RefObject<HTMLElement | null>
|
|
10
|
+
) {
|
|
5
11
|
useEffect(() => {
|
|
6
|
-
if (open) {
|
|
12
|
+
if (open && elementRef.current) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
14
|
+
const ownerDocument = getOwnerDocument(elementRef.current)!;
|
|
15
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
7
16
|
scrollBodyCount += 1;
|
|
8
17
|
|
|
9
18
|
// calculate scrollbar width if mounting the first scroll lock
|
|
10
19
|
let scrollBarWidth = 0;
|
|
11
20
|
if (scrollBodyCount === 1) {
|
|
12
|
-
scrollBarWidth =
|
|
21
|
+
scrollBarWidth =
|
|
22
|
+
ownerWindow.innerWidth - ownerDocument.body.clientWidth;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
ownerDocument.body.style.overflow = 'hidden';
|
|
16
26
|
if (scrollBarWidth > 0) {
|
|
17
|
-
|
|
27
|
+
ownerDocument.body.style.marginRight = `${scrollBarWidth}px`;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
return () => {
|
|
21
31
|
scrollBodyCount -= 1;
|
|
22
32
|
if (scrollBodyCount === 0) {
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
ownerDocument.body.style.overflow = '';
|
|
34
|
+
ownerDocument.body.style.marginRight = '';
|
|
25
35
|
}
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
|
-
}, [open]);
|
|
38
|
+
}, [elementRef, open]);
|
|
29
39
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MutableRefObject, RefCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
export function assignRef<T>(
|
|
4
|
-
ref:
|
|
4
|
+
ref: MutableRefObject<T> | RefCallback<T> | null | undefined,
|
|
5
5
|
value: T
|
|
6
6
|
) {
|
|
7
7
|
if (ref == null) return;
|
|
@@ -9,7 +9,7 @@ export function assignRef<T>(
|
|
|
9
9
|
ref(value);
|
|
10
10
|
} else {
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
ref.current = value;
|
|
13
13
|
} catch (error) {
|
|
14
14
|
throw new Error(`Cannot assign value "${value}" to ref "${ref}"`);
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export function assignRef<T>(
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function assignMultipleRefs<T>(
|
|
20
|
-
...refs: (
|
|
20
|
+
...refs: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]
|
|
21
21
|
): RefCallback<T> {
|
|
22
22
|
return (node: T | null) => {
|
|
23
23
|
refs.forEach((ref) => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useMemo,
|
|
4
|
+
createContext as ReactCreateContext,
|
|
5
|
+
useContext as useReactContext,
|
|
6
|
+
} from 'react';
|
|
7
|
+
|
|
8
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
type ContextProvider<T> = FC<PropsWithChildren<T>>;
|
|
11
|
+
|
|
12
|
+
export function createContext<ContextValueType extends object | null>(
|
|
13
|
+
rootName: string,
|
|
14
|
+
defaultContext?: ContextValueType
|
|
15
|
+
): [
|
|
16
|
+
ContextProvider<ContextValueType>,
|
|
17
|
+
(childName: string) => ContextValueType
|
|
18
|
+
] {
|
|
19
|
+
const Ctx = ReactCreateContext<ContextValueType | undefined>(defaultContext);
|
|
20
|
+
|
|
21
|
+
function Provider(props: PropsWithChildren<ContextValueType>) {
|
|
22
|
+
const { children, ...context } = props;
|
|
23
|
+
const value = useMemo(
|
|
24
|
+
() => context,
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
Object.values(context)
|
|
27
|
+
) as ContextValueType;
|
|
28
|
+
return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function useContext(childName: string) {
|
|
32
|
+
const context = useReactContext(Ctx);
|
|
33
|
+
if (context) {
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
if (defaultContext) {
|
|
37
|
+
return defaultContext;
|
|
38
|
+
}
|
|
39
|
+
throw Error(
|
|
40
|
+
`${childName} must be rendered inside of a ${rootName} component.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Ctx.displayName = `${rootName}Context`;
|
|
45
|
+
Provider.displayName = `${rootName}Provider`;
|
|
46
|
+
|
|
47
|
+
return [Provider, useContext];
|
|
48
|
+
}
|
|
File without changes
|
|
File without changes
|
package/src/utils/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
1
|
+
export * from './assign-ref';
|
|
2
|
+
export * from './can-use-dom';
|
|
3
|
+
export * from './context';
|
|
4
|
+
export * from './get-circular-index';
|
|
5
|
+
export * from './is-right-click';
|
|
6
|
+
export * from './owner-document';
|
|
7
|
+
export * from './polymorphic';
|
|
8
|
+
export * from './rubber-band-clamp';
|
|
9
|
+
export * from './use-stable-callback';
|
|
10
|
+
export * from './wrap-event';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects right clicks
|
|
3
|
+
*
|
|
4
|
+
* @param nativeEvent
|
|
5
|
+
*/
|
|
6
|
+
export function isRightClick(
|
|
7
|
+
nativeEvent: MouseEvent | PointerEvent | TouchEvent
|
|
8
|
+
) {
|
|
9
|
+
return 'which' in nativeEvent
|
|
10
|
+
? nativeEvent.which === 3
|
|
11
|
+
: 'button' in nativeEvent
|
|
12
|
+
? (nativeEvent as any).button === 2
|
|
13
|
+
: false;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { canUseDOM } from './can-use-dom';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get an element's owner document. Useful when components are used in iframes
|
|
5
|
+
* or other environments like dev tools.
|
|
6
|
+
*
|
|
7
|
+
* @param element
|
|
8
|
+
*/
|
|
9
|
+
export function getOwnerDocument<T extends Element>(
|
|
10
|
+
element: T | null | undefined
|
|
11
|
+
) {
|
|
12
|
+
return canUseDOM() ? (element ? element.ownerDocument : document) : null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
// adapted from https://github.com/radix-ui/primitives/blob/2f139a832ba0cdfd445c937ebf63c2e79e0ef7ed/packages/react/polymorphic/src/polymorphic.ts
|
|
3
|
+
// Would have liked to use it directly instead of copying but they are
|
|
4
|
+
// (rightfully) treating it as an internal utility, so copy/paste it is to
|
|
5
|
+
// prevent any needless churn if they make breaking changes. Big thanks to Jenna
|
|
6
|
+
// for the heavy lifting! https://github.com/jjenzz
|
|
7
|
+
|
|
8
|
+
import type * as React from 'react';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
11
|
+
export type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Infers the OwnProps if E is a ForwardRefExoticComponentWithAs
|
|
15
|
+
*/
|
|
16
|
+
export type OwnProps<E> = E extends ForwardRefComponent<any, infer P> ? P : {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Infers the JSX.IntrinsicElement if E is a ForwardRefExoticComponentWithAs
|
|
20
|
+
*/
|
|
21
|
+
export type IntrinsicElement<E> = E extends ForwardRefComponent<infer I, any>
|
|
22
|
+
? I
|
|
23
|
+
: never;
|
|
24
|
+
|
|
25
|
+
type ForwardRefExoticComponent<E, OwnProps> = React.ForwardRefExoticComponent<
|
|
26
|
+
Merge<
|
|
27
|
+
E extends React.ElementType ? React.ComponentPropsWithRef<E> : never,
|
|
28
|
+
OwnProps & { as?: E }
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
export interface ForwardRefComponent<
|
|
33
|
+
IntrinsicElementString,
|
|
34
|
+
OwnProps = {}
|
|
35
|
+
/*
|
|
36
|
+
* Extends original type to ensure built in React types play nice with
|
|
37
|
+
* polymorphic components still e.g. `React.ElementRef` etc.
|
|
38
|
+
*/
|
|
39
|
+
> extends ForwardRefExoticComponent<IntrinsicElementString, OwnProps> {
|
|
40
|
+
/*
|
|
41
|
+
* When `as` prop is passed, use this overload. Merges original own props
|
|
42
|
+
* (without DOM props) and the inferred props from `as` element with the own
|
|
43
|
+
* props taking precendence.
|
|
44
|
+
*
|
|
45
|
+
* We explicitly avoid `React.ElementType` and manually narrow the prop types
|
|
46
|
+
* so that events are typed when using JSX.IntrinsicElements.
|
|
47
|
+
*/
|
|
48
|
+
<As = IntrinsicElementString>(
|
|
49
|
+
props: As extends ''
|
|
50
|
+
? { as: keyof JSX.IntrinsicElements }
|
|
51
|
+
: As extends React.ComponentType<infer P>
|
|
52
|
+
? Merge<P, OwnProps & { as: As }>
|
|
53
|
+
: As extends keyof JSX.IntrinsicElements
|
|
54
|
+
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
|
|
55
|
+
: never
|
|
56
|
+
): React.ReactElement | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface MemoComponent<IntrinsicElementString, OwnProps = {}>
|
|
60
|
+
extends React.MemoExoticComponent<
|
|
61
|
+
ForwardRefComponent<IntrinsicElementString, OwnProps>
|
|
62
|
+
> {
|
|
63
|
+
<As = IntrinsicElementString>(
|
|
64
|
+
props: As extends ''
|
|
65
|
+
? { as: keyof JSX.IntrinsicElements }
|
|
66
|
+
: As extends React.ComponentType<infer P>
|
|
67
|
+
? Merge<P, OwnProps & { as: As }>
|
|
68
|
+
: As extends keyof JSX.IntrinsicElements
|
|
69
|
+
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
|
|
70
|
+
: never
|
|
71
|
+
): React.ReactElement | null;
|
|
72
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
import { useRef, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
3
|
+
import type * as React from 'react';
|
|
4
|
+
|
|
5
|
+
const useEnhancedEffect =
|
|
6
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
10
|
+
* prop and exposed as a stable function to avoid executing effects when
|
|
11
|
+
* passed as a dependency.
|
|
12
|
+
*/
|
|
13
|
+
function createStableCallbackHook<T extends (...args: any[]) => any>(
|
|
14
|
+
useEffectHook: (
|
|
15
|
+
effect: React.EffectCallback,
|
|
16
|
+
deps?: React.DependencyList | undefined
|
|
17
|
+
) => void,
|
|
18
|
+
callback: T | null | undefined
|
|
19
|
+
): T {
|
|
20
|
+
const callbackRef = useRef(callback);
|
|
21
|
+
useEffectHook(() => {
|
|
22
|
+
callbackRef.current = callback;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
return useCallback(
|
|
27
|
+
((...args) => {
|
|
28
|
+
callbackRef.current && callbackRef.current(...args);
|
|
29
|
+
}) as T,
|
|
30
|
+
[]
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
36
|
+
* prop and exposed as a stable function to avoid executing effects when passed
|
|
37
|
+
* as a dependency.
|
|
38
|
+
*/
|
|
39
|
+
export function useStableCallback<T extends (...args: any[]) => any>(
|
|
40
|
+
callback: T | null | undefined
|
|
41
|
+
): T {
|
|
42
|
+
return createStableCallbackHook(useEffect, callback);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
47
|
+
* prop and exposed as a stable function to avoid executing effects when passed
|
|
48
|
+
* as a dependency.
|
|
49
|
+
*
|
|
50
|
+
* Use this over `useStableCallback` when you want the callback to be cached in
|
|
51
|
+
* `useLayoutEffect` instead of `useEffect` to deal with timing issues only when
|
|
52
|
+
* needed.
|
|
53
|
+
*/
|
|
54
|
+
export function useStableLayoutCallback<T extends (...args: any[]) => any>(
|
|
55
|
+
callback: T | null | undefined
|
|
56
|
+
): T {
|
|
57
|
+
return createStableCallbackHook(useEnhancedEffect, callback);
|
|
58
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SyntheticEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
export type CustomEventHandler<
|
|
4
|
+
E extends SyntheticEvent<any> | Event,
|
|
5
|
+
H extends unknown[]
|
|
6
|
+
> = (e: E, ...args: H) => void;
|
|
7
|
+
|
|
8
|
+
export function wrapEvent<
|
|
9
|
+
EventType extends SyntheticEvent<any> | Event,
|
|
10
|
+
H extends unknown[]
|
|
11
|
+
>(
|
|
12
|
+
theirHandler: CustomEventHandler<EventType, H> | undefined,
|
|
13
|
+
ourHandler: CustomEventHandler<EventType, H>
|
|
14
|
+
): CustomEventHandler<EventType, H> {
|
|
15
|
+
return (event: EventType, ...otherArgs: H) => {
|
|
16
|
+
const ret = theirHandler && theirHandler(event, ...otherArgs);
|
|
17
|
+
if (!event.defaultPrevented) {
|
|
18
|
+
return ourHandler(event, ...otherArgs);
|
|
19
|
+
}
|
|
20
|
+
return ret;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { LegacyRef, MutableRefObject, Ref, RefCallback } from 'react';
|
|
2
|
-
export declare function assignRef<T>(ref: LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined, value: T): void;
|
|
3
|
-
export declare function assignMultipleRefs<T>(...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]): RefCallback<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/assignRef.ts"],"names":["assignRef","ref","value","current","error","Error","assignMultipleRefs","refs","node","forEach"],"mappings":"AAEA,OAAO,SAASA,SAAT,CACLC,GADK,EAELC,KAFK,EAGL;AACA,MAAID,GAAG,IAAI,IAAX,EAAiB;;AACjB,MAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,IAAAA,GAAG,CAACC,KAAD,CAAH;AACD,GAFD,MAEO;AACL,QAAI;AACDD,MAAAA,GAAD,CAA6BE,OAA7B,GAAuCD,KAAvC;AACD,KAFD,CAEE,OAAOE,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,iCAAkCH,KAAlC,yBAAoDD,GAApD,QAAN;AACD;AACF;AACF;AAED,OAAO,SAASK,kBAAT,GAEW;AAAA,oCADbC,IACa;AADbA,IAAAA,IACa;AAAA;;AAChB,SAAO,UAACC,IAAD,EAAoB;AACzBD,IAAAA,IAAI,CAACE,OAAL,CAAa,UAACR,GAAD,EAAS;AACpBD,MAAAA,SAAS,CAACC,GAAD,EAAMO,IAAN,CAAT;AACD,KAFD;AAGD,GAJD;AAKD","sourcesContent":["import type { LegacyRef, MutableRefObject, Ref, RefCallback } from 'react';\n\nexport function assignRef<T>(\n ref: LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined,\n value: T\n) {\n if (ref == null) return;\n if (typeof ref === 'function') {\n ref(value);\n } else {\n try {\n (ref as MutableRefObject<T>).current = value;\n } catch (error) {\n throw new Error(`Cannot assign value \"${value}\" to ref \"${ref}\"`);\n }\n }\n}\n\nexport function assignMultipleRefs<T>(\n ...refs: (LegacyRef<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]\n): RefCallback<T> {\n return (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node);\n });\n };\n}\n"],"file":"assignRef.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/createSubscription.ts"],"names":["createSubscription","subscriptions","subscribe","fn","push","splice","indexOf","notify","forEach"],"mappings":"AAAA,OAAO,SAASA,kBAAT,GAA8B;AACnC,MAAMC,aAA6B,GAAG,EAAtC;;AAEA,WAASC,SAAT,CAAmBC,EAAnB,EAAmC;AACjCF,IAAAA,aAAa,CAACG,IAAd,CAAmBD,EAAnB;AACA,WAAO,YAAM;AACXF,MAAAA,aAAa,CAACI,MAAd,CAAqBJ,aAAa,CAACK,OAAd,CAAsBH,EAAtB,CAArB,EAAgD,CAAhD;AACD,KAFD;AAGD;;AAED,WAASI,MAAT,GAAkB;AAChBN,IAAAA,aAAa,CAACO,OAAd,CAAsB,UAACL,EAAD;AAAA,aAAQA,EAAE,EAAV;AAAA,KAAtB;AACD;;AAED,SAAO;AAAED,IAAAA,SAAS,EAATA,SAAF;AAAaK,IAAAA,MAAM,EAANA;AAAb,GAAP;AACD","sourcesContent":["export function createSubscription() {\n const subscriptions: (() => void)[] = [];\n\n function subscribe(fn: () => void) {\n subscriptions.push(fn);\n return () => {\n subscriptions.splice(subscriptions.indexOf(fn), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((fn) => fn());\n }\n\n return { subscribe, notify };\n}\n"],"file":"createSubscription.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/getCircularIndex.ts"],"names":["getCircularIndex","index","maxLength"],"mappings":"AAAA,OAAO,SAASA,gBAAT,CAA0BC,KAA1B,EAAyCC,SAAzC,EAA4D;AACjE,MAAIA,SAAS,GAAG,CAAhB,EAAmB;AACjB,WAAO,IAAP;AACD;;AAED,SAAO,CAAED,KAAK,GAAGC,SAAT,GAAsBA,SAAvB,IAAoCA,SAA3C;AACD","sourcesContent":["export function getCircularIndex(index: number, maxLength: number) {\n if (maxLength < 0) {\n return null;\n }\n\n return ((index % maxLength) + maxLength) % maxLength;\n}\n"],"file":"getCircularIndex.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/rubberBandClamp.ts"],"names":["rubberBand","distance","dimension","constant","rubberBandClamp","min","max","delta"],"mappings":"AAAA;AACA;AACA,OAAO,SAASA,UAAT,CACLC,QADK,EAELC,SAFK,EAIL;AAAA,MADAC,QACA,uEADW,IACX;AACA,SAAQF,QAAQ,GAAGC,SAAX,GAAuBC,QAAxB,IAAqCD,SAAS,GAAGC,QAAQ,GAAGF,QAA5D,CAAP;AACD;AAED,OAAO,SAASG,eAAT,CACLC,GADK,EAELC,GAFK,EAGLC,KAHK,EAKL;AAAA,MADAJ,QACA,uEADW,IACX;;AACA,MAAII,KAAK,GAAGF,GAAZ,EAAiB;AACf,WAAO,CAACL,UAAU,CAACK,GAAG,GAAGE,KAAP,EAAcD,GAAG,GAAGD,GAApB,EAAyBF,QAAzB,CAAX,GAAgDE,GAAvD;AACD;;AACD,MAAIE,KAAK,GAAGD,GAAZ,EAAiB;AACf,WAAON,UAAU,CAACO,KAAK,GAAGD,GAAT,EAAcA,GAAG,GAAGD,GAApB,EAAyBF,QAAzB,CAAV,GAA+CG,GAAtD;AACD;;AAED,SAAOC,KAAP;AACD","sourcesContent":["// https://twitter.com/chpwn/status/285540192096497664\n// iOS constant = 0.55\nexport function rubberBand(\n distance: number,\n dimension: number,\n constant = 0.15\n) {\n return (distance * dimension * constant) / (dimension + constant * distance);\n}\n\nexport function rubberBandClamp(\n min: number,\n max: number,\n delta: number,\n constant = 0.15\n) {\n if (delta < min) {\n return -rubberBand(min - delta, max - min, constant) + min;\n }\n if (delta > max) {\n return rubberBand(delta - max, max - min, constant) + max;\n }\n\n return delta;\n}\n"],"file":"rubberBandClamp.js"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare type CustomEventHandler<E extends React.SyntheticEvent<any>, H extends unknown[]> = (e: E, ...args: H) => void;
|
|
3
|
-
export declare function wrapEvent<E extends React.SyntheticEvent<any>, H extends unknown[]>(theirHandler: CustomEventHandler<E, H> | undefined, ourHandler: CustomEventHandler<E, H>): CustomEventHandler<E, H>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/wrapEvent.ts"],"names":["wrapEvent","theirHandler","ourHandler","event","otherArgs","ret","defaultPrevented"],"mappings":"AAKA,OAAO,SAASA,SAAT,CAILC,YAJK,EAKLC,UALK,EAMqB;AAC1B,SAAO,UAACC,KAAD,EAA+B;AAAA,sCAAjBC,SAAiB;AAAjBA,MAAAA,SAAiB;AAAA;;AACpC,QAAMC,GAAG,GAAGJ,YAAY,IAAIA,YAAY,MAAZ,UAAaE,KAAb,SAAuBC,SAAvB,EAA5B;;AACA,QAAI,CAACD,KAAK,CAACG,gBAAX,EAA6B;AAC3B,aAAOJ,UAAU,MAAV,UAAWC,KAAX,SAAqBC,SAArB,EAAP;AACD;;AACD,WAAOC,GAAP;AACD,GAND;AAOD","sourcesContent":["export type CustomEventHandler<\n E extends React.SyntheticEvent<any>,\n H extends unknown[]\n> = (e: E, ...args: H) => void;\n\nexport function wrapEvent<\n E extends React.SyntheticEvent<any>,\n H extends unknown[]\n>(\n theirHandler: CustomEventHandler<E, H> | undefined,\n ourHandler: CustomEventHandler<E, H>\n): CustomEventHandler<E, H> {\n return (event: E, ...otherArgs: H) => {\n const ret = theirHandler && theirHandler(event, ...otherArgs);\n if (!event.defaultPrevented) {\n return ourHandler(event, ...otherArgs);\n }\n return ret;\n };\n}\n"],"file":"wrapEvent.js"}
|