@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-cjs.js CHANGED
@@ -673,6 +673,15 @@ class CommonUtil {
673
673
  ele.removeChild(ele.firstChild);
674
674
  }
675
675
  }
676
+ static findParent(curr, predicate) {
677
+ if (!curr) {
678
+ return null;
679
+ }
680
+ if (predicate(curr)) {
681
+ return curr;
682
+ }
683
+ return this.findParent(curr.parentElement, predicate);
684
+ }
676
685
  }
677
686
 
678
687
  const docOpsMap = new Map();
@@ -2394,7 +2403,7 @@ class DataEleCheckProps extends DataEleBaseProps {
2394
2403
  if (this.falseChar !== falseChar) {
2395
2404
  props.falseChar = this.falseChar;
2396
2405
  }
2397
- if (this.border) {
2406
+ if (!this.border) {
2398
2407
  props.border = this.border;
2399
2408
  }
2400
2409
  if (this.trueStateColor !== '#f00000') {
@@ -8477,17 +8486,17 @@ class DataElementCheckRenderObject extends LeafRenderObject {
8477
8486
  const style = props.style;
8478
8487
  if (props.multiSelect) {
8479
8488
  style === 'RadioButton' ? this.drawCircleCheckbox(t, width, height, props.checked)
8480
- : this.drawRectCheckbox(t, width, height, props.size, props.checked);
8489
+ : this.drawRectCheckbox(t, width, height, props.size, props.checked, props.border);
8481
8490
  }
8482
8491
  else {
8483
- style === 'CheckBox' ? this.drawRectCheckbox(t, width, height, props.size, props.checked)
8492
+ style === 'CheckBox' ? this.drawRectCheckbox(t, width, height, props.size, props.checked, props.border)
8484
8493
  : this.drawCircleCheckbox(t, width, height, props.checked);
8485
8494
  }
8486
8495
  }
8487
8496
  return t;
8488
8497
  }
8489
- drawRectCheckbox(t, width, height, size, checked) {
8490
- t.children.push({
8498
+ drawRectCheckbox(t, width, height, size, checked, border) {
8499
+ border && t.children.push({
8491
8500
  sel: 'rect',
8492
8501
  data: {
8493
8502
  ns: "http://www.w3.org/2000/svg",
@@ -12404,14 +12413,14 @@ class ElementUtil {
12404
12413
  }
12405
12414
  };
12406
12415
  }
12407
- static getMousePos(e) {
12416
+ static getMousePos(e, scale = 1) {
12408
12417
  const svgContainer = e.currentTarget;
12409
12418
  const parentRect = svgContainer.getBoundingClientRect();
12410
12419
  const localX = e.clientX - parentRect.x; //+ this.viewOptions.pageOffset.x;
12411
12420
  const localY = e.clientY - parentRect.y; //+ this.viewOptions.pageOffset.y;
12412
12421
  return {
12413
- x: localX,
12414
- y: localY
12422
+ x: localX / scale,
12423
+ y: localY / scale
12415
12424
  };
12416
12425
  }
12417
12426
  static createClipPath(id, width, height, x = 0, y = 0) {
@@ -16150,8 +16159,8 @@ class DocumentPaint {
16150
16159
  getDocumentContainerHeight() {
16151
16160
  if (this.docPages.length > 0) {
16152
16161
  return {
16153
- width: this.docContainer.rect.width * this.viewOptions.scale,
16154
- height: this.docContainer.rect.height * this.viewOptions.scale
16162
+ width: this.docContainer.rect.width,
16163
+ height: this.docContainer.rect.height
16155
16164
  };
16156
16165
  }
16157
16166
  else {
@@ -16907,21 +16916,22 @@ class DocumentEvent {
16907
16916
  this.bindEvent();
16908
16917
  }
16909
16918
  getEventListener() {
16919
+ const scale = this.viewOptions.scale;
16910
16920
  return {
16911
16921
  mousedown: (evt) => {
16912
- this.mousedown(evt, ElementUtil.getMousePos(evt));
16922
+ this.mousedown(evt, ElementUtil.getMousePos(evt, scale));
16913
16923
  },
16914
16924
  mouseup: (evt) => {
16915
- this.mouseup(evt, ElementUtil.getMousePos(evt));
16925
+ this.mouseup(evt, ElementUtil.getMousePos(evt, scale));
16916
16926
  },
16917
16927
  click: (evt) => {
16918
16928
  this.mouseClickHandle(evt);
16919
16929
  },
16920
16930
  mousemove: (evt) => {
16921
- this.mousemove(evt, ElementUtil.getMousePos(evt));
16931
+ this.mousemove(evt, ElementUtil.getMousePos(evt, scale));
16922
16932
  },
16923
16933
  dblclick: (evt) => {
16924
- this.mouseDblClickHandle(evt, ElementUtil.getMousePos(evt));
16934
+ this.mouseDblClickHandle(evt, ElementUtil.getMousePos(evt, scale));
16925
16935
  },
16926
16936
  contextmenu: (evt) => {
16927
16937
  this.contextMenu.next(evt);
@@ -20001,11 +20011,10 @@ function createPrintTemplate({ width, height, orient }) {
20001
20011
  @page {
20002
20012
  size: ${orient};
20003
20013
  margin: 0;
20004
- padding: 0;
20005
20014
  }
20006
20015
  div {
20007
20016
  width: ${width}mm;
20008
- height: ${height}mm;
20017
+ min-height: ${height}mm;
20009
20018
  font-size: 0;
20010
20019
  }
20011
20020
  @media print {
@@ -20013,7 +20022,6 @@ function createPrintTemplate({ width, height, orient }) {
20013
20022
  body {
20014
20023
  width: ${width}mm;
20015
20024
  height: ${height}mm;
20016
- margin: 0;
20017
20025
  }
20018
20026
  div {
20019
20027
  width: initial;
@@ -26164,14 +26172,36 @@ class EditorCalendarVNode {
26164
26172
  style: {
26165
26173
  position: 'absolute',
26166
26174
  left: (position.x - 10) + 'px',
26167
- top: position.y + 'px',
26175
+ top: position.y + 5 + position.height + 'px',
26168
26176
  'min-width': '100px',
26169
26177
  'background-color': 'white',
26170
26178
  'z-index': '1000',
26171
26179
  'border-radius': '5px',
26172
26180
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
26173
26181
  'user-select': 'none',
26174
- }
26182
+ },
26183
+ hook: {
26184
+ insert: (vnode) => {
26185
+ const elm = vnode.elm;
26186
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26187
+ if (parent) {
26188
+ const parentRect = parent.getBoundingClientRect();
26189
+ const elmRect = elm.getBoundingClientRect();
26190
+ if (elmRect.top < parentRect.top) {
26191
+ elm.style.top = (position.y - elmRect.height) + 'px';
26192
+ }
26193
+ if (elmRect.left < parentRect.left) {
26194
+ elm.style.left = (position.x - 10) + 'px';
26195
+ }
26196
+ if (elmRect.right > parentRect.right) {
26197
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
26198
+ }
26199
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26200
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26201
+ }
26202
+ }
26203
+ }
26204
+ },
26175
26205
  },
26176
26206
  children: []
26177
26207
  };
@@ -27057,7 +27087,15 @@ class DocEditor {
27057
27087
  }
27058
27088
  },
27059
27089
  children: [
27060
- docContentVNode, inputVNode, dropContainer
27090
+ {
27091
+ sel: 'div.scale-container', data: {
27092
+ style: {
27093
+ transform: 'scale(' + this.viewOptions.scale + ')',
27094
+ transformOrigin: 'left top'
27095
+ }
27096
+ },
27097
+ children: [docContentVNode, inputVNode, dropContainer]
27098
+ }
27061
27099
  ]
27062
27100
  }, ruleFunc.refreshRuleSvg().render()
27063
27101
  ]
@@ -27344,14 +27382,14 @@ class DocEditor {
27344
27382
  const startDecorateRender = element.paintRenders[0];
27345
27383
  if (!startDecorateRender) {
27346
27384
  console.error('未找到数据元开始渲染元素');
27347
- return;
27385
+ return null;
27348
27386
  }
27349
27387
  const { x, height, y, width } = startDecorateRender.rect;
27350
27388
  const pos = ElementUtil.getRenderAbsolutePaintPos(startDecorateRender);
27351
27389
  return {
27352
27390
  x: pos.x + width,
27353
- y: pos.y + height + 5,
27354
- translateY: this.viewOptions.pageOffset.y
27391
+ y: pos.y,
27392
+ height
27355
27393
  };
27356
27394
  }
27357
27395
  /**
@@ -27422,6 +27460,11 @@ class DocEditor {
27422
27460
  this.updateRenderCtx();
27423
27461
  this.flushToSchedule();
27424
27462
  this.documentPaint.layoutPages();
27463
+ const sub = this.afterNodePatch.subscribe(() => {
27464
+ sub.unsubscribe();
27465
+ const scrollDOM = this.svgContainer.querySelector('.scroll-container');
27466
+ scrollDOM.scrollLeft = (scrollDOM.scrollWidth - scrollDOM.getBoundingClientRect().width) / 2;
27467
+ });
27425
27468
  return scale;
27426
27469
  }
27427
27470
  updateRenderCtx() {
@@ -28113,14 +28156,36 @@ class DocEditor {
28113
28156
  style: {
28114
28157
  position: 'absolute',
28115
28158
  left: (position.x - 10) + 'px',
28116
- top: position.y + 'px',
28159
+ top: position.y + 5 + position.height + 'px',
28117
28160
  'min-width': '100px',
28118
28161
  'background-color': 'white',
28119
28162
  'z-index': '1000',
28120
28163
  'border-radius': '5px',
28121
28164
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
28122
28165
  'user-select': 'none',
28123
- }
28166
+ },
28167
+ hook: {
28168
+ insert: (vnode) => {
28169
+ const elm = vnode.elm;
28170
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28171
+ if (parent) {
28172
+ const parentRect = parent.getBoundingClientRect();
28173
+ const elmRect = elm.getBoundingClientRect();
28174
+ if (elmRect.top < parentRect.top) {
28175
+ elm.style.top = (position.y - elmRect.height) + 'px';
28176
+ }
28177
+ if (elmRect.left < parentRect.left) {
28178
+ elm.style.left = (position.x - 10) + 'px';
28179
+ }
28180
+ if (elmRect.right > parentRect.right) {
28181
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
28182
+ }
28183
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28184
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28185
+ }
28186
+ }
28187
+ }
28188
+ },
28124
28189
  },
28125
28190
  children: [
28126
28191
  {