@atlaskit/editor-plugin-block-controls 1.4.30 → 1.4.32

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.32
4
+
5
+ ### Patch Changes
6
+
7
+ - [#113591](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/113591)
8
+ [`cc5ac590d4c43`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cc5ac590d4c43) -
9
+ [ED-23794] Fix the issue where prosemirror drag and drop stop working with block controls plugin
10
+ enabled
11
+ - [#114565](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/114565)
12
+ [`9c4aee75822c7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9c4aee75822c7) -
13
+ Add analytic event for drag and drop click event
14
+
15
+ ## 1.4.31
16
+
17
+ ### Patch Changes
18
+
19
+ - [#110942](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110942)
20
+ [`aa339aee9aa7d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/aa339aee9aa7d) -
21
+ [ED-23431] Fix EditorPluginAPI type system
22
+ - Updated dependencies
23
+
3
24
  ## 1.4.30
4
25
 
5
26
  ### Patch Changes
@@ -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() {
@@ -61,7 +61,8 @@ var destroyFn = function destroyFn(api) {
61
61
  })(tr);
62
62
  }
63
63
  return tr.setMeta(key, {
64
- isDragging: false
64
+ isDragging: false,
65
+ isPMDragging: false
65
66
  });
66
67
  });
67
68
  }
@@ -76,7 +77,8 @@ var initialState = {
76
77
  isMenuOpen: false,
77
78
  editorHeight: 0,
78
79
  isResizerResizing: false,
79
- isDocSizeLimitEnabled: false
80
+ isDocSizeLimitEnabled: false,
81
+ isPMDragging: false
80
82
  };
81
83
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
82
84
  initialState.isDocSizeLimitEnabled = true;
@@ -90,7 +92,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
90
92
  return initialState;
91
93
  },
92
94
  apply: function apply(tr, currentState, oldState, newState) {
93
- var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
95
+ var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
94
96
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
95
97
  return initialState;
96
98
  }
@@ -100,7 +102,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
100
102
  decorationState = currentState.decorationState,
101
103
  editorHeight = currentState.editorHeight,
102
104
  isResizerResizing = currentState.isResizerResizing,
103
- isDragging = currentState.isDragging;
105
+ isDragging = currentState.isDragging,
106
+ isPMDragging = currentState.isPMDragging;
104
107
  var meta = tr.getMeta(key);
105
108
  // when creating analytics during drag/drop events, PM thinks the doc has changed
106
109
  // so tr.docChange is true and causes some decorations to not render
@@ -236,7 +239,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
236
239
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
237
240
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
238
241
  isResizerResizing: isResizerResizing,
239
- isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
242
+ isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
243
+ isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
240
244
  };
241
245
  }
242
246
  },
@@ -255,13 +259,19 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
255
259
  // prosemirror has sends a default transaction on drop (meta where uiEvent is 'drop'),
256
260
  // this duplicates the an empty version of the node it was dropping,
257
261
  // Adding some check here to prevent that if drop position is within activeNode
258
- var state = view.state;
262
+ var state = view.state,
263
+ dispatch = view.dispatch;
259
264
  var pluginState = key.getState(state);
265
+ if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
266
+ dispatch(state.tr.setMeta(key, {
267
+ isPMDragging: false
268
+ }));
269
+ }
260
270
  if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
261
271
  return false;
262
272
  }
263
273
  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 = (node === null || node === void 0 ? void 0 : node.contains(event.target)) || event.target === node;
274
+ var isActiveNode = event.target === node;
265
275
  if (isActiveNode) {
266
276
  // Prevent the default drop behavior if the position is within the activeNode
267
277
  event.preventDefault();
@@ -269,6 +279,21 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
269
279
  }
270
280
  return false;
271
281
  },
282
+ dragstart: function dragstart(view) {
283
+ view.dispatch(view.state.tr.setMeta(key, {
284
+ isPMDragging: true
285
+ }));
286
+ },
287
+ dragend: function dragend(view) {
288
+ var _key$getState2;
289
+ var state = view.state,
290
+ dispatch = view.dispatch;
291
+ if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
292
+ dispatch(state.tr.setMeta(key, {
293
+ isPMDragging: false
294
+ }));
295
+ }
296
+ },
272
297
  mouseover: function mouseover(view, event) {
273
298
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
274
299
  (0, _handleMouseOver.handleMouseOver)(view, event, api);
@@ -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$analytics;
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$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
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 onMouseEnter = (0, _react.useCallback)(function () {
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
  };
@@ -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() {
@@ -55,7 +55,8 @@ const destroyFn = api => {
55
55
  })(tr);
56
56
  }
57
57
  return tr.setMeta(key, {
58
- isDragging: false
58
+ isDragging: false,
59
+ isPMDragging: false
59
60
  });
60
61
  });
