@hailin-zheng/editor-core 2.2.16 → 2.2.18

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.js CHANGED
@@ -1720,18 +1720,26 @@ class ViewOptions {
1720
1720
  dataEleEmptyBgColor = '';
1721
1721
  //数据元鼠标悬浮颜色
1722
1722
  dataEleMouseEnterBgColor = '#d9d9d9';
1723
+ dataEleMouseEnterDecoratorMode = 'background';
1723
1724
  //数据元只读背景颜色
1724
1725
  dataEleReadOnlyBgColor = '#d9d9d9';
1725
1726
  //数据元焦点背景颜色
1726
1727
  dataEleFocusedBgColor = '#d9d9d9';
1728
+ dataEleFocusedDecoratorMode = 'background';
1727
1729
  //数据元正常背景颜色
1728
1730
  dataEleNormalBgColor = '#fafafa';
1731
+ //数据元外部框线颜色
1732
+ dataEleOutlineColor = '#0050b3';
1733
+ //数据组外部框线颜色
1734
+ dataGroupOutlineColor = '#0050b3';
1729
1735
  //数据元错误背景颜色
1730
1736
  dataEleErrorBgColor = '#ff4d4f';
1731
1737
  //数据组修饰符号颜色
1732
1738
  dataGroupDecoratorNormalColor = '#0050b3';
1733
1739
  dataGroupDecoratorMouseEnterColor = '#0050b3';
1740
+ dataGroupMouseEnterDecoratorMode = 'outline';
1734
1741
  dataGroupDecoratorFocusedColor = '#0050b3';
1742
+ dataGroupFocusedDecoratorMode = 'outline';
1735
1743
  //数据组正常背景颜色
1736
1744
  dataGroupNormalBgColor = '#fafafa';
1737
1745
  //数据元没有输入值时背景颜色
@@ -1752,8 +1760,6 @@ class ViewOptions {
1752
1760
  trackDelColor = '#000';
1753
1761
  showLineRect;
1754
1762
  showCharRect;
1755
- //数据元交互修饰模式
1756
- dataEleDecoratorMode = 'outline';
1757
1763
  showTabChar;
1758
1764
  showSpaceChar;
1759
1765
  showLineBreak;
@@ -3730,7 +3736,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3730
3736
  },
3731
3737
  },
3732
3738
  children: [
3733
- pageCorner, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection, copyright
3739
+ pageCorner, highlight, selection, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, copyright
3734
3740
  ]
3735
3741
  };
3736
3742
  }
@@ -3846,17 +3852,18 @@ class InlineGroupInputElement extends InlineGroupElement {
3846
3852
  endDecorate;
3847
3853
  constructor(type) {
3848
3854
  super(type);
3849
- //行内块不允许换行
3850
- this.addEvent('ElementKeyDown', (evt) => {
3851
- const { selectionState, sourceEvent, source } = evt;
3852
- const { startControl, startOffset } = selectionState;
3853
- if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
3854
- if (sourceEvent.shiftKey && sourceEvent.keyCode === 13) ;
3855
- else if (!sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
3856
- evt.isCancel = true;
3857
- }
3858
- }
3859
- }, true);
3855
+ // //行内块不允许换行
3856
+ // this.addEvent<KeyboradElementEvent>('ElementKeyDown', (evt) => {
3857
+ // const { selectionState, sourceEvent, source } = evt;
3858
+ // const { startControl, startOffset } = selectionState;
3859
+ // if (IsInSideInlineGroupInputElement(startControl as LeafElement, startOffset)) {
3860
+ // if (sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
3861
+ // //this.removeNullText();
3862
+ // } else if (!sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
3863
+ // evt.isCancel = true;
3864
+ // }
3865
+ // }
3866
+ // }, true);
3860
3867
  this.addEvent('GotCursor', (evt) => {
3861
3868
  const { startControl, startOffset } = evt.selectionState;
3862
3869
  if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
@@ -4056,7 +4063,11 @@ class DataElementInlineGroup extends InlineGroupInputElement {
4056
4063
  }
4057
4064
  });
4058
4065
  }
4059
- this.parserExpress = { compliedCode, func: new Function(`with(this){ ${compliedCode} }`), depItems: depEleMap };
4066
+ this.parserExpress = {
4067
+ compliedCode,
4068
+ func: new Function(`with(this){ ${compliedCode} }`),
4069
+ depItems: depEleMap
4070
+ };
4060
4071
  }
