@agilehub/agile-editor 1.4.1 → 1.5.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.
@@ -1,276 +1,276 @@
1
- # 菜单扩展
2
-
3
- 本文说明如何给 Agile Editor 添加工具栏按钮。先区分三件事:
4
-
5
- - **菜单按钮**:用户看到的图标、文字和点击事件。
6
- - **Tiptap 命令**:按钮点击后执行什么文档操作。
7
- - **Tiptap 扩展**:文档中是否允许出现新的节点类型。
8
-
9
- 只执行已有命令时,只需要添加按钮。需要新的文档节点时,还要开发 Tiptap 扩展,参见 [二次开发指南](./SECONDARY_DEVELOPMENT.md)。
10
-
11
- ## 选择扩展路线
12
-
13
- | 场景 | 推荐路线 |
14
- | --- | --- |
15
- | 业务项目添加“插入审批意见”等按钮 | 使用 `toolbar_*` 插槽 |
16
- | 业务项目打开自己的表单、弹窗或接口 | 插槽组件 + `created` 获取 Editor |
17
- | 修改编辑器自带按钮 | 修改本仓库源码 |
18
- | 新增“业务”一级菜单 | 修改本仓库源码 |
19
-
20
- ## 业务项目添加菜单
21
-
22
- 业务项目不需要修改编辑器源码,也不需要从 npm 包导入 `classic.vue` 或 `ribbon.vue`。
23
-
24
- ### 1. 获取 Editor
25
-
26
- 父组件不能 `inject('editor')`,因为 Editor 由子组件 `<AgileEditor>` 提供。使用 `created` 事件获取:
27
-
28
- ```vue
29
- <script setup lang="ts">
30
- import { shallowRef } from 'vue'
31
- import type { Editor } from '@tiptap/core'
32
-
33
- const editor = shallowRef<Editor>()
34
- </script>
35
-
36
- <template>
37
- <AgileEditor
38
- @created="({ editor: instance }) => (editor = instance)"
39
- />
40
- </template>
41
- ```
42
-
43
- Editor 是复杂类实例,使用 `shallowRef`,不要使用会深层代理对象的 `ref`。
44
-
45
- ### 2. 创建业务按钮
46
-
47
- ```vue
48
- <!-- BusinessInsertButton.vue -->
49
- <template>
50
- <AgileMenuButton
51
- ico="plus"
52
- text="插入提示"
53
- tooltip="插入业务提示内容"
54
- @menu-click="insertNotice"
55
- />
56
- </template>
57
-
58
- <script setup lang="ts">
59
- import type { Editor } from '@tiptap/core'
60
- import { AgileMenuButton } from '@agilehub/agile-editor'
61
-
62
- const props = defineProps<{
63
- editor?: Editor
64
- }>()
65
-
66
- function insertNotice() {
67
- props.editor
68
- ?.chain()
69
- .focus()
70
- .insertContent('<p>这是一段业务提示内容。</p>')
71
- .run()
72
- }
73
- </script>
74
- ```
75
-
76
- `AgileMenuButton` 应位于编辑器工具栏插槽中,因为它依赖编辑器的上下文。
77
-
78
- ### 3. 放入工具栏插槽
79
-
80
- ```vue
81
- <script setup lang="ts">
82
- import { shallowRef } from 'vue'
83
- import { AgileEditor } from '@agilehub/agile-editor'
84
- import type { Editor } from '@tiptap/core'
85
- import BusinessInsertButton from './BusinessInsertButton.vue'
86
-
87
- const editor = shallowRef<Editor>()
88
- </script>
89
-
90
- <template>
91
- <AgileEditor
92
- @created="({ editor: instance }) => (editor = instance)"
93
- >
94
- <template #toolbar_insert="{ toolbarMode }">
95
- <BusinessInsertButton
96
- :editor="editor"
97
- :data-toolbar-mode="toolbarMode"
98
- />
99
- </template>
100
- </AgileEditor>
101
- </template>
102
- ```
103
-
104
- 插槽会提供 `toolbar-mode`,值为 `classic` 或 `ribbon`。按钮需要不同尺寸时可按该值调整。
105
-
106
- ### 可用工具栏插槽
107
-
108
- | 插槽 | 显示位置 |
109
- | --- | --- |
110
- | `toolbar_base` | “开始”工具栏 |
111
- | `toolbar_insert` | “插入”工具栏 |
112
- | `toolbar_table` | “表格”工具栏 |
113
- | `toolbar_tools` | “工具”工具栏 |
114
- | `toolbar_view` | “视图”工具栏 |
115
- | `toolbar_copyediting` | “审阅/校对”工具栏 |
116
- | `toolbar_actions` | 工具栏右侧操作区 |
117
- | `bubble_menu` | 选区或节点浮动菜单 |
118
-
119
- 插槽对应的菜单必须在 `toolbar.menus` 中启用。
120
-
121
- ### 按钮打开业务弹窗
122
-
123
- ```vue
124
- <template>
125
- <AgileMenuButton
126
- ico="edit"
127
- text="业务弹窗"
128
- @menu-click="visible = true"
129
- />
130
- <AgileDialog
131
- v-model:visible="visible"
132
- header="业务设置"
133
- @confirm="confirm"
134
- >
135
- <input v-model="value" />
136
- </AgileDialog>
137
- </template>
138
-
139
- <script setup lang="ts">
140
- import type { Editor } from '@tiptap/core'
141
- import {
142
- AgileDialog,
143
- AgileMenuButton,
144
- } from '@agilehub/agile-editor'
145
-
146
- const props = defineProps<{ editor?: Editor }>()
147
- const visible = ref(false)
148
- const value = ref('')
149
-
150
- function confirm() {
151
- props.editor
152
- ?.chain()
153
- .focus()
154
- .insertContent(`<p>${value.value}</p>`)
155
- .run()
156
- visible.value = false
157
- }
158
- </script>
159
- ```
160
-
161
- 异步确认前应重新检查 Editor 是否仍然可用。不要无条件复用已经失效的旧选区位置。
162
-
163
- ## 源码项目增加菜单
164
-
165
- 以下步骤只适用于修改本仓库源码。
166
-
167
- ### 1. 创建菜单组件
168
-
169
- 在 `src/components/menus/toolbar/insert/` 下创建:
170
-
171
- ```vue
172
- <!-- notice.vue -->
173
- <template>
174
- <menus-button
175
- ico="plus"
176
- text="插入提示"
177
- tooltip="插入业务提示内容"
178
- @menu-click="insertNotice"
179
- />
180
- </template>
181
-
182
- <script setup lang="ts">
183
- const editor = inject('editor')
184
-
185
- function insertNotice() {
186
- editor.value
187
- ?.chain()
188
- .focus()
189
- .insertContent('<p>这是一段业务提示内容。</p>')
190
- .run()
191
- }
192
- </script>
193
- ```
194
-
195
- 仓库内部 SFC 会自动导入 Vue API、composables 和按目录命名的组件。独立 `.ts` 文件仍需显式 import。
196
-
197
- ### 2. 同时修改两种工具栏
198
-
199
- 在 `src/components/toolbar/classic.vue` 和 `src/components/toolbar/ribbon.vue` 的“插入”分支中加入:
200
-
201
- ```vue
202
- <menus-toolbar-insert-notice
203
- v-if="!disableMenu('notice')"
204
- />
205
- ```
206
-
207
- 如果只在一种布局添加,切换到另一种工具栏后按钮会消失。
208
-
209
- ### 3. 新增图标
210
-
211
- 把 SVG 文件放到:
212
-
213
- ```text
214
- src/assets/icons/
215
- ```
216
-
217
- 文件名会注册为:
218
-
219
- ```text
220
- agile-icon-<文件名>
221
- ```
222
-
223
- 组件中通过 `ico="文件名"` 使用。
224
-
225
- ### 4. 测试按钮
226
-
227
- 检查:
228
-
229
- 1. Classic 工具栏可见。
230
- 2. Ribbon 工具栏可见。
231
- 3. 菜单禁用配置有效。
232
- 4. 只读模式下按钮不可执行修改。
233
- 5. 点击后插入位置和撤销记录正确。
234
-
235
- ## 源码项目增加一级菜单
236
-
237
- 以新增“业务”菜单为例:
238
-
239
- 1. 在 `src/options/config/index.ts` 的 `toolbar.menus` 中加入 `business`。
240
- 2. 在 `src/components/toolbar/index.vue` 的菜单名称映射中加入 `business`。
241
- 3. 在 `src/locales/zh-CN.json` 和 `src/locales/en-US.json` 中加入菜单名称。
242
- 4. 在 `classic.vue` 和 `ribbon.vue` 增加 `currentMenu === 'business'` 分支。
243
- 5. 为两种布局增加 `toolbar_business` 插槽。
244
- 6. 检查 `src/options/schema.ts` 对 `toolbar.menus` 的校验。
245
- 7. 测试切换、隐藏、插槽和两种布局。
246
-
247
- 业务项目仅传入一个任意菜单名不会自动创建新选项卡,自定义一级菜单必须修改源码。
248
-
249
- ## 按钮和命令的关系
250
-
251
- ```text
252
- 菜单按钮
253
- → 执行已有 Tiptap 命令或业务函数
254
- → 修改文档
255
- → renderHTML / NodeView 负责显示
256
- → 保存时序列化
257
- ```
258
-
259
- 注册 Tiptap 扩展不会自动创建按钮;添加按钮也不会自动允许新的节点类型。
260
-
261
- ## 常见问题
262
-
263
- | 问题 | 检查 |
264
- | --- | --- |
265
- | 按钮看不到 | 菜单是否启用、插槽是否正确、两种工具栏是否都已修改 |
266
- | 点击没有反应 | Editor 是否已初始化、命令是否存在、是否只读 |
267
- | 图标不显示 | SVG 文件名、`ico` 值和 sprite symbol |
268
- | 业务按钮无法获取 Editor | 使用 `created` 事件,不要在父组件 inject |
269
- | 按钮只在一种布局出现 | 同时检查 classic 和 ribbon |
270
- | 扩展注册后仍无按钮 | `extensions` 只注册文档能力 |
271
-
272
- ## 继续阅读
273
-
274
- - [外部组件接入](./custom-components.md)
275
- - [二次开发指南](./SECONDARY_DEVELOPMENT.md)
276
- - [组件方法与事件](./api.md)
1
+ # 菜单扩展
2
+
3
+ 本文说明如何给 Agile Editor 添加工具栏按钮。先区分三件事:
4
+
5
+ - **菜单按钮**:用户看到的图标、文字和点击事件。
6
+ - **Tiptap 命令**:按钮点击后执行什么文档操作。
7
+ - **Tiptap 扩展**:文档中是否允许出现新的节点类型。
8
+
9
+ 只执行已有命令时,只需要添加按钮。需要新的文档节点时,还要开发 Tiptap 扩展,参见 [二次开发指南](./SECONDARY_DEVELOPMENT.md)。
10
+
11
+ ## 选择扩展路线
12
+
13
+ | 场景 | 推荐路线 |
14
+ | --- | --- |
15
+ | 业务项目添加“插入审批意见”等按钮 | 使用 `toolbar_*` 插槽 |
16
+ | 业务项目打开自己的表单、弹窗或接口 | 插槽组件 + `created` 获取 Editor |
17
+ | 修改编辑器自带按钮 | 修改本仓库源码 |
18
+ | 新增“业务”一级菜单 | 修改本仓库源码 |
19
+
20
+ ## 业务项目添加菜单
21
+
22
+ 业务项目不需要修改编辑器源码,也不需要从 npm 包导入 `classic.vue` 或 `ribbon.vue`。
23
+
24
+ ### 1. 获取 Editor
25
+
26
+ 父组件不能 `inject('editor')`,因为 Editor 由子组件 `<AgileEditor>` 提供。使用 `created` 事件获取:
27
+
28
+ ```vue
29
+ <script setup lang="ts">
30
+ import { shallowRef } from 'vue'
31
+ import type { Editor } from '@tiptap/core'
32
+
33
+ const editor = shallowRef<Editor>()
34
+ </script>
35
+
36
+ <template>
37
+ <AgileEditor
38
+ @created="({ editor: instance }) => (editor = instance)"
39
+ />
40
+ </template>
41
+ ```
42
+
43
+ Editor 是复杂类实例,使用 `shallowRef`,不要使用会深层代理对象的 `ref`。
44
+
45
+ ### 2. 创建业务按钮
46
+
47
+ ```vue
48
+ <!-- BusinessInsertButton.vue -->
49
+ <template>
50
+ <AgileMenuButton
51
+ ico="plus"
52
+ text="插入提示"
53
+ tooltip="插入业务提示内容"
54
+ @menu-click="insertNotice"
55
+ />
56
+ </template>
57
+
58
+ <script setup lang="ts">
59
+ import type { Editor } from '@tiptap/core'
60
+ import { AgileMenuButton } from '@agilehub/agile-editor'
61
+
62
+ const props = defineProps<{
63
+ editor?: Editor
64
+ }>()
65
+
66
+ function insertNotice() {
67
+ props.editor
68
+ ?.chain()
69
+ .focus()
70
+ .insertContent('<p>这是一段业务提示内容。</p>')
71
+ .run()
72
+ }
73
+ </script>
74
+ ```
75
+
76
+ `AgileMenuButton` 应位于编辑器工具栏插槽中,因为它依赖编辑器的上下文。
77
+
78
+ ### 3. 放入工具栏插槽
79
+
80
+ ```vue
81
+ <script setup lang="ts">
82
+ import { shallowRef } from 'vue'
83
+ import { AgileEditor } from '@agilehub/agile-editor'
84
+ import type { Editor } from '@tiptap/core'
85
+ import BusinessInsertButton from './BusinessInsertButton.vue'
86
+
87
+ const editor = shallowRef<Editor>()
88
+ </script>
89
+
90
+ <template>
91
+ <AgileEditor
92
+ @created="({ editor: instance }) => (editor = instance)"
93
+ >
94
+ <template #toolbar_insert="{ toolbarMode }">
95
+ <BusinessInsertButton
96
+ :editor="editor"
97
+ :data-toolbar-mode="toolbarMode"
98
+ />
99
+ </template>
100
+ </AgileEditor>
101
+ </template>
102
+ ```
103
+
104
+ 插槽会提供 `toolbar-mode`,值为 `classic` 或 `ribbon`。按钮需要不同尺寸时可按该值调整。
105
+
106
+ ### 可用工具栏插槽
107
+
108
+ | 插槽 | 显示位置 |
109
+ | --- | --- |
110
+ | `toolbar_base` | “开始”工具栏 |
111
+ | `toolbar_insert` | “插入”工具栏 |
112
+ | `toolbar_table` | “表格”工具栏 |
113
+ | `toolbar_tools` | “工具”工具栏 |
114
+ | `toolbar_view` | “视图”工具栏 |
115
+ | `toolbar_copyediting` | “审阅/校对”工具栏 |
116
+ | `toolbar_actions` | 工具栏右侧操作区 |
117
+ | `bubble_menu` | 选区或节点浮动菜单 |
118
+
119
+ 插槽对应的菜单必须在 `toolbar.menus` 中启用。
120
+
121
+ ### 按钮打开业务弹窗
122
+
123
+ ```vue
124
+ <template>
125
+ <AgileMenuButton
126
+ ico="edit"
127
+ text="业务弹窗"
128
+ @menu-click="visible = true"
129
+ />
130
+ <AgileDialog
131
+ v-model:visible="visible"
132
+ header="业务设置"
133
+ @confirm="confirm"
134
+ >
135
+ <input v-model="value" />
136
+ </AgileDialog>
137
+ </template>
138
+
139
+ <script setup lang="ts">
140
+ import type { Editor } from '@tiptap/core'
141
+ import {
142
+ AgileDialog,
143
+ AgileMenuButton,
144
+ } from '@agilehub/agile-editor'
145
+
146
+ const props = defineProps<{ editor?: Editor }>()
147
+ const visible = ref(false)
148
+ const value = ref('')
149
+
150
+ function confirm() {
151
+ props.editor
152
+ ?.chain()
153
+ .focus()
154
+ .insertContent(`<p>${value.value}</p>`)
155
+ .run()
156
+ visible.value = false
157
+ }
158
+ </script>
159
+ ```
160
+
161
+ 异步确认前应重新检查 Editor 是否仍然可用。不要无条件复用已经失效的旧选区位置。
162
+
163
+ ## 源码项目增加菜单
164
+
165
+ 以下步骤只适用于修改本仓库源码。
166
+
167
+ ### 1. 创建菜单组件
168
+
169
+ 在 `src/components/menus/toolbar/insert/` 下创建:
170
+
171
+ ```vue
172
+ <!-- notice.vue -->
173
+ <template>
174
+ <menus-button
175
+ ico="plus"
176
+ text="插入提示"
177
+ tooltip="插入业务提示内容"
178
+ @menu-click="insertNotice"
179
+ />
180
+ </template>
181
+
182
+ <script setup lang="ts">
183
+ const editor = inject('editor')
184
+
185
+ function insertNotice() {
186
+ editor.value
187
+ ?.chain()
188
+ .focus()
189
+ .insertContent('<p>这是一段业务提示内容。</p>')
190
+ .run()
191
+ }
192
+ </script>
193
+ ```
194
+
195
+ 仓库内部 SFC 会自动导入 Vue API、composables 和按目录命名的组件。独立 `.ts` 文件仍需显式 import。
196
+
197
+ ### 2. 同时修改两种工具栏
198
+
199
+ 在 `src/components/toolbar/classic.vue` 和 `src/components/toolbar/ribbon.vue` 的“插入”分支中加入:
200
+
201
+ ```vue
202
+ <menus-toolbar-insert-notice
203
+ v-if="!disableMenu('notice')"
204
+ />
205
+ ```
206
+
207
+ 如果只在一种布局添加,切换到另一种工具栏后按钮会消失。
208
+
209
+ ### 3. 新增图标
210
+
211
+ 把 SVG 文件放到:
212
+
213
+ ```text
214
+ src/assets/icons/
215
+ ```
216
+
217
+ 文件名会注册为:
218
+
219
+ ```text
220
+ agile-icon-<文件名>
221
+ ```
222
+
223
+ 组件中通过 `ico="文件名"` 使用。
224
+
225
+ ### 4. 测试按钮
226
+
227
+ 检查:
228
+
229
+ 1. Classic 工具栏可见。
230
+ 2. Ribbon 工具栏可见。
231
+ 3. 菜单禁用配置有效。
232
+ 4. 只读模式下按钮不可执行修改。
233
+ 5. 点击后插入位置和撤销记录正确。
234
+
235
+ ## 源码项目增加一级菜单
236
+
237
+ 以新增“业务”菜单为例:
238
+
239
+ 1. 在 `src/options/config/index.ts` 的 `toolbar.menus` 中加入 `business`。
240
+ 2. 在 `src/components/toolbar/index.vue` 的菜单名称映射中加入 `business`。
241
+ 3. 在 `src/locales/zh-CN.json` 和 `src/locales/en-US.json` 中加入菜单名称。
242
+ 4. 在 `classic.vue` 和 `ribbon.vue` 增加 `currentMenu === 'business'` 分支。
243
+ 5. 为两种布局增加 `toolbar_business` 插槽。
244
+ 6. 检查 `src/options/schema.ts` 对 `toolbar.menus` 的校验。
245
+ 7. 测试切换、隐藏、插槽和两种布局。
246
+
247
+ 业务项目仅传入一个任意菜单名不会自动创建新选项卡,自定义一级菜单必须修改源码。
248
+
249
+ ## 按钮和命令的关系
250
+
251
+ ```text
252
+ 菜单按钮
253
+ → 执行已有 Tiptap 命令或业务函数
254
+ → 修改文档
255
+ → renderHTML / NodeView 负责显示
256
+ → 保存时序列化
257
+ ```
258
+
259
+ 注册 Tiptap 扩展不会自动创建按钮;添加按钮也不会自动允许新的节点类型。
260
+
261
+ ## 常见问题
262
+
263
+ | 问题 | 检查 |
264
+ | --- | --- |
265
+ | 按钮看不到 | 菜单是否启用、插槽是否正确、两种工具栏是否都已修改 |
266
+ | 点击没有反应 | Editor 是否已初始化、命令是否存在、是否只读 |
267
+ | 图标不显示 | SVG 文件名、`ico` 值和 sprite symbol |
268
+ | 业务按钮无法获取 Editor | 使用 `created` 事件,不要在父组件 inject |
269
+ | 按钮只在一种布局出现 | 同时检查 classic 和 ribbon |
270
+ | 扩展注册后仍无按钮 | `extensions` 只注册文档能力 |
271
+
272
+ ## 继续阅读
273
+
274
+ - [外部组件接入](./custom-components.md)
275
+ - [二次开发指南](./SECONDARY_DEVELOPMENT.md)
276
+ - [组件方法与事件](./api.md)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@agilehub/agile-editor",
3
- "version": "1.4.1",
4
- "description": "",
5
- "lastUpdate": "2026-07-22",
3
+ "version": "1.5.0",
4
+ "description": "Rich text editor based on Vue 3 and Tiptap 3",
5
+ "author": "lytdev <lytdev@outlook.com>",
6
6
  "keywords": [
7
7
  "docs editor",
8
8
  "document editor",
@@ -18,9 +18,13 @@
18
18
  "web office",
19
19
  "word editor"
20
20
  ],
21
- "license": "MIT",
22
- "author": {
23
- "name": "agilehub"
21
+ "license": "Apache 2.0",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/lytdev/agile-editor.git"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
24
28
  },
25
29
  "files": [
26
30
  "dist",
@@ -37,9 +41,6 @@
37
41
  "import": "./dist/agile-editor.css"
38
42
  }
39
43
  },
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
44
  "scripts": {
44
45
  "build": "vue-tsc --noEmit && vite build && vue-tsc -p tsconfig.types.json",
45
46
  "typecheck": "vue-tsc --noEmit",
@@ -51,7 +52,7 @@
51
52
  "prepublishOnly": "npm run build"
52
53
  },
53
54
  "dependencies": {
54
- "@agilehub/docx-converter": "1.1.0",
55
+ "@agilehub/docx-converter": "1.2.0",
55
56
  "@agilehub/latex-formula": "1.2.0",
56
57
  "@eslint/object-schema": "3.0.5",
57
58
  "@floating-ui/dom": "1.8.0",