import { toEdgelessEmbedBlock } from '@blocksuite/affine-block-embed'; import { EdgelessCRUDIdentifier, reassociateConnectorsCommand, } from '@blocksuite/affine-block-surface'; import { type AliasInfo } from '@blocksuite/affine-model'; import { EMBED_CARD_HEIGHT, EMBED_CARD_WIDTH, } from '@blocksuite/affine-shared/consts'; import { ThemeExtensionIdentifier, ThemeProvider, } from '@blocksuite/affine-shared/services'; import { Bound } from '@blocksuite/global/gfx'; import { type BlockComponent, BlockStdScope } from '@blocksuite/std'; import { html, nothing } from 'lit'; import { query } from 'lit/decorators.js'; import { choose } from 'lit/directives/choose.js'; import { classMap } from 'lit/directives/class-map.js'; import { guard } from 'lit/directives/guard.js'; import { styleMap } from 'lit/directives/style-map.js'; import { EmbedSyncedDocConfigExtension } from './configs'; import { EmbedSyncedDocBlockComponent } from './embed-synced-doc-block'; export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock( EmbedSyncedDocBlockComponent ) { @query('.affine-embed-synced-doc-edgeless-header-wrapper') accessor headerWrapper: HTMLDivElement | null = null; @query('affine-preview-root') accessor contentElement: BlockComponent | null = null; protected override _renderSyncedView = () => { const { syncedDoc, editorMode } = this; if (!syncedDoc) { console.error('Synced doc is not found'); return html`${nothing}`; } let containerStyleMap = styleMap({ position: 'relative', width: '100%', }); const modelScale = this.model.props.scale ?? 1; const bound = Bound.deserialize(this.model.xywh); const width = bound.w / modelScale; const height = bound.h / modelScale; containerStyleMap = styleMap({ width: `${width}px`, height: `${height}px`, minHeight: `${height}px`, transform: `scale(${modelScale})`, transformOrigin: '0 0', }); const themeService = this.std.get(ThemeProvider); const themeExtension = this.std.getOptional(ThemeExtensionIdentifier); const appTheme = themeService.app$.value; let edgelessTheme = themeService.edgeless$.value; if (themeExtension?.getEdgelessTheme && this.syncedDoc?.id) { edgelessTheme = themeExtension.getEdgelessTheme(this.syncedDoc.id).value; } const theme = this.isPageMode ? appTheme : edgelessTheme; const scale = this.model.props.scale ?? 1; this.dataset.nestedEditor = ''; const renderEditor = () => { return choose(editorMode, [ [ 'page', () => html`
`, ], [ 'edgeless', () => html` `, ], ]); }; const header = this.std .getOptional(EmbedSyncedDocConfigExtension.identifier) ?.edgelessHeader({ model: this.model, std: this.std, }) ?? nothing; return this.renderEmbed( () => html`