@hailin-zheng/editor-core 1.0.10 → 1.0.14

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 (300) hide show
  1. package/lib/doc-ruler.d.ts +51 -0
  2. package/lib/doc-ruler.js +313 -0
  3. package/lib/doc-ruler.js.map +1 -0
  4. package/lib/framework/common-util.d.ts +63 -0
  5. package/lib/framework/common-util.js +178 -0
  6. package/lib/framework/common-util.js.map +1 -0
  7. package/lib/framework/document-change.d.ts +265 -0
  8. package/lib/framework/document-change.js +1342 -0
  9. package/lib/framework/document-change.js.map +1 -0
  10. package/lib/framework/document-combine.d.ts +24 -0
  11. package/lib/framework/document-combine.js +40 -0
  12. package/lib/framework/document-combine.js.map +1 -0
  13. package/lib/framework/document-comment.d.ts +46 -0
  14. package/lib/framework/document-comment.js +148 -0
  15. package/lib/framework/document-comment.js.map +1 -0
  16. package/lib/framework/document-context.d.ts +149 -0
  17. package/lib/framework/document-context.js +330 -0
  18. package/lib/framework/document-context.js.map +1 -0
  19. package/lib/framework/document-eval-func.d.ts +18 -0
  20. package/lib/framework/document-eval-func.js +48 -0
  21. package/lib/framework/document-eval-func.js.map +1 -0
  22. package/lib/framework/document-event.d.ts +213 -0
  23. package/lib/framework/document-event.js +1054 -0
  24. package/lib/framework/document-event.js.map +1 -0
  25. package/lib/framework/document-history.d.ts +26 -0
  26. package/lib/framework/document-history.js +65 -0
  27. package/lib/framework/document-history.js.map +1 -0
  28. package/lib/framework/document-images-loader.d.ts +16 -0
  29. package/lib/framework/document-images-loader.js +66 -0
  30. package/lib/framework/document-images-loader.js.map +1 -0
  31. package/lib/framework/document-input-cursor.d.ts +78 -0
  32. package/lib/framework/document-input-cursor.js +239 -0
  33. package/lib/framework/document-input-cursor.js.map +1 -0
  34. package/lib/framework/document-paint.d.ts +34 -0
  35. package/lib/framework/document-paint.js +103 -0
  36. package/lib/framework/document-paint.js.map +1 -0
  37. package/lib/framework/document-print-offscreen.d.ts +38 -0
  38. package/lib/framework/document-print-offscreen.js +128 -0
  39. package/lib/framework/document-print-offscreen.js.map +1 -0
  40. package/lib/framework/document-print.d.ts +60 -0
  41. package/lib/framework/document-print.js +203 -0
  42. package/lib/framework/document-print.js.map +1 -0
  43. package/lib/framework/document-segmenter.d.ts +2 -0
  44. package/lib/framework/document-segmenter.js +106 -0
  45. package/lib/framework/document-segmenter.js.map +1 -0
  46. package/lib/framework/document-selection.d.ts +89 -0
  47. package/lib/framework/document-selection.js +358 -0
  48. package/lib/framework/document-selection.js.map +1 -0
  49. package/lib/framework/document-template.d.ts +4 -0
  50. package/lib/framework/document-template.js +20 -0
  51. package/lib/framework/document-template.js.map +1 -0
  52. package/lib/framework/document-textline-mode.d.ts +7 -0
  53. package/lib/framework/document-textline-mode.js +30 -0
  54. package/lib/framework/document-textline-mode.js.map +1 -0
  55. package/lib/framework/element-define.d.ts +319 -0
  56. package/lib/framework/element-define.js +579 -0
  57. package/lib/framework/element-define.js.map +1 -0
  58. package/lib/framework/element-event-define.d.ts +98 -0
  59. package/lib/framework/element-event-define.js +108 -0
  60. package/lib/framework/element-event-define.js.map +1 -0
  61. package/lib/framework/element-measure.d.ts +97 -0
  62. package/lib/framework/element-measure.js +551 -0
  63. package/lib/framework/element-measure.js.map +1 -0
  64. package/lib/framework/element-paint.d.ts +42 -0
  65. package/lib/framework/element-paint.js +170 -0
  66. package/lib/framework/element-paint.js.map +1 -0
  67. package/lib/framework/element-props.d.ts +301 -0
  68. package/lib/framework/element-props.js +809 -0
  69. package/lib/framework/element-props.js.map +1 -0
  70. package/lib/framework/element-reader.d.ts +19 -0
  71. package/lib/framework/element-reader.js +151 -0
  72. package/lib/framework/element-reader.js.map +1 -0
  73. package/lib/framework/element-render-cut.d.ts +55 -0
  74. package/lib/framework/element-render-cut.js +449 -0
  75. package/lib/framework/element-render-cut.js.map +1 -0
  76. package/lib/framework/element-serialize.d.ts +30 -0
  77. package/lib/framework/element-serialize.js +113 -0
  78. package/lib/framework/element-serialize.js.map +1 -0
  79. package/lib/framework/element-util.d.ts +369 -0
  80. package/lib/framework/element-util.js +1463 -0
  81. package/lib/framework/element-util.js.map +1 -0
  82. package/lib/framework/impl/checkbox/checkbox-impl.d.ts +24 -0
  83. package/lib/framework/impl/checkbox/checkbox-impl.js +64 -0
  84. package/lib/framework/impl/checkbox/checkbox-impl.js.map +1 -0
  85. package/lib/framework/impl/comments/comment-content-impl.d.ts +40 -0
  86. package/lib/framework/impl/comments/comment-content-impl.js +105 -0
  87. package/lib/framework/impl/comments/comment-content-impl.js.map +1 -0
  88. package/lib/framework/impl/comments/comment-element-impl.d.ts +21 -0
  89. package/lib/framework/impl/comments/comment-element-impl.js +62 -0
  90. package/lib/framework/impl/comments/comment-element-impl.js.map +1 -0
  91. package/lib/framework/impl/comments/comments-container-impl.d.ts +22 -0
  92. package/lib/framework/impl/comments/comments-container-impl.js +62 -0
  93. package/lib/framework/impl/comments/comments-container-impl.js.map +1 -0
  94. package/lib/framework/impl/comments/comments-util.d.ts +12 -0
  95. package/lib/framework/impl/comments/comments-util.js +67 -0
  96. package/lib/framework/impl/comments/comments-util.js.map +1 -0
  97. package/lib/framework/impl/comments/validate-msg-impl.d.ts +21 -0
  98. package/lib/framework/impl/comments/validate-msg-impl.js +83 -0
  99. package/lib/framework/impl/comments/validate-msg-impl.js.map +1 -0
  100. package/lib/framework/impl/data-element/data-decorate-impl.d.ts +30 -0
  101. package/lib/framework/impl/data-element/data-decorate-impl.js +91 -0
  102. package/lib/framework/impl/data-element/data-decorate-impl.js.map +1 -0
  103. package/lib/framework/impl/data-element/data-element-barcode.d.ts +31 -0
  104. package/lib/framework/impl/data-element/data-element-barcode.js +115 -0
  105. package/lib/framework/impl/data-element/data-element-barcode.js.map +1 -0
  106. package/lib/framework/impl/data-element/data-element-base-impl.d.ts +68 -0
  107. package/lib/framework/impl/data-element/data-element-base-impl.js +205 -0
  108. package/lib/framework/impl/data-element/data-element-base-impl.js.map +1 -0
  109. package/lib/framework/impl/data-element/data-element-check-impl.d.ts +35 -0
  110. package/lib/framework/impl/data-element/data-element-check-impl.js +133 -0
  111. package/lib/framework/impl/data-element/data-element-check-impl.js.map +1 -0
  112. package/lib/framework/impl/data-element/data-element-date-impl.d.ts +23 -0
  113. package/lib/framework/impl/data-element/data-element-date-impl.js +111 -0
  114. package/lib/framework/impl/data-element/data-element-date-impl.js.map +1 -0
  115. package/lib/framework/impl/data-element/data-element-group-impl.d.ts +23 -0
  116. package/lib/framework/impl/data-element/data-element-group-impl.js +130 -0
  117. package/lib/framework/impl/data-element/data-element-group-impl.js.map +1 -0
  118. package/lib/framework/impl/data-element/data-element-image-impl.d.ts +30 -0
  119. package/lib/framework/impl/data-element/data-element-image-impl.js +137 -0
  120. package/lib/framework/impl/data-element/data-element-image-impl.js.map +1 -0
  121. package/lib/framework/impl/data-element/data-element-list-impl.d.ts +22 -0
  122. package/lib/framework/impl/data-element/data-element-list-impl.js +131 -0
  123. package/lib/framework/impl/data-element/data-element-list-impl.js.map +1 -0
  124. package/lib/framework/impl/data-element/data-element-text-impl.d.ts +23 -0
  125. package/lib/framework/impl/data-element/data-element-text-impl.js +103 -0
  126. package/lib/framework/impl/data-element/data-element-text-impl.js.map +1 -0
  127. package/lib/framework/impl/decorate/fill-null-space-imple.d.ts +21 -0
  128. package/lib/framework/impl/decorate/fill-null-space-imple.js +43 -0
  129. package/lib/framework/impl/decorate/fill-null-space-imple.js.map +1 -0
  130. package/lib/framework/impl/document/doc-body-impl.d.ts +27 -0
  131. package/lib/framework/impl/document/doc-body-impl.js +79 -0
  132. package/lib/framework/impl/document/doc-body-impl.js.map +1 -0
  133. package/lib/framework/impl/document/doc-body-part-impl.d.ts +30 -0
  134. package/lib/framework/impl/document/doc-body-part-impl.js +94 -0
  135. package/lib/framework/impl/document/doc-body-part-impl.js.map +1 -0
  136. package/lib/framework/impl/document/doc-container-impl.d.ts +16 -0
  137. package/lib/framework/impl/document/doc-container-impl.js +21 -0
  138. package/lib/framework/impl/document/doc-container-impl.js.map +1 -0
  139. package/lib/framework/impl/document/doc-footer-impl.d.ts +26 -0
  140. package/lib/framework/impl/document/doc-footer-impl.js +77 -0
  141. package/lib/framework/impl/document/doc-footer-impl.js.map +1 -0
  142. package/lib/framework/impl/document/doc-header-impl.d.ts +26 -0
  143. package/lib/framework/impl/document/doc-header-impl.js +83 -0
  144. package/lib/framework/impl/document/doc-header-impl.js.map +1 -0
  145. package/lib/framework/impl/document/doc-impl.d.ts +61 -0
  146. package/lib/framework/impl/document/doc-impl.js +209 -0
  147. package/lib/framework/impl/document/doc-impl.js.map +1 -0
  148. package/lib/framework/impl/media-formula/menstrual-history.d.ts +35 -0
  149. package/lib/framework/impl/media-formula/menstrual-history.js +153 -0
  150. package/lib/framework/impl/media-formula/menstrual-history.js.map +1 -0
  151. package/lib/framework/impl/paragraph/p-impl.d.ts +45 -0
  152. package/lib/framework/impl/paragraph/p-impl.js +156 -0
  153. package/lib/framework/impl/paragraph/p-impl.js.map +1 -0
  154. package/lib/framework/impl/picture/image-impl.d.ts +31 -0
  155. package/lib/framework/impl/picture/image-impl.js +124 -0
  156. package/lib/framework/impl/picture/image-impl.js.map +1 -0
  157. package/lib/framework/impl/radio/radio-impl.d.ts +22 -0
  158. package/lib/framework/impl/radio/radio-impl.js +72 -0
  159. package/lib/framework/impl/radio/radio-impl.js.map +1 -0
  160. package/lib/framework/impl/symbol/br-symbol-impl.d.ts +22 -0
  161. package/lib/framework/impl/symbol/br-symbol-impl.js +54 -0
  162. package/lib/framework/impl/symbol/br-symbol-impl.js.map +1 -0
  163. package/lib/framework/impl/symbol/p-symbol-impl.d.ts +19 -0
  164. package/lib/framework/impl/symbol/p-symbol-impl.js +54 -0
  165. package/lib/framework/impl/symbol/p-symbol-impl.js.map +1 -0
  166. package/lib/framework/impl/table/table-cell-impl.d.ts +37 -0
  167. package/lib/framework/impl/table/table-cell-impl.js +145 -0
  168. package/lib/framework/impl/table/table-cell-impl.js.map +1 -0
  169. package/lib/framework/impl/table/table-impl.d.ts +55 -0
  170. package/lib/framework/impl/table/table-impl.js +363 -0
  171. package/lib/framework/impl/table/table-impl.js.map +1 -0
  172. package/lib/framework/impl/table/table-row-impl.d.ts +26 -0
  173. package/lib/framework/impl/table/table-row-impl.js +75 -0
  174. package/lib/framework/impl/table/table-row-impl.js.map +1 -0
  175. package/lib/framework/impl/table/table-split-cell-patch.d.ts +20 -0
  176. package/lib/framework/impl/table/table-split-cell-patch.js +89 -0
  177. package/lib/framework/impl/table/table-split-cell-patch.js.map +1 -0
  178. package/lib/framework/impl/table/table-split-cell.d.ts +90 -0
  179. package/lib/framework/impl/table/table-split-cell.js +464 -0
  180. package/lib/framework/impl/table/table-split-cell.js.map +1 -0
  181. package/lib/framework/impl/table/table-util.d.ts +150 -0
  182. package/lib/framework/impl/table/table-util.js +678 -0
  183. package/lib/framework/impl/table/table-util.js.map +1 -0
  184. package/lib/framework/impl/text/text-impl.d.ts +32 -0
  185. package/lib/framework/impl/text/text-impl.js +149 -0
  186. package/lib/framework/impl/text/text-impl.js.map +1 -0
  187. package/lib/framework/impl/text/track-run-impl.d.ts +27 -0
  188. package/lib/framework/impl/text/track-run-impl.js +112 -0
  189. package/lib/framework/impl/text/track-run-impl.js.map +1 -0
  190. package/lib/framework/notify.d.ts +13 -0
  191. package/lib/framework/notify.js +116 -0
  192. package/lib/framework/notify.js.map +1 -0
  193. package/lib/framework/range-util.d.ts +40 -0
  194. package/lib/framework/range-util.js +312 -0
  195. package/lib/framework/range-util.js.map +1 -0
  196. package/lib/framework/render-context.d.ts +91 -0
  197. package/lib/framework/render-context.js +384 -0
  198. package/lib/framework/render-context.js.map +1 -0
  199. package/lib/framework/render-define.d.ts +109 -0
  200. package/lib/framework/render-define.js +195 -0
  201. package/lib/framework/render-define.js.map +1 -0
  202. package/lib/framework/selection-overlays.d.ts +30 -0
  203. package/lib/framework/selection-overlays.js +124 -0
  204. package/lib/framework/selection-overlays.js.map +1 -0
  205. package/lib/texteditor.d.ts +318 -0
  206. package/lib/texteditor.js +913 -0
  207. package/lib/texteditor.js.map +1 -0
  208. package/lib/util/subject.d.ts +34 -0
  209. package/lib/util/subject.js +88 -0
  210. package/lib/util/subject.js.map +1 -0
  211. package/{src/med_editor/util/table-bind.ts → lib/util/table-bind.d.ts} +2 -3
  212. package/lib/util/table-bind.js +6 -0
  213. package/lib/util/table-bind.js.map +1 -0
  214. package/package.json +2 -2
  215. package/src/med_editor/doc-ruler.ts +0 -340
  216. package/src/med_editor/framework/common-util.ts +0 -200
  217. package/src/med_editor/framework/document-change.ts +0 -1391
  218. package/src/med_editor/framework/document-combine.ts +0 -44
  219. package/src/med_editor/framework/document-comment.ts +0 -163
  220. package/src/med_editor/framework/document-context.ts +0 -410
  221. package/src/med_editor/framework/document-eval-func.ts +0 -53
  222. package/src/med_editor/framework/document-event.ts +0 -1082
  223. package/src/med_editor/framework/document-history.ts +0 -76
  224. package/src/med_editor/framework/document-images-loader.ts +0 -74
  225. package/src/med_editor/framework/document-input-cursor.ts +0 -244
  226. package/src/med_editor/framework/document-paint.ts +0 -110
  227. package/src/med_editor/framework/document-print-offscreen.ts +0 -134
  228. package/src/med_editor/framework/document-print.ts +0 -219
  229. package/src/med_editor/framework/document-segmenter.ts +0 -211
  230. package/src/med_editor/framework/document-selection.ts +0 -389
  231. package/src/med_editor/framework/document-template.ts +0 -20
  232. package/src/med_editor/framework/document-textline-mode.ts +0 -34
  233. package/src/med_editor/framework/element-define.ts +0 -674
  234. package/src/med_editor/framework/element-event-define.ts +0 -141
  235. package/src/med_editor/framework/element-measure.ts +0 -573
  236. package/src/med_editor/framework/element-paint.ts +0 -176
  237. package/src/med_editor/framework/element-props.ts +0 -938
  238. package/src/med_editor/framework/element-reader.ts +0 -159
  239. package/src/med_editor/framework/element-render-cut.ts +0 -456
  240. package/src/med_editor/framework/element-serialize.ts +0 -126
  241. package/src/med_editor/framework/element-util.ts +0 -1564
  242. package/src/med_editor/framework/impl/checkbox/checkbox-impl.ts +0 -71
  243. package/src/med_editor/framework/impl/comments/comment-content-impl.ts +0 -119
  244. package/src/med_editor/framework/impl/comments/comment-element-impl.ts +0 -65
  245. package/src/med_editor/framework/impl/comments/comments-container-impl.ts +0 -68
  246. package/src/med_editor/framework/impl/comments/comments-util.ts +0 -84
  247. package/src/med_editor/framework/impl/comments/validate-msg-impl.ts +0 -94
  248. package/src/med_editor/framework/impl/data-element/data-decorate-impl.ts +0 -95
  249. package/src/med_editor/framework/impl/data-element/data-element-barcode.ts +0 -127
  250. package/src/med_editor/framework/impl/data-element/data-element-base-impl.ts +0 -234
  251. package/src/med_editor/framework/impl/data-element/data-element-check-impl.ts +0 -146
  252. package/src/med_editor/framework/impl/data-element/data-element-date-impl.ts +0 -128
  253. package/src/med_editor/framework/impl/data-element/data-element-group-impl.ts +0 -150
  254. package/src/med_editor/framework/impl/data-element/data-element-image-impl.ts +0 -147
  255. package/src/med_editor/framework/impl/data-element/data-element-list-impl.ts +0 -142
  256. package/src/med_editor/framework/impl/data-element/data-element-text-impl.ts +0 -117
  257. package/src/med_editor/framework/impl/decorate/fill-null-space-imple.ts +0 -48
  258. package/src/med_editor/framework/impl/document/doc-body-impl.ts +0 -95
  259. package/src/med_editor/framework/impl/document/doc-body-part-impl.ts +0 -104
  260. package/src/med_editor/framework/impl/document/doc-container-impl.ts +0 -24
  261. package/src/med_editor/framework/impl/document/doc-footer-impl.ts +0 -88
  262. package/src/med_editor/framework/impl/document/doc-header-impl.ts +0 -100
  263. package/src/med_editor/framework/impl/document/doc-impl.ts +0 -226
  264. package/src/med_editor/framework/impl/media-formula/menstrual-history.ts +0 -175
  265. package/src/med_editor/framework/impl/paragraph/p-impl.ts +0 -190
  266. package/src/med_editor/framework/impl/picture/image-impl.ts +0 -136
  267. package/src/med_editor/framework/impl/radio/radio-impl.ts +0 -79
  268. package/src/med_editor/framework/impl/symbol/br-symbol-impl.ts +0 -60
  269. package/src/med_editor/framework/impl/symbol/p-symbol-impl.ts +0 -57
  270. package/src/med_editor/framework/impl/table/table-cell-impl.ts +0 -156
  271. package/src/med_editor/framework/impl/table/table-impl.ts +0 -401
  272. package/src/med_editor/framework/impl/table/table-row-impl.ts +0 -83
  273. package/src/med_editor/framework/impl/table/table-split-cell-patch.ts +0 -98
  274. package/src/med_editor/framework/impl/table/table-split-cell.ts +0 -475
  275. package/src/med_editor/framework/impl/table/table-util.ts +0 -716
  276. package/src/med_editor/framework/impl/text/text-impl.ts +0 -163
  277. package/src/med_editor/framework/impl/text/track-run-impl.ts +0 -135
  278. package/src/med_editor/framework/notify.ts +0 -130
  279. package/src/med_editor/framework/range-util.ts +0 -321
  280. package/src/med_editor/framework/render-context.ts +0 -431
  281. package/src/med_editor/framework/render-define.ts +0 -224
  282. package/src/med_editor/framework/selection-overlays.ts +0 -133
  283. package/src/med_editor/texteditor.ts +0 -1010
  284. package/src/med_editor/util/subject.ts +0 -118
  285. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225.json +0 -3573
  286. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225.json +0 -3573
  287. package/src/med_editor//345/205/245/351/231/242/350/256/260/345/275/225/346/265/213/350/257/225bug.json +0 -315
  288. 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 +0 -122
  289. 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 +0 -3599
  290. 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 +0 -24586
  291. package/src/med_editor//345/220/210/345/271/266/347/227/205/347/250/213/345/275/225.json +0 -2874
  292. package/src/med_editor//346/211/213/346/234/257/350/256/260/345/275/225.json +0 -341
  293. package/src/med_editor//346/231/256/351/200/232doc/347/261/273/346/226/207/346/241/243.json +0 -2201
  294. package/src/med_editor//346/243/200/351/252/214/347/224/263/350/257/267/345/215/225.json +0 -1069
  295. 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 +0 -125
  296. 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 +0 -86
  297. 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 +0 -115
  298. 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 +0 -108
  299. 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 +0 -272
  300. package/src/med_editor//351/225/277/346/234/237/345/214/273/345/230/261/345/215/225.json +0 -1070
