@atlaskit/editor-plugin-block-controls 2.27.0 → 2.27.4

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 +39 -0
  2. package/dist/cjs/blockControlsPlugin.js +35 -6
  3. package/dist/cjs/pm-plugins/decorations-drop-target.js +11 -5
  4. package/dist/cjs/pm-plugins/main.js +2 -1
  5. package/dist/cjs/pm-plugins/utils/getSelection.js +2 -2
  6. package/dist/cjs/pm-plugins/utils/validation.js +2 -1
  7. package/dist/cjs/ui/block-menu-items.js +103 -0
  8. package/dist/cjs/ui/block-menu.js +77 -0
  9. package/dist/cjs/ui/consts.js +101 -2
  10. package/dist/cjs/ui/drag-handle.js +147 -41
  11. package/dist/cjs/ui/drag-preview.js +83 -34
  12. package/dist/es2019/blockControlsPlugin.js +34 -3
  13. package/dist/es2019/pm-plugins/decorations-drop-target.js +12 -5
  14. package/dist/es2019/pm-plugins/main.js +2 -1
  15. package/dist/es2019/pm-plugins/utils/getSelection.js +1 -1
  16. package/dist/es2019/pm-plugins/utils/validation.js +2 -1
  17. package/dist/es2019/ui/block-menu-items.js +92 -0
  18. package/dist/es2019/ui/block-menu.js +75 -0
  19. package/dist/es2019/ui/consts.js +100 -1
  20. package/dist/es2019/ui/drag-handle.js +152 -40
  21. package/dist/es2019/ui/drag-preview.js +83 -34
  22. package/dist/esm/blockControlsPlugin.js +35 -6
  23. package/dist/esm/pm-plugins/decorations-drop-target.js +11 -5
  24. package/dist/esm/pm-plugins/main.js +2 -1
  25. package/dist/esm/pm-plugins/utils/getSelection.js +1 -1
  26. package/dist/esm/pm-plugins/utils/validation.js +2 -1
  27. package/dist/esm/ui/block-menu-items.js +92 -0
  28. package/dist/esm/ui/block-menu.js +70 -0
  29. package/dist/esm/ui/consts.js +100 -1
  30. package/dist/esm/ui/drag-handle.js +149 -43
  31. package/dist/esm/ui/drag-preview.js +82 -34
  32. package/dist/types/blockControlsPluginType.d.ts +3 -0
  33. package/dist/types/pm-plugins/utils/getSelection.d.ts +3 -3
  34. package/dist/types/pm-plugins/utils/validation.d.ts +1 -1
  35. package/dist/types/ui/block-menu-items.d.ts +17 -0
  36. package/dist/types/ui/block-menu.d.ts +16 -0
  37. package/dist/types/ui/consts.d.ts +7 -0
  38. package/dist/types/ui/drag-preview.d.ts +9 -1
  39. package/dist/types-ts4.5/blockControlsPluginType.d.ts +3 -0
  40. package/dist/types-ts4.5/pm-plugins/utils/getSelection.d.ts +3 -3
  41. package/dist/types-ts4.5/pm-plugins/utils/validation.d.ts +1 -1
  42. package/dist/types-ts4.5/ui/block-menu-items.d.ts +17 -0
  43. package/dist/types-ts4.5/ui/block-menu.d.ts +16 -0
  44. package/dist/types-ts4.5/ui/consts.d.ts +7 -0
  45. package/dist/types-ts4.5/ui/drag-preview.d.ts +9 -1
  46. package/package.json +5 -5
@@ -18,6 +18,7 @@ import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaK
18
18
  import { blockControlsMessages } from '@atlaskit/editor-common/messages';
19
19
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
20
20
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
21
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
21
22
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
22
23
  import { fg } from '@atlaskit/platform-feature-flags';
23
24
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -28,9 +29,8 @@ import Tooltip from '@atlaskit/tooltip';
28
29
  import { key } from '../pm-plugins/main';
29
30
  import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
