feat: improve continue to chat compatibility (#7757)

fix AF-1152
This commit is contained in:
darkskygit
2024-08-06 09:15:42 +00:00
parent 5872b884a5
commit 14669b9ced
3 changed files with 72 additions and 51 deletions

View File

@@ -309,6 +309,15 @@ export class ChatCards extends WithDisposable(LitElement) {
}); });
break; break;
} }
case CardType.Block: {
this.updateContext({
quote: card.text,
markdown: card.markdown,
images: card.images,
});
break;
}
case CardType.Doc: { case CardType.Doc: {
await this._handleDocSelection(card); await this._handleDocSelection(card);
this.updateContext({ this.updateContext({
@@ -336,11 +345,7 @@ export class ChatCards extends WithDisposable(LitElement) {
text, text,
markdown, markdown,
}); });
} else if (!hasText && hasImages && images.length === 1) {
return;
}
if (!hasText && hasImages && images.length === 1) {
const [_, data] = this.host.command const [_, data] = this.host.command
.chain() .chain()
.tryAll(chain => [chain.getImageSelections()]) .tryAll(chain => [chain.getImageSelections()])
@@ -364,8 +369,16 @@ export class ChatCards extends WithDisposable(LitElement) {
image: images[0], image: images[0],
caption, caption,
}); });
} else {
return; const markdown =
(await getSelectedTextContent(this.host, 'markdown')).trim() || '';
this._updateCards({
id: Date.now(),
type: CardType.Block,
text,
markdown,
images,
});
} }
} }

View File

@@ -141,6 +141,10 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
} }
} }
.chat-panel-images-wrapper {
overflow: hidden scroll;
max-height: 128px;
.chat-panel-images { .chat-panel-images {
display: flex; display: flex;
gap: 4px; gap: 4px;
@@ -167,6 +171,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
} }
} }
} }
}
.chat-panel-send svg rect { .chat-panel-send svg rect {
fill: var(--affine-primary-color); fill: var(--affine-primary-color);
@@ -242,12 +247,13 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
private _renderImages(images: File[]) { private _renderImages(images: File[]) {
return html` return html`
<div <div
class="chat-panel-images" class="chat-panel-images-wrapper"
@mouseleave=${() => { @mouseleave=${() => {
this.closeWrapper.style.display = 'none'; this.closeWrapper.style.display = 'none';
this.curIndex = -1; this.curIndex = -1;
}} }}
> >
<div class="chat-panel-images">
${repeat( ${repeat(
images, images,
image => image.name, image => image.name,
@@ -257,10 +263,11 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
@mouseenter=${(evt: MouseEvent) => { @mouseenter=${(evt: MouseEvent) => {
const ele = evt.target as HTMLImageElement; const ele = evt.target as HTMLImageElement;
const rect = ele.getBoundingClientRect(); const rect = ele.getBoundingClientRect();
assertExists(ele.parentElement); assertExists(ele.parentElement?.parentElement);
const parentRect = ele.parentElement.getBoundingClientRect(); const parentRect =
ele.parentElement.parentElement.getBoundingClientRect();
const left = Math.abs(rect.right - parentRect.left) - 8; const left = Math.abs(rect.right - parentRect.left) - 8;
const top = Math.abs(parentRect.top - rect.top) - 8; const top = Math.abs(parentRect.top - rect.top);
this.curIndex = index; this.curIndex = index;
this.closeWrapper.style.display = 'flex'; this.closeWrapper.style.display = 'flex';
this.closeWrapper.style.left = left + 'px'; this.closeWrapper.style.left = left + 'px';
@@ -270,6 +277,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
<img src="${URL.createObjectURL(image)}" alt="${image.name}" /> <img src="${URL.createObjectURL(image)}" alt="${image.name}" />
</div>` </div>`
)} )}
</div>
<div <div
class="close-wrapper" class="close-wrapper"
@click=${() => { @click=${() => {

View File

@@ -249,7 +249,7 @@ export const getSelectedImagesAsBlobs = async (host: EditorHost) => {
chain.getImageSelections(), chain.getImageSelections(),
]) ])
.getSelectedBlocks({ .getSelectedBlocks({
types: ['image'], types: ['block', 'image'],
}) })
.run(); .run();