@@ -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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,29 +141,34 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-panel-images {
|
.chat-panel-images-wrapper {
|
||||||
display: flex;
|
overflow: hidden scroll;
|
||||||
gap: 4px;
|
max-height: 128px;
|
||||||
flex-wrap: wrap;
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
.image-container {
|
.chat-panel-images {
|
||||||
width: 58px;
|
|
||||||
height: 58px;
|
|
||||||
border-radius: 4px;
|
|
||||||
border: 1px solid var(--affine-border-color);
|
|
||||||
cursor: pointer;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
gap: 4px;
|
||||||
align-items: center;
|
flex-wrap: wrap;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
img {
|
.image-container {
|
||||||
max-width: 100%;
|
width: 58px;
|
||||||
max-height: 100%;
|
height: 58px;
|
||||||
width: auto;
|
border-radius: 4px;
|
||||||
height: auto;
|
border: 1px solid var(--affine-border-color);
|
||||||
|
cursor: pointer;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,34 +247,37 @@ 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;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
${repeat(
|
<div class="chat-panel-images">
|
||||||
images,
|
${repeat(
|
||||||
image => image.name,
|
images,
|
||||||
(image, index) =>
|
image => image.name,
|
||||||
html`<div
|
(image, index) =>
|
||||||
class="image-container"
|
html`<div
|
||||||
@mouseenter=${(evt: MouseEvent) => {
|
class="image-container"
|
||||||
const ele = evt.target as HTMLImageElement;
|
@mouseenter=${(evt: MouseEvent) => {
|
||||||
const rect = ele.getBoundingClientRect();
|
const ele = evt.target as HTMLImageElement;
|
||||||
assertExists(ele.parentElement);
|
const rect = ele.getBoundingClientRect();
|
||||||
const parentRect = ele.parentElement.getBoundingClientRect();
|
assertExists(ele.parentElement?.parentElement);
|
||||||
const left = Math.abs(rect.right - parentRect.left) - 8;
|
const parentRect =
|
||||||
const top = Math.abs(parentRect.top - rect.top) - 8;
|
ele.parentElement.parentElement.getBoundingClientRect();
|
||||||
this.curIndex = index;
|
const left = Math.abs(rect.right - parentRect.left) - 8;
|
||||||
this.closeWrapper.style.display = 'flex';
|
const top = Math.abs(parentRect.top - rect.top);
|
||||||
this.closeWrapper.style.left = left + 'px';
|
this.curIndex = index;
|
||||||
this.closeWrapper.style.top = top + 'px';
|
this.closeWrapper.style.display = 'flex';
|
||||||
}}
|
this.closeWrapper.style.left = left + 'px';
|
||||||
>
|
this.closeWrapper.style.top = top + 'px';
|
||||||
<img src="${URL.createObjectURL(image)}" alt="${image.name}" />
|
}}
|
||||||
</div>`
|
>
|
||||||
)}
|
<img src="${URL.createObjectURL(image)}" alt="${image.name}" />
|
||||||
|
</div>`
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="close-wrapper"
|
class="close-wrapper"
|
||||||
@click=${() => {
|
@click=${() => {
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ export const getSelectedImagesAsBlobs = async (host: EditorHost) => {
|
|||||||
chain.getImageSelections(),
|
chain.getImageSelections(),
|
||||||
])
|
])
|
||||||
.getSelectedBlocks({
|
.getSelectedBlocks({
|
||||||
types: ['image'],
|
types: ['block', 'image'],
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user