@atlaskit/editor-plugin-block-controls 2.9.0 → 2.10.1

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/commands/move-to-layout.js +16 -1
  3. package/dist/cjs/pm-plugins/decorations-anchor.js +99 -0
  4. package/dist/cjs/pm-plugins/decorations-common.js +49 -0
  5. package/dist/cjs/pm-plugins/decorations-drag-handle.js +88 -0
  6. package/dist/cjs/pm-plugins/{decorations.js → decorations-drop-target.js} +11 -208
  7. package/dist/cjs/pm-plugins/main.js +21 -19
  8. package/dist/cjs/ui/drop-target-v2.js +3 -3
  9. package/dist/cjs/ui/inline-drop-target.js +79 -20
  10. package/dist/cjs/utils/check-media-layout.js +14 -0
  11. package/dist/cjs/utils/inline-drop-target.js +4 -0
  12. package/dist/es2019/commands/move-to-layout.js +16 -1
  13. package/dist/es2019/pm-plugins/decorations-anchor.js +91 -0
  14. package/dist/es2019/pm-plugins/decorations-common.js +31 -0
  15. package/dist/es2019/pm-plugins/decorations-drag-handle.js +79 -0
  16. package/dist/es2019/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -192
  17. package/dist/es2019/pm-plugins/main.js +3 -1
  18. package/dist/es2019/ui/drop-target-v2.js +1 -1
  19. package/dist/es2019/ui/inline-drop-target.js +77 -18
  20. package/dist/es2019/utils/check-media-layout.js +8 -0
  21. package/dist/es2019/utils/inline-drop-target.js +4 -0
  22. package/dist/esm/commands/move-to-layout.js +16 -1
  23. package/dist/esm/pm-plugins/decorations-anchor.js +92 -0
  24. package/dist/esm/pm-plugins/decorations-common.js +42 -0
  25. package/dist/esm/pm-plugins/decorations-drag-handle.js +81 -0
  26. package/dist/esm/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -203
  27. package/dist/esm/pm-plugins/main.js +3 -1
  28. package/dist/esm/ui/drop-target-v2.js +1 -1
  29. package/dist/esm/ui/inline-drop-target.js +77 -18
  30. package/dist/esm/utils/check-media-layout.js +8 -0
  31. package/dist/esm/utils/inline-drop-target.js +4 -0
  32. package/dist/types/pm-plugins/decorations-anchor.d.ts +13 -0
  33. package/dist/types/pm-plugins/decorations-common.d.ts +7 -0
  34. package/dist/types/pm-plugins/decorations-drag-handle.d.ts +7 -0
  35. package/dist/types/pm-plugins/decorations-drop-target.d.ts +17 -0
  36. package/dist/types/ui/inline-drop-target.d.ts +6 -1
  37. package/dist/types/utils/check-media-layout.d.ts +2 -0
  38. package/dist/types-ts4.5/pm-plugins/decorations-anchor.d.ts +13 -0
  39. package/dist/types-ts4.5/pm-plugins/decorations-common.d.ts +7 -0
  40. package/dist/types-ts4.5/pm-plugins/decorations-drag-handle.d.ts +7 -0
  41. package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +17 -0
  42. package/dist/types-ts4.5/ui/inline-drop-target.d.ts +6 -1
  43. package/dist/types-ts4.5/utils/check-media-layout.d.ts +2 -0
  44. package/package.json +6 -6
  45. package/dist/types/pm-plugins/decorations.d.ts +0 -35
  46. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -35
@@ -22,7 +22,9 @@ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
22
22
  var _anchorUtils = require("../utils/anchor-utils");
23
23
  var _dragTargetDebug = require("../utils/drag-target-debug");
24
24
  var _transactions = require("../utils/transactions");
25
- var _decorations = require("./decorations");
25
+ var _decorationsAnchor = require("./decorations-anchor");
26
+ var _decorationsDragHandle = require("./decorations-drag-handle");
27
+ var _decorationsDropTarget = require("./decorations-drop-target");
26
28
  var _handleMouseOver = require("./handle-mouse-over");
27
29
  var _keymap = require("./keymap");
28
30
  var key = exports.key = new _state.PluginKey('blockControls');
