feat(editor): replace slot with rxjs subject (#10768)

This commit is contained in:
Mirone
2025-03-12 11:29:24 +09:00
committed by GitHub
parent 19f978d9aa
commit cd63e0ed8b
302 changed files with 1405 additions and 1251 deletions
@@ -92,7 +92,7 @@ export const EdgelessSnapshot = (props: Props) => {
// refresh viewport
const gfx = editorHost.std.get(GfxControllerIdentifier);
const disposable = editorHost.std.view.viewUpdated.on(payload => {
const disposable = editorHost.std.view.viewUpdated.subscribe(payload => {
if (
payload.type !== 'block' ||
payload.method !== 'add' ||
@@ -110,7 +110,7 @@ export const EdgelessSnapshot = (props: Props) => {
const bound = boundMap.get(docName);
bound && gfx.viewport.setViewportByBound(bound);
doc.readonly = true;
disposable.dispose();
disposable.unsubscribe();
});
// append to dom node
@@ -42,13 +42,12 @@ export const ProfilePanel = () => {
useEffect(() => {
if (workspace?.docCollection) {
setName(workspace.docCollection.meta.name ?? UNTITLED_WORKSPACE_NAME);
const dispose = workspace.docCollection.meta.commonFieldsUpdated.on(
() => {
const dispose =
workspace.docCollection.meta.commonFieldsUpdated.subscribe(() => {
setName(workspace.docCollection.meta.name ?? UNTITLED_WORKSPACE_NAME);
}
);
});
return () => {
dispose.dispose();
dispose.unsubscribe();
};
} else {
setName(UNTITLED_WORKSPACE_NAME);
@@ -18,10 +18,7 @@ import { ViewService } from '@affine/core/modules/workbench';
import { WorkspaceService } from '@affine/core/modules/workspace';
import { isNewTabTrigger } from '@affine/core/utils';
import track from '@affine/track';
import {
type Disposable,
DisposableGroup,
} from '@blocksuite/affine/global/slot';
import { DisposableGroup } from '@blocksuite/affine/global/disposable';
import { RefNodeSlotsProvider } from '@blocksuite/affine/rich-text';
import {
AiIcon,
@@ -39,6 +36,7 @@ import {
import clsx from 'clsx';
import { memo, useCallback, useEffect, useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import type { Subscription } from 'rxjs';
import { AffineErrorBoundary } from '../../../../components/affine/affine-error-boundary';
import { GlobalPageHistoryModal } from '../../../../components/affine/page-history-modal';
@@ -113,14 +111,18 @@ const DetailPageImpl = memo(function DetailPageImpl() {
}, [editorContainer, isActiveView, setActiveBlockSuiteEditor]);
useEffect(() => {
const disposables: Disposable[] = [];
const disposables: Subscription[] = [];
const openHandler = () => {
workbench.openSidebar();
view.activeSidebarTab('chat');
};
disposables.push(AIProvider.slots.requestOpenWithChat.on(openHandler));
disposables.push(AIProvider.slots.requestSendWithChat.on(openHandler));
return () => disposables.forEach(d => d.dispose());
disposables.push(
AIProvider.slots.requestOpenWithChat.subscribe(openHandler)
);
disposables.push(
AIProvider.slots.requestSendWithChat.subscribe(openHandler)
);
return () => disposables.forEach(d => d.unsubscribe());
}, [activeSidebarTab, view, workbench]);
useEffect(() => {
@@ -169,7 +171,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
if (refNodeSlots) {
disposable.add(
// the event should not be emitted by AffineReference
refNodeSlots.docLinkClicked.on(
refNodeSlots.docLinkClicked.subscribe(
({ pageId, params, openMode, event, host }) => {
if (host !== editorContainer.host) {
return;
@@ -109,7 +109,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
const docModeService = editor.host.std.get(DocModeProvider);
const refNodeService = editor.host.std.getOptional(RefNodeSlotsProvider);
const disposable = [
refNodeService?.docLinkClicked.on(({ host }) => {
refNodeService?.docLinkClicked.subscribe(({ host }) => {
if (host === editor.host) {
(chatPanelRef.current as ChatPanel).doc = editor.doc;
}
@@ -120,7 +120,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
}, editor.doc.id),
];
return () => disposable.forEach(d => d?.dispose());
return () => disposable.forEach(d => d?.unsubscribe());
}, [editor, framework]);
return <div className={styles.root} ref={containerRef} />;
@@ -20,7 +20,7 @@ import {
WorkspacesService,
} from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n';
import { DisposableGroup } from '@blocksuite/affine/global/slot';
import { DisposableGroup } from '@blocksuite/affine/global/disposable';
import { type DocMode, DocModes } from '@blocksuite/affine/model';
import { RefNodeSlotsProvider } from '@blocksuite/affine/rich-text';
import { Logo1Icon } from '@blocksuite/icons/rc';
@@ -201,7 +201,7 @@ const SharePageInner = ({
editorContainer.host?.std.getOptional(RefNodeSlotsProvider);
if (refNodeSlots) {
disposable.add(
refNodeSlots.docLinkClicked.on(({ pageId, params }) => {
refNodeSlots.docLinkClicked.subscribe(({ pageId, params }) => {
if (params) {
const { mode, blockIds, elementIds } = params;
jumpToPageBlock(workspaceId, pageId, mode, blockIds, elementIds);