插件合同

EditorPlugin 与 EditorUIContribution 的独立职责。

让文档进入你的工作流

EditorPlugin

定义与声明扩展入口:@musecanto/editor。

  • name:唯一插件名称,也是 instance.plugins 的索引。
  • extensions({documentId}):创建前提供 Tiptap 扩展。attachEditor 不会改变已有编辑器的 schema;预先将扩展加入原生实例。
  • api(host):创建实例 API。host.getEditor() 返回活动 Tiptap 或 null;host.whenReady(attach) 返回取消函数。
  • setup({editor,instance,documentId}):初始化副作用,返回清理函数。
  • onSaveShortcut(context):处理 Mod+S,返回 boolean 或 Promise<boolean>。true 结束处理;false 继续后续插件。

setup 失败会清理已经安装的插件。destroy 幂等且移除内容订阅。createEditor 拥有并销毁底层实例,attachEditor 仅清理运行时。

EditorUIContribution

定义入口:@musecanto/editor-react。通过 kit 的 ui.contributions 注册。

  • id、order、messages:身份、稳定排序和按 en/zh 组织的消息树。
  • toolbarItems({editor,t,locale}):button、component 或 separator,key 必须唯一。
  • insertItems({editor,t,locale}):id、icon、label、onSelect。
  • bubbleMenus:id、Component、isAvailable、可选 getReferenceClientRect 与 readOnlyAllowed。
  • sidebarItems:key、kind、labelKey、icon、order、readOnlyAllowed、isAvailable;panel 提供 render,action 提供 onSelect。
  • sidebarFooterItems:key 和 render。
  • Provider({editor,children})、Overlay({editor,isEditable}):上下文和浮层。

重复 UI ID、菜单 ID 或工具栏 key 都会报错。核心协议不包含任何 UI 字段,工具栏和菜单容器不导入具体功能包。

类型身份

declare module "@musecanto/editor" {
  interface EditorPluginApis {
    example: { run(): void };
  }
}

本页目录

继续探索编辑器 Playground试写并查看文档输出在 GitHub 查看源码问题反馈与参与贡献

示例使用私有 SDK。
你的内容与存储,由你掌控。