@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,1010 +0,0 @@
1
- import { RenderContenxt } from './framework/render-context';
2
- import { ContentMenuItem, ContextMenuElementEvent, EventMap, HitEventInfo } from './framework/element-event-define';
3
- import { DocumentPaint } from './framework/document-paint';
4
- import { ElementReader } from './framework/element-reader';
5
- import { DocumentEvent } from './framework/document-event';
6
- import { Subject } from 'rxjs';
7
- import { DocumentInput } from './framework/document-input-cursor';
8
- import { DocumentCursor, DocumentSelection, SelectionState } from './framework/document-selection';
9
- import { ElementUtil } from './framework/element-util';
10
- import { DocumentChange } from './framework/document-change';
11
- import { CursorType } from './framework/render-define';
12
- import { SelectionOverlays } from './framework/selection-overlays';
13
- import {
14
- BranchElement,
15
- DocMode,
16
- Element,
17
- ICancelTokenFn,
18
- LeafElement,
19
- MarginProps,
20
- OrientType,
21
- PageOptions,
22
- Position,
23
- TextAlign,
24
- ViewOptions
25
- } from './framework/element-define';
26
- import { ElementSerialize } from './framework/element-serialize';
27
- import { TableElement } from './framework/impl/table/table-impl';
28
- import { documentPrint } from './framework/document-print';
29
- import { DocumentTemplate } from './framework/document-template';
30
- import {
31
- DataElementInlineGroup,
32
- DataElementLeaf, IsInSideDataElement,
33
- validateDataEle
34
- } from './framework/impl/data-element/data-element-base-impl';
35
- import { DocRule } from './doc-ruler';
36
- import { ParagraphProps, TextProps } from './framework/element-props';
37
- import { TextGroupElement } from './framework/impl/text/text-impl';
38
- import { ParagraphElement } from './framework/impl/paragraph/p-impl';
39
- import { TableUtil } from './framework/impl/table/table-util';
40
- import { EditorContext } from './framework/document-context';
41
- import { DocumentElement, DocumentRenderObject } from './framework/impl/document/doc-impl';
42
- import { DocumentComment } from './framework/document-comment';
43
- import { CommContentBaseElement } from './framework/impl/comments/comment-content-impl';
44
- import { DocumentHistory } from './framework/document-history';
45
- import { TableRowElement } from './framework/impl/table/table-row-impl';
46
- import { getFocusTextSegment } from "./framework/document-segmenter";
47
-
48
- import { saveAs } from 'file-saver';
49
- import { DocumentBodyElement } from "./framework/impl/document/doc-body-impl";
50
-
51
- export class CanvasTextEditor {
52
- private contentCtx: CanvasRenderingContext2D;
53
- viewOptions: ViewOptions;
54
- docCtx: EditorContext;
55
- private docComment: DocumentComment;
56
- private renderContext: RenderContenxt;
57
- private documentPaint: DocumentPaint;
58
- elementReader: ElementReader;
59
- private documentEvent: DocumentEvent;
60
- private documentSelection: DocumentSelection;
61
- private documentInput: DocumentInput;
62
- private documentChange: DocumentChange;
63
- private selectionOverlays: SelectionOverlays;
64
- private docRule: DocRule;
65
- private docHistory: DocumentHistory;
66
- private eventMap: EventMap = new EventMap();
67
- selectionChanged: Subject<SelectionState> = new Subject();
68
- beforeRenderSubject: Subject<void> = new Subject();
69
- afterRenderSubject: Subject<void> = new Subject();
70
- selectionState: SelectionState;
71
- //显示右键菜单
72
- onContextMenuItemChanged: Subject<EditorContenxtProps> = new Subject();
73
- //显示数据元编辑框
74
- onShowDataElementEditPanelEvent: Subject<EditorPanelProps> = new Subject();
75
- onDblClickEvent: Subject<Event> = new Subject();
76
- onClickEvent: Subject<Event> = new Subject();
77
- onScrollViewEvent: Subject<number> = new Subject();
78
- //文档改变事件:内容及样式,业务模块需要根据此事件,来追踪当前文档是否改变的状态
79
- onDocChangedEvent: Subject<void> = new Subject();
80
-
81
- constructor(private docScroll: HTMLDivElement, private holdSpace: HTMLDivElement, private ruleCanvas: HTMLCanvasElement, private editCanvasContainer: HTMLDivElement, private editCanvas: HTMLCanvasElement, private editInput: HTMLInputElement, private editCursor: HTMLSpanElement, private cursorWrapper: HTMLDivElement, private scaleContainer: HTMLDivElement) {
82
- this.viewOptions = new ViewOptions();
83
- this.documentSelection = new DocumentSelection();
84
- this.docCtx = new EditorContext(this.documentSelection.selectionState, this.viewOptions);
85
- this.viewOptions.copyRightInfo = '万达信息电子病历编辑器,www.wondersgroup.com';
86
- this.viewOptions.drawCharRectColor = 'green';
87
- this.viewOptions.showLineRect = true;
88
- this.viewOptions.docSpace = 20;
89
- this.viewOptions.reviewWindowWidth = 200;
90
- this.viewOptions.defaultFontName = '宋体'
91
- //整个画布的尺寸
92
- this.viewOptions.viewSettings = {
93
- width: 1000,
94
- height: this.getContainerHeight().height
95
- };
96
- this.viewOptions.editUser = {
97
- id: '6666',
98
- name: '管理员'
99
- };
100
- this.viewOptions.fullPageView = false;
101
- this.viewOptions.enableUndo = true;
102
- this.createDocViewer();
103
- this.docComment = new DocumentComment(this.docCtx);
104
- this.contentCtx = editCanvas.getContext('2d') as CanvasRenderingContext2D;
105
- this.renderContext = new RenderContenxt(this.contentCtx, this.viewOptions, this.docCtx);
106
- this.setCanvasProps();
107
- this.selectionState = this.documentSelection.selectionState;
108
- this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
109
- this.documentPaint = new DocumentPaint(this.viewOptions, this.renderContext, this.docCtx, this.selectionOverlays.selectedSets);
110
- this.elementReader = new ElementReader(this.docCtx, this.viewOptions, this.renderContext);
111
- this.documentEvent = new DocumentEvent(editCanvas, this.documentPaint, this.viewOptions, this.documentSelection.selectionState, this.docCtx);
112
- this.docRule = new DocRule(this.ruleCanvas, this.viewOptions, this.documentSelection.selectionState);
113
- this.documentChange = new DocumentChange(this.documentSelection.selectionState, this.viewOptions, this.elementReader, this.docCtx, this.docComment);
114
- this.docHistory = new DocumentHistory(this.docCtx, this.elementReader, this.onDocChangedEvent);
115
- this.documentInput = new DocumentInput(editInput, editCursor, cursorWrapper, this.docCtx);
116
- this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
117
- this.hitInfoChanged(hitInfo)
118
- });
119
- this.documentEvent.clickEvent.subscribe((evt) => {
120
- this.docClickHandle(evt)
121
- });
122
- this.documentEvent.dblClickEvent.subscribe((evt) => {
123
- this.docDblClickHandle(evt)
124
- });
125
- this.documentEvent.changeCursor.subscribe((cursor) => {
126
- this.changeCursor(cursor)
127
- });
128
- this.documentEvent.contextMenu.subscribe(evt => {
129
- this.onContextMenu(evt)
130
- });
131
- this.documentEvent.trackTipsChanged.subscribe(data => {
132
- });
133
- this.documentInput.onInputEvent.subscribe(data => {
134
- this.documentChange.newInput(data)
135
- });
136
- this.documentInput.onBackspaceEvent.subscribe((evt) => {
137
- this.documentChange.onBackspace(evt)
138
- });
139
- this.documentInput.onEnterEvent.subscribe(() => {
140
- this.documentChange.onEnter()
141
- });
142
- this.documentInput.onCopyEvent.subscribe((evt) => {
143
- this.documentChange.onCopy(evt)
144
- });
145
- this.documentInput.onCutEvent.subscribe((evt) => {
146
- this.documentChange.onCut(evt);
147
- });
148
- this.documentInput.onPasteEvent.subscribe((evt) => {
149
- this.documentChange.onPaste(evt)
150
- });
151
- this.documentInput.onInsertBr.subscribe(() => {
152
- this.documentChange.insertSoftBr()
153
- })
154
- this.documentInput.onLeftEvent.subscribe(() => {
155
- this.documentEvent.moveCursorToLeft()
156
- });
157
- this.documentInput.onRightEvent.subscribe(() => {
158
- this.documentEvent.moveCursorToRight()
159
- });
160
- this.documentInput.onDeleteEvent.subscribe((evt) => this.documentChange.onDeleteKeyHandler(evt));
161
- this.documentInput.onSelectAllEvent.subscribe(() => {
162
- this.documentEvent.selectAll()
163
- });
164
- this.documentInput.onHomeEvent.subscribe(() => {
165
- this.documentEvent.moveCursorToLineStart()
166
- })
167
- this.documentInput.onEndEvent.subscribe(() => {
168
- this.documentEvent.moveCursorToLineEnd()
169
- })
170
- this.documentInput.onUpEvent.subscribe(() => {
171
- this.documentEvent.moveCursorToUpOrDown(true)
172
- })
173
- this.documentInput.onDownEvent.subscribe(() => {
174
- this.documentEvent.moveCursorToUpOrDown(false)
175
- })
176
- this.docCtx.docChange = this.documentChange;
177
- this.listenContainerHeight();
178
- this.refreshDocRule();
179
- this.docCtx.syncRefresh = () => {
180
- this.flushToSchedule()
181
- };
182
- this.viewOptions.onChange.subscribe((type) => {
183
- this.resetViewer(type)
184
- })
185
- }
186
-
187
- /**
188
- * 设置标尺
189
- */
190
- refreshDocRule(): void {
191
- let docLeft = 0//CommonUtil.getOffsetX(this.editCanvas.parentElement as HTMLDivElement);
192
- let pagePL = 0, pagePR = 0;
193
- if (this.documentPaint.docContainer) {
194
- docLeft += this.documentPaint.docContainer.rect.x;
195
- }
196
- if (this.docCtx.document?.props?.padding) {
197
- const { left, right } = this.docCtx.document.props.padding;
198
- pagePL = left;
199
- pagePR = right;
200
- }
201
- this.docRule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
202
- this.docRule.refreshRule();
203
- }
204
-
205
- createDocViewer(): void {
206
- this.viewOptions.mmToPixelsRatio = this.measureMMToPixs();
207
- const width = Math.floor(210 * this.viewOptions.mmToPixelsRatio);
208
- const height = Math.floor(297 * this.viewOptions.mmToPixelsRatio);
209
- this.viewOptions.docPageSettings = new PageOptions(width, height);
210
- this.docScroll.onscroll = (evt) => {
211
- this.scrollView(evt);
212
- };
213
- }
214
-
215
- measureMMToPixs(): number {
216
- const div = document.createElement('div');
217
- div.style.width = '100mm';
218
- document.body.appendChild(div);
219
- const width = div.getBoundingClientRect().width;
220
- document.body.removeChild(div);
221
- return width / 100;
222
- }
223
-
224
- flushTask!: (() => void) | null;
225
- flushTaskThen: Array<(() => void)> = [];
226
- //是否用于跟踪修改状态,在初始化、数据元赋值等情况不需要跟踪修改标志
227
- private trackChangeState = true;
228
- flushToSchedule(): void {
229
- if (this.docCtx.refreshType === 'content') {
230
- //触发动态脚本
231
- this.docCtx.dynamicFunc.invokedScripts();
232
- this.triggerDocChange();
233
- }
234
- if (this.flushTask) {
235
- return;
236
- }
237
- this.flushTask = () => {
238
- this.refreshDocument();
239
- this.flushTaskThen.forEach(item => item());
240
- this.flushTaskThen.length = 0;
241
- this.flushTask = null;
242
- };
243
- Promise.resolve().then(() => {
244
- if (this.flushTask) {
245
- this.flushTask();
246
- }
247
- });
248
- }
249
-
250
- /**
251
- * 触发文档改变事件
252
- * @returns
253
- */
254
- triggerDocChange(): void {
255
- if (!this.trackChangeState) {
256
- return;
257
- }
258
- this.onDocChangedEvent.next();
259
- }
260
-
261
- /**
262
- * fn函数执行时,不触发onDocChange
263
- * @param fn
264
- */
265
- noEffectChange(fn: () => void): void {
266
- const prev = this.trackChangeState;
267
- this.trackChangeState = false;
268
- try {
269
- fn();
270
- } catch (e) {
271
- console.error(e);
272
- }
273
- this.trackChangeState = prev;
274
- }
275
-
276
-
277
-
278
- loadDoc(data: any | DocumentElement): void {
279
- this.elementReader.read(data);
280
- this.refreshDocument();
281
- this.refreshDocRule();
282
- this.docHistory.clear();
283
- }
284
-
285
- /**
286
- * 更新文档容器高度尺寸
287
- */
288
- updateDocumentContainerSize(): void {
289
- this.holdSpace.style.height = this.documentPaint.getDocumentContainerHeight() + 'px';
290
- }
291
-
292
- scrollView(evt: Event): void {
293
- const target = evt.target as HTMLDivElement;
294
- const top = Math.floor(target.scrollTop);
295
- this.editCanvasContainer.style.top = top + 'px';
296
- this.cursorWrapper.style.transform = "translate(0,-" + top + "px)";
297
- this.viewOptions.translateY = top;
298
- this.documentPaint.refreshView();
299
- this.documentEvent.onScrollView();
300
- this.onScrollViewEvent.next(top);
301
-
302
- }
303
-
304
- private refreshDocument(): void {
305
- let rePaint = this.docCtx.refreshType === 'content';
306
- if (rePaint) {
307
- this.documentSelection.clearSnapshot();
308
- this.docComment.readComments();
309
-
310
- this.documentPaint.rePages();
311
- this.beforeRenderSubject.next();
312
- }
313
- const ssChanged = this.documentSelection.updateSelectionState();
314
- this.selectionOverlays.getSelectionTreeData();
315
- this.documentPaint.refreshView(rePaint);
316
- this.updateDocumentContainerSize();
317
- this.setCursor();
318
- ssChanged && this.selectionChanged.next(this.documentSelection.selectionState);
319
- this.docRule.refreshRule();
320
-
321
- }
322
-
323
- private hitInfoChanged(hitInfo: { startHitInfo: HitEventInfo, endHitInfo: HitEventInfo }): void {
324
- this.documentSelection.setSelectionState(hitInfo);
325
- this.refreshDocument();
326
- this.selectionChanged.next(this.documentSelection.selectionState);
327
- }
328
-
329
- /**
330
- * 设置光标
331
- */
332
- private setCursor(): void {
333
- const { startControl, startOffset } = this.selectionState;
334
- if (!this.canSetCursor()) {
335
- this.selectionState.editable = false;
336
- this.documentInput.setCursorVisibility(false);
337
- return;
338
- }
339
- if (this.selectionState.afterSelectionChanged) {
340
- //需要重新刷新,不触发GotCusor事件
341
- if (this.selectionState.afterSelectionChanged(this.selectionState)) {
342
- this.selectionState.afterSelectionChanged = null;
343
- return;
344
- }
345
- }
346
- const { startRegion, hitDocIndex } = this.documentEvent.startHitInfo as HitEventInfo;
347
- const cursorPos = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
348
- this.docCtx.cursorRect = ElementUtil.cloneRect(cursorPos.rect);
349
- this.documentInput.setCursorPosition(cursorPos.rect);
350
- this.selectionState.cursorPos = cursorPos.rect;
351
- this.documentEvent.invokeCursor(startControl);
352
- }
353
-
354
- /**
355
- * 判断是否光标可以设置接受编辑
356
- * @returns
357
- */
358
- private canSetCursor(): boolean {
359
- const { startControl, startOffset, editable } = this.selectionState;
360
- if (!startControl || !editable) {
361
- return false;
362
- }
363
- if (this.viewOptions.docMode === DocMode.Design) {
364
- return true;
365
- }
366
- //浏览模式
367
- if (this.viewOptions.docMode === DocMode.View) {
368
- return false;
369
- }
370
- //表单模式下,如果不在数据元素中,则不显示光标
371
- if (this.viewOptions.docMode === DocMode.FormEdit) {
372
- if (!IsInSideDataElement(startControl, startOffset)) {
373
- return false;
374
- }
375
- }
376
- if (!ElementUtil.verifyHitable(startControl)) {
377
- return false;
378
- }
379
- //表单模式下,数据元不可编辑
380
- if (this.viewOptions.docMode === DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
381
- const dataEle = ElementUtil.getDataElement(startControl);
382
- if (!dataEle.props.editable) {
383
- return false;
384
- }
385
- }
386
- return true;
387
- }
388
-
389
- /**
390
- * 修改光标
391
- * @param newCursor
392
- */
393
- private changeCursor(newCursor: CursorType): void {
394
- this.editCanvas.style.cursor = newCursor;
395
- this.viewOptions.cursor = newCursor;
396
- }
397
-
398
- /**
399
- * 文档点击事件
400
- */
401
- private docClickHandle(evt: MouseEvent): void {
402
- this.setCursor();
403
- this.selectionOverlays.getSelectionTreeData();
404
- this.onClickEvent.next(evt);
405
- }
406
-
407
- /**
408
- * 文档双击事件
409
- * 处理全选当前段落
410
- */
411
- private docDblClickHandle(evt: MouseEvent): void {
412
- const res = getFocusTextSegment(this.selectionState);
413
- if (res) {
414
- this.refreshDocument();
415
- }
416
- this.onDblClickEvent.next(evt);
417
- }
418
-
419
- /**
420
- * 获取当前光标所在的数据元
421
- * @returns
422
- */
423
- getCurrentDataElement(): DataElementInlineGroup | DataElementLeaf | null {
424
- const selectionState = this.documentSelection.selectionState;
425
- const { startControl } = selectionState;
426
- if (startControl) {
427
- if (!ElementUtil.verifyHitable(startControl)) {
428
- return null;
429
- }
430
- return ElementUtil.getParent(startControl, validateDataEle) as DataElementInlineGroup | DataElementLeaf;
431
- }
432
- return null;
433
- }
434
-
435
- /**
436
- * 设置当前光标所在的数据元的值
437
- * @param val
438
- */
439
- setCurrentDataElementValue(val: any): void {
440
- const dataEle = this.getCurrentDataElement();
441
- if (dataEle) {
442
- dataEle?.setValue(val);
443
- this.selectionState.clear();
444
- }
445
- }
446
-
447
- /**
448
- * 获取数据元位置
449
- * @param element
450
- * @returns
451
- */
452
- getDataElementPosition(element: LeafElement) {
453
- const startDecorateRender = this.documentPaint.elementPaint.getLeafElementPaintMap(element);
454
- if (!startDecorateRender) {
455
- console.error('未找到数据元开始渲染元素');
456
- return;
457
- }
458
- const { x, height, y, width } = startDecorateRender.rect;
459
- const pos = ElementUtil.getRenderAbsolutePaintPos(startDecorateRender)
460
- const position = { x: pos.x + width, y: pos.y + height + 5, translateY: this.viewOptions.translateY };
461
- return position
462
- }
463
-
464
- /**
465
- * 获取文档模型
466
- * @returns
467
- */
468
- getDocSchema(): any {
469
- return ElementSerialize.serialize(this.docCtx.document, this.viewOptions);
470
- }
471
-
472
- getDocSchemaJSON(): string {
473
- const res = JSON.stringify(this.getDocSchema());
474
- return res;
475
- }
476
-
477
- /**
478
- * 右键菜单
479
- * @param evt
480
- */
481
- onContextMenu(evt: MouseEvent): void {
482
- evt.preventDefault();
483
- const { selectionState } = this.documentSelection;
484
- const { startControl } = selectionState;
485
- if (!startControl) {
486
- return;
487
- }
488
- const elementEvent = new ContextMenuElementEvent(this.docCtx);
489
- elementEvent.source = startControl;
490
- DocumentEvent.invokeEvent('ElementContextMenu', startControl, elementEvent, 'All', this.docCtx);
491
- const position = { x: evt.offsetX + 10, y: evt.offsetY, translateY: this.viewOptions.translateY };
492
- this.onContextMenuItemChanged.next({ pos: position, menus: elementEvent.menus })
493
- }
494
-
495
- resizeObserver: ResizeObserver | null = null;
496
-
497
- listenContainerHeight(): void {
498
- this.resizeObserver = new ResizeObserver(entries => {
499
- this.updateDocHeight();
500
- }
501
- );
502
- this.resizeObserver.observe(this.docScroll);
503
- this.updateDocHeight();
504
- }
505
-
506
- private updateDocHeight(): void {
507
- const { width, height } = this.getContainerHeight();
508
- this.viewOptions.viewSettings.width = width;
509
- this.viewOptions.viewSettings.height = height;
510
- if (width < this.viewOptions.ContentWidth) {
511
- this.viewOptions.viewSettings.width = this.viewOptions.ContentWidth;
512
- }
513
- this.resetViewer();
514
- }
515
-
516
- resetViewer(type: 'demand' | 'force' | undefined = undefined): void {
517
- const refreshType = type === 'force' ? 'content' : 'appearance';
518
- if (refreshType === 'content') {
519
- this.docCtx.document.pubOnChange('self');
520
- }
521
- this.setCanvasProps();
522
- this.flushToSchedule();
523
- this.flushTaskThen.push(() => {
524
- this.refreshDocRule();
525
- });
526
- }
527
-
528
- /**
529
- * 缩放视图
530
- * @param scale
531
- * @returns
532
- */
533
- scaleView(scale: number): number {
534
- scale = scale < 0.5 ? 0.5 : scale;
535
- scale = scale > 2 ? 2 : scale;
536
- this.viewOptions.scale = scale;
537
- this.scaleContainer.style.transform = `scale(${scale})`;
538
- this.scaleContainer.style.transformOrigin = "center top";
539
- if (scale === 1) {
540
- this.scaleContainer.style.transform = '';
541
- this.scaleContainer.style.transformOrigin = '';
542
- }
543
- this.setCanvasProps();
544
- this.refreshDocRule();
545
- this.flushToSchedule();
546
- return scale;
547
- }
548
-
549
- getContainerHeight(): { height: number, width: number } {
550
- let { height, width } = this.docScroll.getBoundingClientRect();
551
- // const div=this.docScroll.children[0] as HTMLElement;
552
- // const { height, width } = div.getBoundingClientRect();
553
- return { height: Math.floor(height), width: Math.floor(width) };
554
- }
555
-
556
- setCanvasProps(): void {
557
- this.renderContext?.clear();
558
- this.renderContext.setCanvasProps();
559
- this.renderContext?.clear();
560
- }
561
-
562
- /**
563
- * 在当前位置插入表格
564
- * @param row
565
- * @param col
566
- */
567
- insertTable(rows: number, cols: number): void {
568
- const tb = TableElement.createTable(rows, cols);
569
- this.documentChange.insertTable(tb);
570
- }
571
-
572
- /**
573
- * 打印所有文档
574
- */
575
- printAllPages(): void {
576
- documentPrint.print(this.documentSelection.selectionState, this.viewOptions, this.docCtx)
577
- }
578
-
579
- /**
580
- * 导出所有页到base64
581
- */
582
- exportAllPagesToBase64(fileName: string): void {
583
- const imgs = documentPrint.exportCanvasNodes(this.documentSelection.selectionState, this.viewOptions, this.docCtx)
584
- imgs.forEach((item, i) => item.toBlob(blog => {
585
- if (blog) {
586
- saveAs(blog, fileName + i + '.png')
587
- }
588
- }))
589
- }
590
-
591
- exportPDF(): void {
592
- documentPrint.exportPDF('', this.documentSelection.selectionState, this.viewOptions, this.docCtx)
593
- }
594
-
595
- /**
596
- * 清除文档
597
- */
598
- clearDoc(): void {
599
- if (this.docCtx.document) {
600
- this.docCtx.document.destroy();
601
- this.documentSelection.selectionState.clear();
602
- this.documentEvent.clearHitInfo();
603
- }
604
- this.docCtx.clear();
605
- }
606
-
607
- /**
608
- * 新建文档
609
- * @param options
610
- */
611
- createNewDoc(doc: DocumentElement | null = null): void {
612
- //this.docCtx.clear();
613
- const newDoc = doc ?? DocumentTemplate.createA4Doc();
614
- // this.elementReader.setDocument(newDoc);
615
- // this.refreshDocument('content');
616
- this.loadDoc(ElementSerialize.serialize(newDoc, this.viewOptions));
617
- }
618
-
619
- destroy(): void {
620
- this.docCtx.destroy();
621
- this.documentEvent.clearSubEvent();
622
- this.documentInput.destroy();
623
- this.flushTask = null;
624
- }
625
-
626
-
627
- /**
628
- * 获取选区文本属性
629
- * @returns
630
- */
631
- getSelectionTextGroupProps(): TextProps | null {
632
- const selectionState = this.selectionState;
633
- const range = selectionState.selectedRange;
634
- if (!range) {
635
- if (selectionState.collapsed) {
636
- if (selectionState.startControl instanceof TextGroupElement) {
637
- return selectionState.startControl.props;
638
- }
639
- }
640
- return null;
641
- }
642
- const startRange = ElementUtil.getFirstSelectedRange(range);
643
- const endRange = ElementUtil.getLastSelectedRange(range);
644
- if (startRange.target instanceof TextGroupElement) {
645
- return startRange.target.props;
646
- }
647
- return null;
648
- }
649
-
650
- getSelectionParaProps(): ParagraphProps | null {
651
- const selectionState = this.selectionState;
652
- if (!selectionState || !selectionState.startControl) {
653
- return null;
654
- }
655
- const para = ElementUtil.getParentByType(selectionState.startControl, ParagraphElement) as ParagraphElement;
656
- return para.props;
657
- }
658
-
659
- /**
660
- * 设置文本字体大小
661
- * @param fontSize
662
- * @returns
663
- */
664
- setTextFontSize(fontSize: number): void {
665
- if (isNaN(fontSize)) {
666
- return;
667
- }
668
- const setterFunc = (textProps: TextProps) => {
669
- textProps.fontSize = fontSize;
670
- };
671
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
672
- }
673
-
674
- /**
675
- * 设置文本颜色
676
- * @param color \
677
- */
678
- setTextColor(color: string): void {
679
- color = color || "rgb(0,0,0)";
680
- const setterFunc = (textProps: TextProps) => {
681
- textProps.color = color;
682
- };
683
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
684
- }
685
-
686
- /**
687
- * 设置文本字体名称
688
- * @param font
689
- */
690
- setTextFont(font: string): void {
691
- font = font || "宋体";
692
- const setterFunc = (textProps: TextProps) => {
693
- textProps.fontName = font;
694
- };
695
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
696
- }
697
-
698
- /**
699
- * 应用选中文本格式,用于批量设置格式,例如:格式刷
700
- * @param newStyle
701
- */
702
- applyStyle(newStyle: TextProps): void {
703
- const setterFunc = (textProps: TextProps) => {
704
- textProps.setPropsValue(newStyle, textProps);
705
- };
706
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
707
- }
708
-
709
- /**
710
- * 开启格式刷
711
- */
712
- enableFormatBrush(): ICancelTokenFn | null {
713
- const startControl = this.selectionState.startControl;
714
- if (startControl instanceof TextGroupElement) {
715
- const selectedStyle = startControl.props.clone(null);
716
- const selectionOverlayColor = this.viewOptions.selectionOverlaysColor;
717
- this.viewOptions.selectionOverlaysColor = "rgba(0,58,140,0.8)";
718
-
719
- const cancelToken: ICancelTokenFn = {};
720
- const sub = this.onClickEvent.subscribe(() => {
721
- sub.unsubscribe();
722
- this.applyStyle(selectedStyle);
723
- this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
724
- if (cancelToken.onFinish) {
725
- cancelToken.onFinish();
726
- }
727
- });
728
- cancelToken.cancel = () => {
729
- sub.unsubscribe();
730
- this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
731
- };
732
- return cancelToken;
733
- }
734
- return null;
735
- }
736
-
737
- /**
738
- * 设置文本背景颜色
739
- * @param color
740
- */
741
- setTextBackColor(color: string): void {
742
- const setterFunc = (textProps: TextProps) => {
743
- textProps.background = color;
744
- };
745
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
746
- }
747
-
748
- /**
749
- * 切换文本加粗、下划线、删除等文本样式
750
- * @param isEffective
751
- * @param style
752
- * @param matchValue
753
- */
754
- switchTextStyle<P extends keyof TextProps, V extends TextProps[P]>(isEffective: boolean, style: P, matchValue: V, defaultValue: any = undefined): void {
755
- const setterFunc = (textProps: TextProps) => {
756
- if (isEffective) {
757
- textProps[style] = defaultValue as never;
758
- //delete textProps[style];
759
- } else {
760
- textProps[style] = matchValue;
761
- }
762
- };
763
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
764
- }
765
-
766
- /**
767
- * 修改字间距
768
- */
769
- setLetterSpace(letterSpace: number): void {
770
- letterSpace = letterSpace <= 0 ? 0 : letterSpace;
771
- const setterFunc = (textProps: TextProps) => {
772
- textProps.letterSpace = letterSpace;
773
- };
774
- DocumentChange.setTextStyle(this.selectionState, setterFunc);
775
- }
776
-
777
-
778
- /**
779
- * 设置段落对齐
780
- * @param align
781
- */
782
- switchParaAlign(align: TextAlign): void {
783
- const setterFunc = (paraProps: ParagraphProps) => {
784
- paraProps.textAlign = align;
785
- };
786
- DocumentChange.setParaAlign(this.selectionState, setterFunc);
787
- }
788
-
789
-
790
- combineCell(): void {
791
- TableUtil.mergeCells(this.selectionState)
792
- }
793
-
794
- /**
795
- * 切换当前段落项目符号状态
796
- */
797
- setParagraphNumberType(): void {
798
- this.documentChange.setParagraphNumberType();
799
- }
800
-
801
- /**
802
- * 删除当前批注
803
- * @param id
804
- */
805
- removeComment(id: string): void {
806
- this.docComment.removeComment(id);
807
- this.selectionState.clear();
808
- }
809
-
810
- /**
811
- * 移除焦点所在的批注
812
- */
813
- removeCurrentComment(): void {
814
- const comment = ElementUtil.getParent(this.selectionState.startControl, (item => item instanceof CommContentBaseElement)) as CommContentBaseElement;
815
- if (comment) {
816
- this.removeComment(comment.props.id);
817
- }
818
- }
819
-
820
- /**
821
- * 插入批注
822
- */
823
- insertComment(): void {
824
- this.documentChange.insertComment();
825
- }
826
-
827
- /**
828
- * 清除所有批注
829
- */
830
- clearAllComments(): void {
831
- this.docComment.clearAllComments();
832
- }
833
-
834
-
835
- cutTable(): void {
836
- const row = ElementUtil.getParentByType(this.selectionState.startControl, TableRowElement) as TableRowElement;
837
- const tb = row?.parent as TableElement;
838
- TableUtil.cutTable(tb, row.getIndex());
839
- const para = new ParagraphElement();
840
- tb.parent.addChild(para, tb.getIndex() + 1);
841
- }
842
-
843
- /**
844
- * 初始化当前文档创建用户信息
845
- * 一份文档只需要设置一次
846
- */
847
- initCurrentDocUser(userId: string, userName: string, date: string): void {
848
- const doc = this.docCtx.document;
849
- doc.props.createUserId = userId;
850
- doc.props.createUserName = userName;
851
- doc.props.createDate = date;
852
- }
853
-
854
- /**
855
- * 验证文档内容
856
- * @returns
857
- */
858
- validate(): boolean {
859
- this.docComment.clearAllValidates();
860
- return this.documentChange.validate();
861
- }
862
-
863
- /**
864
- * 撤销
865
- */
866
- undo(): void {
867
- this.docHistory.undo();
868
- }
869
-
870
- /**
871
- * 恢复
872
- */
873
- redo(): void {
874
- this.docHistory.redo();
875
- }
876
-
877
- /**
878
- * 是否可以撤销
879
- */
880
- canUndo(): boolean {
881
- return this.docHistory.canUndo;
882
- }
883
-
884
- /**
885
- * 是否可以恢复
886
- */
887
- canRedo(): boolean {
888
- return this.docHistory.canRedo;
889
- }
890
-
891
- switchTrackChanges(eleCtx: BranchElement | null = null): void {
892
- eleCtx = eleCtx || this.docCtx.document;
893
- const body = eleCtx.treeFind(item => item instanceof DocumentBodyElement) as DocumentBodyElement;
894
- if (body) {
895
- body.trackChanges = !body.trackChanges;
896
- } else {
897
- throw new Error('未找到doc-body');
898
- }
899
- }
900
-
901
- get trackTipsChanged() {
902
- return this.documentEvent.trackTipsChanged;
903
- }
904
-
905
- switchFullViewPage(): void {
906
- this.viewOptions.fullPageView = !this.viewOptions.fullPageView;
907
- }
908
-
909
- getSelectedJSON(): string {
910
- return ElementSerialize.getSelectedJSON(this.selectionState, this.viewOptions);
911
- }
912
-
913
- getSelectedText(): string {
914
- const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
915
- return ElementSerialize.serializeString(copySerializeStr as BranchElement);
916
- }
917
-
918
- /**
919
- * 设置纸张方向
920
- * @param orientation
921
- */
922
- setPaperOrient(orientation: OrientType): void {
923
- this.docCtx.document.props.orient = orientation;
924
- this.viewOptions.docPageSettings.orient = orientation;
925
- this.resetViewer('force');
926
- this.selectionState.clear();
927
- }
928
-
929
- /**
930
- * 设置纸张大小,单位为毫米(mm)
931
- * @param width
932
- * @param height
933
- */
934
- setPaperSize(width: number, height: number): void {
935
- const docProps = this.docCtx.document.props;
936
- docProps.width = width;
937
- docProps.height = height;
938
- width = Math.floor(width * this.viewOptions.mmToPixelsRatio);
939
- height = Math.floor(height * this.viewOptions.mmToPixelsRatio);
940
- this.viewOptions.docPageSettings = new PageOptions(width, height, docProps.orient);
941
- this.resetViewer('force');
942
- }
943
-
944
- /**
945
- * 插入强制换页符
946
- */
947
- insertPageBreakPara(): void {
948
- this.documentChange.insertPageBreakPara();
949
- }
950
-
951
- /**
952
- * 显示当前元素到视图中
953
- * @param element
954
- */
955
- bringToView(element: Element): void {
956
- const ele = element instanceof BranchElement ? ElementUtil.getFirstLeafElement(element) : element as LeafElement;
957
- if (ele) {
958
- const region = ElementUtil.getElementRegion(ele);
959
- const renderObj = ele.paintRenders[0];
960
- const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject) as DocumentRenderObject;
961
- const index = docRender.getIndex();
962
- const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
963
- this.selectionState.surround(element);
964
- if (cursorPos.rect.y - this.viewOptions.translateY > 0 && cursorPos.rect.y - this.viewOptions.translateY < this.viewOptions.viewPaintHeight) {
965
- return;
966
- }
967
- this.docScroll.scrollTo(cursorPos.rect.x, cursorPos.rect.y - this.viewOptions.translateY);
968
- }
969
- }
970
-
971
- /**
972
- * 设置当前文档页边距
973
- */
974
- setDocumentMargin(pageMargin: Partial<MarginProps>): void {
975
- if (!this.docCtx.document) {
976
- return;
977
- }
978
- this.docCtx.document.updateMargin(pageMargin);
979
- }
980
-
981
- /**
982
- * 插入元素
983
- * @param targetElement
984
- * @param targetOffset
985
- * @param destEleArray
986
- * @returns
987
- */
988
- insertElement(targetElement: Element, targetOffset: number, destEleArray: Array<Element>): Element | null {
989
- if (!this.selectionState.editable) {
990
- return null;
991
- }
992
- return this.documentChange.insertElement(targetElement, targetOffset, destEleArray);
993
- }
994
-
995
-
996
- }
997
-
998
-
999
- export type EditorCurrentPos = {
1000
- pos: Position
1001
- };
1002
-
1003
- export type EditorContenxtProps = {
1004
- menus: Array<ContentMenuItem>
1005
- } & EditorCurrentPos
1006
-
1007
- export type EditorPanelProps = {
1008
- type: string;
1009
- } & EditorCurrentPos;
1010
-