@hailin-zheng/editor-core 2.0.15 → 2.0.16

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
@@ -2771,6 +2771,7 @@ class DataDecorateElement extends LeafElement {
2771
2771
  }
2772
2772
  }
2773
2773
  });
2774
+ this.disableClick = !isPrefix;
2774
2775
  this.isDecorate = true;
2775
2776
  }
2776
2777
  createRenderObject() {
@@ -3388,7 +3389,6 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3388
3389
  'font-family': '仿宋',
3389
3390
  'font-size': '14',
3390
3391
  "fill": this.element.props.color,
3391
- 'font-style': 'italic',
3392
3392
  x: 0,
3393
3393
  y: 0,
3394
3394
  }
@@ -4279,7 +4279,7 @@ class PSymbolElement extends LeafElement {
4279
4279
  createRenderObject() {
4280
4280
  const symbol = new PSymbolRenderObject(this);
4281
4281
  symbol.rect.height = this.defaultHeight;
4282
- symbol.rect.width = 7;
4282
+ symbol.rect.width = 1;
4283
4283
  return symbol;
4284
4284
  }
4285
4285
  serialize() {
@@ -4828,6 +4828,10 @@ class TextGroupRenderObject extends LeafRenderObject {
4828
4828
  const path = `M${event.relativePagePos.x} ${event.relativePagePos.y} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y}`;
4829
4829
  event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4830
4830
  }
4831
+ //处理null-text
4832
+ if (this.element.isDecorate && this.element.disableClick && !this.element.parent) {
4833
+ t.data.attrs['opacity'] = '0.58';
4834
+ }
4831
4835
  return t;
4832
4836
  }
4833
4837
  }
@@ -5099,10 +5103,7 @@ class SelectionRange {
5099
5103
  }
5100
5104
  setInfo(control, offset) {
5101
5105
  if (control instanceof LeafElement) {
5102
- if (control instanceof TextGroupElement) {
5103
- offset = offset === -1 ? control.text.length : offset;
5104
- }
5105
- offset = offset === -1 ? 1 : offset;
5106
+ offset = ElementUtil.fixedOffset(control, offset);
5106
5107
  return { control, offset };
5107
5108
  }
5108
5109
  else if (control instanceof BranchElement) {
@@ -6301,6 +6302,40 @@ class TableUtil {
6301
6302
  });
6302
6303
  }
6303
6304
  }
6305
+ static getTableData(tb) {
6306
+ //根据实际要提取的行索引进行调整
6307
+ const rowData = [];
6308
+ for (let i = 0; i < tb.length; i++) {
6309
+ const row = tb.getChild(i);
6310
+ const cellData = [];
6311
+ for (let j = 0; j < row.length; j++) {
6312
+ const cell = row.getChild(j);
6313
+ cellData.push(this.getCellData(cell));
6314
+ }
6315
+ rowData.push(cellData);
6316
+ }
6317
+ return rowData;
6318
+ }
6319
+ /**
6320
+ * 获取单元格内的数据元的值
6321
+ * @param target
6322
+ */
6323
+ static getCellData(target) {
6324
+ if (validateDataEle(target)) {
6325
+ const dataEle = target;
6326
+ return { id: dataEle.props.id, value: dataEle.getValue() };
6327
+ }
6328
+ if (target instanceof BranchElement) {
6329
+ for (let i = 0; i < target.length; i++) {
6330
+ const child = target.getChild(i);
6331
+ const val = this.getCellData(child);
6332
+ if (val !== null) {
6333
+ return val;
6334
+ }
6335
+ }
6336
+ }
6337
+ return null;
6338
+ }
6304
6339
  }
6305
6340
 
6306
6341
  class TableElement extends BlockContainerElement {
@@ -8681,6 +8716,46 @@ class ElementUtil {
8681
8716
  ]
8682
8717
  };
8683
8718
  }
