@atlaskit/editor-plugin-table 5.4.14 → 5.4.16

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 (123) hide show
  1. package/CHANGELOG.md +16 -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/DragHandle/HandleIconComponent.js +3 -5
  15. package/dist/cjs/plugins/table/ui/DragHandle/index.js +3 -0
  16. package/dist/cjs/plugins/table/ui/DragPreview/index.js +0 -2
  17. package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +10 -7
  18. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -10
  19. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/index.js +6 -3
  20. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +7 -4
  21. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +74 -37
  22. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  23. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +63 -31
  24. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +12 -8
  25. package/dist/cjs/plugins/table/utils/dom.js +16 -1
  26. package/dist/cjs/plugins/table/utils/index.js +6 -0
  27. package/dist/es2019/plugins/table/commands/hover.js +22 -5
  28. package/dist/es2019/plugins/table/commands/index.js +1 -1
  29. package/dist/es2019/plugins/table/commands/misc.js +8 -3
  30. package/dist/es2019/plugins/table/event-handlers.js +45 -20
  31. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +4 -1
  32. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +7 -6
  33. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +36 -3
  34. package/dist/es2019/plugins/table/pm-plugins/main.js +6 -4
  35. package/dist/es2019/plugins/table/reducer.js +1 -0
  36. package/dist/es2019/plugins/table/toolbar.js +5 -3
  37. package/dist/es2019/plugins/table/ui/ColumnResizeWidget/index.js +5 -3
  38. package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
  39. package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
  40. package/dist/es2019/plugins/table/ui/DragPreview/index.js +0 -2
  41. package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  42. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  43. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  44. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  45. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +73 -37
  46. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  47. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +62 -29
  48. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +12 -9
  49. package/dist/es2019/plugins/table/utils/dom.js +13 -0
  50. package/dist/es2019/plugins/table/utils/index.js +1 -1
  51. package/dist/esm/plugins/table/commands/hover.js +25 -5
  52. package/dist/esm/plugins/table/commands/index.js +1 -1
  53. package/dist/esm/plugins/table/commands/misc.js +8 -3
  54. package/dist/esm/plugins/table/event-handlers.js +55 -33
  55. package/dist/esm/plugins/table/nodeviews/TableComponent.js +4 -1
  56. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +7 -6
  57. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +35 -3
  58. package/dist/esm/plugins/table/pm-plugins/main.js +6 -4
  59. package/dist/esm/plugins/table/reducer.js +1 -0
  60. package/dist/esm/plugins/table/toolbar.js +5 -3
  61. package/dist/esm/plugins/table/ui/ColumnResizeWidget/index.js +5 -3
  62. package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
  63. package/dist/esm/plugins/table/ui/DragHandle/index.js +3 -0
  64. package/dist/esm/plugins/table/ui/DragPreview/index.js +0 -2
  65. package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  66. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  67. package/dist/esm/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  68. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  69. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +74 -37
  70. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  71. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +61 -29
  72. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +12 -8
  73. package/dist/esm/plugins/table/utils/dom.js +15 -0
  74. package/dist/esm/plugins/table/utils/index.js +1 -1
  75. package/dist/types/plugins/table/commands/hover.d.ts +2 -1
  76. package/dist/types/plugins/table/commands/index.d.ts +1 -1
  77. package/dist/types/plugins/table/commands/misc.d.ts +1 -1
  78. package/dist/types/plugins/table/event-handlers.d.ts +2 -0
  79. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  80. package/dist/types/plugins/table/types.d.ts +7 -2
  81. package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
  82. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
  83. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  84. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  85. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  86. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  87. package/dist/types/plugins/table/utils/dom.d.ts +4 -0
  88. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  89. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  90. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  91. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +1 -1
  92. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +2 -0
  93. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  94. package/dist/types-ts4.5/plugins/table/types.d.ts +7 -2
  95. package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
  96. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
  97. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  98. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  99. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  100. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  101. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -0
  102. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  103. package/package.json +2 -2
  104. package/src/__tests__/unit/event-handlers.ts +2 -2
  105. package/src/__tests__/unit/ui/RowDragControls.tsx +1 -0
  106. package/src/plugins/table/commands/hover.ts +37 -7
  107. package/src/plugins/table/commands/index.ts +1 -0
  108. package/src/plugins/table/commands/misc.ts +9 -3
  109. package/src/plugins/table/event-handlers.ts +47 -29
  110. package/src/plugins/table/nodeviews/TableComponent.tsx +4 -1
  111. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +7 -5
  112. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +37 -2
  113. package/src/plugins/table/pm-plugins/main.ts +6 -3
  114. package/src/plugins/table/reducer.ts +1 -0
  115. package/src/plugins/table/types.ts +9 -2
  116. package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +10 -9
  117. package/src/plugins/table/ui/DragHandle/index.tsx +4 -0
  118. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +129 -50
  119. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
  120. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +128 -41
  121. package/src/plugins/table/ui/TableFloatingControls/index.tsx +12 -5
  122. package/src/plugins/table/utils/dom.ts +22 -0
  123. package/src/plugins/table/utils/index.ts +1 -0
