@hailin-zheng/editor-core 2.0.6 → 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) {
@@ -4512,6 +4523,13 @@ class TableRowElement extends BlockContainerElement {
4512
4523
  setChildrenModifyFlag(exports.ModifyFlag.Modify, tb.getChild(j));
4513
4524
  }
4514
4525
  }
4526
+ else if (cell.props.vMerge === 'restart') {
4527
+ const endRowIndex = TableUtil.getVMergeEndIndex(tb, currRowIndex, i);
4528
+ for (let j = currRowIndex; j <= endRowIndex; j++) {
4529
+ setChildrenModifyFlag(exports.ModifyFlag.Modify, tb.getChild(j));
4530
+ }
4531
+ break;
4532
+ }
4515
4533
  cell.modifyFlag = exports.ModifyFlag.Modify;
4516
4534
  }
4517
4535
  }
@@ -5839,7 +5857,7 @@ class TableUtil {
5839
5857
  }
5840
5858
  }
5841
5859
  //如果合并的单元格都是空段落,则不合并内容
5842
- if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length === 1))) {
5860
+ if (!cellContents.every((item) => (item instanceof ParagraphElement && item.length <= 1))) {
5843
5861
  for (let i = 0; i < cellContents.length; i++) {
5844
5862
  startCell.addChild(cellContents[i]);
5845
5863
  }
@@ -8094,7 +8112,7 @@ class ElementUtil {
8094
8112
  static getRecursionPrevSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8095
8113
  const parent = currElement?.parent;
8096
8114
  //删除留痕块的measureRender在不显示留痕模式下,不生成render
8097
- if (!currElement || !parent || (!currElement.cacheRender && !(currElement instanceof TrackRunElement))) {
8115
+ if (!currElement || !parent || (!currElement.paintRenders.length && !(currElement instanceof TrackRunElement))) {
8098
8116
  return null;
8099
8117
  }
8100
8118
  //如果当前数据元不可编辑,则直接跳过
@@ -8200,7 +8218,7 @@ class ElementUtil {
8200
8218
  */
8201
8219
  static getRecursionNextSiblingElement(currElement, inPara = false, forCursor = false, viewOptions) {
8202
8220
  const parent = currElement?.parent;
8203
- if (!currElement || !parent || !currElement.cacheRender) {
8221
+ if (!currElement || !parent || !currElement.paintRenders.length) {
8204
8222
  return null;
8205
8223
  }
8206
8224
  //如果当前数据元不可编辑,则直接跳过
@@ -8629,6 +8647,31 @@ class ElementUtil {
8629
8647
  y: localY
8630
8648
  };
8631
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
+ }
8632
8675
  }
8633
8676
 
8634
8677
  class RenderContext {
@@ -11554,6 +11597,10 @@ class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
11554
11597
  }
11555
11598
  return cloneRender;
11556
11599
  }
11600
+ exportHTML(event) {
11601
+ const t = super.exportHTML(event);
11602
+ return t;
11603
+ }
11557
11604
  }
11558
11605
  class DocumentBodyPartFactory extends ElementFactory {
11559
11606
  match(type) {
@@ -12035,7 +12082,7 @@ class PictureFactory extends ElementFactory {
12035
12082
  picProps.width = props.width;
12036
12083
  picProps.height = props.height;
12037
12084
  picProps.src = props.src;
12038
- picProps.border = props.border || 'all';
12085
+ picProps.border = props.border;
12039
12086
  picProps.title = props.title;
12040
12087
  pic.props = picProps;
12041
12088
  return pic;
@@ -19253,13 +19300,18 @@ class DocumentChange {
19253
19300
  else if (pasteElement instanceof BlockContainerElement) {
19254
19301
  const children = ElementUtil.getChildrenElements(pasteElement);
19255
19302
  //复制的内容全部为段落,执行黏贴操作
19256
- if (children.every(item => item instanceof ParagraphElement)) {
19257
- const targetParagraph = this.splitCurrentParagraph();
19258
- children.forEach((item, i) => {
19259
- targetParagraph.parent.addChild(item, targetParagraph.getIndex());
19260
- });
19261
- this.selectionState.resetRange(children[children.length - 1], -1);
19262
- }
19303
+ // if (children.every(item => item instanceof ParagraphElement)) {
19304
+ // const targetParagraph = this.splitCurrentParagraph();
19305
+ // children.forEach((item, i) => {
19306
+ // targetParagraph.parent.addChild(item, targetParagraph.getIndex());
19307
+ // });
19308
+ // this.selectionState.resetRange(children[children.length - 1], -1);
19309
+ // }
19310
+ const targetParagraph = this.splitCurrentParagraph();
19311
+ children.forEach((item, i) => {
19312
+ targetParagraph.parent.addChild(item, targetParagraph.getIndex());
19313
+ });
19314
+ this.selectionState.resetRange(children[children.length - 1], -1);
19263
19315
  }
19264
19316
  }
19265
19317
  insertSoftBr() {
@@ -25441,51 +25493,62 @@ class DocumentPrintOffscreenBase {
25441
25493
  /**
25442
25494
  * 续打
25443
25495
  */
25444
- async printForContinuation(data, ranges = null, options) {
25445
- const sub = this.beforeRenderEvent.subscribe((event) => {
25446
- const { index, renderCtx, docRender } = event;
25447
- if (index === options.startDocIndex) {
25448
- const bodyRender = docRender.getChild(1);
25449
- let x = 0, y = options.startY, width = bodyRender.rect.width, height = bodyRender.rect.height - (options.startY - bodyRender.rect.y);
25450
- if (options.startDocIndex === options.endDocIndex) {
25451
- height = options.endY - options.startY;
25452
- }
25453
- renderCtx.mainContext.clip(x, y, width, height);
25454
- }
25455
- });
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
+ // });
25456
25509
  this.afterRenderEvent.subscribe((event) => {
25457
- const { index, renderCtx, docRender } = event;
25458
- if (options.startDocIndex !== options.endDocIndex && index === options.endDocIndex) {
25510
+ const { index, renderCtx, docRender, pageSvgVNode } = event;
25511
+ if (index === options.startDocIndex) {
25459
25512
  const bodyRender = docRender.getChild(1);
25460
- const height = bodyRender.rect.height - (options.endY - bodyRender.rect.y);
25461
- renderCtx.contentContext.clearRect(bodyRender.rect.x, options.endY, bodyRender.rect.width, height);
25462
- }
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
+ // }
25463
25527
  });
25464
25528
  await this.prepare(data);
25465
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25529
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, null);
25466
25530
  if (!canvasNodes.length) {
25467
25531
  console.warn('无可打印页');
25468
25532
  return;
25469
25533
  }
25470
25534
  const docProps = this.docCtx.document.props;
25471
25535
  printNodes(canvasNodes, { ...docProps });
25472
- sub.unsubscribe();
25473
- }
25474
- /**
25475
- * 获取绘制的图片,格式为Base64编码
25476
- */
25477
- async getImagesContent(data, ranges = null) {
25478
- await this.prepare(data);
25479
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25480
- if (!canvasNodes.length) {
25481
- console.warn('无可导出页');
25482
- return [];
25483
- }
25484
- return canvasNodes.map(node => node.toDataURL());
25485
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
+ // }
25486
25549
  async getPrintNodes(data, ranges = null) {
25487
25550
  await this.prepare(data);
25488
- const canvasNodes = this.getCanvasNodes(this.documentPaint.docPages, ranges);
25551
+ const canvasNodes = this.getSvgNodes(this.documentPaint.docPages, ranges);
25489
25552
  return canvasNodes;
25490
25553
  }
25491
25554
  /**
@@ -25504,42 +25567,53 @@ class DocumentPrintOffscreenBase {
25504
25567
  height
25505
25568
  });
25506
25569
  }
25507
- getCanvasNodes(printPages, printRanges = null) {
25508
- const { scale, docPageSettings: { width, height } } = this.viewOptions;
25509
- const canvasList = [];
25510
- for (let i = 0; i < printPages.length; i++) {
25511
- if (printRanges && printRanges.indexOf(i) === -1) {
25512
- continue;
25513
- }
25514
- const { canvas: canvasNode, ctx } = this.createCanvas(width, height);
25515
- const renderCtx = this.createRenderCtx(ctx, this.viewOptions, this.docCtx);
25516
- renderCtx.init({ width, height, scale });
25517
- renderCtx.drawMode = 'print';
25518
- const doc = printPages[i];
25519
- const tmp = ElementUtil.cloneRect(doc.rect);
25520
- doc.rect.x = 0;
25521
- doc.rect.y = 0;
25522
- this.beforeRenderEvent.next({ index: i, renderCtx, docRender: doc });
25523
- ElementPaint.drawPage(renderCtx, this.docCtx, doc, { x: 0, y: 0 });
25524
- this.afterRenderEvent.next({ index: i, renderCtx, docRender: doc });
25525
- renderCtx.overlaysContext.clear();
25526
- renderCtx.mainContext.fillRect(0, 0, width, height, 'white');
25527
- renderCtx.commit({ width, height, scale }, { x: 0, y: 0 });
25528
- doc.rect = tmp;
25529
- canvasList.push(canvasNode);
25530
- }
25531
- return canvasList;
25532
- }
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
+ // }
25533
25596
  getSvgNodes(docRenders, printRanges = null) {
25534
25597
  const docSvgHelper = new DocumentSvg(this.viewOptions, new Map(), this.renderCtx); //.getHTMLVNode(docRenders) as Array<EditorVNodeObject>;
25535
25598
  docSvgHelper.mode = 'print';
25536
- const pageSvgVNodes = docRenders.filter((item, index) => !printRanges || printRanges.indexOf(index) >= 0).map(item => docSvgHelper.getPageSvgVNode(item));
25537
25599
  const patch = init([
25538
25600
  modules.class,
25539
25601
  modules.props,
25540
25602
  modules.attributes,
25541
25603
  modules.style
25542
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
+ });
25543
25617
  const domNodes = pageSvgVNodes.map(item => patch(item)); //.map(item => docParser.parseFromString(item, 'text/html').firstChild) as Array<HTMLElement>;
25544
25618
  return domNodes;
25545
25619
  }
@@ -25772,7 +25846,7 @@ class EditorCalendarVNode {
25772
25846
  on: {
25773
25847
  change: (event) => {
25774
25848
  if (moment__default["default"](event.target.value, 'HH:mm:ss').isValid()) {
25775
- this.selectedTime = event.target.value;
25849
+ this.selectedTime.value = event.target.value;
25776
25850
  }
25777
25851
  else {
25778
25852
  event.target.value = this.currTime.value;
@@ -26839,8 +26913,8 @@ class DocEditor {
26839
26913
  */
26840
26914
  getCurrentDataElement() {
26841
26915
  const selectionState = this.documentSelection.selectionState;
26842
- const { startControl, startOffset } = selectionState;
26843
- if (startControl) {
26916
+ const { startControl, startOffset, collapsed } = selectionState;
26917
+ if (startControl && collapsed) {
26844
26918
  if (!ElementUtil.verifyHitable(startControl)) {
26845
26919
  return null;
26846
26920
  }
@@ -27244,7 +27318,7 @@ class DocEditor {
27244
27318
  const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
27245
27319
  const index = docRender.getIndex();
27246
27320
  const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
27247
- this.selectionState.surround(element);
27321
+ this.selectionState.resetRange(element, 0);
27248
27322
  if (cursorPos.rect.y - this.viewOptions.pageOffset.y > 0 && cursorPos.rect.y - this.viewOptions.pageOffset.y < this.viewOptions.viewSettings.height) {
27249
27323
  return;
27250
27324
  }