@atlaskit/editor-plugin-table 5.3.24 → 5.3.26
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/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/cjs/plugins/table/transforms/column-width.js +10 -43
- package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/es2019/plugins/table/transforms/column-width.js +10 -43
- package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +27 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +19 -6
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +6 -1
- package/dist/esm/plugins/table/transforms/column-width.js +10 -43
- package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +26 -1
- package/package.json +2 -5
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +31 -7
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -1
- package/src/plugins/table/transforms/column-width.ts +14 -60
- package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +33 -1
- package/src/__tests__/integration/__snapshots__/auto-size.ts.snap +0 -612
- package/src/__tests__/integration/__snapshots__/delete-columns.ts.snap +0 -820
- package/src/__tests__/integration/__snapshots__/delete-last-column-in-full-width.ts.snap +0 -120
- package/src/__tests__/integration/__snapshots__/delete-last-column-with-empty-action.ts.snap +0 -120
- package/src/__tests__/integration/__snapshots__/delete-last-row-with-empty-action.ts.snap +0 -229
- package/src/__tests__/integration/__snapshots__/insert-row-inside-layout.ts.snap +0 -239
- package/src/__tests__/integration/__snapshots__/resize.ts.snap +0 -2685
- package/src/__tests__/integration/__snapshots__/scale.ts.snap +0 -1085
- package/src/__tests__/integration/arrow-down-into-table.ts +0 -50
- package/src/__tests__/integration/auto-size.ts +0 -92
- package/src/__tests__/integration/cell-selection.ts +0 -105
- package/src/__tests__/integration/delete-columns.ts +0 -99
- package/src/__tests__/integration/delete-last-column-in-full-width.ts +0 -73
- package/src/__tests__/integration/delete-last-column-with-empty-action.ts +0 -60
- package/src/__tests__/integration/delete-last-row-with-empty-action.ts +0 -99
- package/src/__tests__/integration/insert-row-inside-layout.ts +0 -52
- package/src/__tests__/integration/resize.ts +0 -333
- package/src/__tests__/integration/scale.ts +0 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.3.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#42815](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42815) [`7fac5fb48e7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7fac5fb48e7) - ED-20673: Fixed drag menu is not open when clicking on different drag handles consecutively.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 5.3.25
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#42925](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42925) [`8ea16423505`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8ea16423505) - Removes FF platform.editor.update-table-cell-width-via-step
|
|
15
|
+
|
|
3
16
|
## 5.3.24
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -87,17 +87,30 @@ var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenu
|
|
|
87
87
|
return (0, _pluginFactory.createCommand)(function (state) {
|
|
88
88
|
var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
|
|
89
89
|
previousOpenState = _getPluginState3.isDragMenuOpen,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (previousOpenState === isDragMenuOpen) {
|
|
90
|
+
previousDragMenuDirection = _getPluginState3.dragMenuDirection,
|
|
91
|
+
previousDragMenuIndex = _getPluginState3.dragMenuIndex;
|
|
92
|
+
if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
|
+
var updatedMenuOpenState;
|
|
96
|
+
if (isDragMenuOpen !== undefined) {
|
|
97
|
+
updatedMenuOpenState = isDragMenuOpen;
|
|
98
|
+
} else {
|
|
99
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
100
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
101
|
+
// 2 scenarios above , menu should remain open.
|
|
102
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
103
|
+
updatedMenuOpenState = true;
|
|
104
|
+
} else {
|
|
105
|
+
updatedMenuOpenState = !previousOpenState;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
95
108
|
return {
|
|
96
109
|
type: _actions.DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
97
110
|
data: {
|
|
98
|
-
isDragMenuOpen:
|
|
99
|
-
direction: direction !== null && direction !== void 0 ? direction :
|
|
100
|
-
index: index !== null && index !== void 0 ? index :
|
|
111
|
+
isDragMenuOpen: updatedMenuOpenState,
|
|
112
|
+
direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
|
|
113
|
+
index: index !== null && index !== void 0 ? index : previousDragMenuIndex
|
|
101
114
|
}
|
|
102
115
|
};
|
|
103
116
|
}, function (tr) {
|
|
@@ -8,6 +8,7 @@ exports.createPlugin = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
11
12
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
13
|
var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
13
14
|
var _pragmaticDragAndDropReactBeautifulDndAutoscroll = require("@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll");
|
|
@@ -56,7 +57,11 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
56
57
|
};
|
|
57
58
|
if (newTargetCellPosition !== undefined) {
|
|
58
59
|
var cells = (0, _utils.getCellsInRow)(dragMenuIndex)(tr.selection);
|
|
59
|
-
|
|
60
|
+
// ED-20673 check if it is a cell selection,
|
|
61
|
+
// when true, a drag handle is clicked and isDragMenuOpen is true here
|
|
62
|
+
// should not close the drag menu.
|
|
63
|
+
var isCellSelection = tr.selection instanceof _cellSelection.CellSelection;
|
|
64
|
+
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
|
|
60
65
|
return tr.setMeta(_pluginKey.pluginKey, action);
|
|
61
66
|
} // else NOP
|
|
62
67
|
} else {
|
|
@@ -67,52 +67,19 @@ var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidth
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// updating all cells with new attributes
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
for (var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
tr.step(new _transform.AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
80
|
-
}
|
|
81
|
-
seen[pos] = true;
|
|
70
|
+
var seen = {};
|
|
71
|
+
for (var _rowIndex = 0; _rowIndex < map.height; _rowIndex++) {
|
|
72
|
+
for (var _columnIndex = 0; _columnIndex < map.width; _columnIndex++) {
|
|
73
|
+
var _mapIndex = _rowIndex * map.width + _columnIndex;
|
|
74
|
+
var pos = map.map[_mapIndex];
|
|
75
|
+
var cell = table.nodeAt(pos);
|
|
76
|
+
if (!seen[pos] && cell) {
|
|
77
|
+
if (updatedCellsAttrs[pos]) {
|
|
78
|
+
tr.step(new _transform.AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
82
79
|
}
|
|
80
|
+
seen[pos] = true;
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
|
-
} else {
|
|
86
|
-
var rows = [];
|
|
87
|
-
var _seen = {};
|
|
88
|
-
for (var _rowIndex2 = 0; _rowIndex2 < map.height; _rowIndex2++) {
|
|
89
|
-
var row = table.child(_rowIndex2);
|
|
90
|
-
var cells = [];
|
|
91
|
-
for (var _columnIndex2 = 0; _columnIndex2 < map.width; _columnIndex2++) {
|
|
92
|
-
var _mapIndex2 = _rowIndex2 * map.width + _columnIndex2;
|
|
93
|
-
var _pos = map.map[_mapIndex2];
|
|
94
|
-
var _cell = table.nodeAt(_pos);
|
|
95
|
-
if (!_seen[_pos] && _cell) {
|
|
96
|
-
cells.push(_cell.type.createChecked(updatedCellsAttrs[_pos] || _cell.attrs, _cell.content, _cell.marks));
|
|
97
|
-
_seen[_pos] = true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
101
|
-
}
|
|
102
|
-
var tablePos = start - 1;
|
|
103
|
-
var selectionBookmark = tr.selection.getBookmark();
|
|
104
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
105
|
-
/**
|
|
106
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
107
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
108
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
109
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
110
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
111
|
-
* bookmark of selection.
|
|
112
|
-
*
|
|
113
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
114
|
-
*/
|
|
115
|
-
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
116
83
|
}
|
|
117
84
|
return tr;
|
|
118
85
|
};
|
|
@@ -13,6 +13,7 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
|
13
13
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
14
14
|
var _commands = require("../../commands");
|
|
15
15
|
var _commands2 = require("../../pm-plugins/drag-and-drop/commands");
|
|
16
|
+
var _pluginFactory = require("../../pm-plugins/drag-and-drop/plugin-factory");
|
|
16
17
|
var _utils2 = require("../../utils");
|
|
17
18
|
var _dragMenu = require("../../utils/drag-menu");
|
|
18
19
|
var _consts = require("../consts");
|
|
@@ -84,10 +85,34 @@ var DragMenu = exports.DragMenu = function DragMenu(_ref) {
|
|
|
84
85
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
85
86
|
menuItems = _convertToDropdownIte.menuItems,
|
|
86
87
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* This function is to check if the menu should be closed or not.
|
|
91
|
+
* As when continously clicking on drag handle on different rows/columns,
|
|
92
|
+
* should open the menu corresponding to the position of the drag handle.
|
|
93
|
+
* @returns true when the menu should be closed, false otherwise
|
|
94
|
+
*/
|
|
95
|
+
var shouldCloseMenu = function shouldCloseMenu(state) {
|
|
96
|
+
var _getPluginState = (0, _pluginFactory.getPluginState)(state),
|
|
97
|
+
previousOpenState = _getPluginState.isDragMenuOpen,
|
|
98
|
+
previousDragMenuDirection = _getPluginState.dragMenuDirection,
|
|
99
|
+
previousDragMenuIndex = _getPluginState.dragMenuIndex;
|
|
100
|
+
|
|
101
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
102
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
103
|
+
// 2 scenarios above , menu should not be closed.
|
|
104
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
105
|
+
return false;
|
|
106
|
+
} else {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
87
110
|
var closeMenu = function closeMenu() {
|
|
88
111
|
var state = editorView.state,
|
|
89
112
|
dispatch = editorView.dispatch;
|
|
90
|
-
|
|
113
|
+
if (shouldCloseMenu(state)) {
|
|
114
|
+
(0, _commands2.toggleDragMenu)(false, direction, index)(state, dispatch);
|
|
115
|
+
}
|
|
91
116
|
};
|
|
92
117
|
var handleMenuItemActivated = function handleMenuItemActivated(_ref2) {
|
|
93
118
|
var _menuCallback$item$va;
|
|
@@ -71,18 +71,31 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
|
|
|
71
71
|
export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
|
|
72
72
|
let {
|
|
73
73
|
isDragMenuOpen: previousOpenState,
|
|
74
|
-
dragMenuDirection,
|
|
75
|
-
dragMenuIndex
|
|
74
|
+
dragMenuDirection: previousDragMenuDirection,
|
|
75
|
+
dragMenuIndex: previousDragMenuIndex
|
|
76
76
|
} = getPluginState(state);
|
|
77
|
-
if (previousOpenState === isDragMenuOpen) {
|
|
77
|
+
if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
+
let updatedMenuOpenState;
|
|
81
|
+
if (isDragMenuOpen !== undefined) {
|
|
82
|
+
updatedMenuOpenState = isDragMenuOpen;
|
|
83
|
+
} else {
|
|
84
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
85
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
86
|
+
// 2 scenarios above , menu should remain open.
|
|
87
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
88
|
+
updatedMenuOpenState = true;
|
|
89
|
+
} else {
|
|
90
|
+
updatedMenuOpenState = !previousOpenState;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
80
93
|
return {
|
|
81
94
|
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
82
95
|
data: {
|
|
83
|
-
isDragMenuOpen:
|
|
84
|
-
direction: direction !== null && direction !== void 0 ? direction :
|
|
85
|
-
index: index !== null && index !== void 0 ? index :
|
|
96
|
+
isDragMenuOpen: updatedMenuOpenState,
|
|
97
|
+
direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
|
|
98
|
+
index: index !== null && index !== void 0 ? index : previousDragMenuIndex
|
|
86
99
|
}
|
|
87
100
|
};
|
|
88
101
|
}, tr => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
3
4
|
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
4
5
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
5
6
|
import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
|
|
@@ -49,7 +50,11 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
49
50
|
};
|
|
50
51
|
if (newTargetCellPosition !== undefined) {
|
|
51
52
|
const cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
52
|
-
|
|
53
|
+
// ED-20673 check if it is a cell selection,
|
|
54
|
+
// when true, a drag handle is clicked and isDragMenuOpen is true here
|
|
55
|
+
// should not close the drag menu.
|
|
56
|
+
const isCellSelection = tr.selection instanceof CellSelection;
|
|
57
|
+
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
|
|
53
58
|
return tr.setMeta(pluginKey, action);
|
|
54
59
|
} // else NOP
|
|
55
60
|
} else {
|
|
@@ -60,52 +60,19 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// updating all cells with new attributes
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
73
|
-
}
|
|
74
|
-
seen[pos] = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
const rows = [];
|
|
80
|
-
const seen = {};
|
|
81
|
-
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
82
|
-
const row = table.child(rowIndex);
|
|
83
|
-
const cells = [];
|
|
84
|
-
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
85
|
-
const mapIndex = rowIndex * map.width + columnIndex;
|
|
86
|
-
const pos = map.map[mapIndex];
|
|
87
|
-
const cell = table.nodeAt(pos);
|
|
88
|
-
if (!seen[pos] && cell) {
|
|
89
|
-
cells.push(cell.type.createChecked(updatedCellsAttrs[pos] || cell.attrs, cell.content, cell.marks));
|
|
90
|
-
seen[pos] = true;
|
|
63
|
+
const seen = {};
|
|
64
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
65
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
66
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
67
|
+
const pos = map.map[mapIndex];
|
|
68
|
+
const cell = table.nodeAt(pos);
|
|
69
|
+
if (!seen[pos] && cell) {
|
|
70
|
+
if (updatedCellsAttrs[pos]) {
|
|
71
|
+
tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
91
72
|
}
|
|
73
|
+
seen[pos] = true;
|
|
92
74
|
}
|
|
93
|
-
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
94
75
|
}
|
|
95
|
-
const tablePos = start - 1;
|
|
96
|
-
const selectionBookmark = tr.selection.getBookmark();
|
|
97
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
98
|
-
/**
|
|
99
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
100
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
101
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
102
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
103
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
104
|
-
* bookmark of selection.
|
|
105
|
-
*
|
|
106
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
107
|
-
*/
|
|
108
|
-
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
109
76
|
}
|
|
110
77
|
return tr;
|
|
111
78
|
};
|
|
@@ -6,6 +6,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
6
6
|
import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
|
|
7
7
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
8
8
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
9
|
+
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
9
10
|
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
10
11
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
11
12
|
import { dragMenuDropdownWidth } from '../consts';
|
|
@@ -76,12 +77,37 @@ export const DragMenu = ({
|
|
|
76
77
|
menuItems,
|
|
77
78
|
menuCallback
|
|
78
79
|
} = convertToDropdownItems(dragMenuConfig);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* This function is to check if the menu should be closed or not.
|
|
83
|
+
* As when continously clicking on drag handle on different rows/columns,
|
|
84
|
+
* should open the menu corresponding to the position of the drag handle.
|
|
85
|
+
* @returns true when the menu should be closed, false otherwise
|
|
86
|
+
*/
|
|
87
|
+
const shouldCloseMenu = state => {
|
|
88
|
+
let {
|
|
89
|
+
isDragMenuOpen: previousOpenState,
|
|
90
|
+
dragMenuDirection: previousDragMenuDirection,
|
|
91
|
+
dragMenuIndex: previousDragMenuIndex
|
|
92
|
+
} = getPluginState(state);
|
|
93
|
+
|
|
94
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
95
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
96
|
+
// 2 scenarios above , menu should not be closed.
|
|
97
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
98
|
+
return false;
|
|
99
|
+
} else {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
79
103
|
const closeMenu = () => {
|
|
80
104
|
const {
|
|
81
105
|
state,
|
|
82
106
|
dispatch
|
|
83
107
|
} = editorView;
|
|
84
|
-
|
|
108
|
+
if (shouldCloseMenu(state)) {
|
|
109
|
+
toggleDragMenu(false, direction, index)(state, dispatch);
|
|
110
|
+
}
|
|
85
111
|
};
|
|
86
112
|
const handleMenuItemActivated = ({
|
|
87
113
|
item
|
|
@@ -82,17 +82,30 @@ export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, i
|
|
|
82
82
|
return createCommand(function (state) {
|
|
83
83
|
var _getPluginState3 = getPluginState(state),
|
|
84
84
|
previousOpenState = _getPluginState3.isDragMenuOpen,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (previousOpenState === isDragMenuOpen) {
|
|
85
|
+
previousDragMenuDirection = _getPluginState3.dragMenuDirection,
|
|
86
|
+
previousDragMenuIndex = _getPluginState3.dragMenuIndex;
|
|
87
|
+
if (previousOpenState === isDragMenuOpen && previousDragMenuDirection === direction && previousDragMenuIndex === index) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
|
+
var updatedMenuOpenState;
|
|
91
|
+
if (isDragMenuOpen !== undefined) {
|
|
92
|
+
updatedMenuOpenState = isDragMenuOpen;
|
|
93
|
+
} else {
|
|
94
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
95
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
96
|
+
// 2 scenarios above , menu should remain open.
|
|
97
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
98
|
+
updatedMenuOpenState = true;
|
|
99
|
+
} else {
|
|
100
|
+
updatedMenuOpenState = !previousOpenState;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
90
103
|
return {
|
|
91
104
|
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
92
105
|
data: {
|
|
93
|
-
isDragMenuOpen:
|
|
94
|
-
direction: direction !== null && direction !== void 0 ? direction :
|
|
95
|
-
index: index !== null && index !== void 0 ? index :
|
|
106
|
+
isDragMenuOpen: updatedMenuOpenState,
|
|
107
|
+
direction: direction !== null && direction !== void 0 ? direction : previousDragMenuDirection,
|
|
108
|
+
index: index !== null && index !== void 0 ? index : previousDragMenuIndex
|
|
96
109
|
}
|
|
97
110
|
};
|
|
98
111
|
}, function (tr) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
4
5
|
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
5
6
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
7
|
import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
|
|
@@ -49,7 +50,11 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
49
50
|
};
|
|
50
51
|
if (newTargetCellPosition !== undefined) {
|
|
51
52
|
var cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
52
|
-
|
|
53
|
+
// ED-20673 check if it is a cell selection,
|
|
54
|
+
// when true, a drag handle is clicked and isDragMenuOpen is true here
|
|
55
|
+
// should not close the drag menu.
|
|
56
|
+
var isCellSelection = tr.selection instanceof CellSelection;
|
|
57
|
+
if (cells && cells.length && cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) && !isCellSelection) {
|
|
53
58
|
return tr.setMeta(pluginKey, action);
|
|
54
59
|
} // else NOP
|
|
55
60
|
} else {
|
|
@@ -61,52 +61,19 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// updating all cells with new attributes
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
74
|
-
}
|
|
75
|
-
seen[pos] = true;
|
|
64
|
+
var seen = {};
|
|
65
|
+
for (var _rowIndex = 0; _rowIndex < map.height; _rowIndex++) {
|
|
66
|
+
for (var _columnIndex = 0; _columnIndex < map.width; _columnIndex++) {
|
|
67
|
+
var _mapIndex = _rowIndex * map.width + _columnIndex;
|
|
68
|
+
var pos = map.map[_mapIndex];
|
|
69
|
+
var cell = table.nodeAt(pos);
|
|
70
|
+
if (!seen[pos] && cell) {
|
|
71
|
+
if (updatedCellsAttrs[pos]) {
|
|
72
|
+
tr.step(new AttrStep(pos + start, 'colwidth', updatedCellsAttrs[pos].colwidth));
|
|
76
73
|
}
|
|
74
|
+
seen[pos] = true;
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
} else {
|
|
80
|
-
var rows = [];
|
|
81
|
-
var _seen = {};
|
|
82
|
-
for (var _rowIndex2 = 0; _rowIndex2 < map.height; _rowIndex2++) {
|
|
83
|
-
var row = table.child(_rowIndex2);
|
|
84
|
-
var cells = [];
|
|
85
|
-
for (var _columnIndex2 = 0; _columnIndex2 < map.width; _columnIndex2++) {
|
|
86
|
-
var _mapIndex2 = _rowIndex2 * map.width + _columnIndex2;
|
|
87
|
-
var _pos = map.map[_mapIndex2];
|
|
88
|
-
var _cell = table.nodeAt(_pos);
|
|
89
|
-
if (!_seen[_pos] && _cell) {
|
|
90
|
-
cells.push(_cell.type.createChecked(updatedCellsAttrs[_pos] || _cell.attrs, _cell.content, _cell.marks));
|
|
91
|
-
_seen[_pos] = true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
95
|
-
}
|
|
96
|
-
var tablePos = start - 1;
|
|
97
|
-
var selectionBookmark = tr.selection.getBookmark();
|
|
98
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
99
|
-
/**
|
|
100
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
101
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
102
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
103
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
104
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
105
|
-
* bookmark of selection.
|
|
106
|
-
*
|
|
107
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
108
|
-
*/
|
|
109
|
-
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
110
77
|
}
|
|
111
78
|
return tr;
|
|
112
79
|
};
|
|
@@ -7,6 +7,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
7
7
|
import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
|
|
9
9
|
import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
|
|
10
|
+
import { getPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
|
|
10
11
|
import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
|
|
11
12
|
import { getDragMenuConfig } from '../../utils/drag-menu';
|
|
12
13
|
import { dragMenuDropdownWidth } from '../consts';
|
|
@@ -76,10 +77,34 @@ export var DragMenu = function DragMenu(_ref) {
|
|
|
76
77
|
var _convertToDropdownIte = convertToDropdownItems(dragMenuConfig),
|
|
77
78
|
menuItems = _convertToDropdownIte.menuItems,
|
|
78
79
|
menuCallback = _convertToDropdownIte.menuCallback;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* This function is to check if the menu should be closed or not.
|
|
83
|
+
* As when continously clicking on drag handle on different rows/columns,
|
|
84
|
+
* should open the menu corresponding to the position of the drag handle.
|
|
85
|
+
* @returns true when the menu should be closed, false otherwise
|
|
86
|
+
*/
|
|
87
|
+
var shouldCloseMenu = function shouldCloseMenu(state) {
|
|
88
|
+
var _getPluginState = getPluginState(state),
|
|
89
|
+
previousOpenState = _getPluginState.isDragMenuOpen,
|
|
90
|
+
previousDragMenuDirection = _getPluginState.dragMenuDirection,
|
|
91
|
+
previousDragMenuIndex = _getPluginState.dragMenuIndex;
|
|
92
|
+
|
|
93
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
94
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
95
|
+
// 2 scenarios above , menu should not be closed.
|
|
96
|
+
if (previousOpenState === true && previousDragMenuDirection !== direction || previousOpenState === true && previousDragMenuDirection === direction && previousDragMenuIndex !== index) {
|
|
97
|
+
return false;
|
|
98
|
+
} else {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
79
102
|
var closeMenu = function closeMenu() {
|
|
80
103
|
var state = editorView.state,
|
|
81
104
|
dispatch = editorView.dispatch;
|
|
82
|
-
|
|
105
|
+
if (shouldCloseMenu(state)) {
|
|
106
|
+
toggleDragMenu(false, direction, index)(state, dispatch);
|
|
107
|
+
}
|
|
83
108
|
};
|
|
84
109
|
var handleMenuItemActivated = function handleMenuItemActivated(_ref2) {
|
|
85
110
|
var _menuCallback$item$va;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.26",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^32.0.0",
|
|
31
31
|
"@atlaskit/custom-steps": "^0.0.2",
|
|
32
|
-
"@atlaskit/editor-common": "^76.
|
|
32
|
+
"@atlaskit/editor-common": "^76.19.0",
|
|
33
33
|
"@atlaskit/editor-palette": "1.5.2",
|
|
34
34
|
"@atlaskit/editor-plugin-analytics": "^0.3.0",
|
|
35
35
|
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
@@ -118,9 +118,6 @@
|
|
|
118
118
|
"platform.editor.table.column-controls-styles-updated": {
|
|
119
119
|
"type": "boolean"
|
|
120
120
|
},
|
|
121
|
-
"platform.editor.update-table-cell-width-via-step": {
|
|
122
|
-
"type": "boolean"
|
|
123
|
-
},
|
|
124
121
|
"platform.editor.resizing-table-height-improvement": {
|
|
125
122
|
"type": "boolean"
|
|
126
123
|
},
|
|
@@ -131,20 +131,44 @@ export const toggleDragMenu = (
|
|
|
131
131
|
(state) => {
|
|
132
132
|
let {
|
|
133
133
|
isDragMenuOpen: previousOpenState,
|
|
134
|
-
dragMenuDirection,
|
|
135
|
-
dragMenuIndex,
|
|
134
|
+
dragMenuDirection: previousDragMenuDirection,
|
|
135
|
+
dragMenuIndex: previousDragMenuIndex,
|
|
136
136
|
} = getPluginState(state);
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
previousOpenState === isDragMenuOpen &&
|
|
140
|
+
previousDragMenuDirection === direction &&
|
|
141
|
+
previousDragMenuIndex === index
|
|
142
|
+
) {
|
|
138
143
|
return false;
|
|
139
144
|
}
|
|
140
145
|
|
|
146
|
+
let updatedMenuOpenState;
|
|
147
|
+
if (isDragMenuOpen !== undefined) {
|
|
148
|
+
updatedMenuOpenState = isDragMenuOpen;
|
|
149
|
+
} else {
|
|
150
|
+
// menu open but menu direction changed, means user clicked on drag handle of different row/column
|
|
151
|
+
// menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
|
|
152
|
+
// 2 scenarios above , menu should remain open.
|
|
153
|
+
if (
|
|
154
|
+
(previousOpenState === true &&
|
|
155
|
+
previousDragMenuDirection !== direction) ||
|
|
156
|
+
(previousOpenState === true &&
|
|
157
|
+
previousDragMenuDirection === direction &&
|
|
158
|
+
previousDragMenuIndex !== index)
|
|
159
|
+
) {
|
|
160
|
+
updatedMenuOpenState = true;
|
|
161
|
+
} else {
|
|
162
|
+
updatedMenuOpenState = !previousOpenState;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
141
166
|
return {
|
|
142
167
|
type: DragAndDropActionType.TOGGLE_DRAG_MENU,
|
|
143
168
|
data: {
|
|
144
|
-
isDragMenuOpen:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
index: index ?? dragMenuIndex,
|
|
169
|
+
isDragMenuOpen: updatedMenuOpenState,
|
|
170
|
+
direction: direction ?? previousDragMenuDirection,
|
|
171
|
+
index: index ?? previousDragMenuIndex,
|
|
148
172
|
},
|
|
149
173
|
};
|
|
150
174
|
},
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
+
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
8
9
|
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
9
10
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
10
11
|
import { autoScroller } from '@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-autoscroll';
|
|
@@ -65,10 +66,15 @@ export const createPlugin = (
|
|
|
65
66
|
|
|
66
67
|
if (newTargetCellPosition !== undefined) {
|
|
67
68
|
const cells = getCellsInRow(dragMenuIndex)(tr.selection);
|
|
69
|
+
// ED-20673 check if it is a cell selection,
|
|
70
|
+
// when true, a drag handle is clicked and isDragMenuOpen is true here
|
|
71
|
+
// should not close the drag menu.
|
|
72
|
+
const isCellSelection = tr.selection instanceof CellSelection;
|
|
68
73
|
if (
|
|
69
74
|
cells &&
|
|
70
75
|
cells.length &&
|
|
71
|
-
cells[0].node !== tr.doc.nodeAt(newTargetCellPosition)
|
|
76
|
+
cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) &&
|
|
77
|
+
!isCellSelection
|
|
72
78
|
) {
|
|
73
79
|
return tr.setMeta(pluginKey, action);
|
|
74
80
|
} // else NOP
|