@@ -138,13 +140,13 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
138
140
  var shouldRedrawNodeDecs = !isResizerResizing && isNodeDecsMissing;
139
141
  var isActiveNodeModified = false;
140
142
  if (api && shouldRedrawNodeDecs) {
141
- var oldNodeDecs = (0, _decorations.findNodeDecs)(decorations, from, to);
143
+ var oldNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, from, to);
142
144
  decorations = decorations.remove(oldNodeDecs);
143
- var newNodeDecs = (0, _decorations.nodeDecorations)(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
145
+ var newNodeDecs = (0, _decorationsAnchor.nodeDecorations)(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
144
146
  decorations = decorations.add(newState.doc, newNodeDecs);
145
147
  if (latestActiveNode && !isActiveNodeDeleted) {
146
148
  // Find the newly minted node decs that touch the active node
147
- var findNewNodeDecs = (0, _decorations.findNodeDecs)(decorations, latestActiveNode.pos - 1, to);
149
+ var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, latestActiveNode.pos - 1, to);
148
150
 
149
151
  // Find the specific dec that the active node corresponds to
150
152
  var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
@@ -179,13 +181,13 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
179
181
  var shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
180
182
  if (shouldRemoveHandle) {
181
183
  var _activeNode3, _activeNode4;
182
- var oldHandle = (0, _decorations.findHandleDec)(decorations, (_activeNode3 = activeNode) === null || _activeNode3 === void 0 ? void 0 : _activeNode3.pos, (_activeNode4 = activeNode) === null || _activeNode4 === void 0 ? void 0 : _activeNode4.pos);
184
+ var oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode3 = activeNode) === null || _activeNode3 === void 0 ? void 0 : _activeNode3.pos, (_activeNode4 = activeNode) === null || _activeNode4 === void 0 ? void 0 : _activeNode4.pos);
183
185
  decorations = decorations.remove(oldHandle);
184
186
  } else if (api && shouldRecreateHandle) {
185
187
  var _activeNode5, _activeNode6;
186
- var _oldHandle = (0, _decorations.findHandleDec)(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
188
+ var _oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
187
189
  decorations = decorations.remove(_oldHandle);
188
- var handleDec = (0, _decorations.dragHandleDecoration)(api, formatMessage, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.anchorName, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.nodeType, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.handleOptions);
190
+ var handleDec = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.anchorName, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.nodeType, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.handleOptions);
189
191
  decorations = decorations.add(newState.doc, [handleDec]);
190
192
  }
191
193
 
@@ -194,25 +196,25 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
194
196
 
195
197
  // Remove drop target decorations when dragging stops or they need to be redrawn
196
198
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
197
- var dropTargetDecs = (0, _decorations.findDropTargetDecs)(decorations);
199
+ var dropTargetDecs = (0, _decorationsDropTarget.findDropTargetDecs)(decorations);
198
200
  decorations = decorations.remove(dropTargetDecs);
199
201
  }
200
202
 
201
203
  // Add drop targets when dragging starts or some are missing
202
204
  if (api) {
203
205
  if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
204
- var decs = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, latestActiveNode, anchorRectCache);
206
+ var decs = (0, _decorationsDropTarget.dropTargetDecorations)(newState, api, formatMessage, latestActiveNode, anchorRectCache);
205
207
  decorations = decorations.add(newState.doc, decs);
206
208
  }
207
209
  }
208
210
  var isEmptyDoc = (0, _utils.isEmptyDocument)(newState.doc);
209
211
  if (isEmptyDoc) {
210
- var hasNodeDecoration = !!(0, _decorations.findNodeDecs)(decorations).length;
212
+ var hasNodeDecoration = !!(0, _decorationsAnchor.findNodeDecs)(decorations).length;
211
213
  if (!hasNodeDecoration) {
212
- decorations = decorations.add(newState.doc, [(0, _decorations.emptyParagraphNodeDecorations)()]);
214
+ decorations = decorations.add(newState.doc, [(0, _decorationsDragHandle.emptyParagraphNodeDecorations)()]);
213
215
  }
214
216
  }
