import { EditorHost, ShadowlessElement, WithDisposable, } from '@cbi-blocksuite/block-std'; import { PageEditorBlockSpecs } from '@cbi-blocksuite/blocks'; import { noop } from '@cbi-blocksuite/global/utils'; import type { Doc } from '@cbi-blocksuite/store'; import { css, html, nothing } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { createRef, type Ref, ref } from 'lit/directives/ref.js'; noop(EditorHost); @customElement('page-editor') export class PageEditor extends WithDisposable(ShadowlessElement) { static override styles = css` page-editor { font-family: var(--affine-font-family); background: var(--affine-background-primary-color); } page-editor * { box-sizing: border-box; } @media print { page-editor { height: auto; } } .affine-page-viewport { position: relative; height: 100%; overflow-x: hidden; overflow-y: auto; container-name: viewport; container-type: inline-size; } .page-editor-container { display: block; height: 100%; } `; @property({ attribute: false }) doc!: Doc; @property({ attribute: false }) specs = PageEditorBlockSpecs; @property({ type: Boolean }) hasViewport = true; private _host: Ref = createRef(); get host() { return this._host.value as EditorHost; } override connectedCallback() { super.connectedCallback(); this._disposables.add( this.doc.slots.rootAdded.on(() => this.requestUpdate()) ); } override async getUpdateComplete(): Promise { const result = await super.getUpdateComplete(); await this.host.updateComplete; return result; } override render() { if (!this.doc.root) return nothing; return html`
`; } } declare global { interface HTMLElementTagNameMap { 'page-editor': PageEditor; } }