@atlaskit/editor-plugin-block-controls 2.6.2 → 2.7.0

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 (60) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/commands/move-to-layout.js +76 -0
  3. package/dist/cjs/consts.js +3 -2
  4. package/dist/cjs/plugin.js +3 -12
  5. package/dist/cjs/pm-plugins/decorations.js +15 -11
  6. package/dist/cjs/pm-plugins/handle-mouse-over.js +2 -12
  7. package/dist/cjs/pm-plugins/main.js +14 -18
  8. package/dist/cjs/ui/consts.js +8 -1
  9. package/dist/cjs/ui/drop-target-v2.js +24 -17
  10. package/dist/cjs/ui/inline-drop-target.js +138 -0
  11. package/dist/cjs/utils/advanced-layouts-flags.js +11 -0
  12. package/dist/cjs/utils/anchor-utils.js +71 -15
  13. package/dist/cjs/utils/inline-drop-target.js +18 -0
  14. package/dist/es2019/commands/move-to-layout.js +69 -0
  15. package/dist/es2019/consts.js +2 -1
  16. package/dist/es2019/plugin.js +2 -10
  17. package/dist/es2019/pm-plugins/decorations.js +15 -11
  18. package/dist/es2019/pm-plugins/handle-mouse-over.js +2 -12
  19. package/dist/es2019/pm-plugins/main.js +15 -21
  20. package/dist/es2019/ui/consts.js +7 -0
  21. package/dist/es2019/ui/drop-target-v2.js +24 -16
  22. package/dist/es2019/ui/inline-drop-target.js +130 -0
  23. package/dist/es2019/utils/advanced-layouts-flags.js +5 -0
  24. package/dist/es2019/utils/anchor-utils.js +55 -9
  25. package/dist/es2019/utils/inline-drop-target.js +12 -0
  26. package/dist/esm/commands/move-to-layout.js +70 -0
  27. package/dist/esm/consts.js +2 -1
  28. package/dist/esm/plugin.js +3 -12
  29. package/dist/esm/pm-plugins/decorations.js +15 -11
  30. package/dist/esm/pm-plugins/handle-mouse-over.js +2 -12
  31. package/dist/esm/pm-plugins/main.js +15 -19
  32. package/dist/esm/ui/consts.js +7 -0
  33. package/dist/esm/ui/drop-target-v2.js +24 -17
  34. package/dist/esm/ui/inline-drop-target.js +130 -0
  35. package/dist/esm/utils/advanced-layouts-flags.js +5 -0
  36. package/dist/esm/utils/anchor-utils.js +70 -14
  37. package/dist/esm/utils/inline-drop-target.js +12 -0
  38. package/dist/types/commands/move-to-layout.d.ts +3 -0
  39. package/dist/types/consts.d.ts +1 -0
  40. package/dist/types/pm-plugins/decorations.d.ts +3 -3
  41. package/dist/types/pm-plugins/main.d.ts +3 -4
  42. package/dist/types/types.d.ts +1 -1
  43. package/dist/types/ui/consts.d.ts +3 -0
  44. package/dist/types/ui/drop-target-v2.d.ts +3 -3
  45. package/dist/types/ui/inline-drop-target.d.ts +20 -0
  46. package/dist/types/utils/advanced-layouts-flags.d.ts +1 -0
  47. package/dist/types/utils/anchor-utils.d.ts +16 -3
  48. package/dist/types/utils/inline-drop-target.d.ts +2 -0
  49. package/dist/types-ts4.5/commands/move-to-layout.d.ts +3 -0
  50. package/dist/types-ts4.5/consts.d.ts +1 -0
  51. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +3 -3
  52. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -4
  53. package/dist/types-ts4.5/types.d.ts +1 -1
  54. package/dist/types-ts4.5/ui/consts.d.ts +3 -0
  55. package/dist/types-ts4.5/ui/drop-target-v2.d.ts +3 -3
  56. package/dist/types-ts4.5/ui/inline-drop-target.d.ts +20 -0
  57. package/dist/types-ts4.5/utils/advanced-layouts-flags.d.ts +1 -0
  58. package/dist/types-ts4.5/utils/anchor-utils.d.ts +16 -3
  59. package/dist/types-ts4.5/utils/inline-drop-target.d.ts +2 -0
  60. package/package.json +8 -5
