@hailin-zheng/editor-core 1.0.53 → 1.0.56

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 + 10, 20, 'blue');
2783
+ render.contentContext.drawText(caption, textProps, x + 5, y, titleWidth, 20);
2784
+ }
2785
+ }
2758
2786
  }
2759
2787
  const validateDataEle = (ele) => {
2760
2788
  return ele instanceof DataElementLeaf || ele instanceof DataElementInlineGroup;
@@ -6599,8 +6627,8 @@ class DocumentSelection {
6599
6627
  this.selectionState.addRange(startRange);
6600
6628
  }
6601
6629
  /**
6602
- * 获取选区共同的祖先控件
6603
- */
6630
+ * 获取选区共同的祖先控件
6631
+ */
6604
6632
  static getAncestorCommonControl(startControl, endControl) {
6605
6633
  const startNestParents = this.getNestParents(startControl.parent);
6606
6634
  const ancestorCommonControl = this.getCommonParenet(endControl.parent, startNestParents);
@@ -6629,26 +6657,22 @@ 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
- if (this.compareSelectionEquals()) {
6666
+ if (!this.selectionState.rangeDirty) {
6634
6667
  return false;
6635
6668
  }
6636
6669
  const range = this.selectionState.range;
6670
+ //转换选区
6637
6671
  this.transformRange();
6672
+ this.selectionState.clear();
6638
6673
  if (!range) {
6639
6674
  return false;
6640
6675
  }
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
6676
  this.selectionState.editable = range.editable;
6653
6677
  this.selectionState.startControl = range.startControl;
6654
6678
  this.selectionState.startOffset = range.startOffset;
@@ -6658,6 +6682,7 @@ class DocumentSelection {
6658
6682
  this.selectionState.endControlIndex = ElementUtil.getControlIndex(range.endControl);
6659
6683
  this.selectionState.ancestorCommonControl = DocumentSelection.getAncestorCommonControl(this.selectionState.startControl, this.selectionState.endControl);
6660
6684
  this.selectionState.enableTrackChanges = this.getEnableTrackChanges(range.startControl);
6685
+ this.selectionState.rangeDirty = false;
6661
6686
  return true;
6662
6687
  }
6663
6688
  /**
@@ -6668,17 +6693,6 @@ class DocumentSelection {
6668
6693
  const body = ElementUtil.getParentByType(ele, DocumentBodyElement);
6669
6694
  return body?.trackChanges || false;
6670
6695
  }
6671
- compareSelectionEquals() {
6672
- const range = this.selectionState.range;
6673
- const snap = this.snapshotSelectionState;
6674
- if (snap && range) {
6675
- return range.startControl === snap.startControl
6676
- && range.startOffset === snap.startOffset
6677
- && range.endControl === snap.endControl
6678
- && range.endOffset === snap.endOffset;
6679
- }
6680
- return false;
6681
- }
6682
6696
  /**
6683
6697
  * 转换选区内容
6684
6698
  * 处理结束选区在开始选区之前
@@ -6772,9 +6786,14 @@ class SelectionState {
6772
6786
  this.selectedRange = null;
6773
6787
  this.cursorPos = null;
6774
6788
  }
6789
+ /**
6790
+ * 当前选区是否发生改变
6791
+ */
6792
+ rangeDirty = false;
6775
6793
  addRange(range) {
6776
6794
  this.clear();
6777
6795
  this.range = range;
6796
+ this.rangeDirty = true;
6778
6797
  this.onChangedEvent.next();
6779
6798
  }
6780
6799
  resetRange(startControl, startOffset) {
@@ -12247,6 +12266,7 @@ class DocumentEvent {
12247
12266
  const newParents = ElementUtil.getParentElements(focusElement);
12248
12267
  const leaveParents = oldParents.filter(item => newParents.every(oldItem => item !== oldItem));
12249
12268
  const enterParents = newParents.filter(item => oldParents.every(oldItem => item !== oldItem));
12269
+ let cancelEvent = false;
12250
12270
  const loopInvokeEvent = (eventName, array) => {
12251
12271
  for (const element of array) {
12252
12272
  const mouseEvent = new LostCursorEvent(this.docCtx);
@@ -12254,11 +12274,17 @@ class DocumentEvent {
12254
12274
  mouseEvent.currentElement = element;
12255
12275
  mouseEvent.ctx = this.docCtx;
12256
12276
  element.invokeEvent(eventName, mouseEvent);
12277
+ if (mouseEvent.isCancel) {
12278
+ cancelEvent = true;
12279
+ break;
12280
+ }
12257
12281
  }
12258
12282
  };
12259
12283
  loopInvokeEvent('LostCursor', leaveParents);
12260
12284
  loopInvokeEvent('GotCursor', enterParents);
12261
- this.prevCursorItems = newParents;
12285
+ if (!cancelEvent) {
12286
+ this.prevCursorItems = newParents;
12287
+ }
12262
12288
  //dDocumentEvent.invokeEvent('GotCursor', focusElement, getCursorEvent, 'All', this.docCtx);
12263
12289
  }
12264
12290
  /**
@@ -14301,24 +14327,43 @@ class DocumentChange {
14301
14327
  */
14302
14328
  onPaste(evt) {
14303
14329
  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);
14330
+ let pasteText = evt.clipboardData?.getData('text/plain') ?? '';
14331
+ const pasteData = evt.clipboardData?.getData('doc/plain') ?? '';
14332
+ const { collapsed } = this.selectionState;
14333
+ if (!collapsed) {
14334
+ //TODO:如果一个容器内的元素被全部删除,则返回 null
14335
+ // const { cursorEle, cursorOffset } = this.onRangeDelete();
14336
+ // startControl = cursorEle;
14337
+ // startOffset = cursorOffset;
14338
+ this.onRangeDelete();
14339
+ const cb = () => {
14340
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14341
+ };
14342
+ this.docCtx.setPaintedCallback(cb);
14343
+ return;
14344
+ }
14345
+ this.handlePasteContent({ text: pasteText, doc: pasteData }, this.selectionState);
14346
+ }
14347
+ /**
14348
+ * 处理粘贴的内容
14349
+ * @private
14350
+ */
14351
+ handlePasteContent(pasteData, ss) {
14352
+ const { startOffset, startControl, editable } = ss;
14353
+ if (!startControl || !editable) {
14354
+ return;
14355
+ }
14356
+ if (!pasteData.doc) {
14357
+ if (pasteData.text) {
14358
+ this.pastePlainText(pasteData.text);
14309
14359
  }
14310
14360
  return;
14311
14361
  }
14312
- const pasteElement = this.eleReader.readElement(JSON.parse(pasteData));
14362
+ const pasteElement = this.eleReader.readElement(JSON.parse(pasteData.doc));
14313
14363
  if (!pasteElement) {
14314
14364
  console.log('粘贴反序列化数据失败', pasteData);
14315
14365
  return;
14316
14366
  }
14317
- this.selectionState;
14318
- let { startControl, startOffset } = this.selectionState;
14319
- if (!startControl) {
14320
- return;
14321
- }
14322
14367
  //表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
14323
14368
  if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
14324
14369
  const pasteString = ElementSerialize.serializeString(pasteElement, { all: false });
@@ -14349,7 +14394,6 @@ class DocumentChange {
14349
14394
  this.selectionState.resetRange(lastEle, -1);
14350
14395
  return;
14351
14396
  }
14352
- console.log('粘贴:' + pasteData);
14353
14397
  }
14354
14398
  insertSoftBr() {
14355
14399
  let { startControl, startOffset } = this.selectionState;