@atlaskit/editor-plugin-table 5.3.8 → 5.3.10

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 (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/commands/hover.js +4 -2
  3. package/dist/cjs/plugins/table/event-handlers.js +7 -4
  4. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  7. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  8. package/dist/cjs/plugins/table/ui/DragHandle/index.js +6 -4
  9. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +16 -25
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +70 -0
  11. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +12 -77
  12. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  13. package/dist/cjs/plugins/table/ui/icons/index.js +19 -0
  14. package/dist/cjs/plugins/table/ui/ui-styles.js +1 -1
  15. package/dist/es2019/plugins/table/commands/hover.js +4 -2
  16. package/dist/es2019/plugins/table/event-handlers.js +7 -4
  17. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
  18. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  19. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  20. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  21. package/dist/es2019/plugins/table/ui/DragHandle/index.js +5 -3
  22. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +14 -21
  23. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +62 -0
  24. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +8 -74
  25. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +45 -19
  26. package/dist/es2019/plugins/table/ui/icons/index.js +2 -0
  27. package/dist/es2019/plugins/table/ui/ui-styles.js +0 -1
  28. package/dist/esm/plugins/table/commands/hover.js +4 -2
  29. package/dist/esm/plugins/table/event-handlers.js +7 -4
  30. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
  31. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +1 -1
  32. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +3 -2
  33. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +6 -1
  34. package/dist/esm/plugins/table/ui/DragHandle/index.js +5 -3
  35. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +15 -22
  36. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.js +61 -0
  37. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +9 -72
  38. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +45 -20
  39. package/dist/esm/plugins/table/ui/icons/index.js +2 -0
  40. package/dist/esm/plugins/table/ui/ui-styles.js +1 -1
  41. package/dist/types/plugins/table/commands/hover.d.ts +1 -1
  42. package/dist/types/plugins/table/types.d.ts +9 -4
  43. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  44. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  45. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  46. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  47. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  48. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  49. package/dist/types/plugins/table/ui/icons/index.d.ts +2 -0
  50. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
  51. package/dist/types-ts4.5/plugins/table/types.d.ts +9 -4
  52. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +4 -3
  53. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +9 -0
  54. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -3
  55. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +4 -2
  56. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  57. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  58. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +2 -0
  59. package/package.json +2 -1
  60. package/src/__tests__/unit/event-handlers.ts +4 -1
  61. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +58 -12
  62. package/src/plugins/table/commands/hover.ts +7 -2
  63. package/src/plugins/table/event-handlers.ts +18 -4
  64. package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
  65. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +1 -4
  66. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -2
  67. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +5 -0
  68. package/src/plugins/table/types.ts +14 -4
  69. package/src/plugins/table/ui/DragHandle/index.tsx +3 -1
  70. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +36 -39
  71. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +74 -0
  72. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -80
  73. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +62 -32
  74. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +2 -2
  75. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
  76. package/src/plugins/table/ui/icons/index.ts +2 -0
  77. package/src/plugins/table/ui/ui-styles.ts +0 -1
@@ -497,13 +497,14 @@ class TableComponent extends React.Component {
497
497
  const colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
498
498
  editorView: view,
499
499
  tableRef: tableRef,
500
+ getNode: getNode,
500
501
  tableActive: tableActive,
501
502
  hoveredRows: hoveredRows,
502
503
  hoveredCell: hoveredCell,
503
504
  isResizing: isResizing,
504
505
  ordering: ordering,
505
506
  hasHeaderRow: hasHeaderRow
506
- // pass `selection` and `tableHeight` to control re-render
507
+ // pass `selection` to control re-render
507
508
  ,
508
509
  selection: view.state.selection,
509
510
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
@@ -63,5 +63,5 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
63
63
  return tr.setMeta('addToHistory', false);
64
64
  }
65
65
  const move = sourceType === 'table-row' ? moveRow : moveColumn;
66
- return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
66
+ return move(sourceIndex, targetIndex)(tr);
67
67
  });
