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
@@ -0,0 +1,29 @@
import type { PluginBlockSuiteAdapter } from '@toeverything/plugin-infra/type';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { BookMarkUI } from './ui';
export default {
uiDecorator: editor => {
if (
editor.parentElement &&
editor.page.awarenessStore.getFlag('enable_bookmark_operation')
) {
const div = document.createElement('div');
editor.parentElement.appendChild(div);
const root = createRoot(div);
root.render(
<StrictMode>
<BookMarkUI page={editor.page} />
</StrictMode>
);
return () => {
root.unmount();
div.remove();
};
} else {
return () => {};
}
},
} satisfies Partial<PluginBlockSuiteAdapter>;