@@ -1,98 +0,0 @@
1
- export interface ColumnPartOffset extends ColumnPart { offset: number }
2
- export interface ColumnPart { index: number, width: number }
3
- export interface ColumnPatch { type: 'modify' | 'insert', data: ColumnPart }
4
- export class ColumnPatchUtil {
5
- static getPatchPacks(cols: Array<ColumnPart>, splitCols: Array<ColumnPart>): [Array<{ part: ColumnPartOffset, patchs: Array<ColumnPatch> }>, Array<Array<ColumnPart>>] {
6
- const oldLinePointMap = this.getLinePointMap(cols);
7
- //要分割的列坐标
8
- const newLinePointMap = this.getLinePointMap(splitCols);
9
- const resArray: Set<number> = new Set();
10
- const allPointMap = oldLinePointMap.concat(newLinePointMap);
11
- for (let i = 0; i < allPointMap.length; i++) {
12
- const part = allPointMap[i];
13
- resArray.add(part.offset);
14
- resArray.add(part.offset + part.width);
15
- }
16
- const points = Array.from(resArray).sort((first, second) => first - second);
17
- const patchs: Array<{ part: ColumnPartOffset, patchs: Array<ColumnPatch> }> = [];
18
- //获取其他行的拆分补丁
19
- for (let i = 0; i < points.length - 1; i++) {
20
- const partStartOffset = points[i];
21
- const partEndOffset = points[i + 1];
22
- const joinPart = oldLinePointMap.find(item => {
23
- const startOffset = item.offset;
24
- const endOffset = item.offset + item.width;
25
- return (
26
- (startOffset >= partStartOffset && startOffset < partEndOffset)
27
- ||
28
- (endOffset > partStartOffset && endOffset <= partEndOffset)
29
- ||
30
- (startOffset <= partStartOffset && endOffset >= partEndOffset)
31
- )
32
- });
33
- if (joinPart) {
34
- if (joinPart.offset === partStartOffset && joinPart.offset + joinPart.width === partEndOffset) {
35
- continue;
36
- }
37
- const patch = patchs.find(item => item.part === joinPart);
38
- if (patch) {
39
- patch.patchs.push({ type: 'insert', data: { width: partEndOffset - partStartOffset, index: joinPart.index } })
40
- } else {
41
- patchs.push({
42
- part: joinPart,
43
- patchs: [{ type: 'modify', data: { width: partEndOffset - partStartOffset, index: joinPart.index } }]
44
- })
45
- }
46
- }
47
- }
48
- //获取当前行的拆分补丁
49
- const currRowPaths: Array<Array<ColumnPart>> = [];
50
- const allColumnMap = this.getLinePointMap(this.getColumn(points));
51
- for (let i = 0; i < newLinePointMap.length; i++) {
52
- const partStartOffset = newLinePointMap[i].offset;
53
- const partEndOffset = newLinePointMap[i].offset + newLinePointMap[i].width;
54
- const joinParts = allColumnMap.filter(item => {
55
- const startOffset = item.offset;
56
- const endOffset = item.offset + item.width;
57
- return (
58
- (startOffset >= partStartOffset && startOffset < partEndOffset)
59
- ||
60
- (endOffset > partStartOffset && endOffset <= partEndOffset)
61
- ||
62
- (startOffset <= partStartOffset && endOffset >= partEndOffset)
63
- )
64
- });
65
- currRowPaths.push(joinParts);
66
- }
67
- return [patchs, currRowPaths];
68
- }
69
-
70
-
71
- private static getColumn(points: Array<number>): Array<ColumnPart> {
72
- const items: Array<ColumnPart> = [];
73
- for (let index = 0; index < points.length - 1; index++) {
74
- items.push({ index, width: points[index + 1] - points[index] });
75
- }
76
- return items;
77
- }
78
-
79
- private static getSplitCols(width: number, cols: number): Array<ColumnPart> {
80
- const items: Array<ColumnPart> = [];
81
- for (let i = 0; i < cols; i++) {
82
- items.push({ width: Math.floor(width / cols), index: i });
83
- }
84
- items[items.length - 1].width += width - items.reduce((prev, curr) => prev + curr.width, 0);
85
- return items;
86
- }
87
-
88
- private static getLinePointMap(hMergeCols: Array<ColumnPart>): Array<ColumnPartOffset> {
89
- const linePointMap: Array<ColumnPartOffset> = [];
90
- let x = 0;
91
- for (let i = 0; i < hMergeCols.length; i++) {
92
- const col = hMergeCols[i];
93
- linePointMap.push({ index: col.index, width: col.width, offset: x });
94
- x += col.width;
95
- }
96
- return linePointMap;
97
- }
98
- }
@@ -1,475 +0,0 @@
1
- import { SelectionState } from "../../document-selection";
2
- import { ElementUtil } from "../../element-util";
3
- import { TableCellElement } from "./table-cell-impl";
4
- import { TableElement } from "./table-impl";
5
- import { TableRowElement } from "./table-row-impl";
6
- import { ColumnPart, ColumnPartOffset, ColumnPatch, ColumnPatchUtil } from "./table-split-cell-patch";
7
- import { TableUtil } from "./table-util";
8
- /**
9
- * 拆分单元格
10
- * 蜀道难,难于上青天;拆分单元格,头发秃,精神衰,眼睛昏,身体废。
11
- *
12
- * 1.拆分为多列规则:不影响其他列宽度,将当前列宽度均分
13
- */
14
- export class TableSplitCell {
15
- /**
16
- *
17
- * 普通单元格可以任意拆分行和列
18
- * 已合并的单元格,可以拆分任意数量的列;可以拆分的数量必须为合并单元格数量的约数
19
- */
20
- static splitCell(ss: SelectionState, rows: number, cols: number): void {
21
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
22
- if (!focusCell) {
23
- throw new Error('focusCell is null')
24
- }
25
- if (!focusCell.props.hMerge && !focusCell.props.vMerge) {
26
- this.splitNormalCell(ss, rows, cols);
27
- } else {
28
- this.splitMergeCell(ss, rows, cols);
29
- }
30
- // else if (!focusCell.cellProps.hMerge) {
31
- // const { endColIndex } = this.horSplitHorNormalCell(ss, rows, cols);
32
- // this.verSplitVerMergeCell(ss, rows, endColIndex);
33
- // }
34
- // //当前单元格为横向合并单元格
35
- // else {
36
- // const { endColIndex } = this.horSplitHorMergeCell(ss, rows, cols);
37
- // this.verSplitVerMergeCell(ss, rows, endColIndex);
38
- // }
39
- }
40
-
41
-
42
- /**
43
- * 拆分普通的单元格
44
- */
45
- private static splitNormalCell(ss: SelectionState, rows: number, cols: number): void {
46
- rows = rows < 1 ? 1 : rows;
47
- cols = cols < 1 ? 1 : cols;
48
- if (rows === 1 && cols === 1) {
49
- return;
50
- }
51
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
52
- const focusRow = ElementUtil.getParentByType(focusCell, TableRowElement);
53
- const tb = ElementUtil.getParentByType(focusRow, TableElement);
54
- if (!focusCell || !focusRow || !tb) {
55
- throw new Error('focusCell | focusRow | tb is null');
56
- }
57
- const focusCellIndex = focusRow.getChildIndex(focusCell);
58
- const focusRowIndex = focusRow.getIndex();
59
- const cellWidth = tb.getCellWidth(focusCellIndex);
60
- if (focusCell.props.hMerge || focusCell.props.vMerge) {
61
- return;
62
- }
63
- //拆分为多列
64
- if (cols > 1) {
65
- const splitCellWidths = this.getSplitCols(cellWidth, cols);
66
- tb.setCellWidth(focusCellIndex, splitCellWidths[0].width);
67
- for (let i = 1; i < splitCellWidths.length; i++) {
68
- tb.insertCol(focusCellIndex + i, splitCellWidths[i].width);
69
- }
70
- for (let i = 0; i < tb.length; i++) {
71
- const row = tb.getChild(i) as TableRowElement;
72
- //获取主单元格
73
- const masterCell = row.getChild(focusCellIndex) as TableCellElement;
74
- for (let j = 1; j < cols; j++) {
75
- const newCell = new TableCellElement();
76
- row.addChild(newCell, focusCellIndex + j);
77
- if (i < focusRowIndex || i > focusRowIndex) {
78
- //由普通单元格转向合并单元格
79
- if (!masterCell.props.hMerge) {
80
- masterCell.props.hMerge = 'restart';
81
- }
82
- newCell.props.hMerge = 'continue';
83
- }
84
- }
85
- }
86
- }
87
- if (rows > 1) {
88
- for (let i = 1; i < rows; i++) {
89
- const newRow = TableRowElement.createRow(tb.getColsCount());
90
- tb.addChild(newRow, focusRowIndex + i)
91
- for (let j = 0; j < newRow.length; j++) {
92
- const cell = newRow.getChild<TableCellElement>(j);
93
- const masterCell = focusRow.getChild<TableCellElement>(j)
94
- if (j < focusCellIndex || j > focusCellIndex + cols - 1)
95
- //紧挨上级的单元格存在横向合并
96
- if (masterCell.props.hMerge) {
97
- if (masterCell.props.hMerge === 'restart') {
98
- if (!masterCell.props.vMerge) {
99
- masterCell.props.vMerge = 'restart'
100
- }
101
- cell.props.vMerge = 'continue';
102
- }
103
- } else {
104
- if (!masterCell.props.vMerge) {
105
- masterCell.props.vMerge = 'restart'
106
- }
107
- cell.props.vMerge = 'continue'
108
- }
109
- }
110
- }
111
- }
112
- tb.pubOnChange('self');
113
- tb.refreshView();
114
- }
115
-
116
- /**
117
- * 拆分合并的单元格
118
- * @param ss
119
- * @param rows
120
- * @param cols
121
- */
122
- static splitMergeCell(ss: SelectionState, rows: number, cols: number): void {
123
- rows = rows < 1 ? 1 : rows;
124
- cols = cols < 1 ? 1 : cols;
125
- if (rows === 1 && cols === 1) {
126
- return;
127
- }
128
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
129
- const focusRow = ElementUtil.getParentByType(focusCell, TableRowElement);
130
- const tb = ElementUtil.getParentByType(focusRow, TableElement);
131
- if (!focusCell || !focusRow || !tb) {
132
- throw new Error('focusCell | focusRow | tb is null');
133
- }
134
- const focusCellIndex = focusRow.getChildIndex(focusCell);
135
- const focusRowIndex = focusRow.getIndex();
136
- const cellWidth = tb.getCellWidth(focusCellIndex);
137
- if (!focusCell.props.hMerge && !focusCell.props.vMerge) {
138
- return;
139
- }
140
- const mergeRows = this.getVMergeRowsCount(tb, focusRowIndex, focusCellIndex);
141
- const mergeCols = this.getHMergeColsCount(tb, focusRowIndex, focusCellIndex);
142
- //只有拆分的行数需要满足此条件
143
- if (mergeRows > 1 && rows > 1) {
144
- if (rows % mergeRows !== 0) {
145
- throw new Error(`当前合并的行数为:${mergeRows},当前可拆分的行数是${mergeRows}的约数`)
146
- }
147
- }
148
- //拆分的行数、列数等于合并的行数、列数
149
- //执行还原
150
- if (mergeCols === cols && mergeRows === rows) {
151
- TableUtil.restoreCell(ss);
152
- return;
153
- }
154
-
155
- if (mergeCols === 1) {
156
- const { endColIndex } = this.horSplitHorNormalCell(ss, rows, cols);
157
- this.verSplitVerMergeCell(ss, rows, endColIndex);
158
- }
159
- //当前单元格为横向合并单元格
160
- else {
161
- const { endColIndex } = this.horSplitHorMergeCell(ss, rows, cols);
162
- this.verSplitVerMergeCell(ss, rows, endColIndex);
163
- }
164
- }
165
-
166
- /**
167
- * 拆分横向正常的单元格
168
- * @param ss
169
- * @param rows
170
- * @param cols
171
- */
172
- static horSplitHorNormalCell(ss: SelectionState, rows: number, cols: number): { startColIndex: number, endColIndex: number } {
173
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
174
- const focusRow = ElementUtil.getParentByType(focusCell, TableRowElement);
175
- const tb = ElementUtil.getParentByType(focusRow, TableElement);
176
- if (!focusCell || !focusRow || !tb) {
177
- throw new Error('focusCell | focusRow | tb is null');
178
- }
179
- const focusCellIndex = focusRow.getChildIndex(focusCell);
180
- const focusRowIndex = focusRow.getIndex();
181
- const cellWidth = tb.getCellWidth(focusCellIndex);
182
- const splitCellWidths = this.getSplitCols(cellWidth, cols);
183
- tb.setCellWidth(focusCellIndex, splitCellWidths[0].width);
184
- for (let i = 1; i < splitCellWidths.length; i++) {
185
- tb.insertCol(focusCellIndex + i, splitCellWidths[i].width);
186
- }
187
- const mergeRows = this.getVMergeRowsCount(tb, focusRowIndex, focusCellIndex);
188
- rows = rows < mergeRows ? mergeRows : rows;
189
- //向指定的列插入拆分单元格
190
- if (cols > 1) {
191
- for (let i = 0; i < tb.length; i++) {
192
- const currRow = tb.getChild(i) as TableRowElement;
193
- //获取主单元格
194
- const masterCell = currRow.getChild(focusCellIndex) as TableCellElement;
195
- for (let j = 1; j < cols; j++) {
196
- const newCell = new TableCellElement();
197
- currRow.addChild(newCell, focusCellIndex + j);
198
- if (i < focusRowIndex || i >= focusRowIndex + rows) {
199
- //由普通单元格转向合并单元格
200
- if (!masterCell.props.hMerge) {
201
- masterCell.props.hMerge = 'restart';
202
- }
203
- newCell.props.hMerge = 'continue';
204
- } else {
205
- newCell.props.vMerge = masterCell.props.vMerge;
206
- }
207
- }
208
- }
209
- }
210
- //在选中行下插入拆分行
211
- //如果当前是普通单元格
212
- if (!focusCell.props.vMerge) {
213
- debugger
214
- for (let i = 1; i < rows; i++) {
215
- const newRow = TableRowElement.createRow(tb.getColsCount());
216
- tb.addChild(newRow, focusRowIndex + i);
217
- }
218
- }
219
- tb.pubOnChange('to-child');
220
- tb.refreshView();
221
- return {
222
- startColIndex: focusCellIndex,
223
- endColIndex: focusCellIndex + cols - 1
224
- }
225
- }
226
-
227
- /**
228
- * 横向拆分合并的单元格
229
- * @param ss
230
- * @param rows
231
- * @param cols
232
- */
233
- static horSplitHorMergeCell(ss: SelectionState, rows: number, cols: number): { startColIndex: number, endColIndex: number } {
234
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
235
- const focusRow = ElementUtil.getParentByType(focusCell, TableRowElement);
236
- const tb = ElementUtil.getParentByType(focusRow, TableElement);
237
- if (!focusCell || !focusRow || !tb) {
238
- throw new Error('focusCell | focusRow | tb is null');
239
- }
240
- const focusCellIndex = focusRow.getChildIndex(focusCell);
241
- const focusRowIndex = focusRow.getIndex();
242
- const hMergeCols = this.getHMergeCols(tb, focusRowIndex, focusCellIndex, cols);
243
- const colsWidth = hMergeCols.reduce((prev, curr) => prev + curr.width, 0)
244
- const splitCols = this.getSplitCols(colsWidth, cols);
245
- const [otherPacks, currPacks] = ColumnPatchUtil.getPatchPacks(hMergeCols, splitCols);
246
- this.applyHorSplitColumnPatchPacks(tb, focusRowIndex, 1, otherPacks);
247
- this.applyHorSplitColumnCurrPatchPacks(tb, focusRowIndex, focusCellIndex, rows, currPacks);
248
- tb.pubOnChange('to-child');
249
- tb.refreshView();
250
- return {
251
- startColIndex: focusCellIndex,
252
- endColIndex: this.getPrepareNewColCounts(otherPacks, hMergeCols)
253
- }
254
- }
255
-
256
- /**
257
- * 获取需要新创建的列数量
258
- */
259
- private static getPrepareNewColCounts(packs: Array<{ part: ColumnPartOffset, patchs: Array<ColumnPatch> }>, hMergeCols: Array<ColumnPart>): number {
260
- const lastColIndex = hMergeCols[hMergeCols.length - 1].index;
261
- if (packs.length === 0) {
262
- return lastColIndex;
263
- }
264
- const lastColPack = packs.find(pack => pack.part.index === lastColIndex);
265
- if (!lastColPack) {
266
- return lastColIndex;
267
- }
268
- return lastColIndex + lastColPack.patchs.filter(item => item.type === 'insert').length
269
- }
270
-
271
- /**
272
- * 应用横向拆分单元格补丁
273
- */
274
- private static applyHorSplitColumnPatchPacks(tb: TableElement, focusRowIndex: number, splitRows: number, packs: Array<{ part: ColumnPartOffset, patchs: Array<ColumnPatch> }>): void {
275
- for (let i = packs.length - 1; i >= 0; i--) {
276
- const pack = packs[i];
277
- const colIndex = pack.part.index;
278
- for (let j = pack.patchs.length - 1; j >= 0; j--) {
279
- const patch = pack.patchs[j];
280
- if (patch.type === 'modify') {
281
- tb.setCellWidth(colIndex, patch.data.width);
282
- } else if (patch.type === 'insert') {
283
- tb.insertCol(colIndex + 1, patch.data.width);
284
- //向指定的列插入拆分单元格
285
- for (let i = 0; i < tb.length; i++) {
286
- const currRow = tb.getChild(i) as TableRowElement;
287
- //获取主单元格
288
- const masterCell = currRow.getChild(colIndex) as TableCellElement;
289
- const newCell = new TableCellElement();
290
- currRow.addChild(newCell, colIndex + 1);
291
- if (!masterCell.props.hMerge) {
292
- masterCell.props.hMerge = 'restart';
293
- }
294
- newCell.props.hMerge = 'continue';
295
- }
296
- }
297
- }
298
- }
299
- }
300
-
301
- /**
302
- * 存在横向合并的单元格,进行单元格分拆,打补丁
303
- * @param tb
304
- * @param focusRowIndex
305
- * @param focusColInex
306
- * @param splitRows
307
- * @param packs
308
- */
309
- private static applyHorSplitColumnCurrPatchPacks(tb: TableElement, focusRowIndex: number, focusColInex: number, splitRows: number, packs: Array<Array<ColumnPart>>): void {
310
- //获取当前列的合并行数
311
- let vMergeRows = this.getVMergeRowsCount(tb, focusRowIndex, focusColInex);
312
- vMergeRows = vMergeRows === 1 ? 0 : vMergeRows;
313
- const startRow = tb.getChild(focusRowIndex) as TableRowElement;
314
- const endRow = tb.getChild(focusRowIndex + vMergeRows - 1) as TableRowElement;
315
- for (let i = 0; i < packs.length; i++) {
316
- const mergeCols = packs[i];
317
- if (mergeCols.length === 1) {
318
- const startCell = startRow.getChild(focusColInex + mergeCols[0].index) as TableCellElement;
319
- const endCell = endRow.getChild(focusColInex + mergeCols[0].index) as TableCellElement;
320
- TableUtil.combineCells(tb, startCell, endCell);
321
- } else {
322
- // for (let j = 0; j < mergeCols.length; j++) {
323
- // const cell = focusRow.getChild(focusColInex + mergeCols[j].index) as TableCellElement;
324
- // cell.cellProps.hMerge = j === 0 ? 'restart' : 'continue';
325
- // }
326
- const startCell = startRow.getChild(focusColInex + mergeCols[0].index) as TableCellElement;
327
- const endCell = endRow.getChild(focusColInex + mergeCols[mergeCols.length - 1].index) as TableCellElement;
328
- TableUtil.combineCells(tb, startCell, endCell);
329
- }
330
- }
331
- }
332
-
333
-
334
- /**
335
- * 纵向拆分合并的单元格
336
- * 在指定行下插入复制行
337
- * 存在
338
- */
339
- private static verSplitVerMergeCell(ss: SelectionState, rows: number, endColIndex: number): void {
340
- if (rows === 1) {
341
- return;
342
- }
343
- const focusCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
344
- const focusRow = ElementUtil.getParentByType(focusCell, TableRowElement);
345
- const tb = ElementUtil.getParentByType(focusRow, TableElement);
346
- if (!focusCell || !focusRow || !tb) {
347
- throw new Error('focusCell | focusRow | tb is null');
348
- }
349
- const focusCellIndex = focusRow.getChildIndex(focusCell);
350
- const focusRowIndex = focusRow.getIndex();
351
- let mergeRows = 0;
352
- if (focusCell.props.vMerge === 'restart') {
353
- mergeRows = this.getVMergeRowsCount(tb, focusRowIndex, focusCellIndex);
354
- if (mergeRows % rows !== 0) {
355
- throw new Error(`可拆分的行数必须是${mergeRows}的约数`);
356
- }
357
- }
358
- //不存在合并行,则向下新增行
359
- if (mergeRows === 0) {
360
- for (let i = 0; i < rows - 1; i++) {
361
- const newRow = new TableRowElement();
362
- for (let i = 0; i < focusRow.length; i++) {
363
- const focusRowCell = focusRow.getChild(i) as TableCellElement;
364
- const cell = new TableCellElement();
365
- //其他列要纵向合并
366
- if (i < focusCellIndex || i > endColIndex) {
367
- if (!focusRowCell.props.vMerge) {
368
- focusRowCell.props.vMerge = 'restart';
369
- }
370
- cell.props.vMerge = 'continue';
371
- }
372
- cell.props.hMerge = focusRowCell.props.hMerge;
373
- newRow.addChild(cell);
374
- }
375
- tb.addChild(newRow, focusRowIndex + i + 1);
376
- }
377
- }
378
- //存在合并行,则按照约数单个合并分拆为多个合并
379
- else {
380
- //拆分行和合并行相等,则执行还原
381
- if (rows === mergeRows) {
382
- for (let i = 0; i < mergeRows; i++) {
383
- const row = tb.getChild(focusRowIndex + i) as TableRowElement;
384
- for (let j = focusCellIndex; j <= endColIndex; j++) {
385
- const cell = row.getChild(j) as TableCellElement;
386
- cell.props.vMerge = null;
387
- }
388
- }
389
- } else {
390
- for (let i = 0; i < mergeRows; i++) {
391
- if (i % rows === 0) {
392
- const row = tb.getChild(focusRowIndex + i) as TableRowElement;
393
- const cell = row.getChild(focusCellIndex) as TableCellElement;
394
- cell.props.vMerge = 'restart';
395
- }
396
- }
397
- }
398
- }
399
- }
400
-
401
-
402
-
403
- private static getSplitCols(width: number, cols: number): Array<ColumnPart> {
404
- const items: Array<ColumnPart> = [];
405
- for (let i = 0; i < cols; i++) {
406
- items.push({ width: Math.floor(width / cols), index: i });
407
- }
408
- items[items.length - 1].width += width - items.reduce((prev, curr) => prev + curr.width, 0);
409
- return items;
410
- }
411
-
412
- /**
413
- * 获取横向合并的列
414
- * @param tb
415
- * @param currRowIndex
416
- * @param currColIndex
417
- * @param splitCols
418
- */
419
- private static getHMergeCols(tb: TableElement, currRowIndex: number, currColIndex: number, splitCols: number): Array<ColumnPart> {
420
- const row = tb.getChild(currRowIndex) as TableRowElement;
421
- const items: Array<ColumnPart> = [{ width: tb.getCellWidth(currColIndex), index: currColIndex }];
422
- for (let i = currColIndex + 1; i < tb.getColsCount(); i++) {
423
- const cell = row.getChild(i) as TableCellElement;
424
- if (cell.props.hMerge === 'continue') {
425
- items.push({ width: tb.getCellWidth(i), index: i });
426
- } else {
427
- break;
428
- }
429
- }
430
- return items;
431
- }
432
-
433
- /**
434
- * 获取纵向合并的行数
435
- * @param tb
436
- * @param currRowIndex
437
- */
438
- private static getVMergeRowsCount(tb: TableElement, rowIndex: number, colIndex: number): number {
439
- const startCell = <TableCellElement>(<TableRowElement>tb.getChild(rowIndex)).getChild(colIndex)
440
- if (startCell.props.vMerge !== 'restart') {
441
- return 1;
442
- }
443
- let i = 0;
444
- for (i = rowIndex + 1; i < tb.length; i++) {
445
- const row = tb.getChild(i) as TableRowElement;
446
- const cell = row.getChild(colIndex) as TableCellElement;
447
- if (cell.props.vMerge !== 'continue') {
448
- return i - rowIndex;
449
- }
450
- }
451
- return i - rowIndex;
452
- }
453
-
454
- /**
455
- * 获取纵向合并的行数
456
- * @param tb
457
- * @param currRowIndex
458
- */
459
- private static getHMergeColsCount(tb: TableElement, rowIndex: number, colIndex: number): number {
460
- const row = tb.getChild<TableRowElement>(rowIndex);
461
- const startCell = row.getChild<TableCellElement>(colIndex)
462
- if (startCell.props.hMerge !== 'restart') {
463
- return 1;
464
- }
465
- let i = 0;
466
- for (i = colIndex + 1; i < row.length; i++) {
467
- const cell = row.getChild(i) as TableCellElement;
468
- if (cell.props.hMerge !== 'continue') {
469
- return i - colIndex;
470
- }
471
- }
472
- return i - colIndex;
473
- }
474
-
475
- }