@atlaskit/editor-tables 2.2.4 → 2.2.6

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/cell-bookmark.js +0 -10
  3. package/dist/cjs/cell-selection.js +37 -102
  4. package/dist/cjs/index.js +0 -4
  5. package/dist/cjs/pm-plugins/input.js +17 -83
  6. package/dist/cjs/pm-plugins/plugin-key.js +0 -2
  7. package/dist/cjs/pm-plugins/table-editing.js +17 -18
  8. package/dist/cjs/pm-plugins.js +0 -2
  9. package/dist/cjs/table-map.js +67 -138
  10. package/dist/cjs/utils/add-column-at.js +0 -9
  11. package/dist/cjs/utils/add-column.js +8 -24
  12. package/dist/cjs/utils/add-row-at.js +8 -37
  13. package/dist/cjs/utils/add-row.js +2 -23
  14. package/dist/cjs/utils/analytics-helpers.js +4 -15
  15. package/dist/cjs/utils/cells.js +0 -12
  16. package/dist/cjs/utils/clone-tr.js +0 -2
  17. package/dist/cjs/utils/colspan.js +2 -18
  18. package/dist/cjs/utils/copy-paste.js +51 -139
  19. package/dist/cjs/utils/create-table.js +14 -28
  20. package/dist/cjs/utils/draw-cell-selection.js +0 -4
  21. package/dist/cjs/utils/empty-cells.js +0 -6
  22. package/dist/cjs/utils/find.js +6 -18
  23. package/dist/cjs/utils/fix-tables.js +13 -56
  24. package/dist/cjs/utils/for-each-cell.js +3 -17
  25. package/dist/cjs/utils/get-cell-selection-ranges.js +2 -9
  26. package/dist/cjs/utils/get-cells-in-column.js +0 -7
  27. package/dist/cjs/utils/get-cells-in-row.js +0 -7
  28. package/dist/cjs/utils/get-cells-in-table.js +0 -8
  29. package/dist/cjs/utils/get-selection-range-in-column.js +6 -27
  30. package/dist/cjs/utils/get-selection-range-in-row.js +6 -27
  31. package/dist/cjs/utils/get-selection-rect.js +0 -7
  32. package/dist/cjs/utils/go-to-next-cell.js +3 -22
  33. package/dist/cjs/utils/handle-paste.js +5 -34
  34. package/dist/cjs/utils/is-selected.js +6 -23
  35. package/dist/cjs/utils/is-selection-type.js +0 -2
  36. package/dist/cjs/utils/move-column.js +0 -12
  37. package/dist/cjs/utils/move-row.js +0 -11
  38. package/dist/cjs/utils/normalize-selection.js +3 -27
  39. package/dist/cjs/utils/remove-column.js +10 -46
  40. package/dist/cjs/utils/remove-row.js +8 -49
  41. package/dist/cjs/utils/remove-table.js +0 -6
  42. package/dist/cjs/utils/reorder-utils.js +13 -37
  43. package/dist/cjs/utils/replace-table.js +0 -8
  44. package/dist/cjs/utils/select-nodes.js +11 -31
  45. package/dist/cjs/utils/selection-cell.js +0 -5
  46. package/dist/cjs/utils/selection-rect.js +0 -10
  47. package/dist/cjs/utils/set-cell-attrs.js +0 -4
  48. package/dist/cjs/utils/split-cell-with-type.js +2 -35
  49. package/dist/cjs/utils/split-cell.js +0 -4
  50. package/dist/cjs/utils/table-node-types.js +4 -8
  51. package/dist/cjs/utils/tables.js +0 -4
  52. package/dist/cjs/utils/test-utils.js +9 -26
  53. package/dist/cjs/utils/toggle-header.js +3 -16
  54. package/dist/cjs/utils/uuid.js +0 -3
  55. package/dist/cjs/utils.js +0 -42
  56. package/dist/cjs/version.json +1 -1
  57. package/dist/es2019/cell-bookmark.js +0 -5
  58. package/dist/es2019/cell-selection.js +37 -81
  59. package/dist/es2019/index.js +1 -0
  60. package/dist/es2019/pm-plugins/input.js +15 -67
  61. package/dist/es2019/pm-plugins/table-editing.js +3 -12
  62. package/dist/es2019/table-map.js +57 -127
  63. package/dist/es2019/utils/add-column-at.js +2 -4
  64. package/dist/es2019/utils/add-column.js +6 -16
  65. package/dist/es2019/utils/add-row-at.js +8 -22
  66. package/dist/es2019/utils/add-row.js +2 -17
  67. package/dist/es2019/utils/analytics-helpers.js +0 -5
  68. package/dist/es2019/utils/cells.js +4 -9
  69. package/dist/es2019/utils/colspan.js +6 -11
  70. package/dist/es2019/utils/copy-paste.js +41 -115
  71. package/dist/es2019/utils/create-table.js +3 -12
  72. package/dist/es2019/utils/draw-cell-selection.js +0 -1
  73. package/dist/es2019/utils/empty-cells.js +2 -3
  74. package/dist/es2019/utils/find.js +8 -8
  75. package/dist/es2019/utils/fix-tables.js +17 -47
  76. package/dist/es2019/utils/for-each-cell.js +6 -11
  77. package/dist/es2019/utils/get-cell-selection-ranges.js +2 -4
  78. package/dist/es2019/utils/get-cells-in-column.js +2 -3
  79. package/dist/es2019/utils/get-cells-in-row.js +2 -3
  80. package/dist/es2019/utils/get-cells-in-table.js +2 -4
  81. package/dist/es2019/utils/get-selection-range-in-column.js +8 -22
  82. package/dist/es2019/utils/get-selection-range-in-row.js +8 -22
  83. package/dist/es2019/utils/get-selection-rect.js +2 -2
  84. package/dist/es2019/utils/go-to-next-cell.js +3 -19
  85. package/dist/es2019/utils/handle-paste.js +3 -14
  86. package/dist/es2019/utils/is-selected.js +8 -10
  87. package/dist/es2019/utils/is-selection-type.js +0 -1
  88. package/dist/es2019/utils/move-column.js +3 -8
  89. package/dist/es2019/utils/move-row.js +3 -7
  90. package/dist/es2019/utils/normalize-selection.js +0 -16
  91. package/dist/es2019/utils/remove-column.js +10 -27
  92. package/dist/es2019/utils/remove-row.js +12 -32
  93. package/dist/es2019/utils/remove-table.js +2 -4
  94. package/dist/es2019/utils/reorder-utils.js +11 -26
  95. package/dist/es2019/utils/replace-table.js +0 -2
  96. package/dist/es2019/utils/select-nodes.js +9 -20
  97. package/dist/es2019/utils/selection-cell.js +0 -2
  98. package/dist/es2019/utils/selection-rect.js +0 -4
  99. package/dist/es2019/utils/set-cell-attrs.js +2 -2
  100. package/dist/es2019/utils/split-cell-with-type.js +8 -28
  101. package/dist/es2019/utils/split-cell.js +3 -2
  102. package/dist/es2019/utils/table-node-types.js +4 -7
  103. package/dist/es2019/utils/tables.js +0 -2
  104. package/dist/es2019/utils/test-utils.js +12 -16
  105. package/dist/es2019/utils/toggle-header.js +3 -10
  106. package/dist/es2019/utils/uuid.js +0 -2
  107. package/dist/es2019/version.json +1 -1
  108. package/dist/esm/cell-bookmark.js +0 -5
  109. package/dist/esm/cell-selection.js +37 -79
  110. package/dist/esm/index.js +1 -0
  111. package/dist/esm/pm-plugins/input.js +17 -71
  112. package/dist/esm/pm-plugins/table-editing.js +8 -13
  113. package/dist/esm/table-map.js +68 -133
  114. package/dist/esm/utils/add-column-at.js +2 -4
  115. package/dist/esm/utils/add-column.js +8 -20
  116. package/dist/esm/utils/add-row-at.js +8 -23
  117. package/dist/esm/utils/add-row.js +2 -21
  118. package/dist/esm/utils/analytics-helpers.js +4 -10
  119. package/dist/esm/utils/cells.js +0 -5
  120. package/dist/esm/utils/colspan.js +2 -14
  121. package/dist/esm/utils/copy-paste.js +44 -125
  122. package/dist/esm/utils/create-table.js +14 -25
  123. package/dist/esm/utils/draw-cell-selection.js +0 -1
  124. package/dist/esm/utils/empty-cells.js +2 -3
  125. package/dist/esm/utils/find.js +8 -8
  126. package/dist/esm/utils/fix-tables.js +13 -49
  127. package/dist/esm/utils/for-each-cell.js +6 -11
  128. package/dist/esm/utils/get-cell-selection-ranges.js +2 -4
  129. package/dist/esm/utils/get-cells-in-column.js +2 -3
  130. package/dist/esm/utils/get-cells-in-row.js +2 -3
  131. package/dist/esm/utils/get-cells-in-table.js +2 -4
  132. package/dist/esm/utils/get-selection-range-in-column.js +8 -24
  133. package/dist/esm/utils/get-selection-range-in-row.js +8 -24
  134. package/dist/esm/utils/get-selection-rect.js +2 -2
  135. package/dist/esm/utils/go-to-next-cell.js +3 -19
  136. package/dist/esm/utils/handle-paste.js +5 -23
  137. package/dist/esm/utils/is-selected.js +8 -10
  138. package/dist/esm/utils/is-selection-type.js +0 -1
  139. package/dist/esm/utils/move-column.js +3 -8
  140. package/dist/esm/utils/move-row.js +3 -7
  141. package/dist/esm/utils/normalize-selection.js +3 -22
  142. package/dist/esm/utils/remove-column.js +10 -31
  143. package/dist/esm/utils/remove-row.js +8 -35
  144. package/dist/esm/utils/remove-table.js +2 -4
  145. package/dist/esm/utils/reorder-utils.js +11 -26
  146. package/dist/esm/utils/replace-table.js +0 -2
  147. package/dist/esm/utils/select-nodes.js +11 -22
  148. package/dist/esm/utils/selection-cell.js +0 -2
  149. package/dist/esm/utils/selection-rect.js +0 -4
  150. package/dist/esm/utils/set-cell-attrs.js +2 -2
  151. package/dist/esm/utils/split-cell-with-type.js +2 -28
  152. package/dist/esm/utils/split-cell.js +3 -2
  153. package/dist/esm/utils/table-node-types.js +4 -7
  154. package/dist/esm/utils/tables.js +0 -2
  155. package/dist/esm/utils/test-utils.js +12 -16
  156. package/dist/esm/utils/toggle-header.js +3 -10
  157. package/dist/esm/version.json +1 -1
  158. package/package.json +6 -4
