@atlaskit/editor-plugin-table 5.8.2 → 5.8.3
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 +6 -0
- package/dist/cjs/nodeviews/TableComponent.js +17 -62
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +153 -123
- package/dist/cjs/pm-plugins/drag-and-drop/utils/autoscrollers.js +53 -0
- package/dist/cjs/pm-plugins/drag-and-drop/utils/index.js +8 -1
- package/dist/es2019/nodeviews/TableComponent.js +5 -55
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +158 -124
- package/dist/es2019/pm-plugins/drag-and-drop/utils/autoscrollers.js +50 -0
- package/dist/es2019/pm-plugins/drag-and-drop/utils/index.js +2 -1
- package/dist/esm/nodeviews/TableComponent.js +7 -52
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +152 -122
- package/dist/esm/pm-plugins/drag-and-drop/utils/autoscrollers.js +47 -0
- package/dist/esm/pm-plugins/drag-and-drop/utils/index.js +2 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
- package/dist/types/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/nodeviews/TableComponent.tsx +5 -49
- package/src/pm-plugins/drag-and-drop/plugin.ts +202 -157
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +52 -0
- package/src/pm-plugins/drag-and-drop/utils/index.ts +2 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
|
|
@@ -7,7 +7,9 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
9
9
|
import { getCellsInRow } from '@atlaskit/editor-tables/utils';
|
|
10
|
+
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
10
11
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
|
|
12
|
+
import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
|
|
11
13
|
import { findNearestCellIndexToPoint, hasMergedCellsInBetween } from '../../utils';
|
|
12
14
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
13
15
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
@@ -19,6 +21,148 @@ import { DRAGGABLE_TABLE_NODE_SIZE_LIMIT, DropTargetType } from './consts';
|
|
|
19
21
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
20
22
|
import { pluginKey } from './plugin-key';
|
|
21
23
|
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
24
|
+
var destroyFn = function destroyFn(editorView, editorAnalyticsAPI) {
|
|
25
|
+
var editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
|
|
26
|
+
var rowAutoScrollers = editorPageScrollContainer ? [monitorForElements({
|
|
27
|
+
canMonitor: function canMonitor(_ref) {
|
|
28
|
+
var source = _ref.source;
|
|
29
|
+
var _ref2 = source.data,
|
|
30
|
+
type = _ref2.type;
|
|
31
|
+
return type === 'table-row';
|
|
32
|
+
},
|
|
33
|
+
onDragStart: function onDragStart() {
|
|
34
|
+
// auto scroller doesn't work when scroll-behavior: smooth is set, this monitor temporarily removes it via inline styles
|
|
35
|
+
editorPageScrollContainer.style.setProperty('scroll-behavior', 'unset');
|
|
36
|
+
},
|
|
37
|
+
onDrop: function onDrop() {
|
|
38
|
+
// 'null' will remove the inline style
|
|
39
|
+
editorPageScrollContainer.style.setProperty('scroll-behavior', null);
|
|
40
|
+
}
|
|
41
|
+
}), autoScrollForElements({
|
|
42
|
+
element: editorPageScrollContainer,
|
|
43
|
+
canScroll: function canScroll(_ref3) {
|
|
44
|
+
var source = _ref3.source;
|
|
45
|
+
var _ref4 = source.data,
|
|
46
|
+
type = _ref4.type;
|
|
47
|
+
return type === 'table-row';
|
|
48
|
+
}
|
|
49
|
+
})] : [];
|
|
50
|
+
return combine.apply(void 0, rowAutoScrollers.concat([monitorForElements({
|
|
51
|
+
canMonitor: function canMonitor(_ref5) {
|
|
52
|
+
var source = _ref5.source;
|
|
53
|
+
var _ref6 = source.data,
|
|
54
|
+
type = _ref6.type,
|
|
55
|
+
localId = _ref6.localId,
|
|
56
|
+
indexes = _ref6.indexes;
|
|
57
|
+
|
|
58
|
+
// First; Perform any quick checks so we can abort early.
|
|
59
|
+
if (!indexes || !localId ||
|
|
60
|
+
// FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
|
|
61
|
+
// of more then 1 item.
|
|
62
|
+
indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
var _getTablePluginState = getTablePluginState(editorView.state),
|
|
66
|
+
tableNode = _getTablePluginState.tableNode;
|
|
67
|
+
// If the draggable localId is the same as the current selected table localId then we will allow the monitor
|
|
68
|
+
// watch for changes
|
|
69
|
+
return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
|
|
70
|
+
},
|
|
71
|
+
onDragStart: function onDragStart(_ref7) {
|
|
72
|
+
var location = _ref7.location;
|
|
73
|
+
toggleDragMenu(false)(editorView.state, editorView.dispatch);
|
|
74
|
+
},
|
|
75
|
+
onDrag: function onDrag(event) {
|
|
76
|
+
var data = getDraggableDataFromEvent(event);
|
|
77
|
+
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
78
|
+
if (!data) {
|
|
79
|
+
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
84
|
+
// insert location as to where the draggable will most likely be go. For example;
|
|
85
|
+
var sourceType = data.sourceType,
|
|
86
|
+
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
87
|
+
var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
|
|
88
|
+
var hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
|
|
89
|
+
setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
|
|
90
|
+
},
|
|
91
|
+
onDrop: function onDrop(event) {
|
|
92
|
+
var _cell$row, _cell$col;
|
|
93
|
+
var data = getDraggableDataFromEvent(event);
|
|
94
|
+
|
|
95
|
+
// On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
|
|
96
|
+
// over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
|
|
97
|
+
// at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
|
|
98
|
+
// it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
|
|
99
|
+
// then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
|
|
100
|
+
// triggered by this on drop event.
|
|
101
|
+
var _getTablePluginState2 = getTablePluginState(editorView.state),
|
|
102
|
+
hoveredCell = _getTablePluginState2.hoveredCell;
|
|
103
|
+
var cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
|
|
104
|
+
var tr = editorView.state.tr;
|
|
105
|
+
var action = {
|
|
106
|
+
type: 'HOVER_CELL',
|
|
107
|
+
data: {
|
|
108
|
+
hoveredCell: {
|
|
109
|
+
rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
|
|
110
|
+
colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
tr.setMeta(tablePluginKey, action);
|
|
115
|
+
|
|
116
|
+
// If no data can be found then it's most like we do not want to perform any drop action
|
|
117
|
+
if (!data) {
|
|
118
|
+
var _event$source, _event$source2;
|
|
119
|
+
// If we're able to determine the source type of the dropped element then we should report to analytics that
|
|
120
|
+
// the drop event was cancelled. Otherwise we will cancel silently.
|
|
121
|
+
if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
|
|
122
|
+
return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
|
|
123
|
+
}
|
|
124
|
+
return clearDropTarget(tr)(editorView.state, editorView.dispatch);
|
|
125
|
+
}
|
|
126
|
+
var sourceType = data.sourceType,
|
|
127
|
+
sourceIndexes = data.sourceIndexes,
|
|
128
|
+
targetIndex = data.targetIndex,
|
|
129
|
+
targetAdjustedIndex = data.targetAdjustedIndex,
|
|
130
|
+
direction = data.direction;
|
|
131
|
+
|
|
132
|
+
// When we drop on a target we will know the targets row/col index for certain,
|
|
133
|
+
if (sourceType === 'table-row') {
|
|
134
|
+
action.data.hoveredCell.rowIndex = targetIndex;
|
|
135
|
+
} else {
|
|
136
|
+
action.data.hoveredCell.colIndex = targetIndex;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
140
|
+
if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
|
|
141
|
+
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
142
|
+
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
143
|
+
TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
147
|
+
sourceIndex = _sourceIndexes[0];
|
|
148
|
+
requestAnimationFrame(function () {
|
|
149
|
+
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
150
|
+
|
|
151
|
+
// force a colgroup update here, otherwise dropped columns don't have
|
|
152
|
+
// the correct width immediately after the drop
|
|
153
|
+
if (sourceType === 'table-column') {
|
|
154
|
+
var _getTablePluginState3 = getTablePluginState(editorView.state),
|
|
155
|
+
tableRef = _getTablePluginState3.tableRef,
|
|
156
|
+
tableNode = _getTablePluginState3.tableNode;
|
|
157
|
+
if (tableRef && tableNode) {
|
|
158
|
+
insertColgroupFromNode(tableRef, tableNode);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
editorView.focus();
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
})]));
|
|
165
|
+
};
|
|
22
166
|
export var createPlugin = function createPlugin(dispatch, eventDispatcher, editorAnalyticsAPI) {
|
|
23
167
|
return new SafePlugin({
|
|
24
168
|
state: createPluginState(dispatch, function (state) {
|
|
@@ -34,12 +178,12 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher, edito
|
|
|
34
178
|
}),
|
|
35
179
|
key: pluginKey,
|
|
36
180
|
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
37
|
-
var
|
|
38
|
-
oldTargetCellPosition =
|
|
39
|
-
oldTableNode =
|
|
40
|
-
var
|
|
41
|
-
newTargetCellPosition =
|
|
42
|
-
newTableNode =
|
|
181
|
+
var _getTablePluginState4 = getTablePluginState(oldState),
|
|
182
|
+
oldTargetCellPosition = _getTablePluginState4.targetCellPosition,
|
|
183
|
+
oldTableNode = _getTablePluginState4.tableNode;
|
|
184
|
+
var _getTablePluginState5 = getTablePluginState(newState),
|
|
185
|
+
newTargetCellPosition = _getTablePluginState5.targetCellPosition,
|
|
186
|
+
newTableNode = _getTablePluginState5.tableNode;
|
|
43
187
|
var _getPluginState = getPluginState(newState),
|
|
44
188
|
isDragMenuOpen = _getPluginState.isDragMenuOpen,
|
|
45
189
|
dragMenuIndex = _getPluginState.dragMenuIndex,
|
|
@@ -93,121 +237,7 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher, edito
|
|
|
93
237
|
},
|
|
94
238
|
view: function view(editorView) {
|
|
95
239
|
return {
|
|
96
|
-
destroy:
|
|
97
|
-
canMonitor: function canMonitor(_ref) {
|
|
98
|
-
var source = _ref.source;
|
|
99
|
-
var _ref2 = source.data,
|
|
100
|
-
type = _ref2.type,
|
|
101
|
-
localId = _ref2.localId,
|
|
102
|
-
indexes = _ref2.indexes;
|
|
103
|
-
|
|
104
|
-
// First; Perform any quick checks so we can abort early.
|
|
105
|
-
if (!indexes || !localId ||
|
|
106
|
-
// FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
|
|
107
|
-
// of more then 1 item.
|
|
108
|
-
indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
var _getTablePluginState3 = getTablePluginState(editorView.state),
|
|
112
|
-
tableNode = _getTablePluginState3.tableNode;
|
|
113
|
-
// If the draggable localId is the same as the current selected table localId then we will allow the monitor
|
|
114
|
-
// watch for changes
|
|
115
|
-
return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
|
|
116
|
-
},
|
|
117
|
-
onDragStart: function onDragStart(_ref3) {
|
|
118
|
-
var location = _ref3.location;
|
|
119
|
-
toggleDragMenu(false)(editorView.state, editorView.dispatch);
|
|
120
|
-
},
|
|
121
|
-
onDrag: function onDrag(event) {
|
|
122
|
-
var data = getDraggableDataFromEvent(event);
|
|
123
|
-
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
124
|
-
if (!data) {
|
|
125
|
-
clearDropTarget()(editorView.state, editorView.dispatch);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
130
|
-
// insert location as to where the draggable will most likely be go. For example;
|
|
131
|
-
var sourceType = data.sourceType,
|
|
132
|
-
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
133
|
-
var dropTargetType = sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
|
|
134
|
-
var hasMergedCells = hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], dropTargetType)(editorView.state.selection);
|
|
135
|
-
setDropTarget(dropTargetType, targetAdjustedIndex, hasMergedCells)(editorView.state, editorView.dispatch);
|
|
136
|
-
},
|
|
137
|
-
onDrop: function onDrop(event) {
|
|
138
|
-
var _cell$row, _cell$col;
|
|
139
|
-
var data = getDraggableDataFromEvent(event);
|
|
140
|
-
|
|
141
|
-
// On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
|
|
142
|
-
// over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
|
|
143
|
-
// at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
|
|
144
|
-
// it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
|
|
145
|
-
// then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
|
|
146
|
-
// triggered by this on drop event.
|
|
147
|
-
var _getTablePluginState4 = getTablePluginState(editorView.state),
|
|
148
|
-
hoveredCell = _getTablePluginState4.hoveredCell;
|
|
149
|
-
var cell = findNearestCellIndexToPoint(event.location.current.input.clientX, event.location.current.input.clientY);
|
|
150
|
-
var tr = editorView.state.tr;
|
|
151
|
-
var action = {
|
|
152
|
-
type: 'HOVER_CELL',
|
|
153
|
-
data: {
|
|
154
|
-
hoveredCell: {
|
|
155
|
-
rowIndex: (_cell$row = cell === null || cell === void 0 ? void 0 : cell.row) !== null && _cell$row !== void 0 ? _cell$row : hoveredCell.rowIndex,
|
|
156
|
-
colIndex: (_cell$col = cell === null || cell === void 0 ? void 0 : cell.col) !== null && _cell$col !== void 0 ? _cell$col : hoveredCell.colIndex
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
tr.setMeta(tablePluginKey, action);
|
|
161
|
-
|
|
162
|
-
// If no data can be found then it's most like we do not want to perform any drop action
|
|
163
|
-
if (!data) {
|
|
164
|
-
var _event$source, _event$source2;
|
|
165
|
-
// If we're able to determine the source type of the dropped element then we should report to analytics that
|
|
166
|
-
// the drop event was cancelled. Otherwise we will cancel silently.
|
|
167
|
-
if ((event === null || event === void 0 || (_event$source = event.source) === null || _event$source === void 0 || (_event$source = _event$source.data) === null || _event$source === void 0 ? void 0 : _event$source.type) === 'table-row' || (event === null || event === void 0 || (_event$source2 = event.source) === null || _event$source2 === void 0 || (_event$source2 = _event$source2.data) === null || _event$source2 === void 0 ? void 0 : _event$source2.type) === 'table-column') {
|
|
168
|
-
return clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, event.source.data.type, TABLE_STATUS.CANCELLED, tr)(editorView.state, editorView.dispatch);
|
|
169
|
-
}
|
|
170
|
-
return clearDropTarget(tr)(editorView.state, editorView.dispatch);
|
|
171
|
-
}
|
|
172
|
-
var sourceType = data.sourceType,
|
|
173
|
-
sourceIndexes = data.sourceIndexes,
|
|
174
|
-
targetIndex = data.targetIndex,
|
|
175
|
-
targetAdjustedIndex = data.targetAdjustedIndex,
|
|
176
|
-
direction = data.direction;
|
|
177
|
-
|
|
178
|
-
// When we drop on a target we will know the targets row/col index for certain,
|
|
179
|
-
if (sourceType === 'table-row') {
|
|
180
|
-
action.data.hoveredCell.rowIndex = targetIndex;
|
|
181
|
-
} else {
|
|
182
|
-
action.data.hoveredCell.colIndex = targetIndex;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
186
|
-
if (hasMergedCellsInBetween([targetAdjustedIndex - 1, targetAdjustedIndex], sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN)(editorView.state.selection)) {
|
|
187
|
-
clearDropTargetWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType,
|
|
188
|
-
// This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
|
|
189
|
-
TABLE_STATUS.INVALID, tr)(editorView.state, editorView.dispatch);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
var _sourceIndexes = _slicedToArray(sourceIndexes, 1),
|
|
193
|
-
sourceIndex = _sourceIndexes[0];
|
|
194
|
-
requestAnimationFrame(function () {
|
|
195
|
-
moveSourceWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.DRAG_AND_DROP, sourceType, sourceIndex, targetAdjustedIndex + (direction === -1 ? 0 : -1), tr)(editorView.state, editorView.dispatch);
|
|
196
|
-
|
|
197
|
-
// force a colgroup update here, otherwise dropped columns don't have
|
|
198
|
-
// the correct width immediately after the drop
|
|
199
|
-
if (sourceType === 'table-column') {
|
|
200
|
-
var _getTablePluginState5 = getTablePluginState(editorView.state),
|
|
201
|
-
tableRef = _getTablePluginState5.tableRef,
|
|
202
|
-
tableNode = _getTablePluginState5.tableNode;
|
|
203
|
-
if (tableRef && tableNode) {
|
|
204
|
-
insertColgroupFromNode(tableRef, tableNode);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
editorView.focus();
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
})
|
|
240
|
+
destroy: destroyFn(editorView, editorAnalyticsAPI)
|
|
211
241
|
};
|
|
212
242
|
},
|
|
213
243
|
props: {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
2
|
+
import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
|
|
3
|
+
import { dropTargetExtendedWidth } from '../../../ui/consts';
|
|
4
|
+
export var autoScrollerFactory = function autoScrollerFactory(_ref) {
|
|
5
|
+
var tableWrapper = _ref.tableWrapper,
|
|
6
|
+
getNode = _ref.getNode;
|
|
7
|
+
return [autoScrollForElements({
|
|
8
|
+
element: tableWrapper,
|
|
9
|
+
canScroll: function canScroll(_ref2) {
|
|
10
|
+
var source = _ref2.source;
|
|
11
|
+
var _ref3 = source.data,
|
|
12
|
+
localId = _ref3.localId,
|
|
13
|
+
type = _ref3.type;
|
|
14
|
+
var node = getNode();
|
|
15
|
+
return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
|
|
16
|
+
}
|
|
17
|
+
}), unsafeOverflowAutoScrollForElements({
|
|
18
|
+
element: tableWrapper,
|
|
19
|
+
canScroll: function canScroll(_ref4) {
|
|
20
|
+
var source = _ref4.source;
|
|
21
|
+
var _ref5 = source.data,
|
|
22
|
+
localId = _ref5.localId,
|
|
23
|
+
type = _ref5.type;
|
|
24
|
+
var node = getNode();
|
|
25
|
+
return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
|
|
26
|
+
},
|
|
27
|
+
getOverflow: function getOverflow() {
|
|
28
|
+
return {
|
|
29
|
+
fromTopEdge: {
|
|
30
|
+
top: dropTargetExtendedWidth,
|
|
31
|
+
right: dropTargetExtendedWidth,
|
|
32
|
+
left: dropTargetExtendedWidth
|
|
33
|
+
},
|
|
34
|
+
fromRightEdge: {
|
|
35
|
+
right: dropTargetExtendedWidth,
|
|
36
|
+
top: dropTargetExtendedWidth,
|
|
37
|
+
bottom: dropTargetExtendedWidth
|
|
38
|
+
},
|
|
39
|
+
fromLeftEdge: {
|
|
40
|
+
top: dropTargetExtendedWidth,
|
|
41
|
+
left: dropTargetExtendedWidth,
|
|
42
|
+
bottom: dropTargetExtendedWidth
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
})];
|
|
47
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { getDraggableDataFromEvent } from './monitor';
|
|
1
|
+
export { getDraggableDataFromEvent } from './monitor';
|
|
2
|
+
export { autoScrollerFactory } from './autoscrollers';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
type AutoScrollerFactory = {
|
|
3
|
+
tableWrapper: HTMLElement;
|
|
4
|
+
getNode: () => PmNode;
|
|
5
|
+
};
|
|
6
|
+
export declare const autoScrollerFactory: ({ tableWrapper, getNode, }: AutoScrollerFactory) => import("@atlaskit/pragmatic-drag-and-drop/types").CleanupFn[];
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
type AutoScrollerFactory = {
|
|
3
|
+
tableWrapper: HTMLElement;
|
|
4
|
+
getNode: () => PmNode;
|
|
5
|
+
};
|
|
6
|
+
export declare const autoScrollerFactory: ({ tableWrapper, getNode, }: AutoScrollerFactory) => import("@atlaskit/pragmatic-drag-and-drop/types").CleanupFn[];
|
|
7
|
+
export {};
|
package/package.json
CHANGED
|
@@ -31,15 +31,11 @@ import {
|
|
|
31
31
|
} from '@atlaskit/editor-shared-styles';
|
|
32
32
|
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
33
33
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
34
|
-
import {
|
|
35
|
-
autoScrollForElements,
|
|
36
|
-
autoScrollWindowForElements,
|
|
37
|
-
} from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
38
|
-
import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
|
|
39
34
|
import type { CleanupFn } from '@atlaskit/pragmatic-drag-and-drop/types';
|
|
40
35
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
|
|
41
36
|
|
|
42
37
|
import { autoSizeTable, clearHoverSelection } from '../commands';
|
|
38
|
+
import { autoScrollerFactory } from '../pm-plugins/drag-and-drop/utils';
|
|
43
39
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
44
40
|
import type {
|
|
45
41
|
RowStickyState,
|
|
@@ -57,10 +53,9 @@ import {
|
|
|
57
53
|
} from '../pm-plugins/table-resizing/utils';
|
|
58
54
|
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
59
55
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
60
|
-
import type {
|
|
56
|
+
import type { PluginInjectionAPI } from '../types';
|
|
61
57
|
import { TableCssClassName as ClassName, ShadowEvent } from '../types';
|
|
62
58
|
import {
|
|
63
|
-
dropTargetExtendedWidth,
|
|
64
59
|
tableOverflowShadowWidth,
|
|
65
60
|
tableOverflowShadowWidthWide,
|
|
66
61
|
} from '../ui/consts';
|
|
@@ -198,48 +193,9 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
198
193
|
|
|
199
194
|
if (isDragAndDropEnabled) {
|
|
200
195
|
this.dragAndDropCleanupFn = combine(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const { localId, type } =
|
|
205
|
-
source.data as Partial<DraggableSourceData>;
|
|
206
|
-
const node = getNode();
|
|
207
|
-
return localId === node?.attrs.localId && type === 'table-column';
|
|
208
|
-
},
|
|
209
|
-
}),
|
|
210
|
-
autoScrollWindowForElements({
|
|
211
|
-
canScroll: ({ source }) => {
|
|
212
|
-
const { localId, type } =
|
|
213
|
-
source.data as Partial<DraggableSourceData>;
|
|
214
|
-
const node = getNode();
|
|
215
|
-
return localId === node?.attrs.localId && type === 'table-row';
|
|
216
|
-
},
|
|
217
|
-
}),
|
|
218
|
-
unsafeOverflowAutoScrollForElements({
|
|
219
|
-
element: this.wrapper,
|
|
220
|
-
canScroll: ({ source }) => {
|
|
221
|
-
const { localId, type } =
|
|
222
|
-
source.data as Partial<DraggableSourceData>;
|
|
223
|
-
const node = getNode();
|
|
224
|
-
return localId === node?.attrs.localId && type === 'table-column';
|
|
225
|
-
},
|
|
226
|
-
getOverflow: () => ({
|
|
227
|
-
fromTopEdge: {
|
|
228
|
-
top: dropTargetExtendedWidth,
|
|
229
|
-
right: dropTargetExtendedWidth,
|
|
230
|
-
left: dropTargetExtendedWidth,
|
|
231
|
-
},
|
|
232
|
-
fromRightEdge: {
|
|
233
|
-
right: dropTargetExtendedWidth,
|
|
234
|
-
top: dropTargetExtendedWidth,
|
|
235
|
-
bottom: dropTargetExtendedWidth,
|
|
236
|
-
},
|
|
237
|
-
fromLeftEdge: {
|
|
238
|
-
top: dropTargetExtendedWidth,
|
|
239
|
-
left: dropTargetExtendedWidth,
|
|
240
|
-
bottom: dropTargetExtendedWidth,
|
|
241
|
-
},
|
|
242
|
-
}),
|
|
196
|
+
...autoScrollerFactory({
|
|
197
|
+
tableWrapper: this.wrapper,
|
|
198
|
+
getNode,
|
|
243
199
|
}),
|
|
244
200
|
);
|
|
245
201
|
}
|