@hailin-zheng/editor-core 2.0.15 → 2.0.17

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
@@ -2243,12 +2243,14 @@ class DataEleListProps extends DataEleBaseTextProps {
2243
2243
  * 是否允许多选
2244
2244
  */
2245
2245
  multiSelect;
2246
+ displayField = 'value';
2246
2247
  clone(dest) {
2247
2248
  const clone = dest ?? new DataEleListProps();
2248
2249
  super.clone(clone);
2249
2250
  clone.options = [...this.options];
2250
2251
  clone.dropDownStyle = this.dropDownStyle;
2251
2252
  clone.multiSelect = this.multiSelect;
2253
+ clone.displayField = this.displayField;
2252
2254
  return clone;
2253
2255
  }
2254
2256
  getSerializeProps(options) {
@@ -2257,6 +2259,9 @@ class DataEleListProps extends DataEleBaseTextProps {
2257
2259
  multiSelect: this.multiSelect,
2258
2260
  dropDownStyle: this.dropDownStyle,
2259
2261
  };
2262
+ if (this.displayField && this.displayField !== 'value') {
2263
+ props['displayField'] = this.displayField;
2264
+ }
2260
2265
  super.getBaseProps(props, options);
2261
2266
  return props;
2262
2267
  }
@@ -2265,6 +2270,7 @@ class DataEleListProps extends DataEleBaseTextProps {
2265
2270
  this.options = props.options;
2266
2271
  this.multiSelect = props.multiSelect;
2267
2272
  this.dropDownStyle = props.dropDownStyle;
2273
+ this.displayField = props.displayField;
2268
2274
  }
2269
2275
  }
2270
2276
  class CommContentProps extends INotifyPropertyChanged {
@@ -2318,6 +2324,7 @@ class DataEleCheckProps extends DataEleBaseProps {
2318
2324
  falseChar = falseChar;
2319
2325
  trueStateColor = '#f00000';
2320
2326
  falseStateColor = '#000000';
2327
+ style = 'CheckBox';
2321
2328
  clone(dest) {
2322
2329
  const clone = dest ?? new DataEleCheckProps();
2323
2330
  super.cloneBaseProps(clone);
@@ -2332,6 +2339,7 @@ class DataEleCheckProps extends DataEleBaseProps {
2332
2339
  clone.border = this.border;
2333
2340
  clone.trueStateColor = this.trueStateColor;
2334
2341
  clone.falseStateColor = this.falseStateColor;
2342
+ clone.style = this.style;
2335
2343
  return clone;
2336
2344
  }
2337
2345
  getSerializeProps(options) {
@@ -2360,6 +2368,9 @@ class DataEleCheckProps extends DataEleBaseProps {
2360
2368
  if (this.falseStateColor !== '#000000') {
2361
2369
  props.falseStateColor = this.falseStateColor;
2362
2370
  }
2371
+ if (this.style !== 'CheckBox') {
2372
+ props.style = this.style;
2373
+ }
2363
2374
  this.getBaseProps(props, options);
2364
2375
  return props;
2365
2376
  }
@@ -2376,6 +2387,7 @@ class DataEleCheckProps extends DataEleBaseProps {
2376
2387
  this.trueStateColor = props.trueStateColor;
2377
2388
  this.falseStateColor = props.falseStateColor;
2378
2389
  this.border = props.border;
2390
+ this.style = props.style;
2379
2391
  }
2380
2392
  }
2381
2393
  class DataEleImageProps extends DataEleBaseProps {
@@ -2741,6 +2753,7 @@ class DataDecorateElement extends LeafElement {
2741
2753
  }
2742
2754
  }
2743
2755
  });
2756
+ this.disableClick = !isPrefix;
2744
2757
  this.isDecorate = true;
2745
2758
  }
