mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat: add useBlocksuiteEditor hooks (#5366)
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import { atom } from 'jotai';
|
||||
|
||||
export const editorContainerAtom = atom<AffineEditorContainer | null>(null);
|
||||
@@ -1,9 +1,9 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { useBlocksuiteEditor } from '@toeverything/hooks/use-block-suite-editor';
|
||||
import clsx from 'clsx';
|
||||
import { use } from 'foxact/use';
|
||||
import { useAtom } from 'jotai';
|
||||
import type { CSSProperties, ReactElement } from 'react';
|
||||
import {
|
||||
memo,
|
||||
@@ -20,11 +20,8 @@ import {
|
||||
blockSuiteEditorHeaderStyle,
|
||||
blockSuiteEditorStyle,
|
||||
} from './index.css';
|
||||
import { editorContainerAtom } from './index.jotai';
|
||||
import { editorSpecs } from './specs';
|
||||
|
||||
export { editorContainerAtom } from './index.jotai';
|
||||
|
||||
interface BlockElement extends Element {
|
||||
path: string[];
|
||||
}
|
||||
@@ -151,7 +148,7 @@ const BlockSuiteEditorImpl = ({
|
||||
}: EditorProps): ReactElement => {
|
||||
usePageRoot(page);
|
||||
|
||||
const [, setEditorContainer] = useAtom(editorContainerAtom);
|
||||
const [, setEditorContainer] = useBlocksuiteEditor();
|
||||
assertExists(page, 'page should not be null');
|
||||
const editorRef = useRef<AffineEditorContainer | null>(null);
|
||||
if (editorRef.current === null) {
|
||||
@@ -191,8 +188,6 @@ const BlockSuiteEditorImpl = ({
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const editor = editorRef.current;
|
||||
assertExists(editor);
|
||||
const container = containerRef.current;
|
||||
if (!container) {
|
||||
return;
|
||||
@@ -201,6 +196,7 @@ const BlockSuiteEditorImpl = ({
|
||||
setEditorContainer(editor);
|
||||
return () => {
|
||||
editor.remove();
|
||||
setEditorContainer(null);
|
||||
};
|
||||
}, [editor, setEditorContainer]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user