@hailin-zheng/editor-core 2.2.7 → 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -388,7 +388,6 @@ class BlockContentRenderObject extends BranchRenderObject {
388
388
  }
389
389
  }
390
390
  class InlineGroupRenderObject extends BranchRenderObject {
391
- paintPos;
392
391
  }
393
392
  /**
394
393
  * 包含块级渲染元素的容器元素,例如body、table-cell等
@@ -402,18 +401,18 @@ class BlockContainerRenderObject extends BranchRenderObject {
402
401
  /**
403
402
  * 多级 ‘BlockLineRectRenderObject’ 包裹元素,例如 p、table
404
403
  */
405
- class MuiltBlockLineRenderObject extends BlockContentRenderObject {
404
+ class MultiBlockLineRenderObject extends BlockContentRenderObject {
406
405
  }
407
406
  /**
408
407
  * 容器-子内容为多个行内块级元素,例如table-row
409
408
  */
410
- class InlineBlockContainer extends MuiltBlockLineRenderObject {
409
+ class InlineBlockContainer extends MultiBlockLineRenderObject {
411
410
  }
412
411
  /**
413
412
  * 服务于table-cell
414
413
  * 可被多级拆分的元素
415
414
  */
416
- class InlineMuiltBlockLineRenderObject extends MuiltBlockLineRenderObject {
415
+ class InlineMuiltBlockLineRenderObject extends MultiBlockLineRenderObject {
417
416
  }
418
417
  /**
419
418
  * 最小不可分割单位的块级行框,例如 p-line
@@ -1697,12 +1696,22 @@ class ViewOptions {
1697
1696
  defaultColor = "#000000";
1698
1697
  currentFontSize = 14;
1699
1698
  currentFontName = '宋体';
1700
- selectionOverlaysColor = 'rgb(131,175,155,0.5)';
1701
- dataEleOverlaysColor = 'rgb(131,175,155,0.5)';
1702
- dataEleFocusedBgColor = 'rgb(131,175,155,0.8)';
1699
+ //选区颜色
1700
+ selectionColor = 'rgb(131,175,155,0.5)';
1701
+ dataDecoratorNormalColor = '#0050b3';
1702
+ dataDecoratorMouseEnterColor = '#0050b3';
1703
+ dataDecoratorFocusedColor = '#0050b3';
1704
+ //数据元没有输入值时背景颜色
1705
+ dataEleEmptyBgColor = '';
1706
+ //数据元鼠标悬浮颜色
1707
+ dataEleMouseEnterBgColor = '#d9d9d9';
1708
+ //数据元只读背景颜色
1709
+ dataEleReadOnlyBgColor = '#d9d9d9';
1710
+ //数据元焦点背景颜色
1711
+ dataEleFocusedBgColor = '#d9d9d9';
1712
+ //数据元正常背景颜色
1713
+ dataEleNormalBgColor = '#fafafa';
1703
1714
  dataEleErrorBgColor = '#ff4d4f';
1704
- dataEleReadOnlyOverlayColor = '#d9d9d9';
1705
- dataEleOutlineColor = 'rgb(131,175,155,0.7)';
1706
1715
  viewBackcolor = 'rgb(230,230,230)';
1707
1716
  paraSymbolColor = 'rgb(128,128,128)';
1708
1717
  dataGroupColor = 'rgb(0,80,179)';
@@ -1717,7 +1726,6 @@ class ViewOptions {
1717
1726
  showCharRect;
1718
1727
  //数据元交互修饰模式
1719
1728
  dataEleDecoratorMode = 'outline';
1720
- dataEleDecoratorColor = '#ddd';
1721
1729
  showTabChar;
1722
1730
  showSpaceChar;
1723
1731
  showLineBreak;
@@ -2900,7 +2908,7 @@ class DataDecorateElement extends LeafElement {
2900
2908
  const render = new DataDecorateRenderObject(this);
2901
2909
  //render.rect.width = this.dProps.size / 2;
2902
2910
  render.rect.width = 1;
2903
- render.rect.height = 14;
2911
+ render.rect.height = Math.ceil(14 * TEXT_HEIGHT_FACTOR);
2904
2912
  return render;
2905
2913
  }
2906
2914
  serialize() {
@@ -2926,6 +2934,14 @@ class DataDecorateRenderObject extends LeafRenderObject {
2926
2934
  // if(this.element.parent.parent.type==='data-group'){
2927
2935
  // return null;
2928
2936
  // }
2937
+ const options = event.options;
2938
+ let color = options.dataDecoratorNormalColor;
2939
+ if (this.element.dataEle.isMouseenter && options.dataDecoratorMouseEnterColor) {
2940
+ color = options.dataDecoratorMouseEnterColor;
2941
+ }
2942
+ if (this.element.dataEle.isFocused && options.dataDecoratorFocusedColor) {
2943
+ color = options.dataDecoratorFocusedColor;
2944
+ }
2929
2945
  const element = this.element;
2930
2946
  const lineWidth = 3;
2931
2947
  let path = '';
@@ -2939,7 +2955,7 @@ class DataDecorateRenderObject extends LeafRenderObject {
2939
2955
  path = `M ${x - lineWidth} 2 L ${x} 2 L ${x} ${height} L ${x - lineWidth} ${height}`;
2940
2956
  }
2941
2957
  return ElementUtil.createSvgPath({
2942
- stroke: '#0050b3',
2958
+ stroke: color,
2943
2959
  fill: "none",
2944
2960
  'stroke-width': 1,
2945
2961
  d: path
@@ -3105,7 +3121,7 @@ class ParagraphElement extends BlockContentElement {
3105
3121
  return new ParagraphElement();
3106
3122
  }
3107
3123
  }
3108
- class ParagraphRenderObject extends MuiltBlockLineRenderObject {
3124
+ class ParagraphRenderObject extends MultiBlockLineRenderObject {
3109
3125
  /**
3110
3126
  * 绘制项目符号
3111
3127
  */
@@ -3654,7 +3670,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3654
3670
  },
3655
3671
  },
3656
3672
  children: [
3657
- pageCorner, copyright, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection
3673
+ pageCorner, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection, copyright
3658
3674
  ]
3659
3675
  };
