feat(core): support collection search for ai chat (#10987)

Close [BS-2787](https://linear.app/affine-design/issue/BS-2787).
Close [BS-2788](https://linear.app/affine-design/issue/BS-2788).

![截屏2025-03-19 14.15.54.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sJGviKxfE3Ap685cl5bj/573450f9-791b-4cd9-9c75-df93bf9966b4.png)
This commit is contained in:
akumatus
2025-03-20 00:34:12 +00:00
parent f889886b31
commit ee337a16af
7 changed files with 139 additions and 25 deletions
@@ -1,4 +1,5 @@
import type {
SearchCollectionMenuAction,
SearchDocMenuAction,
SearchTagMenuAction,
} from '@affine/core/modules/search-menu/services';
@@ -43,4 +44,9 @@ export interface SearchMenuConfig {
action: SearchTagMenuAction,
abortSignal: AbortSignal
) => LinkedMenuGroup;
getCollectionMenuGroup: (
query: string,
action: SearchCollectionMenuAction,
abortSignal: AbortSignal
) => LinkedMenuGroup;
}
@@ -1,5 +1,8 @@
import { toast } from '@affine/component';
import type { TagMeta } from '@affine/core/components/page-list';
import type {
CollectionMeta,
TagMeta,
} from '@affine/core/components/page-list';
import { ShadowlessElement } from '@blocksuite/affine/block-std';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import { scrollbarStyle } from '@blocksuite/affine/shared/styles';
@@ -314,6 +317,13 @@ export class ChatPanelAddPopover extends SignalWatcher(
this.abortController.signal
);
break;
case AddPopoverMode.Collections:
this._searchGroup = this.searchMenuConfig.getCollectionMenuGroup(
this._query,
this._addCollectionChip,
this.abortController.signal
);
break;
default:
this._searchGroup = this.searchMenuConfig.getDocMenuGroup(
this._query,
@@ -335,6 +345,10 @@ export class ChatPanelAddPopover extends SignalWatcher(
this.abortController.abort();
};
private readonly _addCollectionChip = (_collection: CollectionMeta) => {
this.abortController.abort();
};
private readonly _handleKeyDown = (event: KeyboardEvent) => {
if (event.isComposing) return;