@@ -4,84 +4,67 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSelectionRangeInRow = void 0;
7
-
8
7
  var _getCellsInColumn = require("./get-cells-in-column");
9
-
10
8
  var _getCellsInRow = require("./get-cells-in-row");
11
-
12
9
  // Returns a range of rectangular selection spanning all merged cells around a row at index `rowIndex`.
13
10
  var getSelectionRangeInRow = function getSelectionRangeInRow(rowIndex) {
14
11
  return function (tr) {
15
12
  var startIndex = rowIndex;
16
- var endIndex = rowIndex; // looking for selection start row (startIndex)
13
+ var endIndex = rowIndex;
17
14
 
15
+ // looking for selection start row (startIndex)
18
16
  var _loop = function _loop(i) {
19
17
  var cells = (0, _getCellsInRow.getCellsInRow)(i)(tr.selection);
20
-
21
18
  if (cells) {
22
19
  cells.forEach(function (cell) {
23
20
  var maybeEndIndex = cell.node.attrs.rowspan + i - 1;
24
-
25
21
  if (maybeEndIndex >= startIndex) {
26
22
  startIndex = i;
27
23
  }
28
-
29
24
  if (maybeEndIndex > endIndex) {
30
25
  endIndex = maybeEndIndex;
31
26
  }
32
27
  });
33
28
  }
34
29
  };
35
-
36
30
  for (var i = rowIndex; i >= 0; i--) {
37
31
  _loop(i);
38
- } // looking for selection end row (endIndex)
39
-
40
-
32
+ }
33
+ // looking for selection end row (endIndex)
41
34
  var _loop2 = function _loop2(_i) {
42
35
  var cells = (0, _getCellsInRow.getCellsInRow)(_i)(tr.selection);
43
-
44
36
  if (cells) {
45
37
  cells.forEach(function (cell) {
46
38
  var maybeEndIndex = cell.node.attrs.rowspan + _i - 1;
47
-
48
39
  if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) {
49
40
  endIndex = maybeEndIndex;
50
41
  }
51
42
  });
52
43
  }
53
44
  };
