@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
@@ -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
  }
@@ -0,0 +1,2 @@
1
+ export { DragHandleIcon } from './DragHandleIcon';
2
+ export { DragInMotionIcon } from './DragInMotionIcon';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.8",
3
+ "version": "5.3.10",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -70,6 +70,7 @@
70
70
  "@atlaskit/webdriver-runner": "*",
71
71
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
72
72
  "@atlassian/feature-flags-test-utils": "^0.1.2",
73
+ "@testing-library/dom": "^8.17.1",
73
74
  "@testing-library/react": "^12.1.5",
74
75
  "@testing-library/react-hooks": "^8.0.1",
75
76
  "raf-stub": "^2.0.1",
@@ -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
  });
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
+ import { fireEvent } from '@testing-library/dom';
3
4
  import { render, screen } from '@testing-library/react';
4
5
  import { IntlProvider } from 'react-intl-next';
5
6
 
6
- import type { DocBuilder } from '@atlaskit/editor-common/types';
7
+ import type { DocBuilder, Refs } from '@atlaskit/editor-common/types';
7
8
  // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
8
9
  import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
9
10
  import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
@@ -12,6 +13,7 @@ import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
12
13
  import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
13
14
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
14
15
  import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
16
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
15
17
  import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
16
18
  // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
17
19
  import {
@@ -56,13 +58,28 @@ describe('TableFloatingColumnControls', () => {
56
58
  });
57
59
  };
58
60
 
