@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,56 +4,44 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.findTableClosestToPos = exports.findTable = exports.findCellRectClosestToPos = exports.findCellClosestToPos = void 0;
7
-
8
7
  var _prosemirrorUtils = require("prosemirror-utils");
9
-
10
8
  var _tableMap = require("../table-map");
11
-
12
9
  // Iterates over parent nodes, returning the closest table node.
13
10
  var findTable = function findTable(selection) {
14
11
  return (0, _prosemirrorUtils.findParentNode)(function (node) {
15
12
  return node.type.spec.tableRole && node.type.spec.tableRole === 'table';
16
13
  })(selection);
17
- }; // Iterates over parent nodes, returning a table node closest to a given `$pos`.
18
-
14
+ };
19
15
 
16
+ // Iterates over parent nodes, returning a table node closest to a given `$pos`.
20
17
  exports.findTable = findTable;
21
-
22
18
  var findTableClosestToPos = function findTableClosestToPos($pos) {
23
19
  var predicate = function predicate(node) {
24
20
  return node.type.spec.tableRole && node.type.spec.tableRole === 'table';
25
21
  };
26
-
27
22
  return (0, _prosemirrorUtils.findParentNodeClosestToPos)($pos, predicate);
28
- }; // Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
29
-
23
+ };
30
24
 
25
+ // Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
31
26
  exports.findTableClosestToPos = findTableClosestToPos;
32
-
33
27
  var findCellClosestToPos = function findCellClosestToPos($pos) {
34
28
  var predicate = function predicate(node) {
35
29
  return node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole);
36
30
  };
37
-
38
31
  return (0, _prosemirrorUtils.findParentNodeClosestToPos)($pos, predicate);
39
- }; // Returns the rectangle spanning a cell closest to a given `$pos`.
40
-
32
+ };
41
33
 
34
+ // Returns the rectangle spanning a cell closest to a given `$pos`.
42
35
  exports.findCellClosestToPos = findCellClosestToPos;
43
-
44
36
  var findCellRectClosestToPos = function findCellRectClosestToPos($pos) {
45
37
  var cell = findCellClosestToPos($pos);
46
-
47
38
  if (cell) {
48
39
  var table = findTableClosestToPos($pos);
49
-
50
40
  if (table) {
51
41
  var map = _tableMap.TableMap.get(table.node);
52
-
53
42
  var cellPos = cell.pos - table.start;
54
43
  return map.rectBetween(cellPos, cellPos);
55
44
  }
56
45
  }
57
46
  };
58
-
59
47
  exports.findCellRectClosestToPos = findCellRectClosestToPos;
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.fixTable = fixTable;
9
8
  exports.fixTables = fixTables;
10
-
11
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
-
13
10
  var _pluginKey = require("../pm-plugins/plugin-key");
14
-
15
11
  var _tableMap = require("../table-map");
16
-
17
12
  var _colspan = require("./colspan");
18
-
19
13
  var _tableNodeTypes = require("./table-node-types");
20
-
21
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
22
-
23
15
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
24
-
25
16
  // Helper for iterating through the nodes in a document that changed
26
17
  // compared to the given previous document. Useful for avoiding
27
18
  // duplicate work on each transaction.
@@ -29,82 +20,68 @@ function changedDescendants(old, cur, offsetStart, f) {
29
20
  var offset = offsetStart;
30
21
  var oldSize = old.childCount;
31
22
  var curSize = cur.childCount;
32
-
33
23
  outer: for (var i = 0, j = 0; i < curSize; i++) {
34
24
  var _child = cur.child(i);
35
-
36
25
  for (var scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
37
26
  if (old.child(scan) === _child) {
38
27
  j = scan + 1;
39
- offset += _child.nodeSize; // eslint-disable-next-line no-continue
40
-
28
+ offset += _child.nodeSize;
29
+ // eslint-disable-next-line no-continue
41
30
  continue outer;
42
31
  }
43
32
  }
44
-
45
33
  f(_child, offset);
46
-
47
34
  if (j < oldSize && old.child(j).sameMarkup(_child)) {
48
35
  changedDescendants(old.child(j), _child, offset + 1, f);
49
36
  } else {
50
37
  _child.nodesBetween(0, _child.content.size, f, offset + 1);
51
38
  }
52
-
53
39
  offset += _child.nodeSize;
54
40
  }
55
- } // :: (EditorState, ?EditorState) → ?Transaction
41
+ }
42
+
43
+ // :: (EditorState, ?EditorState) → ?Transaction
56
44
  // Inspect all tables in the given state's document and return a
