index.mjs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import $eRSIW$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
  2. import {useRef as $eRSIW$useRef, useCallback as $eRSIW$useCallback, useEffect as $eRSIW$useEffect, createElement as $eRSIW$createElement, forwardRef as $eRSIW$forwardRef, useState as $eRSIW$useState} from "react";
  3. import {composeEventHandlers as $eRSIW$composeEventHandlers} from "@radix-ui/primitive";
  4. import {createContextScope as $eRSIW$createContextScope} from "@radix-ui/react-context";
  5. import {useControllableState as $eRSIW$useControllableState} from "@radix-ui/react-use-controllable-state";
  6. import {useComposedRefs as $eRSIW$useComposedRefs} from "@radix-ui/react-compose-refs";
  7. import {createPopperScope as $eRSIW$createPopperScope, Root as $eRSIW$Root, Anchor as $eRSIW$Anchor, Content as $eRSIW$Content, Arrow as $eRSIW$Arrow} from "@radix-ui/react-popper";
  8. import {Portal as $eRSIW$Portal} from "@radix-ui/react-portal";
  9. import {Presence as $eRSIW$Presence} from "@radix-ui/react-presence";
  10. import {Primitive as $eRSIW$Primitive} from "@radix-ui/react-primitive";
  11. import {DismissableLayer as $eRSIW$DismissableLayer} from "@radix-ui/react-dismissable-layer";
  12. /* -------------------------------------------------------------------------------------------------
  13. * HoverCard
  14. * -----------------------------------------------------------------------------------------------*/ let $cef8881cdc69808e$var$originalBodyUserSelect;
  15. const $cef8881cdc69808e$var$HOVERCARD_NAME = 'HoverCard';
  16. const [$cef8881cdc69808e$var$createHoverCardContext, $cef8881cdc69808e$export$47b6998a836b7260] = $eRSIW$createContextScope($cef8881cdc69808e$var$HOVERCARD_NAME, [
  17. $eRSIW$createPopperScope
  18. ]);
  19. const $cef8881cdc69808e$var$usePopperScope = $eRSIW$createPopperScope();
  20. const [$cef8881cdc69808e$var$HoverCardProvider, $cef8881cdc69808e$var$useHoverCardContext] = $cef8881cdc69808e$var$createHoverCardContext($cef8881cdc69808e$var$HOVERCARD_NAME);
  21. const $cef8881cdc69808e$export$57a077cc9fbe653e = (props)=>{
  22. const { __scopeHoverCard: __scopeHoverCard , children: children , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , openDelay: openDelay = 700 , closeDelay: closeDelay = 300 } = props;
  23. const popperScope = $cef8881cdc69808e$var$usePopperScope(__scopeHoverCard);
  24. const openTimerRef = $eRSIW$useRef(0);
  25. const closeTimerRef = $eRSIW$useRef(0);
  26. const hasSelectionRef = $eRSIW$useRef(false);
  27. const isPointerDownOnContentRef = $eRSIW$useRef(false);
  28. const [open = false, setOpen] = $eRSIW$useControllableState({
  29. prop: openProp,
  30. defaultProp: defaultOpen,
  31. onChange: onOpenChange
  32. });
  33. const handleOpen = $eRSIW$useCallback(()=>{
  34. clearTimeout(closeTimerRef.current);
  35. openTimerRef.current = window.setTimeout(()=>setOpen(true)
  36. , openDelay);
  37. }, [
  38. openDelay,
  39. setOpen
  40. ]);
  41. const handleClose = $eRSIW$useCallback(()=>{
  42. clearTimeout(openTimerRef.current);
  43. if (!hasSelectionRef.current && !isPointerDownOnContentRef.current) closeTimerRef.current = window.setTimeout(()=>setOpen(false)
  44. , closeDelay);
  45. }, [
  46. closeDelay,
  47. setOpen
  48. ]);
  49. const handleDismiss = $eRSIW$useCallback(()=>setOpen(false)
  50. , [
  51. setOpen
  52. ]); // cleanup any queued state updates on unmount
  53. $eRSIW$useEffect(()=>{
  54. return ()=>{
  55. clearTimeout(openTimerRef.current);
  56. clearTimeout(closeTimerRef.current);
  57. };
  58. }, []);
  59. return /*#__PURE__*/ $eRSIW$createElement($cef8881cdc69808e$var$HoverCardProvider, {
  60. scope: __scopeHoverCard,
  61. open: open,
  62. onOpenChange: setOpen,
  63. onOpen: handleOpen,
  64. onClose: handleClose,
  65. onDismiss: handleDismiss,
  66. hasSelectionRef: hasSelectionRef,
  67. isPointerDownOnContentRef: isPointerDownOnContentRef
  68. }, /*#__PURE__*/ $eRSIW$createElement($eRSIW$Root, popperScope, children));
  69. };
  70. /*#__PURE__*/ Object.assign($cef8881cdc69808e$export$57a077cc9fbe653e, {
  71. displayName: $cef8881cdc69808e$var$HOVERCARD_NAME
  72. });
  73. /* -------------------------------------------------------------------------------------------------
  74. * HoverCardTrigger
  75. * -----------------------------------------------------------------------------------------------*/ const $cef8881cdc69808e$var$TRIGGER_NAME = 'HoverCardTrigger';
  76. const $cef8881cdc69808e$export$ef9f7fd8e4ba882f = /*#__PURE__*/ $eRSIW$forwardRef((props, forwardedRef)=>{
  77. const { __scopeHoverCard: __scopeHoverCard , ...triggerProps } = props;
  78. const context = $cef8881cdc69808e$var$useHoverCardContext($cef8881cdc69808e$var$TRIGGER_NAME, __scopeHoverCard);
  79. const popperScope = $cef8881cdc69808e$var$usePopperScope(__scopeHoverCard);
  80. return /*#__PURE__*/ $eRSIW$createElement($eRSIW$Anchor, $eRSIW$babelruntimehelpersesmextends({
  81. asChild: true
  82. }, popperScope), /*#__PURE__*/ $eRSIW$createElement($eRSIW$Primitive.a, $eRSIW$babelruntimehelpersesmextends({
  83. "data-state": context.open ? 'open' : 'closed'
  84. }, triggerProps, {
  85. ref: forwardedRef,
  86. onPointerEnter: $eRSIW$composeEventHandlers(props.onPointerEnter, $cef8881cdc69808e$var$excludeTouch(context.onOpen)),
  87. onPointerLeave: $eRSIW$composeEventHandlers(props.onPointerLeave, $cef8881cdc69808e$var$excludeTouch(context.onClose)),
  88. onFocus: $eRSIW$composeEventHandlers(props.onFocus, context.onOpen),
  89. onBlur: $eRSIW$composeEventHandlers(props.onBlur, context.onClose) // prevent focus event on touch devices
  90. ,
  91. onTouchStart: $eRSIW$composeEventHandlers(props.onTouchStart, (event)=>event.preventDefault()
  92. )
  93. })));
  94. });
  95. /*#__PURE__*/ Object.assign($cef8881cdc69808e$export$ef9f7fd8e4ba882f, {
  96. displayName: $cef8881cdc69808e$var$TRIGGER_NAME
  97. });
  98. /* -------------------------------------------------------------------------------------------------
  99. * HoverCardPortal
  100. * -----------------------------------------------------------------------------------------------*/ const $cef8881cdc69808e$var$PORTAL_NAME = 'HoverCardPortal';
  101. const [$cef8881cdc69808e$var$PortalProvider, $cef8881cdc69808e$var$usePortalContext] = $cef8881cdc69808e$var$createHoverCardContext($cef8881cdc69808e$var$PORTAL_NAME, {
  102. forceMount: undefined
  103. });
  104. const $cef8881cdc69808e$export$b384c6e0a789f88b = (props)=>{
  105. const { __scopeHoverCard: __scopeHoverCard , forceMount: forceMount , children: children , container: container } = props;
  106. const context = $cef8881cdc69808e$var$useHoverCardContext($cef8881cdc69808e$var$PORTAL_NAME, __scopeHoverCard);
  107. return /*#__PURE__*/ $eRSIW$createElement($cef8881cdc69808e$var$PortalProvider, {
  108. scope: __scopeHoverCard,
  109. forceMount: forceMount
  110. }, /*#__PURE__*/ $eRSIW$createElement($eRSIW$Presence, {
  111. present: forceMount || context.open
  112. }, /*#__PURE__*/ $eRSIW$createElement($eRSIW$Portal, {
  113. asChild: true,
  114. container: container
  115. }, children)));
  116. };
  117. /*#__PURE__*/ Object.assign($cef8881cdc69808e$export$b384c6e0a789f88b, {
  118. displayName: $cef8881cdc69808e$var$PORTAL_NAME
  119. });
  120. /* -------------------------------------------------------------------------------------------------
  121. * HoverCardContent
  122. * -----------------------------------------------------------------------------------------------*/ const $cef8881cdc69808e$var$CONTENT_NAME = 'HoverCardContent';
  123. const $cef8881cdc69808e$export$aa4724a5938c586 = /*#__PURE__*/ $eRSIW$forwardRef((props, forwardedRef)=>{
  124. const portalContext = $cef8881cdc69808e$var$usePortalContext($cef8881cdc69808e$var$CONTENT_NAME, props.__scopeHoverCard);
  125. const { forceMount: forceMount = portalContext.forceMount , ...contentProps } = props;
  126. const context = $cef8881cdc69808e$var$useHoverCardContext($cef8881cdc69808e$var$CONTENT_NAME, props.__scopeHoverCard);
  127. return /*#__PURE__*/ $eRSIW$createElement($eRSIW$Presence, {
  128. present: forceMount || context.open
  129. }, /*#__PURE__*/ $eRSIW$createElement($cef8881cdc69808e$var$HoverCardContentImpl, $eRSIW$babelruntimehelpersesmextends({
  130. "data-state": context.open ? 'open' : 'closed'
  131. }, contentProps, {
  132. onPointerEnter: $eRSIW$composeEventHandlers(props.onPointerEnter, $cef8881cdc69808e$var$excludeTouch(context.onOpen)),
  133. onPointerLeave: $eRSIW$composeEventHandlers(props.onPointerLeave, $cef8881cdc69808e$var$excludeTouch(context.onClose)),
  134. ref: forwardedRef
  135. })));
  136. });
  137. /*#__PURE__*/ Object.assign($cef8881cdc69808e$export$aa4724a5938c586, {
  138. displayName: $cef8881cdc69808e$var$CONTENT_NAME
  139. });
  140. /* ---------------------------------------------------------------------------------------------- */ const $cef8881cdc69808e$var$HoverCardContentImpl = /*#__PURE__*/ $eRSIW$forwardRef((props, forwardedRef)=>{
  141. const { __scopeHoverCard: __scopeHoverCard , onEscapeKeyDown: onEscapeKeyDown , onPointerDownOutside: onPointerDownOutside , onFocusOutside: onFocusOutside , onInteractOutside: onInteractOutside , ...contentProps } = props;
  142. const context = $cef8881cdc69808e$var$useHoverCardContext($cef8881cdc69808e$var$CONTENT_NAME, __scopeHoverCard);
  143. const popperScope = $cef8881cdc69808e$var$usePopperScope(__scopeHoverCard);
  144. const ref = $eRSIW$useRef(null);
  145. const composedRefs = $eRSIW$useComposedRefs(forwardedRef, ref);
  146. const [containSelection, setContainSelection] = $eRSIW$useState(false);
  147. $eRSIW$useEffect(()=>{
  148. if (containSelection) {
  149. const body = document.body; // Safari requires prefix
  150. $cef8881cdc69808e$var$originalBodyUserSelect = body.style.userSelect || body.style.webkitUserSelect;
  151. body.style.userSelect = 'none';
  152. body.style.webkitUserSelect = 'none';
  153. return ()=>{
  154. body.style.userSelect = $cef8881cdc69808e$var$originalBodyUserSelect;
  155. body.style.webkitUserSelect = $cef8881cdc69808e$var$originalBodyUserSelect;
  156. };
  157. }
  158. }, [
  159. containSelection
  160. ]);
  161. $eRSIW$useEffect(()=>{
  162. if (ref.current) {
  163. const handlePointerUp = ()=>{
  164. setContainSelection(false);
  165. context.isPointerDownOnContentRef.current = false; // Delay a frame to ensure we always access the latest selection
  166. setTimeout(()=>{
  167. var _document$getSelectio;
  168. const hasSelection = ((_document$getSelectio = document.getSelection()) === null || _document$getSelectio === void 0 ? void 0 : _document$getSelectio.toString()) !== '';
  169. if (hasSelection) context.hasSelectionRef.current = true;
  170. });
  171. };
  172. document.addEventListener('pointerup', handlePointerUp);
  173. return ()=>{
  174. document.removeEventListener('pointerup', handlePointerUp);
  175. context.hasSelectionRef.current = false;
  176. context.isPointerDownOnContentRef.current = false;
  177. };
  178. }
  179. }, [
  180. context.isPointerDownOnContentRef,
  181. context.hasSelectionRef
  182. ]);
  183. $eRSIW$useEffect(()=>{
  184. if (ref.current) {
  185. const tabbables = $cef8881cdc69808e$var$getTabbableNodes(ref.current);
  186. tabbables.forEach((tabbable)=>tabbable.setAttribute('tabindex', '-1')
  187. );
  188. }
  189. });
  190. return /*#__PURE__*/ $eRSIW$createElement($eRSIW$DismissableLayer, {
  191. asChild: true,
  192. disableOutsidePointerEvents: false,
  193. onInteractOutside: onInteractOutside,
  194. onEscapeKeyDown: onEscapeKeyDown,
  195. onPointerDownOutside: onPointerDownOutside,
  196. onFocusOutside: $eRSIW$composeEventHandlers(onFocusOutside, (event)=>{
  197. event.preventDefault();
  198. }),
  199. onDismiss: context.onDismiss
  200. }, /*#__PURE__*/ $eRSIW$createElement($eRSIW$Content, $eRSIW$babelruntimehelpersesmextends({}, popperScope, contentProps, {
  201. onPointerDown: $eRSIW$composeEventHandlers(contentProps.onPointerDown, (event)=>{
  202. // Contain selection to current layer
  203. if (event.currentTarget.contains(event.target)) setContainSelection(true);
  204. context.hasSelectionRef.current = false;
  205. context.isPointerDownOnContentRef.current = true;
  206. }),
  207. ref: composedRefs,
  208. style: {
  209. ...contentProps.style,
  210. userSelect: containSelection ? 'text' : undefined,
  211. // Safari requires prefix
  212. WebkitUserSelect: containSelection ? 'text' : undefined,
  213. '--radix-hover-card-content-transform-origin': 'var(--radix-popper-transform-origin)',
  214. '--radix-hover-card-content-available-width': 'var(--radix-popper-available-width)',
  215. '--radix-hover-card-content-available-height': 'var(--radix-popper-available-height)',
  216. '--radix-hover-card-trigger-width': 'var(--radix-popper-anchor-width)',
  217. '--radix-hover-card-trigger-height': 'var(--radix-popper-anchor-height)'
  218. }
  219. })));
  220. });
  221. /* -------------------------------------------------------------------------------------------------
  222. * HoverCardArrow
  223. * -----------------------------------------------------------------------------------------------*/ const $cef8881cdc69808e$var$ARROW_NAME = 'HoverCardArrow';
  224. const $cef8881cdc69808e$export$b9744d3e7456d806 = /*#__PURE__*/ $eRSIW$forwardRef((props, forwardedRef)=>{
  225. const { __scopeHoverCard: __scopeHoverCard , ...arrowProps } = props;
  226. const popperScope = $cef8881cdc69808e$var$usePopperScope(__scopeHoverCard);
  227. return /*#__PURE__*/ $eRSIW$createElement($eRSIW$Arrow, $eRSIW$babelruntimehelpersesmextends({}, popperScope, arrowProps, {
  228. ref: forwardedRef
  229. }));
  230. });
  231. /*#__PURE__*/ Object.assign($cef8881cdc69808e$export$b9744d3e7456d806, {
  232. displayName: $cef8881cdc69808e$var$ARROW_NAME
  233. });
  234. /* -----------------------------------------------------------------------------------------------*/ function $cef8881cdc69808e$var$excludeTouch(eventHandler) {
  235. return (event)=>event.pointerType === 'touch' ? undefined : eventHandler()
  236. ;
  237. }
  238. /**
  239. * Returns a list of nodes that can be in the tab sequence.
  240. * @see: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
  241. */ function $cef8881cdc69808e$var$getTabbableNodes(container) {
  242. const nodes = [];
  243. const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
  244. acceptNode: (node)=>{
  245. // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
  246. // runtime's understanding of tabbability, so this automatically accounts
  247. // for any kind of element that could be tabbed to.
  248. return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
  249. }
  250. });
  251. while(walker.nextNode())nodes.push(walker.currentNode);
  252. return nodes;
  253. }
  254. const $cef8881cdc69808e$export$be92b6f5f03c0fe9 = $cef8881cdc69808e$export$57a077cc9fbe653e;
  255. const $cef8881cdc69808e$export$41fb9f06171c75f4 = $cef8881cdc69808e$export$ef9f7fd8e4ba882f;
  256. const $cef8881cdc69808e$export$602eac185826482c = $cef8881cdc69808e$export$b384c6e0a789f88b;
  257. const $cef8881cdc69808e$export$7c6e2c02157bb7d2 = $cef8881cdc69808e$export$aa4724a5938c586;
  258. const $cef8881cdc69808e$export$21b07c8f274aebd5 = $cef8881cdc69808e$export$b9744d3e7456d806;
  259. export {$cef8881cdc69808e$export$47b6998a836b7260 as createHoverCardScope, $cef8881cdc69808e$export$57a077cc9fbe653e as HoverCard, $cef8881cdc69808e$export$ef9f7fd8e4ba882f as HoverCardTrigger, $cef8881cdc69808e$export$b384c6e0a789f88b as HoverCardPortal, $cef8881cdc69808e$export$aa4724a5938c586 as HoverCardContent, $cef8881cdc69808e$export$b9744d3e7456d806 as HoverCardArrow, $cef8881cdc69808e$export$be92b6f5f03c0fe9 as Root, $cef8881cdc69808e$export$41fb9f06171c75f4 as Trigger, $cef8881cdc69808e$export$602eac185826482c as Portal, $cef8881cdc69808e$export$7c6e2c02157bb7d2 as Content, $cef8881cdc69808e$export$21b07c8f274aebd5 as Arrow};
  260. //# sourceMappingURL=index.mjs.map