tfy-web-components 0.0.34 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -58
- package/dist/Button-C77b7jpW.js +284 -0
- package/dist/Button-C77b7jpW.js.map +1 -0
- package/dist/CompositeItem-BGwD51jI.js +33 -0
- package/dist/CompositeItem-BGwD51jI.js.map +1 -0
- package/dist/CompositeList-D4xmSZ5V.js +291 -0
- package/dist/CompositeList-D4xmSZ5V.js.map +1 -0
- package/dist/CompositeRoot-BxrPc7F6.js +351 -0
- package/dist/CompositeRoot-BxrPc7F6.js.map +1 -0
- package/dist/DirectionContext-Pb9yafF5.js +11 -0
- package/dist/DirectionContext-Pb9yafF5.js.map +1 -0
- package/dist/FieldItemContext-DRVgx-D1.js +13 -0
- package/dist/FieldItemContext-DRVgx-D1.js.map +1 -0
- package/dist/{Input-BvwIpntS.js → Input-Dhmo6L2n.js} +100 -78
- package/dist/Input-Dhmo6L2n.js.map +1 -0
- package/dist/Modal-C4MUy9GD.js +696 -0
- package/dist/Modal-C4MUy9GD.js.map +1 -0
- package/dist/{MonacoEditorCore-xfpJ6z-E.js → MonacoEditorCore-n-df5f7I.js} +2 -2
- package/dist/{MonacoEditorCore-xfpJ6z-E.js.map → MonacoEditorCore-n-df5f7I.js.map} +1 -1
- package/dist/Popover-eC_vX5By.js +1074 -0
- package/dist/Popover-eC_vX5By.js.map +1 -0
- package/dist/ToolbarRootContext-B_HxjkNI.js +11 -0
- package/dist/ToolbarRootContext-B_HxjkNI.js.map +1 -0
- package/dist/Tooltip-BuGLP-PU.js +4096 -0
- package/dist/Tooltip-BuGLP-PU.js.map +1 -0
- package/dist/classNames-B1XpQHle.js +44 -0
- package/dist/classNames-B1XpQHle.js.map +1 -0
- package/dist/components/atoms/Accordion.d.ts +19 -37
- package/dist/components/atoms/Accordion.es.js +847 -78
- package/dist/components/atoms/Accordion.es.js.map +1 -1
- package/dist/components/atoms/AudioPlayer.es.js +9 -9
- package/dist/components/atoms/AudioPlayer.es.js.map +1 -1
- package/dist/components/atoms/Avatar.d.ts +42 -9
- package/dist/components/atoms/Avatar.es.js +491 -36
- package/dist/components/atoms/Avatar.es.js.map +1 -1
- package/dist/components/atoms/Badge.d.ts +40 -35
- package/dist/components/atoms/Badge.es.js +163 -53
- package/dist/components/atoms/Badge.es.js.map +1 -1
- package/dist/components/atoms/Button.d.ts +37 -16
- package/dist/components/atoms/Button.es.js +16 -221
- package/dist/components/atoms/Button.es.js.map +1 -1
- package/dist/components/atoms/ButtonGroup.d.ts +53 -0
- package/dist/components/atoms/ButtonGroup.es.js +349 -0
- package/dist/components/atoms/ButtonGroup.es.js.map +1 -0
- package/dist/components/atoms/IconButton.d.ts +23 -9
- package/dist/components/atoms/IconButton.es.js +82 -16
- package/dist/components/atoms/IconButton.es.js.map +1 -1
- package/dist/components/atoms/IconProvider.d.ts +5 -2
- package/dist/components/atoms/IconProvider.es.js +69 -10
- package/dist/components/atoms/IconProvider.es.js.map +1 -1
- package/dist/components/atoms/Logo.d.ts +18 -0
- package/dist/components/atoms/Logo.es.js +79 -0
- package/dist/components/atoms/Logo.es.js.map +1 -0
- package/dist/components/atoms/Modal.d.ts +27 -3
- package/dist/components/atoms/Modal.es.js +15 -16
- package/dist/components/atoms/Modal.es.js.map +1 -1
- package/dist/components/atoms/Notification.d.ts +1 -1
- package/dist/components/atoms/Notification.es.js +26 -3
- package/dist/components/atoms/Notification.es.js.map +1 -1
- package/dist/components/atoms/OutlinedRadio.d.ts +6 -2
- package/dist/components/atoms/OutlinedRadio.es.js +12 -25
- package/dist/components/atoms/OutlinedRadio.es.js.map +1 -1
- package/dist/components/atoms/Progress.d.ts +48 -0
- package/dist/components/atoms/Progress.es.js +279 -0
- package/dist/components/atoms/Progress.es.js.map +1 -0
- package/dist/components/atoms/Skeleton.d.ts +9 -3
- package/dist/components/atoms/Skeleton.es.js +33 -3
- package/dist/components/atoms/Skeleton.es.js.map +1 -1
- package/dist/components/atoms/Spinner.d.ts +15 -4
- package/dist/components/atoms/Spinner.es.js +86 -22
- package/dist/components/atoms/Spinner.es.js.map +1 -1
- package/dist/components/atoms/Switch.d.ts +19 -7
- package/dist/components/atoms/Switch.es.js +288 -50
- package/dist/components/atoms/Switch.es.js.map +1 -1
- package/dist/components/atoms/TabButton.d.ts +17 -3
- package/dist/components/atoms/TabButton.es.js +647 -25
- package/dist/components/atoms/TabButton.es.js.map +1 -1
- package/dist/components/atoms/TabPanel.es.js +1 -1
- package/dist/components/atoms/Tag.d.ts +43 -0
- package/dist/components/atoms/Tag.es.js +219 -0
- package/dist/components/atoms/Tag.es.js.map +1 -0
- package/dist/components/atoms/Tooltip.d.ts +36 -14
- package/dist/components/atoms/Tooltip.es.js +7 -114
- package/dist/components/atoms/Tooltip.es.js.map +1 -1
- package/dist/components/molecules/Alert.d.ts +1 -1
- package/dist/components/molecules/Alert.es.js +13 -9
- package/dist/components/molecules/Alert.es.js.map +1 -1
- package/dist/components/molecules/CopyField.d.ts +2 -2
- package/dist/components/molecules/CopyField.es.js +3 -4
- package/dist/components/molecules/CopyField.es.js.map +1 -1
- package/dist/components/molecules/CustomDrawer.d.ts +5 -4
- package/dist/components/molecules/CustomDrawer.es.js +141 -82
- package/dist/components/molecules/CustomDrawer.es.js.map +1 -1
- package/dist/components/molecules/Dialog.d.ts +16 -8
- package/dist/components/molecules/Dialog.es.js +33 -31
- package/dist/components/molecules/Dialog.es.js.map +1 -1
- package/dist/components/molecules/ImagesPreview.es.js +15 -11
- package/dist/components/molecules/ImagesPreview.es.js.map +1 -1
- package/dist/components/molecules/Input.d.ts +1 -1
- package/dist/components/molecules/Input.es.js +3 -5
- package/dist/components/molecules/Input.es.js.map +1 -1
- package/dist/components/molecules/Markdown/ExpandableMarkdown.d.ts +8 -8
- package/dist/components/molecules/Markdown/components.d.ts +12 -11
- package/dist/components/molecules/Markdown.es.js +26 -49
- package/dist/components/molecules/Markdown.es.js.map +1 -1
- package/dist/components/molecules/Notify.d.ts +30 -1
- package/dist/components/molecules/Notify.es.js +91 -36
- package/dist/components/molecules/Notify.es.js.map +1 -1
- package/dist/components/molecules/SimpleCodeEditor.es.js +32 -19
- package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -1
- package/dist/components/molecules/ToggleButton.d.ts +3 -2
- package/dist/components/molecules/ToggleButton.es.js +155 -57
- package/dist/components/molecules/ToggleButton.es.js.map +1 -1
- package/dist/components/molecules/agent-chat/UserMessage.es.js +2 -2
- package/dist/components/molecules/agent-chat/UserMessage.es.js.map +1 -1
- package/dist/components/molecules/agent-chat/UserMessageEdit.es.js +5 -5
- package/dist/components/molecules/agent-chat/UserMessageEdit.es.js.map +1 -1
- package/dist/components/molecules/agent-chat/index.d.ts +0 -6
- package/dist/components/molecules/agent-chat.es.js +76 -407
- package/dist/components/molecules/agent-chat.es.js.map +1 -1
- package/dist/components/molecules/monacoEditorCore/MonacoEditorCore.d.ts +0 -1
- package/dist/components/theme/colors.d.ts +17 -53
- package/dist/components/theme/colors.es.js +384 -180
- package/dist/components/theme/colors.es.js.map +1 -1
- package/dist/components/theme/theme.d.ts +14 -11
- package/dist/components/theme/theme.es.js +3 -64
- package/dist/components/theme/theme.es.js.map +1 -1
- package/dist/components/theme/useTheme.es.js +1 -4
- package/dist/components/theme/useTheme.es.js.map +1 -1
- package/dist/composite-CrCQWAKA.js +108 -0
- package/dist/composite-CrCQWAKA.js.map +1 -0
- package/dist/composite-DCpXNxz9.js +66 -0
- package/dist/composite-DCpXNxz9.js.map +1 -0
- package/dist/conversions-CbWPvHRE.js +14 -0
- package/dist/conversions-CbWPvHRE.js.map +1 -0
- package/dist/error-FX4R42W-.js +6 -0
- package/dist/error-FX4R42W-.js.map +1 -0
- package/dist/fonts.css +7 -0
- package/dist/hooks/useContainerDimensions.d.ts +1 -1
- package/dist/index-B806bfA-.js +257 -0
- package/dist/index-B806bfA-.js.map +1 -0
- package/dist/index-DSVg79g-.js +45 -0
- package/dist/index-DSVg79g-.js.map +1 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.es.js +58 -9
- package/dist/index.es.js.map +1 -1
- package/dist/inertValue-IJM5NA30.js +11 -0
- package/dist/inertValue-IJM5NA30.js.map +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/markdown.css +13 -14
- package/dist/new-components/atoms/Checkbox.d.ts +6 -0
- package/dist/new-components/atoms/Checkbox.es.js +423 -0
- package/dist/new-components/atoms/Checkbox.es.js.map +1 -0
- package/dist/new-components/atoms/Chip.d.ts +38 -0
- package/dist/new-components/atoms/Chip.es.js +269 -0
- package/dist/new-components/atoms/Chip.es.js.map +1 -0
- package/dist/new-components/atoms/Popover.d.ts +87 -0
- package/dist/new-components/atoms/Popover.es.js +21 -0
- package/dist/new-components/atoms/Popover.es.js.map +1 -0
- package/dist/new-components/atoms/Radio.d.ts +14 -0
- package/dist/new-components/atoms/Radio.es.js +536 -0
- package/dist/new-components/atoms/Radio.es.js.map +1 -0
- package/dist/new-components/atoms/SegmentedControl.d.ts +28 -0
- package/dist/new-components/atoms/SegmentedControl.es.js +326 -0
- package/dist/new-components/atoms/SegmentedControl.es.js.map +1 -0
- package/dist/new-components/atoms/Slider.d.ts +8 -0
- package/dist/new-components/atoms/Slider.es.js +1415 -0
- package/dist/new-components/atoms/Slider.es.js.map +1 -0
- package/dist/new-components/atoms/Toggletip.d.ts +43 -0
- package/dist/new-components/atoms/Toggletip.es.js +216 -0
- package/dist/new-components/atoms/Toggletip.es.js.map +1 -0
- package/dist/new-components/atoms/stories/ThemeComparison.d.ts +8 -0
- package/dist/shadowDom-Bq4g0Qeu.js +52 -0
- package/dist/shadowDom-Bq4g0Qeu.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tfy-YZ5zY9Jw.js +6 -0
- package/dist/tfy-YZ5zY9Jw.js.map +1 -0
- package/dist/theme.css +9 -154
- package/dist/tokens.css +1124 -0
- package/dist/useAnimationFrame-DwhymJoW.js +108 -0
- package/dist/useAnimationFrame-DwhymJoW.js.map +1 -0
- package/dist/useAriaLabelledBy-B6n92QBS.js +49 -0
- package/dist/useAriaLabelledBy-B6n92QBS.js.map +1 -0
- package/dist/useBaseUiId-Ch7ujXpo.js +281 -0
- package/dist/useBaseUiId-Ch7ujXpo.js.map +1 -0
- package/dist/useButton-PUBhT4Vo.js +235 -0
- package/dist/useButton-PUBhT4Vo.js.map +1 -0
- package/dist/useControlled-BSyYkg5C.js +65 -0
- package/dist/useControlled-BSyYkg5C.js.map +1 -0
- package/dist/useIsoLayoutEffect-e9VA-ICd.js +499 -0
- package/dist/useIsoLayoutEffect-e9VA-ICd.js.map +1 -0
- package/dist/useLabelableId-DCLzrdD-.js +241 -0
- package/dist/useLabelableId-DCLzrdD-.js.map +1 -0
- package/dist/useOpenInteractionType-DGWLoAqp.js +1086 -0
- package/dist/useOpenInteractionType-DGWLoAqp.js.map +1 -0
- package/dist/usePopupHandleStore-BdS-xYID.js +2372 -0
- package/dist/usePopupHandleStore-BdS-xYID.js.map +1 -0
- package/dist/useTimeout-BXf1hDIL.js +46 -0
- package/dist/useTimeout-BXf1hDIL.js.map +1 -0
- package/dist/useTransitionStatus-C9gg_XJ-.js +202 -0
- package/dist/useTransitionStatus-C9gg_XJ-.js.map +1 -0
- package/dist/useValueAsRef-BfFRcMg6.js +28 -0
- package/dist/useValueAsRef-BfFRcMg6.js.map +1 -0
- package/dist/utils/classNames.d.ts +3 -2
- package/dist/visuallyHidden-B6H2X3_Y.js +26 -0
- package/dist/visuallyHidden-B6H2X3_Y.js.map +1 -0
- package/dist/vite-env.d.ts +18 -0
- package/package.json +30 -22
- package/dist/Input-BvwIpntS.js.map +0 -1
- package/dist/Notification-BT4CZ69U.js +0 -39
- package/dist/Notification-BT4CZ69U.js.map +0 -1
- package/dist/RootFontSizeContext-7vgn7Y_k.js +0 -22
- package/dist/RootFontSizeContext-7vgn7Y_k.js.map +0 -1
- package/dist/classNames-Dy-RXSjS.js +0 -9
- package/dist/classNames-Dy-RXSjS.js.map +0 -1
- package/dist/components/molecules/DropdownMenu.d.ts +0 -18
- package/dist/components/molecules/DropdownMenu.es.js +0 -104
- package/dist/components/molecules/DropdownMenu.es.js.map +0 -1
- package/dist/components/molecules/ThumbsFeedback.d.ts +0 -13
- package/dist/components/molecules/ThumbsFeedback.es.js +0 -98
- package/dist/components/molecules/ThumbsFeedback.es.js.map +0 -1
- package/dist/components/molecules/agent-chat/SandboxToolCall.d.ts +0 -15
- package/dist/components/molecules/agent-chat/ToolCallCard.d.ts +0 -26
- package/dist/components/molecules/agent-chat/ToolCallContentBlock.d.ts +0 -17
- package/dist/components/theme/lightColorPlugin.d.ts +0 -1
- package/dist/components/theme/lightColorPlugin.es.js +0 -92
- package/dist/components/theme/lightColorPlugin.es.js.map +0 -1
- package/dist/tailwindPreset.d.ts +0 -144
- package/dist/tailwindPreset.es.js +0 -100
- package/dist/tailwindPreset.es.js.map +0 -1
|
@@ -0,0 +1,4096 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useLayoutEffect } from "react";
|
|
7
|
+
import { c as classNames } from "./classNames-B1XpQHle.js";
|
|
8
|
+
import { u as useTimeout, T as Timeout } from "./useTimeout-BXf1hDIL.js";
|
|
9
|
+
import { u as useIsoLayoutEffect, a as useStableCallback, e as useRefWithInit, f as formatErrorMessage, m as mergeProps, d as EMPTY_OBJECT, b as useRenderElement } from "./useIsoLayoutEffect-e9VA-ICd.js";
|
|
10
|
+
import { W as isMouseLikePointerType, I as mergeCleanups, Y as mac, O as webkit, J as createAttribute, E as useFloatingTree, Z as useFloatingParentNodeId, L as getNodeChildren, R as ReactStore, e as popupStoreSelectors, _ as applyPopupOpenChange, g as createInitialPopupStoreState, P as PopupTriggerMap, m as fastComponent, h as usePopupRootStore, j as useImplicitActiveTrigger, k as useOpenStateTransitions, l as PopupHandleAttachment, u as useDismiss, d as usePopupInteractionProps, n as fastComponentRef, o as usePopupHandleStore, q as useTriggerDataForwarding, t as triggerOpenStateMapping, $ as useFloatingPortalNode, a0 as DISABLED_TRANSITIONS_STYLE, a as popupStateMapping, D as POPUP_COLLISION_AVOIDANCE, F as FOCUSABLE_POPUP_PROPS, p as popupTransitionStateMapping } from "./usePopupHandleStore-BdS-xYID.js";
|
|
11
|
+
import { c as createChangeEventDetails, n as none, g as getWindow, p as isElement, D as triggerFocus, j as isHTMLElement, e as triggerPress, h as escapeKey, t as triggerHover, F as getOverflowAncestors, G as getDocumentElement, w as getComputedStyle$1, H as isTopLayer, A as getParentNode, z as isLastTraversableNode, I as isTableElement, J as isContainingBlock, K as getContainingBlock, s as getNodeName, E as isOverflowElement, L as getNodeScroll, M as isWebKit, N as getFrameElement, d as disabled, b as imperativeAction, u as useBaseUiId } from "./useBaseUiId-Ch7ujXpo.js";
|
|
12
|
+
import { a as addEventListener, u as useValueAsRef } from "./useValueAsRef-BfFRcMg6.js";
|
|
13
|
+
import { g as getTarget, c as contains, a as activeElement, b as closest } from "./shadowDom-Bq4g0Qeu.js";
|
|
14
|
+
import { o as ownerDocument, f as isTargetInsideEnabledTrigger, e as isTypeableElement, m as matchesFocusVisible, h as isInteractiveElement, t as triggerDisabled } from "./index-B806bfA-.js";
|
|
15
|
+
import { a as useOnMount } from "./useAnimationFrame-DwhymJoW.js";
|
|
16
|
+
import * as ReactDOM from "react-dom";
|
|
17
|
+
import { u as useDirection } from "./DirectionContext-Pb9yafF5.js";
|
|
18
|
+
import { a as useOpenChangeComplete } from "./useTransitionStatus-C9gg_XJ-.js";
|
|
19
|
+
function resolveValue(value, pointerType) {
|
|
20
|
+
if (pointerType != null && !isMouseLikePointerType(pointerType)) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === "function") {
|
|
24
|
+
return value();
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function getDelay(value, prop, pointerType) {
|
|
29
|
+
const result = resolveValue(value, pointerType);
|
|
30
|
+
if (typeof result === "number") {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
return result == null ? void 0 : result[prop];
|
|
34
|
+
}
|
|
35
|
+
function getRestMs(value) {
|
|
36
|
+
if (typeof value === "function") {
|
|
37
|
+
return value();
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function isClickLikeOpenEvent(openEventType, interactedInside) {
|
|
42
|
+
return interactedInside || openEventType === "click" || openEventType === "mousedown";
|
|
43
|
+
}
|
|
44
|
+
function isHoverOpenEvent(openEventType) {
|
|
45
|
+
return (openEventType == null ? void 0 : openEventType.includes("mouse")) && openEventType !== "mousedown";
|
|
46
|
+
}
|
|
47
|
+
const FloatingDelayGroupContext = /* @__PURE__ */ React.createContext({
|
|
48
|
+
hasProvider: false,
|
|
49
|
+
timeoutMs: 0,
|
|
50
|
+
delayRef: {
|
|
51
|
+
current: 0
|
|
52
|
+
},
|
|
53
|
+
initialDelayRef: {
|
|
54
|
+
current: 0
|
|
55
|
+
},
|
|
56
|
+
timeout: new Timeout(),
|
|
57
|
+
currentIdRef: {
|
|
58
|
+
current: null
|
|
59
|
+
},
|
|
60
|
+
currentContextRef: {
|
|
61
|
+
current: null
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (process.env.NODE_ENV !== "production") FloatingDelayGroupContext.displayName = "FloatingDelayGroupContext";
|
|
65
|
+
function resetDelayRef(delayRef, initialDelayRef) {
|
|
66
|
+
delayRef.current = initialDelayRef.current;
|
|
67
|
+
}
|
|
68
|
+
function FloatingDelayGroup(props) {
|
|
69
|
+
const {
|
|
70
|
+
children,
|
|
71
|
+
delay,
|
|
72
|
+
timeoutMs = 0
|
|
73
|
+
} = props;
|
|
74
|
+
const delayRef = React.useRef(delay);
|
|
75
|
+
const initialDelayRef = React.useRef(delay);
|
|
76
|
+
const currentIdRef = React.useRef(null);
|
|
77
|
+
const currentContextRef = React.useRef(null);
|
|
78
|
+
const timeout = useTimeout();
|
|
79
|
+
useIsoLayoutEffect(() => {
|
|
80
|
+
initialDelayRef.current = delay;
|
|
81
|
+
if (!currentIdRef.current) {
|
|
82
|
+
delayRef.current = delay;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
delayRef.current = {
|
|
86
|
+
open: getDelay(delayRef.current, "open"),
|
|
87
|
+
close: getDelay(delay, "close")
|
|
88
|
+
};
|
|
89
|
+
}, [delay, currentIdRef, delayRef, initialDelayRef]);
|
|
90
|
+
return /* @__PURE__ */ jsx(FloatingDelayGroupContext.Provider, {
|
|
91
|
+
value: React.useMemo(() => ({
|
|
92
|
+
hasProvider: true,
|
|
93
|
+
delayRef,
|
|
94
|
+
initialDelayRef,
|
|
95
|
+
currentIdRef,
|
|
96
|
+
timeoutMs,
|
|
97
|
+
currentContextRef,
|
|
98
|
+
timeout
|
|
99
|
+
}), [timeoutMs, timeout]),
|
|
100
|
+
children
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function useDelayGroup(store, options = {
|
|
104
|
+
open: false
|
|
105
|
+
}) {
|
|
106
|
+
const {
|
|
107
|
+
open
|
|
108
|
+
} = options;
|
|
109
|
+
const floatingId = store.useState("floatingId");
|
|
110
|
+
const groupContext = React.useContext(FloatingDelayGroupContext);
|
|
111
|
+
const {
|
|
112
|
+
currentIdRef,
|
|
113
|
+
delayRef,
|
|
114
|
+
timeoutMs,
|
|
115
|
+
initialDelayRef,
|
|
116
|
+
currentContextRef,
|
|
117
|
+
hasProvider,
|
|
118
|
+
timeout
|
|
119
|
+
} = groupContext;
|
|
120
|
+
const [isInstantPhase, setIsInstantPhase] = React.useState(false);
|
|
121
|
+
const openRef = React.useRef(open);
|
|
122
|
+
useIsoLayoutEffect(() => {
|
|
123
|
+
openRef.current = open;
|
|
124
|
+
}, [open]);
|
|
125
|
+
useIsoLayoutEffect(() => {
|
|
126
|
+
function unset() {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = currentContextRef.current) == null ? void 0 : _a.setIsInstantPhase(false);
|
|
129
|
+
currentIdRef.current = null;
|
|
130
|
+
currentContextRef.current = null;
|
|
131
|
+
delayRef.current = initialDelayRef.current;
|
|
132
|
+
timeout.clear();
|
|
133
|
+
}
|
|
134
|
+
if (!currentIdRef.current) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
if (!open && currentIdRef.current === floatingId) {
|
|
138
|
+
setIsInstantPhase(false);
|
|
139
|
+
if (timeoutMs) {
|
|
140
|
+
const closingId = floatingId;
|
|
141
|
+
timeout.start(timeoutMs, () => {
|
|
142
|
+
if (store.select("open") || currentIdRef.current && currentIdRef.current !== closingId) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
unset();
|
|
146
|
+
});
|
|
147
|
+
return () => {
|
|
148
|
+
if (openRef.current || currentIdRef.current !== closingId) {
|
|
149
|
+
timeout.clear();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
unset();
|
|
154
|
+
}
|
|
155
|
+
return void 0;
|
|
156
|
+
}, [open, floatingId, currentIdRef, delayRef, timeoutMs, initialDelayRef, currentContextRef, timeout, store]);
|
|
157
|
+
useIsoLayoutEffect(() => {
|
|
158
|
+
if (!open) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const prevContext = currentContextRef.current;
|
|
162
|
+
const prevId = currentIdRef.current;
|
|
163
|
+
timeout.clear();
|
|
164
|
+
currentContextRef.current = {
|
|
165
|
+
onOpenChange: store.setOpen,
|
|
166
|
+
setIsInstantPhase
|
|
167
|
+
};
|
|
168
|
+
currentIdRef.current = floatingId;
|
|
169
|
+
delayRef.current = {
|
|
170
|
+
open: 0,
|
|
171
|
+
close: getDelay(initialDelayRef.current, "close")
|
|
172
|
+
};
|
|
173
|
+
if (prevId !== null && prevId !== floatingId) {
|
|
174
|
+
setIsInstantPhase(true);
|
|
175
|
+
prevContext == null ? void 0 : prevContext.setIsInstantPhase(true);
|
|
176
|
+
prevContext == null ? void 0 : prevContext.onOpenChange(false, createChangeEventDetails(none));
|
|
177
|
+
} else {
|
|
178
|
+
setIsInstantPhase(false);
|
|
179
|
+
prevContext == null ? void 0 : prevContext.setIsInstantPhase(false);
|
|
180
|
+
}
|
|
181
|
+
}, [open, floatingId, store, currentIdRef, delayRef, initialDelayRef, currentContextRef, timeout]);
|
|
182
|
+
useIsoLayoutEffect(() => {
|
|
183
|
+
return () => {
|
|
184
|
+
if (currentIdRef.current === floatingId) {
|
|
185
|
+
currentContextRef.current = null;
|
|
186
|
+
if (!openRef.current) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
currentIdRef.current = null;
|
|
190
|
+
resetDelayRef(delayRef, initialDelayRef);
|
|
191
|
+
timeout.clear();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}, [currentContextRef, currentIdRef, delayRef, floatingId, initialDelayRef, timeout]);
|
|
195
|
+
return React.useMemo(() => ({
|
|
196
|
+
activeIdRef: currentIdRef,
|
|
197
|
+
hasProvider,
|
|
198
|
+
delayRef,
|
|
199
|
+
isInstantPhase
|
|
200
|
+
}), [currentIdRef, hasProvider, delayRef, isInstantPhase]);
|
|
201
|
+
}
|
|
202
|
+
const min = Math.min;
|
|
203
|
+
const max = Math.max;
|
|
204
|
+
const round = Math.round;
|
|
205
|
+
const floor = Math.floor;
|
|
206
|
+
const createCoords = (v) => ({
|
|
207
|
+
x: v,
|
|
208
|
+
y: v
|
|
209
|
+
});
|
|
210
|
+
const oppositeSideMap = {
|
|
211
|
+
left: "right",
|
|
212
|
+
right: "left",
|
|
213
|
+
bottom: "top",
|
|
214
|
+
top: "bottom"
|
|
215
|
+
};
|
|
216
|
+
function clamp(start, value, end) {
|
|
217
|
+
return max(start, min(value, end));
|
|
218
|
+
}
|
|
219
|
+
function evaluate(value, param) {
|
|
220
|
+
return typeof value === "function" ? value(param) : value;
|
|
221
|
+
}
|
|
222
|
+
function getSide(placement) {
|
|
223
|
+
return placement.split("-")[0];
|
|
224
|
+
}
|
|
225
|
+
function getAlignment(placement) {
|
|
226
|
+
return placement.split("-")[1];
|
|
227
|
+
}
|
|
228
|
+
function getOppositeAxis(axis) {
|
|
229
|
+
return axis === "x" ? "y" : "x";
|
|
230
|
+
}
|
|
231
|
+
function getAxisLength(axis) {
|
|
232
|
+
return axis === "y" ? "height" : "width";
|
|
233
|
+
}
|
|
234
|
+
function getSideAxis(placement) {
|
|
235
|
+
const firstChar = placement[0];
|
|
236
|
+
return firstChar === "t" || firstChar === "b" ? "y" : "x";
|
|
237
|
+
}
|
|
238
|
+
function getAlignmentAxis(placement) {
|
|
239
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
240
|
+
}
|
|
241
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
242
|
+
if (rtl === void 0) {
|
|
243
|
+
rtl = false;
|
|
244
|
+
}
|
|
245
|
+
const alignment = getAlignment(placement);
|
|
246
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
247
|
+
const length = getAxisLength(alignmentAxis);
|
|
248
|
+
let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
|
|
249
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
250
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
251
|
+
}
|
|
252
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
253
|
+
}
|
|
254
|
+
function getExpandedPlacements(placement) {
|
|
255
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
256
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
257
|
+
}
|
|
258
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
259
|
+
return placement.includes("start") ? placement.replace("start", "end") : placement.replace("end", "start");
|
|
260
|
+
}
|
|
261
|
+
const lrPlacement = ["left", "right"];
|
|
262
|
+
const rlPlacement = ["right", "left"];
|
|
263
|
+
const tbPlacement = ["top", "bottom"];
|
|
264
|
+
const btPlacement = ["bottom", "top"];
|
|
265
|
+
function getSideList(side, isStart, rtl) {
|
|
266
|
+
switch (side) {
|
|
267
|
+
case "top":
|
|
268
|
+
case "bottom":
|
|
269
|
+
if (rtl) return isStart ? rlPlacement : lrPlacement;
|
|
270
|
+
return isStart ? lrPlacement : rlPlacement;
|
|
271
|
+
case "left":
|
|
272
|
+
case "right":
|
|
273
|
+
return isStart ? tbPlacement : btPlacement;
|
|
274
|
+
default:
|
|
275
|
+
return [];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
279
|
+
const alignment = getAlignment(placement);
|
|
280
|
+
let list = getSideList(getSide(placement), direction === "start", rtl);
|
|
281
|
+
if (alignment) {
|
|
282
|
+
list = list.map((side) => side + "-" + alignment);
|
|
283
|
+
if (flipAlignment) {
|
|
284
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return list;
|
|
288
|
+
}
|
|
289
|
+
function getOppositePlacement(placement) {
|
|
290
|
+
const side = getSide(placement);
|
|
291
|
+
return oppositeSideMap[side] + placement.slice(side.length);
|
|
292
|
+
}
|
|
293
|
+
function expandPaddingObject(padding) {
|
|
294
|
+
var _padding$top, _padding$right, _padding$bottom, _padding$left;
|
|
295
|
+
return {
|
|
296
|
+
top: (_padding$top = padding.top) != null ? _padding$top : 0,
|
|
297
|
+
right: (_padding$right = padding.right) != null ? _padding$right : 0,
|
|
298
|
+
bottom: (_padding$bottom = padding.bottom) != null ? _padding$bottom : 0,
|
|
299
|
+
left: (_padding$left = padding.left) != null ? _padding$left : 0
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function getPaddingObject(padding) {
|
|
303
|
+
return typeof padding !== "number" ? expandPaddingObject(padding) : {
|
|
304
|
+
top: padding,
|
|
305
|
+
right: padding,
|
|
306
|
+
bottom: padding,
|
|
307
|
+
left: padding
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function rectToClientRect(rect) {
|
|
311
|
+
const {
|
|
312
|
+
x,
|
|
313
|
+
y,
|
|
314
|
+
width,
|
|
315
|
+
height
|
|
316
|
+
} = rect;
|
|
317
|
+
return {
|
|
318
|
+
width,
|
|
319
|
+
height,
|
|
320
|
+
top: y,
|
|
321
|
+
left: x,
|
|
322
|
+
right: x + width,
|
|
323
|
+
bottom: y + height,
|
|
324
|
+
x,
|
|
325
|
+
y
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function createVirtualElement(domElement, data) {
|
|
329
|
+
let offsetX = null;
|
|
330
|
+
let offsetY = null;
|
|
331
|
+
let isAutoUpdateEvent = false;
|
|
332
|
+
return {
|
|
333
|
+
contextElement: domElement || void 0,
|
|
334
|
+
getBoundingClientRect() {
|
|
335
|
+
var _a;
|
|
336
|
+
const domRect = (domElement == null ? void 0 : domElement.getBoundingClientRect()) || {
|
|
337
|
+
width: 0,
|
|
338
|
+
height: 0,
|
|
339
|
+
x: 0,
|
|
340
|
+
y: 0
|
|
341
|
+
};
|
|
342
|
+
const isXAxis = data.axis === "x" || data.axis === "both";
|
|
343
|
+
const isYAxis = data.axis === "y" || data.axis === "both";
|
|
344
|
+
const canTrackCursorOnAutoUpdate = ["mouseenter", "mousemove"].includes(((_a = data.dataRef.current.openEvent) == null ? void 0 : _a.type) || "") && data.pointerType !== "touch";
|
|
345
|
+
const width = data.axis === "y" ? domRect.width : 0;
|
|
346
|
+
const height = data.axis === "x" ? domRect.height : 0;
|
|
347
|
+
let x = domRect.x;
|
|
348
|
+
let y = domRect.y;
|
|
349
|
+
if (offsetX == null && data.x && isXAxis) {
|
|
350
|
+
offsetX = domRect.x - data.x;
|
|
351
|
+
}
|
|
352
|
+
if (offsetY == null && data.y && isYAxis) {
|
|
353
|
+
offsetY = domRect.y - data.y;
|
|
354
|
+
}
|
|
355
|
+
x -= offsetX || 0;
|
|
356
|
+
y -= offsetY || 0;
|
|
357
|
+
if (!isAutoUpdateEvent || canTrackCursorOnAutoUpdate) {
|
|
358
|
+
x = isXAxis && data.x != null ? data.x : x;
|
|
359
|
+
y = isYAxis && data.y != null ? data.y : y;
|
|
360
|
+
}
|
|
361
|
+
isAutoUpdateEvent = true;
|
|
362
|
+
return {
|
|
363
|
+
width,
|
|
364
|
+
height,
|
|
365
|
+
x,
|
|
366
|
+
y,
|
|
367
|
+
top: y,
|
|
368
|
+
right: x + width,
|
|
369
|
+
bottom: y + height,
|
|
370
|
+
left: x
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function isMouseBasedEvent(event) {
|
|
376
|
+
return event != null && event.clientX != null;
|
|
377
|
+
}
|
|
378
|
+
function useClientPoint(store, props = {}) {
|
|
379
|
+
const {
|
|
380
|
+
enabled = true,
|
|
381
|
+
axis = "both"
|
|
382
|
+
} = props;
|
|
383
|
+
const open = store.useState("open");
|
|
384
|
+
const floating = store.useState("floatingElement");
|
|
385
|
+
const domReference = store.useState("domReferenceElement");
|
|
386
|
+
const dataRef = store.context.dataRef;
|
|
387
|
+
const initialRef = React.useRef(false);
|
|
388
|
+
const cleanupListenerRef = React.useRef(null);
|
|
389
|
+
const [pointerType, setPointerType] = React.useState();
|
|
390
|
+
const [reactive, setReactive] = React.useState([]);
|
|
391
|
+
const resetReference = useStableCallback((reference2) => {
|
|
392
|
+
store.set("positionReference", reference2);
|
|
393
|
+
});
|
|
394
|
+
const setReference = useStableCallback((newX, newY, referenceElement) => {
|
|
395
|
+
if (initialRef.current) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (dataRef.current.openEvent && !isMouseBasedEvent(dataRef.current.openEvent)) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
store.set("positionReference", createVirtualElement(referenceElement ?? domReference, {
|
|
402
|
+
x: newX,
|
|
403
|
+
y: newY,
|
|
404
|
+
axis,
|
|
405
|
+
dataRef,
|
|
406
|
+
pointerType
|
|
407
|
+
}));
|
|
408
|
+
});
|
|
409
|
+
const handleReferenceEnterOrMove = useStableCallback((event) => {
|
|
410
|
+
if (!open) {
|
|
411
|
+
setReference(event.clientX, event.clientY, event.currentTarget);
|
|
412
|
+
} else if (!cleanupListenerRef.current) {
|
|
413
|
+
setReference(event.clientX, event.clientY, event.currentTarget);
|
|
414
|
+
setReactive([]);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
const openCheck = isMouseLikePointerType(pointerType) ? floating : open;
|
|
418
|
+
React.useEffect(() => {
|
|
419
|
+
if (!enabled) {
|
|
420
|
+
resetReference(domReference);
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
if (!openCheck) {
|
|
424
|
+
return void 0;
|
|
425
|
+
}
|
|
426
|
+
function cleanupListener() {
|
|
427
|
+
var _a;
|
|
428
|
+
(_a = cleanupListenerRef.current) == null ? void 0 : _a.call(cleanupListenerRef);
|
|
429
|
+
cleanupListenerRef.current = null;
|
|
430
|
+
}
|
|
431
|
+
const win = getWindow(floating);
|
|
432
|
+
function handleMouseMove(event) {
|
|
433
|
+
const target = getTarget(event);
|
|
434
|
+
if (!contains(floating, target)) {
|
|
435
|
+
setReference(event.clientX, event.clientY);
|
|
436
|
+
} else {
|
|
437
|
+
cleanupListener();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (!dataRef.current.openEvent || isMouseBasedEvent(dataRef.current.openEvent)) {
|
|
441
|
+
cleanupListenerRef.current = addEventListener(win, "mousemove", handleMouseMove);
|
|
442
|
+
} else {
|
|
443
|
+
resetReference(domReference);
|
|
444
|
+
}
|
|
445
|
+
return cleanupListener;
|
|
446
|
+
}, [openCheck, enabled, floating, dataRef, domReference, store, setReference, resetReference, reactive]);
|
|
447
|
+
React.useEffect(() => () => {
|
|
448
|
+
store.set("positionReference", null);
|
|
449
|
+
}, [store]);
|
|
450
|
+
React.useEffect(() => {
|
|
451
|
+
if (enabled && !floating) {
|
|
452
|
+
initialRef.current = false;
|
|
453
|
+
}
|
|
454
|
+
}, [enabled, floating]);
|
|
455
|
+
React.useEffect(() => {
|
|
456
|
+
if (!enabled && open) {
|
|
457
|
+
initialRef.current = true;
|
|
458
|
+
}
|
|
459
|
+
}, [enabled, open]);
|
|
460
|
+
const reference = React.useMemo(() => {
|
|
461
|
+
function setPointerTypeRef(event) {
|
|
462
|
+
setPointerType(event.pointerType);
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
onPointerDown: setPointerTypeRef,
|
|
466
|
+
onPointerEnter: setPointerTypeRef,
|
|
467
|
+
onMouseMove: handleReferenceEnterOrMove,
|
|
468
|
+
onMouseEnter: handleReferenceEnterOrMove
|
|
469
|
+
};
|
|
470
|
+
}, [handleReferenceEnterOrMove]);
|
|
471
|
+
return React.useMemo(() => enabled ? {
|
|
472
|
+
reference,
|
|
473
|
+
trigger: reference
|
|
474
|
+
} : {}, [enabled, reference]);
|
|
475
|
+
}
|
|
476
|
+
const isMacSafari = mac && webkit;
|
|
477
|
+
function useFocus(store, props = {}) {
|
|
478
|
+
const {
|
|
479
|
+
enabled = true,
|
|
480
|
+
delay
|
|
481
|
+
} = props;
|
|
482
|
+
const {
|
|
483
|
+
events,
|
|
484
|
+
dataRef
|
|
485
|
+
} = store.context;
|
|
486
|
+
const blockFocusRef = React.useRef(false);
|
|
487
|
+
const blockedReferenceRef = React.useRef(null);
|
|
488
|
+
const keyboardModalityRef = React.useRef(true);
|
|
489
|
+
const timeout = useTimeout();
|
|
490
|
+
React.useEffect(() => {
|
|
491
|
+
const domReference = store.select("domReferenceElement");
|
|
492
|
+
if (!enabled) {
|
|
493
|
+
return void 0;
|
|
494
|
+
}
|
|
495
|
+
const win = getWindow(domReference);
|
|
496
|
+
function onBlur() {
|
|
497
|
+
const currentDomReference = store.select("domReferenceElement");
|
|
498
|
+
if (!store.select("open") && isHTMLElement(currentDomReference) && currentDomReference === activeElement(ownerDocument(currentDomReference))) {
|
|
499
|
+
blockFocusRef.current = true;
|
|
500
|
+
blockedReferenceRef.current = currentDomReference;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function onKeyDown() {
|
|
504
|
+
keyboardModalityRef.current = true;
|
|
505
|
+
}
|
|
506
|
+
function onPointerDown() {
|
|
507
|
+
keyboardModalityRef.current = false;
|
|
508
|
+
}
|
|
509
|
+
return mergeCleanups(addEventListener(win, "blur", onBlur), isMacSafari && addEventListener(win, "keydown", onKeyDown, true), isMacSafari && addEventListener(win, "pointerdown", onPointerDown, true));
|
|
510
|
+
}, [store, enabled]);
|
|
511
|
+
React.useEffect(() => {
|
|
512
|
+
if (!enabled) {
|
|
513
|
+
return void 0;
|
|
514
|
+
}
|
|
515
|
+
function onOpenChangeLocal(details) {
|
|
516
|
+
if (details.reason === triggerPress || details.reason === escapeKey) {
|
|
517
|
+
const referenceElement = store.select("domReferenceElement");
|
|
518
|
+
if (isElement(referenceElement)) {
|
|
519
|
+
blockedReferenceRef.current = referenceElement;
|
|
520
|
+
blockFocusRef.current = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
events.on("openchange", onOpenChangeLocal);
|
|
525
|
+
return () => {
|
|
526
|
+
events.off("openchange", onOpenChangeLocal);
|
|
527
|
+
};
|
|
528
|
+
}, [events, enabled, store]);
|
|
529
|
+
const reference = React.useMemo(() => {
|
|
530
|
+
function resetBlockedFocus() {
|
|
531
|
+
blockFocusRef.current = false;
|
|
532
|
+
blockedReferenceRef.current = null;
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
onMouseLeave() {
|
|
536
|
+
resetBlockedFocus();
|
|
537
|
+
},
|
|
538
|
+
onFocus(event) {
|
|
539
|
+
const focusTarget = event.currentTarget;
|
|
540
|
+
if (blockFocusRef.current) {
|
|
541
|
+
if (blockedReferenceRef.current === focusTarget) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
resetBlockedFocus();
|
|
545
|
+
}
|
|
546
|
+
const target = getTarget(event.nativeEvent);
|
|
547
|
+
if (isElement(target)) {
|
|
548
|
+
if (isMacSafari && !event.relatedTarget) {
|
|
549
|
+
if (!keyboardModalityRef.current && !isTypeableElement(target)) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
} else if (!matchesFocusVisible(target)) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const movedFromOtherEnabledTrigger = isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements);
|
|
557
|
+
const {
|
|
558
|
+
nativeEvent,
|
|
559
|
+
currentTarget
|
|
560
|
+
} = event;
|
|
561
|
+
if (store.select("open") && movedFromOtherEnabledTrigger || !delay) {
|
|
562
|
+
store.setOpen(true, createChangeEventDetails(triggerFocus, nativeEvent, currentTarget));
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
timeout.start(delay, () => {
|
|
566
|
+
if (blockFocusRef.current) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
store.setOpen(true, createChangeEventDetails(triggerFocus, nativeEvent, currentTarget));
|
|
570
|
+
});
|
|
571
|
+
},
|
|
572
|
+
onBlur(event) {
|
|
573
|
+
resetBlockedFocus();
|
|
574
|
+
const relatedTarget = event.relatedTarget;
|
|
575
|
+
const nativeEvent = event.nativeEvent;
|
|
576
|
+
const movedToFocusGuard = isElement(relatedTarget) && relatedTarget.hasAttribute(createAttribute("focus-guard")) && relatedTarget.getAttribute("data-type") === "outside";
|
|
577
|
+
timeout.start(0, () => {
|
|
578
|
+
var _a;
|
|
579
|
+
const domReference = store.select("domReferenceElement");
|
|
580
|
+
const activeEl = activeElement(ownerDocument(domReference));
|
|
581
|
+
if (!relatedTarget && activeEl === domReference) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (contains((_a = dataRef.current.floatingContext) == null ? void 0 : _a.refs.floating.current, activeEl) || contains(domReference, activeEl) || movedToFocusGuard) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const nextFocusedElement = relatedTarget ?? activeEl;
|
|
588
|
+
if (isTargetInsideEnabledTrigger(nextFocusedElement, store.context.triggerElements)) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
store.setOpen(false, createChangeEventDetails(triggerFocus, nativeEvent));
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}, [dataRef, delay, store, timeout]);
|
|
596
|
+
return React.useMemo(() => enabled ? {
|
|
597
|
+
reference,
|
|
598
|
+
trigger: reference
|
|
599
|
+
} : {}, [enabled, reference]);
|
|
600
|
+
}
|
|
601
|
+
class HoverInteraction {
|
|
602
|
+
constructor() {
|
|
603
|
+
__publicField(this, "pointerType");
|
|
604
|
+
__publicField(this, "interactedInside", false);
|
|
605
|
+
__publicField(this, "handler");
|
|
606
|
+
__publicField(this, "blockMouseMove", true);
|
|
607
|
+
__publicField(this, "performedPointerEventsMutation", false);
|
|
608
|
+
__publicField(this, "pointerEventsScopeElement", null);
|
|
609
|
+
__publicField(this, "pointerEventsReferenceElement", null);
|
|
610
|
+
__publicField(this, "pointerEventsFloatingElement", null);
|
|
611
|
+
__publicField(this, "restTimeoutPending", false);
|
|
612
|
+
__publicField(this, "openChangeTimeout", new Timeout());
|
|
613
|
+
__publicField(this, "restTimeout", new Timeout());
|
|
614
|
+
__publicField(this, "handleCloseOptions");
|
|
615
|
+
__publicField(this, "dispose", () => {
|
|
616
|
+
this.openChangeTimeout.clear();
|
|
617
|
+
this.restTimeout.clear();
|
|
618
|
+
});
|
|
619
|
+
__publicField(this, "disposeEffect", () => {
|
|
620
|
+
return this.dispose;
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
static create() {
|
|
624
|
+
return new HoverInteraction();
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const pointerEventsMutationOwnerByScopeElement = /* @__PURE__ */ new WeakMap();
|
|
628
|
+
function clearSafePolygonPointerEventsMutation(instance) {
|
|
629
|
+
var _a, _b, _c;
|
|
630
|
+
if (!instance.performedPointerEventsMutation) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const scopeElement = instance.pointerEventsScopeElement;
|
|
634
|
+
if (scopeElement && pointerEventsMutationOwnerByScopeElement.get(scopeElement) === instance) {
|
|
635
|
+
(_a = instance.pointerEventsScopeElement) == null ? void 0 : _a.style.removeProperty("pointer-events");
|
|
636
|
+
(_b = instance.pointerEventsReferenceElement) == null ? void 0 : _b.style.removeProperty("pointer-events");
|
|
637
|
+
(_c = instance.pointerEventsFloatingElement) == null ? void 0 : _c.style.removeProperty("pointer-events");
|
|
638
|
+
pointerEventsMutationOwnerByScopeElement.delete(scopeElement);
|
|
639
|
+
}
|
|
640
|
+
instance.performedPointerEventsMutation = false;
|
|
641
|
+
instance.pointerEventsScopeElement = null;
|
|
642
|
+
instance.pointerEventsReferenceElement = null;
|
|
643
|
+
instance.pointerEventsFloatingElement = null;
|
|
644
|
+
}
|
|
645
|
+
function applySafePolygonPointerEventsMutation(instance, options) {
|
|
646
|
+
const {
|
|
647
|
+
scopeElement,
|
|
648
|
+
referenceElement,
|
|
649
|
+
floatingElement
|
|
650
|
+
} = options;
|
|
651
|
+
const existingOwner = pointerEventsMutationOwnerByScopeElement.get(scopeElement);
|
|
652
|
+
if (existingOwner && existingOwner !== instance) {
|
|
653
|
+
clearSafePolygonPointerEventsMutation(existingOwner);
|
|
654
|
+
}
|
|
655
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
656
|
+
instance.performedPointerEventsMutation = true;
|
|
657
|
+
instance.pointerEventsScopeElement = scopeElement;
|
|
658
|
+
instance.pointerEventsReferenceElement = referenceElement;
|
|
659
|
+
instance.pointerEventsFloatingElement = floatingElement;
|
|
660
|
+
pointerEventsMutationOwnerByScopeElement.set(scopeElement, instance);
|
|
661
|
+
scopeElement.style.pointerEvents = "none";
|
|
662
|
+
referenceElement.style.pointerEvents = "auto";
|
|
663
|
+
floatingElement.style.pointerEvents = "auto";
|
|
664
|
+
}
|
|
665
|
+
function useHoverInteractionSharedState(store) {
|
|
666
|
+
const data = store.context.dataRef.current;
|
|
667
|
+
const instance = useRefWithInit(() => data.hoverInteractionState ?? HoverInteraction.create()).current;
|
|
668
|
+
if (!data.hoverInteractionState) {
|
|
669
|
+
data.hoverInteractionState = instance;
|
|
670
|
+
}
|
|
671
|
+
useOnMount(data.hoverInteractionState.disposeEffect);
|
|
672
|
+
return data.hoverInteractionState;
|
|
673
|
+
}
|
|
674
|
+
function useHoverFloatingInteraction(store, parameters = {}) {
|
|
675
|
+
const {
|
|
676
|
+
enabled = true,
|
|
677
|
+
closeDelay: closeDelayProp = 0,
|
|
678
|
+
nodeId: nodeIdProp
|
|
679
|
+
} = parameters;
|
|
680
|
+
const open = store.useState("open");
|
|
681
|
+
const floatingElement = store.useState("floatingElement");
|
|
682
|
+
const domReferenceElement = store.useState("domReferenceElement");
|
|
683
|
+
const {
|
|
684
|
+
dataRef
|
|
685
|
+
} = store.context;
|
|
686
|
+
const tree = useFloatingTree();
|
|
687
|
+
const parentId = useFloatingParentNodeId();
|
|
688
|
+
const instance = useHoverInteractionSharedState(store);
|
|
689
|
+
const childClosedTimeout = useTimeout();
|
|
690
|
+
const isClickLikeOpenEvent$1 = useStableCallback(() => {
|
|
691
|
+
var _a;
|
|
692
|
+
return isClickLikeOpenEvent((_a = dataRef.current.openEvent) == null ? void 0 : _a.type, instance.interactedInside);
|
|
693
|
+
});
|
|
694
|
+
const isHoverOpen = useStableCallback(() => {
|
|
695
|
+
var _a;
|
|
696
|
+
return isHoverOpenEvent((_a = dataRef.current.openEvent) == null ? void 0 : _a.type);
|
|
697
|
+
});
|
|
698
|
+
const clearPointerEvents = useStableCallback(() => {
|
|
699
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
700
|
+
});
|
|
701
|
+
useIsoLayoutEffect(() => {
|
|
702
|
+
if (!open) {
|
|
703
|
+
instance.pointerType = void 0;
|
|
704
|
+
instance.restTimeoutPending = false;
|
|
705
|
+
instance.interactedInside = false;
|
|
706
|
+
clearPointerEvents();
|
|
707
|
+
}
|
|
708
|
+
}, [open, instance, clearPointerEvents]);
|
|
709
|
+
React.useEffect(() => {
|
|
710
|
+
return clearPointerEvents;
|
|
711
|
+
}, [clearPointerEvents]);
|
|
712
|
+
useIsoLayoutEffect(() => {
|
|
713
|
+
var _a, _b, _c, _d, _e;
|
|
714
|
+
if (!enabled) {
|
|
715
|
+
return void 0;
|
|
716
|
+
}
|
|
717
|
+
if (open && ((_a = instance.handleCloseOptions) == null ? void 0 : _a.blockPointerEvents) && isHoverOpen() && isElement(domReferenceElement) && floatingElement) {
|
|
718
|
+
const ref = domReferenceElement;
|
|
719
|
+
const floatingEl = floatingElement;
|
|
720
|
+
const doc = ownerDocument(floatingElement);
|
|
721
|
+
const parentFloating = (_c = (_b = tree == null ? void 0 : tree.nodesRef.current.find((node) => node.id === parentId)) == null ? void 0 : _b.context) == null ? void 0 : _c.elements.floating;
|
|
722
|
+
if (parentFloating) {
|
|
723
|
+
parentFloating.style.pointerEvents = "";
|
|
724
|
+
}
|
|
725
|
+
const cachedScopeElement = instance.pointerEventsScopeElement !== floatingEl ? instance.pointerEventsScopeElement : null;
|
|
726
|
+
const parentScopeElement = parentFloating !== floatingEl ? parentFloating : null;
|
|
727
|
+
const scopeElement = ((_e = (_d = instance.handleCloseOptions) == null ? void 0 : _d.getScope) == null ? void 0 : _e.call(_d)) ?? cachedScopeElement ?? parentScopeElement ?? closest(ref, "[data-rootownerid]") ?? doc.body;
|
|
728
|
+
applySafePolygonPointerEventsMutation(instance, {
|
|
729
|
+
scopeElement,
|
|
730
|
+
referenceElement: ref,
|
|
731
|
+
floatingElement: floatingEl
|
|
732
|
+
});
|
|
733
|
+
return () => {
|
|
734
|
+
clearPointerEvents();
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
return void 0;
|
|
738
|
+
}, [enabled, open, domReferenceElement, floatingElement, instance, isHoverOpen, tree, parentId, clearPointerEvents]);
|
|
739
|
+
React.useEffect(() => {
|
|
740
|
+
if (!enabled) {
|
|
741
|
+
return void 0;
|
|
742
|
+
}
|
|
743
|
+
function hasParentChildren() {
|
|
744
|
+
return !!(tree && parentId && getNodeChildren(tree.nodesRef.current, parentId).length > 0);
|
|
745
|
+
}
|
|
746
|
+
function closeWithDelay(event) {
|
|
747
|
+
const closeDelay = getDelay(closeDelayProp, "close", instance.pointerType);
|
|
748
|
+
const close = () => {
|
|
749
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
750
|
+
tree == null ? void 0 : tree.events.emit("floating.closed", event);
|
|
751
|
+
};
|
|
752
|
+
if (closeDelay) {
|
|
753
|
+
instance.openChangeTimeout.start(closeDelay, close);
|
|
754
|
+
} else {
|
|
755
|
+
instance.openChangeTimeout.clear();
|
|
756
|
+
close();
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
function handleInteractInside(event) {
|
|
760
|
+
const target = getTarget(event);
|
|
761
|
+
if (!isInteractiveElement(target)) {
|
|
762
|
+
instance.interactedInside = false;
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
instance.interactedInside = closest(target, "[aria-haspopup]") != null;
|
|
766
|
+
}
|
|
767
|
+
function onFloatingMouseEnter() {
|
|
768
|
+
instance.openChangeTimeout.clear();
|
|
769
|
+
childClosedTimeout.clear();
|
|
770
|
+
tree == null ? void 0 : tree.events.off("floating.closed", onNodeClosed);
|
|
771
|
+
clearPointerEvents();
|
|
772
|
+
}
|
|
773
|
+
function onFloatingMouseLeave(event) {
|
|
774
|
+
var _a;
|
|
775
|
+
if (hasParentChildren() && tree) {
|
|
776
|
+
tree.events.on("floating.closed", onNodeClosed);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements)) {
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
const currentNodeId = ((_a = dataRef.current.floatingContext) == null ? void 0 : _a.nodeId) ?? nodeIdProp;
|
|
783
|
+
const relatedTarget = event.relatedTarget;
|
|
784
|
+
const isMovingIntoDescendantFloating = tree && currentNodeId && isElement(relatedTarget) && getNodeChildren(tree.nodesRef.current, currentNodeId, false).some((node) => {
|
|
785
|
+
var _a2;
|
|
786
|
+
return contains((_a2 = node.context) == null ? void 0 : _a2.elements.floating, relatedTarget);
|
|
787
|
+
});
|
|
788
|
+
if (isMovingIntoDescendantFloating) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (instance.handler) {
|
|
792
|
+
instance.handler(event);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
clearPointerEvents();
|
|
796
|
+
if (isHoverOpen() && !isClickLikeOpenEvent$1()) {
|
|
797
|
+
closeWithDelay(event);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function onNodeClosed(event) {
|
|
801
|
+
if (!tree || !parentId || hasParentChildren()) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
childClosedTimeout.start(0, () => {
|
|
805
|
+
tree.events.off("floating.closed", onNodeClosed);
|
|
806
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
807
|
+
tree.events.emit("floating.closed", event);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
const floating = floatingElement;
|
|
811
|
+
return mergeCleanups(floating && addEventListener(floating, "mouseenter", onFloatingMouseEnter), floating && addEventListener(floating, "mouseleave", onFloatingMouseLeave), floating && addEventListener(floating, "pointerdown", handleInteractInside, true), () => {
|
|
812
|
+
tree == null ? void 0 : tree.events.off("floating.closed", onNodeClosed);
|
|
813
|
+
});
|
|
814
|
+
}, [enabled, floatingElement, store, dataRef, closeDelayProp, nodeIdProp, isHoverOpen, isClickLikeOpenEvent$1, clearPointerEvents, instance, tree, parentId, childClosedTimeout]);
|
|
815
|
+
}
|
|
816
|
+
const EMPTY_REF = {
|
|
817
|
+
current: null
|
|
818
|
+
};
|
|
819
|
+
function useHoverReferenceInteraction(store, props = {}) {
|
|
820
|
+
const {
|
|
821
|
+
enabled = true,
|
|
822
|
+
delay = 0,
|
|
823
|
+
handleClose = null,
|
|
824
|
+
mouseOnly = false,
|
|
825
|
+
restMs = 0,
|
|
826
|
+
move = true,
|
|
827
|
+
triggerElementRef = EMPTY_REF,
|
|
828
|
+
externalTree,
|
|
829
|
+
isActiveTrigger = true,
|
|
830
|
+
getHandleCloseContext,
|
|
831
|
+
isClosing,
|
|
832
|
+
shouldOpen: shouldOpenProp,
|
|
833
|
+
guardStaleOpen = false
|
|
834
|
+
} = props;
|
|
835
|
+
const {
|
|
836
|
+
dataRef,
|
|
837
|
+
events
|
|
838
|
+
} = store.context;
|
|
839
|
+
const tree = useFloatingTree(externalTree);
|
|
840
|
+
const instance = useHoverInteractionSharedState(store);
|
|
841
|
+
const isHoverCloseActiveRef = React.useRef(false);
|
|
842
|
+
const handleCloseRef = useValueAsRef(handleClose);
|
|
843
|
+
const delayRef = useValueAsRef(delay);
|
|
844
|
+
const restMsRef = useValueAsRef(restMs);
|
|
845
|
+
const enabledRef = useValueAsRef(enabled);
|
|
846
|
+
const shouldOpenRef = useValueAsRef(shouldOpenProp);
|
|
847
|
+
const isClosingRef = useValueAsRef(isClosing);
|
|
848
|
+
const isClickLikeOpenEvent$1 = useStableCallback(() => {
|
|
849
|
+
var _a;
|
|
850
|
+
return isClickLikeOpenEvent((_a = dataRef.current.openEvent) == null ? void 0 : _a.type, instance.interactedInside);
|
|
851
|
+
});
|
|
852
|
+
const checkShouldOpen = useStableCallback(() => {
|
|
853
|
+
var _a;
|
|
854
|
+
return ((_a = shouldOpenRef.current) == null ? void 0 : _a.call(shouldOpenRef)) !== false;
|
|
855
|
+
});
|
|
856
|
+
const isOverInactiveTrigger = useStableCallback((currentDomReference, currentTarget, target) => {
|
|
857
|
+
const allTriggers = store.context.triggerElements;
|
|
858
|
+
if (allTriggers.hasElement(currentTarget)) {
|
|
859
|
+
return !currentDomReference || !contains(currentDomReference, currentTarget);
|
|
860
|
+
}
|
|
861
|
+
if (!isElement(target)) {
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
const targetElement = target;
|
|
865
|
+
return allTriggers.hasMatchingElement((trigger) => contains(trigger, targetElement)) && (!currentDomReference || !contains(currentDomReference, targetElement));
|
|
866
|
+
});
|
|
867
|
+
const cleanupMouseMoveHandler = useStableCallback(() => {
|
|
868
|
+
if (!instance.handler) {
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
const doc = ownerDocument(store.select("domReferenceElement"));
|
|
872
|
+
doc.removeEventListener("mousemove", instance.handler);
|
|
873
|
+
instance.handler = void 0;
|
|
874
|
+
});
|
|
875
|
+
const clearPointerEvents = useStableCallback(() => {
|
|
876
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
877
|
+
});
|
|
878
|
+
if (isActiveTrigger) {
|
|
879
|
+
instance.handleCloseOptions = handleClose == null ? void 0 : handleClose.__options;
|
|
880
|
+
}
|
|
881
|
+
React.useEffect(() => cleanupMouseMoveHandler, [cleanupMouseMoveHandler]);
|
|
882
|
+
React.useEffect(() => {
|
|
883
|
+
if (!enabled) {
|
|
884
|
+
return void 0;
|
|
885
|
+
}
|
|
886
|
+
function onOpenChangeLocal(details) {
|
|
887
|
+
if (!details.open) {
|
|
888
|
+
isHoverCloseActiveRef.current = details.reason === triggerHover;
|
|
889
|
+
cleanupMouseMoveHandler();
|
|
890
|
+
instance.openChangeTimeout.clear();
|
|
891
|
+
instance.restTimeout.clear();
|
|
892
|
+
instance.blockMouseMove = true;
|
|
893
|
+
instance.restTimeoutPending = false;
|
|
894
|
+
} else {
|
|
895
|
+
isHoverCloseActiveRef.current = false;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
events.on("openchange", onOpenChangeLocal);
|
|
899
|
+
return () => {
|
|
900
|
+
events.off("openchange", onOpenChangeLocal);
|
|
901
|
+
};
|
|
902
|
+
}, [enabled, events, instance, cleanupMouseMoveHandler]);
|
|
903
|
+
React.useEffect(() => {
|
|
904
|
+
if (!enabled) {
|
|
905
|
+
return void 0;
|
|
906
|
+
}
|
|
907
|
+
function closeWithDelay(event, runElseBranch = true) {
|
|
908
|
+
const closeDelay = getDelay(delayRef.current, "close", instance.pointerType);
|
|
909
|
+
if (closeDelay) {
|
|
910
|
+
instance.openChangeTimeout.start(closeDelay, () => {
|
|
911
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
912
|
+
tree == null ? void 0 : tree.events.emit("floating.closed", event);
|
|
913
|
+
});
|
|
914
|
+
} else if (runElseBranch) {
|
|
915
|
+
instance.openChangeTimeout.clear();
|
|
916
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
917
|
+
tree == null ? void 0 : tree.events.emit("floating.closed", event);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const trigger = triggerElementRef.current ?? (isActiveTrigger ? store.select("domReferenceElement") : null);
|
|
921
|
+
if (!isElement(trigger)) {
|
|
922
|
+
return void 0;
|
|
923
|
+
}
|
|
924
|
+
function onMouseEnter(event) {
|
|
925
|
+
var _a;
|
|
926
|
+
instance.openChangeTimeout.clear();
|
|
927
|
+
instance.blockMouseMove = false;
|
|
928
|
+
if (mouseOnly && !isMouseLikePointerType(instance.pointerType)) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
const restMsValue = getRestMs(restMsRef.current);
|
|
932
|
+
const openDelay = getDelay(delayRef.current, "open", instance.pointerType);
|
|
933
|
+
const eventTarget = getTarget(event);
|
|
934
|
+
const currentTarget = event.currentTarget ?? null;
|
|
935
|
+
const currentDomReference = store.select("domReferenceElement");
|
|
936
|
+
let triggerNode = currentTarget;
|
|
937
|
+
if (isElement(eventTarget) && !store.context.triggerElements.hasElement(eventTarget)) {
|
|
938
|
+
for (const triggerElement of store.context.triggerElements.elements()) {
|
|
939
|
+
if (contains(triggerElement, eventTarget)) {
|
|
940
|
+
triggerNode = triggerElement;
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (isElement(currentTarget) && isElement(currentDomReference) && !store.context.triggerElements.hasElement(currentTarget) && contains(currentTarget, currentDomReference)) {
|
|
946
|
+
triggerNode = currentDomReference;
|
|
947
|
+
}
|
|
948
|
+
const isOverInactive = triggerNode == null ? false : isOverInactiveTrigger(currentDomReference, triggerNode, eventTarget);
|
|
949
|
+
const isOpen = store.select("open");
|
|
950
|
+
const isInClosingTransition = ((_a = isClosingRef.current) == null ? void 0 : _a.call(isClosingRef)) ?? store.select("transitionStatus") === "ending";
|
|
951
|
+
const isHoverCloseTransition = !isOpen && isInClosingTransition && isHoverCloseActiveRef.current;
|
|
952
|
+
const isReenteringSameTriggerDuringCloseTransition = !isOverInactive && isElement(triggerNode) && isElement(currentDomReference) && contains(currentDomReference, triggerNode) && isHoverCloseTransition;
|
|
953
|
+
const isRestOnlyDelay = restMsValue > 0 && !openDelay;
|
|
954
|
+
const shouldOpenImmediately = isOverInactive && (isOpen || isHoverCloseTransition) || isReenteringSameTriggerDuringCloseTransition;
|
|
955
|
+
const shouldOpen = !isOpen || isOverInactive;
|
|
956
|
+
if (shouldOpenImmediately) {
|
|
957
|
+
if (checkShouldOpen()) {
|
|
958
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
959
|
+
}
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
if (isRestOnlyDelay) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
if (openDelay) {
|
|
966
|
+
instance.openChangeTimeout.start(openDelay, () => {
|
|
967
|
+
if (shouldOpen && checkShouldOpen()) {
|
|
968
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
} else if (shouldOpen) {
|
|
972
|
+
if (checkShouldOpen()) {
|
|
973
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function onMouseLeave(event) {
|
|
978
|
+
if (isClickLikeOpenEvent$1()) {
|
|
979
|
+
clearPointerEvents();
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
cleanupMouseMoveHandler();
|
|
983
|
+
const domReferenceElement = store.select("domReferenceElement");
|
|
984
|
+
const doc = ownerDocument(domReferenceElement);
|
|
985
|
+
instance.restTimeout.clear();
|
|
986
|
+
instance.restTimeoutPending = false;
|
|
987
|
+
const handleCloseContextBase = dataRef.current.floatingContext ?? (getHandleCloseContext == null ? void 0 : getHandleCloseContext());
|
|
988
|
+
if (isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements)) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (handleCloseRef.current && handleCloseContextBase) {
|
|
992
|
+
if (!store.select("open")) {
|
|
993
|
+
instance.openChangeTimeout.clear();
|
|
994
|
+
}
|
|
995
|
+
const currentTrigger = triggerElementRef.current;
|
|
996
|
+
instance.handler = handleCloseRef.current({
|
|
997
|
+
...handleCloseContextBase,
|
|
998
|
+
tree,
|
|
999
|
+
x: event.clientX,
|
|
1000
|
+
y: event.clientY,
|
|
1001
|
+
onClose() {
|
|
1002
|
+
clearPointerEvents();
|
|
1003
|
+
cleanupMouseMoveHandler();
|
|
1004
|
+
if (enabledRef.current && !isClickLikeOpenEvent$1() && currentTrigger === store.select("domReferenceElement")) {
|
|
1005
|
+
closeWithDelay(event, true);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
doc.addEventListener("mousemove", instance.handler);
|
|
1010
|
+
instance.handler(event);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
const shouldClose = instance.pointerType === "touch" ? !contains(store.select("floatingElement"), event.relatedTarget) : true;
|
|
1014
|
+
if (shouldClose) {
|
|
1015
|
+
closeWithDelay(event);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function onMouseOut(event) {
|
|
1019
|
+
if (contains(trigger, event.relatedTarget)) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
instance.openChangeTimeout.clear();
|
|
1023
|
+
instance.restTimeout.clear();
|
|
1024
|
+
instance.restTimeoutPending = false;
|
|
1025
|
+
}
|
|
1026
|
+
const staleOpenGuard = guardStaleOpen ? addEventListener(trigger, "mouseout", onMouseOut) : void 0;
|
|
1027
|
+
if (move) {
|
|
1028
|
+
return mergeCleanups(addEventListener(trigger, "mousemove", onMouseEnter, {
|
|
1029
|
+
once: true
|
|
1030
|
+
}), addEventListener(trigger, "mouseenter", onMouseEnter), addEventListener(trigger, "mouseleave", onMouseLeave), staleOpenGuard);
|
|
1031
|
+
}
|
|
1032
|
+
return mergeCleanups(addEventListener(trigger, "mouseenter", onMouseEnter), addEventListener(trigger, "mouseleave", onMouseLeave), staleOpenGuard);
|
|
1033
|
+
}, [cleanupMouseMoveHandler, clearPointerEvents, dataRef, delayRef, store, enabled, handleCloseRef, instance, isActiveTrigger, isOverInactiveTrigger, isClickLikeOpenEvent$1, mouseOnly, move, restMsRef, triggerElementRef, tree, enabledRef, getHandleCloseContext, isClosingRef, checkShouldOpen, guardStaleOpen]);
|
|
1034
|
+
return React.useMemo(() => {
|
|
1035
|
+
if (!enabled) {
|
|
1036
|
+
return void 0;
|
|
1037
|
+
}
|
|
1038
|
+
function setPointerRef(event) {
|
|
1039
|
+
instance.pointerType = event.pointerType;
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
onPointerDown: setPointerRef,
|
|
1043
|
+
onPointerEnter: setPointerRef,
|
|
1044
|
+
onMouseMove(event) {
|
|
1045
|
+
var _a, _b, _c;
|
|
1046
|
+
const {
|
|
1047
|
+
nativeEvent
|
|
1048
|
+
} = event;
|
|
1049
|
+
const trigger = event.currentTarget;
|
|
1050
|
+
const currentDomReference = store.select("domReferenceElement");
|
|
1051
|
+
const currentOpen = store.select("open");
|
|
1052
|
+
const isOverInactive = isOverInactiveTrigger(currentDomReference, trigger, event.target);
|
|
1053
|
+
if (mouseOnly && !isMouseLikePointerType(instance.pointerType)) {
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (currentOpen && isOverInactive && ((_a = instance.handleCloseOptions) == null ? void 0 : _a.blockPointerEvents)) {
|
|
1057
|
+
const floatingElement = store.select("floatingElement");
|
|
1058
|
+
if (floatingElement) {
|
|
1059
|
+
const scopeElement = ((_c = (_b = instance.handleCloseOptions) == null ? void 0 : _b.getScope) == null ? void 0 : _c.call(_b)) ?? trigger.ownerDocument.body;
|
|
1060
|
+
applySafePolygonPointerEventsMutation(instance, {
|
|
1061
|
+
scopeElement,
|
|
1062
|
+
referenceElement: trigger,
|
|
1063
|
+
floatingElement
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
const restMsValue = getRestMs(restMsRef.current);
|
|
1068
|
+
if (currentOpen && !isOverInactive || restMsValue === 0) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
if (!isOverInactive && instance.restTimeoutPending && event.movementX ** 2 + event.movementY ** 2 < 2) {
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
instance.restTimeout.clear();
|
|
1075
|
+
function handleMouseMove() {
|
|
1076
|
+
instance.restTimeoutPending = false;
|
|
1077
|
+
if (isClickLikeOpenEvent$1()) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const latestOpen = store.select("open");
|
|
1081
|
+
if (!instance.blockMouseMove && (!latestOpen || isOverInactive) && checkShouldOpen()) {
|
|
1082
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, nativeEvent, trigger));
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
if (instance.pointerType === "touch") {
|
|
1086
|
+
ReactDOM.flushSync(() => {
|
|
1087
|
+
handleMouseMove();
|
|
1088
|
+
});
|
|
1089
|
+
} else if (isOverInactive && currentOpen) {
|
|
1090
|
+
handleMouseMove();
|
|
1091
|
+
} else {
|
|
1092
|
+
instance.restTimeoutPending = true;
|
|
1093
|
+
instance.restTimeout.start(restMsValue, handleMouseMove);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
}, [enabled, instance, isClickLikeOpenEvent$1, isOverInactiveTrigger, mouseOnly, store, restMsRef, checkShouldOpen]);
|
|
1098
|
+
}
|
|
1099
|
+
const CURSOR_SPEED_THRESHOLD = 0.1;
|
|
1100
|
+
const CURSOR_SPEED_THRESHOLD_SQUARED = CURSOR_SPEED_THRESHOLD * CURSOR_SPEED_THRESHOLD;
|
|
1101
|
+
const POLYGON_BUFFER = 0.5;
|
|
1102
|
+
function hasIntersectingEdge(pointX, pointY, xi, yi, xj, yj) {
|
|
1103
|
+
return yi >= pointY !== yj >= pointY && pointX <= (xj - xi) * (pointY - yi) / (yj - yi) + xi;
|
|
1104
|
+
}
|
|
1105
|
+
function isPointInQuadrilateral(pointX, pointY, x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
1106
|
+
let isInsideValue = false;
|
|
1107
|
+
if (hasIntersectingEdge(pointX, pointY, x1, y1, x2, y2)) {
|
|
1108
|
+
isInsideValue = !isInsideValue;
|
|
1109
|
+
}
|
|
1110
|
+
if (hasIntersectingEdge(pointX, pointY, x2, y2, x3, y3)) {
|
|
1111
|
+
isInsideValue = !isInsideValue;
|
|
1112
|
+
}
|
|
1113
|
+
if (hasIntersectingEdge(pointX, pointY, x3, y3, x4, y4)) {
|
|
1114
|
+
isInsideValue = !isInsideValue;
|
|
1115
|
+
}
|
|
1116
|
+
if (hasIntersectingEdge(pointX, pointY, x4, y4, x1, y1)) {
|
|
1117
|
+
isInsideValue = !isInsideValue;
|
|
1118
|
+
}
|
|
1119
|
+
return isInsideValue;
|
|
1120
|
+
}
|
|
1121
|
+
function isInsideRect(pointX, pointY, rect) {
|
|
1122
|
+
return pointX >= rect.x && pointX <= rect.x + rect.width && pointY >= rect.y && pointY <= rect.y + rect.height;
|
|
1123
|
+
}
|
|
1124
|
+
function isInsideAxisAlignedRect(pointX, pointY, x1, y1, x2, y2) {
|
|
1125
|
+
const minX = Math.min(x1, x2);
|
|
1126
|
+
const maxX = Math.max(x1, x2);
|
|
1127
|
+
const minY = Math.min(y1, y2);
|
|
1128
|
+
const maxY = Math.max(y1, y2);
|
|
1129
|
+
return pointX >= minX && pointX <= maxX && pointY >= minY && pointY <= maxY;
|
|
1130
|
+
}
|
|
1131
|
+
function safePolygon(options = {}) {
|
|
1132
|
+
const {
|
|
1133
|
+
blockPointerEvents = false
|
|
1134
|
+
} = options;
|
|
1135
|
+
const timeout = new Timeout();
|
|
1136
|
+
const fn = ({
|
|
1137
|
+
x,
|
|
1138
|
+
y,
|
|
1139
|
+
placement,
|
|
1140
|
+
elements,
|
|
1141
|
+
onClose,
|
|
1142
|
+
nodeId,
|
|
1143
|
+
tree
|
|
1144
|
+
}) => {
|
|
1145
|
+
const side = placement == null ? void 0 : placement.split("-")[0];
|
|
1146
|
+
let hasLanded = false;
|
|
1147
|
+
let lastX = null;
|
|
1148
|
+
let lastY = null;
|
|
1149
|
+
let lastCursorTime = typeof performance !== "undefined" ? performance.now() : 0;
|
|
1150
|
+
function isCursorMovingSlowly(nextX, nextY) {
|
|
1151
|
+
const currentTime = performance.now();
|
|
1152
|
+
const elapsedTime = currentTime - lastCursorTime;
|
|
1153
|
+
if (lastX === null || lastY === null || elapsedTime === 0) {
|
|
1154
|
+
lastX = nextX;
|
|
1155
|
+
lastY = nextY;
|
|
1156
|
+
lastCursorTime = currentTime;
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
const deltaX = nextX - lastX;
|
|
1160
|
+
const deltaY = nextY - lastY;
|
|
1161
|
+
const distanceSquared = deltaX * deltaX + deltaY * deltaY;
|
|
1162
|
+
const thresholdSquared = elapsedTime * elapsedTime * CURSOR_SPEED_THRESHOLD_SQUARED;
|
|
1163
|
+
lastX = nextX;
|
|
1164
|
+
lastY = nextY;
|
|
1165
|
+
lastCursorTime = currentTime;
|
|
1166
|
+
return distanceSquared < thresholdSquared;
|
|
1167
|
+
}
|
|
1168
|
+
function close() {
|
|
1169
|
+
timeout.clear();
|
|
1170
|
+
onClose();
|
|
1171
|
+
}
|
|
1172
|
+
return function onMouseMove(event) {
|
|
1173
|
+
timeout.clear();
|
|
1174
|
+
const domReference = elements.domReference;
|
|
1175
|
+
const floating = elements.floating;
|
|
1176
|
+
if (!domReference || !floating || side == null || x == null || y == null) {
|
|
1177
|
+
return void 0;
|
|
1178
|
+
}
|
|
1179
|
+
const {
|
|
1180
|
+
clientX,
|
|
1181
|
+
clientY
|
|
1182
|
+
} = event;
|
|
1183
|
+
const target = getTarget(event);
|
|
1184
|
+
const isLeave = event.type === "mouseleave";
|
|
1185
|
+
const isOverFloatingEl = contains(floating, target);
|
|
1186
|
+
const isOverReferenceEl = contains(domReference, target);
|
|
1187
|
+
if (isOverFloatingEl) {
|
|
1188
|
+
hasLanded = true;
|
|
1189
|
+
if (!isLeave) {
|
|
1190
|
+
return void 0;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
if (isOverReferenceEl) {
|
|
1194
|
+
hasLanded = false;
|
|
1195
|
+
if (!isLeave) {
|
|
1196
|
+
hasLanded = true;
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
if (isLeave && isElement(event.relatedTarget) && contains(floating, event.relatedTarget)) {
|
|
1201
|
+
return void 0;
|
|
1202
|
+
}
|
|
1203
|
+
function hasOpenChildNode() {
|
|
1204
|
+
return Boolean(tree && getNodeChildren(tree.nodesRef.current, nodeId).length > 0);
|
|
1205
|
+
}
|
|
1206
|
+
function closeIfNoOpenChild() {
|
|
1207
|
+
if (!hasOpenChildNode()) {
|
|
1208
|
+
close();
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
if (hasOpenChildNode()) {
|
|
1212
|
+
return void 0;
|
|
1213
|
+
}
|
|
1214
|
+
const refRect = domReference.getBoundingClientRect();
|
|
1215
|
+
const rect = floating.getBoundingClientRect();
|
|
1216
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
1217
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
1218
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
1219
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
1220
|
+
const left = (isFloatingWider ? refRect : rect).left;
|
|
1221
|
+
const right = (isFloatingWider ? refRect : rect).right;
|
|
1222
|
+
const top = (isFloatingTaller ? refRect : rect).top;
|
|
1223
|
+
const bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
1224
|
+
if (side === "top" && y >= refRect.bottom - 1 || side === "bottom" && y <= refRect.top + 1 || side === "left" && x >= refRect.right - 1 || side === "right" && x <= refRect.left + 1) {
|
|
1225
|
+
closeIfNoOpenChild();
|
|
1226
|
+
return void 0;
|
|
1227
|
+
}
|
|
1228
|
+
let isInsideTroughRect = false;
|
|
1229
|
+
switch (side) {
|
|
1230
|
+
case "top":
|
|
1231
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, left, refRect.top + 1, right, rect.bottom - 1);
|
|
1232
|
+
break;
|
|
1233
|
+
case "bottom":
|
|
1234
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, left, rect.top + 1, right, refRect.bottom - 1);
|
|
1235
|
+
break;
|
|
1236
|
+
case "left":
|
|
1237
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, rect.right - 1, bottom, refRect.left + 1, top);
|
|
1238
|
+
break;
|
|
1239
|
+
case "right":
|
|
1240
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, refRect.right - 1, bottom, rect.left + 1, top);
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
if (isInsideTroughRect) {
|
|
1244
|
+
return void 0;
|
|
1245
|
+
}
|
|
1246
|
+
if (hasLanded && !isInsideRect(clientX, clientY, refRect)) {
|
|
1247
|
+
closeIfNoOpenChild();
|
|
1248
|
+
return void 0;
|
|
1249
|
+
}
|
|
1250
|
+
if (!isLeave && isCursorMovingSlowly(clientX, clientY)) {
|
|
1251
|
+
closeIfNoOpenChild();
|
|
1252
|
+
return void 0;
|
|
1253
|
+
}
|
|
1254
|
+
let isInsidePolygon = false;
|
|
1255
|
+
switch (side) {
|
|
1256
|
+
case "top": {
|
|
1257
|
+
const cursorXOffset = isFloatingWider ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
1258
|
+
const cursorPointOneX = isFloatingWider ? x + cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
1259
|
+
const cursorPointTwoX = isFloatingWider ? x - cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
1260
|
+
const cursorPointY = y + POLYGON_BUFFER + 1;
|
|
1261
|
+
const commonYLeft = cursorLeaveFromRight ? rect.bottom - POLYGON_BUFFER : isFloatingWider ? rect.bottom - POLYGON_BUFFER : rect.top;
|
|
1262
|
+
const commonYRight = cursorLeaveFromRight ? isFloatingWider ? rect.bottom - POLYGON_BUFFER : rect.top : rect.bottom - POLYGON_BUFFER;
|
|
1263
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointOneX, cursorPointY, cursorPointTwoX, cursorPointY, rect.left, commonYLeft, rect.right, commonYRight);
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
case "bottom": {
|
|
1267
|
+
const cursorXOffset = isFloatingWider ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
1268
|
+
const cursorPointOneX = isFloatingWider ? x + cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
1269
|
+
const cursorPointTwoX = isFloatingWider ? x - cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
1270
|
+
const cursorPointY = y - POLYGON_BUFFER;
|
|
1271
|
+
const commonYLeft = cursorLeaveFromRight ? rect.top + POLYGON_BUFFER : isFloatingWider ? rect.top + POLYGON_BUFFER : rect.bottom;
|
|
1272
|
+
const commonYRight = cursorLeaveFromRight ? isFloatingWider ? rect.top + POLYGON_BUFFER : rect.bottom : rect.top + POLYGON_BUFFER;
|
|
1273
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointOneX, cursorPointY, cursorPointTwoX, cursorPointY, rect.left, commonYLeft, rect.right, commonYRight);
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
case "left": {
|
|
1277
|
+
const cursorYOffset = isFloatingTaller ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
1278
|
+
const cursorPointOneY = isFloatingTaller ? y + cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
1279
|
+
const cursorPointTwoY = isFloatingTaller ? y - cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
1280
|
+
const cursorPointX = x + POLYGON_BUFFER + 1;
|
|
1281
|
+
const commonXTop = cursorLeaveFromBottom ? rect.right - POLYGON_BUFFER : isFloatingTaller ? rect.right - POLYGON_BUFFER : rect.left;
|
|
1282
|
+
const commonXBottom = cursorLeaveFromBottom ? isFloatingTaller ? rect.right - POLYGON_BUFFER : rect.left : rect.right - POLYGON_BUFFER;
|
|
1283
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, commonXTop, rect.top, commonXBottom, rect.bottom, cursorPointX, cursorPointOneY, cursorPointX, cursorPointTwoY);
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
case "right": {
|
|
1287
|
+
const cursorYOffset = isFloatingTaller ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
1288
|
+
const cursorPointOneY = isFloatingTaller ? y + cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
1289
|
+
const cursorPointTwoY = isFloatingTaller ? y - cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
1290
|
+
const cursorPointX = x - POLYGON_BUFFER;
|
|
1291
|
+
const commonXTop = cursorLeaveFromBottom ? rect.left + POLYGON_BUFFER : isFloatingTaller ? rect.left + POLYGON_BUFFER : rect.right;
|
|
1292
|
+
const commonXBottom = cursorLeaveFromBottom ? isFloatingTaller ? rect.left + POLYGON_BUFFER : rect.right : rect.left + POLYGON_BUFFER;
|
|
1293
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointX, cursorPointOneY, cursorPointX, cursorPointTwoY, commonXTop, rect.top, commonXBottom, rect.bottom);
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
if (!isInsidePolygon) {
|
|
1298
|
+
closeIfNoOpenChild();
|
|
1299
|
+
} else if (!hasLanded) {
|
|
1300
|
+
timeout.start(40, closeIfNoOpenChild);
|
|
1301
|
+
}
|
|
1302
|
+
return void 0;
|
|
1303
|
+
};
|
|
1304
|
+
};
|
|
1305
|
+
fn.__options = {
|
|
1306
|
+
...options,
|
|
1307
|
+
blockPointerEvents
|
|
1308
|
+
};
|
|
1309
|
+
return fn;
|
|
1310
|
+
}
|
|
1311
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
1312
|
+
let {
|
|
1313
|
+
reference,
|
|
1314
|
+
floating
|
|
1315
|
+
} = _ref;
|
|
1316
|
+
const sideAxis = getSideAxis(placement);
|
|
1317
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
1318
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
1319
|
+
const side = getSide(placement);
|
|
1320
|
+
const isVertical = sideAxis === "y";
|
|
1321
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
1322
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
1323
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
1324
|
+
let coords;
|
|
1325
|
+
switch (side) {
|
|
1326
|
+
case "top":
|
|
1327
|
+
coords = {
|
|
1328
|
+
x: commonX,
|
|
1329
|
+
y: reference.y - floating.height
|
|
1330
|
+
};
|
|
1331
|
+
break;
|
|
1332
|
+
case "bottom":
|
|
1333
|
+
coords = {
|
|
1334
|
+
x: commonX,
|
|
1335
|
+
y: reference.y + reference.height
|
|
1336
|
+
};
|
|
1337
|
+
break;
|
|
1338
|
+
case "right":
|
|
1339
|
+
coords = {
|
|
1340
|
+
x: reference.x + reference.width,
|
|
1341
|
+
y: commonY
|
|
1342
|
+
};
|
|
1343
|
+
break;
|
|
1344
|
+
case "left":
|
|
1345
|
+
coords = {
|
|
1346
|
+
x: reference.x - floating.width,
|
|
1347
|
+
y: commonY
|
|
1348
|
+
};
|
|
1349
|
+
break;
|
|
1350
|
+
default:
|
|
1351
|
+
coords = {
|
|
1352
|
+
x: reference.x,
|
|
1353
|
+
y: reference.y
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
const alignment = getAlignment(placement);
|
|
1357
|
+
if (alignment) {
|
|
1358
|
+
coords[alignmentAxis] += commonAlign * (alignment === "end" ? 1 : -1) * (rtl && isVertical ? -1 : 1);
|
|
1359
|
+
}
|
|
1360
|
+
return coords;
|
|
1361
|
+
}
|
|
1362
|
+
async function detectOverflow(state, options) {
|
|
1363
|
+
var _await$platform$isEle;
|
|
1364
|
+
if (options === void 0) {
|
|
1365
|
+
options = {};
|
|
1366
|
+
}
|
|
1367
|
+
const {
|
|
1368
|
+
x,
|
|
1369
|
+
y,
|
|
1370
|
+
platform: platform2,
|
|
1371
|
+
rects,
|
|
1372
|
+
elements,
|
|
1373
|
+
strategy
|
|
1374
|
+
} = state;
|
|
1375
|
+
const {
|
|
1376
|
+
boundary = "clippingAncestors",
|
|
1377
|
+
rootBoundary = "viewport",
|
|
1378
|
+
elementContext = "floating",
|
|
1379
|
+
altBoundary = false,
|
|
1380
|
+
padding = 0
|
|
1381
|
+
} = evaluate(options, state);
|
|
1382
|
+
const paddingObject = getPaddingObject(padding);
|
|
1383
|
+
const altContext = elementContext === "floating" ? "reference" : "floating";
|
|
1384
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
1385
|
+
const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
|
|
1386
|
+
element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
|
|
1387
|
+
boundary,
|
|
1388
|
+
rootBoundary,
|
|
1389
|
+
strategy
|
|
1390
|
+
}));
|
|
1391
|
+
const rect = elementContext === "floating" ? {
|
|
1392
|
+
x,
|
|
1393
|
+
y,
|
|
1394
|
+
width: rects.floating.width,
|
|
1395
|
+
height: rects.floating.height
|
|
1396
|
+
} : rects.reference;
|
|
1397
|
+
const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
|
|
1398
|
+
const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) && await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
|
|
1399
|
+
x: 1,
|
|
1400
|
+
y: 1
|
|
1401
|
+
};
|
|
1402
|
+
const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
1403
|
+
elements,
|
|
1404
|
+
rect,
|
|
1405
|
+
offsetParent,
|
|
1406
|
+
strategy
|
|
1407
|
+
}) : rect);
|
|
1408
|
+
return {
|
|
1409
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
1410
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
1411
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
1412
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
const MAX_RESET_COUNT = 50;
|
|
1416
|
+
const computePosition$1 = async (reference, floating, config) => {
|
|
1417
|
+
const {
|
|
1418
|
+
placement = "bottom",
|
|
1419
|
+
strategy = "absolute",
|
|
1420
|
+
middleware = [],
|
|
1421
|
+
platform: platform2
|
|
1422
|
+
} = config;
|
|
1423
|
+
const platformWithDetectOverflow = platform2.detectOverflow ? platform2 : {
|
|
1424
|
+
...platform2,
|
|
1425
|
+
detectOverflow
|
|
1426
|
+
};
|
|
1427
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
|
|
1428
|
+
let rects = await platform2.getElementRects({
|
|
1429
|
+
reference,
|
|
1430
|
+
floating,
|
|
1431
|
+
strategy
|
|
1432
|
+
});
|
|
1433
|
+
let {
|
|
1434
|
+
x,
|
|
1435
|
+
y
|
|
1436
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
1437
|
+
let statefulPlacement = placement;
|
|
1438
|
+
let resetCount = 0;
|
|
1439
|
+
const middlewareData = {};
|
|
1440
|
+
for (let i = 0; i < middleware.length; i++) {
|
|
1441
|
+
const currentMiddleware = middleware[i];
|
|
1442
|
+
if (!currentMiddleware) {
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
const {
|
|
1446
|
+
name,
|
|
1447
|
+
fn
|
|
1448
|
+
} = currentMiddleware;
|
|
1449
|
+
const {
|
|
1450
|
+
x: nextX,
|
|
1451
|
+
y: nextY,
|
|
1452
|
+
data,
|
|
1453
|
+
reset
|
|
1454
|
+
} = await fn({
|
|
1455
|
+
x,
|
|
1456
|
+
y,
|
|
1457
|
+
initialPlacement: placement,
|
|
1458
|
+
placement: statefulPlacement,
|
|
1459
|
+
strategy,
|
|
1460
|
+
middlewareData,
|
|
1461
|
+
rects,
|
|
1462
|
+
platform: platformWithDetectOverflow,
|
|
1463
|
+
elements: {
|
|
1464
|
+
reference,
|
|
1465
|
+
floating
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
x = nextX != null ? nextX : x;
|
|
1469
|
+
y = nextY != null ? nextY : y;
|
|
1470
|
+
middlewareData[name] = {
|
|
1471
|
+
...middlewareData[name],
|
|
1472
|
+
...data
|
|
1473
|
+
};
|
|
1474
|
+
if (reset && resetCount < MAX_RESET_COUNT) {
|
|
1475
|
+
resetCount++;
|
|
1476
|
+
if (typeof reset === "object") {
|
|
1477
|
+
if (reset.placement) {
|
|
1478
|
+
statefulPlacement = reset.placement;
|
|
1479
|
+
}
|
|
1480
|
+
if (reset.rects) {
|
|
1481
|
+
rects = reset.rects === true ? await platform2.getElementRects({
|
|
1482
|
+
reference,
|
|
1483
|
+
floating,
|
|
1484
|
+
strategy
|
|
1485
|
+
}) : reset.rects;
|
|
1486
|
+
}
|
|
1487
|
+
({
|
|
1488
|
+
x,
|
|
1489
|
+
y
|
|
1490
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
1491
|
+
}
|
|
1492
|
+
i = -1;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return {
|
|
1496
|
+
x,
|
|
1497
|
+
y,
|
|
1498
|
+
placement: statefulPlacement,
|
|
1499
|
+
strategy,
|
|
1500
|
+
middlewareData
|
|
1501
|
+
};
|
|
1502
|
+
};
|
|
1503
|
+
const flip$2 = function(options) {
|
|
1504
|
+
if (options === void 0) {
|
|
1505
|
+
options = {};
|
|
1506
|
+
}
|
|
1507
|
+
return {
|
|
1508
|
+
name: "flip",
|
|
1509
|
+
options,
|
|
1510
|
+
async fn(state) {
|
|
1511
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
1512
|
+
const {
|
|
1513
|
+
placement,
|
|
1514
|
+
middlewareData,
|
|
1515
|
+
rects,
|
|
1516
|
+
initialPlacement,
|
|
1517
|
+
platform: platform2,
|
|
1518
|
+
elements
|
|
1519
|
+
} = state;
|
|
1520
|
+
const {
|
|
1521
|
+
mainAxis: checkMainAxis = true,
|
|
1522
|
+
crossAxis: checkCrossAxis = true,
|
|
1523
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
1524
|
+
fallbackStrategy = "bestFit",
|
|
1525
|
+
fallbackAxisSideDirection = "none",
|
|
1526
|
+
flipAlignment = true,
|
|
1527
|
+
...detectOverflowOptions
|
|
1528
|
+
} = evaluate(options, state);
|
|
1529
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
1530
|
+
return {};
|
|
1531
|
+
}
|
|
1532
|
+
const side = getSide(placement);
|
|
1533
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
1534
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
1535
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
1536
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
1537
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
|
|
1538
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
1539
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
1540
|
+
}
|
|
1541
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
1542
|
+
const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
|
|
1543
|
+
const overflows = [];
|
|
1544
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
1545
|
+
if (checkMainAxis) {
|
|
1546
|
+
overflows.push(overflow[side]);
|
|
1547
|
+
}
|
|
1548
|
+
if (checkCrossAxis) {
|
|
1549
|
+
const sides = getAlignmentSides(placement, rects, rtl);
|
|
1550
|
+
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
1551
|
+
}
|
|
1552
|
+
overflowsData = [...overflowsData, {
|
|
1553
|
+
placement,
|
|
1554
|
+
overflows
|
|
1555
|
+
}];
|
|
1556
|
+
if (!overflows.every((side2) => side2 <= 0)) {
|
|
1557
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
1558
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
1559
|
+
const nextPlacement = placements[nextIndex];
|
|
1560
|
+
if (nextPlacement) {
|
|
1561
|
+
const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
|
|
1562
|
+
if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
|
|
1563
|
+
// overflows the main axis.
|
|
1564
|
+
overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
|
|
1565
|
+
return {
|
|
1566
|
+
data: {
|
|
1567
|
+
index: nextIndex,
|
|
1568
|
+
overflows: overflowsData
|
|
1569
|
+
},
|
|
1570
|
+
reset: {
|
|
1571
|
+
placement: nextPlacement
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
1577
|
+
if (!resetPlacement) {
|
|
1578
|
+
switch (fallbackStrategy) {
|
|
1579
|
+
case "bestFit": {
|
|
1580
|
+
var _overflowsData$filter2;
|
|
1581
|
+
const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
|
|
1582
|
+
if (hasFallbackAxisSideDirection) {
|
|
1583
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
1584
|
+
return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
|
|
1585
|
+
// reading directions favoring greater width.
|
|
1586
|
+
currentSideAxis === "y";
|
|
1587
|
+
}
|
|
1588
|
+
return true;
|
|
1589
|
+
}).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
|
|
1590
|
+
if (placement2) {
|
|
1591
|
+
resetPlacement = placement2;
|
|
1592
|
+
}
|
|
1593
|
+
break;
|
|
1594
|
+
}
|
|
1595
|
+
case "initialPlacement":
|
|
1596
|
+
resetPlacement = initialPlacement;
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (placement !== resetPlacement) {
|
|
1601
|
+
return {
|
|
1602
|
+
reset: {
|
|
1603
|
+
placement: resetPlacement
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return {};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
};
|
|
1612
|
+
const originSides = /* @__PURE__ */ new Set(["left", "top"]);
|
|
1613
|
+
async function convertValueToCoords(state, options) {
|
|
1614
|
+
const {
|
|
1615
|
+
placement,
|
|
1616
|
+
platform: platform2,
|
|
1617
|
+
elements
|
|
1618
|
+
} = state;
|
|
1619
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
1620
|
+
const side = getSide(placement);
|
|
1621
|
+
const alignment = getAlignment(placement);
|
|
1622
|
+
const isVertical = getSideAxis(placement) === "y";
|
|
1623
|
+
const mainAxisMulti = originSides.has(side) ? -1 : 1;
|
|
1624
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
1625
|
+
const rawValue = evaluate(options, state);
|
|
1626
|
+
let {
|
|
1627
|
+
mainAxis,
|
|
1628
|
+
crossAxis,
|
|
1629
|
+
alignmentAxis
|
|
1630
|
+
} = typeof rawValue === "number" ? {
|
|
1631
|
+
mainAxis: rawValue,
|
|
1632
|
+
crossAxis: 0,
|
|
1633
|
+
alignmentAxis: null
|
|
1634
|
+
} : {
|
|
1635
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
1636
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
1637
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
1638
|
+
};
|
|
1639
|
+
if (alignment && typeof alignmentAxis === "number") {
|
|
1640
|
+
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
|
|
1641
|
+
}
|
|
1642
|
+
return isVertical ? {
|
|
1643
|
+
x: crossAxis * crossAxisMulti,
|
|
1644
|
+
y: mainAxis * mainAxisMulti
|
|
1645
|
+
} : {
|
|
1646
|
+
x: mainAxis * mainAxisMulti,
|
|
1647
|
+
y: crossAxis * crossAxisMulti
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
const offset$2 = function(options) {
|
|
1651
|
+
if (options === void 0) {
|
|
1652
|
+
options = 0;
|
|
1653
|
+
}
|
|
1654
|
+
return {
|
|
1655
|
+
name: "offset",
|
|
1656
|
+
options,
|
|
1657
|
+
async fn(state) {
|
|
1658
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
1659
|
+
const {
|
|
1660
|
+
x,
|
|
1661
|
+
y,
|
|
1662
|
+
placement,
|
|
1663
|
+
middlewareData
|
|
1664
|
+
} = state;
|
|
1665
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
1666
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
1667
|
+
return {};
|
|
1668
|
+
}
|
|
1669
|
+
return {
|
|
1670
|
+
x: x + diffCoords.x,
|
|
1671
|
+
y: y + diffCoords.y,
|
|
1672
|
+
data: {
|
|
1673
|
+
...diffCoords,
|
|
1674
|
+
placement
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
};
|
|
1680
|
+
const shift$2 = function(options) {
|
|
1681
|
+
if (options === void 0) {
|
|
1682
|
+
options = {};
|
|
1683
|
+
}
|
|
1684
|
+
return {
|
|
1685
|
+
name: "shift",
|
|
1686
|
+
options,
|
|
1687
|
+
async fn(state) {
|
|
1688
|
+
const {
|
|
1689
|
+
x,
|
|
1690
|
+
y,
|
|
1691
|
+
placement,
|
|
1692
|
+
platform: platform2
|
|
1693
|
+
} = state;
|
|
1694
|
+
const {
|
|
1695
|
+
mainAxis: checkMainAxis = true,
|
|
1696
|
+
crossAxis: checkCrossAxis = false,
|
|
1697
|
+
limiter = {
|
|
1698
|
+
fn: (_ref) => {
|
|
1699
|
+
let {
|
|
1700
|
+
x: x2,
|
|
1701
|
+
y: y2
|
|
1702
|
+
} = _ref;
|
|
1703
|
+
return {
|
|
1704
|
+
x: x2,
|
|
1705
|
+
y: y2
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
},
|
|
1709
|
+
...detectOverflowOptions
|
|
1710
|
+
} = evaluate(options, state);
|
|
1711
|
+
const coords = {
|
|
1712
|
+
x,
|
|
1713
|
+
y
|
|
1714
|
+
};
|
|
1715
|
+
const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
|
|
1716
|
+
const crossAxis = getSideAxis(placement);
|
|
1717
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
1718
|
+
let mainAxisCoord = coords[mainAxis];
|
|
1719
|
+
let crossAxisCoord = coords[crossAxis];
|
|
1720
|
+
const clampCoord = (axis, coord) => clamp(coord + overflow[axis === "y" ? "top" : "left"], coord, coord - overflow[axis === "y" ? "bottom" : "right"]);
|
|
1721
|
+
if (checkMainAxis) {
|
|
1722
|
+
mainAxisCoord = clampCoord(mainAxis, mainAxisCoord);
|
|
1723
|
+
}
|
|
1724
|
+
if (checkCrossAxis) {
|
|
1725
|
+
crossAxisCoord = clampCoord(crossAxis, crossAxisCoord);
|
|
1726
|
+
}
|
|
1727
|
+
const limitedCoords = limiter.fn({
|
|
1728
|
+
...state,
|
|
1729
|
+
[mainAxis]: mainAxisCoord,
|
|
1730
|
+
[crossAxis]: crossAxisCoord
|
|
1731
|
+
});
|
|
1732
|
+
return {
|
|
1733
|
+
...limitedCoords,
|
|
1734
|
+
data: {
|
|
1735
|
+
x: limitedCoords.x - x,
|
|
1736
|
+
y: limitedCoords.y - y,
|
|
1737
|
+
enabled: {
|
|
1738
|
+
[mainAxis]: checkMainAxis,
|
|
1739
|
+
[crossAxis]: checkCrossAxis
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
};
|
|
1746
|
+
const limitShift$2 = function(options) {
|
|
1747
|
+
if (options === void 0) {
|
|
1748
|
+
options = {};
|
|
1749
|
+
}
|
|
1750
|
+
return {
|
|
1751
|
+
options,
|
|
1752
|
+
fn(state) {
|
|
1753
|
+
var _rawOffset$mainAxis, _rawOffset$crossAxis;
|
|
1754
|
+
const {
|
|
1755
|
+
x,
|
|
1756
|
+
y,
|
|
1757
|
+
placement,
|
|
1758
|
+
rects,
|
|
1759
|
+
middlewareData
|
|
1760
|
+
} = state;
|
|
1761
|
+
const {
|
|
1762
|
+
offset: offset2 = 0,
|
|
1763
|
+
mainAxis: checkMainAxis = true,
|
|
1764
|
+
crossAxis: checkCrossAxis = true
|
|
1765
|
+
} = evaluate(options, state);
|
|
1766
|
+
const coords = {
|
|
1767
|
+
x,
|
|
1768
|
+
y
|
|
1769
|
+
};
|
|
1770
|
+
const crossAxis = getSideAxis(placement);
|
|
1771
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
1772
|
+
let mainAxisCoord = coords[mainAxis];
|
|
1773
|
+
let crossAxisCoord = coords[crossAxis];
|
|
1774
|
+
const rawOffset = evaluate(offset2, state);
|
|
1775
|
+
const computedOffset = typeof rawOffset === "number" ? {
|
|
1776
|
+
mainAxis: rawOffset,
|
|
1777
|
+
crossAxis: 0
|
|
1778
|
+
} : {
|
|
1779
|
+
mainAxis: (_rawOffset$mainAxis = rawOffset.mainAxis) != null ? _rawOffset$mainAxis : 0,
|
|
1780
|
+
crossAxis: (_rawOffset$crossAxis = rawOffset.crossAxis) != null ? _rawOffset$crossAxis : 0
|
|
1781
|
+
};
|
|
1782
|
+
if (checkMainAxis) {
|
|
1783
|
+
const len = mainAxis === "y" ? "height" : "width";
|
|
1784
|
+
const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
|
|
1785
|
+
const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
|
|
1786
|
+
if (mainAxisCoord < limitMin) {
|
|
1787
|
+
mainAxisCoord = limitMin;
|
|
1788
|
+
} else if (mainAxisCoord > limitMax) {
|
|
1789
|
+
mainAxisCoord = limitMax;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
if (checkCrossAxis) {
|
|
1793
|
+
var _middlewareData$offse, _middlewareData$offse2;
|
|
1794
|
+
const len = mainAxis === "y" ? "width" : "height";
|
|
1795
|
+
const isOriginSide = originSides.has(getSide(placement));
|
|
1796
|
+
const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
|
|
1797
|
+
const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
|
|
1798
|
+
if (crossAxisCoord < limitMin) {
|
|
1799
|
+
crossAxisCoord = limitMin;
|
|
1800
|
+
} else if (crossAxisCoord > limitMax) {
|
|
1801
|
+
crossAxisCoord = limitMax;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
return {
|
|
1805
|
+
[mainAxis]: mainAxisCoord,
|
|
1806
|
+
[crossAxis]: crossAxisCoord
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
};
|
|
1811
|
+
const size$2 = function(options) {
|
|
1812
|
+
if (options === void 0) {
|
|
1813
|
+
options = {};
|
|
1814
|
+
}
|
|
1815
|
+
return {
|
|
1816
|
+
name: "size",
|
|
1817
|
+
options,
|
|
1818
|
+
async fn(state) {
|
|
1819
|
+
const {
|
|
1820
|
+
placement,
|
|
1821
|
+
rects,
|
|
1822
|
+
platform: platform2,
|
|
1823
|
+
elements
|
|
1824
|
+
} = state;
|
|
1825
|
+
const {
|
|
1826
|
+
apply = () => {
|
|
1827
|
+
},
|
|
1828
|
+
...detectOverflowOptions
|
|
1829
|
+
} = evaluate(options, state);
|
|
1830
|
+
const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
|
|
1831
|
+
const side = getSide(placement);
|
|
1832
|
+
const alignment = getAlignment(placement);
|
|
1833
|
+
const isYAxis = getSideAxis(placement) === "y";
|
|
1834
|
+
const {
|
|
1835
|
+
width,
|
|
1836
|
+
height
|
|
1837
|
+
} = rects.floating;
|
|
1838
|
+
let heightSide;
|
|
1839
|
+
let widthSide;
|
|
1840
|
+
if (side === "top" || side === "bottom") {
|
|
1841
|
+
heightSide = side;
|
|
1842
|
+
widthSide = alignment === (await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right";
|
|
1843
|
+
} else {
|
|
1844
|
+
widthSide = side;
|
|
1845
|
+
heightSide = alignment === "end" ? "top" : "bottom";
|
|
1846
|
+
}
|
|
1847
|
+
const maximumClippingHeight = height - overflow.top - overflow.bottom;
|
|
1848
|
+
const maximumClippingWidth = width - overflow.left - overflow.right;
|
|
1849
|
+
const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
|
|
1850
|
+
const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
|
|
1851
|
+
const shiftData = state.middlewareData.shift;
|
|
1852
|
+
const noShift = !shiftData;
|
|
1853
|
+
let availableHeight2 = overflowAvailableHeight;
|
|
1854
|
+
let availableWidth2 = overflowAvailableWidth;
|
|
1855
|
+
if (shiftData != null && shiftData.enabled.x) {
|
|
1856
|
+
availableWidth2 = maximumClippingWidth;
|
|
1857
|
+
}
|
|
1858
|
+
if (shiftData != null && shiftData.enabled.y) {
|
|
1859
|
+
availableHeight2 = maximumClippingHeight;
|
|
1860
|
+
}
|
|
1861
|
+
if (noShift && !alignment) {
|
|
1862
|
+
if (isYAxis) {
|
|
1863
|
+
availableWidth2 = width - 2 * max(overflow.left, overflow.right);
|
|
1864
|
+
} else {
|
|
1865
|
+
availableHeight2 = height - 2 * max(overflow.top, overflow.bottom);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
await apply({
|
|
1869
|
+
...state,
|
|
1870
|
+
availableWidth: availableWidth2,
|
|
1871
|
+
availableHeight: availableHeight2
|
|
1872
|
+
});
|
|
1873
|
+
const nextDimensions = await platform2.getDimensions(elements.floating);
|
|
1874
|
+
if (width !== nextDimensions.width || height !== nextDimensions.height) {
|
|
1875
|
+
return {
|
|
1876
|
+
reset: {
|
|
1877
|
+
rects: true
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
return {};
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1884
|
+
};
|
|
1885
|
+
function getCssDimensions(element) {
|
|
1886
|
+
const css = getComputedStyle$1(element);
|
|
1887
|
+
let width = parseFloat(css.width) || 0;
|
|
1888
|
+
let height = parseFloat(css.height) || 0;
|
|
1889
|
+
const hasOffset = isHTMLElement(element);
|
|
1890
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
1891
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
1892
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
1893
|
+
if (shouldFallback) {
|
|
1894
|
+
width = offsetWidth;
|
|
1895
|
+
height = offsetHeight;
|
|
1896
|
+
}
|
|
1897
|
+
return {
|
|
1898
|
+
width,
|
|
1899
|
+
height,
|
|
1900
|
+
$: shouldFallback
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
function unwrapElement(element) {
|
|
1904
|
+
return !isElement(element) ? element.contextElement : element;
|
|
1905
|
+
}
|
|
1906
|
+
function getScale(element) {
|
|
1907
|
+
const domElement = unwrapElement(element);
|
|
1908
|
+
if (!isHTMLElement(domElement)) {
|
|
1909
|
+
return createCoords(1);
|
|
1910
|
+
}
|
|
1911
|
+
const rect = domElement.getBoundingClientRect();
|
|
1912
|
+
const {
|
|
1913
|
+
width,
|
|
1914
|
+
height,
|
|
1915
|
+
$
|
|
1916
|
+
} = getCssDimensions(domElement);
|
|
1917
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
1918
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
1919
|
+
if (!x || !Number.isFinite(x)) {
|
|
1920
|
+
x = 1;
|
|
1921
|
+
}
|
|
1922
|
+
if (!y || !Number.isFinite(y)) {
|
|
1923
|
+
y = 1;
|
|
1924
|
+
}
|
|
1925
|
+
return {
|
|
1926
|
+
x,
|
|
1927
|
+
y
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
const noOffsets = /* @__PURE__ */ createCoords(0);
|
|
1931
|
+
function getVisualOffsets(element) {
|
|
1932
|
+
const win = getWindow(element);
|
|
1933
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
1934
|
+
return noOffsets;
|
|
1935
|
+
}
|
|
1936
|
+
return {
|
|
1937
|
+
x: win.visualViewport.offsetLeft,
|
|
1938
|
+
y: win.visualViewport.offsetTop
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
1942
|
+
if (isFixed === void 0) {
|
|
1943
|
+
isFixed = false;
|
|
1944
|
+
}
|
|
1945
|
+
return !!floatingOffsetParent && isFixed && floatingOffsetParent === getWindow(element);
|
|
1946
|
+
}
|
|
1947
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
1948
|
+
if (includeScale === void 0) {
|
|
1949
|
+
includeScale = false;
|
|
1950
|
+
}
|
|
1951
|
+
if (isFixedStrategy === void 0) {
|
|
1952
|
+
isFixedStrategy = false;
|
|
1953
|
+
}
|
|
1954
|
+
const clientRect = element.getBoundingClientRect();
|
|
1955
|
+
const domElement = unwrapElement(element);
|
|
1956
|
+
let scale = createCoords(1);
|
|
1957
|
+
if (includeScale) {
|
|
1958
|
+
if (offsetParent) {
|
|
1959
|
+
if (isElement(offsetParent)) {
|
|
1960
|
+
scale = getScale(offsetParent);
|
|
1961
|
+
}
|
|
1962
|
+
} else {
|
|
1963
|
+
scale = getScale(element);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
1967
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
1968
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
1969
|
+
let width = clientRect.width / scale.x;
|
|
1970
|
+
let height = clientRect.height / scale.y;
|
|
1971
|
+
if (domElement && offsetParent) {
|
|
1972
|
+
const win = getWindow(domElement);
|
|
1973
|
+
const offsetWin = isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
1974
|
+
let currentWin = win;
|
|
1975
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
1976
|
+
while (currentIFrame && offsetWin !== currentWin) {
|
|
1977
|
+
const iframeScale = getScale(currentIFrame);
|
|
1978
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
1979
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
1980
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
1981
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
1982
|
+
x *= iframeScale.x;
|
|
1983
|
+
y *= iframeScale.y;
|
|
1984
|
+
width *= iframeScale.x;
|
|
1985
|
+
height *= iframeScale.y;
|
|
1986
|
+
x += left;
|
|
1987
|
+
y += top;
|
|
1988
|
+
currentWin = getWindow(currentIFrame);
|
|
1989
|
+
currentIFrame = getFrameElement(currentWin);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
return rectToClientRect({
|
|
1993
|
+
width,
|
|
1994
|
+
height,
|
|
1995
|
+
x,
|
|
1996
|
+
y
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
function getWindowScrollBarX(element, rect) {
|
|
2000
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
2001
|
+
if (!rect) {
|
|
2002
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
2003
|
+
}
|
|
2004
|
+
return rect.left + leftScroll;
|
|
2005
|
+
}
|
|
2006
|
+
function getHTMLOffset(documentElement, scroll) {
|
|
2007
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
2008
|
+
const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
|
|
2009
|
+
const y = htmlRect.top + scroll.scrollTop;
|
|
2010
|
+
return {
|
|
2011
|
+
x,
|
|
2012
|
+
y
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
2016
|
+
let {
|
|
2017
|
+
elements,
|
|
2018
|
+
rect,
|
|
2019
|
+
offsetParent,
|
|
2020
|
+
strategy
|
|
2021
|
+
} = _ref;
|
|
2022
|
+
const isFixed = strategy === "fixed";
|
|
2023
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
2024
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
2025
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
2026
|
+
return rect;
|
|
2027
|
+
}
|
|
2028
|
+
let scroll = {
|
|
2029
|
+
scrollLeft: 0,
|
|
2030
|
+
scrollTop: 0
|
|
2031
|
+
};
|
|
2032
|
+
let scale = createCoords(1);
|
|
2033
|
+
const offsets = createCoords(0);
|
|
2034
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
2035
|
+
if (isOffsetParentAnElement || !isFixed) {
|
|
2036
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
2037
|
+
scroll = getNodeScroll(offsetParent);
|
|
2038
|
+
}
|
|
2039
|
+
if (isOffsetParentAnElement) {
|
|
2040
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
2041
|
+
scale = getScale(offsetParent);
|
|
2042
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
2043
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
2047
|
+
return {
|
|
2048
|
+
width: rect.width * scale.x,
|
|
2049
|
+
height: rect.height * scale.y,
|
|
2050
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
|
|
2051
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
function getClientRects(element) {
|
|
2055
|
+
return element.getClientRects ? Array.from(element.getClientRects()) : [];
|
|
2056
|
+
}
|
|
2057
|
+
function getDocumentRect(html) {
|
|
2058
|
+
const scroll = getNodeScroll(html);
|
|
2059
|
+
const body = html.ownerDocument.body;
|
|
2060
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
2061
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
2062
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(html);
|
|
2063
|
+
const y = -scroll.scrollTop;
|
|
2064
|
+
if (getComputedStyle$1(body).direction === "rtl") {
|
|
2065
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
2066
|
+
}
|
|
2067
|
+
return {
|
|
2068
|
+
width,
|
|
2069
|
+
height,
|
|
2070
|
+
x,
|
|
2071
|
+
y
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
const SCROLLBAR_MAX = 25;
|
|
2075
|
+
function getViewportRect(element, strategy, rootBoundary) {
|
|
2076
|
+
if (rootBoundary === void 0) {
|
|
2077
|
+
rootBoundary = "viewport";
|
|
2078
|
+
}
|
|
2079
|
+
const isLayoutViewport = rootBoundary === "layoutViewport";
|
|
2080
|
+
const win = getWindow(element);
|
|
2081
|
+
const html = getDocumentElement(element);
|
|
2082
|
+
const visualViewport = win.visualViewport;
|
|
2083
|
+
let width = html.clientWidth;
|
|
2084
|
+
let height = html.clientHeight;
|
|
2085
|
+
let x = 0;
|
|
2086
|
+
let y = 0;
|
|
2087
|
+
if (visualViewport) {
|
|
2088
|
+
const layoutRelativeClientCoords = !isWebKit() || strategy === "fixed";
|
|
2089
|
+
if (isLayoutViewport) {
|
|
2090
|
+
if (!layoutRelativeClientCoords) {
|
|
2091
|
+
x = -visualViewport.offsetLeft;
|
|
2092
|
+
y = -visualViewport.offsetTop;
|
|
2093
|
+
}
|
|
2094
|
+
} else {
|
|
2095
|
+
width = visualViewport.width;
|
|
2096
|
+
height = visualViewport.height;
|
|
2097
|
+
if (layoutRelativeClientCoords) {
|
|
2098
|
+
x = visualViewport.offsetLeft;
|
|
2099
|
+
y = visualViewport.offsetTop;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
const windowScrollbarX = getWindowScrollBarX(html);
|
|
2104
|
+
if (windowScrollbarX <= 0) {
|
|
2105
|
+
const doc = html.ownerDocument;
|
|
2106
|
+
const body = doc.body;
|
|
2107
|
+
const bodyStyles = getComputedStyle(body);
|
|
2108
|
+
const bodyMarginInline = doc.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
|
|
2109
|
+
const reservedWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
|
|
2110
|
+
const gutter = getComputedStyle(html).scrollbarGutter === "stable both-edges" ? reservedWidth / 2 : reservedWidth;
|
|
2111
|
+
if (gutter <= SCROLLBAR_MAX) {
|
|
2112
|
+
width -= gutter;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
return {
|
|
2116
|
+
width,
|
|
2117
|
+
height,
|
|
2118
|
+
x,
|
|
2119
|
+
y
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
2123
|
+
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
|
2124
|
+
const top = clientRect.top + element.clientTop;
|
|
2125
|
+
const left = clientRect.left + element.clientLeft;
|
|
2126
|
+
const scale = getScale(element);
|
|
2127
|
+
const width = element.clientWidth * scale.x;
|
|
2128
|
+
const height = element.clientHeight * scale.y;
|
|
2129
|
+
const x = left * scale.x;
|
|
2130
|
+
const y = top * scale.y;
|
|
2131
|
+
return {
|
|
2132
|
+
width,
|
|
2133
|
+
height,
|
|
2134
|
+
x,
|
|
2135
|
+
y
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
2139
|
+
let rect;
|
|
2140
|
+
if (clippingAncestor === "viewport" || clippingAncestor === "layoutViewport") {
|
|
2141
|
+
rect = getViewportRect(element, strategy, clippingAncestor);
|
|
2142
|
+
} else if (clippingAncestor === "document") {
|
|
2143
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
2144
|
+
} else if (isElement(clippingAncestor)) {
|
|
2145
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
2146
|
+
} else {
|
|
2147
|
+
const visualOffsets = getVisualOffsets(element);
|
|
2148
|
+
rect = {
|
|
2149
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
2150
|
+
y: clippingAncestor.y - visualOffsets.y,
|
|
2151
|
+
width: clippingAncestor.width,
|
|
2152
|
+
height: clippingAncestor.height
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
return rectToClientRect(rect);
|
|
2156
|
+
}
|
|
2157
|
+
function getClippingElementAncestors(element, cache) {
|
|
2158
|
+
const cachedResult = cache.get(element);
|
|
2159
|
+
if (cachedResult) {
|
|
2160
|
+
return cachedResult;
|
|
2161
|
+
}
|
|
2162
|
+
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
2163
|
+
let lastKeptComputedStyle = null;
|
|
2164
|
+
const elementIsFixed = getComputedStyle$1(element).position === "fixed";
|
|
2165
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
2166
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
2167
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
2168
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
2169
|
+
const lastPosition = lastKeptComputedStyle ? lastKeptComputedStyle.position : elementIsFixed ? "fixed" : "";
|
|
2170
|
+
const shouldDropCurrentNode = !currentNodeIsContaining && (lastPosition === "fixed" || lastPosition === "absolute" && computedStyle.position === "static");
|
|
2171
|
+
if (shouldDropCurrentNode) {
|
|
2172
|
+
result = result.filter((ancestor) => ancestor !== currentNode);
|
|
2173
|
+
} else {
|
|
2174
|
+
lastKeptComputedStyle = computedStyle;
|
|
2175
|
+
}
|
|
2176
|
+
currentNode = getParentNode(currentNode);
|
|
2177
|
+
}
|
|
2178
|
+
cache.set(element, result);
|
|
2179
|
+
return result;
|
|
2180
|
+
}
|
|
2181
|
+
function getClippingRect(_ref) {
|
|
2182
|
+
let {
|
|
2183
|
+
element,
|
|
2184
|
+
boundary,
|
|
2185
|
+
rootBoundary,
|
|
2186
|
+
strategy
|
|
2187
|
+
} = _ref;
|
|
2188
|
+
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
2189
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
2190
|
+
const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
|
|
2191
|
+
let top = firstRect.top;
|
|
2192
|
+
let right = firstRect.right;
|
|
2193
|
+
let bottom = firstRect.bottom;
|
|
2194
|
+
let left = firstRect.left;
|
|
2195
|
+
for (let i = 1; i < clippingAncestors.length; i++) {
|
|
2196
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
|
|
2197
|
+
top = max(rect.top, top);
|
|
2198
|
+
right = min(rect.right, right);
|
|
2199
|
+
bottom = min(rect.bottom, bottom);
|
|
2200
|
+
left = max(rect.left, left);
|
|
2201
|
+
}
|
|
2202
|
+
return {
|
|
2203
|
+
width: right - left,
|
|
2204
|
+
height: bottom - top,
|
|
2205
|
+
x: left,
|
|
2206
|
+
y: top
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
function getDimensions(element) {
|
|
2210
|
+
const {
|
|
2211
|
+
width,
|
|
2212
|
+
height
|
|
2213
|
+
} = getCssDimensions(element);
|
|
2214
|
+
return {
|
|
2215
|
+
width,
|
|
2216
|
+
height
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
2220
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
2221
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
2222
|
+
const isFixed = strategy === "fixed";
|
|
2223
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
2224
|
+
let scroll = {
|
|
2225
|
+
scrollLeft: 0,
|
|
2226
|
+
scrollTop: 0
|
|
2227
|
+
};
|
|
2228
|
+
const offsets = createCoords(0);
|
|
2229
|
+
if (isOffsetParentAnElement || !isFixed) {
|
|
2230
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
2231
|
+
scroll = getNodeScroll(offsetParent);
|
|
2232
|
+
}
|
|
2233
|
+
if (isOffsetParentAnElement) {
|
|
2234
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
2235
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
2236
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
if (!isOffsetParentAnElement && documentElement) {
|
|
2240
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
2241
|
+
}
|
|
2242
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
2243
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
|
|
2244
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
|
|
2245
|
+
return {
|
|
2246
|
+
x,
|
|
2247
|
+
y,
|
|
2248
|
+
width: rect.width,
|
|
2249
|
+
height: rect.height
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
function isStaticPositioned(element) {
|
|
2253
|
+
return getComputedStyle$1(element).position === "static";
|
|
2254
|
+
}
|
|
2255
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
2256
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
|
|
2257
|
+
return null;
|
|
2258
|
+
}
|
|
2259
|
+
if (polyfill) {
|
|
2260
|
+
return polyfill(element);
|
|
2261
|
+
}
|
|
2262
|
+
let rawOffsetParent = element.offsetParent;
|
|
2263
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
2264
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
2265
|
+
}
|
|
2266
|
+
return rawOffsetParent;
|
|
2267
|
+
}
|
|
2268
|
+
function getOffsetParent(element, polyfill) {
|
|
2269
|
+
const win = getWindow(element);
|
|
2270
|
+
if (isTopLayer(element)) {
|
|
2271
|
+
return win;
|
|
2272
|
+
}
|
|
2273
|
+
if (!isHTMLElement(element)) {
|
|
2274
|
+
let svgOffsetParent = getParentNode(element);
|
|
2275
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
2276
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
2277
|
+
return svgOffsetParent;
|
|
2278
|
+
}
|
|
2279
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
2280
|
+
}
|
|
2281
|
+
return win;
|
|
2282
|
+
}
|
|
2283
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
2284
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
2285
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
2286
|
+
}
|
|
2287
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
2288
|
+
return win;
|
|
2289
|
+
}
|
|
2290
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
2291
|
+
}
|
|
2292
|
+
const getElementRects = async function(data) {
|
|
2293
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
2294
|
+
const getDimensionsFn = this.getDimensions;
|
|
2295
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
2296
|
+
return {
|
|
2297
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
2298
|
+
floating: {
|
|
2299
|
+
x: 0,
|
|
2300
|
+
y: 0,
|
|
2301
|
+
width: floatingDimensions.width,
|
|
2302
|
+
height: floatingDimensions.height
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
};
|
|
2306
|
+
function isRTL(element) {
|
|
2307
|
+
return getComputedStyle$1(element).direction === "rtl";
|
|
2308
|
+
}
|
|
2309
|
+
const platform = {
|
|
2310
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
2311
|
+
getDocumentElement,
|
|
2312
|
+
getClippingRect,
|
|
2313
|
+
getOffsetParent,
|
|
2314
|
+
getElementRects,
|
|
2315
|
+
getClientRects,
|
|
2316
|
+
getDimensions,
|
|
2317
|
+
getScale,
|
|
2318
|
+
isElement,
|
|
2319
|
+
isRTL
|
|
2320
|
+
};
|
|
2321
|
+
function rectsAreEqual(a, b) {
|
|
2322
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
2323
|
+
}
|
|
2324
|
+
function observeMove(element, onMove, ancestorResize) {
|
|
2325
|
+
let io = null;
|
|
2326
|
+
let timeoutId;
|
|
2327
|
+
const root = getDocumentElement(element);
|
|
2328
|
+
function cleanup() {
|
|
2329
|
+
var _io;
|
|
2330
|
+
clearTimeout(timeoutId);
|
|
2331
|
+
(_io = io) == null || _io.disconnect();
|
|
2332
|
+
io = null;
|
|
2333
|
+
}
|
|
2334
|
+
function refresh(skip, threshold) {
|
|
2335
|
+
if (skip === void 0) {
|
|
2336
|
+
skip = false;
|
|
2337
|
+
}
|
|
2338
|
+
if (threshold === void 0) {
|
|
2339
|
+
threshold = 1;
|
|
2340
|
+
}
|
|
2341
|
+
cleanup();
|
|
2342
|
+
const elementRectForRootMargin = element.getBoundingClientRect();
|
|
2343
|
+
const {
|
|
2344
|
+
left,
|
|
2345
|
+
top,
|
|
2346
|
+
width,
|
|
2347
|
+
height
|
|
2348
|
+
} = elementRectForRootMargin;
|
|
2349
|
+
if (!skip) {
|
|
2350
|
+
onMove();
|
|
2351
|
+
}
|
|
2352
|
+
if (!width || !height) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
const insetTop = floor(top);
|
|
2356
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
2357
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
2358
|
+
const insetLeft = floor(left);
|
|
2359
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
2360
|
+
const options = {
|
|
2361
|
+
rootMargin,
|
|
2362
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
2363
|
+
};
|
|
2364
|
+
let isFirstUpdate = true;
|
|
2365
|
+
function handleObserve(entries) {
|
|
2366
|
+
const ratio = entries[0].intersectionRatio;
|
|
2367
|
+
if (!rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
|
|
2368
|
+
return refresh();
|
|
2369
|
+
}
|
|
2370
|
+
if (ratio !== threshold) {
|
|
2371
|
+
if (!isFirstUpdate) {
|
|
2372
|
+
return refresh();
|
|
2373
|
+
}
|
|
2374
|
+
if (!ratio) {
|
|
2375
|
+
timeoutId = setTimeout(() => {
|
|
2376
|
+
refresh(false, 1e-7);
|
|
2377
|
+
}, 1e3);
|
|
2378
|
+
} else {
|
|
2379
|
+
refresh(false, ratio);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
isFirstUpdate = false;
|
|
2383
|
+
}
|
|
2384
|
+
try {
|
|
2385
|
+
io = new IntersectionObserver(handleObserve, {
|
|
2386
|
+
...options,
|
|
2387
|
+
// Handle <iframe>s
|
|
2388
|
+
root: root.ownerDocument
|
|
2389
|
+
});
|
|
2390
|
+
} catch (_e) {
|
|
2391
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
2392
|
+
}
|
|
2393
|
+
io.observe(element);
|
|
2394
|
+
}
|
|
2395
|
+
const win = getWindow(element);
|
|
2396
|
+
const handleResize = () => refresh(ancestorResize);
|
|
2397
|
+
win.addEventListener("resize", handleResize);
|
|
2398
|
+
refresh(true);
|
|
2399
|
+
return () => {
|
|
2400
|
+
win.removeEventListener("resize", handleResize);
|
|
2401
|
+
cleanup();
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
function autoUpdate(reference, floating, update, options) {
|
|
2405
|
+
if (options === void 0) {
|
|
2406
|
+
options = {};
|
|
2407
|
+
}
|
|
2408
|
+
const {
|
|
2409
|
+
ancestorScroll = true,
|
|
2410
|
+
ancestorResize = true,
|
|
2411
|
+
elementResize = typeof ResizeObserver === "function",
|
|
2412
|
+
layoutShift = typeof IntersectionObserver === "function",
|
|
2413
|
+
animationFrame = false
|
|
2414
|
+
} = options;
|
|
2415
|
+
const referenceEl = unwrapElement(reference);
|
|
2416
|
+
const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...floating ? getOverflowAncestors(floating) : []] : [];
|
|
2417
|
+
ancestors.forEach((ancestor) => {
|
|
2418
|
+
ancestorScroll && ancestor.addEventListener("scroll", update);
|
|
2419
|
+
ancestorResize && ancestor.addEventListener("resize", update);
|
|
2420
|
+
});
|
|
2421
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update, ancestorResize) : null;
|
|
2422
|
+
let reobserveFrame = -1;
|
|
2423
|
+
let resizeObserver = null;
|
|
2424
|
+
if (elementResize) {
|
|
2425
|
+
resizeObserver = new ResizeObserver((_ref) => {
|
|
2426
|
+
let [firstEntry] = _ref;
|
|
2427
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
|
|
2428
|
+
resizeObserver.unobserve(floating);
|
|
2429
|
+
cancelAnimationFrame(reobserveFrame);
|
|
2430
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
2431
|
+
var _resizeObserver;
|
|
2432
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
update();
|
|
2436
|
+
});
|
|
2437
|
+
if (referenceEl && !animationFrame) {
|
|
2438
|
+
resizeObserver.observe(referenceEl);
|
|
2439
|
+
}
|
|
2440
|
+
if (floating) {
|
|
2441
|
+
resizeObserver.observe(floating);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
let frameId;
|
|
2445
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
2446
|
+
if (animationFrame) {
|
|
2447
|
+
frameLoop();
|
|
2448
|
+
}
|
|
2449
|
+
function frameLoop() {
|
|
2450
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
2451
|
+
if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
|
|
2452
|
+
update();
|
|
2453
|
+
}
|
|
2454
|
+
prevRefRect = nextRefRect;
|
|
2455
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
2456
|
+
}
|
|
2457
|
+
update();
|
|
2458
|
+
return () => {
|
|
2459
|
+
var _resizeObserver2;
|
|
2460
|
+
ancestors.forEach((ancestor) => {
|
|
2461
|
+
ancestorScroll && ancestor.removeEventListener("scroll", update);
|
|
2462
|
+
ancestorResize && ancestor.removeEventListener("resize", update);
|
|
2463
|
+
});
|
|
2464
|
+
cleanupIo == null || cleanupIo();
|
|
2465
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
2466
|
+
resizeObserver = null;
|
|
2467
|
+
if (animationFrame) {
|
|
2468
|
+
cancelAnimationFrame(frameId);
|
|
2469
|
+
}
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
const offset$1 = offset$2;
|
|
2473
|
+
const shift$1 = shift$2;
|
|
2474
|
+
const flip$1 = flip$2;
|
|
2475
|
+
const size$1 = size$2;
|
|
2476
|
+
const limitShift$1 = limitShift$2;
|
|
2477
|
+
const computePosition = (reference, floating, options) => {
|
|
2478
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2479
|
+
const mergedOptions = options != null ? options : {};
|
|
2480
|
+
const platformWithCache = {
|
|
2481
|
+
...platform,
|
|
2482
|
+
...mergedOptions.platform,
|
|
2483
|
+
_c: cache
|
|
2484
|
+
};
|
|
2485
|
+
return computePosition$1(reference, floating, {
|
|
2486
|
+
...mergedOptions,
|
|
2487
|
+
platform: platformWithCache
|
|
2488
|
+
});
|
|
2489
|
+
};
|
|
2490
|
+
var isClient = typeof document !== "undefined";
|
|
2491
|
+
var noop = function noop2() {
|
|
2492
|
+
};
|
|
2493
|
+
var index = isClient ? useLayoutEffect : noop;
|
|
2494
|
+
function deepEqual(a, b) {
|
|
2495
|
+
if (a === b) {
|
|
2496
|
+
return true;
|
|
2497
|
+
}
|
|
2498
|
+
if (typeof a !== typeof b) {
|
|
2499
|
+
return false;
|
|
2500
|
+
}
|
|
2501
|
+
if (typeof a === "function" && a.toString() === b.toString()) {
|
|
2502
|
+
return true;
|
|
2503
|
+
}
|
|
2504
|
+
let length;
|
|
2505
|
+
let i;
|
|
2506
|
+
let keys;
|
|
2507
|
+
if (a && b && typeof a === "object") {
|
|
2508
|
+
if (Array.isArray(a)) {
|
|
2509
|
+
length = a.length;
|
|
2510
|
+
if (length !== b.length) return false;
|
|
2511
|
+
for (i = length; i-- !== 0; ) {
|
|
2512
|
+
if (!deepEqual(a[i], b[i])) {
|
|
2513
|
+
return false;
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
return true;
|
|
2517
|
+
}
|
|
2518
|
+
keys = Object.keys(a);
|
|
2519
|
+
length = keys.length;
|
|
2520
|
+
if (length !== Object.keys(b).length) {
|
|
2521
|
+
return false;
|
|
2522
|
+
}
|
|
2523
|
+
for (i = length; i-- !== 0; ) {
|
|
2524
|
+
if (!{}.hasOwnProperty.call(b, keys[i])) {
|
|
2525
|
+
return false;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
for (i = length; i-- !== 0; ) {
|
|
2529
|
+
const key = keys[i];
|
|
2530
|
+
if (key === "_owner" && a.$$typeof) {
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
if (!deepEqual(a[key], b[key])) {
|
|
2534
|
+
return false;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
return true;
|
|
2538
|
+
}
|
|
2539
|
+
return a !== a && b !== b;
|
|
2540
|
+
}
|
|
2541
|
+
function getDPR(element) {
|
|
2542
|
+
if (typeof window === "undefined") {
|
|
2543
|
+
return 1;
|
|
2544
|
+
}
|
|
2545
|
+
const win = element.ownerDocument.defaultView || window;
|
|
2546
|
+
return win.devicePixelRatio || 1;
|
|
2547
|
+
}
|
|
2548
|
+
function roundByDPR(element, value) {
|
|
2549
|
+
const dpr = getDPR(element);
|
|
2550
|
+
return Math.round(value * dpr) / dpr;
|
|
2551
|
+
}
|
|
2552
|
+
function useLatestRef(value) {
|
|
2553
|
+
const ref = React.useRef(value);
|
|
2554
|
+
index(() => {
|
|
2555
|
+
ref.current = value;
|
|
2556
|
+
});
|
|
2557
|
+
return ref;
|
|
2558
|
+
}
|
|
2559
|
+
function useFloating(options) {
|
|
2560
|
+
if (options === void 0) {
|
|
2561
|
+
options = {};
|
|
2562
|
+
}
|
|
2563
|
+
const {
|
|
2564
|
+
placement = "bottom",
|
|
2565
|
+
strategy = "absolute",
|
|
2566
|
+
middleware = [],
|
|
2567
|
+
platform: platform2,
|
|
2568
|
+
elements: {
|
|
2569
|
+
reference: externalReference,
|
|
2570
|
+
floating: externalFloating
|
|
2571
|
+
} = {},
|
|
2572
|
+
transform = true,
|
|
2573
|
+
whileElementsMounted,
|
|
2574
|
+
open
|
|
2575
|
+
} = options;
|
|
2576
|
+
const [data, setData] = React.useState({
|
|
2577
|
+
x: 0,
|
|
2578
|
+
y: 0,
|
|
2579
|
+
strategy,
|
|
2580
|
+
placement,
|
|
2581
|
+
middlewareData: {},
|
|
2582
|
+
isPositioned: false
|
|
2583
|
+
});
|
|
2584
|
+
const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
|
|
2585
|
+
if (!deepEqual(latestMiddleware, middleware)) {
|
|
2586
|
+
setLatestMiddleware(middleware);
|
|
2587
|
+
}
|
|
2588
|
+
const [_reference, _setReference] = React.useState(null);
|
|
2589
|
+
const [_floating, _setFloating] = React.useState(null);
|
|
2590
|
+
const setReference = React.useCallback((node) => {
|
|
2591
|
+
if (node !== referenceRef.current) {
|
|
2592
|
+
referenceRef.current = node;
|
|
2593
|
+
_setReference(node);
|
|
2594
|
+
}
|
|
2595
|
+
}, []);
|
|
2596
|
+
const setFloating = React.useCallback((node) => {
|
|
2597
|
+
if (node !== floatingRef.current) {
|
|
2598
|
+
floatingRef.current = node;
|
|
2599
|
+
_setFloating(node);
|
|
2600
|
+
}
|
|
2601
|
+
}, []);
|
|
2602
|
+
const referenceEl = externalReference || _reference;
|
|
2603
|
+
const floatingEl = externalFloating || _floating;
|
|
2604
|
+
const referenceRef = React.useRef(null);
|
|
2605
|
+
const floatingRef = React.useRef(null);
|
|
2606
|
+
const dataRef = React.useRef(data);
|
|
2607
|
+
const hasWhileElementsMounted = whileElementsMounted != null;
|
|
2608
|
+
const whileElementsMountedRef = useLatestRef(whileElementsMounted);
|
|
2609
|
+
const platformRef = useLatestRef(platform2);
|
|
2610
|
+
const openRef = useLatestRef(open);
|
|
2611
|
+
const update = React.useCallback(() => {
|
|
2612
|
+
if (!referenceRef.current || !floatingRef.current) {
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
const config = {
|
|
2616
|
+
placement,
|
|
2617
|
+
strategy,
|
|
2618
|
+
middleware: latestMiddleware
|
|
2619
|
+
};
|
|
2620
|
+
if (platformRef.current) {
|
|
2621
|
+
config.platform = platformRef.current;
|
|
2622
|
+
}
|
|
2623
|
+
computePosition(referenceRef.current, floatingRef.current, config).then((data2) => {
|
|
2624
|
+
const fullData = {
|
|
2625
|
+
...data2,
|
|
2626
|
+
// The floating element's position may be recomputed while it's closed
|
|
2627
|
+
// but still mounted (such as when transitioning out). To ensure
|
|
2628
|
+
// `isPositioned` will be `false` initially on the next open, avoid
|
|
2629
|
+
// setting it to `true` when `open === false` (must be specified).
|
|
2630
|
+
isPositioned: openRef.current !== false
|
|
2631
|
+
};
|
|
2632
|
+
if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
|
|
2633
|
+
dataRef.current = fullData;
|
|
2634
|
+
ReactDOM.flushSync(() => {
|
|
2635
|
+
setData(fullData);
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
});
|
|
2639
|
+
}, [latestMiddleware, placement, strategy, platformRef, openRef]);
|
|
2640
|
+
index(() => {
|
|
2641
|
+
if (open === false && dataRef.current.isPositioned) {
|
|
2642
|
+
dataRef.current.isPositioned = false;
|
|
2643
|
+
setData((data2) => ({
|
|
2644
|
+
...data2,
|
|
2645
|
+
isPositioned: false
|
|
2646
|
+
}));
|
|
2647
|
+
}
|
|
2648
|
+
}, [open]);
|
|
2649
|
+
const isMountedRef = React.useRef(false);
|
|
2650
|
+
index(() => {
|
|
2651
|
+
isMountedRef.current = true;
|
|
2652
|
+
return () => {
|
|
2653
|
+
isMountedRef.current = false;
|
|
2654
|
+
};
|
|
2655
|
+
}, []);
|
|
2656
|
+
index(() => {
|
|
2657
|
+
if (referenceEl) referenceRef.current = referenceEl;
|
|
2658
|
+
if (floatingEl) floatingRef.current = floatingEl;
|
|
2659
|
+
if (referenceEl && floatingEl) {
|
|
2660
|
+
if (whileElementsMountedRef.current) {
|
|
2661
|
+
return whileElementsMountedRef.current(referenceEl, floatingEl, update);
|
|
2662
|
+
}
|
|
2663
|
+
update();
|
|
2664
|
+
}
|
|
2665
|
+
}, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
|
|
2666
|
+
const refs = React.useMemo(() => ({
|
|
2667
|
+
reference: referenceRef,
|
|
2668
|
+
floating: floatingRef,
|
|
2669
|
+
setReference,
|
|
2670
|
+
setFloating
|
|
2671
|
+
}), [setReference, setFloating]);
|
|
2672
|
+
const elements = React.useMemo(() => ({
|
|
2673
|
+
reference: referenceEl,
|
|
2674
|
+
floating: floatingEl
|
|
2675
|
+
}), [referenceEl, floatingEl]);
|
|
2676
|
+
const floatingStyles = React.useMemo(() => {
|
|
2677
|
+
const initialStyles = {
|
|
2678
|
+
position: strategy,
|
|
2679
|
+
left: 0,
|
|
2680
|
+
top: 0
|
|
2681
|
+
};
|
|
2682
|
+
if (!elements.floating) {
|
|
2683
|
+
return initialStyles;
|
|
2684
|
+
}
|
|
2685
|
+
const x = roundByDPR(elements.floating, data.x);
|
|
2686
|
+
const y = roundByDPR(elements.floating, data.y);
|
|
2687
|
+
if (transform) {
|
|
2688
|
+
return {
|
|
2689
|
+
...initialStyles,
|
|
2690
|
+
transform: "translate(" + x + "px, " + y + "px)",
|
|
2691
|
+
...getDPR(elements.floating) >= 1.5 && {
|
|
2692
|
+
willChange: "transform"
|
|
2693
|
+
}
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
return {
|
|
2697
|
+
position: strategy,
|
|
2698
|
+
left: x,
|
|
2699
|
+
top: y
|
|
2700
|
+
};
|
|
2701
|
+
}, [strategy, transform, elements.floating, data.x, data.y]);
|
|
2702
|
+
return React.useMemo(() => ({
|
|
2703
|
+
...data,
|
|
2704
|
+
update,
|
|
2705
|
+
refs,
|
|
2706
|
+
elements,
|
|
2707
|
+
floatingStyles
|
|
2708
|
+
}), [data, update, refs, elements, floatingStyles]);
|
|
2709
|
+
}
|
|
2710
|
+
const offset = (options, deps) => {
|
|
2711
|
+
const result = offset$1(options);
|
|
2712
|
+
return {
|
|
2713
|
+
name: result.name,
|
|
2714
|
+
fn: result.fn,
|
|
2715
|
+
options: [options, deps]
|
|
2716
|
+
};
|
|
2717
|
+
};
|
|
2718
|
+
const shift = (options, deps) => {
|
|
2719
|
+
const result = shift$1(options);
|
|
2720
|
+
return {
|
|
2721
|
+
name: result.name,
|
|
2722
|
+
fn: result.fn,
|
|
2723
|
+
options: [options, deps]
|
|
2724
|
+
};
|
|
2725
|
+
};
|
|
2726
|
+
const limitShift = (options, deps) => {
|
|
2727
|
+
const result = limitShift$1(options);
|
|
2728
|
+
return {
|
|
2729
|
+
fn: result.fn,
|
|
2730
|
+
options: [options, deps]
|
|
2731
|
+
};
|
|
2732
|
+
};
|
|
2733
|
+
const flip = (options, deps) => {
|
|
2734
|
+
const result = flip$1(options);
|
|
2735
|
+
return {
|
|
2736
|
+
name: result.name,
|
|
2737
|
+
fn: result.fn,
|
|
2738
|
+
options: [options, deps]
|
|
2739
|
+
};
|
|
2740
|
+
};
|
|
2741
|
+
const size = (options, deps) => {
|
|
2742
|
+
const result = size$1(options);
|
|
2743
|
+
return {
|
|
2744
|
+
name: result.name,
|
|
2745
|
+
fn: result.fn,
|
|
2746
|
+
options: [options, deps]
|
|
2747
|
+
};
|
|
2748
|
+
};
|
|
2749
|
+
const TooltipRootContext = /* @__PURE__ */ React.createContext(void 0);
|
|
2750
|
+
if (process.env.NODE_ENV !== "production") TooltipRootContext.displayName = "TooltipRootContext";
|
|
2751
|
+
function useTooltipRootContext(optional) {
|
|
2752
|
+
const context = React.useContext(TooltipRootContext);
|
|
2753
|
+
if (context === void 0 && !optional) {
|
|
2754
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: TooltipRootContext is missing. Tooltip parts must be placed within <Tooltip.Root>." : formatErrorMessage(72));
|
|
2755
|
+
}
|
|
2756
|
+
return context;
|
|
2757
|
+
}
|
|
2758
|
+
const selectors = {
|
|
2759
|
+
...popupStoreSelectors,
|
|
2760
|
+
disabled: (state) => state.disabled,
|
|
2761
|
+
instantType: (state) => state.instantType,
|
|
2762
|
+
isInstantPhase: (state) => state.isInstantPhase,
|
|
2763
|
+
trackCursorAxis: (state) => state.trackCursorAxis,
|
|
2764
|
+
disableHoverablePopup: (state) => state.disableHoverablePopup,
|
|
2765
|
+
lastOpenChangeReason: (state) => state.openChangeReason,
|
|
2766
|
+
closeOnClick: (state) => state.closeOnClick,
|
|
2767
|
+
// Active and inactive trigger props are the same object, so a constant for triggers that discard
|
|
2768
|
+
// them keeps those triggers from re-rendering when the props change.
|
|
2769
|
+
appliedTriggerProps: (state, apply) => apply ? state.activeTriggerProps : void 0,
|
|
2770
|
+
closeDelay: (state) => state.closeDelay,
|
|
2771
|
+
adaptiveOrigin: (state) => state.adaptiveOrigin
|
|
2772
|
+
};
|
|
2773
|
+
class TooltipStore extends ReactStore {
|
|
2774
|
+
constructor(initialState, floatingId, nested) {
|
|
2775
|
+
const triggerElements = new PopupTriggerMap();
|
|
2776
|
+
super(createInitialState(initialState, triggerElements, floatingId, nested), createInitialContext(triggerElements), selectors);
|
|
2777
|
+
__publicField(this, "setOpen", (nextOpen, eventDetails) => {
|
|
2778
|
+
applyPopupOpenChange(this, nextOpen, eventDetails, {
|
|
2779
|
+
extraState: {
|
|
2780
|
+
openChangeReason: eventDetails.reason
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
// Used by trigger clicks to clear a delayed hover open without reporting a public open-state change.
|
|
2786
|
+
cancelPendingOpen(event) {
|
|
2787
|
+
this.state.floatingRootContext.dispatchOpenChange(false, createChangeEventDetails(triggerPress, event));
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
function createInitialState(initialState, triggerElements, floatingId, nested = false) {
|
|
2791
|
+
const state = {
|
|
2792
|
+
...createInitialPopupStoreState(triggerElements, floatingId, nested),
|
|
2793
|
+
disabled: false,
|
|
2794
|
+
instantType: void 0,
|
|
2795
|
+
isInstantPhase: false,
|
|
2796
|
+
trackCursorAxis: "none",
|
|
2797
|
+
disableHoverablePopup: false,
|
|
2798
|
+
openChangeReason: null,
|
|
2799
|
+
closeOnClick: true,
|
|
2800
|
+
closeDelay: 0,
|
|
2801
|
+
adaptiveOrigin: void 0,
|
|
2802
|
+
...initialState
|
|
2803
|
+
};
|
|
2804
|
+
return state;
|
|
2805
|
+
}
|
|
2806
|
+
function createInitialContext(triggerElements) {
|
|
2807
|
+
return {
|
|
2808
|
+
popupRef: /* @__PURE__ */ React.createRef(),
|
|
2809
|
+
onOpenChange: void 0,
|
|
2810
|
+
onOpenChangeComplete: void 0,
|
|
2811
|
+
triggerElements
|
|
2812
|
+
};
|
|
2813
|
+
}
|
|
2814
|
+
const TooltipRoot = fastComponent(function TooltipRoot2(props) {
|
|
2815
|
+
const {
|
|
2816
|
+
disabled: disabled$1 = false,
|
|
2817
|
+
defaultOpen = false,
|
|
2818
|
+
open: openProp,
|
|
2819
|
+
disableHoverablePopup = false,
|
|
2820
|
+
trackCursorAxis = "none",
|
|
2821
|
+
actionsRef,
|
|
2822
|
+
onOpenChange,
|
|
2823
|
+
onOpenChangeComplete,
|
|
2824
|
+
handle,
|
|
2825
|
+
triggerId: triggerIdProp,
|
|
2826
|
+
defaultTriggerId: defaultTriggerIdProp = null,
|
|
2827
|
+
children
|
|
2828
|
+
} = props;
|
|
2829
|
+
const store = usePopupRootStore((floatingId, nested) => new TooltipStore({
|
|
2830
|
+
open: defaultOpen,
|
|
2831
|
+
openProp,
|
|
2832
|
+
activeTriggerId: defaultTriggerIdProp,
|
|
2833
|
+
triggerIdProp
|
|
2834
|
+
}, floatingId, nested));
|
|
2835
|
+
store.useControlledProp("openProp", openProp);
|
|
2836
|
+
store.useControlledProp("triggerIdProp", triggerIdProp);
|
|
2837
|
+
store.useContextCallback("onOpenChange", onOpenChange);
|
|
2838
|
+
store.useContextCallback("onOpenChangeComplete", onOpenChangeComplete);
|
|
2839
|
+
const openState = store.useState("open");
|
|
2840
|
+
const open = !disabled$1 && openState;
|
|
2841
|
+
const activeTriggerId = store.useState("activeTriggerId");
|
|
2842
|
+
const mounted = store.useState("mounted");
|
|
2843
|
+
const payload = store.useState("payload");
|
|
2844
|
+
store.useSyncedValues({
|
|
2845
|
+
trackCursorAxis,
|
|
2846
|
+
disableHoverablePopup,
|
|
2847
|
+
disabled: disabled$1
|
|
2848
|
+
});
|
|
2849
|
+
useImplicitActiveTrigger(store, {
|
|
2850
|
+
closeOnActiveTriggerUnmount: true
|
|
2851
|
+
});
|
|
2852
|
+
const {
|
|
2853
|
+
forceUnmount,
|
|
2854
|
+
transitionStatus
|
|
2855
|
+
} = useOpenStateTransitions(open, store);
|
|
2856
|
+
const isInstantPhase = store.useState("isInstantPhase");
|
|
2857
|
+
const instantType = store.useState("instantType");
|
|
2858
|
+
const lastOpenChangeReason = store.useState("lastOpenChangeReason");
|
|
2859
|
+
const previousInstantTypeRef = React.useRef(null);
|
|
2860
|
+
useIsoLayoutEffect(() => {
|
|
2861
|
+
if (openState && disabled$1) {
|
|
2862
|
+
store.setOpen(false, createChangeEventDetails(disabled));
|
|
2863
|
+
}
|
|
2864
|
+
}, [openState, disabled$1, store]);
|
|
2865
|
+
useIsoLayoutEffect(() => {
|
|
2866
|
+
if (transitionStatus === "ending" && lastOpenChangeReason === none || transitionStatus !== "ending" && isInstantPhase) {
|
|
2867
|
+
if (instantType !== "delay") {
|
|
2868
|
+
previousInstantTypeRef.current = instantType;
|
|
2869
|
+
}
|
|
2870
|
+
store.set("instantType", "delay");
|
|
2871
|
+
} else if (previousInstantTypeRef.current !== null) {
|
|
2872
|
+
store.set("instantType", previousInstantTypeRef.current);
|
|
2873
|
+
previousInstantTypeRef.current = null;
|
|
2874
|
+
}
|
|
2875
|
+
}, [transitionStatus, isInstantPhase, lastOpenChangeReason, instantType, store]);
|
|
2876
|
+
useIsoLayoutEffect(() => {
|
|
2877
|
+
if (open) {
|
|
2878
|
+
if (activeTriggerId == null) {
|
|
2879
|
+
store.set("payload", void 0);
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
}, [store, activeTriggerId, open]);
|
|
2883
|
+
React.useImperativeHandle(actionsRef, () => ({
|
|
2884
|
+
unmount: forceUnmount,
|
|
2885
|
+
close: () => store.setOpen(false, createChangeEventDetails(imperativeAction))
|
|
2886
|
+
}), [forceUnmount, store]);
|
|
2887
|
+
const shouldRenderInteractions = open || mounted || !disabled$1 && trackCursorAxis !== "none";
|
|
2888
|
+
return /* @__PURE__ */ jsxs(TooltipRootContext.Provider, {
|
|
2889
|
+
value: store,
|
|
2890
|
+
children: [handle && /* @__PURE__ */ jsx(PopupHandleAttachment, {
|
|
2891
|
+
handle,
|
|
2892
|
+
store
|
|
2893
|
+
}), shouldRenderInteractions && /* @__PURE__ */ jsx(TooltipInteractions, {
|
|
2894
|
+
store,
|
|
2895
|
+
disabled: disabled$1,
|
|
2896
|
+
trackCursorAxis
|
|
2897
|
+
}), typeof children === "function" ? children({
|
|
2898
|
+
payload
|
|
2899
|
+
}) : children]
|
|
2900
|
+
});
|
|
2901
|
+
});
|
|
2902
|
+
if (process.env.NODE_ENV !== "production") TooltipRoot.displayName = "TooltipRoot";
|
|
2903
|
+
function TooltipInteractions({
|
|
2904
|
+
store,
|
|
2905
|
+
disabled: disabled2,
|
|
2906
|
+
trackCursorAxis
|
|
2907
|
+
}) {
|
|
2908
|
+
const floatingRootContext = store.useState("floatingRootContext");
|
|
2909
|
+
const dismiss = useDismiss(floatingRootContext, {
|
|
2910
|
+
enabled: !disabled2,
|
|
2911
|
+
referencePress: () => store.select("closeOnClick")
|
|
2912
|
+
});
|
|
2913
|
+
const clientPoint = useClientPoint(floatingRootContext, {
|
|
2914
|
+
enabled: !disabled2 && trackCursorAxis !== "none",
|
|
2915
|
+
axis: trackCursorAxis === "none" ? void 0 : trackCursorAxis
|
|
2916
|
+
});
|
|
2917
|
+
const triggerProps = React.useMemo(() => mergeProps(clientPoint.reference, dismiss.reference), [clientPoint.reference, dismiss.reference]);
|
|
2918
|
+
usePopupInteractionProps(store, {
|
|
2919
|
+
activeTriggerProps: triggerProps,
|
|
2920
|
+
inactiveTriggerProps: triggerProps,
|
|
2921
|
+
popupProps: dismiss.floating ?? EMPTY_OBJECT
|
|
2922
|
+
});
|
|
2923
|
+
return null;
|
|
2924
|
+
}
|
|
2925
|
+
const TooltipProviderContext = /* @__PURE__ */ React.createContext(void 0);
|
|
2926
|
+
if (process.env.NODE_ENV !== "production") TooltipProviderContext.displayName = "TooltipProviderContext";
|
|
2927
|
+
function useTooltipProviderContext() {
|
|
2928
|
+
return React.useContext(TooltipProviderContext);
|
|
2929
|
+
}
|
|
2930
|
+
const OPEN_DELAY = 600;
|
|
2931
|
+
const TOOLTIP_TRIGGER_IDENTIFIER = "data-base-ui-tooltip-trigger";
|
|
2932
|
+
function getTargetElement(event) {
|
|
2933
|
+
const target = getTarget(event);
|
|
2934
|
+
return isElement(target) ? target : null;
|
|
2935
|
+
}
|
|
2936
|
+
const TooltipTrigger$1 = fastComponentRef(function TooltipTrigger(componentProps, forwardedRef) {
|
|
2937
|
+
const {
|
|
2938
|
+
render,
|
|
2939
|
+
className,
|
|
2940
|
+
style,
|
|
2941
|
+
handle,
|
|
2942
|
+
payload,
|
|
2943
|
+
disabled: disabledProp,
|
|
2944
|
+
delay,
|
|
2945
|
+
closeOnClick = true,
|
|
2946
|
+
closeDelay,
|
|
2947
|
+
id: idProp,
|
|
2948
|
+
...elementProps
|
|
2949
|
+
} = componentProps;
|
|
2950
|
+
const rootContext = useTooltipRootContext(true);
|
|
2951
|
+
const handleStore = usePopupHandleStore(handle);
|
|
2952
|
+
const store = handleStore ?? rootContext;
|
|
2953
|
+
if (!store) {
|
|
2954
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Tooltip.Trigger> must be either used within a <Tooltip.Root> component or provided with a handle." : formatErrorMessage(82));
|
|
2955
|
+
}
|
|
2956
|
+
const thisTriggerId = useBaseUiId(idProp);
|
|
2957
|
+
const isTriggerActive = store.useState("isTriggerActive", thisTriggerId);
|
|
2958
|
+
const isOpenedByThisTrigger = store.useState("isOpenedByTrigger", thisTriggerId);
|
|
2959
|
+
const floatingRootContext = store.useState("floatingRootContext");
|
|
2960
|
+
const triggerElementRef = React.useRef(null);
|
|
2961
|
+
const closeDelayWithDefault = closeDelay ?? 0;
|
|
2962
|
+
const {
|
|
2963
|
+
registerTrigger,
|
|
2964
|
+
isMountedByThisTrigger
|
|
2965
|
+
} = useTriggerDataForwarding(thisTriggerId, triggerElementRef, store, {
|
|
2966
|
+
payload,
|
|
2967
|
+
closeOnClick,
|
|
2968
|
+
closeDelay: closeDelayWithDefault
|
|
2969
|
+
});
|
|
2970
|
+
const providerDelay = useTooltipProviderContext();
|
|
2971
|
+
const {
|
|
2972
|
+
activeIdRef,
|
|
2973
|
+
delayRef,
|
|
2974
|
+
isInstantPhase,
|
|
2975
|
+
hasProvider
|
|
2976
|
+
} = useDelayGroup(floatingRootContext, {
|
|
2977
|
+
open: isOpenedByThisTrigger
|
|
2978
|
+
});
|
|
2979
|
+
const hoverInteraction = useHoverInteractionSharedState(floatingRootContext);
|
|
2980
|
+
store.useSyncedValue("isInstantPhase", isInstantPhase);
|
|
2981
|
+
const rootDisabled = store.useState("disabled");
|
|
2982
|
+
const disabled2 = disabledProp ?? rootDisabled;
|
|
2983
|
+
const disabledRef = useValueAsRef(disabled2);
|
|
2984
|
+
const trackCursorAxis = store.useState("trackCursorAxis");
|
|
2985
|
+
const disableHoverablePopup = store.useState("disableHoverablePopup");
|
|
2986
|
+
const isNestedTriggerHoveredRef = React.useRef(false);
|
|
2987
|
+
const nestedTriggerOpenTimeout = useTimeout();
|
|
2988
|
+
const pointerTypeRef = React.useRef(void 0);
|
|
2989
|
+
function getOpenDelay() {
|
|
2990
|
+
if (hasProvider && activeIdRef.current != null) {
|
|
2991
|
+
return 0;
|
|
2992
|
+
}
|
|
2993
|
+
return delay ?? providerDelay ?? OPEN_DELAY;
|
|
2994
|
+
}
|
|
2995
|
+
function isEnabledNestedTriggerTarget(target) {
|
|
2996
|
+
const triggerEl = triggerElementRef.current;
|
|
2997
|
+
if (!triggerEl || !target) {
|
|
2998
|
+
return false;
|
|
2999
|
+
}
|
|
3000
|
+
const nearestTrigger = closest(target, `[${TOOLTIP_TRIGGER_IDENTIFIER}]`);
|
|
3001
|
+
return nearestTrigger !== null && nearestTrigger !== triggerEl && contains(triggerEl, nearestTrigger);
|
|
3002
|
+
}
|
|
3003
|
+
function detectNestedTriggerHover(target) {
|
|
3004
|
+
const nestedTriggerHovered = isEnabledNestedTriggerTarget(target);
|
|
3005
|
+
isNestedTriggerHoveredRef.current = nestedTriggerHovered;
|
|
3006
|
+
if (nestedTriggerHovered) {
|
|
3007
|
+
hoverInteraction.openChangeTimeout.clear();
|
|
3008
|
+
hoverInteraction.restTimeout.clear();
|
|
3009
|
+
hoverInteraction.restTimeoutPending = false;
|
|
3010
|
+
nestedTriggerOpenTimeout.clear();
|
|
3011
|
+
}
|
|
3012
|
+
return nestedTriggerHovered;
|
|
3013
|
+
}
|
|
3014
|
+
const hoverProps = useHoverReferenceInteraction(floatingRootContext, {
|
|
3015
|
+
enabled: !disabled2,
|
|
3016
|
+
mouseOnly: true,
|
|
3017
|
+
move: false,
|
|
3018
|
+
handleClose: !disableHoverablePopup && trackCursorAxis !== "both" ? safePolygon() : null,
|
|
3019
|
+
restMs: getOpenDelay,
|
|
3020
|
+
delay() {
|
|
3021
|
+
if (closeDelay == null && hasProvider) {
|
|
3022
|
+
return {
|
|
3023
|
+
close: getDelay(delayRef.current, "close")
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
return {
|
|
3027
|
+
close: closeDelayWithDefault
|
|
3028
|
+
};
|
|
3029
|
+
},
|
|
3030
|
+
triggerElementRef,
|
|
3031
|
+
isActiveTrigger: isTriggerActive,
|
|
3032
|
+
isClosing: () => store.select("transitionStatus") === "ending",
|
|
3033
|
+
shouldOpen() {
|
|
3034
|
+
return !isNestedTriggerHoveredRef.current;
|
|
3035
|
+
}
|
|
3036
|
+
});
|
|
3037
|
+
const focusProps = useFocus(floatingRootContext, {
|
|
3038
|
+
enabled: !disabled2
|
|
3039
|
+
}).reference;
|
|
3040
|
+
const handleNestedTriggerHover = (event) => {
|
|
3041
|
+
const wasNestedTriggerHovered = isNestedTriggerHoveredRef.current;
|
|
3042
|
+
const target = getTargetElement(event);
|
|
3043
|
+
const nestedTriggerHovered = detectNestedTriggerHover(target);
|
|
3044
|
+
const triggerEl = triggerElementRef.current;
|
|
3045
|
+
const targetInsideTrigger = triggerEl && target && contains(triggerEl, target);
|
|
3046
|
+
if (nestedTriggerHovered && store.select("open") && store.select("lastOpenChangeReason") === triggerHover) {
|
|
3047
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
3048
|
+
return;
|
|
3049
|
+
}
|
|
3050
|
+
if (wasNestedTriggerHovered && !nestedTriggerHovered && targetInsideTrigger && !disabledRef.current && !store.select("open") && triggerEl && // Match the hover hook's non-strict mouse fallback for mouse-only event sequences.
|
|
3051
|
+
isMouseLikePointerType(pointerTypeRef.current)) {
|
|
3052
|
+
const open = () => {
|
|
3053
|
+
if (!isNestedTriggerHoveredRef.current && !disabledRef.current && !store.select("open")) {
|
|
3054
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerEl));
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
const openDelay = getOpenDelay();
|
|
3058
|
+
if (openDelay === 0) {
|
|
3059
|
+
nestedTriggerOpenTimeout.clear();
|
|
3060
|
+
open();
|
|
3061
|
+
} else {
|
|
3062
|
+
nestedTriggerOpenTimeout.start(openDelay, open);
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
};
|
|
3066
|
+
const rootTriggerProps = store.useState("appliedTriggerProps", isMountedByThisTrigger || trackCursorAxis !== "none");
|
|
3067
|
+
const state = {
|
|
3068
|
+
open: isOpenedByThisTrigger
|
|
3069
|
+
};
|
|
3070
|
+
const element = useRenderElement("button", componentProps, {
|
|
3071
|
+
state,
|
|
3072
|
+
ref: [forwardedRef, registerTrigger, triggerElementRef],
|
|
3073
|
+
props: [hoverProps, focusProps, rootTriggerProps, {
|
|
3074
|
+
onMouseOver(event) {
|
|
3075
|
+
handleNestedTriggerHover(event.nativeEvent);
|
|
3076
|
+
},
|
|
3077
|
+
onFocus(event) {
|
|
3078
|
+
if (isEnabledNestedTriggerTarget(getTargetElement(event.nativeEvent))) {
|
|
3079
|
+
event.preventBaseUIHandler();
|
|
3080
|
+
}
|
|
3081
|
+
},
|
|
3082
|
+
onMouseLeave() {
|
|
3083
|
+
isNestedTriggerHoveredRef.current = false;
|
|
3084
|
+
nestedTriggerOpenTimeout.clear();
|
|
3085
|
+
pointerTypeRef.current = void 0;
|
|
3086
|
+
},
|
|
3087
|
+
onPointerEnter(event) {
|
|
3088
|
+
pointerTypeRef.current = event.pointerType;
|
|
3089
|
+
},
|
|
3090
|
+
onPointerDown(event) {
|
|
3091
|
+
pointerTypeRef.current = event.pointerType;
|
|
3092
|
+
store.set("closeOnClick", closeOnClick);
|
|
3093
|
+
if (closeOnClick && !store.select("open")) {
|
|
3094
|
+
store.cancelPendingOpen(event.nativeEvent);
|
|
3095
|
+
}
|
|
3096
|
+
},
|
|
3097
|
+
onClick(event) {
|
|
3098
|
+
if (closeOnClick && !store.select("open")) {
|
|
3099
|
+
store.cancelPendingOpen(event.nativeEvent);
|
|
3100
|
+
}
|
|
3101
|
+
},
|
|
3102
|
+
id: thisTriggerId,
|
|
3103
|
+
[triggerDisabled]: disabled2 ? "" : void 0,
|
|
3104
|
+
[TOOLTIP_TRIGGER_IDENTIFIER]: disabled2 ? void 0 : ""
|
|
3105
|
+
}, elementProps],
|
|
3106
|
+
stateAttributesMapping: triggerOpenStateMapping
|
|
3107
|
+
});
|
|
3108
|
+
return element;
|
|
3109
|
+
});
|
|
3110
|
+
if (process.env.NODE_ENV !== "production") TooltipTrigger$1.displayName = "TooltipTrigger";
|
|
3111
|
+
const TooltipPortalContext = /* @__PURE__ */ React.createContext(void 0);
|
|
3112
|
+
if (process.env.NODE_ENV !== "production") TooltipPortalContext.displayName = "TooltipPortalContext";
|
|
3113
|
+
function useTooltipPortalContext() {
|
|
3114
|
+
const value = React.useContext(TooltipPortalContext);
|
|
3115
|
+
if (value === void 0) {
|
|
3116
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Tooltip.Portal> is missing." : formatErrorMessage(70));
|
|
3117
|
+
}
|
|
3118
|
+
return value;
|
|
3119
|
+
}
|
|
3120
|
+
const FloatingPortalLite = /* @__PURE__ */ React.forwardRef(function FloatingPortalLite2(componentProps, forwardedRef) {
|
|
3121
|
+
const {
|
|
3122
|
+
children,
|
|
3123
|
+
container,
|
|
3124
|
+
className,
|
|
3125
|
+
render,
|
|
3126
|
+
style,
|
|
3127
|
+
...elementProps
|
|
3128
|
+
} = componentProps;
|
|
3129
|
+
const {
|
|
3130
|
+
node: portalNode,
|
|
3131
|
+
subtree: portalSubtree
|
|
3132
|
+
} = useFloatingPortalNode({
|
|
3133
|
+
container,
|
|
3134
|
+
ref: forwardedRef,
|
|
3135
|
+
componentProps,
|
|
3136
|
+
elementProps
|
|
3137
|
+
});
|
|
3138
|
+
if (!portalSubtree && !portalNode) {
|
|
3139
|
+
return null;
|
|
3140
|
+
}
|
|
3141
|
+
return /* @__PURE__ */ jsxs(React.Fragment, {
|
|
3142
|
+
children: [portalSubtree, portalNode && /* @__PURE__ */ ReactDOM.createPortal(children, portalNode)]
|
|
3143
|
+
});
|
|
3144
|
+
});
|
|
3145
|
+
if (process.env.NODE_ENV !== "production") FloatingPortalLite.displayName = "FloatingPortalLite";
|
|
3146
|
+
const TooltipPortal = /* @__PURE__ */ React.forwardRef(function TooltipPortal2(props, forwardedRef) {
|
|
3147
|
+
const {
|
|
3148
|
+
keepMounted = false,
|
|
3149
|
+
...portalProps
|
|
3150
|
+
} = props;
|
|
3151
|
+
const store = useTooltipRootContext();
|
|
3152
|
+
const mounted = store.useState("mounted");
|
|
3153
|
+
const shouldRender = mounted || keepMounted;
|
|
3154
|
+
if (!shouldRender) {
|
|
3155
|
+
return null;
|
|
3156
|
+
}
|
|
3157
|
+
return /* @__PURE__ */ jsx(TooltipPortalContext.Provider, {
|
|
3158
|
+
value: keepMounted,
|
|
3159
|
+
children: /* @__PURE__ */ jsx(FloatingPortalLite, {
|
|
3160
|
+
ref: forwardedRef,
|
|
3161
|
+
...portalProps
|
|
3162
|
+
})
|
|
3163
|
+
});
|
|
3164
|
+
});
|
|
3165
|
+
if (process.env.NODE_ENV !== "production") TooltipPortal.displayName = "TooltipPortal";
|
|
3166
|
+
const TooltipPositionerContext = /* @__PURE__ */ React.createContext(void 0);
|
|
3167
|
+
if (process.env.NODE_ENV !== "production") TooltipPositionerContext.displayName = "TooltipPositionerContext";
|
|
3168
|
+
function useTooltipPositionerContext() {
|
|
3169
|
+
const context = React.useContext(TooltipPositionerContext);
|
|
3170
|
+
if (context === void 0) {
|
|
3171
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: TooltipPositionerContext is missing. TooltipPositioner parts must be placed within <Tooltip.Positioner>." : formatErrorMessage(71));
|
|
3172
|
+
}
|
|
3173
|
+
return context;
|
|
3174
|
+
}
|
|
3175
|
+
function useBaseUIFloating(options) {
|
|
3176
|
+
const {
|
|
3177
|
+
nodeId,
|
|
3178
|
+
externalTree,
|
|
3179
|
+
rootContext: store
|
|
3180
|
+
} = options;
|
|
3181
|
+
const referenceElement = store.useState("referenceElement");
|
|
3182
|
+
const floatingElement = store.useState("floatingElement");
|
|
3183
|
+
const domReferenceElement = store.useState("domReferenceElement");
|
|
3184
|
+
const open = store.useState("open");
|
|
3185
|
+
const floatingId = store.useState("floatingId");
|
|
3186
|
+
const [positionReference, setPositionReferenceRaw] = React.useState(null);
|
|
3187
|
+
const domReferenceRef = React.useRef(null);
|
|
3188
|
+
const tree = useFloatingTree(externalTree);
|
|
3189
|
+
const storeElements = React.useMemo(() => ({
|
|
3190
|
+
reference: referenceElement,
|
|
3191
|
+
floating: floatingElement,
|
|
3192
|
+
domReference: domReferenceElement
|
|
3193
|
+
}), [referenceElement, floatingElement, domReferenceElement]);
|
|
3194
|
+
const position = useFloating({
|
|
3195
|
+
...options,
|
|
3196
|
+
elements: {
|
|
3197
|
+
...storeElements,
|
|
3198
|
+
...positionReference && {
|
|
3199
|
+
reference: positionReference
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
});
|
|
3203
|
+
const setPositionReference = React.useCallback((node) => {
|
|
3204
|
+
const computedPositionReference = isElement(node) ? {
|
|
3205
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
3206
|
+
getClientRects: () => node.getClientRects(),
|
|
3207
|
+
contextElement: node
|
|
3208
|
+
} : node;
|
|
3209
|
+
setPositionReferenceRaw(computedPositionReference);
|
|
3210
|
+
position.refs.setReference(computedPositionReference);
|
|
3211
|
+
}, [position.refs]);
|
|
3212
|
+
const refs = React.useMemo(() => ({
|
|
3213
|
+
...position.refs,
|
|
3214
|
+
setPositionReference,
|
|
3215
|
+
domReference: domReferenceRef
|
|
3216
|
+
}), [position.refs, setPositionReference]);
|
|
3217
|
+
const elements = React.useMemo(() => ({
|
|
3218
|
+
...position.elements,
|
|
3219
|
+
domReference: domReferenceElement
|
|
3220
|
+
}), [position.elements, domReferenceElement]);
|
|
3221
|
+
const context = React.useMemo(() => ({
|
|
3222
|
+
...position,
|
|
3223
|
+
dataRef: store.context.dataRef,
|
|
3224
|
+
open,
|
|
3225
|
+
onOpenChange: store.setOpen,
|
|
3226
|
+
events: store.context.events,
|
|
3227
|
+
floatingId,
|
|
3228
|
+
refs,
|
|
3229
|
+
elements,
|
|
3230
|
+
nodeId,
|
|
3231
|
+
rootStore: store
|
|
3232
|
+
}), [position, refs, elements, nodeId, store, open, floatingId]);
|
|
3233
|
+
useIsoLayoutEffect(() => {
|
|
3234
|
+
if (domReferenceElement) {
|
|
3235
|
+
domReferenceRef.current = domReferenceElement;
|
|
3236
|
+
}
|
|
3237
|
+
}, [domReferenceElement]);
|
|
3238
|
+
useIsoLayoutEffect(() => {
|
|
3239
|
+
store.context.dataRef.current.floatingContext = context;
|
|
3240
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find((n) => n.id === nodeId);
|
|
3241
|
+
if (node) {
|
|
3242
|
+
node.context = context;
|
|
3243
|
+
}
|
|
3244
|
+
});
|
|
3245
|
+
return React.useMemo(() => ({
|
|
3246
|
+
...position,
|
|
3247
|
+
context,
|
|
3248
|
+
refs,
|
|
3249
|
+
elements,
|
|
3250
|
+
rootStore: store
|
|
3251
|
+
}), [position, refs, elements, context, store]);
|
|
3252
|
+
}
|
|
3253
|
+
const baseArrow = (options) => ({
|
|
3254
|
+
name: "arrow",
|
|
3255
|
+
options,
|
|
3256
|
+
async fn(state) {
|
|
3257
|
+
const {
|
|
3258
|
+
x,
|
|
3259
|
+
y,
|
|
3260
|
+
placement,
|
|
3261
|
+
rects,
|
|
3262
|
+
platform: platform2,
|
|
3263
|
+
elements,
|
|
3264
|
+
middlewareData
|
|
3265
|
+
} = state;
|
|
3266
|
+
const {
|
|
3267
|
+
element,
|
|
3268
|
+
padding = 0
|
|
3269
|
+
} = evaluate(options, state) || {};
|
|
3270
|
+
if (element == null) {
|
|
3271
|
+
return {};
|
|
3272
|
+
}
|
|
3273
|
+
const paddingObject = getPaddingObject(padding);
|
|
3274
|
+
const coords = {
|
|
3275
|
+
x,
|
|
3276
|
+
y
|
|
3277
|
+
};
|
|
3278
|
+
const axis = getAlignmentAxis(placement);
|
|
3279
|
+
const length = getAxisLength(axis);
|
|
3280
|
+
const arrowDimensions = await platform2.getDimensions(element);
|
|
3281
|
+
const isYAxis = axis === "y";
|
|
3282
|
+
const minProp = isYAxis ? "top" : "left";
|
|
3283
|
+
const maxProp = isYAxis ? "bottom" : "right";
|
|
3284
|
+
const clientProp = isYAxis ? "clientHeight" : "clientWidth";
|
|
3285
|
+
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
3286
|
+
const startDiff = coords[axis] - rects.reference[axis];
|
|
3287
|
+
const clientSize = elements.floating[clientProp] || rects.floating[length];
|
|
3288
|
+
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
3289
|
+
const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
|
|
3290
|
+
const minPadding = Math.min(paddingObject[minProp], largestPossiblePadding);
|
|
3291
|
+
const maxPadding = Math.min(paddingObject[maxProp], largestPossiblePadding);
|
|
3292
|
+
const min2 = minPadding;
|
|
3293
|
+
const max2 = clientSize - arrowDimensions[length] - maxPadding;
|
|
3294
|
+
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
3295
|
+
const offset2 = clamp(min2, center, max2);
|
|
3296
|
+
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min2 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
3297
|
+
const alignmentOffset = shouldAddOffset ? center < min2 ? center - min2 : center - max2 : 0;
|
|
3298
|
+
return {
|
|
3299
|
+
[axis]: coords[axis] + alignmentOffset,
|
|
3300
|
+
data: {
|
|
3301
|
+
[axis]: offset2,
|
|
3302
|
+
centerOffset: center - offset2 - alignmentOffset,
|
|
3303
|
+
...shouldAddOffset && {
|
|
3304
|
+
alignmentOffset
|
|
3305
|
+
}
|
|
3306
|
+
},
|
|
3307
|
+
reset: shouldAddOffset
|
|
3308
|
+
};
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
const arrow = (options, deps) => {
|
|
3312
|
+
const {
|
|
3313
|
+
name,
|
|
3314
|
+
fn
|
|
3315
|
+
} = baseArrow(options);
|
|
3316
|
+
return {
|
|
3317
|
+
name,
|
|
3318
|
+
fn,
|
|
3319
|
+
options: [options, deps]
|
|
3320
|
+
};
|
|
3321
|
+
};
|
|
3322
|
+
const hide = {
|
|
3323
|
+
name: "hide",
|
|
3324
|
+
async fn(state) {
|
|
3325
|
+
const {
|
|
3326
|
+
width,
|
|
3327
|
+
height,
|
|
3328
|
+
x,
|
|
3329
|
+
y
|
|
3330
|
+
} = state.rects.reference;
|
|
3331
|
+
const anchorHidden = width === 0 && height === 0 && x === 0 && y === 0;
|
|
3332
|
+
const overflow = await state.platform.detectOverflow(state, {
|
|
3333
|
+
elementContext: "reference"
|
|
3334
|
+
});
|
|
3335
|
+
const referenceHidden = overflow.top - height >= 0 || overflow.right - width >= 0 || overflow.bottom - height >= 0 || overflow.left - width >= 0;
|
|
3336
|
+
return {
|
|
3337
|
+
data: {
|
|
3338
|
+
referenceHidden: referenceHidden || anchorHidden
|
|
3339
|
+
}
|
|
3340
|
+
};
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
const DEFAULT_SIDES = {
|
|
3344
|
+
sideX: "left",
|
|
3345
|
+
sideY: "top"
|
|
3346
|
+
};
|
|
3347
|
+
const availableWidth = "--available-width";
|
|
3348
|
+
const availableHeight = "--available-height";
|
|
3349
|
+
const anchorWidth = "--anchor-width";
|
|
3350
|
+
const anchorHeight = "--anchor-height";
|
|
3351
|
+
const transformOrigin = "--transform-origin";
|
|
3352
|
+
const AVAILABLE_WIDTH_VAR = availableWidth;
|
|
3353
|
+
const AVAILABLE_HEIGHT_VAR = availableHeight;
|
|
3354
|
+
function getLogicalSide(sideParam, renderedSide, isRtl) {
|
|
3355
|
+
const isLogicalSideParam = sideParam === "inline-start" || sideParam === "inline-end";
|
|
3356
|
+
const logicalRight = isRtl ? "inline-start" : "inline-end";
|
|
3357
|
+
const logicalLeft = isRtl ? "inline-end" : "inline-start";
|
|
3358
|
+
return {
|
|
3359
|
+
top: "top",
|
|
3360
|
+
right: isLogicalSideParam ? logicalRight : "right",
|
|
3361
|
+
bottom: "bottom",
|
|
3362
|
+
left: isLogicalSideParam ? logicalLeft : "left"
|
|
3363
|
+
}[renderedSide];
|
|
3364
|
+
}
|
|
3365
|
+
function getOffsetData(state, sideParam, isRtl) {
|
|
3366
|
+
const {
|
|
3367
|
+
rects,
|
|
3368
|
+
placement
|
|
3369
|
+
} = state;
|
|
3370
|
+
const data = {
|
|
3371
|
+
side: getLogicalSide(sideParam, getSide(placement), isRtl),
|
|
3372
|
+
align: getAlignment(placement) || "center",
|
|
3373
|
+
anchor: {
|
|
3374
|
+
width: rects.reference.width,
|
|
3375
|
+
height: rects.reference.height
|
|
3376
|
+
},
|
|
3377
|
+
positioner: {
|
|
3378
|
+
width: rects.floating.width,
|
|
3379
|
+
height: rects.floating.height
|
|
3380
|
+
}
|
|
3381
|
+
};
|
|
3382
|
+
return data;
|
|
3383
|
+
}
|
|
3384
|
+
function useAnchorPositioning(params) {
|
|
3385
|
+
return useAnchorPositioningWithHook(params, useBaseUIFloating);
|
|
3386
|
+
}
|
|
3387
|
+
function useAnchorPositioningWithHook(params, useFloatingHook) {
|
|
3388
|
+
var _a, _b;
|
|
3389
|
+
const {
|
|
3390
|
+
// Public parameters
|
|
3391
|
+
anchor,
|
|
3392
|
+
positionMethod = "absolute",
|
|
3393
|
+
side: sideParam = "bottom",
|
|
3394
|
+
sideOffset = 0,
|
|
3395
|
+
align = "center",
|
|
3396
|
+
alignOffset = 0,
|
|
3397
|
+
collisionBoundary,
|
|
3398
|
+
collisionPadding: collisionPaddingParam = 5,
|
|
3399
|
+
sticky = false,
|
|
3400
|
+
arrowPadding = 5,
|
|
3401
|
+
disableAnchorTracking = false,
|
|
3402
|
+
inline: inlineMiddleware,
|
|
3403
|
+
// Private parameters
|
|
3404
|
+
keepMounted = false,
|
|
3405
|
+
floatingRootContext,
|
|
3406
|
+
mounted,
|
|
3407
|
+
collisionAvoidance,
|
|
3408
|
+
shift: shift$12,
|
|
3409
|
+
nodeId,
|
|
3410
|
+
adaptiveOrigin,
|
|
3411
|
+
lazyFlip = false,
|
|
3412
|
+
externalTree
|
|
3413
|
+
} = params;
|
|
3414
|
+
const collisionAvoidanceSide = collisionAvoidance.side || "flip";
|
|
3415
|
+
const collisionAvoidanceAlign = collisionAvoidance.align || "flip";
|
|
3416
|
+
const collisionAvoidanceFallbackAxisSide = collisionAvoidance.fallbackAxisSide || "end";
|
|
3417
|
+
const shiftCrossAxis = (shift$12 == null ? void 0 : shift$12.crossAxis) ?? false;
|
|
3418
|
+
const shiftRootBoundary = shift$12 == null ? void 0 : shift$12.rootBoundary;
|
|
3419
|
+
const anchorFn = typeof anchor === "function" ? anchor : void 0;
|
|
3420
|
+
const anchorFnCallback = useStableCallback(anchorFn);
|
|
3421
|
+
const anchorDep = anchorFn ? anchorFnCallback : anchor;
|
|
3422
|
+
const anchorValueRef = useValueAsRef(anchor);
|
|
3423
|
+
const mountedRef = useValueAsRef(mounted);
|
|
3424
|
+
const direction = useDirection();
|
|
3425
|
+
const isRtl = direction === "rtl";
|
|
3426
|
+
const [mountPlacement, setMountPlacement] = React.useState(null);
|
|
3427
|
+
if (!mounted && mountPlacement !== null) {
|
|
3428
|
+
setMountPlacement(null);
|
|
3429
|
+
}
|
|
3430
|
+
const lockAlign = lazyFlip === "placement";
|
|
3431
|
+
const mountSide = mountPlacement ? getSide(mountPlacement) : null;
|
|
3432
|
+
const mountAlign = mountPlacement && lockAlign ? getAlignment(mountPlacement) || "center" : null;
|
|
3433
|
+
const side = mountSide || {
|
|
3434
|
+
top: "top",
|
|
3435
|
+
right: "right",
|
|
3436
|
+
bottom: "bottom",
|
|
3437
|
+
left: "left",
|
|
3438
|
+
"inline-end": isRtl ? "left" : "right",
|
|
3439
|
+
"inline-start": isRtl ? "right" : "left"
|
|
3440
|
+
}[sideParam];
|
|
3441
|
+
const placementAlign = mountAlign || align;
|
|
3442
|
+
const placement = placementAlign === "center" ? side : `${side}-${placementAlign}`;
|
|
3443
|
+
let collisionPadding = collisionPaddingParam;
|
|
3444
|
+
if (typeof collisionPadding === "number") {
|
|
3445
|
+
collisionPadding = {
|
|
3446
|
+
top: collisionPadding,
|
|
3447
|
+
right: collisionPadding,
|
|
3448
|
+
bottom: collisionPadding,
|
|
3449
|
+
left: collisionPadding
|
|
3450
|
+
};
|
|
3451
|
+
} else if (collisionPadding) {
|
|
3452
|
+
collisionPadding = {
|
|
3453
|
+
top: collisionPadding.top || 0,
|
|
3454
|
+
right: collisionPadding.right || 0,
|
|
3455
|
+
bottom: collisionPadding.bottom || 0,
|
|
3456
|
+
left: collisionPadding.left || 0
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
const bias = 1;
|
|
3460
|
+
const biasTop = sideParam === "bottom" ? bias : 0;
|
|
3461
|
+
const biasBottom = sideParam === "top" ? bias : 0;
|
|
3462
|
+
const biasLeft = sideParam === "right" ? bias : 0;
|
|
3463
|
+
const biasRight = sideParam === "left" ? bias : 0;
|
|
3464
|
+
const commonCollisionProps = {
|
|
3465
|
+
boundary: collisionBoundary === "clipping-ancestors" ? "clippingAncestors" : collisionBoundary,
|
|
3466
|
+
padding: collisionPadding
|
|
3467
|
+
};
|
|
3468
|
+
const arrowRef = React.useRef(null);
|
|
3469
|
+
const sideOffsetRef = useValueAsRef(sideOffset);
|
|
3470
|
+
const alignOffsetRef = useValueAsRef(alignOffset);
|
|
3471
|
+
const sideOffsetDep = typeof sideOffset !== "function" ? sideOffset : 0;
|
|
3472
|
+
const alignOffsetDep = typeof alignOffset !== "function" ? alignOffset : 0;
|
|
3473
|
+
const middleware = [];
|
|
3474
|
+
if (inlineMiddleware) {
|
|
3475
|
+
middleware.push(inlineMiddleware);
|
|
3476
|
+
}
|
|
3477
|
+
middleware.push(offset((state) => {
|
|
3478
|
+
const data = getOffsetData(state, sideParam, isRtl);
|
|
3479
|
+
const sideAxis = typeof sideOffsetRef.current === "function" ? sideOffsetRef.current(data) : sideOffsetRef.current;
|
|
3480
|
+
const alignAxis = typeof alignOffsetRef.current === "function" ? alignOffsetRef.current(data) : alignOffsetRef.current;
|
|
3481
|
+
return {
|
|
3482
|
+
mainAxis: sideAxis,
|
|
3483
|
+
crossAxis: alignAxis,
|
|
3484
|
+
alignmentAxis: alignAxis
|
|
3485
|
+
};
|
|
3486
|
+
}, [sideOffsetDep, alignOffsetDep, isRtl, sideParam]));
|
|
3487
|
+
const shiftDisabled = collisionAvoidanceAlign === "none" && collisionAvoidanceSide !== "shift";
|
|
3488
|
+
const crossAxisShiftEnabled = !shiftDisabled && (sticky || shiftCrossAxis || collisionAvoidanceSide === "shift");
|
|
3489
|
+
const flipMiddleware = collisionAvoidanceSide === "none" ? null : flip({
|
|
3490
|
+
...commonCollisionProps,
|
|
3491
|
+
// Ensure the popup flips if it's been limited by its --available-height and it resizes.
|
|
3492
|
+
// Since the size() padding is smaller than the flip() padding, flip() will take precedence.
|
|
3493
|
+
padding: {
|
|
3494
|
+
top: collisionPadding.top + bias + biasTop,
|
|
3495
|
+
right: collisionPadding.right + bias + biasRight,
|
|
3496
|
+
bottom: collisionPadding.bottom + bias + biasBottom,
|
|
3497
|
+
left: collisionPadding.left + bias + biasLeft
|
|
3498
|
+
},
|
|
3499
|
+
mainAxis: !shiftCrossAxis && collisionAvoidanceSide === "flip",
|
|
3500
|
+
crossAxis: collisionAvoidanceAlign === "flip" ? "alignment" : false,
|
|
3501
|
+
fallbackAxisSideDirection: collisionAvoidanceFallbackAxisSide
|
|
3502
|
+
});
|
|
3503
|
+
const shiftMiddleware = shiftDisabled ? null : shift({
|
|
3504
|
+
...commonCollisionProps,
|
|
3505
|
+
// Use the Layout Viewport to avoid shifting around when pinch-zooming.
|
|
3506
|
+
rootBoundary: shiftRootBoundary,
|
|
3507
|
+
mainAxis: collisionAvoidanceAlign !== "none",
|
|
3508
|
+
crossAxis: crossAxisShiftEnabled,
|
|
3509
|
+
limiter: sticky || shiftCrossAxis ? void 0 : limitShift((limitData) => {
|
|
3510
|
+
if (!arrowRef.current) {
|
|
3511
|
+
return {};
|
|
3512
|
+
}
|
|
3513
|
+
const {
|
|
3514
|
+
width,
|
|
3515
|
+
height
|
|
3516
|
+
} = arrowRef.current.getBoundingClientRect();
|
|
3517
|
+
const sideAxis = getSideAxis(getSide(limitData.placement));
|
|
3518
|
+
const arrowSize = sideAxis === "y" ? width : height;
|
|
3519
|
+
const offsetAmount = sideAxis === "y" ? collisionPadding.left + collisionPadding.right : collisionPadding.top + collisionPadding.bottom;
|
|
3520
|
+
return {
|
|
3521
|
+
offset: arrowSize / 2 + offsetAmount / 2
|
|
3522
|
+
};
|
|
3523
|
+
})
|
|
3524
|
+
}, [commonCollisionProps, sticky, shiftCrossAxis, shiftRootBoundary, collisionPadding, collisionAvoidanceAlign]);
|
|
3525
|
+
if (collisionAvoidanceSide === "shift" || collisionAvoidanceAlign === "shift" || placementAlign === "center") {
|
|
3526
|
+
middleware.push(shiftMiddleware, flipMiddleware);
|
|
3527
|
+
} else {
|
|
3528
|
+
middleware.push(flipMiddleware, shiftMiddleware);
|
|
3529
|
+
}
|
|
3530
|
+
middleware.push(size({
|
|
3531
|
+
...commonCollisionProps,
|
|
3532
|
+
apply({
|
|
3533
|
+
elements: {
|
|
3534
|
+
floating
|
|
3535
|
+
},
|
|
3536
|
+
availableWidth: availableWidth2,
|
|
3537
|
+
availableHeight: availableHeight2,
|
|
3538
|
+
rects
|
|
3539
|
+
}) {
|
|
3540
|
+
if (!mountedRef.current) {
|
|
3541
|
+
return;
|
|
3542
|
+
}
|
|
3543
|
+
const floatingStyle = floating.style;
|
|
3544
|
+
floatingStyle.setProperty(AVAILABLE_WIDTH_VAR, `${availableWidth2}px`);
|
|
3545
|
+
floatingStyle.setProperty(AVAILABLE_HEIGHT_VAR, `${availableHeight2}px`);
|
|
3546
|
+
const dpr = getWindow(floating).devicePixelRatio || 1;
|
|
3547
|
+
const {
|
|
3548
|
+
x: x2,
|
|
3549
|
+
y: y2,
|
|
3550
|
+
width,
|
|
3551
|
+
height
|
|
3552
|
+
} = rects.reference;
|
|
3553
|
+
const anchorWidth$1 = (Math.round((x2 + width) * dpr) - Math.round(x2 * dpr)) / dpr;
|
|
3554
|
+
const anchorHeight$1 = (Math.round((y2 + height) * dpr) - Math.round(y2 * dpr)) / dpr;
|
|
3555
|
+
floatingStyle.setProperty(anchorWidth, `${anchorWidth$1}px`);
|
|
3556
|
+
floatingStyle.setProperty(anchorHeight, `${anchorHeight$1}px`);
|
|
3557
|
+
}
|
|
3558
|
+
}), arrow((state) => ({
|
|
3559
|
+
// `transform-origin` calculations rely on an element existing. If the arrow hasn't been set,
|
|
3560
|
+
// we'll create a fake element.
|
|
3561
|
+
element: arrowRef.current || ownerDocument(state.elements.floating).createElement("div"),
|
|
3562
|
+
// No padding for the fake arrow: it would displace aligned popups on narrow anchors.
|
|
3563
|
+
padding: arrowRef.current ? arrowPadding : 0
|
|
3564
|
+
}), [arrowPadding]), {
|
|
3565
|
+
name: "transformOrigin",
|
|
3566
|
+
fn(state) {
|
|
3567
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
3568
|
+
const {
|
|
3569
|
+
elements: {
|
|
3570
|
+
floating
|
|
3571
|
+
},
|
|
3572
|
+
middlewareData: middlewareData2,
|
|
3573
|
+
placement: renderedPlacement2,
|
|
3574
|
+
platform: platform2,
|
|
3575
|
+
rects,
|
|
3576
|
+
y: y2
|
|
3577
|
+
} = state;
|
|
3578
|
+
const renderedSide2 = getSide(renderedPlacement2);
|
|
3579
|
+
const renderedAlign2 = getAlignment(renderedPlacement2);
|
|
3580
|
+
const isVertical = getSideAxis(renderedSide2) === "y";
|
|
3581
|
+
const arrowEl = arrowRef.current;
|
|
3582
|
+
const sideOffsetValue = typeof sideOffset === "function" ? sideOffset(getOffsetData(state, sideParam, isRtl)) : sideOffset;
|
|
3583
|
+
let crossOrigin;
|
|
3584
|
+
if (!arrowEl && renderedAlign2 && Math.abs(isVertical ? ((_a2 = middlewareData2.shift) == null ? void 0 : _a2.x) || 0 : ((_b2 = middlewareData2.shift) == null ? void 0 : _b2.y) || 0) <= 1) {
|
|
3585
|
+
crossOrigin = renderedAlign2 === "start" === (isVertical && ((_c = platform2.isRTL) == null ? void 0 : _c.call(platform2, floating)) === true) ? "100%" : "0%";
|
|
3586
|
+
} else {
|
|
3587
|
+
const arrowOffset = isVertical ? ((_d = middlewareData2.arrow) == null ? void 0 : _d.x) || 0 : ((_e = middlewareData2.arrow) == null ? void 0 : _e.y) || 0;
|
|
3588
|
+
const arrowSize = isVertical ? (arrowEl == null ? void 0 : arrowEl.clientWidth) || 0 : (arrowEl == null ? void 0 : arrowEl.clientHeight) || 0;
|
|
3589
|
+
crossOrigin = `${arrowOffset + arrowSize / 2}px`;
|
|
3590
|
+
}
|
|
3591
|
+
let sideOrigin = renderedSide2 === "top" || renderedSide2 === "left" ? `calc(100% + ${sideOffsetValue}px)` : `${-sideOffsetValue}px`;
|
|
3592
|
+
if (crossAxisShiftEnabled && isVertical && Math.abs(((_f = middlewareData2.shift) == null ? void 0 : _f.y) || 0) > sideOffsetValue) {
|
|
3593
|
+
sideOrigin = `${rects.reference.y + rects.reference.height / 2 - y2}px`;
|
|
3594
|
+
}
|
|
3595
|
+
floating.style.setProperty(transformOrigin, isVertical ? `${crossOrigin} ${sideOrigin}` : `${sideOrigin} ${crossOrigin}`);
|
|
3596
|
+
return {};
|
|
3597
|
+
}
|
|
3598
|
+
}, hide, adaptiveOrigin);
|
|
3599
|
+
useIsoLayoutEffect(() => {
|
|
3600
|
+
if (!mounted && floatingRootContext) {
|
|
3601
|
+
floatingRootContext.update({
|
|
3602
|
+
referenceElement: null,
|
|
3603
|
+
floatingElement: null,
|
|
3604
|
+
domReferenceElement: null,
|
|
3605
|
+
positionReference: null
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
}, [mounted, floatingRootContext]);
|
|
3609
|
+
const autoUpdateOptions = React.useMemo(() => ({
|
|
3610
|
+
ancestorScroll: !disableAnchorTracking,
|
|
3611
|
+
elementResize: !disableAnchorTracking && typeof ResizeObserver !== "undefined",
|
|
3612
|
+
layoutShift: !disableAnchorTracking && typeof IntersectionObserver !== "undefined"
|
|
3613
|
+
}), [disableAnchorTracking]);
|
|
3614
|
+
const {
|
|
3615
|
+
refs,
|
|
3616
|
+
elements,
|
|
3617
|
+
x,
|
|
3618
|
+
y,
|
|
3619
|
+
middlewareData,
|
|
3620
|
+
update,
|
|
3621
|
+
placement: renderedPlacement,
|
|
3622
|
+
context,
|
|
3623
|
+
isPositioned,
|
|
3624
|
+
floatingStyles: originalFloatingStyles
|
|
3625
|
+
} = useFloatingHook({
|
|
3626
|
+
rootContext: floatingRootContext,
|
|
3627
|
+
open: keepMounted ? mounted : void 0,
|
|
3628
|
+
placement,
|
|
3629
|
+
middleware,
|
|
3630
|
+
strategy: positionMethod,
|
|
3631
|
+
whileElementsMounted: keepMounted ? void 0 : (...args) => autoUpdate(...args, autoUpdateOptions),
|
|
3632
|
+
nodeId,
|
|
3633
|
+
externalTree
|
|
3634
|
+
});
|
|
3635
|
+
const {
|
|
3636
|
+
sideX,
|
|
3637
|
+
sideY
|
|
3638
|
+
} = middlewareData.adaptiveOrigin || DEFAULT_SIDES;
|
|
3639
|
+
const resolvedPosition = isPositioned ? positionMethod : "fixed";
|
|
3640
|
+
const floatingStyles = React.useMemo(() => {
|
|
3641
|
+
let base;
|
|
3642
|
+
if (!isPositioned) {
|
|
3643
|
+
base = {
|
|
3644
|
+
position: resolvedPosition,
|
|
3645
|
+
top: 0,
|
|
3646
|
+
left: 0
|
|
3647
|
+
};
|
|
3648
|
+
} else if (adaptiveOrigin) {
|
|
3649
|
+
base = {
|
|
3650
|
+
position: resolvedPosition,
|
|
3651
|
+
[sideX]: x,
|
|
3652
|
+
[sideY]: y
|
|
3653
|
+
};
|
|
3654
|
+
} else {
|
|
3655
|
+
base = {
|
|
3656
|
+
...originalFloatingStyles,
|
|
3657
|
+
position: resolvedPosition
|
|
3658
|
+
};
|
|
3659
|
+
}
|
|
3660
|
+
base[AVAILABLE_WIDTH_VAR] = "100vw";
|
|
3661
|
+
base[AVAILABLE_HEIGHT_VAR] = "100vh";
|
|
3662
|
+
if (!isPositioned) {
|
|
3663
|
+
base.opacity = 0;
|
|
3664
|
+
}
|
|
3665
|
+
return base;
|
|
3666
|
+
}, [adaptiveOrigin, resolvedPosition, sideX, x, sideY, y, originalFloatingStyles, isPositioned]);
|
|
3667
|
+
const registeredPositionReferenceRef = React.useRef(null);
|
|
3668
|
+
useIsoLayoutEffect(() => {
|
|
3669
|
+
if (!mounted) {
|
|
3670
|
+
return;
|
|
3671
|
+
}
|
|
3672
|
+
const anchorValue = anchorValueRef.current;
|
|
3673
|
+
const resolvedAnchor = typeof anchorValue === "function" ? anchorValue() : anchorValue;
|
|
3674
|
+
const unwrappedElement = (isRef(resolvedAnchor) ? resolvedAnchor.current : resolvedAnchor) || null;
|
|
3675
|
+
const finalAnchor = unwrappedElement || null;
|
|
3676
|
+
if (finalAnchor !== registeredPositionReferenceRef.current) {
|
|
3677
|
+
refs.setPositionReference(finalAnchor);
|
|
3678
|
+
registeredPositionReferenceRef.current = finalAnchor;
|
|
3679
|
+
}
|
|
3680
|
+
}, [mounted, refs, anchorDep, anchorValueRef]);
|
|
3681
|
+
React.useEffect(() => {
|
|
3682
|
+
if (!mounted) {
|
|
3683
|
+
return;
|
|
3684
|
+
}
|
|
3685
|
+
const anchorValue = anchorValueRef.current;
|
|
3686
|
+
if (typeof anchorValue === "function") {
|
|
3687
|
+
return;
|
|
3688
|
+
}
|
|
3689
|
+
if (isRef(anchorValue) && anchorValue.current !== registeredPositionReferenceRef.current) {
|
|
3690
|
+
refs.setPositionReference(anchorValue.current);
|
|
3691
|
+
registeredPositionReferenceRef.current = anchorValue.current;
|
|
3692
|
+
}
|
|
3693
|
+
}, [mounted, refs, anchorDep, anchorValueRef]);
|
|
3694
|
+
React.useEffect(() => {
|
|
3695
|
+
if (keepMounted && mounted && elements.reference && elements.floating) {
|
|
3696
|
+
return autoUpdate(elements.reference, elements.floating, update, autoUpdateOptions);
|
|
3697
|
+
}
|
|
3698
|
+
return void 0;
|
|
3699
|
+
}, [keepMounted, mounted, elements, update, autoUpdateOptions]);
|
|
3700
|
+
const renderedSide = getSide(renderedPlacement);
|
|
3701
|
+
const logicalRenderedSide = getLogicalSide(sideParam, renderedSide, isRtl);
|
|
3702
|
+
const renderedAlign = getAlignment(renderedPlacement) || "center";
|
|
3703
|
+
const anchorHidden = Boolean((_a = middlewareData.hide) == null ? void 0 : _a.referenceHidden);
|
|
3704
|
+
useIsoLayoutEffect(() => {
|
|
3705
|
+
if (lazyFlip && mounted && isPositioned && (renderedSide !== side || lockAlign && renderedAlign !== placementAlign)) {
|
|
3706
|
+
setMountPlacement(renderedPlacement);
|
|
3707
|
+
}
|
|
3708
|
+
}, [lazyFlip, lockAlign, mounted, isPositioned, renderedPlacement, renderedSide, renderedAlign, side, placementAlign]);
|
|
3709
|
+
const arrowStyles = React.useMemo(() => {
|
|
3710
|
+
var _a2, _b2;
|
|
3711
|
+
return {
|
|
3712
|
+
position: "absolute",
|
|
3713
|
+
top: (_a2 = middlewareData.arrow) == null ? void 0 : _a2.y,
|
|
3714
|
+
left: (_b2 = middlewareData.arrow) == null ? void 0 : _b2.x
|
|
3715
|
+
};
|
|
3716
|
+
}, [middlewareData.arrow]);
|
|
3717
|
+
const arrowUncentered = ((_b = middlewareData.arrow) == null ? void 0 : _b.centerOffset) !== 0;
|
|
3718
|
+
return React.useMemo(() => ({
|
|
3719
|
+
positionerStyles: floatingStyles,
|
|
3720
|
+
arrowStyles,
|
|
3721
|
+
arrowRef,
|
|
3722
|
+
arrowUncentered,
|
|
3723
|
+
side: logicalRenderedSide,
|
|
3724
|
+
align: renderedAlign,
|
|
3725
|
+
physicalSide: renderedSide,
|
|
3726
|
+
anchorHidden,
|
|
3727
|
+
refs,
|
|
3728
|
+
context,
|
|
3729
|
+
isPositioned,
|
|
3730
|
+
update
|
|
3731
|
+
}), [floatingStyles, arrowStyles, arrowRef, arrowUncentered, logicalRenderedSide, renderedAlign, renderedSide, anchorHidden, refs, context, isPositioned, update]);
|
|
3732
|
+
}
|
|
3733
|
+
function isRef(param) {
|
|
3734
|
+
return param != null && "current" in param;
|
|
3735
|
+
}
|
|
3736
|
+
function getDisabledMountTransitionStyles(transitionStatus) {
|
|
3737
|
+
return transitionStatus === "starting" ? DISABLED_TRANSITIONS_STYLE : EMPTY_OBJECT;
|
|
3738
|
+
}
|
|
3739
|
+
function usePositioner(componentProps, state, {
|
|
3740
|
+
styles,
|
|
3741
|
+
transitionStatus,
|
|
3742
|
+
props,
|
|
3743
|
+
refs,
|
|
3744
|
+
hidden,
|
|
3745
|
+
inert = false
|
|
3746
|
+
}) {
|
|
3747
|
+
const style = {
|
|
3748
|
+
...styles
|
|
3749
|
+
};
|
|
3750
|
+
if (inert) {
|
|
3751
|
+
style.pointerEvents = "none";
|
|
3752
|
+
}
|
|
3753
|
+
return useRenderElement("div", componentProps, {
|
|
3754
|
+
state,
|
|
3755
|
+
ref: refs,
|
|
3756
|
+
props: [{
|
|
3757
|
+
role: "presentation",
|
|
3758
|
+
hidden,
|
|
3759
|
+
style
|
|
3760
|
+
}, getDisabledMountTransitionStyles(transitionStatus), props],
|
|
3761
|
+
stateAttributesMapping: popupStateMapping
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
const TooltipPositioner = /* @__PURE__ */ React.forwardRef(function TooltipPositioner2(componentProps, forwardedRef) {
|
|
3765
|
+
const {
|
|
3766
|
+
render,
|
|
3767
|
+
className,
|
|
3768
|
+
anchor,
|
|
3769
|
+
positionMethod = "absolute",
|
|
3770
|
+
side = "top",
|
|
3771
|
+
align = "center",
|
|
3772
|
+
sideOffset = 0,
|
|
3773
|
+
alignOffset = 0,
|
|
3774
|
+
collisionBoundary = "clipping-ancestors",
|
|
3775
|
+
collisionPadding = 5,
|
|
3776
|
+
arrowPadding = 5,
|
|
3777
|
+
sticky = false,
|
|
3778
|
+
disableAnchorTracking = false,
|
|
3779
|
+
collisionAvoidance = POPUP_COLLISION_AVOIDANCE,
|
|
3780
|
+
style,
|
|
3781
|
+
...elementProps
|
|
3782
|
+
} = componentProps;
|
|
3783
|
+
const store = useTooltipRootContext();
|
|
3784
|
+
const keepMounted = useTooltipPortalContext();
|
|
3785
|
+
const open = store.useState("open");
|
|
3786
|
+
const mounted = store.useState("mounted");
|
|
3787
|
+
const trackCursorAxis = store.useState("trackCursorAxis");
|
|
3788
|
+
const disableHoverablePopup = store.useState("disableHoverablePopup");
|
|
3789
|
+
const floatingRootContext = store.useState("floatingRootContext");
|
|
3790
|
+
const instantType = store.useState("instantType");
|
|
3791
|
+
const transitionStatus = store.useState("transitionStatus");
|
|
3792
|
+
const adaptiveOrigin = store.useState("adaptiveOrigin");
|
|
3793
|
+
const positioning = useAnchorPositioning({
|
|
3794
|
+
anchor,
|
|
3795
|
+
positionMethod,
|
|
3796
|
+
floatingRootContext,
|
|
3797
|
+
mounted,
|
|
3798
|
+
side,
|
|
3799
|
+
sideOffset,
|
|
3800
|
+
align,
|
|
3801
|
+
alignOffset,
|
|
3802
|
+
collisionBoundary,
|
|
3803
|
+
collisionPadding,
|
|
3804
|
+
sticky,
|
|
3805
|
+
arrowPadding,
|
|
3806
|
+
disableAnchorTracking,
|
|
3807
|
+
keepMounted,
|
|
3808
|
+
collisionAvoidance,
|
|
3809
|
+
adaptiveOrigin
|
|
3810
|
+
});
|
|
3811
|
+
const state = React.useMemo(() => ({
|
|
3812
|
+
open,
|
|
3813
|
+
side: positioning.side,
|
|
3814
|
+
align: positioning.align,
|
|
3815
|
+
anchorHidden: positioning.anchorHidden,
|
|
3816
|
+
instant: trackCursorAxis !== "none" ? "tracking-cursor" : instantType
|
|
3817
|
+
}), [open, positioning.side, positioning.align, positioning.anchorHidden, trackCursorAxis, instantType]);
|
|
3818
|
+
const element = usePositioner(componentProps, state, {
|
|
3819
|
+
styles: positioning.positionerStyles,
|
|
3820
|
+
transitionStatus,
|
|
3821
|
+
props: elementProps,
|
|
3822
|
+
refs: [forwardedRef, store.useStateSetter("positionerElement")],
|
|
3823
|
+
hidden: !mounted,
|
|
3824
|
+
inert: !open || trackCursorAxis === "both" || disableHoverablePopup
|
|
3825
|
+
});
|
|
3826
|
+
return /* @__PURE__ */ jsx(TooltipPositionerContext.Provider, {
|
|
3827
|
+
value: positioning,
|
|
3828
|
+
children: element
|
|
3829
|
+
});
|
|
3830
|
+
});
|
|
3831
|
+
if (process.env.NODE_ENV !== "production") TooltipPositioner.displayName = "TooltipPositioner";
|
|
3832
|
+
const TooltipPopup = /* @__PURE__ */ React.forwardRef(function TooltipPopup2(componentProps, forwardedRef) {
|
|
3833
|
+
const {
|
|
3834
|
+
render,
|
|
3835
|
+
className,
|
|
3836
|
+
style,
|
|
3837
|
+
...elementProps
|
|
3838
|
+
} = componentProps;
|
|
3839
|
+
const store = useTooltipRootContext();
|
|
3840
|
+
const {
|
|
3841
|
+
side,
|
|
3842
|
+
align
|
|
3843
|
+
} = useTooltipPositionerContext();
|
|
3844
|
+
const open = store.useState("open");
|
|
3845
|
+
const instantType = store.useState("instantType");
|
|
3846
|
+
const transitionStatus = store.useState("transitionStatus");
|
|
3847
|
+
const popupProps = store.useState("popupProps");
|
|
3848
|
+
const floatingContext = store.useState("floatingRootContext");
|
|
3849
|
+
const disabled2 = store.useState("disabled");
|
|
3850
|
+
const closeDelay = store.useState("closeDelay");
|
|
3851
|
+
useOpenChangeComplete({
|
|
3852
|
+
open,
|
|
3853
|
+
ref: store.context.popupRef,
|
|
3854
|
+
onComplete() {
|
|
3855
|
+
var _a, _b;
|
|
3856
|
+
if (open) {
|
|
3857
|
+
(_b = (_a = store.context).onOpenChangeComplete) == null ? void 0 : _b.call(_a, true);
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
});
|
|
3861
|
+
useHoverFloatingInteraction(floatingContext, {
|
|
3862
|
+
enabled: !disabled2,
|
|
3863
|
+
closeDelay
|
|
3864
|
+
});
|
|
3865
|
+
const setPopupElement = store.useStateSetter("popupElement");
|
|
3866
|
+
const state = {
|
|
3867
|
+
open,
|
|
3868
|
+
side,
|
|
3869
|
+
align,
|
|
3870
|
+
instant: instantType,
|
|
3871
|
+
transitionStatus
|
|
3872
|
+
};
|
|
3873
|
+
const element = useRenderElement("div", componentProps, {
|
|
3874
|
+
state,
|
|
3875
|
+
ref: [forwardedRef, store.context.popupRef, setPopupElement],
|
|
3876
|
+
props: [FOCUSABLE_POPUP_PROPS, popupProps, getDisabledMountTransitionStyles(transitionStatus), elementProps],
|
|
3877
|
+
stateAttributesMapping: popupTransitionStateMapping
|
|
3878
|
+
});
|
|
3879
|
+
return element;
|
|
3880
|
+
});
|
|
3881
|
+
if (process.env.NODE_ENV !== "production") TooltipPopup.displayName = "TooltipPopup";
|
|
3882
|
+
const TooltipArrow$1 = /* @__PURE__ */ React.forwardRef(function TooltipArrow(componentProps, forwardedRef) {
|
|
3883
|
+
const {
|
|
3884
|
+
render,
|
|
3885
|
+
className,
|
|
3886
|
+
style,
|
|
3887
|
+
...elementProps
|
|
3888
|
+
} = componentProps;
|
|
3889
|
+
const store = useTooltipRootContext();
|
|
3890
|
+
const {
|
|
3891
|
+
arrowRef,
|
|
3892
|
+
side,
|
|
3893
|
+
align,
|
|
3894
|
+
arrowUncentered,
|
|
3895
|
+
arrowStyles
|
|
3896
|
+
} = useTooltipPositionerContext();
|
|
3897
|
+
const open = store.useState("open");
|
|
3898
|
+
const instantType = store.useState("instantType");
|
|
3899
|
+
const state = {
|
|
3900
|
+
open,
|
|
3901
|
+
side,
|
|
3902
|
+
align,
|
|
3903
|
+
uncentered: arrowUncentered,
|
|
3904
|
+
instant: instantType
|
|
3905
|
+
};
|
|
3906
|
+
const element = useRenderElement("div", componentProps, {
|
|
3907
|
+
state,
|
|
3908
|
+
ref: [forwardedRef, arrowRef],
|
|
3909
|
+
props: [{
|
|
3910
|
+
style: arrowStyles,
|
|
3911
|
+
"aria-hidden": true
|
|
3912
|
+
}, elementProps],
|
|
3913
|
+
stateAttributesMapping: popupStateMapping
|
|
3914
|
+
});
|
|
3915
|
+
return element;
|
|
3916
|
+
});
|
|
3917
|
+
if (process.env.NODE_ENV !== "production") TooltipArrow$1.displayName = "TooltipArrow";
|
|
3918
|
+
const TooltipProvider$1 = function TooltipProvider(props) {
|
|
3919
|
+
const {
|
|
3920
|
+
delay,
|
|
3921
|
+
closeDelay,
|
|
3922
|
+
timeout = 400
|
|
3923
|
+
} = props;
|
|
3924
|
+
const delayValue = React.useMemo(() => ({
|
|
3925
|
+
open: delay,
|
|
3926
|
+
close: closeDelay
|
|
3927
|
+
}), [delay, closeDelay]);
|
|
3928
|
+
return /* @__PURE__ */ jsx(TooltipProviderContext.Provider, {
|
|
3929
|
+
value: delay,
|
|
3930
|
+
children: /* @__PURE__ */ jsx(FloatingDelayGroup, {
|
|
3931
|
+
delay: delayValue,
|
|
3932
|
+
timeoutMs: timeout,
|
|
3933
|
+
children: props.children
|
|
3934
|
+
})
|
|
3935
|
+
});
|
|
3936
|
+
};
|
|
3937
|
+
if (process.env.NODE_ENV !== "production") TooltipProvider$1.displayName = "TooltipProvider";
|
|
3938
|
+
function TooltipProvider2({ delay = 300, ...props }) {
|
|
3939
|
+
return /* @__PURE__ */ jsx(TooltipProvider$1, { delay, ...props });
|
|
3940
|
+
}
|
|
3941
|
+
function Tooltip(props) {
|
|
3942
|
+
return /* @__PURE__ */ jsx(TooltipRoot, { "data-slot": "tooltip", ...props });
|
|
3943
|
+
}
|
|
3944
|
+
function TooltipTrigger2(props) {
|
|
3945
|
+
return /* @__PURE__ */ jsx(TooltipTrigger$1, { "data-slot": "tooltip-trigger", ...props });
|
|
3946
|
+
}
|
|
3947
|
+
function TooltipArrow2({ className, ...props }) {
|
|
3948
|
+
return /* @__PURE__ */ jsx(
|
|
3949
|
+
TooltipArrow$1,
|
|
3950
|
+
{
|
|
3951
|
+
"data-slot": "tooltip-arrow",
|
|
3952
|
+
className: classNames(
|
|
3953
|
+
"size-fit",
|
|
3954
|
+
"data-[side=top]:rotate-180 data-[side=left]:rotate-90 data-[side=right]:-rotate-90",
|
|
3955
|
+
className
|
|
3956
|
+
),
|
|
3957
|
+
...props,
|
|
3958
|
+
children: /* @__PURE__ */ jsxs("svg", { "aria-hidden": "true", width: "9", height: "5", viewBox: "0 0 9 5", fill: "none", children: [
|
|
3959
|
+
/* @__PURE__ */ jsx("path", { d: "M.5 4.5h8l-4-4-4 4Z", fill: "currentColor" }),
|
|
3960
|
+
/* @__PURE__ */ jsx("path", { d: "m.5 4.5 4-4 4 4", className: "stroke-border-default" })
|
|
3961
|
+
] })
|
|
3962
|
+
}
|
|
3963
|
+
);
|
|
3964
|
+
}
|
|
3965
|
+
function TooltipContent({
|
|
3966
|
+
className,
|
|
3967
|
+
side = "top",
|
|
3968
|
+
sideOffset = 4,
|
|
3969
|
+
align = "center",
|
|
3970
|
+
alignOffset = 0,
|
|
3971
|
+
arrow: arrow2 = false,
|
|
3972
|
+
arrowClassName,
|
|
3973
|
+
positionerClassName,
|
|
3974
|
+
children,
|
|
3975
|
+
style,
|
|
3976
|
+
...props
|
|
3977
|
+
}) {
|
|
3978
|
+
return /* @__PURE__ */ jsx(TooltipPortal, { children: /* @__PURE__ */ jsxs(
|
|
3979
|
+
TooltipPositioner,
|
|
3980
|
+
{
|
|
3981
|
+
align,
|
|
3982
|
+
alignOffset,
|
|
3983
|
+
side,
|
|
3984
|
+
sideOffset,
|
|
3985
|
+
className: classNames("isolate z-50", positionerClassName),
|
|
3986
|
+
children: [
|
|
3987
|
+
/* @__PURE__ */ jsx(
|
|
3988
|
+
TooltipPopup,
|
|
3989
|
+
{
|
|
3990
|
+
"data-slot": "tooltip-content",
|
|
3991
|
+
className: classNames(
|
|
3992
|
+
"z-50 max-w-xs rounded-md border border-border-default bg-background-surface-inverse px-3 py-1.5 text-body-sm text-text-inverse shadow-md",
|
|
3993
|
+
className
|
|
3994
|
+
),
|
|
3995
|
+
style,
|
|
3996
|
+
...props,
|
|
3997
|
+
children
|
|
3998
|
+
}
|
|
3999
|
+
),
|
|
4000
|
+
arrow2 ? /* @__PURE__ */ jsx(TooltipArrow2, { className: arrowClassName }) : null
|
|
4001
|
+
]
|
|
4002
|
+
}
|
|
4003
|
+
) });
|
|
4004
|
+
}
|
|
4005
|
+
const sizeClasses = {
|
|
4006
|
+
large: "max-w-[26.25rem] max-h-[25rem] text-body-sm",
|
|
4007
|
+
medium: "max-w-[22.5rem] max-h-[18.75rem] text-body-sm",
|
|
4008
|
+
variable: "max-w-none max-h-none",
|
|
4009
|
+
fit: "max-w-fit max-h-none"
|
|
4010
|
+
};
|
|
4011
|
+
function parsePlacement(placement) {
|
|
4012
|
+
const [side, alignPart] = placement.split("-");
|
|
4013
|
+
return { side, align: alignPart ?? "center" };
|
|
4014
|
+
}
|
|
4015
|
+
function LegacyTooltip({
|
|
4016
|
+
title,
|
|
4017
|
+
placement = "top",
|
|
4018
|
+
size: size2 = "fit",
|
|
4019
|
+
border,
|
|
4020
|
+
padding,
|
|
4021
|
+
open,
|
|
4022
|
+
onOpen,
|
|
4023
|
+
onClose,
|
|
4024
|
+
disableHoverListener,
|
|
4025
|
+
disableInteractive,
|
|
4026
|
+
interactive,
|
|
4027
|
+
arrow: arrow2,
|
|
4028
|
+
children,
|
|
4029
|
+
classes,
|
|
4030
|
+
className,
|
|
4031
|
+
variant
|
|
4032
|
+
}) {
|
|
4033
|
+
if (title == null || title === "") {
|
|
4034
|
+
return children;
|
|
4035
|
+
}
|
|
4036
|
+
const { side, align } = parsePlacement(placement);
|
|
4037
|
+
const disableHoverablePopup = disableInteractive !== void 0 ? disableInteractive : interactive !== void 0 ? !interactive : void 0;
|
|
4038
|
+
const contentClass = classNames(
|
|
4039
|
+
sizeClasses[size2 ?? "fit"],
|
|
4040
|
+
arrow2 ? "overflow-visible" : "custom-scrollbar overflow-auto",
|
|
4041
|
+
variant === "light" && "border-border-default bg-background-surface-overlay text-text-primary shadow-md",
|
|
4042
|
+
variant === "dark" && "border-border-default bg-background-surface-inverse text-text-inverse",
|
|
4043
|
+
variant === "unstyled" && "border-0 bg-transparent p-0 text-text-primary shadow-none",
|
|
4044
|
+
border && variant === "light" && "border",
|
|
4045
|
+
classes == null ? void 0 : classes.tooltip
|
|
4046
|
+
);
|
|
4047
|
+
const arrowClassName = variant === "dark" ? "text-background-surface-inverse" : "text-background-surface-overlay";
|
|
4048
|
+
return (
|
|
4049
|
+
// Match MUI Tooltip feel: open immediately on hover (Base UI defaults are 300–600ms).
|
|
4050
|
+
/* @__PURE__ */ jsx(TooltipProvider2, { delay: 0, closeDelay: 0, children: /* @__PURE__ */ jsxs(
|
|
4051
|
+
Tooltip,
|
|
4052
|
+
{
|
|
4053
|
+
open,
|
|
4054
|
+
disableHoverablePopup,
|
|
4055
|
+
onOpenChange: (nextOpen) => {
|
|
4056
|
+
if (nextOpen) {
|
|
4057
|
+
onOpen == null ? void 0 : onOpen();
|
|
4058
|
+
} else {
|
|
4059
|
+
onClose == null ? void 0 : onClose();
|
|
4060
|
+
}
|
|
4061
|
+
},
|
|
4062
|
+
children: [
|
|
4063
|
+
/* @__PURE__ */ jsx(TooltipTrigger2, { render: children, disabled: disableHoverListener, delay: 0, closeDelay: 0 }),
|
|
4064
|
+
/* @__PURE__ */ jsx(
|
|
4065
|
+
TooltipContent,
|
|
4066
|
+
{
|
|
4067
|
+
side,
|
|
4068
|
+
align,
|
|
4069
|
+
arrow: arrow2,
|
|
4070
|
+
arrowClassName,
|
|
4071
|
+
className: contentClass,
|
|
4072
|
+
positionerClassName: classNames(className, classes == null ? void 0 : classes.popper),
|
|
4073
|
+
style: padding != null ? { padding } : void 0,
|
|
4074
|
+
children: title
|
|
4075
|
+
}
|
|
4076
|
+
)
|
|
4077
|
+
]
|
|
4078
|
+
}
|
|
4079
|
+
) })
|
|
4080
|
+
);
|
|
4081
|
+
}
|
|
4082
|
+
const LightTooltip = React.memo((props) => /* @__PURE__ */ jsx(LegacyTooltip, { ...props, variant: "light" }));
|
|
4083
|
+
const DarkTooltip = React.memo((props) => /* @__PURE__ */ jsx(LegacyTooltip, { ...props, variant: "dark" }));
|
|
4084
|
+
const UnstyledTooltip = React.memo((props) => /* @__PURE__ */ jsx(LegacyTooltip, { ...props, variant: "unstyled" }));
|
|
4085
|
+
export {
|
|
4086
|
+
DarkTooltip as D,
|
|
4087
|
+
LightTooltip as L,
|
|
4088
|
+
UnstyledTooltip as U,
|
|
4089
|
+
useAnchorPositioning as a,
|
|
4090
|
+
usePositioner as b,
|
|
4091
|
+
useHoverFloatingInteraction as c,
|
|
4092
|
+
getDisabledMountTransitionStyles as g,
|
|
4093
|
+
safePolygon as s,
|
|
4094
|
+
useHoverReferenceInteraction as u
|
|
4095
|
+
};
|
|
4096
|
+
//# sourceMappingURL=Tooltip-BuGLP-PU.js.map
|