@octanejs/base-ui 0.1.30 → 0.1.32
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/dist/cjs/accordion.cjs +497 -0
- package/dist/cjs/alert-dialog.cjs +65 -0
- package/dist/cjs/avatar.cjs +234 -0
- package/dist/cjs/button.cjs +54 -0
- package/dist/cjs/checkbox-group.cjs +165 -0
- package/dist/cjs/checkbox.cjs +475 -0
- package/dist/cjs/collapsible.cjs +700 -0
- package/dist/cjs/context-menu.cjs +257 -0
- package/dist/cjs/csp-provider.cjs +40 -0
- package/dist/cjs/dialog.cjs +741 -0
- package/dist/cjs/direction-provider.cjs +35 -0
- package/dist/cjs/field.cjs +559 -0
- package/dist/cjs/fieldset.cjs +101 -0
- package/dist/cjs/form.cjs +177 -0
- package/dist/cjs/index.cjs +133 -0
- package/dist/cjs/input.cjs +32 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/menu.cjs +2420 -0
- package/dist/cjs/menubar.cjs +132 -0
- package/dist/cjs/merge-props.cjs +34 -0
- package/dist/cjs/meter.cjs +169 -0
- package/dist/cjs/number-field.cjs +812 -0
- package/dist/cjs/popover.cjs +966 -0
- package/dist/cjs/preview-card.cjs +632 -0
- package/dist/cjs/progress.cjs +206 -0
- package/dist/cjs/radio-group.cjs +264 -0
- package/dist/cjs/radio.cjs +327 -0
- package/dist/cjs/separator.cjs +44 -0
- package/dist/cjs/slider.cjs +1384 -0
- package/dist/cjs/switch.cjs +306 -0
- package/dist/cjs/tabs.cjs +727 -0
- package/dist/cjs/toast.cjs +1766 -0
- package/dist/cjs/toggle-group.cjs +118 -0
- package/dist/cjs/toggle.cjs +121 -0
- package/dist/cjs/tooltip.cjs +835 -0
- package/dist/cjs/unstable-use-media-query.cjs +79 -0
- package/dist/cjs/use-render.cjs +40 -0
- package/dist/cjs/utils/CSPContext.cjs +38 -0
- package/dist/cjs/utils/CheckboxGroupContext.cjs +40 -0
- package/dist/cjs/utils/CompositeRootContext.cjs +40 -0
- package/dist/cjs/utils/ContextMenuRootContext.cjs +42 -0
- package/dist/cjs/utils/DirectionContext.cjs +34 -0
- package/dist/cjs/utils/FloatingPortalLite.cjs +47 -0
- package/dist/cjs/utils/InternalBackdrop.cjs +49 -0
- package/dist/cjs/utils/MenubarContext.cjs +40 -0
- package/dist/cjs/utils/RadioGroupContext.cjs +34 -0
- package/dist/cjs/utils/RequestQueue.cjs +111 -0
- package/dist/cjs/utils/TimeoutManager.cjs +50 -0
- package/dist/cjs/utils/ToggleGroupContext.cjs +40 -0
- package/dist/cjs/utils/adaptiveOriginMiddleware.cjs +94 -0
- package/dist/cjs/utils/addEventListener.cjs +33 -0
- package/dist/cjs/utils/areArraysEqual.cjs +30 -0
- package/dist/cjs/utils/clamp.cjs +30 -0
- package/dist/cjs/utils/closePart.cjs +70 -0
- package/dist/cjs/utils/collapsibleOpenStateMapping.cjs +42 -0
- package/dist/cjs/utils/composeRefs.cjs +68 -0
- package/dist/cjs/utils/composite/CompositeItem.cjs +59 -0
- package/dist/cjs/utils/composite/CompositeList.cjs +177 -0
- package/dist/cjs/utils/composite/CompositeListContext.cjs +43 -0
- package/dist/cjs/utils/composite/CompositeRoot.cjs +118 -0
- package/dist/cjs/utils/composite/grid-utils.cjs +343 -0
- package/dist/cjs/utils/composite/gridNavigation.cjs +92 -0
- package/dist/cjs/utils/composite/keys.cjs +174 -0
- package/dist/cjs/utils/composite/list-utils.cjs +90 -0
- package/dist/cjs/utils/composite/useCompositeItem.cjs +63 -0
- package/dist/cjs/utils/composite/useCompositeListItem.cjs +104 -0
- package/dist/cjs/utils/composite/useCompositeRoot.cjs +263 -0
- package/dist/cjs/utils/constants.cjs +56 -0
- package/dist/cjs/utils/contains.cjs +46 -0
- package/dist/cjs/utils/createChangeEventDetails.cjs +92 -0
- package/dist/cjs/utils/dom.cjs +35 -0
- package/dist/cjs/utils/empty.cjs +34 -0
- package/dist/cjs/utils/field/FieldItemContext.cjs +34 -0
- package/dist/cjs/utils/field/FieldRootContext.cjs +80 -0
- package/dist/cjs/utils/field/FormContext.cjs +41 -0
- package/dist/cjs/utils/field/LabelableContext.cjs +43 -0
- package/dist/cjs/utils/field/LabelableProvider.cjs +115 -0
- package/dist/cjs/utils/field/constants.cjs +68 -0
- package/dist/cjs/utils/field/getCombinedFieldValidityData.cjs +36 -0
- package/dist/cjs/utils/field/useAriaLabelledBy.cjs +87 -0
- package/dist/cjs/utils/field/useFieldControlRegistration.cjs +165 -0
- package/dist/cjs/utils/field/useFieldValidation.cjs +285 -0
- package/dist/cjs/utils/field/useLabel.cjs +99 -0
- package/dist/cjs/utils/field/useLabelableId.cjs +105 -0
- package/dist/cjs/utils/field/useRegisterFieldControl.cjs +60 -0
- package/dist/cjs/utils/findRootOwnerId.cjs +37 -0
- package/dist/cjs/utils/floating/FloatingDelayGroup.cjs +219 -0
- package/dist/cjs/utils/floating/FloatingFocusManager.cjs +685 -0
- package/dist/cjs/utils/floating/FloatingPortal.cjs +230 -0
- package/dist/cjs/utils/floating/FloatingRootStore.cjs +87 -0
- package/dist/cjs/utils/floating/FloatingTree.cjs +86 -0
- package/dist/cjs/utils/floating/FloatingTreeStore.cjs +41 -0
- package/dist/cjs/utils/floating/FocusGuard.cjs +54 -0
- package/dist/cjs/utils/floating/composite.cjs +42 -0
- package/dist/cjs/utils/floating/constants.cjs +34 -0
- package/dist/cjs/utils/floating/createAttribute.cjs +30 -0
- package/dist/cjs/utils/floating/createEventEmitter.cjs +44 -0
- package/dist/cjs/utils/floating/element.cjs +103 -0
- package/dist/cjs/utils/floating/enqueueFocus.cjs +51 -0
- package/dist/cjs/utils/floating/event.cjs +65 -0
- package/dist/cjs/utils/floating/getEmptyRootContext.cjs +42 -0
- package/dist/cjs/utils/floating/gridNavigation.cjs +45 -0
- package/dist/cjs/utils/floating/markOthers.cjs +181 -0
- package/dist/cjs/utils/floating/nodes.cjs +48 -0
- package/dist/cjs/utils/floating/safePolygon.cjs +301 -0
- package/dist/cjs/utils/floating/tabbable.cjs +242 -0
- package/dist/cjs/utils/floating/types.cjs +16 -0
- package/dist/cjs/utils/floating/useClick.cjs +153 -0
- package/dist/cjs/utils/floating/useClientPoint.cjs +225 -0
- package/dist/cjs/utils/floating/useDismiss.cjs +506 -0
- package/dist/cjs/utils/floating/useFloating.cjs +186 -0
- package/dist/cjs/utils/floating/useFloatingRootContext.cjs +75 -0
- package/dist/cjs/utils/floating/useFocus.cjs +184 -0
- package/dist/cjs/utils/floating/useHoverFloatingInteraction.cjs +231 -0
- package/dist/cjs/utils/floating/useHoverInteractionSharedState.cjs +113 -0
- package/dist/cjs/utils/floating/useHoverReferenceInteraction.cjs +380 -0
- package/dist/cjs/utils/floating/useHoverShared.cjs +65 -0
- package/dist/cjs/utils/floating/useListNavigation.cjs +665 -0
- package/dist/cjs/utils/floating/useSyncedFloatingRootContext.cjs +91 -0
- package/dist/cjs/utils/floating/useTypeahead.cjs +187 -0
- package/dist/cjs/utils/formatNumber.cjs +60 -0
- package/dist/cjs/utils/generateId.cjs +32 -0
- package/dist/cjs/utils/getCssDimensions.cjs +42 -0
- package/dist/cjs/utils/getDefaultFormSubmitter.cjs +42 -0
- package/dist/cjs/utils/getDisabledMountTransitionStyles.cjs +32 -0
- package/dist/cjs/utils/getElementRef.cjs +35 -0
- package/dist/cjs/utils/getPseudoElementBounds.cjs +56 -0
- package/dist/cjs/utils/getStateAttributesProps.cjs +46 -0
- package/dist/cjs/utils/hideMiddleware.cjs +42 -0
- package/dist/cjs/utils/inertValue.cjs +30 -0
- package/dist/cjs/utils/matchesFocusVisible.cjs +38 -0
- package/dist/cjs/utils/mergeCleanups.cjs +37 -0
- package/dist/cjs/utils/mergeObjects.cjs +39 -0
- package/dist/cjs/utils/mergeProps.cjs +182 -0
- package/dist/cjs/utils/noop.cjs +29 -0
- package/dist/cjs/utils/number/constants.cjs +34 -0
- package/dist/cjs/utils/number/parse.cjs +258 -0
- package/dist/cjs/utils/number/types.cjs +16 -0
- package/dist/cjs/utils/number/validate.cjs +104 -0
- package/dist/cjs/utils/owner.cjs +35 -0
- package/dist/cjs/utils/platform.cjs +83 -0
- package/dist/cjs/utils/popupStateMapping.cjs +74 -0
- package/dist/cjs/utils/popups/index.cjs +39 -0
- package/dist/cjs/utils/popups/inlineRect.cjs +218 -0
- package/dist/cjs/utils/popups/popupStoreUtils.cjs +379 -0
- package/dist/cjs/utils/popups/popupTriggerMap.cjs +76 -0
- package/dist/cjs/utils/popups/store.cjs +118 -0
- package/dist/cjs/utils/popups/useTriggerFocusGuards.cjs +72 -0
- package/dist/cjs/utils/resolveAriaLabelledBy.cjs +35 -0
- package/dist/cjs/utils/resolveClassName.cjs +30 -0
- package/dist/cjs/utils/resolveRef.cjs +33 -0
- package/dist/cjs/utils/resolveStyle.cjs +30 -0
- package/dist/cjs/utils/serializeValue.cjs +40 -0
- package/dist/cjs/utils/slider/asc.cjs +30 -0
- package/dist/cjs/utils/slider/getMidpoint.cjs +34 -0
- package/dist/cjs/utils/slider/getPushedThumbValues.cjs +73 -0
- package/dist/cjs/utils/slider/getSliderValue.cjs +42 -0
- package/dist/cjs/utils/slider/replaceArrayItemAtIndex.cjs +33 -0
- package/dist/cjs/utils/slider/resolveThumbCollision.cjs +155 -0
- package/dist/cjs/utils/slider/roundValueToStep.cjs +45 -0
- package/dist/cjs/utils/slider/validateMinimumDistance.cjs +40 -0
- package/dist/cjs/utils/slider/valueArrayToPercentages.cjs +36 -0
- package/dist/cjs/utils/store/ReactStore.cjs +135 -0
- package/dist/cjs/utils/store/Store.cjs +83 -0
- package/dist/cjs/utils/store/createSelector.cjs +74 -0
- package/dist/cjs/utils/store/useStore.cjs +51 -0
- package/dist/cjs/utils/stringifyLocale.cjs +36 -0
- package/dist/cjs/utils/useAnchorPositioning.cjs +421 -0
- package/dist/cjs/utils/useAnchoredPopupScrollLock.cjs +59 -0
- package/dist/cjs/utils/useAnimationFrame.cjs +93 -0
- package/dist/cjs/utils/useAnimationsFinished.cjs +98 -0
- package/dist/cjs/utils/useBaseUiId.cjs +36 -0
- package/dist/cjs/utils/useButton.cjs +177 -0
- package/dist/cjs/utils/useCheckboxGroupParent.cjs +114 -0
- package/dist/cjs/utils/useControlled.cjs +47 -0
- package/dist/cjs/utils/useEnhancedClickHandler.cjs +60 -0
- package/dist/cjs/utils/useFocusableWhenDisabled.cjs +77 -0
- package/dist/cjs/utils/useForcedRerendering.cjs +35 -0
- package/dist/cjs/utils/useIsHydrating.cjs +44 -0
- package/dist/cjs/utils/useMixedToggleClickHandler.cjs +66 -0
- package/dist/cjs/utils/useOnFirstRender.cjs +35 -0
- package/dist/cjs/utils/useOnMount.cjs +36 -0
- package/dist/cjs/utils/useOpenChangeComplete.cjs +57 -0
- package/dist/cjs/utils/useOpenInteractionType.cjs +69 -0
- package/dist/cjs/utils/usePopupAutoResize.cjs +191 -0
- package/dist/cjs/utils/usePopupViewport.cjs +283 -0
- package/dist/cjs/utils/usePositioner.cjs +53 -0
- package/dist/cjs/utils/usePressAndHold.cjs +51 -0
- package/dist/cjs/utils/usePreviousValue.cjs +47 -0
- package/dist/cjs/utils/useRefWithInit.cjs +41 -0
- package/dist/cjs/utils/useRegisteredLabelId.cjs +48 -0
- package/dist/cjs/utils/useRenderElement.cjs +106 -0
- package/dist/cjs/utils/useScrollLock.cjs +232 -0
- package/dist/cjs/utils/useStableCallback.cjs +41 -0
- package/dist/cjs/utils/useTimeout.cjs +66 -0
- package/dist/cjs/utils/useTransitionStatus.cjs +116 -0
- package/dist/cjs/utils/useValueAsRef.cjs +43 -0
- package/dist/cjs/utils/useValueChanged.cjs +55 -0
- package/dist/cjs/utils/valueToPercent.cjs +30 -0
- package/dist/cjs/utils/visuallyHidden.cjs +49 -0
- package/package.json +20 -8
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FloatingFocusManager_exports = {};
|
|
20
|
+
__export(FloatingFocusManager_exports, {
|
|
21
|
+
FloatingFocusManager: () => FloatingFocusManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(FloatingFocusManager_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
26
|
+
var import_internal = require("../../internal.cjs");
|
|
27
|
+
var import_addEventListener = require("../addEventListener.cjs");
|
|
28
|
+
var import_mergeCleanups = require("../mergeCleanups.cjs");
|
|
29
|
+
var import_composeRefs = require("../composeRefs.cjs");
|
|
30
|
+
var import_useValueAsRef = require("../useValueAsRef.cjs");
|
|
31
|
+
var import_useStableCallback = require("../useStableCallback.cjs");
|
|
32
|
+
var import_useTimeout = require("../useTimeout.cjs");
|
|
33
|
+
var import_useAnimationFrame = require("../useAnimationFrame.cjs");
|
|
34
|
+
var import_platform = require("../platform.cjs");
|
|
35
|
+
var import_owner = require("../owner.cjs");
|
|
36
|
+
var import_resolveRef = require("../resolveRef.cjs");
|
|
37
|
+
var import_FocusGuard = require("./FocusGuard.cjs");
|
|
38
|
+
var import_element = require("./element.cjs");
|
|
39
|
+
var import_event = require("./event.cjs");
|
|
40
|
+
var import_list_utils = require("../composite/list-utils.cjs");
|
|
41
|
+
var import_tabbable = require("./tabbable.cjs");
|
|
42
|
+
var import_nodes = require("./nodes.cjs");
|
|
43
|
+
var import_composite = require("./composite.cjs");
|
|
44
|
+
var import_createChangeEventDetails = require("../createChangeEventDetails.cjs");
|
|
45
|
+
var import_createAttribute = require("./createAttribute.cjs");
|
|
46
|
+
var import_constants = require("./constants.cjs");
|
|
47
|
+
var import_enqueueFocus = require("./enqueueFocus.cjs");
|
|
48
|
+
var import_markOthers = require("./markOthers.cjs");
|
|
49
|
+
var import_FloatingPortal = require("./FloatingPortal.cjs");
|
|
50
|
+
var import_FloatingTree = require("./FloatingTree.cjs");
|
|
51
|
+
function getEventType(event, lastInteractionType) {
|
|
52
|
+
const win = (0, import_owner.ownerWindow)((0, import_element.getTarget)(event));
|
|
53
|
+
if (event instanceof win.KeyboardEvent) {
|
|
54
|
+
return "keyboard";
|
|
55
|
+
}
|
|
56
|
+
if (event instanceof win.FocusEvent) {
|
|
57
|
+
return lastInteractionType || "keyboard";
|
|
58
|
+
}
|
|
59
|
+
if ("pointerType" in event) {
|
|
60
|
+
return event.pointerType || "keyboard";
|
|
61
|
+
}
|
|
62
|
+
if ("touches" in event) {
|
|
63
|
+
return "touch";
|
|
64
|
+
}
|
|
65
|
+
if (event instanceof win.MouseEvent) {
|
|
66
|
+
return lastInteractionType || (event.detail === 0 ? "keyboard" : "mouse");
|
|
67
|
+
}
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
70
|
+
const LIST_LIMIT = 20;
|
|
71
|
+
let previouslyFocusedElements = [];
|
|
72
|
+
function clearDisconnectedPreviouslyFocusedElements() {
|
|
73
|
+
previouslyFocusedElements = previouslyFocusedElements.filter(
|
|
74
|
+
(entry) => entry.deref()?.isConnected
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function addPreviouslyFocusedElement(element) {
|
|
78
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
79
|
+
if (element && (0, import_dom.getNodeName)(element) !== "body") {
|
|
80
|
+
previouslyFocusedElements.push(new WeakRef(element));
|
|
81
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) {
|
|
82
|
+
previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getPreviouslyFocusedElement() {
|
|
87
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
88
|
+
return previouslyFocusedElements[previouslyFocusedElements.length - 1]?.deref();
|
|
89
|
+
}
|
|
90
|
+
function getFirstTabbableElement(container) {
|
|
91
|
+
if (!container) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if ((0, import_tabbable.isTabbable)(container)) {
|
|
95
|
+
return container;
|
|
96
|
+
}
|
|
97
|
+
return (0, import_tabbable.tabbable)(container)[0] || container;
|
|
98
|
+
}
|
|
99
|
+
function handleTabIndex(floatingFocusElement) {
|
|
100
|
+
if (floatingFocusElement.hasAttribute("tabindex") && !floatingFocusElement.hasAttribute("data-tabindex")) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!floatingFocusElement.getAttribute("role")?.includes("dialog")) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const focusableElements = (0, import_tabbable.focusable)(floatingFocusElement);
|
|
107
|
+
const tabbableContent = focusableElements.filter((element) => {
|
|
108
|
+
const dataTabIndex = element.getAttribute("data-tabindex") || "";
|
|
109
|
+
return (0, import_tabbable.isTabbable)(element) || element.hasAttribute("data-tabindex") && !dataTabIndex.startsWith("-");
|
|
110
|
+
});
|
|
111
|
+
const tabIndex = floatingFocusElement.getAttribute("tabindex");
|
|
112
|
+
if (tabbableContent.length === 0) {
|
|
113
|
+
if (tabIndex !== "0") {
|
|
114
|
+
floatingFocusElement.setAttribute("tabindex", "0");
|
|
115
|
+
floatingFocusElement.setAttribute("data-tabindex", "0");
|
|
116
|
+
}
|
|
117
|
+
} else if (tabIndex !== "-1" || floatingFocusElement.hasAttribute("data-tabindex") && floatingFocusElement.getAttribute("data-tabindex") !== "-1") {
|
|
118
|
+
floatingFocusElement.setAttribute("tabindex", "-1");
|
|
119
|
+
floatingFocusElement.setAttribute("data-tabindex", "-1");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function FloatingFocusManager(props) {
|
|
123
|
+
const slot = (0, import_internal.S)("FloatingFocusManager");
|
|
124
|
+
const {
|
|
125
|
+
context,
|
|
126
|
+
children,
|
|
127
|
+
disabled = false,
|
|
128
|
+
initialFocus = true,
|
|
129
|
+
returnFocus = true,
|
|
130
|
+
restoreFocus = false,
|
|
131
|
+
modal = true,
|
|
132
|
+
closeOnFocusOut = true,
|
|
133
|
+
openInteractionType = "",
|
|
134
|
+
nextFocusableElement,
|
|
135
|
+
previousFocusableElement,
|
|
136
|
+
beforeContentFocusGuardRef,
|
|
137
|
+
externalTree,
|
|
138
|
+
getInsideElements
|
|
139
|
+
} = props;
|
|
140
|
+
const store = context && "rootStore" in context ? context.rootStore : context;
|
|
141
|
+
const open = store.useState("open", (0, import_internal.subSlot)(slot, "open"));
|
|
142
|
+
const domReference = store.useState("domReferenceElement", (0, import_internal.subSlot)(slot, "dom"));
|
|
143
|
+
const floating = store.useState("floatingElement", (0, import_internal.subSlot)(slot, "fel"));
|
|
144
|
+
const { events, dataRef } = store.context;
|
|
145
|
+
const getNodeId = (0, import_useStableCallback.useStableCallback)(
|
|
146
|
+
() => dataRef.current.floatingContext?.nodeId,
|
|
147
|
+
(0, import_internal.subSlot)(slot, "getNodeId")
|
|
148
|
+
);
|
|
149
|
+
const ignoreInitialFocus = initialFocus === false;
|
|
150
|
+
const isUntrappedTypeableCombobox = (0, import_element.isTypeableCombobox)(domReference) && ignoreInitialFocus;
|
|
151
|
+
const initialFocusRef = (0, import_useValueAsRef.useValueAsRef)(initialFocus, (0, import_internal.subSlot)(slot, "ifr"));
|
|
152
|
+
const returnFocusRef = (0, import_useValueAsRef.useValueAsRef)(returnFocus, (0, import_internal.subSlot)(slot, "rfr"));
|
|
153
|
+
const openInteractionTypeRef = (0, import_useValueAsRef.useValueAsRef)(openInteractionType, (0, import_internal.subSlot)(slot, "oitr"));
|
|
154
|
+
const openRef = (0, import_useValueAsRef.useValueAsRef)(open, (0, import_internal.subSlot)(slot, "openRef"));
|
|
155
|
+
const tree = (0, import_FloatingTree.useFloatingTree)(externalTree);
|
|
156
|
+
const portalContext = (0, import_FloatingPortal.usePortalContext)();
|
|
157
|
+
const preventReturnFocusRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "prf"));
|
|
158
|
+
const isPointerDownRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "ipd"));
|
|
159
|
+
const pointerDownOutsideRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "pdo"));
|
|
160
|
+
const lastFocusedTabbableRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "lft"));
|
|
161
|
+
const closeTypeRef = (0, import_octane.useRef)("", (0, import_internal.subSlot)(slot, "ct"));
|
|
162
|
+
const lastInteractionTypeRef = (0, import_octane.useRef)("", (0, import_internal.subSlot)(slot, "lit"));
|
|
163
|
+
const beforeGuardRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "bg"));
|
|
164
|
+
const afterGuardRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ag"));
|
|
165
|
+
const mergedBeforeGuardRef = (0, import_composeRefs.useComposedRefs)(
|
|
166
|
+
beforeGuardRef,
|
|
167
|
+
beforeContentFocusGuardRef,
|
|
168
|
+
portalContext?.beforeInsideRef,
|
|
169
|
+
(0, import_internal.subSlot)(slot, "mbg")
|
|
170
|
+
);
|
|
171
|
+
const mergedAfterGuardRef = (0, import_composeRefs.useComposedRefs)(
|
|
172
|
+
afterGuardRef,
|
|
173
|
+
portalContext?.afterInsideRef,
|
|
174
|
+
(0, import_internal.subSlot)(slot, "mag")
|
|
175
|
+
);
|
|
176
|
+
const blurTimeout = (0, import_useTimeout.useTimeout)((0, import_internal.subSlot)(slot, "bt"));
|
|
177
|
+
const pointerDownTimeout = (0, import_useTimeout.useTimeout)((0, import_internal.subSlot)(slot, "pdt"));
|
|
178
|
+
const restoreFocusFrame = (0, import_useAnimationFrame.useAnimationFrame)((0, import_internal.subSlot)(slot, "rff"));
|
|
179
|
+
const isInsidePortal = portalContext != null;
|
|
180
|
+
const floatingFocusElement = (0, import_element.getFloatingFocusElement)(floating);
|
|
181
|
+
const getTabbableContent = (0, import_useStableCallback.useStableCallback)(
|
|
182
|
+
(container = floatingFocusElement) => {
|
|
183
|
+
return container ? (0, import_tabbable.tabbable)(container) : [];
|
|
184
|
+
},
|
|
185
|
+
(0, import_internal.subSlot)(slot, "gtc")
|
|
186
|
+
);
|
|
187
|
+
const getResolvedInsideElements = (0, import_useStableCallback.useStableCallback)(
|
|
188
|
+
() => getInsideElements?.().filter((element) => element != null) ?? [],
|
|
189
|
+
(0, import_internal.subSlot)(slot, "grie")
|
|
190
|
+
);
|
|
191
|
+
(0, import_octane.useEffect)(
|
|
192
|
+
() => {
|
|
193
|
+
if (disabled || !modal) {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
function onKeyDown(event) {
|
|
197
|
+
if (event.key === "Tab") {
|
|
198
|
+
if ((0, import_element.contains)(floatingFocusElement, (0, import_element.activeElement)((0, import_owner.ownerDocument)(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
|
|
199
|
+
(0, import_list_utils.stopEvent)(event);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const doc = (0, import_owner.ownerDocument)(floatingFocusElement);
|
|
204
|
+
return (0, import_addEventListener.addEventListener)(doc, "keydown", onKeyDown);
|
|
205
|
+
},
|
|
206
|
+
[disabled, floatingFocusElement, modal, isUntrappedTypeableCombobox, getTabbableContent],
|
|
207
|
+
(0, import_internal.subSlot)(slot, "e:tab")
|
|
208
|
+
);
|
|
209
|
+
(0, import_octane.useEffect)(
|
|
210
|
+
() => {
|
|
211
|
+
if (disabled || !open) {
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
const doc = (0, import_owner.ownerDocument)(floatingFocusElement);
|
|
215
|
+
function clearPointerDownOutside() {
|
|
216
|
+
pointerDownOutsideRef.current = false;
|
|
217
|
+
}
|
|
218
|
+
function onPointerDown(event) {
|
|
219
|
+
const target = (0, import_element.getTarget)(event);
|
|
220
|
+
const insideElements = getResolvedInsideElements();
|
|
221
|
+
const pointerTargetInside = (0, import_element.contains)(floating, target) || (0, import_element.contains)(domReference, target) || (0, import_element.contains)(portalContext?.portalNode, target) || insideElements.some(
|
|
222
|
+
(element) => element === target || (0, import_element.contains)(element, target)
|
|
223
|
+
);
|
|
224
|
+
pointerDownOutsideRef.current = !pointerTargetInside;
|
|
225
|
+
lastInteractionTypeRef.current = event.pointerType || "keyboard";
|
|
226
|
+
if (target?.closest(`[${import_constants.CLICK_TRIGGER_IDENTIFIER}]`)) {
|
|
227
|
+
isPointerDownRef.current = true;
|
|
228
|
+
pointerDownTimeout.start(0, () => {
|
|
229
|
+
isPointerDownRef.current = false;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function onKeyDown() {
|
|
234
|
+
lastInteractionTypeRef.current = "keyboard";
|
|
235
|
+
}
|
|
236
|
+
return (0, import_mergeCleanups.mergeCleanups)(
|
|
237
|
+
(0, import_addEventListener.addEventListener)(doc, "pointerdown", onPointerDown, true),
|
|
238
|
+
(0, import_addEventListener.addEventListener)(doc, "pointerup", clearPointerDownOutside, true),
|
|
239
|
+
(0, import_addEventListener.addEventListener)(doc, "pointercancel", clearPointerDownOutside, true),
|
|
240
|
+
(0, import_addEventListener.addEventListener)(doc, "keydown", onKeyDown, true),
|
|
241
|
+
clearPointerDownOutside
|
|
242
|
+
);
|
|
243
|
+
},
|
|
244
|
+
[
|
|
245
|
+
disabled,
|
|
246
|
+
floating,
|
|
247
|
+
domReference,
|
|
248
|
+
floatingFocusElement,
|
|
249
|
+
open,
|
|
250
|
+
portalContext,
|
|
251
|
+
pointerDownTimeout,
|
|
252
|
+
getResolvedInsideElements
|
|
253
|
+
],
|
|
254
|
+
(0, import_internal.subSlot)(slot, "e:track")
|
|
255
|
+
);
|
|
256
|
+
(0, import_octane.useEffect)(
|
|
257
|
+
() => {
|
|
258
|
+
if (disabled || !closeOnFocusOut) {
|
|
259
|
+
return void 0;
|
|
260
|
+
}
|
|
261
|
+
const doc = (0, import_owner.ownerDocument)(floatingFocusElement);
|
|
262
|
+
function handlePointerDown() {
|
|
263
|
+
isPointerDownRef.current = true;
|
|
264
|
+
pointerDownTimeout.start(0, () => {
|
|
265
|
+
isPointerDownRef.current = false;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function handleFocusIn(event) {
|
|
269
|
+
const target = (0, import_element.getTarget)(event);
|
|
270
|
+
if ((0, import_tabbable.isTabbable)(target)) {
|
|
271
|
+
lastFocusedTabbableRef.current = target;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function handleFocusOutside(event) {
|
|
275
|
+
const relatedTarget = event.relatedTarget;
|
|
276
|
+
const currentTarget = event.currentTarget;
|
|
277
|
+
const target = (0, import_element.getTarget)(event);
|
|
278
|
+
if (modal && relatedTarget == null && target != null && (0, import_element.contains)(floating, target)) {
|
|
279
|
+
addPreviouslyFocusedElement(target);
|
|
280
|
+
}
|
|
281
|
+
queueMicrotask(() => {
|
|
282
|
+
const nodeId = getNodeId();
|
|
283
|
+
const triggers = store.context.triggerElements;
|
|
284
|
+
const insideElements = getResolvedInsideElements();
|
|
285
|
+
const isRelatedFocusGuard = relatedTarget?.hasAttribute((0, import_createAttribute.createAttribute)("focus-guard")) && [
|
|
286
|
+
beforeGuardRef.current,
|
|
287
|
+
afterGuardRef.current,
|
|
288
|
+
portalContext?.beforeInsideRef.current,
|
|
289
|
+
portalContext?.afterInsideRef.current,
|
|
290
|
+
portalContext?.beforeOutsideRef.current,
|
|
291
|
+
portalContext?.afterOutsideRef.current,
|
|
292
|
+
(0, import_resolveRef.resolveRef)(previousFocusableElement),
|
|
293
|
+
(0, import_resolveRef.resolveRef)(nextFocusableElement)
|
|
294
|
+
].includes(relatedTarget);
|
|
295
|
+
const movedToUnrelatedNode = !((0, import_element.contains)(domReference, relatedTarget) || (0, import_element.contains)(floating, relatedTarget) || (0, import_element.contains)(relatedTarget, floating) || (0, import_element.contains)(portalContext?.portalNode, relatedTarget) || insideElements.some(
|
|
296
|
+
(element) => element === relatedTarget || (0, import_element.contains)(element, relatedTarget)
|
|
297
|
+
) || relatedTarget != null && triggers.hasElement(relatedTarget) || triggers.hasMatchingElement((trigger) => (0, import_element.contains)(trigger, relatedTarget)) || isRelatedFocusGuard || tree && ((0, import_nodes.getNodeChildren)(tree.nodesRef.current, nodeId).find(
|
|
298
|
+
(node) => (0, import_element.contains)(node.context?.elements.floating, relatedTarget) || (0, import_element.contains)(node.context?.elements.domReference, relatedTarget)
|
|
299
|
+
) || (0, import_nodes.getNodeAncestors)(tree.nodesRef.current, nodeId).find(
|
|
300
|
+
(node) => [
|
|
301
|
+
node.context?.elements.floating,
|
|
302
|
+
(0, import_element.getFloatingFocusElement)(node.context?.elements.floating)
|
|
303
|
+
].includes(relatedTarget) || node.context?.elements.domReference === relatedTarget
|
|
304
|
+
)));
|
|
305
|
+
if (currentTarget === domReference && floatingFocusElement) {
|
|
306
|
+
handleTabIndex(floatingFocusElement);
|
|
307
|
+
}
|
|
308
|
+
if (restoreFocus && currentTarget !== domReference && !(0, import_composite.isElementVisible)(target) && (0, import_element.activeElement)(doc) === doc.body) {
|
|
309
|
+
if ((0, import_dom.isHTMLElement)(floatingFocusElement)) {
|
|
310
|
+
floatingFocusElement.focus();
|
|
311
|
+
if (restoreFocus === "popup") {
|
|
312
|
+
restoreFocusFrame.request(() => {
|
|
313
|
+
floatingFocusElement.focus();
|
|
314
|
+
});
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const tabbableContent = getTabbableContent();
|
|
319
|
+
const prevTabbable = lastFocusedTabbableRef.current;
|
|
320
|
+
const nodeToFocus = (prevTabbable && tabbableContent.includes(prevTabbable) ? prevTabbable : null) || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
321
|
+
if ((0, import_dom.isHTMLElement)(nodeToFocus)) {
|
|
322
|
+
nodeToFocus.focus();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (dataRef.current.insideReactTree) {
|
|
326
|
+
dataRef.current.insideReactTree = false;
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && (isUntrappedTypeableCombobox || relatedTarget !== getPreviouslyFocusedElement())) {
|
|
330
|
+
preventReturnFocusRef.current = true;
|
|
331
|
+
store.setOpen(false, (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.focusOut, event));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function markInsideReactTree() {
|
|
336
|
+
if (pointerDownOutsideRef.current) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
dataRef.current.insideReactTree = true;
|
|
340
|
+
blurTimeout.start(0, () => {
|
|
341
|
+
dataRef.current.insideReactTree = false;
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
const domReferenceElement = (0, import_dom.isHTMLElement)(domReference) ? domReference : null;
|
|
345
|
+
if (!floating && !domReferenceElement) {
|
|
346
|
+
return void 0;
|
|
347
|
+
}
|
|
348
|
+
return (0, import_mergeCleanups.mergeCleanups)(
|
|
349
|
+
domReferenceElement && (0, import_addEventListener.addEventListener)(domReferenceElement, "focusout", handleFocusOutside),
|
|
350
|
+
domReferenceElement && (0, import_addEventListener.addEventListener)(domReferenceElement, "pointerdown", handlePointerDown),
|
|
351
|
+
floating && (0, import_addEventListener.addEventListener)(floating, "focusin", handleFocusIn),
|
|
352
|
+
floating && (0, import_addEventListener.addEventListener)(floating, "focusout", handleFocusOutside),
|
|
353
|
+
floating && portalContext && (0, import_addEventListener.addEventListener)(floating, "focusout", markInsideReactTree, true)
|
|
354
|
+
);
|
|
355
|
+
},
|
|
356
|
+
[
|
|
357
|
+
disabled,
|
|
358
|
+
domReference,
|
|
359
|
+
floating,
|
|
360
|
+
floatingFocusElement,
|
|
361
|
+
modal,
|
|
362
|
+
tree,
|
|
363
|
+
portalContext,
|
|
364
|
+
store,
|
|
365
|
+
closeOnFocusOut,
|
|
366
|
+
restoreFocus,
|
|
367
|
+
getTabbableContent,
|
|
368
|
+
isUntrappedTypeableCombobox,
|
|
369
|
+
getNodeId,
|
|
370
|
+
dataRef,
|
|
371
|
+
blurTimeout,
|
|
372
|
+
pointerDownTimeout,
|
|
373
|
+
restoreFocusFrame,
|
|
374
|
+
nextFocusableElement,
|
|
375
|
+
previousFocusableElement,
|
|
376
|
+
getResolvedInsideElements
|
|
377
|
+
],
|
|
378
|
+
(0, import_internal.subSlot)(slot, "e:focusout")
|
|
379
|
+
);
|
|
380
|
+
(0, import_octane.useEffect)(
|
|
381
|
+
() => {
|
|
382
|
+
if (disabled || !floating || !open) {
|
|
383
|
+
return void 0;
|
|
384
|
+
}
|
|
385
|
+
const portalNodes = Array.from(
|
|
386
|
+
portalContext?.portalNode?.querySelectorAll(`[${(0, import_createAttribute.createAttribute)("portal")}]`) || []
|
|
387
|
+
);
|
|
388
|
+
const ancestors = tree ? (0, import_nodes.getNodeAncestors)(tree.nodesRef.current, getNodeId()) : [];
|
|
389
|
+
const rootAncestorComboboxDomReference = ancestors.find(
|
|
390
|
+
(node) => (0, import_element.isTypeableCombobox)(node.context?.elements.domReference || null)
|
|
391
|
+
)?.context?.elements.domReference;
|
|
392
|
+
const controlInsideElements = [
|
|
393
|
+
floating,
|
|
394
|
+
...portalNodes,
|
|
395
|
+
beforeGuardRef.current,
|
|
396
|
+
afterGuardRef.current,
|
|
397
|
+
portalContext?.beforeOutsideRef.current,
|
|
398
|
+
portalContext?.afterOutsideRef.current,
|
|
399
|
+
...getResolvedInsideElements()
|
|
400
|
+
];
|
|
401
|
+
const insideElements = [
|
|
402
|
+
...controlInsideElements,
|
|
403
|
+
rootAncestorComboboxDomReference,
|
|
404
|
+
(0, import_resolveRef.resolveRef)(previousFocusableElement),
|
|
405
|
+
(0, import_resolveRef.resolveRef)(nextFocusableElement),
|
|
406
|
+
isUntrappedTypeableCombobox ? domReference : null
|
|
407
|
+
].filter((x) => x != null);
|
|
408
|
+
const ariaHiddenCleanup = (0, import_markOthers.markOthers)(insideElements, {
|
|
409
|
+
ariaHidden: modal || isUntrappedTypeableCombobox,
|
|
410
|
+
mark: false
|
|
411
|
+
});
|
|
412
|
+
const markerInsideElements = [floating, ...portalNodes].filter(
|
|
413
|
+
(x) => x != null
|
|
414
|
+
);
|
|
415
|
+
const markerCleanup = (0, import_markOthers.markOthers)(markerInsideElements);
|
|
416
|
+
return () => {
|
|
417
|
+
markerCleanup();
|
|
418
|
+
ariaHiddenCleanup();
|
|
419
|
+
};
|
|
420
|
+
},
|
|
421
|
+
[
|
|
422
|
+
open,
|
|
423
|
+
disabled,
|
|
424
|
+
domReference,
|
|
425
|
+
floating,
|
|
426
|
+
modal,
|
|
427
|
+
portalContext,
|
|
428
|
+
isUntrappedTypeableCombobox,
|
|
429
|
+
tree,
|
|
430
|
+
getNodeId,
|
|
431
|
+
nextFocusableElement,
|
|
432
|
+
previousFocusableElement,
|
|
433
|
+
getResolvedInsideElements
|
|
434
|
+
],
|
|
435
|
+
(0, import_internal.subSlot)(slot, "e:hide")
|
|
436
|
+
);
|
|
437
|
+
(0, import_octane.useLayoutEffect)(
|
|
438
|
+
() => {
|
|
439
|
+
if (!open || disabled || !(0, import_dom.isHTMLElement)(floatingFocusElement)) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const doc = (0, import_owner.ownerDocument)(floatingFocusElement);
|
|
443
|
+
const previouslyFocused = (0, import_element.activeElement)(doc);
|
|
444
|
+
queueMicrotask(() => {
|
|
445
|
+
const initialFocusValueOrFn = initialFocusRef.current;
|
|
446
|
+
const resolvedInitialFocus = typeof initialFocusValueOrFn === "function" ? initialFocusValueOrFn(openInteractionTypeRef.current || "") : initialFocusValueOrFn;
|
|
447
|
+
if (resolvedInitialFocus === void 0 || resolvedInitialFocus === false) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const focusAlreadyInsideFloatingEl = (0, import_element.contains)(floatingFocusElement, previouslyFocused);
|
|
451
|
+
if (focusAlreadyInsideFloatingEl) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
let focusableElements = null;
|
|
455
|
+
const getDefaultFocusElement = () => {
|
|
456
|
+
if (focusableElements == null) {
|
|
457
|
+
focusableElements = getTabbableContent(floatingFocusElement);
|
|
458
|
+
}
|
|
459
|
+
return focusableElements[0] || floatingFocusElement;
|
|
460
|
+
};
|
|
461
|
+
let elToFocus;
|
|
462
|
+
if (resolvedInitialFocus === true || resolvedInitialFocus === null) {
|
|
463
|
+
elToFocus = getDefaultFocusElement();
|
|
464
|
+
} else {
|
|
465
|
+
elToFocus = (0, import_resolveRef.resolveRef)(resolvedInitialFocus);
|
|
466
|
+
}
|
|
467
|
+
elToFocus = elToFocus || getDefaultFocusElement();
|
|
468
|
+
const hadFocusInside = (0, import_element.contains)(floatingFocusElement, (0, import_element.activeElement)(doc));
|
|
469
|
+
(0, import_enqueueFocus.enqueueFocus)(elToFocus, {
|
|
470
|
+
preventScroll: elToFocus === floatingFocusElement,
|
|
471
|
+
shouldFocus() {
|
|
472
|
+
if (!openRef.current) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
if (hadFocusInside) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
const currentActiveElement = (0, import_element.activeElement)(doc);
|
|
479
|
+
const focusMovedInside = currentActiveElement !== elToFocus && (0, import_element.contains)(floatingFocusElement, currentActiveElement);
|
|
480
|
+
return !focusMovedInside;
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
},
|
|
485
|
+
[
|
|
486
|
+
disabled,
|
|
487
|
+
open,
|
|
488
|
+
floatingFocusElement,
|
|
489
|
+
getTabbableContent,
|
|
490
|
+
initialFocusRef,
|
|
491
|
+
openInteractionTypeRef,
|
|
492
|
+
openRef
|
|
493
|
+
],
|
|
494
|
+
(0, import_internal.subSlot)(slot, "e:initfocus")
|
|
495
|
+
);
|
|
496
|
+
(0, import_octane.useLayoutEffect)(
|
|
497
|
+
() => {
|
|
498
|
+
if (disabled || !floatingFocusElement) {
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
const doc = (0, import_owner.ownerDocument)(floatingFocusElement);
|
|
502
|
+
const elementFocusedBeforeOpen = (0, import_element.activeElement)(doc);
|
|
503
|
+
const preferPreviousFocus = openInteractionTypeRef.current == null;
|
|
504
|
+
addPreviouslyFocusedElement(elementFocusedBeforeOpen);
|
|
505
|
+
function onOpenChangeLocal(details) {
|
|
506
|
+
if (!details.open) {
|
|
507
|
+
closeTypeRef.current = getEventType(details.nativeEvent, lastInteractionTypeRef.current);
|
|
508
|
+
}
|
|
509
|
+
if (details.reason === import_createChangeEventDetails.REASONS.triggerHover && details.nativeEvent.type === "mouseleave") {
|
|
510
|
+
preventReturnFocusRef.current = true;
|
|
511
|
+
}
|
|
512
|
+
if (details.reason !== import_createChangeEventDetails.REASONS.outsidePress) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (details.nested) {
|
|
516
|
+
preventReturnFocusRef.current = false;
|
|
517
|
+
} else if ((0, import_event.isVirtualClick)(details.nativeEvent) || (0, import_event.isVirtualPointerEvent)(details.nativeEvent)) {
|
|
518
|
+
preventReturnFocusRef.current = false;
|
|
519
|
+
} else {
|
|
520
|
+
let isPreventScrollSupported = false;
|
|
521
|
+
(0, import_owner.ownerDocument)(floatingFocusElement).createElement("div").focus({
|
|
522
|
+
get preventScroll() {
|
|
523
|
+
isPreventScrollSupported = true;
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
if (isPreventScrollSupported) {
|
|
528
|
+
preventReturnFocusRef.current = false;
|
|
529
|
+
} else {
|
|
530
|
+
preventReturnFocusRef.current = true;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
events.on("openchange", onOpenChangeLocal);
|
|
535
|
+
function getReturnElement() {
|
|
536
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
537
|
+
let resolvedReturnFocusValue = typeof returnFocusValueOrFn === "function" ? returnFocusValueOrFn(closeTypeRef.current) : returnFocusValueOrFn;
|
|
538
|
+
if (resolvedReturnFocusValue === void 0 || resolvedReturnFocusValue === false) {
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
if (resolvedReturnFocusValue === null) {
|
|
542
|
+
resolvedReturnFocusValue = true;
|
|
543
|
+
}
|
|
544
|
+
const referenceReturnElement = domReference?.isConnected ? domReference : null;
|
|
545
|
+
const previousReturnElement = elementFocusedBeforeOpen?.isConnected && (0, import_dom.getNodeName)(elementFocusedBeforeOpen) !== "body" ? elementFocusedBeforeOpen : null;
|
|
546
|
+
let defaultReturnElement = preferPreviousFocus ? previousReturnElement || referenceReturnElement : referenceReturnElement || previousReturnElement;
|
|
547
|
+
if (!defaultReturnElement) {
|
|
548
|
+
defaultReturnElement = getPreviouslyFocusedElement() || null;
|
|
549
|
+
}
|
|
550
|
+
if (typeof resolvedReturnFocusValue === "boolean") {
|
|
551
|
+
return defaultReturnElement;
|
|
552
|
+
}
|
|
553
|
+
return (0, import_resolveRef.resolveRef)(resolvedReturnFocusValue) || defaultReturnElement || null;
|
|
554
|
+
}
|
|
555
|
+
return () => {
|
|
556
|
+
events.off("openchange", onOpenChangeLocal);
|
|
557
|
+
const activeEl = (0, import_element.activeElement)(doc);
|
|
558
|
+
const insideElements = getResolvedInsideElements();
|
|
559
|
+
const isFocusInsideFloatingTree = (0, import_element.contains)(floating, activeEl) || insideElements.some(
|
|
560
|
+
(element) => element === activeEl || (0, import_element.contains)(element, activeEl)
|
|
561
|
+
) || tree && (0, import_nodes.getNodeChildren)(tree.nodesRef.current, getNodeId(), false).some(
|
|
562
|
+
(node) => (0, import_element.contains)(node.context?.elements.floating, activeEl)
|
|
563
|
+
);
|
|
564
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
565
|
+
const returnElement = getReturnElement();
|
|
566
|
+
queueMicrotask(() => {
|
|
567
|
+
const tabbableReturnElement = getFirstTabbableElement(returnElement);
|
|
568
|
+
const hasExplicitReturnFocus = typeof returnFocusValueOrFn !== "boolean";
|
|
569
|
+
if (returnFocusValueOrFn && !preventReturnFocusRef.current && (0, import_dom.isHTMLElement)(tabbableReturnElement) && (!hasExplicitReturnFocus && tabbableReturnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)) {
|
|
570
|
+
tabbableReturnElement.focus({ preventScroll: true });
|
|
571
|
+
}
|
|
572
|
+
preventReturnFocusRef.current = false;
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
[
|
|
577
|
+
disabled,
|
|
578
|
+
floating,
|
|
579
|
+
floatingFocusElement,
|
|
580
|
+
returnFocusRef,
|
|
581
|
+
openInteractionTypeRef,
|
|
582
|
+
events,
|
|
583
|
+
tree,
|
|
584
|
+
domReference,
|
|
585
|
+
getNodeId,
|
|
586
|
+
getResolvedInsideElements
|
|
587
|
+
],
|
|
588
|
+
(0, import_internal.subSlot)(slot, "e:returnfocus")
|
|
589
|
+
);
|
|
590
|
+
(0, import_octane.useLayoutEffect)(
|
|
591
|
+
() => {
|
|
592
|
+
if (!import_platform.platform.engine.webkit || open || !floating) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const activeEl = (0, import_element.activeElement)((0, import_owner.ownerDocument)(floating));
|
|
596
|
+
if (!(0, import_dom.isHTMLElement)(activeEl) || !(0, import_element.isTypeableElement)(activeEl)) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if ((0, import_element.contains)(floating, activeEl)) {
|
|
600
|
+
activeEl.blur();
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
[open, floating],
|
|
604
|
+
(0, import_internal.subSlot)(slot, "e:webkit")
|
|
605
|
+
);
|
|
606
|
+
(0, import_octane.useLayoutEffect)(
|
|
607
|
+
() => {
|
|
608
|
+
if (disabled || !portalContext) {
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
portalContext.setFocusManagerState({
|
|
612
|
+
modal,
|
|
613
|
+
closeOnFocusOut,
|
|
614
|
+
open,
|
|
615
|
+
onOpenChange: store.setOpen,
|
|
616
|
+
domReference
|
|
617
|
+
});
|
|
618
|
+
return () => {
|
|
619
|
+
portalContext.setFocusManagerState(null);
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
[disabled, portalContext, modal, open, store, closeOnFocusOut, domReference],
|
|
623
|
+
(0, import_internal.subSlot)(slot, "e:portalsync")
|
|
624
|
+
);
|
|
625
|
+
(0, import_octane.useLayoutEffect)(
|
|
626
|
+
() => {
|
|
627
|
+
if (disabled || !floatingFocusElement) {
|
|
628
|
+
return void 0;
|
|
629
|
+
}
|
|
630
|
+
handleTabIndex(floatingFocusElement);
|
|
631
|
+
return () => {
|
|
632
|
+
queueMicrotask(clearDisconnectedPreviouslyFocusedElements);
|
|
633
|
+
};
|
|
634
|
+
},
|
|
635
|
+
[disabled, floatingFocusElement],
|
|
636
|
+
(0, import_internal.subSlot)(slot, "e:tabindex")
|
|
637
|
+
);
|
|
638
|
+
const shouldRenderGuards = !disabled && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
639
|
+
return [
|
|
640
|
+
shouldRenderGuards ? (0, import_octane.createElement)(import_FocusGuard.FocusGuard, {
|
|
641
|
+
key: "guard-inside-before",
|
|
642
|
+
"data-type": "inside",
|
|
643
|
+
ref: mergedBeforeGuardRef,
|
|
644
|
+
onFocus(event) {
|
|
645
|
+
if (modal) {
|
|
646
|
+
const els = getTabbableContent();
|
|
647
|
+
(0, import_enqueueFocus.enqueueFocus)(els[els.length - 1]);
|
|
648
|
+
} else if (portalContext?.portalNode) {
|
|
649
|
+
preventReturnFocusRef.current = false;
|
|
650
|
+
if ((0, import_tabbable.isOutsideEvent)(event, portalContext.portalNode)) {
|
|
651
|
+
const nextTabbable = (0, import_tabbable.getNextTabbable)(domReference);
|
|
652
|
+
nextTabbable?.focus();
|
|
653
|
+
} else {
|
|
654
|
+
(0, import_resolveRef.resolveRef)(previousFocusableElement ?? portalContext.beforeOutsideRef)?.focus();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}) : null,
|
|
659
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "children", children }),
|
|
660
|
+
shouldRenderGuards ? (0, import_octane.createElement)(import_FocusGuard.FocusGuard, {
|
|
661
|
+
key: "guard-inside-after",
|
|
662
|
+
"data-type": "inside",
|
|
663
|
+
ref: mergedAfterGuardRef,
|
|
664
|
+
onFocus(event) {
|
|
665
|
+
if (modal) {
|
|
666
|
+
(0, import_enqueueFocus.enqueueFocus)(getTabbableContent()[0]);
|
|
667
|
+
} else if (portalContext?.portalNode) {
|
|
668
|
+
if (closeOnFocusOut) {
|
|
669
|
+
preventReturnFocusRef.current = true;
|
|
670
|
+
}
|
|
671
|
+
if ((0, import_tabbable.isOutsideEvent)(event, portalContext.portalNode)) {
|
|
672
|
+
const prevTabbable = (0, import_tabbable.getPreviousTabbable)(domReference);
|
|
673
|
+
prevTabbable?.focus();
|
|
674
|
+
} else {
|
|
675
|
+
(0, import_resolveRef.resolveRef)(nextFocusableElement ?? portalContext.afterOutsideRef)?.focus();
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}) : null
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
683
|
+
0 && (module.exports = {
|
|
684
|
+
FloatingFocusManager
|
|
685
|
+
});
|