30
31
  import { getLeftPosition, getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
31
- import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
32
- import { isHandleInSelection, selectNode } from '../pm-plugins/utils/getSelection';
33
- import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, topPositionAdjustment } from './consts';
32
+ import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
33
+ import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, nodeMargins, spacingBetweenNodesForPreview, topPositionAdjustment } from './consts';
34
34
  import { dragPreview } from './drag-preview';
35
35
  var iconWrapperStyles = xcss({
36
36
  display: 'flex',
@@ -101,6 +101,16 @@ var handleIconDragStart = function handleIconDragStart(e) {
101
101
  (_e$target$closest = e.target.closest('button')) === null || _e$target$closest === void 0 || _e$target$closest.dispatchEvent(dragEvent);
102
102
  }
103
103
  };
104
+ var getNodeSpacingForPreview = function getNodeSpacingForPreview(node) {
105
+ if (!node) {
106
+ return spacingBetweenNodesForPreview['default'];
107
+ }
108
+ var nodeTypeName = node.type.name;
109
+ if (nodeTypeName === 'heading') {
110
+ return spacingBetweenNodesForPreview["heading".concat(node.attrs.level)] || spacingBetweenNodesForPreview['default'];
111
+ }
112
+ return spacingBetweenNodesForPreview[nodeTypeName] || spacingBetweenNodesForPreview['default'];
113
+ };
104
114
  export var DragHandle = function DragHandle(_ref) {
105
115
  var _api$core2, _api$analytics2, _api$core4;
106
116
  var view = _ref.view,
@@ -126,6 +136,9 @@ export var DragHandle = function DragHandle(_ref) {
126
136
  featureFlagsState = _useSharedPluginState.featureFlagsState;
127
137
  var selection = useSharedPluginStateSelector(api, 'selection.selection');
128
138
  var isLayoutColumn = nodeType === 'layoutColumn';
139
+ var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
140
+ exposure: true
141
+ });
129
142
  useEffect(function () {
130
143
  // blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
131
144
  if (nodeType === 'blockCard') {
@@ -170,7 +183,14 @@ export var DragHandle = function DragHandle(_ref) {
170
183
  return tr;
171
184
  });
172
185
  view.focus();
173
- }, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos, nodeType]);
186
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
187
+ var startPos = getPos();
188
+ if (startPos === undefined) {
189
+ return false;
190
+ }
191
+ api === null || api === void 0 || api.core.actions.execute(api.blockControls.commands.toggleBlockMenu());
192
+ }
193
+ }, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 ? void 0 : api.blockControls.commands, view, getPos, nodeType]);
174
194
 
175
195
  // TODO - This needs to be investigated further. Drag preview generation is not always working
176
196
  // as expected with a node selection. This workaround sets the selection to the node on mouseDown,
@@ -234,56 +254,140 @@ export var DragHandle = function DragHandle(_ref) {
234
254
  };
235
255
  },
