@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-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() {
@@ -4801,12 +4812,13 @@ class TextGroupRenderObject extends LeafRenderObject {
4801
4812
  });
4802
4813
  }
4803
4814
  if (this.element.props.underline) {
4815
+ const underHeight = this.element.props.fontSize * 1.2;
4804
4816
  event.highlights.push({
4805
4817
  sel: 'path',
4806
4818
  data: {
4807
4819
  ns: "http://www.w3.org/2000/svg",
4808
4820
  attrs: {
4809
- d: `M${event.relativePagePos.x} ${event.relativePagePos.y + this.rect.height} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + this.rect.height}`,
4821
+ d: `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + underHeight} ${event.relativePagePos.y + underHeight}`,
4810
4822
  stroke: '#000',
4811
4823
  'stroke-width': 1,
4812
4824
  fill: 'none'
@@ -5846,7 +5858,7 @@ class TableUtil {
5846
5858
  }
5847
5859
  }
5848
5860
  //如果合并的单元格都是空段落,则不合并内容
5849
- if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length === 1))) {
5861
+ if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length <= 1))) {
5850
5862
  for (let i = 0; i < cellContents.length; i++) {
5851
5863
  startCell.addChild(cellContents[i]);
5852
5864
  }
@@ -8101,7 +8113,7 @@ class ElementUtil {
8101
8113
  static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8102
8114
  const parent = currElement?.parent;
8103
8115
  //删除留痕块的measureRender在不显示留痕模式下,不生成render
8104
- if (!currElement || !parent || (!currElement.cacheRender && !(currElement instanceof TrackRunElement))) {
8116
+ if (!currElement || !parent || (!currElement.paintRenders.length && !(currElement instanceof TrackRunElement))) {
8105
8117
  return null;
8106
8118
  }
8107
8119
  //如果当前数据元不可编辑,则直接跳过
@@ -8207,7 +8219,7 @@ class ElementUtil {
8207
8219
  */
8208
8220
  static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8209
8221
  const parent = currElement?.parent;
8210
- if (!currElement || !parent || !currElement.cacheRender) {
8222
+ if (!currElement || !parent || !currElement.paintRenders.length) {
8211
8223
  return null;
8212
8224
  }
8213
8225
  //如果当前数据元不可编辑,则直接跳过
@@ -8636,6 +8648,31 @@ class ElementUtil {
8636
8648
  y: localY
8637
8649
  };
8638
8650
  }
8651
+ static createClipPath(id, width, height, x = 0, y = 0) {
8652
+ return {
8653
+ sel: 'clipPath',
8654
+ data: {
8655
+ ns: 'http://www.w3.org/2000/svg',
8656
+ attrs: {
8657
+ id
8658
+ }
8659
+ },
8660
+ children: [
8661
+ {
8662
+ sel: 'rect',
8663
+ data: {
8664
+ ns: 'http://www.w3.org/2000/svg',
8665
+ attrs: {
8666
+ width,
8667
+ height,
8668
+ x,
8669
+ y
8670
+ }
8671
+ }
8672
+ }
8673
+ ]
8674
+ };
8675
+ }
8639
8676
  }
8640
8677
 
8641
8678
  class RenderContext {
@@ -11561,6 +11598,13 @@ class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
11561
11598
  }
11562
11599
  return cloneRender;
11563
11600
  }
11601
+ exportHTML(event) {
11602
+ const t = super.exportHTML(event);
11603
+ if (this.element.isFocused) {
11604
+ t.children = [ElementUtil.getFillSvgRect(0, 0, this.rect.width, this.rect.height, event.options.selectPrintAreaBgColor)];
11605
+ }
11606
+ return t;
11607
+ }
11564
11608
  }
11565
11609
  class DocumentBodyPartFactory extends ElementFactory {
11566
11610
  match(type) {
@@ -25453,51 +25497,62 @@ class DocumentPrintOffscreenBase {
25453
25497
  /**
25454
25498
  * 续打
25455
25499
  */
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
- });
25500
+ async printForContinuation(data, options) {
25501
+ // const sub = this.beforeRenderEvent.subscribe((event) => {
25502
+ // const {index, renderCtx, docRender, pageSvgVNode} = event;
25503
+ // if (index === options.startDocIndex) {
25504
+ // const bodyRender = docRender.getChild(1);
25505
+ // let x = 0, y = options.startY, width = bodyRender.rect.width,
25506
+ // height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25507
+ // if (options.startDocIndex === options.endDocIndex) {
25508
+ // height = options.endY - options.startY;
25509
+ // }
25510
+ // renderCtx.mainContext.clip(x, y, width, height);
25511
+ // }
25512
+ // });
25468
25513
  this.afterRenderEvent.subscribe((event) => {
25469
- const { index, renderCtx, docRender } = event;
25470
- if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25514
+ const { index, renderCtx, docRender, pageSvgVNode } = event;
25515
+ if (index === options.startDocIndex) {
25471
25516
  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
- }
25517
+ let x = bodyRender.rect.x, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25518
+ // if (options.startDocIndex === options.endDocIndex) {
25519
+ // height = options.endY - options.startY;
25520
+ // }
25521
+ const pageClip = ElementUtil.createClipPath('page-clip-' + index, width, height, x, y);
25522
+ //pageSvgVNode.children?.push(pageClip)
25523
+ pageSvgVNode.children?.push(pageClip);
25524
+ pageSvgVNode.data.attrs['clip-path'] = `url(#${'page-clip-' + index})`;
25525
+ }
25526
+ // if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25527
+ // const bodyRender = docRender.getChild(1);
25528
+ // const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25529
+ // renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25530
+ // }
25475
25531
  });
25476
25532
  await this.prepare(data);
25477
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25533
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, null);
25478
25534
  if (!canvasNodes.length) {
25479
25535
  console.warn('无可打印页');
25480
25536
  return;
25481
25537
  }
25482
25538
  const docProps = this.docCtx.document.props;
25483
25539
  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
25540
  }