54
-
55
45
  for (var _i = rowIndex; _i <= endIndex; _i++) {
56
46
  _loop2(_i);
57
- } // filter out rows without cells (where all columns have rowspan > 1 in the same row)
58
-
47
+ }
59
48
 
49
+ // filter out rows without cells (where all columns have rowspan > 1 in the same row)
60
50
  var indexes = [];
61
-
62
51
  for (var _i2 = startIndex; _i2 <= endIndex; _i2++) {
63
52
  var maybeCells = (0, _getCellsInRow.getCellsInRow)(_i2)(tr.selection);
64
-
65
53
  if (maybeCells && maybeCells.length) {
66
54
  indexes.push(_i2);
67
55
  }
68
56
  }
69
-
70
57
  startIndex = indexes[0];
71
58
  endIndex = indexes[indexes.length - 1];
72
59
  var firstSelectedRowCells = (0, _getCellsInRow.getCellsInRow)(startIndex)(tr.selection);
73
60
  var firstColumnCells = (0, _getCellsInColumn.getCellsInColumn)(0)(tr.selection);
74
-
75
61
  if (!firstSelectedRowCells || !firstColumnCells) {
76
62
  return;
77
63
  }
78
-
79
64
  var $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1].pos);
80
65
  var headCell;
81
-
82
66
  for (var _i3 = endIndex; _i3 >= startIndex; _i3--) {
83
67
  var rowCells = (0, _getCellsInRow.getCellsInRow)(_i3)(tr.selection);
84
-
85
68
  if (rowCells && rowCells.length) {
86
69
  for (var j = firstColumnCells.length - 1; j >= 0; j--) {
87
70
  if (firstColumnCells[j].pos === rowCells[0].pos) {
@@ -89,17 +72,14 @@ var getSelectionRangeInRow = function getSelectionRangeInRow(rowIndex) {
89
72
  break;
90
73
  }
91
74
  }
92
-
93
75
  if (headCell) {
94
76
  break;
95
77
  }
96
78
  }
97
79
  }
98
-
99
80
  if (!headCell) {
100
81
  return;
101
82
  }
102
-
103
83
  var $head = tr.doc.resolve(headCell.pos);
104
84
  return {
105
85
  $anchor: $anchor,
@@ -108,5 +88,4 @@ var getSelectionRangeInRow = function getSelectionRangeInRow(rowIndex) {
108
88
  };
109
89
  };
110
90
  };
