@atlaskit/editor-plugin-table 5.4.15 → 5.4.16
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 +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -33
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +62 -31
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +63 -33
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +61 -29
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -5
- package/dist/esm/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +62 -33
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +60 -29
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/HandleIconComponent.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +10 -9
- package/src/plugins/table/ui/DragHandle/index.tsx +4 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +118 -48
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +126 -41
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
|
|
1
3
|
import React, { useCallback, useMemo } from 'react';
|
|
2
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
3
5
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
6
|
import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
|
|
5
7
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
8
|
+
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
6
9
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
10
|
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
8
11
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -17,7 +20,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
|
|
|
17
20
|
return [];
|
|
18
21
|
};
|
|
19
22
|
export var ColumnControls = function ColumnControls(_ref) {
|
|
20
|
-
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce
|
|
23
|
+
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
|
|
21
24
|
var editorView = _ref.editorView,
|
|
22
25
|
tableActive = _ref.tableActive,
|
|
23
26
|
tableRef = _ref.tableRef,
|
|
@@ -37,13 +40,6 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
37
40
|
var columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
38
41
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
39
42
|
var selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
40
|
-
var gridColumnPosition = useMemo(function () {
|
|
41
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
42
|
-
if (selectedColIndexes.includes(colIndex)) {
|
|
43
|
-
return "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
|
|
44
|
-
}
|
|
45
|
-
return "".concat(colIndex + 1, " / span 1");
|
|
46
|
-
}, [colIndex, selectedColIndexes]);
|
|
47
43
|
var firstRow = tableRef.querySelector('tr');
|
|
48
44
|
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
49
45
|
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
@@ -95,6 +91,63 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
95
91
|
var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
|
|
96
92
|
return sum + cur;
|
|
97
93
|
}, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
|
|
94
|
+
var generateHandleByType = useCallback(function (type) {
|
|
95
|
+
var _colWidths;
|
|
96
|
+
if (!hoveredCell) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
var _getDragDropPluginSta = getDragDropPluginState(editorView.state),
|
|
100
|
+
isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen,
|
|
101
|
+
dragMenuIndex = _getDragDropPluginSta.dragMenuIndex,
|
|
102
|
+
dragMenuDirection = _getDragDropPluginSta.dragMenuDirection;
|
|
103
|
+
var isHover = type === 'hover';
|
|
104
|
+
var isHoveredOnSelectedColumn = isDragMenuOpen && dragMenuDirection === 'column' && dragMenuIndex === colIndex;
|
|
105
|
+
var showCondition = isHover ? !isHoveredOnSelectedColumn && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : isDragMenuOpen && dragMenuDirection === 'column';
|
|
106
|
+
if (!showCondition) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
var selectedColumnPosition = "".concat(dragMenuIndex + 1, " / span ").concat(selectedColIndexes.length);
|
|
110
|
+
var gridColumnPosition = selectedColIndexes.includes(colIndex) ? "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length) : "".concat(colIndex + 1, " / span 1");
|
|
111
|
+
var selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
112
|
+
var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
113
|
+
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
114
|
+
key: type,
|
|
115
|
+
style: {
|
|
116
|
+
gridColumn: isHover ? gridColumnPosition : selectedColumnPosition,
|
|
117
|
+
display: 'flex',
|
|
118
|
+
justifyContent: 'center',
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
height: 'fit-content',
|
|
121
|
+
placeSelf: 'center',
|
|
122
|
+
zIndex: 99
|
|
123
|
+
},
|
|
124
|
+
"data-column-control-index": hoveredCell.colIndex,
|
|
125
|
+
"data-testid": isHover ? 'table-floating-column-control' : 'table-floating-column-control-selected'
|
|
126
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
127
|
+
direction: "column",
|
|
128
|
+
tableLocalId: localId || '',
|
|
129
|
+
indexes: isHover ? colIndexes : selectedColIndexes,
|
|
130
|
+
forceDefaultHandle: !isHover,
|
|
131
|
+
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : 48,
|
|
132
|
+
previewHeight: previewHeight,
|
|
133
|
+
appearance: isHover ? hoveredAppearance : selectedApprearance,
|
|
134
|
+
onClick: handleClick,
|
|
135
|
+
onMouseOver: handleMouseOver,
|
|
136
|
+
onMouseOut: handleMouseOut,
|
|
137
|
+
onMouseUp: handleMouseUp,
|
|
138
|
+
editorView: editorView
|
|
139
|
+
}));
|
|
140
|
+
}, [colIndex, previewHeight, colWidths, colIndexes, editorView, handleClick, handleMouseOut, handleMouseOver, handleMouseUp, hoveredCell, isInDanger, localId, selectedColIndexes]);
|
|
141
|
+
var columnHandles = useCallback(function (hoveredCell) {
|
|
142
|
+
if (!hoveredCell) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
if (hoveredCell.colIndex === undefined) {
|
|
146
|
+
return generateHandleByType('selected');
|
|
147
|
+
}
|
|
148
|
+
var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
149
|
+
return hoveredCell.colIndex < selectedColIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
150
|
+
}, [generateHandleByType, selectedColIndexes]);
|
|
98
151
|
return /*#__PURE__*/React.createElement("div", {
|
|
99
152
|
className: ClassName.DRAG_COLUMN_CONTROLS,
|
|
100
153
|
onMouseMove: handleMouseMove
|
|
@@ -123,30 +176,6 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
123
176
|
right: '0'
|
|
124
177
|
} : {}
|
|
125
178
|
}));
|
|
126
|
-
}), tableActive && !isResizing &&
|
|
127
|
-
style: {
|
|
128
|
-
gridColumn: gridColumnPosition,
|
|
129
|
-
display: 'flex',
|
|
130
|
-
justifyContent: 'center',
|
|
131
|
-
alignItems: 'center',
|
|
132
|
-
height: 'fit-content',
|
|
133
|
-
placeSelf: 'center',
|
|
134
|
-
zIndex: 99
|
|
135
|
-
},
|
|
136
|
-
"data-column-control-index": hoveredCell.colIndex,
|
|
137
|
-
"data-testid": "table-floating-column-control"
|
|
138
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
139
|
-
direction: "column",
|
|
140
|
-
tableLocalId: localId || '',
|
|
141
|
-
indexes: colIndexes,
|
|
142
|
-
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : 48,
|
|
143
|
-
previewHeight: previewHeight,
|
|
144
|
-
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
145
|
-
onClick: handleClick,
|
|
146
|
-
onMouseOver: handleMouseOver,
|
|
147
|
-
onMouseOut: handleMouseOut,
|
|
148
|
-
onMouseUp: handleMouseUp,
|
|
149
|
-
editorView: editorView
|
|
150
|
-
}))));
|
|
179
|
+
}), tableActive && !isResizing && columnHandles(hoveredCell)));
|
|
151
180
|
};
|
|
152
181
|
export default ColumnControls;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
3
|
+
|
|
2
4
|
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
5
|
import { injectIntl } from 'react-intl-next';
|
|
4
6
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -6,6 +8,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
|
6
8
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
7
9
|
import { clearHoverSelection } from '../../../commands';
|
|
8
10
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
11
|
+
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
9
12
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
10
13
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
11
14
|
import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
|
|
@@ -76,13 +79,6 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
76
79
|
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
77
80
|
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
78
81
|
var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
|
|
79
|
-
var gridRowPosition = useMemo(function () {
|
|
80
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
81
|
-
if (selectedRowIndexes.includes(rowIndex)) {
|
|
82
|
-
return "".concat(selectedRowIndexes[0] + 1, " / span ").concat(selectedRowIndexes.length);
|
|
83
|
-
}
|
|
84
|
-
return "".concat(rowIndex + 1, " / span 1");
|
|
85
|
-
}, [rowIndex, selectedRowIndexes]);
|
|
86
82
|
var handleMouseOut = useCallback(function () {
|
|
87
83
|
if (tableActive) {
|
|
88
84
|
var state = editorView.state,
|
|
@@ -109,6 +105,62 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
109
105
|
var handleClick = useCallback(function (e) {
|
|
110
106
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
111
107
|
}, [rowIndex, selectRow]);
|
|
108
|
+
var generateHandleByType = useCallback(function (type) {
|
|
109
|
+
if (!hoveredCell) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
var _getDragDropPluginSta = getDragDropPluginState(editorView.state),
|
|
113
|
+
isDragMenuOpen = _getDragDropPluginSta.isDragMenuOpen,
|
|
114
|
+
dragMenuIndex = _getDragDropPluginSta.dragMenuIndex,
|
|
115
|
+
dragMenuDirection = _getDragDropPluginSta.dragMenuDirection;
|
|
116
|
+
var isHover = type === 'hover';
|
|
117
|
+
var isHoveredOnSelectedRow = isDragMenuOpen && dragMenuDirection === 'row' && dragMenuIndex === rowIndex;
|
|
118
|
+
var showCondition = isHover ? !isHoveredOnSelectedRow && !selectedRowIndexes.includes(rowIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : isDragMenuOpen && dragMenuDirection === 'row' && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
|
|
119
|
+
if (!showCondition) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
var gridRowPosition =
|
|
123
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
124
|
+
selectedRowIndexes.includes(rowIndex) ? "".concat(selectedRowIndexes[0] + 1, " / span ").concat(selectedRowIndexes.length) : "".concat(rowIndex + 1, " / span 1");
|
|
125
|
+
var selectedRowPosition = "".concat(dragMenuIndex + 1, " / span ").concat(selectedRowIndexes.length);
|
|
126
|
+
var selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
127
|
+
var hoveredAppearance = selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
128
|
+
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
key: type,
|
|
130
|
+
style: {
|
|
131
|
+
gridRow: isHover ? gridRowPosition : selectedRowPosition,
|
|
132
|
+
gridColumn: '2',
|
|
133
|
+
display: 'flex',
|
|
134
|
+
height: '100%',
|
|
135
|
+
alignItems: 'center',
|
|
136
|
+
justifyContent: 'center'
|
|
137
|
+
},
|
|
138
|
+
"data-testid": isHover ? 'table-floating-row-drag-handle' : 'table-floating-row-control-selected'
|
|
139
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
140
|
+
direction: "row",
|
|
141
|
+
tableLocalId: currentNodeLocalId,
|
|
142
|
+
indexes: isHover ? rowIndexes : selectedRowIndexes,
|
|
143
|
+
forceDefaultHandle: !isHover,
|
|
144
|
+
previewWidth: tableWidth,
|
|
145
|
+
previewHeight: rowHeights[rowIndex],
|
|
146
|
+
appearance: isHover ? hoveredAppearance : selectedApprearance,
|
|
147
|
+
onClick: handleClick,
|
|
148
|
+
onMouseOver: handleMouseOver,
|
|
149
|
+
onMouseOut: handleMouseOut,
|
|
150
|
+
onMouseUp: onMouseUp,
|
|
151
|
+
editorView: editorView
|
|
152
|
+
}));
|
|
153
|
+
}, [currentNodeLocalId, editorView, handleClick, handleMouseOut, handleMouseOver, hoveredCell, isInDanger, onMouseUp, rowHeights, rowIndex, rowIndexes, selectedRowIndexes, tableWidth]);
|
|
154
|
+
var rowHandles = useCallback(function (hoveredCell) {
|
|
155
|
+
if (!hoveredCell) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (hoveredCell.rowIndex === undefined) {
|
|
159
|
+
return generateHandleByType('selected');
|
|
160
|
+
}
|
|
161
|
+
var sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
162
|
+
return hoveredCell.rowIndex < selectedRowIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
163
|
+
}, [generateHandleByType, selectedRowIndexes]);
|
|
112
164
|
return /*#__PURE__*/React.createElement("div", {
|
|
113
165
|
className: ClassName.DRAG_ROW_CONTROLS,
|
|
114
166
|
style: {
|
|
@@ -148,27 +200,6 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
148
200
|
left: "var(--ds-space-negative-100, -8px)"
|
|
149
201
|
}
|
|
150
202
|
}));
|
|
151
|
-
}), !isResizing &&
|
|
152
|
-
style: {
|
|
153
|
-
gridRow: gridRowPosition,
|
|
154
|
-
gridColumn: '2',
|
|
155
|
-
display: 'flex',
|
|
156
|
-
height: '100%',
|
|
157
|
-
alignItems: 'center',
|
|
158
|
-
justifyContent: 'center'
|
|
159
|
-
},
|
|
160
|
-
"data-testid": "table-floating-row-drag-handle"
|
|
161
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
162
|
-
tableLocalId: currentNodeLocalId,
|
|
163
|
-
indexes: rowIndexes,
|
|
164
|
-
previewWidth: tableWidth,
|
|
165
|
-
previewHeight: rowHeights[rowIndex],
|
|
166
|
-
appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
167
|
-
onClick: handleClick,
|
|
168
|
-
onMouseOver: handleMouseOver,
|
|
169
|
-
onMouseOut: handleMouseOut,
|
|
170
|
-
onMouseUp: onMouseUp,
|
|
171
|
-
editorView: editorView
|
|
172
|
-
})));
|
|
203
|
+
}), !isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell));
|
|
173
204
|
};
|
|
174
205
|
export var DragControls = injectIntl(DragControlsComponent);
|
|
@@ -5,6 +5,7 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
|
5
5
|
type DragHandleProps = {
|
|
6
6
|
tableLocalId: string;
|
|
7
7
|
indexes: number[];
|
|
8
|
+
forceDefaultHandle?: boolean;
|
|
8
9
|
previewWidth?: number;
|
|
9
10
|
previewHeight?: number;
|
|
10
11
|
direction?: TableDirection;
|
|
@@ -15,5 +16,5 @@ type DragHandleProps = {
|
|
|
15
16
|
onMouseUp?: MouseEventHandler;
|
|
16
17
|
editorView: EditorView;
|
|
17
18
|
};
|
|
18
|
-
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
|
|
19
|
+
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, forceDefaultHandle, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
|
|
19
20
|
export {};
|
|
@@ -5,6 +5,7 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
|
5
5
|
type DragHandleProps = {
|
|
6
6
|
tableLocalId: string;
|
|
7
7
|
indexes: number[];
|
|
8
|
+
forceDefaultHandle?: boolean;
|
|
8
9
|
previewWidth?: number;
|
|
9
10
|
previewHeight?: number;
|
|
10
11
|
direction?: TableDirection;
|
|
@@ -15,5 +16,5 @@ type DragHandleProps = {
|
|
|
15
16
|
onMouseUp?: MouseEventHandler;
|
|
16
17
|
editorView: EditorView;
|
|
17
18
|
};
|
|
18
|
-
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
|
|
19
|
+
export declare const DragHandle: ({ tableLocalId, direction, appearance, indexes, forceDefaultHandle, previewWidth, previewHeight, onMouseOver, onMouseOut, onMouseUp, onClick, editorView, }: DragHandleProps) => JSX.Element;
|
|
19
20
|
export {};
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type HandleIconProps = {
|
|
10
10
|
hasMergedCells: boolean;
|
|
11
11
|
direction: 'row' | 'column';
|
|
12
|
+
forceDefaultHandle: boolean;
|
|
12
13
|
isDragMenuOpen: boolean | undefined;
|
|
13
14
|
isRowHandleHovered: boolean;
|
|
14
15
|
isColumnHandleHovered: boolean;
|
|
@@ -20,6 +21,7 @@ type HandleIconProps = {
|
|
|
20
21
|
export const HandleIconComponent = (props: HandleIconProps) => {
|
|
21
22
|
const {
|
|
22
23
|
direction,
|
|
24
|
+
forceDefaultHandle,
|
|
23
25
|
isDragMenuOpen,
|
|
24
26
|
isRowHandleHovered,
|
|
25
27
|
isColumnHandleHovered,
|
|
@@ -29,22 +31,21 @@ export const HandleIconComponent = (props: HandleIconProps) => {
|
|
|
29
31
|
dragMenuDirection,
|
|
30
32
|
} = props;
|
|
31
33
|
const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
34
|
+
|
|
32
35
|
const isCurrentRowOrColumnSelected =
|
|
33
36
|
isCurrentRowSelected || isCurrentColumnSelected;
|
|
37
|
+
|
|
34
38
|
const isDragMenuOpenOnCurrentRowOrColumn =
|
|
35
39
|
isDragMenuOpen &&
|
|
36
40
|
dragMenuDirection === direction &&
|
|
37
41
|
isCurrentRowOrColumnSelected;
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
// hoverred handle or open drag menu
|
|
46
|
-
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
47
|
-
return showNormalHandle;
|
|
43
|
+
if (
|
|
44
|
+
forceDefaultHandle ||
|
|
45
|
+
isHandleHovered ||
|
|
46
|
+
isDragMenuOpenOnCurrentRowOrColumn
|
|
47
|
+
) {
|
|
48
|
+
return hasMergedCells ? <DragHandleDisabledIcon /> : <DragHandleIcon />;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
return <MinimisedHandleIcon />;
|
|
@@ -22,6 +22,7 @@ type DragHandleAppearance = 'default' | 'selected' | 'disabled' | 'danger';
|
|
|
22
22
|
type DragHandleProps = {
|
|
23
23
|
tableLocalId: string;
|
|
24
24
|
indexes: number[];
|
|
25
|
+
forceDefaultHandle?: boolean;
|
|
25
26
|
previewWidth?: number;
|
|
26
27
|
previewHeight?: number;
|
|
27
28
|
direction?: TableDirection;
|
|
@@ -38,6 +39,7 @@ export const DragHandle = ({
|
|
|
38
39
|
direction = 'row',
|
|
39
40
|
appearance = 'default',
|
|
40
41
|
indexes,
|
|
42
|
+
forceDefaultHandle = false,
|
|
41
43
|
previewWidth,
|
|
42
44
|
previewHeight,
|
|
43
45
|
onMouseOver,
|
|
@@ -63,6 +65,7 @@ export const DragHandle = ({
|
|
|
63
65
|
isDragMenuOpen &&
|
|
64
66
|
direction === 'row' &&
|
|
65
67
|
hoveredCell.rowIndex === dragMenuIndex;
|
|
68
|
+
|
|
66
69
|
const isCurrentColumnSelected =
|
|
67
70
|
isDragMenuOpen &&
|
|
68
71
|
direction === 'column' &&
|
|
@@ -83,6 +86,7 @@ export const DragHandle = ({
|
|
|
83
86
|
const handleIconProps = {
|
|
84
87
|
hasMergedCells,
|
|
85
88
|
direction,
|
|
89
|
+
forceDefaultHandle,
|
|
86
90
|
isDragMenuOpen,
|
|
87
91
|
isRowHandleHovered,
|
|
88
92
|
isColumnHandleHovered,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
1
2
|
import type { MouseEvent } from 'react';
|
|
2
3
|
import React, { useCallback, useMemo } from 'react';
|
|
3
4
|
|
|
@@ -13,7 +14,8 @@ import {
|
|
|
13
14
|
selectColumn,
|
|
14
15
|
} from '../../../commands';
|
|
15
16
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
16
|
-
import
|
|
17
|
+
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
18
|
+
import type { CellHoverMeta, HandleTypes } from '../../../types';
|
|
17
19
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
18
20
|
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
19
21
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -66,14 +68,6 @@ export const ColumnControls = ({
|
|
|
66
68
|
const colIndex = hoveredCell?.colIndex;
|
|
67
69
|
const selectedColIndexes = getSelectedColumns(editorView.state.selection);
|
|
68
70
|
|
|
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
|
-
|
|
77
71
|
const firstRow = tableRef.querySelector('tr');
|
|
78
72
|
const hasHeaderRow = firstRow
|
|
79
73
|
? firstRow.getAttribute('data-header-row')
|
|
@@ -140,6 +134,120 @@ export const ColumnControls = ({
|
|
|
140
134
|
|
|
141
135
|
const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
|
|
142
136
|
|
|
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
|
+
|
|
143
251
|
return (
|
|
144
252
|
<div
|
|
145
253
|
className={ClassName.DRAG_COLUMN_CONTROLS}
|
|
@@ -181,45 +289,7 @@ export const ColumnControls = ({
|
|
|
181
289
|
/>
|
|
182
290
|
</div>
|
|
183
291
|
))}
|
|
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
|
-
)}
|
|
292
|
+
{tableActive && !isResizing && columnHandles(hoveredCell)}
|
|
223
293
|
</div>
|
|
224
294
|
</div>
|
|
225
295
|
);
|