Skip to content

Commit

Permalink
refactor(editor): remove deprecated editor slot
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Jan 29, 2025
1 parent f3f6e8c commit 24ebe04
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 54 deletions.
8 changes: 0 additions & 8 deletions blocksuite/blocks/src/_common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import type {
DocMode,
GroupElementModel,
} from '@blocksuite/affine-model';
import type { Slot } from '@blocksuite/global/utils';
import type { Store } from '@blocksuite/store';

/** Common context interface definition for block models. */

type EditorSlots = {
docUpdated: Slot<{ newDocId: string }>;
};

export type AbstractEditor = {
doc: Store;
mode: DocMode;
readonly slots: EditorSlots;
} & HTMLElement;

export type Connectable = Exclude<
Expand Down
3 changes: 0 additions & 3 deletions blocksuite/playground/apps/starter/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ export async function mountDefaultDocEditor(collection: Workspace) {
const modeService = editor.std.provider.get(DocModeProvider);
editor.mode = modeService.getPrimaryMode(doc.id);
setDocModeFromUrlParams(modeService, url.searchParams, doc.id);
editor.slots.docUpdated.on(({ newDocId }) => {
editor.mode = modeService.getPrimaryMode(newDocId);
});

const outlinePanel = new CustomOutlinePanel();
outlinePanel.editor = editor;
Expand Down
22 changes: 1 addition & 21 deletions blocksuite/presets/src/editors/editor-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PageEditorBlockSpecs,
ThemeProvider,
} from '@blocksuite/blocks';
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import {
type BlockModel,
type ExtensionType,
Expand Down Expand Up @@ -115,13 +115,6 @@ export class AffineEditorContainer
return this._std.value.render();
});

/**
* @deprecated need to refactor
*/
slots: AbstractEditor['slots'] = {
docUpdated: new Slot(),
};

get doc() {
return this._doc.value as Store;
}
Expand Down Expand Up @@ -228,19 +221,6 @@ export class AffineEditorContainer
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 })
override accessor autofocus = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
focusBlockEnd,
getLastNoteBlock,
} from '@blocksuite/affine/blocks';
import { Slot } from '@blocksuite/affine/global/utils';
import type {
AffineEditorContainer,
DocTitle,
Expand All @@ -20,7 +19,6 @@ import {
forwardRef,
useCallback,
useImperativeHandle,
useLayoutEffect,
useMemo,
useRef,
} from 'react';
Expand All @@ -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
Expand All @@ -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;
},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 24ebe04

Please sign in to comment.