57
45
  // transaction that fixes them, if necessary. If `oldState` was
58
46
  // provided, that is assumed to hold a previous, known-good state,
59
47
  // which will be used to avoid re-scanning unchanged parts of the
60
48
  // document.
61
-
62
-
63
49
  function fixTables(state, oldState, reportFixedTable) {
64
50
  var tr;
65
-
66
51
  var check = function check(node, pos) {
67
52
  if (node.type.spec.tableRole === 'table') {
68
53
  tr = fixTable(state, node, pos, tr, reportFixedTable);
69
54
  }
70
55
  };
71
-
72
56
  if (!oldState) {
73
57
  state.doc.descendants(check);
74
58
  } else if (oldState.doc !== state.doc) {
75
59
  changedDescendants(oldState.doc, state.doc, 0, check);
76
60
  }
77
-
78
61
  return tr;
79
- } // : (EditorState, Node, number, ?Transaction) → ?Transaction
62
+ }
63
+
64
+ // : (EditorState, Node, number, ?Transaction) → ?Transaction
80
65
  // Fix the given table, if necessary. Will append to the transaction
81
66
  // it was given, if non-null, or create a new one if necessary.
82
-
83
-
84
67
  function fixTable(state, table, tablePos, transaction, reportFixedTable) {
85
68
  var tr = transaction;
86
-
87
69
  var map = _tableMap.TableMap.get(table);
88
-
89
70
  if (!map.problems) {
90
71
  return tr;
91
72
  }
92
-
93
73
  if (!tr) {
94
74
  tr = state.tr;
95
- } // Track which rows we must add cells to, so that we can adjust that
96
- // when fixing collisions.
97
-
75
+ }
98
76
 
77
+ // Track which rows we must add cells to, so that we can adjust that
78
+ // when fixing collisions.
99
79
  var mustAdd = [];
100
-
101
80
  for (var i = 0; i < map.height; i++) {
102
81
  mustAdd.push(0);
103
82
  }
104
-
105
83
  for (var _i = 0; _i < map.problems.length; _i++) {
106
84
  var prob = map.problems[_i];
107
-
108
85
  if (reportFixedTable) {
109
86
  reportFixedTable({
110
87
  state: state,
@@ -112,90 +89,70 @@ function fixTable(state, table, tablePos, transaction, reportFixedTable) {
112
89
  reason: prob.type || 'unknown'
113
90
  });
114
91
  }
115
-
116
92
  if (prob.type === _tableMap.TableProblemTypes.COLLISION) {
117
93
  var collision = prob;
118
94
  var cell = table.nodeAt(prob.pos);
119
-
120
95
  if (!cell) {
121
96
  throw new Error("fixTable: unable to find cell at pos ".concat(prob.pos));
122
97
  }
123
-
124
98
  for (var j = 0; j < cell.attrs.rowspan; j++) {
125
99
  mustAdd[collision.row + j] += collision.n;
126
100
  }
127
-
128
101
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), undefined, (0, _colspan.removeColSpan)(cell.attrs, cell.attrs.colspan - collision.n, collision.n));
129
102
  } else if (prob.type === _tableMap.TableProblemTypes.MISSING) {
130
103
  var missing = prob;
131
104
  mustAdd[missing.row] += missing.n;
132
105
  } else if (prob.type === _tableMap.TableProblemTypes.OVERLONG_ROWSPAN) {
133
106
  var overlong = prob;
134
-
135
107
  var _cell = table.nodeAt(overlong.pos);
136
-
137
108
  if (!_cell) {
138
109
  throw new Error("fixTable: unable to find cell at pos ".concat(prob.pos));
139
110
  }
140
-
141
111
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + overlong.pos), undefined, _objectSpread(_objectSpread({}, _cell.attrs), {}, {
142
112
  rowspan: _cell.attrs.rowspan - overlong.n
143
113
  }));
