@atlaskit/editor-plugin-table 5.2.0 → 5.2.2
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/commands/selection.js +20 -1
- package/dist/cjs/plugins/table/nodeviews/TableRow.js +57 -3
- package/dist/cjs/plugins/table/pm-plugins/table-selection-keymap.js +4 -0
- package/dist/cjs/plugins/table/toolbar.js +2 -2
- package/dist/cjs/plugins/table/types.js +4 -1
- package/dist/es2019/plugins/table/commands/selection.js +18 -1
- package/dist/es2019/plugins/table/nodeviews/TableRow.js +58 -3
- package/dist/es2019/plugins/table/pm-plugins/table-selection-keymap.js +6 -2
- package/dist/es2019/plugins/table/toolbar.js +1 -1
- package/dist/es2019/plugins/table/types.js +5 -1
- package/dist/esm/plugins/table/commands/selection.js +19 -0
- package/dist/esm/plugins/table/nodeviews/TableRow.js +57 -3
- package/dist/esm/plugins/table/pm-plugins/table-selection-keymap.js +6 -2
- package/dist/esm/plugins/table/toolbar.js +1 -1
- package/dist/esm/plugins/table/types.js +5 -1
- package/dist/types/plugins/table/commands/selection.d.ts +1 -0
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +2 -0
- package/dist/types/plugins/table/toolbar.d.ts +1 -0
- package/dist/types/plugins/table/types.d.ts +14 -0
- package/dist/types-ts4.5/plugins/table/commands/selection.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/toolbar.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +14 -0
- package/package.json +7 -2
- package/src/plugins/table/commands/selection.ts +24 -0
- package/src/plugins/table/nodeviews/TableRow.ts +54 -1
- package/src/plugins/table/pm-plugins/table-selection-keymap.ts +15 -1
- package/src/plugins/table/toolbar.tsx +3 -1
- package/src/plugins/table/types.ts +16 -0
- package/tsconfig.app.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#41510](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41510) [`12e9528f975`](https://bitbucket.org/atlassian/atlassian-frontend/commits/12e9528f975) - [ux] Adds a command for shift+arrowUp when pressed inside table to select the whole table when we reach top row.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 5.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#41471](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41471) [`94c3351cece`](https://bitbucket.org/atlassian/atlassian-frontend/commits/94c3351cece) - Table row nodeviews will now be set as drop targets when the DnD FF is enabled
|
|
15
|
+
|
|
3
16
|
## 5.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
|
|
6
|
+
exports.shiftArrowUpFromTable = exports.arrowRightFromTable = exports.arrowLeftFromTable = exports.TableSelectionDirection = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
10
10
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
11
11
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
|
+
var _toolbar = require("../toolbar");
|
|
12
13
|
var TableSelectionDirection = exports.TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
|
|
13
14
|
TableSelectionDirection["TopToBottom"] = "TopToBottom";
|
|
14
15
|
TableSelectionDirection["BottomToTop"] = "BottomToTop";
|
|
@@ -344,4 +345,22 @@ var isSelectionAtStartOfTable = function isSelectionAtStartOfTable($pos, selecti
|
|
|
344
345
|
};
|
|
345
346
|
var isSelectionAtEndOfTable = function isSelectionAtEndOfTable($pos, selection) {
|
|
346
347
|
return (0, _selection.isSelectionAtEndOfNode)($pos, (0, _utils.findTable)(selection));
|
|
348
|
+
};
|
|
349
|
+
var shiftArrowUpFromTable = exports.shiftArrowUpFromTable = function shiftArrowUpFromTable(editorSelectionAPI) {
|
|
350
|
+
return function () {
|
|
351
|
+
return function (state, dispatch) {
|
|
352
|
+
var selection = state.selection;
|
|
353
|
+
var table = (0, _utils.findTable)(selection);
|
|
354
|
+
var selectionRect = (0, _toolbar.getClosestSelectionRect)(state);
|
|
355
|
+
var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top;
|
|
356
|
+
if (table && index === 0) {
|
|
357
|
+
return selectFullTable(editorSelectionAPI)({
|
|
358
|
+
node: table.node,
|
|
359
|
+
startPos: table.start,
|
|
360
|
+
dir: TableSelectionDirection.BottomToTop
|
|
361
|
+
})(state, dispatch);
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
};
|
|
365
|
+
};
|
|
347
366
|
};
|
|
@@ -16,6 +16,8 @@ var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
|
16
16
|
var _throttle = _interopRequireDefault(require("lodash/throttle"));
|
|
17
17
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
18
18
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
19
|
+
var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge");
|
|
20
|
+
var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
19
21
|
var _pluginFactory = require("../pm-plugins/plugin-factory");
|
|
20
22
|
var _pluginKey = require("../pm-plugins/plugin-key");
|
|
21
23
|
var _commands = require("../pm-plugins/sticky-headers/commands");
|
|
@@ -47,9 +49,6 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
47
49
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "listening", false);
|
|
48
50
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "padding", 0);
|
|
49
51
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "top", 0);
|
|
50
|
-
/**
|
|
51
|
-
* Methods
|
|
52
|
-
*/
|
|
53
52
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "headerRowMouseScrollEnd", (0, _debounce.default)(function () {
|
|
54
53
|
_this.dom.classList.remove('no-pointer-events');
|
|
55
54
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
|
|
@@ -75,6 +74,9 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
75
74
|
_this.subscribe();
|
|
76
75
|
}
|
|
77
76
|
}
|
|
77
|
+
if (_this.isDragAndDropEnabled) {
|
|
78
|
+
_this.addDropTarget(_this.contentDOM);
|
|
79
|
+
}
|
|
78
80
|
return _this;
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -121,6 +123,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
121
123
|
}, {
|
|
122
124
|
key: "destroy",
|
|
123
125
|
value: function destroy() {
|
|
126
|
+
var _this$dropTargetClean;
|
|
124
127
|
if (this.isStickyHeaderEnabled) {
|
|
125
128
|
this.unsubscribe();
|
|
126
129
|
var tree = (0, _dom2.getTree)(this.dom);
|
|
@@ -129,6 +132,9 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
129
132
|
}
|
|
130
133
|
this.emitOff(true);
|
|
131
134
|
}
|
|
135
|
+
|
|
136
|
+
// If a drop target cleanup method has been set then we should call it.
|
|
137
|
+
(_this$dropTargetClean = this.dropTargetCleanup) === null || _this$dropTargetClean === void 0 || _this$dropTargetClean.call(this);
|
|
132
138
|
}
|
|
133
139
|
}, {
|
|
134
140
|
key: "ignoreMutation",
|
|
@@ -155,6 +161,54 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
155
161
|
}
|
|
156
162
|
return true;
|
|
157
163
|
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Methods
|
|
167
|
+
*/
|
|
168
|
+
}, {
|
|
169
|
+
key: "addDropTarget",
|
|
170
|
+
value: function addDropTarget(element) {
|
|
171
|
+
var pos = this.getPos();
|
|
172
|
+
if (!Number.isFinite(pos)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (this.dropTargetCleanup) {
|
|
176
|
+
this.dropTargetCleanup();
|
|
177
|
+
}
|
|
178
|
+
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
179
|
+
var targetIndex = resolvedPos.index();
|
|
180
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
181
|
+
this.dropTargetCleanup = (0, _element.dropTargetForElements)({
|
|
182
|
+
element: element,
|
|
183
|
+
canDrop: function canDrop(_ref2) {
|
|
184
|
+
var _data$indexes, _data$indexes2;
|
|
185
|
+
var source = _ref2.source;
|
|
186
|
+
var data = source.data;
|
|
187
|
+
return (
|
|
188
|
+
// Only draggables of row type can be dropped on this target
|
|
189
|
+
data.type === 'table-row' &&
|
|
190
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
191
|
+
data.localId === localId &&
|
|
192
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
193
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
194
|
+
);
|
|
195
|
+
},
|
|
196
|
+
getData: function getData(_ref3) {
|
|
197
|
+
var input = _ref3.input,
|
|
198
|
+
element = _ref3.element;
|
|
199
|
+
var data = {
|
|
200
|
+
localId: localId,
|
|
201
|
+
type: 'table-row',
|
|
202
|
+
targetIndex: targetIndex
|
|
203
|
+
};
|
|
204
|
+
return (0, _closestEdge.attachClosestEdge)(data, {
|
|
205
|
+
input: input,
|
|
206
|
+
element: element,
|
|
207
|
+
allowedEdges: ['top', 'bottom']
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
158
212
|
}, {
|
|
159
213
|
key: "subscribe",
|
|
160
214
|
value: function subscribe() {
|
|
@@ -7,11 +7,15 @@ exports.default = void 0;
|
|
|
7
7
|
exports.tableSelectionKeymapPlugin = tableSelectionKeymapPlugin;
|
|
8
8
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
9
9
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
11
|
var _selection = require("../commands/selection");
|
|
11
12
|
function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
12
13
|
var list = {};
|
|
13
14
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, (0, _selection.arrowRightFromTable)(editorSelectionAPI)(), list);
|
|
14
15
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, (0, _selection.arrowLeftFromTable)(editorSelectionAPI)(), list);
|
|
16
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.shift-arrowup-fix')) {
|
|
17
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.shiftArrowUp.common, (0, _selection.shiftArrowUpFromTable)(editorSelectionAPI)(), list);
|
|
18
|
+
}
|
|
15
19
|
return (0, _keymap.keymap)(list);
|
|
16
20
|
}
|
|
17
21
|
var _default = exports.default = tableSelectionKeymapPlugin;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.messages = exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = void 0;
|
|
7
|
+
exports.messages = exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getClosestSelectionRect = void 0;
|
|
8
8
|
var _react = require("@emotion/react");
|
|
9
9
|
var _reactIntlNext = require("react-intl-next");
|
|
10
10
|
var _customSteps = require("@atlaskit/custom-steps");
|
|
@@ -291,7 +291,7 @@ var getToolbarCellOptionsConfig = exports.getToolbarCellOptionsConfig = function
|
|
|
291
291
|
showSelected: false
|
|
292
292
|
};
|
|
293
293
|
};
|
|
294
|
-
var getClosestSelectionRect = function getClosestSelectionRect(state) {
|
|
294
|
+
var getClosestSelectionRect = exports.getClosestSelectionRect = function getClosestSelectionRect(state) {
|
|
295
295
|
var selection = state.selection;
|
|
296
296
|
return (0, _utils3.isSelectionType)(selection, 'cell') ? (0, _utils3.getSelectionRect)(selection) : (0, _utils3.findCellRectClosestToPos)(selection.$from);
|
|
297
297
|
};
|
|
@@ -117,4 +117,7 @@ var ShadowEvent = exports.ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
|
117
117
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
118
118
|
ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
|
|
119
119
|
return ShadowEvent;
|
|
120
|
-
}({});
|
|
120
|
+
}({});
|
|
121
|
+
/**
|
|
122
|
+
* Drag and Drop interfaces
|
|
123
|
+
*/
|
|
@@ -3,6 +3,7 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
3
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
5
|
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
6
|
+
import { getClosestSelectionRect } from '../toolbar';
|
|
6
7
|
export let TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
|
|
7
8
|
TableSelectionDirection["TopToBottom"] = "TopToBottom";
|
|
8
9
|
TableSelectionDirection["BottomToTop"] = "BottomToTop";
|
|
@@ -305,4 +306,20 @@ const setGapCursorAfterTable = editorSelectionAPI => () => (state, dispatch) =>
|
|
|
305
306
|
return false;
|
|
306
307
|
};
|
|
307
308
|
const isSelectionAtStartOfTable = ($pos, selection) => isSelectionAtStartOfNode($pos, findTable(selection));
|
|
308
|
-
const isSelectionAtEndOfTable = ($pos, selection) => isSelectionAtEndOfNode($pos, findTable(selection));
|
|
309
|
+
const isSelectionAtEndOfTable = ($pos, selection) => isSelectionAtEndOfNode($pos, findTable(selection));
|
|
310
|
+
export const shiftArrowUpFromTable = editorSelectionAPI => () => (state, dispatch) => {
|
|
311
|
+
const {
|
|
312
|
+
selection
|
|
313
|
+
} = state;
|
|
314
|
+
const table = findTable(selection);
|
|
315
|
+
const selectionRect = getClosestSelectionRect(state);
|
|
316
|
+
const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top;
|
|
317
|
+
if (table && index === 0) {
|
|
318
|
+
return selectFullTable(editorSelectionAPI)({
|
|
319
|
+
node: table.node,
|
|
320
|
+
startPos: table.start,
|
|
321
|
+
dir: TableSelectionDirection.BottomToTop
|
|
322
|
+
})(state, dispatch);
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
};
|
|
@@ -3,6 +3,8 @@ import debounce from 'lodash/debounce';
|
|
|
3
3
|
import throttle from 'lodash/throttle';
|
|
4
4
|
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
5
5
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
6
|
+
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
7
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
8
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
7
9
|
import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
|
|
8
10
|
import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
|
|
@@ -29,9 +31,6 @@ export default class TableRow extends TableNodeView {
|
|
|
29
31
|
_defineProperty(this, "listening", false);
|
|
30
32
|
_defineProperty(this, "padding", 0);
|
|
31
33
|
_defineProperty(this, "top", 0);
|
|
32
|
-
/**
|
|
33
|
-
* Methods
|
|
34
|
-
*/
|
|
35
34
|
_defineProperty(this, "headerRowMouseScrollEnd", debounce(() => {
|
|
36
35
|
this.dom.classList.remove('no-pointer-events');
|
|
37
36
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
|
|
@@ -58,6 +57,9 @@ export default class TableRow extends TableNodeView {
|
|
|
58
57
|
this.subscribe();
|
|
59
58
|
}
|
|
60
59
|
}
|
|
60
|
+
if (this.isDragAndDropEnabled) {
|
|
61
|
+
this.addDropTarget(this.contentDOM);
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
@@ -99,6 +101,7 @@ export default class TableRow extends TableNodeView {
|
|
|
99
101
|
return true;
|
|
100
102
|
}
|
|
101
103
|
destroy() {
|
|
104
|
+
var _this$dropTargetClean;
|
|
102
105
|
if (this.isStickyHeaderEnabled) {
|
|
103
106
|
this.unsubscribe();
|
|
104
107
|
const tree = getTree(this.dom);
|
|
@@ -107,6 +110,9 @@ export default class TableRow extends TableNodeView {
|
|
|
107
110
|
}
|
|
108
111
|
this.emitOff(true);
|
|
109
112
|
}
|
|
113
|
+
|
|
114
|
+
// If a drop target cleanup method has been set then we should call it.
|
|
115
|
+
(_this$dropTargetClean = this.dropTargetCleanup) === null || _this$dropTargetClean === void 0 ? void 0 : _this$dropTargetClean.call(this);
|
|
110
116
|
}
|
|
111
117
|
ignoreMutation(mutationRecord) {
|
|
112
118
|
/* tableRows are not directly editable by the user
|
|
@@ -131,6 +137,55 @@ export default class TableRow extends TableNodeView {
|
|
|
131
137
|
}
|
|
132
138
|
return true;
|
|
133
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Methods
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
addDropTarget(element) {
|
|
146
|
+
const pos = this.getPos();
|
|
147
|
+
if (!Number.isFinite(pos)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (this.dropTargetCleanup) {
|
|
151
|
+
this.dropTargetCleanup();
|
|
152
|
+
}
|
|
153
|
+
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
154
|
+
const targetIndex = resolvedPos.index();
|
|
155
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
156
|
+
this.dropTargetCleanup = dropTargetForElements({
|
|
157
|
+
element: element,
|
|
158
|
+
canDrop({
|
|
159
|
+
source
|
|
160
|
+
}) {
|
|
161
|
+
var _data$indexes, _data$indexes2;
|
|
162
|
+
const data = source.data;
|
|
163
|
+
return (
|
|
164
|
+
// Only draggables of row type can be dropped on this target
|
|
165
|
+
data.type === 'table-row' &&
|
|
166
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
167
|
+
data.localId === localId &&
|
|
168
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
169
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
getData({
|
|
173
|
+
input,
|
|
174
|
+
element
|
|
175
|
+
}) {
|
|
176
|
+
const data = {
|
|
177
|
+
localId,
|
|
178
|
+
type: 'table-row',
|
|
179
|
+
targetIndex
|
|
180
|
+
};
|
|
181
|
+
return attachClosestEdge(data, {
|
|
182
|
+
input,
|
|
183
|
+
element,
|
|
184
|
+
allowedEdges: ['top', 'bottom']
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
134
189
|
subscribe() {
|
|
135
190
|
this.editorScrollableElement = findOverflowScrollParent(this.view.dom) || window;
|
|
136
191
|
if (this.editorScrollableElement) {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { bindKeymapWithCommand, moveLeft, moveRight } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapWithCommand, moveLeft, moveRight, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
|
-
import {
|
|
3
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { arrowLeftFromTable, arrowRightFromTable, shiftArrowUpFromTable } from '../commands/selection';
|
|
4
5
|
export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
5
6
|
const list = {};
|
|
6
7
|
bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
|
|
7
8
|
bindKeymapWithCommand(moveLeft.common, arrowLeftFromTable(editorSelectionAPI)(), list);
|
|
9
|
+
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
10
|
+
bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
|
|
11
|
+
}
|
|
8
12
|
return keymap(list);
|
|
9
13
|
}
|
|
10
14
|
export default tableSelectionKeymapPlugin;
|
|
@@ -286,7 +286,7 @@ export const getToolbarCellOptionsConfig = (editorState, editorView, initialSele
|
|
|
286
286
|
showSelected: false
|
|
287
287
|
};
|
|
288
288
|
};
|
|
289
|
-
const getClosestSelectionRect = state => {
|
|
289
|
+
export const getClosestSelectionRect = state => {
|
|
290
290
|
const selection = state.selection;
|
|
291
291
|
return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
292
292
|
};
|
|
@@ -109,4 +109,8 @@ export let ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
|
109
109
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
110
110
|
ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
|
|
111
111
|
return ShadowEvent;
|
|
112
|
-
}({});
|
|
112
|
+
}({});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Drag and Drop interfaces
|
|
116
|
+
*/
|
|
@@ -3,6 +3,7 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
3
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
5
|
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
6
|
+
import { getClosestSelectionRect } from '../toolbar';
|
|
6
7
|
export var TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
|
|
7
8
|
TableSelectionDirection["TopToBottom"] = "TopToBottom";
|
|
8
9
|
TableSelectionDirection["BottomToTop"] = "BottomToTop";
|
|
@@ -338,4 +339,22 @@ var isSelectionAtStartOfTable = function isSelectionAtStartOfTable($pos, selecti
|
|
|
338
339
|
};
|
|
339
340
|
var isSelectionAtEndOfTable = function isSelectionAtEndOfTable($pos, selection) {
|
|
340
341
|
return isSelectionAtEndOfNode($pos, findTable(selection));
|
|
342
|
+
};
|
|
343
|
+
export var shiftArrowUpFromTable = function shiftArrowUpFromTable(editorSelectionAPI) {
|
|
344
|
+
return function () {
|
|
345
|
+
return function (state, dispatch) {
|
|
346
|
+
var selection = state.selection;
|
|
347
|
+
var table = findTable(selection);
|
|
348
|
+
var selectionRect = getClosestSelectionRect(state);
|
|
349
|
+
var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top;
|
|
350
|
+
if (table && index === 0) {
|
|
351
|
+
return selectFullTable(editorSelectionAPI)({
|
|
352
|
+
node: table.node,
|
|
353
|
+
startPos: table.start,
|
|
354
|
+
dir: TableSelectionDirection.BottomToTop
|
|
355
|
+
})(state, dispatch);
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
};
|
|
359
|
+
};
|
|
341
360
|
};
|
|
@@ -11,6 +11,8 @@ import debounce from 'lodash/debounce';
|
|
|
11
11
|
import throttle from 'lodash/throttle';
|
|
12
12
|
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
13
13
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
14
|
+
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
15
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
14
16
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
15
17
|
import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
|
|
16
18
|
import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
|
|
@@ -41,9 +43,6 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
41
43
|
_defineProperty(_assertThisInitialized(_this), "listening", false);
|
|
42
44
|
_defineProperty(_assertThisInitialized(_this), "padding", 0);
|
|
43
45
|
_defineProperty(_assertThisInitialized(_this), "top", 0);
|
|
44
|
-
/**
|
|
45
|
-
* Methods
|
|
46
|
-
*/
|
|
47
46
|
_defineProperty(_assertThisInitialized(_this), "headerRowMouseScrollEnd", debounce(function () {
|
|
48
47
|
_this.dom.classList.remove('no-pointer-events');
|
|
49
48
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
|
|
@@ -69,6 +68,9 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
69
68
|
_this.subscribe();
|
|
70
69
|
}
|
|
71
70
|
}
|
|
71
|
+
if (_this.isDragAndDropEnabled) {
|
|
72
|
+
_this.addDropTarget(_this.contentDOM);
|
|
73
|
+
}
|
|
72
74
|
return _this;
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -115,6 +117,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
115
117
|
}, {
|
|
116
118
|
key: "destroy",
|
|
117
119
|
value: function destroy() {
|
|
120
|
+
var _this$dropTargetClean;
|
|
118
121
|
if (this.isStickyHeaderEnabled) {
|
|
119
122
|
this.unsubscribe();
|
|
120
123
|
var tree = getTree(this.dom);
|
|
@@ -123,6 +126,9 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
123
126
|
}
|
|
124
127
|
this.emitOff(true);
|
|
125
128
|
}
|
|
129
|
+
|
|
130
|
+
// If a drop target cleanup method has been set then we should call it.
|
|
131
|
+
(_this$dropTargetClean = this.dropTargetCleanup) === null || _this$dropTargetClean === void 0 || _this$dropTargetClean.call(this);
|
|
126
132
|
}
|
|
127
133
|
}, {
|
|
128
134
|
key: "ignoreMutation",
|
|
@@ -149,6 +155,54 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
149
155
|
}
|
|
150
156
|
return true;
|
|
151
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Methods
|
|
161
|
+
*/
|
|
162
|
+
}, {
|
|
163
|
+
key: "addDropTarget",
|
|
164
|
+
value: function addDropTarget(element) {
|
|
165
|
+
var pos = this.getPos();
|
|
166
|
+
if (!Number.isFinite(pos)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (this.dropTargetCleanup) {
|
|
170
|
+
this.dropTargetCleanup();
|
|
171
|
+
}
|
|
172
|
+
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
173
|
+
var targetIndex = resolvedPos.index();
|
|
174
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
175
|
+
this.dropTargetCleanup = dropTargetForElements({
|
|
176
|
+
element: element,
|
|
177
|
+
canDrop: function canDrop(_ref2) {
|
|
178
|
+
var _data$indexes, _data$indexes2;
|
|
179
|
+
var source = _ref2.source;
|
|
180
|
+
var data = source.data;
|
|
181
|
+
return (
|
|
182
|
+
// Only draggables of row type can be dropped on this target
|
|
183
|
+
data.type === 'table-row' &&
|
|
184
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
185
|
+
data.localId === localId &&
|
|
186
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
187
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
getData: function getData(_ref3) {
|
|
191
|
+
var input = _ref3.input,
|
|
192
|
+
element = _ref3.element;
|
|
193
|
+
var data = {
|
|
194
|
+
localId: localId,
|
|
195
|
+
type: 'table-row',
|
|
196
|
+
targetIndex: targetIndex
|
|
197
|
+
};
|
|
198
|
+
return attachClosestEdge(data, {
|
|
199
|
+
input: input,
|
|
200
|
+
element: element,
|
|
201
|
+
allowedEdges: ['top', 'bottom']
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
152
206
|
}, {
|
|
153
207
|
key: "subscribe",
|
|
154
208
|
value: function subscribe() {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { bindKeymapWithCommand, moveLeft, moveRight } from '@atlaskit/editor-common/keymaps';
|
|
1
|
+
import { bindKeymapWithCommand, moveLeft, moveRight, shiftArrowUp } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
|
-
import {
|
|
3
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { arrowLeftFromTable, arrowRightFromTable, shiftArrowUpFromTable } from '../commands/selection';
|
|
4
5
|
export function tableSelectionKeymapPlugin(editorSelectionAPI) {
|
|
5
6
|
var list = {};
|
|
6
7
|
bindKeymapWithCommand(moveRight.common, arrowRightFromTable(editorSelectionAPI)(), list);
|
|
7
8
|
bindKeymapWithCommand(moveLeft.common, arrowLeftFromTable(editorSelectionAPI)(), list);
|
|
9
|
+
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
10
|
+
bindKeymapWithCommand(shiftArrowUp.common, shiftArrowUpFromTable(editorSelectionAPI)(), list);
|
|
11
|
+
}
|
|
8
12
|
return keymap(list);
|
|
9
13
|
}
|
|
10
14
|
export default tableSelectionKeymapPlugin;
|
|
@@ -283,7 +283,7 @@ export var getToolbarCellOptionsConfig = function getToolbarCellOptionsConfig(ed
|
|
|
283
283
|
showSelected: false
|
|
284
284
|
};
|
|
285
285
|
};
|
|
286
|
-
var getClosestSelectionRect = function getClosestSelectionRect(state) {
|
|
286
|
+
export var getClosestSelectionRect = function getClosestSelectionRect(state) {
|
|
287
287
|
var selection = state.selection;
|
|
288
288
|
return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
|
|
289
289
|
};
|
|
@@ -111,4 +111,8 @@ export var ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
|
111
111
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
112
112
|
ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
|
|
113
113
|
return ShadowEvent;
|
|
114
|
-
}({});
|
|
114
|
+
}({});
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Drag and Drop interfaces
|
|
118
|
+
*/
|
|
@@ -6,3 +6,4 @@ export declare enum TableSelectionDirection {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const arrowLeftFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
8
8
|
export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
9
|
+
export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
@@ -23,6 +23,7 @@ export default class TableRow extends TableNodeView<HTMLTableRowElement> impleme
|
|
|
23
23
|
private listening;
|
|
24
24
|
private padding;
|
|
25
25
|
private top;
|
|
26
|
+
private dropTargetCleanup?;
|
|
26
27
|
/**
|
|
27
28
|
* Methods: Nodeview Lifecycle
|
|
28
29
|
*/
|
|
@@ -35,6 +36,7 @@ export default class TableRow extends TableNodeView<HTMLTableRowElement> impleme
|
|
|
35
36
|
/**
|
|
36
37
|
* Methods
|
|
37
38
|
*/
|
|
39
|
+
private addDropTarget;
|
|
38
40
|
private headerRowMouseScrollEnd;
|
|
39
41
|
private headerRowMouseScroll;
|
|
40
42
|
private subscribe;
|
|
@@ -33,4 +33,5 @@ export declare const messages: {
|
|
|
33
33
|
};
|
|
34
34
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
35
35
|
export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarDropdown<Command>;
|
|
36
|
+
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
36
37
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
@@ -341,3 +341,17 @@ export type InvalidNodeAttr = {
|
|
|
341
341
|
spanValue: number;
|
|
342
342
|
tableLocalId: string;
|
|
343
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Drag and Drop interfaces
|
|
346
|
+
*/
|
|
347
|
+
export type DraggableType = 'table-row' | 'table-column';
|
|
348
|
+
export interface DraggableSourceData extends Record<string, unknown> {
|
|
349
|
+
type: DraggableType;
|
|
350
|
+
localId: string;
|
|
351
|
+
indexes: number[];
|
|
352
|
+
}
|
|
353
|
+
export interface DraggableTargetData extends Record<string, unknown> {
|
|
354
|
+
type: DraggableType;
|
|
355
|
+
localId: string;
|
|
356
|
+
targetIndex: number;
|
|
357
|
+
}
|
|
@@ -6,3 +6,4 @@ export declare enum TableSelectionDirection {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const arrowLeftFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
8
8
|
export declare const arrowRightFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
9
|
+
export declare const shiftArrowUpFromTable: (editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) => () => Command;
|
|
@@ -23,6 +23,7 @@ export default class TableRow extends TableNodeView<HTMLTableRowElement> impleme
|
|
|
23
23
|
private listening;
|
|
24
24
|
private padding;
|
|
25
25
|
private top;
|
|
26
|
+
private dropTargetCleanup?;
|
|
26
27
|
/**
|
|
27
28
|
* Methods: Nodeview Lifecycle
|
|
28
29
|
*/
|
|
@@ -35,6 +36,7 @@ export default class TableRow extends TableNodeView<HTMLTableRowElement> impleme
|
|
|
35
36
|
/**
|
|
36
37
|
* Methods
|
|
37
38
|
*/
|
|
39
|
+
private addDropTarget;
|
|
38
40
|
private headerRowMouseScrollEnd;
|
|
39
41
|
private headerRowMouseScroll;
|
|
40
42
|
private subscribe;
|
|
@@ -33,4 +33,5 @@ export declare const messages: {
|
|
|
33
33
|
};
|
|
34
34
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
35
35
|
export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarDropdown<Command>;
|
|
36
|
+
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
36
37
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
@@ -341,3 +341,17 @@ export type InvalidNodeAttr = {
|
|
|
341
341
|
spanValue: number;
|
|
342
342
|
tableLocalId: string;
|
|
343
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Drag and Drop interfaces
|
|
346
|
+
*/
|
|
347
|
+
export type DraggableType = 'table-row' | 'table-column';
|
|
348
|
+
export interface DraggableSourceData extends Record<string, unknown> {
|
|
349
|
+
type: DraggableType;
|
|
350
|
+
localId: string;
|
|
351
|
+
indexes: number[];
|
|
352
|
+
}
|
|
353
|
+
export interface DraggableTargetData extends Record<string, unknown> {
|
|
354
|
+
type: DraggableType;
|
|
355
|
+
localId: string;
|
|
356
|
+
targetIndex: number;
|
|
357
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
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.11.0",
|
|
33
33
|
"@atlaskit/editor-palette": "1.5.1",
|
|
34
34
|
"@atlaskit/editor-plugin-analytics": "^0.2.0",
|
|
35
35
|
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"@atlaskit/editor-tables": "^2.3.0",
|
|
39
39
|
"@atlaskit/icon": "^21.12.0",
|
|
40
40
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
41
|
+
"@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
|
|
42
|
+
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
|
|
41
43
|
"@atlaskit/theme": "^12.6.0",
|
|
42
44
|
"@atlaskit/tokens": "^1.26.0",
|
|
43
45
|
"@atlaskit/tooltip": "^17.8.0",
|
|
@@ -125,6 +127,9 @@
|
|
|
125
127
|
"platform.editor.table.increase-shadow-visibility_lh89r": {
|
|
126
128
|
"type": "boolean"
|
|
127
129
|
},
|
|
130
|
+
"platform.editor.table.shift-arrowup-fix": {
|
|
131
|
+
"type": "boolean"
|
|
132
|
+
},
|
|
128
133
|
"platform.editor.table.update-table-resizer-styles": {
|
|
129
134
|
"type": "boolean"
|
|
130
135
|
},
|
|
@@ -20,6 +20,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
20
20
|
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
21
21
|
|
|
22
22
|
import type tablePlugin from '../index';
|
|
23
|
+
import { getClosestSelectionRect } from '../toolbar';
|
|
23
24
|
|
|
24
25
|
export enum TableSelectionDirection {
|
|
25
26
|
TopToBottom = 'TopToBottom',
|
|
@@ -485,3 +486,26 @@ const isSelectionAtStartOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
|
485
486
|
|
|
486
487
|
const isSelectionAtEndOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
487
488
|
isSelectionAtEndOfNode($pos, findTable(selection));
|
|
489
|
+
|
|
490
|
+
export const shiftArrowUpFromTable =
|
|
491
|
+
(
|
|
492
|
+
editorSelectionAPI:
|
|
493
|
+
| ExtractInjectionAPI<typeof tablePlugin>['selection']
|
|
494
|
+
| undefined,
|
|
495
|
+
) =>
|
|
496
|
+
(): Command =>
|
|
497
|
+
(state, dispatch) => {
|
|
498
|
+
const { selection } = state;
|
|
499
|
+
const table = findTable(selection);
|
|
500
|
+
const selectionRect = getClosestSelectionRect(state);
|
|
501
|
+
const index = selectionRect?.top;
|
|
502
|
+
if (table && index === 0) {
|
|
503
|
+
return selectFullTable(editorSelectionAPI)({
|
|
504
|
+
node: table.node,
|
|
505
|
+
startPos: table.start,
|
|
506
|
+
dir: TableSelectionDirection.BottomToTop,
|
|
507
|
+
})(state, dispatch);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return false;
|
|
511
|
+
};
|
|
@@ -6,6 +6,8 @@ import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
|
6
6
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
8
8
|
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
+
import { attachClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge';
|
|
10
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
9
11
|
|
|
10
12
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
11
13
|
import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
|
|
@@ -14,7 +16,7 @@ import {
|
|
|
14
16
|
syncStickyRowToTable,
|
|
15
17
|
updateStickyMargins as updateTableMargin,
|
|
16
18
|
} from '../pm-plugins/table-resizing/utils/dom';
|
|
17
|
-
import type { TablePluginState } from '../types';
|
|
19
|
+
import type { DraggableSourceData, TablePluginState } from '../types';
|
|
18
20
|
import { TableCssClassName as ClassName, TableCssClassName } from '../types';
|
|
19
21
|
import {
|
|
20
22
|
STICKY_HEADER_TOGGLE_TOLERANCE_MS,
|
|
@@ -62,6 +64,10 @@ export default class TableRow
|
|
|
62
64
|
this.subscribe();
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
|
|
68
|
+
if (this.isDragAndDropEnabled) {
|
|
69
|
+
this.addDropTarget(this.contentDOM);
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
/**
|
|
@@ -87,6 +93,7 @@ export default class TableRow
|
|
|
87
93
|
private listening = false;
|
|
88
94
|
private padding: number = 0;
|
|
89
95
|
private top: number = 0;
|
|
96
|
+
private dropTargetCleanup?: () => void;
|
|
90
97
|
|
|
91
98
|
/**
|
|
92
99
|
* Methods: Nodeview Lifecycle
|
|
@@ -133,6 +140,9 @@ export default class TableRow
|
|
|
133
140
|
|
|
134
141
|
this.emitOff(true);
|
|
135
142
|
}
|
|
143
|
+
|
|
144
|
+
// If a drop target cleanup method has been set then we should call it.
|
|
145
|
+
this.dropTargetCleanup?.();
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
ignoreMutation(
|
|
@@ -172,6 +182,49 @@ export default class TableRow
|
|
|
172
182
|
* Methods
|
|
173
183
|
*/
|
|
174
184
|
|
|
185
|
+
private addDropTarget(element: HTMLElement) {
|
|
186
|
+
const pos = this.getPos()!;
|
|
187
|
+
if (!Number.isFinite(pos)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (this.dropTargetCleanup) {
|
|
192
|
+
this.dropTargetCleanup();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
196
|
+
const targetIndex = resolvedPos.index();
|
|
197
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
198
|
+
|
|
199
|
+
this.dropTargetCleanup = dropTargetForElements({
|
|
200
|
+
element: element,
|
|
201
|
+
canDrop({ source }) {
|
|
202
|
+
const data = source.data as DraggableSourceData;
|
|
203
|
+
return (
|
|
204
|
+
// Only draggables of row type can be dropped on this target
|
|
205
|
+
data.type === 'table-row' &&
|
|
206
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
207
|
+
data.localId === localId &&
|
|
208
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
209
|
+
!!data.indexes?.length &&
|
|
210
|
+
data.indexes?.indexOf(targetIndex) === -1
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
getData({ input, element }) {
|
|
214
|
+
const data = {
|
|
215
|
+
localId,
|
|
216
|
+
type: 'table-row',
|
|
217
|
+
targetIndex,
|
|
218
|
+
};
|
|
219
|
+
return attachClosestEdge(data, {
|
|
220
|
+
input,
|
|
221
|
+
element,
|
|
222
|
+
allowedEdges: ['top', 'bottom'],
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
175
228
|
private headerRowMouseScrollEnd = debounce(() => {
|
|
176
229
|
this.dom.classList.remove('no-pointer-events');
|
|
177
230
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT);
|
|
@@ -2,12 +2,18 @@ import {
|
|
|
2
2
|
bindKeymapWithCommand,
|
|
3
3
|
moveLeft,
|
|
4
4
|
moveRight,
|
|
5
|
+
shiftArrowUp,
|
|
5
6
|
} from '@atlaskit/editor-common/keymaps';
|
|
6
7
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
8
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
8
9
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
10
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
11
|
|
|
10
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
arrowLeftFromTable,
|
|
14
|
+
arrowRightFromTable,
|
|
15
|
+
shiftArrowUpFromTable,
|
|
16
|
+
} from '../commands/selection';
|
|
11
17
|
import type tablePlugin from '../index';
|
|
12
18
|
|
|
13
19
|
export function tableSelectionKeymapPlugin(
|
|
@@ -29,6 +35,14 @@ export function tableSelectionKeymapPlugin(
|
|
|
29
35
|
list,
|
|
30
36
|
);
|
|
31
37
|
|
|
38
|
+
if (getBooleanFF('platform.editor.table.shift-arrowup-fix')) {
|
|
39
|
+
bindKeymapWithCommand(
|
|
40
|
+
shiftArrowUp.common!,
|
|
41
|
+
shiftArrowUpFromTable(editorSelectionAPI)(),
|
|
42
|
+
list,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
return keymap(list) as SafePlugin;
|
|
33
47
|
}
|
|
34
48
|
|
|
@@ -420,7 +420,9 @@ export const getToolbarCellOptionsConfig = (
|
|
|
420
420
|
};
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
-
const getClosestSelectionRect = (
|
|
423
|
+
export const getClosestSelectionRect = (
|
|
424
|
+
state: EditorState,
|
|
425
|
+
): Rect | undefined => {
|
|
424
426
|
const selection = state.selection;
|
|
425
427
|
return isSelectionType(selection, 'cell')
|
|
426
428
|
? getSelectionRect(selection)!
|
|
@@ -367,3 +367,19 @@ export type InvalidNodeAttr = {
|
|
|
367
367
|
spanValue: number;
|
|
368
368
|
tableLocalId: string;
|
|
369
369
|
};
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Drag and Drop interfaces
|
|
373
|
+
*/
|
|
374
|
+
export type DraggableType = 'table-row' | 'table-column';
|
|
375
|
+
export interface DraggableSourceData extends Record<string, unknown> {
|
|
376
|
+
type: DraggableType;
|
|
377
|
+
localId: string;
|
|
378
|
+
indexes: number[];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface DraggableTargetData extends Record<string, unknown> {
|
|
382
|
+
type: DraggableType;
|
|
383
|
+
localId: string;
|
|
384
|
+
targetIndex: number;
|
|
385
|
+
}
|
package/tsconfig.app.json
CHANGED
|
@@ -69,6 +69,12 @@
|
|
|
69
69
|
{
|
|
70
70
|
"path": "../../platform/feature-flags/tsconfig.app.json"
|
|
71
71
|
},
|
|
72
|
+
{
|
|
73
|
+
"path": "../../pragmatic-drag-and-drop/core/tsconfig.app.json"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"path": "../../pragmatic-drag-and-drop/hitbox/tsconfig.app.json"
|
|
77
|
+
},
|
|
72
78
|
{
|
|
73
79
|
"path": "../../design-system/theme/tsconfig.app.json"
|
|
74
80
|
},
|