@norio-office/rich-text 0.7.0 → 0.8.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.
Files changed (61) hide show
  1. package/README.md +895 -816
  2. package/dist/ai/bridge.d.ts +335 -0
  3. package/dist/ai/consume-stream.d.ts +8 -0
  4. package/dist/ai/executor.d.ts +19 -0
  5. package/dist/ai/index.d.ts +8 -0
  6. package/dist/ai/index.js +4106 -0
  7. package/dist/ai/tools.d.ts +158 -0
  8. package/dist/ai-protocol/index.d.ts +12 -0
  9. package/dist/ai-protocol/index.js +2372 -0
  10. package/dist/ai-protocol/json-schema.d.ts +5 -0
  11. package/dist/ai-protocol/patch.d.ts +77 -0
  12. package/dist/ai-protocol/references.d.ts +11 -0
  13. package/dist/ai-protocol/stream.d.ts +94 -0
  14. package/dist/ai-protocol/tools.d.ts +8 -0
  15. package/dist/ai-protocol/validation.d.ts +20 -0
  16. package/dist/components/RichTextEditor.vue.d.ts +11 -8
  17. package/dist/components/TextSelectionMenu.vue.d.ts +29 -1
  18. package/dist/document/ai-identity.d.ts +4 -0
  19. package/dist/document/nodes/columns-block.d.ts +2 -0
  20. package/dist/document/nodes/countdown-block.d.ts +2 -0
  21. package/dist/document/nodes/formula-block.d.ts +2 -0
  22. package/dist/document/nodes/highlight-block.d.ts +2 -0
  23. package/dist/document/nodes/image-block.d.ts +8 -0
  24. package/dist/document/nodes/link-block.d.ts +2 -0
  25. package/dist/document/nodes/local-file-block.d.ts +2 -0
  26. package/dist/document/nodes/mention.d.ts +2 -0
  27. package/dist/document/nodes/office-code-block.d.ts +1 -0
  28. package/dist/document/nodes/table-cells.d.ts +2 -0
  29. package/dist/document/nodes/themed-table.d.ts +1 -0
  30. package/dist/document/nodes/video-block.d.ts +8 -0
  31. package/dist/document/schema.d.ts +17 -0
  32. package/dist/extensions/ai-identity.d.ts +1 -0
  33. package/dist/extensions/columns-block.d.ts +1 -2
  34. package/dist/extensions/countdown-block.d.ts +1 -2
  35. package/dist/extensions/formula-block.d.ts +1 -2
  36. package/dist/extensions/highlight-block.d.ts +1 -2
  37. package/dist/extensions/image-block.d.ts +4 -8
  38. package/dist/extensions/link-block.d.ts +1 -2
  39. package/dist/extensions/local-file-block.d.ts +1 -2
  40. package/dist/extensions/mention.d.ts +1 -2
  41. package/dist/extensions/video-block.d.ts +4 -8
  42. package/dist/{html2canvas-4hiP1s1t.js → html2canvas-BnDzIoab.js} +112 -126
  43. package/dist/index.js +8272 -7604
  44. package/dist/index.umd.cjs +2189 -1990
  45. package/dist/nordox/index.d.ts +95 -0
  46. package/dist/nordox/index.js +2094 -0
  47. package/dist/{chunk-C_CI6nMA.js → rolldown-runtime-VHNaYcLd.js} +3 -3
  48. package/dist/style.css +1 -1
  49. package/dist/types.d.ts +9 -1
  50. package/docs/ai/README.md +108 -0
  51. package/docs/ai/acceptance-report.md +88 -0
  52. package/docs/ai/capability-matrix.md +43 -0
  53. package/docs/ai/compatibility.md +9 -0
  54. package/docs/icons.md +21 -0
  55. package/examples/ai/browser/App.vue +151 -0
  56. package/examples/ai/browser/index.html +12 -0
  57. package/examples/ai/browser/main.ts +5 -0
  58. package/examples/ai/browser/tsconfig.json +7 -0
  59. package/examples/ai/browser/vite.config.ts +14 -0
  60. package/examples/ai/node.mjs +28 -0
  61. package/package.json +15 -1
package/README.md CHANGED
@@ -1,25 +1,26 @@
1
1
  # @norio-office/rich-text
2
2
 
3
- 个人开发项目,生产使用前请结合业务场景测试。问题反馈:norio-office@qq.com。
3
+ 一款支持AI局部更新的富文本编辑器;问题反馈:norio-office@qq.com。
4
4
 
