@worktile/theia 1.2.15 → 1.2.16

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.
@@ -828,7 +828,11 @@
828
828
  };
829
829
 
830
830
  var isEmptyParagraph = function (editor, at) {
831
- var _a = __read(getAnchorBlockEntry(editor, at), 1), block = _a[0];
831
+ var entry = getAnchorBlockEntry(editor, at);
832
+ if (!entry) {
833
+ return false;
834
+ }
835
+ var _a = __read(entry, 1), block = _a[0];
832
836
  return slate.Editor.isEmpty(editor, block) && block.type === exports.ElementKinds.paragraph;
833
837
  };
834
838
 
@@ -4727,20 +4731,66 @@
4727
4731
  // block card cursor
4728
4732
  if (anchorNode && i1.hasBlockCard(domSelection)) {
4729
4733
  var isCardLeftCursor = i1.isCardLeft(anchorNode);
4730
- // + left-block-card 或者 → + right-block-card
4731
- if ((isMoveDown && isCardLeftCursor) || (isMoveForward && !isCardLeftCursor)) {
4732
- nativeEvent.preventDefault();
4734
+ if (isMoveUp) {
4733
4735
  var _a = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _a[1];
4736
+ var previousPath = slate.Path.hasPrevious(path) && slate.Path.previous(path);
4737
+ var previousNode = previousPath && getNode(editor, previousPath);
4738
+ if (previousNode && editor.isBlockCard(previousNode)) {
4739
+ i1.AngularEditor.moveBlockCard(editor, previousNode, { direction: isCardLeftCursor ? 'left' : 'right' });
4740
+ }
4741
+ else {
4742
+ var before = slate.Editor.before(editor, path);
4743
+ if (before) {
4744
+ slate.Transforms.select(editor, before);
4745
+ }
4746
+ }
4747
+ nativeEvent.preventDefault();
4748
+ return;
4749
+ }
4750
+ if (isMoveDown) {
4751
+ var _b = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _b[1];
4752
+ var nextPath = slate.Path.next(path);
4753
+ var nextNode = getNode(editor, nextPath);
4754
+ if (nextNode && editor.isBlockCard(nextNode)) {
4755
+ i1.AngularEditor.moveBlockCard(editor, nextNode, { direction: isCardLeftCursor ? 'left' : 'right' });
4756
+ }
4757
+ else {
4758
+ var after = slate.Editor.after(editor, path);
4759
+ if (after) {
4760
+ slate.Transforms.select(editor, slate.Editor.after(editor, path));
4761
+ }
4762
+ }
4763
+ nativeEvent.preventDefault();
4764
+ return;
4765
+ }
4766
+ // → + right-block-card
4767
+ if ((isMoveForward && !isCardLeftCursor)) {
4768
+ nativeEvent.preventDefault();
4769
+ var _c = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _c[1];
4770
+ var nextPath = slate.Path.next(path);
4771
+ var nextNode = getNode(editor, nextPath);
4772
+ if (nextNode && editor.isBlockCard(nextNode)) {
4773
+ event.preventDefault();
4774
+ i1.AngularEditor.moveBlockCard(editor, nextNode, { direction: 'left' });
4775
+ return;
4776
+ }
4734
4777
  var after = slate.Editor.after(editor, path);
4735
4778
  if (after) {
4736
4779
  slate.Transforms.select(editor, slate.Editor.after(editor, path));
4737
4780
  }
4738
4781
  return;
4739
4782
  }
4740
- // ↑ + right-block-card 或者 ← + left-block-card
4741
- if ((isMoveUp && !isCardLeftCursor) || (isMoveBackward && isCardLeftCursor)) {
4783
+ // ← + left-block-card
4784
+ if (isMoveBackward && isCardLeftCursor) {
4742
4785
  nativeEvent.preventDefault();
4743
- var _b = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _b[1];
4786
+ var _d = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _d[1];
4787
+ var previousPath = slate.Path.hasPrevious(path) && slate.Path.previous(path);
4788
+ var previousNode = previousPath && getNode(editor, previousPath);
4789
+ if (previousNode && editor.isBlockCard(previousNode)) {
4790
+ event.preventDefault();
4791
+ i1.AngularEditor.moveBlockCard(editor, previousNode, { direction: 'right' });
4792
+ return;
4793
+ }
4744
4794
  var before = slate.Editor.before(editor, path);
4745
4795
  if (before) {
4746
4796
  slate.Transforms.select(editor, before);
@@ -4750,14 +4800,14 @@
4750
4800
  // move to card center
4751
4801
  if ((isCardLeftCursor && isMoveForward) || (!isCardLeftCursor && isMoveBackward)) {
4752
4802
  nativeEvent.preventDefault();
4753
- var _c = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _c[1];
4803
+ var _e = __read(i1.AngularEditor.toSlateCardEntry(editor, anchorNode), 2), path = _e[1];
4754
4804
  slate.Transforms.select(editor, isCardLeftCursor ? slate.Editor.start(editor, path) : slate.Editor.end(editor, path));
4755
4805
  return;
4756
4806
  }
4757
4807
  }
4758
4808
  // block card center
4759
4809
  if (isCollapsed && (isMoveUp || isMoveDown) && anchorEntry) {
4760
- var _d = __read(anchorEntry, 2), block = _d[0], path = _d[1];
4810
+ var _f = __read(anchorEntry, 2), block = _f[0], path = _f[1];
4761
4811
  if (editor.isBlockCard(block)) {
4762
4812
  event.preventDefault();
4763
4813
  slate.Transforms.select(editor, isMoveUp ? slate.Editor.before(editor, path) : slate.Editor.after(editor, path));
@@ -4765,7 +4815,7 @@
4765
4815
  }
4766
4816
  }
4767
4817
  if (isCollapsed && (isMoveBackward || isMoveForward) && anchorEntry) {
4768
- var _e = __read(anchorEntry, 1), block = _e[0];
4818
+ var _g = __read(anchorEntry, 1), block = _g[0];
4769
4819
  if (editor.isBlockCard(block)) {
4770
4820
  event.preventDefault();
4771
4821
  i1.AngularEditor.moveBlockCard(editor, block, { direction: isMoveBackward ? 'left' : 'right' });
@@ -5151,11 +5201,14 @@
5151
5201
  columnIndex++;
5152
5202
  nextCell = this.table.children[rowIndex].children[columnIndex];
5153
5203
  }
5154
- else {
5204
+ else if (rowIndex + 1 < this.getHeight()) {
5155
5205
  columnIndex = 0;
5156
5206
  rowIndex++;
5157
5207
  nextCell = this.table.children[rowIndex].children[columnIndex];
5158
5208
  }
5209
+ else {
5210
+ nextCell = null;
5211
+ }
5159
5212
  }
5160
5213
  return nextCell;
5161
5214
  };
@@ -5307,7 +5360,7 @@
5307
5360
  return rowspans.some(function (rowspan) { return isInside(rowspan, rowIndx, targetIndex); });
5308
5361
  });
5309
5362
  }
5310
- function calcOriginSpan(table, targetRowIndex, targetColumnIndex) {
5363
+ function getOriginCell(table, targetRowIndex, targetColumnIndex) {
5311
5364
  var _loop_1 = function (rowIndex) {
5312
5365
  var row = table.children[rowIndex];
5313
5366
  var originCell = row.children
@@ -5830,6 +5883,13 @@
5830
5883
  isActiveHeader: function (editor) {
5831
5884
  var _a = __read(slate.Editor.nodes(editor, { match: function (n) { return n.type === exports.ElementKinds.tableRow; } }), 1), tableRowEntry = _a[0];
5832
5885
  return tableRowEntry && tableRowEntry[0] && tableRowEntry[0].header;
5886
+ },
5887
+ selectOriginCell: function (editor, table, rowIndex, columnIndex, isStart) {
5888
+ var origin = getOriginCell(table, rowIndex, columnIndex);
5889
+ if (origin) {
5890
+ var path = i1.AngularEditor.findPath(editor, origin);
5891
+ slate.Transforms.select(editor, isStart ? slate.Editor.start(editor, path) : slate.Editor.end(editor, path));
5892
+ }
5833
5893
  }
5834
5894
  };
5835
5895
 
@@ -6862,6 +6922,9 @@
6862
6922
  if (this.options.mode !== this.element.language) {
6863
6923
  this.useMode();
6864
6924
  }
6925
+ if (!this.readonly && this.isCollapsed) {
6926
+ this.initializeCodemirrorFocus();
6927
+ }
6865
6928
  }
6866
6929
  };
6867
6930
  TheCodeComponent.prototype.ngOnInit = function () {
@@ -10641,7 +10704,7 @@
10641
10704
  }
10642
10705
  // case 2
10643
10706
  if (cell.hidden && !normalizedNodes.includes(cell)) {
10644
- var origin = calcOriginSpan(table, rowIndex, columnIndex);
10707
+ var origin = getOriginCell(table, rowIndex, columnIndex);
10645
10708
  if (!origin) {
10646
10709
  delete table.children[rowIndex].children[columnIndex].hidden;
10647
10710
  }
@@ -10652,7 +10715,7 @@
10652
10715
  };
10653
10716
 
10654
10717
  var withTable = function (editor) {
10655
- var deleteBackward = editor.deleteBackward, deleteForward = editor.deleteForward, onKeydown = editor.onKeydown, setFragmentData = editor.setFragmentData, insertData = editor.insertData, normalizeNode = editor.normalizeNode, isBlockCard = editor.isBlockCard, renderElement = editor.renderElement, deleteCutData = editor.deleteCutData, isContainer = editor.isContainer;
10718
+ var deleteBackward = editor.deleteBackward, deleteForward = editor.deleteForward, onKeydown = editor.onKeydown, setFragmentData = editor.setFragmentData, insertData = editor.insertData, normalizeNode = editor.normalizeNode, isBlockCard = editor.isBlockCard, renderElement = editor.renderElement, deleteCutData = editor.deleteCutData, isContainer = editor.isContainer, onChange = editor.onChange;
10656
10719
  editor.deleteBackward = function (unit) {
10657
10720
  var opts = new TableOptions$1();
10658
10721
  if (!isSelectionInTable(opts, editor)) {
@@ -10723,13 +10786,11 @@
10723
10786
  var aboveCell = aboveRow && aboveRow.children[startPosition.getColumnIndex()];
10724
10787
  if (aboveCell) {
10725
10788
  if (aboveCell.hidden) {
10726
- var originSpan = calcOriginSpan(endPosition.table, startPosition.getRowIndex() - 1, startPosition.getColumnIndex());
10727
- if (originSpan) {
10728
- at = slate.Editor.start(editor, TheEditor.findPath(editor, originSpan));
10729
- }
10789
+ TableEditor.selectOriginCell(editor, startPosition.table, startPosition.getRowIndex() - 1, startPosition.getColumnIndex(), false);
10790
+ return;
10730
10791
  }
10731
10792
  else {
10732
- at = slate.Editor.start(editor, TheEditor.findPath(editor, aboveCell));
10793
+ at = slate.Editor.end(editor, TheEditor.findPath(editor, aboveCell));
10733
10794
  }
10734
10795
  }
10735
10796
  else {
@@ -10758,10 +10819,8 @@
10758
10819
  var belowCell = belowRow && belowRow.children[startPosition.getColumnIndex()];
10759
10820
  if (belowCell) {
10760
10821
  if (belowCell.hidden) {
10761
- var originSpan = calcOriginSpan(endPosition.table, belowRowIndex, startPosition.getColumnIndex());
10762
- if (originSpan) {
10763
- at = slate.Editor.start(editor, TheEditor.findPath(editor, originSpan));
10764
- }
10822
+ TableEditor.selectOriginCell(editor, startPosition.table, startPosition.getRowIndex() + 1, startPosition.getColumnIndex(), true);
10823
+ return;
10765
10824
  }
10766
10825
  else {
10767
10826
  at = slate.Editor.start(editor, TheEditor.findPath(editor, belowCell));
@@ -10780,18 +10839,27 @@
10780
10839
  var beforePoint = slate.Editor.before(editor, editor.selection);
10781
10840
  var beforePosition = beforePoint && TablePosition.create(opts, editor, beforePoint.path);
10782
10841
  if (beforePosition && beforePosition.cell && beforePosition.cell.hidden) {
10842
+ event.preventDefault();
10783
10843
  var at = slate.Editor.end(editor, TheEditor.findPath(editor, beforePosition.findPrevious()));
10784
10844
  slate.Transforms.select(editor, at);
10785
- event.preventDefault();
10786
10845
  }
10787
10846
  }
10788
10847
  if (isMoveForward) {
10789
10848
  var afterPoint = slate.Editor.after(editor, editor.selection);
10790
10849
  var afterPosition = afterPoint && TablePosition.create(opts, editor, afterPoint.path);
10791
10850
  if (afterPosition.cell && afterPosition.cell.hidden) {
10792
- var at = slate.Editor.start(editor, TheEditor.findPath(editor, afterPosition.findNext()));
10793
- slate.Transforms.select(editor, at);
10794
10851
  event.preventDefault();
10852
+ var nextCell = afterPosition.findNext();
10853
+ if (nextCell) {
10854
+ var at = slate.Editor.start(editor, TheEditor.findPath(editor, afterPosition.findNext()));
10855
+ slate.Transforms.select(editor, at);
10856
+ event.preventDefault();
10857
+ }
10858
+ else {
10859
+ i1.AngularEditor.moveBlockCard(editor, startPosition.tableEntry[0], { direction: 'right' });
10860
+ event.preventDefault();
10861
+ }
10862
+ return;
10795
10863
  }
10796
10864
  }
10797
10865
  // Prevent deleting cells in the table
@@ -10872,12 +10940,12 @@
10872
10940
  }
10873
10941
  if (tableFragment) {
10874
10942
  tableFragment = normalizeTable(_.cloneDeep(tableFragment));
10943
+ var plainText = slate.Node.string(tableFragment);
10875
10944
  tableFragment = [tableFragment];
10876
10945
  var stringObj = JSON.stringify(tableFragment);
10877
10946
  var encoded = window.btoa(encodeURIComponent(stringObj));
10878
10947
  unit.setData("application/" + CLIPBOARD_FORMAT_KEY, encoded);
10879
- // unit.setData('text/html', div.innerHTML);
10880
- unit.setData('text/plain', slate.Node.string(tableFragment));
10948
+ unit.setData('text/plain', plainText);
10881
10949
  return;
10882
10950
  }
10883
10951
  setFragmentData(unit);
@@ -10902,7 +10970,7 @@
10902
10970
  for (var j = selectColIndex_1; j <= lastColIndex_1; j++) {
10903
10971
  var row = tablePosition_1.table.children[i];
10904
10972
  if (row && row.children[j]) {
10905
- var originCell = calcOriginSpan(tablePosition_1.table, i, j);
10973
+ var originCell = getOriginCell(tablePosition_1.table, i, j);
10906
10974
  if (originCell && (originCell.colspan || originCell.rowspan)) {
10907
10975
  var path = TheEditor.findPath(editor, originCell).slice(-2);
10908
10976
  resetTableCell(editor, tablePosition_1.table, originCell, path[0], path[1]);
@@ -10960,6 +11028,21 @@
10960
11028
  slate.Transforms.setNodes(editor, { columns: columns }, { at: entry[1] });
10961
11029
  }
10962
11030
  }
11031
+ // adjust selection when selection is in hidden cell
11032
+ if (slate.Element.isElement(entry[0]) && entry[0].type === exports.ElementKinds.tableCell && entry[0].hidden) {
11033
+ if (editor.selection && slate.Range.isCollapsed(editor.selection) && slate.Path.isAncestor(entry[1], editor.selection.anchor.path)) {
11034
+ setTimeout(function () {
11035
+ var opts = new TableOptions$1();
11036
+ var tablePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
11037
+ var origin = getOriginCell(tablePosition.table, tablePosition.getRowIndex(), tablePosition.getColumnIndex());
11038
+ if (origin) {
11039
+ var path = i1.AngularEditor.findPath(editor, origin);
11040
+ slate.Transforms.select(editor, slate.Editor.end(editor, path));
11041
+ }
11042
+ }, 0);
11043
+ return;
11044
+ }
11045
+ }
10963
11046
  normalizeNode(entry);
10964
11047
  };
10965
11048
  editor.isBlockCard = function (element) {
@@ -11007,6 +11090,20 @@
11007
11090
  editor.isContainer = function (element) {
11008
11091
  return element.type === exports.ElementKinds.tableCell ? true : isContainer(element);
11009
11092
  };
11093
+ editor.onChange = function () {
11094
+ onChange();
11095
+ // adujst selection when selection is in hidden cell
11096
+ // just hook set_selection
11097
+ var isCollapsed = editor.selection && slate.Range.isCollapsed(editor.selection);
11098
+ var isSelectionOperation = editor.operations.every(function (op) { return slate.Operation.isSelectionOperation(op); });
11099
+ if (isCollapsed && isSelectionOperation) {
11100
+ var opts = new TableOptions$1();
11101
+ var tablePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
11102
+ if (tablePosition.isInTable() && tablePosition.cell.hidden) {
11103
+ TableEditor.selectOriginCell(editor, tablePosition.table, tablePosition.getRowIndex(), tablePosition.getColumnIndex(), false);
11104
+ }
11105
+ }
11106
+ };
11010
11107
  return editor;
11011
11108
  };
11012
11109
 
@@ -12290,12 +12387,13 @@
12290
12387
  };
12291
12388
  ThePlaceholderComponent.prototype.checkStatus = function () {
12292
12389
  var _this = this;
12293
- var _a, _b;
12390
+ var _a, _b, _c;
12294
12391
  var editor = this.editor;
12295
12392
  var isEmptyShow = typeof ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isEmptyShowPlaceholder) === 'undefined' ? true : this.options.isEmptyShowPlaceholder;
12296
12393
  var isMustShow = (_b = this.options) === null || _b === void 0 ? void 0 : _b.isMustShowPlaceholder;
12394
+ var isReadonly = (_c = this.options) === null || _c === void 0 ? void 0 : _c.readonly;
12297
12395
  // empty content and no selection processing
12298
- if (isEmptyShow && isEmptyContent(editor.children)) {
12396
+ if (!isReadonly && isEmptyShow && isEmptyContent(editor.children)) {
12299
12397
  var firstElementChild = this.contextService.getFirstElementChild();
12300
12398
  var offsetTop = firstElementChild.offsetTop;
12301
12399
  var offsetLeft = firstElementChild.offsetLeft;