@atlaskit/editor-plugin-table 5.3.9 → 5.3.11

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 (68) 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 +3 -2
  5. package/dist/cjs/plugins/table/ui/DragHandle/index.js +11 -25
  6. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +59 -22
  7. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  8. package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +15 -27
  9. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +68 -18
  10. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +47 -29
  11. package/dist/cjs/plugins/table/ui/common-styles.js +2 -2
  12. package/dist/cjs/plugins/table/ui/icons/DragHandleIcon.js +11 -52
  13. package/dist/es2019/plugins/table/commands/hover.js +4 -2
  14. package/dist/es2019/plugins/table/event-handlers.js +7 -4
  15. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +3 -2
  16. package/dist/es2019/plugins/table/ui/DragHandle/index.js +10 -24
  17. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +61 -18
  18. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  19. package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +4 -20
  20. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +69 -17
  21. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +24 -2
  22. package/dist/es2019/plugins/table/ui/common-styles.js +64 -4
  23. package/dist/es2019/plugins/table/ui/icons/DragHandleIcon.js +11 -52
  24. package/dist/esm/plugins/table/commands/hover.js +4 -2
  25. package/dist/esm/plugins/table/event-handlers.js +7 -4
  26. package/dist/esm/plugins/table/nodeviews/TableComponent.js +3 -2
  27. package/dist/esm/plugins/table/ui/DragHandle/index.js +11 -25
  28. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +56 -21
  29. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +3 -1
  30. package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +16 -28
  31. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +67 -19
  32. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +48 -30
  33. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  34. package/dist/esm/plugins/table/ui/icons/DragHandleIcon.js +11 -51
  35. package/dist/types/plugins/table/commands/hover.d.ts +1 -1
  36. package/dist/types/plugins/table/types.d.ts +8 -4
  37. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -3
  38. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
  39. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
  40. package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
  41. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
  42. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  43. package/dist/types/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
  44. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
  45. package/dist/types-ts4.5/plugins/table/types.d.ts +8 -4
  46. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -3
  47. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +6 -5
  48. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +3 -2
  49. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +1 -1
  50. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +6 -4
  51. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
  52. package/dist/types-ts4.5/plugins/table/ui/icons/DragHandleIcon.d.ts +1 -6
  53. package/package.json +1 -1
  54. package/src/__tests__/unit/event-handlers.ts +4 -1
  55. package/src/__tests__/unit/ui/NumberColumn.tsx +5 -8
  56. package/src/__tests__/unit/ui/RowDragControls.tsx +6 -0
  57. package/src/plugins/table/commands/hover.ts +7 -2
  58. package/src/plugins/table/event-handlers.ts +18 -4
  59. package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
  60. package/src/plugins/table/types.ts +13 -4
  61. package/src/plugins/table/ui/DragHandle/index.tsx +10 -26
  62. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +90 -39
  63. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +5 -2
  64. package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +10 -15
  65. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +97 -28
  66. package/src/plugins/table/ui/TableFloatingControls/index.tsx +19 -3
  67. package/src/plugins/table/ui/common-styles.ts +67 -4
  68. package/src/plugins/table/ui/icons/DragHandleIcon.tsx +5 -69
@@ -1,16 +1,27 @@
1
- import React from 'react';
1
+ import type { MouseEvent } from 'react';
2
+ import React, { useCallback, useMemo } from 'react';
2
3
 
4
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
3
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import { CellSelection } from '@atlaskit/editor-tables';
7
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
4
8
 
5
- import type { CellHoverCoordinates } from '../../../types';
9
+ import {
10
+ clearHoverSelection,
11
+ hoverColumns,
12
+ selectColumn,
13
+ } from '../../../commands';
14
+ import type { CellHoverMeta } from '../../../types';
6
15
  import { TableCssClassName as ClassName } from '../../../types';
16
+ import { getSelectedColumnIndexes } from '../../../utils';
7
17
  import { DragHandle } from '../../DragHandle';
8
18
 