111
-
112
91
  exports.getSelectionRangeInRow = getSelectionRangeInRow;
@@ -4,22 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSelectionRect = void 0;
7
-
8
7
  var _tableMap = require("../table-map");
9
-
10
8
  var _isSelectionType = require("./is-selection-type");
11
-
12
9
  // Get the selection rectangle. Returns `undefined` if selection is not a CellSelection.
13
10
  var getSelectionRect = function getSelectionRect(selection) {
14
11
  if (!(0, _isSelectionType.isSelectionType)(selection, 'cell')) {
15
12
  return;
16
13
  }
17
-
18
14
  var start = selection.$anchorCell.start(-1);
19
-
20
15
  var map = _tableMap.TableMap.get(selection.$anchorCell.node(-1));
21
-
22
16
  return map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start);
23
17
  };
24
-
25
18
  exports.getSelectionRect = getSelectionRect;
@@ -4,78 +4,59 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.goToNextCell = goToNextCell;
7
-
8
7
  var _prosemirrorState = require("prosemirror-state");
9
-
10
8
  var _selectionCell = require("./selection-cell");
11
-
12
9
  var _tables = require("./tables");
13
-
14
10
  function moveCellForward($pos) {
15
11
  var nextNodeSize = $pos.nodeAfter ? $pos.nodeAfter.nodeSize : 0;
16
12
  return $pos.node(0).resolve($pos.pos + nextNodeSize);
17
- } // Returns a command for selecting the next (direction=1) or previous
18
- // (direction=-1) cell in a table.
19
-
13
+ }
20
14
 
