import { OpenIcon } from '@blocksuite/affine-components/icons'; import type { EmbedFigmaModel, EmbedFigmaStyles, } from '@blocksuite/affine-model'; import { BlockSelection } from '@blocksuite/block-std'; import { html } from 'lit'; import { state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { styleMap } from 'lit/directives/style-map.js'; import { EmbedBlockComponent } from '../common/embed-block-element.js'; import type { EmbedFigmaBlockService } from './embed-figma-service.js'; import { FigmaIcon, styles } from './styles.js'; export class EmbedFigmaBlockComponent extends EmbedBlockComponent< EmbedFigmaModel, EmbedFigmaBlockService > { static override styles = styles; override _cardStyle: (typeof EmbedFigmaStyles)[number] = 'figma'; protected _isDragging = false; protected _isResizing = false; open = () => { let link = this.model.url; if (!link.match(/^[a-zA-Z]+:\/\//)) { link = 'https://' + link; } window.open(link, '_blank'); }; refreshData = () => {}; private _handleDoubleClick(event: MouseEvent) { event.stopPropagation(); this.open(); } private _selectBlock() { const selectionManager = this.host.selection; const blockSelection = selectionManager.create(BlockSelection, { blockId: this.blockId, }); selectionManager.setGroup('note', [blockSelection]); } protected _handleClick(event: MouseEvent) { event.stopPropagation(); this._selectBlock(); } override connectedCallback() { super.connectedCallback(); this._cardStyle = this.model.style; if (!this.model.description && !this.model.title) { this.doc.withoutTransact(() => { this.doc.updateBlock(this.model, { title: 'Figma', description: this.model.url, }); }); } this.disposables.add( this.model.propsUpdated.on(({ key }) => { if (key === 'url') { this.refreshData(); } }) ); // this is required to prevent iframe from capturing pointer events this.disposables.add( this.selected$.subscribe(selected => { this._showOverlay = this._isResizing || this._isDragging || !selected; }) ); // this is required to prevent iframe from capturing pointer events this.handleEvent('dragStart', () => { this._isDragging = true; this._showOverlay = this._isResizing || this._isDragging || !this.selected$.peek(); }); this.handleEvent('dragEnd', () => { this._isDragging = false; this._showOverlay = this._isResizing || this._isDragging || !this.selected$.peek(); }); } override renderBlock() { const { title, description, url } = this.model; const titleText = title ?? 'Figma'; const descriptionText = description ?? url; return this.renderEmbed( () => html`