@hailin-zheng/editor-core 2.1.17 → 2.1.19

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 (31) hide show
  1. package/index-cjs.d.ts +0 -1
  2. package/index-cjs.js +698 -574
  3. package/index-cjs.js.map +1 -1
  4. package/index.d.ts +0 -1
  5. package/index.js +698 -573
  6. package/index.js.map +1 -1
  7. package/med_editor/doc-editor.d.ts +3 -1
  8. package/med_editor/editor-core.d.ts +4 -0
  9. package/med_editor/framework/common-util.d.ts +1 -0
  10. package/med_editor/framework/document-arrange.d.ts +9 -4
  11. package/med_editor/framework/document-context.d.ts +0 -8
  12. package/med_editor/framework/document-paint.d.ts +3 -3
  13. package/med_editor/framework/document-print-offscreen.d.ts +4 -4
  14. package/med_editor/framework/document-svg.d.ts +10 -4
  15. package/med_editor/framework/element-define.d.ts +1 -3
  16. package/med_editor/framework/element-props.d.ts +15 -1
  17. package/med_editor/framework/element-reader.d.ts +6 -1
  18. package/med_editor/framework/element-render-cut.d.ts +7 -5
  19. package/med_editor/framework/element-util.d.ts +1 -1
  20. package/med_editor/framework/event-subject.d.ts +9 -0
  21. package/med_editor/framework/impl/comments/comment-element-impl.d.ts +7 -0
  22. package/med_editor/framework/impl/comments/comments-container-impl.d.ts +2 -22
  23. package/med_editor/framework/impl/data-element/data-element-image-impl.d.ts +0 -2
  24. package/med_editor/framework/impl/document/doc-impl.d.ts +20 -2
  25. package/med_editor/framework/impl/picture/image-impl.d.ts +0 -2
  26. package/med_editor/framework/impl/table/table-row-impl.d.ts +2 -0
  27. package/med_editor/framework/range-util.d.ts +1 -1
  28. package/med_editor/framework/render-define.d.ts +1 -1
  29. package/med_editor/framework/selection-overlays.d.ts +4 -2
  30. package/package.json +1 -1
  31. package/med_editor/framework/document-images-loader.d.ts +0 -20
package/index-cjs.js CHANGED
@@ -582,6 +582,16 @@ class CommonUtil {
582
582
  }
583
583
  return str;
584
584
  }
585
+ //随机生成rgb颜色
586
+ static randomRgbColor(opacity = -1) {
587
+ let r = Math.floor(Math.random() * 256); //随机生成256以内r值
588
+ let g = Math.floor(Math.random() * 256); //随机生成256以内g值
589
+ let b = Math.floor(Math.random() * 256); //随机生成256以内b值
590
+ if (opacity === -1) {
591
+ return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
592
+ }
593
+ return `rgba(${r},${g},${b},${opacity})`; //返回rgba(r,g,b,a)格式颜色
594
+ }
585
595
  /**
586
596
  * 判断一个数值是否在另一个数值的增益区间中
587
597
  * @param val
@@ -1101,6 +1111,40 @@ class SubjectSubscription$1 extends Subscription$1 {
1101
1111
  function fromEvent(dom, type) {
1102
1112
  return new DOMEventSource(dom, type);
1103
1113
  }
1114
+ class EventBus {
1115
+ subs = new Map();
1116
+ on(event, handler) {
1117
+ let handlers = this.subs.get(event);
1118
+ if (!handlers) {
1119
+ handlers = [];
1120
+ this.subs.set(event, handlers);
1121
+ }
1122
+ const sub = new Subject$1();
1123
+ sub.subscribe(handler);
1124
+ handlers.push(sub);
1125
+ }
1126
+ off(event) {
1127
+ const subs = this.subs.get(event);
1128
+ if (subs) {
1129
+ subs.forEach(item => item.unsubscribe());
1130
+ }
1131
+ this.subs.delete(event);
1132
+ }
1133
+ emit(event, data) {
1134
+ const subs = this.subs.get(event);
1135
+ if (subs) {
1136
+ subs.forEach(item => item.next(data));
1137
+ }
1138
+ }
1139
+ clear() {
1140
+ this.subs.forEach((subs) => {
1141
+ subs.forEach((sub) => {
1142
+ sub.unsubscribe();
1143
+ });
1144
+ });
1145
+ this.subs.clear();
1146
+ }
1147
+ }
1104
1148
 
1105
1149
  class Rect {
1106
1150
  x = 0;
@@ -1705,17 +1749,7 @@ class ViewOptions {
1705
1749
  //两个页的间距
1706
1750
  docSpace = 0;
1707
1751
  //是否显示审阅窗口
1708
- _showReviewWindow = false;
1709
- get showReviewWindow() {
1710
- return this._showReviewWindow;
1711
- }
1712
- set showReviewWindow(value) {
1713
- if (value === this._showReviewWindow) {
1714
- return;
1715
- }
1716
- this._showReviewWindow = value;
1717
- // this.onChange.next();
1718
- }
1752
+ showReviewWindow = false;
1719
1753
  //审阅窗口宽度
1720
1754
  reviewWindowWidth = 200;
1721
1755
  //缩放
@@ -2400,32 +2434,47 @@ class CommContentProps extends INotifyPropertyChanged {
2400
2434
  createId;
2401
2435
  createName;
2402
2436
  createDate;
2437
+ text;
2403
2438
  clone(dest) {
2404
2439
  const clone = dest ?? new CommContentProps();
2405
2440
  super.cloneAttachedProperty(clone);
2406
2441
  clone.id = this.id;
2442
+ clone.text = this.text;
2407
2443
  return clone;
2408
2444
  }
2409
2445
  getSerializeProps(viewOptions) {
2410
2446
  return {
2411
- id: this.id
2447
+ id: this.id,
2448
+ text: this.text
2412
2449
  };
2413
2450
  }
2414
2451
  }
2415
2452
  class CommProps extends INotifyPropertyChanged {
2416
2453
  id;
2417
2454
  markType;
2455
+ text;
2456
+ userId;
2457
+ userName;
2458
+ date;
2418
2459
  clone(dest) {
2419
2460
  const clone = dest ?? new CommProps();
2420
2461
  super.cloneAttachedProperty(clone);
2421
2462
  clone.id = this.id;
2422
2463
  clone.markType = this.markType;
2464
+ clone.text = this.text;
2465
+ clone.userId = this.userId;
2466
+ clone.userName = this.userName;
2467
+ clone.date = this.date;
2423
2468
  return clone;
2424
2469
  }
2425
2470
  getSerializeProps(viewOptions) {
2426
2471
  return {
2427
2472
  id: this.id,
2428
- markType: this.markType
2473
+ markType: this.markType,
2474
+ text: this.text,
2475
+ userId: this.userId,
2476
+ userName: this.userName,
2477
+ date: this.date
2429
2478
  };
2430
2479
  }
2431
2480
  }
@@ -2753,63 +2802,6 @@ class CommsContainerElement extends BlockContainerElement {
2753
2802
  }
2754
2803
  return clone;
2755
2804
  }
2756
- markPairs = [];
2757
- /**
2758
- * 清除所有的批注标识组合
2759
- */
2760
- clearMarkItems() {
2761
- this.markPairs.length = 0;
2762
- }
2763
- identifyCommMark(markElement) {
2764
- const { id } = markElement.props;
2765
- let matchItem = this.markPairs.find(item => item.id === id);
2766
- if (!matchItem) {
2767
- matchItem = { id };
2768
- this.markPairs.push(matchItem);
2769
- }
2770
- matchItem[markElement.props.markType] = markElement;
2771
- }
2772
- /**
2773
- * 根据id,移除批注标记以及批注内容
2774
- * @param id
2775
- */
2776
- removeCommMark(id) {
2777
- const matchIndex = this.markPairs.findIndex(item => item.id === id);
2778
- if (matchIndex >= 0) {
2779
- const matchItem = this.markPairs[matchIndex];
2780
- matchItem.start?.remove();
2781
- matchItem.end?.remove();
2782
- this.markPairs.splice(matchIndex, 1);
2783
- }
2784
- const commContent = this.getCommContent(id);
2785
- if (commContent) {
2786
- commContent.remove();
2787
- }
2788
- }
2789
- /**
2790
- * 清除所有批注
2791
- */
2792
- clearAllComms() {
2793
- for (let i = 0; i < this.markPairs.length; i++) {
2794
- const { start, end } = this.markPairs[i];
2795
- if (start) {
2796
- start.remove();
2797
- }
2798
- if (end) {
2799
- end.remove();
2800
- }
2801
- }
2802
- this.clearItems();
2803
- }
2804
- getCommContent(id) {
2805
- for (let i = 0; i < this.length; i++) {
2806
- const commContent = this.getChild(i);
2807
- if (commContent.props.id === id) {
2808
- return commContent;
2809
- }
2810
- }
2811
- return null;
2812
- }
2813
2805
  }
