@atlaskit/editor-plugin-table 5.3.9 → 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 (31) hide show
  1. package/CHANGELOG.md +6 -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/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -7
  5. package/dist/es2019/plugins/table/commands/hover.js +4 -2
  6. package/dist/es2019/plugins/table/event-handlers.js +7 -4
  7. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -7
  8. package/dist/esm/plugins/table/commands/hover.js +4 -2
  9. package/dist/esm/plugins/table/event-handlers.js +7 -4
  10. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -7
  11. package/dist/types/plugins/table/commands/hover.d.ts +1 -1
  12. package/dist/types/plugins/table/types.d.ts +8 -4
  13. package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  14. package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +2 -2
  15. package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  16. package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  17. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +1 -1
  18. package/dist/types-ts4.5/plugins/table/types.d.ts +8 -4
  19. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  20. package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +2 -2
  21. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -2
  22. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +2 -2
  23. package/package.json +1 -1
  24. package/src/__tests__/unit/event-handlers.ts +4 -1
  25. package/src/plugins/table/commands/hover.ts +7 -2
  26. package/src/plugins/table/event-handlers.ts +18 -4
  27. package/src/plugins/table/types.ts +13 -4
  28. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +28 -23
  29. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +2 -2
  30. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +2 -2
  31. package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.3.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#42000](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42000) [`62e03b45cf6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/62e03b45cf6) - Updated the column drag handle to display the drag preview correctly
8
+
3
9
  ## 5.3.9
4
10
 
5
11
  ### Patch Changes
@@ -138,14 +138,16 @@ var hideResizeHandleLine = exports.hideResizeHandleLine = function hideResizeHan
138
138
  };
139
139
  });
140
140
  };
141
- var hoverCell = exports.hoverCell = function hoverCell(rowIndex, colIndex) {
141
+ var hoverCell = exports.hoverCell = function hoverCell(rowIndex, colIndex, colWidth, colHeight) {
142
142
  return (0, _pluginFactory.createCommand)(function () {
143
143
  return {
144
144
  type: 'HOVER_CELL',
145
145
  data: {
146
146
  hoveredCell: {
147
147
  rowIndex: rowIndex,
148
- colIndex: colIndex
148
+ colIndex: colIndex,
149
+ colWidth: colWidth,
150
+ colHeight: colHeight
149
151
  }
150
152
  }
151
153
  };
@@ -180,7 +180,7 @@ var handleMouseLeave = exports.handleMouseLeave = function handleMouseLeave(view
180
180
  return true;
181
181
  }
182
182
  if (isDragAndDropEnabled) {
183
- (0, _commands.hoverCell)(undefined, undefined)(state, dispatch);
183
+ (0, _commands.hoverCell)()(state, dispatch);
184
184
  }
185
185
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && (0, _commands.hideInsertColumnOrRowButton)()(state, dispatch)) {
186
186
  return true;
@@ -326,7 +326,8 @@ var whenTableInFocus = exports.whenTableInFocus = function whenTableInFocus(even
326
326
  var trackCellLocation = function trackCellLocation(view, mouseEvent) {
327
327
  var target = mouseEvent.target;
328
328
  var maybeTableCell = (0, _utils.isElementInTableCell)(target);
329
- if (!maybeTableCell) {
329
+ var tableRef = (0, _pluginFactory.getPluginState)(view.state).tableRef;
330
+ if (!maybeTableCell || !tableRef) {
330
331
  return;
331
332
  }
332
333
  var colIndex = maybeTableCell.cellIndex;
@@ -334,8 +335,10 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
334
335
  var rowIndex = rowElement && rowElement.rowIndex;
335
336
  var _getPluginState8 = (0, _pluginFactory.getPluginState)(view.state),
336
337
  hoveredCell = _getPluginState8.hoveredCell;
337
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
338
- (0, _commands.hoverCell)(rowIndex, colIndex)(view.state, view.dispatch);
338
+ var colHeight = tableRef.offsetHeight;
339
+ var colWidth = maybeTableCell.offsetWidth;
340
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
341
+ (0, _commands.hoverCell)(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
339
342
  }
340
343
  };
341
344
  var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
@@ -28,7 +28,6 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
28
28
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
29
29
  return width ? "".concat(width - 1, "px") : '0px';
30
30
  }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
31
- var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
32
31
  var _onClick = function onClick(index, event) {};
33
32
  var onMouseOver = function onMouseOver() {};
34
33
  var onMouseOut = function onMouseOut() {};
@@ -41,22 +40,24 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
41
40
  gridTemplateColumns: widths,
42
41
  marginTop: marginTop
43
42
  }
44
- }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/_react.default.createElement("div", {
43
+ }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/_react.default.createElement("div", {
45
44
  style: {
46
- gridColumn: "".concat(colIndex + 1, " / span 1"),
45
+ gridColumn: "".concat(hoveredCell.colIndex + 1, " / span 1"),
47
46
  marginTop: "-15px"
48
47
  },
49
- "data-column-control-index": colIndex,
48
+ "data-column-control-index": hoveredCell.colIndex,
50
49
  "data-testid": "table-floating-column-control"
51
50
  }, /*#__PURE__*/_react.default.createElement(_DragHandle.DragHandle, {
52
51
  direction: "column",
53
- indexes: [colIndex],
52
+ indexes: [hoveredCell.colIndex],
54
53
  onClick: function onClick(event) {
55
- return _onClick(colIndex, event);
54
+ return _onClick(hoveredCell.colIndex, event);
56
55
  },
57
56
  onMouseOver: onMouseOver,
58
57
  onMouseOut: onMouseOut,
59
- tableLocalId: localId || ''
58
+ tableLocalId: localId || '',
59
+ previewWidth: hoveredCell.colWidth,
60
+ previewHeight: hoveredCell.colHeight
60
61
  }))));
61
62
  };
62
63
  var _default = exports.default = ColumnControls;
@@ -99,13 +99,15 @@ export const hideResizeHandleLine = () => createCommand(state => ({
99
99
  decorationSet: updatePluginStateDecorations(state, [], TableDecorations.COLUMN_RESIZING_HANDLE_LINE)
100
100
  }
101
101
  }));
