@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-cjs.js CHANGED
@@ -2750,11 +2750,39 @@ class DataElementRenderObject extends InlineGroupRenderObject {
2750
2750
  }
2751
2751
  if (this.element.props.underline) {
2752
2752
  const y = position.y + 2 + this.rect.height;
2753
- render.contentContext.strokeLines([{ x: position.x, y }, { x: position.x + this.rect.width, y }], 1, '#595959');
2753
+ render.contentContext.strokeLines([{ x: position.x, y }, {
2754
+ x: position.x + this.rect.width,
2755
+ y
2756
+ }], 1, '#595959');
2754
2757
  }
2755
2758
  e.nextRender();
2759
+ this.drawCaption(e);
2756
2760
  });
2757
2761
  }
2762
+ /**
2763
+ * 绘制数据元标题
2764
+ * @param e
2765
+ * @private
2766
+ */
2767
+ drawCaption(e) {
2768
+ const { render, position, docCtx: { viewOptions } } = e;
2769
+ //获取到焦点时,绘制数据元标题
2770
+ if (render.drawMode === 'view' && this.element.isFocused && this.element.paintRenders.indexOf(this) === 0) {
2771
+ const { caption } = this.element.props;
2772
+ if (!caption) {
2773
+ return;
2774
+ }
2775
+ const textProps = new TextProps();
2776
+ textProps.fontSize = 16;
2777
+ textProps.fontName = viewOptions.defaultFontName;
2778
+ textProps.color = '#fff';
2779
+ const titleWidth = render.contentContext.measureText(caption, textProps).width;
2780
+ const x = position.x;
2781
+ const y = position.y - 20;
2782
+ render.contentContext.fillRect(x, y, titleWidth, 20, 'blue');
2783
+ render.contentContext.drawText(caption, textProps, x, y, titleWidth, 20);
2784
+ }
2785
+ }
2758
2786
  }
2759
2787
  const validateDataEle = (ele) => {
2760
2788
  return ele instanceof DataElementLeaf || ele instanceof DataElementInlineGroup;
@@ -6629,6 +6657,11 @@ class DocumentSelection {
6629
6657
  }
6630
6658
  return this.getCommonParenet(control?.parent, array);
6631
6659
  }
6660
+ /**
6661
+ * 更新选区对象
6662
+ * return:当前选区是否改变
6663
+ * @private
6664
+ */
6632
6665
  updateSelectionState() {
6633
6666
  if (this.compareSelectionEquals()) {
6634
6667
  return false;
@@ -6638,17 +6671,6 @@ class DocumentSelection {
6638
6671
  if (!range) {
6639
6672
  return false;
6640
6673
  }
6641
- const startControlIndex = ElementUtil.getControlIndex(range.startControl);
6642
- const endControlIndex = ElementUtil.getControlIndex(range.endControl);
6643
- if (endControlIndex < startControlIndex) {
6644
- const clone = range.clone();
6645
- clone.startControl = range.endControl;
6646
- clone.startOffset = range.endOffset;
6647
- clone.endControl = range.startControl;
6648
- clone.endOffset = range.startOffset;
6649
- clone.editable = range.editable;
6650
- this.selectionState.addRange(clone);
6651
- }
6652
6674
  this.selectionState.editable = range.editable;
6653
6675
  this.selectionState.startControl = range.startControl;
6654
6676
  this.selectionState.startOffset = range.startOffset;
@@ -6773,7 +6795,7 @@ class SelectionState {
6773
6795
  this.cursorPos = null;
6774
6796
  }
6775
6797
  addRange(range) {
6776
- this.clear();
6798
+ //this.clear();
6777
6799
  this.range = range;
6778
6800
  this.onChangedEvent.next();
6779
6801
  }
@@ -12254,6 +12276,9 @@ class DocumentEvent {
12254
12276
  mouseEvent.currentElement = element;
12255
12277
  mouseEvent.ctx = this.docCtx;
12256
12278
  element.invokeEvent(eventName, mouseEvent);
12279
+ if (mouseEvent.isCancel) {
12280
+ break;
12281
+ }
12257
12282
  }
12258
12283
  };
12259
12284
  loopInvokeEvent('LostCursor', leaveParents);
@@ -14301,24 +14326,43 @@ class DocumentChange {
14301
14326
  */
14302
14327
  onPaste(evt) {
14303
14328
  evt.preventDefault();
14304
- let pasteText = evt.clipboardData?.getData('text/plain');
14305
- const pasteData = evt.clipboardData?.getData('doc/plain');
14306
- if (!pasteData) {
14307
- if (pasteText) {
14308
- this.pastePlainText(pasteText);
14329
+ let pasteText = evt.clipboardData?.getData('text/plain') ?? '';
14330
+ const pasteData = evt.clipboardData?.getData('doc/plain') ?? '';
14331
+ const { collapsed } = this.selectionState;
14332
+ if (!collapsed) {
14333
+ //TODO:如果一个容器内的元素被全部删除,则返回 null
14334
+ // const { cursorEle, cursorOffset } = this.onRangeDelete();
14335
+ // startControl = cursorEle;
14336
+ // startOffset = cursorOffset;
14337
+ this.onRangeDelete();
14338
+ const cb = () => {
14339
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14340
+ };
14341
+ this.docCtx.setPaintedCallback(cb);
14342
+ return;
14343
+ }
14344
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14345
+ }
14346
+ /**
14347
+ * 处理粘贴的内容
14348
+ * @private
14349
+ */
14350
+ handlePasteContent(pasteData, ss) {
14351
+ const { startOffset, startControl, editable } = ss;
14352
+ if (!startControl || !editable) {
14353
+ return;
14354
+ }
14355
+ if (!pasteData.doc) {
14356
+ if (pasteData.text) {
14357
+ this.pastePlainText(pasteData.text);
14309
14358
  }
14310
14359
  return;
14311
14360
  }
14312
- const pasteElement = this.eleReader.readElement(JSON.parse(pasteData));
14361
+ const pasteElement = this.eleReader.readElement(JSON.parse(pasteData.doc));
14313
14362
  if (!pasteElement) {
14314
14363
  console.log('粘贴反序列化数据失败', pasteData);
14315
14364
  return;
14316
14365
  }
14317
- this.selectionState;
14318
- let { startControl, startOffset } = this.selectionState;
14319
- if (!startControl) {
14320
- return;
14321
- }
14322
14366
  //表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
14323
14367
  if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
14324
14368
  const pasteString = ElementSerialize.serializeString(pasteElement, { all: false });
@@ -14349,7 +14393,6 @@ class DocumentChange {
14349
14393
  this.selectionState.resetRange(lastEle, -1);
14350
14394
  return;
14351
14395
  }
14352
- console.log('粘贴:' + pasteData);
14353
14396
  }
14354
14397
  insertSoftBr() {
14355
14398
  let { startControl, startOffset } = this.selectionState;