2746
2759
  createRenderObject() {
@@ -3358,7 +3371,6 @@ class DocumentRenderObject extends BlockContainerRenderObject {
3358
3371
  'font-family': '仿宋',
3359
3372
  'font-size': '14',
3360
3373
  "fill": this.element.props.color,
3361
- 'font-style': 'italic',
3362
3374
  x: 0,
3363
3375
  y: 0,
3364
3376
  }
@@ -4249,7 +4261,7 @@ class PSymbolElement extends LeafElement {
4249
4261
  createRenderObject() {
4250
4262
  const symbol = new PSymbolRenderObject(this);
4251
4263
  symbol.rect.height = this.defaultHeight;
4252
- symbol.rect.width = 7;
4264
+ symbol.rect.width = 1;
4253
4265
  return symbol;
4254
4266
  }
4255
4267
  serialize() {
@@ -4749,7 +4761,7 @@ class TextGroupRenderObject extends LeafRenderObject {
4749
4761
  return curr.actualSize + prev;
4750
4762
  }, this.rect.x);
4751
4763
  const x = arr.join(' ');
4752
- const y = this.textMeasures.map(item => this.rect.y + vertHeight).join(' ');
4764
+ const y = this.rect.y + vertHeight; //this.textMeasures.map(item => this.rect.y + vertHeight).join(' ');
4753
4765
  const text = this.textMeasures.map(item => {
4754
4766
  return item.char;
4755
4767
  }).join('');
@@ -4798,6 +4810,10 @@ class TextGroupRenderObject extends LeafRenderObject {
4798
4810
  const path = `M${event.relativePagePos.x} ${event.relativePagePos.y} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y}`;
4799
4811
  event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4800
4812
  }
4813
+ //处理null-text
4814
+ if (this.element.isDecorate && this.element.disableClick && !this.element.parent) {
4815
+ t.data.attrs['opacity'] = '0.58';
4816
+ }
4801
4817
  return t;
4802
4818
  }
4803
4819
  }
@@ -5069,10 +5085,7 @@ class SelectionRange {
5069
5085
  }
5070
5086
  setInfo(control, offset) {
5071
5087
  if (control instanceof LeafElement) {
5072
- if (control instanceof TextGroupElement) {
5073
- offset = offset === -1 ? control.text.length : offset;
5074
- }
5075
- offset = offset === -1 ? 1 : offset;
5088
+ offset = ElementUtil.fixedOffset(control, offset);
5076
5089
  return { control, offset };
5077
5090
  }
5078
5091
  else if (control instanceof BranchElement) {
@@ -6271,6 +6284,40 @@ class TableUtil {
6271
6284
  });
6272
6285
  }
6273
6286
  }
6287
+ static getTableData(tb) {
6288
+ //根据实际要提取的行索引进行调整
6289
+ const rowData = [];
6290
+ for (let i = 0; i < tb.length; i++) {
6291
+ const row = tb.getChild(i);
6292
+ const cellData = [];
6293
+ for (let j = 0; j < row.length; j++) {
6294
+ const cell = row.getChild(j);
6295
+ cellData.push(this.getCellData(cell));
6296
+ }
6297
+ rowData.push(cellData);
6298
+ }
6299
+ return rowData;
6300
+ }
6301
+ /**
6302
+ * 获取单元格内的数据元的值
6303
+ * @param target
6304
+ */
6305
+ static getCellData(target) {
6306
+ if (validateDataEle(target)) {
6307
+ const dataEle = target;
6308
+ return { id: dataEle.props.id, value: dataEle.getValue() };
6309
+ }
6310
+ if (target instanceof BranchElement) {
6311
+ for (let i = 0; i < target.length; i++) {
6312
+ const child = target.getChild(i);
6313
+ const val = this.getCellData(child);
6314
+ if (val !== null) {
6315
+ return val;
6316
+ }
6317
+ }
6318
+ }
6319
+ return null;
6320
+ }
6274
6321
  }
6275
6322
 
6276
6323
  class TableElement extends BlockContainerElement {
@@ -8651,6 +8698,46 @@ class ElementUtil {
8651
8698
  ]
8652
8699
  };
8653
8700
  }
