diff --git a/app/components/Lightbox.tsx b/app/components/Lightbox.tsx index fa4b9bdbc3..9618f13e39 100644 --- a/app/components/Lightbox.tsx +++ b/app/components/Lightbox.tsx @@ -64,6 +64,7 @@ import { HStack } from "./primitives/HStack"; import { useDocumentContext } from "./DocumentContext"; import LightboxComments from "~/scenes/Document/components/Comments/LightboxComments"; import { PortalContext } from "./Portal"; +import useHideElement from "~/hooks/useHideElement"; export enum LightboxStatus { READY_TO_OPEN, @@ -361,6 +362,15 @@ function Lightbox({ images, activeImage, onUpdate, onClose, readOnly }: Props) { } }, [status.image]); + // Hide the inline image in the editor while the lightbox zoom transition is + // active, otherwise a duplicate is visible behind the fading overlay. + useHideElement( + activeImage.getElement(), + status.lightbox !== null && + status.lightbox !== LightboxStatus.READY_TO_OPEN && + status.lightbox !== LightboxStatus.CLOSED + ); + const rememberImagePosition = () => { if (imgRef.current) { const lightboxImgDOMRect = imgRef.current.getBoundingClientRect(); diff --git a/app/hooks/useHideElement.ts b/app/hooks/useHideElement.ts new file mode 100644 index 0000000000..7002df3179 --- /dev/null +++ b/app/hooks/useHideElement.ts @@ -0,0 +1,29 @@ +import { useLayoutEffect } from "react"; + +/** + * Temporarily hides a DOM element while `enabled` is true, restoring its + * previous visibility when disabled or unmounted. Useful for shared-element + * transitions where an element should be hidden so it isn't visible behind the + * animating clone. + * + * @param element The element to hide. + * @param enabled Whether the element should currently be hidden. + */ +export default function useHideElement( + element: Element | null | undefined, + enabled: boolean +) { + useLayoutEffect(() => { + if ( + !enabled || + (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) + ) { + return; + } + const previousVisibility = element.style.visibility; + element.style.visibility = "hidden"; + return () => { + element.style.visibility = previousVisibility; + }; + }, [element, enabled]); +} diff --git a/shared/editor/components/Image.tsx b/shared/editor/components/Image.tsx index 557e9008b8..faff4f7fb9 100644 --- a/shared/editor/components/Image.tsx +++ b/shared/editor/components/Image.tsx @@ -114,6 +114,37 @@ const Image = (props: Props) => { } }; + const actions = [ + isExternalUrl(src) && ( + + ), + imgLink && ( + + ), + !isEditable && ( + + ), + ].filter(Boolean); + return (
{ } style={widthStyle} > - {!dragging && width > 60 && isDownloadable && ( + {!dragging && width > 60 && isDownloadable && actions.length > 0 && ( - {isExternalUrl(src) && ( - <> - - - - )} - {imgLink && ( - <> - - - - )} - + {actions.map((action, index) => ( + + {index > 0 && } + {action} + + ))} )} {error ? (