@@ -12,7 +12,7 @@ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-sc
12
12
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
13
13
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
14
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
- import { AnchorHeightsCache, isAnchorSupported } from '../utils/anchor-utils';
15
+ import { AnchorRectCache, isAnchorSupported } from '../utils/anchor-utils';
16
16
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
17
17
  import { getTrMetadata } from '../utils/transactions';
18
18
  import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, findDropTargetDecs, findHandleDec, findNodeDecs, nodeDecorations } from './decorations';
@@ -88,9 +88,8 @@ var initialState = {
88
88
  isDocSizeLimitEnabled: null,
89
89
  isPMDragging: false
90
90
  };
91
- export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache) {
91
+ export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache) {
92
92
  var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
93
- var isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
94
93
  var activeNode = currentState.activeNode,
95
94
  decorations = currentState.decorations,
96
95
  editorHeight = currentState.editorHeight,
@@ -170,7 +169,7 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
170
169
  var shouldRecreateHandle = latestActiveNode && (activeNodeChanged || isActiveNodeModified || editorSizeChanged || handleNeedsRedraw);
171
170
 
172
171
  // Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
173
- var shouldRemoveHandle = latestActiveNode && ((meta === null || meta === void 0 ? void 0 : meta.hideDragHandle) && isTitleEnterImprovementEnabled || isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
172
+ var shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
174
173
  if (shouldRemoveHandle) {
175
174
  var _activeNode3, _activeNode4;
176
175
  var oldHandle = findHandleDec(decorations, (_activeNode3 = activeNode) === null || _activeNode3 === void 0 ? void 0 : _activeNode3.pos, (_activeNode4 = activeNode) === null || _activeNode4 === void 0 ? void 0 : _activeNode4.pos);
@@ -195,7 +194,7 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
195
194
  // Add drop targets when dragging starts or some are missing
196
195
  if (api) {
197
196
  if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || isBlocksDragTargetDebug()) {
198
- var decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorHeightsCache);
197
+ var decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorRectCache);
199
198
  decorations = decorations.add(newState.doc, decs);
200
199
  }
201
200
  }
@@ -220,10 +219,9 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
220
219
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
221
220
  };
222
221
  };
223
- export var oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache) {
222
+ export var oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache) {
224
223
  var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
225
- var isNestedEnabled = flags.isNestedEnabled,
226
- isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
224
+ var isNestedEnabled = flags.isNestedEnabled;
227
225
  var activeNode = currentState.activeNode,
228
226
  decorations = currentState.decorations,
229
227
  isMenuOpen = currentState.isMenuOpen,
@@ -258,7 +256,7 @@ export var oldApply = function oldApply(api, formatMessage, tr, currentState, ol
258
256
  // During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
259
257
  // Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
260
258
  // Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
261
- if (meta !== null && meta !== void 0 && meta.hideDragHandle && isTitleEnterImprovementEnabled || isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
259
+ if (isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
262
260
  var oldHandle = decorations.find(undefined, undefined, function (spec) {
263
261
  return spec.type === 'drag-handle';
264
262
  });
@@ -384,7 +382,7 @@ export var oldApply = function oldApply(api, formatMessage, tr, currentState, ol
384
382
  // if the transaction is only for analytics and user is dragging, continue to draw drop targets
385
383
  if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
386
384
  var _meta$activeNode7;
387
- var _decs2 = 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, anchorHeightsCache);
385
+ var _decs2 = 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);
388
386
  decorations = decorations.add(newState.doc, _decs2);
389
387
  }
390
388
  }
@@ -422,18 +420,16 @@ export var createPlugin = function createPlugin(api, getIntl) {
422
420
  var isOptimisedApply = isNestedEnabled && editorExperiment('optimised-apply-dnd', true, {
423
421
  exposure: true
424
422
  });
425
- var isTitleEnterImprovementEnabled = fg('confluence_frontend_page_title_enter_improvements');
426
423
  var flags = {
427
424
  isNestedEnabled: isNestedEnabled,
428
- isOptimisedApply: isOptimisedApply,
429
- isTitleEnterImprovementEnabled: isTitleEnterImprovementEnabled
425
+ isOptimisedApply: isOptimisedApply
430
426
  };
431
427
  if (fg('platform_editor_element_dnd_nested_fix_patch_2')) {
432
428
  // TODO: Remove this once FG is used in code
433
429
  }
434
- var anchorHeightsCache;
430
+ var anchorRectCache;
435
431
  if (!isAnchorSupported() && fg('platform_editor_drag_and_drop_target_v2')) {
436
- anchorHeightsCache = new AnchorHeightsCache();
432
+ anchorRectCache = new AnchorRectCache();
437
433
  }
438
434
  return new SafePlugin({
439
435
  key: key,
@@ -443,9 +439,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
443
439
  },
444
440
  apply: function apply(tr, currentState, oldState, newState) {
445
441
  if (isOptimisedApply) {
446
- return newApply(api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache);
442
+ return newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache);
447
443
  }
448
- return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache);
444
+ return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache);
449
445
  }
