@hailin-zheng/editor-core 2.1.18 → 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.
package/index.js CHANGED
@@ -553,6 +553,16 @@ class CommonUtil {
553
553
  }
554
554
  return str;
555
555
  }
556
+ //随机生成rgb颜色
557
+ static randomRgbColor(opacity = -1) {
558
+ let r = Math.floor(Math.random() * 256); //随机生成256以内r值
559
+ let g = Math.floor(Math.random() * 256); //随机生成256以内g值
560
+ let b = Math.floor(Math.random() * 256); //随机生成256以内b值
561
+ if (opacity === -1) {
562
+ return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
563
+ }
564
+ return `rgba(${r},${g},${b},${opacity})`; //返回rgba(r,g,b,a)格式颜色
565
+ }
556
566
  /**
557
567
  * 判断一个数值是否在另一个数值的增益区间中
558
568
  * @param val
@@ -1072,6 +1082,40 @@ class SubjectSubscription$1 extends Subscription$1 {
1072
1082
  function fromEvent(dom, type) {
1073
1083
  return new DOMEventSource(dom, type);
1074
1084
  }
1085
+ class EventBus {
1086
+ subs = new Map();
1087
+ on(event, handler) {
1088
+ let handlers = this.subs.get(event);
1089
+ if (!handlers) {
1090
+ handlers = [];
1091
+ this.subs.set(event, handlers);
1092
+ }
1093
+ const sub = new Subject$1();
1094
+ sub.subscribe(handler);
1095
+ handlers.push(sub);
1096
+ }
1097
+ off(event) {
1098
+ const subs = this.subs.get(event);
1099
+ if (subs) {
1100
+ subs.forEach(item => item.unsubscribe());
1101
+ }
1102
+ this.subs.delete(event);
1103
+ }
1104
+ emit(event, data) {
1105
+ const subs = this.subs.get(event);
1106
+ if (subs) {
1107
+ subs.forEach(item => item.next(data));
1108
+ }
1109
+ }
1110
+ clear() {
1111
+ this.subs.forEach((subs) => {
1112
+ subs.forEach((sub) => {
1113
+ sub.unsubscribe();
1114
+ });
1115
+ });
1116
+ this.subs.clear();
1117
+ }
1118
+ }
1075
1119
 
1076
1120
  class Rect {
1077
1121
  x = 0;
@@ -1676,17 +1720,7 @@ class ViewOptions {
1676
1720
  //两个页的间距
1677
1721
  docSpace = 0;
1678
1722
  //是否显示审阅窗口
1679
- _showReviewWindow = false;
1680
- get showReviewWindow() {
1681
- return this._showReviewWindow;
1682
- }
1683
- set showReviewWindow(value) {
1684
- if (value === this._showReviewWindow) {
1685
- return;
1686
- }
1687
- this._showReviewWindow = value;
1688
- // this.onChange.next();
1689
- }
1723
+ showReviewWindow = false;
1690
1724
  //审阅窗口宽度
1691
1725
  reviewWindowWidth = 200;
1692
1726
  //缩放
@@ -2371,32 +2405,47 @@ class CommContentProps extends INotifyPropertyChanged {
2371
2405
  createId;
2372
2406
  createName;
2373
2407
  createDate;
2408
+ text;
2374
2409
  clone(dest) {
2375
2410
  const clone = dest ?? new CommContentProps();
2376
2411
  super.cloneAttachedProperty(clone);
2377
2412
  clone.id = this.id;
2413
+ clone.text = this.text;
2378
2414
  return clone;
2379
2415
  }
2380
2416
  getSerializeProps(viewOptions) {
2381
2417
  return {
2382
- id: this.id
2418
+ id: this.id,
2419
+ text: this.text
2383
2420
  };
2384
2421
  }
2385
2422
  }
2386
2423
  class CommProps extends INotifyPropertyChanged {
2387
2424
  id;
2388
2425
  markType;
2426
+ text;
2427
+ userId;
2428
+ userName;
2429
+ date;
2389
2430
  clone(dest) {
2390
2431
  const clone = dest ?? new CommProps();
2391
2432
  super.cloneAttachedProperty(clone);
2392
2433
  clone.id = this.id;
2393
2434
  clone.markType = this.markType;
2435
+ clone.text = this.text;
2436
+ clone.userId = this.userId;
2437
+ clone.userName = this.userName;
2438
+ clone.date = this.date;
2394
2439
  return clone;
2395
2440
  }
2396
2441
  getSerializeProps(viewOptions) {
2397
2442
  return {
2398
2443
  id: this.id,
2399
- markType: this.markType
2444
+ markType: this.markType,
2445
+ text: this.text,
2446
+ userId: this.userId,
2447
+ userName: this.userName,
2448
+ date: this.date
2400
2449
  };
2401
2450
  }
2402
2451
  }
@@ -2724,63 +2773,6 @@ class CommsContainerElement extends BlockContainerElement {
2724
2773
  }
2725
2774
  return clone;
2726
2775
  }
2727
- markPairs = [];
2728
- /**
2729
- * 清除所有的批注标识组合
2730
- */
2731
- clearMarkItems() {
2732
- this.markPairs.length = 0;
2733
- }
2734
- identifyCommMark(markElement) {
2735
- const { id } = markElement.props;
2736
- let matchItem = this.markPairs.find(item => item.id === id);
2737
- if (!matchItem) {
2738
- matchItem = { id };
2739
- this.markPairs.push(matchItem);
2740
- }
2741
- matchItem[markElement.props.markType] = markElement;
2742
- }
2743
- /**
2744
- * 根据id,移除批注标记以及批注内容
2745
- * @param id
2746
- */
2747
- removeCommMark(id) {
2748
- const matchIndex = this.markPairs.findIndex(item => item.id === id);
2749
- if (matchIndex >= 0) {
2750
- const matchItem = this.markPairs[matchIndex];
2751
- matchItem.start?.remove();
2752
- matchItem.end?.remove();
2753
- this.markPairs.splice(matchIndex, 1);
2754
- }
2755
- const commContent = this.getCommContent(id);
2756
- if (commContent) {
2757
- commContent.remove();
2758
- }
2759
- }
2760
- /**
2761
- * 清除所有批注
2762
- */
2763
- clearAllComms() {
2764
- for (let i = 0; i < this.markPairs.length; i++) {
2765
- const { start, end } = this.markPairs[i];
2766
- if (start) {
2767
- start.remove();
2768
- }
2769
- if (end) {
2770
- end.remove();
2771
- }
2772
- }
2773
- this.clearItems();
2774
- }
2775
- getCommContent(id) {
2776
- for (let i = 0; i < this.length; i++) {
2777
- const commContent = this.getChild(i);
2778
- if (commContent.props.id === id) {
2779
- return commContent;
2780
- }
2781
- }
2782
- return null;
2783
- }
2784
2776
  }
