@hailin-zheng/editor-core 2.2.8 → 2.2.9

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
@@ -1508,12 +1508,19 @@ class BranchElement extends Element {
1508
1508
  }
1509
1509
  return len;
1510
1510
  }
1511
- treeFilter(predicate) {
1511
+ treeFilter(predicate, options) {
1512
+ if (!options) {
1513
+ options = { includeChildren: true };
1514
+ }
1512
1515
  const items = [];
1513
1516
  for (let i = 0; i < this.length; i++) {
1514
1517
  const item = this.getChild(i);
1515
1518
  if (predicate(item)) {
1516
1519
  items.push(item);
1520
+ //已经匹配节点,不需要匹配当前元素的子节点
1521
+ if (!options.includeChildren) {
1522
+ continue;
1523
+ }
1517
1524
  }
1518
1525
  if (item instanceof BranchElement) {
1519
1526
  items.push(...item.treeFilter(predicate));
@@ -2841,15 +2848,7 @@ class ValidateProps {
2841
2848
  return clone;
2842
2849
  }
2843
2850
  }
2844
- class DataElementGroupProps extends DataEleBaseProps {
2845
- clone(dest) {
2846
- const clone = dest ?? new DataElementGroupProps();
2847
- super.cloneBaseProps(clone);
2848
- }
2849
- getSerializeProps(options) {
2850
- const props = {};
2851
- return this.getBaseProps(props, options);
2852
- }
2851
+ class DataElementGroupProps extends DataEleBaseTextProps {
2853
2852
  }
2854
2853
  class DataElementBarcodeProps {
2855
2854
  type = 'code128';
@@ -8618,7 +8617,62 @@ class DataElementDateFactory extends DataElementBaseFactory {
8618
8617
  }
8619
8618
  }
8620
8619
 
8621
- class DataElementGroupElement extends InlineGroupInputElement {
8620
+ class BreakElement extends LeafElement {
8621
+ textProps;
8622
+ constructor() {
8623
+ super('br');
8624
+ this.textProps = new TextProps();
8625
+ this.textProps.fontSize = 14;
8626
+ this.textProps.fontName = '宋体';
8627
+ this.textProps.color = '#595959';
8628
+ }
8629
+ createRenderObject() {
8630
+ const symbol = new BreakRenderObject(this);
8631
+ symbol.rect.height = 14;
8632
+ symbol.rect.width = 7;
8633
+ return symbol;
8634
+ }
8635
+ serialize() {
8636
+ return {
8637
+ type: 'br',
8638
+ props: {}
8639
+ };
8640
+ }
8641
+ clone() {
8642
+ const clone = new BreakElement();
8643
+ cloneElementBase(this, clone);
8644
+ return clone;
8645
+ }
8646
+ }
8647
+ class BreakRenderObject extends LeafRenderObject {
8648
+ exportSVG(event) {
8649
+ if (!event.options.showEnterSymbol || event.mode === 'print') {
8650
+ return null;
8651
+ }
8652
+ return ElementUtil.createSvgText('↓', { 'dominant-baseline': 'hanging',
8653
+ 'font-family': 'Courier',
8654
+ 'font-size': this.rect.height,
8655
+ x: this.rect.x + 4,
8656
+ y: this.rect.y,
8657
+ fill: 'green' });
8658
+ }
8659
+ clone() {
8660
+ const render = new BreakRenderObject(this.element);
8661
+ render.rect = ElementUtil.cloneRect(this.rect);
8662
+ return render;
8663
+ }
8664
+ }
8665
+ class BreakFactory extends ElementFactory {
8666
+ match(type) {
8667
+ return type === 'br';
8668
+ }
8669
+ createElement(data) {
8670
+ const ele = new BreakElement();
8671
+ return ele;
8672
+ }
8673
+ }
8674
+
8675
+ class DataElementGroupElement extends DataElementInlineGroup {
8622
8676
  constructor() {
8623
8677
  super('data-group');
8624
8678
  this.props = new DataElementGroupProps();
@@ -8631,6 +8685,38 @@ class DataElementGroupElement extends InlineGroupInputElement {
8631
8685
  this.refreshView();
8632
8686
  });
8633
8687
  }
8688
+ setValue(val) {
8689
+ if (val === null || val === undefined) {
8690
+ val = '';
8691
+ }
8692
+ if (this.getValue() === val) {
8693
+ return;
8694
+ }
8695
+ this.pubOnChange('self');
8696
+ this.clearInnerItems();
8697
+ if (typeof val !== 'string') {
8698
+ val += '';
8699
+ }
8700
+ if (val) {
8701
+ const items = val.split('<br/>');
8702
+ if (items.length) {
8703
+ items.forEach((item, index) => {
8704
+ const valueText = new TextGroupElement();
8705
+ this.props.valueTextProps.clone(valueText.props);
8706
+ valueText.text = item + '';
8707
+ this.addChild(valueText, this.length - 1);
8708
+ if (index < items.length - 1) {
8709
+ const brElement = new BreakElement();
8710
+ this.addChild(brElement, this.length - 1);
8711
+ }
8712
+ });
8713
+ }
8714
+ }
8715
+ this.onChangedValidate();
8716
+ }
8717
+ getValue() {
8718
+ return ElementSerialize.serializeString(this, { all: false });
8719
+ }
8634
8720
  clone(data) {
8635
8721
  return super.cloneSelf(data, DataElementGroupElement);
8636
8722
  }
@@ -8666,9 +8752,18 @@ class DataElementGroupFactory extends DataElementBaseFactory {
8666
8752
  createElement(data) {
8667
8753
  const props = data.props;
8668
8754
  const ele = new DataElementGroupElement();
8669
- ElementUtil.readEleBaseProps(ele.props, props);
8755
+ this.createDataEleProps(ele.props, props);
8670
8756
  return ele;
8671
8757
  }
8758
+ createDataEleProps(dest, props) {
8759
+ const dataEleProps = dest;
8760
+ ElementUtil.readEleBaseProps(dataEleProps, props);
8761
+ dataEleProps.nullText = props.nullText;
8762
+ dataEleProps.nullTextProps = ElementUtil.readTextProps(null, props.nullTextProps, this.options);
8763
+ dataEleProps.valueTextProps = ElementUtil.readTextProps(null, props.valueTextProps, this.options);
8764
+ dataEleProps.dataType = props.dataType;
8765
+ return dataEleProps;
8766
+ }
8672
8767
  }
8673
8768
 
8674
8769
  class DataElementImage extends DataElementLeaf {
@@ -8910,61 +9005,6 @@ class DataElementListFactory extends DataElementBaseFactory {
8910
9005
  }
8911
9006
  }
8912
9007
 
8913
- class BreakElement extends LeafElement {
8914
- textProps;
8915
- constructor() {
8916
- super('br');
8917
- this.textProps = new TextProps();
8918
- this.textProps.fontSize = 14;
8919
- this.textProps.fontName = '宋体';
8920
- this.textProps.color = '#595959';
8921
- }
8922
- createRenderObject() {
8923
- const symbol = new BreakRenderObject(this);
8924
- symbol.rect.height = 14;
8925
- symbol.rect.width = 7;
8926
- return symbol;
8927
- }
8928
- serialize() {
8929
- return {
8930
- type: 'br',
8931
- props: {}
8932
- };
8933
- }
8934
- clone() {
8935
- const clone = new BreakElement();
8936
- cloneElementBase(this, clone);
8937
- return clone;
8938
- }
8939
- }
8940
- class BreakRenderObject extends LeafRenderObject {
8941
- exportSVG(event) {
8942
- if (!event.options.showEnterSymbol || event.mode === 'print') {
8943
- return null;
8944
- }
8945
- return ElementUtil.createSvgText('↓', { 'dominant-baseline': 'hanging',
8946
- 'font-family': 'Courier',
8947
- 'font-size': this.rect.height,
8948
- x: this.rect.x + 4,
8949
- y: this.rect.y,
8950
- fill: 'green' });
8951
- }
8952
- clone() {
8953
- const render = new BreakRenderObject(this.element);
8954
- render.rect = ElementUtil.cloneRect(this.rect);
8955
- return render;
8956
- }
8957
- }
8958
- class BreakFactory extends ElementFactory {
8959
- match(type) {
8960
- return type === 'br';
8961
- }
8962
- createElement(data) {
8963
- const ele = new BreakElement();
8964
- return ele;
8965
- }
8966
- }
8967
-
8968
9008
  class DataElementText extends DataElementInlineGroup {
8969
9009
  //props: DataEleBaseTextProps;
8970
9010
  constructor() {
@@ -13303,8 +13343,8 @@ class DocumentContext {
13303
13343
  const dataEleList = this.ctx.treeFilter(item => validateDataEle(item));
13304
13344
  return dataEleList.map(item => item.props.id);
13305
13345
  }
13306
- getControlInstanceList() {
13307
- return this.ctx.treeFilter(item => validateDataEle(item));
13346
+ getControlInstanceList(options) {
13347
+ return this.ctx.treeFilter(item => validateDataEle(item), options);
13308
13348
  }
13309
13349
  getControlById(id) {
13310
13350
  return this.ctx.treeFind(item => validateDataEle(item) && item['props']['id'] === id);
@@ -13327,8 +13367,9 @@ class DocumentContext {
13327
13367
  * 获取数据元结构以及get\set闭包调用函数
13328
13368
  * @returns
13329
13369
  */
13330
- getDataElementModelList() {
13331
- const dataEleList = this.ctx.treeFilter(item => validateDataEle(item) || item instanceof DataElementInlineGroup);
13370
+ getDataElementModelList(options) {
13371
+ const dataEleList = this.ctx.treeFilter(item => validateDataEle(item), options);
13372
+ //数据元、数据组
13332
13373
  const dataInlineGroups = dataEleList.filter(item => item instanceof DataElementInlineGroup);
13333
13374
  const dataLeafs = dataEleList.filter(item => item instanceof DataElementLeaf);
13334
13375
  //复选框数据元
@@ -13337,7 +13378,7 @@ class DocumentContext {
13337
13378
  const dataOtherLeafValues = CommonUtil.removeUnionSet(dataLeafs, dataCheckList).map(item => ({
13338
13379
  id: item.props.id,
13339
13380
  name: item.props.name,
13340
- fieldName: item.props.field,
13381
+ fieldName: item.props.fieldName,
13341
13382
  item,
13342
13383
  getValue: () => {
13343
13384
  return item.getValue();
@@ -21914,7 +21955,7 @@ class DocEditor {
21914
21955
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
21915
21956
  }
21916
21957
  version() {
21917
- return "2.2.8";
21958
+ return "2.2.9";
21918
21959
  }
21919
21960
  switchPageHeaderEditor() {
21920
21961
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);