@atlaskit/editor-plugin-table 5.4.14 → 5.4.15

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 (111) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/afm-cc/tsconfig.json +70 -0
  3. package/dist/cjs/plugins/table/commands/hover.js +26 -6
  4. package/dist/cjs/plugins/table/commands/index.js +6 -0
  5. package/dist/cjs/plugins/table/commands/misc.js +8 -3
  6. package/dist/cjs/plugins/table/event-handlers.js +56 -34
  7. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +4 -1
  8. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +7 -6
  9. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +39 -7
  10. package/dist/cjs/plugins/table/pm-plugins/main.js +5 -3
  11. package/dist/cjs/plugins/table/reducer.js +1 -0
  12. package/dist/cjs/plugins/table/toolbar.js +6 -3
  13. package/dist/cjs/plugins/table/ui/ColumnResizeWidget/index.js +6 -3
  14. package/dist/cjs/plugins/table/ui/DragPreview/index.js +0 -2
  15. package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +10 -7
  16. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -10
  17. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/index.js +6 -3
  18. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +7 -4
  19. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -8
  20. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  21. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  22. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +12 -8
  23. package/dist/cjs/plugins/table/utils/dom.js +16 -1
  24. package/dist/cjs/plugins/table/utils/index.js +6 -0
  25. package/dist/es2019/plugins/table/commands/hover.js +22 -5
  26. package/dist/es2019/plugins/table/commands/index.js +1 -1
  27. package/dist/es2019/plugins/table/commands/misc.js +8 -3
  28. package/dist/es2019/plugins/table/event-handlers.js +45 -20
  29. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +4 -1
  30. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +7 -6
  31. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +36 -3
  32. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -4
  33. package/dist/es2019/plugins/table/reducer.js +1 -0
  34. package/dist/es2019/plugins/table/toolbar.js +5 -3
  35. package/dist/es2019/plugins/table/ui/ColumnResizeWidget/index.js +5 -3
  36. package/dist/es2019/plugins/table/ui/DragPreview/index.js +0 -2
  37. package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  38. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  39. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  40. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  41. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +14 -8
  42. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  43. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  44. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +12 -9
  45. package/dist/es2019/plugins/table/utils/dom.js +13 -0
  46. package/dist/es2019/plugins/table/utils/index.js +1 -1
  47. package/dist/esm/plugins/table/commands/hover.js +25 -5
  48. package/dist/esm/plugins/table/commands/index.js +1 -1
  49. package/dist/esm/plugins/table/commands/misc.js +8 -3
  50. package/dist/esm/plugins/table/event-handlers.js +55 -33
  51. package/dist/esm/plugins/table/nodeviews/TableComponent.js +4 -1
  52. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +7 -6
  53. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +35 -3
  54. package/dist/esm/plugins/table/pm-plugins/main.js +6 -4
  55. package/dist/esm/plugins/table/reducer.js +1 -0
  56. package/dist/esm/plugins/table/toolbar.js +5 -3
  57. package/dist/esm/plugins/table/ui/ColumnResizeWidget/index.js +5 -3
  58. package/dist/esm/plugins/table/ui/DragPreview/index.js +0 -2
  59. package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  60. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  61. package/dist/esm/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  62. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  63. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -8
  64. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  65. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  66. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +12 -8
  67. package/dist/esm/plugins/table/utils/dom.js +15 -0
  68. package/dist/esm/plugins/table/utils/index.js +1 -1
  69. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  70. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  71. package/dist/types/plugins/table/commands/misc.d.ts +1 -1
  72. package/dist/types/plugins/table/event-handlers.d.ts +2 -0
  73. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  74. package/dist/types/plugins/table/types.d.ts +6 -2
  75. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  76. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  77. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  78. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  79. package/dist/types/plugins/table/utils/dom.d.ts +4 -0
  80. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  81. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  82. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  83. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +1 -1
  84. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +2 -0
  85. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  86. package/dist/types-ts4.5/plugins/table/types.d.ts +6 -2
  87. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  88. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  89. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  90. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  91. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -0
  92. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  93. package/package.json +2 -2
  94. package/src/__tests__/unit/event-handlers.ts +2 -2
  95. package/src/__tests__/unit/ui/RowDragControls.tsx +1 -0
  96. package/src/plugins/table/commands/hover.ts +37 -7
  97. package/src/plugins/table/commands/index.ts +1 -0
  98. package/src/plugins/table/commands/misc.ts +9 -3
  99. package/src/plugins/table/event-handlers.ts +47 -29
  100. package/src/plugins/table/nodeviews/TableComponent.tsx +4 -1
  101. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +7 -5
  102. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +37 -2
  103. package/src/plugins/table/pm-plugins/main.ts +6 -3
  104. package/src/plugins/table/reducer.ts +1 -0
  105. package/src/plugins/table/types.ts +7 -2
  106. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +14 -5
  107. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
  108. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +3 -1
  109. package/src/plugins/table/ui/TableFloatingControls/index.tsx +12 -5
  110. package/src/plugins/table/utils/dom.ts +22 -0
  111. package/src/plugins/table/utils/index.ts +1 -0