236
256
  onGenerateDragPreview: function onGenerateDragPreview(_ref4) {
257
+ var _api$blockControls2;
237
258
  var nativeSetDragImage = _ref4.nativeSetDragImage;
259
+ if (isMultiSelect) {
260
+ var _api$core5;
261
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref5) {
262
+ var tr = _ref5.tr;
263
+ var handlePos = getPos();
264
+ if (typeof handlePos !== 'number') {
265
+ return tr;
266
+ }
267
+ if (!tr.selection.empty && handlePos >= tr.selection.$from.start() - 1 && handlePos <= tr.selection.to) {
268
+ var _api$blockControls;
269
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions()({
270
+ tr: tr
271
+ });
272
+ }
273
+ return tr;
274
+ });
275
+ }
276
+ var startPos = getPos();
277
+ var state = view.state;
278
+ var doc = state.doc,
279
+ selection = state.selection;
280
+ var _ref6 = (api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.sharedState.currentState()) || {},
281
+ multiSelectDnD = _ref6.multiSelectDnD;
282
+ var sliceFrom = selection.from;
283
+ var sliceTo = selection.to;
284
+ if (multiSelectDnD) {
285
+ var anchor = multiSelectDnD.anchor,
286
+ head = multiSelectDnD.head;
287
+ sliceFrom = Math.min(anchor, head);
288
+ sliceTo = Math.max(anchor, head);
289
+ }
290
+ var expandedSlice = doc.slice(sliceFrom, sliceTo);
291
+ var isDraggingMultiLine = isMultiSelect && startPos !== undefined && startPos >= sliceFrom && startPos <= sliceTo && expandedSlice.content.childCount > 1;
238
292
  setCustomNativeDragPreview({
239
- render: function render(_ref5) {
240
- var container = _ref5.container;
293
+ getOffset: function getOffset() {
294
+ if (!isDraggingMultiLine) {
295
+ return {
296
+ x: 0,
297
+ y: 0
298
+ };
299
+ } else {
300
+ // Calculate the offset of the preview container,
301
+ // So when drag multiple nodes, the preview align with the position of the selected nodes
302
+ var domAtPos = view.domAtPos.bind(view);
303
+ var domElementsHeightBeforeHandle = 0;
304
+ var nodesStartPos = [];
305
+ var nodesEndPos = [];
306
+ var activeNodeMarginTop = 0;
307
+ for (var i = 0; i < expandedSlice.content.childCount; i++) {
308
+ if (i === 0) {
309
+ var _expandedSlice$conten;
310
+ nodesStartPos[i] = sliceFrom;
311
+ nodesEndPos[i] = sliceFrom + (((_expandedSlice$conten = expandedSlice.content.maybeChild(i)) === null || _expandedSlice$conten === void 0 ? void 0 : _expandedSlice$conten.nodeSize) || 0);
312
+ } else {
313
+ var _expandedSlice$conten2;
314
+ nodesStartPos[i] = nodesEndPos[i - 1];
315
+ nodesEndPos[i] = nodesStartPos[i] + (((_expandedSlice$conten2 = expandedSlice.content.maybeChild(i)) === null || _expandedSlice$conten2 === void 0 ? void 0 : _expandedSlice$conten2.nodeSize) || 0);
316
+ }
317
+
318
+ // when the node is before the handle, calculate the height of the node
319
+ if (nodesEndPos[i] <= startPos) {
320
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
321
+ var currentNodeElement = findDomRefAtPos(nodesStartPos[i], domAtPos);
322
+ var maybeCurrentNode = expandedSlice.content.maybeChild(i);
323
+ var currentNodeSpacing = maybeCurrentNode ? nodeMargins[maybeCurrentNode.type.name].top + nodeMargins[maybeCurrentNode.type.name].bottom : 0;
324
+ domElementsHeightBeforeHandle = domElementsHeightBeforeHandle + currentNodeElement.offsetHeight + currentNodeSpacing;
325
+ } else {
326
+ // when the node is after the handle, calculate the top margin of the active node
327
+ var maybeNextNode = expandedSlice.content.maybeChild(i);
328
+ activeNodeMarginTop = maybeNextNode ? nodeMargins[maybeNextNode.type.name].top : 0;
329
+ break;
330
+ }
331
+ }
332
+ return {
333
+ x: 0,
334
+ y: domElementsHeightBeforeHandle + activeNodeMarginTop
335
+ };
336
+ }
337
+ },
338
+ render: function render(_ref7) {
339
+ var container = _ref7.container;
241
340
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
242
341
  if (!dom) {
243
342
  return;
244
343
  }
245
- return dragPreview(container, dom, nodeType);
344
+ if (!isDraggingMultiLine) {
345
+ return dragPreview(container, {
346
+ dom: dom,
347
+ nodeType: nodeType
348
+ });
349
+ } else {
350
+ var domAtPos = view.domAtPos.bind(view);
351
+ var previewContent = [];
352
+ expandedSlice.content.descendants(function (node, pos, parent, index) {
353
+ // Get the dom element of the node
354
+ //eslint-disable-next-line @atlaskit/editor/no-as-casting
355
+ var nodeDomElement = findDomRefAtPos(sliceFrom + pos, domAtPos);
356
+ var currentNodeSpacing = getNodeSpacingForPreview(node);
357
+ previewContent.push({
358
+ dom: nodeDomElement,
359
+ nodeType: node.type.name,
360
+ nodeSpacing: currentNodeSpacing
361
+ });
362
+ return false; // Only iterate through the first level of nodes
363
+ });
364
+ return dragPreview(container, previewContent);
365
+ }
246
366
  },
247
367
  nativeSetDragImage: nativeSetDragImage
248
368
  });
249
369
  },
