@norio-office/rich-text 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +819 -249
- package/dist/components/BlockColorPanel.vue.d.ts +21 -0
- package/dist/components/ColorPalettePanel.vue.d.ts +13 -0
- package/dist/components/FormulaEditorDialog.vue.d.ts +2 -2
- package/dist/components/ImageBlockView.vue.d.ts +3 -0
- package/dist/components/RichTextEditor.vue.d.ts +19 -14
- package/dist/components/RichTextOutline.vue.d.ts +2 -2
- package/dist/components/TableThemePanel.vue.d.ts +25 -0
- package/dist/components/TextSelectionMenu.vue.d.ts +56 -0
- package/dist/composables/useNodeViewEditable.d.ts +2 -0
- package/dist/extensions/styled-horizontal-rule.d.ts +1 -0
- package/dist/extensions/themed-table.d.ts +1 -0
- package/dist/feature-codes.d.ts +45 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8536 -6934
- package/dist/index.umd.cjs +1865 -1394
- package/dist/style.css +1 -1
- package/dist/types.d.ts +13 -4
- package/dist/utils/color-palette.d.ts +2 -0
- package/dist/utils/divider.d.ts +13 -0
- package/dist/utils/table-theme.d.ts +44 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
# @norio-office/rich-text
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
个人开发项目,生产使用前请结合业务场景测试。问题反馈: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 协同编辑。
|
|
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()`、初始化权判断等占位逻辑必须替换成业务实现。
|
|
10
23
|
|
|
11
24
|
### 安装
|
|
12
25
|
|
|
@@ -20,10 +33,10 @@ npm install @norio-office/rich-text
|
|
|
20
33
|
import '@norio-office/rich-text/style.css'
|
|
21
34
|
```
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
运行环境需要 Vue 3.5+,Tiptap 使用本包声明的 3.x 兼容版本。若包管理器未自动安装 peer dependencies(宿主需要提供的依赖),请按 `package.json` 的版本范围安装,不要混用 Tiptap 2.x 或随意升级到下一主版本:
|
|
24
37
|
|
|
25
38
|
```bash
|
|
26
|
-
npm install vue @tiptap/core @tiptap/vue-3 @tiptap/pm @tiptap/starter-kit @tiptap/extension-placeholder @tiptap/extension-code-block @tiptap/extension-code-block-lowlight @tiptap/extension-collaboration @tiptap/extension-collaboration-caret @tiptap/extension-font-family @tiptap/extension-subscript @tiptap/extension-superscript @tiptap/extension-table @tiptap/extension-table-cell @tiptap/extension-table-header @tiptap/extension-table-row @tiptap/extension-task-item @tiptap/extension-task-list @tiptap/extension-text-style @tiptap/extension-underline @tiptap/y-tiptap lowlight y-prosemirror yjs
|
|
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
|
|
27
40
|
```
|
|
28
41
|
|
|
29
42
|
`html2canvas`、`jspdf`、`katex`、`marked`、`plyr` 已作为普通 dependencies 随包安装。
|
|
@@ -37,7 +50,10 @@ import type { JSONContent } from '@tiptap/core'
|
|
|
37
50
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
38
51
|
import '@norio-office/rich-text/style.css'
|
|
39
52
|
|
|
40
|
-
const content = ref<JSONContent
|
|
53
|
+
const content = ref<JSONContent>({
|
|
54
|
+
type: 'doc',
|
|
55
|
+
content: [{ type: 'paragraph' }],
|
|
56
|
+
})
|
|
41
57
|
</script>
|
|
42
58
|
|
|
43
59
|
<template>
|
|
@@ -48,39 +64,118 @@ const content = ref<JSONContent | null>(null)
|
|
|
48
64
|
也可以使用默认导出:
|
|
49
65
|
|
|
50
66
|
```ts
|
|
51
|
-
import RichTextEditor from '@norio-office/rich-text'
|
|
52
|
-
```
|
|
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 为准,不能用这个赋值方式覆盖房间内容。
|
|
53
134
|
|
|
54
135
|
### Props
|
|
55
136
|
|
|
56
137
|
| Prop | 类型 | 默认值 | 说明 |
|
|
57
138
|
| --- | --- | --- | --- |
|
|
58
|
-
| `modelValue` | `JSONContent \| null` | `null` |
|
|
139
|
+
| `modelValue` | `JSONContent \| null` | `null` | 编辑器 JSON,支持 `v-model`;`null` 不表示清空,见上方示例。 |
|
|
59
140
|
| `documentName` | `string` | `''` | 内置导出下载的文件名基础名;组件会自动追加 `.pdf`、`.png` 或 `.html`。 |
|
|
60
141
|
| `editable` | `boolean` | `true` | 是否允许编辑。 |
|
|
61
|
-
| `mode` | `'edit' \| 'preview'` | `'edit'` | 编辑模式或预览模式。 |
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
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` 时兼容生效。 |
|
|
69
153
|
| `placeholder` | `string` | `''` | 空内容占位文案。 |
|
|
70
154
|
| `mention` | `boolean` | `false` | 是否启用 `@` 提及功能;只有设为 `true` 时输入 `@` 才会打开候选面板,`insertMention()` 才会插入提及节点。 |
|
|
71
|
-
| `collaboration` | `RichTextEditorCollaborationOptions \| null` | `
|
|
155
|
+
| `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs 协同配置,在组件创建时使用。 |
|
|
72
156
|
| `uploadImage` | `RichTextEditorUploadHook \| null` | `null` | 内置图片选择、图片块上传时调用;返回最终可访问 URL 后组件插入图片。 |
|
|
73
157
|
| `uploadVideo` | `RichTextEditorUploadHook \| null` | `null` | 内置视频选择、视频块上传时调用;返回最终可访问 URL 后组件插入视频。 |
|
|
74
158
|
| `uploadFile` | `RichTextEditorUploadHook \| null` | `null` | 本地文件选择器上传时调用;返回最终可访问 URL 后组件插入文件卡片。 |
|
|
75
159
|
| `onUploadError` | `RichTextEditorUploadErrorHandler \| null` | `null` | 上传失败回调;同时也会触发 `upload-error` 事件。 |
|
|
76
|
-
| `mentionProvider` | `RichTextEditorMentionProvider \| null` | `
|
|
77
|
-
| `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `
|
|
78
|
-
|
|
79
|
-
|
|
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`,不要依赖它实现严格的编辑权限隔离。
|
|
80
175
|
|
|
81
176
|
### 水印
|
|
82
177
|
|
|
83
|
-
`watermark` 只作为页面视觉层渲染,不写入编辑器 JSON,也不会影响 `getText()`
|
|
178
|
+
`watermark` 只作为页面视觉层渲染,不写入编辑器 JSON,也不会影响 `getText()` 的纯文本结果。当前导出清理流程会移除水印层,所以 PDF、图片、HTML 和内置打印输出都不保留它。若业务要求导出水印,需要在业务导出流程中另行处理,不能把页面水印当成文件防泄漏能力。
|
|
84
179
|
|
|
85
180
|
```vue
|
|
86
181
|
<RichTextEditor
|
|
@@ -103,51 +198,210 @@ import RichTextEditor from '@norio-office/rich-text'
|
|
|
103
198
|
| `rotate` | `number` | `-24` | 水印倾斜角度,单位 deg。 |
|
|
104
199
|
| `showInEdit` | `boolean` | `true` | 编辑状态下是否显示水印;预览状态始终按配置显示。 |
|
|
105
200
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
201
|
+
旧版白名单兼容示例(不要同时传 `feature-codes`):
|
|
202
|
+
|
|
203
|
+
```vue
|
|
204
|
+
<RichTextEditor
|
|
205
|
+
v-model="content"
|
|
206
|
+
:enabled-export-items="['html', 'image']"
|
|
110
207
|
:enabled-insert-menu-items="['image', 'local-file', 'blockquote']"
|
|
111
208
|
:enabled-toolbar-actions="['blockquote']"
|
|
112
209
|
/>
|
|
113
210
|
```
|
|
114
211
|
|
|
115
|
-
### 可用 Key
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
type
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
句柄只在空闲时悬停显示,不会随光标自动出现。输入(包括中文输入法)、拖动选中文字或块框选时,句柄及其菜单会隐藏;有文字、图片、视频、链接或表格气泡菜单时,也不显示句柄。例如,选中文字后只能看到格式气泡,收起选区后再次移动鼠标到块旁边,才会显示句柄。
|
|
284
|
+
|
|
285
|
+
块侧边菜单与 `Ctrl/Cmd+C`、`Ctrl/Cmd+X`、`Ctrl/Cmd+V` 可以交叉使用,保留表格、高亮块、任务列表、图片等节点类型和属性。菜单粘贴在当前块下方插入,优先读取最新系统剪贴板;普通快捷键粘贴保留文字选区和代码块的原生行为,无需额外对接。
|
|
286
|
+
|
|
287
|
+
菜单读取剪贴板需要安全上下文(HTTPS 或 localhost)和浏览器权限。读取被拒绝时回退到本编辑器缓存,外部内容可用快捷键粘贴;菜单剪切只有在成功写入系统剪贴板后才删除原节点。
|
|
288
|
+
|
|
289
|
+
### 块菜单的对齐与颜色
|
|
290
|
+
|
|
291
|
+
正文和标题的句柄菜单提供“缩进和对齐”:左、中、右对齐显示当前选中项,分割线下方是增加、减少缩进;缩进范围为 0-8,到达边界时对应操作禁用。
|
|
292
|
+
|
|
293
|
+
“颜色”独立放在“缩进和对齐”下方,可设置字体颜色和文字背景色,每项都有“自定义颜色”入口,打开三级内置颜色选择器。“恢复默认”只清除文字色和背景色,保留字体、字号、加粗等格式。
|
|
294
|
+
|
|
295
|
+
有序列表和无序列表的句柄菜单也提供“缩进和对齐”,支持左/中/右对齐及增减缩进。操作统一作用于该列表内的正文和标题(包括嵌套项),保留列表结构、编号及文字格式,不影响其他列表;缩进范围为 0–8,各文本块独立限制,设置后菜单保持打开。
|
|
296
|
+
|
|
297
|
+
句柄菜单顶部的类型按钮会高亮回显当前句柄节点:正文、H1–H6、有序列表、无序列表或待办。回显跟随句柄目标,不受其他位置的光标影响;转换或修改节点后重新打开菜单会显示新类型,插入菜单不会误显示为当前类型。
|
|
298
|
+
|
|
299
|
+
句柄操作菜单默认以句柄中心上下居中,仅在顶部或底部空间不足时向可视区域内避让。定位按实际菜单高度计算,跟随滚动、窗口尺寸和缩放更新;空行“+”的插入菜单仍在按钮下方展开。
|
|
300
|
+
|
|
301
|
+
句柄菜单的“颜色”和“剪切”之间、以及“删除”上方使用统一横线分组,样式与“删除”和添加菜单之间的分割线一致。
|
|
302
|
+
|
|
303
|
+
句柄菜单提供“在上方添加”和“在下方添加”,分别使用对应方向的图标。两者共用基础/常用节点子菜单,在目标块前后插入并保留原块(包括空段落),支持撤销;窄屏使用带“返回”的子菜单。
|
|
304
|
+
|
|
305
|
+
编辑器自有弹出菜单统一使用直角,包括工具栏下拉、插入及句柄多级菜单、文字/表格气泡、颜色/表情/@提及面板,以及图片、视频、链接、代码、倒计时、日期和公式的浮动设置。面板、矩形选项和色块均无圆角;头像、单选圆点及开关保留圆形,正文内容块、图片和主工具栏外观不变。
|
|
306
|
+
|
|
307
|
+
二级、三级颜色菜单选色后保持打开,可连续调整;高亮块边框/填充及分割线颜色同样不会自动关闭。小屏下使用带“返回”的逐级菜单。操作仅作用于句柄对应的块,支持撤销、重做,沿用文档 JSON/HTML 保存,无需新增对接参数。
|
|
308
|
+
|
|
309
|
+
文字背景色使用现有 `textStyle.backgroundColor`,与高亮块整块填充、表格单元格背景色分别设置。段落、标题、列表、引用和高亮块均支持文字颜色菜单。
|
|
310
|
+
|
|
311
|
+
### 文字选区气泡菜单
|
|
312
|
+
|
|
313
|
+
在编辑状态选中文字,会在选区附近显示格式气泡菜单,提供正文/标题、字体、字号、文字色、文字背景色、加粗、斜体、下划线、删除线、上下标、对齐与缩进、行内代码和清除格式。上下标互斥切换;颜色使用内置颜色选择器,最近使用颜色与顶部工具栏共享,选色后不关闭面板。
|
|
314
|
+
|
|
315
|
+
气泡在选择结束后才出现:按住鼠标拖选时隐藏,松开鼠标后显示;按住 Shift 用方向键扩展选区时隐藏,松开 Shift 后显示。例如,拖选两段文字的过程中不会有菜单挡住正文,松开后才显示格式按钮。重新拖选时,已有气泡也会暂时隐藏。
|
|
316
|
+
|
|
317
|
+
顶部工具栏和选区气泡菜单的字号选项统一只保留初号、小初、一号、小一、二号、小二、三号、小三、四号、小四、五号、小五,不显示纯数字字号选项;已有文档的字号数据保持不变。
|
|
318
|
+
|
|
319
|
+
选区气泡的正文按钮显示当前块类型图标;菜单提供正文、一至三级标题、“其他标题”(二级菜单含四至六级)、有序列表、无序列表、任务、代码块、引用和高亮块。代码块与引用之间使用分隔线,代码块、引用、高亮块分别遵循现有 `code-block`、`blockquote`、`highlight-block` 授权码。选择后直接转换或包裹原有内容,不额外插入空块;不提供尚未实现的同步块入口。
|
|
320
|
+
|
|
321
|
+
操作保留选区:行内格式只修改选中文字,对齐、缩进和标题修改所在块。表格内选中文字、单元格或整表时,统一显示一个表格气泡:上方提供字体、字号、文字色、文字背景色、加粗、斜体、下划线、删除线、对齐与缩进,不提供正文/标题、上下标、行内代码和清除格式;下方提供合并、拆分、单元格背景色、主题色及增删行列等表格操作,不能执行的操作会禁用。例如,只选中单元格中的“评论”二字,改字体、字号或文字颜色不会影响同格其他文字;“文字背景颜色”与整格的“设置单元格背景色”互相独立。拖选期间不显示,选择结束后才出现。收起选区、点击外部或按 Escape 可关闭;小屏自动换行,预览/只读和演示时不显示。文字选区优先显示气泡,并关闭已打开的句柄菜单。无需新增对接参数,格式仍随现有文档 JSON/HTML 保存。
|
|
322
|
+
|
|
323
|
+
### 表格主题色
|
|
324
|
+
|
|
325
|
+
选中表格单元格、行或列后,在气泡菜单的“设置单元格背景色”后点击主题图标。内置经典蓝、清新绿、优雅紫、活力橙、玫瑰粉、简约灰,支持分别自定义表头、奇数行、偶数行颜色。
|
|
326
|
+
|
|
327
|
+
也可以鼠标移入表格,打开左侧块操作菜单,悬停或点击“主题色”。该入口上下使用菜单分割线分隔;这里复用相同主题面板,直接修改该菜单对应的表格,不需要先选中单元格;光标位于另一张表格时也不会改错目标。
|
|
328
|
+
|
|
329
|
+
点击三个颜色块会打开编辑器自带的颜色面板,包含默认色、色板、标准色、最近使用和“更多颜色”。默认色恢复经典蓝主题对应区域的颜色;最近使用与工具栏背景色面板共享,选择后立即生效。
|
|
330
|
+
|
|
331
|
+
主题作用于整张表:首行为表头色,第二行开始交替填色,增删行后会自动重新交替。选主题时清除当前表已有的单元格背景覆盖色,之后仍可单独设置单元格背景。“清除样式”清除主题和单元格背景,保留内容、文字格式、合并关系和列宽。
|
|
332
|
+
|
|
333
|
+
无需额外对接接口;主题保存在现有文档 JSON 的表格节点 `attrs.tableTheme` 中,通过 `v-model` / `change` 一起保存,支持撤销、重做、协同和导出。也可在初始文档的表格节点中传入:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
attrs: {
|
|
337
|
+
tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
不传 `tableTheme` 或设置为 `null` 时保留原有表格外观。
|
|
342
|
+
|
|
343
|
+
### 分割线样式与颜色
|
|
344
|
+
|
|
345
|
+
鼠标移入分割线,打开左侧块操作菜单:
|
|
346
|
+
|
|
347
|
+
- **样式**:只展示实线、虚线、点状线的预览,悬停可查看名称,点击即可切换。
|
|
348
|
+
- **颜色**:复用编辑器颜色面板,支持默认色、色板、标准色、最近使用和更多颜色;默认色恢复原来的浅灰色,最近使用与文字颜色面板共享。
|
|
349
|
+
|
|
350
|
+
样式和颜色为独立一组,与上方粘贴、下方删除之间使用菜单分割线分隔。
|
|
351
|
+
|
|
352
|
+
修改只作用于当前菜单对应的分割线,不需要先选中它。无需额外回调;属性保存在 `horizontalRule` 节点中,通过现有 `v-model` / `change` 保存,支持撤销、重做、复制粘贴和导出。初始文档示例:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
{ type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
`lineStyle` 可选 `solid`(实线)、`dashed`(虚线)、`dotted`(点状线);`lineColor` 使用六位 HEX 色值,`null` 表示默认色。不传属性的旧文档仍显示默认实线。`feature-codes` 中的 `divider` 控制插入入口,无需新增授权码。
|
|
359
|
+
|
|
360
|
+
### 高亮块颜色与设置
|
|
361
|
+
|
|
362
|
+
移入高亮块并打开句柄菜单,在“粘贴”和“删除”之间可设置。句柄主菜单按内容撑开,不显示内部滚动条,靠近底部时自动上移:
|
|
363
|
+
|
|
364
|
+
- **边框颜色**:二级菜单提供预设色、无颜色和恢复默认;“自定义颜色”打开三级内置颜色选择器,支持标准色、最近使用、更多颜色、默认和清除颜色。
|
|
365
|
+
- **填充颜色**:独立设置块背景,颜色选择方式同上。
|
|
366
|
+
- **设置**:切换“启用表情”;关闭后隐藏左侧表情,开启后可继续点击表情进行选择。
|
|
367
|
+
|
|
368
|
+
边框和填充独立设置,选色后二级、三级菜单保持打开,可以连续修改;窄屏通过“返回”切换菜单层级。
|
|
369
|
+
|
|
370
|
+
高亮块不再显示气泡菜单。操作仅影响句柄对应的高亮块,不依赖当前光标位置;属性仍保存在文档 JSON/HTML 中,支持撤销、重做,无需新增对接参数。
|
|
371
|
+
|
|
372
|
+
### 引用颜色
|
|
373
|
+
|
|
374
|
+
移入引用块并打开左侧句柄菜单,在“粘贴”和“删除”之间可设置 **边框颜色**、**背景颜色**。二级菜单各提供 15 个预设色,加上无颜色按钮,完整显示两行、每行 8 格;保留原有预设和默认色,并支持恢复默认。“自定义颜色”打开三级内置颜色选择器。选色后菜单保持打开,窄屏通过“返回”切换层级。
|
|
375
|
+
|
|
376
|
+
修改只作用于句柄对应的引用块,不依赖光标位置;边框色、块背景色、文字颜色互不影响。原顶部工具栏的引用颜色设置保留。数据仍使用 `blockquote.attrs.quoteBorderColor`、`blockquote.attrs.quoteBackgroundColor`,随现有文档 JSON/HTML 保存,支持撤销和重做,无需新增对接参数。
|
|
377
|
+
|
|
378
|
+
### 图片描述与链接
|
|
379
|
+
|
|
380
|
+
直接按住图片拖到文档其他位置,会移动原图片,保留宽高、对齐、旋转、描述和链接,不会重复插入。图片组内拖到另一张图片上可调整顺序,拖到组外会移动整组;侧边句柄拖动仍可使用。外部图片文件拖入仍走上传 hook。
|
|
381
|
+
|
|
382
|
+
直接拖图片、句柄拖动和外部文件拖入的块级落点提示统一为蓝色横线及左端圆点。
|
|
383
|
+
|
|
384
|
+
选中图片,点击气泡菜单的“设置图片描述”,即可在图片下方直接输入。描述随输入保存,支持换行;清空文字后再按一次 Backspace,会隐藏描述框,不会删除图片。旧文档或上传结果中已有的 `description` 会自动显示,预览/只读时显示为普通文字。
|
|
385
|
+
|
|
386
|
+
点击“设置图片链接”,在气泡菜单下方弹层输入网址,可勾选“在当前页面打开”。点击“确定”或按 Enter 才保存;“取消”、Escape、点击外部或切换图片均放弃本次修改。清空网址后确定即移除链接,无效网址不会覆盖旧值。
|
|
387
|
+
|
|
388
|
+
编辑状态下点击已设置链接的图片只选中图片,不会跳转;预览、只读或演示状态下才按配置打开链接。保存与导出仍保留链接数据。
|
|
389
|
+
|
|
390
|
+
无需新增对接事件,数据通过现有文档 `v-model` / `change` 保存,也可通过 `insertImage()` 传入:
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
editorRef.value?.insertImage({
|
|
394
|
+
src: 'https://example.com/photo.png',
|
|
395
|
+
description: '图片描述',
|
|
396
|
+
descriptionVisible: true,
|
|
397
|
+
link: 'https://example.com/details',
|
|
398
|
+
linkTarget: '_blank',
|
|
399
|
+
})
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
`descriptionVisible` 可选,不传时根据描述是否为空决定显示;`true` 可显示空描述框,`false` 隐藏描述。`linkTarget` 可选 `_blank`(默认,新页面)或 `_self`(当前页面)。`getImages()` 返回这些字段;描述和已确认链接支持撤销、重做、复制粘贴和导出,未确认的链接草稿不会导出。
|
|
403
|
+
|
|
404
|
+
### 事件
|
|
151
405
|
|
|
152
406
|
| 事件 | Payload | 说明 |
|
|
153
407
|
| --- | --- | --- |
|
|
@@ -159,9 +413,12 @@ type RichTextEditorToolbarActionKey = 'blockquote'
|
|
|
159
413
|
| `upload-error` | `RichTextEditorUploadErrorPayload` | 图片、视频或文件上传 hook 失败时触发。 |
|
|
160
414
|
| `mention-search` | `RichTextEditorMentionProviderPayload` | 函数式监听写法,对应 `onMentionSearch` prop;输入 `@` 后加载候选数据,可返回数组或 `Promise`。 |
|
|
161
415
|
| `mention-item-click` | `RichTextEditorMentionItem` | 点击弹窗候选项或已插入的提及节点时触发。 |
|
|
162
|
-
| `mention-submit` | `RichTextEditorMentionItem` | 点击弹窗 `提及` 按钮并插入提及节点后触发。 |
|
|
416
|
+
| `mention-submit` | `RichTextEditorMentionItem` | 点击弹窗 `提及` 按钮并插入提及节点后触发。 |
|
|
417
|
+
| `outline-change` | `RichTextEditorOutlineState` | 大纲条目或当前激活位置更新;可用 `@outline-change` 获取 `{ items, activePos }`。 |
|
|
163
418
|
|
|
164
|
-
`mention-search` 没有出现在组件的 `defineEmits` 中;Vue 模板里的 `@mention-search="handler"` 会作为 `onMentionSearch` 函数式 prop 传入组件。
|
|
419
|
+
`mention-search` 没有出现在组件的 `defineEmits` 中;Vue 模板里的 `@mention-search="handler"` 会作为 `onMentionSearch` 函数式 prop 传入组件。
|
|
420
|
+
|
|
421
|
+
评论的创建、回复、删除等事件单独列在[评论事件](#评论事件)中。正文提及加载函数可以返回候选数组;评论的 `@comment-mention-search` 是通知事件,返回值不会被用作候选数据,务必使用对应的 provider prop。
|
|
165
422
|
|
|
166
423
|
### @ 提及
|
|
167
424
|
|
|
@@ -178,10 +435,11 @@ import type { JSONContent } from '@tiptap/core'
|
|
|
178
435
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
179
436
|
import type {
|
|
180
437
|
RichTextEditorMentionItem,
|
|
181
|
-
RichTextEditorMentionProviderPayload,
|
|
182
|
-
} from '@norio-office/rich-text'
|
|
183
|
-
|
|
184
|
-
|
|
438
|
+
RichTextEditorMentionProviderPayload,
|
|
439
|
+
} from '@norio-office/rich-text'
|
|
440
|
+
import '@norio-office/rich-text/style.css'
|
|
441
|
+
|
|
442
|
+
const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
|
|
185
443
|
|
|
186
444
|
const mentionItems: RichTextEditorMentionItem[] = [
|
|
187
445
|
{ id: 'user-1001', name: '崔国强', type: 1 },
|
|
@@ -195,7 +453,7 @@ async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload
|
|
|
195
453
|
await new Promise((resolve) => window.setTimeout(resolve, 120))
|
|
196
454
|
|
|
197
455
|
return mentionItems.filter((item) => {
|
|
198
|
-
const matchedType = payload.type === 'all' || item.type === payload.type
|
|
456
|
+
const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
|
|
199
457
|
const matchedKeyword = !query || item.name.toLowerCase().includes(query)
|
|
200
458
|
return matchedType && matchedKeyword
|
|
201
459
|
})
|
|
@@ -225,7 +483,7 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
|
|
|
225
483
|
|
|
226
484
|
### 自定义文案
|
|
227
485
|
|
|
228
|
-
编辑器默认 UI
|
|
486
|
+
编辑器默认 UI 文案为中文。`messages` 只会覆盖代码实际读取的文案 key,并非所有界面文字都已经支持替换。句柄菜单和文字选区菜单的部分文案仍是内置中文;传入不存在的 key 不会改变界面。
|
|
229
487
|
|
|
230
488
|
```vue
|
|
231
489
|
<RichTextEditor
|
|
@@ -276,7 +534,7 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
|
|
|
276
534
|
| `outline.label` | 大纲 |
|
|
277
535
|
| `outline.collapse` | 收起大纲 |
|
|
278
536
|
| `outline.empty.description` | 对文档内容应用“标题”样式,即可自动生成大纲。 |
|
|
279
|
-
| `outline.empty.tip` |
|
|
537
|
+
| `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 |
|
|
280
538
|
| `status.wordCountUnit` | 个字 |
|
|
281
539
|
| `status.presentation.enter` | 演示 |
|
|
282
540
|
| `status.presentation.exit` | 退出演示 |
|
|
@@ -288,8 +546,27 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
|
|
|
288
546
|
|
|
289
547
|
### 预览模式
|
|
290
548
|
|
|
291
|
-
`mode="preview"`
|
|
292
|
-
|
|
549
|
+
`mode="preview"` 会切换到只读预览外壳。预览模式下顶部工具栏、气泡菜单和句柄菜单都不显示,正文不能编辑;图片设置的跳转链接生效,大纲仍可放在左侧或右侧。正文可编辑时,点击图片只用于选中和编辑,不会跳转。
|
|
550
|
+
|
|
551
|
+
| 配置 | 正文能否编辑 | 顶部工具栏 | 适用场景 |
|
|
552
|
+
| --- | --- | --- | --- |
|
|
553
|
+
| 默认 `mode="edit"`、`editable=true` | 能 | 显示 | 写文档 |
|
|
554
|
+
| `mode="edit"`、`:show-toolbar="false"` | 能,除非同时设置 `editable=false` | 隐藏 | 只使用选中文字的气泡菜单和块句柄菜单 |
|
|
555
|
+
| `mode="edit"`、`:editable="false"` | 不能 | 保留,编辑操作受限制 | 编辑页面里的只读状态 |
|
|
556
|
+
| `mode="preview"` | 不能,即使 `editable=true` | 隐藏 | 阅读/预览 |
|
|
557
|
+
|
|
558
|
+
这里限制的是用户交互,不是业务 API 的安全边界。业务方仍应避免在只读时主动调用修改内容的方法。
|
|
559
|
+
|
|
560
|
+
`showToolbar` 默认是 `true`,只控制顶部工具栏,不影响正文编辑、气泡菜单、句柄菜单或底部信息栏。可以动态切换;预览和演示时无论这个属性是什么值,顶部工具栏都会隐藏。
|
|
561
|
+
|
|
562
|
+
例如,保留编辑能力,但隐藏顶部工具栏:
|
|
563
|
+
|
|
564
|
+
```vue
|
|
565
|
+
<RichTextEditor v-model="content" :show-toolbar="false" />
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
切换成只读预览:
|
|
569
|
+
|
|
293
570
|
```vue
|
|
294
571
|
<RichTextEditor
|
|
295
572
|
v-model="content"
|
|
@@ -298,7 +575,9 @@ function handleMentionSubmit(item: RichTextEditorMentionItem) {
|
|
|
298
575
|
/>
|
|
299
576
|
```
|
|
300
577
|
|
|
301
|
-
窄屏下预览模式会自动缩放页面画布,让文档在手机上保持可读。
|
|
578
|
+
窄屏下预览模式会自动缩放页面画布,让文档在手机上保持可读。
|
|
579
|
+
|
|
580
|
+
底部信息栏提供演示、全屏、缩放、导出和打印入口,顶部工具栏不再显示导出、打印。点击“演示”后,组件临时进入只读预览并全屏显示;按 Esc 或通过浏览器退出全屏后,恢复进入前的编辑/预览状态,不修改业务传入的 `mode`、`editable` 或文档内容。例如,从编辑页开始演示,退出后可以继续编辑;从预览页开始演示,退出后仍是预览。
|
|
302
581
|
|
|
303
582
|
### 协同编辑
|
|
304
583
|
|
|
@@ -312,7 +591,7 @@ npm install yjs y-websocket
|
|
|
312
591
|
|
|
313
592
|
```vue
|
|
314
593
|
<script setup lang="ts">
|
|
315
|
-
import { computed, ref } from 'vue'
|
|
594
|
+
import { computed, onBeforeUnmount, ref } from 'vue'
|
|
316
595
|
import * as Y from 'yjs'
|
|
317
596
|
import { WebsocketProvider } from 'y-websocket'
|
|
318
597
|
import type { JSONContent } from '@tiptap/core'
|
|
@@ -326,7 +605,7 @@ const ydoc = new Y.Doc()
|
|
|
326
605
|
const user = {
|
|
327
606
|
userId: 'user_001',
|
|
328
607
|
userName: 'Alice',
|
|
329
|
-
clientUniqueCode:
|
|
608
|
+
clientUniqueCode: crypto.randomUUID(),
|
|
330
609
|
color: '#3b82f6',
|
|
331
610
|
}
|
|
332
611
|
|
|
@@ -347,7 +626,7 @@ const provider = new WebsocketProvider(
|
|
|
347
626
|
},
|
|
348
627
|
)
|
|
349
628
|
|
|
350
|
-
const collaboration = computed(() => ({
|
|
629
|
+
const collaboration = computed(() => ({
|
|
351
630
|
document: ydoc,
|
|
352
631
|
field: 'content',
|
|
353
632
|
provider,
|
|
@@ -356,8 +635,13 @@ const collaboration = computed(() => ({
|
|
|
356
635
|
color: user.color,
|
|
357
636
|
userId: user.userId,
|
|
358
637
|
clientUniqueCode: user.clientUniqueCode,
|
|
359
|
-
},
|
|
360
|
-
}))
|
|
638
|
+
},
|
|
639
|
+
}))
|
|
640
|
+
|
|
641
|
+
onBeforeUnmount(() => {
|
|
642
|
+
provider.destroy()
|
|
643
|
+
ydoc.destroy()
|
|
644
|
+
})
|
|
361
645
|
</script>
|
|
362
646
|
|
|
363
647
|
<template>
|
|
@@ -374,7 +658,8 @@ const collaboration = computed(() => ({
|
|
|
374
658
|
- 同一个协同房间里的所有客户端必须使用同一个 `field`,普通一文档一编辑器场景固定用 `content`。
|
|
375
659
|
- 同一个用户开两个浏览器窗口时,`clientUniqueCode` 必须不同;后端不会按 `userId` 去重在线客户端。
|
|
376
660
|
- `provider + user` 都传入时,组件才会显示远程光标和远程选区。
|
|
377
|
-
- 协同模式下 Y.Doc/Yjs fragment 是内容事实来源,外部 `modelValue` 不会再作为远程内容的权威写入源。
|
|
661
|
+
- 协同模式下 Y.Doc/Yjs fragment 是内容事实来源,外部 `modelValue` 不会再作为远程内容的权威写入源。
|
|
662
|
+
- 协同扩展在组件创建时配置。切换文档/房间或从单人切换到协同时,应销毁旧 provider/Y.Doc,并用新的 `key` 重新挂载编辑器;只改 prop 不会重建协同扩展。
|
|
378
663
|
|
|
379
664
|
初始化规则:
|
|
380
665
|
|
|
@@ -384,10 +669,10 @@ const collaboration = computed(() => ({
|
|
|
384
669
|
|
|
385
670
|
```ts
|
|
386
671
|
const collaboration = computed(() => ({
|
|
387
|
-
document: ydoc,
|
|
388
|
-
field: 'content',
|
|
389
|
-
provider,
|
|
390
|
-
user,
|
|
672
|
+
document: ydoc,
|
|
673
|
+
field: 'content',
|
|
674
|
+
provider,
|
|
675
|
+
user: { name: user.userName, color: user.color, userId: user.userId },
|
|
391
676
|
initializeContent: ownsInitialContent,
|
|
392
677
|
initialContent: ownsInitialContent ? businessContent : null,
|
|
393
678
|
}))
|
|
@@ -407,16 +692,20 @@ http://127.0.0.1:5177/?collab=1&room=rich-demo-file-001&server=ws://127.0.0.1:12
|
|
|
407
692
|
|
|
408
693
|
```vue
|
|
409
694
|
<script setup lang="ts">
|
|
410
|
-
import { ref } from 'vue'
|
|
411
|
-
import * as Y from 'yjs'
|
|
695
|
+
import { onBeforeUnmount, ref } from 'vue'
|
|
696
|
+
import * as Y from 'yjs'
|
|
412
697
|
import { WebsocketProvider } from 'y-websocket'
|
|
413
698
|
import type { JSONContent } from '@tiptap/core'
|
|
414
699
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
415
700
|
import '@norio-office/rich-text/style.css'
|
|
416
701
|
|
|
417
702
|
const ydoc = new Y.Doc()
|
|
418
|
-
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
419
|
-
const content = ref<JSONContent | null>(null)
|
|
703
|
+
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
704
|
+
const content = ref<JSONContent | null>(null)
|
|
705
|
+
onBeforeUnmount(() => {
|
|
706
|
+
provider.destroy()
|
|
707
|
+
ydoc.destroy()
|
|
708
|
+
})
|
|
420
709
|
</script>
|
|
421
710
|
|
|
422
711
|
<template>
|
|
@@ -499,19 +788,37 @@ const editorRef = ref<RichTextEditorInstance | null>(null)
|
|
|
499
788
|
| `getOutlineItems()` | `RichTextEditorOutlineItem[]` | 获取当前目录项。 |
|
|
500
789
|
| `getActiveOutlinePos()` | `number \| null` | 获取当前激活目录项的文档位置。 |
|
|
501
790
|
| `focusOutlineItem(pos)` | `boolean` | 聚焦并跳转到指定目录项。 |
|
|
502
|
-
| `onOutlineChange(handler)` | `() => void` | 监听目录变化,返回取消监听函数。 |
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
791
|
+
| `onOutlineChange(handler)` | `() => void` | 监听目录变化,返回取消监听函数。 |
|
|
792
|
+
| `focusCommentThread(threadId)` | `boolean` | 跳转到指定评论锚点;找不到时返回 `false`。 |
|
|
793
|
+
|
|
794
|
+
媒体插入 API 的位置规则很重要:`insertImage()`、`insertVideo()`、`insertFile()`、`insertLocalFile()` 不会插到一句话的中间。光标所在文本块非空时,在该块前插入并保留原文;为空或只有空白时,替换这个占位块;块级选区则按选区起点插入。若要插到指定位置,先让用户在目标空段落中放置光标再调用。图片数组超过 4 项只取前 4 项。`insertMention()` 则是在当前选区插入行内提及。
|
|
795
|
+
|
|
796
|
+
这些媒体方法只接收已经上传好的地址,不会调用上传 hook。它们和导出实例方法不受顶部菜单白名单统一限制;媒体方法目前也不会自动检查预览/只读状态,调用方应自行判断。实例尚未就绪或参数缺少必要地址时无法插入,返回 `false`;不要将返回值当作服务器保存成功的确认。
|
|
797
|
+
|
|
798
|
+
`getImages()`、`getVideos()`、`getFiles()` 返回有效媒体的摘要,不包含上传占位块,也不是完整存档。例如当前返回值没有完整保留 `assetId` 和图片块尺寸,`insertFile()` 当前也没有保存传入的 `assetId`。需要完整数据时请使用 `getJSON()` 或 `v-model`。
|
|
799
|
+
|
|
800
|
+
### 外置目录组件
|
|
801
|
+
|
|
802
|
+
内置大纲默认收起,内容区边线中部显示图标按钮。点击后按钮隐藏,大纲作为悬浮层展开,上下及配置的一侧贴住内容区边线,不占正文空间;关闭后恢复按钮。左侧按钮为左直角、右圆角,右侧镜像。底部状态栏不再显示大纲按钮。编辑与预览均支持,演示时隐藏。
|
|
803
|
+
|
|
804
|
+
内置目录默认跟随编辑器一起渲染。如果需要把目录放到任意侧栏、抽屉或自定义布局里,可以关闭内置目录,并把编辑器实例传给 `RichTextOutline`。
|
|
507
805
|
|
|
508
806
|
```vue
|
|
509
807
|
<script setup lang="ts">
|
|
510
808
|
import { ref } from 'vue'
|
|
511
|
-
import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
|
|
512
|
-
import type { RichTextEditorInstance } from '@norio-office/rich-text'
|
|
513
|
-
|
|
514
|
-
|
|
809
|
+
import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
|
|
810
|
+
import type { RichTextEditorInstance } from '@norio-office/rich-text'
|
|
811
|
+
import type { JSONContent } from '@tiptap/core'
|
|
812
|
+
import '@norio-office/rich-text/style.css'
|
|
813
|
+
|
|
814
|
+
const editorRef = ref<RichTextEditorInstance | null>(null)
|
|
815
|
+
const content = ref<JSONContent>({
|
|
816
|
+
type: 'doc',
|
|
817
|
+
content: [
|
|
818
|
+
{ type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: '项目说明' }] },
|
|
819
|
+
{ type: 'paragraph' },
|
|
820
|
+
],
|
|
821
|
+
})
|
|
515
822
|
</script>
|
|
516
823
|
|
|
517
824
|
<template>
|
|
@@ -530,19 +837,27 @@ const editorRef = ref<RichTextEditorInstance | null>(null)
|
|
|
530
837
|
|
|
531
838
|
1. 在业务层上传文件。
|
|
532
839
|
2. 等待接口返回可访问 URL。
|
|
533
|
-
3. 调用组件实例方法插入返回内容。
|
|
840
|
+
3. 调用组件实例方法插入返回内容。
|
|
841
|
+
|
|
842
|
+
这是业务自行上传的方式;如果使用下面的内置上传 hook,组件会自动插入,不要在 hook 中再次调用插入 API,否则会出现重复内容。
|
|
534
843
|
|
|
535
844
|
如果使用编辑器内置的图片、视频、本地文件选择器或页面拖拽上传,请传入上传 hook。编辑器只负责把用户选中的 `File` 交给业务侧上传,并在 hook 返回 URL 后插入内容;组件不会内置业务上传接口,也不会自动回退为 base64/blob URL。
|
|
536
845
|
|
|
537
846
|
页面拖拽上传会按文件类型分流:`image/*` 走图片上传,`video/*` 走视频上传,其他格式全部走 `uploadFile` 并插入本地文件卡片。
|
|
538
847
|
|
|
539
848
|
```vue
|
|
540
|
-
<script setup lang="ts">
|
|
541
|
-
import
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
849
|
+
<script setup lang="ts">
|
|
850
|
+
import { ref } from 'vue'
|
|
851
|
+
import type { JSONContent } from '@tiptap/core'
|
|
852
|
+
import { RichTextEditor } from '@norio-office/rich-text'
|
|
853
|
+
import type {
|
|
854
|
+
RichTextEditorUploadInput,
|
|
855
|
+
RichTextEditorUploadResult,
|
|
856
|
+
RichTextEditorUploadErrorPayload,
|
|
857
|
+
} from '@norio-office/rich-text'
|
|
858
|
+
import '@norio-office/rich-text/style.css'
|
|
859
|
+
|
|
860
|
+
const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
|
|
546
861
|
|
|
547
862
|
async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
|
|
548
863
|
const form = new FormData()
|
|
@@ -558,7 +873,9 @@ async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichT
|
|
|
558
873
|
throw new Error('上传失败')
|
|
559
874
|
}
|
|
560
875
|
|
|
561
|
-
|
|
876
|
+
const result = await response.json() as RichTextEditorUploadResult
|
|
877
|
+
if (!result.url) throw new Error('上传接口没有返回 url')
|
|
878
|
+
return result
|
|
562
879
|
}
|
|
563
880
|
|
|
564
881
|
function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
|
|
@@ -578,7 +895,25 @@ function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
|
|
|
578
895
|
</template>
|
|
579
896
|
```
|
|
580
897
|
|
|
581
|
-
`onUploadError` callback prop 和 `@upload-error` 事件都能接收上传失败信息。通常选择一种接入方式即可,避免业务层重复处理。
|
|
898
|
+
`onUploadError` callback prop 和 `@upload-error` 事件都能接收上传失败信息。通常选择一种接入方式即可,避免业务层重复处理。
|
|
899
|
+
|
|
900
|
+
上面的 `/api/upload` 是业务自己实现的接口。hook 接收 `{ file: File, kind: 'image' | 'video' | 'file' }`;返回值不是 URL 字符串,而是以下对象:
|
|
901
|
+
|
|
902
|
+
```json
|
|
903
|
+
{
|
|
904
|
+
"url": "https://cdn.example.com/uploads/photo.png",
|
|
905
|
+
"assetId": "asset-1001",
|
|
906
|
+
"name": "photo.png",
|
|
907
|
+
"size": 2048,
|
|
908
|
+
"mimeType": "image/png",
|
|
909
|
+
"alt": "项目照片",
|
|
910
|
+
"description": "本次项目的示意图"
|
|
911
|
+
}
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
只有 `url` 必填,其余字段可选;缺少 `name`、`size`、`mimeType` 时,内置上传流程会使用原文件的信息。缺少 hook 会报上传错误,不会自动生成 base64;失败任务可在上传面板重试。评论图片可单独传 `uploadCommentImage`,未传时使用 `uploadImage`。
|
|
915
|
+
|
|
916
|
+
地址必须能被阅读文档的人访问。不要把本地磁盘路径或临时 `blob:` 地址当成长期文件地址;返回地址和文件权限由业务负责。
|
|
582
917
|
|
|
583
918
|
插入图片:
|
|
584
919
|
|
|
@@ -644,19 +979,36 @@ editorRef.value?.insertLocalFile({
|
|
|
644
979
|
})
|
|
645
980
|
```
|
|
646
981
|
|
|
647
|
-
### 导出示例
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
982
|
+
### 导出示例
|
|
983
|
+
|
|
984
|
+
下面的函数与“实例 API”示例中的 `editorRef` 一起使用。内置导出菜单会自动下载;实例方法仅返回 Blob/HTML,下载由你控制。
|
|
985
|
+
|
|
986
|
+
| 导出方式 | 当前实现与适用范围 |
|
|
987
|
+
| --- | --- |
|
|
988
|
+
| `exportImage()` | 页面截图;默认 PNG,可选 JPEG。`quality` 可选 0-1,主要影响 JPEG,不传时使用浏览器默认质量。 |
|
|
989
|
+
| `exportPdf()` | 简化的 DOM 文字和矩形色块绘制,生成一张随文档高度延伸的 PDF 页面;不是页面截图,也不是 Word 文件。当前不嵌入图片、视频、SVG 图标,不保证字体、公式、圆角、虚线、水印等细节还原。 |
|
|
990
|
+
| `exportHtml()` | 含内联样式的完整 HTML 文档;媒体地址仍指向原文件服务,不是离线资源包。 |
|
|
991
|
+
| 底部“打印” | 使用浏览器打印流程;需要接近页面原貌的 PDF,可在打印对话框里选择保存为 PDF,并自行检查分页和结果。 |
|
|
992
|
+
|
|
993
|
+
当前几种导出都先复制页面并清理编辑控件,视频块和页面水印也会被清除。因此不能假设导出文件包含页面上的所有元素;上面的“打印”同样受这项清理影响。
|
|
994
|
+
|
|
995
|
+
```ts
|
|
996
|
+
function downloadBlob(blob: Blob, name: string) {
|
|
997
|
+
const url = URL.createObjectURL(blob)
|
|
998
|
+
const link = document.createElement('a')
|
|
999
|
+
link.href = url
|
|
1000
|
+
link.download = name
|
|
1001
|
+
document.body.append(link)
|
|
1002
|
+
link.click()
|
|
1003
|
+
link.remove()
|
|
1004
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async function handleExportPdf() {
|
|
651
1008
|
const blob = await editorRef.value?.exportPdf()
|
|
652
1009
|
if (!blob) return
|
|
653
1010
|
|
|
654
|
-
|
|
655
|
-
const link = document.createElement('a')
|
|
656
|
-
link.href = url
|
|
657
|
-
link.download = 'demo.pdf'
|
|
658
|
-
link.click()
|
|
659
|
-
URL.revokeObjectURL(url)
|
|
1011
|
+
downloadBlob(blob, 'demo.pdf')
|
|
660
1012
|
}
|
|
661
1013
|
|
|
662
1014
|
async function handleExportImage() {
|
|
@@ -665,8 +1017,7 @@ async function handleExportImage() {
|
|
|
665
1017
|
})
|
|
666
1018
|
if (!blob) return
|
|
667
1019
|
|
|
668
|
-
|
|
669
|
-
window.open(url, '_blank')
|
|
1020
|
+
downloadBlob(blob, 'demo.png')
|
|
670
1021
|
}
|
|
671
1022
|
|
|
672
1023
|
function handleExportHtml() {
|
|
@@ -688,10 +1039,11 @@ import type {
|
|
|
688
1039
|
RichTextEditorCollaborationDocument,
|
|
689
1040
|
RichTextEditorCollaborationProvider,
|
|
690
1041
|
RichTextEditorCollaborationUser,
|
|
691
|
-
RichTextEditorCollaborationOptions,
|
|
692
|
-
RichTextEditorCollectedFilePayload,
|
|
693
|
-
RichTextEditorExportItemKey,
|
|
694
|
-
|
|
1042
|
+
RichTextEditorCollaborationOptions,
|
|
1043
|
+
RichTextEditorCollectedFilePayload,
|
|
1044
|
+
RichTextEditorExportItemKey,
|
|
1045
|
+
RichTextEditorCode,
|
|
1046
|
+
RichTextEditorFilePayload,
|
|
695
1047
|
RichTextEditorImageExportOptions,
|
|
696
1048
|
RichTextEditorImagePayload,
|
|
697
1049
|
RichTextEditorInsertMenuItemKey,
|
|
@@ -734,8 +1086,26 @@ import RichTextEditor, {
|
|
|
734
1086
|
|
|
735
1087
|
### 包内文档
|
|
736
1088
|
|
|
737
|
-
- 使用指南:`docs/usage.md`
|
|
738
|
-
- Yjs 服务示例:`yjs/README.md`
|
|
1089
|
+
- 使用指南:`docs/usage.md`
|
|
1090
|
+
- Yjs 服务示例:`yjs/README.md`
|
|
1091
|
+
|
|
1092
|
+
### 常见问题
|
|
1093
|
+
|
|
1094
|
+
| 问题 | 先检查什么 |
|
|
1095
|
+
| --- | --- |
|
|
1096
|
+
| 接入后没有样式 | 是否引入 `@norio-office/rich-text/style.css`,是否由宿主 CSS 覆盖。 |
|
|
1097
|
+
| 传 `null` 却没有清空 | 传一个包含空段落的 `doc` 对象,见保存示例。 |
|
|
1098
|
+
| 图片/视频选择后无法上传 | 对应 hook 是否传入,是否返回 `{ url: '...' }`,接口地址是否真实可用。 |
|
|
1099
|
+
| 调插入方法后图片跑到段落上方 | 媒体 API 默认在非空文本块前插入;指定位置请先把光标放到目标空段落。 |
|
|
1100
|
+
| 设置了白名单,某些句柄项还在 | 白名单不是完整权限系统;当前句柄插入/转换未统一过滤。 |
|
|
1101
|
+
| 评论按钮没显示或不能发布 | `showComments`、`comments` code、当前评论用户是否配置;预览不能新建评论。 |
|
|
1102
|
+
| 输入 `@` 没有候选 | 正文需要 `mention=true` 及数据源;评论使用独立的数据源;白名单需含 `mention`。 |
|
|
1103
|
+
| 两个窗口内容没有同步 | WebSocket 地址、房间名、`field` 是否一致;白名单是否允许 `collaboration`。 |
|
|
1104
|
+
| 菜单粘贴读不到系统内容 | 需要 HTTPS/localhost 和浏览器权限,可改用 Ctrl/Cmd+V。 |
|
|
1105
|
+
| 导出图片缺少远程图片 | 检查图片服务的 CORS、访问权限及加载情况;截图导出依赖浏览器能读取图片。 |
|
|
1106
|
+
| PDF 里图片或样式不完整 | 当前 PDF 是简化的文字/色块绘制,不嵌入图片;可尝试浏览器打印保存 PDF 并检查结果。 |
|
|
1107
|
+
|
|
1108
|
+
长期保存、重新编辑请使用 JSON,评论列表另存;不要将导出 HTML 或简化 PDF 当成无损导入格式。导出前请在目标浏览器验证媒体加载、字体和排版,尤其是包含复杂块的长文档。
|
|
739
1109
|
|
|
740
1110
|
## English
|
|
741
1111
|
|
|
@@ -753,15 +1123,15 @@ The component styles are published as a separate CSS file. Import it in your app
|
|
|
753
1123
|
import '@norio-office/rich-text/style.css'
|
|
754
1124
|
```
|
|
755
1125
|
|
|
756
|
-
If your package manager does not
|
|
1126
|
+
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.
|
|
757
1127
|
|
|
758
1128
|
```bash
|
|
759
|
-
npm install vue @tiptap/core @tiptap/vue-3 @tiptap/pm @tiptap/starter-kit @tiptap/extension-placeholder @tiptap/extension-code-block @tiptap/extension-code-block-lowlight @tiptap/extension-collaboration @tiptap/extension-collaboration-caret @tiptap/extension-font-family @tiptap/extension-subscript @tiptap/extension-superscript @tiptap/extension-table @tiptap/extension-table-cell @tiptap/extension-table-header @tiptap/extension-table-row @tiptap/extension-task-item @tiptap/extension-task-list @tiptap/extension-text-style @tiptap/extension-underline @tiptap/y-tiptap lowlight y-prosemirror yjs
|
|
1129
|
+
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
|
|
760
1130
|
```
|
|
761
1131
|
|
|
762
1132
|
`html2canvas`, `jspdf`, `katex`, `marked`, and `plyr` are regular dependencies and are installed with the package.
|
|
763
1133
|
|
|
764
|
-
### Quick Start
|
|
1134
|
+
### Quick Start
|
|
765
1135
|
|
|
766
1136
|
```vue
|
|
767
1137
|
<script setup lang="ts">
|
|
@@ -770,7 +1140,7 @@ import type { JSONContent } from '@tiptap/core'
|
|
|
770
1140
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
771
1141
|
import '@norio-office/rich-text/style.css'
|
|
772
1142
|
|
|
773
|
-
const content = ref<JSONContent
|
|
1143
|
+
const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
|
|
774
1144
|
</script>
|
|
775
1145
|
|
|
776
1146
|
<template>
|
|
@@ -788,32 +1158,44 @@ import RichTextEditor from '@norio-office/rich-text'
|
|
|
788
1158
|
|
|
789
1159
|
| Prop | Type | Default | Description |
|
|
790
1160
|
| --- | --- | --- | --- |
|
|
791
|
-
| `modelValue` | `JSONContent \| null` | `null` |
|
|
1161
|
+
| `modelValue` | `JSONContent \| null` | `null` | Tiptap JSON content, not an HTML string. `null` does not clear it. |
|
|
792
1162
|
| `documentName` | `string` | `''` | Base filename for built-in downloads. The component appends `.pdf`, `.png`, or `.html`. |
|
|
793
1163
|
| `editable` | `boolean` | `true` | Enables or disables editing. |
|
|
794
|
-
| `mode` | `'edit' \| 'preview'` | `'edit'` | Edit mode or read-only preview mode. |
|
|
1164
|
+
| `mode` | `'edit' \| 'preview'` | `'edit'` | Edit mode or read-only preview mode. |
|
|
1165
|
+
| `showToolbar` | `boolean` | `true` | Shows the top toolbar in edit mode. Always hidden in preview mode. |
|
|
795
1166
|
| `watermark` | `RichTextEditorWatermarkOptions \| null` | `null` | Text watermark configuration for the document page. No watermark is rendered when omitted or when `text` is empty. |
|
|
796
|
-
| `showOutline` | `boolean` | `true` |
|
|
797
|
-
| `outlinePlacement` | `'left' \| 'right'` | `'right'` | Outline panel placement. |
|
|
798
|
-
| `messages` | `RichTextEditorMessages \| null` | `null` | Overrides built-in UI labels. |
|
|
799
|
-
| `
|
|
800
|
-
| `
|
|
801
|
-
| `
|
|
1167
|
+
| `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. |
|
|
1168
|
+
| `outlinePlacement` | `'left' \| 'right'` | `'right'` | Outline panel placement. |
|
|
1169
|
+
| `messages` | `RichTextEditorMessages \| null` | `null` | Overrides built-in UI labels. |
|
|
1170
|
+
| `featureCodes` | `RichTextEditorCode[] \| null` | `null` | Unified whitelist for controlled entries, with the limitations described below. |
|
|
1171
|
+
| `enabledFeatureItems` | `RichTextEditorFeatureItemKey[] \| null` | `null` | Legacy advanced-feature whitelist, including the legacy `outline` code. |
|
|
1172
|
+
| `enabledExportItems` | `RichTextEditorExportItemKey[] \| null` | `undefined` | Legacy export menu whitelist; used only when `featureCodes` is unset. |
|
|
1173
|
+
| `enabledInsertMenuItems` | `RichTextEditorInsertMenuItemKey[] \| null` | `undefined` | Legacy insert menu whitelist; used only when `featureCodes` is unset. |
|
|
1174
|
+
| `enabledToolbarActions` | `RichTextEditorToolbarActionKey[] \| null` | `undefined` | Legacy toolbar action whitelist; used only when `featureCodes` is unset. |
|
|
802
1175
|
| `placeholder` | `string` | `''` | Placeholder text for empty content. |
|
|
803
1176
|
| `mention` | `boolean` | `false` | Enables `@` mention. Only when `true`, typing `@` opens the candidate popup and `insertMention()` can insert a mention node. |
|
|
804
|
-
| `collaboration` | `RichTextEditorCollaborationOptions \| null` | `
|
|
1177
|
+
| `collaboration` | `RichTextEditorCollaborationOptions \| null` | `undefined` | Yjs collaboration options, used at component creation. |
|
|
805
1178
|
| `uploadImage` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by built-in image pickers and image drops. The editor inserts the returned URL. |
|
|
806
1179
|
| `uploadVideo` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by built-in video pickers and video drops. The editor inserts the returned URL. |
|
|
807
1180
|
| `uploadFile` | `RichTextEditorUploadHook \| null` | `null` | Upload hook required by the local file card picker. The editor inserts the returned URL. |
|
|
808
1181
|
| `onUploadError` | `RichTextEditorUploadErrorHandler \| null` | `null` | Optional callback for upload errors. |
|
|
809
|
-
| `mentionProvider` | `RichTextEditorMentionProvider \| null` | `
|
|
810
|
-
| `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `
|
|
811
|
-
|
|
812
|
-
|
|
1182
|
+
| `mentionProvider` | `RichTextEditorMentionProvider \| null` | `undefined` | Compatibility function prop for loading `@` mention candidates. |
|
|
1183
|
+
| `onMentionSearch` | `RichTextEditorMentionProvider \| null` | `undefined` | Async loader used by function-style `@mention-search`; takes precedence over `mentionProvider`. |
|
|
1184
|
+
| `comments` | `RichTextEditorCommentThread[] \| null` | `null` | Business-managed comment threads, stored separately from document JSON. |
|
|
1185
|
+
| `commentUser` | `RichTextEditorCommentUser \| null` | `null` | Current author; falls back to the collaboration user when available. |
|
|
1186
|
+
| `showComments` | `boolean` | `false` | Shows comment UI; also requires the `comments` code when using a whitelist. |
|
|
1187
|
+
| `commentMention` | `boolean` | `true` | Comment mention switch, independent of the main editor's `mention` prop. |
|
|
1188
|
+
| `uploadCommentImage` | `RichTextEditorUploadHook \| null` | `null` | Comment image upload hook; falls back to `uploadImage`. |
|
|
1189
|
+
| `commentMentionProvider` | `RichTextEditorCommentMentionProvider \| null` | `null` | Separate loader for comment mentions. |
|
|
1190
|
+
| `onCommentMentionSearch` | `RichTextEditorCommentMentionProvider \| null` | `null` | Alternative comment mention loader, taking precedence over `commentMentionProvider`. |
|
|
1191
|
+
|
|
1192
|
+
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.
|
|
1193
|
+
|
|
1194
|
+
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.
|
|
813
1195
|
|
|
814
1196
|
### Watermark
|
|
815
1197
|
|
|
816
|
-
`watermark` is
|
|
1198
|
+
`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.
|
|
817
1199
|
|
|
818
1200
|
```vue
|
|
819
1201
|
<RichTextEditor
|
|
@@ -845,42 +1227,165 @@ When whitelist props are omitted, all built-in options remain enabled. Once a li
|
|
|
845
1227
|
/>
|
|
846
1228
|
```
|
|
847
1229
|
|
|
848
|
-
### Available Keys
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
```ts
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1230
|
+
### Available Keys
|
|
1231
|
+
|
|
1232
|
+
All authorization codes are passed through one `feature-codes` list. Import the `RICH_TEXT_EDITOR_*_CODES` constants to avoid hand-written strings:
|
|
1233
|
+
|
|
1234
|
+
```ts
|
|
1235
|
+
import {
|
|
1236
|
+
RICH_TEXT_EDITOR_EXPORT_CODES,
|
|
1237
|
+
RICH_TEXT_EDITOR_FEATURE_CODES,
|
|
1238
|
+
RICH_TEXT_EDITOR_INSERT_MENU_CODES,
|
|
1239
|
+
RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES,
|
|
1240
|
+
} from '@norio-office/rich-text'
|
|
1241
|
+
|
|
1242
|
+
import type { RichTextEditorCode } from '@norio-office/rich-text'
|
|
1243
|
+
|
|
1244
|
+
const featureCodes: RichTextEditorCode[] = [
|
|
1245
|
+
RICH_TEXT_EDITOR_EXPORT_CODES.pdf,
|
|
1246
|
+
RICH_TEXT_EDITOR_INSERT_MENU_CODES.image,
|
|
1247
|
+
RICH_TEXT_EDITOR_FEATURE_CODES.outlineRight,
|
|
1248
|
+
RICH_TEXT_EDITOR_TOOLBAR_ACTION_CODES.blockquote,
|
|
1249
|
+
]
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
`featureCodes` is one unified authorization pool. Export, insert menu, toolbar, and advanced features are all checked against the same array:
|
|
1253
|
+
|
|
1254
|
+
```vue
|
|
1255
|
+
<RichTextEditor
|
|
1256
|
+
v-model="content"
|
|
1257
|
+
:feature-codes="['pdf', 'image']"
|
|
1258
|
+
/>
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
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.
|
|
1262
|
+
|
|
1263
|
+
Complete authorization code list:
|
|
1264
|
+
|
|
1265
|
+
| Code | Group | Controls | Related props |
|
|
1266
|
+
| --- | --- | --- | --- |
|
|
1267
|
+
| `comments` | Advanced feature | Comment button, right-side comment panel, document comment anchor clicks, and comment interactions. | `showComments`, `comments`, `commentUser` |
|
|
1268
|
+
| `outlineLeft` | Advanced feature | Built-in outline and edge icon toggle on the left. | `showOutline` |
|
|
1269
|
+
| `outlineRight` | Advanced feature | Built-in outline and edge icon toggle on the right. | `showOutline` |
|
|
1270
|
+
| `watermark` | Advanced feature | Page watermark display; current exports remove this layer. | `watermark` |
|
|
1271
|
+
| `collaboration` | Advanced feature | Yjs collaboration and remote cursors; without authorization, the editor initializes in single-user mode. | `collaboration` |
|
|
1272
|
+
| `mention` | Advanced feature | Main editor `@` mention, comment input `@` mention popup, and mention instance methods. | `mention`, `commentMention`, `mentionProvider`, `commentMentionProvider` |
|
|
1273
|
+
| `pdf` | Export | PDF export entry in the export menu. | `documentName` |
|
|
1274
|
+
| `html` | Export | HTML export entry in the export menu. | `documentName` |
|
|
1275
|
+
| `image` | Export + insert | Image export entry in the export menu and image entry in the insert menu. | `uploadImage`, `documentName` |
|
|
1276
|
+
| `print` | Export | Print entry in the bottom status bar. | - |
|
|
1277
|
+
| `video` | Insert menu | Video entry in the insert menu. | `uploadVideo` |
|
|
1278
|
+
| `table` | Insert menu | Table entry in the insert menu. | - |
|
|
1279
|
+
| `local-file` | Insert menu | Local file entry in the insert menu. | `uploadFile` |
|
|
1280
|
+
| `columns` | Insert menu | Columns entry in the insert menu. | - |
|
|
1281
|
+
| `highlight-block` | Insert menu | Highlight block entry in the insert menu. | - |
|
|
1282
|
+
| `date` | Insert menu | Date entry in the insert menu; currently reserved as an authorization code. | - |
|
|
1283
|
+
| `code-block` | Insert menu | Code block entry in the insert menu. | - |
|
|
1284
|
+
| `formula` | Insert menu | Formula entry in the insert menu. | - |
|
|
1285
|
+
| `blockquote` | Insert menu + toolbar | Blockquote entry in the insert menu and blockquote button in the toolbar. | - |
|
|
1286
|
+
| `emoji` | Insert menu + toolbar | Emoji entry in the insert menu and emoji button in the toolbar. | - |
|
|
1287
|
+
| `link` | Insert menu | Link entry in the insert menu. | - |
|
|
1288
|
+
| `divider` | Insert menu | Divider entry in the insert menu. | - |
|
|
1289
|
+
| `countdown` | Insert menu | Countdown entry in the insert menu. | - |
|
|
1290
|
+
| `markdown-import` | Insert menu | Markdown import entry in the insert menu. | - |
|
|
1291
|
+
|
|
1292
|
+
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.
|
|
1293
|
+
|
|
1294
|
+
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.
|
|
1295
|
+
|
|
1296
|
+
### Copy, Cut, And Paste
|
|
1297
|
+
|
|
1298
|
+
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.
|
|
1299
|
+
|
|
1300
|
+
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.
|
|
1301
|
+
|
|
1302
|
+
### Block Alignment And Colors
|
|
1303
|
+
|
|
1304
|
+
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.
|
|
1305
|
+
|
|
1306
|
+
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.
|
|
1307
|
+
|
|
1308
|
+
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.
|
|
1309
|
+
|
|
1310
|
+
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.
|
|
1311
|
+
|
|
1312
|
+
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.
|
|
1313
|
+
|
|
1314
|
+
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.
|
|
1315
|
+
|
|
1316
|
+
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.
|
|
1317
|
+
|
|
1318
|
+
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.
|
|
1319
|
+
|
|
1320
|
+
### Text Selection Bubble
|
|
1321
|
+
|
|
1322
|
+
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.
|
|
1323
|
+
|
|
1324
|
+
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.
|
|
1325
|
+
|
|
1326
|
+
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.
|
|
1327
|
+
|
|
1328
|
+
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.
|
|
1329
|
+
|
|
1330
|
+
### Table Themes
|
|
1331
|
+
|
|
1332
|
+
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.
|
|
1333
|
+
|
|
1334
|
+
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.
|
|
1335
|
+
|
|
1336
|
+
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.
|
|
1337
|
+
|
|
1338
|
+
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.
|
|
1339
|
+
|
|
1340
|
+
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:
|
|
1341
|
+
|
|
1342
|
+
```ts
|
|
1343
|
+
attrs: {
|
|
1344
|
+
tableTheme: { header: '#1670d2', odd: '#e8f2ff', even: '#ffffff' },
|
|
1345
|
+
}
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
Omit `tableTheme` or set it to `null` to retain the default table appearance.
|
|
1349
|
+
|
|
1350
|
+
### Divider Style And Color
|
|
1351
|
+
|
|
1352
|
+
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.
|
|
1353
|
+
|
|
1354
|
+
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:
|
|
1355
|
+
|
|
1356
|
+
```ts
|
|
1357
|
+
{ type: 'horizontalRule', attrs: { lineStyle: 'dashed', lineColor: '#1677ff' } }
|
|
1358
|
+
```
|
|
1359
|
+
|
|
1360
|
+
`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.
|
|
1361
|
+
|
|
1362
|
+
### Highlight Block Colors And Settings
|
|
1363
|
+
|
|
1364
|
+
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.
|
|
1365
|
+
|
|
1366
|
+
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.
|
|
1367
|
+
|
|
1368
|
+
### Quote Colors
|
|
1369
|
+
|
|
1370
|
+
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.
|
|
1371
|
+
|
|
1372
|
+
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.
|
|
1373
|
+
|
|
1374
|
+
### Image Captions And Links
|
|
1375
|
+
|
|
1376
|
+
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.
|
|
1377
|
+
|
|
1378
|
+
Native image dragging, side-handle dragging, and external file upload use matching blue block drop lines with a left-end dot.
|
|
1379
|
+
|
|
1380
|
+
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.
|
|
1381
|
+
|
|
1382
|
+
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.
|
|
1383
|
+
|
|
1384
|
+
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.
|
|
1385
|
+
|
|
1386
|
+
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.
|
|
1387
|
+
|
|
1388
|
+
### Events
|
|
884
1389
|
|
|
885
1390
|
| Event | Payload | Description |
|
|
886
1391
|
| --- | --- | --- |
|
|
@@ -892,7 +1397,8 @@ type RichTextEditorToolbarActionKey = 'blockquote'
|
|
|
892
1397
|
| `upload-error` | `RichTextEditorUploadErrorPayload` | Emitted when an image, video, or file upload hook fails. |
|
|
893
1398
|
| `mention-search` | `RichTextEditorMentionProviderPayload` | Function-style listener syntax for the `onMentionSearch` prop; loads candidates after the user types `@`; may return an array or a `Promise`. |
|
|
894
1399
|
| `mention-item-click` | `RichTextEditorMentionItem` | Emitted when a popup candidate or inserted mention node is clicked. |
|
|
895
|
-
| `mention-submit` | `RichTextEditorMentionItem` | Emitted after the popup `提及` button inserts the selected mention. |
|
|
1400
|
+
| `mention-submit` | `RichTextEditorMentionItem` | Emitted after the popup `提及` button inserts the selected mention. |
|
|
1401
|
+
| `outline-change` | `RichTextEditorOutlineState` | Emits `{ items, activePos }` when the outline or active position changes. |
|
|
896
1402
|
|
|
897
1403
|
`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.
|
|
898
1404
|
|
|
@@ -911,10 +1417,11 @@ import type { JSONContent } from '@tiptap/core'
|
|
|
911
1417
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
912
1418
|
import type {
|
|
913
1419
|
RichTextEditorMentionItem,
|
|
914
|
-
RichTextEditorMentionProviderPayload,
|
|
915
|
-
} from '@norio-office/rich-text'
|
|
916
|
-
|
|
917
|
-
|
|
1420
|
+
RichTextEditorMentionProviderPayload,
|
|
1421
|
+
} from '@norio-office/rich-text'
|
|
1422
|
+
import '@norio-office/rich-text/style.css'
|
|
1423
|
+
|
|
1424
|
+
const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
|
|
918
1425
|
|
|
919
1426
|
const mentionItems: RichTextEditorMentionItem[] = [
|
|
920
1427
|
{ id: 'user-1001', name: 'Cui Guoqiang', type: 1 },
|
|
@@ -928,7 +1435,7 @@ async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload
|
|
|
928
1435
|
await new Promise((resolve) => window.setTimeout(resolve, 120))
|
|
929
1436
|
|
|
930
1437
|
return mentionItems.filter((item) => {
|
|
931
|
-
const matchedType = payload.type === 'all' || item.type === payload.type
|
|
1438
|
+
const matchedType = !payload.type || payload.type === 'all' || item.type === payload.type
|
|
932
1439
|
const matchedKeyword = !query || item.name.toLowerCase().includes(query)
|
|
933
1440
|
return matchedType && matchedKeyword
|
|
934
1441
|
})
|
|
@@ -958,7 +1465,7 @@ Clicking a candidate only selects it and emits `mention-item-click`; clicking th
|
|
|
958
1465
|
|
|
959
1466
|
### Custom Labels
|
|
960
1467
|
|
|
961
|
-
The default UI labels are Chinese.
|
|
1468
|
+
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.
|
|
962
1469
|
|
|
963
1470
|
```vue
|
|
964
1471
|
<RichTextEditor
|
|
@@ -1009,7 +1516,7 @@ Common message keys:
|
|
|
1009
1516
|
| `outline.label` | 大纲 | Outline |
|
|
1010
1517
|
| `outline.collapse` | 收起大纲 | Collapse outline |
|
|
1011
1518
|
| `outline.empty.description` | 对文档内容应用“标题”样式,即可自动生成大纲。 | Apply heading styles to generate an outline. |
|
|
1012
|
-
| `outline.empty.tip` |
|
|
1519
|
+
| `outline.empty.tip` | 点击内容区边缘的大纲图标可以展开大纲。 | Use the outline icon at the content-area edge to open the outline. |
|
|
1013
1520
|
| `status.wordCountUnit` | 个字 | characters |
|
|
1014
1521
|
| `status.presentation.enter` | 演示 | Present |
|
|
1015
1522
|
| `status.presentation.exit` | 退出演示 | Exit presentation |
|
|
@@ -1019,9 +1526,21 @@ Common message keys:
|
|
|
1019
1526
|
| `countdown.settingsTitle` | 倒计时设置 | Countdown settings |
|
|
1020
1527
|
| `formula.insertTitle` | 插入 LaTeX 公式 | Insert LaTeX formula |
|
|
1021
1528
|
|
|
1022
|
-
### Preview Mode
|
|
1023
|
-
|
|
1024
|
-
|
|
1529
|
+
### Preview Mode
|
|
1530
|
+
|
|
1531
|
+
`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.
|
|
1532
|
+
|
|
1533
|
+
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.
|
|
1534
|
+
|
|
1535
|
+
`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.
|
|
1536
|
+
|
|
1537
|
+
For example, hide the top toolbar while keeping the document editable:
|
|
1538
|
+
|
|
1539
|
+
```vue
|
|
1540
|
+
<RichTextEditor v-model="content" :show-toolbar="false" />
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
For read-only preview:
|
|
1025
1544
|
|
|
1026
1545
|
```vue
|
|
1027
1546
|
<RichTextEditor
|
|
@@ -1031,7 +1550,9 @@ Use `mode="preview"` to switch the component into a read-only preview shell. In
|
|
|
1031
1550
|
/>
|
|
1032
1551
|
```
|
|
1033
1552
|
|
|
1034
|
-
On narrow screens, preview mode automatically scales the page canvas so the document stays readable on phones.
|
|
1553
|
+
On narrow screens, preview mode automatically scales the page canvas so the document stays readable on phones.
|
|
1554
|
+
|
|
1555
|
+
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.
|
|
1035
1556
|
|
|
1036
1557
|
### Collaboration
|
|
1037
1558
|
|
|
@@ -1045,7 +1566,7 @@ Minimal integration:
|
|
|
1045
1566
|
|
|
1046
1567
|
```vue
|
|
1047
1568
|
<script setup lang="ts">
|
|
1048
|
-
import { computed, ref } from 'vue'
|
|
1569
|
+
import { computed, onBeforeUnmount, ref } from 'vue'
|
|
1049
1570
|
import * as Y from 'yjs'
|
|
1050
1571
|
import { WebsocketProvider } from 'y-websocket'
|
|
1051
1572
|
import type { JSONContent } from '@tiptap/core'
|
|
@@ -1059,7 +1580,7 @@ const ydoc = new Y.Doc()
|
|
|
1059
1580
|
const user = {
|
|
1060
1581
|
userId: 'user_001',
|
|
1061
1582
|
userName: 'Alice',
|
|
1062
|
-
clientUniqueCode:
|
|
1583
|
+
clientUniqueCode: crypto.randomUUID(),
|
|
1063
1584
|
color: '#3b82f6',
|
|
1064
1585
|
}
|
|
1065
1586
|
|
|
@@ -1084,14 +1605,18 @@ const collaboration = computed(() => ({
|
|
|
1084
1605
|
document: ydoc,
|
|
1085
1606
|
field: 'content',
|
|
1086
1607
|
provider,
|
|
1087
|
-
user: {
|
|
1088
|
-
name: user.userName,
|
|
1089
|
-
color: user.color,
|
|
1090
|
-
userId: user.userId,
|
|
1091
|
-
clientUniqueCode: user.clientUniqueCode,
|
|
1092
|
-
},
|
|
1093
|
-
}))
|
|
1094
|
-
|
|
1608
|
+
user: {
|
|
1609
|
+
name: user.userName,
|
|
1610
|
+
color: user.color,
|
|
1611
|
+
userId: user.userId,
|
|
1612
|
+
clientUniqueCode: user.clientUniqueCode,
|
|
1613
|
+
},
|
|
1614
|
+
}))
|
|
1615
|
+
onBeforeUnmount(() => {
|
|
1616
|
+
provider.destroy()
|
|
1617
|
+
ydoc.destroy()
|
|
1618
|
+
})
|
|
1619
|
+
</script>
|
|
1095
1620
|
|
|
1096
1621
|
<template>
|
|
1097
1622
|
<RichTextEditor
|
|
@@ -1105,7 +1630,8 @@ Rules:
|
|
|
1105
1630
|
|
|
1106
1631
|
- Keep the `WebsocketProvider` room name and query `roomId` the same.
|
|
1107
1632
|
- All clients in the same room must use the same `field`; for normal one-file-one-editor use, keep it as `content`.
|
|
1108
|
-
- If the same user opens two browser windows, each window must use a different `clientUniqueCode`.
|
|
1633
|
+
- If the same user opens two browser windows, each window must use a different `clientUniqueCode`.
|
|
1634
|
+
- 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.
|
|
1109
1635
|
- Remote cursors and selections require both `provider` and `user`.
|
|
1110
1636
|
- 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.
|
|
1111
1637
|
|
|
@@ -1117,10 +1643,10 @@ Initialization:
|
|
|
1117
1643
|
|
|
1118
1644
|
```ts
|
|
1119
1645
|
const collaboration = computed(() => ({
|
|
1120
|
-
document: ydoc,
|
|
1121
|
-
field: 'content',
|
|
1122
|
-
provider,
|
|
1123
|
-
user,
|
|
1646
|
+
document: ydoc,
|
|
1647
|
+
field: 'content',
|
|
1648
|
+
provider,
|
|
1649
|
+
user: { name: user.userName, color: user.color, userId: user.userId },
|
|
1124
1650
|
initializeContent: ownsInitialContent,
|
|
1125
1651
|
initialContent: ownsInitialContent ? businessContent : null,
|
|
1126
1652
|
}))
|
|
@@ -1140,16 +1666,20 @@ The component supports both normal single-user editing and optional Yjs collabor
|
|
|
1140
1666
|
|
|
1141
1667
|
```vue
|
|
1142
1668
|
<script setup lang="ts">
|
|
1143
|
-
import { ref } from 'vue'
|
|
1144
|
-
import * as Y from 'yjs'
|
|
1669
|
+
import { onBeforeUnmount, ref } from 'vue'
|
|
1670
|
+
import * as Y from 'yjs'
|
|
1145
1671
|
import { WebsocketProvider } from 'y-websocket'
|
|
1146
1672
|
import type { JSONContent } from '@tiptap/core'
|
|
1147
1673
|
import { RichTextEditor } from '@norio-office/rich-text'
|
|
1148
1674
|
import '@norio-office/rich-text/style.css'
|
|
1149
1675
|
|
|
1150
1676
|
const ydoc = new Y.Doc()
|
|
1151
|
-
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
1152
|
-
const content = ref<JSONContent | null>(null)
|
|
1677
|
+
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
1678
|
+
const content = ref<JSONContent | null>(null)
|
|
1679
|
+
onBeforeUnmount(() => {
|
|
1680
|
+
provider.destroy()
|
|
1681
|
+
ydoc.destroy()
|
|
1682
|
+
})
|
|
1153
1683
|
</script>
|
|
1154
1684
|
|
|
1155
1685
|
<template>
|
|
@@ -1232,19 +1762,33 @@ Available methods:
|
|
|
1232
1762
|
| `getOutlineItems()` | `RichTextEditorOutlineItem[]` | Returns the current outline items. |
|
|
1233
1763
|
| `getActiveOutlinePos()` | `number \| null` | Returns the document position of the active outline item. |
|
|
1234
1764
|
| `focusOutlineItem(pos)` | `boolean` | Focuses and scrolls to an outline item. |
|
|
1235
|
-
| `onOutlineChange(handler)` | `() => void` | Subscribes to outline changes and returns an unsubscribe function. |
|
|
1236
|
-
|
|
1237
|
-
|
|
1765
|
+
| `onOutlineChange(handler)` | `() => void` | Subscribes to outline changes and returns an unsubscribe function. |
|
|
1766
|
+
| `focusCommentThread(threadId)` | `boolean` | Focuses a comment anchor; returns false if not found. |
|
|
1767
|
+
|
|
1768
|
+
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.
|
|
1238
1769
|
|
|
1239
|
-
|
|
1770
|
+
### External Outline Component
|
|
1771
|
+
|
|
1772
|
+
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.
|
|
1773
|
+
|
|
1774
|
+
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`.
|
|
1240
1775
|
|
|
1241
1776
|
```vue
|
|
1242
1777
|
<script setup lang="ts">
|
|
1243
1778
|
import { ref } from 'vue'
|
|
1244
|
-
import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
|
|
1245
|
-
import type { RichTextEditorInstance } from '@norio-office/rich-text'
|
|
1246
|
-
|
|
1247
|
-
|
|
1779
|
+
import { RichTextEditor, RichTextOutline } from '@norio-office/rich-text'
|
|
1780
|
+
import type { RichTextEditorInstance } from '@norio-office/rich-text'
|
|
1781
|
+
import type { JSONContent } from '@tiptap/core'
|
|
1782
|
+
import '@norio-office/rich-text/style.css'
|
|
1783
|
+
|
|
1784
|
+
const editorRef = ref<RichTextEditorInstance | null>(null)
|
|
1785
|
+
const content = ref<JSONContent>({
|
|
1786
|
+
type: 'doc',
|
|
1787
|
+
content: [
|
|
1788
|
+
{ type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: 'Project Notes' }] },
|
|
1789
|
+
{ type: 'paragraph' },
|
|
1790
|
+
],
|
|
1791
|
+
})
|
|
1248
1792
|
</script>
|
|
1249
1793
|
|
|
1250
1794
|
<template>
|
|
@@ -1276,12 +1820,18 @@ Page-level drag upload routes files by MIME type: `image/*` uses image upload,
|
|
|
1276
1820
|
inserted as a local file card.
|
|
1277
1821
|
|
|
1278
1822
|
```vue
|
|
1279
|
-
<script setup lang="ts">
|
|
1280
|
-
import
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1823
|
+
<script setup lang="ts">
|
|
1824
|
+
import { ref } from 'vue'
|
|
1825
|
+
import type { JSONContent } from '@tiptap/core'
|
|
1826
|
+
import { RichTextEditor } from '@norio-office/rich-text'
|
|
1827
|
+
import type {
|
|
1828
|
+
RichTextEditorUploadInput,
|
|
1829
|
+
RichTextEditorUploadResult,
|
|
1830
|
+
RichTextEditorUploadErrorPayload,
|
|
1831
|
+
} from '@norio-office/rich-text'
|
|
1832
|
+
import '@norio-office/rich-text/style.css'
|
|
1833
|
+
|
|
1834
|
+
const content = ref<JSONContent>({ type: 'doc', content: [{ type: 'paragraph' }] })
|
|
1285
1835
|
|
|
1286
1836
|
async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
|
|
1287
1837
|
const form = new FormData()
|
|
@@ -1297,7 +1847,9 @@ async function uploadToServer(payload: RichTextEditorUploadInput): Promise<RichT
|
|
|
1297
1847
|
throw new Error('Upload failed')
|
|
1298
1848
|
}
|
|
1299
1849
|
|
|
1300
|
-
|
|
1850
|
+
const result = await response.json() as RichTextEditorUploadResult
|
|
1851
|
+
if (!result.url) throw new Error('Upload response is missing url')
|
|
1852
|
+
return result
|
|
1301
1853
|
}
|
|
1302
1854
|
|
|
1303
1855
|
function handleUploadError(payload: RichTextEditorUploadErrorPayload) {
|
|
@@ -1383,19 +1935,31 @@ editorRef.value?.insertLocalFile({
|
|
|
1383
1935
|
})
|
|
1384
1936
|
```
|
|
1385
1937
|
|
|
1386
|
-
### Export Example
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1938
|
+
### Export Example
|
|
1939
|
+
|
|
1940
|
+
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.
|
|
1941
|
+
|
|
1942
|
+
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.
|
|
1943
|
+
|
|
1944
|
+
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.
|
|
1945
|
+
|
|
1946
|
+
```ts
|
|
1947
|
+
function downloadBlob(blob: Blob, name: string) {
|
|
1948
|
+
const url = URL.createObjectURL(blob)
|
|
1949
|
+
const link = document.createElement('a')
|
|
1950
|
+
link.href = url
|
|
1951
|
+
link.download = name
|
|
1952
|
+
document.body.append(link)
|
|
1953
|
+
link.click()
|
|
1954
|
+
link.remove()
|
|
1955
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
async function handleExportPdf() {
|
|
1390
1959
|
const blob = await editorRef.value?.exportPdf()
|
|
1391
1960
|
if (!blob) return
|
|
1392
1961
|
|
|
1393
|
-
|
|
1394
|
-
const link = document.createElement('a')
|
|
1395
|
-
link.href = url
|
|
1396
|
-
link.download = 'demo.pdf'
|
|
1397
|
-
link.click()
|
|
1398
|
-
URL.revokeObjectURL(url)
|
|
1962
|
+
downloadBlob(blob, 'demo.pdf')
|
|
1399
1963
|
}
|
|
1400
1964
|
|
|
1401
1965
|
async function handleExportImage() {
|
|
@@ -1404,8 +1968,7 @@ async function handleExportImage() {
|
|
|
1404
1968
|
})
|
|
1405
1969
|
if (!blob) return
|
|
1406
1970
|
|
|
1407
|
-
|
|
1408
|
-
window.open(url, '_blank')
|
|
1971
|
+
downloadBlob(blob, 'demo.png')
|
|
1409
1972
|
}
|
|
1410
1973
|
|
|
1411
1974
|
function handleExportHtml() {
|
|
@@ -1476,11 +2039,11 @@ import RichTextEditor, {
|
|
|
1476
2039
|
- Usage guide: `docs/usage.md`
|
|
1477
2040
|
- Bundled Yjs server example: `yjs/README.md`
|
|
1478
2041
|
|
|
1479
|
-
## 评论功能对接
|
|
2042
|
+
## 评论功能对接
|
|
1480
2043
|
|
|
1481
2044
|
评论功能由组件负责右侧栏 UI、正文锚点标注、回复交互、图片预览和评论输入框里的 `@` 弹层;评论数据本身由业务系统保存。对接时可以把它理解成:组件抛事件,业务保存数据,然后把新的 `comments` 数组再传回组件。
|
|
1482
2045
|
|
|
1483
|
-
|
|
2046
|
+
下面是一个完整的本地演示,包含:
|
|
1484
2047
|
|
|
1485
2048
|
- 当前评论用户假数据
|
|
1486
2049
|
- 已有评论线程假数据
|
|
@@ -1490,11 +2053,11 @@ import RichTextEditor, {
|
|
|
1490
2053
|
- `comment-submit` 统一通知事件,用来拿到“评论了谁、@了谁、评论内容”等信息
|
|
1491
2054
|
|
|
1492
2055
|
```vue
|
|
1493
|
-
<script setup lang="ts">
|
|
1494
|
-
import { ref } from 'vue'
|
|
1495
|
-
import { RichTextEditor } from '@norio-office/rich-text'
|
|
1496
|
-
import type {
|
|
1497
|
-
RichTextEditorCommentCreatePayload,
|
|
2056
|
+
<script setup lang="ts">
|
|
2057
|
+
import { onBeforeUnmount, ref } from 'vue'
|
|
2058
|
+
import { RichTextEditor } from '@norio-office/rich-text'
|
|
2059
|
+
import type {
|
|
2060
|
+
RichTextEditorCommentCreatePayload,
|
|
1498
2061
|
RichTextEditorCommentDeletePayload,
|
|
1499
2062
|
RichTextEditorCommentMentionProviderPayload,
|
|
1500
2063
|
RichTextEditorCommentReplyPayload,
|
|
@@ -1575,10 +2138,15 @@ const comments = ref<RichTextEditorCommentThread[]>([
|
|
|
1575
2138
|
},
|
|
1576
2139
|
])
|
|
1577
2140
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
2141
|
+
const demoObjectUrls: string[] = []
|
|
2142
|
+
onBeforeUnmount(() => demoObjectUrls.forEach(url => URL.revokeObjectURL(url)))
|
|
2143
|
+
|
|
2144
|
+
async function uploadCommentImage(payload: RichTextEditorUploadInput): Promise<RichTextEditorUploadResult> {
|
|
2145
|
+
// 真实项目里改成上传到文件服务,然后返回 url/name/size/mimeType。
|
|
2146
|
+
const url = URL.createObjectURL(payload.file)
|
|
2147
|
+
demoObjectUrls.push(url)
|
|
2148
|
+
return {
|
|
2149
|
+
url,
|
|
1582
2150
|
name: payload.file.name,
|
|
1583
2151
|
size: payload.file.size,
|
|
1584
2152
|
mimeType: payload.file.type,
|
|
@@ -1713,12 +2281,14 @@ function handleCommentSubmit(payload: RichTextEditorCommentSubmitPayload) {
|
|
|
1713
2281
|
</template>
|
|
1714
2282
|
```
|
|
1715
2283
|
|
|
1716
|
-
### 评论 Props
|
|
2284
|
+
### 评论 Props
|
|
2285
|
+
|
|
2286
|
+
上例数据只在内存中更新,刷新页面会丢失;mock 图片地址只在本次页面生命周期有效。生产中必须换成持久化接口和长期可访问的图片 URL。`comment-submit` 是同一次操作的汇总通知,不要与 `comment-create/reply/update` 再重复写入同一条评论。用户身份和编辑/删除权限仍应由后端校验。
|
|
1717
2287
|
|
|
1718
2288
|
| Prop | 类型 | 说明 |
|
|
1719
2289
|
| --- | --- | --- |
|
|
1720
2290
|
| `comments` | `RichTextEditorCommentThread[] \| null` | 评论线程列表,业务方持久化并回传。 |
|
|
1721
|
-
| `commentUser` | `RichTextEditorCommentUser \| null` |
|
|
2291
|
+
| `commentUser` | `RichTextEditorCommentUser \| null` | 当前评论用户;未传时尝试使用协同用户,两者都不可用时不能新建或回复。 |
|
|
1722
2292
|
| `showComments` | `boolean` | 是否显示评论功能;为 `true` 时显示工具栏评论按钮和右侧评论栏,为 `false` 或不传时隐藏评论入口和评论栏。 |
|
|
1723
2293
|
| `uploadCommentImage` | `RichTextEditorUploadHook \| null` | 评论图片上传 hook,返回结构同 `uploadImage`;未传时会回退使用 `uploadImage`。 |
|
|
1724
2294
|
| `commentMention` | `boolean` | 是否启用评论输入框里的 `@` 提及,默认启用。 |
|