@atlaskit/editor-plugin-table 5.4.16 → 5.4.18
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 +14 -0
- package/dist/cjs/plugins/table/commands/hover.js +4 -2
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +2 -2
- package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +4 -6
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -62
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +31 -62
- package/dist/es2019/plugins/table/commands/hover.js +4 -2
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +2 -2
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -3
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -63
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +29 -61
- package/dist/esm/plugins/table/commands/hover.js +4 -2
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +2 -2
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +5 -3
- package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -4
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +33 -62
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +29 -60
- package/dist/types/plugins/table/types.d.ts +1 -1
- package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +0 -1
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +1 -2
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/plugins/table/commands/hover.ts +2 -0
- package/src/plugins/table/nodeviews/TableComponent.tsx +1 -1
- package/src/plugins/table/nodeviews/TableResizer.tsx +4 -2
- package/src/plugins/table/types.ts +1 -2
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +9 -10
- package/src/plugins/table/ui/DragHandle/index.tsx +8 -6
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +3 -2
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +48 -118
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +41 -126
|
@@ -64,6 +64,7 @@ export interface TablePluginState {
|
|
|
64
64
|
tableWrapperTarget?: HTMLElement;
|
|
65
65
|
isContextualMenuOpen?: boolean;
|
|
66
66
|
isInDanger?: boolean;
|
|
67
|
+
isWholeTableInDanger?: boolean;
|
|
67
68
|
insertColumnButtonIndex?: number;
|
|
68
69
|
insertRowButtonIndex?: number;
|
|
69
70
|
isFullWidthModeEnabled?: boolean;
|
|
@@ -420,4 +421,3 @@ export interface DraggableData {
|
|
|
420
421
|
targetClosestEdge: Edge;
|
|
421
422
|
direction: 1 | -1;
|
|
422
423
|
}
|
|
423
|
-
export type HandleTypes = 'hover' | 'selected';
|
|
@@ -5,7 +5,6 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
|
5
5
|
type DragHandleProps = {
|
|
6
6
|
tableLocalId: string;
|
|
7
7
|
indexes: number[];
|
|
8
|
-
forceDefaultHandle?: boolean;
|
|
9
8
|
previewWidth?: number;
|
|
10
9
|
previewHeight?: number;
|
|
11
10
|
direction?: TableDirection;
|
|
@@ -16,5 +15,5 @@ type DragHandleProps = {
|
|
|
16
15
|
onMouseUp?: MouseEventHandler;
|
|
17
16
|
editorView: EditorView;
|
|
18
17
|
};
|
|
19
|
-
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes,
|
|
18
|
+
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
|
|
20
19
|
export {};
|
package/package.json
CHANGED
|
@@ -157,6 +157,7 @@ export const hoverTable = (isInDanger?: boolean, isSelected?: boolean) =>
|
|
|
157
157
|
hoveredColumns,
|
|
158
158
|
hoveredRows,
|
|
159
159
|
isInDanger,
|
|
160
|
+
isWholeTableInDanger: isInDanger,
|
|
160
161
|
},
|
|
161
162
|
};
|
|
162
163
|
},
|
|
@@ -173,6 +174,7 @@ export const clearHoverSelection = () =>
|
|
|
173
174
|
TableDecorations.ALL_CONTROLS_HOVER,
|
|
174
175
|
),
|
|
175
176
|
isInDanger: false,
|
|
177
|
+
isWholeTableInDanger: false,
|
|
176
178
|
},
|
|
177
179
|
}));
|
|
178
180
|
|
|
@@ -143,7 +143,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
143
143
|
this.containerWidth = containerWidth;
|
|
144
144
|
this.isInitialOverflowSent = false;
|
|
145
145
|
|
|
146
|
-
// store table size using previous full-width mode so can detect if it has changed
|
|
146
|
+
// store table size using previous full-width mode so can detect if it has changed.
|
|
147
147
|
const isFullWidthModeEnabled = options
|
|
148
148
|
? options.wasFullWidthModeEnabled
|
|
149
149
|
: false;
|
|
@@ -155,7 +155,7 @@ export const TableResizer = ({
|
|
|
155
155
|
|
|
156
156
|
const resizerMinWidth = getResizerMinWidth(node);
|
|
157
157
|
const handleSize = getResizerHandleHeight(tableRef);
|
|
158
|
-
const {
|
|
158
|
+
const { isWholeTableInDanger } = getPluginState(editorView.state);
|
|
159
159
|
|
|
160
160
|
const { startMeasure, endMeasure, countFrames } = useMeasureFramerate();
|
|
161
161
|
|
|
@@ -394,7 +394,9 @@ export const TableResizer = ({
|
|
|
394
394
|
snap={guidelineSnaps}
|
|
395
395
|
handlePositioning="adjacent"
|
|
396
396
|
isHandleVisible={isTableSelected}
|
|
397
|
-
appearance={
|
|
397
|
+
appearance={
|
|
398
|
+
isTableSelected && isWholeTableInDanger ? 'danger' : undefined
|
|
399
|
+
}
|
|
398
400
|
handleHighlight="shadow"
|
|
399
401
|
handleTooltipContent={formatMessage(messages.resizeTable)}
|
|
400
402
|
>
|
|
@@ -109,6 +109,7 @@ export interface TablePluginState {
|
|
|
109
109
|
tableWrapperTarget?: HTMLElement;
|
|
110
110
|
isContextualMenuOpen?: boolean;
|
|
111
111
|
isInDanger?: boolean;
|
|
112
|
+
isWholeTableInDanger?: boolean;
|
|
112
113
|
insertColumnButtonIndex?: number;
|
|
113
114
|
insertRowButtonIndex?: number;
|
|
114
115
|
isFullWidthModeEnabled?: boolean;
|
|
@@ -462,5 +463,3 @@ export interface DraggableData {
|
|
|
462
463
|
targetClosestEdge: Edge;
|
|
463
464
|
direction: 1 | -1;
|
|
464
465
|
}
|
|
465
|
-
|
|
466
|
-
export type HandleTypes = 'hover' | 'selected';
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type HandleIconProps = {
|
|
10
10
|
hasMergedCells: boolean;
|
|
11
11
|
direction: 'row' | 'column';
|
|
12
|
-
forceDefaultHandle: boolean;
|
|
13
12
|
isDragMenuOpen: boolean | undefined;
|
|
14
13
|
isRowHandleHovered: boolean;
|
|
15
14
|
isColumnHandleHovered: boolean;
|
|
@@ -21,7 +20,6 @@ type HandleIconProps = {
|
|
|
21
20
|
export const HandleIconComponent = (props: HandleIconProps) => {
|
|
22
21
|
const {
|
|
23
22
|
direction,
|
|
24
|
-
forceDefaultHandle,
|
|
25
23
|
isDragMenuOpen,
|
|
26
24
|
isRowHandleHovered,
|
|
27
25
|
isColumnHandleHovered,
|
|
@@ -31,21 +29,22 @@ export const HandleIconComponent = (props: HandleIconProps) => {
|
|
|
31
29
|
dragMenuDirection,
|
|
32
30
|
} = props;
|
|
33
31
|
const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
34
|
-
|
|
35
32
|
const isCurrentRowOrColumnSelected =
|
|
36
33
|
isCurrentRowSelected || isCurrentColumnSelected;
|
|
37
|
-
|
|
38
34
|
const isDragMenuOpenOnCurrentRowOrColumn =
|
|
39
35
|
isDragMenuOpen &&
|
|
40
36
|
dragMenuDirection === direction &&
|
|
41
37
|
isCurrentRowOrColumnSelected;
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
39
|
+
const showNormalHandle = hasMergedCells ? (
|
|
40
|
+
<DragHandleDisabledIcon />
|
|
41
|
+
) : (
|
|
42
|
+
<DragHandleIcon />
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// hoverred handle or open drag menu
|
|
46
|
+
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
47
|
+
return showNormalHandle;
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
return <MinimisedHandleIcon />;
|
|
@@ -4,6 +4,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
import ReactDOM from 'react-dom';
|
|
6
6
|
|
|
7
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
8
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
9
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
9
10
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
@@ -22,7 +23,6 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
|
22
23
|
type DragHandleProps = {
|
|
23
24
|
tableLocalId: string;
|
|
24
25
|
indexes: number[];
|
|
25
|
-
forceDefaultHandle?: boolean;
|
|
26
26
|
previewWidth?: number;
|
|
27
27
|
previewHeight?: number;
|
|
28
28
|
direction?: TableDirection;
|
|
@@ -39,7 +39,6 @@ export const DragHandle = ({
|
|
|
39
39
|
direction = 'row',
|
|
40
40
|
appearance = 'default',
|
|
41
41
|
indexes,
|
|
42
|
-
forceDefaultHandle = false,
|
|
43
42
|
previewWidth,
|
|
44
43
|
previewHeight,
|
|
45
44
|
onMouseOver,
|
|
@@ -65,7 +64,6 @@ export const DragHandle = ({
|
|
|
65
64
|
isDragMenuOpen &&
|
|
66
65
|
direction === 'row' &&
|
|
67
66
|
hoveredCell.rowIndex === dragMenuIndex;
|
|
68
|
-
|
|
69
67
|
const isCurrentColumnSelected =
|
|
70
68
|
isDragMenuOpen &&
|
|
71
69
|
direction === 'column' &&
|
|
@@ -86,7 +84,6 @@ export const DragHandle = ({
|
|
|
86
84
|
const handleIconProps = {
|
|
87
85
|
hasMergedCells,
|
|
88
86
|
direction,
|
|
89
|
-
forceDefaultHandle,
|
|
90
87
|
isDragMenuOpen,
|
|
91
88
|
isRowHandleHovered,
|
|
92
89
|
isColumnHandleHovered,
|
|
@@ -163,9 +160,14 @@ export const DragHandle = ({
|
|
|
163
160
|
}}
|
|
164
161
|
onClick={onClick}
|
|
165
162
|
>
|
|
166
|
-
|
|
163
|
+
{/* cannot block pointer events in Firefox as it breaks Dragging functionality */}
|
|
164
|
+
{browser.gecko ? (
|
|
167
165
|
<HandleIconComponent {...handleIconProps} />
|
|
168
|
-
|
|
166
|
+
) : (
|
|
167
|
+
<span style={{ pointerEvents: 'none' }}>
|
|
168
|
+
<HandleIconComponent {...handleIconProps} />
|
|
169
|
+
</span>
|
|
170
|
+
)}
|
|
169
171
|
</button>
|
|
170
172
|
{previewContainer &&
|
|
171
173
|
previewWidth !== undefined &&
|
|
@@ -131,12 +131,13 @@ export const DragMenu = ({
|
|
|
131
131
|
const hasMergedCells =
|
|
132
132
|
direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
133
133
|
|
|
134
|
-
const
|
|
134
|
+
const shouldMoveDisabled =
|
|
135
|
+
index !== undefined && hasMergedCells(index)(selection);
|
|
135
136
|
|
|
136
137
|
const dragMenuConfig = getDragMenuConfig(
|
|
137
138
|
direction,
|
|
138
139
|
getEditorContainerWidth,
|
|
139
|
-
|
|
140
|
+
shouldMoveDisabled,
|
|
140
141
|
tableMap,
|
|
141
142
|
index,
|
|
142
143
|
targetCellPosition,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
1
|
import type { MouseEvent } from 'react';
|
|
3
2
|
import React, { useCallback, useMemo } from 'react';
|
|
4
3
|
|
|
@@ -14,8 +13,7 @@ import {
|
|
|
14
13
|
selectColumn,
|
|
15
14
|
} from '../../../commands';
|
|
16
15
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
17
|
-
import {
|
|
18
|
-
import type { CellHoverMeta, HandleTypes } from '../../../types';
|
|
16
|
+
import type { CellHoverMeta } from '../../../types';
|
|
19
17
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
20
18
|
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
21
19
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -68,6 +66,14 @@ export const ColumnControls = ({
|
|
|
68
66
|
const colIndex = hoveredCell?.colIndex;
|
|
69
67
|
const selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
70
68
|
|
|
69
|
+
const gridColumnPosition = useMemo(() => {
|
|
70
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
71
|
+
if (selectedColIndexes.includes(colIndex!)) {
|
|
72
|
+
return `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
|
|
73
|
+
}
|
|
74
|
+
return `${colIndex! + 1} / span 1`;
|
|
75
|
+
}, [colIndex, selectedColIndexes]);
|
|
76
|
+
|
|
71
77
|
const firstRow = tableRef.querySelector('tr');
|
|
72
78
|
const hasHeaderRow = firstRow
|
|
73
79
|
? firstRow.getAttribute('data-header-row')
|
|
@@ -134,120 +140,6 @@ export const ColumnControls = ({
|
|
|
134
140
|
|
|
135
141
|
const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
|
|
136
142
|
|
|
137
|
-
const generateHandleByType = useCallback(
|
|
138
|
-
(type: HandleTypes): JSX.Element | null => {
|
|
139
|
-
if (!hoveredCell) {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
const { isDragMenuOpen, dragMenuIndex, dragMenuDirection } =
|
|
143
|
-
getDragDropPluginState(editorView.state);
|
|
144
|
-
const isHover = type === 'hover';
|
|
145
|
-
|
|
146
|
-
const isHoveredOnSelectedColumn =
|
|
147
|
-
isDragMenuOpen &&
|
|
148
|
-
dragMenuDirection === 'column' &&
|
|
149
|
-
dragMenuIndex === colIndex;
|
|
150
|
-
|
|
151
|
-
const showCondition = isHover
|
|
152
|
-
? !isHoveredOnSelectedColumn && Number.isFinite(hoveredCell?.colIndex)
|
|
153
|
-
: isDragMenuOpen && dragMenuDirection === 'column';
|
|
154
|
-
|
|
155
|
-
if (!showCondition) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const selectedColumnPosition = `${dragMenuIndex + 1} / span ${
|
|
160
|
-
selectedColIndexes.length
|
|
161
|
-
}`;
|
|
162
|
-
|
|
163
|
-
const gridColumnPosition = selectedColIndexes.includes(colIndex!)
|
|
164
|
-
? `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`
|
|
165
|
-
: `${colIndex! + 1} / span 1`;
|
|
166
|
-
|
|
167
|
-
const selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
168
|
-
const hoveredAppearance = selectedColIndexes.includes(colIndex!)
|
|
169
|
-
? isInDanger
|
|
170
|
-
? 'danger'
|
|
171
|
-
: 'selected'
|
|
172
|
-
: 'default';
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
showCondition && (
|
|
176
|
-
<div
|
|
177
|
-
key={type}
|
|
178
|
-
style={{
|
|
179
|
-
gridColumn: isHover ? gridColumnPosition : selectedColumnPosition,
|
|
180
|
-
display: 'flex',
|
|
181
|
-
justifyContent: 'center',
|
|
182
|
-
alignItems: 'center',
|
|
183
|
-
height: 'fit-content',
|
|
184
|
-
placeSelf: 'center',
|
|
185
|
-
zIndex: 99,
|
|
186
|
-
}}
|
|
187
|
-
data-column-control-index={hoveredCell.colIndex}
|
|
188
|
-
data-testid={
|
|
189
|
-
isHover
|
|
190
|
-
? 'table-floating-column-control'
|
|
191
|
-
: 'table-floating-column-control-selected'
|
|
192
|
-
}
|
|
193
|
-
>
|
|
194
|
-
<DragHandle
|
|
195
|
-
direction="column"
|
|
196
|
-
tableLocalId={localId || ''}
|
|
197
|
-
indexes={isHover ? colIndexes : selectedColIndexes}
|
|
198
|
-
forceDefaultHandle={!isHover}
|
|
199
|
-
previewWidth={colWidths?.[colIndex!] ?? 48}
|
|
200
|
-
previewHeight={previewHeight}
|
|
201
|
-
appearance={isHover ? hoveredAppearance : selectedApprearance}
|
|
202
|
-
onClick={handleClick}
|
|
203
|
-
onMouseOver={handleMouseOver}
|
|
204
|
-
onMouseOut={handleMouseOut}
|
|
205
|
-
onMouseUp={handleMouseUp}
|
|
206
|
-
editorView={editorView}
|
|
207
|
-
/>
|
|
208
|
-
</div>
|
|
209
|
-
)
|
|
210
|
-
);
|
|
211
|
-
},
|
|
212
|
-
[
|
|
213
|
-
colIndex,
|
|
214
|
-
previewHeight,
|
|
215
|
-
colWidths,
|
|
216
|
-
colIndexes,
|
|
217
|
-
editorView,
|
|
218
|
-
handleClick,
|
|
219
|
-
handleMouseOut,
|
|
220
|
-
handleMouseOver,
|
|
221
|
-
handleMouseUp,
|
|
222
|
-
hoveredCell,
|
|
223
|
-
isInDanger,
|
|
224
|
-
localId,
|
|
225
|
-
selectedColIndexes,
|
|
226
|
-
],
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
const columnHandles = useCallback(
|
|
230
|
-
(hoveredCell: CellHoverMeta | undefined) => {
|
|
231
|
-
if (!hoveredCell) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (hoveredCell.colIndex === undefined) {
|
|
236
|
-
return generateHandleByType('selected');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const sortedHandles = [
|
|
240
|
-
generateHandleByType('hover'),
|
|
241
|
-
generateHandleByType('selected'),
|
|
242
|
-
];
|
|
243
|
-
|
|
244
|
-
return hoveredCell.colIndex < selectedColIndexes[0]
|
|
245
|
-
? sortedHandles
|
|
246
|
-
: sortedHandles.reverse();
|
|
247
|
-
},
|
|
248
|
-
[generateHandleByType, selectedColIndexes],
|
|
249
|
-
);
|
|
250
|
-
|
|
251
143
|
return (
|
|
252
144
|
<div
|
|
253
145
|
className={ClassName.DRAG_COLUMN_CONTROLS}
|
|
@@ -289,7 +181,45 @@ export const ColumnControls = ({
|
|
|
289
181
|
/>
|
|
290
182
|
</div>
|
|
291
183
|
))}
|
|
292
|
-
{tableActive &&
|
|
184
|
+
{tableActive &&
|
|
185
|
+
!isResizing &&
|
|
186
|
+
isTableHovered &&
|
|
187
|
+
!!hoveredCell &&
|
|
188
|
+
Number.isFinite(hoveredCell.colIndex) && (
|
|
189
|
+
<div
|
|
190
|
+
style={{
|
|
191
|
+
gridColumn: gridColumnPosition,
|
|
192
|
+
display: 'flex',
|
|
193
|
+
justifyContent: 'center',
|
|
194
|
+
alignItems: 'center',
|
|
195
|
+
height: 'fit-content',
|
|
196
|
+
placeSelf: 'center',
|
|
197
|
+
zIndex: 99,
|
|
198
|
+
}}
|
|
199
|
+
data-column-control-index={hoveredCell.colIndex}
|
|
200
|
+
data-testid="table-floating-column-control"
|
|
201
|
+
>
|
|
202
|
+
<DragHandle
|
|
203
|
+
direction="column"
|
|
204
|
+
tableLocalId={localId || ''}
|
|
205
|
+
indexes={colIndexes}
|
|
206
|
+
previewWidth={colWidths?.[colIndex!] ?? 48}
|
|
207
|
+
previewHeight={previewHeight}
|
|
208
|
+
appearance={
|
|
209
|
+
selectedColIndexes.includes(hoveredCell.colIndex!)
|
|
210
|
+
? isInDanger
|
|
211
|
+
? 'danger'
|
|
212
|
+
: 'selected'
|
|
213
|
+
: 'default'
|
|
214
|
+
}
|
|
215
|
+
onClick={handleClick}
|
|
216
|
+
onMouseOver={handleMouseOver}
|
|
217
|
+
onMouseOut={handleMouseOut}
|
|
218
|
+
onMouseUp={handleMouseUp}
|
|
219
|
+
editorView={editorView}
|
|
220
|
+
/>
|
|
221
|
+
</div>
|
|
222
|
+
)}
|
|
293
223
|
</div>
|
|
294
224
|
</div>
|
|
295
225
|
);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
1
|
import type { MouseEvent } from 'react';
|
|
3
2
|
import React, {
|
|
4
3
|
Fragment,
|
|
@@ -21,14 +20,9 @@ import { token } from '@atlaskit/tokens';
|
|
|
21
20
|
|
|
22
21
|
import { clearHoverSelection } from '../../../commands';
|
|
23
22
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
24
|
-
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
25
23
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
26
24
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
27
|
-
import type {
|
|
28
|
-
CellHoverMeta,
|
|
29
|
-
DraggableSourceData,
|
|
30
|
-
HandleTypes,
|
|
31
|
-
} from '../../../types';
|
|
25
|
+
import type { CellHoverMeta, DraggableSourceData } from '../../../types';
|
|
32
26
|
import {
|
|
33
27
|
getRowHeights,
|
|
34
28
|
getRowsParams,
|
|
@@ -120,6 +114,14 @@ const DragControlsComponent = ({
|
|
|
120
114
|
|
|
121
115
|
const rowIndex = hoveredCell?.rowIndex;
|
|
122
116
|
|
|
117
|
+
const gridRowPosition = useMemo(() => {
|
|
118
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
119
|
+
if (selectedRowIndexes.includes(rowIndex!)) {
|
|
120
|
+
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
121
|
+
}
|
|
122
|
+
return `${rowIndex! + 1} / span 1`;
|
|
123
|
+
}, [rowIndex, selectedRowIndexes]);
|
|
124
|
+
|
|
123
125
|
const handleMouseOut = useCallback(() => {
|
|
124
126
|
if (tableActive) {
|
|
125
127
|
const { state, dispatch } = editorView;
|
|
@@ -161,124 +163,6 @@ const DragControlsComponent = ({
|
|
|
161
163
|
[rowIndex, selectRow],
|
|
162
164
|
);
|
|
163
165
|
|
|
164
|
-
const generateHandleByType = useCallback(
|
|
165
|
-
(type: HandleTypes): JSX.Element | null => {
|
|
166
|
-
if (!hoveredCell) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
const { isDragMenuOpen, dragMenuIndex, dragMenuDirection } =
|
|
170
|
-
getDragDropPluginState(editorView.state);
|
|
171
|
-
const isHover = type === 'hover';
|
|
172
|
-
|
|
173
|
-
const isHoveredOnSelectedRow =
|
|
174
|
-
isDragMenuOpen &&
|
|
175
|
-
dragMenuDirection === 'row' &&
|
|
176
|
-
dragMenuIndex === rowIndex;
|
|
177
|
-
|
|
178
|
-
const showCondition = isHover
|
|
179
|
-
? !isHoveredOnSelectedRow &&
|
|
180
|
-
!selectedRowIndexes.includes(rowIndex!) &&
|
|
181
|
-
Number.isFinite(hoveredCell?.colIndex)
|
|
182
|
-
: isDragMenuOpen &&
|
|
183
|
-
dragMenuDirection === 'row' &&
|
|
184
|
-
Number.isFinite(hoveredCell?.colIndex);
|
|
185
|
-
|
|
186
|
-
if (!showCondition) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const gridRowPosition =
|
|
191
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
192
|
-
selectedRowIndexes.includes(rowIndex!)
|
|
193
|
-
? `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`
|
|
194
|
-
: `${rowIndex! + 1} / span 1`;
|
|
195
|
-
|
|
196
|
-
const selectedRowPosition = `${dragMenuIndex + 1} / span ${
|
|
197
|
-
selectedRowIndexes.length
|
|
198
|
-
}`;
|
|
199
|
-
|
|
200
|
-
const selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
201
|
-
const hoveredAppearance = selectedRowIndexes.includes(rowIndex!)
|
|
202
|
-
? isInDanger
|
|
203
|
-
? 'danger'
|
|
204
|
-
: 'selected'
|
|
205
|
-
: 'default';
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
showCondition && (
|
|
209
|
-
<div
|
|
210
|
-
key={type}
|
|
211
|
-
style={{
|
|
212
|
-
gridRow: isHover ? gridRowPosition : selectedRowPosition,
|
|
213
|
-
gridColumn: '2',
|
|
214
|
-
display: 'flex',
|
|
215
|
-
height: '100%',
|
|
216
|
-
alignItems: 'center',
|
|
217
|
-
justifyContent: 'center',
|
|
218
|
-
}}
|
|
219
|
-
data-testid={
|
|
220
|
-
isHover
|
|
221
|
-
? 'table-floating-row-drag-handle'
|
|
222
|
-
: 'table-floating-row-control-selected'
|
|
223
|
-
}
|
|
224
|
-
>
|
|
225
|
-
<DragHandle
|
|
226
|
-
direction="row"
|
|
227
|
-
tableLocalId={currentNodeLocalId}
|
|
228
|
-
indexes={isHover ? rowIndexes : selectedRowIndexes}
|
|
229
|
-
forceDefaultHandle={!isHover}
|
|
230
|
-
previewWidth={tableWidth}
|
|
231
|
-
previewHeight={rowHeights[rowIndex!]}
|
|
232
|
-
appearance={isHover ? hoveredAppearance : selectedApprearance}
|
|
233
|
-
onClick={handleClick}
|
|
234
|
-
onMouseOver={handleMouseOver}
|
|
235
|
-
onMouseOut={handleMouseOut}
|
|
236
|
-
onMouseUp={onMouseUp}
|
|
237
|
-
editorView={editorView}
|
|
238
|
-
/>
|
|
239
|
-
</div>
|
|
240
|
-
)
|
|
241
|
-
);
|
|
242
|
-
},
|
|
243
|
-
[
|
|
244
|
-
currentNodeLocalId,
|
|
245
|
-
editorView,
|
|
246
|
-
handleClick,
|
|
247
|
-
handleMouseOut,
|
|
248
|
-
handleMouseOver,
|
|
249
|
-
hoveredCell,
|
|
250
|
-
isInDanger,
|
|
251
|
-
onMouseUp,
|
|
252
|
-
rowHeights,
|
|
253
|
-
rowIndex,
|
|
254
|
-
rowIndexes,
|
|
255
|
-
selectedRowIndexes,
|
|
256
|
-
tableWidth,
|
|
257
|
-
],
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
const rowHandles = useCallback(
|
|
261
|
-
(hoveredCell: CellHoverMeta | undefined) => {
|
|
262
|
-
if (!hoveredCell) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (hoveredCell.rowIndex === undefined) {
|
|
267
|
-
return generateHandleByType('selected');
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const sortedHandles = [
|
|
271
|
-
generateHandleByType('hover'),
|
|
272
|
-
generateHandleByType('selected'),
|
|
273
|
-
];
|
|
274
|
-
|
|
275
|
-
return hoveredCell.rowIndex < selectedRowIndexes[0]
|
|
276
|
-
? sortedHandles
|
|
277
|
-
: sortedHandles.reverse();
|
|
278
|
-
},
|
|
279
|
-
[generateHandleByType, selectedRowIndexes],
|
|
280
|
-
);
|
|
281
|
-
|
|
282
166
|
return (
|
|
283
167
|
<div
|
|
284
168
|
className={ClassName.DRAG_ROW_CONTROLS}
|
|
@@ -335,7 +219,38 @@ const DragControlsComponent = ({
|
|
|
335
219
|
)}
|
|
336
220
|
</Fragment>
|
|
337
221
|
))}
|
|
338
|
-
{!isResizing && Number.isFinite(rowIndex) &&
|
|
222
|
+
{!isResizing && isTableHovered && Number.isFinite(rowIndex) && (
|
|
223
|
+
<div
|
|
224
|
+
style={{
|
|
225
|
+
gridRow: gridRowPosition,
|
|
226
|
+
gridColumn: '2',
|
|
227
|
+
display: 'flex',
|
|
228
|
+
height: '100%',
|
|
229
|
+
alignItems: 'center',
|
|
230
|
+
justifyContent: 'center',
|
|
231
|
+
}}
|
|
232
|
+
data-testid="table-floating-row-drag-handle"
|
|
233
|
+
>
|
|
234
|
+
<DragHandle
|
|
235
|
+
tableLocalId={currentNodeLocalId}
|
|
236
|
+
indexes={rowIndexes}
|
|
237
|
+
previewWidth={tableWidth}
|
|
238
|
+
previewHeight={rowHeights[rowIndex!]}
|
|
239
|
+
appearance={
|
|
240
|
+
selectedRowIndexes.includes(rowIndex!)
|
|
241
|
+
? isInDanger
|
|
242
|
+
? 'danger'
|
|
243
|
+
: 'selected'
|
|
244
|
+
: 'default'
|
|
245
|
+
}
|
|
246
|
+
onClick={handleClick}
|
|
247
|
+
onMouseOver={handleMouseOver}
|
|
248
|
+
onMouseOut={handleMouseOut}
|
|
249
|
+
onMouseUp={onMouseUp}
|
|
250
|
+
editorView={editorView}
|
|
251
|
+
/>
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
339
254
|
</div>
|
|
340
255
|
);
|
|
341
256
|
};
|