@basic-ui/core 0.0.53 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +278 -505
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.js +20 -29
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.js +18 -32
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.js +37 -74
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.js +19 -22
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.js +16 -13
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.js +15 -25
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +7 -7
- package/build/esm/ComboBox/Combobox.js +52 -59
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.js +23 -28
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.js +67 -70
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.js +15 -17
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.js +19 -20
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.js +41 -45
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.js +22 -21
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.js +5 -6
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +2 -2
- package/build/esm/ComboBox/hooks.js +175 -148
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.js +3 -6
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.js +26 -32
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.js +5 -7
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.js +14 -19
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.js +9 -11
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.js +9 -11
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.js +6 -6
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +4 -4
- package/build/esm/Menu/ContextMenuTrigger.js +32 -37
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
- package/build/esm/Menu/Menu.js +33 -49
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +4 -4
- package/build/esm/Menu/MenuButton.js +28 -44
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.js +29 -38
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.js +61 -116
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.js +16 -19
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +1 -1
- package/build/esm/Menu/context.js +14 -12
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.js +1 -1
- package/build/esm/Menu/fixtures/countryList.js.map +1 -1
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.js +13 -18
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.js +24 -33
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +3 -3
- package/build/esm/Popper/Popper.js +44 -61
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.js +11 -16
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.js +3 -5
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.js +9 -11
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/PortalSelectorProvider.d.ts +3 -3
- package/build/esm/Portal/PortalSelectorProvider.js +6 -4
- package/build/esm/Portal/PortalSelectorProvider.js.map +1 -1
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.js +17 -23
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.js +19 -28
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +1 -1
- package/build/esm/RadioButton/context.js +8 -6
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.js +9 -11
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +7 -7
- package/build/esm/Slider/Slider.js +340 -407
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Spinner/Spinner.js +31 -59
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.js +14 -19
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.js +8 -7
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.js +32 -50
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.js +24 -34
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.js +16 -23
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.js +15 -20
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.js +17 -33
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.js +16 -13
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +2 -2
- package/build/esm/Tooltip/Tooltip.js +20 -30
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +2 -2
- package/build/esm/Tooltip/stateMachine.js +95 -81
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +2 -2
- package/build/esm/Tooltip/useTooltip.js +38 -50
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.js +3 -3
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.js +6 -8
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.js +6 -16
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.js +8 -12
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +2 -2
- package/build/esm/hooks/useFocusState.js +9 -15
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +1 -1
- package/build/esm/hooks/useGestureHandlers.js +80 -100
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.js +7 -15
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.js +4 -6
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.js +3 -4
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +1 -1
- package/build/esm/hooks/useReducerMachine.js +15 -26
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +9 -14
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +2 -2
- package/build/esm/hooks/useScope.js +12 -14
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.js +5 -10
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.js +4 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/styles.d.js +2 -0
- package/build/esm/styles.d.js.map +1 -0
- package/build/esm/utils/assign-ref.js +3 -5
- package/build/esm/utils/assign-ref.js.map +1 -1
- package/build/esm/utils/can-use-dom.js.map +1 -1
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +1 -1
- package/build/esm/utils/context.js +13 -20
- package/build/esm/utils/context.js.map +1 -1
- package/build/esm/utils/create-subscription.js +5 -10
- package/build/esm/utils/create-subscription.js.map +1 -1
- package/build/esm/utils/get-circular-index.js +0 -1
- package/build/esm/utils/get-circular-index.js.map +1 -1
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.js.map +1 -1
- package/build/esm/utils/owner-document.js +1 -1
- package/build/esm/utils/owner-document.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +10 -10
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/esm/utils/rubber-band-clamp.js +2 -5
- package/build/esm/utils/rubber-band-clamp.js.map +1 -1
- package/build/esm/utils/use-stable-callback.js +8 -10
- package/build/esm/utils/use-stable-callback.js.map +1 -1
- package/build/esm/utils/wrap-event.d.ts +1 -1
- package/build/esm/utils/wrap-event.js +2 -5
- package/build/esm/utils/wrap-event.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/Accordion/Accordion.tsx +1 -1
- package/src/Accordion/AccordionBody.tsx +1 -1
- package/src/Accordion/AccordionHeader.tsx +1 -2
- package/src/ComboBox/Combobox.tsx +2 -2
- package/src/ComboBox/ComboboxList.tsx +1 -1
- package/src/ComboBox/ComboboxOption.tsx +0 -1
- package/src/ComboBox/hooks.tsx +0 -3
- package/src/FocusLock/useFocusLock.ts +0 -1
- package/src/Menu/Menu.tsx +2 -3
- package/src/Menu/MenuItem.tsx +1 -2
- package/src/Menu/MenuList.tsx +4 -4
- package/src/Modal/Modal.story.tsx +11 -7
- package/src/Modal/ModalBackdrop.tsx +1 -1
- package/src/Modal/NavDrawer.story.tsx +9 -6
- package/src/Popper/Popper.story.tsx +23 -7
- package/src/Popper/Popper.tsx +2 -2
- package/src/RadioButton/RadioButton.story.tsx +2 -1
- package/src/Slider/Slider.tsx +6 -11
- package/src/Spinner/Spinner.tsx +1 -1
- package/src/Tabs/TabList.tsx +1 -1
- package/src/Tooltip/Tooltip.tsx +8 -5
- package/src/Tooltip/useTooltip.ts +1 -1
- package/src/hooks/useControlledState.ts +1 -6
- package/src/hooks/useGestureHandlers.ts +0 -4
- package/src/hooks/useRemoveBodyScroll.ts +0 -1
- package/src/hooks/useScope.ts +1 -1
- package/src/styles.d.ts +1 -0
- package/src/utils/polymorphic.ts +14 -10
- package/src/utils/use-stable-callback.ts +0 -1
- package/build/esm/Carousel/Carousel.d.ts +0 -9
- package/build/esm/Carousel/Carousel.js +0 -38
- package/build/esm/Carousel/Carousel.js.map +0 -1
- package/build/esm/Carousel/Fader.d.ts +0 -14
- package/build/esm/Carousel/Fader.js +0 -76
- package/build/esm/Carousel/Fader.js.map +0 -1
- package/build/esm/Carousel/FaderItem.d.ts +0 -5
- package/build/esm/Carousel/FaderItem.js +0 -16
- package/build/esm/Carousel/FaderItem.js.map +0 -1
- package/build/esm/Carousel/Preloader.d.ts +0 -7
- package/build/esm/Carousel/Preloader.js +0 -70
- package/build/esm/Carousel/Preloader.js.map +0 -1
- package/build/esm/Carousel/Slider.d.ts +0 -14
- package/build/esm/Carousel/Slider.js +0 -212
- package/build/esm/Carousel/Slider.js.map +0 -1
- package/build/esm/Carousel/SliderItem.d.ts +0 -12
- package/build/esm/Carousel/SliderItem.js +0 -41
- package/build/esm/Carousel/SliderItem.js.map +0 -1
- package/build/esm/Carousel/context.d.ts +0 -10
- package/build/esm/Carousel/context.js +0 -8
- package/build/esm/Carousel/context.js.map +0 -1
- package/build/esm/Carousel/getSliderParams.d.ts +0 -9
- package/build/esm/Carousel/getSliderParams.js +0 -85
- package/build/esm/Carousel/getSliderParams.js.map +0 -1
- package/build/esm/Carousel/index.d.ts +0 -7
- package/build/esm/Carousel/index.js +0 -8
- package/build/esm/Carousel/index.js.map +0 -1
- package/build/esm/Carousel/useCarouselGestures.d.ts +0 -30
- package/build/esm/Carousel/useCarouselGestures.js +0 -33
- package/build/esm/Carousel/useCarouselGestures.js.map +0 -1
- package/build/esm/DatePicker/DatePicker.d.ts +0 -24
- package/build/esm/DatePicker/DatePicker.js +0 -101
- package/build/esm/DatePicker/DatePicker.js.map +0 -1
- package/build/esm/DatePicker/DatePickerSelect.d.ts +0 -8
- package/build/esm/DatePicker/DatePickerSelect.js +0 -201
- package/build/esm/DatePicker/DatePickerSelect.js.map +0 -1
- package/build/esm/DatePicker/RangeDatePicker.d.ts +0 -28
- package/build/esm/DatePicker/RangeDatePicker.js +0 -94
- package/build/esm/DatePicker/RangeDatePicker.js.map +0 -1
- package/build/esm/DatePicker/adjustDates.d.ts +0 -4
- package/build/esm/DatePicker/adjustDates.js +0 -18
- package/build/esm/DatePicker/adjustDates.js.map +0 -1
- package/build/esm/DatePicker/contexts.d.ts +0 -31
- package/build/esm/DatePicker/contexts.js +0 -15
- package/build/esm/DatePicker/contexts.js.map +0 -1
- package/build/esm/DatePicker/dateTypes.d.ts +0 -2
- package/build/esm/DatePicker/dateTypes.js +0 -2
- package/build/esm/DatePicker/dateTypes.js.map +0 -1
- package/build/esm/DatePicker/hooks.d.ts +0 -36
- package/build/esm/DatePicker/hooks.js +0 -98
- package/build/esm/DatePicker/hooks.js.map +0 -1
- package/build/esm/DatePicker/index.d.ts +0 -5
- package/build/esm/DatePicker/index.js +0 -6
- package/build/esm/DatePicker/index.js.map +0 -1
- package/build/esm/hooks/useId.d.ts +0 -1
- package/build/esm/hooks/useId.js +0 -25
- package/build/esm/hooks/useId.js.map +0 -1
- package/build/esm/utils/assignRef.d.ts +0 -3
- package/build/esm/utils/assignRef.js +0 -25
- package/build/esm/utils/assignRef.js.map +0 -1
- package/build/esm/utils/getCircularIndex.d.ts +0 -1
- package/build/esm/utils/getCircularIndex.js +0 -8
- package/build/esm/utils/getCircularIndex.js.map +0 -1
- package/build/esm/utils/rubberBandClamp.d.ts +0 -2
- package/build/esm/utils/rubberBandClamp.js +0 -20
- package/build/esm/utils/rubberBandClamp.js.map +0 -1
- package/build/esm/utils/wrapEvent.d.ts +0 -3
- package/build/esm/utils/wrapEvent.js +0 -16
- package/build/esm/utils/wrapEvent.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -7270
package/build/cjs/index.js
CHANGED
|
@@ -7,11 +7,15 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var core = require('@popperjs/core');
|
|
8
8
|
var reactDom = require('react-dom');
|
|
9
9
|
|
|
10
|
+
// AccordionGroup Component
|
|
11
|
+
|
|
10
12
|
const accordionContext = /*#__PURE__*/react.createContext(null);
|
|
11
13
|
const {
|
|
12
14
|
Provider: AccordionProvider
|
|
13
15
|
} = accordionContext;
|
|
14
|
-
const useAccordionContext = () => react.useContext(accordionContext);
|
|
16
|
+
const useAccordionContext = () => react.useContext(accordionContext);
|
|
17
|
+
|
|
18
|
+
// Accordion Component
|
|
15
19
|
|
|
16
20
|
const accordionItemContext = /*#__PURE__*/react.createContext(null);
|
|
17
21
|
const {
|
|
@@ -20,18 +24,16 @@ const {
|
|
|
20
24
|
const useAccordionItemContext = () => react.useContext(accordionItemContext);
|
|
21
25
|
|
|
22
26
|
const tabblable = ['button:enabled:not([readonly])', 'select:enabled:not([readonly])', 'textarea:enabled:not([readonly])', 'input:enabled:not([readonly])', 'a[href]', 'area[href]', 'iframe', 'object', 'embed', '[tabindex]', '[contenteditable]', '[autofocus]'].join(',');
|
|
23
|
-
/* This is naive and will not consider tabIndex */
|
|
24
27
|
|
|
28
|
+
/* This is naive and will not consider tabIndex */
|
|
25
29
|
const getTabblableNodes = parentNode => {
|
|
26
30
|
if (!parentNode) {
|
|
27
31
|
return [];
|
|
28
32
|
}
|
|
29
|
-
|
|
30
33
|
return Array.from(parentNode.querySelectorAll(tabblable));
|
|
31
34
|
};
|
|
32
35
|
function focusOnChildNode(parentNode, itemIndex) {
|
|
33
36
|
const elements = getTabblableNodes(parentNode);
|
|
34
|
-
|
|
35
37
|
if (elements.length > 0) {
|
|
36
38
|
elements[itemIndex === -1 ? elements.length - 1 : 0].focus();
|
|
37
39
|
} else {
|
|
@@ -49,14 +51,13 @@ function useAutoFocus(open, elementRef) {
|
|
|
49
51
|
if (elementRef.current && !elementRef.current.contains(document.activeElement)) {
|
|
50
52
|
focusOnChildNode(elementRef.current, 0);
|
|
51
53
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
56
|
}, [open]);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
function assignRef(ref, value) {
|
|
58
60
|
if (ref == null) return;
|
|
59
|
-
|
|
60
61
|
if (typeof ref === 'function') {
|
|
61
62
|
ref(value);
|
|
62
63
|
} else {
|
|
@@ -81,34 +82,29 @@ function canUseDOM() {
|
|
|
81
82
|
|
|
82
83
|
function createContext(rootName, defaultContext) {
|
|
83
84
|
const Ctx = /*#__PURE__*/react.createContext(defaultContext);
|
|
84
|
-
|
|
85
85
|
function Provider(props) {
|
|
86
86
|
const {
|
|
87
87
|
children,
|
|
88
88
|
...context
|
|
89
89
|
} = props;
|
|
90
|
-
const value = react.useMemo(() => context,
|
|
90
|
+
const value = react.useMemo(() => context,
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
92
|
Object.values(context));
|
|
92
93
|
return /*#__PURE__*/jsxRuntime.jsx(Ctx.Provider, {
|
|
93
94
|
value: value,
|
|
94
95
|
children: children
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
|
-
|
|
98
98
|
function useContext(childName) {
|
|
99
99
|
const context = react.useContext(Ctx);
|
|
100
|
-
|
|
101
100
|
if (context) {
|
|
102
101
|
return context;
|
|
103
102
|
}
|
|
104
|
-
|
|
105
103
|
if (defaultContext) {
|
|
106
104
|
return defaultContext;
|
|
107
105
|
}
|
|
108
|
-
|
|
109
106
|
throw Error(`${childName} must be rendered inside of a ${rootName} component.`);
|
|
110
107
|
}
|
|
111
|
-
|
|
112
108
|
Ctx.displayName = `${rootName}Context`;
|
|
113
109
|
Provider.displayName = `${rootName}Provider`;
|
|
114
110
|
return [Provider, useContext];
|
|
@@ -118,7 +114,6 @@ function getCircularIndex(index, maxLength) {
|
|
|
118
114
|
if (maxLength < 0) {
|
|
119
115
|
return null;
|
|
120
116
|
}
|
|
121
|
-
|
|
122
117
|
return (index % maxLength + maxLength) % maxLength;
|
|
123
118
|
}
|
|
124
119
|
|
|
@@ -137,7 +132,6 @@ function isRightClick(nativeEvent) {
|
|
|
137
132
|
*
|
|
138
133
|
* @param element
|
|
139
134
|
*/
|
|
140
|
-
|
|
141
135
|
function getOwnerDocument(element) {
|
|
142
136
|
return canUseDOM() ? element ? element.ownerDocument : document : null;
|
|
143
137
|
}
|
|
@@ -151,42 +145,39 @@ function rubberBandClamp(min, max, delta, constant = 0.15) {
|
|
|
151
145
|
if (delta < min) {
|
|
152
146
|
return -rubberBand(min - delta, max - min, constant) + min;
|
|
153
147
|
}
|
|
154
|
-
|
|
155
148
|
if (delta > max) {
|
|
156
149
|
return rubberBand(delta - max, max - min, constant) + max;
|
|
157
150
|
}
|
|
158
|
-
|
|
159
151
|
return delta;
|
|
160
152
|
}
|
|
161
153
|
|
|
162
154
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
163
155
|
const useEnhancedEffect$2 = typeof window !== 'undefined' ? react.useLayoutEffect : react.useEffect;
|
|
156
|
+
|
|
164
157
|
/**
|
|
165
158
|
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
166
159
|
* prop and exposed as a stable function to avoid executing effects when
|
|
167
160
|
* passed as a dependency.
|
|
168
161
|
*/
|
|
169
|
-
|
|
170
162
|
function createStableCallbackHook(useEffectHook, callback) {
|
|
171
163
|
const callbackRef = react.useRef(callback);
|
|
172
164
|
useEffectHook(() => {
|
|
173
165
|
callbackRef.current = callback;
|
|
174
|
-
});
|
|
175
|
-
|
|
166
|
+
});
|
|
176
167
|
return react.useCallback((...args) => {
|
|
177
168
|
callbackRef.current && callbackRef.current(...args);
|
|
178
169
|
}, []);
|
|
179
170
|
}
|
|
171
|
+
|
|
180
172
|
/**
|
|
181
173
|
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
182
174
|
* prop and exposed as a stable function to avoid executing effects when passed
|
|
183
175
|
* as a dependency.
|
|
184
176
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
177
|
function useStableCallback(callback) {
|
|
188
178
|
return createStableCallbackHook(react.useEffect, callback);
|
|
189
179
|
}
|
|
180
|
+
|
|
190
181
|
/**
|
|
191
182
|
* Converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
192
183
|
* prop and exposed as a stable function to avoid executing effects when passed
|
|
@@ -196,7 +187,6 @@ function useStableCallback(callback) {
|
|
|
196
187
|
* `useLayoutEffect` instead of `useEffect` to deal with timing issues only when
|
|
197
188
|
* needed.
|
|
198
189
|
*/
|
|
199
|
-
|
|
200
190
|
function useStableLayoutCallback(callback) {
|
|
201
191
|
return createStableCallbackHook(useEnhancedEffect$2, callback);
|
|
202
192
|
}
|
|
@@ -204,11 +194,9 @@ function useStableLayoutCallback(callback) {
|
|
|
204
194
|
function wrapEvent(theirHandler, ourHandler) {
|
|
205
195
|
return (event, ...otherArgs) => {
|
|
206
196
|
const ret = theirHandler && theirHandler(event, ...otherArgs);
|
|
207
|
-
|
|
208
197
|
if (!event || !event.defaultPrevented) {
|
|
209
198
|
return ourHandler(event, ...otherArgs);
|
|
210
199
|
}
|
|
211
|
-
|
|
212
200
|
return ret;
|
|
213
201
|
};
|
|
214
202
|
}
|
|
@@ -218,19 +206,14 @@ function useControlledState(valueProp, onChangeProp, defaultValue, defaultOnChan
|
|
|
218
206
|
const wasControlled = react.useRef(isControlled);
|
|
219
207
|
const hasWarned = react.useRef(false);
|
|
220
208
|
const [valueState, setValueState] = react.useState(defaultValue);
|
|
221
|
-
|
|
222
209
|
if (isControlled) {
|
|
223
210
|
if (!wasControlled.current && !hasWarned.current && process.env.NODE_ENV !== 'production') {
|
|
224
211
|
console.warn('Trying to change from controlled to uncontrolled.');
|
|
225
212
|
hasWarned.current = true;
|
|
226
213
|
}
|
|
227
|
-
|
|
228
|
-
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
229
|
-
valueProp, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
214
|
+
return [valueProp, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
230
215
|
}
|
|
231
|
-
|
|
232
|
-
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
233
|
-
valueState, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
216
|
+
return [valueState, wrapEvent(onChangeProp, defaultOnChange(setValueState))];
|
|
234
217
|
}
|
|
235
218
|
|
|
236
219
|
function useChildrenCounterParent(itemsRef) {
|
|
@@ -259,11 +242,10 @@ function useChildrenCounterChild(itemsRef, itemIndexRef, obj, disabled = false)
|
|
|
259
242
|
if (disabled) {
|
|
260
243
|
itemIndexRef.current = -1;
|
|
261
244
|
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
245
|
+
}
|
|
264
246
|
|
|
247
|
+
// push this option to the optionsRef array
|
|
265
248
|
itemIndexRef.current = itemsRef.current.length;
|
|
266
|
-
|
|
267
249
|
if (obj instanceof Function) {
|
|
268
250
|
itemsRef.current.push(obj(itemIndexRef.current));
|
|
269
251
|
} else {
|
|
@@ -277,7 +259,6 @@ function useFocusReturn(open, rootEl) {
|
|
|
277
259
|
if (open && typeof document !== 'undefined' && document.activeElement instanceof HTMLElement) {
|
|
278
260
|
return document.activeElement;
|
|
279
261
|
}
|
|
280
|
-
|
|
281
262
|
return null;
|
|
282
263
|
})());
|
|
283
264
|
react.useEffect(() => {
|
|
@@ -287,7 +268,6 @@ function useFocusReturn(open, rootEl) {
|
|
|
287
268
|
if (!previousFocusRef.current && document.activeElement instanceof HTMLElement && !rootEl.current?.contains(document.activeElement)) {
|
|
288
269
|
previousFocusRef.current = document.activeElement;
|
|
289
270
|
}
|
|
290
|
-
|
|
291
271
|
const rootElement = rootEl.current;
|
|
292
272
|
const previousElement = previousFocusRef.current;
|
|
293
273
|
return () => {
|
|
@@ -308,15 +288,12 @@ function useFocusState(props = {}) {
|
|
|
308
288
|
onBlur
|
|
309
289
|
} = props;
|
|
310
290
|
const [hasFocus, setHasFocus] = react.useState(false);
|
|
311
|
-
|
|
312
291
|
const handleFocus = () => {
|
|
313
292
|
setHasFocus(true);
|
|
314
293
|
};
|
|
315
|
-
|
|
316
294
|
const handleBlur = () => {
|
|
317
295
|
setHasFocus(false);
|
|
318
296
|
};
|
|
319
|
-
|
|
320
297
|
return {
|
|
321
298
|
bind: {
|
|
322
299
|
onFocus: wrapEvent(onFocus, handleFocus),
|
|
@@ -332,7 +309,6 @@ function useOnClickOutside(ref, handler, active = true) {
|
|
|
332
309
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
333
310
|
return;
|
|
334
311
|
}
|
|
335
|
-
|
|
336
312
|
handler && handler(event);
|
|
337
313
|
}, [ref, handler]);
|
|
338
314
|
react.useEffect(() => {
|
|
@@ -342,7 +318,6 @@ function useOnClickOutside(ref, handler, active = true) {
|
|
|
342
318
|
document.removeEventListener('pointerup', listener);
|
|
343
319
|
};
|
|
344
320
|
}
|
|
345
|
-
|
|
346
321
|
return;
|
|
347
322
|
}, [listener, active]);
|
|
348
323
|
}
|
|
@@ -355,7 +330,6 @@ function useOnKeyDown(ownerWindow, handler, active = true) {
|
|
|
355
330
|
ownerWindow.removeEventListener('keydown', handler);
|
|
356
331
|
};
|
|
357
332
|
}
|
|
358
|
-
|
|
359
333
|
return;
|
|
360
334
|
}, [ownerWindow, active, handler]);
|
|
361
335
|
}
|
|
@@ -368,27 +342,21 @@ function useReducerMachine(chart, reducer, initialData) {
|
|
|
368
342
|
state,
|
|
369
343
|
...data
|
|
370
344
|
} = reducerState;
|
|
371
|
-
|
|
372
345
|
const transition = (action, payload = {}) => {
|
|
373
346
|
const currentState = chart.states[state];
|
|
374
|
-
|
|
375
347
|
if (!currentState) {
|
|
376
348
|
throw new Error(`Unknown currentState "${state}"`);
|
|
377
349
|
}
|
|
378
|
-
|
|
379
350
|
const nextState = currentState.on[action];
|
|
380
|
-
|
|
381
351
|
if (!nextState) {
|
|
382
352
|
throw new Error(`Unknown action "${action}" for state "${state}"`);
|
|
383
353
|
}
|
|
384
|
-
|
|
385
354
|
dispatch({
|
|
386
355
|
type: action,
|
|
387
356
|
nextState,
|
|
388
357
|
...payload
|
|
389
358
|
});
|
|
390
359
|
};
|
|
391
|
-
|
|
392
360
|
return [state, data, transition];
|
|
393
361
|
}
|
|
394
362
|
|
|
@@ -396,26 +364,21 @@ let scrollBodyCount = 0;
|
|
|
396
364
|
function useRemoveBodyScroll(open, elementRef) {
|
|
397
365
|
react.useEffect(() => {
|
|
398
366
|
if (open && elementRef.current) {
|
|
399
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
400
367
|
const ownerDocument = getOwnerDocument(elementRef.current);
|
|
401
368
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
402
|
-
scrollBodyCount += 1;
|
|
369
|
+
scrollBodyCount += 1;
|
|
403
370
|
|
|
371
|
+
// calculate scrollbar width if mounting the first scroll lock
|
|
404
372
|
let scrollBarWidth = 0;
|
|
405
|
-
|
|
406
373
|
if (scrollBodyCount === 1) {
|
|
407
374
|
scrollBarWidth = ownerWindow.innerWidth - ownerDocument.body.clientWidth;
|
|
408
375
|
}
|
|
409
|
-
|
|
410
376
|
ownerDocument.body.style.overflow = 'hidden';
|
|
411
|
-
|
|
412
377
|
if (scrollBarWidth > 0) {
|
|
413
378
|
ownerDocument.body.style.marginRight = `${scrollBarWidth}px`;
|
|
414
379
|
}
|
|
415
|
-
|
|
416
380
|
return () => {
|
|
417
381
|
scrollBodyCount -= 1;
|
|
418
|
-
|
|
419
382
|
if (scrollBodyCount === 0) {
|
|
420
383
|
ownerDocument.body.style.overflow = '';
|
|
421
384
|
ownerDocument.body.style.marginRight = '';
|
|
@@ -455,11 +418,9 @@ function useMeasure(ref) {
|
|
|
455
418
|
setBounds(entry.contentRect);
|
|
456
419
|
});
|
|
457
420
|
}
|
|
458
|
-
|
|
459
421
|
if (ref.current) {
|
|
460
422
|
ro.current.observe(ref.current);
|
|
461
423
|
}
|
|
462
|
-
|
|
463
424
|
return () => {
|
|
464
425
|
if (ro.current) {
|
|
465
426
|
ro.current.disconnect();
|
|
@@ -488,14 +449,14 @@ const initialGestureHandlersState = {
|
|
|
488
449
|
scrollLocked: false
|
|
489
450
|
};
|
|
490
451
|
const FRAMERATE_CONST = 1000 / 60; // 60 fps
|
|
491
|
-
|
|
492
452
|
const VELOCITY_DEPR_FACTOR = FRAMERATE_CONST * 2;
|
|
493
453
|
function gestureHandlers(set, containerRef, options = {}) {
|
|
494
454
|
const {
|
|
495
455
|
ensureTargetIsContainer = false,
|
|
496
456
|
minTouchDelta = 0
|
|
497
|
-
} = options;
|
|
457
|
+
} = options;
|
|
498
458
|
|
|
459
|
+
// Common handlers
|
|
499
460
|
const handleUp = () => {
|
|
500
461
|
set(state => {
|
|
501
462
|
const deltaTime = Date.now() - state.startTime;
|
|
@@ -503,7 +464,8 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
503
464
|
const yDelta = state.y - state.yInitial;
|
|
504
465
|
const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);
|
|
505
466
|
const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);
|
|
506
|
-
const newState = {
|
|
467
|
+
const newState = {
|
|
468
|
+
...state,
|
|
507
469
|
xVelocity,
|
|
508
470
|
yVelocity,
|
|
509
471
|
target: null,
|
|
@@ -512,7 +474,6 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
512
474
|
return newState;
|
|
513
475
|
});
|
|
514
476
|
};
|
|
515
|
-
|
|
516
477
|
const handleDown = e => {
|
|
517
478
|
const {
|
|
518
479
|
target,
|
|
@@ -520,7 +481,8 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
520
481
|
pageY
|
|
521
482
|
} = e;
|
|
522
483
|
set(state => {
|
|
523
|
-
const newState = {
|
|
484
|
+
const newState = {
|
|
485
|
+
...state,
|
|
524
486
|
target,
|
|
525
487
|
x: pageX,
|
|
526
488
|
xDelta: 0,
|
|
@@ -541,38 +503,31 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
541
503
|
return newState;
|
|
542
504
|
});
|
|
543
505
|
};
|
|
544
|
-
|
|
545
506
|
function calcVelocity(deltaSpace, deltaTime, prevVelocity) {
|
|
546
507
|
if (deltaTime < 1) {
|
|
547
508
|
deltaTime = 1;
|
|
548
509
|
}
|
|
549
|
-
|
|
550
510
|
const speed = deltaSpace / deltaTime;
|
|
551
511
|
const depr = 0.5 + Math.min(deltaTime / VELOCITY_DEPR_FACTOR, 0.5);
|
|
552
512
|
return speed * depr + prevVelocity * (1 - depr);
|
|
553
513
|
}
|
|
554
|
-
|
|
555
514
|
function handleMove(e) {
|
|
556
515
|
const {
|
|
557
516
|
pageX,
|
|
558
517
|
pageY
|
|
559
518
|
} = e;
|
|
560
|
-
|
|
561
519
|
if (e.cancelable) {
|
|
562
520
|
// prevent drag & drop behaviour from browser
|
|
563
521
|
e.preventDefault && e.preventDefault();
|
|
564
522
|
}
|
|
565
|
-
|
|
566
523
|
set(state => {
|
|
567
524
|
function getDeltaSum(currentPos, initialPos, prevPos) {
|
|
568
525
|
if (state.scrollLocked || Math.abs(currentPos - initialPos) >= minTouchDelta) {
|
|
569
526
|
state.scrollLocked = true;
|
|
570
527
|
return currentPos - prevPos;
|
|
571
528
|
}
|
|
572
|
-
|
|
573
529
|
return 0;
|
|
574
530
|
}
|
|
575
|
-
|
|
576
531
|
const target = containerRef && containerRef.current || e.target;
|
|
577
532
|
const deltaTime = Date.now() - state.startTime;
|
|
578
533
|
const width = target ? target.offsetWidth : NaN;
|
|
@@ -583,7 +538,8 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
583
538
|
const yDelta = state.yDelta + getDeltaSum(pageY, state.yInitial, state.y);
|
|
584
539
|
const yDeltaPercent = yDelta * 100 / height;
|
|
585
540
|
const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);
|
|
586
|
-
const newState = {
|
|
541
|
+
const newState = {
|
|
542
|
+
...state,
|
|
587
543
|
xDelta,
|
|
588
544
|
xDeltaPercent,
|
|
589
545
|
x: pageX,
|
|
@@ -597,35 +553,28 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
597
553
|
};
|
|
598
554
|
return newState;
|
|
599
555
|
});
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
556
|
+
}
|
|
603
557
|
|
|
558
|
+
// Touch handlers
|
|
604
559
|
|
|
605
560
|
function handleTouchMove(e) {
|
|
606
561
|
if (e.cancelable) {
|
|
607
562
|
// prevent drag & drop behaviour from browser
|
|
608
563
|
e.preventDefault();
|
|
609
564
|
}
|
|
610
|
-
|
|
611
565
|
handleMove(e.touches.item(0));
|
|
612
566
|
}
|
|
613
|
-
|
|
614
567
|
function handleTouchStart(e) {
|
|
615
568
|
// making sure we're not dragging the element when more than one finger press the screen
|
|
616
569
|
const {
|
|
617
570
|
touches
|
|
618
571
|
} = e;
|
|
619
|
-
|
|
620
572
|
if (touches.length > 1) {
|
|
621
573
|
return;
|
|
622
574
|
}
|
|
623
|
-
|
|
624
575
|
if (ensureTargetIsContainer && containerRef && e.target !== containerRef.current) {
|
|
625
576
|
return;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
|
|
577
|
+
}
|
|
629
578
|
const ownerDocument = getOwnerDocument(e.currentTarget);
|
|
630
579
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
631
580
|
ownerWindow.addEventListener('touchmove', handleTouchMove, {
|
|
@@ -635,54 +584,45 @@ function gestureHandlers(set, containerRef, options = {}) {
|
|
|
635
584
|
ownerWindow.addEventListener('touchcancel', handleTouchEnd);
|
|
636
585
|
handleDown(e.touches.item(0));
|
|
637
586
|
}
|
|
638
|
-
|
|
639
587
|
function handleTouchEnd() {
|
|
640
588
|
this.removeEventListener('touchmove', handleTouchMove);
|
|
641
589
|
this.removeEventListener('touchend', handleTouchEnd);
|
|
642
590
|
this.removeEventListener('touchcancel', handleTouchEnd);
|
|
643
591
|
handleUp();
|
|
644
|
-
}
|
|
645
|
-
|
|
592
|
+
}
|
|
646
593
|
|
|
594
|
+
// Mouse handlers
|
|
647
595
|
function handleMouseDown(e) {
|
|
648
596
|
if (ensureTargetIsContainer && containerRef && e.target !== containerRef.current) {
|
|
649
597
|
return;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
|
|
598
|
+
}
|
|
653
599
|
const ownerDocument = getOwnerDocument(e.currentTarget);
|
|
654
600
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
655
|
-
|
|
656
601
|
if (e.button === 0) {
|
|
657
602
|
ownerWindow.addEventListener('mousemove', handleMove);
|
|
658
603
|
ownerWindow.addEventListener('mouseup', handleMouseUp);
|
|
659
604
|
handleDown(e);
|
|
660
605
|
}
|
|
661
606
|
}
|
|
662
|
-
|
|
663
607
|
function handleMouseUp() {
|
|
664
608
|
this.removeEventListener('mousemove', handleMove);
|
|
665
609
|
this.removeEventListener('mouseup', handleMouseUp);
|
|
666
610
|
handleUp();
|
|
667
611
|
}
|
|
668
|
-
/* eslint-enable @typescript-eslint/no-use-before-define */
|
|
669
|
-
|
|
670
|
-
|
|
671
612
|
return {
|
|
672
613
|
onMouseDown: handleMouseDown,
|
|
673
614
|
onTouchStart: handleTouchStart
|
|
674
615
|
};
|
|
675
616
|
}
|
|
676
617
|
const useGestureHandlers = (containerRef, onGesture, options = {}) => {
|
|
677
|
-
const state = react.useRef({
|
|
618
|
+
const state = react.useRef({
|
|
619
|
+
...initialGestureHandlersState
|
|
678
620
|
});
|
|
679
|
-
|
|
680
621
|
const set = cb => {
|
|
681
622
|
state.current = cb(state.current);
|
|
682
623
|
onGesture && onGesture(state.current);
|
|
683
624
|
return state.current;
|
|
684
625
|
};
|
|
685
|
-
|
|
686
626
|
const handlers = gestureHandlers(set, containerRef, options);
|
|
687
627
|
return {
|
|
688
628
|
state: state.current,
|
|
@@ -695,7 +635,6 @@ function getScope(rootRef) {
|
|
|
695
635
|
if (!rootRef.current) {
|
|
696
636
|
return [];
|
|
697
637
|
}
|
|
698
|
-
|
|
699
638
|
const allNodes = rootRef.current.querySelectorAll('*');
|
|
700
639
|
const filtered = [];
|
|
701
640
|
allNodes.forEach(node => {
|
|
@@ -703,19 +642,16 @@ function getScope(rootRef) {
|
|
|
703
642
|
const {
|
|
704
643
|
attributes
|
|
705
644
|
} = node;
|
|
706
|
-
|
|
707
645
|
for (let i = 0; i < attributes.length; i++) {
|
|
708
646
|
const attr = attributes[i];
|
|
709
647
|
props[attr.name] = attr.value;
|
|
710
648
|
}
|
|
711
|
-
|
|
712
649
|
if (matcherFn(node.tagName.toLowerCase(), props, node)) {
|
|
713
650
|
filtered.push(node);
|
|
714
651
|
}
|
|
715
652
|
});
|
|
716
653
|
return filtered;
|
|
717
654
|
};
|
|
718
|
-
|
|
719
655
|
return {
|
|
720
656
|
queryAllNodes
|
|
721
657
|
};
|
|
@@ -733,7 +669,7 @@ const Accordion = /*#__PURE__*/react.forwardRef(function Accordion(props, forwar
|
|
|
733
669
|
...otherProps
|
|
734
670
|
} = props;
|
|
735
671
|
const [childrenHeaderHasFocus, setChildrenHeaderHasFocus] = react.useState(false);
|
|
736
|
-
const ref = react.useRef();
|
|
672
|
+
const ref = react.useRef(null);
|
|
737
673
|
const scope = useScope(ref);
|
|
738
674
|
const contextValue = {
|
|
739
675
|
childrenHeaderHasFocus,
|
|
@@ -796,13 +732,11 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(p
|
|
|
796
732
|
} = props;
|
|
797
733
|
const accordionContext = useAccordionContext();
|
|
798
734
|
const accordionItemContext = useAccordionItemContext();
|
|
799
|
-
const ref = react.useRef();
|
|
735
|
+
const ref = react.useRef(null);
|
|
800
736
|
const [index, setIndex] = react.useState();
|
|
801
|
-
|
|
802
737
|
if (!accordionItemContext) {
|
|
803
738
|
throw new Error('Missing parent <Accordion /> component');
|
|
804
739
|
}
|
|
805
|
-
|
|
806
740
|
react.useEffect(() => {
|
|
807
741
|
if (accordionContext) {
|
|
808
742
|
const allHeaders = accordionContext.scope.current.queryAllNodes(headerScopeQuery) || [];
|
|
@@ -812,23 +746,18 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(p
|
|
|
812
746
|
}, [accordionContext]);
|
|
813
747
|
const onClick = wrapEvent(onClickProp, e => {
|
|
814
748
|
let index = 0;
|
|
815
|
-
|
|
816
749
|
if (accordionItemContext.expanded) {
|
|
817
750
|
index = -1;
|
|
818
751
|
} else if (accordionContext) {
|
|
819
752
|
const allHeaders = accordionContext.scope.current.queryAllNodes(headerScopeQuery) || [];
|
|
820
753
|
index = allHeaders.findIndex(e => e === ref.current);
|
|
821
|
-
|
|
822
754
|
if (index === accordionContext.expandedIndex) {
|
|
823
755
|
index = -1;
|
|
824
756
|
}
|
|
825
|
-
|
|
826
757
|
accordionContext.onChange && accordionContext.onChange(e, index);
|
|
827
758
|
}
|
|
828
|
-
|
|
829
759
|
accordionItemContext.onChange && accordionItemContext.onChange(e, index >= 0);
|
|
830
760
|
});
|
|
831
|
-
|
|
832
761
|
const handleKeyDown = e => {
|
|
833
762
|
switch (e.key) {
|
|
834
763
|
case 'Enter':
|
|
@@ -838,7 +767,6 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(p
|
|
|
838
767
|
e.preventDefault();
|
|
839
768
|
break;
|
|
840
769
|
}
|
|
841
|
-
|
|
842
770
|
case 'ArrowUp':
|
|
843
771
|
case 'ArrowDown':
|
|
844
772
|
case 'Home':
|
|
@@ -847,46 +775,36 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(p
|
|
|
847
775
|
if (!accordionContext) {
|
|
848
776
|
return;
|
|
849
777
|
}
|
|
850
|
-
|
|
851
778
|
const allHeaders = accordionContext.scope.current.queryAllNodes(headerScopeQuery);
|
|
852
779
|
e.preventDefault();
|
|
853
|
-
|
|
854
780
|
if (allHeaders.length === 0) {
|
|
855
781
|
return;
|
|
856
782
|
}
|
|
857
|
-
|
|
858
783
|
let nextIndex = allHeaders.findIndex(e => e === ref.current);
|
|
859
|
-
|
|
860
784
|
switch (e.key) {
|
|
861
785
|
case 'ArrowUp':
|
|
862
786
|
nextIndex += -1;
|
|
863
787
|
break;
|
|
864
|
-
|
|
865
788
|
case 'ArrowDown':
|
|
866
789
|
nextIndex += +1;
|
|
867
790
|
break;
|
|
868
|
-
|
|
869
791
|
case 'Home':
|
|
870
792
|
nextIndex = 0;
|
|
871
793
|
break;
|
|
872
|
-
|
|
873
794
|
case 'End':
|
|
874
795
|
nextIndex = -1;
|
|
875
796
|
break;
|
|
876
|
-
}
|
|
877
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
878
|
-
|
|
797
|
+
}
|
|
879
798
|
|
|
799
|
+
// We're sure it will not be null, because we already checked for allHeaders.length > 0 above
|
|
880
800
|
nextIndex = getCircularIndex(nextIndex, allHeaders.length);
|
|
881
801
|
allHeaders[nextIndex] && allHeaders[nextIndex].focus();
|
|
882
802
|
break;
|
|
883
803
|
}
|
|
884
|
-
|
|
885
804
|
default:
|
|
886
805
|
return;
|
|
887
806
|
}
|
|
888
807
|
};
|
|
889
|
-
|
|
890
808
|
const handleFocus = () => {
|
|
891
809
|
if (accordionContext) {
|
|
892
810
|
if (!accordionContext.childrenHeaderHasFocus) {
|
|
@@ -896,19 +814,18 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(p
|
|
|
896
814
|
}
|
|
897
815
|
}
|
|
898
816
|
};
|
|
899
|
-
|
|
900
817
|
const handleBlur = e => {
|
|
901
818
|
if (accordionContext) {
|
|
902
819
|
const allHeaders = accordionContext.scope.current.queryAllNodes(headerScopeQuery);
|
|
903
|
-
const newFocusIsHeader = allHeaders.findIndex(header => header === e.relatedTarget) >= 0;
|
|
904
|
-
// that is not an accordion header
|
|
820
|
+
const newFocusIsHeader = allHeaders.findIndex(header => header === e.relatedTarget) >= 0;
|
|
905
821
|
|
|
822
|
+
// only remove focus flag if the focus went to some element
|
|
823
|
+
// that is not an accordion header
|
|
906
824
|
if (!newFocusIsHeader) {
|
|
907
825
|
accordionContext.setChildrenHeaderHasFocus(false);
|
|
908
826
|
}
|
|
909
827
|
}
|
|
910
828
|
};
|
|
911
|
-
|
|
912
829
|
const expanded = Boolean(accordionItemContext.expanded || accordionContext && accordionContext.expandedIndex === index);
|
|
913
830
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
914
831
|
ref: assignMultipleRefs(ref, forwardedRef),
|
|
@@ -933,13 +850,11 @@ const AccordionBody = /*#__PURE__*/react.forwardRef(function AccordionBody(props
|
|
|
933
850
|
} = props;
|
|
934
851
|
const accordionItemContext = useAccordionItemContext();
|
|
935
852
|
const accordionContext = useAccordionContext();
|
|
936
|
-
const ref = react.useRef();
|
|
853
|
+
const ref = react.useRef(null);
|
|
937
854
|
const [index, setIndex] = react.useState();
|
|
938
|
-
|
|
939
855
|
if (!accordionItemContext) {
|
|
940
856
|
throw new Error('Missing parent <Accordion /> component');
|
|
941
857
|
}
|
|
942
|
-
|
|
943
858
|
react.useEffect(() => {
|
|
944
859
|
if (accordionContext) {
|
|
945
860
|
const allHeaders = accordionContext.scope.current.queryAllNodes(bodyScopeQuery);
|
|
@@ -990,32 +905,41 @@ function scopeQuery$1(nodeType, props) {
|
|
|
990
905
|
return props['data-reach-combobox-option'] === '';
|
|
991
906
|
}
|
|
992
907
|
|
|
993
|
-
|
|
908
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
994
909
|
// States
|
|
995
|
-
// Nothing going on, waiting for the user to type or use the arrow keys
|
|
996
910
|
|
|
997
|
-
|
|
911
|
+
// Nothing going on, waiting for the user to type or use the arrow keys
|
|
912
|
+
const IDLE = 'IDLE';
|
|
998
913
|
|
|
999
|
-
|
|
914
|
+
// The component is suggesting options as the user types
|
|
915
|
+
const SUGGESTING = 'SUGGESTING';
|
|
1000
916
|
|
|
917
|
+
// The user is using the keyboard to navigate the list, not typing
|
|
1001
918
|
const NAVIGATING = 'NAVIGATING';
|
|
1002
919
|
////////////////////////////////////////////////////////////////////////////////
|
|
1003
920
|
// Actions:
|
|
921
|
+
|
|
1004
922
|
// Used to sync the state with controlled state, right after mounting
|
|
1005
|
-
const INIT = 'INIT';
|
|
923
|
+
const INIT = 'INIT';
|
|
1006
924
|
|
|
1007
|
-
|
|
925
|
+
// User cleared the value w/ backspace, but input still has focus
|
|
926
|
+
const CLEAR = 'CLEAR';
|
|
1008
927
|
|
|
1009
|
-
|
|
928
|
+
// User cleared the value w/ backspace, but input still has focus
|
|
929
|
+
const CLEAR_SELECTION = 'CLEAR_SELECTION';
|
|
1010
930
|
|
|
1011
|
-
|
|
931
|
+
// User is typing
|
|
932
|
+
const CHANGE = 'CHANGE';
|
|
1012
933
|
|
|
1013
|
-
|
|
1014
|
-
|
|
934
|
+
// User is navigating w/ the keyboard
|
|
935
|
+
const NAVIGATE = 'NAVIGATE';
|
|
1015
936
|
|
|
937
|
+
// User can be navigating with keyboard and then click instead, we want the
|
|
938
|
+
// value from the click, not the current nav item
|
|
1016
939
|
const SELECT_WITH_KEYBOARD = 'SELECT_WITH_KEYBOARD';
|
|
1017
|
-
const SELECT_WITH_CLICK = 'SELECT_WITH_CLICK';
|
|
940
|
+
const SELECT_WITH_CLICK = 'SELECT_WITH_CLICK';
|
|
1018
941
|
|
|
942
|
+
// Pretty self-explanatory, user can hit escape or blur to close the popover
|
|
1019
943
|
const ESCAPE = 'ESCAPE';
|
|
1020
944
|
const BLUR = 'BLUR';
|
|
1021
945
|
const FOCUS = 'FOCUS';
|
|
@@ -1069,82 +993,84 @@ const stateChart = {
|
|
|
1069
993
|
}
|
|
1070
994
|
};
|
|
1071
995
|
function comboboxReducer(data, action) {
|
|
1072
|
-
const nextState = {
|
|
996
|
+
const nextState = {
|
|
997
|
+
...data,
|
|
1073
998
|
state: action.nextState,
|
|
1074
999
|
lastActionType: action.type
|
|
1075
1000
|
};
|
|
1076
|
-
|
|
1077
1001
|
switch (action.type) {
|
|
1078
1002
|
case INIT:
|
|
1079
1003
|
case CHANGE:
|
|
1080
|
-
return {
|
|
1004
|
+
return {
|
|
1005
|
+
...nextState,
|
|
1081
1006
|
text: action.text,
|
|
1082
1007
|
navigationItem: '',
|
|
1083
1008
|
item: ''
|
|
1084
1009
|
};
|
|
1085
|
-
|
|
1086
1010
|
case NAVIGATE:
|
|
1087
1011
|
case OPEN_WITH_BUTTON:
|
|
1088
1012
|
if (action.persistSelection) {
|
|
1089
|
-
return {
|
|
1013
|
+
return {
|
|
1014
|
+
...nextState,
|
|
1090
1015
|
navigationItem: data.item
|
|
1091
1016
|
};
|
|
1092
1017
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1018
|
+
return {
|
|
1019
|
+
...nextState,
|
|
1095
1020
|
navigationItem: action.item
|
|
1096
1021
|
};
|
|
1097
|
-
|
|
1098
1022
|
case CLEAR_SELECTION:
|
|
1099
|
-
return {
|
|
1023
|
+
return {
|
|
1024
|
+
...nextState,
|
|
1100
1025
|
navigationItem: ''
|
|
1101
1026
|
};
|
|
1102
|
-
|
|
1103
1027
|
case CLEAR:
|
|
1104
|
-
return {
|
|
1028
|
+
return {
|
|
1029
|
+
...nextState,
|
|
1105
1030
|
text: '',
|
|
1106
1031
|
navigationItem: '',
|
|
1107
1032
|
item: ''
|
|
1108
1033
|
};
|
|
1109
|
-
|
|
1110
1034
|
case BLUR:
|
|
1111
|
-
return {
|
|
1035
|
+
return {
|
|
1036
|
+
...nextState,
|
|
1112
1037
|
text: action.text,
|
|
1113
1038
|
navigationItem: '',
|
|
1114
1039
|
item: action.item
|
|
1115
1040
|
};
|
|
1116
|
-
|
|
1117
1041
|
case CLOSE_WITH_BUTTON:
|
|
1118
1042
|
case ESCAPE:
|
|
1119
|
-
return {
|
|
1043
|
+
return {
|
|
1044
|
+
...nextState,
|
|
1120
1045
|
navigationItem: '',
|
|
1121
1046
|
item: ''
|
|
1122
1047
|
};
|
|
1123
|
-
|
|
1124
1048
|
case SELECT_WITH_CLICK:
|
|
1125
1049
|
case SELECT_WITH_KEYBOARD:
|
|
1126
|
-
return {
|
|
1050
|
+
return {
|
|
1051
|
+
...nextState,
|
|
1127
1052
|
text: action.text,
|
|
1128
1053
|
item: action.item,
|
|
1129
1054
|
navigationItem: ''
|
|
1130
1055
|
};
|
|
1131
|
-
|
|
1132
1056
|
case FOCUS:
|
|
1133
|
-
return {
|
|
1057
|
+
return {
|
|
1058
|
+
...nextState,
|
|
1134
1059
|
navigationItem: action.item
|
|
1135
1060
|
};
|
|
1136
|
-
|
|
1137
1061
|
default:
|
|
1138
1062
|
throw new Error(`Unknown action ${action.type}`);
|
|
1139
1063
|
}
|
|
1140
1064
|
}
|
|
1141
1065
|
const visibleStates = [SUGGESTING, NAVIGATING];
|
|
1142
|
-
const isVisible = state => visibleStates.indexOf(state) >= 0;
|
|
1066
|
+
const isVisible = state => visibleStates.indexOf(state) >= 0;
|
|
1067
|
+
|
|
1068
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1143
1069
|
// The rest is all implementation details
|
|
1070
|
+
|
|
1144
1071
|
// Move focus back to the input if we start navigating w/ the
|
|
1145
1072
|
// keyboard after focus has moved to any focusable content in
|
|
1146
1073
|
// the popup.
|
|
1147
|
-
|
|
1148
1074
|
function useFocusManagement(lastActionType, inputRef) {
|
|
1149
1075
|
// useEffect so that the cursor goes to the end of the input instead
|
|
1150
1076
|
// of awkwardly at the beginning, unclear to me why ...
|
|
@@ -1154,34 +1080,29 @@ function useFocusManagement(lastActionType, inputRef) {
|
|
|
1154
1080
|
}
|
|
1155
1081
|
});
|
|
1156
1082
|
}
|
|
1157
|
-
|
|
1158
1083
|
function getNextItem(currentItem, key, optionsItems, autocomplete) {
|
|
1159
1084
|
const jumpToStartOrEnd = key === 'Home' || key === 'End';
|
|
1160
1085
|
let incr = 1;
|
|
1161
|
-
|
|
1162
1086
|
switch (key) {
|
|
1163
1087
|
case 'PageUp':
|
|
1164
1088
|
incr = -10;
|
|
1165
1089
|
break;
|
|
1166
|
-
|
|
1167
1090
|
case 'PageDown':
|
|
1168
1091
|
incr = 10;
|
|
1169
1092
|
break;
|
|
1170
|
-
|
|
1171
1093
|
case 'End':
|
|
1172
1094
|
case 'ArrowUp':
|
|
1173
1095
|
incr = -1;
|
|
1174
1096
|
break;
|
|
1175
|
-
|
|
1176
1097
|
case 'Home':
|
|
1177
1098
|
case 'ArrowDown':
|
|
1178
1099
|
incr = 1;
|
|
1179
1100
|
break;
|
|
1180
1101
|
}
|
|
1181
|
-
|
|
1182
1102
|
const index = currentItem === '' ? -1 : optionsItems.findIndex(n => String(n.id) === currentItem);
|
|
1183
|
-
const optionsLen = optionsItems.length;
|
|
1103
|
+
const optionsLen = optionsItems.length;
|
|
1184
1104
|
|
|
1105
|
+
// Nothing selected, either go to start, or end
|
|
1185
1106
|
if (index < 0 || jumpToStartOrEnd) {
|
|
1186
1107
|
if (incr > 0) {
|
|
1187
1108
|
// Go to start
|
|
@@ -1192,20 +1113,18 @@ function getNextItem(currentItem, key, optionsItems, autocomplete) {
|
|
|
1192
1113
|
}
|
|
1193
1114
|
} else if (autocomplete) {
|
|
1194
1115
|
const nextIndex = index + incr;
|
|
1195
|
-
|
|
1196
1116
|
if (nextIndex < 0 || nextIndex >= optionsLen) {
|
|
1197
1117
|
// Next is outside the bounds of list, return nothing selected
|
|
1198
1118
|
return null;
|
|
1199
1119
|
}
|
|
1200
|
-
}
|
|
1201
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1202
|
-
|
|
1120
|
+
}
|
|
1203
1121
|
|
|
1122
|
+
// I'm sure it won't be null, we already check optionsLen above
|
|
1204
1123
|
return optionsItems[getCircularIndex(index + incr, optionsLen)];
|
|
1205
|
-
}
|
|
1206
|
-
// HOOKS BTW?) This is probably the hairiest piece but it's not bad.
|
|
1207
|
-
|
|
1124
|
+
}
|
|
1208
1125
|
|
|
1126
|
+
// We want the same events when the input or the popup have focus (HOW COOL ARE
|
|
1127
|
+
// HOOKS BTW?) This is probably the hairiest piece but it's not bad.
|
|
1209
1128
|
function useKeyDown() {
|
|
1210
1129
|
const {
|
|
1211
1130
|
data: {
|
|
@@ -1224,7 +1143,6 @@ function useKeyDown() {
|
|
|
1224
1143
|
} = useComboBoxContext();
|
|
1225
1144
|
return function handleKeyDown(event) {
|
|
1226
1145
|
const optionNodes = listScope.current.queryAllNodes(scopeQuery$1);
|
|
1227
|
-
|
|
1228
1146
|
switch (event.key) {
|
|
1229
1147
|
case 'Home':
|
|
1230
1148
|
case 'End':
|
|
@@ -1235,14 +1153,14 @@ function useKeyDown() {
|
|
|
1235
1153
|
{
|
|
1236
1154
|
// Don't scroll the page
|
|
1237
1155
|
event.preventDefault();
|
|
1238
|
-
const optionsLen = optionNodes.length;
|
|
1156
|
+
const optionsLen = optionNodes.length;
|
|
1157
|
+
|
|
1158
|
+
// If the developer didn't render any options, there's no point in
|
|
1239
1159
|
// trying to navigate--but seriously what the heck? Give us some
|
|
1240
1160
|
// options fam.
|
|
1241
|
-
|
|
1242
1161
|
if (optionsLen === 0) {
|
|
1243
1162
|
return;
|
|
1244
1163
|
}
|
|
1245
|
-
|
|
1246
1164
|
if (state === IDLE) {
|
|
1247
1165
|
// Opening a closed list
|
|
1248
1166
|
transition(NAVIGATE, {
|
|
@@ -1250,10 +1168,10 @@ function useKeyDown() {
|
|
|
1250
1168
|
});
|
|
1251
1169
|
} else {
|
|
1252
1170
|
// When autocompletting, we'll not cycle through the list directly
|
|
1253
|
-
const autocomplete = autocompletePropRef.current;
|
|
1171
|
+
const autocomplete = autocompletePropRef.current;
|
|
1254
1172
|
|
|
1173
|
+
// Get next selected item
|
|
1255
1174
|
const nextItem = getNextItem(navigationItem, event.key, optionNodes, autocomplete);
|
|
1256
|
-
|
|
1257
1175
|
if (nextItem !== null) {
|
|
1258
1176
|
nextItem.scrollIntoView({
|
|
1259
1177
|
behavior: 'auto',
|
|
@@ -1270,10 +1188,8 @@ function useKeyDown() {
|
|
|
1270
1188
|
});
|
|
1271
1189
|
}
|
|
1272
1190
|
}
|
|
1273
|
-
|
|
1274
1191
|
break;
|
|
1275
1192
|
}
|
|
1276
|
-
|
|
1277
1193
|
case 'Escape':
|
|
1278
1194
|
{
|
|
1279
1195
|
if (state !== IDLE) {
|
|
@@ -1281,34 +1197,31 @@ function useKeyDown() {
|
|
|
1281
1197
|
} else if (state === IDLE && text !== '') {
|
|
1282
1198
|
if (!inputRef.current || !clearOnEscapeRef.current) {
|
|
1283
1199
|
break;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1200
|
+
}
|
|
1286
1201
|
|
|
1202
|
+
// emulate a inputRef change event, might not work in future versions of React
|
|
1287
1203
|
const lastValue = inputRef.current.value;
|
|
1288
1204
|
inputRef.current.value = '';
|
|
1289
1205
|
const tracker = inputRef.current._valueTracker;
|
|
1290
|
-
|
|
1291
1206
|
if (tracker) {
|
|
1292
1207
|
tracker.setValue(lastValue);
|
|
1293
1208
|
}
|
|
1294
|
-
|
|
1295
1209
|
const event = new Event('change', {
|
|
1296
1210
|
bubbles: true
|
|
1297
1211
|
});
|
|
1298
1212
|
inputRef.current.dispatchEvent(event);
|
|
1299
1213
|
}
|
|
1300
|
-
|
|
1301
1214
|
break;
|
|
1302
1215
|
}
|
|
1303
|
-
|
|
1304
1216
|
case 'Enter':
|
|
1305
1217
|
{
|
|
1306
1218
|
if (state === NAVIGATING && navigationItem !== '') {
|
|
1307
1219
|
const {
|
|
1308
1220
|
value: navigationValue,
|
|
1309
1221
|
text: navigationText
|
|
1310
|
-
} = optionsRef.current[navigationItem];
|
|
1222
|
+
} = optionsRef.current[navigationItem];
|
|
1311
1223
|
|
|
1224
|
+
// don't want to submit forms
|
|
1312
1225
|
event.preventDefault();
|
|
1313
1226
|
onSelect && onSelect(navigationText, navigationItem, navigationValue);
|
|
1314
1227
|
transition(SELECT_WITH_KEYBOARD, {
|
|
@@ -1316,7 +1229,6 @@ function useKeyDown() {
|
|
|
1316
1229
|
item: navigationItem
|
|
1317
1230
|
});
|
|
1318
1231
|
}
|
|
1319
|
-
|
|
1320
1232
|
break;
|
|
1321
1233
|
}
|
|
1322
1234
|
}
|
|
@@ -1335,7 +1247,6 @@ function useBlur() {
|
|
|
1335
1247
|
buttonRef,
|
|
1336
1248
|
onSelect,
|
|
1337
1249
|
selectOnBlur // not implemented yet
|
|
1338
|
-
|
|
1339
1250
|
} = useComboBoxContext();
|
|
1340
1251
|
return function handleBlur() {
|
|
1341
1252
|
requestAnimationFrame(() => {
|
|
@@ -1387,22 +1298,24 @@ const Combobox = /*#__PURE__*/react.forwardRef(function Combobox({
|
|
|
1387
1298
|
const optionsRef = react.useRef({});
|
|
1388
1299
|
const listScope = react.useRef(getScope({
|
|
1389
1300
|
current: null
|
|
1390
|
-
}));
|
|
1301
|
+
}));
|
|
1391
1302
|
|
|
1303
|
+
// Need this to focus it
|
|
1392
1304
|
const inputRef = react.useRef(null);
|
|
1393
1305
|
const popoverRef = react.useRef(null);
|
|
1394
|
-
const buttonRef = react.useRef(null);
|
|
1306
|
+
const buttonRef = react.useRef(null);
|
|
1307
|
+
|
|
1308
|
+
// When <ComboboxInput autocomplete={false} /> we don't want cycle back to
|
|
1395
1309
|
// the user's value while navigating (because it's always the user's value),
|
|
1396
1310
|
// but we need to know this in useKeyDown which is far away from the prop
|
|
1397
1311
|
// here, so we do something sneaky and write it to this ref on context so we
|
|
1398
1312
|
// can use it anywhere else 😛. Another new trick for me and I'm excited
|
|
1399
1313
|
// about this one too!
|
|
1400
|
-
|
|
1401
1314
|
const autocompletePropRef = react.useRef(false);
|
|
1402
1315
|
const persistSelectionRef = react.useRef(false);
|
|
1403
1316
|
const clearOnEscapeRef = react.useRef(false);
|
|
1404
|
-
const listboxIdRef = react.useRef();
|
|
1405
|
-
const labelIdRef = react.useRef();
|
|
1317
|
+
const listboxIdRef = react.useRef(undefined);
|
|
1318
|
+
const labelIdRef = react.useRef(undefined);
|
|
1406
1319
|
const defaultData = {
|
|
1407
1320
|
// initial state
|
|
1408
1321
|
state: stateChart.initial,
|
|
@@ -1441,7 +1354,8 @@ const Combobox = /*#__PURE__*/react.forwardRef(function Combobox({
|
|
|
1441
1354
|
}), [data, onSelect, listScope, state, transition, openOnFocus, selectOnBlur]);
|
|
1442
1355
|
return /*#__PURE__*/jsxRuntime.jsx(ComboBoxProvider, {
|
|
1443
1356
|
value: context,
|
|
1444
|
-
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1357
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1358
|
+
...rest,
|
|
1445
1359
|
as: innerAs,
|
|
1446
1360
|
"data-reach-combobox": "",
|
|
1447
1361
|
ref: ref,
|
|
@@ -1470,19 +1384,16 @@ const ComboboxButton = /*#__PURE__*/react.forwardRef(function ComboboxButton({
|
|
|
1470
1384
|
isVisible
|
|
1471
1385
|
} = useComboBoxContext();
|
|
1472
1386
|
const handleKeyDown = useKeyDown();
|
|
1473
|
-
|
|
1474
1387
|
const handleClick = () => {
|
|
1475
1388
|
const payload = {
|
|
1476
1389
|
item: data.navigationItem
|
|
1477
1390
|
};
|
|
1478
|
-
|
|
1479
1391
|
if (state === IDLE) {
|
|
1480
1392
|
transition(OPEN_WITH_BUTTON, payload);
|
|
1481
1393
|
} else {
|
|
1482
1394
|
transition(CLOSE_WITH_BUTTON, payload);
|
|
1483
1395
|
}
|
|
1484
1396
|
};
|
|
1485
|
-
|
|
1486
1397
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1487
1398
|
as: innerAs,
|
|
1488
1399
|
"data-reach-combobox-button": "",
|
|
@@ -1529,27 +1440,31 @@ const ComboboxInput = /*#__PURE__*/react.forwardRef(function ComboboxInput({
|
|
|
1529
1440
|
openOnFocus,
|
|
1530
1441
|
optionsRef,
|
|
1531
1442
|
labelIdRef
|
|
1532
|
-
} = useComboBoxContext();
|
|
1443
|
+
} = useComboBoxContext();
|
|
1533
1444
|
|
|
1534
|
-
|
|
1445
|
+
// Keep focus on the input component
|
|
1446
|
+
useFocusManagement(lastActionType, inputRef);
|
|
1535
1447
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1448
|
+
// Keep using the defaultValue until the user started interacting
|
|
1449
|
+
const hasStartedInteracting = react.useRef(false);
|
|
1538
1450
|
|
|
1451
|
+
// Because we close the List on blur, we need to track if the blur is
|
|
1452
|
+
// caused by clicking inside the list, and if so, don't close the List.
|
|
1539
1453
|
const selectOnClickRef = react.useRef(false);
|
|
1540
|
-
const handleBlur = useBlur();
|
|
1454
|
+
const handleBlur = useBlur();
|
|
1541
1455
|
|
|
1456
|
+
// Update ref props
|
|
1542
1457
|
autocompletePropRef.current = autocomplete;
|
|
1543
1458
|
clearOnEscapeRef.current = clearOnEscape;
|
|
1544
|
-
listboxIdRef.current = preferredId || listboxIdRef.current;
|
|
1459
|
+
listboxIdRef.current = preferredId || listboxIdRef.current;
|
|
1460
|
+
|
|
1461
|
+
// [*]... and when controlled, we don't trigger handleValueChange as the user
|
|
1545
1462
|
// types, instead the developer controls it with the normal input onChange
|
|
1546
1463
|
// prop
|
|
1547
|
-
|
|
1548
1464
|
const handleChange = e => {
|
|
1549
1465
|
// After the user started typing, lets forget the defaultValue
|
|
1550
1466
|
hasStartedInteracting.current = true;
|
|
1551
1467
|
const text = e.target.value;
|
|
1552
|
-
|
|
1553
1468
|
if (text.trim() === '') {
|
|
1554
1469
|
transition(CLEAR);
|
|
1555
1470
|
} else {
|
|
@@ -1558,46 +1473,45 @@ const ComboboxInput = /*#__PURE__*/react.forwardRef(function ComboboxInput({
|
|
|
1558
1473
|
});
|
|
1559
1474
|
}
|
|
1560
1475
|
};
|
|
1561
|
-
|
|
1562
1476
|
const handleKeyDown = useKeyDown();
|
|
1563
|
-
|
|
1564
1477
|
const handleFocus = () => {
|
|
1565
1478
|
if (selectOnClick) {
|
|
1566
1479
|
selectOnClickRef.current = true;
|
|
1567
|
-
}
|
|
1480
|
+
}
|
|
1481
|
+
// If we select an option with click, useFocusManagement will focus the
|
|
1568
1482
|
// input, in those cases we don't want to cause the menu to open back up,
|
|
1569
1483
|
// so we guard behind these states
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
1484
|
if (openOnFocus && lastActionType !== SELECT_WITH_CLICK) {
|
|
1573
1485
|
transition(FOCUS, {
|
|
1574
1486
|
item: navigationItem
|
|
1575
1487
|
});
|
|
1576
1488
|
}
|
|
1577
1489
|
};
|
|
1578
|
-
|
|
1579
1490
|
const handleClick = () => {
|
|
1580
1491
|
if (selectOnClickRef.current) {
|
|
1581
1492
|
selectOnClickRef.current = false;
|
|
1582
1493
|
inputRef.current && inputRef.current.select();
|
|
1583
1494
|
}
|
|
1584
1495
|
};
|
|
1585
|
-
|
|
1586
1496
|
const navigationText = navigationItem !== '' ? optionsRef.current[navigationItem].text : undefined;
|
|
1587
1497
|
const fallbackValue = hasStartedInteracting.current ? '' : defaultValue;
|
|
1588
|
-
const inputStrings =
|
|
1498
|
+
const inputStrings =
|
|
1499
|
+
// When idle, we don't have a navigationText on ArrowUp/Down
|
|
1589
1500
|
autocomplete && state === NAVIGATING ? [navigationText, controlledValue, text, fallbackValue] : [controlledValue, text, fallbackValue];
|
|
1590
|
-
const inputValue = inputStrings.find(str => str !== undefined);
|
|
1501
|
+
const inputValue = inputStrings.find(str => str !== undefined);
|
|
1502
|
+
|
|
1503
|
+
// If they are controlling the value we still need to do our transitions, so
|
|
1591
1504
|
// we have this derived state to emulate onChange of the input as we receive
|
|
1592
1505
|
// new `value`s ...[*]
|
|
1593
|
-
|
|
1594
1506
|
react.useEffect(() => {
|
|
1595
1507
|
transition(INIT, {
|
|
1596
1508
|
text: inputValue,
|
|
1597
1509
|
item: ''
|
|
1598
|
-
});
|
|
1510
|
+
});
|
|
1511
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1599
1512
|
}, []);
|
|
1600
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1513
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1514
|
+
...props,
|
|
1601
1515
|
as: innerAs,
|
|
1602
1516
|
"data-reach-combobox-input": "",
|
|
1603
1517
|
ref: assignMultipleRefs(inputRef, forwardedRef),
|
|
@@ -1649,12 +1563,13 @@ const ComboboxList = /*#__PURE__*/react.forwardRef(function ComboboxList({
|
|
|
1649
1563
|
labelIdRef,
|
|
1650
1564
|
listScope
|
|
1651
1565
|
} = useComboBoxContext();
|
|
1652
|
-
const listRef = react.useRef();
|
|
1566
|
+
const listRef = react.useRef(null);
|
|
1653
1567
|
react.useEffect(() => {
|
|
1654
1568
|
listScope.current = getScope(listRef);
|
|
1655
1569
|
}, [listScope]);
|
|
1656
1570
|
persistSelectionRef.current = persistSelection;
|
|
1657
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1571
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1572
|
+
...props,
|
|
1658
1573
|
as: innerAs,
|
|
1659
1574
|
ref: assignMultipleRefs(ref, listRef),
|
|
1660
1575
|
"data-reach-combobox-list": "",
|
|
@@ -1672,21 +1587,17 @@ const ComboboxList = /*#__PURE__*/react.forwardRef(function ComboboxList({
|
|
|
1672
1587
|
// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
|
|
1673
1588
|
function makeHash(str) {
|
|
1674
1589
|
let hash = 0;
|
|
1675
|
-
|
|
1676
1590
|
if (str.length === 0) {
|
|
1677
1591
|
return hash;
|
|
1678
1592
|
}
|
|
1679
|
-
|
|
1680
1593
|
for (let i = 0; i < str.length; i++) {
|
|
1681
1594
|
const char = str.charCodeAt(i);
|
|
1682
1595
|
hash = (hash << 5) - hash + char;
|
|
1683
1596
|
hash = hash & hash;
|
|
1684
1597
|
}
|
|
1685
|
-
|
|
1686
1598
|
return hash;
|
|
1687
1599
|
}
|
|
1688
1600
|
|
|
1689
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
1690
1601
|
const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
1691
1602
|
children,
|
|
1692
1603
|
id: idProp,
|
|
@@ -1709,7 +1620,6 @@ const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
|
1709
1620
|
const isActiveRef = react.useRef(false);
|
|
1710
1621
|
const value = valueProp;
|
|
1711
1622
|
let text = textProp ? textProp : '';
|
|
1712
|
-
|
|
1713
1623
|
if (text.length === 0) {
|
|
1714
1624
|
if (typeof valueProp === 'string' && valueProp.length > 0) {
|
|
1715
1625
|
text = valueProp;
|
|
@@ -1717,7 +1627,6 @@ const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
|
1717
1627
|
throw new Error('Missing text for <ComboboxOption />');
|
|
1718
1628
|
}
|
|
1719
1629
|
}
|
|
1720
|
-
|
|
1721
1630
|
const id = String(makeHash(idProp));
|
|
1722
1631
|
react.useEffect(() => {
|
|
1723
1632
|
const opts = optionsRef.current;
|
|
@@ -1728,10 +1637,11 @@ const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
|
1728
1637
|
return () => {
|
|
1729
1638
|
delete opts[id];
|
|
1730
1639
|
};
|
|
1731
|
-
}, [optionsRef, id, text, value]);
|
|
1640
|
+
}, [optionsRef, id, text, value]);
|
|
1641
|
+
|
|
1642
|
+
// Keep updating this ref with the current
|
|
1732
1643
|
// function pointer for transition, so it can
|
|
1733
1644
|
// be used by the unmount effect below.
|
|
1734
|
-
|
|
1735
1645
|
transitionCleanupRef.current = transition;
|
|
1736
1646
|
isActiveRef.current = navigationItem === id;
|
|
1737
1647
|
react.useEffect(() => {
|
|
@@ -1743,7 +1653,6 @@ const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
|
1743
1653
|
}
|
|
1744
1654
|
};
|
|
1745
1655
|
}, []);
|
|
1746
|
-
|
|
1747
1656
|
const handleClick = () => {
|
|
1748
1657
|
onSelect && onSelect(text, id, value);
|
|
1749
1658
|
transition(SELECT_WITH_CLICK, {
|
|
@@ -1751,15 +1660,16 @@ const ComboboxOption = /*#__PURE__*/react.forwardRef(function ComboboxOption({
|
|
|
1751
1660
|
item: id
|
|
1752
1661
|
});
|
|
1753
1662
|
};
|
|
1754
|
-
|
|
1755
|
-
|
|
1663
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1664
|
+
...props,
|
|
1756
1665
|
as: innerAs,
|
|
1757
1666
|
"data-reach-combobox-option": "",
|
|
1758
1667
|
ref: ref,
|
|
1759
1668
|
id: id,
|
|
1760
1669
|
role: "option",
|
|
1761
1670
|
"aria-selected": isActiveRef.current,
|
|
1762
|
-
"data-highlighted": isActiveRef.current ? '' : undefined
|
|
1671
|
+
"data-highlighted": isActiveRef.current ? '' : undefined
|
|
1672
|
+
// without this the menu will close from `onBlur`, but with it the
|
|
1763
1673
|
// element can be `document.activeElement` and then our focus checks in
|
|
1764
1674
|
// onBlur will work as intended
|
|
1765
1675
|
,
|
|
@@ -1782,22 +1692,25 @@ const ComboboxPopover = /*#__PURE__*/react.forwardRef(function ComboboxPopover({
|
|
|
1782
1692
|
isVisible
|
|
1783
1693
|
} = useComboBoxContext();
|
|
1784
1694
|
const handleKeyDown = useKeyDown();
|
|
1785
|
-
const handleBlur = useBlur();
|
|
1695
|
+
const handleBlur = useBlur();
|
|
1696
|
+
|
|
1697
|
+
// Instead of conditionally rendering the popover we use the `hidden` prop
|
|
1786
1698
|
// because we don't want to unmount on close (from escape or onSelect). If
|
|
1787
1699
|
// we unmounted, then we'd lose the optionsRef and the user wouldn't be able
|
|
1788
1700
|
// to use the arrow keys to pop the list back open. However, the developer
|
|
1789
1701
|
// can conditionally render the ComboboxPopover if they do want to cause
|
|
1790
1702
|
// mount/unmount based on the app's own data (like results.length or
|
|
1791
1703
|
// whatever).
|
|
1792
|
-
|
|
1793
1704
|
const hidden = !isVisible;
|
|
1794
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1705
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1706
|
+
...props,
|
|
1795
1707
|
as: innerAs,
|
|
1796
1708
|
"data-reach-combobox-popover": "",
|
|
1797
1709
|
ref: assignMultipleRefs(popoverRef, forwardedRef),
|
|
1798
1710
|
onKeyDown: wrapEvent(onKeyDown, handleKeyDown),
|
|
1799
1711
|
onBlur: wrapEvent(onBlur, handleBlur),
|
|
1800
|
-
hidden: hidden
|
|
1712
|
+
hidden: hidden
|
|
1713
|
+
// Allow the user to click empty space inside the popover without causing
|
|
1801
1714
|
// to close from useBlur
|
|
1802
1715
|
,
|
|
1803
1716
|
tabIndex: "-1"
|
|
@@ -1813,18 +1726,14 @@ function useFocusLock(ref, opts) {
|
|
|
1813
1726
|
} = opts;
|
|
1814
1727
|
react.useEffect(() => {
|
|
1815
1728
|
const rootEl = ref.current;
|
|
1816
|
-
|
|
1817
1729
|
if (enabled && rootEl) {
|
|
1818
1730
|
focusLockStack.push(rootEl);
|
|
1819
|
-
|
|
1820
1731
|
const listener = event => {
|
|
1821
1732
|
const isActiveFocusLock = focusLockStack[focusLockStack.length - 1] === rootEl;
|
|
1822
|
-
|
|
1823
1733
|
if (!isActiveFocusLock) {
|
|
1824
1734
|
// Not the currently focused lock. Forget about it.
|
|
1825
1735
|
return;
|
|
1826
1736
|
}
|
|
1827
|
-
|
|
1828
1737
|
if (event.target === lockEndRef.current) {
|
|
1829
1738
|
focusOnChildNode(rootEl, 0);
|
|
1830
1739
|
} else if (event.target === lockStartRef.current) {
|
|
@@ -1834,15 +1743,13 @@ function useFocusLock(ref, opts) {
|
|
|
1834
1743
|
focusOnChildNode(rootEl, 0);
|
|
1835
1744
|
}
|
|
1836
1745
|
};
|
|
1837
|
-
|
|
1838
1746
|
document.addEventListener('focusin', listener);
|
|
1839
1747
|
return () => {
|
|
1840
|
-
document.removeEventListener('focusin', listener);
|
|
1841
|
-
|
|
1748
|
+
document.removeEventListener('focusin', listener);
|
|
1842
1749
|
focusLockStack.pop();
|
|
1843
1750
|
};
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1751
|
+
}
|
|
1752
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1846
1753
|
}, [enabled]);
|
|
1847
1754
|
}
|
|
1848
1755
|
|
|
@@ -1891,11 +1798,15 @@ const FocusLock = function FocusLock(props) {
|
|
|
1891
1798
|
});
|
|
1892
1799
|
};
|
|
1893
1800
|
|
|
1801
|
+
// MenuRoot
|
|
1802
|
+
|
|
1894
1803
|
const menuContext = /*#__PURE__*/react.createContext(null);
|
|
1895
1804
|
const {
|
|
1896
1805
|
Provider: MenuProvider
|
|
1897
1806
|
} = menuContext;
|
|
1898
|
-
const useMenuContext = () => react.useContext(menuContext);
|
|
1807
|
+
const useMenuContext = () => react.useContext(menuContext);
|
|
1808
|
+
|
|
1809
|
+
// MenuList
|
|
1899
1810
|
|
|
1900
1811
|
const menuListContext = /*#__PURE__*/react.createContext(null);
|
|
1901
1812
|
const MenuListProvider = menuListContext.Provider;
|
|
@@ -1910,7 +1821,7 @@ const Menu = /*#__PURE__*/react.forwardRef(function Menu(props, forwardedRef) {
|
|
|
1910
1821
|
onChange: onChangeProp,
|
|
1911
1822
|
...otherProps
|
|
1912
1823
|
} = props;
|
|
1913
|
-
const menuListIdRef = react.useRef();
|
|
1824
|
+
const menuListIdRef = react.useRef(undefined);
|
|
1914
1825
|
const openWithArrowKeyRef = react.useRef(null);
|
|
1915
1826
|
const buttonRef = react.useRef(null);
|
|
1916
1827
|
const [open, onChange] = useControlledState(openProp, onChangeProp, defaultOpen, setState => (e, isOpen) => {
|
|
@@ -1919,11 +1830,9 @@ const Menu = /*#__PURE__*/react.forwardRef(function Menu(props, forwardedRef) {
|
|
|
1919
1830
|
const [offsetFn, setOffsetFn] = react.useState(undefined);
|
|
1920
1831
|
menuListIdRef.current = react.useId();
|
|
1921
1832
|
const isContextMenu = react.useRef(false);
|
|
1922
|
-
|
|
1923
1833
|
if (!open && offsetFn) {
|
|
1924
1834
|
setOffsetFn(undefined);
|
|
1925
1835
|
}
|
|
1926
|
-
|
|
1927
1836
|
const value = {
|
|
1928
1837
|
menuListIdRef,
|
|
1929
1838
|
openWithArrowKeyRef,
|
|
@@ -1936,10 +1845,11 @@ const Menu = /*#__PURE__*/react.forwardRef(function Menu(props, forwardedRef) {
|
|
|
1936
1845
|
};
|
|
1937
1846
|
return /*#__PURE__*/jsxRuntime.jsx(MenuProvider, {
|
|
1938
1847
|
value: value,
|
|
1939
|
-
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1940
|
-
|
|
1848
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
1849
|
+
...(Comp !== react.Fragment ? {
|
|
1850
|
+
as: innerAs,
|
|
1851
|
+
ref: forwardedRef
|
|
1941
1852
|
} : {}),
|
|
1942
|
-
ref: forwardedRef,
|
|
1943
1853
|
...otherProps
|
|
1944
1854
|
})
|
|
1945
1855
|
});
|
|
@@ -1964,40 +1874,30 @@ const MenuButton = /*#__PURE__*/react.forwardRef(function MenuButton(props, forw
|
|
|
1964
1874
|
} = useMenuContext();
|
|
1965
1875
|
const buttonIdGenerated = react.useId();
|
|
1966
1876
|
const buttonId = preferredId || buttonIdGenerated;
|
|
1967
|
-
|
|
1968
1877
|
const handleKeyDown = e => {
|
|
1969
1878
|
if (disabled) {
|
|
1970
1879
|
return;
|
|
1971
1880
|
}
|
|
1972
|
-
|
|
1973
1881
|
buttonRef.current = e.currentTarget;
|
|
1974
|
-
|
|
1975
1882
|
const isArrowKey = () => ['ArrowUp', 'ArrowDown'].includes(e.key);
|
|
1976
|
-
|
|
1977
1883
|
const isEnterKey = () => [' ', 'Enter'].includes(e.key);
|
|
1978
|
-
|
|
1979
1884
|
const openedWithArrow = isArrowKey();
|
|
1980
|
-
|
|
1981
1885
|
if (openedWithArrow || isEnterKey()) {
|
|
1982
1886
|
if (openedWithArrow) {
|
|
1983
1887
|
// Used to make it open at the end or begining of the list
|
|
1984
1888
|
openWithArrowKeyRef.current = e.key;
|
|
1985
1889
|
}
|
|
1986
|
-
|
|
1987
1890
|
onChange(e, true);
|
|
1988
1891
|
e.preventDefault();
|
|
1989
1892
|
}
|
|
1990
1893
|
};
|
|
1991
|
-
|
|
1992
1894
|
const handleClick = e => {
|
|
1993
1895
|
if (disabled) {
|
|
1994
1896
|
return;
|
|
1995
1897
|
}
|
|
1996
|
-
|
|
1997
1898
|
buttonRef.current = e.currentTarget;
|
|
1998
1899
|
onChange(e, !open);
|
|
1999
1900
|
};
|
|
2000
|
-
|
|
2001
1901
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2002
1902
|
ref: forwardedRef,
|
|
2003
1903
|
as: innerAs,
|
|
@@ -2034,12 +1934,10 @@ const ContextMenuTrigger = /*#__PURE__*/react.forwardRef(function ContextMenuTri
|
|
|
2034
1934
|
} = useMenuContext();
|
|
2035
1935
|
const idGenerated = react.useId();
|
|
2036
1936
|
const id = preferredId || idGenerated;
|
|
2037
|
-
|
|
2038
1937
|
const handleContextMenu = e => {
|
|
2039
1938
|
if (disabled) {
|
|
2040
1939
|
return;
|
|
2041
1940
|
}
|
|
2042
|
-
|
|
2043
1941
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
2044
1942
|
isContextMenu.current = true;
|
|
2045
1943
|
buttonRef.current = e.currentTarget;
|
|
@@ -2051,7 +1949,6 @@ const ContextMenuTrigger = /*#__PURE__*/react.forwardRef(function ContextMenuTri
|
|
|
2051
1949
|
}) => [mouseX - rect.x, mouseY - rect.y - reference.height]);
|
|
2052
1950
|
e.preventDefault();
|
|
2053
1951
|
};
|
|
2054
|
-
|
|
2055
1952
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2056
1953
|
ref: forwardedRef,
|
|
2057
1954
|
as: innerAs,
|
|
@@ -2084,7 +1981,7 @@ const MenuItem = /*#__PURE__*/react.forwardRef(function MenuItem(props, forwarde
|
|
|
2084
1981
|
navigationItem,
|
|
2085
1982
|
onNavigate
|
|
2086
1983
|
} = useMenuListContext();
|
|
2087
|
-
const ref = react.useRef();
|
|
1984
|
+
const ref = react.useRef(null);
|
|
2088
1985
|
const itemId = react.useId();
|
|
2089
1986
|
const isActive = ref.current && ref.current === navigationItem;
|
|
2090
1987
|
const handleSelect = wrapEvent(onSelect, e => {
|
|
@@ -2092,15 +1989,12 @@ const MenuItem = /*#__PURE__*/react.forwardRef(function MenuItem(props, forwarde
|
|
|
2092
1989
|
buttonRef.current?.focus();
|
|
2093
1990
|
e.preventDefault();
|
|
2094
1991
|
});
|
|
2095
|
-
|
|
2096
1992
|
const handleClick = e => {
|
|
2097
1993
|
if (!disabled) {
|
|
2098
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2099
1994
|
onNavigate && onNavigate(ref.current);
|
|
2100
1995
|
handleSelect(e);
|
|
2101
1996
|
}
|
|
2102
1997
|
};
|
|
2103
|
-
|
|
2104
1998
|
const handleKeyDown = e => {
|
|
2105
1999
|
switch (e.key) {
|
|
2106
2000
|
case ' ':
|
|
@@ -2108,11 +2002,9 @@ const MenuItem = /*#__PURE__*/react.forwardRef(function MenuItem(props, forwarde
|
|
|
2108
2002
|
if (!disabled) {
|
|
2109
2003
|
handleSelect(e);
|
|
2110
2004
|
}
|
|
2111
|
-
|
|
2112
2005
|
break;
|
|
2113
2006
|
}
|
|
2114
2007
|
};
|
|
2115
|
-
|
|
2116
2008
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2117
2009
|
ref: assignMultipleRefs(ref, forwardedRef),
|
|
2118
2010
|
as: innerAs,
|
|
@@ -2146,7 +2038,7 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2146
2038
|
} = props;
|
|
2147
2039
|
const interactedOutside = react.useRef(false);
|
|
2148
2040
|
const itemSearchStr = react.useRef('');
|
|
2149
|
-
const itemSearchClearTimeout = react.useRef();
|
|
2041
|
+
const itemSearchClearTimeout = react.useRef(undefined);
|
|
2150
2042
|
const {
|
|
2151
2043
|
menuListIdRef,
|
|
2152
2044
|
buttonRef,
|
|
@@ -2157,20 +2049,17 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2157
2049
|
} = useMenuContext();
|
|
2158
2050
|
const [navigationItem, setNavigationItem] = react.useState();
|
|
2159
2051
|
const [mounted, setMounted] = react.useState(false);
|
|
2160
|
-
const menuListRef = react.useRef();
|
|
2052
|
+
const menuListRef = react.useRef(null);
|
|
2161
2053
|
const scope = useScope(menuListRef);
|
|
2162
|
-
|
|
2163
2054
|
const onNavigate = el => {
|
|
2164
2055
|
el.focus();
|
|
2165
2056
|
setNavigationItem(el);
|
|
2166
2057
|
};
|
|
2167
|
-
|
|
2168
2058
|
menuListIdRef.current = preferredId || menuListIdRef.current;
|
|
2169
2059
|
useEnhancedEffect$1(() => {
|
|
2170
2060
|
if (!mounted) {
|
|
2171
2061
|
const allItems = scope.current.queryAllNodes(queryScope);
|
|
2172
2062
|
let index = getCircularIndex(openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0, allItems.length);
|
|
2173
|
-
|
|
2174
2063
|
if (defaultActiveItemValue) {
|
|
2175
2064
|
if (typeof defaultActiveItemValue === 'string') {
|
|
2176
2065
|
for (let i = 0; i < allItems.length; i++) {
|
|
@@ -2181,10 +2070,8 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2181
2070
|
}
|
|
2182
2071
|
} else if (Array.isArray(defaultActiveItemValue)) {
|
|
2183
2072
|
const set = new Set(defaultActiveItemValue);
|
|
2184
|
-
|
|
2185
2073
|
for (let i = 0; i < allItems.length; i++) {
|
|
2186
2074
|
const val = allItems[i].dataset.value;
|
|
2187
|
-
|
|
2188
2075
|
if (val && set.has(val)) {
|
|
2189
2076
|
index = i;
|
|
2190
2077
|
break;
|
|
@@ -2192,12 +2079,10 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2192
2079
|
}
|
|
2193
2080
|
}
|
|
2194
2081
|
}
|
|
2195
|
-
|
|
2196
2082
|
if (index !== null) {
|
|
2197
2083
|
onNavigate && onNavigate(allItems[index]);
|
|
2198
2084
|
}
|
|
2199
2085
|
}
|
|
2200
|
-
|
|
2201
2086
|
openWithArrowKeyRef.current = null;
|
|
2202
2087
|
setMounted(true);
|
|
2203
2088
|
}, [mounted, navigationItem, onNavigate, openWithArrowKeyRef, scope, defaultActiveItemValue]);
|
|
@@ -2209,7 +2094,6 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2209
2094
|
interactedOutside.current = true;
|
|
2210
2095
|
return;
|
|
2211
2096
|
}
|
|
2212
|
-
|
|
2213
2097
|
if (e.button === 0) {
|
|
2214
2098
|
onChange(e, false);
|
|
2215
2099
|
}
|
|
@@ -2218,11 +2102,9 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2218
2102
|
onChange(e, false);
|
|
2219
2103
|
}
|
|
2220
2104
|
}
|
|
2221
|
-
|
|
2222
2105
|
e.preventDefault();
|
|
2223
2106
|
}, [buttonRef, isContextMenu, onChange]);
|
|
2224
2107
|
useOnClickOutside(menuListRef, handleClickOutside, open);
|
|
2225
|
-
|
|
2226
2108
|
function handleKeyDown(e) {
|
|
2227
2109
|
switch (e.key) {
|
|
2228
2110
|
case 'Escape':
|
|
@@ -2230,12 +2112,10 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2230
2112
|
{
|
|
2231
2113
|
onChange(e, false);
|
|
2232
2114
|
e.preventDefault(); // prevents focusing on next element, because we will be handling it
|
|
2233
|
-
|
|
2234
2115
|
itemSearchStr.current = '';
|
|
2235
2116
|
buttonRef.current?.focus();
|
|
2236
2117
|
break;
|
|
2237
2118
|
}
|
|
2238
|
-
|
|
2239
2119
|
case 'Home':
|
|
2240
2120
|
case 'End':
|
|
2241
2121
|
case 'ArrowDown':
|
|
@@ -2244,47 +2124,36 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2244
2124
|
itemSearchStr.current = '';
|
|
2245
2125
|
const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
2246
2126
|
const currentIndex = allItems.findIndex(e => e === navigationItem);
|
|
2247
|
-
|
|
2248
2127
|
if (allItems.length === 0) {
|
|
2249
2128
|
return;
|
|
2250
2129
|
}
|
|
2251
|
-
|
|
2252
2130
|
let nextIndex = currentIndex;
|
|
2253
|
-
|
|
2254
2131
|
switch (e.key) {
|
|
2255
2132
|
case 'ArrowUp':
|
|
2256
2133
|
nextIndex += -1;
|
|
2257
2134
|
break;
|
|
2258
|
-
|
|
2259
2135
|
case 'ArrowDown':
|
|
2260
2136
|
nextIndex += 1;
|
|
2261
2137
|
break;
|
|
2262
|
-
|
|
2263
2138
|
case 'Home':
|
|
2264
2139
|
nextIndex = 0;
|
|
2265
2140
|
break;
|
|
2266
|
-
|
|
2267
2141
|
case 'End':
|
|
2268
2142
|
nextIndex = -1;
|
|
2269
2143
|
break;
|
|
2270
|
-
}
|
|
2271
|
-
//
|
|
2272
|
-
|
|
2273
|
-
|
|
2144
|
+
}
|
|
2145
|
+
// We already checked if allItems.length = 0 above
|
|
2274
2146
|
nextIndex = getCircularIndex(nextIndex, allItems.length);
|
|
2275
2147
|
onNavigate && onNavigate(allItems[nextIndex]);
|
|
2276
2148
|
break;
|
|
2277
|
-
|
|
2278
2149
|
default:
|
|
2279
2150
|
{
|
|
2280
2151
|
if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {
|
|
2281
2152
|
// A-Z
|
|
2282
2153
|
e.preventDefault();
|
|
2283
|
-
|
|
2284
2154
|
if (itemSearchStr.current.length === 0 || itemSearchStr.current.slice(-1) !== e.key) {
|
|
2285
2155
|
itemSearchStr.current = itemSearchStr.current + e.key;
|
|
2286
2156
|
}
|
|
2287
|
-
|
|
2288
2157
|
clearTimeout(itemSearchClearTimeout.current);
|
|
2289
2158
|
itemSearchClearTimeout.current = setTimeout(() => {
|
|
2290
2159
|
itemSearchStr.current = '';
|
|
@@ -2293,19 +2162,15 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2293
2162
|
const currentIndex = allItems.findIndex(e => e === navigationItem);
|
|
2294
2163
|
const searchStr = itemSearchStr.current;
|
|
2295
2164
|
let nextIndex = -1;
|
|
2296
|
-
|
|
2297
2165
|
for (let i = searchStr.length === 1 ? 1 : 0; i < allItems.length; i++) {
|
|
2298
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2299
2166
|
const idx = getCircularIndex(currentIndex + i, allItems.length);
|
|
2300
2167
|
const dom = allItems[idx];
|
|
2301
2168
|
const domText = dom.innerText.toLowerCase();
|
|
2302
|
-
|
|
2303
2169
|
if (domText.length > 0 && domText.startsWith(searchStr)) {
|
|
2304
2170
|
nextIndex = idx;
|
|
2305
2171
|
break;
|
|
2306
2172
|
}
|
|
2307
2173
|
}
|
|
2308
|
-
|
|
2309
2174
|
if (nextIndex >= 0 && nextIndex < allItems.length) {
|
|
2310
2175
|
onNavigate && onNavigate(allItems[nextIndex]);
|
|
2311
2176
|
}
|
|
@@ -2313,12 +2178,10 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2313
2178
|
}
|
|
2314
2179
|
}
|
|
2315
2180
|
}
|
|
2316
|
-
|
|
2317
2181
|
if (!open) {
|
|
2318
2182
|
interactedOutside.current = false;
|
|
2319
2183
|
return null;
|
|
2320
2184
|
}
|
|
2321
|
-
|
|
2322
2185
|
return /*#__PURE__*/jsxRuntime.jsx(MenuListProvider, {
|
|
2323
2186
|
value: {
|
|
2324
2187
|
navigationItem,
|
|
@@ -2359,27 +2222,23 @@ const Portal = ({
|
|
|
2359
2222
|
selector: selectorProp
|
|
2360
2223
|
}) => {
|
|
2361
2224
|
const selectorCtx = react.useContext(PortalSelectorContext);
|
|
2362
|
-
|
|
2363
2225
|
if (typeof window === 'undefined') {
|
|
2364
2226
|
return null;
|
|
2365
2227
|
}
|
|
2366
|
-
|
|
2367
2228
|
const selector = selectorProp || selectorCtx || 'body';
|
|
2368
2229
|
const dom = typeof selector === 'string' ? document.querySelector(selector) : selector();
|
|
2369
|
-
|
|
2370
2230
|
if (dom) {
|
|
2371
|
-
return /*#__PURE__*/reactDom.createPortal(
|
|
2231
|
+
return /*#__PURE__*/reactDom.createPortal(/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
2372
2232
|
"data-portal": "",
|
|
2373
2233
|
children: children
|
|
2374
2234
|
}), dom);
|
|
2375
2235
|
}
|
|
2376
|
-
|
|
2377
2236
|
return null;
|
|
2378
2237
|
};
|
|
2379
2238
|
|
|
2380
2239
|
const useEnhancedEffect = typeof window !== 'undefined' ? react.useLayoutEffect : react.useEffect;
|
|
2381
2240
|
const emptyModifiers = [];
|
|
2382
|
-
const Popper = /*#__PURE__*/react.memo(
|
|
2241
|
+
const Popper = /*#__PURE__*/react.memo(/*#__PURE__*/react.forwardRef(function Popper({
|
|
2383
2242
|
placement = 'bottom',
|
|
2384
2243
|
strategy = 'absolute',
|
|
2385
2244
|
as: Comp = 'div',
|
|
@@ -2389,7 +2248,7 @@ const Popper = /*#__PURE__*/react.memo( /*#__PURE__*/react.forwardRef(function P
|
|
|
2389
2248
|
modifiers = emptyModifiers,
|
|
2390
2249
|
usePortal = false,
|
|
2391
2250
|
style = {},
|
|
2392
|
-
portalSelector
|
|
2251
|
+
portalSelector,
|
|
2393
2252
|
distance = 0,
|
|
2394
2253
|
skidding = 0,
|
|
2395
2254
|
arrowPadding = 5,
|
|
@@ -2423,7 +2282,6 @@ const Popper = /*#__PURE__*/react.memo( /*#__PURE__*/react.forwardRef(function P
|
|
|
2423
2282
|
modifiers: [...defaultModifiers, ...modifiers]
|
|
2424
2283
|
});
|
|
2425
2284
|
}
|
|
2426
|
-
|
|
2427
2285
|
return () => {
|
|
2428
2286
|
popperEngineInstance.current && popperEngineInstance.current.destroy();
|
|
2429
2287
|
popperEngineInstance.current = null;
|
|
@@ -2435,10 +2293,10 @@ const Popper = /*#__PURE__*/react.memo( /*#__PURE__*/react.forwardRef(function P
|
|
|
2435
2293
|
const contextValue = {
|
|
2436
2294
|
arrowRef
|
|
2437
2295
|
};
|
|
2438
|
-
|
|
2439
2296
|
const ret = /*#__PURE__*/jsxRuntime.jsx(PopperProvider, {
|
|
2440
2297
|
value: contextValue,
|
|
2441
|
-
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2298
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2299
|
+
...props,
|
|
2442
2300
|
as: innerAs,
|
|
2443
2301
|
ref: assignMultipleRefs(popperRef, forwardedRef),
|
|
2444
2302
|
style: {
|
|
@@ -2450,14 +2308,12 @@ const Popper = /*#__PURE__*/react.memo( /*#__PURE__*/react.forwardRef(function P
|
|
|
2450
2308
|
children: children
|
|
2451
2309
|
})
|
|
2452
2310
|
});
|
|
2453
|
-
|
|
2454
2311
|
if (usePortal) {
|
|
2455
2312
|
return /*#__PURE__*/jsxRuntime.jsx(Portal, {
|
|
2456
2313
|
selector: portalSelector,
|
|
2457
2314
|
children: ret
|
|
2458
2315
|
});
|
|
2459
2316
|
}
|
|
2460
|
-
|
|
2461
2317
|
return ret;
|
|
2462
2318
|
}));
|
|
2463
2319
|
|
|
@@ -2466,17 +2322,15 @@ const PopperArrow = /*#__PURE__*/react.forwardRef(function PopperArrow({
|
|
|
2466
2322
|
...props
|
|
2467
2323
|
}, ref) {
|
|
2468
2324
|
const ctx = usePopperContext();
|
|
2469
|
-
|
|
2470
2325
|
if (ctx === null) {
|
|
2471
2326
|
return null;
|
|
2472
2327
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2328
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2329
|
+
...props,
|
|
2475
2330
|
ref: node => {
|
|
2476
2331
|
if (node && ctx.arrowRef.current && ctx.arrowRef.current !== node) {
|
|
2477
2332
|
throw new Error('You can only render one <PopperArrow /> per <Popper> component');
|
|
2478
2333
|
}
|
|
2479
|
-
|
|
2480
2334
|
assignMultipleRefs(ref, ctx.arrowRef)(node);
|
|
2481
2335
|
},
|
|
2482
2336
|
"data-popper-arrow": ""
|
|
@@ -2495,11 +2349,9 @@ const MenuPopover = /*#__PURE__*/react.forwardRef(function MenuPopover(props, fo
|
|
|
2495
2349
|
offsetFn,
|
|
2496
2350
|
isContextMenu
|
|
2497
2351
|
} = useMenuContext();
|
|
2498
|
-
|
|
2499
2352
|
if (!open) {
|
|
2500
2353
|
return null;
|
|
2501
2354
|
}
|
|
2502
|
-
|
|
2503
2355
|
return /*#__PURE__*/jsxRuntime.jsx(Popper, {
|
|
2504
2356
|
as: as,
|
|
2505
2357
|
innerAs: innerAs,
|
|
@@ -2548,37 +2400,32 @@ const ModalBackdrop = /*#__PURE__*/react.forwardRef(({
|
|
|
2548
2400
|
disableEscapeKeyDown = false,
|
|
2549
2401
|
...otherProps
|
|
2550
2402
|
}, forwardedRef) => {
|
|
2551
|
-
const ref = react.useRef();
|
|
2403
|
+
const ref = react.useRef(null);
|
|
2552
2404
|
const mouseDownTargetRef = react.useRef(null);
|
|
2553
|
-
|
|
2554
2405
|
const handleClick = e => {
|
|
2555
2406
|
// Ignore the events not coming from the "backdrop"
|
|
2556
2407
|
// We don't want to close the dialog when clicking the dialog content.
|
|
2557
2408
|
if (e.target !== e.currentTarget) {
|
|
2558
2409
|
return;
|
|
2559
|
-
}
|
|
2560
|
-
|
|
2410
|
+
}
|
|
2561
2411
|
|
|
2412
|
+
// Make sure the event starts and ends on the same DOM element.
|
|
2562
2413
|
if (e.target !== mouseDownTargetRef.current) {
|
|
2563
2414
|
return;
|
|
2564
2415
|
}
|
|
2565
|
-
|
|
2566
2416
|
mouseDownTargetRef.current = null;
|
|
2567
2417
|
!disableCloseOnClick && onClose?.();
|
|
2568
2418
|
e.stopPropagation();
|
|
2569
2419
|
};
|
|
2570
|
-
|
|
2571
2420
|
const handleMouseDown = e => {
|
|
2572
2421
|
mouseDownTargetRef.current = e.target;
|
|
2573
2422
|
};
|
|
2574
|
-
|
|
2575
2423
|
const handleKeyDown = e => {
|
|
2576
2424
|
if (e.key === 'Escape') {
|
|
2577
2425
|
!disableEscapeKeyDown && onClose?.();
|
|
2578
2426
|
e.stopPropagation();
|
|
2579
2427
|
}
|
|
2580
2428
|
};
|
|
2581
|
-
|
|
2582
2429
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2583
2430
|
ref: assignMultipleRefs(ref, forwardedRef),
|
|
2584
2431
|
"data-modal-root": "",
|
|
@@ -2589,6 +2436,8 @@ const ModalBackdrop = /*#__PURE__*/react.forwardRef(({
|
|
|
2589
2436
|
});
|
|
2590
2437
|
});
|
|
2591
2438
|
|
|
2439
|
+
// RadioGroup Component
|
|
2440
|
+
|
|
2592
2441
|
const RadioGroupContext = /*#__PURE__*/react.createContext(undefined);
|
|
2593
2442
|
const {
|
|
2594
2443
|
Provider: RadioGroupProvider
|
|
@@ -2605,11 +2454,9 @@ const RadioButton = /*#__PURE__*/react.forwardRef(function RadioButton(props, fo
|
|
|
2605
2454
|
...otherProps
|
|
2606
2455
|
} = props;
|
|
2607
2456
|
const radioGroupContext = useRadioGroupContext();
|
|
2608
|
-
|
|
2609
2457
|
const handleChange = e => {
|
|
2610
2458
|
radioGroupContext?.onChange?.(e, valueProp);
|
|
2611
2459
|
};
|
|
2612
|
-
|
|
2613
2460
|
const checked = radioGroupContext ? radioGroupContext.value === valueProp : checkedProp;
|
|
2614
2461
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
2615
2462
|
ref: forwardedRef,
|
|
@@ -2651,24 +2498,24 @@ const RadioGroup = /*#__PURE__*/react.forwardRef(function RadioGroup(props, forw
|
|
|
2651
2498
|
});
|
|
2652
2499
|
|
|
2653
2500
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2654
|
-
|
|
2655
2501
|
const noop = () => {
|
|
2656
2502
|
/* noop */
|
|
2657
2503
|
};
|
|
2504
|
+
const [SliderProvider, useSliderContext] = createContext('Slider');
|
|
2658
2505
|
|
|
2659
|
-
|
|
2506
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
2660
2507
|
|
|
2661
2508
|
/**
|
|
2662
2509
|
* Slider
|
|
2663
2510
|
*
|
|
2664
2511
|
* @see Docs https://reach.tech/slider#slider
|
|
2665
2512
|
*/
|
|
2666
|
-
|
|
2667
2513
|
const Slider = /*#__PURE__*/react.forwardRef(function Slider({
|
|
2668
2514
|
children,
|
|
2669
2515
|
...props
|
|
2670
2516
|
}, forwardedRef) {
|
|
2671
|
-
return /*#__PURE__*/jsxRuntime.jsx(SliderInput, {
|
|
2517
|
+
return /*#__PURE__*/jsxRuntime.jsx(SliderInput, {
|
|
2518
|
+
...props,
|
|
2672
2519
|
ref: forwardedRef,
|
|
2673
2520
|
"data-reach-slider": "",
|
|
2674
2521
|
children: /*#__PURE__*/jsxRuntime.jsxs(SliderTrack, {
|
|
@@ -2676,6 +2523,7 @@ const Slider = /*#__PURE__*/react.forwardRef(function Slider({
|
|
|
2676
2523
|
})
|
|
2677
2524
|
});
|
|
2678
2525
|
});
|
|
2526
|
+
|
|
2679
2527
|
/**
|
|
2680
2528
|
* @see Docs https://reach.tech/slider#slider-props
|
|
2681
2529
|
*/
|
|
@@ -2721,10 +2569,11 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2721
2569
|
children,
|
|
2722
2570
|
...rest
|
|
2723
2571
|
}, forwardedRef) {
|
|
2724
|
-
const touchId = react.useRef();
|
|
2572
|
+
const touchId = react.useRef(undefined);
|
|
2725
2573
|
const fallbackId = react.useId();
|
|
2726
|
-
const id = rest.id || fallbackId;
|
|
2574
|
+
const id = rest.id || fallbackId;
|
|
2727
2575
|
|
|
2576
|
+
// Track whether or not the pointer is down without updating the component
|
|
2728
2577
|
const pointerDownRef = react.useRef(false);
|
|
2729
2578
|
const trackRef = react.useRef(null);
|
|
2730
2579
|
const handleRef = react.useRef(null);
|
|
@@ -2738,10 +2587,11 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2738
2587
|
const value = clamp$1(_value, min, max);
|
|
2739
2588
|
const trackPercent = valueToPercent(value, min, max);
|
|
2740
2589
|
const isVertical = orientation === 'vertical';
|
|
2741
|
-
const handleSize = isVertical ? handleDimensions.height : handleDimensions.width;
|
|
2590
|
+
const handleSize = isVertical ? handleDimensions.height : handleDimensions.width;
|
|
2591
|
+
|
|
2592
|
+
// TODO: Consider removing the `handleAlignment` prop
|
|
2742
2593
|
// We may want to use accept a `handlePosition` prop instead and let apps
|
|
2743
2594
|
// define their own positioning logic, similar to how we do for popovers.
|
|
2744
|
-
|
|
2745
2595
|
const handlePosition = `calc(${trackPercent}% - ${handleAlignment === 'center' ? `${handleSize}px / 2` : `${handleSize}px * ${trackPercent * 0.01}`})`;
|
|
2746
2596
|
const handlePositionRef = react.useRef(handlePosition);
|
|
2747
2597
|
react.useLayoutEffect(() => {
|
|
@@ -2754,17 +2604,16 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2754
2604
|
min,
|
|
2755
2605
|
max
|
|
2756
2606
|
});
|
|
2757
|
-
}, [max, min, orientation, step]);
|
|
2607
|
+
}, [max, min, orientation, step]);
|
|
2758
2608
|
|
|
2609
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_kbd_interaction
|
|
2759
2610
|
const handleKeyDown = useStableLayoutCallback(event => {
|
|
2760
2611
|
if (disabled) {
|
|
2761
2612
|
return;
|
|
2762
2613
|
}
|
|
2763
|
-
|
|
2764
2614
|
let newValue;
|
|
2765
2615
|
const tenSteps = (max - min) / 10;
|
|
2766
2616
|
const keyStep = step || (max - min) / 100;
|
|
2767
|
-
|
|
2768
2617
|
switch (event.key) {
|
|
2769
2618
|
// Decrease the value of the slider by one step.
|
|
2770
2619
|
case 'ArrowLeft':
|
|
@@ -2772,55 +2621,50 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2772
2621
|
newValue = value - keyStep;
|
|
2773
2622
|
break;
|
|
2774
2623
|
// Increase the value of the slider by one step
|
|
2775
|
-
|
|
2776
2624
|
case 'ArrowRight':
|
|
2777
2625
|
case 'ArrowUp':
|
|
2778
2626
|
newValue = value + keyStep;
|
|
2779
2627
|
break;
|
|
2780
2628
|
// Decrement the slider by an amount larger than the step change made by
|
|
2781
2629
|
// `ArrowDown`.
|
|
2782
|
-
|
|
2783
2630
|
case 'PageDown':
|
|
2784
2631
|
newValue = value - tenSteps;
|
|
2785
2632
|
break;
|
|
2786
2633
|
// Increment the slider by an amount larger than the step change made by
|
|
2787
2634
|
// `ArrowUp`.
|
|
2788
|
-
|
|
2789
2635
|
case 'PageUp':
|
|
2790
2636
|
newValue = value + tenSteps;
|
|
2791
2637
|
break;
|
|
2792
2638
|
// Set the slider to the first allowed value in its range.
|
|
2793
|
-
|
|
2794
2639
|
case 'Home':
|
|
2795
2640
|
newValue = min;
|
|
2796
2641
|
break;
|
|
2797
2642
|
// Set the slider to the last allowed value in its range.
|
|
2798
|
-
|
|
2799
2643
|
case 'End':
|
|
2800
2644
|
newValue = max;
|
|
2801
2645
|
break;
|
|
2802
|
-
|
|
2803
2646
|
default:
|
|
2804
2647
|
return;
|
|
2805
2648
|
}
|
|
2806
|
-
|
|
2807
2649
|
newValue = clamp$1(step ? roundValueToStep(newValue, step, min) : newValue, min, max);
|
|
2808
2650
|
onChange(event, newValue);
|
|
2809
2651
|
});
|
|
2810
2652
|
const ariaValueText = getAriaValueText ? getAriaValueText(value) : ariaValueTextProp;
|
|
2811
2653
|
const rangeStyle = {
|
|
2812
2654
|
[isVertical ? 'height' : 'width']: `${trackPercent}%`
|
|
2813
|
-
};
|
|
2655
|
+
};
|
|
2656
|
+
|
|
2657
|
+
// Slide events!
|
|
2814
2658
|
// We will try to use pointer events if they are supported to leverage
|
|
2815
2659
|
// setPointerCapture and releasePointerCapture. We'll fall back to separate
|
|
2816
2660
|
// mouse and touch events.
|
|
2817
2661
|
// TODO: This could be more concise
|
|
2818
|
-
|
|
2819
2662
|
const removeMoveEvents = react.useRef(noop);
|
|
2820
2663
|
const removeStartEvents = react.useRef(noop);
|
|
2821
|
-
const removeEndEvents = react.useRef(noop);
|
|
2822
|
-
// on every render if the user doesn't useCallback
|
|
2664
|
+
const removeEndEvents = react.useRef(noop);
|
|
2823
2665
|
|
|
2666
|
+
// Store our event handlers in refs so we aren't attaching/detaching events
|
|
2667
|
+
// on every render if the user doesn't useCallback
|
|
2824
2668
|
const appEvents = react.useRef({
|
|
2825
2669
|
onMouseMove,
|
|
2826
2670
|
onMouseDown,
|
|
@@ -2843,33 +2687,25 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2843
2687
|
}, [onMouseMove, onMouseDown, onMouseUp, onTouchStart, onTouchEnd, onTouchMove, onPointerDown, onPointerUp]);
|
|
2844
2688
|
const handleSlideStart = useStableLayoutCallback(event => {
|
|
2845
2689
|
if (isRightClick(event)) return;
|
|
2846
|
-
|
|
2847
2690
|
if (disabled) {
|
|
2848
2691
|
pointerDownRef.current = false;
|
|
2849
2692
|
return;
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2693
|
+
}
|
|
2853
2694
|
const ownerDocument = getOwnerDocument(sliderRef.current);
|
|
2854
2695
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
2855
2696
|
pointerDownRef.current = true;
|
|
2856
|
-
|
|
2857
2697
|
if (event.changedTouches) {
|
|
2858
2698
|
// Prevent scrolling for touch events
|
|
2859
2699
|
event.preventDefault();
|
|
2860
2700
|
const touch = event.changedTouches?.[0];
|
|
2861
|
-
|
|
2862
2701
|
if (touch != null) {
|
|
2863
2702
|
touchId.current = touch.identifier;
|
|
2864
2703
|
}
|
|
2865
2704
|
}
|
|
2866
|
-
|
|
2867
2705
|
const newValue = getNewValueFromEvent(event);
|
|
2868
|
-
|
|
2869
2706
|
if (newValue == null) {
|
|
2870
2707
|
return;
|
|
2871
2708
|
}
|
|
2872
|
-
|
|
2873
2709
|
ownerWindow.requestAnimationFrame(() => handleRef.current?.focus());
|
|
2874
2710
|
onChange(event, newValue);
|
|
2875
2711
|
removeMoveEvents.current = addMoveListener();
|
|
@@ -2877,12 +2713,10 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2877
2713
|
});
|
|
2878
2714
|
const setPointerCapture = useStableLayoutCallback(event => {
|
|
2879
2715
|
if (isRightClick(event)) return;
|
|
2880
|
-
|
|
2881
2716
|
if (disabled) {
|
|
2882
2717
|
pointerDownRef.current = false;
|
|
2883
2718
|
return;
|
|
2884
2719
|
}
|
|
2885
|
-
|
|
2886
2720
|
pointerDownRef.current = true;
|
|
2887
2721
|
sliderRef.current?.setPointerCapture(event.pointerId);
|
|
2888
2722
|
});
|
|
@@ -2896,30 +2730,24 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2896
2730
|
pointerDownRef.current = false;
|
|
2897
2731
|
return;
|
|
2898
2732
|
}
|
|
2899
|
-
|
|
2900
2733
|
const newValue = getNewValueFromEvent(event);
|
|
2901
|
-
|
|
2902
2734
|
if (newValue == null) {
|
|
2903
2735
|
return;
|
|
2904
2736
|
}
|
|
2905
|
-
|
|
2906
2737
|
onChange?.(event, newValue);
|
|
2907
2738
|
});
|
|
2908
2739
|
const handleSlideStop = useStableLayoutCallback(event => {
|
|
2909
2740
|
if (isRightClick(event)) return;
|
|
2910
2741
|
pointerDownRef.current = false;
|
|
2911
2742
|
const newValue = getNewValueFromEvent(event);
|
|
2912
|
-
|
|
2913
2743
|
if (newValue == null) {
|
|
2914
2744
|
return;
|
|
2915
2745
|
}
|
|
2916
|
-
|
|
2917
2746
|
touchId.current = undefined;
|
|
2918
2747
|
removeMoveEvents.current();
|
|
2919
2748
|
removeEndEvents.current();
|
|
2920
2749
|
});
|
|
2921
2750
|
const addMoveListener = react.useCallback(() => {
|
|
2922
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2923
2751
|
const ownerDocument = getOwnerDocument(sliderRef.current);
|
|
2924
2752
|
const touchListener = wrapEvent(appEvents.current.onTouchMove, handlePointerMove);
|
|
2925
2753
|
const mouseListener = wrapEvent(appEvents.current.onMouseMove, handlePointerMove);
|
|
@@ -2931,24 +2759,20 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2931
2759
|
};
|
|
2932
2760
|
}, [handlePointerMove]);
|
|
2933
2761
|
const addEndListener = react.useCallback(() => {
|
|
2934
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2935
2762
|
const ownerDocument = getOwnerDocument(sliderRef.current);
|
|
2936
2763
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
2937
2764
|
const pointerListener = wrapEvent(appEvents.current.onPointerUp, releasePointerCapture);
|
|
2938
2765
|
const touchListener = wrapEvent(appEvents.current.onTouchEnd, handleSlideStop);
|
|
2939
2766
|
const mouseListener = wrapEvent(appEvents.current.onMouseUp, handleSlideStop);
|
|
2940
|
-
|
|
2941
2767
|
if ('PointerEvent' in ownerWindow) {
|
|
2942
2768
|
ownerDocument.addEventListener('pointerup', pointerListener);
|
|
2943
2769
|
}
|
|
2944
|
-
|
|
2945
2770
|
ownerDocument.addEventListener('touchend', touchListener);
|
|
2946
2771
|
ownerDocument.addEventListener('mouseup', mouseListener);
|
|
2947
2772
|
return () => {
|
|
2948
2773
|
if ('PointerEvent' in ownerWindow) {
|
|
2949
2774
|
ownerDocument.removeEventListener('pointerup', pointerListener);
|
|
2950
2775
|
}
|
|
2951
|
-
|
|
2952
2776
|
ownerDocument.removeEventListener('touchend', touchListener);
|
|
2953
2777
|
ownerDocument.removeEventListener('mouseup', mouseListener);
|
|
2954
2778
|
};
|
|
@@ -2957,14 +2781,11 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2957
2781
|
// e.preventDefault is ignored by React's synthetic touchStart event, so
|
|
2958
2782
|
// we attach the listener directly to the DOM node
|
|
2959
2783
|
// https://github.com/facebook/react/issues/9809#issuecomment-413978405
|
|
2960
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2961
|
-
const sliderElement = sliderRef.current;
|
|
2962
2784
|
|
|
2785
|
+
const sliderElement = sliderRef.current;
|
|
2963
2786
|
if (!sliderElement) {
|
|
2964
2787
|
return noop;
|
|
2965
|
-
}
|
|
2966
|
-
|
|
2967
|
-
|
|
2788
|
+
}
|
|
2968
2789
|
const ownerDocument = getOwnerDocument(sliderElement);
|
|
2969
2790
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
2970
2791
|
const touchListener = wrapEvent(appEvents.current.onTouchStart, handleSlideStart);
|
|
@@ -2972,15 +2793,12 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
2972
2793
|
const pointerListener = wrapEvent(appEvents.current.onPointerDown, setPointerCapture);
|
|
2973
2794
|
sliderElement.addEventListener('touchstart', touchListener);
|
|
2974
2795
|
sliderElement.addEventListener('mousedown', mouseListener);
|
|
2975
|
-
|
|
2976
2796
|
if ('PointerEvent' in ownerWindow) {
|
|
2977
2797
|
sliderElement.addEventListener('pointerdown', pointerListener);
|
|
2978
2798
|
}
|
|
2979
|
-
|
|
2980
2799
|
return () => {
|
|
2981
2800
|
sliderElement.removeEventListener('touchstart', touchListener);
|
|
2982
2801
|
sliderElement.removeEventListener('mousedown', mouseListener);
|
|
2983
|
-
|
|
2984
2802
|
if ('PointerEvent' in ownerWindow) {
|
|
2985
2803
|
sliderElement.removeEventListener('pointerdown', pointerListener);
|
|
2986
2804
|
}
|
|
@@ -3018,7 +2836,8 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
3018
2836
|
trackRef: trackRef,
|
|
3019
2837
|
rangeStyle: rangeStyle,
|
|
3020
2838
|
updateValue: onChange,
|
|
3021
|
-
children: /*#__PURE__*/jsxRuntime.jsxs(Comp, {
|
|
2839
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(Comp, {
|
|
2840
|
+
...rest,
|
|
3022
2841
|
// @ts-ignore
|
|
3023
2842
|
as: innerAs,
|
|
3024
2843
|
ref: assignMultipleRefs(sliderRef, forwardedRef),
|
|
@@ -3048,6 +2867,7 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
|
|
|
3048
2867
|
})
|
|
3049
2868
|
});
|
|
3050
2869
|
});
|
|
2870
|
+
|
|
3051
2871
|
/**
|
|
3052
2872
|
* @see Docs https://reach.tech/slider#sliderinput-props
|
|
3053
2873
|
*/
|
|
@@ -3072,10 +2892,12 @@ const SliderTrackImpl = /*#__PURE__*/react.forwardRef(function SliderTrack({
|
|
|
3072
2892
|
trackRef
|
|
3073
2893
|
} = useSliderContext('SliderTrack');
|
|
3074
2894
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3075
|
-
ref: assignMultipleRefs(trackRef, forwardedRef)
|
|
2895
|
+
ref: assignMultipleRefs(trackRef, forwardedRef)
|
|
2896
|
+
// @ts-ignore
|
|
3076
2897
|
,
|
|
3077
2898
|
as: innerAs,
|
|
3078
|
-
style: {
|
|
2899
|
+
style: {
|
|
2900
|
+
...style,
|
|
3079
2901
|
position: 'relative'
|
|
3080
2902
|
},
|
|
3081
2903
|
...props,
|
|
@@ -3086,6 +2908,7 @@ const SliderTrackImpl = /*#__PURE__*/react.forwardRef(function SliderTrack({
|
|
|
3086
2908
|
});
|
|
3087
2909
|
});
|
|
3088
2910
|
const SliderTrack = /*#__PURE__*/react.memo(SliderTrackImpl);
|
|
2911
|
+
|
|
3089
2912
|
/**
|
|
3090
2913
|
* @see Docs https://reach.tech/slider#slidertrack-props
|
|
3091
2914
|
*/
|
|
@@ -3113,7 +2936,8 @@ const SliderRangeImpl = /*#__PURE__*/react.forwardRef(function SliderRange({
|
|
|
3113
2936
|
rangeStyle
|
|
3114
2937
|
} = useSliderContext('SliderRange');
|
|
3115
2938
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3116
|
-
ref: forwardedRef
|
|
2939
|
+
ref: forwardedRef
|
|
2940
|
+
// @ts-ignore
|
|
3117
2941
|
,
|
|
3118
2942
|
as: innerAs,
|
|
3119
2943
|
style: {
|
|
@@ -3128,13 +2952,13 @@ const SliderRangeImpl = /*#__PURE__*/react.forwardRef(function SliderRange({
|
|
|
3128
2952
|
});
|
|
3129
2953
|
});
|
|
3130
2954
|
const SliderRange = /*#__PURE__*/react.memo(SliderRangeImpl);
|
|
2955
|
+
|
|
3131
2956
|
/**
|
|
3132
2957
|
* `SliderRange` accepts any props that a HTML div component accepts.
|
|
3133
2958
|
* `SliderRange` will not accept or render any children.
|
|
3134
2959
|
*
|
|
3135
2960
|
* @see Docs https://reach.tech/slider#sliderrange-props
|
|
3136
2961
|
*/
|
|
3137
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
3138
2962
|
|
|
3139
2963
|
////////////////////////////////////////////////////////////////////////////////
|
|
3140
2964
|
|
|
@@ -3171,39 +2995,47 @@ const SliderHandleImpl = /*#__PURE__*/react.forwardRef(function SliderHandle({
|
|
|
3171
2995
|
sliderMax,
|
|
3172
2996
|
value
|
|
3173
2997
|
} = useSliderContext('SliderHandle');
|
|
3174
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp
|
|
2998
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp
|
|
2999
|
+
// @ts-ignore
|
|
3175
3000
|
, {
|
|
3176
3001
|
as: innerAs,
|
|
3177
|
-
"aria-disabled": disabled || undefined
|
|
3002
|
+
"aria-disabled": disabled || undefined
|
|
3003
|
+
// If the slider has a visible label, it is referenced by
|
|
3178
3004
|
// `aria-labelledby` on the slider element. Otherwise, the slider
|
|
3179
3005
|
// element has a label provided by `aria-label`.
|
|
3180
3006
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3181
3007
|
,
|
|
3182
3008
|
"aria-label": ariaLabel,
|
|
3183
|
-
"aria-labelledby": ariaLabel ? undefined : ariaLabelledBy
|
|
3009
|
+
"aria-labelledby": ariaLabel ? undefined : ariaLabelledBy
|
|
3010
|
+
// If the slider is vertically oriented, it has `aria-orientation` set
|
|
3184
3011
|
// to vertical. The default value of `aria-orientation` for a slider is
|
|
3185
3012
|
// horizontal.
|
|
3186
3013
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3187
3014
|
,
|
|
3188
|
-
"aria-orientation": orientation
|
|
3015
|
+
"aria-orientation": orientation
|
|
3016
|
+
// The slider element has the `aria-valuemax` property set to a decimal
|
|
3189
3017
|
// value representing the maximum allowed value of the slider.
|
|
3190
3018
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3191
3019
|
,
|
|
3192
|
-
"aria-valuemax": sliderMax
|
|
3020
|
+
"aria-valuemax": sliderMax
|
|
3021
|
+
// The slider element has the `aria-valuemin` property set to a decimal
|
|
3193
3022
|
// value representing the minimum allowed value of the slider.
|
|
3194
3023
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3195
3024
|
,
|
|
3196
|
-
"aria-valuemin": sliderMin
|
|
3025
|
+
"aria-valuemin": sliderMin
|
|
3026
|
+
// The slider element has the `aria-valuenow` property set to a decimal
|
|
3197
3027
|
// value representing the current value of the slider.
|
|
3198
3028
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3199
3029
|
,
|
|
3200
|
-
"aria-valuenow": value
|
|
3030
|
+
"aria-valuenow": value
|
|
3031
|
+
// If the value of `aria-valuenow` is not user-friendly, e.g., the day
|
|
3201
3032
|
// of the week is represented by a number, the `aria-valuetext` property
|
|
3202
3033
|
// is set to a string that makes the slider value understandable, e.g.,
|
|
3203
3034
|
// "Monday".
|
|
3204
3035
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3205
3036
|
,
|
|
3206
|
-
"aria-valuetext": ariaValueText
|
|
3037
|
+
"aria-valuetext": ariaValueText
|
|
3038
|
+
// The element serving as the focusable slider control has role
|
|
3207
3039
|
// `slider`.
|
|
3208
3040
|
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
3209
3041
|
,
|
|
@@ -3231,12 +3063,12 @@ const SliderHandleImpl = /*#__PURE__*/react.forwardRef(function SliderHandle({
|
|
|
3231
3063
|
});
|
|
3232
3064
|
});
|
|
3233
3065
|
const SliderHandle = /*#__PURE__*/react.memo(SliderHandleImpl);
|
|
3066
|
+
|
|
3234
3067
|
/**
|
|
3235
3068
|
* `SliderRange` accepts any props that a HTML div component accepts.
|
|
3236
3069
|
*
|
|
3237
3070
|
* @see Docs https://reach.tech/slider#sliderhandle-props
|
|
3238
3071
|
*/
|
|
3239
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
3240
3072
|
|
|
3241
3073
|
////////////////////////////////////////////////////////////////////////////////
|
|
3242
3074
|
|
|
@@ -3268,7 +3100,8 @@ const SliderMarkerImpl = /*#__PURE__*/react.forwardRef(function SliderMarker({
|
|
|
3268
3100
|
const absoluteStartPosition = `${valueToPercent(value, sliderMin, sliderMax)}%`;
|
|
3269
3101
|
const state = value < sliderValue ? 'under-value' : value === sliderValue ? 'at-value' : 'over-value';
|
|
3270
3102
|
return inRange ? /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3271
|
-
ref: forwardedRef
|
|
3103
|
+
ref: forwardedRef
|
|
3104
|
+
// @ts-ignore
|
|
3272
3105
|
,
|
|
3273
3106
|
as: innerAs,
|
|
3274
3107
|
style: {
|
|
@@ -3290,14 +3123,17 @@ const SliderMarkerImpl = /*#__PURE__*/react.forwardRef(function SliderMarker({
|
|
|
3290
3123
|
}) : null;
|
|
3291
3124
|
});
|
|
3292
3125
|
const SliderMarker = /*#__PURE__*/react.memo(SliderMarkerImpl);
|
|
3126
|
+
|
|
3293
3127
|
/**
|
|
3294
3128
|
* @see Docs https://reach.tech/slider#slidermarker-props
|
|
3295
3129
|
*/
|
|
3296
3130
|
|
|
3297
3131
|
////////////////////////////////////////////////////////////////////////////////
|
|
3132
|
+
|
|
3298
3133
|
function clamp$1(val, min, max) {
|
|
3299
3134
|
return val > max ? max : val < min ? min : val;
|
|
3300
3135
|
}
|
|
3136
|
+
|
|
3301
3137
|
/**
|
|
3302
3138
|
* This handles the case when num is very small (0.00000001), js will turn
|
|
3303
3139
|
* this into 1e-8. When num is bigger than 1 or less than -1 it won't get
|
|
@@ -3306,33 +3142,26 @@ function clamp$1(val, min, max) {
|
|
|
3306
3142
|
* @param num
|
|
3307
3143
|
* @see https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Slider/Slider.js#L69
|
|
3308
3144
|
*/
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
3145
|
function getDecimalPrecision(num) {
|
|
3312
3146
|
if (Math.abs(num) < 1) {
|
|
3313
3147
|
const parts = num.toExponential().split('e-');
|
|
3314
3148
|
const matissaDecimalPart = parts[0].split('.')[1];
|
|
3315
3149
|
return (matissaDecimalPart ? matissaDecimalPart.length : 0) + parseInt(parts[1], 10);
|
|
3316
3150
|
}
|
|
3317
|
-
|
|
3318
3151
|
const decimalPart = num.toString().split('.')[1];
|
|
3319
3152
|
return decimalPart ? decimalPart.length : 0;
|
|
3320
3153
|
}
|
|
3321
|
-
|
|
3322
3154
|
function percentToValue(percent, min, max) {
|
|
3323
3155
|
return (max - min) * percent + min;
|
|
3324
3156
|
}
|
|
3325
|
-
|
|
3326
3157
|
function roundValueToStep(value, step, min) {
|
|
3327
3158
|
const nearest = Math.round((value - min) / step) * step + min;
|
|
3328
3159
|
return Number(nearest.toFixed(getDecimalPrecision(step)));
|
|
3329
3160
|
}
|
|
3330
|
-
|
|
3331
3161
|
function getPointerPosition(event, touchId) {
|
|
3332
3162
|
if (touchId.current !== undefined && event.changedTouches) {
|
|
3333
3163
|
for (let i = 0; i < event.changedTouches.length; i += 1) {
|
|
3334
3164
|
const touch = event.changedTouches[i];
|
|
3335
|
-
|
|
3336
3165
|
if (touch.identifier === touchId.current) {
|
|
3337
3166
|
return {
|
|
3338
3167
|
x: touch.clientX,
|
|
@@ -3340,16 +3169,13 @@ function getPointerPosition(event, touchId) {
|
|
|
3340
3169
|
};
|
|
3341
3170
|
}
|
|
3342
3171
|
}
|
|
3343
|
-
|
|
3344
3172
|
return false;
|
|
3345
3173
|
}
|
|
3346
|
-
|
|
3347
3174
|
return {
|
|
3348
3175
|
x: event.clientX,
|
|
3349
3176
|
y: event.clientY
|
|
3350
3177
|
};
|
|
3351
3178
|
}
|
|
3352
|
-
|
|
3353
3179
|
function getNewValue(handlePosition, track, props) {
|
|
3354
3180
|
const {
|
|
3355
3181
|
orientation,
|
|
@@ -3357,11 +3183,9 @@ function getNewValue(handlePosition, track, props) {
|
|
|
3357
3183
|
max,
|
|
3358
3184
|
step
|
|
3359
3185
|
} = props;
|
|
3360
|
-
|
|
3361
3186
|
if (!track || !handlePosition) {
|
|
3362
3187
|
return null;
|
|
3363
3188
|
}
|
|
3364
|
-
|
|
3365
3189
|
const {
|
|
3366
3190
|
left,
|
|
3367
3191
|
width,
|
|
@@ -3374,7 +3198,6 @@ function getNewValue(handlePosition, track, props) {
|
|
|
3374
3198
|
const newValue = percentToValue(percent, min, max);
|
|
3375
3199
|
return clamp$1(step ? roundValueToStep(newValue, step, min) : newValue, min, max);
|
|
3376
3200
|
}
|
|
3377
|
-
|
|
3378
3201
|
function useDimensions(ref) {
|
|
3379
3202
|
const [{
|
|
3380
3203
|
width,
|
|
@@ -3382,21 +3205,19 @@ function useDimensions(ref) {
|
|
|
3382
3205
|
}, setDimensions] = react.useState({
|
|
3383
3206
|
width: 0,
|
|
3384
3207
|
height: 0
|
|
3385
|
-
});
|
|
3208
|
+
});
|
|
3209
|
+
// Many existing `useDimensions` type hooks will use `getBoundingClientRect`
|
|
3386
3210
|
// getBoundingClientRect does not work here when borders are applied.
|
|
3387
3211
|
// getComputedStyle is not as performant so we may want to create a utility to
|
|
3388
3212
|
// check for any conflicts with box sizing first and only use
|
|
3389
3213
|
// `getComputedStyle` if neccessary.
|
|
3390
|
-
|
|
3391
3214
|
/* const { width, height } = ref.current
|
|
3392
3215
|
? ref.current.getBoundingClientRect()
|
|
3393
3216
|
: 0; */
|
|
3394
3217
|
|
|
3395
3218
|
react.useLayoutEffect(() => {
|
|
3396
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3397
3219
|
const ownerDocument = getOwnerDocument(ref.current);
|
|
3398
3220
|
const ownerWindow = ownerDocument.defaultView || window;
|
|
3399
|
-
|
|
3400
3221
|
if (ref.current) {
|
|
3401
3222
|
const {
|
|
3402
3223
|
height: _newHeight,
|
|
@@ -3404,7 +3225,6 @@ function useDimensions(ref) {
|
|
|
3404
3225
|
} = ownerWindow.getComputedStyle(ref.current);
|
|
3405
3226
|
const newHeight = parseFloat(_newHeight);
|
|
3406
3227
|
const newWidth = parseFloat(_newWidth);
|
|
3407
|
-
|
|
3408
3228
|
if (newHeight !== height || newWidth !== width) {
|
|
3409
3229
|
setDimensions({
|
|
3410
3230
|
height: newHeight,
|
|
@@ -3419,10 +3239,11 @@ function useDimensions(ref) {
|
|
|
3419
3239
|
height
|
|
3420
3240
|
};
|
|
3421
3241
|
}
|
|
3422
|
-
|
|
3423
3242
|
function valueToPercent(value, min, max) {
|
|
3424
3243
|
return (value - min) * 100 / (max - min);
|
|
3425
|
-
}
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
// Spinner Component
|
|
3426
3247
|
|
|
3427
3248
|
const spinbuttonContext = /*#__PURE__*/react.createContext(null);
|
|
3428
3249
|
const {
|
|
@@ -3448,60 +3269,45 @@ const Spinner = /*#__PURE__*/react.forwardRef(function Spinner(props, forwardedR
|
|
|
3448
3269
|
...otherProps
|
|
3449
3270
|
} = props;
|
|
3450
3271
|
const [spinnerHasFocus, setSpinnerHasFocus] = react.useState(false);
|
|
3451
|
-
const ref = react.useRef();
|
|
3452
|
-
|
|
3272
|
+
const ref = react.useRef(null);
|
|
3453
3273
|
const clamp$1 = value => clamp(value, minValue, maxValue);
|
|
3454
|
-
|
|
3455
3274
|
const handleKeyDown = e => {
|
|
3456
3275
|
let nextValue = value;
|
|
3457
|
-
|
|
3458
3276
|
switch (e.key) {
|
|
3459
3277
|
case 'ArrowUp':
|
|
3460
3278
|
nextValue += 1;
|
|
3461
3279
|
break;
|
|
3462
|
-
|
|
3463
3280
|
case 'ArrowDown':
|
|
3464
3281
|
nextValue -= 1;
|
|
3465
3282
|
break;
|
|
3466
|
-
|
|
3467
3283
|
case 'Home':
|
|
3468
3284
|
nextValue = minValue;
|
|
3469
3285
|
break;
|
|
3470
|
-
|
|
3471
3286
|
case 'End':
|
|
3472
3287
|
nextValue = maxValue;
|
|
3473
3288
|
break;
|
|
3474
|
-
|
|
3475
3289
|
case 'PageUp':
|
|
3476
3290
|
nextValue += stepSize;
|
|
3477
3291
|
break;
|
|
3478
|
-
|
|
3479
3292
|
case 'PageDown':
|
|
3480
3293
|
nextValue -= stepSize;
|
|
3481
3294
|
break;
|
|
3482
|
-
|
|
3483
3295
|
default:
|
|
3484
3296
|
return;
|
|
3485
3297
|
}
|
|
3486
|
-
|
|
3487
3298
|
ref.current && ref.current.focus();
|
|
3488
3299
|
nextValue = clamp$1(nextValue);
|
|
3489
|
-
|
|
3490
3300
|
if (nextValue !== value) {
|
|
3491
3301
|
e.preventDefault(); // prevent scrolling
|
|
3492
|
-
|
|
3493
3302
|
onChange && onChange(e, nextValue);
|
|
3494
3303
|
}
|
|
3495
3304
|
};
|
|
3496
|
-
|
|
3497
3305
|
const handleFocus = () => {
|
|
3498
3306
|
setSpinnerHasFocus(true);
|
|
3499
3307
|
};
|
|
3500
|
-
|
|
3501
3308
|
const handleBlur = () => {
|
|
3502
3309
|
setSpinnerHasFocus(false);
|
|
3503
3310
|
};
|
|
3504
|
-
|
|
3505
3311
|
return /*#__PURE__*/jsxRuntime.jsx(SpinnerProvider, {
|
|
3506
3312
|
value: {
|
|
3507
3313
|
minValue,
|
|
@@ -3536,18 +3342,16 @@ const SpinnerButton = /*#__PURE__*/react.forwardRef(function SpinnerButton(props
|
|
|
3536
3342
|
...otherProps
|
|
3537
3343
|
} = props;
|
|
3538
3344
|
const spinnerContext = useSpinnerContext();
|
|
3539
|
-
|
|
3540
3345
|
if (!spinnerContext) {
|
|
3541
3346
|
throw new Error('Missing <Spinner /> in component tree');
|
|
3542
3347
|
}
|
|
3543
|
-
|
|
3544
3348
|
const handleClick = e => {
|
|
3545
3349
|
const delta = type === 'next' ? 1 : -1;
|
|
3546
3350
|
spinnerContext.onChange && spinnerContext.onChange(e, spinnerContext.value + delta);
|
|
3547
3351
|
};
|
|
3548
|
-
|
|
3549
3352
|
const disabled = type === 'next' ? spinnerContext.value + 1 > spinnerContext.maxValue : spinnerContext.value - 1 < spinnerContext.minValue;
|
|
3550
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3353
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3354
|
+
...otherProps,
|
|
3551
3355
|
type: "button",
|
|
3552
3356
|
ref: forwardedRef,
|
|
3553
3357
|
tabIndex: -1,
|
|
@@ -3558,11 +3362,15 @@ const SpinnerButton = /*#__PURE__*/react.forwardRef(function SpinnerButton(props
|
|
|
3558
3362
|
});
|
|
3559
3363
|
});
|
|
3560
3364
|
|
|
3365
|
+
// Tabs Component
|
|
3366
|
+
|
|
3561
3367
|
const tabsContext = /*#__PURE__*/react.createContext(null);
|
|
3562
3368
|
const {
|
|
3563
3369
|
Provider: TabsProvider
|
|
3564
3370
|
} = tabsContext;
|
|
3565
|
-
const useTabsContext = () => react.useContext(tabsContext);
|
|
3371
|
+
const useTabsContext = () => react.useContext(tabsContext);
|
|
3372
|
+
|
|
3373
|
+
// TabList Component
|
|
3566
3374
|
|
|
3567
3375
|
const tablistContext = /*#__PURE__*/react.createContext(null);
|
|
3568
3376
|
const {
|
|
@@ -3601,15 +3409,12 @@ function scopeQuery(nodeType, props) {
|
|
|
3601
3409
|
function getNextIndex(desiredIndex, delta, allTabs) {
|
|
3602
3410
|
for (let i = 0; i < allTabs.length; i++) {
|
|
3603
3411
|
const nextIndex = getCircularIndex(desiredIndex + delta * i, allTabs.length);
|
|
3604
|
-
|
|
3605
3412
|
if (nextIndex !== null && !allTabs[nextIndex].disabled) {
|
|
3606
3413
|
return nextIndex;
|
|
3607
3414
|
}
|
|
3608
3415
|
}
|
|
3609
|
-
|
|
3610
3416
|
return null;
|
|
3611
3417
|
}
|
|
3612
|
-
|
|
3613
3418
|
const Tab = /*#__PURE__*/react.forwardRef(function Tab(props, forwardedRef) {
|
|
3614
3419
|
const {
|
|
3615
3420
|
as: Comp = 'button',
|
|
@@ -3621,29 +3426,24 @@ const Tab = /*#__PURE__*/react.forwardRef(function Tab(props, forwardedRef) {
|
|
|
3621
3426
|
const tabContext = useTabsContext();
|
|
3622
3427
|
const tabListContext = useTabListContext();
|
|
3623
3428
|
const ref = react.useRef(undefined);
|
|
3624
|
-
|
|
3625
3429
|
if (!tabContext || !tabListContext) {
|
|
3626
3430
|
throw new Error('Missing <Tabs /> or <TabList /> in the component tree');
|
|
3627
3431
|
}
|
|
3628
|
-
|
|
3629
3432
|
const handleKeyDown = e => {
|
|
3630
3433
|
const right = tabListContext.vertical ? 'ArrowDown' : 'ArrowRight';
|
|
3631
3434
|
const left = tabListContext.vertical ? 'ArrowUp' : 'ArrowLeft';
|
|
3632
3435
|
const first = 'Home';
|
|
3633
3436
|
const last = 'End';
|
|
3634
|
-
|
|
3635
3437
|
const navigateIndex = (desiredIndex, isLast) => {
|
|
3636
3438
|
const delta = e.key === right || e.key === first ? 1 : -1;
|
|
3637
3439
|
const allTabs = tabListContext.tabsScope.current.queryAllNodes(scopeQuery);
|
|
3638
3440
|
const currentIndex = ref.current ? allTabs.indexOf(ref.current) : -1;
|
|
3639
3441
|
const nextIndex = getNextIndex(isLast ? desiredIndex : currentIndex + desiredIndex, delta, allTabs);
|
|
3640
|
-
|
|
3641
3442
|
if (nextIndex !== null && nextIndex !== currentIndex && tabContext.onChange) {
|
|
3642
3443
|
allTabs[nextIndex].focus();
|
|
3643
3444
|
!tabListContext.manualActivation && tabContext.onChange(e, nextIndex);
|
|
3644
3445
|
}
|
|
3645
3446
|
};
|
|
3646
|
-
|
|
3647
3447
|
switch (e.key) {
|
|
3648
3448
|
case right:
|
|
3649
3449
|
case left:
|
|
@@ -3651,9 +3451,7 @@ const Tab = /*#__PURE__*/react.forwardRef(function Tab(props, forwardedRef) {
|
|
|
3651
3451
|
navigateIndex(e.key === right ? 1 : -1, false);
|
|
3652
3452
|
break;
|
|
3653
3453
|
}
|
|
3654
|
-
|
|
3655
3454
|
case first: // Home / End
|
|
3656
|
-
|
|
3657
3455
|
case last:
|
|
3658
3456
|
{
|
|
3659
3457
|
navigateIndex(e.key === first ? 0 : -1, true);
|
|
@@ -3661,18 +3459,16 @@ const Tab = /*#__PURE__*/react.forwardRef(function Tab(props, forwardedRef) {
|
|
|
3661
3459
|
}
|
|
3662
3460
|
}
|
|
3663
3461
|
};
|
|
3664
|
-
|
|
3665
3462
|
const handleClick = e => {
|
|
3666
3463
|
const allTabs = tabListContext.tabsScope.current.queryAllNodes(scopeQuery);
|
|
3667
3464
|
const currentIndex = ref.current ? allTabs.indexOf(ref.current) : -1;
|
|
3668
|
-
|
|
3669
3465
|
if (currentIndex >= 0) {
|
|
3670
3466
|
tabContext.onChange && tabContext.onChange(e, currentIndex);
|
|
3671
3467
|
}
|
|
3672
3468
|
};
|
|
3673
|
-
|
|
3674
3469
|
const isSelected = tabIndex === tabContext.currentIndex;
|
|
3675
|
-
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3470
|
+
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3471
|
+
...otherProps,
|
|
3676
3472
|
ref: assignMultipleRefs(ref, forwardedRef),
|
|
3677
3473
|
"data-tab": "",
|
|
3678
3474
|
id: tabContext.tabListId !== null && tabIndex >= 0 ? `tab-${tabContext.tabListId}-${tabIndex}` : undefined,
|
|
@@ -3694,15 +3490,13 @@ const TabList = /*#__PURE__*/react.forwardRef(function TabList(props, forwardedR
|
|
|
3694
3490
|
children: childrenProps,
|
|
3695
3491
|
...otherProps
|
|
3696
3492
|
} = props;
|
|
3697
|
-
const ref = react.useRef();
|
|
3493
|
+
const ref = react.useRef(null);
|
|
3698
3494
|
const tabsScope = useScope(ref);
|
|
3699
3495
|
const tabsContext = useTabsContext();
|
|
3700
3496
|
const id = react.useId();
|
|
3701
|
-
|
|
3702
3497
|
if (!tabsContext) {
|
|
3703
3498
|
throw new Error('Missing <Tabs /> in the component tree');
|
|
3704
3499
|
}
|
|
3705
|
-
|
|
3706
3500
|
react.useEffect(() => {
|
|
3707
3501
|
if (id !== undefined) {
|
|
3708
3502
|
tabsContext.setTabListId(id);
|
|
@@ -3710,7 +3504,6 @@ const TabList = /*#__PURE__*/react.forwardRef(function TabList(props, forwardedR
|
|
|
3710
3504
|
tabsContext.setTabListId(null);
|
|
3711
3505
|
};
|
|
3712
3506
|
}
|
|
3713
|
-
|
|
3714
3507
|
return;
|
|
3715
3508
|
}, [id, tabsContext, tabsContext.setTabListId]);
|
|
3716
3509
|
const children = react.Children.map(childrenProps, (node, index) => /*#__PURE__*/react.cloneElement(node, {
|
|
@@ -3759,11 +3552,9 @@ const TabPanel = /*#__PURE__*/react.forwardRef(function TabPanel(props, forwarde
|
|
|
3759
3552
|
...otherProps
|
|
3760
3553
|
} = props;
|
|
3761
3554
|
const tabsContext = useTabsContext();
|
|
3762
|
-
|
|
3763
3555
|
if (!tabsContext) {
|
|
3764
3556
|
throw new Error('Missing <Tabs /> in the component tree.');
|
|
3765
3557
|
}
|
|
3766
|
-
|
|
3767
3558
|
const isSelected = tabsContext.currentIndex === index;
|
|
3768
3559
|
return /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
3769
3560
|
ref: forwardedRef,
|
|
@@ -3780,18 +3571,15 @@ const TabPanel = /*#__PURE__*/react.forwardRef(function TabPanel(props, forwarde
|
|
|
3780
3571
|
|
|
3781
3572
|
function createSubscription() {
|
|
3782
3573
|
const subscriptions = [];
|
|
3783
|
-
|
|
3784
3574
|
function subscribe(fn) {
|
|
3785
3575
|
subscriptions.push(fn);
|
|
3786
3576
|
return () => {
|
|
3787
3577
|
subscriptions.splice(subscriptions.indexOf(fn), 1);
|
|
3788
3578
|
};
|
|
3789
3579
|
}
|
|
3790
|
-
|
|
3791
3580
|
function notify() {
|
|
3792
3581
|
subscriptions.forEach(fn => fn());
|
|
3793
3582
|
}
|
|
3794
|
-
|
|
3795
3583
|
return {
|
|
3796
3584
|
subscribe,
|
|
3797
3585
|
notify
|
|
@@ -3800,45 +3588,43 @@ function createSubscription() {
|
|
|
3800
3588
|
|
|
3801
3589
|
////////////////////////////////////////////////////////////////////////////////
|
|
3802
3590
|
// Timeouts:
|
|
3591
|
+
|
|
3803
3592
|
// Manages when the user "rests" on an element. Keeps the interface from being
|
|
3804
3593
|
// flashing tooltips all the time as the user moves the mouse around the screen.
|
|
3805
3594
|
let restTimeout;
|
|
3806
|
-
|
|
3807
3595
|
function startRestTimer() {
|
|
3808
3596
|
clearTimeout(restTimeout);
|
|
3809
3597
|
restTimeout = setTimeout(() => {
|
|
3810
3598
|
send(Rest, undefined);
|
|
3811
3599
|
}, 200);
|
|
3812
3600
|
}
|
|
3813
|
-
|
|
3814
3601
|
function clearRestTimer() {
|
|
3815
3602
|
clearTimeout(restTimeout);
|
|
3816
|
-
}
|
|
3817
|
-
|
|
3603
|
+
}
|
|
3818
3604
|
|
|
3605
|
+
// Manages the delay to hide the tooltip after rest leaves.
|
|
3819
3606
|
let leavingVisibleTimer;
|
|
3820
|
-
|
|
3821
3607
|
function startLeavingVisibleTimer() {
|
|
3822
3608
|
clearTimeout(leavingVisibleTimer);
|
|
3823
3609
|
leavingVisibleTimer = setTimeout(() => send(TimeComplete, undefined), 100);
|
|
3824
3610
|
}
|
|
3825
|
-
|
|
3826
3611
|
function clearLeavingVisibleTimer() {
|
|
3827
3612
|
clearTimeout(leavingVisibleTimer);
|
|
3828
|
-
}
|
|
3829
|
-
// State machine
|
|
3613
|
+
}
|
|
3830
3614
|
|
|
3615
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
3616
|
+
// State machine
|
|
3831
3617
|
|
|
3832
3618
|
// Nothing goin' on
|
|
3833
|
-
const Idle = 'IDLE';
|
|
3834
|
-
|
|
3835
|
-
const Focused = 'FOCUSED';
|
|
3836
|
-
|
|
3837
|
-
const Visible = 'VISIBLE';
|
|
3838
|
-
|
|
3839
|
-
const LeavingVisible = 'LEAVING_VISIBLE';
|
|
3619
|
+
const Idle = 'IDLE';
|
|
3620
|
+
// We're considering showing the tooltip, but we're gonna wait a sec
|
|
3621
|
+
const Focused = 'FOCUSED';
|
|
3622
|
+
// It's on!
|
|
3623
|
+
const Visible = 'VISIBLE';
|
|
3624
|
+
// Focus has left, but we want to keep it visible for a sec
|
|
3625
|
+
const LeavingVisible = 'LEAVING_VISIBLE';
|
|
3626
|
+
// The user clicked the tool, so we want to hide the thing, we can't just use
|
|
3840
3627
|
// IDLE because we need to ignore mousemove, etc.
|
|
3841
|
-
|
|
3842
3628
|
const Dismissed = 'DISMISSED';
|
|
3843
3629
|
const Blur = 'BLUR';
|
|
3844
3630
|
const Focus = 'FOCUS';
|
|
@@ -3857,11 +3643,9 @@ const state = {
|
|
|
3857
3643
|
id: ''
|
|
3858
3644
|
}
|
|
3859
3645
|
};
|
|
3860
|
-
|
|
3861
3646
|
function clearContextId() {
|
|
3862
3647
|
state.current.id = '';
|
|
3863
3648
|
}
|
|
3864
|
-
|
|
3865
3649
|
const chart = {
|
|
3866
3650
|
initial: Idle,
|
|
3867
3651
|
states: {
|
|
@@ -3921,11 +3705,12 @@ const chart = {
|
|
|
3921
3705
|
}
|
|
3922
3706
|
}
|
|
3923
3707
|
};
|
|
3924
|
-
|
|
3925
3708
|
function transition(currentState, event, payload) {
|
|
3926
3709
|
const currentStateValue = currentState.state;
|
|
3927
3710
|
const stateDef = chart.states[currentState.state];
|
|
3928
|
-
const nextState = stateDef?.on?.[event];
|
|
3711
|
+
const nextState = stateDef?.on?.[event];
|
|
3712
|
+
|
|
3713
|
+
// Really useful for debugging
|
|
3929
3714
|
// console.log({
|
|
3930
3715
|
// event,
|
|
3931
3716
|
// state: state.current.state,
|
|
@@ -3936,27 +3721,22 @@ function transition(currentState, event, payload) {
|
|
|
3936
3721
|
if (!nextState) {
|
|
3937
3722
|
return currentState;
|
|
3938
3723
|
}
|
|
3939
|
-
|
|
3940
3724
|
if (stateDef && stateDef.leave) {
|
|
3941
3725
|
stateDef.leave(currentStateValue, payload);
|
|
3942
3726
|
}
|
|
3943
|
-
|
|
3944
3727
|
const nextStateValue = nextState;
|
|
3945
3728
|
const nextDef = chart.states[nextStateValue];
|
|
3946
|
-
|
|
3947
3729
|
if (nextDef && nextDef.enter) {
|
|
3948
3730
|
nextDef.enter(nextStateValue, payload);
|
|
3949
3731
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3732
|
+
return {
|
|
3733
|
+
...currentState,
|
|
3952
3734
|
...payload,
|
|
3953
3735
|
state: nextStateValue
|
|
3954
3736
|
};
|
|
3955
3737
|
}
|
|
3956
|
-
|
|
3957
3738
|
function send(event, payload) {
|
|
3958
3739
|
const nextState = transition(state.current, event, payload);
|
|
3959
|
-
|
|
3960
3740
|
if (state.current !== nextState) {
|
|
3961
3741
|
state.current = nextState;
|
|
3962
3742
|
subscription.notify();
|
|
@@ -3981,49 +3761,41 @@ function useTooltip(childProps, childRef, tooltipProps) {
|
|
|
3981
3761
|
setVisible((state.current.state === Visible || state.current.state === LeavingVisible) && state.current.id === id);
|
|
3982
3762
|
});
|
|
3983
3763
|
}, [id]);
|
|
3984
|
-
|
|
3985
3764
|
function handleMouseEnter() {
|
|
3986
3765
|
send(MouseEnter, {
|
|
3987
3766
|
id
|
|
3988
3767
|
});
|
|
3989
3768
|
}
|
|
3990
|
-
|
|
3991
3769
|
function handleMouseMove() {
|
|
3992
3770
|
send(MouseMove, {
|
|
3993
3771
|
id
|
|
3994
3772
|
});
|
|
3995
3773
|
}
|
|
3996
|
-
|
|
3997
3774
|
function handleMouseLeave() {
|
|
3998
3775
|
send(MouseLeave);
|
|
3999
3776
|
}
|
|
4000
|
-
|
|
4001
3777
|
function handleMouseDown() {
|
|
4002
3778
|
// Allow quick click from one tool to another
|
|
4003
3779
|
if (state.current.id === id) {
|
|
4004
3780
|
send(MouseDown);
|
|
4005
3781
|
}
|
|
4006
3782
|
}
|
|
4007
|
-
|
|
4008
3783
|
function handleFocus() {
|
|
4009
3784
|
send(Focus, {
|
|
4010
3785
|
id
|
|
4011
3786
|
});
|
|
4012
3787
|
}
|
|
4013
|
-
|
|
4014
3788
|
function handleBlur() {
|
|
4015
3789
|
// Allow quick click from one tool to another
|
|
4016
3790
|
if (state.current.id === id) {
|
|
4017
3791
|
send(Blur, undefined);
|
|
4018
3792
|
}
|
|
4019
3793
|
}
|
|
4020
|
-
|
|
4021
3794
|
function handleKeyDown(event) {
|
|
4022
3795
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
4023
3796
|
send(SelectWithKeyboard);
|
|
4024
3797
|
}
|
|
4025
3798
|
}
|
|
4026
|
-
|
|
4027
3799
|
const {
|
|
4028
3800
|
label: children,
|
|
4029
3801
|
onMouseEnter: tooltipOnMouseEnter,
|
|
@@ -4032,7 +3804,8 @@ function useTooltip(childProps, childRef, tooltipProps) {
|
|
|
4032
3804
|
...otherTooltipProps
|
|
4033
3805
|
} = tooltipProps;
|
|
4034
3806
|
const tooltipId = `tooltip-${id}`;
|
|
4035
|
-
return [{
|
|
3807
|
+
return [{
|
|
3808
|
+
...childProps,
|
|
4036
3809
|
ref: assignMultipleRefs(childRef, anchorEl),
|
|
4037
3810
|
...(visible && !childProps['aria-label'] && {
|
|
4038
3811
|
'aria-describedby': tooltipId
|
|
@@ -4066,17 +3839,17 @@ const Tooltip = /*#__PURE__*/react.forwardRef(function Tooltip(props, forwardedR
|
|
|
4066
3839
|
...otherProps
|
|
4067
3840
|
} = props;
|
|
4068
3841
|
const child = react.Children.only(children);
|
|
3842
|
+
// React 19: ref lives in props. React <=18: ref lives on element directly.
|
|
3843
|
+
const childRef = child.props.ref ?? child.ref;
|
|
4069
3844
|
const [childProps, {
|
|
4070
3845
|
visible,
|
|
4071
3846
|
...tooltipProps
|
|
4072
|
-
}] = useTooltip(child.props,
|
|
4073
|
-
|
|
3847
|
+
}] = useTooltip(child.props, childRef, otherProps);
|
|
4074
3848
|
if (disabled) {
|
|
4075
3849
|
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
4076
3850
|
children: child
|
|
4077
3851
|
});
|
|
4078
3852
|
}
|
|
4079
|
-
|
|
4080
3853
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
4081
3854
|
children: [/*#__PURE__*/react.cloneElement(child, childProps), visible && /*#__PURE__*/jsxRuntime.jsx(Comp, {
|
|
4082
3855
|
as: innerAs,
|