102
- export const hoverCell = (rowIndex, colIndex) => createCommand(() => {
102
+ export const hoverCell = (rowIndex, colIndex, colWidth, colHeight) => createCommand(() => {
103
103
  return {
104
104
  type: 'HOVER_CELL',
105
105
  data: {
106
106
  hoveredCell: {
107
107
  rowIndex,
108
- colIndex
108
+ colIndex,
109
+ colWidth,
110
+ colHeight
109
111
  }
110
112
  }
111
113
  };
@@ -179,7 +179,7 @@ export const handleMouseLeave = (view, event) => {
179
179
  return true;
180
180
  }
181
181
  if (isDragAndDropEnabled) {
182
- hoverCell(undefined, undefined)(state, dispatch);
182
+ hoverCell()(state, dispatch);
183
183
  }
184
184
  if ((typeof insertColumnButtonIndex !== 'undefined' || typeof insertRowButtonIndex !== 'undefined') && hideInsertColumnOrRowButton()(state, dispatch)) {
185
185
  return true;
@@ -334,7 +334,8 @@ export const whenTableInFocus = (eventHandler, elementContentRects) => (view, mo
334
334
  const trackCellLocation = (view, mouseEvent) => {
335
335
  const target = mouseEvent.target;
336
336
  const maybeTableCell = isElementInTableCell(target);
337
- if (!maybeTableCell) {
337
+ const tableRef = getPluginState(view.state).tableRef;
338
+ if (!maybeTableCell || !tableRef) {
338
339
  return;
339
340
  }
340
341
  const colIndex = maybeTableCell.cellIndex;
@@ -343,8 +344,10 @@ const trackCellLocation = (view, mouseEvent) => {
343
344
  const {
344
345
  hoveredCell
345
346
  } = getPluginState(view.state);
346
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
347
- hoverCell(rowIndex, colIndex)(view.state, view.dispatch);
347
+ const colHeight = tableRef.offsetHeight;
348
+ const colWidth = maybeTableCell.offsetWidth;
349
+ if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex || hoveredCell.colWidth !== colWidth || hoveredCell.colHeight !== colHeight) {
350
+ hoverCell(rowIndex, colIndex, colWidth, colHeight)(view.state, view.dispatch);
348
351
  }
349
352
  };
350
353
  export const withCellTracking = (eventHandler, elementContentRects) => (view, mouseEvent) => {
@@ -20,7 +20,6 @@ export const ColumnControls = ({
20
20
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
21
21
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
22
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';
23
- const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
24
23
  const onClick = (index, event) => {};
25
24
  const onMouseOver = () => {};
26
25
  const onMouseOut = () => {};
@@ -33,20 +32,22 @@ export const ColumnControls = ({
33
32
  gridTemplateColumns: widths,
34
33
  marginTop
35
34
  }
36
- }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
35
+ }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
37
36
  style: {
38
- gridColumn: `${colIndex + 1} / span 1`,
37
+ gridColumn: `${hoveredCell.colIndex + 1} / span 1`,
39
38
  marginTop: `-15px`
40
39
  },
41
- "data-column-control-index": colIndex,
40
+ "data-column-control-index": hoveredCell.colIndex,
42
41
  "data-testid": "table-floating-column-control"
43
42
  }, /*#__PURE__*/React.createElement(DragHandle, {
44
43
  direction: "column",
45
- indexes: [colIndex],
46
- onClick: event => onClick(colIndex, event),
44
+ indexes: [hoveredCell.colIndex],
45
+ onClick: event => onClick(hoveredCell.colIndex, event),
47
46
  onMouseOver: onMouseOver,
48
47
  onMouseOut: onMouseOut,
49
- tableLocalId: localId || ''
48
+ tableLocalId: localId || '',
49
+ previewWidth: hoveredCell.colWidth,
50
+ previewHeight: hoveredCell.colHeight
50
51
  }))));
51
52
  };
52
53
  export default ColumnControls;
@@ -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) {
@@ -21,7 +21,6 @@ export var ColumnControls = function ColumnControls(_ref) {
21
21
  var widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(function (width) {
22
22
  return width ? "".concat(width - 1, "px") : '0px';
23
23
  }).join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
24
- var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
25
24
  var _onClick = function onClick(index, event) {};
26
25
  var onMouseOver = function onMouseOver() {};
27
26
  var onMouseOut = function onMouseOut() {};
@@ -34,22 +33,24 @@ export var ColumnControls = function ColumnControls(_ref) {
34
33
  gridTemplateColumns: widths,
35
34
  marginTop: marginTop
36
35
  }
37
- }, tableActive && !isResizing && Number.isFinite(colIndex) && /*#__PURE__*/React.createElement("div", {
36
+ }, tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
38
37
  style: {
39
- gridColumn: "".concat(colIndex + 1, " / span 1"),
38
+ gridColumn: "".concat(hoveredCell.colIndex + 1, " / span 1"),
40
39
  marginTop: "-15px"
41
40
  },
42
- "data-column-control-index": colIndex,
41
+ "data-column-control-index": hoveredCell.colIndex,
43
42
  "data-testid": "table-floating-column-control"
44
43
  }, /*#__PURE__*/React.createElement(DragHandle, {
45
44
  direction: "column",
46
- indexes: [colIndex],
45
+ indexes: [hoveredCell.colIndex],
47
46
  onClick: function onClick(event) {
48
- return _onClick(colIndex, event);
47
+ return _onClick(hoveredCell.colIndex, event);
49
48
  },
50
49
  onMouseOver: onMouseOver,
51
50
  onMouseOut: onMouseOut,
52
- tableLocalId: localId || ''
51
+ tableLocalId: localId || '',
52
+ previewWidth: hoveredCell.colWidth,
53
+ previewHeight: hoveredCell.colHeight
53
54
  }))));
54
55
  };
