@hailin-zheng/editor-core 2.2.26 → 2.2.28

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-cjs.js CHANGED
@@ -2604,9 +2604,9 @@ class DataEleListProps extends DataEleBaseTextProps {
2604
2604
  }
2605
2605
  options = [];
2606
2606
  /**
2607
- * 是否保存选项到病历文件里面
2607
+ * 是否持久化选项到病历文件里面
2608
2608
  */
2609
- saveOptions = true;
2609
+ persistItems = true;
2610
2610
  dropDownStyle;
2611
2611
  /**
2612
2612
  * 是否允许多选
@@ -2620,28 +2620,41 @@ class DataEleListProps extends DataEleBaseTextProps {
2620
2620
  clone.dropDownStyle = this.dropDownStyle;
2621
2621
  clone.multiSelect = this.multiSelect;
2622
2622
  clone.displayField = this.displayField;
2623
+ clone.persistItems = this.persistItems;
2623
2624
  return clone;
2624
2625
  }
2625
2626
  getSerializeProps(options) {
2626
2627
  const props = {
2627
- options: [...this.options],
2628
2628
  multiSelect: this.multiSelect,
2629
2629
  dropDownStyle: this.dropDownStyle,
2630
+ persistItems: this.persistItems,
2630
2631
  };
2631
2632
  if (this.displayField && this.displayField !== 'value') {
2632
2633
  props['displayField'] = this.displayField;
2633
2634
  }
2635
+ if (this.persistItems) {
2636
+ props.options = [...this.options];
2637
+ }
2634
2638
  super.getBaseProps(props, options);
2635
2639
  return props;
2636
2640
  }
2637
2641
  updateProps(props) {
2638
2642
  super.updateProps(props);
2639
- this.options = props.options;
2640
- this.multiSelect = props.multiSelect;
2641
- this.dropDownStyle = props.dropDownStyle;
2642
- this.displayField = props.displayField;
2643
+ updatePartialProps(this, props);
2643
2644
  }
2644
2645
  }
2646
+ function updatePartialProps(destProps, sourceProps) {
2647
+ const destPropsKeys = Object.keys(destProps);
2648
+ const sourcePropsKeys = Object.keys(sourceProps);
2649
+ sourcePropsKeys.forEach(key => {
2650
+ if (destPropsKeys.includes(key)) {
2651
+ if (destProps[key] === sourceProps[key]) {
2652
+ return;
2653
+ }
2654
+ destProps[key] = sourceProps[key];
2655
+ }
2656
+ });
2657
+ }
2645
2658
  class CommContentProps extends INotifyPropertyChanged {
2646
2659
  id;
2647
2660
  createId;
@@ -6984,6 +6997,9 @@ class DocumentSelection {
6984
6997
  if (!this.snapshotSelectionState) {
6985
6998
  return true;
6986
6999
  }
7000
+ if (this.selectionState.editable !== this.snapshotSelectionState.editable) {
7001
+ return true;
7002
+ }
6987
7003
  if (this.selectionState.startControl !== this.snapshotSelectionState.startControl || this.selectionState.startOffset !== this.snapshotSelectionState.startOffset) {
6988
7004
  return true;
6989
7005
  }
@@ -9408,6 +9424,7 @@ class DataElementListFactory extends DataElementBaseFactory {
9408
9424
  dataEleProps.options = [...options];
9409
9425
  dataEleProps.dropDownStyle = props.dropDownStyle;
9410
9426
  dataEleProps.displayField = props.displayField ?? 'value';
9427
+ dataEleProps.persistItems = props.persistItems ?? true;
9411
9428
  return dataEleProps;
9412
9429
  }
9413
9430
  }
@@ -18653,18 +18670,45 @@ class DocumentChange {
18653
18670
  */
18654
18671
  insertElement(targetElement, targetOffset, destEleArray) {
18655
18672
  let lastEle;
18673
+ //创建文本元素并插入
18674
+ const insertNewText = (text, parent, index) => {
18675
+ const inputTextProps = this.getDefaultTextPropsByOptions();
18676
+ const newTextEle = ElementUtil.getNewTextGroup(inputTextProps);
18677
+ newTextEle.text = text;
18678
+ parent.addChild(newTextEle, index);
18679
+ };
18656
18680
  if (targetElement instanceof TextGroupElement) {
18657
18681
  const { leftElement, rightElement } = this.splitText(targetElement, targetOffset);
18658
18682
  if (leftElement) {
18659
18683
  for (let i = 0; i < destEleArray.length; i++) {
18660
18684
  lastEle = destEleArray[i];
18661
- leftElement.parent.addChild(lastEle, leftElement.getIndex() + 1 + i);
18685
+ //判断是否可以插入元素
18686
+ if (this.canInsertElement(leftElement.parent, lastEle)) {
18687
+ leftElement.parent.addChild(lastEle, leftElement.getIndex() + 1 + i);
18688
+ }
18689
+ else {
18690
+ //序列化为纯文本
18691
+ const serializeString = ElementSerialize.serializeString(lastEle);
18692
+ if (serializeString) {
18693
+ insertNewText(serializeString, leftElement.parent, leftElement.getIndex() + 1 + i);
18694
+ }
18695
+ }
18662
18696
  }
18663
18697
  }
18664
18698
  else if (rightElement) {
18665
18699
  for (let i = 0; i < destEleArray.length; i++) {
18666
18700
  lastEle = destEleArray[i];
18667
- rightElement.parent.addChild(lastEle, rightElement.getIndex());
18701
+ //判断是否可以插入元素
18702
+ if (this.canInsertElement(rightElement.parent, lastEle)) {
18703
+ rightElement.parent.addChild(lastEle, rightElement.getIndex());
18704
+ }
18705
+ else {
18706
+ //序列化为纯文本
18707
+ const serializeString = ElementSerialize.serializeString(lastEle);
18708
+ if (serializeString) {
18709
+ insertNewText(serializeString, rightElement.parent, rightElement.getIndex());
18710
+ }
18711
+ }
18668
18712
  }
18669
18713
  }
18670
18714
  }
@@ -18673,13 +18717,39 @@ class DocumentChange {
18673
18717
  let insertTargetOffset = targetOffset;
18674
18718
  for (let i = 0; i < destEleArray.length; i++) {
18675
18719
  lastEle = destEleArray[i];
18676
- insertTarget.parent.addChild(lastEle, insertTarget.getIndex() + insertTargetOffset);
18677
- insertTarget = lastEle;
18678
- insertTargetOffset = 1;
18720
+ //判断是否可以插入元素
18721
+ if (this.canInsertElement(insertTarget.parent, lastEle)) {
18722
+ insertTarget.parent.addChild(lastEle, insertTarget.getIndex() + insertTargetOffset);
18723
+ insertTarget = lastEle;
18724
+ insertTargetOffset = 1;
18725
+ }
18679
18726
  }
18680
18727
  }
18681
18728
  return lastEle;
18682
18729
  }
