@atlaskit/editor-plugin-table 5.4.19 → 5.4.20
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/index.js +1 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -2
- package/dist/cjs/plugins/table/nodeviews/table.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/consts.js +3 -2
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +38 -14
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/cjs/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -2
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +7 -4
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +4 -2
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +7 -4
- package/dist/cjs/plugins/table/utils/drag-menu.js +10 -6
- package/dist/es2019/plugins/table/index.js +1 -0
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -2
- package/dist/es2019/plugins/table/nodeviews/table.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/consts.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +39 -15
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +5 -0
- package/dist/es2019/plugins/table/ui/DragHandle/HandleIconComponent.js +3 -1
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +6 -4
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +4 -2
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +7 -4
- package/dist/es2019/plugins/table/utils/drag-menu.js +6 -6
- package/dist/esm/plugins/table/index.js +1 -0
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -2
- package/dist/esm/plugins/table/nodeviews/table.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/consts.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +39 -15
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/esm/plugins/table/ui/DragHandle/HandleIconComponent.js +4 -2
- package/dist/esm/plugins/table/ui/DragHandle/index.js +7 -4
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +3 -2
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +4 -2
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -3
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +4 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +5 -3
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +7 -4
- package/dist/esm/plugins/table/utils/drag-menu.js +10 -6
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +4 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/consts.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/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/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
- package/dist/types/plugins/table/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/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/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/pm-plugins/drag-and-drop/plugin.ts +112 -0
- package/src/plugins/table/index.tsx +1 -0
- package/src/plugins/table/nodeviews/TableComponent.tsx +4 -0
- package/src/plugins/table/nodeviews/table.tsx +4 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +9 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/consts.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +49 -17
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +5 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +1 -0
- package/src/plugins/table/ui/DragHandle/HandleIconComponent.tsx +5 -1
- package/src/plugins/table/ui/DragHandle/index.tsx +6 -2
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +3 -1
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +3 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +5 -1
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +3 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +5 -2
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +6 -1
- package/src/plugins/table/utils/drag-menu.ts +6 -6
|
@@ -9,7 +9,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
|
9
9
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
10
10
|
import { DragAndDropActionType } from './actions';
|
|
11
11
|
import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
|
|
12
|
-
import { DropTargetType } from './consts';
|
|
12
|
+
import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
|
|
13
13
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
14
14
|
import { pluginKey } from './plugin-key';
|
|
15
15
|
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
@@ -21,20 +21,26 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
21
21
|
dropTargetIndex: 0,
|
|
22
22
|
isDragMenuOpen: false,
|
|
23
23
|
dragMenuIndex: 0,
|
|
24
|
-
isDragging: false
|
|
24
|
+
isDragging: false,
|
|
25
|
+
canDrag: false
|
|
25
26
|
})),
|
|
26
27
|
key: pluginKey,
|
|
27
28
|
appendTransaction: (transactions, oldState, newState) => {
|
|
28
29
|
const {
|
|
29
|
-
targetCellPosition: oldTargetCellPosition
|
|
30
|
+
targetCellPosition: oldTargetCellPosition,
|
|
31
|
+
tableNode: oldTableNode
|
|
30
32
|
} = getTablePluginState(oldState);
|
|
31
33
|
const {
|
|
32
|
-
targetCellPosition: newTargetCellPosition
|
|
34
|
+
targetCellPosition: newTargetCellPosition,
|
|
35
|
+
tableNode: newTableNode
|
|
33
36
|
} = getTablePluginState(newState);
|
|
34
37
|
const {
|
|
35
38
|
isDragMenuOpen,
|
|
36
|
-
dragMenuIndex
|
|
39
|
+
dragMenuIndex,
|
|
40
|
+
canDrag
|
|
37
41
|
} = getPluginState(newState);
|
|
42
|
+
const stateChanges = [];
|
|
43
|
+
const tr = newState.tr;
|
|
38
44
|
|
|
39
45
|
// What's happening here? you asked... In a nutshell;
|
|
40
46
|
// If the target cell position changes while the drag menu is open then we want to close the drag menu if it has been opened.
|
|
@@ -42,14 +48,6 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
42
48
|
// to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
|
|
43
49
|
if (oldTargetCellPosition !== newTargetCellPosition) {
|
|
44
50
|
if (isDragMenuOpen) {
|
|
45
|
-
const tr = newState.tr;
|
|
46
|
-
const action = {
|
|
47
|
-
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
48
|
-
data: {
|
|
49
|
-
isDragMenuOpen: false,
|
|
50
|
-
direction: undefined
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
51
|
if (newTargetCellPosition !== undefined) {
|
|
54
52
|
const cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
55
53
|
// ED-20673 check if it is a cell selection,
|
|
@@ -57,13 +55,39 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
57
55
|
// should not close the drag menu.
|
|
58
56
|
const isCellSelection = tr.selection instanceof CellSelection;
|
|
59
57
|
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
|
|
60
|
-
|
|
58
|
+
stateChanges.push({
|
|
59
|
+
isDragMenuOpen: false,
|
|
60
|
+
dragMenuDirection: undefined
|
|
61
|
+
});
|
|
61
62
|
} // else NOP
|
|
62
63
|
} else {
|
|
63
|
-
|
|
64
|
+
stateChanges.push({
|
|
65
|
+
isDragMenuOpen: false,
|
|
66
|
+
dragMenuDirection: undefined
|
|
67
|
+
});
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
71
|
+
if ((oldTableNode === null || oldTableNode === void 0 ? void 0 : oldTableNode.nodeSize) !== (newTableNode === null || newTableNode === void 0 ? void 0 : newTableNode.nodeSize)) {
|
|
72
|
+
var _newTableNode$nodeSiz;
|
|
73
|
+
const nextCanDrag = ((_newTableNode$nodeSiz = newTableNode === null || newTableNode === void 0 ? void 0 : newTableNode.nodeSize) !== null && _newTableNode$nodeSiz !== void 0 ? _newTableNode$nodeSiz : 0) < DRAGGABLE_TABLE_NODE_SIZE_LIMIT;
|
|
74
|
+
if (canDrag !== nextCanDrag) {
|
|
75
|
+
stateChanges.push({
|
|
76
|
+
canDrag: nextCanDrag
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (stateChanges.length) {
|
|
81
|
+
return tr.setMeta(pluginKey, {
|
|
82
|
+
type: DragAndDropActionType.UPDATE,
|
|
83
|
+
data: {
|
|
84
|
+
...stateChanges.reduce((state, cur) => ({
|
|
85
|
+
...state,
|
|
86
|
+
...cur
|
|
87
|
+
}), {})
|
|
88
|
+
}
|
|
89
|
+
}).setMeta('addToHistory', false);
|
|
90
|
+
}
|
|
67
91
|
},
|
|
68
92
|
view: editorView => {
|
|
69
93
|
return {
|
|
@@ -25,6 +25,11 @@ export default ((pluginState, action) => {
|
|
|
25
25
|
dragMenuDirection: action.data.direction,
|
|
26
26
|
dragMenuIndex: action.data.index
|
|
27
27
|
};
|
|
28
|
+
case DragAndDropActionType.UPDATE:
|
|
29
|
+
return {
|
|
30
|
+
...pluginState,
|
|
31
|
+
...action.data
|
|
32
|
+
};
|
|
28
33
|
default:
|
|
29
34
|
return pluginState;
|
|
30
35
|
}
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
|
|
3
3
|
export const HandleIconComponent = props => {
|
|
4
4
|
const {
|
|
5
|
+
canDrag,
|
|
5
6
|
direction,
|
|
6
7
|
isDragMenuOpen,
|
|
7
8
|
isRowHandleHovered,
|
|
@@ -14,7 +15,8 @@ export const HandleIconComponent = props => {
|
|
|
14
15
|
const isHandleHovered = isRowHandleHovered || isColumnHandleHovered;
|
|
15
16
|
const isCurrentRowOrColumnSelected = isCurrentRowSelected || isCurrentColumnSelected;
|
|
16
17
|
const isDragMenuOpenOnCurrentRowOrColumn = isDragMenuOpen && dragMenuDirection === direction && isCurrentRowOrColumnSelected;
|
|
17
|
-
const
|
|
18
|
+
const isDragPossible = canDrag && !hasMergedCells;
|
|
19
|
+
const showNormalHandle = !isDragPossible ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
18
20
|
|
|
19
21
|
// hoverred handle or open drag menu
|
|
20
22
|
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
@@ -21,7 +21,8 @@ export const DragHandle = ({
|
|
|
21
21
|
onMouseOut,
|
|
22
22
|
onMouseUp,
|
|
23
23
|
onClick,
|
|
24
|
-
editorView
|
|
24
|
+
editorView,
|
|
25
|
+
canDrag = false
|
|
25
26
|
}) => {
|
|
26
27
|
const dragHandleDivRef = useRef(null);
|
|
27
28
|
const [previewContainer, setPreviewContainer] = useState(null);
|
|
@@ -44,6 +45,7 @@ export const DragHandle = ({
|
|
|
44
45
|
const isColumnHandleHovered = direction === 'column' && hoveredColumns.length > 0;
|
|
45
46
|
const hasMergedCells = useMemo(() => direction === 'row' ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection), [indexes, direction, selection]);
|
|
46
47
|
const handleIconProps = {
|
|
48
|
+
canDrag,
|
|
47
49
|
hasMergedCells,
|
|
48
50
|
direction,
|
|
49
51
|
isDragMenuOpen,
|
|
@@ -59,7 +61,7 @@ export const DragHandle = ({
|
|
|
59
61
|
return draggable({
|
|
60
62
|
element: dragHandleDivRefCurrent,
|
|
61
63
|
canDrag: () => {
|
|
62
|
-
return !hasMergedCells;
|
|
64
|
+
return canDrag && !hasMergedCells;
|
|
63
65
|
},
|
|
64
66
|
getInitialData() {
|
|
65
67
|
return {
|
|
@@ -108,10 +110,10 @@ export const DragHandle = ({
|
|
|
108
110
|
}
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
|
-
}, [tableLocalId, direction, indexes, editorView.state.selection, hasMergedCells]);
|
|
113
|
+
}, [tableLocalId, direction, indexes, editorView.state.selection, hasMergedCells, canDrag]);
|
|
112
114
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
113
115
|
className: classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance, {
|
|
114
|
-
[ClassName.DRAG_HANDLE_DISABLED]: hasMergedCells
|
|
116
|
+
[ClassName.DRAG_HANDLE_DISABLED]: !canDrag || hasMergedCells
|
|
115
117
|
}),
|
|
116
118
|
ref: dragHandleDivRef,
|
|
117
119
|
style: {
|
|
@@ -61,7 +61,8 @@ export const DragMenu = ({
|
|
|
61
61
|
boundariesElement,
|
|
62
62
|
scrollableElement,
|
|
63
63
|
targetCellPosition,
|
|
64
|
-
getEditorContainerWidth
|
|
64
|
+
getEditorContainerWidth,
|
|
65
|
+
canDrag
|
|
65
66
|
}) => {
|
|
66
67
|
const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
67
68
|
const {
|
|
@@ -74,7 +75,7 @@ export const DragMenu = ({
|
|
|
74
75
|
const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
75
76
|
const hasMergedCells = direction === 'row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
76
77
|
const shouldMoveDisabled = index !== undefined && hasMergedCells(index)(selection);
|
|
77
|
-
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
|
|
78
|
+
const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, !!canDrag && !shouldMoveDisabled, tableMap, index, targetCellPosition, selectionRect);
|
|
78
79
|
const {
|
|
79
80
|
menuItems,
|
|
80
81
|
menuCallback
|
|
@@ -16,7 +16,8 @@ const FloatingDragMenu = ({
|
|
|
16
16
|
direction,
|
|
17
17
|
index,
|
|
18
18
|
targetCellPosition,
|
|
19
|
-
getEditorContainerWidth
|
|
19
|
+
getEditorContainerWidth,
|
|
20
|
+
canDrag
|
|
20
21
|
}) => {
|
|
21
22
|
if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
22
23
|
return null;
|
|
@@ -52,7 +53,8 @@ const FloatingDragMenu = ({
|
|
|
52
53
|
direction: direction,
|
|
53
54
|
index: index,
|
|
54
55
|
targetCellPosition: targetCellPosition,
|
|
55
|
-
getEditorContainerWidth: getEditorContainerWidth
|
|
56
|
+
getEditorContainerWidth: getEditorContainerWidth,
|
|
57
|
+
canDrag: canDrag
|
|
56
58
|
}));
|
|
57
59
|
};
|
|
58
60
|
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
|
+
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
3
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
3
4
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
5
|
import { clearHoverSelection, hoverCell, hoverColumns, selectColumn } from '../../../commands';
|
|
@@ -28,7 +29,8 @@ export const ColumnControls = ({
|
|
|
28
29
|
rowHeights,
|
|
29
30
|
colWidths,
|
|
30
31
|
hasHeaderColumn,
|
|
31
|
-
isTableHovered
|
|
32
|
+
isTableHovered,
|
|
33
|
+
canDrag
|
|
32
34
|
}) => {
|
|
33
35
|
var _colWidths$map$join, _rowHeights$, _rowHeights$reduce, _colWidths;
|
|
34
36
|
const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
|
|
@@ -145,14 +147,15 @@ export const ColumnControls = ({
|
|
|
145
147
|
direction: "column",
|
|
146
148
|
tableLocalId: localId || '',
|
|
147
149
|
indexes: colIndexes,
|
|
148
|
-
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths :
|
|
150
|
+
previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
|
|
149
151
|
previewHeight: previewHeight,
|
|
150
152
|
appearance: selectedColIndexes.includes(hoveredCell.colIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
151
153
|
onClick: handleClick,
|
|
152
154
|
onMouseOver: handleMouseOver,
|
|
153
155
|
onMouseOut: handleMouseOut,
|
|
154
156
|
onMouseUp: handleMouseUp,
|
|
155
|
-
editorView: editorView
|
|
157
|
+
editorView: editorView,
|
|
158
|
+
canDrag: canDrag
|
|
156
159
|
}))));
|
|
157
160
|
};
|
|
158
161
|
export default ColumnControls;
|
|
@@ -15,7 +15,8 @@ export const TableFloatingColumnControls = ({
|
|
|
15
15
|
stickyHeader,
|
|
16
16
|
selection,
|
|
17
17
|
isInDanger,
|
|
18
|
-
isTableHovered
|
|
18
|
+
isTableHovered,
|
|
19
|
+
canDrag
|
|
19
20
|
}) => {
|
|
20
21
|
const [tableRect, setTableRect] = useState({
|
|
21
22
|
width: 0,
|
|
@@ -91,7 +92,8 @@ export const TableFloatingColumnControls = ({
|
|
|
91
92
|
isInDanger: isInDanger,
|
|
92
93
|
rowHeights: rowHeights,
|
|
93
94
|
colWidths: colWidths,
|
|
94
|
-
hasHeaderColumn: hasHeaderColumn
|
|
95
|
+
hasHeaderColumn: hasHeaderColumn,
|
|
96
|
+
canDrag: canDrag
|
|
95
97
|
}), hasDropTargets && /*#__PURE__*/React.createElement(ColumnDropTargets, {
|
|
96
98
|
tableRef: tableRef,
|
|
97
99
|
stickyTop: tableActive ? stickyTop : undefined,
|
|
@@ -31,6 +31,7 @@ const DragControlsComponent = ({
|
|
|
31
31
|
isInDanger,
|
|
32
32
|
isResizing,
|
|
33
33
|
isTableHovered,
|
|
34
|
+
canDrag,
|
|
34
35
|
hoverRows,
|
|
35
36
|
selectRow,
|
|
36
37
|
updateCellHoverLocation
|
|
@@ -132,11 +133,11 @@ const DragControlsComponent = ({
|
|
|
132
133
|
"data-end-index": endIndex,
|
|
133
134
|
className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER,
|
|
134
135
|
contentEditable: false,
|
|
135
|
-
key: index
|
|
136
|
+
key: `insert-dot-${index}`
|
|
136
137
|
}, /*#__PURE__*/React.createElement("div", {
|
|
137
138
|
className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
|
|
138
139
|
})), isDragging && /*#__PURE__*/React.createElement(RowDropTarget, {
|
|
139
|
-
key: index
|
|
140
|
+
key: `drop-target-${index}`,
|
|
140
141
|
index: index,
|
|
141
142
|
localId: currentNodeLocalId,
|
|
142
143
|
style: {
|
|
@@ -167,7 +168,8 @@ const DragControlsComponent = ({
|
|
|
167
168
|
onMouseOver: handleMouseOver,
|
|
168
169
|
onMouseOut: handleMouseOut,
|
|
169
170
|
onMouseUp: onMouseUp,
|
|
170
|
-
editorView: editorView
|
|
171
|
+
editorView: editorView,
|
|
172
|
+
canDrag: canDrag
|
|
171
173
|
})));
|
|
172
174
|
};
|
|
173
175
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -99,9 +99,10 @@ export default class TableFloatingControls extends Component {
|
|
|
99
99
|
headerRowHeight,
|
|
100
100
|
stickyHeader,
|
|
101
101
|
hoveredCell,
|
|
102
|
-
isTableHovered
|
|
102
|
+
isTableHovered,
|
|
103
|
+
canDrag
|
|
103
104
|
} = this.props;
|
|
104
|
-
return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
|
|
105
|
+
return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered || canDrag !== nextProps.canDrag;
|
|
105
106
|
}
|
|
106
107
|
componentWillUnmount() {
|
|
107
108
|
if (this.resizeObserver) {
|
|
@@ -124,7 +125,8 @@ export default class TableFloatingControls extends Component {
|
|
|
124
125
|
stickyHeader,
|
|
125
126
|
isDragAndDropEnabled,
|
|
126
127
|
hoveredCell,
|
|
127
|
-
isTableHovered
|
|
128
|
+
isTableHovered,
|
|
129
|
+
canDrag
|
|
128
130
|
} = this.props;
|
|
129
131
|
if (!tableRef) {
|
|
130
132
|
return null;
|
|
@@ -165,7 +167,8 @@ export default class TableFloatingControls extends Component {
|
|
|
165
167
|
tableWidth: this.state.tableWrapperWidth,
|
|
166
168
|
hoverRows: this.hoverRows,
|
|
167
169
|
selectRow: this.selectRow,
|
|
168
|
-
updateCellHoverLocation: this.updateCellHoverLocation
|
|
170
|
+
updateCellHoverLocation: this.updateCellHoverLocation,
|
|
171
|
+
canDrag: canDrag
|
|
169
172
|
})) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
|
|
170
173
|
editorView: editorView,
|
|
171
174
|
tableRef: tableRef,
|
|
@@ -16,7 +16,7 @@ import { deleteRows } from '../transforms';
|
|
|
16
16
|
import { AddColLeftIcon, AddColRightIcon, AddRowAboveIcon, AddRowBelowIcon } from '../ui/icons';
|
|
17
17
|
const canDecrease = (index, min = 0) => index !== undefined && index > min;
|
|
18
18
|
const canIncrease = (index, max = 0) => index !== undefined && index < max;
|
|
19
|
-
export const getDragMenuConfig = (direction, getEditorContainerWidth,
|
|
19
|
+
export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, tableMap, index, targetCellPosition, selectionRect) => {
|
|
20
20
|
const addOptions = direction === 'row' ? [{
|
|
21
21
|
label: 'above',
|
|
22
22
|
offset: 0,
|
|
@@ -41,27 +41,27 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedC
|
|
|
41
41
|
const moveOptions = direction === 'row' ? [{
|
|
42
42
|
label: 'up',
|
|
43
43
|
offset: -1,
|
|
44
|
-
canMove: canDecrease,
|
|
44
|
+
canMove: index => canDrag && canDecrease(index),
|
|
45
45
|
icon: ArrowUpIcon
|
|
46
46
|
}, {
|
|
47
47
|
label: 'down',
|
|
48
48
|
offset: 1,
|
|
49
49
|
canMove: index => {
|
|
50
50
|
var _tableMap$height;
|
|
51
|
-
return canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
|
|
51
|
+
return canDrag && canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
|
|
52
52
|
},
|
|
53
53
|
icon: ArrowDownIcon
|
|
54
54
|
}] : [{
|
|
55
55
|
label: 'left',
|
|
56
56
|
offset: -1,
|
|
57
|
-
canMove: canDecrease,
|
|
57
|
+
canMove: index => canDrag && canDecrease(index),
|
|
58
58
|
icon: ArrowLeftIcon
|
|
59
59
|
}, {
|
|
60
60
|
label: 'right',
|
|
61
61
|
offset: 1,
|
|
62
62
|
canMove: index => {
|
|
63
63
|
var _tableMap$width;
|
|
64
|
-
return canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
|
|
64
|
+
return canDrag && canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
|
|
65
65
|
},
|
|
66
66
|
icon: ArrowRightIcon
|
|
67
67
|
}];
|
|
@@ -129,7 +129,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, hasMergedC
|
|
|
129
129
|
}) => ({
|
|
130
130
|
id: `move_${direction}_${label}`,
|
|
131
131
|
title: `Move ${direction} ${label}`,
|
|
132
|
-
disabled:
|
|
132
|
+
disabled: !canMove(index),
|
|
133
133
|
icon,
|
|
134
134
|
onClick: (state, dispatch) => {
|
|
135
135
|
if (canMove(index)) {
|
|
@@ -345,6 +345,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
345
345
|
direction: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
|
|
346
346
|
index: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
|
|
347
347
|
isOpen: !!(dragAndDropState !== null && dragAndDropState !== void 0 && dragAndDropState.isDragMenuOpen) && !isResizing,
|
|
348
|
+
canDrag: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.canDrag,
|
|
348
349
|
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
349
350
|
}), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
350
351
|
editorView: editorView,
|
|
@@ -511,7 +511,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
511
511
|
options = _this$props10.options,
|
|
512
512
|
getPos = _this$props10.getPos,
|
|
513
513
|
pluginInjectionApi = _this$props10.pluginInjectionApi,
|
|
514
|
-
isDragAndDropEnabled = _this$props10.isDragAndDropEnabled
|
|
514
|
+
isDragAndDropEnabled = _this$props10.isDragAndDropEnabled,
|
|
515
|
+
canDrag = _this$props10.canDrag;
|
|
515
516
|
var _this$state3 = this.state,
|
|
516
517
|
showBeforeShadow = _this$state3.showBeforeShadow,
|
|
517
518
|
showAfterShadow = _this$state3.showAfterShadow;
|
|
@@ -538,6 +539,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
538
539
|
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
539
540
|
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
540
541
|
isDragAndDropEnabled: isDragAndDropEnabled,
|
|
542
|
+
canDrag: canDrag,
|
|
541
543
|
ordering: ordering,
|
|
542
544
|
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
543
545
|
hasHeaderRow: hasHeaderRow
|
|
@@ -564,7 +566,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
564
566
|
selection: view.state.selection,
|
|
565
567
|
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
566
568
|
stickyHeader: this.state.stickyHeader,
|
|
567
|
-
getEditorFeatureFlags: this.props.getEditorFeatureFlags
|
|
569
|
+
getEditorFeatureFlags: this.props.getEditorFeatureFlags,
|
|
570
|
+
canDrag: canDrag
|
|
568
571
|
}) : null;
|
|
569
572
|
var shadowPadding = allowControls && tableActive ? -tableToolbarSize : tableMarginSides;
|
|
570
573
|
var shadowStyle = memoizeOne(function (visible) {
|
|
@@ -18,6 +18,7 @@ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
|
18
18
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
19
19
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
20
20
|
import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
21
|
+
import { pluginKey as tableDragAndDropPluginKey } from '../pm-plugins/drag-and-drop';
|
|
21
22
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
22
23
|
import { pluginKey } from '../pm-plugins/plugin-key';
|
|
23
24
|
import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing';
|
|
@@ -135,14 +136,17 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
135
136
|
tableResizingPluginState: tableResizingPluginKey,
|
|
136
137
|
tableWidthPluginState: tableWidthPluginKey,
|
|
137
138
|
widthPlugin: fakePluginKey,
|
|
138
|
-
mediaState: fakeMediaPluginKey
|
|
139
|
+
mediaState: fakeMediaPluginKey,
|
|
140
|
+
tableDragAndDropState: tableDragAndDropPluginKey
|
|
139
141
|
},
|
|
140
142
|
editorView: props.view,
|
|
141
143
|
render: function render(pluginStates) {
|
|
144
|
+
var _tableDragAndDropStat;
|
|
142
145
|
var tableResizingPluginState = pluginStates.tableResizingPluginState,
|
|
143
146
|
tableWidthPluginState = pluginStates.tableWidthPluginState,
|
|
144
147
|
pluginState = pluginStates.pluginState,
|
|
145
|
-
mediaState = pluginStates.mediaState
|
|
148
|
+
mediaState = pluginStates.mediaState,
|
|
149
|
+
tableDragAndDropState = pluginStates.tableDragAndDropState;
|
|
146
150
|
var containerWidth = props.getEditorContainerWidth();
|
|
147
151
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
148
152
|
var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
|
|
@@ -170,6 +174,7 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
170
174
|
isHeaderRowEnabled: pluginState.isHeaderRowEnabled,
|
|
171
175
|
isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
|
|
172
176
|
isDragAndDropEnabled: pluginState.isDragAndDropEnabled,
|
|
177
|
+
canDrag: (_tableDragAndDropStat = tableDragAndDropState === null || tableDragAndDropState === void 0 ? void 0 : tableDragAndDropState.canDrag) !== null && _tableDragAndDropStat !== void 0 ? _tableDragAndDropStat : false,
|
|
173
178
|
tableActive: tableActive,
|
|
174
179
|
ordering: pluginState.ordering,
|
|
175
180
|
isResizing: isResizing,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export var DragAndDropActionType = {
|
|
2
2
|
SET_DROP_TARGET: 'SET_DROP_TARGET',
|
|
3
3
|
CLEAR_DROP_TARGET: 'CLEAR_DROP_TARGET',
|
|
4
|
-
TOGGLE_DRAG_MENU: 'TOGGLE_DRAG_MENU'
|
|
4
|
+
TOGGLE_DRAG_MENU: 'TOGGLE_DRAG_MENU',
|
|
5
|
+
UPDATE: 'UPDATE'
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
// NOTE: This should be a Union of all possible actions
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
7
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -10,7 +13,7 @@ import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
|
10
13
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
11
14
|
import { DragAndDropActionType } from './actions';
|
|
12
15
|
import { clearDropTarget, moveSource, setDropTarget, toggleDragMenu } from './commands';
|
|
13
|
-
import { DropTargetType } from './consts';
|
|
16
|
+
import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
|
|
14
17
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
15
18
|
import { pluginKey } from './plugin-key';
|
|
16
19
|
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
@@ -23,18 +26,24 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
23
26
|
dropTargetIndex: 0,
|
|
24
27
|
isDragMenuOpen: false,
|
|
25
28
|
dragMenuIndex: 0,
|
|
26
|
-
isDragging: false
|
|
29
|
+
isDragging: false,
|
|
30
|
+
canDrag: false
|
|
27
31
|
};
|
|
28
32
|
}),
|
|
29
33
|
key: pluginKey,
|
|
30
34
|
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
31
35
|
var _getTablePluginState = getTablePluginState(oldState),
|
|
32
|
-
oldTargetCellPosition = _getTablePluginState.targetCellPosition
|
|
36
|
+
oldTargetCellPosition = _getTablePluginState.targetCellPosition,
|
|
37
|
+
oldTableNode = _getTablePluginState.tableNode;
|
|
33
38
|
var _getTablePluginState2 = getTablePluginState(newState),
|
|
34
|
-
newTargetCellPosition = _getTablePluginState2.targetCellPosition
|
|
39
|
+
newTargetCellPosition = _getTablePluginState2.targetCellPosition,
|
|
40
|
+
newTableNode = _getTablePluginState2.tableNode;
|
|
35
41
|
var _getPluginState = getPluginState(newState),
|
|
36
42
|
isDragMenuOpen = _getPluginState.isDragMenuOpen,
|
|
37
|
-
dragMenuIndex = _getPluginState.dragMenuIndex
|
|
43
|
+
dragMenuIndex = _getPluginState.dragMenuIndex,
|
|
44
|
+
canDrag = _getPluginState.canDrag;
|
|
45
|
+
var stateChanges = [];
|
|
46
|
+
var tr = newState.tr;
|
|
38
47
|
|
|
39
48
|
// What's happening here? you asked... In a nutshell;
|
|
40
49
|
// If the target cell position changes while the drag menu is open then we want to close the drag menu if it has been opened.
|
|
@@ -42,14 +51,6 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
42
51
|
// to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
|
|
43
52
|
if (oldTargetCellPosition !== newTargetCellPosition) {
|
|
44
53
|
if (isDragMenuOpen) {
|
|
45
|
-
var tr = newState.tr;
|
|
46
|
-
var action = {
|
|
47
|
-
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
48
|
-
data: {
|
|
49
|
-
isDragMenuOpen: false,
|
|
50
|
-
direction: undefined
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
54
|
if (newTargetCellPosition !== undefined) {
|
|
54
55
|
var cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
55
56
|
// ED-20673 check if it is a cell selection,
|
|
@@ -57,13 +58,36 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
57
58
|
// should not close the drag menu.
|
|
58
59
|
var isCellSelection = tr.selection instanceof CellSelection;
|
|
59
60
|
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
|
|
60
|
-
|
|
61
|
+
stateChanges.push({
|
|
62
|
+
isDragMenuOpen: false,
|
|
63
|
+
dragMenuDirection: undefined
|
|
64
|
+
});
|
|
61
65
|
} // else NOP
|
|
62
66
|
} else {
|
|
63
|
-
|
|
67
|
+
stateChanges.push({
|
|
68
|
+
isDragMenuOpen: false,
|
|
69
|
+
dragMenuDirection: undefined
|
|
70
|
+
});
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
}
|
|
74
|
+
if ((oldTableNode === null || oldTableNode === void 0 ? void 0 : oldTableNode.nodeSize) !== (newTableNode === null || newTableNode === void 0 ? void 0 : newTableNode.nodeSize)) {
|
|
75
|
+
var _newTableNode$nodeSiz;
|
|
76
|
+
var nextCanDrag = ((_newTableNode$nodeSiz = newTableNode === null || newTableNode === void 0 ? void 0 : newTableNode.nodeSize) !== null && _newTableNode$nodeSiz !== void 0 ? _newTableNode$nodeSiz : 0) < DRAGGABLE_TABLE_NODE_SIZE_LIMIT;
|
|
77
|
+
if (canDrag !== nextCanDrag) {
|
|
78
|
+
stateChanges.push({
|
|
79
|
+
canDrag: nextCanDrag
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (stateChanges.length) {
|
|
84
|
+
return tr.setMeta(pluginKey, {
|
|
85
|
+
type: DragAndDropActionType.UPDATE,
|
|
86
|
+
data: _objectSpread({}, stateChanges.reduce(function (state, cur) {
|
|
87
|
+
return _objectSpread(_objectSpread({}, state), cur);
|
|
88
|
+
}, {}))
|
|
89
|
+
}).setMeta('addToHistory', false);
|
|
90
|
+
}
|
|
67
91
|
},
|
|
68
92
|
view: function view(editorView) {
|
|
69
93
|
return {
|
|
@@ -25,6 +25,8 @@ export default (function (pluginState, action) {
|
|
|
25
25
|
dragMenuDirection: action.data.direction,
|
|
26
26
|
dragMenuIndex: action.data.index
|
|
27
27
|
});
|
|
28
|
+
case DragAndDropActionType.UPDATE:
|
|
29
|
+
return _objectSpread(_objectSpread({}, pluginState), action.data);
|
|
28
30
|
default:
|
|
29
31
|
return pluginState;
|
|
30
32
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DragHandleDisabledIcon, DragHandleIcon, MinimisedHandleIcon } from '../icons';
|
|
3
3
|
export var HandleIconComponent = function HandleIconComponent(props) {
|
|
4
|
-
var
|
|
4
|
+
var canDrag = props.canDrag,
|
|
5
|
+
direction = props.direction,
|
|
5
6
|
isDragMenuOpen = props.isDragMenuOpen,
|
|
6
7
|
isRowHandleHovered = props.isRowHandleHovered,
|
|
7
8
|
isColumnHandleHovered = props.isColumnHandleHovered,
|
|
@@ -12,7 +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
|
-
var
|
|
16
|
+
var isDragPossible = canDrag && !hasMergedCells;
|
|
17
|
+
var showNormalHandle = !isDragPossible ? /*#__PURE__*/React.createElement(DragHandleDisabledIcon, null) : /*#__PURE__*/React.createElement(DragHandleIcon, null);
|
|
16
18
|
|
|
17
19
|
// hoverred handle or open drag menu
|
|
18
20
|
if (isHandleHovered || isDragMenuOpenOnCurrentRowOrColumn) {
|
|
@@ -25,7 +25,9 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
25
25
|
onMouseOut = _ref.onMouseOut,
|
|
26
26
|
_onMouseUp = _ref.onMouseUp,
|
|
27
27
|
onClick = _ref.onClick,
|
|
28
|
-
editorView = _ref.editorView
|
|
28
|
+
editorView = _ref.editorView,
|
|
29
|
+
_ref$canDrag = _ref.canDrag,
|
|
30
|
+
_canDrag = _ref$canDrag === void 0 ? false : _ref$canDrag;
|
|
29
31
|
var dragHandleDivRef = useRef(null);
|
|
30
32
|
var _useState = useState(null),
|
|
31
33
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -48,6 +50,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
48
50
|
return direction === 'row' ? hasMergedCellsInRow(indexes[0])(selection) : hasMergedCellsInColumn(indexes[0])(selection);
|
|
49
51
|
}, [indexes, direction, selection]);
|
|
50
52
|
var handleIconProps = {
|
|
53
|
+
canDrag: _canDrag,
|
|
51
54
|
hasMergedCells: hasMergedCells,
|
|
52
55
|
direction: direction,
|
|
53
56
|
isDragMenuOpen: isDragMenuOpen,
|
|
@@ -63,7 +66,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
63
66
|
return draggable({
|
|
64
67
|
element: dragHandleDivRefCurrent,
|
|
65
68
|
canDrag: function canDrag() {
|
|
66
|
-
return !hasMergedCells;
|
|
69
|
+
return _canDrag && !hasMergedCells;
|
|
67
70
|
},
|
|
68
71
|
getInitialData: function getInitialData() {
|
|
69
72
|
return {
|
|
@@ -111,9 +114,9 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
|
-
}, [tableLocalId, direction, indexes, editorView.state.selection, hasMergedCells]);
|
|
117
|
+
}, [tableLocalId, direction, indexes, editorView.state.selection, hasMergedCells, _canDrag]);
|
|
115
118
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
116
|
-
className: classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance, _defineProperty({}, ClassName.DRAG_HANDLE_DISABLED, hasMergedCells)),
|
|
119
|
+
className: classnames(ClassName.DRAG_HANDLE_BUTTON_CONTAINER, appearance, _defineProperty({}, ClassName.DRAG_HANDLE_DISABLED, !_canDrag || hasMergedCells)),
|
|
117
120
|
ref: dragHandleDivRef,
|
|
118
121
|
style: {
|
|
119
122
|
transform: direction === 'column' ? 'none' : 'rotate(90deg)'
|