@atlaskit/editor-plugin-block-controls 2.13.9 → 2.13.11

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 (39) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/commands/move-to-layout.js +10 -4
  3. package/dist/cjs/pm-plugins/decorations-anchor.js +12 -4
  4. package/dist/cjs/pm-plugins/decorations-drop-target.js +13 -8
  5. package/dist/cjs/pm-plugins/handle-mouse-over.js +6 -0
  6. package/dist/cjs/ui/drop-target-v2.js +3 -2
  7. package/dist/cjs/ui/global-styles.js +13 -1
  8. package/dist/cjs/ui/inline-drop-target.js +102 -147
  9. package/dist/cjs/utils/inline-drop-target.js +2 -1
  10. package/dist/cjs/utils/validation.js +15 -2
  11. package/dist/es2019/commands/move-to-layout.js +10 -4
  12. package/dist/es2019/pm-plugins/decorations-anchor.js +13 -5
  13. package/dist/es2019/pm-plugins/decorations-drop-target.js +14 -9
  14. package/dist/es2019/pm-plugins/handle-mouse-over.js +7 -1
  15. package/dist/es2019/ui/drop-target-v2.js +3 -2
  16. package/dist/es2019/ui/global-styles.js +13 -1
  17. package/dist/es2019/ui/inline-drop-target.js +102 -150
  18. package/dist/es2019/utils/inline-drop-target.js +7 -3
  19. package/dist/es2019/utils/validation.js +14 -1
  20. package/dist/esm/commands/move-to-layout.js +10 -4
  21. package/dist/esm/pm-plugins/decorations-anchor.js +13 -5
  22. package/dist/esm/pm-plugins/decorations-drop-target.js +14 -9
  23. package/dist/esm/pm-plugins/handle-mouse-over.js +7 -1
  24. package/dist/esm/ui/drop-target-v2.js +3 -2
  25. package/dist/esm/ui/global-styles.js +13 -1
  26. package/dist/esm/ui/inline-drop-target.js +102 -147
  27. package/dist/esm/utils/inline-drop-target.js +3 -2
  28. package/dist/esm/utils/validation.js +14 -1
  29. package/dist/types/pm-plugins/decorations-drop-target.d.ts +1 -1
  30. package/dist/types/ui/drop-target-v2.d.ts +1 -0
  31. package/dist/types/ui/inline-drop-target.d.ts +0 -18
  32. package/dist/types/utils/inline-drop-target.d.ts +1 -1
  33. package/dist/types/utils/validation.d.ts +3 -2
  34. package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +1 -1
  35. package/dist/types-ts4.5/ui/drop-target-v2.d.ts +1 -0
  36. package/dist/types-ts4.5/ui/inline-drop-target.d.ts +0 -18
  37. package/dist/types-ts4.5/utils/inline-drop-target.d.ts +1 -1
  38. package/dist/types-ts4.5/utils/validation.d.ts +3 -2
  39. package/package.json +3 -3
@@ -2,6 +2,7 @@ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
2
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { maxLayoutColumnSupported } from '../consts';
4
4
  import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
