mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
93b1d6c729
Related to: [BS-3143](https://linear.app/affine-design/issue/BS-3143/更新-loading-和错误样式) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a unified resource controller for managing image and attachment resources, providing improved loading, error, and state handling. - Added a visual loading indicator overlay to image blocks for better feedback during image loading. - **Improvements** - Simplified and centralized image and attachment state management, reducing redundant properties and manual state tracking. - Updated fallback UI for image blocks with clearer titles, descriptions, and improved layout. - Enhanced batch image block creation and download handling for improved efficiency. - Refined image block accessibility with improved alt text and streamlined rendering logic. - Centralized target model selection for image insertion in AI actions. - Reordered CSS declarations without affecting styling. - Improved reactive state tracking for blob upload/download operations in mock server. - **Bug Fixes** - Improved cleanup of object URLs to prevent resource leaks. - Adjusted toolbar logic to more accurately reflect available actions based on image state. - **Tests** - Updated end-to-end tests to match new UI text and behaviors for image loading and error states. - **Chores** - Refactored internal logic and updated comments for clarity and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
127 lines
3.4 KiB
TypeScript
127 lines
3.4 KiB
TypeScript
import type { ResolvedStateInfo } from '@blocksuite/affine-components/resource';
|
|
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
|
import { WithDisposable } from '@blocksuite/global/lit';
|
|
import { ShadowlessElement } from '@blocksuite/std';
|
|
import { css, html } from 'lit';
|
|
import { property } from 'lit/decorators.js';
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
|
|
export const SURFACE_IMAGE_CARD_WIDTH = 220;
|
|
export const SURFACE_IMAGE_CARD_HEIGHT = 122;
|
|
export const NOTE_IMAGE_CARD_WIDTH = 752;
|
|
export const NOTE_IMAGE_CARD_HEIGHT = 78;
|
|
|
|
export class ImageBlockFallbackCard extends WithDisposable(ShadowlessElement) {
|
|
static override styles = css`
|
|
affine-image-fallback-card {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
user-select: none;
|
|
}
|
|
|
|
.affine-image-fallback-card {
|
|
display: flex;
|
|
flex: 1;
|
|
gap: 8px;
|
|
align-self: stretch;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
border-radius: 8px;
|
|
border: 1px solid ${unsafeCSSVarV2('layer/background/tertiary')};
|
|
background: ${unsafeCSSVarV2('layer/background/secondary')};
|
|
padding: 12px;
|
|
}
|
|
|
|
.truncate {
|
|
align-self: stretch;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.affine-image-fallback-card-title {
|
|
display: flex;
|
|
flex-direction: row;
|
|
gap: 8px;
|
|
align-items: center;
|
|
align-self: stretch;
|
|
}
|
|
|
|
.affine-image-fallback-card-title-icon {
|
|
display: flex;
|
|
width: 16px;
|
|
height: 16px;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--affine-text-primary-color);
|
|
}
|
|
|
|
.affine-image-fallback-card-title-text {
|
|
color: var(--affine-placeholder-color);
|
|
font-family: var(--affine-font-family);
|
|
font-size: var(--affine-font-sm);
|
|
font-style: normal;
|
|
font-weight: 600;
|
|
line-height: 22px;
|
|
}
|
|
|
|
.affine-image-fallback-card-description {
|
|
color: var(--affine-text-secondary-color);
|
|
font-family: var(--affine-font-family);
|
|
font-size: var(--affine-font-xs);
|
|
font-style: normal;
|
|
font-weight: 400;
|
|
line-height: 20px;
|
|
}
|
|
|
|
.affine-image-fallback-card.loading {
|
|
.affine-image-fallback-card-title {
|
|
color: var(--affine-placeholder-color);
|
|
}
|
|
}
|
|
|
|
.affine-image-fallback-card.error {
|
|
.affine-image-fallback-card-title-icon {
|
|
color: ${unsafeCSSVarV2('status/error')};
|
|
}
|
|
}
|
|
`;
|
|
|
|
override render() {
|
|
const { icon, title, description, loading, error } = this.state;
|
|
|
|
const classInfo = {
|
|
'affine-image-fallback-card': true,
|
|
'drag-target': true,
|
|
loading,
|
|
error,
|
|
};
|
|
|
|
return html`
|
|
<div class=${classMap(classInfo)}>
|
|
<div class="affine-image-fallback-card-title">
|
|
<div class="affine-image-fallback-card-title-icon">${icon}</div>
|
|
<div class="affine-image-fallback-card-title-text truncate">
|
|
${title}
|
|
</div>
|
|
</div>
|
|
<div class="affine-image-fallback-card-description truncate">
|
|
${description}
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
@property({ attribute: false })
|
|
accessor state!: ResolvedStateInfo;
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'affine-image-fallback-card': ImageBlockFallbackCard;
|
|
}
|
|
}
|