@@ -137,16 +137,36 @@ export var hideResizeHandleLine = function hideResizeHandleLine() {
137
137
  };
138
138
  });
139
139
  };
140
- export var hoverCell = function hoverCell(rowIndex, colIndex, colWidth, colHeight) {
140
+ export var setTableHovered = function setTableHovered(hovered) {
141
141
  return createCommand(function () {
142
+ return {
143
+ type: 'TABLE_HOVERED',
144
+ data: {
145
+ isTableHovered: hovered
146
+ }
147
+ };
148
+ }, function (tr) {
149
+ return tr.setMeta('addToHistory', false);
150
+ });
151
+ };
152
+ export var hoverCell = function hoverCell(rowIndex, colIndex) {
153
+ return createCommand(function (state) {
154
+ var _getPluginState4 = getPluginState(state),
155
+ prevHoveredCell = _getPluginState4.hoveredCell;
156
+
157
+ // If no arguments have been passed then the intention it to reset the hover cell data
158
+ var clear = rowIndex === undefined && colIndex === undefined;
159
+ var nextRowIndex = clear ? undefined : rowIndex !== null && rowIndex !== void 0 ? rowIndex : prevHoveredCell.rowIndex;
160
+ var nextColIndex = clear ? undefined : colIndex !== null && colIndex !== void 0 ? colIndex : prevHoveredCell.colIndex;
161
+ if (nextRowIndex === prevHoveredCell.rowIndex && nextColIndex === prevHoveredCell.colIndex) {
162
+ return false;
163
+ }
142
164
  return {
143
165
  type: 'HOVER_CELL',
144
166
  data: {
145
167
  hoveredCell: {
146
- rowIndex: rowIndex,
147
- colIndex: colIndex,
148
- colWidth: colWidth,
149
- colHeight: colHeight
168
+ rowIndex: nextRowIndex,
169
+ colIndex: nextColIndex
150
170
  }
151
171
  }
152
172
  };
@@ -1,4 +1,4 @@
1
- export { hoverColumns, hoverRows, hoverTable, hoverCell, hoverMergedCells, clearHoverSelection, showResizeHandleLine, hideResizeHandleLine } from './hover';
1
+ export { hoverColumns, hoverRows, hoverTable, hoverCell, hoverMergedCells, clearHoverSelection, showResizeHandleLine, hideResizeHandleLine, setTableHovered } from './hover';
2
2
  export { insertColumn, insertRow, createTable } from './insert';
3
3
  export { getNextLayout, toggleContextualMenu, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './toggle';
4
4
  export { clearMultipleCells } from './clear';
@@ -195,12 +195,17 @@ export var getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySl
195
195
  export var isInsideFirstCellOfRowOrColumn = function isInsideFirstCellOfRowOrColumn(selection, type) {
196
196
  var table = findTable(selection);
197
197
  if (!table || !type) {
198
- return;
198
+ return false;
199
199
  }
200
200
  var map = TableMap.get(table.node);
201
- var cell = selectionCell(selection);
201
+ var cell = findCellClosestToPos(selection.$anchor);
202
+ if (!cell) {
203
+ return false;
204
+ }
205
+ var pos = cell.pos - table.pos - 1;
206
+ // cell positions in table map always start at 1, as they're offsets not positions
202
207
  var index = map.map.findIndex(function (value) {
203
- return value === cell.pos - 1;
208
+ return value === pos;
204
209
  });
205
210
  return type === 'row' ? index % map.width === 0 : index < map.width;
206
211
  };
@@ -5,7 +5,7 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { cellAround, findCellRectClosestToPos, findTable, getSelectionRect, removeTable } from '@atlaskit/editor-tables/utils';
8
- import { addResizeHandleDecorations, clearHoverSelection, hideInsertColumnOrRowButton, hideResizeHandleLine, hoverCell, hoverColumns, selectColumn, setEditorFocus, showInsertColumnButton, showInsertRowButton, showResizeHandleLine } from './commands';
8
+ import { addResizeHandleDecorations, clearHoverSelection, hideInsertColumnOrRowButton, hideResizeHandleLine, hoverCell, hoverColumns, selectColumn, setEditorFocus, setTableHovered, showInsertColumnButton, showInsertRowButton, showResizeHandleLine } from './commands';
9
9
  import { getPluginState as getDragDropPluginState } from './pm-plugins/drag-and-drop/plugin-factory';
10
10
  import { getPluginState } from './pm-plugins/plugin-factory';
11
11
  import { getPluginState as getResizePluginState } from './pm-plugins/table-resizing/plugin-factory';
@@ -98,7 +98,8 @@ export var handleMouseOver = function handleMouseOver(view, mouseEvent) {
98
98
  var target = mouseEvent.target;
99
99
  var _getPluginState = getPluginState(state),
100
100
  insertColumnButtonIndex = _getPluginState.insertColumnButtonIndex,
101
- insertRowButtonIndex = _getPluginState.insertRowButtonIndex;
101
+ insertRowButtonIndex = _getPluginState.insertRowButtonIndex,
102
+ isTableHovered = _getPluginState.isTableHovered;
102
103
  if (isInsertRowButton(target)) {
103
104
  var _getColumnOrRowIndex3 = getColumnOrRowIndex(target),
104
105
  _getColumnOrRowIndex4 = _slicedToArray(_getColumnOrRowIndex3, 2),
@@ -128,6 +129,9 @@ export var handleMouseOver = function handleMouseOver(view, mouseEvent) {
128
129
  right: _endIndex
129
130
  })(state, dispatch);
130
131
  }
132
+ if (!isTableHovered) {
133
+ return setTableHovered(true)(state, dispatch);
134
+ }
131
135
  return false;
132
136
  };
133
137
 
@@ -160,26 +164,46 @@ export var handleMouseOut = function handleMouseOut(view, mouseEvent) {
160
164
  }
161
165
  return false;
162
166
  };
167
+ export var handleMouseEnter = function handleMouseEnter(view, mouseEvent) {
168
+ var state = view.state,
169
+ dispatch = view.dispatch;
170
+ var _getPluginState2 = getPluginState(state),
171
+ isTableHovered = _getPluginState2.isTableHovered;
172
+ if (!isTableHovered) {
173
+ return setTableHovered(true)(state, dispatch);
174
+ }
175
+ return false;
176
+ };
163
177
  export var handleMouseLeave = function handleMouseLeave(view, event) {
164
178
  if (!(event.target instanceof HTMLElement)) {
165
179
  return false;
166
180
  }
167
181
  var state = view.state,
168
182
  dispatch = view.dispatch;
169
- var _getPluginState2 = getPluginState(state),
170
- insertColumnButtonIndex = _getPluginState2.insertColumnButtonIndex,
171
- insertRowButtonIndex = _getPluginState2.insertRowButtonIndex,
172
- isDragAndDropEnabled = _getPluginState2.isDragAndDropEnabled;
183
+ var _getPluginState3 = getPluginState(state),
184
+ insertColumnButtonIndex = _getPluginState3.insertColumnButtonIndex,
185
+ insertRowButtonIndex = _getPluginState3.insertRowButtonIndex,
186
+ isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled,
187
+ isTableHovered = _getPluginState3.isTableHovered;
188
+ if (isTableHovered) {
189
+ if (isDragAndDropEnabled) {
190
+ var _getDragDropPluginSta = getDragDropPluginState(state),
191
+ isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen;
192
+ !isDragMenuOpen && setTableHovered(false)(state, dispatch);
193
+ } else {
194
+ setTableHovered(false)(state, dispatch);
195
+ }
196
+ return true;
197
+ }
198
+
199
+ // If this table doesn't have focus then we want to skip everything after this.
200
+ if (!isTableInFocus(view)) {
201
+ return false;
202
+ }
173
203
  var target = event.target;
174
204
  if (isTableControlsButton(target)) {
175
205
  return true;
176
206
  }
177
- if (isDragAndDropEnabled) {
178
- var _getDragDropPluginSta = getDragDropPluginState(state),
179
- isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen;
180
- // Only set hoveredCell colIndex and rowIndex to undefined if the drag menu is not open
181
- !isDragMenuOpen && hoverCell()(state, dispatch);
182
- }
183
207
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && hideInsertColumnOrRowButton()(state, dispatch)) {
184
208
  return true;
185
209
  }
@@ -193,9 +217,9 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
193
217
  if (isColumnControlsDecorations(element) || isDragColumnFloatingInsertDot(element)) {
194
218
  var state = view.state,
195
219
  dispatch = view.dispatch;
196
- var _getPluginState3 = getPluginState(state),
197
- insertColumnButtonIndex = _getPluginState3.insertColumnButtonIndex,
198
- isDragAndDropEnabled = _getPluginState3.isDragAndDropEnabled;
220
+ var _getPluginState4 = getPluginState(state),
221
+ insertColumnButtonIndex = _getPluginState4.insertColumnButtonIndex,
222
+ isDragAndDropEnabled = _getPluginState4.isDragAndDropEnabled;
199
223
  var _getColumnOrRowIndex9 = getColumnOrRowIndex(element),
200
224
  _getColumnOrRowIndex10 = _slicedToArray(_getColumnOrRowIndex9, 2),
201
225
  startIndex = _getColumnOrRowIndex10[0],
@@ -208,8 +232,8 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
208
232
  if (isRowControlsButton(element) || isDragRowFloatingInsertDot(element)) {
209
233
  var _state3 = view.state,
210
234
  _dispatch4 = view.dispatch;
211
- var _getPluginState4 = getPluginState(_state3),
212
- insertRowButtonIndex = _getPluginState4.insertRowButtonIndex;
235
+ var _getPluginState5 = getPluginState(_state3),
236
+ insertRowButtonIndex = _getPluginState5.insertRowButtonIndex;
213
237
  var _getColumnOrRowIndex11 = getColumnOrRowIndex(element),
214
238
  _getColumnOrRowIndex12 = _slicedToArray(_getColumnOrRowIndex11, 2),
215
239
  _startIndex3 = _getColumnOrRowIndex12[0],
@@ -224,9 +248,9 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
224
248
  if (_positionColumn !== null) {
225
249
  var _state4 = view.state,
226
250
  _dispatch5 = view.dispatch;
227
- var _getPluginState5 = getPluginState(_state4),
228
- resizeHandleColumnIndex = _getPluginState5.resizeHandleColumnIndex,
229
- resizeHandleRowIndex = _getPluginState5.resizeHandleRowIndex;
251
+ var _getPluginState6 = getPluginState(_state4),
252
+ resizeHandleColumnIndex = _getPluginState6.resizeHandleColumnIndex,
253
+ resizeHandleRowIndex = _getPluginState6.resizeHandleRowIndex;
230
254
  var tableCell = closestElement(element, 'td, th');
231
255
  var cellStartPosition = view.posAtDOM(tableCell, 0);
232
256
  var rect = findCellRectClosestToPos(_state4.doc.resolve(cellStartPosition));
@@ -301,8 +325,8 @@ export var handleCut = function handleCut(oldTr, oldState, newState, editorAnaly
301
325
  if (isTableSelected) {
302
326
  tr = removeTable(tr);
303
327
  } else if (tr.selection.isRowSelection()) {
304
- var _getPluginState6 = getPluginState(newState),
305
- isHeaderRowRequired = _getPluginState6.pluginConfig.isHeaderRowRequired;
328
+ var _getPluginState7 = getPluginState(newState),
329
+ isHeaderRowRequired = _getPluginState7.pluginConfig.isHeaderRowRequired;
306
330
  tr = deleteRows(rect, isHeaderRowRequired)(tr);
307
331
  } else if (tr.selection.isColSelection()) {
308
332
  tr = deleteColumns(rect, getAllowAddColumnCustomStep(oldState), editorView)(tr);
@@ -313,10 +337,13 @@ export var handleCut = function handleCut(oldTr, oldState, newState, editorAnaly
313
337
  }
314
338
  return tr;
315
339
  };
340
+ export var isTableInFocus = function isTableInFocus(view) {
341
+ var _getPluginState8, _getResizePluginState;
342
+ return !!((_getPluginState8 = getPluginState(view.state)) !== null && _getPluginState8 !== void 0 && _getPluginState8.tableNode) && !((_getResizePluginState = getResizePluginState(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
343
+ };
316
344
  export var whenTableInFocus = function whenTableInFocus(eventHandler, elementContentRects) {
317
345
  return function (view, mouseEvent) {
318
- var _getPluginState7, _getResizePluginState;
319
- if (!((_getPluginState7 = getPluginState(view.state)) !== null && _getPluginState7 !== void 0 && _getPluginState7.tableNode) || !!((_getResizePluginState = getResizePluginState(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging)) {
346
+ if (!isTableInFocus(view)) {
320
347
  return false;
321
348
  }
322
349
  return eventHandler(view, mouseEvent, elementContentRects);
@@ -326,10 +353,9 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
326
353
  var _tableElement$dataset;
327
354
  var target = mouseEvent.target;
328
355
  var maybeTableCell = isElementInTableCell(target);
329
- var tableRef = getPluginState(view.state).tableRef;
330
- var _getPluginState8 = getPluginState(view.state),
331
- hoveredCell = _getPluginState8.hoveredCell,
332
- tableNode = _getPluginState8.tableNode;
356
+ var _getPluginState9 = getPluginState(view.state),
357
+ tableNode = _getPluginState9.tableNode,
358
+ tableRef = _getPluginState9.tableRef;
333
359
  var tableElement = closestElement(target, 'table');
334
360
 
335
361
  // hover will only trigger if target localId is the same with selected localId
@@ -342,17 +368,13 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
342
368
  var htmlColIndex = maybeTableCell.cellIndex;
343
369
  var rowElement = closestElement(target, 'tr');
344
370
  var htmlRowIndex = rowElement && rowElement.rowIndex;
345
- var colHeight = tableRef.offsetHeight;
346
- var colWidth = maybeTableCell.offsetWidth;
347
371
  var tableMap = tableNode && TableMap.get(tableNode);
348
372
  var colIndex = htmlColIndex;
349
373
  if (tableMap) {
350
374
  var convertedColIndex = convertHTMLCellIndexToColumnIndex(htmlColIndex, htmlRowIndex, tableMap);
351
375
  colIndex = getColumnIndexMappedToColumnIndexInFirstRow(convertedColIndex, htmlRowIndex, tableMap);
352
376
  }
353
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== htmlRowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
354
- hoverCell(htmlRowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
355
- }
377
+ hoverCell(htmlRowIndex, colIndex)(view.state, view.dispatch);
356
378
  };
357
379
  export var withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
358
380
  return function (view, mouseEvent) {
@@ -520,7 +520,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
520
520
  var _getPluginState2 = getPluginState(view.state),
521
521
  isInDanger = _getPluginState2.isInDanger,
522
522
  hoveredRows = _getPluginState2.hoveredRows,
523
- hoveredCell = _getPluginState2.hoveredCell;
523
+ hoveredCell = _getPluginState2.hoveredCell,
524
+ isTableHovered = _getPluginState2.isTableHovered;
524
525
  var tableRef = this.table || undefined;
525
526
  var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
526
527
  var hasHeaderRow = containsHeaderRow(node);
@@ -531,6 +532,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
531
532
  tableActive: tableActive,
532
533
  hoveredRows: hoveredRows,
533
534
  hoveredCell: hoveredCell,
535
+ isTableHovered: isTableHovered,
534
536
  isInDanger: isInDanger,
535
537
  isResizing: isResizing,
536
538
  isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
@@ -553,6 +555,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
553
555
  isInDanger: isInDanger,
554
556
  hoveredRows: hoveredRows,
555
557
  hoveredCell: hoveredCell,
558
+ isTableHovered: isTableHovered,
556
559
  isResizing: isResizing,
557
560
  ordering: ordering,
558
561
  hasHeaderRow: hasHeaderRow
@@ -61,7 +61,7 @@ export var clearDropTarget = function clearDropTarget(tr) {
61
61
  return (tr || originalTr).setMeta('addToHistory', false);
62
62
  });
63
63
  };
64
- export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex) {
64
+ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex, tr) {
65
65
  return createCommand(function (state) {
66
66
  return {
67
67
  type: DragAndDropActionType.CLEAR_DROP_TARGET,
@@ -69,19 +69,20 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
69
69
  decorationSet: DecorationSet.empty
70
70
  }
71
71
  };
72
- }, function (tr) {
72
+ }, function (originalTr) {
73
+ var nextTr = tr || originalTr;
73
74
  if (sourceIndex === targetIndex) {
74
- return tr.setMeta('addToHistory', false);
75
+ return nextTr.setMeta('addToHistory', false);
75
76
  }
76
- var anchor = tr.selection.anchor;
77
+ var anchor = nextTr.selection.anchor;
77
78
  var selectStartOfTable = function selectStartOfTable(newTr) {
78
79
  return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
79
80
  };
80
81
  var isTableRow = sourceType === 'table-row';
81
82
  if (isTableRow) {
82
- return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], tr);
83
+ return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], nextTr);
83
84
  }
84
- return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], tr);
85
+ return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], nextTr);
85
86
  });
86
87
  };
87
88
  export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
@@ -4,8 +4,10 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { getCellsInRow } from '@atlaskit/editor-tables/utils';
6
6
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
7
+ import { findNearestCellIndexToPoint } from '../../utils';
7
8
  import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
8
9
  import { getPluginState as getTablePluginState } from '../plugin-factory';
10
+ import { pluginKey as tablePluginKey } from '../plugin-key';
9
11
  import { DragAndDropActionType } from './actions';
10
12
  import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
11
13
  import { DropTargetType } from './consts';
@@ -106,28 +108,58 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
106
108
  setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
107
109
  },
108
110
  onDrop: function onDrop(event) {
111
+ var _cell$row, _cell$col;
109
112
  var data = getDraggableDataFromEvent(event);
110
113
 
114
+ // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
115
+ // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
116
+ // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
117
+ // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
118
+ // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
119
+ // triggered by this on drop event.
120
+ var _getTablePluginState4 = getTablePluginState(editorView.state),
121
+ hoveredCell = _getTablePluginState4.hoveredCell;
122
+ var cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
123
+ var tr = editorView.state.tr;
124
+ var action = {
125
+ type: 'HOVER_CELL',
126
+ data: {
127
+ hoveredCell: {
128
+ rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
129
+ colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
130
+ }
131
+ }
132
+ };
133
+ tr.setMeta(tablePluginKey, action);
134
+
111
135
  // If no data can be found then it's most like we do not want to perform any drop action
112
136
  if (!data) {
113
- clearDropTarget()(editorView.state, editorView.dispatch);
137
+ clearDropTarget(tr)(editorView.state, editorView.dispatch);
114
138
  return;
115
139
  }
116
140
  var sourceType = data.sourceType,
117
141
  sourceIndexes = data.sourceIndexes,
142
+ targetIndex = data.targetIndex,
118
143
  targetAdjustedIndex = data.targetAdjustedIndex,
119
144
  direction = data.direction;
120
145
 
146
+ // When we drop on a target we will know the targets row/col index for certain,
147
+ if (sourceType === 'table-row') {
148
+ action.data.hoveredCell.rowIndex = targetIndex;
149
+ } else {
150
+ action.data.hoveredCell.colIndex = targetIndex;
151
+ }
152
+
121
153
  // If the drop target index contains merged cells then we should not allow the drop to occur.
122
154
  var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
123
155
  if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
124
- clearDropTarget()(editorView.state, editorView.dispatch);
156
+ clearDropTarget(tr)(editorView.state, editorView.dispatch);
125
157
  return;
126
158
  }
127
159
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
128
160
  sourceIndex = _sourceIndexes[0];
129
161
  requestAnimationFrame(function () {
130
- moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
162
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
131
163
  });
132
164
  }
133
165
  })