@@ -72,7 +72,8 @@ export const createPlugin = (dispatch, eventDispatcher) => {
72
72
  const {
73
73
  sourceType,
74
74
  sourceIndexes,
75
- targetAdjustedIndex
75
+ targetAdjustedIndex,
76
+ direction
76
77
  } = data;
77
78
 
78
79
  // If the drop target index contains merged cells then we should not allow the drop to occur.
@@ -82,7 +83,7 @@ export const createPlugin = (dispatch, eventDispatcher) => {
82
83
  return;
83
84
  }
84
85
  const [sourceIndex] = sourceIndexes;
85
- moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
86
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
86
87
  }
87
88
  })
88
89
  };
@@ -43,6 +43,10 @@ export const getDraggableDataFromEvent = ({
43
43
  // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
44
44
  // the new target index to be 1 index higher.
45
45
  const targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
46
+
47
+ // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
48
+ // the target index, the then the direction of the DnD is decreasing
49
+ const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
46
50
  return {
47
51
  sourceType,
48
52
  sourceLocalId,
@@ -51,6 +55,7 @@ export const getDraggableDataFromEvent = ({
51
55
  targetLocalId,
52
56
  targetIndex,
53
57
  targetAdjustedIndex: targetIndex + targetOffset,
54
- targetClosestEdge
58
+ targetClosestEdge,
59
+ direction
55
60
  };
56
61
  };
@@ -5,7 +5,7 @@ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/ut
5
5
  import { N200, N700 } from '@atlaskit/theme/colors';
6
6
  import { TableCssClassName as ClassName } from '../../types';
7
7
  import { DragPreview } from '../DragPreview';
8
- import { DragHandleIcon } from '../icons/DragHandleIcon';
8
+ import { DragHandleIcon } from '../icons';
9
9
  const mapStateToProps = state => {
10
10
  switch (state) {
11
11
  case 'danger':
@@ -84,8 +84,10 @@ export const DragHandle = ({
84
84
  backgroundColor: `${"var(--ds-surface, white)"}`,
85
85
  borderRadius: '4px',
86
86
  border: `2px solid ${"var(--ds-surface, white)"}`,
87
- transform: direction === 'column' ? 'none' : 'rotate(90deg)'
88
- }
87
+ transform: direction === 'column' ? 'none' : 'rotate(90deg)',
88
+ pointerEvents: 'auto'
89
+ },
90
+ "data-testid": "table-floating-column-controls-drag-handle"
89
91
  }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
90
92
  direction: direction,
91
93
  width: previewWidth,
@@ -1,6 +1,5 @@
1
- import React, { useMemo } from 'react';
1
+ import React from 'react';
2
2
  import { TableCssClassName as ClassName } from '../../../types';
3
- import { getColumnsWidths, getRowHeights } from '../../../utils';
4
3
  import { DragHandle } from '../../DragHandle';
5
4
  export const ColumnControls = ({
6
5
  editorView,
@@ -8,27 +7,19 @@ export const ColumnControls = ({
8
7
  tableRef,
9
8
  hoveredCell,
10
9
  isResizing,
11
- tableHeight,
12
10
  stickyTop,
13
- localId
11
+ localId,
12
+ rowHeights,
13
+ colWidths
14
14
  }) => {
15
- var _rowHeights$;
16
- const rowHeights = useMemo(() => {
17
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
18
- if (tableRef && !!tableHeight) {
19
- return getRowHeights(tableRef);
20
- }
21
- return [0];
22
- }, [tableRef, tableHeight]);
15
+ var _rowHeights$, _colWidths$map$join;
23
16
  if (!tableRef) {
24
17
  return null;
25
18
  }
26
19
  const firstRow = tableRef.querySelector('tr');
27
20
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
28
21
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
29
- const colWidths = getColumnsWidths(editorView);
30
- const widths = colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ');
31
- const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
22
+ 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';
32
23
  const onClick = (index, event) => {};
33
24
  const onMouseOver = () => {};
34
25
  const onMouseOut = () => {};
@@ -41,20 +32,22 @@ export const ColumnControls = ({
41
32
  gridTemplateColumns: widths,
42
33
  marginTop
43
34
  }
44
- }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
35
+ }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
45
36
  style: {
46
- gridColumn: `${colIndex + 1} / span 1`,
37
+ gridColumn: `${hoveredCell.colIndex + 1} / span 1`,
47
38
  marginTop: `-15px`
48
39
  },
49
- "data-column-control-index": colIndex,
40
+ "data-column-control-index": hoveredCell.colIndex,
50
41
  "data-testid": "table-floating-column-control"
51
42
  }, /*#__PURE__*/React.createElement(DragHandle, {
52
43
  direction: "column",
53
- indexes: [],
54
- onClick: event => onClick(colIndex, event),
44
+ indexes: [hoveredCell.colIndex],
45
+ onClick: event => onClick(hoveredCell.colIndex, event),
55
46
  onMouseOver: onMouseOver,
56
47
  onMouseOut: onMouseOut,
57
- tableLocalId: localId || ''
48
+ tableLocalId: localId || '',
49
+ previewWidth: hoveredCell.colWidth,
50
+ previewHeight: hoveredCell.colHeight
58
51
  }))));
59
52
  };
60
53
  export default ColumnControls;
@@ -0,0 +1,62 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
3
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
+ export const ColumnDropTarget = ({
5
+ index,
6
+ localId,
7
+ width,
8
+ height,
9
+ marginTop
10
+ }) => {
11
+ const dropTargetRef = useRef(null);
12
+ useEffect(() => {
13
+ if (!dropTargetRef.current) {
14
+ return;
15
+ }
16
+ return dropTargetForElements({
17
+ element: dropTargetRef.current,
18
+ canDrop({
19
+ source
20
+ }) {
21
+ var _data$indexes, _data$indexes2;
22
+ const data = source.data;
23
+ return (
24
+ // Only draggables of row type can be dropped on this target
25
+ data.type === 'table-column' &&
26
+ // Only draggables which came from the same table can be dropped on this target
27
+ data.localId === localId &&
28
+ // Only draggables which DO NOT include this drop targets index can be dropped
29
+ !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
30
+ );
31
+ },
32
+ getIsSticky: () => true,
33
+ getData({
34
+ input,
35
+ element
36
+ }) {
37
+ const data = {
38
+ localId,
39
+ type: 'table-column',
40
+ targetIndex: index
41
+ };
42
+ return attachClosestEdge(data, {
43
+ input,
44
+ element,
45
+ allowedEdges: ['left', 'right']
46
+ });
47
+ }
48
+ });
49
+ }, [index, localId]);
50
+ return /*#__PURE__*/React.createElement("div", {
51
+ ref: dropTargetRef,
52
+ style: {
53
+ width: width && `${width - 1}px`,
54
+ height: height && `${height}px`,
55
+ marginTop: marginTop && `${marginTop}px`,
56
+ pointerEvents: 'auto'
57
+ },
58
+ "data-drop-target-index": index,
59
+ "data-drop-target-localid": localId,
60
+ "data-testid": "table-floating-column-controls-drop-target"
61
+ });
62
+ };
@@ -1,24 +1,15 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
2
- import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
3
- import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
1
+ import React from 'react';
4
2
  import { TableCssClassName as ClassName } from '../../../types';
5
- import { getColumnsWidths, getRowHeights } from '../../../utils';
3
+ import { ColumnDropTarget } from './ColumnDropTarget';
6
4
  export const ColumnDropTargets = ({
7
- editorView,
8
5
  tableRef,
9
6
  tableHeight,
10
7
  stickyTop,
11
- localId
8
+ localId,
9
+ rowHeights,
10
+ colWidths
12
11
  }) => {
13
12
  var _rowHeights$;
14
- const colWidths = getColumnsWidths(editorView);
15
- const rowHeights = useMemo(() => {
16
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
17
- if (tableRef && !!tableHeight) {
18
- return getRowHeights(tableRef);
19
- }
20
- return [0];
21
- }, [tableRef, tableHeight]);
22
13
  if (!tableRef) {
23
14
  return null;
24
15
  }
@@ -26,11 +17,12 @@ export const ColumnDropTargets = ({
26
17
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
27
18
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
28
19
  return /*#__PURE__*/React.createElement("div", {
29
- className: ClassName.COLUMN_DROP_TARGET_CONTROLS
20
+ className: ClassName.COLUMN_DROP_TARGET_CONTROLS,
21
+ contentEditable: false
30
22
  }, /*#__PURE__*/React.createElement("div", {
31
23
  className: ClassName.COLUMN_CONTROLS_INNER,
32
24
  "data-testid": "table-floating-column-controls-drop-targets"
33
- }, colWidths.map((width, index) => {
25
+ }, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map((width, index) => {
34
26
  return /*#__PURE__*/React.createElement(ColumnDropTarget, {
35
27
  key: index,
36
28
  index: index,
@@ -40,62 +32,4 @@ export const ColumnDropTargets = ({
40
32
  marginTop: marginTop
41
33
  });
42
34
  })));
43
- };
44
- export default ColumnDropTargets;
45
- const ColumnDropTarget = ({
46
- index,
47
- localId,
48
- width,
49
- height,
50
- marginTop
51
- }) => {
52
- const dropTargetRef = useRef(null);
53
- useEffect(() => {
54
- if (!dropTargetRef.current) {
55
- return;
56
- }
57
- return dropTargetForElements({
58
- element: dropTargetRef.current,
59
- canDrop({
60
- source
61
- }) {
62
- var _data$indexes, _data$indexes2;
63
- const data = source.data;
64
- return (
65
- // Only draggables of row type can be dropped on this target
66
- data.type === 'table-column' &&
67
- // Only draggables which came from the same table can be dropped on this target
68
- data.localId === localId &&
69
- // Only draggables which DO NOT include this drop targets index can be dropped
70
- !!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
71
- );
72
- },
73
- getData({
74
- input,
75
- element
76
- }) {
77
- const data = {
78
- localId,
79
- type: 'table-column',
80
- targetIndex: index
81
- };
82
- return attachClosestEdge(data, {
83
- input,
84
- element,
85
- allowedEdges: ['left', 'right']
86
- });
87
- }
88
- });
89
- }, [index, localId]);
90
- return /*#__PURE__*/React.createElement("div", {
91
- ref: dropTargetRef,
92
- style: {
93
- width: width && `${width - 1}px`,
94
- height: height && `${height}px`,
95
- marginTop: marginTop && `${marginTop}px`
96
- },
97
- "data-drop-target-index": index,
98
- "data-drop-target-localid": localId,
99
- "data-testid": "table-floating-column-controls-drop-target"
100
- });
101
35
  };
@@ -1,12 +1,14 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
- import { findTable } from '@atlaskit/editor-tables';
3
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
4
4
  import { TableCssClassName as ClassName } from '../../types';
5
+ import { getColumnsWidths, getRowHeights } from '../../utils';
5
6
  import { ColumnControls } from './ColumnControls';
6
7
  import { ColumnDropTargets } from './ColumnDropTargets';
7
8
  export const TableFloatingColumnControls = ({
8
9
  editorView,
9
10
  tableRef,
11
+ getNode,
10
12
  tableActive,
11
13
  hasHeaderRow,
12
14
  hoveredCell,
@@ -18,6 +20,9 @@ export const TableFloatingColumnControls = ({
18
20
  width: 0,
19
21
  height: 0
20
22
  });
23
+ const [hasDropTargets, setHasDropTargets] = useState(false);
24
+ const node = getNode();
25
+ const currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
21
26
  useEffect(() => {
22
27
  var _window;
23
28
  if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
@@ -37,25 +42,44 @@ export const TableFloatingColumnControls = ({
37
42
  };
38
43
  }
39
44
  }, [tableRef]);
40
- const selectedLocalId = useMemo(() => {
41
- if (!selection) {
42
- return undefined;
43
- }
44
- const tableNode = findTable(selection);
45
- if (!tableNode) {
46
- return undefined;
45
+ useEffect(() => {
46
+ return monitorForElements({
47
+ canMonitor({
48
+ source
49
+ }) {
50
+ const {
51
+ type,
52
+ localId,
53
+ indexes
54
+ } = source.data;
55
+ return type === 'table-column' && !!(indexes !== null && indexes !== void 0 && indexes.length) && localId === currentNodeLocalId;
56
+ },
57
+ onDragStart() {
58
+ setHasDropTargets(true);
59
+ },
60
+ onDrop() {
61
+ setHasDropTargets(false);
62
+ }
63
+ });
64
+ }, [editorView, currentNodeLocalId]);
65
+ const rowHeights = useMemo(() => {
66
+ // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
67
+ if (tableRef && !!tableRect.height) {
68
+ return getRowHeights(tableRef);
47
69
  }
48
- return tableNode.node.attrs.localId;
49
- }, [selection]);
70
+ return [0];
71
+ }, [tableRef, tableRect.height]);
50
72
  if (!tableRef) {
51
73
  return null;
52
74
  }
75
+ const colWidths = getColumnsWidths(editorView);
53
76
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
54
77
  const mountTo = tableRef && (tableRef === null || tableRef === void 0 ? void 0 : tableRef.parentElement) || document.body;
55
78
  return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
56
- className: ClassName.COLUMN_CONTROLS_WRAPPER
57
- }, /*#__PURE__*/React.createElement("div", {
58
- onMouseDown: e => e.preventDefault(),
79
+ className: ClassName.COLUMN_CONTROLS_WRAPPER,
80
+ style: {
81
+ pointerEvents: 'none'
82
+ },
59
83
  "data-testid": "table-floating-column-controls-wrapper"
60
84
  }, /*#__PURE__*/React.createElement(ColumnControls, {
61
85
  editorView: editorView,
@@ -64,14 +88,16 @@ export const TableFloatingColumnControls = ({
64
88
  isResizing: isResizing,
65
89
  tableActive: tableActive,
66
90
  stickyTop: tableActive ? stickyTop : undefined,
67
- tableHeight: tableRect.height,
68
- localId: selectedLocalId
69
- }), /*#__PURE__*/React.createElement(ColumnDropTargets, {
70
- editorView: editorView,
91
+ localId: currentNodeLocalId,
92
+ rowHeights: rowHeights,
93
+ colWidths: colWidths
94
+ }), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
71
95
  tableRef: tableRef,
72
96
  stickyTop: tableActive ? stickyTop : undefined,
73
97
  tableHeight: tableRect.height,
74
- localId: selectedLocalId
75
- }))), mountTo);
98
+ localId: currentNodeLocalId,
99
+ rowHeights: rowHeights,
100
+ colWidths: colWidths
101
+ })), mountTo);
76
102
  };
77
103
  export default TableFloatingColumnControls;
@@ -0,0 +1,2 @@
1
+ export { DragHandleIcon } from './DragHandleIcon';
2
+ export { DragInMotionIcon } from './DragInMotionIcon';
@@ -292,7 +292,6 @@ export const floatingColumnControls = props => {
292
292
  box-sizing: border-box;
293
293
  position: absolute;
294
294
  top: 0;
295
- z-index: -1;
296
295
 
297
296
  .${ClassName.COLUMN_CONTROLS_INNER} {
298
297
  display: flex;
@@ -131,14 +131,16 @@ export var hideResizeHandleLine = function hideResizeHandleLine() {
131
131
  };
132
132
  });
133
133
  };
