@hailin-zheng/editor-core 1.1.28 → 1.1.29

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
@@ -4979,7 +4979,7 @@ class TableUtil {
4979
4979
  let index = colIndex;
4980
4980
  for (let i = colIndex + 1; i < tb.getColsCount(); i++) {
4981
4981
  const cell = currRow.getChild(i);
4982
- if (cell.props.hMerge === 'continue') {
4982
+ if (cell && cell.props.hMerge === 'continue') {
4983
4983
  index = i;
4984
4984
  }
4985
4985
  else {
@@ -5117,6 +5117,9 @@ class TableUtil {
5117
5117
  }
5118
5118
  }
5119
5119
  tb.removeChild(row);
5120
+ if (tb.length === 0) {
5121
+ tb.remove();
5122
+ }
5120
5123
  }
5121
5124
  /**
5122
5125
  * 移除列
@@ -5158,15 +5161,31 @@ class TableUtil {
5158
5161
  if (!ss.startControl) {
5159
5162
  return;
5160
5163
  }
5161
- const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5162
- if (!startCell?.parent) {
5163
- throw new Error('parent is null');
5164
+ const tb = ElementUtil.getParentByType(ss.startControl, TableElement);
5165
+ if (!tb) {
5166
+ return;
5164
5167
  }
5165
- const currRow = startCell.parent;
5166
- const tb = currRow.parent;
5167
- this.removeRow(currRow);
5168
- if (tb.length === 0) {
5169
- tb.remove();
5168
+ if (ss.collapsed) {
5169
+ const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5170
+ if (!startCell?.parent) {
5171
+ throw new Error('parent is null');
5172
+ }
5173
+ const currRow = startCell.parent;
5174
+ this.removeRow(currRow);
5175
+ }
5176
+ else {
5177
+ if (!ss.selectedRange || ss.selectedRange.target !== tb) {
5178
+ return;
5179
+ }
5180
+ const selectedRows = [];
5181
+ ss.selectedRange.selectedChildren.forEach(child => {
5182
+ if (child.target instanceof TableRowElement) {
5183
+ selectedRows.push(child.target);
5184
+ }
5185
+ });
5186
+ if (selectedRows.length) {
5187
+ selectedRows.forEach(row => this.removeRow(row));
5188
+ }
5170
5189
  }
5171
5190
  ss.clear();
5172
5191
  }
@@ -5176,32 +5195,46 @@ class TableUtil {
5176
5195
  */
5177
5196
  static removeCurrCol(ss) {
5178
5197
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5179
- if (!startCell?.parent) {
5180
- throw new Error('parent is null');
5198
+ if (!startCell) {
5199
+ return;
5181
5200
  }
5201
+ let startColIndex = 0;
5202
+ let endColIndex = 0;
5182
5203
  if (ss.collapsed) {
5183
5204
  const currRow = startCell.parent;
5184
5205
  const tb = currRow.parent;
5185
- this.removeCol(tb, startCell.getIndex());
5206
+ startColIndex = startCell.getIndex();
5207
+ endColIndex = this.getHMergeEndIndex(tb, currRow.getIndex(), startColIndex);
5208
+ while (startColIndex <= endColIndex) {
5209
+ this.removeCol(tb, endColIndex);
5210
+ endColIndex--;
5211
+ }
5186
5212
  ss.clear();
5187
5213
  return;
5188
5214
  }
5189
- const { ancestorCommonControl, startControl, endControl } = ss;
5190
- if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5191
- const tbElement = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5192
- const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
5193
- const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
5194
- if (startCell?.parent?.parent === tbElement && endCell?.parent?.parent === tbElement) {
5195
- const startColIndex = startCell.getIndex();
5196
- let endColIndex = endCell.getIndex();
5197
- while (startColIndex <= endColIndex) {
5198
- this.removeCol(tbElement, endColIndex);
5199
- endColIndex--;
5215
+ else {
5216
+ const { ancestorCommonControl, startControl, endControl } = ss;
5217
+ if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5218
+ const tb = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5219
+ const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
5220
+ const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
5221
+ if (startCell?.parent?.parent === tb && endCell?.parent?.parent === tb) {
5222
+ const startColIndex = startCell.getIndex();
5223
+ let endColIndex = this.getHMergeEndIndex(tb, endCell.parent.getIndex(), endCell.getIndex());
5224
+ //选中所有的列,直接删除表格
5225
+ if (startColIndex === 0 && endColIndex === tb.props.cols.length - 1) {
5226
+ tb.remove();
5227
+ ss.clear();
5228
+ return;
5229
+ }
5230
+ while (startColIndex <= endColIndex) {
5231
+ this.removeCol(tb, endColIndex);
5232
+ endColIndex--;
5233
+ }
5200
5234
  }
5201
5235
  }
5202
- tbElement.pubOnChange('self');
5236
+ ss.clear();
5203
5237
  }
5204
- ss.clear();
5205
5238
  }
5206
5239
  /**
5207
5240
  * 合并单元格
@@ -5764,7 +5797,7 @@ class TableElement extends BlockContainerElement {
5764
5797
  this.props.cols = cols;
5765
5798
  }
5766
5799
  getColsCount() {
5767
- return this.actualColsProps.length;
5800
+ return this.props.cols.length;
5768
5801
  }
5769
5802
  clone(data) {
5770
5803
  const clone = new TableElement();
@@ -6024,7 +6057,6 @@ class ElementSerialize {
6024
6057
  prevEle = { ele: child, props: serializeChild };
6025
6058
  }
6026
6059
  }
6027
- return result;
6028
6060
  }
6029
6061
  if (element.props && element.props['__attachedProperty'] && !result.props['__attachedProperty']) {
6030
6062
  result.props['__attachedProperty'] = CommonUtil.cloneValue(element.props['__attachedProperty']);