@hailin-zheng/editor-core 1.1.28 → 1.1.30

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
@@ -702,13 +702,18 @@ function appendToOps(doc, ele, ops) {
702
702
  docOpsMap.set(doc, array = []);
703
703
  }
704
704
  const prevEle = ElementUtil.getPrevSiblingElement(ele);
705
- array.push({
705
+ const log = {
706
706
  index: ElementUtil.getControlIndex(ele, true),
707
707
  parentIndex: ElementUtil.getControlIndex(ele.parent, true),
708
708
  prevIndex: prevEle ? ElementUtil.getControlIndex(prevEle, true) : -1,
709
709
  ele,
710
710
  ops
711
- });
711
+ };
712
+ if (log.prevIndex === -1) {
713
+ const nextEle = ElementUtil.getNextSiblingElement(ele);
714
+ log.nextIndex = nextEle ? ElementUtil.getControlIndex(nextEle, true) : -1;
715
+ }
716
+ array.push(log);
712
717
  }
713
718
  function inputText(ele, startIndex, input) {
714
719
  const options = getDocCtx(ele);
@@ -3860,7 +3865,7 @@ class TableCellElement extends BlockContainerElement {
3860
3865
  }
3861
3866
  beginMeasure(data) {
3862
3867
  //不被合并的单元格
3863
- if (!this.length && this.isNotBeMergedCell()) {
3868
+ if (!this.length) {
3864
3869
  this.addChild(data.createParaFn());
3865
3870
  }
3866
3871
  super.beginMeasure(data);
@@ -4979,7 +4984,7 @@ class TableUtil {
4979
4984
  let index = colIndex;
4980
4985
  for (let i = colIndex + 1; i < tb.getColsCount(); i++) {
4981
4986
  const cell = currRow.getChild(i);
4982
- if (cell.props.hMerge === 'continue') {
4987
+ if (cell && cell.props.hMerge === 'continue') {
4983
4988
  index = i;
4984
4989
  }
4985
4990
  else {
@@ -5117,6 +5122,9 @@ class TableUtil {
5117
5122
  }
5118
5123
  }
5119
5124
  tb.removeChild(row);
5125
+ if (tb.length === 0) {
5126
+ tb.remove();
5127
+ }
5120
5128
  }
5121
5129
  /**
5122
5130
  * 移除列
@@ -5131,7 +5139,7 @@ class TableUtil {
5131
5139
  const hMergeEndIndex = this.getHMergeEndIndex(tb, i, colIndex);
5132
5140
  if (hMergeEndIndex > colIndex) {
5133
5141
  const nextCell = row.getChild(colIndex + 1);
5134
- nextCell.props.hMerge = hMergeEndIndex - colIndex > 2 ? 'restart' : null;
5142
+ nextCell.props.hMerge = hMergeEndIndex - colIndex >= 2 ? 'restart' : null;
5135
5143
  }
5136
5144
  }
5137
5145
  else if (cell.props.hMerge === 'continue') {
@@ -5158,15 +5166,31 @@ class TableUtil {
5158
5166
  if (!ss.startControl) {
5159
5167
  return;
5160
5168
  }
5161
- const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5162
- if (!startCell?.parent) {
5163
- throw new Error('parent is null');
5169
+ const tb = ElementUtil.getParentByType(ss.startControl, TableElement);
5170
+ if (!tb) {
5171
+ return;
5164
5172
  }
5165
- const currRow = startCell.parent;
5166
- const tb = currRow.parent;
5167
- this.removeRow(currRow);
5168
- if (tb.length === 0) {
5169
- tb.remove();
5173
+ if (ss.collapsed) {
5174
+ const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5175
+ if (!startCell?.parent) {
5176
+ throw new Error('parent is null');
5177
+ }
5178
+ const currRow = startCell.parent;
5179
+ this.removeRow(currRow);
5180
+ }
5181
+ else {
5182
+ if (!ss.selectedRange || ss.selectedRange.target !== tb) {
5183
+ return;
5184
+ }
5185
+ const selectedRows = [];
5186
+ ss.selectedRange.selectedChildren.forEach(child => {
5187
+ if (child.target instanceof TableRowElement) {
5188
+ selectedRows.push(child.target);
5189
+ }
5190
+ });
5191
+ if (selectedRows.length) {
5192
+ selectedRows.forEach(row => this.removeRow(row));
5193
+ }
5170
5194
  }
5171
5195
  ss.clear();
5172
5196
  }
@@ -5176,32 +5200,46 @@ class TableUtil {
5176
5200
  */
5177
5201
  static removeCurrCol(ss) {
5178
5202
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
5179
- if (!startCell?.parent) {
5180
- throw new Error('parent is null');
5203
+ if (!startCell) {
5204
+ return;
5181
5205
  }
5206
+ let startColIndex = 0;
5207
+ let endColIndex = 0;
5182
5208
  if (ss.collapsed) {
5183
5209
  const currRow = startCell.parent;
5184
5210
  const tb = currRow.parent;
5185
- this.removeCol(tb, startCell.getIndex());
5211
+ startColIndex = startCell.getIndex();
5212
+ endColIndex = this.getHMergeEndIndex(tb, currRow.getIndex(), startColIndex);
5213
+ while (startColIndex <= endColIndex) {
5214
+ this.removeCol(tb, endColIndex);
5215
+ endColIndex--;
5216
+ }
5186
5217
  ss.clear();
5187
5218
  return;
5188
5219
  }
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--;
5220
+ else {
5221
+ const { ancestorCommonControl, startControl, endControl } = ss;
5222
+ if (ancestorCommonControl instanceof TableElement || ancestorCommonControl instanceof TableRowElement) {
5223
+ const tb = ancestorCommonControl instanceof TableElement ? ancestorCommonControl : ancestorCommonControl.parent;
5224
+ const startCell = ElementUtil.getParentByType(startControl, TableCellElement);
5225
+ const endCell = ElementUtil.getParentByType(endControl, TableCellElement);
5226
+ if (startCell?.parent?.parent === tb && endCell?.parent?.parent === tb) {
5227
+ const startColIndex = startCell.getIndex();
5228
+ let endColIndex = this.getHMergeEndIndex(tb, endCell.parent.getIndex(), endCell.getIndex());
5229
+ //选中所有的列,直接删除表格
5230
+ if (startColIndex === 0 && endColIndex === tb.props.cols.length - 1) {
5231
+ tb.remove();
5232
+ ss.clear();
5233
+ return;
5234
+ }
5235
+ while (startColIndex <= endColIndex) {
5236
+ this.removeCol(tb, endColIndex);
5237
+ endColIndex--;
5238
+ }
5200
5239
  }
5201
5240
  }
5202
- tbElement.pubOnChange('self');
5241
+ ss.clear();
5203
5242
  }
5204
- ss.clear();
5205
5243
  }
5206
5244
  /**
5207
5245
  * 合并单元格
@@ -5764,7 +5802,7 @@ class TableElement extends BlockContainerElement {
5764
5802
  this.props.cols = cols;
5765
5803
  }
5766
5804
  getColsCount() {
5767
- return this.actualColsProps.length;
5805
+ return this.props.cols.length;
5768
5806
  }
5769
5807
  clone(data) {
5770
5808
  const clone = new TableElement();
@@ -6024,7 +6062,6 @@ class ElementSerialize {
6024
6062
  prevEle = { ele: child, props: serializeChild };
6025
6063
  }
6026
6064
  }
6027
- return result;
6028
6065
  }
6029
6066
  if (element.props && element.props['__attachedProperty'] && !result.props['__attachedProperty']) {
6030
6067
  result.props['__attachedProperty'] = CommonUtil.cloneValue(element.props['__attachedProperty']);
@@ -14917,7 +14954,8 @@ class DocumentEvent {
14917
14954
  if (!this.selectionState.cursorPos) {
14918
14955
  return;
14919
14956
  }
14920
- let { x, y } = this.selectionState.cursorPos;
14957
+ let { x, y, height } = this.selectionState.cursorPos;
14958
+ y = y + (height / 2 * (up ? -1 : 1));
14921
14959
  //y -= this.viewOptions.pageOffset.y;
14922
14960
  for (let i = 0; i < 50; i++) {
14923
14961
  const docEvent = new MouseElementEvent(this.docCtx);
@@ -15069,7 +15107,7 @@ class DocumentInput {
15069
15107
  const evt = nodeEvt.sourceEvt;
15070
15108
  const keyEvent = new KeyboradElementEvent(this.docCtx);
15071
15109
  keyEvent.sourceEvent = evt;
15072
- if (DocumentEvent.invokeEvent('ElementKeyDown', this.docCtx.selectionState.startControl, keyEvent, 'Capture')) {
15110
+ if (DocumentEvent.invokeEvent('ElementKeyDown', this.docCtx.selectionState.startControl, keyEvent, 'All')) {
15073
15111
  return;
15074
15112
  }
15075
15113
  if (evt.keyCode === 8) {
@@ -17304,28 +17342,25 @@ class ElementTrackManage {
17304
17342
  }
17305
17343
  }
17306
17344
  restoreToInsert(index, parentIndex, prevIndex, data) {
17307
- const prevSiblingEle = prevIndex !== -1 ? this.getControl(prevIndex) : null;
17345
+ const prevSiblingEle = prevIndex !== -1 ? this.getControl(prevIndex, true) : null;
17346
+ //const nextSiblingEle = prevSiblingEle ? prevSiblingEle.nextSibling : null;
17308
17347
  //获取插入位置之前的元素,然后向后插入目标元素
17309
- const ele = this.getControl(index - 1);
17348
+ //const ele = this.getControl(index - 1,true);
17349
+ const parent = this.getControl(parentIndex, true);
17310
17350
  const target = data.clone(true);
17311
17351
  if (prevSiblingEle) {
17312
17352
  prevSiblingEle.parent.addChild(target, prevSiblingEle.getIndex() + 1);
17313
17353
  }
17314
17354
  else {
17315
- //ele获取的为父容器
17316
- if (index === parentIndex + 1) {
17317
- if (ele instanceof BranchElement) {
17318
- if (ele.type === 'tbc' && ele.getChildLength() === 2) {
17319
- ele.clearItems();
17320
- }
17321
- ele.addChild(target, 0);
17322
- return;
17323
- }
17324
- else {
17325
- throw new Error('父级类型不正确');
17355
+ if (parent instanceof BranchElement) {
17356
+ if (parent.type === 'tbc' && parent.getChildLength() === 2) {
17357
+ parent.clearItems();
17326
17358
  }
17359
+ parent.addChild(target, 0);
17360
+ }
17361
+ else {
17362
+ throw new Error('父级类型不正确');
17327
17363
  }
17328
- ele.parent.addChild(target, ele.getIndex() + 1);
17329
17364
  }
17330
17365
  }
17331
17366
  /**