2785
2777
  class CommsContainerRenderObject extends BlockContainerRenderObject {
2786
2778
  //批注内容是否已经重组,只要重新绘制的时候组合一次即可
@@ -3242,7 +3234,7 @@ class DocumentElement extends BlockContainerElement {
3242
3234
  bodyElement;
3243
3235
  headerElement;
3244
3236
  footerElement;
3245
- commentsContainerElement;
3237
+ //commentsContainerElement!: CommsContainerElement;
3246
3238
  headerEditState = false;
3247
3239
  constructor() {
3248
3240
  super('doc');
@@ -3320,6 +3312,49 @@ class DocumentElement extends BlockContainerElement {
3320
3312
  ss.clear();
3321
3313
  this.refreshView();
3322
3314
  }
3315
+ markPairs = [];
3316
+ /**
3317
+ * 清除所有的批注标识组合
3318
+ */
3319
+ clearMarkItems() {
3320
+ this.markPairs.length = 0;
3321
+ }
3322
+ identifyCommMark(markElement) {
3323
+ const { id } = markElement.props;
3324
+ let matchItem = this.markPairs.find(item => item.id === id);
3325
+ if (!matchItem) {
3326
+ matchItem = { id };
3327
+ this.markPairs.push(matchItem);
3328
+ }
3329
+ matchItem[markElement.props.markType] = markElement;
3330
+ }
3331
+ /**
3332
+ * 根据id,移除批注标记以及批注内容
3333
+ * @param id
3334
+ */
3335
+ removeCommMark(id) {
3336
+ const matchIndex = this.markPairs.findIndex(item => item.id === id);
3337
+ if (matchIndex >= 0) {
3338
+ const matchItem = this.markPairs[matchIndex];
3339
+ matchItem.start?.remove();
3340
+ matchItem.end?.remove();
3341
+ this.markPairs.splice(matchIndex, 1);
3342
+ }
3343
+ }
3344
+ /**
3345
+ * 清除所有批注
3346
+ */
3347
+ clearAllComms() {
3348
+ for (let i = 0; i < this.markPairs.length; i++) {
3349
+ const { start, end } = this.markPairs[i];
3350
+ if (start) {
3351
+ start.remove();
3352
+ }
3353
+ if (end) {
3354
+ end.remove();
3355
+ }
3356
+ }
3357
+ }
3323
3358
  }
3324
3359
  class DocumentRenderObject extends BlockContainerRenderObject {
3325
3360
  constructor(ele) {
@@ -4677,7 +4712,7 @@ class TableRowRenderObject extends MuiltBlockLineRenderObject {
4677
4712
  //被截断的行是否需要重新计算高度
4678
4713
  remeasureState = true;
4679
4714
  //当前行是否存在合并单元格
4680
- hasMergeCells = false;
4715
+ hasMergeCells = undefined;
4681
4716
  render(e) {
4682
4717
  }
4683
4718
  clone() {
@@ -5316,7 +5351,7 @@ class DocumentCursor {
5316
5351
  }
5317
5352
 
5318
5353
  class RangeUtil {
5319
- static getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5354
+ static getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl) {
5320
5355
  if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5321
5356
  const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5322
5357
  return this.getTableSelectionRange(startControl, startOffset, endControl, endOffset, tbElement);
@@ -5395,7 +5430,7 @@ class RangeUtil {
5395
5430
  });
5396
5431
  }
5397
5432
  else {
5398
- const cellRange = this.getSelctionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5433
+ const cellRange = this.getSectionRange(cellFirstLeafElement, 0, cellLastLeafElement, 1, cell);
5399
5434
  cellRanges.push(cellRange);
5400
5435
  }
5401
5436
  }
@@ -7234,12 +7269,42 @@ class CommentsUtil {
7234
7269
  }
7235
7270
  }
7236
7271
 
7272
+ let activeEditorContext = null;
7273
+ function setActiveEditorContext(ctx) {
7274
+ activeEditorContext = ctx;
7275
+ }
7276
+ function getActiveEditorContext() {
7277
+ return activeEditorContext;
7278
+ }
7279
+ function createSignal(state) {
7280
+ let _state = state;
7281
+ const activeCtx = activeEditorContext;
7282
+ const signal = {
7283
+ get value() {
7284
+ return _state;
7285
+ },
7286
+ set value(v) {
7287
+ if (v === _state) {
7288
+ return;
7289
+ }
7290
+ _state = v;
7291
+ signal.onChange();
7292
+ },
7293
+ onChange: () => {
7294
+ activeCtx?.onChange();
7295
+ }
7296
+ };
7297
+ return signal;
7298
+ }
7299
+
7237
7300
  class CommentElement extends LeafElement {
7301
+ color;
7238
7302
  constructor() {
7239
7303
  super('comm');
7240
7304
  this.isDecorate = true;
7241
7305
  this.disableClick = true;
7242
7306
  this.props = new CommProps();
7307
+ this.color = CommonUtil.randomRgbColor(0.5);
7243
7308
  }
7244
7309
  createRenderObject() {
7245
7310
  const render = new CommentRenderObject(this);
@@ -7292,6 +7357,7 @@ class CommentRenderObject extends LeafRenderObject {
7292
7357
  }
7293
7358
  }
7294
7359
  }];
7360
+ this.createCommentTips(event);
7295
7361
  return t;
7296
7362
  }
7297
7363
  clone() {
@@ -7299,6 +7365,90 @@ class CommentRenderObject extends LeafRenderObject {
7299
7365
  clone.rect = ElementUtil.cloneRect(this.rect);
7300
7366
  return clone;
7301
7367
  }
7368
+ createCommentTips(event) {
7369
+ if (this.element.props.markType === 'end') {
7370
+ return;
7371
+ }
7372
+ if (this.element.paintRenders.indexOf(this) !== 0) {
7373
+ return;
7374
+ }
7375
+ const appCtx = getActiveEditorContext();
7376
+ const opType = '批注:';
7377
+ const content = this.element.props.text;
7378
+ const left = 5;
7379
+ let sel = 'div.tg-container';
7380
+ const node = {
7381
+ sel,
7382
+ key: this.element.props.id,
7383
+ data: {
7384
+ style: {
7385
+ left: `${left}px`,
7386
+ top: `${event.globalPos.y}px`
7387
+ },
7388
+ on: {
7389
+ click: (e) => {
7390
+ e.stopPropagation();
7391
+ appCtx?.emit('comment-click', {
7392
+ ...this.element.props
7393
+ });
7394
+ //this.showCommentRange(appCtx!);
7395
+ },
7396
+ dblclick: (e) => {
7397
+ e.stopPropagation();
7398
+ appCtx?.emit('comment-dblclick', {
7399
+ ...this.element.props
7400
+ });
7401
+ }
7402
+ }
7403
+ },
7404
+ children: [{
7405
+ sel: 'div.header',
7406
+ data: {},
7407
+ children: [{
7408
+ sel: 'span.header-user',
7409
+ data: {},
7410
+ text: this.element.props.userName,
7411
+ }, {
7412
+ sel: 'span.header-date',
7413
+ data: {},
7414
+ text: this.element.props.date,
7415
+ }]
7416
+ }, {
7417
+ sel: 'div.content',
7418
+ data: {},
7419
+ text: opType + content
7420
+ }, {
7421
+ sel: 'div.bg',
7422
+ data: {
7423
+ style: {
7424
+ background: this.element.color
7425
+ }
7426
+ }
7427
+ }]
7428
+ };
7429
+ event.addChangeTips(node);
7430
+ // <div class="container">
7431
+ // <div class="header">
7432
+ // <span class="header-user">张三</span>
7433
+ // <span class="header-date">2023.1.21 16:06</span>
7434
+ // </div>
7435
+ // <div class="content">修改了字符串</div>
7436
+ // </div>
7437
+ }
7438
+ /**
7439
+ * 显示批注范围
7440
+ * @private
7441
+ */
7442
+ showCommentRange(appCtx) {
7443
+ const doc = ElementUtil.getParent(this.element, (item) => item.type === 'doc');
7444
+ const commPair = doc.treeFilter(item => item instanceof CommentElement && item.props.id === this.element.props.id);
7445
+ if (commPair.length === 2) {
7446
+ const range = new SelectionRange();
7447
+ range.setStart(commPair[0], 0);
7448
+ range.setEnd(commPair[1], 1);
7449
+ appCtx.selectionState.addRange(range);
7450
+ }
7451
+ }
7302
7452
  }
7303
7453
  class CommentFactory extends ElementFactory {
7304
7454
  match(type) {
@@ -7309,6 +7459,7 @@ class CommentFactory extends ElementFactory {
7309
7459
  const props = data.props;
7310
7460
  ele.props.id = props.id;
7311
7461
  ele.props.markType = props.markType;
7462
+ ele.props.text = props.text;
7312
7463
  return ele;
7313
7464
  }
7314
7465
  }
@@ -8872,18 +9023,6 @@ class DataElementImage extends DataElementLeaf {
8872
9023
  this.props.clone(clone.props);
8873
9024
  return clone;
8874
9025
  }
8875
- loadImage(ctx) {
8876
- if (this.status === 'no') {
8877
- this.status = 'loading';
8878
- const onCallback = (status) => {
8879
- this.status = status;
8880
- if (status === 'completed') {
8881
- this.refreshView();
8882
- }
8883
- };
8884
- ctx.imageLoader.loadImage(this.props.src, onCallback);
8885
- }
8886
- }
8887
9026
  destroy() {
8888
9027
  super.destroy();
8889
9028
  }
@@ -8899,38 +9038,6 @@ class DataElementImage extends DataElementLeaf {
8899
9038
  }
8900
9039
  class DataImageRenderObject extends ResizeLeafRenderObject {
8901
9040
  render(e) {
8902
- const { render, position, docCtx } = e;
8903
- const dataImgElement = this.element;
8904
- const picProps = dataImgElement.props;
8905
- if (dataImgElement.status === 'no') {
8906
- dataImgElement.loadImage(docCtx);
8907
- return;
8908
- }
8909
- if (dataImgElement.status === 'completed') {
8910
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
8911
- if (!imageSource) {
8912
- return;
8913
- }
8914
- if (picProps.border === 'all') {
8915
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
8916
- }
8917
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
8918
- }
8919
- if (render.drawMode === 'view') {
8920
- let { x, y } = position;
8921
- const { width, height } = this.rect;
8922
- const lineWidth = 5;
8923
- const paintColor = '#0050b3';
8924
- render.contentContext.strokeLines([{ x: x + lineWidth, y }, { x, y }, { x, y: y + height }, {
8925
- x: x + lineWidth,
8926
- y: y + height
8927
- }], 1, paintColor);
8928
- x = x + width;
8929
- render.contentContext.strokeLines([{ x: x - lineWidth, y }, { x, y }, { x, y: y + height }, {
8930
- x: x - lineWidth,
8931
- y: y + height
8932
- }], 1, paintColor);
8933
- }
8934
9041
  }
8935
9042
  clone() {
8936
9043
  const clone = new DataImageRenderObject(this.element);
@@ -9807,51 +9914,12 @@ class PictureElement extends LeafElement {
9807
9914
  this.props.clone(clone.props);
9808
9915
  return clone;
9809
9916
  }
9810
- loadImage(ctx) {
9811
- if (this.status === 'no') {
9812
- this.status = 'loading';
9813
- //this.imageSource = new Image();
9814
- //this.imageSource.src = this.props.src;
9815
- // const onload = (e: any) => {
9816
- // this.isLoad = 'completed';
9817
- // this.refreshView('appearance');
9818
- // };
9819
- // const onerror = (e: any) => {
9820
- // this.isLoad = 'error';
9821
- // console.error(e);
9822
- // };
9823
- const onCallback = (status) => {
9824
- this.status = status;
9825
- if (status === 'completed') {
9826
- this.refreshView();
9827
- }
9828
- };
9829
- ctx.imageLoader.loadImage(this.props.src, onCallback);
9830
- }
9831
- }
9832
9917
  destroy() {
9833
9918
  super.destroy();
9834
9919
  }
9835
9920
  }
9836
9921
  class PictureRenderObject extends ResizeLeafRenderObject {
9837
9922
  render(e) {
9838
- const { render, position, docCtx } = e;
9839
- const picElement = this.element;
9840
- const picProps = picElement.props;
9841
- if (picElement.status === 'no') {
9842
- picElement.loadImage(docCtx);
9843
- return;
9844
- }
9845
- if (picElement.status === 'completed') {
9846
- const imageSource = docCtx.imageLoader.getImage(picProps.src);
9847
- if (!imageSource) {
9848
- return;
9849
- }
9850
- if (picProps.border === 'all') {
9851
- render.contentContext.strokeRect(position.x, position.y, this.rect.width, this.rect.height, 'black');
9852
- }
9853
- render.contentContext.ctx.drawImage(imageSource, 0, 0, imageSource.naturalWidth, imageSource.naturalHeight, position.x + 2, position.y + 2, picProps.width, picProps.height);
9854
- }
9855
9923
  }
9856
9924
  clone() {
9857
9925
  const clone = new PictureRenderObject(this.element);
@@ -13268,29 +13336,29 @@ class ElementPaint {
13268
13336
  this.renderCtx.contentContext.fillRect(currPosition.x, currPosition.y, renderObject.rect.width, renderObject.rect.height, this.viewOptions.selectionOverlaysColor);
13269
13337
  }
13270
13338
  }
13271
- if (inViewPort && this.viewOptions.showReviewWindow && this.docCtx.document.commentsContainerElement.cacheRender.selectedSet.has(element)) {
13272
- if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13273
- const measureCommContainer = this.docCtx.document.commentsContainerElement.cacheRender;
13274
- const range = measureCommContainer.selectedSet.get(element);
13275
- if (range.isFullSelected) {
13276
- let commentRangePaintColor = '#ffd591';
13277
- for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13278
- const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13279
- if (commentRangeStatus.commContent.focus) {
13280
- if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13281
- commentRangePaintColor = '#fa8c16';
13282
- }
13283
- }
13284
- }
13285
- const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13286
- const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13287
- x: currPosition.x,
13288
- y: currPosition.y
13289
- });
13290
- this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13291
- }
13292
- }
13293
- }
13339
+ // if (inViewPort && this.viewOptions.showReviewWindow && (<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender).selectedSet.has(element)) {
13340
+ // if (renderObject instanceof LeafRenderObject || renderObject instanceof DataElementRenderObject) {
13341
+ // const measureCommContainer=<CommsContainerRenderObject>this.docCtx.document.commentsContainerElement.cacheRender;
13342
+ // const range = measureCommContainer.selectedSet.get(element) as SelectionContentRange;
13343
+ // if (range.isFullSelected) {
13344
+ // let commentRangePaintColor = '#ffd591';
13345
+ // for (let i = 0; i < measureCommContainer.commentRangeStatus.length; i++) {
13346
+ // const commentRangeStatus = measureCommContainer.commentRangeStatus[i];
13347
+ // if (commentRangeStatus.commContent.focus) {
13348
+ // if (RangeUtil.checkElementFullInRange(commentRangeStatus.range, element)) {
13349
+ // commentRangePaintColor = '#fa8c16';
13350
+ // }
13351
+ // }
13352
+ // }
13353
+ // const overlayRect = { x: currPosition.x, y: currPosition.y, width: rw, height: rh };
13354
+ // const paraLinePos = ElementUtil.getParaLinePos(renderObject, {
13355
+ // x: currPosition.x,
13356
+ // y: currPosition.y
13357
+ // });
13358
+ // this.renderCtx.overlaysContext.fillRect(overlayRect.x, paraLinePos.y, overlayRect.width, paraLinePos.height, commentRangePaintColor);
13359
+ // }
13360
+ // }
13361
+ // }
13294
13362
  }
