vue-editify 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/examples/App.vue +4 -12
  2. package/lib/components/colors/colors.vue.d.ts +9 -0
  3. package/lib/components/colors/props.d.ts +4 -0
  4. package/lib/components/tooltip/tooltip.vue.d.ts +1 -1
  5. package/lib/core/function.d.ts +112 -64
  6. package/lib/core/rule.d.ts +23 -17
  7. package/lib/core/shortcut.d.ts +36 -0
  8. package/lib/core/tool.d.ts +12 -16
  9. package/lib/editify/editify.vue.d.ts +162 -15
  10. package/lib/editify/props.d.ts +1 -5
  11. package/lib/editify/toolbar/props.d.ts +1 -1
  12. package/lib/editify/toolbar/toolbar.vue.d.ts +3 -3
  13. package/lib/editify.es.js +13660 -12954
  14. package/lib/editify.umd.js +2 -2
  15. package/lib/feature/align.d.ts +0 -14
  16. package/lib/feature/heading.d.ts +0 -14
  17. package/lib/feature/lineHeight.d.ts +0 -14
  18. package/lib/feature/orderList.d.ts +1 -3
  19. package/lib/feature/task.d.ts +0 -14
  20. package/lib/feature/unorderList.d.ts +1 -3
  21. package/lib/index.d.ts +164 -17
  22. package/package.json +2 -2
  23. package/src/components/button/button.vue +3 -3
  24. package/src/components/checkbox/checkbox.vue +1 -1
  25. package/src/components/colors/colors.vue +4 -4
  26. package/src/components/colors/props.ts +6 -1
  27. package/src/components/insertAttachment/insertAttachment.vue +1 -1
  28. package/src/components/insertImage/insertImage.vue +1 -1
  29. package/src/components/insertLink/insertLink.vue +1 -1
  30. package/src/components/insertVideo/insertVideo.vue +1 -1
  31. package/src/components/layer/layer.vue +9 -3
  32. package/src/components/tooltip/tooltip.vue +1 -1
  33. package/src/components/updateLink/updateLink.vue +1 -1
  34. package/src/core/function.ts +873 -491
  35. package/src/core/rule.ts +86 -368
  36. package/src/core/shortcut.ts +386 -0
  37. package/src/core/tool.ts +111 -159
  38. package/src/css/var.less +0 -10
  39. package/src/editify/editify.less +85 -39
  40. package/src/editify/editify.vue +204 -88
  41. package/src/editify/menu/menu.vue +2 -3
  42. package/src/editify/props.ts +1 -6
  43. package/src/editify/toolbar/props.ts +2 -2
  44. package/src/editify/toolbar/toolbar.vue +12 -12
  45. package/src/feature/align.ts +2 -62
  46. package/src/feature/attachment.ts +14 -27
  47. package/src/feature/backColor.ts +2 -1
  48. package/src/feature/bold.ts +1 -1
  49. package/src/feature/code.ts +1 -1
  50. package/src/feature/codeBlock.ts +3 -3
  51. package/src/feature/fontFamily.ts +1 -1
  52. package/src/feature/fontSize.ts +1 -1
  53. package/src/feature/foreColor.ts +2 -1
  54. package/src/feature/formatClear.ts +1 -1
  55. package/src/feature/fullScreen.ts +1 -1
  56. package/src/feature/heading.ts +5 -76
  57. package/src/feature/image.ts +1 -1
  58. package/src/feature/indent.ts +1 -1
  59. package/src/feature/infoBlock.ts +6 -37
  60. package/src/feature/italic.ts +1 -1
  61. package/src/feature/lineHeight.ts +2 -78
  62. package/src/feature/link.ts +1 -1
  63. package/src/feature/mathformula.ts +4 -51
  64. package/src/feature/orderList.ts +168 -37
  65. package/src/feature/quote.ts +3 -3
  66. package/src/feature/redo.ts +1 -1
  67. package/src/feature/separator.ts +1 -1
  68. package/src/feature/sourceView.ts +1 -1
  69. package/src/feature/strikethrough.ts +1 -1
  70. package/src/feature/sub.ts +1 -1
  71. package/src/feature/super.ts +1 -1
  72. package/src/feature/table.ts +3 -3
  73. package/src/feature/task.ts +4 -58
  74. package/src/feature/underline.ts +1 -1
  75. package/src/feature/undo.ts +1 -1
  76. package/src/feature/unorderList.ts +108 -37
  77. package/src/feature/video.ts +1 -1
  78. package/src/icon/iconfont.css +39 -3
  79. package/src/icon/iconfont.ttf +0 -0
  80. package/src/icon/iconfont.woff +0 -0
  81. package/src/index.ts +13 -11
  82. package/src/locale/en_US.ts +109 -110
  83. package/src/locale/zh_CN.ts +11 -12
  84. package/lib/feature/panel.d.ts +0 -18
  85. 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, elementIsPanel } from './function'
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 rowElements
10
- * @param rowNumber
11
- * @param columnNumber
9
+ * @param element
12
10
  */
