@atlaskit/editor-plugin-table 5.2.0 → 5.2.1
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/plugins/table/nodeviews/TableRow.js +57 -3
- package/dist/cjs/plugins/table/types.js +4 -1
- package/dist/es2019/plugins/table/nodeviews/TableRow.js +58 -3
- package/dist/es2019/plugins/table/types.js +5 -1
- package/dist/esm/plugins/table/nodeviews/TableRow.js +57 -3
- package/dist/esm/plugins/table/types.js +5 -1
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +2 -0
- package/dist/types/plugins/table/types.d.ts +14 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +14 -0
- package/package.json +4 -2
- package/src/plugins/table/nodeviews/TableRow.ts +54 -1
- package/src/plugins/table/types.ts +16 -0
- package/tsconfig.app.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
3
9
|
## 5.2.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -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() {
|
|
@@ -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,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) {
|
|
@@ -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
|
+
*/
|
|
@@ -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() {
|
|
@@ -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
|
+
*/
|
|
@@ -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;
|
|
@@ -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
|
+
}
|
|
@@ -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;
|
|
@@ -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.1",
|
|
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.10.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",
|
|
@@ -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);
|
|
@@ -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
|
},
|