144
114
  } else if (prob.type === _tableMap.TableProblemTypes.COLWIDTH_MISMATCH) {
145
115
  var _cell2 = table.nodeAt(prob.pos);
146
-
147
116
  if (!_cell2) {
148
117
  throw new Error("fixTable: unable to find cell at pos ".concat(prob.pos));
149
118
  }
150
-
151
119
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), undefined, _objectSpread(_objectSpread({}, _cell2.attrs), {}, {
152
120
  colwidth: prob.colwidth
153
121
  }));
154
122
  }
155
123
  }
156
-
157
124
  var first;
158
125
  var last;
159
-
160
126
  for (var _i2 = 0; _i2 < mustAdd.length; _i2++) {
161
127
  if (mustAdd[_i2]) {
162
128
  if (first == null) {
163
129
  first = _i2;
164
130
  }
165
-
166
131
  last = _i2;
167
132
  }
168
- } // Add the necessary cells, using a heuristic for whether to add the
133
+ }
134
+ // Add the necessary cells, using a heuristic for whether to add the
169
135
  // cells at the start or end of the rows (if it looks like a 'bite'
170
136
  // was taken out of the table, add cells at the start of the row
171
137
  // after the bite. Otherwise add them at the end).
172
-
173
-
174
138
  for (var _i3 = 0, pos = tablePos + 1; _i3 < map.height; _i3++) {
175
139
  var row = table.child(_i3);
176
140
  var end = pos + row.nodeSize;
177
141
  var add = mustAdd[_i3];
178
-
179
142
  if (add > 0) {
180
143
  var tableNodeType = 'cell';
181
-
182
144
  if (row.firstChild) {
183
145
  tableNodeType = row.firstChild.type.spec.tableRole;
184
146
  }
185
-
186
147
  var nodes = [];
187
-
188
148
  for (var _j = 0; _j < add; _j++) {
189
149
  nodes.push((0, _tableNodeTypes.tableNodeTypes)(state.schema)[tableNodeType].createAndFill());
190
150
  }
191
-
192
151
  var side = (_i3 === 0 || first === _i3 - 1) && last === _i3 ? pos + 1 : end - 1;
193
152
  tr.insert(tr.mapping.map(side), nodes);
194
153
  }
195
-
196
154
  pos = end;
197
155
  }
198
-
199
156
  return tr.setMeta(_pluginKey.fixTablesKey, {
200
157
  fixTables: true
201
158
  });
@@ -4,59 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.forEachCellInRow = exports.forEachCellInColumn = void 0;
7
-
8
7
  var _prosemirrorState = require("prosemirror-state");
9
-
10
8
  var _cloneTr = require("./clone-tr");
11
-
12
9
  var _getCellsInColumn = require("./get-cells-in-column");
13
-
14
10
  var _getCellsInRow = require("./get-cells-in-row");
15
-
16
11
  // Returns a new transaction that maps a given `cellTransform` function to each cell in a column at a given `columnIndex`.
17
12
  // It will set the selection into the last cell of the column if `setCursorToLastCell` param is set to `true`.
18
13
  var forEachCellInColumn = function forEachCellInColumn(columnIndex, cellTransform, setCursorToLastCell) {
19
14
  return function (tr) {
20
15
  var cells = (0, _getCellsInColumn.getCellsInColumn)(columnIndex)(tr.selection);
21
-
22
16
  if (cells) {
23
17
  for (var i = cells.length - 1; i >= 0; i--) {
24
18
  tr = cellTransform(cells[i], tr);
25
19
  }
26
-
27
20
  if (setCursorToLastCell) {
28
21
  var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
29
22
  tr.setSelection(_prosemirrorState.Selection.near($pos));
30
23
  }
31
-
32
24
  return (0, _cloneTr.cloneTr)(tr);
33
25
  }
34
-
35
26
  return tr;
36
27
  };
37
- }; // Returns a new transaction that maps a given `cellTransform` function to each cell in a row at a given `rowIndex`.
38
- // It will set the selection into the last cell of the row if `setCursorToLastCell` param is set to `true`.
39
-
28
+ };
40
29
 
30
+ // Returns a new transaction that maps a given `cellTransform` function to each cell in a row at a given `rowIndex`.
31
+ // It will set the selection into the last cell of the row if `setCursorToLastCell` param is set to `true`.
41
32
  exports.forEachCellInColumn = forEachCellInColumn;