8701
+ /**
8702
+ * 判断是否光标可以设置接受编辑
8703
+ * @returns
8704
+ */
8705
+ static canSetCursor(startControl, startOffset, editable, viewOptions) {
8706
+ if (!startControl || !editable) {
8707
+ return false;
8708
+ }
8709
+ if (viewOptions.docMode === DocMode.Design) {
8710
+ return true;
8711
+ }
8712
+ //浏览模式
8713
+ if (viewOptions.docMode === DocMode.View) {
8714
+ return false;
8715
+ }
8716
+ //表单模式下,如果不在数据元素中,则不显示光标
8717
+ if (viewOptions.docMode === DocMode.FormEdit) {
8718
+ if (!IsInSideDataElement(startControl, startOffset)) {
8719
+ return false;
8720
+ }
8721
+ }
8722
+ if (!ElementUtil.verifyHitable(startControl)) {
8723
+ return false;
8724
+ }
8725
+ //表单模式下,数据元不可编辑
8726
+ if (viewOptions.docMode === DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
8727
+ const dataEle = ElementUtil.getDataElement(startControl);
8728
+ if (dataEle && !dataEle.props.editable) {
8729
+ return false;
8730
+ }
8731
+ }
8732
+ return true;
8733
+ }
8734
+ static fixedOffset(control, offset) {
8735
+ if (control instanceof TextGroupElement) {
8736
+ offset = offset === -1 ? control.text.length : offset;
8737
+ }
8738
+ offset = offset === -1 ? 1 : offset;
8739
+ return offset;
8740
+ }
8654
8741
  }
8655
8742
 
8656
8743
  class RenderContext {
@@ -10784,74 +10871,83 @@ class DataElementCheckRenderObject extends LeafRenderObject {
10784
10871
  });
10785
10872
  }
10786
10873
  else {
10874
+ const style = props.style;
10787
10875
  if (props.multiSelect) {
10788
- t.children.push({
10789
- sel: 'rect',
10790
- data: {
10791
- ns: "http://www.w3.org/2000/svg",
10792
- attrs: {
10793
- x: 2,
10794
- y: 0,
10795
- width,
10796
- height,
10797
- stroke: 'black',
10798
- fill: 'none',
10799
- 'stroke-width': 1
10800
- }
10801
- }
10802
- });
10803
- if (props.checked) {
10804
- const paths = ElementUtil.getCheckboxPath(2, 0, props.size, props.size);
10805
- t.children.push({
10806
- sel: 'path',
10807
- data: {
10808
- ns: "http://www.w3.org/2000/svg",
10809
- attrs: {
10810
- d: paths.map((item, index) => {
10811
- return `${index === 0 ? 'M' : 'L'}${item.x},${item.y}`;
10812
- }).join(' '),
10813
- stroke: 'red',
10814
- fill: 'none',
10815
- 'stroke-width': 2
10816
- }
10817
- }
10818
- });
10819
- }
10876
+ style === 'RadioButton' ? this.drawCircleCheckbox(t, width, height, props.checked)
10877
+ : this.drawRectCheckbox(t, width, height, props.size, props.checked);
10820
10878
  }
10821
10879
  else {
10822
- t.children.push({
10823
- sel: 'circle',
10824
- data: {
10825
- ns: "http://www.w3.org/2000/svg",
10826
- attrs: {
10827
- cx: width / 2,
10828
- cy: height / 2,
10829
- r: width / 3,
10830
- stroke: 'black',
10831
- fill: 'none',
10832
- 'stroke-width': 1
10833
- }
10880
+ style === 'CheckBox' ? this.drawRectCheckbox(t, width, height, props.size, props.checked)
10881
+ : this.drawCircleCheckbox(t, width, height, props.checked);
10882
+ }
10883
+ }
10884
+ return t;
10885
+ }
10886
+ drawRectCheckbox(t, width, height, size, checked) {
10887
+ t.children.push({
10888
+ sel: 'rect',
10889
+ data: {
10890
+ ns: "http://www.w3.org/2000/svg",
10891
+ attrs: {
10892
+ x: 2,
10893
+ y: 0,
10894
+ width,
10895
+ height,
10896
+ stroke: 'black',
10897
+ fill: 'none',
10898
+ 'stroke-width': 1
10899
+ }
10900
+ }
10901
+ });
10902
+ if (checked) {
10903
+ const paths = ElementUtil.getCheckboxPath(2, 0, size, size);
10904
+ t.children.push({
10905
+ sel: 'path',
10906
+ data: {
10907
+ ns: "http://www.w3.org/2000/svg",
10908
+ attrs: {
10909
+ d: paths.map((item, index) => {
10910
+ return `${index === 0 ? 'M' : 'L'}${item.x},${item.y}`;
10911
+ }).join(' '),
10912
+ stroke: 'red',
10913
+ fill: 'none',
10914
+ 'stroke-width': 2
10834
10915
  }
10835
- });
10836
- if (props.checked) {
10837
- t.children.push({
10838
- sel: 'circle',
10839
- data: {
10840
- ns: "http://www.w3.org/2000/svg",
10841
- attrs: {
10842
- cx: width / 2,
10843
- cy: height / 2,
10844
- r: width / 5,
10845
- stroke: 'black',
10846
- fill: 'black',
10847
- 'stroke-width': 1
10848
- }
10849
- }
10850
- });
10916
+ }
10917
+ });
10918
+ }
10919
+ }
10920
+ drawCircleCheckbox(t, width, height, checked) {
10921
+ t.children.push({
10922
+ sel: 'circle',
10923
+ data: {
10924
+ ns: "http://www.w3.org/2000/svg",
10925
+ attrs: {
10926
+ cx: 2 + width / 2,
10927
+ cy: height / 2,
10928
+ r: width / 3,
10929
+ stroke: 'black',
10930
+ fill: 'none',
10931
+ 'stroke-width': 1
10851
10932
  }
10852
10933
  }
10934
+ });
10935
+ if (checked) {
10936
+ t.children.push({
10937
+ sel: 'circle',
10938
+ data: {
10939
+ ns: "http://www.w3.org/2000/svg",
10940
+ attrs: {
10941
+ cx: 2 + width / 2,
10942
+ cy: height / 2,
10943
+ r: width / 5,
10944
+ stroke: 'black',
10945
+ fill: 'black',
10946
+ 'stroke-width': 1
10947
+ }
10948
+ }
10949
+ });
10853
10950
  }
10854
- return t;
10855
10951
  }
10856
10952
  }
