Principle:AFK surf Open agent Editor Container Assembly
| Knowledge Sources | |
|---|---|
| Domains | Editor, Web_Components, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of instantiating an editor custom element, assigning a loaded doc store, and assembling per-scope extension lists from a view manager and common extensions.
Description
The BlockSuite editor is a Lit custom element (affine-editor-container) whose behavior is composed from two extension lists: pageSpecs (page-mode rendering) and edgelessSpecs (whiteboard-mode rendering). Each list is the concatenation of scope-specific extensions from a ViewExtensionManager.get(scope) and a shared common extension list (font config, editor setting, parse-doc-url, DocModeProvider override, code-block preview). The editor is bound to a doc store (editor.doc = store) and a collection (for doc-link jumping). Interactive providers like RefNodeSlotsProvider subscribe to signals (e.g. docLinkClicked) to drive navigation. Feature flags gate advanced behaviors. This composition lets the same editor instance render very different surfaces just by swapping the spec list.
Usage
Apply this principle whenever you instantiate a BlockSuite editor or any web-components editor whose behavior is composed from extension lists. Keep scope-specific and common extensions separate so they can be reused and tested independently.
Theoretical Basis
The editor is an extension-composition container: specs = scopeExtensions ⊕ commonExtensions. The view manager resolves scope extensions per mode ('page', 'edgeless'); the common list provides cross-cutting services. DI providers (e.g. DocModeProvider) are overridden by passing a setup object that mutates the container.
Pseudo-code:
const editor = document.createElement('affine-editor-container');
editor.doc = store;
const common = getCommonExtensions(editor);
editor.pageSpecs = [...viewManager.get('page'), ...common];
editor.edgelessSpecs = [...viewManager.get('edgeless'), ...common];