@hailin-zheng/editor-core 2.0.16 → 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 {
@@ -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('');
@@ -10859,74 +10871,83 @@ class DataElementCheckRenderObject extends LeafRenderObject {
10859
10871
  });
10860
10872
  }
10861
10873
  else {
10874
+ const style = props.style;
10862
10875
  if (props.multiSelect) {
10863
- t.children.push({
10864
- sel: 'rect',
10865
- data: {
10866
- ns: "http://www.w3.org/2000/svg",
10867
- attrs: {
10868
- x: 2,
10869
- y: 0,
10870
- width,
10871
- height,
10872
- stroke: 'black',
10873
- fill: 'none',
10874
- 'stroke-width': 1
10875
- }
10876
- }
10877
- });
10878
- if (props.checked) {
10879
- const paths = ElementUtil.getCheckboxPath(2, 0, props.size, props.size);
10880
- t.children.push({
10881
- sel: 'path',
10882
- data: {
10883
- ns: "http://www.w3.org/2000/svg",
10884
- attrs: {
10885
- d: paths.map((item, index) => {
10886
- return `${index === 0 ? 'M' : 'L'}${item.x},${item.y}`;
10887
- }).join(' '),
10888
- stroke: 'red',
10889
- fill: 'none',
10890
- 'stroke-width': 2
10891
- }
10892
- }
10893
- });
10894
- }
10876
+ style === 'RadioButton' ? this.drawCircleCheckbox(t, width, height, props.checked)
10877
+ : this.drawRectCheckbox(t, width, height, props.size, props.checked);
10895
10878
  }
10896
10879
  else {
10897
- t.children.push({
10898
- sel: 'circle',
10899
- data: {
10900
- ns: "http://www.w3.org/2000/svg",
10901
- attrs: {
10902
- cx: 2 + width / 2,
10903
- cy: height / 2,
10904
- r: width / 3,
10905
- stroke: 'black',
10906
- fill: 'none',
10907
- 'stroke-width': 1
10908
- }
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
10909
10915
  }
10910
- });
10911
- if (props.checked) {
10912
- t.children.push({
10913
- sel: 'circle',
10914
- data: {
10915
- ns: "http://www.w3.org/2000/svg",
10916
- attrs: {
10917
- cx: 2 + width / 2,
10918
- cy: height / 2,
10919
- r: width / 5,
10920
- stroke: 'black',
10921
- fill: 'black',
10922
- 'stroke-width': 1
10923
- }
10924
- }
10925
- });
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
10926
10932
  }
10927
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
+ });
10928
10950
  }
10929
- return t;
10930
10951
  }
10931
10952
  }
10932
10953
  class DataElementCheckFactory extends ElementFactory {
@@ -10951,6 +10972,7 @@ class DataElementCheckFactory extends ElementFactory {
10951
10972
  dataEleProps.trueChar = props.trueChar ?? trueChar;
10952
10973
  dataEleProps.falseChar = props.falseChar ?? falseChar;
10953
10974
  dataEleProps.border = props.border ?? true;
10975
+ dataEleProps.style = props.style ?? 'CheckBox';
10954
10976
  return dataEleProps;
10955
10977
  }
10956
10978
  }
@@ -11345,6 +11367,8 @@ class DataElementList extends DataElementInlineGroup {
11345
11367
  }
11346
11368
  this.pubOnChange('self');
11347
11369
  this.clearInnerItems();
11370
+ let displayField = this.props.displayField;
11371
+ displayField = displayField ? displayField : 'value';
11348
11372
  if (this.props.multiSelect) {
11349
11373
  for (let i = 0; i < vals.length; i++) {
11350
11374
  const val = vals[i];
@@ -11353,12 +11377,14 @@ class DataElementList extends DataElementInlineGroup {
11353
11377
  const valueText = new TextGroupElement();
11354
11378
  this.props.valueTextProps.clone(valueText.props);
11355
11379
  const splitSymbol = i < vals.length - 1 ? ';' : '';
11356
- valueText.text = option.value + splitSymbol;
11380
+ valueText.text = option[displayField] + splitSymbol;
11357
11381
  this.addChild(valueText, this.length - 1);
11358
11382
  }
11359
11383
  }
11360
11384
  }
11361
11385
  else {
11386
+ let displayField = this.props.displayField;
11387
+ displayField = displayField ? displayField : 'value';
11362
11388
  if (vals.length > 1) {
11363
11389
  console.warn('当前下拉框是单选模式,不能传入多个值');
11364
11390
  }
@@ -11367,7 +11393,7 @@ class DataElementList extends DataElementInlineGroup {
11367
11393
  if (option) {
11368
11394
  const valueText = new TextGroupElement();
11369
11395
  this.props.valueTextProps.clone(valueText.props);
11370
- valueText.text = option.value;
11396
+ valueText.text = option[displayField];
11371
11397
  this.addChild(valueText, this.length - 1);
11372
11398
  }
11373
11399
  }
@@ -11378,10 +11404,12 @@ class DataElementList extends DataElementInlineGroup {
11378
11404
  if (!values) {
11379
11405
  return '';
11380
11406
  }
11407
+ let displayField = this.props.displayField;
11408
+ displayField = displayField ? displayField : 'value';
11381
11409
  const valueItems = values.split(';');
11382
11410
  const valueCode = [];
11383
11411
  for (const valueItem of valueItems) {
11384
- const option = this.props.options.find(item => item.value === valueItem);
11412
+ const option = this.props.options.find(item => item[displayField] === valueItem);
11385
11413
  if (option) {
11386
11414
  valueCode.push(option.code);
11387
11415
  }
@@ -11426,6 +11454,7 @@ class DataElementListFactory extends DataElementBaseFactory {
11426
11454
  dataEleProps.multiSelect = props.multiSelect;
11427
11455
  dataEleProps.options = [...options];
11428
11456
  dataEleProps.dropDownStyle = props.dropDownStyle;
11457
+ dataEleProps.displayField = props.displayField ?? 'value';
11429
11458
  return dataEleProps;
11430
11459
  }
11431
11460
  }
@@ -27534,6 +27563,15 @@ class DocEditor {
27534
27563
  const { startControl, startOffset } = this.selectionState;
27535
27564
  this.insertElement(startControl, startOffset, [ele]);
27536
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
+ }
27537
27575
  switchPageLayout(mode) {
27538
27576
  this.viewOptions.pageLayoutMode = mode;
27539
27577
  this.flushToSchedule();
@@ -27684,7 +27722,7 @@ class DocEditor {
27684
27722
  const vNodeFunc = this.renderRoot();
27685
27723
  setActiveEditorContext(null);
27686
27724
  const render = () => {
27687
- console.time('patch');
27725
+ //console.time('patch');
27688
27726
  setActiveEditorContext(this);
27689
27727
  const vNode = vNodeFunc.render();
27690
27728
  setActiveEditorContext(null);
@@ -27696,7 +27734,7 @@ class DocEditor {
27696
27734
  this.vNodeDocContent = this.nodePatch(this.svgContainer, vNode);
27697
27735
  }
27698
27736
  this.afterNodePatch.next();
27699
- console.timeEnd('patch');
27737
+ //console.timeEnd('patch');
27700
27738
  };
27701
27739
  render();
27702
27740
  this.onShouldRender.subscribe(() => {