42
-
43
33
  var forEachCellInRow = function forEachCellInRow(rowIndex, cellTransform, setCursorToLastCell) {
44
34
  return function (tr) {
45
35
  var cells = (0, _getCellsInRow.getCellsInRow)(rowIndex)(tr.selection);
46
-
47
36
  if (cells) {
48
37
  for (var i = cells.length - 1; i >= 0; i--) {
49
38
  tr = cellTransform(cells[i], tr);
50
39
  }
51
-
52
40
  if (setCursorToLastCell) {
53
41
  var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
54
42
  tr.setSelection(_prosemirrorState.Selection.near($pos));
55
43
  }
56
44
  }
57
-
58
45
  return tr;
59
46
  };
60
47
  };
61
-
62
48
  exports.forEachCellInRow = forEachCellInRow;
@@ -4,32 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCellSelectionRanges = getCellSelectionRanges;
7
-
8
7
  var _prosemirrorState = require("prosemirror-state");
9
-
10
8
  var _tableMap = require("../table-map");
11
-
12
9
  function getCellSelectionRanges($anchorCell, $headCell) {
13
10
  var table = $anchorCell.node(-1);
14
-
15
11
  var map = _tableMap.TableMap.get(table);
16
-
17
12
  var start = $anchorCell.start(-1);
18
13
  var rect = map.rectBetween($anchorCell.pos - start, $headCell.pos - start);
19
14
  var doc = $anchorCell.node(0);
20
15
  var cells = map.cellsInRect(rect).filter(function (p) {
21
16
  return p !== $headCell.pos - start;
22
- }); // Make the head cell the first range, so that it counts as the
17
+ });
18
+ // Make the head cell the first range, so that it counts as the
23
19
  // primary part of the selection
24
-
25
20
  cells.unshift($headCell.pos - start);
26
21
  return cells.map(function (pos) {
27
22
  var cell = table.nodeAt(pos);
28
-
29
23
  if (cell === null) {
30
24
  throw new Error("No cell at position ".concat(pos));
31
25
  }
32
-
33
26
  var from = pos + start + 1;
34
27
  return new _prosemirrorState.SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));
35
28
  });
@@ -4,22 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCellsInColumn = void 0;
7
-
8
7
  var _tableMap = require("../table-map");
9
-
10
8
  var _find = require("./find");
11
-
12
9
  // Returns an array of cells in a column(s), where `columnIndex` could be a column index or an array of column indexes.
