tfy-web-components 0.0.33 → 0.0.35
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 +1 -1
- package/dist/components/atoms/IconProvider.es.js +48 -7
- package/dist/components/atoms/IconProvider.es.js.map +1 -1
- 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/AgentStepsCard.d.ts +2 -2
- 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 +78 -410
- 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 +19 -4
- package/dist/index.es.js +56 -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/theme.css +9 -154
- package/dist/tokens.css +1136 -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,1086 @@
|
|
|
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 * as React from "react";
|
|
5
|
+
import { v as isShadowRoot, s as getNodeName, j as isHTMLElement, f as focusOut, t as triggerHover, B as outsidePress, c as createChangeEventDetails, g as getWindow, e as triggerPress, E as isOverflowElement } from "./useBaseUiId-Ch7ujXpo.js";
|
|
6
|
+
import { u as useValueAsRef, a as addEventListener } from "./useValueAsRef-BfFRcMg6.js";
|
|
7
|
+
import { E as useFloatingTree, G as usePortalContext, H as tabbable, I as mergeCleanups, J as createAttribute, K as getNodeAncestors, L as getNodeChildren, M as isVirtualClick, N as isVirtualPointerEvent, O as webkit, y as FocusGuard, w as isOutsideEvent, Q as getNextTabbable, S as getPreviousTabbable, T as stopEvent, C as CLICK_TRIGGER_IDENTIFIER, U as isTabbable, V as focusable, W as isMouseLikePointerType, X as ios } from "./usePopupHandleStore-BdS-xYID.js";
|
|
8
|
+
import { N as NOOP, a as useStableCallback, c as useMergedRefs, u as useIsoLayoutEffect, d as EMPTY_OBJECT } from "./useIsoLayoutEffect-e9VA-ICd.js";
|
|
9
|
+
import { u as useTimeout, T as Timeout } from "./useTimeout-BXf1hDIL.js";
|
|
10
|
+
import { u as useAnimationFrame, A as AnimationFrame } from "./useAnimationFrame-DwhymJoW.js";
|
|
11
|
+
import { o as ownerDocument, d as isTypeableCombobox, g as getFloatingFocusElement, e as isTypeableElement } from "./index-B806bfA-.js";
|
|
12
|
+
import { i as isElementVisible } from "./composite-DCpXNxz9.js";
|
|
13
|
+
import { r as resolveRef } from "./useTransitionStatus-C9gg_XJ-.js";
|
|
14
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
15
|
+
import { c as contains, a as activeElement, g as getTarget, b as closest } from "./shadowDom-Bq4g0Qeu.js";
|
|
16
|
+
let rafId = 0;
|
|
17
|
+
function enqueueFocus(el, options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
preventScroll = false,
|
|
20
|
+
sync = false,
|
|
21
|
+
shouldFocus
|
|
22
|
+
} = options;
|
|
23
|
+
cancelAnimationFrame(rafId);
|
|
24
|
+
function exec() {
|
|
25
|
+
if (shouldFocus && !shouldFocus()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
el == null ? void 0 : el.focus({
|
|
29
|
+
preventScroll
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (sync) {
|
|
33
|
+
exec();
|
|
34
|
+
return NOOP;
|
|
35
|
+
}
|
|
36
|
+
const currentRafId = requestAnimationFrame(exec);
|
|
37
|
+
rafId = currentRafId;
|
|
38
|
+
return () => {
|
|
39
|
+
if (rafId === currentRafId) {
|
|
40
|
+
cancelAnimationFrame(currentRafId);
|
|
41
|
+
rafId = 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const markerName = "data-base-ui-inert";
|
|
46
|
+
let ariaHiddenCounterMap = /* @__PURE__ */ new WeakMap();
|
|
47
|
+
let uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
|
|
48
|
+
let markerCounterMap = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
let lockCount = 0;
|
|
50
|
+
function unwrapHost(node) {
|
|
51
|
+
if (!node) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return isShadowRoot(node) ? node.host : unwrapHost(node.parentNode);
|
|
55
|
+
}
|
|
56
|
+
const correctElements = (parent, targets) => targets.map((target) => {
|
|
57
|
+
if (parent.contains(target)) {
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
60
|
+
const correctedTarget = unwrapHost(target);
|
|
61
|
+
if (parent.contains(correctedTarget)) {
|
|
62
|
+
return correctedTarget;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}).filter((x) => x != null);
|
|
66
|
+
const buildKeepSet = (targets) => {
|
|
67
|
+
const keep = /* @__PURE__ */ new Set();
|
|
68
|
+
targets.forEach((target) => {
|
|
69
|
+
let node = target;
|
|
70
|
+
while (node && !keep.has(node)) {
|
|
71
|
+
keep.add(node);
|
|
72
|
+
node = node.parentNode;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return keep;
|
|
76
|
+
};
|
|
77
|
+
const collectOutsideElements = (root, keepElements, stopElements) => {
|
|
78
|
+
const outside = [];
|
|
79
|
+
const walk = (parent) => {
|
|
80
|
+
if (!parent || stopElements.has(parent)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
Array.from(parent.children).forEach((node) => {
|
|
84
|
+
if (getNodeName(node) === "script") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (keepElements.has(node)) {
|
|
88
|
+
walk(node);
|
|
89
|
+
} else {
|
|
90
|
+
outside.push(node);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
walk(root);
|
|
95
|
+
return outside;
|
|
96
|
+
};
|
|
97
|
+
function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, {
|
|
98
|
+
mark = true
|
|
99
|
+
}) {
|
|
100
|
+
const avoidElements = correctElements(body, uncorrectedAvoidElements);
|
|
101
|
+
const markerTargets = mark ? collectOutsideElements(body, buildKeepSet(avoidElements), new Set(avoidElements)) : [];
|
|
102
|
+
const hiddenElements = [];
|
|
103
|
+
const markedElements = [];
|
|
104
|
+
if (ariaHidden) {
|
|
105
|
+
const ariaLiveElements = correctElements(body, Array.from(body.querySelectorAll("[aria-live]")));
|
|
106
|
+
const controlElements = avoidElements.concat(ariaLiveElements);
|
|
107
|
+
const controlTargets = collectOutsideElements(body, buildKeepSet(controlElements), new Set(controlElements));
|
|
108
|
+
controlTargets.forEach((node) => {
|
|
109
|
+
const attr = node.getAttribute("aria-hidden");
|
|
110
|
+
const alreadyHidden = attr !== null && attr !== "false";
|
|
111
|
+
const counterValue = (ariaHiddenCounterMap.get(node) || 0) + 1;
|
|
112
|
+
ariaHiddenCounterMap.set(node, counterValue);
|
|
113
|
+
hiddenElements.push(node);
|
|
114
|
+
if (counterValue === 1 && alreadyHidden) {
|
|
115
|
+
uncontrolledElementsSet.add(node);
|
|
116
|
+
}
|
|
117
|
+
if (!alreadyHidden) {
|
|
118
|
+
node.setAttribute("aria-hidden", "true");
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (mark) {
|
|
123
|
+
markerTargets.forEach((node) => {
|
|
124
|
+
const markerValue = (markerCounterMap.get(node) || 0) + 1;
|
|
125
|
+
markerCounterMap.set(node, markerValue);
|
|
126
|
+
markedElements.push(node);
|
|
127
|
+
if (markerValue === 1) {
|
|
128
|
+
node.setAttribute(markerName, "");
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
lockCount += 1;
|
|
133
|
+
return () => {
|
|
134
|
+
hiddenElements.forEach((element) => {
|
|
135
|
+
const counterValue = (ariaHiddenCounterMap.get(element) || 0) - 1;
|
|
136
|
+
ariaHiddenCounterMap.set(element, counterValue);
|
|
137
|
+
if (!counterValue) {
|
|
138
|
+
if (!uncontrolledElementsSet.has(element)) {
|
|
139
|
+
element.removeAttribute("aria-hidden");
|
|
140
|
+
}
|
|
141
|
+
uncontrolledElementsSet.delete(element);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
if (mark) {
|
|
145
|
+
markedElements.forEach((element) => {
|
|
146
|
+
const markerValue = (markerCounterMap.get(element) || 0) - 1;
|
|
147
|
+
markerCounterMap.set(element, markerValue);
|
|
148
|
+
if (!markerValue) {
|
|
149
|
+
element.removeAttribute(markerName);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
lockCount -= 1;
|
|
154
|
+
if (!lockCount) {
|
|
155
|
+
ariaHiddenCounterMap = /* @__PURE__ */ new WeakMap();
|
|
156
|
+
uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
|
|
157
|
+
markerCounterMap = /* @__PURE__ */ new WeakMap();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function markOthers(avoidElements, options = {}) {
|
|
162
|
+
const {
|
|
163
|
+
ariaHidden = false,
|
|
164
|
+
mark = true
|
|
165
|
+
} = options;
|
|
166
|
+
const body = ownerDocument(avoidElements[0]).body;
|
|
167
|
+
return applyAttributeToOthers(avoidElements, body, ariaHidden, {
|
|
168
|
+
mark
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function getEventType(event, lastInteractionType) {
|
|
172
|
+
const win = getWindow(getTarget(event));
|
|
173
|
+
if (event instanceof win.KeyboardEvent) {
|
|
174
|
+
return "keyboard";
|
|
175
|
+
}
|
|
176
|
+
if (event instanceof win.FocusEvent) {
|
|
177
|
+
return lastInteractionType || "keyboard";
|
|
178
|
+
}
|
|
179
|
+
if ("pointerType" in event) {
|
|
180
|
+
return event.pointerType || (isVirtualClick(event) ? "keyboard" : lastInteractionType || "mouse");
|
|
181
|
+
}
|
|
182
|
+
if ("touches" in event) {
|
|
183
|
+
return "touch";
|
|
184
|
+
}
|
|
185
|
+
if (event instanceof win.MouseEvent) {
|
|
186
|
+
return lastInteractionType || (event.detail === 0 ? "keyboard" : "mouse");
|
|
187
|
+
}
|
|
188
|
+
return "";
|
|
189
|
+
}
|
|
190
|
+
const LIST_LIMIT = 20;
|
|
191
|
+
let previouslyFocusedElements = [];
|
|
192
|
+
function clearDisconnectedPreviouslyFocusedElements() {
|
|
193
|
+
previouslyFocusedElements = previouslyFocusedElements.filter((entry) => {
|
|
194
|
+
var _a;
|
|
195
|
+
return (_a = entry.deref()) == null ? void 0 : _a.isConnected;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function addPreviouslyFocusedElement(element) {
|
|
199
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
200
|
+
if (element && getNodeName(element) !== "body") {
|
|
201
|
+
previouslyFocusedElements.push(new WeakRef(element));
|
|
202
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) {
|
|
203
|
+
previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function getPreviouslyFocusedElement() {
|
|
208
|
+
var _a;
|
|
209
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
210
|
+
return (_a = previouslyFocusedElements[previouslyFocusedElements.length - 1]) == null ? void 0 : _a.deref();
|
|
211
|
+
}
|
|
212
|
+
function getFirstTabbableElement(container) {
|
|
213
|
+
if (!container) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
if (isTabbable(container)) {
|
|
217
|
+
return container;
|
|
218
|
+
}
|
|
219
|
+
return tabbable(container)[0] || container;
|
|
220
|
+
}
|
|
221
|
+
function handleTabIndex(floatingFocusElement) {
|
|
222
|
+
var _a;
|
|
223
|
+
if (floatingFocusElement.hasAttribute("tabindex") && !floatingFocusElement.hasAttribute("data-tabindex")) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!((_a = floatingFocusElement.getAttribute("role")) == null ? void 0 : _a.includes("dialog"))) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const focusableElements = focusable(floatingFocusElement);
|
|
230
|
+
const tabbableContent = focusableElements.filter((element) => {
|
|
231
|
+
const dataTabIndex = element.getAttribute("data-tabindex") || "";
|
|
232
|
+
return isTabbable(element) || element.hasAttribute("data-tabindex") && !dataTabIndex.startsWith("-");
|
|
233
|
+
});
|
|
234
|
+
const tabIndex = floatingFocusElement.getAttribute("tabindex");
|
|
235
|
+
if (tabbableContent.length === 0) {
|
|
236
|
+
if (tabIndex !== "0") {
|
|
237
|
+
floatingFocusElement.setAttribute("tabindex", "0");
|
|
238
|
+
floatingFocusElement.setAttribute("data-tabindex", "0");
|
|
239
|
+
}
|
|
240
|
+
} else if (tabIndex !== "-1" || floatingFocusElement.hasAttribute("data-tabindex") && floatingFocusElement.getAttribute("data-tabindex") !== "-1") {
|
|
241
|
+
floatingFocusElement.setAttribute("tabindex", "-1");
|
|
242
|
+
floatingFocusElement.setAttribute("data-tabindex", "-1");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function FloatingFocusManager(props) {
|
|
246
|
+
const {
|
|
247
|
+
context: store,
|
|
248
|
+
children,
|
|
249
|
+
disabled = false,
|
|
250
|
+
initialFocus = true,
|
|
251
|
+
returnFocus = true,
|
|
252
|
+
explicitReturnFocus,
|
|
253
|
+
restoreFocus = false,
|
|
254
|
+
modal = true,
|
|
255
|
+
closeOnFocusOut = true,
|
|
256
|
+
openInteractionType = "",
|
|
257
|
+
nextFocusableElement,
|
|
258
|
+
previousFocusableElement,
|
|
259
|
+
beforeContentFocusGuardRef,
|
|
260
|
+
externalTree,
|
|
261
|
+
getInsideElements
|
|
262
|
+
} = props;
|
|
263
|
+
const open = store.useState("open");
|
|
264
|
+
const domReference = store.useState("domReferenceElement");
|
|
265
|
+
const floating = store.useState("floatingElement");
|
|
266
|
+
const {
|
|
267
|
+
events,
|
|
268
|
+
dataRef
|
|
269
|
+
} = store.context;
|
|
270
|
+
const getNodeId = useStableCallback(() => {
|
|
271
|
+
var _a;
|
|
272
|
+
return (_a = dataRef.current.floatingContext) == null ? void 0 : _a.nodeId;
|
|
273
|
+
});
|
|
274
|
+
const ignoreInitialFocus = initialFocus === false;
|
|
275
|
+
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
276
|
+
const initialFocusRef = useValueAsRef(initialFocus);
|
|
277
|
+
const returnFocusRef = useValueAsRef(returnFocus);
|
|
278
|
+
const explicitReturnFocusRef = useValueAsRef(explicitReturnFocus);
|
|
279
|
+
const openInteractionTypeRef = useValueAsRef(openInteractionType);
|
|
280
|
+
const openRef = useValueAsRef(open);
|
|
281
|
+
const tree = useFloatingTree(externalTree);
|
|
282
|
+
const portalContext = usePortalContext();
|
|
283
|
+
const preventReturnFocusRef = React.useRef(false);
|
|
284
|
+
const isPointerDownRef = React.useRef(false);
|
|
285
|
+
const pointerDownOutsideRef = React.useRef(false);
|
|
286
|
+
const lastFocusedTabbableRef = React.useRef(null);
|
|
287
|
+
const closeTypeRef = React.useRef("");
|
|
288
|
+
const lastInteractionTypeRef = React.useRef("");
|
|
289
|
+
const beforeGuardRef = React.useRef(null);
|
|
290
|
+
const afterGuardRef = React.useRef(null);
|
|
291
|
+
const mergedBeforeGuardRef = useMergedRefs(beforeGuardRef, beforeContentFocusGuardRef, portalContext == null ? void 0 : portalContext.beforeInsideRef);
|
|
292
|
+
const mergedAfterGuardRef = useMergedRefs(afterGuardRef, portalContext == null ? void 0 : portalContext.afterInsideRef);
|
|
293
|
+
const blurTimeout = useTimeout();
|
|
294
|
+
const pointerDownTimeout = useTimeout();
|
|
295
|
+
const restoreFocusFrame = useAnimationFrame();
|
|
296
|
+
const isInsidePortal = portalContext != null;
|
|
297
|
+
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
298
|
+
const getTabbableContent = useStableCallback((container = floatingFocusElement) => {
|
|
299
|
+
return container ? tabbable(container) : [];
|
|
300
|
+
});
|
|
301
|
+
const getResolvedInsideElements = useStableCallback(() => (getInsideElements == null ? void 0 : getInsideElements().filter((element) => element != null)) ?? []);
|
|
302
|
+
React.useEffect(() => {
|
|
303
|
+
if (disabled || !modal) {
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
function onKeyDown(event) {
|
|
307
|
+
if (event.key === "Tab") {
|
|
308
|
+
if (contains(floatingFocusElement, activeElement(ownerDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
|
|
309
|
+
stopEvent(event);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
314
|
+
return addEventListener(doc, "keydown", onKeyDown);
|
|
315
|
+
}, [disabled, floatingFocusElement, modal, isUntrappedTypeableCombobox, getTabbableContent]);
|
|
316
|
+
React.useEffect(() => {
|
|
317
|
+
if (disabled || !open) {
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
321
|
+
function clearPointerDownOutside() {
|
|
322
|
+
pointerDownOutsideRef.current = false;
|
|
323
|
+
}
|
|
324
|
+
function onPointerDown(event) {
|
|
325
|
+
const target = getTarget(event);
|
|
326
|
+
const insideElements = getResolvedInsideElements();
|
|
327
|
+
const pointerTargetInside = contains(floating, target) || contains(domReference, target) || contains(portalContext == null ? void 0 : portalContext.portalNode, target) || insideElements.some((element) => element === target || contains(element, target));
|
|
328
|
+
pointerDownOutsideRef.current = !pointerTargetInside;
|
|
329
|
+
lastInteractionTypeRef.current = event.pointerType || "keyboard";
|
|
330
|
+
if (closest(target, `[${CLICK_TRIGGER_IDENTIFIER}]`)) {
|
|
331
|
+
isPointerDownRef.current = true;
|
|
332
|
+
pointerDownTimeout.start(0, () => {
|
|
333
|
+
isPointerDownRef.current = false;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function onKeyDown() {
|
|
338
|
+
lastInteractionTypeRef.current = "keyboard";
|
|
339
|
+
}
|
|
340
|
+
return mergeCleanups(
|
|
341
|
+
addEventListener(doc, "pointerdown", onPointerDown, true),
|
|
342
|
+
addEventListener(doc, "pointerup", clearPointerDownOutside, true),
|
|
343
|
+
addEventListener(doc, "pointercancel", clearPointerDownOutside, true),
|
|
344
|
+
addEventListener(doc, "keydown", onKeyDown, true),
|
|
345
|
+
// Avoid a stale `true` leaking into the next open (e.g. keep-mounted popups)
|
|
346
|
+
// if the popup dismissed between pointerdown and pointerup.
|
|
347
|
+
clearPointerDownOutside
|
|
348
|
+
);
|
|
349
|
+
}, [disabled, floating, domReference, floatingFocusElement, open, portalContext, pointerDownTimeout, getResolvedInsideElements]);
|
|
350
|
+
React.useEffect(() => {
|
|
351
|
+
if (disabled || !closeOnFocusOut) {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
355
|
+
function handlePointerDown() {
|
|
356
|
+
isPointerDownRef.current = true;
|
|
357
|
+
pointerDownTimeout.start(0, () => {
|
|
358
|
+
isPointerDownRef.current = false;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function handleFocusIn(event) {
|
|
362
|
+
const target = getTarget(event);
|
|
363
|
+
if (isTabbable(target)) {
|
|
364
|
+
lastFocusedTabbableRef.current = target;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function handleFocusOutside(event) {
|
|
368
|
+
const relatedTarget = event.relatedTarget;
|
|
369
|
+
const currentTarget = event.currentTarget;
|
|
370
|
+
const target = getTarget(event);
|
|
371
|
+
if (modal && relatedTarget == null && target != null && contains(floating, target)) {
|
|
372
|
+
addPreviouslyFocusedElement(target);
|
|
373
|
+
}
|
|
374
|
+
queueMicrotask(() => {
|
|
375
|
+
const nodeId = getNodeId();
|
|
376
|
+
const triggers = store.context.triggerElements;
|
|
377
|
+
const insideElements = getResolvedInsideElements();
|
|
378
|
+
const isRelatedFocusGuard = (relatedTarget == null ? void 0 : relatedTarget.hasAttribute(createAttribute("focus-guard"))) && [beforeGuardRef.current, afterGuardRef.current, portalContext == null ? void 0 : portalContext.beforeInsideRef.current, portalContext == null ? void 0 : portalContext.afterInsideRef.current, portalContext == null ? void 0 : portalContext.beforeOutsideRef.current, portalContext == null ? void 0 : portalContext.afterOutsideRef.current, resolveRef(previousFocusableElement), resolveRef(nextFocusableElement)].includes(relatedTarget);
|
|
379
|
+
const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || insideElements.some((element) => element === relatedTarget || contains(element, relatedTarget)) || triggers.hasMatchingElement((trigger) => contains(trigger, relatedTarget)) || isRelatedFocusGuard || tree && (getNodeChildren(tree.nodesRef.current, nodeId).find((node) => {
|
|
380
|
+
var _a, _b;
|
|
381
|
+
return contains((_a = node.context) == null ? void 0 : _a.elements.floating, relatedTarget) || contains((_b = node.context) == null ? void 0 : _b.elements.domReference, relatedTarget);
|
|
382
|
+
}) || getNodeAncestors(tree.nodesRef.current, nodeId).find((node) => {
|
|
383
|
+
var _a, _b, _c;
|
|
384
|
+
return [(_a = node.context) == null ? void 0 : _a.elements.floating, getFloatingFocusElement((_b = node.context) == null ? void 0 : _b.elements.floating)].includes(relatedTarget) || ((_c = node.context) == null ? void 0 : _c.elements.domReference) === relatedTarget;
|
|
385
|
+
})));
|
|
386
|
+
if (currentTarget === domReference && floatingFocusElement) {
|
|
387
|
+
handleTabIndex(floatingFocusElement);
|
|
388
|
+
}
|
|
389
|
+
if (restoreFocus && currentTarget !== domReference && !isElementVisible(target) && activeElement(doc) === doc.body) {
|
|
390
|
+
if (isHTMLElement(floatingFocusElement)) {
|
|
391
|
+
floatingFocusElement.focus();
|
|
392
|
+
if (restoreFocus === "popup") {
|
|
393
|
+
restoreFocusFrame.request(() => {
|
|
394
|
+
floatingFocusElement.focus();
|
|
395
|
+
});
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const tabbableContent = getTabbableContent();
|
|
400
|
+
const prevTabbable = lastFocusedTabbableRef.current;
|
|
401
|
+
const nodeToFocus = (prevTabbable && tabbableContent.includes(prevTabbable) ? prevTabbable : null) || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
402
|
+
if (isHTMLElement(nodeToFocus)) {
|
|
403
|
+
nodeToFocus.focus();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (dataRef.current.insideReactTree) {
|
|
407
|
+
dataRef.current.insideReactTree = false;
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
|
|
411
|
+
// For an "untrapped" typeable combobox (input role=combobox with
|
|
412
|
+
// initialFocus=false), re-opening the popup and tabbing out should still close it even
|
|
413
|
+
// when the previously focused element (e.g. the next tabbable outside the popup) is
|
|
414
|
+
// focused again. Otherwise, the popup remains open on the second Tab sequence:
|
|
415
|
+
// click input -> Tab (closes) -> click input -> Tab.
|
|
416
|
+
// Allow closing when `isUntrappedTypeableCombobox` regardless of the previously focused element.
|
|
417
|
+
(isUntrappedTypeableCombobox || relatedTarget !== getPreviouslyFocusedElement())) {
|
|
418
|
+
preventReturnFocusRef.current = true;
|
|
419
|
+
store.setOpen(false, createChangeEventDetails(focusOut, event));
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
function markInsideReactTree() {
|
|
424
|
+
if (pointerDownOutsideRef.current) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
dataRef.current.insideReactTree = true;
|
|
428
|
+
blurTimeout.start(0, () => {
|
|
429
|
+
dataRef.current.insideReactTree = false;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
const domReferenceElement = isHTMLElement(domReference) ? domReference : null;
|
|
433
|
+
if (!floating && !domReferenceElement) {
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
return mergeCleanups(domReferenceElement && addEventListener(domReferenceElement, "focusout", handleFocusOutside), domReferenceElement && addEventListener(domReferenceElement, "pointerdown", handlePointerDown), floating && addEventListener(floating, "focusin", handleFocusIn), floating && addEventListener(floating, "focusout", handleFocusOutside), floating && portalContext && addEventListener(floating, "focusout", markInsideReactTree, true));
|
|
437
|
+
}, [disabled, domReference, floating, floatingFocusElement, modal, tree, portalContext, store, closeOnFocusOut, restoreFocus, getTabbableContent, isUntrappedTypeableCombobox, getNodeId, dataRef, blurTimeout, pointerDownTimeout, restoreFocusFrame, nextFocusableElement, previousFocusableElement, getResolvedInsideElements]);
|
|
438
|
+
React.useEffect(() => {
|
|
439
|
+
var _a, _b, _c;
|
|
440
|
+
if (disabled || !floating || !open) {
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
const portalNodes = Array.from(((_a = portalContext == null ? void 0 : portalContext.portalNode) == null ? void 0 : _a.querySelectorAll(`[${createAttribute("portal")}]`)) || []);
|
|
444
|
+
const ancestors = tree ? getNodeAncestors(tree.nodesRef.current, getNodeId()) : [];
|
|
445
|
+
const rootAncestorComboboxDomReference = (_c = (_b = ancestors.find((node) => {
|
|
446
|
+
var _a2;
|
|
447
|
+
return isTypeableCombobox(((_a2 = node.context) == null ? void 0 : _a2.elements.domReference) || null);
|
|
448
|
+
})) == null ? void 0 : _b.context) == null ? void 0 : _c.elements.domReference;
|
|
449
|
+
const controlInsideElements = [floating, ...portalNodes, beforeGuardRef.current, afterGuardRef.current, portalContext == null ? void 0 : portalContext.beforeOutsideRef.current, portalContext == null ? void 0 : portalContext.afterOutsideRef.current, ...getResolvedInsideElements()];
|
|
450
|
+
const insideElements = [...controlInsideElements, rootAncestorComboboxDomReference, resolveRef(previousFocusableElement), resolveRef(nextFocusableElement), isUntrappedTypeableCombobox ? domReference : null].filter((x) => x != null);
|
|
451
|
+
const ariaHiddenCleanup = markOthers(insideElements, {
|
|
452
|
+
ariaHidden: modal || isUntrappedTypeableCombobox,
|
|
453
|
+
mark: false
|
|
454
|
+
});
|
|
455
|
+
const markerInsideElements = [floating, ...portalNodes].filter((x) => x != null);
|
|
456
|
+
const markerCleanup = markOthers(markerInsideElements);
|
|
457
|
+
return () => {
|
|
458
|
+
markerCleanup();
|
|
459
|
+
ariaHiddenCleanup();
|
|
460
|
+
};
|
|
461
|
+
}, [open, disabled, domReference, floating, modal, portalContext, isUntrappedTypeableCombobox, tree, getNodeId, nextFocusableElement, previousFocusableElement, getResolvedInsideElements]);
|
|
462
|
+
useIsoLayoutEffect(() => {
|
|
463
|
+
if (!open || disabled || !isHTMLElement(floatingFocusElement)) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
closeTypeRef.current = "";
|
|
467
|
+
lastInteractionTypeRef.current = "";
|
|
468
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
469
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
470
|
+
queueMicrotask(() => {
|
|
471
|
+
const initialFocusValueOrFn = initialFocusRef.current;
|
|
472
|
+
const resolvedInitialFocus = typeof initialFocusValueOrFn === "function" ? initialFocusValueOrFn(openInteractionTypeRef.current || "") : initialFocusValueOrFn;
|
|
473
|
+
if (resolvedInitialFocus === void 0 || resolvedInitialFocus === false) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
|
|
477
|
+
if (focusAlreadyInsideFloatingEl) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
let focusableElements = null;
|
|
481
|
+
const getDefaultFocusElement = () => {
|
|
482
|
+
if (focusableElements == null) {
|
|
483
|
+
focusableElements = getTabbableContent(floatingFocusElement);
|
|
484
|
+
}
|
|
485
|
+
return focusableElements[0] || floatingFocusElement;
|
|
486
|
+
};
|
|
487
|
+
let elToFocus;
|
|
488
|
+
if (resolvedInitialFocus === true || resolvedInitialFocus === null) {
|
|
489
|
+
elToFocus = getDefaultFocusElement();
|
|
490
|
+
} else {
|
|
491
|
+
elToFocus = resolveRef(resolvedInitialFocus);
|
|
492
|
+
}
|
|
493
|
+
elToFocus = elToFocus || getDefaultFocusElement();
|
|
494
|
+
const hadFocusInside = contains(floatingFocusElement, activeElement(doc));
|
|
495
|
+
const openEvent = dataRef.current.openEvent;
|
|
496
|
+
const openedByVirtualPress = (openEvent == null ? void 0 : openEvent.type) === "mousedown" && isVirtualClick(openEvent);
|
|
497
|
+
void enqueueFocus(elToFocus, {
|
|
498
|
+
sync: openedByVirtualPress,
|
|
499
|
+
preventScroll: elToFocus === floatingFocusElement,
|
|
500
|
+
shouldFocus() {
|
|
501
|
+
if (!openRef.current) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
if (hadFocusInside) {
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
const currentActiveElement = activeElement(doc);
|
|
508
|
+
const focusMovedInside = currentActiveElement !== elToFocus && contains(floatingFocusElement, currentActiveElement);
|
|
509
|
+
return !focusMovedInside;
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
}, [disabled, open, floatingFocusElement, getTabbableContent, initialFocusRef, openInteractionTypeRef, openRef, dataRef]);
|
|
514
|
+
const pendingReturnFocusRef = React.useRef(null);
|
|
515
|
+
useIsoLayoutEffect(() => {
|
|
516
|
+
if (disabled || !floatingFocusElement) {
|
|
517
|
+
pendingReturnFocusRef.current = null;
|
|
518
|
+
return void 0;
|
|
519
|
+
}
|
|
520
|
+
if (pendingReturnFocusRef.current) {
|
|
521
|
+
pendingReturnFocusRef.current.cancelled = true;
|
|
522
|
+
pendingReturnFocusRef.current = null;
|
|
523
|
+
}
|
|
524
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
525
|
+
const elementFocusedBeforeOpen = activeElement(doc);
|
|
526
|
+
const preferPreviousFocus = openInteractionTypeRef.current == null;
|
|
527
|
+
addPreviouslyFocusedElement(elementFocusedBeforeOpen);
|
|
528
|
+
function onOpenChangeLocal(details) {
|
|
529
|
+
var _a;
|
|
530
|
+
if (!details.open) {
|
|
531
|
+
closeTypeRef.current = getEventType(details.nativeEvent, lastInteractionTypeRef.current);
|
|
532
|
+
}
|
|
533
|
+
if (details.reason === focusOut && ((_a = details.triggerElement) == null ? void 0 : _a.hasAttribute(createAttribute("focus-guard"))) || details.reason === triggerHover && details.nativeEvent.type === "mouseleave") {
|
|
534
|
+
preventReturnFocusRef.current = true;
|
|
535
|
+
}
|
|
536
|
+
if (details.reason !== outsidePress) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (details.nested) {
|
|
540
|
+
preventReturnFocusRef.current = false;
|
|
541
|
+
} else if (isVirtualClick(details.nativeEvent) || isVirtualPointerEvent(details.nativeEvent)) {
|
|
542
|
+
preventReturnFocusRef.current = false;
|
|
543
|
+
} else {
|
|
544
|
+
let isPreventScrollSupported = false;
|
|
545
|
+
ownerDocument(floatingFocusElement).createElement("div").focus({
|
|
546
|
+
get preventScroll() {
|
|
547
|
+
isPreventScrollSupported = true;
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
if (isPreventScrollSupported) {
|
|
552
|
+
preventReturnFocusRef.current = false;
|
|
553
|
+
} else {
|
|
554
|
+
preventReturnFocusRef.current = true;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
events.on("openchange", onOpenChangeLocal);
|
|
559
|
+
function getReturnElement(closeType) {
|
|
560
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
561
|
+
let resolvedReturnFocusValue = typeof returnFocusValueOrFn === "function" ? returnFocusValueOrFn(closeType) : returnFocusValueOrFn;
|
|
562
|
+
if (resolvedReturnFocusValue === void 0 || resolvedReturnFocusValue === false) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
if (resolvedReturnFocusValue === null) {
|
|
566
|
+
resolvedReturnFocusValue = true;
|
|
567
|
+
}
|
|
568
|
+
const referenceReturnElement = (domReference == null ? void 0 : domReference.isConnected) ? domReference : null;
|
|
569
|
+
const previousReturnElement = (elementFocusedBeforeOpen == null ? void 0 : elementFocusedBeforeOpen.isConnected) && getNodeName(elementFocusedBeforeOpen) !== "body" ? elementFocusedBeforeOpen : null;
|
|
570
|
+
let defaultReturnElement = preferPreviousFocus ? previousReturnElement || referenceReturnElement : referenceReturnElement || previousReturnElement;
|
|
571
|
+
if (!defaultReturnElement) {
|
|
572
|
+
defaultReturnElement = getPreviouslyFocusedElement() || null;
|
|
573
|
+
}
|
|
574
|
+
if (typeof resolvedReturnFocusValue === "boolean") {
|
|
575
|
+
return defaultReturnElement;
|
|
576
|
+
}
|
|
577
|
+
return resolveRef(resolvedReturnFocusValue) || defaultReturnElement || null;
|
|
578
|
+
}
|
|
579
|
+
return () => {
|
|
580
|
+
events.off("openchange", onOpenChangeLocal);
|
|
581
|
+
const activeEl = activeElement(doc);
|
|
582
|
+
const insideElements = getResolvedInsideElements();
|
|
583
|
+
const isFocusInsideFloatingTree = contains(floating, activeEl) || insideElements.some((element) => element === activeEl || contains(element, activeEl)) || tree && getNodeChildren(tree.nodesRef.current, getNodeId(), false).some((node) => {
|
|
584
|
+
var _a;
|
|
585
|
+
return contains((_a = node.context) == null ? void 0 : _a.elements.floating, activeEl);
|
|
586
|
+
});
|
|
587
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
588
|
+
const closeType = closeTypeRef.current;
|
|
589
|
+
const returnElement = getReturnElement(closeType);
|
|
590
|
+
const job = {
|
|
591
|
+
cancelled: false
|
|
592
|
+
};
|
|
593
|
+
pendingReturnFocusRef.current = job;
|
|
594
|
+
queueMicrotask(() => {
|
|
595
|
+
if (pendingReturnFocusRef.current === job) {
|
|
596
|
+
pendingReturnFocusRef.current = null;
|
|
597
|
+
}
|
|
598
|
+
const tabbableReturnElement = getFirstTabbableElement(returnElement);
|
|
599
|
+
const hasExplicitReturnFocus = (
|
|
600
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
601
|
+
explicitReturnFocusRef.current ?? typeof returnFocusValueOrFn !== "boolean"
|
|
602
|
+
);
|
|
603
|
+
if (!job.cancelled && returnFocusValueOrFn && !preventReturnFocusRef.current && isHTMLElement(tabbableReturnElement) && // If the focus moved somewhere else after mount, avoid returning focus
|
|
604
|
+
// since it likely entered a different element which should be
|
|
605
|
+
// respected: https://github.com/floating-ui/floating-ui/issues/2607
|
|
606
|
+
(!hasExplicitReturnFocus && tabbableReturnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)) {
|
|
607
|
+
const focusOptions = {
|
|
608
|
+
preventScroll: true
|
|
609
|
+
};
|
|
610
|
+
if (closeType === "keyboard") {
|
|
611
|
+
focusOptions.focusVisible = true;
|
|
612
|
+
}
|
|
613
|
+
tabbableReturnElement.focus(focusOptions);
|
|
614
|
+
}
|
|
615
|
+
preventReturnFocusRef.current = false;
|
|
616
|
+
});
|
|
617
|
+
};
|
|
618
|
+
}, [disabled, floating, floatingFocusElement, returnFocusRef, explicitReturnFocusRef, openInteractionTypeRef, events, tree, domReference, getNodeId, getResolvedInsideElements]);
|
|
619
|
+
useIsoLayoutEffect(() => {
|
|
620
|
+
if (!webkit || open || !floating) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const activeEl = activeElement(ownerDocument(floating));
|
|
624
|
+
if (!isHTMLElement(activeEl) || !isTypeableElement(activeEl)) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (contains(floating, activeEl)) {
|
|
628
|
+
activeEl.blur();
|
|
629
|
+
}
|
|
630
|
+
}, [open, floating]);
|
|
631
|
+
useIsoLayoutEffect(() => {
|
|
632
|
+
if (disabled || !portalContext) {
|
|
633
|
+
return void 0;
|
|
634
|
+
}
|
|
635
|
+
portalContext.setFocusManagerState({
|
|
636
|
+
modal,
|
|
637
|
+
closeOnFocusOut,
|
|
638
|
+
open,
|
|
639
|
+
onOpenChange: store.setOpen,
|
|
640
|
+
domReference
|
|
641
|
+
});
|
|
642
|
+
return () => {
|
|
643
|
+
portalContext.setFocusManagerState(null);
|
|
644
|
+
};
|
|
645
|
+
}, [disabled, portalContext, modal, open, store, closeOnFocusOut, domReference]);
|
|
646
|
+
useIsoLayoutEffect(() => {
|
|
647
|
+
if (disabled || !floatingFocusElement) {
|
|
648
|
+
return void 0;
|
|
649
|
+
}
|
|
650
|
+
handleTabIndex(floatingFocusElement);
|
|
651
|
+
return () => {
|
|
652
|
+
queueMicrotask(clearDisconnectedPreviouslyFocusedElements);
|
|
653
|
+
};
|
|
654
|
+
}, [disabled, floatingFocusElement]);
|
|
655
|
+
const shouldRenderGuards = !disabled && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
656
|
+
return /* @__PURE__ */ jsxs(React.Fragment, {
|
|
657
|
+
children: [shouldRenderGuards && /* @__PURE__ */ jsx(FocusGuard, {
|
|
658
|
+
"data-type": "inside",
|
|
659
|
+
ref: mergedBeforeGuardRef,
|
|
660
|
+
onFocus: (event) => {
|
|
661
|
+
var _a;
|
|
662
|
+
if (modal) {
|
|
663
|
+
const els = getTabbableContent();
|
|
664
|
+
void enqueueFocus(els[els.length - 1]);
|
|
665
|
+
} else if (portalContext == null ? void 0 : portalContext.portalNode) {
|
|
666
|
+
preventReturnFocusRef.current = false;
|
|
667
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
668
|
+
const nextTabbable = getNextTabbable(domReference);
|
|
669
|
+
nextTabbable == null ? void 0 : nextTabbable.focus();
|
|
670
|
+
} else {
|
|
671
|
+
(_a = resolveRef(previousFocusableElement ?? portalContext.beforeOutsideRef)) == null ? void 0 : _a.focus();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}), children, shouldRenderGuards && /* @__PURE__ */ jsx(FocusGuard, {
|
|
676
|
+
"data-type": "inside",
|
|
677
|
+
ref: mergedAfterGuardRef,
|
|
678
|
+
onFocus: (event) => {
|
|
679
|
+
var _a;
|
|
680
|
+
if (modal) {
|
|
681
|
+
void enqueueFocus(getTabbableContent()[0]);
|
|
682
|
+
} else if (portalContext == null ? void 0 : portalContext.portalNode) {
|
|
683
|
+
if (closeOnFocusOut) {
|
|
684
|
+
preventReturnFocusRef.current = true;
|
|
685
|
+
}
|
|
686
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
687
|
+
const prevTabbable = getPreviousTabbable(domReference);
|
|
688
|
+
prevTabbable == null ? void 0 : prevTabbable.focus();
|
|
689
|
+
} else {
|
|
690
|
+
(_a = resolveRef(nextFocusableElement ?? portalContext.afterOutsideRef)) == null ? void 0 : _a.focus();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
})]
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
function useClick(store, props = {}) {
|
|
698
|
+
const {
|
|
699
|
+
enabled = true,
|
|
700
|
+
event: eventOption = "click",
|
|
701
|
+
toggle = true,
|
|
702
|
+
ignoreMouse = false,
|
|
703
|
+
stickIfOpen = true,
|
|
704
|
+
touchOpenDelay = 0,
|
|
705
|
+
reason = triggerPress
|
|
706
|
+
} = props;
|
|
707
|
+
const dataRef = store.context.dataRef;
|
|
708
|
+
const pointerTypeRef = React.useRef(void 0);
|
|
709
|
+
const frame = useAnimationFrame();
|
|
710
|
+
const touchOpenTimeout = useTimeout();
|
|
711
|
+
const reference = React.useMemo(() => {
|
|
712
|
+
function setOpenWithTouchDelay(nextOpen, nativeEvent, target, pointerType) {
|
|
713
|
+
const details = createChangeEventDetails(reason, nativeEvent, target);
|
|
714
|
+
if (nextOpen && pointerType === "touch" && touchOpenDelay > 0) {
|
|
715
|
+
touchOpenTimeout.start(touchOpenDelay, () => {
|
|
716
|
+
store.setOpen(true, details);
|
|
717
|
+
});
|
|
718
|
+
} else {
|
|
719
|
+
store.setOpen(nextOpen, details);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function getNextOpen(open, currentTarget, isClickLikeOpenEvent) {
|
|
723
|
+
const openEvent = dataRef.current.openEvent;
|
|
724
|
+
const hasClickedOnInactiveTrigger = store.select("domReferenceElement") !== currentTarget;
|
|
725
|
+
if (open && hasClickedOnInactiveTrigger) {
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
if (!open) {
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
if (!toggle) {
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
if (openEvent && (typeof stickIfOpen === "function" ? stickIfOpen() : stickIfOpen)) {
|
|
735
|
+
return !isClickLikeOpenEvent(openEvent.type);
|
|
736
|
+
}
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
onPointerDown(event) {
|
|
741
|
+
pointerTypeRef.current = isMouseLikePointerType(event.pointerType, true) && isVirtualPointerEvent(event.nativeEvent) ? "virtual" : event.pointerType;
|
|
742
|
+
},
|
|
743
|
+
onMouseDown(event) {
|
|
744
|
+
const pointerType = pointerTypeRef.current;
|
|
745
|
+
const nativeEvent = event.nativeEvent;
|
|
746
|
+
const open = store.select("open");
|
|
747
|
+
if (event.button !== 0 || eventOption === "click" || isMouseLikePointerType(pointerType, true) && ignoreMouse) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const nextOpen = getNextOpen(open, event.currentTarget, (openEventType) => openEventType === "click" || openEventType === "mousedown");
|
|
751
|
+
const target = getTarget(nativeEvent);
|
|
752
|
+
const isTypeable = isTypeableElement(target);
|
|
753
|
+
if (isTypeable || pointerType === "virtual") {
|
|
754
|
+
setOpenWithTouchDelay(nextOpen, nativeEvent, isTypeable ? target : event.currentTarget, pointerType);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
const eventCurrentTarget = event.currentTarget;
|
|
758
|
+
frame.request(() => {
|
|
759
|
+
setOpenWithTouchDelay(nextOpen, nativeEvent, eventCurrentTarget, pointerType);
|
|
760
|
+
});
|
|
761
|
+
},
|
|
762
|
+
onClick(event) {
|
|
763
|
+
if (eventOption === "mousedown-only") {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const pointerType = pointerTypeRef.current;
|
|
767
|
+
if (eventOption === "mousedown" && pointerType) {
|
|
768
|
+
pointerTypeRef.current = void 0;
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (isMouseLikePointerType(pointerType, true) && ignoreMouse) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const open = store.select("open");
|
|
775
|
+
const nextOpen = getNextOpen(open, event.currentTarget, (openEventType) => openEventType === "click" || openEventType === "mousedown" || openEventType === "keydown" || openEventType === "keyup");
|
|
776
|
+
setOpenWithTouchDelay(nextOpen, event.nativeEvent, event.currentTarget, pointerType);
|
|
777
|
+
},
|
|
778
|
+
onKeyDown() {
|
|
779
|
+
pointerTypeRef.current = void 0;
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}, [dataRef, eventOption, ignoreMouse, reason, store, stickIfOpen, toggle, frame, touchOpenTimeout, touchOpenDelay]);
|
|
783
|
+
return React.useMemo(() => enabled ? {
|
|
784
|
+
reference
|
|
785
|
+
} : EMPTY_OBJECT, [enabled, reference]);
|
|
786
|
+
}
|
|
787
|
+
const InternalBackdrop = /* @__PURE__ */ React.forwardRef(function InternalBackdrop2(props, ref) {
|
|
788
|
+
const {
|
|
789
|
+
cutout,
|
|
790
|
+
...otherProps
|
|
791
|
+
} = props;
|
|
792
|
+
let clipPath;
|
|
793
|
+
if (cutout) {
|
|
794
|
+
const rect = cutout.getBoundingClientRect();
|
|
795
|
+
clipPath = `polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${rect.left}px ${rect.top}px,${rect.left}px ${rect.bottom}px,${rect.right}px ${rect.bottom}px,${rect.right}px ${rect.top}px,${rect.left}px ${rect.top}px)`;
|
|
796
|
+
}
|
|
797
|
+
return /* @__PURE__ */ jsx("div", {
|
|
798
|
+
ref,
|
|
799
|
+
role: "presentation",
|
|
800
|
+
"data-base-ui-inert": "",
|
|
801
|
+
...otherProps,
|
|
802
|
+
style: {
|
|
803
|
+
position: "fixed",
|
|
804
|
+
inset: 0,
|
|
805
|
+
userSelect: "none",
|
|
806
|
+
WebkitUserSelect: "none",
|
|
807
|
+
clipPath
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
});
|
|
811
|
+
if (process.env.NODE_ENV !== "production") InternalBackdrop.displayName = "InternalBackdrop";
|
|
812
|
+
let originalHtmlStyles = {};
|
|
813
|
+
let originalBodyStyles = {};
|
|
814
|
+
let originalHtmlScrollBehavior = "";
|
|
815
|
+
function getViewportScroller(html, body) {
|
|
816
|
+
return isOverflowElement(html) ? html : body;
|
|
817
|
+
}
|
|
818
|
+
function isPageScrollLocked(win, html, body) {
|
|
819
|
+
return /hidden|clip/.test(win.getComputedStyle(getViewportScroller(html, body)).overflowY);
|
|
820
|
+
}
|
|
821
|
+
function hasInsetScrollbars(referenceElement) {
|
|
822
|
+
if (typeof document === "undefined") {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
const doc = ownerDocument(referenceElement);
|
|
826
|
+
const win = getWindow(doc);
|
|
827
|
+
return win.innerWidth - doc.documentElement.clientWidth > 0;
|
|
828
|
+
}
|
|
829
|
+
function supportsStableScrollbarGutter(referenceElement) {
|
|
830
|
+
const supported = typeof CSS !== "undefined" && CSS.supports && CSS.supports("scrollbar-gutter", "stable");
|
|
831
|
+
if (!supported || typeof document === "undefined") {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
const doc = ownerDocument(referenceElement);
|
|
835
|
+
const html = doc.documentElement;
|
|
836
|
+
const body = doc.body;
|
|
837
|
+
const scrollContainer = getViewportScroller(html, body);
|
|
838
|
+
const originalScrollContainerOverflowY = scrollContainer.style.overflowY;
|
|
839
|
+
const originalHtmlStyleGutter = html.style.scrollbarGutter;
|
|
840
|
+
html.style.scrollbarGutter = "stable";
|
|
841
|
+
scrollContainer.style.overflowY = "scroll";
|
|
842
|
+
const before = scrollContainer.offsetWidth;
|
|
843
|
+
scrollContainer.style.overflowY = "hidden";
|
|
844
|
+
const after = scrollContainer.offsetWidth;
|
|
845
|
+
scrollContainer.style.overflowY = originalScrollContainerOverflowY;
|
|
846
|
+
html.style.scrollbarGutter = originalHtmlStyleGutter;
|
|
847
|
+
return before === after;
|
|
848
|
+
}
|
|
849
|
+
function preventScrollOverlayScrollbars(referenceElement) {
|
|
850
|
+
const doc = ownerDocument(referenceElement);
|
|
851
|
+
const html = doc.documentElement;
|
|
852
|
+
const body = doc.body;
|
|
853
|
+
const elementToLock = getViewportScroller(html, body);
|
|
854
|
+
const originalElementToLockStyles = {
|
|
855
|
+
overflowY: elementToLock.style.overflowY,
|
|
856
|
+
overflowX: elementToLock.style.overflowX
|
|
857
|
+
};
|
|
858
|
+
Object.assign(elementToLock.style, {
|
|
859
|
+
overflowY: "hidden",
|
|
860
|
+
overflowX: "hidden"
|
|
861
|
+
});
|
|
862
|
+
return () => {
|
|
863
|
+
Object.assign(elementToLock.style, originalElementToLockStyles);
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function preventScrollInsetScrollbars(referenceElement) {
|
|
867
|
+
var _a;
|
|
868
|
+
const doc = ownerDocument(referenceElement);
|
|
869
|
+
const html = doc.documentElement;
|
|
870
|
+
const body = doc.body;
|
|
871
|
+
const win = getWindow(html);
|
|
872
|
+
let scrollTop = 0;
|
|
873
|
+
let scrollLeft = 0;
|
|
874
|
+
let updateGutterOnly = false;
|
|
875
|
+
const resizeFrame = AnimationFrame.create();
|
|
876
|
+
if (webkit && (((_a = win.visualViewport) == null ? void 0 : _a.scale) ?? 1) !== 1) {
|
|
877
|
+
return () => {
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
function lockScroll() {
|
|
881
|
+
const htmlStyles = win.getComputedStyle(html);
|
|
882
|
+
const bodyStyles = win.getComputedStyle(body);
|
|
883
|
+
const htmlScrollbarGutterValue = htmlStyles.scrollbarGutter || "";
|
|
884
|
+
const hasBothEdges = htmlScrollbarGutterValue.includes("both-edges");
|
|
885
|
+
const scrollbarGutterValue = hasBothEdges ? "stable both-edges" : "stable";
|
|
886
|
+
scrollTop = html.scrollTop;
|
|
887
|
+
scrollLeft = html.scrollLeft;
|
|
888
|
+
originalHtmlStyles = {
|
|
889
|
+
scrollbarGutter: html.style.scrollbarGutter,
|
|
890
|
+
overflowY: html.style.overflowY,
|
|
891
|
+
overflowX: html.style.overflowX
|
|
892
|
+
};
|
|
893
|
+
originalHtmlScrollBehavior = html.style.scrollBehavior;
|
|
894
|
+
originalBodyStyles = {
|
|
895
|
+
position: body.style.position,
|
|
896
|
+
height: body.style.height,
|
|
897
|
+
width: body.style.width,
|
|
898
|
+
boxSizing: body.style.boxSizing,
|
|
899
|
+
overflowY: body.style.overflowY,
|
|
900
|
+
overflowX: body.style.overflowX,
|
|
901
|
+
scrollBehavior: body.style.scrollBehavior
|
|
902
|
+
};
|
|
903
|
+
const isScrollableY = html.scrollHeight > html.clientHeight;
|
|
904
|
+
const isScrollableX = html.scrollWidth > html.clientWidth;
|
|
905
|
+
const hasConstantOverflowY = htmlStyles.overflowY === "scroll" || bodyStyles.overflowY === "scroll";
|
|
906
|
+
const hasConstantOverflowX = htmlStyles.overflowX === "scroll" || bodyStyles.overflowX === "scroll";
|
|
907
|
+
const scrollbarWidth = Math.max(0, win.innerWidth - body.clientWidth);
|
|
908
|
+
const scrollbarHeight = Math.max(0, win.innerHeight - body.clientHeight);
|
|
909
|
+
const marginY = parseFloat(bodyStyles.marginTop) + parseFloat(bodyStyles.marginBottom);
|
|
910
|
+
const marginX = parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight);
|
|
911
|
+
const elementToLock = getViewportScroller(html, body);
|
|
912
|
+
updateGutterOnly = supportsStableScrollbarGutter(referenceElement);
|
|
913
|
+
if (updateGutterOnly) {
|
|
914
|
+
html.style.scrollbarGutter = scrollbarGutterValue;
|
|
915
|
+
elementToLock.style.overflowY = "hidden";
|
|
916
|
+
elementToLock.style.overflowX = "hidden";
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
Object.assign(html.style, {
|
|
920
|
+
scrollbarGutter: scrollbarGutterValue,
|
|
921
|
+
overflowY: "hidden",
|
|
922
|
+
overflowX: "hidden"
|
|
923
|
+
});
|
|
924
|
+
if (isScrollableY || hasConstantOverflowY) {
|
|
925
|
+
html.style.overflowY = "scroll";
|
|
926
|
+
}
|
|
927
|
+
if (isScrollableX || hasConstantOverflowX) {
|
|
928
|
+
html.style.overflowX = "scroll";
|
|
929
|
+
}
|
|
930
|
+
Object.assign(body.style, {
|
|
931
|
+
position: "relative",
|
|
932
|
+
height: marginY || scrollbarHeight ? `calc(100dvh - ${marginY + scrollbarHeight}px)` : "100dvh",
|
|
933
|
+
width: marginX || scrollbarWidth ? `calc(100vw - ${marginX + scrollbarWidth}px)` : "100vw",
|
|
934
|
+
boxSizing: "border-box",
|
|
935
|
+
// Assign the longhands that `cleanup` restores, so nothing is left behind.
|
|
936
|
+
overflowY: "hidden",
|
|
937
|
+
overflowX: "hidden",
|
|
938
|
+
scrollBehavior: "unset"
|
|
939
|
+
});
|
|
940
|
+
body.scrollTop = scrollTop;
|
|
941
|
+
body.scrollLeft = scrollLeft;
|
|
942
|
+
html.setAttribute("data-base-ui-scroll-locked", "");
|
|
943
|
+
html.style.scrollBehavior = "unset";
|
|
944
|
+
}
|
|
945
|
+
function cleanup() {
|
|
946
|
+
Object.assign(html.style, originalHtmlStyles);
|
|
947
|
+
Object.assign(body.style, originalBodyStyles);
|
|
948
|
+
if (!updateGutterOnly) {
|
|
949
|
+
html.scrollTop = scrollTop;
|
|
950
|
+
html.scrollLeft = scrollLeft;
|
|
951
|
+
html.removeAttribute("data-base-ui-scroll-locked");
|
|
952
|
+
html.style.scrollBehavior = originalHtmlScrollBehavior;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
function handleResize() {
|
|
956
|
+
cleanup();
|
|
957
|
+
resizeFrame.request(lockScroll);
|
|
958
|
+
}
|
|
959
|
+
lockScroll();
|
|
960
|
+
const unsubscribeResize = addEventListener(win, "resize", handleResize);
|
|
961
|
+
return () => {
|
|
962
|
+
resizeFrame.cancel();
|
|
963
|
+
cleanup();
|
|
964
|
+
if (typeof win.removeEventListener === "function") {
|
|
965
|
+
unsubscribeResize();
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
class ScrollLocker {
|
|
970
|
+
constructor() {
|
|
971
|
+
__publicField(this, "lockCount", 0);
|
|
972
|
+
__publicField(this, "restore", null);
|
|
973
|
+
__publicField(this, "timeoutLock", Timeout.create());
|
|
974
|
+
__publicField(this, "timeoutUnlock", Timeout.create());
|
|
975
|
+
__publicField(this, "release", () => {
|
|
976
|
+
this.lockCount -= 1;
|
|
977
|
+
if (this.lockCount === 0 && this.restore) {
|
|
978
|
+
this.timeoutUnlock.start(0, this.unlock);
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
__publicField(this, "unlock", () => {
|
|
982
|
+
var _a;
|
|
983
|
+
if (this.lockCount === 0 && this.restore) {
|
|
984
|
+
(_a = this.restore) == null ? void 0 : _a.call(this);
|
|
985
|
+
this.restore = null;
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
acquire(referenceElement) {
|
|
990
|
+
this.lockCount += 1;
|
|
991
|
+
if (this.lockCount === 1 && this.restore === null) {
|
|
992
|
+
this.timeoutLock.start(0, () => this.lock(referenceElement));
|
|
993
|
+
}
|
|
994
|
+
return this.release;
|
|
995
|
+
}
|
|
996
|
+
lock(referenceElement) {
|
|
997
|
+
if (this.lockCount === 0 || this.restore !== null) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const doc = ownerDocument(referenceElement);
|
|
1001
|
+
const html = doc.documentElement;
|
|
1002
|
+
const body = doc.body;
|
|
1003
|
+
const win = getWindow(html);
|
|
1004
|
+
if (isPageScrollLocked(win, html, body)) {
|
|
1005
|
+
const observer = new win.MutationObserver(() => {
|
|
1006
|
+
if (isPageScrollLocked(win, html, body)) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
observer.disconnect();
|
|
1010
|
+
this.restore = null;
|
|
1011
|
+
this.lock(referenceElement);
|
|
1012
|
+
});
|
|
1013
|
+
const options = {
|
|
1014
|
+
attributes: true
|
|
1015
|
+
};
|
|
1016
|
+
observer.observe(html, options);
|
|
1017
|
+
observer.observe(body, options);
|
|
1018
|
+
this.restore = () => observer.disconnect();
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
const hasOverlayScrollbars = ios || !hasInsetScrollbars(referenceElement);
|
|
1022
|
+
this.restore = hasOverlayScrollbars ? preventScrollOverlayScrollbars(referenceElement) : preventScrollInsetScrollbars(referenceElement);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
const SCROLL_LOCKER = new ScrollLocker();
|
|
1026
|
+
function useScrollLock(enabled = true, referenceElement = null) {
|
|
1027
|
+
useIsoLayoutEffect(() => {
|
|
1028
|
+
if (!enabled) {
|
|
1029
|
+
return void 0;
|
|
1030
|
+
}
|
|
1031
|
+
return SCROLL_LOCKER.acquire(referenceElement);
|
|
1032
|
+
}, [enabled, referenceElement]);
|
|
1033
|
+
}
|
|
1034
|
+
function useEnhancedClickHandler(handler) {
|
|
1035
|
+
const lastClickInteractionTypeRef = React.useRef("");
|
|
1036
|
+
const handlePointerDown = React.useCallback((event) => {
|
|
1037
|
+
if (event.defaultPrevented) {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
lastClickInteractionTypeRef.current = event.pointerType;
|
|
1041
|
+
handler(event, event.pointerType);
|
|
1042
|
+
}, [handler]);
|
|
1043
|
+
const handleClick = React.useCallback((event) => {
|
|
1044
|
+
if (event.detail === 0) {
|
|
1045
|
+
handler(event, "keyboard");
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if ("pointerType" in event) {
|
|
1049
|
+
handler(event, event.pointerType);
|
|
1050
|
+
} else {
|
|
1051
|
+
handler(event, lastClickInteractionTypeRef.current);
|
|
1052
|
+
}
|
|
1053
|
+
lastClickInteractionTypeRef.current = "";
|
|
1054
|
+
}, [handler]);
|
|
1055
|
+
return {
|
|
1056
|
+
onClick: handleClick,
|
|
1057
|
+
onPointerDown: handlePointerDown
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
function useOpenMethodTriggerProps(open, setOpenMethod) {
|
|
1061
|
+
const handleTriggerClick = useStableCallback((_, interactionType) => {
|
|
1062
|
+
const isOpen = typeof open === "function" ? open() : open;
|
|
1063
|
+
if (!isOpen) {
|
|
1064
|
+
setOpenMethod(interactionType || // On iOS Safari, the hitslop around touch targets means tapping outside an element's
|
|
1065
|
+
// bounds does not fire `pointerdown` but does fire `mousedown`. The `interactionType`
|
|
1066
|
+
// will be "" in that case.
|
|
1067
|
+
(ios ? "touch" : ""));
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
const {
|
|
1071
|
+
onClick,
|
|
1072
|
+
onPointerDown
|
|
1073
|
+
} = useEnhancedClickHandler(handleTriggerClick);
|
|
1074
|
+
return React.useMemo(() => ({
|
|
1075
|
+
onClick,
|
|
1076
|
+
onPointerDown
|
|
1077
|
+
}), [onClick, onPointerDown]);
|
|
1078
|
+
}
|
|
1079
|
+
export {
|
|
1080
|
+
FloatingFocusManager as F,
|
|
1081
|
+
InternalBackdrop as I,
|
|
1082
|
+
useClick as a,
|
|
1083
|
+
useOpenMethodTriggerProps as b,
|
|
1084
|
+
useScrollLock as u
|
|
1085
|
+
};
|
|
1086
|
+
//# sourceMappingURL=useOpenInteractionType-DGWLoAqp.js.map
|