From b4f56c0a78cc0efb4d6f4ab1237b9b8d5593458f Mon Sep 17 00:00:00 2001 From: fundon Date: Wed, 7 May 2025 13:20:51 +0000 Subject: [PATCH] fix(editor): attachment size in embed view (#12177) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: [BS-3434](https://linear.app/affine-design/issue/BS-3434/修复-attachment-从-card-切换为-embed-尺寸问题) Screenshot 2025-05-07 at 20 38 53 ## Summary by CodeRabbit - **New Features** - Added dedicated embed actions for PDF and video attachments, ensuring consistent sizing and improved rendering for these media types. - **Refactor** - Centralized PDF and video embed card dimensions using shared constants for more consistent and maintainable sizing. - Improved styling for video embeds, including better layout and responsive sizing. --- .../affine/blocks/attachment/src/embed.ts | 54 +++++++++++++++---- .../extensions/attachment-embed-view.tsx | 8 ++- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/blocksuite/affine/blocks/attachment/src/embed.ts b/blocksuite/affine/blocks/attachment/src/embed.ts index 6a44d9ee94..f2f91fcecb 100644 --- a/blocksuite/affine/blocks/attachment/src/embed.ts +++ b/blocksuite/affine/blocks/attachment/src/embed.ts @@ -3,6 +3,10 @@ import { type ImageBlockProps, MAX_IMAGE_WIDTH, } from '@blocksuite/affine-model'; +import { + EMBED_CARD_HEIGHT, + EMBED_CARD_WIDTH, +} from '@blocksuite/affine-shared/consts'; import { FileSizeLimitProvider } from '@blocksuite/affine-shared/services'; import { readImageSize, @@ -17,6 +21,7 @@ import type { ExtensionType } from '@blocksuite/store'; import { Extension } from '@blocksuite/store'; import type { TemplateResult } from 'lit'; import { html } from 'lit'; +import { styleMap } from 'lit/directives/style-map.js'; import { getAttachmentBlob } from './utils'; @@ -97,11 +102,13 @@ export class AttachmentEmbedService extends Extension { // Converts to embed view. convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) { const config = this.values.find(config => config.check(model, maxFileSize)); - if (!config?.action) { - model.store.updateBlock(model, { embed: true }); + + if (config?.action) { + config.action(model, this.std)?.catch(console.error); return; } - config.action(model, this.std)?.catch(console.error); + + model.store.updateBlock(model, { embed: true }); } embedded(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) { @@ -142,14 +149,27 @@ const embedConfig: AttachmentEmbedConfig[] = [ name: 'pdf', check: (model, maxFileSize) => model.props.type === 'application/pdf' && model.props.size <= maxFileSize, + action: model => { + const bound = Bound.deserialize(model.props.xywh); + bound.w = EMBED_CARD_WIDTH.pdf; + bound.h = EMBED_CARD_HEIGHT.pdf; + model.store.updateBlock(model, { + embed: true, + style: 'pdf', + xywh: bound.serialize(), + }); + }, template: (_, blobUrl) => { // More options: https://tinytip.co/tips/html-pdf-params/ // https://chromium.googlesource.com/chromium/src/+/refs/tags/121.0.6153.1/chrome/browser/resources/pdf/open_pdf_params_parser.ts const parameters = '#toolbar=0'; return html`