mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 19:40:30 +08:00
2d3130eac9
Fixed compat error for new built-in template with test updated.  <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an option to enable or disable bitmap rendering in the renderer settings. - Introduced a cooldown period after zooming before block optimization resumes, improving rendering performance and stability. - **Bug Fixes** - Improved handling of cases where block components may be missing, preventing potential runtime errors. - **Tests** - Expanded and refined tests to verify zooming behavior, bitmap caching, and internal state transitions for enhanced reliability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import type { Rect } from '@blocksuite/affine-gfx-turbo-renderer';
|
|
import {
|
|
BlockLayoutHandlerExtension,
|
|
BlockLayoutHandlersIdentifier,
|
|
} from '@blocksuite/affine-gfx-turbo-renderer';
|
|
import type { Container } from '@blocksuite/global/di';
|
|
import type { EditorHost, GfxBlockComponent } from '@blocksuite/std';
|
|
import { clientToModelCoord, type ViewportRecord } from '@blocksuite/std/gfx';
|
|
import type { BlockModel } from '@blocksuite/store';
|
|
|
|
import type { ImageLayout } from './image-painter.worker';
|
|
|
|
export class ImageLayoutHandlerExtension extends BlockLayoutHandlerExtension<ImageLayout> {
|
|
readonly blockType = 'affine:image';
|
|
|
|
static override setup(di: Container) {
|
|
di.addImpl(
|
|
BlockLayoutHandlersIdentifier('image'),
|
|
ImageLayoutHandlerExtension
|
|
);
|
|
}
|
|
|
|
override queryLayout(
|
|
model: BlockModel,
|
|
host: EditorHost,
|
|
viewportRecord: ViewportRecord
|
|
): ImageLayout | null {
|
|
const component = host.std.view.getBlock(
|
|
model.id
|
|
) as GfxBlockComponent | null;
|
|
if (!component) return null;
|
|
|
|
const imageContainer = component.querySelector('.affine-image-container');
|
|
if (!imageContainer) return null;
|
|
|
|
const resizableImg = component.querySelector(
|
|
'.resizable-img'
|
|
) as HTMLElement;
|
|
if (!resizableImg) return null;
|
|
|
|
const { zoom, viewScale } = viewportRecord;
|
|
const rect = resizableImg.getBoundingClientRect();
|
|
|
|
const [modelX, modelY] = clientToModelCoord(viewportRecord, [
|
|
rect.x,
|
|
rect.y,
|
|
]);
|
|
|
|
const imageLayout: ImageLayout = {
|
|
type: 'affine:image',
|
|
blockId: model.id,
|
|
rect: {
|
|
x: modelX,
|
|
y: modelY,
|
|
w: rect.width / zoom / viewScale,
|
|
h: rect.height / zoom / viewScale,
|
|
},
|
|
};
|
|
|
|
return imageLayout;
|
|
}
|
|
|
|
calculateBound(layout: ImageLayout) {
|
|
const rect: Rect = layout.rect;
|
|
|
|
return {
|
|
rect,
|
|
subRects: [rect],
|
|
};
|
|
}
|
|
}
|