15
+ // Returns a command for selecting the next (direction=1) or previous
16
+ // (direction=-1) cell in a table.
21
17
  function goToNextCell(direction) {
22
18
  return function (state, dispatch) {
23
19
  if (!(0, _tables.isInTable)(state)) {
24
20
  return false;
25
21
  }
26
-
27
22
  var cellSelection = (0, _selectionCell.selectionCell)(state.selection);
28
-
29
23
  if (!cellSelection) {
30
24
  return false;
31
25
  }
32
-
33
26
  var cell = findNextCell(cellSelection, direction);
34
-
35
27
  if (cell === undefined) {
36
28
  return false;
37
29
  }
38
-
39
30
  if (dispatch) {
40
31
  var $cell = state.doc.resolve(cell);
41
32
  dispatch(state.tr.setSelection(_prosemirrorState.TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
42
33
  }
43
-
44
34
  return true;
45
35
  };
46
36
  }
47
-
48
37
  function findNextCell($cell, direction) {
49
38
  if (direction === -1) {
50
39
  var before = $cell.nodeBefore;
51
-
52
40
  if (before) {
53
41
  return $cell.pos - before.nodeSize;
54
42
  }
55
-
56
43
  for (var row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
57
44
  var rowNode = $cell.node(-1).child(row);
58
-
59
45
  if (rowNode.childCount && rowNode.lastChild) {
60
46
  return rowEnd - 1 - rowNode.lastChild.nodeSize;
61
47
  }
62
-
63
48
  rowEnd -= rowNode.nodeSize;
64
49
  }
65
50
  } else {
66
51
  if ($cell.index() < $cell.parent.childCount - 1 && $cell.nodeAfter) {
67
52
  return $cell.pos + $cell.nodeAfter.nodeSize;
68
53
  }
69
-
70
54
  var table = $cell.node(-1);
71
-
72
55
  for (var _row = $cell.indexAfter(-1), rowStart = $cell.after(); _row < table.childCount; _row++) {
73
56
  var _rowNode = table.child(_row);
74
-
75
57
  if (_rowNode.childCount) {
76
58
  return rowStart + 1;
77
59
  }
78
-
79
60
  rowStart += _rowNode.nodeSize;
80
61
  }
81
62
  }
@@ -4,35 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.handlePaste = handlePaste;
7
-
8
7
  var _prosemirrorModel = require("prosemirror-model");
9
-
10
8
  var _cellSelection = require("../cell-selection");
11
-
12
9
  var _tableMap2 = require("../table-map");
13
-
14
10
  var _selectionCell = require("../utils/selection-cell");
15
-
16
11
  var _tableNodeTypes = require("../utils/table-node-types");
17
-
18
12
  var _tables = require("../utils/tables");
19
-
20
13
  var _copyPaste = require("./copy-paste");
21
-
22
14
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
23
-
24
15
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
-
26
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
27
-
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
28
17
  function handlePaste(view, event, slice) {
29
18
  if (!(0, _tables.isInTable)(view.state)) {
30
19
  return false;
31
20
  }
32
-
33
21
  var cells = (0, _copyPaste.pastedCells)(slice);
34
22
  var sel = view.state.selection;
35
-
36
23
  if (sel instanceof _cellSelection.CellSelection) {
37
24
  if (!cells) {
38
25
  cells = {
@@ -41,57 +28,43 @@ function handlePaste(view, event, slice) {
41
28
  rows: [_prosemirrorModel.Fragment.from((0, _copyPaste.fitSlice)((0, _tableNodeTypes.tableNodeTypes)(view.state.schema).cell, slice))]
42
29
  };
43
30
  }
44
-
45
31
  var table = sel.$anchorCell.node(-1);
46
32
  var start = sel.$anchorCell.start(-1);
47
-
48
33
  var tableMap = _tableMap2.TableMap.get(table);
49
-
50
34
  var rect = tableMap.rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start);
51
35
  cells = (0, _copyPaste.clipCells)(cells, rect.right - rect.left, rect.bottom - rect.top);
52
36
  (0, _copyPaste.insertCells)(view.state, view.dispatch, start, rect, clearColumnWidthOfCells(cells, rect, tableMap));
53
37
  return true;
54
38
  }
55
-
56
39
  if (cells) {
57
40
  var $cell = (0, _selectionCell.selectionCell)(sel);
58
-
59
41
  if (!$cell) {
60
42
  throw new Error("handlePaste: no cell found");
61
43
  }
62
-
63
44
  var _start = $cell.start(-1);
64
-
65
45
  var _rect = _tableMap2.TableMap.get($cell.node(-1)).findCell($cell.pos - _start);
66
-
67
46
  var _tableMap = _tableMap2.TableMap.get($cell.node(-1));
68
-
69
47
  (0, _copyPaste.insertCells)(view.state, view.dispatch, _start, _rect, clearColumnWidthOfCells(cells, _rect, _tableMap));
70
48
  return true;
71
49
  }
72
-
73
50
  return false;
74
- } // Clear the pasted cells column widths so that it maintains
51
+ }
52
+
53
+ // Clear the pasted cells column widths so that it maintains
75
54
  // the column widths of the destination table only if the pasted
76
55
  // cells overlap with existing cells in the destination table.
77
56
  // If the table grows on paste, keep the column widhts of the
78
57
  // original table.
79
-
80
-
81
58
  var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, table) {
82
59
  var overlappingCells = [];
83
-
84
60
  var _iterator = _createForOfIteratorHelper(cells.rows),
85
- _step;
86
-
61
+ _step;
87
62
  try {
88
63
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
89
64
  var row = _step.value;
90
65
  var colNum = rect.left;
91
-
92
66
  for (var index = 0; index < row.childCount; index++) {
93
67
  var _cell = row.child(index);
94
-
95
68
  if (colNum + _cell.attrs.colspan <= table.width) {
96
69
  overlappingCells.push(_cell);
97
70
  colNum += _cell.attrs.colspan;
@@ -105,11 +78,9 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
105
78
  } finally {
106
79
  _iterator.f();
107
80
  }
108
-
109
81
  for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
110
82
  var cell = _overlappingCells[_i];
111
83
  cell.attrs.colwidth = null;
112
84
  }
113
-
114
85
  return cells;
115
86
  };
@@ -4,42 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isTableSelected = exports.isRowSelected = exports.isRectSelected = exports.isColumnSelected = void 0;
7
-
8
7
  var _tableMap = require("../table-map");
9
-
10
8
  var _isSelectionType = require("./is-selection-type");
11
-
12
9
  // Checks if a given CellSelection rect is selected
13
10
  var isRectSelected = function isRectSelected(rect) {
14
11
  return function (selection) {
15
12
  if (!(0, _isSelectionType.isSelectionType)(selection, 'cell')) {
16
13
  return false;
17
14
  }
18
-
19
15
  var map = _tableMap.TableMap.get(selection.$anchorCell.node(-1));
20
-
21
16
  var start = selection.$anchorCell.start(-1);
22
17
  var cells = map.cellsInRect(rect);
23
18
  var selectedCells = map.cellsInRect(map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start));
24
-
25
19
  for (var i = 0, count = cells.length; i < count; i++) {
26
20
  if (selectedCells.indexOf(cells[i]) === -1) {
27
21
  return false;
28
22
  }
29
23
  }
30
-
31
24
  return true;
32
25
  };
33
- }; // Checks if entire column at index `columnIndex` is selected.
34
-
26
+ };
35
27
 
