@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
@@ -1,9 +1,10 @@
1
- import { TableMap } from '../table-map'; // array = [
1
+ import { TableMap } from '../table-map';
2
+
3
+ // array = [
2
4
  // [A1, B1, C1, null],
3
5
  // [A2, B2, null, D1],
4
6
  // [A3. B3, C2, null],
5
7
  // ]
6
-
7
8
  // This function transposes an array of array flipping the columns for rows,
8
9
  // transposition is a familiar algebra concept;
9
10
  // you can get more details here:
@@ -32,7 +33,9 @@ export var transpose = function transpose(array) {
32
33
  return column[i];
33
34
  });
34
35
  });
35
- }; // :: (tableNode: Node, tableArray: Array<Node>) -> Node
36
+ };
37
+
38
+ // :: (tableNode: Node, tableArray: Array<Node>) -> Node
36
39
  // This function will transform a matrix of nodes
37
40
  // into table node respecting merged cells and rows configurations,
38
41
  // for example this array will be convert to the table below:
@@ -58,57 +61,49 @@ export var transpose = function transpose(array) {
58
61
  // |______|______|______|______|
59
62
  // ```
60
63
  //
61
-
62
64
  export var convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
63
65
  var rowsPM = [];
64
66
  var map = TableMap.get(tableNode);
65
-
66
67
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
67
68
  var row = tableNode.child(rowIndex);
68
69
  var rowCells = [];
69
-
70
70
  for (var colIndex = 0; colIndex < map.width; colIndex++) {
71
71
  if (!arrayOfNodes[rowIndex][colIndex]) {
72
72
  continue;
73
73
  }
74
-
75
74
  var cellPos = map.map[rowIndex * map.width + colIndex];
76
75
  var cell = arrayOfNodes[rowIndex][colIndex];
77
76
  var oldCell = tableNode.nodeAt(cellPos);
78
-
79
77
  if (!cell || !oldCell) {
80
78
  continue;
81
79
  }
82
-
83
80
  var newCell = oldCell.type.createChecked(Object.assign({}, cell.attrs), cell.content, cell.marks);
84
81
  rowCells.push(newCell);
85
82
  }
86
-
87
83
  rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks));
88
84
  }
89
-
90
85
  var newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
91
86
  return newTable;
92
87
  };
93
-
94
88
  var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOrigin, indexesTarget, directionOverride) {
95
89
  var direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
96
90
  var rowsExtracted = arrayOfNodes.splice(indexesOrigin[0], indexesOrigin.length);
97
91
  var positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
98
92
  var target;
99
-
100
93
  if (directionOverride === -1 && direction === 1) {
101
94
  target = indexesTarget[0] - 1;
102
95
  } else if (directionOverride === 1 && direction === -1) {
103
96
  target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1;
104
97
  } else {
105
98
  target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;
106
- } // @ts-ignore no idea what this line does
107
-
99
+ }
108
100
 
101
+ // @ts-ignore no idea what this line does
109
102
  arrayOfNodes.splice.apply(arrayOfNodes, [target, 0].concat(rowsExtracted));
110
103
  return arrayOfNodes;
111
- }; // :: (tableNode: Node) -> Array<Node>
104
+ };
105
+
106
+ // :: (tableNode: Node) -> Array<Node>
112
107
  // This function will transform the table node
113
108
  // into a matrix of rows and columns respecting merged cells,
114
109
  // for example this table will be convert to the below:
@@ -134,33 +129,25 @@ var moveRowInArrayOfRows = function moveRowInArrayOfRows(arrayOfNodes, indexesOr
134
129
  // [A3. B3, C2, null],
135
130
  // ]
136
131
  // ```
137
-
138
-
139
132
  export var convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRows(tableNode) {
140
133
  var map = TableMap.get(tableNode);
141
134
  var rows = [];
142
-
143
135
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
144
136
  var rowCells = [];
145
137
  var seen = {};
146
-
147
138
  for (var colIndex = 0; colIndex < map.width; colIndex++) {
148
139
  var cellPos = map.map[rowIndex * map.width + colIndex];
149
140
  var cell = tableNode.nodeAt(cellPos);
150
141
  var rect = map.findCell(cellPos);
151
-
152
142
  if (!cell || seen[cellPos] || rect.top !== rowIndex) {
153
143
  rowCells.push(null);
154
144
  continue;
155
145
  }
156
-
157
146
  seen[cellPos] = true;
158
147
  rowCells.push(cell);
159
148
  }
160
-
161
149
  rows.push(rowCells);
162
150
  }
163
-
164
151
  return rows;
165
152
  };