13295
13363
  /**
13296
13364
  * 触发页面绘制结束事件
@@ -13309,149 +13377,30 @@ class ElementPaint {
13309
13377
  const { x: rx, y: ry } = renderObject.rect;
13310
13378
  const currPosition = { x: rx + parent.x, y: ry + parent.y };
13311
13379
  if (renderObject instanceof BranchRenderObject) {
13312
- const nextRenderFn = onceTask(() => {
13313
- for (let i = 0; i < renderObject.length; i++) {
13314
- const child = renderObject.getChild(i);
13315
- this.drawPage(renderCtx, docCtx, child, currPosition);
13316
- }
13317
- });
13318
- const renderData = {
13319
- position: currPosition,
13320
- nextRender: nextRenderFn,
13321
- render: renderCtx,
13322
- docCtx
13323
- };
13324
- renderObject.render(renderData);
13325
- nextRenderFn();
13326
- }
13327
- else if (renderObject instanceof LeafRenderObject) {
13328
- const renderData = {
13329
- position: currPosition,
13330
- nextRender: () => { },
13331
- render: renderCtx,
13332
- docCtx: docCtx
13333
- };
13334
- renderObject.render(renderData);
13335
- }
13336
- }
13337
- }
13338
-
13339
- /**
13340
- * 用于处理选区拖蓝
13341
- */
13342
- class SelectionOverlays {
13343
- selectionState;
13344
- selectionRange;
13345
- selectedSets = new Map();
13346
- constructor(selectionState) {
13347
- this.selectionState = selectionState;
13348
- }
13349
- getSelectionTreeData() {
13350
- let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
13351
- this.selectedSets.clear();
13352
- if (this.selectionRange) {
13353
- this.selectionRange.selectedChildren.length = 0;
13354
- }
13355
- this.selectionRange = null;
13356
- if (!startControl || !endControl || !ancestorCommonControl) {
13357
- //this.selectionRange?.selectedChildren.length=0;
13358
- this.selectionState.selectedRange = null;
13359
- return;
13360
- }
13361
- if (collapsed) {
13362
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13363
- this.selectionState.selectedRange = commonRange;
13364
- this.selectedSets.clear();
13365
- return;
13366
- }
13367
- const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
13368
- startControl = fixStartElement.element;
13369
- startOffset = fixStartElement.offset;
13370
- const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
13371
- endControl = fixEndElement.element;
13372
- endOffset = fixEndElement.offset;
13373
- const commonRange = RangeUtil.getSelctionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
13374
- //console.log(commonRange);
13375
- this.selectionRange = commonRange;
13376
- this.convertSelectRangeToSet();
13377
- this.selectionState.selectedRange = commonRange;
13378
- }
13379
- convertSelectRangeToSet() {
13380
- this.selectedSets.clear();
13381
- if (this.selectionRange) {
13382
- SelectionOverlays.addToSets(this.selectionRange, this.selectedSets);
13383
- }
13384
- }
13385
- static addToSets(range, set) {
13386
- set.set(range.target, range);
13387
- for (let i = 0; i < range.selectedChildren.length; i++) {
13388
- //单元格全部选中效果,单元格整个拖蓝即可
13389
- if (range.isFullSelected && range.target.type === 'tbc') {
13390
- continue;
13391
- }
13392
- this.addToSets(range.selectedChildren[i], set);
13393
- }
13394
- }
13395
- /**
13396
- * 添加到批注集合
13397
- * @param range
13398
- * @param set
13399
- */
13400
- static addToCommentSets(range, set) {
13401
- set.set(range.target, range);
13402
- for (let i = 0; i < range.selectedChildren.length; i++) {
13403
- this.addToCommentSets(range.selectedChildren[i], set);
13404
- }
13405
- }
13406
- /**
13407
- * 修正开始选区内容
13408
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13409
- */
13410
- fixStartSelectionElement(element, offset, ancestorCommonControl) {
13411
- if (!(ancestorCommonControl instanceof TableElement)) {
13412
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13413
- if (lookupParentCell) {
13414
- if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
13415
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13416
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13417
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13418
- const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
13419
- if (!rowFirstLeafElement) {
13420
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13421
- }
13422
- return {
13423
- element: rowFirstLeafElement,
13424
- offset: 0
13425
- };
13426
- }
13427
- }
13428
- }
13429
- return { element, offset };
13430
- }
13431
- /**
13432
- * 修正开始选区内容
13433
- * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
13434
- */
13435
- fixEndSelectionElement(element, offset, ancestorCommonControl) {
13436
- if (!(ancestorCommonControl instanceof TableElement)) {
13437
- const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
13438
- if (lookupParentCell) {
13439
- const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
13440
- const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
13441
- if (ancestorCommonControlIndex < lookupParentTbIndex) {
13442
- const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
13443
- if (!rowLastLeafElement) {
13444
- ElementUtil.getLastLeafElement(lookupParentCell.parent);
13445
- throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
13446
- }
13447
- return {
13448
- element: rowLastLeafElement,
13449
- offset: 1
13450
- };
13380
+ const nextRenderFn = onceTask(() => {
13381
+ for (let i = 0; i < renderObject.length; i++) {
13382
+ const child = renderObject.getChild(i);
13383
+ this.drawPage(renderCtx, docCtx, child, currPosition);
13451
13384
  }
13452
- }
13385
+ });
13386
+ const renderData = {
13387
+ position: currPosition,
13388
+ nextRender: nextRenderFn,
13389
+ render: renderCtx,
13390
+ docCtx
13391
+ };
13392
+ renderObject.render(renderData);
13393
+ nextRenderFn();
13394
+ }
13395
+ else if (renderObject instanceof LeafRenderObject) {
13396
+ const renderData = {
13397
+ position: currPosition,
13398
+ nextRender: () => { },
13399
+ render: renderCtx,
13400
+ docCtx: docCtx
13401
+ };
13402
+ renderObject.render(renderData);
13453
13403
  }
13454
- return { element, offset };
13455
13404
  }
13456
13405
  }
13457
13406
 
@@ -13503,78 +13452,6 @@ class DocumentEvalFunc {
13503
13452
  }
13504
13453
  }
13505
13454
 
13506
- class DocumentImagesBaseLoader {
13507
- images = [];
13508
- clear() {
13509
- this.images.length = 0;
13510
- }
13511
- loadImage(src, onCallback) {
13512
- if (!src) {
13513
- return;
13514
- }
13515
- //已经存在的资源不需要重新加载
13516
- let matchItem = this.images.find(item => item.src === src);
13517
- if (matchItem) {
13518
- if (matchItem.loadStatus === 'no') {
13519
- matchItem.cbs.push(onCallback);
13520
- }
13521
- else {
13522
- onCallback(matchItem.loadStatus);
13523
- }
13524
- return;
13525
- }
13526
- const task = this.createRequestImage(src);
13527
- const imgItem = {
13528
- ele: undefined,
13529
- src,
13530
- cbs: [onCallback],
13531
- loadStatus: 'no',
13532
- task
13533
- };
13534
- this.images.push(imgItem);
13535
- // if (this.viewOptions.resourceMode === 'immediate') {
13536
- // ele.onload = (e) => { this.invokeImgLoad(src, 'completed'); };
13537
- // ele.onerror = (e) => { this.invokeImgLoad(src, 'error'); };
13538
- // }
13539
- }
13540
- invokeImgLoad(src, status, data) {
13541
- const img = this.images.find(item => item.src === src);
13542
- if (img) {
13543
- img.loadStatus = status;
13544
- img.cbs.forEach(cb => cb(status));
13545
- img.ele = data;
13546
- }
13547
- }
13548
- getLoadTasks() {
13549
- return this.images.map(item => item.task);
13550
- }
13551
- getImage(src) {
13552
- const img = this.images.find(item => item.src === src);
13553
- return img?.ele;
13554
- }
13555
- /**
13556
- * 判断图片是否都已经加载完毕
13557
- * 用于打印时判断,如果当前图片没有加载完毕就打印,图片是打印不出来
13558
- * @returns
13559
- */
13560
- imagesLoadCompleted() {
13561
- if (this.images.length === 0) {
13562
- return true;
13563
- }
13564
- return this.images.every(item => ['completed', 'error'].includes(item.loadStatus));
13565
- }
13566
- }
13567
- class DocumentImagesLoader extends DocumentImagesBaseLoader {
13568
- createRequestImage(url) {
13569
- const ele = new Image();
13570
- ele.src = url;
13571
- return new Promise((r, i) => {
13572
- ele.onload = (e) => { this.invokeImgLoad(url, 'completed', ele); r(); };
13573
- ele.onerror = (e) => { this.invokeImgLoad(url, 'error', ele); r(); };
13574
- });
13575
- }
13576
- }
13577
-
13578
13455
  /**
13579
13456
  * 当前打开的文档的上下文信息,当前文档所有的属性设置都暴露在上下文中
13580
13457
  */
