@hailin-zheng/editor-core 2.0.7 → 2.0.8

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() {
@@ -5816,7 +5827,7 @@ class TableUtil {
5816
5827
  }
5817
5828
  }
5818
5829
  //如果合并的单元格都是空段落,则不合并内容
5819
- if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length === 1))) {
5830
+ if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length <= 1))) {
5820
5831
  for (let i = 0; i < cellContents.length; i++) {
5821
5832
  startCell.addChild(cellContents[i]);
5822
5833
  }
@@ -8071,7 +8082,7 @@ class ElementUtil {
8071
8082
  static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8072
8083
  const parent = currElement?.parent;
8073
8084
  //删除留痕块的measureRender在不显示留痕模式下,不生成render
8074
- if (!currElement || !parent || (!currElement.cacheRender && !(currElement instanceof TrackRunElement))) {
8085
+ if (!currElement || !parent || (!currElement.paintRenders.length && !(currElement instanceof TrackRunElement))) {
8075
8086
  return null;
8076
8087
  }
8077
8088
  //如果当前数据元不可编辑,则直接跳过
@@ -8177,7 +8188,7 @@ class ElementUtil {
8177
8188
  */
8178
8189
  static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8179
8190
  const parent = currElement?.parent;
8180
- if (!currElement || !parent || !currElement.cacheRender) {
8191
+ if (!currElement || !parent || !currElement.paintRenders.length) {
8181
8192
  return null;
8182
8193
  }
8183
8194
  //如果当前数据元不可编辑,则直接跳过
@@ -8606,6 +8617,31 @@ class ElementUtil {
8606
8617
  y: localY
8607
8618
  };
8608
8619
  }
8620
+ static createClipPath(id, width, height, x = 0, y = 0) {
8621
+ return {
8622
+ sel: 'clipPath',
8623
+ data: {
8624
+ ns: 'http://www.w3.org/2000/svg',
8625
+ attrs: {
8626
+ id
8627
+ }
8628
+ },
8629
+ children: [
8630
+ {
8631
+ sel: 'rect',
8632
+ data: {
8633
+ ns: 'http://www.w3.org/2000/svg',
8634
+ attrs: {
8635
+ width,
8636
+ height,
8637
+ x,
8638
+ y
8639
+ }
8640
+ }
8641
+ }
8642
+ ]
8643
+ };
8644
+ }
8609
8645
  }
8610
8646
 
8611
8647
  class RenderContext {
@@ -11531,6 +11567,10 @@ class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
11531
11567
  }
11532
11568
  return cloneRender;
11533
11569
  }
11570
+ exportHTML(event) {
11571
+ const t = super.exportHTML(event);
11572
+ return t;
11573
+ }
11534
11574
  }
11535
11575
  class DocumentBodyPartFactory extends ElementFactory {
11536
11576
  match(type) {
@@ -25423,51 +25463,62 @@ class DocumentPrintOffscreenBase {
25423
25463
  /**
25424
25464
  * 续打
25425
25465
  */
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
- });
25466
+ async printForContinuation(data, options) {
25467
+ // const sub = this.beforeRenderEvent.subscribe((event) => {
25468
+ // const {index, renderCtx, docRender, pageSvgVNode} = event;
25469
+ // if (index === options.startDocIndex) {
25470
+ // const bodyRender = docRender.getChild(1);
25471
+ // let x = 0, y = options.startY, width = bodyRender.rect.width,
25472
+ // height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25473
+ // if (options.startDocIndex === options.endDocIndex) {
25474
+ // height = options.endY - options.startY;
25475
+ // }
25476
+ // renderCtx.mainContext.clip(x, y, width, height);
25477
+ // }
25478
+ // });
25438
25479
  this.afterRenderEvent.subscribe((event) => {
25439
- const { index, renderCtx, docRender } = event;
25440
- if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25480
+ const { index, renderCtx, docRender, pageSvgVNode } = event;
25481
+ if (index === options.startDocIndex) {
25441
25482
  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
- }
25483
+ let x = bodyRender.rect.x, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25484
+ // if (options.startDocIndex === options.endDocIndex) {
25485
+ // height = options.endY - options.startY;
25486
+ // }
25487
+ const pageClip = ElementUtil.createClipPath('page-clip-' + index, width, height, x, y);
25488
+ //pageSvgVNode.children?.push(pageClip)
25489
+ pageSvgVNode.children?.push(pageClip);
25490
+ pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
25491
+ }
25492
+ // if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25493
+ // const bodyRender = docRender.getChild(1);
25494
+ // const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25495
+ // renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25496
+ // }
25445
25497
  });
25446
25498
  await this.prepare(data);
25447
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25499
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, null);
25448
25500
  if (!canvasNodes.length) {
25449
25501
  console.warn('无可打印页');
25450
25502
  return;
25451
25503
  }
25452
25504
  const docProps = this.docCtx.document.props;
25453
25505
  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
25506
  }