166
153
  export var moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) {
@@ -177,7 +164,6 @@ export var moveTableColumn = function moveTableColumn(table, indexesOrigin, inde
177
164
  export var isValidReorder = function isValidReorder(originIndex, targetIndex, targets, type) {
178
165
  var direction = originIndex > targetIndex ? -1 : 1;
179
166
  var errorMessage = "Target position is invalid, you can't move the ".concat(type, " ").concat(originIndex, " to ").concat(targetIndex, ", the target can't be split. You could use tryToFit option.");
180
-
181
167
  if (direction === 1) {
182
168
  if (targets.slice(0, targets.length - 1).indexOf(targetIndex) !== -1) {
183
169
  throw new Error(errorMessage);
@@ -187,6 +173,5 @@ export var isValidReorder = function isValidReorder(originIndex, targetIndex, ta
187
173
  throw new Error(errorMessage);
188
174
  }
189
175
  }
190
-
191
176
  return true;
192
177
  };
@@ -5,7 +5,6 @@ import { isTableSelected } from './is-selected';
5
5
  export var replaceSelectedTable = function replaceSelectedTable(state, content) {
6
6
  if (isTableSelected(state.selection)) {
7
7
  var table = findTable(state.selection);
8
-
9
8
  if (table) {
10
9
  var slice = typeof content === 'string' ? new Slice(Fragment.from(state.schema.text(content)), 0, 0) : content;
11
10
  var tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
@@ -13,6 +12,5 @@ export var replaceSelectedTable = function replaceSelectedTable(state, content)
13
12
  return tr;
14
13
  }
15
14
  }
16
-
17
15
  return state.tr;
18
16
  };
@@ -2,31 +2,26 @@ 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
  var select = function select(type) {
7
6
  return function (index, expand) {
8
7
  return function (tr) {
9
8
  var table = findTable(tr.selection);
10
9
  var isRowSelection = type === 'row';
11
-
12
10
  if (table) {
13
- var map = TableMap.get(table.node); // Check if the index is valid
11
+ var map = TableMap.get(table.node);
14
12
 
13
+ // Check if the index is valid
15
14
  if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
16
15
  var left = isRowSelection ? 0 : index;
17
16
  var top = isRowSelection ? index : 0;
18
17
  var right = isRowSelection ? map.width : index + 1;
19
18
  var bottom = isRowSelection ? index + 1 : map.height;
20
-
21
19
  if (expand) {
22
20
  var cell = findCellClosestToPos(tr.selection.$from);
23
-
24
21
  if (!cell) {
25
22
  return tr;
26
23
  }
27
-
28
24
  var selRect = map.findCell(cell.pos - table.start);
29
-
30
25
  if (isRowSelection) {
31
26
  top = Math.min(top, selRect.top);
32
27
  bottom = Math.max(bottom, selRect.bottom);
@@ -35,7 +30,6 @@ var select = function select(type) {
35
30
  right = Math.max(right, selRect.right);
36
31
  }
37
32
  }
38
-
39
33
  var cellsInFirstRow = map.cellsInRect({
40
34
  left: left,
41
35
  top: top,
@@ -55,26 +49,25 @@ var select = function select(type) {
55
49
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
56
50
  }
57
51
  }
58
-
59
52
  return tr;
60
53
  };
61
54
  };
62
- }; // Returns a new transaction that selects a column at index `columnIndex`.
63
- // Use the optional `expand` param to extend from current selection.
64
-
55
+ };
65
56
 
66
- export var selectColumn = select('column'); // Returns a new transaction that selects a row at index `rowIndex`.
57
+ // Returns a new transaction that selects a column at index `columnIndex`.
67
58
  // Use the optional `expand` param to extend from current selection.
59
+ export var selectColumn = select('column');
68
60
 
69
- export var selectRow = select('row'); // Returns a new transaction that selects a table.
61
+ // Returns a new transaction that selects a row at index `rowIndex`.
62
+ // Use the optional `expand` param to extend from current selection.
63
+ export var selectRow = select('row');
70
64
 
65
+ // Returns a new transaction that selects a table.
71
66
  export var selectTable = function selectTable(tr) {
72
67
  var table = findTable(tr.selection);
73
-
74
68
  if (table) {
75
69
  var _TableMap$get = TableMap.get(table.node),
76
- map = _TableMap$get.map;
77
-
70
+ map = _TableMap$get.map;
78
71
  if (map && map.length) {
79
72
  var head = table.start + map[0];
80
73
  var anchor = table.start + map[map.length - 1];
@@ -83,16 +76,13 @@ export var selectTable = function selectTable(tr) {
83
76
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
84
77
  }
85
78
  }
86
-
87
79
  return tr;
88
80
  };
89
81
  export var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
90
82
  var table = findTableClosestToPos($pos);
91
-
92
83
  if (table) {
93
84
  var _TableMap$get2 = TableMap.get(table.node),
94
- map = _TableMap$get2.map;
95
-
85
+ map = _TableMap$get2.map;
96
86
  if (map && map.length) {
97
87
  var head = table.start + map[0];
98
88
  var anchor = table.start + map[map.length - 1];
@@ -101,6 +91,5 @@ export var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos)
101
91
  return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
102
92
  }
103
93
  }
104
-
105
94
  return tr;
106
95
  };
@@ -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
  var sel = state.selection;
9
9
  var $pos = selectionCell(sel);
10
-
11
10
  if (!$pos) {
12
11
  throw new Error("selectedRect: invalid $pos for selection");
13
12
  }
14
-
15
13
  var table = $pos.node(-1);
16
14
  var tableStart = $pos.start(-1);
17
15
  var map = TableMap.get(table);
18
16
  var 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,12 +1,12 @@
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 var setCellAttrs = function setCellAttrs(cell, attrs) {
4
5
  return function (tr) {
5
6
  if (cell) {
6
7
  tr.setNodeMarkup(cell.pos, undefined, Object.assign({}, cell.node.attrs, attrs));
7
8
  return cloneTr(tr);
8
9
  }
9
-
10
10
  return tr;
11
11
  };
12
12
  };
@@ -1,9 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
2
  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; }
4
-
5
3
  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) { _defineProperty(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; }
6
-
7
4
  import { ResolvedPos } from 'prosemirror-model';
8
5
  import { CellSelection } from '../cell-selection';
9
6
  import { cellAround } from './cells';
@@ -12,12 +9,10 @@ export function cellWrapping($pos) {
12
9
  for (var d = $pos.depth; d > 0; d--) {
13
10
  // Sometimes the cell can be in the same depth.
14
11
  var role = $pos.node(d).type.spec.tableRole;
15
-
16
12
  if (role === 'cell' || role === 'header_cell') {
17
13
  return $pos.node(d);
18
14
  }
19
15
  }
20
-
21
16
  return null;
22
17
  }
23
18
  // Split a selected cell, whose rowpan or colspan is greater than one,
@@ -26,81 +21,64 @@ export function splitCellWithType(getCellType) {
26
21
  return function (state, dispatch) {
27
22
  var sel = state.selection;
28
23
  var cellNode, cellPos;
29
-
30
24
  if (!(sel instanceof CellSelection)) {
31
25
  cellNode = cellWrapping(sel.$from);
32
-
33
26
  if (!cellNode) {
34
27
  return false;
35
28
  }
36
-
37
29
  var cellNodeAround = cellAround(sel.$from);
38
30
  cellPos = cellNodeAround && cellNodeAround.pos;
39
31
  } else {
40
32
  if (sel.$anchorCell.pos !== sel.$headCell.pos) {
41
33
  return false;
42
34
  }
43
-
44
35
  cellNode = sel.$anchorCell.nodeAfter;
45
36
  cellPos = sel.$anchorCell.pos;
46
37
  }
47
-
48
38
  if (cellNode && cellNode.attrs.colspan === 1 && cellNode.attrs.rowspan === 1) {
49
39
  return false;
50
40
  }
51
-
52
41
  if (cellNode && dispatch) {
53
42
  var cellAttrs = cellNode.attrs,
54
- attrs = [],
55
- colwidth = cellAttrs.colwidth;
56
-
43
+ attrs = [],
44
+ colwidth = cellAttrs.colwidth;
57
45
  if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
58
46
  cellAttrs = _objectSpread(_objectSpread({}, cellAttrs), {}, {
59
47
  rowspan: 1
60
48
  });
61
49
  }
62
-
63
50
  if (cellAttrs.colspan && cellAttrs.colspan > 1) {
64
51
  cellAttrs = _objectSpread(_objectSpread({}, cellAttrs), {}, {
65
52
  colspan: 1
66
53
  });
67
54
  }
68
-
69
55
  var rect = selectedRect(state);
70
56
  var tr = state.tr;
71
-
72
57
  for (var i = 0; i < rect.right - rect.left; i++) {
73
58
  attrs.push(colwidth ? _objectSpread(_objectSpread({}, cellAttrs), {}, {
74
59
  colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
75
60
  }) : cellAttrs);
76
61
  }
77
-
78
62
  var lastCell = null;
79
-
80
63
  for (var row = rect.top; row < rect.bottom; row++) {
81
64
  var pos = rect.map.positionAt(row, rect.left, rect.table);
82
-
83
65
  if (row === rect.top) {
84
66
  pos += cellNode.nodeSize;
85
67
  }
86
-
87
68
  for (var col = rect.left, _i = 0; col < rect.right; col++, _i++) {
88
69
  if (col === rect.left && row === rect.top) {
89
70
  continue;
90
71
  }
91
-
92
72
  var cellType = getCellType({
93
73
  node: cellNode,
94
74
  row: row,
95
75
  col: col
96
76
  }).createAndFill(attrs[_i]);
97
-
98
77
  if (cellType) {
99
78
  tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), cellType);
100
79
  }
101
80
  }
102
81
  }
103
-
104
82
  if (typeof cellPos === 'number') {
105
83
  tr.setNodeMarkup(cellPos, getCellType({
106
84
  node: cellNode,
@@ -108,16 +86,12 @@ export function splitCellWithType(getCellType) {
108
86
  col: rect.left
109
87
  }), attrs[0]);
110
88
  }
111
-
112
89
  var $lastCellPosition = lastCell && tr.doc.resolve(lastCell);
113
-
114
90
  if (sel instanceof CellSelection && $lastCellPosition instanceof ResolvedPos) {
115
91
  tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), $lastCellPosition));
116
92
  }
117
-
118
93
  dispatch(tr);
119
94
  }
