fix(editor): remove copy-as-png from toolbar of surface-ref (#11493)

This commit is contained in:
L-Sun
2025-04-07 06:03:49 +00:00
parent ea9de7b542
commit 4e33059d58
2 changed files with 1 additions and 79 deletions

View File

@@ -11,7 +11,6 @@ import { CaptionIcon, CopyIcon, DeleteIcon } from '@blocksuite/icons/lit';
import { html } from 'lit';
import { SurfaceRefBlockComponent } from '../surface-ref-block';
import { surfaceRefToBlob, writeImageBlobToClipboard } from '../utils';
export const surfaceRefToolbarModuleConfig: ToolbarModuleConfig = {
actions: [
@@ -73,37 +72,6 @@ export const surfaceRefToolbarModuleConfig: ToolbarModuleConfig = {
return !!surfaceRefBlock.referenceModel;
},
actions: [
{
id: 'a.surface-ref-copy-as-image',
label: 'Copy as Image',
icon: CopyIcon(),
placement: ActionPlacement.More,
when: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return false;
return !!surfaceRefBlock.referenceModel;
},
run: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return;
surfaceRefToBlob(surfaceRefBlock)
.then(async blob => {
if (!blob) {
toast(ctx.host, 'Failed to render surface-ref to image');
} else {
await writeImageBlobToClipboard(blob);
toast(ctx.host, 'Copied image to clipboard');
}
})
.catch(console.error);
},
},
// TODO(@L-Sun): add duplicate action after refactoring root-block/edgeless
],
},

View File

@@ -1,22 +1,16 @@
import { isFrameBlock } from '@blocksuite/affine-block-frame';
import type { SurfaceBlockComponent } from '@blocksuite/affine-block-surface';
import { ExportManager } from '@blocksuite/affine-block-surface';
import type { SurfaceRefBlockComponent } from '@blocksuite/affine-block-surface-ref';
import {
GroupElementModel,
MindmapElementModel,
ShapeElementModel,
} from '@blocksuite/affine-model';
import { BlockSuiteError } from '@blocksuite/global/exceptions';
import { Bound } from '@blocksuite/global/gfx';
import { assertType } from '@blocksuite/global/utils';
import {
EdgelessIcon,
FrameIcon,
GroupIcon,
MindmapIcon,
} from '@blocksuite/icons/lit';
import { GfxControllerIdentifier, type GfxModel } from '@blocksuite/std/gfx';
import { type GfxModel } from '@blocksuite/std/gfx';
import { html, type TemplateResult } from 'lit';
export const noContentPlaceholder = html`
@@ -117,46 +111,6 @@ export const noContentPlaceholder = html`
</svg>
`;
export const surfaceRefToBlob = async (
surfaceRefBlock: SurfaceRefBlockComponent
): Promise<Blob | null> => {
const { referenceModel, previewEditor } = surfaceRefBlock;
if (!referenceModel || !previewEditor) return null;
const exportManager = previewEditor.std.get(ExportManager);
const gfx = previewEditor.std.get(GfxControllerIdentifier);
const { surface } = gfx;
if (!surface) return null;
const surfaceBlock = previewEditor.std.view.getBlock(surface.id);
if (!surfaceBlock) return null;
assertType<SurfaceBlockComponent>(surfaceBlock);
const canvas = await exportManager.edgelessToCanvas(
surfaceBlock.renderer,
Bound.deserialize(referenceModel.xywh),
gfx,
undefined,
undefined,
{ zoom: surfaceBlock.renderer.viewport.zoom }
);
if (!canvas) {
throw new BlockSuiteError(
BlockSuiteError.ErrorCode.ValueNotExists,
'Failed to export edgeless to canvas'
);
}
return new Promise((resolve, reject) => {
canvas.toBlob(blob => (blob ? resolve(blob) : reject(null)), 'image/png');
});
};
export const writeImageBlobToClipboard = async (blob: Blob) => {
await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]);
};
export const TYPE_ICON_MAP: {
[key: string]: {
name: string;