autumnnote 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ A modern, lightweight WYSIWYG rich-text editor built with vanilla JavaScript (ES
16
16
 
17
17
  > Write rich text. No dependencies. No drama.
18
18
 
19
- [Live Demo](https://cmm-cmm.github.io/Autumn-Note/)
19
+ [Live Demo](https://cmm-cmm.github.io/Autumn-Note/) · [Docs](https://cmm-cmm.github.io/Autumn-Note/docs.html) · [Playground](https://cmm-cmm.github.io/Autumn-Note/playground.html)
20
20
 
21
21
  <p align="center"><img src="demo/Screenshot.png" alt="AutumnNote Screenshot"/></p>
22
22
 
@@ -27,14 +27,15 @@ A modern, lightweight WYSIWYG rich-text editor built with vanilla JavaScript (ES
27
27
  1. [Features](#features)
28
28
  2. [Installation](#installation)
29
29
  3. [Quick Start](#quick-start)
30
- 4. [API](#api)
31
- 5. [Options](#options)
32
- 6. [Toolbar Customisation](#toolbar-customisation)
33
- 7. [Keyboard Shortcuts](#keyboard-shortcuts)
34
- 8. [Mentions](#mentions)
35
- 9. [Project Structure](#project-structure)
36
- 10. [Comparison](#comparison)
37
- 11. [License](#license)
30
+ 4. [Plugin API](#plugin-api)
31
+ 5. [API](#api)
32
+ 6. [Options](#options)
33
+ 7. [Toolbar Customisation](#toolbar-customisation)
34
+ 8. [Keyboard Shortcuts](#keyboard-shortcuts)
35
+ 9. [Mentions](#mentions)
36
+ 10. [Project Structure](#project-structure)
37
+ 11. [Comparison](#comparison)
38
+ 12. [License](#license)
38
39
 
39
40
  ---
40
41
 
@@ -109,7 +110,7 @@ Right-click inside the editor opens a context menu with: **Undo**, **Redo**, **C
109
110
  - **No jQuery** — pure vanilla ES2022, zero runtime dependencies
110
111
  - **Bootstrap friendly** — optional Bootstrap 4/5 styling (`useBootstrap: true`)
111
112
  - **FontAwesome ready** — auto-detects FA on the page; falls back to built-in SVG icons
112
- - **Plugin-ready** — register custom modules via `AutumnNote.defaults`
113
+ - **Plugin API** — first-class plugin system: `AutumnNote.use(plugin)`, `context.getPlugin(name)`, global button registry (`registerButton`), per-instance installation, `AsnPlugin<T>` TypeScript interface
113
114
  - **Tree-shakeable** — ES module build; all core utilities individually exported
114
115
  - **TypeScript definitions** — bundled `types/index.d.ts` with full JSDoc coverage
115
116
  - **@mention autocomplete** — type `@` (or any custom trigger) to open a floating dropdown backed by a user-supplied `onSearch` function; inserts a non-editable mention chip; customisable chip HTML via `onInsert`
@@ -269,6 +270,61 @@ const editor = AutumnNote.create('#my-editor', {
269
270
 
270
271
  ---
271
272
 
273
+ ## Plugin API
274
+
275
+ Plugins package editor extensions — custom modules, toolbar buttons, and event handlers — into a reusable, distributable object.
276
+
277
+ ```js
278
+ import AutumnNote from 'autumnnote';
279
+
280
+ const WordCountPlugin = {
281
+ name: 'word-count',
282
+ version: '1.0.0',
283
+ // Buttons registered BEFORE create() — usable by name in toolbar config
284
+ buttons: [{
285
+ name: 'wordCountBtn',
286
+ icon: 'hashtag',
287
+ tooltip: 'Word count',
288
+ action: (ctx) => alert(`${ctx.getWordCount()} words`),
289
+ }],
290
+ // Called after all built-in modules initialise
291
+ install(ctx, options) {
292
+ ctx.on('change', () => console.log('words:', ctx.getWordCount()));
293
+ return { getMax: () => options.maxWords };
294
+ },
295
+ uninstall(ctx) { /* cleanup */ },
296
+ };
297
+
298
+ // Global — applied to every future editor instance
299
+ AutumnNote.use(WordCountPlugin, { maxWords: 500 });
300
+
301
+ const editor = AutumnNote.create('#editor', {
302
+ toolbar: [['bold', 'italic', 'wordCountBtn']], // 'wordCountBtn' resolved from registry
303
+ });
304
+
305
+ editor.getPlugin('word-count').getMax(); // → 500
306
+ ```
307
+
308
+ **Per-instance installation:**
309
+
310
+ ```js
311
+ const editor = AutumnNote.create('#editor');
312
+ editor.use(WordCountPlugin, { maxWords: 200 });
313
+ editor.invoke('toolbar.rebuild'); // re-render toolbar with new buttons
314
+ ```
315
+
316
+ | Method | Description |
317
+ |---|---|
318
+ | `AutumnNote.use(plugin, opts?)` | Install globally. Buttons registered immediately; `install()` called after modules init. |
319
+ | `AutumnNote.hasPlugin(name)` | Returns `true` if plugin registered globally. |
320
+ | `AutumnNote.registerButton(def)` | Register a single button globally by name. |
321
+ | `context.use(plugin, opts?)` | Install on this instance only. |
322
+ | `context.getPlugin<T>(name)` | Returns the public API from `plugin.install()`. |
323
+
324
+ See the [full Plugin API docs →](https://cmm-cmm.github.io/Autumn-Note/docs.html#plugin-api)
325
+
326
+ ---
327
+
272
328
  ## API
273
329
 
274
330
  ### Factory