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(canvas): add copy image (#8181)
Seamus4f98fc6bb088
diff --git a/apps/web/src/features/block-canvas/README.md b/apps/web/src/features/block-canvas/README.mdindex e173e9a15e..268206d870 100644--- a/apps/web/src/features/block-canvas/README.md+++ b/apps/web/src/features/block-canvas/README.md@@ -60,6 +60,10 @@ panel tokens; the dot-grid visibility toggle hides every level.The shared context menu exposes clipboard, grouping, layer ordering, select-all,and delete actions, with normal keyboard navigation and focus restoration. Activeembedded editors and text editing retain their own context menus.+With exactly one image selected, the context menu and inspector also offer+**Copy image** and **Save image** for the original image, without canvas styling+or transforms. These reuse the shared image actions (including native mobile+sharing) and stay disabled while the image source or an action is pending.Selecting Arrow, Line, Connector, or Pencil repairs invisible drawing defaults:missing/transparent strokes use theme Ink, zero width uses 2 px, and zero opacityuses full opacity. Other style choices and existing shapes are preserved.diff --git a/apps/web/src/features/block-canvas/queries/media.ts b/apps/web/src/features/block-canvas/queries/media.tsnew file mode 100644index 0000000000..8ab62350f8--- /dev/null+++ b/apps/web/src/features/block-canvas/queries/media.ts@@ -0,0 +1,23 @@+import { staticFileIdEndpoint } from '@core/constant/servers';+import type { MediaSource } from '@macro-inc/graphics';+import { useBinaryDocumentQuery } from '@queries/storage/binary-document';+import type { Accessor } from 'solid-js';++export function useCanvasMediaSource(+ source: Accessor<MediaSource | undefined>+) {+ const query = useBinaryDocumentQuery(() => {+ const value = source();+ return value?.type === 'document' ? value.id : '';+ });+ return {+ url: () => {+ const value = source();+ if (!value) return undefined;+ if (value.type === 'url') return value.url;+ if (value.type === 'static') return staticFileIdEndpoint(value.id);+ return query.isSuccess ? query.data : undefined;+ },+ unavailable: () => source()?.type === 'document' && query.isError,+ };+}diff --git a/apps/web/src/features/block-canvas/views/canvas-context-menu.tsx b/apps/web/src/features/block-canvas/views/canvas-context-menu.tsxindex b1ca2120f8..49b77f1e30 100644--- a/apps/web/src/features/block-canvas/views/canvas-context-menu.tsx+++ b/apps/web/src/features/block-canvas/views/canvas-context-menu.tsx@@ -13,18 +13,25 @@ import ArrowLineUp from '@phosphor/arrow-line-up.svg';import ArrowUp from '@phosphor/arrow-up.svg';import Clipboard from '@phosphor/clipboard.svg';import Copy from '@phosphor/copy.svg';+import DownloadSimple from '@phosphor/download-simple.svg';import Scissors from '@phosphor/scissors.svg';import SelectionAll from '@phosphor/selection-all.svg';import SelectionPlus from '@phosphor/selection-plus.svg';import SelectionSlash from '@phosphor/selection-slash.svg';import Stack from '@phosphor/stack.svg';import Trash from '@phosphor/trash.svg';+import { Show } from 'solid-js';import type { CanvasClipboard } from '../clipboard';import type { CanvasState } from '../primitives/create-canvas-state';export function CanvasContextMenu(props: {state: CanvasState;clipboard: CanvasClipboard;+ imageActions?: {+ disabled: boolean;+ onCopy: () => void;+ onSave: () => void;+ };onClose: () => void;}) {const selected = () => props.state.selection().length > 0;@@ -72,6 +79,25 @@ export function CanvasContextMenu(props: {onClick={props.state.duplicate}/><MenuSeparator />+ <Show when={props.imageActions}>+ {(actions) => (+ <>+ <MenuItem+ text="Copy image"+ icon={Copy}+ disabled={actions().disabled}+ onClick={() => actions().onCopy()}+ />+ <MenuItem+ text="Save image"+ icon={DownloadSimple}+ disabled={actions().disabled}+ onClick={() => actions().onSave()}+ />+ <MenuSeparator />+ </>+ )}+ </Show><MenuItemtext="Group"icon={SelectionPlus}diff --git a/apps/web/src/features/block-canvas/views/canvas-view.tsx b/apps/web/src/features/block-canvas/views/canvas-view.tsxindex 273e2f6ec5..7453f1f742 100644--- a/apps/web/src/features/block-canvas/views/canvas-view.tsx+++ b/apps/web/src/features/block-canvas/views/canvas-view.tsx@@ -1,4 +1,5 @@import { useSidePanel } from '@components/app/side-panel';+import { createImageActions } from '@core/component/Lightbox/createImageActions';import { ContextMenu } from '@kobalte/core/context-menu';import {alignCommand,@@ -16,7 +17,9 @@ import {RectangleView,TextView,} from '@macro-inc/graphics/solid';-import { Layer } from '@ui';+import Copy from '@phosphor/copy.svg';+import DownloadSimple from '@phosphor/download-simple.svg';+import { Button, Layer } from '@ui';import {type Component,createMemo,@@ -47,6 +50,7 @@ import type {} from '../primitives/create-canvas-state';import type { CanvasInsertState } from '../primitives/create-insert-state';import { attachTextInput } from '../primitives/text-input';+import { useCanvasMediaSource } from '../queries/media';import { CanvasContextMenu } from './canvas-context-menu';import {CanvasDrawingToolbar,@@ -95,6 +99,19 @@ export function CanvasView(props: {state.selection().length === 1? state.document.items[state.selection()[0]!]: undefined;+ const selectedImage = () => {+ const item = selectedItem();+ return item?.type === 'image' ? item : undefined;+ };+ const imageSource = useCanvasMediaSource(+ () => selectedImage()?.geometry.source+ );+ const imageActions = createImageActions({+ src: imageSource.url,+ imageId: () => selectedImage()?.id ?? '',+ });+ const imageActionsDisabled = () =>+ !imageSource.url() || imageActions.isPrefetching() || imageActions.isBusy();const styleKinds = () =>state.shapes().length? state.shapes().map((item) => item.type)@@ -394,6 +411,26 @@ export function CanvasView(props: {onScrub={() => state.text.scrubFontSize(state.inspector)}/></Show>+ <Show when={selectedImage()}>+ <div class="flex flex-col gap-2 p-3">+ <Button+ size="sm"+ disabled={imageActionsDisabled()}+ onClick={() => void imageActions.copyToClipboard()}+ >+ <Copy />+ Copy image+ </Button>+ <Button+ size="sm"+ disabled={imageActionsDisabled()}+ onClick={() => void imageActions.downloadImage()}+ >+ <DownloadSimple />+ Save image+ </Button>+ </div>+ </Show><Show when={selectedItem()?.type === 'video'}><buttontype="button"@@ -651,6 +688,15 @@ export function CanvasView(props: {<CanvasContextMenustate={state}clipboard={props.clipboard}+ imageActions={+ selectedImage()+ ? {+ disabled: imageActionsDisabled(),+ onCopy: () => void imageActions.copyToClipboard(),+ onSave: () => void imageActions.downloadImage(),+ }+ : undefined+ }onClose={focus}/></ContextMenu>diff --git a/apps/web/src/features/block-canvas/views/embedded-items.tsx b/apps/web/src/features/block-canvas/views/embedded-items.tsxindex 63dbe272fd..4ceccbb0bb 100644--- a/apps/web/src/features/block-canvas/views/embedded-items.tsx+++ b/apps/web/src/features/block-canvas/views/embedded-items.tsx@@ -1,9 +1,7 @@import { DocumentPreviewContent } from '@core/component/DocumentPreview';import { DocumentPreviewSkeleton } from '@core/component/DocumentPreviewSkeleton';import { fileTypeToBlockName } from '@core/constant/allBlocks';-import { staticFileIdEndpoint } from '@core/constant/servers';import type { ShapeViewProps } from '@macro-inc/graphics/solid';-import { useBinaryDocumentQuery } from '@queries/storage/binary-document';import { Card } from '@ui';import { type Component, ErrorBoundary, Show, Suspense } from 'solid-js';import { Dynamic } from 'solid-js/web';@@ -13,6 +11,7 @@ import {CanvasMediaSkeleton,} from '../components/media-content';import { canEmbedDocument } from '../core/document-display';+import { useCanvasMediaSource } from '../queries/media';export function CanvasMediaView(props: ShapeViewProps<'image' | 'video'> & {@@ -20,17 +19,7 @@ export function CanvasMediaView(onStop: () => void;}) {- const source = () => props.item.geometry.source;- const query = useBinaryDocumentQuery(() => {- const s = source();- return s.type === 'document' ? s.id : '';- });- const url = () => {- const value = source();- if (value.type === 'url') return value.url;- if (value.type === 'static') return staticFileIdEndpoint(value.id);- return query.isSuccess ? query.data : undefined;- };+ const source = useCanvasMediaSource(() => props.item.geometry.source);return (<divdata-canvas-media={props.item.type}@@ -44,10 +33,10 @@ export function CanvasMediaView(><Suspense fallback={<CanvasMediaSkeleton />}><CanvasMediaContent- url={url()}+ url={source.url()}type={props.item.type}name={props.item.geometry.name}- unavailable={query.isError}+ unavailable={source.unavailable()}playing={props.playing}onStop={props.onStop}/>diff --git a/docs/agent-guide/canvas.md b/docs/agent-guide/canvas.mdindex 2130dba0f5..c7016fa435 100644--- a/docs/agent-guide/canvas.md+++ b/docs/agent-guide/canvas.md@@ -14,3 +14,14 @@ Pasting a supported routed Macro app link onto the canvas creates a textnode with an entity mention, as legacy links do. Routed links retain compatibleblock targets, but not workspace paths or pane-local search state; unsupportedlinks remain text.++## Copying and saving images++Select exactly one image to show **Copy image** and **Save image** in both the+context menu and the Canvas inspector. They use the original image, without+canvas transforms or styling. Copy writes image data where supported; the shared+image action can fall back to copying its URL. Save downloads the source format+on desktop and uses the native share sheet on supported mobile devices.+Controls are disabled while resolving the image source or running an action.+Check an uploaded image and a workspace image, and confirm both actions disappear+for multiple selections, groups, videos, and non-image shapes.