@atlaskit/editor-plugin-block-controls 1.4.21 → 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.
@@ -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,22 +121,32 @@ 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));
126
- api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.focus();
127
- },
128
- onDrop() {
129
- var _api$core7;
130
- api === null || api === void 0 ? void 0 : (_api$core7 = api.core) === null || _api$core7 === void 0 ? void 0 : _api$core7.actions.execute(({
128
+ api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
131
129
  tr
132
130
  }) => {
133
- return tr.setMeta(key, {
134
- isDragging: false
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
135
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;
136
148
  });
149
+ api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.focus();
137
150
  }
138
151
  });
139
152
  }, [api, start, view, anchorName, nodeType]);
@@ -141,12 +154,9 @@ export const DragHandle = ({
141
154
  const positionStyles = useMemo(() => {
142
155
  const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
143
156
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
144
- if (!dom) {
145
- return;
146
- }
147
157
  const hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
148
158
  const isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
149
- 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;
150
160
  if (supportsAnchor) {
151
161
  return {
152
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
  },
@@ -7,6 +7,7 @@ import { DropTarget } from '../ui/drop-target';
7
7
  import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
8
8
  export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
9
9
  var decs = [];
10
+ unmountDecorations('data-blocks-drop-target-container');
10
11
  // Decoration state is used to keep track of the position of the drop targets
11
12
  // and allows us to easily map the updated position in the plugin apply method.
12
13
  var decorationState = [];
@@ -17,6 +18,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
17
18
  });
18
19
  decs.push(Decoration.widget(pos, function () {
19
20
  var element = document.createElement('div');
21
+ element.setAttribute('data-blocks-drop-target-container', 'true');
20
22
  ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
21
23
  api: api,
22
24
  index: index
@@ -41,6 +43,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
41
43
  });
42
44
  decs.push(Decoration.widget(newState.doc.nodeSize - 2, function () {
43
45
  var element = document.createElement('div');
46
+ element.setAttribute('data-blocks-drop-target-container', 'true');
44
47
  ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
45
48
  api: api,
46
49
  index: decorationState.length
@@ -73,10 +76,12 @@ export var nodeDecorations = function nodeDecorations(newState) {
73
76
  */
74
77
  export var mouseMoveWrapperDecorations = function mouseMoveWrapperDecorations(newState, api) {
75
78
  var decs = [];
79
+ unmountDecorations('data-blocks-decoration-container');
76
80
  newState.doc.descendants(function (node, pos, _parent, index) {
77
81
  var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
78
82
  decs.push(Decoration.widget(pos, function (view, getPos) {
79
83
  var element = document.createElement('div');
84
+ element.setAttribute('data-blocks-decoration-container', 'true');
80
85
  ReactDOM.render( /*#__PURE__*/createElement(MouseMoveWrapper, {
81
86
  view: view,
82
87
  api: api,
@@ -101,6 +106,7 @@ export var dragHandleDecoration = function dragHandleDecoration(pos, anchorName,
101
106
  return Decoration.widget(pos, function (view, getPos) {
102
107
  var element = document.createElement('div');
103
108
  element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
109
+ element.setAttribute('data-blocks-drag-handle-container', 'true');
104
110
  ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
105
111
  view: view,
106
112
  api: api,
@@ -111,6 +117,17 @@ export var dragHandleDecoration = function dragHandleDecoration(pos, anchorName,
111
117
  return element;
112
118
  }, {
113
119
  side: -1,
114
- id: 'drag-handle'
120
+ id: 'drag-handle',
121
+ destroy: function destroy(node) {
122
+ ReactDOM.unmountComponentAtNode(node);
123
+ }
124
+ });
125
+ };
126
+ var unmountDecorations = function unmountDecorations(selector) {
127
+ // Removing decorations manually instead of using native destroy function in prosemirror API
128
+ // as it was more responsive and causes less re-rendering
129
+ var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
130
+ decorationsToRemove.forEach(function (el) {
131
+ ReactDOM.unmountComponentAtNode(el);
115
132
  });
116
133
  };
@@ -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';
@@ -27,18 +28,17 @@ var destroyFn = function destroyFn(api) {
27
28
  scrollable.style.setProperty('scroll-behavior', 'unset');
28
29
  },
29
30
  onDrop: function onDrop(_ref2) {
31
+ var _api$core;
30
32
  var location = _ref2.location,
31
33
  source = _ref2.source;
32
34
  scrollable.style.setProperty('scroll-behavior', null);
33
-
34
- // if no drop targets are rendered, assume that drop is invalid
35
- if (location.current.dropTargets.length === 0) {
36
- var _api$core;
37
- var _ref3 = source.data,
38
- start = _ref3.start;
39
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
35
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
36
+ var tr = _ref3.tr;
37
+ var _ref4 = source.data,
38
+ start = _ref4.start;
39
+ // if no drop targets are rendered, assume that drop is invalid
40
+ if (location.current.dropTargets.length === 0) {
40
41
  var _api$analytics;
41
- var tr = _ref4.tr;
42
42
  var resolvedMovingNode = tr.doc.resolve(start);
43
43
  var maybeNode = resolvedMovingNode.nodeAfter;
44
44
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
@@ -51,9 +51,11 @@ var destroyFn = function destroyFn(api) {
51
51
  nodeType: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
52
52
  }
53
53
  })(tr);
54
- return tr;
54
+ }
55
+ return tr.setMeta(key, {
56
+ isDragging: false
55
57
  });
56
- }
58
+ });
57
59
  }
58
60
  }));
59
61
  return combine.apply(void 0, cleanupFn);
@@ -80,7 +82,7 @@ export var createPlugin = function createPlugin(api) {
80
82
  return initialState;
81
83
  },
82
84
  apply: function apply(tr, currentState, oldState, newState) {
83
- var _decorationState, _meta$activeNode, _meta$isDragging, _meta$editorHeight;
85
+ var _meta$activeNode, _meta$isDragging, _meta$editorHeight;
84
86
  if (initialState.isDocSizeLimitEnabled && newState.doc.nodeSize > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
85
87
  return initialState;
86
88
  }
@@ -89,8 +91,14 @@ export var createPlugin = function createPlugin(api) {
89
91
  isMenuOpen = currentState.isMenuOpen,
90
92
  decorationState = currentState.decorationState,
91
93
  editorHeight = currentState.editorHeight,
92
- isResizerResizing = currentState.isResizerResizing;
94
+ isResizerResizing = currentState.isResizerResizing,
95
+ isDragging = currentState.isDragging;
93
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
+ });
94
102
 
95
103
  // If tables or media are being resized, we want to hide the drag handle
96
104
  var resizerMeta = tr.getMeta('is-resizer-resizing');
@@ -120,7 +128,14 @@ export var createPlugin = function createPlugin(api) {
120
128
  // Note: Quite often the handle is not in the right position after a node is moved
121
129
  // it is safer for now to not show it when a node is moved
122
130
  if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved)) {
123
- 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);
124
139
  decorations = decorations.add(newState.doc, [draghandleDec]);
125
140
  }
126
141
  }
@@ -137,7 +152,8 @@ export var createPlugin = function createPlugin(api) {
137
152
  }
138
153
 
139
154
  // Add drop targets when node is being dragged
140
- 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) {
141
157
  var _dropTargetDecoration = dropTargetDecorations(oldState, newState, api),
142
158
  _decs = _dropTargetDecoration.decs,
143
159
  updatedDecorationState = _dropTargetDecoration.decorationState;
@@ -155,7 +171,7 @@ export var createPlugin = function createPlugin(api) {
155
171
  }
156
172
 
157
173
  // Map drop target decoration positions when the document changes
158
- if (tr.docChanged && currentState.isDragging) {
174
+ if (tr.docChanged && isDragging) {
159
175
  decorationState = decorationState.map(function (_ref8) {
160
176
  var index = _ref8.index,
161
177
  pos = _ref8.pos;
@@ -180,9 +196,9 @@ export var createPlugin = function createPlugin(api) {
180
196
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
181
197
  return {
182
198
  decorations: decorations,
183
- decorationState: (_decorationState = decorationState) !== null && _decorationState !== void 0 ? _decorationState : currentState.decorationState,
199
+ decorationState: decorationState,
184
200
  activeNode: isEmptyDoc ? null : (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : mappedActiveNodePos,
185
- 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,
186
202
  isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
187
203
  editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
188
204
  isResizerResizing: isResizerResizing,
@@ -224,7 +240,7 @@ export var createPlugin = function createPlugin(api) {
224
240
  return {
225
241
  destroy: function destroy() {
226
242
  resizeObserver.unobserve(dom);
227
- return pragmaticCleanup;
243
+ pragmaticCleanup();
228
244
  }
229
245
  };
230
246
  }
@@ -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,21 +121,31 @@ 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));
126
- api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
127
- },
128
- onDrop: function onDrop() {
129
- var _api$core7;
130
- api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref6) {
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;
131
130
  var tr = _ref6.tr;
132
- return tr.setMeta(key, {
133
- isDragging: false
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
134
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;
135
147
  });
148
+ api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.focus();
136
149
  }
137
150
  });
138
151
  }, [api, start, view, anchorName, nodeType]);
@@ -140,12 +153,9 @@ export var DragHandle = function DragHandle(_ref) {
140
153
  var positionStyles = useMemo(function () {
141
154
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
142
155
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
143
- if (!dom) {
144
- return;
145
- }
146
156
  var hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
147
157
  var isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
148
- 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;
149
159
  if (supportsAnchor) {
150
160
  return {
151
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
1
  export { blockControlsPlugin } from './plugin';
2
- export type { BlockControlsPlugin, DecorationState } from './types';
2
+ export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
@@ -19,6 +19,15 @@ export interface PluginState {
19
19
  isDocSizeLimitEnabled: boolean;
20
20
  }
21
21
  export type ReleaseHiddenDecoration = () => boolean | undefined;
22
+ export type BlockControlsSharedState = {
23
+ isMenuOpen: boolean;
24
+ activeNode: {
25
+ pos: number;
26
+ anchorName: string;
27
+ } | null;
28
+ decorationState: DecorationState;
29
+ isDragging: boolean;
30
+ } | undefined;
22
31
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
23
32
  dependencies: [
24
33
  OptionalPlugin<EditorDisabledPlugin>,
@@ -26,15 +35,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
26
35
  OptionalPlugin<FeatureFlagsPlugin>,
27
36
  OptionalPlugin<AnalyticsPlugin>
28
37
  ];
29
- sharedState: {
30
- isMenuOpen: boolean;
31
- activeNode: {
32
- pos: number;
33
- anchorName: string;
34
- } | null;
35
- decorationState: DecorationState;
36
- isDragging: boolean;
37
- } | undefined;
38
+ sharedState: BlockControlsSharedState;
38
39
  commands: {
39
40
  moveNode: (start: number, to: number) => EditorCommand;
40
41
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
@@ -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
1
  export { blockControlsPlugin } from './plugin';
2
- export type { BlockControlsPlugin, DecorationState } from './types';
2
+ export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
@@ -19,6 +19,15 @@ export interface PluginState {
19
19
  isDocSizeLimitEnabled: boolean;
20
20
  }
21
21
  export type ReleaseHiddenDecoration = () => boolean | undefined;
22
+ export type BlockControlsSharedState = {
23
+ isMenuOpen: boolean;
24
+ activeNode: {
25
+ pos: number;
26
+ anchorName: string;
27
+ } | null;
28
+ decorationState: DecorationState;
29
+ isDragging: boolean;
30
+ } | undefined;
22
31
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
23
32
  dependencies: [
24
33
  OptionalPlugin<EditorDisabledPlugin>,
@@ -26,15 +35,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
26
35
  OptionalPlugin<FeatureFlagsPlugin>,
27
36
  OptionalPlugin<AnalyticsPlugin>
28
37
  ];
29
- sharedState: {
30
- isMenuOpen: boolean;
31
- activeNode: {
32
- pos: number;
33
- anchorName: string;
34
- } | null;
35
- decorationState: DecorationState;
36
- isDragging: boolean;
37
- } | undefined;
38
+ sharedState: BlockControlsSharedState;
38
39
  commands: {
39
40
  moveNode: (start: number, to: number) => EditorCommand;
40
41
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
@@ -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.21",
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,19 +31,20 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^82.7.0",
34
+ "@atlaskit/adf-schema": "^36.10.7",
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",
37
38
  "@atlaskit/editor-plugin-feature-flags": "^1.1.0",
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",