@hailin-zheng/editor-core 1.1.11 → 1.1.12

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.
@@ -26,6 +26,8 @@ export declare class NodeEvent {
26
26
  */
27
27
  onWheelHandler(evt: WheelEvent): void;
28
28
  onContextMenuHandler(evt: MouseEvent): void;
29
+ onCopyHandler(evt: ClipboardEvent): void;
30
+ onKeydownHandler(evt: KeyboardEvent): void;
29
31
  getHitNode(hitPos: Position, parentPos: Position): IHitInfo | null;
30
32
  getMouseHitNode(node: NodeCore, hitPos: Position, parentPos: Position): IHitInfo | null;
31
33
  invokeNodeFocusedEvent(prevNode: NodeCore | null, prevParents: Array<NodeCore>, currNode: NodeCore | null): void;
package/index-cjs.js CHANGED
@@ -1958,7 +1958,7 @@ class TableRowProps extends INotifyPropertyChanged {
1958
1958
  class TableProps extends INotifyPropertyChanged {
1959
1959
  id;
1960
1960
  cols;
1961
- alignment;
1961
+ align;
1962
1962
  border = 'all';
1963
1963
  allowBreakRow;
1964
1964
  clone(dest) {
@@ -1966,7 +1966,7 @@ class TableProps extends INotifyPropertyChanged {
1966
1966
  super.cloneAttachedProperty(clone);
1967
1967
  clone.id = this.id;
1968
1968
  clone.cols = [...this.cols];
1969
- clone.alignment = this.alignment;
1969
+ clone.align = this.align;
1970
1970
  clone.border = this.border;
1971
1971
  return clone;
1972
1972
  }
@@ -1974,7 +1974,7 @@ class TableProps extends INotifyPropertyChanged {
1974
1974
  return {
1975
1975
  id: this.id,
1976
1976
  cols: this.cols,
1977
- alignment: this.alignment,
1977
+ alignment: this.align,
1978
1978
  border: this.border
1979
1979
  };
1980
1980
  }
@@ -3202,7 +3202,7 @@ class DataElementRenderObject extends InlineGroupRenderObject {
3202
3202
  textProps.fontSize = 16;
3203
3203
  textProps.fontName = viewOptions.defaultFontName;
3204
3204
  textProps.color = '#fff';
3205
- const titleWidth = render.contentContext.measureText(caption, textProps).width;
3205
+ const titleWidth = render.contentContext.measureText2(caption, textProps);
3206
3206
  const x = position.x;
3207
3207
  const y = position.y - 20;
3208
3208
  render.contentContext.fillRect(x, y, titleWidth + 10, 20, 'blue');
@@ -4840,7 +4840,9 @@ class TableElement extends BlockContainerElement {
4840
4840
  return clone;
4841
4841
  }
4842
4842
  createRenderObject() {
4843
- return new TableRenderObject(this);
4843
+ const render = new TableRenderObject(this);
4844
+ render.rect.width = this.props.cols.reduce((prev, curr) => curr + prev, 0);
4845
+ return render;
4844
4846
  }
4845
4847
  beginMeasure(data) {
4846
4848
  super.beginMeasure(data);
@@ -4929,7 +4931,7 @@ class TableFactory extends ElementFactory {
4929
4931
  tbProps.border = props.border || 'all';
4930
4932
  tbProps.cols = [];
4931
4933
  tbProps.id = props.id;
4932
- tbProps.alignment = props.alignment;
4934
+ tbProps.align = props.align;
4933
4935
  for (const col of cols) {
4934
4936
  if (typeof col === 'object') {
4935
4937
  tbProps.cols.push(col.width);
@@ -5086,7 +5088,7 @@ class TextGroupElement extends LeafElement {
5086
5088
  return this.textMeasures.map(item => item.char).join('');
5087
5089
  }
5088
5090
  createRenderObject(data) {
5089
- if (!this.isMeasure || this.modifyFlag !== exports.ModifyFlag.None) {
5091
+ if (!this.isMeasure || this.modifyFlag !== exports.ModifyFlag.None || !this.cacheRender) {
5090
5092
  data.renderCtx.contentContext.measureTextUnits(this.textMeasures, this.props);
5091
5093
  this.isMeasure = true;
5092
5094
  }
@@ -5582,7 +5584,7 @@ class ElementUtil {
5582
5584
  line.rect.x = innerRect.x;
5583
5585
  }
5584
5586
  line.rect.y = innerRect.height + innerRect.y + line.margin.top;
5585
- //line.rect.maxWidth = innerRect.maxWidth;
5587
+ this.setHorizontalAlign(line, innerRect);
5586
5588
  innerRect.height += line.rect.height + line.margin.top + line.margin.bottom;
5587
5589
  }
5588
5590
  render.updateRenderHeight(innerRect);
@@ -5590,8 +5592,7 @@ class ElementUtil {
5590
5592
  }
5591
5593
  static remeasureTableRow(rowRender, foreceColIndex = -1) {
5592
5594
  const rowEle = rowRender.element;
5593
- const rowMinHeight = rowEle.props.minHeight > 19 ? rowEle.props.minHeight : 19;
5594
- let maxCellHeight = rowMinHeight;
5595
+ let maxCellHeight = rowEle.props.minHeight > 19 ? rowEle.props.minHeight : 19;
5595
5596
  //限制行最小高度
5596
5597
  maxCellHeight = maxCellHeight < 19 ? 19 : maxCellHeight;
5597
5598
  //获取行内非纵向合并单元格的最高单元格高度
@@ -5673,11 +5674,24 @@ class ElementUtil {
5673
5674
  }
5674
5675
  }
5675
5676
  /**
5676
- * 设置表格横向排列方式
5677
- * @param tbRender
5677
+ * 设置原色横向排列方式
5678
5678
  * @private
5679
- */
5680
- static setTableAlign(tbRender) {
5679
+ * @param render
5680
+ * @param limitRect
5681
+ */
5682
+ static setHorizontalAlign(render, limitRect) {
5683
+ if (render.element && render.element.props && render.element.props.align) {
5684
+ const align = render.element.props.align;
5685
+ if (align) {
5686
+ const remainSpace = limitRect.width - render.rect.width;
5687
+ if (align === 'center') {
5688
+ render.rect.x = Math.floor(remainSpace / 2);
5689
+ }
5690
+ else if (align === 'end') {
5691
+ render.rect.x = remainSpace;
5692
+ }
5693
+ }
5694
+ }
5681
5695
  // const {alignment} = tbRender.element.props;
5682
5696
  // if (!alignment) {
5683
5697
  // return;
@@ -7090,6 +7104,10 @@ class PaintContent {
7090
7104
  const textMeasure = this.ctx.measureText(text);
7091
7105
  return { width: textMeasure.width, height: textProps.fontSize };
7092
7106
  }
7107
+ measureText2(text, font) {
7108
+ this.ctx.font = font.fontSize + 'px ' + font.fontName;
7109
+ return this.ctx.measureText(text).width;
7110
+ }
7093
7111
  measureTextUnits(units, textProps) {
7094
7112
  this.ctx.font = textProps.getFont();
7095
7113
  const letterSpace = textProps.letterSpace ?? 0;
@@ -11764,8 +11782,7 @@ class DocumentArrange {
11764
11782
  item.rect.y = bodyInnerLimitRect.height + item.margin.top;
11765
11783
  pageBodyRender.addChild(item);
11766
11784
  bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
11767
- //上一个元素的bottom-margin
11768
- //bodyInnerLimitRect.prevMargin = item.margin.bottom;
11785
+ ElementUtil.setHorizontalAlign(item, bodyInnerLimitRect);
11769
11786
  ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
11770
11787
  };
11771
11788
  for (let i = 0; i < doc.bodyElement.length; i++) {
@@ -13726,6 +13743,9 @@ class DocumentEvent {
13726
13743
  this.editor.addEventListener('contextmenu', evt => {
13727
13744
  this.contextMenu.next(evt.sourceEvt);
13728
13745
  });
13746
+ this.editor.addEventListener('keydown', evt => {
13747
+ this.onKeydown(evt.sourceEvt);
13748
+ });
13729
13749
  this.documentInput.onLeftEvent.subscribe(() => {
13730
13750
  this.moveCursorToLeft();
13731
13751
  });
@@ -14159,6 +14179,10 @@ class DocumentEvent {
14159
14179
  mouseDblClickHandle(nodeEvt) {
14160
14180
  const docEvent = new MouseElementEvent(this.docCtx);
14161
14181
  this.setEventViewPos(nodeEvt.sourceHitPos, docEvent);
14182
+ const hitInfo = this.getHitInfo(docEvent);
14183
+ if (!hitInfo) {
14184
+ return;
14185
+ }
14162
14186
  //需要先处理是否开启页眉页脚编辑功能
14163
14187
  const hitRegion = this.getHitRegion(docEvent);
14164
14188
  if ((hitRegion === 'footer' || hitRegion === 'header') && !this.docCtx.document.headerEditState) {
@@ -14169,7 +14193,7 @@ class DocumentEvent {
14169
14193
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
14170
14194
  return;
14171
14195
  }
14172
- const hitInfo = this.getHitInfo(docEvent);
14196
+ //const hitInfo = this.getHitInfo(docEvent);
14173
14197
  if (hitInfo) {
14174
14198
  docEvent.source = hitInfo.element;
14175
14199
  docEvent.sourceRender = hitInfo.render;
@@ -14779,9 +14803,8 @@ class DocumentEvent {
14779
14803
  }
14780
14804
  /**
14781
14805
  * 获取点击的文档区域
14782
- * @param docRender
14783
- * @param pos
14784
14806
  * @returns
14807
+ * @param docEvent
14785
14808
  */
14786
14809
  getHitRegion(docEvent) {
14787
14810
  const hitDocInfo = this.getHitDocPage(docEvent);
@@ -14812,6 +14835,30 @@ class DocumentEvent {
14812
14835
  return null;
14813
14836
  }
14814
14837
  }
14838
+ onKeydown(evt) {
14839
+ const copy = () => {
14840
+ const input = document.createElement('input');
14841
+ document.body.appendChild(input);
14842
+ input.select();
14843
+ input.focus();
14844
+ input.addEventListener('copy', evt2 => {
14845
+ document.body.removeChild(input);
14846
+ const execCopy = this.editor['execCopy'];
14847
+ execCopy.call(this.editor, evt2);
14848
+ });
14849
+ document.execCommand('copy');
14850
+ };
14851
+ if (navigator.appVersion.indexOf('Mac') >= 0) {
14852
+ if (evt.metaKey && evt.keyCode === 67) {
14853
+ copy();
14854
+ }
14855
+ }
14856
+ else {
14857
+ if (evt.ctrlKey && evt.keyCode === 67) {
14858
+ copy();
14859
+ }
14860
+ }
14861
+ }
14815
14862
  }
14816
14863
 
14817
14864
  /**
@@ -18104,7 +18151,7 @@ class NodeEvent {
18104
18151
  this.canvas = canvas;
18105
18152
  this.setAppState(null);
18106
18153
  canvas.addEventListener('mousedown', evt => {
18107
- evt.preventDefault();
18154
+ //evt.preventDefault();
18108
18155
  this.setActiveAppContext(() => this.onMousedownHandler(evt));
18109
18156
  });
18110
18157
  canvas.addEventListener('mousemove', evt => {
@@ -18126,6 +18173,9 @@ class NodeEvent {
18126
18173
  canvas.addEventListener('contextmenu', evt => {
18127
18174
  this.setActiveAppContext(() => this.onContextMenuHandler(evt));
18128
18175
  });
18176
+ canvas.addEventListener('keydown', evt => {
18177
+ this.setActiveAppContext(() => this.onKeydownHandler(evt));
18178
+ });
18129
18179
  this.root.addEventListener('preGotFocus', (evt) => {
18130
18180
  this.invokeNodeFocusedEvent(this.prevNode, this.prevFocusNodes, evt.source);
18131
18181
  }, true);
@@ -18422,6 +18472,30 @@ class NodeEvent {
18422
18472
  };
18423
18473
  invokeEvent(onContextMenuEvent, 'contextmenu', this.appState.sourceNode);
18424
18474
  }
18475
+ onCopyHandler(evt) {
18476
+ if (this.appState.sourceNode) {
18477
+ const onCopyEvent = {
18478
+ source: this.appState.sourceNode,
18479
+ cancelable: true,
18480
+ isCancel: false,
18481
+ target: this.appState.sourceNode,
18482
+ sourceEvt: evt
18483
+ };
18484
+ invokeEvent(onCopyEvent, 'copy', this.appState.sourceNode);
18485
+ }
18486
+ }
18487
+ onKeydownHandler(evt) {
18488
+ if (this.appState.sourceNode) {
18489
+ const onKeydownEvent = {
18490
+ source: this.appState.sourceNode,
18491
+ cancelable: true,
18492
+ isCancel: false,
18493
+ target: this.appState.sourceNode,
18494
+ sourceEvt: evt
18495
+ };
18496
+ invokeEvent(onKeydownEvent, 'keydown', this.appState.sourceNode);
18497
+ }
18498
+ }
18425
18499
  getHitNode(hitPos, parentPos) {
18426
18500
  if (this.root.popNodes.length) {
18427
18501
  for (let i = this.root.popNodes.length - 1; i >= 0; i--) {
@@ -20873,6 +20947,13 @@ class CanvasTextEditor extends AbsolutePanel {
20873
20947
  const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
20874
20948
  return ElementSerialize.serializeString(copySerializeStr);
20875
20949
  }
20950
+ /**
20951
+ * 执行编辑器内部复制事件
20952
+ * @param evt
20953
+ */
20954
+ execCopy(evt) {
20955
+ this.documentChange.onCopy(evt);
20956
+ }
20876
20957
  /**
20877
20958
  * 设置纸张方向
20878
20959
  * @param orientation