@atlaskit/editor-plugin-table 0.1.0 → 0.1.1

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 (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +2 -11
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -9,173 +9,175 @@ import { AddColumnStep } from '@atlaskit/adf-schema/steps';
9
9
  import { setMeta } from './metadata';
10
10
  import { splitCellsInColumns } from './split';
11
11
 
12
- const deleteColumnsCustomStep = (rect: Rect) => (
13
- tr: Transaction,
14
- ): Transaction => {
15
- const table = findTable(tr.selection);
16
- if (!table) {
17
- return tr;
18
- }
19
-
20
- // Need to split all the merge in the ranges (this is the current behaviour)
21
- // Maybe is better to split only the last column?
22
- // TODO: After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
23
- splitCellsInColumns(tr, table.pos, rect.left, rect.right);
24
-
25
- // Delete the columns
26
- let mapStart = tr.mapping.maps.length;
27
- const originalDoc = tr.doc;
28
- const deletedColumns = [];
29
- for (let i = rect.left; i < rect.right; i++) {
30
- const step = AddColumnStep.create(originalDoc, table.pos, i, true);
31
- deletedColumns.push(i);
32
- tr.step(step.map(tr.mapping.slice(mapStart))!);
33
- }
12
+ const deleteColumnsCustomStep =
13
+ (rect: Rect) =>
14
+ (tr: Transaction): Transaction => {
15
+ const table = findTable(tr.selection);
16
+ if (!table) {
17
+ return tr;
18
+ }
34
19
 
35
- const tablePosResult = tr.mapping.mapResult(table.pos);
36
- if (tablePosResult.deleted) {
37
- const pos = Math.min(tablePosResult.pos, tr.doc.nodeSize - 1);
38
- tr.setSelection(Selection.near(tr.doc.resolve(pos)));
39
- } else {
40
- const newTable = tr.doc.nodeAt(tablePosResult.pos);
41
- if (newTable) {
42
- const cursorPos = getNextCursorPos(newTable, deletedColumns);
43
- tr.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)));
20
+ // Need to split all the merge in the ranges (this is the current behaviour)
21
+ // Maybe is better to split only the last column?
22
+ // TODO: After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
23
+ splitCellsInColumns(tr, table.pos, rect.left, rect.right);
24
+
25
+ // Delete the columns
26
+ let mapStart = tr.mapping.maps.length;
27
+ const originalDoc = tr.doc;
28
+ const deletedColumns = [];
29
+ for (let i = rect.left; i < rect.right; i++) {
30
+ const step = AddColumnStep.create(originalDoc, table.pos, i, true);
31
+ deletedColumns.push(i);
32
+ tr.step(step.map(tr.mapping.slice(mapStart))!);
44
33
  }
45
- }
46
34
 
47
- return tr;
48
- };
35
+ const tablePosResult = tr.mapping.mapResult(table.pos);
36
+ if (tablePosResult.deleted) {
37
+ const pos = Math.min(tablePosResult.pos, tr.doc.nodeSize - 1);
38
+ tr.setSelection(Selection.near(tr.doc.resolve(pos)));
39
+ } else {
40
+ const newTable = tr.doc.nodeAt(tablePosResult.pos);
41
+ if (newTable) {
42
+ const cursorPos = getNextCursorPos(newTable, deletedColumns);
43
+ tr.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)));
44
+ }
45
+ }
49
46
 