9
- export interface Props {
19
+ export interface ColumnControlsProps {
10
20
  editorView: EditorView;
11
21
  tableActive?: boolean;
22
+ isInDanger?: boolean;
12
23
  tableRef: HTMLTableElement;
13
- hoveredCell?: CellHoverCoordinates;
24
+ hoveredCell?: CellHoverMeta;
14
25
  isResizing?: boolean;
15
26
  stickyTop?: number;
16
27
  localId?: string;
@@ -18,7 +29,18 @@ export interface Props {
18
29
  colWidths?: (number | undefined)[];
19
30
  }
20
31
 
21
- export const ColumnControls: React.FC<Props> = ({
32
+ const getSelectedColumns = (selection: Selection) => {
33
+ if (selection instanceof CellSelection && selection.isColSelection()) {
34
+ const rect = getSelectionRect(selection);
35
+ if (!rect) {
36
+ return [];
37
+ }
38
+ return getSelectedColumnIndexes(rect);
39
+ }
40
+ return [];
41
+ };
42
+
43
+ export const ColumnControls = ({
22
44
  editorView,
23
45
  tableActive,
24
46
  tableRef,
@@ -26,12 +48,23 @@ export const ColumnControls: React.FC<Props> = ({
26
48
  isResizing,
27
49
  stickyTop,
28
50
  localId,
51
+ isInDanger,
29
52
  rowHeights,
30
53
  colWidths,
31
- }) => {
32
- if (!tableRef) {
33
- return null;
34
- }
54
+ }: ColumnControlsProps) => {
55
+ const widths =
56
+ colWidths?.map((width) => (width ? `${width - 1}px` : '0px')).join(' ') ??
57
+ '0px';
58
+ const colIndex = hoveredCell?.colIndex;
59
+ const selectedColIndexes = getSelectedColumns(editorView.state.selection);
60
+
61
+ const gridColumnPosition = useMemo(() => {
62
+ // if more than one row is selected, ensure the handle spans over the selected range
63
+ if (selectedColIndexes.includes(colIndex!)) {
64
+ return `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
65
+ }
66
+ return `${colIndex! + 1} / span 1`;
67
+ }, [colIndex, selectedColIndexes]);
35
68
 
36
69
  const firstRow = tableRef.querySelector('tr');
37
70
  const hasHeaderRow = firstRow
@@ -41,19 +74,25 @@ export const ColumnControls: React.FC<Props> = ({
41
74
  const marginTop =
42
75
  hasHeaderRow && stickyTop !== undefined ? rowHeights?.[0] ?? 0 : 0;
43
76
 
44
- const widths =
45
- colWidths?.map((width) => (width ? `${width - 1}px` : '0px')).join(' ') ??
46
- '0px';
47
-
48
- const colIndex = hoveredCell?.colIndex;
77
+ const handleClick = useCallback(
78
+ (event: MouseEvent) => {
79
+ const { state, dispatch } = editorView;
80
+ selectColumn(colIndex!, event.shiftKey)(state, dispatch);
81
+ },
82
+ [colIndex, editorView],
83
+ );
49
84
 
50
- const onClick = (
51
- index: number,
52
- event: React.MouseEvent<Element, MouseEvent>,
53
- ) => {};
85
+ const handleMouseOver = useCallback(() => {
86
+ const { state, dispatch } = editorView;
87
+ hoverColumns([colIndex!])(state, dispatch);
88
+ }, [colIndex, editorView]);
54
89
 
55
- const onMouseOver = () => {};
56
- const onMouseOut = () => {};
90
+ const handleMouseOut = useCallback(() => {
91
+ if (tableActive) {
92
+ const { state, dispatch } = editorView;
93
+ clearHoverSelection()(state, dispatch);
94
+ }
95
+ }, [editorView, tableActive]);
57
96
 
58
97
  return (
59
98
  <div className={ClassName.COLUMN_CONTROLS_WITH_DRAG}>
@@ -65,25 +104,37 @@ export const ColumnControls: React.FC<Props> = ({
65
104
  marginTop,
66
105
  }}
67
106
  >
68
- {tableActive && !isResizing && Number.isFinite(colIndex) && (
69
- <div
70
- style={{
71
- gridColumn: `${(colIndex as number) + 1} / span 1`,
72
- marginTop: `-15px`,
73
- }}
74
- data-column-control-index={colIndex}
75
- data-testid="table-floating-column-control"
76
- >
77
- <DragHandle
78
- direction="column"
79
- indexes={[colIndex!]}
80
- onClick={(event) => onClick(colIndex as number, event)}
81
- onMouseOver={onMouseOver}
82
- onMouseOut={onMouseOut}
83
- tableLocalId={localId || ''}
84
- />
85
- </div>
86
- )}
107
+ {tableActive &&
108
+ !isResizing &&
109
+ !!hoveredCell &&
110
+ Number.isFinite(hoveredCell.colIndex) && (
111
+ <div
112
+ style={{
113
+ gridColumn: gridColumnPosition,
114
+ marginTop: `-15px`,
115
+ }}
116
+ data-column-control-index={hoveredCell.colIndex}
117
+ data-testid="table-floating-column-control"
118
+ >
119
+ <DragHandle
120
+ direction="column"
121
+ tableLocalId={localId || ''}
122
+ indexes={[hoveredCell.colIndex!]}
123
+ previewWidth={hoveredCell.colWidth}
124
+ previewHeight={hoveredCell.colHeight}
125
+ appearance={
126
+ selectedColIndexes.includes(hoveredCell.colIndex!)
127
+ ? isInDanger
128
+ ? 'danger'
129
+ : 'selected'
130
+ : 'default'
131
+ }
132
+ onClick={handleClick}
133
+ onMouseOver={handleMouseOver}
134
+ onMouseOut={handleMouseOut}
135
+ />
136
+ </div>
137
+ )}
87
138
  </div>
88
139
  </div>
89
140
  );
@@ -10,7 +10,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
11
11
 
12
12
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
13
- import type { CellHoverCoordinates, DraggableSourceData } from '../../types';
13
+ import type { CellHoverMeta, DraggableSourceData } from '../../types';
14
14
  import { TableCssClassName as ClassName } from '../../types';
15
15
  import { getColumnsWidths, getRowHeights } from '../../utils';
16
16
 
@@ -24,10 +24,11 @@ export interface Props {
24
24
  tableRef?: HTMLTableElement;
25
25
  getNode: () => PmNode;
26
26
  tableActive?: boolean;
27
+ isInDanger?: boolean;
27
28
  hasHeaderRow?: boolean;
28
29
  headerRowHeight?: number;
29
30
  hoveredRows?: number[];
30
- hoveredCell?: CellHoverCoordinates;
31
+ hoveredCell?: CellHoverMeta;
31
32
  isResizing?: boolean;
32
33
  ordering?: TableColumnOrdering;
33
34
  stickyHeader?: RowStickyState;
@@ -43,6 +44,7 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
43
44
  isResizing,
44
45
  stickyHeader,
45
46
  selection,
47
+ isInDanger,
46
48
  }) => {
47
49
  const [tableRect, setTableRect] = useState<{ width: number; height: number }>(
48
50
  { width: 0, height: 0 },
@@ -132,6 +134,7 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
132
134
  tableActive={tableActive}
133
135
  stickyTop={tableActive ? stickyTop : undefined}
134
136
  localId={currentNodeLocalId}
137
+ isInDanger={isInDanger}
135
138
  rowHeights={rowHeights}
136
139
  colWidths={colWidths}
137
140
  />
@@ -6,8 +6,7 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { isRowSelected } from '@atlaskit/editor-tables/utils';
8
8
 
9
- import { clearHoverSelection, hoverCell } from '../../../commands';
10
- import { getPluginState } from '../../../pm-plugins/plugin-factory';
9
+ import { clearHoverSelection } from '../../../commands';
11
10
  import { TableCssClassName as ClassName } from '../../../types';
12
11
  import { getRowHeights } from '../../../utils';
13
12
  import { tableBorderColor } from '../../consts';
@@ -19,6 +18,7 @@ export interface Props {
19
18
  hoverRows: (rows: number[], danger?: boolean) => void;
20
19
  hoveredRows?: number[];
21
20
  selectRow: (row: number, expand: boolean) => void;
21
+ updateCellHoverLocation: (rowIndex: number) => void;
22
22
  hasHeaderRow?: boolean;
23
23
  isInDanger?: boolean;
24
24
  isResizing?: boolean;
@@ -28,8 +28,13 @@ export interface Props {
28
28
 
29
29
  export default class NumberColumn extends Component<Props, any> {
30
30
  render() {
31
- const { tableRef, hasHeaderRow, isDragAndDropEnabled, tableActive } =
32
- this.props;
31
+ const {
32
+ tableRef,
33
+ hasHeaderRow,
34
+ isDragAndDropEnabled,
35
+ tableActive,
36
+ updateCellHoverLocation,
37
+ } = this.props;
33
38
  const rowHeights = getRowHeights(tableRef);
34
39
 
35
40
  return (
@@ -54,7 +59,7 @@ export default class NumberColumn extends Component<Props, any> {
54
59
  className={this.getClassNames(index, true)}
55
60
  data-index={index}
56
61
  style={this.getCellStyles(index, rowHeight)}
57
- onMouseOver={() => this.updateDragHandleLocation(index)}
62
+ onMouseOver={() => updateCellHoverLocation(index)}
58
63
  >
59
64
  {hasHeaderRow ? (index > 0 ? index : null) : index + 1}
60
65
  </div>
@@ -109,16 +114,6 @@ export default class NumberColumn extends Component<Props, any> {
109
114
  }
110
115
  };
111
116
 
112
- private updateDragHandleLocation = (rowIndex: number) => {
113
- const { editorView, tableActive } = this.props;
114
- const { state, dispatch } = editorView;
115
- const { hoveredCell } = getPluginState(state);
116
-
117
- if (tableActive && hoveredCell.rowIndex !== rowIndex) {
118
- hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
119
- }
120
- };
121
-
122
117
  private getCellStyles = (index: number, rowHeight: number) => {
123
118
  const { stickyTop, hasHeaderRow } = this.props;
124
119
  if (stickyTop && hasHeaderRow && index === 0) {
@@ -1,76 +1,145 @@
1
- import React from 'react';
1
+ import type { MouseEvent } from 'react';
2
+ import React, { useCallback, useMemo } from 'react';
2
3
 
3
4
  import { injectIntl } from 'react-intl-next';
4
5
  import type { WrappedComponentProps } from 'react-intl-next';
5
6
 
7
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
6
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
- import { findTable } from '@atlaskit/editor-tables/utils';
9
+ import { CellSelection } from '@atlaskit/editor-tables';
10
+ import { findTable, getSelectionRect } from '@atlaskit/editor-tables/utils';
8
11
 
9
- import type { CellHoverCoordinates } from '../../../types';
12
+ import { clearHoverSelection } from '../../../commands';
13
+ import type { CellHoverMeta } from '../../../types';
10
14
  import { TableCssClassName as ClassName } from '../../../types';
11
- import { getRowHeights } from '../../../utils';
15
+ import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
12
16
  import { DragHandle } from '../../DragHandle';
13
17
 
14
18
  type DragControlsProps = {
15
19
  editorView: EditorView;
16
20
  tableRef: HTMLTableElement;
17
21
  tableActive?: boolean;
18
- hoveredCell?: CellHoverCoordinates;
19
- hoverRows?: (rows: number[], danger?: boolean) => void;
20
- selectRow?: (row: number, expand: boolean) => void;
22
+ hoveredCell?: CellHoverMeta;
23
+ isInDanger?: boolean;
24
+ hoverRows: (rows: number[], danger?: boolean) => void;
25
+ selectRow: (row: number, expand: boolean) => void;
26
+ updateCellHoverLocation: (rowIndex: number) => void;
27
+ };
28
+
29
+ const getSelectedRows = (selection: Selection) => {
30
+ if (selection instanceof CellSelection && selection.isRowSelection()) {
31
+ const rect = getSelectionRect(selection);
32
+ if (!rect) {
33
+ return [];
34
+ }
35
+ return getSelectedRowIndexes(rect);
36
+ }
37
+ return [];
21
38
  };
22
39
 
23
40
  const DragControlsComponent = ({
24
41
  tableRef,
25
42
  hoveredCell,
26
- hoverRows,
27
- selectRow,
28
43
  tableActive,
29
44
  editorView,
45
+ isInDanger,
46
+ hoverRows,
47
+ selectRow,
48
+ updateCellHoverLocation,
30
49
  }: DragControlsProps & WrappedComponentProps) => {
31
50
  const rowHeights = getRowHeights(tableRef);
32
- const heights = rowHeights
33
- .map((height, index) => `${height - 1}px`)
34
- .join(' ');
51
+ const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
52
+ const selectedRowIndexes = getSelectedRows(editorView.state.selection);
35
53
  const rowWidth = tableRef.offsetWidth;
36
-
37
- const onClick = (
38
- index: number,
39
- event: React.MouseEvent<Element, MouseEvent>,
40
- ) => {};
41
-
42
- const onMouseOver = () => {};
43
- const onMouseOut = () => {};
44
-
45
54
  const rowIndex = hoveredCell?.rowIndex;
46
55
 
56
+ const gridRowPosition = useMemo(() => {
57
+ // if more than one row is selected, ensure the handle spans over the selected range
58
+ if (selectedRowIndexes.includes(rowIndex!)) {
59
+ return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
60
+ }
61
+ return `${rowIndex! + 1} / span 1`;
62
+ }, [rowIndex, selectedRowIndexes]);
63
+
47
64
  const getLocalId = () => {
48
65
  const tableNode = findTable(editorView.state.selection);
49
66
  return tableNode?.node?.attrs?.localId || '';
50
67
  };
51
68
 
69
+ const handleMouseOut = useCallback(() => {
70
+ if (tableActive) {
71
+ const { state, dispatch } = editorView;
72
+ clearHoverSelection()(state, dispatch);
73
+ }
74
+ }, [editorView, tableActive]);
75
+
76
+ const handleMouseMove = useCallback(
77
+ (e: MouseEvent) => {
78
+ // avoid updating if event target is drag handle
79
+ if (
80
+ !(e.nativeEvent.target as Element).classList.contains(
81
+ ClassName.ROW_CONTROLS_WITH_DRAG,
82
+ )
83
+ ) {
84
+ return;
85
+ }
86
+
87
+ const hoverHeight = e.nativeEvent.offsetY;
88
+ let totalHeight = 0;
89
+ const rowIndex = rowHeights.findIndex((row) => {
90
+ totalHeight += row;
91
+ return hoverHeight <= totalHeight;
92
+ });
93
+
94
+ updateCellHoverLocation(rowIndex);
95
+ },
96
+ [updateCellHoverLocation, rowHeights],
97
+ );
98
+
99
+ const handleMouseOver = useCallback(() => {
100
+ hoverRows([rowIndex!]);
101
+ }, [hoverRows, rowIndex]);
102
+
103
+ const handleClick = useCallback(
104
+ (e: MouseEvent) => {
105
+ selectRow(rowIndex!, e?.shiftKey);
106
+ },
107
+ [rowIndex, selectRow],
108
+ );
109
+
52
110
  return (
53
111
  <div
54
112
  className={ClassName.ROW_CONTROLS_WITH_DRAG}
55
113
  style={{
56
114
  gridTemplateRows: heights,
57
115
  }}
116
+ onMouseMove={handleMouseMove}
58
117
  >
59
- {rowIndex !== undefined && Number.isFinite(rowIndex) && (
118
+ {Number.isFinite(rowIndex) && (
60
119
  <div
61
120
  style={{
62
- gridRow: `${(rowIndex as number) + 1} / span 1`,
121
+ gridRow: gridRowPosition,
63
122
  display: 'flex',
123
+ height: '100%',
124
+ alignItems: 'center',
125
+ justifyContent: 'center',
64
126
  }}
65
127
  >
66
128
  <DragHandle
67
- onClick={(event) => onClick(rowIndex as number, event)}
68
- onMouseOver={onMouseOver}
69
- onMouseOut={onMouseOut}
70
129
  tableLocalId={getLocalId()}
71
- indexes={[rowIndex]}
130
+ indexes={[rowIndex!]}
72
131
  previewWidth={rowWidth}
73
- previewHeight={rowHeights[rowIndex]}
132
+ previewHeight={rowHeights[rowIndex!]}
133
+ appearance={
134
+ selectedRowIndexes.includes(rowIndex!)
135
+ ? isInDanger
136
+ ? 'danger'
137
+ : 'selected'
138
+ : 'default'
139
+ }
140
+ onClick={handleClick}
141
+ onMouseOver={handleMouseOver}
142
+ onMouseOut={handleMouseOut}
74
143
  />
75
144
  </div>
76
145
  )}
@@ -5,9 +5,10 @@ import { browser } from '@atlaskit/editor-common/utils';
5
5
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
- import { hoverRows, selectRow } from '../../commands';
8
+ import { hoverCell, hoverRows, selectRow } from '../../commands';
9
+ import { getPluginState } from '../../pm-plugins/plugin-factory';
9
10
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
10
- import type { CellHoverCoordinates } from '../../types';
11
+ import type { CellHoverMeta } from '../../types';
11
12
  import { isSelectionUpdated } from '../../utils';
12
13
 
13
14
  import { CornerControls } from './CornerControls';
@@ -28,7 +29,7 @@ export interface Props {
28
29
  hasHeaderRow?: boolean;
29
30
  headerRowHeight?: number;
30
31
  hoveredRows?: number[];
31
- hoveredCell?: CellHoverCoordinates;
32
+ hoveredCell?: CellHoverMeta;
32
33
  ordering?: TableColumnOrdering;
33
34
  stickyHeader?: RowStickyState;
34
35
  }
@@ -145,6 +146,7 @@ export default class TableFloatingControls extends Component<Props, State> {
145
146
  isInDanger={isInDanger}
146
147
  isResizing={isResizing}
147
148
  selectRow={this.selectRow}
149
+ updateCellHoverLocation={this.updateCellHoverLocation}
148
150
  stickyTop={stickyTop}
149
151
  isDragAndDropEnabled={isDragAndDropEnabled}
150
152
  />
@@ -157,8 +159,11 @@ export default class TableFloatingControls extends Component<Props, State> {
157
159
  tableRef={tableRef}
158
160
  hoveredCell={hoveredCell}
159
161
  editorView={editorView}
162
+ tableActive={tableActive}
163
+ isInDanger={isInDanger}
160
164
  hoverRows={this.hoverRows}
161
165
  selectRow={this.selectRow}
166
+ updateCellHoverLocation={this.updateCellHoverLocation}
162
167
  />
163
168
  ) : (
164
169
  <>
@@ -204,4 +209,15 @@ export default class TableFloatingControls extends Component<Props, State> {
204
209
  const { state, dispatch } = this.props.editorView;
205
210
  hoverRows(rows, danger)(state, dispatch);
206
211
  };
212
+
213
+ // re-use across numbered columns and row controls
214
+ private updateCellHoverLocation = (rowIndex: number) => {
215
+ const { editorView, tableActive } = this.props;
216
+ const { state, dispatch } = editorView;
217
+ const { hoveredCell } = getPluginState(state);
218
+
219
+ if (tableActive && hoveredCell.rowIndex !== rowIndex) {
220
+ hoverCell(rowIndex, hoveredCell.colIndex)(state, dispatch);
221
+ }
222
+ };
207
223
  }
@@ -249,7 +249,7 @@ const tableRowControlStyles = () => {
249
249
  position: absolute;
250
250
  margin-top: ${tableMarginTop}px;
251
251
  left: -${tableToolbarSize + 1}px;
252
- z-index: ${rowControlsZIndex};
252
+ z-index: ${rowControlsZIndex + 4};
253
253
  }
254
254
  `
255
255
  : css`
@@ -705,14 +705,77 @@ export const tableStyles = (
705
705
  align-items: center;
706
706
  position: absolute;
707
707
  left: -4px;
708
+ z-index: ${akEditorUnitZIndex};
708
709
  }
709
710
 
710
711
  .${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
711
712
  cursor: grab;
712
- width: max-content;
713
713
  padding: 0;
714
- border: none;
715
- background: none;
714
+
715
+ border-radius: 6px;
716
+ width: max-content;
717
+ height: max-content;
718
+ border: 2px solid ${token('elevation.surface', N0)};
719
+ display: flex;
720
+ justify-content: center;
721
+ align-items: center;
722
+
723
+ svg {
724
+ rect {
725
+ //
726
+ fill: ${token('color.background.accent.gray.subtlest', '#F1F2F4')};
727
+ }
728
+ g {
729
+ fill: ${token('color.icon.subtle', '#626F86')};
730
+ }
731
+ }
732
+
733
+ &:hover {
734
+ svg {
735
+ rect {
736
+ fill: ${token('color.background.accent.blue.subtle', '#579DFF')};
737
+ }
738
+ g {
739
+ fill: ${token('color.icon.inverse', '#FFF')};
740
+ }
741
+ }
742
+ }
743
+
744
+ &.selected {
745
+ svg {
746
+ rect {
747
+ fill: ${token('color.background.accent.blue.subtle', '#579DFF')};
748
+ }
749
+ g {
750
+ fill: ${token('color.icon.inverse', '#FFF')};
751
+ }
752
+ }
753
+ }
754
+
755
+ &.danger {
756
+ svg {
757
+ rect {
758
+ fill: ${token(
759
+ 'color.background.accent.red.subtler.pressed',
760
+ '#F87462',
761
+ )};
762
+ }
763
+ g {
764
+ fill: ${token('color.border.inverse', '#FFF')};
765
+ }
766
+ }
767
+ }
768
+
769
+ &.disabled {
770
+ svg {
771
+ rect {
772
+ fill: ${token('color.background.accent.gray.subtlest', '#F1F2F4')};
773
+ }
774
+ g {
775
+ fill: ${token('color.border.inverse', '#FFF')};
776
+ }
777
+ }
778
+ }
716
779
  }
717
780
 
718
781
  ${floatingColumnControls(props)}
@@ -1,74 +1,10 @@
1
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
2
1
  import React from 'react';
3
2
 
4
- interface DragHandleIconProps {
5
- backgroundColor?: string;
6
- foregroundColor?: string;
7
- }
8
-
9
- export const DragHandleIcon = ({
10
- backgroundColor,
11
- foregroundColor,
12
- }: DragHandleIconProps) => (
13
- <svg
14
- width="28"
15
- height="20"
16
- viewBox="0 0 28 20"
17
- fill="none"
18
- xmlns="http://www.w3.org/2000/svg"
19
- >
20
- <rect
21
- x="1"
22
- y="1"
23
- width="26"
24
- height="18"
25
- rx="5"
26
- fill={backgroundColor || '#F1F2F4'}
27
- />
28
- <g clipPath="url(#clip0_125_45007)">
29
- <path
30
- d="M11 12C11 11.4477 10.5523 11 10 11C9.44772 11 9 11.4477 9 12C9 12.5523 9.44772 13 10 13C10.5523 13 11 12.5523 11 12Z"
31
- fill={foregroundColor || '#626F86'}
32
- />
33
- <path
34
- d="M11 8C11 7.44772 10.5523 7 10 7C9.44772 7 9 7.44772 9 8C9 8.55228 9.44772 9 10 9C10.5523 9 11 8.55228 11 8Z"
35
- fill={foregroundColor || '#626F86'}
36
- />
37
- <path
38
- d="M19 12C19 11.4477 18.5523 11 18 11C17.4477 11 17 11.4477 17 12C17 12.5523 17.4477 13 18 13C18.5523 13 19 12.5523 19 12Z"
39
- fill={foregroundColor || '#626F86'}
40
- />
41
- <path
42
- d="M19 8C19 7.44772 18.5523 7 18 7C17.4477 7 17 7.44772 17 8C17 8.55228 17.4477 9 18 9C18.5523 9 19 8.55228 19 8Z"
43
- fill={foregroundColor || '#626F86'}
44
- />
45
- <path
46
- d="M15 12C15 11.4477 14.5523 11 14 11C13.4477 11 13 11.4477 13 12C13 12.5523 13.4477 13 14 13C14.5523 13 15 12.5523 15 12Z"
47
- fill={foregroundColor || '#626F86'}
48
- />
49
- <path
50
- d="M15 8C15 7.44772 14.5523 7 14 7C13.4477 7 13 7.44772 13 8C13 8.55228 13.4477 9 14 9C14.5523 9 15 8.55228 15 8Z"
51
- fill={foregroundColor || '#626F86'}
52
- />
3
+ export const DragHandleIcon = () => (
4
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none">
5
+ <rect width="24" height="16" rx="4" />
6
+ <g>
7
+ <path d="M9 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM9 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM17 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 10a1 1 0 1 0-2 0 1 1 0 0 0 2 0ZM13 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z" />
53
8
  </g>
54
- <rect
55
- x="1"
56
- y="1"
57
- width="26"
58
- height="18"
59
- rx="5"
60
- stroke="white"
61
- strokeWidth="2"
62
- />
63
- <defs>
64
- <clipPath id="clip0_125_45007">
65
- <rect
66
- width="16"
67
- height="24"
68
- fill="white"
69
- transform="matrix(0 -1 1 0 2 18)"
70
- />
71
- </clipPath>
72
- </defs>
73
9
  </svg>
74
10
  );