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/types/index.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface AsnOptions {
21
21
  /** Show the resize handle in the statusbar. */
22
22
  resizable?: boolean;
23
23
  /** Toolbar button group configuration. */
24
- toolbar?: Array<Array<ToolbarItemDef>>;
24
+ toolbar?: Array<Array<ToolbarItemDef | string>>;
25
25
  /** Use Bootstrap button classes on toolbar buttons. */
26
26
  useBootstrap?: boolean;
27
27
  /** CSS class(es) applied to Bootstrap toolbar buttons. */
@@ -234,6 +234,31 @@ export interface DropdownDef {
234
234
 
235
235
  export type ToolbarItemDef = ButtonDef | DropdownDef | GridButtonDef | ColorPickerDef;
236
236
 
237
+ // ---------------------------------------------------------------------------
238
+ // Plugin API
239
+ // ---------------------------------------------------------------------------
240
+
241
+ /**
242
+ * Plugin descriptor passed to `AutumnNote.use()` or `context.use()`.
243
+ * `T` is the shape of the public API returned by `install()`, accessible
244
+ * via `context.getPlugin<T>(name)`.
245
+ */
246
+ export interface AsnPlugin<T = unknown> {
247
+ /** Unique plugin identifier. */
248
+ name: string;
249
+ /** Semantic version string (informational only). */
250
+ version?: string;
251
+ /** Button definitions to register in the global button registry. */
252
+ buttons?: ToolbarItemDef[];
253
+ /**
254
+ * Called after all built-in modules have initialised.
255
+ * Return an object to expose it as the plugin's public API.
256
+ */
257
+ install?: (context: Context, options: Record<string, unknown>) => T | null | void;
258
+ /** Called when the editor instance is destroyed. */
259
+ uninstall?: (context: Context) => void;
260
+ }
261
+
237
262
  // ---------------------------------------------------------------------------
238
263
  // Entry-point re-exports
239
264
  // ---------------------------------------------------------------------------
@@ -394,6 +419,18 @@ export declare class Context {
394
419
  */
395
420
  registerModule(name: string, ModuleClass: new (ctx: Context) => object): this;
396
421
 
422
+ /**
423
+ * Installs a plugin on this editor instance.
424
+ * If called after create(), call `ctx.invoke('toolbar.rebuild')` to render new buttons.
425
+ */
426
+ use<T = unknown>(plugin: AsnPlugin<T>, options?: Record<string, unknown>): this;
427
+
428
+ /**
429
+ * Returns the public API returned by `plugin.install()`, or null.
430
+ * Cast to your plugin's return type: `ctx.getPlugin<MyPluginApi>('my-plugin')`.
431
+ */
432
+ getPlugin<T = unknown>(name: string): T | null;
433
+
397
434
  /** Completely removes the editor and restores the original element. */
398
435
  destroy(): void;
399
436
  }
@@ -476,6 +513,22 @@ export interface AutumnNoteStatic {
476
513
  */
477
514
  registerModule(name: string, ModuleClass: new (ctx: Context) => object): void;
478
515
 
516
+ /**
517
+ * Installs a plugin globally — applied to every future editor instance.
518
+ * Plugin `buttons` are registered immediately so Toolbar can resolve them by name.
519
+ * Plugin `install()` is called after all built-in modules have initialised.
520
+ */
521
+ use<T = unknown>(plugin: AsnPlugin<T>, options?: Record<string, unknown>): this;
522
+
523
+ /** Returns true if a plugin with the given name has been registered globally. */
524
+ hasPlugin(name: string): boolean;
525
+
526
+ /**
527
+ * Registers a single button in the global button registry so it can be
528
+ * referenced by string name in toolbar configuration.
529
+ */
530
+ registerButton(btnDef: ToolbarItemDef): this;
531
+
479
532
  /** Library version string. */
480
533
  readonly version: string;
481
534
  }