@radix-ui/react-dismissable-layer 1.0.6-rc.6 → 1.1.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1,7 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;A;;;;;;;ACSA;;oGAEA,CAEA,MAAMW,4CAAsB,GAAG,kBAA/B,AAAA;AACA,MAAMC,oCAAc,GAAG,yBAAvB,AAAA;AACA,MAAMC,0CAAoB,GAAG,qCAA7B,AAAA;AACA,MAAMC,mCAAa,GAAG,+BAAtB,AAAA;AAEA,IAAIC,+CAAJ,AAAA;AAEA,MAAMC,6CAAuB,GAAA,aAAGZ,CAAAA,0BAAA,CAAoB;IAClDc,MAAM,EAAE,IAAIC,GAAJ,EAD0C;IAElDC,sCAAsC,EAAE,IAAID,GAAJ,EAFU;IAGlDE,QAAQ,EAAE,IAAIF,GAAJ,EAAVE;CAH8B,CAAhC,AAAoD;AA0CpD,MAAMrB,yCAAgB,GAAA,aAAGI,CAAAA,uBAAA,CACvB,CAACmB,KAAD,EAAQC,YAAR,GAAyB;IAAA,IAAA,mBAAA,AAAA;IACvB,MAAM,+BACJC,2BAA2B,GAAG,KAD1B,G,iBAEJC,eAFI,CAAA,E,sBAGJC,oBAHI,CAAA,E,gBAIJC,cAJI,CAAA,E,mBAKJC,iBALI,CAAA,E,WAMJC,SANI,CAAA,EAOJ,GAAGC,UAAH,EAPI,GAQFR,KARJ,AAAM;IASN,MAAMS,OAAO,GAAG5B,uBAAA,CAAiBY,6CAAjB,CAAhB,AAAA;IACA,MAAM,CAACkB,KAAD,EAAOC,OAAP,CAAA,GAAkB/B,qBAAA,CAA+C,IAA/C,CAAxB,AAAA;IACA,MAAMiC,aAAa,GAAA,AAAA,CAAA,mBAAA,GAAGH,KAAH,KAAA,IAAA,IAAGA,KAAH,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAGA,KAAI,CAAEG,aA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F,EAWG;QAAChE,aAAD;QAAgB8D,kBAAhB;KAXH,CAWC,CAAA;IAED,OAAO;QACLtB,cAAc,EAAE,IAAOuB,yBAAyB,CAACjB,OAA1B,GAAoC,IADtD;QAAA;QAELL,aAAa,EAAE,IAAOsB,yBAAyB,CAACjB,OAA1B,GAAoC,KAA1DL;KAFF,CAAO;CAIR;AAED,SAASP,oCAAT,GAA0B;IACxB,MAAMjB,KAAK,GAAG,IAAIgD,WAAJ,CAAgB1F,oCAAhB,CAAd,AAAA;IACA2B,QAAQ,CAACgE,aAAT,CAAuBjD,KAAvB,CAAAf,CAAAA;CACD;AAED,SAASoD,kDAAT,CACEa,IADF,EAEEC,OAFF,EAGEC,MAHF,EAIE,E,UAAEd,QAAAA,CAAAA,EAJJ,EAKE;IACA,MAAMrC,MAAM,GAAGmD,MAAM,CAACjB,aAAP,CAAqBlC,MAApC,AAAA;IACA,MAAMD,KAAK,GAAG,IAAIgD,WAAJ,CAAgBE,IAAhB,EAAsB;QAAEG,OAAO,EAAE,KAAX;QAAkBC,UAAU,EAAE,IAA9B;Q,QAAoCF,MAAAA;KAA1D,CAAd,AAAoC;IACpC,IAAID,OAAJ,EAAalD,MAAM,CAACmB,gBAAP,CAAwB8B,IAAxB,EAA8BC,OAA9B,EAAwD;QAAEX,IAAI,EAAE,IAANA;KAA1D,CAAwD,CAAA;IAErE,IAAIF,QAAJ,EACErF,wDAA2B,CAACgD,MAAD,EAASD,KAAT,CAA3B,CAAA/C;SAEAgD,MAAM,CAACgD,aAAP,CAAqBjD,KAArB,CAAAC,CAAAA;CAEH;AAED,MAAMrD,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAM,GAAGF,yCAAf,AAAA;;ADhWA","sources":["packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["export {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n} from './DismissableLayer';\nexport type { DismissableLayerProps } from './DismissableLayer';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\n\nconst DISMISSABLE_LAYER_NAME = 'DismissableLayer';\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n layers: new Set<DismissableLayerElement>(),\n layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n branches: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n /**\n * When `true`, hover/focus/click interactions will be disabled on elements outside\n * the `DismissableLayer`. Users will need to click twice on outside elements to\n * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n */\n disableOutsidePointerEvents?: boolean;\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n /**\n * Event handler called when the focus moves outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onFocusOutside?: (event: FocusOutsideEvent) => void;\n /**\n * Event handler called when an interaction happens outside the `DismissableLayer`.\n * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n * Can be prevented.\n */\n onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n /**\n * Handler called when the `DismissableLayer` should be dismissed\n */\n onDismiss?: () => void;\n}\n\nconst DismissableLayer = React.forwardRef<DismissableLayerElement, DismissableLayerProps>(\n (props, forwardedRef) => {\n const {\n disableOutsidePointerEvents = false,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n onDismiss,\n ...layerProps\n } = props;\n const context = React.useContext(DismissableLayerContext);\n const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n const [, force] = React.useState({});\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node));\n const layers = Array.from(context.layers);\n const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore\n const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore\n const index = node ? layers.indexOf(node) : -1;\n const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n\n const pointerDownOutside = usePointerDownOutside((event) => {\n const target = event.target as HTMLElement;\n const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));\n if (!isPointerEventsEnabled || isPointerDownOnBranch) return;\n onPointerDownOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n const focusOutside = useFocusOutside((event) => {\n const target = event.target as HTMLElement;\n const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n if (isFocusInBranch) return;\n onFocusOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n useEscapeKeydown((event) => {\n const isHighestLayer = index === context.layers.size - 1;\n if (!isHighestLayer) return;\n onEscapeKeyDown?.(event);\n if (!event.defaultPrevented && onDismiss) {\n event.preventDefault();\n onDismiss();\n }\n }, ownerDocument);\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n ownerDocument.body.style.pointerEvents = 'none';\n }\n context.layersWithOutsidePointerEventsDisabled.add(node);\n }\n context.layers.add(node);\n dispatchUpdate();\n return () => {\n if (\n disableOutsidePointerEvents &&\n context.layersWithOutsidePointerEventsDisabled.size === 1\n ) {\n ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n /**\n * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n * and add it to the end again so the layering order wouldn't be _creation order_.\n * We only want them to be removed from context stacks when unmounted.\n */\n React.useEffect(() => {\n return () => {\n if (!node) return;\n context.layers.delete(node);\n context.layersWithOutsidePointerEventsDisabled.delete(node);\n dispatchUpdate();\n };\n }, [node, context]);\n\n React.useEffect(() => {\n const handleUpdate = () => force({});\n document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n }, []);\n\n return (\n <Primitive.div\n {...layerProps}\n ref={composedRefs}\n style={{\n pointerEvents: isBodyPointerEventsDisabled\n ? isPointerEventsEnabled\n ? 'auto'\n : 'none'\n : undefined,\n ...props.style,\n }}\n onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n onPointerDownCapture={composeEventHandlers(\n props.onPointerDownCapture,\n pointerDownOutside.onPointerDownCapture\n )}\n />\n );\n }\n);\n\nDismissableLayer.displayName = DISMISSABLE_LAYER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\nconst BRANCH_NAME = 'DismissableLayerBranch';\n\ntype DismissableLayerBranchElement = React.ElementRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = React.forwardRef<\n DismissableLayerBranchElement,\n DismissableLayerBranchProps\n>((props, forwardedRef) => {\n const context = React.useContext(DismissableLayerContext);\n const ref = React.useRef<DismissableLayerBranchElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n const node = ref.current;\n if (node) {\n context.branches.add(node);\n return () => {\n context.branches.delete(node);\n };\n }\n }, [context.branches]);\n\n return <Primitive.div {...props} ref={composedRefs} />;\n});\n\nDismissableLayerBranch.displayName = BRANCH_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`\n * to mimic layer dismissing behaviour present in OS.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n const handleClickRef = React.useRef(() => {});\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n\n function handleAndDispatchPointerDownOutsideEvent() {\n handleAndDispatchCustomEvent(\n POINTER_DOWN_OUTSIDE,\n handlePointerDownOutside,\n eventDetail,\n { discrete: true }\n );\n }\n\n /**\n * On touch devices, we need to wait for a click event because browsers implement\n * a ~350ms delay between the time the user stops touching the display and when the\n * browser executres events. We need to ensure we don't reactivate pointer-events within\n * this timeframe otherwise the browser may execute events that should have been prevented.\n *\n * Additionally, this also lets us deal automatically with cancellations when a click event\n * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.\n *\n * This is why we also continuously remove the previous listener, because we cannot be\n * certain that it was raised, and therefore cleaned-up.\n */\n if (event.pointerType === 'touch') {\n ownerDocument.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\n } else {\n // We need to remove the event listener in case the outside click has been canceled.\n // See: https://github.com/radix-ui/primitives/issues/2171\n ownerDocument.removeEventListener('click', handleClickRef.current);\n }\n isPointerInsideReactTreeRef.current = false;\n };\n /**\n * if this hook executes in a component that mounts via a `pointerdown` event, the event\n * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n * this by delaying the event listener registration on the document.\n * This is not React specific, but rather how the DOM works, ie:\n * ```\n * button.addEventListener('pointerdown', () => {\n * console.log('I will log');\n * document.addEventListener('pointerdown', () => {\n * console.log('I will also log');\n * })\n * });\n */\n const timerId = window.setTimeout(() => {\n ownerDocument.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n ownerDocument.removeEventListener('click', handleClickRef.current);\n };\n }, [ownerDocument, handlePointerDownOutside]);\n\n return {\n // ensures we check React component tree (not just DOM tree)\n onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n onFocusOutside?: (event: FocusOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n const isFocusInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handleFocus = (event: FocusEvent) => {\n if (event.target && !isFocusInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n discrete: false,\n });\n }\n };\n ownerDocument.addEventListener('focusin', handleFocus);\n return () => ownerDocument.removeEventListener('focusin', handleFocus);\n }, [ownerDocument, handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new CustomEvent(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n name: string,\n handler: ((event: E) => void) | undefined,\n detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n { discrete }: { discrete: boolean }\n) {\n const target = detail.originalEvent.target;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n if (discrete) {\n dispatchDiscreteCustomEvent(target, event);\n } else {\n target.dispatchEvent(event);\n }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],"names":["DismissableLayer","DismissableLayerBranch","Root","Branch","React","composeEventHandlers","Primitive","dispatchDiscreteCustomEvent","useComposedRefs","useCallbackRef","useEscapeKeydown","DISMISSABLE_LAYER_NAME","CONTEXT_UPDATE","POINTER_DOWN_OUTSIDE","FOCUS_OUTSIDE","originalBodyPointerEvents","DismissableLayerContext","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","ownerDocument","globalThis","document","force","composedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","usePointerDownOutside","event","target","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","useFocusOutside","isFocusInBranch","isHighestLayer","preventDefault","useEffect","body","style","pointerEvents","add","dispatchUpdate","delete","handleUpdate","addEventListener","removeEventListener","undefined","onFocusCapture","onBlurCapture","onPointerDownCapture","BRANCH_NAME","ref","useRef","current","handlePointerDownOutside","isPointerInsideReactTreeRef","handleClickRef","handlePointerDown","eventDetail","originalEvent","handleAndDispatchPointerDownOutsideEvent","handleAndDispatchCustomEvent","discrete","pointerType","once","timerId","window","setTimeout","clearTimeout","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","CustomEvent","dispatchEvent","name","handler","detail","bubbles","cancelable"],"version":3,"file":"index.js.map"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/DismissableLayer.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\n\nconst DISMISSABLE_LAYER_NAME = 'DismissableLayer';\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n layers: new Set<DismissableLayerElement>(),\n layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n branches: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n /**\n * When `true`, hover/focus/click interactions will be disabled on elements outside\n * the `DismissableLayer`. Users will need to click twice on outside elements to\n * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n */\n disableOutsidePointerEvents?: boolean;\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n /**\n * Event handler called when the focus moves outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onFocusOutside?: (event: FocusOutsideEvent) => void;\n /**\n * Event handler called when an interaction happens outside the `DismissableLayer`.\n * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n * Can be prevented.\n */\n onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n /**\n * Handler called when the `DismissableLayer` should be dismissed\n */\n onDismiss?: () => void;\n}\n\nconst DismissableLayer = React.forwardRef<DismissableLayerElement, DismissableLayerProps>(\n (props, forwardedRef) => {\n const {\n disableOutsidePointerEvents = false,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n onDismiss,\n ...layerProps\n } = props;\n const context = React.useContext(DismissableLayerContext);\n const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n const [, force] = React.useState({});\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node));\n const layers = Array.from(context.layers);\n const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore\n const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore\n const index = node ? layers.indexOf(node) : -1;\n const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n\n const pointerDownOutside = usePointerDownOutside((event) => {\n const target = event.target as HTMLElement;\n const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));\n if (!isPointerEventsEnabled || isPointerDownOnBranch) return;\n onPointerDownOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n const focusOutside = useFocusOutside((event) => {\n const target = event.target as HTMLElement;\n const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n if (isFocusInBranch) return;\n onFocusOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n useEscapeKeydown((event) => {\n const isHighestLayer = index === context.layers.size - 1;\n if (!isHighestLayer) return;\n onEscapeKeyDown?.(event);\n if (!event.defaultPrevented && onDismiss) {\n event.preventDefault();\n onDismiss();\n }\n }, ownerDocument);\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n ownerDocument.body.style.pointerEvents = 'none';\n }\n context.layersWithOutsidePointerEventsDisabled.add(node);\n }\n context.layers.add(node);\n dispatchUpdate();\n return () => {\n if (\n disableOutsidePointerEvents &&\n context.layersWithOutsidePointerEventsDisabled.size === 1\n ) {\n ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n /**\n * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n * and add it to the end again so the layering order wouldn't be _creation order_.\n * We only want them to be removed from context stacks when unmounted.\n */\n React.useEffect(() => {\n return () => {\n if (!node) return;\n context.layers.delete(node);\n context.layersWithOutsidePointerEventsDisabled.delete(node);\n dispatchUpdate();\n };\n }, [node, context]);\n\n React.useEffect(() => {\n const handleUpdate = () => force({});\n document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n }, []);\n\n return (\n <Primitive.div\n {...layerProps}\n ref={composedRefs}\n style={{\n pointerEvents: isBodyPointerEventsDisabled\n ? isPointerEventsEnabled\n ? 'auto'\n : 'none'\n : undefined,\n ...props.style,\n }}\n onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n onPointerDownCapture={composeEventHandlers(\n props.onPointerDownCapture,\n pointerDownOutside.onPointerDownCapture\n )}\n />\n );\n }\n);\n\nDismissableLayer.displayName = DISMISSABLE_LAYER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\nconst BRANCH_NAME = 'DismissableLayerBranch';\n\ntype DismissableLayerBranchElement = React.ElementRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = React.forwardRef<\n DismissableLayerBranchElement,\n DismissableLayerBranchProps\n>((props, forwardedRef) => {\n const context = React.useContext(DismissableLayerContext);\n const ref = React.useRef<DismissableLayerBranchElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n const node = ref.current;\n if (node) {\n context.branches.add(node);\n return () => {\n context.branches.delete(node);\n };\n }\n }, [context.branches]);\n\n return <Primitive.div {...props} ref={composedRefs} />;\n});\n\nDismissableLayerBranch.displayName = BRANCH_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`\n * to mimic layer dismissing behaviour present in OS.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n const handleClickRef = React.useRef(() => {});\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n\n function handleAndDispatchPointerDownOutsideEvent() {\n handleAndDispatchCustomEvent(\n POINTER_DOWN_OUTSIDE,\n handlePointerDownOutside,\n eventDetail,\n { discrete: true }\n );\n }\n\n /**\n * On touch devices, we need to wait for a click event because browsers implement\n * a ~350ms delay between the time the user stops touching the display and when the\n * browser executres events. We need to ensure we don't reactivate pointer-events within\n * this timeframe otherwise the browser may execute events that should have been prevented.\n *\n * Additionally, this also lets us deal automatically with cancellations when a click event\n * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.\n *\n * This is why we also continuously remove the previous listener, because we cannot be\n * certain that it was raised, and therefore cleaned-up.\n */\n if (event.pointerType === 'touch') {\n ownerDocument.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\n } else {\n // We need to remove the event listener in case the outside click has been canceled.\n // See: https://github.com/radix-ui/primitives/issues/2171\n ownerDocument.removeEventListener('click', handleClickRef.current);\n }\n isPointerInsideReactTreeRef.current = false;\n };\n /**\n * if this hook executes in a component that mounts via a `pointerdown` event, the event\n * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n * this by delaying the event listener registration on the document.\n * This is not React specific, but rather how the DOM works, ie:\n * ```\n * button.addEventListener('pointerdown', () => {\n * console.log('I will log');\n * document.addEventListener('pointerdown', () => {\n * console.log('I will also log');\n * })\n * });\n */\n const timerId = window.setTimeout(() => {\n ownerDocument.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n ownerDocument.removeEventListener('click', handleClickRef.current);\n };\n }, [ownerDocument, handlePointerDownOutside]);\n\n return {\n // ensures we check React component tree (not just DOM tree)\n onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n onFocusOutside?: (event: FocusOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n const isFocusInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handleFocus = (event: FocusEvent) => {\n if (event.target && !isFocusInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n discrete: false,\n });\n }\n };\n ownerDocument.addEventListener('focusin', handleFocus);\n return () => ownerDocument.removeEventListener('focusin', handleFocus);\n }, [ownerDocument, handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new CustomEvent(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n name: string,\n handler: ((event: E) => void) | undefined,\n detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n { discrete }: { discrete: boolean }\n) {\n const target = detail.originalEvent.target;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n if (discrete) {\n dispatchDiscreteCustomEvent(target, event);\n } else {\n target.dispatchEvent(event);\n }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,yBAAqC;AACrC,+BAAuD;AACvD,kCAAgC;AAChC,sCAA+B;AAC/B,wCAAiC;AAuJ3B;AA/IN,MAAM,yBAAyB;AAC/B,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;AAC7B,MAAM,gBAAgB;AAEtB,MAAI;AAEJ,MAAM,0BAAgC,oBAAc;AAAA,IAClD,QAAQ,oBAAI,IAA6B;AAAA,IACzC,wCAAwC,oBAAI,IAA6B;AAAA,IACzE,UAAU,oBAAI,IAAmC;AAAA,EACnD,CAAC;AAsCD,MAAM,mBAAyB;AAAA,IAC7B,CAAC,OAAO,iBAAiB;AACvB,YAAM;AAAA,QACJ,8BAA8B;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL,IAAI;AACJ,YAAM,UAAgB,iBAAW,uBAAuB;AACxD,YAAM,CAAC,MAAM,OAAO,IAAU,eAAyC,IAAI;AAC3E,YAAM,gBAAgB,MAAM,iBAAiB,YAAY;AACzD,YAAM,CAAC,EAAE,KAAK,IAAU,eAAS,CAAC,CAAC;AACnC,YAAM,mBAAe,2CAAgB,cAAc,CAACA,UAAS,QAAQA,KAAI,CAAC;AAC1E,YAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;AACxC,YAAM,CAAC,4CAA4C,IAAI,CAAC,GAAG,QAAQ,sCAAsC,EAAE,MAAM,EAAE;AACnH,YAAM,oDAAoD,OAAO,QAAQ,4CAA4C;AACrH,YAAM,QAAQ,OAAO,OAAO,QAAQ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,4BAA4B,UAAU;AAAA,IACrE;AAAA,EACF;AAMA,WAAS,gBACP,gBACA,gBAA0B,YAAY,UACtC;AACA,UAAM,yBAAqB,8CAAe,cAAc;AACxD,UAAM,4BAAkC,aAAO,KAAK;AAEpD,IAAM,gBAAU,MAAM;AACpB,YAAM,cAAc,CAAC,UAAsB;AACzC,YAAI,MAAM,UAAU,CAAC,0BAA0B,SAAS;AACtD,gBAAM,cAAc,EAAE,eAAe,MAAM;AAC3C,uCAA6B,eAAe,oBAAoB,aAAa;AAAA,YAC3E,UAAU;AAAA,UACZ,CAAC;AAAA,QACH;AAAA,MACF;AACA,oBAAc,iBAAiB,WAAW,WAAW;AACrD,aAAO,MAAM,cAAc,oBAAoB,WAAW,WAAW;AAAA,IACvE,GAAG,CAAC,eAAe,kBAAkB,CAAC;AAEtC,WAAO;AAAA,MACL,gBAAgB,MAAO,0BAA0B,UAAU;AAAA,MAC3D,eAAe,MAAO,0BAA0B,UAAU;AAAA,IAC5D;AAAA,EACF;AAEA,WAAS,iBAAiB;AACxB,UAAM,QAAQ,IAAI,YAAY,cAAc;AAC5C,aAAS,cAAc,KAAK;AAAA,EAC9B;AAEA,WAAS,6BACP,MACA,SACA,QACA,EAAE,SAAS,GACX;AACA,UAAM,SAAS,OAAO,cAAc;AACpC,UAAM,QAAQ,IAAI,YAAY,MAAM,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,CAAC;AAChF,QAAI,QAAS,QAAO,iBAAiB,MAAM,SAA0B,EAAE,MAAM,KAAK,CAAC;AAEnF,QAAI,UAAU;AACZ,8DAA4B,QAAQ,KAAK;AAAA,IAC3C,OAAO;AACL,aAAO,cAAc,KAAK;AAAA,IAC5B;AAAA,EACF;AAEA,MAAM,OAAO;AACb,MAAM,SAAS;",
6
+ "names": ["node", "handleAndDispatchPointerDownOutsideEvent"]
7
+ }
package/dist/index.mjs CHANGED
@@ -1,283 +1,221 @@
1
- import $kqwpH$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
- import {createContext as $kqwpH$createContext, forwardRef as $kqwpH$forwardRef, useContext as $kqwpH$useContext, useState as $kqwpH$useState, useEffect as $kqwpH$useEffect, createElement as $kqwpH$createElement, useRef as $kqwpH$useRef} from "react";
3
- import {composeEventHandlers as $kqwpH$composeEventHandlers} from "@radix-ui/primitive";
4
- import {Primitive as $kqwpH$Primitive, dispatchDiscreteCustomEvent as $kqwpH$dispatchDiscreteCustomEvent} from "@radix-ui/react-primitive";
5
- import {useComposedRefs as $kqwpH$useComposedRefs} from "@radix-ui/react-compose-refs";
6
- import {useCallbackRef as $kqwpH$useCallbackRef} from "@radix-ui/react-use-callback-ref";
7
- import {useEscapeKeydown as $kqwpH$useEscapeKeydown} from "@radix-ui/react-use-escape-keydown";
1
+ "use client";
8
2
 
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
- /* -------------------------------------------------------------------------------------------------
17
- * DismissableLayer
18
- * -----------------------------------------------------------------------------------------------*/ const $5cb92bef7577960e$var$DISMISSABLE_LAYER_NAME = 'DismissableLayer';
19
- const $5cb92bef7577960e$var$CONTEXT_UPDATE = 'dismissableLayer.update';
20
- const $5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
21
- const $5cb92bef7577960e$var$FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
22
- let $5cb92bef7577960e$var$originalBodyPointerEvents;
23
- const $5cb92bef7577960e$var$DismissableLayerContext = /*#__PURE__*/ $kqwpH$createContext({
24
- layers: new Set(),
25
- layersWithOutsidePointerEventsDisabled: new Set(),
26
- branches: new Set()
3
+ // packages/react/dismissable-layer/src/DismissableLayer.tsx
4
+ import * as React from "react";
5
+ import { composeEventHandlers } from "@radix-ui/primitive";
6
+ import { Primitive, dispatchDiscreteCustomEvent } from "@radix-ui/react-primitive";
7
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
8
+ import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
9
+ import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var DISMISSABLE_LAYER_NAME = "DismissableLayer";
12
+ var CONTEXT_UPDATE = "dismissableLayer.update";
13
+ var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
14
+ var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
15
+ var originalBodyPointerEvents;
16
+ var DismissableLayerContext = React.createContext({
17
+ layers: /* @__PURE__ */ new Set(),
18
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
19
+ branches: /* @__PURE__ */ new Set()
27
20
  });
28
- const $5cb92bef7577960e$export$177fb62ff3ec1f22 = /*#__PURE__*/ $kqwpH$forwardRef((props, forwardedRef)=>{
29
- var _node$ownerDocument;
30
- const { disableOutsidePointerEvents: disableOutsidePointerEvents = false , onEscapeKeyDown: onEscapeKeyDown , onPointerDownOutside: onPointerDownOutside , onFocusOutside: onFocusOutside , onInteractOutside: onInteractOutside , onDismiss: onDismiss , ...layerProps } = props;
31
- const context = $kqwpH$useContext($5cb92bef7577960e$var$DismissableLayerContext);
32
- const [node1, setNode] = $kqwpH$useState(null);
33
- const ownerDocument = (_node$ownerDocument = node1 === null || node1 === void 0 ? void 0 : node1.ownerDocument) !== null && _node$ownerDocument !== void 0 ? _node$ownerDocument : globalThis === null || globalThis === void 0 ? void 0 : globalThis.document;
34
- const [, force] = $kqwpH$useState({});
35
- const composedRefs = $kqwpH$useComposedRefs(forwardedRef, (node)=>setNode(node)
36
- );
21
+ var DismissableLayer = React.forwardRef(
22
+ (props, forwardedRef) => {
23
+ const {
24
+ disableOutsidePointerEvents = false,
25
+ onEscapeKeyDown,
26
+ onPointerDownOutside,
27
+ onFocusOutside,
28
+ onInteractOutside,
29
+ onDismiss,
30
+ ...layerProps
31
+ } = props;
32
+ const context = React.useContext(DismissableLayerContext);
33
+ const [node, setNode] = React.useState(null);
34
+ const ownerDocument = node?.ownerDocument ?? globalThis?.document;
35
+ const [, force] = React.useState({});
36
+ const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
37
37
  const layers = Array.from(context.layers);
38
- const [highestLayerWithOutsidePointerEventsDisabled] = [
39
- ...context.layersWithOutsidePointerEventsDisabled
40
- ].slice(-1); // prettier-ignore
41
- const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore
42
- const index = node1 ? layers.indexOf(node1) : -1;
38
+ const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
39
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
40
+ const index = node ? layers.indexOf(node) : -1;
43
41
  const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
44
42
  const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
45
- const pointerDownOutside = $5cb92bef7577960e$var$usePointerDownOutside((event)=>{
46
- const target = event.target;
47
- const isPointerDownOnBranch = [
48
- ...context.branches
49
- ].some((branch)=>branch.contains(target)
50
- );
51
- if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
52
- onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event);
53
- onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
54
- if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
43
+ const pointerDownOutside = usePointerDownOutside((event) => {
44
+ const target = event.target;
45
+ const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
46
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
47
+ onPointerDownOutside?.(event);
48
+ onInteractOutside?.(event);
49
+ if (!event.defaultPrevented) onDismiss?.();
55
50
  }, ownerDocument);
56
- const focusOutside = $5cb92bef7577960e$var$useFocusOutside((event)=>{
57
- const target = event.target;
58
- const isFocusInBranch = [
59
- ...context.branches
60
- ].some((branch)=>branch.contains(target)
61
- );
62
- if (isFocusInBranch) return;
63
- onFocusOutside === null || onFocusOutside === void 0 || onFocusOutside(event);
64
- onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
65
- if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
51
+ const focusOutside = useFocusOutside((event) => {
52
+ const target = event.target;
53
+ const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
54
+ if (isFocusInBranch) return;
55
+ onFocusOutside?.(event);
56
+ onInteractOutside?.(event);
57
+ if (!event.defaultPrevented) onDismiss?.();
66
58
  }, ownerDocument);
67
- $kqwpH$useEscapeKeydown((event)=>{
68
- const isHighestLayer = index === context.layers.size - 1;
69
- if (!isHighestLayer) return;
70
- onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
71
- if (!event.defaultPrevented && onDismiss) {
72
- event.preventDefault();
73
- onDismiss();
74
- }
59
+ useEscapeKeydown((event) => {
60
+ const isHighestLayer = index === context.layers.size - 1;
61
+ if (!isHighestLayer) return;
62
+ onEscapeKeyDown?.(event);
63
+ if (!event.defaultPrevented && onDismiss) {
64
+ event.preventDefault();
65
+ onDismiss();
66
+ }
75
67
  }, ownerDocument);
76
- $kqwpH$useEffect(()=>{
77
- if (!node1) return;
78
- if (disableOutsidePointerEvents) {
79
- if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
80
- $5cb92bef7577960e$var$originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
81
- ownerDocument.body.style.pointerEvents = 'none';
82
- }
83
- context.layersWithOutsidePointerEventsDisabled.add(node1);
68
+ React.useEffect(() => {
69
+ if (!node) return;
70
+ if (disableOutsidePointerEvents) {
71
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
72
+ originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
73
+ ownerDocument.body.style.pointerEvents = "none";
84
74
  }
85
- context.layers.add(node1);
86
- $5cb92bef7577960e$var$dispatchUpdate();
87
- return ()=>{
88
- if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) ownerDocument.body.style.pointerEvents = $5cb92bef7577960e$var$originalBodyPointerEvents;
89
- };
90
- }, [
91
- node1,
92
- ownerDocument,
93
- disableOutsidePointerEvents,
94
- context
95
- ]);
96
- /**
97
- * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
98
- * because a change to `disableOutsidePointerEvents` would remove this layer from the stack
99
- * and add it to the end again so the layering order wouldn't be _creation order_.
100
- * We only want them to be removed from context stacks when unmounted.
101
- */ $kqwpH$useEffect(()=>{
102
- return ()=>{
103
- if (!node1) return;
104
- context.layers.delete(node1);
105
- context.layersWithOutsidePointerEventsDisabled.delete(node1);
106
- $5cb92bef7577960e$var$dispatchUpdate();
107
- };
108
- }, [
109
- node1,
110
- context
111
- ]);
112
- $kqwpH$useEffect(()=>{
113
- const handleUpdate = ()=>force({})
114
- ;
115
- document.addEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate);
116
- return ()=>document.removeEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate)
117
- ;
75
+ context.layersWithOutsidePointerEventsDisabled.add(node);
76
+ }
77
+ context.layers.add(node);
78
+ dispatchUpdate();
79
+ return () => {
80
+ if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
81
+ ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
82
+ }
83
+ };
84
+ }, [node, ownerDocument, disableOutsidePointerEvents, context]);
85
+ React.useEffect(() => {
86
+ return () => {
87
+ if (!node) return;
88
+ context.layers.delete(node);
89
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
90
+ dispatchUpdate();
91
+ };
92
+ }, [node, context]);
93
+ React.useEffect(() => {
94
+ const handleUpdate = () => force({});
95
+ document.addEventListener(CONTEXT_UPDATE, handleUpdate);
96
+ return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
118
97
  }, []);
119
- return /*#__PURE__*/ $kqwpH$createElement($kqwpH$Primitive.div, $kqwpH$babelruntimehelpersesmextends({}, layerProps, {
98
+ return /* @__PURE__ */ jsx(
99
+ Primitive.div,
100
+ {
101
+ ...layerProps,
120
102
  ref: composedRefs,
121
103
  style: {
122
- pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? 'auto' : 'none' : undefined,
123
- ...props.style
104
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
105
+ ...props.style
124
106
  },
125
- onFocusCapture: $kqwpH$composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
126
- onBlurCapture: $kqwpH$composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
127
- onPointerDownCapture: $kqwpH$composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
128
- }));
129
- });
130
- /*#__PURE__*/ Object.assign($5cb92bef7577960e$export$177fb62ff3ec1f22, {
131
- displayName: $5cb92bef7577960e$var$DISMISSABLE_LAYER_NAME
132
- });
133
- /* -------------------------------------------------------------------------------------------------
134
- * DismissableLayerBranch
135
- * -----------------------------------------------------------------------------------------------*/ const $5cb92bef7577960e$var$BRANCH_NAME = 'DismissableLayerBranch';
136
- const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRef((props, forwardedRef)=>{
137
- const context = $kqwpH$useContext($5cb92bef7577960e$var$DismissableLayerContext);
138
- const ref = $kqwpH$useRef(null);
139
- const composedRefs = $kqwpH$useComposedRefs(forwardedRef, ref);
140
- $kqwpH$useEffect(()=>{
141
- const node = ref.current;
142
- if (node) {
143
- context.branches.add(node);
144
- return ()=>{
145
- context.branches.delete(node);
146
- };
147
- }
148
- }, [
149
- context.branches
150
- ]);
151
- return /*#__PURE__*/ $kqwpH$createElement($kqwpH$Primitive.div, $kqwpH$babelruntimehelpersesmextends({}, props, {
152
- ref: composedRefs
153
- }));
154
- });
155
- /*#__PURE__*/ Object.assign($5cb92bef7577960e$export$4d5eb2109db14228, {
156
- displayName: $5cb92bef7577960e$var$BRANCH_NAME
107
+ onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
108
+ onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
109
+ onPointerDownCapture: composeEventHandlers(
110
+ props.onPointerDownCapture,
111
+ pointerDownOutside.onPointerDownCapture
112
+ )
113
+ }
114
+ );
115
+ }
116
+ );
117
+ DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
118
+ var BRANCH_NAME = "DismissableLayerBranch";
119
+ var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
120
+ const context = React.useContext(DismissableLayerContext);
121
+ const ref = React.useRef(null);
122
+ const composedRefs = useComposedRefs(forwardedRef, ref);
123
+ React.useEffect(() => {
124
+ const node = ref.current;
125
+ if (node) {
126
+ context.branches.add(node);
127
+ return () => {
128
+ context.branches.delete(node);
129
+ };
130
+ }
131
+ }, [context.branches]);
132
+ return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref: composedRefs });
157
133
  });
158
- /* -----------------------------------------------------------------------------------------------*/ /**
159
- * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`
160
- * to mimic layer dismissing behaviour present in OS.
161
- * Returns props to pass to the node we want to check for outside events.
162
- */ function $5cb92bef7577960e$var$usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) {
163
- const handlePointerDownOutside = $kqwpH$useCallbackRef(onPointerDownOutside);
164
- const isPointerInsideReactTreeRef = $kqwpH$useRef(false);
165
- const handleClickRef = $kqwpH$useRef(()=>{});
166
- $kqwpH$useEffect(()=>{
167
- const handlePointerDown = (event)=>{
168
- if (event.target && !isPointerInsideReactTreeRef.current) {
169
- const eventDetail = {
170
- originalEvent: event
171
- };
172
- function handleAndDispatchPointerDownOutsideEvent() {
173
- $5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
174
- discrete: true
175
- });
176
- }
177
- /**
178
- * On touch devices, we need to wait for a click event because browsers implement
179
- * a ~350ms delay between the time the user stops touching the display and when the
180
- * browser executres events. We need to ensure we don't reactivate pointer-events within
181
- * this timeframe otherwise the browser may execute events that should have been prevented.
182
- *
183
- * Additionally, this also lets us deal automatically with cancellations when a click event
184
- * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.
185
- *
186
- * This is why we also continuously remove the previous listener, because we cannot be
187
- * certain that it was raised, and therefore cleaned-up.
188
- */ if (event.pointerType === 'touch') {
189
- ownerDocument.removeEventListener('click', handleClickRef.current);
190
- handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
191
- ownerDocument.addEventListener('click', handleClickRef.current, {
192
- once: true
193
- });
194
- } else handleAndDispatchPointerDownOutsideEvent();
195
- } else // We need to remove the event listener in case the outside click has been canceled.
196
- // See: https://github.com/radix-ui/primitives/issues/2171
197
- ownerDocument.removeEventListener('click', handleClickRef.current);
198
- isPointerInsideReactTreeRef.current = false;
199
- };
200
- /**
201
- * if this hook executes in a component that mounts via a `pointerdown` event, the event
202
- * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid
203
- * this by delaying the event listener registration on the document.
204
- * This is not React specific, but rather how the DOM works, ie:
205
- * ```
206
- * button.addEventListener('pointerdown', () => {
207
- * console.log('I will log');
208
- * document.addEventListener('pointerdown', () => {
209
- * console.log('I will also log');
210
- * })
211
- * });
212
- */ const timerId = window.setTimeout(()=>{
213
- ownerDocument.addEventListener('pointerdown', handlePointerDown);
214
- }, 0);
215
- return ()=>{
216
- window.clearTimeout(timerId);
217
- ownerDocument.removeEventListener('pointerdown', handlePointerDown);
218
- ownerDocument.removeEventListener('click', handleClickRef.current);
134
+ DismissableLayerBranch.displayName = BRANCH_NAME;
135
+ function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
136
+ const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
137
+ const isPointerInsideReactTreeRef = React.useRef(false);
138
+ const handleClickRef = React.useRef(() => {
139
+ });
140
+ React.useEffect(() => {
141
+ const handlePointerDown = (event) => {
142
+ if (event.target && !isPointerInsideReactTreeRef.current) {
143
+ let handleAndDispatchPointerDownOutsideEvent2 = function() {
144
+ handleAndDispatchCustomEvent(
145
+ POINTER_DOWN_OUTSIDE,
146
+ handlePointerDownOutside,
147
+ eventDetail,
148
+ { discrete: true }
149
+ );
219
150
  };
220
- }, [
221
- ownerDocument,
222
- handlePointerDownOutside
223
- ]);
224
- return {
225
- // ensures we check React component tree (not just DOM tree)
226
- onPointerDownCapture: ()=>isPointerInsideReactTreeRef.current = true
151
+ var handleAndDispatchPointerDownOutsideEvent = handleAndDispatchPointerDownOutsideEvent2;
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 {
158
+ handleAndDispatchPointerDownOutsideEvent2();
159
+ }
160
+ } else {
161
+ ownerDocument.removeEventListener("click", handleClickRef.current);
162
+ }
163
+ isPointerInsideReactTreeRef.current = false;
227
164
  };
165
+ const timerId = window.setTimeout(() => {
166
+ ownerDocument.addEventListener("pointerdown", handlePointerDown);
167
+ }, 0);
168
+ return () => {
169
+ window.clearTimeout(timerId);
170
+ ownerDocument.removeEventListener("pointerdown", handlePointerDown);
171
+ ownerDocument.removeEventListener("click", handleClickRef.current);
172
+ };
173
+ }, [ownerDocument, handlePointerDownOutside]);
174
+ return {
175
+ // ensures we check React component tree (not just DOM tree)
176
+ onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
177
+ };
228
178
  }
229
- /**
230
- * Listens for when focus happens outside a react subtree.
231
- * Returns props to pass to the root (node) of the subtree we want to check.
232
- */ function $5cb92bef7577960e$var$useFocusOutside(onFocusOutside, ownerDocument = globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) {
233
- const handleFocusOutside = $kqwpH$useCallbackRef(onFocusOutside);
234
- const isFocusInsideReactTreeRef = $kqwpH$useRef(false);
235
- $kqwpH$useEffect(()=>{
236
- const handleFocus = (event)=>{
237
- if (event.target && !isFocusInsideReactTreeRef.current) {
238
- const eventDetail = {
239
- originalEvent: event
240
- };
241
- $5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
242
- discrete: false
243
- });
244
- }
245
- };
246
- ownerDocument.addEventListener('focusin', handleFocus);
247
- return ()=>ownerDocument.removeEventListener('focusin', handleFocus)
248
- ;
249
- }, [
250
- ownerDocument,
251
- handleFocusOutside
252
- ]);
253
- return {
254
- onFocusCapture: ()=>isFocusInsideReactTreeRef.current = true
255
- ,
256
- onBlurCapture: ()=>isFocusInsideReactTreeRef.current = false
179
+ function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
180
+ const handleFocusOutside = useCallbackRef(onFocusOutside);
181
+ const isFocusInsideReactTreeRef = React.useRef(false);
182
+ React.useEffect(() => {
183
+ const handleFocus = (event) => {
184
+ if (event.target && !isFocusInsideReactTreeRef.current) {
185
+ const eventDetail = { originalEvent: event };
186
+ handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
187
+ discrete: false
188
+ });
189
+ }
257
190
  };
191
+ ownerDocument.addEventListener("focusin", handleFocus);
192
+ return () => ownerDocument.removeEventListener("focusin", handleFocus);
193
+ }, [ownerDocument, handleFocusOutside]);
194
+ return {
195
+ onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
196
+ onBlurCapture: () => isFocusInsideReactTreeRef.current = false
197
+ };
258
198
  }