@@ -8,9 +8,11 @@ export declare const handleClick: (view: EditorView, event: Event) => boolean;
8
8
  export declare const handleMouseOver: (view: EditorView, mouseEvent: Event) => boolean;
9
9
  export declare const handleMouseDown: (_: EditorView, event: Event) => boolean;
10
10
  export declare const handleMouseOut: (view: EditorView, mouseEvent: Event) => boolean;
11
+ export declare const handleMouseEnter: (view: EditorView, mouseEvent: Event) => boolean;
11
12
  export declare const handleMouseLeave: (view: EditorView, event: Event) => boolean;
12
13
  export declare const handleMouseMove: (view: EditorView, event: Event, elementContentRects?: ElementContentRects) => boolean;
13
14
  export declare function handleTripleClick(view: EditorView, pos: number): boolean;
14
15
  export declare const handleCut: (oldTr: Transaction, oldState: EditorState, newState: EditorState, editorAnalyticsAPI?: EditorAnalyticsAPI, editorView?: EditorView) => Transaction;
16
+ export declare const isTableInFocus: (view: EditorView) => boolean;
15
17
  export declare const whenTableInFocus: (eventHandler: (view: EditorView, mouseEvent: Event, elementContentRects?: ElementContentRects) => boolean, elementContentRects?: ElementContentRects) => (view: EditorView, mouseEvent: Event) => boolean;
16
18
  export declare const withCellTracking: (eventHandler: (view: EditorView, mouseEvent: Event, elementContentRects?: ElementContentRects) => boolean, elementContentRects?: ElementContentRects) => (view: EditorView, mouseEvent: Event) => boolean;
@@ -8,5 +8,5 @@ export declare const getDecorations: (state: EditorState) => DecorationSet;
8
8
  export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
9
9
  export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
10
10
  export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
11
- export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
11
+ export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
12
12
  export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number) => import("@atlaskit/editor-common/types").Command;
@@ -47,8 +47,6 @@ export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
47
47
  export interface CellHoverMeta {
48
48
  colIndex?: number;
49
49
  rowIndex?: number;
50
- colWidth?: number;
51
- colHeight?: number;
52
50
  }
