@activecollab/components 2.0.528 → 2.0.529

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.
Files changed (28) hide show
  1. package/dist/cjs/components/GlobalPortal/GlobalPortal.js +10 -4
  2. package/dist/cjs/components/GlobalPortal/GlobalPortal.js.map +1 -1
  3. package/dist/cjs/components/ModalRoot/ModalRoot.js +5 -4
  4. package/dist/cjs/components/ModalRoot/ModalRoot.js.map +1 -1
  5. package/dist/cjs/components/ModalRoot/modalRootStack.js +21 -13
  6. package/dist/cjs/components/ModalRoot/modalRootStack.js.map +1 -1
  7. package/dist/cjs/components/ModalRoot/useModalStackHost.js +43 -5
  8. package/dist/cjs/components/ModalRoot/useModalStackHost.js.map +1 -1
  9. package/dist/esm/components/GlobalPortal/GlobalPortal.d.ts +6 -4
  10. package/dist/esm/components/GlobalPortal/GlobalPortal.d.ts.map +1 -1
  11. package/dist/esm/components/GlobalPortal/GlobalPortal.js +9 -4
  12. package/dist/esm/components/GlobalPortal/GlobalPortal.js.map +1 -1
  13. package/dist/esm/components/ModalRoot/ModalRoot.d.ts.map +1 -1
  14. package/dist/esm/components/ModalRoot/ModalRoot.js +5 -4
  15. package/dist/esm/components/ModalRoot/ModalRoot.js.map +1 -1
  16. package/dist/esm/components/ModalRoot/modalRootStack.d.ts +8 -4
  17. package/dist/esm/components/ModalRoot/modalRootStack.d.ts.map +1 -1
  18. package/dist/esm/components/ModalRoot/modalRootStack.js +15 -11
  19. package/dist/esm/components/ModalRoot/modalRootStack.js.map +1 -1
  20. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts +4 -2
  21. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts.map +1 -1
  22. package/dist/esm/components/ModalRoot/useModalStackHost.js +36 -5
  23. package/dist/esm/components/ModalRoot/useModalStackHost.js.map +1 -1
  24. package/dist/index.js +76 -25
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.min.js +1 -1
  27. package/dist/index.min.js.map +1 -1
  28. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","useForkRef","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","dialog","setDialog","dialogRef","setDialogNode","node","current","handleRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","finishClose","_dialogRef$current","undefined","close","showModal","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","document","body","querySelector","preventDefault","contains","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","activeElement","handleNativeClose","handlePointerDown","currentTarget","handleClick","_overlayRootRef$curre4","stopPropagation","handleExited","createElement","forwardProps","enabled","noIsolation","_extends","value","in","onExited","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { isTopModalRoot, popModalRoot, pushModalRoot } from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n const finishClose = useCallback(() => {\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n dialogRef.current?.close();\n setMounted(false);\n onClose?.();\n }, [onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(overlayRootRef.current);\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n }, [open, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n },\n [dialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (openRef.current && !dialog.open) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,cAAc,EAAEC,YAAY,EAAEC,aAAa,QAAQ,kBAAkB;AAC9E,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,OAAOC,UAAU,MAAM,wBAAwB;AA+B/C,OAAO,MAAMC,SAAS,gBAAGf,UAAU,CACjC,CAAAgB,IAAA,EAgBEC,GAAG,KACA;EAAA,I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AOxB,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEgE,EAAE,EAAE1E,IAAI;IAAE2E,QAAQ,EAAER;EAAa,CAAC,CAAC,GAC9CzD,QACmB,CAAC,eAC1B7B,KAAA,CAAAuF,aAAA;IAAKrE,GAAG,EAAEkC,cAAe;IAACtB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDd,SAAS,CAAC+E,WAAW,GAAG,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","useForkRef","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","dialog","setDialog","dialogRef","setDialogNode","node","current","handleRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","finishClose","_dialogRef$current","undefined","close","showModal","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","document","body","querySelector","preventDefault","contains","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","activeElement","handleNativeClose","handlePointerDown","currentTarget","handleClick","_overlayRootRef$curre4","stopPropagation","handleExited","createElement","forwardProps","enabled","noIsolation","_extends","value","in","onExited","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { isTopModalRoot, popModalRoot, pushModalRoot } from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n const finishClose = useCallback(() => {\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n dialogRef.current?.close();\n setMounted(false);\n onClose?.();\n }, [onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(overlayRootRef.current);\n }\n }, [open, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n },\n [dialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (openRef.current && !dialog.open) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO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AA,CAAAuF,aAAA,CAAC3E,eAAe,EAAA+E,QAAA,KACVzD,IAAI;IACRJ,SAAS,EAAEtB,UAAU,CAAC,cAAc,EAAEsB,SAAS,CAAE;IACjD,cAAYX,IAAI,GAAG,MAAM,GAAG,SAAU;IACtCY,aAAa,EAAEkD,iBAAkB;IACjCjD,OAAO,EAAEmD,WAAY;IACrBlD,SAAS,EAAE8B;EAAc,iBAEzB/D,KAAA,CAAAuF,aAAA,CAACzE,uBAAuB;IAAC8E,KAAK,EAAEvC;EAAe,GAC5C,OAAOxB,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEgE,EAAE,EAAE1E,IAAI;IAAE2E,QAAQ,EAAER;EAAa,CAAC,CAAC,GAC9CzD,QACmB,CAAC,eAC1B7B,KAAA,CAAAuF,aAAA;IAAKrE,GAAG,EAAEkC,cAAe;IAACtB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDd,SAAS,CAAC+E,WAAW,GAAG,WAAW","ignoreList":[]}
@@ -2,12 +2,16 @@ type Listener = () => void;
2
2
  export declare const pushModalRoot: (overlayRoot: HTMLElement | null) => number;
3
3
  export declare const popModalRoot: (id: number) => void;
4
4
  export declare const isTopModalRoot: (id: number) => boolean;
5
- /** The overlay root of the top open modal root, where content that must stay above every modal goes. */
6
- export declare const getTopModalOverlayRoot: () => HTMLElement | null;
5
+ /**
6
+ * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
7
+ * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into
8
+ * itself.
9
+ */
10
+ export declare const getTopModalOverlayRoot: (outside?: Node) => HTMLElement | null;
7
11
  /** The id of the top open modal root, or undefined when none is open. */
8
12
  export declare const getTopModalRootId: () => number | undefined;
9
- /** The overlay root of the top modal root among those opened no later than the given one. */
10
- export declare const getModalOverlayRootUpTo: (id: number) => HTMLElement | null;
13
+ /** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */
14
+ export declare const getModalOverlayRootUpTo: (id: number, outside?: Node) => HTMLElement | null;
11
15
  export declare const subscribeToModalRoots: (listener: Listener) => (() => void);
12
16
  export {};
13
17
  //# sourceMappingURL=modalRootStack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAc3B,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,GAAG,IAAI,KAAG,MAM/D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,IAOzC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,KAAG,OACR,CAAC;AAErC,wGAAwG;AACxG,eAAO,MAAM,sBAAsB,QAAO,WAAW,GAAG,IACV,CAAC;AAE/C,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,QAAO,MAAM,GAAG,SACjB,CAAC;AAE9B,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,KAAG,WAAW,GAAG,IAIlE,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,KAAG,CAAC,MAAM,IAAI,CAMrE,CAAC"}
1
+ {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAc3B,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,GAAG,IAAI,KAAG,MAM/D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,IAOzC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,KAAG,OACR,CAAC;AAKrC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,IAAI,KAAG,WAAW,GAAG,IACS,CAAC;AAEhF,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,QAAO,MAAM,GAAG,SACjB,CAAC;AAE9B,gHAAgH;AAChH,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,UAAU,IAAI,KACb,WAAW,GAAG,IAEQ,CAAC;AAE1B,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,KAAG,CAAC,MAAM,IAAI,CAMrE,CAAC"}
@@ -22,24 +22,28 @@ export const isTopModalRoot = id => {
22
22
  var _stack;
23
23
  return ((_stack = stack[stack.length - 1]) == null ? void 0 : _stack.id) === id;
24
24
  };
25
+ const isInside = (entry, outside) => !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);
25
26
 
26
- /** The overlay root of the top open modal root, where content that must stay above every modal goes. */
27
- export const getTopModalOverlayRoot = () => {
28
- var _stack$overlayRoot, _stack2;
29
- return (_stack$overlayRoot = (_stack2 = stack[stack.length - 1]) == null ? void 0 : _stack2.overlayRoot) != null ? _stack$overlayRoot : null;
27
+ /**
28
+ * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
29
+ * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into
30
+ * itself.
31
+ */
32
+ export const getTopModalOverlayRoot = outside => {
33
+ var _stack$filter$pop$ove, _stack$filter$pop;
34
+ return (_stack$filter$pop$ove = (_stack$filter$pop = stack.filter(entry => !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop.overlayRoot) != null ? _stack$filter$pop$ove : null;
30
35
  };
31
36
 
32
37
  /** The id of the top open modal root, or undefined when none is open. */
33
38
  export const getTopModalRootId = () => {
34
- var _stack3;
35
- return (_stack3 = stack[stack.length - 1]) == null ? void 0 : _stack3.id;
39
+ var _stack2;
40
+ return (_stack2 = stack[stack.length - 1]) == null ? void 0 : _stack2.id;
36
41
  };
37
42
 
38
- /** The overlay root of the top modal root among those opened no later than the given one. */
39
- export const getModalOverlayRootUpTo = id => {
40
- var _entries$overlayRoot, _entries;
41
- const entries = stack.filter(entry => entry.id <= id);
42
- return (_entries$overlayRoot = (_entries = entries[entries.length - 1]) == null ? void 0 : _entries.overlayRoot) != null ? _entries$overlayRoot : null;
43
+ /** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */
44
+ export const getModalOverlayRootUpTo = (id, outside) => {
45
+ var _stack$filter$pop$ove2, _stack$filter$pop2;
46
+ return (_stack$filter$pop$ove2 = (_stack$filter$pop2 = stack.filter(entry => entry.id <= id && !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop2.overlayRoot) != null ? _stack$filter$pop$ove2 : null;
43
47
  };
44
48
  export const subscribeToModalRoots = listener => {
45
49
  listeners.add(listener);
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","notify","forEach","listener","pushModalRoot","overlayRoot","id","popModalRoot","some","entry","filter","isTopModalRoot","_stack","length","getTopModalOverlayRoot","_stack$overlayRoot","_stack2","getTopModalRootId","_stack3","getModalOverlayRootUpTo","_entries$overlayRoot","_entries","entries","subscribeToModalRoots","add","delete"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nexport const pushModalRoot = (overlayRoot: HTMLElement | null): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot }];\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\nexport const isTopModalRoot = (id: number): boolean =>\n stack[stack.length - 1]?.id === id;\n\n/** The overlay root of the top open modal root, where content that must stay above every modal goes. */\nexport const getTopModalOverlayRoot = (): HTMLElement | null =>\n stack[stack.length - 1]?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n stack[stack.length - 1]?.id;\n\n/** The overlay root of the top modal root among those opened no later than the given one. */\nexport const getModalOverlayRootUpTo = (id: number): HTMLElement | null => {\n const entries = stack.filter((entry) => entry.id <= id);\n\n return entries[entries.length - 1]?.overlayRoot ?? null;\n};\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n"],"mappings":"AAOA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AAEd,MAAMC,MAAM,GAAGA,CAAA,KAAYJ,SAAS,CAACK,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAAC,CAAC,CAAC;AAEtE,OAAO,MAAMC,aAAa,GAAIC,WAA+B,IAAa;EACxEL,MAAM,IAAI,CAAC;EACXD,KAAK,GAAG,CAAC,GAAGA,KAAK,EAAE;IAAEO,EAAE,EAAEN,MAAM;IAAEK;EAAY,CAAC,CAAC;EAC/CJ,MAAM,CAAC,CAAC;EAER,OAAOD,MAAM;AACf,CAAC;AAED,OAAO,MAAMO,YAAY,GAAID,EAAU,IAAW;EAChD,IAAI,CAACP,KAAK,CAACS,IAAI,CAAEC,KAAK,IAAKA,KAAK,CAACH,EAAE,KAAKA,EAAE,CAAC,EAAE;IAC3C;EACF;EAEAP,KAAK,GAAGA,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,KAAKA,EAAE,CAAC;EAChDL,MAAM,CAAC,CAAC;AACV,CAAC;AAED,OAAO,MAAMU,cAAc,GAAIL,EAAU;EAAA,IAAAM,MAAA;EAAA,OACvC,EAAAA,MAAA,GAAAb,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBD,MAAA,CAAyBN,EAAE,MAAKA,EAAE;AAAA;;AAEpC;AACA,OAAO,MAAMQ,sBAAsB,GAAGA,CAAA;EAAA,IAAAC,kBAAA,EAAAC,OAAA;EAAA,QAAAD,kBAAA,IAAAC,OAAA,GACpCjB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBG,OAAA,CAAyBX,WAAW,YAAAU,kBAAA,GAAI,IAAI;AAAA;;AAE9C;AACA,OAAO,MAAME,iBAAiB,GAAGA,CAAA;EAAA,IAAAC,OAAA;EAAA,QAAAA,OAAA,GAC/BnB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBK,OAAA,CAAyBZ,EAAE;AAAA;;AAE7B;AACA,OAAO,MAAMa,uBAAuB,GAAIb,EAAU,IAAyB;EAAA,IAAAc,oBAAA,EAAAC,QAAA;EACzE,MAAMC,OAAO,GAAGvB,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,IAAIA,EAAE,CAAC;EAEvD,QAAAc,oBAAA,IAAAC,QAAA,GAAOC,OAAO,CAACA,OAAO,CAACT,MAAM,GAAG,CAAC,CAAC,qBAA3BQ,QAAA,CAA6BhB,WAAW,YAAAe,oBAAA,GAAI,IAAI;AACzD,CAAC;AAED,OAAO,MAAMG,qBAAqB,GAAIpB,QAAkB,IAAmB;EACzEN,SAAS,CAAC2B,GAAG,CAACrB,QAAQ,CAAC;EAEvB,OAAO,MAAY;IACjBN,SAAS,CAAC4B,MAAM,CAACtB,QAAQ,CAAC;EAC5B,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","notify","forEach","listener","pushModalRoot","overlayRoot","id","popModalRoot","some","entry","filter","isTopModalRoot","_stack","length","isInside","outside","contains","getTopModalOverlayRoot","_stack$filter$pop$ove","_stack$filter$pop","pop","getTopModalRootId","_stack2","getModalOverlayRootUpTo","_stack$filter$pop$ove2","_stack$filter$pop2","subscribeToModalRoots","add","delete"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nexport const pushModalRoot = (overlayRoot: HTMLElement | null): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot }];\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\nexport const isTopModalRoot = (id: number): boolean =>\n stack[stack.length - 1]?.id === id;\n\nconst isInside = (entry: Entry, outside?: Node) =>\n !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);\n\n/**\n * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root\n * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into\n * itself.\n */\nexport const getTopModalOverlayRoot = (outside?: Node): HTMLElement | null =>\n stack.filter((entry) => !isInside(entry, outside)).pop()?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n stack[stack.length - 1]?.id;\n\n/** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */\nexport const getModalOverlayRootUpTo = (\n id: number,\n outside?: Node\n): HTMLElement | null =>\n stack.filter((entry) => entry.id <= id && !isInside(entry, outside)).pop()\n ?.overlayRoot ?? null;\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n"],"mappings":"AAOA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AAEd,MAAMC,MAAM,GAAGA,CAAA,KAAYJ,SAAS,CAACK,OAAO,CAAEC,QAAQ,IAAKA,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AAO,MAAMG,iBAAiB,GAAGA,CAAA;EAAA,IAAAC,OAAA;EAAA,QAAAA,OAAA,GAC/BvB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBS,OAAA,CAAyBhB,EAAE;AAAA;;AAE7B;AACA,OAAO,MAAMiB,uBAAuB,GAAGA,CACrCjB,EAAU,EACVS,OAAc;EAAA,IAAAS,sBAAA,EAAAC,kBAAA;EAAA,QAAAD,sBAAA,IAAAC,kBAAA,GAEd1B,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,IAAIA,EAAE,IAAI,CAACQ,QAAQ,CAACL,KAAK,EAAEM,OAAO,CAAC,CAAC,CAACK,GAAG,CAAC,CAAC,qBAA1EK,kBAAA,CACIpB,WAAW,YAAAmB,sBAAA,GAAI,IAAI;AAAA;AAEzB,OAAO,MAAME,qBAAqB,GAAIvB,QAAkB,IAAmB;EACzEN,SAAS,CAAC8B,GAAG,CAACxB,QAAQ,CAAC;EAEvB,OAAO,MAAY;IACjBN,SAAS,CAAC+B,MAAM,CAACzB,QAAQ,CAAC;EAC5B,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
3
- * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content
4
- * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the
3
+ * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
4
+ * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
5
+ * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
6
+ * when the host changes. Returns whether the
5
7
  * host is in the page, which it is from a layout effect after the first render with it.
6
8
  */
7
9
  export declare const useModalStackHost: (host: HTMLElement | null, upToModalRootId?: number) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OA+BF,CAAC"}
1
+ {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AA8CA;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OA+BF,CAAC"}
@@ -1,10 +1,41 @@
1
1
  import { useLayoutEffect, useState } from "react";
2
2
  import { getModalOverlayRootUpTo, getTopModalOverlayRoot, subscribeToModalRoots } from "./modalRootStack";
3
+ const getScrollPositions = host => Array.from(host.querySelectorAll("*")).filter(element => element.scrollTop || element.scrollLeft).map(element => ({
4
+ element,
5
+ top: element.scrollTop,
6
+ left: element.scrollLeft
7
+ }));
8
+
9
+ /**
10
+ * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops
11
+ * the focus, so without moveBefore they are put back after the move.
12
+ */
13
+ const moveHost = (host, target) => {
14
+ if (host.isConnected && target.moveBefore) {
15
+ target.moveBefore(host, null);
16
+ return;
17
+ }
18
+ const scrollPositions = host.isConnected ? getScrollPositions(host) : [];
19
+ const focused = host.contains(document.activeElement) ? document.activeElement : null;
20
+ target.appendChild(host);
21
+ scrollPositions.forEach(_ref => {
22
+ let element = _ref.element,
23
+ top = _ref.top,
24
+ left = _ref.left;
25
+ element.scrollTop = top;
26
+ element.scrollLeft = left;
27
+ });
28
+ focused == null || focused.focus({
29
+ preventScroll: true
30
+ });
31
+ };
3
32
 
4
33
  /**
5
34
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
6
- * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content
7
- * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the
35
+ * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
36
+ * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
37
+ * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
38
+ * when the host changes. Returns whether the
8
39
  * host is in the page, which it is from a layout effect after the first render with it.
9
40
  */
10
41
  export const useModalStackHost = (host, upToModalRootId) => {
@@ -16,10 +47,10 @@ export const useModalStackHost = (host, upToModalRootId) => {
16
47
  return undefined;
17
48
  }
18
49
  const place = () => {
19
- var _ref;
20
- const target = (_ref = upToModalRootId === undefined ? getTopModalOverlayRoot() : getModalOverlayRootUpTo(upToModalRootId)) != null ? _ref : document.body;
50
+ var _ref2;
51
+ const target = (_ref2 = upToModalRootId === undefined ? getTopModalOverlayRoot(host) : getModalOverlayRootUpTo(upToModalRootId, host)) != null ? _ref2 : document.body;
21
52
  if (host.parentElement !== target) {
22
- target.appendChild(host);
53
+ moveHost(host, target);
23
54
  }
24
55
  };
25
56
  place();
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","subscribeToModalRoots","useModalStackHost","host","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref","target","document","body","parentElement","appendChild","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content\n * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot()\n : getModalOverlayRootUpTo(upToModalRootId)) ?? document.body;\n\n if (host.parentElement !== target) {\n target.appendChild(host);\n }\n };\n\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,qBAAqB,QAChB,kBAAkB;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAGA,CAC/BC,IAAwB,EACxBC,eAAwB,KACZ;EACZ,MAAAC,SAAA,GAAoCP,QAAQ,CAAqB,IAAI,CAAC;IAA/DQ,UAAU,GAAAD,SAAA;IAAEE,aAAa,GAAAF,SAAA;EAEhCR,eAAe,CAAC,MAAM;IACpB,IAAI,CAACM,IAAI,EAAE;MACT,OAAOK,SAAS;IAClB;IAEA,MAAMC,KAAK,GAAGA,CAAA,KAAM;MAAA,IAAAC,IAAA;MAClB,MAAMC,MAAM,IAAAD,IAAA,GACTN,eAAe,KAAKI,SAAS,GAC1BR,sBAAsB,CAAC,CAAC,GACxBD,uBAAuB,CAACK,eAAe,CAAC,YAAAM,IAAA,GAAKE,QAAQ,CAACC,IAAI;MAEhE,IAAIV,IAAI,CAACW,aAAa,KAAKH,MAAM,EAAE;QACjCA,MAAM,CAACI,WAAW,CAACZ,IAAI,CAAC;MAC1B;IACF,CAAC;IAEDM,KAAK,CAAC,CAAC;IACPF,aAAa,CAACJ,IAAI,CAAC;IAEnB,MAAMa,WAAW,GAAGf,qBAAqB,CAACQ,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXO,WAAW,CAAC,CAAC;MACbb,IAAI,CAACc,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACd,IAAI,EAAEC,eAAe,CAAC,CAAC;EAE3B,OAAOD,IAAI,KAAK,IAAI,IAAIG,UAAU,KAAKH,IAAI;AAC7C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","subscribeToModalRoots","getScrollPositions","host","Array","from","querySelectorAll","filter","element","scrollTop","scrollLeft","map","top","left","moveHost","target","isConnected","moveBefore","scrollPositions","focused","contains","document","activeElement","appendChild","forEach","_ref","focus","preventScroll","useModalStackHost","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref2","body","parentElement","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\ntype MovableParent = HTMLElement & {\n moveBefore?: (node: Node, child: Node | null) => void;\n};\n\nconst getScrollPositions = (host: HTMLElement) =>\n Array.from(host.querySelectorAll<HTMLElement>(\"*\"))\n .filter((element) => element.scrollTop || element.scrollLeft)\n .map((element) => ({\n element,\n top: element.scrollTop,\n left: element.scrollLeft,\n }));\n\n/**\n * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops\n * the focus, so without moveBefore they are put back after the move.\n */\nconst moveHost = (host: HTMLElement, target: MovableParent) => {\n if (host.isConnected && target.moveBefore) {\n target.moveBefore(host, null);\n\n return;\n }\n\n const scrollPositions = host.isConnected ? getScrollPositions(host) : [];\n const focused = host.contains(document.activeElement)\n ? (document.activeElement as HTMLElement)\n : null;\n\n target.appendChild(host);\n\n scrollPositions.forEach(({ element, top, left }) => {\n element.scrollTop = top;\n element.scrollLeft = left;\n });\n focused?.focus({ preventScroll: true });\n};\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not\n * counted, since its overlay root is inside the host. The node moves as modals open and close, so content\n * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or\n * when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot(host)\n : getModalOverlayRootUpTo(upToModalRootId, host)) ?? document.body;\n\n if (host.parentElement !== target) {\n moveHost(host, target);\n }\n };\n\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,qBAAqB,QAChB,kBAAkB;AAMzB,MAAMC,kBAAkB,GAAIC,IAAiB,IAC3CC,KAAK,CAACC,IAAI,CAACF,IAAI,CAACG,gBAAgB,CAAc,GAAG,CAAC,CAAC,CAChDC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,IAAID,OAAO,CAACE,UAAU,CAAC,CAC5DC,GAAG,CAAEH,OAAO,KAAM;EACjBA,OAAO;EACPI,GAAG,EAAEJ,OAAO,CAACC,SAAS;EACtBI,IAAI,EAAEL,OAAO,CAACE;AAChB,CAAC,CAAC,CAAC;;AAEP;AACA;AACA;AACA;AACA,MAAMI,QAAQ,GAAGA,CAACX,IAAiB,EAAEY,MAAqB,KAAK;EAC7D,IAAIZ,IAAI,CAACa,WAAW,IAAID,MAAM,CAACE,UAAU,EAAE;IACzCF,MAAM,CAACE,UAAU,CAACd,IAAI,EAAE,IAAI,CAAC;IAE7B;EACF;EAEA,MAAMe,eAAe,G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AI,EAAEY,MAAM,CAAC;MACxB;IACF,CAAC;IAEDmB,KAAK,CAAC,CAAC;IACPF,aAAa,CAAC7B,IAAI,CAAC;IAEnB,MAAMmC,WAAW,GAAGrC,qBAAqB,CAACiC,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXI,WAAW,CAAC,CAAC;MACbnC,IAAI,CAACoC,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACpC,IAAI,EAAE0B,eAAe,CAAC,CAAC;EAE3B,OAAO1B,IAAI,KAAK,IAAI,IAAI4B,UAAU,KAAK5B,IAAI;AAC7C,CAAC","ignoreList":[]}
package/dist/index.js CHANGED
@@ -19125,26 +19125,34 @@
19125
19125
  var _stack;
19126
19126
  return ((_stack = stack[stack.length - 1]) === null || _stack === void 0 ? void 0 : _stack.id) === id;
19127
19127
  };
19128
+ var isInside = function isInside(entry, outside) {
19129
+ return !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);
19130
+ };
19128
19131
 
19129
- /** The overlay root of the top open modal root, where content that must stay above every modal goes. */
19130
- var getTopModalOverlayRoot = function getTopModalOverlayRoot() {
19131
- var _stack$overlayRoot, _stack2;
19132
- return (_stack$overlayRoot = (_stack2 = stack[stack.length - 1]) === null || _stack2 === void 0 ? void 0 : _stack2.overlayRoot) !== null && _stack$overlayRoot !== void 0 ? _stack$overlayRoot : null;
19132
+ /**
19133
+ * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
19134
+ * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into
19135
+ * itself.
19136
+ */
19137
+ var getTopModalOverlayRoot = function getTopModalOverlayRoot(outside) {
19138
+ var _stack$filter$pop$ove, _stack$filter$pop;
19139
+ return (_stack$filter$pop$ove = (_stack$filter$pop = stack.filter(function (entry) {
19140
+ return !isInside(entry, outside);
19141
+ }).pop()) === null || _stack$filter$pop === void 0 ? void 0 : _stack$filter$pop.overlayRoot) !== null && _stack$filter$pop$ove !== void 0 ? _stack$filter$pop$ove : null;
19133
19142
  };
19134
19143
 
19135
19144
  /** The id of the top open modal root, or undefined when none is open. */
19136
19145
  var getTopModalRootId = function getTopModalRootId() {
19137
- var _stack3;
19138
- return (_stack3 = stack[stack.length - 1]) === null || _stack3 === void 0 ? void 0 : _stack3.id;
19146
+ var _stack2;
19147
+ return (_stack2 = stack[stack.length - 1]) === null || _stack2 === void 0 ? void 0 : _stack2.id;
19139
19148
  };
19140
19149
 
19141
- /** The overlay root of the top modal root among those opened no later than the given one. */
19142
- var getModalOverlayRootUpTo = function getModalOverlayRootUpTo(id) {
19143
- var _entries$overlayRoot, _entries;
19144
- var entries = stack.filter(function (entry) {
19145
- return entry.id <= id;
19146
- });
19147
- return (_entries$overlayRoot = (_entries = entries[entries.length - 1]) === null || _entries === void 0 ? void 0 : _entries.overlayRoot) !== null && _entries$overlayRoot !== void 0 ? _entries$overlayRoot : null;
19150
+ /** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */
19151
+ var getModalOverlayRootUpTo = function getModalOverlayRootUpTo(id, outside) {
19152
+ var _stack$filter$pop$ove2, _stack$filter$pop2;
19153
+ return (_stack$filter$pop$ove2 = (_stack$filter$pop2 = stack.filter(function (entry) {
19154
+ return entry.id <= id && !isInside(entry, outside);
19155
+ }).pop()) === null || _stack$filter$pop2 === void 0 ? void 0 : _stack$filter$pop2.overlayRoot) !== null && _stack$filter$pop$ove2 !== void 0 ? _stack$filter$pop$ove2 : null;
19148
19156
  };
19149
19157
  var subscribeToModalRoots = function subscribeToModalRoots(listener) {
19150
19158
  listeners.add(listener);
@@ -19221,17 +19229,18 @@
19221
19229
  }, [onClose]);
19222
19230
 
19223
19231
  // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the
19224
- // same node, gets it back.
19232
+ // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it
19233
+ // is rendered and can get its scroll positions back.
19225
19234
  React.useLayoutEffect(function () {
19226
19235
  if (!open || !dialog) {
19227
19236
  return;
19228
19237
  }
19229
- if (stackIdRef.current === undefined) {
19230
- stackIdRef.current = pushModalRoot(overlayRootRef.current);
19231
- }
19232
19238
  if (!dialog.open) {
19233
19239
  dialog.showModal();
19234
19240
  }
19241
+ if (stackIdRef.current === undefined) {
19242
+ stackIdRef.current = pushModalRoot(overlayRootRef.current);
19243
+ }
19235
19244
  }, [open, dialog]);
19236
19245
 
19237
19246
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
@@ -28586,10 +28595,48 @@
28586
28595
  })(["@media (min-width:640px){display:none;}"]);
28587
28596
  StyledHeader$2.displayName = "StyledHeader";
28588
28597
 
28598
+ var getScrollPositions = function getScrollPositions(host) {
28599
+ return Array.from(host.querySelectorAll("*")).filter(function (element) {
28600
+ return element.scrollTop || element.scrollLeft;
28601
+ }).map(function (element) {
28602
+ return {
28603
+ element,
28604
+ top: element.scrollTop,
28605
+ left: element.scrollLeft
28606
+ };
28607
+ });
28608
+ };
28609
+
28610
+ /**
28611
+ * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops
28612
+ * the focus, so without moveBefore they are put back after the move.
28613
+ */
28614
+ var moveHost = function moveHost(host, target) {
28615
+ if (host.isConnected && target.moveBefore) {
28616
+ target.moveBefore(host, null);
28617
+ return;
28618
+ }
28619
+ var scrollPositions = host.isConnected ? getScrollPositions(host) : [];
28620
+ var focused = host.contains(document.activeElement) ? document.activeElement : null;
28621
+ target.appendChild(host);
28622
+ scrollPositions.forEach(function (_ref) {
28623
+ var element = _ref.element,
28624
+ top = _ref.top,
28625
+ left = _ref.left;
28626
+ element.scrollTop = top;
28627
+ element.scrollLeft = left;
28628
+ });
28629
+ focused === null || focused === void 0 || focused.focus({
28630
+ preventScroll: true
28631
+ });
28632
+ };
28633
+
28589
28634
  /**
28590
28635
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
28591
- * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content
28592
- * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the
28636
+ * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
28637
+ * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
28638
+ * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
28639
+ * when the host changes. Returns whether the
28593
28640
  * host is in the page, which it is from a layout effect after the first render with it.
28594
28641
  */
28595
28642
  var useModalStackHost = function useModalStackHost(host, upToModalRootId) {
@@ -28602,10 +28649,10 @@
28602
28649
  return undefined;
28603
28650
  }
28604
28651
  var place = function place() {
28605
- var _ref;
28606
- var target = (_ref = upToModalRootId === undefined ? getTopModalOverlayRoot() : getModalOverlayRootUpTo(upToModalRootId)) !== null && _ref !== void 0 ? _ref : document.body;
28652
+ var _ref2;
28653
+ var target = (_ref2 = upToModalRootId === undefined ? getTopModalOverlayRoot(host) : getModalOverlayRootUpTo(upToModalRootId, host)) !== null && _ref2 !== void 0 ? _ref2 : document.body;
28607
28654
  if (host.parentElement !== target) {
28608
- target.appendChild(host);
28655
+ moveHost(host, target);
28609
28656
  }
28610
28657
  };
28611
28658
  place();
@@ -32296,9 +32343,11 @@
32296
32343
  };
32297
32344
 
32298
32345
  /**
32299
- * Renders content that must stay above every modal, such as toasts. Everything outside an open native modal is inert,
32300
- * so the content follows the top open modal into its overlay root and comes back to document.body once none is open.
32346
+ * Renders content that must stay above every modal, such as toasts, a chat or a feedback prompt. Everything outside
32347
+ * an open native modal is inert, so the content follows the top open modal into its overlay root and comes back to
32348
+ * document.body once none is open.
32301
32349
  * The host node moves instead of the content being portalled again, so the content never remounts on the way.
32350
+ * Portals from the content, such as a menu or a tooltip, render into the host too, so they move along with it.
32302
32351
  * The host is attached in a layout effect after the content mounts, so content that measures itself on mount reads
32303
32352
  * no size there, and a transition that runs while the host moves restarts.
32304
32353
  */
@@ -32308,7 +32357,9 @@
32308
32357
  _useState2 = _slicedToArray(_useState, 1),
32309
32358
  host = _useState2[0];
32310
32359
  useModalStackHost(host);
32311
- return /*#__PURE__*/ReactDOM__default["default"].createPortal(children, host);
32360
+ return /*#__PURE__*/ReactDOM__default["default"].createPortal(/*#__PURE__*/React__default["default"].createElement(PortalContainerProvider, {
32361
+ value: host
32362
+ }, children), host);
32312
32363
  };
32313
32364
  GlobalPortal.displayName = "GlobalPortal";
32314
32365