@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-cjs.js CHANGED
@@ -1569,6 +1569,8 @@ class ViewOptions {
1569
1569
  //整页模式,不分页
1570
1570
  _fullPageView = false;
1571
1571
  ruleHeight = 30;
1572
+ //是否打印页眉页脚线
1573
+ printHeaderFooterLine = false;
1572
1574
  get fullPageView() {
1573
1575
  return this._fullPageView;
1574
1576
  }
@@ -3731,6 +3733,21 @@ class DataElementRenderObject extends InlineGroupRenderObject {
3731
3733
  exportHTML(event) {
3732
3734
  const node = super.exportHTML(event);
3733
3735
  exportDecoratorHTML(event, this);
3736
+ if (this.element.props.underline) {
3737
+ const { x, y } = event.relativePagePos;
3738
+ event.highlights.push({
3739
+ sel: 'path',
3740
+ data: {
3741
+ ns: 'http://www.w3.org/2000/svg',
3742
+ attrs: {
3743
+ d: `M${x} ${y + this.rect.height} L${x + this.rect.width} ${y + this.rect.height}`,
3744
+ stroke: '#000',
3745
+ fill: 'none',
3746
+ 'stroke-width': 1
3747
+ }
3748
+ }
3749
+ });
3750
+ }
3734
3751
  return node;
3735
3752
  }
3736
3753
  /**
@@ -4005,7 +4022,7 @@ class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
4005
4022
  return cloneRender;
4006
4023
  }
4007
4024
  exportHTML(event) {
4008
- return {
4025
+ const t = {
4009
4026
  sel: "g",
4010
4027
  data: {
4011
4028
  ns: "http://www.w3.org/2000/svg",
@@ -4014,6 +4031,10 @@ class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
4014
4031
  }
4015
4032
  }
4016
4033
  };
4034
+ if (this.element.disableClick && event.mode === 'view') {
4035
+ t.data.attrs['opacity'] = 0.5;
4036
+ }
4037
+ return t;
4017
4038
  }
4018
4039
  }
4019
4040
  class DocumentBodyFactory extends ElementFactory {
@@ -4092,15 +4113,25 @@ class DocumentFooterRenderObject extends BlockContainerRenderObject {
4092
4113
  return cloneRender;
4093
4114
  }
4094
4115
  exportHTML(event) {
4095
- return {
4096
- sel: "g",
4097
- data: {
4098
- ns: "http://www.w3.org/2000/svg",
4099
- attrs: {
4100
- transform: `translate(${this.rect.x},${this.rect.y})`
4101
- }
4102
- }
4103
- };
4116
+ const t = super.exportHTML(event);
4117
+ if (this.element.disableClick && event.mode === 'view') {
4118
+ t.data.attrs.opacity = 0.5;
4119
+ }
4120
+ if (event.options.printHeaderFooterLine) {
4121
+ t.children = [{
4122
+ sel: 'path',
4123
+ data: {
4124
+ ns: "http://www.w3.org/2000/svg",
4125
+ attrs: {
4126
+ d: `M${0} ${0} h${this.rect.width} `,
4127
+ stroke: '#000',
4128
+ 'stroke-width': "1",
4129
+ fill: 'none',
4130
+ }
4131
+ }
4132
+ }];
4133
+ }
4134
+ return t;
4104
4135
  }
4105
4136
  }
4106
4137
  class DocumentFooterFactory extends ElementFactory {
@@ -4189,7 +4220,7 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4189
4220
  const isHeaderEmpty = ElementUtil.checkEmptyRenderContent(this);
4190
4221
  let headerLine;
4191
4222
  //存在输入内容时,绘制页眉-页体分割线
4192
- if (!isHeaderEmpty || !this.element.disableClick) {
4223
+ if (!isHeaderEmpty || !this.element.disableClick || event.mode === 'print') {
4193
4224
  headerLine = {
4194
4225
  sel: 'path',
4195
4226
  data: {
@@ -4197,7 +4228,7 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4197
4228
  attrs: {
4198
4229
  d: `M${0} ${this.rect.height} L${this.rect.width} ${this.rect.height}`,
4199
4230
  stroke: '#000',
4200
- 'stroke-width': '0.5',
4231
+ 'stroke-width': '1',
4201
4232
  fill: 'none',
4202
4233
  x: 0,
4203
4234
  y: this.rect.height,
@@ -4215,6 +4246,9 @@ class DocumentHeaderRenderObject extends BlockContainerRenderObject {
4215
4246
  },
4216
4247
  children: []
4217
4248
  };
4249
+ if (this.element.disableClick && event.mode === 'view') {
4250
+ t.data.attrs.opacity = 0.5;
4251
+ }
4218
4252
  if (headerLine) {
4219
4253
  t.children = [headerLine];
4220
4254
  }
@@ -4413,7 +4447,7 @@ class TableCellRenderObject extends InlineMuiltBlockLineRenderObject {
4413
4447
  const t = super.exportHTML(event);
4414
4448
  const counter = event.getCounter('cell');
4415
4449
  const clipId = `CP_${counter}`;
4416
- t.children = [...CommonUtil.toArray(event.getChildNodes(this)), this.createClipPath(clipId)];
4450
+ t.children = [...CommonUtil.toArray(event.getChildNodes(this)), ElementUtil.createClipPath(clipId, this.rect.width, this.rect.height)];
4417
4451
  if (this.element.props.backgroundColor) {
4418
4452
  //t.data.attrs.fill = this.element.props.backgroundColor;
4419
4453
  t.children.splice(0, 0, this.createBgRect());
@@ -4439,29 +4473,6 @@ class TableCellRenderObject extends InlineMuiltBlockLineRenderObject {
4439
4473
  }
4440
4474
  return null;
4441
4475
  }
4442
- createClipPath(id) {
4443
- return {
4444
- sel: 'clipPath',
4445
- data: {
4446
- ns: 'http://www.w3.org/2000/svg',
4447
- attrs: {
4448
- id
4449
- }
4450
- },
4451
- children: [
4452
- {
4453
- sel: 'rect',
4454
- data: {
4455
- ns: 'http://www.w3.org/2000/svg',
4456
- attrs: {
4457
- width: this.rect.width,
4458
- height: this.rect.height
4459
- }
4460
- }
4461
- }
4462
- ]
4463
- };
4464
- }
4465
4476
  }
4466
4477
  class TableCellFactory extends ElementFactory {
4467
4478
  match(type) {
@@ -4519,7 +4530,7 @@ class TableRowElement extends BlockContainerElement {
4519
4530
  }
4520
4531
  break;
4521
4532
  }
4522
- //cell.modifyFlag = ModifyFlag.Modify;
4533
+ cell.modifyFlag = exports.ModifyFlag.Modify;
4523
4534
  }
4524
4535
  }
4525
4536
  createRenderObject() {
@@ -5846,7 +5857,7 @@ class TableUtil {
5846
5857
  }
5847
5858
  }
5848
5859
  //如果合并的单元格都是空段落,则不合并内容
5849
- if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length === 1))) {
5860
+ if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length <= 1))) {
5850
5861
  for (let i = 0; i < cellContents.length; i++) {
5851
5862
  startCell.addChild(cellContents[i]);
5852
5863
  }
@@ -8101,7 +8112,7 @@ class ElementUtil {
8101
8112
  static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8102
8113
  const parent = currElement?.parent;
8103
8114
  //删除留痕块的measureRender在不显示留痕模式下,不生成render
8104
- if (!currElement || !parent || (!currElement.cacheRender && !(currElement instanceof TrackRunElement))) {
8115
+ if (!currElement || !parent || (!currElement.paintRenders.length && !(currElement instanceof TrackRunElement))) {
8105
8116
  return null;
8106
8117
  }
8107
8118
  //如果当前数据元不可编辑,则直接跳过
@@ -8207,7 +8218,7 @@ class ElementUtil {
8207
8218
  */
8208
8219
  static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8209
8220
  const parent = currElement?.parent;
8210
- if (!currElement || !parent || !currElement.cacheRender) {
8221
+ if (!currElement || !parent || !currElement.paintRenders.length) {
8211
8222
  return null;
8212
8223
  }
8213
8224
  //如果当前数据元不可编辑,则直接跳过
@@ -8636,6 +8647,31 @@ class ElementUtil {
8636
8647
  y: localY
8637
8648
  };
8638
8649
  }
8650
+ static createClipPath(id, width, height, x = 0, y = 0) {
8651
+ return {
8652
+ sel: 'clipPath',
8653
+ data: {
8654
+ ns: 'http://www.w3.org/2000/svg',
8655
+ attrs: {
8656
+ id
8657
+ }
8658
+ },
8659
+ children: [
8660
+ {
8661
+ sel: 'rect',
8662
+ data: {
8663
+ ns: 'http://www.w3.org/2000/svg',
8664
+ attrs: {
8665
+ width,
8666
+ height,
8667
+ x,
8668
+ y
8669
+ }
8670
+ }
8671
+ }
8672
+ ]
8673
+ };
8674
+ }
8639
8675
  }
8640
8676
 
8641
8677
  class RenderContext {
@@ -11561,6 +11597,10 @@ class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
11561
11597
  }
11562
11598
  return cloneRender;
11563
11599
  }