18730
+ /**
18731
+ * 校验容器是否允许插入元素
18732
+ * @param container
18733
+ * @param ele
18734
+ * @returns
18735
+ */
18736
+ canInsertElement(container, ele) {
18737
+ //是否为数据元
18738
+ const isDataEle = container instanceof DataElementInlineGroup;
18739
+ //数据元内部不能嵌套数据元
18740
+ if (isDataEle && ele instanceof DataElementInlineGroup) {
18741
+ return false;
18742
+ }
18743
+ //非布局元素不可以插入段落
18744
+ if (!(container instanceof BlockContainerElement) && ele instanceof BlockContentElement) {
18745
+ return false;
18746
+ }
18747
+ //段落内容内不能插入布局元素
18748
+ if (!(container instanceof BlockContentElement) && ele instanceof BlockContainerElement) {
18749
+ return false;
18750
+ }
18751
+ return true;
18752
+ }
18683
18753
  /**
18684
18754
  * 根据开始位置和结束位置,将字符切割成指定的区间
18685
18755
  * @param text
@@ -18935,10 +19005,7 @@ class DocumentChange {
18935
19005
  }
18936
19006
  //表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
18937
19007
  if (this.viewOptions.docMode === exports.DocMode.FormEdit) {
18938
- const pasteString = pasteEles.map(item => ElementSerialize.serializeString(item)).join('');
18939
- if (pasteString) {
18940
- this.pastePlainText(pasteString);
18941
- }
19008
+ this.handlePasteInFormEditMode(pasteEles);
18942
19009
  return;
18943
19010
  }
18944
19011
  //复制的内容为表格,且操作位于单元格内
@@ -18966,6 +19033,23 @@ class DocumentChange {
18966
19033
  this.selectionState.resetRange(lastEle, -1);
18967
19034
  }
18968
19035
  }
19036
+ /**
19037
+ * 处理表单模式下的粘贴事件
19038
+ * @param data 要粘贴的元素
19039
+ */
19040
+ handlePasteInFormEditMode(data) {
19041
+ // if (data.some(item => this.canInsertElement()))
19042
+ // const pasteString = data.map(item => ElementSerialize.serializeString(item)).join('');
19043
+ // if (pasteString) {
19044
+ // this.pastePlainText(pasteString);
19045
+ // }
19046
+ const { startControl, startOffset } = this.selectionState;
19047
+ const lastEle = this.insertElement(startControl, startOffset, data);
19048
+ this.selectionState.clear();
19049
+ if (lastEle && lastEle.parent) {
19050
+ this.selectionState.resetRange(lastEle, -1);
19051
+ }
19052
+ }
18969
19053
  /**
18970
19054
  * 复制单元格向另一个单元格粘贴
18971
19055
  * @private
@@ -22042,6 +22126,14 @@ class DocEditor {
22042
22126
  getDocSchema() {
22043
22127
  return ElementSerialize.serialize(this.docCtx.document, this.viewOptions);
22044
22128
  }
22129
+ /**
22130
+ * 获取元素模型
22131
+ * @param ele
22132
+ * @returns
22133
+ */
22134
+ getEleSchemaJSON(ele) {
22135
+ return JSON.stringify(ElementSerialize.serialize(ele, this.viewOptions));
22136
+ }
22045
22137
  getDocSchemaJSON() {
22046
22138
  const res = JSON.stringify(this.getDocSchema());
22047
22139
  return res;
@@ -23052,7 +23144,7 @@ class DocEditor {
23052
23144
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
23053
23145
  }
23054
23146
  version() {
23055
- return "2.2.26";
23147
+ return "2.2.28";
23056
23148
  }
23057
23149
  switchPageHeaderEditor() {
23058
23150
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -29087,6 +29179,7 @@ exports.textLineRenderMode = textLineRenderMode;
29087
29179
  exports.toRawType = toRawType;
29088
29180
  exports.toTypeString = toTypeString;
29089
29181
  exports.trueChar = trueChar;
29182
+ exports.updatePartialProps = updatePartialProps;
29090
29183
  exports.validateDataEle = validateDataEle;
29091
29184
  exports.validateDataEleRenderObj = validateDataEleRenderObj;
29092
29185
  exports.validateDataGroup = validateDataGroup;