250
370
  onDragStart: function onDragStart() {
251
- var _api$core5;
371
+ var _api$core6;
252
372
  if (start === undefined) {
253
373
  return;
254
374
  }
255
- api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
256
- var _api$blockControls2, _api$analytics3;
257
- var tr = _ref6.tr;
258
- var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
259
- exposure: true
260
- });
375
+ api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref8) {
376
+ var _tr$getMeta, _api$blockControls3, _api$analytics3;
377
+ var tr = _ref8.tr;
261
378
  var nodeTypes, hasSelectedMultipleNodes;
262
379
  var resolvedMovingNode = tr.doc.resolve(start);
263
380
  var maybeNode = resolvedMovingNode.nodeAfter;
264
- if (isMultiSelect) {
265
- var _tr$getMeta;
266
- var handlePos = getPos();
267
- if (typeof handlePos !== 'number') {
268
- return tr;
269
- }
270
- if (!tr.selection.empty && handlePos >= tr.selection.$from.start() - 1 && handlePos <= tr.selection.to) {
271
- var _api$blockControls;
272
- api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions()({
273
- tr: tr
274
- });
275
- }
276
- var multiSelectDnD = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.multiSelectDnD;
277
- if (multiSelectDnD) {
278
- var attributes = getMultiSelectAnalyticsAttributes(tr, multiSelectDnD.anchor, multiSelectDnD.head);
279
- nodeTypes = attributes.nodeTypes;
280
- hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
281
- } else {
282
- nodeTypes = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name;
283
- hasSelectedMultipleNodes = false;
284
- }
381
+ var multiSelectDnD = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.multiSelectDnD;
382
+ if (multiSelectDnD) {
383
+ var attributes = getMultiSelectAnalyticsAttributes(tr, multiSelectDnD.anchor, multiSelectDnD.head);
384
+ nodeTypes = attributes.nodeTypes;
385
+ hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
386
+ } else {
387
+ nodeTypes = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name;
388
+ hasSelectedMultipleNodes = false;
285
389
  }
286
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.setNodeDragged(getPos, anchorName, nodeType)({
390
+ api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.setNodeDragged(getPos, anchorName, nodeType)({
287
391
  tr: tr
288
392
  });
289
393
  tr.setMeta('scrollIntoView', false);
@@ -305,7 +409,7 @@ export var DragHandle = function DragHandle(_ref) {
305
409
  view.focus();
306
410
  }
307
411
  });
308
- }, [anchorName, api, getPos, nodeType, start, view]);
412
+ }, [anchorName, api, getPos, isMultiSelect, nodeType, start, view]);
309
413
  var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
