@hailin-zheng/editor-core 2.0.27 → 2.0.29

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();
@@ -3426,7 +3435,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3426
3435
  ns: "http://www.w3.org/2000/svg",
3427
3436
  attrs: {
3428
3437
  id: "selection",
3429
- }
3438
+ },
3430
3439
  },
3431
3440
  children: []
3432
3441
  };
@@ -3451,7 +3460,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3451
3460
  height: this.rect.height,
3452
3461
  viewBox: `0 0 ${this.rect.width} ${this.rect.height}`,
3453
3462
  overflow: "hidden"
3454
- }
3463
+ },
3455
3464
  },
3456
3465
  children: [
3457
3466
  pageCorner, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection
@@ -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",
@@ -13368,6 +13377,7 @@ class EditorContext {
13368
13377
  this._document.destroy();
13369
13378
  }
13370
13379
  this.clearPrevDocCb = null;
13380
+ this.selectionState.startHitInfo = null;
13371
13381
  };
13372
13382
  }
13373
13383
  clear() {
@@ -19997,9 +20007,6 @@ function createPrintTemplate({ width, height, orient }) {
19997
20007
  box-sizing: border-box;
19998
20008
  -moz-box-sizing: border-box;
19999
20009
  }
20000
- body *{
20001
- white-space: pre;
20002
- }
20003
20010
  @page {
20004
20011
  size: ${orient};
20005
20012
  margin: 0;
@@ -26164,14 +26171,36 @@ class EditorCalendarVNode {
26164
26171
  style: {
26165
26172
  position: 'absolute',
26166
26173
  left: (position.x - 10) + 'px',
26167
- top: position.y + 'px',
26174
+ top: position.y + 5 + position.height + 'px',
26168
26175
  'min-width': '100px',
26169
26176
  'background-color': 'white',
26170
26177
  'z-index': '1000',
26171
26178
  'border-radius': '5px',
26172
26179
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
26173
26180
  'user-select': 'none',
26174
- }
26181
+ },
26182
+ hook: {
26183
+ insert: (vnode) => {
26184
+ const elm = vnode.elm;
26185
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26186
+ if (parent) {
26187
+ const parentRect = parent.getBoundingClientRect();
26188
+ const elmRect = elm.getBoundingClientRect();
26189
+ if (elmRect.top < parentRect.top) {
26190
+ elm.style.top = (position.y - elmRect.height) + 'px';
26191
+ }
26192
+ if (elmRect.left < parentRect.left) {
26193
+ elm.style.left = (position.x - 10) + 'px';
26194
+ }
26195
+ if (elmRect.right > parentRect.right) {
26196
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
26197
+ }
26198
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26199
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26200
+ }
26201
+ }
26202
+ }
26203
+ },
26175
26204
  },
26176
26205
  children: []
26177
26206
  };