134
- export var hoverCell = function hoverCell(rowIndex, colIndex) {
134
+ export var hoverCell = function hoverCell(rowIndex, colIndex, colWidth, colHeight) {
135
135
  return createCommand(function () {
136
136
  return {
137
137
  type: 'HOVER_CELL',
138
138
  data: {
139
139
  hoveredCell: {
140
140
  rowIndex: rowIndex,
141
- colIndex: colIndex
141
+ colIndex: colIndex,
142
+ colWidth: colWidth,
143
+ colHeight: colHeight
142
144
  }
143
145
  }
144
146
  };
@@ -171,7 +171,7 @@ export var handleMouseLeave = function handleMouseLeave(view, event) {
171
171
  return true;
172
172
  }
173
173
  if (isDragAndDropEnabled) {
174
- hoverCell(undefined, undefined)(state, dispatch);
174
+ hoverCell()(state, dispatch);
175
175
  }
176
176
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && hideInsertColumnOrRowButton()(state, dispatch)) {
177
177
  return true;
@@ -317,7 +317,8 @@ export var whenTableInFocus = function whenTableInFocus(eventHandler, elementCon
317
317
  var trackCellLocation = function trackCellLocation(view, mouseEvent) {
318
318
  var target = mouseEvent.target;
319
319
  var maybeTableCell = isElementInTableCell(target);
320
- if (!maybeTableCell) {
320
+ var tableRef = getPluginState(view.state).tableRef;
321
+ if (!maybeTableCell || !tableRef) {
321
322
  return;
322
323
  }
323
324
  var colIndex = maybeTableCell.cellIndex;
@@ -325,8 +326,10 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
325
326
  var rowIndex = rowElement && rowElement.rowIndex;
326
327
  var _getPluginState8 = getPluginState(view.state),
327
328
  hoveredCell = _getPluginState8.hoveredCell;
328
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
329
- hoverCell(rowIndex, colIndex)(view.state, view.dispatch);
329
+ var colHeight = tableRef.offsetHeight;
330
+ var colWidth = maybeTableCell.offsetWidth;
331
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
332
+ hoverCell(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
330
333
  }
331
334
  };
332
335
  export var withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
@@ -492,13 +492,14 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
492
492
  var colControls = /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
493
493
  editorView: view,
494
494
  tableRef: tableRef,
495
+ getNode: getNode,
495
496
  tableActive: tableActive,
496
497
  hoveredRows: hoveredRows,
497
498
  hoveredCell: hoveredCell,
498
499
  isResizing: isResizing,
499
500
  ordering: ordering,
500
501
  hasHeaderRow: hasHeaderRow
501
- // pass `selection` and `tableHeight` to control re-render
502
+ // pass `selection` to control re-render
502
503
  ,
503
504
  selection: view.state.selection,
504
505
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
@@ -72,6 +72,6 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
72
72
  return tr.setMeta('addToHistory', false);
73
73
  }
74
74
  var move = sourceType === 'table-row' ? moveRow : moveColumn;
75
- return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
75
+ return move(sourceIndex, targetIndex)(tr);
76
76
  });
77
77
  };
@@ -69,7 +69,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
69
69
  }
70
70
  var sourceType = data.sourceType,
71
71
  sourceIndexes = data.sourceIndexes,
72
- targetAdjustedIndex = data.targetAdjustedIndex;
72
+ targetAdjustedIndex = data.targetAdjustedIndex,
73
+ direction = data.direction;
73
74
 
74
75
  // If the drop target index contains merged cells then we should not allow the drop to occur.
75
76
  var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
@@ -79,7 +80,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
79
80
  }
