@hailin-zheng/editor-core 2.1.0 → 2.1.1

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
  /**
@@ -1580,6 +1578,8 @@ class ViewOptions {
1580
1578
  ruleHeight = 30;
1581
1579
  //是否打印页眉页脚线
1582
1580
  printHeaderFooterLine = false;
1581
+ //显示段落回车符号
1582
+ showEnterSymbol = false;
1583
1583
  get fullPageView() {
1584
1584
  return this._fullPageView;
1585
1585
  }
@@ -4334,6 +4334,27 @@ class PSymbolRenderObject extends LeafRenderObject {
4334
4334
  }
4335
4335
  render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
4336
4336
  }
4337
+ exportHTML(event) {
4338
+ if (!event.options.showEnterSymbol || event.mode === 'print') {
4339
+ return null;
4340
+ }
4341
+ return {
4342
+ sel: 'text',
4343
+ text: '↵',
4344
+ data: {
4345
+ ns: "http://www.w3.org/2000/svg",
4346
+ attrs: {
4347
+ //"transform": `translate(0,${(height - props.fontSize) / 2})`,
4348
+ 'dominant-baseline': 'hanging',
4349
+ 'font-family': 'Courier',
4350
+ 'font-size': this.element.defaultHeight,
4351
+ x: this.rect.x,
4352
+ y: this.rect.y,
4353
+ fill: 'green'
4354
+ }
4355
+ },
4356
+ };
4357
+ }
4337
4358
  //绘制段落符号
4338
4359
  clone() {
4339
4360
  const render = new PSymbolRenderObject(this.element);
@@ -8223,30 +8244,13 @@ class DataElementBarcode extends DataElementLeaf {
8223
8244
  return this.props.text;
8224
8245
  }
8225
8246
  drawBarcode(renderCtx, pos) {
8226
- this.createBarcodeCache();
8227
8247
  renderCtx.contentContext.ctx.drawImage(this.barCodeCanvas, pos.x, pos.y, this.props.width, this.props.height);
8228
8248
  }
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
8249
  }
8246
8250
  class DataElementBarcodeRenderObject extends ResizeLeafRenderObject {
8247
8251
  render(e) {
8248
- const barcodeEle = this.element;
8249
- barcodeEle.drawBarcode(e.render, e.position);
8252
+ // const barcodeEle = this.element as DataElementBarcode;
8253
+ // barcodeEle.drawBarcode(e.render, e.position);
8250
8254
  }
8251
8255
  clone() {
8252
8256
  const clone = new DataElementBarcodeRenderObject(this.element);
@@ -9120,6 +9124,27 @@ class BreakRenderObject extends LeafRenderObject {
9120
9124
  }
9121
9125
  render.contentContext.drawText('↓', this.element.textProps, position.x, position.y, 20, this.rect.height);
9122
9126
  }
9127
+ exportHTML(event) {
9128
+ if (!event.options.showEnterSymbol || event.mode === 'print') {
9129
+ return null;
9130
+ }
9131
+ return {
9132
+ sel: 'text',
9133
+ text: '↓',
9134
+ data: {
9135
+ ns: "http://www.w3.org/2000/svg",
9136
+ attrs: {
9137
+ //"transform": `translate(0,${(height - props.fontSize) / 2})`,
9138
+ 'dominant-baseline': 'hanging',
9139
+ 'font-family': 'Courier',
9140
+ 'font-size': this.rect.height,
9141
+ x: this.rect.x + 4,
9142
+ y: this.rect.y,
9143
+ fill: 'green'
9144
+ }
9145
+ },
9146
+ };
9147
+ }
9123
9148
  clone() {
9124
9149
  const render = new BreakRenderObject(this.element);
9125
9150
  render.rect = ElementUtil.cloneRect(this.rect);
@@ -9160,6 +9185,9 @@ class DataElementText extends DataElementInlineGroup {
9160
9185
  if (!this.startDecorate) {
9161
9186
  return;
9162
9187
  }
9188
+ if (val === null || val === undefined) {
9189
+ val = '';
9190
+ }
9163
9191
  if (this.getValue() === val) {
9164
9192
  return;
9165
9193
  }
@@ -12440,6 +12468,7 @@ class ElementUtil {
12440
12468
  };
12441
12469
  }
12442
12470
  static getMousePos(e, scale = 1) {
12471
+ //scale=1;
12443
12472
  const svgContainer = e.currentTarget;
12444
12473
  const parentRect = svgContainer.getBoundingClientRect();
12445
12474
  const localX = e.clientX - parentRect.x; //+ this.viewOptions.pageOffset.x;
@@ -16160,7 +16189,9 @@ class DocumentPaint {
16160
16189
  //文档容器总宽度等于内容宽度
16161
16190
  //单页模式,docContainer居中
16162
16191
  this.docContainer.rect.width = viewWidth;
16163
- let docLeft = Math.floor((viewWidth - contentWidth) / 2);
16192
+ //let docLeft = Math.floor((viewWidth - contentWidth) / 2);
16193
+ //处理由于缩放问题,transform-origin:left-top,因此需要提前计算需要偏移的位置
16194
+ let docLeft = Math.floor((viewWidth - contentWidth * (this.viewOptions.scale)) / 2);
16164
16195
  docLeft = docLeft < 0 ? 0 : docLeft;
16165
16196
  pages.forEach(item => item.rect.x = docLeft);
16166
16197
  this.docContainer.rect.x = 0;
@@ -19167,7 +19198,8 @@ class DocumentChange {
19167
19198
  if (!prevEle) {
19168
19199
  const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true, this.viewOptions);
19169
19200
  if (nextEle) {
19170
- this.selectionState.resetRange(nextEle, 0);
19201
+ //this.selectionState.resetRange(nextEle, 0);
19202
+ this.setSelectionStateByDeleteEvent(nextEle, 0, control);
19171
19203
  control.remove();
19172
19204
  return;
19173
19205
  }
@@ -19175,24 +19207,48 @@ class DocumentChange {
19175
19207
  return;
19176
19208
  }
19177
19209
  if (ElementUtil.isInSameParagraph(control, prevEle)) {
19178
- this.selectionState.resetRange(prevEle, -1);
19210
+ //this.selectionState.resetRange(prevEle, -1);
19211
+ this.setSelectionStateByDeleteEvent(prevEle, -1, control);
19179
19212
  control.remove();
19180
19213
  return;
19181
19214
  }
19182
19215
  else {
19183
19216
  const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true, this.viewOptions);
19184
19217
  if (nextEle && ElementUtil.getPrevSiblingElement(nextEle) === control) {
19185
- this.selectionState.resetRange(nextEle, 0);
19218
+ //this.selectionState.resetRange(nextEle, 0);
19219
+ this.setSelectionStateByDeleteEvent(nextEle, 0, control);
19186
19220
  control.remove();
19187
19221
  return;
19188
19222
  }
19189
19223
  else {
19190
- this.selectionState.resetRange(prevEle, -1);
19224
+ //this.selectionState.resetRange(prevEle, -1);
19225
+ this.setSelectionStateByDeleteEvent(prevEle, -1, control);
19191
19226
  control.remove();
19192
19227
  return;
19193
19228
  }
19194
19229
  }
19195
19230
  }
19231
+ /**
19232
+ * 处理在表单模式下光标定位的问题
19233
+ * @param target
19234
+ * @param targetOffset
19235
+ * @param deleteTarget
19236
+ * @private
19237
+ */
19238
+ setSelectionStateByDeleteEvent(target, targetOffset, deleteTarget) {
19239
+ if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
19240
+ const dataEle = ElementUtil.getParent(deleteTarget, (item) => item instanceof DataElementInlineGroup);
19241
+ if (dataEle && ElementUtil.getParent(target, (item) => item instanceof DataElementInlineGroup) === dataEle) {
19242
+ this.selectionState.resetRange(target, targetOffset);
19243
+ return;
19244
+ }
19245
+ if (dataEle) {
19246
+ this.selectionState.resetRange(dataEle.startDecorate, 1);
19247
+ return;
19248
+ }
19249
+ }
19250
+ this.selectionState.resetRange(target, targetOffset);
19251
+ }
19196
19252
  /**
19197
19253
  * 回车事件
19198
19254
  */