8719
+ /**
8720
+ * 判断是否光标可以设置接受编辑
8721
+ * @returns
8722
+ */
8723
+ static canSetCursor(startControl, startOffset, editable, viewOptions) {
8724
+ if (!startControl || !editable) {
8725
+ return false;
8726
+ }
8727
+ if (viewOptions.docMode === exports.DocMode.Design) {
8728
+ return true;
8729
+ }
8730
+ //浏览模式
8731
+ if (viewOptions.docMode === exports.DocMode.View) {
8732
+ return false;
8733
+ }
8734
+ //表单模式下,如果不在数据元素中,则不显示光标
8735
+ if (viewOptions.docMode === exports.DocMode.FormEdit) {
8736
+ if (!IsInSideDataElement(startControl, startOffset)) {
8737
+ return false;
8738
+ }
8739
+ }
8740
+ if (!ElementUtil.verifyHitable(startControl)) {
8741
+ return false;
8742
+ }
8743
+ //表单模式下,数据元不可编辑
8744
+ if (viewOptions.docMode === exports.DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
8745
+ const dataEle = ElementUtil.getDataElement(startControl);
8746
+ if (dataEle && !dataEle.props.editable) {
8747
+ return false;
8748
+ }
8749
+ }
8750
+ return true;
8751
+ }
8752
+ static fixedOffset(control, offset) {
8753
+ if (control instanceof TextGroupElement) {
8754
+ offset = offset === -1 ? control.text.length : offset;
8755
+ }
8756
+ offset = offset === -1 ? 1 : offset;
8757
+ return offset;
8758
+ }
8684
8759
  }
8685
8760
 
