@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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/commands/selection.js +23 -1
- package/dist/cjs/event-handlers.js +25 -9
- package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/cjs/nodeviews/TableCell.js +5 -30
- package/dist/cjs/nodeviews/TableComponent.js +96 -41
- package/dist/cjs/nodeviews/TableContainer.js +19 -17
- package/dist/cjs/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/plugin.js +2 -3
- package/dist/cjs/pm-plugins/main.js +3 -18
- package/dist/cjs/pm-plugins/sticky-headers/types.js +1 -5
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +11 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +22 -23
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/cjs/pm-plugins/table-selection-keymap.js +3 -0
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
- package/dist/cjs/utils/column-controls.js +5 -5
- package/dist/cjs/utils/dom.js +13 -15
- package/dist/es2019/commands/selection.js +22 -0
- package/dist/es2019/event-handlers.js +25 -9
- package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/es2019/nodeviews/TableCell.js +1 -24
- package/dist/es2019/nodeviews/TableComponent.js +69 -31
- package/dist/es2019/nodeviews/TableContainer.js +16 -18
- package/dist/es2019/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/plugin.js +2 -3
- package/dist/es2019/pm-plugins/main.js +3 -18
- package/dist/es2019/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +21 -22
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/es2019/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
- package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
- package/dist/es2019/utils/column-controls.js +6 -6
- package/dist/es2019/utils/dom.js +13 -15
- package/dist/esm/commands/selection.js +22 -0
- package/dist/esm/event-handlers.js +25 -9
- package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/esm/nodeviews/TableCell.js +5 -30
- package/dist/esm/nodeviews/TableComponent.js +96 -41
- package/dist/esm/nodeviews/TableContainer.js +20 -18
- package/dist/esm/nodeviews/TableResizer.js +1 -1
- package/dist/esm/plugin.js +2 -3
- package/dist/esm/pm-plugins/main.js +3 -18
- package/dist/esm/pm-plugins/sticky-headers/types.js +0 -1
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +3 -7
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +10 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +23 -24
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -2
- package/dist/esm/pm-plugins/table-selection-keymap.js +5 -2
- package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/esm/ui/TableFloatingControls/index.js +113 -224
- package/dist/esm/utils/column-controls.js +6 -6
- package/dist/esm/utils/dom.js +13 -15
- package/dist/types/commands/selection.d.ts +1 -0
- package/dist/types/event-handlers.d.ts +3 -4
- package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types/nodeviews/TableCell.d.ts +1 -5
- package/dist/types/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types/types.d.ts +0 -3
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types/utils/dom.d.ts +10 -2
- package/dist/types-ts4.5/commands/selection.d.ts +1 -0
- package/dist/types-ts4.5/event-handlers.d.ts +3 -4
- package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +0 -3
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types-ts4.5/utils/dom.d.ts +10 -2
- package/package.json +8 -6
- package/src/commands/selection.ts +33 -0
- package/src/event-handlers.ts +105 -103
- package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
- package/src/nodeviews/TableCell.ts +0 -26
- package/src/nodeviews/TableComponent.tsx +81 -34
- package/src/nodeviews/TableContainer.tsx +19 -25
- package/src/nodeviews/TableResizer.tsx +1 -4
- package/src/plugin.tsx +5 -4
- package/src/pm-plugins/main.ts +3 -22
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +3 -6
- package/src/pm-plugins/table-resizing/utils/misc.ts +13 -0
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +22 -28
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +3 -10
- package/src/pm-plugins/table-selection-keymap.ts +10 -0
- package/src/types.ts +0 -4
- package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
- package/src/ui/TableFloatingControls/index.tsx +155 -241
- package/src/utils/column-controls.ts +5 -6
- 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 {
|
|
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
|
|
81
|
+
if (isTableScalingEnabled) {
|
|
82
|
+
const tableNodeWidth = getTableContainerWidth(table);
|
|
83
83
|
return {
|
|
84
84
|
index,
|
|
85
|
-
width:
|
|
86
|
-
minWidth
|
|
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
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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,
|
|
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 && !!
|
|
94
|
+
if (tableRef && !!tableWrapperHeight) {
|
|
119
95
|
return getRowHeights(tableRef);
|
|
120
96
|
}
|
|
121
97
|
return [0];
|
|
122
|
-
}, [tableRef,
|
|
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={
|
|
144
|
+
tableHeight={tableWrapperHeight}
|
|
169
145
|
localId={currentNodeLocalId}
|
|
170
146
|
colWidths={colWidths}
|
|
171
147
|
getScrollOffset={getScrollOffset}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import 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
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const cellRef = findDomRefAtPos(
|
|
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 +=
|
|
42
|
+
i += node.attrs.colspan - 1;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
}
|