13
- const autocompleteTableCells = (editor: AlexEditor, rowElements: AlexElement[], rowNumber: number, columnNumber: number) => {
14
- //遍历所有的单元格
15
- AlexElement.flatElements(rowElements).forEach(item => {
16
- if (item.parsedom == 'td' && item.hasMarks()) {
17
- //删除被合并的标识
18
- if (item.marks!['data-editify-merged']) {
19
- delete item.marks!['data-editify-merged']
20
- }
21
- //获取colspan
22
- const colspan = isNaN(Number(item.marks!['colspan'])) ? 1 : Number(item.marks!['colspan'])
23
- //获取rowspan
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
- rowElements.forEach(rowElement => {
87
- //遍历该行的单元格获取总列数
88
- const number = rowElement.children!.length
89
- if (number < columnNumber) {
90
- for (let i = 0; i < columnNumber - number; i++) {
91
- const column = AlexElement.create({
92
- type: 'inblock',
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 updateRangeInPre = (editor: AlexEditor, element: AlexElement, originalTextElements: AlexElement[], newElements: AlexElement[]) => {
204
- if (!editor.range) {
205
- return
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
- if (editor.range.focus.element.getBlock().isEqual(element)) {
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
- * 元素格式化时转换ol和li标签
57
+ * 视频格式化处理
255
58
  * @param editor
256
59
  * @param element
257
60
  */
258
- export const parseList = (editor: AlexEditor, element: AlexElement) => {
259
- //ol标签和ul标签转为div
260
- if (element.parsedom == 'ol' || element.parsedom == 'ul') {
261
- if (element.hasChildren()) {
262
- element.children!.forEach(el => {
263
- const newEl = el.clone()
264
- newEl.parsedom = 'div'
265
- newEl.type = element.type
266
- if (newEl.hasMarks()) {
267
- newEl.marks!['data-editify-list'] = element.parsedom
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
- element.toEmpty()
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 orderdListHandle = (editor: AlexEditor, element: AlexElement) => {
287
- //有序列表的序号处理
288
- if (!element.isEmpty() && elementIsList(element, true)) {
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 commonElementHandle = (editor: AlexEditor, element: AlexElement) => {
309
- //图片、视频和链接设置marks
310
- if (element.parsedom == 'img' || element.parsedom == 'video' || element.parsedom == 'a') {
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
- if (element.parsedom == 'video' || element.parsedom == 'hr') {
323
- const previousElement = editor.getPreviousElement(element)
324
- const newTextElement = editor.getNextElement(element)
325
- //如果不存在前一个元素或者前一个元素不是空白元素则设置空白元素
326
- if (!previousElement || !previousElement.isSpaceText()) {
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
- * 元素格式化时处理表格:th转为td
129
+ * 表格格式化处理
360
130
  * @param editor
361
131
  * @param element
362
132
  */
363
- export const tableThTdHandle = (_editor: AlexEditor, element: AlexElement) => {
364
- if (element.parsedom == 'th') {
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
- * 元素格式化时处理pre,将pre的内容根据语言进行样式处理
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 (<LanguagesItemType>item).value == language
333
+ return (item as LanguagesItemType).value == language
577
334
  }
578
- return <string>item == language
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
- const previousElement = editor.getPreviousElement(element)
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) || elementIsPanel(el) || ['blockquote', 'pre', 'table', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].includes(el.parsedom!)) {
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()