Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channel): copy and download on hover for inline images (#7385)
Peter Chinman1b51727cad95
diff --git a/apps/web/src/features/block-canvas/views/canvas-view.tsx b/apps/web/src/features/block-canvas/views/canvas-view.tsxindex 89740c0de3..fa218118ab 100644--- a/apps/web/src/features/block-canvas/views/canvas-view.tsx+++ b/apps/web/src/features/block-canvas/views/canvas-view.tsx@@ -1,5 +1,5 @@import { useSidePanel } from '@components/app/side-panel';-import { createImageActions } from '@core/component/Lightbox/createImageActions';+import { createImageActions } from '@core/component/ImageActions';import { fireAndForget } from '@core/util/fireAndForget';import Copy from '@icon/system/regular/copy.svg';import DownloadSimple from '@icon/system/regular/download-simple.svg';diff --git a/apps/web/src/features/channel/Media/MediaGrid.tsx b/apps/web/src/features/channel/Media/MediaGrid.tsxindex cca902591c..a7144397e7 100644--- a/apps/web/src/features/channel/Media/MediaGrid.tsx+++ b/apps/web/src/features/channel/Media/MediaGrid.tsx@@ -1,4 +1,5 @@import { FileDownloadButton } from '@core/component/FileDownload';+import { isTouchDevice } from '@core/mobile/isTouchDevice';import { createFileDownload } from '@core/util/createFileDownload';import ExpandIcon from '@icon/system/regular/arrows-out-simple.svg';import { constrainImageDimensions } from '@macro-inc/lexical-core/utils/media';@@ -6,6 +7,7 @@ import { Button, cn } from '@ui';import { createMemo, createSignal, For, Match, Show, Switch } from 'solid-js';import { mediaDownloadSource } from '../queries/static-media-download';import { MediaImage } from './MediaImage';+import { MediaImageActions } from './MediaImageActions';import { MediaVideo } from './MediaVideo';import type { MediaItem } from './media-items';@@ -31,36 +33,43 @@ function MessageImageTile(props: {);return (- <button- type="button"- class="relative flex rounded-2xl border border-edge"- style={{- width: dimensions() ? `${dimensions()!.width}px` : undefined,- 'max-width': '100%',- }}- onClick={props.onOpen}- aria-label="Open image viewer"- >- <MediaImage.Image- src={props.item.src}- previewSrc={props.item.previewSrc}- class="max-h-[80vh] w-full select-none rounded-2xl object-contain"- width={dimensions()?.width ?? props.item.width ?? undefined}- height={dimensions()?.height ?? props.item.height ?? undefined}- fallback={<MediaImage.Fallback fill={!!dimensions()} />}- onError={props.onError}+ // The button keeps the tile's size and frame; this wrapper only positions+ // the toolbar beside it, since a button can't contain buttons.+ <div class="group/media relative flex max-w-full">+ <button+ type="button"+ class="relative flex rounded-2xl border border-edge"style={{- ...(dimensions()- ? {- 'aspect-ratio': `${dimensions()!.width} / ${dimensions()!.height}`,- 'max-width': `${dimensions()!.width}px`,- }- : {- 'max-width': `${props.large ? SINGLE_IMAGE_MAX_WIDTH : MESSAGE_GALLERY_IMAGE_MAX_WIDTH}px`,- }),+ width: dimensions() ? `${dimensions()!.width}px` : undefined,+ 'max-width': '100%',}}- />- </button>+ onClick={props.onOpen}+ aria-label="Open image viewer"+ >+ <MediaImage.Image+ src={props.item.src}+ previewSrc={props.item.previewSrc}+ class="max-h-[80vh] w-full select-none rounded-2xl object-contain"+ width={dimensions()?.width ?? props.item.width ?? undefined}+ height={dimensions()?.height ?? props.item.height ?? undefined}+ fallback={<MediaImage.Fallback fill={!!dimensions()} />}+ onError={props.onError}+ style={{+ ...(dimensions()+ ? {+ 'aspect-ratio': `${dimensions()!.width} / ${dimensions()!.height}`,+ 'max-width': `${dimensions()!.width}px`,+ }+ : {+ 'max-width': `${props.large ? SINGLE_IMAGE_MAX_WIDTH : MESSAGE_GALLERY_IMAGE_MAX_WIDTH}px`,+ }),+ }}+ />+ </button>+ <Show when={!isTouchDevice()}>+ <MediaImageActions item={props.item} />+ </Show>+ </div>);}diff --git a/apps/web/src/features/channel/Media/MediaImageActions.tsx b/apps/web/src/features/channel/Media/MediaImageActions.tsxnew file mode 100644index 0000000000..6733505431--- /dev/null+++ b/apps/web/src/features/channel/Media/MediaImageActions.tsx@@ -0,0 +1,34 @@+import {+ createImageActions,+ ImageActionButtons,+} from '@core/component/ImageActions';+import { cn } from '@ui';+import type { MediaItem } from './media-items';++/**+ * Copy / download affordances for an image rendered inline in a message,+ * mirroring the lightbox toolbar and styled like the inline video toolbar.+ * Call sites render this inside a `group/media` positioned container.+ *+ * Only mount this for pointer devices: `createImageActions` pre-fetches the+ * full-resolution blob on iOS, which would mean downloading every inline image+ * in the channel at full size.+ */+export function MediaImageActions(props: { item: MediaItem }) {+ const actions = createImageActions({+ src: () => props.item.fullSrc,+ imageId: () => props.item.id,+ });++ return (+ <div+ class={cn(+ 'absolute right-2 top-2 z-10 flex items-center rounded-full bg-surface/90 opacity-0 transition-opacity group-hover/media:opacity-100 group-focus-within/media:opacity-100',+ actions.isBusy() && 'opacity-100'+ )}+ onClick={(event) => event.stopPropagation()}+ >+ <ImageActionButtons actions={actions} />+ </div>+ );+}diff --git a/apps/web/src/features/channel/Media/tests/media-grid.test.tsx b/apps/web/src/features/channel/Media/tests/media-grid.test.tsxnew file mode 100644index 0000000000..2447bcac85--- /dev/null+++ b/apps/web/src/features/channel/Media/tests/media-grid.test.tsx@@ -0,0 +1,74 @@+import { cleanup, render, screen } from '@solidjs/testing-library';+import userEvent from '@testing-library/user-event';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+import { MediaGrid } from '../MediaGrid';+import type { MediaItem } from '../media-items';++const isTouchDevice = vi.hoisted(() => vi.fn(() => false));+const imageActions = vi.hoisted(() => ({+ copyImageToClipboard: vi.fn(+ async (+ _getBlob: () => Promise<Blob | undefined>,+ _fallbackUrl: string+ ) => {}+ ),+ downloadImage: vi.fn(+ async (_getBlob: () => Promise<Blob | undefined>, _imageId: string) => {}+ ),+}));++vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice }));+vi.mock('@core/util/imageActions', () => imageActions);+vi.mock('@core/util/platformFetch', () => ({+ platformFetch: async () => new Response(new Blob()),+}));++const imageItem: MediaItem = {+ id: 'img-1',+ src: 'https://example.test/medium/img-1',+ fullSrc: 'https://example.test/full/img-1',+ kind: 'image',+ width: 800,+ height: 600,+};++beforeEach(() => {+ isTouchDevice.mockReturnValue(false);+ imageActions.copyImageToClipboard.mockClear();+ imageActions.downloadImage.mockClear();+});+afterEach(cleanup);++it('offers copy and download on an inline message image', async () => {+ render(() => (+ <MediaGrid items={[imageItem]} variant="message" onOpen={() => {}} />+ ));++ await userEvent.click(screen.getByRole('button', { name: 'Copy image' }));+ expect(imageActions.copyImageToClipboard).toHaveBeenCalledOnce();++ await userEvent.click(screen.getByRole('button', { name: 'Download image' }));+ expect(imageActions.downloadImage.mock.calls[0]?.[1]).toBe('img-1');+});++it('keeps the image itself clickable alongside the hover actions', async () => {+ const onOpen = vi.fn();+ render(() => (+ <MediaGrid items={[imageItem]} variant="message" onOpen={onOpen} />+ ));++ await userEvent.click(+ screen.getByRole('button', { name: 'Open image viewer' })+ );+ expect(onOpen).toHaveBeenCalledWith(0);+});++it('omits the hover actions on touch devices, where the viewer provides them', () => {+ isTouchDevice.mockReturnValue(true);+ render(() => (+ <MediaGrid items={[imageItem]} variant="message" onOpen={() => {}} />+ ));++ expect(screen.queryByRole('button', { name: 'Copy image' })).toBeNull();+ expect(screen.queryByRole('button', { name: 'Download image' })).toBeNull();+});diff --git a/apps/web/src/lib/core/component/ImageActions/ImageActionButtons.tsx b/apps/web/src/lib/core/component/ImageActions/ImageActionButtons.tsxnew file mode 100644index 0000000000..77ec8cc210--- /dev/null+++ b/apps/web/src/lib/core/component/ImageActions/ImageActionButtons.tsx@@ -0,0 +1,48 @@+import Spinner from '@icon/system/bold/spinner-gap-bold.svg?component-solid';+import ClipboardIcon from '@icon/system/regular/clipboard.svg';+import DownloadIcon from '@icon/system/regular/download-simple.svg';+import { Button } from '@ui';+import type { createImageActions } from './createImageActions';++type ImageActionButtonsProps = {+ actions: ReturnType<typeof createImageActions>;+};++/** Copy + download buttons for a single image, driven by `createImageActions`. */+export function ImageActionButtons(props: ImageActionButtonsProps) {+ const disabled = () =>+ props.actions.isBusy() || props.actions.isPrefetching();++ return (+ <>+ <Button+ aria-label="Copy image"+ tooltip="Copy image"+ variant="ghost"+ size="icon-md"+ onClick={() => props.actions.copyToClipboard()}+ disabled={disabled()}+ >+ {props.actions.isCopying() ? (+ <Spinner class="size-4 touch:size-6 shrink-0 pointer-events-none animate-spin" />+ ) : (+ <ClipboardIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />+ )}+ </Button>+ <Button+ aria-label="Download image"+ tooltip="Download image"+ variant="ghost"+ size="icon-md"+ onClick={() => props.actions.downloadImage()}+ disabled={disabled()}+ >+ {props.actions.isDownloading() ? (+ <Spinner class="size-4 touch:size-6 shrink-0 pointer-events-none animate-spin" />+ ) : (+ <DownloadIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />+ )}+ </Button>+ </>+ );+}diff --git a/apps/web/src/lib/core/component/Lightbox/createImageActions.test.ts b/apps/web/src/lib/core/component/ImageActions/createImageActions.test.tssimilarity index 100%rename from apps/web/src/lib/core/component/Lightbox/createImageActions.test.tsrename to apps/web/src/lib/core/component/ImageActions/createImageActions.test.tsdiff --git a/apps/web/src/lib/core/component/Lightbox/createImageActions.ts b/apps/web/src/lib/core/component/ImageActions/createImageActions.tssimilarity index 100%rename from apps/web/src/lib/core/component/Lightbox/createImageActions.tsrename to apps/web/src/lib/core/component/ImageActions/createImageActions.tsdiff --git a/apps/web/src/lib/core/component/ImageActions/index.ts b/apps/web/src/lib/core/component/ImageActions/index.tsnew file mode 100644index 0000000000..6996f4f420--- /dev/null+++ b/apps/web/src/lib/core/component/ImageActions/index.ts@@ -0,0 +1,2 @@+export { createImageActions } from './createImageActions';+export { ImageActionButtons } from './ImageActionButtons';diff --git a/apps/web/src/lib/core/component/Lightbox/Lightbox.tsx b/apps/web/src/lib/core/component/Lightbox/Lightbox.tsxindex 78414e7ec3..7082505364 100644--- a/apps/web/src/lib/core/component/Lightbox/Lightbox.tsx+++ b/apps/web/src/lib/core/component/Lightbox/Lightbox.tsx@@ -1,12 +1,13 @@+import {+ createImageActions,+ ImageActionButtons,+} from '@core/component/ImageActions';import Spinner from '@icon/system/bold/spinner-gap-bold.svg?component-solid';-import ClipboardIcon from '@icon/system/regular/clipboard.svg';-import DownloadIcon from '@icon/system/regular/download-simple.svg';import XIcon from '@icon/system/regular/x.svg';import { Dialog, useDialogContext } from '@kobalte/core/dialog';import { Button, cn } from '@ui';import {type Accessor,- type Component,createEffect,createSignal,type JSX,@@ -15,22 +16,11 @@ import {} from 'solid-js';import { Zoompinch, type ZoompinchHandle } from '../Zoompinch';import { createGestures } from './createGestures';-import { createImageActions } from './createImageActions';import { createMomentum } from './createMomentum';import { createZoomModel } from './createZoomModel';import { LightboxChrome } from './LightboxChrome';import { LightboxToolbar } from './LightboxToolbar';-const SpinnerIcon: Component<JSX.SvgSVGAttributes<SVGSVGElement>> = (p) => (- <Spinner- {...p}- class={cn(- 'size-4 touch:size-6 shrink-0 pointer-events-none animate-spin',- p.class- )}- />-);-type LightboxProps = {// Current image to displaysrc: Accessor<string | undefined>;@@ -94,34 +84,7 @@ export function Lightbox(props: LightboxProps) {class="flex items-center justify-center bg-surface rounded-md overflow-hidden"><LightboxToolbar isVisible={true}>- <Button- aria-label="Copy image"- tooltip="Copy image"- variant="ghost"- size="icon-md"- onClick={images.copyToClipboard}- disabled={images.isBusy() || images.isPrefetching()}- >- {images.isCopying() ? (- <SpinnerIcon />- ) : (- <ClipboardIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />- )}- </Button>- <Button- aria-label="Download image"- tooltip="Download image"- variant="ghost"- size="icon-md"- onClick={images.downloadImage}- disabled={images.isBusy() || images.isPrefetching()}- >- {images.isDownloading() ? (- <SpinnerIcon />- ) : (- <DownloadIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />- )}- </Button>+ <ImageActionButtons actions={images} /><Dialog.CloseButtonaria-label="Close"tooltip="Close"diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.mdindex 7d5d18ed1a..d13a662c36 100644--- a/docs/agent-guide/channels.md+++ b/docs/agent-guide/channels.md@@ -338,6 +338,19 @@ button that copies the whole section; a call that failed is faded, shows theerror as its subtitle, and adds an `Error` section. Rows for a call still runningshow whatever has arrived so far.+## Inline image actions++An image attached to a channel message renders inline. Hovering it, or focusing+it with the keyboard, reveals a small toolbar at its top right with+`Copy image` and `Download image`, the same two actions the lightbox offers;+it fades out when the pointer leaves and stays up while an action runs. Copy writes the full-resolution image to the+clipboard (`Copied to clipboard`, or `Copied image URL to clipboard` when the+browser refuses an image write) and Download saves it as+`image-<attachment id>.<ext>` (`Downloaded image`). Clicking the image itself+still opens the lightbox. Touch layouts do not get this toolbar: tap the image+and use the lightbox toolbar instead. Videos have their own toolbar; see+[Downloading channel videos](#downloading-channel-videos).+## Reading channel attachments through MCPWhen an agent reads a channel through Macro MCP, `ReadChannelMessages`,