@box/blueprint-web 19.6.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_LICENSES +119 -0
- package/dist/lib-esm/accordion/accordion.js +6 -6
- package/dist/lib-esm/accordion/types.d.ts +1 -1
- package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
- package/dist/lib-esm/checkbox/types.d.ts +1 -1
- package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
- package/dist/lib-esm/collapsible/types.d.ts +1 -1
- package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
- package/dist/lib-esm/date-picker/date-picker.js +8 -7
- package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
- package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
- package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
- package/dist/lib-esm/modal/modal-close.js +2 -2
- package/dist/lib-esm/modal/modal-content.d.ts +1 -1
- package/dist/lib-esm/modal/modal-content.js +4 -4
- package/dist/lib-esm/modal/modal-description.js +2 -2
- package/dist/lib-esm/modal/modal-title.js +2 -2
- package/dist/lib-esm/modal/modal-trigger.js +2 -2
- package/dist/lib-esm/modal/modal.d.ts +1 -1
- package/dist/lib-esm/modal/modal.js +1 -1
- package/dist/lib-esm/modal/types.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
- package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
- package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/chip.js +2 -2
- package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
- package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
- package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
- package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
- package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
- package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
- package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
- package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
- package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
- package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
- package/dist/lib-esm/radio-group/index.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.js +2 -2
- package/dist/lib-esm/radio-group/radio-item.js +3 -3
- package/dist/lib-esm/radio-group/types.d.ts +1 -1
- package/dist/lib-esm/select/select.js +12 -12
- package/dist/lib-esm/select/types.d.ts +1 -1
- package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
- package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
- package/dist/lib-esm/side-panel/side-panel.js +1 -1
- package/dist/lib-esm/side-panel/types.d.ts +1 -1
- package/dist/lib-esm/switch/switch-item.js +3 -3
- package/dist/lib-esm/switch/types.d.ts +1 -1
- package/dist/lib-esm/toolbar/index.d.ts +2 -2
- package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
- package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
- package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/types.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.js +6 -6
- package/dist/lib-esm/tooltip/types.d.ts +1 -1
- package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
- package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
- package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
- package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
- package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
- package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
- package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
- package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
- package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
- package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
- package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
- package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
- package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
- package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
- package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
- package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
- package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
- package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
- package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
- package/dist/lib-esm/utils/radix-compat/select.js +901 -0
- package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
- package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
- package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
- package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
- package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
- package/package.json +8 -19
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useStoreState, Tooltip, useTooltipStore } from '@ariakit/react';
|
|
3
|
+
import { forwardRef, useRef, useCallback, useEffect, useContext, createContext, useState, useId, useMemo } from 'react';
|
|
4
|
+
import { composeEventHandlers } from '../composeEventHandlers.js';
|
|
5
|
+
import { useControllableState } from '../useControllableState.js';
|
|
6
|
+
import { AllowAutoFocus } from './allow-auto-focus.js';
|
|
7
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
8
|
+
import { useDismissable } from './dismissable.js';
|
|
9
|
+
import { PopperArrow, usePopper, PopperArrowProvider, getPopperCssVariables } from './popper.js';
|
|
10
|
+
import { Portal as Portal$1 } from './portal.js';
|
|
11
|
+
import { Presence } from './presence.js';
|
|
12
|
+
import { Slot, getAsChildRender } from './slot.js';
|
|
13
|
+
import { overlayStoreOptions } from './store-options.js';
|
|
14
|
+
import { useStripViewportHeight } from './viewport-height.js';
|
|
15
|
+
import { VisuallyHidden } from './visually-hidden.js';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_DELAY_DURATION = 700;
|
|
18
|
+
const TOOLTIP_OPEN = 'tooltip.open';
|
|
19
|
+
const TooltipProviderContext = /*#__PURE__*/createContext(null);
|
|
20
|
+
function useTooltipProviderContext(consumerName) {
|
|
21
|
+
const context = useContext(TooltipProviderContext);
|
|
22
|
+
if (!context) {
|
|
23
|
+
throw new Error(`\`${consumerName}\` must be used within \`TooltipProvider\``);
|
|
24
|
+
}
|
|
25
|
+
return context;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Shares the open delays of all tooltips, like the Radix `TooltipProvider`: once a tooltip opened, other
|
|
29
|
+
* tooltips open instantly until `skipDelayDuration` passed since the last one closed.
|
|
30
|
+
*/
|
|
31
|
+
const Provider = ({
|
|
32
|
+
children,
|
|
33
|
+
delayDuration = DEFAULT_DELAY_DURATION,
|
|
34
|
+
skipDelayDuration = 300,
|
|
35
|
+
disableHoverableContent = false
|
|
36
|
+
}) => {
|
|
37
|
+
const [isOpenDelayed, setIsOpenDelayed] = useState(true);
|
|
38
|
+
const isPointerInTransitRef = useRef(false);
|
|
39
|
+
const skipDelayTimerRef = useRef(0);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const skipDelayTimer = skipDelayTimerRef.current;
|
|
42
|
+
return () => window.clearTimeout(skipDelayTimer);
|
|
43
|
+
}, []);
|
|
44
|
+
const onOpen = useCallback(() => {
|
|
45
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
|
46
|
+
setIsOpenDelayed(false);
|
|
47
|
+
}, []);
|
|
48
|
+
const onClose = useCallback(() => {
|
|
49
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
|
50
|
+
skipDelayTimerRef.current = window.setTimeout(() => setIsOpenDelayed(true), skipDelayDuration);
|
|
51
|
+
}, [skipDelayDuration]);
|
|
52
|
+
const onPointerInTransitChange = useCallback(inTransit => {
|
|
53
|
+
isPointerInTransitRef.current = inTransit;
|
|
54
|
+
}, []);
|
|
55
|
+
const value = useMemo(() => ({
|
|
56
|
+
isOpenDelayed,
|
|
57
|
+
delayDuration,
|
|
58
|
+
onOpen,
|
|
59
|
+
onClose,
|
|
60
|
+
onPointerInTransitChange,
|
|
61
|
+
isPointerInTransitRef,
|
|
62
|
+
disableHoverableContent
|
|
63
|
+
}), [isOpenDelayed, delayDuration, onOpen, onClose, onPointerInTransitChange, disableHoverableContent]);
|
|
64
|
+
return jsx(TooltipProviderContext.Provider, {
|
|
65
|
+
value: value,
|
|
66
|
+
children: children
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
Provider.displayName = 'TooltipProvider';
|
|
70
|
+
const TooltipContext = /*#__PURE__*/createContext(null);
|
|
71
|
+
function useTooltipContext(consumerName) {
|
|
72
|
+
const context = useContext(TooltipContext);
|
|
73
|
+
if (!context) {
|
|
74
|
+
throw new Error(`\`${consumerName}\` must be used within \`Tooltip\``);
|
|
75
|
+
}
|
|
76
|
+
return context;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Tooltip with the Radix API, DOM and open/close state machine (pointer move opens after the provider delay,
|
|
80
|
+
* focus opens instantly, pointer down, click, blur and scroll close it), rendered by the Ariakit `Tooltip`.
|
|
81
|
+
*/
|
|
82
|
+
const Root = props => {
|
|
83
|
+
const {
|
|
84
|
+
children,
|
|
85
|
+
open: openProp,
|
|
86
|
+
defaultOpen = false,
|
|
87
|
+
onOpenChange,
|
|
88
|
+
disableHoverableContent: disableHoverableContentProp,
|
|
89
|
+
delayDuration: delayDurationProp
|
|
90
|
+
} = props;
|
|
91
|
+
const providerContext = useTooltipProviderContext('Tooltip');
|
|
92
|
+
const [trigger, setTrigger] = useState(null);
|
|
93
|
+
const contentId = useId();
|
|
94
|
+
const openTimerRef = useRef(0);
|
|
95
|
+
const disableHoverableContent = disableHoverableContentProp ?? providerContext.disableHoverableContent;
|
|
96
|
+
const delayDuration = delayDurationProp ?? providerContext.delayDuration;
|
|
97
|
+
const wasOpenDelayedRef = useRef(false);
|
|
98
|
+
const [open = false, setOpen] = useControllableState({
|
|
99
|
+
prop: openProp,
|
|
100
|
+
defaultProp: defaultOpen,
|
|
101
|
+
onChange: nextOpen => {
|
|
102
|
+
if (nextOpen) {
|
|
103
|
+
providerContext.onOpen();
|
|
104
|
+
document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
|
|
105
|
+
} else {
|
|
106
|
+
providerContext.onClose();
|
|
107
|
+
}
|
|
108
|
+
onOpenChange?.(nextOpen);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const stateAttribute = useMemo(() => {
|
|
112
|
+
if (!open) {
|
|
113
|
+
return 'closed';
|
|
114
|
+
}
|
|
115
|
+
return wasOpenDelayedRef.current ? 'delayed-open' : 'instant-open';
|
|
116
|
+
}, [open]);
|
|
117
|
+
const handleOpen = useCallback(() => {
|
|
118
|
+
window.clearTimeout(openTimerRef.current);
|
|
119
|
+
wasOpenDelayedRef.current = false;
|
|
120
|
+
setOpen(true);
|
|
121
|
+
}, [setOpen]);
|
|
122
|
+
const handleClose = useCallback(() => {
|
|
123
|
+
window.clearTimeout(openTimerRef.current);
|
|
124
|
+
setOpen(false);
|
|
125
|
+
}, [setOpen]);
|
|
126
|
+
const handleDelayedOpen = useCallback(() => {
|
|
127
|
+
window.clearTimeout(openTimerRef.current);
|
|
128
|
+
openTimerRef.current = window.setTimeout(() => {
|
|
129
|
+
wasOpenDelayedRef.current = true;
|
|
130
|
+
setOpen(true);
|
|
131
|
+
}, delayDuration);
|
|
132
|
+
}, [delayDuration, setOpen]);
|
|
133
|
+
useEffect(() => () => window.clearTimeout(openTimerRef.current), []);
|
|
134
|
+
const store = useTooltipStore({
|
|
135
|
+
...overlayStoreOptions,
|
|
136
|
+
open,
|
|
137
|
+
setOpen: nextOpen => {
|
|
138
|
+
if (!nextOpen) {
|
|
139
|
+
handleClose();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
store.setAnchorElement(trigger);
|
|
145
|
+
}, [store, trigger]);
|
|
146
|
+
const {
|
|
147
|
+
isOpenDelayed
|
|
148
|
+
} = providerContext;
|
|
149
|
+
const onTriggerEnter = useCallback(() => {
|
|
150
|
+
if (isOpenDelayed) {
|
|
151
|
+
handleDelayedOpen();
|
|
152
|
+
} else {
|
|
153
|
+
handleOpen();
|
|
154
|
+
}
|
|
155
|
+
}, [isOpenDelayed, handleDelayedOpen, handleOpen]);
|
|
156
|
+
const onTriggerLeave = useCallback(() => {
|
|
157
|
+
if (disableHoverableContent) {
|
|
158
|
+
handleClose();
|
|
159
|
+
} else {
|
|
160
|
+
// Clear the timer in case the pointer leaves the trigger before the tooltip is opened.
|
|
161
|
+
window.clearTimeout(openTimerRef.current);
|
|
162
|
+
}
|
|
163
|
+
}, [handleClose, disableHoverableContent]);
|
|
164
|
+
const value = useMemo(() => ({
|
|
165
|
+
contentId,
|
|
166
|
+
open,
|
|
167
|
+
stateAttribute,
|
|
168
|
+
trigger,
|
|
169
|
+
onTriggerChange: setTrigger,
|
|
170
|
+
onTriggerEnter,
|
|
171
|
+
onTriggerLeave,
|
|
172
|
+
onOpen: handleOpen,
|
|
173
|
+
onClose: handleClose,
|
|
174
|
+
disableHoverableContent,
|
|
175
|
+
store
|
|
176
|
+
}), [contentId, open, stateAttribute, trigger, onTriggerEnter, onTriggerLeave, handleOpen, handleClose, disableHoverableContent, store]);
|
|
177
|
+
return jsx(TooltipContext.Provider, {
|
|
178
|
+
value: value,
|
|
179
|
+
children: children
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
Root.displayName = 'Tooltip';
|
|
183
|
+
const Trigger = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
184
|
+
const {
|
|
185
|
+
asChild,
|
|
186
|
+
...triggerProps
|
|
187
|
+
} = props;
|
|
188
|
+
const context = useTooltipContext('TooltipTrigger');
|
|
189
|
+
const providerContext = useTooltipProviderContext('TooltipTrigger');
|
|
190
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
|
|
191
|
+
const isPointerDownRef = useRef(false);
|
|
192
|
+
const hasPointerMoveOpenedRef = useRef(false);
|
|
193
|
+
const handlePointerUp = useCallback(() => {
|
|
194
|
+
isPointerDownRef.current = false;
|
|
195
|
+
}, []);
|
|
196
|
+
useEffect(() => () => document.removeEventListener('pointerup', handlePointerUp), [handlePointerUp]);
|
|
197
|
+
const Comp = asChild ? Slot : 'button';
|
|
198
|
+
return jsx(Comp
|
|
199
|
+
// Tooltip triggers are often links, so `type=button` isn't set, as in Radix.
|
|
200
|
+
, {
|
|
201
|
+
"aria-describedby": context.open ? context.contentId : undefined,
|
|
202
|
+
"data-state": context.stateAttribute,
|
|
203
|
+
...triggerProps,
|
|
204
|
+
ref: composedRefs,
|
|
205
|
+
onPointerMove: composeEventHandlers(props.onPointerMove, event => {
|
|
206
|
+
if (event.pointerType === 'touch') {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
|
|
210
|
+
context.onTriggerEnter();
|
|
211
|
+
hasPointerMoveOpenedRef.current = true;
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
onPointerLeave: composeEventHandlers(props.onPointerLeave, () => {
|
|
215
|
+
context.onTriggerLeave();
|
|
216
|
+
hasPointerMoveOpenedRef.current = false;
|
|
217
|
+
}),
|
|
218
|
+
onPointerDown: composeEventHandlers(props.onPointerDown, () => {
|
|
219
|
+
isPointerDownRef.current = true;
|
|
220
|
+
document.addEventListener('pointerup', handlePointerUp, {
|
|
221
|
+
once: true
|
|
222
|
+
});
|
|
223
|
+
}),
|
|
224
|
+
onFocus: composeEventHandlers(props.onFocus, () => {
|
|
225
|
+
if (!isPointerDownRef.current) {
|
|
226
|
+
context.onOpen();
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
onBlur: composeEventHandlers(props.onBlur, context.onClose),
|
|
230
|
+
onClick: composeEventHandlers(props.onClick, context.onClose)
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
Trigger.displayName = 'TooltipTrigger';
|
|
234
|
+
/* -------------------------------------------------------------------------------------------------
|
|
235
|
+
* Portal
|
|
236
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
237
|
+
const PortalContext = /*#__PURE__*/createContext({
|
|
238
|
+
forceMount: undefined
|
|
239
|
+
});
|
|
240
|
+
const Portal = ({
|
|
241
|
+
forceMount,
|
|
242
|
+
children,
|
|
243
|
+
container
|
|
244
|
+
}) => {
|
|
245
|
+
const context = useTooltipContext('TooltipPortal');
|
|
246
|
+
return jsx(PortalContext.Provider, {
|
|
247
|
+
value: {
|
|
248
|
+
forceMount
|
|
249
|
+
},
|
|
250
|
+
children: jsx(Presence, {
|
|
251
|
+
present: Boolean(forceMount) || context.open,
|
|
252
|
+
children: jsx(Portal$1, {
|
|
253
|
+
container: container,
|
|
254
|
+
children: children
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
Portal.displayName = 'TooltipPortal';
|
|
260
|
+
const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
261
|
+
const portalContext = useContext(PortalContext);
|
|
262
|
+
const {
|
|
263
|
+
forceMount = portalContext.forceMount,
|
|
264
|
+
side = 'top',
|
|
265
|
+
...contentProps
|
|
266
|
+
} = props;
|
|
267
|
+
const context = useTooltipContext('TooltipContent');
|
|
268
|
+
return jsx(Presence, {
|
|
269
|
+
present: Boolean(forceMount) || context.open,
|
|
270
|
+
children: context.disableHoverableContent ? jsx(ContentImpl, {
|
|
271
|
+
side: side,
|
|
272
|
+
...contentProps,
|
|
273
|
+
ref: forwardedRef
|
|
274
|
+
}) : jsx(ContentHoverable, {
|
|
275
|
+
side: side,
|
|
276
|
+
...contentProps,
|
|
277
|
+
ref: forwardedRef
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
Content.displayName = 'TooltipContent';
|
|
282
|
+
/** Keeps the tooltip open while the pointer moves from the trigger to the content (Radix's grace area). */
|
|
283
|
+
const ContentHoverable = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
284
|
+
const context = useTooltipContext('TooltipContent');
|
|
285
|
+
const providerContext = useTooltipProviderContext('TooltipContent');
|
|
286
|
+
const [content, setContent] = useState(null);
|
|
287
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
288
|
+
const [pointerGraceArea, setPointerGraceArea] = useState(null);
|
|
289
|
+
const {
|
|
290
|
+
trigger,
|
|
291
|
+
onClose
|
|
292
|
+
} = context;
|
|
293
|
+
const {
|
|
294
|
+
onPointerInTransitChange
|
|
295
|
+
} = providerContext;
|
|
296
|
+
const handleRemoveGraceArea = useCallback(() => {
|
|
297
|
+
setPointerGraceArea(null);
|
|
298
|
+
onPointerInTransitChange(false);
|
|
299
|
+
}, [onPointerInTransitChange]);
|
|
300
|
+
const handleCreateGraceArea = useCallback((event, hoverTarget) => {
|
|
301
|
+
const currentTarget = event.currentTarget;
|
|
302
|
+
const exitPoint = {
|
|
303
|
+
x: event.clientX,
|
|
304
|
+
y: event.clientY
|
|
305
|
+
};
|
|
306
|
+
const exitSide = getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
|
|
307
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
|
308
|
+
const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
|
|
309
|
+
setPointerGraceArea(getHull([...paddedExitPoints, ...hoverTargetPoints]));
|
|
310
|
+
onPointerInTransitChange(true);
|
|
311
|
+
}, [onPointerInTransitChange]);
|
|
312
|
+
useEffect(() => () => handleRemoveGraceArea(), [handleRemoveGraceArea]);
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
if (!trigger || !content) {
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
const handleTriggerLeave = event => handleCreateGraceArea(event, content);
|
|
318
|
+
const handleContentLeave = event => handleCreateGraceArea(event, trigger);
|
|
319
|
+
trigger.addEventListener('pointerleave', handleTriggerLeave);
|
|
320
|
+
content.addEventListener('pointerleave', handleContentLeave);
|
|
321
|
+
return () => {
|
|
322
|
+
trigger.removeEventListener('pointerleave', handleTriggerLeave);
|
|
323
|
+
content.removeEventListener('pointerleave', handleContentLeave);
|
|
324
|
+
};
|
|
325
|
+
}, [trigger, content, handleCreateGraceArea, handleRemoveGraceArea]);
|
|
326
|
+
useEffect(() => {
|
|
327
|
+
if (!pointerGraceArea) {
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
const handleTrackPointerGrace = event => {
|
|
331
|
+
const target = event.target;
|
|
332
|
+
const pointerPosition = {
|
|
333
|
+
x: event.clientX,
|
|
334
|
+
y: event.clientY
|
|
335
|
+
};
|
|
336
|
+
const hasEnteredTarget = trigger?.contains(target) || content?.contains(target);
|
|
337
|
+
const isPointerOutsideGraceArea = !isPointInPolygon(pointerPosition, pointerGraceArea);
|
|
338
|
+
if (hasEnteredTarget) {
|
|
339
|
+
handleRemoveGraceArea();
|
|
340
|
+
} else if (isPointerOutsideGraceArea) {
|
|
341
|
+
handleRemoveGraceArea();
|
|
342
|
+
onClose();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
document.addEventListener('pointermove', handleTrackPointerGrace);
|
|
346
|
+
return () => document.removeEventListener('pointermove', handleTrackPointerGrace);
|
|
347
|
+
}, [trigger, content, pointerGraceArea, onClose, handleRemoveGraceArea]);
|
|
348
|
+
return jsx(ContentImpl, {
|
|
349
|
+
...props,
|
|
350
|
+
ref: composedRefs
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
const preventFocusOutsideDismiss = event => event.preventDefault();
|
|
354
|
+
const noopUpdatePosition = () => undefined;
|
|
355
|
+
// Ariakit gives the tooltip element `role="tooltip"`; as in Radix, only the visually hidden copy has the role.
|
|
356
|
+
const renderWithoutRole = ({
|
|
357
|
+
role: _role,
|
|
358
|
+
...htmlProps
|
|
359
|
+
}) => jsx("div", {
|
|
360
|
+
...htmlProps
|
|
361
|
+
});
|
|
362
|
+
const ContentImpl = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
363
|
+
const {
|
|
364
|
+
children,
|
|
365
|
+
'aria-label': ariaLabel,
|
|
366
|
+
onEscapeKeyDown,
|
|
367
|
+
onPointerDownOutside,
|
|
368
|
+
side,
|
|
369
|
+
sideOffset,
|
|
370
|
+
align,
|
|
371
|
+
alignOffset,
|
|
372
|
+
arrowPadding,
|
|
373
|
+
avoidCollisions,
|
|
374
|
+
collisionBoundary,
|
|
375
|
+
collisionPadding,
|
|
376
|
+
sticky,
|
|
377
|
+
hideWhenDetached,
|
|
378
|
+
updatePositionStrategy,
|
|
379
|
+
onPlaced,
|
|
380
|
+
asChild,
|
|
381
|
+
style,
|
|
382
|
+
...contentProps
|
|
383
|
+
} = props;
|
|
384
|
+
const context = useTooltipContext('TooltipContent');
|
|
385
|
+
const {
|
|
386
|
+
onClose,
|
|
387
|
+
trigger,
|
|
388
|
+
store
|
|
389
|
+
} = context;
|
|
390
|
+
const [content, setContent] = useState(null);
|
|
391
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
392
|
+
const wrapper = useStoreState(store, 'popoverElement');
|
|
393
|
+
useStripViewportHeight(content);
|
|
394
|
+
// Close this tooltip if another one opens.
|
|
395
|
+
useEffect(() => {
|
|
396
|
+
document.addEventListener(TOOLTIP_OPEN, onClose);
|
|
397
|
+
return () => document.removeEventListener(TOOLTIP_OPEN, onClose);
|
|
398
|
+
}, [onClose]);
|
|
399
|
+
// Close the tooltip if the trigger is scrolled.
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
if (!trigger) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
const handleScroll = event => {
|
|
405
|
+
const target = event.target;
|
|
406
|
+
if (target?.contains(trigger)) {
|
|
407
|
+
onClose();
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
window.addEventListener('scroll', handleScroll, {
|
|
411
|
+
capture: true
|
|
412
|
+
});
|
|
413
|
+
return () => window.removeEventListener('scroll', handleScroll, {
|
|
414
|
+
capture: true
|
|
415
|
+
});
|
|
416
|
+
}, [trigger, onClose]);
|
|
417
|
+
const dismissable = useDismissable({
|
|
418
|
+
open: context.open,
|
|
419
|
+
onDismiss: onClose,
|
|
420
|
+
onEscapeKeyDown,
|
|
421
|
+
onPointerDownOutside,
|
|
422
|
+
onFocusOutside: preventFocusOutsideDismiss
|
|
423
|
+
});
|
|
424
|
+
const popper = usePopper({
|
|
425
|
+
anchor: trigger,
|
|
426
|
+
wrapper,
|
|
427
|
+
content,
|
|
428
|
+
side,
|
|
429
|
+
sideOffset,
|
|
430
|
+
align,
|
|
431
|
+
alignOffset,
|
|
432
|
+
arrowPadding,
|
|
433
|
+
avoidCollisions,
|
|
434
|
+
collisionBoundary,
|
|
435
|
+
collisionPadding,
|
|
436
|
+
sticky,
|
|
437
|
+
hideWhenDetached,
|
|
438
|
+
updatePositionStrategy,
|
|
439
|
+
onPlaced
|
|
440
|
+
});
|
|
441
|
+
const asChildRender = getAsChildRender(asChild, children, contentChildren => jsxs(Fragment, {
|
|
442
|
+
children: [jsx(AllowAutoFocus, {
|
|
443
|
+
children: contentChildren
|
|
444
|
+
}), jsx(VisuallyHidden, {
|
|
445
|
+
id: context.contentId,
|
|
446
|
+
role: "tooltip",
|
|
447
|
+
children: ariaLabel || contentChildren
|
|
448
|
+
})]
|
|
449
|
+
}), ['role']);
|
|
450
|
+
return jsx(PopperArrowProvider, {
|
|
451
|
+
value: popper.arrowContext,
|
|
452
|
+
children: jsx(Tooltip, {
|
|
453
|
+
alwaysVisible: true,
|
|
454
|
+
autoFocusOnHide: false,
|
|
455
|
+
autoFocusOnShow: false,
|
|
456
|
+
"data-side": popper.contentProps['data-side'],
|
|
457
|
+
"data-align": popper.contentProps['data-align'],
|
|
458
|
+
"data-state": context.stateAttribute,
|
|
459
|
+
disablePointerEventsOnApproach: false,
|
|
460
|
+
focusable: false,
|
|
461
|
+
hideOnEscape: false,
|
|
462
|
+
hideOnHoverOutside: false,
|
|
463
|
+
hideOnInteractOutside: dismissable.hideOnInteractOutside,
|
|
464
|
+
portal: false,
|
|
465
|
+
render: asChildRender.render ?? renderWithoutRole,
|
|
466
|
+
store: store,
|
|
467
|
+
updatePosition: noopUpdatePosition,
|
|
468
|
+
...contentProps,
|
|
469
|
+
// `wrapperProps` isn't Radix API, so a consumer's mustn't replace the positioning ones.
|
|
470
|
+
wrapperProps: popper.wrapperProps,
|
|
471
|
+
ref: composedRefs,
|
|
472
|
+
onBlurCapture: composeEventHandlers(contentProps.onBlurCapture, dismissable.contentProps.onBlurCapture),
|
|
473
|
+
onFocusCapture: composeEventHandlers(contentProps.onFocusCapture, dismissable.contentProps.onFocusCapture),
|
|
474
|
+
onPointerDownCapture: composeEventHandlers(contentProps.onPointerDownCapture, dismissable.contentProps.onPointerDownCapture),
|
|
475
|
+
style: {
|
|
476
|
+
...style,
|
|
477
|
+
...getPopperCssVariables('tooltip'),
|
|
478
|
+
...popper.contentProps.style
|
|
479
|
+
},
|
|
480
|
+
children: asChildRender.children
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
const Arrow = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(PopperArrow, {
|
|
485
|
+
...props,
|
|
486
|
+
ref: forwardedRef
|
|
487
|
+
}));
|
|
488
|
+
Arrow.displayName = 'TooltipArrow';
|
|
489
|
+
/* -----------------------------------------------------------------------------------------------*/
|
|
490
|
+
function getExitSideFromRect(point, rect) {
|
|
491
|
+
const top = Math.abs(rect.top - point.y);
|
|
492
|
+
const bottom = Math.abs(rect.bottom - point.y);
|
|
493
|
+
const right = Math.abs(rect.right - point.x);
|
|
494
|
+
const left = Math.abs(rect.left - point.x);
|
|
495
|
+
switch (Math.min(top, bottom, right, left)) {
|
|
496
|
+
case left:
|
|
497
|
+
return 'left';
|
|
498
|
+
case right:
|
|
499
|
+
return 'right';
|
|
500
|
+
case top:
|
|
501
|
+
return 'top';
|
|
502
|
+
default:
|
|
503
|
+
return 'bottom';
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
|
507
|
+
switch (exitSide) {
|
|
508
|
+
case 'top':
|
|
509
|
+
return [{
|
|
510
|
+
x: exitPoint.x - padding,
|
|
511
|
+
y: exitPoint.y + padding
|
|
512
|
+
}, {
|
|
513
|
+
x: exitPoint.x + padding,
|
|
514
|
+
y: exitPoint.y + padding
|
|
515
|
+
}];
|
|
516
|
+
case 'bottom':
|
|
517
|
+
return [{
|
|
518
|
+
x: exitPoint.x - padding,
|
|
519
|
+
y: exitPoint.y - padding
|
|
520
|
+
}, {
|
|
521
|
+
x: exitPoint.x + padding,
|
|
522
|
+
y: exitPoint.y - padding
|
|
523
|
+
}];
|
|
524
|
+
case 'left':
|
|
525
|
+
return [{
|
|
526
|
+
x: exitPoint.x + padding,
|
|
527
|
+
y: exitPoint.y - padding
|
|
528
|
+
}, {
|
|
529
|
+
x: exitPoint.x + padding,
|
|
530
|
+
y: exitPoint.y + padding
|
|
531
|
+
}];
|
|
532
|
+
default:
|
|
533
|
+
return [{
|
|
534
|
+
x: exitPoint.x - padding,
|
|
535
|
+
y: exitPoint.y - padding
|
|
536
|
+
}, {
|
|
537
|
+
x: exitPoint.x - padding,
|
|
538
|
+
y: exitPoint.y + padding
|
|
539
|
+
}];
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function getPointsFromRect(rect) {
|
|
543
|
+
const {
|
|
544
|
+
top,
|
|
545
|
+
right,
|
|
546
|
+
bottom,
|
|
547
|
+
left
|
|
548
|
+
} = rect;
|
|
549
|
+
return [{
|
|
550
|
+
x: left,
|
|
551
|
+
y: top
|
|
552
|
+
}, {
|
|
553
|
+
x: right,
|
|
554
|
+
y: top
|
|
555
|
+
}, {
|
|
556
|
+
x: right,
|
|
557
|
+
y: bottom
|
|
558
|
+
}, {
|
|
559
|
+
x: left,
|
|
560
|
+
y: bottom
|
|
561
|
+
}];
|
|
562
|
+
}
|
|
563
|
+
// Based on https://github.com/substack/point-in-polygon
|
|
564
|
+
function isPointInPolygon(point, polygon) {
|
|
565
|
+
const {
|
|
566
|
+
x,
|
|
567
|
+
y
|
|
568
|
+
} = point;
|
|
569
|
+
let inside = false;
|
|
570
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i, i += 1) {
|
|
571
|
+
const xi = polygon[i].x;
|
|
572
|
+
const yi = polygon[i].y;
|
|
573
|
+
const xj = polygon[j].x;
|
|
574
|
+
const yj = polygon[j].y;
|
|
575
|
+
const isAboveI = yi > y;
|
|
576
|
+
const isAboveJ = yj > y;
|
|
577
|
+
const intersect = isAboveI !== isAboveJ && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
578
|
+
if (intersect) {
|
|
579
|
+
inside = !inside;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return inside;
|
|
583
|
+
}
|
|
584
|
+
// Convex hull, see https://www.nayuki.io/page/convex-hull-algorithm
|
|
585
|
+
function getHull(points) {
|
|
586
|
+
const sortedPoints = points.slice().sort((a, b) => {
|
|
587
|
+
if (a.x !== b.x) {
|
|
588
|
+
return a.x < b.x ? -1 : 1;
|
|
589
|
+
}
|
|
590
|
+
if (a.y !== b.y) {
|
|
591
|
+
return a.y < b.y ? -1 : 1;
|
|
592
|
+
}
|
|
593
|
+
return 0;
|
|
594
|
+
});
|
|
595
|
+
return getHullPresorted(sortedPoints);
|
|
596
|
+
}
|
|
597
|
+
function getHullPresorted(points) {
|
|
598
|
+
if (points.length <= 1) {
|
|
599
|
+
return points.slice();
|
|
600
|
+
}
|
|
601
|
+
const upperHull = [];
|
|
602
|
+
points.forEach(p => {
|
|
603
|
+
while (upperHull.length >= 2) {
|
|
604
|
+
const q = upperHull[upperHull.length - 1];
|
|
605
|
+
const r = upperHull[upperHull.length - 2];
|
|
606
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) {
|
|
607
|
+
upperHull.pop();
|
|
608
|
+
} else {
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
upperHull.push(p);
|
|
613
|
+
});
|
|
614
|
+
upperHull.pop();
|
|
615
|
+
const lowerHull = [];
|
|
616
|
+
for (let i = points.length - 1; i >= 0; i -= 1) {
|
|
617
|
+
const p = points[i];
|
|
618
|
+
while (lowerHull.length >= 2) {
|
|
619
|
+
const q = lowerHull[lowerHull.length - 1];
|
|
620
|
+
const r = lowerHull[lowerHull.length - 2];
|
|
621
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) {
|
|
622
|
+
lowerHull.pop();
|
|
623
|
+
} else {
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
lowerHull.push(p);
|
|
628
|
+
}
|
|
629
|
+
lowerHull.pop();
|
|
630
|
+
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) {
|
|
631
|
+
return upperHull;
|
|
632
|
+
}
|
|
633
|
+
return upperHull.concat(lowerHull);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export { Arrow, Content, Portal, Provider, Root, Root as Tooltip, Arrow as TooltipArrow, Content as TooltipContent, Portal as TooltipPortal, Provider as TooltipProvider, Trigger as TooltipTrigger, Trigger };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the next value matching the search, starting after the current match.
|
|
3
|
+
* Repeating one character cycles through the values starting with it, like in Radix menus and selects.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getNextMatch(values: string[], search: string, currentMatch?: string): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Item based variant of `getNextMatch`, used by the select where several items can share a text.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findNextItem<T extends {
|
|
10
|
+
textValue: string;
|
|
11
|
+
}>(items: T[], search: string, currentItem?: T): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the typeahead search string, reset one second after the last key press.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useTypeaheadSearch(onSearchChange: (search: string) => void): readonly [import("react").MutableRefObject<string>, (key: string) => void, () => void];
|
|
16
|
+
/** Whether the key press should start or continue a typeahead search. */
|
|
17
|
+
export declare function isTypeaheadKey(event: {
|
|
18
|
+
key: string;
|
|
19
|
+
ctrlKey: boolean;
|
|
20
|
+
altKey: boolean;
|
|
21
|
+
metaKey: boolean;
|
|
22
|
+
}): boolean;
|