25507
+ // /**
25508
+ // * 获取绘制的图片,格式为Base64编码
25509
+ // */
25510
+ // async getImagesContent(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<Array<string>> {
25511
+ // await this.prepare(data);
25512
+ // const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25513
+ // if (!canvasNodes.length) {
25514
+ // console.warn('无可导出页')
25515
+ // return [];
25516
+ // }
25517
+ // return canvasNodes.map(node => node.toDataURL());
25518
+ // }
25468
25519
  async getPrintNodes(data, ranges = null) {
25469
25520
  await this.prepare(data);
25470
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25521
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
25471
25522
  return canvasNodes;
25472
25523
  }
25473
25524
  /**
@@ -25486,42 +25537,53 @@ class DocumentPrintOffscreenBase {
25486
25537
  height
25487
25538
  });
25488
25539
  }
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
- }
25540
+ // getCanvasNodes(printPages: Array<DocumentRenderObject>, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
25541
+ // const {scale, docPageSettings: {width, height}} = this.viewOptions;
25542
+ // const canvasList: Array<HTMLCanvasElement> = [];
25543
+ // for (let i = 0; i < printPages.length; i++) {
25544
+ // if (printRanges && printRanges.indexOf(i) === -1) {
25545
+ // continue;
25546
+ // }
25547
+ // const {canvas: canvasNode, ctx} = this.createCanvas(width, height);
25548
+ // const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25549
+ // renderCtx.init({width, height, scale});
25550
+ // renderCtx.drawMode = 'print';
25551
+ // const doc = printPages[i];
25552
+ // const tmp = ElementUtil.cloneRect(doc.rect);
25553
+ // doc.rect.x = 0;
25554
+ // doc.rect.y = 0;
25555
+ // this.beforeRenderEvent.next({index: i, renderCtx, docRender: doc})
25556
+ // ElementPaint.drawPage(renderCtx, this.docCtx, doc, {x: 0, y: 0});
25557
+ // this.afterRenderEvent.next({index: i, renderCtx, docRender: doc})
25558
+ // renderCtx.overlaysContext.clear();
25559
+ // renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25560
+ // renderCtx.commit({width, height, scale}, {x: 0, y: 0});
25561
+ // doc.rect = tmp;
25562
+ // canvasList.push(canvasNode);
25563
+ // }
25564
+ // return canvasList;
25565
+ // }
25515
25566
  getSvgNodes(docRenders, printRanges = null) {
25516
25567
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25517
25568
  docSvgHelper.mode = 'print';
25518
- const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
25519
25569
  const patch = init([
25520
25570
  modules.class,
25521
25571
  modules.props,
25522
25572
  modules.attributes,
25523
25573
  modules.style
25524
25574
  ]);
25575
+ // const pageSvgVNodes = docRenders.filter((item, index) =>
25576
+ // !printRanges || printRanges.indexOf(index) >= 0)
25577
+ // .map(item => docSvgHelper.getPageSvgVNode(item));
25578
+ const pageSvgVNodes = [];
25579
+ docRenders.forEach((item, index) => {
25580
+ if (!printRanges || printRanges.indexOf(index) >= 0) {
25581
+ //this.beforeRenderEvent.next({index, renderCtx: this.renderCtx, docRender: item})
25582
+ const pageSvg = docSvgHelper.getPageSvgVNode(item);
25583
+ this.afterRenderEvent.next({ index, renderCtx: this.renderCtx, docRender: item, pageSvgVNode: pageSvg });
25584
+ pageSvgVNodes.push(pageSvg);
25585
+ }
25586
+ });
25525
25587
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
25526
25588
  return domNodes;
25527
25589
  }
@@ -25754,7 +25816,7 @@ class EditorCalendarVNode {
25754
25816
  on: {
25755
25817
  change: (event) => {
25756
25818
  if (moment(event.target.value, 'HH:mm:ss').isValid()) {
25757
- this.selectedTime = event.target.value;
25819
+ this.selectedTime.value = event.target.value;
25758
25820
  }
25759
25821
  else {
25760
25822
  event.target.value = this.currTime.value;
@@ -26821,8 +26883,8 @@ class DocEditor {
26821
26883
  */
26822
26884
  getCurrentDataElement() {
26823
26885
  const selectionState = this.documentSelection.selectionState;
26824
- const { startControl, startOffset } = selectionState;
26825
- if (startControl) {
26886
+ const { startControl, startOffset, collapsed } = selectionState;
26887
+ if (startControl && collapsed) {
26826
26888
  if (!ElementUtil.verifyHitable(startControl)) {
26827
26889
  return null;
26828
26890
  }
@@ -27226,7 +27288,7 @@ class DocEditor {
27226
27288
  const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
27227
27289
  const index = docRender.getIndex();
27228
27290
  const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
27229
- this.selectionState.surround(element);
27291
+ this.selectionState.resetRange(element, 0);
27230
27292
  if (cursorPos.rect.y - this.viewOptions.pageOffset.y > 0 && cursorPos.rect.y - this.viewOptions.pageOffset.y < this.viewOptions.viewSettings.height) {
27231
27293
  return;
27232
27294
  }