fix(core): direct replacement of old card with new card in ai chat input (#7324)
Closes: [BS-643](https://linear.app/affine-design/issue/BS-643/continue-with-ai-:-在存在候选内容的情况下,点击-continue-with-ai-应该将选区内容直接替换) https://github.com/toeverything/AFFiNE/assets/27926/ff6e2c31-9d2e-462b-aa7e-6ef1eba50ef5
This commit is contained in:
@@ -2,6 +2,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
|||||||
import { WithDisposable } from '@blocksuite/block-std';
|
import { WithDisposable } from '@blocksuite/block-std';
|
||||||
import {
|
import {
|
||||||
type ImageBlockModel,
|
type ImageBlockModel,
|
||||||
|
isInsideEdgelessEditor,
|
||||||
type NoteBlockModel,
|
type NoteBlockModel,
|
||||||
NoteDisplayMode,
|
NoteDisplayMode,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
@@ -97,11 +98,15 @@ const MAX_CARDS = 3;
|
|||||||
export class ChatCards extends WithDisposable(LitElement) {
|
export class ChatCards extends WithDisposable(LitElement) {
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: none;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([data-show]) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
${cardsStyles}
|
${cardsStyles}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -361,10 +366,10 @@ export class ChatCards extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _extractOnEdgeless() {
|
private async _extractOnEdgeless(host: EditorHost) {
|
||||||
if (!this.host.closest('edgeless-editor')) return;
|
if (!isInsideEdgelessEditor(host)) return;
|
||||||
|
|
||||||
const canvas = await selectedToCanvas(this.host);
|
const canvas = await selectedToCanvas(host);
|
||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
|
|
||||||
const blob: Blob | null = await new Promise(resolve =>
|
const blob: Blob | null = await new Promise(resolve =>
|
||||||
@@ -423,13 +428,13 @@ export class ChatCards extends WithDisposable(LitElement) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly _appendCardWithParams = async ({
|
private async _appendCardWithParams({
|
||||||
// host: _,
|
host,
|
||||||
mode,
|
mode,
|
||||||
autoSelect,
|
autoSelect,
|
||||||
}: AIChatParams) => {
|
}: AIChatParams) {
|
||||||
if (mode === 'edgeless') {
|
if (mode === 'edgeless') {
|
||||||
await this._extractOnEdgeless();
|
await this._extractOnEdgeless(host);
|
||||||
} else {
|
} else {
|
||||||
await this._extract();
|
await this._extract();
|
||||||
}
|
}
|
||||||
@@ -444,7 +449,7 @@ export class ChatCards extends WithDisposable(LitElement) {
|
|||||||
|
|
||||||
await this._selectCard(card);
|
await this._selectCard(card);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
protected override async willUpdate(changedProperties: PropertyValues) {
|
protected override async willUpdate(changedProperties: PropertyValues) {
|
||||||
if (changedProperties.has('temporaryParams') && this.temporaryParams) {
|
if (changedProperties.has('temporaryParams') && this.temporaryParams) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import {
|
|||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||||
import { customElement, property, query, state } from 'lit/decorators.js';
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
||||||
import { cache } from 'lit/directives/cache.js';
|
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
@@ -277,16 +276,11 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
|||||||
</div>
|
</div>
|
||||||
${this._renderAIOnboarding()}
|
${this._renderAIOnboarding()}
|
||||||
</div>
|
</div>
|
||||||
${cache(
|
|
||||||
this.showChatCards
|
|
||||||
? html`
|
|
||||||
<chat-cards
|
<chat-cards
|
||||||
.updateContext=${this.updateContext}
|
.updateContext=${this.updateContext}
|
||||||
.host=${this.host}
|
.host=${this.host}
|
||||||
></chat-cards>
|
?data-show=${this.showChatCards}
|
||||||
`
|
></chat-cards>`
|
||||||
: nothing
|
|
||||||
)}`
|
|
||||||
: repeat(filteredItems, (item, index) => {
|
: repeat(filteredItems, (item, index) => {
|
||||||
const isLast = index === filteredItems.length - 1;
|
const isLast = index === filteredItems.length - 1;
|
||||||
return html`<div class="message">
|
return html`<div class="message">
|
||||||
|
|||||||
Reference in New Issue
Block a user