28
+ // Checks if entire column at index `columnIndex` is selected.
36
29
  exports.isRectSelected = isRectSelected;
37
-
38
30
  var isColumnSelected = function isColumnSelected(columnIndex) {
39
31
  return function (selection) {
40
32
  if ((0, _isSelectionType.isSelectionType)(selection, 'cell')) {
41
33
  var map = _tableMap.TableMap.get(selection.$anchorCell.node(-1));
42
-
43
34
  return isRectSelected({
44
35
  left: columnIndex,
45
36
  right: columnIndex + 1,
@@ -47,19 +38,16 @@ var isColumnSelected = function isColumnSelected(columnIndex) {
47
38
  bottom: map.height
48
39
  })(selection);
49
40
  }
50
-
51
41
  return false;
52
42
  };
53
- }; // Checks if entire row at index `rowIndex` is selected.
54
-
43
+ };
55
44
 
45
+ // Checks if entire row at index `rowIndex` is selected.
56
46
  exports.isColumnSelected = isColumnSelected;
57
-
58
47
  var isRowSelected = function isRowSelected(rowIndex) {
59
48
  return function (selection) {
60
49
  if ((0, _isSelectionType.isSelectionType)(selection, 'cell')) {
61
50
  var map = _tableMap.TableMap.get(selection.$anchorCell.node(-1));
62
-
63
51
  return isRectSelected({
64
52
  left: 0,
65
53
  right: map.width,
@@ -67,18 +55,15 @@ var isRowSelected = function isRowSelected(rowIndex) {
67
55
  bottom: rowIndex + 1
68
56
  })(selection);
69
57
  }
70
-
71
58
  return false;
72
59
  };
73
- }; // Checks if entire table is selected
74
-
60
+ };
75
61
 
62
+ // Checks if entire table is selected
76
63
  exports.isRowSelected = isRowSelected;