120
-
121
95
  return true;
122
96
  };
123
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 var splitCell = function splitCell(state, dispatch) {
6
7
  var nodeTypes = tableNodeTypes(state.schema);
7
8
  return splitCellWithType(function (_ref) {
@@ -1,20 +1,17 @@
1
1
  export function tableNodeTypes(schema) {
2
2
  var 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 (var name in schema.nodes) {
10
9
  var type = schema.nodes[name];
11
10
  var 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
  }
@@ -1,12 +1,10 @@
1
1
  export function isInTable(state) {
2
2
  var $head = state.selection.$head;
3
-
4
3
  for (var d = $head.depth; d > 0; d--) {
5
4
  if ($head.node(d).type.spec.tableRole === 'row') {
6
5
  return true;
7
6
  }
8
7
  }
9
-
10
8
  return false;
11
9
  }
12
10
  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 var addRowBefore = function addRowBefore(state, dispatch) {
8
9
  if (!isInTable(state)) {
9
10
  return false;
10
11
  }
11
-
12
12
  if (dispatch) {
13
13
  var 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 var addRowAfter = function addRowAfter(state, dispatch) {
22
22
  if (!isInTable(state)) {
23
23
  return false;
24
24
  }
25
-
26
25
  if (dispatch) {
27
26
  var 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 var addColumnBefore = function addColumnBefore(state, dispatch) {
36
35
  if (!isInTable(state)) {
37
36
  return false;
38
37
  }
39
-
40
38
  if (dispatch) {
41
39
  var 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 var addColumnAfter = function addColumnAfter(state, dispatch) {
50
48
  if (!isInTable(state)) {
51
49
  return false;
52
50
  }
53
-
54
51
  if (dispatch) {
55
52
  var 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 (var i = 0; i < cellPositions.length; i++) {
15
14
  var 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
  var types = tableNodeTypes(state.schema);
33
30
  var rect = selectedRect(state),
34
- tr = state.tr;
31
+ tr = state.tr;
35
32
  var isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
36
33
  var isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
37
34
  var isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
38
35
  var selectionStartsAt = isHeaderEnabled ? 1 : 0;
39
36
  var cellsRect = type === 'column' ? new Rect(0, selectionStartsAt, 1, rect.map.height) : type === 'row' ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect;
40
37
  var 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(function (relativeCellPos) {
51
46
  var cellPos = relativeCellPos + rect.tableStart;
52
47
  var 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
  }
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "A package that contains common classes and utility functions for editor tables",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,8 +29,8 @@
29
29
  "prosemirror-view": "1.23.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@atlaskit/adf-schema": "^25.1.0",
33
- "@atlaskit/editor-test-helpers": "^18.0.0",
32
+ "@atlaskit/adf-schema": "^25.5.0",
33
+ "@atlaskit/editor-test-helpers": "^18.2.0",
34
34
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1"
35
35
  },
36
36
  "techstack": {
@@ -42,7 +42,9 @@
42
42
  },
43
43
  "@repo/internal": {
44
44
  "deprecation": "no-deprecated-imports",
45
- "theming": "tokens",
45
+ "design-tokens": [
46
+ "color"
47
+ ],
46
48
  "styling": [
47
49
  "emotion"
48
50
  ]