25541
+ // /**
25542
+ // * 获取绘制的图片,格式为Base64编码
25543
+ // */
25544
+ // async getImagesContent(data: any | DocumentElement, ranges: Array<number> | null = null): Promise<Array<string>> {
25545
+ // await this.prepare(data);
25546
+ // const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25547
+ // if (!canvasNodes.length) {
25548
+ // console.warn('无可导出页')
25549
+ // return [];
25550
+ // }
25551
+ // return canvasNodes.map(node => node.toDataURL());
25552
+ // }
25498
25553
  async getPrintNodes(data, ranges = null) {
25499
25554
  await this.prepare(data);
25500
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25555
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
25501
25556
  return canvasNodes;
25502
25557
  }
25503
25558
  /**
@@ -25516,42 +25571,53 @@ class DocumentPrintOffscreenBase {
25516
25571
  height
25517
25572
  });
25518
25573
  }
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
- }
25574
+ // getCanvasNodes(printPages: Array<DocumentRenderObject>, printRanges: Array<number> | null = null): Array<HTMLCanvasElement> {
25575
+ // const {scale, docPageSettings: {width, height}} = this.viewOptions;
25576
+ // const canvasList: Array<HTMLCanvasElement> = [];
25577
+ // for (let i = 0; i < printPages.length; i++) {
25578
+ // if (printRanges && printRanges.indexOf(i) === -1) {
25579
+ // continue;
25580
+ // }
25581
+ // const {canvas: canvasNode, ctx} = this.createCanvas(width, height);
25582
+ // const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25583
+ // renderCtx.init({width, height, scale});
25584
+ // renderCtx.drawMode = 'print';
25585
+ // const doc = printPages[i];
25586
+ // const tmp = ElementUtil.cloneRect(doc.rect);
25587
+ // doc.rect.x = 0;
25588
+ // doc.rect.y = 0;
25589
+ // this.beforeRenderEvent.next({index: i, renderCtx, docRender: doc})
25590
+ // ElementPaint.drawPage(renderCtx, this.docCtx, doc, {x: 0, y: 0});
25591
+ // this.afterRenderEvent.next({index: i, renderCtx, docRender: doc})
25592
+ // renderCtx.overlaysContext.clear();
25593
+ // renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25594
+ // renderCtx.commit({width, height, scale}, {x: 0, y: 0});
25595
+ // doc.rect = tmp;
25596
+ // canvasList.push(canvasNode);
25597
+ // }
25598
+ // return canvasList;
25599
+ // }
25545
25600
  getSvgNodes(docRenders, printRanges = null) {
25546
25601
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25547
25602
  docSvgHelper.mode = 'print';
25548
- const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
25549
25603
  const patch = init([
25550
25604
  modules.class,
25551
25605
  modules.props,
25552
25606
  modules.attributes,
25553
25607
  modules.style
25554
25608
  ]);
25609
+ // const pageSvgVNodes = docRenders.filter((item, index) =>
25610
+ // !printRanges || printRanges.indexOf(index) >= 0)
25611
+ // .map(item => docSvgHelper.getPageSvgVNode(item));
25612
+ const pageSvgVNodes = [];
25613
+ docRenders.forEach((item, index) => {
25614
+ if (!printRanges || printRanges.indexOf(index) >= 0) {
25615
+ //this.beforeRenderEvent.next({index, renderCtx: this.renderCtx, docRender: item})
25616
+ const pageSvg = docSvgHelper.getPageSvgVNode(item);
25617
+ this.afterRenderEvent.next({ index, renderCtx: this.renderCtx, docRender: item, pageSvgVNode: pageSvg });
25618
+ pageSvgVNodes.push(pageSvg);
25619
+ }
25620
+ });
25555
25621
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
25556
25622
  return domNodes;
25557
25623
  }
@@ -25784,7 +25850,7 @@ class EditorCalendarVNode {
25784
25850
  on: {
25785
25851
  change: (event) => {
25786
25852
  if (moment__default["default"](event.target.value, 'HH:mm:ss').isValid()) {
25787
- this.selectedTime = event.target.value;
25853
+ this.selectedTime.value = event.target.value;
25788
25854
  }
25789
25855
  else {
25790
25856
  event.target.value = this.currTime.value;
@@ -26851,8 +26917,8 @@ class DocEditor {
26851
26917
  */
26852
26918
  getCurrentDataElement() {
26853
26919
  const selectionState = this.documentSelection.selectionState;
26854
- const { startControl, startOffset } = selectionState;
26855
- if (startControl) {
26920
+ const { startControl, startOffset, collapsed } = selectionState;
26921
+ if (startControl && collapsed) {
26856
26922
  if (!ElementUtil.verifyHitable(startControl)) {
26857
26923
  return null;
26858
26924
  }
@@ -27256,7 +27322,7 @@ class DocEditor {
27256
27322
  const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
27257
27323
  const index = docRender.getIndex();
27258
27324
  const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
27259
- this.selectionState.surround(element);
27325
+ this.selectionState.resetRange(element, 0);
27260
27326
  if (cursorPos.rect.y - this.viewOptions.pageOffset.y > 0 && cursorPos.rect.y - this.viewOptions.pageOffset.y < this.viewOptions.viewSettings.height) {
27261
27327
  return;
27262
27328
  }