@hailin-zheng/editor-core 1.0.7 → 1.0.10

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 (237) hide show
  1. package/package.json +3 -4
  2. package/{lib/doc-ruler.js → src/med_editor/doc-ruler.ts} +101 -74
  3. package/src/med_editor/framework/common-util.ts +200 -0
  4. package/{lib/framework/document-change.js → src/med_editor/framework/document-change.ts} +308 -259
  5. package/{lib/framework/document-combine.js → src/med_editor/framework/document-combine.ts} +15 -11
  6. package/{lib/framework/document-comment.js → src/med_editor/framework/document-comment.ts} +52 -37
  7. package/{lib/framework/document-context.js → src/med_editor/framework/document-context.ts} +181 -101
  8. package/{lib/framework/document-eval-func.js → src/med_editor/framework/document-eval-func.ts} +16 -11
  9. package/{lib/framework/document-event.js → src/med_editor/framework/document-event.ts} +244 -216
  10. package/{lib/framework/document-history.js → src/med_editor/framework/document-history.ts} +25 -14
  11. package/{lib/framework/document-images-loader.js → src/med_editor/framework/document-images-loader.ts} +25 -17
  12. package/{lib/framework/document-input-cursor.js → src/med_editor/framework/document-input-cursor.ts} +76 -71
  13. package/{lib/framework/document-paint.js → src/med_editor/framework/document-paint.ts} +35 -28
  14. package/{lib/framework/document-print-offscreen.js → src/med_editor/framework/document-print-offscreen.ts} +25 -19
  15. package/{lib/framework/document-print.js → src/med_editor/framework/document-print.ts} +57 -41
  16. package/src/med_editor/framework/document-segmenter.ts +211 -0
  17. package/{lib/framework/document-selection.js → src/med_editor/framework/document-selection.ts} +116 -85
  18. package/{lib/framework/document-template.js → src/med_editor/framework/document-template.ts} +3 -3
  19. package/src/med_editor/framework/document-textline-mode.ts +34 -0
  20. package/{lib/framework/element-define.js → src/med_editor/framework/element-define.ts} +301 -206
  21. package/src/med_editor/framework/element-event-define.ts +141 -0
  22. package/{lib/framework/element-measure.js → src/med_editor/framework/element-measure.ts} +143 -121
  23. package/{lib/framework/element-paint.js → src/med_editor/framework/element-paint.ts} +44 -38
  24. package/{lib/framework/element-props.js → src/med_editor/framework/element-props.ts} +331 -202
  25. package/{lib/framework/element-reader.js → src/med_editor/framework/element-reader.ts} +39 -31
  26. package/{lib/framework/element-render-cut.js → src/med_editor/framework/element-render-cut.ts} +113 -106
  27. package/{lib/framework/element-serialize.js → src/med_editor/framework/element-serialize.ts} +37 -24
  28. package/{lib/framework/element-util.js → src/med_editor/framework/element-util.ts} +317 -216
  29. package/{lib/framework/impl/checkbox/checkbox-impl.js → src/med_editor/framework/impl/checkbox/checkbox-impl.ts} +27 -20
  30. package/{lib/framework/impl/comments/comment-content-impl.js → src/med_editor/framework/impl/comments/comment-content-impl.ts} +45 -31
  31. package/{lib/framework/impl/comments/comment-element-impl.js → src/med_editor/framework/impl/comments/comment-element-impl.ts} +23 -20
  32. package/{lib/framework/impl/comments/comments-container-impl.js → src/med_editor/framework/impl/comments/comments-container-impl.ts} +22 -16
  33. package/{lib/framework/impl/comments/comments-util.js → src/med_editor/framework/impl/comments/comments-util.ts} +34 -17
  34. package/{lib/framework/impl/comments/validate-msg-impl.js → src/med_editor/framework/impl/comments/validate-msg-impl.ts} +28 -17
  35. package/{lib/framework/impl/data-element/data-decorate-impl.js → src/med_editor/framework/impl/data-element/data-decorate-impl.ts} +26 -22
  36. package/{lib/framework/impl/data-element/data-element-barcode.js → src/med_editor/framework/impl/data-element/data-element-barcode.ts} +41 -29
  37. package/{lib/framework/impl/data-element/data-element-base-impl.js → src/med_editor/framework/impl/data-element/data-element-base-impl.ts} +73 -44
  38. package/{lib/framework/impl/data-element/data-element-check-impl.js → src/med_editor/framework/impl/data-element/data-element-check-impl.ts} +48 -35
  39. package/{lib/framework/impl/data-element/data-element-date-impl.js → src/med_editor/framework/impl/data-element/data-element-date-impl.ts} +41 -24
  40. package/{lib/framework/impl/data-element/data-element-group-impl.js → src/med_editor/framework/impl/data-element/data-element-group-impl.ts} +52 -32
  41. package/{lib/framework/impl/data-element/data-element-image-impl.js → src/med_editor/framework/impl/data-element/data-element-image-impl.ts} +38 -28
  42. package/{lib/framework/impl/data-element/data-element-list-impl.js → src/med_editor/framework/impl/data-element/data-element-list-impl.ts} +42 -31
  43. package/{lib/framework/impl/data-element/data-element-text-impl.js → src/med_editor/framework/impl/data-element/data-element-text-impl.ts} +36 -22
  44. package/{lib/framework/impl/decorate/fill-null-space-imple.js → src/med_editor/framework/impl/decorate/fill-null-space-imple.ts} +15 -10
  45. package/{lib/framework/impl/document/doc-body-impl.js → src/med_editor/framework/impl/document/doc-body-impl.ts} +32 -16
  46. package/{lib/framework/impl/document/doc-body-part-impl.js → src/med_editor/framework/impl/document/doc-body-part-impl.ts} +27 -17
  47. package/src/med_editor/framework/impl/document/doc-container-impl.ts +24 -0
  48. package/{lib/framework/impl/document/doc-footer-impl.js → src/med_editor/framework/impl/document/doc-footer-impl.ts} +30 -19
  49. package/{lib/framework/impl/document/doc-header-impl.js → src/med_editor/framework/impl/document/doc-header-impl.ts} +34 -17
  50. package/{lib/framework/impl/document/doc-impl.js → src/med_editor/framework/impl/document/doc-impl.ts} +62 -45
  51. package/{lib/framework/impl/media-formula/menstrual-history.js → src/med_editor/framework/impl/media-formula/menstrual-history.ts} +58 -36
  52. package/{lib/framework/impl/paragraph/p-impl.js → src/med_editor/framework/impl/paragraph/p-impl.ts} +64 -30
  53. package/{lib/framework/impl/picture/image-impl.js → src/med_editor/framework/impl/picture/image-impl.ts} +37 -25
  54. package/{lib/framework/impl/radio/radio-impl.js → src/med_editor/framework/impl/radio/radio-impl.ts} +28 -21
  55. package/{lib/framework/impl/symbol/br-symbol-impl.js → src/med_editor/framework/impl/symbol/br-symbol-impl.ts} +21 -15
  56. package/{lib/framework/impl/symbol/p-symbol-impl.js → src/med_editor/framework/impl/symbol/p-symbol-impl.ts} +15 -12
  57. package/{lib/framework/impl/table/table-cell-impl.js → src/med_editor/framework/impl/table/table-cell-impl.ts} +41 -30
  58. package/{lib/framework/impl/table/table-impl.js → src/med_editor/framework/impl/table/table-impl.ts} +122 -84
  59. package/{lib/framework/impl/table/table-row-impl.js → src/med_editor/framework/impl/table/table-row-impl.ts} +26 -18
  60. package/{lib/framework/impl/table/table-split-cell-patch.js → src/med_editor/framework/impl/table/table-split-cell-patch.ts} +31 -22
  61. package/{lib/framework/impl/table/table-split-cell.js → src/med_editor/framework/impl/table/table-split-cell.ts} +105 -94
  62. package/{lib/framework/impl/table/table-util.js → src/med_editor/framework/impl/table/table-util.ts} +197 -159
  63. package/{lib/framework/impl/text/text-impl.js → src/med_editor/framework/impl/text/text-impl.ts} +49 -35
  64. package/{lib/framework/impl/text/track-run-impl.js → src/med_editor/framework/impl/text/track-run-impl.ts} +53 -30
  65. package/{lib/framework/notify.js → src/med_editor/framework/notify.ts} +50 -36
  66. package/{lib/framework/range-util.js → src/med_editor/framework/range-util.ts} +80 -71
  67. package/{lib/framework/render-context.js → src/med_editor/framework/render-context.ts} +111 -64
  68. package/{lib/framework/render-define.js → src/med_editor/framework/render-define.ts} +90 -61
  69. package/{lib/framework/selection-overlays.js → src/med_editor/framework/selection-overlays.ts} +25 -16
  70. package/{lib/texteditor.js → src/med_editor/texteditor.ts} +288 -191
  71. package/src/med_editor/util/subject.ts +118 -0
  72. package/{lib/util/table-bind.js → src/med_editor/util/table-bind.ts} +2 -2
  73. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225.json +3573 -0
  74. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225.json +3573 -0
  75. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225bug.json +315 -0
  76. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/211/271/346/263/250.json +122 -0
  77. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/346/226/207/346/241/243/351/252/214/350/257/201.json +3599 -0
  78. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225/351/225/277/346/226/207/346/234/254.json +24586 -0
  79. package/src/med_editor//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225.json +2874 -0
  80. package/src/med_editor//346/211/213/346/234/257/350/256/260/345/275/225.json +341 -0
  81. package/src/med_editor//346/231/256/351/200/232doc/347/261/273/346/226/207/346/241/243.json +2201 -0
  82. package/src/med_editor//346/243/200/351/252/214/347/224/263/350/257/267/345/215/225.json +1069 -0
  83. package/src/med_editor//347/227/205/347/250/213/345/275/225//345/206/205/351/225/234/344/270/213/346/262/273/347/226/227/350/256/260/345/275/225.json +125 -0
  84. package/src/med_editor//347/227/205/347/250/213/345/275/225//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225/346/250/241/346/235/277.json +86 -0
  85. package/src/med_editor//347/227/205/347/250/213/345/275/225//346/227/245/345/270/270/347/227/205/347/250/213/350/256/260/345/275/225.json +115 -0
  86. package/src/med_editor//347/227/205/347/250/213/345/275/225//346/237/245/346/210/277/350/256/260/345/275/2251.json +108 -0
  87. package/src/med_editor//347/227/205/347/250/213/345/275/225//351/246/226/346/254/241/344/270/212/347/272/247/345/214/273/345/270/210/346/237/245/346/210/277/350/256/260/345/275/225.json +272 -0
  88. package/src/med_editor//351/225/277/346/234/237/345/214/273/345/230/261/345/215/225.json +1070 -0
  89. package/lib/doc-ruler.d.ts +0 -51
  90. package/lib/doc-ruler.js.map +0 -1
  91. package/lib/framework/common-util.d.ts +0 -63
  92. package/lib/framework/common-util.js +0 -178
  93. package/lib/framework/common-util.js.map +0 -1
  94. package/lib/framework/document-change.d.ts +0 -265
  95. package/lib/framework/document-change.js.map +0 -1
  96. package/lib/framework/document-combine.d.ts +0 -24
  97. package/lib/framework/document-combine.js.map +0 -1
  98. package/lib/framework/document-comment.d.ts +0 -46
  99. package/lib/framework/document-comment.js.map +0 -1
  100. package/lib/framework/document-context.d.ts +0 -149
  101. package/lib/framework/document-context.js.map +0 -1
  102. package/lib/framework/document-eval-func.d.ts +0 -18
  103. package/lib/framework/document-eval-func.js.map +0 -1
  104. package/lib/framework/document-event.d.ts +0 -213
  105. package/lib/framework/document-event.js.map +0 -1
  106. package/lib/framework/document-history.d.ts +0 -26
  107. package/lib/framework/document-history.js.map +0 -1
  108. package/lib/framework/document-images-loader.d.ts +0 -16
  109. package/lib/framework/document-images-loader.js.map +0 -1
  110. package/lib/framework/document-input-cursor.d.ts +0 -78
  111. package/lib/framework/document-input-cursor.js.map +0 -1
  112. package/lib/framework/document-paint.d.ts +0 -34
  113. package/lib/framework/document-paint.js.map +0 -1
  114. package/lib/framework/document-print-offscreen.d.ts +0 -38
  115. package/lib/framework/document-print-offscreen.js.map +0 -1
  116. package/lib/framework/document-print.d.ts +0 -60
  117. package/lib/framework/document-print.js.map +0 -1
  118. package/lib/framework/document-segmenter.d.ts +0 -2
  119. package/lib/framework/document-segmenter.js +0 -106
  120. package/lib/framework/document-segmenter.js.map +0 -1
  121. package/lib/framework/document-selection.d.ts +0 -89
  122. package/lib/framework/document-selection.js.map +0 -1
  123. package/lib/framework/document-template.d.ts +0 -4
  124. package/lib/framework/document-template.js.map +0 -1
  125. package/lib/framework/document-textline-mode.d.ts +0 -7
  126. package/lib/framework/document-textline-mode.js +0 -30
  127. package/lib/framework/document-textline-mode.js.map +0 -1
  128. package/lib/framework/element-define.d.ts +0 -319
  129. package/lib/framework/element-define.js.map +0 -1
  130. package/lib/framework/element-event-define.d.ts +0 -99
  131. package/lib/framework/element-event-define.js +0 -108
  132. package/lib/framework/element-event-define.js.map +0 -1
  133. package/lib/framework/element-measure.d.ts +0 -97
  134. package/lib/framework/element-measure.js.map +0 -1
  135. package/lib/framework/element-paint.d.ts +0 -42
  136. package/lib/framework/element-paint.js.map +0 -1
  137. package/lib/framework/element-props.d.ts +0 -301
  138. package/lib/framework/element-props.js.map +0 -1
  139. package/lib/framework/element-reader.d.ts +0 -19
  140. package/lib/framework/element-reader.js.map +0 -1
  141. package/lib/framework/element-render-cut.d.ts +0 -55
  142. package/lib/framework/element-render-cut.js.map +0 -1
  143. package/lib/framework/element-serialize.d.ts +0 -30
  144. package/lib/framework/element-serialize.js.map +0 -1
  145. package/lib/framework/element-util.d.ts +0 -369
  146. package/lib/framework/element-util.js.map +0 -1
  147. package/lib/framework/impl/checkbox/checkbox-impl.d.ts +0 -24
  148. package/lib/framework/impl/checkbox/checkbox-impl.js.map +0 -1
  149. package/lib/framework/impl/comments/comment-content-impl.d.ts +0 -40
  150. package/lib/framework/impl/comments/comment-content-impl.js.map +0 -1
  151. package/lib/framework/impl/comments/comment-element-impl.d.ts +0 -21
  152. package/lib/framework/impl/comments/comment-element-impl.js.map +0 -1
  153. package/lib/framework/impl/comments/comments-container-impl.d.ts +0 -22
  154. package/lib/framework/impl/comments/comments-container-impl.js.map +0 -1
  155. package/lib/framework/impl/comments/comments-util.d.ts +0 -12
  156. package/lib/framework/impl/comments/comments-util.js.map +0 -1
  157. package/lib/framework/impl/comments/validate-msg-impl.d.ts +0 -21
  158. package/lib/framework/impl/comments/validate-msg-impl.js.map +0 -1
  159. package/lib/framework/impl/data-element/data-decorate-impl.d.ts +0 -30
  160. package/lib/framework/impl/data-element/data-decorate-impl.js.map +0 -1
  161. package/lib/framework/impl/data-element/data-element-barcode.d.ts +0 -31
  162. package/lib/framework/impl/data-element/data-element-barcode.js.map +0 -1
  163. package/lib/framework/impl/data-element/data-element-base-impl.d.ts +0 -68
  164. package/lib/framework/impl/data-element/data-element-base-impl.js.map +0 -1
  165. package/lib/framework/impl/data-element/data-element-check-impl.d.ts +0 -35
  166. package/lib/framework/impl/data-element/data-element-check-impl.js.map +0 -1
  167. package/lib/framework/impl/data-element/data-element-date-impl.d.ts +0 -23
  168. package/lib/framework/impl/data-element/data-element-date-impl.js.map +0 -1
  169. package/lib/framework/impl/data-element/data-element-group-impl.d.ts +0 -23
  170. package/lib/framework/impl/data-element/data-element-group-impl.js.map +0 -1
  171. package/lib/framework/impl/data-element/data-element-image-impl.d.ts +0 -30
  172. package/lib/framework/impl/data-element/data-element-image-impl.js.map +0 -1
  173. package/lib/framework/impl/data-element/data-element-list-impl.d.ts +0 -22
  174. package/lib/framework/impl/data-element/data-element-list-impl.js.map +0 -1
  175. package/lib/framework/impl/data-element/data-element-text-impl.d.ts +0 -23
  176. package/lib/framework/impl/data-element/data-element-text-impl.js.map +0 -1
  177. package/lib/framework/impl/decorate/fill-null-space-imple.d.ts +0 -21
  178. package/lib/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
  179. package/lib/framework/impl/document/doc-body-impl.d.ts +0 -27
  180. package/lib/framework/impl/document/doc-body-impl.js.map +0 -1
  181. package/lib/framework/impl/document/doc-body-part-impl.d.ts +0 -30
  182. package/lib/framework/impl/document/doc-body-part-impl.js.map +0 -1
  183. package/lib/framework/impl/document/doc-container-impl.d.ts +0 -16
  184. package/lib/framework/impl/document/doc-container-impl.js +0 -21
  185. package/lib/framework/impl/document/doc-container-impl.js.map +0 -1
  186. package/lib/framework/impl/document/doc-footer-impl.d.ts +0 -26
  187. package/lib/framework/impl/document/doc-footer-impl.js.map +0 -1
  188. package/lib/framework/impl/document/doc-header-impl.d.ts +0 -26
  189. package/lib/framework/impl/document/doc-header-impl.js.map +0 -1
  190. package/lib/framework/impl/document/doc-impl.d.ts +0 -61
  191. package/lib/framework/impl/document/doc-impl.js.map +0 -1
  192. package/lib/framework/impl/media-formula/menstrual-history.d.ts +0 -35
  193. package/lib/framework/impl/media-formula/menstrual-history.js.map +0 -1
  194. package/lib/framework/impl/paragraph/p-impl.d.ts +0 -45
  195. package/lib/framework/impl/paragraph/p-impl.js.map +0 -1
  196. package/lib/framework/impl/picture/image-impl.d.ts +0 -31
  197. package/lib/framework/impl/picture/image-impl.js.map +0 -1
  198. package/lib/framework/impl/radio/radio-impl.d.ts +0 -22
  199. package/lib/framework/impl/radio/radio-impl.js.map +0 -1
  200. package/lib/framework/impl/symbol/br-symbol-impl.d.ts +0 -22
  201. package/lib/framework/impl/symbol/br-symbol-impl.js.map +0 -1
  202. package/lib/framework/impl/symbol/p-symbol-impl.d.ts +0 -19
  203. package/lib/framework/impl/symbol/p-symbol-impl.js.map +0 -1
  204. package/lib/framework/impl/table/table-cell-impl.d.ts +0 -37
  205. package/lib/framework/impl/table/table-cell-impl.js.map +0 -1
  206. package/lib/framework/impl/table/table-impl.d.ts +0 -55
  207. package/lib/framework/impl/table/table-impl.js.map +0 -1
  208. package/lib/framework/impl/table/table-row-impl.d.ts +0 -26
  209. package/lib/framework/impl/table/table-row-impl.js.map +0 -1
  210. package/lib/framework/impl/table/table-split-cell-patch.d.ts +0 -20
  211. package/lib/framework/impl/table/table-split-cell-patch.js.map +0 -1
  212. package/lib/framework/impl/table/table-split-cell.d.ts +0 -90
  213. package/lib/framework/impl/table/table-split-cell.js.map +0 -1
  214. package/lib/framework/impl/table/table-util.d.ts +0 -150
  215. package/lib/framework/impl/table/table-util.js.map +0 -1
  216. package/lib/framework/impl/text/text-impl.d.ts +0 -32
  217. package/lib/framework/impl/text/text-impl.js.map +0 -1
  218. package/lib/framework/impl/text/track-run-impl.d.ts +0 -27
  219. package/lib/framework/impl/text/track-run-impl.js.map +0 -1
  220. package/lib/framework/notify.d.ts +0 -13
  221. package/lib/framework/notify.js.map +0 -1
  222. package/lib/framework/range-util.d.ts +0 -40
  223. package/lib/framework/range-util.js.map +0 -1
  224. package/lib/framework/render-context.d.ts +0 -91
  225. package/lib/framework/render-context.js.map +0 -1
  226. package/lib/framework/render-define.d.ts +0 -109
  227. package/lib/framework/render-define.js.map +0 -1
  228. package/lib/framework/selection-overlays.d.ts +0 -30
  229. package/lib/framework/selection-overlays.js.map +0 -1
  230. package/lib/texteditor.d.ts +0 -318
  231. package/lib/texteditor.js.map +0 -1
  232. package/lib/util/subject.d.ts +0 -34
  233. package/lib/util/subject.js +0 -88
  234. package/lib/util/subject.js.map +0 -1
  235. package/lib/util/table-bind.d.ts +0 -5
  236. package/lib/util/table-bind.js.map +0 -1
  237. package/tsconfig.json +0 -25
