fix: copilot ci (#9066)

This commit is contained in:
darkskygit
2024-12-09 11:11:04 +00:00
parent 814b4c9cb0
commit 31146e5213
10 changed files with 95 additions and 80 deletions

View File

@@ -3,9 +3,8 @@ import {
DocModeProvider,
RefNodeSlotsProvider,
} from '@blocksuite/affine/blocks';
import { assertExists } from '@blocksuite/affine/global/utils';
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
import { forwardRef, useCallback, useEffect, useRef } from 'react';
import { forwardRef, useEffect, useRef } from 'react';
import * as styles from './chat.css';
@@ -20,13 +19,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
ref: React.ForwardedRef<ChatPanel>
) {
const chatPanelRef = useRef<ChatPanel | null>(null);
const onRefChange = useCallback((container: HTMLDivElement | null) => {
if (container) {
assertExists(chatPanelRef.current, 'chat panel should be initialized');
container.append(chatPanelRef.current);
}
}, []);
const containerRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
if (onLoad && chatPanelRef.current) {
@@ -45,40 +38,32 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
}, [onLoad, ref]);
useEffect(() => {
if (!editor) return;
const pageService = editor.host?.std.getService('affine:page');
if (!pageService) return;
const docModeService = editor.host?.std.get(DocModeProvider);
const refNodeService = editor.host?.std.getOptional(RefNodeSlotsProvider);
if (!editor || !editor.host) return;
if (!chatPanelRef.current) {
chatPanelRef.current = new ChatPanel();
chatPanelRef.current.host = editor.host;
chatPanelRef.current.doc = editor.doc;
containerRef.current?.append(chatPanelRef.current);
} else {
chatPanelRef.current.host = editor.host;
chatPanelRef.current.doc = editor.doc;
}
const docModeService = editor.host.std.get(DocModeProvider);
const refNodeService = editor.host.std.getOptional(RefNodeSlotsProvider);
const disposable = [
refNodeService &&
refNodeService.docLinkClicked.on(() => {
(chatPanelRef.current as ChatPanel).doc = editor.doc;
}),
docModeService &&
docModeService.onPrimaryModeChange(() => {
if (!editor.host) return;
(chatPanelRef.current as ChatPanel).host = editor.host;
}, editor.doc.id),
refNodeService?.docLinkClicked.on(() => {
(chatPanelRef.current as ChatPanel).doc = editor.doc;
}),
docModeService?.onPrimaryModeChange(() => {
if (!editor.host) return;
(chatPanelRef.current as ChatPanel).host = editor.host;
}, editor.doc.id),
];
return () => disposable.forEach(d => d?.dispose());
}, [editor]);
if (!editor) {
return;
}
if (!chatPanelRef.current) {
chatPanelRef.current = new ChatPanel();
}
if (editor.host) {
(chatPanelRef.current as ChatPanel).host = editor.host;
}
(chatPanelRef.current as ChatPanel).doc = editor.doc;
// (copilotPanelRef.current as CopilotPanel).fitPadding = [20, 20, 20, 20];
return <div className={styles.root} ref={onRefChange} />;
return <div className={styles.root} ref={containerRef} />;
});