3660
3676
  }
@@ -3692,11 +3708,10 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3692
3708
  }
3693
3709
  const str = "\u6f14\u793a\u7248\u672c";
3694
3710
  const textProps = new TextProps();
3695
- textProps.color = "#000";
3696
- textProps.fontName = '仿宋';
3711
+ textProps.color = "#bfbfbf";
3712
+ textProps.fontName = '宋体';
3697
3713
  textProps.fontSize = 80;
3698
3714
  textProps.fontStyle = 'italic';
3699
- event.renderCtx.contentContext.measureText(str, textProps);
3700
3715
  const getTextRotationAngle = (width, height) => {
3701
3716
  return Math.atan(height / width) * 180 / Math.PI;
3702
3717
  };
@@ -3715,6 +3730,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3715
3730
  'font-size': textProps.fontSize,
3716
3731
  "stroke": textProps.color,
3717
3732
  'fill': '#fff',
3733
+ 'opacity': '0.5',
3718
3734
  x: this.rect.width / 2,
3719
3735
  y: this.rect.height / 2,
3720
3736
  }
@@ -4102,68 +4118,85 @@ class DataElementBaseFactory extends ElementFactory {
4102
4118
  * @param r
4103
4119
  */
4104
4120
  function exportDecoratorHTML(event, r) {
4105
- const canPaint = r.element.isMouseenter || r.element.isFocused;
4106
- if (!canPaint) {
4121
+ if (event.mode === 'print') {
4107
4122
  return;
4108
4123
  }
4109
- const mode = event.options.dataEleDecoratorMode;
4110
- const color = event.options.dataEleDecoratorColor;
4111
- if (mode === 'none') {
4112
- return;
4124
+ const options = event.options;
4125
+ let color = options.dataEleNormalBgColor;
4126
+ //空数据元填充颜色
4127
+ if (r.element.length === 2 && options.dataEleEmptyBgColor) {
4128
+ color = options.dataEleEmptyBgColor;
4113
4129
  }
4114
- if (mode === 'overlay') {
4115
- const bgX = event.relativePagePos.x;
4116
- const bgY = event.relativePagePos.y;
4117
- event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4118
- return;
4130
+ if (r.element.isMouseenter && options.dataEleMouseEnterBgColor) {
4131
+ color = options.dataEleMouseEnterBgColor;
4119
4132
  }
4120
- else if (mode === 'outline') {
4121
- const verOffset = 0;
4122
- const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
4123
- if (renderPosMap.length > 1) {
4124
- const secondGroupRenderPos = renderPosMap[1].pos;
4125
- if (secondGroupRenderPos.x + renderPosMap[1].render.rect.width > event.relativePagePos.x) {
4126
- const leftPoints = [];
4127
- const rightPoints = [];
4128
- for (let i = 0; i < renderPosMap.length; i++) {
4129
- const groupRender = renderPosMap[i].render;
4130
- const groupRenderPos = renderPosMap[i].pos;
4131
- leftPoints.push({ x: groupRenderPos.x, y: groupRenderPos.y - verOffset });
4132
- rightPoints.push({
4133
- x: groupRenderPos.x + groupRender.rect.width,
4134
- y: groupRenderPos.y - verOffset
4135
- });
4136
- leftPoints.push({
4137
- x: groupRenderPos.x,
4138
- y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4139
- });
4140
- rightPoints.push({
4141
- x: groupRenderPos.x + groupRender.rect.width,
4142
- y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4143
- });
4144
- }
4145
- const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
4146
- const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
4147
- const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ");
4148
- event.highlights.push(ElementUtil.createSvgPath({
4149
- d: path,
4150
- stroke: color,
4151
- fill: 'none',
4152
- 'stroke-width': 1
4153
- }));
4154
- return;
4155
- }
4156
- }
4157
- for (let i = 0; i < renderPosMap.length; i++) {
4158
- const currRen = renderPosMap[i];
4159
- event.highlights.push(ElementUtil.createSvgPath({
4160
- 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`,
4161
- stroke: '#0050b3',
4162
- fill: 'none',
4163
- 'stroke-width': 1
4164
- }));
4165
- }
4133
+ if (r.element.isFocused && options.dataEleFocusedBgColor) {
4134
+ color = options.dataEleFocusedBgColor;
4166
4135
  }
4136
+ //绘制背景
4137
+ const bgX = event.relativePagePos.x;
4138
+ const bgY = event.relativePagePos.y;
4139
+ event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4140
+ // const canPaint = r.element.isMouseenter || r.element.isFocused;
4141
+ // if (!canPaint) {
4142
+ // return;
4143
+ // }
4144
+ // const mode = event.options.dataEleDecoratorMode;
4145
+ // if (mode === 'none') {
4146
+ // return;
4147
+ // }
4148
+ // if (mode === 'overlay') {
4149
+ // const bgX = event.relativePagePos.x;
4150
+ // const bgY = event.relativePagePos.y;
4151
+ // event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, r.rect.width, r.rect.height, color));
4152
+ // return;
4153
+ // } else if (mode === 'outline') {
4154
+ // const verOffset = 0;
4155
+ // const renderPosMap = getCurrentParaGroupRenders(r).map(item => ({ pos: getRenderPosToDoc(item), render: item }));
4156
+ // if (renderPosMap.length > 1) {
4157
+ // const secondGroupRenderPos = renderPosMap[1].pos;
4158
+ // if (secondGroupRenderPos.x + renderPosMap[1].render.rect.width > event.relativePagePos.x) {
4159
+ // const leftPoints: Array<Position> = [];
4160
+ // const rightPoints: Array<Position> = [];
4161
+ // for (let i = 0; i < renderPosMap.length; i++) {
4162
+ // const groupRender = renderPosMap[i].render;
4163
+ // const groupRenderPos = renderPosMap[i].pos;
4164
+ // leftPoints.push({ x: groupRenderPos.x, y: groupRenderPos.y - verOffset });
4165
+ // rightPoints.push({
4166
+ // x: groupRenderPos.x + groupRender.rect.width,
4167
+ // y: groupRenderPos.y - verOffset
4168
+ // });
4169
+ // leftPoints.push({
4170
+ // x: groupRenderPos.x,
4171
+ // y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4172
+ // });
4173
+ // rightPoints.push({
4174
+ // x: groupRenderPos.x + groupRender.rect.width,
4175
+ // y: groupRenderPos.y + groupRender.rect.height + verOffset * 2
4176
+ // });
4177
+ // }
4178
+ // const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
4179
+ // const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
4180
+ // const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ")
4181
+ // event.highlights.push(ElementUtil.createSvgPath({
4182
+ // d: path,
4183
+ // stroke: color,
4184
+ // fill: 'none',
4185
+ // 'stroke-width': 1
4186
+ // }));
4187
+ // return;
4188
+ // }
4189
+ // }
4190
+ // for (let i = 0; i < renderPosMap.length; i++) {
4191
+ // const currRen = renderPosMap[i];
4192
+ // event.highlights.push(ElementUtil.createSvgPath({
4193
+ // 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`,
4194
+ // stroke: '#0050b3',
4195
+ // fill: 'none',
4196
+ // 'stroke-width': 1
4197
+ // }));
4198
+ // }
4199
+ // }
4167
4200
  }
4168
4201
  /**
4169
4202
  * 渲染数据源验证错误提示框
@@ -4268,30 +4301,6 @@ function renderUnderWavyLine(event, r, color) {
4268
4301
  d += Array(Math.ceil(width / 3)).fill("3,0").join(' t ');
4269
4302
  const path = ElementUtil.createSvgPath({ d, fill: 'none', stroke: color });
4270
4303
  event.highlights.push(path);
4271
- }
4272
- /**
4273
- * 获取渲染元素相对稳当的位置
4274
- * @param render
4275
- * @param refPos
4276
- */
4277
- function getRenderPosToDoc(render, refPos = null) {
4278
- refPos = refPos ?? { x: 0, y: 0 };
4279
- if (render instanceof DocumentRenderObject) {
4280
- return refPos;
4281
- }
4282
- const currPos = { x: render.rect.x + refPos.x, y: render.rect.y + refPos.y };
4283
- return getRenderPosToDoc(render.parent, currPos);
4284
- }
4285
- function getCurrentParaGroupRenders(r) {
4286
- const renders = [];
4287
- const currParaRender = ElementUtil.getParentRender(r, ParagraphRenderObject);
4288
- for (let i = 0; i < r.element.paintRenders.length; i++) {
4289
- const paraRender = ElementUtil.getParentRender(r.element.paintRenders[i], ParagraphRenderObject);
4290
- if (paraRender === currParaRender) {
4291
- renders.push(r.element.paintRenders[i]);
4292
- }
4293
- }
4294
- return renders;
4295
4304
  }
4296
4305
 
4297
4306
  class DocumentBodyElement extends BlockContainerElement {
@@ -4333,7 +4342,7 @@ class DocumentBodyElement extends BlockContainerElement {
4333
4342
  super.beginMeasure(data);
4334
4343
  }
4335
4344
  }
4336
- class DocumentBodyRenderObject extends MuiltBlockLineRenderObject {
4345
+ class DocumentBodyRenderObject extends MultiBlockLineRenderObject {
4337
4346
  clone(cloneData = true) {
4338
4347
  const cloneRender = new DocumentBodyRenderObject(this.element);
4339
4348
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -4632,7 +4641,7 @@ class TableRowElement extends BlockContainerElement {
4632
4641
  return tr;
4633
4642
  }
4634
4643
  }
4635
- class TableRowRenderObject extends MuiltBlockLineRenderObject {
4644
+ class TableRowRenderObject extends MultiBlockLineRenderObject {
4636
4645
  //被截断的行是否需要重新计算高度
4637
4646
  remeasureState = true;
4638
4647
  //当前行是否存在合并单元格
@@ -4862,9 +4871,7 @@ class TextGroupRenderObject extends LeafRenderObject {
4862
4871
  event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4863
4872
  }
4864
4873
  //处理null-text
4865
- if (this.element.isDecorate && this.element.disableClick && !this.element.parent) {
4866
- t.data.attrs['opacity'] = '0.58';
4867
- }
4874
+ if (this.element.isDecorate && this.element.disableClick && !this.element.parent) ;
4868
4875
  return t;
4869
4876
  }
4870
4877
  }
@@ -6131,7 +6138,7 @@ class TableElement extends BlockContainerElement {
6131
6138
  };
6132
6139
  }
6133
6140
  }
6134
- class TableRenderObject extends MuiltBlockLineRenderObject {
6141
+ class TableRenderObject extends MultiBlockLineRenderObject {
6135
6142
  setRenderWidth(maxWidth) {
6136
6143
  super.setRenderWidth(maxWidth);
6137
6144
  }
@@ -9088,33 +9095,23 @@ class DataContainerElement extends BlockContainerElement {
9088
9095
  }
9089
9096
  super.beginMeasure(data);
9090
9097
  }
9091
- serialize() {
9092
- const p = {
9098
+ serialize(viewOptions) {
9099
+ return {
9093
9100
  type: this.type,
9094
- props: {}
9101
+ props: {
9102
+ ...this.props.getSerializeProps(viewOptions)
9103
+ }
9095
9104
  };
9096
- if (this.props.id) {
9097
- p['id'] = this.props.id;
9098
- }
9099
- if (this.props.name) {
9100
- p['name'] = this.props.name;
9101
- }
9102
- if (this.props.caption) {
9103
- p['caption'] = this.props.caption;
9104
- }
9105
- return p;
9106
9105
  }
9107
9106
  clone(data) {
9108
9107
  const clone = new DataContainerElement();
9109
- clone.props.id = this.props.id;
9110
- clone.props.name = this.props.name;
9111
- clone.props.caption = this.props.caption;
9108
+ this.props.clone(clone.props);
9112
9109
  cloneElementBase(this, clone);
9113
9110
  cloneChildren(this, clone, data);
9114
9111
  return clone;
9115
9112
  }
9116
9113
  }
9117
- class DataContainerRenderObject extends MuiltBlockLineRenderObject {
9114
+ class DataContainerRenderObject extends MultiBlockLineRenderObject {
9118
9115
  clone(cloneData = true) {
9119
9116
  const cloneRender = new DataContainerRenderObject(this.element);
9120
9117
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -9139,24 +9136,21 @@ class DataContainerFactory extends ElementFactory {
9139
9136
  return type === 'data-container';
9140
9137
  }
9141
9138
  createElement(data) {
9142
- const element = new DataContainerElement();
9139
+ const ele = new DataContainerElement();
9143
9140
  const props = data.props;
9144
- if (props?.id) {
9145
- element.props.id = props.id;
9146
- }
9147
- if (props?.name) {
9148
- element.props.name = props.name;
9149
- }
9150
- if (props?.caption) {
9151
- element.props.caption = props.caption;
9152
- }
9153
- return element;
9141
+ ElementUtil.readEleBaseProps(ele.props, props);
9142
+ return ele;
9154
9143
  }
9155
9144
  }
9156
- class DataContainerProps {
9157
- caption;
9158
- id;
9159
- name;
9145
+ class DataContainerProps extends DataEleBaseProps {
9146
+ clone(dest) {
9147
+ const clone = dest ?? new DataContainerProps();
9148
+ super.cloneBaseProps(clone);
9149
+ }
9150
+ getSerializeProps(options) {
9151
+ const props = {};
9152
+ return this.getBaseProps(props, options);
9153
+ }
9160
9154
  }
9161
9155
 
9162
9156
  /**
@@ -9242,7 +9236,7 @@ class DocumentBodyPartElement extends BlockContainerElement {
9242
9236
  return clone;
9243
9237
  }
9244
9238
  }
9245
- class DocumentBodyPartRenderObject extends MuiltBlockLineRenderObject {
9239
+ class DocumentBodyPartRenderObject extends MultiBlockLineRenderObject {
9246
9240
  clone(cloneData = true) {
9247
9241
  const cloneRender = new DocumentBodyPartRenderObject(this.element);
9248
9242
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
@@ -10618,10 +10612,10 @@ class ElementSerialize {
10618
10612
  }
10619
10613
  }
10620
10614
  if (element.props && element.props['__attachedProperty'] && !result.props['__attachedProperty']) {
10621
- result.props['__attachedProperty'] = CommonUtil.cloneValue(element.props['__attachedProperty']);
10615
+ result.props['__attachedProperty'] = this.serializeObject(element.props['__attachedProperty']);
10622
10616
  }
10623
10617
  if (element.attribute) {
10624
- result['attribute'] = this.serializeAttribute(element);
10618
+ result['attribute'] = this.serializeObject(element.attribute);
10625
10619
  }
10626
10620
  return result;
10627
10621
  }
@@ -10645,20 +10639,23 @@ class ElementSerialize {
10645
10639
  }
10646
10640
  return "";
10647
10641
  }
10648
- static serializeAttribute(element) {
10649
- if (element.attribute) {
10650
- const result = {};
10651
- for (const key in element.attribute) {
10652
- if (element.attribute[key] !== undefined && element.attribute[key] !== null) {
10653
- result[key] = element.attribute[key];
10642
+ static serializeObject(obj) {
10643
+ if (obj === null || obj === undefined) {
10644
+ return null;
10645
+ }
10646
+ const result = {};
10647
+ for (const key in obj) {
10648
+ if (obj[key] !== undefined && obj[key] !== null) {
10649
+ if (key.startsWith("__")) {
10650
+ continue;
10654
10651
  }
10652
+ result[key] = obj[key];
10655
10653
  }
10656
- if (Object.keys(result).length === 0) {
10657
- return null;
10658
- }
10659
- return CommonUtil.cloneValue(result);
10660
10654
  }
10661
- return null;
10655
+ if (Object.keys(result).length === 0) {
10656
+ return null;
10657
+ }
10658
+ return CommonUtil.cloneValue(result);
10662
10659
  }
10663
10660
  /**
10664
10661
  * 获取选中的结构
@@ -14685,7 +14682,7 @@ class DocumentArrange {
14685
14682
  }
14686
14683
  const cloneRender = this.pMeasure.createRenderObject(render.element);
14687
14684
  cloneRender.setRenderWidth(render.rect.width);
14688
- if (render instanceof MuiltBlockLineRenderObject) {
14685
+ if (render instanceof MultiBlockLineRenderObject) {
14689
14686
  let sumHeight = 0;
14690
14687
  const children = [...render.getItems()];
14691
14688
  let j = 0;
@@ -14694,7 +14691,7 @@ class DocumentArrange {
14694
14691
  //sumHeight = ElementUtil.remeasure(cloneRender);
14695
14692
  const calcBlockLineHeight = this.getBlockLineHeight(blockLine);
14696
14693
  if (calcBlockLineHeight + sumHeight > limitHeight) {
14697
- if (blockLine instanceof MuiltBlockLineRenderObject) {
14694
+ if (blockLine instanceof MultiBlockLineRenderObject) {
14698
14695
  //限制的外框尺寸
14699
14696
  const availHeight = limitHeight - sumHeight;
14700
14697
  //限制的内框尺寸
@@ -15404,9 +15401,12 @@ class DocumentEvent {
15404
15401
  },
15405
15402
  mouseup: (evt) => {
15406
15403
  this.mouseup(evt, ElementUtil.getMousePos(evt, scale));
15404
+ this.mouseClickHandle(evt);
15407
15405
  },
15408
15406
  click: (evt) => {
15409
- this.mouseClickHandle(evt);
15407
+ //nulltext 不触发 click 事件,暂且这么处理
15408
+ //移到 mouseup 事件中处理
15409
+ //this.mouseClickHandle(evt);
15410
15410
  },
15411
15411
  mousemove: (evt) => {
15412
15412
  this.mousemove(evt, ElementUtil.getMousePos(evt, scale));
@@ -18700,103 +18700,56 @@ function getFocusTextSegment(selection) {
18700
18700
  let { startControl: element, startOffset: offset } = selection;
18701
18701
  if (!(element instanceof TextGroupElement))
18702
18702
  return false;
18703
- if (!supportSegment())
18704
- return false;
18705
18703
  const focusEle = element;
18706
- offset = offset + 1;
18707
- offset = offset > focusEle.textMeasures.length ? focusEle.textMeasures.length : offset;
18708
- //获取连续的字符
18709
- const items = [...getConsecutiveTextsByDirection(element), element, ...getConsecutiveTextsByDirection(element, false)];
18710
- const sortItems = getTextSortData(items);
18711
- const { index, text } = sortItems.reduce((prev, curr) => {
18712
- prev.text += curr.text;
18713
- if (prev.completed) {
18714
- return prev;
18715
- }
18716
- if (curr.item === focusEle) {
18717
- prev.index += offset;
18718
- prev.completed = true;
18719
- }
18720
- else {
18721
- prev.index += curr.item.textMeasures.length;
18722
- }
18723
- return prev;
18724
- }, { completed: false, index: 0, text: '' });
18725
- const { index: hitIndex, len: hitLen } = getHitSegment(text, index);
18726
- const matchSegment = sortItems.filter(item => (item.index <= hitIndex && item.endIndex > hitIndex) || (item.index <= hitIndex + hitLen && item.endIndex > hitIndex + hitLen));
18727
- const startSegment = matchSegment[0];
18728
- const endSegment = matchSegment[matchSegment.length - 1];
18729
- const startOffset = hitIndex - startSegment.index;
18730
- const endOffset = hitIndex + hitLen - endSegment.index;
18731
- const newRange = new SelectionRange();
18732
- newRange.setStart(startSegment.item, startOffset);
18733
- newRange.setEnd(endSegment.item, endOffset);
18734
- selection.addRange(newRange);
18704
+ const focusText = focusEle.text;
18705
+ if (!focusText) {
18706
+ return false;
18707
+ }
18708
+ const [start, end] = tokenize(focusText, offset);
18709
+ const range = new SelectionRange();
18710
+ range.setStart(focusEle, start);
18711
+ range.setEnd(focusEle, end + 1);
18712
+ selection.addRange(range);
18735
18713
  return true;
18736
18714
  }
18737
- /**
18738
- * 进行分词
18739
- * @param text
18740
- * @param focusOffset
18741
- */
18742
- function getHitSegment(text, focusOffset) {
18743
- const segmenter = new Intl.Segmenter("zh-CN", { granularity: "word" });
18744
- const iterator1 = segmenter.segment(text)[Symbol.iterator]();
18745
- const segItems = Array.from(iterator1);
18746
- let index = 0;
18747
- for (let i = 0; i < segItems.length; i++) {
18748
- const segItem = segItems[i];
18749
- const currIndex = segItem.index;
18750
- const currLen = segItem.segment.length;
18751
- if (focusOffset > currIndex && focusOffset <= currLen + currIndex) {
18752
- return {
18753
- index,
18754
- len: currLen
18755
- };
18715
+ function tokenize(text, index) {
18716
+ if (text.length === 0) {
18717
+ return [0, 0]; // 处理空字符串的情况
18718
+ }
18719
+ const isChinese = (char) => {
18720
+ return /^[\u4e00-\u9fa5]+$/.test(char);
18721
+ };
18722
+ const isEnglish = (char) => {
18723
+ return /^[a-zA-Z]+$/.test(char);
18724
+ };
18725
+ const isNumeric = (char) => {
18726
+ return /^[0-9]+$/.test(char);
18727
+ };
18728
+ let start = index;
18729
+ let end = index;
18730
+ // 向左查找开始位置
18731
+ while (start > 0) {
18732
+ if ((isChinese(text[start]) && isChinese(text[start - 1])) ||
18733
+ (isEnglish(text[start]) && isEnglish(text[start - 1])) ||
18734
+ (isNumeric(text[start]) && isNumeric(text[start - 1]))) {
18735
+ start--;
18736
+ }
18737
+ else {
18738
+ break;
18756
18739
  }
18757
- index += currLen;
18758
18740
  }
18759
- throw new Error('未获取到对应的分词词组');
18760
- }
18761
- function supportSegment() {
18762
- return typeof Intl.Segmenter === 'function';
18763
- }
18764
- /**
18765
- * 根据前后顺序标识索引位
18766
- * @param texts
18767
- */
18768
- function getTextSortData(texts) {
18769
- let index = 0;
18770
- const sortItems = [];
18771
- for (let i = 0; i < texts.length; i++) {
18772
- const item = texts[i];
18773
- const sortData = {
18774
- len: item.textMeasures.length,
18775
- index,
18776
- endIndex: index + item.textMeasures.length,
18777
- item,
18778
- text: item.text
18779
- };
18780
- sortItems.push(sortData);
18781
- index += sortData.len;
18741
+ // 向右查找结束位置
18742
+ while (end < text.length - 1) {
18743
+ if ((isChinese(text[end]) && isChinese(text[end + 1])) ||
18744
+ (isEnglish(text[end]) && isEnglish(text[end + 1])) ||
18745
+ (isNumeric(text[end]) && isNumeric(text[end + 1]))) {
18746
+ end++;
18747
+ }
18748
+ else {
18749
+ break;
18750
+ }
18782
18751
  }
18783
- return sortItems;
18784
- }
18785
- /**
18786
- * 获取指定方向上连续的字符
18787
- * @param element
18788
- * @param prev
18789
- */
18790
- function getConsecutiveTextsByDirection(element, prev = true) {
18791
- let prevText = element;
18792
- const prevTexts = [];
18793
- const func = prev ? ElementUtil.getPrevSiblingElement : ElementUtil.getNextSiblingElement;
18794
- const addItem = prev ? prevTexts.unshift : prevTexts.push;
18795
- while ((prevText = func(prevText)) && prevText instanceof TextGroupElement) {
18796
- //addItem(prevText);
18797
- addItem.apply(prevTexts, [prevText]);
18798
- }
18799
- return prevTexts;
18752
+ return [start, end];
18800
18753
  }
18801
18754
 
18802
18755
  /**
@@ -19361,7 +19314,7 @@ class DocumentSvg {
19361
19314
  ns: 'http://www.w3.org/2000/svg',
19362
19315
  attrs: {
19363
19316
  stroke: 'none',
19364
- fill: item.color ?? 'rgb(85,165,255)',
19317
+ fill: item.color ?? this.viewOptions.selectionColor,
19365
19318
  'paint-order': 'stroke fill markers',
19366
19319
  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`,
19367
19320
  'fill-opacity': '0.5'
@@ -20756,6 +20709,7 @@ class DocEditor {
20756
20709
  ssChanged && this.documentEvent.invokeCursor(this.selectionState.startControl);
20757
20710
  this.documentSelection.clearSnapshot();
20758
20711
  this.documentSelection.takeSnapshot();
20712
+ return ssChanged;
20759
20713
  }
20760
20714
  /**
20761
20715
  * 根据当前选区,更新待输入文本字体信息
@@ -20795,6 +20749,7 @@ class DocEditor {
20795
20749
  this.selectionState.cursorPos = cursorRect;
20796
20750
  const abPos = ElementUtil.cloneRect(cursorRect);
20797
20751
  this.setCursorPosition(abPos);
20752
+ this.setCursorVisibility(true);
20798
20753
  //this.documentEvent.invokeCursor(startControl);
20799
20754
  return;
20800
20755
  }
@@ -20828,7 +20783,7 @@ class DocEditor {
20828
20783
  setCursorVisibility(visibility) {
20829
20784
  if (visibility) {
20830
20785
  //this.editInput.style.removeProperty('display');
20831
- this.editInput.focus();
20786
+ this.editInput.focus({ preventScroll: true });
20832
20787
  }
20833
20788
  }
20834
20789
  hiddenInput(reset = true, pos = null) {
@@ -20850,7 +20805,6 @@ class DocEditor {
20850
20805
  this.editInput.style.height = position.height + 'px';
20851
20806
  this.editInput.style.width = "1.6px";
20852
20807
  this.editInput.readOnly = false;
20853
- this.setCursorVisibility(true);
20854
20808
  //判断光标位置是否被可见,如果不可见,需要将其设置到可见区域
20855
20809
  //TODO:暂时不做处理
20856
20810
  //this.setCursorInputStatus();
@@ -20886,7 +20840,7 @@ class DocEditor {
20886
20840
  * 文档点击事件
20887
20841
  */
20888
20842
  docClickHandle(evt) {
20889
- this.hiddenInput();
20843
+ //this.hiddenInput();
20890
20844
  // this.setCursor();
20891
20845
  // this.updateSelection();
20892
20846
  this.refreshDocument();
@@ -21186,20 +21140,20 @@ class DocEditor {
21186
21140
  const startControl = this.selectionState.startControl;
21187
21141
  if (startControl instanceof TextGroupElement) {
21188
21142
  const selectedStyle = startControl.props.clone(null);
21189
- const selectionOverlayColor = this.viewOptions.selectionOverlaysColor;
21190
- this.viewOptions.selectionOverlaysColor = "rgba(0,58,140,0.8)";
21143
+ const selectionColor = this.viewOptions.selectionColor;
21144
+ this.viewOptions.selectionColor = "rgba(0,58,140,0.8)";
21191
21145
  const cancelToken = {};
21192
21146
  const sub = this.onClickEvent.subscribe(() => {
21193
21147
  sub.unsubscribe();
21194
21148
  this.setTextFormat(selectedStyle);
21195
- this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
21149
+ this.viewOptions.selectionColor = selectionColor;
21196
21150
  if (cancelToken.onFinish) {
21197
21151
  cancelToken.onFinish(null);
21198
21152
  }
21199
21153
  });
21200
21154
  cancelToken.cancel = () => {
21201
21155
  sub.unsubscribe();
21202
- this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
21156
+ this.viewOptions.selectionColor = selectionColor;
21203
21157
  };
21204
21158
  return cancelToken;
21205
21159
  }
@@ -21960,7 +21914,7 @@ class DocEditor {
21960
21914
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
21961
21915
  }
21962
21916
  version() {
21963
- return "2.2.7";
21917
+ return "2.2.8";
21964
21918
  }
21965
21919
  switchPageHeaderEditor() {
21966
21920
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -27679,5 +27633,5 @@ function removeDuplicatesEvent(events) {
27679
27633
  return arr;
27680
27634
  }
27681
27635
 
27682
- 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, IsInSideInlineGroupInputElement, KeyboradElementEvent, LeafElement, LeafRenderObject, LostCursorEvent, MarginProps, ModifyFlag, MouseElementEvent, MousedownElementEvent, MuiltBlockLineRenderObject, 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, exportDecoratorHTML, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getFocusTextSegment, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, reactiveMap, removeEle, removeText, renderErrorTip, renderUnderWavyLine, runTextLineRender, setChildrenModifyFlag, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateInlineInputRenderObj, watchChanged };
27636
+ 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, 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, exportDecoratorHTML, falseChar, fontMapFunc, formatEle, fromEvent, generatePatch, getCalleeName, getFocusTextSegment, inputText, insertEle, invokeTypeHandler, isDate, logUpdateEleProps, objectToString$4 as objectToString, onTableContextmenu, onceTask, parser, reactiveMap, removeEle, removeText, renderErrorTip, renderUnderWavyLine, runTextLineRender, setChildrenModifyFlag, setNotifyChangedCallback, setTraceTrackingFlag, suppressTracking, targetMaps, textLineRenderMode, toRawType, toTypeString, trueChar, validateDataEle, validateDataEleRenderObj, validateInlineInputRenderObj, watchChanged };
27683
27637
  //# sourceMappingURL=index.js.map