10857
10953
  class DataElementCheckFactory extends ElementFactory {
@@ -10876,6 +10972,7 @@ class DataElementCheckFactory extends ElementFactory {
10876
10972
  dataEleProps.trueChar = props.trueChar ?? trueChar;
10877
10973
  dataEleProps.falseChar = props.falseChar ?? falseChar;
10878
10974
  dataEleProps.border = props.border ?? true;
10975
+ dataEleProps.style = props.style ?? 'CheckBox';
10879
10976
  return dataEleProps;
10880
10977
  }
10881
10978
  }
@@ -11270,6 +11367,8 @@ class DataElementList extends DataElementInlineGroup {
11270
11367
  }
11271
11368
  this.pubOnChange('self');
11272
11369
  this.clearInnerItems();
11370
+ let displayField = this.props.displayField;
11371
+ displayField = displayField ? displayField : 'value';
11273
11372
  if (this.props.multiSelect) {
11274
11373
  for (let i = 0; i < vals.length; i++) {
11275
11374
  const val = vals[i];
@@ -11278,12 +11377,14 @@ class DataElementList extends DataElementInlineGroup {
11278
11377
  const valueText = new TextGroupElement();
11279
11378
  this.props.valueTextProps.clone(valueText.props);
11280
11379
  const splitSymbol = i < vals.length - 1 ? ';' : '';
11281
- valueText.text = option.value + splitSymbol;
11380
+ valueText.text = option[displayField] + splitSymbol;
11282
11381
  this.addChild(valueText, this.length - 1);
11283
11382
  }
11284
11383
  }
11285
11384
  }
