Files
upstream-affine/blocksuite/integration-test/src/editors/editor-container.ts
upstream-mirror 50f788e799
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:31:07 +05:00

226 lines
5.0 KiB
TypeScript

import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import type { DocMode } from '@blocksuite/affine/model';
import { ThemeProvider } from '@blocksuite/affine/shared/services';
import { BlockStdScope, ShadowlessElement } from '@blocksuite/affine/std';
import {
type BlockModel,
type ExtensionType,
type Store,
} from '@blocksuite/affine/store';
import { computed, signal } from '@preact/signals-core';
import { css, html } from 'lit';
import { property } from 'lit/decorators.js';
import { keyed } from 'lit/directives/keyed.js';
import { when } from 'lit/directives/when.js';
export class TestAffineEditorContainer extends SignalWatcher(
WithDisposable(ShadowlessElement)
) {
static override styles = css`
.affine-page-viewport {
position: relative;
display: flex;
flex-direction: column;
overflow-x: hidden;
overflow-y: auto;
container-name: viewport;
container-type: inline-size;
font-family: var(--affine-font-family);
}
.affine-page-viewport * {
box-sizing: border-box;
}
@media print {
.affine-page-viewport {
height: auto;
}
}
.playground-page-editor-container {
flex-grow: 1;
font-family: var(--affine-font-family);
display: block;
}
.playground-page-editor-container * {
box-sizing: border-box;
}
@media print {
.playground-page-editor-container {
height: auto;
}
}
.edgeless-editor-container {
font-family: var(--affine-font-family);
background: var(--affine-background-primary-color);
display: block;
height: 100%;
position: relative;
overflow: clip;
}
.edgeless-editor-container * {
box-sizing: border-box;
}
@media print {
.edgeless-editor-container {
height: auto;
}
}
.affine-edgeless-viewport {
display: block;
height: 100%;
position: relative;
overflow: clip;
container-name: viewport;
container-type: inline-size;
}
`;
private readonly _doc = signal<Store>();
private readonly _edgelessSpecs = signal<ExtensionType[]>([]);
private readonly _mode = signal<DocMode>('page');
private readonly _pageSpecs = signal<ExtensionType[]>([]);
private readonly _specs = computed(() =>
this._mode.value === 'page'
? this._pageSpecs.value
: this._edgelessSpecs.value
);
private readonly _std = computed(() => {
return new BlockStdScope({
store: this.doc,
extensions: this._specs.value,
});
});
private readonly _editorTemplate = computed(() => {
return this._std.value.render();
});
get doc() {
return this._doc.value as Store;
}
set doc(doc: Store) {
this._doc.value = doc;
}
set edgelessSpecs(specs: ExtensionType[]) {
this._edgelessSpecs.value = specs;
}
get edgelessSpecs() {
return this._edgelessSpecs.value;
}
get host() {
try {
return this.std.host;
} catch {
return null;
}
}
get mode() {
return this._mode.value;
}
set mode(mode: DocMode) {
this._mode.value = mode;
}
set pageSpecs(specs: ExtensionType[]) {
this._pageSpecs.value = specs;
}
get pageSpecs() {
return this._pageSpecs.value;
}
get rootModel() {
return this.doc.root as BlockModel;
}
get std() {
return this._std.value;
}
override connectedCallback() {
super.connectedCallback();
this._disposables.add(
this.doc.slots.rootAdded.subscribe(() => this.requestUpdate())
);
}
override firstUpdated() {
if (this.mode === 'page') {
setTimeout(() => {
if (this.autofocus && this.mode === 'page') {
const richText = this.querySelector('rich-text');
const inlineEditor = richText?.inlineEditor;
inlineEditor?.focusEnd();
}
});
}
}
override render() {
const mode = this._mode.value;
const themeService = this.std.get(ThemeProvider);
const appTheme = themeService.app$.value;
const edgelessTheme = themeService.edgeless$.value;
return html`${keyed(
this.rootModel.id + mode,
html`
<div
data-theme=${mode === 'page' ? appTheme : edgelessTheme}
class=${
mode === 'page'
? 'affine-page-viewport'
: 'affine-edgeless-viewport'
}
>
${when(
mode === 'page',
() => html` <doc-title .doc=${this.doc}></doc-title> `
)}
<div
class=${
mode === 'page'
? 'page-editor playground-page-editor-container'
: 'edgeless-editor-container'
}
>
${this._editorTemplate.value}
</div>
</div>
`
)}`;
}
switchEditor(mode: DocMode) {
this._mode.value = mode;
}
@property({ attribute: false })
override accessor autofocus = false;
}
declare global {
interface HTMLElementTagNameMap {
'affine-editor-container': TestAffineEditorContainer;
}
}