77
-
78
64
  var isTableSelected = function isTableSelected(selection) {
79
65
  if ((0, _isSelectionType.isSelectionType)(selection, 'cell')) {
80
66
  var map = _tableMap.TableMap.get(selection.$anchorCell.node(-1));
81
-
82
67
  return isRectSelected({
83
68
  left: 0,
84
69
  right: map.width,
@@ -86,8 +71,6 @@ var isTableSelected = function isTableSelected(selection) {
86
71
  bottom: map.height
87
72
  })(selection);
88
73
  }
89
-
90
74
  return false;
91
75
  };
92
-
93
76
  exports.isTableSelected = isTableSelected;
@@ -4,12 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isSelectionType = isSelectionType;
7
-
8
7
  function isSelectionType(selection, type) {
9
8
  if (!selection) {
10
9
  return false;
11
10
  }
12
-
13
11
  var serialized = selection.toJSON();
14
12
  return serialized.type === type;
15
13
  }
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.moveColumn = void 0;
7
-
8
7
  var _cloneTr = require("./clone-tr");
9
-
10
8
  var _find = require("./find");
11
-
12
9
  var _getSelectionRangeInColumn = require("./get-selection-range-in-column");
13
-
14
10
  var _reorderUtils = require("./reorder-utils");
15
-
16
11
  // :: (originColumnIndex: number, targetColumnIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
17
12
  // Returns a new transaction that moves the origin column to the target index;
18
13
  //
@@ -148,29 +143,22 @@ var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex) {
148
143
  };
149
144
  return function (tr) {
150
145
  var _originalColumnRanges, _targetColumnRanges$i;
151
-
152
146
  var table = (0, _find.findTable)(tr.selection);
153
-
154
147
  if (!table) {
155
148
  return tr;
156
149
  }
157
-
158
150
  var originalColumnRanges = (0, _getSelectionRangeInColumn.getSelectionRangeInColumn)(originColumnIndex)(tr);
159
151
  var targetColumnRanges = (0, _getSelectionRangeInColumn.getSelectionRangeInColumn)(targetColumnIndex)(tr);
160
152
  var indexesOriginColumn = (_originalColumnRanges = originalColumnRanges === null || originalColumnRanges === void 0 ? void 0 : originalColumnRanges.indexes) !== null && _originalColumnRanges !== void 0 ? _originalColumnRanges : [];
161
153
  var indexesTargetColumn = (_targetColumnRanges$i = targetColumnRanges === null || targetColumnRanges === void 0 ? void 0 : targetColumnRanges.indexes) !== null && _targetColumnRanges$i !== void 0 ? _targetColumnRanges$i : [];
162
-
163
154
  if (indexesOriginColumn.includes(targetColumnIndex)) {
164
155
  return tr;
165
156
  }
166
-
167
157
  if (!options.tryToFit && indexesTargetColumn.length > 1) {
168
158
  (0, _reorderUtils.isValidReorder)(originColumnIndex, targetColumnIndex, indexesTargetColumn, 'column');
169
159
  }
170
-
171
160
  var newTable = (0, _reorderUtils.moveTableColumn)(table, indexesOriginColumn, indexesTargetColumn, options.direction);
172
161
  return (0, _cloneTr.cloneTr)(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
173
162
  };
174
163
  };
175
-
176
164
  exports.moveColumn = moveColumn;
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.moveRow = void 0;
7
-
8
7
  var _cloneTr = require("./clone-tr");
9
-
10
8
  var _find = require("./find");
11
-
12
9
  var _getSelectionRangeInRow = require("./get-selection-range-in-row");
13
-
14
10
  var _reorderUtils = require("./reorder-utils");
15
-
16
11
  // :: (originRowIndex: number, targetRowIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
17
12
  // Returns a new transaction that moves the origin row to the target index;
18
13
  //
@@ -163,27 +158,21 @@ var moveRow = function moveRow(originRowIndex, targetRowIndex) {
163
158
  };
164
159
  return function (tr) {
165
160
  var table = (0, _find.findTable)(tr.selection);
166
-
167
161
  if (!table) {
168
162
  return tr;
169
163
  }
170
-
171
164
  var originalRowRanges = (0, _getSelectionRangeInRow.getSelectionRangeInRow)(originRowIndex)(tr);
172
165
  var targetRowRanges = (0, _getSelectionRangeInRow.getSelectionRangeInRow)(targetRowIndex)(tr);
173
166
  var indexesOriginRow = (originalRowRanges === null || originalRowRanges === void 0 ? void 0 : originalRowRanges.indexes) || [];
174
167
  var indexesTargetRow = (targetRowRanges === null || targetRowRanges === void 0 ? void 0 : targetRowRanges.indexes) || [];
175
-
176
168
  if (indexesOriginRow.includes(targetRowIndex)) {
177
169
  return tr;
178
170
  }
179
-
180
171
  if (!options.tryToFit && indexesTargetRow.length > 1) {
181
172
  (0, _reorderUtils.isValidReorder)(originRowIndex, targetRowIndex, indexesTargetRow, 'row');
182
173
  }
183
-
184
174
  var newTable = (0, _reorderUtils.moveTableRow)(table, indexesOriginRow, indexesTargetRow, options.direction);
185
175
  return (0, _cloneTr.cloneTr)(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
186
176
  };
187
177
  };
