@hailin-zheng/editor-core 2.0.7 → 2.0.9

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
@@ -1539,6 +1539,8 @@ class ViewOptions {
1539
1539
  //整页模式,不分页
1540
1540
  _fullPageView = false;
1541
1541
  ruleHeight = 30;
1542
+ //是否打印页眉页脚线
1543
+ printHeaderFooterLine = false;
1542
1544
  get fullPageView() {
1543
1545
  return this._fullPageView;
1544
1546
  }
@@ -3701,6 +3703,21 @@ class DataElementRenderObject extends InlineGroupRenderObject {
3701
3703
  exportHTML(event) {
3702
3704
  const node = super.exportHTML(event);
3703
3705
  exportDecoratorHTML(event, this);
3706
+ if (this.element.props.underline) {
3707
+ const { x, y } = event.relativePagePos;
3708
+ event.highlights.push({
3709
+ sel: 'path',
3710
+ data: {
3711
+ ns: 'http://www.w3.org/2000/svg',
3712
+ attrs: {
3713
+ d: `M${x} ${y + this.rect.height} L${x + this.rect.width} ${y + this.rect.height}`,
3714
+ stroke: '#000',
3715
+ fill: 'none',
3716
+ 'stroke-width': 1
3717
+ }
3718
+ }
3719
+ });
3720
+ }
3704
3721
  return node;
3705
3722
  }
3706
3723
  /**
@@ -3975,7 +3992,7 @@ class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
3975
3992
  return cloneRender;
3976
3993
  }
3977
3994
  exportHTML(event) {
3978
- return {
3995
+ const t = {
3979
3996
  sel: "g",
3980
3997
  data: {
3981
3998
  ns: "http://www.w3.org/2000/svg",
@@ -3984,6 +4001,10 @@ class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
3984
4001
  }
3985
4002
  }
3986
4003
  };
4004
+ if (this.element.disableClick && event.mode === 'view') {
4005
+ t.data.attrs['opacity'] = 0.5;
4006
+ }
4007
+ return t;
3987
4008
  }
3988
4009
  }
3989
4010
  class DocumentBodyFactory extends ElementFactory {
@@ -4062,15 +4083,25 @@ class DocumentFooterRenderObject extends BlockContainerRenderObject {
4062
4083
  return cloneRender;
4063
4084
  }
4064
4085
  exportHTML(event) {
4065
- return {
4066
- sel: "g",
4067
- data: {
4068
- ns: "http://www.w3.org/2000/svg",
4069
- attrs: {
4070
- transform: `translate(${this.rect.x},${this.rect.y})`
4071
- }
4072
- }
4073
- };
4086
+ const t = super.exportHTML(event);
4087
+ if (this.element.disableClick && event.mode === 'view') {
4088
+ t.data.attrs.opacity = 0.5;
4089
+ }
4090
+ if (event.options.printHeaderFooterLine) {
4091
+ t.children = [{
4092
+ sel: 'path',
4093
+ data: {
4094
+ ns: "http://www.w3.org/2000/svg",
4095
+ attrs: {
4096
+ d: `M${0} ${0} h${this.rect.width} `,
4097
+ stroke: '#000',
4098
+ 'stroke-width': "1",
4099
+ fill: 'none',
4100
+ }
4101
+ }
4102
+ }];
4103
+ }
4104
+ return t;
4074
4105
  }
4075
4106
  }
4076
4107
  class DocumentFooterFactory extends ElementFactory {
@@ -4159,7 +4190,7 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4159
4190
  const isHeaderEmpty = ElementUtil.checkEmptyRenderContent(this);
4160
4191
  let headerLine;
4161
4192
  //存在输入内容时,绘制页眉-页体分割线
4162
- if (!isHeaderEmpty || !this.element.disableClick) {
4193
+ if (!isHeaderEmpty || !this.element.disableClick || event.mode === 'print') {
4163
4194
  headerLine = {
4164
4195
  sel: 'path',
4165
4196
  data: {
@@ -4167,7 +4198,7 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4167
4198
  attrs: {
4168
4199
  d: `M${0} ${this.rect.height} L${this.rect.width} ${this.rect.height}`,
4169
4200
  stroke: '#000',
4170
- 'stroke-width': '0.5',
4201
+ 'stroke-width': '1',
4171
4202
  fill: 'none',
4172
4203
  x: 0,
4173
4204
  y: this.rect.height,
@@ -4185,6 +4216,9 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4185
4216
  },
4186
4217
  children: []
4187
4218
  };
4219
+ if (this.element.disableClick && event.mode === 'view') {
4220
+ t.data.attrs.opacity = 0.5;
4221
+ }
4188
4222
  if (headerLine) {
4189
4223
  t.children = [headerLine];
4190
4224
  }
@@ -4383,7 +4417,7 @@ class TableCellRenderObject extends InlineMuiltBlockLineRenderObject {
4383
4417
  const t = super.exportHTML(event);
4384
4418
  const counter = event.getCounter('cell');
4385
4419
  const clipId = `CP_${counter}`;
4386
- t.children = [...CommonUtil.toArray(event.getChildNodes(this)), this.createClipPath(clipId)];
4420
+ t.children = [...CommonUtil.toArray(event.getChildNodes(this)), ElementUtil.createClipPath(clipId, this.rect.width, this.rect.height)];
4387
4421
  if (this.element.props.backgroundColor) {
4388
4422
  //t.data.attrs.fill = this.element.props.backgroundColor;
4389
4423
  t.children.splice(0, 0, this.createBgRect());
@@ -4409,29 +4443,6 @@ class TableCellRenderObject extends InlineMuiltBlockLineRenderObject {
4409
4443
  }
4410
4444
  return null;
4411
4445
  }
4412
- createClipPath(id) {
4413
- return {
4414
- sel: 'clipPath',
4415
- data: {
4416
- ns: 'http://www.w3.org/2000/svg',
4417
- attrs: {
4418
- id
4419
- }
4420
- },
4421
- children: [
4422
- {
4423
- sel: 'rect',
4424
- data: {
4425
- ns: 'http://www.w3.org/2000/svg',
4426
- attrs: {
4427
- width: this.rect.width,
4428
- height: this.rect.height
4429
- }
4430
- }
4431
- }
4432
- ]
4433
- };
4434
- }
4435
4446
  }
4436
4447
  class TableCellFactory extends ElementFactory {
4437
4448
  match(type) {
@@ -4489,7 +4500,7 @@ class TableRowElement extends BlockContainerElement {
4489
4500
  }
4490
4501
  break;
4491
4502
  }
4492
- //cell.modifyFlag = ModifyFlag.Modify;
4503
+ cell.modifyFlag = ModifyFlag$1.Modify;
4493
4504
  }
4494
4505
  }
4495
4506
  createRenderObject() {
@@ -4771,12 +4782,13 @@ class TextGroupRenderObject extends LeafRenderObject {
4771
4782
  });
4772
4783
  }
4773
4784
  if (this.element.props.underline) {
4785
+ const underHeight = this.element.props.fontSize * 1.2;
4774
4786
  event.highlights.push({
4775
4787
  sel: 'path',
4776
4788
  data: {
4777
4789
  ns: "http://www.w3.org/2000/svg",
4778
4790
  attrs: {
4779
- d: `M${event.relativePagePos.x} ${event.relativePagePos.y + this.rect.height} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + this.rect.height}`,
4791
+ d: `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + underHeight} ${event.relativePagePos.y + underHeight}`,
4780
4792
  stroke: '#000',
4781
4793
  'stroke-width': 1,
4782
4794
  fill: 'none'
@@ -5816,7 +5828,7 @@ class TableUtil {
5816
5828
  }
5817
5829
  }
5818
5830
  //如果合并的单元格都是空段落,则不合并内容
5819
- if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length === 1))) {
5831
+ if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length <= 1))) {
5820
5832
  for (let i = 0; i < cellContents.length; i++) {
5821
5833
  startCell.addChild(cellContents[i]);
5822
5834
  }
@@ -8071,7 +8083,7 @@ class ElementUtil {
8071
8083
  static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8072
8084
  const parent = currElement?.parent;
8073
8085
  //删除留痕块的measureRender在不显示留痕模式下,不生成render
8074
- if (!currElement || !parent || (!currElement.cacheRender && !(currElement instanceof TrackRunElement))) {
8086
+ if (!currElement || !parent || (!currElement.paintRenders.length && !(currElement instanceof TrackRunElement))) {
8075
8087
  return null;
8076
8088
  }
8077
8089
  //如果当前数据元不可编辑,则直接跳过
@@ -8177,7 +8189,7 @@ class ElementUtil {
8177
8189
  */
8178
8190
  static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8179
8191
  const parent = currElement?.parent;
8180
- if (!currElement || !parent || !currElement.cacheRender) {
8192
+ if (!currElement || !parent || !currElement.paintRenders.length) {
8181
8193
  return null;
8182
8194
  }
8183
8195
  //如果当前数据元不可编辑,则直接跳过
@@ -8606,6 +8618,31 @@ class ElementUtil {
8606
8618
  y: localY
8607
8619
  };
8608
8620
  }
8621
+ static createClipPath(id, width, height, x = 0, y = 0) {
8622
+ return {
8623
+ sel: 'clipPath',
8624
+ data: {
8625
+ ns: 'http://www.w3.org/2000/svg',
8626
+ attrs: {
8627
+ id
8628
+ }
8629
+ },
8630
+ children: [
8631
+ {
8632
+ sel: 'rect',
8633
+ data: {
8634
+ ns: 'http://www.w3.org/2000/svg',
8635
+ attrs: {
8636
+ width,
8637
+ height,
8638
+ x,
8639
+ y
8640
+ }
8641
+ }
8642
+ }
8643
+ ]
8644
+ };
8645
+ }
8609
8646
  }
8610
8647
 
8611
8648
  class RenderContext {
@@ -11531,6 +11568,13 @@ class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
11531
11568
  }
11532
11569
  return cloneRender;
11533
11570
  }
