@monimesl/dot-renderer-react 0.1.0-alpha.7 → 0.1.0-alpha.9
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 +39 -1
- package/dist/LICENSE-PHOSPHOR +21 -21
- package/dist/_virtual/_rolldown/runtime.js +14 -0
- package/dist/_virtual/builtin_esm-external-require-react.js +9 -0
- package/dist/color.js +105 -0
- package/dist/components/amount-input.d.ts +6 -0
- package/dist/components/amount-input.js +106 -0
- package/dist/components/button.d.ts +6 -0
- package/dist/components/button.js +42 -0
- package/dist/components/carousel.d.ts +6 -0
- package/dist/components/carousel.js +254 -0
- package/dist/components/chip.d.ts +6 -0
- package/dist/components/chip.js +41 -0
- package/dist/components/code-input.d.ts +6 -0
- package/dist/components/code-input.js +97 -0
- package/dist/components/detail-row.d.ts +6 -0
- package/dist/components/detail-row.js +40 -0
- package/dist/components/divider.d.ts +6 -0
- package/dist/components/divider.js +18 -0
- package/dist/components/empty-state.d.ts +6 -0
- package/dist/components/empty-state.js +66 -0
- package/dist/components/feedback.d.ts +8 -0
- package/dist/components/feedback.js +85 -0
- package/dist/components/field-box.js +44 -0
- package/dist/components/field.js +43 -0
- package/dist/components/footer.d.ts +6 -0
- package/dist/components/footer.js +24 -0
- package/dist/components/grid.d.ts +7 -0
- package/dist/components/grid.js +98 -0
- package/dist/components/icon-artwork.js +74 -0
- package/dist/components/icon.d.ts +6 -0
- package/dist/components/icon.js +40 -0
- package/dist/components/image.d.ts +6 -0
- package/dist/components/image.js +40 -0
- package/dist/components/index.d.ts +30 -0
- package/dist/components/index.js +72 -0
- package/dist/components/input.d.ts +6 -0
- package/dist/components/input.js +86 -0
- package/dist/components/link.d.ts +6 -0
- package/dist/components/link.js +39 -0
- package/dist/components/list.d.ts +7 -0
- package/dist/components/list.js +143 -0
- package/dist/components/option-place.js +9 -0
- package/dist/components/option.d.ts +6 -0
- package/dist/components/option.js +43 -0
- package/dist/components/padding.d.ts +2 -0
- package/dist/components/padding.js +27 -0
- package/dist/components/pressable.js +17 -0
- package/dist/components/qr-code.d.ts +6 -0
- package/dist/components/qr-code.js +58 -0
- package/dist/components/scroll.d.ts +6 -0
- package/dist/components/scroll.js +55 -0
- package/dist/components/select.d.ts +6 -0
- package/dist/components/select.js +92 -0
- package/dist/components/sheet.d.ts +8 -0
- package/dist/components/sheet.js +105 -0
- package/dist/components/skeleton.d.ts +6 -0
- package/dist/components/skeleton.js +55 -0
- package/dist/components/spinner.d.ts +6 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/tabs.d.ts +7 -0
- package/dist/components/tabs.js +91 -0
- package/dist/components/text-area.d.ts +6 -0
- package/dist/components/text-area.js +42 -0
- package/dist/components/text.d.ts +6 -0
- package/dist/components/text.js +46 -0
- package/dist/components/toast.d.ts +6 -0
- package/dist/components/toast.js +56 -0
- package/dist/components/toggles.d.ts +9 -0
- package/dist/components/toggles.js +149 -0
- package/dist/components/tokens.js +37 -0
- package/dist/components/tones.js +24 -0
- package/dist/components/typed-text.js +28 -0
- package/dist/components/view.d.ts +6 -0
- package/dist/components/view.js +51 -0
- package/dist/index.d.ts +35 -64
- package/dist/index.js +32 -22636
- package/dist/page-root.d.ts +2 -0
- package/dist/page-root.js +20 -0
- package/dist/portal.js +8 -0
- package/dist/renderer.d.ts +17 -0
- package/dist/renderer.js +33 -0
- package/dist/root.d.ts +10 -0
- package/dist/root.js +51 -0
- package/dist/styles.css +95 -1
- package/dist/theme.d.ts +25 -0
- package/dist/theme.js +84 -0
- package/dist/types.d.ts +7 -0
- package/dist/vendor/@base-ui/react/checkbox/indicator/CheckboxIndicator.js +51 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRoot.js +265 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/checkbox/utils/getCheckboxStateAttributesMapping.js +15 -0
- package/dist/vendor/@base-ui/react/checkbox-group/CheckboxGroupContext.js +10 -0
- package/dist/vendor/@base-ui/react/dialog/backdrop/DialogBackdrop.js +40 -0
- package/dist/vendor/@base-ui/react/dialog/close/DialogClose.js +39 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopup.js +92 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopupCssVars.js +8 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopupDataAttributes.js +7 -0
- package/dist/vendor/@base-ui/react/dialog/portal/DialogPortal.js +38 -0
- package/dist/vendor/@base-ui/react/dialog/portal/DialogPortalContext.js +13 -0
- package/dist/vendor/@base-ui/react/dialog/root/DialogRoot.js +16 -0
- package/dist/vendor/@base-ui/react/dialog/root/DialogRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/dialog/root/useDialogRoot.js +77 -0
- package/dist/vendor/@base-ui/react/dialog/root/useRenderDialogRoot.js +65 -0
- package/dist/vendor/@base-ui/react/dialog/store/DialogStore.js +70 -0
- package/dist/vendor/@base-ui/react/dialog/title/DialogTitle.js +25 -0
- package/dist/vendor/@base-ui/react/dialog/utils/stateAttributesMapping.js +17 -0
- package/dist/vendor/@base-ui/react/field/control/FieldControlDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/field/item/FieldItemContext.js +10 -0
- package/dist/vendor/@base-ui/react/field/root/useFieldValidation.js +18 -0
- package/dist/vendor/@base-ui/react/fieldset/root/FieldsetRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingFocusManager.js +477 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingPortal.js +165 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingRootStore.js +65 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingTree.js +22 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/hooks/useDismiss.js +373 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/hooks/useSyncedFloatingRootContext.js +58 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/composite.js +40 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/constants.js +5 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/createAttribute.js +6 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/createEventEmitter.js +18 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/element.js +26 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/enqueueFocus.js +25 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/event.js +25 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/markOthers.js +116 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/nodes.js +16 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/tabbable.js +135 -0
- package/dist/vendor/@base-ui/react/internals/TransitionStatusDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/internals/composite/composite.js +89 -0
- package/dist/vendor/@base-ui/react/internals/composite/constants.js +4 -0
- package/dist/vendor/@base-ui/react/internals/composite/item/CompositeItem.js +21 -0
- package/dist/vendor/@base-ui/react/internals/composite/item/useCompositeItem.js +31 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/CompositeList.js +180 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/CompositeListContext.js +15 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/useCompositeListItem.js +54 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/CompositeRoot.js +62 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/CompositeRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/useCompositeRoot.js +170 -0
- package/dist/vendor/@base-ui/react/internals/constants.js +18 -0
- package/dist/vendor/@base-ui/react/internals/createBaseUIEventDetails.js +40 -0
- package/dist/vendor/@base-ui/react/internals/direction-context/DirectionContext.js +10 -0
- package/dist/vendor/@base-ui/react/internals/field-constants/constants.js +33 -0
- package/dist/vendor/@base-ui/react/internals/field-register-control/useRegisterFieldControl.js +40 -0
- package/dist/vendor/@base-ui/react/internals/field-root-context/FieldRootContext.js +45 -0
- package/dist/vendor/@base-ui/react/internals/form-context/FormContext.js +18 -0
- package/dist/vendor/@base-ui/react/internals/getStateAttributesProps.js +17 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/LabelableContext.js +24 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/useAriaLabelledBy.js +35 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/useLabelableId.js +57 -0
- package/dist/vendor/@base-ui/react/internals/reason-parts.js +14 -0
- package/dist/vendor/@base-ui/react/internals/serializeValue.js +12 -0
- package/dist/vendor/@base-ui/react/internals/stateAttributesMapping.js +11 -0
- package/dist/vendor/@base-ui/react/internals/use-button/useButton.js +137 -0
- package/dist/vendor/@base-ui/react/internals/useAnimationsFinished.js +94 -0
- package/dist/vendor/@base-ui/react/internals/useBaseUiId.js +13 -0
- package/dist/vendor/@base-ui/react/internals/useOpenChangeComplete.js +28 -0
- package/dist/vendor/@base-ui/react/internals/useRenderElement.js +109 -0
- package/dist/vendor/@base-ui/react/internals/useTransitionStatus.js +70 -0
- package/dist/vendor/@base-ui/react/internals/useValueChanged.js +15 -0
- package/dist/vendor/@base-ui/react/merge-props/mergeProps.js +153 -0
- package/dist/vendor/@base-ui/react/radio/indicator/RadioIndicator.js +46 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRoot.js +179 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/radio/utils/stateAttributesMapping.js +14 -0
- package/dist/vendor/@base-ui/react/radio-group/RadioGroup.js +170 -0
- package/dist/vendor/@base-ui/react/radio-group/RadioGroupContext.js +10 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRoot.js +170 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/switch/stateAttributesMapping.js +12 -0
- package/dist/vendor/@base-ui/react/switch/thumb/SwitchThumb.js +25 -0
- package/dist/vendor/@base-ui/react/tabs/list/TabsList.js +98 -0
- package/dist/vendor/@base-ui/react/tabs/list/TabsListContext.js +13 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRoot.js +213 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRootContext.js +16 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRootDataAttributes.js +8 -0
- package/dist/vendor/@base-ui/react/tabs/root/stateAttributesMapping.js +5 -0
- package/dist/vendor/@base-ui/react/tabs/tab/TabsTab.js +137 -0
- package/dist/vendor/@base-ui/react/utils/CommonPopupDataAttributes.js +24 -0
- package/dist/vendor/@base-ui/react/utils/CommonTriggerDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/utils/FocusGuard.js +32 -0
- package/dist/vendor/@base-ui/react/utils/InternalBackdrop.js +30 -0
- package/dist/vendor/@base-ui/react/utils/dispatchClickWithModifiers.js +25 -0
- package/dist/vendor/@base-ui/react/utils/popupStateMapping.js +22 -0
- package/dist/vendor/@base-ui/react/utils/popups/popupStoreUtils.js +247 -0
- package/dist/vendor/@base-ui/react/utils/popups/popupTriggerMap.js +96 -0
- package/dist/vendor/@base-ui/react/utils/popups/store.js +94 -0
- package/dist/vendor/@base-ui/react/utils/resolveClassName.js +13 -0
- package/dist/vendor/@base-ui/react/utils/resolveRef.js +11 -0
- package/dist/vendor/@base-ui/react/utils/resolveStyle.js +13 -0
- package/dist/vendor/@base-ui/react/utils/useFocusableWhenDisabled.js +30 -0
- package/dist/vendor/@base-ui/utils/addEventListener.js +12 -0
- package/dist/vendor/@base-ui/utils/createLogOnce.js +20 -0
- package/dist/vendor/@base-ui/utils/empty.js +6 -0
- package/dist/vendor/@base-ui/utils/error.js +5 -0
- package/dist/vendor/@base-ui/utils/fastHooks.js +68 -0
- package/dist/vendor/@base-ui/utils/formatErrorMessage.js +27 -0
- package/dist/vendor/@base-ui/utils/getDefaultFormSubmitter.js +25 -0
- package/dist/vendor/@base-ui/utils/getReactElementRef.js +14 -0
- package/dist/vendor/@base-ui/utils/inertValue.js +8 -0
- package/dist/vendor/@base-ui/utils/isElementDisabled.js +6 -0
- package/dist/vendor/@base-ui/utils/mergeCleanups.js +14 -0
- package/dist/vendor/@base-ui/utils/mergeObjects.js +11 -0
- package/dist/vendor/@base-ui/utils/owner.js +7 -0
- package/dist/vendor/@base-ui/utils/platform/engine.js +8 -0
- package/dist/vendor/@base-ui/utils/platform/env.js +6 -0
- package/dist/vendor/@base-ui/utils/platform/os.js +15 -0
- package/dist/vendor/@base-ui/utils/platform/screen-reader.js +9 -0
- package/dist/vendor/@base-ui/utils/platform/shared.js +36 -0
- package/dist/vendor/@base-ui/utils/reactVersion.js +8 -0
- package/dist/vendor/@base-ui/utils/safeReact.js +13 -0
- package/dist/vendor/@base-ui/utils/shadowDom.js +26 -0
- package/dist/vendor/@base-ui/utils/store/ReactStore.js +181 -0
- package/dist/vendor/@base-ui/utils/store/Store.js +102 -0
- package/dist/vendor/@base-ui/utils/store/useStore.js +97 -0
- package/dist/vendor/@base-ui/utils/useAnimationFrame.js +87 -0
- package/dist/vendor/@base-ui/utils/useControlled.js +52 -0
- package/dist/vendor/@base-ui/utils/useId.js +32 -0
- package/dist/vendor/@base-ui/utils/useIsoLayoutEffect.js +7 -0
- package/dist/vendor/@base-ui/utils/useMergedRefs.js +87 -0
- package/dist/vendor/@base-ui/utils/useOnMount.js +12 -0
- package/dist/vendor/@base-ui/utils/useRefWithInit.js +18 -0
- package/dist/vendor/@base-ui/utils/useScrollLock.js +206 -0
- package/dist/vendor/@base-ui/utils/useStableCallback.js +38 -0
- package/dist/vendor/@base-ui/utils/useTimeout.js +43 -0
- package/dist/vendor/@base-ui/utils/useValueAsRef.js +27 -0
- package/dist/vendor/@base-ui/utils/visuallyHidden.js +23 -0
- package/dist/vendor/@base-ui/utils/warn.js +5 -0
- package/dist/vendor/@floating-ui/utils/dist/floating-ui.utils.dom.js +49 -0
- package/dist/vendor/uqr/dist/index.js +858 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +74 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js +77 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +69 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +64 -0
- package/dist/vendor/use-sync-external-store/shim/index.js +11 -0
- package/dist/vendor/use-sync-external-store/shim/with-selector.js +11 -0
- package/package.json +8 -14
- package/dist/garra-versions.json +0 -7
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMergedRefs } from "../../../utils/useMergedRefs.js";
|
|
3
|
+
import { getNodeName, getWindow, isHTMLElement } from "../../../../@floating-ui/utils/dist/floating-ui.utils.dom.js";
|
|
4
|
+
import { useStableCallback } from "../../../utils/useStableCallback.js";
|
|
5
|
+
import { useIsoLayoutEffect } from "../../../utils/useIsoLayoutEffect.js";
|
|
6
|
+
import { ownerDocument } from "../../../utils/owner.js";
|
|
7
|
+
import { focusOut } from "../../internals/reason-parts.js";
|
|
8
|
+
import { createChangeEventDetails } from "../../internals/createBaseUIEventDetails.js";
|
|
9
|
+
import { useTimeout } from "../../../utils/useTimeout.js";
|
|
10
|
+
import { webkit } from "../../../utils/platform/engine.js";
|
|
11
|
+
import { isVirtualClick, isVirtualPointerEvent, stopEvent } from "../utils/event.js";
|
|
12
|
+
import { activeElement, contains, getTarget } from "../../../utils/shadowDom.js";
|
|
13
|
+
import { getFloatingFocusElement, isTypeableCombobox, isTypeableElement } from "../utils/element.js";
|
|
14
|
+
import { addEventListener } from "../../../utils/addEventListener.js";
|
|
15
|
+
import { mergeCleanups } from "../../../utils/mergeCleanups.js";
|
|
16
|
+
import { useValueAsRef } from "../../../utils/useValueAsRef.js";
|
|
17
|
+
import { useAnimationFrame } from "../../../utils/useAnimationFrame.js";
|
|
18
|
+
import { FocusGuard } from "../../utils/FocusGuard.js";
|
|
19
|
+
import { isElementVisible } from "../utils/composite.js";
|
|
20
|
+
import { focusable, getNextTabbable, getPreviousTabbable, isOutsideEvent, isTabbable, tabbable } from "../utils/tabbable.js";
|
|
21
|
+
import { getNodeAncestors, getNodeChildren } from "../utils/nodes.js";
|
|
22
|
+
import { createAttribute } from "../utils/createAttribute.js";
|
|
23
|
+
import { enqueueFocus } from "../utils/enqueueFocus.js";
|
|
24
|
+
import { markOthers } from "../utils/markOthers.js";
|
|
25
|
+
import "../../internals/constants.js";
|
|
26
|
+
import { usePortalContext } from "./FloatingPortal.js";
|
|
27
|
+
import { useFloatingTree } from "./FloatingTree.js";
|
|
28
|
+
import { resolveRef } from "../../utils/resolveRef.js";
|
|
29
|
+
import * as React from "react";
|
|
30
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
31
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/floating-ui-react/components/FloatingFocusManager.mjs
|
|
32
|
+
function getEventType(event, lastInteractionType) {
|
|
33
|
+
const win = getWindow(getTarget(event));
|
|
34
|
+
if (event instanceof win.KeyboardEvent) return "keyboard";
|
|
35
|
+
if (event instanceof win.FocusEvent) return lastInteractionType || "keyboard";
|
|
36
|
+
if ("pointerType" in event) return event.pointerType || "keyboard";
|
|
37
|
+
if ("touches" in event) return "touch";
|
|
38
|
+
if (event instanceof win.MouseEvent) return lastInteractionType || (event.detail === 0 ? "keyboard" : "mouse");
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
const LIST_LIMIT = 20;
|
|
42
|
+
let previouslyFocusedElements = [];
|
|
43
|
+
function clearDisconnectedPreviouslyFocusedElements() {
|
|
44
|
+
previouslyFocusedElements = previouslyFocusedElements.filter((entry) => {
|
|
45
|
+
return entry.deref()?.isConnected;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function addPreviouslyFocusedElement(element) {
|
|
49
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
50
|
+
if (element && getNodeName(element) !== "body") {
|
|
51
|
+
previouslyFocusedElements.push(new WeakRef(element));
|
|
52
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) previouslyFocusedElements = previouslyFocusedElements.slice(-20);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function getPreviouslyFocusedElement() {
|
|
56
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
57
|
+
return previouslyFocusedElements[previouslyFocusedElements.length - 1]?.deref();
|
|
58
|
+
}
|
|
59
|
+
function getFirstTabbableElement(container) {
|
|
60
|
+
if (!container) return null;
|
|
61
|
+
if (isTabbable(container)) return container;
|
|
62
|
+
return tabbable(container)[0] || container;
|
|
63
|
+
}
|
|
64
|
+
function handleTabIndex(floatingFocusElement) {
|
|
65
|
+
if (floatingFocusElement.hasAttribute("tabindex") && !floatingFocusElement.hasAttribute("data-tabindex")) return;
|
|
66
|
+
if (!floatingFocusElement.getAttribute("role")?.includes("dialog")) return;
|
|
67
|
+
const tabbableContent = focusable(floatingFocusElement).filter((element) => {
|
|
68
|
+
const dataTabIndex = element.getAttribute("data-tabindex") || "";
|
|
69
|
+
return isTabbable(element) || element.hasAttribute("data-tabindex") && !dataTabIndex.startsWith("-");
|
|
70
|
+
});
|
|
71
|
+
const tabIndex = floatingFocusElement.getAttribute("tabindex");
|
|
72
|
+
if (tabbableContent.length === 0) {
|
|
73
|
+
if (tabIndex !== "0") {
|
|
74
|
+
floatingFocusElement.setAttribute("tabindex", "0");
|
|
75
|
+
floatingFocusElement.setAttribute("data-tabindex", "0");
|
|
76
|
+
}
|
|
77
|
+
} else if (tabIndex !== "-1" || floatingFocusElement.hasAttribute("data-tabindex") && floatingFocusElement.getAttribute("data-tabindex") !== "-1") {
|
|
78
|
+
floatingFocusElement.setAttribute("tabindex", "-1");
|
|
79
|
+
floatingFocusElement.setAttribute("data-tabindex", "-1");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Provides focus management for the floating element.
|
|
84
|
+
* @see https://floating-ui.com/docs/FloatingFocusManager
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
function FloatingFocusManager(props) {
|
|
88
|
+
const { context, children, disabled = false, initialFocus = true, returnFocus = true, restoreFocus = false, modal = true, closeOnFocusOut = true, openInteractionType = "", nextFocusableElement, previousFocusableElement, beforeContentFocusGuardRef, externalTree, getInsideElements } = props;
|
|
89
|
+
const store = "rootStore" in context ? context.rootStore : context;
|
|
90
|
+
const open = store.useState("open");
|
|
91
|
+
const domReference = store.useState("domReferenceElement");
|
|
92
|
+
const floating = store.useState("floatingElement");
|
|
93
|
+
const { events, dataRef } = store.context;
|
|
94
|
+
const getNodeId = useStableCallback(() => dataRef.current.floatingContext?.nodeId);
|
|
95
|
+
const ignoreInitialFocus = initialFocus === false;
|
|
96
|
+
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
97
|
+
const initialFocusRef = useValueAsRef(initialFocus);
|
|
98
|
+
const returnFocusRef = useValueAsRef(returnFocus);
|
|
99
|
+
const openInteractionTypeRef = useValueAsRef(openInteractionType);
|
|
100
|
+
const openRef = useValueAsRef(open);
|
|
101
|
+
const tree = useFloatingTree(externalTree);
|
|
102
|
+
const portalContext = usePortalContext();
|
|
103
|
+
const preventReturnFocusRef = React.useRef(false);
|
|
104
|
+
const isPointerDownRef = React.useRef(false);
|
|
105
|
+
const pointerDownOutsideRef = React.useRef(false);
|
|
106
|
+
const lastFocusedTabbableRef = React.useRef(null);
|
|
107
|
+
const closeTypeRef = React.useRef("");
|
|
108
|
+
const lastInteractionTypeRef = React.useRef("");
|
|
109
|
+
const beforeGuardRef = React.useRef(null);
|
|
110
|
+
const afterGuardRef = React.useRef(null);
|
|
111
|
+
const mergedBeforeGuardRef = useMergedRefs(beforeGuardRef, beforeContentFocusGuardRef, portalContext?.beforeInsideRef);
|
|
112
|
+
const mergedAfterGuardRef = useMergedRefs(afterGuardRef, portalContext?.afterInsideRef);
|
|
113
|
+
const blurTimeout = useTimeout();
|
|
114
|
+
const pointerDownTimeout = useTimeout();
|
|
115
|
+
const restoreFocusFrame = useAnimationFrame();
|
|
116
|
+
const isInsidePortal = portalContext != null;
|
|
117
|
+
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
118
|
+
const getTabbableContent = useStableCallback((container = floatingFocusElement) => {
|
|
119
|
+
return container ? tabbable(container) : [];
|
|
120
|
+
});
|
|
121
|
+
const getResolvedInsideElements = useStableCallback(() => getInsideElements?.().filter((element) => element != null) ?? []);
|
|
122
|
+
React.useEffect(() => {
|
|
123
|
+
if (disabled || !modal) return;
|
|
124
|
+
function onKeyDown(event) {
|
|
125
|
+
if (event.key === "Tab") {
|
|
126
|
+
if (contains(floatingFocusElement, activeElement(ownerDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) stopEvent(event);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
130
|
+
return addEventListener(doc, "keydown", onKeyDown);
|
|
131
|
+
}, [
|
|
132
|
+
disabled,
|
|
133
|
+
floatingFocusElement,
|
|
134
|
+
modal,
|
|
135
|
+
isUntrappedTypeableCombobox,
|
|
136
|
+
getTabbableContent
|
|
137
|
+
]);
|
|
138
|
+
React.useEffect(() => {
|
|
139
|
+
if (disabled || !open) return;
|
|
140
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
141
|
+
function clearPointerDownOutside() {
|
|
142
|
+
pointerDownOutsideRef.current = false;
|
|
143
|
+
}
|
|
144
|
+
function onPointerDown(event) {
|
|
145
|
+
const target = getTarget(event);
|
|
146
|
+
const insideElements = getResolvedInsideElements();
|
|
147
|
+
const pointerTargetInside = contains(floating, target) || contains(domReference, target) || contains(portalContext?.portalNode, target) || insideElements.some((element) => element === target || contains(element, target));
|
|
148
|
+
pointerDownOutsideRef.current = !pointerTargetInside;
|
|
149
|
+
lastInteractionTypeRef.current = event.pointerType || "keyboard";
|
|
150
|
+
if (target?.closest(`[data-base-ui-click-trigger]`)) {
|
|
151
|
+
isPointerDownRef.current = true;
|
|
152
|
+
pointerDownTimeout.start(0, () => {
|
|
153
|
+
isPointerDownRef.current = false;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function onKeyDown() {
|
|
158
|
+
lastInteractionTypeRef.current = "keyboard";
|
|
159
|
+
}
|
|
160
|
+
return mergeCleanups(addEventListener(doc, "pointerdown", onPointerDown, true), addEventListener(doc, "pointerup", clearPointerDownOutside, true), addEventListener(doc, "pointercancel", clearPointerDownOutside, true), addEventListener(doc, "keydown", onKeyDown, true), clearPointerDownOutside);
|
|
161
|
+
}, [
|
|
162
|
+
disabled,
|
|
163
|
+
floating,
|
|
164
|
+
domReference,
|
|
165
|
+
floatingFocusElement,
|
|
166
|
+
open,
|
|
167
|
+
portalContext,
|
|
168
|
+
pointerDownTimeout,
|
|
169
|
+
getResolvedInsideElements
|
|
170
|
+
]);
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
if (disabled || !closeOnFocusOut) return;
|
|
173
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
174
|
+
function handlePointerDown() {
|
|
175
|
+
isPointerDownRef.current = true;
|
|
176
|
+
pointerDownTimeout.start(0, () => {
|
|
177
|
+
isPointerDownRef.current = false;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function handleFocusIn(event) {
|
|
181
|
+
const target = getTarget(event);
|
|
182
|
+
if (isTabbable(target)) lastFocusedTabbableRef.current = target;
|
|
183
|
+
}
|
|
184
|
+
function handleFocusOutside(event) {
|
|
185
|
+
const relatedTarget = event.relatedTarget;
|
|
186
|
+
const currentTarget = event.currentTarget;
|
|
187
|
+
const target = getTarget(event);
|
|
188
|
+
if (modal && relatedTarget == null && target != null && contains(floating, target)) addPreviouslyFocusedElement(target);
|
|
189
|
+
queueMicrotask(() => {
|
|
190
|
+
const nodeId = getNodeId();
|
|
191
|
+
const triggers = store.context.triggerElements;
|
|
192
|
+
const insideElements = getResolvedInsideElements();
|
|
193
|
+
const isRelatedFocusGuard = relatedTarget?.hasAttribute(createAttribute("focus-guard")) && [
|
|
194
|
+
beforeGuardRef.current,
|
|
195
|
+
afterGuardRef.current,
|
|
196
|
+
portalContext?.beforeInsideRef.current,
|
|
197
|
+
portalContext?.afterInsideRef.current,
|
|
198
|
+
portalContext?.beforeOutsideRef.current,
|
|
199
|
+
portalContext?.afterOutsideRef.current,
|
|
200
|
+
resolveRef(previousFocusableElement),
|
|
201
|
+
resolveRef(nextFocusableElement)
|
|
202
|
+
].includes(relatedTarget);
|
|
203
|
+
const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(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) => contains(node.context?.elements.floating, relatedTarget) || contains(node.context?.elements.domReference, relatedTarget)) || getNodeAncestors(tree.nodesRef.current, nodeId).find((node) => [node.context?.elements.floating, getFloatingFocusElement(node.context?.elements.floating)].includes(relatedTarget) || node.context?.elements.domReference === relatedTarget)));
|
|
204
|
+
if (currentTarget === domReference && floatingFocusElement) handleTabIndex(floatingFocusElement);
|
|
205
|
+
if (restoreFocus && currentTarget !== domReference && !isElementVisible(target) && activeElement(doc) === doc.body) {
|
|
206
|
+
if (isHTMLElement(floatingFocusElement)) {
|
|
207
|
+
floatingFocusElement.focus();
|
|
208
|
+
if (restoreFocus === "popup") {
|
|
209
|
+
restoreFocusFrame.request(() => {
|
|
210
|
+
floatingFocusElement.focus();
|
|
211
|
+
});
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const tabbableContent = getTabbableContent();
|
|
216
|
+
const prevTabbable = lastFocusedTabbableRef.current;
|
|
217
|
+
const nodeToFocus = (prevTabbable && tabbableContent.includes(prevTabbable) ? prevTabbable : null) || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
218
|
+
if (isHTMLElement(nodeToFocus)) nodeToFocus.focus();
|
|
219
|
+
}
|
|
220
|
+
if (dataRef.current.insideReactTree) {
|
|
221
|
+
dataRef.current.insideReactTree = false;
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && (isUntrappedTypeableCombobox || relatedTarget !== getPreviouslyFocusedElement())) {
|
|
225
|
+
preventReturnFocusRef.current = true;
|
|
226
|
+
store.setOpen(false, createChangeEventDetails(focusOut, event));
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function markInsideReactTree() {
|
|
231
|
+
if (pointerDownOutsideRef.current) return;
|
|
232
|
+
dataRef.current.insideReactTree = true;
|
|
233
|
+
blurTimeout.start(0, () => {
|
|
234
|
+
dataRef.current.insideReactTree = false;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const domReferenceElement = isHTMLElement(domReference) ? domReference : null;
|
|
238
|
+
if (!floating && !domReferenceElement) return;
|
|
239
|
+
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));
|
|
240
|
+
}, [
|
|
241
|
+
disabled,
|
|
242
|
+
domReference,
|
|
243
|
+
floating,
|
|
244
|
+
floatingFocusElement,
|
|
245
|
+
modal,
|
|
246
|
+
tree,
|
|
247
|
+
portalContext,
|
|
248
|
+
store,
|
|
249
|
+
closeOnFocusOut,
|
|
250
|
+
restoreFocus,
|
|
251
|
+
getTabbableContent,
|
|
252
|
+
isUntrappedTypeableCombobox,
|
|
253
|
+
getNodeId,
|
|
254
|
+
dataRef,
|
|
255
|
+
blurTimeout,
|
|
256
|
+
pointerDownTimeout,
|
|
257
|
+
restoreFocusFrame,
|
|
258
|
+
nextFocusableElement,
|
|
259
|
+
previousFocusableElement,
|
|
260
|
+
getResolvedInsideElements
|
|
261
|
+
]);
|
|
262
|
+
React.useEffect(() => {
|
|
263
|
+
if (disabled || !floating || !open) return;
|
|
264
|
+
const portalNodes = Array.from(portalContext?.portalNode?.querySelectorAll(`[${createAttribute("portal")}]`) || []);
|
|
265
|
+
const rootAncestorComboboxDomReference = (tree ? getNodeAncestors(tree.nodesRef.current, getNodeId()) : []).find((node) => isTypeableCombobox(node.context?.elements.domReference || null))?.context?.elements.domReference;
|
|
266
|
+
const insideElements = [
|
|
267
|
+
...[
|
|
268
|
+
floating,
|
|
269
|
+
...portalNodes,
|
|
270
|
+
beforeGuardRef.current,
|
|
271
|
+
afterGuardRef.current,
|
|
272
|
+
portalContext?.beforeOutsideRef.current,
|
|
273
|
+
portalContext?.afterOutsideRef.current,
|
|
274
|
+
...getResolvedInsideElements()
|
|
275
|
+
],
|
|
276
|
+
rootAncestorComboboxDomReference,
|
|
277
|
+
resolveRef(previousFocusableElement),
|
|
278
|
+
resolveRef(nextFocusableElement),
|
|
279
|
+
isUntrappedTypeableCombobox ? domReference : null
|
|
280
|
+
].filter((x) => x != null);
|
|
281
|
+
const ariaHiddenCleanup = markOthers(insideElements, {
|
|
282
|
+
ariaHidden: modal || isUntrappedTypeableCombobox,
|
|
283
|
+
mark: false
|
|
284
|
+
});
|
|
285
|
+
const markerInsideElements = [floating, ...portalNodes].filter((x) => x != null);
|
|
286
|
+
const markerCleanup = markOthers(markerInsideElements);
|
|
287
|
+
return () => {
|
|
288
|
+
markerCleanup();
|
|
289
|
+
ariaHiddenCleanup();
|
|
290
|
+
};
|
|
291
|
+
}, [
|
|
292
|
+
open,
|
|
293
|
+
disabled,
|
|
294
|
+
domReference,
|
|
295
|
+
floating,
|
|
296
|
+
modal,
|
|
297
|
+
portalContext,
|
|
298
|
+
isUntrappedTypeableCombobox,
|
|
299
|
+
tree,
|
|
300
|
+
getNodeId,
|
|
301
|
+
nextFocusableElement,
|
|
302
|
+
previousFocusableElement,
|
|
303
|
+
getResolvedInsideElements
|
|
304
|
+
]);
|
|
305
|
+
useIsoLayoutEffect(() => {
|
|
306
|
+
if (!open || disabled || !isHTMLElement(floatingFocusElement)) return;
|
|
307
|
+
closeTypeRef.current = "";
|
|
308
|
+
lastInteractionTypeRef.current = "";
|
|
309
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
310
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
311
|
+
queueMicrotask(() => {
|
|
312
|
+
const initialFocusValueOrFn = initialFocusRef.current;
|
|
313
|
+
const resolvedInitialFocus = typeof initialFocusValueOrFn === "function" ? initialFocusValueOrFn(openInteractionTypeRef.current || "") : initialFocusValueOrFn;
|
|
314
|
+
if (resolvedInitialFocus === void 0 || resolvedInitialFocus === false) return;
|
|
315
|
+
if (contains(floatingFocusElement, previouslyFocusedElement)) return;
|
|
316
|
+
let focusableElements = null;
|
|
317
|
+
const getDefaultFocusElement = () => {
|
|
318
|
+
if (focusableElements == null) focusableElements = getTabbableContent(floatingFocusElement);
|
|
319
|
+
return focusableElements[0] || floatingFocusElement;
|
|
320
|
+
};
|
|
321
|
+
let elToFocus;
|
|
322
|
+
if (resolvedInitialFocus === true || resolvedInitialFocus === null) elToFocus = getDefaultFocusElement();
|
|
323
|
+
else elToFocus = resolveRef(resolvedInitialFocus);
|
|
324
|
+
elToFocus = elToFocus || getDefaultFocusElement();
|
|
325
|
+
const hadFocusInside = contains(floatingFocusElement, activeElement(doc));
|
|
326
|
+
enqueueFocus(elToFocus, {
|
|
327
|
+
preventScroll: elToFocus === floatingFocusElement,
|
|
328
|
+
shouldFocus() {
|
|
329
|
+
if (!openRef.current) return false;
|
|
330
|
+
if (hadFocusInside) return true;
|
|
331
|
+
const currentActiveElement = activeElement(doc);
|
|
332
|
+
return !(currentActiveElement !== elToFocus && contains(floatingFocusElement, currentActiveElement));
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}, [
|
|
337
|
+
disabled,
|
|
338
|
+
open,
|
|
339
|
+
floatingFocusElement,
|
|
340
|
+
getTabbableContent,
|
|
341
|
+
initialFocusRef,
|
|
342
|
+
openInteractionTypeRef,
|
|
343
|
+
openRef
|
|
344
|
+
]);
|
|
345
|
+
useIsoLayoutEffect(() => {
|
|
346
|
+
if (disabled || !floatingFocusElement) return;
|
|
347
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
348
|
+
const elementFocusedBeforeOpen = activeElement(doc);
|
|
349
|
+
const preferPreviousFocus = openInteractionTypeRef.current == null;
|
|
350
|
+
addPreviouslyFocusedElement(elementFocusedBeforeOpen);
|
|
351
|
+
function onOpenChangeLocal(details) {
|
|
352
|
+
if (!details.open) closeTypeRef.current = getEventType(details.nativeEvent, lastInteractionTypeRef.current);
|
|
353
|
+
if (details.reason === "trigger-hover" && details.nativeEvent.type === "mouseleave") preventReturnFocusRef.current = true;
|
|
354
|
+
if (details.reason !== "outside-press") return;
|
|
355
|
+
if (details.nested) preventReturnFocusRef.current = false;
|
|
356
|
+
else if (isVirtualClick(details.nativeEvent) || isVirtualPointerEvent(details.nativeEvent)) preventReturnFocusRef.current = false;
|
|
357
|
+
else {
|
|
358
|
+
let isPreventScrollSupported = false;
|
|
359
|
+
ownerDocument(floatingFocusElement).createElement("div").focus({ get preventScroll() {
|
|
360
|
+
isPreventScrollSupported = true;
|
|
361
|
+
return false;
|
|
362
|
+
} });
|
|
363
|
+
if (isPreventScrollSupported) preventReturnFocusRef.current = false;
|
|
364
|
+
else preventReturnFocusRef.current = true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
events.on("openchange", onOpenChangeLocal);
|
|
368
|
+
function getReturnElement(closeType) {
|
|
369
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
370
|
+
let resolvedReturnFocusValue = typeof returnFocusValueOrFn === "function" ? returnFocusValueOrFn(closeType) : returnFocusValueOrFn;
|
|
371
|
+
if (resolvedReturnFocusValue === void 0 || resolvedReturnFocusValue === false) return null;
|
|
372
|
+
if (resolvedReturnFocusValue === null) resolvedReturnFocusValue = true;
|
|
373
|
+
const referenceReturnElement = domReference?.isConnected ? domReference : null;
|
|
374
|
+
const previousReturnElement = elementFocusedBeforeOpen?.isConnected && getNodeName(elementFocusedBeforeOpen) !== "body" ? elementFocusedBeforeOpen : null;
|
|
375
|
+
let defaultReturnElement = preferPreviousFocus ? previousReturnElement || referenceReturnElement : referenceReturnElement || previousReturnElement;
|
|
376
|
+
if (!defaultReturnElement) defaultReturnElement = getPreviouslyFocusedElement() || null;
|
|
377
|
+
if (typeof resolvedReturnFocusValue === "boolean") return defaultReturnElement;
|
|
378
|
+
return resolveRef(resolvedReturnFocusValue) || defaultReturnElement || null;
|
|
379
|
+
}
|
|
380
|
+
return () => {
|
|
381
|
+
events.off("openchange", onOpenChangeLocal);
|
|
382
|
+
const activeEl = activeElement(doc);
|
|
383
|
+
const insideElements = getResolvedInsideElements();
|
|
384
|
+
const isFocusInsideFloatingTree = contains(floating, activeEl) || insideElements.some((element) => element === activeEl || contains(element, activeEl)) || tree && getNodeChildren(tree.nodesRef.current, getNodeId(), false).some((node) => contains(node.context?.elements.floating, activeEl));
|
|
385
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
386
|
+
const closeType = closeTypeRef.current;
|
|
387
|
+
const returnElement = getReturnElement(closeType);
|
|
388
|
+
queueMicrotask(() => {
|
|
389
|
+
const tabbableReturnElement = getFirstTabbableElement(returnElement);
|
|
390
|
+
const hasExplicitReturnFocus = typeof returnFocusValueOrFn !== "boolean";
|
|
391
|
+
if (returnFocusValueOrFn && !preventReturnFocusRef.current && isHTMLElement(tabbableReturnElement) && (!hasExplicitReturnFocus && tabbableReturnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)) {
|
|
392
|
+
const focusOptions = { preventScroll: true };
|
|
393
|
+
if (closeType === "keyboard") focusOptions.focusVisible = true;
|
|
394
|
+
tabbableReturnElement.focus(focusOptions);
|
|
395
|
+
}
|
|
396
|
+
preventReturnFocusRef.current = false;
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
}, [
|
|
400
|
+
disabled,
|
|
401
|
+
floating,
|
|
402
|
+
floatingFocusElement,
|
|
403
|
+
returnFocusRef,
|
|
404
|
+
openInteractionTypeRef,
|
|
405
|
+
events,
|
|
406
|
+
tree,
|
|
407
|
+
domReference,
|
|
408
|
+
getNodeId,
|
|
409
|
+
getResolvedInsideElements
|
|
410
|
+
]);
|
|
411
|
+
useIsoLayoutEffect(() => {
|
|
412
|
+
if (!webkit || open || !floating) return;
|
|
413
|
+
const activeEl = activeElement(ownerDocument(floating));
|
|
414
|
+
if (!isHTMLElement(activeEl) || !isTypeableElement(activeEl)) return;
|
|
415
|
+
if (contains(floating, activeEl)) activeEl.blur();
|
|
416
|
+
}, [open, floating]);
|
|
417
|
+
useIsoLayoutEffect(() => {
|
|
418
|
+
if (disabled || !portalContext) return;
|
|
419
|
+
portalContext.setFocusManagerState({
|
|
420
|
+
modal,
|
|
421
|
+
closeOnFocusOut,
|
|
422
|
+
open,
|
|
423
|
+
onOpenChange: store.setOpen,
|
|
424
|
+
domReference
|
|
425
|
+
});
|
|
426
|
+
return () => {
|
|
427
|
+
portalContext.setFocusManagerState(null);
|
|
428
|
+
};
|
|
429
|
+
}, [
|
|
430
|
+
disabled,
|
|
431
|
+
portalContext,
|
|
432
|
+
modal,
|
|
433
|
+
open,
|
|
434
|
+
store,
|
|
435
|
+
closeOnFocusOut,
|
|
436
|
+
domReference
|
|
437
|
+
]);
|
|
438
|
+
useIsoLayoutEffect(() => {
|
|
439
|
+
if (disabled || !floatingFocusElement) return;
|
|
440
|
+
handleTabIndex(floatingFocusElement);
|
|
441
|
+
return () => {
|
|
442
|
+
queueMicrotask(clearDisconnectedPreviouslyFocusedElements);
|
|
443
|
+
};
|
|
444
|
+
}, [disabled, floatingFocusElement]);
|
|
445
|
+
const shouldRenderGuards = !disabled && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
446
|
+
return /*#__PURE__*/ jsxs(React.Fragment, { children: [
|
|
447
|
+
shouldRenderGuards && /*#__PURE__*/ jsx(FocusGuard, {
|
|
448
|
+
"data-type": "inside",
|
|
449
|
+
ref: mergedBeforeGuardRef,
|
|
450
|
+
onFocus: (event) => {
|
|
451
|
+
if (modal) {
|
|
452
|
+
const els = getTabbableContent();
|
|
453
|
+
enqueueFocus(els[els.length - 1]);
|
|
454
|
+
} else if (portalContext?.portalNode) {
|
|
455
|
+
preventReturnFocusRef.current = false;
|
|
456
|
+
if (isOutsideEvent(event, portalContext.portalNode)) getNextTabbable(domReference)?.focus();
|
|
457
|
+
else resolveRef(previousFocusableElement ?? portalContext.beforeOutsideRef)?.focus();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}),
|
|
461
|
+
children,
|
|
462
|
+
shouldRenderGuards && /*#__PURE__*/ jsx(FocusGuard, {
|
|
463
|
+
"data-type": "inside",
|
|
464
|
+
ref: mergedAfterGuardRef,
|
|
465
|
+
onFocus: (event) => {
|
|
466
|
+
if (modal) enqueueFocus(getTabbableContent()[0]);
|
|
467
|
+
else if (portalContext?.portalNode) {
|
|
468
|
+
if (closeOnFocusOut) preventReturnFocusRef.current = true;
|
|
469
|
+
if (isOutsideEvent(event, portalContext.portalNode)) getPreviousTabbable(domReference)?.focus();
|
|
470
|
+
else resolveRef(nextFocusableElement ?? portalContext.afterOutsideRef)?.focus();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
})
|
|
474
|
+
] });
|
|
475
|
+
}
|
|
476
|
+
//#endregion
|
|
477
|
+
export { FloatingFocusManager };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EMPTY_OBJECT } from "../../../utils/empty.js";
|
|
3
|
+
import { useRenderElement } from "../../internals/useRenderElement.js";
|
|
4
|
+
import { isNode } from "../../../../@floating-ui/utils/dist/floating-ui.utils.dom.js";
|
|
5
|
+
import { useStableCallback } from "../../../utils/useStableCallback.js";
|
|
6
|
+
import { useIsoLayoutEffect } from "../../../utils/useIsoLayoutEffect.js";
|
|
7
|
+
import "../../internals/reason-parts.js";
|
|
8
|
+
import { createChangeEventDetails } from "../../internals/createBaseUIEventDetails.js";
|
|
9
|
+
import { useId as useId$1 } from "../../../utils/useId.js";
|
|
10
|
+
import { addEventListener } from "../../../utils/addEventListener.js";
|
|
11
|
+
import { mergeCleanups } from "../../../utils/mergeCleanups.js";
|
|
12
|
+
import { FocusGuard } from "../../utils/FocusGuard.js";
|
|
13
|
+
import { disableFocusInside, enableFocusInside, getNextTabbable, getPreviousTabbable, isOutsideEvent } from "../utils/tabbable.js";
|
|
14
|
+
import { createAttribute } from "../utils/createAttribute.js";
|
|
15
|
+
import { ownerVisuallyHidden } from "../../internals/constants.js";
|
|
16
|
+
import * as React from "react";
|
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
import * as ReactDOM from "react-dom";
|
|
19
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/floating-ui-react/components/FloatingPortal.mjs
|
|
20
|
+
const PortalContext = /*#__PURE__*/ React.createContext(null);
|
|
21
|
+
if (process.env.NODE_ENV !== "production") PortalContext.displayName = "PortalContext";
|
|
22
|
+
const usePortalContext = () => React.useContext(PortalContext);
|
|
23
|
+
const attr = createAttribute("portal");
|
|
24
|
+
function useFloatingPortalNode(props = {}) {
|
|
25
|
+
const { ref, container: containerProp, componentProps = EMPTY_OBJECT, elementProps } = props;
|
|
26
|
+
const uniqueId = useId$1();
|
|
27
|
+
const parentPortalNode = usePortalContext()?.portalNode;
|
|
28
|
+
const [containerElement, setContainerElement] = React.useState(null);
|
|
29
|
+
const [portalNode, setPortalNode] = React.useState(null);
|
|
30
|
+
const setPortalNodeRef = useStableCallback((node) => {
|
|
31
|
+
if (node !== null) setPortalNode(node);
|
|
32
|
+
});
|
|
33
|
+
const containerRef = React.useRef(null);
|
|
34
|
+
useIsoLayoutEffect(() => {
|
|
35
|
+
if (containerProp === null) {
|
|
36
|
+
if (containerRef.current) {
|
|
37
|
+
containerRef.current = null;
|
|
38
|
+
setPortalNode(null);
|
|
39
|
+
setContainerElement(null);
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const resolvedContainer = (containerProp && (isNode(containerProp) ? containerProp : containerProp.current)) ?? parentPortalNode ?? document.body;
|
|
44
|
+
if (resolvedContainer == null) {
|
|
45
|
+
if (containerRef.current) {
|
|
46
|
+
containerRef.current = null;
|
|
47
|
+
setPortalNode(null);
|
|
48
|
+
setContainerElement(null);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (containerRef.current !== resolvedContainer) {
|
|
53
|
+
containerRef.current = resolvedContainer;
|
|
54
|
+
setPortalNode(null);
|
|
55
|
+
setContainerElement(resolvedContainer);
|
|
56
|
+
}
|
|
57
|
+
}, [containerProp, parentPortalNode]);
|
|
58
|
+
const portalElement = useRenderElement("div", componentProps, {
|
|
59
|
+
ref: [ref, setPortalNodeRef],
|
|
60
|
+
props: [{
|
|
61
|
+
id: uniqueId,
|
|
62
|
+
[attr]: ""
|
|
63
|
+
}, elementProps]
|
|
64
|
+
});
|
|
65
|
+
const portalSubtree = containerElement && portalElement ? /*#__PURE__*/ ReactDOM.createPortal(portalElement, containerElement) : null;
|
|
66
|
+
return {
|
|
67
|
+
node: portalNode,
|
|
68
|
+
nodeId: /*#__PURE__*/ React.isValidElement(portalElement) ? portalElement.props.id : void 0,
|
|
69
|
+
subtree: portalSubtree
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Portals the floating element into a given container element — by default,
|
|
74
|
+
* outside of the app root and into the body.
|
|
75
|
+
* This is necessary to ensure the floating element can appear outside any
|
|
76
|
+
* potential parent containers that cause clipping (such as `overflow: hidden`),
|
|
77
|
+
* while retaining its location in the React tree.
|
|
78
|
+
* @see https://floating-ui.com/docs/FloatingPortal
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
const FloatingPortal = /*#__PURE__*/ React.forwardRef(function FloatingPortal(componentProps, forwardedRef) {
|
|
82
|
+
const { render, className, style, children, container, portalOwnerRole, ...elementProps } = componentProps;
|
|
83
|
+
const { node: portalNode, nodeId: portalNodeId, subtree: portalSubtree } = useFloatingPortalNode({
|
|
84
|
+
container,
|
|
85
|
+
ref: forwardedRef,
|
|
86
|
+
componentProps,
|
|
87
|
+
elementProps
|
|
88
|
+
});
|
|
89
|
+
const beforeOutsideRef = React.useRef(null);
|
|
90
|
+
const afterOutsideRef = React.useRef(null);
|
|
91
|
+
const beforeInsideRef = React.useRef(null);
|
|
92
|
+
const afterInsideRef = React.useRef(null);
|
|
93
|
+
const [focusManagerState, setFocusManagerState] = React.useState(null);
|
|
94
|
+
const focusInsideDisabledRef = React.useRef(false);
|
|
95
|
+
const modal = focusManagerState?.modal;
|
|
96
|
+
const open = focusManagerState?.open;
|
|
97
|
+
const shouldRenderGuards = !!focusManagerState && !focusManagerState.modal && focusManagerState.open && !!portalNode;
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
if (!portalNode || modal) return;
|
|
100
|
+
function onFocus(event) {
|
|
101
|
+
if (portalNode && event.relatedTarget && isOutsideEvent(event)) {
|
|
102
|
+
if (event.type === "focusin") {
|
|
103
|
+
if (focusInsideDisabledRef.current) {
|
|
104
|
+
enableFocusInside(portalNode);
|
|
105
|
+
focusInsideDisabledRef.current = false;
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
disableFocusInside(portalNode);
|
|
109
|
+
focusInsideDisabledRef.current = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return mergeCleanups(addEventListener(portalNode, "focusin", onFocus, true), addEventListener(portalNode, "focusout", onFocus, true));
|
|
114
|
+
}, [portalNode, modal]);
|
|
115
|
+
useIsoLayoutEffect(() => {
|
|
116
|
+
if (!portalNode || open !== true || !focusInsideDisabledRef.current) return;
|
|
117
|
+
enableFocusInside(portalNode);
|
|
118
|
+
focusInsideDisabledRef.current = false;
|
|
119
|
+
}, [open, portalNode]);
|
|
120
|
+
const portalContextValue = React.useMemo(() => ({
|
|
121
|
+
beforeOutsideRef,
|
|
122
|
+
afterOutsideRef,
|
|
123
|
+
beforeInsideRef,
|
|
124
|
+
afterInsideRef,
|
|
125
|
+
portalNode,
|
|
126
|
+
setFocusManagerState
|
|
127
|
+
}), [portalNode]);
|
|
128
|
+
return /*#__PURE__*/ jsxs(React.Fragment, { children: [portalSubtree, /*#__PURE__*/ jsxs(PortalContext.Provider, {
|
|
129
|
+
value: portalContextValue,
|
|
130
|
+
children: [
|
|
131
|
+
shouldRenderGuards && portalNode && /*#__PURE__*/ jsx(FocusGuard, {
|
|
132
|
+
"data-type": "outside",
|
|
133
|
+
ref: beforeOutsideRef,
|
|
134
|
+
onFocus: (event) => {
|
|
135
|
+
if (isOutsideEvent(event, portalNode)) beforeInsideRef.current?.focus();
|
|
136
|
+
else {
|
|
137
|
+
const domReference = focusManagerState ? focusManagerState.domReference : null;
|
|
138
|
+
getPreviousTabbable(domReference)?.focus();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}),
|
|
142
|
+
shouldRenderGuards && portalNode && /*#__PURE__*/ jsx("span", {
|
|
143
|
+
role: portalOwnerRole,
|
|
144
|
+
"aria-owns": portalNodeId,
|
|
145
|
+
style: ownerVisuallyHidden
|
|
146
|
+
}),
|
|
147
|
+
portalNode && /*#__PURE__*/ ReactDOM.createPortal(children, portalNode),
|
|
148
|
+
shouldRenderGuards && portalNode && /*#__PURE__*/ jsx(FocusGuard, {
|
|
149
|
+
"data-type": "outside",
|
|
150
|
+
ref: afterOutsideRef,
|
|
151
|
+
onFocus: (event) => {
|
|
152
|
+
if (isOutsideEvent(event, portalNode)) afterInsideRef.current?.focus();
|
|
153
|
+
else {
|
|
154
|
+
const domReference = focusManagerState ? focusManagerState.domReference : null;
|
|
155
|
+
getNextTabbable(domReference)?.focus();
|
|
156
|
+
if (focusManagerState?.closeOnFocusOut) focusManagerState?.onOpenChange(false, createChangeEventDetails("focus-out", event.nativeEvent));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
})] });
|
|
162
|
+
});
|
|
163
|
+
if (process.env.NODE_ENV !== "production") FloatingPortal.displayName = "FloatingPortal";
|
|
164
|
+
//#endregion
|
|
165
|
+
export { FloatingPortal, useFloatingPortalNode, usePortalContext };
|