@hailin-zheng/editor-core 1.0.53 → 1.0.54

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
@@ -2741,11 +2741,39 @@ class DataElementRenderObject extends InlineGroupRenderObject {
2741
2741
  }
2742
2742
  if (this.element.props.underline) {
2743
2743
  const y = position.y + 2 + this.rect.height;
2744
- render.contentContext.strokeLines([{ x: position.x, y }, { x: position.x + this.rect.width, y }], 1, '#595959');
2744
+ render.contentContext.strokeLines([{ x: position.x, y }, {
2745
+ x: position.x + this.rect.width,
2746
+ y
2747
+ }], 1, '#595959');
2745
2748
  }
2746
2749
  e.nextRender();
2750
+ this.drawCaption(e);
2747
2751
  });
2748
2752
  }
2753
+ /**
2754
+ * 绘制数据元标题
2755
+ * @param e
2756
+ * @private
2757
+ */
2758
+ drawCaption(e) {
2759
+ const { render, position, docCtx: { viewOptions } } = e;
2760
+ //获取到焦点时,绘制数据元标题
2761
+ if (render.drawMode === 'view' && this.element.isFocused && this.element.paintRenders.indexOf(this) === 0) {
2762
+ const { caption } = this.element.props;
2763
+ if (!caption) {
2764
+ return;
2765
+ }
2766
+ const textProps = new TextProps();
2767
+ textProps.fontSize = 16;
2768
+ textProps.fontName = viewOptions.defaultFontName;
2769
+ textProps.color = '#fff';
2770
+ const titleWidth = render.contentContext.measureText(caption, textProps).width;
2771
+ const x = position.x;
2772
+ const y = position.y - 20;
2773
+ render.contentContext.fillRect(x, y, titleWidth, 20, 'blue');
2774
+ render.contentContext.drawText(caption, textProps, x, y, titleWidth, 20);
2775
+ }
2776
+ }
2749
2777
  }
2750
2778
  const validateDataEle = (ele) => {
2751
2779
  return ele instanceof DataElementLeaf || ele instanceof DataElementInlineGroup;
@@ -6620,6 +6648,11 @@ class DocumentSelection {
6620
6648
  }
6621
6649
  return this.getCommonParenet(control?.parent, array);
6622
6650
  }
6651
+ /**
6652
+ * 更新选区对象
6653
+ * return:当前选区是否改变
6654
+ * @private
6655
+ */
6623
6656
  updateSelectionState() {
6624
6657
  if (this.compareSelectionEquals()) {
6625
6658
  return false;
@@ -6629,17 +6662,6 @@ class DocumentSelection {
6629
6662
  if (!range) {
6630
6663
  return false;
6631
6664
  }
6632
- const startControlIndex = ElementUtil.getControlIndex(range.startControl);
6633
- const endControlIndex = ElementUtil.getControlIndex(range.endControl);
6634
- if (endControlIndex < startControlIndex) {
6635
- const clone = range.clone();
6636
- clone.startControl = range.endControl;
6637
- clone.startOffset = range.endOffset;
6638
- clone.endControl = range.startControl;
6639
- clone.endOffset = range.startOffset;
6640
- clone.editable = range.editable;
6641
- this.selectionState.addRange(clone);
6642
- }
6643
6665
  this.selectionState.editable = range.editable;
6644
6666
  this.selectionState.startControl = range.startControl;
6645
6667
  this.selectionState.startOffset = range.startOffset;
@@ -6764,7 +6786,7 @@ class SelectionState {
6764
6786
  this.cursorPos = null;
6765
6787
  }
6766
6788
  addRange(range) {
6767
- this.clear();
6789
+ //this.clear();
6768
6790
  this.range = range;
6769
6791
  this.onChangedEvent.next();
6770
6792
  }
@@ -12245,6 +12267,9 @@ class DocumentEvent {
12245
12267
  mouseEvent.currentElement = element;
12246
12268
  mouseEvent.ctx = this.docCtx;
12247
12269
  element.invokeEvent(eventName, mouseEvent);
12270
+ if (mouseEvent.isCancel) {
12271
+ break;
12272
+ }
12248
12273
  }
12249
12274
  };
12250
12275
  loopInvokeEvent('LostCursor', leaveParents);
@@ -14292,24 +14317,43 @@ class DocumentChange {
14292
14317
  */
14293
14318
  onPaste(evt) {
14294
14319
  evt.preventDefault();
14295
- let pasteText = evt.clipboardData?.getData('text/plain');
14296
- const pasteData = evt.clipboardData?.getData('doc/plain');
14297
- if (!pasteData) {
14298
- if (pasteText) {
14299
- this.pastePlainText(pasteText);
14320
+ let pasteText = evt.clipboardData?.getData('text/plain') ?? '';
14321
+ const pasteData = evt.clipboardData?.getData('doc/plain') ?? '';
14322
+ const { collapsed } = this.selectionState;
14323
+ if (!collapsed) {
14324
+ //TODO:如果一个容器内的元素被全部删除,则返回 null
14325
+ // const { cursorEle, cursorOffset } = this.onRangeDelete();
14326
+ // startControl = cursorEle;
14327
+ // startOffset = cursorOffset;
14328
+ this.onRangeDelete();
14329
+ const cb = () => {
14330
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14331
+ };
14332
+ this.docCtx.setPaintedCallback(cb);
14333
+ return;
14334
+ }
14335
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14336
+ }
14337
+ /**
14338
+ * 处理粘贴的内容
14339
+ * @private
14340
+ */
14341
+ handlePasteContent(pasteData, ss) {
14342
+ const { startOffset, startControl, editable } = ss;
14343
+ if (!startControl || !editable) {
14344
+ return;
14345
+ }
14346
+ if (!pasteData.doc) {
14347
+ if (pasteData.text) {
14348
+ this.pastePlainText(pasteData.text);
14300
14349
  }
14301
14350
  return;
14302
14351
  }
14303
- const pasteElement = this.eleReader.readElement(JSON.parse(pasteData));
14352
+ const pasteElement = this.eleReader.readElement(JSON.parse(pasteData.doc));
14304
14353
  if (!pasteElement) {
14305
14354
  console.log('粘贴反序列化数据失败', pasteData);
14306
14355
  return;
14307
14356
  }
14308
- this.selectionState;
14309
- let { startControl, startOffset } = this.selectionState;
14310
- if (!startControl) {
14311
- return;
14312
- }
14313
14357
  //表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
14314
14358
  if (this.viewOptions.docMode === DocMode.FormEdit) {
14315
14359
  const pasteString = ElementSerialize.serializeString(pasteElement, { all: false });
@@ -14340,7 +14384,6 @@ class DocumentChange {
14340
14384
  this.selectionState.resetRange(lastEle, -1);
14341
14385
  return;
14342
14386
  }
14343
- console.log('粘贴:' + pasteData);
14344
14387
  }
14345
14388
  insertSoftBr() {
14346
14389
  let { startControl, startOffset } = this.selectionState;