@atlaskit/editor-plugin-table 5.4.13 → 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 (119) 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/index.js +7 -5
  15. package/dist/cjs/plugins/table/ui/DragPreview/index.js +0 -2
  16. package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +10 -7
  17. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -10
  18. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/index.js +6 -3
  19. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +7 -4
  20. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +18 -8
  21. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  22. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  23. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +12 -8
  24. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  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/index.js +8 -6
  39. package/dist/es2019/plugins/table/ui/DragPreview/index.js +0 -2
  40. package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  41. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  42. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  43. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  44. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -8
  45. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  46. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  47. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +12 -9
  48. package/dist/es2019/plugins/table/ui/common-styles.js +6 -4
  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/index.js +7 -5
  63. package/dist/esm/plugins/table/ui/DragPreview/index.js +0 -2
  64. package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +9 -7
  65. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +11 -9
  66. package/dist/esm/plugins/table/ui/FloatingContextualMenu/index.js +5 -3
  67. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +6 -4
  68. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +18 -8
  69. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  70. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +2 -1
  71. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +12 -8
  72. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  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 +6 -2
  81. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  82. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  83. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  84. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  85. package/dist/types/plugins/table/utils/dom.d.ts +4 -0
  86. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  87. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
  88. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
  89. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +1 -1
  90. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +2 -0
  91. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +1 -1
  92. package/dist/types-ts4.5/plugins/table/types.d.ts +6 -2
  93. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  94. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
  95. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
  96. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
  97. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +4 -0
  98. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  99. package/package.json +2 -2
  100. package/src/__tests__/unit/event-handlers.ts +2 -2
  101. package/src/__tests__/unit/ui/RowDragControls.tsx +1 -0
  102. package/src/plugins/table/commands/hover.ts +37 -7
  103. package/src/plugins/table/commands/index.ts +1 -0
  104. package/src/plugins/table/commands/misc.ts +9 -3
  105. package/src/plugins/table/event-handlers.ts +47 -29
  106. package/src/plugins/table/nodeviews/TableComponent.tsx +4 -1
  107. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +7 -5
  108. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +37 -2
  109. package/src/plugins/table/pm-plugins/main.ts +6 -3
  110. package/src/plugins/table/reducer.ts +1 -0
  111. package/src/plugins/table/types.ts +7 -2
  112. package/src/plugins/table/ui/DragHandle/index.tsx +7 -7
  113. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +16 -5
  114. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
  115. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +3 -1
  116. package/src/plugins/table/ui/TableFloatingControls/index.tsx +12 -5
  117. package/src/plugins/table/ui/common-styles.ts +6 -4
  118. package/src/plugins/table/utils/dom.ts +22 -0
  119. package/src/plugins/table/utils/index.ts +1 -0
@@ -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
@@ -27,9 +27,10 @@ export const ColumnControls = ({
27
27
  isInDanger,
28
28
  rowHeights,
29
29
  colWidths,
30
- hasHeaderColumn
30
+ hasHeaderColumn,
31
+ isTableHovered
31
32
  }) => {
32
- var _colWidths$map$join, _rowHeights$;
33
+ var _colWidths$map$join, _rowHeights$, _rowHeights$reduce, _colWidths;
33
34
  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
35
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
35
36
  const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
@@ -73,10 +74,14 @@ export const ColumnControls = ({
73
74
  state,
74
75
  dispatch
75
76
  } = 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);
77
+ if (tableActive) {
78
+ // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
79
+ // of the opposite dimension. For example; here when we mouse over the column drag handle then we're technically
80
+ // also hovering over row 0 index. And vice-versa with rows. This means we don't need to worry about knowing the
81
+ // current row index. We can just force it to 0.
82
+ hoverCell(0, Number(colIndex))(state, dispatch);
78
83
  }
79
- }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, tableActive]);
84
+ }, [editorView, tableActive]);
80
85
  const handleMouseOut = useCallback(() => {
81
86
  if (tableActive) {
82
87
  const {
@@ -96,6 +101,7 @@ export const ColumnControls = ({
96
101
  const colIndexes = useMemo(() => {
97
102
  return [colIndex];
98
103
  }, [colIndex]);
104
+ 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;
99
105
  return /*#__PURE__*/React.createElement("div", {
100
106
  className: ClassName.DRAG_COLUMN_CONTROLS,
101
107
  onMouseMove: handleMouseMove
@@ -123,12 +129,14 @@ export const ColumnControls = ({
123
129
  style: columnParams.length - 1 === index ? {
124
130
  right: '0'
125
131
  } : {}
126
- }))), tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
132
+ }))), tableActive && !isResizing && isTableHovered && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
127
133
  style: {
128
134
  gridColumn: gridColumnPosition,
129
135
  display: 'flex',
130
136
  justifyContent: 'center',
131
137
  alignItems: 'center',
138
+ height: 'fit-content',
139
+ placeSelf: 'center',
132
140
  zIndex: 99
133
141
  },
134
142
  "data-column-control-index": hoveredCell.colIndex,
@@ -137,8 +145,8 @@ export const ColumnControls = ({
137
145
  direction: "column",
138
146
  tableLocalId: localId || '',
139
147
  indexes: colIndexes,
140
- previewWidth: hoveredCell.colWidth,
141
- previewHeight: hoveredCell.colHeight,
148
+ previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : 48,
149
+ previewHeight: previewHeight,
142
150
  appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
143
151
  onClick: handleClick,
144
152
  onMouseOver: handleMouseOver,
@@ -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,
@@ -30,6 +30,7 @@ const DragControlsComponent = ({
30
30
  editorView,
31
31
  isInDanger,
32
32
  isResizing,
33
+ isTableHovered,
33
34
  hoverRows,
34
35
  selectRow,
35
36
  updateCellHoverLocation
@@ -146,7 +147,7 @@ const DragControlsComponent = ({
146
147
  position: 'relative',
147
148
  left: "var(--ds-space-negative-100, -8px)"
148
149
  }
149
- }))), !isResizing && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
150
+ }))), !isResizing && isTableHovered && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
150
151
  style: {
151
152
  gridRow: gridRowPosition,
152
153
  gridColumn: '2',
@@ -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,
@@ -657,19 +657,21 @@ export const tableStyles = props => {
657
657
 
658
658
  .${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
659
659
  cursor: grab;
660
- padding: 0;
660
+ pointer-events: auto;
661
661
 
662
+ line-height: 0;
663
+ padding: 0;
662
664
  border-radius: 6px;
663
665
  width: max-content;
664
- height: max-content;
665
666
  border: 2px solid ${`var(--ds-surface, ${N0})`};
667
+
666
668
  display: flex;
667
669
  justify-content: center;
668
670
  align-items: center;
669
671
  outline: none !important;
670
672
 
671
673
  &.${ClassName.DRAG_HANDLE_DISABLED} {
672
- & > svg {
674
+ & svg {
673
675
  & > rect.${ClassName.DRAG_HANDLE_MINIMISED} {
674
676
  fill: ${"var(--ds-background-accent-gray-subtler, #DCDFE4)"};
675
677
  }
@@ -683,7 +685,7 @@ export const tableStyles = props => {
683
685
  }
684
686
 
685
687
  &:not(.${ClassName.DRAG_HANDLE_DISABLED}) {
686
- & > svg {
688
+ & svg {
687
689
  rect {
688
690
  fill: ${"var(--ds-background-accent-gray-subtler, #DCDFE4)"};
689
691
  }
@@ -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
  };
@@ -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) {