mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
feat(core): add chat-panel track (#11323)
Close [AF-2434](https://linear.app/affine-design/issue/AF-2434).
This commit is contained in:
@@ -34,6 +34,7 @@ export interface DocDisplayConfig {
|
||||
cleanup: () => void;
|
||||
};
|
||||
getDocMeta: (docId: string) => Partial<DocMeta> | null;
|
||||
getDocPrimaryMode: (docId: string) => 'page' | 'edgeless';
|
||||
getDoc: (docId: string) => Store | null;
|
||||
getReferenceDocs: (docIds: string[]) => {
|
||||
signal: Signal<
|
||||
|
||||
@@ -263,6 +263,7 @@ export class ChatPanelChips extends SignalWatcher(
|
||||
<chat-panel-add-popover
|
||||
.addChip=${this._addChip}
|
||||
.searchMenuConfig=${this.searchMenuConfig}
|
||||
.docDisplayConfig=${this.docDisplayConfig}
|
||||
.abortController=${this._abortController}
|
||||
></chat-panel-add-popover>
|
||||
`,
|
||||
|
||||
@@ -3,11 +3,13 @@ import type {
|
||||
CollectionMeta,
|
||||
TagMeta,
|
||||
} from '@affine/core/components/page-list';
|
||||
import track from '@affine/track';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { scrollbarStyle } from '@blocksuite/affine/shared/styles';
|
||||
import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine/shared/theme';
|
||||
import { openFileOrFiles } from '@blocksuite/affine/shared/utils';
|
||||
import { ShadowlessElement } from '@blocksuite/affine/std';
|
||||
import type { DocMeta } from '@blocksuite/affine/store';
|
||||
import {
|
||||
CollectionsIcon,
|
||||
MoreHorizontalIcon,
|
||||
@@ -15,13 +17,12 @@ import {
|
||||
TagsIcon,
|
||||
UploadIcon,
|
||||
} from '@blocksuite/icons/lit';
|
||||
import type { DocMeta } from '@blocksuite/store';
|
||||
import { Signal } from '@preact/signals-core';
|
||||
import { css, html, type TemplateResult } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type { SearchMenuConfig } from '../chat-config';
|
||||
import type { DocDisplayConfig, SearchMenuConfig } from '../chat-config';
|
||||
import type { ChatChip } from '../chat-context';
|
||||
|
||||
enum AddPopoverMode {
|
||||
@@ -171,6 +172,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
file,
|
||||
state: 'processing',
|
||||
});
|
||||
this._track('file');
|
||||
this.abortController.abort();
|
||||
};
|
||||
|
||||
@@ -244,6 +246,9 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
@property({ attribute: false })
|
||||
accessor searchMenuConfig!: SearchMenuConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor docDisplayConfig!: DocDisplayConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor addChip!: (chip: ChatChip) => void;
|
||||
|
||||
@@ -450,6 +455,8 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
docId: meta.id,
|
||||
state: 'processing',
|
||||
});
|
||||
const mode = this.docDisplayConfig.getDocPrimaryMode(meta.id);
|
||||
this._track('doc', mode);
|
||||
this.abortController.abort();
|
||||
};
|
||||
|
||||
@@ -458,6 +465,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
tagId: tag.id,
|
||||
state: 'processing',
|
||||
});
|
||||
this._track('tags');
|
||||
this.abortController.abort();
|
||||
};
|
||||
|
||||
@@ -466,6 +474,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
collectionId: collection.id,
|
||||
state: 'processing',
|
||||
});
|
||||
this._track('collections');
|
||||
this.abortController.abort();
|
||||
};
|
||||
|
||||
@@ -510,4 +519,15 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _track(
|
||||
method: 'doc' | 'file' | 'tags' | 'collections',
|
||||
type?: 'page' | 'edgeless'
|
||||
) {
|
||||
track.$.chatPanel.chatPanelInput.addEmbeddingDoc({
|
||||
control: 'addButton',
|
||||
method,
|
||||
type,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import track from '@affine/track';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std';
|
||||
import { Signal } from '@preact/signals-core';
|
||||
@@ -83,6 +84,12 @@ export class ChatPanelDocChip extends SignalWatcher(
|
||||
...this.chip,
|
||||
state: 'processing',
|
||||
});
|
||||
const mode = this.docDisplayConfig.getDocPrimaryMode(this.chip.docId);
|
||||
track.$.chatPanel.chatPanelInput.addEmbeddingDoc({
|
||||
control: 'addButton',
|
||||
method: 'suggestion',
|
||||
type: mode,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -101,6 +101,10 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
||||
const docRecord = docsService.list.doc$(docId).value;
|
||||
return docRecord?.meta$.value ?? null;
|
||||
},
|
||||
getDocPrimaryMode: (docId: string) => {
|
||||
const docRecord = docsService.list.doc$(docId).value;
|
||||
return docRecord?.primaryMode$.value ?? 'page';
|
||||
},
|
||||
getDoc: (docId: string) => {
|
||||
const doc = workspaceService.workspace.docCollection.getDoc(docId);
|
||||
return doc?.getStore() ?? null;
|
||||
|
||||
@@ -132,6 +132,10 @@ type PaymentEvents =
|
||||
| 'confirmResumingSubscription';
|
||||
// END SECTION
|
||||
|
||||
// SECTION: ai
|
||||
type AIEvents = 'addEmbeddingDoc';
|
||||
// END SECTION
|
||||
|
||||
// SECTION: attachment
|
||||
type AttachmentEvents =
|
||||
| 'openAttachmentInFullscreen'
|
||||
@@ -177,6 +181,7 @@ type UserEvents =
|
||||
| AccountEvents
|
||||
| PaymentEvents
|
||||
| DNDEvents
|
||||
| AIEvents
|
||||
| AttachmentEvents
|
||||
| TemplateEvents
|
||||
| NotificationEvents
|
||||
@@ -362,6 +367,9 @@ const PageEvents = {
|
||||
importModal: ['open'],
|
||||
snapshot: ['import', 'export'],
|
||||
},
|
||||
chatPanel: {
|
||||
chatPanelInput: ['addEmbeddingDoc'],
|
||||
},
|
||||
attachment: {
|
||||
$: [
|
||||
'openAttachmentInFullscreen',
|
||||
@@ -567,6 +575,11 @@ export type EventArgs = {
|
||||
linkDoc: { type: string; journal: boolean };
|
||||
drop: { type: string };
|
||||
dragStart: { type: string };
|
||||
addEmbeddingDoc: {
|
||||
type?: 'page' | 'edgeless';
|
||||
control: 'addButton' | 'atMenu';
|
||||
method: 'doc' | 'file' | 'tags' | 'collections' | 'suggestion';
|
||||
};
|
||||
openAttachmentInFullscreen: AttachmentEventArgs;
|
||||
openAttachmentInNewTab: AttachmentEventArgs;
|
||||
openAttachmentInPeekView: AttachmentEventArgs;
|
||||
|
||||
Reference in New Issue
Block a user