2814
2806
  class CommsContainerRenderObject extends BlockContainerRenderObject {
2815
2807
  //批注内容是否已经重组,只要重新绘制的时候组合一次即可
@@ -3271,7 +3263,7 @@ class DocumentElement extends BlockContainerElement {
3271
3263
  bodyElement;
3272
3264
  headerElement;
3273
3265
  footerElement;
3274
- commentsContainerElement;
3266
+ //commentsContainerElement!: CommsContainerElement;
3275
3267
  headerEditState = false;
3276
3268
  constructor() {
3277
3269
  super('doc');
@@ -3349,6 +3341,49 @@ class DocumentElement extends BlockContainerElement {
3349
3341
  ss.clear();
3350
3342
  this.refreshView();
3351
3343
  }
3344
+ markPairs = [];
3345
+ /**
3346
+ * 清除所有的批注标识组合
3347
+ */
3348
+ clearMarkItems() {
3349
+ this.markPairs.length = 0;
3350
+ }
3351
+ identifyCommMark(markElement) {
3352
+ const { id } = markElement.props;
3353
+ let matchItem = this.markPairs.find(item => item.id === id);
3354
+ if (!matchItem) {
3355
+ matchItem = { id };
3356
+ this.markPairs.push(matchItem);
3357
+ }
3358
+ matchItem[markElement.props.markType] = markElement;
3359
+ }
3360
+ /**
3361
+ * 根据id,移除批注标记以及批注内容
3362
+ * @param id
3363
+ */
3364
+ removeCommMark(id) {
3365
+ const matchIndex = this.markPairs.findIndex(item => item.id === id);
3366
+ if (matchIndex >= 0) {
3367
+ const matchItem = this.markPairs[matchIndex];
3368
+ matchItem.start?.remove();
3369
+ matchItem.end?.remove();
3370
+ this.markPairs.splice(matchIndex, 1);
3371
+ }
3372
+ }
3373
+ /**
3374
+ * 清除所有批注
3375
+ */
3376
+ clearAllComms() {
3377
+ for (let i = 0; i < this.markPairs.length; i++) {
3378
+ const { start, end } = this.markPairs[i];
3379
+ if (start) {
3380
+ start.remove();
3381
+ }
3382
+ if (end) {
3383
+ end.remove();
3384
+ }
3385
+ }
3386
+ }
3352
3387
  }
3353
3388
  class DocumentRenderObject extends BlockContainerRenderObject {
3354
3389
  constructor(ele) {
@@ -4703,10 +4738,16 @@ class TableRowElement extends BlockContainerElement {
4703
4738
  }
4704
4739
  }
4705
4740
  class TableRowRenderObject extends MuiltBlockLineRenderObject {
4741
+ //被截断的行是否需要重新计算高度
4742
+ remeasureState = true;
4743
+ //当前行是否存在合并单元格
4744
+ hasMergeCells = undefined;
4706
4745
  render(e) {
4707
4746
  }
4708
4747
  clone() {
4709
4748
  const cloneRender = new TableRowRenderObject(this.element);
4749
+ cloneRender.remeasureState = this.remeasureState;
4750
+ cloneRender.hasMergeCells = this.hasMergeCells;
4710
4751
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
4711
4752
  for (let i = 0; i < this.length; i++) {
4712
4753
  cloneRender.addChild(this.getChild(i).clone());
@@ -5339,7 +5380,7 @@ class DocumentCursor {
5339
5380
  }
5340
5381
 
5341
5382
  class RangeUtil {
5342
- static getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5383
+ static getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5343
5384
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5344
5385
  const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5345
5386
  return this.getTableSelectionRange(startControl, startOffset, endControl, endOffset, tbElement);
@@ -5418,7 +5459,7 @@ class RangeUtil {
5418
5459
  });
5419
5460
  }
5420
5461
  else {
5421
- const cellRange = this.getSelctionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5462
+ const cellRange = this.getSectionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5422
5463
  cellRanges.push(cellRange);
5423
5464
  }
5424
5465
  }
@@ -7257,12 +7298,42 @@ class CommentsUtil {
7257
7298
  }
7258
7299
  }
7259
7300
 
7301
+ let activeEditorContext = null;
7302
+ function setActiveEditorContext(ctx) {
7303
+ activeEditorContext = ctx;
7304
+ }
7305
+ function getActiveEditorContext() {
7306
+ return activeEditorContext;
7307
+ }
7308
+ function createSignal(state) {
7309
+ let _state = state;
7310
+ const activeCtx = activeEditorContext;
7311
+ const signal = {
7312
+ get value() {
7313
+ return _state;
7314
+ },
7315
+ set value(v) {
7316
+ if (v === _state) {
7317
+ return;
7318
+ }
7319
+ _state = v;
7320
+ signal.onChange();
7321
+ },
7322
+ onChange: () => {
7323
+ activeCtx?.onChange();
7324
+ }
7325
+ };
7326
+ return signal;
7327
+ }
7328
+
7260
7329
  class CommentElement extends LeafElement {
7330
+ color;
7261
7331
  constructor() {
7262
7332
  super('comm');
7263
7333
  this.isDecorate = true;
7264
7334
  this.disableClick = true;
7265
7335
  this.props = new CommProps();
7336
+ this.color = CommonUtil.randomRgbColor(0.5);
7266
7337
  }
7267
7338
  createRenderObject() {
7268
7339
  const render = new CommentRenderObject(this);
@@ -7315,6 +7386,7 @@ class CommentRenderObject extends LeafRenderObject {
7315
7386
  }
7316
7387
  }
7317
7388
  }];
7389
+ this.createCommentTips(event);
7318
7390
  return t;
7319
7391
  }
7320
7392
  clone() {
@@ -7322,6 +7394,90 @@ class CommentRenderObject extends LeafRenderObject {
7322
7394
  clone.rect = ElementUtil.cloneRect(this.rect);
7323
7395
  return clone;
7324
7396
  }
7397
+ createCommentTips(event) {
7398
+ if (this.element.props.markType === 'end') {
7399
+ return;
7400
+ }
7401
+ if (this.element.paintRenders.indexOf(this) !== 0) {
7402
+ return;
7403
+ }
7404
+ const appCtx = getActiveEditorContext();
7405
+ const opType = '批注:';
7406
+ const content = this.element.props.text;
7407
+ const left = 5;
7408
+ let sel = 'div.tg-container';
7409
+ const node = {
7410
+ sel,
7411
+ key: this.element.props.id,
7412
+ data: {
7413
+ style: {
7414
+ left: `${left}px`,
7415
+ top: `${event.globalPos.y}px`
7416
+ },
7417
+ on: {
7418
+ click: (e) => {
7419
+ e.stopPropagation();
7420
+ appCtx?.emit('comment-click', {
7421
+ ...this.element.props
7422
+ });
7423
+ //this.showCommentRange(appCtx!);
7424
+ },
7425
+ dblclick: (e) => {
7426
+ e.stopPropagation();
7427
+ appCtx?.emit('comment-dblclick', {
7428
+ ...this.element.props
7429
+ });
7430
+ }
7431
+ }
7432
+ },
7433
+ children: [{
7434
+ sel: 'div.header',
7435
+ data: {},
7436
+ children: [{
7437
+ sel: 'span.header-user',
7438
+ data: {},
7439
+ text: this.element.props.userName,
7440
+ }, {
7441
+ sel: 'span.header-date',
7442
+ data: {},
7443
+ text: this.element.props.date,
7444
+ }]
7445
+ }, {
7446
+ sel: 'div.content',
7447
+ data: {},
7448
+ text: opType + content
7449
+ }, {
7450
+ sel: 'div.bg',
7451
+ data: {
7452
+ style: {
7453
+ background: this.element.color
7454
+ }
7455
+ }
7456
+ }]
7457
+ };
7458
+ event.addChangeTips(node);
7459
+ // <div class="container">
7460
+ // <div class="header">
7461
+ // <span class="header-user">张三</span>
7462
+ // <span class="header-date">2023.1.21 16:06</span>
7463
+ // </div>
7464
+ // <div class="content">修改了字符串</div>
7465
+ // </div>
7466
+ }
7467
+ /**
7468
+ * 显示批注范围
7469
+ * @private
7470
+ */
7471
+ showCommentRange(appCtx) {
7472
+ const doc = ElementUtil.getParent(this.element, (item) => item.type === 'doc');
7473
+ const commPair = doc.treeFilter(item => item instanceof CommentElement && item.props.id === this.element.props.id);
7474
+ if (commPair.length === 2) {
7475
+ const range = new SelectionRange();
7476
+ range.setStart(commPair[0], 0);
7477
+ range.setEnd(commPair[1], 1);
7478
+ appCtx.selectionState.addRange(range);
7479
+ }
7480
+ }
7325
7481
  }
7326
7482
  class CommentFactory extends ElementFactory {
7327
7483
  match(type) {
@@ -7332,6 +7488,7 @@ class CommentFactory extends ElementFactory {
7332
7488
  const props = data.props;
7333
7489
  ele.props.id = props.id;
7334
7490
  ele.props.markType = props.markType;
7491
+ ele.props.text = props.text;
7335
7492
  return ele;
7336
7493
  }
7337
7494
  }
@@ -8895,18 +9052,6 @@ class DataElementImage extends DataElementLeaf {
8895
9052
  this.props.clone(clone.props);
8896
9053
  return clone;
8897
9054
  }
8898
- loadImage(ctx) {
8899
- if (this.status === 'no') {
8900
- this.status = 'loading';
8901
- const onCallback = (status) => {
8902
- this.status = status;
8903
- if (status === 'completed') {
8904
- this.refreshView();
8905
- }
8906
- };
8907
- ctx.imageLoader.loadImage(this.props.src, onCallback);
8908
- }
8909
- }
8910
9055
  destroy() {
8911
9056
  super.destroy();
8912
9057
  }
@@ -8922,38 +9067,6 @@ class DataElementImage extends DataElementLeaf {
8922
9067
  }
8923
9068
  class DataImageRenderObject extends ResizeLeafRenderObject {
8924
9069
  render(e) {
8925
- const { render, position, docCtx } = e;
8926
- const dataImgElement = this.element;
8927
- const picProps = dataImgElement.props;
8928
- if (dataImgElement.status === 'no') {
8929
- dataImgElement.loadImage(docCtx);
8930
- return;
8931
- }
8932
- if (dataImgElement.status === 'completed') {
8933
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
8934
- if (!imageSource) {
8935
- return;
8936
- }
8937
- if (picProps.border === 'all') {
8938
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
8939
- }
8940
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
8941
- }
8942
- if (render.drawMode === 'view') {
8943
- let { x, y } = position;
8944
- const { width, height } = this.rect;
8945
- const lineWidth = 5;
8946
- const paintColor = '#0050b3';
8947
- render.contentContext.strokeLines([{ x: x + lineWidth, y }, { x, y }, { x, y: y + height }, {
8948
- x: x + lineWidth,
8949
- y: y + height
8950
- }], 1, paintColor);
8951
- x = x + width;
8952
- render.contentContext.strokeLines([{ x: x - lineWidth, y }, { x, y }, { x, y: y + height }, {
8953
- x: x - lineWidth,
8954
- y: y + height
8955
- }], 1, paintColor);
8956
- }
8957
9070
  }
8958
9071
  clone() {
8959
9072
  const clone = new DataImageRenderObject(this.element);
@@ -9830,51 +9943,12 @@ class PictureElement extends LeafElement {
9830
9943
  this.props.clone(clone.props);
9831
9944
  return clone;
9832
9945
  }
9833
- loadImage(ctx) {
9834
- if (this.status === 'no') {
9835
- this.status = 'loading';
9836
- //this.imageSource = new Image();
9837
- //this.imageSource.src = this.props.src;
9838
- // const onload = (e: any) => {
9839
- // this.isLoad = 'completed';
9840
- // this.refreshView('appearance');
9841
- // };
9842
- // const onerror = (e: any) => {
9843
- // this.isLoad = 'error';
9844
- // console.error(e);
9845
- // };
9846
- const onCallback = (status) => {
9847
- this.status = status;
9848
- if (status === 'completed') {
9849
- this.refreshView();
9850
- }
9851
- };
9852
- ctx.imageLoader.loadImage(this.props.src, onCallback);
9853
- }
9854
- }
9855
9946
  destroy() {
9856
9947
  super.destroy();
9857
9948
  }
9858
9949
  }
9859
9950
  class PictureRenderObject extends ResizeLeafRenderObject {
9860
9951
  render(e) {
9861
- const { render, position, docCtx } = e;
9862
- const picElement = this.element;
9863
- const picProps = picElement.props;
9864
- if (picElement.status === 'no') {
9865
- picElement.loadImage(docCtx);
9866
- return;
9867
- }
9868
- if (picElement.status === 'completed') {
9869
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
9870
- if (!imageSource) {
9871
- return;
9872
- }
9873
- if (picProps.border === 'all') {
9874
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
9875
- }
9876
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
9877
- }
9878
9952
  }
9879
9953
  clone() {
9880
9954
  const clone = new PictureRenderObject(this.element);
@@ -11218,7 +11292,12 @@ class ElementUtil {
11218
11292
  if (render instanceof TableRenderObject) {
11219
11293
  //this.setTableAlign(render);
11220
11294
  this.remeasureTableMerge(render);
11221
- render.getItems().forEach(item => this.remeasure(item, false), null);
11295
+ render.getItems().forEach(item => {
11296
+ if (item.remeasureState) {
11297
+ this.remeasure(item, false);
11298
+ item.remeasureState = false;
11299
+ }
11300
+ }, null);
11222
11301
  }
11223
11302
  const innerRect = render.getInnerRect();
11224
11303
  innerRect.height = 0;
@@ -11234,7 +11313,7 @@ class ElementUtil {
11234
11313
  render.updateRenderHeight(innerRect);
11235
11314
  return innerRect.height;
11236
11315
  }
11237
- static remeasureTableRow(rowRender, foreceColIndex = -1) {
11316
+ static remeasureTableRow(rowRender, forceColIndex = -1) {
11238
11317
  const rowEle = rowRender.element;
11239
11318
  let maxCellHeight = rowEle.props.minHeight > 20 ? rowEle.props.minHeight : 20;
11240
11319
  //限制行最小高度
@@ -11243,7 +11322,7 @@ class ElementUtil {
11243
11322
  for (let i = 0; i < rowRender.length; i++) {
11244
11323
  const cellRender = rowRender.getChild(i);
11245
11324
  const { vMerge } = cellRender.element.props;
11246
- if (cellRender.rect.height > maxCellHeight && (vMerge !== 'restart' || i === foreceColIndex)) {
11325
+ if (cellRender.rect.height > maxCellHeight && (vMerge !== 'restart' || i === forceColIndex)) {
11247
11326
  maxCellHeight = cellRender.rect.height;
11248
11327
  }
11249
11328
  }
@@ -11252,7 +11331,7 @@ class ElementUtil {
11252
11331
  const cellRender = rowRender.getChild(i);
11253
11332
  const cellElement = cellRender.element;
11254
11333
  const { vMerge } = cellElement.props;
11255
- if ((vMerge !== 'restart' || i === foreceColIndex) || cellRender.rect.height < maxCellHeight) {
11334
+ if ((vMerge !== 'restart' || i === forceColIndex) || cellRender.rect.height < maxCellHeight) {
11256
11335
  cellRender.rect.height = maxCellHeight;
11257
11336
  }
11258
11337
  //处理单元格内容纵向居中
@@ -11347,11 +11426,16 @@ class ElementUtil {
11347
11426
  let needReCalc = false;
11348
11427
  for (let i = 0; i < tbRender.length; i++) {
11349
11428
  const row = tbRender.getChild(i);
11429
+ if (row.hasMergeCells === false) {
11430
+ continue;
11431
+ }
11432
+ row.hasMergeCells = false;
11350
11433
  for (let j = 0; j < row.length; j++) {
11351
11434
  const cellRender = row.getChild(j);
11352
11435
  const ele = cellRender.element;
11353
11436
  const { vMerge } = ele.props;
11354
11437
  if (vMerge === 'restart') {
11438
+ row.hasMergeCells = true;
11355
11439
  const eleIndex = ele.getIndex();
11356
11440
  const continueRows = this.getContinueVMergeRenderRows(tbRender, i, eleIndex);
11357
11441
  if (!continueRows.length) {
@@ -13281,29 +13365,29 @@ class ElementPaint {
13281
13365
  this.renderCtx.contentContext.fillRect(currPosition.x, currPosition.y, renderObject.rect.width, renderObject.rect.height, this.viewOptions.selectionOverlaysColor);
13282
13366
  }
13283
13367
  }
13284
- if (inViewPort && this.viewOptions.showReviewWindow && this.docCtx.document.commentsContainerElement.cacheRender.selectedSet.has(element)) {
13285
- if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13286
- const measureCommContainer = this.docCtx.document.commentsContainerElement.cacheRender;
13287
- const range = measureCommContainer.selectedSet.get(element);
13288
- if (range.isFullSelected) {
13289
- let commentRangePaintColor = '#ffd591';
13290
- for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13291
- const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13292
- if (commentRangeStatus.commContent.focus) {
13293
- if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13294
- commentRangePaintColor = '#fa8c16';
13295
- }
13296
- }
13297
- }
13298
- const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13299
- const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13300
- x: currPosition.x,
13301
- y: currPosition.y
13302
- });
13303
- this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13304
- }
13305
- }
13306
- }
13368
+ // if (inViewPort && this.viewOptions.showReviewWindow && (<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender).selectedSet.has(element)) {
13369
+ // if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13370
+ // const measureCommContainer=<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender;
13371
+ // const range = measureCommContainer.selectedSet.get(element) as SelectionContentRange;
13372
+ // if (range.isFullSelected) {
13373
+ // let commentRangePaintColor = '#ffd591';
13374
+ // for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13375
+ // const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13376
+ // if (commentRangeStatus.commContent.focus) {
13377
+ // if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13378
+ // commentRangePaintColor = '#fa8c16';
13379
+ // }
13380
+ // }
13381
+ // }
13382
+ // const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13383
+ // const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13384
+ // x: currPosition.x,
13385
+ // y: currPosition.y
13386
+ // });
13387
+ // this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13388
+ // }
13389
+ // }
13390
+ // }
13307
13391
  }
13308
13392
  /**
13309
13393
  * 触发页面绘制结束事件
@@ -13349,125 +13433,6 @@ class ElementPaint {
13349
13433
  }
13350
13434
  }
13351
13435
 
13352
- /**
13353
- * 用于处理选区拖蓝
13354
- */
13355
- class SelectionOverlays {
13356
- selectionState;
13357
- selectionRange;
13358
- selectedSets = new Map();
13359
- constructor(selectionState) {
13360
- this.selectionState = selectionState;
13361
- }
13362
- getSelectionTreeData() {
13363
- let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
13364
- this.selectedSets.clear();
13365
- if (this.selectionRange) {
13366
- this.selectionRange.selectedChildren.length = 0;
13367
- }
13368
- this.selectionRange = null;
13369
- if (!startControl || !endControl || !ancestorCommonControl) {
13370
- //this.selectionRange?.selectedChildren.length=0;
13371
- this.selectionState.selectedRange = null;
13372
- return;
13373
- }
13374
- if (collapsed) {
13375
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13376
- this.selectionState.selectedRange = commonRange;
13377
- this.selectedSets.clear();
13378
- return;
13379
- }
13380
- const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
13381
- startControl = fixStartElement.element;
13382
- startOffset = fixStartElement.offset;
13383
- const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
13384
- endControl = fixEndElement.element;
13385
- endOffset = fixEndElement.offset;
13386
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13387
- //console.log(commonRange);
13388
- this.selectionRange = commonRange;
13389
- this.convertSelectRangeToSet();
13390
- this.selectionState.selectedRange = commonRange;
13391
- }
13392
- convertSelectRangeToSet() {
13393
- this.selectedSets.clear();
13394
- if (this.selectionRange) {
13395
- SelectionOverlays.addToSets(this.selectionRange, this.selectedSets);
13396
- }
13397
- }
13398
- static addToSets(range, set) {
13399
- set.set(range.target, range);
13400
- for (let i = 0; i < range.selectedChildren.length; i++) {
13401
- //单元格全部选中效果,单元格整个拖蓝即可
13402
- if (range.isFullSelected && range.target.type === 'tbc') {
13403
- continue;
13404
- }
13405
- this.addToSets(range.selectedChildren[i], set);
13406
- }
13407
- }
13408
- /**
13409
- * 添加到批注集合
13410
- * @param range
13411
- * @param set
13412
- */
13413
- static addToCommentSets(range, set) {
13414
- set.set(range.target, range);
13415
- for (let i = 0; i < range.selectedChildren.length; i++) {
13416
- this.addToCommentSets(range.selectedChildren[i], set);
13417
- }
13418
- }
13419
- /**
13420
- * 修正开始选区内容
13421
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13422
- */
13423
- fixStartSelectionElement(element, offset, ancestorCommonControl) {
13424
- if (!(ancestorCommonControl instanceof TableElement)) {
13425
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13426
- if (lookupParentCell) {
13427
- if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
13428
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13429
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13430
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13431
- const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
13432
- if (!rowFirstLeafElement) {
13433
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13434
- }
13435
- return {
13436
- element: rowFirstLeafElement,
13437
- offset: 0
13438
- };
13439
- }
13440
- }
13441
- }
13442
- return { element, offset };
13443
- }
13444
- /**
13445
- * 修正开始选区内容
13446
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13447
- */
13448
- fixEndSelectionElement(element, offset, ancestorCommonControl) {
13449
- if (!(ancestorCommonControl instanceof TableElement)) {
13450
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13451
- if (lookupParentCell) {
13452
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13453
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13454
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13455
- const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
13456
- if (!rowLastLeafElement) {
13457
- ElementUtil.getLastLeafElement(lookupParentCell.parent);
13458
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13459
- }
13460
- return {
13461
- element: rowLastLeafElement,
13462
- offset: 1
13463
- };
13464
- }
13465
- }
13466
- }
13467
- return { element, offset };
13468
- }
13469
- }
13470
-
13471
13436
  class DocumentEvalFunc {
13472
13437
  docCtx;
13473
13438
  constructor(docCtx) {
@@ -13508,83 +13473,11 @@ class DocumentEvalFunc {
13508
13473
  this.scriptsFunc = null;
13509
13474
  }
13510
13475
  }
13511
- /**
13512
- * 触发动态脚本
13513
- */
13514
- invokedScripts() {
13515
- this.scriptsFunc?.();
13516
- }
13517
- }
13518
-
13519
- class DocumentImagesBaseLoader {
13520
- images = [];
13521
- clear() {
13522
- this.images.length = 0;
13523
- }
13524
- loadImage(src, onCallback) {
13525
- if (!src) {
13526
- return;
13527
- }
13528
- //已经存在的资源不需要重新加载
13529
- let matchItem = this.images.find(item => item.src === src);
13530
- if (matchItem) {
13531
- if (matchItem.loadStatus === 'no') {
13532
- matchItem.cbs.push(onCallback);
13533
- }
13534
- else {
13535
- onCallback(matchItem.loadStatus);
13536
- }
13537
- return;
13538
- }
13539
- const task = this.createRequestImage(src);
13540
- const imgItem = {
13541
- ele: undefined,
13542
- src,
13543
- cbs: [onCallback],
13544
- loadStatus: 'no',
13545
- task
13546
- };
13547
- this.images.push(imgItem);
13548
- // if (this.viewOptions.resourceMode === 'immediate') {
13549
- // ele.onload = (e) => { this.invokeImgLoad(src, 'completed'); };
13550
- // ele.onerror = (e) => { this.invokeImgLoad(src, 'error'); };
13551
- // }
13552
- }
13553
- invokeImgLoad(src, status, data) {
13554
- const img = this.images.find(item => item.src === src);
13555
- if (img) {
13556
- img.loadStatus = status;
13557
- img.cbs.forEach(cb => cb(status));
13558
- img.ele = data;
13559
- }
13560
- }
13561
- getLoadTasks() {
13562
- return this.images.map(item => item.task);
13563
- }
13564
- getImage(src) {
13565
- const img = this.images.find(item => item.src === src);
13566
- return img?.ele;
13567
- }
13568
- /**
13569
- * 判断图片是否都已经加载完毕
13570
- * 用于打印时判断,如果当前图片没有加载完毕就打印,图片是打印不出来
13571
- * @returns
13572
- */
13573
- imagesLoadCompleted() {
13574
- if (this.images.length === 0) {
13575
- return true;
13576
- }
13577
- return this.images.every(item => ['completed', 'error'].includes(item.loadStatus));
13578
- }
13579
- }
13580
- class DocumentImagesLoader extends DocumentImagesBaseLoader {
13581
- createRequestImage(url) {
13582
- const ele = new Image();
13583
- ele.src = url;
13584
- return new Promise((r, i) => {
13585
- ele.onload = (e) => { this.invokeImgLoad(url, 'completed', ele); r(); };
13586
- ele.onerror = (e) => { this.invokeImgLoad(url, 'error', ele); r(); };
13587
- });
13476
+ /**
13477
+ * 触发动态脚本
13478
+ */
13479
+ invokedScripts() {
13480
+ this.scriptsFunc?.();
13588
13481
  }
13589
13482
  }
13590
13483
 
@@ -13600,7 +13493,7 @@ class EditorContext {
13600
13493
  //文档刷新的订阅事件
13601
13494
  //refSub!: Subscription;
13602
13495
  syncRefresh;
13603
- imageLoader;
13496
+ //imageLoader: IImageLoader;
13604
13497
  dynamicFunc;
13605
13498
  docChange;
13606
13499
  clearPrevDocCb;
@@ -13610,7 +13503,7 @@ class EditorContext {
13610
13503
  this.selectionState = selectionState;
13611
13504
  this.viewOptions = viewOptions;
13612
13505
  this.dynamicFunc = new DocumentEvalFunc(this);
13613
- this.imageLoader = new DocumentImagesLoader();
13506
+ //this.imageLoader = new DocumentImagesLoader();
13614
13507
  this.selectionState.onChangedEvent.subscribe(() => {
13615
13508
  this.syncRefresh?.();
13616
13509
  });
@@ -13651,7 +13544,7 @@ class EditorContext {
13651
13544
  }
13652
13545
  clear() {
13653
13546
  this.selectionState.clear();
13654
- this.imageLoader.clear();
13547
+ //this.imageLoader.clear();
13655
13548
  this.dynamicFunc.destroyScripts();
13656
13549
  this.isDirty = false;
13657
13550
  }
@@ -13693,7 +13586,7 @@ class EditorContext {
13693
13586
  this.document.destroy();
13694
13587
  this.clearPrevDocCb?.();
13695
13588
  //this.ele_types_handlers.length = 0;
13696
- this.imageLoader.clear();
13589
+ //this.imageLoader.clear();
13697
13590
  this._document = null;
13698
13591
  }
13699
13592
  /**
@@ -13728,6 +13621,17 @@ class EditorContext {
13728
13621
  return this._document.modifyFlag === exports.ModifyFlag.None ? 'appearance' : 'content';
13729
13622
  }
13730
13623
  }
13624
+ // export interface IImageLoader {
13625
+ // clear(): void;
13626
+ //
13627
+ // loadImage(src: string, onCallback: (status: ImgLoadStatus) => void): void;
13628
+ //
13629
+ // getImage(src: string): HTMLImageElement | undefined;
13630
+ //
13631
+ // imagesLoadCompleted(): boolean;
13632
+ //
13633
+ // getLoadTasks(): Array<Promise<void>>;
13634
+ // }
13731
13635
  /**
13732
13636
  * 文档上下文
13733
13637
  */
@@ -14621,13 +14525,139 @@ class ParagraphMeasure {
14621
14525
  }
14622
14526
  }
14623
14527
 
14528
+ /**
14529
+ * 用于处理选区拖蓝
14530
+ */
14531
+ class SelectionOverlays {
14532
+ selectionState;
14533
+ selectionRange;
14534
+ //选区对象集合
14535
+ selectionEleSets = new Map();
14536
+ //批注对象集合
14537
+ commRangeSets = new Map();
14538
+ constructor(selectionState) {
14539
+ this.selectionState = selectionState;
14540
+ }
14541
+ getSelectionTreeData() {
14542
+ let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
14543
+ this.selectionEleSets.clear();
14544
+ if (this.selectionRange) {
14545
+ this.selectionRange.selectedChildren.length = 0;
14546
+ }
14547
+ this.selectionRange = null;
14548
+ if (!startControl || !endControl || !ancestorCommonControl) {
14549
+ //this.selectionRange?.selectedChildren.length=0;
14550
+ this.selectionState.selectedRange = null;
14551
+ return;
14552
+ }
14553
+ if (collapsed) {
14554
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14555
+ this.selectionState.selectedRange = commonRange;
14556
+ this.selectionEleSets.clear();
14557
+ return;
14558
+ }
14559
+ const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
14560
+ startControl = fixStartElement.element;
14561
+ startOffset = fixStartElement.offset;
14562
+ const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
14563
+ endControl = fixEndElement.element;
14564
+ endOffset = fixEndElement.offset;
14565
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14566
+ //console.log(commonRange);
14567
+ this.selectionRange = commonRange;
14568
+ this.convertSelectRangeToSet();
14569
+ this.selectionState.selectedRange = commonRange;
14570
+ }
14571
+ convertSelectRangeToSet() {
14572
+ this.selectionEleSets.clear();
14573
+ if (this.selectionRange) {
14574
+ SelectionOverlays.addToSets(this.selectionRange, this.selectionEleSets);
14575
+ }
14576
+ }
14577
+ static addToSets(range, set) {
14578
+ set.set(range.target, range);
14579
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14580
+ //单元格全部选中效果,单元格整个拖蓝即可
14581
+ if (range.isFullSelected && range.target.type === 'tbc') {
14582
+ continue;
14583
+ }
14584
+ this.addToSets(range.selectedChildren[i], set);
14585
+ }
14586
+ }
14587
+ /**
14588
+ * 添加到批注集合
14589
+ * @param range
14590
+ * @param set
14591
+ * @param rangeColor 用以显示批注区间的颜色
14592
+ */
14593
+ static addToCommentSets(range, set, rangeColor) {
14594
+ range['rangeColor'] = rangeColor;
14595
+ set.set(range.target, range);
14596
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14597
+ this.addToCommentSets(range.selectedChildren[i], set, rangeColor);
14598
+ }
14599
+ }
14600
+ /**
14601
+ * 修正开始选区内容
14602
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14603
+ */
14604
+ fixStartSelectionElement(element, offset, ancestorCommonControl) {
14605
+ if (!(ancestorCommonControl instanceof TableElement)) {
14606
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14607
+ if (lookupParentCell) {
14608
+ if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
14609
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14610
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14611
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14612
+ const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
14613
+ if (!rowFirstLeafElement) {
14614
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14615
+ }
14616
+ return {
14617
+ element: rowFirstLeafElement,
14618
+ offset: 0
14619
+ };
14620
+ }
14621
+ }
14622
+ }
14623
+ return { element, offset };
14624
+ }
14625
+ /**
14626
+ * 修正开始选区内容
14627
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14628
+ */
14629
+ fixEndSelectionElement(element, offset, ancestorCommonControl) {
14630
+ if (!(ancestorCommonControl instanceof TableElement)) {
14631
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14632
+ if (lookupParentCell) {
14633
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14634
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14635
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14636
+ const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
14637
+ if (!rowLastLeafElement) {
14638
+ ElementUtil.getLastLeafElement(lookupParentCell.parent);
14639
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14640
+ }
14641
+ return {
14642
+ element: rowLastLeafElement,
14643
+ offset: 1
14644
+ };
14645
+ }
14646
+ }
14647
+ }
14648
+ return { element, offset };
14649
+ }
14650
+ }
14651
+
14624
14652
  class DocumentArrange {
14625
14653
  docCtx;
14626
14654
  renderCtx;
14655
+ seo;
14627
14656
  options;
14628
- constructor(docCtx, renderCtx) {
14657
+ constructor(docCtx, renderCtx, seo) {
14629
14658
  this.docCtx = docCtx;
14630
14659
  this.renderCtx = renderCtx;
14660
+ this.seo = seo;
14631
14661
  this.options = this.docCtx.viewOptions;
14632
14662
  }
14633
14663
  /**
@@ -14649,24 +14679,25 @@ class DocumentArrange {
14649
14679
  parser: new DynamicContextParser(doc, this.docCtx.selectionState),
14650
14680
  createParaFn: () => this.createDefaultPara()
14651
14681
  };
14652
- doc.commentsContainerElement.clearMarkItems();
14682
+ doc.clearMarkItems();
14653
14683
  this.clearPaintCache(doc, data);
14654
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14684
+ //this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14655
14685
  const docRenders = this.arrangeDoc();
14656
14686
  this.setMeasureCompletedModifyFlag(doc);
14657
14687
  this.cacheDocRenders(docRenders);
14688
+ this.generateCommRange();
14658
14689
  return docRenders;
14659
14690
  });
14660
14691
  }
14661
- commentsRender;
14692
+ //commentsRender!: CommsContainerRenderObject;
14662
14693
  arrangeDoc() {
14663
14694
  const doc = this.docCtx.document;
14664
14695
  const docRender = doc.createRenderObject();
14665
14696
  const innerRect = docRender.getInnerRect();
14666
14697
  const headerRender = this.measureControl(doc.headerElement, innerRect.width);
14667
14698
  const footerRender = this.measureControl(doc.footerElement, innerRect.width);
14668
- const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth);
14669
- this.commentsRender = commentsRender;
14699
+ //const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth) as CommsContainerRenderObject;
14700
+ //this.commentsRender = commentsRender;
14670
14701
  const { headerLine, footerLine } = docRender;
14671
14702
  let bodyMarginTop = headerLine + headerRender.rect.height + 6;
14672
14703
  let bodyMarginBottom = footerLine + footerRender.rect.height;
@@ -14761,15 +14792,15 @@ class DocumentArrange {
14761
14792
  cloneFooterRender.rect.x = limitRect.x;
14762
14793
  cloneFooterRender.rect.y = documentRender.rect.height - bodyMarginBottom;
14763
14794
  currColumn === 0 && documentRender.addChild(cloneFooterRender);
14764
- //审阅模式,添加审阅窗口
14765
- if (this.options.showReviewWindow && commentsRender) {
14766
- const commentsContainer = this.createRenderObject(commentsRender.element);
14767
- commentsContainer.padding.top = bodyMarginTop;
14768
- commentsContainer.rect.height = documentRender.rect.height;
14769
- documentRender.addChild(commentsContainer);
14770
- commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14771
- documentRender.rect.width += this.options.reviewWindowWidth;
14772
- }
14795
+ // //审阅模式,添加审阅窗口
14796
+ // if (this.options.showReviewWindow && commentsRender) {
14797
+ // const commentsContainer = this.createRenderObject(commentsRender.element) as CommsContainerRenderObject;
14798
+ // commentsContainer.padding.top = bodyMarginTop;
14799
+ // commentsContainer.rect.height = documentRender.rect.height;
14800
+ // documentRender.addChild(commentsContainer);
14801
+ // commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14802
+ // documentRender.rect.width += this.options.reviewWindowWidth;
14803
+ // }
14773
14804
  currColumn++;
14774
14805
  if (currColumn === docColumns) {
14775
14806
  currColumn = 0;
@@ -14797,8 +14828,7 @@ class DocumentArrange {
14797
14828
  }
14798
14829
  if (element instanceof BlockContentElement) {
14799
14830
  const pRange = new ParagraphMeasure(this.options, this.renderCtx);
14800
- const innerLineRects = pRange.measureParagraph(element, maxWidth);
14801
- return innerLineRects;
14831
+ return pRange.measureParagraph(element, maxWidth);
14802
14832
  }
14803
14833
  else if (element instanceof BlockContainerElement) {
14804
14834
  const renders = [];
@@ -14936,7 +14966,6 @@ class DocumentArrange {
14936
14966
  * 切割渲染元素
14937
14967
  * @param tbRender 被切割的对象
14938
14968
  * @param limitHeight
14939
- * @param addFunc
14940
14969
  * @returns
14941
14970
  */
14942
14971
  cutTable(tbRender, limitHeight) {
@@ -14966,29 +14995,27 @@ class DocumentArrange {
14966
14995
  while (currRow) {
14967
14996
  const rowContentHeight = this.getBlockLineHeight(currRow);
14968
14997
  if (rowContentHeight + sumHeight > limitHeight) {
14969
- if (currRow instanceof MuiltBlockLineRenderObject) {
14970
- //限制的外框尺寸
14971
- const availHeight = limitHeight - sumHeight;
14972
- //限制的内框尺寸
14973
- const limitRenderInnterHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
14974
- const cutRow = this.cutRowRenderItem(currRow, limitRenderInnterHeight);
14975
- if (cutRow) {
14976
- cloneTbRender.addChild(cutRow);
14977
- sumHeight += cutRow.rect.height;
14978
- if (currRow.getItems().some(item => item.length !== 0)) {
14979
- cutRows.push(currRow);
14980
- }
14981
- else {
14982
- tbRender.removeChild(currRow);
14983
- }
14984
- if (currRow === joinRow) {
14985
- break;
14986
- }
14987
- currRow = rows[++j];
14998
+ //行存在最小高度,且当前行跨页的情况下,不截断该行
14999
+ if (currRow.element.props.minHeight) {
15000
+ break;
15001
+ }
15002
+ //限制的外框尺寸
15003
+ const availHeight = limitHeight - sumHeight;
15004
+ const limitRenderInnerHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
15005
+ const cutRow = this.cutRowRenderItem(currRow, limitRenderInnerHeight);
15006
+ if (cutRow) {
15007
+ cloneTbRender.addChild(cutRow);
15008
+ sumHeight += cutRow.rect.height;
15009
+ if (currRow.getItems().some(item => item.length !== 0)) {
15010
+ cutRows.push(currRow);
14988
15011
  }
14989
15012
  else {
15013
+ tbRender.removeChild(currRow);
15014
+ }
15015
+ if (currRow === joinRow) {
14990
15016
  break;
14991
15017
  }
15018
+ currRow = rows[++j];
14992
15019
  }
14993
15020
  else {
14994
15021
  break;
@@ -15020,6 +15047,7 @@ class DocumentArrange {
15020
15047
  // if (render.element.props.minHeight > 0 && render.rect.height < limitHeight) {
15021
15048
  // return null;
15022
15049
  // }
15050
+ render.remeasureState = true;
15023
15051
  const cloneRowRender = render.element.createRenderObject();
15024
15052
  cloneRowRender.rect.width = render.rect.width;
15025
15053
  //cloneRowRender.rect.maxWidth = render.rect.height;
@@ -15211,7 +15239,7 @@ class DocumentArrange {
15211
15239
  }
15212
15240
  identifyComment(ele) {
15213
15241
  if (ele instanceof CommentElement) {
15214
- this.docCtx.document.commentsContainerElement.identifyCommMark(ele);
15242
+ this.docCtx.document.identifyCommMark(ele);
15215
15243
  }
15216
15244
  }
15217
15245
  cacheDoc;
@@ -15222,6 +15250,22 @@ class DocumentArrange {
15222
15250
  });
15223
15251
  this.cacheDoc = null;
15224
15252
  }
15253
+ /**
15254
+ * 生成批注区间信息
15255
+ * @param renderTree
15256
+ */
15257
+ generateCommRange() {
15258
+ this.seo.commRangeSets.clear();
15259
+ const commMarks = this.docCtx.document.markPairs;
15260
+ for (let i = 0; i < commMarks.length; i++) {
15261
+ const commMark = commMarks[i];
15262
+ if (commMark.start && commMark.end) {
15263
+ const ancestor = DocumentSelection.getAncestorCommonControl(commMark.start, commMark.end);
15264
+ const range = RangeUtil.getSectionRange(commMark.start, 0, commMark.end, 1, ancestor);
15265
+ SelectionOverlays.addToCommentSets(range, this.seo.commRangeSets, commMark.start.color);
15266
+ }
15267
+ }
15268
+ }
15225
15269
  cacheRenders(renderTree) {
15226
15270
  if (renderTree.element) {
15227
15271
  renderTree.element.paintRenders.push(renderTree);
@@ -15916,7 +15960,10 @@ class ElementRenderCut {
15916
15960
  documentRender.addChild(cloneFooterRender);
15917
15961
  //审阅模式,添加审阅窗口
15918
15962
  if (this.options.showReviewWindow && commentsRender) {
15919
- const commentsContainer = commentsRender.element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
15963
+ const commentsContainer = commentsRender.element.createRenderObject({
15964
+ options: this.options,
15965
+ renderCtx: this.renderContext
15966
+ });
15920
15967
  commentsContainer.padding.top = bodyMarginTop;
15921
15968
  commentsContainer.rect.height = documentRender.rect.height;
15922
15969
  documentRender.addChild(commentsContainer);
@@ -15927,13 +15974,19 @@ class ElementRenderCut {
15927
15974
  return docPages;
15928
15975
  }
15929
15976
  getDocInnerRect(documentRender) {
15930
- const render = documentRender.element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
15977
+ const render = documentRender.element.createRenderObject({
15978
+ options: this.options,
15979
+ renderCtx: this.renderContext
15980
+ });
15931
15981
  render.padding = documentRender.padding;
15932
15982
  return render.getInnerRect();
15933
15983
  }
15934
15984
  getFullViewDocRender(documentRender, documentElement) {
15935
15985
  const commentsRender = documentRender.getChild(3);
15936
- const commentsContainer = commentsRender.element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
15986
+ const commentsContainer = commentsRender.element.createRenderObject({
15987
+ options: this.options,
15988
+ renderCtx: this.renderContext
15989
+ });
15937
15990
  documentRender.rect.height -= commentsContainer.rect.height;
15938
15991
  const bodyRender = documentRender.getChild(1);
15939
15992
  if (this.options.showReviewWindow) {
@@ -15947,7 +16000,10 @@ class ElementRenderCut {
15947
16000
  return [documentRender];
15948
16001
  }
15949
16002
  createEmptyBodyRender(bodyRender, limitRect) {
15950
- const pageBodyRender = bodyRender.element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
16003
+ const pageBodyRender = bodyRender.element.createRenderObject({
16004
+ options: this.options,
16005
+ renderCtx: this.renderContext
16006
+ });
15951
16007
  pageBodyRender.rect.width = limitRect.width;
15952
16008
  const bodyInnerLimitRect = pageBodyRender.getInnerRect();
15953
16009
  if (this.options.fullPageView) {
@@ -15971,7 +16027,10 @@ class ElementRenderCut {
15971
16027
  if (render instanceof TableRenderObject) {
15972
16028
  return this.cutTable(render, limitHeight);
15973
16029
  }
15974
- const cloneRender = render.element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
16030
+ const cloneRender = render.element.createRenderObject({
16031
+ options: this.options,
16032
+ renderCtx: this.renderContext
16033
+ });
15975
16034
  cloneRender.setRenderWidth(render.rect.width);
15976
16035
  if (render instanceof MuiltBlockLineRenderObject) {
15977
16036
  let sumHeight = 0;
@@ -16106,16 +16165,16 @@ class ElementRenderCut {
16106
16165
  }
16107
16166
  const cloneRowRender = render.element.createRenderObject();
16108
16167
  cloneRowRender.rect.width = render.rect.width;
16168
+ render.remeasureState = true;
16109
16169
  //cloneRowRender.rect.maxWidth = render.rect.height;
16110
16170
  const cellRenders = [...render.getItems()];
16111
16171
  const cutCellRenders = [];
16112
16172
  for (let i = 0; i < cellRenders.length; i++) {
16113
16173
  const cellRender = cellRenders[i];
16174
+ this.markMergeRowRenderDirty(cellRender);
16114
16175
  if (cellRender.rect.height > limitHeight) {
16115
- //限制的外框尺寸
16116
- const availHeight = limitHeight;
16117
16176
  //限制的内框尺寸
16118
- const limitCellHeight = ElementUtil.innerRectMaxHeight(cellRender, availHeight);
16177
+ const limitCellHeight = ElementUtil.innerRectMaxHeight(cellRender, limitHeight);
16119
16178
  const cutCellRender = this.cutRenderItem(cellRender, limitCellHeight);
16120
16179
  if (cutCellRender) {
16121
16180
  cutCellRenders.push(cutCellRender);
@@ -16139,7 +16198,10 @@ class ElementRenderCut {
16139
16198
  for (let i = 0; i < cutCellRenders.length; i++) {
16140
16199
  let cellRender = cutCellRenders[i];
16141
16200
  if (!cellRender) {
16142
- cellRender = cellRenders[i].element.createRenderObject({ options: this.options, renderCtx: this.renderContext });
16201
+ cellRender = cellRenders[i].element.createRenderObject({
16202
+ options: this.options,
16203
+ renderCtx: this.renderContext
16204
+ });
16143
16205
  cellRender.rect = ElementUtil.cloneRect(cellRenders[i].rect);
16144
16206
  ElementUtil.remeasure(cellRender);
16145
16207
  }
@@ -16149,6 +16211,33 @@ class ElementRenderCut {
16149
16211
  return cloneRowRender;
16150
16212
  }
16151
16213
  }
16214
+ /**
16215
+ * 标记合并单元格所在行需要重新计算
16216
+ * @param cellRender
16217
+ * @private
16218
+ */
16219
+ markMergeRowRenderDirty(cellRender) {
16220
+ const cellEle = cellRender.element;
16221
+ if (cellEle.props.vMerge !== 'restart') {
16222
+ return;
16223
+ }
16224
+ const rowRender = cellRender.parent;
16225
+ rowRender.element;
16226
+ const tb = rowRender.parent;
16227
+ const cellYPos = cellRender.rect.y;
16228
+ for (let i = rowRender.getIndex() + 1; i < tb.length; i++) {
16229
+ const nextRowRender = tb.getChild(i);
16230
+ if (nextRowRender.rect.y <= cellYPos) {
16231
+ nextRowRender.remeasureState = true;
16232
+ nextRowRender.getItems().forEach(item => {
16233
+ this.markMergeRowRenderDirty(item);
16234
+ });
16235
+ }
16236
+ else {
16237
+ break;
16238
+ }
16239
+ }
16240
+ }
16152
16241
  /**
16153
16242
  * 修复->已经截断的合并单元格要向下移动到合适的位置
16154
16243
  * @param tbRender
@@ -16272,7 +16361,7 @@ class ElementRenderCut {
16272
16361
  class DocumentPaint {
16273
16362
  renderContext;
16274
16363
  docCtx;
16275
- selectedSets;
16364
+ seo;
16276
16365
  elementMeasure;
16277
16366
  elementRenderCut;
16278
16367
  elementPaint;
@@ -16280,10 +16369,10 @@ class DocumentPaint {
16280
16369
  docContainer;
16281
16370
  //commsContainer!: CommsContainerRenderObject;
16282
16371
  viewOptions;
16283
- constructor(renderContext, docCtx, selectedSets) {
16372
+ constructor(renderContext, docCtx, seo) {
16284
16373
  this.renderContext = renderContext;
16285
16374
  this.docCtx = docCtx;
16286
- this.selectedSets = selectedSets;
16375
+ this.seo = seo;
16287
16376
  this.viewOptions = this.docCtx.viewOptions;
16288
16377
  this.elementMeasure = new ElementMeasure(this.docCtx, this.renderContext);
16289
16378
  this.elementRenderCut = new ElementRenderCut(this.viewOptions, this.renderContext);
@@ -16305,7 +16394,7 @@ class DocumentPaint {
16305
16394
  // //console.timeEnd('排版计时');
16306
16395
  // //console.time('断页计时');
16307
16396
  // const docPages = this.elementRenderCut.cutPage(documentRender, this.docCtx.document);
16308
- const newMeasure = new DocumentArrange(this.docCtx, this.renderContext);
16397
+ const newMeasure = new DocumentArrange(this.docCtx, this.renderContext, this.seo);
16309
16398
  const docPages = newMeasure.measureDoc();
16310
16399
  // this.commsContainer = newMeasure.commentsRender as CommsContainerRenderObject;
16311
16400
  // if (this.commsContainer) {
@@ -16402,7 +16491,7 @@ class DocumentPaint {
16402
16491
  }
16403
16492
  }
16404
16493
  refreshView() {
16405
- this.elementPaint.drawPages(this.docContainer, this.selectedSets);
16494
+ this.elementPaint.drawPages(this.docContainer, this.seo.selectionEleSets);
16406
16495
  }
16407
16496
  getDocPages() {
16408
16497
  return this.docPages;
@@ -16417,31 +16506,31 @@ class DocumentPaint {
16417
16506
  if (!this.viewOptions.showReviewWindow) {
16418
16507
  return;
16419
16508
  }
16420
- const cce = this.docCtx.document.commentsContainerElement;
16421
- const set = new Map();
16422
- const commentRangeStatus = [];
16423
- for (let i = 0; i < cce.length; i++) {
16424
- const commContent = cce.getChild(i);
16425
- const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
16426
- if (commMarkPair) {
16427
- if (commMarkPair.start) {
16428
- commContent.startMark = commMarkPair.start;
16429
- }
16430
- if (commMarkPair.end) {
16431
- commContent.endMark = commMarkPair.end;
16432
- }
16433
- }
16434
- const { startMark, endMark, props: { id }, focus } = commContent;
16435
- const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
16436
- const commonRange = RangeUtil.getSelctionRange(startMark, 0, endMark, 1, ancestorCommonControl);
16437
- SelectionOverlays.addToCommentSets(commonRange, set);
16438
- commentRangeStatus.push({
16439
- commContent,
16440
- range: commonRange
16441
- });
16442
- }
16443
- cce.cacheRender.selectedSet = set;
16444
- cce.cacheRender.commentRangeStatus = commentRangeStatus;
16509
+ // const cce = this.docCtx.document.commentsContainerElement;
16510
+ // const set = new Map<Element, SelectionContentRange>();
16511
+ // const commentRangeStatus: Array<CommentRangeStatus> = [];
16512
+ // for (let i = 0; i < cce.length; i++) {
16513
+ // const commContent = cce.getChild(i) as CommContentElement;
16514
+ // const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
16515
+ // if (commMarkPair) {
16516
+ // if (commMarkPair.start) {
16517
+ // commContent.startMark = commMarkPair.start;
16518
+ // }
16519
+ // if (commMarkPair.end) {
16520
+ // commContent.endMark = commMarkPair.end;
16521
+ // }
16522
+ // }
16523
+ // const {startMark, endMark, props: {id}, focus} = commContent;
16524
+ // const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
16525
+ // const commonRange = RangeUtil.getSectionRange(startMark, 0, endMark, 1, ancestorCommonControl);
16526
+ // SelectionOverlays.addToCommentSets(commonRange, set);
16527
+ // commentRangeStatus.push({
16528
+ // commContent,
16529
+ // range: commonRange
16530
+ // })
16531
+ // }
16532
+ // (<CommsContainerRenderObject>cce.cacheRender).selectedSet = set;
16533
+ // (<CommsContainerRenderObject>cce.cacheRender).commentRangeStatus = commentRangeStatus;
16445
16534
  }
16446
16535
  }
16447
16536
 
@@ -16641,15 +16730,15 @@ class ElementReader {
16641
16730
  document.bodyElement = document.find((item) => item instanceof DocumentBodyElement);
16642
16731
  document.headerElement = document.find((item) => item instanceof DocumentHeaderElement);
16643
16732
  document.footerElement = document.find((item) => item instanceof DocumentFooterElement);
16644
- document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement);
16645
- if (!document.commentsContainerElement) {
16646
- document.commentsContainerElement = new CommsContainerElement();
16647
- }
16733
+ // document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement) as CommsContainerElement;
16734
+ // if (!document.commentsContainerElement) {
16735
+ // document.commentsContainerElement = new CommsContainerElement();
16736
+ // }
16648
16737
  document.clearItems();
16649
16738
  document.addChild(document.headerElement);
16650
16739
  document.addChild(document.bodyElement);
16651
16740
  document.addChild(document.footerElement);
16652
- document.addChild(document.commentsContainerElement);
16741
+ //document.addChild(document.commentsContainerElement);
16653
16742
  this.docCtx.document = document;
16654
16743
  document.viewOptions = this.docCtx.viewOptions;
16655
16744
  const width = Math.floor(document.props.width * this.docCtx.viewOptions.mmToPixelsRatio);
@@ -16657,7 +16746,7 @@ class ElementReader {
16657
16746
  this.docCtx.viewOptions.docPageSettings = new PageOptions(width, height, document.props.orient);
16658
16747
  //this.viewOptions.viewSettings.width = this.viewOptions.docPageSettings.width + 10;
16659
16748
  }
16660
- readElement(data) {
16749
+ readElement(data, strictMode = false) {
16661
16750
  if (typeof data === 'string') {
16662
16751
  data = JSON.parse(data);
16663
16752
  }
@@ -16672,19 +16761,27 @@ class ElementReader {
16672
16761
  const children = data.children || [];
16673
16762
  for (const child of children) {
16674
16763
  //element.addChild(this.readElement(child));
16675
- childArr.push(this.readElement(child));
16764
+ const childEle = this.readElement(child);
16765
+ childEle && childArr.push(childEle);
16676
16766
  }
16677
16767
  }
16678
16768
  factory.readCompleted(element, childArr);
16679
16769
  return element;
16680
16770
  }
16681
16771
  }
16682
- throw new Error('未知的元素类型:' + type);
16772
+ if (strictMode) {
16773
+ throw new Error('未知的元素类型:' + type, data);
16774
+ }
16775
+ else {
16776
+ console.error('未知的元素类型:' + type, data);
16777
+ return null;
16778
+ }
16683
16779
  }
16684
- // propsReadFuncs: Map<string, (data: any) => any> = new Map();
16685
- // registerReadFunc<T>(propName: string, func: (data: T) => T): void {
16686
- // this.propsReadFuncs.set(propName, func);
16687
- // }
16780
+ /**
16781
+ * 读取扩展属性
16782
+ * @param data
16783
+ * @param element
16784
+ */
16688
16785
  readExtendsProps(data, element) {
16689
16786
  if (!data.props) {
16690
16787
  return;
@@ -19532,7 +19629,7 @@ class DocumentChange {
19532
19629
  return paragraph;
19533
19630
  }
19534
19631
  const last = ElementUtil.getLastLeafElement(paragraph);
19535
- const selectedParaRange = RangeUtil.getSelctionRange(startControl, startOffset, last, 1, paragraph);
19632
+ const selectedParaRange = RangeUtil.getSectionRange(startControl, startOffset, last, 1, paragraph);
19536
19633
  selectedParaRange.isFullSelected = false;
19537
19634
  const breakPara = ElementUtil.cloneRange(selectedParaRange, true);
19538
19635
  ElementUtil.fixParagraphContent(paragraph);
@@ -20154,22 +20251,26 @@ class DocumentChange {
20154
20251
  const id = nanoid.nanoid(5);
20155
20252
  const startCommMark = new CommentElement();
20156
20253
  startCommMark.props.id = id;
20254
+ startCommMark.props.userId = this.viewOptions.editUser.id;
20255
+ startCommMark.props.userName = this.viewOptions.editUser.name;
20256
+ startCommMark.props.date = CommonUtil.formatNow('YYYY-MM-DD HH:mm:ss');
20157
20257
  startCommMark.props.markType = 'start';
20158
20258
  const endCommMark = new CommentElement();
20159
20259
  endCommMark.props.id = id;
20160
20260
  endCommMark.props.markType = 'end';
20161
20261
  this.insertElement(endControl, endOffset, [endCommMark]);
20162
20262
  this.insertElement(startControl, startOffset, [startCommMark]);
20163
- const commContent = new CommContentElement();
20164
- commContent.props.id = id;
20165
- commContent.props.createId = this.viewOptions.editUser.id;
20166
- commContent.props.createName = this.viewOptions.editUser.name;
20167
- commContent.props.createDate = new Date();
20168
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20169
- if (pos < 0) {
20170
- throw new Error('获取插入的批注位置不正确');
20171
- }
20172
- this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
20263
+ startCommMark.props.text = '插入测试批注信息' + new Date();
20264
+ // const commContent = new CommContentElement();
20265
+ // commContent.props.id = id;
20266
+ // commContent.props.createId = this.viewOptions.editUser.id;
20267
+ // commContent.props.createName = this.viewOptions.editUser.name;
20268
+ // commContent.props.createDate = new Date();
20269
+ // const pos = this.docComment.getCommMarkIndex(startCommMark);
20270
+ // if (pos < 0) {
20271
+ // throw new Error('获取插入的批注位置不正确');
20272
+ // }
20273
+ // this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
20173
20274
  this.selectionState.clear();
20174
20275
  }
20175
20276
  validate() {
@@ -20193,8 +20294,8 @@ class DocumentChange {
20193
20294
  validateElement.props.title = caption + '验证';
20194
20295
  validateElement.props.id = id;
20195
20296
  validateElement.setContent(item.error);
20196
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20197
- this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
20297
+ this.docComment.getCommMarkIndex(startCommMark);
20298
+ //this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
20198
20299
  });
20199
20300
  this.docCtx.selectionState.clear();
20200
20301
  return false;
@@ -20620,7 +20721,6 @@ class DocumentComment {
20620
20721
  // }
20621
20722
  // this.commMarkList = commList;
20622
20723
  // this.commContentList = commContentList;
20623
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
20624
20724
  this.isDirty = false;
20625
20725
  }
20626
20726
  /**
@@ -20656,28 +20756,46 @@ class DocumentComment {
20656
20756
  if (!endRange) {
20657
20757
  return;
20658
20758
  }
20659
- const commPairs = [];
20660
- const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
20661
- for (let i = 0; i < markPairs.length; i++) {
20662
- const { start: startMark, end: endMark } = markPairs[i];
20663
- if (!startMark || !endMark) {
20664
- continue;
20665
- }
20666
- const commPair = {
20667
- startMark,
20668
- endMark,
20669
- startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
20670
- endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
20671
- };
20672
- commPairs.push(commPair);
20673
- }
20674
- for (let i = 0; i < commPairs.length; i++) {
20675
- const commPair = commPairs[i];
20676
- if (commPair.endMarkStatus) {
20677
- this.removeComment(commPair.endMark.props.id);
20759
+ const selectedComms = [];
20760
+ RangeUtil.recursionTraversalRangeHandler(selectedRange, (range) => {
20761
+ if (range.target instanceof CommentElement && range.isFullSelected) {
20762
+ selectedComms.push(range.target);
20678
20763
  }
20679
- else if (commPair.startMarkStatus) ;
20764
+ });
20765
+ if (selectedComms.length > 0) {
20766
+ const ids = selectedComms.map(item => item.props.id);
20767
+ const commList = this.docCtx.document.treeFilter(item => item.type === 'comm' && ids.indexOf(item.props.id) >= 0);
20768
+ commList.forEach(item => item.remove());
20769
+ return;
20680
20770
  }
20771
+ return;
20772
+ // const commPairs: Array<CommMarkSelectedStatus> = [];
20773
+ // const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
20774
+ // for (let i = 0; i < markPairs.length; i++) {
20775
+ // const {start: startMark, end: endMark} = markPairs[i];
20776
+ // if (!startMark || !endMark) {
20777
+ // continue;
20778
+ // }
20779
+ // const commPair: CommMarkSelectedStatus = {
20780
+ // startMark,
20781
+ // endMark,
20782
+ // startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
20783
+ // endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
20784
+ // };
20785
+ // commPairs.push(commPair)
20786
+ // }
20787
+ //
20788
+ // for (let i = 0; i < commPairs.length; i++) {
20789
+ // const commPair = commPairs[i];
20790
+ // if (commPair.endMarkStatus) {
20791
+ // this.removeComment(commPair.endMark.props.id);
20792
+ // } else if (commPair.startMarkStatus) {
20793
+ // // const newStartMark = new CommentElement();
20794
+ // // newStartMark.props.id = commPair.startMark.props.id;
20795
+ // // commPair.startMark.isDecorate = false;
20796
+ // // DocumentChange.insertElement(endRange.target, endRange.endOffset, [newStartMark]);
20797
+ // }
20798
+ // }
20681
20799
  }
20682
20800
  }
20683
20801
  /**
@@ -20685,7 +20803,7 @@ class DocumentComment {
20685
20803
  * @param id
20686
20804
  */
20687
20805
  removeComment(id) {
20688
- this.docCtx.document.commentsContainerElement.removeCommMark(id);
20806
+ this.docCtx.document.removeCommMark(id);
20689
20807
  }
20690
20808
  getCommMarkIndex(commMark) {
20691
20809
  const markType = commMark.props.markType;
@@ -20697,7 +20815,7 @@ class DocumentComment {
20697
20815
  * 清除所有批注
20698
20816
  */
20699
20817
  clearAllComments() {
20700
- this.docCtx.document.commentsContainerElement.clearAllComms();
20818
+ this.docCtx.document.clearAllComms();
20701
20819
  this.docCtx.selectionState.clear();
20702
20820
  }
20703
20821
  /**
@@ -21123,15 +21241,15 @@ class ElementTrackManage {
21123
21241
 
21124
21242
  class DocumentSvg {
21125
21243
  viewOptions;
21126
- selectedSets;
21244
+ sso;
21127
21245
  renderCtx;
21128
21246
  highlights = [];
21129
21247
  mode = "view";
21130
21248
  //当前页位置
21131
21249
  pagePos;
21132
- constructor(viewOptions, selectedSets, renderCtx) {
21250
+ constructor(viewOptions, sso, renderCtx) {
21133
21251
  this.viewOptions = viewOptions;
21134
- this.selectedSets = selectedSets;
21252
+ this.sso = sso;
21135
21253
  this.renderCtx = renderCtx;
21136
21254
  }
21137
21255
  getVNode(render, selectionRects, parentPos) {
@@ -21141,22 +21259,8 @@ class DocumentSvg {
21141
21259
  width: render.rect.width,
21142
21260
  height: render.rect.height
21143
21261
  };
21144
- if (this.selectedSets.has(render.element)) {
21145
- const range = this.selectedSets.get(render.element);
21146
- if (render.element && render instanceof LeafRenderObject) {
21147
- if (range.isFullSelected) {
21148
- selectionRects.push(currPos);
21149
- }
21150
- else {
21151
- if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
21152
- const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
21153
- const width = endX - startX;
21154
- const x = currPos.x + startX;
21155
- selectionRects.push({ x, y: currPos.y, width, height: currPos.height });
21156
- }
21157
- }
21158
- }
21159
- }
21262
+ //处理选区遮罩
21263
+ this.createSelectionRect(render, selectionRects, currPos);
21160
21264
  //审阅窗口重新计算位置
21161
21265
  if (this.viewOptions.showReviewWindow && render instanceof CommsContainerRenderObject) {
21162
21266
  CommentsUtil.arrangeComments(render);
@@ -21220,12 +21324,18 @@ class DocumentSvg {
21220
21324
  if (selectionRectsTemp.length > 0) {
21221
21325
  const startX = selectionRectsTemp[0].x;
21222
21326
  const endX = selectionRectsTemp[selectionRectsTemp.length - 1].x + selectionRectsTemp[selectionRectsTemp.length - 1].width;
21223
- selectionRects.push({ x: startX, y: currPos.y, width: endX - startX, height: currPos.height });
21327
+ selectionRects.push({
21328
+ x: startX,
21329
+ y: currPos.y,
21330
+ width: endX - startX,
21331
+ height: currPos.height,
21332
+ color: selectionRectsTemp[0].color
21333
+ });
21224
21334
  selectionRectsTemp.length = 0;
21225
21335
  }
21226
21336
  }
21227
21337
  else if (render instanceof TableCellRenderObject) {
21228
- if (this.selectedSets.has(render.element) && this.selectedSets.get(render.element)?.isFullSelected) {
21338
+ if (this.sso.selectionEleSets.has(render.element) && this.sso.selectionEleSets.get(render.element)?.isFullSelected) {
21229
21339
  selectionRects.push(currPos);
21230
21340
  selectionRectsTemp.length = 0;
21231
21341
  }
@@ -21267,11 +21377,39 @@ class DocumentSvg {
21267
21377
  }
21268
21378
  return currVNode;
21269
21379
  }
21380
+ createSelectionRect(render, selectionRects, currPos) {
21381
+ const items = [this.sso.selectionEleSets, this.sso.commRangeSets];
21382
+ for (const item of items) {
21383
+ if (item.has(render.element)) {
21384
+ const range = item.get(render.element);
21385
+ if (render.element && render instanceof LeafRenderObject) {
21386
+ if (range.isFullSelected) {
21387
+ selectionRects.push({ ...currPos, color: range['rangeColor'] });
21388
+ }
21389
+ else {
21390
+ if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
21391
+ const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
21392
+ const width = endX - startX;
21393
+ const x = currPos.x + startX;
21394
+ // @ts-ignore
21395
+ selectionRects.push({
21396
+ x,
21397
+ y: currPos.y,
21398
+ width,
21399
+ height: currPos.height,
21400
+ color: range['rangeColor']
21401
+ });
21402
+ }
21403
+ }
21404
+ }
21405
+ }
21406
+ }
21407
+ }
21270
21408
  getHTMLVNode(docRenders) {
21271
21409
  this.counterMap = {};
21272
- const pageNodes = docRenders.filter(item => this.checkInViewBox(item)).map(item => {
21410
+ return docRenders.filter(item => this.checkInViewBox(item)).map(item => {
21273
21411
  const pageSvg = this.getPageSvgVNode(item);
21274
- const pageUnit = {
21412
+ return {
21275
21413
  sel: 'div.page-unit',
21276
21414
  data: {
21277
21415
  style: {
@@ -21286,9 +21424,7 @@ class DocumentSvg {
21286
21424
  },
21287
21425
  children: [pageSvg]
21288
21426
  };
21289
- return pageUnit;
21290
21427
  });
21291
- return pageNodes;
21292
21428
  }
21293
21429
  /**
21294
21430
  * 判断当前元素是否在视窗内
@@ -21326,7 +21462,7 @@ class DocumentSvg {
21326
21462
  ns: 'http://www.w3.org/2000/svg',
21327
21463
  attrs: {
21328
21464
  stroke: 'none',
21329
- fill: 'rgb(85,165,255)',
21465
+ fill: item.color ?? 'rgb(85,165,255)',
21330
21466
  'paint-order': 'stroke fill markers',
21331
21467
  d: `M${item.x} ${item.y} L${item.x + item.width} ${item.y} L${item.x + item.width} ${item.y + item.height} L${item.x} ${item.y + item.height} Z`,
21332
21468
  'fill-opacity': '0.5'
@@ -26336,7 +26472,10 @@ class DocumentPrintOffscreenBase {
26336
26472
  const ss = new SelectionState();
26337
26473
  this.docCtx = new EditorContext(ss, this.viewOptions);
26338
26474
  this.renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
26339
- this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, new Map());
26475
+ this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, {
26476
+ selectionEleSets: new Map(),
26477
+ commRangeSets: new Map()
26478
+ });
26340
26479
  this.elementReader = new ElementReader(this.docCtx);
26341
26480
  this.docCtx.syncRefresh = () => {
26342
26481
  };
@@ -26351,8 +26490,8 @@ class DocumentPrintOffscreenBase {
26351
26490
  // const docProps = this.docCtx.document.props;
26352
26491
  // printNodes(canvasNodes, {...docProps});
26353
26492
  // }
26354
- async print(data, ranges = null) {
26355
- await this.prepare(data);
26493
+ print(data, ranges = null) {
26494
+ this.prepare(data);
26356
26495
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26357
26496
  if (!canvasNodes.length) {
26358
26497
  console.warn('无可打印页');
@@ -26367,7 +26506,7 @@ class DocumentPrintOffscreenBase {
26367
26506
  /**
26368
26507
  * 续打
26369
26508
  */
26370
- async printForContinuation(data, options) {
26509
+ printForContinuation(data, options) {
26371
26510
  this.afterRenderEvent.subscribe((event) => {
26372
26511
  const { index, renderCtx, docRender, pageSvgVNode } = event;
26373
26512
  if (index === options.startDocIndex && options.startY !== 0) {
@@ -26381,7 +26520,7 @@ class DocumentPrintOffscreenBase {
26381
26520
  pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
26382
26521
  }
26383
26522
  });
26384
- await this.prepare(data);
26523
+ this.prepare(data);
26385
26524
  const printRanges = new Array(this.documentPaint.docPages.length).fill(0).map((item, index) => index).filter(index => index >= options.startDocIndex);
26386
26525
  let svgNodes = this.getSvgNodes(this.documentPaint.docPages, printRanges);
26387
26526
  if (!svgNodes.length) {
@@ -26406,8 +26545,8 @@ class DocumentPrintOffscreenBase {
26406
26545
  // }
26407
26546
  // return canvasNodes.map(node => node.toDataURL());
26408
26547
  // }
26409
- async getPrintNodes(data, ranges = null) {
26410
- await this.prepare(data);
26548
+ getPrintNodes(data, ranges = null) {
26549
+ this.prepare(data);
26411
26550
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26412
26551
  return canvasNodes;
26413
26552
  }
@@ -26418,11 +26557,11 @@ class DocumentPrintOffscreenBase {
26418
26557
  * 读取数据,排版
26419
26558
  * @param data
26420
26559
  */
26421
- async prepare(data) {
26560
+ prepare(data) {
26422
26561
  //将doc的json格式数据读取转化为DocumentElement的树
26423
26562
  this.elementReader.read(data);
26424
26563
  this.documentPaint.rePages();
26425
- await Promise.all(this.docCtx.imageLoader.getLoadTasks());
26564
+ //await Promise.all(this.docCtx.imageLoader.getLoadTasks());
26426
26565
  const { scale, docPageSettings: { width, height } } = this.viewOptions;
26427
26566
  this.renderCtx.update({ scale, width, height });
26428
26567
  ElementUtil.setCanvasProps(this.renderCtx.mainContext.ctx.canvas, this.renderCtx.mainContext.ctx, {
@@ -26457,7 +26596,10 @@ class DocumentPrintOffscreenBase {
26457
26596
  // return canvasList;
26458
26597
  // }
26459
26598
  getSvgNodes(docRenders, printRanges = null) {
26460
- const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
26599
+ const docSvgHelper = new DocumentSvg(this.viewOptions, {
26600
+ selectionEleSets: new Map,
26601
+ commRangeSets: new Map()
26602
+ }, this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
26461
26603
  docSvgHelper.mode = 'print';
26462
26604
  const patch = init([
26463
26605
  modules.class,
@@ -26501,31 +26643,6 @@ class DocumentPrintOffscreen extends DocumentPrintOffscreenBase {
26501
26643
  }
26502
26644
  }
26503
26645
 
26504
- let activeEditorContext = null;
26505
- function setActiveEditorContext(ctx) {
26506
- activeEditorContext = ctx;
26507
- }
26508
- function createSignal(state) {
26509
- let _state = state;
26510
- const activeCtx = activeEditorContext;
26511
- const signal = {
26512
- get value() {
26513
- return _state;
26514
- },
26515
- set value(v) {
26516
- if (v === _state) {
26517
- return;
26518
- }
26519
- _state = v;
26520
- signal.onChange();
26521
- },
26522
- onChange: () => {
26523
- activeCtx?.onChange();
26524
- }
26525
- };
26526
- return signal;
26527
- }
26528
-
26529
26646
  /**
26530
26647
  * 渲染日历虚拟节点处理类
26531
26648
  */
@@ -27394,6 +27511,8 @@ class DocEditor {
27394
27511
  onDestroy = new Subject$1();
27395
27512
  beforeNodePatch = new Subject$1();
27396
27513
  afterNodePatch = new Subject$1();
27514
+ //自定义事件传递消息
27515
+ eventBus;
27397
27516
  editInput;
27398
27517
  scrollContainer;
27399
27518
  constructor(svgContainer) {
@@ -27424,13 +27543,14 @@ class DocEditor {
27424
27543
  this.renderContext.init({ width: 500, height: 500, scale: 1 });
27425
27544
  this.selectionState = this.documentSelection.selectionState;
27426
27545
  this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
27427
- this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays.selectedSets);
27546
+ this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays);
27428
27547
  this.documentInput = new DocumentInput(this.docCtx);
27429
27548
  this.docComment = new DocumentComment(this.docCtx);
27430
27549
  this.elementReader = new ElementReader(this.docCtx);
27431
27550
  this.documentChange = new DocumentChange(this.elementReader, this.docCtx, this.docComment, this.documentInput);
27432
27551
  this.documentEvent = new DocumentEvent(this.documentPaint, this.docCtx, this.documentInput);
27433
27552
  this.historyMange = new ElementTrackManage(this.docCtx, this.elementReader);
27553
+ this.eventBus = new EventBus();
27434
27554
  this.createPatch();
27435
27555
  this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
27436
27556
  this.hitInfoChanged(hitInfo);
@@ -27970,6 +28090,7 @@ class DocEditor {
27970
28090
  insertTable(rows, cols) {
27971
28091
  const tb = TableUtil.createTable(rows, cols, this.selectionState);
27972
28092
  this.documentChange.insertTable(tb);
28093
+ return tb;
27973
28094
  }
27974
28095
  /**
27975
28096
  * 插入软换行符
@@ -28014,6 +28135,7 @@ class DocEditor {
28014
28135
  this.docCtx.destroy();
28015
28136
  this.documentEvent.clearSubEvent();
28016
28137
  this.selectionState.destroy();
28138
+ this.eventBus.clear();
28017
28139
  this.destroyDOM();
28018
28140
  this.flushTask = null;
28019
28141
  Object.keys(this).forEach(key => {
@@ -28527,7 +28649,7 @@ class DocEditor {
28527
28649
  this.tipContainer = tipsContainer;
28528
28650
  docContent.data.style.height = this.documentPaint.getDocumentContainerHeight().height + 'px';
28529
28651
  const docRenders = this.documentPaint.docContainer.getItems();
28530
- const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays.selectedSets, this.renderContext);
28652
+ const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays, this.renderContext);
28531
28653
  const vNode = svgGenerator.getHTMLVNode(docRenders);
28532
28654
  const children = docContent.children;
28533
28655
  children.push(tipsContainer);
@@ -28834,7 +28956,7 @@ class DocEditor {
28834
28956
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28835
28957
  }
28836
28958
  version() {
28837
- return "2.1.17";
28959
+ return "2.1.19";
28838
28960
  }
28839
28961
  switchPageHeaderEditor() {
28840
28962
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -28844,6 +28966,9 @@ class DocEditor {
28844
28966
  const paraTexts = paras.map(item => ElementSerialize.serializeString(item, { all: false }));
28845
28967
  return paraTexts.join('\n');
28846
28968
  }
28969
+ emit(event, args) {
28970
+ this.eventBus.emit(event, args);
28971
+ }
28847
28972
  }
28848
28973
 
28849
28974
  /**
@@ -29115,8 +29240,6 @@ exports.DocumentFooterRenderObject = DocumentFooterRenderObject;
29115
29240
  exports.DocumentHeaderElement = DocumentHeaderElement;
29116
29241
  exports.DocumentHeaderFactory = DocumentHeaderFactory;
29117
29242
  exports.DocumentHeaderRenderObject = DocumentHeaderRenderObject;
29118
- exports.DocumentImagesBaseLoader = DocumentImagesBaseLoader;
29119
- exports.DocumentImagesLoader = DocumentImagesLoader;
29120
29243
  exports.DocumentInput = DocumentInput;
29121
29244
  exports.DocumentPaint = DocumentPaint;
29122
29245
  exports.DocumentPrintOffscreen = DocumentPrintOffscreen;
@@ -29134,6 +29257,7 @@ exports.ElementPaint = ElementPaint;
29134
29257
  exports.ElementReader = ElementReader;
29135
29258
  exports.ElementSerialize = ElementSerialize;
29136
29259
  exports.ElementUtil = ElementUtil;
29260
+ exports.EventBus = EventBus;
29137
29261
  exports.EventMap = EventMap;
29138
29262
  exports.EventSourceCore = EventSourceCore$1;
29139
29263
  exports.FillNullSpaceElement = FillNullSpaceElement;