Skip to content

Build your personal knowledge base with Trilium Notes

chore(skills): document Trilium toolbars and remove non-Trilium fluff

Elian Dorancd807d917f1d
diff --git a/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md b/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md
index 389a14d5e1..e1bde44d70 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md
@@ -23,57 +23,30 @@ Where a snippet shows an `@ckeditor/ckeditor5-*` or relative `../utils.js` impor
internal style), treat it as a pointer to where the symbol lives upstream, not the path you'd write
in a Trilium plugin.
-## Toolbar + menu-bar button in one factory
+## Buttons & the component factory
-Official feature-UI plugins register **both** a toolbar button and a menu-bar item from a single
-shared factory, using the `menuBar:` name prefix. The button binds to the command and refocuses
-the editor on execute.
+Trilium registers toolbar buttons directly via `editor.ui.componentFactory.add(...)` in each
+plugin's `*ui.ts` (see `ui-and-localization.md` for the Trilium pattern and the `toolbar.ts`
+wiring). Trilium has **no menu bar**, so there is no `menuBar:<name>` registration — and the
+library's internal `_getBasicStylesButtonCreator` helper / `MenuBarMenuListItemButtonView` are not
+used here. Useful library facts that still apply:
-```ts
-// Source: packages/ckeditor5-basic-styles/src/{bold/boldui.ts, utils.ts}
-import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5';
-// The shared factory is the library's internal helper; downstream import it as
-// `_getBasicStylesButtonCreator` from 'ckeditor5', or write the ~12-line factory yourself.
-import { _getBasicStylesButtonCreator as getButtonCreator } from 'ckeditor5';
-
-const createButton = getButtonCreator( {
- editor, commandName: 'bold', plugin: this,
- icon: IconBold, label: t( 'Bold' ), keystroke: 'CTRL+B'
-} );
-
-editor.ui.componentFactory.add( 'bold', () => createButton( ButtonView ) );
-editor.ui.componentFactory.add( 'menuBar:bold', () => createButton( MenuBarMenuListItemButtonView ) );
-```
-
-The factory (`packages/ckeditor5-basic-styles/src/utils.ts`, exported as
-`_getBasicStylesButtonCreator`) does: `view.set({ label, icon, keystroke, isToggleable: true })`,
-`view.bind('isEnabled').to(command,'isEnabled')`, `view.bind('isOn').to(command,'value')`, sets
-`role: 'menuitemcheckbox'` for the menu-bar variant or `tooltip: true` for the toolbar variant,
-and on `execute` runs the command + `editor.editing.view.focus()`.
-
-- **Menu bar** is registered with the `menuBar:<name>` component name; `MenuBarMenuListItemButtonView`
- is pre-set with `withText: true`, `withKeystroke: true`, `tooltip: false`, `role: 'menuitem'`.
- `SwitchButtonView` auto-sets `isToggleable`. `FileDialogButtonView` fires a `done` event with a
- `FileList` (`acceptedType`, `allowMultipleFiles`) — use for file pickers
- (`packages/ckeditor5-ui/src/button/filedialogbuttonview.ts`).
+ `FileList` (`acceptedType`, `allowMultipleFiles`) — use for file pickers.
- `componentFactory` API: `add(name, locale => view)`, `create(name)`, `has(name)`, `names()`;
names are case-insensitive; views are created fresh per `create()`.
-## Glue plugin flags & TS dependency typing
+## Glue plugin & dependency typing
```ts
-// packages/ckeditor5-basic-styles/src/bold.ts
-export class Bold extends Plugin {
- public static get requires(): PluginDependenciesOf<[ BoldEditing, BoldUI ]> {
- return [ BoldEditing, BoldUI ];
- }
- public static get pluginName() { return 'Bold' as const; }
- public static override get isOfficialPlugin(): true { return true; } // first-party marker
+export class Admonition extends Plugin {
+ public static get requires() { return [ AdmonitionEditing, AdmonitionUI ] as const; }
+ public static get pluginName() { return 'Admonition' as const; }
}
```
-- `isOfficialPlugin` / `isPremiumPlugin` are licensing/telemetry flags (default `false`); set them
- with the exact `: true` return type or omit entirely (`ckeditor-plugin-flags` ESLint rule).
+- Trilium glue plugins use `pluginName` / `requires` with `as const` and **do not** set the
+ library's `isOfficialPlugin` / `isPremiumPlugin` flags (those are CKSource first-party markers).
- `requires()` may list classes **or** plugin-name strings; order = load order.
- A `Command` must never go in `config.plugins` (it throws) — register with `editor.commands.add()`.
@@ -81,10 +54,10 @@ export class Bold extends Plugin {
```ts
// packages/ckeditor5-<feature>/src/augmentation.ts
-declare module '@ckeditor/ckeditor5-core' {
- interface PluginsMap { [ Bold.pluginName ]: Bold; }
- interface CommandsMap { bold: AttributeCommand; }
- interface EditorConfig { myFeature?: MyFeatureConfig; }
+declare module 'ckeditor5' {
+ interface PluginsMap { [ Admonition.pluginName ]: Admonition; }
+ interface CommandsMap { admonition: AdmonitionCommand; } // optional — only if exposed
+ interface EditorConfig { admonition?: AdmonitionConfig; }
}
```
diff --git a/.claude/skills/ckeditor5-plugin-development/references/recipes.md b/.claude/skills/ckeditor5-plugin-development/references/recipes.md
index 0995300060..5e23568802 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/recipes.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/recipes.md
@@ -7,17 +7,17 @@ content of a single text note, so these recipes operate over that note's model r
## Get the editor instance
-```js
-// In a function plugin:
-function MyPlugin( editor ) { /* editor.* */ }
+Inside plugin code you already have it: `this.editor` (in a `Plugin`/`Command` subclass) or the
+`editor` argument of a function plugin / converter / `componentFactory` callback. You don't fetch
+it from the DOM — in Trilium the editor is created and owned by the React watchdog component
+(`apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx`), not by plugin code.
-// From a DOM editable element:
-const editor = document.querySelector( '.ck-editor__editable_inline' ).ckeditorInstance;
+```js
+class MyPlugin extends Plugin {
+ init() { const editor = this.editor; /* … */ }
+}
```
-`CKEDITOR_VERSION` in the console reports the version. There is no global registry of
-instances by default.
-
## Insert content
```js
diff --git a/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md b/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md
index 581f5534da..62a1f8b7c0 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md
@@ -44,7 +44,8 @@ consumers**. An optional `dist/` "NIM build" (the upstream new-installation-meth
generated for standalone use but is **gitignored and eslint-ignored** — never import from it inside
the monorepo.
-Config files (one set per package):
+Config files (typical set per package — not every package has all of them; e.g. collapsible
+currently lacks `eslint.config.js`/stylelint + lint scripts):
- `tsconfig.json` — `composite: true`, `target: es2019`, `strict`, `module/moduleResolution:
NodeNext`; plus `tsconfig.test.json` for tests.
@@ -52,6 +53,9 @@ Config files (one set per package):
- `eslint.config.js` — `eslint-config-ckeditor5` + `eslint-plugin-ckeditor5-rules`.
- `stylelint-config-ckeditor5` for theme CSS.
+Plugin packages have **no `vite.config.ts`** — only the aggregator (`packages/ckeditor5`) builds;
+each plugin just ships raw TS via `main: src/index.ts`, compiled by whatever bundles the editor.
+
`src/` files: `{feature}.ts` (glue), `{feature}editing.ts`, `{feature}ui.ts`, optional
`{feature}command.ts`, `augmentation.ts`, `index.ts`. Complex plugins add `constants.ts`
(`ELEMENTS`/`ATTRIBUTES`/`COMMANDS`/`CLASSES`), `utils.ts` (model-query helpers), and split
diff --git a/.claude/skills/ckeditor5-plugin-development/references/ui-and-localization.md b/.claude/skills/ckeditor5-plugin-development/references/ui-and-localization.md
index 69f5292e4d..f200b957c2 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/ui-and-localization.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/ui-and-localization.md
@@ -81,6 +81,39 @@ component factory entry alone is not enough. Real examples: the admonition butto
**Best practice:** on any user action (button/dropdown execute), call
`editor.editing.view.focus()` so the editor keeps focus.
+## Trilium toolbars (`toolbar.ts`)
+
+*Which* names appear, and *where*, is decided in
+`apps/client/src/widgets/type_widgets/text/toolbar.ts`. `buildToolbarConfig(isClassicToolbar)`
+picks one of three layouts:
+
+- **`buildClassicToolbar()`** — the fixed, multi-row toolbar above the editable (used by
+ `ClassicEditor`). Returns `{ toolbar: { items: [ … ] } }`.
+- **`buildFloatingToolbar()`** — used by `PopupEditor`. Returns **two** floating toolbars:
+ `{ toolbar: { items: [ … ] }, blockToolbar: [ … ] }` — a **selection toolbar** (a balloon over
+ the selected text) and a **block toolbar** (the `BlockToolbar` plugin, present only in
+ `POPUP_EDITOR_PLUGINS`, shown at the start of the current block).
+- **`buildMobileToolbar()`** — a single flattened `items` array for touch (checked first).
+
+Each `items` / `blockToolbar` entry is one of:
+
+```ts
+"bold" // a component-factory name (string)
+"|" // a visual separator
+{ label: "Insert", icon, items: [ // a grouped dropdown (nestable)
+ "link", "internallink", "includeNote", "|", "collapsible", "math", "mermaid"
+] }
+```
+
+So adding a custom toolbar item is a **two-step** wire-up: register the component in your plugin's
+`*ui.ts` (above), **and** add its name to the right array(s) in `toolbar.ts` — classic, the floating
+`toolbar`, the floating `blockToolbar`, and/or mobile, as appropriate. Registering the component
+alone makes it available but invisible. (`AttributeEditor`'s minimal toolbar isn't built here.)
+
+> A **widget contextual toolbar** — buttons that appear when a widget is *selected* — is different:
+> it's registered inside the plugin via `WidgetToolbarRepository`, **not** listed in `toolbar.ts`.
+> See `widgets.md`.
+
## Component catalog
| Component | Purpose / key props |
diff --git a/.claude/skills/ckeditor5-plugin-development/references/widgets.md b/.claude/skills/ckeditor5-plugin-development/references/widgets.md
index 2481ec02ee..3fdaee6da9 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/widgets.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/widgets.md
@@ -180,9 +180,11 @@ Boolean-attribute convention: set `true` to enable, **remove** the attribute to
## Widget contextual toolbar
-Use `WidgetToolbarRepository` (register in `afterInit()`, because it depends on runtime state).
-Items come from config; `getRelatedElement` decides when the toolbar shows by finding the
-widget view element (detect via the custom property + `isWidget()`):
+A contextual toolbar appears when a **widget is selected** — distinct from the main `toolbar.ts`
+toolbar (which holds the insert button). Register it **inside the plugin** with
+`WidgetToolbarRepository` (in `afterInit()`, because it depends on runtime state). Items come from
+config; `getRelatedElement` decides when the toolbar shows by finding the widget view element
+(detect via the custom property + `isWidget()`):
```js
import { Plugin, WidgetToolbarRepository } from 'ckeditor5';
@@ -303,6 +305,9 @@ handlers skip them — math/mermaid use this around their source inputs.
**Registering a new widget plugin in Trilium.** A new plugin is wired in two places: add it to
the correct array in `packages/ckeditor5/src/plugins.ts` (e.g. `EXTERNAL_PLUGINS` for the
-package-level plugins like `Mermaid`, `Admonition`, `Collapsible`, `Footnotes`, `Math`), and
-add its toolbar component name to `apps/client/src/widgets/type_widgets/text/toolbar.ts`.
-Files use `declare module 'ckeditor5'` augmentation for config and command typings.
+package-level plugins like `Mermaid`, `Admonition`, `Collapsible`, `Footnotes`, `Math`), and add
+its **insert-button** component name to `apps/client/src/widgets/type_widgets/text/toolbar.ts` (see
+`ui-and-localization.md`). The widget's *contextual* toolbar (above) is separate — registered in the
+plugin, not in `toolbar.ts`. Trilium has several (mermaid, admonition, code-block — the last even
+hides itself when the `BalloonToolbar` is shown). Files use `declare module 'ckeditor5'`
+augmentation for config and command typings.