@hailin-zheng/editor-core 2.1.11 → 2.1.13

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
@@ -2237,7 +2237,7 @@ class DataEleBaseProps extends INotifyPropertyChanged {
2237
2237
  required;
2238
2238
  printable;
2239
2239
  secretBrowse;
2240
- editable;
2240
+ editable = true;
2241
2241
  deleteable;
2242
2242
  minLength;
2243
2243
  underline;
@@ -4900,7 +4900,7 @@ class TextGroupRenderObject extends LeafRenderObject {
4900
4900
  const arr = [];
4901
4901
  let text = '';
4902
4902
  this.textMeasures.reduce((prev, curr) => {
4903
- if (curr.char !== ' ') {
4903
+ if (curr.char !== ' ' && curr.char !== '\n' && curr.char !== '\r') {
4904
4904
  arr.push(prev);
4905
4905
  text += curr.char;
4906
4906
  }
@@ -5241,7 +5241,7 @@ class SelectionRange {
5241
5241
  }
5242
5242
  else if (control instanceof BranchElement) {
5243
5243
  if (offset > control.length) {
5244
- throw new Error('超索引');
5244
+ offset = control.length - 1;
5245
5245
  }
5246
5246
  if (offset === control.length) {
5247
5247
  const child = control.getChild(offset - 1);
@@ -10023,6 +10023,103 @@ class RadioBoxRenderObject extends LeafRenderObject {
10023
10023
  }
10024
10024
  }
10025
10025
 
10026
+ /**
10027
+ * 强制分页符号
10028
+ */
10029
+ class PageBreakElement extends LeafElement {
10030
+ textProps;
10031
+ constructor() {
10032
+ super('page-br');
10033
+ this.textProps = new TextProps();
10034
+ this.textProps.fontSize = 14;
10035
+ this.textProps.fontName = '宋体';
10036
+ this.textProps.color = '#1890ff';
10037
+ }
10038
+ createRenderObject() {
10039
+ const symbol = new PageBreakRenderObject(this);
10040
+ symbol.rect.height = 14;
10041
+ symbol.rect.width = 7;
10042
+ return symbol;
10043
+ }
10044
+ serialize() {
10045
+ return {
10046
+ type: 'page-br',
10047
+ props: {}
10048
+ };
10049
+ }
10050
+ clone() {
10051
+ const clone = new PageBreakElement();
10052
+ //clone.renderCtx = this.renderCtx;
10053
+ return clone;
10054
+ }
10055
+ }
10056
+ class PageBreakRenderObject extends LeafRenderObject {
10057
+ render(e) {
10058
+ const { render, position } = e;
10059
+ if (render.drawMode === 'print') {
10060
+ return;
10061
+ }
10062
+ render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
10063
+ }
10064
+ clone() {
10065
+ const render = new PageBreakRenderObject(this.element);
10066
+ render.rect = ElementUtil.cloneRect(this.rect);
10067
+ return render;
10068
+ }
10069
+ }
10070
+ class PageBreakFactory extends ElementFactory {
10071
+ match(type) {
10072
+ return type === 'page-br';
10073
+ }
10074
+ createElement(data) {
10075
+ return new PageBreakElement();
10076
+ }
10077
+ }
10078
+
10079
+ class TabElement extends LeafElement {
10080
+ constructor() {
10081
+ super('tab');
10082
+ }
10083
+ createRenderObject() {
10084
+ const symbol = new TabRenderObject(this);
10085
+ symbol.rect.height = 14;
10086
+ symbol.rect.width = 28;
10087
+ return symbol;
10088
+ }
10089
+ serialize() {
10090
+ return {
10091
+ type: 'tab',
10092
+ props: {}
10093
+ };
10094
+ }
10095
+ clone() {
10096
+ return new TabElement();
10097
+ }
10098
+ }
10099
+ class TabRenderObject extends LeafRenderObject {
10100
+ render(e) {
10101
+ const { render, position } = e;
10102
+ if (render.drawMode === 'print') {
10103
+ return;
10104
+ }
10105
+ //render.contentContext.fillRect(position.x,position.y,this.rect.width,this.rect.height,'red');
10106
+ }
10107
+ clone() {
10108
+ const render = new TabRenderObject(this.element);
10109
+ render.rect = ElementUtil.cloneRect(this.rect);
10110
+ return render;
10111
+ }
10112
+ }
10113
+ class TabFactory extends ElementFactory {
10114
+ match(type) {
10115
+ return type === 'tab';
10116
+ }
10117
+ createElement(data) {
10118
+ const ele = new TabElement();
10119
+ return ele;
10120
+ }
10121
+ }
10122
+
10026
10123
  class ColumnPatchUtil {
10027
10124
  static getPatchPacks(cols, splitCols) {
10028
10125
  const oldLinePointMap = this.getLinePointMap(cols);
@@ -13974,50 +14071,6 @@ class DynamicContextParser {
13974
14071
  }
13975
14072
  }
13976
14073
 
13977
- class TabElement extends LeafElement {
13978
- constructor() {
13979
- super('tab');
13980
- }
13981
- createRenderObject() {
13982
- const symbol = new TabRenderObject(this);
13983
- symbol.rect.height = 14;
13984
- symbol.rect.width = 28;
13985
- return symbol;
13986
- }
13987
- serialize() {
13988
- return {
13989
- type: 'tab',
13990
- props: {}
13991
- };
13992
- }
13993
- clone() {
13994
- return new TabElement();
13995
- }
13996
- }
13997
- class TabRenderObject extends LeafRenderObject {
13998
- render(e) {
13999
- const { render, position } = e;
14000
- if (render.drawMode === 'print') {
14001
- return;
14002
- }
14003
- //render.contentContext.fillRect(position.x,position.y,this.rect.width,this.rect.height,'red');
14004
- }
14005
- clone() {
14006
- const render = new TabRenderObject(this.element);
14007
- render.rect = ElementUtil.cloneRect(this.rect);
14008
- return render;
14009
- }
14010
- }
14011
- class TabFactory extends ElementFactory {
14012
- match(type) {
14013
- return type === 'tab';
14014
- }
14015
- createElement(data) {
14016
- const ele = new TabElement();
14017
- return ele;
14018
- }
14019
- }
14020
-
14021
14074
  class ParagraphMeasure {
14022
14075
  options;
14023
14076
  renderCtx;
@@ -16369,59 +16422,6 @@ class DocumentPaint {
16369
16422
  }
16370
16423
  }
16371
16424
 
16372
- /**
16373
- * 强制分页符号
16374
- */
16375
- class PageBreakElement extends LeafElement {
16376
- textProps;
16377
- constructor() {
16378
- super('page-br');
16379
- this.textProps = new TextProps();
16380
- this.textProps.fontSize = 14;
16381
- this.textProps.fontName = '宋体';
16382
- this.textProps.color = '#1890ff';
16383
- }
16384
- createRenderObject() {
16385
- const symbol = new PageBreakRenderObject(this);
16386
- symbol.rect.height = 14;
16387
- symbol.rect.width = 7;
16388
- return symbol;
16389
- }
16390
- serialize() {
16391
- return {
16392
- type: 'page-br',
16393
- props: {}
16394
- };
16395
- }
16396
- clone() {
16397
- const clone = new PageBreakElement();
16398
- //clone.renderCtx = this.renderCtx;
16399
- return clone;
16400
- }
16401
- }
16402
- class PageBreakRenderObject extends LeafRenderObject {
16403
- render(e) {
16404
- const { render, position } = e;
16405
- if (render.drawMode === 'print') {
16406
- return;
16407
- }
16408
- render.contentContext.drawText('↩', this.element.textProps, position.x, position.y, 20, this.rect.height);
16409
- }
16410
- clone() {
16411
- const render = new PageBreakRenderObject(this.element);
16412
- render.rect = ElementUtil.cloneRect(this.rect);
16413
- return render;
16414
- }
16415
- }
16416
- class PageBreakFactory extends ElementFactory {
16417
- match(type) {
16418
- return type === 'page-br';
16419
- }
16420
- createElement(data) {
16421
- return new PageBreakElement();
16422
- }
16423
- }
16424
-
16425
16425
  const fontSize = 12;
16426
16426
  const verPadding = 2;
16427
16427
  /**
@@ -16635,6 +16635,9 @@ class ElementReader {
16635
16635
  //this.viewOptions.viewSettings.width = this.viewOptions.docPageSettings.width + 10;
16636
16636
  }
16637
16637
  readElement(data) {
16638
+ if (typeof data === 'string') {
16639
+ data = JSON.parse(data);
16640
+ }
16638
16641
  const type = data.type;
16639
16642
  for (const factory of this.factories) {
16640
16643
  if (factory.match(type)) {
@@ -19164,7 +19167,7 @@ class DocumentChange {
19164
19167
  const dataEle = control.parent;
19165
19168
  //空数据元,并且当前光标处于数据元开始位置
19166
19169
  if (this.canDeleteInlineGroup(dataEle)) {
19167
- this.setCurosrForDeleteAction(dataEle);
19170
+ this.setCursorForDeleteAction(dataEle);
19168
19171
  dataEle.remove();
19169
19172
  return;
19170
19173
  }
@@ -19256,7 +19259,7 @@ class DocumentChange {
19256
19259
  //空数据元,并且当前光标处于数据元开始位置
19257
19260
  if (control.isPrefix) {
19258
19261
  if (this.canDeleteInlineGroup(dataEle)) {
19259
- this.setCurosrForDeleteAction(dataEle);
19262
+ this.setCursorForDeleteAction(dataEle);
19260
19263
  dataEle.remove();
19261
19264
  }
19262
19265
  else {
@@ -19994,23 +19997,42 @@ class DocumentChange {
19994
19997
  console.log('当前单元格列数不足以粘贴');
19995
19998
  return;
19996
19999
  }
19997
- if (pasteTb.length > 1) {
19998
- console.log('当前单元格只能粘贴一行');
19999
- return;
20000
- }
20001
- const pasteRow = pasteTb.getChild(0);
20002
- for (let i = 0; i < pasteRow.length; i++) {
20003
- const pasteCell = pasteRow.getChild(i);
20004
- const targetCell = targetRow.getChild(colIndex + i);
20005
- targetCell.clearItems();
20006
- ElementUtil.getChildrenElements(pasteCell).forEach(item => {
20007
- targetCell.addChild(item.clone(true), -1);
20008
- });
20000
+ // if (pasteTb.length > 1) {
20001
+ // console.log('当前单元格只能粘贴一行');
20002
+ // return;
20003
+ // }
20004
+ const range = new SelectionRange();
20005
+ if (pasteTb.length > targetTb.length - targetRow.getIndex()) {
20006
+ const addRows = pasteTb.length - (targetTb.length - targetRow.getIndex());
20007
+ for (let i = 0; i < addRows; i++) {
20008
+ targetTb.addChild(TableRowElement.createRow(targetTb.props.cols.length));
20009
+ }
20010
+ }
20011
+ for (let j = 0; j < pasteTb.length; j++) {
20012
+ const pasteRow = pasteTb.getChild(j);
20013
+ for (let i = 0; i < pasteRow.length; i++) {
20014
+ const pasteCell = pasteRow.getChild(i);
20015
+ const targetCell = targetTb.getChild(targetRow.getIndex() + j).getChild(colIndex + i);
20016
+ if (targetCell) {
20017
+ //选区开始位置
20018
+ if (j === 0 && i === 0) {
20019
+ range.setStart(targetCell, 0);
20020
+ range.setEnd(targetCell, -1);
20021
+ }
20022
+ else {
20023
+ range.setEnd(targetCell, -1);
20024
+ }
20025
+ targetCell.clearItems();
20026
+ ElementUtil.getChildrenElements(pasteCell).forEach(item => {
20027
+ targetCell.addChild(item.clone(true), -1);
20028
+ });
20029
+ }
20030
+ }
20009
20031
  }
20010
20032
  //设置选区
20011
- const range = new SelectionRange();
20012
- range.setStart(targetRow.getChild(colIndex), 0);
20013
- range.setEnd(targetRow.getChild(colIndex + pasteRow.length - 1), -1);
20033
+ // const range = new SelectionRange();
20034
+ // range.setStart(targetRow.getChild(colIndex), 0);
20035
+ // range.setEnd(targetRow.getChild(colIndex + pasteRow.length - 1), -1);
20014
20036
  this.selectionState.addRange(range);
20015
20037
  }
20016
20038
  insertSoftBr() {
@@ -20150,12 +20172,12 @@ class DocumentChange {
20150
20172
  */
20151
20173
  removeEmptyText(text) {
20152
20174
  //const nextLeafElementInPara = ElementUtil.getRecursionNextSiblingElement(text, true, true); getComputedStyle
20153
- this.setCurosrForDeleteAction(text);
20175
+ this.setCursorForDeleteAction(text);
20154
20176
  const parent = text.parent;
20155
20177
  text.remove();
20156
20178
  this.removeEmtpyInlineBlock(parent);
20157
20179
  }
20158
- setCurosrForDeleteAction(control) {
20180
+ setCursorForDeleteAction(control) {
20159
20181
  const cursorInfo = this.getCursorElementByDeleteAction(control);
20160
20182
  if (cursorInfo) {
20161
20183
  this.selectionState.resetRange(cursorInfo.ele, cursorInfo.offset);
@@ -20167,10 +20189,19 @@ class DocumentChange {
20167
20189
  getCursorElementByDeleteAction(control) {
20168
20190
  if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
20169
20191
  if (control.parent instanceof DataElementInlineGroup) {
20170
- return {
20171
- ele: control.parent.startDecorate,
20172
- offset: 1
20173
- };
20192
+ const prevLeafElementInPara = ElementUtil.getRecursionPrevSiblingElement(control, true, true, this.viewOptions);
20193
+ if (prevLeafElementInPara && ElementUtil.getParent(prevLeafElementInPara, item => item instanceof DataElementInlineGroup)) {
20194
+ return {
20195
+ ele: prevLeafElementInPara,
20196
+ offset: ElementUtil.getElementEndOffset(prevLeafElementInPara)
20197
+ };
20198
+ }
20199
+ else {
20200
+ return {
20201
+ ele: control.parent.startDecorate,
20202
+ offset: 1
20203
+ };
20204
+ }
20174
20205
  }
20175
20206
  }
20176
20207
  const prevLeafElementInPara = ElementUtil.getRecursionPrevSiblingElement(control, false, true, this.viewOptions);
@@ -20337,7 +20368,7 @@ function createPrintTemplate({ width, height, orient }) {
20337
20368
  white-space: pre;
20338
20369
  }
20339
20370
  @page {
20340
- size: ${width}px ${height - 1}px ${orient};
20371
+ size: ${orient};
20341
20372
  margin: 0;
20342
20373
  }
20343
20374
  div {
@@ -27958,6 +27989,20 @@ class DocEditor {
27958
27989
  }
27959
27990
  });
27960
27991
  }
27992
+ /**
27993
+ * 将元素序列化为字符串,和serialize方法不同的是,该方法区别在于对留痕信息的处理
27994
+ * @param ele
27995
+ */
27996
+ serializeString(ele) {
27997
+ return ElementSerialize.serializeString(ele);
27998
+ }
27999
+ /**
28000
+ * 将元素序列化为JSON对象,可进一步操作该对象序列化为JSON对象
28001
+ * @param ele
28002
+ */
28003
+ serialize(ele) {
28004
+ return ElementSerialize.serialize(ele, this.viewOptions);
28005
+ }
27961
28006
  /**
27962
28007
  * 获取选区文本属性
27963
28008
  * @returns
@@ -28239,6 +28284,10 @@ class DocEditor {
28239
28284
  * @param ele
28240
28285
  */
28241
28286
  insertNewElement(ele) {
28287
+ if (ele instanceof TableElement) {
28288
+ this.documentChange.insertTable(ele);
28289
+ return;
28290
+ }
28242
28291
  const { startControl, startOffset } = this.selectionState;
28243
28292
  this.insertElement(startControl, startOffset, [ele]);
28244
28293
  }
@@ -28753,7 +28802,7 @@ class DocEditor {
28753
28802
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
28754
28803
  }
28755
28804
  version() {
28756
- return "2.1.11";
28805
+ return "2.1.13";
28757
28806
  }
28758
28807
  switchPageHeaderEditor() {
28759
28808
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -29075,6 +29124,9 @@ exports.OnceSubject = OnceSubject;
29075
29124
  exports.PSymbolElement = PSymbolElement;
29076
29125
  exports.PSymbolRenderObject = PSymbolRenderObject;
29077
29126
  exports.PaddingProps = PaddingProps;
29127
+ exports.PageBreakElement = PageBreakElement;
29128
+ exports.PageBreakFactory = PageBreakFactory;
29129
+ exports.PageBreakRenderObject = PageBreakRenderObject;
29078
29130
  exports.PageOptions = PageOptions;
29079
29131
  exports.PaintContent = PaintContent;
29080
29132
  exports.ParagraphElement = ParagraphElement;
@@ -29102,6 +29154,9 @@ exports.SelectionState = SelectionState;
29102
29154
  exports.Subject = Subject$1;
29103
29155
  exports.SubjectSubscription = SubjectSubscription$1;
29104
29156
  exports.Subscription = Subscription$1;
29157
+ exports.TabElement = TabElement;
29158
+ exports.TabFactory = TabFactory;
29159
+ exports.TabRenderObject = TabRenderObject;
29105
29160
  exports.TableCellElement = TableCellElement;
29106
29161
  exports.TableCellFactory = TableCellFactory;
29107
29162
  exports.TableCellProps = TableCellProps;