@atlaskit/editor-plugin-block-controls 1.4.14 → 1.4.16

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,23 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.16
4
+
5
+ ### Patch Changes
6
+
7
+ - [#108805](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108805)
8
+ [`3695cb26b9899`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3695cb26b9899) -
9
+ Add analytic events for drag events
10
+ - Updated dependencies
11
+
12
+ ## 1.4.15
13
+
14
+ ### Patch Changes
15
+
16
+ - [#110434](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110434)
17
+ [`fca2ac7c4fb70`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fca2ac7c4fb70) -
18
+ [ux] Show generic drag preview when dragging an embed node
19
+ - Updated dependencies
20
+
3
21
  ## 1.4.14
4
22
 
5
23
  ### Patch Changes
@@ -7,11 +7,48 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.key = exports.createPlugin = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
10
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
12
13
  var _view = require("@atlaskit/editor-prosemirror/view");
14
+ var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
13
15
  var _decorations = require("./decorations");
14
16
  var key = exports.key = new _state.PluginKey('blockControls');
17
+ var destroyFn = function destroyFn(api) {
18
+ return (0, _adapter.monitorForElements)({
19
+ canMonitor: function canMonitor(_ref) {
20
+ var source = _ref.source;
21
+ return source.data.type === 'element';
22
+ },
23
+ onDrop: function onDrop(_ref2) {
24
+ var location = _ref2.location,
25
+ source = _ref2.source;
26
+ // if no drop targets are rendered, assume that drop is invalid
27
+ if (location.current.dropTargets.length === 0) {
28
+ var _api$core;
29
+ var _ref3 = source.data,
30
+ start = _ref3.start;
31
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
32
+ var _api$analytics;
33
+ var tr = _ref4.tr;
34
+ var resolvedMovingNode = tr.doc.resolve(start);
35
+ var maybeNode = resolvedMovingNode.nodeAfter;
36
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
37
+ eventType: _analytics.EVENT_TYPE.UI,
38
+ action: _analytics.ACTION.CANCELLED,
39
+ actionSubject: _analytics.ACTION_SUBJECT.DRAG,
40
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
41
+ attributes: {
42
+ nodeDepth: resolvedMovingNode.depth,
43
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
44
+ }
45
+ })(tr);
46
+ return tr;
47
+ });
48
+ }
49
+ }
50
+ });
51
+ };
15
52
  var createPlugin = exports.createPlugin = function createPlugin(api) {
16
53
  return new _safePlugin.SafePlugin({
17
54
  key: key,
@@ -52,8 +89,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
52
89
 
53
90
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
54
91
  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) {
55
- var oldHandle = decorations.find().filter(function (_ref) {
56
- var spec = _ref.spec;
92
+ var oldHandle = decorations.find().filter(function (_ref5) {
93
+ var spec = _ref5.spec;
57
94
  return spec.id === 'drag-handle';
58
95
  });
59
96
  decorations = decorations.remove(oldHandle);
@@ -72,8 +109,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
72
109
 
73
110
  // Remove drop target decoration when dragging stops
74
111
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
75
- var dropTargetDecs = decorations.find().filter(function (_ref2) {
76
- var spec = _ref2.spec;
112
+ var dropTargetDecs = decorations.find().filter(function (_ref6) {
113
+ var spec = _ref6.spec;
77
114
  return spec.type === 'drop-target-decoration';
78
115
  });
79
116
  decorations = decorations.remove(dropTargetDecs);
@@ -81,9 +118,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
81
118
 
82
119
  // Map drop target decoration positions when the document changes
83
120
  if (tr.docChanged && currentState.isDragging) {
84
- decorationState = decorationState.map(function (_ref3) {
85
- var index = _ref3.index,
86
- pos = _ref3.pos;
121
+ decorationState = decorationState.map(function (_ref7) {
122
+ var index = _ref7.index,
123
+ pos = _ref7.pos;
87
124
  return {
88
125
  index: index,
89
126
  pos: tr.mapping.map(pos)
@@ -143,6 +180,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
143
180
  return {
144
181
  destroy: function destroy() {
145
182
  resizeObserver.unobserve(dom);
183
+ return destroyFn(api);
146
184
  }
147
185
  };
148
186
  }
@@ -105,6 +105,12 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
105
105
  }
106
106
  return (0, _adapter.draggable)({
107
107
  element: element,
108
+ getInitialData: function getInitialData() {
109
+ return {
110
+ type: 'element',
111
+ start: start
112
+ };
113
+ },
108
114
  onGenerateDragPreview: function onGenerateDragPreview(_ref4) {
109
115
  var nativeSetDragImage = _ref4.nativeSetDragImage;
110
116
  (0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
@@ -114,7 +120,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
114
120
  if (!dom) {
115
121
  return;
116
122
  }
117
- return (0, _dragPreview.dragPreview)(container, dom);
123
+ return (0, _dragPreview.dragPreview)(container, dom, nodeType);
118
124
  },
119
125
  nativeSetDragImage: nativeSetDragImage
120
126
  });
@@ -4,7 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dragPreview = void 0;
7
- var dragPreview = exports.dragPreview = function dragPreview(container, dom) {
7
+ //
8
+ var previewStyle = {
9
+ borderColor: "var(--ds-border-focused, #388BFF)",
10
+ borderStyle: 'solid',
11
+ borderRadius: "var(--ds-border-radius-100, 4px)",
12
+ borderWidth: "var(--ds-border-width-outline, 2px)",
13
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
14
+ };
15
+ var dragPreview = exports.dragPreview = function dragPreview(container, dom, nodeType) {
8
16
  var rect = dom.getBoundingClientRect();
9
17
  container.style.width = "".concat(rect.width, "px");
10
18
  container.style.height = "".concat(rect.height, "px");
@@ -12,15 +20,23 @@ var dragPreview = exports.dragPreview = function dragPreview(container, dom) {
12
20
  var parent = document.createElement('div');
13
21
  // ProseMirror class is required to make sure the cloned dom is styled correctly
14
22
  parent.classList.add('ProseMirror');
15
- parent.style.opacity = '0.3';
23
+ var isEmbedCard = nodeType === 'embedCard';
24
+ if (isEmbedCard) {
25
+ parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
26
+ parent.style.borderRadius = previewStyle.borderRadius;
27
+ parent.style.backgroundColor = previewStyle.backgroundColor;
28
+ parent.style.height = '100%';
29
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
30
+ }
16
31
  var resizer = dom.querySelector('.resizer-item');
17
- var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
32
+ var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
18
33
 
19
34
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
20
35
  clonedDom.style.marginLeft = '0';
21
36
  clonedDom.style.marginTop = '0';
22
37
  clonedDom.style.marginRight = '0';
23
38
  clonedDom.style.marginBottom = '0';
39
+ clonedDom.style.opacity = '0.4';
24
40
  parent.appendChild(clonedDom);
25
41
  container.appendChild(parent);
26
42
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -8,6 +8,7 @@ exports.DropTarget = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var _react2 = require("@emotion/react");
11
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _hooks = require("@atlaskit/editor-common/hooks");
12
13
  var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
13
14
  var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
@@ -62,7 +63,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
62
63
  scrollable.style.setProperty('scroll-behavior', 'unset');
63
64
  },
64
65
  onDragEnter: function onDragEnter() {
65
- return setIsDraggedOver(true);
66
+ setIsDraggedOver(true);
66
67
  },
67
68
  onDragLeave: function onDragLeave() {
68
69
  return setIsDraggedOver(false);
@@ -81,9 +82,25 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
81
82
  }) || {},
82
83
  pos = _ref3.pos;
83
84
  if (activeNode && pos !== undefined) {
84
- var _api$core, _api$blockControls2;
85
+ var _api$core;
85
86
  var start = activeNode.pos;
86
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos));
87
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (state) {
88
+ var _api$blockControls2, _api$analytics;
89
+ var resolvedMovingNode = state.tr.doc.resolve(start);
90
+ var maybeNode = resolvedMovingNode.nodeAfter;
91
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.moveNode(start, pos)(state);
92
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
93
+ eventType: _analytics.EVENT_TYPE.UI,
94
+ action: _analytics.ACTION.DRAGGED,
95
+ actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
96
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
97
+ attributes: {
98
+ nodeDepth: resolvedMovingNode.depth,
99
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
100
+ }
101
+ })(state.tr);
102
+ return state.tr;
103
+ });
87
104
  }
88
105
  }
89
106
  }));
@@ -96,7 +113,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
96
113
  ref: ref,
97
114
  "data-testid": "block-ctrl-drop-target"
98
115
  },
99
- //4px gap to clear expand node border
116
+ // 4px gap to clear expand node border
100
117
  isDraggedOver && (0, _react2.jsx)("div", {
101
118
  css: styleDropIndicator,
102
119
  style: {
@@ -1,9 +1,48 @@
1
1
  import rafSchedule from 'raf-schd';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
5
7
  import { dragHandleDecoration, dropTargetDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
6
8
  export const key = new PluginKey('blockControls');
9
+ const destroyFn = api => {
10
+ return monitorForElements({
11
+ canMonitor: ({
12
+ source
13
+ }) => source.data.type === 'element',
14
+ onDrop: ({
15
+ location,
16
+ source
17
+ }) => {
18
+ // if no drop targets are rendered, assume that drop is invalid
19
+ if (location.current.dropTargets.length === 0) {
20
+ var _api$core;
21
+ const {
22
+ start
23
+ } = source.data;
24
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
25
+ tr
26
+ }) => {
27
+ var _api$analytics;
28
+ const resolvedMovingNode = tr.doc.resolve(start);
29
+ const maybeNode = resolvedMovingNode.nodeAfter;
30
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
31
+ eventType: EVENT_TYPE.UI,
32
+ action: ACTION.CANCELLED,
33
+ actionSubject: ACTION_SUBJECT.DRAG,
34
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
35
+ attributes: {
36
+ nodeDepth: resolvedMovingNode.depth,
37
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
38
+ }
39
+ })(tr);
40
+ return tr;
41
+ });
42
+ }
43
+ }
44
+ });
45
+ };
7
46
  export const createPlugin = api => {
8
47
  return new SafePlugin({
9
48
  key,
@@ -137,6 +176,7 @@ export const createPlugin = api => {
137
176
  return {
138
177
  destroy() {
139
178
  resizeObserver.unobserve(dom);
179
+ return destroyFn(api);
140
180
  }
141
181
  };
142
182
  }
@@ -97,6 +97,10 @@ export const DragHandle = ({
97
97
  }
98
98
  return draggable({
99
99
  element,
100
+ getInitialData: () => ({
101
+ type: 'element',
102
+ start
103
+ }),
100
104
  onGenerateDragPreview: ({
101
105
  nativeSetDragImage
102
106
  }) => {
@@ -108,7 +112,7 @@ export const DragHandle = ({
108
112
  if (!dom) {
109
113
  return;
110
114
  }
111
- return dragPreview(container, dom);
115
+ return dragPreview(container, dom, nodeType);
112
116
  },
113
117
  nativeSetDragImage
114
118
  });
@@ -1,4 +1,12 @@
1
- export const dragPreview = (container, dom) => {
1
+ //
2
+ const previewStyle = {
3
+ borderColor: "var(--ds-border-focused, #388BFF)",
4
+ borderStyle: 'solid',
5
+ borderRadius: "var(--ds-border-radius-100, 4px)",
6
+ borderWidth: "var(--ds-border-width-outline, 2px)",
7
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
8
+ };
9
+ export const dragPreview = (container, dom, nodeType) => {
2
10
  const rect = dom.getBoundingClientRect();
3
11
  container.style.width = `${rect.width}px`;
4
12
  container.style.height = `${rect.height}px`;
@@ -6,15 +14,23 @@ export const dragPreview = (container, dom) => {
6
14
  const parent = document.createElement('div');
7
15
  // ProseMirror class is required to make sure the cloned dom is styled correctly
8
16
  parent.classList.add('ProseMirror');
9
- parent.style.opacity = '0.3';
17
+ const isEmbedCard = nodeType === 'embedCard';
18
+ if (isEmbedCard) {
19
+ parent.style.border = `${previewStyle.borderWidth} ${previewStyle.borderStyle} ${previewStyle.borderColor}`;
20
+ parent.style.borderRadius = previewStyle.borderRadius;
21
+ parent.style.backgroundColor = previewStyle.backgroundColor;
22
+ parent.style.height = '100%';
23
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
24
+ }
10
25
  const resizer = dom.querySelector('.resizer-item');
11
- const clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
26
+ const clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
12
27
 
13
28
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
14
29
  clonedDom.style.marginLeft = '0';
15
30
  clonedDom.style.marginTop = '0';
16
31
  clonedDom.style.marginRight = '0';
17
32
  clonedDom.style.marginBottom = '0';
33
+ clonedDom.style.opacity = '0.4';
18
34
  parent.appendChild(clonedDom);
19
35
  container.appendChild(parent);
20
36
  const scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -1,6 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
5
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
6
  import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
6
7
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
@@ -49,7 +50,9 @@ export const DropTarget = ({
49
50
  onDrag: () => {
50
51
  scrollable.style.setProperty('scroll-behavior', 'unset');
51
52
  },
52
- onDragEnter: () => setIsDraggedOver(true),
53
+ onDragEnter: () => {
54
+ setIsDraggedOver(true);
55
+ },
53
56
  onDragLeave: () => setIsDraggedOver(false),
54
57
  onDrop: () => {
55
58
  var _api$blockControls;
@@ -65,11 +68,27 @@ export const DropTarget = ({
65
68
  pos
66
69
  } = decorationState.find(dec => dec.index === index) || {};
67
70
  if (activeNode && pos !== undefined) {
68
- var _api$core, _api$blockControls2, _api$blockControls2$c;
71
+ var _api$core;
69
72
  const {
70
73
  pos: start
71
74
  } = activeNode;
72
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.moveNode(start, pos));
75
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(state => {
76
+ var _api$blockControls2, _api$blockControls2$c, _api$analytics;
77
+ const resolvedMovingNode = state.tr.doc.resolve(start);
78
+ const maybeNode = resolvedMovingNode.nodeAfter;
79
+ api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.moveNode(start, pos)(state);
80
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
81
+ eventType: EVENT_TYPE.UI,
82
+ action: ACTION.DRAGGED,
83
+ actionSubject: ACTION_SUBJECT.ELEMENT,
84
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
85
+ attributes: {
86
+ nodeDepth: resolvedMovingNode.depth,
87
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
88
+ }
89
+ })(state.tr);
90
+ return state.tr;
91
+ });
73
92
  }
74
93
  }
75
94
  }));
@@ -82,7 +101,7 @@ export const DropTarget = ({
82
101
  ref: ref,
83
102
  "data-testid": "block-ctrl-drop-target"
84
103
  },
85
- //4px gap to clear expand node border
104
+ // 4px gap to clear expand node border
86
105
  isDraggedOver && jsx("div", {
87
106
  css: styleDropIndicator,
88
107
  style: {
@@ -1,10 +1,47 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import rafSchedule from 'raf-schd';
3
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
8
  import { dragHandleDecoration, dropTargetDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
7
9
  export var key = new PluginKey('blockControls');
10
+ var destroyFn = function destroyFn(api) {
11
+ return monitorForElements({
12
+ canMonitor: function canMonitor(_ref) {
13
+ var source = _ref.source;
14
+ return source.data.type === 'element';
15
+ },
16
+ onDrop: function onDrop(_ref2) {
17
+ var location = _ref2.location,
18
+ source = _ref2.source;
19
+ // if no drop targets are rendered, assume that drop is invalid
20
+ if (location.current.dropTargets.length === 0) {
21
+ var _api$core;
22
+ var _ref3 = source.data,
23
+ start = _ref3.start;
24
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
25
+ var _api$analytics;
26
+ var tr = _ref4.tr;
27
+ var resolvedMovingNode = tr.doc.resolve(start);
28
+ var maybeNode = resolvedMovingNode.nodeAfter;
29
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
30
+ eventType: EVENT_TYPE.UI,
31
+ action: ACTION.CANCELLED,
32
+ actionSubject: ACTION_SUBJECT.DRAG,
33
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
34
+ attributes: {
35
+ nodeDepth: resolvedMovingNode.depth,
36
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
37
+ }
38
+ })(tr);
39
+ return tr;
40
+ });
41
+ }
42
+ }
43
+ });
44
+ };
8
45
  export var createPlugin = function createPlugin(api) {
9
46
  return new SafePlugin({
10
47
  key: key,
@@ -45,8 +82,8 @@ export var createPlugin = function createPlugin(api) {
45
82
 
46
83
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
47
84
  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) {
48
- var oldHandle = decorations.find().filter(function (_ref) {
49
- var spec = _ref.spec;
85
+ var oldHandle = decorations.find().filter(function (_ref5) {
86
+ var spec = _ref5.spec;
50
87
  return spec.id === 'drag-handle';
51
88
  });
52
89
  decorations = decorations.remove(oldHandle);
@@ -65,8 +102,8 @@ export var createPlugin = function createPlugin(api) {
65
102
 
66
103
  // Remove drop target decoration when dragging stops
67
104
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
68
- var dropTargetDecs = decorations.find().filter(function (_ref2) {
69
- var spec = _ref2.spec;
105
+ var dropTargetDecs = decorations.find().filter(function (_ref6) {
106
+ var spec = _ref6.spec;
70
107
  return spec.type === 'drop-target-decoration';
71
108
  });
72
109
  decorations = decorations.remove(dropTargetDecs);
@@ -74,9 +111,9 @@ export var createPlugin = function createPlugin(api) {
74
111
 
75
112
  // Map drop target decoration positions when the document changes
76
113
  if (tr.docChanged && currentState.isDragging) {
77
- decorationState = decorationState.map(function (_ref3) {
78
- var index = _ref3.index,
79
- pos = _ref3.pos;
114
+ decorationState = decorationState.map(function (_ref7) {
115
+ var index = _ref7.index,
116
+ pos = _ref7.pos;
80
117
  return {
81
118
  index: index,
82
119
  pos: tr.mapping.map(pos)
@@ -136,6 +173,7 @@ export var createPlugin = function createPlugin(api) {
136
173
  return {
137
174
  destroy: function destroy() {
138
175
  resizeObserver.unobserve(dom);
176
+ return destroyFn(api);
139
177
  }
140
178
  };
141
179
  }
@@ -97,6 +97,12 @@ export var DragHandle = function DragHandle(_ref) {
97
97
  }
98
98
  return draggable({
99
99
  element: element,
100
+ getInitialData: function getInitialData() {
101
+ return {
102
+ type: 'element',
103
+ start: start
104
+ };
105
+ },
100
106
  onGenerateDragPreview: function onGenerateDragPreview(_ref4) {
101
107
  var nativeSetDragImage = _ref4.nativeSetDragImage;
102
108
  setCustomNativeDragPreview({
@@ -106,7 +112,7 @@ export var DragHandle = function DragHandle(_ref) {
106
112
  if (!dom) {
107
113
  return;
108
114
  }
109
- return dragPreview(container, dom);
115
+ return dragPreview(container, dom, nodeType);
110
116
  },
111
117
  nativeSetDragImage: nativeSetDragImage
112
118
  });
@@ -1,4 +1,12 @@
1
- export var dragPreview = function dragPreview(container, dom) {
1
+ //
2
+ var previewStyle = {
3
+ borderColor: "var(--ds-border-focused, #388BFF)",
4
+ borderStyle: 'solid',
5
+ borderRadius: "var(--ds-border-radius-100, 4px)",
6
+ borderWidth: "var(--ds-border-width-outline, 2px)",
7
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
8
+ };
9
+ export var dragPreview = function dragPreview(container, dom, nodeType) {
2
10
  var rect = dom.getBoundingClientRect();
3
11
  container.style.width = "".concat(rect.width, "px");
4
12
  container.style.height = "".concat(rect.height, "px");
@@ -6,15 +14,23 @@ export var dragPreview = function dragPreview(container, dom) {
6
14
  var parent = document.createElement('div');
7
15
  // ProseMirror class is required to make sure the cloned dom is styled correctly
8
16
  parent.classList.add('ProseMirror');
9
- parent.style.opacity = '0.3';
17
+ var isEmbedCard = nodeType === 'embedCard';
18
+ if (isEmbedCard) {
19
+ parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
20
+ parent.style.borderRadius = previewStyle.borderRadius;
21
+ parent.style.backgroundColor = previewStyle.backgroundColor;
22
+ parent.style.height = '100%';
23
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
24
+ }
10
25
  var resizer = dom.querySelector('.resizer-item');
11
- var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
26
+ var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
12
27
 
13
28
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
14
29
  clonedDom.style.marginLeft = '0';
15
30
  clonedDom.style.marginTop = '0';
16
31
  clonedDom.style.marginRight = '0';
17
32
  clonedDom.style.marginBottom = '0';
33
+ clonedDom.style.opacity = '0.4';
18
34
  parent.appendChild(clonedDom);
19
35
  container.appendChild(parent);
20
36
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
6
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
7
  import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
7
8
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
@@ -54,7 +55,7 @@ export var DropTarget = function DropTarget(_ref) {
54
55
  scrollable.style.setProperty('scroll-behavior', 'unset');
55
56
  },
56
57
  onDragEnter: function onDragEnter() {
57
- return setIsDraggedOver(true);
58
+ setIsDraggedOver(true);
58
59
  },
59
60
  onDragLeave: function onDragLeave() {
60
61
  return setIsDraggedOver(false);
@@ -73,9 +74,25 @@ export var DropTarget = function DropTarget(_ref) {
73
74
  }) || {},
74
75
  pos = _ref3.pos;
75
76
  if (activeNode && pos !== undefined) {
76
- var _api$core, _api$blockControls2;
77
+ var _api$core;
77
78
  var start = activeNode.pos;
78
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos));
79
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (state) {
80
+ var _api$blockControls2, _api$analytics;
81
+ var resolvedMovingNode = state.tr.doc.resolve(start);
82
+ var maybeNode = resolvedMovingNode.nodeAfter;
83
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.moveNode(start, pos)(state);
84
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
85
+ eventType: EVENT_TYPE.UI,
86
+ action: ACTION.DRAGGED,
87
+ actionSubject: ACTION_SUBJECT.ELEMENT,
88
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
89
+ attributes: {
90
+ nodeDepth: resolvedMovingNode.depth,
91
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
92
+ }
93
+ })(state.tr);
94
+ return state.tr;
95
+ });
79
96
  }
80
97
  }
81
98
  }));
@@ -88,7 +105,7 @@ export var DropTarget = function DropTarget(_ref) {
88
105
  ref: ref,
89
106
  "data-testid": "block-ctrl-drop-target"
90
107
  },
91
- //4px gap to clear expand node border
108
+ // 4px gap to clear expand node border
92
109
  isDraggedOver && jsx("div", {
93
110
  css: styleDropIndicator,
94
111
  style: {
@@ -1,4 +1,5 @@
1
1
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import { type AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
2
3
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
3
4
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
5
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
@@ -20,7 +21,8 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
20
21
  dependencies: [
21
22
  OptionalPlugin<EditorDisabledPlugin>,
22
23
  OptionalPlugin<WidthPlugin>,
23
- OptionalPlugin<FeatureFlagsPlugin>
24
+ OptionalPlugin<FeatureFlagsPlugin>,
25
+ OptionalPlugin<AnalyticsPlugin>
24
26
  ];
25
27
  sharedState: {
26
28
  isMenuOpen: boolean;
@@ -1 +1 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement) => () => HTMLElement;
1
+ export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
@@ -1,4 +1,5 @@
1
1
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import { type AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
2
3
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
3
4
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
5
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
@@ -20,7 +21,8 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
20
21
  dependencies: [
21
22
  OptionalPlugin<EditorDisabledPlugin>,
22
23
  OptionalPlugin<WidthPlugin>,
23
- OptionalPlugin<FeatureFlagsPlugin>
24
+ OptionalPlugin<FeatureFlagsPlugin>,
25
+ OptionalPlugin<AnalyticsPlugin>
24
26
  ];
25
27
  sharedState: {
26
28
  isMenuOpen: boolean;
@@ -1 +1 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement) => () => HTMLElement;
1
+ export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.14",
3
+ "version": "1.4.16",
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,8 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^82.3.0",
34
+ "@atlaskit/editor-common": "^82.5.0",
35
+ "@atlaskit/editor-plugin-analytics": "^1.2.3",
35
36
  "@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
36
37
  "@atlaskit/editor-plugin-feature-flags": "^1.1.0",
37
38
  "@atlaskit/editor-plugin-width": "^1.1.0",