@atlaskit/editor-tables 2.8.2 → 2.8.3

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 (76) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/afm-cc/tsconfig.json +5 -1
  3. package/afm-jira/tsconfig.json +5 -1
  4. package/afm-post-office/tsconfig.json +5 -1
  5. package/dist/cjs/cell-bookmark.js +3 -2
  6. package/dist/cjs/cell-selection.js +17 -8
  7. package/dist/cjs/pm-plugins/input.js +23 -4
  8. package/dist/cjs/table-map.js +21 -9
  9. package/dist/cjs/utils/add-column.js +2 -0
  10. package/dist/cjs/utils/add-row.js +2 -0
  11. package/dist/cjs/utils/clone-column.js +7 -0
  12. package/dist/cjs/utils/clone-row.js +2 -0
  13. package/dist/cjs/utils/copy-paste.js +29 -1
  14. package/dist/cjs/utils/find.js +5 -1
  15. package/dist/cjs/utils/fix-tables.js +8 -1
  16. package/dist/cjs/utils/get-cells-in-column.js +2 -0
  17. package/dist/cjs/utils/get-cells-in-row.js +2 -0
  18. package/dist/cjs/utils/move-column.js +9 -1
  19. package/dist/cjs/utils/move-row.js +2 -0
  20. package/dist/cjs/utils/normalize-selection.js +2 -0
  21. package/dist/cjs/utils/reorder-utils.js +20 -4
  22. package/dist/cjs/utils/split-cell-with-type.js +3 -3
  23. package/dist/cjs/utils/uuid.js +8 -4
  24. package/dist/es2019/cell-bookmark.js +3 -0
  25. package/dist/es2019/cell-selection.js +14 -1
  26. package/dist/es2019/index.js +3 -0
  27. package/dist/es2019/pm-plugins/input.js +23 -4
  28. package/dist/es2019/pm-plugins.js +3 -0
  29. package/dist/es2019/table-map.js +53 -41
  30. package/dist/es2019/utils/add-column.js +2 -0
  31. package/dist/es2019/utils/add-row-at.js +4 -4
  32. package/dist/es2019/utils/add-row.js +2 -0
  33. package/dist/es2019/utils/clone-column.js +11 -1
  34. package/dist/es2019/utils/clone-row.js +7 -2
  35. package/dist/es2019/utils/copy-paste.js +29 -1
  36. package/dist/es2019/utils/find.js +4 -1
  37. package/dist/es2019/utils/fix-tables.js +8 -1
  38. package/dist/es2019/utils/get-cells-in-column.js +2 -0
  39. package/dist/es2019/utils/get-cells-in-row.js +2 -0
  40. package/dist/es2019/utils/get-selection-range-in-column.js +2 -2
  41. package/dist/es2019/utils/get-selection-range-in-row.js +2 -2
  42. package/dist/es2019/utils/move-column.js +13 -2
  43. package/dist/es2019/utils/move-row.js +7 -2
  44. package/dist/es2019/utils/normalize-selection.js +2 -0
  45. package/dist/es2019/utils/remove-row.js +3 -3
  46. package/dist/es2019/utils/remove-table.js +1 -1
  47. package/dist/es2019/utils/reorder-utils.js +21 -5
  48. package/dist/es2019/utils/replace-table.js +1 -1
  49. package/dist/es2019/utils/split-cell-with-type.js +6 -6
  50. package/dist/es2019/utils/toggle-header.js +6 -6
  51. package/dist/es2019/utils/uuid.js +4 -1
  52. package/dist/es2019/utils.js +3 -0
  53. package/dist/esm/cell-bookmark.js +4 -2
  54. package/dist/esm/cell-selection.js +18 -7
  55. package/dist/esm/index.js +3 -0
  56. package/dist/esm/pm-plugins/input.js +23 -4
  57. package/dist/esm/pm-plugins.js +3 -0
  58. package/dist/esm/table-map.js +21 -9
  59. package/dist/esm/utils/add-column.js +2 -0
  60. package/dist/esm/utils/add-row.js +2 -0
  61. package/dist/esm/utils/clone-column.js +7 -0
  62. package/dist/esm/utils/clone-row.js +2 -0
  63. package/dist/esm/utils/copy-paste.js +29 -1
  64. package/dist/esm/utils/find.js +5 -1
  65. package/dist/esm/utils/fix-tables.js +8 -1
  66. package/dist/esm/utils/get-cells-in-column.js +2 -0
  67. package/dist/esm/utils/get-cells-in-row.js +2 -0
  68. package/dist/esm/utils/move-column.js +9 -1
  69. package/dist/esm/utils/move-row.js +2 -0
  70. package/dist/esm/utils/normalize-selection.js +2 -0
  71. package/dist/esm/utils/reorder-utils.js +20 -4
  72. package/dist/esm/utils/split-cell-with-type.js +3 -3
  73. package/dist/esm/utils/uuid.js +8 -4
  74. package/dist/esm/utils.js +3 -0
  75. package/package.json +8 -2
  76. package/tsconfig.json +0 -1
