feat: update blocksuite 0.3.0-alpha.4 (#543)

This commit is contained in:
zuomeng wang
2022-12-01 20:45:18 +00:00
committed by GitHub
parent f10237d207
commit 850ed4d825
4 changed files with 291 additions and 29 deletions

View File

@@ -78,11 +78,11 @@ const UndoRedo = () => {
const { editor } = useEditor();
useEffect(() => {
if (!editor) return;
const { space } = editor;
const { page } = editor;
space.signals.historyUpdated.on(() => {
setCanUndo(space.canUndo);
setCanRedo(space.canRedo);
page.signals.historyUpdated.on(() => {
setCanUndo(page.canUndo);
setCanRedo(page.canRedo);
});
}, [editor]);
@@ -92,7 +92,7 @@ const UndoRedo = () => {
<StyledToolbarItem
disable={!canUndo}
onClick={() => {
editor?.space?.undo();
editor?.page?.undo();
}}
>
<UndoIcon />
@@ -102,7 +102,7 @@ const UndoRedo = () => {
<StyledToolbarItem
disable={!canRedo}
onClick={() => {
editor?.space?.redo();
editor?.page?.redo();
}}
>
<RedoIcon />

View File

@@ -2,7 +2,8 @@ import { useEditor } from '@/components/editor-provider';
import '@blocksuite/blocks';
import '@blocksuite/blocks/style';
import type { EditorContainer } from '@blocksuite/editor';
import { createEditor } from '@blocksuite/editor';
import { createEditor, BlockSchema } from '@blocksuite/editor';
import { Workspace } from '@blocksuite/store';
import { forwardRef, Suspense, useEffect, useRef } from 'react';
import pkg from '../../package.json';
import exampleMarkdown from './example-markdown';
@@ -14,7 +15,9 @@ const BlockSuiteEditor = forwardRef<EditorContainer>(({}, ref) => {
if (!containerElement.current) {
return;
}
const editor = createEditor();
const workspace = new Workspace({});
const page = workspace.createPage('page0').register(BlockSchema);
const editor = createEditor(page);
containerElement.current.appendChild(editor);
if (ref) {
if ('current' in ref) {
@@ -38,14 +41,14 @@ export const Editor = () => {
return;
}
setEditor(editorRef.current);
const { space } = editorRef.current as EditorContainer;
const pageId = space.addBlock({
const { page } = editorRef.current as EditorContainer;
const pageId = page.addBlock({
flavour: 'affine:page',
title: 'Welcome to the AFFiNE Alpha',
});
const groupId = space.addBlock({ flavour: 'affine:group' }, pageId);
const groupId = page.addBlock({ flavour: 'affine:group' }, pageId);
editorRef.current.clipboard.importMarkdown(exampleMarkdown, `${groupId}`);
space.resetHistory();
page.resetHistory();
}, [setEditor]);
useEffect(() => {