Merge pull request #678 from toeverything/0106/surface

feat: compat with surface block structure
This commit is contained in:
DarkSky
2023-01-06 17:34:18 +08:00
committed by GitHub
9 changed files with 62 additions and 44 deletions

View File

@@ -11,10 +11,10 @@
},
"dependencies": {
"@affine/datacenter": "workspace:*",
"@blocksuite/blocks": "0.3.1",
"@blocksuite/editor": "0.3.1",
"@blocksuite/blocks": "=0.3.1-20230106060050-1aad55d",
"@blocksuite/editor": "=0.3.1-20230106060050-1aad55d",
"@blocksuite/icons": "^2.0.2",
"@blocksuite/store": "0.3.1",
"@blocksuite/store": "=0.3.1-20230106060050-1aad55d",
"@emotion/css": "^11.10.0",
"@emotion/react": "^11.10.4",
"@emotion/server": "^11.10.0",

View File

@@ -22,14 +22,14 @@ export const EditorHeader = () => {
useEffect(() => {
onPropsUpdated(editor => {
setTitle(editor.model?.title || 'Untitled');
setTitle(editor.pageBlockModel?.title || 'Untitled');
});
}, [onPropsUpdated]);
useEffect(() => {
setTimeout(() => {
// If first time in, need to wait for editor to be inserted into DOM
setTitle(editor?.model?.title || 'Untitled');
setTitle(editor?.pageBlockModel?.title || 'Untitled');
}, 300);
}, [editor]);

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);
});
@@ -26,7 +26,7 @@ export const usePropsUpdated: UsePropsUpdated = () => {
return () => {
callbackQueue.current = [];
editor?.model?.propsUpdated.dispose();
editor?.pageBlockModel?.propsUpdated?.dispose();
};
}, [editor]);

View File

@@ -43,12 +43,16 @@ const All = () => {
if (page) {
currentWorkspace?.setPageMeta(page.id, { title });
if (page && page.root === null) {
setTimeout(() => {
setTimeout(async () => {
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}`);
await 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();

View File

@@ -26,8 +26,8 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@blocksuite/blocks": "^0.3.1",
"@blocksuite/store": "^0.3.1",
"@blocksuite/blocks": "=0.3.1-20230106060050-1aad55d",
"@blocksuite/store": "=0.3.1-20230106060050-1aad55d",
"debug": "^4.3.4",
"encoding": "^0.1.13",
"firebase": "^9.15.0",