Implementation:AFK surf Open agent Mount Default Doc Editor
| Knowledge Sources | |
|---|---|
| Domains | Editor, Web_Components, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Concrete orchestrator that resolves the target document from URL parameters, creates the editor app, sets the primary mode, applies URL-driven mode overrides, and attaches hash-change navigation.
Description
mountDefaultDocEditor is the entry point for mounting the starter playground editor. It resolves the doc from the URL (via getDocFromUrlParams), delegates to createTestApp to build the editor + debug panels, queries the DocModeProvider for the primary mode, applies URL ?mode= overrides (via setDocModeFromUrlParams), and registers a hash-change listener (listenHashChange) so browser navigation swaps documents. The companion createTestApp appends the editor to #app, instantiates the debug menu, docs panel, frame panel, outline panel/viewer, adapter panel (with transformer middlewares), comment panel, and attachment viewer, and sets the global window.editor/window.doc/window.host/window.std debug handles.
Usage
Call this function after initStarterDocCollection. Used by the starter playground main() and any custom integration that wants the full playground mount (editor + debug panels + hash navigation).
Code Reference
Source Location
- Repository: Open-Agent
- File: blocksuite/playground/apps/starter/utils/setup-playground.ts (L12-42); createTestApp in blocksuite/playground/apps/starter/utils/app.ts (L20-93)
Signature
async function mountDefaultDocEditor(
collection: Workspace
): Promise<TestAffineEditorContainer>;
async function createTestApp(
doc: Store,
collection: Workspace
): Promise<TestAffineEditorContainer>;
Import
import { mountDefaultDocEditor } from './utils/setup-playground';
import { createTestApp } from './utils/app.js';
import { DocModeProvider } from '@blocksuite/affine/shared/services';
import {
getDocFromUrlParams,
listenHashChange,
setDocModeFromUrlParams,
} from '../../_common/history.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| collection | Workspace | Yes | The collection whose docs are addressable via URL |
| URL params (docId, mode, init) | string | Drive doc selection, mode, multi-editor layout |
Outputs
| Name | Type | Description |
|---|---|---|
| editor | TestAffineEditorContainer | Editor appended to #app; debug panels appended to body; global debug handles set; hash navigation attached |
Usage Examples
Standard Mount
await initStarterDocCollection(collection);
await mountDefaultDocEditor(collection);
// Editor is live in #app; navigate via #docId or ?docId=...
Custom createTestApp
const doc = getDocFromUrlParams(collection, new URL(location.toString()));
const editor = await createTestApp(doc, collection);
// createTestApp appends editor + all debug panels and sets window.editor