mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(editor): remove deprecated editor slot (#9908)
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
focusBlockEnd,
|
||||
getLastNoteBlock,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Slot } from '@blocksuite/affine/global/utils';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
DocTitle,
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useImperativeHandle,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
} from 'react';
|
||||
@@ -38,13 +36,6 @@ interface BlocksuiteEditorContainerProps {
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
// mimic the interface of the webcomponent and expose slots & host
|
||||
type BlocksuiteEditorContainerRef = Pick<
|
||||
(typeof AffineEditorContainer)['prototype'],
|
||||
'mode' | 'doc' | 'slots' | 'host'
|
||||
> &
|
||||
HTMLDivElement;
|
||||
|
||||
export const BlocksuiteEditorContainer = forwardRef<
|
||||
AffineEditorContainer,
|
||||
BlocksuiteEditorContainerProps
|
||||
@@ -59,23 +50,11 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
const featureFlags = useService(FeatureFlagService).flags;
|
||||
const enableEditorRTL = useLiveData(featureFlags.enable_editor_rtl.$);
|
||||
|
||||
const slots: BlocksuiteEditorContainerRef['slots'] = useMemo(() => {
|
||||
return {
|
||||
editorModeSwitched: new Slot(),
|
||||
docUpdated: new Slot(),
|
||||
};
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
slots.docUpdated.emit({ newDocId: page.id });
|
||||
}, [page, slots.docUpdated]);
|
||||
|
||||
/**
|
||||
* mimic an AffineEditorContainer using proxy
|
||||
*/
|
||||
const affineEditorContainerProxy = useMemo(() => {
|
||||
const api = {
|
||||
slots,
|
||||
get page() {
|
||||
return page;
|
||||
},
|
||||
@@ -133,7 +112,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
}) as unknown as AffineEditorContainer & { origin: HTMLDivElement };
|
||||
|
||||
return proxy;
|
||||
}, [mode, page, slots]);
|
||||
}, [mode, page]);
|
||||
|
||||
useImperativeHandle(ref, () => affineEditorContainerProxy, [
|
||||
affineEditorContainerProxy,
|
||||
|
||||
Reference in New Issue
Block a user