@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
@@ -2,29 +2,24 @@ import { CellSelection } from '../cell-selection';
2
2
  import { TableMap } from '../table-map';
3
3
  import { cloneTr } from './clone-tr';
4
4
  import { findCellClosestToPos, findTable, findTableClosestToPos } from './find';
5
-
6
5
  const select = type => (index, expand) => tr => {
7
6
  const table = findTable(tr.selection);
8
7
  const isRowSelection = type === 'row';
9
-
10
8
  if (table) {
11
- const map = TableMap.get(table.node); // Check if the index is valid
9
+ const map = TableMap.get(table.node);
12
10
 
11
+ // Check if the index is valid
13
12
  if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
14
13
  let left = isRowSelection ? 0 : index;
15
14
  let top = isRowSelection ? index : 0;
16
15
  let right = isRowSelection ? map.width : index + 1;
17
16
  let bottom = isRowSelection ? index + 1 : map.height;
18
-
19
17
  if (expand) {
20
18
  const cell = findCellClosestToPos(tr.selection.$from);
21
-
22
19
  if (!cell) {
23
20
  return tr;
24
21
  }
25
-
26
22
  const selRect = map.findCell(cell.pos - table.start);
27
-
28
23
  if (isRowSelection) {
29
24
  top = Math.min(top, selRect.top);
30
25
  bottom = Math.max(bottom, selRect.bottom);
@@ -33,7 +28,6 @@ const select = type => (index, expand) => tr => {
33
28
  right = Math.max(right, selRect.right);
34
29
  }
35
30
  }
36
-
37
31
  const cellsInFirstRow = map.cellsInRect({
38
32
  left,
39
33
  top,
@@ -53,25 +47,24 @@ const select = type => (index, expand) => tr => {
53
47
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
54
48
  }
55
49
  }
56
-
57
50
  return tr;
58
- }; // Returns a new transaction that selects a column at index `columnIndex`.
59
- // Use the optional `expand` param to extend from current selection.
60
-
51
+ };
61
52
 
62
- export const selectColumn = select('column'); // Returns a new transaction that selects a row at index `rowIndex`.
53
+ // Returns a new transaction that selects a column at index `columnIndex`.
63
54
  // Use the optional `expand` param to extend from current selection.
55
+ export const selectColumn = select('column');
64
56
 
65
- export const selectRow = select('row'); // Returns a new transaction that selects a table.
57
+ // Returns a new transaction that selects a row at index `rowIndex`.
58
+ // Use the optional `expand` param to extend from current selection.
59
+ export const selectRow = select('row');
66
60
 
61
+ // Returns a new transaction that selects a table.
67
62
  export const selectTable = tr => {
68
63
  const table = findTable(tr.selection);
69
-
70
64
  if (table) {
71
65
  const {
72
66
  map
73
67
  } = TableMap.get(table.node);
74
-
75
68
  if (map && map.length) {
76
69
  const head = table.start + map[0];
77
70
  const anchor = table.start + map[map.length - 1];
@@ -80,17 +73,14 @@ export const selectTable = tr => {
80
73
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
81
74
  }
82
75
  }
83
-
84
76
  return tr;
85
77
  };
86
78
  export const selectTableClosestToPos = (tr, $pos) => {
87
79
  const table = findTableClosestToPos($pos);
88
-
89
80
  if (table) {
90
81
  const {
91
82
  map
92
83
  } = TableMap.get(table.node);
93
-
94
84
  if (map && map.length) {
95
85
  const head = table.start + map[0];
96
86
  const anchor = table.start + map[map.length - 1];
@@ -99,6 +89,5 @@ export const selectTableClosestToPos = (tr, $pos) => {
99
89
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
100
90
  }
101
91
  }
102
-
103
92
  return tr;
104
93
  };
@@ -4,10 +4,8 @@ export function selectionCell(selection) {
4
4
  if (isSelectionType(selection, 'cell')) {
5
5
  return selection.$anchorCell.pos > selection.$headCell.pos ? selection.$anchorCell : selection.$headCell;
6
6
  }
7
-
8
7
  if (isSelectionType(selection, 'node') && selection.node.type.spec.tableRole === 'cell') {
9
8
  return selection.$anchor;
10
9
  }
11
-
12
10
  return cellAround(selection.$head) || cellNear(selection.$head);
13
11
  }
@@ -7,22 +7,18 @@ import { selectionCell } from './selection-cell';
7
7
  export function selectedRect(state) {
8
8
  const sel = state.selection;
9
9
  const $pos = selectionCell(sel);
10
-
11
10
  if (!$pos) {
12
11
  throw new Error(`selectedRect: invalid $pos for selection`);
13
12
  }
14
-
15
13
  const table = $pos.node(-1);
16
14
  const tableStart = $pos.start(-1);
17
15
  const map = TableMap.get(table);
18
16
  let rect;
19
-
20
17
  if (sel instanceof CellSelection) {
21
18
  rect = map.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart);
22
19
  } else {
23
20
  rect = map.findCell($pos.pos - tableStart);
24
21
  }
25
-
26
22
  rect.tableStart = tableStart;
27
23
  rect.map = map;
28
24
  rect.table = table;
@@ -1,10 +1,10 @@
1
- import { cloneTr } from './clone-tr'; // Returns a new transaction that sets given `attrs` to a given `cell`.
1
+ import { cloneTr } from './clone-tr';
2
2
 
3
+ // Returns a new transaction that sets given `attrs` to a given `cell`.
3
4
  export const setCellAttrs = (cell, attrs) => tr => {
4
5
  if (cell) {
5
6
  tr.setNodeMarkup(cell.pos, undefined, Object.assign({}, cell.node.attrs, attrs));
6
7
  return cloneTr(tr);
7
8
  }
8
-
9
9
  return tr;
10
10
  };
@@ -6,12 +6,10 @@ export function cellWrapping($pos) {
6
6
  for (let d = $pos.depth; d > 0; d--) {
7
7
  // Sometimes the cell can be in the same depth.
8
8
  const role = $pos.node(d).type.spec.tableRole;
9
-
10
9
  if (role === 'cell' || role === 'header_cell') {
11
10
  return $pos.node(d);
12
11
  }
13
12
  }
14
-
15
13
  return null;
16
14
  }
17
15
  // Split a selected cell, whose rowpan or colspan is greater than one,
@@ -20,81 +18,67 @@ export function splitCellWithType(getCellType) {
20
18
  return (state, dispatch) => {
21
19
  let sel = state.selection;
22
20
  let cellNode, cellPos;
23
-
24
21
  if (!(sel instanceof CellSelection)) {
25
22
  cellNode = cellWrapping(sel.$from);
26
-
27
23
  if (!cellNode) {
28
24
  return false;
29
25
  }
30
-
31
26
  const cellNodeAround = cellAround(sel.$from);
32
27
  cellPos = cellNodeAround && cellNodeAround.pos;
33
28
  } else {
34
29
  if (sel.$anchorCell.pos !== sel.$headCell.pos) {
35
30
  return false;
36
31
  }
37
-
38
32
  cellNode = sel.$anchorCell.nodeAfter;
39
33
  cellPos = sel.$anchorCell.pos;
40
34
  }
41
-
42
35
  if (cellNode && cellNode.attrs.colspan === 1 && cellNode.attrs.rowspan === 1) {
43
36
  return false;
44
37
  }
45
-
46
38
  if (cellNode && dispatch) {
47
39
  let cellAttrs = cellNode.attrs,
48
- attrs = [],
49
- colwidth = cellAttrs.colwidth;
50
-
40
+ attrs = [],
41
+ colwidth = cellAttrs.colwidth;
51
42
  if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
52
- cellAttrs = { ...cellAttrs,
43
+ cellAttrs = {
44
+ ...cellAttrs,
53
45
  rowspan: 1
54
46
  };
55
47
  }
56
-
57
48
  if (cellAttrs.colspan && cellAttrs.colspan > 1) {
58
- cellAttrs = { ...cellAttrs,
49
+ cellAttrs = {
50
+ ...cellAttrs,
59
51
  colspan: 1
60
52
  };
61
53
  }
62
-
63
54
  let rect = selectedRect(state);
64
55
  let tr = state.tr;
65
-
66
56
  for (let i = 0; i < rect.right - rect.left; i++) {
67
- attrs.push(colwidth ? { ...cellAttrs,
57
+ attrs.push(colwidth ? {
58
+ ...cellAttrs,
68
59
  colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
69
60
  } : cellAttrs);
70
61
  }
71
-
72
62
  let lastCell = null;
73
-
74
63
  for (let row = rect.top; row < rect.bottom; row++) {
75
64
  let pos = rect.map.positionAt(row, rect.left, rect.table);
76
-
77
65
  if (row === rect.top) {
78
66
  pos += cellNode.nodeSize;
79
67
  }
80
-
81
68
  for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
82
69
  if (col === rect.left && row === rect.top) {
83
70
  continue;
84
71
  }
85
-
86
72
  const cellType = getCellType({
87
73
  node: cellNode,
88
74
  row,
89
75
  col
90
76
  }).createAndFill(attrs[i]);
91
-
92
77
  if (cellType) {
93
78
  tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), cellType);
94
79
  }
95
80
  }
96
81
  }
97
-
98
82
  if (typeof cellPos === 'number') {
99
83
  tr.setNodeMarkup(cellPos, getCellType({
100
84
  node: cellNode,
@@ -102,16 +86,12 @@ export function splitCellWithType(getCellType) {
102
86
  col: rect.left
103
87
  }), attrs[0]);
104
88
  }
105
-
106
89
  const $lastCellPosition = lastCell && tr.doc.resolve(lastCell);
107
-
108
90
  if (sel instanceof CellSelection && $lastCellPosition instanceof ResolvedPos) {
109
91
  tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), $lastCellPosition));
110
92
  }
111
-
112
93
  dispatch(tr);
113
94
  }
114
-
115
95
  return true;
116
96
  };
117
97
  }
@@ -1,7 +1,8 @@
1
1
  import { splitCellWithType } from './split-cell-with-type';
2
- import { tableNodeTypes } from './table-node-types'; // Split a selected cell, whose rowpan or colspan is greater than one,
3
- // into smaller cells. Use the first cell type for the new cells.
2
+ import { tableNodeTypes } from './table-node-types';
4
3
 
4
+ // Split a selected cell, whose rowpan or colspan is greater than one,
5
+ // into smaller cells. Use the first cell type for the new cells.
5
6
  export const splitCell = (state, dispatch) => {
6
7
  const nodeTypes = tableNodeTypes(state.schema);
7
8
  return splitCellWithType(({
@@ -1,20 +1,17 @@
1
1
  export function tableNodeTypes(schema) {
2
2
  let result = schema.cached.tableNodeTypes;
3
-
4
3
  if (!result) {
5
- result = {}; // eslint-disable-next-line no-param-reassign
6
-
7
- schema.cached.tableNodeTypes = result; // eslint-disable-next-line guard-for-in
8
-
4
+ result = {};
5
+ // eslint-disable-next-line no-param-reassign
6
+ schema.cached.tableNodeTypes = result;
7
+ // eslint-disable-next-line guard-for-in
9
8
  for (const name in schema.nodes) {
10
9
  const type = schema.nodes[name];
11
10
  const role = type.spec.tableRole;
12
-
13
11
  if (role) {
14
12
  result[role] = type;
15
13
  }
16
14
  }
17
15
  }
18
-
19
16
  return result;
20
17
  }
@@ -2,13 +2,11 @@ export function isInTable(state) {
2
2
  const {
3
3
  $head
4
4
  } = state.selection;
5
-
6
5
  for (let d = $head.depth; d > 0; d--) {
7
6
  if ($head.node(d).type.spec.tableRole === 'row') {
8
7
  return true;
9
8
  }
10
9
  }
11
-
12
10
  return false;
13
11
  }
14
12
  export function inSameTable($a, $b) {
@@ -1,60 +1,56 @@
1
1
  import { addColumn } from './add-column';
2
2
  import { addRow } from './add-row';
3
3
  import { selectedRect } from './selection-rect';
4
- import { isInTable } from './tables'; // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
5
- // Add a table row before the selection.
4
+ import { isInTable } from './tables';
6
5
 
6
+ // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
7
+ // Add a table row before the selection.
7
8
  export const addRowBefore = (state, dispatch) => {
8
9
  if (!isInTable(state)) {
9
10
  return false;
10
11
  }
11
-
12
12
  if (dispatch) {
13
13
  const rect = selectedRect(state);
14
14
  dispatch(addRow(state.tr, rect, rect.top));
15
15
  }
16
-
17
16
  return true;
18
- }; // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
19
- // Add a table row after the selection.
17
+ };
20
18
 
19
+ // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
20
+ // Add a table row after the selection.
21
21
  export const addRowAfter = (state, dispatch) => {
22
22
  if (!isInTable(state)) {
23
23
  return false;
24
24
  }
25
-
26
25
  if (dispatch) {
27
26
  const rect = selectedRect(state);
28
27
  dispatch(addRow(state.tr, rect, rect.bottom));
29
28
  }
30
-
31
29
  return true;
32
- }; // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
33
- // Command to add a column before the column with the selection.
30
+ };
34
31
 
32
+ // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
33
+ // Command to add a column before the column with the selection.
35
34
  export const addColumnBefore = (state, dispatch) => {
36
35
  if (!isInTable(state)) {
37
36
  return false;
38
37
  }
39
-
40
38
  if (dispatch) {
41
39
  const rect = selectedRect(state);
42
40
  dispatch(addColumn(state.tr, rect, rect.left));
43
41
  }
44
-
45
42
  return true;
46
- }; // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
47
- // Command to add a column after the column with the selection.
43
+ };
48
44
 
45
+ // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
46
+ // Command to add a column after the column with the selection.
49
47
  export const addColumnAfter = (state, dispatch) => {
50
48
  if (!isInTable(state)) {
51
49
  return false;
52
50
  }
53
-
54
51
  if (dispatch) {
55
52
  const rect = selectedRect(state);
56
53
  dispatch(addColumn(state.tr, rect, rect.right));
57
54
  }
58
-
59
55
  return true;
60
56
  };
@@ -10,35 +10,31 @@ export function isHeaderEnabledByType(type, rect, types) {
10
10
  right: type === 'row' ? rect.map.width : 1,
11
11
  bottom: type === 'column' ? rect.map.height : 1
12
12
  });
13
-
14
13
  for (let i = 0; i < cellPositions.length; i++) {
15
14
  const cell = rect.table.nodeAt(cellPositions[i]);
16
-
17
15
  if (cell && cell.type !== types.header_cell) {
18
16
  return false;
19
17
  }
20
18
  }
21
-
22
19
  return true;
23
- } // Toggles between row/column header and normal cells (Only applies to first row/column).
20
+ }
24
21
 
22
+ // Toggles between row/column header and normal cells (Only applies to first row/column).
25
23
  export function toggleHeader(type) {
26
24
  return function (state, dispatch) {
27
25
  if (!isInTable(state)) {
28
26
  return false;
29
27
  }
30
-
31
28
  if (dispatch) {
32
29
  let types = tableNodeTypes(state.schema);
33
30
  let rect = selectedRect(state),
34
- tr = state.tr;
31
+ tr = state.tr;
35
32
  let isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
36
33
  let isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
37
34
  let isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
38
35
  let selectionStartsAt = isHeaderEnabled ? 1 : 0;
39
36
  const cellsRect = type === 'column' ? new Rect(0, selectionStartsAt, 1, rect.map.height) : type === 'row' ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect;
40
37
  let newType;
41
-
42
38
  if (type === 'column') {
43
39
  newType = isHeaderColumnEnabled ? types.cell : types.header_cell;
44
40
  } else if (type === 'row') {
@@ -46,18 +42,15 @@ export function toggleHeader(type) {
46
42
  } else {
47
43
  newType = types.cell;
48
44
  }
49
-
50
45
  rect.map.cellsInRect(cellsRect).forEach(relativeCellPos => {
51
46
  const cellPos = relativeCellPos + rect.tableStart;
52
47
  const cell = tr.doc.nodeAt(cellPos);
53
-
54
48
  if (cell) {
55
49
  tr.setNodeMarkup(cellPos, newType, cell.attrs);
56
50
  }
57
51
  });
58
52
  dispatch(tr);
59
53
  }
60
-
61
54
  return true;
62
55
  };
63
56
  }
@@ -15,9 +15,7 @@ export const uuid = {
15
15
  setStatic(value) {
16
16
  staticValue = value;
17
17
  },
18
-
19
18
  generate() {
20
19
  return staticValue || generateUuid();
21
20
  }
22
-
23
21
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "sideEffects": false
5
5
  }
@@ -5,11 +5,9 @@ import { inSameTable } from './utils/tables';
5
5
  export var CellBookmark = /*#__PURE__*/function () {
6
6
  function CellBookmark(anchor, head) {
7
7
  _classCallCheck(this, CellBookmark);
8
-
9
8
  this.anchor = anchor;
10
9
  this.head = head;
11
10
  }
12
-
13
11
  _createClass(CellBookmark, [{
14
12
  key: "map",
15
13
  value: function map(mapping) {
@@ -20,7 +18,6 @@ export var CellBookmark = /*#__PURE__*/function () {
20
18
  value: function resolve(doc) {
21
19
  var $anchorCell = doc.resolve(this.anchor);
22
20
  var $headCell = doc.resolve(this.head);
23
-
24
21
  if ($anchorCell.parent.type.spec.tableRole === 'row' && $headCell.parent.type.spec.tableRole === 'row' && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) {
25
22
  var data = {
26
23
  type: 'cell',
@@ -29,10 +26,8 @@ export var CellBookmark = /*#__PURE__*/function () {
29
26
  };
30
27
  return Selection.fromJSON(doc, data);
31
28
  }
32
-
33
29
  return Selection.near($headCell, 1);
34
30
  }
35
31
  }]);
36
-
37
32
  return CellBookmark;
38
33
  }();