215
- var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && (0, _decorations.findHandleDec)(decorations, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos).length === 0 ? null : latestActiveNode;
217
+ var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && (0, _decorationsDragHandle.findHandleDec)(decorations, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos).length === 0 ? null : latestActiveNode;
216
218
  return {
217
219
  decorations: decorations,
218
220
  activeNode: newActiveNode,
@@ -307,7 +309,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
307
309
  return spec.type !== 'drop-target-decoration';
308
310
  });
309
311
  decorations = decorations.remove(oldNodeDecs);
310
- var newNodeDecs = (0, _decorations.nodeDecorations)(newState);
312
+ var newNodeDecs = (0, _decorationsAnchor.nodeDecorations)(newState);
311
313
  decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(newNodeDecs));
312
314
  if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
313
315
  var mappedPosisiton = tr.mapping.map(activeNode.pos);
@@ -331,7 +333,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
331
333
  var decAtPos = newNodeDecs.find(function (dec) {
332
334
  return dec.from === mappedPosisiton;
333
335
  });
334
- draghandleDec = (0, _decorations.dragHandleDecoration)(api, formatMessage, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref6 = (_meta$activeNode$anch = meta === null || meta === void 0 || (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref6 !== void 0 ? _ref6 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref7 = (_meta$activeNode$node = meta === null || meta === void 0 || (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref7 !== void 0 ? _ref7 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, meta === null || meta === void 0 || (_meta$activeNode6 = meta.activeNode) === null || _meta$activeNode6 === void 0 ? void 0 : _meta$activeNode6.handleOptions);
336
+ draghandleDec = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref6 = (_meta$activeNode$anch = meta === null || meta === void 0 || (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref6 !== void 0 ? _ref6 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref7 = (_meta$activeNode$node = meta === null || meta === void 0 || (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref7 !== void 0 ? _ref7 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, meta === null || meta === void 0 || (_meta$activeNode6 = meta.activeNode) === null || _meta$activeNode6 === void 0 ? void 0 : _meta$activeNode6.handleOptions);
335
337
  } else {
336
338
  var nodeType = activeNode.nodeType;
337
339
  var anchorName = activeNode.anchorName;
@@ -344,7 +346,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
344
346
  anchorName: anchorName
345
347
  };
346
348
  }
347
- draghandleDec = (0, _decorations.dragHandleDecoration)(api, formatMessage, activeNode.pos, anchorName, nodeType);
349
+ draghandleDec = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, activeNode.pos, anchorName, nodeType);
348
350
  }
349
351
  decorations = decorations.add(newState.doc, [draghandleDec]);
350
352
  }
@@ -356,7 +358,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
356
358
  return spec.type === 'drag-handle';
357
359
  });
358
360
  decorations = decorations.remove(_oldHandle3);
359
- var decs = (0, _decorations.dragHandleDecoration)(api, formatMessage, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
361
+ var decs = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
360
362
  decorations = decorations.add(newState.doc, [decs]);
361
363
  }
362
364
 
@@ -366,7 +368,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
366
368
  return spec.type === 'drag-handle';
367
369
  });
368
370
  decorations = decorations.remove(_oldHandle4);
369
- var _decs = (0, _decorations.dragHandleDecoration)(api, formatMessage, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
371
+ var _decs = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
370
372
  decorations = decorations.add(newState.doc, [_decs]);
371
373
  }
372
374
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
@@ -389,7 +391,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
389
391
  // if the transaction is only for analytics and user is dragging, continue to draw drop targets
390
392
  if (shouldCreateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
391
393
  var _meta$activeNode7;
392
- var _decs2 = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorRectCache);
394
+ var _decs2 = (0, _decorationsDropTarget.dropTargetDecorations)(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorRectCache);
393
395
  decorations = decorations.add(newState.doc, _decs2);
394
396
  }
395
397
  }
@@ -399,7 +401,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
399
401
  return spec.type === 'node-decoration';
400
402
  }).length;
401
403
  if (!hasNodeDecoration) {
402
- decorations = decorations.add(newState.doc, [(0, _decorations.emptyParagraphNodeDecorations)()]);
404
+ decorations = decorations.add(newState.doc, [(0, _decorationsDragHandle.emptyParagraphNodeDecorations)()]);
403
405
  }
404
406
  }
