@atlaskit/editor-plugin-block-controls 1.4.21 → 1.4.22
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 +8 -0
- package/dist/cjs/pm-plugins/decorations.js +18 -1
- package/dist/cjs/pm-plugins/main.js +22 -16
- package/dist/cjs/ui/drag-handle.js +0 -9
- package/dist/es2019/pm-plugins/decorations.js +18 -1
- package/dist/es2019/pm-plugins/main.js +11 -4
- package/dist/es2019/ui/drag-handle.js +0 -10
- package/dist/esm/pm-plugins/decorations.js +18 -1
- package/dist/esm/pm-plugins/main.js +22 -16
- package/dist/esm/ui/drag-handle.js +0 -9
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +10 -9
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +10 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.4.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#111855](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111855)
|
|
8
|
+
[`858997cc1d1e0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/858997cc1d1e0) -
|
|
9
|
+
ED-23619 Improve drop latency by cleaning up decorations before they are being redrawn
|
|
10
|
+
|
|
3
11
|
## 1.4.21
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -14,6 +14,7 @@ var _dropTarget = require("../ui/drop-target");
|
|
|
14
14
|
var _mouseMoveWrapper = require("../ui/mouse-move-wrapper");
|
|
15
15
|
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
16
16
|
var decs = [];
|
|
17
|
+
unmountDecorations('data-blocks-drop-target-container');
|
|
17
18
|
// Decoration state is used to keep track of the position of the drop targets
|
|
18
19
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
19
20
|
var decorationState = [];
|
|
@@ -24,6 +25,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
24
25
|
});
|
|
25
26
|
decs.push(_view.Decoration.widget(pos, function () {
|
|
26
27
|
var element = document.createElement('div');
|
|
28
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
27
29
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
28
30
|
api: api,
|
|
29
31
|
index: index
|
|
@@ -48,6 +50,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
48
50
|
});
|
|
49
51
|
decs.push(_view.Decoration.widget(newState.doc.nodeSize - 2, function () {
|
|
50
52
|
var element = document.createElement('div');
|
|
53
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
51
54
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
52
55
|
api: api,
|
|
53
56
|
index: decorationState.length
|
|
@@ -80,10 +83,12 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
80
83
|
*/
|
|
81
84
|
var mouseMoveWrapperDecorations = exports.mouseMoveWrapperDecorations = function mouseMoveWrapperDecorations(newState, api) {
|
|
82
85
|
var decs = [];
|
|
86
|
+
unmountDecorations('data-blocks-decoration-container');
|
|
83
87
|
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
84
88
|
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
85
89
|
decs.push(_view.Decoration.widget(pos, function (view, getPos) {
|
|
86
90
|
var element = document.createElement('div');
|
|
91
|
+
element.setAttribute('data-blocks-decoration-container', 'true');
|
|
87
92
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_mouseMoveWrapper.MouseMoveWrapper, {
|
|
88
93
|
view: view,
|
|
89
94
|
api: api,
|
|
@@ -108,6 +113,7 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
108
113
|
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
109
114
|
var element = document.createElement('div');
|
|
110
115
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
116
|
+
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
111
117
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
|
|
112
118
|
view: view,
|
|
113
119
|
api: api,
|
|
@@ -118,6 +124,17 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
118
124
|
return element;
|
|
119
125
|
}, {
|
|
120
126
|
side: -1,
|
|
121
|
-
id: 'drag-handle'
|
|
127
|
+
id: 'drag-handle',
|
|
128
|
+
destroy: function destroy(node) {
|
|
129
|
+
_reactDom.default.unmountComponentAtNode(node);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
var unmountDecorations = function unmountDecorations(selector) {
|
|
134
|
+
// Removing decorations manually instead of using native destroy function in prosemirror API
|
|
135
|
+
// as it was more responsive and causes less re-rendering
|
|
136
|
+
var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
|
|
137
|
+
decorationsToRemove.forEach(function (el) {
|
|
138
|
+
_reactDom.default.unmountComponentAtNode(el);
|
|
122
139
|
});
|
|
123
140
|
};
|
|
@@ -34,18 +34,24 @@ var destroyFn = function destroyFn(api) {
|
|
|
34
34
|
scrollable.style.setProperty('scroll-behavior', 'unset');
|
|
35
35
|
},
|
|
36
36
|
onDrop: function onDrop(_ref2) {
|
|
37
|
+
var _api$core;
|
|
37
38
|
var location = _ref2.location,
|
|
38
39
|
source = _ref2.source;
|
|
39
40
|
scrollable.style.setProperty('scroll-behavior', null);
|
|
40
|
-
|
|
41
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
42
|
+
var tr = _ref3.tr;
|
|
43
|
+
return tr.setMeta(key, {
|
|
44
|
+
isDragging: false
|
|
45
|
+
});
|
|
46
|
+
});
|
|
41
47
|
// if no drop targets are rendered, assume that drop is invalid
|
|
42
48
|
if (location.current.dropTargets.length === 0) {
|
|
43
|
-
var _api$
|
|
44
|
-
var
|
|
45
|
-
start =
|
|
46
|
-
api === null || api === void 0 || (_api$
|
|
49
|
+
var _api$core2;
|
|
50
|
+
var _ref4 = source.data,
|
|
51
|
+
start = _ref4.start;
|
|
52
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
|
|
47
53
|
var _api$analytics;
|
|
48
|
-
var tr =
|
|
54
|
+
var tr = _ref5.tr;
|
|
49
55
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
50
56
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
51
57
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
@@ -106,8 +112,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
106
112
|
|
|
107
113
|
// During resize, remove the drag handle widget
|
|
108
114
|
if (isResizerResizing || nodeCountChanged || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
109
|
-
var oldHandle = decorations.find().filter(function (
|
|
110
|
-
var spec =
|
|
115
|
+
var oldHandle = decorations.find().filter(function (_ref6) {
|
|
116
|
+
var spec = _ref6.spec;
|
|
111
117
|
return spec.id === 'drag-handle';
|
|
112
118
|
});
|
|
113
119
|
decorations = decorations.remove(oldHandle);
|
|
@@ -134,8 +140,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
134
140
|
|
|
135
141
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
136
142
|
if (meta !== null && meta !== void 0 && meta.activeNode && (meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) && api) {
|
|
137
|
-
var _oldHandle = decorations.find().filter(function (
|
|
138
|
-
var spec =
|
|
143
|
+
var _oldHandle = decorations.find().filter(function (_ref7) {
|
|
144
|
+
var spec = _ref7.spec;
|
|
139
145
|
return spec.id === 'drag-handle';
|
|
140
146
|
});
|
|
141
147
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -154,8 +160,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
154
160
|
|
|
155
161
|
// Remove drop target decoration when dragging stops
|
|
156
162
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
|
|
157
|
-
var dropTargetDecs = decorations.find().filter(function (
|
|
158
|
-
var spec =
|
|
163
|
+
var dropTargetDecs = decorations.find().filter(function (_ref8) {
|
|
164
|
+
var spec = _ref8.spec;
|
|
159
165
|
return spec.type === 'drop-target-decoration';
|
|
160
166
|
});
|
|
161
167
|
decorations = decorations.remove(dropTargetDecs);
|
|
@@ -163,9 +169,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
163
169
|
|
|
164
170
|
// Map drop target decoration positions when the document changes
|
|
165
171
|
if (tr.docChanged && currentState.isDragging) {
|
|
166
|
-
decorationState = decorationState.map(function (
|
|
167
|
-
var index =
|
|
168
|
-
pos =
|
|
172
|
+
decorationState = decorationState.map(function (_ref9) {
|
|
173
|
+
var index = _ref9.index,
|
|
174
|
+
pos = _ref9.pos;
|
|
169
175
|
return {
|
|
170
176
|
index: index,
|
|
171
177
|
pos: tr.mapping.map(pos)
|
|
@@ -231,7 +237,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
231
237
|
return {
|
|
232
238
|
destroy: function destroy() {
|
|
233
239
|
resizeObserver.unobserve(dom);
|
|
234
|
-
|
|
240
|
+
pragmaticCleanup();
|
|
235
241
|
}
|
|
236
242
|
};
|
|
237
243
|
}
|
|
@@ -132,15 +132,6 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
132
132
|
}
|
|
133
133
|
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
134
134
|
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
|
|
135
|
-
},
|
|
136
|
-
onDrop: function onDrop() {
|
|
137
|
-
var _api$core7;
|
|
138
|
-
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref6) {
|
|
139
|
-
var tr = _ref6.tr;
|
|
140
|
-
return tr.setMeta(_main.key, {
|
|
141
|
-
isDragging: false
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
135
|
}
|
|
145
136
|
});
|
|
146
137
|
}, [api, start, view, anchorName, nodeType]);
|
|
@@ -6,6 +6,7 @@ import { DropTarget } from '../ui/drop-target';
|
|
|
6
6
|
import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
|
|
7
7
|
export const dropTargetDecorations = (oldState, newState, api) => {
|
|
8
8
|
const decs = [];
|
|
9
|
+
unmountDecorations('data-blocks-drop-target-container');
|
|
9
10
|
// Decoration state is used to keep track of the position of the drop targets
|
|
10
11
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
11
12
|
const decorationState = [];
|
|
@@ -16,6 +17,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
16
17
|
});
|
|
17
18
|
decs.push(Decoration.widget(pos, () => {
|
|
18
19
|
const element = document.createElement('div');
|
|
20
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
19
21
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
20
22
|
api,
|
|
21
23
|
index
|
|
@@ -40,6 +42,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
40
42
|
});
|
|
41
43
|
decs.push(Decoration.widget(newState.doc.nodeSize - 2, () => {
|
|
42
44
|
const element = document.createElement('div');
|
|
45
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
43
46
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
44
47
|
api,
|
|
45
48
|
index: decorationState.length
|
|
@@ -73,10 +76,12 @@ export const nodeDecorations = newState => {
|
|
|
73
76
|
*/
|
|
74
77
|
export const mouseMoveWrapperDecorations = (newState, api) => {
|
|
75
78
|
const decs = [];
|
|
79
|
+
unmountDecorations('data-blocks-decoration-container');
|
|
76
80
|
newState.doc.descendants((node, pos, _parent, index) => {
|
|
77
81
|
const anchorName = `--node-anchor-${node.type.name}-${index}`;
|
|
78
82
|
decs.push(Decoration.widget(pos, (view, getPos) => {
|
|
79
83
|
const element = document.createElement('div');
|
|
84
|
+
element.setAttribute('data-blocks-decoration-container', 'true');
|
|
80
85
|
ReactDOM.render( /*#__PURE__*/createElement(MouseMoveWrapper, {
|
|
81
86
|
view,
|
|
82
87
|
api,
|
|
@@ -101,6 +106,7 @@ export const dragHandleDecoration = (pos, anchorName, nodeType, api) => {
|
|
|
101
106
|
return Decoration.widget(pos, (view, getPos) => {
|
|
102
107
|
const element = document.createElement('div');
|
|
103
108
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
109
|
+
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
104
110
|
ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
|
|
105
111
|
view,
|
|
106
112
|
api,
|
|
@@ -111,6 +117,17 @@ export const dragHandleDecoration = (pos, anchorName, nodeType, api) => {
|
|
|
111
117
|
return element;
|
|
112
118
|
}, {
|
|
113
119
|
side: -1,
|
|
114
|
-
id: 'drag-handle'
|
|
120
|
+
id: 'drag-handle',
|
|
121
|
+
destroy: node => {
|
|
122
|
+
ReactDOM.unmountComponentAtNode(node);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const unmountDecorations = selector => {
|
|
127
|
+
// Removing decorations manually instead of using native destroy function in prosemirror API
|
|
128
|
+
// as it was more responsive and causes less re-rendering
|
|
129
|
+
const decorationsToRemove = document.querySelectorAll(`[${selector}="true"]`);
|
|
130
|
+
decorationsToRemove.forEach(el => {
|
|
131
|
+
ReactDOM.unmountComponentAtNode(el);
|
|
115
132
|
});
|
|
116
133
|
};
|
|
@@ -28,15 +28,22 @@ const destroyFn = api => {
|
|
|
28
28
|
location,
|
|
29
29
|
source
|
|
30
30
|
}) => {
|
|
31
|
+
var _api$core;
|
|
31
32
|
scrollable.style.setProperty('scroll-behavior', null);
|
|
32
|
-
|
|
33
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
34
|
+
tr
|
|
35
|
+
}) => {
|
|
36
|
+
return tr.setMeta(key, {
|
|
37
|
+
isDragging: false
|
|
38
|
+
});
|
|
39
|
+
});
|
|
33
40
|
// if no drop targets are rendered, assume that drop is invalid
|
|
34
41
|
if (location.current.dropTargets.length === 0) {
|
|
35
|
-
var _api$
|
|
42
|
+
var _api$core2;
|
|
36
43
|
const {
|
|
37
44
|
start
|
|
38
45
|
} = source.data;
|
|
39
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
46
|
+
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
|
|
40
47
|
tr
|
|
41
48
|
}) => {
|
|
42
49
|
var _api$analytics;
|
|
@@ -226,7 +233,7 @@ export const createPlugin = api => {
|
|
|
226
233
|
return {
|
|
227
234
|
destroy() {
|
|
228
235
|
resizeObserver.unobserve(dom);
|
|
229
|
-
|
|
236
|
+
pragmaticCleanup();
|
|
230
237
|
}
|
|
231
238
|
};
|
|
232
239
|
}
|
|
@@ -124,16 +124,6 @@ export const DragHandle = ({
|
|
|
124
124
|
}
|
|
125
125
|
api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
126
126
|
api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.focus();
|
|
127
|
-
},
|
|
128
|
-
onDrop() {
|
|
129
|
-
var _api$core7;
|
|
130
|
-
api === null || api === void 0 ? void 0 : (_api$core7 = api.core) === null || _api$core7 === void 0 ? void 0 : _api$core7.actions.execute(({
|
|
131
|
-
tr
|
|
132
|
-
}) => {
|
|
133
|
-
return tr.setMeta(key, {
|
|
134
|
-
isDragging: false
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
127
|
}
|
|
138
128
|
});
|
|
139
129
|
}, [api, start, view, anchorName, nodeType]);
|
|
@@ -7,6 +7,7 @@ import { DropTarget } from '../ui/drop-target';
|
|
|
7
7
|
import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
|
|
8
8
|
export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
9
9
|
var decs = [];
|
|
10
|
+
unmountDecorations('data-blocks-drop-target-container');
|
|
10
11
|
// Decoration state is used to keep track of the position of the drop targets
|
|
11
12
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
12
13
|
var decorationState = [];
|
|
@@ -17,6 +18,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
17
18
|
});
|
|
18
19
|
decs.push(Decoration.widget(pos, function () {
|
|
19
20
|
var element = document.createElement('div');
|
|
21
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
20
22
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
21
23
|
api: api,
|
|
22
24
|
index: index
|
|
@@ -41,6 +43,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
41
43
|
});
|
|
42
44
|
decs.push(Decoration.widget(newState.doc.nodeSize - 2, function () {
|
|
43
45
|
var element = document.createElement('div');
|
|
46
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
44
47
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
45
48
|
api: api,
|
|
46
49
|
index: decorationState.length
|
|
@@ -73,10 +76,12 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
73
76
|
*/
|
|
74
77
|
export var mouseMoveWrapperDecorations = function mouseMoveWrapperDecorations(newState, api) {
|
|
75
78
|
var decs = [];
|
|
79
|
+
unmountDecorations('data-blocks-decoration-container');
|
|
76
80
|
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
77
81
|
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
78
82
|
decs.push(Decoration.widget(pos, function (view, getPos) {
|
|
79
83
|
var element = document.createElement('div');
|
|
84
|
+
element.setAttribute('data-blocks-decoration-container', 'true');
|
|
80
85
|
ReactDOM.render( /*#__PURE__*/createElement(MouseMoveWrapper, {
|
|
81
86
|
view: view,
|
|
82
87
|
api: api,
|
|
@@ -101,6 +106,7 @@ export var dragHandleDecoration = function dragHandleDecoration(pos, anchorName,
|
|
|
101
106
|
return Decoration.widget(pos, function (view, getPos) {
|
|
102
107
|
var element = document.createElement('div');
|
|
103
108
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
109
|
+
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
104
110
|
ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
|
|
105
111
|
view: view,
|
|
106
112
|
api: api,
|
|
@@ -111,6 +117,17 @@ export var dragHandleDecoration = function dragHandleDecoration(pos, anchorName,
|
|
|
111
117
|
return element;
|
|
112
118
|
}, {
|
|
113
119
|
side: -1,
|
|
114
|
-
id: 'drag-handle'
|
|
120
|
+
id: 'drag-handle',
|
|
121
|
+
destroy: function destroy(node) {
|
|
122
|
+
ReactDOM.unmountComponentAtNode(node);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
var unmountDecorations = function unmountDecorations(selector) {
|
|
127
|
+
// Removing decorations manually instead of using native destroy function in prosemirror API
|
|
128
|
+
// as it was more responsive and causes less re-rendering
|
|
129
|
+
var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
|
|
130
|
+
decorationsToRemove.forEach(function (el) {
|
|
131
|
+
ReactDOM.unmountComponentAtNode(el);
|
|
115
132
|
});
|
|
116
133
|
};
|
|
@@ -27,18 +27,24 @@ var destroyFn = function destroyFn(api) {
|
|
|
27
27
|
scrollable.style.setProperty('scroll-behavior', 'unset');
|
|
28
28
|
},
|
|
29
29
|
onDrop: function onDrop(_ref2) {
|
|
30
|
+
var _api$core;
|
|
30
31
|
var location = _ref2.location,
|
|
31
32
|
source = _ref2.source;
|
|
32
33
|
scrollable.style.setProperty('scroll-behavior', null);
|
|
33
|
-
|
|
34
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
35
|
+
var tr = _ref3.tr;
|
|
36
|
+
return tr.setMeta(key, {
|
|
37
|
+
isDragging: false
|
|
38
|
+
});
|
|
39
|
+
});
|
|
34
40
|
// if no drop targets are rendered, assume that drop is invalid
|
|
35
41
|
if (location.current.dropTargets.length === 0) {
|
|
36
|
-
var _api$
|
|
37
|
-
var
|
|
38
|
-
start =
|
|
39
|
-
api === null || api === void 0 || (_api$
|
|
42
|
+
var _api$core2;
|
|
43
|
+
var _ref4 = source.data,
|
|
44
|
+
start = _ref4.start;
|
|
45
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
|
|
40
46
|
var _api$analytics;
|
|
41
|
-
var tr =
|
|
47
|
+
var tr = _ref5.tr;
|
|
42
48
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
43
49
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
44
50
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
@@ -99,8 +105,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
99
105
|
|
|
100
106
|
// During resize, remove the drag handle widget
|
|
101
107
|
if (isResizerResizing || nodeCountChanged || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
102
|
-
var oldHandle = decorations.find().filter(function (
|
|
103
|
-
var spec =
|
|
108
|
+
var oldHandle = decorations.find().filter(function (_ref6) {
|
|
109
|
+
var spec = _ref6.spec;
|
|
104
110
|
return spec.id === 'drag-handle';
|
|
105
111
|
});
|
|
106
112
|
decorations = decorations.remove(oldHandle);
|
|
@@ -127,8 +133,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
127
133
|
|
|
128
134
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
129
135
|
if (meta !== null && meta !== void 0 && meta.activeNode && (meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) && api) {
|
|
130
|
-
var _oldHandle = decorations.find().filter(function (
|
|
131
|
-
var spec =
|
|
136
|
+
var _oldHandle = decorations.find().filter(function (_ref7) {
|
|
137
|
+
var spec = _ref7.spec;
|
|
132
138
|
return spec.id === 'drag-handle';
|
|
133
139
|
});
|
|
134
140
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -147,8 +153,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
147
153
|
|
|
148
154
|
// Remove drop target decoration when dragging stops
|
|
149
155
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
|
|
150
|
-
var dropTargetDecs = decorations.find().filter(function (
|
|
151
|
-
var spec =
|
|
156
|
+
var dropTargetDecs = decorations.find().filter(function (_ref8) {
|
|
157
|
+
var spec = _ref8.spec;
|
|
152
158
|
return spec.type === 'drop-target-decoration';
|
|
153
159
|
});
|
|
154
160
|
decorations = decorations.remove(dropTargetDecs);
|
|
@@ -156,9 +162,9 @@ export var createPlugin = function createPlugin(api) {
|
|
|
156
162
|
|
|
157
163
|
// Map drop target decoration positions when the document changes
|
|
158
164
|
if (tr.docChanged && currentState.isDragging) {
|
|
159
|
-
decorationState = decorationState.map(function (
|
|
160
|
-
var index =
|
|
161
|
-
pos =
|
|
165
|
+
decorationState = decorationState.map(function (_ref9) {
|
|
166
|
+
var index = _ref9.index,
|
|
167
|
+
pos = _ref9.pos;
|
|
162
168
|
return {
|
|
163
169
|
index: index,
|
|
164
170
|
pos: tr.mapping.map(pos)
|
|
@@ -224,7 +230,7 @@ export var createPlugin = function createPlugin(api) {
|
|
|
224
230
|
return {
|
|
225
231
|
destroy: function destroy() {
|
|
226
232
|
resizeObserver.unobserve(dom);
|
|
227
|
-
|
|
233
|
+
pragmaticCleanup();
|
|
228
234
|
}
|
|
229
235
|
};
|
|
230
236
|
}
|
|
@@ -124,15 +124,6 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
124
124
|
}
|
|
125
125
|
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
126
126
|
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
|
|
127
|
-
},
|
|
128
|
-
onDrop: function onDrop() {
|
|
129
|
-
var _api$core7;
|
|
130
|
-
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref6) {
|
|
131
|
-
var tr = _ref6.tr;
|
|
132
|
-
return tr.setMeta(key, {
|
|
133
|
-
isDragging: false
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
127
|
}
|
|
137
128
|
});
|
|
138
129
|
}, [api, start, view, anchorName, nodeType]);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { blockControlsPlugin } from './plugin';
|
|
2
|
-
export type { BlockControlsPlugin, DecorationState } from './types';
|
|
2
|
+
export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -19,6 +19,15 @@ export interface PluginState {
|
|
|
19
19
|
isDocSizeLimitEnabled: boolean;
|
|
20
20
|
}
|
|
21
21
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
22
|
+
export type BlockControlsSharedState = {
|
|
23
|
+
isMenuOpen: boolean;
|
|
24
|
+
activeNode: {
|
|
25
|
+
pos: number;
|
|
26
|
+
anchorName: string;
|
|
27
|
+
} | null;
|
|
28
|
+
decorationState: DecorationState;
|
|
29
|
+
isDragging: boolean;
|
|
30
|
+
} | undefined;
|
|
22
31
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
23
32
|
dependencies: [
|
|
24
33
|
OptionalPlugin<EditorDisabledPlugin>,
|
|
@@ -26,15 +35,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
26
35
|
OptionalPlugin<FeatureFlagsPlugin>,
|
|
27
36
|
OptionalPlugin<AnalyticsPlugin>
|
|
28
37
|
];
|
|
29
|
-
sharedState:
|
|
30
|
-
isMenuOpen: boolean;
|
|
31
|
-
activeNode: {
|
|
32
|
-
pos: number;
|
|
33
|
-
anchorName: string;
|
|
34
|
-
} | null;
|
|
35
|
-
decorationState: DecorationState;
|
|
36
|
-
isDragging: boolean;
|
|
37
|
-
} | undefined;
|
|
38
|
+
sharedState: BlockControlsSharedState;
|
|
38
39
|
commands: {
|
|
39
40
|
moveNode: (start: number, to: number) => EditorCommand;
|
|
40
41
|
showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { blockControlsPlugin } from './plugin';
|
|
2
|
-
export type { BlockControlsPlugin, DecorationState } from './types';
|
|
2
|
+
export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
|
|
@@ -19,6 +19,15 @@ export interface PluginState {
|
|
|
19
19
|
isDocSizeLimitEnabled: boolean;
|
|
20
20
|
}
|
|
21
21
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
22
|
+
export type BlockControlsSharedState = {
|
|
23
|
+
isMenuOpen: boolean;
|
|
24
|
+
activeNode: {
|
|
25
|
+
pos: number;
|
|
26
|
+
anchorName: string;
|
|
27
|
+
} | null;
|
|
28
|
+
decorationState: DecorationState;
|
|
29
|
+
isDragging: boolean;
|
|
30
|
+
} | undefined;
|
|
22
31
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
23
32
|
dependencies: [
|
|
24
33
|
OptionalPlugin<EditorDisabledPlugin>,
|
|
@@ -26,15 +35,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
26
35
|
OptionalPlugin<FeatureFlagsPlugin>,
|
|
27
36
|
OptionalPlugin<AnalyticsPlugin>
|
|
28
37
|
];
|
|
29
|
-
sharedState:
|
|
30
|
-
isMenuOpen: boolean;
|
|
31
|
-
activeNode: {
|
|
32
|
-
pos: number;
|
|
33
|
-
anchorName: string;
|
|
34
|
-
} | null;
|
|
35
|
-
decorationState: DecorationState;
|
|
36
|
-
isDragging: boolean;
|
|
37
|
-
} | undefined;
|
|
38
|
+
sharedState: BlockControlsSharedState;
|
|
38
39
|
commands: {
|
|
39
40
|
moveNode: (start: number, to: number) => EditorCommand;
|
|
40
41
|
showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.22",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^82.
|
|
34
|
+
"@atlaskit/editor-common": "^82.8.0",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^1.2.3",
|
|
36
36
|
"@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
|
|
37
37
|
"@atlaskit/editor-plugin-feature-flags": "^1.1.0",
|