@atlaskit/editor-plugin-table 6.0.0 → 6.1.0
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 +10 -0
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +16 -12
- package/dist/cjs/pm-plugins/drag-and-drop/commands.js +5 -5
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +4 -6
- package/dist/cjs/utils/drag-menu.js +1 -1
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +12 -12
- package/dist/es2019/pm-plugins/drag-and-drop/commands.js +5 -5
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +4 -4
- package/dist/es2019/utils/drag-menu.js +1 -1
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +15 -12
- package/dist/esm/pm-plugins/drag-and-drop/commands.js +5 -5
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +4 -6
- package/dist/esm/utils/drag-menu.js +1 -1
- package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +2 -2
- package/dist/types/pm-plugins/drag-and-drop/commands.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands.d.ts +1 -1
- package/package.json +5 -5
- package/src/__tests__/unit/analytics.ts +53 -17
- package/src/__tests__/visual-regression/index.ts +3 -1
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +13 -14
- package/src/pm-plugins/drag-and-drop/commands.ts +5 -6
- package/src/pm-plugins/drag-and-drop/plugin.ts +3 -3
- package/src/utils/drag-menu.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 6.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#67400](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/67400) [`191436e36f93`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/191436e36f93) - Optimised the table move row logic to perform insert/delete steps rather than an entire table replacement
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 6.0.0
|
|
4
14
|
|
|
5
15
|
### Major Changes
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalytics = exports.clearDropTargetWithAnalytics = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
10
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
9
11
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
@@ -11,8 +13,9 @@ var _utils2 = require("../../utils");
|
|
|
11
13
|
var _analytics2 = require("../../utils/analytics");
|
|
12
14
|
var _commands = require("./commands");
|
|
13
15
|
var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
|
|
14
|
-
return function (inputMethod, sourceType, status, tr) {
|
|
16
|
+
return function (inputMethod, sourceType, sourceIndexes, status, tr) {
|
|
15
17
|
return (0, _analytics2.withEditorAnalyticsAPI)(function (_ref) {
|
|
18
|
+
var _sourceIndexes$length;
|
|
16
19
|
var selection = _ref.selection;
|
|
17
20
|
var _getSelectedTableInfo = (0, _utils2.getSelectedTableInfo)(selection),
|
|
18
21
|
totalRowCount = _getSelectedTableInfo.totalRowCount,
|
|
@@ -23,8 +26,7 @@ var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = functi
|
|
|
23
26
|
actionSubjectId: null,
|
|
24
27
|
attributes: {
|
|
25
28
|
inputMethod: inputMethod,
|
|
26
|
-
|
|
27
|
-
count: 1,
|
|
29
|
+
count: (_sourceIndexes$length = sourceIndexes === null || sourceIndexes === void 0 ? void 0 : sourceIndexes.length) !== null && _sourceIndexes$length !== void 0 ? _sourceIndexes$length : 0,
|
|
28
30
|
distance: 0,
|
|
29
31
|
status: status,
|
|
30
32
|
totalRowCount: totalRowCount,
|
|
@@ -41,7 +43,7 @@ var clearDropTargetWithAnalytics = exports.clearDropTargetWithAnalytics = functi
|
|
|
41
43
|
};
|
|
42
44
|
};
|
|
43
45
|
var moveSourceWithAnalytics = exports.moveSourceWithAnalytics = function moveSourceWithAnalytics(editorAnalyticsAPI) {
|
|
44
|
-
return function (inputMethod, sourceType,
|
|
46
|
+
return function (inputMethod, sourceType, sourceIndexes, targetIndex, tr) {
|
|
45
47
|
return (0, _analytics2.withEditorAnalyticsAPI)(function (_ref2) {
|
|
46
48
|
var selection = _ref2.selection;
|
|
47
49
|
var _getSelectedTableInfo2 = (0, _utils2.getSelectedTableInfo)(selection),
|
|
@@ -53,12 +55,14 @@ var moveSourceWithAnalytics = exports.moveSourceWithAnalytics = function moveSou
|
|
|
53
55
|
actionSubjectId: null,
|
|
54
56
|
attributes: {
|
|
55
57
|
inputMethod: inputMethod,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// This
|
|
59
|
-
distance:
|
|
58
|
+
count: sourceIndexes.length,
|
|
59
|
+
// This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
|
|
60
|
+
// of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
|
|
61
|
+
distance: Math.min.apply(Math, (0, _toConsumableArray2.default)(sourceIndexes.map(function (v) {
|
|
62
|
+
return targetIndex - v;
|
|
63
|
+
}))),
|
|
60
64
|
// If a drop doesn't actually change anything then we're going to mark the event as cancelled.
|
|
61
|
-
status:
|
|
65
|
+
status: sourceIndexes.includes(targetIndex) ? _analytics.TABLE_STATUS.CANCELLED : _analytics.TABLE_STATUS.SUCCESS,
|
|
62
66
|
totalRowCount: totalRowCount,
|
|
63
67
|
totalColumnCount: totalColumnCount
|
|
64
68
|
},
|
|
@@ -66,7 +70,7 @@ var moveSourceWithAnalytics = exports.moveSourceWithAnalytics = function moveSou
|
|
|
66
70
|
};
|
|
67
71
|
})(editorAnalyticsAPI)(function (state, dispatch) {
|
|
68
72
|
if (dispatch) {
|
|
69
|
-
(0, _commands.moveSource)(sourceType,
|
|
73
|
+
(0, _commands.moveSource)(sourceType, sourceIndexes, targetIndex, tr)(state, dispatch);
|
|
70
74
|
}
|
|
71
75
|
return true;
|
|
72
76
|
});
|
|
@@ -84,7 +88,7 @@ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShort
|
|
|
84
88
|
var isRow = sourceType === 'table-row';
|
|
85
89
|
var selectedIndexes = isRow ? (0, _utils2.getSelectedRowIndexes)(selectionRect) : (0, _utils2.getSelectedColumnIndexes)(selectionRect);
|
|
86
90
|
|
|
87
|
-
// We can move if only one row/column selected
|
|
91
|
+
// FIXME: We can move if only one row/column selected
|
|
88
92
|
if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
|
|
89
93
|
return false;
|
|
90
94
|
}
|
|
@@ -111,7 +115,7 @@ var moveSourceWithAnalyticsViaShortcut = exports.moveSourceWithAnalyticsViaShort
|
|
|
111
115
|
if (hasMergedCellsInTarget) {
|
|
112
116
|
return false;
|
|
113
117
|
}
|
|
114
|
-
return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, sourceIndex, targetIndex)(state, dispatch);
|
|
118
|
+
return moveSourceWithAnalytics(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT, sourceType, [sourceIndex], targetIndex)(state, dispatch);
|
|
115
119
|
};
|
|
116
120
|
};
|
|
117
121
|
};
|
|
@@ -66,7 +66,7 @@ var clearDropTarget = exports.clearDropTarget = function clearDropTarget(tr) {
|
|
|
66
66
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
|
-
var moveSource = exports.moveSource = function moveSource(sourceType,
|
|
69
|
+
var moveSource = exports.moveSource = function moveSource(sourceType, sourceIndexes, targetIndex, tr) {
|
|
70
70
|
return (0, _pluginFactory.createCommand)(function (state) {
|
|
71
71
|
return {
|
|
72
72
|
type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
@@ -74,9 +74,9 @@ var moveSource = exports.moveSource = function moveSource(sourceType, sourceInde
|
|
|
74
74
|
decorationSet: _view.DecorationSet.empty
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
}, function (originalTr) {
|
|
77
|
+
}, function (originalTr, state) {
|
|
78
78
|
var nextTr = tr || originalTr;
|
|
79
|
-
if (
|
|
79
|
+
if (sourceIndexes.includes(targetIndex)) {
|
|
80
80
|
return nextTr.setMeta('addToHistory', false);
|
|
81
81
|
}
|
|
82
82
|
var anchor = nextTr.selection.anchor;
|
|
@@ -85,9 +85,9 @@ var moveSource = exports.moveSource = function moveSource(sourceType, sourceInde
|
|
|
85
85
|
};
|
|
86
86
|
var isTableRow = sourceType === 'table-row';
|
|
87
87
|
if (isTableRow) {
|
|
88
|
-
return (0, _transforms.combineTransforms)([(0, _utils.moveRow)(
|
|
88
|
+
return (0, _transforms.combineTransforms)([(0, _utils.moveRow)(state, sourceIndexes, targetIndex), selectStartOfTable, (0, _utils.selectRow)(targetIndex)], nextTr);
|
|
89
89
|
}
|
|
90
|
-
return (0, _transforms.combineTransforms)([(0, _utils.moveColumn)(
|
|
90
|
+
return (0, _transforms.combineTransforms)([(0, _utils.moveColumn)(sourceIndexes, targetIndex), selectStartOfTable, (0, _utils.selectColumn)(targetIndex)], nextTr);
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
var toggleDragMenu = exports.toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
11
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
@@ -126,7 +125,8 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
|
|
|
126
125
|
// If we're able to determine the source type of the dropped element then we should report to analytics that
|
|
127
126
|
// the drop event was cancelled. Otherwise we will cancel silently.
|
|
128
127
|
if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
|
|
129
|
-
|
|
128
|
+
var _event$source$data;
|
|
129
|
+
return (0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, (_event$source$data = event.source.data) === null || _event$source$data === void 0 ? void 0 : _event$source$data.indexes, _analytics.TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
|
|
130
130
|
}
|
|
131
131
|
return (0, _commands.clearDropTarget)(tr)(editorView.state, editorView.dispatch);
|
|
132
132
|
}
|
|
@@ -145,15 +145,13 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
|
|
|
145
145
|
|
|
146
146
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
147
147
|
if ((0, _utils2.hasMergedCellsInBetween)([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN)(editorView.state.selection)) {
|
|
148
|
-
(0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
148
|
+
(0, _commandsWithAnalytics.clearDropTargetWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes,
|
|
149
149
|
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
150
150
|
_analytics.TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
|
-
var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
|
|
154
|
-
sourceIndex = _sourceIndexes[0];
|
|
155
153
|
requestAnimationFrame(function () {
|
|
156
|
-
(0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
154
|
+
(0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
157
155
|
|
|
158
156
|
// force a colgroup update here, otherwise dropped columns don't have
|
|
159
157
|
// the correct width immediately after the drop
|
|
@@ -183,7 +183,7 @@ var getDragMenuConfig = exports.getDragMenuConfig = function getDragMenuConfig(d
|
|
|
183
183
|
onClick: function onClick(state, dispatch) {
|
|
184
184
|
if (canMove(index)) {
|
|
185
185
|
requestAnimationFrame(function () {
|
|
186
|
-
(0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), index, index + offset)(editorView.state, editorView.dispatch);
|
|
186
|
+
(0, _commandsWithAnalytics.moveSourceWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), [index], index + offset)(editorView.state, editorView.dispatch);
|
|
187
187
|
});
|
|
188
188
|
return true;
|
|
189
189
|
}
|
|
@@ -4,10 +4,11 @@ import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tab
|
|
|
4
4
|
import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo, hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils';
|
|
5
5
|
import { withEditorAnalyticsAPI } from '../../utils/analytics';
|
|
6
6
|
import { clearDropTarget, moveSource } from './commands';
|
|
7
|
-
export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, status, tr) => {
|
|
7
|
+
export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, status, tr) => {
|
|
8
8
|
return withEditorAnalyticsAPI(({
|
|
9
9
|
selection
|
|
10
10
|
}) => {
|
|
11
|
+
var _sourceIndexes$length;
|
|
11
12
|
const {
|
|
12
13
|
totalRowCount,
|
|
13
14
|
totalColumnCount
|
|
@@ -18,8 +19,7 @@ export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod,
|
|
|
18
19
|
actionSubjectId: null,
|
|
19
20
|
attributes: {
|
|
20
21
|
inputMethod,
|
|
21
|
-
|
|
22
|
-
count: 1,
|
|
22
|
+
count: (_sourceIndexes$length = sourceIndexes === null || sourceIndexes === void 0 ? void 0 : sourceIndexes.length) !== null && _sourceIndexes$length !== void 0 ? _sourceIndexes$length : 0,
|
|
23
23
|
distance: 0,
|
|
24
24
|
status,
|
|
25
25
|
totalRowCount,
|
|
@@ -34,7 +34,7 @@ export const clearDropTargetWithAnalytics = editorAnalyticsAPI => (inputMethod,
|
|
|
34
34
|
return true;
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
export const moveSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType,
|
|
37
|
+
export const moveSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourceType, sourceIndexes, targetIndex, tr) => {
|
|
38
38
|
return withEditorAnalyticsAPI(({
|
|
39
39
|
selection
|
|
40
40
|
}) => {
|
|
@@ -48,12 +48,12 @@ export const moveSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourc
|
|
|
48
48
|
actionSubjectId: null,
|
|
49
49
|
attributes: {
|
|
50
50
|
inputMethod,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// This
|
|
54
|
-
distance: targetIndex -
|
|
51
|
+
count: sourceIndexes.length,
|
|
52
|
+
// This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
|
|
53
|
+
// of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
|
|
54
|
+
distance: Math.min(...sourceIndexes.map(v => targetIndex - v)),
|
|
55
55
|
// If a drop doesn't actually change anything then we're going to mark the event as cancelled.
|
|
56
|
-
status:
|
|
56
|
+
status: sourceIndexes.includes(targetIndex) ? TABLE_STATUS.CANCELLED : TABLE_STATUS.SUCCESS,
|
|
57
57
|
totalRowCount,
|
|
58
58
|
totalColumnCount
|
|
59
59
|
},
|
|
@@ -61,7 +61,7 @@ export const moveSourceWithAnalytics = editorAnalyticsAPI => (inputMethod, sourc
|
|
|
61
61
|
};
|
|
62
62
|
})(editorAnalyticsAPI)((state, dispatch) => {
|
|
63
63
|
if (dispatch) {
|
|
64
|
-
moveSource(sourceType,
|
|
64
|
+
moveSource(sourceType, sourceIndexes, targetIndex, tr)(state, dispatch);
|
|
65
65
|
}
|
|
66
66
|
return true;
|
|
67
67
|
});
|
|
@@ -78,7 +78,7 @@ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceT
|
|
|
78
78
|
const isRow = sourceType === 'table-row';
|
|
79
79
|
const selectedIndexes = isRow ? getSelectedRowIndexes(selectionRect) : getSelectedColumnIndexes(selectionRect);
|
|
80
80
|
|
|
81
|
-
// We can move if only one row/column selected
|
|
81
|
+
// FIXME: We can move if only one row/column selected
|
|
82
82
|
if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
@@ -106,5 +106,5 @@ export const moveSourceWithAnalyticsViaShortcut = editorAnalyticsAPI => (sourceT
|
|
|
106
106
|
if (hasMergedCellsInTarget) {
|
|
107
107
|
return false;
|
|
108
108
|
}
|
|
109
|
-
return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, sourceIndex, targetIndex)(state, dispatch);
|
|
109
|
+
return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, [sourceIndex], targetIndex)(state, dispatch);
|
|
110
110
|
};
|
|
@@ -53,25 +53,25 @@ export const clearDropTarget = tr => createCommand(state => {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
}, originalTr => (tr || originalTr).setMeta('addToHistory', false));
|
|
56
|
-
export const moveSource = (sourceType,
|
|
56
|
+
export const moveSource = (sourceType, sourceIndexes, targetIndex, tr) => createCommand(state => {
|
|
57
57
|
return {
|
|
58
58
|
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
59
59
|
data: {
|
|
60
60
|
decorationSet: DecorationSet.empty
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
}, originalTr => {
|
|
63
|
+
}, (originalTr, state) => {
|
|
64
64
|
const nextTr = tr || originalTr;
|
|
65
|
-
if (
|
|
65
|
+
if (sourceIndexes.includes(targetIndex)) {
|
|
66
66
|
return nextTr.setMeta('addToHistory', false);
|
|
67
67
|
}
|
|
68
68
|
const anchor = nextTr.selection.anchor;
|
|
69
69
|
const selectStartOfTable = newTr => newTr.setSelection(TextSelection.create(newTr.doc, anchor));
|
|
70
70
|
const isTableRow = sourceType === 'table-row';
|
|
71
71
|
if (isTableRow) {
|
|
72
|
-
return combineTransforms([moveRow(
|
|
72
|
+
return combineTransforms([moveRow(state, sourceIndexes, targetIndex), selectStartOfTable, selectRow(targetIndex)], nextTr);
|
|
73
73
|
}
|
|
74
|
-
return combineTransforms([moveColumn(
|
|
74
|
+
return combineTransforms([moveColumn(sourceIndexes, targetIndex), selectStartOfTable, selectColumn(targetIndex)], nextTr);
|
|
75
75
|
});
|
|
76
76
|
export const toggleDragMenu = (isDragMenuOpen, direction, index) => createCommand(state => {
|
|
77
77
|
let {
|
|
@@ -126,7 +126,8 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
|
|
|
126
126
|
// If we're able to determine the source type of the dropped element then we should report to analytics that
|
|
127
127
|
// the drop event was cancelled. Otherwise we will cancel silently.
|
|
128
128
|
if ((event === null || event === void 0 ? void 0 : (_event$source = event.source) === null || _event$source === void 0 ? void 0 : (_event$source$data = _event$source.data) === null || _event$source$data === void 0 ? void 0 : _event$source$data.type) === 'table-row' || (event === null || event === void 0 ? void 0 : (_event$source2 = event.source) === null || _event$source2 === void 0 ? void 0 : (_event$source2$data = _event$source2.data) === null || _event$source2$data === void 0 ? void 0 : _event$source2$data.type) === 'table-column') {
|
|
129
|
-
|
|
129
|
+
var _event$source$data2;
|
|
130
|
+
return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, (_event$source$data2 = event.source.data) === null || _event$source$data2 === void 0 ? void 0 : _event$source$data2.indexes, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
|
|
130
131
|
}
|
|
131
132
|
return clearDropTarget(tr)(editorView.state, editorView.dispatch);
|
|
132
133
|
}
|
|
@@ -147,14 +148,13 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
|
|
|
147
148
|
|
|
148
149
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
149
150
|
if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
|
|
150
|
-
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
151
|
+
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes,
|
|
151
152
|
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
152
153
|
TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
155
|
-
const [sourceIndex] = sourceIndexes;
|
|
156
156
|
requestAnimationFrame(() => {
|
|
157
|
-
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
157
|
+
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
158
158
|
|
|
159
159
|
// force a colgroup update here, otherwise dropped columns don't have
|
|
160
160
|
// the correct width immediately after the drop
|
|
@@ -166,7 +166,7 @@ export const getDragMenuConfig = (direction, getEditorContainerWidth, canDrag, h
|
|
|
166
166
|
onClick: (state, dispatch) => {
|
|
167
167
|
if (canMove(index)) {
|
|
168
168
|
requestAnimationFrame(() => {
|
|
169
|
-
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, `table-${direction}`, index, index + offset)(editorView.state, editorView.dispatch);
|
|
169
|
+
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, `table-${direction}`, [index], index + offset)(editorView.state, editorView.dispatch);
|
|
170
170
|
});
|
|
171
171
|
return true;
|
|
172
172
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
3
4
|
import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
@@ -5,8 +6,9 @@ import { getSelectedColumnIndexes, getSelectedRowIndexes, getSelectedTableInfo,
|
|
|
5
6
|
import { withEditorAnalyticsAPI } from '../../utils/analytics';
|
|
6
7
|
import { clearDropTarget, moveSource } from './commands';
|
|
7
8
|
export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(editorAnalyticsAPI) {
|
|
8
|
-
return function (inputMethod, sourceType, status, tr) {
|
|
9
|
+
return function (inputMethod, sourceType, sourceIndexes, status, tr) {
|
|
9
10
|
return withEditorAnalyticsAPI(function (_ref) {
|
|
11
|
+
var _sourceIndexes$length;
|
|
10
12
|
var selection = _ref.selection;
|
|
11
13
|
var _getSelectedTableInfo = getSelectedTableInfo(selection),
|
|
12
14
|
totalRowCount = _getSelectedTableInfo.totalRowCount,
|
|
@@ -17,8 +19,7 @@ export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(
|
|
|
17
19
|
actionSubjectId: null,
|
|
18
20
|
attributes: {
|
|
19
21
|
inputMethod: inputMethod,
|
|
20
|
-
|
|
21
|
-
count: 1,
|
|
22
|
+
count: (_sourceIndexes$length = sourceIndexes === null || sourceIndexes === void 0 ? void 0 : sourceIndexes.length) !== null && _sourceIndexes$length !== void 0 ? _sourceIndexes$length : 0,
|
|
22
23
|
distance: 0,
|
|
23
24
|
status: status,
|
|
24
25
|
totalRowCount: totalRowCount,
|
|
@@ -35,7 +36,7 @@ export var clearDropTargetWithAnalytics = function clearDropTargetWithAnalytics(
|
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
38
|
export var moveSourceWithAnalytics = function moveSourceWithAnalytics(editorAnalyticsAPI) {
|
|
38
|
-
return function (inputMethod, sourceType,
|
|
39
|
+
return function (inputMethod, sourceType, sourceIndexes, targetIndex, tr) {
|
|
39
40
|
return withEditorAnalyticsAPI(function (_ref2) {
|
|
40
41
|
var selection = _ref2.selection;
|
|
41
42
|
var _getSelectedTableInfo2 = getSelectedTableInfo(selection),
|
|
@@ -47,12 +48,14 @@ export var moveSourceWithAnalytics = function moveSourceWithAnalytics(editorAnal
|
|
|
47
48
|
actionSubjectId: null,
|
|
48
49
|
attributes: {
|
|
49
50
|
inputMethod: inputMethod,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// This
|
|
53
|
-
distance:
|
|
51
|
+
count: sourceIndexes.length,
|
|
52
|
+
// This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
|
|
53
|
+
// of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
|
|
54
|
+
distance: Math.min.apply(Math, _toConsumableArray(sourceIndexes.map(function (v) {
|
|
55
|
+
return targetIndex - v;
|
|
56
|
+
}))),
|
|
54
57
|
// If a drop doesn't actually change anything then we're going to mark the event as cancelled.
|
|
55
|
-
status:
|
|
58
|
+
status: sourceIndexes.includes(targetIndex) ? TABLE_STATUS.CANCELLED : TABLE_STATUS.SUCCESS,
|
|
56
59
|
totalRowCount: totalRowCount,
|
|
57
60
|
totalColumnCount: totalColumnCount
|
|
58
61
|
},
|
|
@@ -60,7 +63,7 @@ export var moveSourceWithAnalytics = function moveSourceWithAnalytics(editorAnal
|
|
|
60
63
|
};
|
|
61
64
|
})(editorAnalyticsAPI)(function (state, dispatch) {
|
|
62
65
|
if (dispatch) {
|
|
63
|
-
moveSource(sourceType,
|
|
66
|
+
moveSource(sourceType, sourceIndexes, targetIndex, tr)(state, dispatch);
|
|
64
67
|
}
|
|
65
68
|
return true;
|
|
66
69
|
});
|
|
@@ -78,7 +81,7 @@ export var moveSourceWithAnalyticsViaShortcut = function moveSourceWithAnalytics
|
|
|
78
81
|
var isRow = sourceType === 'table-row';
|
|
79
82
|
var selectedIndexes = isRow ? getSelectedRowIndexes(selectionRect) : getSelectedColumnIndexes(selectionRect);
|
|
80
83
|
|
|
81
|
-
// We can move if only one row/column selected
|
|
84
|
+
// FIXME: We can move if only one row/column selected
|
|
82
85
|
if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
|
|
83
86
|
return false;
|
|
84
87
|
}
|
|
@@ -105,7 +108,7 @@ export var moveSourceWithAnalyticsViaShortcut = function moveSourceWithAnalytics
|
|
|
105
108
|
if (hasMergedCellsInTarget) {
|
|
106
109
|
return false;
|
|
107
110
|
}
|
|
108
|
-
return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, sourceIndex, targetIndex)(state, dispatch);
|
|
111
|
+
return moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, sourceType, [sourceIndex], targetIndex)(state, dispatch);
|
|
109
112
|
};
|
|
110
113
|
};
|
|
111
114
|
};
|
|
@@ -61,7 +61,7 @@ export var clearDropTarget = function clearDropTarget(tr) {
|
|
|
61
61
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
-
export var moveSource = function moveSource(sourceType,
|
|
64
|
+
export var moveSource = function moveSource(sourceType, sourceIndexes, targetIndex, tr) {
|
|
65
65
|
return createCommand(function (state) {
|
|
66
66
|
return {
|
|
67
67
|
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
@@ -69,9 +69,9 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
|
|
|
69
69
|
decorationSet: DecorationSet.empty
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
}, function (originalTr) {
|
|
72
|
+
}, function (originalTr, state) {
|
|
73
73
|
var nextTr = tr || originalTr;
|
|
74
|
-
if (
|
|
74
|
+
if (sourceIndexes.includes(targetIndex)) {
|
|
75
75
|
return nextTr.setMeta('addToHistory', false);
|
|
76
76
|
}
|
|
77
77
|
var anchor = nextTr.selection.anchor;
|
|
@@ -80,9 +80,9 @@ export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex
|
|
|
80
80
|
};
|
|
81
81
|
var isTableRow = sourceType === 'table-row';
|
|
82
82
|
if (isTableRow) {
|
|
83
|
-
return combineTransforms([moveRow(
|
|
83
|
+
return combineTransforms([moveRow(state, sourceIndexes, targetIndex), selectStartOfTable, selectRow(targetIndex)], nextTr);
|
|
84
84
|
}
|
|
85
|
-
return combineTransforms([moveColumn(
|
|
85
|
+
return combineTransforms([moveColumn(sourceIndexes, targetIndex), selectStartOfTable, selectColumn(targetIndex)], nextTr);
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
export var toggleDragMenu = function toggleDragMenu(isDragMenuOpen, direction, index) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
4
|
import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
|
|
@@ -119,7 +118,8 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
|
|
|
119
118
|
// If we're able to determine the source type of the dropped element then we should report to analytics that
|
|
120
119
|
// the drop event was cancelled. Otherwise we will cancel silently.
|
|
121
120
|
if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
|
|
122
|
-
|
|
121
|
+
var _event$source$data;
|
|
122
|
+
return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, (_event$source$data = event.source.data) === null || _event$source$data === void 0 ? void 0 : _event$source$data.indexes, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
|
|
123
123
|
}
|
|
124
124
|
return clearDropTarget(tr)(editorView.state, editorView.dispatch);
|
|
125
125
|
}
|
|
@@ -138,15 +138,13 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
|
|
|
138
138
|
|
|
139
139
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
140
140
|
if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
|
|
141
|
-
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
141
|
+
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes,
|
|
142
142
|
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
143
143
|
TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
-
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
147
|
-
sourceIndex = _sourceIndexes[0];
|
|
148
146
|
requestAnimationFrame(function () {
|
|
149
|
-
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
147
|
+
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndexes, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
150
148
|
|
|
151
149
|
// force a colgroup update here, otherwise dropped columns don't have
|
|
152
150
|
// the correct width immediately after the drop
|
|
@@ -176,7 +176,7 @@ export var getDragMenuConfig = function getDragMenuConfig(direction, getEditorCo
|
|
|
176
176
|
onClick: function onClick(state, dispatch) {
|
|
177
177
|
if (canMove(index)) {
|
|
178
178
|
requestAnimationFrame(function () {
|
|
179
|
-
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), index, index + offset)(editorView.state, editorView.dispatch);
|
|
179
|
+
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.TABLE_CONTEXT_MENU, "table-".concat(direction), [index], index + offset)(editorView.state, editorView.dispatch);
|
|
180
180
|
});
|
|
181
181
|
return true;
|
|
182
182
|
}
|
|
@@ -3,6 +3,6 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import type { DraggableData, DraggableType } from '../../types';
|
|
6
|
-
export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
|
|
7
|
-
export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType,
|
|
6
|
+
export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndexes: number[] | undefined, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
|
|
7
|
+
export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => Command;
|
|
8
8
|
export declare const moveSourceWithAnalyticsViaShortcut: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (sourceType: DraggableType, direction: DraggableData['direction']) => Command;
|
|
@@ -8,5 +8,5 @@ export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
|
8
8
|
export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
|
|
9
9
|
export declare const setDropTarget: (type: DropTargetType, index: number, hasMergedCells: boolean, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
10
10
|
export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
11
|
-
export declare const moveSource: (sourceType: DraggableType,
|
|
11
|
+
export declare const moveSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
12
12
|
export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -3,6 +3,6 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import type { DraggableData, DraggableType } from '../../types';
|
|
6
|
-
export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
|
|
7
|
-
export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType,
|
|
6
|
+
export declare const clearDropTargetWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP, sourceType: DraggableType, sourceIndexes: number[] | undefined, status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID, tr?: Transaction) => Command;
|
|
7
|
+
export declare const moveSourceWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT, sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => Command;
|
|
8
8
|
export declare const moveSourceWithAnalyticsViaShortcut: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (sourceType: DraggableType, direction: DraggableData['direction']) => Command;
|
|
@@ -8,5 +8,5 @@ export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
|
8
8
|
export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
|
|
9
9
|
export declare const setDropTarget: (type: DropTargetType, index: number, hasMergedCells: boolean, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
10
10
|
export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
11
|
-
export declare const moveSource: (sourceType: DraggableType,
|
|
11
|
+
export declare const moveSource: (sourceType: DraggableType, sourceIndexes: number[], targetIndex: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
12
12
|
export declare const toggleDragMenu: (isDragMenuOpen: boolean | undefined, direction?: TableDirection, index?: number) => import("@atlaskit/editor-common/types").Command;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.3.0",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.11",
|
|
33
|
-
"@atlaskit/editor-common": "^76.
|
|
33
|
+
"@atlaskit/editor-common": "^76.41.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.5.2",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
36
36
|
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"@atlaskit/editor-plugin-width": "^0.2.0",
|
|
40
40
|
"@atlaskit/editor-prosemirror": "1.1.0",
|
|
41
41
|
"@atlaskit/editor-shared-styles": "^2.9.0",
|
|
42
|
-
"@atlaskit/editor-tables": "^2.
|
|
42
|
+
"@atlaskit/editor-tables": "^2.4.0",
|
|
43
43
|
"@atlaskit/icon": "^22.0.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
45
45
|
"@atlaskit/pragmatic-drag-and-drop": "^0.25.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^0.8.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
|
|
48
|
-
"@atlaskit/primitives": "^1.
|
|
48
|
+
"@atlaskit/primitives": "^1.18.0",
|
|
49
49
|
"@atlaskit/theme": "^12.6.0",
|
|
50
50
|
"@atlaskit/toggle": "^13.0.0",
|
|
51
|
-
"@atlaskit/tokens": "^1.
|
|
51
|
+
"@atlaskit/tokens": "^1.34.0",
|
|
52
52
|
"@atlaskit/tooltip": "^18.1.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@emotion/react": "^11.7.1",
|
|
@@ -751,24 +751,59 @@ describe('Table analytic events', () => {
|
|
|
751
751
|
|
|
752
752
|
describe('track moved', () => {
|
|
753
753
|
it.each([
|
|
754
|
-
[
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
[
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
754
|
+
[
|
|
755
|
+
'Column',
|
|
756
|
+
INPUT_METHOD.TABLE_CONTEXT_MENU,
|
|
757
|
+
[0],
|
|
758
|
+
1,
|
|
759
|
+
TABLE_STATUS.SUCCESS,
|
|
760
|
+
1,
|
|
761
|
+
],
|
|
762
|
+
[
|
|
763
|
+
'Column',
|
|
764
|
+
INPUT_METHOD.TABLE_CONTEXT_MENU,
|
|
765
|
+
[2],
|
|
766
|
+
0,
|
|
767
|
+
TABLE_STATUS.SUCCESS,
|
|
768
|
+
-2,
|
|
769
|
+
],
|
|
770
|
+
[
|
|
771
|
+
'Column',
|
|
772
|
+
INPUT_METHOD.TABLE_CONTEXT_MENU,
|
|
773
|
+
[2],
|
|
774
|
+
2,
|
|
775
|
+
TABLE_STATUS.CANCELLED,
|
|
776
|
+
0,
|
|
777
|
+
],
|
|
778
|
+
|
|
779
|
+
['Row', INPUT_METHOD.TABLE_CONTEXT_MENU, [0], 1, TABLE_STATUS.SUCCESS, 1],
|
|
780
|
+
[
|
|
781
|
+
'Row',
|
|
782
|
+
INPUT_METHOD.TABLE_CONTEXT_MENU,
|
|
783
|
+
[2],
|
|
784
|
+
0,
|
|
785
|
+
TABLE_STATUS.SUCCESS,
|
|
786
|
+
-2,
|
|
787
|
+
],
|
|
788
|
+
[
|
|
789
|
+
'Row',
|
|
790
|
+
INPUT_METHOD.TABLE_CONTEXT_MENU,
|
|
791
|
+
[2],
|
|
792
|
+
2,
|
|
793
|
+
TABLE_STATUS.CANCELLED,
|
|
794
|
+
0,
|
|
795
|
+
],
|
|
796
|
+
|
|
797
|
+
['Column', INPUT_METHOD.DRAG_AND_DROP, [0], 1, TABLE_STATUS.SUCCESS, 1],
|
|
798
|
+
['Column', INPUT_METHOD.DRAG_AND_DROP, [2], 0, TABLE_STATUS.SUCCESS, -2],
|
|
799
|
+
['Column', INPUT_METHOD.DRAG_AND_DROP, [2], 2, TABLE_STATUS.CANCELLED, 0],
|
|
800
|
+
|
|
801
|
+
['Row', INPUT_METHOD.DRAG_AND_DROP, [0], 1, TABLE_STATUS.SUCCESS, 1],
|
|
802
|
+
['Row', INPUT_METHOD.DRAG_AND_DROP, [2], 0, TABLE_STATUS.SUCCESS, -2],
|
|
803
|
+
['Row', INPUT_METHOD.DRAG_AND_DROP, [2], 2, TABLE_STATUS.CANCELLED, 0],
|
|
769
804
|
])(
|
|
770
805
|
'should fire v3 analytics for %s using input %s moving index from %i to %i with status %s',
|
|
771
|
-
(type, inputMethod, sourceIndex, targetIndex, status) => {
|
|
806
|
+
(type, inputMethod, sourceIndex, targetIndex, status, distance) => {
|
|
772
807
|
const { editorView } = editor(defaultTableDoc);
|
|
773
808
|
moveSourceWithAnalytics(editorAnalyticsAPIFake)(
|
|
774
809
|
inputMethod as
|
|
@@ -786,7 +821,7 @@ describe('Table analytic events', () => {
|
|
|
786
821
|
attributes: expect.objectContaining({
|
|
787
822
|
inputMethod,
|
|
788
823
|
count: 1,
|
|
789
|
-
distance
|
|
824
|
+
distance,
|
|
790
825
|
status,
|
|
791
826
|
totalRowCount: 3,
|
|
792
827
|
totalColumnCount: 3,
|
|
@@ -828,6 +863,7 @@ describe('Table analytic events', () => {
|
|
|
828
863
|
| INPUT_METHOD.TABLE_CONTEXT_MENU
|
|
829
864
|
| INPUT_METHOD.DRAG_AND_DROP,
|
|
830
865
|
type === 'Row' ? 'table-row' : 'table-column',
|
|
866
|
+
[0],
|
|
831
867
|
status as TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
|
|
832
868
|
)(editorView.state, editorView.dispatch);
|
|
833
869
|
|
|
@@ -42,7 +42,9 @@ describe('Snapshot Test: Table', () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
describe('numbered list', () => {
|
|
45
|
-
|
|
45
|
+
// FIXME: Skipping this test as it is flaky
|
|
46
|
+
// Build link: https://bitbucket.org/atlassian/atlassian-frontend/pipelines/results/2289567
|
|
47
|
+
it.skip('should not overflow table cell, when there are more than 100 ordered list items', async () => {
|
|
46
48
|
await initEditor(page, tableWith100ListItemsADF);
|
|
47
49
|
|
|
48
50
|
// initial elements
|
|
@@ -34,6 +34,7 @@ export const clearDropTargetWithAnalytics =
|
|
|
34
34
|
(
|
|
35
35
|
inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP,
|
|
36
36
|
sourceType: DraggableType,
|
|
37
|
+
sourceIndexes: number[] | undefined,
|
|
37
38
|
status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
|
|
38
39
|
tr?: Transaction,
|
|
39
40
|
) => {
|
|
@@ -49,8 +50,7 @@ export const clearDropTargetWithAnalytics =
|
|
|
49
50
|
actionSubjectId: null,
|
|
50
51
|
attributes: {
|
|
51
52
|
inputMethod,
|
|
52
|
-
|
|
53
|
-
count: 1,
|
|
53
|
+
count: sourceIndexes?.length ?? 0,
|
|
54
54
|
distance: 0,
|
|
55
55
|
status,
|
|
56
56
|
totalRowCount,
|
|
@@ -74,7 +74,7 @@ export const moveSourceWithAnalytics =
|
|
|
74
74
|
| INPUT_METHOD.DRAG_AND_DROP
|
|
75
75
|
| INPUT_METHOD.SHORTCUT,
|
|
76
76
|
sourceType: DraggableType,
|
|
77
|
-
|
|
77
|
+
sourceIndexes: number[],
|
|
78
78
|
targetIndex: number,
|
|
79
79
|
tr?: Transaction,
|
|
80
80
|
) => {
|
|
@@ -90,15 +90,14 @@ export const moveSourceWithAnalytics =
|
|
|
90
90
|
actionSubjectId: null,
|
|
91
91
|
attributes: {
|
|
92
92
|
inputMethod,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// This
|
|
96
|
-
distance: targetIndex -
|
|
93
|
+
count: sourceIndexes.length,
|
|
94
|
+
// This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
|
|
95
|
+
// of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
|
|
96
|
+
distance: Math.min(...sourceIndexes.map((v) => targetIndex - v)),
|
|
97
97
|
// If a drop doesn't actually change anything then we're going to mark the event as cancelled.
|
|
98
|
-
status:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
: TABLE_STATUS.SUCCESS,
|
|
98
|
+
status: sourceIndexes.includes(targetIndex)
|
|
99
|
+
? TABLE_STATUS.CANCELLED
|
|
100
|
+
: TABLE_STATUS.SUCCESS,
|
|
102
101
|
totalRowCount,
|
|
103
102
|
totalColumnCount,
|
|
104
103
|
},
|
|
@@ -106,7 +105,7 @@ export const moveSourceWithAnalytics =
|
|
|
106
105
|
};
|
|
107
106
|
})(editorAnalyticsAPI)((state, dispatch) => {
|
|
108
107
|
if (dispatch) {
|
|
109
|
-
moveSource(sourceType,
|
|
108
|
+
moveSource(sourceType, sourceIndexes, targetIndex, tr)(state, dispatch);
|
|
110
109
|
}
|
|
111
110
|
return true;
|
|
112
111
|
});
|
|
@@ -131,7 +130,7 @@ export const moveSourceWithAnalyticsViaShortcut =
|
|
|
131
130
|
? getSelectedRowIndexes(selectionRect)
|
|
132
131
|
: getSelectedColumnIndexes(selectionRect);
|
|
133
132
|
|
|
134
|
-
// We can move if only one row/column selected
|
|
133
|
+
// FIXME: We can move if only one row/column selected
|
|
135
134
|
if (selectedIndexes.length === 0 || selectedIndexes.length > 1) {
|
|
136
135
|
return false;
|
|
137
136
|
}
|
|
@@ -172,7 +171,7 @@ export const moveSourceWithAnalyticsViaShortcut =
|
|
|
172
171
|
return moveSourceWithAnalytics(editorAnalyticsAPI)(
|
|
173
172
|
INPUT_METHOD.SHORTCUT,
|
|
174
173
|
sourceType,
|
|
175
|
-
sourceIndex,
|
|
174
|
+
[sourceIndex],
|
|
176
175
|
targetIndex,
|
|
177
176
|
)(state, dispatch);
|
|
178
177
|
};
|
|
@@ -100,7 +100,7 @@ export const clearDropTarget = (tr?: Transaction) =>
|
|
|
100
100
|
|
|
101
101
|
export const moveSource = (
|
|
102
102
|
sourceType: DraggableType,
|
|
103
|
-
|
|
103
|
+
sourceIndexes: number[],
|
|
104
104
|
targetIndex: number,
|
|
105
105
|
tr?: Transaction,
|
|
106
106
|
) =>
|
|
@@ -113,9 +113,9 @@ export const moveSource = (
|
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
115
|
},
|
|
116
|
-
(originalTr: Transaction) => {
|
|
116
|
+
(originalTr: Transaction, state) => {
|
|
117
117
|
const nextTr = tr || originalTr;
|
|
118
|
-
if (
|
|
118
|
+
if (sourceIndexes.includes(targetIndex)) {
|
|
119
119
|
return nextTr.setMeta('addToHistory', false);
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -124,11 +124,10 @@ export const moveSource = (
|
|
|
124
124
|
newTr.setSelection(TextSelection.create(newTr.doc, anchor));
|
|
125
125
|
|
|
126
126
|
const isTableRow = sourceType === 'table-row';
|
|
127
|
-
|
|
128
127
|
if (isTableRow) {
|
|
129
128
|
return combineTransforms(
|
|
130
129
|
[
|
|
131
|
-
moveRow(
|
|
130
|
+
moveRow(state, sourceIndexes, targetIndex),
|
|
132
131
|
selectStartOfTable,
|
|
133
132
|
selectRow(targetIndex),
|
|
134
133
|
],
|
|
@@ -138,7 +137,7 @@ export const moveSource = (
|
|
|
138
137
|
|
|
139
138
|
return combineTransforms(
|
|
140
139
|
[
|
|
141
|
-
moveColumn(
|
|
140
|
+
moveColumn(sourceIndexes, targetIndex),
|
|
142
141
|
selectStartOfTable,
|
|
143
142
|
selectColumn(targetIndex),
|
|
144
143
|
],
|
|
@@ -163,6 +163,7 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
|
|
|
163
163
|
return clearDropTargetWithAnalytics(editorAnalyticsAPI)(
|
|
164
164
|
INPUT_METHOD.DRAG_AND_DROP,
|
|
165
165
|
event.source.data.type,
|
|
166
|
+
event.source.data?.indexes as number[] | undefined,
|
|
166
167
|
TABLE_STATUS.CANCELLED,
|
|
167
168
|
tr,
|
|
168
169
|
)(editorView.state, editorView.dispatch);
|
|
@@ -197,6 +198,7 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
|
|
|
197
198
|
clearDropTargetWithAnalytics(editorAnalyticsAPI)(
|
|
198
199
|
INPUT_METHOD.DRAG_AND_DROP,
|
|
199
200
|
sourceType,
|
|
201
|
+
sourceIndexes,
|
|
200
202
|
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
201
203
|
TABLE_STATUS.INVALID,
|
|
202
204
|
tr,
|
|
@@ -204,13 +206,11 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
|
|
|
204
206
|
return;
|
|
205
207
|
}
|
|
206
208
|
|
|
207
|
-
const [sourceIndex] = sourceIndexes;
|
|
208
|
-
|
|
209
209
|
requestAnimationFrame(() => {
|
|
210
210
|
moveSourceWithAnalytics(editorAnalyticsAPI)(
|
|
211
211
|
INPUT_METHOD.DRAG_AND_DROP,
|
|
212
212
|
sourceType,
|
|
213
|
-
|
|
213
|
+
sourceIndexes,
|
|
214
214
|
targetAdjustedIndex + (direction === -1 ? 0 : -1),
|
|
215
215
|
tr,
|
|
216
216
|
)(editorView.state, editorView.dispatch);
|
package/src/utils/drag-menu.ts
CHANGED