vue-editify 0.2.17 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +4 -12
- package/lib/components/colors/colors.vue.d.ts +9 -0
- package/lib/components/colors/props.d.ts +4 -0
- package/lib/components/tooltip/tooltip.vue.d.ts +1 -1
- package/lib/core/function.d.ts +112 -64
- package/lib/core/rule.d.ts +23 -17
- package/lib/core/shortcut.d.ts +36 -0
- package/lib/core/tool.d.ts +12 -16
- package/lib/editify/editify.vue.d.ts +162 -15
- package/lib/editify/props.d.ts +1 -5
- package/lib/editify/toolbar/props.d.ts +1 -1
- package/lib/editify/toolbar/toolbar.vue.d.ts +3 -3
- package/lib/editify.es.js +13660 -12954
- package/lib/editify.umd.js +2 -2
- package/lib/feature/align.d.ts +0 -14
- package/lib/feature/heading.d.ts +0 -14
- package/lib/feature/lineHeight.d.ts +0 -14
- package/lib/feature/orderList.d.ts +1 -3
- package/lib/feature/task.d.ts +0 -14
- package/lib/feature/unorderList.d.ts +1 -3
- package/lib/index.d.ts +164 -17
- package/package.json +2 -2
- package/src/components/button/button.vue +3 -3
- package/src/components/checkbox/checkbox.vue +1 -1
- package/src/components/colors/colors.vue +4 -4
- package/src/components/colors/props.ts +6 -1
- package/src/components/insertAttachment/insertAttachment.vue +1 -1
- package/src/components/insertImage/insertImage.vue +1 -1
- package/src/components/insertLink/insertLink.vue +1 -1
- package/src/components/insertVideo/insertVideo.vue +1 -1
- package/src/components/layer/layer.vue +9 -3
- package/src/components/tooltip/tooltip.vue +1 -1
- package/src/components/updateLink/updateLink.vue +1 -1
- package/src/core/function.ts +873 -491
- package/src/core/rule.ts +86 -368
- package/src/core/shortcut.ts +386 -0
- package/src/core/tool.ts +111 -159
- package/src/css/var.less +0 -10
- package/src/editify/editify.less +85 -39
- package/src/editify/editify.vue +204 -88
- package/src/editify/menu/menu.vue +2 -3
- package/src/editify/props.ts +1 -6
- package/src/editify/toolbar/props.ts +2 -2
- package/src/editify/toolbar/toolbar.vue +12 -12
- package/src/feature/align.ts +2 -62
- package/src/feature/attachment.ts +14 -27
- package/src/feature/backColor.ts +2 -1
- package/src/feature/bold.ts +1 -1
- package/src/feature/code.ts +1 -1
- package/src/feature/codeBlock.ts +3 -3
- package/src/feature/fontFamily.ts +1 -1
- package/src/feature/fontSize.ts +1 -1
- package/src/feature/foreColor.ts +2 -1
- package/src/feature/formatClear.ts +1 -1
- package/src/feature/fullScreen.ts +1 -1
- package/src/feature/heading.ts +5 -76
- package/src/feature/image.ts +1 -1
- package/src/feature/indent.ts +1 -1
- package/src/feature/infoBlock.ts +6 -37
- package/src/feature/italic.ts +1 -1
- package/src/feature/lineHeight.ts +2 -78
- package/src/feature/link.ts +1 -1
- package/src/feature/mathformula.ts +4 -51
- package/src/feature/orderList.ts +168 -37
- package/src/feature/quote.ts +3 -3
- package/src/feature/redo.ts +1 -1
- package/src/feature/separator.ts +1 -1
- package/src/feature/sourceView.ts +1 -1
- package/src/feature/strikethrough.ts +1 -1
- package/src/feature/sub.ts +1 -1
- package/src/feature/super.ts +1 -1
- package/src/feature/table.ts +3 -3
- package/src/feature/task.ts +4 -58
- package/src/feature/underline.ts +1 -1
- package/src/feature/undo.ts +1 -1
- package/src/feature/unorderList.ts +108 -37
- package/src/feature/video.ts +1 -1
- package/src/icon/iconfont.css +39 -3
- package/src/icon/iconfont.ttf +0 -0
- package/src/icon/iconfont.woff +0 -0
- package/src/index.ts +13 -11
- package/src/locale/en_US.ts +109 -110
- package/src/locale/zh_CN.ts +11 -12
- package/lib/feature/panel.d.ts +0 -18
- package/src/feature/panel.ts +0 -107
package/src/core/rule.ts
CHANGED
@@ -1,313 +1,99 @@
|
|
1
1
|
import { AlexEditor, AlexElement, AlexElementCreateConfigType } from 'alex-editor'
|
2
2
|
import { common as DapCommon, color as DapColor } from 'dap-util'
|
3
3
|
import { LanguagesItemType, getHljsHtml } from '@/hljs'
|
4
|
-
import { getTableSize, getCellSpanNumber, elementIsList, elementIsTask, elementIsAttachment, elementIsMathformula, elementIsInfoBlock,
|
4
|
+
import { getTableSize, getCellSpanNumber, elementIsList, elementIsTask, elementIsAttachment, elementIsMathformula, elementIsInfoBlock, autocompleteTableCells, autoHideMergedTableCells, updateRangeInPre, addSpaceTextToBothSides } from './function'
|
5
5
|
|
6
6
|
/**
|
7
|
-
*
|
7
|
+
* 有序列表和无序列表的格式化处理
|
8
8
|
* @param editor
|
9
|
-
* @param
|
10
|
-
* @param rowNumber
|
11
|
-
* @param columnNumber
|
9
|
+
* @param element
|
12
10
|
*/
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
const rowspan = isNaN(Number(item.marks!['rowspan'])) ? 1 : Number(item.marks!['rowspan'])
|
25
|
-
//针对colspan>1的单元格在后面补全隐藏的单元格
|
26
|
-
if (colspan > 1) {
|
27
|
-
let i = 1
|
28
|
-
//补全的数量小于需要补全的数量并且列总数量小于理论数量
|
29
|
-
while (i < colspan && item.parent!.children!.length < columnNumber) {
|
30
|
-
const column = AlexElement.create({
|
31
|
-
type: 'inblock',
|
32
|
-
parsedom: 'td',
|
33
|
-
marks: {
|
34
|
-
'data-editify-merged': 'true'
|
35
|
-
},
|
36
|
-
children: [
|
37
|
-
{
|
38
|
-
type: 'closed',
|
39
|
-
parsedom: 'br'
|
40
|
-
}
|
41
|
-
]
|
42
|
-
})
|
43
|
-
editor.addElementAfter(column, item)
|
44
|
-
i++
|
45
|
-
}
|
46
|
-
}
|
47
|
-
//针对rowspan>1的单元格在后面的行中对应位置补全隐藏的单元格
|
48
|
-
if (rowspan > 1) {
|
49
|
-
let el = item
|
50
|
-
let i = 1
|
51
|
-
while (i < rowspan && editor.getNextElement(el.parent!) && editor.getNextElement(el.parent!)!.children!.length < columnNumber) {
|
52
|
-
//下一行
|
53
|
-
const nextRow = editor.getNextElement(el.parent!)!
|
54
|
-
//单元格在行中的序列
|
55
|
-
const index = el.parent!.children!.findIndex(item => item.isEqual(el))
|
56
|
-
//下一行对应的单元格
|
57
|
-
const nextCell = nextRow.children![index]
|
58
|
-
//根据当前单元格的跨列数补充符合跨列数的隐藏单元格
|
59
|
-
for (let j = 0; j < colspan; j++) {
|
60
|
-
const column = AlexElement.create({
|
61
|
-
type: 'inblock',
|
62
|
-
parsedom: 'td',
|
63
|
-
marks: {
|
64
|
-
'data-editify-merged': 'true'
|
65
|
-
},
|
66
|
-
children: [
|
67
|
-
{
|
68
|
-
type: 'closed',
|
69
|
-
parsedom: 'br'
|
70
|
-
}
|
71
|
-
]
|
72
|
-
})
|
73
|
-
if (nextCell) {
|
74
|
-
editor.addElementBefore(column, nextCell)
|
75
|
-
} else {
|
76
|
-
editor.addElementTo(column, nextRow, nextRow.children!.length)
|
77
|
-
}
|
78
|
-
}
|
79
|
-
el = nextRow.children![index]
|
80
|
-
i++
|
11
|
+
export const listHandle = (editor: AlexEditor, element: AlexElement) => {
|
12
|
+
//ol标签和ul标签转为div
|
13
|
+
if ((element.parsedom == 'ol' || element.parsedom == 'ul') && element.hasChildren()) {
|
14
|
+
element.children!.forEach(el => {
|
15
|
+
el.type = element.type
|
16
|
+
el.parsedom = 'div'
|
17
|
+
if (el.hasMarks()) {
|
18
|
+
el.marks!['data-editify-list'] = element.parsedom
|
19
|
+
} else {
|
20
|
+
el.marks = {
|
21
|
+
'data-editify-list': element.parsedom
|
81
22
|
}
|
82
23
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
parsedom: 'td',
|
94
|
-
children: [
|
95
|
-
{
|
96
|
-
type: 'closed',
|
97
|
-
parsedom: 'br'
|
98
|
-
}
|
99
|
-
]
|
100
|
-
})
|
101
|
-
editor.addElementTo(column, rowElement, rowElement.children!.length)
|
102
|
-
}
|
103
|
-
}
|
104
|
-
})
|
105
|
-
//获取总行数
|
106
|
-
const length = rowElements.length
|
107
|
-
//判断总行数是否小于实际行数则补全行
|
108
|
-
if (length < rowNumber) {
|
109
|
-
for (let i = 0; i < rowNumber - length; i++) {
|
110
|
-
const children: AlexElementCreateConfigType[] = []
|
111
|
-
for (let j = 0; j < columnNumber; j++) {
|
112
|
-
children.push({
|
113
|
-
type: 'inblock',
|
114
|
-
parsedom: 'td',
|
115
|
-
children: [
|
116
|
-
{
|
117
|
-
type: 'closed',
|
118
|
-
parsedom: 'br'
|
119
|
-
}
|
120
|
-
]
|
121
|
-
})
|
122
|
-
}
|
123
|
-
const row = AlexElement.create({
|
124
|
-
type: 'inblock',
|
125
|
-
parsedom: 'tr',
|
126
|
-
children
|
127
|
-
})
|
128
|
-
rowElements.push(row)
|
129
|
-
}
|
24
|
+
//如果是有序列表添加唯一标记
|
25
|
+
el.marks!['data-editify-element'] = el.key
|
26
|
+
//插入到该元素之前
|
27
|
+
editor.addElementBefore(el, element)
|
28
|
+
})
|
29
|
+
element.children = []
|
30
|
+
}
|
31
|
+
//有序列表和无序列表添加唯一标记
|
32
|
+
if (!element.isEmpty() && (elementIsList(element, true) || elementIsList(element, false))) {
|
33
|
+
element.marks!['data-editify-element'] = element.key
|
130
34
|
}
|
131
35
|
}
|
132
36
|
|
133
37
|
/**
|
134
|
-
*
|
135
|
-
* @param editor
|
136
|
-
* @param rowElements
|
137
|
-
*/
|
138
|
-
const autoHideMergedTableCells = (editor: AlexEditor, rowElements: AlexElement[]) => {
|
139
|
-
const cells = AlexElement.flatElements(rowElements).filter(item => item.parsedom == 'td')
|
140
|
-
cells.forEach(cell => {
|
141
|
-
if (cell.hasMarks() && !cell.marks!['data-editify-merged']) {
|
142
|
-
//获取colspan
|
143
|
-
const colspan = isNaN(Number(cell.marks!['colspan'])) ? 1 : Number(cell.marks!['colspan'])
|
144
|
-
//获取rowspan
|
145
|
-
const rowspan = isNaN(Number(cell.marks!['rowspan'])) ? 1 : Number(cell.marks!['rowspan'])
|
146
|
-
//如果是跨列单元格,隐藏该单元格同行后的colspan-1个单元格
|
147
|
-
if (colspan > 1) {
|
148
|
-
let el = cell
|
149
|
-
let i = 1
|
150
|
-
while (i < colspan) {
|
151
|
-
const nextCell = editor.getNextElement(el)!
|
152
|
-
if (nextCell) {
|
153
|
-
if (nextCell.hasMarks()) {
|
154
|
-
nextCell.marks!['data-editify-merged'] = 'true'
|
155
|
-
} else {
|
156
|
-
nextCell.marks = {
|
157
|
-
'data-editify-merged': 'true'
|
158
|
-
}
|
159
|
-
}
|
160
|
-
el = nextCell
|
161
|
-
i++
|
162
|
-
} else {
|
163
|
-
break
|
164
|
-
}
|
165
|
-
}
|
166
|
-
}
|
167
|
-
//如果是跨行单元格,隐藏该单元格同列后的rowspan-1行单元格
|
168
|
-
if (rowspan > 1) {
|
169
|
-
const index = cell.parent!.children!.findIndex(item => item.isEqual(cell))
|
170
|
-
let el = cell
|
171
|
-
let i = 1
|
172
|
-
while (i < rowspan && el && editor.getNextElement(el.parent!)) {
|
173
|
-
const nextRow = editor.getNextElement(el.parent!)!
|
174
|
-
//根据跨行单元格占据的列数,在后的rowspan-1行中隐藏colspan个单元格
|
175
|
-
for (let j = index; j < index + colspan; j++) {
|
176
|
-
const current = nextRow.children![j]
|
177
|
-
if (current) {
|
178
|
-
if (current.hasMarks()) {
|
179
|
-
current.marks!['data-editify-merged'] = 'true'
|
180
|
-
} else {
|
181
|
-
current.marks = {
|
182
|
-
'data-editify-merged': 'true'
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
}
|
187
|
-
el = nextRow.children![index]
|
188
|
-
i++
|
189
|
-
}
|
190
|
-
}
|
191
|
-
}
|
192
|
-
})
|
193
|
-
}
|
194
|
-
|
195
|
-
/**
|
196
|
-
* 更新代码块内的光标位置
|
38
|
+
* 图片格式化处理
|
197
39
|
* @param editor
|
198
40
|
* @param element
|
199
|
-
* @param originalTextElements
|
200
|
-
* @param newElements
|
201
|
-
* @returns
|
202
41
|
*/
|
203
|
-
const
|
204
|
-
if (!
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
if (editor.range.anchor.element.getBlock().isEqual(element)) {
|
209
|
-
//获取起点所在文本元素的在所有文本元素中的序列
|
210
|
-
const elIndex = originalTextElements.findIndex(el => editor.range!.anchor.element.isEqual(el))
|
211
|
-
//起点在整个代码内容中的位置
|
212
|
-
const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.anchor.offset
|
213
|
-
//获取pre下新的子孙元素中全部的文本元素
|
214
|
-
const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
|
215
|
-
let i = 0
|
216
|
-
let index = 0
|
217
|
-
//遍历
|
218
|
-
while (i < newTextElements.length) {
|
219
|
-
let newIndex = index + newTextElements[i].textContent!.length
|
220
|
-
if (offset >= index && offset <= newIndex) {
|
221
|
-
editor.range.anchor.element = newTextElements[i]
|
222
|
-
editor.range.anchor.offset = offset - index
|
223
|
-
break
|
224
|
-
}
|
225
|
-
i++
|
226
|
-
index = newIndex
|
42
|
+
export const imageHandle = (_editor: AlexEditor, element: AlexElement) => {
|
43
|
+
if (!element.isEmpty() && element.parsedom == 'img') {
|
44
|
+
//添加唯一标记
|
45
|
+
const marks = {
|
46
|
+
'data-editify-element': element.key
|
227
47
|
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
const elIndex = originalTextElements.findIndex(el => editor.range!.focus.element.isEqual(el))
|
233
|
-
//终点在整个代码内容中的位置
|
234
|
-
const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.focus.offset
|
235
|
-
//获取全部的新文本元素
|
236
|
-
const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
|
237
|
-
let i = 0
|
238
|
-
let index = 0
|
239
|
-
//遍历
|
240
|
-
while (i < newTextElements.length) {
|
241
|
-
let newIndex = index + newTextElements[i].textContent!.length
|
242
|
-
if (offset >= index && offset <= newIndex) {
|
243
|
-
editor.range.focus.element = newTextElements[i]
|
244
|
-
editor.range.focus.offset = offset - index
|
245
|
-
break
|
246
|
-
}
|
247
|
-
i++
|
248
|
-
index = newIndex
|
48
|
+
if (element.hasMarks()) {
|
49
|
+
Object.assign(element.marks!, marks)
|
50
|
+
} else {
|
51
|
+
element.marks = marks
|
249
52
|
}
|
250
53
|
}
|
251
54
|
}
|
252
55
|
|
253
56
|
/**
|
254
|
-
*
|
57
|
+
* 视频格式化处理
|
255
58
|
* @param editor
|
256
59
|
* @param element
|
257
60
|
*/
|
258
|
-
export const
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
element.
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
} else {
|
269
|
-
newEl.marks = {
|
270
|
-
'data-editify-list': element.parsedom
|
271
|
-
}
|
272
|
-
}
|
273
|
-
//插入到该元素之前
|
274
|
-
editor.addElementBefore(newEl, element)
|
275
|
-
})
|
61
|
+
export const videoHandle = (editor: AlexEditor, element: AlexElement) => {
|
62
|
+
if (!element.isEmpty() && element.parsedom == 'video') {
|
63
|
+
//添加唯一标记
|
64
|
+
const marks = {
|
65
|
+
'data-editify-element': element.key
|
66
|
+
}
|
67
|
+
if (element.hasMarks()) {
|
68
|
+
Object.assign(element.marks!, marks)
|
69
|
+
} else {
|
70
|
+
element.marks = marks
|
276
71
|
}
|
277
|
-
|
72
|
+
//两侧加上空白元素
|
73
|
+
addSpaceTextToBothSides(editor, element)
|
278
74
|
}
|
279
75
|
}
|
280
76
|
|
281
77
|
/**
|
282
|
-
*
|
78
|
+
* 分隔线格式化处理
|
283
79
|
* @param editor
|
284
80
|
* @param element
|
285
81
|
*/
|
286
|
-
export const
|
287
|
-
|
288
|
-
if (!element.isEmpty() &&
|
289
|
-
|
290
|
-
const previousElement = editor.getPreviousElement(element)
|
291
|
-
//如果前一个元素存在并且也是有序列表
|
292
|
-
if (previousElement && !previousElement.isEmpty() && elementIsList(previousElement, true)) {
|
293
|
-
const previousValue = Number(previousElement.marks!['data-editify-value'])
|
294
|
-
element.marks!['data-editify-value'] = previousValue + 1
|
295
|
-
}
|
296
|
-
//前一个元素不是有序列表,则从0开始
|
297
|
-
else {
|
298
|
-
element.marks!['data-editify-value'] = 1
|
299
|
-
}
|
82
|
+
export const separatorHandle = (editor: AlexEditor, element: AlexElement) => {
|
83
|
+
//两侧加上空白元素
|
84
|
+
if (!element.isEmpty() && element.parsedom == 'hr') {
|
85
|
+
addSpaceTextToBothSides(editor, element)
|
300
86
|
}
|
301
87
|
}
|
302
88
|
|
303
89
|
/**
|
304
|
-
*
|
90
|
+
* 链接格式化处理
|
305
91
|
* @param editor
|
306
92
|
* @param element
|
307
93
|
*/
|
308
|
-
export const
|
309
|
-
|
310
|
-
if (element.
|
94
|
+
export const linkHandle = (_editor: AlexEditor, element: AlexElement) => {
|
95
|
+
//添加唯一标记
|
96
|
+
if (!element.isEmpty() && element.parsedom == 'a') {
|
311
97
|
const marks = {
|
312
98
|
'data-editify-element': element.key
|
313
99
|
}
|
@@ -317,32 +103,16 @@ export const commonElementHandle = (editor: AlexEditor, element: AlexElement) =>
|
|
317
103
|
element.marks = marks
|
318
104
|
}
|
319
105
|
}
|
106
|
+
}
|
320
107
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
const spaceText = AlexElement.getSpaceElement()
|
328
|
-
editor.addElementBefore(spaceText, element)
|
329
|
-
}
|
330
|
-
//如果不存在后一个元素或者后一个元素不是空白元素则设置空白元素
|
331
|
-
if (!newTextElement || !newTextElement.isSpaceText()) {
|
332
|
-
const spaceText = AlexElement.getSpaceElement()
|
333
|
-
editor.addElementAfter(spaceText, element)
|
334
|
-
}
|
335
|
-
//如果光标在视频上则更新光标位置
|
336
|
-
if (editor.range && element.isContains(editor.range.anchor.element)) {
|
337
|
-
editor.range.anchor.moveToEnd(editor.getNextElement(element)!)
|
338
|
-
}
|
339
|
-
if (editor.range && element.isContains(editor.range.focus.element)) {
|
340
|
-
editor.range.focus.moveToEnd(editor.getNextElement(element)!)
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
108
|
+
/**
|
109
|
+
* 行内代码格式化处理
|
110
|
+
* @param _editor
|
111
|
+
* @param element
|
112
|
+
*/
|
113
|
+
export const codeHandle = (_editor: AlexEditor, element: AlexElement) => {
|
344
114
|
//将code转为span[data-editify-code]
|
345
|
-
if (element.parsedom == 'code') {
|
115
|
+
if (!element.isEmpty() && element.parsedom == 'code') {
|
346
116
|
element.parsedom = 'span'
|
347
117
|
const marks = {
|
348
118
|
'data-editify-code': true
|
@@ -356,22 +126,16 @@ export const commonElementHandle = (editor: AlexEditor, element: AlexElement) =>
|
|
356
126
|
}
|
357
127
|
|
358
128
|
/**
|
359
|
-
*
|
129
|
+
* 表格格式化处理
|
360
130
|
* @param editor
|
361
131
|
* @param element
|
362
132
|
*/
|
363
|
-
export const
|
364
|
-
|
133
|
+
export const tableHandle = (editor: AlexEditor, element: AlexElement) => {
|
134
|
+
//处理th转为td
|
135
|
+
if (!element.isEmpty() && element.parsedom == 'th') {
|
365
136
|
element.parsedom = 'td'
|
366
137
|
}
|
367
|
-
|
368
|
-
|
369
|
-
/**
|
370
|
-
* 元素格式化时处理表格:格式化表格
|
371
|
-
* @param editor
|
372
|
-
* @param element
|
373
|
-
*/
|
374
|
-
export const tableFormatHandle = (editor: AlexEditor, element: AlexElement) => {
|
138
|
+
//格式化表格结构和内容
|
375
139
|
if (element.hasChildren() && element.parsedom == 'table') {
|
376
140
|
//设置key到marks上
|
377
141
|
if (element.hasMarks()) {
|
@@ -458,16 +222,8 @@ export const tableFormatHandle = (editor: AlexEditor, element: AlexElement) => {
|
|
458
222
|
//对表格单元格合并状态进行处理
|
459
223
|
autoHideMergedTableCells(editor, rows)
|
460
224
|
}
|
461
|
-
|
462
|
-
|
463
|
-
/**
|
464
|
-
* 元素格式化时处理表格:处理光标在表格隐藏单元格内的情况
|
465
|
-
* @param editor
|
466
|
-
* @param element
|
467
|
-
*/
|
468
|
-
export const tableRangeMergedHandle = (editor: AlexEditor, element: AlexElement) => {
|
469
|
-
//如果元素是被隐藏的单元格,并且光标在该单元格内
|
470
|
-
if (element.parsedom == 'td' && element.hasMarks() && element.marks!['data-editify-merged'] && editor.range) {
|
225
|
+
//处理光标在表格隐藏单元格内的情况
|
226
|
+
if (!element.isEmpty() && element.parsedom == 'td' && element.hasMarks() && element.marks!['data-editify-merged'] && editor.range) {
|
471
227
|
//单元格向左查找设置焦点
|
472
228
|
const queryLeftSetRange = (_element: AlexElement, callback: (ele: AlexElement) => void) => {
|
473
229
|
//是否已查找到
|
@@ -548,7 +304,7 @@ export const tableRangeMergedHandle = (editor: AlexEditor, element: AlexElement)
|
|
548
304
|
}
|
549
305
|
|
550
306
|
/**
|
551
|
-
*
|
307
|
+
* 代码块格式化处理
|
552
308
|
* @param editor
|
553
309
|
* @param element
|
554
310
|
* @param highlight
|
@@ -556,7 +312,8 @@ export const tableRangeMergedHandle = (editor: AlexEditor, element: AlexElement)
|
|
556
312
|
*/
|
557
313
|
export const preHandle = (editor: AlexEditor, element: AlexElement, highlight: boolean, languages: (string | LanguagesItemType)[]) => {
|
558
314
|
//如果是代码块进行处理
|
559
|
-
if (element.parsedom == 'pre') {
|
315
|
+
if (!element.isEmpty() && element.parsedom == 'pre') {
|
316
|
+
//设置key属性
|
560
317
|
const marks = {
|
561
318
|
'data-editify-element': element.key
|
562
319
|
}
|
@@ -573,9 +330,9 @@ export const preHandle = (editor: AlexEditor, element: AlexElement, highlight: b
|
|
573
330
|
//语言类型是否是列表内的
|
574
331
|
const flag = languages.some(item => {
|
575
332
|
if (DapCommon.isObject(item)) {
|
576
|
-
return (
|
333
|
+
return (item as LanguagesItemType).value == language
|
577
334
|
}
|
578
|
-
return
|
335
|
+
return (item as string) == language
|
579
336
|
})
|
580
337
|
//如果不是列表内的则清除
|
581
338
|
if (!flag) {
|
@@ -618,7 +375,7 @@ export const preHandle = (editor: AlexEditor, element: AlexElement, highlight: b
|
|
618
375
|
}
|
619
376
|
|
620
377
|
/**
|
621
|
-
*
|
378
|
+
* 附件格式化处理
|
622
379
|
* @param editor
|
623
380
|
* @param element
|
624
381
|
* @param $editTrans
|
@@ -631,70 +388,31 @@ export const attachmentHandle = (editor: AlexEditor, element: AlexElement, $edit
|
|
631
388
|
if (!element.marks!['data-editify-attachment-name']) {
|
632
389
|
element.marks!['data-editify-attachment-name'] = $editTrans('attachmentDefaultName')
|
633
390
|
}
|
634
|
-
|
635
|
-
|
636
|
-
//后一个元素
|
637
|
-
const newTextElement = editor.getNextElement(element)
|
638
|
-
//如果不存在前一个元素或者前一个元素不是空白元素则设置空白元素
|
639
|
-
if (!previousElement || !previousElement.isSpaceText()) {
|
640
|
-
const spaceText = AlexElement.getSpaceElement()
|
641
|
-
editor.addElementBefore(spaceText, element)
|
642
|
-
}
|
643
|
-
//如果不存在后一个元素或者后一个元素不是空白元素则设置空白元素
|
644
|
-
if (!newTextElement || !newTextElement.isSpaceText()) {
|
645
|
-
const spaceText = AlexElement.getSpaceElement()
|
646
|
-
editor.addElementAfter(spaceText, element)
|
647
|
-
}
|
648
|
-
//如果光标在元素上则更新光标位置
|
649
|
-
if (editor.range && element.isContains(editor.range.anchor.element)) {
|
650
|
-
editor.range.anchor.moveToEnd(editor.getNextElement(element)!)
|
651
|
-
}
|
652
|
-
if (editor.range && element.isContains(editor.range.focus.element)) {
|
653
|
-
editor.range.focus.moveToEnd(editor.getNextElement(element)!)
|
654
|
-
}
|
391
|
+
//两侧设置空白元素
|
392
|
+
addSpaceTextToBothSides(editor, element)
|
655
393
|
}
|
656
394
|
}
|
657
395
|
|
658
396
|
/**
|
659
|
-
*
|
397
|
+
* 数学公式格式化处理
|
660
398
|
* @param editor
|
661
399
|
* @param element
|
662
400
|
*/
|
663
401
|
export const mathformulaHandle = (editor: AlexEditor, element: AlexElement) => {
|
664
|
-
|
402
|
+
//两侧设置空白元素
|
665
403
|
if (!element.isEmpty() && elementIsMathformula(element)) {
|
666
|
-
|
667
|
-
const previousElement = editor.getPreviousElement(element)
|
668
|
-
//后一个元素
|
669
|
-
const newTextElement = editor.getNextElement(element)
|
670
|
-
//如果不存在前一个元素或者前一个元素不是空白元素则设置空白元素
|
671
|
-
if (!previousElement || !previousElement.isSpaceText()) {
|
672
|
-
const spaceText = AlexElement.getSpaceElement()
|
673
|
-
editor.addElementBefore(spaceText, element)
|
674
|
-
}
|
675
|
-
//如果不存在后一个元素或者后一个元素不是空白元素则设置空白元素
|
676
|
-
if (!newTextElement || !newTextElement.isSpaceText()) {
|
677
|
-
const spaceText = AlexElement.getSpaceElement()
|
678
|
-
editor.addElementAfter(spaceText, element)
|
679
|
-
}
|
680
|
-
//如果光标在元素上则更新光标位置
|
681
|
-
if (editor.range && element.isContains(editor.range.anchor.element)) {
|
682
|
-
editor.range.anchor.moveToEnd(editor.getNextElement(element)!)
|
683
|
-
}
|
684
|
-
if (editor.range && element.isContains(editor.range.focus.element)) {
|
685
|
-
editor.range.focus.moveToEnd(editor.getNextElement(element)!)
|
686
|
-
}
|
404
|
+
addSpaceTextToBothSides(editor, element)
|
687
405
|
}
|
688
406
|
}
|
689
407
|
|
690
408
|
/**
|
691
|
-
*
|
409
|
+
* 信息块格式化处理
|
692
410
|
* @param editor
|
693
411
|
* @param element
|
694
412
|
* @param color
|
695
413
|
*/
|
696
414
|
export const infoBlockHandle = (_editor: AlexEditor, element: AlexElement, color: string) => {
|
697
|
-
if (elementIsInfoBlock(element) && color) {
|
415
|
+
if (!element.isEmpty() && elementIsInfoBlock(element) && color) {
|
698
416
|
const parseColor = DapColor.hex2rgb(color)
|
699
417
|
if (element.hasStyles()) {
|
700
418
|
element.styles!['background-color'] = `rgba(${parseColor[0]},${parseColor[1]},${parseColor[2]},0.15)`
|
@@ -709,14 +427,14 @@ export const infoBlockHandle = (_editor: AlexEditor, element: AlexElement, color
|
|
709
427
|
}
|
710
428
|
|
711
429
|
/**
|
712
|
-
*
|
430
|
+
* 一些特殊的内部块元素,转为根级块元素
|
713
431
|
* @param editor
|
714
432
|
* @param element
|
715
433
|
*/
|
716
434
|
export const specialInblockHandle = (editor: AlexEditor, element: AlexElement) => {
|
717
435
|
if (element.hasChildren()) {
|
718
436
|
element.children!.forEach(el => {
|
719
|
-
if (elementIsList(el, true) || elementIsList(el, false) || elementIsTask(el) || elementIsInfoBlock(el) ||
|
437
|
+
if (elementIsList(el, true) || elementIsList(el, false) || elementIsTask(el) || elementIsInfoBlock(el) || ['blockquote', 'pre', 'table', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].includes(el.parsedom!)) {
|
720
438
|
const newEl = el.clone()
|
721
439
|
newEl.type = 'block'
|
722
440
|
const block = element.getBlock()
|