61
62
  }
@@ -70,7 +71,8 @@ const initialState = {
70
71
  isMenuOpen: false,
71
72
  editorHeight: 0,
72
73
  isResizerResizing: false,
73
- isDocSizeLimitEnabled: false
74
+ isDocSizeLimitEnabled: false,
75
+ isPMDragging: false
74
76
  };
75
77
  if (getBooleanFF('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
76
78
  initialState.isDocSizeLimitEnabled = true;
@@ -84,7 +86,7 @@ export const createPlugin = api => {
84
86
  return initialState;
85
87
  },
86
88
  apply(tr, currentState, oldState, newState) {
87
- var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
89
+ var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
88
90
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
89
91
  return initialState;
90
92
  }
@@ -95,7 +97,8 @@ export const createPlugin = api => {
95
97
  decorationState,
96
98
  editorHeight,
97
99
  isResizerResizing,
98
- isDragging
100
+ isDragging,
101
+ isPMDragging
99
102
  } = currentState;
100
103
  const meta = tr.getMeta(key);
101
104
  // when creating analytics during drag/drop events, PM thinks the doc has changed
@@ -227,7 +230,8 @@ export const createPlugin = api => {
227
230
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
228
231
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
229
232
  isResizerResizing: isResizerResizing,
230
- isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
233
+ isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
234
+ isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
231
235
  };
232
236
  }
233
237
  },
@@ -247,14 +251,20 @@ export const createPlugin = api => {
247
251
  // this duplicates the an empty version of the node it was dropping,
248
252
  // Adding some check here to prevent that if drop position is within activeNode
249
253
  const {
250
- state
254
+ state,
255
+ dispatch
251
256
  } = view;
252
257
  const pluginState = key.getState(state);
258
+ if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
259
+ dispatch(state.tr.setMeta(key, {
260
+ isPMDragging: false
261
+ }));
262
+ }
253
263
  if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
254
264
  return false;
255
265
  }
256
266
  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 = (node === null || node === void 0 ? void 0 : node.contains(event.target)) || event.target === node;
267
+ const isActiveNode = event.target === node;
258
268
  if (isActiveNode) {
259
269
  // Prevent the default drop behavior if the position is within the activeNode
260
270
  event.preventDefault();
@@ -262,6 +272,23 @@ export const createPlugin = api => {
262
272
  }
263
273
  return false;
264
274
  },
275
+ dragstart(view) {
276
+ view.dispatch(view.state.tr.setMeta(key, {
277
+ isPMDragging: true
278
+ }));
279
+ },
280
+ dragend(view) {
281
+ var _key$getState2;
282
+ const {
283
+ state,
284
+ dispatch
285
+ } = view;
286
+ if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
287
+ dispatch(state.tr.setMeta(key, {
288
+ isPMDragging: false
289
+ }));
290
+ }
291
+ },
265
292
  mouseover: (view, event) => {
266
293
  if (getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
267
294
  handleMouseOver(view, event, api);
@@ -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$analytics;
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$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
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: 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
  };
@@ -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() {
@@ -54,7 +54,8 @@ var destroyFn = function destroyFn(api) {
54
54
  })(tr);
55
55
  }
56
56
  return tr.setMeta(key, {
57
- isDragging: false
57
+ isDragging: false,
58
+ isPMDragging: false
58
59
  });
59
60
  });
60
61
  }
@@ -69,7 +70,8 @@ var initialState = {
69
70
  isMenuOpen: false,
70
71
  editorHeight: 0,
71
72
  isResizerResizing: false,
72
- isDocSizeLimitEnabled: false
73
+ isDocSizeLimitEnabled: false,
74
+ isPMDragging: false
73
75
  };
