Editor libraries
The editor splits its larger surfaces into role libraries. Import only the ones you use.
document_editor_view.dart
Host-built view controls, without importing the complete workspace.
| Capability | API |
|---|---|
| Read mounted geometry | PaginatedCanvasController, PaginatedCanvasSnapshot, DocumentView |
| Choose an arrangement | resolveDocumentCanvasLayoutChoice(currentLayoutMode:, layoutMode:, zoom:) returns the shared arrangement/zoom intent |
| Fit and zoom | resolveDocumentZoomFit, DocumentZoomSliderRow, documentZoomPresets, paginatedCanvasZoomStep |
| Custom slider | documentZoomSliderPosition and documentZoomForSliderPosition share the logarithmic track and percentage snapping |
| Frame below toolbars | DocumentEditorContentFrame, DocumentRulerFrame, DocumentEditorThemeScope |
| Style ruler markers | DocumentEditorTheme.rulerAccentColor, .rulerMarkerCornerRadius; zero radius gives sharp corners |
| Supply control strings | DocumentEditorLocalizations.delegateFor; ruler and zoom strings currently use it |
| Present preparation | DocumentPreparationStatus, DocumentPreparationReason, DocumentPreparingBuilder; set DocumentEditorTheme.preparingBuilder |
| Anchor a host card | showDocumentPopover<T>(context, anchorRect:, semanticLabel:, builder:) shares the document-menu adapter |
Apply arrangement and zoom results through the same callbacks bound to the editor. In runtime paginated hosts, wire onZoomChanged back to zoom; gesture and shortcut intents need that binding. Read the current canvas rather than keeping another reading camera. Slider drags preview locally and commit once at the end.
Popover anchors use global logical pixels. The helper captures theme and localizations, returns the chosen result (or null on dismissal), and closes on outside press, Escape or navigation. Its anchor is a snapshot; dismiss/reopen when changing the underlying target. Capture host dependencies before opening, as with Flutter's showMenu. The context menu and host card use the same CDX placement, keyboard and transient-surface machinery.
dart
import 'package:flutter/widgets.dart';
import 'package:vyuh_document_editor/document_editor_view.dart';
import 'package:vyuh_document_editor/vyuh_document_editor.dart' as runtime;
// Install above DocumentEditor: framing stays below its built-in toolbar.
Widget frameHostEditor({
required runtime.DocumentEditorController controller,
required PaginatedCanvasController canvas,
required Widget editor,
}) => DocumentEditorThemeScope(
theme: DocumentEditorTheme.light().copyWith(rulerMarkerCornerRadius: 2),
child: DocumentEditorContentFrame(
frame: (viewport) => DocumentRulerFrame(
controller: controller,
canvasController: canvas,
onSectionFormatChanged: controller.setSectionFormat,
child: viewport,
),
child: editor,
),
);
// Reuse the existing host zoom binding. This control owns no camera state.
Widget hostZoomSlider({
required PaginatedCanvasController canvas,
required ValueChanged<double> onZoomChanged,
}) => ListenableBuilder(
listenable: canvas,
builder: (_, _) => DocumentZoomSliderRow(
zoom: canvas.snapshot?.zoom ?? 1,
onChanged: onZoomChanged,
),
);
double fitHostPages(PaginatedCanvasSnapshot snapshot) =>
resolveDocumentZoomFit(snapshot, DocumentZoomFit.width);
Future<String?> showWordCard(BuildContext context, Rect globalWordRect) =>
showDocumentPopover<String>(
context,
anchorRect: globalWordRect,
semanticLabel: 'Word details',
builder: (_, close) => GestureDetector(
onTap: () => close('selected'),
child: const Padding(
padding: EdgeInsets.all(12),
child: Text('Select this word'),
),
),
);
class HostDocumentStrings extends DocumentEditorLocalizations {
const HostDocumentStrings();
@override
String get showRulers => 'Afficher les règles';
@override
String get hideRulers => 'Masquer les règles';
@override
String get zoom => 'Échelle';
}
// Add this delegate to MaterialApp.localizationsDelegates alongside the app's
// usual Flutter delegates and supportedLocales. English remains the fallback.
final hostDocumentStrings = DocumentEditorLocalizations.delegateFor(
(locale) => locale.languageCode == 'fr'
? const HostDocumentStrings()
: const DocumentEditorLocalizations(),
);The localization delegate covers ruler visibility, slider and preparation labels. Other built-in strings remain tracked in feedback #23.
document_editor_workspace.dart
Application chrome around the editor (about 330 names).
| Group | Main types |
|---|---|
| Theme and scaffold | DocumentEditorTheme, DocumentEditorWorkspaceScaffold, DocumentEditorWorkspaceSession |
| Ribbon and toolbars | DocumentEditorWorkspaceRibbon, DocumentEditorRibbon, DocumentWorkspaceToolbar, DocumentMenuBar, DocumentCommandPalette, RibbonMenuButton, RibbonToolButton, RibbonChoicePanel |
| Properties | DocumentPropertiesWorkspace, DocumentPropertiesWorkspaceController, DocumentPropertiesPanel, DocumentPropertiesRegistry, documentPropertiesRegistryFor(registry) |
| Inspector access | DocumentInspectorConfiguration, DocumentInspectorAccess, DocumentInspectorAddress |
| Dialogs and menus | LinkUrlDialog, DocumentExportMenu, DocumentInsertMenu (over documentInsertActions), PageSetupMenu, DocumentFormFieldDialog, showKeyboardShortcutsDialog |
| Rulers | DocumentRulerFrame, DocumentRulerUnit |
| Review and navigation | DocumentReviewWorkspacePanel, DocumentNavigationOutline, DocumentPageThumbnailOutline |
| Slash commands | SlashCommandPalette (the default trigger presenter), documentSlashTrigger, buildDocumentSlashCommandCatalog (the registered and provided actions whose insertKind is not none) |
Guides: Components, Property inspector, tutorial step 8.
document_editor_extensions.dart
Extension classes and authoring contracts.
| Group | Main types |
|---|---|
| Starter extensions | ParagraphDocumentExtension, TextEditingDocumentExtension, ListDocumentExtension, FieldDocumentExtension. The block quote, checklist, code block, divider, image, shape, table, text box and table of contents extensions are in their own _editor packages, collected by vyuh_document_editor_elements. |
| Registry | ElementRegistry, DocumentHostExtension, EditorAction, EditorActionProvider, EditorActionContext, EditorActionSurface, DocumentContextMenuPlacement, DocumentContextMenuTarget, InlineInteractionContribution, InlineInteraction, InlineInteractionContext, DocumentKeyHandler, DocumentTriggerContribution, InputRule, ElementActivationContribution, ElementPropertiesContribution |
| Views | buildParagraphView, TextBoxView |
| Element-declared chrome | ElementOutlineContributor, ElementBlockStrokeContributor, ElementBlockColorContributor |
| Placement | EditorImagePlacement, generated-graphic and floating-block placement helpers |
Guide: Build an extension.
document_editor_rendering.dart
Re-exports layout.dart plus Flutter rendering: DocumentPreview (read-only view of a controller), PaginatedDocumentView, FlutterDocumentMeasurementPort, caret and selection painters, block views, scrollbars, watermark and line-number layers.
document_editor_integration.dart
Host services: waitForCurrentExportLayout, waitForCurrentExportResources, DocumentExportLayoutSuperseded, import pipelines (DocumentImporter), clipboard adapters and platform bindings.
document_code_editor.dart
DocumentSourceCodeEditor, DocumentCodePropertyEditor and code diagnostics/syntax contracts for element source editing (Mermaid, KaTeX, code blocks).
diagnostics.dart
Paint audit and frame probes for performance work. Not needed by apps.