feat: compat with surface block structure

This commit is contained in:
Yifeng Wang 2023-01-06 13:26:10 +08:00 committed by himself65
parent 2b8c975e6c
commit 449b08c9c2
4 changed files with 12 additions and 9 deletions

View File

@ -31,9 +31,10 @@ export const ImportModal = ({ open, onClose }: ImportModalProps) => {
setTimeout(() => {
const editor = document.querySelector('editor-container');
if (editor) {
const groupId = page.addBlock({ flavour: 'affine:group' }, pageId);
page.addBlock({ flavour: 'affine:surface' }, null);
const frameId = page.addBlock({ flavour: 'affine:frame' }, pageId);
// TODO blocksuite should offer a method to import markdown from store
editor.clipboard.importMarkdown(template.source, `${groupId}`);
editor.clipboard.importMarkdown(template.source, `${frameId}`);
page.resetHistory();
editor.requestUpdate();
}

View File

@ -17,7 +17,7 @@ export const usePropsUpdated: UsePropsUpdated = () => {
return;
}
setTimeout(() => {
editor.model?.propsUpdated.on(() => {
editor.pageBlockModel?.propsUpdated.on(() => {
callbackQueue.current.forEach(callback => {
callback(editor);
});

View File

@ -46,9 +46,10 @@ const All = () => {
setTimeout(() => {
const editor = document.querySelector('editor-container');
if (editor) {
const groupId = page.addBlock({ flavour: 'affine:group' }, pageId);
page.addBlock({ flavour: 'affine:surface' }, null);
const frameId = page.addBlock({ flavour: 'affine:frame' }, pageId);
// TODO blocksuite should offer a method to import markdown from store
editor.clipboard.importMarkdown(template.source, `${groupId}`);
editor.clipboard.importMarkdown(template.source, `${frameId}`);
page.resetHistory();
editor.requestUpdate();
}

View File

@ -55,14 +55,15 @@ const Page: NextPageWithLayout = () => {
flavour: 'affine:page',
title,
});
const groupId = currentPage!.addBlock(
{ flavour: 'affine:group' },
currentPage!.addBlock({ flavour: 'affine:surface' }, null);
const frameId = currentPage!.addBlock(
{ flavour: 'affine:frame' },
pageId
);
currentPage!.addBlock({ flavour: 'affine:group' }, pageId);
currentPage!.addBlock({ flavour: 'affine:frame' }, pageId);
// If this is a first page in workspace, init an introduction markdown
if (isFirstPage) {
editor.clipboard.importMarkdown(exampleMarkdown, `${groupId}`);
editor.clipboard.importMarkdown(exampleMarkdown, `${frameId}`);
currentWorkspace!.setPageMeta(currentPage!.id, { title });
}
currentPage!.resetHistory();