@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
|
@@ -162,6 +162,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
162
162
|
}, {
|
|
163
163
|
key: "addDropTarget",
|
|
164
164
|
value: function addDropTarget(element) {
|
|
165
|
+
var _this2 = this;
|
|
165
166
|
var pos = this.getPos();
|
|
166
167
|
if (!Number.isFinite(pos)) {
|
|
167
168
|
return;
|
|
@@ -169,15 +170,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
169
170
|
if (this.dropTargetCleanup) {
|
|
170
171
|
this.dropTargetCleanup();
|
|
171
172
|
}
|
|
172
|
-
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
173
|
-
var targetIndex = resolvedPos.index();
|
|
174
|
-
var localId = resolvedPos.parent.attrs.localId;
|
|
175
173
|
this.dropTargetCleanup = dropTargetForElements({
|
|
176
174
|
element: element,
|
|
177
175
|
canDrop: function canDrop(_ref2) {
|
|
178
176
|
var _data$indexes, _data$indexes2;
|
|
179
177
|
var source = _ref2.source;
|
|
180
178
|
var data = source.data;
|
|
179
|
+
var _this2$getCurrentData = _this2.getCurrentData(),
|
|
180
|
+
localId = _this2$getCurrentData.localId,
|
|
181
|
+
targetIndex = _this2$getCurrentData.targetIndex;
|
|
181
182
|
return (
|
|
182
183
|
// Only draggables of row type can be dropped on this target
|
|
183
184
|
data.type === 'table-row' &&
|
|
@@ -187,9 +188,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
187
188
|
!!((_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
|
);
|
|
189
190
|
},
|
|
191
|
+
getIsSticky: function getIsSticky() {
|
|
192
|
+
return true;
|
|
193
|
+
},
|
|
190
194
|
getData: function getData(_ref3) {
|
|
191
195
|
var input = _ref3.input,
|
|
192
196
|
element = _ref3.element;
|
|
197
|
+
var _this2$getCurrentData2 = _this2.getCurrentData(),
|
|
198
|
+
localId = _this2$getCurrentData2.localId,
|
|
199
|
+
targetIndex = _this2$getCurrentData2.targetIndex;
|
|
193
200
|
var data = {
|
|
194
201
|
localId: localId,
|
|
195
202
|
type: 'table-row',
|
|
@@ -203,6 +210,17 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
203
210
|
}
|
|
204
211
|
});
|
|
205
212
|
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "getCurrentData",
|
|
215
|
+
value: function getCurrentData() {
|
|
216
|
+
var resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
217
|
+
var targetIndex = resolvedPos.index();
|
|
218
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
219
|
+
return {
|
|
220
|
+
targetIndex: targetIndex,
|
|
221
|
+
localId: localId
|
|
222
|
+
};
|
|
223
|
+
}
|
|
206
224
|
}, {
|
|
207
225
|
key: "subscribe",
|
|
208
226
|
value: function subscribe() {
|
|
@@ -251,7 +269,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
251
269
|
}, {
|
|
252
270
|
key: "initObservers",
|
|
253
271
|
value: function initObservers() {
|
|
254
|
-
var
|
|
272
|
+
var _this3 = this;
|
|
255
273
|
if (!this.dom || this.dom.dataset.isObserved) {
|
|
256
274
|
return;
|
|
257
275
|
}
|
|
@@ -268,15 +286,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
268
286
|
window.requestAnimationFrame(function () {
|
|
269
287
|
var _getTree;
|
|
270
288
|
// we expect tree to be defined after animation frame
|
|
271
|
-
var tableContainer = (_getTree = getTree(
|
|
289
|
+
var tableContainer = (_getTree = getTree(_this3.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(TableCssClassName.NODEVIEW_WRAPPER));
|
|
272
290
|
if (tableContainer) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
[
|
|
291
|
+
_this3.sentinels.top = tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_TOP).item(0);
|
|
292
|
+
_this3.sentinels.bottom = tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_BOTTOM).item(0);
|
|
293
|
+
[_this3.sentinels.top, _this3.sentinels.bottom].forEach(function (el) {
|
|
276
294
|
// skip if already observed for another row on this table
|
|
277
295
|
if (el && !el.dataset.isObserved) {
|
|
278
296
|
el.dataset.isObserved = 'true';
|
|
279
|
-
|
|
297
|
+
_this3.intersectionObserver.observe(el);
|
|
280
298
|
}
|
|
281
299
|
});
|
|
282
300
|
}
|
|
@@ -288,27 +306,27 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
288
306
|
}, {
|
|
289
307
|
key: "createResizeObserver",
|
|
290
308
|
value: function createResizeObserver() {
|
|
291
|
-
var
|
|
309
|
+
var _this4 = this;
|
|
292
310
|
this.resizeObserver = new ResizeObserver(function (entries) {
|
|
293
|
-
var tree = getTree(
|
|
311
|
+
var tree = getTree(_this4.dom);
|
|
294
312
|
if (!tree) {
|
|
295
313
|
return;
|
|
296
314
|
}
|
|
297
315
|
var table = tree.table;
|
|
298
316
|
entries.forEach(function (entry) {
|
|
299
|
-
var
|
|
317
|
+
var _this4$editorScrollab;
|
|
300
318
|
// On resize of the parent scroll element we need to adjust the width
|
|
301
319
|
// of the sticky header
|
|
302
|
-
if (entry.target.className === ((
|
|
303
|
-
|
|
320
|
+
if (entry.target.className === ((_this4$editorScrollab = _this4.editorScrollableElement) === null || _this4$editorScrollab === void 0 ? void 0 : _this4$editorScrollab.className)) {
|
|
321
|
+
_this4.updateStickyHeaderWidth();
|
|
304
322
|
} else {
|
|
305
323
|
var newHeight = entry.contentRect ? entry.contentRect.height : entry.target.offsetHeight;
|
|
306
|
-
if (
|
|
324
|
+
if (_this4.sentinels.bottom &&
|
|
307
325
|
// When the table header is sticky, it would be taller by a 1px (border-bottom),
|
|
308
326
|
// So we adding this check to allow a 1px difference.
|
|
309
|
-
Math.abs(newHeight - (
|
|
310
|
-
|
|
311
|
-
|
|
327
|
+
Math.abs(newHeight - (_this4.stickyRowHeight || 0)) > stickyHeaderBorderBottomWidth) {
|
|
328
|
+
_this4.stickyRowHeight = newHeight;
|
|
329
|
+
_this4.sentinels.bottom.style.bottom = "".concat(tableScrollbarOffset + stickyRowOffsetTop + newHeight, "px");
|
|
312
330
|
updateTableMargin(table);
|
|
313
331
|
}
|
|
314
332
|
}
|
|
@@ -318,9 +336,9 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
318
336
|
}, {
|
|
319
337
|
key: "createIntersectionObserver",
|
|
320
338
|
value: function createIntersectionObserver() {
|
|
321
|
-
var
|
|
339
|
+
var _this5 = this;
|
|
322
340
|
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
323
|
-
var tree = getTree(
|
|
341
|
+
var tree = getTree(_this5.dom);
|
|
324
342
|
if (!tree) {
|
|
325
343
|
return;
|
|
326
344
|
}
|
|
@@ -343,28 +361,28 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
343
361
|
var sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
344
362
|
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
345
363
|
var _entry$rootBounds3;
|
|
346
|
-
tree &&
|
|
347
|
-
|
|
364
|
+
tree && _this5.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
365
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
348
366
|
} else {
|
|
349
|
-
table &&
|
|
367
|
+
table && _this5.makeRowHeaderNotSticky(table);
|
|
350
368
|
}
|
|
351
369
|
}
|
|
352
370
|
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
353
371
|
var _entry$rootBounds4;
|
|
354
|
-
var sentinelIsAboveScrollArea = entry.boundingClientRect.top -
|
|
372
|
+
var sentinelIsAboveScrollArea = entry.boundingClientRect.top - _this5.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
355
373
|
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
356
374
|
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
357
375
|
if (browser.gecko) {
|
|
358
|
-
if (
|
|
359
|
-
|
|
376
|
+
if (_this5.lastStickyTimestamp && Date.now() - _this5.lastStickyTimestamp > STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
377
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
360
378
|
}
|
|
361
379
|
} else {
|
|
362
|
-
|
|
380
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
363
381
|
}
|
|
364
382
|
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
365
383
|
var _entry$rootBounds5;
|
|
366
|
-
tree &&
|
|
367
|
-
|
|
384
|
+
tree && _this5.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
385
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
368
386
|
}
|
|
369
387
|
}
|
|
370
388
|
return;
|
|
@@ -439,12 +457,12 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
439
457
|
}, {
|
|
440
458
|
key: "refireIntersectionObservers",
|
|
441
459
|
value: function refireIntersectionObservers() {
|
|
442
|
-
var
|
|
460
|
+
var _this6 = this;
|
|
443
461
|
if (this.isSticky) {
|
|
444
462
|
[this.sentinels.top, this.sentinels.bottom].forEach(function (el) {
|
|
445
|
-
if (el &&
|
|
446
|
-
|
|
447
|
-
|
|
463
|
+
if (el && _this6.intersectionObserver) {
|
|
464
|
+
_this6.intersectionObserver.unobserve(el);
|
|
465
|
+
_this6.intersectionObserver.observe(el);
|
|
448
466
|
}
|
|
449
467
|
});
|
|
450
468
|
}
|
|
@@ -453,7 +471,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
453
471
|
key: "makeHeaderRowSticky",
|
|
454
472
|
value: function makeHeaderRowSticky(tree, scrollTop) {
|
|
455
473
|
var _tbody$firstChild,
|
|
456
|
-
|
|
474
|
+
_this7 = this;
|
|
457
475
|
// If header row height is more than 50% of viewport height don't do this
|
|
458
476
|
if (this.isSticky || this.stickyRowHeight && this.stickyRowHeight > window.innerHeight / 2) {
|
|
459
477
|
return;
|
|
@@ -490,7 +508,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
490
508
|
});
|
|
491
509
|
var fastScrollThresholdMs = 500;
|
|
492
510
|
setTimeout(function () {
|
|
493
|
-
|
|
511
|
+
_this7.refireIntersectionObservers();
|
|
494
512
|
}, fastScrollThresholdMs);
|
|
495
513
|
}
|
|
496
514
|
this.dom.style.top = "".concat(domTop, "px");
|
|
@@ -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
|
|
|
@@ -40,12 +42,36 @@ export var setDropTarget = function setDropTarget(type, index, tr) {
|
|
|
40
42
|
});
|
|
41
43
|
};
|
|
42
44
|
export var clearDropTarget = function clearDropTarget(tr) {
|
|
43
|
-
return createCommand({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
return createCommand(function (state) {
|
|
46
|
+
var _getPluginState2 = getPluginState(state),
|
|
47
|
+
dropTargetType = _getPluginState2.dropTargetType,
|
|
48
|
+
dropTargetIndex = _getPluginState2.dropTargetIndex;
|
|
49
|
+
if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
|
|
50
|
+
return false;
|
|
47
51
|
}
|
|
52
|
+
return {
|
|
53
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
54
|
+
data: {
|
|
55
|
+
decorationSet: DecorationSet.empty
|
|
56
|
+
}
|
|
57
|
+
};
|
|
48
58
|
}, function (originalTr) {
|
|
49
59
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
50
60
|
});
|
|
61
|
+
};
|
|
62
|
+
export var moveSource = function moveSource(sourceType, sourceIndex, targetIndex) {
|
|
63
|
+
return createCommand(function (state) {
|
|
64
|
+
return {
|
|
65
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
66
|
+
data: {
|
|
67
|
+
decorationSet: DecorationSet.empty
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, function (tr) {
|
|
71
|
+
if (sourceIndex === targetIndex) {
|
|
72
|
+
return tr.setMeta('addToHistory', false);
|
|
73
|
+
}
|
|
74
|
+
var move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
75
|
+
return move(sourceIndex, targetIndex + (sourceIndex > targetIndex ? 0 : -1))(tr);
|
|
76
|
+
});
|
|
51
77
|
};
|
|
@@ -3,7 +3,6 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
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; }
|
|
4
4
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
6
|
-
import { handleDocOrSelectionChanged } from './handlers';
|
|
7
6
|
import { pluginKey } from './plugin-key';
|
|
8
7
|
import reducer from './reducer';
|
|
9
8
|
var _pluginFactory = pluginFactory(pluginKey, reducer, {
|
|
@@ -22,9 +21,7 @@ var _pluginFactory = pluginFactory(pluginKey, reducer, {
|
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
return pluginState;
|
|
25
|
-
}
|
|
26
|
-
onDocChanged: handleDocOrSelectionChanged,
|
|
27
|
-
onSelectionChanged: handleDocOrSelectionChanged
|
|
24
|
+
}
|
|
28
25
|
}),
|
|
29
26
|
createPluginState = _pluginFactory.createPluginState,
|
|
30
27
|
createCommand = _pluginFactory.createCommand,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
5
4
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
6
5
|
import { hasMergedCellsInColumn, hasMergedCellsInRow } from '../../utils/merged-cells';
|
|
7
6
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
7
|
+
import { clearDropTarget, moveSource, setDropTarget } from './commands';
|
|
8
8
|
import { DropTargetType } from './consts';
|
|
9
9
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
10
10
|
import { pluginKey } from './plugin-key';
|
|
@@ -46,25 +46,25 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
46
46
|
},
|
|
47
47
|
onDrag: function onDrag(event) {
|
|
48
48
|
var 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
|
+
var sourceType = data.sourceType,
|
|
58
|
+
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
59
|
+
var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
|
|
60
|
+
setDropTarget(dropTargetType, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
62
61
|
},
|
|
63
62
|
onDrop: function onDrop(event) {
|
|
64
63
|
var data = getDraggableDataFromEvent(event);
|
|
65
64
|
|
|
66
65
|
// If no data can be found then it's most like we do not want to perform any drop action
|
|
67
66
|
if (!data) {
|
|
67
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
var sourceType = data.sourceType,
|
|
@@ -74,12 +74,12 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
|
74
74
|
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
75
75
|
var hasMergedCells = sourceType === 'table-row' ? hasMergedCellsInRow : hasMergedCellsInColumn;
|
|
76
76
|
if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
|
|
77
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
|
-
var move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
80
80
|
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
81
81
|
sourceIndex = _sourceIndexes[0];
|
|
82
|
-
|
|
82
|
+
moveSource(sourceType, sourceIndex, targetAdjustedIndex)(editorView.state, editorView.dispatch);
|
|
83
83
|
}
|
|
84
84
|
})
|
|
85
85
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { DraggableType } from '../../types';
|
|
4
5
|
import { TableDecorations } from '../../types';
|
|
5
|
-
import
|
|
6
|
+
import { DropTargetType } from './consts';
|
|
6
7
|
export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
7
8
|
export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
|
|
8
9
|
export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
9
10
|
export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
11
|
+
export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { DraggableType } from '../../types';
|
|
4
5
|
import { TableDecorations } from '../../types';
|
|
5
|
-
import
|
|
6
|
+
import { DropTargetType } from './consts';
|
|
6
7
|
export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
7
8
|
export declare const updatePluginStateDecorations: (state: EditorState, decorations: Decoration[], key: TableDecorations) => DecorationSet;
|
|
8
9
|
export declare const setDropTarget: (type: DropTargetType, index: number, tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
9
10
|
export declare const clearDropTarget: (tr?: Transaction) => import("@atlaskit/editor-common/types").Command;
|
|
11
|
+
export declare const moveSource: (sourceType: DraggableType, sourceIndex: number, targetIndex: number) => import("@atlaskit/editor-common/types").Command;
|
package/package.json
CHANGED
|
@@ -192,14 +192,11 @@ export default class TableRow
|
|
|
192
192
|
this.dropTargetCleanup();
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
196
|
-
const targetIndex = resolvedPos.index();
|
|
197
|
-
const localId = resolvedPos.parent.attrs.localId;
|
|
198
|
-
|
|
199
195
|
this.dropTargetCleanup = dropTargetForElements({
|
|
200
196
|
element: element,
|
|
201
|
-
canDrop({ source }) {
|
|
197
|
+
canDrop: ({ source }) => {
|
|
202
198
|
const data = source.data as DraggableSourceData;
|
|
199
|
+
const { localId, targetIndex } = this.getCurrentData();
|
|
203
200
|
return (
|
|
204
201
|
// Only draggables of row type can be dropped on this target
|
|
205
202
|
data.type === 'table-row' &&
|
|
@@ -210,7 +207,9 @@ export default class TableRow
|
|
|
210
207
|
data.indexes?.indexOf(targetIndex) === -1
|
|
211
208
|
);
|
|
212
209
|
},
|
|
213
|
-
|
|
210
|
+
getIsSticky: () => true,
|
|
211
|
+
getData: ({ input, element }) => {
|
|
212
|
+
const { localId, targetIndex } = this.getCurrentData();
|
|
214
213
|
const data = {
|
|
215
214
|
localId,
|
|
216
215
|
type: 'table-row',
|
|
@@ -225,6 +224,13 @@ export default class TableRow
|
|
|
225
224
|
});
|
|
226
225
|
}
|
|
227
226
|
|
|
227
|
+
private getCurrentData() {
|
|
228
|
+
const resolvedPos = this.view.state.doc.resolve(this.getPos()!);
|
|
229
|
+
const targetIndex = resolvedPos.index();
|
|
230
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
231
|
+
return { targetIndex, localId };
|
|
232
|
+
}
|
|
233
|
+
|
|
228
234
|
private headerRowMouseScrollEnd = debounce(() => {
|
|
229
235
|
this.dom.classList.remove('no-pointer-events');
|
|
230
236
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT);
|
|
@@ -4,7 +4,9 @@ import type {
|
|
|
4
4
|
} from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import type { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
7
8
|
|
|
9
|
+
import type { DraggableType } from '../../types';
|
|
8
10
|
import { TableDecorations } from '../../types';
|
|
9
11
|
import {
|
|
10
12
|
createColumnInsertLine,
|
|
@@ -13,7 +15,7 @@ import {
|
|
|
13
15
|
} from '../../utils';
|
|
14
16
|
|
|
15
17
|
import { DragAndDropActionType } from './actions';
|
|
16
|
-
import
|
|
18
|
+
import { DropTargetType } from './consts';
|
|
17
19
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
18
20
|
import { pluginKey } from './plugin-key';
|
|
19
21
|
|
|
@@ -71,12 +73,46 @@ export const setDropTarget = (
|
|
|
71
73
|
|
|
72
74
|
export const clearDropTarget = (tr?: Transaction) =>
|
|
73
75
|
createCommand(
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
76
|
+
(state) => {
|
|
77
|
+
const { dropTargetType, dropTargetIndex } = getPluginState(state);
|
|
78
|
+
if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
84
|
+
data: {
|
|
85
|
+
decorationSet: DecorationSet.empty,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
79
88
|
},
|
|
80
89
|
(originalTr: Transaction) =>
|
|
81
90
|
(tr || originalTr).setMeta('addToHistory', false),
|
|
82
91
|
);
|
|
92
|
+
|
|
93
|
+
export const moveSource = (
|
|
94
|
+
sourceType: DraggableType,
|
|
95
|
+
sourceIndex: number,
|
|
96
|
+
targetIndex: number,
|
|
97
|
+
) =>
|
|
98
|
+
createCommand(
|
|
99
|
+
(state) => {
|
|
100
|
+
return {
|
|
101
|
+
type: DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
102
|
+
data: {
|
|
103
|
+
decorationSet: DecorationSet.empty,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
(tr: Transaction) => {
|
|
108
|
+
if (sourceIndex === targetIndex) {
|
|
109
|
+
return tr.setMeta('addToHistory', false);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
113
|
+
return move(
|
|
114
|
+
sourceIndex,
|
|
115
|
+
targetIndex + (sourceIndex > targetIndex ? 0 : -1),
|
|
116
|
+
)(tr);
|
|
117
|
+
},
|
|
118
|
+
);
|
|
@@ -2,7 +2,6 @@ import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
|
2
2
|
|
|
3
3
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
4
4
|
|
|
5
|
-
import { handleDocOrSelectionChanged } from './handlers';
|
|
6
5
|
import { pluginKey } from './plugin-key';
|
|
7
6
|
import reducer from './reducer';
|
|
8
7
|
|
|
@@ -28,6 +27,4 @@ export const { createPluginState, createCommand, getPluginState } =
|
|
|
28
27
|
}
|
|
29
28
|
return pluginState;
|
|
30
29
|
},
|
|
31
|
-
onDocChanged: handleDocOrSelectionChanged,
|
|
32
|
-
onSelectionChanged: handleDocOrSelectionChanged,
|
|
33
30
|
});
|
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import { moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
|
|
9
8
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
10
9
|
|
|
11
10
|
import type { DraggableSourceData } from '../../types';
|
|
@@ -15,6 +14,7 @@ import {
|
|
|
15
14
|
} from '../../utils/merged-cells';
|
|
16
15
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
17
16
|
|
|
17
|
+
import { clearDropTarget, moveSource, setDropTarget } from './commands';
|
|
18
18
|
import { DropTargetType } from './consts';
|
|
19
19
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
20
20
|
import { pluginKey } from './plugin-key';
|
|
@@ -59,25 +59,31 @@ export const createPlugin = (
|
|
|
59
59
|
},
|
|
60
60
|
onDrag(event) {
|
|
61
61
|
const data = getDraggableDataFromEvent(event);
|
|
62
|
-
|
|
63
62
|
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
64
63
|
if (!data) {
|
|
64
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
69
69
|
// insert location as to where the draggable will most likely be go. For example;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const { sourceType, targetAdjustedIndex } = data;
|
|
71
|
+
const dropTargetType =
|
|
72
|
+
sourceType === 'table-row'
|
|
73
|
+
? DropTargetType.ROW
|
|
74
|
+
: DropTargetType.COLUMN;
|
|
75
|
+
|
|
76
|
+
setDropTarget(dropTargetType, targetAdjustedIndex)(
|
|
77
|
+
editorView.state,
|
|
78
|
+
editorView.dispatch,
|
|
79
|
+
);
|
|
75
80
|
},
|
|
76
81
|
onDrop(event) {
|
|
77
82
|
const data = getDraggableDataFromEvent(event);
|
|
78
83
|
|
|
79
84
|
// If no data can be found then it's most like we do not want to perform any drop action
|
|
80
85
|
if (!data) {
|
|
86
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
83
89
|
|
|
@@ -91,15 +97,16 @@ export const createPlugin = (
|
|
|
91
97
|
if (
|
|
92
98
|
hasMergedCells(targetAdjustedIndex)(editorView.state.selection)
|
|
93
99
|
) {
|
|
100
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
96
103
|
|
|
97
|
-
const move = sourceType === 'table-row' ? moveRow : moveColumn;
|
|
98
|
-
|
|
99
104
|
const [sourceIndex] = sourceIndexes;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
moveSource(
|
|
106
|
+
sourceType,
|
|
107
|
+
sourceIndex,
|
|
108
|
+
targetAdjustedIndex,
|
|
109
|
+
)(editorView.state, editorView.dispatch);
|
|
103
110
|
},
|
|
104
111
|
}),
|
|
105
112
|
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handleDocOrSelectionChanged = void 0;
|
|
7
|
-
var _utils = require("@atlaskit/editor-tables/utils");
|
|
8
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
9
|
-
|
|
10
|
-
var buildPluginState = function buildPluginState(builders) {
|
|
11
|
-
return function (props) {
|
|
12
|
-
return function (pluginState) {
|
|
13
|
-
return builders.reduce(function (_pluginState, transform) {
|
|
14
|
-
return transform(props)(_pluginState);
|
|
15
|
-
}, pluginState);
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
var handleDocOrSelectionChanged = exports.handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, pluginState) {
|
|
20
|
-
return buildPluginState([])({
|
|
21
|
-
tr: tr,
|
|
22
|
-
table: (0, _utils.findTable)(tr.selection)
|
|
23
|
-
})(pluginState);
|
|
24
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
2
|
-
|
|
3
|
-
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
4
|
-
const buildPluginState = builders => props => pluginState => {
|
|
5
|
-
return builders.reduce((_pluginState, transform) => transform(props)(_pluginState), pluginState);
|
|
6
|
-
};
|
|
7
|
-
export const handleDocOrSelectionChanged = (tr, pluginState) => buildPluginState([])({
|
|
8
|
-
tr,
|
|
9
|
-
table: findTable(tr.selection)
|
|
10
|
-
})(pluginState);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
2
|
-
|
|
3
|
-
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
4
|
-
var buildPluginState = function buildPluginState(builders) {
|
|
5
|
-
return function (props) {
|
|
6
|
-
return function (pluginState) {
|
|
7
|
-
return builders.reduce(function (_pluginState, transform) {
|
|
8
|
-
return transform(props)(_pluginState);
|
|
9
|
-
}, pluginState);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, pluginState) {
|
|
14
|
-
return buildPluginState([])({
|
|
15
|
-
tr: tr,
|
|
16
|
-
table: findTable(tr.selection)
|
|
17
|
-
})(pluginState);
|
|
18
|
-
};
|