@atlaskit/editor-plugin-block-controls 1.4.31 → 1.4.33
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 +24 -0
- package/dist/cjs/plugin.js +3 -2
- package/dist/cjs/pm-plugins/main.js +49 -7
- package/dist/cjs/ui/drag-handle.js +15 -2
- package/dist/cjs/ui/mouse-move-wrapper.js +15 -2
- package/dist/cjs/utils/getSelection.js +4 -0
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/main.js +53 -8
- package/dist/es2019/ui/drag-handle.js +15 -2
- package/dist/es2019/ui/mouse-move-wrapper.js +14 -1
- package/dist/es2019/utils/getSelection.js +4 -0
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/pm-plugins/main.js +50 -8
- package/dist/esm/ui/drag-handle.js +15 -2
- package/dist/esm/ui/mouse-move-wrapper.js +15 -2
- package/dist/esm/utils/getSelection.js +4 -0
- package/dist/types/pm-plugins/main.d.ts +1 -0
- package/dist/types/types.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.4.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#111344](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111344)
|
|
8
|
+
[`a89589001c3b1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a89589001c3b1) -
|
|
9
|
+
[ED-23591] Select media node when there is only one within mediaGroup
|
|
10
|
+
- [#114726](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/114726)
|
|
11
|
+
[`3735569cbd151`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3735569cbd151) -
|
|
12
|
+
ED-23811 Set selection when command+shift+up is pressed in blocks plugin
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 1.4.32
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#113591](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/113591)
|
|
20
|
+
[`cc5ac590d4c43`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cc5ac590d4c43) -
|
|
21
|
+
[ED-23794] Fix the issue where prosemirror drag and drop stop working with block controls plugin
|
|
22
|
+
enabled
|
|
23
|
+
- [#114565](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/114565)
|
|
24
|
+
[`9c4aee75822c7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9c4aee75822c7) -
|
|
25
|
+
Add analytic event for drag and drop click event
|
|
26
|
+
|
|
3
27
|
## 1.4.31
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -91,7 +91,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
getSharedState: function getSharedState(editorState) {
|
|
94
|
-
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4;
|
|
94
|
+
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5;
|
|
95
95
|
if (!editorState) {
|
|
96
96
|
return undefined;
|
|
97
97
|
}
|
|
@@ -99,7 +99,8 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
99
99
|
isMenuOpen: (_key$getState$isMenuO = (_key$getState = _main.key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.isMenuOpen) !== null && _key$getState$isMenuO !== void 0 ? _key$getState$isMenuO : false,
|
|
100
100
|
activeNode: (_key$getState$activeN = (_key$getState2 = _main.key.getState(editorState)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode) !== null && _key$getState$activeN !== void 0 ? _key$getState$activeN : null,
|
|
101
101
|
decorationState: (_key$getState$decorat = (_key$getState3 = _main.key.getState(editorState)) === null || _key$getState3 === void 0 ? void 0 : _key$getState3.decorationState) !== null && _key$getState$decorat !== void 0 ? _key$getState$decorat : [],
|
|
102
|
-
isDragging: (_key$getState$isDragg = (_key$getState4 = _main.key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false
|
|
102
|
+
isDragging: (_key$getState$isDragg = (_key$getState4 = _main.key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false,
|
|
103
|
+
isPMDragging: (_key$getState$isPMDra = (_key$getState5 = _main.key.getState(editorState)) === null || _key$getState5 === void 0 ? void 0 : _key$getState5.isPMDragging) !== null && _key$getState$isPMDra !== void 0 ? _key$getState$isPMDra : false
|
|
103
104
|
};
|
|
104
105
|
},
|
|
105
106
|
contentComponent: function contentComponent() {
|
|
@@ -10,6 +10,7 @@ var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
|
10
10
|
var _steps = require("@atlaskit/adf-schema/steps");
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
12
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
13
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
14
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
15
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
16
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -61,7 +62,8 @@ var destroyFn = function destroyFn(api) {
|
|
|
61
62
|
})(tr);
|
|
62
63
|
}
|
|
63
64
|
return tr.setMeta(key, {
|
|
64
|
-
isDragging: false
|
|
65
|
+
isDragging: false,
|
|
66
|
+
isPMDragging: false
|
|
65
67
|
});
|
|
66
68
|
});
|
|
67
69
|
}
|
|
@@ -76,7 +78,8 @@ var initialState = {
|
|
|
76
78
|
isMenuOpen: false,
|
|
77
79
|
editorHeight: 0,
|
|
78
80
|
isResizerResizing: false,
|
|
79
|
-
isDocSizeLimitEnabled: false
|
|
81
|
+
isDocSizeLimitEnabled: false,
|
|
82
|
+
isPMDragging: false
|
|
80
83
|
};
|
|
81
84
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
|
|
82
85
|
initialState.isDocSizeLimitEnabled = true;
|
|
@@ -90,7 +93,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
90
93
|
return initialState;
|
|
91
94
|
},
|
|
92
95
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
93
|
-
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
|
|
96
|
+
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
|
|
94
97
|
if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
|
|
95
98
|
return initialState;
|
|
96
99
|
}
|
|
@@ -100,7 +103,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
100
103
|
decorationState = currentState.decorationState,
|
|
101
104
|
editorHeight = currentState.editorHeight,
|
|
102
105
|
isResizerResizing = currentState.isResizerResizing,
|
|
103
|
-
isDragging = currentState.isDragging
|
|
106
|
+
isDragging = currentState.isDragging,
|
|
107
|
+
isPMDragging = currentState.isPMDragging;
|
|
104
108
|
var meta = tr.getMeta(key);
|
|
105
109
|
// when creating analytics during drag/drop events, PM thinks the doc has changed
|
|
106
110
|
// so tr.docChange is true and causes some decorations to not render
|
|
@@ -236,7 +240,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
236
240
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
237
241
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
238
242
|
isResizerResizing: isResizerResizing,
|
|
239
|
-
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
|
|
243
|
+
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
244
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
240
245
|
};
|
|
241
246
|
}
|
|
242
247
|
},
|
|
@@ -255,13 +260,19 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
255
260
|
// prosemirror has sends a default transaction on drop (meta where uiEvent is 'drop'),
|
|
256
261
|
// this duplicates the an empty version of the node it was dropping,
|
|
257
262
|
// Adding some check here to prevent that if drop position is within activeNode
|
|
258
|
-
var state = view.state
|
|
263
|
+
var state = view.state,
|
|
264
|
+
dispatch = view.dispatch;
|
|
259
265
|
var pluginState = key.getState(state);
|
|
266
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
|
|
267
|
+
dispatch(state.tr.setMeta(key, {
|
|
268
|
+
isPMDragging: false
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
260
271
|
if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
|
|
261
272
|
return false;
|
|
262
273
|
}
|
|
263
274
|
var node = view.nodeDOM(pluginState === null || pluginState === void 0 || (_pluginState$activeNo = pluginState.activeNode) === null || _pluginState$activeNo === void 0 ? void 0 : _pluginState$activeNo.pos);
|
|
264
|
-
var isActiveNode =
|
|
275
|
+
var isActiveNode = event.target === node;
|
|
265
276
|
if (isActiveNode) {
|
|
266
277
|
// Prevent the default drop behavior if the position is within the activeNode
|
|
267
278
|
event.preventDefault();
|
|
@@ -269,11 +280,42 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
269
280
|
}
|
|
270
281
|
return false;
|
|
271
282
|
},
|
|
283
|
+
dragstart: function dragstart(view) {
|
|
284
|
+
view.dispatch(view.state.tr.setMeta(key, {
|
|
285
|
+
isPMDragging: true
|
|
286
|
+
}));
|
|
287
|
+
},
|
|
288
|
+
dragend: function dragend(view) {
|
|
289
|
+
var _key$getState2;
|
|
290
|
+
var state = view.state,
|
|
291
|
+
dispatch = view.dispatch;
|
|
292
|
+
if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
|
|
293
|
+
dispatch(state.tr.setMeta(key, {
|
|
294
|
+
isPMDragging: false
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
},
|
|
272
298
|
mouseover: function mouseover(view, event) {
|
|
273
299
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
274
300
|
(0, _handleMouseOver.handleMouseOver)(view, event, api);
|
|
275
301
|
}
|
|
276
302
|
return false;
|
|
303
|
+
},
|
|
304
|
+
keydown: function keydown(view, event) {
|
|
305
|
+
// Command + Shift + ArrowUp to select was broken with the plugin enabled so this manually sets the selection
|
|
306
|
+
var _view$state = view.state,
|
|
307
|
+
selection = _view$state.selection,
|
|
308
|
+
doc = _view$state.doc,
|
|
309
|
+
tr = _view$state.tr;
|
|
310
|
+
var metaKey = _utils.browser.mac ? event.metaKey : event.ctrlKey;
|
|
311
|
+
if (event.key === 'ArrowUp' && event.shiftKey && metaKey) {
|
|
312
|
+
if (selection instanceof _state.TextSelection || selection instanceof _state.NodeSelection) {
|
|
313
|
+
var newSelection = _state.TextSelection.create(doc, selection.head, 1);
|
|
314
|
+
view.dispatch(tr.setSelection(newSelection));
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
277
319
|
}
|
|
278
320
|
}
|
|
279
321
|
},
|
|
@@ -94,6 +94,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
94
94
|
var _api$core;
|
|
95
95
|
setDragHandleSelected(!dragHandleSelected);
|
|
96
96
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
97
|
+
var _api$analytics;
|
|
97
98
|
var tr = _ref2.tr;
|
|
98
99
|
if (start === undefined) {
|
|
99
100
|
return tr;
|
|
@@ -102,6 +103,18 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
102
103
|
tr.setMeta(_main.key, {
|
|
103
104
|
pos: start
|
|
104
105
|
});
|
|
106
|
+
var resolvedMovingNode = tr.doc.resolve(start);
|
|
107
|
+
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
108
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
109
|
+
eventType: _analytics.EVENT_TYPE.UI,
|
|
110
|
+
action: _analytics.ACTION.CLICKED,
|
|
111
|
+
actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
|
|
112
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
113
|
+
attributes: {
|
|
114
|
+
nodeDepth: resolvedMovingNode.depth,
|
|
115
|
+
nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
|
|
116
|
+
}
|
|
117
|
+
})(tr);
|
|
105
118
|
return tr;
|
|
106
119
|
});
|
|
107
120
|
view.focus();
|
|
@@ -182,7 +195,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
182
195
|
return;
|
|
183
196
|
}
|
|
184
197
|
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref7) {
|
|
185
|
-
var _api$blockControls, _api$
|
|
198
|
+
var _api$blockControls, _api$analytics2;
|
|
186
199
|
var tr = _ref7.tr;
|
|
187
200
|
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
|
|
188
201
|
tr: tr
|
|
@@ -190,7 +203,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
190
203
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
191
204
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
192
205
|
tr.setMeta('scrollIntoView', false);
|
|
193
|
-
api === null || api === void 0 || (_api$
|
|
206
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
|
|
194
207
|
eventType: _analytics.EVENT_TYPE.UI,
|
|
195
208
|
action: _analytics.ACTION.DRAGGED,
|
|
196
209
|
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
@@ -9,6 +9,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _react2 = require("@emotion/react");
|
|
11
11
|
var _bindEventListener = require("bind-event-listener");
|
|
12
|
+
var _main = require("../pm-plugins/main");
|
|
12
13
|
var _dragHandlePositions = require("../utils/drag-handle-positions");
|
|
13
14
|
var _consts = require("./consts");
|
|
14
15
|
/** @jsx jsx */
|
|
@@ -61,7 +62,7 @@ var MouseMoveWrapper = exports.MouseMoveWrapper = function MouseMoveWrapper(_ref
|
|
|
61
62
|
return (_unbind = unbind) === null || _unbind === void 0 ? void 0 : _unbind();
|
|
62
63
|
};
|
|
63
64
|
}, []);
|
|
64
|
-
var
|
|
65
|
+
var _onMouseEnter = (0, _react.useCallback)(function () {
|
|
65
66
|
if (!isDragging.current) {
|
|
66
67
|
setHideWrapper(true);
|
|
67
68
|
}
|
|
@@ -123,10 +124,22 @@ var MouseMoveWrapper = exports.MouseMoveWrapper = function MouseMoveWrapper(_ref
|
|
|
123
124
|
}, [view, anchorName]);
|
|
124
125
|
return (0, _react2.jsx)("div", {
|
|
125
126
|
ref: ref,
|
|
126
|
-
onMouseEnter: onMouseEnter
|
|
127
|
+
onMouseEnter: function onMouseEnter() {
|
|
128
|
+
var _key$getState;
|
|
129
|
+
// Once onDragEnter handler is processed, wrapper for drop target is hidden
|
|
130
|
+
// This means wrapper for draggable is shown, triggering onMouseEnter and showing draggable's drag handle again
|
|
131
|
+
// hence we want to ignore it while we still dragging
|
|
132
|
+
if (!((_key$getState = _main.key.getState(view.state)) !== null && _key$getState !== void 0 && _key$getState.isPMDragging)) {
|
|
133
|
+
_onMouseEnter();
|
|
134
|
+
}
|
|
135
|
+
},
|
|
127
136
|
css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
|
|
128
137
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
129
138
|
,
|
|
130
139
|
style: pos
|
|
140
|
+
// we want achieve the same result as onMouseEnter: make wrapper inactive and display drag handle next to drop target
|
|
141
|
+
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
142
|
+
,
|
|
143
|
+
onDragEnter: _onMouseEnter
|
|
131
144
|
});
|
|
132
145
|
};
|
|
@@ -15,6 +15,10 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
|
|
|
15
15
|
// decisionList node is not selectable, but we want to select the whole node not just text
|
|
16
16
|
if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
|
|
17
17
|
return new _state.NodeSelection($startPos);
|
|
18
|
+
// TODO: support multiple nodes selection
|
|
19
|
+
} else if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup' && node.childCount === 1) {
|
|
20
|
+
var $mediaStartPos = tr.doc.resolve(start + 1);
|
|
21
|
+
return new _state.NodeSelection($mediaStartPos);
|
|
18
22
|
} else {
|
|
19
23
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
20
24
|
// Find the first inline node in the node
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -79,7 +79,7 @@ export const blockControlsPlugin = ({
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
getSharedState(editorState) {
|
|
82
|
-
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4;
|
|
82
|
+
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5;
|
|
83
83
|
if (!editorState) {
|
|
84
84
|
return undefined;
|
|
85
85
|
}
|
|
@@ -87,7 +87,8 @@ export const blockControlsPlugin = ({
|
|
|
87
87
|
isMenuOpen: (_key$getState$isMenuO = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.isMenuOpen) !== null && _key$getState$isMenuO !== void 0 ? _key$getState$isMenuO : false,
|
|
88
88
|
activeNode: (_key$getState$activeN = (_key$getState2 = key.getState(editorState)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode) !== null && _key$getState$activeN !== void 0 ? _key$getState$activeN : null,
|
|
89
89
|
decorationState: (_key$getState$decorat = (_key$getState3 = key.getState(editorState)) === null || _key$getState3 === void 0 ? void 0 : _key$getState3.decorationState) !== null && _key$getState$decorat !== void 0 ? _key$getState$decorat : [],
|
|
90
|
-
isDragging: (_key$getState$isDragg = (_key$getState4 = key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false
|
|
90
|
+
isDragging: (_key$getState$isDragg = (_key$getState4 = key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false,
|
|
91
|
+
isPMDragging: (_key$getState$isPMDra = (_key$getState5 = key.getState(editorState)) === null || _key$getState5 === void 0 ? void 0 : _key$getState5.isPMDragging) !== null && _key$getState$isPMDra !== void 0 ? _key$getState$isPMDra : false
|
|
91
92
|
};
|
|
92
93
|
},
|
|
93
94
|
contentComponent() {
|
|
@@ -2,7 +2,8 @@ import rafSchedule from 'raf-schd';
|
|
|
2
2
|
import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import {
|
|
5
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
6
|
+
import { NodeSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
8
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
9
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
@@ -55,7 +56,8 @@ const destroyFn = api => {
|
|
|
55
56
|
})(tr);
|
|
56
57
|
}
|
|
57
58
|
return tr.setMeta(key, {
|
|
58
|
-
isDragging: false
|
|
59
|
+
isDragging: false,
|
|
60
|
+
isPMDragging: false
|
|
59
61
|
});
|
|
60
62
|
});
|
|
61
63
|
}
|
|
@@ -70,7 +72,8 @@ const initialState = {
|
|
|
70
72
|
isMenuOpen: false,
|
|
71
73
|
editorHeight: 0,
|
|
72
74
|
isResizerResizing: false,
|
|
73
|
-
isDocSizeLimitEnabled: false
|
|
75
|
+
isDocSizeLimitEnabled: false,
|
|
76
|
+
isPMDragging: false
|
|
74
77
|
};
|
|
75
78
|
if (getBooleanFF('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
|
|
76
79
|
initialState.isDocSizeLimitEnabled = true;
|
|
@@ -84,7 +87,7 @@ export const createPlugin = api => {
|
|
|
84
87
|
return initialState;
|
|
85
88
|
},
|
|
86
89
|
apply(tr, currentState, oldState, newState) {
|
|
87
|
-
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
|
|
90
|
+
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
|
|
88
91
|
if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
|
|
89
92
|
return initialState;
|
|
90
93
|
}
|
|
@@ -95,7 +98,8 @@ export const createPlugin = api => {
|
|
|
95
98
|
decorationState,
|
|
96
99
|
editorHeight,
|
|
97
100
|
isResizerResizing,
|
|
98
|
-
isDragging
|
|
101
|
+
isDragging,
|
|
102
|
+
isPMDragging
|
|
99
103
|
} = currentState;
|
|
100
104
|
const meta = tr.getMeta(key);
|
|
101
105
|
// when creating analytics during drag/drop events, PM thinks the doc has changed
|
|
@@ -227,7 +231,8 @@ export const createPlugin = api => {
|
|
|
227
231
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
228
232
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
229
233
|
isResizerResizing: isResizerResizing,
|
|
230
|
-
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
|
|
234
|
+
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
235
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
231
236
|
};
|
|
232
237
|
}
|
|
233
238
|
},
|
|
@@ -247,14 +252,20 @@ export const createPlugin = api => {
|
|
|
247
252
|
// this duplicates the an empty version of the node it was dropping,
|
|
248
253
|
// Adding some check here to prevent that if drop position is within activeNode
|
|
249
254
|
const {
|
|
250
|
-
state
|
|
255
|
+
state,
|
|
256
|
+
dispatch
|
|
251
257
|
} = view;
|
|
252
258
|
const pluginState = key.getState(state);
|
|
259
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
|
|
260
|
+
dispatch(state.tr.setMeta(key, {
|
|
261
|
+
isPMDragging: false
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
253
264
|
if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
|
|
254
265
|
return false;
|
|
255
266
|
}
|
|
256
267
|
const node = view.nodeDOM(pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$activeNo = pluginState.activeNode) === null || _pluginState$activeNo === void 0 ? void 0 : _pluginState$activeNo.pos);
|
|
257
|
-
const isActiveNode =
|
|
268
|
+
const isActiveNode = event.target === node;
|
|
258
269
|
if (isActiveNode) {
|
|
259
270
|
// Prevent the default drop behavior if the position is within the activeNode
|
|
260
271
|
event.preventDefault();
|
|
@@ -262,11 +273,45 @@ export const createPlugin = api => {
|
|
|
262
273
|
}
|
|
263
274
|
return false;
|
|
264
275
|
},
|
|
276
|
+
dragstart(view) {
|
|
277
|
+
view.dispatch(view.state.tr.setMeta(key, {
|
|
278
|
+
isPMDragging: true
|
|
279
|
+
}));
|
|
280
|
+
},
|
|
281
|
+
dragend(view) {
|
|
282
|
+
var _key$getState2;
|
|
283
|
+
const {
|
|
284
|
+
state,
|
|
285
|
+
dispatch
|
|
286
|
+
} = view;
|
|
287
|
+
if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
|
|
288
|
+
dispatch(state.tr.setMeta(key, {
|
|
289
|
+
isPMDragging: false
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
},
|
|
265
293
|
mouseover: (view, event) => {
|
|
266
294
|
if (getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
267
295
|
handleMouseOver(view, event, api);
|
|
268
296
|
}
|
|
269
297
|
return false;
|
|
298
|
+
},
|
|
299
|
+
keydown(view, event) {
|
|
300
|
+
// Command + Shift + ArrowUp to select was broken with the plugin enabled so this manually sets the selection
|
|
301
|
+
const {
|
|
302
|
+
selection,
|
|
303
|
+
doc,
|
|
304
|
+
tr
|
|
305
|
+
} = view.state;
|
|
306
|
+
const metaKey = browser.mac ? event.metaKey : event.ctrlKey;
|
|
307
|
+
if (event.key === 'ArrowUp' && event.shiftKey && metaKey) {
|
|
308
|
+
if (selection instanceof TextSelection || selection instanceof NodeSelection) {
|
|
309
|
+
const newSelection = TextSelection.create(doc, selection.head, 1);
|
|
310
|
+
view.dispatch(tr.setSelection(newSelection));
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
270
315
|
}
|
|
271
316
|
}
|
|
272
317
|
},
|
|
@@ -81,6 +81,7 @@ export const DragHandle = ({
|
|
|
81
81
|
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
82
82
|
tr
|
|
83
83
|
}) => {
|
|
84
|
+
var _api$analytics;
|
|
84
85
|
if (start === undefined) {
|
|
85
86
|
return tr;
|
|
86
87
|
}
|
|
@@ -88,6 +89,18 @@ export const DragHandle = ({
|
|
|
88
89
|
tr.setMeta(key, {
|
|
89
90
|
pos: start
|
|
90
91
|
});
|
|
92
|
+
const resolvedMovingNode = tr.doc.resolve(start);
|
|
93
|
+
const maybeNode = resolvedMovingNode.nodeAfter;
|
|
94
|
+
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
|
|
95
|
+
eventType: EVENT_TYPE.UI,
|
|
96
|
+
action: ACTION.CLICKED,
|
|
97
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
98
|
+
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
99
|
+
attributes: {
|
|
100
|
+
nodeDepth: resolvedMovingNode.depth,
|
|
101
|
+
nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
|
|
102
|
+
}
|
|
103
|
+
})(tr);
|
|
91
104
|
return tr;
|
|
92
105
|
});
|
|
93
106
|
view.focus();
|
|
@@ -172,14 +185,14 @@ export const DragHandle = ({
|
|
|
172
185
|
api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.execute(({
|
|
173
186
|
tr
|
|
174
187
|
}) => {
|
|
175
|
-
var _api$blockControls, _api$
|
|
188
|
+
var _api$blockControls, _api$analytics2;
|
|
176
189
|
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)({
|
|
177
190
|
tr
|
|
178
191
|
});
|
|
179
192
|
const resolvedMovingNode = tr.doc.resolve(start);
|
|
180
193
|
const maybeNode = resolvedMovingNode.nodeAfter;
|
|
181
194
|
tr.setMeta('scrollIntoView', false);
|
|
182
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
195
|
+
api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.attachAnalyticsEvent({
|
|
183
196
|
eventType: EVENT_TYPE.UI,
|
|
184
197
|
action: ACTION.DRAGGED,
|
|
185
198
|
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react
|
|
|
4
4
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
5
5
|
import { css, jsx } from '@emotion/react';
|
|
6
6
|
import { bind } from 'bind-event-listener';
|
|
7
|
+
import { key } from '../pm-plugins/main';
|
|
7
8
|
import { getTopPosition } from '../utils/drag-handle-positions';
|
|
8
9
|
import { DRAG_HANDLE_ZINDEX } from './consts';
|
|
9
10
|
const basicStyles = css({
|
|
@@ -108,10 +109,22 @@ export const MouseMoveWrapper = ({
|
|
|
108
109
|
}, [view, anchorName]);
|
|
109
110
|
return jsx("div", {
|
|
110
111
|
ref: ref,
|
|
111
|
-
onMouseEnter:
|
|
112
|
+
onMouseEnter: () => {
|
|
113
|
+
var _key$getState;
|
|
114
|
+
// Once onDragEnter handler is processed, wrapper for drop target is hidden
|
|
115
|
+
// This means wrapper for draggable is shown, triggering onMouseEnter and showing draggable's drag handle again
|
|
116
|
+
// hence we want to ignore it while we still dragging
|
|
117
|
+
if (!((_key$getState = key.getState(view.state)) !== null && _key$getState !== void 0 && _key$getState.isPMDragging)) {
|
|
118
|
+
onMouseEnter();
|
|
119
|
+
}
|
|
120
|
+
},
|
|
112
121
|
css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
|
|
113
122
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
114
123
|
,
|
|
115
124
|
style: pos
|
|
125
|
+
// we want achieve the same result as onMouseEnter: make wrapper inactive and display drag handle next to drop target
|
|
126
|
+
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
127
|
+
,
|
|
128
|
+
onDragEnter: onMouseEnter
|
|
116
129
|
});
|
|
117
130
|
};
|
|
@@ -9,6 +9,10 @@ export const getSelection = (tr, start) => {
|
|
|
9
9
|
// decisionList node is not selectable, but we want to select the whole node not just text
|
|
10
10
|
if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
|
|
11
11
|
return new NodeSelection($startPos);
|
|
12
|
+
// TODO: support multiple nodes selection
|
|
13
|
+
} else if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup' && node.childCount === 1) {
|
|
14
|
+
const $mediaStartPos = tr.doc.resolve(start + 1);
|
|
15
|
+
return new NodeSelection($mediaStartPos);
|
|
12
16
|
} else {
|
|
13
17
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
14
18
|
// Find the first inline node in the node
|
package/dist/esm/plugin.js
CHANGED
|
@@ -84,7 +84,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
getSharedState: function getSharedState(editorState) {
|
|
87
|
-
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4;
|
|
87
|
+
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$decorat, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5;
|
|
88
88
|
if (!editorState) {
|
|
89
89
|
return undefined;
|
|
90
90
|
}
|
|
@@ -92,7 +92,8 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
92
92
|
isMenuOpen: (_key$getState$isMenuO = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.isMenuOpen) !== null && _key$getState$isMenuO !== void 0 ? _key$getState$isMenuO : false,
|
|
93
93
|
activeNode: (_key$getState$activeN = (_key$getState2 = key.getState(editorState)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode) !== null && _key$getState$activeN !== void 0 ? _key$getState$activeN : null,
|
|
94
94
|
decorationState: (_key$getState$decorat = (_key$getState3 = key.getState(editorState)) === null || _key$getState3 === void 0 ? void 0 : _key$getState3.decorationState) !== null && _key$getState$decorat !== void 0 ? _key$getState$decorat : [],
|
|
95
|
-
isDragging: (_key$getState$isDragg = (_key$getState4 = key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false
|
|
95
|
+
isDragging: (_key$getState$isDragg = (_key$getState4 = key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false,
|
|
96
|
+
isPMDragging: (_key$getState$isPMDra = (_key$getState5 = key.getState(editorState)) === null || _key$getState5 === void 0 ? void 0 : _key$getState5.isPMDragging) !== null && _key$getState$isPMDra !== void 0 ? _key$getState$isPMDra : false
|
|
96
97
|
};
|
|
97
98
|
},
|
|
98
99
|
contentComponent: function contentComponent() {
|
|
@@ -3,7 +3,8 @@ import rafSchedule from 'raf-schd';
|
|
|
3
3
|
import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
|
|
4
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
-
import {
|
|
6
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { NodeSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
8
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
9
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
@@ -54,7 +55,8 @@ var destroyFn = function destroyFn(api) {
|
|
|
54
55
|
})(tr);
|
|
55
56
|
}
|
|
56
57
|
return tr.setMeta(key, {
|
|
57
|
-
isDragging: false
|
|
58
|
+
isDragging: false,
|
|
59
|
+
isPMDragging: false
|
|
58
60
|
});
|
|
59
61
|
});
|
|
60
62
|
}
|
|
@@ -69,7 +71,8 @@ var initialState = {
|
|
|
69
71
|
isMenuOpen: false,
|
|
70
72
|
editorHeight: 0,
|
|
71
73
|
isResizerResizing: false,
|
|
72
|
-
isDocSizeLimitEnabled: false
|
|
74
|
+
isDocSizeLimitEnabled: false,
|
|
75
|
+
isPMDragging: false
|
|
73
76
|
};
|
|
74
77
|
if (getBooleanFF('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
|
|
75
78
|
initialState.isDocSizeLimitEnabled = true;
|
|
@@ -83,7 +86,7 @@ export var createPlugin = function createPlugin(api) {
|
|
|
83
86
|
return initialState;
|
|
84
87
|
},
|
|
85
88
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
86
|
-
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
|
|
89
|
+
var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
|
|
87
90
|
if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
|
|
88
91
|
return initialState;
|
|
89
92
|
}
|
|
@@ -93,7 +96,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
93
96
|
decorationState = currentState.decorationState,
|
|
94
97
|
editorHeight = currentState.editorHeight,
|
|
95
98
|
isResizerResizing = currentState.isResizerResizing,
|
|
96
|
-
isDragging = currentState.isDragging
|
|
99
|
+
isDragging = currentState.isDragging,
|
|
100
|
+
isPMDragging = currentState.isPMDragging;
|
|
97
101
|
var meta = tr.getMeta(key);
|
|
98
102
|
// when creating analytics during drag/drop events, PM thinks the doc has changed
|
|
99
103
|
// so tr.docChange is true and causes some decorations to not render
|
|
@@ -229,7 +233,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
229
233
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
230
234
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
231
235
|
isResizerResizing: isResizerResizing,
|
|
232
|
-
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
|
|
236
|
+
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
237
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
233
238
|
};
|
|
234
239
|
}
|
|
235
240
|
},
|
|
@@ -248,13 +253,19 @@ export var createPlugin = function createPlugin(api) {
|
|
|
248
253
|
// prosemirror has sends a default transaction on drop (meta where uiEvent is 'drop'),
|
|
249
254
|
// this duplicates the an empty version of the node it was dropping,
|
|
250
255
|
// Adding some check here to prevent that if drop position is within activeNode
|
|
251
|
-
var state = view.state
|
|
256
|
+
var state = view.state,
|
|
257
|
+
dispatch = view.dispatch;
|
|
252
258
|
var pluginState = key.getState(state);
|
|
259
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
|
|
260
|
+
dispatch(state.tr.setMeta(key, {
|
|
261
|
+
isPMDragging: false
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
253
264
|
if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
|
|
254
265
|
return false;
|
|
255
266
|
}
|
|
256
267
|
var node = view.nodeDOM(pluginState === null || pluginState === void 0 || (_pluginState$activeNo = pluginState.activeNode) === null || _pluginState$activeNo === void 0 ? void 0 : _pluginState$activeNo.pos);
|
|
257
|
-
var isActiveNode =
|
|
268
|
+
var isActiveNode = event.target === node;
|
|
258
269
|
if (isActiveNode) {
|
|
259
270
|
// Prevent the default drop behavior if the position is within the activeNode
|
|
260
271
|
event.preventDefault();
|
|
@@ -262,11 +273,42 @@ export var createPlugin = function createPlugin(api) {
|
|
|
262
273
|
}
|
|
263
274
|
return false;
|
|
264
275
|
},
|
|
276
|
+
dragstart: function dragstart(view) {
|
|
277
|
+
view.dispatch(view.state.tr.setMeta(key, {
|
|
278
|
+
isPMDragging: true
|
|
279
|
+
}));
|
|
280
|
+
},
|
|
281
|
+
dragend: function dragend(view) {
|
|
282
|
+
var _key$getState2;
|
|
283
|
+
var state = view.state,
|
|
284
|
+
dispatch = view.dispatch;
|
|
285
|
+
if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
|
|
286
|
+
dispatch(state.tr.setMeta(key, {
|
|
287
|
+
isPMDragging: false
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
290
|
+
},
|
|
265
291
|
mouseover: function mouseover(view, event) {
|
|
266
292
|
if (getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
267
293
|
handleMouseOver(view, event, api);
|
|
268
294
|
}
|
|
269
295
|
return false;
|
|
296
|
+
},
|
|
297
|
+
keydown: function keydown(view, event) {
|
|
298
|
+
// Command + Shift + ArrowUp to select was broken with the plugin enabled so this manually sets the selection
|
|
299
|
+
var _view$state = view.state,
|
|
300
|
+
selection = _view$state.selection,
|
|
301
|
+
doc = _view$state.doc,
|
|
302
|
+
tr = _view$state.tr;
|
|
303
|
+
var metaKey = browser.mac ? event.metaKey : event.ctrlKey;
|
|
304
|
+
if (event.key === 'ArrowUp' && event.shiftKey && metaKey) {
|
|
305
|
+
if (selection instanceof TextSelection || selection instanceof NodeSelection) {
|
|
306
|
+
var newSelection = TextSelection.create(doc, selection.head, 1);
|
|
307
|
+
view.dispatch(tr.setSelection(newSelection));
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
270
312
|
}
|
|
271
313
|
}
|
|
272
314
|
},
|
|
@@ -86,6 +86,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
86
86
|
var _api$core;
|
|
87
87
|
setDragHandleSelected(!dragHandleSelected);
|
|
88
88
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
89
|
+
var _api$analytics;
|
|
89
90
|
var tr = _ref2.tr;
|
|
90
91
|
if (start === undefined) {
|
|
91
92
|
return tr;
|
|
@@ -94,6 +95,18 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
94
95
|
tr.setMeta(key, {
|
|
95
96
|
pos: start
|
|
96
97
|
});
|
|
98
|
+
var resolvedMovingNode = tr.doc.resolve(start);
|
|
99
|
+
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
100
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
101
|
+
eventType: EVENT_TYPE.UI,
|
|
102
|
+
action: ACTION.CLICKED,
|
|
103
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
104
|
+
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
105
|
+
attributes: {
|
|
106
|
+
nodeDepth: resolvedMovingNode.depth,
|
|
107
|
+
nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
|
|
108
|
+
}
|
|
109
|
+
})(tr);
|
|
97
110
|
return tr;
|
|
98
111
|
});
|
|
99
112
|
view.focus();
|
|
@@ -174,7 +187,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
174
187
|
return;
|
|
175
188
|
}
|
|
176
189
|
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref7) {
|
|
177
|
-
var _api$blockControls, _api$
|
|
190
|
+
var _api$blockControls, _api$analytics2;
|
|
178
191
|
var tr = _ref7.tr;
|
|
179
192
|
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
|
|
180
193
|
tr: tr
|
|
@@ -182,7 +195,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
182
195
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
183
196
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
184
197
|
tr.setMeta('scrollIntoView', false);
|
|
185
|
-
api === null || api === void 0 || (_api$
|
|
198
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
|
|
186
199
|
eventType: EVENT_TYPE.UI,
|
|
187
200
|
action: ACTION.DRAGGED,
|
|
188
201
|
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react
|
|
|
5
5
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
6
6
|
import { css, jsx } from '@emotion/react';
|
|
7
7
|
import { bind } from 'bind-event-listener';
|
|
8
|
+
import { key } from '../pm-plugins/main';
|
|
8
9
|
import { getTopPosition } from '../utils/drag-handle-positions';
|
|
9
10
|
import { DRAG_HANDLE_ZINDEX } from './consts';
|
|
10
11
|
var basicStyles = css({
|
|
@@ -53,7 +54,7 @@ export var MouseMoveWrapper = function MouseMoveWrapper(_ref) {
|
|
|
53
54
|
return (_unbind = unbind) === null || _unbind === void 0 ? void 0 : _unbind();
|
|
54
55
|
};
|
|
55
56
|
}, []);
|
|
56
|
-
var
|
|
57
|
+
var _onMouseEnter = useCallback(function () {
|
|
57
58
|
if (!isDragging.current) {
|
|
58
59
|
setHideWrapper(true);
|
|
59
60
|
}
|
|
@@ -115,10 +116,22 @@ export var MouseMoveWrapper = function MouseMoveWrapper(_ref) {
|
|
|
115
116
|
}, [view, anchorName]);
|
|
116
117
|
return jsx("div", {
|
|
117
118
|
ref: ref,
|
|
118
|
-
onMouseEnter: onMouseEnter
|
|
119
|
+
onMouseEnter: function onMouseEnter() {
|
|
120
|
+
var _key$getState;
|
|
121
|
+
// Once onDragEnter handler is processed, wrapper for drop target is hidden
|
|
122
|
+
// This means wrapper for draggable is shown, triggering onMouseEnter and showing draggable's drag handle again
|
|
123
|
+
// hence we want to ignore it while we still dragging
|
|
124
|
+
if (!((_key$getState = key.getState(view.state)) !== null && _key$getState !== void 0 && _key$getState.isPMDragging)) {
|
|
125
|
+
_onMouseEnter();
|
|
126
|
+
}
|
|
127
|
+
},
|
|
119
128
|
css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
|
|
120
129
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
121
130
|
,
|
|
122
131
|
style: pos
|
|
132
|
+
// we want achieve the same result as onMouseEnter: make wrapper inactive and display drag handle next to drop target
|
|
133
|
+
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
134
|
+
,
|
|
135
|
+
onDragEnter: _onMouseEnter
|
|
123
136
|
});
|
|
124
137
|
};
|
|
@@ -9,6 +9,10 @@ export var getSelection = function getSelection(tr, start) {
|
|
|
9
9
|
// decisionList node is not selectable, but we want to select the whole node not just text
|
|
10
10
|
if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
|
|
11
11
|
return new NodeSelection($startPos);
|
|
12
|
+
// TODO: support multiple nodes selection
|
|
13
|
+
} else if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup' && node.childCount === 1) {
|
|
14
|
+
var $mediaStartPos = tr.doc.resolve(start + 1);
|
|
15
|
+
return new NodeSelection($mediaStartPos);
|
|
12
16
|
} else {
|
|
13
17
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
14
18
|
// Find the first inline node in the node
|
package/dist/types/types.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export interface PluginState {
|
|
|
17
17
|
} | null;
|
|
18
18
|
isResizerResizing: boolean;
|
|
19
19
|
isDocSizeLimitEnabled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* is dragging the node without using drag handle, i,e, native prosemirror DnD
|
|
22
|
+
*/
|
|
23
|
+
isPMDragging: boolean;
|
|
20
24
|
}
|
|
21
25
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
22
26
|
export type BlockControlsSharedState = {
|
|
@@ -27,6 +31,7 @@ export type BlockControlsSharedState = {
|
|
|
27
31
|
} | null;
|
|
28
32
|
decorationState: DecorationState;
|
|
29
33
|
isDragging: boolean;
|
|
34
|
+
isPMDragging: boolean;
|
|
30
35
|
} | undefined;
|
|
31
36
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
32
37
|
dependencies: [
|
|
@@ -17,6 +17,10 @@ export interface PluginState {
|
|
|
17
17
|
} | null;
|
|
18
18
|
isResizerResizing: boolean;
|
|
19
19
|
isDocSizeLimitEnabled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* is dragging the node without using drag handle, i,e, native prosemirror DnD
|
|
22
|
+
*/
|
|
23
|
+
isPMDragging: boolean;
|
|
20
24
|
}
|
|
21
25
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
22
26
|
export type BlockControlsSharedState = {
|
|
@@ -27,6 +31,7 @@ export type BlockControlsSharedState = {
|
|
|
27
31
|
} | null;
|
|
28
32
|
decorationState: DecorationState;
|
|
29
33
|
isDragging: boolean;
|
|
34
|
+
isPMDragging: boolean;
|
|
30
35
|
} | undefined;
|
|
31
36
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
32
37
|
dependencies: [
|
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.33",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
41
41
|
"@atlaskit/editor-shared-styles": "^2.12.0",
|
|
42
42
|
"@atlaskit/editor-tables": "^2.7.0",
|
|
43
|
-
"@atlaskit/icon": "^22.
|
|
43
|
+
"@atlaskit/icon": "^22.5.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^0.2.0",
|
|
45
45
|
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.3.0",
|