Objects and commands
Looking for the typed API?
This page covers the editor runtime (DocumentEditorController and the canonical model). For DocumentController, typed commands and Result, see Typed Document API.
Everyday calls read directly: controller.insertText('Hello') or controller.setParagraphAlignment(TextAlignment.center). Extension packages supply those methods.
Core objects
| Object | Role |
|---|---|
Document | Immutable content: sections, styles, notes, review records. The value you save. |
DocumentEditorState | One snapshot: document, selection, viewport bookmark, revision. |
DocumentEditorController | Edits, selection, undo and redo; connects your app. |
DocumentWorkflowSession | The same editing without a widget. |
DocumentPosition / DocumentSelection | A block ID and offset; a base and extent. |
Pages are derived from the document. Address content by ID and logical position, not by page or widget coordinates.
Start with paragraphs
dart
import 'package:vyuh_document_editor/vyuh_document_editor.dart';
import 'package:vyuh_document/paragraph_extension.dart';
final controller = DocumentEditorController.richText(
layoutMode: DocumentEditorLayoutMode.pageless,
);
controller.insertText('Hello');
// Mount inside your own bounded widget; no workspace shell is required.
DocumentEditor(
controller: controller,
configuration: DocumentEditorConfiguration.richText(),
);Keep the controller in host state and dispose it with that state. The controller decides what can be edited; the configuration decides how it looks. Pass extensions and schema for a broader editor; the default constructor installs the full set. See the tutorial.
Configure the experience
| Decision | API |
|---|---|
| Content | DocumentEditorController.richText() for paragraphs; extensions and schema for more. Fixed for the controller's lifetime. |
| Layout | layoutMode at construction: paginated (default) or pageless. Use paged mode for headers, footers, notes and sections. |
| Controls | DocumentEditorConfiguration: toolbar, inspector, shortcuts, context menu. Hiding a control keeps the content capability. |
See extension composition and toolbar configuration.
Extension-owned methods
| Owner package | Examples of methods made visible by its import |
|---|---|
vyuh_document (paragraph_extension.dart) | insertText, deleteBackward, splitBlock, insertParagraph, insertHeading, toggleMark, setParagraphAlignment, setLink, requestLink |
vyuh_document_extension_code | insertCodeBlock, setCodeLanguage, setCodeBlockPresentation |
vyuh_document_extension_checklist | insertChecklistItem, setChecklistChecked |
vyuh_document_extension_list | insertListItem, setListMarker, setListNumberingSequence |
vyuh_document_extension_table | insertTable, insertRowBelow, setCellPadding, setTableAlignment |
vyuh_document_extension_image | insertImage, setImageSize, setImageFit, insertImageCaption, requestPictureChange |
vyuh_document_extension_field | insertInlineField, insertFootnote, insertEndnote |
vyuh_document_extension_block_quote | insertBlockQuote, setBlockQuoteTone, setBlockQuotePadding |
vyuh_document_extension_divider | insertDivider, setDividerFormat |
vyuh_document_extension_text_box | insertTextBox |
vyuh_document_extension_shape | insertShape |
vyuh_document_extension_table_of_contents | insertTableOfContents, setSelectedTableOfContentsConfig |
vyuh_document_extension_mermaid | insertMermaid, setMermaidGeometry, replaceMermaid |
vyuh_document_extension_katex | insertEquation, setEquationGeometry, replaceEquation |
vyuh_document_extension_diagram | insertDiagram, setDiagramGeometry, replaceDiagram |
Import the families whose methods your code uses; the editor barrel does not re-export them. Commands act on the current selection, or on the next typing when the selection is a caret.
Import visibility and runtime availability
An import makes a method visible; installing its DocumentExtension makes it run. Calling a command that is not installed throws DocumentCommandUnavailableException and changes nothing.
Generic controls can take a DocumentCommandTarget (implemented by the controller) and test hasCommand(TableDocumentCommands.insertTable) before offering an action. undo, redo, replaceDocument, selection and transaction live on the controller itself.
For multi-step edits, use transactions.