Compare commits

...

1 Commits

Author SHA1 Message Date
Cats Juice
415308ea27
fix(core): fix ai input style in chat block and simply img rendering 2025-06-26 16:46:49 +08:00
3 changed files with 49 additions and 62 deletions

View File

@ -51,7 +51,8 @@ export class AIChatInput extends SignalWatcher(
0px 0px 0px 0px rgba(28, 158, 228, 0), 0px 0px 0px 0px rgba(28, 158, 228, 0),
0px 0px 0px 2px transparent; 0px 0px 0px 2px transparent;
} }
[data-theme='light'] .chat-panel-input { [data-theme='light'] .chat-panel-input,
.chat-panel-input {
box-shadow: box-shadow:
var(--border-shadow), var(--border-shadow),
0px 0px 0px 3px transparent, 0px 0px 0px 3px transparent,
@ -253,6 +254,10 @@ export class AIChatInput extends SignalWatcher(
font-size: 20px; font-size: 20px;
background: var(--affine-v2-icon-activated); background: var(--affine-v2-icon-activated);
color: var(--affine-v2-layer-pureWhite); color: var(--affine-v2-layer-pureWhite);
border: none;
padding: 0;
background: transparent;
cursor: pointer;
} }
.chat-panel-send[aria-disabled='true'] { .chat-panel-send[aria-disabled='true'] {
cursor: not-allowed; cursor: not-allowed;
@ -269,6 +274,9 @@ export class AIChatInput extends SignalWatcher(
border-radius: 50%; border-radius: 50%;
font-size: 24px; font-size: 24px;
color: var(--affine-v2-icon-activated); color: var(--affine-v2-icon-activated);
border: none;
padding: 0;
background: transparent;
} }
.chat-input-footer-spacer { .chat-input-footer-spacer {
flex: 1; flex: 1;

View File

@ -28,6 +28,9 @@ export class ChatInputPreference extends SignalWatcher(
color: var(--affine-v2-icon-primary); color: var(--affine-v2-icon-primary);
transition: all 0.23s ease; transition: all 0.23s ease;
border-radius: 4px; border-radius: 4px;
background: transparent;
border: none;
cursor: pointer;
} }
.chat-input-preference-trigger:hover { .chat-input-preference-trigger:hover {
background-color: var(--affine-v2-layer-background-hoverOverlay); background-color: var(--affine-v2-layer-background-hoverOverlay);

View File

@ -1,8 +1,9 @@
import { scrollbarStyle } from '@blocksuite/affine/shared/styles'; import { scrollbarStyle } from '@blocksuite/affine/shared/styles';
import { CloseIcon } from '@blocksuite/icons/lit'; import { CloseIcon } from '@blocksuite/icons/lit';
import { css, html, LitElement } from 'lit'; import { css, html, LitElement } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js'; import { repeat } from 'lit/directives/repeat.js';
import { styleMap } from 'lit/directives/style-map.js';
export class ImagePreviewGrid extends LitElement { export class ImagePreviewGrid extends LitElement {
static override styles = css` static override styles = css`
@ -11,6 +12,10 @@ export class ImagePreviewGrid extends LitElement {
overflow-y: hidden; overflow-y: hidden;
max-height: 80px; max-height: 80px;
white-space: nowrap; white-space: nowrap;
/* to prevent the close button from being clipped */
padding-top: 8px;
margin-top: -8px;
} }
${scrollbarStyle('.image-preview-wrapper')} ${scrollbarStyle('.image-preview-wrapper')}
@ -28,42 +33,42 @@ export class ImagePreviewGrid extends LitElement {
height: 68px; height: 68px;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
overflow: hidden;
position: relative; position: relative;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
flex: 0 0 auto; flex: 0 0 auto;
} border: 1px solid var(--affine-v2-layer-insideBorder-border);
background-size: cover;
.image-container img { background-position: center;
max-width: 100%; background-repeat: no-repeat;
max-height: 100%;
width: auto;
height: auto;
} }
.close-wrapper { .close-wrapper {
width: 16px; width: 16px;
height: 16px; height: 16px;
border-radius: 4px; border-radius: 4px;
border: 1px solid var(--affine-border-color); border: 0.5px solid var(--affine-v2-layer-insideBorder-border);
justify-content: center; justify-content: center;
align-items: center; align-items: center;
display: none; display: none;
position: absolute; position: absolute;
background-color: var(--affine-white); background-color: var(--affine-v2-layer-background-primary);
color: var(--affine-v2-icon-primary);
z-index: 1; z-index: 1;
cursor: pointer; cursor: pointer;
top: -6px;
right: -6px;
}
.image-container:hover .close-wrapper {
display: flex;
} }
.close-wrapper:hover { .close-wrapper:hover {
background-color: var(--affine-background-error-color); background-color: var(--affine-v2-layer-background-error);
border: 1px solid var(--affine-error-color); border: 0.5px solid var(--affine-v2-button-error);
} color: var(--affine-v2-button-error);
.close-wrapper:hover svg path {
fill: var(--affine-error-color);
} }
`; `;
@ -129,37 +134,11 @@ export class ImagePreviewGrid extends LitElement {
} }
}; };
private readonly _handleMouseEnter = (evt: MouseEvent, index: number) => { private readonly _handleDelete = (index: number) => {
const ele = evt.target as HTMLImageElement; const file = this.images[index];
const rect = ele.getBoundingClientRect(); const url = this._getObjectUrl(file);
if (!ele.parentElement) return; this._releaseObjectUrl(url);
const parentRect = ele.parentElement.getBoundingClientRect(); this.onImageRemove?.(index);
const left = Math.abs(rect.right - parentRect.left);
const top = Math.abs(parentRect.top - rect.top);
this.currentIndex = index;
if (!this.closeWrapper) return;
this.closeWrapper.style.display = 'flex';
this.closeWrapper.style.left = left + 'px';
this.closeWrapper.style.top = top + 'px';
};
private readonly _handleMouseLeave = () => {
if (!this.closeWrapper) return;
this.closeWrapper.style.display = 'none';
this.currentIndex = -1;
};
private readonly _handleDelete = () => {
if (this.currentIndex >= 0 && this.currentIndex < this.images.length) {
const file = this.images[this.currentIndex];
const url = this._getObjectUrl(file);
this._releaseObjectUrl(url);
this.onImageRemove?.(this.currentIndex);
this.currentIndex = -1;
if (!this.closeWrapper) return;
this.closeWrapper.style.display = 'none';
}
}; };
override disconnectedCallback() { override disconnectedCallback() {
@ -169,7 +148,7 @@ export class ImagePreviewGrid extends LitElement {
override render() { override render() {
return html` return html`
<div class="image-preview-wrapper" @mouseleave=${this._handleMouseLeave}> <div class="image-preview-wrapper">
<div class="images-container"> <div class="images-container">
${repeat( ${repeat(
this.images, this.images,
@ -180,18 +159,21 @@ export class ImagePreviewGrid extends LitElement {
<div <div
class="image-container" class="image-container"
@error=${() => this._releaseObjectUrl(url)} @error=${() => this._releaseObjectUrl(url)}
@mouseenter=${(evt: MouseEvent) => style=${styleMap({
this._handleMouseEnter(evt, index)} backgroundImage: `url(${url})`,
})}
> >
<img src="${url}" alt="${image.name}" /> <div
class="close-wrapper"
@click=${() => this._handleDelete(index)}
>
${CloseIcon()}
</div>
</div> </div>
`; `;
} }
)} )}
</div> </div>
<div class="close-wrapper" @click=${this._handleDelete}>
${CloseIcon()}
</div>
</div> </div>
`; `;
} }
@ -201,12 +183,6 @@ export class ImagePreviewGrid extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
accessor onImageRemove: ((index: number) => void) | null = null; accessor onImageRemove: ((index: number) => void) | null = null;
@query('.close-wrapper')
accessor closeWrapper: HTMLDivElement | null = null;
@state()
accessor currentIndex = -1;
} }
declare global { declare global {