13
10
  var getCellsInColumn = function getCellsInColumn(columnIndexes) {
14
11
  return function (selection) {
15
12
  var table = (0, _find.findTable)(selection);
16
-
17
13
  if (!table) {
18
14
  return;
19
15
  }
20
-
21
16
  var map = _tableMap.TableMap.get(table.node);
22
-
23
17
  var indexes = Array.isArray(columnIndexes) ? columnIndexes : [columnIndexes];
24
18
  return indexes.filter(function (index) {
25
19
  return index >= 0 && index <= map.width - 1;
@@ -43,5 +37,4 @@ var getCellsInColumn = function getCellsInColumn(columnIndexes) {
43
37
  }, []);
44
38
  };
45
39
  };
46
-
47
40
  exports.getCellsInColumn = getCellsInColumn;
@@ -4,22 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCellsInRow = void 0;
7
-
8
7
  var _tableMap = require("../table-map");
9
-
10
8
  var _find = require("./find");
11
-
12
9
  // Returns an array of cells in a row(s), where `rowIndex` could be a row index or an array of row indexes.
13
10
  var getCellsInRow = function getCellsInRow(rowIndex) {
14
11
  return function (selection) {
15
12
  var table = (0, _find.findTable)(selection);
16
-
17
13
  if (!table) {
18
14
  return;
19
15
  }
20
-
21
16
  var map = _tableMap.TableMap.get(table.node);
22
-
23
17
  var indexes = Array.isArray(rowIndex) ? rowIndex : [rowIndex];
24
18
  return indexes.filter(function (index) {
25
19
  return index >= 0 && index <= map.height - 1;
@@ -43,5 +37,4 @@ var getCellsInRow = function getCellsInRow(rowIndex) {
43
37
  }, []);
44
38
  };
45
39
  };
46
-
47
40
  exports.getCellsInRow = getCellsInRow;
@@ -4,21 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCellsInTable = void 0;
7
-
8
7
  var _tableMap = require("../table-map");
9
-
10
8
  var _find = require("./find");
11
-
12
9
  // Returns an array of all cells in a table.
13
10
  var getCellsInTable = function getCellsInTable(selection) {
14
11
  var table = (0, _find.findTable)(selection);
15
-
16
12
  if (!table) {
17
13
  return;
18
14
  }
19
-
20
15
  var map = _tableMap.TableMap.get(table.node);
21
-
22
16
  var positions = map.cellsInRect({
23
17
  left: 0,
24
18
  right: map.width,
@@ -27,7 +21,6 @@ var getCellsInTable = function getCellsInTable(selection) {
27
21
  });
28
22
  return positions.map(function (cellPos) {
29
23
  var node = table.node.nodeAt(cellPos);
30
-
31
24
  if (node) {
32
25
  var pos = cellPos + table.start;
33
26
  return {
@@ -41,5 +34,4 @@ var getCellsInTable = function getCellsInTable(selection) {
41
34
  return typeof cell !== 'undefined';
42
35
  });
43
36
  };
44
-
45
37
  exports.getCellsInTable = getCellsInTable;
@@ -4,84 +4,67 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSelectionRangeInColumn = 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 column at index `columnIndex`.
13
10
  var getSelectionRangeInColumn = function getSelectionRangeInColumn(columnIndex) {
14
11
  return function (tr) {
15
12
  var startIndex = columnIndex;
16
- var endIndex = columnIndex; // looking for selection start column (startIndex)
13
+ var endIndex = columnIndex;
17
14
 
15
+ // looking for selection start column (startIndex)
18
16
  var _loop = function _loop(i) {
19
17
  var cells = (0, _getCellsInColumn.getCellsInColumn)(i)(tr.selection);
20
-
21
18
  if (cells) {
22
19
  cells.forEach(function (cell) {
23
20
  var maybeEndIndex = cell.node.attrs.colspan + 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 = columnIndex; i >= 0; i--) {
37
31
  _loop(i);
38
- } // looking for selection end column (endIndex)
39
-
40
-
32
+ }
33
+ // looking for selection end column (endIndex)
41
34
  var _loop2 = function _loop2(_i) {
42
35
  var cells = (0, _getCellsInColumn.getCellsInColumn)(_i)(tr.selection);
43
-
44
36
  if (cells) {
45
37
  cells.forEach(function (cell) {
46
38
  var maybeEndIndex = cell.node.attrs.colspan + _i - 1;
47
-
48
39
  if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) {
49
40
  endIndex = maybeEndIndex;
50
41
  }
51
42
  });
52
43
  }
53
44
  };
54
-
55
45
  for (var _i = columnIndex; _i <= endIndex; _i++) {
56
46
  _loop2(_i);
57
- } // filter out columns without cells (where all rows have colspan > 1 in the same column)
58
-
47
+ }
59
48
 
49
+ // filter out columns without cells (where all rows have colspan > 1 in the same column)
60
50
  var indexes = [];
61
-
62
51
  for (var _i2 = startIndex; _i2 <= endIndex; _i2++) {
63
52
  var maybeCells = (0, _getCellsInColumn.getCellsInColumn)(_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 firstSelectedColumnCells = (0, _getCellsInColumn.getCellsInColumn)(startIndex)(tr.selection);
73
60
  var firstRowCells = (0, _getCellsInRow.getCellsInRow)(0)(tr.selection);
74
-
75
61
  if (!firstSelectedColumnCells || !firstRowCells) {
76
62
  return;
77
63
  }
78
-
79
64
  var $anchor = tr.doc.resolve(firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos);
80
65
  var headCell;
81
-
82
66
  for (var _i3 = endIndex; _i3 >= startIndex; _i3--) {
83
67
  var columnCells = (0, _getCellsInColumn.getCellsInColumn)(_i3)(tr.selection);
84
-
85
68
  if (columnCells && columnCells.length) {
86
69
  for (var j = firstRowCells.length - 1; j >= 0; j--) {
87
70
  if (firstRowCells[j].pos === columnCells[0].pos) {
@@ -89,17 +72,14 @@ var getSelectionRangeInColumn = function getSelectionRangeInColumn(columnIndex)
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 getSelectionRangeInColumn = function getSelectionRangeInColumn(columnIndex)
108
88
  };
109
89
  };
110
90
  };
111
-
112
91
  exports.getSelectionRangeInColumn = getSelectionRangeInColumn;