61
+ const getNodeFunc = (view: EditorView, refs: Refs) => () =>
62
+ view.state.doc.nodeAt(refs['<node>'])!;
63
+
64
+ afterEach(async () => {
65
+ // cleanup any pending drags
66
+ fireEvent.dragEnd(window);
67
+ // Optional: unwind a post-drop browser bug fix
68
+ // tick forward a micro task to flush a post-drag bug fix
69
+ await 1;
70
+ // this will trigger the fix to be released
71
+ fireEvent.pointerMove(window);
72
+ });
73
+
59
74
  it('should not render floating column controls when tableRef undefined and drag and drop is not enabled', () => {
60
- const { editorView } = editor(
61
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
75
+ const { editorView, refs } = editor(
76
+ doc(p('text'), '{<node>}', table()(tr(tdEmpty, tdEmpty, tdEmpty))),
62
77
  );
78
+
63
79
  const { container } = render(
64
80
  <TableFloatingColumnControls
65
81
  editorView={editorView}
82
+ getNode={getNodeFunc(editorView, refs)}
66
83
  getEditorFeatureFlags={fakeGetEditorFeatureFlags}
67
84
  />,
68
85
  );
@@ -70,8 +87,8 @@ describe('TableFloatingColumnControls', () => {
70
87
  });
71
88
 
72
89
  it('should not render floating column controls when tableRef undefined and drag and drop is enabled', () => {
73
- const { editorView } = editor(
74
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
90
+ const { editorView, refs } = editor(
91
+ doc(p('text'), '{<node>}', table()(tr(tdEmpty, tdEmpty, tdEmpty))),
75
92
  {
76
93
  dragAndDropEnabled: true,
77
94
  },
@@ -79,16 +96,23 @@ describe('TableFloatingColumnControls', () => {
79
96
  const { container } = render(
80
97
  <TableFloatingColumnControls
81
98
  editorView={editorView}
99
+ getNode={getNodeFunc(editorView, refs)}
82
100
  getEditorFeatureFlags={fakeGetEditorFeatureFlags}
83
101
  />,
84
102
  );
85
103
  expect(container.innerHTML).toEqual('');
86
104
  });
87
105
 
88
- // FIXME and unskip: presumably doesn't work becuase TableFloatingColumnControls are now mounted via ReactDOM.createPortal
89
- it.skip('should render a drop target per column', () => {
90
- const { editorView } = editor(
91
- doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty, tdEmpty))),
106
+ it.todo('should not render drop target when no drag is active');
107
+
108
+ it.todo(
109
+ 'should render a drop target per column when dragging' /*, () => {
110
+ const { editorView, refs } = editor(
111
+ doc(
112
+ p('text'),
113
+ '{<node>}',
114
+ table()(tr(tdEmpty, tdCursor, tdEmpty, tdEmpty, tdEmpty)),
115
+ ),
92
116
  {
93
117
  dragAndDropEnabled: true,
94
118
  },
@@ -98,25 +122,44 @@ describe('TableFloatingColumnControls', () => {
98
122
  render(
99
123
  <IntlProvider locale="en">
100
124
  <TableFloatingColumnControls
125
+ getNode={getNodeFunc(editorView, refs)}
101
126
  tableRef={ref}
102
127
  tableActive={true}
128
+ hoveredCell={{ colIndex: 1, rowIndex: 0}}
103
129
  editorView={editorView}
104
130
  getEditorFeatureFlags={fakeGetEditorFeatureFlags}
105
131
  />
106
132
  </IntlProvider>,
107
133
  );
108
134
 
135
+ screen.debug();
136
+
137
+ const dragHandle = screen.getByTestId(
138
+ 'table-floating-column-controls-drag-handle',
139
+ );
140
+
141
+ fireEvent.dragStart(dragHandle);
142
+
143
+ // ticking forward an animation frame will complete the lift
144
+ // @ts-expect-error
145
+ requestAnimationFrame.step();
146
+
109
147
  const dropTargets = screen.getAllByTestId(
110
148
  'table-floating-column-controls-drop-target',
111
149
  );
112
150
 
113
151
  expect(dropTargets).toHaveLength(5);
114
- });
152
+ }*/,
153
+ );
115
154
 
116
155
  // FIXME and unskp: presumably doesn't work becuase TableFloatingColumnControls are now mounted via ReactDOM.createPortal
117
156
  it.skip('should render a drop target per column regardless of row count', () => {
118
- const { editorView } = editor(
119
- doc(p('text'), table()(tr(tdEmpty), tr(tdEmpty), tr(tdEmpty))),
157
+ const { editorView, refs } = editor(
158
+ doc(
159
+ p('text'),
160
+ '{<node>}',
161
+ table()(tr(tdEmpty), tr(tdEmpty), tr(tdEmpty)),
162
+ ),
120
163
  {
121
164
  dragAndDropEnabled: true,
122
165
  },
@@ -126,6 +169,7 @@ describe('TableFloatingColumnControls', () => {
126
169
  render(
127
170
  <IntlProvider locale="en">
128
171
  <TableFloatingColumnControls
172
+ getNode={getNodeFunc(editorView, refs)}
129
173
  tableRef={ref}
130
174
  tableActive={true}
131
175
  editorView={editorView}
@@ -139,4 +183,6 @@ describe('TableFloatingColumnControls', () => {
139
183
  );
140
184
  expect(dropTargets).toHaveLength(1);
141
185
  });
186
+
187
+ it.todo('should remove column drop targets when dragging ends');
142
188
  });
@@ -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
 
@@ -439,13 +439,14 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
439
439
  <TableFloatingColumnControls
440
440
  editorView={view}
441
441
  tableRef={tableRef}
442
+ getNode={getNode}
442
443
  tableActive={tableActive}
443
444
  hoveredRows={hoveredRows}
444
445
  hoveredCell={hoveredCell}
445
446
  isResizing={isResizing}
446
447
  ordering={ordering}
447
448
  hasHeaderRow={hasHeaderRow}
448
- // pass `selection` and `tableHeight` to control re-render
449
+ // pass `selection` to control re-render
449
450
  selection={view.state.selection}
450
451
  headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
451
452
  stickyHeader={this.state.stickyHeader}
@@ -110,9 +110,6 @@ export const moveSource = (
110
110
  }
111
111
 
112
112
  const move = sourceType === 'table-row' ? moveRow : moveColumn;
113
- return move(
114
- sourceIndex,
115
- targetIndex + (sourceIndex > targetIndex ? 0 : -1),
116
- )(tr);
113
+ return move(sourceIndex, targetIndex)(tr);
117
114
  },
118
115
  );
@@ -87,7 +87,12 @@ export const createPlugin = (
87
87
  return;
88
88
  }
89
89
 
90
- const { sourceType, sourceIndexes, targetAdjustedIndex } = data;
90
+ const {
91
+ sourceType,
92
+ sourceIndexes,
93
+ targetAdjustedIndex,
94
+ direction,
95
+ } = data;
91
96
 
92
97
  // If the drop target index contains merged cells then we should not allow the drop to occur.
93
98
  const hasMergedCells =
@@ -105,7 +110,7 @@ export const createPlugin = (
105
110
  moveSource(
106
111
  sourceType,
107
112
  sourceIndex,
108
- targetAdjustedIndex,
113
+ targetAdjustedIndex + (direction === -1 ? 0 : -1),
109
114
  )(editorView.state, editorView.dispatch);
110
115
  },
111
116
  }),
@@ -59,6 +59,10 @@ export const getDraggableDataFromEvent = ({
59
59
  const targetOffset =
60
60
  targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
61
61
 
62
+ // since only consecutive rows/cols can be moved we can assume that if the first index is greater then
63
+ // the target index, the then the direction of the DnD is decreasing
64
+ const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
65
+
62
66
  return {
63
67
  sourceType,
64
68
  sourceLocalId,
@@ -68,5 +72,6 @@ export const getDraggableDataFromEvent = ({
68
72
  targetIndex,
69
73
  targetAdjustedIndex: targetIndex + targetOffset,
70
74
  targetClosestEdge,
75
+ direction,
71
76
  };
72
77
  };
@@ -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';
@@ -421,4 +430,5 @@ export interface DraggableData {
421
430
  targetIndex: number;
422
431
  targetAdjustedIndex: number;
423
432
  targetClosestEdge: Edge;
433
+ direction: 1 | -1;
424
434
  }
@@ -10,7 +10,7 @@ import { token } from '@atlaskit/tokens';
10
10
 
11
11
  import { TableCssClassName as ClassName } from '../../types';
12
12
  import { DragPreview } from '../DragPreview';
13
- import { DragHandleIcon } from '../icons/DragHandleIcon';
13
+ import { DragHandleIcon } from '../icons';
14
14
 
15
15
  type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
16
16
 
@@ -99,7 +99,9 @@ export const DragHandle = ({
99
99
  borderRadius: '4px',
100
100
  border: `2px solid ${token('elevation.surface', 'white')}`,
101
101
  transform: direction === 'column' ? 'none' : 'rotate(90deg)',
102
+ pointerEvents: 'auto',
102
103
  }}
104
+ data-testid="table-floating-column-controls-drag-handle"
103
105
  >
104
106
  <DragHandleIcon {...iconProps} />
105
107
  {previewContainer &&
@@ -1,21 +1,21 @@
1
- import React, { useMemo } from 'react';
1
+ 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
- import { getColumnsWidths, getRowHeights } from '../../../utils';
8
7
  import { DragHandle } from '../../DragHandle';
9
8
 
10
9
  export interface Props {
11
10
  editorView: EditorView;
12
11
  tableActive?: boolean;
13
12
  tableRef: HTMLTableElement;
14
- hoveredCell?: CellHoverCoordinates;
13
+ hoveredCell?: CellHoverMeta;
15
14
  isResizing?: boolean;
16
15
  stickyTop?: number;
17
- tableHeight?: number;
18
16
  localId?: string;
17
+ rowHeights?: number[];
18
+ colWidths?: (number | undefined)[];
19
19
  }
20
20
 
21
21
  export const ColumnControls: React.FC<Props> = ({
@@ -24,18 +24,11 @@ export const ColumnControls: React.FC<Props> = ({
24
24
  tableRef,
25
25
  hoveredCell,
26
26
  isResizing,
27
- tableHeight,
28
27
  stickyTop,
29
28
  localId,
29
+ rowHeights,
30
+ colWidths,
30
31
  }) => {
31
- const rowHeights = useMemo(() => {
32
- // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
33
- if (tableRef && !!tableHeight) {
34
- return getRowHeights(tableRef);
35
- }
36
- return [0];
37
- }, [tableRef, tableHeight]);
38
-
39
32
  if (!tableRef) {
40
33
  return null;
41
34
  }
@@ -48,12 +41,9 @@ export const ColumnControls: React.FC<Props> = ({
48
41
  const marginTop =
49
42
  hasHeaderRow && stickyTop !== undefined ? rowHeights?.[0] ?? 0 : 0;
50
43
 
51
- const colWidths = getColumnsWidths(editorView);
52
- const widths = colWidths
53
- .map((width) => (width ? `${width - 1}px` : '0px'))
54
- .join(' ');
55
-
56
- const colIndex = hoveredCell?.colIndex;
44
+ const widths =
45
+ colWidths?.map((width) => (width ? `${width - 1}px` : '0px')).join(' ') ??
46
+ '0px';
57
47
 
58
48
  const onClick = (
59
49
  index: number,
@@ -73,25 +63,32 @@ export const ColumnControls: React.FC<Props> = ({
73
63
  marginTop,
74
64
  }}
75
65
  >
76
- {tableActive && !isResizing && Number.isFinite(colIndex) && (
77
- <div
78
- style={{
79
- gridColumn: `${(colIndex as number) + 1} / span 1`,
80
- marginTop: `-15px`,
81
- }}
82
- data-column-control-index={colIndex}
83
- data-testid="table-floating-column-control"
84
- >
85
- <DragHandle
86
- direction="column"
87
- indexes={[]}
88
- onClick={(event) => onClick(colIndex as number, event)}
89
- onMouseOver={onMouseOver}
90
- onMouseOut={onMouseOut}
91
- tableLocalId={localId || ''}
92
- />
93
- </div>
94
- )}
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
+ )}
95
92
  </div>
96
93
  </div>
97
94
  );
@@ -0,0 +1,74 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+
3
+ import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
4
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
+
6
+ import type { DraggableSourceData } from '../../../types';
7
+
8
+ export interface Props {
9
+ index: number;
10
+ localId?: string;
11
+ width?: number;
12
+ height?: number;
13
+ marginTop?: number;
14
+ }
15
+
16
+ export const ColumnDropTarget: React.FC<Props> = ({
17
+ index,
18
+ localId,
19
+ width,
20
+ height,
21
+ marginTop,
22
+ }) => {
23
+ const dropTargetRef = useRef<HTMLDivElement | null>(null);
24
+
25
+ useEffect(() => {
26
+ if (!dropTargetRef.current) {
27
+ return;
28
+ }
29
+
30
+ return dropTargetForElements({
31
+ element: dropTargetRef.current,
32
+ canDrop({ source }) {
33
+ const data = source.data as DraggableSourceData;
34
+ return (
35
+ // Only draggables of row type can be dropped on this target
36
+ data.type === 'table-column' &&
37
+ // Only draggables which came from the same table can be dropped on this target
38
+ data.localId === localId &&
39
+ // Only draggables which DO NOT include this drop targets index can be dropped
40
+ !!data.indexes?.length &&
41
+ data.indexes?.indexOf(index) === -1
42
+ );
43
+ },
44
+ getIsSticky: () => true,
45
+ getData({ input, element }) {
46
+ const data = {
47
+ localId,
48
+ type: 'table-column',
49
+ targetIndex: index,
50
+ };
51
+ return attachClosestEdge(data, {
52
+ input,
53
+ element,
54
+ allowedEdges: ['left', 'right'],
55
+ });
56
+ },
57
+ });
58
+ }, [index, localId]);
59
+
60
+ return (
61
+ <div
62
+ ref={dropTargetRef}
63
+ style={{
64
+ width: width && `${width - 1}px`,
65
+ height: height && `${height}px`,
66
+ marginTop: marginTop && `${marginTop}px`,
67
+ pointerEvents: 'auto',
68
+ }}
69
+ data-drop-target-index={index}
70
+ data-drop-target-localid={localId}
71
+ data-testid="table-floating-column-controls-drop-target"
72
+ />
73
+ );
74
+ };