Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Reviewing a CKEditor 5 plugin (Trilium)
A structured checklist for reviewing Trilium CKEditor plugin code under packages/ckeditor5/src/plugins/.
Pair each item with the relevant reference file when you need the "why". Flag deviations; not
every item applies to every plugin (e.g. a UI-only or editing-only plugin). The Trilium
integration items at the end are specific to this monorepo.
Architecture & structure
- Editing/UI split: a glue plugin (
static get requires() { return [ XEditing, XUI ]; }), with schema/conversion/commands in*Editingand UI in*UI. Single-file plugins are ok for trivial features but a split is expected for anything reusable. -
static get pluginName()present (TS:as const) andstatic get requires()declares real dependencies (e.g.Widget,ContextualBalloon,WidgetToolbarRepository). - Init logic in
init(); cross-plugin runtime wiring inafterInit(). - Plugin knows little about other plugins — collaborates via commands/events/schema, not reaching into internals.
- Self-configuring: schema pre-configured; config defaults via
editor.config.define(), read viaeditor.config.get(). No required manual schema setup pushed onto the user.
Schema
- Inline features
schema.extend( '$text', { allowAttributes } ); elements/objects useschema.register()with correctinheritAllFrom($blockObject/$inlineObject/$block) andallowIn/allowContentOf. - Semantic flags correct:
isLimitfor non-splittable editables, object types for atomic elements;addChildCheck/addAttributeCheckused to disallow invalid nesting/attrs.
Conversion
- Symmetric coverage: an upcast plus downcast; editing vs. data downcast split
only when needed (widget/UI extras go to
editingDowncastsogetData()stays clean). - Correct helpers/direction (
elementTo…upcast,…ToElementdowncast);attributeToElementnaming reflects model-first thinking. - Custom callback converters use the provided
writer; consumables handled in advanced converters; inline widgets registerviewToModelPositionOutsideModelElementmapping. - Everything rendered/round-tripped has a converter (un-converted elements/attributes are filtered out).
Commands
- Logic lives in a
Command, not inline in a button handler. -
refresh()setsisEnabledfrom a real schema check (disabled where the attribute/child isn't allowed) andvaluereflecting current state; no manual state fightingrefresh(). -
execute()wraps mutations inmodel.change(); handles collapsed vs. ranged selection; usesgetValidRanges/insertObject/insertContentrather than unsafe low-level writes. - Boolean attributes set
true/ removed (never stored asfalse). - External disabling via
forceDisabled()/clearForceDisabled();affectsData=falseonly for non-data commands that must stay enabled in read-only.
UI
- Components registered in
editor.ui.componentFactory.add(name, locale => view);localepassed to constructors. - Button/dropdown state bound to command (
bind('isOn','isEnabled').to(command,'value','isEnabled')), not manually toggled. - Handlers call
editor.editing.view.focus()after executing. - Custom views encapsulate their DOM (no direct
element.*writes that collide with bindings); dropdowns/dialogs/balloons use the provided helpers; balloons clean up viaclickOutsideHandlerand remove themselves on hide.
Accessibility
- Keyboard support:
editor.keystrokes.set()for shortcuts; form views useFocusTracker+KeystrokeHandler+FocusCycler, and destroy them indestroy(). - Shortcuts registered with
editor.accessibility.addKeystrokeInfos()and shown in the buttonkeystroketooltip; labels set even whenwithTextis false. - Dialogs/modals always leave a way to close (don't trap Esc without an alternative).
Localization
- All user-facing strings go through
editor.t()with the English text itself as the message id — no translation keys in plugin code. - The translation function is named
tat every call site (t(…),editor.t(…),this.t(…)). A parameter or local namedtranslate/_tis invisible to the registry scan, so the string never gets translated in any locale. - Every first argument is a literal, never a variable. Labels held in a table and read as
t( def.label )are the recurring version of this; they belong in a switch (getAdmonitionTitle(),getLinkDisplayModeLabel(),getBoxSizeLabel()). - Each new message has an English entry under
text-editor.ckinapps/client/src/translations/en/translation.json, keyed by the slug of its text — unless CKEditor already ships that string, in which case there must be no entry (ours merges after core and would override upstream in every locale). - Interpolation uses
%0/%1, not a template literal and not{{name}}. - Strings that reach no translation function at all — the case no test can catch. Read the
plugin's
label:/tooltip:/title:/placeholder:/aria-labeland any text built by concatenation or in asetTemplatechildren array. - A keystroke mentioned in a message comes from
renderShortcut( editor, SHORTCUT ), not from resolving key names inside the package.
Conventions & hygiene
- Naming/imports/file names/CSS-BEM/JSDoc/TS rules per
conventions.md;CKEditorErrorwith@error. - Imports: library symbols from
ckeditor5; cross-package from@triliumnext/*; all local/relative imports carry file extensions (./foo.js). - License header matches the package's existing convention (varies per package — some carry the CKSource header, some don't; don't add/strip wholesale).
-
pluginName/requiresdeclaredas const; type augmentation done viadeclare module 'ckeditor5'(config + command/plugin maps). - Custom SVG icons live in
packages/ckeditor5/src/icons/and are imported with?rawby the file that uses them. - Listeners use
this.listenTo()(auto-cleaned); any other resources cleaned indestroy(). -
ckeditor5-metadata.jsonupdated for new public plugins/UI/HTML output. - Model is the source of truth — no view hacks standing in for model state (except genuine view-only state like focus).
Trilium integration
- Plugin registered in
packages/ckeditor5/src/plugins.tsin the correct array (package-level plugins like the widget features go inEXTERNAL_PLUGINS; in-tree glue plugins go in the internal list). - Toolbar component name added to
apps/client/src/widgets/type_widgets/text/toolbar.ts(registering the component-factory entry alone won't surface it). - Works across all three editor classes used by Trilium —
AttributeEditor(Balloon),ClassicEditor(Decoupled),PopupEditor(Balloon +BlockToolbar). - Block widgets enforce structural invariants with
registerPostFixer(admonition, collapsible) rather than relying on command-side cleanup. - An added, renamed, redrawn or removed SVG icon (or a
ckeditor5bump) comes with a regeneratedckepack (text-editor-icons.woff2+icon_pack_text_editor.json), and no page indocs/User Guidestill uses a removedcke-*class. Seeui-and-localization.md, "Theckeicon pack". - Tests use the right environment: happy-dom for unit/model logic; Playwright (browser) only where real DOM/layout is required.