@@ -11,7 +11,7 @@ import { findTable } from '@atlaskit/editor-tables/utils';
11
11
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
12
  import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../commands';
13
13
  import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
14
- import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus, withCellTracking } from '../event-handlers';
14
+ import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseEnter, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus, withCellTracking } from '../event-handlers';
15
15
  import { createTableView } from '../nodeviews/table';
16
16
  import TableCell from '../nodeviews/TableCell';
17
17
  import TableRow from '../nodeviews/TableRow';
@@ -27,6 +27,7 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
27
27
  var _window;
28
28
  var state = createPluginState(dispatch, _objectSpread(_objectSpread(_objectSpread({
29
29
  pluginConfig: pluginConfig,
30
+ isTableHovered: false,
30
31
  insertColumnButtonIndex: undefined,
31
32
  insertRowButtonIndex: undefined,
32
33
  isFullWidthModeEnabled: fullWidthModeEnabled,
@@ -241,11 +242,12 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
241
242
  focus: handleFocus,
242
243
  blur: handleBlur,
243
244
  mousedown: withCellTracking(handleMouseDown),
244
- mouseover: whenTableInFocus(withCellTracking(handleMouseOver)),
245
- mouseleave: whenTableInFocus(handleMouseLeave),
245
+ mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
246
+ mouseleave: handleMouseLeave,
246
247
  mouseout: whenTableInFocus(handleMouseOut),
247
248
  mousemove: whenTableInFocus(handleMouseMove, elementContentRects),
248
- click: whenTableInFocus(handleClick)
249
+ mouseenter: handleMouseEnter,
250
+ click: withCellTracking(whenTableInFocus(handleClick))
249
251
  },
250
252
  handleTripleClick: handleTripleClick
251
253
  }
@@ -90,6 +90,7 @@ export default (function (pluginState, action) {
90
90
  case 'HOVER_ROWS':
91
91
  case 'HOVER_COLUMNS':
92
92
  case 'HOVER_TABLE':
93
+ case 'TABLE_HOVERED':
93
94
  case 'HOVER_MERGED_CELLS':
94
95
  case 'HOVER_CELL':
95
96
  case 'SHOW_RESIZE_HANDLE_LINE':
@@ -1,3 +1,5 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
1
3
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
2
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
5
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
@@ -85,7 +87,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
85
87
  },
86
88
  selected: false,
87
89
  disabled: false,
88
- elemAfter: /*#__PURE__*/React.createElement("div", {
90
+ elemAfter: jsx("div", {
89
91
  css: shortcutStyle
90
92
  }, tooltip(addColumnAfter))
91
93
  }, {
@@ -104,7 +106,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
104
106
  },
105
107
  selected: false,
106
108
  disabled: false,
107
- elemAfter: /*#__PURE__*/React.createElement("div", {
109
+ elemAfter: jsx("div", {
108
110
  css: shortcutStyle
109
111
  }, tooltip(addRowAfter))
110
112
  }, {
@@ -236,7 +238,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
236
238
  },
237
239
  selected: false,
238
240
  disabled: false,
239
- elemAfter: /*#__PURE__*/React.createElement("div", {
241
+ elemAfter: jsx("div", {
240
242
  css: shortcutStyle
241
243
  }, tooltip(backspace))
242
244
  });
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
2
3
  import React from 'react';
4
+ import { jsx } from '@emotion/react';
3
5
  import { useIntl } from 'react-intl-next';
4
6
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
5
7
  import Tooltip from '@atlaskit/tooltip';
@@ -11,20 +13,20 @@ export var ColumnResizeWidget = function ColumnResizeWidget(_ref) {
11
13
  var _useIntl = useIntl(),
12
14
  formatMessage = _useIntl.formatMessage;
13
15
  if (!includeTooltip) {
14
- return /*#__PURE__*/React.createElement("div", {
16
+ return jsx("div", {
15
17
  className: TableCssClassName.RESIZE_HANDLE_DECORATION,
16
18
  "data-start-index": startIndex,
17
19
  "data-end-index": endIndex
18
20
  });
19
21
  }
20
- return /*#__PURE__*/React.createElement(Tooltip, {
22
+ return jsx(Tooltip, {
21
23
  content: formatMessage(messages.adjustColumns),
22
24
  hideTooltipOnClick: true,
23
25
  hideTooltipOnMouseDown: true,
24
26
  position: "mouse",
25
27
  mousePosition: "auto-start"
26
28
  }, function (tooltipProps) {
27
- return /*#__PURE__*/React.createElement("div", _extends({
29
+ return jsx("div", _extends({
28
30
  className: TableCssClassName.RESIZE_HANDLE_DECORATION,
29
31
  "data-start-index": startIndex,
30
32
  "data-end-index": endIndex
@@ -1,5 +1,3 @@
1
- /* index.tsx generated by @compiled/babel-plugin v0.26.1 */
2
- import { ax, ix } from "@compiled/react/runtime";
3
1
  import React from 'react';
4
2
  import { Box, xcss } from '@atlaskit/primitives';
5
3
  import { DragInMotionIcon } from '../icons/DragInMotionIcon';
@@ -1,4 +1,6 @@
1
+ /** @jsx jsx */
1
2
  import React from 'react';
3
+ import { jsx } from '@emotion/react';
2
4
  import { injectIntl } from 'react-intl-next';
3
5
  import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
4
6
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
@@ -42,7 +44,7 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
42
44
  return null;
43
45
  }
44
46
  var labelCellOptions = formatMessage(messages.cellOptions);
45
- var button = /*#__PURE__*/React.createElement("div", {
47
+ var button = jsx("div", {
46
48
  css: function css(theme) {
47
49
  return [tableFloatingCellButtonStyles({
48
50
  theme: theme
@@ -50,19 +52,19 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
50
52
  theme: theme
51
53
  })];
52
54
  }
53
- }, /*#__PURE__*/React.createElement(ToolbarButton, {
55
+ }, jsx(ToolbarButton, {
54
56
  className: ClassName.CONTEXTUAL_MENU_BUTTON,
55
57
  selected: isContextualMenuOpen,
56
58
  title: labelCellOptions,
57
59
  onClick: handleClick,
58
- iconBefore: /*#__PURE__*/React.createElement(ExpandIcon, {
60
+ iconBefore: jsx(ExpandIcon, {
59
61
  label: ""
60
62
  }),
61
63
  "aria-label": labelCellOptions
62
64
  }));
63
65
  var parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
64
66
  if (stickyHeader && parentSticky && tableWrapper) {
65
- return /*#__PURE__*/React.createElement(FixedButton, {
67
+ return jsx(FixedButton, {
66
68
  offset: BUTTON_OFFSET,
67
69
  stickyHeader: stickyHeader,
68
70
  tableWrapper: tableWrapper,
@@ -72,7 +74,7 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
72
74
  isContextualMenuOpen: isContextualMenuOpen
73
75
  }, button);
74
76
  }
75
- return /*#__PURE__*/React.createElement(Popup, {
77
+ return jsx(Popup, {
76
78
  alignX: "right",
77
79
  alignY: "start",
78
80
  target: targetCellRef,
@@ -87,9 +89,9 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
87
89
  });
88
90
  var FloatingContextualButton = injectIntl(FloatingContextualButtonInner);
89
91
  export default function (props) {
90
- return /*#__PURE__*/React.createElement(ErrorBoundary, {
92
+ return jsx(ErrorBoundary, {
91
93
  component: ACTION_SUBJECT.FLOATING_CONTEXTUAL_BUTTON,
92
94
  dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
93
95
  fallbackComponent: null
94
- }, /*#__PURE__*/React.createElement(FloatingContextualButton, props));
96
+ }, jsx(FloatingContextualButton, props));
95
97
  }
@@ -9,7 +9,9 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
9
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
10
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
11
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ /** @jsx jsx */
12
13
  import { Component } from 'react';
14
+ import { jsx } from '@emotion/react';
13
15
  import { injectIntl } from 'react-intl-next';
14
16
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
15
17
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -80,15 +82,15 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
80
82
  value: {
81
83
  name: 'background'
82
84
  },
83
- elemAfter: /*#__PURE__*/React.createElement("div", {
85
+ elemAfter: jsx("div", {
84
86
  className: DropdownMenuSharedCssClassName.SUBMENU
85
- }, /*#__PURE__*/React.createElement("div", {
87
+ }, jsx("div", {
86
88
  css: cellColourPreviewStyles(background),
87
89
  className: ClassName.CONTEXTUAL_MENU_ICON
88
- }), isSubmenuOpen && /*#__PURE__*/React.createElement("div", {
90
+ }), isSubmenuOpen && jsx("div", {
89
91
  className: ClassName.CONTEXTUAL_SUBMENU,
90
92
  ref: _this.handleSubMenuRef
91
- }, /*#__PURE__*/React.createElement(ColorPalette, {
93
+ }, jsx(ColorPalette, {
92
94
  cols: 7,
93
95
  onClick: _this.setColor,
94
96
  selectedColor: background,
@@ -105,7 +107,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
105
107
  value: {
106
108
  name: 'insert_column'
107
109
  },
108
- elemAfter: /*#__PURE__*/React.createElement("div", {
110
+ elemAfter: jsx("div", {
109
111
  css: shortcutStyle
110
112
  }, tooltip(addColumnAfter))
111
113
  });
@@ -114,7 +116,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
114
116
  value: {
115
117
  name: 'insert_row'
116
118
  },
117
- elemAfter: /*#__PURE__*/React.createElement("div", {
119
+ elemAfter: jsx("div", {
118
120
  css: shortcutStyle
119
121
  }, tooltip(addRowAfter))
120
122
  });
@@ -194,7 +196,7 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
194
196
  value: {
195
197
  name: 'clear'
196
198
  },
197
- elemAfter: /*#__PURE__*/React.createElement("div", {
199
+ elemAfter: jsx("div", {
198
200
  css: shortcutStyle
199
201
  }, tooltip(backspace))
200
202
  });
@@ -356,10 +358,10 @@ export var ContextualMenu = /*#__PURE__*/function (_Component) {
356
358
  if (!items) {
357
359
  return null;
358
360
  }
359
- return /*#__PURE__*/React.createElement("div", {
361
+ return jsx("div", {
360
362
  "data-testid": "table-cell-contextual-menu",
361
363
  onMouseLeave: this.closeSubmenu
362
- }, /*#__PURE__*/React.createElement(DropdownMenu, {
364
+ }, jsx(DropdownMenu, {
363
365
  mountTo: mountPoint
364
366
  //This needs be removed when the a11y is completely handled
365
367
  //Disabling key navigation now as it works only partially