@hailin-zheng/editor-core 1.0.3 → 1.0.6

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