@atlaskit/editor-plugin-table 5.3.11 → 5.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/plugins/table/index.js +15 -2
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +80 -0
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +60 -0
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +9 -7
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/cjs/plugins/table/ui/consts.js +3 -2
- package/dist/cjs/plugins/table/utils/drag-menu.js +59 -0
- package/dist/es2019/plugins/table/index.js +15 -2
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +26 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +42 -3
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +7 -0
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +77 -0
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +54 -0
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/es2019/plugins/table/ui/consts.js +2 -1
- package/dist/es2019/plugins/table/utils/drag-menu.js +44 -0
- package/dist/esm/plugins/table/index.js +15 -2
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/actions.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +27 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +43 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +6 -0
- package/dist/esm/plugins/table/ui/DragHandle/index.js +2 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +73 -0
- package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +53 -0
- package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +5 -5
- package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +2 -2
- package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +1 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +10 -8
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -0
- package/dist/esm/plugins/table/ui/consts.js +2 -1
- package/dist/esm/plugins/table/utils/drag-menu.js +52 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +4 -2
- package/dist/types/plugins/table/ui/DragPreview/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
- package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
- package/dist/types/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
- package/dist/types/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/drag-menu.d.ts +7 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +8 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +4 -2
- package/dist/types-ts4.5/plugins/table/ui/DragPreview/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +19 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +21 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +4 -5
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +7 -0
- package/package.json +3 -3
- package/src/plugins/table/index.tsx +16 -0
- package/src/plugins/table/nodeviews/TableComponent.tsx +2 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +14 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +43 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +41 -2
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +7 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +5 -0
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/ui/DragHandle/index.tsx +5 -1
- package/src/plugins/table/ui/DragPreview/index.tsx +2 -1
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +2 -1
- package/src/plugins/table/ui/FloatingDeleteButton/types.ts +3 -1
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +99 -0
- package/src/plugins/table/ui/FloatingDragMenu/index.tsx +84 -0
- package/src/plugins/table/ui/FloatingInsertButton/InsertButton.tsx +8 -7
- package/src/plugins/table/ui/FloatingInsertButton/getPopupOptions.ts +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +10 -7
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +16 -7
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +5 -0
- package/src/plugins/table/ui/consts.ts +2 -0
- package/src/plugins/table/utils/drag-menu.ts +65 -0
|
@@ -477,6 +477,7 @@ class TableComponent extends React.Component {
|
|
|
477
477
|
}, /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
478
478
|
editorView: view,
|
|
479
479
|
tableRef: tableRef,
|
|
480
|
+
tableNode: node,
|
|
480
481
|
tableActive: tableActive,
|
|
481
482
|
hoveredRows: hoveredRows,
|
|
482
483
|
hoveredCell: hoveredCell,
|
|
@@ -484,7 +485,7 @@ class TableComponent extends React.Component {
|
|
|
484
485
|
isResizing: isResizing,
|
|
485
486
|
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
486
487
|
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
487
|
-
isDragAndDropEnabled:
|
|
488
|
+
isDragAndDropEnabled: isDragAndDropEnabled,
|
|
488
489
|
ordering: ordering,
|
|
489
490
|
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
490
491
|
hasHeaderRow: hasHeaderRow
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
2
|
+
import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
|
|
3
3
|
import { TableDecorations } from '../../types';
|
|
4
4
|
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
5
5
|
import { DragAndDropActionType } from './actions';
|
|
@@ -62,6 +62,29 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
|
|
|
62
62
|
if (sourceIndex === targetIndex) {
|
|
63
63
|
return tr.setMeta('addToHistory', false);
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
65
|
+
const isTableRow = sourceType === 'table-row';
|
|
66
|
+
const move = isTableRow ? moveRow : moveColumn;
|
|
67
|
+
const newTr = move(sourceIndex, targetIndex)(tr);
|
|
68
|
+
const select = isTableRow ? selectRow : selectColumn;
|
|
69
|
+
return select(targetIndex)(newTr);
|
|
70
|
+
});
|
|
71
|
+
export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
|
|
72
|
+
let {
|
|
73
|
+
isDragMenuOpen: previousOpenState,
|
|
74
|
+
dragMenuDirection,
|
|
75
|
+
dragMenuIndex
|
|
76
|
+
} = getPluginState(state);
|
|
77
|
+
if (previousOpenState === isDragMenuOpen) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
82
|
+
data: {
|
|
83
|
+
isDragMenuOpen: isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
|
|
84
|
+
direction: direction !== null && direction !== void 0 ? direction : dragMenuDirection,
|
|
85
|
+
index: index !== null && index !== void 0 ? index : dragMenuIndex
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}, tr => {
|
|
89
|
+
return tr.setMeta('addToHistory', false);
|
|
67
90
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
3
4
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
4
5
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
|
|
5
6
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
7
|
+
import { DragAndDropActionType } from './actions';
|
|
6
8
|
import { clearDropTarget, moveSource, setDropTarget } from './commands';
|
|
7
9
|
import { DropTargetType } from './consts';
|
|
8
10
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
@@ -12,12 +14,49 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
12
14
|
return new SafePlugin({
|
|
13
15
|
state: createPluginState(dispatch, state => ({
|
|
14
16
|
decorationSet: DecorationSet.empty,
|
|
15
|
-
// TODO: This is example placeholder state. We could use this to track which row/col is currently set as the drop target
|
|
16
|
-
// This would result in a blue highlight being displayed on the corrisponding row/column to single the drop target location.
|
|
17
17
|
dropTargetType: DropTargetType.NONE,
|
|
18
|
-
dropTargetIndex: 0
|
|
18
|
+
dropTargetIndex: 0,
|
|
19
|
+
isDragMenuOpen: false,
|
|
20
|
+
dragMenuIndex: 0
|
|
19
21
|
})),
|
|
20
22
|
key: pluginKey,
|
|
23
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
24
|
+
const {
|
|
25
|
+
targetCellPosition: oldTargetCellPosition
|
|
26
|
+
} = getTablePluginState(oldState);
|
|
27
|
+
const {
|
|
28
|
+
targetCellPosition: newTargetCellPosition
|
|
29
|
+
} = getTablePluginState(newState);
|
|
30
|
+
const {
|
|
31
|
+
isDragMenuOpen,
|
|
32
|
+
dragMenuIndex
|
|
33
|
+
} = getPluginState(newState);
|
|
34
|
+
|
|
35
|
+
// What's happening here? you asked... In a nutshell;
|
|
36
|
+
// 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.
|
|
37
|
+
// This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
|
|
38
|
+
// to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
|
|
39
|
+
if (oldTargetCellPosition !== newTargetCellPosition) {
|
|
40
|
+
if (isDragMenuOpen) {
|
|
41
|
+
const tr = newState.tr;
|
|
42
|
+
const action = {
|
|
43
|
+
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
44
|
+
data: {
|
|
45
|
+
isDragMenuOpen: false,
|
|
46
|
+
direction: undefined
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (newTargetCellPosition !== undefined) {
|
|
50
|
+
const cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
51
|
+
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)) {
|
|
52
|
+
return tr.setMeta(pluginKey, action);
|
|
53
|
+
} // else NOP
|
|
54
|
+
} else {
|
|
55
|
+
return tr.setMeta(pluginKey, action);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
21
60
|
view: editorView => {
|
|
22
61
|
return {
|
|
23
62
|
destroy: monitorForElements({
|
|
@@ -16,6 +16,13 @@ export default ((pluginState, action) => {
|
|
|
16
16
|
dropTargetType: DropTargetType.NONE,
|
|
17
17
|
dropTargetIndex: 0
|
|
18
18
|
};
|
|
19
|
+
case DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
20
|
+
return {
|
|
21
|
+
...pluginState,
|
|
22
|
+
isDragMenuOpen: action.data.isDragMenuOpen,
|
|
23
|
+
dragMenuDirection: action.data.direction,
|
|
24
|
+
dragMenuIndex: action.data.index
|
|
25
|
+
};
|
|
19
26
|
default:
|
|
20
27
|
return pluginState;
|
|
21
28
|
}
|
|
@@ -15,6 +15,7 @@ export const DragHandle = ({
|
|
|
15
15
|
previewHeight,
|
|
16
16
|
onMouseOver,
|
|
17
17
|
onMouseOut,
|
|
18
|
+
onMouseUp,
|
|
18
19
|
onClick
|
|
19
20
|
}) => {
|
|
20
21
|
const dragHandleDivRef = useRef(null);
|
|
@@ -73,6 +74,7 @@ export const DragHandle = ({
|
|
|
73
74
|
"data-testid": "table-floating-column-controls-drag-handle",
|
|
74
75
|
onMouseOver: onMouseOver,
|
|
75
76
|
onMouseOut: onMouseOut,
|
|
77
|
+
onMouseUp: onMouseUp,
|
|
76
78
|
onClick: onClick
|
|
77
79
|
}, /*#__PURE__*/React.createElement(DragHandleIcon, null), previewContainer && previewWidth !== undefined && previewHeight !== undefined && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(DragPreview, {
|
|
78
80
|
direction: direction,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
3
|
+
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
|
+
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
5
|
+
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
6
|
+
import { dragMenuDropdownWidth } from '../consts';
|
|
7
|
+
const convertToDropdownItems = dragMenuConfig => {
|
|
8
|
+
let menuItems = [];
|
|
9
|
+
let menuCallback = {};
|
|
10
|
+
dragMenuConfig.forEach(item => {
|
|
11
|
+
menuItems.push({
|
|
12
|
+
key: item.id,
|
|
13
|
+
content: item.title,
|
|
14
|
+
value: {
|
|
15
|
+
name: item.id
|
|
16
|
+
},
|
|
17
|
+
isDisabled: item.disabled
|
|
18
|
+
});
|
|
19
|
+
item.onClick && (menuCallback[item.id] = item.onClick);
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
menuItems,
|
|
23
|
+
menuCallback
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const DragMenu = ({
|
|
27
|
+
direction = 'row',
|
|
28
|
+
index,
|
|
29
|
+
isOpen,
|
|
30
|
+
editorView,
|
|
31
|
+
tableNode,
|
|
32
|
+
mountPoint,
|
|
33
|
+
boundariesElement,
|
|
34
|
+
scrollableElement
|
|
35
|
+
}) => {
|
|
36
|
+
const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
|
|
37
|
+
const dragMenuConfig = getDragMenuConfig(direction, tableMap, index);
|
|
38
|
+
const {
|
|
39
|
+
menuItems,
|
|
40
|
+
menuCallback
|
|
41
|
+
} = convertToDropdownItems(dragMenuConfig);
|
|
42
|
+
const closeMenu = () => {
|
|
43
|
+
const {
|
|
44
|
+
state,
|
|
45
|
+
dispatch
|
|
46
|
+
} = editorView;
|
|
47
|
+
toggleDragMenu(false)(state, dispatch);
|
|
48
|
+
};
|
|
49
|
+
const onMenuItemActivated = ({
|
|
50
|
+
item
|
|
51
|
+
}) => {
|
|
52
|
+
var _menuCallback$item$va;
|
|
53
|
+
(_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 ? void 0 : _menuCallback$item$va.call(menuCallback, editorView.state, editorView.dispatch);
|
|
54
|
+
closeMenu();
|
|
55
|
+
};
|
|
56
|
+
if (!menuItems) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
60
|
+
mountTo: mountPoint
|
|
61
|
+
//This needs be removed when the a11y is completely handled
|
|
62
|
+
//Disabling key navigation now as it works only partially
|
|
63
|
+
,
|
|
64
|
+
arrowKeyNavigationProviderOptions: {
|
|
65
|
+
type: ArrowKeyNavigationType.MENU,
|
|
66
|
+
disableArrowKeyNavigation: true
|
|
67
|
+
},
|
|
68
|
+
items: [{
|
|
69
|
+
items: menuItems
|
|
70
|
+
}],
|
|
71
|
+
isOpen: isOpen,
|
|
72
|
+
onOpenChange: closeMenu,
|
|
73
|
+
onItemActivated: onMenuItemActivated,
|
|
74
|
+
fitWidth: dragMenuDropdownWidth,
|
|
75
|
+
boundariesElement: boundariesElement
|
|
76
|
+
});
|
|
77
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { dragMenuDropdownWidth } from '../consts';
|
|
6
|
+
import { DragMenu } from './DragMenu';
|
|
7
|
+
const FloatingDragMenu = ({
|
|
8
|
+
mountPoint,
|
|
9
|
+
boundariesElement,
|
|
10
|
+
scrollableElement,
|
|
11
|
+
editorView,
|
|
12
|
+
isOpen,
|
|
13
|
+
tableRef,
|
|
14
|
+
tableNode,
|
|
15
|
+
direction,
|
|
16
|
+
index,
|
|
17
|
+
targetCellPosition
|
|
18
|
+
}) => {
|
|
19
|
+
if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
23
|
+
const targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
|
|
24
|
+
if (!targetCellRef) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
|
|
29
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
30
|
+
alignX: "left",
|
|
31
|
+
alignY: "top",
|
|
32
|
+
target: targetCellRef,
|
|
33
|
+
mountTo: mountPoint,
|
|
34
|
+
boundariesElement: boundariesElement,
|
|
35
|
+
scrollableElement: scrollableElement,
|
|
36
|
+
fitWidth: dragMenuDropdownWidth
|
|
37
|
+
// z-index value below is to ensure that this menu is above other floating menu
|
|
38
|
+
// in table, but below floating dialogs like typeaheads, pickers, etc.
|
|
39
|
+
,
|
|
40
|
+
zIndex: akEditorFloatingOverlapPanelZIndex,
|
|
41
|
+
forcePlacement: true,
|
|
42
|
+
offset: [7, 0],
|
|
43
|
+
stick: true
|
|
44
|
+
}, /*#__PURE__*/React.createElement(DragMenu, {
|
|
45
|
+
editorView: editorView,
|
|
46
|
+
isOpen: isOpen,
|
|
47
|
+
boundariesElement: boundariesElement,
|
|
48
|
+
tableNode: tableNode,
|
|
49
|
+
direction: direction,
|
|
50
|
+
index: index
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
|
54
|
+
export default FloatingDragMenu;
|
|
@@ -46,7 +46,7 @@ const tooltipMessageByType = type => {
|
|
|
46
46
|
const InsertButton = ({
|
|
47
47
|
onMouseDown,
|
|
48
48
|
tableRef,
|
|
49
|
-
|
|
49
|
+
direction,
|
|
50
50
|
intl: {
|
|
51
51
|
formatMessage
|
|
52
52
|
},
|
|
@@ -54,8 +54,8 @@ const InsertButton = ({
|
|
|
54
54
|
}) => {
|
|
55
55
|
const content = /*#__PURE__*/React.createElement(Tooltip, {
|
|
56
56
|
content: /*#__PURE__*/React.createElement(ToolTipContent, {
|
|
57
|
-
description: formatMessage(tooltipMessageByType(
|
|
58
|
-
keymap:
|
|
57
|
+
description: formatMessage(tooltipMessageByType(direction)),
|
|
58
|
+
keymap: direction === 'row' ? addRowAfter : addColumnAfter
|
|
59
59
|
}),
|
|
60
60
|
position: "top"
|
|
61
61
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -72,13 +72,13 @@ const InsertButton = ({
|
|
|
72
72
|
fillRule: "evenodd"
|
|
73
73
|
})))), /*#__PURE__*/React.createElement("div", {
|
|
74
74
|
className: ClassName.CONTROLS_INSERT_LINE,
|
|
75
|
-
style:
|
|
75
|
+
style: direction === 'row' ? {
|
|
76
76
|
width: getInsertLineWidth(tableRef)
|
|
77
77
|
} : {
|
|
78
78
|
height: getInsertLineHeight(tableRef, hasStickyHeaders)
|
|
79
79
|
}
|
|
80
80
|
})));
|
|
81
|
-
const floatingButtonClassName =
|
|
81
|
+
const floatingButtonClassName = direction === 'column' ? ClassName.CONTROLS_FLOATING_BUTTON_COLUMN : ClassName.CONTROLS_FLOATING_BUTTON_ROW;
|
|
82
82
|
return /*#__PURE__*/React.createElement("div", {
|
|
83
83
|
className: floatingButtonClassName
|
|
84
84
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -75,8 +75,8 @@ function getColumnOptions(index, tableContainer, hasNumberedColumns) {
|
|
|
75
75
|
}
|
|
76
76
|
return options;
|
|
77
77
|
}
|
|
78
|
-
function getPopupOptions(
|
|
79
|
-
switch (
|
|
78
|
+
function getPopupOptions(direction, index, hasNumberedColumns, tableContainer) {
|
|
79
|
+
switch (direction) {
|
|
80
80
|
case 'column':
|
|
81
81
|
return getColumnOptions(index, tableContainer, hasNumberedColumns);
|
|
82
82
|
case 'row':
|
|
@@ -114,7 +114,7 @@ export class FloatingInsertButton extends React.Component {
|
|
|
114
114
|
}, getPopupOptions(type, index, hasNumberedColumns, tableContainerWrapper), {
|
|
115
115
|
zIndex: zIndex
|
|
116
116
|
}), /*#__PURE__*/React.createElement(InsertButton, {
|
|
117
|
-
|
|
117
|
+
direction: type,
|
|
118
118
|
tableRef: tableRef,
|
|
119
119
|
onMouseDown: type === 'column' ? this.insertColumn : this.insertRow,
|
|
120
120
|
hasStickyHeaders: this.props.hasStickyHeaders || false
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { injectIntl } from 'react-intl-next';
|
|
3
3
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
4
|
-
import {
|
|
4
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { clearHoverSelection } from '../../../commands';
|
|
6
|
+
import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
|
|
6
7
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
8
|
import { getRowHeights, getSelectedRowIndexes } from '../../../utils';
|
|
8
9
|
import { DragHandle } from '../../DragHandle';
|
|
@@ -18,6 +19,7 @@ const getSelectedRows = selection => {
|
|
|
18
19
|
};
|
|
19
20
|
const DragControlsComponent = ({
|
|
20
21
|
tableRef,
|
|
22
|
+
tableNode,
|
|
21
23
|
hoveredCell,
|
|
22
24
|
tableActive,
|
|
23
25
|
editorView,
|
|
@@ -26,10 +28,14 @@ const DragControlsComponent = ({
|
|
|
26
28
|
selectRow,
|
|
27
29
|
updateCellHoverLocation
|
|
28
30
|
}) => {
|
|
31
|
+
var _tableNode$attrs$loca, _tableNode$attrs;
|
|
29
32
|
const rowHeights = getRowHeights(tableRef);
|
|
30
33
|
const heights = rowHeights.map(height => `${height - 1}px`).join(' ');
|
|
31
34
|
const selectedRowIndexes = getSelectedRows(editorView.state.selection);
|
|
32
35
|
const rowWidth = tableRef.offsetWidth;
|
|
36
|
+
const onMouseUp = useCallback(() => {
|
|
37
|
+
toggleDragMenu(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex)(editorView.state, editorView.dispatch);
|
|
38
|
+
}, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex]);
|
|
33
39
|
const rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
|
|
34
40
|
const gridRowPosition = useMemo(() => {
|
|
35
41
|
// if more than one row is selected, ensure the handle spans over the selected range
|
|
@@ -38,11 +44,6 @@ const DragControlsComponent = ({
|
|
|
38
44
|
}
|
|
39
45
|
return `${rowIndex + 1} / span 1`;
|
|
40
46
|
}, [rowIndex, selectedRowIndexes]);
|
|
41
|
-
const getLocalId = () => {
|
|
42
|
-
var _tableNode$node, _tableNode$node$attrs;
|
|
43
|
-
const tableNode = findTable(editorView.state.selection);
|
|
44
|
-
return (tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$node = tableNode.node) === null || _tableNode$node === void 0 ? void 0 : (_tableNode$node$attrs = _tableNode$node.attrs) === null || _tableNode$node$attrs === void 0 ? void 0 : _tableNode$node$attrs.localId) || '';
|
|
45
|
-
};
|
|
46
47
|
const handleMouseOut = useCallback(() => {
|
|
47
48
|
if (tableActive) {
|
|
48
49
|
const {
|
|
@@ -86,14 +87,15 @@ const DragControlsComponent = ({
|
|
|
86
87
|
justifyContent: 'center'
|
|
87
88
|
}
|
|
88
89
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
89
|
-
tableLocalId:
|
|
90
|
+
tableLocalId: (_tableNode$attrs$loca = tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$attrs = tableNode.attrs) === null || _tableNode$attrs === void 0 ? void 0 : _tableNode$attrs.localId) !== null && _tableNode$attrs$loca !== void 0 ? _tableNode$attrs$loca : '',
|
|
90
91
|
indexes: [rowIndex],
|
|
91
92
|
previewWidth: rowWidth,
|
|
92
93
|
previewHeight: rowHeights[rowIndex],
|
|
93
94
|
appearance: selectedRowIndexes.includes(rowIndex) ? isInDanger ? 'danger' : 'selected' : 'default',
|
|
94
95
|
onClick: handleClick,
|
|
95
96
|
onMouseOver: handleMouseOver,
|
|
96
|
-
onMouseOut: handleMouseOut
|
|
97
|
+
onMouseOut: handleMouseOut,
|
|
98
|
+
onMouseUp: onMouseUp
|
|
97
99
|
})));
|
|
98
100
|
};
|
|
99
101
|
export const DragControls = injectIntl(DragControlsComponent);
|
|
@@ -105,6 +105,7 @@ export default class TableFloatingControls extends Component {
|
|
|
105
105
|
const {
|
|
106
106
|
editorView,
|
|
107
107
|
tableRef,
|
|
108
|
+
tableNode,
|
|
108
109
|
isInDanger,
|
|
109
110
|
isResizing,
|
|
110
111
|
isNumberColumnEnabled,
|
|
@@ -138,6 +139,7 @@ export default class TableFloatingControls extends Component {
|
|
|
138
139
|
isDragAndDropEnabled: isDragAndDropEnabled
|
|
139
140
|
}) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragControls, {
|
|
140
141
|
tableRef: tableRef,
|
|
142
|
+
tableNode: tableNode,
|
|
141
143
|
hoveredCell: hoveredCell,
|
|
142
144
|
editorView: editorView,
|
|
143
145
|
tableActive: tableActive,
|
|
@@ -104,4 +104,5 @@ export const tableOverflowShadowWidthWide = 32;
|
|
|
104
104
|
export const TABLE_SNAP_GAP = 9;
|
|
105
105
|
export const TABLE_HIGHLIGHT_GAP = 10;
|
|
106
106
|
export const TABLE_HIGHLIGHT_TOLERANCE = 2;
|
|
107
|
-
export const STICKY_HEADER_TOGGLE_TOLERANCE_MS = 5;
|
|
107
|
+
export const STICKY_HEADER_TOGGLE_TOLERANCE_MS = 5;
|
|
108
|
+
export const dragMenuDropdownWidth = 240;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { moveSource } from '../pm-plugins/drag-and-drop/commands';
|
|
2
|
+
const canDecrease = (index, min = 0) => index !== undefined && index > min;
|
|
3
|
+
const canIncrease = (index, max = 0) => index !== undefined && index < max;
|
|
4
|
+
export const getDragMenuConfig = (direction, tableMap, index) => {
|
|
5
|
+
const moveOptions = direction === 'row' ? [{
|
|
6
|
+
label: 'up',
|
|
7
|
+
offset: -1,
|
|
8
|
+
canMove: canDecrease
|
|
9
|
+
}, {
|
|
10
|
+
label: 'down',
|
|
11
|
+
offset: 1,
|
|
12
|
+
canMove: index => {
|
|
13
|
+
var _tableMap$height;
|
|
14
|
+
return canIncrease(index, ((_tableMap$height = tableMap === null || tableMap === void 0 ? void 0 : tableMap.height) !== null && _tableMap$height !== void 0 ? _tableMap$height : 0) - 1);
|
|
15
|
+
}
|
|
16
|
+
}] : [{
|
|
17
|
+
label: 'left',
|
|
18
|
+
offset: -1,
|
|
19
|
+
canMove: canDecrease
|
|
20
|
+
}, {
|
|
21
|
+
label: 'right',
|
|
22
|
+
offset: 1,
|
|
23
|
+
canMove: index => {
|
|
24
|
+
var _tableMap$width;
|
|
25
|
+
return canIncrease(index, ((_tableMap$width = tableMap === null || tableMap === void 0 ? void 0 : tableMap.width) !== null && _tableMap$width !== void 0 ? _tableMap$width : 0) - 1);
|
|
26
|
+
}
|
|
27
|
+
}];
|
|
28
|
+
return [...moveOptions.map(({
|
|
29
|
+
label,
|
|
30
|
+
offset,
|
|
31
|
+
canMove
|
|
32
|
+
}) => ({
|
|
33
|
+
id: `move_${direction}_${label}`,
|
|
34
|
+
title: `Move ${direction} ${label}`,
|
|
35
|
+
disabled: !canMove(index),
|
|
36
|
+
onClick: (state, dispatch) => {
|
|
37
|
+
if (canMove(index)) {
|
|
38
|
+
moveSource(`table-${direction}`, index, index + offset)(state, dispatch);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}))];
|
|
44
|
+
};
|
|
@@ -28,6 +28,7 @@ import { getToolbarConfig } from './toolbar';
|
|
|
28
28
|
import FloatingContextualButton from './ui/FloatingContextualButton';
|
|
29
29
|
import FloatingContextualMenu from './ui/FloatingContextualMenu';
|
|
30
30
|
import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
31
|
+
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
31
32
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
32
33
|
import LayoutButton from './ui/LayoutButton';
|
|
33
34
|
import { isLayoutSupported } from './utils';
|
|
@@ -249,7 +250,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
249
250
|
var resizingPluginState = _ref13.tableResizingPluginState,
|
|
250
251
|
stickyHeadersState = _ref13.stickyHeadersState,
|
|
251
252
|
tablePluginState = _ref13.tablePluginState,
|
|
252
|
-
tableWidthPluginState = _ref13.tableWidthPluginState
|
|
253
|
+
tableWidthPluginState = _ref13.tableWidthPluginState,
|
|
254
|
+
dragAndDropState = _ref13.dragAndDropState;
|
|
253
255
|
var state = editorView.state;
|
|
254
256
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
255
257
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
@@ -266,7 +268,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
266
268
|
insertRowButtonIndex = _ref14.insertRowButtonIndex,
|
|
267
269
|
isHeaderColumnEnabled = _ref14.isHeaderColumnEnabled,
|
|
268
270
|
isHeaderRowEnabled = _ref14.isHeaderRowEnabled,
|
|
269
|
-
tableWrapperTarget = _ref14.tableWrapperTarget
|
|
271
|
+
tableWrapperTarget = _ref14.tableWrapperTarget,
|
|
272
|
+
isDragAndDropEnabled = _ref14.isDragAndDropEnabled;
|
|
270
273
|
var allowControls = pluginConfig.allowControls;
|
|
271
274
|
var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
|
|
272
275
|
var LayoutContent = options && !options.tableResizingEnabled && isLayoutSupported(state) && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
|
|
@@ -317,6 +320,16 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
317
320
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
318
321
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
319
322
|
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
323
|
+
}), isDragAndDropEnabled && /*#__PURE__*/React.createElement(FloatingDragMenu, {
|
|
324
|
+
editorView: editorView,
|
|
325
|
+
mountPoint: popupsMountPoint,
|
|
326
|
+
boundariesElement: popupsBoundariesElement,
|
|
327
|
+
tableRef: tableRef,
|
|
328
|
+
tableNode: tableNode,
|
|
329
|
+
targetCellPosition: targetCellPosition,
|
|
330
|
+
direction: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
|
|
331
|
+
index: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
|
|
332
|
+
isOpen: !!(dragAndDropState !== null && dragAndDropState !== void 0 && dragAndDropState.isDragMenuOpen) && !isResizing
|
|
320
333
|
}), allowControls && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
321
334
|
editorView: editorView,
|
|
322
335
|
selection: editorView.state.selection,
|
|
@@ -472,6 +472,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
472
472
|
}, /*#__PURE__*/React.createElement(TableFloatingControls, {
|
|
473
473
|
editorView: view,
|
|
474
474
|
tableRef: tableRef,
|
|
475
|
+
tableNode: node,
|
|
475
476
|
tableActive: tableActive,
|
|
476
477
|
hoveredRows: hoveredRows,
|
|
477
478
|
hoveredCell: hoveredCell,
|
|
@@ -479,7 +480,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
479
480
|
isResizing: isResizing,
|
|
480
481
|
isNumberColumnEnabled: node.attrs.isNumberColumnEnabled,
|
|
481
482
|
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
482
|
-
isDragAndDropEnabled:
|
|
483
|
+
isDragAndDropEnabled: isDragAndDropEnabled,
|
|
483
484
|
ordering: ordering,
|
|
484
485
|
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
485
486
|
hasHeaderRow: hasHeaderRow
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
2
|
+
import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
|
|
3
3
|
import { TableDecorations } from '../../types';
|
|
4
4
|
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
5
5
|
import { DragAndDropActionType } from './actions';
|
|
@@ -71,7 +71,31 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
|
|
|
71
71
|
if (sourceIndex === targetIndex) {
|
|
72
72
|
return tr.setMeta('addToHistory', false);
|
|
73
73
|
}
|
|
74
|
-
var
|
|
75
|
-
|
|
74
|
+
var isTableRow = sourceType === 'table-row';
|
|
75
|
+
var move = isTableRow ? moveRow : moveColumn;
|
|
76
|
+
var newTr = move(sourceIndex, targetIndex)(tr);
|
|
77
|
+
var select = isTableRow ? selectRow : selectColumn;
|
|
78
|
+
return select(targetIndex)(newTr);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
|
|
82
|
+
return createCommand(function (state) {
|
|
83
|
+
var _getPluginState3 = getPluginState(state),
|
|
84
|
+
previousOpenState = _getPluginState3.isDragMenuOpen,
|
|
85
|
+
dragMenuDirection = _getPluginState3.dragMenuDirection,
|
|
86
|
+
dragMenuIndex = _getPluginState3.dragMenuIndex;
|
|
87
|
+
if (previousOpenState === isDragMenuOpen) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
92
|
+
data: {
|
|
93
|
+
isDragMenuOpen: isDragMenuOpen === undefined ? !previousOpenState : isDragMenuOpen,
|
|
94
|
+
direction: direction !== null && direction !== void 0 ? direction : dragMenuDirection,
|
|
95
|
+
index: index !== null && index !== void 0 ? index : dragMenuIndex
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, function (tr) {
|
|
99
|
+
return tr.setMeta('addToHistory', false);
|
|
76
100
|
});
|
|
77
101
|
};
|