11571
+ exportHTML(event) {
11572
+ const t = super.exportHTML(event);
11573
+ if (this.element.isFocused) {
11574
+ t.children = [ElementUtil.getFillSvgRect(0, 0, this.rect.width, this.rect.height, event.options.selectPrintAreaBgColor)];
11575
+ }
11576
+ return t;
11577
+ }
11534
11578
  }
11535
11579
  class DocumentBodyPartFactory extends ElementFactory {
11536
11580
  match(type) {
@@ -25423,51 +25467,62 @@ class DocumentPrintOffscreenBase {
25423
25467
  /**
25424
25468
  * 续打
25425
25469
  */
25426
- async printForContinuation(data, ranges = null, options) {
25427
- const sub = this.beforeRenderEvent.subscribe((event) => {
25428
- const { index, renderCtx, docRender } = event;
25429
- if (index === options.startDocIndex) {
25430
- const bodyRender = docRender.getChild(1);
25431
- let x = 0, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25432
- if (options.startDocIndex === options.endDocIndex) {
25433
- height = options.endY - options.startY;
25434
- }
25435
- renderCtx.mainContext.clip(x, y, width, height);
25436
- }
25437
- });
25470
+ async printForContinuation(data, options) {
25471
+ // const sub = this.beforeRenderEvent.subscribe((event) => {
25472
+ // const {index, renderCtx, docRender, pageSvgVNode} = event;
25473
+ // if (index === options.startDocIndex) {
25474
+ // const bodyRender = docRender.getChild(1);
25475
+ // let x = 0, y = options.startY, width = bodyRender.rect.width,
25476
+ // height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25477
+ // if (options.startDocIndex === options.endDocIndex) {
25478
+ // height = options.endY - options.startY;
25479
+ // }
25480
+ // renderCtx.mainContext.clip(x, y, width, height);
25481
+ // }
25482
+ // });
25438
25483
  this.afterRenderEvent.subscribe((event) => {
25439
- const { index, renderCtx, docRender } = event;
25440
- if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25484
+ const { index, renderCtx, docRender, pageSvgVNode } = event;
25485
+ if (index === options.startDocIndex) {
25441
25486
  const bodyRender = docRender.getChild(1);
25442
- const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25443
- renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25444
- }
25487
+ let x = bodyRender.rect.x, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25488
+ // if (options.startDocIndex === options.endDocIndex) {
25489
+ // height = options.endY - options.startY;
25490
+ // }
25491
+ const pageClip = ElementUtil.createClipPath('page-clip-' + index, width, height, x, y);
25492
+ //pageSvgVNode.children?.push(pageClip)
25493
+ pageSvgVNode.children?.push(pageClip);
25494
+ pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
25495
+ }
25496
+ // if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25497
+ // const bodyRender = docRender.getChild(1);
25498
+ // const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25499
+ // renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25500
+ // }
25445
25501
  });
25446
25502
  await this.prepare(data);
25447
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25503
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, null);
25448
25504
  if (!canvasNodes.length) {
25449
25505
  console.warn('无可打印页');
25450
25506
  return;
25451
25507
  }
25452
25508
  const docProps = this.docCtx.document.props;
25453
25509
  printNodes(canvasNodes, { ...docProps });
25454
- sub.unsubscribe();
25455
- }
25456
- /**
25457
- * 获取绘制的图片,格式为Base64编码
25458
- */
25459
- async getImagesContent(data, ranges = null) {
25460
- await this.prepare(data);
25461
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25462
- if (!canvasNodes.length) {
25463
- console.warn('无可导出页');
25464
- return [];
25465
- }
25466
- return canvasNodes.map(node => node.toDataURL());
25467
25510
  }
25511
+ // /**
25512
+ // * 获取绘制的图片,格式为Base64编码
25513
+ // */
25514
+ // async getImagesContent(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<Array<string>> {
25515
+ // await this.prepare(data);
25516
+ // const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25517
+ // if (!canvasNodes.length) {
25518
+ // console.warn('无可导出页')
25519
+ // return [];
25520
+ // }
25521
+ // return canvasNodes.map(node => node.toDataURL());
25522
+ // }
25468
25523
  async getPrintNodes(data, ranges = null) {
25469
25524
  await this.prepare(data);
25470
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25525
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
25471
25526
  return canvasNodes;
25472
25527
  }
25473
25528
  /**
@@ -25486,42 +25541,53 @@ class DocumentPrintOffscreenBase {
25486
25541
  height
25487
25542
  });
25488
25543
  }
25489
- getCanvasNodes(printPages, printRanges = null) {
25490
- const { scale, docPageSettings: { width, height } } = this.viewOptions;
25491
- const canvasList = [];
25492
- for (let i = 0; i < printPages.length; i++) {
25493
- if (printRanges && printRanges.indexOf(i) === -1) {
25494
- continue;
25495
- }
25496
- const { canvas: canvasNode, ctx } = this.createCanvas(width, height);
25497
- const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25498
- renderCtx.init({ width, height, scale });
25499
- renderCtx.drawMode = 'print';
25500
- const doc = printPages[i];
25501
- const tmp = ElementUtil.cloneRect(doc.rect);
25502
- doc.rect.x = 0;
25503
- doc.rect.y = 0;
25504
- this.beforeRenderEvent.next({ index: i, renderCtx, docRender: doc });
25505
- ElementPaint.drawPage(renderCtx, this.docCtx, doc, { x: 0, y: 0 });
25506
- this.afterRenderEvent.next({ index: i, renderCtx, docRender: doc });
25507
- renderCtx.overlaysContext.clear();
25508
- renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25509
- renderCtx.commit({ width, height, scale }, { x: 0, y: 0 });
25510
- doc.rect = tmp;
25511
- canvasList.push(canvasNode);
25512
- }
25513
- return canvasList;
25514
- }
25544
+ // getCanvasNodes(printPages: Array<DocumentRenderObject>, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
25545
+ // const {scale, docPageSettings: {width, height}} = this.viewOptions;
25546
+ // const canvasList: Array<HTMLCanvasElement> = [];
25547
+ // for (let i = 0; i < printPages.length; i++) {
25548
+ // if (printRanges && printRanges.indexOf(i) === -1) {
25549
+ // continue;
25550
+ // }
25551
+ // const {canvas: canvasNode, ctx} = this.createCanvas(width, height);
25552
+ // const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25553
+ // renderCtx.init({width, height, scale});
25554
+ // renderCtx.drawMode = 'print';
25555
+ // const doc = printPages[i];
25556
+ // const tmp = ElementUtil.cloneRect(doc.rect);
25557
+ // doc.rect.x = 0;
25558
+ // doc.rect.y = 0;
25559
+ // this.beforeRenderEvent.next({index: i, renderCtx, docRender: doc})
25560
+ // ElementPaint.drawPage(renderCtx, this.docCtx, doc, {x: 0, y: 0});
25561
+ // this.afterRenderEvent.next({index: i, renderCtx, docRender: doc})
25562
+ // renderCtx.overlaysContext.clear();
25563
+ // renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25564
+ // renderCtx.commit({width, height, scale}, {x: 0, y: 0});
25565
+ // doc.rect = tmp;
25566
+ // canvasList.push(canvasNode);
25567
+ // }
25568
+ // return canvasList;
25569
+ // }
25515
25570
  getSvgNodes(docRenders, printRanges = null) {
25516
25571
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25517
25572
  docSvgHelper.mode = 'print';
25518
- const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
25519
25573
  const patch = init([
25520
25574
  modules.class,
25521
25575
  modules.props,
25522
25576
  modules.attributes,
25523
25577
  modules.style
25524
25578
  ]);
25579
+ // const pageSvgVNodes = docRenders.filter((item, index) =>
25580
+ // !printRanges || printRanges.indexOf(index) >= 0)
25581
+ // .map(item => docSvgHelper.getPageSvgVNode(item));
25582
+ const pageSvgVNodes = [];
25583
+ docRenders.forEach((item, index) => {
25584
+ if (!printRanges || printRanges.indexOf(index) >= 0) {
25585
+ //this.beforeRenderEvent.next({index, renderCtx: this.renderCtx, docRender: item})
25586
+ const pageSvg = docSvgHelper.getPageSvgVNode(item);
25587
+ this.afterRenderEvent.next({ index, renderCtx: this.renderCtx, docRender: item, pageSvgVNode: pageSvg });
25588
+ pageSvgVNodes.push(pageSvg);
25589
+ }
25590
+ });
25525
25591
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
25526
25592
  return domNodes;
25527
25593
  }
@@ -25754,7 +25820,7 @@ class EditorCalendarVNode {
25754
25820
  on: {
25755
25821
  change: (event) => {
25756
25822
  if (moment(event.target.value, 'HH:mm:ss').isValid()) {
25757
- this.selectedTime = event.target.value;
25823
+ this.selectedTime.value = event.target.value;
25758
25824
  }
25759
25825
  else {
25760
25826
  event.target.value = this.currTime.value;
@@ -26821,8 +26887,8 @@ class DocEditor {
26821
26887
  */
26822
26888
  getCurrentDataElement() {
26823
26889
  const selectionState = this.documentSelection.selectionState;
26824
- const { startControl, startOffset } = selectionState;
26825
- if (startControl) {
26890
+ const { startControl, startOffset, collapsed } = selectionState;
26891
+ if (startControl && collapsed) {
26826
26892
  if (!ElementUtil.verifyHitable(startControl)) {
26827
26893
  return null;
26828
26894
  }
@@ -27226,7 +27292,7 @@ class DocEditor {
27226
27292
  const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
27227
27293
  const index = docRender.getIndex();
27228
27294
  const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
27229
- this.selectionState.surround(element);
27295
+ this.selectionState.resetRange(element, 0);
27230
27296
  if (cursorPos.rect.y - this.viewOptions.pageOffset.y > 0 && cursorPos.rect.y - this.viewOptions.pageOffset.y < this.viewOptions.viewSettings.height) {
27231
27297
  return;
27232
27298
  }