@atlaskit/editor-plugin-table 5.4.17 → 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 +7 -0
- 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/TableFloatingColumnControls/ColumnControls/index.js +33 -62
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +31 -62
- 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/TableFloatingColumnControls/ColumnControls/index.js +33 -63
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +29 -61
- 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/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 +0 -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 +0 -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/types.ts +0 -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/TableFloatingColumnControls/ColumnControls/index.tsx +48 -118
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +41 -126
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
-
|
|
3
1
|
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
2
|
import { injectIntl } from 'react-intl-next';
|
|
5
3
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -7,7 +5,6 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
|
7
5
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
8
6
|
import { clearHoverSelection } from '../../../commands';
|
|
9
7
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
10
|
-
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
11
8
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
12
9
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
13
10
|
import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
|
|
@@ -77,6 +74,13 @@ const DragControlsComponent = ({
|
|
|
77
74
|
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
78
75
|
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
79
76
|
const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
|
|
77
|
+
const gridRowPosition = useMemo(() => {
|
|
78
|
+
// if more than one row is selected, ensure the handle spans over the selected range
|
|
79
|
+
if (selectedRowIndexes.includes(rowIndex)) {
|
|
80
|
+
return `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}`;
|
|
81
|
+
}
|
|
82
|
+
return `${rowIndex + 1} / span 1`;
|
|
83
|
+
}, [rowIndex, selectedRowIndexes]);
|
|
80
84
|
const handleMouseOut = useCallback(() => {
|
|
81
85
|
if (tableActive) {
|
|
82
86
|
const {
|
|
@@ -105,63 +109,6 @@ const DragControlsComponent = ({
|
|
|
105
109
|
const handleClick = useCallback(e => {
|
|
106
110
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
107
111
|
}, [rowIndex, selectRow]);
|
|
108
|
-
const generateHandleByType = useCallback(type => {
|
|
109
|
-
if (!hoveredCell) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
const {
|
|
113
|
-
isDragMenuOpen,
|
|
114
|
-
dragMenuIndex,
|
|
115
|
-
dragMenuDirection
|
|
116
|
-
} = getDragDropPluginState(editorView.state);
|
|
117
|
-
const isHover = type === 'hover';
|
|
118
|
-
const isHoveredOnSelectedRow = isDragMenuOpen && dragMenuDirection === 'row' && dragMenuIndex === rowIndex;
|
|
119
|
-
const 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);
|
|
120
|
-
if (!showCondition) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
const gridRowPosition =
|
|
124
|
-
// if more than one row is selected, ensure the handle spans over the selected range
|
|
125
|
-
selectedRowIndexes.includes(rowIndex) ? `${selectedRowIndexes[0] + 1} / span ${selectedRowIndexes.length}` : `${rowIndex + 1} / span 1`;
|
|
126
|
-
const selectedRowPosition = `${dragMenuIndex + 1} / span ${selectedRowIndexes.length}`;
|
|
127
|
-
const selectedApprearance = isInDanger ? 'danger' : 'selected';
|
|
128
|
-
const hoveredAppearance = selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
|
|
129
|
-
return showCondition && /*#__PURE__*/React.createElement("div", {
|
|
130
|
-
key: type,
|
|
131
|
-
style: {
|
|
132
|
-
gridRow: isHover ? gridRowPosition : selectedRowPosition,
|
|
133
|
-
gridColumn: '2',
|
|
134
|
-
display: 'flex',
|
|
135
|
-
height: '100%',
|
|
136
|
-
alignItems: 'center',
|
|
137
|
-
justifyContent: 'center'
|
|
138
|
-
},
|
|
139
|
-
"data-testid": isHover ? 'table-floating-row-drag-handle' : 'table-floating-row-control-selected'
|
|
140
|
-
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
141
|
-
direction: "row",
|
|
142
|
-
tableLocalId: currentNodeLocalId,
|
|
143
|
-
indexes: isHover ? rowIndexes : selectedRowIndexes,
|
|
144
|
-
forceDefaultHandle: !isHover,
|
|
145
|
-
previewWidth: tableWidth,
|
|
146
|
-
previewHeight: rowHeights[rowIndex],
|
|
147
|
-
appearance: isHover ? hoveredAppearance : selectedApprearance,
|
|
148
|
-
onClick: handleClick,
|
|
149
|
-
onMouseOver: handleMouseOver,
|
|
150
|
-
onMouseOut: handleMouseOut,
|
|
151
|
-
onMouseUp: onMouseUp,
|
|
152
|
-
editorView: editorView
|
|
153
|
-
}));
|
|
154
|
-
}, [currentNodeLocalId, editorView, handleClick, handleMouseOut, handleMouseOver, hoveredCell, isInDanger, onMouseUp, rowHeights, rowIndex, rowIndexes, selectedRowIndexes, tableWidth]);
|
|
155
|
-
const rowHandles = useCallback(hoveredCell => {
|
|
156
|
-
if (!hoveredCell) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
if (hoveredCell.rowIndex === undefined) {
|
|
160
|
-
return generateHandleByType('selected');
|
|
161
|
-
}
|
|
162
|
-
const sortedHandles = [generateHandleByType('hover'), generateHandleByType('selected')];
|
|
163
|
-
return hoveredCell.rowIndex < selectedRowIndexes[0] ? sortedHandles : sortedHandles.reverse();
|
|
164
|
-
}, [generateHandleByType, selectedRowIndexes]);
|
|
165
112
|
return /*#__PURE__*/React.createElement("div", {
|
|
166
113
|
className: ClassName.DRAG_ROW_CONTROLS,
|
|
167
114
|
style: {
|
|
@@ -200,6 +147,27 @@ const DragControlsComponent = ({
|
|
|
200
147
|
position: 'relative',
|
|
201
148
|
left: "var(--ds-space-negative-100, -8px)"
|
|
202
149
|
}
|
|
203
|
-
}))), !isResizing && Number.isFinite(rowIndex) &&
|
|
150
|
+
}))), !isResizing && isTableHovered && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
style: {
|
|
152
|
+
gridRow: gridRowPosition,
|
|
153
|
+
gridColumn: '2',
|
|
154
|
+
display: 'flex',
|
|
155
|
+
height: '100%',
|
|
156
|
+
alignItems: 'center',
|
|
157
|
+
justifyContent: 'center'
|
|
158
|
+
},
|
|
159
|
+
"data-testid": "table-floating-row-drag-handle"
|
|
160
|
+
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
161
|
+
tableLocalId: currentNodeLocalId,
|
|
162
|
+
indexes: rowIndexes,
|
|
163
|
+
previewWidth: tableWidth,
|
|
164
|
+
previewHeight: rowHeights[rowIndex],
|
|
165
|
+
appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
166
|
+
onClick: handleClick,
|
|
167
|
+
onMouseOver: handleMouseOver,
|
|
168
|
+
onMouseOut: handleMouseOut,
|
|
169
|
+
onMouseUp: onMouseUp,
|
|
170
|
+
editorView: editorView
|
|
171
|
+
})));
|
|
204
172
|
};
|
|
205
173
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
|
|
3
3
|
export var HandleIconComponent = function HandleIconComponent(props) {
|
|
4
4
|
var direction = props.direction,
|
|
5
|
-
forceDefaultHandle = props.forceDefaultHandle,
|
|
6
5
|
isDragMenuOpen = props.isDragMenuOpen,
|
|
7
6
|
isRowHandleHovered = props.isRowHandleHovered,
|
|
8
7
|
isColumnHandleHovered = props.isColumnHandleHovered,
|
|
@@ -13,8 +12,11 @@ export var HandleIconComponent = function HandleIconComponent(props) {
|
|
|
13
12
|
var isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
14
13
|
var isCurrentRowOrColumnSelected = isCurrentRowSelected || isCurrentColumnSelected;
|
|
15
14
|
var isDragMenuOpenOnCurrentRowOrColumn = isDragMenuOpen && dragMenuDirection === direction && isCurrentRowOrColumnSelected;
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
var showNormalHandle = hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
16
|
+
|
|
17
|
+
// hoverred handle or open drag menu
|
|
18
|
+
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
19
|
+
return showNormalHandle;
|
|
18
20
|
}
|
|
19
21
|
return /*#__PURE__*/React.createElement(MinimisedHandleIcon, null);
|
|
20
22
|
};
|
|
@@ -3,6 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
import ReactDOM from 'react-dom';
|
|
6
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
6
7
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
7
8
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
|
|
8
9
|
import { getPluginState as getDragDropPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
@@ -18,8 +19,6 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
18
19
|
_ref$appearance = _ref.appearance,
|
|
19
20
|
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
20
21
|
indexes = _ref.indexes,
|
|
21
|
-
_ref$forceDefaultHand = _ref.forceDefaultHandle,
|
|
22
|
-
forceDefaultHandle = _ref$forceDefaultHand === void 0 ? false : _ref$forceDefaultHand,
|
|
23
22
|
previewWidth = _ref.previewWidth,
|
|
24
23
|
previewHeight = _ref.previewHeight,
|
|
25
24
|
onMouseOver = _ref.onMouseOver,
|
|
@@ -51,7 +50,6 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
51
50
|
var handleIconProps = {
|
|
52
51
|
hasMergedCells: hasMergedCells,
|
|
53
52
|
direction: direction,
|
|
54
|
-
forceDefaultHandle: forceDefaultHandle,
|
|
55
53
|
isDragMenuOpen: isDragMenuOpen,
|
|
56
54
|
isRowHandleHovered: isRowHandleHovered,
|
|
57
55
|
isColumnHandleHovered: isColumnHandleHovered,
|
|
@@ -121,7 +119,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
121
119
|
_onMouseUp && _onMouseUp(e);
|
|
122
120
|
},
|
|
123
121
|
onClick: onClick
|
|
124
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
122
|
+
}, browser.gecko ? /*#__PURE__*/React.createElement(HandleIconComponent, handleIconProps) : /*#__PURE__*/React.createElement("span", {
|
|
125
123
|
style: {
|
|
126
124
|
pointerEvents: 'none'
|
|
127
125
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
-
|
|
3
1
|
import React, { useCallback, useMemo } from 'react';
|
|
4
2
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
5
3
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
6
4
|
import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
|
|
7
5
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
8
|
-
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
9
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
10
7
|
import { getRowsParams, getSelectedColumnIndexes } from '../../../utils';
|
|
11
8
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -20,7 +17,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
|
|
|
20
17
|
return [];
|
|
21
18
|
};
|
|
22
19
|
export var ColumnControls = function ColumnControls(_ref) {
|
|
23
|
-
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
|
|
20
|
+
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce, _colWidths;
|
|
24
21
|
var editorView = _ref.editorView,
|
|
25
22
|
tableActive = _ref.tableActive,
|
|
26
23
|
tableRef = _ref.tableRef,
|
|
@@ -40,6 +37,13 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
40
37
|
var columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
|
|
41
38
|
var colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
|
|
42
39
|
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]);
|
|
43
47
|
var firstRow = tableRef.querySelector('tr');
|
|
44
48
|
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
45
49
|
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
@@ -91,63 +95,6 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
91
95
|
var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
|
|
92
96
|
return sum + cur;
|
|
93
97
|
}, 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]);
|
|
151
98
|
return /*#__PURE__*/React.createElement("div", {
|
|
152
99
|
className: ClassName.DRAG_COLUMN_CONTROLS,
|
|
153
100
|
onMouseMove: handleMouseMove
|
|
@@ -176,6 +123,30 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
176
123
|
right: '0'
|
|
177
124
|
} : {}
|
|
178
125
|
}));
|
|
179
|
-
}), tableActive && !isResizing &&
|
|
126
|
+
}), tableActive && !isResizing && isTableHovered && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
|
|
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
|
+
}))));
|
|
180
151
|
};
|
|
181
152
|
export default ColumnControls;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
3
|
-
|
|
4
2
|
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
3
|
import { injectIntl } from 'react-intl-next';
|
|
6
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -8,7 +6,6 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
|
8
6
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
9
7
|
import { clearHoverSelection } from '../../../commands';
|
|
10
8
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
11
|
-
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
12
9
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
13
10
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
14
11
|
import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
|
|
@@ -79,6 +76,13 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
79
76
|
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
80
77
|
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
81
78
|
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]);
|
|
82
86
|
var handleMouseOut = useCallback(function () {
|
|
83
87
|
if (tableActive) {
|
|
84
88
|
var state = editorView.state,
|
|
@@ -105,62 +109,6 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
105
109
|
var handleClick = useCallback(function (e) {
|
|
106
110
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
107
111
|
}, [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]);
|
|
164
112
|
return /*#__PURE__*/React.createElement("div", {
|
|
165
113
|
className: ClassName.DRAG_ROW_CONTROLS,
|
|
166
114
|
style: {
|
|
@@ -200,6 +148,27 @@ var DragControlsComponent = function DragControlsComponent(_ref) {
|
|
|
200
148
|
left: "var(--ds-space-negative-100, -8px)"
|
|
201
149
|
}
|
|
202
150
|
}));
|
|
203
|
-
}), !isResizing && Number.isFinite(rowIndex) &&
|
|
151
|
+
}), !isResizing && isTableHovered && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
|
|
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
|
+
})));
|
|
204
173
|
};
|
|
205
174
|
export var DragControls = injectIntl(DragControlsComponent);
|
|
@@ -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 {};
|
|
@@ -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
|
@@ -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 &&
|