450
446
  },
451
447
  props: {
@@ -495,8 +491,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
495
491
  return false;
496
492
  },
497
493
  dragstart: function dragstart(view) {
498
- var _anchorHeightsCache;
499
- (_anchorHeightsCache = anchorHeightsCache) === null || _anchorHeightsCache === void 0 || _anchorHeightsCache.setEditorView(view);
494
+ var _anchorRectCache;
495
+ (_anchorRectCache = anchorRectCache) === null || _anchorRectCache === void 0 || _anchorRectCache.setEditorView(view);
500
496
  view.dispatch(view.state.tr.setMeta(key, {
501
497
  isPMDragging: true
502
498
  }));
@@ -159,4 +159,11 @@ export var nodeMargins = {
159
159
  top: 0,
160
160
  bottom: 0
161
161
  }
162
+ };
163
+ export var DEFAULT_COLUMN_DISTRIBUTIONS = {
164
+ 1: 100,
165
+ 2: 50,
166
+ 3: 33.33,
167
+ 4: 25,
168
+ 5: 20
162
169
  };
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  /**
@@ -16,7 +17,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
16
17
  import { getNodeAnchor } from '../pm-plugins/decorations';
17
18
  import { isAnchorSupported } from '../utils/anchor-utils';
18
19
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
20
+ import { shouldAllowInlineDropTarget } from '../utils/inline-drop-target';
19
21
  import { getNestedNodeLeftPaddingMargin } from './consts';
22
+ import { InlineDropTarget } from './inline-drop-target';
20
23
  var DEFAULT_DROP_INDICATOR_WIDTH = 760;
21
24
  var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
22
25
  var EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
@@ -72,7 +75,7 @@ var HoverZone = function HoverZone(_ref) {
72
75
  node = _ref.node,
73
76
  parent = _ref.parent,
74
77
  editorWidth = _ref.editorWidth,
75
- anchorHeightsCache = _ref.anchorHeightsCache,
78
+ anchorRectCache = _ref.anchorRectCache,
76
79
  position = _ref.position,
77
80
  isNestedDropTarget = _ref.isNestedDropTarget,
78
81
  dropTargetStyle = _ref.dropTargetStyle;
@@ -91,7 +94,7 @@ var HoverZone = function HoverZone(_ref) {
91
94
  var anchorName = node ? getNodeAnchor(node) : '';
92
95
  var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
93
96
  var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
94
- var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((anchorHeightsCache === null || anchorHeightsCache === void 0 ? void 0 : anchorHeightsCache.getHeight(anchorName)) || 0) / 2, "px + ").concat(heightStyleOffset, ")") : '4px';
97
+ var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? 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';
95
98
  var transform = position === 'upper' ? "translateY(calc(-100% + ".concat(transformOffset, "))") : "translateY(".concat(transformOffset, ")");
96
99
  return css({
97
100
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
@@ -101,7 +104,7 @@ var HoverZone = function HoverZone(_ref) {
101
104
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
102
105
  maxWidth: "".concat(editorWidth || 0, "px")
103
106
  });
104
- }, [anchorHeightsCache, editorWidth, node, position]);
107
+ }, [anchorRectCache, editorWidth, node, position]);
105
108
  var isFullHeight = useMemo(function () {
106
109
  return dropTargetStyle === 'fullHeight';
107
110
  }, [dropTargetStyle]);
@@ -121,16 +124,16 @@ var HoverZone = function HoverZone(_ref) {
121
124
  hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
122
125
  });
123
126
  };
124
- export var DropTargetV2 = function DropTargetV2(_ref2) {
127
+ export var DropTargetV2 = function DropTargetV2(props) {
125
128
  var _dynamicStyle;
126
- var api = _ref2.api,
127
- getPos = _ref2.getPos,
128
- prevNode = _ref2.prevNode,
129
- nextNode = _ref2.nextNode,
130
- parentNode = _ref2.parentNode,
131
- formatMessage = _ref2.formatMessage,
132
- anchorHeightsCache = _ref2.anchorHeightsCache,
133
- dropTargetStyle = _ref2.dropTargetStyle;
129
+ var api = props.api,
130
+ getPos = props.getPos,
131
+ prevNode = props.prevNode,
132
+ nextNode = props.nextNode,
133
+ parentNode = props.parentNode,
134
+ formatMessage = props.formatMessage,
135
+ anchorRectCache = props.anchorRectCache,
136
+ dropTargetStyle = props.dropTargetStyle;
134
137
  var _useState = useState(false),
135
138
  _useState2 = _slicedToArray(_useState, 2),
136
139
  isDraggedOver = _useState2[0],
@@ -140,8 +143,8 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
140
143
  var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
141
144
  var onDrop = function onDrop() {
142
145
  var _api$blockControls;
143
- var _ref3 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
144
- activeNode = _ref3.activeNode;
146
+ var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
147
+ activeNode = _ref2.activeNode;
145
148
  if (!activeNode) {
146
149
  return;
147
150
  }
@@ -166,7 +169,7 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
166
169
  onDrop: onDrop,
167
170
  node: prevNode,
168
171
  editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
169
- anchorHeightsCache: anchorHeightsCache,
172
+ anchorRectCache: anchorRectCache,
170
173
  position: "upper",
171
174
  isNestedDropTarget: isNestedDropTarget
172
175
  }), jsx("div", {
@@ -194,9 +197,13 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
194
197
  node: nextNode,
195
198
  parent: parentNode,
196
199
  editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
197
- anchorHeightsCache: anchorHeightsCache,
200
+ anchorRectCache: anchorRectCache,
198
201
  position: "lower",
199
202
  isNestedDropTarget: isNestedDropTarget,
200
203
  dropTargetStyle: dropTargetStyle
201
- }));
204
+ }), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode) && jsx(Fragment, null, jsx(InlineDropTarget, _extends({}, props, {
205
+ position: "left"
206
+ })), jsx(InlineDropTarget, _extends({}, props, {
207
+ position: "right"
208
+ }))));
202
209
  };
@@ -0,0 +1,130 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
3
+ /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
4
+ /**
5
+ * @jsxRuntime classic
6
+ * @jsx jsx
7
+ */
8
+ import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
+
10
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
11
+ import { css, jsx } from '@emotion/react';
12
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
+ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
14
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
+ import { getNodeAnchor } from '../pm-plugins/decorations';
16
+ import { isAnchorSupported } from '../utils/anchor-utils';
17
+ var dropTargetCommonStyle = css({
18
+ position: 'absolute',
19
+ display: 'block'
20
+ });
21
+ var hideDropTargetStyle = css({
22
+ display: 'none'
23
+ });
24
+ var hoverZoneCommonStyle = css({
25
+ position: 'absolute',
26
+ // same value as block hover zone
27
+ zIndex: 110
28
+ });
29
+
30
+ // gap between node boundary and drop indicator/drop zone
31
+ var GAP = 4;
32
+ var HOVER_ZONE_WIDTH_OFFSET = 40;
33
+ var HOVER_ZONE_HEIGHT_OFFSET = 10;
34
+ var HOVER_ZONE_DEFAULT_WIDTH = 40;
35
+ export var InlineDropTarget = function InlineDropTarget(_ref) {
36
+ var api = _ref.api,
37
+ nextNode = _ref.nextNode,
38
+ position = _ref.position,
39
+ anchorRectCache = _ref.anchorRectCache;
40
+ var _useSharedPluginState = useSharedPluginState(api, ['width']),
41
+ widthState = _useSharedPluginState.widthState;
42
+ var _useState = useState(false),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ isDraggedOver = _useState2[0],
45
+ setIsDraggedOver = _useState2[1];
46
+ var anchorName = nextNode ? getNodeAnchor(nextNode) : '';
47
+ var handleDragEnter = useCallback(function () {
48
+ setIsDraggedOver(true);
49
+ }, []);
50
+ var handleDragLeave = useCallback(function () {
51
+ setIsDraggedOver(false);
52
+ }, []);
53
+ var dropTargetRectStyle = useMemo(function () {
54
+ if (isAnchorSupported()) {
55
+ return css({
56
+ height: "calc(anchor-size(".concat(anchorName, " height))"),
57
+ positionAnchor: anchorName,
58
+ left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
59
+ top: "calc(anchor(top))"
60
+ });
61
+ }
62
+ var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
63
+ return css({
64
+ height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
65
+ 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"),
66
+ top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
67
+ });
68
+ }, [anchorName, anchorRectCache, position]);
69
+ return jsx(Fragment, null, jsx("div", {
70
+ "data-test-id": "block-ctrl-drop-target-".concat(position),
71
+ css: [dropTargetCommonStyle, dropTargetRectStyle, !isDraggedOver && hideDropTargetStyle]
72
+ }, jsx(DropIndicator, {
73
+ edge: position
74
+ })), jsx(InlineHoverZone, {
75
+ position: position,
76
+ node: nextNode,
77
+ editorWidthState: widthState,
78
+ anchorRectCache: anchorRectCache,
79
+ onDragEnter: handleDragEnter,
80
+ onDragLeave: handleDragLeave,
81
+ onDrop: function onDrop() {}
82
+ }));
83
+ };
84
+ export var InlineHoverZone = function InlineHoverZone(_ref2) {
85
+ var node = _ref2.node,
86
+ editorWidthState = _ref2.editorWidthState,
87
+ anchorRectCache = _ref2.anchorRectCache,
88
+ position = _ref2.position,
89
+ onDragEnter = _ref2.onDragEnter,
90
+ onDragLeave = _ref2.onDragLeave,
91
+ onDrop = _ref2.onDrop;
92
+ var ref = useRef(null);
93
+ var _ref3 = editorWidthState || {},
94
+ editorWith = _ref3.width;
95
+ var anchorName = node ? getNodeAnchor(node) : '';
96
+ useEffect(function () {
97
+ if (ref.current) {
98
+ return dropTargetForElements({
99
+ element: ref.current,
100
+ onDragEnter: onDragEnter,
101
+ onDragLeave: onDragLeave,
102
+ onDrop: onDrop
103
+ });
104
+ }
105
+ }, [onDragEnter, onDragLeave, onDrop]);
106
+ var inlineHoverZoneRectStyle = useMemo(function () {
107
+ if (isAnchorSupported()) {
108
+ return css({
109
+ positionAnchor: anchorName,
110
+ left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
111
+ right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
112
+ top: "calc(anchor(top))",
113
+ width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
114
+ height: "calc(anchor-size(".concat(anchorName, " height))")
115
+ });
116
+ }
117
+ var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
118
+ var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
119
+ return css({
120
+ 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"),
121
+ top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
122
+ width: "".concat(width, "px"),
123
+ height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
124
+ });
125
+ }, [anchorName, anchorRectCache, editorWith, position]);
126
+ return jsx("div", {
127
+ ref: ref,
128
+ css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
129
+ });
130
+ };
@@ -0,0 +1,5 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+ export var isPreRelease1 = function isPreRelease1() {
4
+ return editorExperiment('advanced_layouts', true) || fg('platform_editor_advanced_layouts_pre_release_1');
5
+ };
@@ -11,36 +11,42 @@ export var isAnchorSupported = memoizeOne(function () {
11
11
  }
12
12
  return false;
13
13
  });
