@atlaskit/editor-plugin-table 5.3.3 → 5.3.5
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 +12 -0
- package/dist/cjs/plugins/table/nodeviews/TableRow.js +53 -35
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -9
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
- package/dist/es2019/plugins/table/nodeviews/TableRow.js +22 -7
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -5
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +11 -10
- package/dist/esm/plugins/table/nodeviews/TableRow.js +53 -35
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +30 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +1 -4
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +9 -9
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +3 -1
- package/package.json +1 -1
- package/src/plugins/table/nodeviews/TableRow.ts +12 -6
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +42 -6
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +0 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +19 -12
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -24
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -10
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +0 -18
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +0 -3
- package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#41864](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41864) [`34e85d7299e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/34e85d7299e) - The table row nodeview needs to fetch the current live index and id when the canDrop and getData DnD methods are called. This is due to the fact that prosemirror reorders the tr elements efficently which causes the target indexes to be reordered and never updated.
|
|
8
|
+
|
|
9
|
+
## 5.3.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#41793](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41793) [`7e48d39f900`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7e48d39f900) - Connected the Pragmatic DnD monitor to the new drop target insert line decorations
|
|
14
|
+
|
|
3
15
|
## 5.3.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -168,6 +168,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
168
168
|
}, {
|
|
169
169
|
key: "addDropTarget",
|
|
170
170
|
value: function addDropTarget(element) {
|
|
171
|
+
var _this2 = this;
|
|
171
172
|
var pos = this.getPos();
|
|
172
173
|
if (!Number.isFinite(pos)) {
|
|
173
174
|
return;
|
|
@@ -175,15 +176,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
175
176
|
if (this.dropTargetCleanup) {
|
|
176
177
|
this.dropTargetCleanup();
|
|
177
178
|
}
|
|
178
|
-
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
179
|
-
var targetIndex = resolvedPos.index();
|
|
180
|
-
var localId = resolvedPos.parent.attrs.localId;
|
|
181
179
|
this.dropTargetCleanup = (0, _element.dropTargetForElements)({
|
|
182
180
|
element: element,
|
|
183
181
|
canDrop: function canDrop(_ref2) {
|
|
184
182
|
var _data$indexes, _data$indexes2;
|
|
185
183
|
var source = _ref2.source;
|
|
186
184
|
var data = source.data;
|
|
185
|
+
var _this2$getCurrentData = _this2.getCurrentData(),
|
|
186
|
+
localId = _this2$getCurrentData.localId,
|
|
187
|
+
targetIndex = _this2$getCurrentData.targetIndex;
|
|
187
188
|
return (
|
|
188
189
|
// Only draggables of row type can be dropped on this target
|
|
189
190
|
data.type === 'table-row' &&
|
|
@@ -193,9 +194,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
193
194
|
!!((_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
|
);
|
|
195
196
|
},
|
|
197
|
+
getIsSticky: function getIsSticky() {
|
|
198
|
+
return true;
|
|
199
|
+
},
|
|
196
200
|
getData: function getData(_ref3) {
|
|
197
201
|
var input = _ref3.input,
|
|
198
202
|
element = _ref3.element;
|
|
203
|
+
var _this2$getCurrentData2 = _this2.getCurrentData(),
|
|
204
|
+
localId = _this2$getCurrentData2.localId,
|
|
205
|
+
targetIndex = _this2$getCurrentData2.targetIndex;
|
|
199
206
|
var data = {
|
|
200
207
|
localId: localId,
|
|
201
208
|
type: 'table-row',
|
|
@@ -209,6 +216,17 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
209
216
|
}
|
|
210
217
|
});
|
|
211
218
|
}
|
|
219
|
+
}, {
|
|
220
|
+
key: "getCurrentData",
|
|
221
|
+
value: function getCurrentData() {
|
|
222
|
+
var resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
223
|
+
var targetIndex = resolvedPos.index();
|
|
224
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
225
|
+
return {
|
|
226
|
+
targetIndex: targetIndex,
|
|
227
|
+
localId: localId
|
|
228
|
+
};
|
|
229
|
+
}
|
|
212
230
|
}, {
|
|
213
231
|
key: "subscribe",
|
|
214
232
|
value: function subscribe() {
|
|
@@ -257,7 +275,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
257
275
|
}, {
|
|
258
276
|
key: "initObservers",
|
|
259
277
|
value: function initObservers() {
|
|
260
|
-
var
|
|
278
|
+
var _this3 = this;
|
|
261
279
|
if (!this.dom || this.dom.dataset.isObserved) {
|
|
262
280
|
return;
|
|
263
281
|
}
|
|
@@ -274,15 +292,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
274
292
|
window.requestAnimationFrame(function () {
|
|
275
293
|
var _getTree;
|
|
276
294
|
// we expect tree to be defined after animation frame
|
|
277
|
-
var tableContainer = (_getTree = (0, _dom2.getTree)(
|
|
295
|
+
var tableContainer = (_getTree = (0, _dom2.getTree)(_this3.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(_types.TableCssClassName.NODEVIEW_WRAPPER));
|
|
278
296
|
if (tableContainer) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
[
|
|
297
|
+
_this3.sentinels.top = tableContainer.getElementsByClassName(_types.TableCssClassName.TABLE_STICKY_SENTINEL_TOP).item(0);
|
|
298
|
+
_this3.sentinels.bottom = tableContainer.getElementsByClassName(_types.TableCssClassName.TABLE_STICKY_SENTINEL_BOTTOM).item(0);
|
|
299
|
+
[_this3.sentinels.top, _this3.sentinels.bottom].forEach(function (el) {
|
|
282
300
|
// skip if already observed for another row on this table
|
|
283
301
|
if (el && !el.dataset.isObserved) {
|
|
284
302
|
el.dataset.isObserved = 'true';
|
|
285
|
-
|
|
303
|
+
_this3.intersectionObserver.observe(el);
|
|
286
304
|
}
|
|
287
305
|
});
|
|
288
306
|
}
|
|
@@ -294,27 +312,27 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
294
312
|
}, {
|
|
295
313
|
key: "createResizeObserver",
|
|
296
314
|
value: function createResizeObserver() {
|
|
297
|
-
var
|
|
315
|
+
var _this4 = this;
|
|
298
316
|
this.resizeObserver = new ResizeObserver(function (entries) {
|
|
299
|
-
var tree = (0, _dom2.getTree)(
|
|
317
|
+
var tree = (0, _dom2.getTree)(_this4.dom);
|
|
300
318
|
if (!tree) {
|
|
301
319
|
return;
|
|
302
320
|
}
|
|
303
321
|
var table = tree.table;
|
|
304
322
|
entries.forEach(function (entry) {
|
|
305
|
-
var
|
|
323
|
+
var _this4$editorScrollab;
|
|
306
324
|
// On resize of the parent scroll element we need to adjust the width
|
|
307
325
|
// of the sticky header
|
|
308
|
-
if (entry.target.className === ((
|
|
309
|
-
|
|
326
|
+
if (entry.target.className === ((_this4$editorScrollab = _this4.editorScrollableElement) === null || _this4$editorScrollab === void 0 ? void 0 : _this4$editorScrollab.className)) {
|
|
327
|
+
_this4.updateStickyHeaderWidth();
|
|
310
328
|
} else {
|
|
311
329
|
var newHeight = entry.contentRect ? entry.contentRect.height : entry.target.offsetHeight;
|
|
312
|
-
if (
|
|
330
|
+
if (_this4.sentinels.bottom &&
|
|
313
331
|
// When the table header is sticky, it would be taller by a 1px (border-bottom),
|
|
314
332
|
// So we adding this check to allow a 1px difference.
|
|
315
|
-
Math.abs(newHeight - (
|
|
316
|
-
|
|
317
|
-
|
|
333
|
+
Math.abs(newHeight - (_this4.stickyRowHeight || 0)) > _consts.stickyHeaderBorderBottomWidth) {
|
|
334
|
+
_this4.stickyRowHeight = newHeight;
|
|
335
|
+
_this4.sentinels.bottom.style.bottom = "".concat(_consts.tableScrollbarOffset + _consts.stickyRowOffsetTop + newHeight, "px");
|
|
318
336
|
(0, _dom.updateStickyMargins)(table);
|
|
319
337
|
}
|
|
320
338
|
}
|
|
@@ -324,9 +342,9 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
324
342
|
}, {
|
|
325
343
|
key: "createIntersectionObserver",
|
|
326
344
|
value: function createIntersectionObserver() {
|
|
327
|
-
var
|
|
345
|
+
var _this5 = this;
|
|
328
346
|
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
329
|
-
var tree = (0, _dom2.getTree)(
|
|
347
|
+
var tree = (0, _dom2.getTree)(_this5.dom);
|
|
330
348
|
if (!tree) {
|
|
331
349
|
return;
|
|
332
350
|
}
|
|
@@ -349,28 +367,28 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
349
367
|
var sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
350
368
|
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
351
369
|
var _entry$rootBounds3;
|
|
352
|
-
tree &&
|
|
353
|
-
|
|
370
|
+
tree && _this5.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
371
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
354
372
|
} else {
|
|
355
|
-
table &&
|
|
373
|
+
table && _this5.makeRowHeaderNotSticky(table);
|
|
356
374
|
}
|
|
357
375
|
}
|
|
358
376
|
if (target.classList.contains(_types.TableCssClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
359
377
|
var _entry$rootBounds4;
|
|
360
|
-
var sentinelIsAboveScrollArea = entry.boundingClientRect.top -
|
|
378
|
+
var sentinelIsAboveScrollArea = entry.boundingClientRect.top - _this5.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
361
379
|
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
362
380
|
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
363
381
|
if (_utils.browser.gecko) {
|
|
364
|
-
if (
|
|
365
|
-
|
|
382
|
+
if (_this5.lastStickyTimestamp && Date.now() - _this5.lastStickyTimestamp > _consts.STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
383
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
366
384
|
}
|
|
367
385
|
} else {
|
|
368
|
-
|
|
386
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
369
387
|
}
|
|
370
388
|
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
371
389
|
var _entry$rootBounds5;
|
|
372
|
-
tree &&
|
|
373
|
-
|
|
390
|
+
tree && _this5.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
391
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
374
392
|
}
|
|
375
393
|
}
|
|
376
394
|
return;
|
|
@@ -445,12 +463,12 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
445
463
|
}, {
|
|
446
464
|
key: "refireIntersectionObservers",
|
|
447
465
|
value: function refireIntersectionObservers() {
|
|
448
|
-
var
|
|
466
|
+
var _this6 = this;
|
|
449
467
|
if (this.isSticky) {
|
|
450
468
|
[this.sentinels.top, this.sentinels.bottom].forEach(function (el) {
|
|
451
|
-
if (el &&
|
|
452
|
-
|
|
453
|
-
|
|
469
|
+
if (el && _this6.intersectionObserver) {
|
|
470
|
+
_this6.intersectionObserver.unobserve(el);
|
|
471
|
+
_this6.intersectionObserver.observe(el);
|
|
454
472
|
}
|
|
455
473
|
});
|
|
456
474
|
}
|
|
@@ -459,7 +477,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
459
477
|
key: "makeHeaderRowSticky",
|
|
460
478
|
value: function makeHeaderRowSticky(tree, scrollTop) {
|
|
461
479
|
var _tbody$firstChild,
|
|
462
|
-
|
|
480
|
+
_this7 = this;
|
|
463
481
|
// If header row height is more than 50% of viewport height don't do this
|
|
464
482
|
if (this.isSticky || this.stickyRowHeight && this.stickyRowHeight > window.innerHeight / 2) {
|
|
465
483
|
return;
|
|
@@ -496,7 +514,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
496
514
|
});
|
|
497
515
|
var fastScrollThresholdMs = 500;
|
|
498
516
|
setTimeout(function () {
|
|
499
|
-
|
|
517
|
+
_this7.refireIntersectionObservers();
|
|
500
518
|
}, fastScrollThresholdMs);
|
|
501
519
|
}
|
|
502
520
|
this.dom.style.top = "".concat(domTop, "px");
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.updatePluginStateDecorations = exports.setDropTarget = exports.getDecorations = exports.clearDropTarget = void 0;
|
|
6
|
+
exports.updatePluginStateDecorations = exports.setDropTarget = exports.moveSource = exports.getDecorations = exports.clearDropTarget = void 0;
|
|
7
7
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
8
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
8
9
|
var _types = require("../../types");
|
|
9
|
-
var
|
|
10
|
+
var _utils2 = require("../../utils");
|
|
10
11
|
var _actions = require("./actions");
|
|
12
|
+
var _consts = require("./consts");
|
|
11
13
|
var _pluginFactory = require("./plugin-factory");
|
|
12
14
|
var _pluginKey = require("./plugin-key");
|
|
13
15
|
// TODO: This command is a placeholder example. Please replace this if required.
|
|
@@ -16,7 +18,7 @@ var getDecorations = exports.getDecorations = function getDecorations(state) {
|
|
|
16
18
|
return ((_pluginKey$getState = _pluginKey.pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || _view.DecorationSet.empty;
|
|
17
19
|
};
|
|
18
20
|
var updatePluginStateDecorations = exports.updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
|
|
19
|
-
return (0,
|
|
21
|
+
return (0, _utils2.updateDecorations)(state.doc, getDecorations(state), decorations, key);
|
|
20
22
|
};
|
|
21
23
|
var setDropTarget = exports.setDropTarget = function setDropTarget(type, index, tr) {
|
|
22
24
|
return (0, _pluginFactory.createCommand)(function (state) {
|
|
@@ -28,9 +30,9 @@ var setDropTarget = exports.setDropTarget = function setDropTarget(type, index,
|
|
|
28
30
|
}
|
|
29
31
|
var decorationSet = _view.DecorationSet.empty;
|
|
30
32
|
if (type === 'column') {
|
|
31
|
-
decorationSet = updatePluginStateDecorations(state, (0,
|
|
33
|
+
decorationSet = updatePluginStateDecorations(state, (0, _utils2.createColumnInsertLine)(index, state.selection), _types.TableDecorations.COLUMN_INSERT_LINE);
|
|
32
34
|
} else if (type === 'row') {
|
|
33
|
-
decorationSet = updatePluginStateDecorations(state, (0,
|
|
35
|
+
decorationSet = updatePluginStateDecorations(state, (0, _utils2.createRowInsertLine)(index, state.selection), _types.TableDecorations.ROW_INSERT_LINE);
|
|
34
36
|
}
|
|
35
37
|
return {
|
|
36
38
|
type: _actions.DragAndDropActionType.SET_DROP_TARGET,
|
|
@@ -45,12 +47,36 @@ var setDropTarget = exports.setDropTarget = function setDropTarget(type, index,
|
|
|
45
47
|
});
|
|
46
48
|
};
|
|
47
49
|
var clearDropTarget = exports.clearDropTarget = function clearDropTarget(tr) {
|
|
48
|
-
return (0, _pluginFactory.createCommand)({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
return (0, _pluginFactory.createCommand)(function (state) {
|
|
51
|
+
var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
|
|
52
|
+
dropTargetType = _getPluginState2.dropTargetType,
|
|
53
|
+
dropTargetIndex = _getPluginState2.dropTargetIndex;
|
|
54
|
+
if (dropTargetType === _consts.DropTargetType.NONE && dropTargetIndex === 0) {
|
|
55
|
+
return false;
|
|
52
56
|
}
|
|
57
|
+
return {
|
|
58
|
+
type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
59
|
+
data: {
|
|
60
|
+
decorationSet: _view.DecorationSet.empty
|
|
61
|
+
}
|
|
62
|
+
};
|
|
53
63
|
}, function (originalTr) {
|
|
54
64
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
55
65
|
});
|
|
66
|
+
};
|
|
67
|
+
var moveSource = exports.moveSource = function moveSource(sourceType, sourceIndex, targetIndex) {
|
|
68
|
+
return (0, _pluginFactory.createCommand)(function (state) {
|
|
69
|
+
return {
|
|
70
|
+
type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
71
|
+
data: {
|
|
72
|
+
decorationSet: _view.DecorationSet.empty
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}, function (tr) {
|
|
76
|
+
if (sourceIndex === targetIndex) {
|
|
77
|
+
return tr.setMeta('addToHistory', false);
|
|
78
|
+
}
|
|
79
|
+
var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
|
|
80
|
+
return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
|
|
81
|
+
});
|
|
56
82
|
};
|
|
@@ -8,7 +8,6 @@ exports.getPluginState = exports.createPluginState = exports.createCommand = voi
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
10
|
var _pluginKey = require("../plugin-key");
|
|
11
|
-
var _handlers = require("./handlers");
|
|
12
11
|
var _pluginKey2 = require("./plugin-key");
|
|
13
12
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
14
13
|
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; }
|
|
@@ -29,9 +28,7 @@ var _pluginFactory = (0, _utils.pluginFactory)(_pluginKey2.pluginKey, _reducer.d
|
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
return pluginState;
|
|
32
|
-
}
|
|
33
|
-
onDocChanged: _handlers.handleDocOrSelectionChanged,
|
|
34
|
-
onSelectionChanged: _handlers.handleDocOrSelectionChanged
|
|
31
|
+
}
|
|
35
32
|
}),
|
|
36
33
|
createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
|
|
37
34
|
createCommand = exports.createCommand = _pluginFactory.createCommand,
|
|
@@ -8,10 +8,10 @@ exports.createPlugin = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
-
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
11
|
var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
13
12
|
var _mergedCells = require("../../utils/merged-cells");
|
|
14
13
|
var _pluginFactory = require("../plugin-factory");
|
|
14
|
+
var _commands = require("./commands");
|
|
15
15
|
var _consts = require("./consts");
|
|
16
16
|
var _pluginFactory2 = require("./plugin-factory");
|
|
17
17
|
var _pluginKey = require("./plugin-key");
|
|
@@ -53,25 +53,25 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
53
53
|
},
|
|
54
54
|
onDrag: function onDrag(event) {
|
|
55
55
|
var data = (0, _monitor.getDraggableDataFromEvent)(event);
|
|
56
|
-
|
|
57
56
|
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
58
57
|
if (!data) {
|
|
58
|
+
(0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
63
63
|
// insert location as to where the draggable will most likely be go. For example;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// );
|
|
64
|
+
var sourceType = data.sourceType,
|
|
65
|
+
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
66
|
+
var dropTargetType = sourceType === 'table-row' ? _consts.DropTargetType.ROW : _consts.DropTargetType.COLUMN;
|
|
67
|
+
(0, _commands.setDropTarget)(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
69
68
|
},
|
|
70
69
|
onDrop: function onDrop(event) {
|
|
71
70
|
var data = (0, _monitor.getDraggableDataFromEvent)(event);
|
|
72
71
|
|
|
73
72
|
// If no data can be found then it's most like we do not want to perform any drop action
|
|
74
73
|
if (!data) {
|
|
74
|
+
(0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
var sourceType = data.sourceType,
|
|
@@ -81,12 +81,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventD
|
|
|
81
81
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
82
82
|
var hasMergedCells = sourceType === 'table-row' ? _mergedCells.hasMergedCellsInRow : _mergedCells.hasMergedCellsInColumn;
|
|
83
83
|
if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
|
|
84
|
+
(0, _commands.clearDropTarget)()(editorView.state, editorView.dispatch);
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
|
-
var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
|
|
87
87
|
var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
|
|
88
88
|
sourceIndex = _sourceIndexes[0];
|
|
89
|
-
|
|
89
|
+
(0, _commands.moveSource)(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
90
90
|
}
|
|
91
91
|
})
|
|
92
92
|
};
|
|
@@ -150,16 +150,17 @@ export default class TableRow extends TableNodeView {
|
|
|
150
150
|
if (this.dropTargetCleanup) {
|
|
151
151
|
this.dropTargetCleanup();
|
|
152
152
|
}
|
|
153
|
-
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
154
|
-
const targetIndex = resolvedPos.index();
|
|
155
|
-
const localId = resolvedPos.parent.attrs.localId;
|
|
156
153
|
this.dropTargetCleanup = dropTargetForElements({
|
|
157
154
|
element: element,
|
|
158
|
-
canDrop({
|
|
155
|
+
canDrop: ({
|
|
159
156
|
source
|
|
160
|
-
}) {
|
|
157
|
+
}) => {
|
|
161
158
|
var _data$indexes, _data$indexes2;
|
|
162
159
|
const data = source.data;
|
|
160
|
+
const {
|
|
161
|
+
localId,
|
|
162
|
+
targetIndex
|
|
163
|
+
} = this.getCurrentData();
|
|
163
164
|
return (
|
|
164
165
|
// Only draggables of row type can be dropped on this target
|
|
165
166
|
data.type === 'table-row' &&
|
|
@@ -169,10 +170,15 @@ export default class TableRow extends TableNodeView {
|
|
|
169
170
|
!!((_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
|
);
|
|
171
172
|
},
|
|
172
|
-
|
|
173
|
+
getIsSticky: () => true,
|
|
174
|
+
getData: ({
|
|
173
175
|
input,
|
|
174
176
|
element
|
|
175
|
-
}) {
|
|
177
|
+
}) => {
|
|
178
|
+
const {
|
|
179
|
+
localId,
|
|
180
|
+
targetIndex
|
|
181
|
+
} = this.getCurrentData();
|
|
176
182
|
const data = {
|
|
177
183
|
localId,
|
|
178
184
|
type: 'table-row',
|
|
@@ -186,6 +192,15 @@ export default class TableRow extends TableNodeView {
|
|
|
186
192
|
}
|
|
187
193
|
});
|
|
188
194
|
}
|
|
195
|
+
getCurrentData() {
|
|
196
|
+
const resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
197
|
+
const targetIndex = resolvedPos.index();
|
|
198
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
199
|
+
return {
|
|
200
|
+
targetIndex,
|
|
201
|
+
localId
|
|
202
|
+
};
|
|
203
|
+
}
|
|
189
204
|
subscribe() {
|
|
190
205
|
this.editorScrollableElement = findOverflowScrollParent(this.view.dom) || window;
|
|
191
206
|
if (this.editorScrollableElement) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
+
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
2
3
|
import { TableDecorations } from '../../types';
|
|
3
4
|
import { createColumnInsertLine, createRowInsertLine, updateDecorations } from '../../utils';
|
|
4
5
|
import { DragAndDropActionType } from './actions';
|
|
6
|
+
import { DropTargetType } from './consts';
|
|
5
7
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
6
8
|
import { pluginKey } from './plugin-key';
|
|
7
9
|
|
|
@@ -34,9 +36,32 @@ export const setDropTarget = (type, index, tr) => createCommand(state => {
|
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
}, originalTr => (tr || originalTr).setMeta('addToHistory', false));
|
|
37
|
-
export const clearDropTarget = tr => createCommand({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
export const clearDropTarget = tr => createCommand(state => {
|
|
40
|
+
const {
|
|
41
|
+
dropTargetType,
|
|
42
|
+
dropTargetIndex
|
|
43
|
+
} = getPluginState(state);
|
|
44
|
+
if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
49
|
+
data: {
|
|
50
|
+
decorationSet: DecorationSet.empty
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}, originalTr => (tr || originalTr).setMeta('addToHistory', false));
|
|
54
|
+
export const moveSource = (sourceType, sourceIndex, targetIndex) => createCommand(state => {
|
|
55
|
+
return {
|
|
56
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
57
|
+
data: {
|
|
58
|
+
decorationSet: DecorationSet.empty
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, tr => {
|
|
62
|
+
if (sourceIndex === targetIndex) {
|
|
63
|
+
return tr.setMeta('addToHistory', false);
|
|
41
64
|
}
|
|
42
|
-
|
|
65
|
+
const move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
66
|
+
return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
|
|
67
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
3
|
-
import { handleDocOrSelectionChanged } from './handlers';
|
|
4
3
|
import { pluginKey } from './plugin-key';
|
|
5
4
|
import reducer from './reducer';
|
|
6
5
|
export const {
|
|
@@ -26,7 +25,5 @@ export const {
|
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
27
|
return pluginState;
|
|
29
|
-
}
|
|
30
|
-
onDocChanged: handleDocOrSelectionChanged,
|
|
31
|
-
onSelectionChanged: handleDocOrSelectionChanged
|
|
28
|
+
}
|
|
32
29
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
4
3
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
5
4
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
|
|
6
5
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
6
|
+
import { clearDropTarget, moveSource, setDropTarget } from './commands';
|
|
7
7
|
import { DropTargetType } from './consts';
|
|
8
8
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
9
9
|
import { pluginKey } from './plugin-key';
|
|
@@ -46,26 +46,27 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
46
46
|
},
|
|
47
47
|
onDrag(event) {
|
|
48
48
|
const data = getDraggableDataFromEvent(event);
|
|
49
|
-
|
|
50
49
|
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
51
50
|
if (!data) {
|
|
51
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
56
56
|
// insert location as to where the draggable will most likely be go. For example;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const {
|
|
58
|
+
sourceType,
|
|
59
|
+
targetAdjustedIndex
|
|
60
|
+
} = data;
|
|
61
|
+
const dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
|
|
62
|
+
setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
62
63
|
},
|
|
63
|
-
|
|
64
64
|
onDrop(event) {
|
|
65
65
|
const data = getDraggableDataFromEvent(event);
|
|
66
66
|
|
|
67
67
|
// If no data can be found then it's most like we do not want to perform any drop action
|
|
68
68
|
if (!data) {
|
|
69
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
const {
|
|
@@ -77,11 +78,11 @@ export const createPlugin = (dispatch, eventDispatcher) => {
|
|
|
77
78
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
78
79
|
const hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
79
80
|
if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
|
|
81
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
|
-
const move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
83
84
|
const [sourceIndex] = sourceIndexes;
|
|
84
|
-
|
|
85
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
85
86
|
}
|
|
86
87
|
})
|
|
87
88
|
};
|