feat: add @affine/bookmark-block plugin (#2618)

This commit is contained in:
Himself65
2023-05-31 17:08:03 +08:00
committed by himself65
parent 341731bbfc
commit bd3ea956e2
15 changed files with 202 additions and 49 deletions
@@ -16,14 +16,6 @@ import {
blockSuiteEditorHeaderStyle,
blockSuiteEditorStyle,
} from './index.css';
import { bookmarkPlugin } from './plugins/bookmark';
export type EditorPlugin = {
flavour: string;
onInit?: (page: Page, editor: Readonly<EditorContainer>) => void;
onLoad?: (page: Page, editor: EditorContainer) => () => void;
render?: (props: { page: Page }) => ReactElement | null;
};
export type EditorProps = {
page: Page;
@@ -50,9 +42,6 @@ const ImagePreviewModal = lazy(() =>
}))
);
// todo(himself65): plugin-infra should support this
const plugins = [bookmarkPlugin];
const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
const { onLoad, page, mode, style, onInit } = props;
const JotaiEditorContainer = useAtomValue(
@@ -77,9 +66,6 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
editor.page = page;
if (page.root === null) {
onInit(page, editor);
plugins.forEach(plugin => {
plugin.onInit?.(page, editor);
});
}
}
}, [editor, page, onInit]);
@@ -88,7 +74,6 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
if (editor.page && onLoad) {
const disposes = [] as ((() => void) | undefined)[];
disposes.push(onLoad?.(page, editor));
disposes.push(...plugins.map(plugin => plugin.onLoad?.(page, editor)));
return () => {
disposes
.filter((dispose): dispose is () => void => !!dispose)
@@ -201,12 +186,6 @@ export const BlockSuiteEditor = memo(function BlockSuiteEditor(
)}
</Suspense>
)}
{plugins.map(plugin => {
const Renderer = plugin.render;
return Renderer ? (
<Renderer page={props.page} key={plugin.flavour} />
) : null;
})}
</ErrorBoundary>
);
});