55
56
  export default ColumnControls;
@@ -6,4 +6,4 @@ export declare const hoverTable: (isInDanger?: boolean, isSelected?: boolean) =>
6
6
  export declare const clearHoverSelection: () => import("@atlaskit/editor-common/types").Command;
7
7
  export declare const showResizeHandleLine: (cellColumnPositioning: CellColumnPositioning) => import("@atlaskit/editor-common/types").Command;
8
8
  export declare const hideResizeHandleLine: () => import("@atlaskit/editor-common/types").Command;
9
- export declare const hoverCell: (rowIndex?: number, colIndex?: number) => import("@atlaskit/editor-common/types").Command;
9
+ export declare const hoverCell: (rowIndex?: number, colIndex?: number, colWidth?: number, colHeight?: number) => import("@atlaskit/editor-common/types").Command;
@@ -44,15 +44,17 @@ export interface PluginConfig {
44
44
  }
45
45
  export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
46
46
  export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
47
- export type CellHoverCoordinates = {
47
+ export interface CellHoverMeta {
48
48
  colIndex?: number;
49
49
  rowIndex?: number;
50
- };
50
+ colWidth?: number;
51
+ colHeight?: number;
52
+ }
51
53
  export interface TablePluginState {
52
54
  editorHasFocus?: boolean;
53
55
  hoveredColumns: number[];
54
56
  hoveredRows: number[];
55
- hoveredCell: CellHoverCoordinates;
57
+ hoveredCell: CellHoverMeta;
56
58
  pluginConfig: PluginConfig;
57
59
  isHeaderColumnEnabled: boolean;
58
60
  isHeaderRowEnabled: boolean;
@@ -170,7 +172,9 @@ export type TablePluginAction = {
170
172
  };
171
173
  } | {
172
174
  type: 'HOVER_CELL';
173
- data: CellHoverCoordinates;
175
+ data: {
176
+ hoveredCell: CellHoverMeta;
177
+ };
174
178
  } | {
175
179
  type: 'SET_TARGET_CELL_POSITION';
176
180
  data: {
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
- import type { CellHoverCoordinates } from '../../../types';
3
+ import type { CellHoverMeta } from '../../../types';
4
4
  export interface Props {
5
5
  editorView: EditorView;
6
6
  tableActive?: boolean;
7
7
  tableRef: HTMLTableElement;
8
- hoveredCell?: CellHoverCoordinates;
8
+ hoveredCell?: CellHoverMeta;
9
9
  isResizing?: boolean;
10
10
  stickyTop?: number;
11
11
  localId?: string;
@@ -5,7 +5,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
8
- import type { CellHoverCoordinates } from '../../types';
8
+ import type { CellHoverMeta } from '../../types';
9
9
  export interface Props {
10
10
  editorView: EditorView;
11
11
  getEditorFeatureFlags: GetEditorFeatureFlags;
@@ -16,7 +16,7 @@ export interface Props {
16
16
  hasHeaderRow?: boolean;
17
17
  headerRowHeight?: number;
18
18
  hoveredRows?: number[];
19
- hoveredCell?: CellHoverCoordinates;
19
+ hoveredCell?: CellHoverMeta;
20
20
  isResizing?: boolean;
21
21
  ordering?: TableColumnOrdering;
22
22
  stickyHeader?: RowStickyState;
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import type { WrappedComponentProps } from 'react-intl-next';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { CellHoverCoordinates } from '../../../types';
4
+ import type { CellHoverMeta } from '../../../types';
5
5
  type DragControlsProps = {
6
6
  editorView: EditorView;
7
7
  tableRef: HTMLTableElement;
8
8
  tableActive?: boolean;
9
- hoveredCell?: CellHoverCoordinates;
9
+ hoveredCell?: CellHoverMeta;
10
10
  hoverRows?: (rows: number[], danger?: boolean) => void;
11
11
  selectRow?: (row: number, expand: boolean) => void;
12
12
  };
@@ -3,7 +3,7 @@ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
3
3
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
6
- import type { CellHoverCoordinates } from '../../types';
6
+ import type { CellHoverMeta } from '../../types';
7
7
  export interface Props {
8
8
  editorView: EditorView;
9
9
  selection?: Selection;
@@ -18,7 +18,7 @@ export interface Props {
18
18
  hasHeaderRow?: boolean;
19
19
  headerRowHeight?: number;
20
20
  hoveredRows?: number[];
21
- hoveredCell?: CellHoverCoordinates;
21
+ hoveredCell?: CellHoverMeta;
22
22
  ordering?: TableColumnOrdering;
23
23
  stickyHeader?: RowStickyState;
24
24
  }
@@ -6,4 +6,4 @@ export declare const hoverTable: (isInDanger?: boolean, isSelected?: boolean) =>
6
6
  export declare const clearHoverSelection: () => import("@atlaskit/editor-common/types").Command;
7
7
  export declare const showResizeHandleLine: (cellColumnPositioning: CellColumnPositioning) => import("@atlaskit/editor-common/types").Command;
8
8
  export declare const hideResizeHandleLine: () => import("@atlaskit/editor-common/types").Command;
9
- export declare const hoverCell: (rowIndex?: number, colIndex?: number) => import("@atlaskit/editor-common/types").Command;
9
+ export declare const hoverCell: (rowIndex?: number, colIndex?: number, colWidth?: number, colHeight?: number) => import("@atlaskit/editor-common/types").Command;
@@ -44,15 +44,17 @@ export interface PluginConfig {
44
44
  }
45
45
  export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
46
46
  export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
47
- export type CellHoverCoordinates = {
47
+ export interface CellHoverMeta {
48
48
  colIndex?: number;
49
49
  rowIndex?: number;
50
- };
50
+ colWidth?: number;
51
+ colHeight?: number;
52
+ }
51
53
  export interface TablePluginState {
52
54
  editorHasFocus?: boolean;
53
55
  hoveredColumns: number[];
54
56
  hoveredRows: number[];
55
- hoveredCell: CellHoverCoordinates;
57
+ hoveredCell: CellHoverMeta;
56
58
  pluginConfig: PluginConfig;
57
59
  isHeaderColumnEnabled: boolean;
58
60
  isHeaderRowEnabled: boolean;
@@ -170,7 +172,9 @@ export type TablePluginAction = {
170
172
  };
171
173
  } | {
172
174
  type: 'HOVER_CELL';
173
- data: CellHoverCoordinates;
175
+ data: {
176
+ hoveredCell: CellHoverMeta;
177
+ };
174
178
  } | {
175
179
  type: 'SET_TARGET_CELL_POSITION';
176
180
  data: {
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
- import type { CellHoverCoordinates } from '../../../types';
3
+ import type { CellHoverMeta } from '../../../types';
4
4
  export interface Props {
5
5
  editorView: EditorView;
6
6
  tableActive?: boolean;
7
7
  tableRef: HTMLTableElement;
8
- hoveredCell?: CellHoverCoordinates;
8
+ hoveredCell?: CellHoverMeta;
9
9
  isResizing?: boolean;
10
10
  stickyTop?: number;
11
11
  localId?: string;
@@ -5,7 +5,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
8
- import type { CellHoverCoordinates } from '../../types';
8
+ import type { CellHoverMeta } from '../../types';
9
9
  export interface Props {
10
10
  editorView: EditorView;
11
11
  getEditorFeatureFlags: GetEditorFeatureFlags;
@@ -16,7 +16,7 @@ export interface Props {
16
16
  hasHeaderRow?: boolean;
17
17
  headerRowHeight?: number;
18
18
  hoveredRows?: number[];
19
- hoveredCell?: CellHoverCoordinates;
19
+ hoveredCell?: CellHoverMeta;
20
20
  isResizing?: boolean;
21
21
  ordering?: TableColumnOrdering;
22
22
  stickyHeader?: RowStickyState;
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import type { WrappedComponentProps } from 'react-intl-next';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { CellHoverCoordinates } from '../../../types';
4
+ import type { CellHoverMeta } from '../../../types';
5
5
  type DragControlsProps = {
6
6
  editorView: EditorView;
7
7
  tableRef: HTMLTableElement;
8
8
  tableActive?: boolean;
9
- hoveredCell?: CellHoverCoordinates;
9
+ hoveredCell?: CellHoverMeta;
10
10
  hoverRows?: (rows: number[], danger?: boolean) => void;
11
11
  selectRow?: (row: number, expand: boolean) => void;
12
12
  };
@@ -3,7 +3,7 @@ import type { TableColumnOrdering } from '@atlaskit/custom-steps';
3
3
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
6
- import type { CellHoverCoordinates } from '../../types';
6
+ import type { CellHoverMeta } from '../../types';
7
7
  export interface Props {
8
8
  editorView: EditorView;
9
9
  selection?: Selection;
@@ -18,7 +18,7 @@ export interface Props {
18
18
  hasHeaderRow?: boolean;
19
19
  headerRowHeight?: number;
20
20
  hoveredRows?: number[];
21
- hoveredCell?: CellHoverCoordinates;
21
+ hoveredCell?: CellHoverMeta;
22
22
  ordering?: TableColumnOrdering;
23
23
  stickyHeader?: RowStickyState;
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.9",
3
+ "version": "5.3.10",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -301,7 +301,10 @@ describe('withCellTracking', () => {
301
301
  withCellTracking(jest.fn())(editorView, event as any);
302
302
 
303
303
  const pluginState = getPluginState(editorView.state);
304
- expect(pluginState.hoveredCell).toEqual({ colIndex: 0, rowIndex: 0 });
304
+ expect(pluginState.hoveredCell).toEqual({
305
+ colIndex: undefined,
306
+ rowIndex: undefined,
307
+ });
305
308
  });
306
309
  });
307
310
  });
@@ -191,13 +191,18 @@ export const hideResizeHandleLine = () =>
191
191
  },
192
192
  }));
193
193
 
194
- export const hoverCell = (rowIndex?: number, colIndex?: number) =>
194
+ export const hoverCell = (
195
+ rowIndex?: number,
196
+ colIndex?: number,
197
+ colWidth?: number,
198
+ colHeight?: number,
199
+ ) =>
195
200
  createCommand(
196
201
  () => {
197
202
  return {
198
203
  type: 'HOVER_CELL',
199
204
  data: {
200
- hoveredCell: { rowIndex, colIndex },
205
+ hoveredCell: { rowIndex, colIndex, colWidth, colHeight },
201
206
  },
202
207
  };
203
208
  },
@@ -288,7 +288,7 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
288
288
  }
289
289
 
290
290
  if (isDragAndDropEnabled) {
291
- hoverCell(undefined, undefined)(state, dispatch);
291
+ hoverCell()(state, dispatch);
292
292
  }
293
293
 
294
294
  if (
@@ -512,8 +512,9 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
512
512
  const maybeTableCell = isElementInTableCell(
513
513
  target as HTMLElement,
514
514
  ) as HTMLTableCellElement | null;
515
+ const tableRef = getPluginState(view.state).tableRef;
515
516
 
516
- if (!maybeTableCell) {
517
+ if (!maybeTableCell || !tableRef) {
517
518
  return;
518
519
  }
519
520
 
@@ -525,8 +526,21 @@ const trackCellLocation = (view: EditorView, mouseEvent: Event) => {
525
526
  const rowIndex = rowElement && rowElement.rowIndex;
526
527
  const { hoveredCell } = getPluginState(view.state);
527
528
 
528
- if (hoveredCell.colIndex !== colIndex || hoveredCell.rowIndex !== rowIndex) {
529
- hoverCell(rowIndex, colIndex)(view.state, view.dispatch);
529
+ const colHeight = tableRef.offsetHeight;
530
+ const colWidth = maybeTableCell.offsetWidth;
531
+
532
+ if (
533
+ hoveredCell.colIndex !== colIndex ||
534
+ hoveredCell.rowIndex !== rowIndex ||
535
+ hoveredCell.colWidth !== colWidth ||
536
+ hoveredCell.colHeight !== colHeight
537
+ ) {
538
+ hoverCell(
539
+ rowIndex,
540
+ colIndex,
541
+ colWidth,
542
+ colHeight,
543
+ )(view.state, view.dispatch);
530
544
  }
531
545
  };
532
546
 
@@ -85,14 +85,18 @@ export type { ColumnResizingPluginState } from '@atlaskit/editor-common/types';
85
85
  *
86
86
  */
87
87
  export type CellColumnPositioning = Pick<Rect, 'right' | 'left'>;
88
-
89
- export type CellHoverCoordinates = { colIndex?: number; rowIndex?: number };
88
+ export interface CellHoverMeta {
89
+ colIndex?: number;
90
+ rowIndex?: number;
91
+ colWidth?: number;
92
+ colHeight?: number;
93
+ }
90
94
 
91
95
  export interface TablePluginState {
92
96
  editorHasFocus?: boolean;
93
97
  hoveredColumns: number[];
94
98
  hoveredRows: number[];
95
- hoveredCell: CellHoverCoordinates;
99
+ hoveredCell: CellHoverMeta;
96
100
  pluginConfig: PluginConfig;
97
101
  isHeaderColumnEnabled: boolean;
98
102
  isHeaderRowEnabled: boolean;
@@ -200,7 +204,12 @@ export type TablePluginAction =
200
204
  | { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
201
205
  | { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
202
206
  | { type: 'HIDE_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
203
- | { type: 'HOVER_CELL'; data: CellHoverCoordinates }
207
+ | {
208
+ type: 'HOVER_CELL';
209
+ data: {
210
+ hoveredCell: CellHoverMeta;
211
+ };
212
+ }
204
213
  | { type: 'SET_TARGET_CELL_POSITION'; data: { targetCellPosition?: number } }
205
214
  | {
206
215
  type: 'SELECT_COLUMN';
@@ -2,7 +2,7 @@ import React from 'react';
2
2
 
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
 
5
- import type { CellHoverCoordinates } from '../../../types';
5
+ import type { CellHoverMeta } from '../../../types';
6
6
  import { TableCssClassName as ClassName } from '../../../types';
7
7
  import { DragHandle } from '../../DragHandle';
8
8
 
@@ -10,7 +10,7 @@ export interface Props {
10
10
  editorView: EditorView;
11
11
  tableActive?: boolean;
12
12
  tableRef: HTMLTableElement;
13
- hoveredCell?: CellHoverCoordinates;
13
+ hoveredCell?: CellHoverMeta;
14
14
  isResizing?: boolean;
15
15
  stickyTop?: number;
16
16
  localId?: string;
@@ -45,8 +45,6 @@ export const ColumnControls: React.FC<Props> = ({
45
45
  colWidths?.map((width) => (width ? `${width - 1}px` : '0px')).join(' ') ??
46
46
  '0px';
47
47
 
48
- const colIndex = hoveredCell?.colIndex;
49
-
50
48
  const onClick = (
51
49
  index: number,
52
50
  event: React.MouseEvent<Element, MouseEvent>,
@@ -65,25 +63,32 @@ export const ColumnControls: React.FC<Props> = ({
65
63
  marginTop,
66
64
  }}
67
65
  >
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
- )}
66
+ {tableActive &&
67
+ !isResizing &&
68
+ !!hoveredCell &&
69
+ Number.isFinite(hoveredCell.colIndex) && (
70
+ <div
71
+ style={{
72
+ gridColumn: `${(hoveredCell.colIndex as number) + 1} / span 1`,
73
+ marginTop: `-15px`,
74
+ }}
75
+ data-column-control-index={hoveredCell.colIndex}
76
+ data-testid="table-floating-column-control"
77
+ >
78
+ <DragHandle
79
+ direction="column"
80
+ indexes={[hoveredCell.colIndex!]}
81
+ onClick={(event) =>
82
+ onClick(hoveredCell.colIndex as number, event)
83
+ }
84
+ onMouseOver={onMouseOver}
85
+ onMouseOut={onMouseOut}
86
+ tableLocalId={localId || ''}
87
+ previewWidth={hoveredCell.colWidth}
88
+ previewHeight={hoveredCell.colHeight}
89
+ />
90
+ </div>
91
+ )}
87
92
  </div>
88
93
  </div>
89
94
  );
@@ -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
 
@@ -27,7 +27,7 @@ export interface Props {
27
27
  hasHeaderRow?: boolean;
28
28
  headerRowHeight?: number;
29
29
  hoveredRows?: number[];
30
- hoveredCell?: CellHoverCoordinates;
30
+ hoveredCell?: CellHoverMeta;
31
31
  isResizing?: boolean;
32
32
  ordering?: TableColumnOrdering;
33
33
  stickyHeader?: RowStickyState;
@@ -6,7 +6,7 @@ import type { WrappedComponentProps } from 'react-intl-next';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import { findTable } from '@atlaskit/editor-tables/utils';
8
8
 
9
- import type { CellHoverCoordinates } from '../../../types';
9
+ import type { CellHoverMeta } from '../../../types';
10
10
  import { TableCssClassName as ClassName } from '../../../types';
11
11
  import { getRowHeights } from '../../../utils';
12
12
  import { DragHandle } from '../../DragHandle';
@@ -15,7 +15,7 @@ type DragControlsProps = {
15
15
  editorView: EditorView;
16
16
  tableRef: HTMLTableElement;
17
17
  tableActive?: boolean;
18
- hoveredCell?: CellHoverCoordinates;
18
+ hoveredCell?: CellHoverMeta;
19
19
  hoverRows?: (rows: number[], danger?: boolean) => void;
20
20
  selectRow?: (row: number, expand: boolean) => void;
21
21
  };
@@ -7,7 +7,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
 
8
8
  import { hoverRows, selectRow } from '../../commands';
9
9
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
10
- import type { CellHoverCoordinates } from '../../types';
10
+ import type { CellHoverMeta } from '../../types';
11
11
  import { isSelectionUpdated } from '../../utils';
12
12
 
13
13
  import { CornerControls } from './CornerControls';
@@ -28,7 +28,7 @@ export interface Props {
28
28
  hasHeaderRow?: boolean;
29
29
  headerRowHeight?: number;
30
30
  hoveredRows?: number[];
31
- hoveredCell?: CellHoverCoordinates;
31
+ hoveredCell?: CellHoverMeta;
32
32
  ordering?: TableColumnOrdering;
33
33
  stickyHeader?: RowStickyState;
34
34
  }