@atlaskit/editor-plugin-table 5.4.15 → 5.4.17
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/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 +3 -5
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- 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/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 +3 -5
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- 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/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 +3 -5
- package/dist/esm/plugins/table/ui/DragHandle/index.js +3 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +2 -2
- 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 +2 -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 +2 -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/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 +3 -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/FloatingDragMenu/DragMenu.tsx +3 -2
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +118 -48
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +126 -41
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
|
|
1
3
|
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
4
|
import { injectIntl } from 'react-intl-next';
|
|
3
5
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
@@ -5,6 +7,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
|
5
7
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
8
|
import { clearHoverSelection } from '../../../commands';
|
|
7
9
|
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
10
|
+
import { getPluginState as getDragDropPluginState } from '../../../pm-plugins/drag-and-drop/plugin-factory';
|
|
8
11
|
import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
|
|
9
12
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
10
13
|
import { getRowHeights, getRowsParams, getSelectedRowIndexes } from '../../../utils';
|
|
@@ -74,13 +77,6 @@ const DragControlsComponent = ({
|
|
|
74
77
|
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
75
78
|
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
76
79
|
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]);
|
|
84
80
|
const handleMouseOut = useCallback(() => {
|
|
85
81
|
if (tableActive) {
|
|
86
82
|
const {
|
|
@@ -109,6 +105,63 @@ const DragControlsComponent = ({
|
|
|
109
105
|
const handleClick = useCallback(e => {
|
|
110
106
|
selectRow(rowIndex, e === null || e === void 0 ? void 0 : e.shiftKey);
|
|
111
107
|
}, [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]);
|
|
112
165
|
return /*#__PURE__*/React.createElement("div", {
|
|
113
166
|
className: ClassName.DRAG_ROW_CONTROLS,
|
|
114
167
|
style: {
|
|
@@ -147,27 +200,6 @@ const DragControlsComponent = ({
|
|
|
147
200
|
position: 'relative',
|
|
148
201
|
left: "var(--ds-space-negative-100, -8px)"
|
|
149
202
|
}
|
|
150
|
-
}))), !isResizing &&
|
|
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
|
-
})));
|
|
203
|
+
}))), !isResizing && Number.isFinite(rowIndex) && rowHandles(hoveredCell));
|
|
172
204
|
};
|
|
173
205
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -99,7 +99,8 @@ export var hoverTable = function hoverTable(isInDanger, isSelected) {
|
|
|
99
99
|
decorationSet: updatePluginStateDecorations(state, decorations, TableDecorations.TABLE_CONTROLS_HOVER),
|
|
100
100
|
hoveredColumns: hoveredColumns,
|
|
101
101
|
hoveredRows: hoveredRows,
|
|
102
|
-
isInDanger: isInDanger
|
|
102
|
+
isInDanger: isInDanger,
|
|
103
|
+
isWholeTableInDanger: isInDanger
|
|
103
104
|
}
|
|
104
105
|
};
|
|
105
106
|
}, function (tr) {
|
|
@@ -112,7 +113,8 @@ export var clearHoverSelection = function clearHoverSelection() {
|
|
|
112
113
|
type: 'CLEAR_HOVER_SELECTION',
|
|
113
114
|
data: {
|
|
114
115
|
decorationSet: updatePluginStateDecorations(state, [], TableDecorations.ALL_CONTROLS_HOVER),
|
|
115
|
-
isInDanger: false
|
|
116
|
+
isInDanger: false,
|
|
117
|
+
isWholeTableInDanger: false
|
|
116
118
|
}
|
|
117
119
|
};
|
|
118
120
|
});
|
|
@@ -279,7 +279,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
279
279
|
_this.containerWidth = _containerWidth;
|
|
280
280
|
_this.isInitialOverflowSent = false;
|
|
281
281
|
|
|
282
|
-
// store table size using previous full-width mode so can detect if it has changed
|
|
282
|
+
// store table size using previous full-width mode so can detect if it has changed.
|
|
283
283
|
var isFullWidthModeEnabled = _options ? _options.wasFullWidthModeEnabled : false;
|
|
284
284
|
_this.layoutSize = _this.tableNodeLayoutSize(_this.node, _containerWidth.width, {
|
|
285
285
|
isFullWidthModeEnabled: isFullWidthModeEnabled
|
|
@@ -95,7 +95,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
95
95
|
var resizerMinWidth = getResizerMinWidth(node);
|
|
96
96
|
var handleSize = getResizerHandleHeight(tableRef);
|
|
97
97
|
var _getPluginState = getPluginState(editorView.state),
|
|
98
|
-
|
|
98
|
+
isWholeTableInDanger = _getPluginState.isWholeTableInDanger;
|
|
99
99
|
var _useMeasureFramerate = useMeasureFramerate(),
|
|
100
100
|
startMeasure = _useMeasureFramerate.startMeasure,
|
|
101
101
|
endMeasure = _useMeasureFramerate.endMeasure,
|
|
@@ -242,7 +242,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
242
242
|
snap: guidelineSnaps,
|
|
243
243
|
handlePositioning: "adjacent",
|
|
244
244
|
isHandleVisible: isTableSelected,
|
|
245
|
-
appearance:
|
|
245
|
+
appearance: isTableSelected && isWholeTableInDanger ? 'danger' : undefined,
|
|
246
246
|
handleHighlight: "shadow",
|
|
247
247
|
handleTooltipContent: formatMessage(messages.resizeTable)
|
|
248
248
|
}, children);
|
|
@@ -2,6 +2,7 @@ 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,
|
|
5
6
|
isDragMenuOpen = props.isDragMenuOpen,
|
|
6
7
|
isRowHandleHovered = props.isRowHandleHovered,
|
|
7
8
|
isColumnHandleHovered = props.isColumnHandleHovered,
|
|
@@ -12,11 +13,8 @@ export var HandleIconComponent = function HandleIconComponent(props) {
|
|
|
12
13
|
var isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
13
14
|
var isCurrentRowOrColumnSelected = isCurrentRowSelected || isCurrentColumnSelected;
|
|
14
15
|
var isDragMenuOpenOnCurrentRowOrColumn = isDragMenuOpen && dragMenuDirection === direction && isCurrentRowOrColumnSelected;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// hoverred handle or open drag menu
|
|
18
|
-
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
19
|
-
return showNormalHandle;
|
|
16
|
+
if (forceDefaultHandle || isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
17
|
+
return hasMergedCells ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
20
18
|
}
|
|
21
19
|
return /*#__PURE__*/React.createElement(MinimisedHandleIcon, null);
|
|
22
20
|
};
|
|
@@ -18,6 +18,8 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
18
18
|
_ref$appearance = _ref.appearance,
|
|
19
19
|
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
20
20
|
indexes = _ref.indexes,
|
|
21
|
+
_ref$forceDefaultHand = _ref.forceDefaultHandle,
|
|
22
|
+
forceDefaultHandle = _ref$forceDefaultHand === void 0 ? false : _ref$forceDefaultHand,
|
|
21
23
|
previewWidth = _ref.previewWidth,
|
|
22
24
|
previewHeight = _ref.previewHeight,
|
|
23
25
|
onMouseOver = _ref.onMouseOver,
|
|
@@ -49,6 +51,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
49
51
|
var handleIconProps = {
|
|
50
52
|
hasMergedCells: hasMergedCells,
|
|
51
53
|
direction: direction,
|
|
54
|
+
forceDefaultHandle: forceDefaultHandle,
|
|
52
55
|
isDragMenuOpen: isDragMenuOpen,
|
|
53
56
|
isRowHandleHovered: isRowHandleHovered,
|
|
54
57
|
isColumnHandleHovered: isColumnHandleHovered,
|
|
@@ -74,8 +74,8 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
74
74
|
var selection = state.selection;
|
|
75
75
|
var selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
76
76
|
var hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
77
|
-
var
|
|
78
|
-
var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth,
|
|
77
|
+
var shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
78
|
+
var dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
|
|
79
79
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
80
80
|
menuItems = _convertToDropdownIte.menuItems,
|
|
81
81
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
@@ -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);
|
|
@@ -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,3 +421,4 @@ export interface DraggableData {
|
|
|
420
421
|
targetClosestEdge: Edge;
|
|
421
422
|
direction: 1 | -1;
|
|
422
423
|
}
|
|
424
|
+
export type HandleTypes = 'hover' | 'selected';
|
|
@@ -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 {};
|
|
@@ -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,3 +421,4 @@ export interface DraggableData {
|
|
|
420
421
|
targetClosestEdge: Edge;
|
|
421
422
|
direction: 1 | -1;
|
|
422
423
|
}
|
|
424
|
+
export type HandleTypes = 'hover' | 'selected';
|
|
@@ -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
|
@@ -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,3 +463,5 @@ export interface DraggableData {
|
|
|
462
463
|
targetClosestEdge: Edge;
|
|
463
464
|
direction: 1 | -1;
|
|
464
465
|
}
|
|
466
|
+
|
|
467
|
+
export type HandleTypes = 'hover' | 'selected';
|