@atlaskit/editor-plugin-table 7.5.5 → 7.5.7

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 (100) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/commands/selection.js +23 -1
  3. package/dist/cjs/event-handlers.js +25 -9
  4. package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
  5. package/dist/cjs/nodeviews/TableCell.js +5 -30
  6. package/dist/cjs/nodeviews/TableComponent.js +96 -41
  7. package/dist/cjs/nodeviews/TableContainer.js +19 -17
  8. package/dist/cjs/nodeviews/TableResizer.js +1 -1
  9. package/dist/cjs/plugin.js +2 -3
  10. package/dist/cjs/pm-plugins/main.js +3 -18
  11. package/dist/cjs/pm-plugins/sticky-headers/types.js +1 -5
  12. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  13. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +11 -1
  14. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +22 -23
  15. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  16. package/dist/cjs/pm-plugins/table-selection-keymap.js +3 -0
  17. package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
  18. package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
  19. package/dist/cjs/utils/column-controls.js +5 -5
  20. package/dist/cjs/utils/dom.js +13 -15
  21. package/dist/es2019/commands/selection.js +22 -0
  22. package/dist/es2019/event-handlers.js +25 -9
  23. package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
  24. package/dist/es2019/nodeviews/TableCell.js +1 -24
  25. package/dist/es2019/nodeviews/TableComponent.js +69 -31
  26. package/dist/es2019/nodeviews/TableContainer.js +16 -18
  27. package/dist/es2019/nodeviews/TableResizer.js +1 -1
  28. package/dist/es2019/plugin.js +2 -3
  29. package/dist/es2019/pm-plugins/main.js +3 -18
  30. package/dist/es2019/pm-plugins/sticky-headers/types.js +0 -1
  31. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  32. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +10 -0
  33. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +21 -22
  34. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  35. package/dist/es2019/pm-plugins/table-selection-keymap.js +5 -2
  36. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
  37. package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
  38. package/dist/es2019/utils/column-controls.js +6 -6
  39. package/dist/es2019/utils/dom.js +13 -15
  40. package/dist/esm/commands/selection.js +22 -0
  41. package/dist/esm/event-handlers.js +25 -9
  42. package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
  43. package/dist/esm/nodeviews/TableCell.js +5 -30
  44. package/dist/esm/nodeviews/TableComponent.js +96 -41
  45. package/dist/esm/nodeviews/TableContainer.js +20 -18
  46. package/dist/esm/nodeviews/TableResizer.js +1 -1
  47. package/dist/esm/plugin.js +2 -3
  48. package/dist/esm/pm-plugins/main.js +3 -18
  49. package/dist/esm/pm-plugins/sticky-headers/types.js +0 -1
  50. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +3 -7
  51. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +10 -0
  52. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +23 -24
  53. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -2
  54. package/dist/esm/pm-plugins/table-selection-keymap.js +5 -2
  55. package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
  56. package/dist/esm/ui/TableFloatingControls/index.js +113 -224
  57. package/dist/esm/utils/column-controls.js +6 -6
  58. package/dist/esm/utils/dom.js +13 -15
  59. package/dist/types/commands/selection.d.ts +1 -0
  60. package/dist/types/event-handlers.d.ts +3 -4
  61. package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  62. package/dist/types/nodeviews/TableCell.d.ts +1 -5
  63. package/dist/types/nodeviews/TableComponent.d.ts +4 -0
  64. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  65. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  66. package/dist/types/types.d.ts +0 -3
  67. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
  68. package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
  69. package/dist/types/utils/dom.d.ts +10 -2
  70. package/dist/types-ts4.5/commands/selection.d.ts +1 -0
  71. package/dist/types-ts4.5/event-handlers.d.ts +3 -4
  72. package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  73. package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
  74. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
  75. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  76. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
  77. package/dist/types-ts4.5/types.d.ts +0 -3
  78. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
  79. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
  80. package/dist/types-ts4.5/utils/dom.d.ts +10 -2
  81. package/package.json +8 -6
  82. package/src/commands/selection.ts +33 -0
  83. package/src/event-handlers.ts +105 -103
  84. package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
  85. package/src/nodeviews/TableCell.ts +0 -26
  86. package/src/nodeviews/TableComponent.tsx +81 -34
  87. package/src/nodeviews/TableContainer.tsx +19 -25
  88. package/src/nodeviews/TableResizer.tsx +1 -4
  89. package/src/plugin.tsx +5 -4
  90. package/src/pm-plugins/main.ts +3 -22
  91. package/src/pm-plugins/table-resizing/utils/colgroup.ts +3 -6
  92. package/src/pm-plugins/table-resizing/utils/misc.ts +13 -0
  93. package/src/pm-plugins/table-resizing/utils/resize-state.ts +22 -28
  94. package/src/pm-plugins/table-resizing/utils/scale-table.ts +3 -10
  95. package/src/pm-plugins/table-selection-keymap.ts +10 -0
  96. package/src/types.ts +0 -4
  97. package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
  98. package/src/ui/TableFloatingControls/index.tsx +155 -241
  99. package/src/utils/column-controls.ts +5 -6
  100. package/src/utils/dom.ts +12 -19
