mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { DocModeProvider } from '@blocksuite/blocks';
|
|
import { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
|
import type { Workspace } from '@blocksuite/store';
|
|
|
|
import {
|
|
getDocFromUrlParams,
|
|
listenHashChange,
|
|
setDocModeFromUrlParams,
|
|
} from '../../_common/history.js';
|
|
import { createTestApp } from './app.js';
|
|
|
|
export async function mountDefaultDocEditor(collection: Workspace) {
|
|
const app = document.getElementById('app');
|
|
if (!app) return;
|
|
|
|
const url = new URL(location.toString());
|
|
const doc = getDocFromUrlParams(collection, url);
|
|
|
|
const editor = await createTestApp(doc, collection);
|
|
|
|
const modeService = editor.std.provider.get(DocModeProvider);
|
|
editor.mode = modeService.getPrimaryMode(doc.id);
|
|
setDocModeFromUrlParams(modeService, url.searchParams, doc.id);
|
|
|
|
// for multiple editor
|
|
const params = new URLSearchParams(location.search);
|
|
const init = params.get('init');
|
|
if (init && init.startsWith('multiple-editor')) {
|
|
app.childNodes.forEach(node => {
|
|
if (node instanceof TestAffineEditorContainer) {
|
|
node.style.flex = '1';
|
|
if (init === 'multiple-editor-vertical') {
|
|
node.style.overflow = 'auto';
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
listenHashChange(collection, editor);
|
|
|
|
return editor;
|
|
}
|