@@ -26172,6 +26228,7 @@ function createSignal(state) {
26172
26228
  * 渲染日历虚拟节点处理类
26173
26229
  */
26174
26230
  class EditorCalendarVNode {
26231
+ viewOptions;
26175
26232
  currYear;
26176
26233
  currMonth;
26177
26234
  currCalendarMode;
@@ -26180,7 +26237,8 @@ class EditorCalendarVNode {
26180
26237
  onSetValue = new Subject$1();
26181
26238
  currTime;
26182
26239
  selectedTime;
26183
- constructor() {
26240
+ constructor(viewOptions) {
26241
+ this.viewOptions = viewOptions;
26184
26242
  this.currYear = createSignal(new Date().getFullYear());
26185
26243
  //月份赋值是按照索引来的,所以要减1
26186
26244
  this.currMonth = createSignal(new Date().getMonth());
@@ -26248,36 +26306,49 @@ class EditorCalendarVNode {
26248
26306
  hook: {
26249
26307
  insert: (vnode) => {
26250
26308
  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
- }
26309
+ this.resizePosition(elm, position);
26310
+ },
26311
+ update: (oldVnode, vnode) => {
26312
+ const elm = vnode.elm;
26313
+ this.resizePosition(elm, position);
26275
26314
  }
26276
26315
  },
26277
26316
  },
26278
26317
  children: []
26279
26318
  };
26280
26319
  }
26320
+ resizePosition(elm, position) {
26321
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
26322
+ const scale = this.viewOptions.scale;
26323
+ if (parent) {
26324
+ const parentRect = parent.getBoundingClientRect();
26325
+ const elmRect = elm.getBoundingClientRect();
26326
+ // elmRect.width /= scale;
26327
+ // elmRect.height /= scale;
26328
+ // parentRect.width /= scale;
26329
+ // parentRect.height /= scale;
26330
+ if (elmRect.top < parentRect.top) {
26331
+ elm.style.top = (position.y - elmRect.height / scale) + 'px';
26332
+ }
26333
+ if (elmRect.left < parentRect.left) {
26334
+ elm.style.left = (position.x - 10) + 'px';
26335
+ }
26336
+ if (elmRect.right > parentRect.right) {
26337
+ elm.style.left = (position.x - elmRect.width / scale + 10) + 'px';
26338
+ //elm.style.left = parentRect.width - elmRect.width + 'px';
26339
+ }
26340
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
26341
+ const newTop = position.y - position.height - elmRect.height;
26342
+ const oldTop = position.y + 5 + position.height;
26343
+ //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
26344
+ if (newTop > 0 && oldTop - newTop < elmRect.top - parentRect.top) {
26345
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26346
+ }
26347
+ //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
26348
+ //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
26349
+ }
26350
+ }
26351
+ }
26281
26352
  renderDay() {
26282
26353
  //获取当前月份需要渲染的天数集合
26283
26354
  const days = this.getDays();
@@ -27122,8 +27193,13 @@ class DocEditor {
27122
27193
  const listVNode = this.renderDataListVNode();
27123
27194
  const dropContainer = {
27124
27195
  sel: 'div.drop-container',
27125
- data: {},
27126
- children: [listVNode.render(), calendarFunc.render(), menuFunc.render()]
27196
+ data: {
27197
+ style: {
27198
+ 'transform-origin': '0 0',
27199
+ 'transform': `scale(${this.viewOptions.scale})`
27200
+ }
27201
+ },
27202
+ children: [inputVNode, listVNode.render(), calendarFunc.render(), menuFunc.render()]
27127
27203
  };
27128
27204
  return {
27129
27205
  sel: 'div.svg-container',
@@ -27161,18 +27237,7 @@ class DocEditor {
27161
27237
  }
27162
27238
  }
27163
27239
  },
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
- ]
27240
+ children: [docContentVNode, dropContainer]
27176
27241
  }, ruleFunc.refreshRuleSvg().render()