5
+ import { isInSameLayout } from '../utils/validation';
5
6
  var createNewLayout = function createNewLayout(schema, layoutContents) {
6
7
  if (layoutContents.length === 0 || layoutContents.length > maxLayoutColumnSupported()) {
7
8
  return null;
@@ -47,8 +48,13 @@ var moveNode = function moveNode(from, to, newNode, sourceNodeSize, tr) {
47
48
  tr.delete(mappedFrom, mappedFromEnd);
48
49
  return tr;
49
50
  };
50
- var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos, sourceNode, from, to, tr) {
51
- if (toLayout.childCount < maxLayoutColumnSupported()) {
51
+ var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos, sourceNode, from, to, tr, isSameLayout) {
52
+ if (isSameLayout) {
53
+ // reorder columns
54
+ tr.delete(from, from + sourceNode.nodeSize);
55
+ var mappedTo = tr.mapping.map(to);
56
+ tr.insert(mappedTo, sourceNode).setSelection(new NodeSelection(tr.doc.resolve(mappedTo))).scrollIntoView();
57
+ } else if (toLayout.childCount < maxLayoutColumnSupported()) {
52
58
  var newColumnWidth = DEFAULT_COLUMN_DISTRIBUTIONS[toLayout.childCount + 1];
53
59
  updateColumnWidths(tr, toLayout, toLayoutPos, newColumnWidth);
54
60
  var _ref2 = tr.doc.type.schema.nodes || {},
@@ -130,12 +136,12 @@ export var moveToLayout = function moveToLayout(api) {
130
136
  }
131
137
  if (toNode.type === layoutSection) {
132
138
  var toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize - 1 : to + 1;
133
- return moveToExistingLayout(toNode, to, fromNodeWithoutBreakout, from, toPos, tr);
139
+ return moveToExistingLayout(toNode, to, fromNodeWithoutBreakout, from, toPos, tr, isInSameLayout($from, $to));
134
140
  } else if (toNode.type === layoutColumn) {
135
141
  var toLayout = $to.parent;
136
142
  var toLayoutPos = to - $to.parentOffset - 1;
137
143
  var _toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize : to;
138
- return moveToExistingLayout(toLayout, toLayoutPos, fromNodeWithoutBreakout, from, _toPos, tr);
144
+ return moveToExistingLayout(toLayout, toLayoutPos, fromNodeWithoutBreakout, from, _toPos, tr, isInSameLayout($from, $to));
139
145
  } else {
140
146
  var toNodeWithoutBreakout = toNode;
141
147
 
@@ -2,11 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
- import { isPreRelease2 } from '../utils/advanced-layouts-flags';
5
+ import { isPreRelease1, isPreRelease2 } from '../utils/advanced-layouts-flags';
6
6
  import { getNestedDepth, getNodeAnchor, TYPE_NODE_DEC } from './decorations-common';
7
7
  var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
8
8
  var IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
9
9
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
10
+ var IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT = ['listItem', 'taskList', 'decisionList'];
10
11
  export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
11
12
  // Optimisation to avoid drawing node decorations for empty table cells
12
13
  if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
@@ -15,13 +16,20 @@ export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
15
16
  return false;
16
17
  }
17
18
  }
19
+ if (isPreRelease1()) {
20
+ return !IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT.includes(node.type.name);
21
+ }
18
22
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
19
23
  };
20
- var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes) {
24
+ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, parent) {
21
25
  var isEmbedCard = 'embedCard' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_3');
22
26
 
23
27
  // TODO use isWrappedMedia when clean up the feature flag
24
28
  var isMediaSingle = 'mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1');
29
+ var isFirstTableHeaderOrTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && ['tableHeader', 'tableRow'].includes(node.type.name) && isPreRelease1();
30
+ if (isFirstTableHeaderOrTableRow) {
31
+ return false;
32
+ }
25
33
  return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
26
34
  };
27
35
 
@@ -59,7 +67,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
59
67
  var docFrom = from === undefined || from < 0 ? 0 : from;
60
68
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
61
69
  var ignore_nodes = isPreRelease2() ? IGNORE_NODES_NEXT : IGNORE_NODES;
62
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
70
+ newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
63
71
  var _Decoration$node;
64
72
  var depth = 0;
65
73
  var anchorName;
@@ -71,10 +79,10 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
71
79
  if (node.isInline) {
72
80
  return false;
73
81
  }
74
- if (shouldIgnoreNode(node, ignore_nodes)) {
82
+ depth = newState.doc.resolve(pos).depth;
83
+ if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
75
84
  return shouldDescend; //skip over, don't consider it a valid depth
76
85
  }
77
- depth = newState.doc.resolve(pos).depth;
78
86
  anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
79
87
  } else {
80
88
  var _anchorName2;
@@ -14,7 +14,7 @@ import { DropTargetLayout } from '../ui/drop-target-layout';
14
14
  import { DropTargetV2, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET } from '../ui/drop-target-v2';
15
15
  import { isPreRelease2 } from '../utils/advanced-layouts-flags';
16
16
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
17
- import { canMoveNodeToIndex } from '../utils/validation';
17
+ import { canMoveNodeToIndex, isInSameLayout } from '../utils/validation';
18
18
  import { getNestedDepth, TYPE_DROP_TARGET_DEC, unmountDecorations } from './decorations-common';
19
19
  var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
20
20
  var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
@@ -81,7 +81,7 @@ export var findDropTargetDecs = function findDropTargetDecs(decorations, from, t
81
81
  return spec.type === TYPE_DROP_TARGET_DEC;
82
82
  });