@@ -1,40 +1,45 @@
1
- import { ElementUtil } from "@/med_editor/framework/element-util";
1
+ import { SelectionState } from "../../document-selection";
2
+ import { ElementUtil } from "../../element-util";
3
+ import { Element } from "../../element-define";
2
4
  import { ParagraphElement } from "../paragraph/p-impl";
3
5
  import { TableCellElement } from "./table-cell-impl";
4
6
  import { TableElement } from "./table-impl";
5
7
  import { TableRowElement } from "./table-row-impl";
8
+
9
+
6
10
  export class TableUtil {
7
- static canDeleteTable(ss) {
11
+
12
+ static canDeleteTable(ss: SelectionState): boolean {
8
13
  const { startControl } = ss;
9
14
  if (!startControl) {
10
15
  return false;
11
16
  }
12
17
  const tb = ElementUtil.getParentByType(startControl, TableElement);
13
- return tb ? true : false;
18
+ return !!tb;
14
19
  }
15
20
  /**
16
21
  * 校验当前选区是否可以执行合并单元格操作
17
- * @param ss
18
- * @returns
22
+ * @param ss
23
+ * @returns
19
24
  */
20
- static canMergeCells(ss) {
25
+ static canMergeCells(ss: SelectionState): boolean {
21
26
  const { ancestorCommonControl, startControl, endControl, collapsed, selectedRange } = ss;
22
27
  if (collapsed) {
23
28
  return false;
24
29
  }
25
30
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
26
- const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
31
+ const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent as TableElement;
27
32
  const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
28
33
  const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
29
34
  if (startCell?.parent?.parent === tbElement && endCell?.parent?.parent === tbElement) {
30
35
  const tbRegion = this.getTableRectSelectedRegion(tbElement, startCell, endCell);
31
36
  if (selectedRange && selectedRange.target === tbElement) {
32
- const selectedCells = [];
33
- selectedRange.selectedChildren.every(item => item.selectedChildren.every(cell => selectedCells.push(cell.target)));
37
+ const selectedCells: Array<TableCellElement> = [];
38
+ selectedRange.selectedChildren.every(item => item.selectedChildren.every(cell => selectedCells.push(cell.target as TableCellElement)));
34
39
  for (let i = tbRegion.startRow; i <= tbRegion.endRow; i++) {
35
- const currRow = tbElement.getChild(i);
40
+ const currRow = tbElement.getChild<TableRowElement>(i);
36
41
  for (let j = tbRegion.startCol; j <= tbRegion.endCol; j++) {
37
- const currCell = currRow.getChild(j);
42
+ const currCell = currRow.getChild<TableCellElement>(j);
38
43
  if (currCell.isNotBeMergedCell() && selectedCells.indexOf(currCell) < 0) {
39
44
  return false;
40
45
  }
@@ -46,90 +51,93 @@ export class TableUtil {
46
51
  }
47
52
  return false;
48
53
  }
54
+
49
55
  /**
50
56
  * 获取横向合并当前单元格合并结束索引位置
51
- * @param tb
52
- * @param rowIndex
53
- * @param colIndex
57
+ * @param tb
58
+ * @param rowIndex
59
+ * @param colIndex
54
60
  */
55
- static getHMergeEndIndex(tb, rowIndex, colIndex) {
56
- const currRow = tb.getChild(rowIndex);
61
+ static getHMergeEndIndex(tb: TableElement, rowIndex: number, colIndex: number): number {
62
+ const currRow = tb.getChild(rowIndex) as TableRowElement;
57
63
  let index = colIndex;
58
64
  for (let i = colIndex + 1; i < tb.getColsCount(); i++) {
59
- const cell = currRow.getChild(i);
65
+ const cell = currRow.getChild(i) as TableCellElement;
60
66
  if (cell.props.hMerge === 'continue') {
61
67
  index = i;
62
- }
63
- else {
68
+ } else {
64
69
  break;
65
70
  }
66
71
  }
67
72
  return index;
68
73
  }
74
+
69
75
  /**
70
76
  * 获取横向合并当前单元格合并开始索引位置
71
- * @param tb
72
- * @param rowIndex
73
- * @param colIndex
77
+ * @param tb
78
+ * @param rowIndex
79
+ * @param colIndex
74
80
  */
75
- static getHMergeStartIndex(tb, rowIndex, colIndex) {
76
- const row = tb.getChild(rowIndex);
81
+ static getHMergeStartIndex(tb: TableElement, rowIndex: number, colIndex: number): number {
82
+ const row = tb.getChild(rowIndex) as TableRowElement;
77
83
  for (let i = colIndex - 1; i >= 0; i--) {
78
- const cell = row.getChild(i);
84
+ const cell = row.getChild(i) as TableCellElement;
79
85
  if (cell.props.hMerge === 'restart') {
80
86
  return i;
81
87
  }
82
88
  }
83
89
  throw new Error('未找到主合并单元格');
84
90
  }
91
+
85
92
  /**
86
93
  * 获取纵向合并当前单元格合并结束索引位置
87
- * @param tb
88
- * @param rowIndex
94
+ * @param tb
95
+ * @param rowIndex
89
96
  * @param colIndex i
90
97
  */
91
- static getVMergeEndIndex(tb, rowIndex, colIndex) {
98
+ static getVMergeEndIndex(tb: TableElement, rowIndex: number, colIndex: number): number {
92
99
  let index = rowIndex;
93
100
  for (let i = rowIndex + 1; i < tb.length; i++) {
94
- const currRow = tb.getChild(i);
95
- const cell = currRow.getChild(colIndex);
101
+ const currRow = tb.getChild(i) as TableRowElement;
102
+ const cell = currRow.getChild(colIndex) as TableCellElement;
96
103
  if (cell.props.vMerge === 'continue') {
97
104
  index = i;
98
- }
99
- else {
105
+ } else {
100
106
  break;
101
107
  }
102
108
  }
103
109
  return index;
104
110
  }
111
+
105
112
  /**
106
113
  * 获取纵向合并当前单元格合并开始索引位置
107
- * @param tb
108
- * @param rowIndex
114
+ * @param tb
115
+ * @param rowIndex
109
116
  * @param colIndex i
110
117
  */
111
- static getVMergeStartIndex(tb, rowIndex, colIndex) {
118
+ static getVMergeStartIndex(tb: TableElement, rowIndex: number, colIndex: number): number {
112
119
  for (let i = rowIndex - 1; i >= 0; i--) {
113
- const currRow = tb.getChild(i);
114
- const cell = currRow.getChild(colIndex);
120
+ const currRow = tb.getChild(i) as TableRowElement;
121
+ const cell = currRow.getChild(colIndex) as TableCellElement;
115
122
  if (cell.props.vMerge === 'restart') {
116
123
  return i;
117
124
  }
118
125
  }
119
126
  throw new Error('未找到主合并单元格');
120
127
  }
128
+
121
129
  /**
122
130
  * 合并单元格
123
- * @param ss
124
- * @returns
131
+ * @param ss
132
+ * @returns
125
133
  */
126
- static mergeCells(ss) {
134
+ static mergeCells(ss: SelectionState): void {
127
135
  const { ancestorCommonControl, startControl, endControl, collapsed } = ss;
128
136
  if (collapsed) {
129
137
  return;
130
138
  }
131
139
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
132
- const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
140
+ const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent as TableElement;
133
141
  const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
134
142
  const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
135
143
  if (startCell?.parent?.parent === tbElement && endCell?.parent?.parent === tbElement) {
@@ -140,51 +148,50 @@ export class TableUtil {
140
148
  ss.clear();
141
149
  }
142
150
  }
151
+
143
152
  /**
144
153
  * 在合并单元格后需要校验
145
154
  * 1.如果某个行的所有单元格都不是normal,则需要删除当前行
146
155
  * 2.如果某个列的所有的单元格都不是normal,则需要删除当前列
147
156
  */
148
- static checkRowBeMerged(ss) {
157
+ private static checkRowBeMerged(ss: SelectionState): void {
149
158
  const tb = ElementUtil.getParentByType(ss.startControl, TableElement);
150
- if (!tb) {
151
- return;
152
- }
159
+ if (!tb) { return }
153
160
  const colsCount = tb.getColsCount();
154
- const fullMergeRows = [];
161
+ const fullMergeRows: Array<TableRowElement> = [];
155
162
  for (let i = 0; i < tb.length; i++) {
156
- const row = tb.getChild(i);
163
+ const row = tb.getChild(i) as TableRowElement;
157
164
  let count = 0;
158
165
  for (let j = 0; j < colsCount; j++) {
159
- const cell = row.getChild(j);
166
+ const cell = row.getChild(j) as TableCellElement;
160
167
  if (!cell.isNotBeMergedCell()) {
161
168
  count++;
162
169
  }
163
170
  }
164
171
  //当前行所有的单元格都被合并,需要删除
165
172
  if (count === colsCount) {
166
- fullMergeRows.push(row);
173
+ fullMergeRows.push(row)
167
174
  }
168
175
  }
169
176
  fullMergeRows.forEach(row => this.removeRow(row));
170
177
  }
178
+
171
179
  /**
172
180
  * 移除行
173
- * @param row
181
+ * @param row
174
182
  */
175
- static removeRow(row) {
183
+ private static removeRow(row: TableRowElement): void {
176
184
  const rowIndex = row.getIndex();
177
- const tb = row.parent;
185
+ const tb = row.parent as TableElement;
178
186
  for (let i = 0; i < row.length; i++) {
179
- const cell = row.getChild(i);
187
+ const cell = row.getChild<TableCellElement>(i);
180
188
  if (cell.props.vMerge === 'restart') {
181
189
  const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
182
190
  if (vMergeEndIndex > rowIndex) {
183
- const nextRow = tb.getChild(rowIndex + 1);
184
- nextRow.getChild(i).props.vMerge = vMergeEndIndex - rowIndex > 2 ? 'restart' : null;
191
+ const nextRow = tb.getChild<TableRowElement>(rowIndex + 1);
192
+ nextRow.getChild<TableCellElement>(i).props.vMerge = vMergeEndIndex - rowIndex > 2 ? 'restart' : null;
185
193
  }
186
- }
187
- else if (cell.props.vMerge === 'continue') {
194
+ } else if (cell.props.vMerge === 'continue') {
188
195
  // const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
189
196
  // if (vMergeEndIndex > rowIndex) {
190
197
  // const nextRow = tb.getChild<TableRowElement>(rowIndex + 1);
@@ -194,76 +201,79 @@ export class TableUtil {
194
201
  const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
195
202
  //当前单元格处于合并行的最后一行,并且合并的行数为2行
196
203
  if (vMergeEndIndex === rowIndex && vMergeEndIndex - vMergeStartIndex === 1) {
197
- const aboveCell = tb.getChild(vMergeStartIndex).getChild(i);
204
+ const aboveCell = tb.getChild<TableRowElement>(vMergeStartIndex).getChild<TableCellElement>(i)
198
205
  aboveCell.props.vMerge = null;
199
206
  }
200
207
  }
201
208
  }
202
209
  tb.removeChild(row);
203
210
  }
211
+
204
212
  /**
205
213
  * 移除列
206
- * @param tb
207
- * @param colIndex
214
+ * @param tb
215
+ * @param colIndex
208
216
  */
209
- static removeCol(tb, colIndex) {
217
+ private static removeCol(tb: TableElement, colIndex: number): void {
210
218
  for (let i = 0; i < tb.length; i++) {
211
- const row = tb.getChild(i);
212
- const cell = row.getChild(colIndex);
219
+ const row = tb.getChild<TableRowElement>(i);
220
+ const cell = row.getChild<TableCellElement>(colIndex);
213
221
  if (cell.props.hMerge === 'restart') {
214
222
  const hMergeEndIndex = this.getHMergeEndIndex(tb, i, colIndex);
215
223
  if (hMergeEndIndex > colIndex) {
216
- const nextCell = row.getChild(colIndex + 1);
224
+ const nextCell = row.getChild<TableCellElement>(colIndex + 1);
217
225
  nextCell.props.hMerge = hMergeEndIndex - colIndex > 2 ? 'restart' : null;
218
226
  }
219
- }
220
- else if (cell.props.hMerge === 'continue') {
227
+ } else if (cell.props.hMerge === 'continue') {
221
228
  const hMergeStartIndex = this.getHMergeStartIndex(tb, i, colIndex);
222
229
  const hMergeEndIndex = this.getHMergeEndIndex(tb, i, colIndex);
223
230
  //当前单元格处于合并行的最后一行,并且合并的行数为2行
224
231
  if (hMergeEndIndex === colIndex && hMergeEndIndex - hMergeStartIndex === 1) {
225
- const masterVMergeCell = tb.getChild(hMergeStartIndex).getChild(i);
232
+ const masterVMergeCell = tb.getChild<TableRowElement>(hMergeStartIndex).getChild<TableCellElement>(i)
226
233
  masterVMergeCell.props.hMerge = null;
227
234
  }
235
+
228
236
  }
229
237
  row.removeChild(cell);
230
238
  }
231
239
  tb.removeCol(colIndex);
232
240
  }
241
+
233
242
  /**
234
243
  * 移除光标所在的当前行
235
- * @param ss
244
+ * @param ss
236
245
  */
237
- static removeCurrRow(ss) {
246
+ static removeCurrRow(ss: SelectionState): void {
238
247
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
239
248
  if (!startCell?.parent) {
240
- throw new Error('parent is null');
249
+ throw new Error('parent is null')
241
250
  }
242
- const currRow = startCell.parent;
243
- const tb = currRow.parent;
251
+ const currRow = startCell.parent as TableRowElement;
252
+ const tb = currRow.parent as TableElement;
244
253
  this.removeRow(currRow);
245
254
  tb.pubOnChange('self');
246
255
  tb.refreshView();
247
256
  }
257
+
248
258
  /**
249
259
  * 移除光标所在的当前列
250
- * @param ss
260
+ * @param ss
251
261
  */
252
- static removeCurrCol(ss) {
262
+ static removeCurrCol(ss: SelectionState): void {
253
263
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
254
264
  if (!startCell?.parent) {
255
- throw new Error('parent is null');
265
+ throw new Error('parent is null')
256
266
  }
257
267
  if (ss.collapsed) {
258
- const currRow = startCell.parent;
259
- const tb = currRow.parent;
268
+ const currRow = startCell.parent as TableRowElement;
269
+ const tb = currRow.parent as TableElement;
260
270
  this.removeCol(tb, startCell.getIndex());
261
271
  ss.clear();
262
272
  return;
263
273
  }
264
274
  const { ancestorCommonControl, startControl, endControl } = ss;
265
275
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
266
- const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
276
+ const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent as TableElement;
267
277
  const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
268
278
  const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
269
279
  if (startCell?.parent?.parent === tbElement && endCell?.parent?.parent === tbElement) {
@@ -278,16 +288,17 @@ export class TableUtil {
278
288
  }
279
289
  ss.clear();
280
290
  }
291
+
281
292
  /**
282
293
  * 合并单元格
283
294
  */
284
- static combineCells(tbElement, startCell, endCell) {
295
+ static combineCells(tbElement: TableElement, startCell: TableCellElement, endCell: TableCellElement): void {
285
296
  const tbRegion = this.getTableRectSelectedRegion(tbElement, startCell, endCell);
286
- const cellContents = [];
297
+ const cellContents: Array<Element> = [];
287
298
  for (let i = tbRegion.startRow; i <= tbRegion.endRow; i++) {
288
- const currRow = tbElement.getChild(i);
299
+ const currRow = tbElement.getChild<TableRowElement>(i);
289
300
  for (let j = tbRegion.startCol; j <= tbRegion.endCol; j++) {
290
- const currCell = currRow.getChild(j);
301
+ const currCell = currRow.getChild<TableCellElement>(j);
291
302
  currCell.props.vMerge = null;
292
303
  currCell.props.hMerge = 'continue';
293
304
  if (j === tbRegion.startCol) {
@@ -307,7 +318,9 @@ export class TableUtil {
307
318
  }
308
319
  }
309
320
  }
310
- static canSplitCell(ss) {
321
+
322
+
323
+ static canSplitCell(ss: SelectionState): boolean {
311
324
  const { ancestorCommonControl, startControl, endControl, collapsed } = ss;
312
325
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
313
326
  const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
@@ -318,8 +331,7 @@ export class TableUtil {
318
331
  return startCell.props.hMerge === 'restart' || startCell.props.vMerge === 'restart';
319
332
  }
320
333
  }
321
- }
322
- else {
334
+ } else {
323
335
  const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
324
336
  if (!startCell) {
325
337
  throw new Error('startCell is null');
@@ -327,13 +339,15 @@ export class TableUtil {
327
339
  const { hMerge, vMerge } = startCell?.props;
328
340
  return hMerge === 'restart' || vMerge === 'restart' || !hMerge || !vMerge;
329
341
  }
342
+
330
343
  return false;
331
344
  }
345
+
332
346
  /**
333
347
  * 将合并的单元格合并还原
334
- * @param ss
348
+ * @param ss
335
349
  */
336
- static restoreCell(ss) {
350
+ static restoreCell(ss: SelectionState): void {
337
351
  const { ancestorCommonControl, startControl, endControl, collapsed } = ss;
338
352
  const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
339
353
  if (startCell) {
@@ -342,16 +356,17 @@ export class TableUtil {
342
356
  startCell.refreshView();
343
357
  }
344
358
  }
345
- static restoreCellMerge(cell) {
359
+
360
+ private static restoreCellMerge(cell: TableCellElement): void {
346
361
  const { vMerge, hMerge } = cell.props;
347
- const row = cell.parent;
348
- const tb = row.parent;
362
+ const row = cell.parent as TableRowElement;
363
+ const tb = row.parent as TableElement;
349
364
  const rowIndex = row.getIndex();
350
365
  const colIndex = cell.getIndex();
351
366
  if (vMerge === 'restart') {
352
367
  for (let i = rowIndex + 1; i < tb.length; i++) {
353
- const row = tb.getChild(i);
354
- const cell = row.getChild(colIndex);
368
+ const row = tb.getChild(i) as TableRowElement;
369
+ const cell = row.getChild(colIndex) as TableCellElement;
355
370
  if (cell.props.vMerge === "continue") {
356
371
  cell.props.vMerge = null;
357
372
  if (cell.props.hMerge === "restart") {
@@ -362,7 +377,7 @@ export class TableUtil {
362
377
  }
363
378
  if (hMerge === 'restart') {
364
379
  for (let i = colIndex + 1; i < row.length; i++) {
365
- const cell = row.getChild(i);
380
+ const cell = row.getChild(i) as TableCellElement;
366
381
  if (cell.props.hMerge === "continue") {
367
382
  cell.props.hMerge = null;
368
383
  if (cell.props.vMerge === "restart") {
@@ -374,27 +389,30 @@ export class TableUtil {
374
389
  cell.props.hMerge = null;
375
390
  cell.props.vMerge = null;
376
391
  }
377
- static getVMergeRows(tb, masterRowIndex, masterColIndex) {
378
- const items = [];
392
+
393
+
394
+ private static getVMergeRows(tb: TableElement, masterRowIndex: number, masterColIndex: number): Array<TableRowElement> {
395
+ const items: Array<TableRowElement> = [];
379
396
  for (let i = masterRowIndex + 1; i < tb.length; i++) {
380
- const row = tb.getChild(i);
381
- const cell = row.getChild(masterColIndex);
397
+ const row = <TableRowElement>tb.getChild(i);
398
+ const cell = row.getChild(masterColIndex) as TableCellElement;
382
399
  if (cell.props.vMerge === 'continue') {
383
400
  items.push(row);
384
- }
385
- else {
401
+ } else {
386
402
  return items;
387
403
  }
388
404
  }
389
405
  return items;
390
406
  }
391
- static insertCol(ss, insertColIndex) {
407
+
408
+
409
+ static insertCol(ss: SelectionState, insertColIndex: number): void {
392
410
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
393
411
  if (!startCell?.parent) {
394
- throw new Error('parent is null');
412
+ throw new Error('parent is null')
395
413
  }
396
- const startRow = startCell.parent;
397
- const tb = startRow.parent;
414
+ const startRow = startCell.parent as TableRowElement;
415
+ const tb = startRow.parent as TableElement;
398
416
  const currColIndex = startCell.getIndex();
399
417
  const colsCount = tb.getColsCount();
400
418
  insertColIndex = insertColIndex < 0 ? 0 : insertColIndex;
@@ -403,17 +421,17 @@ export class TableUtil {
403
421
  const insertColWidth = insertColIndex === colsCount ? tb.getCellWidth(colsCount - 1) : tb.getCellWidth(insertColIndex);
404
422
  const newColWidth = Math.floor(insertColWidth / 2);
405
423
  if (newColWidth < 20) {
406
- console.warn('插入列的最小宽度不能小于20,当前为:' + newColWidth);
424
+ console.warn('插入列的最小宽度不能小于20,当前为:' + newColWidth)
407
425
  return;
408
426
  }
409
427
  for (let i = 0; i < tb.length; i++) {
410
- const row = tb.getChild(i);
428
+ const row = tb.getChild<TableRowElement>(i)
411
429
  const newCell = new TableCellElement();
412
430
  if (insertColIndex === 0 || insertColIndex === colsCount) {
413
431
  row.addChild(newCell, insertColIndex);
414
432
  continue;
415
433
  }
416
- const focusCell = row.getChild(insertColIndex);
434
+ const focusCell = row.getChild<TableCellElement>(insertColIndex);
417
435
  if (focusCell) {
418
436
  if (focusCell.props.hMerge === 'continue') {
419
437
  //获取合并行的最后的行索引
@@ -421,25 +439,26 @@ export class TableUtil {
421
439
  if (hMergeEndColIndex > insertColIndex || (hMergeEndColIndex === insertColIndex && currColIndex < insertColIndex)) {
422
440
  newCell.props.hMerge = 'continue';
423
441
  }
424
- }
425
- else if (focusCell.props.hMerge === 'restart' && currColIndex > insertColIndex) {
442
+ } else if (focusCell.props.hMerge === 'restart' && currColIndex > insertColIndex) {
426
443
  newCell.props.hMerge = 'continue';
427
444
  }
428
445
  }
429
446
  row.addChild(newCell, insertColIndex);
430
447
  }
448
+
431
449
  tb.setCellWidth(insertColIndex === colsCount ? insertColIndex - 1 : insertColIndex, insertColWidth - newColWidth);
432
450
  tb.insertCol(insertColIndex, newColWidth);
433
451
  tb.pubOnChange('self');
434
452
  tb.refreshView();
435
453
  }
436
- static insertRow(ss, insertRowIndex) {
454
+
455
+ static insertRow(ss: SelectionState, insertRowIndex: number): TableRowElement {
437
456
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
438
457
  if (!startCell?.parent) {
439
- throw new Error('parent is null');
458
+ throw new Error('parent is null')
440
459
  }
441
- const startRow = startCell.parent;
442
- const tb = startRow.parent;
460
+ const startRow = startCell.parent as TableRowElement;
461
+ const tb = startRow.parent as TableElement;
443
462
  const currRowIndex = startRow.getIndex();
444
463
  insertRowIndex = insertRowIndex < 0 ? 0 : insertRowIndex;
445
464
  insertRowIndex = insertRowIndex > tb.length ? tb.length : insertRowIndex;
@@ -450,10 +469,10 @@ export class TableUtil {
450
469
  tb.refreshView();
451
470
  return newRow;
452
471
  }
453
- const destRow = tb.getChild(insertRowIndex);
472
+ const destRow = tb.getChild(insertRowIndex) as TableRowElement;
454
473
  for (let i = 0; i < destRow.length; i++) {
455
- const destCell = destRow.getChild(i);
456
- const newCell = newRow.getChild(i);
474
+ const destCell = destRow.getChild(i) as TableCellElement;
475
+ const newCell = newRow.getChild(i) as TableCellElement;
457
476
  //如果当前单元格是普通单元格或者合并列的最后一个单元格,则不做处理
458
477
  if (destCell.props.vMerge === 'continue') {
459
478
  //获取合并列的最后的行索引
@@ -462,71 +481,76 @@ export class TableUtil {
462
481
  newCell.props.vMerge = 'continue';
463
482
  //newCell.cellProps.hMerge = destCell.cellProps.hMerge;
464
483
  }
465
- }
466
- else if (destCell.props.vMerge === 'restart' && currRowIndex > insertRowIndex) {
484
+ } else if (destCell.props.vMerge === 'restart' && currRowIndex > insertRowIndex) {
467
485
  //在上方新增行,目标行单元格属于合并的起点
468
486
  newCell.props.vMerge = 'continue';
469
487
  //newCell.cellProps.hMerge = destCell.cellProps.hMerge;
470
488
  }
489
+
471
490
  }
472
491
  tb.addChild(newRow, insertRowIndex);
473
492
  tb.refreshView();
474
493
  return newRow;
475
494
  }
495
+
476
496
  /**
477
497
  * 在下方插入行
478
498
  */
479
- static insertRowBelow(ss) {
499
+ static insertRowBelow(ss: SelectionState): void {
480
500
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
481
501
  if (!startCell?.parent) {
482
- throw new Error('parent is null');
502
+ throw new Error('parent is null')
483
503
  }
484
- const startRow = startCell.parent;
504
+ const startRow = startCell.parent as TableRowElement;
485
505
  const currRowIndex = startRow.getIndex();
486
506
  this.insertRow(ss, currRowIndex + 1);
487
507
  }
508
+
488
509
  /**
489
510
  * 在上方插入行
490
511
  */
491
- static insertRowAbove(ss) {
512
+ static insertRowAbove(ss: SelectionState): void {
492
513
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
493
514
  if (!startCell?.parent) {
494
- throw new Error('parent is null');
515
+ throw new Error('parent is null')
495
516
  }
496
- const startRow = startCell.parent;
517
+ const startRow = startCell.parent as TableRowElement;
497
518
  const currRowIndex = startRow.getIndex();
498
519
  this.insertRow(ss, currRowIndex);
499
520
  }
521
+
500
522
  /**
501
523
  * 在右侧插入列
502
524
  */
503
- static insertColToRight(ss) {
525
+ static insertColToRight(ss: SelectionState): void {
504
526
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
505
527
  if (!startCell?.parent) {
506
- throw new Error('parent is null');
528
+ throw new Error('parent is null')
507
529
  }
508
530
  const currColIndex = startCell.getIndex();
509
531
  this.insertCol(ss, currColIndex + 1);
510
532
  }
533
+
511
534
  /**
512
535
  * 在左侧插入列
513
536
  */
514
- static insertColToLeft(ss) {
537
+ static insertColToLeft(ss: SelectionState): void {
515
538
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
516
539
  if (!startCell?.parent) {
517
- throw new Error('parent is null');
540
+ throw new Error('parent is null')
518
541
  }
519
542
  const currColIndex = startCell.getIndex();
520
543
  this.insertCol(ss, currColIndex);
521
544
  }
545
+
522
546
  /**
523
547
  * 跳转到下一个单元格中
524
- * @param ss
548
+ * @param ss
525
549
  */
526
- static moveNextCell(ss) {
550
+ static moveNextCell(ss: SelectionState): void {
527
551
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
528
552
  if (!startCell?.parent) {
529
- throw new Error('parent is null');
553
+ throw new Error('parent is null')
530
554
  }
531
555
  const rowIndex = startCell.parent.getIndex();
532
556
  const nextCell = this.getNextCell(ss);
@@ -540,24 +564,26 @@ export class TableUtil {
540
564
  ss.resetRange(newRow, 0);
541
565
  newRow.refreshView();
542
566
  }
567
+
568
+
543
569
  /**
544
570
  * 获取下一个可定位的单元格
545
- * @param ss
546
- * @returns
571
+ * @param ss
572
+ * @returns
547
573
  */
548
- static getNextCell(ss) {
574
+ static getNextCell(ss: SelectionState): TableCellElement | undefined {
549
575
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
550
576
  if (!startCell?.parent) {
551
- throw new Error('parent is null');
577
+ throw new Error('parent is null')
552
578
  }
553
579
  const rowIndex = startCell.parent.getIndex();
554
580
  const colIndex = startCell.getIndex();
555
- const tb = startCell.parent.parent;
581
+ const tb = startCell.parent.parent as TableElement;
556
582
  for (let i = rowIndex; i < tb.length; i++) {
557
583
  let j = i === rowIndex ? colIndex + 1 : 0;
558
- const currRow = tb.getChild(i);
584
+ const currRow = tb.getChild(i) as TableRowElement;
559
585
  for (; j < tb.getColsCount(); j++) {
560
- const currCell = currRow.getChild(j);
586
+ const currCell = currRow.getChild(j) as TableCellElement;
561
587
  if (currCell.isNotBeMergedCell()) {
562
588
  return currCell;
563
589
  }
@@ -565,16 +591,19 @@ export class TableUtil {
565
591
  }
566
592
  //throw new Error('getNextCell is null')
567
593
  }
594
+
568
595
  /**
569
596
  * 当前光标是否在最后一个单元格中
570
597
  */
571
- static isLastVisiableCell(ss) {
598
+ static isLastVisiableCell(ss: SelectionState): boolean {
572
599
  return !this.getNextCell(ss);
573
600
  }
601
+
602
+
574
603
  /**
575
604
  * 移除当前table
576
605
  */
577
- static removeTable(ss) {
606
+ static removeTable(ss: SelectionState): void {
578
607
  const tb = ElementUtil.getParentByType(ss.startControl, TableElement);
579
608
  if (!tb) {
580
609
  console.warn('当前位置不存在表格');
@@ -583,36 +612,37 @@ export class TableUtil {
583
612
  tb.parent.refreshView();
584
613
  tb.remove();
585
614
  }
615
+
586
616
  /**
587
617
  * 设置表格单元格对角线
588
- * @param ss
589
- * @param diagonal
590
- * @returns
618
+ * @param ss
619
+ * @param diagonal
620
+ * @returns
591
621
  */
592
- static setTableCellDiagonal(ss, diagonal) {
622
+ static setTableCellDiagonal(ss: SelectionState, diagonal: 'main' | 'sub'): void {
593
623
  const tc = ElementUtil.getParentByType(ss.startControl, TableCellElement);
594
624
  if (!tc) {
595
625
  console.warn('当前位置不存在表格');
596
- return;
626
+ return
597
627
  }
598
628
  if (!tc.props.diagonal || tc.props.diagonal !== diagonal) {
599
629
  tc.props.diagonal = diagonal;
600
- }
601
- else if (tc.props.diagonal === diagonal) {
630
+ } else if (tc.props.diagonal === diagonal) {
602
631
  tc.props.diagonal = null;
603
632
  }
604
633
  tc.refreshView();
605
634
  }
635
+
606
636
  /**
607
637
  * 将当前表格截断成两个相邻的表格
608
- * @param tb
609
- * @param rowIndex
638
+ * @param tb
639
+ * @param rowIndex
610
640
  */
611
- static cutTable(tb, rowIndex) {
641
+ static cutTable(tb: TableElement, rowIndex: number): void {
612
642
  if (rowIndex === 0 || rowIndex === tb.length - 1) {
613
643
  return;
614
644
  }
615
- const newTb = tb.clone(false);
645
+ const newTb = tb.clone(false) as TableElement;
616
646
  const len = tb.length - 1;
617
647
  while (len > rowIndex) {
618
648
  const child = tb.getChild(len);
@@ -623,14 +653,15 @@ export class TableUtil {
623
653
  tb.parent.addChild(newTb, tb.getIndex() + 1);
624
654
  }
625
655
  }
656
+
626
657
  /**
627
658
  * 获取表格选区区域最大的矩形区域
628
- * @param tb
629
- * @param startCell
630
- * @param endCell
631
- * @returns
659
+ * @param tb
660
+ * @param startCell
661
+ * @param endCell
662
+ * @returns
632
663
  */
633
- static getTableRectSelectedRegion(tb, startCell, endCell) {
664
+ static getTableRectSelectedRegion(tb: TableElement, startCell: TableCellElement, endCell: TableCellElement): ITableSelectedRegion {
634
665
  let startRow = startCell.parent.getIndex();
635
666
  let startCol = startCell.getIndex();
636
667
  let endRow = endCell.parent.getIndex();
@@ -642,9 +673,9 @@ export class TableUtil {
642
673
  [endCol, startCol] = [startCol, endCol];
643
674
  }
644
675
  for (let i = startRow; i <= endRow; i++) {
645
- const row = tb.getChild(i);
676
+ const row = tb.getChild(i) as TableRowElement;
646
677
  for (let j = startCol; j <= endCol; j++) {
647
- const cell = row.getChild(j);
678
+ const cell = row.getChild(j) as TableCellElement;
648
679
  const { hMerge, vMerge } = cell.props;
649
680
  if (hMerge === 'continue') {
650
681
  const startColIndex = TableUtil.getHMergeStartIndex(tb, i, j);
@@ -672,7 +703,14 @@ export class TableUtil {
672
703
  }
673
704
  }
674
705
  }
675
- return { startRow, endRow, startCol, endCol };
706
+ return { startRow, endRow, startCol, endCol }
676
707
  }
677
708
  }
678
- //# sourceMappingURL=table-util.js.map
709
+
710
+
711
+ export interface ITableSelectedRegion {
712
+ startRow: number;
713
+ endRow: number;
714
+ startCol: number;
715
+ endCol: number;
716
+ }