14
- export var AnchorHeightsCache = /*#__PURE__*/function () {
15
- function AnchorHeightsCache() {
16
- _classCallCheck(this, AnchorHeightsCache);
17
- _defineProperty(this, "anchorHeightsMap", {});
14
+ export var AnchorRectCache = /*#__PURE__*/function () {
15
+ function AnchorRectCache() {
16
+ _classCallCheck(this, AnchorRectCache);
17
+ _defineProperty(this, "anchorRectMap", {});
18
18
  _defineProperty(this, "isAnchorSupported", isAnchorSupported());
19
19
  _defineProperty(this, "isDirty", true);
20
20
  _defineProperty(this, "view", null);
21
21
  }
22
- _createClass(AnchorHeightsCache, [{
22
+ _createClass(AnchorRectCache, [{
23
23
  key: "clear",
24
24
  value: function clear() {
25
25
  this.isDirty = true;
26
- this.anchorHeightsMap = {};
26
+ this.anchorRectMap = {};
27
27
  }
28
28
  }, {
29
- key: "getHeights",
30
- value: function getHeights() {
29
+ key: "getRects",
30
+ value: function getRects() {
31
31
  if (this.isDirty) {
32
32
  var _this$view;
33
33
  var anchorElements = ((_this$view = this.view) === null || _this$view === void 0 ? void 0 : _this$view.dom.querySelectorAll('[data-drag-handler-anchor-name]')) || [];
34
- this.anchorHeightsMap = Array.from(anchorElements).reduce(function (prev, curr) {
34
+ this.anchorRectMap = Array.from(anchorElements).reduce(function (prev, curr) {
35
35
  var anchorName = curr.getAttribute('data-drag-handler-anchor-name');
36
36
  if (anchorName) {
37
- return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, anchorName, curr.clientHeight));
37
+ return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, anchorName, {
38
+ height: curr.clientHeight,
39
+ top: curr.offsetTop,
40
+ left: curr.offsetLeft,
41
+ right: curr.offsetLeft + curr.clientWidth,
42
+ width: curr.clientWidth
43
+ }));
38
44
  }
39
45
  return prev;
40
46
  }, {});
41
47
  this.isDirty = false;
42
48
  }
43
- return this.anchorHeightsMap;
49
+ return this.anchorRectMap;
44
50
  }
45
51
  }, {
46
52
  key: "setEditorView",
@@ -52,12 +58,62 @@ export var AnchorHeightsCache = /*#__PURE__*/function () {
52
58
  }, {
53
59
  key: "getHeight",
54
60
  value: function getHeight(anchorName) {
61
+ var _rects$anchorName;
55
62
  if (this.isAnchorSupported) {
56
63
  return null;
57
64
  }
58
- var heights = this.getHeights();
59
- return heights[anchorName];
65
+ var rects = this.getRects();
66
+ return (_rects$anchorName = rects[anchorName]) === null || _rects$anchorName === void 0 ? void 0 : _rects$anchorName.height;
67
+ }
68
+ }, {
69
+ key: "getWidth",
70
+ value: function getWidth(anchorName) {
71
+ var _rects$anchorName2;
72
+ if (this.isAnchorSupported) {
73
+ return null;
74
+ }
75
+ var rects = this.getRects();
76
+ return (_rects$anchorName2 = rects[anchorName]) === null || _rects$anchorName2 === void 0 ? void 0 : _rects$anchorName2.width;
77
+ }
78
+ }, {
79
+ key: "getLeft",
80
+ value: function getLeft(anchorName) {
81
+ var _rects$anchorName3;
82
+ if (this.isAnchorSupported) {
83
+ return null;
84
+ }
85
+ var rects = this.getRects();
86
+ return (_rects$anchorName3 = rects[anchorName]) === null || _rects$anchorName3 === void 0 ? void 0 : _rects$anchorName3.left;
87
+ }
88
+ }, {
89
+ key: "getTop",
90
+ value: function getTop(anchorName) {
91
+ var _rects$anchorName4;
92
+ if (this.isAnchorSupported) {
93
+ return null;
94
+ }
95
+ var rects = this.getRects();
96
+ return (_rects$anchorName4 = rects[anchorName]) === null || _rects$anchorName4 === void 0 ? void 0 : _rects$anchorName4.top;
97
+ }
98
+ }, {
99
+ key: "getRight",
100
+ value: function getRight(anchorName) {
101
+ var _rects$anchorName5;
102
+ if (this.isAnchorSupported) {
103
+ return null;
104
+ }
105
+ var rects = this.getRects();
106
+ return (_rects$anchorName5 = rects[anchorName]) === null || _rects$anchorName5 === void 0 ? void 0 : _rects$anchorName5.right;
107
+ }
108
+ }, {
109
+ key: "getRect",
110
+ value: function getRect(anchorName) {
111
+ if (this.isAnchorSupported) {
112
+ return null;
113
+ }
114
+ var rects = this.getRects();
115
+ return rects[anchorName];
60
116
  }
61
117
  }]);
62
- return AnchorHeightsCache;
118
+ return AnchorRectCache;
63
119
  }();
@@ -0,0 +1,12 @@
1
+ import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
2
+ import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
3
+ import { isPreRelease1 } from './advanced-layouts-flags';
4
+ export var shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
5
+ if (!isPreRelease1() || isNested) {
6
+ return false;
7
+ }
8
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
9
+ return node.childCount < MAX_LAYOUT_COLUMN_SUPPORTED;
10
+ }
11
+ return !isEmptyParagraph(node);
12
+ };
@@ -0,0 +1,3 @@
1
+ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockControlsPlugin } from '../types';
3
+ export declare const moveToLayout: (api?: ExtractInjectionAPI<BlockControlsPlugin>) => (from: number, to: number, position: 'left' | 'right') => EditorCommand;
@@ -4,3 +4,4 @@ export declare enum DIRECTION {
4
4
  LEFT = "left",
5
5
  RIGHT = "right"
6
6
  }
7
+ export declare const MAX_LAYOUT_COLUMN_SUPPORTED = 3;
@@ -5,7 +5,7 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
5
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  import type { ActiveNode, BlockControlsPlugin, HandleOptions } from '../types';
7
7
  import { type DropTargetProps } from '../ui/drop-target';
8
- import { type AnchorHeightsCache } from '../utils/anchor-utils';
8
+ import { type AnchorRectCache } from '../utils/anchor-utils';
9
9
  export declare const TYPE_DROP_TARGET_DEC = "drop-target-decoration";
10
10
  export declare const TYPE_HANDLE_DEC = "drag-handle";
11
11
  export declare const TYPE_NODE_DEC = "node-decoration";
@@ -27,8 +27,8 @@ export declare const findHandleDec: (decorations: DecorationSet, from?: number,
27
27
  * @returns
28
28
  */
29
29
  export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
30
- export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorHeightsCache?: AnchorHeightsCache) => Decoration;
31
- export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorHeightsCache?: AnchorHeightsCache, from?: number, to?: number) => Decoration[];
30
+ export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
31
+ export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
32
32
  export declare const emptyParagraphNodeDecorations: () => Decoration;
33
33
  export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
34
34
  export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -5,14 +5,13 @@ import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemir
5
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { BlockControlsPlugin, PluginState } from '../types';
8
- import { AnchorHeightsCache } from '../utils/anchor-utils';
8
+ import { AnchorRectCache } from '../utils/anchor-utils';
9
9
  export declare const key: PluginKey<PluginState>;
10
10
  export interface FlagType {
11
11
  isNestedEnabled: boolean;
12
12
  isOptimisedApply: boolean;
13
- isTitleEnterImprovementEnabled: boolean;
14
13
  }
15
- export declare const newApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
14
+ export declare const newApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, anchorRectCache?: AnchorRectCache) => {
16
15
  decorations: DecorationSet;
17
16
  activeNode: any;
18
17
  isDragging: any;
@@ -24,7 +23,7 @@ export declare const newApply: (api: ExtractInjectionAPI<BlockControlsPlugin> |
24
23
  isDocSizeLimitEnabled: boolean | null;
25
24
  isPMDragging: any;
26
25
  };
27
- export declare const oldApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, oldState: EditorState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
26
+ export declare const oldApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, oldState: EditorState, newState: EditorState, flags: FlagType, anchorRectCache?: AnchorRectCache) => {
28
27
  decorations: DecorationSet;
29
28
  activeNode: any;
30
29
  isDragging: any;
@@ -58,9 +58,9 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
58
58
  ];
