vue-editify 0.2.13 → 0.2.15

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 (190) hide show
  1. package/examples/App.vue +49 -67
  2. package/lib/components/button/button.vue.d.ts +62 -60
  3. package/lib/components/button/index.d.ts +4 -0
  4. package/lib/components/button/props.d.ts +12 -1
  5. package/lib/components/checkbox/checkbox.vue.d.ts +9 -9
  6. package/lib/components/checkbox/index.d.ts +4 -0
  7. package/lib/components/checkbox/props.d.ts +2 -2
  8. package/lib/components/colors/colors.vue.d.ts +4 -4
  9. package/lib/components/colors/index.d.ts +4 -0
  10. package/lib/components/colors/props.d.ts +2 -2
  11. package/lib/components/icon/index.d.ts +4 -0
  12. package/lib/components/insertAttachment/index.d.ts +4 -0
  13. package/lib/{plugins/attachment → components}/insertAttachment/insertAttachment.vue.d.ts +3 -3
  14. package/lib/{plugins/attachment → components}/insertAttachment/props.d.ts +1 -1
  15. package/lib/components/insertImage/index.d.ts +4 -0
  16. package/lib/components/insertImage/insertImage.vue.d.ts +3 -3
  17. package/lib/components/insertImage/props.d.ts +1 -1
  18. package/lib/components/insertLink/index.d.ts +4 -0
  19. package/lib/components/insertLink/insertLink.vue.d.ts +6 -6
  20. package/lib/components/insertLink/props.d.ts +3 -3
  21. package/lib/components/insertMathformula/index.d.ts +4 -0
  22. package/lib/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue.d.ts +3 -3
  23. package/lib/{plugins/mathformula → components}/insertMathformula/props.d.ts +2 -2
  24. package/lib/components/insertTable/index.d.ts +4 -0
  25. package/lib/components/insertTable/insertTable.vue.d.ts +3 -3
  26. package/lib/components/insertTable/props.d.ts +2 -2
  27. package/lib/components/insertVideo/index.d.ts +4 -0
  28. package/lib/components/insertVideo/insertVideo.vue.d.ts +3 -3
  29. package/lib/components/insertVideo/props.d.ts +1 -1
  30. package/lib/components/layer/index.d.ts +4 -0
  31. package/lib/components/layer/layer.vue.d.ts +10 -8
  32. package/lib/components/tooltip/index.d.ts +4 -0
  33. package/lib/components/tooltip/tooltip.vue.d.ts +6 -4
  34. package/lib/components/triangle/index.d.ts +4 -0
  35. package/lib/components/triangle/triangle.vue.d.ts +1 -1
  36. package/lib/components/updateLink/index.d.ts +4 -0
  37. package/lib/components/updateLink/props.d.ts +17 -0
  38. package/lib/components/updateLink/updateLink.vue.d.ts +38 -0
  39. package/lib/core/function.d.ts +113 -36
  40. package/lib/core/rule.d.ts +20 -0
  41. package/lib/core/tool.d.ts +36 -34
  42. package/lib/editify/editify.vue.d.ts +86 -53
  43. package/lib/editify/menu/index.d.ts +4 -0
  44. package/lib/{components → editify}/menu/menu.vue.d.ts +3 -4
  45. package/lib/{components → editify}/menu/props.d.ts +1 -1
  46. package/lib/editify/props.d.ts +3 -7
  47. package/lib/editify/toolbar/index.d.ts +4 -0
  48. package/lib/{components → editify}/toolbar/props.d.ts +2 -2
  49. package/lib/{components → editify}/toolbar/toolbar.vue.d.ts +53 -53
  50. package/lib/editify.es.js +8879 -7668
  51. package/lib/editify.umd.js +2 -2
  52. package/lib/feature/align.d.ts +32 -0
  53. package/lib/feature/attachment.d.ts +18 -0
  54. package/lib/feature/backColor.d.ts +32 -0
  55. package/lib/feature/bold.d.ts +32 -0
  56. package/lib/feature/code.d.ts +32 -0
  57. package/lib/feature/codeBlock.d.ts +32 -0
  58. package/lib/feature/fontFamily.d.ts +32 -0
  59. package/lib/feature/fontSize.d.ts +32 -0
  60. package/lib/feature/foreColor.d.ts +32 -0
  61. package/lib/feature/formatClear.d.ts +32 -0
  62. package/lib/feature/fullScreen.d.ts +18 -0
  63. package/lib/feature/heading.d.ts +32 -0
  64. package/lib/feature/image.d.ts +32 -0
  65. package/lib/feature/indent.d.ts +18 -0
  66. package/lib/feature/infoBlock.d.ts +18 -0
  67. package/lib/feature/italic.d.ts +32 -0
  68. package/lib/feature/lineHeight.d.ts +32 -0
  69. package/lib/feature/link.d.ts +26 -0
  70. package/lib/feature/mathformula.d.ts +22 -0
  71. package/lib/feature/orderList.d.ts +32 -0
  72. package/lib/feature/panel.d.ts +18 -0
  73. package/lib/feature/quote.d.ts +18 -0
  74. package/lib/feature/redo.d.ts +18 -0
  75. package/lib/feature/separator.d.ts +18 -0
  76. package/lib/feature/sourceView.d.ts +18 -0
  77. package/lib/feature/strikethrough.d.ts +32 -0
  78. package/lib/feature/sub.d.ts +32 -0
  79. package/lib/feature/super.d.ts +32 -0
  80. package/lib/feature/table.d.ts +32 -0
  81. package/lib/feature/task.d.ts +32 -0
  82. package/lib/feature/underline.d.ts +32 -0
  83. package/lib/feature/undo.d.ts +18 -0
  84. package/lib/feature/unorderList.d.ts +32 -0
  85. package/lib/feature/video.d.ts +38 -0
  86. package/lib/index.d.ts +104 -69
  87. package/package.json +5 -5
  88. package/src/components/button/button.vue +21 -24
  89. package/src/components/button/index.ts +5 -0
  90. package/src/components/button/props.ts +14 -1
  91. package/src/components/checkbox/checkbox.vue +1 -1
  92. package/src/components/checkbox/index.ts +5 -0
  93. package/src/components/checkbox/props.ts +1 -1
  94. package/src/components/colors/colors.vue +3 -3
  95. package/src/components/colors/index.ts +5 -0
  96. package/src/components/colors/props.ts +2 -2
  97. package/src/components/icon/index.ts +5 -0
  98. package/src/components/insertAttachment/index.ts +5 -0
  99. package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.vue +4 -2
  100. package/src/{plugins/attachment → components}/insertAttachment/props.ts +1 -1
  101. package/src/components/insertImage/index.ts +5 -0
  102. package/src/components/insertImage/insertImage.vue +5 -5
  103. package/src/components/insertImage/props.ts +1 -1
  104. package/src/components/insertLink/index.ts +5 -0
  105. package/src/components/insertLink/insertLink.vue +10 -10
  106. package/src/components/insertLink/props.ts +3 -3
  107. package/src/components/insertMathformula/index.ts +5 -0
  108. package/src/{plugins/mathformula → components}/insertMathformula/props.ts +2 -2
  109. package/src/components/insertTable/index.ts +5 -0
  110. package/src/components/insertTable/props.ts +2 -2
  111. package/src/components/insertVideo/index.ts +5 -0
  112. package/src/components/insertVideo/insertVideo.vue +2 -2
  113. package/src/components/insertVideo/props.ts +1 -1
  114. package/src/components/layer/index.ts +5 -0
  115. package/src/components/layer/layer.vue +42 -4
  116. package/src/components/tooltip/index.ts +5 -0
  117. package/src/components/tooltip/tooltip.vue +1 -1
  118. package/src/components/triangle/index.ts +5 -0
  119. package/src/components/triangle/triangle.vue +1 -1
  120. package/src/components/updateLink/index.ts +5 -0
  121. package/src/components/updateLink/props.ts +21 -0
  122. package/src/components/{toolbar/toolbar.less → updateLink/updateLink.less} +4 -20
  123. package/src/components/updateLink/updateLink.vue +74 -0
  124. package/src/core/function.ts +289 -97
  125. package/src/core/rule.ts +96 -7
  126. package/src/core/tool.ts +234 -78
  127. package/src/editify/editify.less +2 -0
  128. package/src/editify/editify.vue +182 -185
  129. package/src/editify/menu/index.ts +5 -0
  130. package/src/editify/menu/menu.vue +215 -0
  131. package/src/{components → editify}/menu/props.ts +1 -1
  132. package/src/editify/props.ts +7 -11
  133. package/src/editify/toolbar/index.ts +5 -0
  134. package/src/{components → editify}/toolbar/props.ts +1 -1
  135. package/src/editify/toolbar/toolbar.less +10 -0
  136. package/src/editify/toolbar/toolbar.vue +103 -0
  137. package/src/feature/align.ts +128 -0
  138. package/src/feature/attachment.ts +109 -0
  139. package/src/feature/backColor.ts +171 -0
  140. package/src/feature/bold.ts +136 -0
  141. package/src/feature/code.ts +136 -0
  142. package/src/feature/codeBlock.ts +204 -0
  143. package/src/feature/fontFamily.ts +140 -0
  144. package/src/feature/fontSize.ts +142 -0
  145. package/src/feature/foreColor.ts +173 -0
  146. package/src/feature/formatClear.ts +118 -0
  147. package/src/feature/fullScreen.ts +57 -0
  148. package/src/feature/heading.ts +154 -0
  149. package/src/feature/image.ts +225 -0
  150. package/src/feature/indent.ts +73 -0
  151. package/src/feature/infoBlock.ts +94 -0
  152. package/src/feature/italic.ts +136 -0
  153. package/src/feature/lineHeight.ts +165 -0
  154. package/src/feature/link.ts +149 -0
  155. package/src/feature/mathformula.ts +147 -0
  156. package/src/feature/orderList.ts +116 -0
  157. package/src/feature/panel.ts +108 -0
  158. package/src/feature/quote.ts +61 -0
  159. package/src/feature/redo.ts +56 -0
  160. package/src/feature/separator.ts +62 -0
  161. package/src/feature/sourceView.ts +59 -0
  162. package/src/feature/strikethrough.ts +136 -0
  163. package/src/feature/sub.ts +136 -0
  164. package/src/feature/super.ts +136 -0
  165. package/src/feature/table.ts +994 -0
  166. package/src/feature/task.ts +116 -0
  167. package/src/feature/underline.ts +136 -0
  168. package/src/feature/undo.ts +56 -0
  169. package/src/feature/unorderList.ts +116 -0
  170. package/src/feature/video.ts +339 -0
  171. package/src/hljs/index.ts +1 -1
  172. package/src/index.ts +69 -21
  173. package/src/locale/en_US.ts +3 -3
  174. package/src/locale/zh_CN.ts +3 -3
  175. package/lib/plugins/attachment/index.d.ts +0 -37
  176. package/lib/plugins/infoBlock/index.d.ts +0 -55
  177. package/lib/plugins/mathformula/index.d.ts +0 -49
  178. package/lib/plugins/panel/index.d.ts +0 -48
  179. package/src/components/menu/menu.vue +0 -1655
  180. package/src/components/toolbar/toolbar.vue +0 -1677
  181. package/src/plugins/attachment/index.ts +0 -237
  182. package/src/plugins/infoBlock/index.ts +0 -238
  183. package/src/plugins/mathformula/index.ts +0 -295
  184. package/src/plugins/panel/index.ts +0 -228
  185. package/tsconfig.json +0 -31
  186. package/tsconfig.node.json +0 -11
  187. /package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.less +0 -0
  188. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.less +0 -0
  189. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue +0 -0
  190. /package/src/{components → editify}/menu/menu.less +0 -0
