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