@atlaskit/editor-plugin-table 5.3.34 → 5.3.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/plugins/table/event-handlers.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +10 -4
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
- package/dist/cjs/plugins/table/utils/drag-menu.js +3 -1
- package/dist/cjs/plugins/table/utils/transforms.js +11 -0
- package/dist/es2019/plugins/table/event-handlers.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +8 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
- package/dist/es2019/plugins/table/utils/drag-menu.js +3 -1
- package/dist/es2019/plugins/table/utils/transforms.js +5 -0
- package/dist/esm/plugins/table/event-handlers.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +10 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +5 -2
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +4 -2
- package/dist/esm/plugins/table/utils/drag-menu.js +3 -1
- package/dist/esm/plugins/table/utils/transforms.js +5 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
- package/dist/types/plugins/table/utils/transforms.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/transforms.d.ts +2 -0
- package/package.json +2 -2
- package/src/plugins/table/event-handlers.ts +4 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +26 -4
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +9 -5
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +1 -0
- package/src/plugins/table/utils/drag-menu.ts +7 -5
- package/src/plugins/table/utils/transforms.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.3.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#43255](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43255) [`404fa3bc44e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/404fa3bc44e) - Add requestAnimationFrame around move row/column command to fix an issue where selection would be lost
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
3
10
|
## 5.3.34
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -359,7 +359,7 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
|
359
359
|
};
|
|
360
360
|
var withCellTracking = exports.withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
|
|
361
361
|
return function (view, mouseEvent) {
|
|
362
|
-
if ((0, _pluginFactory2.getPluginState)(view.state).isDragAndDropEnabled) {
|
|
362
|
+
if ((0, _pluginFactory2.getPluginState)(view.state).isDragAndDropEnabled && !(0, _pluginFactory.getPluginState)(view.state).isDragging) {
|
|
363
363
|
trackCellLocation(view, mouseEvent);
|
|
364
364
|
}
|
|
365
365
|
return eventHandler(view, mouseEvent, elementContentRects);
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.updatePluginStateDecorations = exports.toggleDragMenu = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.clearDropTarget = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
7
8
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
8
9
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
9
10
|
var _types = require("../../types");
|
|
10
11
|
var _utils2 = require("../../utils");
|
|
12
|
+
var _transforms = require("../../utils/transforms");
|
|
11
13
|
var _actions = require("./actions");
|
|
12
14
|
var _consts = require("./consts");
|
|
13
15
|
var _pluginFactory = require("./plugin-factory");
|
|
@@ -76,11 +78,15 @@ var moveSource = exports.moveSource = function moveSource(sourceType, sourceInde
|
|
|
76
78
|
if (sourceIndex === targetIndex) {
|
|
77
79
|
return tr.setMeta('addToHistory', false);
|
|
78
80
|
}
|
|
81
|
+
var anchor = tr.selection.anchor;
|
|
82
|
+
var selectStartOfTable = function selectStartOfTable(newTr) {
|
|
83
|
+
return newTr.setSelection(_state.TextSelection.create(newTr.doc, anchor));
|
|
84
|
+
};
|
|
79
85
|
var isTableRow = sourceType === 'table-row';
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return
|
|
86
|
+
if (isTableRow) {
|
|
87
|
+
return (0, _transforms.combineTransforms)([(0, _utils.moveRow)(sourceIndex, targetIndex), selectStartOfTable, (0, _utils.selectRow)(targetIndex)], tr);
|
|
88
|
+
}
|
|
89
|
+
return (0, _transforms.combineTransforms)([(0, _utils.moveColumn)(sourceIndex, targetIndex), selectStartOfTable, (0, _utils.selectColumn)(targetIndex)], tr);
|
|
84
90
|
});
|
|
85
91
|
};
|
|
86
92
|
var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
|
|
@@ -27,7 +27,8 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
27
27
|
dropTargetType: _consts.DropTargetType.NONE,
|
|
28
28
|
dropTargetIndex: 0,
|
|
29
29
|
isDragMenuOpen: false,
|
|
30
|
-
dragMenuIndex: 0
|
|
30
|
+
dragMenuIndex: 0,
|
|
31
|
+
isDragging: false
|
|
31
32
|
};
|
|
32
33
|
}),
|
|
33
34
|
key: _pluginKey.pluginKey,
|
|
@@ -132,7 +133,9 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
132
133
|
}
|
|
133
134
|
var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
|
|
134
135
|
sourceIndex = _sourceIndexes[0];
|
|
135
|
-
(
|
|
136
|
+
requestAnimationFrame(function () {
|
|
137
|
+
(0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
|
|
138
|
+
});
|
|
136
139
|
}
|
|
137
140
|
})
|
|
138
141
|
};
|
|
@@ -16,13 +16,15 @@ var _default = exports.default = function _default(pluginState, action) {
|
|
|
16
16
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
17
17
|
decorationSet: action.data.decorationSet,
|
|
18
18
|
dropTargetType: action.data.type,
|
|
19
|
-
dropTargetIndex: action.data.index
|
|
19
|
+
dropTargetIndex: action.data.index,
|
|
20
|
+
isDragging: true
|
|
20
21
|
});
|
|
21
22
|
case _actions.DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
22
23
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
23
24
|
decorationSet: action.data.decorationSet,
|
|
24
25
|
dropTargetType: _consts.DropTargetType.NONE,
|
|
25
|
-
dropTargetIndex: 0
|
|
26
|
+
dropTargetIndex: 0,
|
|
27
|
+
isDragging: false
|
|
26
28
|
});
|
|
27
29
|
case _actions.DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
28
30
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
@@ -148,7 +148,9 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
148
148
|
icon: icon,
|
|
149
149
|
onClick: function onClick(state, dispatch) {
|
|
150
150
|
if (canMove(index)) {
|
|
151
|
-
(
|
|
151
|
+
requestAnimationFrame(function () {
|
|
152
|
+
(0, _commands2.moveSource)("table-".concat(direction), index, index + offset)(state, dispatch);
|
|
153
|
+
});
|
|
152
154
|
return true;
|
|
153
155
|
}
|
|
154
156
|
return false;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.combineTransforms = void 0;
|
|
7
|
+
var combineTransforms = exports.combineTransforms = function combineTransforms(transforms, tr) {
|
|
8
|
+
return transforms.reduce(function (prev, curr) {
|
|
9
|
+
return curr(prev);
|
|
10
|
+
}, tr);
|
|
11
|
+
};
|
|
@@ -366,7 +366,7 @@ const trackCellLocation = (view, mouseEvent) => {
|
|
|
366
366
|
}
|
|
367
367
|
};
|
|
368
368
|
export const withCellTracking = (eventHandler, elementContentRects) => (view, mouseEvent) => {
|
|
369
|
-
if (getPluginState(view.state).isDragAndDropEnabled) {
|
|
369
|
+
if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
|
|
370
370
|
trackCellLocation(view, mouseEvent);
|
|
371
371
|
}
|
|
372
372
|
return eventHandler(view, mouseEvent, elementContentRects);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
1
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
3
|
import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
|
|
3
4
|
import { TableDecorations } from '../../types';
|
|
4
5
|
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
6
|
+
import { combineTransforms } from '../../utils/transforms';
|
|
5
7
|
import { DragAndDropActionType } from './actions';
|
|
6
8
|
import { DropTargetType } from './consts';
|
|
7
9
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
@@ -62,11 +64,13 @@ export const moveSource = (sourceType, sourceIndex, targetIndex) => createComman
|
|
|
62
64
|
if (sourceIndex === targetIndex) {
|
|
63
65
|
return tr.setMeta('addToHistory', false);
|
|
64
66
|
}
|
|
67
|
+
const anchor = tr.selection.anchor;
|
|
68
|
+
const selectStartOfTable = newTr => newTr.setSelection(TextSelection.create(newTr.doc, anchor));
|
|
65
69
|
const isTableRow = sourceType === 'table-row';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
+
if (isTableRow) {
|
|
71
|
+
return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], tr);
|
|
72
|
+
}
|
|
73
|
+
return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], tr);
|
|
70
74
|
});
|
|
71
75
|
export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
|
|
72
76
|
let {
|
|
@@ -18,7 +18,8 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
18
18
|
dropTargetType: DropTargetType.NONE,
|
|
19
19
|
dropTargetIndex: 0,
|
|
20
20
|
isDragMenuOpen: false,
|
|
21
|
-
dragMenuIndex: 0
|
|
21
|
+
dragMenuIndex: 0,
|
|
22
|
+
isDragging: false
|
|
22
23
|
})),
|
|
23
24
|
key: pluginKey,
|
|
24
25
|
appendTransaction: (transactions, oldState, newState) => {
|
|
@@ -132,7 +133,9 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
const [sourceIndex] = sourceIndexes;
|
|
135
|
-
|
|
136
|
+
requestAnimationFrame(() => {
|
|
137
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
|
|
138
|
+
});
|
|
136
139
|
}
|
|
137
140
|
})
|
|
138
141
|
};
|
|
@@ -7,14 +7,16 @@ export default ((pluginState, action) => {
|
|
|
7
7
|
...pluginState,
|
|
8
8
|
decorationSet: action.data.decorationSet,
|
|
9
9
|
dropTargetType: action.data.type,
|
|
10
|
-
dropTargetIndex: action.data.index
|
|
10
|
+
dropTargetIndex: action.data.index,
|
|
11
|
+
isDragging: true
|
|
11
12
|
};
|
|
12
13
|
case DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
13
14
|
return {
|
|
14
15
|
...pluginState,
|
|
15
16
|
decorationSet: action.data.decorationSet,
|
|
16
17
|
dropTargetType: DropTargetType.NONE,
|
|
17
|
-
dropTargetIndex: 0
|
|
18
|
+
dropTargetIndex: 0,
|
|
19
|
+
isDragging: false
|
|
18
20
|
};
|
|
19
21
|
case DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
20
22
|
return {
|
|
@@ -133,7 +133,9 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, tableMap,
|
|
|
133
133
|
icon,
|
|
134
134
|
onClick: (state, dispatch) => {
|
|
135
135
|
if (canMove(index)) {
|
|
136
|
-
|
|
136
|
+
requestAnimationFrame(() => {
|
|
137
|
+
moveSource(`table-${direction}`, index, index + offset)(state, dispatch);
|
|
138
|
+
});
|
|
137
139
|
return true;
|
|
138
140
|
}
|
|
139
141
|
return false;
|
|
@@ -350,7 +350,7 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
|
350
350
|
};
|
|
351
351
|
export var withCellTracking = function withCellTracking(eventHandler, elementContentRects) {
|
|
352
352
|
return function (view, mouseEvent) {
|
|
353
|
-
if (getPluginState(view.state).isDragAndDropEnabled) {
|
|
353
|
+
if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
|
|
354
354
|
trackCellLocation(view, mouseEvent);
|
|
355
355
|
}
|
|
356
356
|
return eventHandler(view, mouseEvent, elementContentRects);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
1
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
3
|
import { moveColumn, moveRow, selectColumn, selectRow } from '@atlaskit/editor-tables/utils';
|
|
3
4
|
import { TableDecorations } from '../../types';
|
|
4
5
|
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
6
|
+
import { combineTransforms } from '../../utils/transforms';
|
|
5
7
|
import { DragAndDropActionType } from './actions';
|
|
6
8
|
import { DropTargetType } from './consts';
|
|
7
9
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
@@ -71,11 +73,15 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
|
|
|
71
73
|
if (sourceIndex === targetIndex) {
|
|
72
74
|
return tr.setMeta('addToHistory', false);
|
|
73
75
|
}
|
|
76
|
+
var anchor = tr.selection.anchor;
|
|
77
|
+
var selectStartOfTable = function selectStartOfTable(newTr) {
|
|
78
|
+
return newTr.setSelection(TextSelection.create(newTr.doc, anchor));
|
|
79
|
+
};
|
|
74
80
|
var isTableRow = sourceType === 'table-row';
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return
|
|
81
|
+
if (isTableRow) {
|
|
82
|
+
return combineTransforms([moveRow(sourceIndex, targetIndex), selectStartOfTable, selectRow(targetIndex)], tr);
|
|
83
|
+
}
|
|
84
|
+
return combineTransforms([moveColumn(sourceIndex, targetIndex), selectStartOfTable, selectColumn(targetIndex)], tr);
|
|
79
85
|
});
|
|
80
86
|
};
|
|
81
87
|
export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
|
|
@@ -20,7 +20,8 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
20
20
|
dropTargetType: DropTargetType.NONE,
|
|
21
21
|
dropTargetIndex: 0,
|
|
22
22
|
isDragMenuOpen: false,
|
|
23
|
-
dragMenuIndex: 0
|
|
23
|
+
dragMenuIndex: 0,
|
|
24
|
+
isDragging: false
|
|
24
25
|
};
|
|
25
26
|
}),
|
|
26
27
|
key: pluginKey,
|
|
@@ -125,7 +126,9 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
125
126
|
}
|
|
126
127
|
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
127
128
|
sourceIndex = _sourceIndexes[0];
|
|
128
|
-
|
|
129
|
+
requestAnimationFrame(function () {
|
|
130
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1))(editorView.state, editorView.dispatch);
|
|
131
|
+
});
|
|
129
132
|
}
|
|
130
133
|
})
|
|
131
134
|
};
|
|
@@ -9,13 +9,15 @@ export default (function (pluginState, action) {
|
|
|
9
9
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
10
10
|
decorationSet: action.data.decorationSet,
|
|
11
11
|
dropTargetType: action.data.type,
|
|
12
|
-
dropTargetIndex: action.data.index
|
|
12
|
+
dropTargetIndex: action.data.index,
|
|
13
|
+
isDragging: true
|
|
13
14
|
});
|
|
14
15
|
case DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
15
16
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
16
17
|
decorationSet: action.data.decorationSet,
|
|
17
18
|
dropTargetType: DropTargetType.NONE,
|
|
18
|
-
dropTargetIndex: 0
|
|
19
|
+
dropTargetIndex: 0,
|
|
20
|
+
isDragging: false
|
|
19
21
|
});
|
|
20
22
|
case DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
21
23
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
@@ -141,7 +141,9 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
|
|
|
141
141
|
icon: icon,
|
|
142
142
|
onClick: function onClick(state, dispatch) {
|
|
143
143
|
if (canMove(index)) {
|
|
144
|
-
|
|
144
|
+
requestAnimationFrame(function () {
|
|
145
|
+
moveSource("table-".concat(direction), index, index + offset)(state, dispatch);
|
|
146
|
+
});
|
|
145
147
|
return true;
|
|
146
148
|
}
|
|
147
149
|
return false;
|
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.35",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@atlaskit/pragmatic-drag-and-drop": "^0.24.0",
|
|
45
45
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.7.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
|
|
47
|
-
"@atlaskit/primitives": "^1.
|
|
47
|
+
"@atlaskit/primitives": "^1.11.0",
|
|
48
48
|
"@atlaskit/theme": "^12.6.0",
|
|
49
49
|
"@atlaskit/tokens": "^1.28.0",
|
|
50
50
|
"@atlaskit/tooltip": "^18.0.0",
|
|
@@ -587,7 +587,10 @@ export const withCellTracking =
|
|
|
587
587
|
elementContentRects?: ElementContentRects,
|
|
588
588
|
) =>
|
|
589
589
|
(view: EditorView, mouseEvent: Event): boolean => {
|
|
590
|
-
if (
|
|
590
|
+
if (
|
|
591
|
+
getPluginState(view.state).isDragAndDropEnabled &&
|
|
592
|
+
!getDragDropPluginState(view.state).isDragging
|
|
593
|
+
) {
|
|
591
594
|
trackCellLocation(view, mouseEvent);
|
|
592
595
|
}
|
|
593
596
|
return eventHandler(view, mouseEvent, elementContentRects);
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
EditorState,
|
|
3
3
|
Transaction,
|
|
4
4
|
} from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import type { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
6
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
8
|
import {
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
createRowInsertLine,
|
|
19
20
|
updateDecorations,
|
|
20
21
|
} from '../../utils';
|
|
22
|
+
import { combineTransforms } from '../../utils/transforms';
|
|
21
23
|
|
|
22
24
|
import { DragAndDropActionType } from './actions';
|
|
23
25
|
import { DropTargetType } from './consts';
|
|
@@ -114,11 +116,31 @@ export const moveSource = (
|
|
|
114
116
|
return tr.setMeta('addToHistory', false);
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
const anchor = tr.selection.anchor;
|
|
120
|
+
const selectStartOfTable = (newTr: Transaction) =>
|
|
121
|
+
newTr.setSelection(TextSelection.create(newTr.doc, anchor));
|
|
122
|
+
|
|
117
123
|
const isTableRow = sourceType === 'table-row';
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
|
|
125
|
+
if (isTableRow) {
|
|
126
|
+
return combineTransforms(
|
|
127
|
+
[
|
|
128
|
+
moveRow(sourceIndex, targetIndex),
|
|
129
|
+
selectStartOfTable,
|
|
130
|
+
selectRow(targetIndex),
|
|
131
|
+
],
|
|
132
|
+
tr,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return combineTransforms(
|
|
137
|
+
[
|
|
138
|
+
moveColumn(sourceIndex, targetIndex),
|
|
139
|
+
selectStartOfTable,
|
|
140
|
+
selectColumn(targetIndex),
|
|
141
|
+
],
|
|
142
|
+
tr,
|
|
143
|
+
);
|
|
122
144
|
},
|
|
123
145
|
);
|
|
124
146
|
|
|
@@ -39,6 +39,7 @@ export const createPlugin = (
|
|
|
39
39
|
dropTargetIndex: 0,
|
|
40
40
|
isDragMenuOpen: false,
|
|
41
41
|
dragMenuIndex: 0,
|
|
42
|
+
isDragging: false,
|
|
42
43
|
})),
|
|
43
44
|
key: pluginKey,
|
|
44
45
|
appendTransaction: (transactions, oldState, newState) => {
|
|
@@ -160,11 +161,14 @@ export const createPlugin = (
|
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
const [sourceIndex] = sourceIndexes;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
|
|
165
|
+
requestAnimationFrame(() => {
|
|
166
|
+
moveSource(
|
|
167
|
+
sourceType,
|
|
168
|
+
sourceIndex,
|
|
169
|
+
targetAdjustedIndex + (direction === -1 ? 0 : -1),
|
|
170
|
+
)(editorView.state, editorView.dispatch);
|
|
171
|
+
});
|
|
168
172
|
},
|
|
169
173
|
}),
|
|
170
174
|
};
|
|
@@ -14,6 +14,7 @@ export default (
|
|
|
14
14
|
decorationSet: action.data.decorationSet,
|
|
15
15
|
dropTargetType: action.data.type,
|
|
16
16
|
dropTargetIndex: action.data.index,
|
|
17
|
+
isDragging: true,
|
|
17
18
|
};
|
|
18
19
|
case DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
19
20
|
return {
|
|
@@ -21,6 +22,7 @@ export default (
|
|
|
21
22
|
decorationSet: action.data.decorationSet,
|
|
22
23
|
dropTargetType: DropTargetType.NONE,
|
|
23
24
|
dropTargetIndex: 0,
|
|
25
|
+
isDragging: false,
|
|
24
26
|
};
|
|
25
27
|
case DragAndDropActionType.TOGGLE_DRAG_MENU:
|
|
26
28
|
return {
|
|
@@ -194,11 +194,13 @@ export const getDragMenuConfig = (
|
|
|
194
194
|
icon,
|
|
195
195
|
onClick: (state: EditorState, dispatch?: CommandDispatch) => {
|
|
196
196
|
if (canMove(index)) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
requestAnimationFrame(() => {
|
|
198
|
+
moveSource(
|
|
199
|
+
`table-${direction}`,
|
|
200
|
+
index!,
|
|
201
|
+
index! + offset,
|
|
202
|
+
)(state, dispatch);
|
|
203
|
+
});
|
|
202
204
|
return true;
|
|
203
205
|
}
|
|
204
206
|
return false;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
|
|
3
|
+
export const combineTransforms = (
|
|
4
|
+
transforms: Array<(tr: Transaction) => Transaction>,
|
|
5
|
+
tr: Transaction,
|
|
6
|
+
) => {
|
|
7
|
+
return transforms.reduce((prev, curr) => {
|
|
8
|
+
return curr(prev);
|
|
9
|
+
}, tr);
|
|
10
|
+
};
|