@@ -27202,22 +27231,26 @@ class DocEditor {
27202
27231
  */
27203
27232
  setCursor() {
27204
27233
  this.selectionState;
27205
- if (!this.canSetCursor() || !this.documentEvent.startHitInfo) {
27234
+ if (!this.canSetCursor() || !this.selectionState.startHitInfo) {
27206
27235
  this.selectionState.editable = false;
27207
27236
  this.docCtx.selectionState.cursorPos = null;
27208
- this.hiddenInput(false);
27237
+ const cursorRect = this.getCursorRect();
27238
+ this.hiddenInput(false, cursorRect);
27209
27239
  return false;
27210
27240
  }
27211
27241
  const cursorRect = this.getCursorRect();
27212
27242
  this.docCtx.cursorRect = ElementUtil.cloneRect(cursorRect);
27213
27243
  this.selectionState.cursorPos = cursorRect;
27214
- const abPos = this.transToAbsolutePos(ElementUtil.cloneRect(cursorRect));
27244
+ const abPos = ElementUtil.cloneRect(cursorRect);
27215
27245
  this.setCursorPosition(abPos);
27216
27246
  //this.documentEvent.invokeCursor(startControl);
27217
27247
  return true;
27218
27248
  }
27219
27249
  getCursorRect() {
27220
27250
  try {
27251
+ if (!this.documentEvent.startHitInfo) {
27252
+ return { x: 0, y: 0, width: 0, height: 0 };
27253
+ }
27221
27254
  const { startControl, startOffset } = this.selectionState;
27222
27255
  const { startRegion, hitDocIndex } = this.documentEvent.startHitInfo;
27223
27256
  const cursorPos = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
@@ -27234,14 +27267,16 @@ class DocEditor {
27234
27267
  */
27235
27268
  setCursorVisibility(visibility) {
27236
27269
  if (visibility) {
27270
+ this.editInput.style.removeProperty('display');
27237
27271
  this.editInput.focus();
27238
27272
  }
27239
27273
  }
27240
- hiddenInput(reset = true) {
27274
+ hiddenInput(reset = true, pos = null) {
27241
27275
  //this.input.style.display = 'none';
27242
- this.editInput.style.left = '-2px';
27243
- this.editInput.style.top = '-2px';
27276
+ this.editInput.style.left = pos ? pos.x + 'px' : '-2px';
27277
+ this.editInput.style.top = pos ? pos.y + 'px' : '-2px';
27244
27278
  this.editInput.readOnly = true;
27279
+ this.editInput.style.display = 'none';
27245
27280
  !reset && this.editInput.focus();
27246
27281
  }
27247
27282
  /**
@@ -27256,22 +27291,6 @@ class DocEditor {
27256
27291
  this.setCursorVisibility(true);
27257
27292
  //this.setCursorInputStatus();
27258
27293
  }
27259
- /**
27260
- * 将相对坐标位置转换为绝对坐标位
27261
- * 由于缩放,导致绝对位置=相对位置*scale
27262
- * @param pos
27263
- */
27264
- transToAbsolutePos(pos) {
27265
- const { scale } = this.viewOptions;
27266
- this.documentPaint.docContainer.rect.x;
27267
- this.documentPaint.docContainer.rect.y;
27268
- pos.x = pos.x * scale;
27269
- pos.y = pos.y * scale;
27270
- if ('height' in pos) {
27271
- pos.height = pos.height * scale;
27272
- }
27273
- return pos;
27274
- }
27275
27294
  /**
27276
27295
  * 判断是否光标可以设置接受编辑
27277
27296
  * @returns
@@ -27354,14 +27373,14 @@ class DocEditor {
27354
27373
  const startDecorateRender = element.paintRenders[0];
27355
27374
  if (!startDecorateRender) {
27356
27375
  console.error('未找到数据元开始渲染元素');
27357
- return;
27376
+ return null;
27358
27377
  }
27359
27378
  const { x, height, y, width } = startDecorateRender.rect;
27360
27379
  const pos = ElementUtil.getRenderAbsolutePaintPos(startDecorateRender);
27361
27380
  return {
27362
27381
  x: pos.x + width,
27363
- y: pos.y + height + 5,
27364
- translateY: this.viewOptions.pageOffset.y
27382
+ y: pos.y,
27383
+ height
27365
27384
  };
27366
27385
  }
27367
27386
  /**
@@ -28123,14 +28142,36 @@ class DocEditor {
28123
28142
  style: {
28124
28143
  position: 'absolute',
28125
28144
  left: (position.x - 10) + 'px',
28126
- top: position.y + 'px',
28145
+ top: position.y + 5 + position.height + 'px',
28127
28146
  'min-width': '100px',
28128
28147
  'background-color': 'white',
28129
28148
  'z-index': '1000',
28130
28149
  'border-radius': '5px',
28131
28150
  'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
28132
28151
  'user-select': 'none',
28133
- }
28152
+ },
28153
+ hook: {
28154
+ insert: (vnode) => {
28155
+ const elm = vnode.elm;
28156
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28157
+ if (parent) {
28158
+ const parentRect = parent.getBoundingClientRect();
28159
+ const elmRect = elm.getBoundingClientRect();
28160
+ if (elmRect.top < parentRect.top) {
28161
+ elm.style.top = (position.y - elmRect.height) + 'px';
28162
+ }
28163
+ if (elmRect.left < parentRect.left) {
28164
+ elm.style.left = (position.x - 10) + 'px';
28165
+ }
28166
+ if (elmRect.right > parentRect.right) {
28167
+ elm.style.left = (position.x - elmRect.width + 10) + 'px';
28168
+ }
28169
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28170
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28171
+ }
28172
+ }
28173
+ }
28174
+ },
28134
28175
  },
28135
28176
  children: [
28136
28177
  {