4061
4072
  catch (e) {
4062
4073
  console.error('解析表达式出错,parseEleExpression', this.props.expression);
@@ -4173,6 +4184,7 @@ function exportDataEleDecoratorSVG$1(event, r) {
4173
4184
  return;
4174
4185
  }
4175
4186
  const options = event.options;
4187
+ let mode = 'background';
4176
4188
  let color = options.dataEleNormalBgColor;
4177
4189
  //空数据元填充颜色
4178
4190
  if (r.element.length === 2 && options.dataEleEmptyBgColor) {
@@ -4180,17 +4192,69 @@ function exportDataEleDecoratorSVG$1(event, r) {
4180
4192
  }
4181
4193
  if (r.element.isMouseenter && options.dataEleMouseEnterBgColor) {
4182
4194
  color = options.dataEleMouseEnterBgColor;
4195
+ mode = options.dataEleMouseEnterDecoratorMode;
4183
4196
  }
4184
4197
  if (r.element.isFocused && options.dataEleFocusedBgColor) {
4185
4198
  color = options.dataEleFocusedBgColor;
4199
+ mode = options.dataEleFocusedDecoratorMode;
4186
4200
  }
4187
4201
  if (!color) {
4188
4202
  return;
4189
4203
  }
4190
4204
  //绘制背景
4191
- const bgX = event.relativePagePos.x;
4192
- const bgY = event.relativePagePos.y;
4193
- event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4205
+ if (['all', 'background'].includes(mode)) {
4206
+ const bgX = event.relativePagePos.x;
4207
+ const bgY = event.relativePagePos.y;
4208
+ event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4209
+ }
4210
+ if (['all', 'outline'].includes(mode)) {
4211
+ color = event.options.dataEleOutlineColor;
4212
+ const verOffset = 0;
4213
+ const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
4214
+ if (renderPosMap.length > 1) {
4215
+ const secondGroupRenderPos = renderPosMap[1].pos;
4216
+ if (secondGroupRenderPos.x + renderPosMap[1].render.rect.width > event.relativePagePos.x) {
4217
+ const leftPoints = [];
4218
+ const rightPoints = [];
4219
+ for (let i = 0; i < renderPosMap.length; i++) {
4220
+ const groupRender = renderPosMap[i].render;
4221
+ const groupRenderPos = renderPosMap[i].pos;
4222
+ leftPoints.push({ x: groupRenderPos.x, y: groupRenderPos.y - verOffset });
4223
+ rightPoints.push({
4224
+ x: groupRenderPos.x + groupRender.rect.width,
4225
+ y: groupRenderPos.y - verOffset
4226
+ });
4227
+ leftPoints.push({
4228
+ x: groupRenderPos.x,
4229
+ y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4230
+ });
4231
+ rightPoints.push({
4232
+ x: groupRenderPos.x + groupRender.rect.width,
4233
+ y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4234
+ });
4235
+ }
4236
+ const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
4237
+ const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
4238
+ const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ");
4239
+ event.highlights.push(ElementUtil.createSvgPath({
4240
+ d: path,
4241
+ stroke: color,
4242
+ fill: 'none',
4243
+ 'stroke-width': 1
4244
+ }));
4245
+ return;
4246
+ }
4247
+ }
4248
+ for (let i = 0; i < renderPosMap.length; i++) {
4249
+ const currRen = renderPosMap[i];
4250
+ event.highlights.push(ElementUtil.createSvgPath({
4251
+ d: `M${currRen.pos.x} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y + currRen.render.rect.height} L${currRen.pos.x} ${currRen.pos.y + currRen.render.rect.height} Z`,
4252
+ stroke: color,
4253
+ fill: 'none',
4254
+ 'stroke-width': 1
4255
+ }));
4256
+ }
4257
+ }
4194
4258
  // const canPaint = r.element.isMouseenter || r.element.isFocused;
4195
4259
  // if (!canPaint) {
4196
4260
  // return;
@@ -4205,51 +4269,6 @@ function exportDataEleDecoratorSVG$1(event, r) {
4205
4269
  // event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4206
4270
  // return;
4207
4271
  // } else if (mode === 'outline') {
4208
- // const verOffset = 0;
4209
- // const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
4210
- // if (renderPosMap.length > 1) {
4211
- // const secondGroupRenderPos = renderPosMap[1].pos;
4212
- // if (secondGroupRenderPos.x + renderPosMap[1].render.rect.width > event.relativePagePos.x) {
4213
- // const leftPoints: Array<Position> = [];
4214
- // const rightPoints: Array<Position> = [];
4215
- // for (let i = 0; i < renderPosMap.length; i++) {
4216
- // const groupRender = renderPosMap[i].render;
4217
- // const groupRenderPos = renderPosMap[i].pos;
4218
- // leftPoints.push({ x: groupRenderPos.x, y: groupRenderPos.y - verOffset });
4219
- // rightPoints.push({
4220
- // x: groupRenderPos.x + groupRender.rect.width,
4221
- // y: groupRenderPos.y - verOffset
4222
- // });
4223
- // leftPoints.push({
4224
- // x: groupRenderPos.x,
4225
- // y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4226
- // });
4227
- // rightPoints.push({
4228
- // x: groupRenderPos.x + groupRender.rect.width,
4229
- // y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4230
- // });
4231
- // }
4232
- // const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
4233
- // const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
4234
- // const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ")
4235
- // event.highlights.push(ElementUtil.createSvgPath({
4236
- // d: path,
4237
- // stroke: color,
4238
- // fill: 'none',
4239
- // 'stroke-width': 1
4240
- // }));
4241
- // return;
4242
- // }
4243
- // }
4244
- // for (let i = 0; i < renderPosMap.length; i++) {
4245
- // const currRen = renderPosMap[i];
4246
- // event.highlights.push(ElementUtil.createSvgPath({
4247
- // d: `M${currRen.pos.x} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y + currRen.render.rect.height} L${currRen.pos.x} ${currRen.pos.y + currRen.render.rect.height} Z`,
4248
- // stroke: '#0050b3',
4249
- // fill: 'none',
4250
- // 'stroke-width': 1
4251
- // }));
4252
- // }
4253
4272
  // }
4254
4273
  }
4255
4274
  /**
@@ -4356,6 +4375,30 @@ function renderUnderWavyLine(event, r, color) {
4356
4375
  const path = ElementUtil.createSvgPath({ d, fill: 'none', stroke: color });
4357
4376
  event.highlights.push(path);
4358
4377
  }
4378
+ /**
4379
+ * 获取渲染元素相对稳当的位置
4380
+ * @param render
4381
+ * @param refPos
4382
+ */
4383
+ function getRenderPosToDoc(render, refPos = null) {
4384
+ refPos = refPos ?? { x: 0, y: 0 };
4385
+ if (render instanceof DocumentRenderObject) {
4386
+ return refPos;
4387
+ }
4388
+ const currPos = { x: render.rect.x + refPos.x, y: render.rect.y + refPos.y };
4389
+ return getRenderPosToDoc(render.parent, currPos);
4390
+ }
4391
+ function getCurrentParaGroupRenders(r) {
4392
+ const renders = [];
4393
+ const currParaRender = ElementUtil.getParentRender(r, ParagraphRenderObject);
4394
+ for (let i = 0; i < r.element.paintRenders.length; i++) {
4395
+ const paraRender = ElementUtil.getParentRender(r.element.paintRenders[i], ParagraphRenderObject);
4396
+ if (paraRender === currParaRender) {
4397
+ renders.push(r.element.paintRenders[i]);
4398
+ }
4399
+ }
4400
+ return renders;
4401
+ }
4359
4402
  function renderUnderline(event, render) {
4360
4403
  const { x, y } = event.relativePagePos;
4361
4404
  event.highlights.push({
@@ -4452,7 +4495,7 @@ class PSymbolElement extends LeafElement {
4452
4495
  }
4453
4496
  createRenderObject() {
4454
4497
  const symbol = new PSymbolRenderObject(this);
4455
- symbol.rect.height = this.defaultHeight;
4498
+ symbol.rect.height = Math.ceil(this.defaultHeight * TEXT_HEIGHT_FACTOR);
4456
4499
  symbol.rect.width = 1;
4457
4500
  return symbol;
4458
4501
  }
@@ -4474,12 +4517,20 @@ class PSymbolRenderObject extends LeafRenderObject {
4474
4517
  if (!event.options.showEnterSymbol || event.mode === 'print') {
4475
4518
  return null;
4476
4519
  }
4477
- return ElementUtil.createSvgText('↵', { 'dominant-baseline': 'hanging',
4478
- 'font-family': 'Courier',
4479
- 'font-size': this.element.defaultHeight,
4520
+ const font = `14px 宋体`;
4521
+ const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(font);
4522
+ let y = this.rect.y;
4523
+ //基线处理
4524
+ y += actualFontBoundingBoxAscent ?? 0;
4525
+ //行高处理
4526
+ y += (this.rect.height - 14) / 2;
4527
+ return ElementUtil.createSvgText('↵', {
4528
+ 'font-family': '宋体',
4529
+ 'font-size': 14,
4480
4530
  x: this.rect.x,
4481
- y: this.rect.y,
4482
- fill: 'green' });
4531
+ y: y,
4532
+ fill: 'green'
4533
+ });
4483
4534
  }
4484
4535
  //绘制段落符号
4485
4536
  clone() {
@@ -8698,7 +8749,7 @@ class BreakElement extends LeafElement {
8698
8749
  }
8699
8750
  createRenderObject() {
8700
8751
  const symbol = new BreakRenderObject(this);
8701
- symbol.rect.height = 14;
8752
+ symbol.rect.height = Math.ceil(14 * TEXT_HEIGHT_FACTOR);
8702
8753
  symbol.rect.width = 7;
8703
8754
  return symbol;
8704
8755
  }
@@ -8719,12 +8770,26 @@ class BreakRenderObject extends LeafRenderObject {
8719
8770
  if (!event.options.showEnterSymbol || event.mode === 'print') {
8720
8771
  return null;
8721
8772
  }
8722
- return ElementUtil.createSvgText('↓', { 'dominant-baseline': 'hanging',
8723
- 'font-family': 'Courier',
8724
- 'font-size': this.rect.height,
8725
- x: this.rect.x + 4,
8726
- y: this.rect.y,
8727
- fill: 'green' });
8773
+ // return ElementUtil.createSvgText( '↓',{ 'dominant-baseline': 'hanging',
8774
+ // 'font-family': 'Courier',
8775
+ // 'font-size': this.rect.height,
8776
+ // x: this.rect.x + 4,
8777
+ // y: this.rect.y,
8778
+ // fill: 'green'});
8779
+ const font = `14px 宋体`;
8780
+ const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(font);
8781
+ let y = 0;
8782
+ //基线处理
8783
+ y += actualFontBoundingBoxAscent ?? 0;
8784
+ //行高处理
8785
+ y += (this.parent.rect.height - 14) / 2;
8786
+ return ElementUtil.createSvgText('↓', {
8787
+ 'font-family': '宋体',
8788
+ 'font-size': 14,
8789
+ x: this.rect.x,
8790
+ y: y,
8791
+ fill: 'green'
8792
+ });
8728
8793
  }
8729
8794
  clone() {
8730
8795
  const render = new BreakRenderObject(this.element);
@@ -8876,23 +8941,76 @@ function exportDataEleDecoratorSVG(event, r) {
8876
8941
  }
8877
8942
  const options = event.options;
8878
8943
  let color = options.dataGroupNormalBgColor;
8944
+ let mode = 'background';
8879
8945
  //空数据元填充颜色
8880
8946
  if (r.element.length === 2 && options.dataGroupEmptyBgColor) {
8881
8947
  color = options.dataGroupEmptyBgColor;
8882
8948
  }
8883
8949
  if (r.element.isMouseenter && options.dataGroupMouseEnterBgColor) {
8884
8950
  color = options.dataGroupMouseEnterBgColor;
8951
+ mode = options.dataGroupMouseEnterDecoratorMode;
8885
8952
  }
8886
8953
  if (r.element.isFocused && options.dataGroupFocusedBgColor) {
8887
8954
  color = options.dataGroupFocusedBgColor;
8955
+ mode = options.dataGroupFocusedDecoratorMode;
8888
8956
  }
8889
8957
  if (!color) {
8890
8958
  return;
8891
8959
  }
8892
8960
  //绘制背景
8893
- const bgX = event.relativePagePos.x;
8894
- const bgY = event.relativePagePos.y;
8895
- event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
8961
+ if (['all', 'background'].includes(mode)) {
8962
+ const bgX = event.relativePagePos.x;
8963
+ const bgY = event.relativePagePos.y;
8964
+ event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
8965
+ }
8966
+ if (['all', 'outline'].includes(mode)) {
8967
+ color = event.options.dataGroupOutlineColor;
8968
+ const verOffset = 0;
8969
+ const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
8970
+ if (renderPosMap.length > 1) {
8971
+ const secondGroupRenderPos = renderPosMap[1].pos;
8972
+ if (secondGroupRenderPos.x + renderPosMap[1].render.rect.width > event.relativePagePos.x) {
8973
+ const leftPoints = [];
8974
+ const rightPoints = [];
8975
+ for (let i = 0; i < renderPosMap.length; i++) {
8976
+ const groupRender = renderPosMap[i].render;
8977
+ const groupRenderPos = renderPosMap[i].pos;
8978
+ leftPoints.push({ x: groupRenderPos.x, y: groupRenderPos.y - verOffset });
8979
+ rightPoints.push({
8980
+ x: groupRenderPos.x + groupRender.rect.width,
8981
+ y: groupRenderPos.y - verOffset
8982
+ });
8983
+ leftPoints.push({
8984
+ x: groupRenderPos.x,
8985
+ y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
8986
+ });
8987
+ rightPoints.push({
8988
+ x: groupRenderPos.x + groupRender.rect.width,
8989
+ y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
8990
+ });
8991
+ }
8992
+ const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
8993
+ const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
8994
+ const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ");
8995
+ event.highlights.push(ElementUtil.createSvgPath({
8996
+ d: path,
8997
+ stroke: color,
8998
+ fill: 'none',
8999
+ 'stroke-width': 1
9000
+ }));
9001
+ return;
9002
+ }
9003
+ }
9004
+ for (let i = 0; i < renderPosMap.length; i++) {
9005
+ const currRen = renderPosMap[i];
9006
+ event.highlights.push(ElementUtil.createSvgPath({
9007
+ d: `M${currRen.pos.x} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y} L${currRen.pos.x + currRen.render.rect.width} ${currRen.pos.y + currRen.render.rect.height} L${currRen.pos.x} ${currRen.pos.y + currRen.render.rect.height} Z`,
9008
+ stroke: color,
9009
+ fill: 'none',
9010
+ 'stroke-width': 1
9011
+ }));
9012
+ }
9013
+ }
8896
9014
  }
8897
9015
 
8898
9016
  class DataElementImage extends DataElementLeaf {
@@ -10859,9 +10977,22 @@ class ElementSerialize {
10859
10977
  const { startCol, endCol } = tbRegion;
10860
10978
  const cloneTb = ElementUtil.cloneRange(range, false, 'copy');
10861
10979
  cloneTb.props.cols = cloneTb.props.cols.slice(startCol, endCol + 1);
10862
- return cloneTb;
10980
+ return [cloneTb];
10863
10981
  }
10864
- return ElementUtil.cloneRange(range, false, 'copy');
10982
+ //元素全选的情况下
10983
+ // if (range.isFullSelected) {
10984
+ // const ele = ElementUtil.cloneRange(range, false, 'copy');
10985
+ // return ele ? [ele] : null;
10986
+ // }
10987
+ //元素部分选中的情况下,只获取选中的部分元素
10988
+ const selectedEle = range.selectedChildren.map(item => ElementUtil.cloneRange(item, false, 'copy'));
10989
+ const list = [];
10990
+ selectedEle.forEach(item => {
10991
+ if (item) {
10992
+ list.push(item);
10993
+ }
10994
+ });
10995
+ return list;
10865
10996
  }
10866
10997
  /**
10867
10998
  * 选中的文本
@@ -10869,18 +11000,19 @@ class ElementSerialize {
10869
11000
  * @param viewOptions
10870
11001
  */
10871
11002
  static getSelectedText(ss, viewOptions) {
10872
- const selectedStruct = this.getSelectedStruct(ss, viewOptions);
10873
- if (selectedStruct) {
10874
- return this.serializeString(selectedStruct);
11003
+ const selectedStructs = this.getSelectedStruct(ss, viewOptions);
11004
+ if (selectedStructs) {
11005
+ return selectedStructs.map(item => this.serializeString(item)).join('');
10875
11006
  }
10876
11007
  else {
10877
11008
  return '';
10878
11009
  }
10879
11010
  }
10880
11011
  static getSelectedJSON(ss, viewOptions) {
10881
- const selectedStruct = this.getSelectedStruct(ss, viewOptions);
10882
- if (selectedStruct) {
10883
- return JSON.stringify(this.serialize(selectedStruct, viewOptions));
11012
+ const selectedStructs = this.getSelectedStruct(ss, viewOptions);
11013
+ if (selectedStructs) {
11014
+ //return JSON.stringify(this.serialize(selectedStructs, viewOptions));
11015
+ return JSON.stringify(selectedStructs.map(item => this.serialize(item, viewOptions)).filter(item => item));
10884
11016
  }
10885
11017
  else {
10886
11018
  return '';
@@ -14191,6 +14323,11 @@ class ParagraphMeasure {
14191
14323
  parent: parentLine,
14192
14324
  isCloseToBody: parentLine.isCloseToBody,
14193
14325
  applyNewLine() {
14326
+ //申请新行前,需要将当前内联元素的宽度扩充到可用最大宽度
14327
+ const space = parentLine.limitWidth - parentLine.lineWidth();
14328
+ if (space > 0) {
14329
+ render.rect.width += space;
14330
+ }
14194
14331
  parentLine.applyNewLine();
14195
14332
  render = ele.createRenderObject({ options, renderCtx, execute });
14196
14333
  parentLine.add(render);
@@ -16797,7 +16934,7 @@ class DocumentEvent {
16797
16934
  this.moveCursorToRightHandle(nextEle, ElementUtil.fixedOffset(nextEle, -1));
16798
16935
  return;
16799
16936
  }
16800
- this.selectionState.resetRange(nextEle, 1);
16937
+ this.selectionState.resetRange(nextEle, 0);
16801
16938
  return;
16802
16939
  }
16803
16940
  }
@@ -17995,6 +18132,9 @@ class DocumentChange {
17995
18132
  const { startControl } = this.selectionState;
17996
18133
  const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
17997
18134
  const breakPara = this.splitCurrentParagraph();
18135
+ if (!breakPara) {
18136
+ return;
18137
+ }
17998
18138
  //选中的是一个元素
17999
18139
  if (breakPara === paragraph) {
18000
18140
  const clonePara = paragraph.clone(false);
@@ -18016,6 +18156,9 @@ class DocumentChange {
18016
18156
  */
18017
18157
  insertLayoutContainer(ele) {
18018
18158
  const breakPara = this.splitCurrentParagraph();
18159
+ if (!breakPara) {
18160
+ return;
18161
+ }
18019
18162
  breakPara.parent.addChild(ele, breakPara.getIndex());
18020
18163
  this.selectionState.resetRange(ele, 0);
18021
18164
  }
@@ -18025,6 +18168,11 @@ class DocumentChange {
18025
18168
  */
18026
18169
  splitCurrentParagraph() {
18027
18170
  const { startControl, startOffset } = this.selectionState;
18171
+ //内联数据块不能拆分两部分
18172
+ if (!this.allowSplitParagraph()) {
18173
+ console.warn("内联数据块不能拆分!");
18174
+ return null;
18175
+ }
18028
18176
  const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
18029
18177
  const paraContainer = paragraph.parent;
18030
18178
  //如果选中的是段落第一个元素
@@ -18445,67 +18593,53 @@ class DocumentChange {
18445
18593
  }
18446
18594
  return;
18447
18595
  }
18448
- const pasteElement = this.eleReader.readElement(JSON.parse(pasteData.doc));
18449
- if (!pasteElement) {
18450
- console.log('粘贴反序列化数据失败', pasteData);
18596
+ let data = JSON.parse(pasteData.doc);
18597
+ const pasteEles = [];
18598
+ data = Array.isArray(data) ? data : [data];
18599
+ data.forEach(item => {
18600
+ const ele = this.eleReader.readElement(item);
18601
+ if (ele) {
18602
+ pasteEles.push(ele);
18603
+ }
18604
+ else {
18605
+ console.log('粘贴反序列化数据失败', item);
18606
+ }
18607
+ });
18608
+ if (!pasteEles.length) {
18451
18609
  return;
18452
18610
  }
18453
18611
  //表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
18454
18612
  if (this.viewOptions.docMode === DocMode.FormEdit) {
18455
- const pasteString = ElementSerialize.serializeString(pasteElement, { all: false });
18613
+ const pasteString = pasteEles.map(item => ElementSerialize.serializeString(item, { all: false })).join('');
18456
18614
  if (pasteString) {
18457
18615
  this.pastePlainText(pasteString);
18458
18616
  }
18459
18617
  return;
18460
18618
  }
18461
- if (pasteElement instanceof ParagraphElement || pasteElement instanceof InlineGroupElement) {
18462
- const children = [];
18463
- if (pasteElement instanceof ParagraphElement) {
18464
- children.push(...ElementUtil.getChildrenElements(pasteElement));
18465
- }
18466
- else if (pasteElement instanceof InlineGroupElement) {
18467
- //当前粘贴的元素为数据元,并且在数据元内部粘贴
18468
- if (IsInSideDataElement(startControl, startOffset) && pasteElement instanceof DataElementInlineGroup) {
18469
- const pasteChildren = pasteElement.getInnerItems().map(item => item.clone(true));
18470
- children.push(...pasteChildren);
18471
- }
18472
- else {
18473
- children.push(pasteElement);
18474
- }
18475
- }
18476
- if (!children.length) {
18477
- throw new Error('段落子元素为空');
18478
- }
18479
- const lastEle = this.insertElement(startControl, startOffset, children);
18480
- this.selectionState.resetRange(lastEle, -1);
18481
- return;
18619
+ //复制的内容为表格,且操作位于单元格内
18620
+ if (pasteEles[0] instanceof TableElement && ElementUtil.getParentByType(startControl, TableCellElement) && pasteEles.length === 1) {
18621
+ this.pasteTableToCell(pasteEles[0]);
18482
18622
  }
18483
- else if (pasteElement instanceof BlockContainerElement) {
18623
+ //复制的为表格或者段落
18624
+ else if (pasteEles[0] instanceof BlockContainerElement || pasteEles[0] instanceof ParagraphElement) {
18484
18625
  const children = [];
18485
- if (pasteElement instanceof TableElement) {
18486
- children.push(pasteElement);
18487
- if (ElementUtil.getParentByType(startControl, TableCellElement)) {
18488
- this.pasteTableToCell(pasteElement);
18489
- return;
18490
- }
18491
- }
18492
- else {
18493
- children.push(...ElementUtil.getChildrenElements(pasteElement));
18494
- }
18495
- //复制的内容全部为段落,执行黏贴操作
18496
- // if (children.every(item => item instanceof ParagraphElement)) {
18497
- // const targetParagraph = this.splitCurrentParagraph();
18498
- // children.forEach((item, i) => {
18499
- // targetParagraph.parent.addChild(item, targetParagraph.getIndex());
18500
- // });
18501
- // this.selectionState.resetRange(children[children.length - 1], -1);
18502
- // }
18626
+ children.push(...pasteEles);
18503
18627
  const targetParagraph = this.splitCurrentParagraph();
18628
+ if (!targetParagraph) {
18629
+ return;
18630
+ }
18504
18631
  children.forEach((item, i) => {
18505
18632
  targetParagraph.parent.addChild(item, targetParagraph.getIndex());
18506
18633
  });
18507
18634
  this.selectionState.resetRange(children[children.length - 1], -1);
18508
18635
  }
18636
+ //符合段落内的元素约定
18637
+ else {
18638
+ const children = [];
18639
+ children.push(...pasteEles);
18640
+ const lastEle = this.insertElement(startControl, startOffset, children);
18641
+ this.selectionState.resetRange(lastEle, -1);
18642
+ }
18509
18643
  }
18510
18644
  /**
18511
18645
  * 复制单元格向另一个单元格粘贴
@@ -18601,6 +18735,9 @@ class DocumentChange {
18601
18735
  }
18602
18736
  else {
18603
18737
  const breakPara = this.splitCurrentParagraph();
18738
+ if (!breakPara) {
18739
+ return;
18740
+ }
18604
18741
  for (let i = 0; i < textItems.length; i++) {
18605
18742
  const newPara = breakPara.clone(false);
18606
18743
  const inputTextProps = this.getDefaultTextPropsByOptions();
@@ -18612,6 +18749,20 @@ class DocumentChange {
18612
18749
  this.selectionState.resetRange(breakPara, 0);
18613
18750
  }
18614
18751
  }
18752
+ /**
18753
+ * 当前光标位置是否允许分割生成两个段落
18754
+ */
18755
+ allowSplitParagraph(target) {
18756
+ if (!target) {
18757
+ target = this.selectionState;
18758
+ }
18759
+ const { startControl, startOffset } = target;
18760
+ //内联数据块不能拆分两部分
18761
+ if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
18762
+ return false;
18763
+ }
18764
+ return true;
18765
+ }
18615
18766
  /**
18616
18767
  * 向当前光标追加文本
18617
18768
  * @param appendStr
@@ -19672,7 +19823,6 @@ class DocumentSvg {
19672
19823
  fill: item.color ?? this.viewOptions.selectionColor,
19673
19824
  'paint-order': 'stroke fill markers',
19674
19825
  d: `M${item.x} ${item.y} L${item.x + item.width} ${item.y} L${item.x + item.width} ${item.y + item.height} L${item.x} ${item.y + item.height} Z`,
19675
- 'fill-opacity': '0.5'
19676
19826
  }
19677
19827
  }
19678
19828
  }));
@@ -21657,8 +21807,13 @@ class DocEditor {
21657
21807
  return ElementSerialize.getSelectedJSON(this.selectionState, this.viewOptions);
21658
21808
  }
21659
21809
  getSelectedText() {
21660
- const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
21661
- return ElementSerialize.serializeString(copySerializeStr);
21810
+ const selectedEles = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
21811
+ if (!selectedEles) {
21812
+ return '';
21813
+ }
21814
+ return selectedEles.map(ele => {
21815
+ return ElementSerialize.serializeString(ele);
21816
+ }).join('');
21662
21817
  }
21663
21818
  /**
21664
21819
  * 执行编辑器内部复制事件
@@ -22289,7 +22444,7 @@ class DocEditor {
22289
22444
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
22290
22445
  }
22291
22446
  version() {
22292
- return "2.2.16";
22447
+ return "2.2.18";
22293
22448
  }
22294
22449
  switchPageHeaderEditor() {
22295
22450
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -22603,6 +22758,39 @@ class DocEditor {
22603
22758
  }
22604
22759
  return res;
22605
22760
  }
22761
+ /**
22762
+ * 返回当前光标处是否允许截断段落生成新的段落
22763
+ * @returns
22764
+ */
22765
+ allowSplitParagraph() {
22766
+ return this.documentChange.allowSplitParagraph();
22767
+ }
22768
+ /**
22769
+ * 设置元素属性(attribute)
22770
+ * @param ele
22771
+ * @param attr
22772
+ * @param value
22773
+ */
22774
+ setEleAttribute(ele, attr, value) {
22775
+ ElementUtil.setEleAttribute(ele, attr, value);
22776
+ }
22777
+ /**
22778
+ * 获取元素属性(attribute)
22779
+ * @param ele
22780
+ * @param attr
22781
+ * @returns
22782
+ */
22783
+ getEleAttribute(ele, attr) {
22784
+ return ElementUtil.getEleAttribute(ele, attr);
22785
+ }
22786
+ /**
22787
+ * 删除元素属性(attribute)
22788
+ * @param ele
22789
+ * @param attr
22790
+ */
22791
+ removeEleAttribute(ele, attr) {
22792
+ ElementUtil.removeEleAttribute(ele, attr);
22793
+ }
22606
22794
  }
22607
22795
 
22608
22796
  /**
@@ -28012,5 +28200,5 @@ function removeDuplicatesEvent(events) {
28012
28200
  return arr;
28013
28201
  }
28014
28202
 
28015
- export { BlockContainerElement, BlockContainerRenderObject, BlockContentElement, BlockContentRenderObject, BlockLineRectRenderObject, BodyPartProps, BooleanEnum, BorderProps, BranchElement, BranchRenderObject, BreakElement, BreakFactory, BreakRenderObject, CheckBoxElement, CheckBoxFactory, CheckBoxProps, CheckBoxRenderObject, ColumnPatchUtil, CommContentBaseElement, CommContentBaseRenderObject, CommContentElement, CommContentProps, CommContentRenderObject, CommProps, CommentContentFactory, CommentElement, CommentFactory, CommentRenderObject, CommentsFactory, CommonUtil, CommsContainerElement, CommsContainerRenderObject, ContentMenuItem, ContextMenuElementEvent, CopyElementEvent, DOMEventSource, DOMSubscription, DataContainerElement, DataContainerFactory, DataContainerProps, DataContainerRenderObject, DataDecorateElement, DataDecorateProps, DataDecorateRenderObject, DataEleBaseProps, DataEleBaseTextProps, DataEleCheckProps, DataEleDateProps, DataEleImageProps, DataEleListProps, DataEleMHProps, DataElementBarcode, DataElementBarcodeFactory, DataElementBarcodeProps, DataElementBarcodeRenderObject, DataElementBaseFactory, DataElementCheck, DataElementCheckFactory, DataElementCheckRenderObject, DataElementDate, DataElementDateFactory, DataElementDateRenderObject, DataElementGroupElement, DataElementGroupFactory, DataElementGroupProps, DataElementGroupRenderObject, DataElementImage, DataElementImgFactory, DataElementInlineGroup, DataElementLeaf, DataElementList, DataElementListFactory, DataElementListRenderObject, DataElementMH, DataElementMHFactory, DataElementRenderObject, DataElementText, DataElementTextFactory, DataElementTextRenderObject, DataImageRenderObject, DataRenderMH, DocEditor, DocInputSuggestions, DocMode, DocumentBodyElement, DocumentBodyFactory, DocumentBodyPartElement, DocumentBodyPartFactory, DocumentBodyPartRenderObject, DocumentBodyRenderObject, DocumentChange, DocumentCombine, DocumentComment, DocumentContainerRender, DocumentContext, DocumentCursor, DocumentElement, DocumentEvalFunc, DocumentEvent, DocumentFactory, DocumentFooterElement, DocumentFooterFactory, DocumentFooterRenderObject, DocumentHeaderElement, DocumentHeaderFactory, DocumentHeaderRenderObject, DocumentInput, DocumentPaginator, DocumentPrintOffscreen, DocumentPrintOffscreenBase, DocumentProps, DocumentRenderObject, DocumentSelection, DocumentTemplate, DropElementEvent, EditMode, EditorContext, Element, ElementEvent, ElementFactory, ElementReader, ElementSerialize, ElementUtil, EventBus, EventMap, EventSourceCore, FillNullSpaceElement, FillNullSpaceRenderObject, GetTrackTipsEvent, GotCursorEvent, IDispose, INotifyPropertyChanged, InlineBlockContainer, InlineGroupElement, InlineGroupInputElement, InlineGroupRenderObject, InlineMuiltBlockLineRenderObject, InputElementEvent, IsInSideDataElement, IsInSideDataGroup, IsInSideInlineGroupInputElement, KeyboradElementEvent, LeafElement, LeafRenderObject, LostCursorEvent, MarginProps, ModifyFlag, MouseElementEvent, MousedownElementEvent, MultiBlockLineRenderObject, OnceSubject, PSymbolElement, PSymbolRenderObject, PaddingProps, PageBreakElement, PageBreakFactory, PageBreakRenderObject, PageOptions, PaintContent, ParagraphElement, ParagraphFactory, ParagraphLineRectRenderObject, ParagraphNumberType, ParagraphProps, ParagraphRenderObject, PasteElementEvent, PermanentTeethElement, PermanentTeethFactory, PermanentTeethProps, PermanentTeethRenderObject, PictureElement, PictureFactory, PictureProps, PictureRenderObject, RadioBoxElement, RadioBoxFactory, RadioBoxProps, RadioBoxRenderObject, RangeUtil, Rect, RenderContext, RenderObject, RenderObjectType, ResizeLeafRenderObject, RowMinHeight, RunElementFactory, SVGElement, SVGFactory, SVGProps, SVGRenderObject, SelectionOverlays, SelectionRange, SelectionState, Subject, SubjectSubscription, Subscription, TEXT_HEIGHT_FACTOR, TabElement, TabFactory, TabRenderObject, TableCellElement, TableCellFactory, TableCellProps, TableCellRenderObject, TableElement, TableFactory, TableProps, TableRenderObject, TableRowElement, TableRowFactory, TableRowProps, TableRowRenderObject, TableSplitCell, TableUtil, TextGroupElement, TextGroupFactory, TextGroupRenderObject, TextProps, TextUnitsHolder, TrackRunElement, TrackRunProps, TrackRunRenderObject, TrackRunTypeEnum, ValidateCondition, ValidateElement, ValidateProps, ValidateRenderObject, ViewOptions, addReturn, clearChildrenRenderCache, clearTraces, cloneChildren, cloneElementBase, defaultParaHanging, deleteCurrentParagraph, docOpsMap, elementTypeEventHandler, exportDataEleDecoratorSVG$1 as exportDataEleDecoratorSVG, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getFocusTextSegment, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, reactiveMap, refreshEditor, removeEle, removeText, renderErrorTip, renderUnderWavyLine, renderUnderline, runTextLineRender, setChildrenModifyFlag, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateDataGroup, validateInlineInputRenderObj, watchChanged };
28203
+ export { BlockContainerElement, BlockContainerRenderObject, BlockContentElement, BlockContentRenderObject, BlockLineRectRenderObject, BodyPartProps, BooleanEnum, BorderProps, BranchElement, BranchRenderObject, BreakElement, BreakFactory, BreakRenderObject, CheckBoxElement, CheckBoxFactory, CheckBoxProps, CheckBoxRenderObject, ColumnPatchUtil, CommContentBaseElement, CommContentBaseRenderObject, CommContentElement, CommContentProps, CommContentRenderObject, CommProps, CommentContentFactory, CommentElement, CommentFactory, CommentRenderObject, CommentsFactory, CommonUtil, CommsContainerElement, CommsContainerRenderObject, ContentMenuItem, ContextMenuElementEvent, CopyElementEvent, DOMEventSource, DOMSubscription, DataContainerElement, DataContainerFactory, DataContainerProps, DataContainerRenderObject, DataDecorateElement, DataDecorateProps, DataDecorateRenderObject, DataEleBaseProps, DataEleBaseTextProps, DataEleCheckProps, DataEleDateProps, DataEleImageProps, DataEleListProps, DataEleMHProps, DataElementBarcode, DataElementBarcodeFactory, DataElementBarcodeProps, DataElementBarcodeRenderObject, DataElementBaseFactory, DataElementCheck, DataElementCheckFactory, DataElementCheckRenderObject, DataElementDate, DataElementDateFactory, DataElementDateRenderObject, DataElementGroupElement, DataElementGroupFactory, DataElementGroupProps, DataElementGroupRenderObject, DataElementImage, DataElementImgFactory, DataElementInlineGroup, DataElementLeaf, DataElementList, DataElementListFactory, DataElementListRenderObject, DataElementMH, DataElementMHFactory, DataElementRenderObject, DataElementText, DataElementTextFactory, DataElementTextRenderObject, DataImageRenderObject, DataRenderMH, DocEditor, DocInputSuggestions, DocMode, DocumentBodyElement, DocumentBodyFactory, DocumentBodyPartElement, DocumentBodyPartFactory, DocumentBodyPartRenderObject, DocumentBodyRenderObject, DocumentChange, DocumentCombine, DocumentComment, DocumentContainerRender, DocumentContext, DocumentCursor, DocumentElement, DocumentEvalFunc, DocumentEvent, DocumentFactory, DocumentFooterElement, DocumentFooterFactory, DocumentFooterRenderObject, DocumentHeaderElement, DocumentHeaderFactory, DocumentHeaderRenderObject, DocumentInput, DocumentPaginator, DocumentPrintOffscreen, DocumentPrintOffscreenBase, DocumentProps, DocumentRenderObject, DocumentSelection, DocumentTemplate, DropElementEvent, EditMode, EditorContext, Element, ElementEvent, ElementFactory, ElementReader, ElementSerialize, ElementUtil, EventBus, EventMap, EventSourceCore, FillNullSpaceElement, FillNullSpaceRenderObject, GetTrackTipsEvent, GotCursorEvent, IDispose, INotifyPropertyChanged, InlineBlockContainer, InlineGroupElement, InlineGroupInputElement, InlineGroupRenderObject, InlineMuiltBlockLineRenderObject, InputElementEvent, IsInSideDataElement, IsInSideDataGroup, IsInSideInlineGroupInputElement, KeyboradElementEvent, LeafElement, LeafRenderObject, LostCursorEvent, MarginProps, ModifyFlag, MouseElementEvent, MousedownElementEvent, MultiBlockLineRenderObject, OnceSubject, PSymbolElement, PSymbolRenderObject, PaddingProps, PageBreakElement, PageBreakFactory, PageBreakRenderObject, PageOptions, PaintContent, ParagraphElement, ParagraphFactory, ParagraphLineRectRenderObject, ParagraphNumberType, ParagraphProps, ParagraphRenderObject, PasteElementEvent, PermanentTeethElement, PermanentTeethFactory, PermanentTeethProps, PermanentTeethRenderObject, PictureElement, PictureFactory, PictureProps, PictureRenderObject, RadioBoxElement, RadioBoxFactory, RadioBoxProps, RadioBoxRenderObject, RangeUtil, Rect, RenderContext, RenderObject, RenderObjectType, ResizeLeafRenderObject, RowMinHeight, RunElementFactory, SVGElement, SVGFactory, SVGProps, SVGRenderObject, SelectionOverlays, SelectionRange, SelectionState, Subject, SubjectSubscription, Subscription, TEXT_HEIGHT_FACTOR, TabElement, TabFactory, TabRenderObject, TableCellElement, TableCellFactory, TableCellProps, TableCellRenderObject, TableElement, TableFactory, TableProps, TableRenderObject, TableRowElement, TableRowFactory, TableRowProps, TableRowRenderObject, TableSplitCell, TableUtil, TextGroupElement, TextGroupFactory, TextGroupRenderObject, TextProps, TextUnitsHolder, TrackRunElement, TrackRunProps, TrackRunRenderObject, TrackRunTypeEnum, ValidateCondition, ValidateElement, ValidateProps, ValidateRenderObject, ViewOptions, addReturn, clearChildrenRenderCache, clearTraces, cloneChildren, cloneElementBase, defaultParaHanging, deleteCurrentParagraph, docOpsMap, elementTypeEventHandler, exportDataEleDecoratorSVG$1 as exportDataEleDecoratorSVG, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getCurrentParaGroupRenders, getFocusTextSegment, getRenderPosToDoc, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, reactiveMap, refreshEditor, removeEle, removeText, renderErrorTip, renderUnderWavyLine, renderUnderline, runTextLineRender, setChildrenModifyFlag, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateDataGroup, validateInlineInputRenderObj, watchChanged };
28016
28204
  //# sourceMappingURL=index.js.map