259
- function $5cb92bef7577960e$var$dispatchUpdate() {
260
- const event = new CustomEvent($5cb92bef7577960e$var$CONTEXT_UPDATE);
261
- document.dispatchEvent(event);
199
+ function dispatchUpdate() {
200
+ const event = new CustomEvent(CONTEXT_UPDATE);
201
+ document.dispatchEvent(event);
262
202
  }
263
- function $5cb92bef7577960e$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete: discrete }) {
264
- const target = detail.originalEvent.target;
265
- const event = new CustomEvent(name, {
266
- bubbles: false,
267
- cancelable: true,
268
- detail: detail
269
- });
270
- if (handler) target.addEventListener(name, handler, {
271
- once: true
272
- });
273
- if (discrete) $kqwpH$dispatchDiscreteCustomEvent(target, event);
274
- else target.dispatchEvent(event);
203
+ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
204
+ const target = detail.originalEvent.target;
205
+ const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
206
+ if (handler) target.addEventListener(name, handler, { once: true });
207
+ if (discrete) {
208
+ dispatchDiscreteCustomEvent(target, event);
209
+ } else {
210
+ target.dispatchEvent(event);
211
+ }
275
212
  }
276
- const $5cb92bef7577960e$export$be92b6f5f03c0fe9 = $5cb92bef7577960e$export$177fb62ff3ec1f22;
277
- const $5cb92bef7577960e$export$aecb2ddcb55c95be = $5cb92bef7577960e$export$4d5eb2109db14228;
278
-
279
-
280
-
281
-
282
- export {$5cb92bef7577960e$export$177fb62ff3ec1f22 as DismissableLayer, $5cb92bef7577960e$export$4d5eb2109db14228 as DismissableLayerBranch, $5cb92bef7577960e$export$be92b6f5f03c0fe9 as Root, $5cb92bef7577960e$export$aecb2ddcb55c95be as Branch};
213
+ var Root = DismissableLayer;
214
+ var Branch = DismissableLayerBranch;
215
+ export {
216
+ Branch,
217
+ DismissableLayer,
218
+ DismissableLayerBranch,
219
+ Root
220
+ };
283
221
  //# sourceMappingURL=index.mjs.map