@floating-ui/react-dom-interactions
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,4 +0,6 @@ | ||
import React, { useLayoutEffect, useEffect, useMemo, useContext, useRef, useCallback, createContext, useState, forwardRef } from 'react'; | ||
import * as React from 'react'; | ||
import React__default, { useLayoutEffect, useEffect, useContext, useRef, useCallback, createContext, useState, forwardRef, useMemo } from 'react'; | ||
import { getOverflowAncestors, useFloating as useFloating$1 } from '@floating-ui/react-dom'; | ||
export * from '@floating-ui/react-dom'; | ||
import pointInPolygon from 'point-in-polygon'; | ||
import { createPortal } from 'react-dom'; | ||
@@ -28,12 +30,33 @@ | ||
let globalId = 0; | ||
let serverHandoffComplete = false; | ||
let count = 0; | ||
function genId() { | ||
return "floating-ui-" + globalId++; | ||
} | ||
const genId = () => "floating-ui-" + count++; | ||
function useFloatingId() { | ||
return useMemo(genId, []); | ||
const initialId = serverHandoffComplete ? genId() : null; | ||
const [id, setId] = React.useState(initialId); | ||
index(() => { | ||
if (id === null) { | ||
setId(genId()); | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
React.useEffect(() => { | ||
if (!serverHandoffComplete) { | ||
serverHandoffComplete = true; | ||
} | ||
}, []); | ||
return id; | ||
} | ||
const useReactId = React.useId; | ||
/** | ||
* Uses React 18's built-in `useId()` when available, or falls back to a | ||
* slightly less performant (requiring a double render) implementation for | ||
* earlier React versions. | ||
*/ | ||
const useId = useReactId != null ? useReactId : useFloatingId; | ||
const FloatingNodeContext = /*#__PURE__*/createContext(null); | ||
@@ -52,3 +75,3 @@ const FloatingTreeContext = /*#__PURE__*/createContext(null); | ||
const useFloatingNodeId = () => { | ||
const id = useFloatingId(); | ||
const id = useId(); | ||
const tree = useFloatingTree(); | ||
@@ -79,3 +102,3 @@ const parentId = useFloatingParentNodeId(); | ||
const parentId = useFloatingParentNodeId(); | ||
return /*#__PURE__*/React.createElement(FloatingNodeContext.Provider, { | ||
return /*#__PURE__*/React__default.createElement(FloatingNodeContext.Provider, { | ||
value: { | ||
@@ -105,3 +128,3 @@ id, | ||
}, []); | ||
return /*#__PURE__*/React.createElement(FloatingTreeContext.Provider, { | ||
return /*#__PURE__*/React__default.createElement(FloatingTreeContext.Provider, { | ||
value: { | ||
@@ -182,54 +205,2 @@ nodesRef, | ||
var pointInPolygon$1 = {exports: {}}; | ||
var flat = function pointInPolygonFlat (point, vs, start, end) { | ||
var x = point[0], y = point[1]; | ||
var inside = false; | ||
if (start === undefined) start = 0; | ||
if (end === undefined) end = vs.length; | ||
var len = (end-start)/2; | ||
for (var i = 0, j = len - 1; i < len; j = i++) { | ||
var xi = vs[start+i*2+0], yi = vs[start+i*2+1]; | ||
var xj = vs[start+j*2+0], yj = vs[start+j*2+1]; | ||
var intersect = ((yi > y) !== (yj > y)) | ||
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi); | ||
if (intersect) inside = !inside; | ||
} | ||
return inside; | ||
}; | ||
// ray-casting algorithm based on | ||
// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html | ||
var nested = function pointInPolygonNested (point, vs, start, end) { | ||
var x = point[0], y = point[1]; | ||
var inside = false; | ||
if (start === undefined) start = 0; | ||
if (end === undefined) end = vs.length; | ||
var len = end - start; | ||
for (var i = 0, j = len - 1; i < len; j = i++) { | ||
var xi = vs[i+start][0], yi = vs[i+start][1]; | ||
var xj = vs[j+start][0], yj = vs[j+start][1]; | ||
var intersect = ((yi > y) !== (yj > y)) | ||
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi); | ||
if (intersect) inside = !inside; | ||
} | ||
return inside; | ||
}; | ||
var pointInPolygonFlat = flat; | ||
var pointInPolygonNested = nested; | ||
pointInPolygon$1.exports = function pointInPolygon (point, vs, start, end) { | ||
if (vs.length > 0 && Array.isArray(vs[0])) { | ||
return pointInPolygonNested(point, vs, start, end); | ||
} else { | ||
return pointInPolygonFlat(point, vs, start, end); | ||
} | ||
}; | ||
pointInPolygon$1.exports.nested = pointInPolygonNested; | ||
pointInPolygon$1.exports.flat = pointInPolygonFlat; | ||
var pointInPolygon = pointInPolygon$1.exports; | ||
function getDocument(floating) { | ||
@@ -475,6 +446,6 @@ var _floating$ownerDocume; | ||
setMounted(true); | ||
}, []); | ||
}, [id]); | ||
if (mounted && portalRef.current) { | ||
return /*#__PURE__*/React.createElement(FloatingPortalContext.Provider, { | ||
return /*#__PURE__*/React__default.createElement(FloatingPortalContext.Provider, { | ||
value: id | ||
@@ -512,8 +483,44 @@ }, /*#__PURE__*/createPortal(children, portalRef.current)); | ||
const FloatingOverlay = /*#__PURE__*/forwardRef(function FloatingOverlay(props, ref) { | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
const FloatingOverlay = /*#__PURE__*/forwardRef(function FloatingOverlay(_ref, ref) { | ||
let { | ||
lockScroll = false, | ||
...rest | ||
} = _ref; | ||
index(() => { | ||
if (!lockScroll) { | ||
return; | ||
} | ||
const scrollX = window.pageXOffset; | ||
const scrollY = window.pageYOffset; // RTL <body> scrollbar | ||
const scrollbarX = Math.round(document.documentElement.getBoundingClientRect().left) + document.documentElement.scrollLeft; | ||
const paddingProp = scrollbarX ? 'paddingLeft' : 'paddingRight'; | ||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; | ||
Object.assign(document.body.style, { | ||
position: 'fixed', | ||
overflow: 'hidden', | ||
top: "-" + scrollY + "px", | ||
left: "-" + scrollX + "px", | ||
right: '0', | ||
[paddingProp]: scrollbarWidth + "px" | ||
}); | ||
return () => { | ||
Object.assign(document.body.style, { | ||
position: '', | ||
overflow: '', | ||
top: '', | ||
left: '', | ||
right: '', | ||
[paddingProp]: '' | ||
}); | ||
window.scrollTo(scrollX, scrollY); | ||
}; | ||
}, [lockScroll]); | ||
return /*#__PURE__*/React__default.createElement("div", _extends({ | ||
ref: ref | ||
}, props, { | ||
}, rest, { | ||
style: { | ||
position: 'fixed', | ||
overflow: 'auto', | ||
top: 0, | ||
@@ -523,5 +530,3 @@ right: 0, | ||
left: 0, | ||
width: '100%', | ||
height: '100%', | ||
...props.style | ||
...rest.style | ||
} | ||
@@ -531,3 +536,7 @@ })); | ||
function getDelay(value, prop) { | ||
function getDelay(value, prop, pointerType) { | ||
if (pointerType && pointerType !== 'mouse') { | ||
return 0; | ||
} | ||
if (typeof value === 'number') { | ||
@@ -548,5 +557,5 @@ return value; | ||
delay = 0, | ||
handleLeave = null, | ||
handleClose = null, | ||
mouseOnly = false, | ||
pointerRestMs = 0 | ||
restMs = 0 | ||
} = _temp === void 0 ? {} : _temp; | ||
@@ -561,11 +570,17 @@ const { | ||
const tree = useFloatingTree(); | ||
const pointerTypeRef = useRef(); | ||
const timeoutRef = useRef(); | ||
const handlerRef = useRef(); | ||
const pointerRestTimeoutRef = useRef(); | ||
const blockPointerMoveRef = useRef(true); | ||
const restTimeoutRef = useRef(); | ||
const blockMouseMoveRef = useRef(true); | ||
index(() => { | ||
if (!open) { | ||
pointerTypeRef.current = undefined; | ||
} | ||
}); | ||
useEffect(() => { | ||
function onDismiss() { | ||
clearTimeout(timeoutRef.current); | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
blockPointerMoveRef.current = true; | ||
clearTimeout(restTimeoutRef.current); | ||
blockMouseMoveRef.current = true; | ||
} | ||
@@ -579,3 +594,3 @@ | ||
useEffect(() => { | ||
if (!enabled || !handleLeave) { | ||
if (!enabled || !handleClose) { | ||
return; | ||
@@ -587,3 +602,3 @@ } | ||
if ((_dataRef$current$open = dataRef.current.openEvent) != null && _dataRef$current$open.type.includes('pointer')) { | ||
if ((_dataRef$current$open = dataRef.current.openEvent) != null && _dataRef$current$open.type.includes('mouse')) { | ||
onOpenChange(false); | ||
@@ -598,5 +613,4 @@ } | ||
}; | ||
}, [refs.floating, onOpenChange, enabled, handleLeave, dataRef]); | ||
function closeWithDelay(runElseBranch) { | ||
}, [refs.floating, onOpenChange, enabled, handleClose, dataRef]); | ||
const closeWithDelay = useCallback(function (runElseBranch) { | ||
if (runElseBranch === void 0) { | ||
@@ -608,74 +622,97 @@ runElseBranch = true; | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => onOpenChange(false), getDelay(delay, 'close')); | ||
timeoutRef.current = setTimeout(() => onOpenChange(false), getDelay(delay, 'close', pointerTypeRef.current)); | ||
} else if (runElseBranch) { | ||
onOpenChange(false); | ||
} | ||
} | ||
}, [delay, onOpenChange]); | ||
if (!enabled) { | ||
return {}; | ||
} | ||
function setPointerRef(event) { | ||
pointerTypeRef.current = event.pointerType; | ||
} // Registering the mouse events on the reference directly to bypass React's | ||
// delegation system. If the cursor was on a disabled element and then entered | ||
// the reference (no gap), `mouseenter` doesn't fire in the delegation system. | ||
return { | ||
reference: { | ||
onPointerMove() { | ||
if (open || pointerRestMs === 0) { | ||
return; | ||
} | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
pointerRestTimeoutRef.current = setTimeout(() => { | ||
if (!blockPointerMoveRef.current) { | ||
onOpenChange(true); | ||
} | ||
}, pointerRestMs); | ||
}, | ||
useEffect(() => { | ||
function onMouseEnter(event) { | ||
if (open || mouseOnly && pointerTypeRef.current !== 'mouse') { | ||
return; | ||
} | ||
onPointerEnter(event) { | ||
if (open || mouseOnly && event.pointerType !== 'mouse') { | ||
return; | ||
} | ||
blockMouseMoveRef.current = false; | ||
dataRef.current.openEvent = event; | ||
blockPointerMoveRef.current = false; | ||
dataRef.current.openEvent = event.nativeEvent; | ||
if (delay) { | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => { | ||
onOpenChange(true); | ||
}, getDelay(delay, 'open')); | ||
} else { | ||
if (delay) { | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => { | ||
onOpenChange(true); | ||
} | ||
}, | ||
}, getDelay(delay, 'open', pointerTypeRef.current)); | ||
} else { | ||
onOpenChange(true); | ||
} | ||
} | ||
onPointerLeave(event) { | ||
var _dataRef$current$open2; | ||
function onMouseLeave(event) { | ||
var _dataRef$current$open2; | ||
if (((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.type) === 'click') { | ||
return; | ||
} | ||
if (((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.type) === 'click') { | ||
return; | ||
} | ||
const doc = getDocument(refs.floating.current); | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
const doc = getDocument(refs.floating.current); | ||
clearTimeout(restTimeoutRef.current); | ||
if (handleLeave) { | ||
clearTimeout(timeoutRef.current); | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
handlerRef.current = handleLeave({ ...context, | ||
tree, | ||
x: event.clientX, | ||
y: event.clientY, | ||
if (handleClose) { | ||
clearTimeout(timeoutRef.current); | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
handlerRef.current = handleClose({ ...context, | ||
tree, | ||
x: event.clientX, | ||
y: event.clientY, | ||
onClose() { | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
closeWithDelay(); | ||
} | ||
onClose() { | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
closeWithDelay(); | ||
} | ||
}); | ||
doc.addEventListener('pointermove', handlerRef.current); | ||
}); | ||
doc.addEventListener('pointermove', handlerRef.current); | ||
return; | ||
} | ||
closeWithDelay(); | ||
} | ||
const reference = refs.reference.current; | ||
if (isElement(reference)) { | ||
reference.addEventListener('mouseenter', onMouseEnter); | ||
reference.addEventListener('mouseleave', onMouseLeave); | ||
return () => { | ||
reference.removeEventListener('mouseenter', onMouseEnter); | ||
reference.removeEventListener('mouseleave', onMouseLeave); | ||
}; | ||
} | ||
}, [closeWithDelay, context, delay, handleClose, dataRef, mouseOnly, onOpenChange, open, tree, refs.reference, refs.floating]); | ||
if (!enabled) { | ||
return {}; | ||
} | ||
return { | ||
reference: { | ||
onPointerDown: setPointerRef, | ||
onPointerEnter: setPointerRef, | ||
onMouseMove() { | ||
if (open || restMs === 0) { | ||
return; | ||
} | ||
closeWithDelay(); | ||
clearTimeout(restTimeoutRef.current); | ||
restTimeoutRef.current = setTimeout(() => { | ||
if (!blockMouseMoveRef.current) { | ||
onOpenChange(true); | ||
} | ||
}, restMs); | ||
} | ||
@@ -685,7 +722,7 @@ | ||
floating: { | ||
onPointerEnter() { | ||
onMouseEnter() { | ||
clearTimeout(timeoutRef.current); | ||
}, | ||
onPointerLeave: () => closeWithDelay(false) | ||
onMouseLeave: () => closeWithDelay(false) | ||
} | ||
@@ -724,3 +761,3 @@ }; | ||
}, []); | ||
return /*#__PURE__*/React.createElement(FloatingDelayGroupContext.Provider, { | ||
return /*#__PURE__*/React__default.createElement(FloatingDelayGroupContext.Provider, { | ||
value: { ...state, | ||
@@ -781,3 +818,3 @@ setState, | ||
} = _temp === void 0 ? {} : _temp; | ||
const rootId = useFloatingId(); | ||
const rootId = useId(); | ||
const floatingProps = { | ||
@@ -914,5 +951,14 @@ id: rootId, | ||
const doc = getDocument(refs.floating.current); | ||
escapeKey && doc.addEventListener('keydown', onKeyDown); | ||
outsidePointerDown && doc.addEventListener('pointerdown', onPointerDown); | ||
const ancestors = ancestorScroll ? [...(isElement(refs.reference.current) ? getOverflowAncestors(refs.reference.current) : []), ...(isElement(refs.floating.current) ? getOverflowAncestors(refs.floating.current) : [])] : []; | ||
escapeKey && doc.addEventListener('keydown', onKeyDown); // Use `mousedown` instead of `pointerdown` as it acts more like a click | ||
// on touch devices than a `touchstart` (which can result in accidental | ||
// dismissals too easily.) | ||
outsidePointerDown && doc.addEventListener('mousedown', onPointerDown); | ||
const ancestors = (ancestorScroll ? [...(isElement(refs.reference.current) ? getOverflowAncestors(refs.reference.current) : []), ...(isElement(refs.floating.current) ? getOverflowAncestors(refs.floating.current) : [])] : []).filter(ancestor => { | ||
var _doc$defaultView; | ||
return (// Ignore the visual viewport for scrolling dismissal (allow pinch-zoom) | ||
ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport) | ||
); | ||
}); | ||
ancestors.forEach(ancestor => ancestor.addEventListener('scroll', onScroll, { | ||
@@ -923,3 +969,3 @@ passive: true | ||
escapeKey && doc.removeEventListener('keydown', onKeyDown); | ||
outsidePointerDown && doc.removeEventListener('pointerdown', onPointerDown); | ||
outsidePointerDown && doc.removeEventListener('mousedown', onPointerDown); | ||
ancestors.forEach(ancestor => ancestor.removeEventListener('scroll', onScroll)); | ||
@@ -1019,3 +1065,3 @@ }; | ||
onFocus(event) { | ||
var _refs$reference$curre, _dataRef$current$open; | ||
var _dataRef$current$open, _refs$reference$curre, _dataRef$current$open2; | ||
@@ -1031,3 +1077,3 @@ // Note: due to the `window` focus/blur listeners, switching between | ||
if (event.type === 'focus' && dataRef.current.openEvent === 'mousedown' && isElement(refs.reference.current) && (_refs$reference$curre = refs.reference.current) != null && _refs$reference$curre.contains((_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.target)) { | ||
if (event.type === 'focus' && ((_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type) === 'mousedown' && isElement(refs.reference.current) && (_refs$reference$curre = refs.reference.current) != null && _refs$reference$curre.contains((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.target)) { | ||
return; | ||
@@ -1059,4 +1105,16 @@ } | ||
function stopEvent(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
const FOCUSABLE_ELEMENT_SELECTOR = 'a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]'; | ||
// When working with nested elements, we need to let the rendering occur before | ||
// attempting focus. This fixes unwanted scrolling to the bottom of the document | ||
function focus(el) { | ||
requestAnimationFrame(() => { | ||
el == null ? void 0 : el.focus(); | ||
}); | ||
} | ||
/** | ||
@@ -1067,2 +1125,4 @@ * Traps focus in a loop of focusable elements while the floating element is | ||
*/ | ||
const useFocusTrap = function (_ref, _temp) { | ||
@@ -1080,4 +1140,3 @@ let { | ||
modal = true, | ||
inert = false, | ||
scrollLock = false | ||
inert = false | ||
} = _temp === void 0 ? {} : _temp; | ||
@@ -1118,5 +1177,3 @@ const portalId = useFloatingPortalId(); | ||
if (first === refs.floating.current && !first.contains(first.ownerDocument.activeElement)) { | ||
first.focus({ | ||
preventScroll: true | ||
}); | ||
focus(first); | ||
} | ||
@@ -1130,18 +1187,8 @@ } | ||
if (typeof initialContentFocus === 'number') { | ||
var _focusableElements$in; | ||
(_focusableElements$in = focusableElements[initialContentFocus]) == null ? void 0 : _focusableElements$in.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements[initialContentFocus]); | ||
} else if (initialContentFocus.current) { | ||
var _focusableElements$fi; | ||
(_focusableElements$fi = focusableElements.find(element => element === initialContentFocus.current)) == null ? void 0 : _focusableElements$fi.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements.find(element => element === initialContentFocus.current)); | ||
} | ||
} else if (modal && isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus({ | ||
preventScroll: true | ||
}); | ||
focus(refs.reference.current); | ||
} | ||
@@ -1180,6 +1227,3 @@ }, [getFocusableElements, open, inert, modal, initialContentFocus, enabled, refs.reference, refs.floating]); | ||
if (event.key === 'Tab') { | ||
var _focusableElements$in2; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
stopEvent(event); | ||
const focusableElements = getFocusableElements(); | ||
@@ -1197,5 +1241,3 @@ | ||
(_focusableElements$in2 = focusableElements[indexRef.current]) == null ? void 0 : _focusableElements$in2.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements[indexRef.current]); | ||
} | ||
@@ -1228,36 +1270,23 @@ } | ||
const nodes = doc.querySelectorAll("body > *:not(#" + portalId + ")"); | ||
const originalValues = []; | ||
nodes.forEach(node => { | ||
node.setAttribute('aria-hidden', 'true'); | ||
const originalValue = node.getAttribute('aria-hidden'); | ||
originalValues.push(originalValue); | ||
node.setAttribute('aria-hidden', 'hidden'); | ||
}); | ||
return () => { | ||
if ((portal == null ? void 0 : portal.firstElementChild) === refs.floating.current) { | ||
nodes.forEach(node => { | ||
node.removeAttribute('aria-hidden'); | ||
nodes.forEach((node, index) => { | ||
const originalValue = originalValues[index]; | ||
if (originalValue === null) { | ||
node.removeAttribute('aria-hidden'); | ||
} else { | ||
node.setAttribute('aria-hidden', originalValue); | ||
} | ||
}); | ||
} | ||
}; | ||
}, [open, modal, scrollLock, portalId, enabled, refs.floating]); | ||
index(() => { | ||
if (!open || !enabled) { | ||
return; | ||
} | ||
}, [open, modal, portalId, enabled, refs.floating]); | ||
const doc = getDocument(refs.floating.current); | ||
if (scrollLock) { | ||
var _doc$defaultView; | ||
const scrollbarWidth = ((_doc$defaultView = doc.defaultView) != null ? _doc$defaultView : window).innerWidth - doc.documentElement.offsetWidth; | ||
doc.documentElement.style.overflow = 'hidden'; | ||
doc.body.style.paddingRight = scrollbarWidth + "px"; | ||
} | ||
return () => { | ||
if (scrollLock) { | ||
doc.documentElement.style.overflow = ''; | ||
doc.body.style.paddingRight = ''; | ||
} | ||
}; | ||
}, [open, scrollLock, enabled]); | ||
if (!enabled) { | ||
@@ -1290,7 +1319,2 @@ return {}; | ||
function stop(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
function findNonDisabledIndex(listRef, _temp) { | ||
@@ -1301,9 +1325,10 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
const list = getPresentListItems(listRef); | ||
let index = startingIndex; | ||
do { | ||
var _listRef$current$inde, _listRef$current$inde2; | ||
var _list$index, _list$index2; | ||
index = index + (decrement ? -1 : 1); | ||
} while ((_listRef$current$inde = listRef.current[index]) != null && _listRef$current$inde.hasAttribute('disabled') || ((_listRef$current$inde2 = listRef.current[index]) == null ? void 0 : _listRef$current$inde2.getAttribute('aria-disabled')) === 'true'); | ||
} while ((_list$index = list[index]) != null && _list$index.hasAttribute('disabled') || ((_list$index2 = list[index]) == null ? void 0 : _list$index2.getAttribute('aria-disabled')) === 'true'); | ||
@@ -1326,3 +1351,3 @@ return index === -1 ? 0 : index; | ||
function isMainorientationKey(key, orientation) { | ||
function isMainOrientationKey(key, orientation) { | ||
const vertical = key === ARROW_UP || key === ARROW_DOWN; | ||
@@ -1333,3 +1358,3 @@ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT; | ||
function isMainorientationToStartKey(key, orientation, rtl) { | ||
function isMainOrientationToStartKey(key, orientation, rtl) { | ||
const vertical = key === ARROW_UP; | ||
@@ -1340,3 +1365,3 @@ const horizontal = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT; | ||
function isMainorientationToEndKey(key, orientation, rtl) { | ||
function isMainOrientationToEndKey(key, orientation, rtl) { | ||
const vertical = key === ARROW_DOWN; | ||
@@ -1347,3 +1372,3 @@ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT; | ||
function isCrossorientationOpenKey(key, orientation, rtl) { | ||
function isCrossOrientationOpenKey(key, orientation, rtl) { | ||
const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT; | ||
@@ -1354,3 +1379,3 @@ const horizontal = key === ARROW_DOWN; | ||
function isCrossorientationCloseKey(key, orientation, rtl) { | ||
function isCrossOrientationCloseKey(key, orientation, rtl) { | ||
const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT; | ||
@@ -1368,6 +1393,10 @@ const horizontal = key === ARROW_UP; | ||
decrement: true, | ||
startingIndex: listRef.current.length | ||
startingIndex: getPresentListItems(listRef).length | ||
}); | ||
} | ||
function getPresentListItems(listRef) { | ||
return listRef.current.filter(item => item != null); | ||
} | ||
/** | ||
@@ -1393,2 +1422,3 @@ * Adds focus-managed indexed navigation via arrow keys to a list of items | ||
rtl = false, | ||
virtual = false, | ||
focusItemOnOpen = 'auto', | ||
@@ -1406,9 +1436,16 @@ orientation = 'vertical' | ||
const keyRef = useRef(''); | ||
const [activeId, setActiveId] = useState(); | ||
const focusItem = useCallback((listRef, indexRef) => { | ||
var _listRef$current$inde3; | ||
if (virtual) { | ||
var _getPresentListItems$; | ||
(_listRef$current$inde3 = listRef.current[indexRef.current]) == null ? void 0 : _listRef$current$inde3.focus({ | ||
preventScroll: true | ||
}); | ||
}, []); | ||
setActiveId((_getPresentListItems$ = getPresentListItems(listRef)[indexRef.current]) == null ? void 0 : _getPresentListItems$.id); | ||
} else { | ||
var _getPresentListItems$2; | ||
(_getPresentListItems$2 = getPresentListItems(listRef)[indexRef.current]) == null ? void 0 : _getPresentListItems$2.focus({ | ||
preventScroll: true | ||
}); | ||
} | ||
}, [virtual]); | ||
index(() => { | ||
@@ -1445,4 +1482,4 @@ if (!enabled) { | ||
if (open) { | ||
if (isMainorientationKey(keyRef.current, orientation) || focusOnOpenRef.current && (keyRef.current === ' ' || keyRef.current === 'Enter')) { | ||
indexRef.current = isMainorientationToStartKey(keyRef.current, orientation, rtl) ? getMaxIndex(listRef) : getMinIndex(listRef); | ||
if (isMainOrientationKey(keyRef.current, orientation) || focusOnOpenRef.current && (keyRef.current === ' ' || keyRef.current === 'Enter')) { | ||
indexRef.current = isMainOrientationToStartKey(keyRef.current, orientation, rtl) ? getMaxIndex(listRef) : getMinIndex(listRef); | ||
onNavigate(indexRef.current); | ||
@@ -1454,3 +1491,3 @@ focusItem(listRef, indexRef); | ||
keyRef.current = ''; | ||
}, [open, listRef, selectedIndex, onNavigate, focusItem, enabled]); | ||
}, [open, listRef, selectedIndex, onNavigate, focusItem, enabled, orientation, rtl]); | ||
index(() => { | ||
@@ -1483,5 +1520,6 @@ if (!enabled) { | ||
onNavigate(null); | ||
} | ||
}, [open, selectedIndex, activeIndex, enabled]); | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [open, selectedIndex, activeIndex, enabled, focusItemOnOpen]); | ||
function pointerCheck(event) { | ||
@@ -1498,4 +1536,73 @@ if (focusItemOnOpen === 'auto') { | ||
function onFloatingKeyDown(event) { | ||
if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) { | ||
stopEvent(event); | ||
onOpenChange(false); | ||
if (isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus(); | ||
} | ||
return; | ||
} | ||
const currentIndex = indexRef.current; | ||
const minIndex = getMinIndex(listRef); | ||
const maxIndex = getMaxIndex(listRef); | ||
if (event.key === 'Home') { | ||
indexRef.current = minIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (event.key === 'End') { | ||
indexRef.current = maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (isMainOrientationKey(event.key, orientation)) { | ||
stopEvent(event); | ||
if (!virtual && event.currentTarget.ownerDocument.activeElement === event.currentTarget) { | ||
indexRef.current = selectedIndex != null ? selectedIndex : isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
return; | ||
} | ||
if (isMainOrientationToEndKey(event.key, orientation, rtl)) { | ||
if (loop) { | ||
indexRef.current = currentIndex === maxIndex ? minIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
}); | ||
} else { | ||
indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
})); | ||
} | ||
} else { | ||
if (loop) { | ||
indexRef.current = currentIndex === minIndex ? maxIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
}); | ||
} else { | ||
indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
})); | ||
} | ||
} | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
} | ||
return { | ||
reference: { | ||
reference: { ...(virtual && { | ||
'aria-activedescendant': activeId | ||
}), | ||
onPointerEnter: pointerCheck, | ||
@@ -1505,2 +1612,6 @@ onPointerDown: pointerCheck, | ||
onKeyDown(event) { | ||
if (virtual && open) { | ||
return onFloatingKeyDown(event); | ||
} | ||
if (focusItemOnOpen === 'auto') { | ||
@@ -1512,12 +1623,6 @@ focusOnOpenRef.current = true; | ||
if (isElement(refs.reference.current) && refs.reference.current.tagName !== 'BUTTON') { | ||
if (event.key === 'Enter' || event.key === ' ') { | ||
onOpenChange(true); | ||
} | ||
} | ||
if (nested) { | ||
if (isCrossorientationOpenKey(event.key, orientation, rtl)) { | ||
if (isCrossOrientationOpenKey(event.key, orientation, rtl)) { | ||
indexRef.current = getMinIndex(listRef); | ||
stop(event); | ||
stopEvent(event); | ||
onOpenChange(true); | ||
@@ -1530,5 +1635,5 @@ onNavigate(indexRef.current); | ||
if (isMainorientationKey(event.key, orientation)) { | ||
if (isMainOrientationKey(event.key, orientation)) { | ||
if (selectedIndex == null) { | ||
indexRef.current = isMainorientationToEndKey(event.key, orientation, rtl) ? getMinIndex(listRef) : getMaxIndex(listRef); | ||
indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? getMinIndex(listRef) : getMaxIndex(listRef); | ||
} else { | ||
@@ -1538,6 +1643,10 @@ indexRef.current = selectedIndex; | ||
stop(event); | ||
stopEvent(event); | ||
onOpenChange(true); | ||
onNavigate(indexRef.current); | ||
} | ||
if (virtual && !open) { | ||
onFloatingKeyDown(event); | ||
} | ||
} | ||
@@ -1548,70 +1657,6 @@ | ||
'aria-orientation': orientation === 'both' ? undefined : orientation, | ||
onKeyDown(event) { | ||
if (nested && isCrossorientationCloseKey(event.key, orientation, rtl)) { | ||
stop(event); | ||
onOpenChange(false); | ||
if (isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus(); | ||
} | ||
return; | ||
} | ||
const currentIndex = indexRef.current; | ||
const minIndex = getMinIndex(listRef); | ||
const maxIndex = getMaxIndex(listRef); | ||
if (event.key === 'Home') { | ||
indexRef.current = minIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (event.key === 'End') { | ||
indexRef.current = maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (isMainorientationKey(event.key, orientation)) { | ||
stop(event); | ||
if (event.currentTarget.ownerDocument.activeElement === event.currentTarget) { | ||
indexRef.current = selectedIndex != null ? selectedIndex : isMainorientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
return; | ||
} | ||
if (isMainorientationToEndKey(event.key, orientation, rtl)) { | ||
if (loop) { | ||
indexRef.current = currentIndex === maxIndex ? minIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
}); | ||
} else { | ||
indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
})); | ||
} | ||
} else { | ||
if (loop) { | ||
indexRef.current = currentIndex === minIndex ? maxIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
}); | ||
} else { | ||
indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
})); | ||
} | ||
} | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
} | ||
...(virtual && { | ||
'aria-activedescendant': activeId | ||
}), | ||
onKeyDown: onFloatingKeyDown | ||
} | ||
@@ -1630,3 +1675,4 @@ }; | ||
let { | ||
open | ||
open, | ||
dataRef | ||
} = _ref; | ||
@@ -1638,4 +1684,4 @@ let { | ||
enabled = true, | ||
onFind = null, | ||
debounceMs = 500, | ||
findMatch = null, | ||
resetMs = 500, | ||
ignoreKeys = [], | ||
@@ -1655,9 +1701,14 @@ selectedIndex = null | ||
if (open) { | ||
var _ref3; | ||
clearTimeout(timeoutIdRef.current); | ||
prevIndexRef.current = (_ref3 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref3 : -1; | ||
matchIndexRef.current = null; | ||
stringRef.current = ''; | ||
} | ||
}, [open]); | ||
index(() => { | ||
// Sync arrow key navigation but not typeahead navigation | ||
if (open && stringRef.current === '') { | ||
var _ref3; | ||
prevIndexRef.current = (_ref3 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref3 : -1; | ||
} | ||
}, [open, selectedIndex, activeIndex]); | ||
@@ -1670,5 +1721,8 @@ | ||
if (event.key === ' ' && stringRef.current.length > 0) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
if (stringRef.current.length > 0) { | ||
dataRef.current.typing = true; | ||
if (event.key === ' ') { | ||
stopEvent(event); | ||
} | ||
} | ||
@@ -1701,5 +1755,7 @@ | ||
prevIndexRef.current = matchIndexRef.current; | ||
}, debounceMs); | ||
dataRef.current.typing = false; | ||
}, resetMs); | ||
const prevIndex = prevIndexRef.current; | ||
const str = [...listContent.slice((prevIndex != null ? prevIndex : 0) + 1), ...listContent.slice(0, prevIndex != null ? prevIndex : 0)].find(text => onFind ? onFind(text, stringRef.current) : (text == null ? void 0 : text.toLowerCase().indexOf(stringRef.current)) === 0); | ||
const orderedList = [...listContent.slice((prevIndex != null ? prevIndex : 0) + 1), ...listContent.slice(0, (prevIndex != null ? prevIndex : 0) + 1)]; | ||
const str = findMatch ? findMatch(orderedList, stringRef.current) : orderedList.find(text => (text == null ? void 0 : text.toLowerCase().indexOf(stringRef.current)) === 0); | ||
const index = str ? listContent.indexOf(str) : -1; | ||
@@ -1764,2 +1820,2 @@ | ||
export { FloatingDelayGroup, FloatingNode, FloatingOverlay, FloatingPortal, FloatingTree, safePolygon, useClick, useDelayGroup, useDelayGroupContext, useDismiss, useFloating, useFloatingId, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useFocus, useFocusTrap, useHover, useInteractions, useListNavigation, useRole, useTypeahead }; | ||
export { FloatingDelayGroup, FloatingNode, FloatingOverlay, FloatingPortal, FloatingTree, safePolygon, useClick, useDelayGroup, useDelayGroupContext, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useFocus, useFocusTrap, useHover, useId, useInteractions, useListNavigation, useRole, useTypeahead }; |
@@ -1,1 +0,1 @@ | ||
import e,{useLayoutEffect as n,useEffect as r,useMemo as t,useContext as o,useRef as u,useCallback as c,createContext as i,useState as l,forwardRef as a}from"react";import{getOverflowAncestors as f,useFloating as d}from"@floating-ui/react-dom";export*from"@floating-ui/react-dom";import{createPortal as s}from"react-dom";var v="undefined"!=typeof document?n:r;function p(){const e=new Map;return{emit(n,r){var t;null==(t=e.get(n))||t.forEach((e=>e(r)))},on(n,r){e.set(n,[...e.get(n)||[],r])},off(n,r){e.set(n,(e.get(n)||[]).filter((e=>e!==r)))}}}let g=0;function m(){return"floating-ui-"+g++}function h(){return t(m,[])}const y=i(null),w=i(null),b=()=>{var e,n;return null!=(e=null==(n=o(y))?void 0:n.id)?e:null},E=()=>o(w),x=()=>{const e=h(),n=E(),r=b();return v((()=>{const t={id:e,parentId:r};return null==n||n.addNode(t),()=>{null==n||n.removeNode(t)}}),[n,e,r]),e},k=n=>{let{children:r,id:t}=n;const o=b();return e.createElement(y.Provider,{value:{id:t,parentId:o}},r)},I=n=>{let{children:r}=n;const t=u([]),o=c((e=>{t.current=[...t.current,e]}),[]),i=c((e=>{t.current=t.current.filter((n=>n!==e))}),[]);return e.createElement(w.Provider,{value:{nodesRef:t,addNode:o,removeNode:i,events:p()}},r)};function L(e){return Object.entries(null!=e?e:{}).reduce(((e,n)=>{let[r,t]=n;return e[r]=[t],e}),{})}function T(e,n,r){const t={reference:"reference"===r?L(e):{},floating:"floating"===r?L(e):{}};return n.forEach((e=>{var n;const o=null!=(n=null==e?void 0:e[r])?n:{};Object.keys(o).forEach((e=>{var n;"function"==typeof o[e]&&(null==t[r][e]&&(t[r][e]=[]),null==(n=t[r][e])||n.push(o[e]))}))})),{..."floating"===r&&{tabIndex:-1},...e,...n.reduce(((e,n)=>(Object.assign(e,null==n?void 0:n[r]),e)),{}),...Object.entries(t[r]).reduce(((e,n)=>{let[r,t]=n;return 0===r.indexOf("on")&&(e[r]=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];t.forEach((e=>e(...n)))}),e}),{})}}const A=function(e){return void 0===e&&(e=[]),{getReferenceProps:n=>T(n,e,"reference"),getFloatingProps:n=>T(n,e,"floating")}};var R={exports:{}},O=function(e,n,r,t){var o=e[0],u=e[1],c=!1;void 0===r&&(r=0),void 0===t&&(t=n.length);for(var i=(t-r)/2,l=0,a=i-1;l<i;a=l++){var f=n[r+2*l+0],d=n[r+2*l+1],s=n[r+2*a+0],v=n[r+2*a+1];d>u!=v>u&&o<(s-f)*(u-d)/(v-d)+f&&(c=!c)}return c},D=function(e,n,r,t){var o=e[0],u=e[1],c=!1;void 0===r&&(r=0),void 0===t&&(t=n.length);for(var i=t-r,l=0,a=i-1;l<i;a=l++){var f=n[l+r][0],d=n[l+r][1],s=n[a+r][0],v=n[a+r][1];d>u!=v>u&&o<(s-f)*(u-d)/(v-d)+f&&(c=!c)}return c};R.exports=function(e,n,r,t){return n.length>0&&Array.isArray(n[0])?D(e,n,r,t):O(e,n,r,t)},R.exports.nested=D,R.exports.flat=O;var C=R.exports;function P(e){var n;return null!=(n=null==e?void 0:e.ownerDocument)?n:document}function S(e){var n;return null!=(n=P(e).defaultView)?n:window}function N(e){return!!e&&e instanceof S(e).Element}function j(e){return!!e&&e instanceof S(e).HTMLElement}function B(e,n){var r;let t=null!=(r=null==e?void 0:e.nodesRef.current.filter((e=>{var r;return e.parentId===n&&(null==(r=e.context)?void 0:r.open)})))?r:[],o=t;for(;o.length;){var u;o=null!=(u=null==e?void 0:e.nodesRef.current.filter((e=>{var n;return null==(n=o)?void 0:n.some((n=>{var r;return e.parentId===n.id&&(null==(r=e.context)?void 0:r.open)}))})))?u:[],t=t.concat(o)}return t}function M(e){let n,{timeout:r=0,debug:t=null}=void 0===e?{}:e;return e=>{let{x:o,y:u,placement:c,refs:i,onClose:l,nodeId:a,tree:f}=e;return function(e){var d;if("touch"===e.pointerType)return;const{target:s,clientX:v,clientY:p}=e,g=s;if("pointermove"===e.type&&N(i.reference.current)&&i.reference.current.contains(g)||null!=(d=i.floating.current)&&d.contains(g))return;if(f&&B(f,a).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))return;if(!i.reference.current||!i.floating.current||null==c||null==o||null==u)return;const m=i.reference.current.getBoundingClientRect(),h=i.floating.current.getBoundingClientRect(),y=c.split("-")[0],w=o>h.right-h.width/2,b=u>h.bottom-h.height/2;switch(y){case"top":if(v>=h.left&&v<=h.right&&p>=h.bottom&&p<=m.top)return;break;case"bottom":if(v>=h.left&&v<=h.right&&p>=m.bottom&&p<=h.top)return;break;case"left":if(v>=h.right&&v<=m.left&&p>=h.left&&p<=h.right)return;break;case"right":if(v>=h.right&&v<=m.left&&p>=h.right&&p<=m.left)return}function E(e){let[n,r]=e;const t=h.width>m.width,o=h.height>m.height;switch(y){case"top":{const e=[t?n:w?n+1:n-1,r+1],o=[t?n:w?n-1:n+1,r+1],u=[[h.left,w||t?h.bottom-1:h.top],[h.right,w?t?h.bottom-1:h.top:h.bottom-1]];return w?[e,o,...u]:[e,...u,o]}case"bottom":{const e=[t?n:w?n+1:n-1,r-1],o=[t?n:w?n-1:n+1,r-1],u=[[h.left,w||t?h.top+1:h.bottom],[h.right,w?t?h.top+1:h.bottom:h.top+1]];return w?[e,o,...u]:[e,...u,o]}case"left":{const e=[n+1,o?r:b?r-1:r+1],t=[n+1,o?r:b?r+1:r-1],u=[[b||o?h.right-1:h.left,h.top],[b?o?h.right-1:h.left:h.right-1,h.bottom]];return b?[e,...u,t]:[...u,e,t]}case"right":{const e=[n-1,o?r:b?r+1:r-1],t=[n-1,o?r:b?r-1:r+1],u=[[b||o?h.left+1:h.right,h.top],[b?o?h.left+1:h.right:h.left+1,h.bottom]];return b?[e,t,...u]:[e,...u,t]}}}const x=E([o,u]);"production"!==process.env.NODE_ENV&&(null==t||t(E([o,u]).slice(0,4).join(", "))),C([v,p],x)?r&&(n=setTimeout(l,r)):(clearTimeout(n),l())}}}const K="floating-ui-root",F=i(K),U=n=>{let{children:r,id:t=K}=n;const[o,c]=l(!1),i=u(null);return v((()=>{const e=document.getElementById(t);e?i.current=e:(i.current=document.createElement("div"),i.current.id=t);const n=i.current;document.body.contains(n)||document.body.appendChild(n),c(!0)}),[]),o&&i.current?e.createElement(F.Provider,{value:t},s(r,i.current)):null};function V(){return V=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},V.apply(this,arguments)}const q=a((function(n,r){return e.createElement("div",V({ref:r},n,{style:{position:"fixed",top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",...n.style}}))}));function H(e,n){return"number"==typeof e?e:null==e?void 0:e[n]}const W=function(e,n){let{enabled:t=!0,delay:o=0,handleLeave:c=null,mouseOnly:i=!1,pointerRestMs:l=0}=void 0===n?{}:n;const{open:a,onOpenChange:f,dataRef:d,events:s,refs:v}=e,p=E(),g=u(),m=u(),h=u(),y=u(!0);function w(e){void 0===e&&(e=!0),o?(clearTimeout(g.current),g.current=setTimeout((()=>f(!1)),H(o,"close"))):e&&f(!1)}return r((()=>{function e(){clearTimeout(g.current),clearTimeout(h.current),y.current=!0}return s.on("dismiss",e),()=>{s.off("dismiss",e)}}),[s]),r((()=>{if(!t||!c)return;function e(){var e;null!=(e=d.current.openEvent)&&e.type.includes("pointer")&&f(!1)}const n=P(v.floating.current).documentElement;return n.addEventListener("mouseleave",e),()=>{n.removeEventListener("mouseleave",e)}}),[v.floating,f,t,c,d]),t?{reference:{onPointerMove(){a||0===l||(clearTimeout(h.current),h.current=setTimeout((()=>{y.current||f(!0)}),l))},onPointerEnter(e){a||i&&"mouse"!==e.pointerType||(y.current=!1,d.current.openEvent=e.nativeEvent,o?(clearTimeout(g.current),g.current=setTimeout((()=>{f(!0)}),H(o,"open"))):f(!0))},onPointerLeave(n){var r;if("click"===(null==(r=d.current.openEvent)?void 0:r.type))return;const t=P(v.floating.current);if(clearTimeout(h.current),c)return clearTimeout(g.current),m.current&&t.removeEventListener("pointermove",m.current),m.current=c({...e,tree:p,x:n.clientX,y:n.clientY,onClose(){m.current&&t.removeEventListener("pointermove",m.current),w()}}),void t.addEventListener("pointermove",m.current);w()}},floating:{onPointerEnter(){clearTimeout(g.current)},onPointerLeave:()=>w(!1)}}:{}},X=i({delay:1e3,initialDelay:1e3,currentId:null,setCurrentId:()=>{},setState:()=>{}}),Y=()=>o(X),z=n=>{let{children:r,delay:t}=n;const[o,u]=l({delay:t,initialDelay:t,currentId:null}),i=c((e=>{u((n=>({...n,currentId:e})))}),[]);return e.createElement(X.Provider,{value:{...o,setState:u,setCurrentId:i}},r)},_=(e,n)=>{let{open:t,onOpenChange:o}=e,{id:u}=n;const{currentId:c,initialDelay:i,setState:l}=Y();r((()=>{c&&o&&(l((e=>({...e,delay:{open:0,close:H(i,"close")}}))),c!==u&&o(!1))}),[u,o,l,c,i]),r((()=>{!t&&c===u&&o&&(o(!1),l((e=>({...e,delay:i,currentId:null}))))}),[t,l,c,u,o,i])},G=function(e,n){let{open:r}=e,{enabled:t=!0,role:o="dialog"}=void 0===n?{}:n;const u=h(),c={id:u,role:o};return t?"tooltip"===o?{reference:{"aria-describedby":r?u:void 0},floating:c}:{reference:{"aria-expanded":r?"true":"false","aria-haspopup":o,"aria-controls":r?u:void 0,..."listbox"===o&&{role:"combobox"}},floating:c}:{}},J=function(e,n){let{open:r,onOpenChange:t,dataRef:o}=e,{enabled:u=!0}=void 0===n?{}:n;return u?{reference:{onClick(e){var n;r?"click"===(null==(n=o.current.openEvent)?void 0:n.type)&&t(!1):t(!0);o.current.openEvent=e.nativeEvent}}}:{}},Q=function(e,n){let{open:t,onOpenChange:o,refs:u,events:i,nodeId:l}=e,{enabled:a=!0,escapeKey:d=!0,outsidePointerDown:s=!0,referencePointerDown:v=!1,ancestorScroll:p=!1}=void 0===n?{}:n;const g=E(),m=c((()=>{j(u.reference.current)&&u.reference.current.focus()}),[u.reference.current]);return r((()=>{if(!t||!a)return;function e(e){"Escape"===e.key&&(i.emit("dismiss"),o(!1),m())}function n(e){var n;const r=g&&B(g,l).some((n=>{var r,t;return null==(r=n.context)||null==(t=r.refs.floating.current)?void 0:t.contains(e.target)}));null!=(n=u.floating.current)&&n.contains(e.target)||N(u.reference.current)&&u.reference.current.contains(e.target)||r||(i.emit("dismiss"),o(!1),m())}function r(){o(!1)}const c=P(u.floating.current);d&&c.addEventListener("keydown",e),s&&c.addEventListener("pointerdown",n);const v=p?[...N(u.reference.current)?f(u.reference.current):[],...N(u.floating.current)?f(u.floating.current):[]]:[];return v.forEach((e=>e.addEventListener("scroll",r,{passive:!0}))),()=>{d&&c.removeEventListener("keydown",e),s&&c.removeEventListener("pointerdown",n),v.forEach((e=>e.removeEventListener("scroll",r)))}}),[d,s,i,g,l,t,o,m,p,a,u.floating,u.reference]),a?{reference:{onPointerDown(){v&&(i.emit("dismiss"),o(!1))}}}:{}},Z=function(e,n){let{open:t,onOpenChange:o,dataRef:c,refs:i,events:l}=e,{enabled:a=!0,keyboardOnly:f=!0}=void 0===n?{}:n;const d=u(!1);return r((()=>{var e;if(!a)return;const n=null!=(e=P(i.floating.current).defaultView)?e:window;function r(){d.current=!t}function o(){setTimeout((()=>{d.current=!1}))}return n.addEventListener("focus",o),n.addEventListener("blur",r),()=>{n.addEventListener("focus",o),n.removeEventListener("blur",r)}}),[i.floating,t,a]),r((()=>{if(a)return l.on("dismiss",e),()=>{l.off("dismiss",e)};function e(){d.current=!0}}),[l,a]),a?{reference:{onPointerDown(e){let{pointerType:n}=e;d.current=!(!n||!f)},onFocus(e){var n,r;d.current||"focus"===e.type&&"mousedown"===c.current.openEvent&&N(i.reference.current)&&null!=(n=i.reference.current)&&n.contains(null==(r=c.current.openEvent)?void 0:r.target)||(c.current.openEvent=e.nativeEvent,o(!0))},onBlur(e){var n;const r=e.relatedTarget;null!=(n=i.floating.current)&&n.contains(r)||N(i.reference.current)&&i.reference.current.contains(r)||(d.current=!1,o(!1))}}}:{}},$=function(e,n){let{open:t,onOpenChange:i,refs:l,nodeId:a}=e,{enabled:f=!0,initialContentFocus:d=0,order:s=["content"],modal:p=!0,inert:g=!1,scrollLock:m=!1}=void 0===n?{}:n;const h=o(F),y=E(),w=u(0),b=c((()=>s.map((e=>{return j(l.reference.current)&&"reference"===e?l.reference.current:l.floating.current&&"floating"===e?l.floating.current:"content"===e?Array.from(null!=(n=null==(r=l.floating.current)?void 0:r.querySelectorAll("a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]"))?n:[]):null;var n,r})).filter(Boolean).flat()),[l.floating,l.reference,s]);function x(e){var n;const r=e.relatedTarget;null!=(n=l.floating.current)&&n.contains(r)||!N(l.reference.current)||l.reference.current.contains(r)||i(!1)}return r((()=>{if(!f)return;const e=b();var n;if(g){if(t){const n=e[0];n!==l.floating.current||n.contains(n.ownerDocument.activeElement)||n.focus({preventScroll:!0})}}else if(t){if("number"==typeof d)null==(n=e[d])||n.focus({preventScroll:!0});else if(d.current){var r;null==(r=e.find((e=>e===d.current)))||r.focus({preventScroll:!0})}}else p&&j(l.reference.current)&&l.reference.current.focus({preventScroll:!0})}),[b,t,g,p,d,f,l.reference,l.floating]),r((()=>{if(!p||!f)return;const e=P(l.floating.current);if(!t)return e.removeEventListener("keydown",n),void(w.current=0);function n(e){var n;if((null==y||null==(n=y.nodesRef.current)||!n.filter((e=>{let{parentId:n}=e;return n===a})).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))&&"Tab"===e.key){var r;e.preventDefault(),e.stopPropagation();const n=b();if(g)return;e.shiftKey?w.current=0===w.current?n.length-1:w.current-1:w.current=w.current===n.length-1?0:w.current+1,null==(r=n[w.current])||r.focus({preventScroll:!0})}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[b,null==y?void 0:y.nodesRef,a,t,p,g,f,l.floating]),r((()=>{if(!t||!p||!f)return;const e=P(l.floating.current),n=e.querySelector("#"+h),r=e.querySelectorAll("body > *:not(#"+h+")");return r.forEach((e=>{e.setAttribute("aria-hidden","true")})),()=>{(null==n?void 0:n.firstElementChild)===l.floating.current&&r.forEach((e=>{e.removeAttribute("aria-hidden")}))}}),[t,p,m,h,f,l.floating]),v((()=>{if(!t||!f)return;const e=P(l.floating.current);if(m){var n;const r=(null!=(n=e.defaultView)?n:window).innerWidth-e.documentElement.offsetWidth;e.documentElement.style.overflow="hidden",e.body.style.paddingRight=r+"px"}return()=>{m&&(e.documentElement.style.overflow="",e.body.style.paddingRight="")}}),[t,m,f]),f?p?{floating:{"aria-modal":"true"}}:{reference:{onBlur:x},floating:{onBlur:x}}:{}};function ee(e){e.preventDefault(),e.stopPropagation()}function ne(e,n){let{startingIndex:r=-1,decrement:t=!1}=void 0===n?{}:n,o=r;do{var u,c;o+=t?-1:1}while(null!=(u=e.current[o])&&u.hasAttribute("disabled")||"true"===(null==(c=e.current[o])?void 0:c.getAttribute("aria-disabled")));return-1===o?0:o}function re(e,n,r){switch(e){case"vertical":return n;case"horizontal":return r;default:return n||r}}function te(e,n){return re(n,"ArrowUp"===e||"ArrowDown"===e,"ArrowLeft"===e||"ArrowRight"===e)}function oe(e,n,r){return re(n,"ArrowDown"===e,r?"ArrowLeft"===e:"ArrowRight"===e)}function ue(e){return ne(e)}function ce(e){return ne(e,{decrement:!0,startingIndex:e.current.length})}const ie=function(e,n){let{open:r,onOpenChange:t,refs:o}=e,{listRef:i,activeIndex:l,onNavigate:a,enabled:f=!0,selectedIndex:d=null,loop:s=!1,nested:p=!1,rtl:g=!1,focusItemOnOpen:m="auto",orientation:h="vertical"}=void 0===n?{listRef:{current:[]},activeIndex:null,onNavigate:()=>{}}:n;const y=u(m),w=u(null!=d?d:-1),b=u(""),E=c(((e,n)=>{var r;null==(r=e.current[n.current])||r.focus({preventScroll:!0})}),[]);function x(e){"auto"===m&&(y.current=!e.pointerType)}return v((()=>{f&&(null!=d&&(w.current=d),r&&y.current&&(a(w.current),E(i,w)))}),[r,d,i,a,E,f]),v((()=>{f&&r&&null!=l&&(w.current=l,a(w.current),E(i,w))}),[r,l,i,a,E,f]),v((()=>{null==d&&f&&(r&&(te(b.current,h)||y.current&&(" "===b.current||"Enter"===b.current))&&(w.current=function(e,n,r){return re(n,"ArrowUp"===e,r?"ArrowRight"===e:"ArrowLeft"===e)}(b.current,h,g)?ce(i):ue(i),a(w.current),E(i,w)),b.current="")}),[r,i,d,a,E,f]),v((()=>{var e;f&&(r||null==d||null==(e=o.reference.current)||e.focus({preventScroll:!0}))}),[o.reference,d,r,f]),v((()=>{var e;f&&(r||("auto"===m&&(y.current=!0),w.current=null!=(e=null!=d?d:l)?e:-1,a(null)))}),[r,d,l,f]),f?{reference:{onPointerEnter:x,onPointerDown:x,onKeyDown(e){"auto"===m&&(y.current=!0),b.current=e.key,N(o.reference.current)&&"BUTTON"!==o.reference.current.tagName&&("Enter"!==e.key&&" "!==e.key||t(!0)),p?function(e,n,r){return re(n,r?"ArrowLeft"===e:"ArrowRight"===e,"ArrowDown"===e)}(e.key,h,g)&&(w.current=ue(i),ee(e),t(!0),a(w.current)):te(e.key,h)&&(w.current=null==d?oe(e.key,h,g)?ue(i):ce(i):d,ee(e),t(!0),a(w.current))}},floating:{"aria-orientation":"both"===h?void 0:h,onKeyDown(e){if(p&&function(e,n,r){return re(n,r?"ArrowRight"===e:"ArrowLeft"===e,"ArrowUp"===e)}(e.key,h,g))return ee(e),t(!1),void(j(o.reference.current)&&o.reference.current.focus());const n=w.current,r=ue(i),u=ce(i);if("Home"===e.key&&(w.current=r,a(w.current),E(i,w)),"End"===e.key&&(w.current=u,a(w.current),E(i,w)),te(e.key,h)){if(ee(e),e.currentTarget.ownerDocument.activeElement===e.currentTarget)return w.current=null!=d?d:oe(e.key,h,g)?r:u,a(w.current),void E(i,w);oe(e.key,h,g)?w.current=s?n===u?r:ne(i,{startingIndex:n}):Math.min(u,ne(i,{startingIndex:n})):w.current=s?n===r?u:ne(i,{startingIndex:n,decrement:!0}):Math.max(r,ne(i,{startingIndex:n,decrement:!0})),a(w.current),E(i,w)}}}}:{}},le=function(e,n){var r;let{open:t}=e,{listRef:o,activeIndex:c,onMatch:i=(()=>{}),enabled:l=!0,onFind:a=null,debounceMs:f=500,ignoreKeys:d=[],selectedIndex:s=null}=void 0===n?{listRef:{current:[]},activeIndex:null}:n;const p=u(),g=u(""),m=u(null!=(r=null!=s?s:c)?r:-1),h=u(null);function y(e){if(!e.currentTarget.contains(P(e.currentTarget).activeElement))return;" "===e.key&&g.current.length>0&&(e.preventDefault(),e.stopPropagation());const n=o.current;if(null==n||["Home","End","Escape","Enter","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight",...d].includes(e.key))return;n.every((e=>{var n,r;return!e||(null==(n=e[0])?void 0:n.toLowerCase())!==(null==(r=e[1])?void 0:r.toLowerCase())}))&&g.current===e.key&&(g.current="",m.current=h.current),g.current+=e.key,clearTimeout(p.current),p.current=setTimeout((()=>{g.current="",m.current=h.current}),f);const r=m.current,t=[...n.slice((null!=r?r:0)+1),...n.slice(0,null!=r?r:0)].find((e=>a?a(e,g.current):0===(null==e?void 0:e.toLowerCase().indexOf(g.current)))),u=t?n.indexOf(t):-1;-1!==u&&(i(u),h.current=u)}return v((()=>{var e;t&&(clearTimeout(p.current),m.current=null!=(e=null!=s?s:c)?e:-1,h.current=null,g.current="")}),[t,s,c]),l?{reference:{onKeyDown:y},floating:{onKeyDown:y}}:{}};function ae(e){let{open:n=!1,onOpenChange:r=(()=>{}),placement:o,middleware:c,strategy:i,nodeId:a}=void 0===e?{}:e;const f=E(),s=u({}),g=l((()=>p()))[0],m=d({placement:o,middleware:c,strategy:i}),h=t((()=>({...m,dataRef:s,nodeId:a,events:g,open:n,onOpenChange:r})),[m,s,a,g,n,r]);return v((()=>{const e=null==f?void 0:f.nodesRef.current.find((e=>e.id===a));e&&(e.context=h)})),t((()=>({context:h,...m})),[m,h])}export{z as FloatingDelayGroup,k as FloatingNode,q as FloatingOverlay,U as FloatingPortal,I as FloatingTree,M as safePolygon,J as useClick,_ as useDelayGroup,Y as useDelayGroupContext,Q as useDismiss,ae as useFloating,h as useFloatingId,x as useFloatingNodeId,b as useFloatingParentNodeId,E as useFloatingTree,Z as useFocus,$ as useFocusTrap,W as useHover,A as useInteractions,ie as useListNavigation,G as useRole,le as useTypeahead}; | ||
import*as e from"react";import n,{useLayoutEffect as t,useEffect as r,useContext as o,useRef as u,useCallback as c,createContext as i,useState as l,forwardRef as a,useMemo as f}from"react";import{getOverflowAncestors as d,useFloating as s}from"@floating-ui/react-dom";export*from"@floating-ui/react-dom";import v from"point-in-polygon";import{createPortal as m}from"react-dom";var g="undefined"!=typeof document?t:r;function p(){const e=new Map;return{emit(n,t){var r;null==(r=e.get(n))||r.forEach((e=>e(t)))},on(n,t){e.set(n,[...e.get(n)||[],t])},off(n,t){e.set(n,(e.get(n)||[]).filter((e=>e!==t)))}}}let h=!1,y=0;const w=()=>"floating-ui-"+y++;const b=e.useId,E=null!=b?b:function(){const n=h?w():null,[t,r]=e.useState(n);return g((()=>{null===t&&r(w())}),[]),e.useEffect((()=>{h||(h=!0)}),[]),t},x=i(null),L=i(null),I=()=>{var e,n;return null!=(e=null==(n=o(x))?void 0:n.id)?e:null},A=()=>o(L),T=()=>{const e=E(),n=A(),t=I();return g((()=>{const r={id:e,parentId:t};return null==n||n.addNode(r),()=>{null==n||n.removeNode(r)}}),[n,e,t]),e},k=e=>{let{children:t,id:r}=e;const o=I();return n.createElement(x.Provider,{value:{id:r,parentId:o}},t)},O=e=>{let{children:t}=e;const r=u([]),o=c((e=>{r.current=[...r.current,e]}),[]),i=c((e=>{r.current=r.current.filter((n=>n!==e))}),[]);return n.createElement(L.Provider,{value:{nodesRef:r,addNode:o,removeNode:i,events:p()}},t)};function R(e){return Object.entries(null!=e?e:{}).reduce(((e,n)=>{let[t,r]=n;return e[t]=[r],e}),{})}function C(e,n,t){const r={reference:"reference"===t?R(e):{},floating:"floating"===t?R(e):{}};return n.forEach((e=>{var n;const o=null!=(n=null==e?void 0:e[t])?n:{};Object.keys(o).forEach((e=>{var n;"function"==typeof o[e]&&(null==r[t][e]&&(r[t][e]=[]),null==(n=r[t][e])||n.push(o[e]))}))})),{..."floating"===t&&{tabIndex:-1},...e,...n.reduce(((e,n)=>(Object.assign(e,null==n?void 0:n[t]),e)),{}),...Object.entries(r[t]).reduce(((e,n)=>{let[t,r]=n;return 0===t.indexOf("on")&&(e[t]=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];r.forEach((e=>e(...n)))}),e}),{})}}const D=function(e){return void 0===e&&(e=[]),{getReferenceProps:n=>C(n,e,"reference"),getFloatingProps:n=>C(n,e,"floating")}};function P(e){var n;return null!=(n=null==e?void 0:e.ownerDocument)?n:document}function M(e){var n;return null!=(n=P(e).defaultView)?n:window}function S(e){return!!e&&e instanceof M(e).Element}function j(e){return!!e&&e instanceof M(e).HTMLElement}function B(e,n){var t;let r=null!=(t=null==e?void 0:e.nodesRef.current.filter((e=>{var t;return e.parentId===n&&(null==(t=e.context)?void 0:t.open)})))?t:[],o=r;for(;o.length;){var u;o=null!=(u=null==e?void 0:e.nodesRef.current.filter((e=>{var n;return null==(n=o)?void 0:n.some((n=>{var t;return e.parentId===n.id&&(null==(t=e.context)?void 0:t.open)}))})))?u:[],r=r.concat(o)}return r}function N(e){let n,{timeout:t=0,debug:r=null}=void 0===e?{}:e;return e=>{let{x:o,y:u,placement:c,refs:i,onClose:l,nodeId:a,tree:f}=e;return function(e){var d;if("touch"===e.pointerType)return;const{target:s,clientX:m,clientY:g}=e,p=s;if("pointermove"===e.type&&S(i.reference.current)&&i.reference.current.contains(p)||null!=(d=i.floating.current)&&d.contains(p))return;if(f&&B(f,a).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))return;if(!i.reference.current||!i.floating.current||null==c||null==o||null==u)return;const h=i.reference.current.getBoundingClientRect(),y=i.floating.current.getBoundingClientRect(),w=c.split("-")[0],b=o>y.right-y.width/2,E=u>y.bottom-y.height/2;switch(w){case"top":if(m>=y.left&&m<=y.right&&g>=y.bottom&&g<=h.top)return;break;case"bottom":if(m>=y.left&&m<=y.right&&g>=h.bottom&&g<=y.top)return;break;case"left":if(m>=y.right&&m<=h.left&&g>=y.left&&g<=y.right)return;break;case"right":if(m>=y.right&&m<=h.left&&g>=y.right&&g<=h.left)return}function x(e){let[n,t]=e;const r=y.width>h.width,o=y.height>h.height;switch(w){case"top":{const e=[r?n:b?n+1:n-1,t+1],o=[r?n:b?n-1:n+1,t+1],u=[[y.left,b||r?y.bottom-1:y.top],[y.right,b?r?y.bottom-1:y.top:y.bottom-1]];return b?[e,o,...u]:[e,...u,o]}case"bottom":{const e=[r?n:b?n+1:n-1,t-1],o=[r?n:b?n-1:n+1,t-1],u=[[y.left,b||r?y.top+1:y.bottom],[y.right,b?r?y.top+1:y.bottom:y.top+1]];return b?[e,o,...u]:[e,...u,o]}case"left":{const e=[n+1,o?t:E?t-1:t+1],r=[n+1,o?t:E?t+1:t-1],u=[[E||o?y.right-1:y.left,y.top],[E?o?y.right-1:y.left:y.right-1,y.bottom]];return E?[e,...u,r]:[...u,e,r]}case"right":{const e=[n-1,o?t:E?t+1:t-1],r=[n-1,o?t:E?t-1:t+1],u=[[E||o?y.left+1:y.right,y.top],[E?o?y.left+1:y.right:y.left+1,y.bottom]];return E?[e,r,...u]:[e,...u,r]}}}const L=x([o,u]);"production"!==process.env.NODE_ENV&&(null==r||r(x([o,u]).slice(0,4).join(", "))),v([m,g],L)?t&&(n=setTimeout(l,t)):(clearTimeout(n),l())}}}const K="floating-ui-root",F=i(K),V=e=>{let{children:t,id:r=K}=e;const[o,c]=l(!1),i=u(null);return g((()=>{const e=document.getElementById(r);e?i.current=e:(i.current=document.createElement("div"),i.current.id=r);const n=i.current;document.body.contains(n)||document.body.appendChild(n),c(!0)}),[r]),o&&i.current?n.createElement(F.Provider,{value:r},m(t,i.current)):null};function q(){return q=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},q.apply(this,arguments)}const U=a((function(e,t){let{lockScroll:r=!1,...o}=e;return g((()=>{if(!r)return;const e=window.pageXOffset,n=window.pageYOffset,t=Math.round(document.documentElement.getBoundingClientRect().left)+document.documentElement.scrollLeft?"paddingLeft":"paddingRight",o=window.innerWidth-document.documentElement.clientWidth;return Object.assign(document.body.style,{position:"fixed",overflow:"hidden",top:"-"+n+"px",left:"-"+e+"px",right:"0",[t]:o+"px"}),()=>{Object.assign(document.body.style,{position:"",overflow:"",top:"",left:"",right:"",[t]:""}),window.scrollTo(e,n)}}),[r]),n.createElement("div",q({ref:t},o,{style:{position:"fixed",overflow:"auto",top:0,right:0,bottom:0,left:0,...o.style}}))}));function H(e,n,t){return t&&"mouse"!==t?0:"number"==typeof e?e:null==e?void 0:e[n]}const X=function(e,n){let{enabled:t=!0,delay:o=0,handleClose:i=null,mouseOnly:l=!1,restMs:a=0}=void 0===n?{}:n;const{open:f,onOpenChange:d,dataRef:s,events:v,refs:m}=e,p=A(),h=u(),y=u(),w=u(),b=u(),E=u(!0);g((()=>{f||(h.current=void 0)})),r((()=>{function e(){clearTimeout(y.current),clearTimeout(b.current),E.current=!0}return v.on("dismiss",e),()=>{v.off("dismiss",e)}}),[v]),r((()=>{if(!t||!i)return;function e(){var e;null!=(e=s.current.openEvent)&&e.type.includes("mouse")&&d(!1)}const n=P(m.floating.current).documentElement;return n.addEventListener("mouseleave",e),()=>{n.removeEventListener("mouseleave",e)}}),[m.floating,d,t,i,s]);const x=c((function(e){void 0===e&&(e=!0),o?(clearTimeout(y.current),y.current=setTimeout((()=>d(!1)),H(o,"close",h.current))):e&&d(!1)}),[o,d]);function L(e){h.current=e.pointerType}return r((()=>{function n(e){f||l&&"mouse"!==h.current||(E.current=!1,s.current.openEvent=e,o?(clearTimeout(y.current),y.current=setTimeout((()=>{d(!0)}),H(o,"open",h.current))):d(!0))}function t(n){var t;if("click"===(null==(t=s.current.openEvent)?void 0:t.type))return;const r=P(m.floating.current);if(clearTimeout(b.current),i)return clearTimeout(y.current),w.current&&r.removeEventListener("pointermove",w.current),w.current=i({...e,tree:p,x:n.clientX,y:n.clientY,onClose(){w.current&&r.removeEventListener("pointermove",w.current),x()}}),void r.addEventListener("pointermove",w.current);x()}const r=m.reference.current;if(S(r))return r.addEventListener("mouseenter",n),r.addEventListener("mouseleave",t),()=>{r.removeEventListener("mouseenter",n),r.removeEventListener("mouseleave",t)}}),[x,e,o,i,s,l,d,f,p,m.reference,m.floating]),t?{reference:{onPointerDown:L,onPointerEnter:L,onMouseMove(){f||0===a||(clearTimeout(b.current),b.current=setTimeout((()=>{E.current||d(!0)}),a))}},floating:{onMouseEnter(){clearTimeout(y.current)},onMouseLeave:()=>x(!1)}}:{}},Y=i({delay:1e3,initialDelay:1e3,currentId:null,setCurrentId:()=>{},setState:()=>{}}),W=()=>o(Y),z=e=>{let{children:t,delay:r}=e;const[o,u]=l({delay:r,initialDelay:r,currentId:null}),i=c((e=>{u((n=>({...n,currentId:e})))}),[]);return n.createElement(Y.Provider,{value:{...o,setState:u,setCurrentId:i}},t)},_=(e,n)=>{let{open:t,onOpenChange:o}=e,{id:u}=n;const{currentId:c,initialDelay:i,setState:l}=W();r((()=>{c&&o&&(l((e=>({...e,delay:{open:0,close:H(i,"close")}}))),c!==u&&o(!1))}),[u,o,l,c,i]),r((()=>{!t&&c===u&&o&&(o(!1),l((e=>({...e,delay:i,currentId:null}))))}),[t,l,c,u,o,i])},G=function(e,n){let{open:t}=e,{enabled:r=!0,role:o="dialog"}=void 0===n?{}:n;const u=E(),c={id:u,role:o};return r?"tooltip"===o?{reference:{"aria-describedby":t?u:void 0},floating:c}:{reference:{"aria-expanded":t?"true":"false","aria-haspopup":o,"aria-controls":t?u:void 0,..."listbox"===o&&{role:"combobox"}},floating:c}:{}},J=function(e,n){let{open:t,onOpenChange:r,dataRef:o}=e,{enabled:u=!0}=void 0===n?{}:n;return u?{reference:{onClick(e){var n;t?"click"===(null==(n=o.current.openEvent)?void 0:n.type)&&r(!1):r(!0);o.current.openEvent=e.nativeEvent}}}:{}},Q=function(e,n){let{open:t,onOpenChange:o,refs:u,events:i,nodeId:l}=e,{enabled:a=!0,escapeKey:f=!0,outsidePointerDown:s=!0,referencePointerDown:v=!1,ancestorScroll:m=!1}=void 0===n?{}:n;const g=A(),p=c((()=>{j(u.reference.current)&&u.reference.current.focus()}),[u.reference.current]);return r((()=>{if(!t||!a)return;function e(e){"Escape"===e.key&&(i.emit("dismiss"),o(!1),p())}function n(e){var n;const t=g&&B(g,l).some((n=>{var t,r;return null==(t=n.context)||null==(r=t.refs.floating.current)?void 0:r.contains(e.target)}));null!=(n=u.floating.current)&&n.contains(e.target)||S(u.reference.current)&&u.reference.current.contains(e.target)||t||(i.emit("dismiss"),o(!1),p())}function r(){o(!1)}const c=P(u.floating.current);f&&c.addEventListener("keydown",e),s&&c.addEventListener("mousedown",n);const v=(m?[...S(u.reference.current)?d(u.reference.current):[],...S(u.floating.current)?d(u.floating.current):[]]:[]).filter((e=>{var n;return e!==(null==(n=c.defaultView)?void 0:n.visualViewport)}));return v.forEach((e=>e.addEventListener("scroll",r,{passive:!0}))),()=>{f&&c.removeEventListener("keydown",e),s&&c.removeEventListener("mousedown",n),v.forEach((e=>e.removeEventListener("scroll",r)))}}),[f,s,i,g,l,t,o,p,m,a,u.floating,u.reference]),a?{reference:{onPointerDown(){v&&(i.emit("dismiss"),o(!1))}}}:{}},Z=function(e,n){let{open:t,onOpenChange:o,dataRef:c,refs:i,events:l}=e,{enabled:a=!0,keyboardOnly:f=!0}=void 0===n?{}:n;const d=u(!1);return r((()=>{var e;if(!a)return;const n=null!=(e=P(i.floating.current).defaultView)?e:window;function r(){d.current=!t}function o(){setTimeout((()=>{d.current=!1}))}return n.addEventListener("focus",o),n.addEventListener("blur",r),()=>{n.addEventListener("focus",o),n.removeEventListener("blur",r)}}),[i.floating,t,a]),r((()=>{if(a)return l.on("dismiss",e),()=>{l.off("dismiss",e)};function e(){d.current=!0}}),[l,a]),a?{reference:{onPointerDown(e){let{pointerType:n}=e;d.current=!(!n||!f)},onFocus(e){var n,t,r;d.current||"focus"===e.type&&"mousedown"===(null==(n=c.current.openEvent)?void 0:n.type)&&S(i.reference.current)&&null!=(t=i.reference.current)&&t.contains(null==(r=c.current.openEvent)?void 0:r.target)||(c.current.openEvent=e.nativeEvent,o(!0))},onBlur(e){var n;const t=e.relatedTarget;null!=(n=i.floating.current)&&n.contains(t)||S(i.reference.current)&&i.reference.current.contains(t)||(d.current=!1,o(!1))}}}:{}};function $(e){e.preventDefault(),e.stopPropagation()}function ee(e){requestAnimationFrame((()=>{null==e||e.focus()}))}const ne=function(e,n){let{open:t,onOpenChange:i,refs:l,nodeId:a}=e,{enabled:f=!0,initialContentFocus:d=0,order:s=["content"],modal:v=!0,inert:m=!1}=void 0===n?{}:n;const g=o(F),p=A(),h=u(0),y=c((()=>s.map((e=>{return j(l.reference.current)&&"reference"===e?l.reference.current:l.floating.current&&"floating"===e?l.floating.current:"content"===e?Array.from(null!=(n=null==(t=l.floating.current)?void 0:t.querySelectorAll("a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]"))?n:[]):null;var n,t})).filter(Boolean).flat()),[l.floating,l.reference,s]);function w(e){var n;const t=e.relatedTarget;null!=(n=l.floating.current)&&n.contains(t)||!S(l.reference.current)||l.reference.current.contains(t)||i(!1)}return r((()=>{if(!f)return;const e=y();if(m){if(t){const n=e[0];n!==l.floating.current||n.contains(n.ownerDocument.activeElement)||ee(n)}}else t?"number"==typeof d?ee(e[d]):d.current&&ee(e.find((e=>e===d.current))):v&&j(l.reference.current)&&ee(l.reference.current)}),[y,t,m,v,d,f,l.reference,l.floating]),r((()=>{if(!v||!f)return;const e=P(l.floating.current);if(!t)return e.removeEventListener("keydown",n),void(h.current=0);function n(e){var n;if((null==p||null==(n=p.nodesRef.current)||!n.filter((e=>{let{parentId:n}=e;return n===a})).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))&&"Tab"===e.key){$(e);const n=y();if(m)return;e.shiftKey?h.current=0===h.current?n.length-1:h.current-1:h.current=h.current===n.length-1?0:h.current+1,ee(n[h.current])}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[y,null==p?void 0:p.nodesRef,a,t,v,m,f,l.floating]),r((()=>{if(!t||!v||!f)return;const e=P(l.floating.current),n=e.querySelector("#"+g),r=e.querySelectorAll("body > *:not(#"+g+")"),o=[];return r.forEach((e=>{const n=e.getAttribute("aria-hidden");o.push(n),e.setAttribute("aria-hidden","hidden")})),()=>{(null==n?void 0:n.firstElementChild)===l.floating.current&&r.forEach(((e,n)=>{const t=o[n];null===t?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",t)}))}}),[t,v,g,f,l.floating]),f?v?{floating:{"aria-modal":"true"}}:{reference:{onBlur:w},floating:{onBlur:w}}:{}};function te(e,n){let{startingIndex:t=-1,decrement:r=!1}=void 0===n?{}:n;const o=le(e);let u=t;do{var c,i;u+=r?-1:1}while(null!=(c=o[u])&&c.hasAttribute("disabled")||"true"===(null==(i=o[u])?void 0:i.getAttribute("aria-disabled")));return-1===u?0:u}function re(e,n,t){switch(e){case"vertical":return n;case"horizontal":return t;default:return n||t}}function oe(e,n){return re(n,"ArrowUp"===e||"ArrowDown"===e,"ArrowLeft"===e||"ArrowRight"===e)}function ue(e,n,t){return re(n,"ArrowDown"===e,t?"ArrowLeft"===e:"ArrowRight"===e)}function ce(e){return te(e)}function ie(e){return te(e,{decrement:!0,startingIndex:le(e).length})}function le(e){return e.current.filter((e=>null!=e))}const ae=function(e,n){let{open:t,onOpenChange:r,refs:o}=e,{listRef:i,activeIndex:a,onNavigate:f,enabled:d=!0,selectedIndex:s=null,loop:v=!1,nested:m=!1,rtl:p=!1,virtual:h=!1,focusItemOnOpen:y="auto",orientation:w="vertical"}=void 0===n?{listRef:{current:[]},activeIndex:null,onNavigate:()=>{}}:n;const b=u(y),E=u(null!=s?s:-1),x=u(""),[L,I]=l(),A=c(((e,n)=>{var t,r;h?I(null==(t=le(e)[n.current])?void 0:t.id):null==(r=le(e)[n.current])||r.focus({preventScroll:!0})}),[h]);function T(e){"auto"===y&&(b.current=!e.pointerType)}if(g((()=>{d&&(null!=s&&(E.current=s),t&&b.current&&(f(E.current),A(i,E)))}),[t,s,i,f,A,d]),g((()=>{d&&t&&null!=a&&(E.current=a,f(E.current),A(i,E))}),[t,a,i,f,A,d]),g((()=>{null==s&&d&&(t&&(oe(x.current,w)||b.current&&(" "===x.current||"Enter"===x.current))&&(E.current=function(e,n,t){return re(n,"ArrowUp"===e,t?"ArrowRight"===e:"ArrowLeft"===e)}(x.current,w,p)?ie(i):ce(i),f(E.current),A(i,E)),x.current="")}),[t,i,s,f,A,d,w,p]),g((()=>{var e;d&&(t||null==s||null==(e=o.reference.current)||e.focus({preventScroll:!0}))}),[o.reference,s,t,d]),g((()=>{var e;d&&(t||("auto"===y&&(b.current=!0),E.current=null!=(e=null!=s?s:a)?e:-1,f(null)))}),[t,s,a,d,y]),!d)return{};function k(e){if(m&&function(e,n,t){return re(n,t?"ArrowRight"===e:"ArrowLeft"===e,"ArrowUp"===e)}(e.key,w,p))return $(e),r(!1),void(j(o.reference.current)&&o.reference.current.focus());const n=E.current,t=ce(i),u=ie(i);if("Home"===e.key&&(E.current=t,f(E.current),A(i,E)),"End"===e.key&&(E.current=u,f(E.current),A(i,E)),oe(e.key,w)){if($(e),!h&&e.currentTarget.ownerDocument.activeElement===e.currentTarget)return E.current=null!=s?s:ue(e.key,w,p)?t:u,f(E.current),void A(i,E);ue(e.key,w,p)?E.current=v?n===u?t:te(i,{startingIndex:n}):Math.min(u,te(i,{startingIndex:n})):E.current=v?n===t?u:te(i,{startingIndex:n,decrement:!0}):Math.max(t,te(i,{startingIndex:n,decrement:!0})),f(E.current),A(i,E)}}return{reference:{...h&&{"aria-activedescendant":L},onPointerEnter:T,onPointerDown:T,onKeyDown(e){if(h&&t)return k(e);"auto"===y&&(b.current=!0),x.current=e.key,m?function(e,n,t){return re(n,t?"ArrowLeft"===e:"ArrowRight"===e,"ArrowDown"===e)}(e.key,w,p)&&(E.current=ce(i),$(e),r(!0),f(E.current)):(oe(e.key,w)&&(E.current=null==s?ue(e.key,w,p)?ce(i):ie(i):s,$(e),r(!0),f(E.current)),h&&!t&&k(e))}},floating:{"aria-orientation":"both"===w?void 0:w,...h&&{"aria-activedescendant":L},onKeyDown:k}}},fe=function(e,n){var t;let{open:r,dataRef:o}=e,{listRef:c,activeIndex:i,onMatch:l=(()=>{}),enabled:a=!0,findMatch:f=null,resetMs:d=500,ignoreKeys:s=[],selectedIndex:v=null}=void 0===n?{listRef:{current:[]},activeIndex:null}:n;const m=u(),p=u(""),h=u(null!=(t=null!=v?v:i)?t:-1),y=u(null);function w(e){if(!e.currentTarget.contains(P(e.currentTarget).activeElement))return;p.current.length>0&&(o.current.typing=!0," "===e.key&&$(e));const n=c.current;if(null==n||["Home","End","Escape","Enter","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight",...s].includes(e.key))return;n.every((e=>{var n,t;return!e||(null==(n=e[0])?void 0:n.toLowerCase())!==(null==(t=e[1])?void 0:t.toLowerCase())}))&&p.current===e.key&&(p.current="",h.current=y.current),p.current+=e.key,clearTimeout(m.current),m.current=setTimeout((()=>{p.current="",h.current=y.current,o.current.typing=!1}),d);const t=h.current,r=[...n.slice((null!=t?t:0)+1),...n.slice(0,(null!=t?t:0)+1)],u=f?f(r,p.current):r.find((e=>0===(null==e?void 0:e.toLowerCase().indexOf(p.current)))),i=u?n.indexOf(u):-1;-1!==i&&(l(i),y.current=i)}return g((()=>{r&&(clearTimeout(m.current),y.current=null,p.current="")}),[r]),g((()=>{var e;r&&""===p.current&&(h.current=null!=(e=null!=v?v:i)?e:-1)}),[r,v,i]),a?{reference:{onKeyDown:w},floating:{onKeyDown:w}}:{}};function de(e){let{open:n=!1,onOpenChange:t=(()=>{}),placement:r,middleware:o,strategy:c,nodeId:i}=void 0===e?{}:e;const a=A(),d=u({}),v=l((()=>p()))[0],m=s({placement:r,middleware:o,strategy:c}),h=f((()=>({...m,dataRef:d,nodeId:i,events:v,open:n,onOpenChange:t})),[m,d,i,v,n,t]);return g((()=>{const e=null==a?void 0:a.nodesRef.current.find((e=>e.id===i));e&&(e.context=h)})),f((()=>({context:h,...m})),[m,h])}export{z as FloatingDelayGroup,k as FloatingNode,U as FloatingOverlay,V as FloatingPortal,O as FloatingTree,N as safePolygon,J as useClick,_ as useDelayGroup,W as useDelayGroupContext,Q as useDismiss,de as useFloating,T as useFloatingNodeId,I as useFloatingParentNodeId,A as useFloatingTree,Z as useFocus,ne as useFocusTrap,X as useHover,E as useId,D as useInteractions,ae as useListNavigation,G as useRole,fe as useTypeahead}; |
@@ -9,2 +9,21 @@ (function (global, factory) { | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
@@ -34,12 +53,33 @@ | ||
let globalId = 0; | ||
let serverHandoffComplete = false; | ||
let count = 0; | ||
function genId() { | ||
return "floating-ui-" + globalId++; | ||
} | ||
const genId = () => "floating-ui-" + count++; | ||
function useFloatingId() { | ||
return React.useMemo(genId, []); | ||
const initialId = serverHandoffComplete ? genId() : null; | ||
const [id, setId] = React__namespace.useState(initialId); | ||
index(() => { | ||
if (id === null) { | ||
setId(genId()); | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
React__namespace.useEffect(() => { | ||
if (!serverHandoffComplete) { | ||
serverHandoffComplete = true; | ||
} | ||
}, []); | ||
return id; | ||
} | ||
const useReactId = React__namespace.useId; | ||
/** | ||
* Uses React 18's built-in `useId()` when available, or falls back to a | ||
* slightly less performant (requiring a double render) implementation for | ||
* earlier React versions. | ||
*/ | ||
const useId = useReactId != null ? useReactId : useFloatingId; | ||
const FloatingNodeContext = /*#__PURE__*/React.createContext(null); | ||
@@ -58,3 +98,3 @@ const FloatingTreeContext = /*#__PURE__*/React.createContext(null); | ||
const useFloatingNodeId = () => { | ||
const id = useFloatingId(); | ||
const id = useId(); | ||
const tree = useFloatingTree(); | ||
@@ -478,3 +518,3 @@ const parentId = useFloatingParentNodeId(); | ||
setMounted(true); | ||
}, []); | ||
}, [id]); | ||
@@ -515,8 +555,44 @@ if (mounted && portalRef.current) { | ||
const FloatingOverlay = /*#__PURE__*/React.forwardRef(function FloatingOverlay(props, ref) { | ||
const FloatingOverlay = /*#__PURE__*/React.forwardRef(function FloatingOverlay(_ref, ref) { | ||
let { | ||
lockScroll = false, | ||
...rest | ||
} = _ref; | ||
index(() => { | ||
if (!lockScroll) { | ||
return; | ||
} | ||
const scrollX = window.pageXOffset; | ||
const scrollY = window.pageYOffset; // RTL <body> scrollbar | ||
const scrollbarX = Math.round(document.documentElement.getBoundingClientRect().left) + document.documentElement.scrollLeft; | ||
const paddingProp = scrollbarX ? 'paddingLeft' : 'paddingRight'; | ||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; | ||
Object.assign(document.body.style, { | ||
position: 'fixed', | ||
overflow: 'hidden', | ||
top: "-" + scrollY + "px", | ||
left: "-" + scrollX + "px", | ||
right: '0', | ||
[paddingProp]: scrollbarWidth + "px" | ||
}); | ||
return () => { | ||
Object.assign(document.body.style, { | ||
position: '', | ||
overflow: '', | ||
top: '', | ||
left: '', | ||
right: '', | ||
[paddingProp]: '' | ||
}); | ||
window.scrollTo(scrollX, scrollY); | ||
}; | ||
}, [lockScroll]); | ||
return /*#__PURE__*/React__default["default"].createElement("div", _extends({ | ||
ref: ref | ||
}, props, { | ||
}, rest, { | ||
style: { | ||
position: 'fixed', | ||
overflow: 'auto', | ||
top: 0, | ||
@@ -526,5 +602,3 @@ right: 0, | ||
left: 0, | ||
width: '100%', | ||
height: '100%', | ||
...props.style | ||
...rest.style | ||
} | ||
@@ -534,3 +608,7 @@ })); | ||
function getDelay(value, prop) { | ||
function getDelay(value, prop, pointerType) { | ||
if (pointerType && pointerType !== 'mouse') { | ||
return 0; | ||
} | ||
if (typeof value === 'number') { | ||
@@ -551,5 +629,5 @@ return value; | ||
delay = 0, | ||
handleLeave = null, | ||
handleClose = null, | ||
mouseOnly = false, | ||
pointerRestMs = 0 | ||
restMs = 0 | ||
} = _temp === void 0 ? {} : _temp; | ||
@@ -564,11 +642,17 @@ const { | ||
const tree = useFloatingTree(); | ||
const pointerTypeRef = React.useRef(); | ||
const timeoutRef = React.useRef(); | ||
const handlerRef = React.useRef(); | ||
const pointerRestTimeoutRef = React.useRef(); | ||
const blockPointerMoveRef = React.useRef(true); | ||
const restTimeoutRef = React.useRef(); | ||
const blockMouseMoveRef = React.useRef(true); | ||
index(() => { | ||
if (!open) { | ||
pointerTypeRef.current = undefined; | ||
} | ||
}); | ||
React.useEffect(() => { | ||
function onDismiss() { | ||
clearTimeout(timeoutRef.current); | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
blockPointerMoveRef.current = true; | ||
clearTimeout(restTimeoutRef.current); | ||
blockMouseMoveRef.current = true; | ||
} | ||
@@ -582,3 +666,3 @@ | ||
React.useEffect(() => { | ||
if (!enabled || !handleLeave) { | ||
if (!enabled || !handleClose) { | ||
return; | ||
@@ -590,3 +674,3 @@ } | ||
if ((_dataRef$current$open = dataRef.current.openEvent) != null && _dataRef$current$open.type.includes('pointer')) { | ||
if ((_dataRef$current$open = dataRef.current.openEvent) != null && _dataRef$current$open.type.includes('mouse')) { | ||
onOpenChange(false); | ||
@@ -601,5 +685,4 @@ } | ||
}; | ||
}, [refs.floating, onOpenChange, enabled, handleLeave, dataRef]); | ||
function closeWithDelay(runElseBranch) { | ||
}, [refs.floating, onOpenChange, enabled, handleClose, dataRef]); | ||
const closeWithDelay = React.useCallback(function (runElseBranch) { | ||
if (runElseBranch === void 0) { | ||
@@ -611,74 +694,97 @@ runElseBranch = true; | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => onOpenChange(false), getDelay(delay, 'close')); | ||
timeoutRef.current = setTimeout(() => onOpenChange(false), getDelay(delay, 'close', pointerTypeRef.current)); | ||
} else if (runElseBranch) { | ||
onOpenChange(false); | ||
} | ||
} | ||
}, [delay, onOpenChange]); | ||
if (!enabled) { | ||
return {}; | ||
} | ||
function setPointerRef(event) { | ||
pointerTypeRef.current = event.pointerType; | ||
} // Registering the mouse events on the reference directly to bypass React's | ||
// delegation system. If the cursor was on a disabled element and then entered | ||
// the reference (no gap), `mouseenter` doesn't fire in the delegation system. | ||
return { | ||
reference: { | ||
onPointerMove() { | ||
if (open || pointerRestMs === 0) { | ||
return; | ||
} | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
pointerRestTimeoutRef.current = setTimeout(() => { | ||
if (!blockPointerMoveRef.current) { | ||
onOpenChange(true); | ||
} | ||
}, pointerRestMs); | ||
}, | ||
React.useEffect(() => { | ||
function onMouseEnter(event) { | ||
if (open || mouseOnly && pointerTypeRef.current !== 'mouse') { | ||
return; | ||
} | ||
onPointerEnter(event) { | ||
if (open || mouseOnly && event.pointerType !== 'mouse') { | ||
return; | ||
} | ||
blockMouseMoveRef.current = false; | ||
dataRef.current.openEvent = event; | ||
blockPointerMoveRef.current = false; | ||
dataRef.current.openEvent = event.nativeEvent; | ||
if (delay) { | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => { | ||
onOpenChange(true); | ||
}, getDelay(delay, 'open')); | ||
} else { | ||
if (delay) { | ||
clearTimeout(timeoutRef.current); | ||
timeoutRef.current = setTimeout(() => { | ||
onOpenChange(true); | ||
} | ||
}, | ||
}, getDelay(delay, 'open', pointerTypeRef.current)); | ||
} else { | ||
onOpenChange(true); | ||
} | ||
} | ||
onPointerLeave(event) { | ||
var _dataRef$current$open2; | ||
function onMouseLeave(event) { | ||
var _dataRef$current$open2; | ||
if (((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.type) === 'click') { | ||
return; | ||
} | ||
if (((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.type) === 'click') { | ||
return; | ||
} | ||
const doc = getDocument(refs.floating.current); | ||
clearTimeout(pointerRestTimeoutRef.current); | ||
const doc = getDocument(refs.floating.current); | ||
clearTimeout(restTimeoutRef.current); | ||
if (handleLeave) { | ||
clearTimeout(timeoutRef.current); | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
handlerRef.current = handleLeave({ ...context, | ||
tree, | ||
x: event.clientX, | ||
y: event.clientY, | ||
if (handleClose) { | ||
clearTimeout(timeoutRef.current); | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
handlerRef.current = handleClose({ ...context, | ||
tree, | ||
x: event.clientX, | ||
y: event.clientY, | ||
onClose() { | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
closeWithDelay(); | ||
} | ||
onClose() { | ||
handlerRef.current && doc.removeEventListener('pointermove', handlerRef.current); | ||
closeWithDelay(); | ||
} | ||
}); | ||
doc.addEventListener('pointermove', handlerRef.current); | ||
}); | ||
doc.addEventListener('pointermove', handlerRef.current); | ||
return; | ||
} | ||
closeWithDelay(); | ||
} | ||
const reference = refs.reference.current; | ||
if (isElement(reference)) { | ||
reference.addEventListener('mouseenter', onMouseEnter); | ||
reference.addEventListener('mouseleave', onMouseLeave); | ||
return () => { | ||
reference.removeEventListener('mouseenter', onMouseEnter); | ||
reference.removeEventListener('mouseleave', onMouseLeave); | ||
}; | ||
} | ||
}, [closeWithDelay, context, delay, handleClose, dataRef, mouseOnly, onOpenChange, open, tree, refs.reference, refs.floating]); | ||
if (!enabled) { | ||
return {}; | ||
} | ||
return { | ||
reference: { | ||
onPointerDown: setPointerRef, | ||
onPointerEnter: setPointerRef, | ||
onMouseMove() { | ||
if (open || restMs === 0) { | ||
return; | ||
} | ||
closeWithDelay(); | ||
clearTimeout(restTimeoutRef.current); | ||
restTimeoutRef.current = setTimeout(() => { | ||
if (!blockMouseMoveRef.current) { | ||
onOpenChange(true); | ||
} | ||
}, restMs); | ||
} | ||
@@ -688,7 +794,7 @@ | ||
floating: { | ||
onPointerEnter() { | ||
onMouseEnter() { | ||
clearTimeout(timeoutRef.current); | ||
}, | ||
onPointerLeave: () => closeWithDelay(false) | ||
onMouseLeave: () => closeWithDelay(false) | ||
} | ||
@@ -783,3 +889,3 @@ }; | ||
} = _temp === void 0 ? {} : _temp; | ||
const rootId = useFloatingId(); | ||
const rootId = useId(); | ||
const floatingProps = { | ||
@@ -916,5 +1022,14 @@ id: rootId, | ||
const doc = getDocument(refs.floating.current); | ||
escapeKey && doc.addEventListener('keydown', onKeyDown); | ||
outsidePointerDown && doc.addEventListener('pointerdown', onPointerDown); | ||
const ancestors = ancestorScroll ? [...(isElement(refs.reference.current) ? reactDom.getOverflowAncestors(refs.reference.current) : []), ...(isElement(refs.floating.current) ? reactDom.getOverflowAncestors(refs.floating.current) : [])] : []; | ||
escapeKey && doc.addEventListener('keydown', onKeyDown); // Use `mousedown` instead of `pointerdown` as it acts more like a click | ||
// on touch devices than a `touchstart` (which can result in accidental | ||
// dismissals too easily.) | ||
outsidePointerDown && doc.addEventListener('mousedown', onPointerDown); | ||
const ancestors = (ancestorScroll ? [...(isElement(refs.reference.current) ? reactDom.getOverflowAncestors(refs.reference.current) : []), ...(isElement(refs.floating.current) ? reactDom.getOverflowAncestors(refs.floating.current) : [])] : []).filter(ancestor => { | ||
var _doc$defaultView; | ||
return (// Ignore the visual viewport for scrolling dismissal (allow pinch-zoom) | ||
ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport) | ||
); | ||
}); | ||
ancestors.forEach(ancestor => ancestor.addEventListener('scroll', onScroll, { | ||
@@ -925,3 +1040,3 @@ passive: true | ||
escapeKey && doc.removeEventListener('keydown', onKeyDown); | ||
outsidePointerDown && doc.removeEventListener('pointerdown', onPointerDown); | ||
outsidePointerDown && doc.removeEventListener('mousedown', onPointerDown); | ||
ancestors.forEach(ancestor => ancestor.removeEventListener('scroll', onScroll)); | ||
@@ -1021,3 +1136,3 @@ }; | ||
onFocus(event) { | ||
var _refs$reference$curre, _dataRef$current$open; | ||
var _dataRef$current$open, _refs$reference$curre, _dataRef$current$open2; | ||
@@ -1033,3 +1148,3 @@ // Note: due to the `window` focus/blur listeners, switching between | ||
if (event.type === 'focus' && dataRef.current.openEvent === 'mousedown' && isElement(refs.reference.current) && (_refs$reference$curre = refs.reference.current) != null && _refs$reference$curre.contains((_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.target)) { | ||
if (event.type === 'focus' && ((_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type) === 'mousedown' && isElement(refs.reference.current) && (_refs$reference$curre = refs.reference.current) != null && _refs$reference$curre.contains((_dataRef$current$open2 = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open2.target)) { | ||
return; | ||
@@ -1061,4 +1176,16 @@ } | ||
function stopEvent(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
const FOCUSABLE_ELEMENT_SELECTOR = 'a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]'; | ||
// When working with nested elements, we need to let the rendering occur before | ||
// attempting focus. This fixes unwanted scrolling to the bottom of the document | ||
function focus(el) { | ||
requestAnimationFrame(() => { | ||
el == null ? void 0 : el.focus(); | ||
}); | ||
} | ||
/** | ||
@@ -1069,2 +1196,4 @@ * Traps focus in a loop of focusable elements while the floating element is | ||
*/ | ||
const useFocusTrap = function (_ref, _temp) { | ||
@@ -1082,4 +1211,3 @@ let { | ||
modal = true, | ||
inert = false, | ||
scrollLock = false | ||
inert = false | ||
} = _temp === void 0 ? {} : _temp; | ||
@@ -1120,5 +1248,3 @@ const portalId = useFloatingPortalId(); | ||
if (first === refs.floating.current && !first.contains(first.ownerDocument.activeElement)) { | ||
first.focus({ | ||
preventScroll: true | ||
}); | ||
focus(first); | ||
} | ||
@@ -1132,18 +1258,8 @@ } | ||
if (typeof initialContentFocus === 'number') { | ||
var _focusableElements$in; | ||
(_focusableElements$in = focusableElements[initialContentFocus]) == null ? void 0 : _focusableElements$in.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements[initialContentFocus]); | ||
} else if (initialContentFocus.current) { | ||
var _focusableElements$fi; | ||
(_focusableElements$fi = focusableElements.find(element => element === initialContentFocus.current)) == null ? void 0 : _focusableElements$fi.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements.find(element => element === initialContentFocus.current)); | ||
} | ||
} else if (modal && isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus({ | ||
preventScroll: true | ||
}); | ||
focus(refs.reference.current); | ||
} | ||
@@ -1182,6 +1298,3 @@ }, [getFocusableElements, open, inert, modal, initialContentFocus, enabled, refs.reference, refs.floating]); | ||
if (event.key === 'Tab') { | ||
var _focusableElements$in2; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
stopEvent(event); | ||
const focusableElements = getFocusableElements(); | ||
@@ -1199,5 +1312,3 @@ | ||
(_focusableElements$in2 = focusableElements[indexRef.current]) == null ? void 0 : _focusableElements$in2.focus({ | ||
preventScroll: true | ||
}); | ||
focus(focusableElements[indexRef.current]); | ||
} | ||
@@ -1230,36 +1341,23 @@ } | ||
const nodes = doc.querySelectorAll("body > *:not(#" + portalId + ")"); | ||
const originalValues = []; | ||
nodes.forEach(node => { | ||
node.setAttribute('aria-hidden', 'true'); | ||
const originalValue = node.getAttribute('aria-hidden'); | ||
originalValues.push(originalValue); | ||
node.setAttribute('aria-hidden', 'hidden'); | ||
}); | ||
return () => { | ||
if ((portal == null ? void 0 : portal.firstElementChild) === refs.floating.current) { | ||
nodes.forEach(node => { | ||
node.removeAttribute('aria-hidden'); | ||
nodes.forEach((node, index) => { | ||
const originalValue = originalValues[index]; | ||
if (originalValue === null) { | ||
node.removeAttribute('aria-hidden'); | ||
} else { | ||
node.setAttribute('aria-hidden', originalValue); | ||
} | ||
}); | ||
} | ||
}; | ||
}, [open, modal, scrollLock, portalId, enabled, refs.floating]); | ||
index(() => { | ||
if (!open || !enabled) { | ||
return; | ||
} | ||
}, [open, modal, portalId, enabled, refs.floating]); | ||
const doc = getDocument(refs.floating.current); | ||
if (scrollLock) { | ||
var _doc$defaultView; | ||
const scrollbarWidth = ((_doc$defaultView = doc.defaultView) != null ? _doc$defaultView : window).innerWidth - doc.documentElement.offsetWidth; | ||
doc.documentElement.style.overflow = 'hidden'; | ||
doc.body.style.paddingRight = scrollbarWidth + "px"; | ||
} | ||
return () => { | ||
if (scrollLock) { | ||
doc.documentElement.style.overflow = ''; | ||
doc.body.style.paddingRight = ''; | ||
} | ||
}; | ||
}, [open, scrollLock, enabled]); | ||
if (!enabled) { | ||
@@ -1292,7 +1390,2 @@ return {}; | ||
function stop(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
function findNonDisabledIndex(listRef, _temp) { | ||
@@ -1303,9 +1396,10 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
const list = getPresentListItems(listRef); | ||
let index = startingIndex; | ||
do { | ||
var _listRef$current$inde, _listRef$current$inde2; | ||
var _list$index, _list$index2; | ||
index = index + (decrement ? -1 : 1); | ||
} while ((_listRef$current$inde = listRef.current[index]) != null && _listRef$current$inde.hasAttribute('disabled') || ((_listRef$current$inde2 = listRef.current[index]) == null ? void 0 : _listRef$current$inde2.getAttribute('aria-disabled')) === 'true'); | ||
} while ((_list$index = list[index]) != null && _list$index.hasAttribute('disabled') || ((_list$index2 = list[index]) == null ? void 0 : _list$index2.getAttribute('aria-disabled')) === 'true'); | ||
@@ -1328,3 +1422,3 @@ return index === -1 ? 0 : index; | ||
function isMainorientationKey(key, orientation) { | ||
function isMainOrientationKey(key, orientation) { | ||
const vertical = key === ARROW_UP || key === ARROW_DOWN; | ||
@@ -1335,3 +1429,3 @@ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT; | ||
function isMainorientationToStartKey(key, orientation, rtl) { | ||
function isMainOrientationToStartKey(key, orientation, rtl) { | ||
const vertical = key === ARROW_UP; | ||
@@ -1342,3 +1436,3 @@ const horizontal = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT; | ||
function isMainorientationToEndKey(key, orientation, rtl) { | ||
function isMainOrientationToEndKey(key, orientation, rtl) { | ||
const vertical = key === ARROW_DOWN; | ||
@@ -1349,3 +1443,3 @@ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT; | ||
function isCrossorientationOpenKey(key, orientation, rtl) { | ||
function isCrossOrientationOpenKey(key, orientation, rtl) { | ||
const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT; | ||
@@ -1356,3 +1450,3 @@ const horizontal = key === ARROW_DOWN; | ||
function isCrossorientationCloseKey(key, orientation, rtl) { | ||
function isCrossOrientationCloseKey(key, orientation, rtl) { | ||
const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT; | ||
@@ -1370,6 +1464,10 @@ const horizontal = key === ARROW_UP; | ||
decrement: true, | ||
startingIndex: listRef.current.length | ||
startingIndex: getPresentListItems(listRef).length | ||
}); | ||
} | ||
function getPresentListItems(listRef) { | ||
return listRef.current.filter(item => item != null); | ||
} | ||
/** | ||
@@ -1395,2 +1493,3 @@ * Adds focus-managed indexed navigation via arrow keys to a list of items | ||
rtl = false, | ||
virtual = false, | ||
focusItemOnOpen = 'auto', | ||
@@ -1408,9 +1507,16 @@ orientation = 'vertical' | ||
const keyRef = React.useRef(''); | ||
const [activeId, setActiveId] = React.useState(); | ||
const focusItem = React.useCallback((listRef, indexRef) => { | ||
var _listRef$current$inde3; | ||
if (virtual) { | ||
var _getPresentListItems$; | ||
(_listRef$current$inde3 = listRef.current[indexRef.current]) == null ? void 0 : _listRef$current$inde3.focus({ | ||
preventScroll: true | ||
}); | ||
}, []); | ||
setActiveId((_getPresentListItems$ = getPresentListItems(listRef)[indexRef.current]) == null ? void 0 : _getPresentListItems$.id); | ||
} else { | ||
var _getPresentListItems$2; | ||
(_getPresentListItems$2 = getPresentListItems(listRef)[indexRef.current]) == null ? void 0 : _getPresentListItems$2.focus({ | ||
preventScroll: true | ||
}); | ||
} | ||
}, [virtual]); | ||
index(() => { | ||
@@ -1447,4 +1553,4 @@ if (!enabled) { | ||
if (open) { | ||
if (isMainorientationKey(keyRef.current, orientation) || focusOnOpenRef.current && (keyRef.current === ' ' || keyRef.current === 'Enter')) { | ||
indexRef.current = isMainorientationToStartKey(keyRef.current, orientation, rtl) ? getMaxIndex(listRef) : getMinIndex(listRef); | ||
if (isMainOrientationKey(keyRef.current, orientation) || focusOnOpenRef.current && (keyRef.current === ' ' || keyRef.current === 'Enter')) { | ||
indexRef.current = isMainOrientationToStartKey(keyRef.current, orientation, rtl) ? getMaxIndex(listRef) : getMinIndex(listRef); | ||
onNavigate(indexRef.current); | ||
@@ -1456,3 +1562,3 @@ focusItem(listRef, indexRef); | ||
keyRef.current = ''; | ||
}, [open, listRef, selectedIndex, onNavigate, focusItem, enabled]); | ||
}, [open, listRef, selectedIndex, onNavigate, focusItem, enabled, orientation, rtl]); | ||
index(() => { | ||
@@ -1485,5 +1591,6 @@ if (!enabled) { | ||
onNavigate(null); | ||
} | ||
}, [open, selectedIndex, activeIndex, enabled]); | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [open, selectedIndex, activeIndex, enabled, focusItemOnOpen]); | ||
function pointerCheck(event) { | ||
@@ -1500,4 +1607,73 @@ if (focusItemOnOpen === 'auto') { | ||
function onFloatingKeyDown(event) { | ||
if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) { | ||
stopEvent(event); | ||
onOpenChange(false); | ||
if (isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus(); | ||
} | ||
return; | ||
} | ||
const currentIndex = indexRef.current; | ||
const minIndex = getMinIndex(listRef); | ||
const maxIndex = getMaxIndex(listRef); | ||
if (event.key === 'Home') { | ||
indexRef.current = minIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (event.key === 'End') { | ||
indexRef.current = maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (isMainOrientationKey(event.key, orientation)) { | ||
stopEvent(event); | ||
if (!virtual && event.currentTarget.ownerDocument.activeElement === event.currentTarget) { | ||
indexRef.current = selectedIndex != null ? selectedIndex : isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
return; | ||
} | ||
if (isMainOrientationToEndKey(event.key, orientation, rtl)) { | ||
if (loop) { | ||
indexRef.current = currentIndex === maxIndex ? minIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
}); | ||
} else { | ||
indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
})); | ||
} | ||
} else { | ||
if (loop) { | ||
indexRef.current = currentIndex === minIndex ? maxIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
}); | ||
} else { | ||
indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
})); | ||
} | ||
} | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
} | ||
return { | ||
reference: { | ||
reference: { ...(virtual && { | ||
'aria-activedescendant': activeId | ||
}), | ||
onPointerEnter: pointerCheck, | ||
@@ -1507,2 +1683,6 @@ onPointerDown: pointerCheck, | ||
onKeyDown(event) { | ||
if (virtual && open) { | ||
return onFloatingKeyDown(event); | ||
} | ||
if (focusItemOnOpen === 'auto') { | ||
@@ -1514,12 +1694,6 @@ focusOnOpenRef.current = true; | ||
if (isElement(refs.reference.current) && refs.reference.current.tagName !== 'BUTTON') { | ||
if (event.key === 'Enter' || event.key === ' ') { | ||
onOpenChange(true); | ||
} | ||
} | ||
if (nested) { | ||
if (isCrossorientationOpenKey(event.key, orientation, rtl)) { | ||
if (isCrossOrientationOpenKey(event.key, orientation, rtl)) { | ||
indexRef.current = getMinIndex(listRef); | ||
stop(event); | ||
stopEvent(event); | ||
onOpenChange(true); | ||
@@ -1532,5 +1706,5 @@ onNavigate(indexRef.current); | ||
if (isMainorientationKey(event.key, orientation)) { | ||
if (isMainOrientationKey(event.key, orientation)) { | ||
if (selectedIndex == null) { | ||
indexRef.current = isMainorientationToEndKey(event.key, orientation, rtl) ? getMinIndex(listRef) : getMaxIndex(listRef); | ||
indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? getMinIndex(listRef) : getMaxIndex(listRef); | ||
} else { | ||
@@ -1540,6 +1714,10 @@ indexRef.current = selectedIndex; | ||
stop(event); | ||
stopEvent(event); | ||
onOpenChange(true); | ||
onNavigate(indexRef.current); | ||
} | ||
if (virtual && !open) { | ||
onFloatingKeyDown(event); | ||
} | ||
} | ||
@@ -1550,70 +1728,6 @@ | ||
'aria-orientation': orientation === 'both' ? undefined : orientation, | ||
onKeyDown(event) { | ||
if (nested && isCrossorientationCloseKey(event.key, orientation, rtl)) { | ||
stop(event); | ||
onOpenChange(false); | ||
if (isHTMLElement(refs.reference.current)) { | ||
refs.reference.current.focus(); | ||
} | ||
return; | ||
} | ||
const currentIndex = indexRef.current; | ||
const minIndex = getMinIndex(listRef); | ||
const maxIndex = getMaxIndex(listRef); | ||
if (event.key === 'Home') { | ||
indexRef.current = minIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (event.key === 'End') { | ||
indexRef.current = maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
if (isMainorientationKey(event.key, orientation)) { | ||
stop(event); | ||
if (event.currentTarget.ownerDocument.activeElement === event.currentTarget) { | ||
indexRef.current = selectedIndex != null ? selectedIndex : isMainorientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex; | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
return; | ||
} | ||
if (isMainorientationToEndKey(event.key, orientation, rtl)) { | ||
if (loop) { | ||
indexRef.current = currentIndex === maxIndex ? minIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
}); | ||
} else { | ||
indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex | ||
})); | ||
} | ||
} else { | ||
if (loop) { | ||
indexRef.current = currentIndex === minIndex ? maxIndex : findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
}); | ||
} else { | ||
indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, { | ||
startingIndex: currentIndex, | ||
decrement: true | ||
})); | ||
} | ||
} | ||
onNavigate(indexRef.current); | ||
focusItem(listRef, indexRef); | ||
} | ||
} | ||
...(virtual && { | ||
'aria-activedescendant': activeId | ||
}), | ||
onKeyDown: onFloatingKeyDown | ||
} | ||
@@ -1632,3 +1746,4 @@ }; | ||
let { | ||
open | ||
open, | ||
dataRef | ||
} = _ref; | ||
@@ -1640,4 +1755,4 @@ let { | ||
enabled = true, | ||
onFind = null, | ||
debounceMs = 500, | ||
findMatch = null, | ||
resetMs = 500, | ||
ignoreKeys = [], | ||
@@ -1657,9 +1772,14 @@ selectedIndex = null | ||
if (open) { | ||
var _ref3; | ||
clearTimeout(timeoutIdRef.current); | ||
prevIndexRef.current = (_ref3 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref3 : -1; | ||
matchIndexRef.current = null; | ||
stringRef.current = ''; | ||
} | ||
}, [open]); | ||
index(() => { | ||
// Sync arrow key navigation but not typeahead navigation | ||
if (open && stringRef.current === '') { | ||
var _ref3; | ||
prevIndexRef.current = (_ref3 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref3 : -1; | ||
} | ||
}, [open, selectedIndex, activeIndex]); | ||
@@ -1672,5 +1792,8 @@ | ||
if (event.key === ' ' && stringRef.current.length > 0) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
if (stringRef.current.length > 0) { | ||
dataRef.current.typing = true; | ||
if (event.key === ' ') { | ||
stopEvent(event); | ||
} | ||
} | ||
@@ -1703,5 +1826,7 @@ | ||
prevIndexRef.current = matchIndexRef.current; | ||
}, debounceMs); | ||
dataRef.current.typing = false; | ||
}, resetMs); | ||
const prevIndex = prevIndexRef.current; | ||
const str = [...listContent.slice((prevIndex != null ? prevIndex : 0) + 1), ...listContent.slice(0, prevIndex != null ? prevIndex : 0)].find(text => onFind ? onFind(text, stringRef.current) : (text == null ? void 0 : text.toLowerCase().indexOf(stringRef.current)) === 0); | ||
const orderedList = [...listContent.slice((prevIndex != null ? prevIndex : 0) + 1), ...listContent.slice(0, (prevIndex != null ? prevIndex : 0) + 1)]; | ||
const str = findMatch ? findMatch(orderedList, stringRef.current) : orderedList.find(text => (text == null ? void 0 : text.toLowerCase().indexOf(stringRef.current)) === 0); | ||
const index = str ? listContent.indexOf(str) : -1; | ||
@@ -1777,3 +1902,2 @@ | ||
exports.useFloating = useFloating; | ||
exports.useFloatingId = useFloatingId; | ||
exports.useFloatingNodeId = useFloatingNodeId; | ||
@@ -1785,2 +1909,3 @@ exports.useFloatingParentNodeId = useFloatingParentNodeId; | ||
exports.useHover = useHover; | ||
exports.useId = useId; | ||
exports.useInteractions = useInteractions; | ||
@@ -1787,0 +1912,0 @@ exports.useListNavigation = useListNavigation; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("@floating-ui/react-dom"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","@floating-ui/react-dom","react-dom"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).FloatingUIReactDOM={},e.React,e.FloatingUIReactDOM,e.ReactDOM)}(this,(function(e,n,t,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=o(n),c="undefined"!=typeof document?n.useLayoutEffect:n.useEffect;function l(){const e=new Map;return{emit(n,t){var r;null==(r=e.get(n))||r.forEach((e=>e(t)))},on(n,t){e.set(n,[...e.get(n)||[],t])},off(n,t){e.set(n,(e.get(n)||[]).filter((e=>e!==t)))}}}let i=0;function a(){return"floating-ui-"+i++}function f(){return n.useMemo(a,[])}const s=n.createContext(null),d=n.createContext(null),v=()=>{var e,t;return null!=(e=null==(t=n.useContext(s))?void 0:t.id)?e:null},g=()=>n.useContext(d);function p(e){return Object.entries(null!=e?e:{}).reduce(((e,n)=>{let[t,r]=n;return e[t]=[r],e}),{})}function m(e,n,t){const r={reference:"reference"===t?p(e):{},floating:"floating"===t?p(e):{}};return n.forEach((e=>{var n;const o=null!=(n=null==e?void 0:e[t])?n:{};Object.keys(o).forEach((e=>{var n;"function"==typeof o[e]&&(null==r[t][e]&&(r[t][e]=[]),null==(n=r[t][e])||n.push(o[e]))}))})),{..."floating"===t&&{tabIndex:-1},...e,...n.reduce(((e,n)=>(Object.assign(e,null==n?void 0:n[t]),e)),{}),...Object.entries(r[t]).reduce(((e,n)=>{let[t,r]=n;return 0===t.indexOf("on")&&(e[t]=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];r.forEach((e=>e(...n)))}),e}),{})}}var y={exports:{}},h=function(e,n,t,r){var o=e[0],u=e[1],c=!1;void 0===t&&(t=0),void 0===r&&(r=n.length);for(var l=(r-t)/2,i=0,a=l-1;i<l;a=i++){var f=n[t+2*i+0],s=n[t+2*i+1],d=n[t+2*a+0],v=n[t+2*a+1];s>u!=v>u&&o<(d-f)*(u-s)/(v-s)+f&&(c=!c)}return c},b=function(e,n,t,r){var o=e[0],u=e[1],c=!1;void 0===t&&(t=0),void 0===r&&(r=n.length);for(var l=r-t,i=0,a=l-1;i<l;a=i++){var f=n[i+t][0],s=n[i+t][1],d=n[a+t][0],v=n[a+t][1];s>u!=v>u&&o<(d-f)*(u-s)/(v-s)+f&&(c=!c)}return c};y.exports=function(e,n,t,r){return n.length>0&&Array.isArray(n[0])?b(e,n,t,r):h(e,n,t,r)},y.exports.nested=b,y.exports.flat=h;var E=y.exports;function w(e){var n;return null!=(n=null==e?void 0:e.ownerDocument)?n:document}function x(e){var n;return null!=(n=w(e).defaultView)?n:window}function R(e){return!!e&&e instanceof x(e).Element}function k(e){return!!e&&e instanceof x(e).HTMLElement}function C(e,n){var t;let r=null!=(t=null==e?void 0:e.nodesRef.current.filter((e=>{var t;return e.parentId===n&&(null==(t=e.context)?void 0:t.open)})))?t:[],o=r;for(;o.length;){var u;o=null!=(u=null==e?void 0:e.nodesRef.current.filter((e=>{var n;return null==(n=o)?void 0:n.some((n=>{var t;return e.parentId===n.id&&(null==(t=e.context)?void 0:t.open)}))})))?u:[],r=r.concat(o)}return r}const I="floating-ui-root",T=n.createContext(I);function O(){return O=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},O.apply(this,arguments)}const L=n.forwardRef((function(e,n){return u.default.createElement("div",O({ref:n},e,{style:{position:"fixed",top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",...e.style}}))}));function D(e,n){return"number"==typeof e?e:null==e?void 0:e[n]}const P=n.createContext({delay:1e3,initialDelay:1e3,currentId:null,setCurrentId:()=>{},setState:()=>{}}),A=()=>n.useContext(P),F="ArrowUp",S="ArrowDown",M="ArrowLeft",N="ArrowRight";function j(e){e.preventDefault(),e.stopPropagation()}function B(e,n){let{startingIndex:t=-1,decrement:r=!1}=void 0===n?{}:n,o=t;do{var u,c;o+=r?-1:1}while(null!=(u=e.current[o])&&u.hasAttribute("disabled")||"true"===(null==(c=e.current[o])?void 0:c.getAttribute("aria-disabled")));return-1===o?0:o}function K(e,n,t){switch(e){case"vertical":return n;case"horizontal":return t;default:return n||t}}function q(e,n){return K(n,e===F||e===S,e===M||e===N)}function U(e,n,t){return K(n,e===S,t?e===M:e===N)}function H(e){return B(e)}function V(e){return B(e,{decrement:!0,startingIndex:e.current.length})}e.FloatingDelayGroup=e=>{let{children:t,delay:r}=e;const[o,c]=n.useState({delay:r,initialDelay:r,currentId:null}),l=n.useCallback((e=>{c((n=>({...n,currentId:e})))}),[]);return u.default.createElement(P.Provider,{value:{...o,setState:c,setCurrentId:l}},t)},e.FloatingNode=e=>{let{children:n,id:t}=e;const r=v();return u.default.createElement(s.Provider,{value:{id:t,parentId:r}},n)},e.FloatingOverlay=L,e.FloatingPortal=e=>{let{children:t,id:o=I}=e;const[l,i]=n.useState(!1),a=n.useRef(null);return c((()=>{const e=document.getElementById(o);e?a.current=e:(a.current=document.createElement("div"),a.current.id=o);const n=a.current;document.body.contains(n)||document.body.appendChild(n),i(!0)}),[]),l&&a.current?u.default.createElement(T.Provider,{value:o},r.createPortal(t,a.current)):null},e.FloatingTree=e=>{let{children:t}=e;const r=n.useRef([]),o=n.useCallback((e=>{r.current=[...r.current,e]}),[]),c=n.useCallback((e=>{r.current=r.current.filter((n=>n!==e))}),[]);return u.default.createElement(d.Provider,{value:{nodesRef:r,addNode:o,removeNode:c,events:l()}},t)},e.safePolygon=function(e){let n,{timeout:t=0,debug:r=null}=void 0===e?{}:e;return e=>{let{x:o,y:u,placement:c,refs:l,onClose:i,nodeId:a,tree:f}=e;return function(e){var s;if("touch"===e.pointerType)return;const{target:d,clientX:v,clientY:g}=e,p=d;if("pointermove"===e.type&&R(l.reference.current)&&l.reference.current.contains(p)||null!=(s=l.floating.current)&&s.contains(p))return;if(f&&C(f,a).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))return;if(!l.reference.current||!l.floating.current||null==c||null==o||null==u)return;const m=l.reference.current.getBoundingClientRect(),y=l.floating.current.getBoundingClientRect(),h=c.split("-")[0],b=o>y.right-y.width/2,w=u>y.bottom-y.height/2;switch(h){case"top":if(v>=y.left&&v<=y.right&&g>=y.bottom&&g<=m.top)return;break;case"bottom":if(v>=y.left&&v<=y.right&&g>=m.bottom&&g<=y.top)return;break;case"left":if(v>=y.right&&v<=m.left&&g>=y.left&&g<=y.right)return;break;case"right":if(v>=y.right&&v<=m.left&&g>=y.right&&g<=m.left)return}function x(e){let[n,t]=e;const r=y.width>m.width,o=y.height>m.height;switch(h){case"top":{const e=[r?n:b?n+1:n-1,t+1],o=[r?n:b?n-1:n+1,t+1],u=[[y.left,b||r?y.bottom-1:y.top],[y.right,b?r?y.bottom-1:y.top:y.bottom-1]];return b?[e,o,...u]:[e,...u,o]}case"bottom":{const e=[r?n:b?n+1:n-1,t-1],o=[r?n:b?n-1:n+1,t-1],u=[[y.left,b||r?y.top+1:y.bottom],[y.right,b?r?y.top+1:y.bottom:y.top+1]];return b?[e,o,...u]:[e,...u,o]}case"left":{const e=[n+1,o?t:w?t-1:t+1],r=[n+1,o?t:w?t+1:t-1],u=[[w||o?y.right-1:y.left,y.top],[w?o?y.right-1:y.left:y.right-1,y.bottom]];return w?[e,...u,r]:[...u,e,r]}case"right":{const e=[n-1,o?t:w?t+1:t-1],r=[n-1,o?t:w?t-1:t+1],u=[[w||o?y.left+1:y.right,y.top],[w?o?y.left+1:y.right:y.left+1,y.bottom]];return w?[e,r,...u]:[e,...u,r]}}}const k=x([o,u]);"production"!==process.env.NODE_ENV&&(null==r||r(x([o,u]).slice(0,4).join(", "))),E([v,g],k)?t&&(n=setTimeout(i,t)):(clearTimeout(n),i())}}},e.useClick=function(e,n){let{open:t,onOpenChange:r,dataRef:o}=e,{enabled:u=!0}=void 0===n?{}:n;return u?{reference:{onClick(e){var n;t?"click"===(null==(n=o.current.openEvent)?void 0:n.type)&&r(!1):r(!0);o.current.openEvent=e.nativeEvent}}}:{}},e.useDelayGroup=(e,t)=>{let{open:r,onOpenChange:o}=e,{id:u}=t;const{currentId:c,initialDelay:l,setState:i}=A();n.useEffect((()=>{c&&o&&(i((e=>({...e,delay:{open:0,close:D(l,"close")}}))),c!==u&&o(!1))}),[u,o,i,c,l]),n.useEffect((()=>{!r&&c===u&&o&&(o(!1),i((e=>({...e,delay:l,currentId:null}))))}),[r,i,c,u,o,l])},e.useDelayGroupContext=A,e.useDismiss=function(e,r){let{open:o,onOpenChange:u,refs:c,events:l,nodeId:i}=e,{enabled:a=!0,escapeKey:f=!0,outsidePointerDown:s=!0,referencePointerDown:d=!1,ancestorScroll:v=!1}=void 0===r?{}:r;const p=g(),m=n.useCallback((()=>{k(c.reference.current)&&c.reference.current.focus()}),[c.reference.current]);return n.useEffect((()=>{if(!o||!a)return;function e(e){"Escape"===e.key&&(l.emit("dismiss"),u(!1),m())}function n(e){var n;const t=p&&C(p,i).some((n=>{var t,r;return null==(t=n.context)||null==(r=t.refs.floating.current)?void 0:r.contains(e.target)}));null!=(n=c.floating.current)&&n.contains(e.target)||R(c.reference.current)&&c.reference.current.contains(e.target)||t||(l.emit("dismiss"),u(!1),m())}function r(){u(!1)}const d=w(c.floating.current);f&&d.addEventListener("keydown",e),s&&d.addEventListener("pointerdown",n);const g=v?[...R(c.reference.current)?t.getOverflowAncestors(c.reference.current):[],...R(c.floating.current)?t.getOverflowAncestors(c.floating.current):[]]:[];return g.forEach((e=>e.addEventListener("scroll",r,{passive:!0}))),()=>{f&&d.removeEventListener("keydown",e),s&&d.removeEventListener("pointerdown",n),g.forEach((e=>e.removeEventListener("scroll",r)))}}),[f,s,l,p,i,o,u,m,v,a,c.floating,c.reference]),a?{reference:{onPointerDown(){d&&(l.emit("dismiss"),u(!1))}}}:{}},e.useFloating=function(e){let{open:r=!1,onOpenChange:o=(()=>{}),placement:u,middleware:i,strategy:a,nodeId:f}=void 0===e?{}:e;const s=g(),d=n.useRef({}),v=n.useState((()=>l()))[0],p=t.useFloating({placement:u,middleware:i,strategy:a}),m=n.useMemo((()=>({...p,dataRef:d,nodeId:f,events:v,open:r,onOpenChange:o})),[p,d,f,v,r,o]);return c((()=>{const e=null==s?void 0:s.nodesRef.current.find((e=>e.id===f));e&&(e.context=m)})),n.useMemo((()=>({context:m,...p})),[p,m])},e.useFloatingId=f,e.useFloatingNodeId=()=>{const e=f(),n=g(),t=v();return c((()=>{const r={id:e,parentId:t};return null==n||n.addNode(r),()=>{null==n||n.removeNode(r)}}),[n,e,t]),e},e.useFloatingParentNodeId=v,e.useFloatingTree=g,e.useFocus=function(e,t){let{open:r,onOpenChange:o,dataRef:u,refs:c,events:l}=e,{enabled:i=!0,keyboardOnly:a=!0}=void 0===t?{}:t;const f=n.useRef(!1);return n.useEffect((()=>{var e;if(!i)return;const n=null!=(e=w(c.floating.current).defaultView)?e:window;function t(){f.current=!r}function o(){setTimeout((()=>{f.current=!1}))}return n.addEventListener("focus",o),n.addEventListener("blur",t),()=>{n.addEventListener("focus",o),n.removeEventListener("blur",t)}}),[c.floating,r,i]),n.useEffect((()=>{if(i)return l.on("dismiss",e),()=>{l.off("dismiss",e)};function e(){f.current=!0}}),[l,i]),i?{reference:{onPointerDown(e){let{pointerType:n}=e;f.current=!(!n||!a)},onFocus(e){var n,t;f.current||"focus"===e.type&&"mousedown"===u.current.openEvent&&R(c.reference.current)&&null!=(n=c.reference.current)&&n.contains(null==(t=u.current.openEvent)?void 0:t.target)||(u.current.openEvent=e.nativeEvent,o(!0))},onBlur(e){var n;const t=e.relatedTarget;null!=(n=c.floating.current)&&n.contains(t)||R(c.reference.current)&&c.reference.current.contains(t)||(f.current=!1,o(!1))}}}:{}},e.useFocusTrap=function(e,t){let{open:r,onOpenChange:o,refs:u,nodeId:l}=e,{enabled:i=!0,initialContentFocus:a=0,order:f=["content"],modal:s=!0,inert:d=!1,scrollLock:v=!1}=void 0===t?{}:t;const p=n.useContext(T),m=g(),y=n.useRef(0),h=n.useCallback((()=>f.map((e=>{return k(u.reference.current)&&"reference"===e?u.reference.current:u.floating.current&&"floating"===e?u.floating.current:"content"===e?Array.from(null!=(n=null==(t=u.floating.current)?void 0:t.querySelectorAll("a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]"))?n:[]):null;var n,t})).filter(Boolean).flat()),[u.floating,u.reference,f]);function b(e){var n;const t=e.relatedTarget;null!=(n=u.floating.current)&&n.contains(t)||!R(u.reference.current)||u.reference.current.contains(t)||o(!1)}return n.useEffect((()=>{if(!i)return;const e=h();var n;if(d){if(r){const n=e[0];n!==u.floating.current||n.contains(n.ownerDocument.activeElement)||n.focus({preventScroll:!0})}}else if(r){if("number"==typeof a)null==(n=e[a])||n.focus({preventScroll:!0});else if(a.current){var t;null==(t=e.find((e=>e===a.current)))||t.focus({preventScroll:!0})}}else s&&k(u.reference.current)&&u.reference.current.focus({preventScroll:!0})}),[h,r,d,s,a,i,u.reference,u.floating]),n.useEffect((()=>{if(!s||!i)return;const e=w(u.floating.current);if(!r)return e.removeEventListener("keydown",n),void(y.current=0);function n(e){var n;if((null==m||null==(n=m.nodesRef.current)||!n.filter((e=>{let{parentId:n}=e;return n===l})).some((e=>{let{context:n}=e;return null==n?void 0:n.open})))&&"Tab"===e.key){var t;e.preventDefault(),e.stopPropagation();const n=h();if(d)return;e.shiftKey?y.current=0===y.current?n.length-1:y.current-1:y.current=y.current===n.length-1?0:y.current+1,null==(t=n[y.current])||t.focus({preventScroll:!0})}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[h,null==m?void 0:m.nodesRef,l,r,s,d,i,u.floating]),n.useEffect((()=>{if(!r||!s||!i)return;const e=w(u.floating.current),n=e.querySelector("#"+p),t=e.querySelectorAll("body > *:not(#"+p+")");return t.forEach((e=>{e.setAttribute("aria-hidden","true")})),()=>{(null==n?void 0:n.firstElementChild)===u.floating.current&&t.forEach((e=>{e.removeAttribute("aria-hidden")}))}}),[r,s,v,p,i,u.floating]),c((()=>{if(!r||!i)return;const e=w(u.floating.current);if(v){var n;const t=(null!=(n=e.defaultView)?n:window).innerWidth-e.documentElement.offsetWidth;e.documentElement.style.overflow="hidden",e.body.style.paddingRight=t+"px"}return()=>{v&&(e.documentElement.style.overflow="",e.body.style.paddingRight="")}}),[r,v,i]),i?s?{floating:{"aria-modal":"true"}}:{reference:{onBlur:b},floating:{onBlur:b}}:{}},e.useHover=function(e,t){let{enabled:r=!0,delay:o=0,handleLeave:u=null,mouseOnly:c=!1,pointerRestMs:l=0}=void 0===t?{}:t;const{open:i,onOpenChange:a,dataRef:f,events:s,refs:d}=e,v=g(),p=n.useRef(),m=n.useRef(),y=n.useRef(),h=n.useRef(!0);function b(e){void 0===e&&(e=!0),o?(clearTimeout(p.current),p.current=setTimeout((()=>a(!1)),D(o,"close"))):e&&a(!1)}return n.useEffect((()=>{function e(){clearTimeout(p.current),clearTimeout(y.current),h.current=!0}return s.on("dismiss",e),()=>{s.off("dismiss",e)}}),[s]),n.useEffect((()=>{if(!r||!u)return;function e(){var e;null!=(e=f.current.openEvent)&&e.type.includes("pointer")&&a(!1)}const n=w(d.floating.current).documentElement;return n.addEventListener("mouseleave",e),()=>{n.removeEventListener("mouseleave",e)}}),[d.floating,a,r,u,f]),r?{reference:{onPointerMove(){i||0===l||(clearTimeout(y.current),y.current=setTimeout((()=>{h.current||a(!0)}),l))},onPointerEnter(e){i||c&&"mouse"!==e.pointerType||(h.current=!1,f.current.openEvent=e.nativeEvent,o?(clearTimeout(p.current),p.current=setTimeout((()=>{a(!0)}),D(o,"open"))):a(!0))},onPointerLeave(n){var t;if("click"===(null==(t=f.current.openEvent)?void 0:t.type))return;const r=w(d.floating.current);if(clearTimeout(y.current),u)return clearTimeout(p.current),m.current&&r.removeEventListener("pointermove",m.current),m.current=u({...e,tree:v,x:n.clientX,y:n.clientY,onClose(){m.current&&r.removeEventListener("pointermove",m.current),b()}}),void r.addEventListener("pointermove",m.current);b()}},floating:{onPointerEnter(){clearTimeout(p.current)},onPointerLeave:()=>b(!1)}}:{}},e.useInteractions=function(e){return void 0===e&&(e=[]),{getReferenceProps:n=>m(n,e,"reference"),getFloatingProps:n=>m(n,e,"floating")}},e.useListNavigation=function(e,t){let{open:r,onOpenChange:o,refs:u}=e,{listRef:l,activeIndex:i,onNavigate:a,enabled:f=!0,selectedIndex:s=null,loop:d=!1,nested:v=!1,rtl:g=!1,focusItemOnOpen:p="auto",orientation:m="vertical"}=void 0===t?{listRef:{current:[]},activeIndex:null,onNavigate:()=>{}}:t;const y=n.useRef(p),h=n.useRef(null!=s?s:-1),b=n.useRef(""),E=n.useCallback(((e,n)=>{var t;null==(t=e.current[n.current])||t.focus({preventScroll:!0})}),[]);function w(e){"auto"===p&&(y.current=!e.pointerType)}return c((()=>{f&&(null!=s&&(h.current=s),r&&y.current&&(a(h.current),E(l,h)))}),[r,s,l,a,E,f]),c((()=>{f&&r&&null!=i&&(h.current=i,a(h.current),E(l,h))}),[r,i,l,a,E,f]),c((()=>{null==s&&f&&(r&&(q(b.current,m)||y.current&&(" "===b.current||"Enter"===b.current))&&(h.current=function(e,n,t){return K(n,e===F,t?e===N:e===M)}(b.current,m,g)?V(l):H(l),a(h.current),E(l,h)),b.current="")}),[r,l,s,a,E,f]),c((()=>{var e;f&&(r||null==s||null==(e=u.reference.current)||e.focus({preventScroll:!0}))}),[u.reference,s,r,f]),c((()=>{var e;f&&(r||("auto"===p&&(y.current=!0),h.current=null!=(e=null!=s?s:i)?e:-1,a(null)))}),[r,s,i,f]),f?{reference:{onPointerEnter:w,onPointerDown:w,onKeyDown(e){"auto"===p&&(y.current=!0),b.current=e.key,R(u.reference.current)&&"BUTTON"!==u.reference.current.tagName&&("Enter"!==e.key&&" "!==e.key||o(!0)),v?function(e,n,t){return K(n,t?e===M:e===N,e===S)}(e.key,m,g)&&(h.current=H(l),j(e),o(!0),a(h.current)):q(e.key,m)&&(h.current=null==s?U(e.key,m,g)?H(l):V(l):s,j(e),o(!0),a(h.current))}},floating:{"aria-orientation":"both"===m?void 0:m,onKeyDown(e){if(v&&function(e,n,t){return K(n,t?e===N:e===M,e===F)}(e.key,m,g))return j(e),o(!1),void(k(u.reference.current)&&u.reference.current.focus());const n=h.current,t=H(l),r=V(l);if("Home"===e.key&&(h.current=t,a(h.current),E(l,h)),"End"===e.key&&(h.current=r,a(h.current),E(l,h)),q(e.key,m)){if(j(e),e.currentTarget.ownerDocument.activeElement===e.currentTarget)return h.current=null!=s?s:U(e.key,m,g)?t:r,a(h.current),void E(l,h);U(e.key,m,g)?h.current=d?n===r?t:B(l,{startingIndex:n}):Math.min(r,B(l,{startingIndex:n})):h.current=d?n===t?r:B(l,{startingIndex:n,decrement:!0}):Math.max(t,B(l,{startingIndex:n,decrement:!0})),a(h.current),E(l,h)}}}}:{}},e.useRole=function(e,n){let{open:t}=e,{enabled:r=!0,role:o="dialog"}=void 0===n?{}:n;const u=f(),c={id:u,role:o};return r?"tooltip"===o?{reference:{"aria-describedby":t?u:void 0},floating:c}:{reference:{"aria-expanded":t?"true":"false","aria-haspopup":o,"aria-controls":t?u:void 0,..."listbox"===o&&{role:"combobox"}},floating:c}:{}},e.useTypeahead=function(e,t){var r;let{open:o}=e,{listRef:u,activeIndex:l,onMatch:i=(()=>{}),enabled:a=!0,onFind:f=null,debounceMs:s=500,ignoreKeys:d=[],selectedIndex:v=null}=void 0===t?{listRef:{current:[]},activeIndex:null}:t;const g=n.useRef(),p=n.useRef(""),m=n.useRef(null!=(r=null!=v?v:l)?r:-1),y=n.useRef(null);function h(e){if(!e.currentTarget.contains(w(e.currentTarget).activeElement))return;" "===e.key&&p.current.length>0&&(e.preventDefault(),e.stopPropagation());const n=u.current;if(null==n||["Home","End","Escape","Enter","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight",...d].includes(e.key))return;n.every((e=>{var n,t;return!e||(null==(n=e[0])?void 0:n.toLowerCase())!==(null==(t=e[1])?void 0:t.toLowerCase())}))&&p.current===e.key&&(p.current="",m.current=y.current),p.current+=e.key,clearTimeout(g.current),g.current=setTimeout((()=>{p.current="",m.current=y.current}),s);const t=m.current,r=[...n.slice((null!=t?t:0)+1),...n.slice(0,null!=t?t:0)].find((e=>f?f(e,p.current):0===(null==e?void 0:e.toLowerCase().indexOf(p.current)))),o=r?n.indexOf(r):-1;-1!==o&&(i(o),y.current=o)}return c((()=>{var e;o&&(clearTimeout(g.current),m.current=null!=(e=null!=v?v:l)?e:-1,y.current=null,p.current="")}),[o,v,l]),a?{reference:{onKeyDown:h},floating:{onKeyDown:h}}:{}},Object.keys(t).forEach((function(n){"default"===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@floating-ui/react-dom"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","@floating-ui/react-dom","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FloatingUIReactDOM={},e.React,e.FloatingUIReactDOM,e.ReactDOM)}(this,(function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var c=u(t),i=o(t),l="undefined"!=typeof document?t.useLayoutEffect:t.useEffect;function a(){const e=new Map;return{emit(t,n){var r;null==(r=e.get(t))||r.forEach((e=>e(n)))},on(t,n){e.set(t,[...e.get(t)||[],n])},off(t,n){e.set(t,(e.get(t)||[]).filter((e=>e!==n)))}}}let s=!1,f=0;const d=()=>"floating-ui-"+f++;const v=c.useId,g=null!=v?v:function(){const e=s?d():null,[t,n]=c.useState(e);return l((()=>{null===t&&n(d())}),[]),c.useEffect((()=>{s||(s=!0)}),[]),t},p=t.createContext(null),m=t.createContext(null),y=()=>{var e,n;return null!=(e=null==(n=t.useContext(p))?void 0:n.id)?e:null},h=()=>t.useContext(m);function b(e){return Object.entries(null!=e?e:{}).reduce(((e,t)=>{let[n,r]=t;return e[n]=[r],e}),{})}function E(e,t,n){const r={reference:"reference"===n?b(e):{},floating:"floating"===n?b(e):{}};return t.forEach((e=>{var t;const o=null!=(t=null==e?void 0:e[n])?t:{};Object.keys(o).forEach((e=>{var t;"function"==typeof o[e]&&(null==r[n][e]&&(r[n][e]=[]),null==(t=r[n][e])||t.push(o[e]))}))})),{..."floating"===n&&{tabIndex:-1},...e,...t.reduce(((e,t)=>(Object.assign(e,null==t?void 0:t[n]),e)),{}),...Object.entries(r[n]).reduce(((e,t)=>{let[n,r]=t;return 0===n.indexOf("on")&&(e[n]=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];r.forEach((e=>e(...t)))}),e}),{})}}var w={exports:{}},x=function(e,t,n,r){var o=e[0],u=e[1],c=!1;void 0===n&&(n=0),void 0===r&&(r=t.length);for(var i=(r-n)/2,l=0,a=i-1;l<i;a=l++){var s=t[n+2*l+0],f=t[n+2*l+1],d=t[n+2*a+0],v=t[n+2*a+1];f>u!=v>u&&o<(d-s)*(u-f)/(v-f)+s&&(c=!c)}return c},R=function(e,t,n,r){var o=e[0],u=e[1],c=!1;void 0===n&&(n=0),void 0===r&&(r=t.length);for(var i=r-n,l=0,a=i-1;l<i;a=l++){var s=t[l+n][0],f=t[l+n][1],d=t[a+n][0],v=t[a+n][1];f>u!=v>u&&o<(d-s)*(u-f)/(v-f)+s&&(c=!c)}return c};w.exports=function(e,t,n,r){return t.length>0&&Array.isArray(t[0])?R(e,t,n,r):x(e,t,n,r)},w.exports.nested=R,w.exports.flat=x;var O=w.exports;function C(e){var t;return null!=(t=null==e?void 0:e.ownerDocument)?t:document}function k(e){var t;return null!=(t=C(e).defaultView)?t:window}function I(e){return!!e&&e instanceof k(e).Element}function T(e){return!!e&&e instanceof k(e).HTMLElement}function L(e,t){var n;let r=null!=(n=null==e?void 0:e.nodesRef.current.filter((e=>{var n;return e.parentId===t&&(null==(n=e.context)?void 0:n.open)})))?n:[],o=r;for(;o.length;){var u;o=null!=(u=null==e?void 0:e.nodesRef.current.filter((e=>{var t;return null==(t=o)?void 0:t.some((t=>{var n;return e.parentId===t.id&&(null==(n=e.context)?void 0:n.open)}))})))?u:[],r=r.concat(o)}return r}const D="floating-ui-root",P=t.createContext(D);function A(){return A=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},A.apply(this,arguments)}const j=t.forwardRef((function(e,t){let{lockScroll:n=!1,...r}=e;return l((()=>{if(!n)return;const e=window.pageXOffset,t=window.pageYOffset,r=Math.round(document.documentElement.getBoundingClientRect().left)+document.documentElement.scrollLeft?"paddingLeft":"paddingRight",o=window.innerWidth-document.documentElement.clientWidth;return Object.assign(document.body.style,{position:"fixed",overflow:"hidden",top:"-"+t+"px",left:"-"+e+"px",right:"0",[r]:o+"px"}),()=>{Object.assign(document.body.style,{position:"",overflow:"",top:"",left:"",right:"",[r]:""}),window.scrollTo(e,t)}}),[n]),i.default.createElement("div",A({ref:t},r,{style:{position:"fixed",overflow:"auto",top:0,right:0,bottom:0,left:0,...r.style}}))}));function M(e,t,n){return n&&"mouse"!==n?0:"number"==typeof e?e:null==e?void 0:e[t]}const F=t.createContext({delay:1e3,initialDelay:1e3,currentId:null,setCurrentId:()=>{},setState:()=>{}}),S=()=>t.useContext(F);function N(e){e.preventDefault(),e.stopPropagation()}function B(e){requestAnimationFrame((()=>{null==e||e.focus()}))}const q="ArrowUp",K="ArrowDown",V="ArrowLeft",_="ArrowRight";function H(e,t){let{startingIndex:n=-1,decrement:r=!1}=void 0===t?{}:t;const o=W(e);let u=n;do{var c,i;u+=r?-1:1}while(null!=(c=o[u])&&c.hasAttribute("disabled")||"true"===(null==(i=o[u])?void 0:i.getAttribute("aria-disabled")));return-1===u?0:u}function U(e,t,n){switch(e){case"vertical":return t;case"horizontal":return n;default:return t||n}}function G(e,t){return U(t,e===q||e===K,e===V||e===_)}function X(e,t,n){return U(t,e===K,n?e===V:e===_)}function Y(e){return H(e)}function z(e){return H(e,{decrement:!0,startingIndex:W(e).length})}function W(e){return e.current.filter((e=>null!=e))}e.FloatingDelayGroup=e=>{let{children:n,delay:r}=e;const[o,u]=t.useState({delay:r,initialDelay:r,currentId:null}),c=t.useCallback((e=>{u((t=>({...t,currentId:e})))}),[]);return i.default.createElement(F.Provider,{value:{...o,setState:u,setCurrentId:c}},n)},e.FloatingNode=e=>{let{children:t,id:n}=e;const r=y();return i.default.createElement(p.Provider,{value:{id:n,parentId:r}},t)},e.FloatingOverlay=j,e.FloatingPortal=e=>{let{children:n,id:o=D}=e;const[u,c]=t.useState(!1),a=t.useRef(null);return l((()=>{const e=document.getElementById(o);e?a.current=e:(a.current=document.createElement("div"),a.current.id=o);const t=a.current;document.body.contains(t)||document.body.appendChild(t),c(!0)}),[o]),u&&a.current?i.default.createElement(P.Provider,{value:o},r.createPortal(n,a.current)):null},e.FloatingTree=e=>{let{children:n}=e;const r=t.useRef([]),o=t.useCallback((e=>{r.current=[...r.current,e]}),[]),u=t.useCallback((e=>{r.current=r.current.filter((t=>t!==e))}),[]);return i.default.createElement(m.Provider,{value:{nodesRef:r,addNode:o,removeNode:u,events:a()}},n)},e.safePolygon=function(e){let t,{timeout:n=0,debug:r=null}=void 0===e?{}:e;return e=>{let{x:o,y:u,placement:c,refs:i,onClose:l,nodeId:a,tree:s}=e;return function(e){var f;if("touch"===e.pointerType)return;const{target:d,clientX:v,clientY:g}=e,p=d;if("pointermove"===e.type&&I(i.reference.current)&&i.reference.current.contains(p)||null!=(f=i.floating.current)&&f.contains(p))return;if(s&&L(s,a).some((e=>{let{context:t}=e;return null==t?void 0:t.open})))return;if(!i.reference.current||!i.floating.current||null==c||null==o||null==u)return;const m=i.reference.current.getBoundingClientRect(),y=i.floating.current.getBoundingClientRect(),h=c.split("-")[0],b=o>y.right-y.width/2,E=u>y.bottom-y.height/2;switch(h){case"top":if(v>=y.left&&v<=y.right&&g>=y.bottom&&g<=m.top)return;break;case"bottom":if(v>=y.left&&v<=y.right&&g>=m.bottom&&g<=y.top)return;break;case"left":if(v>=y.right&&v<=m.left&&g>=y.left&&g<=y.right)return;break;case"right":if(v>=y.right&&v<=m.left&&g>=y.right&&g<=m.left)return}function w(e){let[t,n]=e;const r=y.width>m.width,o=y.height>m.height;switch(h){case"top":{const e=[r?t:b?t+1:t-1,n+1],o=[r?t:b?t-1:t+1,n+1],u=[[y.left,b||r?y.bottom-1:y.top],[y.right,b?r?y.bottom-1:y.top:y.bottom-1]];return b?[e,o,...u]:[e,...u,o]}case"bottom":{const e=[r?t:b?t+1:t-1,n-1],o=[r?t:b?t-1:t+1,n-1],u=[[y.left,b||r?y.top+1:y.bottom],[y.right,b?r?y.top+1:y.bottom:y.top+1]];return b?[e,o,...u]:[e,...u,o]}case"left":{const e=[t+1,o?n:E?n-1:n+1],r=[t+1,o?n:E?n+1:n-1],u=[[E||o?y.right-1:y.left,y.top],[E?o?y.right-1:y.left:y.right-1,y.bottom]];return E?[e,...u,r]:[...u,e,r]}case"right":{const e=[t-1,o?n:E?n+1:n-1],r=[t-1,o?n:E?n-1:n+1],u=[[E||o?y.left+1:y.right,y.top],[E?o?y.left+1:y.right:y.left+1,y.bottom]];return E?[e,r,...u]:[e,...u,r]}}}const x=w([o,u]);"production"!==process.env.NODE_ENV&&(null==r||r(w([o,u]).slice(0,4).join(", "))),O([v,g],x)?n&&(t=setTimeout(l,n)):(clearTimeout(t),l())}}},e.useClick=function(e,t){let{open:n,onOpenChange:r,dataRef:o}=e,{enabled:u=!0}=void 0===t?{}:t;return u?{reference:{onClick(e){var t;n?"click"===(null==(t=o.current.openEvent)?void 0:t.type)&&r(!1):r(!0);o.current.openEvent=e.nativeEvent}}}:{}},e.useDelayGroup=(e,n)=>{let{open:r,onOpenChange:o}=e,{id:u}=n;const{currentId:c,initialDelay:i,setState:l}=S();t.useEffect((()=>{c&&o&&(l((e=>({...e,delay:{open:0,close:M(i,"close")}}))),c!==u&&o(!1))}),[u,o,l,c,i]),t.useEffect((()=>{!r&&c===u&&o&&(o(!1),l((e=>({...e,delay:i,currentId:null}))))}),[r,l,c,u,o,i])},e.useDelayGroupContext=S,e.useDismiss=function(e,r){let{open:o,onOpenChange:u,refs:c,events:i,nodeId:l}=e,{enabled:a=!0,escapeKey:s=!0,outsidePointerDown:f=!0,referencePointerDown:d=!1,ancestorScroll:v=!1}=void 0===r?{}:r;const g=h(),p=t.useCallback((()=>{T(c.reference.current)&&c.reference.current.focus()}),[c.reference.current]);return t.useEffect((()=>{if(!o||!a)return;function e(e){"Escape"===e.key&&(i.emit("dismiss"),u(!1),p())}function t(e){var t;const n=g&&L(g,l).some((t=>{var n,r;return null==(n=t.context)||null==(r=n.refs.floating.current)?void 0:r.contains(e.target)}));null!=(t=c.floating.current)&&t.contains(e.target)||I(c.reference.current)&&c.reference.current.contains(e.target)||n||(i.emit("dismiss"),u(!1),p())}function r(){u(!1)}const d=C(c.floating.current);s&&d.addEventListener("keydown",e),f&&d.addEventListener("mousedown",t);const m=(v?[...I(c.reference.current)?n.getOverflowAncestors(c.reference.current):[],...I(c.floating.current)?n.getOverflowAncestors(c.floating.current):[]]:[]).filter((e=>{var t;return e!==(null==(t=d.defaultView)?void 0:t.visualViewport)}));return m.forEach((e=>e.addEventListener("scroll",r,{passive:!0}))),()=>{s&&d.removeEventListener("keydown",e),f&&d.removeEventListener("mousedown",t),m.forEach((e=>e.removeEventListener("scroll",r)))}}),[s,f,i,g,l,o,u,p,v,a,c.floating,c.reference]),a?{reference:{onPointerDown(){d&&(i.emit("dismiss"),u(!1))}}}:{}},e.useFloating=function(e){let{open:r=!1,onOpenChange:o=(()=>{}),placement:u,middleware:c,strategy:i,nodeId:s}=void 0===e?{}:e;const f=h(),d=t.useRef({}),v=t.useState((()=>a()))[0],g=n.useFloating({placement:u,middleware:c,strategy:i}),p=t.useMemo((()=>({...g,dataRef:d,nodeId:s,events:v,open:r,onOpenChange:o})),[g,d,s,v,r,o]);return l((()=>{const e=null==f?void 0:f.nodesRef.current.find((e=>e.id===s));e&&(e.context=p)})),t.useMemo((()=>({context:p,...g})),[g,p])},e.useFloatingNodeId=()=>{const e=g(),t=h(),n=y();return l((()=>{const r={id:e,parentId:n};return null==t||t.addNode(r),()=>{null==t||t.removeNode(r)}}),[t,e,n]),e},e.useFloatingParentNodeId=y,e.useFloatingTree=h,e.useFocus=function(e,n){let{open:r,onOpenChange:o,dataRef:u,refs:c,events:i}=e,{enabled:l=!0,keyboardOnly:a=!0}=void 0===n?{}:n;const s=t.useRef(!1);return t.useEffect((()=>{var e;if(!l)return;const t=null!=(e=C(c.floating.current).defaultView)?e:window;function n(){s.current=!r}function o(){setTimeout((()=>{s.current=!1}))}return t.addEventListener("focus",o),t.addEventListener("blur",n),()=>{t.addEventListener("focus",o),t.removeEventListener("blur",n)}}),[c.floating,r,l]),t.useEffect((()=>{if(l)return i.on("dismiss",e),()=>{i.off("dismiss",e)};function e(){s.current=!0}}),[i,l]),l?{reference:{onPointerDown(e){let{pointerType:t}=e;s.current=!(!t||!a)},onFocus(e){var t,n,r;s.current||"focus"===e.type&&"mousedown"===(null==(t=u.current.openEvent)?void 0:t.type)&&I(c.reference.current)&&null!=(n=c.reference.current)&&n.contains(null==(r=u.current.openEvent)?void 0:r.target)||(u.current.openEvent=e.nativeEvent,o(!0))},onBlur(e){var t;const n=e.relatedTarget;null!=(t=c.floating.current)&&t.contains(n)||I(c.reference.current)&&c.reference.current.contains(n)||(s.current=!1,o(!1))}}}:{}},e.useFocusTrap=function(e,n){let{open:r,onOpenChange:o,refs:u,nodeId:c}=e,{enabled:i=!0,initialContentFocus:l=0,order:a=["content"],modal:s=!0,inert:f=!1}=void 0===n?{}:n;const d=t.useContext(P),v=h(),g=t.useRef(0),p=t.useCallback((()=>a.map((e=>{return T(u.reference.current)&&"reference"===e?u.reference.current:u.floating.current&&"floating"===e?u.floating.current:"content"===e?Array.from(null!=(t=null==(n=u.floating.current)?void 0:n.querySelectorAll("a[href],area[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),button:not([disabled]),iframe,object,embed,*[tabindex],*[contenteditable]"))?t:[]):null;var t,n})).filter(Boolean).flat()),[u.floating,u.reference,a]);function m(e){var t;const n=e.relatedTarget;null!=(t=u.floating.current)&&t.contains(n)||!I(u.reference.current)||u.reference.current.contains(n)||o(!1)}return t.useEffect((()=>{if(!i)return;const e=p();if(f){if(r){const t=e[0];t!==u.floating.current||t.contains(t.ownerDocument.activeElement)||B(t)}}else r?"number"==typeof l?B(e[l]):l.current&&B(e.find((e=>e===l.current))):s&&T(u.reference.current)&&B(u.reference.current)}),[p,r,f,s,l,i,u.reference,u.floating]),t.useEffect((()=>{if(!s||!i)return;const e=C(u.floating.current);if(!r)return e.removeEventListener("keydown",t),void(g.current=0);function t(e){var t;if((null==v||null==(t=v.nodesRef.current)||!t.filter((e=>{let{parentId:t}=e;return t===c})).some((e=>{let{context:t}=e;return null==t?void 0:t.open})))&&"Tab"===e.key){N(e);const t=p();if(f)return;e.shiftKey?g.current=0===g.current?t.length-1:g.current-1:g.current=g.current===t.length-1?0:g.current+1,B(t[g.current])}}return e.addEventListener("keydown",t),()=>{e.removeEventListener("keydown",t)}}),[p,null==v?void 0:v.nodesRef,c,r,s,f,i,u.floating]),t.useEffect((()=>{if(!r||!s||!i)return;const e=C(u.floating.current),t=e.querySelector("#"+d),n=e.querySelectorAll("body > *:not(#"+d+")"),o=[];return n.forEach((e=>{const t=e.getAttribute("aria-hidden");o.push(t),e.setAttribute("aria-hidden","hidden")})),()=>{(null==t?void 0:t.firstElementChild)===u.floating.current&&n.forEach(((e,t)=>{const n=o[t];null===n?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n)}))}}),[r,s,d,i,u.floating]),i?s?{floating:{"aria-modal":"true"}}:{reference:{onBlur:m},floating:{onBlur:m}}:{}},e.useHover=function(e,n){let{enabled:r=!0,delay:o=0,handleClose:u=null,mouseOnly:c=!1,restMs:i=0}=void 0===n?{}:n;const{open:a,onOpenChange:s,dataRef:f,events:d,refs:v}=e,g=h(),p=t.useRef(),m=t.useRef(),y=t.useRef(),b=t.useRef(),E=t.useRef(!0);l((()=>{a||(p.current=void 0)})),t.useEffect((()=>{function e(){clearTimeout(m.current),clearTimeout(b.current),E.current=!0}return d.on("dismiss",e),()=>{d.off("dismiss",e)}}),[d]),t.useEffect((()=>{if(!r||!u)return;function e(){var e;null!=(e=f.current.openEvent)&&e.type.includes("mouse")&&s(!1)}const t=C(v.floating.current).documentElement;return t.addEventListener("mouseleave",e),()=>{t.removeEventListener("mouseleave",e)}}),[v.floating,s,r,u,f]);const w=t.useCallback((function(e){void 0===e&&(e=!0),o?(clearTimeout(m.current),m.current=setTimeout((()=>s(!1)),M(o,"close",p.current))):e&&s(!1)}),[o,s]);function x(e){p.current=e.pointerType}return t.useEffect((()=>{function t(e){a||c&&"mouse"!==p.current||(E.current=!1,f.current.openEvent=e,o?(clearTimeout(m.current),m.current=setTimeout((()=>{s(!0)}),M(o,"open",p.current))):s(!0))}function n(t){var n;if("click"===(null==(n=f.current.openEvent)?void 0:n.type))return;const r=C(v.floating.current);if(clearTimeout(b.current),u)return clearTimeout(m.current),y.current&&r.removeEventListener("pointermove",y.current),y.current=u({...e,tree:g,x:t.clientX,y:t.clientY,onClose(){y.current&&r.removeEventListener("pointermove",y.current),w()}}),void r.addEventListener("pointermove",y.current);w()}const r=v.reference.current;if(I(r))return r.addEventListener("mouseenter",t),r.addEventListener("mouseleave",n),()=>{r.removeEventListener("mouseenter",t),r.removeEventListener("mouseleave",n)}}),[w,e,o,u,f,c,s,a,g,v.reference,v.floating]),r?{reference:{onPointerDown:x,onPointerEnter:x,onMouseMove(){a||0===i||(clearTimeout(b.current),b.current=setTimeout((()=>{E.current||s(!0)}),i))}},floating:{onMouseEnter(){clearTimeout(m.current)},onMouseLeave:()=>w(!1)}}:{}},e.useId=g,e.useInteractions=function(e){return void 0===e&&(e=[]),{getReferenceProps:t=>E(t,e,"reference"),getFloatingProps:t=>E(t,e,"floating")}},e.useListNavigation=function(e,n){let{open:r,onOpenChange:o,refs:u}=e,{listRef:c,activeIndex:i,onNavigate:a,enabled:s=!0,selectedIndex:f=null,loop:d=!1,nested:v=!1,rtl:g=!1,virtual:p=!1,focusItemOnOpen:m="auto",orientation:y="vertical"}=void 0===n?{listRef:{current:[]},activeIndex:null,onNavigate:()=>{}}:n;const h=t.useRef(m),b=t.useRef(null!=f?f:-1),E=t.useRef(""),[w,x]=t.useState(),R=t.useCallback(((e,t)=>{var n,r;p?x(null==(n=W(e)[t.current])?void 0:n.id):null==(r=W(e)[t.current])||r.focus({preventScroll:!0})}),[p]);function O(e){"auto"===m&&(h.current=!e.pointerType)}if(l((()=>{s&&(null!=f&&(b.current=f),r&&h.current&&(a(b.current),R(c,b)))}),[r,f,c,a,R,s]),l((()=>{s&&r&&null!=i&&(b.current=i,a(b.current),R(c,b))}),[r,i,c,a,R,s]),l((()=>{null==f&&s&&(r&&(G(E.current,y)||h.current&&(" "===E.current||"Enter"===E.current))&&(b.current=function(e,t,n){return U(t,e===q,n?e===_:e===V)}(E.current,y,g)?z(c):Y(c),a(b.current),R(c,b)),E.current="")}),[r,c,f,a,R,s,y,g]),l((()=>{var e;s&&(r||null==f||null==(e=u.reference.current)||e.focus({preventScroll:!0}))}),[u.reference,f,r,s]),l((()=>{var e;s&&(r||("auto"===m&&(h.current=!0),b.current=null!=(e=null!=f?f:i)?e:-1,a(null)))}),[r,f,i,s,m]),!s)return{};function C(e){if(v&&function(e,t,n){return U(t,n?e===_:e===V,e===q)}(e.key,y,g))return N(e),o(!1),void(T(u.reference.current)&&u.reference.current.focus());const t=b.current,n=Y(c),r=z(c);if("Home"===e.key&&(b.current=n,a(b.current),R(c,b)),"End"===e.key&&(b.current=r,a(b.current),R(c,b)),G(e.key,y)){if(N(e),!p&&e.currentTarget.ownerDocument.activeElement===e.currentTarget)return b.current=null!=f?f:X(e.key,y,g)?n:r,a(b.current),void R(c,b);X(e.key,y,g)?b.current=d?t===r?n:H(c,{startingIndex:t}):Math.min(r,H(c,{startingIndex:t})):b.current=d?t===n?r:H(c,{startingIndex:t,decrement:!0}):Math.max(n,H(c,{startingIndex:t,decrement:!0})),a(b.current),R(c,b)}}return{reference:{...p&&{"aria-activedescendant":w},onPointerEnter:O,onPointerDown:O,onKeyDown(e){if(p&&r)return C(e);"auto"===m&&(h.current=!0),E.current=e.key,v?function(e,t,n){return U(t,n?e===V:e===_,e===K)}(e.key,y,g)&&(b.current=Y(c),N(e),o(!0),a(b.current)):(G(e.key,y)&&(b.current=null==f?X(e.key,y,g)?Y(c):z(c):f,N(e),o(!0),a(b.current)),p&&!r&&C(e))}},floating:{"aria-orientation":"both"===y?void 0:y,...p&&{"aria-activedescendant":w},onKeyDown:C}}},e.useRole=function(e,t){let{open:n}=e,{enabled:r=!0,role:o="dialog"}=void 0===t?{}:t;const u=g(),c={id:u,role:o};return r?"tooltip"===o?{reference:{"aria-describedby":n?u:void 0},floating:c}:{reference:{"aria-expanded":n?"true":"false","aria-haspopup":o,"aria-controls":n?u:void 0,..."listbox"===o&&{role:"combobox"}},floating:c}:{}},e.useTypeahead=function(e,n){var r;let{open:o,dataRef:u}=e,{listRef:c,activeIndex:i,onMatch:a=(()=>{}),enabled:s=!0,findMatch:f=null,resetMs:d=500,ignoreKeys:v=[],selectedIndex:g=null}=void 0===n?{listRef:{current:[]},activeIndex:null}:n;const p=t.useRef(),m=t.useRef(""),y=t.useRef(null!=(r=null!=g?g:i)?r:-1),h=t.useRef(null);function b(e){if(!e.currentTarget.contains(C(e.currentTarget).activeElement))return;m.current.length>0&&(u.current.typing=!0," "===e.key&&N(e));const t=c.current;if(null==t||["Home","End","Escape","Enter","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight",...v].includes(e.key))return;t.every((e=>{var t,n;return!e||(null==(t=e[0])?void 0:t.toLowerCase())!==(null==(n=e[1])?void 0:n.toLowerCase())}))&&m.current===e.key&&(m.current="",y.current=h.current),m.current+=e.key,clearTimeout(p.current),p.current=setTimeout((()=>{m.current="",y.current=h.current,u.current.typing=!1}),d);const n=y.current,r=[...t.slice((null!=n?n:0)+1),...t.slice(0,(null!=n?n:0)+1)],o=f?f(r,m.current):r.find((e=>0===(null==e?void 0:e.toLowerCase().indexOf(m.current)))),i=o?t.indexOf(o):-1;-1!==i&&(a(i),h.current=i)}return l((()=>{o&&(clearTimeout(p.current),h.current=null,m.current="")}),[o]),l((()=>{var e;o&&""===m.current&&(y.current=null!=(e=null!=g?g:i)?e:-1)}),[o,g,i]),s?{reference:{onKeyDown:b},floating:{onKeyDown:b}}:{}},Object.keys(n).forEach((function(t){"default"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@floating-ui/react-dom-interactions", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"@rollingversions": { | ||
@@ -24,3 +24,4 @@ "baseVersion": [ | ||
}, | ||
"./package.json": "./package.json" | ||
"./package.json": "./package.json", | ||
"./src/index.ts": "./src/index.ts" | ||
}, | ||
@@ -36,4 +37,3 @@ "sideEffects": false, | ||
"test": "jest test", | ||
"build": "NODE_ENV=build rollup -c", | ||
"dev": "parcel test/visual/index.html --dist-dir test/visual/dist" | ||
"build": "NODE_ENV=build rollup -c" | ||
}, | ||
@@ -48,3 +48,3 @@ "author": "atomiks", | ||
}, | ||
"homepage": "https://floating-ui.com/docs/floating-interactions", | ||
"homepage": "https://floating-ui.com/docs/react-dom-interactions", | ||
"keywords": [ | ||
@@ -60,10 +60,6 @@ "tooltip", | ||
], | ||
"peerDependencies": { | ||
"react": ">=16.8.0", | ||
"react-dom": ">=16.8.0" | ||
}, | ||
"dependencies": { | ||
"@floating-ui/react-dom": "^0.3.4", | ||
"point-in-polygon": "^1.1.0", | ||
"use-isomorphic-layout-effect": "^1.1.1", | ||
"@floating-ui/react-dom": "^0.6.0" | ||
"use-isomorphic-layout-effect": "^1.1.1" | ||
}, | ||
@@ -86,5 +82,2 @@ "devDependencies": { | ||
"jest": "^27.3.1", | ||
"parcel": "^2.0.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-merge-refs": "^1.1.0", | ||
@@ -91,0 +84,0 @@ "rollup": "^2.60.1", |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
/** | ||
@@ -8,2 +8,4 @@ * Provides base styling for a fixed overlay element to dim content or block | ||
*/ | ||
export declare const FloatingOverlay: import("react").ForwardRefExoticComponent<Pick<React.HTMLProps<HTMLDivElement>, string | number | symbol> & import("react").RefAttributes<HTMLDivElement>>; | ||
export declare const FloatingOverlay: React.ForwardRefExoticComponent<Pick<React.HTMLProps<HTMLDivElement> & { | ||
lockScroll?: boolean; | ||
}, "start" | "name" | "data" | "width" | "height" | "size" | "open" | "className" | "id" | "prefix" | "slot" | "children" | "value" | "cite" | "form" | "label" | "span" | "style" | "summary" | "title" | "pattern" | "key" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "as" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "classID" | "cols" | "colSpan" | "content" | "controls" | "coords" | "crossOrigin" | "dateTime" | "default" | "defer" | "disabled" | "download" | "encType" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "list" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "nonce" | "noValidate" | "optimum" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "selected" | "shape" | "sizes" | "src" | "srcDoc" | "srcLang" | "srcSet" | "step" | "target" | "type" | "useMap" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "lang" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "lockScroll"> & React.RefAttributes<HTMLDivElement>>; |
@@ -9,3 +9,2 @@ import { MutableRefObject } from 'react'; | ||
inert?: boolean; | ||
scrollLock?: boolean; | ||
} | ||
@@ -17,2 +16,2 @@ /** | ||
*/ | ||
export declare const useFocusTrap: ({ open, onOpenChange, refs, nodeId }: FloatingContext, { enabled, initialContentFocus, order, modal, inert, scrollLock, }?: Props) => ElementProps; | ||
export declare const useFocusTrap: ({ open, onOpenChange, refs, nodeId }: FloatingContext, { enabled, initialContentFocus, order, modal, inert, }?: Props) => ElementProps; |
import type { ElementProps, FloatingContext, FloatingTreeType } from '../types'; | ||
export declare function getDelay(value: Props['delay'], prop: 'open' | 'close'): number; | ||
export declare function getDelay(value: Props['delay'], prop: 'open' | 'close', pointerType?: PointerEvent['pointerType']): number; | ||
export interface Props { | ||
enabled?: boolean; | ||
handleLeave?: null | ((context: FloatingContext & { | ||
handleClose?: null | ((context: FloatingContext & { | ||
onClose: () => void; | ||
tree?: FloatingTreeType | null; | ||
}) => (event: PointerEvent) => void); | ||
pointerRestMs?: number; | ||
restMs?: number; | ||
delay?: number | Partial<{ | ||
@@ -20,2 +20,2 @@ open: number; | ||
*/ | ||
export declare const useHover: (context: FloatingContext, { enabled, delay, handleLeave, mouseOnly, pointerRestMs, }?: Props) => ElementProps; | ||
export declare const useHover: (context: FloatingContext, { enabled, delay, handleClose, mouseOnly, restMs, }?: Props) => ElementProps; |
@@ -13,2 +13,3 @@ import React from 'react'; | ||
rtl?: boolean; | ||
virtual?: boolean; | ||
orientation?: 'vertical' | 'horizontal' | 'both'; | ||
@@ -21,2 +22,2 @@ } | ||
*/ | ||
export declare const useListNavigation: ({ open, onOpenChange, refs }: FloatingContext, { listRef, activeIndex, onNavigate, enabled, selectedIndex, loop, nested, rtl, focusItemOnOpen, orientation, }?: Props) => ElementProps; | ||
export declare const useListNavigation: ({ open, onOpenChange, refs }: FloatingContext, { listRef, activeIndex, onNavigate, enabled, selectedIndex, loop, nested, rtl, virtual, focusItemOnOpen, orientation, }?: Props) => ElementProps; |
@@ -8,4 +8,4 @@ import React from 'react'; | ||
enabled?: boolean; | ||
onFind?: null | ((itemString: string | null, typedString: string) => boolean); | ||
debounceMs?: number; | ||
findMatch?: null | ((list: Array<string | null>, typedString: string) => string | null | undefined); | ||
resetMs?: number; | ||
ignoreKeys?: Array<string>; | ||
@@ -19,2 +19,2 @@ selectedIndex?: number | null; | ||
*/ | ||
export declare const useTypeahead: ({ open }: FloatingContext, { listRef, activeIndex, onMatch, enabled, onFind, debounceMs, ignoreKeys, selectedIndex, }?: Props) => ElementProps; | ||
export declare const useTypeahead: ({ open, dataRef }: FloatingContext, { listRef, activeIndex, onMatch, enabled, findMatch, resetMs, ignoreKeys, selectedIndex, }?: Props) => ElementProps; |
@@ -1,3 +0,17 @@ | ||
import { UseFloatingReturn } from '@floating-ui/react-dom'; | ||
import { MutableRefObject } from 'react'; | ||
import { ComputePositionReturn, VirtualElement } from '@floating-ui/react-dom'; | ||
import type { FloatingContext, Middleware, Placement, Strategy } from './types'; | ||
declare type Data = Omit<ComputePositionReturn, 'x' | 'y'> & { | ||
x: number | null; | ||
y: number | null; | ||
}; | ||
export declare type UseFloatingReturn = Data & { | ||
update: () => void; | ||
reference: (node: Element | VirtualElement | null) => void; | ||
floating: (node: HTMLElement | null) => void; | ||
refs: { | ||
reference: MutableRefObject<Element | VirtualElement | null>; | ||
floating: MutableRefObject<HTMLElement | null>; | ||
}; | ||
}; | ||
export interface Props { | ||
@@ -24,3 +38,3 @@ open: boolean; | ||
export { useDismiss } from './hooks/useDismiss'; | ||
export { useFloatingId } from './hooks/useFloatingId'; | ||
export { useId } from './hooks/useId'; | ||
export { useFocus } from './hooks/useFocus'; | ||
@@ -27,0 +41,0 @@ export { useFocusTrap } from './hooks/useFocusTrap'; |
@@ -1,3 +0,3 @@ | ||
import type { UseFloatingReturn } from '@floating-ui/react-dom'; | ||
import React from 'react'; | ||
import type { UseFloatingReturn } from './'; | ||
export * from './'; | ||
@@ -11,2 +11,7 @@ export * from '@floating-ui/dom'; | ||
} | ||
export interface ContextData { | ||
openEvent?: MouseEvent | PointerEvent | FocusEvent; | ||
typing?: boolean; | ||
[key: string]: any; | ||
} | ||
export interface FloatingContext extends UseFloatingReturn { | ||
@@ -16,3 +21,3 @@ open: boolean; | ||
events: FloatingEvents; | ||
dataRef: React.MutableRefObject<Record<string, any>>; | ||
dataRef: React.MutableRefObject<ContextData>; | ||
nodeId: string | undefined; | ||
@@ -19,0 +24,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import React from 'react'; | ||
import type { ElementProps } from './types'; | ||
@@ -2,0 +3,0 @@ export declare const useInteractions: (propsList?: Array<ElementProps | void>) => { |
import type { FloatingTreeType } from '../types'; | ||
export declare function getChildren(tree: FloatingTreeType, id: string | undefined): any; | ||
export declare function getChildren(tree: FloatingTreeType, id: string | undefined): import("../types").FloatingNodeType[]; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
220669
3
20
32
5113
2
+ Added@floating-ui/core@0.3.1(transitive)
+ Added@floating-ui/dom@0.1.10(transitive)
+ Added@floating-ui/react-dom@0.3.4(transitive)
- Removed@floating-ui/core@0.6.2(transitive)
- Removed@floating-ui/dom@0.4.5(transitive)
- Removed@floating-ui/react-dom@0.6.3(transitive)