@hailin-zheng/editor-core 2.0.28 → 2.0.30

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
@@ -643,6 +643,15 @@ class CommonUtil {
643
643
  ele.removeChild(ele.firstChild);
644
644
  }
645
645
  }
646
+ static findParent(curr, predicate) {
647
+ if (!curr) {
648
+ return null;
649
+ }
650
+ if (predicate(curr)) {
651
+ return curr;
652
+ }
653
+ return this.findParent(curr.parentElement, predicate);
654
+ }
646
655
  }
647
656
 
648
657
  const docOpsMap = new Map();
@@ -2364,7 +2373,7 @@ class DataEleCheckProps extends DataEleBaseProps {
2364
2373
  if (this.falseChar !== falseChar) {
2365
2374
  props.falseChar = this.falseChar;
2366
2375
  }
2367
- if (this.border) {
2376
+ if (!this.border) {
2368
2377
  props.border = this.border;
2369
2378
  }
2370
2379
  if (this.trueStateColor !== '#f00000') {
@@ -8447,17 +8456,17 @@ class DataElementCheckRenderObject extends LeafRenderObject {
8447
8456
  const style = props.style;
8448
8457
  if (props.multiSelect) {
8449
8458
  style === 'RadioButton' ? this.drawCircleCheckbox(t, width, height, props.checked)
8450
- : this.drawRectCheckbox(t, width, height, props.size, props.checked);
8459
+ : this.drawRectCheckbox(t, width, height, props.size, props.checked, props.border);
8451
8460
  }
8452
8461
  else {
8453
- style === 'CheckBox' ? this.drawRectCheckbox(t, width, height, props.size, props.checked)
8462
+ style === 'CheckBox' ? this.drawRectCheckbox(t, width, height, props.size, props.checked, props.border)
8454
8463
  : this.drawCircleCheckbox(t, width, height, props.checked);
8455
8464
  }
8456
8465
  }
8457
8466
  return t;
8458
8467
  }
8459
- drawRectCheckbox(t, width, height, size, checked) {
8460
- t.children.push({
8468
+ drawRectCheckbox(t, width, height, size, checked, border) {
8469
+ border && t.children.push({
8461
8470
  sel: 'rect',
8462
8471
  data: {
8463
8472
  ns: "http://www.w3.org/2000/svg",
@@ -12374,14 +12383,14 @@ class ElementUtil {
12374
12383
  }
12375
12384
  };
12376
12385
  }
12377
- static getMousePos(e) {
12386
+ static getMousePos(e, scale = 1) {
12378
12387
  const svgContainer = e.currentTarget;
12379
12388
  const parentRect = svgContainer.getBoundingClientRect();
12380
12389
  const localX = e.clientX - parentRect.x; //+ this.viewOptions.pageOffset.x;
12381
12390
  const localY = e.clientY - parentRect.y; //+ this.viewOptions.pageOffset.y;
12382
12391
  return {
12383
- x: localX,
12384
- y: localY
12392
+ x: localX / scale,
12393
+ y: localY / scale
12385
12394
  };
12386
12395
  }
12387
12396
  static createClipPath(id, width, height, x = 0, y = 0) {
@@ -16120,8 +16129,8 @@ class DocumentPaint {
16120
16129
  getDocumentContainerHeight() {
16121
16130
  if (this.docPages.length > 0) {
16122
16131
  return {
16123
- width: this.docContainer.rect.width * this.viewOptions.scale,
16124
- height: this.docContainer.rect.height * this.viewOptions.scale
16132
+ width: this.docContainer.rect.width,
16133
+ height: this.docContainer.rect.height
16125
16134
  };
16126
16135
  }
16127
16136
  else {
@@ -16877,21 +16886,22 @@ class DocumentEvent {
16877
16886
  this.bindEvent();
16878
16887
  }
16879
16888
  getEventListener() {
16889
+ const scale = this.viewOptions.scale;
16880
16890
  return {
16881
16891
  mousedown: (evt) => {
16882
- this.mousedown(evt, ElementUtil.getMousePos(evt));
16892
+ this.mousedown(evt, ElementUtil.getMousePos(evt, scale));
16883
16893
  },
16884
16894
  mouseup: (evt) => {
16885
- this.mouseup(evt, ElementUtil.getMousePos(evt));
16895
+ this.mouseup(evt, ElementUtil.getMousePos(evt, scale));
16886
16896
  },
16887
16897
  click: (evt) => {
16888
16898
  this.mouseClickHandle(evt);
16889
16899
  },
16890
16900
  mousemove: (evt) => {
16891
- this.mousemove(evt, ElementUtil.getMousePos(evt));
16901
+ this.mousemove(evt, ElementUtil.getMousePos(evt, scale));
16892
16902
  },
16893
16903
  dblclick: (evt) => {
16894
- this.mouseDblClickHandle(evt, ElementUtil.getMousePos(evt));
16904
+ this.mouseDblClickHandle(evt, ElementUtil.getMousePos(evt, scale));
16895
16905
  },
16896
16906
  contextmenu: (evt) => {
16897
16907
  this.contextMenu.next(evt);
@@ -19971,11 +19981,10 @@ function createPrintTemplate({ width, height, orient }) {
19971
19981
  @page {
19972
19982
  size: ${orient};
19973
19983
  margin: 0;
19974
- padding: 0;
19975
19984
  }
19976
19985
  div {
19977
19986
  width: ${width}mm;
19978
- height: ${height}mm;
19987
+ min-height: ${height}mm;
19979
19988
  font-size: 0;
19980
19989
  }
19981
19990
  @media print {
@@ -19983,7 +19992,6 @@ function createPrintTemplate({ width, height, orient }) {
19983
19992
  body {
19984
19993
  width: ${width}mm;
19985
19994
  height: ${height}mm;
19986
- margin: 0;
19987
19995
  }
19988
19996
  div {
19989
19997
  width: initial;
@@ -26134,14 +26142,36 @@ class EditorCalendarVNode {
26134
26142
  style: {
26135
26143
  position: 'absolute',
26136
26144
  left: (position.x - 10) + 'px',
26137
- top: position.y + 'px',
26145
+ top: position.y + 5 + position.height + 'px',
26138
26146
  'min-width': '100px',
26139
26147
  'background-color': 'white',
26140
26148
  'z-index': '1000',
26141
26149
  'border-radius': '5px',
26142
26150
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
26143
26151
  'user-select': 'none',
26144
- }
26152
+ },
26153
+ hook: {
26154
+ insert: (vnode) => {
26155
+ const elm = vnode.elm;
26156
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26157
+ if (parent) {
26158
+ const parentRect = parent.getBoundingClientRect();
26159
+ const elmRect = elm.getBoundingClientRect();
26160
+ if (elmRect.top < parentRect.top) {
26161
+ elm.style.top = (position.y - elmRect.height) + 'px';
26162
+ }
26163
+ if (elmRect.left < parentRect.left) {
26164
+ elm.style.left = (position.x - 10) + 'px';
26165
+ }
26166
+ if (elmRect.right > parentRect.right) {
26167
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
26168
+ }
26169
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26170
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26171
+ }
26172
+ }
26173
+ }
26174
+ },
26145
26175
  },
26146
26176
  children: []
26147
26177
  };
@@ -27027,7 +27057,15 @@ class DocEditor {
27027
27057
  }
27028
27058
  },
27029
27059
  children: [
27030
- docContentVNode, inputVNode, dropContainer
27060
+ {
27061
+ sel: 'div.scale-container', data: {
27062
+ style: {
27063
+ transform: 'scale(' + this.viewOptions.scale + ')',
27064
+ transformOrigin: 'left top'
27065
+ }
27066
+ },
27067
+ children: [docContentVNode, inputVNode, dropContainer]
27068
+ }
27031
27069
  ]
27032
27070
  }, ruleFunc.refreshRuleSvg().render()
27033
27071
  ]
@@ -27314,14 +27352,14 @@ class DocEditor {
27314
27352
  const startDecorateRender = element.paintRenders[0];
27315
27353
  if (!startDecorateRender) {
27316
27354
  console.error('未找到数据元开始渲染元素');
27317
- return;
27355
+ return null;
27318
27356
  }
27319
27357
  const { x, height, y, width } = startDecorateRender.rect;
27320
27358
  const pos = ElementUtil.getRenderAbsolutePaintPos(startDecorateRender);
27321
27359
  return {
27322
27360
  x: pos.x + width,
27323
- y: pos.y + height + 5,
27324
- translateY: this.viewOptions.pageOffset.y
27361
+ y: pos.y,
27362
+ height
27325
27363
  };
27326
27364
  }
27327
27365
  /**
@@ -27392,6 +27430,11 @@ class DocEditor {
27392
27430
  this.updateRenderCtx();
27393
27431
  this.flushToSchedule();
27394
27432
  this.documentPaint.layoutPages();
27433
+ const sub = this.afterNodePatch.subscribe(() => {
27434
+ sub.unsubscribe();
27435
+ const scrollDOM = this.svgContainer.querySelector('.scroll-container');
27436
+ scrollDOM.scrollLeft = (scrollDOM.scrollWidth - scrollDOM.getBoundingClientRect().width) / 2;
27437
+ });
27395
27438
  return scale;
27396
27439
  }
27397
27440
  updateRenderCtx() {
@@ -28083,14 +28126,36 @@ class DocEditor {
28083
28126
  style: {
28084
28127
  position: 'absolute',
28085
28128
  left: (position.x - 10) + 'px',
28086
- top: position.y + 'px',
28129
+ top: position.y + 5 + position.height + 'px',
28087
28130
  'min-width': '100px',
28088
28131
  'background-color': 'white',
28089
28132
  'z-index': '1000',
28090
28133
  'border-radius': '5px',
28091
28134
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
28092
28135
  'user-select': 'none',
28093
- }
28136
+ },
28137
+ hook: {
28138
+ insert: (vnode) => {
28139
+ const elm = vnode.elm;
28140
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28141
+ if (parent) {
28142
+ const parentRect = parent.getBoundingClientRect();
28143
+ const elmRect = elm.getBoundingClientRect();
28144
+ if (elmRect.top < parentRect.top) {
28145
+ elm.style.top = (position.y - elmRect.height) + 'px';
28146
+ }
28147
+ if (elmRect.left < parentRect.left) {
28148
+ elm.style.left = (position.x - 10) + 'px';
28149
+ }
28150
+ if (elmRect.right > parentRect.right) {
28151
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
28152
+ }
28153
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28154
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28155
+ }
28156
+ }
28157
+ }
28158
+ },
28094
28159
  },
28095
28160
  children: [
28096
28161
  {