@hailin-zheng/editor-core 2.1.0 → 2.1.2

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
@@ -7,7 +7,6 @@ var moment = require('moment');
7
7
  var acor = require('acorn');
8
8
  var astring = require('astring');
9
9
  var estraverse = require('estraverse');
10
- var bwipjs = require('bwip-js');
11
10
  var JsBarcode = require('jsbarcode');
12
11
  var snabbdom = require('snabbdom');
13
12
 
@@ -34,7 +33,6 @@ function _interopNamespace(e) {
34
33
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
35
34
  var acor__namespace = /*#__PURE__*/_interopNamespace(acor);
36
35
  var estraverse__default = /*#__PURE__*/_interopDefaultLegacy(estraverse);
37
- var bwipjs__namespace = /*#__PURE__*/_interopNamespace(bwipjs);
38
36
  var JsBarcode__default = /*#__PURE__*/_interopDefaultLegacy(JsBarcode);
39
37
 
40
38
  /**
@@ -682,6 +680,23 @@ class CommonUtil {
682
680
  }
683
681
  return this.findParent(curr.parentElement, predicate);
684
682
  }
683
+ static isIntersect(rect1, rect2) {
684
+ const left1 = rect1.x;
685
+ const top1 = rect1.y;
686
+ const right1 = rect1.x + rect1.width;
687
+ const bottom1 = rect1.y + rect1.height;
688
+ const left2 = rect2.x;
689
+ const top2 = rect2.y;
690
+ const right2 = rect2.x + rect2.width;
691
+ const bottom2 = rect2.y + rect2.height;
692
+ if (left1 >= right2 || left2 >= right1) {
693
+ return false;
694
+ }
695
+ if (top1 >= bottom2 || top2 >= bottom1) {
696
+ return false;
697
+ }
698
+ return true;
699
+ }
685
700
  }
686
701
 
687
702
  const docOpsMap = new Map();
@@ -1548,6 +1563,8 @@ class ViewOptions {
1548
1563
  paraSymbolColor = 'rgb(128,128,128)';
1549
1564
  dataGroupColor = 'rgb(0,80,179)';
1550
1565
  defaultLineHeight = 1;
1566
+ //虚拟视图模式,处理可视区域内的元素
1567
+ virtualViewMode = false;
1551
1568
  //新增-留痕块文本颜色
1552
1569
  trackInsColor = '#ff4d4f';
1553
1570
  //删除-留痕块文本颜色
@@ -1580,6 +1597,8 @@ class ViewOptions {
1580
1597
  ruleHeight = 30;
1581
1598
  //是否打印页眉页脚线
1582
1599
  printHeaderFooterLine = false;
1600
+ //显示段落回车符号
1601
+ showEnterSymbol = false;
1583
1602
  get fullPageView() {
1584
1603
  return this._fullPageView;
1585
1604
  }
@@ -4334,6 +4353,27 @@ class PSymbolRenderObject extends LeafRenderObject {
4334
4353
  }
4335
4354
  render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
4336
4355
  }
4356
+ exportHTML(event) {
4357
+ if (!event.options.showEnterSymbol || event.mode === 'print') {
4358
+ return null;
4359
+ }
4360
+ return {
4361
+ sel: 'text',
4362
+ text: '↵',
4363
+ data: {
4364
+ ns: "http://www.w3.org/2000/svg",
4365
+ attrs: {
4366
+ //"transform": `translate(0,${(height - props.fontSize) / 2})`,
4367
+ 'dominant-baseline': 'hanging',
4368
+ 'font-family': 'Courier',
4369
+ 'font-size': this.element.defaultHeight,
4370
+ x: this.rect.x,
4371
+ y: this.rect.y,
4372
+ fill: 'green'
4373
+ }
4374
+ },
4375
+ };
4376
+ }
4337
4377
  //绘制段落符号
4338
4378
  clone() {
4339
4379
  const render = new PSymbolRenderObject(this.element);
@@ -8223,30 +8263,13 @@ class DataElementBarcode extends DataElementLeaf {
8223
8263
  return this.props.text;
8224
8264
  }
8225
8265
  drawBarcode(renderCtx, pos) {
8226
- this.createBarcodeCache();
8227
8266
  renderCtx.contentContext.ctx.drawImage(this.barCodeCanvas, pos.x, pos.y, this.props.width, this.props.height);
8228
8267
  }
8229
- createBarcodeCache() {
8230
- if (this.cache) {
8231
- return;
8232
- }
8233
- this.cache = true;
8234
- if (!this.barCodeCanvas) {
8235
- this.barCodeCanvas = document.createElement('canvas');
8236
- }
8237
- this.barCodeCanvas = bwipjs__namespace.toCanvas(this.barCodeCanvas, {
8238
- bcid: this.props.type,
8239
- text: this.props.text || "0123456789",
8240
- height: 10,
8241
- includetext: true,
8242
- textxalign: "center", // Always good to set this
8243
- });
8244
- }
8245
8268
  }
8246
8269
  class DataElementBarcodeRenderObject extends ResizeLeafRenderObject {
8247
8270
  render(e) {
8248
- const barcodeEle = this.element;
8249
- barcodeEle.drawBarcode(e.render, e.position);
8271
+ // const barcodeEle = this.element as DataElementBarcode;
8272
+ // barcodeEle.drawBarcode(e.render, e.position);
8250
8273
  }
8251
8274
  clone() {
8252
8275
  const clone = new DataElementBarcodeRenderObject(this.element);
@@ -9120,6 +9143,27 @@ class BreakRenderObject extends LeafRenderObject {
9120
9143
  }
9121
9144
  render.contentContext.drawText('↓', this.element.textProps, position.x, position.y, 20, this.rect.height);
9122
9145
  }
9146
+ exportHTML(event) {
9147
+ if (!event.options.showEnterSymbol || event.mode === 'print') {
9148
+ return null;
9149
+ }
9150
+ return {
9151
+ sel: 'text',
9152
+ text: '↓',
9153
+ data: {
9154
+ ns: "http://www.w3.org/2000/svg",
9155
+ attrs: {
9156
+ //"transform": `translate(0,${(height - props.fontSize) / 2})`,
9157
+ 'dominant-baseline': 'hanging',
9158
+ 'font-family': 'Courier',
9159
+ 'font-size': this.rect.height,
9160
+ x: this.rect.x + 4,
9161
+ y: this.rect.y,
9162
+ fill: 'green'
9163
+ }
9164
+ },
9165
+ };
9166
+ }
9123
9167
  clone() {
9124
9168
  const render = new BreakRenderObject(this.element);
9125
9169
  render.rect = ElementUtil.cloneRect(this.rect);
@@ -9160,6 +9204,9 @@ class DataElementText extends DataElementInlineGroup {
9160
9204
  if (!this.startDecorate) {
9161
9205
  return;
9162
9206
  }
9207
+ if (val === null || val === undefined) {
9208
+ val = '';
9209
+ }
9163
9210
  if (this.getValue() === val) {
9164
9211
  return;
9165
9212
  }
@@ -12440,6 +12487,7 @@ class ElementUtil {
12440
12487
  };
12441
12488
  }
12442
12489
  static getMousePos(e, scale = 1) {
12490
+ //scale=1;
12443
12491
  const svgContainer = e.currentTarget;
12444
12492
  const parentRect = svgContainer.getBoundingClientRect();
12445
12493
  const localX = e.clientX - parentRect.x; //+ this.viewOptions.pageOffset.x;
@@ -16156,11 +16204,13 @@ class DocumentPaint {
16156
16204
  this.docContainer.clear();
16157
16205
  const { pageLayoutMode, viewSettings: { width: viewWidth } } = this.viewOptions;
16158
16206
  //文档内容区宽度
16159
- const contentWidth = this.viewOptions.contentWidth;
16207
+ const { contentWidth, scale } = this.viewOptions;
16160
16208
  //文档容器总宽度等于内容宽度
16161
16209
  //单页模式,docContainer居中
16162
16210
  this.docContainer.rect.width = viewWidth;
16163
- let docLeft = Math.floor((viewWidth - contentWidth) / 2);
16211
+ //let docLeft = Math.floor((viewWidth - contentWidth) / 2);
16212
+ //处理由于缩放问题,transform-origin:left-top,因此需要提前计算需要偏移的位置
16213
+ let docLeft = Math.floor((viewWidth - contentWidth * scale) / 2) / scale;
16164
16214
  docLeft = docLeft < 0 ? 0 : docLeft;
16165
16215
  pages.forEach(item => item.rect.x = docLeft);
16166
16216
  this.docContainer.rect.x = 0;
@@ -16311,6 +16361,132 @@ class PageBreakFactory extends ElementFactory {
16311
16361
  }
16312
16362
  }
16313
16363
 
16364
+ const fontSize = 12;
16365
+ const verPadding = 2;
16366
+ /**
16367
+ * 恒牙牙位图
16368
+ */
16369
+ class PermanentTeethElement extends LeafElement {
16370
+ constructor() {
16371
+ super('permanent-teeth');
16372
+ this.props = new PermanentTeethProps();
16373
+ this.props.topLeft = '87654321';
16374
+ this.props.topRight = '12345678';
16375
+ this.props.bottomLeft = '87654321';
16376
+ this.props.bottomRight = '12345678';
16377
+ }
16378
+ clone(data) {
16379
+ const clone = new PermanentTeethElement();
16380
+ clone.props = this.props.clone();
16381
+ return clone;
16382
+ }
16383
+ createRenderObject(data) {
16384
+ const clone = new PermanentTeethRenderObject(this);
16385
+ clone.rect.width = 150;
16386
+ //字体大小*2+上下间距2*2
16387
+ clone.rect.height = fontSize * 2 + verPadding * 2;
16388
+ //clone.rect= ElementUtil.cloneRect(this.rect);
16389
+ return clone;
16390
+ }
16391
+ serialize(viewOptions) {
16392
+ return {
16393
+ type: this.type,
16394
+ props: this.props.getSerializeProps(viewOptions)
16395
+ };
16396
+ }
16397
+ }
16398
+ class PermanentTeethRenderObject extends LeafRenderObject {
16399
+ render(e) {
16400
+ }
16401
+ clone() {
16402
+ const clone = new PermanentTeethRenderObject(this.element);
16403
+ clone.rect = ElementUtil.cloneRect(this.rect);
16404
+ return clone;
16405
+ }
16406
+ // measure(): { width: number, height: number } {
16407
+ // const ele = this.element;
16408
+ //
16409
+ // }
16410
+ exportHTML(event) {
16411
+ const ele = this.element;
16412
+ const g = super.exportHTML(event);
16413
+ const contentHorPadding = 4;
16414
+ g.children = [];
16415
+ // g.children.push(ElementUtil.getFillSvgPath(`M 0 ${this.rect.height / 2} h${this.rect.width}`, '#000', 1));
16416
+ // g.children.push(ElementUtil.getFillSvgPath(`M ${this.rect.width / 2} 0 v${this.rect.height}`, '#000', 1));
16417
+ //
16418
+ g.children.push(ElementUtil.getFillSvgRect(0, this.rect.height / 2, this.rect.width, 1, '#000'));
16419
+ g.children.push(ElementUtil.getFillSvgRect(this.rect.width / 2, 0, 1, this.rect.height, '#000'));
16420
+ const getSvgText = (text, x, y) => {
16421
+ return {
16422
+ sel: 'text',
16423
+ text: text,
16424
+ data: {
16425
+ ns: "http://www.w3.org/2000/svg",
16426
+ attrs: {
16427
+ 'dominant-baseline': 'hanging',
16428
+ 'font-family': 'Arial',
16429
+ 'font-size': fontSize,
16430
+ x,
16431
+ y,
16432
+ }
16433
+ },
16434
+ };
16435
+ };
16436
+ const topLeftWidth = event.renderCtx.mainContext.measureTextWidth(ele.props.topLeft, {
16437
+ fontSize: fontSize,
16438
+ fontName: 'Arial'
16439
+ });
16440
+ const bottomLeftWidth = event.renderCtx.mainContext.measureTextWidth(ele.props.bottomLeft, {
16441
+ fontSize: fontSize,
16442
+ fontName: 'Arial'
16443
+ });
16444
+ g.children.push(getSvgText(ele.props.topLeft, this.rect.width / 2 - topLeftWidth - contentHorPadding, verPadding));
16445
+ g.children.push(getSvgText(ele.props.topRight, this.rect.width / 2 + contentHorPadding, verPadding));
16446
+ g.children.push(getSvgText(ele.props.bottomLeft, this.rect.width / 2 - bottomLeftWidth - contentHorPadding, this.rect.height - fontSize + verPadding));
16447
+ g.children.push(getSvgText(ele.props.bottomRight, this.rect.width / 2 + contentHorPadding, this.rect.height - fontSize + verPadding));
16448
+ return g;
16449
+ }
16450
+ }
16451
+ class PermanentTeethFactory extends ElementFactory {
16452
+ match(type) {
16453
+ return type === 'permanent-teeth';
16454
+ }
16455
+ createElement(data) {
16456
+ const ele = new PermanentTeethElement();
16457
+ ele.props.bottomLeft = data.props?.bottomLeft ?? '';
16458
+ ele.props.bottomRight = data.props?.bottomRight ?? '';
16459
+ ele.props.topLeft = data.props?.topLeft ?? '';
16460
+ ele.props.topRight = data.props?.topRight ?? '';
16461
+ return ele;
16462
+ }
16463
+ }
16464
+ /**
16465
+ * 恒牙牙位图属性
16466
+ */
16467
+ class PermanentTeethProps extends INotifyPropertyChanged {
16468
+ topLeft;
16469
+ topRight;
16470
+ bottomLeft;
16471
+ bottomRight;
16472
+ getSerializeProps(viewOptions) {
16473
+ return {
16474
+ topLeft: this.topLeft,
16475
+ topRight: this.topRight,
16476
+ bottomLeft: this.bottomLeft,
16477
+ bottomRight: this.bottomRight,
16478
+ };
16479
+ }
16480
+ clone(dest) {
16481
+ dest = dest || new PermanentTeethProps();
16482
+ dest.topLeft = this.topLeft;
16483
+ dest.topRight = this.topRight;
16484
+ dest.bottomLeft = this.bottomLeft;
16485
+ dest.bottomRight = this.bottomRight;
16486
+ return dest;
16487
+ }
16488
+ }
16489
+
16314
16490
  class ElementReader {
16315
16491
  docCtx;
16316
16492
  constructor(docCtx) {
@@ -16352,6 +16528,7 @@ class ElementReader {
16352
16528
  this.addFactory(DocumentBodyPartFactory);
16353
16529
  this.addFactory(PageBreakFactory);
16354
16530
  this.addFactory(TabFactory);
16531
+ this.addFactory(PermanentTeethFactory);
16355
16532
  // this.registerReadFunc<TrackRunProps>('ins-run', (data) => {
16356
16533
  // const props = new TrackRunProps(data.type);
16357
16534
  // props.userId = data.userId;
@@ -17045,6 +17222,7 @@ class DocumentEvent {
17045
17222
  docEvent.shift = evt.shiftKey;
17046
17223
  docEvent.ctrl = evt.ctrlKey;
17047
17224
  this.ismousedown = false;
17225
+ this.mousedownPos = { x: docEvent.globalX, y: docEvent.globalY };
17048
17226
  //console.log('松开了')
17049
17227
  this.edgeRenderInfo = null;
17050
17228
  }
@@ -19167,7 +19345,8 @@ class DocumentChange {
19167
19345
  if (!prevEle) {
19168
19346
  const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true, this.viewOptions);
19169
19347
  if (nextEle) {
19170
- this.selectionState.resetRange(nextEle, 0);
19348
+ //this.selectionState.resetRange(nextEle, 0);
19349
+ this.setSelectionStateByDeleteEvent(nextEle, 0, control);
19171
19350
  control.remove();
19172
19351
  return;
19173
19352
  }
@@ -19175,24 +19354,48 @@ class DocumentChange {
19175
19354
  return;
19176
19355
  }
19177
19356
  if (ElementUtil.isInSameParagraph(control, prevEle)) {
19178
- this.selectionState.resetRange(prevEle, -1);
19357
+ //this.selectionState.resetRange(prevEle, -1);
19358
+ this.setSelectionStateByDeleteEvent(prevEle, -1, control);
19179
19359
  control.remove();
19180
19360
  return;
19181
19361
  }
19182
19362
  else {
19183
19363
  const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true, this.viewOptions);
19184
19364
  if (nextEle && ElementUtil.getPrevSiblingElement(nextEle) === control) {
19185
- this.selectionState.resetRange(nextEle, 0);
19365
+ //this.selectionState.resetRange(nextEle, 0);
19366
+ this.setSelectionStateByDeleteEvent(nextEle, 0, control);
19186
19367
  control.remove();
19187
19368
  return;
19188
19369
  }
19189
19370
  else {
19190
- this.selectionState.resetRange(prevEle, -1);
19371
+ //this.selectionState.resetRange(prevEle, -1);
19372
+ this.setSelectionStateByDeleteEvent(prevEle, -1, control);
19191
19373
  control.remove();
19192
19374
  return;
19193
19375
  }
19194
19376
  }
19195
19377
  }
19378
+ /**
19379
+ * 处理在表单模式下光标定位的问题
19380
+ * @param target
19381
+ * @param targetOffset
19382
+ * @param deleteTarget
19383
+ * @private
19384
+ */
19385
+ setSelectionStateByDeleteEvent(target, targetOffset, deleteTarget) {
19386
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
19387
+ const dataEle = ElementUtil.getParent(deleteTarget, (item) => item instanceof DataElementInlineGroup);
19388
+ if (dataEle && ElementUtil.getParent(target, (item) => item instanceof DataElementInlineGroup) === dataEle) {
19389
+ this.selectionState.resetRange(target, targetOffset);
19390
+ return;
19391
+ }
19392
+ if (dataEle) {
19393
+ this.selectionState.resetRange(dataEle.startDecorate, 1);
19394
+ return;
19395
+ }
19396
+ }
19397
+ this.selectionState.resetRange(target, targetOffset);
19398
+ }
19196
19399
  /**
19197
19400
  * 回车事件
19198
19401
  */
@@ -20918,7 +21121,7 @@ class DocumentSvg {
20918
21121
  }
20919
21122
  getHTMLVNode(docRenders) {
20920
21123
  this.counterMap = {};
20921
- const pageNodes = docRenders.map(item => {
21124
+ const pageNodes = docRenders.filter(item => this.checkInViewBox(item)).map(item => {
20922
21125
  const pageSvg = this.getPageSvgVNode(item);
20923
21126
  const pageUnit = {
20924
21127
  sel: 'div.page-unit',
@@ -20943,6 +21146,24 @@ class DocumentSvg {
20943
21146
  });
20944
21147
  return pageNodes;
20945
21148
  }
21149
+ /**
21150
+ * 判断当前元素是否在视窗内
21151
+ * @param rect
21152
+ * @private
21153
+ */
21154
+ checkInViewBox(item) {
21155
+ if (!this.viewOptions.virtualViewMode || this.mode === 'print') {
21156
+ return true;
21157
+ }
21158
+ const viewBoxRect = {
21159
+ x: this.viewOptions.pageOffset.x,
21160
+ y: this.viewOptions.pageOffset.y,
21161
+ width: this.viewOptions.viewSettings.width,
21162
+ height: this.viewOptions.viewSettings.height
21163
+ };
21164
+ const eleRect = item.rect;
21165
+ return CommonUtil.isIntersect(viewBoxRect, eleRect);
21166
+ }
20946
21167
  getPageSvgVNode(item) {
20947
21168
  this.highlights = [];
20948
21169
  const rects = [];
@@ -26172,6 +26393,7 @@ function createSignal(state) {
26172
26393
  * 渲染日历虚拟节点处理类
26173
26394
  */
26174
26395
  class EditorCalendarVNode {
26396
+ viewOptions;
26175
26397
  currYear;
26176
26398
  currMonth;
26177
26399
  currCalendarMode;
@@ -26180,7 +26402,8 @@ class EditorCalendarVNode {
26180
26402
  onSetValue = new Subject$1();
26181
26403
  currTime;
26182
26404
  selectedTime;
26183
- constructor() {
26405
+ constructor(viewOptions) {
26406
+ this.viewOptions = viewOptions;
26184
26407
  this.currYear = createSignal(new Date().getFullYear());
26185
26408
  //月份赋值是按照索引来的,所以要减1
26186
26409
  this.currMonth = createSignal(new Date().getMonth());
@@ -26248,36 +26471,49 @@ class EditorCalendarVNode {
26248
26471
  hook: {
26249
26472
  insert: (vnode) => {
26250
26473
  const elm = vnode.elm;
26251
- const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26252
- if (parent) {
26253
- const parentRect = parent.getBoundingClientRect();
26254
- const elmRect = elm.getBoundingClientRect();
26255
- if (elmRect.top < parentRect.top) {
26256
- elm.style.top = (position.y - elmRect.height) + 'px';
26257
- }
26258
- if (elmRect.left < parentRect.left) {
26259
- elm.style.left = (position.x - 10) + 'px';
26260
- }
26261
- if (elmRect.right > parentRect.right) {
26262
- elm.style.left = (position.x - elmRect.width + 10) + 'px';
26263
- }
26264
- if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26265
- const newTop = position.y - position.height - elmRect.height;
26266
- const oldTop = position.y + 5 + position.height;
26267
- //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
26268
- if (oldTop - newTop < elmRect.top - parentRect.top) {
26269
- elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26270
- }
26271
- //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
26272
- //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26273
- }
26274
- }
26474
+ this.resizePosition(elm, position);
26475
+ },
26476
+ update: (oldVnode, vnode) => {
26477
+ const elm = vnode.elm;
26478
+ this.resizePosition(elm, position);
26275
26479
  }
26276
26480
  },
26277
26481
  },
26278
26482
  children: []
26279
26483
  };
26280
26484
  }
26485
+ resizePosition(elm, position) {
26486
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26487
+ const scale = this.viewOptions.scale;
26488
+ if (parent) {
26489
+ const parentRect = parent.getBoundingClientRect();
26490
+ const elmRect = elm.getBoundingClientRect();
26491
+ // elmRect.width /= scale;
26492
+ // elmRect.height /= scale;
26493
+ // parentRect.width /= scale;
26494
+ // parentRect.height /= scale;
26495
+ if (elmRect.top < parentRect.top) {
26496
+ elm.style.top = (position.y - elmRect.height / scale) + 'px';
26497
+ }
26498
+ if (elmRect.left < parentRect.left) {
26499
+ elm.style.left = (position.x - 10) + 'px';
26500
+ }
26501
+ if (elmRect.right > parentRect.right) {
26502
+ elm.style.left = (position.x - elmRect.width / scale + 10) + 'px';
26503
+ //elm.style.left = parentRect.width - elmRect.width + 'px';
26504
+ }
26505
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26506
+ const newTop = position.y - position.height - elmRect.height;
26507
+ const oldTop = position.y + 5 + position.height;
26508
+ //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
26509
+ if (newTop > 0 && oldTop - newTop < elmRect.top - parentRect.top) {
26510
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26511
+ }
26512
+ //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
26513
+ //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26514
+ }
26515
+ }
26516
+ }
26281
26517
  renderDay() {
26282
26518
  //获取当前月份需要渲染的天数集合
26283
26519
  const days = this.getDays();
@@ -27122,8 +27358,13 @@ class DocEditor {
27122
27358
  const listVNode = this.renderDataListVNode();
27123
27359
  const dropContainer = {
27124
27360
  sel: 'div.drop-container',
27125
- data: {},
27126
- children: [listVNode.render(), calendarFunc.render(), menuFunc.render()]
27361
+ data: {
27362
+ style: {
27363
+ 'transform-origin': '0 0',
27364
+ 'transform': `scale(${this.viewOptions.scale})`
27365
+ }
27366
+ },
27367
+ children: [inputVNode, listVNode.render(), calendarFunc.render(), menuFunc.render()]
27127
27368
  };
27128
27369
  return {
27129
27370
  sel: 'div.svg-container',
@@ -27161,18 +27402,7 @@ class DocEditor {
27161
27402
  }
27162
27403
  }
27163
27404
  },
27164
- children: [
27165
- {
27166
- sel: 'div.scale-container', data: {
27167
- style: {
27168
- transform: 'scale(' + this.viewOptions.scale + ')',
27169
- transformOrigin: 'right top',
27170
- width: this.viewOptions.docPageSettings.width + 'px',
27171
- }
27172
- },
27173
- children: [docContentVNode, inputVNode, dropContainer]
27174
- }
27175
- ]
27405
+ children: [docContentVNode, dropContainer]
27176
27406
  }, ruleFunc.refreshRuleSvg().render()
27177
27407
  ]
27178
27408
  };
@@ -27560,11 +27790,11 @@ class DocEditor {
27560
27790
  this.updateRenderCtx();
27561
27791
  this.flushToSchedule();
27562
27792
  this.documentPaint.layoutPages();
27563
- const sub = this.afterNodePatch.subscribe(() => {
27564
- sub.unsubscribe();
27565
- const scrollDOM = this.svgContainer.querySelector('.scroll-container');
27566
- scrollDOM.scrollLeft = (scrollDOM.scrollWidth - scrollDOM.getBoundingClientRect().width) / 2;
27567
- });
27793
+ // const sub = this.afterNodePatch.subscribe(() => {
27794
+ // sub.unsubscribe();
27795
+ // const scrollDOM = this.svgContainer.querySelector('.scroll-container') as HTMLElement;
27796
+ // scrollDOM.scrollLeft = (scrollDOM.scrollWidth - scrollDOM.getBoundingClientRect().width) / 2;
27797
+ // })
27568
27798
  return scale;
27569
27799
  }
27570
27800
  updateRenderCtx() {
@@ -28096,6 +28326,8 @@ class DocEditor {
28096
28326
  position: 'relative',
28097
28327
  width: '0px',
28098
28328
  'user-select': 'none',
28329
+ transform: 'scale(' + this.viewOptions.scale + ')',
28330
+ 'transform-origin': '0 0'
28099
28331
  },
28100
28332
  on: this.documentEvent.getEventListener()
28101
28333
  },
@@ -28274,30 +28506,11 @@ class DocEditor {
28274
28506
  hook: {
28275
28507
  insert: (vnode) => {
28276
28508
  const elm = vnode.elm;
28277
- const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28278
- if (parent) {
28279
- const parentRect = parent.getBoundingClientRect();
28280
- const elmRect = elm.getBoundingClientRect();
28281
- if (elmRect.top < parentRect.top) {
28282
- elm.style.top = (position.y - elmRect.height) + 'px';
28283
- }
28284
- if (elmRect.left < parentRect.left) {
28285
- elm.style.left = (position.x - 10) + 'px';
28286
- }
28287
- if (elmRect.right > parentRect.right) {
28288
- elm.style.left = (position.x - elmRect.width + 10) + 'px';
28289
- }
28290
- if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28291
- const newTop = position.y - position.height - elmRect.height;
28292
- const oldTop = position.y + 5 + position.height;
28293
- //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
28294
- if (oldTop - newTop < elmRect.top - parentRect.top) {
28295
- elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28296
- }
28297
- //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
28298
- //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28299
- }
28300
- }
28509
+ editor.resizePosition(elm, position);
28510
+ },
28511
+ update: (oldVnode, vnode) => {
28512
+ const elm = vnode.elm;
28513
+ editor.resizePosition(elm, position);
28301
28514
  }
28302
28515
  },
28303
28516
  },
@@ -28316,8 +28529,40 @@ class DocEditor {
28316
28529
  }
28317
28530
  };
28318
28531
  }
28532
+ resizePosition(elm, position) {
28533
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28534
+ const scale = this.viewOptions.scale;
28535
+ if (parent) {
28536
+ const parentRect = parent.getBoundingClientRect();
28537
+ const elmRect = elm.getBoundingClientRect();
28538
+ // elmRect.width /= scale;
28539
+ // elmRect.height /= scale;
28540
+ // parentRect.width /= scale;
28541
+ // parentRect.height /= scale;
28542
+ if (elmRect.top < parentRect.top) {
28543
+ elm.style.top = (position.y - elmRect.height / scale) + 'px';
28544
+ }
28545
+ if (elmRect.left < parentRect.left) {
28546
+ elm.style.left = (position.x - 10) + 'px';
28547
+ }
28548
+ if (elmRect.right > parentRect.right) {
28549
+ elm.style.left = (position.x - elmRect.width / scale + 10) + 'px';
28550
+ //elm.style.left = parentRect.width - elmRect.width + 'px';
28551
+ }
28552
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28553
+ const newTop = position.y - position.height - elmRect.height;
28554
+ const oldTop = position.y + 5 + position.height;
28555
+ //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
28556
+ if (newTop > 0 && oldTop - newTop < elmRect.top - parentRect.top) {
28557
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28558
+ }
28559
+ //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
28560
+ //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28561
+ }
28562
+ }
28563
+ }
28319
28564
  renderCalendar() {
28320
- const calendar = new EditorCalendarVNode();
28565
+ const calendar = new EditorCalendarVNode(this.viewOptions);
28321
28566
  const editor = this;
28322
28567
  calendar.onSetValue.subscribe((value) => {
28323
28568
  const dataEle = editor.getCurrentDataElement();
@@ -28403,7 +28648,7 @@ class DocEditor {
28403
28648
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28404
28649
  }
28405
28650
  version() {
28406
- return "2.1.0";
28651
+ return "2.1.2";
28407
28652
  }
28408
28653
  }
28409
28654