mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix(editor): ref on click slots should not be global (#9830)
fix AF-2129
This commit is contained in:
@@ -433,6 +433,7 @@ const CREATE_AS_DOC = {
|
||||
|
||||
host.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.emit({
|
||||
pageId: newDoc.id,
|
||||
host,
|
||||
});
|
||||
let complete = false;
|
||||
(function addContent() {
|
||||
|
||||
@@ -30,7 +30,10 @@ import { pageHistoryModalAtom } from '../../../components/atoms/page-history';
|
||||
import { useBlockSuiteMetaHelper } from './use-block-suite-meta-helper';
|
||||
import { useExportPage } from './use-export-page';
|
||||
|
||||
export function useRegisterBlocksuiteEditorCommands(editor: Editor) {
|
||||
export function useRegisterBlocksuiteEditorCommands(
|
||||
editor: Editor,
|
||||
active: boolean
|
||||
) {
|
||||
const doc = useService(DocService).doc;
|
||||
const docId = doc.id;
|
||||
const mode = useLiveData(editor.mode$);
|
||||
@@ -82,6 +85,10 @@ export function useRegisterBlocksuiteEditorCommands(editor: Editor) {
|
||||
const openInAppService = useServiceOptional(OpenInAppService);
|
||||
|
||||
useEffect(() => {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unsubs: Array<() => void> = [];
|
||||
const preconditionStrategy = () =>
|
||||
PreconditionStrategy.InPaperOrEdgeless && !trash;
|
||||
@@ -375,5 +382,6 @@ export function useRegisterBlocksuiteEditorCommands(editor: Editor) {
|
||||
defaultPageWidth,
|
||||
checked,
|
||||
openInAppService,
|
||||
active,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ export function useRegisterCopyLinkCommands({
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isActiveView) {
|
||||
return;
|
||||
}
|
||||
const unsubs: Array<() => void> = [];
|
||||
|
||||
unsubs.push(
|
||||
|
||||
@@ -165,7 +165,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
return;
|
||||
}, [globalContext, isActiveView, isInTrash]);
|
||||
|
||||
useRegisterBlocksuiteEditorCommands(editor);
|
||||
useRegisterBlocksuiteEditorCommands(editor, isActiveView);
|
||||
const title = useLiveData(doc.title$);
|
||||
usePageDocumentTitle(title);
|
||||
|
||||
@@ -182,7 +182,10 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
disposable.add(
|
||||
// the event should not be emitted by AffineReference
|
||||
refNodeSlots.docLinkClicked.on(
|
||||
({ pageId, params, openMode, event }) => {
|
||||
({ pageId, params, openMode, event, host }) => {
|
||||
if (host !== editorHost) {
|
||||
return;
|
||||
}
|
||||
openMode ??=
|
||||
event && isNewTabTrigger(event)
|
||||
? 'open-in-new-tab'
|
||||
|
||||
@@ -91,8 +91,10 @@ 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(() => {
|
||||
(chatPanelRef.current as ChatPanel).doc = editor.doc;
|
||||
refNodeService?.docLinkClicked.on(({ host }) => {
|
||||
if (host === editor.host) {
|
||||
(chatPanelRef.current as ChatPanel).doc = editor.doc;
|
||||
}
|
||||
}),
|
||||
docModeService?.onPrimaryModeChange(() => {
|
||||
if (!editor.host) return;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useThemeColorV2 } from '@affine/component';
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary';
|
||||
import { useRegisterBlocksuiteEditorCommands } from '@affine/core/components/hooks/affine/use-register-blocksuite-editor-commands';
|
||||
import { useActiveBlocksuiteEditor } from '@affine/core/components/hooks/use-block-suite-editor';
|
||||
import { useDocMetaHelper } from '@affine/core/components/hooks/use-block-suite-page-meta';
|
||||
import { usePageDocumentTitle } from '@affine/core/components/hooks/use-global-state';
|
||||
@@ -140,7 +139,6 @@ const DetailPageImpl = () => {
|
||||
};
|
||||
}, [globalContext, isInTrash]);
|
||||
|
||||
useRegisterBlocksuiteEditorCommands(editor);
|
||||
const title = useLiveData(doc.title$);
|
||||
usePageDocumentTitle(title);
|
||||
|
||||
|
||||
@@ -106,6 +106,9 @@ function DocPeekPreviewEditor({
|
||||
disposableGroup.add(
|
||||
// todo(@pengx17): seems not working
|
||||
refNodeSlots.docLinkClicked.on(options => {
|
||||
if (options.host !== editorContainer.host) {
|
||||
return;
|
||||
}
|
||||
peekView
|
||||
.open({
|
||||
docRef: { docId: options.pageId },
|
||||
|
||||
Reference in New Issue
Block a user