74
76
  if (getBooleanFF('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
75
77
  initialState.isDocSizeLimitEnabled = true;
@@ -83,7 +85,7 @@ export var createPlugin = function createPlugin(api) {
83
85
  return initialState;
84
86
  },
85
87
  apply: function apply(tr, currentState, oldState, newState) {
86
- var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight;
88
+ var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$isPMDragging;
87
89
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
88
90
  return initialState;
89
91
  }
@@ -93,7 +95,8 @@ export var createPlugin = function createPlugin(api) {
93
95
  decorationState = currentState.decorationState,
94
96
  editorHeight = currentState.editorHeight,
95
97
  isResizerResizing = currentState.isResizerResizing,
96
- isDragging = currentState.isDragging;
98
+ isDragging = currentState.isDragging,
99
+ isPMDragging = currentState.isPMDragging;
97
100
  var meta = tr.getMeta(key);
98
101
  // when creating analytics during drag/drop events, PM thinks the doc has changed
99
102
  // so tr.docChange is true and causes some decorations to not render
@@ -229,7 +232,8 @@ export var createPlugin = function createPlugin(api) {
229
232
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
230
233
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
231
234
  isResizerResizing: isResizerResizing,
232
- isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled
235
+ isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
236
+ isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
233
237
  };
234
238
  }
235
239
  },
@@ -248,13 +252,19 @@ export var createPlugin = function createPlugin(api) {
248
252
  // prosemirror has sends a default transaction on drop (meta where uiEvent is 'drop'),
249
253
  // this duplicates the an empty version of the node it was dropping,
250
254
  // Adding some check here to prevent that if drop position is within activeNode
251
- var state = view.state;
255
+ var state = view.state,
256
+ dispatch = view.dispatch;
252
257
  var pluginState = key.getState(state);
258
+ if (pluginState !== null && pluginState !== void 0 && pluginState.isPMDragging) {
259
+ dispatch(state.tr.setMeta(key, {
260
+ isPMDragging: false
261
+ }));
262
+ }
253
263
  if (!(event.target instanceof HTMLElement) || !(pluginState !== null && pluginState !== void 0 && pluginState.activeNode)) {
254
264
  return false;
255
265
  }
256
266
  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 = (node === null || node === void 0 ? void 0 : node.contains(event.target)) || event.target === node;
267
+ var isActiveNode = event.target === node;
258
268
  if (isActiveNode) {
259
269
  // Prevent the default drop behavior if the position is within the activeNode
260
270
  event.preventDefault();
@@ -262,6 +272,21 @@ export var createPlugin = function createPlugin(api) {
262
272
  }
263
273
  return false;
264
274
  },
275
+ dragstart: function dragstart(view) {
276
+ view.dispatch(view.state.tr.setMeta(key, {
277
+ isPMDragging: true
278
+ }));
279
+ },
280
+ dragend: function dragend(view) {
281
+ var _key$getState2;
282
+ var state = view.state,
283
+ dispatch = view.dispatch;
284
+ if ((_key$getState2 = key.getState(state)) !== null && _key$getState2 !== void 0 && _key$getState2.isPMDragging) {
285
+ dispatch(state.tr.setMeta(key, {
286
+ isPMDragging: false
287
+ }));
288
+ }
289
+ },
265
290
  mouseover: function mouseover(view, event) {
266
291
  if (getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
267
292
  handleMouseOver(view, event, api);
@@ -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$analytics;
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$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
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 onMouseEnter = useCallback(function () {
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
  };
@@ -13,4 +13,5 @@ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin
13
13
  editorHeight: any;
14
14
  isResizerResizing: boolean;
15
15
  isDocSizeLimitEnabled: boolean;
16
+ isPMDragging: any;
16
17
  }>;
@@ -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: [
@@ -2,4 +2,4 @@ export declare const DRAG_HANDLE_HEIGHT = 24;
2
2
  export declare const DRAG_HANDLE_WIDTH = 12;
3
3
  export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export declare const DRAG_HANDLE_ZINDEX: number;
5
- export declare const dragHandleGap: (nodeType: string) => 12 | 8;
5
+ export declare const dragHandleGap: (nodeType: string) => 8 | 12;
@@ -13,4 +13,5 @@ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin
13
13
  editorHeight: any;
14
14
  isResizerResizing: boolean;
15
15
  isDocSizeLimitEnabled: boolean;
16
+ isPMDragging: any;
16
17
  }>;
@@ -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: [
@@ -2,4 +2,4 @@ export declare const DRAG_HANDLE_HEIGHT = 24;
2
2
  export declare const DRAG_HANDLE_WIDTH = 12;
3
3
  export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export declare const DRAG_HANDLE_ZINDEX: number;
5
- export declare const dragHandleGap: (nodeType: string) => 12 | 8;
5
+ export declare const dragHandleGap: (nodeType: string) => 8 | 12;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.30",
3
+ "version": "1.4.32",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^37.0.0",
35
- "@atlaskit/editor-common": "^82.14.0",
35
+ "@atlaskit/editor-common": "^83.0.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.3.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
38
38
  "@atlaskit/editor-plugin-feature-flags": "^1.1.0",