53
51
  export interface TablePluginState {
54
52
  editorHasFocus?: boolean;
@@ -82,6 +80,7 @@ export interface TablePluginState {
82
80
  wasFullWidthModeEnabled?: boolean;
83
81
  isTableResizingEnabled?: boolean;
84
82
  isDragAndDropEnabled?: boolean;
83
+ isTableHovered?: boolean;
85
84
  }
86
85
  export type TablePluginAction = {
87
86
  type: 'SET_EDITOR_FOCUS';
@@ -175,6 +174,11 @@ export type TablePluginAction = {
175
174
  data: {
176
175
  hoveredCell: CellHoverMeta;
177
176
  };
177
+ } | {
178
+ type: 'TABLE_HOVERED';
179
+ data: {
180
+ isTableHovered: boolean;
181
+ };
178
182
  } | {
179
183
  type: 'SET_TARGET_CELL_POSITION';
180
184
  data: {
@@ -416,3 +420,4 @@ export interface DraggableData {
416
420
  targetClosestEdge: Edge;
417
421
  direction: 1 | -1;
418
422
  }
423
+ export type HandleTypes = 'hover' | 'selected';
@@ -2,6 +2,7 @@
2
2
  type HandleIconProps = {
3
3
  hasMergedCells: boolean;
4
4
  direction: 'row' | 'column';
5
+ forceDefaultHandle: boolean;
5
6
  isDragMenuOpen: boolean | undefined;
6
7
  isRowHandleHovered: boolean;
7
8
  isColumnHandleHovered: boolean;
@@ -5,6 +5,7 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
5
5
  type DragHandleProps = {
6
6
  tableLocalId: string;
7
7
  indexes: number[];
8
+ forceDefaultHandle?: boolean;
8
9
  previewWidth?: number;
9
10
  previewHeight?: number;
10
11
  direction?: TableDirection;
@@ -15,5 +16,5 @@ type DragHandleProps = {
15
16
  onMouseUp?: MouseEventHandler;
16
17
  editorView: EditorView;
17
18
  };
18
- export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
19
+ export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, forceDefaultHandle, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
19
20
  export {};
@@ -13,6 +13,7 @@ export interface ColumnControlsProps {
13
13
  rowHeights?: number[];
14
14
  colWidths?: (number | undefined)[];
15
15
  hasHeaderColumn?: boolean;
16
+ isTableHovered?: boolean;
16
17
  }
17
- export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, }: ColumnControlsProps) => JSX.Element;
18
+ export declare const ColumnControls: ({ editorView, tableActive, tableRef, hoveredCell, isResizing, stickyTop, localId, isInDanger, rowHeights, colWidths, hasHeaderColumn, isTableHovered, }: ColumnControlsProps) => JSX.Element;
18
19
  export default ColumnControls;
@@ -21,6 +21,7 @@ export interface Props {
21
21
  isResizing?: boolean;
22
22
  ordering?: TableColumnOrdering;
23
23
  stickyHeader?: RowStickyState;
24
+ isTableHovered?: boolean;
24
25
  }
25
26
  export declare const TableFloatingColumnControls: React.FC<Props>;
26
27
  export default TableFloatingColumnControls;
@@ -12,6 +12,7 @@ type DragControlsProps = {
12
12
  hoveredCell?: CellHoverMeta;
13
13
  isInDanger?: boolean;
14
14
  isResizing?: boolean;
15
+ isTableHovered?: boolean;
15
16
  hoverRows: (rows: number[], danger?: boolean) => void;
16
17
  selectRow: (row: number, expand: boolean) => void;
17
18
  updateCellHoverLocation: (rowIndex: number) => void;
@@ -12,6 +12,7 @@ export interface Props {
12
12
  tableNode?: PmNode;
13
13
  tableActive?: boolean;
14
14
  isInDanger?: boolean;
15
+ isTableHovered?: boolean;
15
16
  isResizing?: boolean;
16
17
  isHeaderRowEnabled?: boolean;
17
18
  isHeaderColumnEnabled?: boolean;
@@ -29,3 +29,7 @@ export type TableDOMElements = {
29
29
  };
30
30
  export declare const getTree: (tr: HTMLTableRowElement) => TableDOMElements | null;
31
31
  export declare const getTop: (element: HTMLElement | Window | undefined) => number;
32
+ export declare const findNearestCellIndexToPoint: (x: number, y: number) => {
33
+ row: number;
34
+ col: number;
35
+ } | undefined;
@@ -2,7 +2,7 @@ export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, is
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnInsertLine, createColumnLineResize, createRowInsertLine, } from './decoration';
3
3
  export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow, } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, } from './paste';
5
- export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, isDragRowControlsButton, isDragColumnFloatingInsertDot, isDragRowFloatingInsertDot, isDragCornerButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, } from './dom';
5
+ export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, isDragRowControlsButton, isDragColumnFloatingInsertDot, isDragRowFloatingInsertDot, isDragCornerButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, findNearestCellIndexToPoint, } from './dom';
6
6
  export { convertHTMLCellIndexToColumnIndex, getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames, getColumnIndexMappedToColumnIndexInFirstRow, } from './column-controls';
7
7
  export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getRowsParams, getRowClassNames, copyPreviousRow, } from './row-controls';