27177
27242
  ]
27178
27243
  };
@@ -27560,11 +27625,11 @@ class DocEditor {
27560
27625
  this.updateRenderCtx();
27561
27626
  this.flushToSchedule();
27562
27627
  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
- });
27628
+ // const sub = this.afterNodePatch.subscribe(() => {
27629
+ // sub.unsubscribe();
27630
+ // const scrollDOM = this.svgContainer.querySelector('.scroll-container') as HTMLElement;
27631
+ // scrollDOM.scrollLeft = (scrollDOM.scrollWidth - scrollDOM.getBoundingClientRect().width) / 2;
27632
+ // })
27568
27633
  return scale;
27569
27634
  }
27570
27635
  updateRenderCtx() {
@@ -28096,6 +28161,8 @@ class DocEditor {
28096
28161
  position: 'relative',
28097
28162
  width: '0px',
28098
28163
  'user-select': 'none',
28164
+ transform: 'scale(' + this.viewOptions.scale + ')',
28165
+ 'transform-origin': '0 0'
28099
28166
  },
28100
28167
  on: this.documentEvent.getEventListener()
28101
28168
  },
@@ -28274,30 +28341,11 @@ class DocEditor {
28274
28341
  hook: {
28275
28342
  insert: (vnode) => {
28276
28343
  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
- }
28344
+ editor.resizePosition(elm, position);
28345
+ },
28346
+ update: (oldVnode, vnode) => {
28347
+ const elm = vnode.elm;
28348
+ editor.resizePosition(elm, position);
28301
28349
  }
28302
28350
  },
