1import { o as __toESM } from "./chunk-6z4oVpB-.js"; 2import { t as require_react } from "./react-CCT1erMQ.js"; 3import { t as require_jsx_runtime } from "./jsx-runtime-6ToSbptA.js"; 4import { n as _objectSpread2, r as init_objectSpread2, t as _objectWithoutProperties } from "./objectWithoutProperties-Cgp7QKOy.js"; 5import { o as composeEventHandlers, r as useLayoutEffect2, t as useCallbackRef } from "./dist-Cz4mcmaa.js"; 6import { n as useComposedRefs } from "./dist-DaeMORX8.js"; 7import { t as require_react_dom } from "./react-dom-Dddidh9b.js"; 8import { n as dispatchDiscreteCustomEvent, t as Primitive } from "./dist-DetJSI7l.js"; 9var import_react = /* @__PURE__ */ __toESM(require_react(), 1); 10function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = (() => { 11 var _globalThis; 12 return (_globalThis = globalThis) === null || _globalThis === void 0 ? void 0 : _globalThis.document; 13})()) { 14 const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp); 15 import_react.useEffect(() => { 16 const handleKeyDown = (event) => { 17 if (event.key === "Escape") onEscapeKeyDown(event); 18 }; 19 ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true }); 20 return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true }); 21 }, [onEscapeKeyDown, ownerDocument]); 22} 23var import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1); 24init_objectSpread2(); 25var _excluded$1 = [ 26 "disableOutsidePointerEvents", 27 "onEscapeKeyDown", 28 "onPointerDownOutside", 29 "onFocusOutside", 30 "onInteractOutside", 31 "onDismiss" 32]; 33var DISMISSABLE_LAYER_NAME = "DismissableLayer"; 34var CONTEXT_UPDATE = "dismissableLayer.update"; 35var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside"; 36var FOCUS_OUTSIDE = "dismissableLayer.focusOutside"; 37var originalBodyPointerEvents; 38var DismissableLayerContext = import_react.createContext({ 39 layers: /* @__PURE__ */ new Set(), 40 layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(), 41 branches: /* @__PURE__ */ new Set() 42}); 43var DismissableLayer = import_react.forwardRef((props, forwardedRef) => { 44 var _node$ownerDocument, _globalThis; 45 const { disableOutsidePointerEvents = false, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, onDismiss } = props, layerProps = _objectWithoutProperties(props, _excluded$1); 46 const context = import_react.useContext(DismissableLayerContext); 47 const [node, setNode] = import_react.useState(null); 48 const ownerDocument = (_node$ownerDocument = node === null || node === void 0 ? void 0 : node.ownerDocument) !== null && _node$ownerDocument !== void 0 ? _node$ownerDocument : (_globalThis = globalThis) === null || _globalThis === void 0 ? void 0 : _globalThis.document; 49 const [, force] = import_react.useState({}); 50 const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2)); 51 const layers = Array.from(context.layers); 52 const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); 53 const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); 54 const index = node ? layers.indexOf(node) : -1; 55 const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0; 56 const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex; 57 const pointerDownOutside = usePointerDownOutside((event) => { 58 const target = event.target; 59 const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target)); 60 if (!isPointerEventsEnabled || isPointerDownOnBranch) return; 61 onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event); 62 onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event); 63 if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss(); 64 }, ownerDocument); 65 const focusOutside = useFocusOutside((event) => { 66 const target = event.target; 67 if ([...context.branches].some((branch) => branch.contains(target))) return; 68 onFocusOutside === null || onFocusOutside === void 0 || onFocusOutside(event); 69 onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event); 70 if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss(); 71 }, ownerDocument);
72 useEscapeKeydown((event) => { 73 if (!(index === context.layers.size - 1)) return; 74 onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event); 75 if (!event.defaultPrevented && onDismiss) { 76 event.preventDefault(); 77 onDismiss(); 78 } 79 }, ownerDocument); 80 import_react.useEffect(() => { 81 if (!node) return; 82 if (disableOutsidePointerEvents) { 83 if (context.layersWithOutsidePointerEventsDisabled.size === 0) { 84 originalBodyPointerEvents = ownerDocument.body.style.pointerEvents; 85 ownerDocument.body.style.pointerEvents = "none"; 86 } 87 context.layersWithOutsidePointerEventsDisabled.add(node); 88 } 89 context.layers.add(node); 90 dispatchUpdate(); 91 return () => { 92 if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) ownerDocument.body.style.pointerEvents = originalBodyPointerEvents; 93 }; 94 }, [ 95 node, 96 ownerDocument, 97 disableOutsidePointerEvents, 98 context 99 ]); 100 import_react.useEffect(() => { 101 return () => { 102 if (!node) return; 103 context.layers.delete(node); 104 context.layersWithOutsidePointerEventsDisabled.delete(node); 105 dispatchUpdate(); 106 }; 107 }, [node, context]); 108 import_react.useEffect(() => { 109 const handleUpdate = () => force({}); 110 document.addEventListener(CONTEXT_UPDATE, handleUpdate); 111 return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate); 112 }, []); 113 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, _objectSpread2(_objectSpread2({}, layerProps), {}, { 114 ref: composedRefs, 115 style: _objectSpread2({ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0 }, props.style), 116 onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture), 117 onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture), 118 onPointerDownCapture: composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture) 119 })); 120});
121DismissableLayer.displayName = DISMISSABLE_LAYER_NAME; 122var BRANCH_NAME = "DismissableLayerBranch"; 123var DismissableLayerBranch = import_react.forwardRef((props, forwardedRef) => { 124 const context = import_react.useContext(DismissableLayerContext); 125 const ref = import_react.useRef(null); 126 const composedRefs = useComposedRefs(forwardedRef, ref); 127 import_react.useEffect(() => { 128 const node = ref.current; 129 if (node) { 130 context.branches.add(node); 131 return () => { 132 context.branches.delete(node); 133 }; 134 } 135 }, [context.branches]); 136 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, _objectSpread2(_objectSpread2({}, props), {}, { ref: composedRefs })); 137}); 138DismissableLayerBranch.displayName = BRANCH_NAME; 139function usePointerDownOutside(onPointerDownOutside, ownerDocument = (() => { 140 var _globalThis2; 141 return (_globalThis2 = globalThis) === null || _globalThis2 === void 0 ? void 0 : _globalThis2.document; 142})()) { 143 const handlePointerDownOutside = useCallbackRef(onPointerDownOutside); 144 const isPointerInsideReactTreeRef = import_react.useRef(false); 145 const handleClickRef = import_react.useRef(() => {}); 146 import_react.useEffect(() => { 147 const handlePointerDown = (event) => { 148 if (event.target && !isPointerInsideReactTreeRef.current) { 149 let handleAndDispatchPointerDownOutsideEvent2 = function() { 150 handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, { discrete: true }); 151 }; 152 const eventDetail = { originalEvent: event }; 153 if (event.pointerType === "touch") { 154 ownerDocument.removeEventListener("click", handleClickRef.current); 155 handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2; 156 ownerDocument.addEventListener("click", handleClickRef.current, { once: true }); 157 } else handleAndDispatchPointerDownOutsideEvent2(); 158 } else ownerDocument.removeEventListener("click", handleClickRef.current); 159 isPointerInsideReactTreeRef.current = false; 160 }; 161 const timerId = window.setTimeout(() => { 162 ownerDocument.addEventListener("pointerdown", handlePointerDown); 163 }, 0); 164 return () => { 165 window.clearTimeout(timerId); 166 ownerDocument.removeEventListener("pointerdown", handlePointerDown); 167 ownerDocument.removeEventListener("click", handleClickRef.current); 168 }; 169 }, [ownerDocument, handlePointerDownOutside]); 170 return { onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true }; 171} 172function useFocusOutside(onFocusOutside, ownerDocument = (() => { 173 var _globalThis3; 174 return (_globalThis3 = globalThis) === null || _globalThis3 === void 0 ? void 0 : _globalThis3.document; 175})()) { 176 const handleFocusOutside = useCallbackRef(onFocusOutside); 177 const isFocusInsideReactTreeRef = import_react.useRef(false); 178 import_react.useEffect(() => { 179 const handleFocus = (event) => { 180 if (event.target && !isFocusInsideReactTreeRef.current) handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, { originalEvent: event }, { discrete: false }); 181 }; 182 ownerDocument.addEventListener("focusin", handleFocus); 183 return () => ownerDocument.removeEventListener("focusin", handleFocus); 184 }, [ownerDocument, handleFocusOutside]); 185 return { 186 onFocusCapture: () => isFocusInsideReactTreeRef.current = true, 187 onBlurCapture: () => isFocusInsideReactTreeRef.current = false 188 }; 189} 190function dispatchUpdate() { 191 const event = new CustomEvent(CONTEXT_UPDATE); 192 document.dispatchEvent(event); 193} 194function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) { 195 const target = detail.originalEvent.target; 196 const event = new CustomEvent(name, { 197 bubbles: false, 198 cancelable: true, 199 detail 200 }); 201 if (handler) target.addEventListener(name, handler, { once: true }); 202 if (discrete) dispatchDiscreteCustomEvent(target, event); 203 else target.dispatchEvent(event); 204} 205var Root = DismissableLayer; 206var Branch = DismissableLayerBranch; 207var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom(), 1); 208init_objectSpread2(); 209var _excluded = ["container"]; 210var PORTAL_NAME = "Portal"; 211var Portal = import_react.forwardRef((props, forwardedRef) => { 212 var _globalThis; 213 const { container: containerProp } = props, portalProps = _objectWithoutProperties(props, _excluded); 214 const [mounted, setMounted] = import_react.useState(false); 215 useLayoutEffect2(() => setMounted(true), []); 216 const container = containerProp || mounted && ((_globalThis = globalThis) === null || _globalThis === void 0 || (_globalThis = _globalThis.document) === null || _globalThis === void 0 ? void 0 : _globalThis.body); 217 return container ? import_react_dom.createPortal(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.div, _objectSpread2
217(_objectSpread2({}, portalProps), {}, { ref: forwardedRef })), container) : null; 218}); 219Portal.displayName = PORTAL_NAME; 220export { Root as i, Branch as n, DismissableLayer as r, Portal as t }; 221 222//# sourceMappingURL=dist-DjKy_3Dj.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.