feat: use footnote for perplexity search results (#9851)

Support issue [BS-2475](https://linear.app/affine-design/issue/BS-2475).

![截屏2025-01-22 16.49.25.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sJGviKxfE3Ap685cl5bj/49febcdf-e403-4a2e-ba99-da36df34e08c.png)
This commit is contained in:
akumatus
2025-01-22 10:54:00 +00:00
parent f8a515e89a
commit 862a9d0bc4
5 changed files with 69 additions and 39 deletions

View File

@@ -14,7 +14,7 @@ import { css, html, nothing } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import { styleMap } from 'lit/directives/style-map.js';
import { debounce, throttle } from 'lodash-es';
import { debounce } from 'lodash-es';
import {
EdgelessEditorActions,
@@ -132,9 +132,6 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
@query('.chat-panel-messages')
accessor messagesContainer: HTMLDivElement | null = null;
@query('.message:nth-last-child(2)')
accessor lastMessage: HTMLDivElement | null = null;
private _renderAIOnboarding() {
return this.isLoading ||
!this.host?.doc.get(FeatureFlagService).getFlag('enable_ai_onboarding')
@@ -192,16 +189,6 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
100
);
private readonly _scrollIntoView = () => {
if (!this.lastMessage) return;
this.lastMessage.scrollIntoView({ behavior: 'smooth' });
};
private readonly _throttledScrollIntoView = throttle(
this._scrollIntoView,
500
);
protected override render() {
const { items } = this.chatContextValue;
const { isLoading } = this;
@@ -300,12 +287,6 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
);
}
protected override updated() {
if (this.chatContextValue.status === 'transmitting') {
this._throttledScrollIntoView();
}
}
renderItem(item: ChatItem, isLast: boolean) {
const { status, error } = this.chatContextValue;
const { host } = this;

View File

@@ -9,6 +9,7 @@ import type { Store } from '@blocksuite/affine/store';
import { css, html, type PropertyValues } from 'lit';
import { property, state } from 'lit/decorators.js';
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
import { throttle } from 'lodash-es';
import { AIHelpIcon, SmallHintIcon } from '../_common/icons';
import { AIProvider } from '../provider';
@@ -191,6 +192,8 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
this._chatMessages.value?.scrollToEnd();
};
private readonly _throttledScrollToEnd = throttle(this._scrollToEnd, 1000);
private readonly _cleanupHistories = async () => {
const notification = this.host.std.getOptional(NotificationProvider);
if (!notification) return;
@@ -229,7 +232,6 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
}
if (
!this.isLoading &&
_changedProperties.has('chatContextValue') &&
(this.chatContextValue.status === 'loading' ||
this.chatContextValue.status === 'error' ||
@@ -237,6 +239,13 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
) {
setTimeout(this._scrollToEnd, 500);
}
if (
_changedProperties.has('chatContextValue') &&
this.chatContextValue.status === 'transmitting'
) {
this._throttledScrollToEnd();
}
}
override connectedCallback() {