11286
11385
  else {
11386
+ let displayField = this.props.displayField;
11387
+ displayField = displayField ? displayField : 'value';
11287
11388
  if (vals.length > 1) {
11288
11389
  console.warn('当前下拉框是单选模式,不能传入多个值');
11289
11390
  }
@@ -11292,7 +11393,7 @@ class DataElementList extends DataElementInlineGroup {
11292
11393
  if (option) {
11293
11394
  const valueText = new TextGroupElement();
11294
11395
  this.props.valueTextProps.clone(valueText.props);
11295
- valueText.text = option.value;
11396
+ valueText.text = option[displayField];
11296
11397
  this.addChild(valueText, this.length - 1);
11297
11398
  }
11298
11399
  }
@@ -11303,10 +11404,12 @@ class DataElementList extends DataElementInlineGroup {
11303
11404
  if (!values) {
11304
11405
  return '';
11305
11406
  }
11407
+ let displayField = this.props.displayField;
11408
+ displayField = displayField ? displayField : 'value';
11306
11409
  const valueItems = values.split(';');
11307
11410
  const valueCode = [];
11308
11411
  for (const valueItem of valueItems) {
11309
- const option = this.props.options.find(item => item.value === valueItem);
11412
+ const option = this.props.options.find(item => item[displayField] === valueItem);
11310
11413
  if (option) {
11311
11414
  valueCode.push(option.code);
11312
11415
  }
@@ -11351,6 +11454,7 @@ class DataElementListFactory extends DataElementBaseFactory {
11351
11454
  dataEleProps.multiSelect = props.multiSelect;
11352
11455
  dataEleProps.options = [...options];
11353
11456
  dataEleProps.dropDownStyle = props.dropDownStyle;
11457
+ dataEleProps.displayField = props.displayField ?? 'value';
11354
11458
  return dataEleProps;
11355
11459
  }
11356
11460
  }
@@ -17536,7 +17640,6 @@ class DocumentEvent {
17536
17640
  if (resizeColWidth < minColWidth || cellWidth < minColWidth) {
17537
17641
  return;
17538
17642
  }
17539
- console.log(resizeColWidth, cellWidth);
17540
17643
  table.setCellWidth(resizeColIndex, resizeColWidth);
17541
17644
  table.setCellWidth(cellIndex, cellWidth);
17542
17645
  this.edgeRenderInfo.mousedownPos = this.currentPos;
@@ -17710,6 +17813,15 @@ class DocumentEvent {
17710
17813
  */
17711
17814
  moveCursorToLeft() {
17712
17815
  const { startControl, startOffset } = this.selectionState;
17816
+ this.moveCursorToLeftHandle(startControl, startOffset);
17817
+ }
17818
+ /**
17819
+ * 向左移动光标处理函数
17820
+ * @param startControl
17821
+ * @param startOffset
17822
+ * @private
17823
+ */
17824
+ moveCursorToLeftHandle(startControl, startOffset) {
17713
17825
  if (startOffset === 0) {
17714
17826
  const oldRegion = ElementUtil.getElementRegion(startControl);
17715
17827
  const prevEle = ElementUtil.getRecursionPrevSiblingElement(startControl, false, true, this.viewOptions);
@@ -17718,6 +17830,10 @@ class DocumentEvent {
17718
17830
  if (newRegion !== oldRegion) {
17719
17831
  return;
17720
17832
  }
17833
+ if (this.viewOptions.docMode === DocMode.FormEdit && !ElementUtil.canSetCursor(prevEle, ElementUtil.fixedOffset(prevEle, -1), true, this.viewOptions)) {
17834
+ this.moveCursorToLeftHandle(prevEle, 0);
17835
+ return;
17836
+ }
17721
17837
  this.selectionState.resetRange(prevEle, -1);
17722
17838
  return;
17723
17839
  }
@@ -17727,6 +17843,10 @@ class DocumentEvent {
17727
17843
  this.selectionState.resetRange(startControl, startOffset - 1);
17728
17844
  }
17729
17845
  else {
17846
+ if (this.viewOptions.docMode === DocMode.FormEdit && !ElementUtil.canSetCursor(startControl, ElementUtil.fixedOffset(startControl, 0), true, this.viewOptions)) {
17847
+ this.moveCursorToLeftHandle(startControl, 0);
17848
+ return;
17849
+ }
17730
17850
  this.selectionState.resetRange(startControl, 0);
17731
17851
  }
17732
17852
  }
@@ -17736,6 +17856,9 @@ class DocumentEvent {
17736
17856
  */
17737
17857
  moveCursorToRight() {
17738
17858
  const { startControl, startOffset } = this.selectionState;
17859
+ this.moveCursorToRightHandle(startControl, startOffset);
17860
+ }
17861
+ moveCursorToRightHandle(startControl, startOffset) {
17739
17862
  if (this.isLeafEleEndOffset(startControl, startOffset)) {
17740
17863
  const oldRegion = ElementUtil.getElementRegion(startControl);
17741
17864
  const nextEle = ElementUtil.getRecursionNextSiblingElement(startControl, false, true, this.viewOptions);
@@ -17744,7 +17867,11 @@ class DocumentEvent {
17744
17867
  if (oldRegion !== newRegion) {
17745
17868
  return;
17746
17869
  }
17747
- this.selectionState.resetRange(nextEle, 0);
17870
+ if (this.viewOptions.docMode === DocMode.FormEdit && !ElementUtil.canSetCursor(nextEle, ElementUtil.fixedOffset(nextEle, -1), true, this.viewOptions)) {
17871
+ this.moveCursorToRightHandle(nextEle, ElementUtil.fixedOffset(nextEle, -1));
17872
+ return;
17873
+ }
17874
+ this.selectionState.resetRange(nextEle, 1);
17748
17875
  return;
17749
17876
  }
17750
17877
  }
@@ -17753,6 +17880,10 @@ class DocumentEvent {
17753
17880
  this.selectionState.resetRange(startControl, startOffset + 1);
17754
17881
  }
17755
17882
  else {
17883
+ if (this.viewOptions.docMode === DocMode.FormEdit && !ElementUtil.canSetCursor(startControl, 0, true, this.viewOptions)) {
17884
+ this.moveCursorToRightHandle(startControl, ElementUtil.fixedOffset(startControl, -1));
17885
+ return;
17886
+ }
17756
17887
  this.selectionState.resetRange(startControl, 1);
17757
17888
  }
17758
17889
  }
@@ -26938,33 +27069,7 @@ class DocEditor {
26938
27069
  */
26939
27070
  canSetCursor() {
26940
27071
  const { startControl, startOffset, editable } = this.selectionState;
26941
- if (!startControl || !editable) {
26942
- return false;
26943
- }
26944
- if (this.viewOptions.docMode === DocMode.Design) {
26945
- return true;
26946
- }
26947
- //浏览模式
26948
- if (this.viewOptions.docMode === DocMode.View) {
26949
- return false;
26950
- }
26951
- //表单模式下,如果不在数据元素中,则不显示光标
26952
- if (this.viewOptions.docMode === DocMode.FormEdit) {
26953
- if (!IsInSideDataElement(startControl, startOffset)) {
26954
- return false;
26955
- }
26956
- }
26957
- if (!ElementUtil.verifyHitable(startControl)) {
26958
- return false;
26959
- }
26960
- //表单模式下,数据元不可编辑
26961
- if (this.viewOptions.docMode === DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
26962
- const dataEle = ElementUtil.getDataElement(startControl);
26963
- if (dataEle && !dataEle.props.editable) {
26964
- return false;
26965
- }
26966
- }
26967
- return true;
27072
+ return ElementUtil.canSetCursor(startControl, startOffset, editable, this.viewOptions);
26968
27073
  }
26969
27074
  /**
26970
27075
  * 修改光标
@@ -27458,6 +27563,15 @@ class DocEditor {
27458
27563
  const { startControl, startOffset } = this.selectionState;
27459
27564
  this.insertElement(startControl, startOffset, [ele]);
27460
27565
  }
27566
+ test() {
27567
+ const text = new TextGroupElement();
27568
+ text.props.fontName = '宋体';
27569
+ text.props.fontSize = 14;
27570
+ text.text = '哈哈';
27571
+ const br = new BreakElement();
27572
+ const { startControl, startOffset } = this.selectionState;
27573
+ this.insertElement(startControl, startOffset, [text, br]);
27574
+ }
27461
27575
  switchPageLayout(mode) {
27462
27576
  this.viewOptions.pageLayoutMode = mode;
27463
27577
  this.flushToSchedule();