refactor(editor): optimize pasting process of attachments and images (#12276)

Related to: [BS-3146](https://linear.app/affine-design/issue/BS-3146/import-paste-接口改进优化)
This commit is contained in:
fundon
2025-05-18 01:57:42 +00:00
parent f3693a91c3
commit 8726b0e462
14 changed files with 240 additions and 76 deletions

View File

@@ -771,14 +771,11 @@ export async function pasteContent(
export async function pasteTestImage(page: Page) {
await page.evaluate(async () => {
const imageBlob = await fetch(`${location.origin}/test-card-1.png`).then(
response => response.blob()
);
const imageFile = new File([imageBlob], 'test-card-1.png', {
const resp = await fetch(`${location.origin}/test-card-1.png`);
const blob = await resp.blob();
const file = new File([blob], 'test-card-1.png', {
type: 'image/png',
});
const e = new ClipboardEvent('paste', {
clipboardData: new DataTransfer(),
});
@@ -788,7 +785,7 @@ export async function pasteTestImage(page: Page) {
value: document,
});
e.clipboardData?.items.add(imageFile);
e.clipboardData?.items.add(file);
document.dispatchEvent(e);
});
await waitNextFrame(page);