@@ -0,0 +1,994 @@
1
+ import { computed, defineComponent, h, inject, PropType, ref, Ref } from 'vue'
2
+ import { AlexEditor, AlexElement, AlexElementsRangeType, AlexElementCreateConfigType } from 'alex-editor'
3
+ import { Button } from '@/components/button'
4
+ import { Icon } from '@/components/icon'
5
+ import { getCellMergeElement, getCellSpanNumber, getMatchElementByElement, getMatchElementByRange, getTableSize, hasMathformulaInRange, hasPanelInRange, hasPreInRange, hasTableInRange, insertTable, setTableCellMerged } from '@/core/function'
6
+ import { MenuTableButtonType } from '@/core/tool'
7
+ import { InsertTable } from '@/components/insertTable'
8
+
9
+ /**
10
+ * feature名称
11
+ */
12
+ const FEATURE_NAME = 'table'
13
+
14
+ /**
15
+ * 工具栏 - 表格操作
16
+ */
17
+ export const TableToolbar = defineComponent(
18
+ (props, { emit }) => {
19
+ const editor = inject<Ref<AlexEditor>>('editor')!
20
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
21
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
22
+
23
+ //是否可以合并单元格
24
+ const canMergeCells = computed<(type: 'left' | 'right' | 'up' | 'down') => boolean>(() => {
25
+ return (type: 'left' | 'right' | 'up' | 'down') => {
26
+ if (!editor.value.range) {
27
+ return false
28
+ }
29
+ //光标所在单元格
30
+ const cell = getMatchElementByElement(editor.value.range.focus.element, {
31
+ parsedom: 'td'
32
+ })
33
+ //如果光标不在单元格内
34
+ if (!cell) {
35
+ return false
36
+ }
37
+ //判断是否可以向左合并
38
+ if (type == 'left') {
39
+ //是否可以向左合并
40
+ let flag = false
41
+ //当前单元格的rowspan
42
+ const cellSpanNum = getCellSpanNumber(cell)
43
+ //获取左侧单元格
44
+ const previousColumn = editor.value.getPreviousElement(cell)
45
+ //如果左侧单元格存在
46
+ if (previousColumn) {
47
+ //左侧单元格是隐藏的单元格
48
+ if (previousColumn.hasMarks() && previousColumn.marks!['data-editify-merged']) {
49
+ //获取合并该隐藏单元格的那个单元格
50
+ const { crossColumnElement } = getCellMergeElement(editor.value, previousColumn)
51
+ //如果是被跨列合并则判断跨列单元格占据的行数与当前单元格的行数是否一致
52
+ if (crossColumnElement) {
53
+ const { rowspan } = getCellSpanNumber(crossColumnElement)
54
+ flag = rowspan == cellSpanNum.rowspan
55
+ }
56
+ }
57
+ //左侧单元格不是隐藏的单元格
58
+ else {
59
+ //判断所占行数是否一致
60
+ const { rowspan } = getCellSpanNumber(previousColumn)
61
+ flag = rowspan == cellSpanNum.rowspan
62
+ }
63
+ }
64
+ return flag
65
+ }
66
+ //判断是否可以向右合并
67
+ if (type == 'right') {
68
+ //是否可以向右合并
69
+ let flag = false
70
+ //当前单元格的rowspan
71
+ const cellSpanNum = getCellSpanNumber(cell)
72
+ //获取右侧的单元格
73
+ let nextColumn = editor.value.getNextElement(cell)
74
+ //如果右侧单元格存在
75
+ while (nextColumn) {
76
+ //右侧单元格是隐藏的单元格
77
+ if (nextColumn.hasMarks() && nextColumn.marks!['data-editify-merged']) {
78
+ //获取合并该隐藏单元格的那个单元格
79
+ const { crossColumnElement } = getCellMergeElement(editor.value, nextColumn)
80
+ //如果是被跨列合并的表示属于当前单元格内,继续向右查询
81
+ if (crossColumnElement) {
82
+ nextColumn = editor.value.getNextElement(nextColumn)
83
+ }
84
+ //被跨行合并的直接结束,不能向右合并
85
+ else {
86
+ break
87
+ }
88
+ }
89
+ //右侧单元格不是隐藏的
90
+ else {
91
+ //判断行数是否与当前单元格一致
92
+ const { rowspan } = getCellSpanNumber(nextColumn)
93
+ //如果一致则可以合并
94
+ flag = rowspan == cellSpanNum.rowspan
95
+ //不管是否一致都直接结束
96
+ break
97
+ }
98
+ }
99
+ return flag
100
+ }
101
+ //判断是否可以向上合并
102
+ if (type == 'up') {
103
+ //是否可以向上合并
104
+ let flag = false
105
+ //当前单元格的colspan
106
+ const cellSpanNum = getCellSpanNumber(cell)
107
+ //获取单元格在行中的序列
108
+ const index = cell.parent!.children!.findIndex(item => item.isEqual(cell))
109
+ //获取上一行
110
+ const previousRow = editor.value.getPreviousElement(cell.parent!)
111
+ //如果上一行存在
112
+ if (previousRow) {
113
+ //获取上一行中对应序列的单元格
114
+ const column = previousRow.children![index]
115
+ //单元格是隐藏的单元格
116
+ if (column.hasMarks() && column.marks!['data-editify-merged']) {
117
+ //获取合并该隐藏单元格的那个单元格
118
+ const { crossRowElement } = getCellMergeElement(editor.value, column)
119
+ //如果是被跨行合并则判断跨列单元格占据的列数与当前单元格的列数是否一致
120
+ if (crossRowElement) {
121
+ const { colspan } = getCellSpanNumber(crossRowElement)
122
+ flag = colspan == cellSpanNum.colspan
123
+ }
124
+ }
125
+ //单元格不是隐藏的单元格
126
+ else {
127
+ //判断所占列数是否一致
128
+ const { colspan } = getCellSpanNumber(column)
129
+ flag = colspan == cellSpanNum.colspan
130
+ }
131
+ }
132
+ return flag
133
+ }
134
+ //判断是否可以向下合并
135
+ if (type == 'down') {
136
+ //是否可以向下合并
137
+ let flag = false
138
+ //当前单元格的colspan
139
+ const cellSpanNum = getCellSpanNumber(cell)
140
+ //获取单元格在行中的序列
141
+ const index = cell.parent!.children!.findIndex(item => item.isEqual(cell))
142
+ //获取下一行
143
+ let nextRow = editor.value.getNextElement(cell.parent!)
144
+ //如果下一行存在
145
+ while (nextRow) {
146
+ //获取下一行中对应序列的单元格
147
+ const column = nextRow.children![index]
148
+ //单元格是隐藏的单元格
149
+ if (column.hasMarks() && column.marks!['data-editify-merged']) {
150
+ //获取合并该隐藏单元格的那个单元格
151
+ const { crossRowElement } = getCellMergeElement(editor.value, column)
152
+ //如果是被跨行合并的表示属于当前单元格内,继续向下查询
153
+ if (crossRowElement) {
154
+ nextRow = editor.value.getNextElement(nextRow)
155
+ }
156
+ //被跨列合并的直接结束,不能向右合并
157
+ else {
158
+ break
159
+ }
160
+ }
161
+ //单元格不是隐藏的
162
+ else {
163
+ //判断列数是否与当前单元格一致
164
+ const { colspan } = getCellSpanNumber(column)
165
+ //如果一致则可以合并
166
+ flag = colspan == cellSpanNum.colspan
167
+ //不管是否一致都直接结束
168
+ break
169
+ }
170
+ }
171
+ return flag
172
+ }
173
+ return false
174
+ }
175
+ })
176
+
177
+ //表格前后插入段落
178
+ const insertParagraphWithTable = (type: 'up' | 'down' | undefined = 'up') => {
179
+ const table = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'table' })
180
+ if (table) {
181
+ const paragraph = AlexElement.create({
182
+ type: 'block',
183
+ parsedom: AlexElement.BLOCK_NODE,
184
+ children: [
185
+ {
186
+ type: 'closed',
187
+ parsedom: 'br'
188
+ }
189
+ ]
190
+ })
191
+ if (type == 'up') {
192
+ editor.value.addElementBefore(paragraph, table)
193
+ } else {
194
+ editor.value.addElementAfter(paragraph, table)
195
+ }
196
+ editor.value.range!.anchor.moveToEnd(paragraph)
197
+ editor.value.range!.focus.moveToEnd(paragraph)
198
+ editor.value.formatElementStack()
199
+ editor.value.domRender()
200
+ editor.value.rangeRender()
201
+ }
202
+ }
203
+ //表格前后插入行
204
+ const insertTableRow = (type: 'up' | 'down' | undefined = 'up') => {
205
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
206
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
207
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
208
+ }
209
+ const row = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'tr' })
210
+ if (row) {
211
+ const tbody = row.parent!
212
+ const { columnNumber } = getTableSize(tbody.children!)
213
+ const children: AlexElementCreateConfigType[] = []
214
+ for (let i = 0; i < columnNumber; i++) {
215
+ children.push({
216
+ type: 'inblock',
217
+ parsedom: 'td',
218
+ children: [
219
+ {
220
+ type: 'closed',
221
+ parsedom: 'br'
222
+ }
223
+ ]
224
+ })
225
+ }
226
+ const newRow = AlexElement.create({
227
+ type: 'inblock',
228
+ parsedom: 'tr',
229
+ children
230
+ })
231
+ if (type == 'up') {
232
+ editor.value.addElementBefore(newRow, row)
233
+ } else {
234
+ editor.value.addElementAfter(newRow, row)
235
+ }
236
+ //重置光标
237
+ editor.value.range!.anchor.moveToStart(newRow)
238
+ editor.value.range!.focus.moveToStart(newRow)
239
+ //渲染
240
+ editor.value.formatElementStack()
241
+ editor.value.domRender()
242
+ editor.value.rangeRender()
243
+ //更新工具条位置
244
+ setTimeout(() => {
245
+ emit('reset-toolbar')
246
+ }, 0)
247
+ }
248
+ }
249
+ //表格前后插入列
250
+ const insertTableColumn = (type: 'left' | 'right' | undefined = 'left') => {
251
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
252
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
253
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
254
+ }
255
+ const column = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'td' })
256
+ if (column) {
257
+ const row = column.parent!
258
+ const tbody = row.parent!
259
+ const table = tbody.parent!
260
+ const rows = tbody.children
261
+ const index = row.children!.findIndex(item => {
262
+ return item.isEqual(column)
263
+ })
264
+ //插入列
265
+ rows!.forEach(item => {
266
+ const newColumn = AlexElement.create({
267
+ type: 'inblock',
268
+ parsedom: 'td',
269
+ children: [
270
+ {
271
+ type: 'closed',
272
+ parsedom: 'br'
273
+ }
274
+ ]
275
+ })
276
+ if (type == 'left') {
277
+ editor.value.addElementTo(newColumn, item, index)
278
+ } else {
279
+ editor.value.addElementTo(newColumn, item, index + 1)
280
+ }
281
+ })
282
+ //插入col
283
+ const colgroup = table.children!.find(item => {
284
+ return item.parsedom == 'colgroup'
285
+ })!
286
+ const col = AlexElement.create({
287
+ type: 'closed',
288
+ parsedom: 'col'
289
+ })
290
+ if (type == 'left') {
291
+ editor.value.addElementTo(col, colgroup, index)
292
+ } else {
293
+ editor.value.addElementTo(col, colgroup, index + 1)
294
+ }
295
+ if (type == 'left') {
296
+ const previousColumn = editor.value.getPreviousElement(column)!
297
+ editor.value.range!.anchor.moveToStart(previousColumn)
298
+ editor.value.range!.focus.moveToStart(previousColumn)
299
+ } else {
300
+ const nextColumn = editor.value.getNextElement(column)!
301
+ editor.value.range!.anchor.moveToStart(nextColumn)
302
+ editor.value.range!.focus.moveToStart(nextColumn)
303
+ }
304
+ //渲染
305
+ editor.value.formatElementStack()
306
+ editor.value.domRender()
307
+ editor.value.rangeRender()
308
+ }
309
+ }
310
+ //删除表格
311
+ const deleteTable = () => {
312
+ const element = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'table' })
313
+ if (element) {
314
+ element.toEmpty()
315
+ editor.value.formatElementStack()
316
+ editor.value.domRender()
317
+ editor.value.rangeRender()
318
+ }
319
+ }
320
+ //删除表格行
321
+ const deleteTableRow = () => {
322
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
323
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
324
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
325
+ }
326
+ const column = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'td' })
327
+ if (column) {
328
+ //光标所在行
329
+ const row = column.parent!
330
+ //如果只有一行则删除表格
331
+ if (row.parent!.children!.length == 1) {
332
+ deleteTable()
333
+ return
334
+ }
335
+ //光标所在的单元格在行中的序列
336
+ const index = row.children!.findIndex(item => {
337
+ return item.isEqual(column)
338
+ })
339
+ //上一行
340
+ const previousRow = editor.value.getPreviousElement(row)
341
+ //下一行
342
+ const nextRow = editor.value.getNextElement(row)
343
+ //遍历行中的每一个单元格
344
+ row.children!.forEach((item, i) => {
345
+ //获取单元格占的行数
346
+ const itemSpanNum = getCellSpanNumber(item)
347
+ //是隐藏的单元格
348
+ if (item.hasMarks() && item.marks!['data-editify-merged']) {
349
+ const { crossRowElement } = getCellMergeElement(editor.value, item)
350
+ //如果是被跨行单元格合并的
351
+ if (crossRowElement) {
352
+ const { rowspan } = getCellSpanNumber(crossRowElement)
353
+ if (rowspan - 1 == 1) {
354
+ delete crossRowElement.marks!['rowspan']
355
+ } else {
356
+ crossRowElement.marks!['rowspan'] = rowspan - 1
357
+ }
358
+ }
359
+ }
360
+ //是跨行的单元格
361
+ else if (itemSpanNum.rowspan > 1) {
362
+ //获取下一行
363
+ let el = editor.value.getNextElement(row)
364
+ if (el && itemSpanNum.rowspan - 1 > 1) {
365
+ if (el.children![i].hasMarks()) {
366
+ el.children![i].marks!['rowspan'] = itemSpanNum.rowspan - 1
367
+ } else {
368
+ el.children![i].marks = {
369
+ rowspan: itemSpanNum.rowspan - 1
370
+ }
371
+ }
372
+ }
373
+ }
374
+ })
375
+ //删除行
376
+ row.toEmpty()
377
+ //重置光标
378
+ if (previousRow) {
379
+ editor.value.range!.anchor.moveToEnd(previousRow.children![index])
380
+ editor.value.range!.focus.moveToEnd(previousRow.children![index])
381
+ } else {
382
+ editor.value.range!.anchor.moveToEnd(nextRow!.children![index])
383
+ editor.value.range!.focus.moveToEnd(nextRow!.children![index])
384
+ }
385
+ //渲染
386
+ editor.value.formatElementStack()
387
+ editor.value.domRender()
388
+ editor.value.rangeRender()
389
+ //更新工具条位置
390
+ setTimeout(() => {
391
+ emit('reset-toolbar')
392
+ }, 0)
393
+ }
394
+ }
395
+ //删除表格列
396
+ const deleteTableColumn = () => {
397
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
398
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
399
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
400
+ }
401
+ const column = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'td' })
402
+ if (column) {
403
+ //光标所在行
404
+ const row = column.parent!
405
+ //所有的行元素
406
+ const rows = row.parent!.children!
407
+ //表格元素
408
+ const table = row.parent!.parent!
409
+ //如果光标所在行只有一个单元格则删除表格
410
+ if (row.children!.length == 1) {
411
+ deleteTable()
412
+ return
413
+ }
414
+ //光标所在的单元格在行中的序列
415
+ const index = row.children!.findIndex(item => {
416
+ return item.isEqual(column)
417
+ })
418
+ //前一个单元格
419
+ const previousColumn = editor.value.getPreviousElement(column)
420
+ //后一个单元格
421
+ const nextColumn = editor.value.getNextElement(column)
422
+ //遍历所有的行元素
423
+ rows.forEach(item => {
424
+ //对应序列的单元格
425
+ const cell = item.children![index]
426
+ const cellSpanNum = getCellSpanNumber(cell)
427
+ //是隐藏的单元格
428
+ if (cell.hasMarks() && cell.marks!['data-editify-merged']) {
429
+ const { crossColumnElement } = getCellMergeElement(editor.value, cell)
430
+ //如果是被跨列单元格合并的
431
+ if (crossColumnElement) {
432
+ const { colspan } = getCellSpanNumber(crossColumnElement)
433
+ if (colspan - 1 == 1) {
434
+ delete crossColumnElement.marks!['colspan']
435
+ } else {
436
+ crossColumnElement.marks!['colspan'] = colspan - 1
437
+ }
438
+ }
439
+ }
440
+ //跨列的单元格
441
+ else if (cellSpanNum.colspan > 1) {
442
+ //获取下一个单元格
443
+ let el = editor.value.getNextElement(cell)
444
+ if (el && cellSpanNum.colspan - 1 > 1) {
445
+ if (el.hasMarks()) {
446
+ el.marks!['colspan'] = cellSpanNum.colspan - 1
447
+ } else {
448
+ el.marks = {
449
+ colspan: cellSpanNum.colspan - 1
450
+ }
451
+ }
452
+ }
453
+ }
454
+ cell.toEmpty()
455
+ })
456
+ //删除col
457
+ const colgroup = table.children!.find(item => {
458
+ return item.parsedom == 'colgroup'
459
+ })!
460
+ colgroup.children![index].toEmpty()
461
+ if (previousColumn) {
462
+ editor.value.range!.anchor.moveToEnd(previousColumn)
463
+ editor.value.range!.focus.moveToEnd(previousColumn)
464
+ } else {
465
+ editor.value.range!.anchor.moveToEnd(nextColumn!)
466
+ editor.value.range!.focus.moveToEnd(nextColumn!)
467
+ }
468
+ //渲染
469
+ editor.value.formatElementStack()
470
+ editor.value.domRender()
471
+ editor.value.rangeRender()
472
+ }
473
+ }
474
+ //合并单元格
475
+ const mergeCells = (type: 'left' | 'right' | 'up' | 'down') => {
476
+ if (!canMergeCells.value(type)) {
477
+ return
478
+ }
479
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
480
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
481
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
482
+ }
483
+ const column = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'td' })
484
+ if (column) {
485
+ //向左合并单元格
486
+ if (type == 'left') {
487
+ //当前单元格所占行数和列数
488
+ const cellSpanNum = getCellSpanNumber(column)
489
+ //获取左侧单元格
490
+ const previousColumn = editor.value.getPreviousElement(column)
491
+ //如果左侧单元格存在
492
+ if (previousColumn) {
493
+ //左侧单元格是隐藏的单元格
494
+ if (previousColumn.hasMarks() && previousColumn.marks!['data-editify-merged']) {
495
+ //获取合并该隐藏单元格的那个单元格
496
+ const { crossColumnElement } = getCellMergeElement(editor.value, previousColumn)
497
+ //如果是被跨列合并则判断跨列单元格占据的行数与当前单元格的行数是否一致
498
+ if (crossColumnElement) {
499
+ const { rowspan, colspan } = getCellSpanNumber(crossColumnElement)
500
+ //进行合并
501
+ if (rowspan == cellSpanNum.rowspan) {
502
+ crossColumnElement.marks!['colspan'] = colspan + cellSpanNum.colspan
503
+ column.children!.forEach(item => {
504
+ crossColumnElement.children!.push(item)
505
+ item.parent = crossColumnElement
506
+ })
507
+ setTableCellMerged(column)
508
+ editor.value.range!.anchor.moveToEnd(crossColumnElement)
509
+ editor.value.range!.focus.moveToEnd(crossColumnElement)
510
+ editor.value.formatElementStack()
511
+ editor.value.domRender()
512
+ editor.value.rangeRender()
513
+ }
514
+ }
515
+ }
516
+ //左侧单元格不是隐藏的单元格
517
+ else {
518
+ //判断所占行数是否一致
519
+ const { rowspan, colspan } = getCellSpanNumber(previousColumn)
520
+ //进行合并
521
+ if (rowspan == cellSpanNum.rowspan) {
522
+ if (previousColumn.hasMarks()) {
523
+ previousColumn.marks!['colspan'] = colspan + cellSpanNum.colspan
524
+ } else {
525
+ previousColumn.marks = {
526
+ colspan: colspan + cellSpanNum.colspan
527
+ }
528
+ }
529
+ column.children!.forEach(item => {
530
+ previousColumn.children!.push(item)
531
+ item.parent = previousColumn
532
+ })
533
+ setTableCellMerged(column)
534
+ editor.value.range!.anchor.moveToEnd(previousColumn)
535
+ editor.value.range!.focus.moveToEnd(previousColumn)
536
+ editor.value.formatElementStack()
537
+ editor.value.domRender()
538
+ editor.value.rangeRender()
539
+ }
540
+ }
541
+ }
542
+ }
543
+ //向右合并单元格
544
+ else if (type == 'right') {
545
+ //当前单元格所占行数和列数
546
+ const cellSpanNum = getCellSpanNumber(column)
547
+ //获取右侧的单元格
548
+ let nextColumn = editor.value.getNextElement(column)
549
+ //如果右侧单元格存在
550
+ while (nextColumn) {
551
+ //右侧单元格是隐藏的单元格
552
+ if (nextColumn.hasMarks() && nextColumn.marks!['data-editify-merged']) {
553
+ //获取合并该隐藏单元格的那个单元格
554
+ const { crossColumnElement } = getCellMergeElement(editor.value, nextColumn)
555
+ //如果是被跨列合并的表示属于当前单元格内,继续向右查询
556
+ if (crossColumnElement) {
557
+ nextColumn = editor.value.getNextElement(nextColumn)
558
+ }
559
+ //被跨行合并的直接结束,不能向右合并
560
+ else {
561
+ break
562
+ }
563
+ }
564
+ //右侧单元格不是隐藏的
565
+ else {
566
+ //判断行数是否与当前单元格一致
567
+ const { rowspan, colspan } = getCellSpanNumber(nextColumn)
568
+ //如果一致则可以合并
569
+ if (rowspan == cellSpanNum.rowspan) {
570
+ if (column.hasMarks()) {
571
+ column.marks!['colspan'] = cellSpanNum.colspan + colspan
572
+ } else {
573
+ column.marks = {
574
+ colspan: cellSpanNum.colspan + colspan
575
+ }
576
+ }
577
+ nextColumn.children!.forEach(item => {
578
+ column.children!.push(item)
579
+ item.parent = column
580
+ })
581
+ setTableCellMerged(nextColumn)
582
+ editor.value.range!.anchor.moveToEnd(column)
583
+ editor.value.range!.focus.moveToEnd(column)
584
+ editor.value.formatElementStack()
585
+ editor.value.domRender()
586
+ editor.value.rangeRender()
587
+ }
588
+ //不管是否一致都直接结束
589
+ break
590
+ }
591
+ }
592
+ }
593
+ //向上合并单元格
594
+ else if (type == 'up') {
595
+ //当前单元格所占行数和列数
596
+ const cellSpanNum = getCellSpanNumber(column)
597
+ //获取单元格在行中的序列
598
+ const index = column.parent!.children!.findIndex(item => item.isEqual(column))
599
+ //获取上一行
600
+ const previousRow = editor.value.getPreviousElement(column.parent!)
601
+ //如果上一行存在
602
+ if (previousRow) {
603
+ //获取上一行中对应序列的单元格
604
+ const previousColumn = previousRow.children![index]
605
+ //单元格是隐藏的单元格
606
+ if (previousColumn.hasMarks() && previousColumn.marks!['data-editify-merged']) {
607
+ //获取合并该隐藏单元格的那个单元格
608
+ const { crossRowElement } = getCellMergeElement(editor.value, previousColumn)
609
+ //如果是被跨行合并则判断跨列单元格占据的列数与当前单元格的列数是否一致
610
+ if (crossRowElement) {
611
+ const { rowspan, colspan } = getCellSpanNumber(crossRowElement)
612
+ //进行合并
613
+ if (colspan == cellSpanNum.colspan) {
614
+ crossRowElement.marks!['rowspan'] = rowspan + cellSpanNum.rowspan
615
+ column.children!.forEach(item => {
616
+ crossRowElement.children!.push(item)
617
+ item.parent = crossRowElement
618
+ })
619
+ setTableCellMerged(column)
620
+ editor.value.range!.anchor.moveToEnd(crossRowElement)
621
+ editor.value.range!.focus.moveToEnd(crossRowElement)
622
+ editor.value.formatElementStack()
623
+ editor.value.domRender()
624
+ editor.value.rangeRender()
625
+ }
626
+ }
627
+ }
628
+ //单元格不是隐藏的单元格
629
+ else {
630
+ //判断所占列数是否一致
631
+ const { rowspan, colspan } = getCellSpanNumber(previousColumn)
632
+ //进行合并
633
+ if (colspan == cellSpanNum.colspan) {
634
+ if (previousColumn.hasMarks()) {
635
+ previousColumn.marks!['rowspan'] = rowspan + cellSpanNum.rowspan
636
+ } else {
637
+ previousColumn.marks = {
638
+ rowspan: rowspan + cellSpanNum.rowspan
639
+ }
640
+ }
641
+ column.children!.forEach(item => {
642
+ previousColumn.children!.push(item)
643
+ item.parent = previousColumn
644
+ })
645
+ setTableCellMerged(column)
646
+ editor.value.range!.anchor.moveToEnd(previousColumn)
647
+ editor.value.range!.focus.moveToEnd(previousColumn)
648
+ editor.value.formatElementStack()
649
+ editor.value.domRender()
650
+ editor.value.rangeRender()
651
+ }
652
+ }
653
+ }
654
+ }
655
+ //向下合并单元格
656
+ else if (type == 'down') {
657
+ //当前单元格所占行数和列数
658
+ const cellSpanNum = getCellSpanNumber(column)
659
+ //获取单元格在行中的序列
660
+ const index = column.parent!.children!.findIndex(item => item.isEqual(column))
661
+ //获取下一行
662
+ let nextRow = editor.value.getNextElement(column.parent!)
663
+ //如果下一行存在
664
+ while (nextRow) {
665
+ //获取下一行中对应序列的单元格
666
+ const nextColumn = nextRow.children![index]
667
+ //单元格是隐藏的单元格
668
+ if (nextColumn.hasMarks() && nextColumn.marks!['data-editify-merged']) {
669
+ //获取合并该隐藏单元格的那个单元格
670
+ const { crossRowElement } = getCellMergeElement(editor.value, nextColumn)
671
+ //如果是被跨行合并的表示属于当前单元格内,继续向下查询
672
+ if (crossRowElement) {
673
+ nextRow = editor.value.getNextElement(nextRow)
674
+ }
675
+ //被跨列合并的直接结束,不能向右合并
676
+ else {
677
+ break
678
+ }
679
+ }
680
+ //单元格不是隐藏的
681
+ else {
682
+ //判断列数是否与当前单元格一致
683
+ const { rowspan, colspan } = getCellSpanNumber(nextColumn)
684
+ //如果一致则可以合并
685
+ if (colspan == cellSpanNum.colspan) {
686
+ if (column.hasMarks()) {
687
+ column.marks!['rowspan'] = cellSpanNum.rowspan + rowspan
688
+ } else {
689
+ column.marks = {
690
+ rowspan: cellSpanNum.rowspan + rowspan
691
+ }
692
+ }
693
+ nextColumn.children!.forEach(item => {
694
+ column.children!.push(item)
695
+ item.parent = column
696
+ })
697
+ setTableCellMerged(nextColumn)
698
+ editor.value.range!.anchor.moveToEnd(column)
699
+ editor.value.range!.focus.moveToEnd(column)
700
+ editor.value.formatElementStack()
701
+ editor.value.domRender()
702
+ editor.value.rangeRender()
703
+ }
704
+ //不管是否一致都直接结束
705
+ break
706
+ }
707
+ }
708
+ }
709
+ }
710
+ }
711
+
712
+ return () => {
713
+ return [
714
+ //表格前插入段落
715
+ h(
716
+ Button,
717
+ {
718
+ name: 'textWrapUp',
719
+ title: $editTrans('textWrapUp'),
720
+ tooltip: props.tooltip,
721
+ color: props.color,
722
+ zIndex: props.zIndex,
723
+ onOperate: () => insertParagraphWithTable('up')
724
+ },
725
+ {
726
+ default: () => h(Icon, { value: 'text-wrap', class: 'editify-icon-rotate' })
727
+ }
728
+ ),
729
+ //表格后插入段落
730
+ h(
731
+ Button,
732
+ {
733
+ name: 'textWrapDown',
734
+ title: $editTrans('textWrapDown'),
735
+ tooltip: props.tooltip,
736
+ color: props.color,
737
+ zIndex: props.zIndex,
738
+ rightBorder: true,
739
+ onOperate: () => insertParagraphWithTable('down')
740
+ },
741
+ {
742
+ default: () => h(Icon, { value: 'text-wrap' })
743
+ }
744
+ ),
745
+ //向前插入行
746
+ h(
747
+ Button,
748
+ {
749
+ name: 'insertRowTop',
750
+ title: $editTrans('insertRowTop'),
751
+ tooltip: props.tooltip,
752
+ color: props.color,
753
+ zIndex: props.zIndex,
754
+ onOperate: () => insertTableRow('up')
755
+ },
756
+ {
757
+ default: () => h(Icon, { value: 'insert-row-top' })
758
+ }
759
+ ),
760
+ //向后插入行
761
+ h(
762
+ Button,
763
+ {
764
+ name: 'insertRowBottom',
765
+ title: $editTrans('insertRowBottom'),
766
+ tooltip: props.tooltip,
767
+ color: props.color,
768
+ zIndex: props.zIndex,
769
+ onOperate: () => insertTableRow('down')
770
+ },
771
+ {
772
+ default: () => h(Icon, { value: 'insert-row-bottom' })
773
+ }
774
+ ),
775
+ //删除行
776
+ h(
777
+ Button,
778
+ {
779
+ name: 'deleteRow',
780
+ title: $editTrans('deleteRow'),
781
+ tooltip: props.tooltip,
782
+ color: props.color,
783
+ zIndex: props.zIndex,
784
+ rightBorder: true,
785
+ onOperate: () => deleteTableRow()
786
+ },
787
+ {
788
+ default: () => h(Icon, { value: 'delete-row' })
789
+ }
790
+ ),
791
+ //向前插入列
792
+ h(
793
+ Button,
794
+ {
795
+ name: 'insertColumnLeft',
796
+ title: $editTrans('insertColumnLeft'),
797
+ tooltip: props.tooltip,
798
+ color: props.color,
799
+ zIndex: props.zIndex,
800
+ onOperate: () => insertTableColumn('left')
801
+ },
802
+ {
803
+ default: () => h(Icon, { value: 'insert-column-left' })
804
+ }
805
+ ),
806
+ //向后插入列
807
+ h(
808
+ Button,
809
+ {
810
+ name: 'insertColumnRight',
811
+ title: $editTrans('insertColumnRight'),
812
+ tooltip: props.tooltip,
813
+ color: props.color,
814
+ zIndex: props.zIndex,
815
+ onOperate: () => insertTableColumn('right')
816
+ },
817
+ {
818
+ default: () => h(Icon, { value: 'insert-column-right' })
819
+ }
820
+ ),
821
+ //删除列
822
+ h(
823
+ Button,
824
+ {
825
+ name: 'deleteColumn',
826
+ title: $editTrans('deleteColumn'),
827
+ tooltip: props.tooltip,
828
+ color: props.color,
829
+ zIndex: props.zIndex,
830
+ rightBorder: true,
831
+ onOperate: () => deleteTableColumn()
832
+ },
833
+ {
834
+ default: () => h(Icon, { value: 'delete-column' })
835
+ }
836
+ ),
837
+ //向左合并单元格
838
+ h(
839
+ Button,
840
+ {
841
+ name: 'mergeCellsLeft',
842
+ title: $editTrans('mergeCellsLeft'),
843
+ tooltip: props.tooltip,
844
+ color: props.color,
845
+ zIndex: props.zIndex,
846
+ disabled: !canMergeCells.value('left'),
847
+ onOperate: () => mergeCells('left')
848
+ },
849
+ {
850
+ default: () => h(Icon, { value: 'merge-cells-left' })
851
+ }
852
+ ),
853
+ //向右合并单元格
854
+ h(
855
+ Button,
856
+ {
857
+ name: 'mergeCellsRight',
858
+ title: $editTrans('mergeCellsRight'),
859
+ tooltip: props.tooltip,
860
+ color: props.color,
861
+ zIndex: props.zIndex,
862
+ disabled: !canMergeCells.value('right'),
863
+ onOperate: () => mergeCells('right')
864
+ },
865
+ {
866
+ default: () => h(Icon, { value: 'merge-cells-right' })
867
+ }
868
+ ),
869
+ //向上合并单元格
870
+ h(
871
+ Button,
872
+ {
873
+ name: 'mergeCellsUp',
874
+ title: $editTrans('mergeCellsUp'),
875
+ tooltip: props.tooltip,
876
+ color: props.color,
877
+ zIndex: props.zIndex,
878
+ disabled: !canMergeCells.value('up'),
879
+ onOperate: () => mergeCells('up')
880
+ },
881
+ {
882
+ default: () => h(Icon, { value: 'merge-cells-up' })
883
+ }
884
+ ),
885
+ //向下合并单元格
886
+ h(
887
+ Button,
888
+ {
889
+ name: 'mergeCellsDown',
890
+ title: $editTrans('mergeCellsDown'),
891
+ tooltip: props.tooltip,
892
+ color: props.color,
893
+ zIndex: props.zIndex,
894
+ disabled: !canMergeCells.value('down'),
895
+ onOperate: () => mergeCells('down')
896
+ },
897
+ {
898
+ default: () => h(Icon, { value: 'merge-cells-down' })
899
+ }
900
+ ),
901
+ //删除表格
902
+ h(
903
+ Button,
904
+ {
905
+ name: 'deleteTable',
906
+ title: $editTrans('deleteTable'),
907
+ tooltip: props.tooltip,
908
+ color: props.color,
909
+ zIndex: props.zIndex,
910
+ leftBorder: true,
911
+ onOperate: () => deleteTable()
912
+ },
913
+ {
914
+ default: () => h(Icon, { value: 'delete-table' })
915
+ }
916
+ )
917
+ ]
918
+ }
919
+ },
920
+ {
921
+ name: `_${FEATURE_NAME}`,
922
+ props: {
923
+ color: String,
924
+ zIndex: Number,
925
+ tooltip: Boolean
926
+ },
927
+ emits: ['reset-toolbar']
928
+ }
929
+ )
930
+
931
+ /**
932
+ * 菜单栏 - 插入表格
933
+ */
934
+ export const TableMenuButton = defineComponent(
935
+ props => {
936
+ const editor = inject<Ref<AlexEditor>>('editor')!
937
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
938
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
939
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
940
+
941
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
942
+
943
+ return () => {
944
+ return props.config.show
945
+ ? h(
946
+ Button,
947
+ {
948
+ ref: btnRef,
949
+ name: FEATURE_NAME,
950
+ tooltip: props.tooltip,
951
+ color: props.color,
952
+ zIndex: props.zIndex,
953
+ type: 'select',
954
+ hideScroll: true,
955
+ title: $editTrans('insertTable'),
956
+ leftBorder: props.config.leftBorder,
957
+ rightBorder: props.config.rightBorder,
958
+ active: false,
959
+ disabled: props.disabled || isSourceView.value || hasTableInRange(editor.value, dataRangeCaches.value) || hasPreInRange(editor.value, dataRangeCaches.value) || hasMathformulaInRange(editor.value, dataRangeCaches.value) || hasPanelInRange(editor.value, dataRangeCaches.value) || props.config.disabled
960
+ },
961
+ {
962
+ default: () =>
963
+ h(Icon, {
964
+ value: 'table'
965
+ }),
966
+ layer: () =>
967
+ h(InsertTable, {
968
+ color: props.color,
969
+ maxRows: props.config.maxRows,
970
+ maxColumns: props.config.maxColumns,
971
+ onInsert: (row, column) => {
972
+ insertTable(editor.value, row, column)
973
+ editor.value.formatElementStack()
974
+ editor.value.domRender()
975
+ editor.value.rangeRender()
976
+ btnRef.value!.show = false
977
+ }
978
+ })
979
+ }
980
+ )
981
+ : null
982
+ }
983
+ },
984
+ {
985
+ name: `_${FEATURE_NAME}`,
986
+ props: {
987
+ color: String,
988
+ zIndex: Number,
989
+ config: Object as PropType<MenuTableButtonType>,
990
+ tooltip: Boolean,
991
+ disabled: Boolean
992
+ }
993
+ }
994
+ )