80
81
  var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
81
82
  sourceIndex = _sourceIndexes[0];
82
- moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
83
+ moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
83
84
  }
84
85
  })
85
86
  };
@@ -40,6 +40,10 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
40
40
  // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
41
41
  // the new target index to be 1 index higher.
42
42
  var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
43
+
44
+ // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
45
+ // the target index, the then the direction of the DnD is decreasing
46
+ var direction = sourceIndexes[0] > targetIndex ? -1 : 1;
43
47
  return {
44
48
  sourceType: sourceType,
45
49
  sourceLocalId: sourceLocalId,
@@ -48,6 +52,7 @@ export var getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref)
48
52
  targetLocalId: targetLocalId,
49
53
  targetIndex: targetIndex,
50
54
  targetAdjustedIndex: targetIndex + targetOffset,
51
- targetClosestEdge: targetClosestEdge
55
+ targetClosestEdge: targetClosestEdge,
56
+ direction: direction
52
57
  };
53
58
  };
@@ -6,7 +6,7 @@ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/ut
6
6
  import { N200, N700 } from '@atlaskit/theme/colors';
7
7
  import { TableCssClassName as ClassName } from '../../types';
8
8
  import { DragPreview } from '../DragPreview';
9
- import { DragHandleIcon } from '../icons/DragHandleIcon';
9
+ import { DragHandleIcon } from '../icons';
10
10
  var mapStateToProps = function mapStateToProps(state) {
11
11
  switch (state) {
12
12
  case 'danger':
@@ -88,8 +88,10 @@ export var DragHandle = function DragHandle(_ref) {
88
88
  backgroundColor: "var(--ds-surface, white)",
89
89
  borderRadius: '4px',
90
90
  border: "2px solid ".concat("var(--ds-surface, white)"),
91
- transform: direction === 'column' ? 'none' : 'rotate(90deg)'
92
- }
91
+ transform: direction === 'column' ? 'none' : 'rotate(90deg)',
92
+ pointerEvents: 'auto'
93
+ },
94
+ "data-testid": "table-floating-column-controls-drag-handle"
93
95
  }, /*#__PURE__*/React.createElement(DragHandleIcon, iconProps), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
94
96
  direction: direction,
95
97
  width: previewWidth,