@atlaskit/editor-plugin-block-controls 1.4.22 → 1.4.23

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,13 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.23
4
+
5
+ ### Patch Changes
6
+
7
+ - [#112385](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112385)
8
+ [`7889fc5a6eff5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7889fc5a6eff5) -
9
+ Add new moved events for dnd, change which events are fired in block control plugin
10
+
3
11
  ## 1.4.22
4
12
 
5
13
  ### Patch Changes
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.blockControlsPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _main = require("./pm-plugins/main");
10
11
  var _dragHandleMenu = require("./ui/drag-handle-menu");
11
12
  var _globalStyles = require("./ui/global-styles");
@@ -25,9 +26,10 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
25
26
  commands: {
26
27
  moveNode: function moveNode(start, to) {
27
28
  return function (_ref2) {
28
- var _node$nodeSize;
29
+ var _node$nodeSize, _api$analytics;
29
30
  var tr = _ref2.tr;
30
31
  var node = tr.doc.nodeAt(start);
32
+ var resolvedNode = tr.doc.resolve(start);
31
33
  if (!node) {
32
34
  return tr;
33
35
  }
@@ -42,6 +44,16 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
42
44
  nodeMoved: true
43
45
  });
44
46
  api === null || api === void 0 || api.core.actions.focus();
47
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
48
+ eventType: _analytics.EVENT_TYPE.TRACK,
49
+ action: _analytics.ACTION.MOVED,
50
+ actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
51
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
52
+ attributes: {
53
+ nodeDepth: resolvedNode.depth,
54
+ nodeType: node.type.name
55
+ }
56
+ })(tr);
45
57
  return tr;
46
58
  };
47
59
  },
@@ -7,6 +7,7 @@ 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 _steps = require("@atlaskit/adf-schema/steps");
10
11
  var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
13
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -40,18 +41,11 @@ var destroyFn = function destroyFn(api) {
40
41
  scrollable.style.setProperty('scroll-behavior', null);
41
42
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
42
43
  var tr = _ref3.tr;
43
- return tr.setMeta(key, {
44
- isDragging: false
45
- });
46
- });
47
- // if no drop targets are rendered, assume that drop is invalid
48
- if (location.current.dropTargets.length === 0) {
49
- var _api$core2;
50
44
  var _ref4 = source.data,
51
45
  start = _ref4.start;
52
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
46
+ // if no drop targets are rendered, assume that drop is invalid
47
+ if (location.current.dropTargets.length === 0) {
53
48
  var _api$analytics;
54
- var tr = _ref5.tr;
55
49
  var resolvedMovingNode = tr.doc.resolve(start);
56
50
  var maybeNode = resolvedMovingNode.nodeAfter;
57
51
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
@@ -64,9 +58,11 @@ var destroyFn = function destroyFn(api) {
64
58
  nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
65
59
  }
66
60
  })(tr);
67
- return tr;
61
+ }
62
+ return tr.setMeta(key, {
63
+ isDragging: false
68
64
  });
69
- }
65
+ });
70
66
  }
71
67
  }));
72
68
  return _combine.combine.apply(void 0, cleanupFn);
@@ -93,7 +89,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
93
89
  return initialState;
94
90
  },
95
91
  apply: function apply(tr, currentState, oldState, newState) {
96
- var _decorationState, _meta$activeNode, _meta$isDragging, _meta$editorHeight;
92
+ var _meta$activeNode, _meta$isDragging, _meta$editorHeight;
97
93
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
98
94
  return initialState;
99
95
  }
@@ -102,8 +98,14 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
102
98
  isMenuOpen = currentState.isMenuOpen,
103
99
  decorationState = currentState.decorationState,
104
100
  editorHeight = currentState.editorHeight,
105
- isResizerResizing = currentState.isResizerResizing;
101
+ isResizerResizing = currentState.isResizerResizing,
102
+ isDragging = currentState.isDragging;
106
103
  var meta = tr.getMeta(key);
104
+ // when creating analytics during drag/drop events, PM thinks the doc has changed
105
+ // so tr.docChange is true and causes some decorations to not render
106
+ var isAnalyticTr = tr.steps.every(function (step) {
107
+ return step instanceof _steps.AnalyticsStep;
108
+ });
107
109
 
108
110
  // If tables or media are being resized, we want to hide the drag handle
109
111
  var resizerMeta = tr.getMeta('is-resizer-resizing');
@@ -112,8 +114,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
112
114
 
113
115
  // During resize, remove the drag handle widget
114
116
  if (isResizerResizing || nodeCountChanged || meta !== null && meta !== void 0 && meta.nodeMoved) {
115
- var oldHandle = decorations.find().filter(function (_ref6) {
116
- var spec = _ref6.spec;
117
+ var oldHandle = decorations.find().filter(function (_ref5) {
118
+ var spec = _ref5.spec;
117
119
  return spec.id === 'drag-handle';
118
120
  });
119
121
  decorations = decorations.remove(oldHandle);
@@ -133,15 +135,22 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
133
135
  // Note: Quite often the handle is not in the right position after a node is moved
134
136
  // it is safer for now to not show it when a node is moved
135
137
  if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
136
- var draghandleDec = (0, _decorations.dragHandleDecoration)(activeNode.pos, activeNode.anchorName, activeNode.nodeType, api);
138
+ var newActiveNode = activeNode && tr.doc.nodeAt(tr.mapping.map(activeNode.pos));
139
+ var nodeType = activeNode.nodeType;
140
+ var anchorName = activeNode.anchorName;
141
+ if (newActiveNode && (newActiveNode === null || newActiveNode === void 0 ? void 0 : newActiveNode.type.name) !== activeNode.nodeType && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
142
+ nodeType = newActiveNode.type.name;
143
+ anchorName = activeNode.anchorName.replace(activeNode.nodeType, nodeType);
144
+ }
145
+ var draghandleDec = (0, _decorations.dragHandleDecoration)(activeNode.pos, anchorName, nodeType, api);
137
146
  decorations = decorations.add(newState.doc, [draghandleDec]);
138
147
  }
139
148
  }
140
149
 
141
150
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
142
151
  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) {
143
- var _oldHandle = decorations.find().filter(function (_ref7) {
144
- var spec = _ref7.spec;
152
+ var _oldHandle = decorations.find().filter(function (_ref6) {
153
+ var spec = _ref6.spec;
145
154
  return spec.id === 'drag-handle';
146
155
  });
147
156
  decorations = decorations.remove(_oldHandle);
@@ -150,7 +159,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
150
159
  }
151
160
 
152
161
  // Add drop targets when node is being dragged
153
- if (meta !== null && meta !== void 0 && meta.isDragging && !tr.docChanged && api) {
162
+ // if the transaction is only for analytics and user is dragging, continue to draw drop targets
163
+ if (meta !== null && meta !== void 0 && meta.isDragging && (!tr.docChanged || tr.docChanged && isAnalyticTr) && api) {
154
164
  var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api),
155
165
  _decs = _dropTargetDecoration.decs,
156
166
  updatedDecorationState = _dropTargetDecoration.decorationState;
@@ -160,18 +170,18 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
160
170
 
161
171
  // Remove drop target decoration when dragging stops
162
172
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
163
- var dropTargetDecs = decorations.find().filter(function (_ref8) {
164
- var spec = _ref8.spec;
173
+ var dropTargetDecs = decorations.find().filter(function (_ref7) {
174
+ var spec = _ref7.spec;
165
175
  return spec.type === 'drop-target-decoration';
166
176
  });
167
177
  decorations = decorations.remove(dropTargetDecs);
168
178
  }
169
179
 
170
180
  // Map drop target decoration positions when the document changes
171
- if (tr.docChanged && currentState.isDragging) {
172
- decorationState = decorationState.map(function (_ref9) {
173
- var index = _ref9.index,
174
- pos = _ref9.pos;
181
+ if (tr.docChanged && isDragging) {
182
+ decorationState = decorationState.map(function (_ref8) {
183
+ var index = _ref8.index,
184
+ pos = _ref8.pos;
175
185
  return {
176
186
  index: index,
177
187
  pos: tr.mapping.map(pos)
@@ -193,9 +203,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
193
203
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
194
204
  return {
195
205
  decorations: decorations,
196
- decorationState: (_decorationState = decorationState) !== null && _decorationState !== void 0 ? _decorationState : currentState.decorationState,
206
+ decorationState: decorationState,
197
207
  activeNode: isEmptyDoc ? null : (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : mappedActiveNodePos,
198
- isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : currentState.isDragging,
208
+ isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
199
209
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
200
210
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
201
211
  isResizerResizing: isResizerResizing,
@@ -8,6 +8,7 @@ exports.DragHandle = 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 _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-handler"));
13
14
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
@@ -19,6 +20,8 @@ var _consts = require("./consts");
19
20
  var _dragPreview = require("./drag-preview");
20
21
  /** @jsx jsx */
21
22
 
23
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
24
+
22
25
  var dragHandleButtonStyles = (0, _react2.css)({
23
26
  position: 'absolute',
24
27
  padding: "var(--ds-space-025, 2px)".concat(" 0"),
@@ -126,11 +129,30 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
126
129
  });
127
130
  },
128
131
  onDragStart: function onDragStart() {
129
- var _api$core5, _api$blockControls, _api$core6;
132
+ var _api$core5, _api$core6;
130
133
  if (start === undefined) {
131
134
  return;
132
135
  }
133
- api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
136
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
137
+ var _api$blockControls, _api$analytics;
138
+ var tr = _ref6.tr;
139
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
140
+ tr: tr
141
+ });
142
+ var resolvedMovingNode = tr.doc.resolve(start);
143
+ var maybeNode = resolvedMovingNode.nodeAfter;
144
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
145
+ eventType: _analytics.EVENT_TYPE.UI,
146
+ action: _analytics.ACTION.DRAGGED,
147
+ actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
148
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
149
+ attributes: {
150
+ nodeDepth: resolvedMovingNode.depth,
151
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
152
+ }
153
+ })(tr);
154
+ return tr;
155
+ });
134
156
  api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
135
157
  }
136
158
  });
@@ -139,12 +161,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
139
161
  var positionStyles = (0, _react.useMemo)(function () {
140
162
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
141
163
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
142
- if (!dom) {
143
- return;
144
- }
145
164
  var hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
146
165
  var isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
147
- var innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
166
+ var innerContainer = dom ? hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null : null;
148
167
  if (supportsAnchor) {
149
168
  return {
150
169
  left: hasResizer || isExtension ? (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
@@ -8,12 +8,13 @@ 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");
12
11
  var _hooks = require("@atlaskit/editor-common/hooks");
13
12
  var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
14
13
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
15
14
  /** @jsx jsx */
16
15
 
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
17
+
17
18
  var DEFAULT_DROP_INDICATOR_WIDTH = 760;
18
19
  var styleDropTarget = (0, _react2.css)({
19
20
  height: "var(--ds-space-100, 8px)",
@@ -69,25 +70,9 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
69
70
  }) || {},
70
71
  pos = _ref3.pos;
71
72
  if (activeNode && pos !== undefined) {
72
- var _api$core;
73
+ var _api$core, _api$blockControls2;
73
74
  var start = activeNode.pos;
74
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (state) {
75
- var _api$blockControls2, _api$analytics;
76
- var resolvedMovingNode = state.tr.doc.resolve(start);
77
- var maybeNode = resolvedMovingNode.nodeAfter;
78
- 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);
79
- api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
80
- eventType: _analytics.EVENT_TYPE.UI,
81
- action: _analytics.ACTION.DRAGGED,
82
- actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
83
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
84
- attributes: {
85
- nodeDepth: resolvedMovingNode.depth,
86
- nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
87
- }
88
- })(state.tr);
89
- return state.tr;
90
- });
75
+ 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));
91
76
  }
92
77
  }
93
78
  });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.GlobalStylesWrapper = void 0;
7
7
  var _react = require("@emotion/react");
8
8
  /** @jsx jsx */
9
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
9
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
10
 
11
11
  var globalStyles = (0, _react.css)({
12
12
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
@@ -12,6 +12,8 @@ var _bindEventListener = require("bind-event-listener");
12
12
  var _dragHandlePositions = require("../utils/drag-handle-positions");
13
13
  /** @jsx jsx */
14
14
 
15
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
16
+
15
17
  var basicStyles = (0, _react2.css)({
16
18
  position: 'absolute',
17
19
  width: '100%',
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getTopPosition = exports.getLeftPosition = void 0;
7
7
  var _consts = require("../ui/consts");
8
8
  var getTopPosition = exports.getTopPosition = function getTopPosition(dom) {
9
+ if (!dom) {
10
+ return 'auto';
11
+ }
9
12
  var table = dom.querySelector('table');
10
13
  if (table) {
11
14
  return "".concat(dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
@@ -14,6 +17,9 @@ var getTopPosition = exports.getTopPosition = function getTopPosition(dom) {
14
17
  }
15
18
  };
16
19
  var getLeftPosition = exports.getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates) {
20
+ if (!dom) {
21
+ return 'auto';
22
+ }
17
23
  if (!innerContainer) {
18
24
  return "".concat(dom.offsetLeft - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
19
25
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { createPlugin, key } from './pm-plugins/main';
3
4
  import { DragHandleMenu } from './ui/drag-handle-menu';
4
5
  import { GlobalStylesWrapper } from './ui/global-styles';
@@ -17,8 +18,9 @@ export const blockControlsPlugin = ({
17
18
  moveNode: (start, to) => ({
18
19
  tr
19
20
  }) => {
20
- var _node$nodeSize;
21
+ var _node$nodeSize, _api$analytics;
21
22
  const node = tr.doc.nodeAt(start);
23
+ const resolvedNode = tr.doc.resolve(start);
22
24
  if (!node) {
23
25
  return tr;
24
26
  }
@@ -33,6 +35,16 @@ export const blockControlsPlugin = ({
33
35
  nodeMoved: true
34
36
  });
35
37
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
38
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
39
+ eventType: EVENT_TYPE.TRACK,
40
+ action: ACTION.MOVED,
41
+ actionSubject: ACTION_SUBJECT.ELEMENT,
42
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
43
+ attributes: {
44
+ nodeDepth: resolvedNode.depth,
45
+ nodeType: node.type.name
46
+ }
47
+ })(tr);
36
48
  return tr;
37
49
  },
38
50
  showDragHandleAt: (pos, anchorName, nodeType) => ({
@@ -1,4 +1,5 @@
1
1
  import rafSchedule from 'raf-schd';
2
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
2
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';
@@ -33,19 +34,11 @@ const destroyFn = api => {
33
34
  api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
34
35
  tr
35
36
  }) => {
36
- return tr.setMeta(key, {
37
- isDragging: false
38
- });
39
- });
40
- // if no drop targets are rendered, assume that drop is invalid
41
- if (location.current.dropTargets.length === 0) {
42
- var _api$core2;
43
37
  const {
44
38
  start
45
39
  } = source.data;
46
- api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
47
- tr
48
- }) => {
40
+ // if no drop targets are rendered, assume that drop is invalid
41
+ if (location.current.dropTargets.length === 0) {
49
42
  var _api$analytics;
50
43
  const resolvedMovingNode = tr.doc.resolve(start);
51
44
  const maybeNode = resolvedMovingNode.nodeAfter;
@@ -59,9 +52,11 @@ const destroyFn = api => {
59
52
  nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
60
53
  }
61
54
  })(tr);
62
- return tr;
55
+ }
56
+ return tr.setMeta(key, {
57
+ isDragging: false
63
58
  });
64
- }
59
+ });
65
60
  }
66
61
  }));
67
62
  return combine(...cleanupFn);
@@ -88,7 +83,7 @@ export const createPlugin = api => {
88
83
  return initialState;
89
84
  },
90
85
  apply(tr, currentState, oldState, newState) {
91
- var _decorationState, _meta$activeNode, _meta$isDragging, _meta$editorHeight;
86
+ var _meta$activeNode, _meta$isDragging, _meta$editorHeight;
92
87
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
93
88
  return initialState;
94
89
  }
@@ -98,9 +93,13 @@ export const createPlugin = api => {
98
93
  isMenuOpen,
99
94
  decorationState,
100
95
  editorHeight,
101
- isResizerResizing
96
+ isResizerResizing,
97
+ isDragging
102
98
  } = currentState;
103
99
  const meta = tr.getMeta(key);
100
+ // when creating analytics during drag/drop events, PM thinks the doc has changed
101
+ // so tr.docChange is true and causes some decorations to not render
102
+ const isAnalyticTr = tr.steps.every(step => step instanceof AnalyticsStep);
104
103
 
105
104
  // If tables or media are being resized, we want to hide the drag handle
106
105
  const resizerMeta = tr.getMeta('is-resizer-resizing');
@@ -129,7 +128,14 @@ export const createPlugin = api => {
129
128
  // Note: Quite often the handle is not in the right position after a node is moved
130
129
  // it is safer for now to not show it when a node is moved
131
130
  if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
132
- const draghandleDec = dragHandleDecoration(activeNode.pos, activeNode.anchorName, activeNode.nodeType, api);
131
+ const newActiveNode = activeNode && tr.doc.nodeAt(tr.mapping.map(activeNode.pos));
132
+ let nodeType = activeNode.nodeType;
133
+ let anchorName = activeNode.anchorName;
134
+ if (newActiveNode && (newActiveNode === null || newActiveNode === void 0 ? void 0 : newActiveNode.type.name) !== activeNode.nodeType && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
135
+ nodeType = newActiveNode.type.name;
136
+ anchorName = activeNode.anchorName.replace(activeNode.nodeType, nodeType);
137
+ }
138
+ const draghandleDec = dragHandleDecoration(activeNode.pos, anchorName, nodeType, api);
133
139
  decorations = decorations.add(newState.doc, [draghandleDec]);
134
140
  }
135
141
  }
@@ -145,7 +151,8 @@ export const createPlugin = api => {
145
151
  }
146
152
 
147
153
  // Add drop targets when node is being dragged
148
- if (meta !== null && meta !== void 0 && meta.isDragging && !tr.docChanged && api) {
154
+ // if the transaction is only for analytics and user is dragging, continue to draw drop targets
155
+ if (meta !== null && meta !== void 0 && meta.isDragging && (!tr.docChanged || tr.docChanged && isAnalyticTr) && api) {
149
156
  const {
150
157
  decs,
151
158
  decorationState: updatedDecorationState
@@ -163,7 +170,7 @@ export const createPlugin = api => {
163
170
  }
164
171
 
165
172
  // Map drop target decoration positions when the document changes
166
- if (tr.docChanged && currentState.isDragging) {
173
+ if (tr.docChanged && isDragging) {
167
174
  decorationState = decorationState.map(({
168
175
  index,
169
176
  pos
@@ -189,9 +196,9 @@ export const createPlugin = api => {
189
196
  const isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
190
197
  return {
191
198
  decorations,
192
- decorationState: (_decorationState = decorationState) !== null && _decorationState !== void 0 ? _decorationState : currentState.decorationState,
199
+ decorationState,
193
200
  activeNode: isEmptyDoc ? null : (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : mappedActiveNodePos,
194
- isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : currentState.isDragging,
201
+ isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
195
202
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
196
203
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
197
204
  isResizerResizing: isResizerResizing,
@@ -1,6 +1,9 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
6
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
8
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
6
9
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -118,11 +121,31 @@ export const DragHandle = ({
118
121
  });
119
122
  },
120
123
  onDragStart() {
121
- var _api$core5, _api$blockControls, _api$core6;
124
+ var _api$core5, _api$core6;
122
125
  if (start === undefined) {
123
126
  return;
124
127
  }
125
- api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
128
+ api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
129
+ tr
130
+ }) => {
131
+ var _api$blockControls, _api$analytics;
132
+ 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)({
133
+ tr
134
+ });
135
+ const resolvedMovingNode = tr.doc.resolve(start);
136
+ const maybeNode = resolvedMovingNode.nodeAfter;
137
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
138
+ eventType: EVENT_TYPE.UI,
139
+ action: ACTION.DRAGGED,
140
+ actionSubject: ACTION_SUBJECT.ELEMENT,
141
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
142
+ attributes: {
143
+ nodeDepth: resolvedMovingNode.depth,
144
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
145
+ }
146
+ })(tr);
147
+ return tr;
148
+ });
126
149
  api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.focus();
127
150
  }
128
151
  });
@@ -131,12 +154,9 @@ export const DragHandle = ({
131
154
  const positionStyles = useMemo(() => {
132
155
  const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
133
156
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
134
- if (!dom) {
135
- return;
136
- }
137
157
  const hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
138
158
  const isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
139
- const innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
159
+ const innerContainer = dom ? hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null : null;
140
160
  if (supportsAnchor) {
141
161
  return {
142
162
  left: hasResizer || isExtension ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : `calc(anchor(${anchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType)}px)`,
@@ -1,7 +1,8 @@
1
1
  /** @jsx jsx */
2
2
  import { useEffect, useRef, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
- 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 { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
7
8
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -55,27 +56,11 @@ export const DropTarget = ({
55
56
  pos
56
57
  } = decorationState.find(dec => dec.index === index) || {};
57
58
  if (activeNode && pos !== undefined) {
58
- var _api$core;
59
+ var _api$core, _api$blockControls2, _api$blockControls2$c;
59
60
  const {
60
61
  pos: start
61
62
  } = activeNode;
62
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(state => {
63
- var _api$blockControls2, _api$blockControls2$c, _api$analytics;
64
- const resolvedMovingNode = state.tr.doc.resolve(start);
65
- const maybeNode = resolvedMovingNode.nodeAfter;
66
- 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);
67
- api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
68
- eventType: EVENT_TYPE.UI,
69
- action: ACTION.DRAGGED,
70
- actionSubject: ACTION_SUBJECT.ELEMENT,
71
- actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
72
- attributes: {
73
- nodeDepth: resolvedMovingNode.depth,
74
- nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
75
- }
76
- })(state.tr);
77
- return state.tr;
78
- });
63
+ 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));
79
64
  }
80
65
  }
81
66
  });
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
2
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
3
  import { css, Global, jsx } from '@emotion/react';
4
4
  const globalStyles = css({
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
6
  import { bind } from 'bind-event-listener';
5
7
  import { getTopPosition } from '../utils/drag-handle-positions';
@@ -1,5 +1,8 @@
1
1
  import { DRAG_HANDLE_WIDTH, dragHandleGap } from '../ui/consts';
2
2
  export const getTopPosition = dom => {
3
+ if (!dom) {
4
+ return 'auto';
5
+ }
3
6
  const table = dom.querySelector('table');
4
7
  if (table) {
5
8
  return `${dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0)}px`;
@@ -8,6 +11,9 @@ export const getTopPosition = dom => {
8
11
  }
9
12
  };
10
13
  export const getLeftPosition = (dom, type, innerContainer, macroInteractionUpdates) => {
14
+ if (!dom) {
15
+ return 'auto';
16
+ }
11
17
  if (!innerContainer) {
12
18
  return `${dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px`;
13
19
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { createPlugin, key } from './pm-plugins/main';
3
4
  import { DragHandleMenu } from './ui/drag-handle-menu';
4
5
  import { GlobalStylesWrapper } from './ui/global-styles';
@@ -18,9 +19,10 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
18
19
  commands: {
19
20
  moveNode: function moveNode(start, to) {
20
21
  return function (_ref2) {
21
- var _node$nodeSize;
22
+ var _node$nodeSize, _api$analytics;
22
23
  var tr = _ref2.tr;
23
24
  var node = tr.doc.nodeAt(start);
25
+ var resolvedNode = tr.doc.resolve(start);
24
26
  if (!node) {
25
27
  return tr;
26
28
  }
@@ -35,6 +37,16 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
35
37
  nodeMoved: true
36
38
  });
37
39
  api === null || api === void 0 || api.core.actions.focus();
40
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
41
+ eventType: EVENT_TYPE.TRACK,
42
+ action: ACTION.MOVED,
43
+ actionSubject: ACTION_SUBJECT.ELEMENT,
44
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
45
+ attributes: {
46
+ nodeDepth: resolvedNode.depth,
47
+ nodeType: node.type.name
48
+ }
49
+ })(tr);
38
50
  return tr;
39
51
  };
40
52
  },
@@ -1,5 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import rafSchedule from 'raf-schd';
3
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
3
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
@@ -33,18 +34,11 @@ var destroyFn = function destroyFn(api) {
33
34
  scrollable.style.setProperty('scroll-behavior', null);
34
35
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
35
36
  var tr = _ref3.tr;
36
- return tr.setMeta(key, {
37
- isDragging: false
38
- });
39
- });
40
- // if no drop targets are rendered, assume that drop is invalid
41
- if (location.current.dropTargets.length === 0) {
42
- var _api$core2;
43
37
  var _ref4 = source.data,
44
38
  start = _ref4.start;
45
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
39
+ // if no drop targets are rendered, assume that drop is invalid
40
+ if (location.current.dropTargets.length === 0) {
46
41
  var _api$analytics;
47
- var tr = _ref5.tr;
48
42
  var resolvedMovingNode = tr.doc.resolve(start);
49
43
  var maybeNode = resolvedMovingNode.nodeAfter;
50
44
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
@@ -57,9 +51,11 @@ var destroyFn = function destroyFn(api) {
57
51
  nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
58
52
  }
59
53
  })(tr);
60
- return tr;
54
+ }
55
+ return tr.setMeta(key, {
56
+ isDragging: false
61
57
  });
62
- }
58
+ });
63
59
  }
64
60
  }));
65
61
  return combine.apply(void 0, cleanupFn);
@@ -86,7 +82,7 @@ export var createPlugin = function createPlugin(api) {
86
82
  return initialState;
87
83
  },
88
84
  apply: function apply(tr, currentState, oldState, newState) {
89
- var _decorationState, _meta$activeNode, _meta$isDragging, _meta$editorHeight;
85
+ var _meta$activeNode, _meta$isDragging, _meta$editorHeight;
90
86
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
91
87
  return initialState;
92
88
  }
@@ -95,8 +91,14 @@ export var createPlugin = function createPlugin(api) {
95
91
  isMenuOpen = currentState.isMenuOpen,
96
92
  decorationState = currentState.decorationState,
97
93
  editorHeight = currentState.editorHeight,
98
- isResizerResizing = currentState.isResizerResizing;
94
+ isResizerResizing = currentState.isResizerResizing,
95
+ isDragging = currentState.isDragging;
99
96
  var meta = tr.getMeta(key);
97
+ // when creating analytics during drag/drop events, PM thinks the doc has changed
98
+ // so tr.docChange is true and causes some decorations to not render
99
+ var isAnalyticTr = tr.steps.every(function (step) {
100
+ return step instanceof AnalyticsStep;
101
+ });
100
102
 
101
103
  // If tables or media are being resized, we want to hide the drag handle
102
104
  var resizerMeta = tr.getMeta('is-resizer-resizing');
@@ -105,8 +107,8 @@ export var createPlugin = function createPlugin(api) {
105
107
 
106
108
  // During resize, remove the drag handle widget
107
109
  if (isResizerResizing || nodeCountChanged || meta !== null && meta !== void 0 && meta.nodeMoved) {
108
- var oldHandle = decorations.find().filter(function (_ref6) {
109
- var spec = _ref6.spec;
110
+ var oldHandle = decorations.find().filter(function (_ref5) {
111
+ var spec = _ref5.spec;
110
112
  return spec.id === 'drag-handle';
111
113
  });
112
114
  decorations = decorations.remove(oldHandle);
@@ -126,15 +128,22 @@ export var createPlugin = function createPlugin(api) {
126
128
  // Note: Quite often the handle is not in the right position after a node is moved
127
129
  // it is safer for now to not show it when a node is moved
128
130
  if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
129
- var draghandleDec = dragHandleDecoration(activeNode.pos, activeNode.anchorName, activeNode.nodeType, api);
131
+ var newActiveNode = activeNode && tr.doc.nodeAt(tr.mapping.map(activeNode.pos));
132
+ var nodeType = activeNode.nodeType;
133
+ var anchorName = activeNode.anchorName;
134
+ if (newActiveNode && (newActiveNode === null || newActiveNode === void 0 ? void 0 : newActiveNode.type.name) !== activeNode.nodeType && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
135
+ nodeType = newActiveNode.type.name;
136
+ anchorName = activeNode.anchorName.replace(activeNode.nodeType, nodeType);
137
+ }
138
+ var draghandleDec = dragHandleDecoration(activeNode.pos, anchorName, nodeType, api);
130
139
  decorations = decorations.add(newState.doc, [draghandleDec]);
131
140
  }
132
141
  }
133
142
 
134
143
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
135
144
  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) {
136
- var _oldHandle = decorations.find().filter(function (_ref7) {
137
- var spec = _ref7.spec;
145
+ var _oldHandle = decorations.find().filter(function (_ref6) {
146
+ var spec = _ref6.spec;
138
147
  return spec.id === 'drag-handle';
139
148
  });
140
149
  decorations = decorations.remove(_oldHandle);
@@ -143,7 +152,8 @@ export var createPlugin = function createPlugin(api) {
143
152
  }
144
153
 
145
154
  // Add drop targets when node is being dragged
146
- if (meta !== null && meta !== void 0 && meta.isDragging && !tr.docChanged && api) {
155
+ // if the transaction is only for analytics and user is dragging, continue to draw drop targets
156
+ if (meta !== null && meta !== void 0 && meta.isDragging && (!tr.docChanged || tr.docChanged && isAnalyticTr) && api) {
147
157
  var _dropTargetDecoration = dropTargetDecorations(oldState, newState, api),
148
158
  _decs = _dropTargetDecoration.decs,
149
159
  updatedDecorationState = _dropTargetDecoration.decorationState;
@@ -153,18 +163,18 @@ export var createPlugin = function createPlugin(api) {
153
163
 
154
164
  // Remove drop target decoration when dragging stops
155
165
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
156
- var dropTargetDecs = decorations.find().filter(function (_ref8) {
157
- var spec = _ref8.spec;
166
+ var dropTargetDecs = decorations.find().filter(function (_ref7) {
167
+ var spec = _ref7.spec;
158
168
  return spec.type === 'drop-target-decoration';
159
169
  });
160
170
  decorations = decorations.remove(dropTargetDecs);
161
171
  }
162
172
 
163
173
  // Map drop target decoration positions when the document changes
164
- if (tr.docChanged && currentState.isDragging) {
165
- decorationState = decorationState.map(function (_ref9) {
166
- var index = _ref9.index,
167
- pos = _ref9.pos;
174
+ if (tr.docChanged && isDragging) {
175
+ decorationState = decorationState.map(function (_ref8) {
176
+ var index = _ref8.index,
177
+ pos = _ref8.pos;
168
178
  return {
169
179
  index: index,
170
180
  pos: tr.mapping.map(pos)
@@ -186,9 +196,9 @@ export var createPlugin = function createPlugin(api) {
186
196
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
187
197
  return {
188
198
  decorations: decorations,
189
- decorationState: (_decorationState = decorationState) !== null && _decorationState !== void 0 ? _decorationState : currentState.decorationState,
199
+ decorationState: decorationState,
190
200
  activeNode: isEmptyDoc ? null : (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : mappedActiveNodePos,
191
- isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : currentState.isDragging,
201
+ isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
192
202
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
193
203
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
194
204
  isResizerResizing: isResizerResizing,
@@ -1,7 +1,10 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
6
  import { css, jsx } from '@emotion/react';
7
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
8
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
9
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
7
10
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -118,11 +121,30 @@ export var DragHandle = function DragHandle(_ref) {
118
121
  });
119
122
  },
120
123
  onDragStart: function onDragStart() {
121
- var _api$core5, _api$blockControls, _api$core6;
124
+ var _api$core5, _api$core6;
122
125
  if (start === undefined) {
123
126
  return;
124
127
  }
125
- api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
128
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
129
+ var _api$blockControls, _api$analytics;
130
+ var tr = _ref6.tr;
131
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
132
+ tr: tr
133
+ });
134
+ var resolvedMovingNode = tr.doc.resolve(start);
135
+ var maybeNode = resolvedMovingNode.nodeAfter;
136
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
137
+ eventType: EVENT_TYPE.UI,
138
+ action: ACTION.DRAGGED,
139
+ actionSubject: ACTION_SUBJECT.ELEMENT,
140
+ actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
141
+ attributes: {
142
+ nodeDepth: resolvedMovingNode.depth,
143
+ nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
144
+ }
145
+ })(tr);
146
+ return tr;
147
+ });
126
148
  api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
127
149
  }
128
150
  });
@@ -131,12 +153,9 @@ export var DragHandle = function DragHandle(_ref) {
131
153
  var positionStyles = useMemo(function () {
132
154
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
133
155
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
134
- if (!dom) {
135
- return;
136
- }
137
156
  var hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
138
157
  var isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
139
- var innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
158
+ var innerContainer = dom ? hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null : null;
140
159
  if (supportsAnchor) {
141
160
  return {
142
161
  left: hasResizer || isExtension ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
@@ -1,8 +1,9 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useEffect, useRef, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
6
  import { css, jsx } from '@emotion/react';
5
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
6
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
8
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
8
9
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -61,25 +62,9 @@ export var DropTarget = function DropTarget(_ref) {
61
62
  }) || {},
62
63
  pos = _ref3.pos;
63
64
  if (activeNode && pos !== undefined) {
64
- var _api$core;
65
+ var _api$core, _api$blockControls2;
65
66
  var start = activeNode.pos;
66
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (state) {
67
- var _api$blockControls2, _api$analytics;
68
- var resolvedMovingNode = state.tr.doc.resolve(start);
69
- var maybeNode = resolvedMovingNode.nodeAfter;
70
- 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);
71
- api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
72
- eventType: EVENT_TYPE.UI,
73
- action: ACTION.DRAGGED,
74
- actionSubject: ACTION_SUBJECT.ELEMENT,
75
- actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
76
- attributes: {
77
- nodeDepth: resolvedMovingNode.depth,
78
- nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
79
- }
80
- })(state.tr);
81
- return state.tr;
82
- });
67
+ 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));
83
68
  }
84
69
  }
85
70
  });
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
2
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
3
  import { css, Global, jsx } from '@emotion/react';
4
4
  var globalStyles = css({
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
@@ -1,6 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
6
  import { css, jsx } from '@emotion/react';
5
7
  import { bind } from 'bind-event-listener';
6
8
  import { getTopPosition } from '../utils/drag-handle-positions';
@@ -1,5 +1,8 @@
1
1
  import { DRAG_HANDLE_WIDTH, dragHandleGap } from '../ui/consts';
2
2
  export var getTopPosition = function getTopPosition(dom) {
3
+ if (!dom) {
4
+ return 'auto';
5
+ }
3
6
  var table = dom.querySelector('table');
4
7
  if (table) {
5
8
  return "".concat(dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
@@ -8,6 +11,9 @@ export var getTopPosition = function getTopPosition(dom) {
8
11
  }
9
12
  };
10
13
  export var getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates) {
14
+ if (!dom) {
15
+ return 'auto';
16
+ }
11
17
  if (!innerContainer) {
12
18
  return "".concat(dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px");
13
19
  }
@@ -1,2 +1,2 @@
1
- export declare const getTopPosition: (dom: HTMLElement) => string;
2
- export declare const getLeftPosition: (dom: HTMLElement, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
1
+ export declare const getTopPosition: (dom: HTMLElement | null) => string;
2
+ export declare const getLeftPosition: (dom: HTMLElement | null, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
@@ -1,2 +1,2 @@
1
- export declare const getTopPosition: (dom: HTMLElement) => string;
2
- export declare const getLeftPosition: (dom: HTMLElement, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
1
+ export declare const getTopPosition: (dom: HTMLElement | null) => string;
2
+ export declare const getLeftPosition: (dom: HTMLElement | null, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,6 +31,7 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
+ "@atlaskit/adf-schema": "^36.10.7",
34
35
  "@atlaskit/editor-common": "^82.8.0",
35
36
  "@atlaskit/editor-plugin-analytics": "^1.2.3",
36
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
@@ -38,12 +39,12 @@
38
39
  "@atlaskit/editor-plugin-width": "^1.1.0",
39
40
  "@atlaskit/editor-prosemirror": "4.0.1",
40
41
  "@atlaskit/editor-tables": "^2.7.0",
41
- "@atlaskit/icon": "^22.3.0",
42
+ "@atlaskit/icon": "^22.4.0",
42
43
  "@atlaskit/platform-feature-flags": "^0.2.0",
43
44
  "@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
44
45
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.3.0",
45
46
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
46
- "@atlaskit/tokens": "^1.50.0",
47
+ "@atlaskit/tokens": "^1.51.0",
47
48
  "@babel/runtime": "^7.0.0",
48
49
  "@emotion/react": "^11.7.1",
49
50
  "bind-event-listener": "^3.0.0",