11600
+ exportHTML(event) {
11601
+ const t = super.exportHTML(event);
11602
+ return t;
11603
+ }
11564
11604
  }
11565
11605
  class DocumentBodyPartFactory extends ElementFactory {
11566
11606
  match(type) {
@@ -25453,51 +25493,62 @@ class DocumentPrintOffscreenBase {
25453
25493
  /**
25454
25494
  * 续打
25455
25495
  */
25456
- async printForContinuation(data, ranges = null, options) {
25457
- const sub = this.beforeRenderEvent.subscribe((event) => {
25458
- const { index, renderCtx, docRender } = event;
25459
- if (index === options.startDocIndex) {
25460
- const bodyRender = docRender.getChild(1);
25461
- let x = 0, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25462
- if (options.startDocIndex === options.endDocIndex) {
25463
- height = options.endY - options.startY;
25464
- }
25465
- renderCtx.mainContext.clip(x, y, width, height);
25466
- }
25467
- });
25496
+ async printForContinuation(data, options) {
25497
+ // const sub = this.beforeRenderEvent.subscribe((event) => {
25498
+ // const {index, renderCtx, docRender, pageSvgVNode} = event;
25499
+ // if (index === options.startDocIndex) {
25500
+ // const bodyRender = docRender.getChild(1);
25501
+ // let x = 0, y = options.startY, width = bodyRender.rect.width,
25502
+ // height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25503
+ // if (options.startDocIndex === options.endDocIndex) {
25504
+ // height = options.endY - options.startY;
25505
+ // }
25506
+ // renderCtx.mainContext.clip(x, y, width, height);
25507
+ // }
25508
+ // });
25468
25509
  this.afterRenderEvent.subscribe((event) => {
25469
- const { index, renderCtx, docRender } = event;
25470
- if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25510
+ const { index, renderCtx, docRender, pageSvgVNode } = event;
25511
+ if (index === options.startDocIndex) {
25471
25512
  const bodyRender = docRender.getChild(1);
25472
- const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25473
- renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25474
- }
25513
+ let x = bodyRender.rect.x, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25514
+ // if (options.startDocIndex === options.endDocIndex) {
25515
+ // height = options.endY - options.startY;
25516
+ // }
25517
+ const pageClip = ElementUtil.createClipPath('page-clip-' + index, width, height, x, y);
25518
+ //pageSvgVNode.children?.push(pageClip)
25519
+ pageSvgVNode.children?.push(pageClip);
25520
+ pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
25521
+ }
25522
+ // if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25523
+ // const bodyRender = docRender.getChild(1);
25524
+ // const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25525
+ // renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25526
+ // }
25475
25527
  });
25476
25528
  await this.prepare(data);
25477
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25529
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, null);
25478
25530
  if (!canvasNodes.length) {
25479
25531
  console.warn('无可打印页');
25480
25532
  return;
25481
25533
  }
25482
25534
  const docProps = this.docCtx.document.props;
25483
25535
  printNodes(canvasNodes, { ...docProps });
25484
- sub.unsubscribe();
25485
- }
25486
- /**
25487
- * 获取绘制的图片,格式为Base64编码
25488
- */
25489
- async getImagesContent(data, ranges = null) {
25490
- await this.prepare(data);
25491
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25492
- if (!canvasNodes.length) {
25493
- console.warn('无可导出页');
25494
- return [];
25495
- }
25496
- return canvasNodes.map(node => node.toDataURL());
25497
25536
  }
25537
+ // /**
25538
+ // * 获取绘制的图片,格式为Base64编码
25539
+ // */
25540
+ // async getImagesContent(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<Array<string>> {
25541
+ // await this.prepare(data);
25542
+ // const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25543
+ // if (!canvasNodes.length) {
25544
+ // console.warn('无可导出页')
25545
+ // return [];
25546
+ // }
25547
+ // return canvasNodes.map(node => node.toDataURL());
25548
+ // }
25498
25549
  async getPrintNodes(data, ranges = null) {
25499
25550
  await this.prepare(data);
25500
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25551
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
25501
25552
  return canvasNodes;
25502
25553
  }
25503
25554
  /**
@@ -25516,42 +25567,53 @@ class DocumentPrintOffscreenBase {
25516
25567
  height
25517
25568
  });
25518
25569
  }
25519
- getCanvasNodes(printPages, printRanges = null) {
25520
- const { scale, docPageSettings: { width, height } } = this.viewOptions;
25521
- const canvasList = [];
25522
- for (let i = 0; i < printPages.length; i++) {
25523
- if (printRanges && printRanges.indexOf(i) === -1) {
25524
- continue;
25525
- }
25526
- const { canvas: canvasNode, ctx } = this.createCanvas(width, height);
25527
- const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25528
- renderCtx.init({ width, height, scale });
25529
- renderCtx.drawMode = 'print';
25530
- const doc = printPages[i];
25531
- const tmp = ElementUtil.cloneRect(doc.rect);
25532
- doc.rect.x = 0;
25533
- doc.rect.y = 0;
25534
- this.beforeRenderEvent.next({ index: i, renderCtx, docRender: doc });
25535
- ElementPaint.drawPage(renderCtx, this.docCtx, doc, { x: 0, y: 0 });
25536
- this.afterRenderEvent.next({ index: i, renderCtx, docRender: doc });
25537
- renderCtx.overlaysContext.clear();
25538
- renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25539
- renderCtx.commit({ width, height, scale }, { x: 0, y: 0 });
25540
- doc.rect = tmp;
25541
- canvasList.push(canvasNode);
25542
- }
25543
- return canvasList;
25544
- }
25570
+ // getCanvasNodes(printPages: Array<DocumentRenderObject>, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
25571
+ // const {scale, docPageSettings: {width, height}} = this.viewOptions;
25572
+ // const canvasList: Array<HTMLCanvasElement> = [];
25573
+ // for (let i = 0; i < printPages.length; i++) {
25574
+ // if (printRanges && printRanges.indexOf(i) === -1) {
25575
+ // continue;
25576
+ // }
25577
+ // const {canvas: canvasNode, ctx} = this.createCanvas(width, height);
25578
+ // const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25579
+ // renderCtx.init({width, height, scale});
25580
+ // renderCtx.drawMode = 'print';
25581
+ // const doc = printPages[i];
25582
+ // const tmp = ElementUtil.cloneRect(doc.rect);
25583
+ // doc.rect.x = 0;
25584
+ // doc.rect.y = 0;
25585
+ // this.beforeRenderEvent.next({index: i, renderCtx, docRender: doc})
25586
+ // ElementPaint.drawPage(renderCtx, this.docCtx, doc, {x: 0, y: 0});
25587
+ // this.afterRenderEvent.next({index: i, renderCtx, docRender: doc})
25588
+ // renderCtx.overlaysContext.clear();
25589
+ // renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25590
+ // renderCtx.commit({width, height, scale}, {x: 0, y: 0});
25591
+ // doc.rect = tmp;
25592
+ // canvasList.push(canvasNode);
25593
+ // }
25594
+ // return canvasList;
25595
+ // }
25545
25596
  getSvgNodes(docRenders, printRanges = null) {
25546
25597
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25547
25598
  docSvgHelper.mode = 'print';
25548
- const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
25549
25599
  const patch = init([
25550
25600
  modules.class,
25551
25601
  modules.props,
25552
25602
  modules.attributes,
25553
25603
  modules.style
25554
25604
  ]);
25605
+ // const pageSvgVNodes = docRenders.filter((item, index) =>
25606
+ // !printRanges || printRanges.indexOf(index) >= 0)
25607
+ // .map(item => docSvgHelper.getPageSvgVNode(item));
25608
+ const pageSvgVNodes = [];
25609
+ docRenders.forEach((item, index) => {
25610
+ if (!printRanges || printRanges.indexOf(index) >= 0) {
25611
+ //this.beforeRenderEvent.next({index, renderCtx: this.renderCtx, docRender: item})
25612
+ const pageSvg = docSvgHelper.getPageSvgVNode(item);
25613
+ this.afterRenderEvent.next({ index, renderCtx: this.renderCtx, docRender: item, pageSvgVNode: pageSvg });
25614
+ pageSvgVNodes.push(pageSvg);
25615
+ }
25616
+ });
25555
25617
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
25556
25618
  return domNodes;
25557
25619
  }
@@ -25784,7 +25846,7 @@ class EditorCalendarVNode {
25784
25846
  on: {
25785
25847
  change: (event) => {
25786
25848
  if (moment__default["default"](event.target.value, 'HH:mm:ss').isValid()) {
25787
- this.selectedTime = event.target.value;
25849
+ this.selectedTime.value = event.target.value;
25788
25850
  }
25789
25851
  else {
25790
25852
  event.target.value = this.currTime.value;
@@ -26851,8 +26913,8 @@ class DocEditor {
26851
26913
  */
26852
26914
  getCurrentDataElement() {
26853
26915
  const selectionState = this.documentSelection.selectionState;
26854
- const { startControl, startOffset } = selectionState;
26855
- if (startControl) {
26916
+ const { startControl, startOffset, collapsed } = selectionState;
26917
+ if (startControl && collapsed) {
26856
26918
  if (!ElementUtil.verifyHitable(startControl)) {
26857
26919
  return null;
26858
26920
  }
@@ -27256,7 +27318,7 @@ class DocEditor {
27256
27318
  const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
27257
27319
  const index = docRender.getIndex();
27258
27320
  const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
27259
- this.selectionState.surround(element);
27321
+ this.selectionState.resetRange(element, 0);
27260
27322
  if (cursorPos.rect.y - this.viewOptions.pageOffset.y > 0 && cursorPos.rect.y - this.viewOptions.pageOffset.y < this.viewOptions.viewSettings.height) {
27261
27323
  return;
27262
27324
  }