50
- const deleteColumnsLegacy = (rect: Rect) => (tr: Transaction): Transaction => {
51
- const table = findTable(tr.selection);
52
- if (!table) {
53
47
  return tr;
54
- }
48
+ };
49
+
50
+ const deleteColumnsLegacy =
51
+ (rect: Rect) =>
52
+ (tr: Transaction): Transaction => {
53
+ const table = findTable(tr.selection);
54
+ if (!table) {
55
+ return tr;
56
+ }
55
57
 
56
- const columnsToDelete: number[] = [];
57
- for (let i = rect.left; i < rect.right; i++) {
58
- columnsToDelete.push(i);
59
- }
58
+ const columnsToDelete: number[] = [];
59
+ for (let i = rect.left; i < rect.right; i++) {
60
+ columnsToDelete.push(i);
61
+ }
60
62
 
61
- if (!columnsToDelete.length) {
62
- return tr;
63
- }
63
+ if (!columnsToDelete.length) {
64
+ return tr;
65
+ }
64
66
 
65
- const map = TableMap.get(table.node);
66
- const rows: PMNode[] = [];
67
- const seen: { [key: string]: boolean } = {};
68
- const deletedCells: { [key: string]: boolean } = {};
67
+ const map = TableMap.get(table.node);
68
+ const rows: PMNode[] = [];
69
+ const seen: { [key: string]: boolean } = {};
70
+ const deletedCells: { [key: string]: boolean } = {};
69
71
 
70
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
71
- const rowCells: PMNode[] = [];
72
- const row = table.node.child(rowIndex);
73
-
74
- for (let colIndex = 0; colIndex < map.width; colIndex++) {
75
- const cellPos = map.map[rowIndex * map.width + colIndex];
76
- const cell = table.node.nodeAt(cellPos);
77
- if (!cell) {
78
- continue;
79
- }
80
- const cellsInColumn = map.cellsInRect({
81
- left: colIndex,
82
- top: 0,
83
- right: colIndex + 1,
84
- bottom: map.height,
85
- });
86
- if (columnsToDelete.indexOf(colIndex) === -1) {
87
- // decrement colspans for col-spanning cells that overlap deleted columns
88
- if (cellsInColumn.indexOf(cellPos) > -1 && !seen[cellPos]) {
89
- let overlappingCols = 0;
90
- columnsToDelete.forEach((colIndexToDelete) => {
91
- if (
92
- colIndex < colIndexToDelete &&
93
- cell.attrs.colspan + colIndex - 1 >= colIndexToDelete
94
- ) {
95
- overlappingCols += 1;
72
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
73
+ const rowCells: PMNode[] = [];
74
+ const row = table.node.child(rowIndex);
75
+
76
+ for (let colIndex = 0; colIndex < map.width; colIndex++) {
77
+ const cellPos = map.map[rowIndex * map.width + colIndex];
78
+ const cell = table.node.nodeAt(cellPos);
79
+ if (!cell) {
80
+ continue;
81
+ }
82
+ const cellsInColumn = map.cellsInRect({
83
+ left: colIndex,
84
+ top: 0,
85
+ right: colIndex + 1,
86
+ bottom: map.height,
87
+ });
88
+ if (columnsToDelete.indexOf(colIndex) === -1) {
89
+ // decrement colspans for col-spanning cells that overlap deleted columns
90
+ if (cellsInColumn.indexOf(cellPos) > -1 && !seen[cellPos]) {
91
+ let overlappingCols = 0;
92
+ columnsToDelete.forEach((colIndexToDelete) => {
93
+ if (
94
+ colIndex < colIndexToDelete &&
95
+ cell.attrs.colspan + colIndex - 1 >= colIndexToDelete
96
+ ) {
97
+ overlappingCols += 1;
98
+ }
99
+ });
100
+ if (overlappingCols > 0) {
101
+ const attrs: CellAttributes = {
102
+ ...cell.attrs,
103
+ colspan: cell.attrs.colspan - overlappingCols,
104
+ };
105
+ if (cell.attrs.colwidth) {
106
+ const minColIndex = Math.min(...columnsToDelete);
107
+ const pos =
108
+ minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
109
+ const colwidth = cell.attrs.colwidth.slice() || [];
110
+ colwidth.splice(pos, overlappingCols);
111
+ attrs.colwidth = colwidth;
112
+ }
113
+ const newCell = cell.type.createChecked(
114
+ attrs,
115
+ cell.content,
116
+ cell.marks,
117
+ );
118
+ rowCells.push(newCell);
119
+ seen[cellPos] = true;
120
+ continue;
96
121
  }
97
- });
98
- if (overlappingCols > 0) {
122
+ } else if (deletedCells[cellPos]) {
123
+ // if we're removing a col-spanning cell, we need to add missing cells to columns to the right
99
124
  const attrs: CellAttributes = {
100
125
  ...cell.attrs,
101
- colspan: cell.attrs.colspan - overlappingCols,
126
+ colspan: 1,
127
+ rowspan: 1,
102
128
  };
103
129
  if (cell.attrs.colwidth) {
104
- const minColIndex = Math.min(...columnsToDelete);
105
- const pos =
106
- minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
107
- const colwidth = cell.attrs.colwidth.slice() || [];
108
- colwidth.splice(pos, overlappingCols);
109
- attrs.colwidth = colwidth;
130
+ const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
131
+ attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
110
132
  }
111
133
  const newCell = cell.type.createChecked(
112
134
  attrs,
113
- cell.content,
135
+ cell.type.schema.nodes.paragraph.createChecked(),
114
136
  cell.marks,
115
137
  );
116
138
  rowCells.push(newCell);
117
- seen[cellPos] = true;
118
139
  continue;
119
140
  }
120
- } else if (deletedCells[cellPos]) {
121
- // if we're removing a col-spanning cell, we need to add missing cells to columns to the right
122
- const attrs: CellAttributes = {
123
- ...cell.attrs,
124
- colspan: 1,
125
- rowspan: 1,
126
- };
127
- if (cell.attrs.colwidth) {
128
- const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
129
- attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
141
+
142
+ // normal cells that we want to keep
143
+ if (!seen[cellPos]) {
144
+ seen[cellPos] = true;
145
+ rowCells.push(cell);
130
146
  }
131
- const newCell = cell.type.createChecked(
132
- attrs,
133
- cell.type.schema.nodes.paragraph.createChecked(),
134
- cell.marks,
135
- );
136
- rowCells.push(newCell);
137
- continue;
147
+ } else if (cellsInColumn.indexOf(cellPos) > -1) {
148
+ deletedCells[cellPos] = true;
138
149
  }
150
+ }
139
151
 
140
- // normal cells that we want to keep
141
- if (!seen[cellPos]) {
142
- seen[cellPos] = true;
143
- rowCells.push(cell);
144
- }
145
- } else if (cellsInColumn.indexOf(cellPos) > -1) {
146
- deletedCells[cellPos] = true;
152
+ if (rowCells.length) {
153
+ rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
147
154
  }
148
155
  }
149
156
 
150
- if (rowCells.length) {
151
- rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
157
+ if (!rows.length) {
158
+ return setMeta({ type: 'DELETE_COLUMNS', problem: 'EMPTY_TABLE' })(tr);
152
159
  }
153
- }
154
-
155
- if (!rows.length) {
156
- return setMeta({ type: 'DELETE_COLUMNS', problem: 'EMPTY_TABLE' })(tr);
157
- }
158
160
 
159
- const newTable = table.node.type.createChecked(
160
- table.node.attrs,
161
- rows,
162
- table.node.marks,
163
- );
161
+ const newTable = table.node.type.createChecked(
162
+ table.node.attrs,
163
+ rows,
164
+ table.node.marks,
165
+ );
164
166
 
165
- const fixedTable = fixRowSpans(newTable);
166
- if (fixedTable === null) {
167
- return setMeta({ type: 'DELETE_COLUMNS', problem: 'FIX_ROWSPANS' })(tr);
168
- }
167
+ const fixedTable = fixRowSpans(newTable);
168
+ if (fixedTable === null) {
169
+ return setMeta({ type: 'DELETE_COLUMNS', problem: 'FIX_ROWSPANS' })(tr);
170
+ }
169
171
 
170
- const cursorPos = getNextCursorPos(newTable, columnsToDelete);
172
+ const cursorPos = getNextCursorPos(newTable, columnsToDelete);
171
173
 
172
- return setMeta({ type: 'DELETE_COLUMNS' })(
173
- tr
174
- .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
175
- // move cursor to the left of the deleted columns if possible, otherwise - to the first column
176
- .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
177
- );
178
- };
174
+ return setMeta({ type: 'DELETE_COLUMNS' })(
175
+ tr
176
+ .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
177
+ // move cursor to the left of the deleted columns if possible, otherwise - to the first column
178
+ .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
179
+ );
180
+ };
179
181
 
180
182
  function getNextCursorPos(table: PMNode, deletedColumns: number[]): number {
181
183
  const minColumn = Math.min(...deletedColumns);
@@ -241,11 +243,11 @@ function fixRowSpans(table: PMNode): PMNode | null {
241
243
  return table.type.createChecked(table.attrs, rows, table.marks);
242
244
  }
243
245
 
244
- export const deleteColumns = (rect: Rect, allowAddColumnCustomStep = false) => (
245
- tr: Transaction,
246
- ): Transaction => {
247
- if (allowAddColumnCustomStep) {
248
- return deleteColumnsCustomStep(rect)(tr);
249
- }
250
- return deleteColumnsLegacy(rect)(tr);
251
- };
246
+ export const deleteColumns =
247
+ (rect: Rect, allowAddColumnCustomStep = false) =>
248
+ (tr: Transaction): Transaction => {
249
+ if (allowAddColumnCustomStep) {
250
+ return deleteColumnsCustomStep(rect)(tr);
251
+ }
252
+ return deleteColumnsLegacy(rect)(tr);
253
+ };
@@ -8,139 +8,138 @@ import { CellAttributes } from '@atlaskit/adf-schema';
8
8
  import { removeEmptyColumns } from './merge';
9
9
  import { setMeta } from './metadata';
10
10
 
11
- export const deleteRows = (
12
- rect: Rect,
13
- isHeaderRowRequired: boolean = false,
14
- ) => (tr: Transaction): Transaction => {
15
- const table = findTable(tr.selection);
16
- if (!table) {
17
- return tr;
18
- }
19
-
20
- const rowsToDelete: number[] = [];
21
-
22
- const map = TableMap.get(table.node);
23
-
24
- for (let i = rect.top; i < rect.bottom; i++) {
25
- // skip header row if its required
26
- if (isHeaderRowRequired) {
27
- const cell = table.node.nodeAt(map.map[i * map.width]);
28
- if (cell && cell.type !== cell.type.schema.nodes.tableHeader) {
11
+ export const deleteRows =
12
+ (rect: Rect, isHeaderRowRequired: boolean = false) =>
13
+ (tr: Transaction): Transaction => {
14
+ const table = findTable(tr.selection);
15
+ if (!table) {
16
+ return tr;
17
+ }
18
+
19
+ const rowsToDelete: number[] = [];
20
+
21
+ const map = TableMap.get(table.node);
22
+
23
+ for (let i = rect.top; i < rect.bottom; i++) {
24
+ // skip header row if its required
25
+ if (isHeaderRowRequired) {
26
+ const cell = table.node.nodeAt(map.map[i * map.width]);
27
+ if (cell && cell.type !== cell.type.schema.nodes.tableHeader) {
28
+ rowsToDelete.push(i);
29
+ }
30
+ } else {
29
31
  rowsToDelete.push(i);
30
32
  }
31
- } else {
32
- rowsToDelete.push(i);
33
33
  }
34
- }
35
34
 
36
- if (!rowsToDelete.length) {
37
- return tr;
38
- }
35
+ if (!rowsToDelete.length) {
36
+ return tr;
37
+ }
39
38
 
40
- const rows: PMNode[] = [];
41
- const seen: { [key: string]: boolean } = {};
42
- const deletedCells: { [key: string]: boolean } = {};
39
+ const rows: PMNode[] = [];
40
+ const seen: { [key: string]: boolean } = {};
41
+ const deletedCells: { [key: string]: boolean } = {};
43
42
 
44
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
45
- const rowCells: PMNode[] = [];
46
- const row = table.node.child(rowIndex);
43
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
44
+ const rowCells: PMNode[] = [];
45
+ const row = table.node.child(rowIndex);
47
46
 
48
- for (let colIndex = 0; colIndex < map.width; colIndex++) {
49
- const cellPos = map.map[rowIndex * map.width + colIndex];
50
- const cell = table.node.nodeAt(cellPos);
51
- if (!cell) {
52
- continue;
53
- }
54
- const cellsInRow = map.cellsInRect({
55
- left: 0,
56
- top: rowIndex,
57
- right: map.width,
58
- bottom: rowIndex + 1,
59
- });
60
- if (rowsToDelete.indexOf(rowIndex) === -1 && !seen[cellPos]) {
61
- // decrement rowspans for row-spanning cells that overlap deleted rows
62
- if (cellsInRow.indexOf(cellPos) > -1) {
63
- let overlappingRows = 0;
64
- rowsToDelete.forEach((rowIndexToDelete) => {
65
- if (
66
- rowIndex < rowIndexToDelete &&
67
- cell.attrs.rowspan + rowIndex - 1 >= rowIndexToDelete
68
- ) {
69
- overlappingRows += 1;
47
+ for (let colIndex = 0; colIndex < map.width; colIndex++) {
48
+ const cellPos = map.map[rowIndex * map.width + colIndex];
49
+ const cell = table.node.nodeAt(cellPos);
50
+ if (!cell) {
51
+ continue;
52
+ }
53
+ const cellsInRow = map.cellsInRect({
54
+ left: 0,
55
+ top: rowIndex,
56
+ right: map.width,
57
+ bottom: rowIndex + 1,
58
+ });
59
+ if (rowsToDelete.indexOf(rowIndex) === -1 && !seen[cellPos]) {
60
+ // decrement rowspans for row-spanning cells that overlap deleted rows
61
+ if (cellsInRow.indexOf(cellPos) > -1) {
62
+ let overlappingRows = 0;
63
+ rowsToDelete.forEach((rowIndexToDelete) => {
64
+ if (
65
+ rowIndex < rowIndexToDelete &&
66
+ cell.attrs.rowspan + rowIndex - 1 >= rowIndexToDelete
67
+ ) {
68
+ overlappingRows += 1;
69
+ }
70
+ });
71
+ if (overlappingRows > 0) {
72
+ const newCell = cell.type.createChecked(
73
+ {
74
+ ...cell.attrs,
75
+ rowspan: cell.attrs.rowspan - overlappingRows,
76
+ },
77
+ cell.content,
78
+ cell.marks,
79
+ );
80
+ rowCells.push(newCell);
81
+ seen[cellPos] = true;
82
+ continue;
83
+ }
84
+ } else if (deletedCells[cellPos]) {
85
+ // if we're removing a row-spanning cell, we need to add missing cells to rows below
86
+ const attrs: CellAttributes = {
87
+ ...cell.attrs,
88
+ colspan: 1,
89
+ rowspan: 1,
90
+ };
91
+ if (cell.attrs.colwidth) {
92
+ const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
93
+ attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
70
94
  }
71
- });
72
- if (overlappingRows > 0) {
73
95
  const newCell = cell.type.createChecked(
74
- {
75
- ...cell.attrs,
76
- rowspan: cell.attrs.rowspan - overlappingRows,
77
- },
78
- cell.content,
96
+ attrs,
97
+ cell.type.schema.nodes.paragraph.createChecked(),
79
98
  cell.marks,
80
99
  );
81
100
  rowCells.push(newCell);
82
- seen[cellPos] = true;
83
101
  continue;
84
102
  }
85
- } else if (deletedCells[cellPos]) {
86
- // if we're removing a row-spanning cell, we need to add missing cells to rows below
87
- const attrs: CellAttributes = {
88
- ...cell.attrs,
89
- colspan: 1,
90
- rowspan: 1,
91
- };
92
- if (cell.attrs.colwidth) {
93
- const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
94
- attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
103
+
104
+ // normal cells that we want to keep
105
+ if (!seen[cellPos]) {
106
+ seen[cellPos] = true;
107
+ rowCells.push(cell);
95
108
  }
96
- const newCell = cell.type.createChecked(
97
- attrs,
98
- cell.type.schema.nodes.paragraph.createChecked(),
99
- cell.marks,
100
- );
101
- rowCells.push(newCell);
102
- continue;
109
+ } else if (cellsInRow.indexOf(cellPos) > -1) {
110
+ deletedCells[cellPos] = true;
103
111
  }
112
+ }
104
113
 
105
- // normal cells that we want to keep
106
- if (!seen[cellPos]) {
107
- seen[cellPos] = true;
108
- rowCells.push(cell);
109
- }
110
- } else if (cellsInRow.indexOf(cellPos) > -1) {
111
- deletedCells[cellPos] = true;
114
+ if (rowCells.length) {
115
+ rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
112
116
  }
113
117
  }
114
118
 
115
- if (rowCells.length) {
116
- rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
119
+ if (!rows.length) {
120
+ return setMeta({ type: 'DELETE_ROWS', problem: 'EMPTY_TABLE' })(tr);
117
121
  }
118
- }
119
-
120
- if (!rows.length) {
121
- return setMeta({ type: 'DELETE_ROWS', problem: 'EMPTY_TABLE' })(tr);
122
- }
123
-
124
- const newTable = table.node.type.createChecked(
125
- table.node.attrs,
126
- rows,
127
- table.node.marks,
128
- );
129
- const fixedTable = removeEmptyColumns(newTable);
130
- if (fixedTable === null) {
131
- return setMeta({ type: 'DELETE_ROWS', problem: 'REMOVE_EMPTY_COLUMNS' })(
132
- tr,
122
+
123
+ const newTable = table.node.type.createChecked(
124
+ table.node.attrs,
125
+ rows,
126
+ table.node.marks,
127
+ );
128
+ const fixedTable = removeEmptyColumns(newTable);
129
+ if (fixedTable === null) {
130
+ return setMeta({ type: 'DELETE_ROWS', problem: 'REMOVE_EMPTY_COLUMNS' })(
131
+ tr,
132
+ );
133
+ }
134
+ const cursorPos = getNextCursorPos(newTable, rowsToDelete);
135
+
136
+ return setMeta({ type: 'DELETE_ROWS' })(
137
+ tr
138
+ .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
139
+ // move cursor before the deleted rows if possible, otherwise - to the first row
140
+ .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
133
141
  );
134
- }
135
- const cursorPos = getNextCursorPos(newTable, rowsToDelete);
136
-
137
- return setMeta({ type: 'DELETE_ROWS' })(
138
- tr
139
- .replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
140
- // move cursor before the deleted rows if possible, otherwise - to the first row
141
- .setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))),
142
- );
143
- };
142
+ };
144
143
 
145
144
  function getNextCursorPos(table: PMNode, deletedRows: number[]): number {
146
145
  const minRow = Math.min(...deletedRows);
@@ -24,12 +24,12 @@ export type TableMetaData =
24
24
  problem?: TableProblems;
25
25
  };
26
26
 
27
- export const setMeta = (meta: TableMetaData) => (
28
- tr: Transaction,
29
- ): Transaction => {
30
- if ('problem' in meta) {
31
- // Send analytics event whenever we encounter with a problem
32
- fireAnalytics(meta);
33
- }
34
- return tr.setMeta(pluginKey, meta);
35
- };
27
+ export const setMeta =
28
+ (meta: TableMetaData) =>
29
+ (tr: Transaction): Transaction => {
30
+ if ('problem' in meta) {
31
+ // Send analytics event whenever we encounter with a problem
32
+ fireAnalytics(meta);
33
+ }
34
+ return tr.setMeta(pluginKey, meta);
35
+ };
@@ -377,12 +377,13 @@ export class ContextualMenu extends Component<
377
377
  this.toggleOpen();
378
378
  break;
379
379
  case 'distribute_columns':
380
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
381
- selectionRect,
382
- state,
383
- editorView.domAtPos.bind(editorView),
384
- getEditorContainerWidth,
385
- );
380
+ const newResizeStateWithAnalytics =
381
+ getNewResizeStateFromSelectedColumns(
382
+ selectionRect,
383
+ state,
384
+ editorView.domAtPos.bind(editorView),
385
+ getEditorContainerWidth,
386
+ );
386
387
 
387
388
  if (newResizeStateWithAnalytics) {
388
389
  distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
@@ -1,4 +1,4 @@
1
- import React, { Component } from 'react';
1
+ import React, { Component, SyntheticEvent } from 'react';
2
2
 
3
3
  import { Selection } from 'prosemirror-state';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -263,7 +263,8 @@ class FloatingDeleteButton extends Component<Props, State> {
263
263
  * @private
264
264
  * @memberof FloatingDeleteButton
265
265
  */
266
- private handleClick = () => {
266
+ private handleClick = (event: SyntheticEvent) => {
267
+ event.preventDefault();
267
268
  const { editorAnalyticsAPI } = this.props;
268
269
  let { state, dispatch } = this.props.editorView;
269
270
  const {
@@ -202,11 +202,8 @@ export class FloatingInsertButton extends React.Component<
202
202
  }
203
203
 
204
204
  private getCellPosition(type: 'column' | 'row'): number | null {
205
- const {
206
- tableNode,
207
- insertColumnButtonIndex,
208
- insertRowButtonIndex,
209
- } = this.props;
205
+ const { tableNode, insertColumnButtonIndex, insertRowButtonIndex } =
206
+ this.props;
210
207
  const tableMap = TableMap.get(tableNode!);
211
208
 
212
209
  if (type === 'column') {