mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 23:07:02 +08:00
feat: update blocksuite 0.3.0-alpha.4 (#543)
This commit is contained in:
@@ -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 />
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user