28303
28351
  },
@@ -28316,8 +28364,40 @@ class DocEditor {
28316
28364
  }
28317
28365
  };
28318
28366
  }
28367
+ resizePosition(elm, position) {
28368
+ const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
28369
+ const scale = this.viewOptions.scale;
28370
+ if (parent) {
28371
+ const parentRect = parent.getBoundingClientRect();
28372
+ const elmRect = elm.getBoundingClientRect();
28373
+ // elmRect.width /= scale;
28374
+ // elmRect.height /= scale;
28375
+ // parentRect.width /= scale;
28376
+ // parentRect.height /= scale;
28377
+ if (elmRect.top < parentRect.top) {
28378
+ elm.style.top = (position.y - elmRect.height / scale) + 'px';
28379
+ }
28380
+ if (elmRect.left < parentRect.left) {
28381
+ elm.style.left = (position.x - 10) + 'px';
28382
+ }
28383
+ if (elmRect.right > parentRect.right) {
28384
+ elm.style.left = (position.x - elmRect.width / scale + 10) + 'px';
28385
+ //elm.style.left = parentRect.width - elmRect.width + 'px';
28386
+ }
28387
+ if (elmRect.top + elmRect.height > parentRect.top + parentRect.height) {
28388
+ const newTop = position.y - position.height - elmRect.height;
28389
+ const oldTop = position.y + 5 + position.height;
28390
+ //计算前后的高度的差距,然后判断新的值是否在父元素的范围内,如果不在则使用旧的值
28391
+ if (newTop > 0 && oldTop - newTop < elmRect.top - parentRect.top) {
28392
+ elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28393
+ }
28394
+ //elm.style.top = (top - (elmRect.top + elmRect.height - (parentRect.top + parentRect.height))) + 'px';
28395
+ //elm.style.top = (position.y - position.height - elmRect.height) + 'px';
28396
+ }
28397
+ }
28398
+ }
28319
28399
  renderCalendar() {
28320
- const calendar = new EditorCalendarVNode();
28400
+ const calendar = new EditorCalendarVNode(this.viewOptions);
28321
28401
  const editor = this;
28322
28402
  calendar.onSetValue.subscribe((value) => {
28323
28403
  const dataEle = editor.getCurrentDataElement();
@@ -28403,7 +28483,7 @@ class DocEditor {
28403
28483
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28404
28484
  }
28405
28485
  version() {
28406
- return "2.1.0";
28486
+ return "2.1.1";
28407
28487
  }
28408
28488
  }
28409
28489