mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 21:06:22 +08:00
19e9f970f4
Related to: https://github.com/toeverything/AFFiNE/pull/9849 Currently missing selected style in note under edgeless. <img width="860" alt="Screenshot 2025-02-20 at 20 51 12" src="https://github.com/user-attachments/assets/77d68cfb-13d0-4e09-a567-f2a30ba72db1" />
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
|
import type { HoverController } from '@blocksuite/affine-components/hover';
|
|
import { AttachmentBlockStyles } from '@blocksuite/affine-model';
|
|
import {
|
|
EMBED_CARD_HEIGHT,
|
|
EMBED_CARD_WIDTH,
|
|
} from '@blocksuite/affine-shared/consts';
|
|
import { toGfxBlockComponent } from '@blocksuite/block-std';
|
|
import { styleMap } from 'lit/directives/style-map.js';
|
|
|
|
import { AttachmentBlockComponent } from './attachment-block.js';
|
|
|
|
export class AttachmentEdgelessBlockComponent extends toGfxBlockComponent(
|
|
AttachmentBlockComponent
|
|
) {
|
|
protected override _whenHover: HoverController | null = null;
|
|
|
|
override blockDraggable = false;
|
|
|
|
get slots() {
|
|
return this.std.get(EdgelessLegacySlotIdentifier);
|
|
}
|
|
|
|
override connectedCallback(): void {
|
|
super.connectedCallback();
|
|
|
|
this._disposables.add(
|
|
this.slots.elementResizeStart.on(() => {
|
|
this._isResizing = true;
|
|
this._showOverlay = true;
|
|
})
|
|
);
|
|
|
|
this._disposables.add(
|
|
this.slots.elementResizeEnd.on(() => {
|
|
this._isResizing = false;
|
|
this._showOverlay =
|
|
this._isResizing || this._isDragging || !this.selected$.peek();
|
|
})
|
|
);
|
|
}
|
|
|
|
override onClick(_: MouseEvent) {
|
|
return;
|
|
}
|
|
|
|
override renderGfxBlock() {
|
|
const { style$ } = this.model;
|
|
const cardStyle = style$.value ?? AttachmentBlockStyles[1];
|
|
const width = EMBED_CARD_WIDTH[cardStyle];
|
|
const height = EMBED_CARD_HEIGHT[cardStyle];
|
|
const bound = this.model.elementBound;
|
|
const scaleX = bound.w / width;
|
|
const scaleY = bound.h / height;
|
|
|
|
this.containerStyleMap = styleMap({
|
|
width: `${width}px`,
|
|
height: `${height}px`,
|
|
transform: `scale(${scaleX}, ${scaleY})`,
|
|
transformOrigin: '0 0',
|
|
overflow: 'hidden',
|
|
});
|
|
|
|
return this.renderPageContent();
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'affine-edgeless-attachment': AttachmentEdgelessBlockComponent;
|
|
}
|
|
}
|