83
83
  };
84
- export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
84
+ export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache, isSameLayout) {
85
85
  return Decoration.widget(pos, function (_, getPos) {
86
86
  var element = document.createElement('div');
87
87
  element.setAttribute('data-blocks-drop-target-container', 'true');
@@ -95,7 +95,8 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
95
95
  element.style.setProperty('display', 'block');
96
96
  ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
97
97
  getPos: getPos,
98
- anchorRectCache: anchorRectCache
98
+ anchorRectCache: anchorRectCache,
99
+ isSameLayout: isSameLayout
99
100
  })), element);
100
101
  } else {
101
102
  ReactDOM.render( /*#__PURE__*/createElement(DropTarget, _objectSpread(_objectSpread({}, props), {}, {
@@ -129,7 +130,8 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
129
130
  var docTo = to === undefined || to > POS_END_OF_DOC ? POS_END_OF_DOC : to;
130
131
  var prevNode;
131
132
  var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
132
- var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
133
+ var $activeNodePos = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos);
134
+ var activePMNode = $activeNodePos && $activeNodePos.nodeAfter;
133
135
  anchorRectCache === null || anchorRectCache === void 0 || anchorRectCache.clear();
134
136
  var prevNodeStack = [];
135
137
  var popNodeStack = function popNodeStack(depth) {
@@ -149,12 +151,15 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
149
151
  var depth = 0;
150
152
  // drop target deco at the end position
151
153
  var endPos;
154
+ var $pos = newState.doc.resolve(pos);
155
+ var isSameLayout = $activeNodePos && isInSameLayout($activeNodePos, $pos);
152
156
  if (editorExperiment('nested-dnd', true)) {
153
- depth = newState.doc.resolve(pos).depth;
157
+ depth = $pos.depth;
154
158
  if (isAdvancedLayoutsPreRelease2) {
155
- if (node.type.name === 'layoutColumn' && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutSection' && (parent === null || parent === void 0 ? void 0 : parent.firstChild) !== node &&
159
+ if (node.type.name === 'layoutColumn' && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutSection' && (parent === null || parent === void 0 ? void 0 : parent.firstChild) !== node && (
156
160
  // Not the first node
157
- (parent === null || parent === void 0 ? void 0 : parent.childCount) < maxLayoutColumnSupported()) {
161
+ (parent === null || parent === void 0 ? void 0 : parent.childCount) < maxLayoutColumnSupported() || isSameLayout)) {
162
+ // Add drop target for layout columns
158
163
  decs.push(createLayoutDropTargetDecoration(pos, {
159
164
  api: api,
160
165
  parent: parent,
@@ -178,7 +183,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
178
183
  }
179
184
  return shouldDescend(node); //skip over, don't consider it a valid depth
180
185
  }
181
- var canDrop = activePMNode && canMoveNodeToIndex(parent, index, activePMNode);
186
+ var canDrop = activePMNode && canMoveNodeToIndex(parent, index, activePMNode, node);
182
187
 
183
188
  //NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
184
189
  if (!canDrop && !isBlocksDragTargetDebug()) {
@@ -205,7 +210,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
205
210
  parentNode: parent || undefined,
206
211
  formatMessage: formatMessage,
207
212
  dropTargetStyle: shouldShowFullHeight ? 'remainingHeight' : 'default'
208
- }, -1, anchorRectCache));
213
+ }, -1, anchorRectCache, isSameLayout));
209
214
  if (endPos !== undefined) {
210
215
  decs.push(createDropTargetDecoration(endPos, {
211
216
  api: api,
@@ -1,6 +1,6 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
2
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
- import { isPreRelease2 } from '../utils/advanced-layouts-flags';
3
+ import { isPreRelease1, isPreRelease2 } from '../utils/advanced-layouts-flags';
4
4
  var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(target) {
5
5
  if (target instanceof HTMLHeadingElement || target instanceof HTMLParagraphElement) {
6
6
  var _target$parentElement;
@@ -44,6 +44,12 @@ export var handleMouseOver = function handleMouseOver(view, event, api) {
44
44
  if (editorExperiment('nested-dnd', true) && isEmptyNestedParagraphOrHeading(rootElement)) {
45
45
  return false;
46
46
  }
47
+ if (rootElement.getAttribute('data-drag-handler-node-type') === 'media' && isPreRelease1()) {
48
+ rootElement = rootElement.closest('[data-drag-handler-anchor-name][data-drag-handler-node-type="mediaSingle"]');
49
+ if (!rootElement) {
50
+ return false;
51
+ }
52
+ }
47
53
  var parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
48
54
  var parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
49
55
 
@@ -179,7 +179,8 @@ export var DropTargetV2 = function DropTargetV2(props) {
179
179
  formatMessage = props.formatMessage,
180
180
  anchorRectCache = props.anchorRectCache,
181
181
  _props$dropTargetStyl = props.dropTargetStyle,
182
- dropTargetStyle = _props$dropTargetStyl === void 0 ? 'default' : _props$dropTargetStyl;
182
+ dropTargetStyle = _props$dropTargetStyl === void 0 ? 'default' : _props$dropTargetStyl,
183
+ isSameLayout = props.isSameLayout;
183
184
  var _useState = useState(false),
184
185
  _useState2 = _slicedToArray(_useState, 2),
185
186
  isDraggedOver = _useState2[0],
@@ -246,7 +247,7 @@ export var DropTargetV2 = function DropTargetV2(props) {
246
247
  anchorRectCache: anchorRectCache,
247
248
  position: "lower",
248
249
  isNestedDropTarget: isNestedDropTarget
249
- }), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode) && jsx(Fragment, null, jsx(InlineDropTarget, _extends({}, props, {
250
+ }), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode, isSameLayout) && jsx(Fragment, null, jsx(InlineDropTarget, _extends({}, props, {
250
251
  position: "left"
251
252
  })), jsx(InlineDropTarget, _extends({}, props, {
252
253
  position: "right"
@@ -5,6 +5,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  */
6
6
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
7
  import { css, Global, jsx } from '@emotion/react';
8
+ import { akEditorCalculatedWideLayoutWidth, akEditorCalculatedWideLayoutWidthSmallViewport } from '@atlaskit/editor-shared-styles';
8
9
  import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
11
  import { DRAG_HANDLE_MAX_WIDTH_PLUS_GAP, DRAG_HANDLE_WIDTH } from './consts';
@@ -142,6 +143,17 @@ var withFormatInLayoutStyleFixSelectors = ["".concat(dragHandleContainer, ":firs
142
143
  var withInlineNodeStyleWithChromeFix = css(_defineProperty({}, withInlineNodeStyleWithChromeFixSelectors, {
143
144
  transform: 'scale(0)'
144
145
  }));
146
+ var legacyBreakoutWideLayoutStyle = css({
147
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-values
148
+ '.ProseMirror-widget[data-blocks-drop-target-container="true"]': {
149
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
150
+ '--ak-editor--legacy-breakout-wide-layout-width': "".concat(akEditorCalculatedWideLayoutWidthSmallViewport, "px"),
151
+ '@media (width>=1280px)': {
152
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
153
+ '--ak-editor--legacy-breakout-wide-layout-width': "".concat(akEditorCalculatedWideLayoutWidth, "px")
154
+ }
155
+ }
156
+ });
145
157
  var globalStyles = function globalStyles() {
146
158
  return fg('platform_editor_element_dnd_nested_fix_patch_3') ? css({
147
159
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
@@ -218,7 +230,7 @@ var withAnchorNameZindexNestedStyle = css({
218
230
  });
219
231
  export var GlobalStylesWrapper = function GlobalStylesWrapper() {
220
232
  return jsx(Global, {
221
- styles: [globalStyles(), editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, editorExperiment('platform_editor_empty_line_prompt', true, {
233
+ styles: [globalStyles(), editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, editorExperiment('platform_editor_empty_line_prompt', true, {
222
234
  exposure: false
223
235
  }) ? emptyBlockExperimentGlobalStyles : undefined, fg('platform_editor_element_dnd_nested_fix_patch_1') ? withDividerInPanelStyleFix : undefined, fg('platform_editor_element_dnd_nested_fix_patch_2') ? withFormatInLayoutStyleFix : undefined, fg('platform_editor_element_dnd_nested_fix_patch_3') ? [withRelativePosStyle, topLevelNodeMarginStyles, editorExperiment('nested-dnd', true) ? withAnchorNameZindexNestedStyle : withAnchorNameZindexStyle] : undefined]
224
236
  });
@@ -5,11 +5,10 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  * @jsxRuntime classic
6
6
  * @jsx jsx
7
7
  */
8
- import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
9
 
10
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
11
11
  import { css, jsx } from '@emotion/react';
12
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
12
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
14
13
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
14
  import { B200 } from '@atlaskit/theme/colors';
@@ -17,10 +16,6 @@ import { getNodeAnchor } from '../pm-plugins/decorations-common';
17
16
  import { useActiveAnchorTracker } from '../utils/active-anchor-tracker';
18
17
  import { isAnchorSupported } from '../utils/anchor-utils';
19
18
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
20
- var dropTargetCommonStyle = css({
21
- position: 'absolute',
22
- display: 'block'
23
- });
24
19
  var hoverZoneCommonStyle = css({
25
20
  position: 'absolute',
26
21
  // above the top and bottom drop zone as block hover zone
@@ -29,68 +24,34 @@ var hoverZoneCommonStyle = css({
29
24
 
30
25
  // gap between node boundary and drop indicator/drop zone
31
26
  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
27
  var dropTargetLayoutHintStyle = css({
36
28
  height: '100%',
37
- position: 'relative',
29
+ position: 'absolute',
38
30
  borderRight: "1px dashed ".concat("var(--ds-border-focused, ".concat(B200, ")")),
39
- width: 0
31
+ width: 0,
32
+ left: 0
40
33
  });
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);
34
+ var dropTargetLayoutHintLeftStyle = css({
35
+ left: 'unset',
36
+ right: 0
37
+ });
38
+ var defaultNodeDimension = {
39
+ width: '0',
40
+ height: '0',
41
+ top: 'unset'
42
+ };
43
+ var getWidthOffset = function getWidthOffset(node, width, position) {
44
+ if (node.type.name === 'mediaSingle' || node.type.name === 'table') {
45
+ var isLeftPosition = position === 'left';
46
+ if (node.attrs.layout === 'align-start') {
47
+ return isLeftPosition ? "-0.5*(var(--ak-editor--line-length) - ".concat(width, ")") : "0.5*(var(--ak-editor--line-length) - ".concat(width, ")");
48
+ } else if ((node === null || node === void 0 ? void 0 : node.attrs.layout) === 'align-end') {
49
+ return isLeftPosition ? "0.5*(var(--ak-editor--line-length) - ".concat(width, ")") : "-0.5*(var(--ak-editor--line-length) - ".concat(width, ")");
88
50
  }
89
51
  }
90
- return {
91
- left: 0,
92
- right: 0
93
- };
52
+ if (node.type.name === 'bodiedExtension' || node.type.name === 'extension') {
53
+ return '-12px';
54
+ }
94
55
  };
95
56
  export var InlineDropTarget = function InlineDropTarget(_ref) {
96
57
  var api = _ref.api,
@@ -98,41 +59,65 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
98
59
  position = _ref.position,
99
60
  anchorRectCache = _ref.anchorRectCache,
100
61
  getPos = _ref.getPos;
101
- var _useSharedPluginState = useSharedPluginState(api, ['width']),
102
- widthState = _useSharedPluginState.widthState;
62
+ var ref = useRef(null);
103
63
  var _useState = useState(false),
104
64
  _useState2 = _slicedToArray(_useState, 2),
105
65
  isDraggedOver = _useState2[0],
106
66
  setIsDraggedOver = _useState2[1];
107
- var anchorName = nextNode ? getNodeAnchor(nextNode) : '';
67
+ var anchorName = useMemo(function () {
68
+ return nextNode ? getNodeAnchor(nextNode) : '';
69
+ }, [nextNode]);
108
70
  var _useActiveAnchorTrack = useActiveAnchorTracker(anchorName),
109
71
  _useActiveAnchorTrack2 = _slicedToArray(_useActiveAnchorTrack, 1),
110
72
  isActiveAnchor = _useActiveAnchorTrack2[0];
111
- var handleDragEnter = useCallback(function () {
112
- setIsDraggedOver(true);
113
- }, []);
114
- var handleDragLeave = useCallback(function () {
115
- setIsDraggedOver(false);
116
- }, []);
117
- var offsets = useMemo(function () {
118
- return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
119
- }, [nextNode, widthState]);
120
- var dropTargetRectStyle = useMemo(function () {
73
+ var isLeftPosition = position === 'left';
74
+ var nodeDimension = useMemo(function () {
75
+ if (!nextNode) {
76
+ return defaultNodeDimension;
77
+ }
78
+ var innerContainerWidth = null;
79
+ var targetAnchorName = anchorName;
80
+ if (['blockCard', 'embedCard'].includes(nextNode.type.name)) {
81
+ if (nextNode.attrs.layout === 'wide') {
82
+ innerContainerWidth = "max(var(--ak-editor--legacy-breakout-wide-layout-width), var(--ak-editor--line-length))";
83
+ } else if (nextNode.attrs.layout === 'full-width') {
84
+ innerContainerWidth = 'max(calc(var(--ak-editor-max-container-width) - var(--ak-editor--default-gutter-padding) * 2), var(--ak-editor--line-length))';
85
+ }
86
+ } else if (nextNode.type.name === 'table' && nextNode.firstChild) {
87
+ var _anchorRectCache$getR;
88
+ var tableWidthAnchor = getNodeAnchor(nextNode.firstChild);
89
+ innerContainerWidth = isAnchorSupported() ? "anchor-size(".concat(tableWidthAnchor, " width)") : "".concat((anchorRectCache === null || anchorRectCache === void 0 || (_anchorRectCache$getR = anchorRectCache.getRect(tableWidthAnchor)) === null || _anchorRectCache$getR === void 0 ? void 0 : _anchorRectCache$getR.width) || 0, "px");
90
+ if (nextNode.attrs.width) {
91
+ // when the table has horizontal scroll
92
+ innerContainerWidth = "min(".concat(nextNode.attrs.width, "px, ").concat(innerContainerWidth, ")");
93
+ }
94
+ } else if (nextNode.type.name === 'mediaSingle' && nextNode.firstChild) {
95
+ targetAnchorName = getNodeAnchor(nextNode.firstChild);
96
+ }
121
97
  if (isAnchorSupported()) {
122
- return css({
123
- height: "calc(anchor-size(".concat(anchorName, " height))"),
124
- positionAnchor: anchorName,
125
- left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
126
- top: "calc(anchor(top))"
127
- });
98
+ var width = innerContainerWidth || "anchor-size(".concat(targetAnchorName, " width)");
99
+ var height = "anchor-size(".concat(targetAnchorName, " height)");
100
+ return {
101
+ width: width,
102
+ height: height,
103
+ top: 'anchor(top)',
104
+ widthOffset: getWidthOffset(nextNode, width, position)
105
+ };
128
106
  }
129
- var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
130
- return css({
131
- height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
132
- 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"),
133
- top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
134
- });
135
- }, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
107
+ if (anchorRectCache) {
108
+ var nodeRect = anchorRectCache.getRect(targetAnchorName);
109
+ var _width = innerContainerWidth || "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0, "px");
110
+ var top = nodeRect !== null && nodeRect !== void 0 && nodeRect.top ? "".concat(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top, "px") : 'unset';
111
+ var _height = "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px");
112
+ return {
113
+ width: _width,
114
+ height: _height,
115
+ top: top,
116
+ widthOffset: getWidthOffset(nextNode, _width, position)
117
+ };
118
+ }
119
+ return defaultNodeDimension;
120
+ }, [anchorName, anchorRectCache, nextNode, position]);
136
121
  var onDrop = useCallback(function () {
137
122
  var _api$blockControls;
138
123
  var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
@@ -149,72 +134,42 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
149
134
  }));
150
135
  }
151
136
  }, [api, getPos, position]);
152
- return jsx(Fragment, null, jsx("div", {
153
- "data-test-id": "block-ctrl-drop-target-".concat(position),
154
- css: [dropTargetCommonStyle, dropTargetRectStyle]
155
- }, isDraggedOver || isBlocksDragTargetDebug() ? jsx(DropIndicator, {
156
- edge: position
157
- }) : isActiveAnchor && jsx("div", {
158
- "data-testid": "block-ctrl-drop-hint",
159
- css: dropTargetLayoutHintStyle
160
- })), jsx(InlineHoverZone, {
161
- position: position,
162
- node: nextNode,
163
- editorWidthState: widthState,
164
- anchorRectCache: anchorRectCache,
165
- onDragEnter: handleDragEnter,
166
- onDragLeave: handleDragLeave,
167
- onDrop: onDrop,
168
- offsets: offsets
169
- }));
170
- };
171
- export var InlineHoverZone = function InlineHoverZone(_ref3) {
172
- var node = _ref3.node,
173
- editorWidthState = _ref3.editorWidthState,
174
- anchorRectCache = _ref3.anchorRectCache,
175
- position = _ref3.position,
176
- offsets = _ref3.offsets,
177
- onDragEnter = _ref3.onDragEnter,
178
- onDragLeave = _ref3.onDragLeave,
179
- onDrop = _ref3.onDrop;
180
- var ref = useRef(null);
181
- var _ref4 = editorWidthState || {},
182
- editorWith = _ref4.width;
183
- var anchorName = node ? getNodeAnchor(node) : '';
137
+ var inlineHoverZoneRectStyle = useMemo(function () {
138
+ return css({
139
+ positionAnchor: anchorName,
140
+ minWidth: "var(--ds-space-100, 8px)",
141
+ left: isLeftPosition ? 0 : 'unset',
142
+ right: isLeftPosition ? 'unset' : 0,
143
+ top: "calc(anchor(top))",
144
+ width: nodeDimension.widthOffset ? "calc((100% - ".concat(nodeDimension.width, ")/2 - ").concat(GAP, "px + ").concat(nodeDimension.widthOffset, ")") : "calc((100% - ".concat(nodeDimension.width, ")/2 - ").concat(GAP, "px)"),
145
+ height: "calc(".concat(nodeDimension.height, ")")
146
+ });
147
+ }, [anchorName, isLeftPosition, nodeDimension]);
148
+ var dropIndicatorPos = useMemo(function () {
149
+ return isLeftPosition ? 'right' : 'left';
150
+ }, [isLeftPosition]);
184
151
  useEffect(function () {
185
152
  if (ref.current) {
186
153
  return dropTargetForElements({
187
154
  element: ref.current,
188
- onDragEnter: onDragEnter,
189
- onDragLeave: onDragLeave,
155
+ onDragEnter: function onDragEnter() {
156
+ setIsDraggedOver(true);
157
+ },
158
+ onDragLeave: function onDragLeave() {
159
+ setIsDraggedOver(false);
160
+ },
190
161
  onDrop: onDrop
191
162
  });
192
163
  }
193
- }, [onDragEnter, onDragLeave, onDrop]);
194
- var inlineHoverZoneRectStyle = useMemo(function () {
195
- var offset = offsets[position];
196
- if (isAnchorSupported()) {
197
- return css({
198
- positionAnchor: anchorName,
199
- left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
200
- right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
201
- top: "calc(anchor(top))",
202
- 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"),
203
- height: "calc(anchor-size(".concat(anchorName, " height))")
204
- });
205
- }
206
- var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
207
- var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
208
- return css({
209
- 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"),
210
- top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
211
- width: "".concat(width, "px"),
212
- height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
213
- });
214
- }, [anchorName, anchorRectCache, editorWith, offsets, position]);
164
+ }, [onDrop, setIsDraggedOver]);
215
165
  return jsx("div", {
216
166
  ref: ref,
217
- "data-test-id": "drop-target-hover-zone-".concat(position),
167
+ "data-testid": "drop-target-hover-zone-".concat(position),
218
168
  css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
219
- });
169
+ }, isDraggedOver || isBlocksDragTargetDebug() ? jsx(DropIndicator, {
170
+ edge: dropIndicatorPos
171
+ }) : isActiveAnchor && jsx("div", {
172
+ "data-testid": "block-ctrl-drop-hint",
173
+ css: [dropTargetLayoutHintStyle, isLeftPosition && dropTargetLayoutHintLeftStyle]
174
+ }));
220
175
  };
@@ -1,8 +1,9 @@
1
1
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
2
2
  import { maxLayoutColumnSupported } from '../consts';
3
- import { isPreRelease1 } from './advanced-layouts-flags';
3
+ import { isPreRelease1, isPreRelease2 } from './advanced-layouts-flags';
4
4
  import { isWrappedMedia } from './check-media-layout';
5
5
  export var shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
6
+ var isSameLayout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
6
7
  if (!isPreRelease1() || isNested) {
7
8
  return false;
8
9
  }
@@ -10,7 +11,7 @@ export var shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(is
10
11
  return false;
11
12
  }
12
13
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
13
- return node.childCount < maxLayoutColumnSupported();
14
+ return node.childCount < maxLayoutColumnSupported() || isPreRelease2() && isSameLayout;
14
15
  }
15
16
  return !isEmptyParagraph(node);
16
17
  };
@@ -1,6 +1,7 @@
1
1
  import memoizeOne from 'memoize-one';
2
2
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
+ import { isPreRelease2 } from '../utils/advanced-layouts-flags';
4
5
  export var isInsideTable = function isInsideTable(nodeType) {
5
6
  var _nodeType$schema$node = nodeType.schema.nodes,
6
7
  tableCell = _nodeType$schema$node.tableCell,
@@ -19,6 +20,13 @@ export var isExpand = function isExpand(nodeType) {
19
20
  export var isNestedExpand = function isNestedExpand(nodeType) {
20
21
  return nodeType === nodeType.schema.nodes.nestedExpand;
21
22
  };
23
+ export var isInSameLayout = function isInSameLayout($from, $to) {
24
+ var fromNode = $from.nodeAfter;
25
+ var toNode = $to.nodeAfter;
26
+ return !!(fromNode && toNode && fromNode.type.name === 'layoutColumn' && ['layoutSection', 'layoutColumn'].includes(toNode.type.name) && (
27
+ // fromNode can either be in the same layoutSection as toNode or is a layoutColumn inside the toNode (type layoutSection)
28
+ $from.sameParent($to) || $from.parent === toNode));
29
+ };
22
30
 
23
31
  /**
24
32
  * This function converts an expand into a nested expand,
@@ -61,7 +69,12 @@ export var memoizedTransformExpandToNestedExpand = memoizeOne(function (node) {
61
69
  return null;
62
70
  }
63
71
  });
64
- export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
72
+ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, destNode) {
73
+ if (isPreRelease2() &&
74
+ // Allow drag layout column and drop into layout section
75
+ srcNode.type.name === 'layoutColumn' && (destNode === null || destNode === void 0 ? void 0 : destNode.type.name) === 'layoutSection') {
76
+ return true;
77
+ }
65
78
  var srcNodeType = srcNode.type;
66
79
  var parentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
67
80
  var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;
@@ -14,6 +14,6 @@ import { type AnchorRectCache } from '../utils/anchor-utils';
14
14
  * @returns
15
15
  */
16
16
  export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
17
- export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
17
+ export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache, isSameLayout?: boolean) => Decoration;
18
18
  export declare const createLayoutDropTargetDecoration: (pos: number, props: Omit<DropTargetLayoutProps, 'getPos'>) => Decoration;
19
19
  export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
@@ -5,4 +5,5 @@ export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-blo
5
5
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = "--editor-block-controls-drop-indicator-gap";
6
6
  export declare const DropTargetV2: (props: DropTargetProps & {
7
7
  anchorRectCache?: AnchorRectCache | undefined;
8
+ isSameLayout?: boolean | undefined;
8
9
  }) => jsx.JSX.Element;