@@ -13587,7 +13464,7 @@ class EditorContext {
13587
13464
  //文档刷新的订阅事件
13588
13465
  //refSub!: Subscription;
13589
13466
  syncRefresh;
13590
- imageLoader;
13467
+ //imageLoader: IImageLoader;
13591
13468
  dynamicFunc;
13592
13469
  docChange;
13593
13470
  clearPrevDocCb;
@@ -13597,7 +13474,7 @@ class EditorContext {
13597
13474
  this.selectionState = selectionState;
13598
13475
  this.viewOptions = viewOptions;
13599
13476
  this.dynamicFunc = new DocumentEvalFunc(this);
13600
- this.imageLoader = new DocumentImagesLoader();
13477
+ //this.imageLoader = new DocumentImagesLoader();
13601
13478
  this.selectionState.onChangedEvent.subscribe(() => {
13602
13479
  this.syncRefresh?.();
13603
13480
  });
@@ -13638,7 +13515,7 @@ class EditorContext {
13638
13515
  }
13639
13516
  clear() {
13640
13517
  this.selectionState.clear();
13641
- this.imageLoader.clear();
13518
+ //this.imageLoader.clear();
13642
13519
  this.dynamicFunc.destroyScripts();
13643
13520
  this.isDirty = false;
13644
13521
  }
@@ -13680,7 +13557,7 @@ class EditorContext {
13680
13557
  this.document.destroy();
13681
13558
  this.clearPrevDocCb?.();
13682
13559
  //this.ele_types_handlers.length = 0;
13683
- this.imageLoader.clear();
13560
+ //this.imageLoader.clear();
13684
13561
  this._document = null;
13685
13562
  }
13686
13563
  /**
@@ -13715,6 +13592,17 @@ class EditorContext {
13715
13592
  return this._document.modifyFlag === ModifyFlag$1.None ? 'appearance' : 'content';
13716
13593
  }
13717
13594
  }
13595
+ // export interface IImageLoader {
13596
+ // clear(): void;
13597
+ //
13598
+ // loadImage(src: string, onCallback: (status: ImgLoadStatus) => void): void;
13599
+ //
13600
+ // getImage(src: string): HTMLImageElement | undefined;
13601
+ //
13602
+ // imagesLoadCompleted(): boolean;
13603
+ //
13604
+ // getLoadTasks(): Array<Promise<void>>;
13605
+ // }
13718
13606
  /**
13719
13607
  * 文档上下文
13720
13608
  */
@@ -14608,13 +14496,139 @@ class ParagraphMeasure {
14608
14496
  }
14609
14497
  }
14610
14498
 
14499
+ /**
14500
+ * 用于处理选区拖蓝
14501
+ */
14502
+ class SelectionOverlays {
14503
+ selectionState;
14504
+ selectionRange;
14505
+ //选区对象集合
14506
+ selectionEleSets = new Map();
14507
+ //批注对象集合
14508
+ commRangeSets = new Map();
14509
+ constructor(selectionState) {
14510
+ this.selectionState = selectionState;
14511
+ }
14512
+ getSelectionTreeData() {
14513
+ let { ancestorCommonControl, startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
14514
+ this.selectionEleSets.clear();
14515
+ if (this.selectionRange) {
14516
+ this.selectionRange.selectedChildren.length = 0;
14517
+ }
14518
+ this.selectionRange = null;
14519
+ if (!startControl || !endControl || !ancestorCommonControl) {
14520
+ //this.selectionRange?.selectedChildren.length=0;
14521
+ this.selectionState.selectedRange = null;
14522
+ return;
14523
+ }
14524
+ if (collapsed) {
14525
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14526
+ this.selectionState.selectedRange = commonRange;
14527
+ this.selectionEleSets.clear();
14528
+ return;
14529
+ }
14530
+ const fixStartElement = this.fixStartSelectionElement(startControl, startOffset, ancestorCommonControl);
14531
+ startControl = fixStartElement.element;
14532
+ startOffset = fixStartElement.offset;
14533
+ const fixEndElement = this.fixEndSelectionElement(endControl, endOffset, ancestorCommonControl);
14534
+ endControl = fixEndElement.element;
14535
+ endOffset = fixEndElement.offset;
14536
+ const commonRange = RangeUtil.getSectionRange(startControl, startOffset, endControl, endOffset, ancestorCommonControl);
14537
+ //console.log(commonRange);
14538
+ this.selectionRange = commonRange;
14539
+ this.convertSelectRangeToSet();
14540
+ this.selectionState.selectedRange = commonRange;
14541
+ }
14542
+ convertSelectRangeToSet() {
14543
+ this.selectionEleSets.clear();
14544
+ if (this.selectionRange) {
14545
+ SelectionOverlays.addToSets(this.selectionRange, this.selectionEleSets);
14546
+ }
14547
+ }
14548
+ static addToSets(range, set) {
14549
+ set.set(range.target, range);
14550
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14551
+ //单元格全部选中效果,单元格整个拖蓝即可
14552
+ if (range.isFullSelected && range.target.type === 'tbc') {
14553
+ continue;
14554
+ }
14555
+ this.addToSets(range.selectedChildren[i], set);
14556
+ }
14557
+ }
14558
+ /**
14559
+ * 添加到批注集合
14560
+ * @param range
14561
+ * @param set
14562
+ * @param rangeColor 用以显示批注区间的颜色
14563
+ */
14564
+ static addToCommentSets(range, set, rangeColor) {
14565
+ range['rangeColor'] = rangeColor;
14566
+ set.set(range.target, range);
14567
+ for (let i = 0; i < range.selectedChildren.length; i++) {
14568
+ this.addToCommentSets(range.selectedChildren[i], set, rangeColor);
14569
+ }
14570
+ }
14571
+ /**
14572
+ * 修正开始选区内容
14573
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14574
+ */
14575
+ fixStartSelectionElement(element, offset, ancestorCommonControl) {
14576
+ if (!(ancestorCommonControl instanceof TableElement)) {
14577
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14578
+ if (lookupParentCell) {
14579
+ if (!lookupParentCell.parent || !lookupParentCell.parent.parent) ;
14580
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14581
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14582
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14583
+ const rowFirstLeafElement = ElementUtil.getFirstLeafElement(lookupParentCell.parent);
14584
+ if (!rowFirstLeafElement) {
14585
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14586
+ }
14587
+ return {
14588
+ element: rowFirstLeafElement,
14589
+ offset: 0
14590
+ };
14591
+ }
14592
+ }
14593
+ }
14594
+ return { element, offset };
14595
+ }
14596
+ /**
14597
+ * 修正开始选区内容
14598
+ * 1.如果当前选区开始于表格内容,结束选区位于表格外,则需要开始选区内容重定位到单元格第一个元素
14599
+ */
14600
+ fixEndSelectionElement(element, offset, ancestorCommonControl) {
14601
+ if (!(ancestorCommonControl instanceof TableElement)) {
14602
+ const lookupParentCell = ElementUtil.getParentByType(element, TableCellElement);
14603
+ if (lookupParentCell) {
14604
+ const lookupParentTbIndex = ElementUtil.getControlIndex(lookupParentCell.parent.parent);
14605
+ const ancestorCommonControlIndex = ElementUtil.getControlIndex(ancestorCommonControl);
14606
+ if (ancestorCommonControlIndex < lookupParentTbIndex) {
14607
+ const rowLastLeafElement = ElementUtil.getLastLeafElement(lookupParentCell.parent);
14608
+ if (!rowLastLeafElement) {
14609
+ ElementUtil.getLastLeafElement(lookupParentCell.parent);
14610
+ throw new Error('当前元素处于表格内元素,未能定位到当前单元格首个元素');
14611
+ }
14612
+ return {
14613
+ element: rowLastLeafElement,
14614
+ offset: 1
14615
+ };
14616
+ }
14617
+ }
14618
+ }
14619
+ return { element, offset };
14620
+ }
14621
+ }
14622
+
14611
14623
  class DocumentArrange {
14612
14624
  docCtx;
14613
14625
  renderCtx;
14626
+ seo;
14614
14627
  options;
14615
- constructor(docCtx, renderCtx) {
14628
+ constructor(docCtx, renderCtx, seo) {
14616
14629
  this.docCtx = docCtx;
14617
14630
  this.renderCtx = renderCtx;
14631
+ this.seo = seo;
14618
14632
  this.options = this.docCtx.viewOptions;
14619
14633
  }
14620
14634
  /**
@@ -14636,24 +14650,25 @@ class DocumentArrange {
14636
14650
  parser: new DynamicContextParser(doc, this.docCtx.selectionState),
14637
14651
  createParaFn: () => this.createDefaultPara()
14638
14652
  };
14639
- doc.commentsContainerElement.clearMarkItems();
14653
+ doc.clearMarkItems();
14640
14654
  this.clearPaintCache(doc, data);
14641
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14655
+ //this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
14642
14656
  const docRenders = this.arrangeDoc();
14643
14657
  this.setMeasureCompletedModifyFlag(doc);
14644
14658
  this.cacheDocRenders(docRenders);
14659
+ this.generateCommRange();
14645
14660
  return docRenders;
14646
14661
  });
14647
14662
  }
14648
- commentsRender;
14663
+ //commentsRender!: CommsContainerRenderObject;
14649
14664
  arrangeDoc() {
14650
14665
  const doc = this.docCtx.document;
14651
14666
  const docRender = doc.createRenderObject();
14652
14667
  const innerRect = docRender.getInnerRect();
14653
14668
  const headerRender = this.measureControl(doc.headerElement, innerRect.width);
14654
14669
  const footerRender = this.measureControl(doc.footerElement, innerRect.width);
14655
- const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth);
14656
- this.commentsRender = commentsRender;
14670
+ //const commentsRender = this.measureControl(doc.commentsContainerElement, this.options.reviewWindowWidth) as CommsContainerRenderObject;
14671
+ //this.commentsRender = commentsRender;
14657
14672
  const { headerLine, footerLine } = docRender;
14658
14673
  let bodyMarginTop = headerLine + headerRender.rect.height + 6;
14659
14674
  let bodyMarginBottom = footerLine + footerRender.rect.height;
@@ -14748,15 +14763,15 @@ class DocumentArrange {
14748
14763
  cloneFooterRender.rect.x = limitRect.x;
14749
14764
  cloneFooterRender.rect.y = documentRender.rect.height - bodyMarginBottom;
14750
14765
  currColumn === 0 && documentRender.addChild(cloneFooterRender);
14751
- //审阅模式,添加审阅窗口
14752
- if (this.options.showReviewWindow && commentsRender) {
14753
- const commentsContainer = this.createRenderObject(commentsRender.element);
14754
- commentsContainer.padding.top = bodyMarginTop;
14755
- commentsContainer.rect.height = documentRender.rect.height;
14756
- documentRender.addChild(commentsContainer);
14757
- commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14758
- documentRender.rect.width += this.options.reviewWindowWidth;
14759
- }
14766
+ // //审阅模式,添加审阅窗口
14767
+ // if (this.options.showReviewWindow && commentsRender) {
14768
+ // const commentsContainer = this.createRenderObject(commentsRender.element) as CommsContainerRenderObject;
14769
+ // commentsContainer.padding.top = bodyMarginTop;
14770
+ // commentsContainer.rect.height = documentRender.rect.height;
14771
+ // documentRender.addChild(commentsContainer);
14772
+ // commentsContainer.rect.x = documentRender.rect.x + documentRender.rect.width;
14773
+ // documentRender.rect.width += this.options.reviewWindowWidth;
14774
+ // }
14760
14775
  currColumn++;
14761
14776
  if (currColumn === docColumns) {
14762
14777
  currColumn = 0;
@@ -14784,8 +14799,7 @@ class DocumentArrange {
14784
14799
  }
14785
14800
  if (element instanceof BlockContentElement) {
14786
14801
  const pRange = new ParagraphMeasure(this.options, this.renderCtx);
14787
- const innerLineRects = pRange.measureParagraph(element, maxWidth);
14788
- return innerLineRects;
14802
+ return pRange.measureParagraph(element, maxWidth);
14789
14803
  }
14790
14804
  else if (element instanceof BlockContainerElement) {
14791
14805
  const renders = [];
@@ -14923,7 +14937,6 @@ class DocumentArrange {
14923
14937
  * 切割渲染元素
14924
14938
  * @param tbRender 被切割的对象
14925
14939
  * @param limitHeight
14926
- * @param addFunc
14927
14940
  * @returns
14928
14941
  */
14929
14942
  cutTable(tbRender, limitHeight) {
@@ -14953,6 +14966,10 @@ class DocumentArrange {
14953
14966
  while (currRow) {
14954
14967
  const rowContentHeight = this.getBlockLineHeight(currRow);
14955
14968
  if (rowContentHeight + sumHeight > limitHeight) {
14969
+ //行存在最小高度,且当前行跨页的情况下,不截断该行
14970
+ if (currRow.element.props.minHeight) {
14971
+ break;
14972
+ }
14956
14973
  //限制的外框尺寸
14957
14974
  const availHeight = limitHeight - sumHeight;
14958
14975
  const limitRenderInnerHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
@@ -15193,7 +15210,7 @@ class DocumentArrange {
15193
15210
  }
15194
15211
  identifyComment(ele) {
15195
15212
  if (ele instanceof CommentElement) {
15196
- this.docCtx.document.commentsContainerElement.identifyCommMark(ele);
15213
+ this.docCtx.document.identifyCommMark(ele);
15197
15214
  }
15198
15215
  }
15199
15216
  cacheDoc;
@@ -15204,6 +15221,22 @@ class DocumentArrange {
15204
15221
  });
15205
15222
  this.cacheDoc = null;
15206
15223
  }
15224
+ /**
15225
+ * 生成批注区间信息
15226
+ * @param renderTree
15227
+ */
15228
+ generateCommRange() {
15229
+ this.seo.commRangeSets.clear();
15230
+ const commMarks = this.docCtx.document.markPairs;
15231
+ for (let i = 0; i < commMarks.length; i++) {
15232
+ const commMark = commMarks[i];
15233
+ if (commMark.start && commMark.end) {
15234
+ const ancestor = DocumentSelection.getAncestorCommonControl(commMark.start, commMark.end);
15235
+ const range = RangeUtil.getSectionRange(commMark.start, 0, commMark.end, 1, ancestor);
15236
+ SelectionOverlays.addToCommentSets(range, this.seo.commRangeSets, commMark.start.color);
15237
+ }
15238
+ }
15239
+ }
15207
15240
  cacheRenders(renderTree) {
15208
15241
  if (renderTree.element) {
15209
15242
  renderTree.element.paintRenders.push(renderTree);
@@ -16299,7 +16332,7 @@ class ElementRenderCut {
16299
16332
  class DocumentPaint {
16300
16333
  renderContext;
16301
16334
  docCtx;
16302
- selectedSets;
16335
+ seo;
16303
16336
  elementMeasure;
16304
16337
  elementRenderCut;
16305
16338
  elementPaint;
@@ -16307,10 +16340,10 @@ class DocumentPaint {
16307
16340
  docContainer;
16308
16341
  //commsContainer!: CommsContainerRenderObject;
16309
16342
  viewOptions;
16310
- constructor(renderContext, docCtx, selectedSets) {
16343
+ constructor(renderContext, docCtx, seo) {
16311
16344
  this.renderContext = renderContext;
16312
16345
  this.docCtx = docCtx;
16313
- this.selectedSets = selectedSets;
16346
+ this.seo = seo;
16314
16347
  this.viewOptions = this.docCtx.viewOptions;
16315
16348
  this.elementMeasure = new ElementMeasure(this.docCtx, this.renderContext);
16316
16349
  this.elementRenderCut = new ElementRenderCut(this.viewOptions, this.renderContext);
@@ -16332,7 +16365,7 @@ class DocumentPaint {
16332
16365
  // //console.timeEnd('排版计时');
16333
16366
  // //console.time('断页计时');
16334
16367
  // const docPages = this.elementRenderCut.cutPage(documentRender, this.docCtx.document);
16335
- const newMeasure = new DocumentArrange(this.docCtx, this.renderContext);
16368
+ const newMeasure = new DocumentArrange(this.docCtx, this.renderContext, this.seo);
16336
16369
  const docPages = newMeasure.measureDoc();
16337
16370
  // this.commsContainer = newMeasure.commentsRender as CommsContainerRenderObject;
16338
16371
  // if (this.commsContainer) {
@@ -16429,7 +16462,7 @@ class DocumentPaint {
16429
16462
  }
16430
16463
  }
16431
16464
  refreshView() {
16432
- this.elementPaint.drawPages(this.docContainer, this.selectedSets);
16465
+ this.elementPaint.drawPages(this.docContainer, this.seo.selectionEleSets);
16433
16466
  }
16434
16467
  getDocPages() {
16435
16468
  return this.docPages;
@@ -16444,31 +16477,31 @@ class DocumentPaint {
16444
16477
  if (!this.viewOptions.showReviewWindow) {
16445
16478
  return;
16446
16479
  }
16447
- const cce = this.docCtx.document.commentsContainerElement;
16448
- const set = new Map();
16449
- const commentRangeStatus = [];
16450
- for (let i = 0; i < cce.length; i++) {
16451
- const commContent = cce.getChild(i);
16452
- const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
16453
- if (commMarkPair) {
16454
- if (commMarkPair.start) {
16455
- commContent.startMark = commMarkPair.start;
16456
- }
16457
- if (commMarkPair.end) {
16458
- commContent.endMark = commMarkPair.end;
16459
- }
16460
- }
16461
- const { startMark, endMark, props: { id }, focus } = commContent;
16462
- const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
16463
- const commonRange = RangeUtil.getSelctionRange(startMark, 0, endMark, 1, ancestorCommonControl);
16464
- SelectionOverlays.addToCommentSets(commonRange, set);
16465
- commentRangeStatus.push({
16466
- commContent,
16467
- range: commonRange
16468
- });
16469
- }
16470
- cce.cacheRender.selectedSet = set;
16471
- cce.cacheRender.commentRangeStatus = commentRangeStatus;
16480
+ // const cce = this.docCtx.document.commentsContainerElement;
16481
+ // const set = new Map<Element, SelectionContentRange>();
16482
+ // const commentRangeStatus: Array<CommentRangeStatus> = [];
16483
+ // for (let i = 0; i < cce.length; i++) {
16484
+ // const commContent = cce.getChild(i) as CommContentElement;
16485
+ // const commMarkPair = cce.markPairs.find(item => item.id === commContent.props.id);
16486
+ // if (commMarkPair) {
16487
+ // if (commMarkPair.start) {
16488
+ // commContent.startMark = commMarkPair.start;
16489
+ // }
16490
+ // if (commMarkPair.end) {
16491
+ // commContent.endMark = commMarkPair.end;
16492
+ // }
16493
+ // }
16494
+ // const {startMark, endMark, props: {id}, focus} = commContent;
16495
+ // const ancestorCommonControl = DocumentSelection.getAncestorCommonControl(startMark, endMark);
16496
+ // const commonRange = RangeUtil.getSectionRange(startMark, 0, endMark, 1, ancestorCommonControl);
16497
+ // SelectionOverlays.addToCommentSets(commonRange, set);
16498
+ // commentRangeStatus.push({
16499
+ // commContent,
16500
+ // range: commonRange
16501
+ // })
16502
+ // }
16503
+ // (<CommsContainerRenderObject>cce.cacheRender).selectedSet = set;
16504
+ // (<CommsContainerRenderObject>cce.cacheRender).commentRangeStatus = commentRangeStatus;
16472
16505
  }
16473
16506
  }
16474
16507
 
@@ -16668,15 +16701,15 @@ class ElementReader {
16668
16701
  document.bodyElement = document.find((item) => item instanceof DocumentBodyElement);
16669
16702
  document.headerElement = document.find((item) => item instanceof DocumentHeaderElement);
16670
16703
  document.footerElement = document.find((item) => item instanceof DocumentFooterElement);
16671
- document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement);
16672
- if (!document.commentsContainerElement) {
16673
- document.commentsContainerElement = new CommsContainerElement();
16674
- }
16704
+ // document.commentsContainerElement = document.find((item) => item instanceof CommsContainerElement) as CommsContainerElement;
16705
+ // if (!document.commentsContainerElement) {
16706
+ // document.commentsContainerElement = new CommsContainerElement();
16707
+ // }
16675
16708
  document.clearItems();
16676
16709
  document.addChild(document.headerElement);
16677
16710
  document.addChild(document.bodyElement);
16678
16711
  document.addChild(document.footerElement);
16679
- document.addChild(document.commentsContainerElement);
16712
+ //document.addChild(document.commentsContainerElement);
16680
16713
  this.docCtx.document = document;
16681
16714
  document.viewOptions = this.docCtx.viewOptions;
16682
16715
  const width = Math.floor(document.props.width * this.docCtx.viewOptions.mmToPixelsRatio);
@@ -16684,7 +16717,7 @@ class ElementReader {
16684
16717
  this.docCtx.viewOptions.docPageSettings = new PageOptions(width, height, document.props.orient);
16685
16718
  //this.viewOptions.viewSettings.width = this.viewOptions.docPageSettings.width + 10;
16686
16719
  }
16687
- readElement(data) {
16720
+ readElement(data, strictMode = false) {
16688
16721
  if (typeof data === 'string') {
16689
16722
  data = JSON.parse(data);
16690
16723
  }
@@ -16699,19 +16732,27 @@ class ElementReader {
16699
16732
  const children = data.children || [];
16700
16733
  for (const child of children) {
16701
16734
  //element.addChild(this.readElement(child));
16702
- childArr.push(this.readElement(child));
16735
+ const childEle = this.readElement(child);
16736
+ childEle && childArr.push(childEle);
16703
16737
  }
16704
16738
  }
16705
16739
  factory.readCompleted(element, childArr);
16706
16740
  return element;
16707
16741
  }
16708
16742
  }
16709
- throw new Error('未知的元素类型:' + type);
16743
+ if (strictMode) {
16744
+ throw new Error('未知的元素类型:' + type, data);
16745
+ }
16746
+ else {
16747
+ console.error('未知的元素类型:' + type, data);
16748
+ return null;
16749
+ }
16710
16750
  }
16711
- // propsReadFuncs: Map<string, (data: any) => any> = new Map();
16712
- // registerReadFunc<T>(propName: string, func: (data: T) => T): void {
16713
- // this.propsReadFuncs.set(propName, func);
16714
- // }
16751
+ /**
16752
+ * 读取扩展属性
16753
+ * @param data
16754
+ * @param element
16755
+ */
16715
16756
  readExtendsProps(data, element) {
16716
16757
  if (!data.props) {
16717
16758
  return;
@@ -19559,7 +19600,7 @@ class DocumentChange {
19559
19600
  return paragraph;
19560
19601
  }
19561
19602
  const last = ElementUtil.getLastLeafElement(paragraph);
19562
- const selectedParaRange = RangeUtil.getSelctionRange(startControl, startOffset, last, 1, paragraph);
19603
+ const selectedParaRange = RangeUtil.getSectionRange(startControl, startOffset, last, 1, paragraph);
19563
19604
  selectedParaRange.isFullSelected = false;
19564
19605
  const breakPara = ElementUtil.cloneRange(selectedParaRange, true);
19565
19606
  ElementUtil.fixParagraphContent(paragraph);
@@ -20181,22 +20222,26 @@ class DocumentChange {
20181
20222
  const id = nanoid(5);
20182
20223
  const startCommMark = new CommentElement();
20183
20224
  startCommMark.props.id = id;
20225
+ startCommMark.props.userId = this.viewOptions.editUser.id;
20226
+ startCommMark.props.userName = this.viewOptions.editUser.name;
20227
+ startCommMark.props.date = CommonUtil.formatNow('YYYY-MM-DD HH:mm:ss');
20184
20228
  startCommMark.props.markType = 'start';
20185
20229
  const endCommMark = new CommentElement();
20186
20230
  endCommMark.props.id = id;
20187
20231
  endCommMark.props.markType = 'end';
20188
20232
  this.insertElement(endControl, endOffset, [endCommMark]);
20189
20233
  this.insertElement(startControl, startOffset, [startCommMark]);
20190
- const commContent = new CommContentElement();
20191
- commContent.props.id = id;
20192
- commContent.props.createId = this.viewOptions.editUser.id;
20193
- commContent.props.createName = this.viewOptions.editUser.name;
20194
- commContent.props.createDate = new Date();
20195
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20196
- if (pos < 0) {
20197
- throw new Error('获取插入的批注位置不正确');
20198
- }
20199
- this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
20234
+ startCommMark.props.text = '插入测试批注信息' + new Date();
20235
+ // const commContent = new CommContentElement();
20236
+ // commContent.props.id = id;
20237
+ // commContent.props.createId = this.viewOptions.editUser.id;
20238
+ // commContent.props.createName = this.viewOptions.editUser.name;
20239
+ // commContent.props.createDate = new Date();
20240
+ // const pos = this.docComment.getCommMarkIndex(startCommMark);
20241
+ // if (pos < 0) {
20242
+ // throw new Error('获取插入的批注位置不正确');
20243
+ // }
20244
+ // this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
20200
20245
  this.selectionState.clear();
20201
20246
  }
20202
20247
  validate() {
@@ -20220,8 +20265,8 @@ class DocumentChange {
20220
20265
  validateElement.props.title = caption + '验证';
20221
20266
  validateElement.props.id = id;
20222
20267
  validateElement.setContent(item.error);
20223
- const pos = this.docComment.getCommMarkIndex(startCommMark);
20224
- this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
20268
+ this.docComment.getCommMarkIndex(startCommMark);
20269
+ //this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
20225
20270
  });
20226
20271
  this.docCtx.selectionState.clear();
20227
20272
  return false;
@@ -20647,7 +20692,6 @@ class DocumentComment {
20647
20692
  // }
20648
20693
  // this.commMarkList = commList;
20649
20694
  // this.commContentList = commContentList;
20650
- this.docCtx.viewOptions.showReviewWindow = this.docCtx.document.commentsContainerElement.markPairs.length > 0;
20651
20695
  this.isDirty = false;
20652
20696
  }
20653
20697
  /**
@@ -20683,28 +20727,46 @@ class DocumentComment {
20683
20727
  if (!endRange) {
20684
20728
  return;
20685
20729
  }
20686
- const commPairs = [];
20687
- const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
20688
- for (let i = 0; i < markPairs.length; i++) {
20689
- const { start: startMark, end: endMark } = markPairs[i];
20690
- if (!startMark || !endMark) {
20691
- continue;
20692
- }
20693
- const commPair = {
20694
- startMark,
20695
- endMark,
20696
- startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
20697
- endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
20698
- };
20699
- commPairs.push(commPair);
20700
- }
20701
- for (let i = 0; i < commPairs.length; i++) {
20702
- const commPair = commPairs[i];
20703
- if (commPair.endMarkStatus) {
20704
- this.removeComment(commPair.endMark.props.id);
20730
+ const selectedComms = [];
20731
+ RangeUtil.recursionTraversalRangeHandler(selectedRange, (range) => {
20732
+ if (range.target instanceof CommentElement && range.isFullSelected) {
20733
+ selectedComms.push(range.target);
20705
20734
  }
20706
- else if (commPair.startMarkStatus) ;
20735
+ });
20736
+ if (selectedComms.length > 0) {
20737
+ const ids = selectedComms.map(item => item.props.id);
20738
+ const commList = this.docCtx.document.treeFilter(item => item.type === 'comm' && ids.indexOf(item.props.id) >= 0);
20739
+ commList.forEach(item => item.remove());
20740
+ return;
20707
20741
  }
20742
+ return;
20743
+ // const commPairs: Array<CommMarkSelectedStatus> = [];
20744
+ // const markPairs = this.docCtx.document.commentsContainerElement.markPairs;
20745
+ // for (let i = 0; i < markPairs.length; i++) {
20746
+ // const {start: startMark, end: endMark} = markPairs[i];
20747
+ // if (!startMark || !endMark) {
20748
+ // continue;
20749
+ // }
20750
+ // const commPair: CommMarkSelectedStatus = {
20751
+ // startMark,
20752
+ // endMark,
20753
+ // startMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, startMark),
20754
+ // endMarkStatus: RangeUtil.checkElementFullInRange(selectedRange, endMark),
20755
+ // };
20756
+ // commPairs.push(commPair)
20757
+ // }
20758
+ //
20759
+ // for (let i = 0; i < commPairs.length; i++) {
20760
+ // const commPair = commPairs[i];
20761
+ // if (commPair.endMarkStatus) {
20762
+ // this.removeComment(commPair.endMark.props.id);
20763
+ // } else if (commPair.startMarkStatus) {
20764
+ // // const newStartMark = new CommentElement();
20765
+ // // newStartMark.props.id = commPair.startMark.props.id;
20766
+ // // commPair.startMark.isDecorate = false;
20767
+ // // DocumentChange.insertElement(endRange.target, endRange.endOffset, [newStartMark]);
20768
+ // }
20769
+ // }
20708
20770
  }
20709
20771
  }
20710
20772
  /**
@@ -20712,7 +20774,7 @@ class DocumentComment {
20712
20774
  * @param id
20713
20775
  */
20714
20776
  removeComment(id) {
20715
- this.docCtx.document.commentsContainerElement.removeCommMark(id);
20777
+ this.docCtx.document.removeCommMark(id);
20716
20778
  }
20717
20779
  getCommMarkIndex(commMark) {
20718
20780
  const markType = commMark.props.markType;
@@ -20724,7 +20786,7 @@ class DocumentComment {
20724
20786
  * 清除所有批注
20725
20787
  */
20726
20788
  clearAllComments() {
20727
- this.docCtx.document.commentsContainerElement.clearAllComms();
20789
+ this.docCtx.document.clearAllComms();
20728
20790
  this.docCtx.selectionState.clear();
20729
20791
  }
20730
20792
  /**
@@ -21150,15 +21212,15 @@ class ElementTrackManage {
21150
21212
 
21151
21213
  class DocumentSvg {
21152
21214
  viewOptions;
21153
- selectedSets;
21215
+ sso;
21154
21216
  renderCtx;
21155
21217
  highlights = [];
21156
21218
  mode = "view";
21157
21219
  //当前页位置
21158
21220
  pagePos;
21159
- constructor(viewOptions, selectedSets, renderCtx) {
21221
+ constructor(viewOptions, sso, renderCtx) {
21160
21222
  this.viewOptions = viewOptions;
21161
- this.selectedSets = selectedSets;
21223
+ this.sso = sso;
21162
21224
  this.renderCtx = renderCtx;
21163
21225
  }
21164
21226
  getVNode(render, selectionRects, parentPos) {
@@ -21168,22 +21230,8 @@ class DocumentSvg {
21168
21230
  width: render.rect.width,
21169
21231
  height: render.rect.height
21170
21232
  };
21171
- if (this.selectedSets.has(render.element)) {
21172
- const range = this.selectedSets.get(render.element);
21173
- if (render.element && render instanceof LeafRenderObject) {
21174
- if (range.isFullSelected) {
21175
- selectionRects.push(currPos);
21176
- }
21177
- else {
21178
- if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
21179
- const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
21180
- const width = endX - startX;
21181
- const x = currPos.x + startX;
21182
- selectionRects.push({ x, y: currPos.y, width, height: currPos.height });
21183
- }
21184
- }
21185
- }
21186
- }
21233
+ //处理选区遮罩
21234
+ this.createSelectionRect(render, selectionRects, currPos);
21187
21235
  //审阅窗口重新计算位置
21188
21236
  if (this.viewOptions.showReviewWindow && render instanceof CommsContainerRenderObject) {
21189
21237
  CommentsUtil.arrangeComments(render);
@@ -21247,12 +21295,18 @@ class DocumentSvg {
21247
21295
  if (selectionRectsTemp.length > 0) {
21248
21296
  const startX = selectionRectsTemp[0].x;
21249
21297
  const endX = selectionRectsTemp[selectionRectsTemp.length - 1].x + selectionRectsTemp[selectionRectsTemp.length - 1].width;
21250
- selectionRects.push({ x: startX, y: currPos.y, width: endX - startX, height: currPos.height });
21298
+ selectionRects.push({
21299
+ x: startX,
21300
+ y: currPos.y,
21301
+ width: endX - startX,
21302
+ height: currPos.height,
21303
+ color: selectionRectsTemp[0].color
21304
+ });
21251
21305
  selectionRectsTemp.length = 0;
21252
21306
  }
21253
21307
  }
21254
21308
  else if (render instanceof TableCellRenderObject) {
21255
- if (this.selectedSets.has(render.element) && this.selectedSets.get(render.element)?.isFullSelected) {
21309
+ if (this.sso.selectionEleSets.has(render.element) && this.sso.selectionEleSets.get(render.element)?.isFullSelected) {
21256
21310
  selectionRects.push(currPos);
21257
21311
  selectionRectsTemp.length = 0;
21258
21312
  }
@@ -21294,11 +21348,39 @@ class DocumentSvg {
21294
21348
  }
21295
21349
  return currVNode;
21296
21350
  }
21351
+ createSelectionRect(render, selectionRects, currPos) {
21352
+ const items = [this.sso.selectionEleSets, this.sso.commRangeSets];
21353
+ for (const item of items) {
21354
+ if (item.has(render.element)) {
21355
+ const range = item.get(render.element);
21356
+ if (render.element && render instanceof LeafRenderObject) {
21357
+ if (range.isFullSelected) {
21358
+ selectionRects.push({ ...currPos, color: range['rangeColor'] });
21359
+ }
21360
+ else {
21361
+ if (render.element instanceof TextGroupElement && range.endOffset > range.startOffset) {
21362
+ const { startX, endX } = ElementUtil.getTextRenderHorX(render, range.startOffset, range.endOffset);
21363
+ const width = endX - startX;
21364
+ const x = currPos.x + startX;
21365
+ // @ts-ignore
21366
+ selectionRects.push({
21367
+ x,
21368
+ y: currPos.y,
21369
+ width,
21370
+ height: currPos.height,
21371
+ color: range['rangeColor']
21372
+ });
21373
+ }
21374
+ }
21375
+ }
21376
+ }
21377
+ }
21378
+ }
21297
21379
  getHTMLVNode(docRenders) {
21298
21380
  this.counterMap = {};
21299
- const pageNodes = docRenders.filter(item => this.checkInViewBox(item)).map(item => {
21381
+ return docRenders.filter(item => this.checkInViewBox(item)).map(item => {
21300
21382
  const pageSvg = this.getPageSvgVNode(item);
21301
- const pageUnit = {
21383
+ return {
21302
21384
  sel: 'div.page-unit',
21303
21385
  data: {
21304
21386
  style: {
@@ -21313,9 +21395,7 @@ class DocumentSvg {
21313
21395
  },
21314
21396
  children: [pageSvg]
21315
21397
  };
21316
- return pageUnit;
21317
21398
  });
21318
- return pageNodes;
21319
21399
  }
21320
21400
  /**
21321
21401
  * 判断当前元素是否在视窗内
@@ -21353,7 +21433,7 @@ class DocumentSvg {
21353
21433
  ns: 'http://www.w3.org/2000/svg',
21354
21434
  attrs: {
21355
21435
  stroke: 'none',
21356
- fill: 'rgb(85,165,255)',
21436
+ fill: item.color ?? 'rgb(85,165,255)',
21357
21437
  'paint-order': 'stroke fill markers',
21358
21438
  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`,
21359
21439
  'fill-opacity': '0.5'
@@ -26363,7 +26443,10 @@ class DocumentPrintOffscreenBase {
26363
26443
  const ss = new SelectionState();
26364
26444
  this.docCtx = new EditorContext(ss, this.viewOptions);
26365
26445
  this.renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
26366
- this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, new Map());
26446
+ this.documentPaint = new DocumentPaint(this.renderCtx, this.docCtx, {
26447
+ selectionEleSets: new Map(),
26448
+ commRangeSets: new Map()
26449
+ });
26367
26450
  this.elementReader = new ElementReader(this.docCtx);
26368
26451
  this.docCtx.syncRefresh = () => {
26369
26452
  };
@@ -26378,8 +26461,8 @@ class DocumentPrintOffscreenBase {
26378
26461
  // const docProps = this.docCtx.document.props;
26379
26462
  // printNodes(canvasNodes, {...docProps});
26380
26463
  // }
26381
- async print(data, ranges = null) {
26382
- await this.prepare(data);
26464
+ print(data, ranges = null) {
26465
+ this.prepare(data);
26383
26466
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26384
26467
  if (!canvasNodes.length) {
26385
26468
  console.warn('无可打印页');
@@ -26394,7 +26477,7 @@ class DocumentPrintOffscreenBase {
26394
26477
  /**
26395
26478
  * 续打
26396
26479
  */
26397
- async printForContinuation(data, options) {
26480
+ printForContinuation(data, options) {
26398
26481
  this.afterRenderEvent.subscribe((event) => {
26399
26482
  const { index, renderCtx, docRender, pageSvgVNode } = event;
26400
26483
  if (index === options.startDocIndex && options.startY !== 0) {
@@ -26408,7 +26491,7 @@ class DocumentPrintOffscreenBase {
26408
26491
  pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
26409
26492
  }
26410
26493
  });
26411
- await this.prepare(data);
26494
+ this.prepare(data);
26412
26495
  const printRanges = new Array(this.documentPaint.docPages.length).fill(0).map((item, index) => index).filter(index => index >= options.startDocIndex);
26413
26496
  let svgNodes = this.getSvgNodes(this.documentPaint.docPages, printRanges);
26414
26497
  if (!svgNodes.length) {
@@ -26433,8 +26516,8 @@ class DocumentPrintOffscreenBase {
26433
26516
  // }
26434
26517
  // return canvasNodes.map(node => node.toDataURL());
26435
26518
  // }
26436
- async getPrintNodes(data, ranges = null) {
26437
- await this.prepare(data);
26519
+ getPrintNodes(data, ranges = null) {
26520
+ this.prepare(data);
26438
26521
  const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
26439
26522
  return canvasNodes;
26440
26523
  }
@@ -26445,11 +26528,11 @@ class DocumentPrintOffscreenBase {
26445
26528
  * 读取数据,排版
26446
26529
  * @param data
26447
26530
  */
26448
- async prepare(data) {
26531
+ prepare(data) {
26449
26532
  //将doc的json格式数据读取转化为DocumentElement的树
26450
26533
  this.elementReader.read(data);
26451
26534
  this.documentPaint.rePages();
26452
- await Promise.all(this.docCtx.imageLoader.getLoadTasks());
26535
+ //await Promise.all(this.docCtx.imageLoader.getLoadTasks());
26453
26536
  const { scale, docPageSettings: { width, height } } = this.viewOptions;
26454
26537
  this.renderCtx.update({ scale, width, height });
26455
26538
  ElementUtil.setCanvasProps(this.renderCtx.mainContext.ctx.canvas, this.renderCtx.mainContext.ctx, {
@@ -26484,7 +26567,10 @@ class DocumentPrintOffscreenBase {
26484
26567
  // return canvasList;
26485
26568
  // }
26486
26569
  getSvgNodes(docRenders, printRanges = null) {
26487
- const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
26570
+ const docSvgHelper = new DocumentSvg(this.viewOptions, {
26571
+ selectionEleSets: new Map,
26572
+ commRangeSets: new Map()
26573
+ }, this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
26488
26574
  docSvgHelper.mode = 'print';
26489
26575
  const patch = init([
26490
26576
  modules.class,
@@ -26528,31 +26614,6 @@ class DocumentPrintOffscreen extends DocumentPrintOffscreenBase {
26528
26614
  }
26529
26615
  }
26530
26616
 
26531
- let activeEditorContext = null;
26532
- function setActiveEditorContext(ctx) {
26533
- activeEditorContext = ctx;
26534
- }
26535
- function createSignal(state) {
26536
- let _state = state;
26537
- const activeCtx = activeEditorContext;
26538
- const signal = {
26539
- get value() {
26540
- return _state;
26541
- },
26542
- set value(v) {
26543
- if (v === _state) {
26544
- return;
26545
- }
26546
- _state = v;
26547
- signal.onChange();
26548
- },
26549
- onChange: () => {
26550
- activeCtx?.onChange();
26551
- }
26552
- };
26553
- return signal;
26554
- }
26555
-
26556
26617
  /**
26557
26618
  * 渲染日历虚拟节点处理类
26558
26619
  */
@@ -27421,6 +27482,8 @@ class DocEditor {
27421
27482
  onDestroy = new Subject$1();
27422
27483
  beforeNodePatch = new Subject$1();
27423
27484
  afterNodePatch = new Subject$1();
27485
+ //自定义事件传递消息
27486
+ eventBus;
27424
27487
  editInput;
27425
27488
  scrollContainer;
27426
27489
  constructor(svgContainer) {
@@ -27451,13 +27514,14 @@ class DocEditor {
27451
27514
  this.renderContext.init({ width: 500, height: 500, scale: 1 });
27452
27515
  this.selectionState = this.documentSelection.selectionState;
27453
27516
  this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
27454
- this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays.selectedSets);
27517
+ this.documentPaint = new DocumentPaint(this.renderContext, this.docCtx, this.selectionOverlays);
27455
27518
  this.documentInput = new DocumentInput(this.docCtx);
27456
27519
  this.docComment = new DocumentComment(this.docCtx);
27457
27520
  this.elementReader = new ElementReader(this.docCtx);
27458
27521
  this.documentChange = new DocumentChange(this.elementReader, this.docCtx, this.docComment, this.documentInput);
27459
27522
  this.documentEvent = new DocumentEvent(this.documentPaint, this.docCtx, this.documentInput);
27460
27523
  this.historyMange = new ElementTrackManage(this.docCtx, this.elementReader);
27524
+ this.eventBus = new EventBus();
27461
27525
  this.createPatch();
27462
27526
  this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
27463
27527
  this.hitInfoChanged(hitInfo);
@@ -28042,6 +28106,7 @@ class DocEditor {
28042
28106
  this.docCtx.destroy();
28043
28107
  this.documentEvent.clearSubEvent();
28044
28108
  this.selectionState.destroy();
28109
+ this.eventBus.clear();
28045
28110
  this.destroyDOM();
28046
28111
  this.flushTask = null;
28047
28112
  Object.keys(this).forEach(key => {
@@ -28555,7 +28620,7 @@ class DocEditor {
28555
28620
  this.tipContainer = tipsContainer;
28556
28621
  docContent.data.style.height = this.documentPaint.getDocumentContainerHeight().height + 'px';
28557
28622
  const docRenders = this.documentPaint.docContainer.getItems();
28558
- const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays.selectedSets, this.renderContext);
28623
+ const svgGenerator = new DocumentSvg(this.viewOptions, this.selectionOverlays, this.renderContext);
28559
28624
  const vNode = svgGenerator.getHTMLVNode(docRenders);
28560
28625
  const children = docContent.children;
28561
28626
  children.push(tipsContainer);
@@ -28862,7 +28927,7 @@ class DocEditor {
28862
28927
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28863
28928
  }
28864
28929
  version() {
28865
- return "2.1.18";
28930
+ return "2.1.19";
28866
28931
  }
28867
28932
  switchPageHeaderEditor() {
28868
28933
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -28872,6 +28937,9 @@ class DocEditor {
28872
28937
  const paraTexts = paras.map(item => ElementSerialize.serializeString(item, { all: false }));
28873
28938
  return paraTexts.join('\n');
28874
28939
  }
28940
+ emit(event, args) {
28941
+ this.eventBus.emit(event, args);
28942
+ }
28875
28943
  }
28876
28944
 
28877
28945
  /**
@@ -29043,5 +29111,5 @@ function removeDuplicatesEvent(events) {
29043
29111
  return arr;
29044
29112
  }
29045
29113
 
29046
- export { BlockContainerElement, BlockContainerRenderObject, BlockContentElement, BlockContentRenderObject, BlockLineRectRenderObject, BodyPartProps, BooleanEnum, BorderProps, BranchElement, BranchRenderObject, BreakElement, BreakFactory, BreakRenderObject, CheckBoxElement, CheckBoxFactory, CheckBoxProps, CheckBoxRenderObject, ColumnPatchUtil, CommContentBaseElement, CommContentBaseRenderObject, CommContentElement, CommContentProps, CommContentRenderObject, CommProps, CommentContentFactory, CommentElement, CommentFactory, CommentRenderObject, CommentsFactory, CommentsUtil, CommonUtil, CommsContainerElement, CommsContainerRenderObject, ContentMenuItem, ContextMenuElementEvent, CopyElementEvent, DOMEventSource, DOMSubscription, DataDecorateElement, DataDecorateProps, DataDecorateRenderObject, DataEleBaseProps, DataEleBaseTextProps, DataEleCheckProps, DataEleDateProps, DataEleImageProps, DataEleListProps, DataEleMHProps, DataElementBarcode, DataElementBarcodeFactory, DataElementBarcodeProps, DataElementBarcodeRenderObject, DataElementBaseFactory, DataElementCheck, DataElementCheckFactory, DataElementCheckRenderObject, DataElementDate, DataElementDateFactory, DataElementDateRenderObject, DataElementGroupElement, DataElementGroupFactory, DataElementGroupProps, DataElementGroupRenderObject, DataElementImage, DataElementImgFactory, DataElementInlineGroup, DataElementLeaf, DataElementList, DataElementListFactory, DataElementListRenderObject, DataElementMH, DataElementMHFactory, DataElementRenderObject, DataElementText, DataElementTextFactory, DataElementTextRenderObject, DataImageRenderObject, DataRenderMH, DocEditor, DocMode, DocumentBodyElement, DocumentBodyFactory, DocumentBodyPartElement, DocumentBodyPartFactory, DocumentBodyPartRenderObject, DocumentBodyRenderObject, DocumentChange, DocumentCombine, DocumentComment, DocumentContainerRender, DocumentContext, DocumentCursor, DocumentElement, DocumentEvalFunc, DocumentEvent, DocumentFactory, DocumentFooterElement, DocumentFooterFactory, DocumentFooterRenderObject, DocumentHeaderElement, DocumentHeaderFactory, DocumentHeaderRenderObject, DocumentImagesBaseLoader, DocumentImagesLoader, DocumentInput, DocumentPaint, DocumentPrintOffscreen, DocumentPrintOffscreenBase, DocumentProps, DocumentRenderObject, DocumentSelection, DocumentTemplate, DropElementEvent, EditMode, EditorContext, Element, ElementEvent, ElementFactory, ElementPaint, ElementReader, ElementSerialize, ElementUtil, EventMap, EventSourceCore$1 as EventSourceCore, FillNullSpaceElement, FillNullSpaceRenderObject, GetTrackTipsEvent, GotCursorEvent, IDispose, INotifyPropertyChanged, InlineBlockContainer, InlineGroupElement, InlineGroupInputElement, InlineGroupRenderObject, InlineMuiltBlockLineRenderObject, InputElementEvent, IsInSideDataElement, IsInSideInlineGroupInputElement, KeyboradElementEvent, LeafElement, LeafRenderObject, LostCursorEvent, MarginProps, ModifyFlag$1 as ModifyFlag, MouseElementEvent, MousedownElementEvent, MuiltBlockLineRenderObject, OnceSubject, PSymbolElement, PSymbolRenderObject, PaddingProps, PageBreakElement, PageBreakFactory, PageBreakRenderObject, PageOptions, PaintContent, ParagraphElement, ParagraphFactory, ParagraphLineRectRenderObject, ParagraphNumberType, ParagraphProps, ParagraphRenderObject, PasteElementEvent, PictureElement, PictureFactory, PictureProps, PictureRenderObject, RadioBoxElement, RadioBoxFactory, RadioBoxProps, RadioBoxRenderObject, RangeUtil, Rect, RenderContext, RenderObject, RenderObjectType, ResizeLeafRenderObject, RunElementFactory, SelectionOverlays, SelectionRange, SelectionState, Subject$1 as Subject, SubjectSubscription$1 as SubjectSubscription, Subscription$1 as Subscription, TabElement, TabFactory, TabRenderObject, TableCellElement, TableCellFactory, TableCellProps, TableCellRenderObject, TableElement, TableFactory, TableProps, TableRenderObject, TableRowElement, TableRowFactory, TableRowProps, TableRowRenderObject, TableSplitCell, TableUtil, TextGroupElement, TextGroupFactory, TextGroupRenderObject, TextProps, TrackRunElement, TrackRunProps, TrackRunRenderObject, TrackRunTypeEnum, ValidateCondition, ValidateElement, ValidateProps, ValidateRenderObject, ViewOptions, clearChildrenRenderCache, clearTraces, createPrintTemplate, defaultParaHanging, deleteCurrentParagraph, docOpsMap, documentPrint, drawDecorator, elementTypeEventHandler, exportDecoratorHTML, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getFocusTextSegment, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, printNodes, reactiveMap, removeEle, removeText, runTextLineRender, setChildrenModifyFlag, setDataElementProps, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateInlineInputRenderObj, watchChanged };
29114
+ export { BlockContainerElement, BlockContainerRenderObject, BlockContentElement, BlockContentRenderObject, BlockLineRectRenderObject, BodyPartProps, BooleanEnum, BorderProps, BranchElement, BranchRenderObject, BreakElement, BreakFactory, BreakRenderObject, CheckBoxElement, CheckBoxFactory, CheckBoxProps, CheckBoxRenderObject, ColumnPatchUtil, CommContentBaseElement, CommContentBaseRenderObject, CommContentElement, CommContentProps, CommContentRenderObject, CommProps, CommentContentFactory, CommentElement, CommentFactory, CommentRenderObject, CommentsFactory, CommentsUtil, CommonUtil, CommsContainerElement, CommsContainerRenderObject, ContentMenuItem, ContextMenuElementEvent, CopyElementEvent, DOMEventSource, DOMSubscription, DataDecorateElement, DataDecorateProps, DataDecorateRenderObject, DataEleBaseProps, DataEleBaseTextProps, DataEleCheckProps, DataEleDateProps, DataEleImageProps, DataEleListProps, DataEleMHProps, DataElementBarcode, DataElementBarcodeFactory, DataElementBarcodeProps, DataElementBarcodeRenderObject, DataElementBaseFactory, DataElementCheck, DataElementCheckFactory, DataElementCheckRenderObject, DataElementDate, DataElementDateFactory, DataElementDateRenderObject, DataElementGroupElement, DataElementGroupFactory, DataElementGroupProps, DataElementGroupRenderObject, DataElementImage, DataElementImgFactory, DataElementInlineGroup, DataElementLeaf, DataElementList, DataElementListFactory, DataElementListRenderObject, DataElementMH, DataElementMHFactory, DataElementRenderObject, DataElementText, DataElementTextFactory, DataElementTextRenderObject, DataImageRenderObject, DataRenderMH, DocEditor, DocMode, DocumentBodyElement, DocumentBodyFactory, DocumentBodyPartElement, DocumentBodyPartFactory, DocumentBodyPartRenderObject, DocumentBodyRenderObject, DocumentChange, DocumentCombine, DocumentComment, DocumentContainerRender, DocumentContext, DocumentCursor, DocumentElement, DocumentEvalFunc, DocumentEvent, DocumentFactory, DocumentFooterElement, DocumentFooterFactory, DocumentFooterRenderObject, DocumentHeaderElement, DocumentHeaderFactory, DocumentHeaderRenderObject, DocumentInput, DocumentPaint, DocumentPrintOffscreen, DocumentPrintOffscreenBase, DocumentProps, DocumentRenderObject, DocumentSelection, DocumentTemplate, DropElementEvent, EditMode, EditorContext, Element, ElementEvent, ElementFactory, ElementPaint, ElementReader, ElementSerialize, ElementUtil, EventBus, EventMap, EventSourceCore$1 as EventSourceCore, FillNullSpaceElement, FillNullSpaceRenderObject, GetTrackTipsEvent, GotCursorEvent, IDispose, INotifyPropertyChanged, InlineBlockContainer, InlineGroupElement, InlineGroupInputElement, InlineGroupRenderObject, InlineMuiltBlockLineRenderObject, InputElementEvent, IsInSideDataElement, IsInSideInlineGroupInputElement, KeyboradElementEvent, LeafElement, LeafRenderObject, LostCursorEvent, MarginProps, ModifyFlag$1 as ModifyFlag, MouseElementEvent, MousedownElementEvent, MuiltBlockLineRenderObject, OnceSubject, PSymbolElement, PSymbolRenderObject, PaddingProps, PageBreakElement, PageBreakFactory, PageBreakRenderObject, PageOptions, PaintContent, ParagraphElement, ParagraphFactory, ParagraphLineRectRenderObject, ParagraphNumberType, ParagraphProps, ParagraphRenderObject, PasteElementEvent, PictureElement, PictureFactory, PictureProps, PictureRenderObject, RadioBoxElement, RadioBoxFactory, RadioBoxProps, RadioBoxRenderObject, RangeUtil, Rect, RenderContext, RenderObject, RenderObjectType, ResizeLeafRenderObject, RunElementFactory, SelectionOverlays, SelectionRange, SelectionState, Subject$1 as Subject, SubjectSubscription$1 as SubjectSubscription, Subscription$1 as Subscription, TabElement, TabFactory, TabRenderObject, TableCellElement, TableCellFactory, TableCellProps, TableCellRenderObject, TableElement, TableFactory, TableProps, TableRenderObject, TableRowElement, TableRowFactory, TableRowProps, TableRowRenderObject, TableSplitCell, TableUtil, TextGroupElement, TextGroupFactory, TextGroupRenderObject, TextProps, TrackRunElement, TrackRunProps, TrackRunRenderObject, TrackRunTypeEnum, ValidateCondition, ValidateElement, ValidateProps, ValidateRenderObject, ViewOptions, clearChildrenRenderCache, clearTraces, createPrintTemplate, defaultParaHanging, deleteCurrentParagraph, docOpsMap, documentPrint, drawDecorator, elementTypeEventHandler, exportDecoratorHTML, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getFocusTextSegment, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, printNodes, reactiveMap, removeEle, removeText, runTextLineRender, setChildrenModifyFlag, setDataElementProps, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateInlineInputRenderObj, watchChanged };
29047
29115
  //# sourceMappingURL=index.js.map