@atlaskit/editor-plugin-block-controls 1.11.1 → 1.11.2

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,18 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#129108](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129108)
8
+ [`c3bcb8b4001bd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3bcb8b4001bd) -
9
+ ED-24540 Clean up droptarget decorations after dropping in nested nodes to fix node splitting
10
+ issue
11
+ - [#129411](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129411)
12
+ [`2cfee5779f921`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2cfee5779f921) -
13
+ ED-24456 improve drop target vertical position for nested nodes
14
+ - Updated dependencies
15
+
3
16
  ## 1.11.1
4
17
 
5
18
  ### Patch Changes
@@ -138,8 +138,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
138
138
  if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
139
139
  isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
140
140
  }
141
- var dropTargetLen = decorations.find().filter(function (_ref8) {
142
- var spec = _ref8.spec;
141
+ var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
143
142
  return spec.type === 'drop-target-decoration';
144
143
  }).length;
145
144
 
@@ -164,8 +163,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
164
163
 
165
164
  // Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
166
165
  if (redrawDecorations && !isResizerResizing && api) {
167
- var oldNodeDecs = decorations.find().filter(function (_ref9) {
168
- var spec = _ref9.spec;
166
+ var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
169
167
  return spec.type !== 'drop-target-decoration';
170
168
  });
171
169
  decorations = decorations.remove(oldNodeDecs);
@@ -202,8 +200,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
202
200
 
203
201
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
204
202
  if (api && 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) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
205
- var _oldHandle = decorations.find().filter(function (_ref10) {
206
- var spec = _ref10.spec;
203
+ var _oldHandle = decorations.find(undefined, undefined, function (spec) {
207
204
  return spec.id === 'drag-handle';
208
205
  });
209
206
  decorations = decorations.remove(_oldHandle);
@@ -213,8 +210,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
213
210
 
214
211
  // Remove previous drag handle widget and draw new drag handle widget when node type changes
215
212
  if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
216
- var _oldHandle2 = decorations.find().filter(function (_ref11) {
217
- var spec = _ref11.spec;
213
+ var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
218
214
  return spec.id === 'drag-handle';
219
215
  });
220
216
  decorations = decorations.remove(_oldHandle2);
@@ -222,14 +218,20 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
222
218
  decorations = decorations.add(newState.doc, [_decs]);
223
219
  }
224
220
  var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
225
- var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
221
+ var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
226
222
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
227
- // Remove drop target decoration when dragging stops
228
- var dropTargetDecs = decorations.find().filter(function (_ref12) {
229
- var spec = _ref12.spec;
230
- return spec.type === 'drop-target-decoration';
231
- });
232
- decorations = decorations.remove(dropTargetDecs);
223
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
224
+ var remainingDecs = decorations.find(undefined, undefined, function (spec) {
225
+ return spec.type !== 'drop-target-decoration';
226
+ });
227
+ decorations = _view.DecorationSet.create(newState.doc, remainingDecs);
228
+ } else {
229
+ // Remove drop target decoration when dragging stops
230
+ var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
231
+ return spec.type === 'drop-target-decoration';
232
+ });
233
+ decorations = decorations.remove(dropTargetDecs);
234
+ }
233
235
  }
234
236
  if (api) {
235
237
  // Add drop targets when node is being dragged
@@ -246,9 +248,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
246
248
 
247
249
  //Map drop target decoration positions when the document changes
248
250
  if (shouldMapDropTargets) {
249
- decorationState = decorationState.map(function (_ref13) {
250
- var id = _ref13.id,
251
- pos = _ref13.pos;
251
+ decorationState = decorationState.map(function (_ref8) {
252
+ var id = _ref8.id,
253
+ pos = _ref8.pos;
252
254
  return {
253
255
  id: id,
254
256
  pos: tr.mapping.map(pos)
@@ -261,8 +263,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
261
263
  decorations = decorations.map(tr.mapping, tr.doc);
262
264
  }
263
265
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
264
- var hasNodeDecoration = decorations.find().some(function (_ref14) {
265
- var spec = _ref14.spec;
266
+ var hasNodeDecoration = decorations.find().some(function (_ref9) {
267
+ var spec = _ref9.spec;
266
268
  return spec.type === 'node-decoration';
267
269
  });
268
270
  if (!hasNodeDecoration && isEmptyDoc) {
@@ -23,6 +23,7 @@ var _consts = require("./consts");
23
23
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
24
24
 
25
25
  var DEFAULT_DROP_INDICATOR_WIDTH = 760;
26
+ var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
26
27
  var styleDropTarget = (0, _react2.css)({
27
28
  height: "var(--ds-space-100, 8px)",
28
29
  marginTop: "var(--ds-space-negative-100, -8px)",
@@ -32,6 +33,12 @@ var styleDropTarget = (0, _react2.css)({
32
33
  display: 'block',
33
34
  zIndex: _constants.layers.card()
34
35
  });
36
+ var styleDropIndicator = (0, _react2.css)({
37
+ height: '100%',
38
+ margin: '0 auto',
39
+ position: 'relative',
40
+ width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
41
+ });
35
42
  var nestedDropIndicatorStyle = (0, _react2.css)({
36
43
  position: 'relative'
37
44
  });
@@ -42,10 +49,9 @@ var marginLookupMap = Object.fromEntries(Object.entries(_consts.spaceLookupMap).
42
49
  return [key,
43
50
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
44
51
  (0, _react2.css)({
45
- marginTop: value
52
+ transform: "translateY(".concat(value, ")")
46
53
  })];
47
54
  }));
48
- var BASE_LINE_MARGIN = -8;
49
55
  var getNodeMargins = function getNodeMargins(node) {
50
56
  if (!node) {
51
57
  return _consts.nodeMargins['default'];
@@ -56,26 +62,19 @@ var getNodeMargins = function getNodeMargins(node) {
56
62
  }
57
63
  return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
58
64
  };
59
- var getDropTargetPositionStyle = function getDropTargetPositionStyle(prevNode, nextNode) {
65
+ var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
60
66
  if (!prevNode || !nextNode) {
61
67
  return null;
62
68
  }
63
- var space = BASE_LINE_MARGIN - Math.round((getNodeMargins(prevNode).bottom - getNodeMargins(nextNode).top) / 2);
64
- if (space < -24) {
65
- return marginLookupMap[-24];
66
- } else if (space > 24) {
67
- return marginLookupMap[24];
68
- } else {
69
- return marginLookupMap[space];
69
+ var top = getNodeMargins(nextNode).top;
70
+ var bottom = getNodeMargins(prevNode).bottom;
71
+ var merginDiff = Math.round((top - bottom) / 2);
72
+ if (merginDiff === 0) {
73
+ return null;
70
74
  }
75
+ var offset = Math.max(Math.min(merginDiff, 24), -24);
76
+ return marginLookupMap[offset];
71
77
  };
72
- var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
73
- var styleDropIndicator = (0, _react2.css)({
74
- height: '100%',
75
- margin: '0 auto',
76
- position: 'relative',
77
- width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
78
- });
79
78
  var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
80
79
  var api = _ref3.api,
81
80
  id = _ref3.id,
@@ -127,22 +126,22 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
127
126
  }
128
127
  });
129
128
  }, [id, api, formatMessage]);
130
- var topTargetMarginStyle = (0, _react.useMemo)(function () {
129
+ var dropTargetOffsetStyle = (0, _react.useMemo)(function () {
131
130
  /**
132
131
  * First child of a nested node.
133
- * Disable the position adjustment for the nested node temporarily
132
+ * Disable the position adjustment temporarily
134
133
  */
135
- if (parentNode === prevNode || isNestedDropTarget) {
134
+ if (parentNode === prevNode) {
136
135
  return null;
137
136
  }
138
- return getDropTargetPositionStyle(prevNode, nextNode);
139
- }, [prevNode, nextNode, parentNode, isNestedDropTarget]);
137
+ return getDropTargetOffsetStyle(prevNode, nextNode);
138
+ }, [prevNode, nextNode, parentNode]);
140
139
  var widthStyle = (0, _defineProperty2.default)({}, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px"));
141
140
  return (
142
141
  // Note: Firefox has trouble with using a button element as the handle for drag and drop
143
142
  (0, _react2.jsx)("div", {
144
143
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
145
- css: [styleDropTarget, topTargetMarginStyle, isNestedDropTarget && nestedDropIndicatorStyle]
144
+ css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
146
145
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
147
146
  ,
148
147
  style: widthStyle,
@@ -131,9 +131,7 @@ export const createPlugin = (api, getIntl) => {
131
131
  if (!fg('platform_editor_elements_dnd_nested')) {
132
132
  isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
133
133
  }
134
- const dropTargetLen = decorations.find().filter(({
135
- spec
136
- }) => spec.type === 'drop-target-decoration').length;
134
+ const dropTargetLen = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration').length;
137
135
 
138
136
  //TODO: Fix this logic for nested scenarios
139
137
  if (!fg('platform_editor_elements_dnd_nested')) {
@@ -157,9 +155,7 @@ export const createPlugin = (api, getIntl) => {
157
155
 
158
156
  // Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
159
157
  if (redrawDecorations && !isResizerResizing && api) {
160
- const oldNodeDecs = decorations.find().filter(({
161
- spec
162
- }) => spec.type !== 'drop-target-decoration');
158
+ const oldNodeDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
163
159
  decorations = decorations.remove(oldNodeDecs);
164
160
  const nodeDecs = nodeDecorations(newState);
165
161
  decorations = decorations.add(newState.doc, [...nodeDecs]);
@@ -194,9 +190,7 @@ export const createPlugin = (api, getIntl) => {
194
190
 
195
191
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
196
192
  if (api && 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) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
197
- const oldHandle = decorations.find().filter(({
198
- spec
199
- }) => spec.id === 'drag-handle');
193
+ const oldHandle = decorations.find(undefined, undefined, spec => spec.id === 'drag-handle');
200
194
  decorations = decorations.remove(oldHandle);
201
195
  const decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
202
196
  decorations = decorations.add(newState.doc, [decs]);
@@ -204,21 +198,22 @@ export const createPlugin = (api, getIntl) => {
204
198
 
205
199
  // Remove previous drag handle widget and draw new drag handle widget when node type changes
206
200
  if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
207
- const oldHandle = decorations.find().filter(({
208
- spec
209
- }) => spec.id === 'drag-handle');
201
+ const oldHandle = decorations.find(undefined, undefined, spec => spec.id === 'drag-handle');
210
202
  decorations = decorations.remove(oldHandle);
211
203
  const decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
212
204
  decorations = decorations.add(newState.doc, [decs]);
213
205
  }
214
206
  const shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
215
- const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
207
+ const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
216
208
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
217
- // Remove drop target decoration when dragging stops
218
- const dropTargetDecs = decorations.find().filter(({
219
- spec
220
- }) => spec.type === 'drop-target-decoration');
221
- decorations = decorations.remove(dropTargetDecs);
209
+ if (fg('platform_editor_elements_dnd_nested')) {
210
+ const remainingDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
211
+ decorations = DecorationSet.create(newState.doc, remainingDecs);
212
+ } else {
213
+ // Remove drop target decoration when dragging stops
214
+ const dropTargetDecs = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration');
215
+ decorations = decorations.remove(dropTargetDecs);
216
+ }
222
217
  }
223
218
  if (api) {
224
219
  // Add drop targets when node is being dragged
@@ -13,6 +13,7 @@ import { layers } from '@atlaskit/theme/constants';
13
13
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
14
14
  import { nodeMargins, spaceLookupMap } from './consts';
15
15
  const DEFAULT_DROP_INDICATOR_WIDTH = 760;
16
+ const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
16
17
  const styleDropTarget = css({
17
18
  height: "var(--ds-space-100, 8px)",
18
19
  marginTop: "var(--ds-space-negative-100, -8px)",
@@ -22,15 +23,20 @@ const styleDropTarget = css({
22
23
  display: 'block',
23
24
  zIndex: layers.card()
24
25
  });
26
+ const styleDropIndicator = css({
27
+ height: '100%',
28
+ margin: '0 auto',
29
+ position: 'relative',
30
+ width: `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH}, 100%)`
31
+ });
25
32
  const nestedDropIndicatorStyle = css({
26
33
  position: 'relative'
27
34
  });
28
35
  const marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(([key, value], i) => [key,
29
36
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
30
37
  css({
31
- marginTop: value
38
+ transform: `translateY(${value})`
32
39
  })]));
33
- const BASE_LINE_MARGIN = -8;
34
40
  const getNodeMargins = node => {
35
41
  if (!node) {
36
42
  return nodeMargins['default'];
@@ -41,26 +47,19 @@ const getNodeMargins = node => {
41
47
  }
42
48
  return nodeMargins[nodeTypeName] || nodeMargins['default'];
43
49
  };
44
- const getDropTargetPositionStyle = (prevNode, nextNode) => {
50
+ const getDropTargetOffsetStyle = (prevNode, nextNode) => {
45
51
  if (!prevNode || !nextNode) {
46
52
  return null;
47
53
  }
48
- const space = BASE_LINE_MARGIN - Math.round((getNodeMargins(prevNode).bottom - getNodeMargins(nextNode).top) / 2);
49
- if (space < -24) {
50
- return marginLookupMap[-24];
51
- } else if (space > 24) {
52
- return marginLookupMap[24];
53
- } else {
54
- return marginLookupMap[space];
54
+ const top = getNodeMargins(nextNode).top;
55
+ const bottom = getNodeMargins(prevNode).bottom;
56
+ const merginDiff = Math.round((top - bottom) / 2);
57
+ if (merginDiff === 0) {
58
+ return null;
55
59
  }
60
+ const offset = Math.max(Math.min(merginDiff, 24), -24);
61
+ return marginLookupMap[offset];
56
62
  };
57
- const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
58
- const styleDropIndicator = css({
59
- height: '100%',
60
- margin: '0 auto',
61
- position: 'relative',
62
- width: `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH}, 100%)`
63
- });
64
63
  export const DropTarget = ({
65
64
  api,
66
65
  id,
@@ -111,16 +110,16 @@ export const DropTarget = ({
111
110
  }
112
111
  });
113
112
  }, [id, api, formatMessage]);
114
- const topTargetMarginStyle = useMemo(() => {
113
+ const dropTargetOffsetStyle = useMemo(() => {
115
114
  /**
116
115
  * First child of a nested node.
117
- * Disable the position adjustment for the nested node temporarily
116
+ * Disable the position adjustment temporarily
118
117
  */
119
- if (parentNode === prevNode || isNestedDropTarget) {
118
+ if (parentNode === prevNode) {
120
119
  return null;
121
120
  }
122
- return getDropTargetPositionStyle(prevNode, nextNode);
123
- }, [prevNode, nextNode, parentNode, isNestedDropTarget]);
121
+ return getDropTargetOffsetStyle(prevNode, nextNode);
122
+ }, [prevNode, nextNode, parentNode]);
124
123
  const widthStyle = {
125
124
  [EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH]: isNestedDropTarget ? '100%' : `${(widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH}px`
126
125
  };
@@ -128,7 +127,7 @@ export const DropTarget = ({
128
127
  // Note: Firefox has trouble with using a button element as the handle for drag and drop
129
128
  jsx("div", {
130
129
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
131
- css: [styleDropTarget, topTargetMarginStyle, isNestedDropTarget && nestedDropIndicatorStyle]
130
+ css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
132
131
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
133
132
  ,
134
133
  style: widthStyle,
@@ -131,8 +131,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
131
131
  if (!fg('platform_editor_elements_dnd_nested')) {
132
132
  isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
133
133
  }
134
- var dropTargetLen = decorations.find().filter(function (_ref8) {
135
- var spec = _ref8.spec;
134
+ var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
136
135
  return spec.type === 'drop-target-decoration';
137
136
  }).length;
138
137
 
@@ -157,8 +156,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
157
156
 
158
157
  // Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
159
158
  if (redrawDecorations && !isResizerResizing && api) {
160
- var oldNodeDecs = decorations.find().filter(function (_ref9) {
161
- var spec = _ref9.spec;
159
+ var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
162
160
  return spec.type !== 'drop-target-decoration';
163
161
  });
164
162
  decorations = decorations.remove(oldNodeDecs);
@@ -195,8 +193,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
195
193
 
196
194
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
197
195
  if (api && 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) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
198
- var _oldHandle = decorations.find().filter(function (_ref10) {
199
- var spec = _ref10.spec;
196
+ var _oldHandle = decorations.find(undefined, undefined, function (spec) {
200
197
  return spec.id === 'drag-handle';
201
198
  });
202
199
  decorations = decorations.remove(_oldHandle);
@@ -206,8 +203,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
206
203
 
207
204
  // Remove previous drag handle widget and draw new drag handle widget when node type changes
208
205
  if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
209
- var _oldHandle2 = decorations.find().filter(function (_ref11) {
210
- var spec = _ref11.spec;
206
+ var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
211
207
  return spec.id === 'drag-handle';
212
208
  });
213
209
  decorations = decorations.remove(_oldHandle2);
@@ -215,14 +211,20 @@ export var createPlugin = function createPlugin(api, getIntl) {
215
211
  decorations = decorations.add(newState.doc, [_decs]);
216
212
  }
217
213
  var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
218
- var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
214
+ var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
219
215
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
220
- // Remove drop target decoration when dragging stops
221
- var dropTargetDecs = decorations.find().filter(function (_ref12) {
222
- var spec = _ref12.spec;
223
- return spec.type === 'drop-target-decoration';
224
- });
225
- decorations = decorations.remove(dropTargetDecs);
216
+ if (fg('platform_editor_elements_dnd_nested')) {
217
+ var remainingDecs = decorations.find(undefined, undefined, function (spec) {
218
+ return spec.type !== 'drop-target-decoration';
219
+ });
220
+ decorations = DecorationSet.create(newState.doc, remainingDecs);
221
+ } else {
222
+ // Remove drop target decoration when dragging stops
223
+ var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
224
+ return spec.type === 'drop-target-decoration';
225
+ });
226
+ decorations = decorations.remove(dropTargetDecs);
227
+ }
226
228
  }
227
229
  if (api) {
228
230
  // Add drop targets when node is being dragged
@@ -239,9 +241,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
239
241
 
240
242
  //Map drop target decoration positions when the document changes
241
243
  if (shouldMapDropTargets) {
242
- decorationState = decorationState.map(function (_ref13) {
243
- var id = _ref13.id,
244
- pos = _ref13.pos;
244
+ decorationState = decorationState.map(function (_ref8) {
245
+ var id = _ref8.id,
246
+ pos = _ref8.pos;
245
247
  return {
246
248
  id: id,
247
249
  pos: tr.mapping.map(pos)
@@ -254,8 +256,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
254
256
  decorations = decorations.map(tr.mapping, tr.doc);
255
257
  }
256
258
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
257
- var hasNodeDecoration = decorations.find().some(function (_ref14) {
258
- var spec = _ref14.spec;
259
+ var hasNodeDecoration = decorations.find().some(function (_ref9) {
260
+ var spec = _ref9.spec;
259
261
  return spec.type === 'node-decoration';
260
262
  });
261
263
  if (!hasNodeDecoration && isEmptyDoc) {
@@ -15,6 +15,7 @@ import { layers } from '@atlaskit/theme/constants';
15
15
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
16
16
  import { nodeMargins, spaceLookupMap } from './consts';
17
17
  var DEFAULT_DROP_INDICATOR_WIDTH = 760;
18
+ var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
18
19
  var styleDropTarget = css({
19
20
  height: "var(--ds-space-100, 8px)",
20
21
  marginTop: "var(--ds-space-negative-100, -8px)",
@@ -24,6 +25,12 @@ var styleDropTarget = css({
24
25
  display: 'block',
25
26
  zIndex: layers.card()
26
27
  });
28
+ var styleDropIndicator = css({
29
+ height: '100%',
30
+ margin: '0 auto',
31
+ position: 'relative',
32
+ width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
33
+ });
27
34
  var nestedDropIndicatorStyle = css({
28
35
  position: 'relative'
29
36
  });
@@ -34,10 +41,9 @@ var marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(func
34
41
  return [key,
35
42
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
36
43
  css({
37
- marginTop: value
44
+ transform: "translateY(".concat(value, ")")
38
45
  })];
39
46
  }));
40
- var BASE_LINE_MARGIN = -8;
41
47
  var getNodeMargins = function getNodeMargins(node) {
42
48
  if (!node) {
43
49
  return nodeMargins['default'];
@@ -48,26 +54,19 @@ var getNodeMargins = function getNodeMargins(node) {
48
54
  }
49
55
  return nodeMargins[nodeTypeName] || nodeMargins['default'];
50
56
  };
51
- var getDropTargetPositionStyle = function getDropTargetPositionStyle(prevNode, nextNode) {
57
+ var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
52
58
  if (!prevNode || !nextNode) {
53
59
  return null;
54
60
  }
55
- var space = BASE_LINE_MARGIN - Math.round((getNodeMargins(prevNode).bottom - getNodeMargins(nextNode).top) / 2);
56
- if (space < -24) {
57
- return marginLookupMap[-24];
58
- } else if (space > 24) {
59
- return marginLookupMap[24];
60
- } else {
61
- return marginLookupMap[space];
61
+ var top = getNodeMargins(nextNode).top;
62
+ var bottom = getNodeMargins(prevNode).bottom;
63
+ var merginDiff = Math.round((top - bottom) / 2);
64
+ if (merginDiff === 0) {
65
+ return null;
62
66
  }
67
+ var offset = Math.max(Math.min(merginDiff, 24), -24);
68
+ return marginLookupMap[offset];
63
69
  };
64
- var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
65
- var styleDropIndicator = css({
66
- height: '100%',
67
- margin: '0 auto',
68
- position: 'relative',
69
- width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
70
- });
71
70
  export var DropTarget = function DropTarget(_ref3) {
72
71
  var api = _ref3.api,
73
72
  id = _ref3.id,
@@ -119,22 +118,22 @@ export var DropTarget = function DropTarget(_ref3) {
119
118
  }
120
119
  });
121
120
  }, [id, api, formatMessage]);
122
- var topTargetMarginStyle = useMemo(function () {
121
+ var dropTargetOffsetStyle = useMemo(function () {
123
122
  /**
124
123
  * First child of a nested node.
125
- * Disable the position adjustment for the nested node temporarily
124
+ * Disable the position adjustment temporarily
126
125
  */
127
- if (parentNode === prevNode || isNestedDropTarget) {
126
+ if (parentNode === prevNode) {
128
127
  return null;
129
128
  }
130
- return getDropTargetPositionStyle(prevNode, nextNode);
131
- }, [prevNode, nextNode, parentNode, isNestedDropTarget]);
129
+ return getDropTargetOffsetStyle(prevNode, nextNode);
130
+ }, [prevNode, nextNode, parentNode]);
132
131
  var widthStyle = _defineProperty({}, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px"));
133
132
  return (
134
133
  // Note: Firefox has trouble with using a button element as the handle for drag and drop
135
134
  jsx("div", {
136
135
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
137
- css: [styleDropTarget, topTargetMarginStyle, isNestedDropTarget && nestedDropIndicatorStyle]
136
+ css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
138
137
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
139
138
  ,
140
139
  style: widthStyle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
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,7 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^87.6.0",
34
+ "@atlaskit/editor-common": "^87.10.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.7.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
@@ -40,14 +40,14 @@
40
40
  "@atlaskit/editor-prosemirror": "5.0.1",
41
41
  "@atlaskit/editor-shared-styles": "^2.13.0",
42
42
  "@atlaskit/editor-tables": "^2.8.0",
43
- "@atlaskit/icon": "^22.11.0",
43
+ "@atlaskit/icon": "^22.12.0",
44
44
  "@atlaskit/platform-feature-flags": "^0.3.0",
45
45
  "@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
46
46
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
48
- "@atlaskit/theme": "^12.11.0",
49
- "@atlaskit/tokens": "^1.57.0",
50
- "@atlaskit/tooltip": "^18.6.0",
48
+ "@atlaskit/theme": "^13.0.0",
49
+ "@atlaskit/tokens": "^1.58.0",
50
+ "@atlaskit/tooltip": "^18.7.0",
51
51
  "@babel/runtime": "^7.0.0",
52
52
  "@emotion/react": "^11.7.1",
53
53
  "bind-event-listener": "^3.0.0",