310
414
  var calculatePosition = useCallback(function () {
311
415
  var parentNodeType;
@@ -390,14 +494,11 @@ export var DragHandle = function DragHandle(_ref) {
390
494
  }
391
495
  }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
392
496
  useEffect(function () {
393
- var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
394
- exposure: true
395
- });
396
497
  if (!isMultiSelect || typeof start !== 'number' || !selection) {
397
498
  return;
398
499
  }
399
- setDragHandleSelected(isHandleInSelection(view.state, selection, start));
400
- }, [start, selection, view.state]);
500
+ setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
501
+ }, [start, selection, view.state, isMultiSelect]);
401
502
  var helpDescriptors = isTopLevelNode && fg('platform_editor_advanced_layouts_accessibility') ? [{
402
503
  description: formatMessage(blockControlsMessages.dragToMove)
403
504
  }, {
@@ -423,7 +524,12 @@ export var DragHandle = function DragHandle(_ref) {
423
524
  }];
424
525
  var isParentNodeOfTypeLayout;
425
526
  if (!isTopLevelNode && (fg('platform_editor_advanced_layouts_accessibility') || handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused) && editorExperiment('nested-dnd', true)) {
426
- isParentNodeOfTypeLayout = nodeType === 'layoutSection' || view.state.doc.resolve(getNestedNodePosition(view.state)).node().type.name === 'layoutColumn';
527
+ var pos = getPos();
528
+ if (typeof pos === 'number') {
529
+ var _$pos$parent;
530
+ var $pos = view.state.doc.resolve(pos);
531
+ isParentNodeOfTypeLayout = ($pos === null || $pos === void 0 || (_$pos$parent = $pos.parent) === null || _$pos$parent === void 0 ? void 0 : _$pos$parent.type.name) === 'layoutColumn';
532
+ }
427
533
  if (isParentNodeOfTypeLayout) {
428
534
  helpDescriptors = [].concat(_toConsumableArray(helpDescriptors), [{
429
535
  description: formatMessage(blockControlsMessages.moveLeft),
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import { browser } from '@atlaskit/editor-common/browser';
2
3
  import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { B200, N20, N30 } from '@atlaskit/theme/colors';
@@ -15,14 +16,8 @@ var previewStyleOld = {
15
16
  borderWidth: "var(--ds-border-width-outline, 2px)",
16
17
  backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
17
18
  };
18
- export var dragPreview = function dragPreview(container, dom, nodeType) {
19
+ var getPreviewContainerDimensionsForSingle = function getPreviewContainerDimensionsForSingle(dom, nodeType) {
19
20
  var nodeContainer = dom;
20
- container.style.pointerEvents = 'none';
21
- var parent = document.createElement('div');
22
- // ProseMirror class is required to make sure the cloned dom is styled correctly
23
- parent.classList.add('ProseMirror', 'block-ctrl-drag-preview');
24
- var embedCard = dom.querySelector('.embedCardView-content-wrap');
25
- var shouldBeGenericPreview = nodeType === 'embedCard' || nodeType === 'extension' || !!embedCard;
26
21
  if (fg('platform_editor_elements_drag_and_drop_ed_23189')) {
27
22
  var iframeContainer = dom.querySelector('iframe');
28
23
  if (nodeType === 'embedCard') {
@@ -30,41 +25,94 @@ export var dragPreview = function dragPreview(container, dom, nodeType) {
30
25
  } else if (nodeType === 'extension' && iframeContainer) {
31
26
  nodeContainer = iframeContainer;
32
27
  }
33
- shouldBeGenericPreview = nodeType === 'embedCard' || !!embedCard || nodeType === 'extension' && !!iframeContainer;
34
28
  }
35
29
  var nodeContainerRect = nodeContainer.getBoundingClientRect();
36
- container.style.width = "".concat(nodeContainerRect.width, "px");
37
- container.style.height = "".concat(nodeContainerRect.height, "px");
30
+ return {
31
+ width: nodeContainerRect.width,
32
+ height: nodeContainerRect.height
33
+ };
34
+ };
35
+ var getPreviewContainerDimensions = function getPreviewContainerDimensions(dragPreviewContent) {
36
+ var maxWidth = 0;
37
+ var heightSum = 0;
38
+ for (var index = 0; index < dragPreviewContent.length; index++) {
39
+ var element = dragPreviewContent[index];
40
+ var _getPreviewContainerD = getPreviewContainerDimensionsForSingle(element.dom, element.nodeType),
41
+ width = _getPreviewContainerD.width,
42
+ height = _getPreviewContainerD.height;
43
+ if (width > maxWidth) {
44
+ maxWidth = width;
45
+ }
46
+ heightSum += height;
47
+ }
48
+ return {
49
+ width: maxWidth,
50
+ height: heightSum
51
+ };
52
+ };
53
+ var createGenericPreview = function createGenericPreview() {
54
+ var generalPreview = document.createElement('div');
55
+ // ProseMirror class is required to make sure the cloned dom is styled correctly
56
+ generalPreview.classList.add('ProseMirror', 'block-ctrl-drag-preview');
38
57
  var previewStyle = fg('platform_editor_elements_drag_and_drop_ed_23189') ? previewStyleNew : previewStyleOld;
58
+ generalPreview.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
59
+ generalPreview.style.borderRadius = previewStyle.borderRadius;
60
+ generalPreview.style.backgroundColor = previewStyle.backgroundColor;
61
+ generalPreview.style.height = '100%';
62
+ generalPreview.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
63
+ return generalPreview;
64
+ };
65
+ var createContentPreviewElement = function createContentPreviewElement(dom, nodeType, nodeSpacing) {
66
+ var contentPreviewOneElement = document.createElement('div');
67
+ contentPreviewOneElement.classList.add('ProseMirror', 'block-ctrl-drag-preview');
68
+ var resizer = dom.querySelector('.resizer-item');
69
+ var clonedDom = resizer && ['mediaSingle', 'table'].includes(nodeType) ?
70
+ // Ignored via go/ees005
71
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
72
+ resizer.cloneNode(true) :
73
+ // Ignored via go/ees005
74
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
75
+ dom.cloneNode(true);
76
+ clonedDom.style.marginLeft = '0';
77
+ clonedDom.style.marginTop = nodeSpacing ? "".concat(nodeSpacing.top) : '0';
78
+ clonedDom.style.marginRight = '0';
79
+ clonedDom.style.marginBottom = nodeSpacing ? "".concat(nodeSpacing.bottom) : '0';
80
+ clonedDom.style.boxShadow = 'none';
81
+ clonedDom.style.opacity = browser.windows ? '1' : fg('platform_editor_elements_drag_and_drop_ed_23189') ? '0.31' : '0.4';
82
+ contentPreviewOneElement.appendChild(clonedDom);
83
+ return contentPreviewOneElement;
84
+ };
85
+ var isGenericPreview = function isGenericPreview(dom, nodeType) {
86
+ var embedCard = dom.querySelector('.embedCardView-content-wrap');
87
+ return fg('platform_editor_elements_drag_and_drop_ed_23189') ? nodeType === 'embedCard' || !!embedCard || nodeType === 'extension' && !!dom.querySelector('iframe') : nodeType === 'embedCard' || !!embedCard || nodeType === 'extension';
88
+ };
89
+ var createPreviewForElement = function createPreviewForElement(dom, nodeType, nodeSpacing) {
90
+ var shouldBeGenericPreview = isGenericPreview(dom, nodeType);
39
91
  if (shouldBeGenericPreview) {
40
- parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
41
- parent.style.borderRadius = previewStyle.borderRadius;
42
- parent.style.backgroundColor = previewStyle.backgroundColor;
43
- parent.style.height = '100%';
44
- parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
92
+ return createGenericPreview();
45
93
  } else {
46
- var resizer = dom.querySelector('.resizer-item');
47
- var clonedDom = resizer && ['mediaSingle', 'table'].includes(nodeType) ?
48
- // Ignored via go/ees005
49
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
50
- resizer.cloneNode(true) :
51
- // Ignored via go/ees005
52
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
53
- dom.cloneNode(true);
54
-
55
- // Remove any margin from the cloned element to ensure is doesn't position incorrectly
56
- clonedDom.style.marginLeft = '0';
57
- clonedDom.style.marginTop = '0';
58
- clonedDom.style.marginRight = '0';
59
- clonedDom.style.marginBottom = '0';
60
- clonedDom.style.boxShadow = 'none';
61
- clonedDom.style.opacity = browser.windows ? '1' : fg('platform_editor_elements_drag_and_drop_ed_23189') ? '0.31' : '0.4';
62
- parent.appendChild(clonedDom);
94
+ return createContentPreviewElement(dom, nodeType, nodeSpacing);
95
+ }
96
+ };
97
+ export var dragPreview = function dragPreview(container, dragPreviewContent) {
98
+ container.style.pointerEvents = 'none';
99
+ if (!Array.isArray(dragPreviewContent) && _typeof(dragPreviewContent) === 'object') {
100
+ dragPreviewContent = [dragPreviewContent];
101
+ }
102
+ var _getPreviewContainerD2 = getPreviewContainerDimensions(dragPreviewContent),
103
+ maxWidth = _getPreviewContainerD2.width,
104
+ maxHeight = _getPreviewContainerD2.height;
105
+ container.style.width = "".concat(maxWidth, "px");
106
+ container.style.height = "".concat(maxHeight, "px");
107
+ var previewWrapperFragment = document.createDocumentFragment();
108
+ for (var index = 0; index < dragPreviewContent.length; index++) {
109
+ var element = dragPreviewContent[index];
110
+ var contentPreviewOneElement = createPreviewForElement(element.dom, element.nodeType, element.nodeSpacing);
111
+ previewWrapperFragment.appendChild(contentPreviewOneElement);
63
112
  }
64
- container.appendChild(parent);
113
+ container.appendChild(previewWrapperFragment);
65
114
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
66
115
  var scrollParentClassNames = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent.className;
67
-
68
116
  // Add the scroll parent class to the container to ensure the cloned element is styled correctly
69
117
  container.className = scrollParentClassNames || '';
70
118
  container.classList.remove('fabric-editor-popup-scroll-parent');
@@ -86,6 +86,9 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
86
86
  }) => EditorCommand;
87
87
  moveNode: MoveNode;
88
88
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
89
+ toggleBlockMenu: (options?: {
90
+ closeMenu?: boolean;
91
+ }) => EditorCommand;
89
92
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
90
93
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
91
94
  };
@@ -1,10 +1,10 @@
1
1
  import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { EditorState, NodeSelection, TextSelection, type Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
@@ -14,6 +14,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
14
14
  * @param handlePos
15
15
  * @returns
16
16
  */
17
- export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
17
+ export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
18
18
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
19
19
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
@@ -17,4 +17,4 @@ export declare const transformExpandToNestedExpand: (expandNode: PMNode) => PMNo
17
17
  export declare const transformSliceExpandToNestedExpand: (slice: Slice) => Slice | null;
18
18
  export declare const memoizedTransformExpandToNestedExpand: import("memoize-one").MemoizedFn<(node: PMNode) => PMNode | null>;
19
19
  export declare function canMoveNodeToIndex(destParent: PMNode, indexIntoParent: number, srcNode: PMNode, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
- export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, doc: PMNode, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
+ export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import type { IntlShape } from 'react-intl-next';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
8
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
9
+ export declare const getBlockMenuItems: (formatMessage: IntlShape['formatMessage']) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export declare const menuItemsCallback: {
13
+ moveUp: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
14
+ moveDown: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
15
+ copy: () => void;
16
+ delete: () => void;
17
+ };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
5
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
6
+ type BlockMenuProps = {
7
+ editorView: EditorView | undefined;
8
+ mountPoint?: HTMLElement;
9
+ boundariesElement?: HTMLElement;
10
+ scrollableElement?: HTMLElement;
11
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
12
+ };
13
+ declare const _default: React.FC<import("react-intl-next").WithIntlProps<BlockMenuProps & WrappedComponentProps>> & {
14
+ WrappedComponent: React.ComponentType<BlockMenuProps & WrappedComponentProps>;
15
+ };
16
+ export default _default;
@@ -29,6 +29,12 @@ export declare const dropTargetMarginMap: {
29
29
  export declare const spaceLookupMap: {
30
30
  [k: string]: string;
31
31
  };
32
+ export declare const spacingBetweenNodesForPreview: {
33
+ [key: string]: {
34
+ top: string;
35
+ bottom: string;
36
+ };
37
+ };
32
38
  export declare const nodeMargins: {
33
39
  [key: string]: {
34
40
  top: number;
@@ -38,3 +44,4 @@ export declare const nodeMargins: {
38
44
  export declare const DEFAULT_COLUMN_DISTRIBUTIONS: {
39
45
  [key: number]: number;
40
46
  };
47
+ export declare const BLOCK_MENU_WIDTH = 220;
@@ -1 +1,9 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
1
+ export type DragPreviewContent = {
2
+ dom: HTMLElement;
3
+ nodeType: string;
4
+ nodeSpacing?: {
5
+ top: string;
6
+ bottom: string;
7
+ };
8
+ };
9
+ export declare const dragPreview: (container: HTMLElement, dragPreviewContent: DragPreviewContent | DragPreviewContent[]) => () => HTMLElement;
@@ -86,6 +86,9 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
86
86
  }) => EditorCommand;
87
87
  moveNode: MoveNode;
88
88
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
89
+ toggleBlockMenu: (options?: {
90
+ closeMenu?: boolean;
91
+ }) => EditorCommand;
89
92
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
90
93
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
91
94
  };
@@ -1,10 +1,10 @@
1
1
  import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { EditorState, NodeSelection, TextSelection, type Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
@@ -14,6 +14,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
14
14
  * @param handlePos
15
15
  * @returns
16
16
  */
17
- export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
17
+ export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
18
18
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
19
19
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
@@ -17,4 +17,4 @@ export declare const transformExpandToNestedExpand: (expandNode: PMNode) => PMNo
17
17
  export declare const transformSliceExpandToNestedExpand: (slice: Slice) => Slice | null;
18
18
  export declare const memoizedTransformExpandToNestedExpand: import("memoize-one").MemoizedFn<(node: PMNode) => PMNode | null>;
19
19
  export declare function canMoveNodeToIndex(destParent: PMNode, indexIntoParent: number, srcNode: PMNode, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
- export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, doc: PMNode, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
+ export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import type { IntlShape } from 'react-intl-next';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
8
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
9
+ export declare const getBlockMenuItems: (formatMessage: IntlShape['formatMessage']) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export declare const menuItemsCallback: {
13
+ moveUp: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
14
+ moveDown: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
15
+ copy: () => void;
16
+ delete: () => void;
17
+ };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
5
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
6
+ type BlockMenuProps = {
7
+ editorView: EditorView | undefined;
8
+ mountPoint?: HTMLElement;
9
+ boundariesElement?: HTMLElement;
10
+ scrollableElement?: HTMLElement;
11
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
12
+ };
13
+ declare const _default: React.FC<import("react-intl-next").WithIntlProps<BlockMenuProps & WrappedComponentProps>> & {
14
+ WrappedComponent: React.ComponentType<BlockMenuProps & WrappedComponentProps>;
15
+ };
16
+ export default _default;
@@ -29,6 +29,12 @@ export declare const dropTargetMarginMap: {
29
29
  export declare const spaceLookupMap: {
30
30
  [k: string]: string;
31
31
  };
32
+ export declare const spacingBetweenNodesForPreview: {
33
+ [key: string]: {
34
+ top: string;
35
+ bottom: string;
36
+ };
37
+ };
32
38
  export declare const nodeMargins: {
33
39
  [key: string]: {
34
40
  top: number;
@@ -38,3 +44,4 @@ export declare const nodeMargins: {
38
44
  export declare const DEFAULT_COLUMN_DISTRIBUTIONS: {
39
45
  [key: number]: number;
40
46
  };
47
+ export declare const BLOCK_MENU_WIDTH = 220;
@@ -1 +1,9 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
1
+ export type DragPreviewContent = {
2
+ dom: HTMLElement;
3
+ nodeType: string;
4
+ nodeSpacing?: {
5
+ top: string;
6
+ bottom: string;
7
+ };
8
+ };
9
+ export declare const dragPreview: (container: HTMLElement, dragPreviewContent: DragPreviewContent | DragPreviewContent[]) => () => HTMLElement;