8
8
  export type { RowParams } from './row-controls';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.4.14",
3
+ "version": "5.4.16",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^35.0.0",
31
- "@atlaskit/custom-steps": "^0.0.6",
31
+ "@atlaskit/custom-steps": "^0.0.7",
32
32
  "@atlaskit/editor-common": "^76.25.0",
33
33
  "@atlaskit/editor-palette": "1.5.2",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.3.0",
@@ -191,7 +191,7 @@ describe('table event handlers', () => {
191
191
 
192
192
  describe('#handleMouseOver', () => {
193
193
  describe('when insert col/row button is hidden', () => {
194
- it('should return false', () => {
194
+ it('should set table as hovered', () => {
195
195
  const { editorView } = editor(
196
196
  doc(table()(tr(tdCursor, tdEmpty), tr(tdEmpty, tdEmpty))),
197
197
  );
@@ -205,7 +205,7 @@ describe('table event handlers', () => {
205
205
  const event = {
206
206
  target: editorView.dom.querySelector('td'),
207
207
  };
208
- expect(handleMouseOver(editorView, event as MouseEvent)).toEqual(false);
208
+ expect(handleMouseOver(editorView, event as MouseEvent)).toEqual(true);
209
209
  });
210
210
  });
211
211
 
@@ -71,6 +71,7 @@ describe('NumberColumn', () => {
71
71
  tableActive
72
72
  editorView={editorView}
73
73
  hoveredCell={{ rowIndex: 1, colIndex: 1 }}
74
+ isTableHovered={true}
74
75
  hoverRows={jest.fn()}
75
76
  selectRow={jest.fn()}
76
77
  updateCellHoverLocation={jest.fn()}
@@ -202,18 +202,48 @@ export const hideResizeHandleLine = () =>
202
202
  },
203
203
  }));
204
204
 
205
- export const hoverCell = (
206
- rowIndex?: number,
207
- colIndex?: number,
208
- colWidth?: number,
209
- colHeight?: number,
210
- ) =>
205
+ export const setTableHovered = (hovered: boolean) =>
211
206
  createCommand(
212
207
  () => {
208
+ return {
209
+ type: 'TABLE_HOVERED',
210
+ data: {
211
+ isTableHovered: hovered,
212
+ },
213
+ };
214
+ },
215
+ (tr) => tr.setMeta('addToHistory', false),
216
+ );
217
+
218
+ export const hoverCell = (rowIndex?: number, colIndex?: number) =>
219
+ createCommand(
220
+ (state) => {
221
+ const { hoveredCell: prevHoveredCell } = getPluginState(state);
222
+
223
+ // If no arguments have been passed then the intention it to reset the hover cell data
224
+ const clear = rowIndex === undefined && colIndex === undefined;
225
+
226
+ const nextRowIndex = clear
227
+ ? undefined
228
+ : rowIndex ?? prevHoveredCell.rowIndex;
229
+ const nextColIndex = clear
230
+ ? undefined
231
+ : colIndex ?? prevHoveredCell.colIndex;
232
+
233
+ if (
234
+ nextRowIndex === prevHoveredCell.rowIndex &&
235
+ nextColIndex === prevHoveredCell.colIndex
236
+ ) {
237
+ return false;
238
+ }
239
+
213
240
  return {
214
241
  type: 'HOVER_CELL',
215
242
  data: {
216
- hoveredCell: { rowIndex, colIndex, colWidth, colHeight },
243
+ hoveredCell: {
244
+ rowIndex: nextRowIndex,
245
+ colIndex: nextColIndex,
246
+ },
217
247
  },
218
248
  };
219
249
  },
@@ -7,6 +7,7 @@ export {
7
7
  clearHoverSelection,
8
8
  showResizeHandleLine,
9
9
  hideResizeHandleLine,
10
+ setTableHovered,
10
11
  } from './hover';
11
12
  export { insertColumn, insertRow, createTable } from './insert';
12
13
  export {
@@ -317,11 +317,17 @@ export const isInsideFirstCellOfRowOrColumn = (
317
317
  const table = findTable(selection);
318
318
 
319
319
  if (!table || !type) {
320
- return;
320
+ return false;
321
321
  }
322
+
322
323
  const map = TableMap.get(table.node!);
323
- const cell = selectionCell(selection);
324
- const index = map.map.findIndex((value) => value === cell!.pos! - 1);
324
+ const cell = findCellClosestToPos(selection.$anchor);
325
+ if (!cell) {
326
+ return false;
327
+ }
328
+ const pos = cell.pos - table.pos - 1;
329
+ // cell positions in table map always start at 1, as they're offsets not positions
330
+ const index = map.map.findIndex((value) => value === pos);
325
331
 
326
332
  return type === 'row' ? index % map.width === 0 : index < map.width;
327
333
  };
@@ -37,6 +37,7 @@ import {
37
37
  hoverColumns,
38
38
  selectColumn,
39
39
  setEditorFocus,
40
+ setTableHovered,
40
41
  showInsertColumnButton,
41
42
  showInsertRowButton,
42
43
  showResizeHandleLine,
@@ -193,7 +194,7 @@ export const handleMouseOver = (
193
194
  }
194
195
  const { state, dispatch } = view;
195
196
  const target = mouseEvent.target;
196
- const { insertColumnButtonIndex, insertRowButtonIndex } =
197
+ const { insertColumnButtonIndex, insertRowButtonIndex, isTableHovered } =
197
198
  getPluginState(state);
198
199
 
199
200
  if (isInsertRowButton(target)) {
@@ -230,6 +231,10 @@ export const handleMouseOver = (
230
231
  );
231
232
  }
232
233
 
234
+ if (!isTableHovered) {
235
+ return setTableHovered(true)(state, dispatch);
236
+ }
237
+
233
238
  return false;
234
239
  };
235
240
 
@@ -284,6 +289,21 @@ export const handleMouseOut = (
284
289
  return false;
285
290
  };
286
291
 
292
+ export const handleMouseEnter = (
293
+ view: EditorView,
294
+ mouseEvent: Event,
295
+ ): boolean => {
296
+ const { state, dispatch } = view;
297
+
298
+ const { isTableHovered } = getPluginState(state);
299
+
300
+ if (!isTableHovered) {
301
+ return setTableHovered(true)(state, dispatch);
302
+ }
303
+
304
+ return false;
305
+ };
306
+
287
307
  export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
288
308
  if (!(event.target instanceof HTMLElement)) {
289
309
  return false;
@@ -294,17 +314,27 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
294
314
  insertColumnButtonIndex,
295
315
  insertRowButtonIndex,
296
316
  isDragAndDropEnabled,
317
+ isTableHovered,
297
318
  } = getPluginState(state);
298
319
 
299
- const target = event.target;
300
- if (isTableControlsButton(target)) {
320
+ if (isTableHovered) {
321
+ if (isDragAndDropEnabled) {
322
+ const { isDragMenuOpen } = getDragDropPluginState(state);
323
+ !isDragMenuOpen && setTableHovered(false)(state, dispatch);
324
+ } else {
325
+ setTableHovered(false)(state, dispatch);
326
+ }
301
327
  return true;
302
328
  }
303
329
 
304
- if (isDragAndDropEnabled) {
305
- const { isDragMenuOpen } = getDragDropPluginState(state);
306
- // Only set hoveredCell colIndex and rowIndex to undefined if the drag menu is not open
307
- !isDragMenuOpen && hoverCell()(state, dispatch);
330
+ // If this table doesn't have focus then we want to skip everything after this.
331
+ if (!isTableInFocus(view)) {
332
+ return false;
333
+ }
334
+
335
+ const target = event.target;
336
+ if (isTableControlsButton(target)) {
337
+ return true;
308
338
  }
309
339
 
310
340
  if (
@@ -509,6 +539,13 @@ export const handleCut = (
509
539
  return tr;
510
540
  };
511
541
 
542
+ export const isTableInFocus = (view: EditorView) => {
543
+ return (
544
+ !!getPluginState(view.state)?.tableNode &&
545
+ !getResizePluginState(view.state)?.dragging
546
+ );
547
+ };
548
+
512
549
  export const whenTableInFocus =
513
550
  (
514
551
  eventHandler: (
@@ -519,10 +556,7 @@ export const whenTableInFocus =
519
556
  elementContentRects?: ElementContentRects,
520
557
  ) =>
521
558
  (view: EditorView, mouseEvent: Event): boolean => {
522
- if (
523
- !getPluginState(view.state)?.tableNode ||
524
- !!getResizePluginState(view.state)?.dragging
525
- ) {
559
+ if (!isTableInFocus(view)) {
526
560
  return false;
527
561
  }
528
562
 
@@ -534,8 +568,7 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
534
568
  const maybeTableCell = isElementInTableCell(
535
569
  target as HTMLElement,
536
570
  ) as HTMLTableCellElement | null;
537
- const tableRef = getPluginState(view.state).tableRef;
538
- const { hoveredCell, tableNode } = getPluginState(view.state);
571
+ const { tableNode, tableRef } = getPluginState(view.state);
539
572
 
540
573
  const tableElement = closestElement(
541
574
  target as HTMLElement,
@@ -561,9 +594,6 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
561
594
  ) as HTMLTableRowElement;
562
595
  const htmlRowIndex = rowElement && rowElement.rowIndex;
563
596
 
564
- const colHeight = tableRef.offsetHeight;
565
- const colWidth = maybeTableCell.offsetWidth;
566
-
567
597
  const tableMap = tableNode && TableMap.get(tableNode);
568
598
  let colIndex = htmlColIndex;
569
599
  if (tableMap) {
@@ -580,19 +610,7 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
580
610
  );
581
611
  }
582
612
 
583
- if (
584
- hoveredCell.colIndex !== colIndex ||
585
- hoveredCell.rowIndex !== htmlRowIndex ||
586
- hoveredCell.colWidth !== colWidth ||
587
- hoveredCell.colHeight !== colHeight
588
- ) {
589
- hoverCell(
590
- htmlRowIndex,
591
- colIndex,
592
- colWidth,
593
- colHeight,
594
- )(view.state, view.dispatch);
595
- }
613
+ hoverCell(htmlRowIndex, colIndex)(view.state, view.dispatch);
596
614
  };
597
615
 
598
616
  export const withCellTracking =
@@ -474,7 +474,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
474
474
  const { showBeforeShadow, showAfterShadow } = this.state;
475
475
  const node = getNode();
476
476
  // doesn't work well with WithPluginState
477
- const { isInDanger, hoveredRows, hoveredCell } = getPluginState(view.state);
477
+ const { isInDanger, hoveredRows, hoveredCell, isTableHovered } =
478
+ getPluginState(view.state);
478
479
 
479
480
  const tableRef = this.table || undefined;
480
481
  const headerRow = tableRef
@@ -490,6 +491,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
490
491
  tableActive={tableActive}
491
492
  hoveredRows={hoveredRows}
492
493
  hoveredCell={hoveredCell}
494
+ isTableHovered={isTableHovered}
493
495
  isInDanger={isInDanger}
494
496
  isResizing={isResizing}
495
497
  isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
@@ -514,6 +516,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
514
516
  isInDanger={isInDanger}
515
517
  hoveredRows={hoveredRows}
516
518
  hoveredCell={hoveredCell}
519
+ isTableHovered={isTableHovered}
517
520
  isResizing={isResizing}
518
521
  ordering={ordering}
519
522
  hasHeaderRow={hasHeaderRow}
@@ -101,6 +101,7 @@ export const moveSource = (
101
101
  sourceType: DraggableType,
102
102
  sourceIndex: number,
103
103
  targetIndex: number,
104
+ tr?: Transaction,
104
105
  ) =>
105
106
  createCommand(
106
107
  (state) => {
@@ -111,12 +112,13 @@ export const moveSource = (
111
112
  },
112
113
  };
113
114
  },
114
- (tr: Transaction) => {
115
+ (originalTr: Transaction) => {
116
+ const nextTr = tr || originalTr;
115
117
  if (sourceIndex === targetIndex) {
116
- return tr.setMeta('addToHistory', false);
118
+ return nextTr.setMeta('addToHistory', false);
117
119
  }
118
120
 
119
- const anchor = tr.selection.anchor;
121
+ const anchor = nextTr.selection.anchor;
120
122
  const selectStartOfTable = (newTr: Transaction) =>
121
123
  newTr.setSelection(TextSelection.create(newTr.doc, anchor));
122
124
 
@@ -129,7 +131,7 @@ export const moveSource = (
129
131
  selectStartOfTable,
130
132
  selectRow(targetIndex),
131
133
  ],
132
- tr,
134
+ nextTr,
133
135
  );
134
136
  }
135
137
 
@@ -139,7 +141,7 @@ export const moveSource = (
139
141
  selectStartOfTable,
140
142
  selectColumn(targetIndex),
141
143
  ],
142
- tr,
144
+ nextTr,
143
145
  );
144
146
  },
145
147
  );
@@ -10,11 +10,13 @@ import { getCellsInRow } from '@atlaskit/editor-tables/utils';
10
10
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
11
11
 
12
12
  import type { DraggableSourceData } from '../../types';
13
+ import { findNearestCellIndexToPoint } from '../../utils';
13
14
  import {
14
15
  hasMergedCellsInColumn,
15
16
  hasMergedCellsInRow,
16
17
  } from '../../utils/merged-cells';
17
18
  import { getPluginState as getTablePluginState } from '../plugin-factory';
19
+ import { pluginKey as tablePluginKey } from '../plugin-key';
18
20
 
19
21
  import { DragAndDropActionType } from './actions';
20
22
  import {
@@ -135,19 +137,51 @@ export const createPlugin = (
135
137
  onDrop(event) {
136
138
  const data = getDraggableDataFromEvent(event);
137
139
 
140
+ // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
141
+ // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
142
+ // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
143
+ // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
144
+ // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
145
+ // triggered by this on drop event.
146
+ const { hoveredCell } = getTablePluginState(editorView.state);
147
+
148
+ const cell = findNearestCellIndexToPoint(
149
+ event.location.current.input.clientX,
150
+ event.location.current.input.clientY,
151
+ );
152
+ const tr = editorView.state.tr;
153
+ const action = {
154
+ type: 'HOVER_CELL',
155
+ data: {
156
+ hoveredCell: {
157
+ rowIndex: cell?.row ?? hoveredCell.rowIndex,
158
+ colIndex: cell?.col ?? hoveredCell.colIndex,
159
+ },
160
+ },
161
+ };
162
+ tr.setMeta(tablePluginKey, action);
163
+
138
164
  // If no data can be found then it's most like we do not want to perform any drop action
139
165
  if (!data) {
140
- clearDropTarget()(editorView.state, editorView.dispatch);
166
+ clearDropTarget(tr)(editorView.state, editorView.dispatch);
141
167
  return;
142
168
  }
143
169
 
144
170
  const {
145
171
  sourceType,
146
172
  sourceIndexes,
173
+ targetIndex,
147
174
  targetAdjustedIndex,
148
175
  direction,
149
176
  } = data;
150
177
 
178
+ // When we drop on a target we will know the targets row/col index for certain,
179
+ if (sourceType === 'table-row') {
180
+ action.data.hoveredCell.rowIndex = targetIndex;
181
+ } else {
182
+ action.data.hoveredCell.colIndex = targetIndex;
183
+ }
184
+
151
185
  // If the drop target index contains merged cells then we should not allow the drop to occur.
152
186
  const hasMergedCells =
153
187
  sourceType === 'table-row'
@@ -156,7 +190,7 @@ export const createPlugin = (
156
190
  if (
157
191
  hasMergedCells(targetAdjustedIndex)(editorView.state.selection)
158
192
  ) {
159
- clearDropTarget()(editorView.state, editorView.dispatch);
193
+ clearDropTarget(tr)(editorView.state, editorView.dispatch);
160
194
  return;
161
195
  }
162
196
 
@@ -167,6 +201,7 @@ export const createPlugin = (
167
201
  sourceType,
168
202
  sourceIndex,
169
203
  targetAdjustedIndex + (direction === -1 ? 0 : -1),
204
+ tr,
170
205
  )(editorView.state, editorView.dispatch);
171
206
  });
172
207
  },
@@ -57,6 +57,7 @@ import {
57
57
  handleCut,
58
58
  handleFocus,
59
59
  handleMouseDown,
60
+ handleMouseEnter,
60
61
  handleMouseLeave,
61
62
  handleMouseMove,
62
63
  handleMouseOut,
@@ -112,6 +113,7 @@ export const createPlugin = (
112
113
  ) => {
113
114
  const state = createPluginState(dispatch, {
114
115
  pluginConfig,
116
+ isTableHovered: false,
115
117
  insertColumnButtonIndex: undefined,
116
118
  insertRowButtonIndex: undefined,
117
119
  isFullWidthModeEnabled: fullWidthModeEnabled,
@@ -382,11 +384,12 @@ export const createPlugin = (
382
384
  focus: handleFocus,
383
385
  blur: handleBlur,
384
386
  mousedown: withCellTracking(handleMouseDown),
385
- mouseover: whenTableInFocus(withCellTracking(handleMouseOver)),
386
- mouseleave: whenTableInFocus(handleMouseLeave),
387
+ mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
388
+ mouseleave: handleMouseLeave,
387
389
  mouseout: whenTableInFocus(handleMouseOut),
388
390
  mousemove: whenTableInFocus(handleMouseMove, elementContentRects),
389
- click: whenTableInFocus(handleClick),
391
+ mouseenter: handleMouseEnter,
392
+ click: withCellTracking(whenTableInFocus(handleClick)),
390
393
  },
391
394
 
392
395
  handleTripleClick,
@@ -145,6 +145,7 @@ export default (
145
145
  case 'HOVER_ROWS':
146
146
  case 'HOVER_COLUMNS':
147
147
  case 'HOVER_TABLE':
148
+ case 'TABLE_HOVERED':
148
149
  case 'HOVER_MERGED_CELLS':
149
150
  case 'HOVER_CELL':
150
151
  case 'SHOW_RESIZE_HANDLE_LINE':
@@ -88,8 +88,6 @@ export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
88
88
  export interface CellHoverMeta {
89
89
  colIndex?: number;
90
90
  rowIndex?: number;
91
- colWidth?: number;
92
- colHeight?: number;
93
91
  }
94
92
 
95
93
  export interface TablePluginState {
@@ -130,6 +128,7 @@ export interface TablePluginState {
130
128
  wasFullWidthModeEnabled?: boolean;
131
129
  isTableResizingEnabled?: boolean;
132
130
  isDragAndDropEnabled?: boolean;
131
+ isTableHovered?: boolean;
133
132
  }
134
133
 
135
134
  export type TablePluginAction =
@@ -210,6 +209,12 @@ export type TablePluginAction =
210
209
  hoveredCell: CellHoverMeta;
211
210
  };
212
211
  }
212
+ | {
213
+ type: 'TABLE_HOVERED';
214
+ data: {
215
+ isTableHovered: boolean;
216
+ };
217
+ }
213
218
  | { type: 'SET_TARGET_CELL_POSITION'; data: { targetCellPosition?: number } }
214
219
  | {
215
220
  type: 'SELECT_COLUMN';
@@ -457,3 +462,5 @@ export interface DraggableData {
457
462
  targetClosestEdge: Edge;
458
463
  direction: 1 | -1;
459
464
  }
465
+
466
+ export type HandleTypes = 'hover' | 'selected';