@hailin-zheng/editor-core 1.0.61 → 1.0.62

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/README.md CHANGED
@@ -79,7 +79,7 @@
79
79
  * <a href="#setCellBackground">setCellBackground 表格背景颜色</a>
80
80
 
81
81
  <h3 id="summary"><code>简介</code></h3>
82
- 编辑器 基于 ts+canvas。运行环境新版浏览器。
82
+ 编辑器 基于 ts+canvas。运行环境现代主流浏览器(chrome等)。
83
83
 
84
84
  <h3 id="install"><code>安装</code></h3>
85
85
  执行 npm i editor-core,安装编辑器。从 “editor-core” 可以引入编辑器类editor-core、loadDoc等导出的属性方法。
@@ -1635,7 +1635,96 @@ const getSelectionState = (): SelectionState => getEditor().selectionState;
1635
1635
  ```
1636
1636
  <!-- /div -->
1637
1637
 
1638
-
1638
+ <h3>如果当前性别为男性,隐藏月经史数据元</h3>
1639
+ ```js
1640
+ //获取文档上下文
1641
+ const docEleCtx = this.docCtx.getCtx(this.docCtx.document);
1642
+ //获取年龄数据元
1643
+ const dataEle = docEleCtx.getControlById('1493477712134672386') as DataElementText;
1644
+ //获取要隐藏的数据组
1645
+ const dataGroup = docEleCtx.ctx.treeFind((item) => item instanceof DataElementGroupElement) as DataElementGroupElement;
1646
+ //侦听数据元更改时间
1647
+ dataEle.onChangeSubject.subscribe((e) => {
1648
+ //在文档重新排版、绘制前,获取最终的指定节点的内容
1649
+ const beforeRefreshSub = this.onBeforeRefreshDocument.subscribe((e2) => {
1650
+ console.log('内容发生改变,隐藏数据组');
1651
+ //获取年龄数据元输入的值
1652
+ const age = Number.parseInt(dataEle.getValue());
1653
+ //年龄大于20,隐藏数据元
1654
+ dataGroup.props.hidden = age > 20;
1655
+ //取消订阅事件
1656
+ beforeRefreshSub.unsubscribe();
1657
+ });
1658
+
1659
+ });
1660
+ ```
1661
+ <h3>插入新段落</h3>
1662
+ 说明:在当前段落后面插入新段落,段落的内容为当前时间
1663
+
1664
+ ```typescript
1665
+ const {startControl} = this.selectionState;
1666
+ if (!startControl) {
1667
+ return;
1668
+ }
1669
+ //1.获取当前段落
1670
+ const currentParagraph = ElementUtil.getParentByType(startControl, ParagraphElement) as ParagraphElement;
1671
+ //2.创建新段落对象
1672
+ const newPara = ParagraphElement.createElement();
1673
+ //3.创建文本对象
1674
+ const newText = new TextGroupElement();
1675
+ newText.text = '当前时间为' + new Date();
1676
+ newText.props.fontName = '楷体';
1677
+ newText.props.fontSize = 18;
1678
+ newText.props.color = '#5b8c00';
1679
+ //4.将文本对象追加到新段落中
1680
+ newPara.addChild(newText);
1681
+ //5.在当前段落后面追加新段落
1682
+ currentParagraph.parent.addChild(newPara, currentParagraph.getIndex() + 1);
1683
+ //6.定位光标到新段落末尾处
1684
+ this.selectionState.resetRange(newText,-1);
1685
+ ```
1686
+ <h3>插入文本数据元</h3>
1687
+ 说明:在当前位置插入文本数据元
1688
+ ```typescript
1689
+ const {startControl} = this.selectionState;
1690
+ if (!startControl) {
1691
+ return;
1692
+ }
1693
+ const newDataTextElement=new DataElementText();
1694
+ newDataTextElement.props.nullText='请输入内容';
1695
+ newDataTextElement.props.nullTextProps=new TextProps();
1696
+ newDataTextElement.props.nullTextProps.fontSize=16;
1697
+ newDataTextElement.props.nullTextProps.fontName='宋体';
1698
+ newDataTextElement.props.nullTextProps.color='#ffc53d';
1699
+ newDataTextElement.props.valueTextProps=new TextProps();
1700
+ newDataTextElement.props.valueTextProps.fontSize=18;
1701
+ newDataTextElement.props.valueTextProps.fontName='楷体';
1702
+ newDataTextElement.props.valueTextProps.color='#096dd9';
1703
+ this.insertNewElement(newDataTextElement);
1704
+ ```
1705
+ <h3>修改页眉</h3>
1706
+ 说明:可以批量修改所有模板的页眉
1707
+ ```typescript
1708
+ //1.获取页眉对象
1709
+ const headerElement=this.docCtx.document.headerElement;
1710
+
1711
+ //2.创建新段落对象
1712
+ const newPara = ParagraphElement.createElement();
1713
+ //3.段落文本居中显示
1714
+ newPara.props.textAlign='center';
1715
+ //4.创建文本对象
1716
+ const newText = new TextGroupElement();
1717
+ newText.text = 'XXX人民医院病历文书';
1718
+ newText.props.fontName = '楷体';
1719
+ newText.props.fontSize = 28;
1720
+ newText.props.color = '#000';
1721
+ //5.将文本对象追加到新段落中
1722
+ newPara.addChild(newText);
1723
+
1724
+ //6.清除页眉内容,并添加新内容
1725
+ headerElement.clearItems();
1726
+ headerElement.addChild(newPara);
1727
+ ```
1639
1728
  <!--
1640
1729
  编辑页脚页眉
1641
1730
  双击页眉,body,页脚 开启是否可编辑,默认body 是可编辑;
package/index-cjs.js CHANGED
@@ -1472,6 +1472,8 @@ class ViewOptions {
1472
1472
  pageNumOffset = 0;
1473
1473
  //页排版模式:单页模式、多页模式、适应页宽模式
1474
1474
  pageLayoutMode = 'singlePage';
1475
+ //默认tab缩进的量
1476
+ defaultIndent = 20;
1475
1477
  //内容区宽度,受审阅窗口宽度影响
1476
1478
  get contentWidth() {
1477
1479
  if (this.showReviewWindow) {
@@ -1734,6 +1736,12 @@ class TextProps extends INotifyPropertyChanged {
1734
1736
  && this.border === props.border;
1735
1737
  }
1736
1738
  }
1739
+ exports.ParagraphNumberType = void 0;
1740
+ (function (ParagraphNumberType) {
1741
+ ParagraphNumberType[ParagraphNumberType["none"] = -1] = "none";
1742
+ ParagraphNumberType[ParagraphNumberType["ul"] = 0] = "ul";
1743
+ ParagraphNumberType[ParagraphNumberType["ol"] = 1] = "ol";
1744
+ })(exports.ParagraphNumberType || (exports.ParagraphNumberType = {}));
1737
1745
  class ParagraphProps extends INotifyPropertyChanged {
1738
1746
  //段落默认的文本属性
1739
1747
  //textProps!: TextProps;
@@ -1741,7 +1749,7 @@ class ParagraphProps extends INotifyPropertyChanged {
1741
1749
  hanging = 0;
1742
1750
  lineHeight = 1.3;
1743
1751
  textAlign = 'left';
1744
- numberType = -1;
1752
+ numberType = exports.ParagraphNumberType.none;
1745
1753
  pageBreak = false;
1746
1754
  clone(dest = null) {
1747
1755
  const clone = dest ?? new ParagraphProps();
@@ -1769,7 +1777,7 @@ class ParagraphProps extends INotifyPropertyChanged {
1769
1777
  if (this.textAlign && this.textAlign !== "left") {
1770
1778
  props["textAlign"] = this.textAlign;
1771
1779
  }
1772
- if (this.numberType !== -1) {
1780
+ if (this.numberType !== exports.ParagraphNumberType.none) {
1773
1781
  props["numberType"] = this.numberType;
1774
1782
  }
1775
1783
  if (this.pageBreak) {
@@ -2379,6 +2387,13 @@ class ValidateProps {
2379
2387
  id;
2380
2388
  title;
2381
2389
  msg;
2390
+ clone(dest) {
2391
+ const clone = dest ?? new ValidateProps();
2392
+ clone.id = this.id;
2393
+ clone.title = this.title;
2394
+ clone.msg = this.msg;
2395
+ return clone;
2396
+ }
2382
2397
  }
2383
2398
  class DataElementGroupProps {
2384
2399
  id;
@@ -3301,6 +3316,19 @@ class ParagraphElement extends BlockContentElement {
3301
3316
  }
3302
3317
  }
3303
3318
  }, true);
3319
+ this.addEvent('ElementKeyDown', evt => {
3320
+ //当前存在缩进,点击tab
3321
+ if (evt.sourceEvent.keyCode === 9) {
3322
+ const { startControl, startOffset } = evt.selectionState;
3323
+ if (startOffset === 0 && startControl === this.getChild(0)) {
3324
+ const defaultIndent = evt.ctx.viewOptions.defaultIndent;
3325
+ let increaseValue = evt.sourceEvent.shiftKey ? -defaultIndent : defaultIndent;
3326
+ this.props.indent += increaseValue;
3327
+ evt.isCancel = true;
3328
+ evt.sourceEvent.preventDefault();
3329
+ }
3330
+ }
3331
+ }, true);
3304
3332
  }
3305
3333
  /**
3306
3334
  * 设置样式
@@ -3348,25 +3376,39 @@ class ParagraphRenderObject extends MuiltBlockLineRenderObject {
3348
3376
  */
3349
3377
  drawProjectNumber(ctx, viewOptions) {
3350
3378
  const paraElement = this.element;
3351
- if (paraElement.props.numberType >= 0) {
3379
+ if (paraElement.props.numberType !== exports.ParagraphNumberType.none) {
3352
3380
  if (paraElement.paintRenders.indexOf(this) > 0) {
3353
3381
  return;
3354
3382
  }
3355
3383
  const firstLine = this.getChild(0);
3356
- if (!firstLine) {
3357
- debugger;
3358
- }
3359
3384
  const firstInline = firstLine.getChild(0);
3360
- if (!firstInline) {
3361
- debugger;
3362
- }
3363
3385
  const firstInlinePaintPos = ElementUtil.getRenderAbsolutePaintPos(firstInline, {
3364
3386
  x: 0,
3365
3387
  y: -viewOptions.translateY
3366
3388
  });
3367
- const numberSymbolY = firstInlinePaintPos.y + Math.ceil(firstInline.rect.height / 2);
3368
- //ctx.contentContext.drawText(str, textProps, firstInlinePaintPos.x - paraElement.paraProps.indent, numberSymbolY, 14, 14);
3369
- ctx.contentContext.fillCircular(firstInlinePaintPos.x - paraElement.props.indent + 2, numberSymbolY, 4);
3389
+ if (paraElement.props.numberType === exports.ParagraphNumberType.ul) {
3390
+ const numberSymbolY = firstInlinePaintPos.y + Math.ceil(firstInline.rect.height / 2);
3391
+ ctx.contentContext.fillCircular(firstInlinePaintPos.x - paraElement.props.indent + 2, numberSymbolY, 4);
3392
+ }
3393
+ else if (paraElement.props.numberType === exports.ParagraphNumberType.ol) {
3394
+ const parent = paraElement.parent;
3395
+ let i = paraElement.getIndex() - 1;
3396
+ for (; i >= 0; i--) {
3397
+ if (parent.getChild(i) instanceof ParagraphElement) {
3398
+ //紧挨上面的段落
3399
+ const prevSiblingPara = parent.getChild(i);
3400
+ if (prevSiblingPara.props.numberType !== paraElement.props.numberType || prevSiblingPara.props.indent !== paraElement.props.indent) {
3401
+ break;
3402
+ }
3403
+ }
3404
+ }
3405
+ const olText = (paraElement.getIndex() - i) + '.';
3406
+ const textProps = new TextProps();
3407
+ textProps.color = '#000';
3408
+ textProps.fontSize = firstInline.rect.height - 4;
3409
+ textProps.fontName = '宋体';
3410
+ ctx.contentContext.drawText(olText, textProps, firstInlinePaintPos.x - paraElement.props.indent + 2, firstInlinePaintPos.y + 2, 40, textProps.fontSize);
3411
+ }
3370
3412
  }
3371
3413
  }
3372
3414
  clone() {
@@ -7045,7 +7087,14 @@ class CommContentElement extends CommContentBaseElement {
7045
7087
  };
7046
7088
  }
7047
7089
  clone(data) {
7048
- throw new Error('不支持');
7090
+ const clone = new CommContentElement();
7091
+ this.props.clone(clone.props);
7092
+ if (data) {
7093
+ for (let i = 0; i < this.length; i++) {
7094
+ clone.addChild(this.getChild(i).clone(true));
7095
+ }
7096
+ }
7097
+ return clone;
7049
7098
  }
7050
7099
  }
7051
7100
  class CommContentRenderObject extends CommContentBaseRenderObject {
@@ -7061,7 +7110,10 @@ class CommContentRenderObject extends CommContentBaseRenderObject {
7061
7110
  });
7062
7111
  const commMarkLinePos = ElementUtil.getParaLinePos(this.commMarkRender.render, commMarkPos);
7063
7112
  commMarkPos.y = commMarkLinePos.y + 2;
7064
- const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender, { x: 0, y: -e.docCtx.viewOptions.translateY });
7113
+ const docRenderPos = ElementUtil.getRenderAbsolutePaintPos(docRender, {
7114
+ x: 0,
7115
+ y: -e.docCtx.viewOptions.translateY
7116
+ });
7065
7117
  const marginLeft = commMarkPos.x - docRenderPos.x - docRender.padding.left;
7066
7118
  const marginRight = e.docCtx.viewOptions.docPageSettings.width - marginLeft - docRender.padding.right * 2;
7067
7119
  e.render.overlaysContext.drawDashLine([commMarkPos, {
@@ -7258,7 +7310,14 @@ class ValidateElement extends CommContentBaseElement {
7258
7310
  return null;
7259
7311
  }
7260
7312
  clone(data) {
7261
- throw new Error("Method not implemented.");
7313
+ const clone = new ValidateElement();
7314
+ this.props.clone(clone.props);
7315
+ if (data) {
7316
+ for (let i = 0; i < this.length; i++) {
7317
+ clone.addChild(this.getChild(i).clone(true));
7318
+ }
7319
+ }
7320
+ return clone;
7262
7321
  }
7263
7322
  setContent(content) {
7264
7323
  this.clearItems();
@@ -11666,63 +11725,6 @@ class DocumentPaint {
11666
11725
  }
11667
11726
  }
11668
11727
 
11669
- /**
11670
- * 段落行
11671
- */
11672
- class ParaLineElement extends LeafElement {
11673
- constructor() {
11674
- super('p-line');
11675
- this.props = new ParaLineProps();
11676
- }
11677
- clone(data) {
11678
- const clone = new ParaLineElement();
11679
- this.props.clone(clone.props);
11680
- return clone;
11681
- }
11682
- createRenderObject(options, renderCtx) {
11683
- const render = new ParaLineRenderObject(this);
11684
- render.rect.width = 9999;
11685
- return render;
11686
- }
11687
- serialize(viewOptions) {
11688
- return {
11689
- type: this.type,
11690
- props: {
11691
- ...this.props
11692
- }
11693
- };
11694
- }
11695
- }
11696
- class ParaLineRenderObject extends LeafRenderObject {
11697
- clone() {
11698
- const clone = new ParaLineRenderObject(this.element);
11699
- clone.rect = ElementUtil.cloneRect(this.rect);
11700
- return clone;
11701
- }
11702
- render(e) {
11703
- const { render, position } = e;
11704
- render.contentContext.drawHoriLine(position.x, position.y, this.parent.rect.width, 'black', 1);
11705
- }
11706
- }
11707
- class ParaLineElementFactory extends ElementFactory {
11708
- createElement(data, renderCtx) {
11709
- const ele = new ParaLineElement();
11710
- ele.props.lineType = data.props?.lineType ?? 'solid';
11711
- return ele;
11712
- }
11713
- match(type) {
11714
- return type === 'p-line';
11715
- }
11716
- }
11717
- class ParaLineProps {
11718
- lineType = 'solid';
11719
- clone(dest) {
11720
- const clone = dest ?? new ParaLineProps();
11721
- clone.lineType = this.lineType;
11722
- return clone;
11723
- }
11724
- }
11725
-
11726
11728
  class ElementReader {
11727
11729
  docCtx;
11728
11730
  renderCtx;
@@ -11764,7 +11766,6 @@ class ElementReader {
11764
11766
  this.addFactory(RunElementFactory);
11765
11767
  this.addFactory(DataElementGroupFactory);
11766
11768
  this.addFactory(DocumentBodyPartFactory);
11767
- this.addFactory(ParaLineElementFactory);
11768
11769
  // this.registerReadFunc<TrackRunProps>('ins-run', (data) => {
11769
11770
  // const props = new TrackRunProps(data.type);
11770
11771
  // props.userId = data.userId;
@@ -14444,12 +14445,12 @@ class DocumentChange {
14444
14445
  }
14445
14446
  const para = ElementUtil.getParentByType(startControl, ParagraphElement);
14446
14447
  const format = {};
14447
- if (para.props.numberType >= 0) {
14448
- format.numberType = -1;
14448
+ if (para.props.numberType !== exports.ParagraphNumberType.none) {
14449
+ format.numberType = exports.ParagraphNumberType.none;
14449
14450
  format.indent = 0;
14450
14451
  }
14451
14452
  else {
14452
- format.numberType = 0;
14453
+ format.numberType = exports.ParagraphNumberType.ul;
14453
14454
  format.indent = 15;
14454
14455
  }
14455
14456
  para.setFormat(format);
@@ -16668,27 +16669,6 @@ class CanvasTextEditor {
16668
16669
  }
16669
16670
  this.flushToSchedule();
16670
16671
  }
16671
- test2() {
16672
- //获取文档上下文
16673
- const docEleCtx = this.docCtx.getCtx(this.docCtx.document);
16674
- //获取年龄数据元
16675
- const dataEle = docEleCtx.getControlById('1493477712134672386');
16676
- //获取要隐藏的数据组
16677
- const dataGroup = docEleCtx.ctx.treeFind((item) => item instanceof DataElementGroupElement);
16678
- //侦听数据元更改时间
16679
- dataEle.onChangeSubject.subscribe((e) => {
16680
- //在文档重新排版、绘制前,获取最终的指定节点的内容
16681
- const beforeRefreshSub = this.onBeforeRefreshDocument.subscribe((e2) => {
16682
- console.log('内容发生改变,隐藏数据组');
16683
- //获取年龄数据元输入的值
16684
- const age = Number.parseInt(dataEle.getValue());
16685
- //年龄大于20,隐藏数据元
16686
- dataGroup.props.hidden = age > 20;
16687
- //取消订阅事件
16688
- beforeRefreshSub.unsubscribe();
16689
- });
16690
- });
16691
- }
16692
16672
  }
16693
16673
 
16694
16674
  /**