@agilehub/agile-editor 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -9
- package/dist/agile-editor.css +1 -1
- package/dist/agile-editor.js +26042 -30842
- package/package.json +140 -138
package/README.md
CHANGED
|
@@ -1,9 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
# 项目介绍
|
|
2
|
+
|
|
3
|
+
Agile Editor 是一个基于 Vue3 和 Tiptap3 的本土化开源文档编辑器,提供类似于 Microsoft Word 的在线编辑功能和浏览体验。它提供了强大的文档编辑能力和 AI 创作功能,支持分页模式和普通 Web 模式、Markdown 语法、富文本编辑、多种格式的节点插入等功能。
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## 目录结构
|
|
7
|
+
```
|
|
8
|
+
├─assets
|
|
9
|
+
│ ├─icons // svg图标目录
|
|
10
|
+
│ ├─images // 项目用到的图片
|
|
11
|
+
│ └─styles // 项目定义的样式及变量
|
|
12
|
+
├─components // 编辑器区域内容(操作栏/编辑器/底部栏等)
|
|
13
|
+
│ ├─container // 页面布局容器
|
|
14
|
+
│ ├─editor // 内容编辑区域
|
|
15
|
+
│ ├─menus // 菜单
|
|
16
|
+
│ │ ├─block // 鼠标悬停在段落后左侧呈现的快捷菜单
|
|
17
|
+
│ │ ├─bubble // 内容选中后的浮动菜单
|
|
18
|
+
│ │ │ ├─callout // 高亮块
|
|
19
|
+
│ │ │ ├─file // 文件
|
|
20
|
+
│ │ │ ├─image // 图片
|
|
21
|
+
│ │ │ ├─link // 链接
|
|
22
|
+
│ │ │ ├─node // 未细分类的node
|
|
23
|
+
│ │ │ ├─tag // 标签
|
|
24
|
+
│ │ │ ├─text-box // 文本框
|
|
25
|
+
│ │ │ └─webpage // 网页
|
|
26
|
+
│ │ └─toolbar // 顶部菜单栏
|
|
27
|
+
│ │ ├─base // 开始菜单的内容
|
|
28
|
+
│ │ ├─insert // 插入菜单的内容
|
|
29
|
+
│ │ ├─table // 表格菜单的内容
|
|
30
|
+
│ │ ├─tools // 工具菜单的内容
|
|
31
|
+
│ │ └─view // 视图菜单的内容
|
|
32
|
+
│ ├─picker // 公共选择器组件
|
|
33
|
+
│ ├─statusbar // 底部状态栏
|
|
34
|
+
│ └─toolbar // 顶部操作栏
|
|
35
|
+
├─composable //共享工具函数
|
|
36
|
+
├─extensions // 扩展组件
|
|
37
|
+
│ ├─audio // 音频
|
|
38
|
+
│ ├─callout // 高亮块
|
|
39
|
+
│ ├─code-block // 代码块
|
|
40
|
+
│ ├─columns // 分栏
|
|
41
|
+
│ ├─file // 文件
|
|
42
|
+
│ ├─footnotes // 脚注
|
|
43
|
+
│ ├─iframe // iframe
|
|
44
|
+
│ ├─image // 图片
|
|
45
|
+
│ ├─office-paste // 粘贴功能
|
|
46
|
+
│ ├─tag // 标签
|
|
47
|
+
│ ├─text-box // 文本框
|
|
48
|
+
│ └─video // 视频
|
|
49
|
+
├─locales // 语言国际化
|
|
50
|
+
├─options // 编辑器配置
|
|
51
|
+
│ └─config // 默认配置
|
|
52
|
+
└─utils // 工具
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 研发参考
|
|
56
|
+
* [WPS云文档](https://www.kdocs.cn/latest)
|
|
57
|
+
* [飞书云文档](https://my.feishu.cn/drive/home/)
|
|
58
|
+
|
|
59
|
+
## 基本介绍
|
|
60
|
+
### 组件使用说明
|
|
61
|
+
* [TDesign Vue Next for Web](https://tdesign.tencent.com/vue-next/getting-started)
|
|
62
|
+
* [Umo Editor组件列表](https://dev.umodoc.com/cn/docs/editor/components)
|
|
63
|
+
|
|
64
|
+
### 图标使用说明
|
|
65
|
+
|
|
66
|
+
svg参考来源:
|
|
67
|
+
* [iconfont](https://www.iconfont.cn/)
|
|
68
|
+
* [IconPark](https://iconpark.oceanengine.com/official)
|
|
69
|
+
|
|
70
|
+
图标采用svg的方式,在src/assets/icons目录下管理。添加新的图标时,请按照以下步骤进行:
|
|
71
|
+
1. 创建一个名为`iconName`.svg的文件,将图标的svg代码复制到文件中。
|
|
72
|
+
2. 在组件是使用ico="`iconName`"的形式引入图标。
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### 添加菜单
|
|
76
|
+
|
|
77
|
+
#### 添加总菜单
|
|
78
|
+
`src\options\config\index.js`的`toolbar.menus` 添加主菜单的value
|
|
79
|
+
`src\components\toolbar\index.vue`文件的`defaultToolbarMenus`添加数据
|
|
80
|
+
`src\locales\zh-CN.json`添加汉化
|
|
81
|
+
`src\components\toolbar\classic.vue`和`src\components\toolbar\ribbon.vue`添加条件判断`<template v-if="currentMenu === 'tools'">`
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#### 添加子菜单
|
|
85
|
+
在对应的总菜单目录下创建子菜单组件如`src\components\menus\toolbar\review\annotation.vue`
|
|
86
|
+
组件的图标`ico="annotation"`需要在`src\assets\icons`里面添加svg图,然后图标下面的文字`:text="t('review.annotation')"`需要在`src\locales\zh-CN.json`里面的`review.annotation`添加中文汉化
|
|
87
|
+
在`src\components\toolbar\classic.vue`和`src\components\toolbar\ribbon.vue`里面添加组件`<menus-toolbar-tools-annotation />`,
|
|
88
|
+
|
|
89
|
+
###自定义组件
|
|
90
|
+
### 创建组件文件夹
|
|
91
|
+
在`extensions`文件夹创建目录`circle-text`,里面包含index.js和node-view.vue
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## 使用方法
|
|
95
|
+
### 配置文档保存方法
|
|
96
|
+
直接在编辑器配置中定义方法
|
|
97
|
+
const options = {
|
|
98
|
+
async onSave(content, page, document) { },
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### 配置文件上传方法
|
|
103
|
+
直接在编辑器配置中定义方法
|
|
104
|
+
const options = {
|
|
105
|
+
async onFileUpload(file) { },
|
|
106
|
+
onFileDelete(id, url, type) { }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
### 配置修订模式是否开启
|
|
110
|
+
#### 1.直接在编辑器配置extensions中定义,通过enabled的值来定义是否开启
|
|
111
|
+
const options = {
|
|
112
|
+
extensions: [
|
|
113
|
+
TrackChangeExtension.configure({
|
|
114
|
+
enabled: false,
|
|
115
|
+
dataOpUserId: 'u-1001',
|
|
116
|
+
dataOpUserNickname: 'Alice',
|
|
117
|
+
}),
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
#### 2.或者通过编辑器方法
|
|
121
|
+
editor.value?.commands?.toggleTrackChangeStatus?.();
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### 常用方法
|
|
125
|
+
* 获取选取的文本
|
|
126
|
+
``` javascript
|
|
127
|
+
import { getSelectionText } from '@/utils/selection'
|
|
128
|
+
const selectedText = getSelectionText(editor.value)
|
|
129
|
+
```
|
|
130
|
+
`editor.value.getText() / editor.value.getHTML()` 返回的是整篇文档的纯文本/HTML,不是选中内容。
|
|
131
|
+
如果还想要选中的富文本结构(不是纯文本),可以看 `editor.value.state.doc.slice(from, to)` 或 `state.doc.cut(from, to)`,再自行序列化成 HTML。
|
|
132
|
+
|
|
133
|
+
* 关于`editor?.isActive`的用法
|
|
134
|
+
> editor?.isActive 是 Tiptap Editor 实例 上的方法(@tiptap/core 自带),用来判断当前光标/选区处某个节点(node)或标记(mark)是否处于激活状态。项目里 editor 是从 index.vue 通过 inject('editor') 注入的 ref,所以在 <template> 里自动解包写成 editor?.isActive(...),在 <script> 里要写 editor.value?.isActive(...)。
|
|
135
|
+
|
|
136
|
+
它有两种签名:
|
|
137
|
+
```javascript
|
|
138
|
+
isActive(name) // 只按类型名判断
|
|
139
|
+
isActive(name, attributes) // 按类型名 + 属性值判断
|
|
140
|
+
isActive(attributes) // 只按属性值判断(自动遍历所有节点/标记)
|
|
141
|
+
```
|
|
142
|
+
项目里的四种用法
|
|
143
|
+
|
|
144
|
+
1. 只传标记/节点名 —— 判断该类型是否激活
|
|
145
|
+
```javascript
|
|
146
|
+
<!-- bold.vue:7 加粗标记 -->
|
|
147
|
+
:menu-active="editor?.isActive('bold')"
|
|
148
|
+
|
|
149
|
+
<!-- line-height.vue:8 段落/标题节点(配合 && 组合判断) -->
|
|
150
|
+
:disabled="!editor?.isActive('paragraph') && !editor?.isActive('heading')"
|
|
151
|
+
|
|
152
|
+
<!-- table/type.vue:7 是否在表格内 -->
|
|
153
|
+
:disabled="!editor?.isActive('table')"
|
|
154
|
+
```
|
|
155
|
+
2. 传节点名 + 属性对象 —— 判断该节点且属性为指定值
|
|
156
|
+
```javascript
|
|
157
|
+
<!-- heading.vue:94 标题且层级为 level -->
|
|
158
|
+
const heading = (level) => editor.value?.isActive('heading', { level })
|
|
159
|
+
|
|
160
|
+
<!-- line-height.vue:25-26 段落/标题且行高为 item.value -->
|
|
161
|
+
editor.value?.isActive('paragraph', { lineHeight: item.value }) ||
|
|
162
|
+
editor.value?.isActive('heading', { lineHeight: item.value })
|
|
163
|
+
```
|
|
164
|
+
3. 传标记名 + 属性对象 —— 判断自定义标记的某个属性值
|
|
165
|
+
```javascript
|
|
166
|
+
<!-- float-left.vue:5 自定义 float 标记 -->
|
|
167
|
+
:menu-active="editor?.isActive('float', { float: 'left' })"
|
|
168
|
+
|
|
169
|
+
<!-- nowrap.vue:5 自定义 nowrap 标记 -->
|
|
170
|
+
:menu-active="editor?.isActive('nowrap', { 'white-space': 'nowrap' })"
|
|
171
|
+
|
|
172
|
+
<!-- circle-text.vue:8 自定义 circleStyle 标记 -->
|
|
173
|
+
editor?.isActive('circleStyle', { style: circleStyle })
|
|
174
|
+
```
|
|
175
|
+
4. 只传属性对象 —— 不指定类型,让 Tiptap 遍历所有节点/标记,任一命中该属性即激活
|
|
176
|
+
```javascript
|
|
177
|
+
<!-- align-left.vue:8-9 文本对齐或块对齐任一命中 -->
|
|
178
|
+
editor?.isActive({ textAlign: 'left' }) ||
|
|
179
|
+
editor?.isActive({ nodeAlign: 'flex-start' })
|
|
180
|
+
|
|
181
|
+
<!-- word-wrap.vue:24 自动换行属性 -->
|
|
182
|
+
active: editor.value?.isActive({ wordWrap: 'normal' })
|
|
183
|
+
|
|
184
|
+
<!-- writing-mode.vue:19 文字方向 -->
|
|
185
|
+
active: editor.value?.isActive({ writingMode: 'horizontal-tb' })
|
|
186
|
+
```
|
|
187
|
+
典型配套用法
|
|
188
|
+
|
|
189
|
+
isActive 通常和另外两个方法成对出现,构成菜单按钮的状态 + 可用性 + 动作三件套(见 bold.vue):
|
|
190
|
+
|
|
191
|
+
┌──────────────────────────────────────────────────┬─────────────────────────────────────┐
|
|
192
|
+
│ 方法 │ 作用 │
|
|
193
|
+
├──────────────────────────────────────────────────┼─────────────────────────────────────┤
|
|
194
|
+
│ editor?.isActive('bold') │ 高亮当前按钮(:menu-active) │
|
|
195
|
+
├──────────────────────────────────────────────────┼─────────────────────────────────────┤
|
|
196
|
+
│ editor?.can().chain().focus().toggleBold().run() │ 预判该命令此刻能否执行(:disabled) │
|
|
197
|
+
├──────────────────────────────────────────────────┼─────────────────────────────────────┤
|
|
198
|
+
│ editor?.chain().focus().toggleBold().run() │ 点击时真正执行命令(@menu-click) │
|
|
199
|
+
└──────────────────────────────────────────────────┴─────────────────────────────────────┘
|