59
59
  sharedState: BlockControlsSharedState;
60
60
  commands: {
61
+ moveToLayout: (start: number, to: number, position: 'left' | 'right') => EditorCommand;
61
62
  moveNode: (start: number, to: number, inputMethod?: MoveNodeMethod, formatMessage?: IntlShape['formatMessage']) => EditorCommand;
62
63
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
63
- hideDragHandle: () => EditorCommand;
64
64
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
65
65
  };
66
66
  }>;
@@ -27,3 +27,6 @@ export declare const nodeMargins: {
27
27
  bottom: number;
28
28
  };
29
29
  };
30
+ export declare const DEFAULT_COLUMN_DISTRIBUTIONS: {
31
+ [key: number]: number;
32
+ };
@@ -1,8 +1,8 @@
1
1
  import { jsx } from '@emotion/react';
2
- import { type AnchorHeightsCache } from '../utils/anchor-utils';
2
+ import { type AnchorRectCache } from '../utils/anchor-utils';
3
3
  import { type DropTargetProps } from './drop-target';
4
4
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-block-controls-drop-indicator-offset";
5
5
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = "--editor-block-controls-drop-indicator-gap";
6
- export declare const DropTargetV2: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, anchorHeightsCache, dropTargetStyle, }: DropTargetProps & {
7
- anchorHeightsCache?: AnchorHeightsCache | undefined;
6
+ export declare const DropTargetV2: (props: DropTargetProps & {
7
+ anchorRectCache?: AnchorRectCache | undefined;
8
8
  }) => jsx.JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { type EditorContainerWidth } from '@atlaskit/editor-common/src/types';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
+ import { type AnchorRectCache } from '../utils/anchor-utils';
5
+ import { type DropTargetProps } from './drop-target';
6
+ export declare const InlineDropTarget: ({ api, nextNode, position, anchorRectCache, }: DropTargetProps & {
7
+ anchorRectCache?: AnchorRectCache | undefined;
8
+ position: 'left' | 'right';
9
+ }) => jsx.JSX.Element;
10
+ type InlineHoverZoneProps = {
11
+ node?: PMNode;
12
+ editorWidthState?: EditorContainerWidth;
13
+ anchorRectCache?: AnchorRectCache;
14
+ position: 'left' | 'right';
15
+ onDragEnter: () => void;
16
+ onDragLeave: () => void;
17
+ onDrop: () => void;
18
+ };
19
+ export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
20
+ export {};
@@ -0,0 +1 @@
1
+ export declare const isPreRelease1: () => boolean;
@@ -1,12 +1,25 @@
1
1
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
2
  export declare const isAnchorSupported: import("memoize-one").MemoizedFn<() => boolean>;
3
- export declare class AnchorHeightsCache {
4
- private anchorHeightsMap;
3
+ type RectInfo = {
4
+ height: number;
5
+ top: number;
6
+ left: number;
7
+ right: number;
8
+ width: number;
9
+ };
10
+ export declare class AnchorRectCache {
11
+ private anchorRectMap;
5
12
  private isAnchorSupported;
6
13
  private isDirty;
7
14
  private view;
8
15
  clear(): void;
9
- private getHeights;
16
+ private getRects;
10
17
  setEditorView(view: EditorView): void;
11
18
  getHeight(anchorName: string): number | null;
19
+ getWidth(anchorName: string): number | null;
20
+ getLeft(anchorName: string): number | null;
21
+ getTop(anchorName: string): number | null;
22
+ getRight(anchorName: string): number | null;
23
+ getRect(anchorName: string): RectInfo | null;
12
24
  }
25
+ export {};