188
-
189
178
  exports.moveRow = moveRow;
@@ -4,27 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.normalizeSelection = normalizeSelection;
7
-
8
7
  var _prosemirrorState = require("prosemirror-state");
9
-
10
8
  var _cellSelection = require("../cell-selection");
11
-
12
9
  var _tableMap = require("../table-map");
13
-
14
10
  function normalizeSelection(state, transaction, allowTableNodeSelection) {
15
11
  var tr = transaction;
16
12
  var sel = (tr || state).selection;
17
-
18
13
  var _ref = tr || state,
19
- doc = _ref.doc;
20
-
14
+ doc = _ref.doc;
21
15
  var normalize;
22
16
  var role;
23
-
24
17
  if (sel instanceof _prosemirrorState.NodeSelection) {
25
18
  role = sel.node.type.spec.tableRole;
26
19
  }
27
-
28
20
  if (sel instanceof _prosemirrorState.NodeSelection && role) {
29
21
  if (role === 'cell' || role === 'header_cell') {
30
22
  normalize = _cellSelection.CellSelection.create(doc, sel.from);
@@ -33,7 +25,6 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
33
25
  normalize = _cellSelection.CellSelection.rowSelection($cell, $cell);
34
26
  } else if (!allowTableNodeSelection) {
35
27
  var map = _tableMap.TableMap.get(sel.node);
36
-
37
28
  var start = sel.from + 1;
38
29
  var lastCell = start + map.map[map.width * map.height - 1];
39
30
  normalize = _cellSelection.CellSelection.create(doc, start + 1, lastCell);
@@ -43,65 +34,50 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
43
34
  } else if (sel instanceof _prosemirrorState.TextSelection && isTextSelectionAcrossCells(sel)) {
44
35
  normalize = _prosemirrorState.TextSelection.create(doc, sel.$from.start(), sel.$from.end());
45
36
  }
46
-
47
37
  if (normalize) {
48
38
  (tr || (tr = state.tr)).setSelection(normalize);
49
39
  }
50
-
51
40
  return tr;
52
41
  }
53
-
54
42
  function isCellBoundarySelection(_ref2) {
55
43
  var $from = _ref2.$from,
56
- $to = _ref2.$to;
57
-
44
+ $to = _ref2.$to;
58
45
  if ($from.pos === $to.pos || $from.pos < $from.pos - 6) {
59
46
  return false;
60
47
  } // Cheap elimination
61
-
62
-
63
48
  var afterFrom = $from.pos;
64
49
  var beforeTo = $to.pos;
65
50
  var depth = $from.depth;
66
-
67
51
  for (; depth >= 0; depth--, afterFrom++) {
68
52
  if ($from.after(depth + 1) < $from.end(depth)) {
69
53
  break;
70
54
  }
71
55
  }
72
-
73
56
  for (var d = $to.depth; d >= 0; d--, beforeTo--) {
74
57
  if ($to.before(d + 1) > $to.start(d)) {
75
58
  break;
76
59
  }
77
60
  }
78
-
79
61
  return afterFrom === beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
80
62
  }
81
-
82
63
  function isTextSelectionAcrossCells(_ref3) {
83
64
  var $from = _ref3.$from,
84
- $to = _ref3.$to;
65
+ $to = _ref3.$to;
85
66
  var fromCellBoundaryNode;
86
67
  var toCellBoundaryNode;
87
-
88
68
  for (var i = $from.depth; i > 0; i--) {
89
69
  var node = $from.node(i);
90
-
91
70
  if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
92
71
  fromCellBoundaryNode = node;
93
72
  break;
94
73
  }
95
74
  }
96
-
97
75
  for (var _i = $to.depth; _i > 0; _i--) {
98
76
  var _node = $to.node(_i);
99
-
100
77
  if (_node.type.spec.tableRole === 'cell' || _node.type.spec.tableRole === 'header_cell') {
101
78
  toCellBoundaryNode = _node;
102
79
  break;
103
80
  }
104
81
  }
105
-
106
82
  return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
107
83
  }