Typed identifiers
No public API takes a string to name an action, a toolbar section, an operation or a mark. You pass a typed value, such as MarkActionId.bold, TableActionId.insert, CoreDocumentOperation.textInsert or TextMark.bold, so a typo fails at compile time and your editor lists what exists.
Who declares what
Each owner declares its own closed set next to its code: an enum, or a final class when an identifier carries data.
| Identifies | Interface | Declared by |
|---|---|---|
| Editor actions | EditorActionId | The editor (HistoryActionId, MarkActionId, TableActionId, WorkspaceCommandId, …) and each extension (KatexActionId, MermaidActionId, DiagramActionId, CitationActionId) |
| Toolbar sections | DocumentToolbarSectionId | The editor (EditorToolbarSectionId) and extensions |
| Document operations | DocumentOperationId | The core (CoreDocumentOperation, DocumentWorkflowOperation) and extensions |
| Marks | TextMark | The core |
Declare and use action IDs
dart
import 'package:vyuh_document_editor/vyuh_document_editor.dart';
// An extension declares its actions as one closed set. `key` is the persisted
// spelling (saved toolbar settings, widget keys); it is written only here.
enum StampActionId with EditorActionKey implements EditorActionId {
approved('stamp-approved'),
rejected('stamp-rejected');
const StampActionId(this.key);
@override
final String key;
}
// Hosts name actions by value, so a typo or a missing action does not compile.
final configuration = DocumentEditorConfiguration(
toolbar: DocumentToolbarConfiguration(
actionIds: {
HistoryActionId.undo,
MarkActionId.bold,
StampActionId.approved,
},
),
policy: DocumentEditorPolicy(disabledActionIds: {StampActionId.rejected}),
);Register each action with its typed id (EditorAction.toolbar(id: StampActionId.approved, …)). Toolbars, policies, menus and the command palette then refer to it by that value.
Where strings remain
Strings appear only where something is stored or sent:
- Saved keys.
id.keyis what saved toolbar settings and widget keys hold.registry.decodeActionKeys(keys)reads them back, returning the matchingidsand anyunknownKeys. - The wire format. Transactions and receipts carry an operation's
wireName(text.insert). - Content data. Block IDs and source IDs are your own strings.