@hailin-zheng/editor-core 1.1.10 → 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;
@@ -9741,6 +9759,7 @@ class SelectionState {
9741
9759
  selectedRange;
9742
9760
  editable = true;
9743
9761
  renderContainer;
9762
+ //光标所在的位置,当前位置时相对文档的位置,而非DOM页面中的位置
9744
9763
  cursorPos;
9745
9764
  //当前选区的上下文是否支持留痕修改
9746
9765
  enableTrackChanges = false;
@@ -11763,8 +11782,7 @@ class DocumentArrange {
11763
11782
  item.rect.y = bodyInnerLimitRect.height + item.margin.top;
11764
11783
  pageBodyRender.addChild(item);
11765
11784
  bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
11766
- //上一个元素的bottom-margin
11767
- //bodyInnerLimitRect.prevMargin = item.margin.bottom;
11785
+ ElementUtil.setHorizontalAlign(item, bodyInnerLimitRect);
11768
11786
  ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
11769
11787
  };
11770
11788
  for (let i = 0; i < doc.bodyElement.length; i++) {
@@ -13725,6 +13743,9 @@ class DocumentEvent {
13725
13743
  this.editor.addEventListener('contextmenu', evt => {
13726
13744
  this.contextMenu.next(evt.sourceEvt);
13727
13745
  });
13746
+ this.editor.addEventListener('keydown', evt => {
13747
+ this.onKeydown(evt.sourceEvt);
13748
+ });
13728
13749
  this.documentInput.onLeftEvent.subscribe(() => {
13729
13750
  this.moveCursorToLeft();
13730
13751
  });
@@ -14158,6 +14179,10 @@ class DocumentEvent {
14158
14179
  mouseDblClickHandle(nodeEvt) {
14159
14180
  const docEvent = new MouseElementEvent(this.docCtx);
14160
14181
  this.setEventViewPos(nodeEvt.sourceHitPos, docEvent);
14182
+ const hitInfo = this.getHitInfo(docEvent);
14183
+ if (!hitInfo) {
14184
+ return;
14185
+ }
14161
14186
  //需要先处理是否开启页眉页脚编辑功能
14162
14187
  const hitRegion = this.getHitRegion(docEvent);
14163
14188
  if ((hitRegion === 'footer' || hitRegion === 'header') && !this.docCtx.document.headerEditState) {
@@ -14168,7 +14193,7 @@ class DocumentEvent {
14168
14193
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
14169
14194
  return;
14170
14195
  }
14171
- const hitInfo = this.getHitInfo(docEvent);
14196
+ //const hitInfo = this.getHitInfo(docEvent);
14172
14197
  if (hitInfo) {
14173
14198
  docEvent.source = hitInfo.element;
14174
14199
  docEvent.sourceRender = hitInfo.render;
@@ -14737,7 +14762,7 @@ class DocumentEvent {
14737
14762
  return;
14738
14763
  }
14739
14764
  let { x, y } = this.selectionState.cursorPos;
14740
- y -= this.viewOptions.pageOffset.y;
14765
+ //y -= this.viewOptions.pageOffset.y;
14741
14766
  for (let i = 0; i < 50; i++) {
14742
14767
  const docEvent = new MouseElementEvent(this.docCtx);
14743
14768
  docEvent.globalX = x;
@@ -14778,9 +14803,8 @@ class DocumentEvent {
14778
14803
  }
14779
14804
  /**
14780
14805
  * 获取点击的文档区域
14781
- * @param docRender
14782
- * @param pos
14783
14806
  * @returns
14807
+ * @param docEvent
14784
14808
  */
14785
14809
  getHitRegion(docEvent) {
14786
14810
  const hitDocInfo = this.getHitDocPage(docEvent);
@@ -14811,6 +14835,30 @@ class DocumentEvent {
14811
14835
  return null;
14812
14836
  }
14813
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
+ }
14814
14862
  }
14815
14863
 
14816
14864
  /**
@@ -14922,7 +14970,6 @@ class DocumentInput {
14922
14970
  * @param visibility
14923
14971
  */
14924
14972
  setCursorVisibility(visibility) {
14925
- //this.cursorWrapper.style.display = visibility ? 'block' : 'none';
14926
14973
  if (visibility) {
14927
14974
  this.setInputFocus(true);
14928
14975
  }
@@ -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--) {
@@ -20416,8 +20490,6 @@ class CanvasTextEditor extends AbsolutePanel {
20416
20490
  const { startRegion, hitDocIndex } = this.documentEvent.startHitInfo;
20417
20491
  const cursorPos = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
20418
20492
  this.docCtx.cursorRect = ElementUtil.cloneRect(cursorPos.rect);
20419
- this.transToAbsolutePos(ElementUtil.cloneRect(cursorPos.rect));
20420
- //this.documentInput.setCursorPosition(abPos);
20421
20493
  const focusEvent = {
20422
20494
  target: this,
20423
20495
  source: this,
@@ -20875,6 +20947,13 @@ class CanvasTextEditor extends AbsolutePanel {
20875
20947
  const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
20876
20948
  return ElementSerialize.serializeString(copySerializeStr);
20877
20949
  }
20950
+ /**
20951
+ * 执行编辑器内部复制事件
20952
+ * @param evt
20953
+ */
20954
+ execCopy(evt) {
20955
+ this.documentChange.onCopy(evt);
20956
+ }
20878
20957
  /**
20879
20958
  * 设置纸张方向
20880
20959
  * @param orientation
@@ -21174,11 +21253,12 @@ class CanvasTextEditor extends AbsolutePanel {
21174
21253
  drawCaret(e) {
21175
21254
  const appCtx = getCurrentActiveAppContext();
21176
21255
  if (appCtx) {
21177
- const caretPos = this.selectionState.cursorPos;
21256
+ let caretPos = this.selectionState.cursorPos;
21178
21257
  if (!caretPos) {
21179
21258
  appCtx.root.hiddenInput();
21180
21259
  return;
21181
21260
  }
21261
+ caretPos = ElementUtil.cloneRect(caretPos);
21182
21262
  caretPos.x += this.border + this.padding + e.renderPos.x;
21183
21263
  caretPos.y += this.border + this.padding + e.renderPos.y;
21184
21264
  appCtx.root.setInputPosition(caretPos);