refactor(editor): remove deprecated editor slot (#9908)
This commit is contained in:
@@ -4,19 +4,11 @@ import type {
|
|||||||
DocMode,
|
DocMode,
|
||||||
GroupElementModel,
|
GroupElementModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import type { Slot } from '@blocksuite/global/utils';
|
|
||||||
import type { Store } from '@blocksuite/store';
|
import type { Store } from '@blocksuite/store';
|
||||||
|
|
||||||
/** Common context interface definition for block models. */
|
|
||||||
|
|
||||||
type EditorSlots = {
|
|
||||||
docUpdated: Slot<{ newDocId: string }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AbstractEditor = {
|
export type AbstractEditor = {
|
||||||
doc: Store;
|
doc: Store;
|
||||||
mode: DocMode;
|
mode: DocMode;
|
||||||
readonly slots: EditorSlots;
|
|
||||||
} & HTMLElement;
|
} & HTMLElement;
|
||||||
|
|
||||||
export type Connectable = Exclude<
|
export type Connectable = Exclude<
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ export async function mountDefaultDocEditor(collection: Workspace) {
|
|||||||
const modeService = editor.std.provider.get(DocModeProvider);
|
const modeService = editor.std.provider.get(DocModeProvider);
|
||||||
editor.mode = modeService.getPrimaryMode(doc.id);
|
editor.mode = modeService.getPrimaryMode(doc.id);
|
||||||
setDocModeFromUrlParams(modeService, url.searchParams, doc.id);
|
setDocModeFromUrlParams(modeService, url.searchParams, doc.id);
|
||||||
editor.slots.docUpdated.on(({ newDocId }) => {
|
|
||||||
editor.mode = modeService.getPrimaryMode(newDocId);
|
|
||||||
});
|
|
||||||
|
|
||||||
const outlinePanel = new CustomOutlinePanel();
|
const outlinePanel = new CustomOutlinePanel();
|
||||||
outlinePanel.editor = editor;
|
outlinePanel.editor = editor;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
PageEditorBlockSpecs,
|
PageEditorBlockSpecs,
|
||||||
ThemeProvider,
|
ThemeProvider,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||||
import {
|
import {
|
||||||
type BlockModel,
|
type BlockModel,
|
||||||
type ExtensionType,
|
type ExtensionType,
|
||||||
@@ -115,13 +115,6 @@ export class AffineEditorContainer
|
|||||||
return this._std.value.render();
|
return this._std.value.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated need to refactor
|
|
||||||
*/
|
|
||||||
slots: AbstractEditor['slots'] = {
|
|
||||||
docUpdated: new Slot(),
|
|
||||||
};
|
|
||||||
|
|
||||||
get doc() {
|
get doc() {
|
||||||
return this._doc.value as Store;
|
return this._doc.value as Store;
|
||||||
}
|
}
|
||||||
@@ -228,19 +221,6 @@ export class AffineEditorContainer
|
|||||||
this._mode.value = mode;
|
this._mode.value = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated need to refactor
|
|
||||||
*/
|
|
||||||
override updated(changedProperties: Map<string, unknown>) {
|
|
||||||
if (changedProperties.has('doc')) {
|
|
||||||
this.slots.docUpdated.emit({ newDocId: this.doc.id });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!changedProperties.has('doc') && !changedProperties.has('mode')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
override accessor autofocus = false;
|
override accessor autofocus = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
focusBlockEnd,
|
focusBlockEnd,
|
||||||
getLastNoteBlock,
|
getLastNoteBlock,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Slot } from '@blocksuite/affine/global/utils';
|
|
||||||
import type {
|
import type {
|
||||||
AffineEditorContainer,
|
AffineEditorContainer,
|
||||||
DocTitle,
|
DocTitle,
|
||||||
@@ -20,7 +19,6 @@ import {
|
|||||||
forwardRef,
|
forwardRef,
|
||||||
useCallback,
|
useCallback,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
useLayoutEffect,
|
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
@@ -38,13 +36,6 @@ interface BlocksuiteEditorContainerProps {
|
|||||||
style?: React.CSSProperties;
|
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<
|
export const BlocksuiteEditorContainer = forwardRef<
|
||||||
AffineEditorContainer,
|
AffineEditorContainer,
|
||||||
BlocksuiteEditorContainerProps
|
BlocksuiteEditorContainerProps
|
||||||
@@ -59,23 +50,11 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
const featureFlags = useService(FeatureFlagService).flags;
|
const featureFlags = useService(FeatureFlagService).flags;
|
||||||
const enableEditorRTL = useLiveData(featureFlags.enable_editor_rtl.$);
|
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
|
* mimic an AffineEditorContainer using proxy
|
||||||
*/
|
*/
|
||||||
const affineEditorContainerProxy = useMemo(() => {
|
const affineEditorContainerProxy = useMemo(() => {
|
||||||
const api = {
|
const api = {
|
||||||
slots,
|
|
||||||
get page() {
|
get page() {
|
||||||
return page;
|
return page;
|
||||||
},
|
},
|
||||||
@@ -133,7 +112,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
}) as unknown as AffineEditorContainer & { origin: HTMLDivElement };
|
}) as unknown as AffineEditorContainer & { origin: HTMLDivElement };
|
||||||
|
|
||||||
return proxy;
|
return proxy;
|
||||||
}, [mode, page, slots]);
|
}, [mode, page]);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => affineEditorContainerProxy, [
|
useImperativeHandle(ref, () => affineEditorContainerProxy, [
|
||||||
affineEditorContainerProxy,
|
affineEditorContainerProxy,
|
||||||
|
|||||||
Reference in New Issue
Block a user