@@ -115,6 +115,8 @@ function ensureRectangular(schema, rowsFragment) {
115
115
  rows.push(Fragment.empty);
116
116
  }
117
117
  if (widths[r] < width) {
118
+ // Ignored via go/ees005
119
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
120
  const empty = tableNodeTypes(schema).cell.createAndFill();
119
121
  const cells = [];
120
122
  for (let i = widths[r]; i < width; i++) {
@@ -201,6 +203,8 @@ export function clipCells({
201
203
 
202
204
  // Make sure a table has at least the given width and height. Return
203
205
  // true if something was changed.
206
+ // Ignored via go/ees005
207
+ // eslint-disable-next-line @typescript-eslint/max-params
204
208
  function growTable(tr, map, table, start, width, height, mapFrom) {
205
209
  const {
206
210
  schema
@@ -215,8 +219,12 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
215
219
  const cells = [];
216
220
  let add;
217
221
  if (rowNode.lastChild == null || rowNode.lastChild.type === types.cell) {
222
+ // Ignored via go/ees005
223
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
218
224
  add = empty || (empty = types.cell.createAndFill());
219
225
  } else {
226
+ // Ignored via go/ees005
227
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
220
228
  add = emptyHead || (emptyHead = types.header_cell.createAndFill());
221
229
  }
222
230
  for (let i = map.width; i < width; i++) {
@@ -239,7 +247,13 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
239
247
  }
240
248
  header = node.type === types.header_cell;
241
249
  }
242
- cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill()));
250
+ cells.push(header ?
251
+ // Ignored via go/ees005
252
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
253
+ emptyHead || (emptyHead = types.header_cell.createAndFill()) :
254
+ // Ignored via go/ees005
255
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
256
+ empty || (empty = types.cell.createAndFill()));
243
257
  }
244
258
  const emptyRow = types.row.create(null, Fragment.from(cells));
245
259
  const rows = [];
@@ -254,6 +268,8 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
254
268
  // Make sure the given line (left, top) to (right, top) doesn't cross
255
269
  // any rowspan cells by splitting cells that cross it. Return true if
256
270
  // something changed.
271
+ // Ignored via go/ees005
272
+ // eslint-disable-next-line @typescript-eslint/max-params
257
273
  function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
258
274
  if (top === 0 || top === map.height) {
259
275
  return false;
@@ -293,6 +309,8 @@ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
293
309
  // Make sure the given line (left, top) to (left, bottom) doesn't
294
310
  // cross any colspan cells by splitting cells that cross it. Return
295
311
  // true if something changed.
312
+ // Ignored via go/ees005
313
+ // eslint-disable-next-line @typescript-eslint/max-params
296
314
  function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
297
315
  if (left === 0 || left === map.width) {
298
316
  return false;
@@ -320,10 +338,16 @@ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
320
338
  }
321
339
  return found;
322
340
  }
341
+
342
+ // Ignored via go/ees005
343
+ // eslint-disable-next-line @typescript-eslint/max-params
323
344
  function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabled, headerColumnEnabled) {
324
345
  const {
325
346
  schema
326
347
  } = state;
348
+
349
+ // Ignored via go/ees005
350
+ // eslint-disable-next-line @typescript-eslint/max-params
327
351
  const setMarkup = (tr, row, col, headerEnabled) => {
328
352
  const cellPos = tableStart + tableMap.positionAt(row, col, table);
329
353
  const cell = tr.doc.nodeAt(cellPos);
@@ -350,6 +374,8 @@ function applyHeaderCells(tr, tableMap, state, tableStart, table, headerRowEnabl
350
374
 
351
375
  // Insert the given set of cells (as returned by `pastedCells`) into a
352
376
  // table, at the position pointed at by rect.
377
+ // Ignored via go/ees005
378
+ // eslint-disable-next-line @typescript-eslint/max-params
353
379
  export function insertCells(state, dispatch, tableStart, rect, cells) {
354
380
  let table = state.doc;
355
381
  const newRect = selectedRect(state);
@@ -376,6 +402,8 @@ export function insertCells(state, dispatch, tableStart, rect, cells) {
376
402
  } = state;
377
403
  let mapFrom = 0;
378
404
  function recomp() {
405
+ // Ignored via go/ees005
406
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
379
407
  table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
380
408
  map = TableMap.get(table);
381
409
  mapFrom = tr.mapping.maps.length;
@@ -12,7 +12,10 @@ export const findTableClosestToPos = $pos => {
12
12
 
13
13
  // Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
14
14
  export const findCellClosestToPos = $pos => {
15
- const predicate = node => node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole);
15
+ const predicate = node =>
16
+ // Ignored via go/ees005
17
+ // eslint-disable-next-line require-unicode-regexp
18
+ node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole);
16
19
  return findParentNodeClosestToPos($pos, predicate);
17
20
  };
18
21
 
@@ -5,17 +5,20 @@ import { tableNodeTypes } from './table-node-types';
5
5
  // Helper for iterating through the nodes in a document that changed
6
6
  // compared to the given previous document. Useful for avoiding
7
7
  // duplicate work on each transaction.
8
+ // Ignored via go/ees005
9
+ // eslint-disable-next-line @typescript-eslint/max-params
8
10
  function changedDescendants(old, cur, offsetStart, f) {
9
11
  let offset = offsetStart;
10
12
  const oldSize = old.childCount;
11
13
  const curSize = cur.childCount;
14
+ // eslint-disable-next-line no-labels
12
15
  outer: for (let i = 0, j = 0; i < curSize; i++) {
13
16
  const child = cur.child(i);
14
17
  for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
15
18
  if (old.child(scan) === child) {
16
19
  j = scan + 1;
17
20
  offset += child.nodeSize;
18
- // eslint-disable-next-line no-continue
21
+ // eslint-disable-next-line no-continue, no-labels
19
22
  continue outer;
20
23
  }
21
24
  }
@@ -53,6 +56,8 @@ export function fixTables(state, oldState, reportFixedTable) {
53
56
  // : (EditorState, Node, number, ?Transaction) → ?Transaction
54
57
  // Fix the given table, if necessary. Will append to the transaction
55
58
  // it was given, if non-null, or create a new one if necessary.
59
+ // Ignored via go/ees005
60
+ // eslint-disable-next-line @typescript-eslint/max-params
56
61
  export function fixTable(state, table, tablePos, transaction, reportFixedTable) {
57
62
  let tr = transaction;
58
63
  const map = TableMap.get(table);
@@ -137,6 +142,8 @@ export function fixTable(state, table, tablePos, transaction, reportFixedTable)
137
142
  }
138
143
  const nodes = [];
139
144
  for (let j = 0; j < add; j++) {
145
+ // Ignored via go/ees005
146
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140
147
  nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill());
141
148
  }
142
149
  const side = (i === 0 || first === i - 1) && last === i ? pos + 1 : end - 1;
@@ -17,6 +17,8 @@ export const getCellsInColumn = columnIndexes => selection => {
17
17
  bottom: map.height
18
18
  });
19
19
  return acc.concat(cells.map(nodePos => {
20
+ // Ignored via go/ees005
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
22
  const node = table.node.nodeAt(nodePos);
21
23
  const pos = nodePos + table.start;
22
24
  return {
@@ -17,6 +17,8 @@ export const getCellsInRow = rowIndex => selection => {
17
17
  bottom: index + 1
18
18
  });
19
19
  return acc.concat(cells.map(nodePos => {
20
+ // Ignored via go/ees005
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
22
  const node = table.node.nodeAt(nodePos);
21
23
  const pos = nodePos + table.start;
22
24
  return {
@@ -11,7 +11,7 @@ export const getSelectionRangeInColumn = (startColIndex, endColIndex = startColI
11
11
  const cells = getCellsInColumn(i)(tr.selection);
12
12
  if (cells) {
13
13
  cells.forEach(cell => {
14
- let maybeEndIndex = cell.node.attrs.colspan + i - 1;
14
+ const maybeEndIndex = cell.node.attrs.colspan + i - 1;
15
15
  if (maybeEndIndex >= startIndex) {
16
16
  startIndex = i;
17
17
  }
@@ -26,7 +26,7 @@ export const getSelectionRangeInColumn = (startColIndex, endColIndex = startColI
26
26
  const cells = getCellsInColumn(i)(tr.selection);
27
27
  if (cells) {
28
28
  cells.forEach(cell => {
29
- let maybeEndIndex = cell.node.attrs.colspan + i - 1;
29
+ const maybeEndIndex = cell.node.attrs.colspan + i - 1;
30
30
  if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) {
31
31
  endIndex = maybeEndIndex;
32
32
  }
@@ -11,7 +11,7 @@ export const getSelectionRangeInRow = (startRowIndex, endRowIndex = startRowInde
11
11
  const cells = getCellsInRow(i)(tr.selection);
12
12
  if (cells) {
13
13
  cells.forEach(cell => {
14
- let maybeEndIndex = cell.node.attrs.rowspan + i - 1;
14
+ const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
15
15
  if (maybeEndIndex >= startIndex) {
16
16
  startIndex = i;
17
17
  }
@@ -26,7 +26,7 @@ export const getSelectionRangeInRow = (startRowIndex, endRowIndex = startRowInde
26
26
  const cells = getCellsInRow(i)(tr.selection);
27
27
  if (cells) {
28
28
  cells.forEach(cell => {
29
- let maybeEndIndex = cell.node.attrs.rowspan + i - 1;
29
+ const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
30
30
  if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) {
31
31
  endIndex = maybeEndIndex;
32
32
  }
@@ -1,3 +1,4 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  import { CellSelection } from '../cell-selection';
2
3
  import { TableMap } from '../table-map';
3
4
  import { determineTableHeaderStateFromTableNode } from './analyse-table';
@@ -139,7 +140,10 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
139
140
  tryToFit: false,
140
141
  direction: 0,
141
142
  selectAfterMove: false
142
- }) => tr => {
143
+ }
144
+ // Ignored via go/ees005
145
+ // eslint-disable-next-line @typescript-eslint/max-params
146
+ ) => tr => {
143
147
  var _originalColumnRanges, _targetColumnRanges$i;
144
148
  const table = findTable(tr.selection);
145
149
  if (!table) {
@@ -207,9 +211,11 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
207
211
  // The actual target index needs to be translated per row, this is because row/col spans can affect the amount of
208
212
  // cells each row contains.
209
213
  const rowTargetPosition = translateTargetPosition(y, actualTargetIndex, tableMap);
214
+ // Ignored via go/ees005
215
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
210
216
  const node = table.node.nodeAt(rowTargetPosition);
211
217
  const pos = table.start + rowTargetPosition;
212
- const insertPos = direction === 'end' ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
218
+ const insertPos = direction === 'end' || tableMap.isCellMergedTopLeft(y, actualTargetIndex) && fg('platform_editor_table_fix_move_column') ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
213
219
  newTr.insert(insertPos, row.map(({
214
220
  node
215
221
  }, x) => normalizeCellNode(node, rowHeaderEnabled && y === 0, columnHeaderEnabled && actualTargetIndex === 0 && x === 0, types)));
@@ -229,12 +235,17 @@ export const moveColumn = (state, originColumnIndex, targetColumnIndex, options
229
235
  }
230
236
  return newTr;
231
237
  };
238
+
239
+ // Ignored via go/ees005
240
+ // eslint-disable-next-line @typescript-eslint/max-params
232
241
  function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, types) {
233
242
  const newTargetType = rowHeaderEnabled || columnHeaderEnabled ? types.header_cell : types.cell;
234
243
  return cellNode.type !== newTargetType ? newTargetType.create(cellNode.attrs, cellNode.content, cellNode.marks) : cellNode;
235
244
  }
236
245
  function createContentNodeFactory(table) {
237
246
  return nodePos => {
247
+ // Ignored via go/ees005
248
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
238
249
  const node = table.node.nodeAt(nodePos);
239
250
  const pos = nodePos + table.start;
240
251
  return {
@@ -155,7 +155,10 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
155
155
  tryToFit: false,
156
156
  direction: 0,
157
157
  selectAfterMove: false
158
- }) => tr => {
158
+ }
159
+ // Ignored via go/ees005
160
+ // eslint-disable-next-line @typescript-eslint/max-params
161
+ ) => tr => {
159
162
  const table = findTable(tr.selection);
160
163
  if (!table) {
161
164
  return tr;
@@ -248,8 +251,10 @@ export const moveRow = (state, originRowIndex, targetRowIndex, options = {
248
251
  * This ensures the row node cell type correctly reflect what they should be.
249
252
  * @returns A copy of the rowNode
250
253
  */
254
+ // Ignored via go/ees005
255
+ // eslint-disable-next-line @typescript-eslint/max-params
251
256
  function normalizeRowNode(rowNode, rowHeaderEnabled, columnHeaderEnabled, types) {
252
- let content = [];
257
+ const content = [];
253
258
  rowNode.forEach((node, offset, index) => {
254
259
  const newTargetType = rowHeaderEnabled || columnHeaderEnabled && index === 0 ? types.header_cell : types.cell;
255
260
  content.push(node.type !== newTargetType ? newTargetType.create(node.attrs, node.content, node.marks) : node);
@@ -56,6 +56,8 @@ function isCellBoundarySelection({
56
56
  break;
57
57
  }
58
58
  }
59
+ // Ignored via go/ees005
60
+ // eslint-disable-next-line require-unicode-regexp
59
61
  return afterFrom === beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
60
62
  }
61
63
  function isTextSelectionAcrossCells({
@@ -14,11 +14,11 @@ function removeRow(tr, {
14
14
  for (let i = 0; i < rowIndex; i++) {
15
15
  rowPos += table.child(i).nodeSize;
16
16
  }
17
- let nextRow = rowPos + table.child(rowIndex).nodeSize;
18
- let mapFrom = tr.mapping.maps.length;
17
+ const nextRow = rowPos + table.child(rowIndex).nodeSize;
18
+ const mapFrom = tr.mapping.maps.length;
19
19
  tr.delete(rowPos + tableStart, nextRow + tableStart);
20
20
  for (let col = 0, index = rowIndex * map.width; col < map.width; col++, index++) {
21
- let pos = map.map[index];
21
+ const pos = map.map[index];
22
22
  if (rowIndex > 0 && pos === map.map[index - map.width]) {
23
23
  // If this cell starts in the row above, simply reduce its rowspan
24
24
  const cell = table.nodeAt(pos);
@@ -6,7 +6,7 @@ export const removeTable = tr => {
6
6
  $from
7
7
  } = tr.selection;
8
8
  for (let depth = $from.depth; depth > 0; depth--) {
9
- let node = $from.node(depth);
9
+ const node = $from.node(depth);
10
10
  if (node.type.spec.tableRole === 'table') {
11
11
  return cloneTr(tr.delete($from.before(depth), $from.after(depth)));
12
12
  }
@@ -28,7 +28,11 @@ import { TableMap } from '../table-map';
28
28
  // ['a3', 'b3', 'c3', 'd3'],
29
29
  // ]
30
30
  // ```
31
+ // Ignored via go/ees005
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
33
  export const transpose = array => {
34
+ // Ignored via go/ees005
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
36
  return array[0].map((_, i) => {
33
37
  return array.map(column => column[i]);
34
38
  });
@@ -84,8 +88,11 @@ export const convertArrayOfRowsToTableNode = (tableNode, arrayOfNodes) => {
84
88
  const newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
85
89
  return newTable;
86
90
  };
87
- const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) => {
88
- let direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
91
+ const moveRowInArrayOfRows = (arrayOfNodes, indexesOrigin, indexesTarget, directionOverride
92
+ // Ignored via go/ees005
93
+ // eslint-disable-next-line @typescript-eslint/max-params
94
+ ) => {
95
+ const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
89
96
  const rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
90
97
  const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
91
98
  let target;
@@ -149,18 +156,27 @@ export const convertTableNodeToArrayOfRows = tableNode => {
149
156
  }
150
157
  return rows;
151
158
  };
152
- export const moveTableRow = (table, indexesOrigin, indexesTarget, direction) => {
159
+ export const moveTableRow = (table, indexesOrigin, indexesTarget, direction
160
+ // Ignored via go/ees005
161
+ // eslint-disable-next-line @typescript-eslint/max-params
162
+ ) => {
153
163
  let rows = convertTableNodeToArrayOfRows(table.node);
154
164
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
155
165
  return convertArrayOfRowsToTableNode(table.node, rows);
156
166
  };
157
- export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction) => {
167
+ export const moveTableColumn = (table, indexesOrigin, indexesTarget, direction
168
+ // Ignored via go/ees005
169
+ // eslint-disable-next-line @typescript-eslint/max-params
170
+ ) => {
158
171
  let rows = transpose(convertTableNodeToArrayOfRows(table.node));
159
172
  rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
160
173
  rows = transpose(rows);
161
174
  return convertArrayOfRowsToTableNode(table.node, rows);
162
175
  };
163
- export const isValidReorder = (originIndex, targetIndex, targets, type) => {
176
+ export const isValidReorder = (originIndex, targetIndex, targets, type
177
+ // Ignored via go/ees005
178
+ // eslint-disable-next-line @typescript-eslint/max-params
179
+ ) => {
164
180
  const direction = originIndex > targetIndex ? -1 : 1;
165
181
  const errorMessage = `Target position is invalid, you can't move the ${type} ${originIndex} to ${targetIndex}, the target can't be split. You could use tryToFit option.`;
166
182
  if (direction === 1) {
@@ -7,7 +7,7 @@ export const replaceSelectedTable = (state, content) => {
7
7
  const table = findTable(state.selection);
8
8
  if (table) {
9
9
  const slice = typeof content === 'string' ? new Slice(Fragment.from(state.schema.text(content)), 0, 0) : content;
10
- let tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
10
+ const tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
11
11
  tr.setSelection(TextSelection.create(tr.doc, table.pos + slice.size + 1));
12
12
  return tr;
13
13
  }
@@ -16,7 +16,7 @@ export function cellWrapping($pos) {
16
16
  // into smaller cells with the cell type (th, td) returned by getType function.
17
17
  export function splitCellWithType(getCellType) {
18
18
  return (state, dispatch) => {
19
- let sel = state.selection;
19
+ const sel = state.selection;
20
20
  let cellNode, cellPos;
21
21
  if (!(sel instanceof CellSelection)) {
22
22
  cellNode = cellWrapping(sel.$from);
@@ -36,9 +36,9 @@ export function splitCellWithType(getCellType) {
36
36
  return false;
37
37
  }
38
38
  if (cellNode && dispatch) {
39
- let cellAttrs = cellNode.attrs,
40
- attrs = [],
41
- colwidth = cellAttrs.colwidth;
39
+ let cellAttrs = cellNode.attrs;
40
+ const attrs = [];
41
+ const colwidth = cellAttrs.colwidth;
42
42
  if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
43
43
  cellAttrs = {
44
44
  ...cellAttrs,
@@ -51,8 +51,8 @@ export function splitCellWithType(getCellType) {
51
51
  colspan: 1
52
52
  };
53
53
  }
54
- let rect = selectedRect(state);
55
- let tr = state.tr;
54
+ const rect = selectedRect(state);
55
+ const tr = state.tr;
56
56
  for (let i = 0; i < rect.right - rect.left; i++) {
57
57
  attrs.push(colwidth ? {
58
58
  ...cellAttrs,
@@ -26,13 +26,13 @@ export function toggleHeader(type) {
26
26
  return false;
27
27
  }
28
28
  if (dispatch) {
29
- let types = tableNodeTypes(state.schema);
30
- let rect = selectedRect(state),
29
+ const types = tableNodeTypes(state.schema);
30
+ const rect = selectedRect(state),
31
31
  tr = state.tr;
32
- let isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
33
- let isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
34
- let isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
35
- let selectionStartsAt = isHeaderEnabled ? 1 : 0;
32
+ const isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
33
+ const isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
34
+ const isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
35
+ const selectionStartsAt = isHeaderEnabled ? 1 : 0;
36
36
  const cellsRect = type === 'column' ? new Rect(0, selectionStartsAt, 1, rect.map.height) : type === 'row' ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect;
37
37
  let newType;
38
38
  if (type === 'column') {
@@ -4,7 +4,10 @@
4
4
  */
5
5
 
6
6
  /* eslint-disable no-bitwise */
7
- export const generateUuid = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
7
+ export const generateUuid = () =>
8
+ // Ignored via go/ees005
9
+ // eslint-disable-next-line require-unicode-regexp
10
+ 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
8
11
  const r = Math.random() * 16 | 0;
9
12
  return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
10
13
  });
@@ -1,3 +1,6 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ // Entry file in package.json
3
+
1
4
  export { addColumnAt } from './utils/add-column-at';
2
5
  export { addColumn, columnIsHeader } from './utils/add-column';
3
6
  export { addRowAt } from './utils/add-row-at';
@@ -1,5 +1,8 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
+ /* eslint-disable @atlaskit/editor/no-re-export */
4
+ // Entry file in package.json
5
+
3
6
  import { Selection } from '@atlaskit/editor-prosemirror/state';
4
7
  import { inSameTable } from './utils/tables';
5
8
  export var CellBookmark = /*#__PURE__*/function () {
@@ -8,7 +11,7 @@ export var CellBookmark = /*#__PURE__*/function () {
8
11
  this.anchor = anchor;
9
12
  this.head = head;
10
13
  }
11
- _createClass(CellBookmark, [{
14
+ return _createClass(CellBookmark, [{
12
15
  key: "map",
13
16
  value: function map(mapping) {
14
17
  return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
@@ -29,5 +32,4 @@ export var CellBookmark = /*#__PURE__*/function () {
29
32
  return Selection.near($headCell, 1);
30
33
  }
31
34
  }]);
32
- return CellBookmark;
33
35
  }();
@@ -1,13 +1,16 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
7
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
- function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ /* eslint-disable @atlaskit/editor/no-re-export */
12
+ // Entry file in package.json
13
+
11
14
  // Was copied from https://github.com/ProseMirror/prosemirror-tables/blob/master/src/cellselection.js
12
15
 
13
16
  // This file defines a ProseMirror selection subclass that models
@@ -30,8 +33,6 @@ import { inSameTable } from './utils/tables';
30
33
  // selects across cells, and will be drawn by giving selected cells a
31
34
  // `selectedCell` CSS class.
32
35
  export var CellSelection = /*#__PURE__*/function (_Selection) {
33
- _inherits(CellSelection, _Selection);
34
- var _super = _createSuper(CellSelection);
35
36
  // :: (ResolvedPos, ?ResolvedPos)
36
37
  // A table selection is identified by its anchor and head cells. The
37
38
  // positions given to this constructor should point _before_ two
@@ -43,7 +44,7 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
43
44
  var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
44
45
  _classCallCheck(this, CellSelection);
45
46
  var ranges = getCellSelectionRanges($anchorCell, $headCell);
46
- _this = _super.call(this, ranges[0].$from, ranges[0].$to, ranges);
47
+ _this = _callSuper(this, CellSelection, [ranges[0].$from, ranges[0].$to, ranges]);
47
48
  // :: ResolvedPos
48
49
  // A resolved position pointing _in front of_ the anchor cell (the one
49
50
  // that doesn't move when extending the selection).
@@ -55,7 +56,8 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
55
56
  _this.visible = false;
56
57
  return _this;
57
58
  }
58
- _createClass(CellSelection, [{
59
+ _inherits(CellSelection, _Selection);
60
+ return _createClass(CellSelection, [{
59
61
  key: "map",
60
62
  value: function map(doc, mapping) {
61
63
  var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
@@ -108,6 +110,8 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
108
110
  attrs = removeColSpan(attrs, 0, extraLeft);
109
111
  }
110
112
  if (extraRight > 0) {
113
+ // Ignored via go/ees005
114
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111
115
  attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
112
116
  }
113
117
  if (cellRect.left < rect.left) {
@@ -193,7 +197,11 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
193
197
  if (Math.min(anchorTop, headTop) > 0) {
194
198
  return false;
195
199
  }
200
+ // Ignored via go/ees005
201
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
196
202
  var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
203
+ // Ignored via go/ees005
204
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
197
205
  var headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan;
198
206
  return Math.max(anchorBot, headBot) === this.$headCell.node(-1).childCount;
199
207
  }
@@ -235,7 +243,11 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
235
243
  if (Math.min(anchorLeft, headLeft) > 0) {
236
244
  return false;
237
245
  }
246
+ // Ignored via go/ees005
247
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
238
248
  var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
249
+ // Ignored via go/ees005
250
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
251
  var headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
240
252
  return Math.max(anchorRight, headRight) === map.width;
241
253
  }
@@ -332,6 +344,5 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
332
344
  return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
333
345
  }
334
346
  }]);
335
- return CellSelection;
336
347
  }(Selection);
337
348
  Selection.jsonID('cell', CellSelection);
package/dist/esm/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ // Entry file in package.json
3
+
1
4
  /**
2
5
  This package is based on prosemirror-tables, https://github.com/ProseMirror/prosemirror-tables
3
6