@basic-ui/core 0.0.50 → 0.0.52
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 +3 -3
- package/build/cjs/index.js +106 -92
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +9 -9
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +6 -6
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +7 -7
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +9 -9
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +19 -19
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.d.ts +4 -4
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.d.ts +2 -2
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +7 -7
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.d.ts +1 -1
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +18 -18
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +9 -9
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +17 -17
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +7 -7
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +11 -11
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +9 -9
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.d.ts +5 -5
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +30 -30
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +37 -37
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.d.ts +8 -8
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.d.ts +1 -1
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.d.ts +1 -1
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +9 -9
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.d.ts +1 -1
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.d.ts +3 -3
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.d.ts +7 -7
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +7 -7
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +7 -7
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.d.ts +4 -4
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.d.ts +2 -2
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +11 -11
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +10 -10
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +11 -11
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +8 -8
- package/build/esm/Menu/MenuItem.js +1 -0
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +7 -7
- package/build/esm/Menu/MenuList.js +17 -4
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +8 -8
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +25 -25
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.d.ts +1 -1
- package/build/esm/Menu/fixtures/countryList.js.map +1 -1
- package/build/esm/Menu/index.d.ts +6 -6
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.d.ts +1 -1
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +9 -9
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +10 -10
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.d.ts +2 -2
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +35 -35
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +6 -6
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +6 -6
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.d.ts +3 -3
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +6 -6
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/index.d.ts +1 -1
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +10 -10
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +12 -12
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +9 -9
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.d.ts +2 -2
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +7 -7
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.d.ts +1 -1
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +197 -197
- package/build/esm/Slider/Slider.js +82 -82
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/Slider/index.d.ts +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Spinner/Spinner.d.ts +12 -12
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +8 -8
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.d.ts +12 -12
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.d.ts +2 -2
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +7 -7
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +9 -9
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +8 -8
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +8 -8
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +10 -10
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +17 -17
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.d.ts +5 -5
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.d.ts +1 -1
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +10 -10
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.d.ts +1 -1
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +28 -28
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +10 -10
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.d.ts +13 -13
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.d.ts +2 -2
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +7 -7
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +3 -3
- package/build/esm/hooks/useControlledState.js +1 -1
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +2 -2
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +11 -11
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +52 -52
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.d.ts +7 -7
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +24 -24
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -2
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +11 -11
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.d.ts +1 -1
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.d.ts +15 -15
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils/assign-ref.d.ts +3 -3
- package/build/esm/utils/assign-ref.js.map +1 -1
- package/build/esm/utils/can-use-dom.d.ts +1 -1
- package/build/esm/utils/can-use-dom.js.map +1 -1
- package/build/esm/utils/clamp.d.ts +1 -1
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +7 -7
- package/build/esm/utils/context.js.map +1 -1
- package/build/esm/utils/create-subscription.d.ts +4 -4
- package/build/esm/utils/create-subscription.js.map +1 -1
- package/build/esm/utils/get-circular-index.d.ts +1 -1
- package/build/esm/utils/get-circular-index.js.map +1 -1
- package/build/esm/utils/index.d.ts +10 -10
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.d.ts +6 -6
- package/build/esm/utils/is-right-click.js +4 -4
- package/build/esm/utils/is-right-click.js.map +1 -1
- package/build/esm/utils/owner-document.d.ts +7 -7
- package/build/esm/utils/owner-document.js +5 -5
- package/build/esm/utils/owner-document.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +39 -39
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/esm/utils/rubber-band-clamp.d.ts +2 -2
- package/build/esm/utils/rubber-band-clamp.js.map +1 -1
- package/build/esm/utils/use-stable-callback.d.ts +16 -16
- package/build/esm/utils/use-stable-callback.js +16 -16
- package/build/esm/utils/use-stable-callback.js.map +1 -1
- package/build/esm/utils/wrap-event.d.ts +3 -3
- package/build/esm/utils/wrap-event.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Accordion/Accordion.story.tsx +74 -74
- package/src/Accordion/Accordion.tsx +59 -59
- package/src/Accordion/AccordionBody.tsx +52 -52
- package/src/Accordion/AccordionHeader.tsx +167 -167
- package/src/Accordion/AccordionItem.tsx +50 -50
- package/src/Accordion/context.ts +37 -37
- package/src/Accordion/index.ts +4 -4
- package/src/Accordion/scopeQuery.ts +7 -7
- package/src/Accordion/styles.css +21 -21
- package/src/CheckBox/CheckBox.tsx +41 -41
- package/src/CheckBox/index.ts +1 -1
- package/src/ComboBox/ComboBox.story.tsx +120 -120
- package/src/ComboBox/Combobox.tsx +148 -148
- package/src/ComboBox/ComboboxButton.tsx +61 -61
- package/src/ComboBox/ComboboxInput.tsx +187 -187
- package/src/ComboBox/ComboboxLabel.tsx +33 -33
- package/src/ComboBox/ComboboxList.tsx +47 -47
- package/src/ComboBox/ComboboxOption.tsx +111 -111
- package/src/ComboBox/ComboboxPopover.tsx +64 -64
- package/src/ComboBox/cities.ts +23194 -23194
- package/src/ComboBox/context.ts +35 -35
- package/src/ComboBox/hooks.tsx +451 -451
- package/src/ComboBox/index.ts +8 -8
- package/src/ComboBox/makeHash.ts +19 -19
- package/src/ComboBox/scopeQuery.ts +6 -6
- package/src/ComboBox/styles.css +32 -32
- package/src/FocusLock/FocusLock.tsx +66 -66
- package/src/FocusLock/index.ts +1 -1
- package/src/FocusLock/tabUtils.ts +40 -40
- package/src/FocusLock/useFocusLock.ts +56 -56
- package/src/List/List.story.tsx +18 -18
- package/src/List/List.tsx +17 -17
- package/src/List/ListItem.tsx +23 -23
- package/src/List/context.ts +19 -19
- package/src/List/index.ts +2 -2
- package/src/Menu/ContextMenu.story.tsx +73 -73
- package/src/Menu/ContextMenuTrigger.tsx +76 -76
- package/src/Menu/Menu.story.tsx +160 -160
- package/src/Menu/Menu.tsx +83 -83
- package/src/Menu/MenuButton.tsx +83 -83
- package/src/Menu/MenuComplex.story.tsx +58 -58
- package/src/Menu/MenuItem.tsx +88 -87
- package/src/Menu/MenuList.tsx +254 -243
- package/src/Menu/MenuPopover.tsx +35 -35
- package/src/Menu/context.ts +44 -44
- package/src/Menu/fixtures/countryList.ts +198 -198
- package/src/Menu/index.ts +6 -6
- package/src/Menu/scope.ts +7 -7
- package/src/Menu/styles.css +42 -42
- package/src/Modal/Modal.story.tsx +258 -258
- package/src/Modal/Modal.tsx +48 -48
- package/src/Modal/ModalBackdrop.tsx +78 -78
- package/src/Modal/NavDrawer.story.tsx +158 -158
- package/src/Modal/index.ts +2 -2
- package/src/Modal/styles.css +46 -46
- package/src/Popper/Popper.story.tsx +263 -263
- package/src/Popper/Popper.tsx +154 -154
- package/src/Popper/PopperArrow.tsx +35 -35
- package/src/Popper/context.ts +10 -10
- package/src/Popper/index.ts +3 -3
- package/src/Popper/styles.css +60 -60
- package/src/Portal/Portal.tsx +20 -20
- package/src/Portal/index.ts +1 -1
- package/src/RadioButton/RadioButton.story.tsx +77 -77
- package/src/RadioButton/RadioButton.tsx +55 -55
- package/src/RadioButton/RadioGroup.tsx +60 -60
- package/src/RadioButton/context.ts +17 -17
- package/src/RadioButton/index.ts +2 -2
- package/src/SkipNav/SkipNav.tsx +16 -16
- package/src/SkipNav/index.tsx +1 -1
- package/src/Slider/Slider.story.tsx +45 -45
- package/src/Slider/Slider.tsx +1120 -1120
- package/src/Slider/index.ts +1 -1
- package/src/Slider/styles.css +131 -131
- package/src/Spinner/Spinner.story.tsx +31 -31
- package/src/Spinner/Spinner.tsx +117 -117
- package/src/Spinner/SpinnerButton.tsx +54 -54
- package/src/Spinner/context.ts +20 -20
- package/src/Spinner/index.ts +2 -2
- package/src/Spinner/styles.css +23 -23
- package/src/Tabs/Tab.story.tsx +80 -80
- package/src/Tabs/Tab.tsx +136 -136
- package/src/Tabs/TabList.tsx +71 -71
- package/src/Tabs/TabPanel.tsx +53 -53
- package/src/Tabs/TabPanels.tsx +30 -30
- package/src/Tabs/Tabs.tsx +46 -46
- package/src/Tabs/context.ts +30 -30
- package/src/Tabs/index.tsx +5 -5
- package/src/Tabs/scopeQuery.ts +6 -6
- package/src/Tooltip/Tooltip.story.tsx +61 -61
- package/src/Tooltip/Tooltip.tsx +50 -50
- package/src/Tooltip/index.ts +1 -1
- package/src/Tooltip/stateMachine.ts +192 -192
- package/src/Tooltip/styles.css +17 -17
- package/src/Tooltip/useTooltip.ts +136 -136
- package/src/hooks/index.ts +13 -13
- package/src/hooks/useAutoFocus.ts +22 -22
- package/src/hooks/useChildrenCounter.ts +51 -51
- package/src/hooks/useControlledState.ts +3 -3
- package/src/hooks/useFocusReturn.ts +43 -43
- package/src/hooks/useFocusState.ts +30 -30
- package/src/hooks/useGestureHandlers.ts +286 -286
- package/src/hooks/useMeasure.ts +33 -33
- package/src/hooks/useOnClickOutside.ts +32 -32
- package/src/hooks/useOnKeyDown.ts +19 -19
- package/src/hooks/useReducerMachine.ts +60 -60
- package/src/hooks/useRemoveBodyScroll.ts +39 -39
- package/src/hooks/useScope.ts +52 -52
- package/src/hooks/useThrottle.ts +19 -19
- package/src/index.ts +20 -20
- package/src/utils/assign-ref.ts +27 -27
- package/src/utils/can-use-dom.ts +7 -7
- package/src/utils/clamp.ts +3 -3
- package/src/utils/context.tsx +48 -48
- package/src/utils/create-subscription.ts +16 -16
- package/src/utils/get-circular-index.ts +7 -7
- package/src/utils/index.ts +10 -10
- package/src/utils/is-right-click.ts +14 -14
- package/src/utils/owner-document.ts +13 -13
- package/src/utils/polymorphic.ts +78 -78
- package/src/utils/rubber-band-clamp.ts +25 -25
- package/src/utils/use-stable-callback.ts +58 -58
- package/src/utils/wrap-event.ts +22 -22
|
@@ -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":";AACA,SAASA,QAAT,QAAyB,OAAzB;AAEA,SAASC,SAAT,QAA0B,qBAA1B;AAEA,OAAO,SAASC,aAAT,GAKL;EAAA,IAJAC,KAIA,uEADI,EACJ;EACA,IAAQC,OAAR,GAA4BD,KAA5B,CAAQC,OAAR;EAAA,IAAiBC,MAAjB,GAA4BF,KAA5B,CAAiBE,MAAjB;;EACA,gBAAgCL,QAAQ,CAAC,KAAD,CAAxC;EAAA;EAAA,IAAOM,QAAP;EAAA,IAAiBC,WAAjB;;EAEA,IAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;IACxBD,WAAW,CAAC,IAAD,CAAX;EACD,CAFD;;EAIA,IAAME,UAAU,GAAG,SAAbA,UAAa,GAAM;IACvBF,WAAW,CAAC,KAAD,CAAX;EACD,CAFD;;EAIA,OAAO;IACLG,IAAI,EAAE;MACJN,OAAO,EAAEH,SAAS,CAACG,OAAD,EAAUI,WAAV,CADd;MAEJH,MAAM,EAAEJ,SAAS,CAACI,MAAD,EAASI,UAAT;IAFb,CADD;IAKLH,QAAQ,EAARA;EALK,CAAP;AAOD"}
|
|
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';\r\nimport { useState } from 'react';\r\n\r\nimport { wrapEvent } from '../utils/wrap-event';\r\n\r\nexport function useFocusState<T>(\r\n props: {\r\n onFocus?: FocusEventHandler<T>;\r\n onBlur?: FocusEventHandler<T>;\r\n } = {}\r\n) {\r\n const { onFocus, onBlur } = props;\r\n const [hasFocus, setHasFocus] = useState(false);\r\n\r\n const handleFocus = () => {\r\n setHasFocus(true);\r\n };\r\n\r\n const handleBlur = () => {\r\n setHasFocus(false);\r\n };\r\n\r\n return {\r\n bind: {\r\n onFocus: wrapEvent(onFocus, handleFocus),\r\n onBlur: wrapEvent(onBlur, handleBlur),\r\n },\r\n hasFocus,\r\n };\r\n}\r\n"],"mappings":";AACA,SAASA,QAAT,QAAyB,OAAzB;AAEA,SAASC,SAAT,QAA0B,qBAA1B;AAEA,OAAO,SAASC,aAAT,GAKL;EAAA,IAJAC,KAIA,uEADI,EACJ;EACA,IAAQC,OAAR,GAA4BD,KAA5B,CAAQC,OAAR;EAAA,IAAiBC,MAAjB,GAA4BF,KAA5B,CAAiBE,MAAjB;;EACA,gBAAgCL,QAAQ,CAAC,KAAD,CAAxC;EAAA;EAAA,IAAOM,QAAP;EAAA,IAAiBC,WAAjB;;EAEA,IAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;IACxBD,WAAW,CAAC,IAAD,CAAX;EACD,CAFD;;EAIA,IAAME,UAAU,GAAG,SAAbA,UAAa,GAAM;IACvBF,WAAW,CAAC,KAAD,CAAX;EACD,CAFD;;EAIA,OAAO;IACLG,IAAI,EAAE;MACJN,OAAO,EAAEH,SAAS,CAACG,OAAD,EAAUI,WAAV,CADd;MAEJH,MAAM,EAAEJ,SAAS,CAACI,MAAD,EAASI,UAAT;IAFb,CADD;IAKLH,QAAQ,EAARA;EALK,CAAP;AAOD"}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import type { MutableRefObject, MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
-
export interface GestureHandlersState {
|
|
3
|
-
target: null | EventTarget;
|
|
4
|
-
x: number;
|
|
5
|
-
xDelta: number;
|
|
6
|
-
xDeltaPercent: number;
|
|
7
|
-
xInitial: number;
|
|
8
|
-
xPrev: number;
|
|
9
|
-
xVelocity: number;
|
|
10
|
-
y: number;
|
|
11
|
-
yDelta: number;
|
|
12
|
-
yDeltaPercent: number;
|
|
13
|
-
yInitial: number;
|
|
14
|
-
yPrev: number;
|
|
15
|
-
yVelocity: number;
|
|
16
|
-
startTime: number;
|
|
17
|
-
down: boolean;
|
|
18
|
-
scrollLocked: boolean;
|
|
19
|
-
}
|
|
20
|
-
declare type SetStateFunc<S> = (state: (prevState: Readonly<S>) => S, callback?: () => void) => void;
|
|
21
|
-
export interface GestureHandlersReturn {
|
|
22
|
-
onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;
|
|
23
|
-
onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;
|
|
24
|
-
}
|
|
25
|
-
export interface GestureHandlerOptions {
|
|
26
|
-
ensureTargetIsContainer?: boolean;
|
|
27
|
-
minTouchDelta?: number;
|
|
28
|
-
}
|
|
29
|
-
export declare const initialGestureHandlersState: GestureHandlersState;
|
|
30
|
-
export declare function gestureHandlers(set: SetStateFunc<GestureHandlersState>, containerRef?: MutableRefObject<HTMLElement | null>, options?: GestureHandlerOptions): GestureHandlersReturn;
|
|
31
|
-
export declare const useGestureHandlers: (containerRef: MutableRefObject<HTMLElement | null> | undefined, onGesture: (e: GestureHandlersState) => void, options?: GestureHandlerOptions) => {
|
|
32
|
-
state: {
|
|
33
|
-
target: null | EventTarget;
|
|
34
|
-
x: number;
|
|
35
|
-
xDelta: number;
|
|
36
|
-
xDeltaPercent: number;
|
|
37
|
-
xInitial: number;
|
|
38
|
-
xPrev: number;
|
|
39
|
-
xVelocity: number;
|
|
40
|
-
y: number;
|
|
41
|
-
yDelta: number;
|
|
42
|
-
yDeltaPercent: number;
|
|
43
|
-
yInitial: number;
|
|
44
|
-
yPrev: number;
|
|
45
|
-
yVelocity: number;
|
|
46
|
-
startTime: number;
|
|
47
|
-
down: boolean;
|
|
48
|
-
scrollLocked: boolean;
|
|
49
|
-
};
|
|
50
|
-
handlers: GestureHandlersReturn;
|
|
51
|
-
};
|
|
52
|
-
export {};
|
|
1
|
+
import type { MutableRefObject, MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
+
export interface GestureHandlersState {
|
|
3
|
+
target: null | EventTarget;
|
|
4
|
+
x: number;
|
|
5
|
+
xDelta: number;
|
|
6
|
+
xDeltaPercent: number;
|
|
7
|
+
xInitial: number;
|
|
8
|
+
xPrev: number;
|
|
9
|
+
xVelocity: number;
|
|
10
|
+
y: number;
|
|
11
|
+
yDelta: number;
|
|
12
|
+
yDeltaPercent: number;
|
|
13
|
+
yInitial: number;
|
|
14
|
+
yPrev: number;
|
|
15
|
+
yVelocity: number;
|
|
16
|
+
startTime: number;
|
|
17
|
+
down: boolean;
|
|
18
|
+
scrollLocked: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare type SetStateFunc<S> = (state: (prevState: Readonly<S>) => S, callback?: () => void) => void;
|
|
21
|
+
export interface GestureHandlersReturn {
|
|
22
|
+
onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;
|
|
23
|
+
onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface GestureHandlerOptions {
|
|
26
|
+
ensureTargetIsContainer?: boolean;
|
|
27
|
+
minTouchDelta?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const initialGestureHandlersState: GestureHandlersState;
|
|
30
|
+
export declare function gestureHandlers(set: SetStateFunc<GestureHandlersState>, containerRef?: MutableRefObject<HTMLElement | null>, options?: GestureHandlerOptions): GestureHandlersReturn;
|
|
31
|
+
export declare const useGestureHandlers: (containerRef: MutableRefObject<HTMLElement | null> | undefined, onGesture: (e: GestureHandlersState) => void, options?: GestureHandlerOptions) => {
|
|
32
|
+
state: {
|
|
33
|
+
target: null | EventTarget;
|
|
34
|
+
x: number;
|
|
35
|
+
xDelta: number;
|
|
36
|
+
xDeltaPercent: number;
|
|
37
|
+
xInitial: number;
|
|
38
|
+
xPrev: number;
|
|
39
|
+
xVelocity: number;
|
|
40
|
+
y: number;
|
|
41
|
+
yDelta: number;
|
|
42
|
+
yDeltaPercent: number;
|
|
43
|
+
yInitial: number;
|
|
44
|
+
yPrev: number;
|
|
45
|
+
yVelocity: number;
|
|
46
|
+
startTime: number;
|
|
47
|
+
down: boolean;
|
|
48
|
+
scrollLocked: boolean;
|
|
49
|
+
};
|
|
50
|
+
handlers: GestureHandlersReturn;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGestureHandlers.js","names":["useRef","getOwnerDocument","initialGestureHandlersState","target","x","xDelta","xDeltaPercent","xInitial","xPrev","xVelocity","y","yDelta","yDeltaPercent","yInitial","yPrev","yVelocity","startTime","down","scrollLocked","FRAMERATE_CONST","VELOCITY_DEPR_FACTOR","gestureHandlers","set","containerRef","options","ensureTargetIsContainer","minTouchDelta","handleUp","state","deltaTime","Date","now","calcVelocity","newState","handleDown","e","pageX","pageY","deltaSpace","prevVelocity","speed","depr","Math","min","handleMove","cancelable","preventDefault","getDeltaSum","currentPos","initialPos","prevPos","abs","current","width","offsetWidth","NaN","height","offsetHeight","handleTouchMove","touches","item","handleTouchStart","length","ownerDocument","currentTarget","ownerWindow","defaultView","window","addEventListener","passive","handleTouchEnd","removeEventListener","handleMouseDown","button","handleMouseUp","onMouseDown","onTouchStart","useGestureHandlers","onGesture","cb","handlers"],"sources":["../../../src/hooks/useGestureHandlers.ts"],"sourcesContent":["import type {\n MutableRefObject,\n MouseEvent as ReactMouseEvent,\n TouchEvent as ReactTouchEvent,\n} from 'react';\nimport { useRef } from 'react';\n\nimport { getOwnerDocument } from '../utils';\n\nexport interface GestureHandlersState {\n target: null | EventTarget;\n x: number;\n xDelta: number;\n xDeltaPercent: number;\n xInitial: number;\n xPrev: number;\n xVelocity: number;\n y: number;\n yDelta: number;\n yDeltaPercent: number;\n yInitial: number;\n yPrev: number;\n yVelocity: number;\n startTime: number;\n down: boolean;\n scrollLocked: boolean;\n}\n\ntype SetStateFunc<S> = (\n state: (prevState: Readonly<S>) => S,\n callback?: () => void\n) => void;\n\nexport interface GestureHandlersReturn {\n onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;\n onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;\n}\n\nexport interface GestureHandlerOptions {\n ensureTargetIsContainer?: boolean;\n minTouchDelta?: number;\n}\n\nexport const initialGestureHandlersState: GestureHandlersState = {\n target: null,\n x: 0,\n xDelta: 0,\n xDeltaPercent: 0,\n xInitial: 0,\n xPrev: 0,\n xVelocity: 0,\n y: 0,\n yDelta: 0,\n yDeltaPercent: 0,\n yInitial: 0,\n yPrev: 0,\n yVelocity: 0,\n startTime: 0,\n down: false,\n scrollLocked: false,\n};\n\nconst FRAMERATE_CONST = 1000 / 60; // 60 fps\nconst VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;\n\nexport function gestureHandlers(\n set: SetStateFunc<GestureHandlersState>,\n containerRef?: MutableRefObject<HTMLElement | null>,\n options: GestureHandlerOptions = {}\n): GestureHandlersReturn {\n const { ensureTargetIsContainer = false, minTouchDelta = 0 } = options;\n\n // Common handlers\n const handleUp = () => {\n set((state: GestureHandlersState) => {\n const deltaTime = Date.now() - state.startTime;\n const xDelta = state.x - state.xInitial;\n const yDelta = state.y - state.yInitial;\n const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);\n const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);\n const newState: GestureHandlersState = {\n ...state,\n xVelocity,\n yVelocity,\n target: null,\n down: false,\n };\n\n return newState;\n });\n };\n\n const handleDown = (e: MouseEvent) => {\n const { target, pageX, pageY } = e;\n\n set((state: GestureHandlersState) => {\n const newState = {\n ...state,\n target,\n x: pageX,\n xDelta: 0,\n xDeltaPercent: 0,\n xVelocity: 0,\n xInitial: pageX,\n xPrev: pageX,\n y: pageY,\n yDelta: 0,\n yDeltaPercent: 0,\n yVelocity: 0,\n yInitial: pageY,\n yPrev: pageY,\n startTime: Date.now(),\n down: true,\n scrollLocked: false,\n };\n\n return newState;\n });\n };\n\n function calcVelocity(\n deltaSpace: number,\n deltaTime: number,\n prevVelocity: number\n ) {\n if (deltaTime < 1) {\n deltaTime = 1;\n }\n const speed = deltaSpace / deltaTime;\n const depr = 0.5 + Math.min(deltaTime / VELOCITY_DEPR_FACTOR, 0.5);\n return speed * depr + prevVelocity * (1 - depr);\n }\n\n function handleMove(e: MouseEvent) {\n const { pageX, pageY } = e;\n if (e.cancelable) {\n // prevent drag & drop behaviour from browser\n e.preventDefault && e.preventDefault();\n }\n\n set((state: GestureHandlersState) => {\n function getDeltaSum(\n currentPos: number,\n initialPos: number,\n prevPos: number\n ): number {\n if (\n state.scrollLocked ||\n Math.abs(currentPos - initialPos) >= minTouchDelta\n ) {\n state.scrollLocked = true;\n return currentPos - prevPos;\n }\n return 0;\n }\n\n const target =\n (containerRef && containerRef.current) || (e as any).target;\n\n const deltaTime = Date.now() - state.startTime;\n\n const width = target ? target.offsetWidth : NaN;\n const xDelta = state.xDelta + getDeltaSum(pageX, state.xInitial, state.x);\n const xDeltaPercent = (xDelta * 100) / width;\n const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);\n\n const height = target ? target.offsetHeight : NaN;\n const yDelta = state.yDelta + getDeltaSum(pageY, state.yInitial, state.y);\n const yDeltaPercent = (yDelta * 100) / height;\n const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);\n\n const newState = {\n ...state,\n xDelta,\n xDeltaPercent,\n x: pageX,\n xPrev: state.x,\n xVelocity,\n yDelta,\n yDeltaPercent,\n y: pageY,\n yPrev: state.y,\n yVelocity,\n };\n\n return newState;\n });\n }\n\n // Touch handlers\n\n /* eslint-disable @typescript-eslint/no-use-before-define */\n function handleTouchMove(e: TouchEvent) {\n if (e.cancelable) {\n // prevent drag & drop behaviour from browser\n e.preventDefault();\n }\n handleMove(e.touches.item(0) as any);\n }\n\n function handleTouchStart(e: ReactTouchEvent<HTMLElement>) {\n // making sure we're not dragging the element when more than one finger press the screen\n const { touches } = e;\n if (touches.length > 1) {\n return;\n }\n\n if (\n ensureTargetIsContainer &&\n containerRef &&\n e.target !== containerRef.current\n ) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const ownerDocument = getOwnerDocument(e.currentTarget)!;\n const ownerWindow = ownerDocument.defaultView || window;\n ownerWindow.addEventListener('touchmove', handleTouchMove, {\n passive: false,\n });\n ownerWindow.addEventListener('touchend', handleTouchEnd);\n ownerWindow.addEventListener('touchcancel', handleTouchEnd);\n handleDown(e.touches.item(0) as any);\n }\n\n function handleTouchEnd(this: Window) {\n this.removeEventListener('touchmove', handleTouchMove);\n this.removeEventListener('touchend', handleTouchEnd);\n this.removeEventListener('touchcancel', handleTouchEnd);\n handleUp();\n }\n\n // Mouse handlers\n function handleMouseDown(e: ReactMouseEvent<HTMLElement>) {\n if (\n ensureTargetIsContainer &&\n containerRef &&\n e.target !== containerRef.current\n ) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const ownerDocument = getOwnerDocument(e.currentTarget)!;\n const ownerWindow = ownerDocument.defaultView || window;\n if (e.button === 0) {\n ownerWindow.addEventListener('mousemove', handleMove);\n ownerWindow.addEventListener('mouseup', handleMouseUp);\n handleDown(e as any);\n }\n }\n\n function handleMouseUp(this: Window) {\n this.removeEventListener('mousemove', handleMove);\n this.removeEventListener('mouseup', handleMouseUp);\n handleUp();\n }\n /* eslint-enable @typescript-eslint/no-use-before-define */\n\n return {\n onMouseDown: handleMouseDown,\n onTouchStart: handleTouchStart,\n };\n}\n\nexport const useGestureHandlers = (\n containerRef: MutableRefObject<HTMLElement | null> | undefined,\n onGesture: (e: GestureHandlersState) => void,\n options: GestureHandlerOptions = {}\n) => {\n const state = useRef({ ...initialGestureHandlersState });\n\n const set = (\n cb: (prevState: GestureHandlersState) => GestureHandlersState\n ) => {\n state.current = cb(state.current);\n onGesture && onGesture(state.current);\n\n return state.current;\n };\n\n const handlers = gestureHandlers(set, containerRef, options);\n\n return { state: state.current, handlers };\n};\n"],"mappings":";AAKA,SAASA,MAAT,QAAuB,OAAvB;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAoCA,OAAO,IAAMC,2BAAiD,GAAG;EAC/DC,MAAM,EAAE,IADuD;EAE/DC,CAAC,EAAE,CAF4D;EAG/DC,MAAM,EAAE,CAHuD;EAI/DC,aAAa,EAAE,CAJgD;EAK/DC,QAAQ,EAAE,CALqD;EAM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AEH,eADR;IAELI,YAAY,EAAEf;EAFT,CAAP;AAID;AAED,OAAO,IAAMgB,kBAAkB,GAAG,SAArBA,kBAAqB,CAChCtD,YADgC,EAEhCuD,SAFgC,EAI7B;EAAA,IADHtD,OACG,uEAD8B,EAC9B;EACH,IAAMI,KAAK,GAAG5B,MAAM,cAAME,2BAAN,EAApB;;EAEA,IAAMoB,GAAG,GAAG,SAANA,GAAM,CACVyD,EADU,EAEP;IACHnD,KAAK,CAACwB,OAAN,GAAgB2B,EAAE,CAACnD,KAAK,CAACwB,OAAP,CAAlB;IACA0B,SAAS,IAAIA,SAAS,CAAClD,KAAK,CAACwB,OAAP,CAAtB;IAEA,OAAOxB,KAAK,CAACwB,OAAb;EACD,CAPD;;EASA,IAAM4B,QAAQ,GAAG3D,eAAe,CAACC,GAAD,EAAMC,YAAN,EAAoBC,OAApB,CAAhC;EAEA,OAAO;IAAEI,KAAK,EAAEA,KAAK,CAACwB,OAAf;IAAwB4B,QAAQ,EAARA;EAAxB,CAAP;AACD,CAnBM"}
|
|
1
|
+
{"version":3,"file":"useGestureHandlers.js","names":["useRef","getOwnerDocument","initialGestureHandlersState","target","x","xDelta","xDeltaPercent","xInitial","xPrev","xVelocity","y","yDelta","yDeltaPercent","yInitial","yPrev","yVelocity","startTime","down","scrollLocked","FRAMERATE_CONST","VELOCITY_DEPR_FACTOR","gestureHandlers","set","containerRef","options","ensureTargetIsContainer","minTouchDelta","handleUp","state","deltaTime","Date","now","calcVelocity","newState","handleDown","e","pageX","pageY","deltaSpace","prevVelocity","speed","depr","Math","min","handleMove","cancelable","preventDefault","getDeltaSum","currentPos","initialPos","prevPos","abs","current","width","offsetWidth","NaN","height","offsetHeight","handleTouchMove","touches","item","handleTouchStart","length","ownerDocument","currentTarget","ownerWindow","defaultView","window","addEventListener","passive","handleTouchEnd","removeEventListener","handleMouseDown","button","handleMouseUp","onMouseDown","onTouchStart","useGestureHandlers","onGesture","cb","handlers"],"sources":["../../../src/hooks/useGestureHandlers.ts"],"sourcesContent":["import type {\r\n MutableRefObject,\r\n MouseEvent as ReactMouseEvent,\r\n TouchEvent as ReactTouchEvent,\r\n} from 'react';\r\nimport { useRef } from 'react';\r\n\r\nimport { getOwnerDocument } from '../utils';\r\n\r\nexport interface GestureHandlersState {\r\n target: null | EventTarget;\r\n x: number;\r\n xDelta: number;\r\n xDeltaPercent: number;\r\n xInitial: number;\r\n xPrev: number;\r\n xVelocity: number;\r\n y: number;\r\n yDelta: number;\r\n yDeltaPercent: number;\r\n yInitial: number;\r\n yPrev: number;\r\n yVelocity: number;\r\n startTime: number;\r\n down: boolean;\r\n scrollLocked: boolean;\r\n}\r\n\r\ntype SetStateFunc<S> = (\r\n state: (prevState: Readonly<S>) => S,\r\n callback?: () => void\r\n) => void;\r\n\r\nexport interface GestureHandlersReturn {\r\n onMouseDown: (e: ReactMouseEvent<HTMLElement>) => void;\r\n onTouchStart: (e: ReactTouchEvent<HTMLElement>) => void;\r\n}\r\n\r\nexport interface GestureHandlerOptions {\r\n ensureTargetIsContainer?: boolean;\r\n minTouchDelta?: number;\r\n}\r\n\r\nexport const initialGestureHandlersState: GestureHandlersState = {\r\n target: null,\r\n x: 0,\r\n xDelta: 0,\r\n xDeltaPercent: 0,\r\n xInitial: 0,\r\n xPrev: 0,\r\n xVelocity: 0,\r\n y: 0,\r\n yDelta: 0,\r\n yDeltaPercent: 0,\r\n yInitial: 0,\r\n yPrev: 0,\r\n yVelocity: 0,\r\n startTime: 0,\r\n down: false,\r\n scrollLocked: false,\r\n};\r\n\r\nconst FRAMERATE_CONST = 1000 / 60; // 60 fps\r\nconst VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;\r\n\r\nexport function gestureHandlers(\r\n set: SetStateFunc<GestureHandlersState>,\r\n containerRef?: MutableRefObject<HTMLElement | null>,\r\n options: GestureHandlerOptions = {}\r\n): GestureHandlersReturn {\r\n const { ensureTargetIsContainer = false, minTouchDelta = 0 } = options;\r\n\r\n // Common handlers\r\n const handleUp = () => {\r\n set((state: GestureHandlersState) => {\r\n const deltaTime = Date.now() - state.startTime;\r\n const xDelta = state.x - state.xInitial;\r\n const yDelta = state.y - state.yInitial;\r\n const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);\r\n const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);\r\n const newState: GestureHandlersState = {\r\n ...state,\r\n xVelocity,\r\n yVelocity,\r\n target: null,\r\n down: false,\r\n };\r\n\r\n return newState;\r\n });\r\n };\r\n\r\n const handleDown = (e: MouseEvent) => {\r\n const { target, pageX, pageY } = e;\r\n\r\n set((state: GestureHandlersState) => {\r\n const newState = {\r\n ...state,\r\n target,\r\n x: pageX,\r\n xDelta: 0,\r\n xDeltaPercent: 0,\r\n xVelocity: 0,\r\n xInitial: pageX,\r\n xPrev: pageX,\r\n y: pageY,\r\n yDelta: 0,\r\n yDeltaPercent: 0,\r\n yVelocity: 0,\r\n yInitial: pageY,\r\n yPrev: pageY,\r\n startTime: Date.now(),\r\n down: true,\r\n scrollLocked: false,\r\n };\r\n\r\n return newState;\r\n });\r\n };\r\n\r\n function calcVelocity(\r\n deltaSpace: number,\r\n deltaTime: number,\r\n prevVelocity: number\r\n ) {\r\n if (deltaTime < 1) {\r\n deltaTime = 1;\r\n }\r\n const speed = deltaSpace / deltaTime;\r\n const depr = 0.5 + Math.min(deltaTime / VELOCITY_DEPR_FACTOR, 0.5);\r\n return speed * depr + prevVelocity * (1 - depr);\r\n }\r\n\r\n function handleMove(e: MouseEvent) {\r\n const { pageX, pageY } = e;\r\n if (e.cancelable) {\r\n // prevent drag & drop behaviour from browser\r\n e.preventDefault && e.preventDefault();\r\n }\r\n\r\n set((state: GestureHandlersState) => {\r\n function getDeltaSum(\r\n currentPos: number,\r\n initialPos: number,\r\n prevPos: number\r\n ): number {\r\n if (\r\n state.scrollLocked ||\r\n Math.abs(currentPos - initialPos) >= minTouchDelta\r\n ) {\r\n state.scrollLocked = true;\r\n return currentPos - prevPos;\r\n }\r\n return 0;\r\n }\r\n\r\n const target =\r\n (containerRef && containerRef.current) || (e as any).target;\r\n\r\n const deltaTime = Date.now() - state.startTime;\r\n\r\n const width = target ? target.offsetWidth : NaN;\r\n const xDelta = state.xDelta + getDeltaSum(pageX, state.xInitial, state.x);\r\n const xDeltaPercent = (xDelta * 100) / width;\r\n const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);\r\n\r\n const height = target ? target.offsetHeight : NaN;\r\n const yDelta = state.yDelta + getDeltaSum(pageY, state.yInitial, state.y);\r\n const yDeltaPercent = (yDelta * 100) / height;\r\n const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);\r\n\r\n const newState = {\r\n ...state,\r\n xDelta,\r\n xDeltaPercent,\r\n x: pageX,\r\n xPrev: state.x,\r\n xVelocity,\r\n yDelta,\r\n yDeltaPercent,\r\n y: pageY,\r\n yPrev: state.y,\r\n yVelocity,\r\n };\r\n\r\n return newState;\r\n });\r\n }\r\n\r\n // Touch handlers\r\n\r\n /* eslint-disable @typescript-eslint/no-use-before-define */\r\n function handleTouchMove(e: TouchEvent) {\r\n if (e.cancelable) {\r\n // prevent drag & drop behaviour from browser\r\n e.preventDefault();\r\n }\r\n handleMove(e.touches.item(0) as any);\r\n }\r\n\r\n function handleTouchStart(e: ReactTouchEvent<HTMLElement>) {\r\n // making sure we're not dragging the element when more than one finger press the screen\r\n const { touches } = e;\r\n if (touches.length > 1) {\r\n return;\r\n }\r\n\r\n if (\r\n ensureTargetIsContainer &&\r\n containerRef &&\r\n e.target !== containerRef.current\r\n ) {\r\n return;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n const ownerDocument = getOwnerDocument(e.currentTarget)!;\r\n const ownerWindow = ownerDocument.defaultView || window;\r\n ownerWindow.addEventListener('touchmove', handleTouchMove, {\r\n passive: false,\r\n });\r\n ownerWindow.addEventListener('touchend', handleTouchEnd);\r\n ownerWindow.addEventListener('touchcancel', handleTouchEnd);\r\n handleDown(e.touches.item(0) as any);\r\n }\r\n\r\n function handleTouchEnd(this: Window) {\r\n this.removeEventListener('touchmove', handleTouchMove);\r\n this.removeEventListener('touchend', handleTouchEnd);\r\n this.removeEventListener('touchcancel', handleTouchEnd);\r\n handleUp();\r\n }\r\n\r\n // Mouse handlers\r\n function handleMouseDown(e: ReactMouseEvent<HTMLElement>) {\r\n if (\r\n ensureTargetIsContainer &&\r\n containerRef &&\r\n e.target !== containerRef.current\r\n ) {\r\n return;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n const ownerDocument = getOwnerDocument(e.currentTarget)!;\r\n const ownerWindow = ownerDocument.defaultView || window;\r\n if (e.button === 0) {\r\n ownerWindow.addEventListener('mousemove', handleMove);\r\n ownerWindow.addEventListener('mouseup', handleMouseUp);\r\n handleDown(e as any);\r\n }\r\n }\r\n\r\n function handleMouseUp(this: Window) {\r\n this.removeEventListener('mousemove', handleMove);\r\n this.removeEventListener('mouseup', handleMouseUp);\r\n handleUp();\r\n }\r\n /* eslint-enable @typescript-eslint/no-use-before-define */\r\n\r\n return {\r\n onMouseDown: handleMouseDown,\r\n onTouchStart: handleTouchStart,\r\n };\r\n}\r\n\r\nexport const useGestureHandlers = (\r\n containerRef: MutableRefObject<HTMLElement | null> | undefined,\r\n onGesture: (e: GestureHandlersState) => void,\r\n options: GestureHandlerOptions = {}\r\n) => {\r\n const state = useRef({ ...initialGestureHandlersState });\r\n\r\n const set = (\r\n cb: (prevState: GestureHandlersState) => GestureHandlersState\r\n ) => {\r\n state.current = cb(state.current);\r\n onGesture && onGesture(state.current);\r\n\r\n return state.current;\r\n };\r\n\r\n const handlers = gestureHandlers(set, containerRef, options);\r\n\r\n return { state: state.current, handlers };\r\n};\r\n"],"mappings":";AAKA,SAASA,MAAT,QAAuB,OAAvB;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAoCA,OAAO,IAAMC,2BAAiD,GAAG;EAC/DC,MAAM,EAAE,IADuD;EAE/DC,CAAC,EAAE,CA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,mBAAL,CAAyB,SAAzB,EAAoCG,aAApC;IACA/C,QAAQ;EACT;EACD;;;EAEA,OAAO;IACLgD,WAAW,EAAEH,eADR;IAELI,YAAY,EAAEf;EAFT,CAAP;AAID;AAED,OAAO,IAAMgB,kBAAkB,GAAG,SAArBA,kBAAqB,CAChCtD,YADgC,EAEhCuD,SAFgC,EAI7B;EAAA,IADHtD,OACG,uEAD8B,EAC9B;EACH,IAAMI,KAAK,GAAG5B,MAAM,cAAME,2BAAN,EAApB;;EAEA,IAAMoB,GAAG,GAAG,SAANA,GAAM,CACVyD,EADU,EAEP;IACHnD,KAAK,CAACwB,OAAN,GAAgB2B,EAAE,CAACnD,KAAK,CAACwB,OAAP,CAAlB;IACA0B,SAAS,IAAIA,SAAS,CAAClD,KAAK,CAACwB,OAAP,CAAtB;IAEA,OAAOxB,KAAK,CAACwB,OAAb;EACD,CAPD;;EASA,IAAM4B,QAAQ,GAAG3D,eAAe,CAACC,GAAD,EAAMC,YAAN,EAAoBC,OAApB,CAAhC;EAEA,OAAO;IAAEI,KAAK,EAAEA,KAAK,CAACwB,OAAf;IAAwB4B,QAAQ,EAARA;EAAxB,CAAP;AACD,CAnBM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MutableRefObject } from 'react';
|
|
2
|
-
export declare function useMeasure(ref: MutableRefObject<HTMLElement | null>): {
|
|
3
|
-
left: number;
|
|
4
|
-
top: number;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
};
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
export declare function useMeasure(ref: MutableRefObject<HTMLElement | null>): {
|
|
3
|
+
left: number;
|
|
4
|
+
top: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMeasure.js","names":["useRef","useState","useEffect","useMeasure","ref","ro","left","top","width","height","bounds","setBounds","current","ResizeObserver","entries","entry","contentRect","observe","disconnect"],"sources":["../../../src/hooks/useMeasure.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useRef, useState, useEffect } from 'react';\n\nexport function useMeasure(ref: MutableRefObject<HTMLElement | null>) {\n const ro = useRef<ResizeObserver | null>(null);\n const [bounds, setBounds] = useState({\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n });\n\n useEffect(() => {\n if (ro.current === null) {\n ro.current = new ResizeObserver((entries: any) => {\n const entry = entries[0];\n setBounds(entry.contentRect);\n });\n }\n\n if (ref.current) {\n ro.current.observe(ref.current);\n }\n\n return () => {\n if (ro.current) {\n ro.current.disconnect();\n }\n };\n }, [ref]);\n\n return bounds;\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,EAA2BC,SAA3B,QAA4C,OAA5C;AAEA,OAAO,SAASC,UAAT,CAAoBC,GAApB,EAA+D;EACpE,IAAMC,EAAE,GAAGL,MAAM,CAAwB,IAAxB,CAAjB;;EACA,gBAA4BC,QAAQ,CAAC;IACnCK,IAAI,EAAE,CAD6B;IAEnCC,GAAG,EAAE,CAF8B;IAGnCC,KAAK,EAAE,CAH4B;IAInCC,MAAM,EAAE;EAJ2B,CAAD,CAApC;EAAA;EAAA,IAAOC,MAAP;EAAA,IAAeC,SAAf;;EAOAT,SAAS,CAAC,YAAM;IACd,IAAIG,EAAE,CAACO,OAAH,KAAe,IAAnB,EAAyB;MACvBP,EAAE,CAACO,OAAH,GAAa,IAAIC,cAAJ,CAAmB,UAACC,OAAD,EAAkB;QAChD,IAAMC,KAAK,GAAGD,OAAO,CAAC,CAAD,CAArB;QACAH,SAAS,CAACI,KAAK,CAACC,WAAP,CAAT;MACD,CAHY,CAAb;IAID;;IAED,IAAIZ,GAAG,CAACQ,OAAR,EAAiB;MACfP,EAAE,CAACO,OAAH,CAAWK,OAAX,CAAmBb,GAAG,CAACQ,OAAvB;IACD;;IAED,OAAO,YAAM;MACX,IAAIP,EAAE,CAACO,OAAP,EAAgB;QACdP,EAAE,CAACO,OAAH,CAAWM,UAAX;MACD;IACF,CAJD;EAKD,CAjBQ,EAiBN,CAACd,GAAD,CAjBM,CAAT;EAmBA,OAAOM,MAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"useMeasure.js","names":["useRef","useState","useEffect","useMeasure","ref","ro","left","top","width","height","bounds","setBounds","current","ResizeObserver","entries","entry","contentRect","observe","disconnect"],"sources":["../../../src/hooks/useMeasure.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { useRef, useState, useEffect } from 'react';\r\n\r\nexport function useMeasure(ref: MutableRefObject<HTMLElement | null>) {\r\n const ro = useRef<ResizeObserver | null>(null);\r\n const [bounds, setBounds] = useState({\r\n left: 0,\r\n top: 0,\r\n width: 0,\r\n height: 0,\r\n });\r\n\r\n useEffect(() => {\r\n if (ro.current === null) {\r\n ro.current = new ResizeObserver((entries: any) => {\r\n const entry = entries[0];\r\n setBounds(entry.contentRect);\r\n });\r\n }\r\n\r\n if (ref.current) {\r\n ro.current.observe(ref.current);\r\n }\r\n\r\n return () => {\r\n if (ro.current) {\r\n ro.current.disconnect();\r\n }\r\n };\r\n }, [ref]);\r\n\r\n return bounds;\r\n}\r\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,EAA2BC,SAA3B,QAA4C,OAA5C;AAEA,OAAO,SAASC,UAAT,CAAoBC,GAApB,EAA+D;EACpE,IAAMC,EAAE,GAAGL,MAAM,CAAwB,IAAxB,CAAjB;;EACA,gBAA4BC,QAAQ,CAAC;IACnCK,IAAI,EAAE,CAD6B;IAEnCC,GAAG,EAAE,CAF8B;IAGnCC,KAAK,EAAE,CAH4B;IAInCC,MAAM,EAAE;EAJ2B,CAAD,CAApC;EAAA;EAAA,IAAOC,MAAP;EAAA,IAAeC,SAAf;;EAOAT,SAAS,CAAC,YAAM;IACd,IAAIG,EAAE,CAACO,OAAH,KAAe,IAAnB,EAAyB;MACvBP,EAAE,CAACO,OAAH,GAAa,IAAIC,cAAJ,CAAmB,UAACC,OAAD,EAAkB;QAChD,IAAMC,KAAK,GAAGD,OAAO,CAAC,CAAD,CAArB;QACAH,SAAS,CAACI,KAAK,CAACC,WAAP,CAAT;MACD,CAHY,CAAb;IAID;;IAED,IAAIZ,GAAG,CAACQ,OAAR,EAAiB;MACfP,EAAE,CAACO,OAAH,CAAWK,OAAX,CAAmBb,GAAG,CAACQ,OAAvB;IACD;;IAED,OAAO,YAAM;MACX,IAAIP,EAAE,CAACO,OAAP,EAAgB;QACdP,EAAE,CAACO,OAAH,CAAWM,UAAX;MACD;IACF,CAJD;EAKD,CAjBQ,EAiBN,CAACd,GAAD,CAjBM,CAAT;EAmBA,OAAOM,MAAP;AACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RefObject } from 'react';
|
|
2
|
-
export declare function useOnClickOutside(ref: RefObject<any>, handler: (e: PointerEvent) => void, active?: boolean): void;
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export declare function useOnClickOutside(ref: RefObject<any>, handler: (e: PointerEvent) => void, active?: boolean): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnClickOutside.js","names":["useEffect","useCallback","useOnClickOutside","ref","handler","active","listener","event","current","contains","target","document","addEventListener","removeEventListener"],"sources":["../../../src/hooks/useOnClickOutside.ts"],"sourcesContent":["import type { RefObject } from 'react';\nimport { useEffect, useCallback } from 'react';\n\nexport function useOnClickOutside(\n ref: RefObject<any>,\n handler: (e: PointerEvent) => void,\n active = true\n) {\n const listener = useCallback(\n (event: PointerEvent) => {\n // Do nothing if clicking ref's element or descendent elements\n if (!ref.current || ref.current.contains(event.target)) {\n return;\n }\n\n handler && handler(event);\n },\n [ref, handler]\n );\n\n useEffect(() => {\n if (active) {\n document.addEventListener('pointerup', listener);\n\n return () => {\n document.removeEventListener('pointerup', listener);\n };\n }\n\n return;\n }, [listener, active]);\n}\n"],"mappings":"AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,OAAvC;AAEA,OAAO,SAASC,iBAAT,CACLC,GADK,EAELC,OAFK,EAIL;EAAA,IADAC,MACA,uEADS,IACT;EACA,IAAMC,QAAQ,GAAGL,WAAW,CAC1B,UAACM,KAAD,EAAyB;IACvB;IACA,IAAI,CAACJ,GAAG,CAACK,OAAL,IAAgBL,GAAG,CAACK,OAAJ,CAAYC,QAAZ,CAAqBF,KAAK,CAACG,MAA3B,CAApB,EAAwD;MACtD;IACD;;IAEDN,OAAO,IAAIA,OAAO,CAACG,KAAD,CAAlB;EACD,CARyB,EAS1B,CAACJ,GAAD,EAAMC,OAAN,CAT0B,CAA5B;EAYAJ,SAAS,CAAC,YAAM;IACd,IAAIK,MAAJ,EAAY;MACVM,QAAQ,CAACC,gBAAT,CAA0B,WAA1B,EAAuCN,QAAvC;MAEA,OAAO,YAAM;QACXK,QAAQ,CAACE,mBAAT,CAA6B,WAA7B,EAA0CP,QAA1C;MACD,CAFD;IAGD;;IAED;EACD,CAVQ,EAUN,CAACA,QAAD,EAAWD,MAAX,CAVM,CAAT;AAWD"}
|
|
1
|
+
{"version":3,"file":"useOnClickOutside.js","names":["useEffect","useCallback","useOnClickOutside","ref","handler","active","listener","event","current","contains","target","document","addEventListener","removeEventListener"],"sources":["../../../src/hooks/useOnClickOutside.ts"],"sourcesContent":["import type { RefObject } from 'react';\r\nimport { useEffect, useCallback } from 'react';\r\n\r\nexport function useOnClickOutside(\r\n ref: RefObject<any>,\r\n handler: (e: PointerEvent) => void,\r\n active = true\r\n) {\r\n const listener = useCallback(\r\n (event: PointerEvent) => {\r\n // Do nothing if clicking ref's element or descendent elements\r\n if (!ref.current || ref.current.contains(event.target)) {\r\n return;\r\n }\r\n\r\n handler && handler(event);\r\n },\r\n [ref, handler]\r\n );\r\n\r\n useEffect(() => {\r\n if (active) {\r\n document.addEventListener('pointerup', listener);\r\n\r\n return () => {\r\n document.removeEventListener('pointerup', listener);\r\n };\r\n }\r\n\r\n return;\r\n }, [listener, active]);\r\n}\r\n"],"mappings":"AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,OAAvC;AAEA,OAAO,SAASC,iBAAT,CACLC,GADK,EAELC,OAFK,EAIL;EAAA,IADAC,MACA,uEADS,IACT;EACA,IAAMC,QAAQ,GAAGL,WAAW,CAC1B,UAACM,KAAD,EAAyB;IACvB;IACA,IAAI,CAACJ,GAAG,CAACK,OAAL,IAAgBL,GAAG,CAACK,OAAJ,CAAYC,QAAZ,CAAqBF,KAAK,CAACG,MAA3B,CAApB,EAAwD;MACtD;IACD;;IAEDN,OAAO,IAAIA,OAAO,CAACG,KAAD,CAAlB;EACD,CARyB,EAS1B,CAACJ,GAAD,EAAMC,OAAN,CAT0B,CAA5B;EAYAJ,SAAS,CAAC,YAAM;IACd,IAAIK,MAAJ,EAAY;MACVM,QAAQ,CAACC,gBAAT,CAA0B,WAA1B,EAAuCN,QAAvC;MAEA,OAAO,YAAM;QACXK,QAAQ,CAACE,mBAAT,CAA6B,WAA7B,EAA0CP,QAA1C;MACD,CAFD;IAGD;;IAED;EACD,CAVQ,EAUN,CAACA,QAAD,EAAWD,MAAX,CAVM,CAAT;AAWD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useOnKeyDown(ownerWindow: Window, handler: (e: KeyboardEvent) => void, active?: boolean): void;
|
|
1
|
+
export declare function useOnKeyDown(ownerWindow: Window, handler: (e: KeyboardEvent) => void, active?: boolean): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnKeyDown.js","names":["useEffect","useOnKeyDown","ownerWindow","handler","active","addEventListener","removeEventListener"],"sources":["../../../src/hooks/useOnKeyDown.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useOnKeyDown(\n ownerWindow: Window,\n handler: (e: KeyboardEvent) => void,\n active = true\n) {\n useEffect(() => {\n if (active) {\n ownerWindow.addEventListener('keydown', handler);\n\n return () => {\n ownerWindow.removeEventListener('keydown', handler);\n };\n }\n\n return;\n }, [ownerWindow, active, handler]);\n}\n"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAO,SAASC,YAAT,CACLC,WADK,EAELC,OAFK,EAIL;EAAA,IADAC,MACA,uEADS,IACT;EACAJ,SAAS,CAAC,YAAM;IACd,IAAII,MAAJ,EAAY;MACVF,WAAW,CAACG,gBAAZ,CAA6B,SAA7B,EAAwCF,OAAxC;MAEA,OAAO,YAAM;QACXD,WAAW,CAACI,mBAAZ,CAAgC,SAAhC,EAA2CH,OAA3C;MACD,CAFD;IAGD;;IAED;EACD,CAVQ,EAUN,CAACD,WAAD,EAAcE,MAAd,EAAsBD,OAAtB,CAVM,CAAT;AAWD"}
|
|
1
|
+
{"version":3,"file":"useOnKeyDown.js","names":["useEffect","useOnKeyDown","ownerWindow","handler","active","addEventListener","removeEventListener"],"sources":["../../../src/hooks/useOnKeyDown.ts"],"sourcesContent":["import { useEffect } from 'react';\r\n\r\nexport function useOnKeyDown(\r\n ownerWindow: Window,\r\n handler: (e: KeyboardEvent) => void,\r\n active = true\r\n) {\r\n useEffect(() => {\r\n if (active) {\r\n ownerWindow.addEventListener('keydown', handler);\r\n\r\n return () => {\r\n ownerWindow.removeEventListener('keydown', handler);\r\n };\r\n }\r\n\r\n return;\r\n }, [ownerWindow, active, handler]);\r\n}\r\n"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAO,SAASC,YAAT,CACLC,WADK,EAELC,OAFK,EAIL;EAAA,IADAC,MACA,uEADS,IACT;EACAJ,SAAS,CAAC,YAAM;IACd,IAAII,MAAJ,EAAY;MACVF,WAAW,CAACG,gBAAZ,CAA6B,SAA7B,EAAwCF,OAAxC;MAEA,OAAO,YAAM;QACXD,WAAW,CAACI,mBAAZ,CAAgC,SAAhC,EAA2CH,OAA3C;MACD,CAFD;IAGD;;IAED;EACD,CAVQ,EAUN,CAACD,WAAD,EAAcE,MAAd,EAAsBD,OAAtB,CAVM,CAAT;AAWD"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { Reducer } from 'react';
|
|
2
|
-
export interface StateChart<STypes extends string, ATypes extends string> {
|
|
3
|
-
initial: STypes;
|
|
4
|
-
states: {
|
|
5
|
-
[state in STypes]?: {
|
|
6
|
-
enter?: (prevState: STypes, payload: any) => void;
|
|
7
|
-
leave?: (nextState: STypes, payload: any) => void;
|
|
8
|
-
on: {
|
|
9
|
-
[action in ATypes]?: STypes;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export interface StateMachineState<STypes, ATypes> {
|
|
15
|
-
state: STypes;
|
|
16
|
-
lastActionType: ATypes;
|
|
17
|
-
}
|
|
18
|
-
export interface StateMachineAction<STypes, ATypes> {
|
|
19
|
-
type: ATypes;
|
|
20
|
-
nextState: STypes;
|
|
21
|
-
}
|
|
22
|
-
declare type TransitionType<ATypes extends string> = (action: ATypes, payload: any) => void;
|
|
23
|
-
export declare function useReducerMachine<S extends StateMachineState<STypes, ATypes>, A extends StateMachineAction<STypes, ATypes>, STypes extends string, ATypes extends string>(chart: StateChart<STypes, ATypes>, reducer: Reducer<S, A>, initialData: S): [STypes, Omit<S, 'state'>, TransitionType<ATypes>];
|
|
24
|
-
export {};
|
|
1
|
+
import type { Reducer } from 'react';
|
|
2
|
+
export interface StateChart<STypes extends string, ATypes extends string> {
|
|
3
|
+
initial: STypes;
|
|
4
|
+
states: {
|
|
5
|
+
[state in STypes]?: {
|
|
6
|
+
enter?: (prevState: STypes, payload: any) => void;
|
|
7
|
+
leave?: (nextState: STypes, payload: any) => void;
|
|
8
|
+
on: {
|
|
9
|
+
[action in ATypes]?: STypes;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface StateMachineState<STypes, ATypes> {
|
|
15
|
+
state: STypes;
|
|
16
|
+
lastActionType: ATypes;
|
|
17
|
+
}
|
|
18
|
+
export interface StateMachineAction<STypes, ATypes> {
|
|
19
|
+
type: ATypes;
|
|
20
|
+
nextState: STypes;
|
|
21
|
+
}
|
|
22
|
+
declare type TransitionType<ATypes extends string> = (action: ATypes, payload: any) => void;
|
|
23
|
+
export declare function useReducerMachine<S extends StateMachineState<STypes, ATypes>, A extends StateMachineAction<STypes, ATypes>, STypes extends string, ATypes extends string>(chart: StateChart<STypes, ATypes>, reducer: Reducer<S, A>, initialData: S): [STypes, Omit<S, 'state'>, TransitionType<ATypes>];
|
|
24
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReducerMachine.js","names":["useReducer","useReducerMachine","chart","reducer","initialData","reducerState","dispatch","state","data","transition","action","payload","currentState","states","Error","nextState","on","type"],"sources":["../../../src/hooks/useReducerMachine.ts"],"sourcesContent":["import type { Reducer } from 'react';\nimport { useReducer } from 'react';\n\nexport interface StateChart<STypes extends string, ATypes extends string> {\n initial: STypes;\n states: {\n [state in STypes]?: {\n enter?: (prevState: STypes, payload: any) => void;\n leave?: (nextState: STypes, payload: any) => void;\n on: { [action in ATypes]?: STypes };\n };\n };\n}\n\nexport interface StateMachineState<STypes, ATypes> {\n state: STypes;\n lastActionType: ATypes;\n}\n\nexport interface StateMachineAction<STypes, ATypes> {\n type: ATypes;\n nextState: STypes;\n}\n\ntype TransitionType<ATypes extends string> = (\n action: ATypes,\n payload: any\n) => void;\n\n// This manages transitions between states with a built in reducer to manage\n// the data that goes with those transitions.\nexport function useReducerMachine<\n S extends StateMachineState<STypes, ATypes>,\n A extends StateMachineAction<STypes, ATypes>,\n STypes extends string,\n ATypes extends string\n>(\n chart: StateChart<STypes, ATypes>,\n reducer: Reducer<S, A>,\n initialData: S\n): [STypes, Omit<S, 'state'>, TransitionType<ATypes>] {\n const [reducerState, dispatch] = useReducer(reducer, initialData);\n const { state, ...data } = reducerState;\n\n const transition: TransitionType<ATypes> = (action, payload = {}) => {\n const currentState = chart.states[state];\n if (!currentState) {\n throw new Error(`Unknown currentState \"${state}\"`);\n }\n\n const nextState: STypes | undefined = currentState.on[action];\n if (!nextState) {\n throw new Error(`Unknown action \"${action}\" for state \"${state}\"`);\n }\n\n dispatch({ type: action, nextState, ...payload } as any);\n };\n\n return [state, data, transition];\n}\n"],"mappings":";;;;AACA,SAASA,UAAT,QAA2B,OAA3B;AA4BA;AACA;AACA,OAAO,SAASC,iBAAT,CAMLC,KANK,EAOLC,OAPK,EAQLC,WARK,EAS+C;EACpD,kBAAiCJ,UAAU,CAACG,OAAD,EAAUC,WAAV,CAA3C;EAAA;EAAA,IAAOC,YAAP;EAAA,IAAqBC,QAArB;;EACA,IAAQC,KAAR,GAA2BF,YAA3B,CAAQE,KAAR;EAAA,IAAkBC,IAAlB,4BAA2BH,YAA3B;;EAEA,IAAMI,UAAkC,GAAG,SAArCA,UAAqC,CAACC,MAAD,EAA0B;IAAA,IAAjBC,OAAiB,uEAAP,EAAO;IACnE,IAAMC,YAAY,GAAGV,KAAK,CAACW,MAAN,CAAaN,KAAb,CAArB;;IACA,IAAI,CAACK,YAAL,EAAmB;MACjB,MAAM,IAAIE,KAAJ,kCAAmCP,KAAnC,QAAN;IACD;;IAED,IAAMQ,SAA6B,GAAGH,YAAY,CAACI,EAAb,CAAgBN,MAAhB,CAAtC;;IACA,IAAI,CAACK,SAAL,EAAgB;MACd,MAAM,IAAID,KAAJ,4BAA6BJ,MAA7B,4BAAmDH,KAAnD,QAAN;IACD;;IAEDD,QAAQ;MAAGW,IAAI,EAAEP,MAAT;MAAiBK,SAAS,EAATA;IAAjB,GAA+BJ,OAA/B,EAAR;EACD,CAZD;;EAcA,OAAO,CAACJ,KAAD,EAAQC,IAAR,EAAcC,UAAd,CAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"useReducerMachine.js","names":["useReducer","useReducerMachine","chart","reducer","initialData","reducerState","dispatch","state","data","transition","action","payload","currentState","states","Error","nextState","on","type"],"sources":["../../../src/hooks/useReducerMachine.ts"],"sourcesContent":["import type { Reducer } from 'react';\r\nimport { useReducer } from 'react';\r\n\r\nexport interface StateChart<STypes extends string, ATypes extends string> {\r\n initial: STypes;\r\n states: {\r\n [state in STypes]?: {\r\n enter?: (prevState: STypes, payload: any) => void;\r\n leave?: (nextState: STypes, payload: any) => void;\r\n on: { [action in ATypes]?: STypes };\r\n };\r\n };\r\n}\r\n\r\nexport interface StateMachineState<STypes, ATypes> {\r\n state: STypes;\r\n lastActionType: ATypes;\r\n}\r\n\r\nexport interface StateMachineAction<STypes, ATypes> {\r\n type: ATypes;\r\n nextState: STypes;\r\n}\r\n\r\ntype TransitionType<ATypes extends string> = (\r\n action: ATypes,\r\n payload: any\r\n) => void;\r\n\r\n// This manages transitions between states with a built in reducer to manage\r\n// the data that goes with those transitions.\r\nexport function useReducerMachine<\r\n S extends StateMachineState<STypes, ATypes>,\r\n A extends StateMachineAction<STypes, ATypes>,\r\n STypes extends string,\r\n ATypes extends string\r\n>(\r\n chart: StateChart<STypes, ATypes>,\r\n reducer: Reducer<S, A>,\r\n initialData: S\r\n): [STypes, Omit<S, 'state'>, TransitionType<ATypes>] {\r\n const [reducerState, dispatch] = useReducer(reducer, initialData);\r\n const { state, ...data } = reducerState;\r\n\r\n const transition: TransitionType<ATypes> = (action, payload = {}) => {\r\n const currentState = chart.states[state];\r\n if (!currentState) {\r\n throw new Error(`Unknown currentState \"${state}\"`);\r\n }\r\n\r\n const nextState: STypes | undefined = currentState.on[action];\r\n if (!nextState) {\r\n throw new Error(`Unknown action \"${action}\" for state \"${state}\"`);\r\n }\r\n\r\n dispatch({ type: action, nextState, ...payload } as any);\r\n };\r\n\r\n return [state, data, transition];\r\n}\r\n"],"mappings":";;;;AACA,SAASA,UAAT,QAA2B,OAA3B;AA4BA;AACA;AACA,OAAO,SAASC,iBAAT,CAMLC,KANK,EAOLC,OAPK,EAQLC,WARK,EAS+C;EACpD,kBAAiCJ,UAAU,CAACG,OAAD,EAAUC,WAAV,CAA3C;EAAA;EAAA,IAAOC,YAAP;EAAA,IAAqBC,QAArB;;EACA,IAAQC,KAAR,GAA2BF,YAA3B,CAAQE,KAAR;EAAA,IAAkBC,IAAlB,4BAA2BH,YAA3B;;EAEA,IAAMI,UAAkC,GAAG,SAArCA,UAAqC,CAACC,MAAD,EAA0B;IAAA,IAAjBC,OAAiB,uEAAP,EAAO;IACnE,IAAMC,YAAY,GAAGV,KAAK,CAACW,MAAN,CAAaN,KAAb,CAArB;;IACA,IAAI,CAACK,YAAL,EAAmB;MACjB,MAAM,IAAIE,KAAJ,kCAAmCP,KAAnC,QAAN;IACD;;IAED,IAAMQ,SAA6B,GAAGH,YAAY,CAACI,EAAb,CAAgBN,MAAhB,CAAtC;;IACA,IAAI,CAACK,SAAL,EAAgB;MACd,MAAM,IAAID,KAAJ,4BAA6BJ,MAA7B,4BAAmDH,KAAnD,QAAN;IACD;;IAEDD,QAAQ;MAAGW,IAAI,EAAEP,MAAT;MAAiBK,SAAS,EAATA;IAAjB,GAA+BJ,OAA/B,EAAR;EACD,CAZD;;EAcA,OAAO,CAACJ,KAAD,EAAQC,IAAR,EAAcC,UAAd,CAAP;AACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RefObject } from 'react';
|
|
2
|
-
export declare function useRemoveBodyScroll(open: boolean, elementRef: RefObject<HTMLElement | null>): void;
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export declare function useRemoveBodyScroll(open: boolean, elementRef: RefObject<HTMLElement | null>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoveBodyScroll.js","names":["useEffect","getOwnerDocument","scrollBodyCount","useRemoveBodyScroll","open","elementRef","current","ownerDocument","ownerWindow","defaultView","window","scrollBarWidth","innerWidth","body","clientWidth","style","overflow","marginRight"],"sources":["../../../src/hooks/useRemoveBodyScroll.ts"],"sourcesContent":["import type { RefObject } from 'react';\nimport { useEffect } from 'react';\n\nimport { getOwnerDocument } from '../utils';\n\nlet scrollBodyCount = 0;\nexport function useRemoveBodyScroll(\n open: boolean,\n elementRef: RefObject<HTMLElement | null>\n) {\n useEffect(() => {\n if (open && elementRef.current) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const ownerDocument = getOwnerDocument(elementRef.current)!;\n const ownerWindow = ownerDocument.defaultView || window;\n scrollBodyCount += 1;\n\n // calculate scrollbar width if mounting the first scroll lock\n let scrollBarWidth = 0;\n if (scrollBodyCount === 1) {\n scrollBarWidth =\n ownerWindow.innerWidth - ownerDocument.body.clientWidth;\n }\n\n ownerDocument.body.style.overflow = 'hidden';\n if (scrollBarWidth > 0) {\n ownerDocument.body.style.marginRight = `${scrollBarWidth}px`;\n }\n\n return () => {\n scrollBodyCount -= 1;\n if (scrollBodyCount === 0) {\n ownerDocument.body.style.overflow = '';\n ownerDocument.body.style.marginRight = '';\n }\n };\n }\n }, [elementRef, open]);\n}\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAEA,IAAIC,eAAe,GAAG,CAAtB;AACA,OAAO,SAASC,mBAAT,CACLC,IADK,EAELC,UAFK,EAGL;EACAL,SAAS,CAAC,YAAM;IACd,IAAII,IAAI,IAAIC,UAAU,CAACC,OAAvB,EAAgC;MAC9B;MACA,IAAMC,aAAa,GAAGN,gBAAgB,CAACI,UAAU,CAACC,OAAZ,CAAtC;MACA,IAAME,WAAW,GAAGD,aAAa,CAACE,WAAd,IAA6BC,MAAjD;MACAR,eAAe,IAAI,CAAnB,CAJ8B,CAM9B;;MACA,IAAIS,cAAc,GAAG,CAArB;;MACA,IAAIT,eAAe,KAAK,CAAxB,EAA2B;QACzBS,cAAc,GACZH,WAAW,CAACI,UAAZ,GAAyBL,aAAa,CAACM,IAAd,CAAmBC,WAD9C;MAED;;MAEDP,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBC,QAAzB,GAAoC,QAApC;;MACA,IAAIL,cAAc,GAAG,CAArB,EAAwB;QACtBJ,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBE,WAAzB,aAA0CN,cAA1C;MACD;;MAED,OAAO,YAAM;QACXT,eAAe,IAAI,CAAnB;;QACA,IAAIA,eAAe,KAAK,CAAxB,EAA2B;UACzBK,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBC,QAAzB,GAAoC,EAApC;UACAT,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBE,WAAzB,GAAuC,EAAvC;QACD;MACF,CAND;IAOD;EACF,CA3BQ,EA2BN,CAACZ,UAAD,EAAaD,IAAb,CA3BM,CAAT;AA4BD"}
|
|
1
|
+
{"version":3,"file":"useRemoveBodyScroll.js","names":["useEffect","getOwnerDocument","scrollBodyCount","useRemoveBodyScroll","open","elementRef","current","ownerDocument","ownerWindow","defaultView","window","scrollBarWidth","innerWidth","body","clientWidth","style","overflow","marginRight"],"sources":["../../../src/hooks/useRemoveBodyScroll.ts"],"sourcesContent":["import type { RefObject } from 'react';\r\nimport { useEffect } from 'react';\r\n\r\nimport { getOwnerDocument } from '../utils';\r\n\r\nlet scrollBodyCount = 0;\r\nexport function useRemoveBodyScroll(\r\n open: boolean,\r\n elementRef: RefObject<HTMLElement | null>\r\n) {\r\n useEffect(() => {\r\n if (open && elementRef.current) {\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n const ownerDocument = getOwnerDocument(elementRef.current)!;\r\n const ownerWindow = ownerDocument.defaultView || window;\r\n scrollBodyCount += 1;\r\n\r\n // calculate scrollbar width if mounting the first scroll lock\r\n let scrollBarWidth = 0;\r\n if (scrollBodyCount === 1) {\r\n scrollBarWidth =\r\n ownerWindow.innerWidth - ownerDocument.body.clientWidth;\r\n }\r\n\r\n ownerDocument.body.style.overflow = 'hidden';\r\n if (scrollBarWidth > 0) {\r\n ownerDocument.body.style.marginRight = `${scrollBarWidth}px`;\r\n }\r\n\r\n return () => {\r\n scrollBodyCount -= 1;\r\n if (scrollBodyCount === 0) {\r\n ownerDocument.body.style.overflow = '';\r\n ownerDocument.body.style.marginRight = '';\r\n }\r\n };\r\n }\r\n }, [elementRef, open]);\r\n}\r\n"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAEA,IAAIC,eAAe,GAAG,CAAtB;AACA,OAAO,SAASC,mBAAT,CACLC,IADK,EAELC,UAFK,EAGL;EACAL,SAAS,CAAC,YAAM;IACd,IAAII,IAAI,IAAIC,UAAU,CAACC,OAAvB,EAAgC;MAC9B;MACA,IAAMC,aAAa,GAAGN,gBAAgB,CAACI,UAAU,CAACC,OAAZ,CAAtC;MACA,IAAME,WAAW,GAAGD,aAAa,CAACE,WAAd,IAA6BC,MAAjD;MACAR,eAAe,IAAI,CAAnB,CAJ8B,CAM9B;;MACA,IAAIS,cAAc,GAAG,CAArB;;MACA,IAAIT,eAAe,KAAK,CAAxB,EAA2B;QACzBS,cAAc,GACZH,WAAW,CAACI,UAAZ,GAAyBL,aAAa,CAACM,IAAd,CAAmBC,WAD9C;MAED;;MAEDP,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBC,QAAzB,GAAoC,QAApC;;MACA,IAAIL,cAAc,GAAG,CAArB,EAAwB;QACtBJ,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBE,WAAzB,aAA0CN,cAA1C;MACD;;MAED,OAAO,YAAM;QACXT,eAAe,IAAI,CAAnB;;QACA,IAAIA,eAAe,KAAK,CAAxB,EAA2B;UACzBK,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBC,QAAzB,GAAoC,EAApC;UACAT,aAAa,CAACM,IAAd,CAAmBE,KAAnB,CAAyBE,WAAzB,GAAuC,EAAvC;QACD;MACF,CAND;IAOD;EACF,CA3BQ,EA2BN,CAACZ,UAAD,EAAaD,IAAb,CA3BM,CAAT;AA4BD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { MutableRefObject } from 'react';
|
|
2
|
-
export declare type ScopeMatcherFn = (nodeType: string, props: {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
}, instance: Element) => boolean;
|
|
5
|
-
export declare type Scope<T extends HTMLElement> = MutableRefObject<{
|
|
6
|
-
queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];
|
|
7
|
-
}>;
|
|
8
|
-
export declare function getScope<T extends HTMLElement, R extends HTMLElement>(rootRef: MutableRefObject<R | undefined | null>): {
|
|
9
|
-
queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];
|
|
10
|
-
};
|
|
11
|
-
export declare function useScope<T extends HTMLElement, R extends HTMLElement>(rootRef: MutableRefObject<R | undefined | null>): Scope<T>;
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
export declare type ScopeMatcherFn = (nodeType: string, props: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}, instance: Element) => boolean;
|
|
5
|
+
export declare type Scope<T extends HTMLElement> = MutableRefObject<{
|
|
6
|
+
queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare function getScope<T extends HTMLElement, R extends HTMLElement>(rootRef: MutableRefObject<R | undefined | null>): {
|
|
9
|
+
queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];
|
|
10
|
+
};
|
|
11
|
+
export declare function useScope<T extends HTMLElement, R extends HTMLElement>(rootRef: MutableRefObject<R | undefined | null>): Scope<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScope.js","names":["useRef","getScope","rootRef","queryAllNodes","matcherFn","current","allNodes","querySelectorAll","filtered","forEach","node","props","attributes","i","length","attr","name","value","tagName","toLowerCase","push","useScope","scope"],"sources":["../../../src/hooks/useScope.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useRef } from 'react';\n\nexport type ScopeMatcherFn = (\n nodeType: string,\n props: {\n [key: string]: string;\n },\n instance: Element\n) => boolean;\n\nexport type Scope<T extends HTMLElement> = MutableRefObject<{\n queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];\n}>;\n\nexport function getScope<T extends HTMLElement, R extends HTMLElement>(\n rootRef: MutableRefObject<R | undefined | null>\n) {\n const queryAllNodes = (matcherFn: ScopeMatcherFn) => {\n if (!rootRef.current) {\n return [];\n }\n\n const allNodes = rootRef.current.querySelectorAll('*');\n\n const filtered: T[] = [];\n allNodes.forEach((node) => {\n const props = {};\n const { attributes } = node;\n for (let i = 0; i < attributes.length; i++) {\n const attr = attributes[i];\n props[attr.name] = attr.value;\n }\n\n if (matcherFn(node.tagName.toLowerCase(), props, node)) {\n filtered.push(node as T);\n }\n });\n\n return filtered;\n };\n\n return { queryAllNodes };\n}\n\nexport function useScope<T extends HTMLElement, R extends HTMLElement>(\n rootRef: MutableRefObject<R | undefined | null>\n): Scope<T> {\n const scope: Scope<T> = useRef(getScope(rootRef));\n\n return scope;\n}\n"],"mappings":"AACA,SAASA,MAAT,QAAuB,OAAvB;AAcA,OAAO,SAASC,QAAT,CACLC,OADK,EAEL;EACA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,SAAD,EAA+B;IACnD,IAAI,CAACF,OAAO,CAACG,OAAb,EAAsB;MACpB,OAAO,EAAP;IACD;;IAED,IAAMC,QAAQ,GAAGJ,OAAO,CAACG,OAAR,CAAgBE,gBAAhB,CAAiC,GAAjC,CAAjB;IAEA,IAAMC,QAAa,GAAG,EAAtB;IACAF,QAAQ,CAACG,OAAT,CAAiB,UAACC,IAAD,EAAU;MACzB,IAAMC,KAAK,GAAG,EAAd;MACA,IAAQC,UAAR,GAAuBF,IAAvB,CAAQE,UAAR;;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,EAAxC,EAA4C;QAC1C,IAAME,IAAI,GAAGH,UAAU,CAACC,CAAD,CAAvB;QACAF,KAAK,CAACI,IAAI,CAACC,IAAN,CAAL,GAAmBD,IAAI,CAACE,KAAxB;MACD;;MAED,IAAIb,SAAS,CAACM,IAAI,CAACQ,OAAL,CAAaC,WAAb,EAAD,EAA6BR,KAA7B,EAAoCD,IAApC,CAAb,EAAwD;QACtDF,QAAQ,CAACY,IAAT,CAAcV,IAAd;MACD;IACF,CAXD;IAaA,OAAOF,QAAP;EACD,CAtBD;;EAwBA,OAAO;IAAEL,aAAa,EAAbA;EAAF,CAAP;AACD;AAED,OAAO,SAASkB,QAAT,CACLnB,OADK,EAEK;EACV,IAAMoB,KAAe,GAAGtB,MAAM,CAACC,QAAQ,CAACC,OAAD,CAAT,CAA9B;EAEA,OAAOoB,KAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"useScope.js","names":["useRef","getScope","rootRef","queryAllNodes","matcherFn","current","allNodes","querySelectorAll","filtered","forEach","node","props","attributes","i","length","attr","name","value","tagName","toLowerCase","push","useScope","scope"],"sources":["../../../src/hooks/useScope.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { useRef } from 'react';\r\n\r\nexport type ScopeMatcherFn = (\r\n nodeType: string,\r\n props: {\r\n [key: string]: string;\r\n },\r\n instance: Element\r\n) => boolean;\r\n\r\nexport type Scope<T extends HTMLElement> = MutableRefObject<{\r\n queryAllNodes: (matcherFn: ScopeMatcherFn) => T[];\r\n}>;\r\n\r\nexport function getScope<T extends HTMLElement, R extends HTMLElement>(\r\n rootRef: MutableRefObject<R | undefined | null>\r\n) {\r\n const queryAllNodes = (matcherFn: ScopeMatcherFn) => {\r\n if (!rootRef.current) {\r\n return [];\r\n }\r\n\r\n const allNodes = rootRef.current.querySelectorAll('*');\r\n\r\n const filtered: T[] = [];\r\n allNodes.forEach((node) => {\r\n const props = {};\r\n const { attributes } = node;\r\n for (let i = 0; i < attributes.length; i++) {\r\n const attr = attributes[i];\r\n props[attr.name] = attr.value;\r\n }\r\n\r\n if (matcherFn(node.tagName.toLowerCase(), props, node)) {\r\n filtered.push(node as T);\r\n }\r\n });\r\n\r\n return filtered;\r\n };\r\n\r\n return { queryAllNodes };\r\n}\r\n\r\nexport function useScope<T extends HTMLElement, R extends HTMLElement>(\r\n rootRef: MutableRefObject<R | undefined | null>\r\n): Scope<T> {\r\n const scope: Scope<T> = useRef(getScope(rootRef));\r\n\r\n return scope;\r\n}\r\n"],"mappings":"AACA,SAASA,MAAT,QAAuB,OAAvB;AAcA,OAAO,SAASC,QAAT,CACLC,OADK,EAEL;EACA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,SAAD,EAA+B;IACnD,IAAI,CAACF,OAAO,CAACG,OAAb,EAAsB;MACpB,OAAO,EAAP;IACD;;IAED,IAAMC,QAAQ,GAAGJ,OAAO,CAACG,OAAR,CAAgBE,gBAAhB,CAAiC,GAAjC,CAAjB;IAEA,IAAMC,QAAa,GAAG,EAAtB;IACAF,QAAQ,CAACG,OAAT,CAAiB,UAACC,IAAD,EAAU;MACzB,IAAMC,KAAK,GAAG,EAAd;MACA,IAAQC,UAAR,GAAuBF,IAAvB,CAAQE,UAAR;;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,EAAxC,EAA4C;QAC1C,IAAME,IAAI,GAAGH,UAAU,CAACC,CAAD,CAAvB;QACAF,KAAK,CAACI,IAAI,CAACC,IAAN,CAAL,GAAmBD,IAAI,CAACE,KAAxB;MACD;;MAED,IAAIb,SAAS,CAACM,IAAI,CAACQ,OAAL,CAAaC,WAAb,EAAD,EAA6BR,KAA7B,EAAoCD,IAApC,CAAb,EAAwD;QACtDF,QAAQ,CAACY,IAAT,CAAcV,IAAd;MACD;IACF,CAXD;IAaA,OAAOF,QAAP;EACD,CAtBD;;EAwBA,OAAO;IAAEL,aAAa,EAAbA;EAAF,CAAP;AACD;AAED,OAAO,SAASkB,QAAT,CACLnB,OADK,EAEK;EACV,IAAMoB,KAAe,GAAGtB,MAAM,CAACC,QAAQ,CAACC,OAAD,CAAT,CAA9B;EAEA,OAAOoB,KAAP;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useThrottle<T>(value: T, limit: number): T;
|
|
1
|
+
export declare function useThrottle<T>(value: T, limit: number): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottle.js","names":["useState","useEffect","useRef","useThrottle","value","limit","throttledValue","setThrottledValue","lastRan","Date","now","handler","setTimeout","current","clearTimeout"],"sources":["../../../src/hooks/useThrottle.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\nexport function useThrottle<T>(value: T, limit: number) {\n const [throttledValue, setThrottledValue] = useState(value);\n const lastRan = useRef(Date.now());\n\n useEffect(() => {\n const handler = setTimeout(() => {\n setThrottledValue(value);\n lastRan.current = Date.now();\n }, limit - (Date.now() - lastRan.current));\n\n return () => {\n clearTimeout(handler);\n };\n }, [value, limit]);\n\n return throttledValue;\n}\n"],"mappings":";AAAA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,QAA4C,OAA5C;AAEA,OAAO,SAASC,WAAT,CAAwBC,KAAxB,EAAkCC,KAAlC,EAAiD;EACtD,gBAA4CL,QAAQ,CAACI,KAAD,CAApD;EAAA;EAAA,IAAOE,cAAP;EAAA,IAAuBC,iBAAvB;;EACA,IAAMC,OAAO,GAAGN,MAAM,CAACO,IAAI,CAACC,GAAL,EAAD,CAAtB;EAEAT,SAAS,CAAC,YAAM;IACd,IAAMU,OAAO,GAAGC,UAAU,CAAC,YAAM;MAC/BL,iBAAiB,CAACH,KAAD,CAAjB;MACAI,OAAO,CAACK,OAAR,GAAkBJ,IAAI,CAACC,GAAL,EAAlB;IACD,CAHyB,EAGvBL,KAAK,IAAII,IAAI,CAACC,GAAL,KAAaF,OAAO,CAACK,OAAzB,CAHkB,CAA1B;IAKA,OAAO,YAAM;MACXC,YAAY,CAACH,OAAD,CAAZ;IACD,CAFD;EAGD,CATQ,EASN,CAACP,KAAD,EAAQC,KAAR,CATM,CAAT;EAWA,OAAOC,cAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"useThrottle.js","names":["useState","useEffect","useRef","useThrottle","value","limit","throttledValue","setThrottledValue","lastRan","Date","now","handler","setTimeout","current","clearTimeout"],"sources":["../../../src/hooks/useThrottle.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\r\n\r\nexport function useThrottle<T>(value: T, limit: number) {\r\n const [throttledValue, setThrottledValue] = useState(value);\r\n const lastRan = useRef(Date.now());\r\n\r\n useEffect(() => {\r\n const handler = setTimeout(() => {\r\n setThrottledValue(value);\r\n lastRan.current = Date.now();\r\n }, limit - (Date.now() - lastRan.current));\r\n\r\n return () => {\r\n clearTimeout(handler);\r\n };\r\n }, [value, limit]);\r\n\r\n return throttledValue;\r\n}\r\n"],"mappings":";AAAA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,QAA4C,OAA5C;AAEA,OAAO,SAASC,WAAT,CAAwBC,KAAxB,EAAkCC,KAAlC,EAAiD;EACtD,gBAA4CL,QAAQ,CAACI,KAAD,CAApD;EAAA;EAAA,IAAOE,cAAP;EAAA,IAAuBC,iBAAvB;;EACA,IAAMC,OAAO,GAAGN,MAAM,CAACO,IAAI,CAACC,GAAL,EAAD,CAAtB;EAEAT,SAAS,CAAC,YAAM;IACd,IAAMU,OAAO,GAAGC,UAAU,CAAC,YAAM;MAC/BL,iBAAiB,CAACH,KAAD,CAAjB;MACAI,OAAO,CAACK,OAAR,GAAkBJ,IAAI,CAACC,GAAL,EAAlB;IACD,CAHyB,EAGvBL,KAAK,IAAII,IAAI,CAACC,GAAL,KAAaF,OAAO,CAACK,OAAzB,CAHkB,CAA1B;IAKA,OAAO,YAAM;MACXC,YAAY,CAACH,OAAD,CAAZ;IACD,CAFD;EAGD,CATQ,EASN,CAACP,KAAD,EAAQC,KAAR,CATM,CAAT;EAWA,OAAOC,cAAP;AACD"}
|
package/build/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from './Accordion';
|
|
2
|
-
export * from './CheckBox';
|
|
3
|
-
export * from './ComboBox';
|
|
4
|
-
export * from './FocusLock';
|
|
5
|
-
export * from './Menu';
|
|
6
|
-
export * from './Modal';
|
|
7
|
-
export * from './Popper';
|
|
8
|
-
export * from './Portal';
|
|
9
|
-
export * from './RadioButton';
|
|
10
|
-
export * from './Slider';
|
|
11
|
-
export * from './Spinner';
|
|
12
|
-
export * from './Tabs';
|
|
13
|
-
export * from './Tooltip';
|
|
14
|
-
export * from './utils';
|
|
15
|
-
export * from './hooks';
|
|
1
|
+
export * from './Accordion';
|
|
2
|
+
export * from './CheckBox';
|
|
3
|
+
export * from './ComboBox';
|
|
4
|
+
export * from './FocusLock';
|
|
5
|
+
export * from './Menu';
|
|
6
|
+
export * from './Modal';
|
|
7
|
+
export * from './Popper';
|
|
8
|
+
export * from './Portal';
|
|
9
|
+
export * from './RadioButton';
|
|
10
|
+
export * from './Slider';
|
|
11
|
+
export * from './Spinner';
|
|
12
|
+
export * from './Tabs';
|
|
13
|
+
export * from './Tooltip';
|
|
14
|
+
export * from './utils';
|
|
15
|
+
export * from './hooks';
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["// Components\nexport * from './Accordion';\nexport * from './CheckBox';\nexport * from './ComboBox';\nexport * from './FocusLock';\nexport * from './Menu';\nexport * from './Modal';\nexport * from './Popper';\nexport * from './Portal';\nexport * from './RadioButton';\nexport * from './Slider';\nexport * from './Spinner';\nexport * from './Tabs';\nexport * from './Tooltip';\n\n// General React utilities\nexport * from './utils';\n\n// Hooks\nexport * from './hooks';\n"],"mappings":"AAAA;AACA,cAAc,aAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,aAAd;AACA,cAAc,QAAd;AACA,cAAc,SAAd;AACA,cAAc,UAAd;AACA,cAAc,UAAd;AACA,cAAc,eAAd;AACA,cAAc,UAAd;AACA,cAAc,WAAd;AACA,cAAc,QAAd;AACA,cAAc,WAAd,C,CAEA;;AACA,cAAc,SAAd,C,CAEA;;AACA,cAAc,SAAd"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["// Components\r\nexport * from './Accordion';\r\nexport * from './CheckBox';\r\nexport * from './ComboBox';\r\nexport * from './FocusLock';\r\nexport * from './Menu';\r\nexport * from './Modal';\r\nexport * from './Popper';\r\nexport * from './Portal';\r\nexport * from './RadioButton';\r\nexport * from './Slider';\r\nexport * from './Spinner';\r\nexport * from './Tabs';\r\nexport * from './Tooltip';\r\n\r\n// General React utilities\r\nexport * from './utils';\r\n\r\n// Hooks\r\nexport * from './hooks';\r\n"],"mappings":"AAAA;AACA,cAAc,aAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,aAAd;AACA,cAAc,QAAd;AACA,cAAc,SAAd;AACA,cAAc,UAAd;AACA,cAAc,UAAd;AACA,cAAc,eAAd;AACA,cAAc,UAAd;AACA,cAAc,WAAd;AACA,cAAc,QAAd;AACA,cAAc,WAAd,C,CAEA;;AACA,cAAc,SAAd,C,CAEA;;AACA,cAAc,SAAd"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { MutableRefObject, RefCallback } from 'react';
|
|
2
|
-
export declare function assignRef<T>(ref: MutableRefObject<T> | RefCallback<T> | null | undefined, value: T): void;
|
|
3
|
-
export declare function assignMultipleRefs<T>(...refs: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]): RefCallback<T>;
|
|
1
|
+
import type { MutableRefObject, RefCallback } from 'react';
|
|
2
|
+
export declare function assignRef<T>(ref: MutableRefObject<T> | RefCallback<T> | null | undefined, value: T): void;
|
|
3
|
+
export declare function assignMultipleRefs<T>(...refs: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]): RefCallback<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assign-ref.js","names":["assignRef","ref","value","current","error","Error","assignMultipleRefs","refs","node","forEach"],"sources":["../../../src/utils/assign-ref.ts"],"sourcesContent":["import type { MutableRefObject, RefCallback } from 'react';\n\nexport function assignRef<T>(\n ref: MutableRefObject<T> | RefCallback<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.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: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]\n): RefCallback<T> {\n return (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node);\n });\n };\n}\n"],"mappings":"AAEA,OAAO,SAASA,SAAT,CACLC,GADK,EAELC,KAFK,EAGL;EACA,IAAID,GAAG,IAAI,IAAX,EAAiB;;EACjB,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;IAC7BA,GAAG,CAACC,KAAD,CAAH;EACD,CAFD,MAEO;IACL,IAAI;MACFD,GAAG,CAACE,OAAJ,GAAcD,KAAd;IACD,CAFD,CAEE,OAAOE,KAAP,EAAc;MACd,MAAM,IAAIC,KAAJ,iCAAkCH,KAAlC,yBAAoDD,GAApD,QAAN;IACD;EACF;AACF;AAED,OAAO,SAASK,kBAAT,GAEW;EAAA,kCADbC,IACa;IADbA,IACa;EAAA;;EAChB,OAAO,UAACC,IAAD,EAAoB;IACzBD,IAAI,CAACE,OAAL,CAAa,UAACR,GAAD,EAAS;MACpBD,SAAS,CAACC,GAAD,EAAMO,IAAN,CAAT;IACD,CAFD;EAGD,CAJD;AAKD"}
|
|
1
|
+
{"version":3,"file":"assign-ref.js","names":["assignRef","ref","value","current","error","Error","assignMultipleRefs","refs","node","forEach"],"sources":["../../../src/utils/assign-ref.ts"],"sourcesContent":["import type { MutableRefObject, RefCallback } from 'react';\r\n\r\nexport function assignRef<T>(\r\n ref: MutableRefObject<T> | RefCallback<T> | null | undefined,\r\n value: T\r\n) {\r\n if (ref == null) return;\r\n if (typeof ref === 'function') {\r\n ref(value);\r\n } else {\r\n try {\r\n ref.current = value;\r\n } catch (error) {\r\n throw new Error(`Cannot assign value \"${value}\" to ref \"${ref}\"`);\r\n }\r\n }\r\n}\r\n\r\nexport function assignMultipleRefs<T>(\r\n ...refs: (MutableRefObject<T> | RefCallback<T> | null | undefined)[]\r\n): RefCallback<T> {\r\n return (node: T | null) => {\r\n refs.forEach((ref) => {\r\n assignRef(ref, node);\r\n });\r\n };\r\n}\r\n"],"mappings":"AAEA,OAAO,SAASA,SAAT,CACLC,GADK,EAELC,KAFK,EAGL;EACA,IAAID,GAAG,IAAI,IAAX,EAAiB;;EACjB,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;IAC7BA,GAAG,CAACC,KAAD,CAAH;EACD,CAFD,MAEO;IACL,IAAI;MACFD,GAAG,CAACE,OAAJ,GAAcD,KAAd;IACD,CAFD,CAEE,OAAOE,KAAP,EAAc;MACd,MAAM,IAAIC,KAAJ,iCAAkCH,KAAlC,yBAAoDD,GAApD,QAAN;IACD;EACF;AACF;AAED,OAAO,SAASK,kBAAT,GAEW;EAAA,kCADbC,IACa;IADbA,IACa;EAAA;;EAChB,OAAO,UAACC,IAAD,EAAoB;IACzBD,IAAI,CAACE,OAAL,CAAa,UAACR,GAAD,EAAS;MACpBD,SAAS,CAACC,GAAD,EAAMO,IAAN,CAAT;IACD,CAFD;EAGD,CAJD;AAKD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function canUseDOM(): boolean;
|
|
1
|
+
export declare function canUseDOM(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"can-use-dom.js","names":["canUseDOM","window","document","createElement"],"sources":["../../../src/utils/can-use-dom.ts"],"sourcesContent":["export function canUseDOM() {\n return !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n );\n}\n"],"mappings":"AAAA,OAAO,SAASA,SAAT,GAAqB;EAC1B,OAAO,CAAC,EACN,OAAOC,MAAP,KAAkB,WAAlB,IACAA,MAAM,CAACC,QADP,IAEAD,MAAM,CAACC,QAAP,CAAgBC,aAHV,CAAR;AAKD"}
|
|
1
|
+
{"version":3,"file":"can-use-dom.js","names":["canUseDOM","window","document","createElement"],"sources":["../../../src/utils/can-use-dom.ts"],"sourcesContent":["export function canUseDOM() {\r\n return !!(\r\n typeof window !== 'undefined' &&\r\n window.document &&\r\n window.document.createElement\r\n );\r\n}\r\n"],"mappings":"AAAA,OAAO,SAASA,SAAT,GAAqB;EAC1B,OAAO,CAAC,EACN,OAAOC,MAAP,KAAkB,WAAlB,IACAA,MAAM,CAACC,QADP,IAEAD,MAAM,CAACC,QAAP,CAAgBC,aAHV,CAAR;AAKD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function clamp(value: number, min: number, max: number): number;
|
|
1
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.js","names":["clamp","value","min","max","Math"],"sources":["../../../src/utils/clamp.ts"],"sourcesContent":["export function clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n"],"mappings":"AAAA,OAAO,SAASA,KAAT,CAAeC,KAAf,EAA8BC,GAA9B,EAA2CC,GAA3C,EAAwD;EAC7D,OAAOC,IAAI,CAACF,GAAL,CAASE,IAAI,CAACD,GAAL,CAASF,KAAT,EAAgBC,GAAhB,CAAT,EAA+BC,GAA/B,CAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"clamp.js","names":["clamp","value","min","max","Math"],"sources":["../../../src/utils/clamp.ts"],"sourcesContent":["export function clamp(value: number, min: number, max: number) {\r\n return Math.min(Math.max(value, min), max);\r\n}\r\n"],"mappings":"AAAA,OAAO,SAASA,KAAT,CAAeC,KAAf,EAA8BC,GAA9B,EAA2CC,GAA3C,EAAwD;EAC7D,OAAOC,IAAI,CAACF,GAAL,CAASE,IAAI,CAACD,GAAL,CAASF,KAAT,EAAgBC,GAAhB,CAAT,EAA+BC,GAA/B,CAAP;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
-
declare type ContextProvider<T> = FC<PropsWithChildren<T>>;
|
|
3
|
-
export declare function createContext<ContextValueType extends object | null>(rootName: string, defaultContext?: ContextValueType): [
|
|
4
|
-
ContextProvider<ContextValueType>,
|
|
5
|
-
(childName: string) => ContextValueType
|
|
6
|
-
];
|
|
7
|
-
export {};
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
declare type ContextProvider<T> = FC<PropsWithChildren<T>>;
|
|
3
|
+
export declare function createContext<ContextValueType extends object | null>(rootName: string, defaultContext?: ContextValueType): [
|
|
4
|
+
ContextProvider<ContextValueType>,
|
|
5
|
+
(childName: string) => ContextValueType
|
|
6
|
+
];
|
|
7
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["useMemo","createContext","ReactCreateContext","useContext","useReactContext","rootName","defaultContext","Ctx","Provider","props","children","context","value","Object","values","childName","Error","displayName"],"sources":["../../../src/utils/context.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport {\n useMemo,\n createContext as ReactCreateContext,\n useContext as useReactContext,\n} from 'react';\n\n////////////////////////////////////////////////////////////////////////////////\n\ntype ContextProvider<T> = FC<PropsWithChildren<T>>;\n\nexport function createContext<ContextValueType extends object | null>(\n rootName: string,\n defaultContext?: ContextValueType\n): [\n ContextProvider<ContextValueType>,\n (childName: string) => ContextValueType\n] {\n const Ctx = ReactCreateContext<ContextValueType | undefined>(defaultContext);\n\n function Provider(props: PropsWithChildren<ContextValueType>) {\n const { children, ...context } = props;\n const value = useMemo(\n () => context,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(context)\n ) as ContextValueType;\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n function useContext(childName: string) {\n const context = useReactContext(Ctx);\n if (context) {\n return context;\n }\n if (defaultContext) {\n return defaultContext;\n }\n throw Error(\n `${childName} must be rendered inside of a ${rootName} component.`\n );\n }\n\n Ctx.displayName = `${rootName}Context`;\n Provider.displayName = `${rootName}Provider`;\n\n return [Provider, useContext];\n}\n"],"mappings":";;AACA,SACEA,OADF,EAEEC,aAAa,IAAIC,kBAFnB,EAGEC,UAAU,IAAIC,eAHhB,QAIO,OAJP,C,CAMA;;;AAIA,OAAO,SAASH,aAAT,CACLI,QADK,EAELC,cAFK,EAML;EACA,IAAMC,GAAG,gBAAGL,kBAAkB,CAA+BI,cAA/B,CAA9B;;EAEA,SAASE,QAAT,CAAkBC,KAAlB,EAA8D;IAC5D,IAAQC,QAAR,GAAiCD,KAAjC,CAAQC,QAAR;IAAA,IAAqBC,OAArB,4BAAiCF,KAAjC;;IACA,IAAMG,KAAK,GAAGZ,OAAO,CACnB;MAAA,OAAMW,OAAN;IAAA,CADmB,EAEnB;IACAE,MAAM,CAACC,MAAP,CAAcH,OAAd,CAHmB,CAArB;IAKA,oBAAO,KAAC,GAAD,CAAK,QAAL;MAAc,KAAK,EAAEC,KAArB;MAAA,UAA6BF;IAA7B,EAAP;EACD;;EAED,SAASP,UAAT,CAAoBY,SAApB,EAAuC;IACrC,IAAMJ,OAAO,GAAGP,eAAe,CAACG,GAAD,CAA/B;;IACA,IAAII,OAAJ,EAAa;MACX,OAAOA,OAAP;IACD;;IACD,IAAIL,cAAJ,EAAoB;MAClB,OAAOA,cAAP;IACD;;IACD,MAAMU,KAAK,WACND,SADM,2CACoCV,QADpC,iBAAX;EAGD;;EAEDE,GAAG,CAACU,WAAJ,aAAqBZ,QAArB;EACAG,QAAQ,CAACS,WAAT,aAA0BZ,QAA1B;EAEA,OAAO,CAACG,QAAD,EAAWL,UAAX,CAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"context.js","names":["useMemo","createContext","ReactCreateContext","useContext","useReactContext","rootName","defaultContext","Ctx","Provider","props","children","context","value","Object","values","childName","Error","displayName"],"sources":["../../../src/utils/context.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\r\nimport {\r\n useMemo,\r\n createContext as ReactCreateContext,\r\n useContext as useReactContext,\r\n} from 'react';\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n\r\ntype ContextProvider<T> = FC<PropsWithChildren<T>>;\r\n\r\nexport function createContext<ContextValueType extends object | null>(\r\n rootName: string,\r\n defaultContext?: ContextValueType\r\n): [\r\n ContextProvider<ContextValueType>,\r\n (childName: string) => ContextValueType\r\n] {\r\n const Ctx = ReactCreateContext<ContextValueType | undefined>(defaultContext);\r\n\r\n function Provider(props: PropsWithChildren<ContextValueType>) {\r\n const { children, ...context } = props;\r\n const value = useMemo(\r\n () => context,\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n Object.values(context)\r\n ) as ContextValueType;\r\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\r\n }\r\n\r\n function useContext(childName: string) {\r\n const context = useReactContext(Ctx);\r\n if (context) {\r\n return context;\r\n }\r\n if (defaultContext) {\r\n return defaultContext;\r\n }\r\n throw Error(\r\n `${childName} must be rendered inside of a ${rootName} component.`\r\n );\r\n }\r\n\r\n Ctx.displayName = `${rootName}Context`;\r\n Provider.displayName = `${rootName}Provider`;\r\n\r\n return [Provider, useContext];\r\n}\r\n"],"mappings":";;AACA,SACEA,OADF,EAEEC,aAAa,IAAIC,kBAFnB,EAGEC,UAAU,IAAIC,eAHhB,QAIO,OAJP,C,CAMA;;;AAIA,OAAO,SAASH,aAAT,CACLI,QADK,EAELC,cAFK,EAML;EACA,IAAMC,GAAG,gBAAGL,kBAAkB,CAA+BI,cAA/B,CAA9B;;EAEA,SAASE,QAAT,CAAkBC,KAAlB,EAA8D;IAC5D,IAAQC,QAAR,GAAiCD,KAAjC,CAAQC,QAAR;IAAA,IAAqBC,OAArB,4BAAiCF,KAAjC;;IACA,IAAMG,KAAK,GAAGZ,OAAO,CACnB;MAAA,OAAMW,OAAN;IAAA,CADmB,EAEnB;IACAE,MAAM,CAACC,MAAP,CAAcH,OAAd,CAHmB,CAArB;IAKA,oBAAO,KAAC,GAAD,CAAK,QAAL;MAAc,KAAK,EAAEC,KAArB;MAAA,UAA6BF;IAA7B,EAAP;EACD;;EAED,SAASP,UAAT,CAAoBY,SAApB,EAAuC;IACrC,IAAMJ,OAAO,GAAGP,eAAe,CAACG,GAAD,CAA/B;;IACA,IAAII,OAAJ,EAAa;MACX,OAAOA,OAAP;IACD;;IACD,IAAIL,cAAJ,EAAoB;MAClB,OAAOA,cAAP;IACD;;IACD,MAAMU,KAAK,WACND,SADM,2CACoCV,QADpC,iBAAX;EAGD;;EAEDE,GAAG,CAACU,WAAJ,aAAqBZ,QAArB;EACAG,QAAQ,CAACS,WAAT,aAA0BZ,QAA1B;EAEA,OAAO,CAACG,QAAD,EAAWL,UAAX,CAAP;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function createSubscription(): {
|
|
2
|
-
subscribe: (fn: () => void) => () => void;
|
|
3
|
-
notify: () => void;
|
|
4
|
-
};
|
|
1
|
+
export declare function createSubscription(): {
|
|
2
|
+
subscribe: (fn: () => void) => () => void;
|
|
3
|
+
notify: () => void;
|
|
4
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-subscription.js","names":["createSubscription","subscriptions","subscribe","fn","push","splice","indexOf","notify","forEach"],"sources":["../../../src/utils/create-subscription.ts"],"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"],"mappings":"AAAA,OAAO,SAASA,kBAAT,GAA8B;EACnC,IAAMC,aAA6B,GAAG,EAAtC;;EAEA,SAASC,SAAT,CAAmBC,EAAnB,EAAmC;IACjCF,aAAa,CAACG,IAAd,CAAmBD,EAAnB;IACA,OAAO,YAAM;MACXF,aAAa,CAACI,MAAd,CAAqBJ,aAAa,CAACK,OAAd,CAAsBH,EAAtB,CAArB,EAAgD,CAAhD;IACD,CAFD;EAGD;;EAED,SAASI,MAAT,GAAkB;IAChBN,aAAa,CAACO,OAAd,CAAsB,UAACL,EAAD;MAAA,OAAQA,EAAE,EAAV;IAAA,CAAtB;EACD;;EAED,OAAO;IAAED,SAAS,EAATA,SAAF;IAAaK,MAAM,EAANA;EAAb,CAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"create-subscription.js","names":["createSubscription","subscriptions","subscribe","fn","push","splice","indexOf","notify","forEach"],"sources":["../../../src/utils/create-subscription.ts"],"sourcesContent":["export function createSubscription() {\r\n const subscriptions: (() => void)[] = [];\r\n\r\n function subscribe(fn: () => void) {\r\n subscriptions.push(fn);\r\n return () => {\r\n subscriptions.splice(subscriptions.indexOf(fn), 1);\r\n };\r\n }\r\n\r\n function notify() {\r\n subscriptions.forEach((fn) => fn());\r\n }\r\n\r\n return { subscribe, notify };\r\n}\r\n"],"mappings":"AAAA,OAAO,SAASA,kBAAT,GAA8B;EACnC,IAAMC,aAA6B,GAAG,EAAtC;;EAEA,SAASC,SAAT,CAAmBC,EAAnB,EAAmC;IACjCF,aAAa,CAACG,IAAd,CAAmBD,EAAnB;IACA,OAAO,YAAM;MACXF,aAAa,CAACI,MAAd,CAAqBJ,aAAa,CAACK,OAAd,CAAsBH,EAAtB,CAArB,EAAgD,CAAhD;IACD,CAFD;EAGD;;EAED,SAASI,MAAT,GAAkB;IAChBN,aAAa,CAACO,OAAd,CAAsB,UAACL,EAAD;MAAA,OAAQA,EAAE,EAAV;IAAA,CAAtB;EACD;;EAED,OAAO;IAAED,SAAS,EAATA,SAAF;IAAaK,MAAM,EAANA;EAAb,CAAP;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getCircularIndex(index: number, maxLength: number): number | null;
|
|
1
|
+
export declare function getCircularIndex(index: number, maxLength: number): number | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-circular-index.js","names":["getCircularIndex","index","maxLength"],"sources":["../../../src/utils/get-circular-index.ts"],"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"],"mappings":"AAAA,OAAO,SAASA,gBAAT,CAA0BC,KAA1B,EAAyCC,SAAzC,EAA4D;EACjE,IAAIA,SAAS,GAAG,CAAhB,EAAmB;IACjB,OAAO,IAAP;EACD;;EAED,OAAO,CAAED,KAAK,GAAGC,SAAT,GAAsBA,SAAvB,IAAoCA,SAA3C;AACD"}
|
|
1
|
+
{"version":3,"file":"get-circular-index.js","names":["getCircularIndex","index","maxLength"],"sources":["../../../src/utils/get-circular-index.ts"],"sourcesContent":["export function getCircularIndex(index: number, maxLength: number) {\r\n if (maxLength < 0) {\r\n return null;\r\n }\r\n\r\n return ((index % maxLength) + maxLength) % maxLength;\r\n}\r\n"],"mappings":"AAAA,OAAO,SAASA,gBAAT,CAA0BC,KAA1B,EAAyCC,SAAzC,EAA4D;EACjE,IAAIA,SAAS,GAAG,CAAhB,EAAmB;IACjB,OAAO,IAAP;EACD;;EAED,OAAO,CAAED,KAAK,GAAGC,SAAT,GAAsBA,SAAvB,IAAoCA,SAA3C;AACD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
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';
|
|
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';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/index.ts"],"sourcesContent":["export * from './assign-ref';\nexport * from './can-use-dom';\nexport * from './context';\nexport * from './get-circular-index';\nexport * from './is-right-click';\nexport * from './owner-document';\nexport * from './polymorphic';\nexport * from './rubber-band-clamp';\nexport * from './use-stable-callback';\nexport * from './wrap-event';\n"],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,eAAd;AACA,cAAc,WAAd;AACA,cAAc,sBAAd;AACA,cAAc,kBAAd;AACA,cAAc,kBAAd;AACA,cAAc,eAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,cAAd"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/index.ts"],"sourcesContent":["export * from './assign-ref';\r\nexport * from './can-use-dom';\r\nexport * from './context';\r\nexport * from './get-circular-index';\r\nexport * from './is-right-click';\r\nexport * from './owner-document';\r\nexport * from './polymorphic';\r\nexport * from './rubber-band-clamp';\r\nexport * from './use-stable-callback';\r\nexport * from './wrap-event';\r\n"],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,eAAd;AACA,cAAc,WAAd;AACA,cAAc,sBAAd;AACA,cAAc,kBAAd;AACA,cAAc,kBAAd;AACA,cAAc,eAAd;AACA,cAAc,qBAAd;AACA,cAAc,uBAAd;AACA,cAAc,cAAd"}
|