index.js 17 KB

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