@hailin-zheng/editor-core 2.2.14 → 2.2.16

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-cjs.js CHANGED
@@ -53,8 +53,6 @@ class ElementEvent {
53
53
  * 当前所在的对象
54
54
  */
55
55
  currentElement;
56
- currentRenderObjectX;
57
- currentRenderObjectY;
58
56
  //是否取消向上冒泡
59
57
  isCancel;
60
58
  globalX;
@@ -770,8 +768,11 @@ class CommonUtil {
770
768
  const shouldCallNow = elapsed >= wait;
771
769
  clearTimeout(timeout);
772
770
  if (shouldCallNow) {
773
- fn.apply(context, args);
774
- lastExecTime = Date.now();
771
+ //延迟执行,微任务
772
+ Promise.resolve().then(() => {
773
+ fn.apply(context, args);
774
+ lastExecTime = Date.now();
775
+ });
775
776
  }
776
777
  else {
777
778
  timeout = setTimeout(() => {
@@ -1000,6 +1001,8 @@ function generatePatch(doc, clear = true) {
1000
1001
  }
1001
1002
  if ('insert' in op.ops) {
1002
1003
  insertOpsMap.set(ele, op);
1004
+ //对象复制出来,避免paintRenders等内存占用
1005
+ op.ops.insert = op.ops.insert.clone(true);
1003
1006
  }
1004
1007
  //当前为新插入的元素
1005
1008
  if ('insText' in op.ops) {
@@ -1254,7 +1257,7 @@ class Element {
1254
1257
  modifyFlag = exports.ModifyFlag.Modify;
1255
1258
  isMouseenter;
1256
1259
  _eventMap;
1257
- _refreshEvent = new Subject();
1260
+ //private _refreshEvent: Subject<void> = new Subject();
1258
1261
  _onChangeEvent = new Subject();
1259
1262
  observers = new WeakMap();
1260
1263
  paintRenders = [];
@@ -1359,14 +1362,15 @@ class Element {
1359
1362
  return 0;
1360
1363
  }
1361
1364
  }
1362
- get refreshSubject() {
1363
- return this._refreshEvent;
1364
- }
1365
+ // get refreshSubject(): Subject<void> {
1366
+ // return this._refreshEvent;
1367
+ // }
1365
1368
  get onChangeSubject() {
1366
1369
  return this._onChangeEvent;
1367
1370
  }
1368
1371
  refreshView() {
1369
- this._refreshEvent.next();
1372
+ //this._refreshEvent.next();
1373
+ //refreshEditor(this);
1370
1374
  }
1371
1375
  unsubscribe(element) {
1372
1376
  const subs = this.observers.get(element);
@@ -1448,13 +1452,13 @@ class BranchElement extends Element {
1448
1452
  child.parent = this;
1449
1453
  this.chilren.splice(index, 0, child);
1450
1454
  insertEle(child);
1451
- const refSub = child.refreshSubject.subscribe((data) => {
1452
- this.refreshSubject.next(data);
1453
- });
1455
+ //const refSub = child.refreshSubject.subscribe((data) => {
1456
+ //this.refreshSubject.next(data);
1457
+ // });
1454
1458
  const onChangeSub = child.onChangeSubject.subscribe((data) => {
1455
1459
  this.pubOnChange('tracker');
1456
1460
  });
1457
- this.addsubscribe(child, refSub, onChangeSub);
1461
+ this.addsubscribe(child, onChangeSub);
1458
1462
  this.pubOnChange('self');
1459
1463
  }
1460
1464
  removeChild(child) {
@@ -1734,9 +1738,9 @@ class ViewOptions {
1734
1738
  currentFontName = '宋体';
1735
1739
  //选区颜色
1736
1740
  selectionColor = 'rgb(131,175,155,0.5)';
1737
- dataDecoratorNormalColor = '#0050b3';
1738
- dataDecoratorMouseEnterColor = '#0050b3';
1739
- dataDecoratorFocusedColor = '#0050b3';
1741
+ dataEleDecoratorNormalColor = '#0050b3';
1742
+ dataEleDecoratorMouseEnterColor = '#0050b3';
1743
+ dataEleDecoratorFocusedColor = '#0050b3';
1740
1744
  //数据元修饰符宽度
1741
1745
  dataDecoratorWidth = 1;
1742
1746
  //是否显示数据元修饰符
@@ -1753,12 +1757,18 @@ class ViewOptions {
1753
1757
  dataEleNormalBgColor = '#fafafa';
1754
1758
  //数据元错误背景颜色
1755
1759
  dataEleErrorBgColor = '#ff4d4f';
1756
- //数据元正常背景颜色
1757
- dataGroupEleNormalBgColor = '';
1760
+ //数据组修饰符号颜色
1761
+ dataGroupDecoratorNormalColor = '#0050b3';
1762
+ dataGroupDecoratorMouseEnterColor = '#0050b3';
1763
+ dataGroupDecoratorFocusedColor = '#0050b3';
1764
+ //数据组正常背景颜色
1765
+ dataGroupNormalBgColor = '#fafafa';
1766
+ //数据元没有输入值时背景颜色
1767
+ dataGroupEmptyBgColor = '';
1758
1768
  //数据元鼠标悬浮颜色
1759
- dataGroupMouseEnterBgColor = '';
1760
- //数据元只读背景颜色
1761
- dataGroupFocusedBgColor = '';
1769
+ dataGroupMouseEnterBgColor = '#f5f5f5';
1770
+ //数据元焦点背景颜色
1771
+ dataGroupFocusedBgColor = '#f0f0f0';
1762
1772
  viewBackcolor = 'rgb(230,230,230)';
1763
1773
  paraSymbolColor = 'rgb(128,128,128)';
1764
1774
  dataGroupColor = 'rgb(0,80,179)';
@@ -1803,6 +1813,8 @@ class ViewOptions {
1803
1813
  showEnterSymbol = false;
1804
1814
  enableVisibleExpression = false;
1805
1815
  shapeRendering = 'auto';
1816
+ //是否开启快速测量
1817
+ enableFastMeasure = false;
1806
1818
  get fullPageView() {
1807
1819
  return this._fullPageView;
1808
1820
  }
@@ -2970,16 +2982,22 @@ class DataDecorateRenderObject extends LeafRenderObject {
2970
2982
  if (event.mode === 'print') {
2971
2983
  return null;
2972
2984
  }
2985
+ if (this.element.dataEle.type === 'data-group') {
2986
+ return this.exportDataGroupSVG(event);
2987
+ }
2973
2988
  // if(this.element.parent.parent.type==='data-group'){
2974
2989
  // return null;
2975
2990
  // }
2976
2991
  const options = event.options;
2977
- let color = options.dataDecoratorNormalColor;
2978
- if (this.element.dataEle.isMouseenter && options.dataDecoratorMouseEnterColor) {
2979
- color = options.dataDecoratorMouseEnterColor;
2992
+ let color = options.dataEleDecoratorNormalColor;
2993
+ if (this.element.dataEle.isMouseenter && options.dataEleDecoratorMouseEnterColor) {
2994
+ color = options.dataEleDecoratorMouseEnterColor;
2995
+ }
2996
+ if (this.element.dataEle.isFocused && options.dataEleDecoratorFocusedColor) {
2997
+ color = options.dataEleDecoratorFocusedColor;
2980
2998
  }
2981
- if (this.element.dataEle.isFocused && options.dataDecoratorFocusedColor) {
2982
- color = options.dataDecoratorFocusedColor;
2999
+ if (!color) {
3000
+ return null;
2983
3001
  }
2984
3002
  const element = this.element;
2985
3003
  const lineWidth = 3;
@@ -3000,6 +3018,37 @@ class DataDecorateRenderObject extends LeafRenderObject {
3000
3018
  d: path
3001
3019
  });
3002
3020
  }
3021
+ exportDataGroupSVG(event) {
3022
+ const options = event.options;
3023
+ let color = options.dataGroupDecoratorNormalColor;
3024
+ if (this.element.dataEle.isMouseenter && options.dataGroupDecoratorMouseEnterColor) {
3025
+ color = options.dataGroupDecoratorMouseEnterColor;
3026
+ }
3027
+ if (this.element.dataEle.isFocused && options.dataGroupDecoratorFocusedColor) {
3028
+ color = options.dataGroupDecoratorFocusedColor;
3029
+ }
3030
+ if (!color) {
3031
+ return null;
3032
+ }
3033
+ const element = this.element;
3034
+ const lineWidth = 4;
3035
+ let path = '';
3036
+ const height = this.parent.rect.height - 4;
3037
+ if (element.isPrefix) {
3038
+ const x = this.rect.x + this.rect.width / 2;
3039
+ path = `M ${x + lineWidth} 2 L ${x} 2 L ${x} ${height} L ${x + lineWidth} ${height}`;
3040
+ }
3041
+ else {
3042
+ const x = this.rect.x + this.rect.width / 2;
3043
+ path = `M ${x - lineWidth} 2 L ${x} 2 L ${x} ${height} L ${x - lineWidth} ${height}`;
3044
+ }
3045
+ return ElementUtil.createSvgPath({
3046
+ stroke: color,
3047
+ fill: "none",
3048
+ 'stroke-width': 2,
3049
+ d: path
3050
+ });
3051
+ }
3003
3052
  }
3004
3053
 
3005
3054
  function parser(code, objects) {
@@ -3481,6 +3530,7 @@ class DocumentElement extends BlockContainerElement {
3481
3530
  footerElement;
3482
3531
  //commentsContainerElement!: CommsContainerElement;
3483
3532
  headerEditState = false;
3533
+ editorContext = null;
3484
3534
  constructor() {
3485
3535
  super('doc');
3486
3536
  this.props = new DocumentProps();
@@ -3514,11 +3564,11 @@ class DocumentElement extends BlockContainerElement {
3514
3564
  }
3515
3565
  };
3516
3566
  }
3517
- clone() {
3567
+ clone(data) {
3518
3568
  const clone = new DocumentElement();
3519
3569
  this.props.clone(clone.props);
3520
3570
  cloneElementBase(this, clone);
3521
- cloneChildren(this, clone, true);
3571
+ cloneChildren(this, clone, data);
3522
3572
  return clone;
3523
3573
  }
3524
3574
  /**
@@ -3554,7 +3604,7 @@ class DocumentElement extends BlockContainerElement {
3554
3604
  this.headerEditState = false;
3555
3605
  }
3556
3606
  ss.clear();
3557
- this.refreshView();
3607
+ //this.refreshView();
3558
3608
  }
3559
3609
  markPairs = [];
3560
3610
  /**
@@ -3829,7 +3879,7 @@ class InlineGroupInputElement extends InlineGroupElement {
3829
3879
  this.addEvent('ElementKeyDown', (evt) => {
3830
3880
  const { selectionState, sourceEvent, source } = evt;
3831
3881
  const { startControl, startOffset } = selectionState;
3832
- if (IsInSideDataElement(startControl, startOffset)) {
3882
+ if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
3833
3883
  if (sourceEvent.shiftKey && sourceEvent.keyCode === 13) ;
3834
3884
  else if (!sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
3835
3885
  evt.isCancel = true;
@@ -3838,7 +3888,7 @@ class InlineGroupInputElement extends InlineGroupElement {
3838
3888
  }, true);
3839
3889
  this.addEvent('GotCursor', (evt) => {
3840
3890
  const { startControl, startOffset } = evt.selectionState;
3841
- if (IsInSideDataElement(startControl, startOffset)) {
3891
+ if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
3842
3892
  this.isFocused = true;
3843
3893
  }
3844
3894
  });
@@ -3935,11 +3985,13 @@ class DataElementInlineGroup extends InlineGroupInputElement {
3935
3985
  });
3936
3986
  this.addEvent('ElementMousemove', (evt) => {
3937
3987
  this.isMouseenter = true;
3938
- this.refreshView();
3988
+ evt.ctx.refreshView();
3989
+ //this.refreshView();
3939
3990
  });
3940
3991
  this.addEvent('ElementMouseLeave', (evt) => {
3941
3992
  this.isMouseenter = false;
3942
- this.refreshView();
3993
+ evt.ctx.refreshView();
3994
+ //this.refreshView()
3943
3995
  });
3944
3996
  this.addEvent('GotCursor', (evt) => {
3945
3997
  this.onGotCursorEvent(evt);
@@ -4079,21 +4131,10 @@ function getCurrOptions(ele) {
4079
4131
  class DataElementRenderObject extends InlineGroupRenderObject {
4080
4132
  exportSVG(event) {
4081
4133
  const node = super.exportSVG(event);
4082
- exportDecoratorHTML(event, this);
4134
+ exportDataEleDecoratorSVG$1(event, this);
4135
+ //绘制下划线
4083
4136
  if (this.element.props.underline) {
4084
- const { x, y } = event.relativePagePos;
4085
- event.highlights.push({
4086
- sel: 'path',
4087
- data: {
4088
- ns: 'http://www.w3.org/2000/svg',
4089
- attrs: {
4090
- d: `M${x} ${y + this.rect.height} L${x + this.rect.width} ${y + this.rect.height}`,
4091
- stroke: '#000',
4092
- fill: 'none',
4093
- 'stroke-width': 1
4094
- }
4095
- }
4096
- });
4137
+ renderUnderline(event, this);
4097
4138
  }
4098
4139
  renderErrorTip(event, this);
4099
4140
  return node;
@@ -4156,7 +4197,7 @@ class DataElementBaseFactory extends ElementFactory {
4156
4197
  * @param event
4157
4198
  * @param r
4158
4199
  */
4159
- function exportDecoratorHTML(event, r) {
4200
+ function exportDataEleDecoratorSVG$1(event, r) {
4160
4201
  if (event.mode === 'print') {
4161
4202
  return;
4162
4203
  }
@@ -4172,6 +4213,9 @@ function exportDecoratorHTML(event, r) {
4172
4213
  if (r.element.isFocused && options.dataEleFocusedBgColor) {
4173
4214
  color = options.dataEleFocusedBgColor;
4174
4215
  }
4216
+ if (!color) {
4217
+ return;
4218
+ }
4175
4219
  //绘制背景
4176
4220
  const bgX = event.relativePagePos.x;
4177
4221
  const bgY = event.relativePagePos.y;
@@ -4340,6 +4384,21 @@ function renderUnderWavyLine(event, r, color) {
4340
4384
  d += Array(Math.ceil(width / 3)).fill("3,0").join(' t ');
4341
4385
  const path = ElementUtil.createSvgPath({ d, fill: 'none', stroke: color });
4342
4386
  event.highlights.push(path);
4387
+ }
4388
+ function renderUnderline(event, render) {
4389
+ const { x, y } = event.relativePagePos;
4390
+ event.highlights.push({
4391
+ sel: 'path',
4392
+ data: {
4393
+ ns: 'http://www.w3.org/2000/svg',
4394
+ attrs: {
4395
+ d: `M${x} ${y + render.rect.height} L${x + render.rect.width} ${y + render.rect.height}`,
4396
+ stroke: '#000',
4397
+ fill: 'none',
4398
+ 'stroke-width': 1
4399
+ }
4400
+ }
4401
+ });
4343
4402
  }
4344
4403
 
4345
4404
  class DocumentBodyElement extends BlockContainerElement {
@@ -5617,7 +5676,7 @@ class TableUtil {
5617
5676
  if (startCell) {
5618
5677
  this.restoreCellMerge(startCell);
5619
5678
  ss.resetRange(startCell, 0);
5620
- startCell.refreshView();
5679
+ //startCell.refreshView();
5621
5680
  }
5622
5681
  }
5623
5682
  static restoreCellMerge(cell) {
@@ -5715,7 +5774,7 @@ class TableUtil {
5715
5774
  tb.setCellWidth(insertColIndex === colsCount ? insertColIndex - 1 : insertColIndex, insertColWidth - newColWidth);
5716
5775
  tb.insertCol(insertColIndex, newColWidth);
5717
5776
  tb.pubOnChange('self');
5718
- tb.refreshView();
5777
+ //tb.refreshView();
5719
5778
  }
5720
5779
  /**
5721
5780
  * 在指定位置插入行
@@ -5744,7 +5803,7 @@ class TableUtil {
5744
5803
  //新行插在第一行或者最后一行
5745
5804
  if (insertRowIndex === 0 || insertRowIndex === tb.length) {
5746
5805
  tb.addChild(newRow, insertRowIndex);
5747
- tb.refreshView();
5806
+ //tb.refreshView();
5748
5807
  return newRow;
5749
5808
  }
5750
5809
  const destRow = tb.getChild(insertRowIndex);
@@ -5763,7 +5822,7 @@ class TableUtil {
5763
5822
  newCell.props.hMerge = destCell.props.hMerge;
5764
5823
  }
5765
5824
  tb.addChild(newRow, insertRowIndex);
5766
- tb.refreshView();
5825
+ //tb.refreshView();
5767
5826
  return newRow;
5768
5827
  }
5769
5828
  /**
@@ -5825,14 +5884,14 @@ class TableUtil {
5825
5884
  const nextCell = this.getNextCell(ss);
5826
5885
  if (nextCell) {
5827
5886
  ss.resetRange(nextCell, 0);
5828
- nextCell.refreshView();
5887
+ //nextCell.refreshView();
5829
5888
  return;
5830
5889
  }
5831
5890
  //新增行,并定位
5832
5891
  const tb = ElementUtil.getParentByType(startCell, TableElement);
5833
5892
  const newRow = this.insertNewRow(tb, rowIndex + 1);
5834
5893
  ss.resetRange(newRow, 0);
5835
- newRow.refreshView();
5894
+ //newRow.refreshView();
5836
5895
  }
5837
5896
  /**
5838
5897
  * 获取下一个可定位的单元格
@@ -5874,7 +5933,7 @@ class TableUtil {
5874
5933
  console.warn('当前位置不存在表格');
5875
5934
  return;
5876
5935
  }
5877
- tb.parent.refreshView();
5936
+ //tb.parent.refreshView();
5878
5937
  tb.remove();
5879
5938
  }
5880
5939
  /**
@@ -5895,7 +5954,7 @@ class TableUtil {
5895
5954
  else if (tc.props.diagonal === diagonal) {
5896
5955
  tc.props.diagonal = null;
5897
5956
  }
5898
- tc.refreshView();
5957
+ //tc.refreshView();
5899
5958
  }
5900
5959
  /**
5901
5960
  * 将当前表格截断成两个相邻的表格
@@ -6505,11 +6564,11 @@ class CommContentBaseElement extends BlockContainerElement {
6505
6564
  super(type);
6506
6565
  this.addEvent('GotCursor', () => {
6507
6566
  this.focus = true;
6508
- this.refreshView();
6567
+ //this.refreshView()
6509
6568
  });
6510
6569
  this.addEvent('LostCursor', () => {
6511
6570
  this.focus = false;
6512
- this.refreshView();
6571
+ //this.refreshView()
6513
6572
  });
6514
6573
  }
6515
6574
  }
@@ -8718,11 +8777,13 @@ class DataElementGroupElement extends InlineGroupInputElement {
8718
8777
  this.props = new DataElementGroupProps();
8719
8778
  this.addEvent('ElementMousemove', (evt) => {
8720
8779
  this.isMouseenter = true;
8721
- this.refreshView();
8780
+ //this.refreshView();
8781
+ evt.ctx.refreshView();
8722
8782
  });
8723
8783
  this.addEvent('ElementMouseLeave', (evt) => {
8724
8784
  this.isMouseenter = false;
8725
- this.refreshView();
8785
+ evt.ctx.refreshView();
8786
+ //this.refreshView();
8726
8787
  });
8727
8788
  }
8728
8789
  setValue(val) {
@@ -8738,13 +8799,15 @@ class DataElementGroupElement extends InlineGroupInputElement {
8738
8799
  val += '';
8739
8800
  }
8740
8801
  if (val) {
8741
- const items = val.split('<br/>');
8802
+ const items = val.split('\n');
8742
8803
  if (items.length) {
8743
8804
  items.forEach((item, index) => {
8744
- const valueText = new TextGroupElement();
8745
- this.props.valueTextProps.clone(valueText.props);
8746
- valueText.text = item + '';
8747
- this.addChild(valueText, this.length - 1);
8805
+ if (item) {
8806
+ const valueText = new TextGroupElement();
8807
+ this.props.valueTextProps.clone(valueText.props);
8808
+ valueText.text = item + '';
8809
+ this.addChild(valueText, this.length - 1);
8810
+ }
8748
8811
  if (index < items.length - 1) {
8749
8812
  const brElement = new BreakElement();
8750
8813
  this.addChild(brElement, this.length - 1);
@@ -8783,6 +8846,15 @@ class DataElementGroupRenderObject extends InlineGroupRenderObject {
8783
8846
  }
8784
8847
  return cloneRender;
8785
8848
  }
8849
+ exportSVG(event) {
8850
+ const node = super.exportSVG(event);
8851
+ exportDataEleDecoratorSVG(event, this);
8852
+ //绘制下划线
8853
+ if (this.element.props.underline) {
8854
+ renderUnderline(event, this);
8855
+ }
8856
+ return node;
8857
+ }
8786
8858
  }
8787
8859
  class DataElementGroupFactory extends DataElementBaseFactory {
8788
8860
  match(type) {
@@ -8821,6 +8893,35 @@ function IsInSideDataGroup(control, offset) {
8821
8893
  }
8822
8894
  function validateDataGroup(control) {
8823
8895
  return control instanceof DataElementGroupElement;
8896
+ }
8897
+ /**
8898
+ * 渲染数据元背景修饰
8899
+ * @param event
8900
+ * @param r
8901
+ */
8902
+ function exportDataEleDecoratorSVG(event, r) {
8903
+ if (event.mode === 'print') {
8904
+ return;
8905
+ }
8906
+ const options = event.options;
8907
+ let color = options.dataGroupNormalBgColor;
8908
+ //空数据元填充颜色
8909
+ if (r.element.length === 2 && options.dataGroupEmptyBgColor) {
8910
+ color = options.dataGroupEmptyBgColor;
8911
+ }
8912
+ if (r.element.isMouseenter && options.dataGroupMouseEnterBgColor) {
8913
+ color = options.dataGroupMouseEnterBgColor;
8914
+ }
8915
+ if (r.element.isFocused && options.dataGroupFocusedBgColor) {
8916
+ color = options.dataGroupFocusedBgColor;
8917
+ }
8918
+ if (!color) {
8919
+ return;
8920
+ }
8921
+ //绘制背景
8922
+ const bgX = event.relativePagePos.x;
8923
+ const bgY = event.relativePagePos.y;
8924
+ event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
8824
8925
  }
8825
8926
 
8826
8927
  class DataElementImage extends DataElementLeaf {
@@ -9102,13 +9203,15 @@ class DataElementText extends DataElementInlineGroup {
9102
9203
  val += '';
9103
9204
  }
9104
9205
  if (val) {
9105
- const items = val.split('<br/>');
9206
+ const items = val.split('\n');
9106
9207
  if (items.length) {
9107
9208
  items.forEach((item, index) => {
9108
- const valueText = new TextGroupElement();
9109
- this.props.valueTextProps.clone(valueText.props);
9110
- valueText.text = item + '';
9111
- this.addChild(valueText, this.length - 1);
9209
+ if (item) {
9210
+ const valueText = new TextGroupElement();
9211
+ this.props.valueTextProps.clone(valueText.props);
9212
+ valueText.text = item + '';
9213
+ this.addChild(valueText, this.length - 1);
9214
+ }
9112
9215
  if (index < items.length - 1) {
9113
9216
  const brElement = new BreakElement();
9114
9217
  this.addChild(brElement, this.length - 1);
@@ -9176,11 +9279,13 @@ class DataContainerElement extends BlockContainerElement {
9176
9279
  this.props = new DataContainerProps();
9177
9280
  this.addEvent('GotCursor', (evt) => {
9178
9281
  this.isFocused = true;
9179
- this.refreshView();
9282
+ evt.ctx.refreshView();
9283
+ //this.refreshView();
9180
9284
  });
9181
9285
  this.addEvent('LostCursor', (evt) => {
9182
9286
  this.isFocused = false;
9183
- this.refreshView();
9287
+ evt.ctx.refreshView();
9288
+ //this.refreshView();
9184
9289
  });
9185
9290
  }
9186
9291
  createRenderObject() {
@@ -9295,19 +9400,23 @@ class DocumentBodyPartElement extends BlockContainerElement {
9295
9400
  super('body-part');
9296
9401
  this.addEvent('ElementMousemove', (evt) => {
9297
9402
  this.isMouseenter = true;
9298
- this.refreshView();
9403
+ evt.ctx.refreshView();
9404
+ //this.refreshView();
9299
9405
  });
9300
9406
  this.addEvent('ElementMouseLeave', (evt) => {
9301
9407
  this.isMouseenter = false;
9302
- this.refreshView();
9408
+ evt.ctx.refreshView();
9409
+ //this.refreshView();
9303
9410
  });
9304
9411
  this.addEvent('GotCursor', (evt) => {
9305
9412
  this.isFocused = true;
9306
- this.refreshView();
9413
+ evt.ctx.refreshView();
9414
+ //this.refreshView();
9307
9415
  });
9308
9416
  this.addEvent('LostCursor', (evt) => {
9309
9417
  this.isFocused = false;
9310
- this.refreshView();
9418
+ evt.ctx.refreshView();
9419
+ //this.refreshView();
9311
9420
  });
9312
9421
  this.props = new BodyPartProps();
9313
9422
  }
@@ -10221,7 +10330,7 @@ class TableSplitCell {
10221
10330
  }
10222
10331
  }
10223
10332
  tb.pubOnChange('self');
10224
- tb.refreshView();
10333
+ //tb.refreshView();
10225
10334
  }
10226
10335
  /**
10227
10336
  * 拆分合并的单元格
@@ -10328,7 +10437,7 @@ class TableSplitCell {
10328
10437
  }
10329
10438
  }
10330
10439
  tb.pubOnChange('to-child');
10331
- tb.refreshView();
10440
+ //tb.refreshView();
10332
10441
  return {
10333
10442
  startColIndex: focusCellIndex,
10334
10443
  endColIndex: focusCellIndex + cols - 1
@@ -10358,7 +10467,7 @@ class TableSplitCell {
10358
10467
  TableUtil.restoreCell(ss);
10359
10468
  this.applyHorSplitColumnCurrPatchPacks(tb, focusRowIndex, focusCellIndex, rows, currPacks);
10360
10469
  tb.pubOnChange('to-child');
10361
- tb.refreshView();
10470
+ //tb.refreshView();
10362
10471
  return {
10363
10472
  startColIndex: focusCellIndex,
10364
10473
  endColIndex: this.getPrepareNewColCounts(otherPacks, hMergeCols)
@@ -10726,6 +10835,9 @@ class ElementSerialize {
10726
10835
  if (element instanceof PSymbolElement) {
10727
10836
  return '\n';
10728
10837
  }
10838
+ if (element instanceof BreakElement) {
10839
+ return '\n';
10840
+ }
10729
10841
  if (element instanceof BranchElement) {
10730
10842
  const items = [];
10731
10843
  for (let i = 0; i < element.length; i++) {
@@ -13274,6 +13386,7 @@ class EditorContext {
13274
13386
  //suggestionsList: Array<ISuggestionData> = [];
13275
13387
  //currentSuggestionsList: Array<ISuggestionData> = [];
13276
13388
  suggestions = new DocInputSuggestions();
13389
+ //editor->this->others
13277
13390
  onKeyDownEvent = new Subject();
13278
13391
  constructor(selectionState, viewOptions) {
13279
13392
  this.selectionState = selectionState;
@@ -13283,6 +13396,16 @@ class EditorContext {
13283
13396
  this.syncRefresh?.();
13284
13397
  });
13285
13398
  }
13399
+ /**
13400
+ * 刷新视图
13401
+ */
13402
+ refreshView() {
13403
+ this.syncRefresh?.();
13404
+ }
13405
+ /**
13406
+ * 编辑器文档刷新后回调(DOM渲染完成后回调)
13407
+ * @param cb
13408
+ */
13286
13409
  onNextView(cb) {
13287
13410
  if (!cb) {
13288
13411
  this.nextViewFns.length = 0;
@@ -13297,25 +13420,27 @@ class EditorContext {
13297
13420
  set document(value) {
13298
13421
  this.clearPrevDocCb?.();
13299
13422
  this._document = value;
13423
+ this._document['editorContext'] = this;
13300
13424
  // this.refSub = this._document.refreshSubject.subscribe((data) => {
13301
13425
  // data = data ?? 'content';
13302
13426
  // this.isDirty = this.isDirty || data === 'content';
13303
13427
  // this.syncRefresh?.(data);
13304
13428
  // });
13305
- const docRefreshSub = this._document.refreshSubject.subscribe(() => {
13306
- this.syncRefresh?.();
13307
- });
13429
+ // const docRefreshSub = this._document.refreshSubject.subscribe(() => {
13430
+ // this.syncRefresh?.();
13431
+ // });
13308
13432
  const docChangedSub = this._document.onChangeSubject.subscribe(() => {
13309
13433
  this.syncRefresh?.();
13310
13434
  });
13311
13435
  this.syncRefresh();
13312
13436
  this.clearPrevDocCb = () => {
13313
- docRefreshSub.unsubscribe();
13437
+ //docRefreshSub.unsubscribe();
13314
13438
  docChangedSub.unsubscribe();
13315
13439
  if (this._document) {
13316
13440
  this.selectionState?.renderContainer?.destroy();
13317
13441
  this.clear();
13318
13442
  this._document.destroy();
13443
+ this._document.editorContext = null;
13319
13444
  clearTraces(this._document);
13320
13445
  }
13321
13446
  this.clearPrevDocCb = null;
@@ -13326,6 +13451,7 @@ class EditorContext {
13326
13451
  this.selectionState.clear();
13327
13452
  this.isDirty = false;
13328
13453
  this.suggestions.clear();
13454
+ this.currentOpsLog.length = 0;
13329
13455
  //this.clearEleDepMaps();
13330
13456
  }
13331
13457
  get defaultCtx() {
@@ -13368,6 +13494,7 @@ class EditorContext {
13368
13494
  //this.ele_types_handlers.length = 0;
13369
13495
  //this.imageLoader.clear();
13370
13496
  this._document = null;
13497
+ this.currentOpsLog.length = 0;
13371
13498
  this.suggestions.destroy();
13372
13499
  }
13373
13500
  /**
@@ -13390,11 +13517,13 @@ class EditorContext {
13390
13517
  oldDataElement.remove();
13391
13518
  }
13392
13519
  currentRefreshType = null;
13520
+ //当前操作日志
13521
+ currentOpsLog = [];
13393
13522
  get refreshType() {
13394
- if (!this._document) {
13523
+ if (!this._document || this._document.modifyFlag === exports.ModifyFlag.None) {
13395
13524
  return null;
13396
13525
  }
13397
- return this._document.modifyFlag === exports.ModifyFlag.None ? 'appearance' : 'content';
13526
+ return this._document.modifyFlag === exports.ModifyFlag.Track ? 'appearance' : 'content';
13398
13527
  }
13399
13528
  adaptiveScale() {
13400
13529
  if (this.viewOptions.pageLayoutMode !== 'fit-page') {
@@ -13670,6 +13799,18 @@ class DocumentContext {
13670
13799
  }
13671
13800
  return arr;
13672
13801
  }
13802
+ }
13803
+ function refreshEditor(ele) {
13804
+ const doc = ElementUtil.getParent(ele, e => e.type === 'doc');
13805
+ if (doc) {
13806
+ const editorCtx = doc['editorContext'];
13807
+ if (editorCtx) {
13808
+ editorCtx.refreshView();
13809
+ }
13810
+ else {
13811
+ console.warn("doc.editorContext is null,不能刷新!");
13812
+ }
13813
+ }
13673
13814
  }
13674
13815
 
13675
13816
  class DynamicExecute {
@@ -15200,6 +15341,83 @@ class DocumentArrange {
15200
15341
  tmp.props.lineHeight = this.options.defaultLineHeight;
15201
15342
  return tmp;
15202
15343
  }
15344
+ patchParagraph() {
15345
+ if (!this.options.enableFastMeasure) {
15346
+ return false;
15347
+ }
15348
+ this.pMeasure = new ParagraphMeasure(this.options, this.renderCtx, this.execute);
15349
+ const ops = this.docCtx.currentOpsLog;
15350
+ if (!ops.length) {
15351
+ return false;
15352
+ }
15353
+ if (ops.every(op => 'delText' in op.ops || 'insText' in op.ops || ('insert' in op.ops && op.ops.insert.type === 'text'))) {
15354
+ const parentIndex = ops[0].parentIndex;
15355
+ //查找父容器
15356
+ const parentEle = ElementUtil.getControlByIndex(this.docCtx.document, { currIndex: -1, index: parentIndex }, true);
15357
+ const paraEle = ElementUtil.getParent(parentEle, item => item instanceof ParagraphElement);
15358
+ if (!paraEle) {
15359
+ return false;
15360
+ }
15361
+ const cacheRender = paraEle.cacheRender;
15362
+ if (!cacheRender) {
15363
+ return false;
15364
+ }
15365
+ //已经绘制的渲染对象
15366
+ const paintRenders = paraEle.paintRenders;
15367
+ const measureParaRenders = this.pMeasure.measureParagraph(paraEle, cacheRender.rect.width);
15368
+ if (measureParaRenders.length !== 1) {
15369
+ return false;
15370
+ }
15371
+ const measureParaRender = measureParaRenders[0];
15372
+ if (cacheRender.rect.width !== measureParaRender.rect.width || cacheRender.rect.height !== measureParaRender.rect.height) {
15373
+ return false;
15374
+ }
15375
+ //第一种情况,出现在页面或者页尾上
15376
+ const measureParaRenderLines = measureParaRender.length;
15377
+ const paintRendersLines = paintRenders.reduce((prev, curr) => {
15378
+ prev.push(...curr.getItems());
15379
+ return prev;
15380
+ }, []);
15381
+ if (paintRendersLines.length % measureParaRenderLines !== 0) {
15382
+ return false;
15383
+ }
15384
+ //完全一致,逐个替换
15385
+ if (paintRendersLines.length === measureParaRenderLines) {
15386
+ for (let i = 0; i < paintRendersLines.length; i++) {
15387
+ const line = paintRendersLines[i];
15388
+ const index = line.getIndex();
15389
+ const tempLine = measureParaRender.getChild(i).clone();
15390
+ tempLine.rect.width = line.rect.width;
15391
+ tempLine.rect.height = line.rect.height;
15392
+ tempLine.rect.x = line.rect.x;
15393
+ tempLine.rect.y = line.rect.y;
15394
+ line.parent.insertChild(tempLine, index);
15395
+ line.parent.removeChild(line);
15396
+ }
15397
+ return true;
15398
+ }
15399
+ }
15400
+ return false;
15401
+ }
15402
+ fastPatchReset(docRenders) {
15403
+ //测量阶段,对于空段落会插入段落符号,新表格会插入空段落,此时不需要记录节点的更改,以最大的节点进行记录
15404
+ return suppressTracking(() => {
15405
+ const doc = this.docCtx.document;
15406
+ this.execute = new DynamicExecute(doc, this.docCtx.selectionState);
15407
+ this.pMeasure = new ParagraphMeasure(this.options, this.renderCtx, this.execute);
15408
+ const data = {
15409
+ doc,
15410
+ options: this.options,
15411
+ execute: this.execute,
15412
+ renderCtx: this.renderCtx,
15413
+ createParaFn: () => this.createDefaultPara()
15414
+ };
15415
+ this.reset(data);
15416
+ this.setMeasureCompletedModifyFlag(doc);
15417
+ this.cacheDocRenders(docRenders);
15418
+ this.generateCommRange();
15419
+ });
15420
+ }
15203
15421
  }
15204
15422
 
15205
15423
  /**
@@ -15227,7 +15445,12 @@ class DocumentPaginator {
15227
15445
  this.docCtx.selectionState.renderContainer = this.docContainer;
15228
15446
  this.docContainer.rect.width = this.viewOptions.docPageSettings.width;
15229
15447
  const newMeasure = new DocumentArrange(this.docCtx, this.renderContext, this.seo);
15230
- this.docPages = newMeasure.measureDoc();
15448
+ if (newMeasure.patchParagraph()) {
15449
+ newMeasure.fastPatchReset(this.docPages);
15450
+ }
15451
+ else {
15452
+ this.docPages = newMeasure.measureDoc();
15453
+ }
15231
15454
  this.adjustTipLayoutWidth();
15232
15455
  this.layoutPages();
15233
15456
  }
@@ -20697,7 +20920,7 @@ class DocEditor {
20697
20920
  },
20698
20921
  on: {
20699
20922
  resize: () => {
20700
- console.log('resize');
20923
+ //console.log('resize')
20701
20924
  }
20702
20925
  }
20703
20926
  },
@@ -20715,10 +20938,13 @@ class DocEditor {
20715
20938
  const target = evt.target;
20716
20939
  this.viewOptions.pageOffset.x = target.scrollLeft;
20717
20940
  this.viewOptions.pageOffset.y = target.scrollTop;
20718
- this.onChange();
20941
+ //this.onChange();
20942
+ //滚动的时候,不需要重新计算元素
20943
+ //只需要重新渲染vnode即可
20944
+ this.onPatchVNodeSubject.next();
20719
20945
  },
20720
20946
  resize: () => {
20721
- console.log('resize');
20947
+ //console.log('resize')
20722
20948
  }
20723
20949
  },
20724
20950
  hook: {
@@ -20781,12 +21007,12 @@ class DocEditor {
20781
21007
  this.refreshDocument();
20782
21008
  this.flushTask = null;
20783
21009
  //回调
20784
- let cbs = [...this.docCtx.nextViewFns];
20785
- if (cbs.length) {
20786
- this.docCtx.onNextView(null);
20787
- cbs.forEach(cb => cb());
20788
- return;
20789
- }
21010
+ // let cbs = [...this.docCtx.nextViewFns];
21011
+ // if (cbs.length) {
21012
+ // this.docCtx.onNextView(null);
21013
+ // cbs.forEach(cb => cb());
21014
+ // return;
21015
+ // }
20790
21016
  this.historyMange.generateTrack();
20791
21017
  this.historyMange.generateSelectionLog();
20792
21018
  };
@@ -20836,9 +21062,9 @@ class DocEditor {
20836
21062
  * @returns
20837
21063
  */
20838
21064
  refreshDocument() {
20839
- if (this.docCtx.refreshType === null) {
20840
- return;
20841
- }
21065
+ // if (this.docCtx.refreshType === null) {
21066
+ // return;
21067
+ // }
20842
21068
  this.docCtx.currentRefreshType = this.docCtx.refreshType;
20843
21069
  if (this.docCtx.currentRefreshType) {
20844
21070
  this.onBeforeRefreshDocument.next();
@@ -21719,6 +21945,7 @@ class DocEditor {
21719
21945
  this.vNodeDocContent = this.nodePatch(this.svgContainer, vNode);
21720
21946
  }
21721
21947
  this.afterNodePatch.next();
21948
+ this.onNextView();
21722
21949
  //console.timeEnd('patch');
21723
21950
  };
21724
21951
  render();
@@ -21729,6 +21956,13 @@ class DocEditor {
21729
21956
  render();
21730
21957
  }, 32));
21731
21958
  }
21959
+ onNextView() {
21960
+ let cbs = [...this.docCtx.nextViewFns];
21961
+ if (cbs.length) {
21962
+ this.docCtx.onNextView();
21963
+ cbs.forEach(cb => cb());
21964
+ }
21965
+ }
21732
21966
  /**
21733
21967
  * 留痕提示的容器框,用于渲染后重新计算纵向位置
21734
21968
  * @private
@@ -22084,7 +22318,7 @@ class DocEditor {
22084
22318
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
22085
22319
  }
22086
22320
  version() {
22087
- return "2.2.14";
22321
+ return "2.2.16";
22088
22322
  }
22089
22323
  switchPageHeaderEditor() {
22090
22324
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -22167,6 +22401,7 @@ class DocEditor {
22167
22401
  readDocChangeLog() {
22168
22402
  //获取文档的变更日志
22169
22403
  const ops = generatePatch(this.docCtx.document, false);
22404
+ this.docCtx.currentOpsLog = [...ops];
22170
22405
  //1.处理批注删除不对称的问题
22171
22406
  for (let i = 0; i < ops.length; i++) {
22172
22407
  const op = ops[i];
@@ -22422,7 +22657,7 @@ class DocumentCombine {
22422
22657
  * 用于合并文档计算
22423
22658
  */
22424
22659
  load() {
22425
- const template = this.mainTemplate.clone();
22660
+ const template = this.mainTemplate.clone(true);
22426
22661
  const body = template.find((item) => item instanceof DocumentBodyElement);
22427
22662
  body.clearItems();
22428
22663
  for (let i = 0; i < this.docParts.length; i++) {
@@ -27784,13 +28019,13 @@ const onTableContextmenu = (evt) => {
27784
28019
  evt.menus.push({
27785
28020
  caption: '上方插入段落', click: () => {
27786
28021
  currentElement.parent.addChild(ParagraphElement.createElement(), currentElement.getIndex());
27787
- currentElement.refreshView();
28022
+ //currentElement.refreshView()
27788
28023
  }
27789
28024
  });
27790
28025
  evt.menus.push({
27791
28026
  caption: '下方插入段落', click: () => {
27792
28027
  currentElement.parent.addChild(ParagraphElement.createElement(), currentElement.getIndex() + 1);
27793
- currentElement.refreshView();
28028
+ //currentElement.refreshView()
27794
28029
  }
27795
28030
  });
27796
28031
  evt.menus = removeDuplicatesEvent(evt.menus);
@@ -28035,7 +28270,7 @@ exports.defaultParaHanging = defaultParaHanging;
28035
28270
  exports.deleteCurrentParagraph = deleteCurrentParagraph;
28036
28271
  exports.docOpsMap = docOpsMap;
28037
28272
  exports.elementTypeEventHandler = elementTypeEventHandler;
28038
- exports.exportDecoratorHTML = exportDecoratorHTML;
28273
+ exports.exportDataEleDecoratorSVG = exportDataEleDecoratorSVG$1;
28039
28274
  exports.falseChar = falseChar;
28040
28275
  exports.fontMapFunc = fontMapFunc;
28041
28276
  exports.formatEle = formatEle;
@@ -28053,10 +28288,12 @@ exports.onTableContextmenu = onTableContextmenu;
28053
28288
  exports.onceTask = onceTask;
28054
28289
  exports.parser = parser;
28055
28290
  exports.reactiveMap = reactiveMap;
28291
+ exports.refreshEditor = refreshEditor;
28056
28292
  exports.removeEle = removeEle;
28057
28293
  exports.removeText = removeText;
28058
28294
  exports.renderErrorTip = renderErrorTip;
28059
28295
  exports.renderUnderWavyLine = renderUnderWavyLine;
28296
+ exports.renderUnderline = renderUnderline;
28060
28297
  exports.runTextLineRender = runTextLineRender;
28061
28298
  exports.setChildrenModifyFlag = setChildrenModifyFlag;
28062
28299
  exports.setNotifyChangedCallback = setNotifyChangedCallback;