Skip to content

Build your personal knowledge base with Trilium Notes

chore(skills): add clipboard-emitter, observable-declare, and HMR footguns to ckeditor5-plugin-development

Elian Doranf92eb3c65c4a
diff --git a/.claude/skills/ckeditor5-plugin-development/SKILL.md b/.claude/skills/ckeditor5-plugin-development/SKILL.md
index 06c429c734..4a40296d91 100644
--- a/.claude/skills/ckeditor5-plugin-development/SKILL.md
+++ b/.claude/skills/ckeditor5-plugin-development/SKILL.md
@@ -236,6 +236,9 @@ converters instead of `attributeToElement`; see `references/widgets.md`.
`pnpm --filter @triliumnext/ckeditor5-<feature> test` (also `lint`, `stylelint`, `test:debug`).
- **Verify** with `editor.getData()` / `editor.setData()` and by exercising selection edge
cases (collapsed vs. ranged, inside objects/limits).
+- **A changed plugin won't apply to an already-open editor via HMR.** A plugin's `init()` runs
+ only when the editor is *built*, so do a **full page reload** (or close/reopen the note) to get a
+ fresh editor instance that picks up your change — otherwise you're testing the old code.
## Reference map
diff --git a/.claude/skills/ckeditor5-plugin-development/references/architecture.md b/.claude/skills/ckeditor5-plugin-development/references/architecture.md
index 1316f6fd40..3c17c0c09c 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/architecture.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/architecture.md
@@ -244,6 +244,16 @@ this.set( 'value', undefined );
command.on( 'change:value', ( evt, name, newVal, oldVal ) => {} );
```
+- **Footgun (TypeScript) — declare observable fields with `declare x: T`, never `x!: T`.** A field
+ you back with `this.set({ x })` must be typed with the **type-only `declare`** modifier (emits no
+ code). The definite-assignment form `x!: T` looks equivalent but, under `useDefineForClassFields`
+ (the default at our `target: es2022`, and the Vite/esbuild default), it emits a real field
+ initializer that pre-sets the property to `undefined`; CKEditor's `this.set({ x })` then throws
+ `observable-set-cannot-override` (it refuses to convert an own data property into an observable
+ accessor). `declare` is the correct CKEditor 5 pattern — see
+ `packages/ckeditor5/src/plugins/file_upload/progressbarview.ts` (`declare width: number;` +
+ `this.set( 'width', 100 )`).
+
- **Binding** mirrors one observable's properties to another (heavily used in UI):
```js
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 e1bde44d70..28e693e604 100644
--- a/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md
+++ b/.claude/skills/ckeditor5-plugin-development/references/core-plugin-patterns.md
@@ -209,11 +209,24 @@ Intercept paste/copy/drop via the clipboard pipeline events rather than raw DOM:
// packages/ckeditor5-clipboard/src/clipboardpipeline.ts
// input chain: view 'paste'/'drop' → 'clipboardInput' → 'inputTransformation' → 'contentInsertion'
// output chain: view 'copy'/'cut' → 'clipboardOutput'
-this.listenTo( editor.plugins.get( 'ClipboardPipeline' ), 'inputTransformation', ( evt, data ) => {
+import { ClipboardPipeline } from 'ckeditor5';
+static get requires() { return [ ClipboardPipeline ]; } // and add it to requires()
+this.listenTo( editor.plugins.get( ClipboardPipeline ), 'inputTransformation', ( evt, data ) => {
// data.content is a view DocumentFragment; transform pasted content here
}, { priority: 'low' } );
```
+- **Footgun — `inputTransformation`/`contentInsertion` fire on `ClipboardPipeline`, NOT the
+ `Clipboard` umbrella plugin.** `editor.plugins.get( Clipboard )` does **not** emit those events:
+ in `@ckeditor/ckeditor5-clipboard`, `ClipboardPipeline._setupPasteDrop()` is what fires
+ `new EventInfo( this, 'inputTransformation' )`, and the separate `Clipboard` class never
+ references the event (its `init()` only registers keystroke accessibility info) — there is no
+ `.delegate()` between them. So `this.listenTo( editor.plugins.get( Clipboard ), 'inputTransformation', … )`
+ is a **silently-dead handler** (no error, never runs). Listen on `ClipboardPipeline` and add it to
+ `requires()`. (Contrast: the raw `'clipboardInput'` view event fires on
+ `editor.editing.view.document` — a different, correct emitter that the upload pipeline does listen
+ to; see `packages/ckeditor5/src/plugins/file_upload/fileuploadediting.ts`.)
+
Add a custom observer by subclassing `DomEventObserver` and `view.addObserver(MyObserver)` (see the
double-click recipe in `recipes.md`). Prefix custom view events with a namespace.