@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
@@ -1,5 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ /** @jsx jsx */
2
3
  import { Component } from 'react';
4
+ import { jsx } from '@emotion/react';
3
5
  import { injectIntl } from 'react-intl-next';
4
6
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
5
7
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -73,15 +75,15 @@ export class ContextualMenu extends Component {
73
75
  value: {
74
76
  name: 'background'
75
77
  },
76
- elemAfter: /*#__PURE__*/React.createElement("div", {
78
+ elemAfter: jsx("div", {
77
79
  className: DropdownMenuSharedCssClassName.SUBMENU
78
- }, /*#__PURE__*/React.createElement("div", {
80
+ }, jsx("div", {
79
81
  css: cellColourPreviewStyles(background),
80
82
  className: ClassName.CONTEXTUAL_MENU_ICON
81
- }), isSubmenuOpen && /*#__PURE__*/React.createElement("div", {
83
+ }), isSubmenuOpen && jsx("div", {
82
84
  className: ClassName.CONTEXTUAL_SUBMENU,
83
85
  ref: this.handleSubMenuRef
84
- }, /*#__PURE__*/React.createElement(ColorPalette, {
86
+ }, jsx(ColorPalette, {
85
87
  cols: 7,
86
88
  onClick: this.setColor,
87
89
  selectedColor: background,
@@ -98,7 +100,7 @@ export class ContextualMenu extends Component {
98
100
  value: {
99
101
  name: 'insert_column'
100
102
  },
101
- elemAfter: /*#__PURE__*/React.createElement("div", {
103
+ elemAfter: jsx("div", {
102
104
  css: shortcutStyle
103
105
  }, tooltip(addColumnAfter))
104
106
  });
@@ -107,7 +109,7 @@ export class ContextualMenu extends Component {
107
109
  value: {
108
110
  name: 'insert_row'
109
111
  },
110
- elemAfter: /*#__PURE__*/React.createElement("div", {
112
+ elemAfter: jsx("div", {
111
113
  css: shortcutStyle
112
114
  }, tooltip(addRowAfter))
113
115
  });
@@ -191,7 +193,7 @@ export class ContextualMenu extends Component {
191
193
  value: {
192
194
  name: 'clear'
193
195
  },
194
- elemAfter: /*#__PURE__*/React.createElement("div", {
196
+ elemAfter: jsx("div", {
195
197
  css: shortcutStyle
196
198
  }, tooltip(backspace))
197
199
  });
@@ -373,10 +375,10 @@ export class ContextualMenu extends Component {
373
375
  if (!items) {
374
376
  return null;
375
377
  }
376
- return /*#__PURE__*/React.createElement("div", {
378
+ return jsx("div", {
377
379
  "data-testid": "table-cell-contextual-menu",
378
380
  onMouseLeave: this.closeSubmenu
379
- }, /*#__PURE__*/React.createElement(DropdownMenu, {
381
+ }, jsx(DropdownMenu, {
380
382
  mountTo: mountPoint
381
383
  //This needs be removed when the a11y is completely handled
382
384
  //Disabling key navigation now as it works only partially
@@ -1,3 +1,5 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
1
3
  import { Popup } from '@atlaskit/editor-common/ui';
2
4
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
5
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
@@ -36,7 +38,7 @@ const FloatingContextualMenu = ({
36
38
  return null;
37
39
  }
38
40
  const parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
39
- return /*#__PURE__*/React.createElement(Popup, {
41
+ return jsx(Popup, {
40
42
  alignX: "right",
41
43
  alignY: "top",
42
44
  target: targetCellRef,
@@ -52,9 +54,9 @@ const FloatingContextualMenu = ({
52
54
  forcePlacement: true,
53
55
  offset: [-7, 0],
54
56
  stick: true
55
- }, /*#__PURE__*/React.createElement("div", {
57
+ }, jsx("div", {
56
58
  css: tablePopupStyles
57
- }, /*#__PURE__*/React.createElement(ContextualMenu, {
59
+ }, jsx(ContextualMenu, {
58
60
  editorView: editorView,
59
61
  offset: [contextualMenuTriggerSize / 2, -contextualMenuTriggerSize],
60
62
  isOpen: isOpen,
@@ -1,3 +1,5 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
1
3
  import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
2
4
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
3
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -24,15 +26,15 @@ const convertToDropdownItems = dragMenuConfig => {
24
26
  name: item.id
25
27
  },
26
28
  isDisabled: item.disabled,
27
- elemBefore: item.icon ? /*#__PURE__*/React.createElement("div", {
29
+ elemBefore: item.icon ? jsx("div", {
28
30
  style: {
29
31
  marginRight: "var(--ds-space-negative-075, -6px)",
30
32
  display: 'flex'
31
33
  }
32
- }, /*#__PURE__*/React.createElement(item.icon, {
34
+ }, jsx(item.icon, {
33
35
  label: item.title
34
36
  })) : undefined,
35
- elemAfter: item.keymap ? /*#__PURE__*/React.createElement("div", {
37
+ elemAfter: item.keymap ? jsx("div", {
36
38
  css: shortcutStyle
37
39
  }, item.keymap) : undefined
38
40
  });
@@ -135,7 +137,7 @@ export const DragMenu = ({
135
137
  if (!menuItems) {
136
138
  return null;
137
139
  }
138
- return /*#__PURE__*/React.createElement(DropdownMenu, {
140
+ return jsx(DropdownMenu, {
139
141
  mountTo: mountPoint
140
142
  //This needs be removed when the a11y is completely handled
141
143
  //Disabling key navigation now as it works only partially
@@ -1,8 +1,11 @@
1
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
+
1
3
  import React, { useCallback, useMemo } from 'react';
2
4
  import { CellSelection } from '@atlaskit/editor-tables';
3
5
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
4
6
  import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
5
7
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
8
+ import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
6
9
  import { TableCssClassName as ClassName } from '../../../types';
7
10
  import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
8
11
  import { DragHandle } from '../../DragHandle';
@@ -27,21 +30,15 @@ export const ColumnControls = ({
27
30
  isInDanger,
28
31
  rowHeights,
29
32
  colWidths,
30
- hasHeaderColumn
33
+ hasHeaderColumn,
34
+ isTableHovered
31
35
  }) => {
32
- var _colWidths$map$join, _rowHeights$;
36
+ var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
33
37
  const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
34
38
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
35
39
  const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
36
40
  const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
37
41
  const selectedColIndexes = getSelectedColumns(editorView.state.selection);
38
- const gridColumnPosition = useMemo(() => {
39
- // if more than one row is selected, ensure the handle spans over the selected range
40
- if (selectedColIndexes.includes(colIndex)) {
41
- return `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
42
- }
43
- return `${colIndex + 1} / span 1`;
44
- }, [colIndex, selectedColIndexes]);
45
42
  const firstRow = tableRef.querySelector('tr');
46
43
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
47
44
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
@@ -73,10 +70,14 @@ export const ColumnControls = ({
73
70
  state,
74
71
  dispatch
75
72
  } = editorView;
76
- if (tableActive && (hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) !== Number(colIndex)) {
77
- hoverCell(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, Number(colIndex))(state, dispatch);
73
+ if (tableActive) {
74
+ // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
75
+ // of the opposite dimension. For example; here when we mouse over the column drag handle then we're technically
76
+ // also hovering over row 0 index. And vice-versa with rows. This means we don't need to worry about knowing the
77
+ // current row index. We can just force it to 0.
78
+ hoverCell(0, Number(colIndex))(state, dispatch);
78
79
  }
79
- }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, tableActive]);
80
+ }, [editorView, tableActive]);
80
81
  const handleMouseOut = useCallback(() => {
81
82
  if (tableActive) {
82
83
  const {
@@ -96,6 +97,65 @@ export const ColumnControls = ({
96
97
  const colIndexes = useMemo(() => {
97
98
  return [colIndex];
98
99
  }, [colIndex]);
100
+ const previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce((sum, cur) => sum + cur, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
101
+ const generateHandleByType = useCallback(type => {
102
+ var _colWidths;
103
+ if (!hoveredCell) {
104
+ return null;
105
+ }
106
+ const {
107
+ isDragMenuOpen,
108
+ dragMenuIndex,
109
+ dragMenuDirection
110
+ } = getDragDropPluginState(editorView.state);
111
+ const isHover = type === 'hover';
112
+ const isHoveredOnSelectedColumn = isDragMenuOpen && dragMenuDirection === 'column' && dragMenuIndex === colIndex;
113
+ const showCondition = isHover ? !isHoveredOnSelectedColumn && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : isDragMenuOpen && dragMenuDirection === 'column';
114
+ if (!showCondition) {
115
+ return null;
116
+ }
117
+ const selectedColumnPosition = `${dragMenuIndex + 1} / span ${selectedColIndexes.length}`;
118
+ const gridColumnPosition = selectedColIndexes.includes(colIndex) ? `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}` : `${colIndex + 1} / span 1`;
119
+ const selectedApprearance = isInDanger ? 'danger' : 'selected';
120
+ const hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
121
+ return showCondition && /*#__PURE__*/React.createElement("div", {
122
+ key: type,
123
+ style: {
124
+ gridColumn: isHover ? gridColumnPosition : selectedColumnPosition,
125
+ display: 'flex',
126
+ justifyContent: 'center',
127
+ alignItems: 'center',
128
+ height: 'fit-content',
129
+ placeSelf: 'center',
130
+ zIndex: 99
131
+ },
132
+ "data-column-control-index": hoveredCell.colIndex,
133
+ "data-testid": isHover ? 'table-floating-column-control' : 'table-floating-column-control-selected'
134
+ }, /*#__PURE__*/React.createElement(DragHandle, {
135
+ direction: "column",
136
+ tableLocalId: localId || '',
137
+ indexes: isHover ? colIndexes : selectedColIndexes,
138
+ forceDefaultHandle: !isHover,
139
+ previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : 48,
140
+ previewHeight: previewHeight,
141
+ appearance: isHover ? hoveredAppearance : selectedApprearance,
142
+ onClick: handleClick,
143
+ onMouseOver: handleMouseOver,
144
+ onMouseOut: handleMouseOut,
145
+ onMouseUp: handleMouseUp,
146
+ editorView: editorView
147
+ }));
148
+ }, [colIndex, previewHeight, colWidths, colIndexes, editorView, handleClick, handleMouseOut, handleMouseOver, handleMouseUp, hoveredCell, isInDanger, localId, selectedColIndexes]);
149
+ const columnHandles = useCallback(hoveredCell => {
150
+ if (!hoveredCell) {
151
+ return null;
152
+ }
153
+ if (hoveredCell.colIndex === undefined) {
154
+ return generateHandleByType('selected');
155
+ }
156
+ const sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
157
+ return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
158
+ }, [generateHandleByType, selectedColIndexes]);
99
159
  return /*#__PURE__*/React.createElement("div", {
100
160
  className: ClassName.DRAG_COLUMN_CONTROLS,
101
161
  onMouseMove: handleMouseMove
@@ -123,30 +183,6 @@ export const ColumnControls = ({
123
183
  style: columnParams.length - 1 === index ? {
124
184
  right: '0'
125
185
  } : {}
126
- }))), tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
127
- style: {
128
- gridColumn: gridColumnPosition,
129
- display: 'flex',
130
- justifyContent: 'center',
131
- alignItems: 'center',
132
- height: 'fit-content',
133
- placeSelf: 'center',
134
- zIndex: 99
135
- },
136
- "data-column-control-index": hoveredCell.colIndex,
137
- "data-testid": "table-floating-column-control"
138
- }, /*#__PURE__*/React.createElement(DragHandle, {
139
- direction: "column",
140
- tableLocalId: localId || '',
141
- indexes: colIndexes,
142
- previewWidth: hoveredCell.colWidth,
143
- previewHeight: hoveredCell.colHeight,
144
- appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
145
- onClick: handleClick,
146
- onMouseOver: handleMouseOver,
147
- onMouseOut: handleMouseOut,
148
- onMouseUp: handleMouseUp,
149
- editorView: editorView
150
- }))));
186
+ }))), tableActive && !isResizing && columnHandles(hoveredCell)));
151
187
  };
152
188
  export default ColumnControls;
@@ -14,7 +14,8 @@ export const TableFloatingColumnControls = ({
14
14
  isResizing,
15
15
  stickyHeader,
16
16
  selection,
17
- isInDanger
17
+ isInDanger,
18
+ isTableHovered
18
19
  }) => {
19
20
  const [tableRect, setTableRect] = useState({
20
21
  width: 0,
@@ -84,6 +85,7 @@ export const TableFloatingColumnControls = ({
84
85
  tableRef: tableRef,
85
86
  isResizing: isResizing,
86
87
  tableActive: tableActive,
88
+ isTableHovered: isTableHovered,
87
89
  stickyTop: tableActive ? stickyTop : undefined,
88
90
  localId: currentNodeLocalId,
89
91
  isInDanger: isInDanger,
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
+
1
3
  import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
2
4
  import { injectIntl } from 'react-intl-next';
3
5
  import { CellSelection } from '@atlaskit/editor-tables';
@@ -5,6 +7,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
7
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
6
8
  import { clearHoverSelection } from '../../../commands';
7
9
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
10
+ import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
8
11
  import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
9
12
  import { TableCssClassName as ClassName } from '../../../types';
10
13
  import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
@@ -30,6 +33,7 @@ const DragControlsComponent = ({
30
33
  editorView,
31
34
  isInDanger,
32
35
  isResizing,
36
+ isTableHovered,
33
37
  hoverRows,
34
38
  selectRow,
35
39
  updateCellHoverLocation
@@ -73,13 +77,6 @@ const DragControlsComponent = ({
73
77
  toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
74
78
  }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
75
79
  const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
76
- const gridRowPosition = useMemo(() => {
77
- // if more than one row is selected, ensure the handle spans over the selected range
78
- if (selectedRowIndexes.includes(rowIndex)) {
79
- return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
80
- }
81
- return `${rowIndex + 1} / span 1`;
82
- }, [rowIndex, selectedRowIndexes]);
83
80
  const handleMouseOut = useCallback(() => {
84
81
  if (tableActive) {
85
82
  const {
@@ -108,6 +105,63 @@ const DragControlsComponent = ({
108
105
  const handleClick = useCallback(e => {
109
106
  selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
110
107
  }, [rowIndex, selectRow]);
108
+ const generateHandleByType = useCallback(type => {
109
+ if (!hoveredCell) {
110
+ return null;
111
+ }
112
+ const {
113
+ isDragMenuOpen,
114
+ dragMenuIndex,
115
+ dragMenuDirection
116
+ } = getDragDropPluginState(editorView.state);
117
+ const isHover = type === 'hover';
118
+ const isHoveredOnSelectedRow = isDragMenuOpen && dragMenuDirection === 'row' && dragMenuIndex === rowIndex;
119
+ const showCondition = isHover ? !isHoveredOnSelectedRow && !selectedRowIndexes.includes(rowIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : isDragMenuOpen && dragMenuDirection === 'row' && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
120
+ if (!showCondition) {
121
+ return null;
122
+ }
123
+ const gridRowPosition =
124
+ // if more than one row is selected, ensure the handle spans over the selected range
125
+ selectedRowIndexes.includes(rowIndex) ? `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}` : `${rowIndex + 1} / span 1`;
126
+ const selectedRowPosition = `${dragMenuIndex + 1} / span ${selectedRowIndexes.length}`;
127
+ const selectedApprearance = isInDanger ? 'danger' : 'selected';
128
+ const hoveredAppearance = selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
129
+ return showCondition && /*#__PURE__*/React.createElement("div", {
130
+ key: type,
131
+ style: {
132
+ gridRow: isHover ? gridRowPosition : selectedRowPosition,
133
+ gridColumn: '2',
134
+ display: 'flex',
135
+ height: '100%',
136
+ alignItems: 'center',
137
+ justifyContent: 'center'
138
+ },
139
+ "data-testid": isHover ? 'table-floating-row-drag-handle' : 'table-floating-row-control-selected'
140
+ }, /*#__PURE__*/React.createElement(DragHandle, {
141
+ direction: "row",
142
+ tableLocalId: currentNodeLocalId,
143
+ indexes: isHover ? rowIndexes : selectedRowIndexes,
144
+ forceDefaultHandle: !isHover,
145
+ previewWidth: tableWidth,
146
+ previewHeight: rowHeights[rowIndex],
147
+ appearance: isHover ? hoveredAppearance : selectedApprearance,
148
+ onClick: handleClick,
149
+ onMouseOver: handleMouseOver,
150
+ onMouseOut: handleMouseOut,
151
+ onMouseUp: onMouseUp,
152
+ editorView: editorView
153
+ }));
154
+ }, [currentNodeLocalId, editorView, handleClick, handleMouseOut, handleMouseOver, hoveredCell, isInDanger, onMouseUp, rowHeights, rowIndex, rowIndexes, selectedRowIndexes, tableWidth]);
155
+ const rowHandles = useCallback(hoveredCell => {
156
+ if (!hoveredCell) {
157
+ return null;
158
+ }
159
+ if (hoveredCell.rowIndex === undefined) {
160
+ return generateHandleByType('selected');
161
+ }
162
+ const sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
163
+ return hoveredCell.rowIndex < selectedRowIndexes[0] ? sortedHandles : sortedHandles.reverse();
164
+ }, [generateHandleByType, selectedRowIndexes]);
111
165
  return /*#__PURE__*/React.createElement("div", {
112
166
  className: ClassName.DRAG_ROW_CONTROLS,
113
167
  style: {
@@ -146,27 +200,6 @@ const DragControlsComponent = ({
146
200
  position: 'relative',
147
201
  left: "var(--ds-space-negative-100, -8px)"
148
202
  }
149
- }))), !isResizing && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
150
- style: {
151
- gridRow: gridRowPosition,
152
- gridColumn: '2',
153
- display: 'flex',
154
- height: '100%',
155
- alignItems: 'center',
156
- justifyContent: 'center'
157
- },
158
- "data-testid": "table-floating-row-drag-handle"
159
- }, /*#__PURE__*/React.createElement(DragHandle, {
160
- tableLocalId: currentNodeLocalId,
161
- indexes: rowIndexes,
162
- previewWidth: tableWidth,
163
- previewHeight: rowHeights[rowIndex],
164
- appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
165
- onClick: handleClick,
166
- onMouseOver: handleMouseOver,
167
- onMouseOut: handleMouseOut,
168
- onMouseUp: onMouseUp,
169
- editorView: editorView
170
- })));
203
+ }))), !isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell));
171
204
  };
172
205
  export const DragControls = injectIntl(DragControlsComponent);
@@ -2,7 +2,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
3
  import { browser } from '@atlaskit/editor-common/utils';
4
4
  import { hoverCell, hoverRows, selectRow } from '../../commands';
5
- import { getPluginState } from '../../pm-plugins/plugin-factory';
6
5
  import { TableCssClassName as ClassName } from '../../types';
7
6
  import { isSelectionUpdated } from '../../utils';
8
7
  import { CornerControls, DragCornerControls } from './CornerControls';
@@ -42,11 +41,12 @@ export default class TableFloatingControls extends Component {
42
41
  state,
43
42
  dispatch
44
43
  } = editorView;
45
- const {
46
- hoveredCell
47
- } = getPluginState(state);
48
- if (tableActive && hoveredCell.rowIndex !== rowIndex) {
49
- hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
44
+ if (tableActive) {
45
+ // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
46
+ // of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
47
+ // also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
48
+ // current column index. We can just force it to 0.
49
+ hoverCell(rowIndex, 0)(state, dispatch);
50
50
  }
51
51
  });
52
52
  this.state = {
@@ -98,9 +98,10 @@ export default class TableFloatingControls extends Component {
98
98
  ordering,
99
99
  headerRowHeight,
100
100
  stickyHeader,
101
- hoveredCell
101
+ hoveredCell,
102
+ isTableHovered
102
103
  } = this.props;
103
- return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell;
104
+ return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
104
105
  }
105
106
  componentWillUnmount() {
106
107
  if (this.resizeObserver) {
@@ -122,7 +123,8 @@ export default class TableFloatingControls extends Component {
122
123
  hoveredRows,
123
124
  stickyHeader,
124
125
  isDragAndDropEnabled,
125
- hoveredCell
126
+ hoveredCell,
127
+ isTableHovered
126
128
  } = this.props;
127
129
  if (!tableRef) {
128
130
  return null;
@@ -155,6 +157,7 @@ export default class TableFloatingControls extends Component {
155
157
  tableRef: tableRef,
156
158
  tableNode: tableNode,
157
159
  hoveredCell: hoveredCell,
160
+ isTableHovered: isTableHovered,
158
161
  editorView: editorView,
159
162
  tableActive: tableActive,
160
163
  isInDanger: isInDanger,
@@ -177,4 +177,17 @@ export const getTop = element => {
177
177
  return 0;
178
178
  }
179
179
  return (_element$getBoundingC = element === null || element === void 0 ? void 0 : (_element$getBoundingC2 = element.getBoundingClientRect) === null || _element$getBoundingC2 === void 0 ? void 0 : (_element$getBoundingC3 = _element$getBoundingC2.call(element)) === null || _element$getBoundingC3 === void 0 ? void 0 : _element$getBoundingC3.top) !== null && _element$getBoundingC !== void 0 ? _element$getBoundingC : 0;
180
+ };
181
+ export const findNearestCellIndexToPoint = (x, y) => {
182
+ var _cell$parentElement;
183
+ const elements = document.elementsFromPoint(x, y);
184
+ const cell = elements.find(el => el.nodeName.toUpperCase() === 'TD' || el.nodeName.toUpperCase() === 'TH');
185
+ const row = (_cell$parentElement = cell === null || cell === void 0 ? void 0 : cell.parentElement) !== null && _cell$parentElement !== void 0 ? _cell$parentElement : undefined;
186
+ if (!Number.isFinite(row === null || row === void 0 ? void 0 : row.rowIndex) || !Number.isFinite(cell === null || cell === void 0 ? void 0 : cell.cellIndex)) {
187
+ return undefined;
188
+ }
189
+ return {
190
+ row: row.rowIndex,
191
+ col: cell.cellIndex
192
+ };
180
193
  };
@@ -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 { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
@@ -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
  };