8686
8761
  class RenderContext {
@@ -10854,7 +10929,7 @@ class DataElementCheckRenderObject extends LeafRenderObject {
10854
10929
  data: {
10855
10930
  ns: "http://www.w3.org/2000/svg",
10856
10931
  attrs: {
10857
- cx: width / 2,
10932
+ cx: 2 + width / 2,
10858
10933
  cy: height / 2,
10859
10934
  r: width / 3,
10860
10935
  stroke: 'black',
@@ -10869,7 +10944,7 @@ class DataElementCheckRenderObject extends LeafRenderObject {
10869
10944
  data: {
10870
10945
  ns: "http://www.w3.org/2000/svg",
10871
10946
  attrs: {
10872
- cx: width / 2,
10947
+ cx: 2 + width / 2,
10873
10948
  cy: height / 2,
10874
10949
  r: width / 5,
10875
10950
  stroke: 'black',
@@ -17566,7 +17641,6 @@ class DocumentEvent {
17566
17641
  if (resizeColWidth < minColWidth || cellWidth < minColWidth) {
17567
17642
  return;
17568
17643
  }
17569
- console.log(resizeColWidth, cellWidth);
17570
17644
  table.setCellWidth(resizeColIndex, resizeColWidth);
17571
17645
  table.setCellWidth(cellIndex, cellWidth);
17572
17646
  this.edgeRenderInfo.mousedownPos = this.currentPos;
@@ -17740,6 +17814,15 @@ class DocumentEvent {
17740
17814
  */
17741
17815
  moveCursorToLeft() {
17742
17816
  const { startControl, startOffset } = this.selectionState;
17817
+ this.moveCursorToLeftHandle(startControl, startOffset);
17818
+ }
17819
+ /**
17820
+ * 向左移动光标处理函数
17821
+ * @param startControl
17822
+ * @param startOffset
17823
+ * @private
17824
+ */
17825
+ moveCursorToLeftHandle(startControl, startOffset) {
17743
17826
  if (startOffset === 0) {
17744
17827
  const oldRegion = ElementUtil.getElementRegion(startControl);
17745
17828
  const prevEle = ElementUtil.getRecursionPrevSiblingElement(startControl, false, true, this.viewOptions);
@@ -17748,6 +17831,10 @@ class DocumentEvent {
17748
17831
  if (newRegion !== oldRegion) {
17749
17832
  return;
17750
17833
  }
17834
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit && !ElementUtil.canSetCursor(prevEle, ElementUtil.fixedOffset(prevEle, -1), true, this.viewOptions)) {
17835
+ this.moveCursorToLeftHandle(prevEle, 0);
17836
+ return;
17837
+ }
17751
17838
  this.selectionState.resetRange(prevEle, -1);
17752
17839
  return;
17753
17840
  }
@@ -17757,6 +17844,10 @@ class DocumentEvent {
17757
17844
  this.selectionState.resetRange(startControl, startOffset - 1);
17758
17845
  }
17759
17846
  else {
17847
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit && !ElementUtil.canSetCursor(startControl, ElementUtil.fixedOffset(startControl, 0), true, this.viewOptions)) {
17848
+ this.moveCursorToLeftHandle(startControl, 0);
17849
+ return;
17850
+ }
17760
17851
  this.selectionState.resetRange(startControl, 0);
17761
17852
  }
17762
17853
  }
@@ -17766,6 +17857,9 @@ class DocumentEvent {
17766
17857
  */
17767
17858
  moveCursorToRight() {
17768
17859
  const { startControl, startOffset } = this.selectionState;
17860
+ this.moveCursorToRightHandle(startControl, startOffset);
17861
+ }
17862
+ moveCursorToRightHandle(startControl, startOffset) {
17769
17863
  if (this.isLeafEleEndOffset(startControl, startOffset)) {
17770
17864
  const oldRegion = ElementUtil.getElementRegion(startControl);
17771
17865
  const nextEle = ElementUtil.getRecursionNextSiblingElement(startControl, false, true, this.viewOptions);
@@ -17774,7 +17868,11 @@ class DocumentEvent {
17774
17868
  if (oldRegion !== newRegion) {
17775
17869
  return;
17776
17870
  }
17777
- this.selectionState.resetRange(nextEle, 0);
17871
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit && !ElementUtil.canSetCursor(nextEle, ElementUtil.fixedOffset(nextEle, -1), true, this.viewOptions)) {
17872
+ this.moveCursorToRightHandle(nextEle, ElementUtil.fixedOffset(nextEle, -1));
17873
+ return;
17874
+ }
17875
+ this.selectionState.resetRange(nextEle, 1);
17778
17876
  return;
17779
17877
  }
17780
17878
  }
@@ -17783,6 +17881,10 @@ class DocumentEvent {
17783
17881
  this.selectionState.resetRange(startControl, startOffset + 1);
17784
17882
  }
17785
17883
  else {
17884
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit && !ElementUtil.canSetCursor(startControl, 0, true, this.viewOptions)) {
17885
+ this.moveCursorToRightHandle(startControl, ElementUtil.fixedOffset(startControl, -1));
17886
+ return;
17887
+ }
17786
17888
  this.selectionState.resetRange(startControl, 1);
17787
17889
  }
17788
17890
  }
@@ -26968,33 +27070,7 @@ class DocEditor {
26968
27070
  */
26969
27071
  canSetCursor() {
26970
27072
  const { startControl, startOffset, editable } = this.selectionState;
26971
- if (!startControl || !editable) {
26972
- return false;
26973
- }
26974
- if (this.viewOptions.docMode === exports.DocMode.Design) {
26975
- return true;
26976
- }
26977
- //浏览模式
26978
- if (this.viewOptions.docMode === exports.DocMode.View) {
26979
- return false;
26980
- }
26981
- //表单模式下,如果不在数据元素中,则不显示光标
26982
- if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
26983
- if (!IsInSideDataElement(startControl, startOffset)) {
26984
- return false;
26985
- }
26986
- }
26987
- if (!ElementUtil.verifyHitable(startControl)) {
26988
- return false;
26989
- }
26990
- //表单模式下,数据元不可编辑
26991
- if (this.viewOptions.docMode === exports.DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
26992
- const dataEle = ElementUtil.getDataElement(startControl);
26993
- if (dataEle && !dataEle.props.editable) {
26994
- return false;
26995
- }
26996
- }
26997
- return true;
27073
+ return ElementUtil.canSetCursor(startControl, startOffset, editable, this.viewOptions);
26998
27074
  }
26999
27075
  /**
27000
27076
  * 修改光标
@@ -27638,7 +27714,7 @@ class DocEditor {
27638
27714
  const vNodeFunc = this.renderRoot();
27639
27715
  setActiveEditorContext(null);
27640
27716
  const render = () => {
27641
- //console.time('patch');
27717
+ console.time('patch');
27642
27718
  setActiveEditorContext(this);
27643
27719
  const vNode = vNodeFunc.render();
27644
27720
  setActiveEditorContext(null);
@@ -27650,7 +27726,7 @@ class DocEditor {
27650
27726
  this.vNodeDocContent = this.nodePatch(this.svgContainer, vNode);
27651
27727
  }
27652
27728
  this.afterNodePatch.next();
27653
- //console.timeEnd('patch');
27729
+ console.timeEnd('patch');
27654
27730
  };
27655
27731
  render();
27656
27732
  this.onShouldRender.subscribe(() => {