feat: bump blocksuite (#5575)

This commit is contained in:
regischen
2024-01-12 12:41:27 +08:00
committed by GitHub
parent 89b5c96d25
commit 3602f1cac0
16 changed files with 221 additions and 215 deletions

View File

@@ -5,12 +5,12 @@ import {
import { pushNotificationAtom } from '@affine/component/notification-center';
import { apis } from '@affine/electron-api';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageService } from '@blocksuite/blocks';
import {
HtmlTransformer,
MarkdownTransformer,
type PageBlockModel,
} from '@blocksuite/blocks';
import { ContentParser } from '@blocksuite/blocks/content-parser';
import type { Page } from '@blocksuite/store';
import { useSetAtom } from 'jotai';
import { nanoid } from 'nanoid';
@@ -18,29 +18,17 @@ import { useCallback } from 'react';
type ExportType = 'pdf' | 'html' | 'png' | 'markdown';
const contentParserWeakMap = new WeakMap<Page, ContentParser>();
const getContentParser = (page: Page) => {
if (!contentParserWeakMap.has(page)) {
contentParserWeakMap.set(
page,
new ContentParser(page, {
imageProxyEndpoint: !environment.isDesktop
? runtimeConfig.imageProxyUrl
: undefined,
})
);
}
return contentParserWeakMap.get(page) as ContentParser;
};
interface ExportHandlerOptions {
page: Page;
type: ExportType;
}
async function exportHandler({ page, type }: ExportHandlerOptions) {
const contentParser = getContentParser(page);
const editorRoot = document.querySelector('editor-host');
let pageService: PageService | null = null;
if (editorRoot) {
pageService = editorRoot.spec.getService('affine:page') as PageService;
}
switch (type) {
case 'html':
await HtmlTransformer.exportPage(page);
@@ -54,12 +42,15 @@ async function exportHandler({ page, type }: ExportHandlerOptions) {
(page.root as PageBlockModel).title.toString()
);
} else {
await contentParser['exportPdf']();
if (!pageService) return;
await pageService.exportManager.exportPdf();
}
break;
case 'png':
await contentParser['exportPng']();
case 'png': {
if (!pageService) return;
await pageService.exportManager.exportPng();
break;
}
}
}