405
407
  var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, function (spec) {
@@ -15,7 +15,7 @@ var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box")
15
15
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
16
16
  var _constants = require("@atlaskit/theme/constants");
17
17
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
- var _decorations = require("../pm-plugins/decorations");
18
+ var _decorationsCommon = require("../pm-plugins/decorations-common");
19
19
  var _anchorUtils = require("../utils/anchor-utils");
20
20
  var _dragTargetDebug = require("../utils/drag-target-debug");
21
21
  var _inlineDropTarget = require("../utils/inline-drop-target");
@@ -94,7 +94,7 @@ var HoverZone = function HoverZone(_ref) {
94
94
  }, [onDragEnter, onDragLeave, onDrop]);
95
95
  var isRemainingheight = dropTargetStyle === 'remainingHeight';
96
96
  var hoverZoneUpperStyle = (0, _react.useMemo)(function () {
97
- var anchorName = node ? (0, _decorations.getNodeAnchor)(node) : '';
97
+ var anchorName = node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
98
98
  var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
99
99
  var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
100
100
  var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? (0, _anchorUtils.isAnchorSupported)() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0) / 2, "px + ").concat(heightStyleOffset, ")") : '4px';
@@ -119,7 +119,7 @@ var HoverZone = function HoverZone(_ref) {
119
119
  // only apply upper drop zone
120
120
  if (isRemainingheight && position === 'upper') {
121
121
  // previous node
122
- var anchorName = node ? (0, _decorations.getNodeAnchor)(node) : '';
122
+ var anchorName = node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
123
123
  var top = 'unset';
124
124
  if (anchorName) {
125
125
  var enabledDropZone = enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '');
@@ -11,8 +11,9 @@ var _react2 = require("@emotion/react");
11
11
  var _hooks = require("@atlaskit/editor-common/hooks");
12
12
  var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
13
13
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
14
- var _decorations = require("../pm-plugins/decorations");
14
+ var _decorationsCommon = require("../pm-plugins/decorations-common");
15
15
  var _anchorUtils = require("../utils/anchor-utils");
16
+ var _dragTargetDebug = require("../utils/drag-target-debug");
16
17
  /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
17
18
  /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
18
19
  /**
@@ -26,13 +27,10 @@ var dropTargetCommonStyle = (0, _react2.css)({
26
27
  position: 'absolute',
27
28
  display: 'block'
28
29
  });
29
- var hideDropTargetStyle = (0, _react2.css)({
30
- display: 'none'
31
- });
32
30
  var hoverZoneCommonStyle = (0, _react2.css)({
33
31
  position: 'absolute',
34
- // same value as block hover zone
35
- zIndex: 110
32
+ // above the top and bottom drop zone as block hover zone
33
+ zIndex: 120
36
34
  });
37
35
 
38
36
  // gap between node boundary and drop indicator/drop zone
@@ -40,6 +38,60 @@ var GAP = 4;
40
38
  var HOVER_ZONE_WIDTH_OFFSET = 40;
41
39
  var HOVER_ZONE_HEIGHT_OFFSET = 10;
42
40
  var HOVER_ZONE_DEFAULT_WIDTH = 40;
41
+ var getDropTargetPositionOverride = function getDropTargetPositionOverride(node, editorWidth) {
42
+ if (!node || !editorWidth) {
43
+ return {
44
+ left: 0,
45
+ right: 0
46
+ };
47
+ }
48
+ var getOffsets = function getOffsets(nodeWidth) {
49
+ var offset = (editorWidth - nodeWidth) / 2;
50
+ return {
51
+ left: offset,
52
+ right: offset
53
+ };
54
+ };
55
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
56
+ return getOffsets(node.attrs.width);
57
+ }
58
+
59
+ // media single 🤦
60
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
61
+ var mediaNodeWidth = 0;
62
+ if (node.attrs.width) {
63
+ if (node.attrs.widthType === 'pixel') {
64
+ mediaNodeWidth = node.attrs.width;
65
+ } else if (editorWidth) {
66
+ mediaNodeWidth = node.attrs.width / 100 * editorWidth;
67
+ }
68
+ } else {
69
+ // use media width
70
+ var mediaNode = node.firstChild;
71
+ if (mediaNode && mediaNode.attrs.width) {
72
+ mediaNodeWidth = mediaNode.attrs.width;
73
+ }
74
+ }
75
+ if (mediaNodeWidth) {
76
+ if (node.attrs.layout === 'align-start') {
77
+ return {
78
+ left: 0,
79
+ right: editorWidth - mediaNodeWidth
80
+ };
81
+ } else if (node.attrs.layout === 'align-end') {
82
+ return {
83
+ left: editorWidth - mediaNodeWidth,
84
+ right: 0
85
+ };
86
+ }
87
+ return getOffsets(mediaNodeWidth);
88
+ }
89
+ }
90
+ return {
91
+ left: 0,
92
+ right: 0
93
+ };
94
+ };
43
95
  var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref) {
44
96
  var api = _ref.api,
45
97
  nextNode = _ref.nextNode,
@@ -52,29 +104,32 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
52
104
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
53
105
  isDraggedOver = _useState2[0],
54
106
  setIsDraggedOver = _useState2[1];
55
- var anchorName = nextNode ? (0, _decorations.getNodeAnchor)(nextNode) : '';
107
+ var anchorName = nextNode ? (0, _decorationsCommon.getNodeAnchor)(nextNode) : '';
56
108
  var handleDragEnter = (0, _react.useCallback)(function () {
57
109
  setIsDraggedOver(true);
58
110
  }, []);
59
111
  var handleDragLeave = (0, _react.useCallback)(function () {
60
112
  setIsDraggedOver(false);
61
113
  }, []);
114
+ var offsets = (0, _react.useMemo)(function () {
115
+ return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
116
+ }, [nextNode, widthState]);
62
117
  var dropTargetRectStyle = (0, _react.useMemo)(function () {
63
118
  if ((0, _anchorUtils.isAnchorSupported)()) {
64
119
  return (0, _react2.css)({
65
120
  height: "calc(anchor-size(".concat(anchorName, " height))"),
66
121
  positionAnchor: anchorName,
67
- left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
122
+ left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
68
123
  top: "calc(anchor(top))"
69
124
  });
70
125
  }
71
126
  var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
72
127
  return (0, _react2.css)({
73
128
  height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
74
- left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
129
+ left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP + offsets.left, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offsets.right, "px"),
75
130
  top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
76
131
  });
77
- }, [anchorName, anchorRectCache, position]);
132
+ }, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
78
133
  var onDrop = (0, _react.useCallback)(function () {
79
134
  var _api$blockControls;
80
135
  var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
@@ -91,8 +146,8 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
91
146
  }, [api, getPos, position]);
92
147
  return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)("div", {
93
148
  "data-test-id": "block-ctrl-drop-target-".concat(position),
94
- css: [dropTargetCommonStyle, dropTargetRectStyle, !isDraggedOver && hideDropTargetStyle]
95
- }, (0, _react2.jsx)(_box.DropIndicator, {
149
+ css: [dropTargetCommonStyle, dropTargetRectStyle]
150
+ }, (isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)(_box.DropIndicator, {
96
151
  edge: position
97
152
  })), (0, _react2.jsx)(InlineHoverZone, {
98
153
  position: position,
@@ -101,7 +156,8 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
101
156
  anchorRectCache: anchorRectCache,
102
157
  onDragEnter: handleDragEnter,
103
158
  onDragLeave: handleDragLeave,
104
- onDrop: onDrop
159
+ onDrop: onDrop,
160
+ offsets: offsets
105
161
  }));
106
162
  };
107
163
  var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3) {
@@ -109,13 +165,14 @@ var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3)
109
165
  editorWidthState = _ref3.editorWidthState,
110
166
  anchorRectCache = _ref3.anchorRectCache,
111
167
  position = _ref3.position,
168
+ offsets = _ref3.offsets,
112
169
  onDragEnter = _ref3.onDragEnter,
113
170
  onDragLeave = _ref3.onDragLeave,
114
171
  onDrop = _ref3.onDrop;
115
172
  var ref = (0, _react.useRef)(null);
116
173
  var _ref4 = editorWidthState || {},
117
174
  editorWith = _ref4.width;
118
- var anchorName = node ? (0, _decorations.getNodeAnchor)(node) : '';
175
+ var anchorName = node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
119
176
  (0, _react.useEffect)(function () {
120
177
  if (ref.current) {
121
178
  return (0, _adapter.dropTargetForElements)({
@@ -127,27 +184,29 @@ var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3)
127
184
  }
128
185
  }, [onDragEnter, onDragLeave, onDrop]);
129
186
  var inlineHoverZoneRectStyle = (0, _react.useMemo)(function () {
187
+ var offset = offsets[position];
130
188
  if ((0, _anchorUtils.isAnchorSupported)()) {
131
189
  return (0, _react2.css)({
132
190
  positionAnchor: anchorName,
133
- left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
134
- right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
191
+ left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
192
+ right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
135
193
  top: "calc(anchor(top))",
136
- width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
194
+ width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px + ").concat(offset, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
137
195
  height: "calc(anchor-size(".concat(anchorName, " height))")
138
196
  });
139
197
  }
140
198
  var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
141
- var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
199
+ var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
142
200
  return (0, _react2.css)({
143
- left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
201
+ left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP + offset, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offset, "px"),
144
202
  top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
145
203
  width: "".concat(width, "px"),
146
204
  height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
147
205
  });
148
- }, [anchorName, anchorRectCache, editorWith, position]);
206
+ }, [anchorName, anchorRectCache, editorWith, offsets, position]);
149
207
  return (0, _react2.jsx)("div", {
150
208
  ref: ref,
209
+ "data-test-id": "drop-target-hover-zone-".concat(position),
151
210
  css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
152
211
  });
153
212
  };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isWrappedMedia = void 0;
7
+ var isWrappedMedia = exports.isWrappedMedia = function isWrappedMedia(node) {
8
+ if ('mediaSingle' === (node === null || node === void 0 ? void 0 : node.type.name)) {
9
+ if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
10
+ return true;
11
+ }
12
+ }
13
+ return false;
14
+ };
@@ -7,10 +7,14 @@ exports.shouldAllowInlineDropTarget = void 0;
7
7
  var _utils = require("@atlaskit/editor-common/utils");
8
8
  var _consts = require("../consts");
9
9
  var _advancedLayoutsFlags = require("./advanced-layouts-flags");
10
+ var _checkMediaLayout = require("./check-media-layout");
10
11
  var shouldAllowInlineDropTarget = exports.shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
11
12
  if (!(0, _advancedLayoutsFlags.isPreRelease1)() || isNested) {
12
13
  return false;
13
14
  }
15
+ if ((0, _checkMediaLayout.isWrappedMedia)(node)) {
16
+ return false;
17
+ }
14
18
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
15
19
  return node.childCount < _consts.MAX_LAYOUT_COLUMN_SUPPORTED;
16
20
  }
@@ -1,4 +1,5 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
3
4
  import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
4
5
  const createNewLayout = (schema, layoutContents) => {
@@ -68,13 +69,25 @@ export const moveToLayout = api => (from, to, position) => ({
68
69
  if ($to.nodeAfter.type === layoutSection) {
69
70
  const existingLayoutNode = $to.nodeAfter;
70
71
  if (existingLayoutNode.childCount < MAX_LAYOUT_COLUMN_SUPPORTED) {
72
+ const newColumnWidth = DEFAULT_COLUMN_DISTRIBUTIONS[existingLayoutNode.childCount + 1];
73
+ if (newColumnWidth) {
74
+ existingLayoutNode.content.forEach((node, offset) => {
75
+ if (node.type === layoutColumn) {
76
+ tr = tr.setNodeAttribute(to + offset + 1, 'width', newColumnWidth);
77
+ }
78
+ });
79
+ }
71
80
  const toPos = position === 'left' ? to + 1 : to + existingLayoutNode.nodeSize - 1;
72
81
  tr = tr.insert(toPos,
73
82
  // resolve again the source node after node updated (remove breakout marks)
74
- layoutColumn.create(null, tr.doc.resolve(from).nodeAfter));
83
+ layoutColumn.create({
84
+ width: newColumnWidth
85
+ }, tr.doc.resolve(from).nodeAfter));
86
+ tr = tr.setSelection(new NodeSelection(tr.doc.resolve(toPos)));
75
87
  const mappedFrom = tr.mapping.map(from);
76
88
  const mappedFromEnd = mappedFrom + fromNode.nodeSize;
77
89
  tr = tr.delete(mappedFrom, mappedFromEnd);
90
+ tr = tr.scrollIntoView();
78
91
  return tr;
79
92
  }
80
93
  return tr;
@@ -91,6 +104,8 @@ export const moveToLayout = api => (from, to, position) => ({
91
104
  const mappedTo = tr.mapping.map(to);
92
105
  tr = tr.delete(mappedTo, mappedTo + toNode.nodeSize);
93
106
  tr = tr.insert(mappedTo, newLayout); // insert the content at the new position
107
+ tr = tr.setSelection(new NodeSelection(tr.doc.resolve(mappedTo)));
108
+ tr = tr.scrollIntoView();
94
109
  }
95
110
  return tr;
96
111
  }
@@ -0,0 +1,91 @@
1
+ import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
+ import { getNestedDepth, getNodeAnchor, TYPE_NODE_DEC } from './decorations-common';
5
+ const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
6
+ const IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
7
+ export const shouldDescendIntoNode = node => {
8
+ // Optimisation to avoid drawing node decorations for empty table cells
9
+ if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
10
+ var _node$firstChild;
11
+ if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
12
+ return false;
13
+ }
14
+ }
15
+ return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
16
+ };
17
+ const shouldIgnoreNode = node => {
18
+ // TODO use isWrappedMedia when clean up the featue flag
19
+ if ('mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1')) {
20
+ if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
21
+ return true;
22
+ }
23
+ }
24
+ return IGNORE_NODES.includes(node.type.name);
25
+ };
26
+
27
+ /**
28
+ * Find node decorations in the pos range between from and to (non-inclusive)
29
+ * @param decorations
30
+ * @param from
31
+ * @param to
32
+ * @returns
33
+ */
34
+ export const findNodeDecs = (decorations, from, to) => {
35
+ let newfrom = from;
36
+ let newTo = to;
37
+
38
+ // make it non-inclusive
39
+ if (newfrom !== undefined) {
40
+ newfrom++;
41
+ }
42
+
43
+ // make it non-inclusive
44
+ if (newTo !== undefined) {
45
+ newTo--;
46
+ }
47
+
48
+ // return empty array if range reversed
49
+ if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
50
+ return new Array();
51
+ }
52
+ return decorations.find(newfrom, newTo, spec => spec.type === TYPE_NODE_DEC);
53
+ };
54
+ export const nodeDecorations = (newState, from, to) => {
55
+ const decs = [];
56
+ const docFrom = from === undefined || from < 0 ? 0 : from;
57
+ const docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
58
+ newState.doc.nodesBetween(docFrom, docTo, (node, pos, _parent, index) => {
59
+ let depth = 0;
60
+ let anchorName;
61
+ const shouldDescend = shouldDescendIntoNode(node);
62
+ anchorName = getNodeAnchor(node);
63
+ if (editorExperiment('nested-dnd', true)) {
64
+ var _anchorName;
65
+ // Doesn't descend into a node
66
+ if (node.isInline) {
67
+ return false;
68
+ }
69
+ if (shouldIgnoreNode(node)) {
70
+ return shouldDescend; //skip over, don't consider it a valid depth
71
+ }
72
+ depth = newState.doc.resolve(pos).depth;
73
+ anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : `--node-anchor-${node.type.name}-${pos}`;
74
+ } else {
75
+ var _anchorName2;
76
+ anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : `--node-anchor-${node.type.name}-${index}`;
77
+ }
78
+ decs.push(Decoration.node(pos, pos + node.nodeSize, {
79
+ style: `anchor-name: ${anchorName}; ${pos === 0 ? 'margin-top: 0px;' : ''}; position: relative; z-index: 1;`,
80
+ ['data-drag-handler-anchor-name']: anchorName,
81
+ ['data-drag-handler-node-type']: node.type.name,
82
+ ['data-drag-handler-anchor-depth']: `${depth}`
83
+ }, {
84
+ type: TYPE_NODE_DEC,
85
+ anchorName,
86
+ nodeType: node.type.name
87
+ }));
88
+ return shouldDescend && depth < getNestedDepth();
89
+ });
90
+ return decs;
91
+ };
@@ -0,0 +1,31 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import ReactDOM from 'react-dom';
3
+ import uuid from 'uuid';
4
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
+ export const TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
6
+ export const TYPE_HANDLE_DEC = 'drag-handle';
7
+ export const TYPE_NODE_DEC = 'node-decoration';
8
+ export const getNestedDepth = () => editorExperiment('nested-dnd', true) ? 100 : 0;
9
+ export const getNodeAnchor = node => {
10
+ const handleId = ObjHash.getForNode(node);
11
+ return `--node-anchor-${node.type.name}-${handleId}`;
12
+ };
13
+ class ObjHash {
14
+ static getForNode(node) {
15
+ if (this.caching.has(node)) {
16
+ return this.caching.get(node);
17
+ }
18
+ const uniqueId = uuid();
19
+ this.caching.set(node, uniqueId);
20
+ return uniqueId;
21
+ }
22
+ }
23
+ _defineProperty(ObjHash, "caching", new WeakMap());
24
+ export const unmountDecorations = selector => {
25
+ // Removing decorations manually instead of using native destroy function in prosemirror API
26
+ // as it was more responsive and causes less re-rendering
27
+ const decorationsToRemove = document.querySelectorAll(`[${selector}="true"]`);
28
+ decorationsToRemove.forEach(el => {
29
+ ReactDOM.unmountComponentAtNode(el);
30
+ });
31
+ };
@@ -0,0 +1,79 @@
1
+ import { createElement } from 'react';
2
+ import { bind } from 'bind-event-listener';
3
+ import ReactDOM from 'react-dom';
4
+ import uuid from 'uuid';
5
+ import { Decoration } from '@atlaskit/editor-prosemirror/view';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
7
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
+ import { DragHandle } from '../ui/drag-handle';
9
+ import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
10
+ export const emptyParagraphNodeDecorations = () => {
11
+ const anchorName = `--node-anchor-paragraph-0`;
12
+ const style = `anchor-name: ${anchorName}; margin-top: 0px;`;
13
+ return Decoration.node(0, 2, {
14
+ style,
15
+ ['data-drag-handler-anchor-name']: anchorName
16
+ }, {
17
+ type: TYPE_NODE_DEC
18
+ });
19
+ };
20
+ export const findHandleDec = (decorations, from, to) => {
21
+ return decorations.find(from, to, spec => spec.type === TYPE_HANDLE_DEC);
22
+ };
23
+ export const dragHandleDecoration = (api, formatMessage, pos, anchorName, nodeType, handleOptions) => {
24
+ unmountDecorations('data-blocks-drag-handle-container');
25
+ let unbind;
26
+ return Decoration.widget(pos, (view, getPos) => {
27
+ const element = document.createElement('span');
28
+ // Need to set it to inline to avoid text being split when merging two paragraphs
29
+ // platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
30
+ element.style.display = fg('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
31
+ element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
32
+ element.setAttribute('data-blocks-drag-handle-container', 'true');
33
+ let isTopLevelNode = true;
34
+ if (editorExperiment('nested-dnd', true)) {
35
+ const newPos = fg('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
36
+ if (typeof newPos === 'number') {
37
+ const $pos = view.state.doc.resolve(newPos);
38
+ isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
39
+ }
40
+ /*
41
+ * We disable mouseover event to fix flickering issue on hover
42
+ * However, the tooltip for nested drag handle is no long working.
43
+ */
44
+ if (newPos === undefined || !isTopLevelNode) {
45
+ // This will also hide the tooltip.
46
+ unbind = bind(element, {
47
+ type: 'mouseover',
48
+ listener: e => {
49
+ e.stopPropagation();
50
+ }
51
+ });
52
+ }
53
+ }
54
+
55
+ // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
56
+ // due to margins applied to other nodes eg. Headings
57
+ element.style.clear = 'unset';
58
+ ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
59
+ view,
60
+ api,
61
+ formatMessage,
62
+ getPos,
63
+ anchorName,
64
+ nodeType,
65
+ handleOptions,
66
+ isTopLevelNode
67
+ }), element);
68
+ return element;
69
+ }, {
70
+ side: -1,
71
+ type: TYPE_HANDLE_DEC,
72
+ testid: `${TYPE_HANDLE_DEC}-${uuid()}`,
73
+ destroy: () => {
74
+ if (editorExperiment('nested-dnd', true)) {
75
+ unbind && unbind();
76
+ }
77
+ }
78
+ });
79
+ };