@@ -1,4 +1,5 @@
1
1
  import type { TableLayout } from '@atlaskit/adf-schema';
2
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
2
3
  import {
3
4
  tableCellMinWidth,
4
5
  tableNewColumnMinWidth,
@@ -20,15 +21,9 @@ import {
20
21
  import type { ColumnState } from './column-state';
21
22
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
22
23
  import { syncStickyRowToTable } from './dom';
23
- import { getTableContainerElementWidth, getTableMaxWidth } from './misc';
24
+ import { getTableMaxWidth, getTableScalingPercent } from './misc';
24
25
  import type { ResizeState, ResizeStateWithAnalytics } from './types';
25
26
 
26
- import {
27
- COLUMN_MIN_WIDTH,
28
- MAX_SCALING_PERCENT,
29
- TABLE_DEFAULT_WIDTH,
30
- } from './index';
31
-
32
27
  export const getResizeState = ({
33
28
  minWidth,
34
29
  maxSize,
@@ -46,6 +41,10 @@ export const getResizeState = ({
46
41
  domAtPos: (pos: number) => { node: Node; offset: number };
47
42
  isTableScalingEnabled: boolean;
48
43
  }): ResizeState => {
44
+ if (isTableScalingEnabled) {
45
+ const scalePercent = getTableScalingPercent(table, tableRef);
46
+ minWidth = Math.ceil(minWidth / scalePercent);
47
+ }
49
48
  // If the table has been resized, we can use the column widths from the table node
50
49
  if (hasTableBeenResized(table)) {
51
50
  const cols = calcTableColumnWidths(table).map((width, index) => ({
@@ -79,11 +78,12 @@ export const getResizeState = ({
79
78
  const cols = Array.from(colgroupChildren).map((_, index) => {
80
79
  // If the table hasn't been resized and we have a table width attribute, we can use it
81
80
  // to calculate the widths of the columns
82
- if (isTableScalingEnabled && table.attrs.width) {
81
+ if (isTableScalingEnabled) {
82
+ const tableNodeWidth = getTableContainerWidth(table);
83
83
  return {
84
84
  index,
85
- width: table.attrs.width / colgroupChildren.length,
86
- minWidth: COLUMN_MIN_WIDTH,
85
+ width: tableNodeWidth / colgroupChildren.length,
86
+ minWidth,
87
87
  };
88
88
  }
89
89
  const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
@@ -116,24 +116,18 @@ export const updateColgroup = (
116
116
  if (getBooleanFF('platform.editor.custom-table-width')) {
117
117
  const columnsCount = cols.length;
118
118
  if (isTableScalingEnabled && tableNode) {
119
- const tableWidth = getTableContainerElementWidth(tableNode);
120
- if (tableWidth) {
121
- let renderWidth =
122
- tableRef.parentElement?.clientWidth || TABLE_DEFAULT_WIDTH;
123
- let scalePercent = renderWidth / tableWidth;
124
- scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
125
- state.cols
126
- .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
127
- .forEach((column, i) => {
128
- const fixedColWidth = getColWidthFix(column.width, columnsCount);
129
- const scaledWidth = fixedColWidth * Math.min(scalePercent, 1);
130
- const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
131
- // we aren't handling the remaining pixels here when the 48px min width is reached
132
- if (cols[i]) {
133
- cols[i].style.width = `${finalWidth}px`;
134
- }
135
- });
136
- }
119
+ const scalePercent = getTableScalingPercent(tableNode, tableRef);
120
+ state.cols
121
+ .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
122
+ .forEach((column, i) => {
123
+ const fixedColWidth = getColWidthFix(column.width, columnsCount);
124
+ const scaledWidth = fixedColWidth * scalePercent;
125
+ const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
126
+ // we aren't handling the remaining pixels here when the 48px min width is reached
127
+ if (cols[i]) {
128
+ cols[i].style.width = `${finalWidth}px`;
129
+ }
130
+ });
137
131
  } else {
138
132
  state.cols
139
133
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
@@ -182,18 +182,11 @@ export const previewScaleTable = (
182
182
  }
183
183
 
184
184
  const resizeState = parentWidth
185
- ? scaleWithParent(
186
- tableRef,
187
- parentWidth,
188
- node,
189
- start,
190
- domAtPos,
191
- isTableScalingEnabled,
192
- )
193
- : scale(tableRef, options, domAtPos, isTableScalingEnabled);
185
+ ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false)
186
+ : scale(tableRef, options, domAtPos, false);
194
187
 
195
188
  if (resizeState) {
196
- updateColgroup(resizeState, tableRef, node, isTableScalingEnabled);
189
+ updateColgroup(resizeState, tableRef, node, false);
197
190
  }
198
191
  };
199
192
 
@@ -5,6 +5,7 @@ import {
5
5
  moveRight,
6
6
  selectColumn,
7
7
  selectRow,
8
+ selectTable,
8
9
  shiftArrowUp,
9
10
  } from '@atlaskit/editor-common/keymaps';
10
11
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -15,6 +16,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
16
  import {
16
17
  arrowLeftFromTable,
17
18
  arrowRightFromTable,
19
+ modASelectTable,
18
20
  selectColumns,
19
21
  selectRows,
20
22
  shiftArrowUpFromTable,
@@ -62,6 +64,14 @@ export function tableSelectionKeymapPlugin(
62
64
  );
63
65
  }
64
66
 
67
+ if (getBooleanFF('platform.editor.table.cmd-a-select-table')) {
68
+ bindKeymapWithCommand(
69
+ selectTable.common!,
70
+ modASelectTable(editorSelectionAPI)(),
71
+ list,
72
+ );
73
+ }
74
+
65
75
  return keymap(list) as SafePlugin;
66
76
  }
67
77
 
package/src/types.ts CHANGED
@@ -447,10 +447,6 @@ export interface ToolbarMenuContext {
447
447
  formatMessage: IntlShape['formatMessage'];
448
448
  }
449
449
 
450
- export type ElementContentRects = {
451
- [key: string]: ResizeObserverEntry['contentRect'];
452
- };
453
-
454
450
  export enum ShadowEvent {
455
451
  SHOW_BEFORE_SHADOW = 'showBeforeShadow',
456
452
  SHOW_AFTER_SHADOW = 'showAfterShadow',
@@ -38,6 +38,7 @@ export interface Props {
38
38
  tableContainerWidth?: number;
39
39
  isNumberColumnEnabled?: boolean;
40
40
  getScrollOffset?: () => number;
41
+ tableWrapperHeight?: number;
41
42
  }
42
43
 
43
44
  export const TableFloatingColumnControls = ({
@@ -55,10 +56,8 @@ export const TableFloatingColumnControls = ({
55
56
  tableContainerWidth,
56
57
  isNumberColumnEnabled,
57
58
  getScrollOffset,
59
+ tableWrapperHeight,
58
60
  }: Props) => {
59
- const [tableRect, setTableRect] = useState<{ width: number; height: number }>(
60
- { width: 0, height: 0 },
61
- );
62
61
  const [isDragging, setIsDragging] = useState(false);
63
62
  const containerRef = useRef<HTMLDivElement>(null);
64
63
 
@@ -70,29 +69,6 @@ export const TableFloatingColumnControls = ({
70
69
  ? stickyHeader.top
71
70
  : undefined;
72
71
 
73
- useEffect(() => {
74
- if (tableRef && window?.ResizeObserver) {
75
- const resizeObserver = new ResizeObserver((entries) => {
76
- for (let entry of entries) {
77
- setTableRect((prev) => {
78
- if (
79
- prev.width !== entry.contentRect.width ||
80
- prev.height !== entry.contentRect.height
81
- ) {
82
- return entry.contentRect;
83
- }
84
- return prev;
85
- });
86
- }
87
- });
88
- resizeObserver.observe(tableRef);
89
-
90
- return () => {
91
- resizeObserver.disconnect();
92
- };
93
- }
94
- }, [tableRef]);
95
-
96
72
  useEffect(() => {
97
73
  return monitorForElements({
98
74
  canMonitor({ source }) {
@@ -115,11 +91,11 @@ export const TableFloatingColumnControls = ({
115
91
 
116
92
  const rowHeights = useMemo(() => {
117
93
  // NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
118
- if (tableRef && !!tableRect.height) {
94
+ if (tableRef && !!tableWrapperHeight) {
119
95
  return getRowHeights(tableRef);
120
96
  }
121
97
  return [0];
122
- }, [tableRef, tableRect.height]);
98
+ }, [tableRef, tableWrapperHeight]);
123
99
 
124
100
  if (!tableRef || !tableActive || isResizing) {
125
101
  return null;
@@ -165,7 +141,7 @@ export const TableFloatingColumnControls = ({
165
141
  <ColumnDropTargets
166
142
  tableRef={tableRef}
167
143
  isHeaderSticky={stickyHeader?.sticky && hasHeaderRow}
168
- tableHeight={tableRect.height}
144
+ tableHeight={tableWrapperHeight}
169
145
  localId={currentNodeLocalId}
170
146
  colWidths={colWidths}
171
147
  getScrollOffset={getScrollOffset}
@@ -1,4 +1,4 @@
1
- import React, { Component } from 'react';
1
+ import React, { useCallback } from 'react';
2
2
 
3
3
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
4
4
  import { browser } from '@atlaskit/editor-common/utils';
@@ -10,13 +10,12 @@ import { hoverCell, hoverRows, selectRow, selectRows } from '../../commands';
10
10
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
11
11
  import { TableCssClassName as ClassName } from '../../types';
12
12
  import type { CellHoverMeta } from '../../types';
13
- import { isSelectionUpdated } from '../../utils';
14
13
 
15
14
  import { CornerControls, DragCornerControls } from './CornerControls';
16
15
  import NumberColumn from './NumberColumn';
17
16
  import { DragControls, RowControls } from './RowControls';
18
17
 
19
- export interface Props {
18
+ export interface TableFloatingControlsProps {
20
19
  editorView: EditorView;
21
20
  selection?: Selection;
22
21
  tableRef?: HTMLTableElement;
@@ -36,248 +35,163 @@ export interface Props {
36
35
  ordering?: TableColumnOrdering;
37
36
  stickyHeader?: RowStickyState;
38
37
  insertRowButtonIndex?: number;
38
+ tableWrapperWidth?: number;
39
39
  }
40
40
 
41
- interface State {
42
- tableWrapperWidth: number;
43
- tableWrapperHeight: number;
44
- }
45
-
46
- export default class TableFloatingControls extends Component<Props, State> {
47
- static displayName = 'TableFloatingControls';
48
- private resizeObserver?: ResizeObserver;
49
-
50
- constructor(props: Props) {
51
- super(props);
52
-
53
- this.state = {
54
- tableWrapperWidth: 0,
55
- /** Height needs to be tracked to re-render decorations correctly, do not remove */
56
- tableWrapperHeight: 0,
57
- };
58
- }
59
-
60
- componentDidMount() {
61
- this.tryInitResizeObserver();
62
- }
63
-
64
- componentDidUpdate() {
65
- // tableRef prop is not guaranteed to be defined after componentDidMount, so retry to init resize observer on update
66
- this.tryInitResizeObserver();
67
- }
68
-
69
- // tracking the table height changes to update floating controls
70
- private tryInitResizeObserver() {
71
- let { tableRef } = this.props;
72
- if (tableRef && !this.resizeObserver && window?.ResizeObserver) {
73
- const tableWrapper = tableRef.closest(
74
- `.${ClassName.TABLE_NODE_WRAPPER}`,
75
- ) as Element;
76
- this.resizeObserver = new ResizeObserver((entries) => {
77
- for (let entry of entries) {
78
- this.setState((prev) => {
79
- return prev?.tableWrapperWidth === entry.contentRect.width &&
80
- prev.tableWrapperHeight === entry.contentRect.height
81
- ? prev
82
- : {
83
- tableWrapperWidth: entry.contentRect.width,
84
- tableWrapperHeight: entry.contentRect.height,
85
- };
86
- });
87
- }
88
- });
89
- this.resizeObserver.observe(tableWrapper);
90
- }
91
- }
92
-
93
- shouldComponentUpdate(nextProps: Props, nextState: State) {
94
- const {
95
- tableRef,
96
- isInDanger,
97
- isResizing,
98
- isHeaderRowEnabled,
99
- isNumberColumnEnabled,
100
- hoveredRows,
101
- selection,
102
- tableActive,
103
- isHeaderColumnEnabled,
104
- ordering,
105
- headerRowHeight,
106
- stickyHeader,
107
- hoveredCell,
108
- isTableHovered,
109
- } = this.props;
110
- return (
111
- this.state.tableWrapperWidth !== nextState.tableWrapperWidth ||
112
- this.state.tableWrapperHeight !== nextState.tableWrapperHeight ||
113
- ordering !== nextProps.ordering ||
114
- tableRef !== nextProps.tableRef ||
115
- tableActive !== nextProps.tableActive ||
116
- isInDanger !== nextProps.isInDanger ||
117
- isResizing !== nextProps.isResizing ||
118
- hoveredRows !== nextProps.hoveredRows ||
119
- isHeaderRowEnabled !== nextProps.isHeaderRowEnabled ||
120
- isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled ||
121
- isNumberColumnEnabled !== nextProps.isNumberColumnEnabled ||
122
- isSelectionUpdated(selection!, nextProps.selection) ||
123
- headerRowHeight !== nextProps.headerRowHeight ||
124
- stickyHeader !== nextProps.stickyHeader ||
125
- hoveredCell !== nextProps.hoveredCell ||
126
- isTableHovered !== nextProps.isTableHovered
127
- );
128
- }
41
+ export const TableFloatingControls = ({
42
+ editorView,
43
+ tableRef,
44
+ tableNode,
45
+ isInDanger,
46
+ isResizing,
47
+ isNumberColumnEnabled,
48
+ isHeaderRowEnabled,
49
+ isHeaderColumnEnabled,
50
+ tableActive,
51
+ hasHeaderRow,
52
+ hoveredRows,
53
+ stickyHeader,
54
+ isDragAndDropEnabled,
55
+ hoveredCell,
56
+ isTableHovered,
57
+ tableWrapperWidth,
58
+ }: TableFloatingControlsProps) => {
59
+ const _selectRow = useCallback(
60
+ (row: number, expand: boolean) => {
61
+ const { state, dispatch } = editorView;
62
+ // fix for issue ED-4665
63
+ if (browser.ie_version === 11) {
64
+ (editorView.dom as HTMLElement).blur();
65
+ }
66
+ selectRow(row, expand)(state, dispatch);
67
+ },
68
+ [editorView],
69
+ );
70
+
71
+ const _selectRows = useCallback(
72
+ (rowIndexes: number[]) => {
73
+ const { state, dispatch } = editorView;
74
+ // fix for issue ED-4665
75
+ if (browser.ie_version === 11) {
76
+ (editorView.dom as HTMLElement).blur();
77
+ }
78
+ selectRows(rowIndexes)(state, dispatch);
79
+ },
80
+ [editorView],
81
+ );
82
+
83
+ const _hoverRows = useCallback(
84
+ (rows: Array<number>, danger?: boolean) => {
85
+ const { state, dispatch } = editorView;
86
+ hoverRows(rows, danger)(state, dispatch);
87
+ },
88
+ [editorView],
89
+ );
129
90
 
130
- componentWillUnmount() {
131
- if (this.resizeObserver) {
132
- this.resizeObserver.disconnect();
133
- }
91
+ // re-use across numbered columns and row controls
92
+ const updateCellHoverLocation = useCallback(
93
+ (rowIndex: number) => {
94
+ const { state, dispatch } = editorView;
95
+
96
+ if (tableActive) {
97
+ // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
98
+ // of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
99
+ // also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
100
+ // current column index. We can just force it to 0.
101
+ hoverCell(rowIndex, 0)(state, dispatch);
102
+ }
103
+ },
104
+ [editorView, tableActive],
105
+ );
106
+
107
+ if (!tableRef) {
108
+ return null;
134
109
  }
135
110
 
136
- render() {
137
- const {
138
- editorView,
139
- tableRef,
140
- tableNode,
141
- isInDanger,
142
- isResizing,
143
- isNumberColumnEnabled,
144
- isHeaderRowEnabled,
145
- isHeaderColumnEnabled,
146
- tableActive,
147
- hasHeaderRow,
148
- hoveredRows,
149
- stickyHeader,
150
- isDragAndDropEnabled,
151
- hoveredCell,
152
- isTableHovered,
153
- } = this.props;
154
-
155
- if (!tableRef) {
156
- return null;
157
- }
158
-
159
- const stickyTop =
160
- stickyHeader && stickyHeader.sticky && hasHeaderRow
161
- ? stickyHeader.top
162
- : undefined;
163
-
164
- const wrapperClassName = isDragAndDropEnabled
165
- ? ClassName.DRAG_ROW_CONTROLS_WRAPPER
166
- : ClassName.ROW_CONTROLS_WRAPPER;
167
-
168
- return (
169
- <div className={wrapperClassName}>
170
- <div onMouseDown={(e) => !isDragAndDropEnabled && e.preventDefault()}>
171
- {isNumberColumnEnabled ? (
172
- <NumberColumn
173
- editorView={editorView}
174
- hoverRows={this.hoverRows}
175
- tableRef={tableRef}
176
- tableActive={tableActive}
177
- hoveredRows={hoveredRows}
178
- hasHeaderRow={hasHeaderRow}
179
- isInDanger={isInDanger}
180
- isResizing={isResizing}
181
- selectRow={this.selectRow}
182
- updateCellHoverLocation={this.updateCellHoverLocation}
183
- stickyTop={stickyTop}
184
- isDragAndDropEnabled={isDragAndDropEnabled}
185
- />
186
- ) : null}
187
-
188
- {tableActive && (
189
- <>
190
- {isDragAndDropEnabled ? (
191
- <>
192
- <DragCornerControls
193
- editorView={editorView}
194
- tableRef={tableRef}
195
- isInDanger={isInDanger}
196
- isResizing={isResizing}
197
- />
198
- <DragControls
199
- tableRef={tableRef}
200
- tableNode={tableNode}
201
- hoveredCell={hoveredCell}
202
- isTableHovered={isTableHovered}
203
- editorView={editorView}
204
- tableActive={tableActive}
205
- isInDanger={isInDanger}
206
- isResizing={isResizing}
207
- tableWidth={this.state.tableWrapperWidth}
208
- hoverRows={this.hoverRows}
209
- selectRow={this.selectRow}
210
- selectRows={this.selectRows}
211
- updateCellHoverLocation={this.updateCellHoverLocation}
212
- />
213
- </>
214
- ) : (
215
- <>
216
- <CornerControls
217
- editorView={editorView}
218
- tableRef={tableRef}
219
- isInDanger={isInDanger}
220
- isResizing={isResizing}
221
- isHeaderRowEnabled={isHeaderRowEnabled}
222
- isHeaderColumnEnabled={isHeaderColumnEnabled}
223
- hoveredRows={hoveredRows}
224
- stickyTop={tableActive ? stickyTop : undefined}
225
- />
226
- <RowControls
227
- editorView={editorView}
228
- tableRef={tableRef}
229
- hoverRows={this.hoverRows}
230
- hoveredRows={hoveredRows}
231
- isInDanger={isInDanger}
232
- isResizing={isResizing}
233
- selectRow={this.selectRow}
234
- stickyTop={tableActive ? stickyTop : undefined}
235
- />
236
- </>
237
- )}
238
- </>
239
- )}
240
- </div>
111
+ const stickyTop =
112
+ stickyHeader && stickyHeader.sticky && hasHeaderRow
113
+ ? stickyHeader.top
114
+ : undefined;
115
+
116
+ const wrapperClassName = isDragAndDropEnabled
117
+ ? ClassName.DRAG_ROW_CONTROLS_WRAPPER
118
+ : ClassName.ROW_CONTROLS_WRAPPER;
119
+
120
+ return (
121
+ <div className={wrapperClassName}>
122
+ <div onMouseDown={(e) => !isDragAndDropEnabled && e.preventDefault()}>
123
+ {isNumberColumnEnabled ? (
124
+ <NumberColumn
125
+ editorView={editorView}
126
+ hoverRows={_hoverRows}
127
+ tableRef={tableRef}
128
+ tableActive={tableActive}
129
+ hoveredRows={hoveredRows}
130
+ hasHeaderRow={hasHeaderRow}
131
+ isInDanger={isInDanger}
132
+ isResizing={isResizing}
133
+ selectRow={_selectRow}
134
+ updateCellHoverLocation={updateCellHoverLocation}
135
+ stickyTop={stickyTop}
136
+ isDragAndDropEnabled={isDragAndDropEnabled}
137
+ />
138
+ ) : null}
139
+
140
+ {tableActive && (
141
+ <>
142
+ {isDragAndDropEnabled ? (
143
+ <>
144
+ <DragCornerControls
145
+ editorView={editorView}
146
+ tableRef={tableRef}
147
+ isInDanger={isInDanger}
148
+ isResizing={isResizing}
149
+ />
150
+ <DragControls
151
+ tableRef={tableRef}
152
+ tableNode={tableNode}
153
+ hoveredCell={hoveredCell}
154
+ isTableHovered={isTableHovered}
155
+ editorView={editorView}
156
+ tableActive={tableActive}
157
+ isInDanger={isInDanger}
158
+ isResizing={isResizing}
159
+ tableWidth={tableWrapperWidth!}
160
+ hoverRows={_hoverRows}
161
+ selectRow={_selectRow}
162
+ selectRows={_selectRows}
163
+ updateCellHoverLocation={updateCellHoverLocation}
164
+ />
165
+ </>
166
+ ) : (
167
+ <>
168
+ <CornerControls
169
+ editorView={editorView}
170
+ tableRef={tableRef}
171
+ isInDanger={isInDanger}
172
+ isResizing={isResizing}
173
+ isHeaderRowEnabled={isHeaderRowEnabled}
174
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
175
+ hoveredRows={hoveredRows}
176
+ stickyTop={tableActive ? stickyTop : undefined}
177
+ />
178
+ <RowControls
179
+ editorView={editorView}
180
+ tableRef={tableRef}
181
+ hoverRows={_hoverRows}
182
+ hoveredRows={hoveredRows}
183
+ isInDanger={isInDanger}
184
+ isResizing={isResizing}
185
+ selectRow={_selectRow}
186
+ stickyTop={tableActive ? stickyTop : undefined}
187
+ />
188
+ </>
189
+ )}
190
+ </>
191
+ )}
241
192
  </div>
242
- );
243
- }
193
+ </div>
194
+ );
195
+ };
244
196
 
245
- private selectRow = (row: number, expand: boolean) => {
246
- const { editorView } = this.props;
247
- const { state, dispatch } = editorView;
248
- // fix for issue ED-4665
249
- if (browser.ie_version === 11) {
250
- (editorView.dom as HTMLElement).blur();
251
- }
252
- selectRow(row, expand)(state, dispatch);
253
- };
254
-
255
- private selectRows = (rowIndexes: number[]) => {
256
- const { editorView } = this.props;
257
- const { state, dispatch } = editorView;
258
- // fix for issue ED-4665
259
- if (browser.ie_version === 11) {
260
- (editorView.dom as HTMLElement).blur();
261
- }
262
- selectRows(rowIndexes)(state, dispatch);
263
- };
264
-
265
- private hoverRows = (rows: Array<number>, danger?: boolean) => {
266
- const { state, dispatch } = this.props.editorView;
267
- hoverRows(rows, danger)(state, dispatch);
268
- };
269
-
270
- // re-use across numbered columns and row controls
271
- private updateCellHoverLocation = (rowIndex: number) => {
272
- const { editorView, tableActive } = this.props;
273
- const { state, dispatch } = editorView;
274
-
275
- if (tableActive) {
276
- // For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
277
- // of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
278
- // also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
279
- // current column index. We can just force it to 0.
280
- hoverCell(rowIndex, 0)(state, dispatch);
281
- }
282
- };
283
- }
197
+ export default TableFloatingControls;
@@ -6,7 +6,6 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import {
8
8
  findTable,
9
- getCellsInColumn,
10
9
  getSelectionRect,
11
10
  isColumnSelected,
12
11
  isTableSelected,
@@ -34,13 +33,13 @@ export const getColumnsWidths = (
34
33
  // When there is no cell we need to fill it with undefined
35
34
  widths = Array.from({ length: map.width });
36
35
  for (let i = 0; i < map.width; i++) {
37
- const cells = getCellsInColumn(i)(selection)!;
38
- const cell = cells[0];
39
- if (cell) {
40
- const cellRef = findDomRefAtPos(cell.pos, domAtPos) as HTMLElement;
36
+ if (!map.isCellMergedTopLeft(0, i)) {
37
+ const node = table.node.nodeAt(map.map[i])!;
38
+ const pos = map.map[i] + table.start;
39
+ const cellRef = findDomRefAtPos(pos, domAtPos) as HTMLElement;
41
40
  const rect = cellRef.getBoundingClientRect();
42
41
  widths[i] = (rect ? rect.width : cellRef.offsetWidth) + 1;
43
- i += cell.node.attrs.colspan - 1;
42
+ i += node.attrs.colspan - 1;
44
43
  }
45
44
  }
46
45
  }