5
5
  中文 | [English](#english)
6
6
 
7
7
  ## 中文
8
8
 
9
- `@norio-office/rich-text` 是一个基于 Vue 3 和 Tiptap 3 的富文本编辑器组件,内置文档式编辑界面、图片/视频/文件块、表格、公式、倒计时、高亮块、大纲、预览模式、导出能力,以及可选的 Yjs 协同编辑。
10
-
11
- 本文按当前仓库实现说明。编辑器负责编辑界面和内容结构;保存接口、文件服务器、评论数据库、协同服务器由你的项目提供。下面的 `/api/...` 和 `example.com` 都是示例地址,不是组件自带的服务。
12
-
13
- ### 从哪里开始
14
-
15
- - 第一次接入:[快速开始](#快速开始),然后看[保存、加载与清空](#保存加载与清空)。
16
- - 上传附件:[上传并插入](#上传并插入)。
17
- - 控制显示的功能:[可用 Key](#可用-key);限制用户编辑:[预览模式](#预览模式)。
18
- - 自己做按钮:[实例 API](#实例-api);自己放目录:[外置目录组件](#外置目录组件)。
19
- - 接多人协作:[协同编辑](#协同编辑);接评论:[评论功能对接](#评论功能对接)。
20
- - 遇到问题:先看[常见问题](#常见问题)。
21
-
22
- 带完整 `<script setup>` 和 `<template>` 的示例可以作为一个 Vue 组件使用;只有 `<RichTextEditor ... />` 或函数的片段,需要合并到前面的组件中。`yourUploadApi()`、初始化权判断等占位逻辑必须替换成业务实现。
9
+ `@norio-office/rich-text` 是一个基于 Vue 3 和 Tiptap 3 的富文本编辑器组件,内置文档式编辑界面、图片/视频/文件块、表格、公式、倒计时、高亮块、大纲、预览模式、导出能力,以及可选的 Yjs 协同编辑。
10
+
11
+ 本文按当前仓库实现说明。编辑器负责编辑界面和内容结构;保存接口、文件服务器、评论数据库、协同服务器由你的项目提供。下面的 `/api/...` 和 `example.com` 都是示例地址,不是组件自带的服务。
12
+
13
+ ### 从哪里开始
14
+
15
+ - 第一次接入:[快速开始](#快速开始),然后看[保存、加载与清空](#保存加载与清空)。
16
+ - 上传附件:[上传并插入](#上传并插入)。
17
+ - 控制显示的功能:[可用 Key](#可用-key);限制用户编辑:[预览模式](#预览模式)。
18
+ - 自己做按钮:[实例 API](#实例-api);自己放目录:[外置目录组件](#外置目录组件)。
19
+ - 接多人协作:[协同编辑](#协同编辑);接评论:[评论功能对接](#评论功能对接)。
20
+ - 接入 AI 局部编辑、目标标记、流式预览和 `.nordox` 文件:先看[AI Skill 接入与使用](#ai-skill-接入与使用),再看[AI 接入指南](docs/ai/README.md)。
21
+ - 遇到问题:先看[常见问题](#常见问题)。
22
+
23
+ 带完整 `<script setup>` 和 `<template>` 的示例可以作为一个 Vue 组件使用;只有 `<RichTextEditor ... />` 或函数的片段,需要合并到前面的组件中。`yourUploadApi()`、初始化权判断等占位逻辑必须替换成业务实现。
23
24
 
24
25
  ### 安装
25
26
 
@@ -33,13 +34,13 @@ npm install @norio-office/rich-text
33
34
  import '@norio-office/rich-text/style.css'
34
35
  ```
35
36
 
36
- 运行环境需要 Vue 3.5+,Tiptap 使用本包声明的 3.x 兼容版本。若包管理器未自动安装 peer dependencies(宿主需要提供的依赖),请按 `package.json` 的版本范围安装,不要混用 Tiptap 2.x 或随意升级到下一主版本:
37
+ 运行环境需要 Vue 3.5+,Tiptap 使用本包声明的 3.x 兼容版本。`@tiptap/core`、`@tiptap/pm`、`@tiptap/vue-3`、starter-kit 和各扩展应解析到同一兼容的 3.x 版本,不要混装不同小版本(例如 core 3.32 与 vue-3 3.22)。若包管理器未自动安装 peer dependencies(宿主需要提供的依赖),请按 `package.json` 的版本范围安装,不要混用 Tiptap 2.x 或随意升级到下一主版本:
37
38
 
38
39
  ```bash
39
- npm install vue@^3.5.0 @tiptap/core@^3.22.1 @tiptap/vue-3@^3.22.1 @tiptap/pm@^3.22.1 @tiptap/starter-kit@^3.22.1 @tiptap/extension-placeholder@^3.22.1 @tiptap/extension-code-block@^3.22.1 @tiptap/extension-code-block-lowlight@^3.22.1 @tiptap/extension-collaboration@^3.22.2 @tiptap/extension-collaboration-caret@^3.22.2 @tiptap/extension-font-family@^3.22.1 @tiptap/extension-horizontal-rule@^3.22.1 @tiptap/extension-subscript@^3.22.1 @tiptap/extension-superscript@^3.22.1 @tiptap/extension-table@^3.22.1 @tiptap/extension-table-cell@^3.22.1 @tiptap/extension-table-header@^3.22.1 @tiptap/extension-table-row@^3.22.1 @tiptap/extension-task-item@^3.22.1 @tiptap/extension-task-list@^3.22.1 @tiptap/extension-text-style@^3.22.1 @tiptap/extension-underline@^3.22.1 @tiptap/y-tiptap@^3.0.2 lowlight@^3.3.0 y-prosemirror@^1.2.6 yjs@^13.6.30
40
+ npm install vue@^3.5.0 @tiptap/core@^3.22.1 @tiptap/vue-3@^3.22.1 @tiptap/pm@^3.22.1 @tiptap/starter-kit@^3.22.1 @tiptap/extension-placeholder@^3.22.1 @tiptap/extension-code-block@^3.22.1 @tiptap/extension-code-block-lowlight@^3.22.1 @tiptap/extension-collaboration@^3.22.2 @tiptap/extension-collaboration-caret@^3.22.2 @tiptap/extension-font-family@^3.22.1 @tiptap/extension-horizontal-rule@^3.22.1 @tiptap/extension-subscript@^3.22.1 @tiptap/extension-superscript@^3.22.1 @tiptap/extension-table@^3.22.1 @tiptap/extension-table-cell@^3.22.1 @tiptap/extension-table-header@^3.22.1 @tiptap/extension-table-row@^3.22.1 @tiptap/extension-task-item@^3.22.1 @tiptap/extension-task-list@^3.22.1 @tiptap/extension-text-style@^3.22.1 @tiptap/extension-underline@^3.22.1 @tiptap/y-tiptap@^3.0.2 lowlight@^3.3.0 y-prosemirror@^1.2.6 yjs@^13.6.30
40
41
  ```
41
42
 
42
- `html2canvas`、`jspdf`、`katex`、`marked`、`plyr` 已作为普通 dependencies 随包安装。
43
+ `fflate`、`html2canvas`、`jspdf`、`katex`、`marked`、`plyr` 已作为普通 dependencies 随包安装。
43
44
 
44
45
  ### 快速开始
45
46
 
@@ -50,10 +51,10 @@ import type { JSONContent } from '@tiptap/core'
50
51
  import { RichTextEditor } from '@norio-office/rich-text'
51
52
  import '@norio-office/rich-text/style.css'
52
53
 
53
- const content = ref<JSONContent>({
54
- type: 'doc',
55
- content: [{ type: 'paragraph' }],
56
- })
54
+ const content = ref<JSONContent>({
55
+ type: 'doc',
56
+ content: [{ type: 'paragraph' }],
57
+ })
57
58
  </script>
58
59
 
59
60
  <template>
@@ -64,118 +65,182 @@ const content = ref<JSONContent>({
64
65
  也可以使用默认导出:
65
66
 
66
67
  ```ts
67
- import RichTextEditor from '@norio-office/rich-text'
68
- ```
69
-
70
- 这个例子从空文档开始。`content` 是 Tiptap JSON 对象,不是 HTML 字符串;编辑后 `v-model` 会更新这个对象,但不会自动保存到服务器。组件依赖浏览器 DOM,SSR 项目应在客户端挂载它。
71
-
72
- ### 保存、加载与清空
73
-
74
- 单人编辑时,把完整 JSON 存入数据库,打开文档时再赋给 `content`。不要只保存 `getText()`,它会丢失标题、颜色、表格和图片等结构。
75
-
76
- 下面是可独立使用的本地演示:手动保存到浏览器 `localStorage`,重新打开页面时恢复。它不涉及上传或服务器,也不适用于多人协同的内容同步。
77
-
78
- ```vue
79
- <script setup lang="ts">
80
- import { onMounted, ref } from 'vue'
81
- import type { JSONContent } from '@tiptap/core'
82
- import { RichTextEditor } from '@norio-office/rich-text'
83
- import '@norio-office/rich-text/style.css'
84
-
85
- const storageKey = 'rich-text-demo'
86
- const createEmptyDocument = (): JSONContent => ({
87
- type: 'doc',
88
- content: [{ type: 'paragraph' }],
89
- })
90
- const content = ref<JSONContent>(createEmptyDocument())
91
- const status = ref('')
92
-
93
- onMounted(() => {
94
- try {
95
- const saved = localStorage.getItem(storageKey)
96
- if (!saved) return
97
- const parsed = JSON.parse(saved) as JSONContent
98
- if (parsed.type !== 'doc' || !Array.isArray(parsed.content)) {
99
- throw new Error('文档格式不正确')
100
- }
101
- content.value = parsed
102
- status.value = '已恢复上次保存的文档'
103
- } catch {
104
- status.value = '读取失败,已打开空文档'
105
- }
106
- })
107
-
108
- function saveDocument() {
109
- try {
110
- localStorage.setItem(storageKey, JSON.stringify(content.value))
111
- status.value = '已保存到当前浏览器'
112
- } catch {
113
- status.value = '保存失败,请检查浏览器存储空间或权限'
114
- }
115
- }
116
-
117
- function clearDocument() {
118
- content.value = createEmptyDocument()
119
- status.value = '已清空编辑区,点击保存后才覆盖旧存档'
120
- }
121
- </script>
122
-
123
- <template>
124
- <button type="button" @click="saveDocument">保存</button>
125
- <button type="button" @click="clearDocument">清空</button>
126
- <span>{{ status }}</span>
127
- <RichTextEditor v-model="content" document-name="演示文档" />
128
- </template>
129
- ```
130
-
131
- 实际项目可以将 `localStorage` 换成自己的读写接口。若监听 `change` 自动保存,建议做防抖和失败提示;`v-model` 和 `change` 对应同一次内容更新,不要分别调用两次保存接口。
132
-
133
- 注意:当前实现中,初次挂载不传 `modelValue` 或传 `null`,单人模式会显示内置示例文字,不是空文档;挂载后将它改成 `null` 也不会清空。要清空请传上例的 `{ type: 'doc', content: [{ type: 'paragraph' }] }`。协同模式以 Yjs 为准,不能用这个赋值方式覆盖房间内容。
68
+ import RichTextEditor from '@norio-office/rich-text'
69
+ ```
70
+
71
+ 这个例子从空文档开始。`content` 是 Tiptap JSON 对象,不是 HTML 字符串;编辑后 `v-model` 会更新这个对象,但不会自动保存到服务器。组件依赖浏览器 DOM,SSR 项目应在客户端挂载它。
72
+
73
+ ### AI Skill 接入与使用
74
+
75
+ **Skill 在哪里:**源码位于本仓库的 `packages/skills/norio-rich-text/`,独立发布地址为 [norio-office-rich-text-skill](https://github.com/cgq001/norio-office-rich-text-skill)。入口是 [`SKILL.md`](https://github.com/cgq001/norio-office-rich-text-skill/blob/main/norio-rich-text/SKILL.md);`references/` 提供协议和操作说明,`examples/` 提供输入样例,`schemas/` 提供校验规则,`scripts/` 是可选的离线 CLI。Skill 不随 `@norio-office/rich-text` npm 包自动安装;请把整个 `norio-rich-text/` 目录放到所用 AI 平台支持的 Skill 位置,并按该平台的方式启用它,不要只复制 `SKILL.md`。
76
+
77
+ **接入在线编辑器:**宿主项目仍需安装上面的编辑器包,并完成以下绑定;单独安装 Skill 不会连接到浏览器里的文档。
78
+
79
+ 1. 在编辑模式渲染 `<RichTextEditor ref="editorRef" :show-ai-target-button="true" />`。按钮默认不显示;预览模式下始终隐藏。
80
+ 2. 组件挂载后,用真实编辑器实例和稳定的 `documentId` 创建 `createRichTextAiBridge`,监听 `ai-target-change`。用户点按钮会锁定当前光标/选区;点正文、点标记关闭按钮或宿主调用 `clearAiTarget()` 会清除标记,并通过事件通知宿主。再次点工具栏按钮不会取消标记。
81
+ 3. 将 `getRichTextToolDefinitions()` 的定义和 `createRichTextToolHandlers(bridge, host)` 的同名处理函数注册到自己的 AI 运行时。宿主负责模型请求、文档权限、外部资源授权、文件存储和请求取消;编辑器不自带这些服务。
82
+ 4. 发送编辑指令前读取 `bridge.getAiTarget()`,用它的 `targetId` 创建 `bridge.createEditContext(...)`,把返回的 `contextId`、`targetRefs` 等交给工具调用。不要自行构造 `targetRef` 或直接替换整个 `v-model` 来做局部编辑。
83
+
84
+ 下面是浏览器侧的关键绑定(假设已在组件挂载后取得 `editorRef`,并准备好 `hostDocumentId`、`activeTarget`;保存函数和 AI 工具注册由你的项目实现):
85
+
86
+ ```ts
87
+ import { createRichTextAiBridge, createRichTextToolHandlers } from '@norio-office/rich-text/ai'
88
+ import { getRichTextToolDefinitions } from '@norio-office/rich-text/ai-protocol'
89
+
90
+ const bridge = createRichTextAiBridge(editorRef.value!, { documentId: hostDocumentId })
91
+ const stop = bridge.onEvent(event => {
92
+ if (event.type === 'ai-target-change') {
93
+ activeTarget.value = event.target // null 表示标记已清除;宿主也应取消相应的模型请求。
94
+ }
95
+ })
96
+ const handlers = createRichTextToolHandlers(bridge, {
97
+ createDocument: async ({ title, bytes }) => {
98
+ // 由宿主保存 .nordox 字节,并返回持久化后的文档 ID。
99
+ return { documentId: await hostSaveDocument(title, bytes) }
100
+ },
101
+ })
102
+ const definitions = getRichTextToolDefinitions()
103
+ // 将 definitions 和 handlers 中的同名函数注册到宿主 AI 运行时。
104
+
105
+ function beginAiEdit(userInstruction: string) {
106
+ const target = bridge.getAiTarget()
107
+ if (!target) throw new Error('请先选择 AI 编辑范围')
108
+ const context = bridge.createEditContext({
109
+ requestId: crypto.randomUUID(), instruction: userInstruction,
110
+ scope: 'selection', targetId: target.targetId,
111
+ })
112
+ // 后续读取与局部修改只使用 context.contextId、context.targetRefs 等返回值。
113
+ return context
114
+ }
115
+
116
+ // 宿主的“取消范围”按钮;编辑器正文点击和标记关闭按钮也会发出清除事件。
117
+ function clearRange() {
118
+ if (activeTarget.value) {
119
+ bridge.clearAiTarget({ targetId: activeTarget.value.targetId, reason: 'host-close' })
120
+ }
121
+ }
122
+ // 文档页面卸载时:stop(); bridge.dispose()
123
+ ```
124
+
125
+ Skill 指导 AI 使用 `richtext_get_capabilities`、`richtext_get_selection`、`richtext_read_target`、`richtext_apply_patch` 等工具;**工具必须由宿主实际注册和授权**。在单人模式和 Yjs 协作模式下均通过同一个 Bridge 执行局部编辑;协作模式还需要宿主原有的协同连接、权限和保存流程。运行时示例见 [`examples/ai/browser/App.vue`](examples/ai/browser/App.vue),完整约束、流式预览和资源处理见 [AI 接入指南](docs/ai/README.md)及 [Skill 集成说明](https://github.com/cgq001/norio-office-rich-text-skill/blob/main/norio-rich-text/references/integration.md)。
126
+
127
+ **只生成/校验文件:**Node.js 20+ 环境安装兼容的 `@norio-office/rich-text` 后,在 Skill 目录运行:
128
+
129
+ ```bash
130
+ node scripts/rich-text.mjs capabilities
131
+ node scripts/rich-text.mjs validate-document --input examples/basic-document.json
132
+ node scripts/rich-text.mjs create --input examples/basic-document.json --output result.nordox
133
+ ```
134
+
135
+ CLI 不能直接修改打开的编辑器;在线编辑必须由宿主接通 Bridge 和工具处理函数。
136
+
137
+ ### 保存、加载与清空
138
+
139
+ 单人编辑时,把完整 JSON 存入数据库,打开文档时再赋给 `content`。不要只保存 `getText()`,它会丢失标题、颜色、表格和图片等结构。
140
+
141
+ 下面是可独立使用的本地演示:手动保存到浏览器 `localStorage`,重新打开页面时恢复。它不涉及上传或服务器,也不适用于多人协同的内容同步。
142
+
143
+ ```vue
144
+ <script setup lang="ts">
145
+ import { onMounted, ref } from 'vue'
146
+ import type { JSONContent } from '@tiptap/core'
147
+ import { RichTextEditor } from '@norio-office/rich-text'
148
+ import '@norio-office/rich-text/style.css'
149
+
150
+ const storageKey = 'rich-text-demo'
151
+ const createEmptyDocument = (): JSONContent => ({
152
+ type: 'doc',
153
+ content: [{ type: 'paragraph' }],
154
+ })
155
+ const content = ref<JSONContent>(createEmptyDocument())
156
+ const status = ref('')
157
+
158
+ onMounted(() => {
159
+ try {
160
+ const saved = localStorage.getItem(storageKey)
161
+ if (!saved) return
162
+ const parsed = JSON.parse(saved) as JSONContent
163
+ if (parsed.type !== 'doc' || !Array.isArray(parsed.content)) {
164
+ throw new Error('文档格式不正确')
165
+ }
166
+ content.value = parsed
167
+ status.value = '已恢复上次保存的文档'
168
+ } catch {
169
+ status.value = '读取失败,已打开空文档'
170
+ }
171
+ })
172
+
173
+ function saveDocument() {
174
+ try {
175
+ localStorage.setItem(storageKey, JSON.stringify(content.value))
176
+ status.value = '已保存到当前浏览器'
177
+ } catch {
178
+ status.value = '保存失败,请检查浏览器存储空间或权限'
179
+ }
180
+ }
181
+
182
+ function clearDocument() {
183
+ content.value = createEmptyDocument()
184
+ status.value = '已清空编辑区,点击保存后才覆盖旧存档'
185
+ }
186
+ </script>
187
+
188
+ <template>
189
+ <button type="button" @click="saveDocument">保存</button>
190
+ <button type="button" @click="clearDocument">清空</button>
191
+ <span>{{ status }}</span>
192
+ <RichTextEditor v-model="content" document-name="演示文档" />
193
+ </template>
194
+ ```
195
+
196
+ 实际项目可以将 `localStorage` 换成自己的读写接口。若监听 `change` 自动保存,建议做防抖和失败提示;`v-model` 和 `change` 对应同一次内容更新,不要分别调用两次保存接口。
197
+
198
+ 注意:当前实现中,初次挂载不传 `modelValue` 或传 `null`,单人模式会显示内置示例文字,不是空文档;挂载后将它改成 `null` 也不会清空。要清空请传上例的 `{ type: 'doc', content: [{ type: 'paragraph' }] }`。协同模式以 Yjs 为准,不能用这个赋值方式覆盖房间内容。
134
199
 
135
200
  ### Props
136
201
 
137
202
  | Prop | 类型 | 默认值 | 说明 |
138
203
  | --- | --- | --- | --- |
139
- | `modelValue` | `JSONContent \| null` | `null` | 编辑器 JSON,支持 `v-model`;`null` 不表示清空,见上方示例。 |
140
- | `documentName` | `string` | `''` | 内置导出下载的文件名基础名;组件会自动追加 `.pdf`、`.png` 或 `.html`。 |
141
- | `editable` | `boolean` | `true` | 是否允许编辑。 |
142
- | `mode` | `'edit' \| 'preview'` | `'edit'` | 编辑模式或预览模式。 |
143
- | `showToolbar` | `boolean` | `true` | 编辑状态下是否显示顶部工具栏。预览状态下始终隐藏。 |
144
- | `watermark` | `RichTextEditorWatermarkOptions \| null` | `null` | 文档页面文本水印配置;不传或 `text` 为空时不显示水印。 |
145
- | `showOutline` | `boolean` | `true` | 是否启用内置大纲及贴边入口,面板默认收起。设为 `false` 后可以配合外部 `RichTextOutline` 组件自行放置目录。 |
146
- | `outlinePlacement` | `'left' \| 'right'` | `'right'` | 大纲面板位置。 |
147
- | `messages` | `RichTextEditorMessages \| null` | `null` | 覆盖内置 UI 文案。 |
148
- | `featureCodes` | `RichTextEditorCode[] \| null` | `null` | 受控入口的统一白名单,适用边界见下方说明。Vue 模板中写作 `feature-codes`。 |
149
- | `enabledFeatureItems` | `RichTextEditorFeatureItemKey[] \| null` | `null` | 旧版高级功能白名单;未传 `featureCodes` 时生效,支持旧的 `outline`。 |
150
- | `enabledExportItems` | `RichTextEditorExportItemKey[] \| null` | `undefined` | 旧版导出菜单白名单;未传 `featureCodes` 时兼容生效。 |
151
- | `enabledInsertMenuItems` | `RichTextEditorInsertMenuItemKey[] \| null` | `undefined` | 旧版插入菜单白名单;未传 `featureCodes` 时兼容生效。 |
152
- | `enabledToolbarActions` | `RichTextEditorToolbarActionKey[] \| null` | `undefined` | 旧版工具栏能力白名单;未传 `featureCodes` 时兼容生效。 |
204
+ | `modelValue` | `JSONContent \| null` | `null` | 编辑器 JSON,支持 `v-model`;`null` 不表示清空,见上方示例。 |
205
+ | `documentName` | `string` | `''` | 文档名称,用作 `.nordox` 导出时的标题;PDF、图片、HTML 的下载文件名由宿主决定。 |
206
+ | `mode` | `'edit' \| 'preview'` | `'edit'` | 编辑模式或预览模式。 |
207
+ | `showToolbar` | `boolean` | `true` | 编辑状态下是否显示顶部工具栏。预览状态下始终隐藏。 |
208
+ | `showAiTargetButton` | `boolean` | `false` | 在工具栏末尾显示 AI 编辑目标按钮;需宿主创建 Bridge 并订阅目标事件。预览状态下隐藏。 |
209
+ | `watermark` | `RichTextEditorWatermarkOptions \| null` | `null` | 文档页面文本水印配置;不传或 `text` 为空时不显示水印。 |
210
+ | `showOutline` | `boolean` | `true` | 是否启用内置大纲及贴边入口,面板默认收起。设为 `false` 后可以配合外部 `RichTextOutline` 组件自行放置目录。 |
211
+ | `outlinePlacement` | `'left' \| 'right'` | `'right'` | 大纲面板位置。 |
212
+ | `messages` | `RichTextEditorMessages \| null` | `null` | 覆盖内置 UI 文案。 |
213
+ | `featureCodes` | `RichTextEditorCode[] \| null` | `null` | 受控入口的统一白名单,适用边界见下方说明。Vue 模板中写作 `feature-codes`。 |
214
+ | `enabledFeatureItems` | `RichTextEditorFeatureItemKey[] \| null` | `null` | 旧版高级功能白名单;未传 `featureCodes` 时生效,支持旧的 `outline`。 |
215
+ | `enabledExportItems` | `RichTextEditorExportItemKey[] \| null` | `undefined` | 兼容保留的旧版参数;内置导出/打印入口已移除,不影响实例导出方法。 |
216
+ | `enabledInsertMenuItems` | `RichTextEditorInsertMenuItemKey[] \| null` | `undefined` | 旧版插入菜单白名单;未传 `featureCodes` 时兼容生效。 |
217
+ | `enabledToolbarActions` | `RichTextEditorToolbarActionKey[] \| null` | `undefined` | 旧版工具栏能力白名单;未传 `featureCodes` 时兼容生效。 |
153
218
  | `placeholder` | `string` | `''` | 空内容占位文案。 |
154
219
  | `mention` | `boolean` | `false` | 是否启用 `@` 提及功能;只有设为 `true` 时输入 `@` 才会打开候选面板,`insertMention()` 才会插入提及节点。 |
155
- | `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs 协同配置,在组件创建时使用。 |
220
+ | `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs 协同配置,在组件创建时使用。 |
156
221
  | `uploadImage` | `RichTextEditorUploadHook \| null` | `null` | 内置图片选择、图片块上传时调用;返回最终可访问 URL 后组件插入图片。 |
157
222
  | `uploadVideo` | `RichTextEditorUploadHook \| null` | `null` | 内置视频选择、视频块上传时调用;返回最终可访问 URL 后组件插入视频。 |
158
223
  | `uploadFile` | `RichTextEditorUploadHook \| null` | `null` | 本地文件选择器上传时调用;返回最终可访问 URL 后组件插入文件卡片。 |
159
224
  | `onUploadError` | `RichTextEditorUploadErrorHandler \| null` | `null` | 上传失败回调;同时也会触发 `upload-error` 事件。 |
160
- | `mentionProvider` | `RichTextEditorMentionProvider \| null` | `undefined` | `@` 提及候选数据提供函数,兼容用法。 |
161
- | `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `undefined` | `@mention-search` 函数式事件对应的异步候选加载函数;优先于 `mentionProvider`。 |
162
- | `comments` | `RichTextEditorCommentThread[] \| null` | `null` | 评论列表,由业务保存并回传;不写入正文 JSON。 |
163
- | `commentUser` | `RichTextEditorCommentUser \| null` | `null` | 当前评论用户;未传时尝试从协同用户中获取,两者都不可用则不能新建或回复。 |
164
- | `showComments` | `boolean` | `false` | 显示评论入口和侧栏;使用功能白名单时还需包含 `comments`。 |
165
- | `commentMention` | `boolean` | `true` | 评论输入框中的提及开关,与正文 `mention` 独立;白名单还需包含 `mention`。 |
166
- | `uploadCommentImage` | `RichTextEditorUploadHook \| null` | `null` | 评论图片上传;未传时回退到 `uploadImage`。 |
167
- | `commentMentionProvider` | `RichTextEditorCommentMentionProvider \| null` | `null` | 评论提及候选加载函数,与正文候选独立。 |
168
- | `onCommentMentionSearch` | `RichTextEditorCommentMentionProvider \| null` | `null` | 评论候选加载函数的另一种传法;优先于 `commentMentionProvider`。 |
169
-
170
- `featureCodes` 不传或为 `null` 时回退到对应的旧版白名单;旧版也未配置时,不限制这些受控功能。评论、正文提及和协同仍需各自的配置。传数组后,优先于四个旧版白名单;传 `[]` 表示不开放受白名单控制的入口。比如 `['pdf', 'image']` 保留底部 PDF/图片导出和图片插入入口。
171
-
172
- 表中的 `undefined` 表示组件没有给该可选 prop 设置显式默认值,即“未传入”;这些配置传 `null` 同样按未配置处理,白名单会继续使用对应的旧版配置(若有)。
173
-
174
- 这里的“授权码”是前端功能开关,不是安全权限:基础文字格式仍可使用,当前句柄的插入/转换菜单、拖拽上传和多数实例方法没有统一按此数组过滤,也不会删除文档已有节点。业务权限、上传权限和保存权限需要在业务层及后端校验。新项目建议统一使用 `feature-codes`,不要依赖它实现严格的编辑权限隔离。
225
+ | `mentionProvider` | `RichTextEditorMentionProvider \| null` | `undefined` | `@` 提及候选数据提供函数,兼容用法。 |
226
+ | `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `undefined` | `@mention-search` 函数式事件对应的异步候选加载函数;优先于 `mentionProvider`。 |
227
+ | `comments` | `RichTextEditorCommentThread[] \| null` | `null` | 评论列表,由业务保存并回传;不写入正文 JSON。 |
228
+ | `commentUser` | `RichTextEditorCommentUser \| null` | `null` | 当前评论用户;未传时尝试从协同用户中获取,两者都不可用则不能新建或回复。 |
229
+ | `showComments` | `boolean` | `false` | 显示评论入口和侧栏;使用功能白名单时还需包含 `comments`。 |
230
+ | `commentMention` | `boolean` | `true` | 评论输入框中的提及开关,与正文 `mention` 独立;白名单还需包含 `mention`。 |
231
+ | `uploadCommentImage` | `RichTextEditorUploadHook \| null` | `null` | 评论图片上传;未传时回退到 `uploadImage`。 |
232
+ | `commentMentionProvider` | `RichTextEditorCommentMentionProvider \| null` | `null` | 评论提及候选加载函数,与正文候选独立。 |
233
+ | `onCommentMentionSearch` | `RichTextEditorCommentMentionProvider \| null` | `null` | 评论候选加载函数的另一种传法;优先于 `commentMentionProvider`。 |
234
+
235
+ `featureCodes` 不传或为 `null` 时回退到对应的旧版白名单;旧版也未配置时,不限制这些受控功能。评论、正文提及和协同仍需各自的配置。传数组后,优先于仍有界面入口的旧版白名单;传 `[]` 表示不开放受白名单控制的入口。比如 `['image']` 保留插入菜单里的图片入口。导出和打印不再提供内置界面入口,`pdf`、`html`、`print` 代码仅为兼容旧配置保留,实例导出方法不受这些代码限制。
236
+
237
+ 表中的 `undefined` 表示组件没有给该可选 prop 设置显式默认值,即“未传入”;这些配置传 `null` 同样按未配置处理,白名单会继续使用对应的旧版配置(若有)。
238
+
239
+ 这里的“授权码”是前端功能开关,不是安全权限:基础文字格式仍可使用,当前句柄的插入/转换菜单、拖拽上传和多数实例方法没有统一按此数组过滤,也不会删除文档已有节点。业务权限、上传权限和保存权限需要在业务层及后端校验。新项目建议统一使用 `feature-codes`,不要依赖它实现严格的编辑权限隔离。
175
240
 
176
241
  ### 水印
177
242
 
178
- `watermark` 只作为页面视觉层渲染,不写入编辑器 JSON,也不会影响 `getText()` 的纯文本结果。当前导出清理流程会移除水印层,所以 PDF、图片、HTML 和内置打印输出都不保留它。若业务要求导出水印,需要在业务导出流程中另行处理,不能把页面水印当成文件防泄漏能力。
243
+ `watermark` 只作为页面视觉层渲染,不写入编辑器 JSON,也不会影响 `getText()` 的纯文本结果。当前导出清理流程会移除水印层,所以 PDF、图片、HTML 输出都不保留它。若业务要求导出水印,需要在业务导出流程中另行处理,不能把页面水印当成文件防泄漏能力。
179
244
 
180
245
  ```vue
181
246
  <RichTextEditor
@@ -198,206 +263,210 @@ function clearDocument() {
198
263
  | `rotate` | `number` | `-24` | 水印倾斜角度,单位 deg。 |
199
264
  | `showInEdit` | `boolean` | `true` | 编辑状态下是否显示水印;预览状态始终按配置显示。 |
200
265
 
201
- 旧版白名单兼容示例(不要同时传 `feature-codes`):
202
-
203
- ```vue
204
- <RichTextEditor
205
- v-model="content"
206
- :enabled-export-items="['html', 'image']"
266
+ 旧版白名单兼容示例(不要同时传 `feature-codes`):
267
+
268
+ ```vue
269
+ <RichTextEditor
270
+ v-model="content"
271
+ :enabled-export-items="['html', 'image']"
207
272
  :enabled-insert-menu-items="['image', 'local-file', 'blockquote']"
208
273
  :enabled-toolbar-actions="['blockquote']"
209
274
  />
210
275
  ```
211
276
 
212
- ### 可用 Key
213
-
214
- 所有授权码统一从 `feature-codes` 传入,也可以从包里导入各类 `RICH_TEXT_EDITOR_*_CODES` 避免手写字符串:
215
-
216
- ```ts
217
- import {
218
- RICH_TEXT_EDITOR_EXPORT_CODES,
219
- RICH_TEXT_EDITOR_FEATURE_CODES,
220
- RICH_TEXT_EDITOR_INSERT_MENU_CODES,
221
- RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES,
222
- } from '@norio-office/rich-text'
223
- import type { RichTextEditorCode } from '@norio-office/rich-text'
224
-
225
- const featureCodes: RichTextEditorCode[] = [
226
- RICH_TEXT_EDITOR_EXPORT_CODES.pdf,
227
- RICH_TEXT_EDITOR_INSERT_MENU_CODES.image,
228
- RICH_TEXT_EDITOR_FEATURE_CODES.outlineRight,
229
- RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES.blockquote,
230
- ]
231
- ```
232
-
233
- 上述常量是对象,取其中的值组成数组即可。`featureCodes` 是受控入口共用的白名单;它的适用边界见 Props 下方说明:
234
-
235
- ```vue
236
- <RichTextEditor
237
- v-model="content"
238
- :feature-codes="['pdf', 'image']"
239
- />
240
- ```
241
-
242
- 上面这个配置会开启 PDF 导出、图片导出和插入图片入口。因为 `image` 是统一授权码,所以它会同时命中导出图片和插入图片。
243
-
244
- 完整授权码清单:
245
-
246
- | Code | 分类 | 控制内容 | 仍需配合的 prop |
247
- | --- | --- | --- | --- |
248
- | `comments` | 高级功能 | 评论按钮、右侧评论栏、正文评论锚点点击和评论交互。 | `showComments`、`comments`、`commentUser` |
249
- | `outlineLeft` | 高级功能 | 内置大纲和贴边图标按钮,授权后位于左侧。 | `showOutline` |
250
- | `outlineRight` | 高级功能 | 内置大纲和贴边图标按钮,授权后位于右侧。 | `showOutline` |
251
- | `watermark` | 高级功能 | 页面水印显示;当前导出不会保留水印。 | `watermark` |
252
- | `collaboration` | 高级功能 | Yjs 协同编辑和协同光标;未授权时按单人模式初始化。 | `collaboration` |
253
- | `mention` | 高级功能 | 正文 `@` 提及、评论输入框里的 `@` 提及弹层和提及实例方法。 | `mention`、`commentMention`、`mentionProvider`、`commentMentionProvider` |
254
- | `pdf` | 导出 | 导出菜单里的 PDF 导出入口。 | `documentName` |
255
- | `html` | 导出 | 导出菜单里的 HTML 导出入口。 | `documentName` |
256
- | `image` | 导出 + 插入 | 导出菜单里的图片导出入口,同时控制插入菜单里的图片入口。 | `uploadImage`、`documentName` |
257
- | `print` | 导出 | 底部信息栏的打印入口。 | - |
258
- | `video` | 插入菜单 | 插入菜单里的视频入口。 | `uploadVideo` |
259
- | `table` | 插入菜单 | 插入菜单里的表格入口。 | - |
260
- | `local-file` | 插入菜单 | 插入菜单里的本地文件入口。 | `uploadFile` |
261
- | `columns` | 插入菜单 | 插入菜单里的分栏入口。 | - |
262
- | `highlight-block` | 插入菜单 | 插入菜单里的高亮块入口。 | - |
263
- | `date` | 插入菜单 | 插入菜单里的日期入口;当前作为授权码预留。 | - |
264
- | `code-block` | 插入菜单 | 插入菜单里的代码块入口。 | - |
265
- | `formula` | 插入菜单 | 插入菜单里的公式入口。 | - |
266
- | `blockquote` | 插入菜单 + 工具栏 | 插入菜单里的引用入口,同时控制工具栏里的引用按钮。 | - |
267
- | `emoji` | 插入菜单 + 工具栏 | 插入菜单里的表情入口,同时控制工具栏里的表情按钮。 | - |
268
- | `link` | 插入菜单 | 插入菜单里的链接入口。 | - |
269
- | `divider` | 插入菜单 | 插入菜单里的分割线入口。 | - |
270
- | `countdown` | 插入菜单 | 插入菜单里的倒计时入口。 | - |
271
- | `markdown-import` | 插入菜单 | 插入菜单里的 Markdown 导入入口。 | - |
272
-
273
- 同一个 code 只写一次即可;例如 `image` 同时授权图片导出和插入图片,`blockquote` 同时授权插入引用和工具栏引用按钮。
274
-
275
- 大纲授权规则:`featureCodes` 里只有 `outlineLeft` 时,大纲及入口显示在左侧;只有 `outlineRight` 时显示在右侧;两个都有时按 `outlinePlacement` 决定位置;两个都没有时不显示内置大纲和贴边入口。
276
-
277
- 举例:想保留评论、正文提及和右侧大纲,可以传 `['comments', 'mention', 'outlineRight']`,同时配置 `:show-comments="true"`、`:mention="true"`、当前用户和各自的数据源。只写 code 不会自动生成评论用户、提及候选或上传接口。
278
-
279
- ### 复制、剪切和粘贴
280
-
281
- 先分清两个菜单:选中文字后浮在附近的是“文字气泡”,用来改选中文字的格式;鼠标移到段落、图片、表格等块旁边后出现的按钮是“句柄”,打开的是整块操作菜单。句柄菜单始终操作它对应的块,不一定是光标所在的块。
282
-
283
- 块侧边菜单与 `Ctrl/Cmd+C`、`Ctrl/Cmd+X`、`Ctrl/Cmd+V` 可以交叉使用,保留表格、高亮块、任务列表、图片等节点类型和属性。菜单粘贴在当前块下方插入,优先读取最新系统剪贴板;普通快捷键粘贴保留文字选区和代码块的原生行为,无需额外对接。
284
-
285
- 菜单读取剪贴板需要安全上下文(HTTPS 或 localhost)和浏览器权限。读取被拒绝时回退到本编辑器缓存,外部内容可用快捷键粘贴;菜单剪切只有在成功写入系统剪贴板后才删除原节点。
286
-
287
- ### 块菜单的对齐与颜色
288
-
289
- 正文和标题的句柄菜单提供“缩进和对齐”:左、中、右对齐显示当前选中项,分割线下方是增加、减少缩进;缩进范围为 0-8,到达边界时对应操作禁用。
290
-
291
- “颜色”独立放在“缩进和对齐”下方,可设置字体颜色和文字背景色,每项都有“自定义颜色”入口,打开三级内置颜色选择器。“恢复默认”只清除文字色和背景色,保留字体、字号、加粗等格式。
292
-
293
- 有序列表和无序列表的句柄菜单也提供“缩进和对齐”,支持左/中/右对齐及增减缩进。操作统一作用于该列表内的正文和标题(包括嵌套项),保留列表结构、编号及文字格式,不影响其他列表;缩进范围为 0–8,各文本块独立限制,设置后菜单保持打开。
294
-
295
- 句柄菜单顶部的类型按钮会高亮回显当前句柄节点:正文、H1–H6、有序列表、无序列表或待办。回显跟随句柄目标,不受其他位置的光标影响;转换或修改节点后重新打开菜单会显示新类型,插入菜单不会误显示为当前类型。
296
-
297
- 句柄操作菜单默认以句柄中心上下居中,仅在顶部或底部空间不足时向可视区域内避让。定位按实际菜单高度计算,跟随滚动、窗口尺寸和缩放更新;空行“+”的插入菜单仍在按钮下方展开。
298
-
299
- 句柄菜单的“颜色”和“剪切”之间、以及“删除”上方使用统一横线分组,样式与“删除”和添加菜单之间的分割线一致。
300
-
301
- 句柄菜单提供“在上方添加”和“在下方添加”,分别使用对应方向的图标。两者共用基础/常用节点子菜单,在目标块前后插入并保留原块(包括空段落),支持撤销;窄屏使用带“返回”的子菜单。
302
-
303
- 编辑器自有弹出菜单统一使用直角,包括工具栏下拉、插入及句柄多级菜单、文字/表格气泡、颜色/表情/@提及面板,以及图片、视频、链接、代码、倒计时、日期和公式的浮动设置。面板、矩形选项和色块均无圆角;头像、单选圆点及开关保留圆形,正文内容块、图片和主工具栏外观不变。
304
-
305
- 二级、三级颜色菜单选色后保持打开,可连续调整;高亮块边框/填充及分割线颜色同样不会自动关闭。小屏下使用带“返回”的逐级菜单。操作仅作用于句柄对应的块,支持撤销、重做,沿用文档 JSON/HTML 保存,无需新增对接参数。
306
-
307
- 文字背景色使用现有 `textStyle.backgroundColor`,与高亮块整块填充、表格单元格背景色分别设置。段落、标题、列表、引用和高亮块均支持文字颜色菜单。
308
-
309
- ### 文字选区气泡菜单
310
-
311
- 在编辑状态选中文字,会在选区附近显示格式气泡菜单,提供正文/标题、字体、字号、文字色、文字背景色、加粗、斜体、下划线、删除线、上下标、对齐与缩进、行内代码和清除格式。上下标互斥切换;颜色使用内置颜色选择器,最近使用颜色与顶部工具栏共享,选色后不关闭面板。
312
-
313
- 顶部工具栏和选区气泡菜单的字号选项统一只保留初号、小初、一号、小一、二号、小二、三号、小三、四号、小四、五号、小五,不显示纯数字字号选项;已有文档的字号数据保持不变。
314
-
315
- 选区气泡的正文按钮显示当前块类型图标;菜单提供正文、一至三级标题、“其他标题”(二级菜单含四至六级)、有序列表、无序列表、任务、代码块、引用和高亮块。代码块与引用之间使用分隔线,代码块、引用、高亮块分别遵循现有 `code-block`、`blockquote`、`highlight-block` 授权码。选择后直接转换或包裹原有内容,不额外插入空块;不提供尚未实现的同步块入口。
316
-
317
- 操作保留选区:行内格式只修改选中文字,对齐、缩进和标题修改所在块。表格内选中文字显示文字气泡,选中单元格或整表显示表格气泡。收起选区、点击外部或按 Escape 可关闭;小屏自动换行,预览/只读、演示和块句柄菜单打开时不显示。无需新增对接参数,格式仍随现有文档 JSON/HTML 保存。
318
-
319
- ### 表格主题色
320
-
321
- 选中表格单元格、行或列后,在气泡菜单的“设置单元格背景色”后点击主题图标。内置经典蓝、清新绿、优雅紫、活力橙、玫瑰粉、简约灰,支持分别自定义表头、奇数行、偶数行颜色。
322
-
323
- 也可以鼠标移入表格,打开左侧块操作菜单,悬停或点击“主题色”。该入口上下使用菜单分割线分隔;这里复用相同主题面板,直接修改该菜单对应的表格,不需要先选中单元格;光标位于另一张表格时也不会改错目标。
324
-
325
- 点击三个颜色块会打开编辑器自带的颜色面板,包含默认色、色板、标准色、最近使用和“更多颜色”。默认色恢复经典蓝主题对应区域的颜色;最近使用与工具栏背景色面板共享,选择后立即生效。
326
-
327
- 主题作用于整张表:首行为表头色,第二行开始交替填色,增删行后会自动重新交替。选主题时清除当前表已有的单元格背景覆盖色,之后仍可单独设置单元格背景。“清除样式”清除主题和单元格背景,保留内容、文字格式、合并关系和列宽。
328
-
329
- 无需额外对接接口;主题保存在现有文档 JSON 的表格节点 `attrs.tableTheme` 中,通过 `v-model` / `change` 一起保存,支持撤销、重做、协同和导出。也可在初始文档的表格节点中传入:
330
-
331
- ```ts
332
- attrs: {
333
- tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
334
- }
335
- ```
336
-
337
- 不传 `tableTheme` 或设置为 `null` 时保留原有表格外观。
338
-
339
- ### 分割线样式与颜色
340
-
341
- 鼠标移入分割线,打开左侧块操作菜单:
342
-
343
- - **样式**:只展示实线、虚线、点状线的预览,悬停可查看名称,点击即可切换。
344
- - **颜色**:复用编辑器颜色面板,支持默认色、色板、标准色、最近使用和更多颜色;默认色恢复原来的浅灰色,最近使用与文字颜色面板共享。
345
-
346
- 样式和颜色为独立一组,与上方粘贴、下方删除之间使用菜单分割线分隔。
347
-
348
- 修改只作用于当前菜单对应的分割线,不需要先选中它。无需额外回调;属性保存在 `horizontalRule` 节点中,通过现有 `v-model` / `change` 保存,支持撤销、重做、复制粘贴和导出。初始文档示例:
349
-
350
- ```ts
351
- { type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
352
- ```
353
-
354
- `lineStyle` 可选 `solid`(实线)、`dashed`(虚线)、`dotted`(点状线);`lineColor` 使用六位 HEX 色值,`null` 表示默认色。不传属性的旧文档仍显示默认实线。`feature-codes` 中的 `divider` 控制插入入口,无需新增授权码。
355
-
356
- ### 高亮块颜色与设置
357
-
358
- 移入高亮块并打开句柄菜单,在“粘贴”和“删除”之间可设置。句柄主菜单按内容撑开,不显示内部滚动条,靠近底部时自动上移:
359
-
360
- - **边框颜色**:二级菜单提供预设色、无颜色和恢复默认;“自定义颜色”打开三级内置颜色选择器,支持标准色、最近使用、更多颜色、默认和清除颜色。
361
- - **填充颜色**:独立设置块背景,颜色选择方式同上。
362
- - **设置**:切换“启用表情”;关闭后隐藏左侧表情,开启后可继续点击表情进行选择。
363
-
364
- 边框和填充独立设置,选色后二级、三级菜单保持打开,可以连续修改;窄屏通过“返回”切换菜单层级。
365
-
366
- 高亮块不再显示气泡菜单。操作仅影响句柄对应的高亮块,不依赖当前光标位置;属性仍保存在文档 JSON/HTML 中,支持撤销、重做,无需新增对接参数。
367
-
368
- ### 引用颜色
369
-
370
- 移入引用块并打开左侧句柄菜单,在“粘贴”和“删除”之间可设置 **边框颜色**、**背景颜色**。二级菜单各提供 15 个预设色,加上无颜色按钮,完整显示两行、每行 8 格;保留原有预设和默认色,并支持恢复默认。“自定义颜色”打开三级内置颜色选择器。选色后菜单保持打开,窄屏通过“返回”切换层级。
371
-
372
- 修改只作用于句柄对应的引用块,不依赖光标位置;边框色、块背景色、文字颜色互不影响。原顶部工具栏的引用颜色设置保留。数据仍使用 `blockquote.attrs.quoteBorderColor`、`blockquote.attrs.quoteBackgroundColor`,随现有文档 JSON/HTML 保存,支持撤销和重做,无需新增对接参数。
373
-
374
- ### 图片描述与链接
375
-
376
- 直接按住图片拖到文档其他位置,会移动原图片,保留宽高、对齐、旋转、描述和链接,不会重复插入。图片组内拖到另一张图片上可调整顺序,拖到组外会移动整组;侧边句柄拖动仍可使用。外部图片文件拖入仍走上传 hook。
377
-
378
- 直接拖图片、句柄拖动和外部文件拖入的块级落点提示统一为蓝色横线及左端圆点。
379
-
380
- 选中图片,点击气泡菜单的“设置图片描述”,即可在图片下方直接输入。描述随输入保存,支持换行;清空文字后再按一次 Backspace,会隐藏描述框,不会删除图片。旧文档或上传结果中已有的 `description` 会自动显示,预览/只读时显示为普通文字。
381
-
382
- 点击“设置图片链接”,在气泡菜单下方弹层输入网址,可勾选“在当前页面打开”。点击“确定”或按 Enter 才保存;“取消”、Escape、点击外部或切换图片均放弃本次修改。清空网址后确定即移除链接,无效网址不会覆盖旧值。
383
-
384
- 编辑状态下点击已设置链接的图片只选中图片,不会跳转;预览、只读或演示状态下才按配置打开链接。保存与导出仍保留链接数据。
385
-
386
- 无需新增对接事件,数据通过现有文档 `v-model` / `change` 保存,也可通过 `insertImage()` 传入:
387
-
388
- ```ts
389
- editorRef.value?.insertImage({
390
- src: 'https://example.com/photo.png',
391
- description: '图片描述',
392
- descriptionVisible: true,
393
- link: 'https://example.com/details',
394
- linkTarget: '_blank',
395
- })
396
- ```
397
-
398
- `descriptionVisible` 可选,不传时根据描述是否为空决定显示;`true` 可显示空描述框,`false` 隐藏描述。`linkTarget` 可选 `_blank`(默认,新页面)或 `_self`(当前页面)。`getImages()` 返回这些字段;描述和已确认链接支持撤销、重做、复制粘贴和导出,未确认的链接草稿不会导出。
399
-
400
- ### 事件
277
+ ### 可用 Key
278
+
279
+ 所有授权码统一从 `feature-codes` 传入,也可以从包里导入各类 `RICH_TEXT_EDITOR_*_CODES` 避免手写字符串:
280
+
281
+ ```ts
282
+ import {
283
+ RICH_TEXT_EDITOR_EXPORT_CODES,
284
+ RICH_TEXT_EDITOR_FEATURE_CODES,
285
+ RICH_TEXT_EDITOR_INSERT_MENU_CODES,
286
+ RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES,
287
+ } from '@norio-office/rich-text'
288
+ import type { RichTextEditorCode } from '@norio-office/rich-text'
289
+
290
+ const featureCodes: RichTextEditorCode[] = [
291
+ RICH_TEXT_EDITOR_EXPORT_CODES.pdf,
292
+ RICH_TEXT_EDITOR_INSERT_MENU_CODES.image,
293
+ RICH_TEXT_EDITOR_FEATURE_CODES.outlineRight,
294
+ RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES.blockquote,
295
+ ]
296
+ ```
297
+
298
+ 上述常量是对象,取其中的值组成数组即可。`featureCodes` 是受控入口共用的白名单;它的适用边界见 Props 下方说明:
299
+
300
+ ```vue
301
+ <RichTextEditor
302
+ v-model="content"
303
+ :feature-codes="['pdf', 'image']"
304
+ />
305
+ ```
306
+
307
+ 上面这个配置会开启 PDF 导出、图片导出和插入图片入口。因为 `image` 是统一授权码,所以它会同时命中导出图片和插入图片。
308
+
309
+ 完整授权码清单:
310
+
311
+ | Code | 分类 | 控制内容 | 仍需配合的 prop |
312
+ | --- | --- | --- | --- |
313
+ | `comments` | 高级功能 | 评论按钮、右侧评论栏、正文评论锚点点击和评论交互。 | `showComments`、`comments`、`commentUser` |
314
+ | `outlineLeft` | 高级功能 | 内置大纲和贴边图标按钮,授权后位于左侧。 | `showOutline` |
315
+ | `outlineRight` | 高级功能 | 内置大纲和贴边图标按钮,授权后位于右侧。 | `showOutline` |
316
+ | `watermark` | 高级功能 | 页面水印显示;当前导出不会保留水印。 | `watermark` |
317
+ | `collaboration` | 高级功能 | Yjs 协同编辑和协同光标;未授权时按单人模式初始化。 | `collaboration` |
318
+ | `mention` | 高级功能 | 正文 `@` 提及、评论输入框里的 `@` 提及弹层和提及实例方法。 | `mention`、`commentMention`、`mentionProvider`、`commentMentionProvider` |
319
+ | `pdf` | 兼容代码 | 内置入口已移除;`exportPdf()` 仍可调用。 | - |
320
+ | `html` | 兼容代码 | 内置入口已移除;`exportHtml()` 仍可调用。 | - |
321
+ | `image` | 插入菜单 | 控制插入菜单里的图片入口;`exportImage()` 不受白名单限制。 | `uploadImage` |
322
+ | `print` | 兼容代码 | 内置打印入口已移除。 | - |
323
+ | `video` | 插入菜单 | 插入菜单里的视频入口。 | `uploadVideo` |
324
+ | `table` | 插入菜单 | 插入菜单里的表格入口。 | - |
325
+ | `local-file` | 插入菜单 | 插入菜单里的本地文件入口。 | `uploadFile` |
326
+ | `columns` | 插入菜单 | 插入菜单里的分栏入口。 | - |
327
+ | `highlight-block` | 插入菜单 | 插入菜单里的高亮块入口。 | - |
328
+ | `date` | 插入菜单 | 插入菜单里的日期入口;当前作为授权码预留。 | - |
329
+ | `code-block` | 插入菜单 | 插入菜单里的代码块入口。 | - |
330
+ | `formula` | 插入菜单 | 插入菜单里的公式入口。 | - |
331
+ | `blockquote` | 插入菜单 + 工具栏 | 插入菜单里的引用入口,同时控制工具栏里的引用按钮。 | - |
332
+ | `emoji` | 插入菜单 + 工具栏 | 插入菜单里的表情入口,同时控制工具栏里的表情按钮。 | - |
333
+ | `link` | 插入菜单 | 插入菜单里的链接入口。 | - |
334
+ | `divider` | 插入菜单 | 插入菜单里的分割线入口。 | - |
335
+ | `countdown` | 插入菜单 | 插入菜单里的倒计时入口。 | - |
336
+ | `markdown-import` | 插入菜单 | 插入菜单里的 Markdown 导入入口。 | - |
337
+
338
+ 同一个 code 只写一次即可;例如 `blockquote` 同时控制插入引用和工具栏引用按钮。导出实例方法不受 code 控制。
339
+
340
+ 大纲授权规则:`featureCodes` 里只有 `outlineLeft` 时,大纲及入口显示在左侧;只有 `outlineRight` 时显示在右侧;两个都有时按 `outlinePlacement` 决定位置;两个都没有时不显示内置大纲和贴边入口。
341
+
342
+ 举例:想保留评论、正文提及和右侧大纲,可以传 `['comments', 'mention', 'outlineRight']`,同时配置 `:show-comments="true"`、`:mention="true"`、当前用户和各自的数据源。只写 code 不会自动生成评论用户、提及候选或上传接口。
343
+
344
+ ### 复制、剪切和粘贴
345
+
346
+ 先分清两个菜单:选中文字后浮在附近的是“文字气泡”,用来改选中文字的格式;鼠标移到段落、图片、表格等块旁边后出现的按钮是“句柄”,打开的是整块操作菜单。句柄菜单始终操作它对应的块,不一定是光标所在的块。
347
+
348
+ 句柄只在空闲时悬停显示,不会随光标自动出现。输入(包括中文输入法)、拖动选中文字或块框选时,句柄及其菜单会隐藏;有文字、图片、视频、链接或表格气泡菜单时,也不显示句柄。例如,选中文字后只能看到格式气泡,收起选区后再次移动鼠标到块旁边,才会显示句柄。
349
+
350
+ 块侧边菜单与 `Ctrl/Cmd+C`、`Ctrl/Cmd+X`、`Ctrl/Cmd+V` 可以交叉使用,保留表格、高亮块、任务列表、图片等节点类型和属性。菜单粘贴在当前块下方插入,优先读取最新系统剪贴板;普通快捷键粘贴保留文字选区和代码块的原生行为,无需额外对接。
351
+
352
+ 菜单读取剪贴板需要安全上下文(HTTPS 或 localhost)和浏览器权限。读取被拒绝时回退到本编辑器缓存,外部内容可用快捷键粘贴;菜单剪切只有在成功写入系统剪贴板后才删除原节点。
353
+
354
+ ### 块菜单的对齐与颜色
355
+
356
+ 正文和标题的句柄菜单提供“缩进和对齐”:左、中、右对齐显示当前选中项,分割线下方是增加、减少缩进;缩进范围为 0-8,到达边界时对应操作禁用。
357
+
358
+ “颜色”独立放在“缩进和对齐”下方,可设置字体颜色和文字背景色,每项都有“自定义颜色”入口,打开三级内置颜色选择器。“恢复默认”只清除文字色和背景色,保留字体、字号、加粗等格式。
359
+
360
+ 有序列表和无序列表的句柄菜单也提供“缩进和对齐”,支持左/中/右对齐及增减缩进。操作统一作用于该列表内的正文和标题(包括嵌套项),保留列表结构、编号及文字格式,不影响其他列表;缩进范围为 0–8,各文本块独立限制,设置后菜单保持打开。
361
+
362
+ 句柄菜单顶部的类型按钮会高亮回显当前句柄节点:正文、H1–H6、有序列表、无序列表或待办。回显跟随句柄目标,不受其他位置的光标影响;转换或修改节点后重新打开菜单会显示新类型,插入菜单不会误显示为当前类型。
363
+
364
+ 句柄操作菜单默认以句柄中心上下居中,仅在顶部或底部空间不足时向可视区域内避让。定位按实际菜单高度计算,跟随滚动、窗口尺寸和缩放更新;空行“+”的插入菜单仍在按钮下方展开。
365
+
366
+ 句柄菜单的“颜色”和“剪切”之间、以及“删除”上方使用统一横线分组,样式与“删除”和添加菜单之间的分割线一致。
367
+
368
+ 句柄菜单提供“在上方添加”和“在下方添加”,分别使用对应方向的图标。两者共用基础/常用节点子菜单,在目标块前后插入并保留原块(包括空段落),支持撤销;窄屏使用带“返回”的子菜单。
369
+
370
+ 编辑器自有弹出菜单统一使用直角,包括工具栏下拉、插入及句柄多级菜单、文字/表格气泡、颜色/表情/@提及面板,以及图片、视频、链接、代码、倒计时、日期和公式的浮动设置。面板、矩形选项和色块均无圆角;头像、单选圆点及开关保留圆形,正文内容块、图片和主工具栏外观不变。
371
+
372
+ 二级、三级颜色菜单选色后保持打开,可连续调整;高亮块边框/填充及分割线颜色同样不会自动关闭。小屏下使用带“返回”的逐级菜单。操作仅作用于句柄对应的块,支持撤销、重做,沿用文档 JSON/HTML 保存,无需新增对接参数。
373
+
374
+ 文字背景色使用现有 `textStyle.backgroundColor`,与高亮块整块填充、表格单元格背景色分别设置。段落、标题、列表、引用和高亮块均支持文字颜色菜单。
375
+
376
+ ### 文字选区气泡菜单
377
+
378
+ 在编辑状态选中文字,会在选区附近显示格式气泡菜单,提供正文/标题、字体、字号、文字色、文字背景色、加粗、斜体、下划线、删除线、上下标、对齐与缩进、行内代码和清除格式。上下标互斥切换;颜色使用内置颜色选择器,最近使用颜色与顶部工具栏共享,选色后不关闭面板。
379
+
380
+ 气泡在选择结束后才出现:按住鼠标拖选时隐藏,松开鼠标后显示;按住 Shift 用方向键扩展选区时隐藏,松开 Shift 后显示。例如,拖选两段文字的过程中不会有菜单挡住正文,松开后才显示格式按钮。重新拖选时,已有气泡也会暂时隐藏。
381
+
382
+ 顶部工具栏和选区气泡菜单的字号选项统一只保留初号、小初、一号、小一、二号、小二、三号、小三、四号、小四、五号、小五,不显示纯数字字号选项;已有文档的字号数据保持不变。
383
+
384
+ 选区气泡的正文按钮显示当前块类型图标;菜单提供正文、一至三级标题、“其他标题”(二级菜单含四至六级)、有序列表、无序列表、任务、代码块、引用和高亮块。代码块与引用之间使用分隔线,代码块、引用、高亮块分别遵循现有 `code-block`、`blockquote`、`highlight-block` 授权码。选择后直接转换或包裹原有内容,不额外插入空块;不提供尚未实现的同步块入口。
385
+
386
+ 操作保留选区:行内格式只修改选中文字,对齐、缩进和标题修改所在块。表格内选中文字、单元格或整表时,统一显示一个表格气泡:上方提供字体、字号、文字色、文字背景色、加粗、斜体、下划线、删除线、对齐与缩进,不提供正文/标题、上下标、行内代码和清除格式;下方提供合并、拆分、单元格背景色、主题色及增删行列等表格操作,不能执行的操作会禁用。例如,只选中单元格中的“评论”二字,改字体、字号或文字颜色不会影响同格其他文字;“文字背景颜色”与整格的“设置单元格背景色”互相独立。拖选期间不显示,选择结束后才出现。收起选区、点击外部或按 Escape 可关闭;小屏自动换行,预览/只读和演示时不显示。文字选区优先显示气泡,并关闭已打开的句柄菜单。无需新增对接参数,格式仍随现有文档 JSON/HTML 保存。
387
+
388
+ ### 表格主题色
389
+
390
+ 选中表格单元格、行或列后,在气泡菜单的“设置单元格背景色”后点击主题图标。内置经典蓝、清新绿、优雅紫、活力橙、玫瑰粉、简约灰,支持分别自定义表头、奇数行、偶数行颜色。
391
+
392
+ 也可以鼠标移入表格,打开左侧块操作菜单,悬停或点击“主题色”。该入口上下使用菜单分割线分隔;这里复用相同主题面板,直接修改该菜单对应的表格,不需要先选中单元格;光标位于另一张表格时也不会改错目标。
393
+
394
+ 点击三个颜色块会打开编辑器自带的颜色面板,包含默认色、色板、标准色、最近使用和“更多颜色”。默认色恢复经典蓝主题对应区域的颜色;最近使用与工具栏背景色面板共享,选择后立即生效。
395
+
396
+ 主题作用于整张表:首行为表头色,第二行开始交替填色,增删行后会自动重新交替。选主题时清除当前表已有的单元格背景覆盖色,之后仍可单独设置单元格背景。“清除样式”清除主题和单元格背景,保留内容、文字格式、合并关系和列宽。
397
+
398
+ 无需额外对接接口;主题保存在现有文档 JSON 的表格节点 `attrs.tableTheme` 中,通过 `v-model` / `change` 一起保存,支持撤销、重做、协同和导出。也可在初始文档的表格节点中传入:
399
+
400
+ ```ts
401
+ attrs: {
402
+ tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
403
+ }
404
+ ```
405
+
406
+ 不传 `tableTheme` 或设置为 `null` 时保留原有表格外观。
407
+
408
+ ### 分割线样式与颜色
409
+
410
+ 鼠标移入分割线,打开左侧块操作菜单:
411
+
412
+ - **样式**:只展示实线、虚线、点状线的预览,悬停可查看名称,点击即可切换。
413
+ - **颜色**:复用编辑器颜色面板,支持默认色、色板、标准色、最近使用和更多颜色;默认色恢复原来的浅灰色,最近使用与文字颜色面板共享。
414
+
415
+ 样式和颜色为独立一组,与上方粘贴、下方删除之间使用菜单分割线分隔。
416
+
417
+ 修改只作用于当前菜单对应的分割线,不需要先选中它。无需额外回调;属性保存在 `horizontalRule` 节点中,通过现有 `v-model` / `change` 保存,支持撤销、重做、复制粘贴和导出。初始文档示例:
418
+
419
+ ```ts
420
+ { type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
421
+ ```
422
+
423
+ `lineStyle` 可选 `solid`(实线)、`dashed`(虚线)、`dotted`(点状线);`lineColor` 使用六位 HEX 色值,`null` 表示默认色。不传属性的旧文档仍显示默认实线。`feature-codes` 中的 `divider` 控制插入入口,无需新增授权码。
424
+
425
+ ### 高亮块颜色与设置
426
+
427
+ 移入高亮块并打开句柄菜单,在“粘贴”和“删除”之间可设置。句柄主菜单按内容撑开,不显示内部滚动条,靠近底部时自动上移:
428
+
429
+ - **边框颜色**:二级菜单提供预设色、无颜色和恢复默认;“自定义颜色”打开三级内置颜色选择器,支持标准色、最近使用、更多颜色、默认和清除颜色。
430
+ - **填充颜色**:独立设置块背景,颜色选择方式同上。
431
+ - **设置**:切换“启用表情”;关闭后隐藏左侧表情,开启后可继续点击表情进行选择。
432
+
433
+ 边框和填充独立设置,选色后二级、三级菜单保持打开,可以连续修改;窄屏通过“返回”切换菜单层级。
434
+
435
+ 高亮块不再显示气泡菜单。操作仅影响句柄对应的高亮块,不依赖当前光标位置;属性仍保存在文档 JSON/HTML 中,支持撤销、重做,无需新增对接参数。
436
+
437
+ ### 引用颜色
438
+
439
+ 移入引用块并打开左侧句柄菜单,在“粘贴”和“删除”之间可设置 **边框颜色**、**背景颜色**。二级菜单各提供 15 个预设色,加上无颜色按钮,完整显示两行、每行 8 格;保留原有预设和默认色,并支持恢复默认。“自定义颜色”打开三级内置颜色选择器。选色后菜单保持打开,窄屏通过“返回”切换层级。
440
+
441
+ 修改只作用于句柄对应的引用块,不依赖光标位置;边框色、块背景色、文字颜色互不影响。原顶部工具栏的引用颜色设置保留。数据仍使用 `blockquote.attrs.quoteBorderColor`、`blockquote.attrs.quoteBackgroundColor`,随现有文档 JSON/HTML 保存,支持撤销和重做,无需新增对接参数。
442
+
443
+ ### 图片描述与链接
444
+
445
+ 直接按住图片拖到文档其他位置,会移动原图片,保留宽高、对齐、旋转、描述和链接,不会重复插入。图片组内拖到另一张图片上可调整顺序,拖到组外会移动整组;侧边句柄拖动仍可使用。外部图片文件拖入仍走上传 hook。
446
+
447
+ 直接拖图片、句柄拖动和外部文件拖入的块级落点提示统一为蓝色横线及左端圆点。
448
+
449
+ 选中图片,点击气泡菜单的“设置图片描述”,即可在图片下方直接输入。描述随输入保存,支持换行;清空文字后再按一次 Backspace,会隐藏描述框,不会删除图片。旧文档或上传结果中已有的 `description` 会自动显示,预览/只读时显示为普通文字。
450
+
451
+ 点击“设置图片链接”,在气泡菜单下方弹层输入网址,可勾选“在当前页面打开”。点击“确定”或按 Enter 才保存;“取消”、Escape、点击外部或切换图片均放弃本次修改。清空网址后确定即移除链接,无效网址不会覆盖旧值。
452
+
453
+ 编辑状态下点击已设置链接的图片只选中图片,不会跳转;预览、只读或演示状态下才按配置打开链接。保存与导出仍保留链接数据。
454
+
455
+ 无需新增对接事件,数据通过现有文档 `v-model` / `change` 保存,也可通过 `insertImage()` 传入:
456
+
457
+ ```ts
458
+ editorRef.value?.insertImage({
459
+ src: 'https://example.com/photo.png',
460
+ description: '图片描述',
461
+ descriptionVisible: true,
462
+ link: 'https://example.com/details',
463
+ linkTarget: '_blank',
464
+ })
465
+ ```
466
+
467
+ `descriptionVisible` 可选,不传时根据描述是否为空决定显示;`true` 可显示空描述框,`false` 隐藏描述。`linkTarget` 可选 `_blank`(默认,新页面)或 `_self`(当前页面)。`getImages()` 返回这些字段;描述和已确认链接支持撤销、重做、复制粘贴和导出,未确认的链接草稿不会导出。
468
+
469
+ ### 事件
401
470
 
402
471
  | 事件 | Payload | 说明 |
403
472
  | --- | --- | --- |
@@ -409,12 +478,12 @@ editorRef.value?.insertImage({
409
478
  | `upload-error` | `RichTextEditorUploadErrorPayload` | 图片、视频或文件上传 hook 失败时触发。 |
410
479
  | `mention-search` | `RichTextEditorMentionProviderPayload` | 函数式监听写法,对应 `onMentionSearch` prop;输入 `@` 后加载候选数据,可返回数组或 `Promise`。 |
411
480
  | `mention-item-click` | `RichTextEditorMentionItem` | 点击弹窗候选项或已插入的提及节点时触发。 |
412
- | `mention-submit` | `RichTextEditorMentionItem` | 点击弹窗 `提及` 按钮并插入提及节点后触发。 |
413
- | `outline-change` | `RichTextEditorOutlineState` | 大纲条目或当前激活位置更新;可用 `@outline-change` 获取 `{ items, activePos }`。 |
481
+ | `mention-submit` | `RichTextEditorMentionItem` | 点击弹窗 `提及` 按钮并插入提及节点后触发。 |
482
+ | `outline-change` | `RichTextEditorOutlineState` | 大纲条目或当前激活位置更新;可用 `@outline-change` 获取 `{ items, activePos }`。 |
483
+
484
+ `mention-search` 没有出现在组件的 `defineEmits` 中;Vue 模板里的 `@mention-search="handler"` 会作为 `onMentionSearch` 函数式 prop 传入组件。
414
485
 
415
- `mention-search` 没有出现在组件的 `defineEmits` 中;Vue 模板里的 `@mention-search="handler"` 会作为 `onMentionSearch` 函数式 prop 传入组件。
416
-
417
- 评论的创建、回复、删除等事件单独列在[评论事件](#评论事件)中。正文提及加载函数可以返回候选数组;评论的 `@comment-mention-search` 是通知事件,返回值不会被用作候选数据,务必使用对应的 provider prop。
486
+ 评论的创建、回复、删除等事件单独列在[评论事件](#评论事件)中。正文提及加载函数可以返回候选数组;评论的 `@comment-mention-search` 是通知事件,返回值不会被用作候选数据,务必使用对应的 provider prop。
418
487
 
419
488
  ### @ 提及
420
489
 
@@ -431,11 +500,11 @@ import type { JSONContent } from '@tiptap/core'
431
500
  import { RichTextEditor } from '@norio-office/rich-text'
432
501
  import type {
433
502
  RichTextEditorMentionItem,
434
- RichTextEditorMentionProviderPayload,
435
- } from '@norio-office/rich-text'
436
- import '@norio-office/rich-text/style.css'
437
-
438
- const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
503
+ RichTextEditorMentionProviderPayload,
504
+ } from '@norio-office/rich-text'
505
+ import '@norio-office/rich-text/style.css'
506
+
507
+ const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
439
508
 
440
509
  const mentionItems: RichTextEditorMentionItem[] = [
441
510
  { id: 'user-1001', name: '崔国强', type: 1 },
@@ -449,7 +518,7 @@ async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload
449
518
  await new Promise((resolve) => window.setTimeout(resolve, 120))
450
519
 
451
520
  return mentionItems.filter((item) => {
452
- const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
521
+ const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
453
522
  const matchedKeyword = !query || item.name.toLowerCase().includes(query)
454
523
  return matchedType && matchedKeyword
455
524
  })
@@ -479,7 +548,7 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
479
548
 
480
549
  ### 自定义文案
481
550
 
482
- 编辑器默认 UI 文案为中文。`messages` 只会覆盖代码实际读取的文案 key,并非所有界面文字都已经支持替换。句柄菜单和文字选区菜单的部分文案仍是内置中文;传入不存在的 key 不会改变界面。
551
+ 编辑器默认 UI 文案为中文。`messages` 只会覆盖代码实际读取的文案 key,并非所有界面文字都已经支持替换。句柄菜单和文字选区菜单的部分文案仍是内置中文;传入不存在的 key 不会改变界面。
483
552
 
484
553
  ```vue
485
554
  <RichTextEditor
@@ -530,7 +599,7 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
530
599
  | `outline.label` | 大纲 |
531
600
  | `outline.collapse` | 收起大纲 |
532
601
  | `outline.empty.description` | 对文档内容应用“标题”样式,即可自动生成大纲。 |
533
- | `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 |
602
+ | `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 |
534
603
  | `status.wordCountUnit` | 个字 |
535
604
  | `status.presentation.enter` | 演示 |
536
605
  | `status.presentation.exit` | 退出演示 |
@@ -542,27 +611,26 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
542
611
 
543
612
  ### 预览模式
544
613
 
545
- `mode="preview"` 会切换到只读预览外壳。预览模式下顶部工具栏、气泡菜单和句柄菜单都不显示,正文不能编辑;图片设置的跳转链接生效,大纲仍可放在左侧或右侧。正文可编辑时,点击图片只用于选中和编辑,不会跳转。
546
-
547
- | 配置 | 正文能否编辑 | 顶部工具栏 | 适用场景 |
548
- | --- | --- | --- | --- |
549
- | 默认 `mode="edit"`、`editable=true` | 能 | 显示 | 写文档 |
550
- | `mode="edit"`、`:show-toolbar="false"` | 能,除非同时设置 `editable=false` | 隐藏 | 只使用选中文字的气泡菜单和块句柄菜单 |
551
- | `mode="edit"`、`:editable="false"` | 不能 | 保留,编辑操作受限制 | 编辑页面里的只读状态 |
552
- | `mode="preview"` | 不能,即使 `editable=true` | 隐藏 | 阅读/预览 |
553
-
554
- 这里限制的是用户交互,不是业务 API 的安全边界。业务方仍应避免在只读时主动调用修改内容的方法。
555
-
556
- `showToolbar` 默认是 `true`,只控制顶部工具栏,不影响正文编辑、气泡菜单、句柄菜单或底部信息栏。可以动态切换;预览和演示时无论这个属性是什么值,顶部工具栏都会隐藏。
557
-
558
- 例如,保留编辑能力,但隐藏顶部工具栏:
559
-
560
- ```vue
561
- <RichTextEditor v-model="content" :show-toolbar="false" />
562
- ```
563
-
564
- 切换成只读预览:
565
-
614
+ `mode="preview"` 会切换到只读预览外壳。预览模式下顶部工具栏、气泡菜单和句柄菜单都不显示,正文不能编辑;图片设置的跳转链接生效,大纲仍可放在左侧或右侧。正文可编辑时,点击图片只用于选中和编辑,不会跳转。
615
+
616
+ | 配置 | 正文能否编辑 | 顶部工具栏 | 适用场景 |
617
+ | --- | --- | --- | --- |
618
+ | 默认 `mode="edit"` | 能 | 显示 | 写文档 |
619
+ | `mode="edit"`、`:show-toolbar="false"` | 能 | 隐藏 | 只使用选中文字的气泡菜单和块句柄菜单 |
620
+ | `mode="preview"` | 不能 | 隐藏 | 阅读/预览 |
621
+
622
+ 这里限制的是用户交互,不是业务 API 的安全边界。业务方仍应避免在只读时主动调用修改内容的方法。
623
+
624
+ `showToolbar` 默认是 `true`,只控制顶部工具栏,不影响正文编辑、气泡菜单、句柄菜单或底部信息栏。可以动态切换;预览和演示时无论这个属性是什么值,顶部工具栏都会隐藏。
625
+
626
+ 例如,保留编辑能力,但隐藏顶部工具栏:
627
+
628
+ ```vue
629
+ <RichTextEditor v-model="content" :show-toolbar="false" />
630
+ ```
631
+
632
+ 切换成只读预览:
633
+
566
634
  ```vue
567
635
  <RichTextEditor
568
636
  v-model="content"
@@ -571,9 +639,9 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
571
639
  />
572
640
  ```
573
641
 
574
- 窄屏下预览模式会自动缩放页面画布,让文档在手机上保持可读。
575
-
576
- 底部信息栏提供演示、全屏、缩放、导出和打印入口,顶部工具栏不再显示导出、打印。点击“演示”后,组件临时进入只读预览并全屏显示;按 Esc 或通过浏览器退出全屏后,恢复进入前的编辑/预览状态,不修改业务传入的 `mode`、`editable` 或文档内容。例如,从编辑页开始演示,退出后可以继续编辑;从预览页开始演示,退出后仍是预览。
642
+ 窄屏下预览模式会自动缩放页面画布,让文档在手机上保持可读。
643
+
644
+ 底部信息栏提供演示、全屏和缩放;编辑器界面不提供导出或打印入口。点击“演示”后,组件临时进入只读预览并全屏显示;按 Esc 或通过浏览器退出全屏后,恢复进入前的编辑/预览状态,不修改业务传入的 `mode` 或文档内容。例如,从编辑页开始演示,退出后可以继续编辑;从预览页开始演示,退出后仍是预览。
577
645
 
578
646
  ### 协同编辑
579
647
 
@@ -587,7 +655,7 @@ npm install yjs y-websocket
587
655
 
588
656
  ```vue
589
657
  <script setup lang="ts">
590
- import { computed, onBeforeUnmount, ref } from 'vue'
658
+ import { computed, onBeforeUnmount, ref } from 'vue'
591
659
  import * as Y from 'yjs'
592
660
  import { WebsocketProvider } from 'y-websocket'
593
661
  import type { JSONContent } from '@tiptap/core'
@@ -601,7 +669,7 @@ const ydoc = new Y.Doc()
601
669
  const user = {
602
670
  userId: 'user_001',
603
671
  userName: 'Alice',
604
- clientUniqueCode: crypto.randomUUID(),
672
+ clientUniqueCode: crypto.randomUUID(),
605
673
  color: '#3b82f6',
606
674
  }
607
675
 
@@ -622,7 +690,7 @@ const provider = new WebsocketProvider(
622
690
  },
623
691
  )
624
692
 
625
- const collaboration = computed(() => ({
693
+ const collaboration = computed(() => ({
626
694
  document: ydoc,
627
695
  field: 'content',
628
696
  provider,
@@ -631,13 +699,13 @@ const collaboration = computed(() => ({
631
699
  color: user.color,
632
700
  userId: user.userId,
633
701
  clientUniqueCode: user.clientUniqueCode,
634
- },
635
- }))
636
-
637
- onBeforeUnmount(() => {
638
- provider.destroy()
639
- ydoc.destroy()
640
- })
702
+ },
703
+ }))
704
+
705
+ onBeforeUnmount(() => {
706
+ provider.destroy()
707
+ ydoc.destroy()
708
+ })
641
709
  </script>
642
710
 
643
711
  <template>
@@ -654,8 +722,8 @@ onBeforeUnmount(() => {
654
722
  - 同一个协同房间里的所有客户端必须使用同一个 `field`,普通一文档一编辑器场景固定用 `content`。
655
723
  - 同一个用户开两个浏览器窗口时,`clientUniqueCode` 必须不同;后端不会按 `userId` 去重在线客户端。
656
724
  - `provider + user` 都传入时,组件才会显示远程光标和远程选区。
657
- - 协同模式下 Y.Doc/Yjs fragment 是内容事实来源,外部 `modelValue` 不会再作为远程内容的权威写入源。
658
- - 协同扩展在组件创建时配置。切换文档/房间或从单人切换到协同时,应销毁旧 provider/Y.Doc,并用新的 `key` 重新挂载编辑器;只改 prop 不会重建协同扩展。
725
+ - 协同模式下 Y.Doc/Yjs fragment 是内容事实来源,外部 `modelValue` 不会再作为远程内容的权威写入源。
726
+ - 协同扩展在组件创建时配置。切换文档/房间或从单人切换到协同时,应销毁旧 provider/Y.Doc,并用新的 `key` 重新挂载编辑器;只改 prop 不会重建协同扩展。
659
727
 
660
728
  初始化规则:
661
729
 
@@ -665,10 +733,10 @@ onBeforeUnmount(() => {
665
733
 
666
734
  ```ts
667
735
  const collaboration = computed(() => ({
668
- document: ydoc,
669
- field: 'content',
670
- provider,
671
- user: { name: user.userName, color: user.color, userId: user.userId },
736
+ document: ydoc,
737
+ field: 'content',
738
+ provider,
739
+ user: { name: user.userName, color: user.color, userId: user.userId },
672
740
  initializeContent: ownsInitialContent,
673
741
  initialContent: ownsInitialContent ? businessContent : null,
674
742
  }))
@@ -688,20 +756,20 @@ http://127.0.0.1:5177/?collab=1&room=rich-demo-file-001&server=ws://127.0.0.1:12
688
756
 
689
757
  ```vue
690
758
  <script setup lang="ts">
691
- import { onBeforeUnmount, ref } from 'vue'
692
- import * as Y from 'yjs'
759
+ import { onBeforeUnmount, ref } from 'vue'
760
+ import * as Y from 'yjs'
693
761
  import { WebsocketProvider } from 'y-websocket'
694
762
  import type { JSONContent } from '@tiptap/core'
695
763
  import { RichTextEditor } from '@norio-office/rich-text'
696
764
  import '@norio-office/rich-text/style.css'
697
765
 
698
766
  const ydoc = new Y.Doc()
699
- const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
700
- const content = ref<JSONContent | null>(null)
701
- onBeforeUnmount(() => {
702
- provider.destroy()
703
- ydoc.destroy()
704
- })
767
+ const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
768
+ const content = ref<JSONContent | null>(null)
769
+ onBeforeUnmount(() => {
770
+ provider.destroy()
771
+ ydoc.destroy()
772
+ })
705
773
  </script>
706
774
 
707
775
  <template>
@@ -784,37 +852,37 @@ const editorRef = ref<RichTextEditorInstance | null>(null)
784
852
  | `getOutlineItems()` | `RichTextEditorOutlineItem[]` | 获取当前目录项。 |
785
853
  | `getActiveOutlinePos()` | `number \| null` | 获取当前激活目录项的文档位置。 |
786
854
  | `focusOutlineItem(pos)` | `boolean` | 聚焦并跳转到指定目录项。 |
787
- | `onOutlineChange(handler)` | `() => void` | 监听目录变化,返回取消监听函数。 |
788
- | `focusCommentThread(threadId)` | `boolean` | 跳转到指定评论锚点;找不到时返回 `false`。 |
789
-
790
- 媒体插入 API 的位置规则很重要:`insertImage()`、`insertVideo()`、`insertFile()`、`insertLocalFile()` 不会插到一句话的中间。光标所在文本块非空时,在该块前插入并保留原文;为空或只有空白时,替换这个占位块;块级选区则按选区起点插入。若要插到指定位置,先让用户在目标空段落中放置光标再调用。图片数组超过 4 项只取前 4 项。`insertMention()` 则是在当前选区插入行内提及。
791
-
792
- 这些媒体方法只接收已经上传好的地址,不会调用上传 hook。它们和导出实例方法不受顶部菜单白名单统一限制;媒体方法目前也不会自动检查预览/只读状态,调用方应自行判断。实例尚未就绪或参数缺少必要地址时无法插入,返回 `false`;不要将返回值当作服务器保存成功的确认。
793
-
794
- `getImages()`、`getVideos()`、`getFiles()` 返回有效媒体的摘要,不包含上传占位块,也不是完整存档。例如当前返回值没有完整保留 `assetId` 和图片块尺寸,`insertFile()` 当前也没有保存传入的 `assetId`。需要完整数据时请使用 `getJSON()` 或 `v-model`。
795
-
796
- ### 外置目录组件
797
-
798
- 内置大纲默认收起,内容区边线中部显示图标按钮。点击后按钮隐藏,大纲作为悬浮层展开,上下及配置的一侧贴住内容区边线,不占正文空间;关闭后恢复按钮。左侧按钮为左直角、右圆角,右侧镜像。底部状态栏不再显示大纲按钮。编辑与预览均支持,演示时隐藏。
799
-
800
- 内置目录默认跟随编辑器一起渲染。如果需要把目录放到任意侧栏、抽屉或自定义布局里,可以关闭内置目录,并把编辑器实例传给 `RichTextOutline`。
855
+ | `onOutlineChange(handler)` | `() => void` | 监听目录变化,返回取消监听函数。 |
856
+ | `focusCommentThread(threadId)` | `boolean` | 跳转到指定评论锚点;找不到时返回 `false`。 |
857
+
858
+ 媒体插入 API 的位置规则很重要:`insertImage()`、`insertVideo()`、`insertFile()`、`insertLocalFile()` 不会插到一句话的中间。光标所在文本块非空时,在该块前插入并保留原文;为空或只有空白时,替换这个占位块;块级选区则按选区起点插入。若要插到指定位置,先让用户在目标空段落中放置光标再调用。图片数组超过 4 项只取前 4 项。`insertMention()` 则是在当前选区插入行内提及。
859
+
860
+ 这些媒体方法只接收已经上传好的地址,不会调用上传 hook。它们和导出实例方法不受顶部菜单白名单统一限制;媒体方法目前也不会自动检查预览/只读状态,调用方应自行判断。实例尚未就绪或参数缺少必要地址时无法插入,返回 `false`;不要将返回值当作服务器保存成功的确认。
861
+
862
+ `getImages()`、`getVideos()`、`getFiles()` 返回有效媒体的摘要,不包含上传占位块,也不是完整存档。例如当前返回值没有完整保留 `assetId` 和图片块尺寸,`insertFile()` 当前也没有保存传入的 `assetId`。需要完整数据时请使用 `getJSON()` 或 `v-model`。
863
+
864
+ ### 外置目录组件
865
+
866
+ 内置大纲默认收起,内容区边线中部显示图标按钮。点击后按钮隐藏,大纲作为悬浮层展开,上下及配置的一侧贴住内容区边线,不占正文空间;关闭后恢复按钮。左侧按钮为左直角、右圆角,右侧镜像。底部状态栏不再显示大纲按钮。编辑与预览均支持,演示时隐藏。
867
+
868
+ 内置目录默认跟随编辑器一起渲染。如果需要把目录放到任意侧栏、抽屉或自定义布局里,可以关闭内置目录,并把编辑器实例传给 `RichTextOutline`。
801
869
 
802
870
  ```vue
803
871
  <script setup lang="ts">
804
872
  import { ref } from 'vue'
805
- import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
806
- import type { RichTextEditorInstance } from '@norio-office/rich-text'
807
- import type { JSONContent } from '@tiptap/core'
808
- import '@norio-office/rich-text/style.css'
809
-
810
- const editorRef = ref<RichTextEditorInstance | null>(null)
811
- const content = ref<JSONContent>({
812
- type: 'doc',
813
- content: [
814
- { type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: '项目说明' }] },
815
- { type: 'paragraph' },
816
- ],
817
- })
873
+ import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
874
+ import type { RichTextEditorInstance } from '@norio-office/rich-text'
875
+ import type { JSONContent } from '@tiptap/core'
876
+ import '@norio-office/rich-text/style.css'
877
+
878
+ const editorRef = ref<RichTextEditorInstance | null>(null)
879
+ const content = ref<JSONContent>({
880
+ type: 'doc',
881
+ content: [
882
+ { type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: '项目说明' }] },
883
+ { type: 'paragraph' },
884
+ ],
885
+ })
818
886
  </script>
819
887
 
820
888
  <template>
@@ -833,27 +901,27 @@ const content = ref<JSONContent>({
833
901
 
834
902
  1. 在业务层上传文件。
835
903
  2. 等待接口返回可访问 URL。
836
- 3. 调用组件实例方法插入返回内容。
837
-
838
- 这是业务自行上传的方式;如果使用下面的内置上传 hook,组件会自动插入,不要在 hook 中再次调用插入 API,否则会出现重复内容。
904
+ 3. 调用组件实例方法插入返回内容。
905
+
906
+ 这是业务自行上传的方式;如果使用下面的内置上传 hook,组件会自动插入,不要在 hook 中再次调用插入 API,否则会出现重复内容。
839
907
 
840
908
  如果使用编辑器内置的图片、视频、本地文件选择器或页面拖拽上传,请传入上传 hook。编辑器只负责把用户选中的 `File` 交给业务侧上传,并在 hook 返回 URL 后插入内容;组件不会内置业务上传接口,也不会自动回退为 base64/blob URL。
841
909
 
842
910
  页面拖拽上传会按文件类型分流:`image/*` 走图片上传,`video/*` 走视频上传,其他格式全部走 `uploadFile` 并插入本地文件卡片。
843
911
 
844
912
  ```vue
845
- <script setup lang="ts">
846
- import { ref } from 'vue'
847
- import type { JSONContent } from '@tiptap/core'
848
- import { RichTextEditor } from '@norio-office/rich-text'
849
- import type {
850
- RichTextEditorUploadInput,
851
- RichTextEditorUploadResult,
852
- RichTextEditorUploadErrorPayload,
853
- } from '@norio-office/rich-text'
854
- import '@norio-office/rich-text/style.css'
855
-
856
- const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
913
+ <script setup lang="ts">
914
+ import { ref } from 'vue'
915
+ import type { JSONContent } from '@tiptap/core'
916
+ import { RichTextEditor } from '@norio-office/rich-text'
917
+ import type {
918
+ RichTextEditorUploadInput,
919
+ RichTextEditorUploadResult,
920
+ RichTextEditorUploadErrorPayload,
921
+ } from '@norio-office/rich-text'
922
+ import '@norio-office/rich-text/style.css'
923
+
924
+ const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
857
925
 
858
926
  async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
859
927
  const form = new FormData()
@@ -869,9 +937,9 @@ async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichT
869
937
  throw new Error('上传失败')
870
938
  }
871
939
 
872
- const result = await response.json() as RichTextEditorUploadResult
873
- if (!result.url) throw new Error('上传接口没有返回 url')
874
- return result
940
+ const result = await response.json() as RichTextEditorUploadResult
941
+ if (!result.url) throw new Error('上传接口没有返回 url')
942
+ return result
875
943
  }
876
944
 
877
945
  function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
@@ -891,25 +959,25 @@ function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
891
959
  </template>
892
960
  ```
893
961
 
894
- `onUploadError` callback prop 和 `@upload-error` 事件都能接收上传失败信息。通常选择一种接入方式即可,避免业务层重复处理。
895
-
896
- 上面的 `/api/upload` 是业务自己实现的接口。hook 接收 `{ file: File, kind: 'image' | 'video' | 'file' }`;返回值不是 URL 字符串,而是以下对象:
897
-
898
- ```json
899
- {
900
- "url": "https://cdn.example.com/uploads/photo.png",
901
- "assetId": "asset-1001",
902
- "name": "photo.png",
903
- "size": 2048,
904
- "mimeType": "image/png",
905
- "alt": "项目照片",
906
- "description": "本次项目的示意图"
907
- }
908
- ```
909
-
910
- 只有 `url` 必填,其余字段可选;缺少 `name`、`size`、`mimeType` 时,内置上传流程会使用原文件的信息。缺少 hook 会报上传错误,不会自动生成 base64;失败任务可在上传面板重试。评论图片可单独传 `uploadCommentImage`,未传时使用 `uploadImage`。
911
-
912
- 地址必须能被阅读文档的人访问。不要把本地磁盘路径或临时 `blob:` 地址当成长期文件地址;返回地址和文件权限由业务负责。
962
+ `onUploadError` callback prop 和 `@upload-error` 事件都能接收上传失败信息。通常选择一种接入方式即可,避免业务层重复处理。
963
+
964
+ 上面的 `/api/upload` 是业务自己实现的接口。hook 接收 `{ file: File, kind: 'image' | 'video' | 'file' }`;返回值不是 URL 字符串,而是以下对象:
965
+
966
+ ```json
967
+ {
968
+ "url": "https://cdn.example.com/uploads/photo.png",
969
+ "assetId": "asset-1001",
970
+ "name": "photo.png",
971
+ "size": 2048,
972
+ "mimeType": "image/png",
973
+ "alt": "项目照片",
974
+ "description": "本次项目的示意图"
975
+ }
976
+ ```
977
+
978
+ 只有 `url` 必填,其余字段可选;缺少 `name`、`size`、`mimeType` 时,内置上传流程会使用原文件的信息。缺少 hook 会报上传错误,不会自动生成 base64;失败任务可在上传面板重试。评论图片可单独传 `uploadCommentImage`,未传时使用 `uploadImage`。
979
+
980
+ 地址必须能被阅读文档的人访问。不要把本地磁盘路径或临时 `blob:` 地址当成长期文件地址;返回地址和文件权限由业务负责。
913
981
 
914
982
  插入图片:
915
983
 
@@ -975,36 +1043,35 @@ editorRef.value?.insertLocalFile({
975
1043
  })
976
1044
  ```
977
1045
 
978
- ### 导出示例
979
-
980
- 下面的函数与“实例 API”示例中的 `editorRef` 一起使用。内置导出菜单会自动下载;实例方法仅返回 Blob/HTML,下载由你控制。
981
-
982
- | 导出方式 | 当前实现与适用范围 |
983
- | --- | --- |
984
- | `exportImage()` | 页面截图;默认 PNG,可选 JPEG。`quality` 可选 0-1,主要影响 JPEG,不传时使用浏览器默认质量。 |
985
- | `exportPdf()` | 简化的 DOM 文字和矩形色块绘制,生成一张随文档高度延伸的 PDF 页面;不是页面截图,也不是 Word 文件。当前不嵌入图片、视频、SVG 图标,不保证字体、公式、圆角、虚线、水印等细节还原。 |
986
- | `exportHtml()` | 含内联样式的完整 HTML 文档;媒体地址仍指向原文件服务,不是离线资源包。 |
987
- | 底部“打印” | 使用浏览器打印流程;需要接近页面原貌的 PDF,可在打印对话框里选择保存为 PDF,并自行检查分页和结果。 |
988
-
989
- 当前几种导出都先复制页面并清理编辑控件,视频块和页面水印也会被清除。因此不能假设导出文件包含页面上的所有元素;上面的“打印”同样受这项清理影响。
990
-
991
- ```ts
992
- function downloadBlob(blob: Blob, name: string) {
993
- const url = URL.createObjectURL(blob)
994
- const link = document.createElement('a')
995
- link.href = url
996
- link.download = name
997
- document.body.append(link)
998
- link.click()
999
- link.remove()
1000
- window.setTimeout(() => URL.revokeObjectURL(url), 1000)
1001
- }
1002
-
1003
- async function handleExportPdf() {
1046
+ ### 导出示例
1047
+
1048
+ 下面的函数与“实例 API”示例中的 `editorRef` 一起使用。编辑器不显示导出按钮;实例方法仅返回 Blob/HTML,下载由宿主控制。
1049
+
1050
+ | 导出方式 | 当前实现与适用范围 |
1051
+ | --- | --- |
1052
+ | `exportImage()` | 页面截图;默认 PNG,可选 JPEG。`quality` 可选 0-1,主要影响 JPEG,不传时使用浏览器默认质量。 |
1053
+ | `exportPdf()` | 简化的 DOM 文字和矩形色块绘制,生成一张随文档高度延伸的 PDF 页面;不是页面截图,也不是 Word 文件。当前不嵌入图片、视频、SVG 图标,不保证字体、公式、圆角、虚线、水印等细节还原。 |
1054
+ | `exportHtml()` | 含内联样式的完整 HTML 文档;媒体地址仍指向原文件服务,不是离线资源包。 |
1055
+
1056
+ 当前几种导出都先复制页面并清理编辑控件,视频块和页面水印也会被清除。因此不能假设导出文件包含页面上的所有元素。
1057
+
1058
+ ```ts
1059
+ function downloadBlob(blob: Blob, name: string) {
1060
+ const url = URL.createObjectURL(blob)
1061
+ const link = document.createElement('a')
1062
+ link.href = url
1063
+ link.download = name
1064
+ document.body.append(link)
1065
+ link.click()
1066
+ link.remove()
1067
+ window.setTimeout(() => URL.revokeObjectURL(url), 1000)
1068
+ }
1069
+
1070
+ async function handleExportPdf() {
1004
1071
  const blob = await editorRef.value?.exportPdf()
1005
1072
  if (!blob) return
1006
1073
 
1007
- downloadBlob(blob, 'demo.pdf')
1074
+ downloadBlob(blob, 'demo.pdf')
1008
1075
  }
1009
1076
 
1010
1077
  async function handleExportImage() {
@@ -1013,7 +1080,7 @@ async function handleExportImage() {
1013
1080
  })
1014
1081
  if (!blob) return
1015
1082
 
1016
- downloadBlob(blob, 'demo.png')
1083
+ downloadBlob(blob, 'demo.png')
1017
1084
  }
1018
1085
 
1019
1086
  function handleExportHtml() {
@@ -1035,11 +1102,11 @@ import type {
1035
1102
  RichTextEditorCollaborationDocument,
1036
1103
  RichTextEditorCollaborationProvider,
1037
1104
  RichTextEditorCollaborationUser,
1038
- RichTextEditorCollaborationOptions,
1039
- RichTextEditorCollectedFilePayload,
1040
- RichTextEditorExportItemKey,
1041
- RichTextEditorCode,
1042
- RichTextEditorFilePayload,
1105
+ RichTextEditorCollaborationOptions,
1106
+ RichTextEditorCollectedFilePayload,
1107
+ RichTextEditorExportItemKey,
1108
+ RichTextEditorCode,
1109
+ RichTextEditorFilePayload,
1043
1110
  RichTextEditorImageExportOptions,
1044
1111
  RichTextEditorImagePayload,
1045
1112
  RichTextEditorInsertMenuItemKey,
@@ -1082,26 +1149,26 @@ import RichTextEditor, {
1082
1149
 
1083
1150
  ### 包内文档
1084
1151
 
1085
- - 使用指南:`docs/usage.md`
1086
- - Yjs 服务示例:`yjs/README.md`
1087
-
1088
- ### 常见问题
1089
-
1090
- | 问题 | 先检查什么 |
1091
- | --- | --- |
1092
- | 接入后没有样式 | 是否引入 `@norio-office/rich-text/style.css`,是否由宿主 CSS 覆盖。 |
1093
- | 传 `null` 却没有清空 | 传一个包含空段落的 `doc` 对象,见保存示例。 |
1094
- | 图片/视频选择后无法上传 | 对应 hook 是否传入,是否返回 `{ url: '...' }`,接口地址是否真实可用。 |
1095
- | 调插入方法后图片跑到段落上方 | 媒体 API 默认在非空文本块前插入;指定位置请先把光标放到目标空段落。 |
1096
- | 设置了白名单,某些句柄项还在 | 白名单不是完整权限系统;当前句柄插入/转换未统一过滤。 |
1097
- | 评论按钮没显示或不能发布 | `showComments`、`comments` code、当前评论用户是否配置;预览不能新建评论。 |
1098
- | 输入 `@` 没有候选 | 正文需要 `mention=true` 及数据源;评论使用独立的数据源;白名单需含 `mention`。 |
1099
- | 两个窗口内容没有同步 | WebSocket 地址、房间名、`field` 是否一致;白名单是否允许 `collaboration`。 |
1100
- | 菜单粘贴读不到系统内容 | 需要 HTTPS/localhost 和浏览器权限,可改用 Ctrl/Cmd+V。 |
1101
- | 导出图片缺少远程图片 | 检查图片服务的 CORS、访问权限及加载情况;截图导出依赖浏览器能读取图片。 |
1102
- | PDF 里图片或样式不完整 | 当前 PDF 是简化的文字/色块绘制,不嵌入图片;可尝试浏览器打印保存 PDF 并检查结果。 |
1103
-
1104
- 长期保存、重新编辑请使用 JSON,评论列表另存;不要将导出 HTML 或简化 PDF 当成无损导入格式。导出前请在目标浏览器验证媒体加载、字体和排版,尤其是包含复杂块的长文档。
1152
+ - 使用指南:`docs/usage.md`
1153
+ - Yjs 服务示例:`yjs/README.md`
1154
+
1155
+ ### 常见问题
1156
+
1157
+ | 问题 | 先检查什么 |
1158
+ | --- | --- |
1159
+ | 接入后没有样式 | 是否引入 `@norio-office/rich-text/style.css`,是否由宿主 CSS 覆盖。 |
1160
+ | 传 `null` 却没有清空 | 传一个包含空段落的 `doc` 对象,见保存示例。 |
1161
+ | 图片/视频选择后无法上传 | 对应 hook 是否传入,是否返回 `{ url: '...' }`,接口地址是否真实可用。 |
1162
+ | 调插入方法后图片跑到段落上方 | 媒体 API 默认在非空文本块前插入;指定位置请先把光标放到目标空段落。 |
1163
+ | 设置了白名单,某些句柄项还在 | 白名单不是完整权限系统;当前句柄插入/转换未统一过滤。 |
1164
+ | 评论按钮没显示或不能发布 | `showComments`、`comments` code、当前评论用户是否配置;预览不能新建评论。 |
1165
+ | 输入 `@` 没有候选 | 正文需要 `mention=true` 及数据源;评论使用独立的数据源;白名单需含 `mention`。 |
1166
+ | 两个窗口内容没有同步 | WebSocket 地址、房间名、`field` 是否一致;白名单是否允许 `collaboration`。 |
1167
+ | 菜单粘贴读不到系统内容 | 需要 HTTPS/localhost 和浏览器权限,可改用 Ctrl/Cmd+V。 |
1168
+ | 导出图片缺少远程图片 | 检查图片服务的 CORS、访问权限及加载情况;截图导出依赖浏览器能读取图片。 |
1169
+ | PDF 里图片或样式不完整 | 当前 PDF 是简化的文字/色块绘制,不嵌入图片;可尝试浏览器打印保存 PDF 并检查结果。 |
1170
+
1171
+ 长期保存、重新编辑请使用 JSON,评论列表另存;不要将导出 HTML 或简化 PDF 当成无损导入格式。导出前请在目标浏览器验证媒体加载、字体和排版,尤其是包含复杂块的长文档。
1105
1172
 
1106
1173
  ## English
1107
1174
 
@@ -1119,15 +1186,15 @@ The component styles are published as a separate CSS file. Import it in your app
1119
1186
  import '@norio-office/rich-text/style.css'
1120
1187
  ```
1121
1188
 
1122
- Use Vue 3.5+ and the compatible Tiptap 3.x ranges declared in `package.json`; do not mix Tiptap major versions. If your package manager does not install peers automatically, use the versioned installation command in the Chinese installation section.
1189
+ Use Vue 3.5+ and the compatible Tiptap 3.x ranges declared in `package.json`. Keep `@tiptap/core`, `@tiptap/pm`, `@tiptap/vue-3`, starter-kit and extensions on matching compatible 3.x versions; mixing minor releases (for example core 3.32 with vue-3 3.22) can fail at runtime. If your package manager does not install peers automatically, use the versioned installation command in the Chinese installation section.
1123
1190
 
1124
1191
  ```bash
1125
- npm install vue@^3.5.0 @tiptap/core@^3.22.1 @tiptap/vue-3@^3.22.1 @tiptap/pm@^3.22.1 @tiptap/starter-kit@^3.22.1 @tiptap/extension-placeholder@^3.22.1 @tiptap/extension-code-block@^3.22.1 @tiptap/extension-code-block-lowlight@^3.22.1 @tiptap/extension-collaboration@^3.22.2 @tiptap/extension-collaboration-caret@^3.22.2 @tiptap/extension-font-family@^3.22.1 @tiptap/extension-horizontal-rule@^3.22.1 @tiptap/extension-subscript@^3.22.1 @tiptap/extension-superscript@^3.22.1 @tiptap/extension-table@^3.22.1 @tiptap/extension-table-cell@^3.22.1 @tiptap/extension-table-header@^3.22.1 @tiptap/extension-table-row@^3.22.1 @tiptap/extension-task-item@^3.22.1 @tiptap/extension-task-list@^3.22.1 @tiptap/extension-text-style@^3.22.1 @tiptap/extension-underline@^3.22.1 @tiptap/y-tiptap@^3.0.2 lowlight@^3.3.0 y-prosemirror@^1.2.6 yjs@^13.6.30
1192
+ npm install vue@^3.5.0 @tiptap/core@^3.22.1 @tiptap/vue-3@^3.22.1 @tiptap/pm@^3.22.1 @tiptap/starter-kit@^3.22.1 @tiptap/extension-placeholder@^3.22.1 @tiptap/extension-code-block@^3.22.1 @tiptap/extension-code-block-lowlight@^3.22.1 @tiptap/extension-collaboration@^3.22.2 @tiptap/extension-collaboration-caret@^3.22.2 @tiptap/extension-font-family@^3.22.1 @tiptap/extension-horizontal-rule@^3.22.1 @tiptap/extension-subscript@^3.22.1 @tiptap/extension-superscript@^3.22.1 @tiptap/extension-table@^3.22.1 @tiptap/extension-table-cell@^3.22.1 @tiptap/extension-table-header@^3.22.1 @tiptap/extension-table-row@^3.22.1 @tiptap/extension-task-item@^3.22.1 @tiptap/extension-task-list@^3.22.1 @tiptap/extension-text-style@^3.22.1 @tiptap/extension-underline@^3.22.1 @tiptap/y-tiptap@^3.0.2 lowlight@^3.3.0 y-prosemirror@^1.2.6 yjs@^13.6.30
1126
1193
  ```
1127
1194
 
1128
1195
  `html2canvas`, `jspdf`, `katex`, `marked`, and `plyr` are regular dependencies and are installed with the package.
1129
1196
 
1130
- ### Quick Start
1197
+ ### Quick Start
1131
1198
 
1132
1199
  ```vue
1133
1200
  <script setup lang="ts">
@@ -1136,7 +1203,7 @@ import type { JSONContent } from '@tiptap/core'
1136
1203
  import { RichTextEditor } from '@norio-office/rich-text'
1137
1204
  import '@norio-office/rich-text/style.css'
1138
1205
 
1139
- const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1206
+ const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1140
1207
  </script>
1141
1208
 
1142
1209
  <template>
@@ -1150,48 +1217,56 @@ Default import is also supported:
1150
1217
  import RichTextEditor from '@norio-office/rich-text'
1151
1218
  ```
1152
1219
 
1220
+ ### AI Skill
1221
+
1222
+ The Skill source is `packages/skills/norio-rich-text/` in this repository; its separate publishing destination is the [Skill repository](https://github.com/cgq001/norio-office-rich-text-skill). Copy the entire `norio-rich-text/` directory to a Skill location supported by your AI platform. It is not included in the editor's npm package, and copying it does not automatically register tools or connect a live editor.
1223
+
1224
+ For live editing, install the editor package, opt in with `:show-ai-target-button="true"`, bind `createRichTextAiBridge` to the mounted editor, subscribe to `ai-target-change`, and register the definitions from `getRichTextToolDefinitions()` with matching `createRichTextToolHandlers` in your host AI runtime. The host supplies model transport, permissions, resource authorization, persistence and request cancellation. Use `bridge.getAiTarget()` and its `targetId` when creating an edit context; never invent target references. The same Bridge supports local and Yjs collaborative editing when the host collaboration session is ready. See the [Chinese integration steps](#ai-skill-接入与使用), [AI integration guide](docs/ai/README.md), [Skill instructions](https://github.com/cgq001/norio-office-rich-text-skill/blob/main/norio-rich-text/SKILL.md), and [runnable browser example](examples/ai/browser/App.vue).
1225
+
1226
+ For offline validation or `.nordox` creation, use Node.js 20+ and a compatible installed `@norio-office/rich-text` package, then run `node scripts/rich-text.mjs capabilities` or the other commands documented in the Skill directory. The CLI cannot edit an open browser editor.
1227
+
1153
1228
  ### Props
1154
1229
 
1155
1230
  | Prop | Type | Default | Description |
1156
1231
  | --- | --- | --- | --- |
1157
- | `modelValue` | `JSONContent \| null` | `null` | Tiptap JSON content, not an HTML string. `null` does not clear it. |
1158
- | `documentName` | `string` | `''` | Base filename for built-in downloads. The component appends `.pdf`, `.png`, or `.html`. |
1159
- | `editable` | `boolean` | `true` | Enables or disables editing. |
1160
- | `mode` | `'edit' \| 'preview'` | `'edit'` | Edit mode or read-only preview mode. |
1161
- | `showToolbar` | `boolean` | `true` | Shows the top toolbar in edit mode. Always hidden in preview mode. |
1232
+ | `modelValue` | `JSONContent \| null` | `null` | Tiptap JSON content, not an HTML string. `null` does not clear it. |
1233
+ | `documentName` | `string` | `''` | Document name used as the `.nordox` export title. The host chooses PDF, image, and HTML download filenames. |
1234
+ | `mode` | `'edit' \| 'preview'` | `'edit'` | Edit mode or read-only preview mode. |
1235
+ | `showToolbar` | `boolean` | `true` | Shows the top toolbar in edit mode. Always hidden in preview mode. |
1236
+ | `showAiTargetButton` | `boolean` | `false` | Shows the AI target button at the end of the toolbar. The host must bind a Bridge and subscribe to target events. Hidden in preview mode. |
1162
1237
  | `watermark` | `RichTextEditorWatermarkOptions \| null` | `null` | Text watermark configuration for the document page. No watermark is rendered when omitted or when `text` is empty. |
1163
- | `showOutline` | `boolean` | `true` | Enables the built-in outline and edge toggle; the panel starts collapsed. Set it to `false` when placing an external `RichTextOutline` component yourself. |
1164
- | `outlinePlacement` | `'left' \| 'right'` | `'right'` | Outline panel placement. |
1165
- | `messages` | `RichTextEditorMessages \| null` | `null` | Overrides built-in UI labels. |
1166
- | `featureCodes` | `RichTextEditorCode[] \| null` | `null` | Unified whitelist for controlled entries, with the limitations described below. |
1167
- | `enabledFeatureItems` | `RichTextEditorFeatureItemKey[] \| null` | `null` | Legacy advanced-feature whitelist, including the legacy `outline` code. |
1168
- | `enabledExportItems` | `RichTextEditorExportItemKey[] \| null` | `undefined` | Legacy export menu whitelist; used only when `featureCodes` is unset. |
1169
- | `enabledInsertMenuItems` | `RichTextEditorInsertMenuItemKey[] \| null` | `undefined` | Legacy insert menu whitelist; used only when `featureCodes` is unset. |
1170
- | `enabledToolbarActions` | `RichTextEditorToolbarActionKey[] \| null` | `undefined` | Legacy toolbar action whitelist; used only when `featureCodes` is unset. |
1238
+ | `showOutline` | `boolean` | `true` | Enables the built-in outline and edge toggle; the panel starts collapsed. Set it to `false` when placing an external `RichTextOutline` component yourself. |
1239
+ | `outlinePlacement` | `'left' \| 'right'` | `'right'` | Outline panel placement. |
1240
+ | `messages` | `RichTextEditorMessages \| null` | `null` | Overrides built-in UI labels. |
1241
+ | `featureCodes` | `RichTextEditorCode[] \| null` | `null` | Unified whitelist for controlled entries, with the limitations described below. |
1242
+ | `enabledFeatureItems` | `RichTextEditorFeatureItemKey[] \| null` | `null` | Legacy advanced-feature whitelist, including the legacy `outline` code. |
1243
+ | `enabledExportItems` | `RichTextEditorExportItemKey[] \| null` | `undefined` | Retained for compatibility; built-in export/print controls have been removed and instance export methods remain available. |
1244
+ | `enabledInsertMenuItems` | `RichTextEditorInsertMenuItemKey[] \| null` | `undefined` | Legacy insert menu whitelist; used only when `featureCodes` is unset. |
1245
+ | `enabledToolbarActions` | `RichTextEditorToolbarActionKey[] \| null` | `undefined` | Legacy toolbar action whitelist; used only when `featureCodes` is unset. |
1171
1246
  | `placeholder` | `string` | `''` | Placeholder text for empty content. |
1172
1247
  | `mention` | `boolean` | `false` | Enables `@` mention. Only when `true`, typing `@` opens the candidate popup and `insertMention()` can insert a mention node. |
1173
- | `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs collaboration options, used at component creation. |
1248
+ | `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs collaboration options, used at component creation. |
1174
1249
  | `uploadImage` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by built-in image pickers and image drops. The editor inserts the returned URL. |
1175
1250
  | `uploadVideo` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by built-in video pickers and video drops. The editor inserts the returned URL. |
1176
1251
  | `uploadFile` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by the local file card picker. The editor inserts the returned URL. |
1177
1252
  | `onUploadError` | `RichTextEditorUploadErrorHandler \| null` | `null` | Optional callback for upload errors. |
1178
- | `mentionProvider` | `RichTextEditorMentionProvider \| null` | `undefined` | Compatibility function prop for loading `@` mention candidates. |
1179
- | `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `undefined` | Async loader used by function-style `@mention-search`; takes precedence over `mentionProvider`. |
1180
- | `comments` | `RichTextEditorCommentThread[] \| null` | `null` | Business-managed comment threads, stored separately from document JSON. |
1181
- | `commentUser` | `RichTextEditorCommentUser \| null` | `null` | Current author; falls back to the collaboration user when available. |
1182
- | `showComments` | `boolean` | `false` | Shows comment UI; also requires the `comments` code when using a whitelist. |
1183
- | `commentMention` | `boolean` | `true` | Comment mention switch, independent of the main editor's `mention` prop. |
1184
- | `uploadCommentImage` | `RichTextEditorUploadHook \| null` | `null` | Comment image upload hook; falls back to `uploadImage`. |
1185
- | `commentMentionProvider` | `RichTextEditorCommentMentionProvider \| null` | `null` | Separate loader for comment mentions. |
1186
- | `onCommentMentionSearch` | `RichTextEditorCommentMentionProvider \| null` | `null` | Alternative comment mention loader, taking precedence over `commentMentionProvider`. |
1187
-
1188
- When `featureCodes` is omitted or null, each area falls back to its legacy whitelist; without either list, controlled entries are unrestricted. Comments, mentions and collaboration still need their own configuration. A supplied array takes precedence over legacy lists; `[]` disables only whitelist-controlled entries. These codes are UI switches, not security permissions: basic formatting, current handle insert/transform menus, file drops and most instance methods are not uniformly filtered. Existing nodes are not removed. Enforce business permissions on the host and server.
1189
-
1190
- Persist the full JSON to reopen an editable document; `getText()` and exported HTML are not lossless substitutes. Comments are stored separately. On initial non-collaborative mount, missing/null content currently displays built-in sample text; subsequent null assignments are ignored. Clear with `{ type: 'doc', content: [{ type: 'paragraph' }] }`. Collaboration uses Yjs instead of model-value assignments. See the Chinese save/load example for a complete localStorage demo.
1253
+ | `mentionProvider` | `RichTextEditorMentionProvider \| null` | `undefined` | Compatibility function prop for loading `@` mention candidates. |
1254
+ | `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `undefined` | Async loader used by function-style `@mention-search`; takes precedence over `mentionProvider`. |
1255
+ | `comments` | `RichTextEditorCommentThread[] \| null` | `null` | Business-managed comment threads, stored separately from document JSON. |
1256
+ | `commentUser` | `RichTextEditorCommentUser \| null` | `null` | Current author; falls back to the collaboration user when available. |
1257
+ | `showComments` | `boolean` | `false` | Shows comment UI; also requires the `comments` code when using a whitelist. |
1258
+ | `commentMention` | `boolean` | `true` | Comment mention switch, independent of the main editor's `mention` prop. |
1259
+ | `uploadCommentImage` | `RichTextEditorUploadHook \| null` | `null` | Comment image upload hook; falls back to `uploadImage`. |
1260
+ | `commentMentionProvider` | `RichTextEditorCommentMentionProvider \| null` | `null` | Separate loader for comment mentions. |
1261
+ | `onCommentMentionSearch` | `RichTextEditorCommentMentionProvider \| null` | `null` | Alternative comment mention loader, taking precedence over `commentMentionProvider`. |
1262
+
1263
+ When `featureCodes` is omitted or null, controlled areas fall back to their legacy whitelists; without either list, controlled entries are unrestricted. Comments, mentions and collaboration still need their own configuration. A supplied array takes precedence for entries that still exist; `[]` disables only whitelist-controlled entries. Export and print have no built-in controls: `pdf`, `html`, and `print` remain as compatibility codes, while instance export methods are not filtered by them. These codes are UI switches, not security permissions: basic formatting, current handle insert/transform menus, file drops and most instance methods are not uniformly filtered. Existing nodes are not removed. Enforce business permissions on the host and server.
1264
+
1265
+ Persist the full JSON to reopen an editable document; `getText()` and exported HTML are not lossless substitutes. Comments are stored separately. On initial non-collaborative mount, missing/null content currently displays built-in sample text; subsequent null assignments are ignored. Clear with `{ type: 'doc', content: [{ type: 'paragraph' }] }`. Collaboration uses Yjs instead of model-value assignments. See the Chinese save/load example for a complete localStorage demo.
1191
1266
 
1192
1267
  ### Watermark
1193
1268
 
1194
- `watermark` is a visual page layer, not document JSON, and does not affect `getText()`. The current export cleanup removes that layer from PDF, image, HTML and built-in print output. Add export watermarks in your host export workflow when required; the on-screen layer is not file-level data-loss protection.
1269
+ `watermark` is a visual page layer, not document JSON, and does not affect `getText()`. The current export cleanup removes that layer from PDF, image, and HTML output. Add export watermarks in your host export workflow when required; the on-screen layer is not file-level data-loss protection.
1195
1270
 
1196
1271
  ```vue
1197
1272
  <RichTextEditor
@@ -1223,161 +1298,165 @@ Persist the full JSON to reopen an editable document; `getText()` and exported H
1223
1298
  />
1224
1299
  ```
1225
1300
 
1226
- ### Available Keys
1227
-
1228
- All authorization codes are passed through one `feature-codes` list. Import the `RICH_TEXT_EDITOR_*_CODES` constants to avoid hand-written strings:
1229
-
1230
- ```ts
1231
- import {
1232
- RICH_TEXT_EDITOR_EXPORT_CODES,
1233
- RICH_TEXT_EDITOR_FEATURE_CODES,
1234
- RICH_TEXT_EDITOR_INSERT_MENU_CODES,
1235
- RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES,
1236
- } from '@norio-office/rich-text'
1237
-
1238
- import type { RichTextEditorCode } from '@norio-office/rich-text'
1239
-
1240
- const featureCodes: RichTextEditorCode[] = [
1241
- RICH_TEXT_EDITOR_EXPORT_CODES.pdf,
1242
- RICH_TEXT_EDITOR_INSERT_MENU_CODES.image,
1243
- RICH_TEXT_EDITOR_FEATURE_CODES.outlineRight,
1244
- RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES.blockquote,
1245
- ]
1246
- ```
1247
-
1248
- `featureCodes` is one unified authorization pool. Export, insert menu, toolbar, and advanced features are all checked against the same array:
1249
-
1250
- ```vue
1251
- <RichTextEditor
1252
- v-model="content"
1253
- :feature-codes="['pdf', 'image']"
1254
- />
1255
- ```
1256
-
1257
- This enables PDF export, image export, and the insert-image entry. Because `image` is a unified code, it matches both image export and image insertion.
1258
-
1259
- Complete authorization code list:
1260
-
1261
- | Code | Group | Controls | Related props |
1262
- | --- | --- | --- | --- |
1263
- | `comments` | Advanced feature | Comment button, right-side comment panel, document comment anchor clicks, and comment interactions. | `showComments`, `comments`, `commentUser` |
1264
- | `outlineLeft` | Advanced feature | Built-in outline and edge icon toggle on the left. | `showOutline` |
1265
- | `outlineRight` | Advanced feature | Built-in outline and edge icon toggle on the right. | `showOutline` |
1266
- | `watermark` | Advanced feature | Page watermark display; current exports remove this layer. | `watermark` |
1267
- | `collaboration` | Advanced feature | Yjs collaboration and remote cursors; without authorization, the editor initializes in single-user mode. | `collaboration` |
1268
- | `mention` | Advanced feature | Main editor `@` mention, comment input `@` mention popup, and mention instance methods. | `mention`, `commentMention`, `mentionProvider`, `commentMentionProvider` |
1269
- | `pdf` | Export | PDF export entry in the export menu. | `documentName` |
1270
- | `html` | Export | HTML export entry in the export menu. | `documentName` |
1271
- | `image` | Export + insert | Image export entry in the export menu and image entry in the insert menu. | `uploadImage`, `documentName` |
1272
- | `print` | Export | Print entry in the bottom status bar. | - |
1273
- | `video` | Insert menu | Video entry in the insert menu. | `uploadVideo` |
1274
- | `table` | Insert menu | Table entry in the insert menu. | - |
1275
- | `local-file` | Insert menu | Local file entry in the insert menu. | `uploadFile` |
1276
- | `columns` | Insert menu | Columns entry in the insert menu. | - |
1277
- | `highlight-block` | Insert menu | Highlight block entry in the insert menu. | - |
1278
- | `date` | Insert menu | Date entry in the insert menu; currently reserved as an authorization code. | - |
1279
- | `code-block` | Insert menu | Code block entry in the insert menu. | - |
1280
- | `formula` | Insert menu | Formula entry in the insert menu. | - |
1281
- | `blockquote` | Insert menu + toolbar | Blockquote entry in the insert menu and blockquote button in the toolbar. | - |
1282
- | `emoji` | Insert menu + toolbar | Emoji entry in the insert menu and emoji button in the toolbar. | - |
1283
- | `link` | Insert menu | Link entry in the insert menu. | - |
1284
- | `divider` | Insert menu | Divider entry in the insert menu. | - |
1285
- | `countdown` | Insert menu | Countdown entry in the insert menu. | - |
1286
- | `markdown-import` | Insert menu | Markdown import entry in the insert menu. | - |
1287
-
1288
- Write a shared code only once. For example, `image` authorizes both image export and image insertion; `blockquote` authorizes both insert-menu blockquote and the toolbar blockquote button.
1289
-
1290
- Outline authorization rule: with only `outlineLeft`, the outline and its edge toggle appear on the left; with only `outlineRight`, they appear on the right; with both, `outlinePlacement` decides placement; with neither, the built-in outline and edge toggle are hidden.
1291
-
1292
- ### Copy, Cut, And Paste
1293
-
1294
- Block-menu actions interoperate with `Ctrl/Cmd+C`, `Ctrl/Cmd+X`, and `Ctrl/Cmd+V`, preserving node types, attributes, and formatting. Menu paste inserts below the current block and prefers the latest system clipboard. Native paste keeps text-selection and code-block semantics. No additional integration is required.
1295
-
1296
- Menu clipboard reads require a secure context (HTTPS or localhost) and browser permission. If reads are denied, the editor falls back to its local copy cache; use keyboard paste for external content. Menu cut deletes the source only after a successful rich clipboard write.
1297
-
1298
- ### Block Alignment And Colors
1299
-
1300
- Paragraph, heading, ordered-list, and bullet-list handle menus provide left/center/right alignment with an active check, followed by separated increase/decrease indent actions. A list handle updates its paragraph/heading content, including nested items, while preserving list structure, numbering, marks, and unrelated blocks. Mixed alignments show no check; indentation is limited to 0-8 per text block, with actions disabled only when no target can change.
1301
-
1302
- The type buttons highlight the handle target's current paragraph, H1-H6, ordered/bullet/task-list type, independently of the caret. Active buttons expose `aria-pressed` and use the same blue styling for their text and icons. Reopening after a conversion reflects the new type; insertion controls have no current-type highlight.
1303
-
1304
- Handle menus provide Add Above and Add Below with corresponding directional icons. Both reuse the basic/common insertion submenu and insert at the target block's boundaries without replacing it, including empty paragraphs. Insertions support undo; narrow screens use a submenu with a Back button.
1305
-
1306
- Action menus center vertically on the handle using their measured height, shifting only to stay within the visible editor/window intersection. Placement updates on scroll, resize, and zoom. Empty-line plus/insert menus still open below their button.
1307
-
1308
- Editor-owned popup menus, panels, and their rectangular controls use square corners, including dropdowns, nested handle menus, bubbles, palettes, emoji/mention panels, and floating media/code/date/formula editing controls. Semantic circles (avatars, radio dots, switches) and document surfaces retain their existing shapes. Native browser pickers are not restyled.
1309
-
1310
- The separate **Color** entry provides font and text-background presets and per-field custom colors in a third-level shared palette. Restore-default clears only these two color attributes, preserving fonts, sizes, and other formatting. Paragraphs, headings, lists, blockquotes, and highlight blocks support text colors; text backgrounds use the existing `textStyle.backgroundColor` mark independently of highlight-block fills and table-cell backgrounds.
1311
-
1312
- Second/third-level color menus remain open after changes, including highlight-block border/fill and divider color palettes. Narrow viewports use stacked menus with back navigation. Changes target the handle block, support undo/redo and existing JSON/HTML persistence, and require no new integration API.
1313
-
1314
- ### Text Selection Bubble
1315
-
1316
- Selecting text in edit mode shows paragraph/headings, font family/size, text/background colors, bold/italic/underline/strike, superscript/subscript, alignment/indentation, inline code, and clear-format controls. Actions reuse the toolbar commands and preserve the selection. Superscript/subscript are mutually exclusive; color palettes share recent colors with the toolbar and remain open after changes.
1317
-
1318
- The block-type button shows the current type's icon. Its dropdown offers paragraph, headings 1-3, a nested headings 4-6 menu, ordered/bullet/task lists, code blocks, then a separator followed by quotes and highlight blocks. Code, quote, and highlight options respect the existing `code-block`, `blockquote`, and `highlight-block` feature codes. Choices transform or wrap the existing content rather than insert empty blocks. Font-size menus offer only the 12 Chinese named sizes, without numeric-only options.
1319
-
1320
- Inline formatting affects only the selected text, while heading/alignment/indentation changes affect its blocks. Text selection inside cells uses the text bubble; whole-cell/table selections use table actions. Outside clicks, collapsed selections, and Escape dismiss the menu. It wraps on narrow screens and is hidden in preview/read-only, presentation, or while handle menus are open. No new integration API or document attributes are required.
1321
-
1322
- ### Table Themes
1323
-
1324
- Select table cells, rows, or columns, then click the theme icon after the cell-background button in the bubble menu. Six presets (blue, green, purple, orange, pink, and gray) and custom header, odd-row, and even-row colors are available.
1325
-
1326
- Alternatively, hover over a table, open its left-hand block menu, then hover or click Theme Color. Separators appear above and below this entry. This opens the same panel and updates that menu's table without requiring a cell selection, even when the caret is in another table.
1327
-
1328
- Each custom color opens the editor's shared palette with Default, swatches, standard colors, recent colors, and More Colors. Default restores that region's classic-blue color. Recent colors are shared with the toolbar background-color palette, and changes apply immediately.
1329
-
1330
- The first row receives the header color; data rows start at the second row and alternate automatically after rows are inserted or removed. Applying a theme removes existing cell background overrides; individual cells can be recolored afterward. Clear Styles removes the theme and cell backgrounds while preserving content, text formatting, merged cells, and column widths.
1331
-
1332
- No extra integration callback is required. Table themes are saved in `attrs.tableTheme` through the existing document `v-model` / `change` flow, and support undo/redo, collaboration, and exports. To initialize a themed table, supply:
1333
-
1334
- ```ts
1335
- attrs: {
1336
- tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
1337
- }
1338
- ```
1339
-
1340
- Omit `tableTheme` or set it to `null` to retain the default table appearance.
1341
-
1342
- ### Divider Style And Color
1343
-
1344
- Hover over a divider and open its left-hand block menu. Style and Color form a separate group between Paste and Delete, with separators above and below. Style shows only solid, dashed, and dotted previews, with names in hover tooltips. Color uses the shared editor palette, including Default, swatches, standard colors, recent colors, and More Colors. Default restores the original light gray; recent colors are shared with text colors.
1345
-
1346
- Only that menu's divider is modified; no selection or additional callback is required. The existing document `v-model` / `change` flow persists its attributes, with undo/redo, clipboard, and export support:
1347
-
1348
- ```ts
1349
- { type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
1350
- ```
1351
-
1352
- `lineStyle` accepts `solid`, `dashed`, or `dotted`. `lineColor` accepts six-digit HEX colors or `null` for the default. Old documents without these attributes retain the default solid line. The existing `divider` feature code controls insertion; no new authorization code is needed.
1353
-
1354
- ### Highlight Block Colors And Settings
1355
-
1356
- The highlight-block handle menu provides **Border Color**, **Fill Color**, and **Settings** between paste and delete. The main handle menu grows naturally without an internal scrollbar and shifts upward near the bottom edge. Each color menu has second-level presets, no-color, and restore-default actions; Custom Color opens the shared third-level palette with standard, recent, custom, default, and clear-color actions. Border and fill remain independent, and both menu levels stay open after selection. Narrow viewports use back navigation between levels. Settings contains the emoji enable/disable switch; enabling it restores the inline emoji picker.
1357
-
1358
- Highlight blocks no longer show a bubble menu. Changes target the hovered block rather than the caret, preserve document JSON/HTML attributes, and support undo/redo. No new integration props or events are required.
1359
-
1360
- ### Quote Colors
1361
-
1362
- The blockquote handle menu exposes **Border Color** and **Background Color** between paste and delete. Each second-level palette contains 15 colors plus no-color, filling two complete rows of 8 swatches while preserving existing presets and defaults. Restore-default remains available; Custom Color opens the shared third-level picker. Both levels remain open after changes, with back navigation on narrow screens.
1363
-
1364
- Changes target the handle's blockquote independently of the caret, other surface colors, and text marks. The toolbar quote picker remains available. Colors persist through the existing `blockquote.attrs.quoteBorderColor` and `blockquote.attrs.quoteBackgroundColor` JSON/HTML attributes, with undo/redo support and no new integration API.
1365
-
1366
- ### Image Captions And Links
1367
-
1368
- Dragging an image to another position in the same editor moves the original block and preserves dimensions, alignment, rotation, captions, and links without inserting a duplicate. Dragging within a group reorders its items; dropping outside moves the entire group. Side-handle dragging and external image-file upload hooks remain available.
1369
-
1370
- Native image dragging, side-handle dragging, and external file upload use matching blue block drop lines with a left-end dot.
1371
-
1372
- Select an image and use its caption action to type directly below it. Captions save while typing and support multiple lines. After clearing the text, one extra Backspace hides only the caption input. Existing descriptions display automatically; preview/read-only modes use plain text.
1373
-
1374
- The link action opens a popover below the toolbar with a URL, an Open In Current Page checkbox, Cancel, and Confirm. Only Confirm or Enter saves. Cancel, Escape, outside clicks, and selecting another image discard drafts. Confirm an empty URL to remove a link; invalid URLs do not replace existing values.
1375
-
1376
- In edit mode, clicking a linked image selects it without navigation. Links open with their configured target only in preview, read-only, or presentation mode. Saved documents and exports still retain the link.
1377
-
1378
- No additional integration events are required. Document `v-model` / `change` and `insertImage()` accept `description`, optional `descriptionVisible` (otherwise inferred from the description), `link`, and optional `linkTarget` (`_blank` by default, or `_self`). `getImages()` retains these fields. Undo/redo, clipboard, and exports preserve saved captions and confirmed links, but not link drafts.
1379
-
1380
- ### Events
1301
+ ### Available Keys
1302
+
1303
+ All authorization codes are passed through one `feature-codes` list. Import the `RICH_TEXT_EDITOR_*_CODES` constants to avoid hand-written strings:
1304
+
1305
+ ```ts
1306
+ import {
1307
+ RICH_TEXT_EDITOR_EXPORT_CODES,
1308
+ RICH_TEXT_EDITOR_FEATURE_CODES,
1309
+ RICH_TEXT_EDITOR_INSERT_MENU_CODES,
1310
+ RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES,
1311
+ } from '@norio-office/rich-text'
1312
+
1313
+ import type { RichTextEditorCode } from '@norio-office/rich-text'
1314
+
1315
+ const featureCodes: RichTextEditorCode[] = [
1316
+ RICH_TEXT_EDITOR_EXPORT_CODES.pdf,
1317
+ RICH_TEXT_EDITOR_INSERT_MENU_CODES.image,
1318
+ RICH_TEXT_EDITOR_FEATURE_CODES.outlineRight,
1319
+ RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES.blockquote,
1320
+ ]
1321
+ ```
1322
+
1323
+ `featureCodes` is one unified authorization pool. Export, insert menu, toolbar, and advanced features are all checked against the same array:
1324
+
1325
+ ```vue
1326
+ <RichTextEditor
1327
+ v-model="content"
1328
+ :feature-codes="['pdf', 'image']"
1329
+ />
1330
+ ```
1331
+
1332
+ This enables PDF export, image export, and the insert-image entry. Because `image` is a unified code, it matches both image export and image insertion.
1333
+
1334
+ Complete authorization code list:
1335
+
1336
+ | Code | Group | Controls | Related props |
1337
+ | --- | --- | --- | --- |
1338
+ | `comments` | Advanced feature | Comment button, right-side comment panel, document comment anchor clicks, and comment interactions. | `showComments`, `comments`, `commentUser` |
1339
+ | `outlineLeft` | Advanced feature | Built-in outline and edge icon toggle on the left. | `showOutline` |
1340
+ | `outlineRight` | Advanced feature | Built-in outline and edge icon toggle on the right. | `showOutline` |
1341
+ | `watermark` | Advanced feature | Page watermark display; current exports remove this layer. | `watermark` |
1342
+ | `collaboration` | Advanced feature | Yjs collaboration and remote cursors; without authorization, the editor initializes in single-user mode. | `collaboration` |
1343
+ | `mention` | Advanced feature | Main editor `@` mention, comment input `@` mention popup, and mention instance methods. | `mention`, `commentMention`, `mentionProvider`, `commentMentionProvider` |
1344
+ | `pdf` | Compatibility code | Built-in control removed; `exportPdf()` remains available. | - |
1345
+ | `html` | Compatibility code | Built-in control removed; `exportHtml()` remains available. | - |
1346
+ | `image` | Insert menu | Controls image insertion; `exportImage()` is not filtered by the whitelist. | `uploadImage` |
1347
+ | `print` | Compatibility code | Built-in print control removed. | - |
1348
+ | `video` | Insert menu | Video entry in the insert menu. | `uploadVideo` |
1349
+ | `table` | Insert menu | Table entry in the insert menu. | - |
1350
+ | `local-file` | Insert menu | Local file entry in the insert menu. | `uploadFile` |
1351
+ | `columns` | Insert menu | Columns entry in the insert menu. | - |
1352
+ | `highlight-block` | Insert menu | Highlight block entry in the insert menu. | - |
1353
+ | `date` | Insert menu | Date entry in the insert menu; currently reserved as an authorization code. | - |
1354
+ | `code-block` | Insert menu | Code block entry in the insert menu. | - |
1355
+ | `formula` | Insert menu | Formula entry in the insert menu. | - |
1356
+ | `blockquote` | Insert menu + toolbar | Blockquote entry in the insert menu and blockquote button in the toolbar. | - |
1357
+ | `emoji` | Insert menu + toolbar | Emoji entry in the insert menu and emoji button in the toolbar. | - |
1358
+ | `link` | Insert menu | Link entry in the insert menu. | - |
1359
+ | `divider` | Insert menu | Divider entry in the insert menu. | - |
1360
+ | `countdown` | Insert menu | Countdown entry in the insert menu. | - |
1361
+ | `markdown-import` | Insert menu | Markdown import entry in the insert menu. | - |
1362
+
1363
+ Write a shared code only once. For example, `blockquote` controls both insert-menu blockquote and the toolbar blockquote button. Instance export methods are not controlled by these codes.
1364
+
1365
+ Outline authorization rule: with only `outlineLeft`, the outline and its edge toggle appear on the left; with only `outlineRight`, they appear on the right; with both, `outlinePlacement` decides placement; with neither, the built-in outline and edge toggle are hidden.
1366
+
1367
+ ### Copy, Cut, And Paste
1368
+
1369
+ Block-menu actions interoperate with `Ctrl/Cmd+C`, `Ctrl/Cmd+X`, and `Ctrl/Cmd+V`, preserving node types, attributes, and formatting. Menu paste inserts below the current block and prefers the latest system clipboard. Native paste keeps text-selection and code-block semantics. No additional integration is required.
1370
+
1371
+ Menu clipboard reads require a secure context (HTTPS or localhost) and browser permission. If reads are denied, the editor falls back to its local copy cache; use keyboard paste for external content. Menu cut deletes the source only after a successful rich clipboard write.
1372
+
1373
+ ### Block Alignment And Colors
1374
+
1375
+ Block handles appear only on idle hover, not automatically at the caret. Typing (including IME composition), dragging a text selection, and block marquee selection hide the handles and their menus. Text, image, video, link, and table bubbles take priority over handles. For example, selecting text shows only its formatting bubble; collapse the selection and hover over a block again to reveal its handle.
1376
+
1377
+ Paragraph, heading, ordered-list, and bullet-list handle menus provide left/center/right alignment with an active check, followed by separated increase/decrease indent actions. A list handle updates its paragraph/heading content, including nested items, while preserving list structure, numbering, marks, and unrelated blocks. Mixed alignments show no check; indentation is limited to 0-8 per text block, with actions disabled only when no target can change.
1378
+
1379
+ The type buttons highlight the handle target's current paragraph, H1-H6, ordered/bullet/task-list type, independently of the caret. Active buttons expose `aria-pressed` and use the same blue styling for their text and icons. Reopening after a conversion reflects the new type; insertion controls have no current-type highlight.
1380
+
1381
+ Handle menus provide Add Above and Add Below with corresponding directional icons. Both reuse the basic/common insertion submenu and insert at the target block's boundaries without replacing it, including empty paragraphs. Insertions support undo; narrow screens use a submenu with a Back button.
1382
+
1383
+ Action menus center vertically on the handle using their measured height, shifting only to stay within the visible editor/window intersection. Placement updates on scroll, resize, and zoom. Empty-line plus/insert menus still open below their button.
1384
+
1385
+ Editor-owned popup menus, panels, and their rectangular controls use square corners, including dropdowns, nested handle menus, bubbles, palettes, emoji/mention panels, and floating media/code/date/formula editing controls. Semantic circles (avatars, radio dots, switches) and document surfaces retain their existing shapes. Native browser pickers are not restyled.
1386
+
1387
+ The separate **Color** entry provides font and text-background presets and per-field custom colors in a third-level shared palette. Restore-default clears only these two color attributes, preserving fonts, sizes, and other formatting. Paragraphs, headings, lists, blockquotes, and highlight blocks support text colors; text backgrounds use the existing `textStyle.backgroundColor` mark independently of highlight-block fills and table-cell backgrounds.
1388
+
1389
+ Second/third-level color menus remain open after changes, including highlight-block border/fill and divider color palettes. Narrow viewports use stacked menus with back navigation. Changes target the handle block, support undo/redo and existing JSON/HTML persistence, and require no new integration API.
1390
+
1391
+ ### Text Selection Bubble
1392
+
1393
+ Selecting text in edit mode shows paragraph/headings, font family/size, text/background colors, bold/italic/underline/strike, superscript/subscript, alignment/indentation, inline code, and clear-format controls. Actions reuse the toolbar commands and preserve the selection. Superscript/subscript are mutually exclusive; color palettes share recent colors with the toolbar and remain open after changes.
1394
+
1395
+ The bubble appears after selection finishes, not during a mouse drag. It stays hidden until the pointer is released, or until Shift is released after expanding a selection with navigation keys. Starting another selection temporarily hides an existing bubble. For example, dragging across two paragraphs leaves the text unobstructed; releasing the mouse reveals the formatting controls.
1396
+
1397
+ The block-type button shows the current type's icon. Its dropdown offers paragraph, headings 1-3, a nested headings 4-6 menu, ordered/bullet/task lists, code blocks, then a separator followed by quotes and highlight blocks. Code, quote, and highlight options respect the existing `code-block`, `blockquote`, and `highlight-block` feature codes. Choices transform or wrap the existing content rather than insert empty blocks. Font-size menus offer only the 12 Chinese named sizes, without numeric-only options.
1398
+
1399
+ Inline formatting affects only the selected text, while heading/alignment/indentation changes affect its blocks. Text, cell, and whole-table selections share one table bubble: font, size, text/background colors, bold, italic, underline, strike, and alignment/indentation above, and merge/split, cell background, theme, and row/column actions below. The table bubble omits block type, superscript/subscript, inline code, and clear formatting. Unavailable operations are disabled. For example, changing the font or color of a selected word does not change the rest of its cell; text background and whole-cell background are separate. The bubble stays hidden during selection gestures and appears when they finish. Outside clicks, collapsed selections, and Escape dismiss the menu. It wraps on narrow screens and is hidden in preview/read-only or presentation. A text selection takes priority and closes any open handle menu. No new integration API or document attributes are required.
1400
+
1401
+ ### Table Themes
1402
+
1403
+ Select table cells, rows, or columns, then click the theme icon after the cell-background button in the bubble menu. Six presets (blue, green, purple, orange, pink, and gray) and custom header, odd-row, and even-row colors are available.
1404
+
1405
+ Alternatively, hover over a table, open its left-hand block menu, then hover or click Theme Color. Separators appear above and below this entry. This opens the same panel and updates that menu's table without requiring a cell selection, even when the caret is in another table.
1406
+
1407
+ Each custom color opens the editor's shared palette with Default, swatches, standard colors, recent colors, and More Colors. Default restores that region's classic-blue color. Recent colors are shared with the toolbar background-color palette, and changes apply immediately.
1408
+
1409
+ The first row receives the header color; data rows start at the second row and alternate automatically after rows are inserted or removed. Applying a theme removes existing cell background overrides; individual cells can be recolored afterward. Clear Styles removes the theme and cell backgrounds while preserving content, text formatting, merged cells, and column widths.
1410
+
1411
+ No extra integration callback is required. Table themes are saved in `attrs.tableTheme` through the existing document `v-model` / `change` flow, and support undo/redo, collaboration, and exports. To initialize a themed table, supply:
1412
+
1413
+ ```ts
1414
+ attrs: {
1415
+ tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
1416
+ }
1417
+ ```
1418
+
1419
+ Omit `tableTheme` or set it to `null` to retain the default table appearance.
1420
+
1421
+ ### Divider Style And Color
1422
+
1423
+ Hover over a divider and open its left-hand block menu. Style and Color form a separate group between Paste and Delete, with separators above and below. Style shows only solid, dashed, and dotted previews, with names in hover tooltips. Color uses the shared editor palette, including Default, swatches, standard colors, recent colors, and More Colors. Default restores the original light gray; recent colors are shared with text colors.
1424
+
1425
+ Only that menu's divider is modified; no selection or additional callback is required. The existing document `v-model` / `change` flow persists its attributes, with undo/redo, clipboard, and export support:
1426
+
1427
+ ```ts
1428
+ { type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
1429
+ ```
1430
+
1431
+ `lineStyle` accepts `solid`, `dashed`, or `dotted`. `lineColor` accepts six-digit HEX colors or `null` for the default. Old documents without these attributes retain the default solid line. The existing `divider` feature code controls insertion; no new authorization code is needed.
1432
+
1433
+ ### Highlight Block Colors And Settings
1434
+
1435
+ The highlight-block handle menu provides **Border Color**, **Fill Color**, and **Settings** between paste and delete. The main handle menu grows naturally without an internal scrollbar and shifts upward near the bottom edge. Each color menu has second-level presets, no-color, and restore-default actions; Custom Color opens the shared third-level palette with standard, recent, custom, default, and clear-color actions. Border and fill remain independent, and both menu levels stay open after selection. Narrow viewports use back navigation between levels. Settings contains the emoji enable/disable switch; enabling it restores the inline emoji picker.
1436
+
1437
+ Highlight blocks no longer show a bubble menu. Changes target the hovered block rather than the caret, preserve document JSON/HTML attributes, and support undo/redo. No new integration props or events are required.
1438
+
1439
+ ### Quote Colors
1440
+
1441
+ The blockquote handle menu exposes **Border Color** and **Background Color** between paste and delete. Each second-level palette contains 15 colors plus no-color, filling two complete rows of 8 swatches while preserving existing presets and defaults. Restore-default remains available; Custom Color opens the shared third-level picker. Both levels remain open after changes, with back navigation on narrow screens.
1442
+
1443
+ Changes target the handle's blockquote independently of the caret, other surface colors, and text marks. The toolbar quote picker remains available. Colors persist through the existing `blockquote.attrs.quoteBorderColor` and `blockquote.attrs.quoteBackgroundColor` JSON/HTML attributes, with undo/redo support and no new integration API.
1444
+
1445
+ ### Image Captions And Links
1446
+
1447
+ Dragging an image to another position in the same editor moves the original block and preserves dimensions, alignment, rotation, captions, and links without inserting a duplicate. Dragging within a group reorders its items; dropping outside moves the entire group. Side-handle dragging and external image-file upload hooks remain available.
1448
+
1449
+ Native image dragging, side-handle dragging, and external file upload use matching blue block drop lines with a left-end dot.
1450
+
1451
+ Select an image and use its caption action to type directly below it. Captions save while typing and support multiple lines. After clearing the text, one extra Backspace hides only the caption input. Existing descriptions display automatically; preview/read-only modes use plain text.
1452
+
1453
+ The link action opens a popover below the toolbar with a URL, an Open In Current Page checkbox, Cancel, and Confirm. Only Confirm or Enter saves. Cancel, Escape, outside clicks, and selecting another image discard drafts. Confirm an empty URL to remove a link; invalid URLs do not replace existing values.
1454
+
1455
+ In edit mode, clicking a linked image selects it without navigation. Links open with their configured target only in preview, read-only, or presentation mode. Saved documents and exports still retain the link.
1456
+
1457
+ No additional integration events are required. Document `v-model` / `change` and `insertImage()` accept `description`, optional `descriptionVisible` (otherwise inferred from the description), `link`, and optional `linkTarget` (`_blank` by default, or `_self`). `getImages()` retains these fields. Undo/redo, clipboard, and exports preserve saved captions and confirmed links, but not link drafts.
1458
+
1459
+ ### Events
1381
1460
 
1382
1461
  | Event | Payload | Description |
1383
1462
  | --- | --- | --- |
@@ -1389,8 +1468,8 @@ No additional integration events are required. Document `v-model` / `change` and
1389
1468
  | `upload-error` | `RichTextEditorUploadErrorPayload` | Emitted when an image, video, or file upload hook fails. |
1390
1469
  | `mention-search` | `RichTextEditorMentionProviderPayload` | Function-style listener syntax for the `onMentionSearch` prop; loads candidates after the user types `@`; may return an array or a `Promise`. |
1391
1470
  | `mention-item-click` | `RichTextEditorMentionItem` | Emitted when a popup candidate or inserted mention node is clicked. |
1392
- | `mention-submit` | `RichTextEditorMentionItem` | Emitted after the popup `提及` button inserts the selected mention. |
1393
- | `outline-change` | `RichTextEditorOutlineState` | Emits `{ items, activePos }` when the outline or active position changes. |
1471
+ | `mention-submit` | `RichTextEditorMentionItem` | Emitted after the popup `提及` button inserts the selected mention. |
1472
+ | `outline-change` | `RichTextEditorOutlineState` | Emits `{ items, activePos }` when the outline or active position changes. |
1394
1473
 
1395
1474
  `mention-search` is not declared in the component's `defineEmits`. In Vue templates, `@mention-search="handler"` is passed to the component as the `onMentionSearch` function prop.
1396
1475
 
@@ -1409,11 +1488,11 @@ import type { JSONContent } from '@tiptap/core'
1409
1488
  import { RichTextEditor } from '@norio-office/rich-text'
1410
1489
  import type {
1411
1490
  RichTextEditorMentionItem,
1412
- RichTextEditorMentionProviderPayload,
1413
- } from '@norio-office/rich-text'
1414
- import '@norio-office/rich-text/style.css'
1415
-
1416
- const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1491
+ RichTextEditorMentionProviderPayload,
1492
+ } from '@norio-office/rich-text'
1493
+ import '@norio-office/rich-text/style.css'
1494
+
1495
+ const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1417
1496
 
1418
1497
  const mentionItems: RichTextEditorMentionItem[] = [
1419
1498
  { id: 'user-1001', name: 'Cui Guoqiang', type: 1 },
@@ -1427,7 +1506,7 @@ async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload
1427
1506
  await new Promise((resolve) => window.setTimeout(resolve, 120))
1428
1507
 
1429
1508
  return mentionItems.filter((item) => {
1430
- const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
1509
+ const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
1431
1510
  const matchedKeyword = !query || item.name.toLowerCase().includes(query)
1432
1511
  return matchedType && matchedKeyword
1433
1512
  })
@@ -1457,7 +1536,7 @@ Clicking a candidate only selects it and emits `mention-item-click`; clicking th
1457
1536
 
1458
1537
  ### Custom Labels
1459
1538
 
1460
- The default UI labels are Chinese. `messages` only overrides keys actually read by the implementation. Some handle and selection-menu labels remain hard-coded Chinese; unknown keys have no effect.
1539
+ The default UI labels are Chinese. `messages` only overrides keys actually read by the implementation. Some handle and selection-menu labels remain hard-coded Chinese; unknown keys have no effect.
1461
1540
 
1462
1541
  ```vue
1463
1542
  <RichTextEditor
@@ -1508,7 +1587,7 @@ Common message keys:
1508
1587
  | `outline.label` | 大纲 | Outline |
1509
1588
  | `outline.collapse` | 收起大纲 | Collapse outline |
1510
1589
  | `outline.empty.description` | 对文档内容应用“标题”样式,即可自动生成大纲。 | Apply heading styles to generate an outline. |
1511
- | `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 | Use the outline icon at the content-area edge to open the outline. |
1590
+ | `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 | Use the outline icon at the content-area edge to open the outline. |
1512
1591
  | `status.wordCountUnit` | 个字 | characters |
1513
1592
  | `status.presentation.enter` | 演示 | Present |
1514
1593
  | `status.presentation.exit` | 退出演示 | Exit presentation |
@@ -1518,21 +1597,21 @@ Common message keys:
1518
1597
  | `countdown.settingsTitle` | 倒计时设置 | Countdown settings |
1519
1598
  | `formula.insertTitle` | 插入 LaTeX 公式 | Insert LaTeX formula |
1520
1599
 
1521
- ### Preview Mode
1522
-
1523
- `editable=false` in edit mode preserves the toolbar by default while disabling user editing; preview always hides it. Host code must still guard calls to mutating instance methods. The component needs a browser DOM; mount client-side in SSR applications.
1524
-
1525
- Use `mode="preview"` to switch the component into a read-only preview shell. The top toolbar, bubble menus, and block handle menus are hidden, editing is disabled, image links work, and the outline can be placed on either side. When editing is enabled, clicking an image selects it for editing instead of following its link.
1526
-
1527
- `showToolbar` defaults to `true` and can be changed dynamically. It only controls the top toolbar, not editing, bubble menus, block handle menus, or the bottom status bar. Preview and presentation always hide the top toolbar, regardless of this prop.
1528
-
1529
- For example, hide the top toolbar while keeping the document editable:
1530
-
1531
- ```vue
1532
- <RichTextEditor v-model="content" :show-toolbar="false" />
1533
- ```
1534
-
1535
- For read-only preview:
1600
+ ### Preview Mode
1601
+
1602
+ Host code must still guard calls to mutating instance methods in preview mode. The component needs a browser DOM; mount client-side in SSR applications.
1603
+
1604
+ Use `mode="preview"` to switch the component into a read-only preview shell. The top toolbar, bubble menus, and block handle menus are hidden, editing is disabled, image links work, and the outline can be placed on either side. When editing is enabled, clicking an image selects it for editing instead of following its link.
1605
+
1606
+ `showToolbar` defaults to `true` and can be changed dynamically. It only controls the top toolbar, not editing, bubble menus, block handle menus, or the bottom status bar. Preview and presentation always hide the top toolbar, regardless of this prop.
1607
+
1608
+ For example, hide the top toolbar while keeping the document editable:
1609
+
1610
+ ```vue
1611
+ <RichTextEditor v-model="content" :show-toolbar="false" />
1612
+ ```
1613
+
1614
+ For read-only preview:
1536
1615
 
1537
1616
  ```vue
1538
1617
  <RichTextEditor
@@ -1542,9 +1621,9 @@ For read-only preview:
1542
1621
  />
1543
1622
  ```
1544
1623
 
1545
- On narrow screens, preview mode automatically scales the page canvas so the document stays readable on phones.
1546
-
1547
- Presentation, fullscreen, zoom, export, and print are available in the bottom status bar; export and print are no longer in the top toolbar. Presentation temporarily switches the component to read-only preview in fullscreen. Pressing Escape or leaving fullscreen through the browser restores the original edit/preview state without modifying the host's `mode`, `editable`, or document content. For example, starting from edit mode returns to editing, while starting from preview remains in preview.
1624
+ On narrow screens, preview mode automatically scales the page canvas so the document stays readable on phones.
1625
+
1626
+ Presentation, fullscreen, and zoom are available in the bottom status bar; export and print have no editor UI controls. Presentation temporarily switches the component to read-only preview in fullscreen. Pressing Escape or leaving fullscreen through the browser restores the original edit/preview state without modifying the host's `mode` or document content. For example, starting from edit mode returns to editing, while starting from preview remains in preview.
1548
1627
 
1549
1628
  ### Collaboration
1550
1629
 
@@ -1558,7 +1637,7 @@ Minimal integration:
1558
1637
 
1559
1638
  ```vue
1560
1639
  <script setup lang="ts">
1561
- import { computed, onBeforeUnmount, ref } from 'vue'
1640
+ import { computed, onBeforeUnmount, ref } from 'vue'
1562
1641
  import * as Y from 'yjs'
1563
1642
  import { WebsocketProvider } from 'y-websocket'
1564
1643
  import type { JSONContent } from '@tiptap/core'
@@ -1572,7 +1651,7 @@ const ydoc = new Y.Doc()
1572
1651
  const user = {
1573
1652
  userId: 'user_001',
1574
1653
  userName: 'Alice',
1575
- clientUniqueCode: crypto.randomUUID(),
1654
+ clientUniqueCode: crypto.randomUUID(),
1576
1655
  color: '#3b82f6',
1577
1656
  }
1578
1657
 
@@ -1597,18 +1676,18 @@ const collaboration = computed(() => ({
1597
1676
  document: ydoc,
1598
1677
  field: 'content',
1599
1678
  provider,
1600
- user: {
1601
- name: user.userName,
1602
- color: user.color,
1603
- userId: user.userId,
1604
- clientUniqueCode: user.clientUniqueCode,
1605
- },
1606
- }))
1607
- onBeforeUnmount(() => {
1608
- provider.destroy()
1609
- ydoc.destroy()
1610
- })
1611
- </script>
1679
+ user: {
1680
+ name: user.userName,
1681
+ color: user.color,
1682
+ userId: user.userId,
1683
+ clientUniqueCode: user.clientUniqueCode,
1684
+ },
1685
+ }))
1686
+ onBeforeUnmount(() => {
1687
+ provider.destroy()
1688
+ ydoc.destroy()
1689
+ })
1690
+ </script>
1612
1691
 
1613
1692
  <template>
1614
1693
  <RichTextEditor
@@ -1622,8 +1701,8 @@ Rules:
1622
1701
 
1623
1702
  - Keep the `WebsocketProvider` room name and query `roomId` the same.
1624
1703
  - All clients in the same room must use the same `field`; for normal one-file-one-editor use, keep it as `content`.
1625
- - If the same user opens two browser windows, each window must use a different `clientUniqueCode`.
1626
- - Collaboration extensions are configured at creation. When changing rooms or switching editing modes, destroy the old provider/document and remount with a new Vue key; changing props alone does not rebuild the extensions.
1704
+ - If the same user opens two browser windows, each window must use a different `clientUniqueCode`.
1705
+ - Collaboration extensions are configured at creation. When changing rooms or switching editing modes, destroy the old provider/document and remount with a new Vue key; changing props alone does not rebuild the extensions.
1627
1706
  - Remote cursors and selections require both `provider` and `user`.
1628
1707
  - In collaboration mode, the Y.Doc/Yjs fragment is authoritative. External `modelValue` is only an emitted snapshot and must not continuously drive remote collaborative content.
1629
1708
 
@@ -1635,10 +1714,10 @@ Initialization:
1635
1714
 
1636
1715
  ```ts
1637
1716
  const collaboration = computed(() => ({
1638
- document: ydoc,
1639
- field: 'content',
1640
- provider,
1641
- user: { name: user.userName, color: user.color, userId: user.userId },
1717
+ document: ydoc,
1718
+ field: 'content',
1719
+ provider,
1720
+ user: { name: user.userName, color: user.color, userId: user.userId },
1642
1721
  initializeContent: ownsInitialContent,
1643
1722
  initialContent: ownsInitialContent ? businessContent : null,
1644
1723
  }))
@@ -1658,20 +1737,20 @@ The component supports both normal single-user editing and optional Yjs collabor
1658
1737
 
1659
1738
  ```vue
1660
1739
  <script setup lang="ts">
1661
- import { onBeforeUnmount, ref } from 'vue'
1662
- import * as Y from 'yjs'
1740
+ import { onBeforeUnmount, ref } from 'vue'
1741
+ import * as Y from 'yjs'
1663
1742
  import { WebsocketProvider } from 'y-websocket'
1664
1743
  import type { JSONContent } from '@tiptap/core'
1665
1744
  import { RichTextEditor } from '@norio-office/rich-text'
1666
1745
  import '@norio-office/rich-text/style.css'
1667
1746
 
1668
1747
  const ydoc = new Y.Doc()
1669
- const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
1670
- const content = ref<JSONContent | null>(null)
1671
- onBeforeUnmount(() => {
1672
- provider.destroy()
1673
- ydoc.destroy()
1674
- })
1748
+ const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
1749
+ const content = ref<JSONContent | null>(null)
1750
+ onBeforeUnmount(() => {
1751
+ provider.destroy()
1752
+ ydoc.destroy()
1753
+ })
1675
1754
  </script>
1676
1755
 
1677
1756
  <template>
@@ -1754,33 +1833,33 @@ Available methods:
1754
1833
  | `getOutlineItems()` | `RichTextEditorOutlineItem[]` | Returns the current outline items. |
1755
1834
  | `getActiveOutlinePos()` | `number \| null` | Returns the document position of the active outline item. |
1756
1835
  | `focusOutlineItem(pos)` | `boolean` | Focuses and scrolls to an outline item. |
1757
- | `onOutlineChange(handler)` | `() => void` | Subscribes to outline changes and returns an unsubscribe function. |
1758
- | `focusCommentThread(threadId)` | `boolean` | Focuses a comment anchor; returns false if not found. |
1759
-
1760
- Media insertion methods insert before the current nonempty text block, preserving it; empty/whitespace text blocks are replaced, and block-level selections insert at their starting position. They do not insert in the middle of a sentence. Place the caret in a target empty paragraph for explicit placement. They accept already-uploaded URLs and do not call upload hooks or uniformly enforce whitelist/read-only settings; check permissions in your host code. Image arrays are truncated to four items. Media getters return summaries of valid media, not a complete archive; current summaries omit `assetId` and image-block dimensions, and `insertFile()` does not persist `assetId`. Save JSON for full fidelity.
1836
+ | `onOutlineChange(handler)` | `() => void` | Subscribes to outline changes and returns an unsubscribe function. |
1837
+ | `focusCommentThread(threadId)` | `boolean` | Focuses a comment anchor; returns false if not found. |
1838
+
1839
+ Media insertion methods insert before the current nonempty text block, preserving it; empty/whitespace text blocks are replaced, and block-level selections insert at their starting position. They do not insert in the middle of a sentence. Place the caret in a target empty paragraph for explicit placement. They accept already-uploaded URLs and do not call upload hooks or uniformly enforce whitelist/read-only settings; check permissions in your host code. Image arrays are truncated to four items. Media getters return summaries of valid media, not a complete archive; current summaries omit `assetId` and image-block dimensions, and `insertFile()` does not persist `assetId`. Save JSON for full fidelity.
1840
+
1841
+ ### External Outline Component
1761
1842
 
1762
- ### External Outline Component
1763
-
1764
- The built-in outline starts collapsed with an icon button halfway down the configured content-area edge. Opening it hides the button and shows a floating panel flush with the top, bottom, and outer edge without reflowing the document. Closing restores the button. The left button has square left corners and rounded right corners; the right button is mirrored. The status bar no longer contains an outline toggle. Edit and preview modes support it; presentation hides it.
1765
-
1766
- The editor renders its built-in outline by default. To place the outline in any sidebar, drawer, or custom layout, hide the built-in panel and pass the editor instance to `RichTextOutline`.
1843
+ The built-in outline starts collapsed with an icon button halfway down the configured content-area edge. Opening it hides the button and shows a floating panel flush with the top, bottom, and outer edge without reflowing the document. Closing restores the button. The left button has square left corners and rounded right corners; the right button is mirrored. The status bar no longer contains an outline toggle. Edit and preview modes support it; presentation hides it.
1844
+
1845
+ The editor renders its built-in outline by default. To place the outline in any sidebar, drawer, or custom layout, hide the built-in panel and pass the editor instance to `RichTextOutline`.
1767
1846
 
1768
1847
  ```vue
1769
1848
  <script setup lang="ts">
1770
1849
  import { ref } from 'vue'
1771
- import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
1772
- import type { RichTextEditorInstance } from '@norio-office/rich-text'
1773
- import type { JSONContent } from '@tiptap/core'
1774
- import '@norio-office/rich-text/style.css'
1775
-
1776
- const editorRef = ref<RichTextEditorInstance | null>(null)
1777
- const content = ref<JSONContent>({
1778
- type: 'doc',
1779
- content: [
1780
- { type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: 'Project Notes' }] },
1781
- { type: 'paragraph' },
1782
- ],
1783
- })
1850
+ import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
1851
+ import type { RichTextEditorInstance } from '@norio-office/rich-text'
1852
+ import type { JSONContent } from '@tiptap/core'
1853
+ import '@norio-office/rich-text/style.css'
1854
+
1855
+ const editorRef = ref<RichTextEditorInstance | null>(null)
1856
+ const content = ref<JSONContent>({
1857
+ type: 'doc',
1858
+ content: [
1859
+ { type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: 'Project Notes' }] },
1860
+ { type: 'paragraph' },
1861
+ ],
1862
+ })
1784
1863
  </script>
1785
1864
 
1786
1865
  <template>
@@ -1812,18 +1891,18 @@ Page-level drag upload routes files by MIME type: `image/*` uses image upload,
1812
1891
  inserted as a local file card.
1813
1892
 
1814
1893
  ```vue
1815
- <script setup lang="ts">
1816
- import { ref } from 'vue'
1817
- import type { JSONContent } from '@tiptap/core'
1818
- import { RichTextEditor } from '@norio-office/rich-text'
1819
- import type {
1820
- RichTextEditorUploadInput,
1821
- RichTextEditorUploadResult,
1822
- RichTextEditorUploadErrorPayload,
1823
- } from '@norio-office/rich-text'
1824
- import '@norio-office/rich-text/style.css'
1825
-
1826
- const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1894
+ <script setup lang="ts">
1895
+ import { ref } from 'vue'
1896
+ import type { JSONContent } from '@tiptap/core'
1897
+ import { RichTextEditor } from '@norio-office/rich-text'
1898
+ import type {
1899
+ RichTextEditorUploadInput,
1900
+ RichTextEditorUploadResult,
1901
+ RichTextEditorUploadErrorPayload,
1902
+ } from '@norio-office/rich-text'
1903
+ import '@norio-office/rich-text/style.css'
1904
+
1905
+ const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
1827
1906
 
1828
1907
  async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
1829
1908
  const form = new FormData()
@@ -1839,9 +1918,9 @@ async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichT
1839
1918
  throw new Error('Upload failed')
1840
1919
  }
1841
1920
 
1842
- const result = await response.json() as RichTextEditorUploadResult
1843
- if (!result.url) throw new Error('Upload response is missing url')
1844
- return result
1921
+ const result = await response.json() as RichTextEditorUploadResult
1922
+ if (!result.url) throw new Error('Upload response is missing url')
1923
+ return result
1845
1924
  }
1846
1925
 
1847
1926
  function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
@@ -1927,31 +2006,31 @@ editorRef.value?.insertLocalFile({
1927
2006
  })
1928
2007
  ```
1929
2008
 
1930
- ### Export Example
1931
-
1932
- Use these functions with the `editorRef` from Instance API. Built-in menus download automatically; instance methods only return data. Upload hooks must return an object with a required `url`, not a URL string, and should not call insertion methods again. Demo API URLs must be replaced by your own backend.
1933
-
1934
- Image export captures the page (PNG by default; JPEG supports quality 0-1). PDF export instead uses a simplified DOM text/rectangle renderer on one document-height page, without embedding images, videos or SVG icons, and without guaranteeing complex font/formula/border/watermark fidelity. For a more faithful PDF, try the browser's Print / Save as PDF and verify it. HTML exports a complete styled document but does not bundle remote media. Persist JSON for editing, not these export formats.
1935
-
1936
- All built-in export paths clone and clean the page first, removing editing controls, video blocks and watermark layers. Built-in print shares this cleanup; it is not an exact export of every on-screen element.
1937
-
1938
- ```ts
1939
- function downloadBlob(blob: Blob, name: string) {
1940
- const url = URL.createObjectURL(blob)
1941
- const link = document.createElement('a')
1942
- link.href = url
1943
- link.download = name
1944
- document.body.append(link)
1945
- link.click()
1946
- link.remove()
1947
- window.setTimeout(() => URL.revokeObjectURL(url), 1000)
1948
- }
1949
-
1950
- async function handleExportPdf() {
2009
+ ### Export Example
2010
+
2011
+ Use these functions with the `editorRef` from Instance API. The editor has no export button; instance methods return data and the host handles downloads. Upload hooks must return an object with a required `url`, not a URL string, and should not call insertion methods again. Demo API URLs must be replaced by your own backend.
2012
+
2013
+ Image export captures the page (PNG by default; JPEG supports quality 0-1). PDF export instead uses a simplified DOM text/rectangle renderer on one document-height page, without embedding images, videos or SVG icons, and without guaranteeing complex font/formula/border/watermark fidelity. For a more faithful PDF, try the browser's Print / Save as PDF and verify it. HTML exports a complete styled document but does not bundle remote media. Persist JSON for editing, not these export formats.
2014
+
2015
+ The export methods clone and clean the page first, removing editing controls, video blocks and watermark layers. They do not export every on-screen element.
2016
+
2017
+ ```ts
2018
+ function downloadBlob(blob: Blob, name: string) {
2019
+ const url = URL.createObjectURL(blob)
2020
+ const link = document.createElement('a')
2021
+ link.href = url
2022
+ link.download = name
2023
+ document.body.append(link)
2024
+ link.click()
2025
+ link.remove()
2026
+ window.setTimeout(() => URL.revokeObjectURL(url), 1000)
2027
+ }
2028
+
2029
+ async function handleExportPdf() {
1951
2030
  const blob = await editorRef.value?.exportPdf()
1952
2031
  if (!blob) return
1953
2032
 
1954
- downloadBlob(blob, 'demo.pdf')
2033
+ downloadBlob(blob, 'demo.pdf')
1955
2034
  }
1956
2035
 
1957
2036
  async function handleExportImage() {
@@ -1960,7 +2039,7 @@ async function handleExportImage() {
1960
2039
  })
1961
2040
  if (!blob) return
1962
2041
 
1963
- downloadBlob(blob, 'demo.png')
2042
+ downloadBlob(blob, 'demo.png')
1964
2043
  }
1965
2044
 
1966
2045
  function handleExportHtml() {
@@ -2031,11 +2110,11 @@ import RichTextEditor, {
2031
2110
  - Usage guide: `docs/usage.md`
2032
2111
  - Bundled Yjs server example: `yjs/README.md`
2033
2112
 
2034
- ## 评论功能对接
2113
+ ## 评论功能对接
2035
2114
 
2036
2115
  评论功能由组件负责右侧栏 UI、正文锚点标注、回复交互、图片预览和评论输入框里的 `@` 弹层;评论数据本身由业务系统保存。对接时可以把它理解成:组件抛事件,业务保存数据,然后把新的 `comments` 数组再传回组件。
2037
2116
 
2038
- 下面是一个完整的本地演示,包含:
2117
+ 下面是一个完整的本地演示,包含:
2039
2118
 
2040
2119
  - 当前评论用户假数据
2041
2120
  - 已有评论线程假数据
@@ -2045,11 +2124,11 @@ import RichTextEditor, {
2045
2124
  - `comment-submit` 统一通知事件,用来拿到“评论了谁、@了谁、评论内容”等信息
2046
2125
 
2047
2126
  ```vue
2048
- <script setup lang="ts">
2049
- import { onBeforeUnmount, ref } from 'vue'
2050
- import { RichTextEditor } from '@norio-office/rich-text'
2051
- import type {
2052
- RichTextEditorCommentCreatePayload,
2127
+ <script setup lang="ts">
2128
+ import { onBeforeUnmount, ref } from 'vue'
2129
+ import { RichTextEditor } from '@norio-office/rich-text'
2130
+ import type {
2131
+ RichTextEditorCommentCreatePayload,
2053
2132
  RichTextEditorCommentDeletePayload,
2054
2133
  RichTextEditorCommentMentionProviderPayload,
2055
2134
  RichTextEditorCommentReplyPayload,
@@ -2130,15 +2209,15 @@ const comments = ref<RichTextEditorCommentThread[]>([
2130
2209
  },
2131
2210
  ])
2132
2211
 
2133
- const demoObjectUrls: string[] = []
2134
- onBeforeUnmount(() => demoObjectUrls.forEach(url => URL.revokeObjectURL(url)))
2135
-
2136
- async function uploadCommentImage(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
2137
- // 真实项目里改成上传到文件服务,然后返回 url/name/size/mimeType。
2138
- const url = URL.createObjectURL(payload.file)
2139
- demoObjectUrls.push(url)
2140
- return {
2141
- url,
2212
+ const demoObjectUrls: string[] = []
2213
+ onBeforeUnmount(() => demoObjectUrls.forEach(url => URL.revokeObjectURL(url)))
2214
+
2215
+ async function uploadCommentImage(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
2216
+ // 真实项目里改成上传到文件服务,然后返回 url/name/size/mimeType。
2217
+ const url = URL.createObjectURL(payload.file)
2218
+ demoObjectUrls.push(url)
2219
+ return {
2220
+ url,
2142
2221
  name: payload.file.name,
2143
2222
  size: payload.file.size,
2144
2223
  mimeType: payload.file.type,
@@ -2273,14 +2352,14 @@ function handleCommentSubmit(payload: RichTextEditorCommentSubmitPayload) {
2273
2352
  </template>
2274
2353
  ```
2275
2354
 
2276
- ### 评论 Props
2277
-
2278
- 上例数据只在内存中更新,刷新页面会丢失;mock 图片地址只在本次页面生命周期有效。生产中必须换成持久化接口和长期可访问的图片 URL。`comment-submit` 是同一次操作的汇总通知,不要与 `comment-create/reply/update` 再重复写入同一条评论。用户身份和编辑/删除权限仍应由后端校验。
2355
+ ### 评论 Props
2356
+
2357
+ 上例数据只在内存中更新,刷新页面会丢失;mock 图片地址只在本次页面生命周期有效。生产中必须换成持久化接口和长期可访问的图片 URL。`comment-submit` 是同一次操作的汇总通知,不要与 `comment-create/reply/update` 再重复写入同一条评论。用户身份和编辑/删除权限仍应由后端校验。
2279
2358
 
2280
2359
  | Prop | 类型 | 说明 |
2281
2360
  | --- | --- | --- |
2282
2361
  | `comments` | `RichTextEditorCommentThread[] \| null` | 评论线程列表,业务方持久化并回传。 |
2283
- | `commentUser` | `RichTextEditorCommentUser \| null` | 当前评论用户;未传时尝试使用协同用户,两者都不可用时不能新建或回复。 |
2362
+ | `commentUser` | `RichTextEditorCommentUser \| null` | 当前评论用户;未传时尝试使用协同用户,两者都不可用时不能新建或回复。 |
2284
2363
  | `showComments` | `boolean` | 是否显示评论功能;为 `true` 时显示工具栏评论按钮和右侧评论栏,为 `false` 或不传时隐藏评论入口和评论栏。 |
2285
2364
  | `uploadCommentImage` | `RichTextEditorUploadHook \| null` | 评论图片上传 hook,返回结构同 `uploadImage`;未传时会回退使用 `uploadImage`。 |
2286
2365
  | `commentMention` | `boolean` | 是否启用评论输入框里的 `@` 提及,默认启用。 |