@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.13.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [`dda502e353b44`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dda502e353b44) -
8
+ [ux] [ED-25317] Implement drag and drop a layout column within the same layout section
9
+
10
+ ## 2.13.10
11
+
12
+ ### Patch Changes
13
+
14
+ - [#162501](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162501)
15
+ [`3bdd9f8231197`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3bdd9f8231197) -
16
+ ED-25579 fix vertical drop target bugs
17
+ - Updated dependencies
18
+
3
19
  ## 2.13.9
4
20
 
5
21
  ### Patch Changes
@@ -8,6 +8,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _consts = require("../consts");
10
10
  var _consts2 = require("../ui/consts");
11
+ var _validation = require("../utils/validation");
11
12
  var createNewLayout = function createNewLayout(schema, layoutContents) {
12
13
  if (layoutContents.length === 0 || layoutContents.length > (0, _consts.maxLayoutColumnSupported)()) {
13
14
  return null;
@@ -53,8 +54,13 @@ var moveNode = function moveNode(from, to, newNode, sourceNodeSize, tr) {
53
54
  tr.delete(mappedFrom, mappedFromEnd);
54
55
  return tr;
55
56
  };
56
- var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos, sourceNode, from, to, tr) {
57
- if (toLayout.childCount < (0, _consts.maxLayoutColumnSupported)()) {
57
+ var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos, sourceNode, from, to, tr, isSameLayout) {
58
+ if (isSameLayout) {
59
+ // reorder columns
60
+ tr.delete(from, from + sourceNode.nodeSize);
61
+ var mappedTo = tr.mapping.map(to);
62
+ tr.insert(mappedTo, sourceNode).setSelection(new _state.NodeSelection(tr.doc.resolve(mappedTo))).scrollIntoView();
63
+ } else if (toLayout.childCount < (0, _consts.maxLayoutColumnSupported)()) {
58
64
  var newColumnWidth = _consts2.DEFAULT_COLUMN_DISTRIBUTIONS[toLayout.childCount + 1];
59
65
  updateColumnWidths(tr, toLayout, toLayoutPos, newColumnWidth);
60
66
  var _ref2 = tr.doc.type.schema.nodes || {},
@@ -136,12 +142,12 @@ var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
136
142
  }
137
143
  if (toNode.type === layoutSection) {
138
144
  var toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize - 1 : to + 1;
139
- return moveToExistingLayout(toNode, to, fromNodeWithoutBreakout, from, toPos, tr);
145
+ return moveToExistingLayout(toNode, to, fromNodeWithoutBreakout, from, toPos, tr, (0, _validation.isInSameLayout)($from, $to));
140
146
  } else if (toNode.type === layoutColumn) {
141
147
  var toLayout = $to.parent;
142
148
  var toLayoutPos = to - $to.parentOffset - 1;
143
149
  var _toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize : to;
144
- return moveToExistingLayout(toLayout, toLayoutPos, fromNodeWithoutBreakout, from, _toPos, tr);
150
+ return moveToExistingLayout(toLayout, toLayoutPos, fromNodeWithoutBreakout, from, _toPos, tr, (0, _validation.isInSameLayout)($from, $to));
145
151
  } else {
146
152
  var toNodeWithoutBreakout = toNode;
147
153
 
@@ -14,6 +14,7 @@ var _decorationsCommon = require("./decorations-common");
14
14
  var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
15
15
  var IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
16
16
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
17
+ var IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT = ['listItem', 'taskList', 'decisionList'];
17
18
  var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
18
19
  // Optimisation to avoid drawing node decorations for empty table cells
19
20
  if (['tableCell', 'tableHeader'].includes(node.type.name) && !(0, _experiments.editorExperiment)('table-nested-dnd', true) && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3')) {
@@ -22,13 +23,20 @@ var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDesce
22
23
  return false;
23
24
  }
24
25
  }
26
+ if ((0, _advancedLayoutsFlags.isPreRelease1)()) {
27
+ return !IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT.includes(node.type.name);
28
+ }
25
29
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
26
30
  };
27
- var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes) {
31
+ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, parent) {
28
32
  var isEmbedCard = 'embedCard' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3');
29
33
 
30
34
  // TODO use isWrappedMedia when clean up the feature flag
31
35
  var isMediaSingle = 'mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1');
36
+ var isFirstTableHeaderOrTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && ['tableHeader', 'tableRow'].includes(node.type.name) && (0, _advancedLayoutsFlags.isPreRelease1)();
37
+ if (isFirstTableHeaderOrTableRow) {
38
+ return false;
39
+ }
32
40
  return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
33
41
  };
34
42
 
@@ -66,7 +74,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
66
74
  var docFrom = from === undefined || from < 0 ? 0 : from;
67
75
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
68
76
  var ignore_nodes = (0, _advancedLayoutsFlags.isPreRelease2)() ? IGNORE_NODES_NEXT : IGNORE_NODES;
69
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
77
+ newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
70
78
  var _Decoration$node;
71
79
  var depth = 0;
72
80
  var anchorName;
@@ -78,10 +86,10 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
78
86
  if (node.isInline) {
79
87
  return false;
80
88
  }
81
- if (shouldIgnoreNode(node, ignore_nodes)) {
89
+ depth = newState.doc.resolve(pos).depth;
90
+ if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
82
91
  return shouldDescend; //skip over, don't consider it a valid depth
83
92
  }
84
- depth = newState.doc.resolve(pos).depth;
85
93
  anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
86
94
  } else {
87
95
  var _anchorName2;
@@ -88,7 +88,7 @@ var findDropTargetDecs = exports.findDropTargetDecs = function findDropTargetDec
88
88
  return spec.type === _decorationsCommon.TYPE_DROP_TARGET_DEC;
89
89
  });
90
90
  };
91
- var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
91
+ var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache, isSameLayout) {
92
92
  return _view.Decoration.widget(pos, function (_, getPos) {
93
93
  var element = document.createElement('div');
94
94
  element.setAttribute('data-blocks-drop-target-container', 'true');
@@ -102,7 +102,8 @@ var createDropTargetDecoration = exports.createDropTargetDecoration = function c
102
102
  element.style.setProperty('display', 'block');
103
103
  _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTargetV.DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
104
104
  getPos: getPos,
105
- anchorRectCache: anchorRectCache
105
+ anchorRectCache: anchorRectCache,
106
+ isSameLayout: isSameLayout
106
107
  })), element);
107
108
  } else {
108
109
  _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, _objectSpread(_objectSpread({}, props), {}, {
@@ -136,7 +137,8 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
136
137
  var docTo = to === undefined || to > POS_END_OF_DOC ? POS_END_OF_DOC : to;
137
138
  var prevNode;
138
139
  var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
139
- var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
140
+ var $activeNodePos = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos);
141
+ var activePMNode = $activeNodePos && $activeNodePos.nodeAfter;
140
142
  anchorRectCache === null || anchorRectCache === void 0 || anchorRectCache.clear();
141
143
  var prevNodeStack = [];
142
144
  var popNodeStack = function popNodeStack(depth) {
@@ -156,12 +158,15 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
156
158
  var depth = 0;
157
159
  // drop target deco at the end position
158
160
  var endPos;
161
+ var $pos = newState.doc.resolve(pos);
162
+ var isSameLayout = $activeNodePos && (0, _validation.isInSameLayout)($activeNodePos, $pos);
159
163
  if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
160
- depth = newState.doc.resolve(pos).depth;
164
+ depth = $pos.depth;
161
165
  if (isAdvancedLayoutsPreRelease2) {
162
- 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 &&
166
+ 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 && (
163
167
  // Not the first node
164
- (parent === null || parent === void 0 ? void 0 : parent.childCount) < (0, _consts.maxLayoutColumnSupported)()) {
168
+ (parent === null || parent === void 0 ? void 0 : parent.childCount) < (0, _consts.maxLayoutColumnSupported)() || isSameLayout)) {
169
+ // Add drop target for layout columns
165
170
  decs.push(createLayoutDropTargetDecoration(pos, {
166
171
  api: api,
167
172
  parent: parent,
@@ -185,7 +190,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
185
190
  }
186
191
  return shouldDescend(node); //skip over, don't consider it a valid depth
187
192
  }
188
- var canDrop = activePMNode && (0, _validation.canMoveNodeToIndex)(parent, index, activePMNode);
193
+ var canDrop = activePMNode && (0, _validation.canMoveNodeToIndex)(parent, index, activePMNode, node);
189
194
 
190
195
  //NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
191
196
  if (!canDrop && !(0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
@@ -212,7 +217,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
212
217
  parentNode: parent || undefined,
213
218
  formatMessage: formatMessage,
214
219
  dropTargetStyle: shouldShowFullHeight ? 'remainingHeight' : 'default'
215
- }, -1, anchorRectCache));
220
+ }, -1, anchorRectCache, isSameLayout));
216
221
  if (endPos !== undefined) {
217
222
  decs.push(createDropTargetDecoration(endPos, {
218
223
  api: api,
@@ -50,6 +50,12 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
50
50
  if ((0, _experiments.editorExperiment)('nested-dnd', true) && isEmptyNestedParagraphOrHeading(rootElement)) {
51
51
  return false;
52
52
  }
53
+ if (rootElement.getAttribute('data-drag-handler-node-type') === 'media' && (0, _advancedLayoutsFlags.isPreRelease1)()) {
54
+ rootElement = rootElement.closest('[data-drag-handler-anchor-name][data-drag-handler-node-type="mediaSingle"]');
55
+ if (!rootElement) {
56
+ return false;
57
+ }
58
+ }
53
59
  var parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
54
60
  var parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
55
61
 
@@ -187,7 +187,8 @@ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(props) {
187
187
  formatMessage = props.formatMessage,
188
188
  anchorRectCache = props.anchorRectCache,
189
189
  _props$dropTargetStyl = props.dropTargetStyle,
190
- dropTargetStyle = _props$dropTargetStyl === void 0 ? 'default' : _props$dropTargetStyl;
190
+ dropTargetStyle = _props$dropTargetStyl === void 0 ? 'default' : _props$dropTargetStyl,
191
+ isSameLayout = props.isSameLayout;
191
192
  var _useState = (0, _react.useState)(false),
192
193
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
193
194
  isDraggedOver = _useState2[0],
@@ -254,7 +255,7 @@ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(props) {
254
255
  anchorRectCache: anchorRectCache,
255
256
  position: "lower",
256
257
  isNestedDropTarget: isNestedDropTarget
257
- }), (0, _inlineDropTarget.shouldAllowInlineDropTarget)(isNestedDropTarget, nextNode) && (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget, (0, _extends2.default)({}, props, {
258
+ }), (0, _inlineDropTarget.shouldAllowInlineDropTarget)(isNestedDropTarget, nextNode, isSameLayout) && (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget, (0, _extends2.default)({}, props, {
258
259
  position: "left"
259
260
  })), (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget, (0, _extends2.default)({}, props, {
260
261
  position: "right"
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.GlobalStylesWrapper = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("@emotion/react");
10
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
10
11
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var _consts = require("./consts");
@@ -150,6 +151,17 @@ var withFormatInLayoutStyleFixSelectors = ["".concat(dragHandleContainer, ":firs
150
151
  var withInlineNodeStyleWithChromeFix = (0, _react.css)((0, _defineProperty2.default)({}, withInlineNodeStyleWithChromeFixSelectors, {
151
152
  transform: 'scale(0)'
152
153
  }));
154
+ var legacyBreakoutWideLayoutStyle = (0, _react.css)({
155
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-values
156
+ '.ProseMirror-widget[data-blocks-drop-target-container="true"]': {
157
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
158
+ '--ak-editor--legacy-breakout-wide-layout-width': "".concat(_editorSharedStyles.akEditorCalculatedWideLayoutWidthSmallViewport, "px"),
159
+ '@media (width>=1280px)': {
160
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
161
+ '--ak-editor--legacy-breakout-wide-layout-width': "".concat(_editorSharedStyles.akEditorCalculatedWideLayoutWidth, "px")
162
+ }
163
+ }
164
+ });
153
165
  var globalStyles = function globalStyles() {
154
166
  return (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? (0, _react.css)({
155
167
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
@@ -226,7 +238,7 @@ var withAnchorNameZindexNestedStyle = (0, _react.css)({
226
238
  });
227
239
  var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
228
240
  return (0, _react.jsx)(_react.Global, {
229
- styles: [globalStyles(), (0, _experiments.editorExperiment)('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, (0, _experiments.editorExperiment)('platform_editor_empty_line_prompt', true, {
241
+ styles: [globalStyles(), (0, _experiments.editorExperiment)('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, (0, _experiments.editorExperiment)('platform_editor_empty_line_prompt', true, {
230
242
  exposure: false
231
243
  }) ? _globalStyles.emptyBlockExperimentGlobalStyles : undefined, (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1') ? withDividerInPanelStyleFix : undefined, (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2') ? withFormatInLayoutStyleFix : undefined, (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? [withRelativePosStyle, topLevelNodeMarginStyles, (0, _experiments.editorExperiment)('nested-dnd', true) ? withAnchorNameZindexNestedStyle : withAnchorNameZindexStyle] : undefined]
232
244
  });
@@ -4,11 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.InlineHoverZone = exports.InlineDropTarget = void 0;
7
+ exports.InlineDropTarget = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var _react2 = require("@emotion/react");
11
- var _hooks = require("@atlaskit/editor-common/hooks");
12
11
  var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
13
12
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
14
13
  var _colors = require("@atlaskit/theme/colors");
@@ -23,12 +22,8 @@ var _dragTargetDebug = require("../utils/drag-target-debug");
23
22
  * @jsx jsx
24
23
  */
25
24
 
26
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
25
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
27
26
 
28
- var dropTargetCommonStyle = (0, _react2.css)({
29
- position: 'absolute',
30
- display: 'block'
31
- });
32
27
  var hoverZoneCommonStyle = (0, _react2.css)({
33
28
  position: 'absolute',
34
29
  // above the top and bottom drop zone as block hover zone
@@ -37,68 +32,34 @@ var hoverZoneCommonStyle = (0, _react2.css)({
37
32
 
38
33
  // gap between node boundary and drop indicator/drop zone
39
34
  var GAP = 4;
40
- var HOVER_ZONE_WIDTH_OFFSET = 40;
41
- var HOVER_ZONE_HEIGHT_OFFSET = 10;
42
- var HOVER_ZONE_DEFAULT_WIDTH = 40;
43
35
  var dropTargetLayoutHintStyle = (0, _react2.css)({
44
36
  height: '100%',
45
- position: 'relative',
37
+ position: 'absolute',
46
38
  borderRight: "1px dashed ".concat("var(--ds-border-focused, ".concat(_colors.B200, ")")),
47
- width: 0
39
+ width: 0,
40
+ left: 0
48
41
  });
49
- var getDropTargetPositionOverride = function getDropTargetPositionOverride(node, editorWidth) {
50
- if (!node || !editorWidth) {
51
- return {
52
- left: 0,
53
- right: 0
54
- };
55
- }
56
- var getOffsets = function getOffsets(nodeWidth) {
57
- var offset = (editorWidth - nodeWidth) / 2;
58
- return {
59
- left: offset,
60
- right: offset
61
- };
62
- };
63
- if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
64
- return getOffsets(node.attrs.width);
65
- }
66
-
67
- // media single 🤦
68
- if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
69
- var mediaNodeWidth = 0;
70
- if (node.attrs.width) {
71
- if (node.attrs.widthType === 'pixel') {
72
- mediaNodeWidth = node.attrs.width;
73
- } else if (editorWidth) {
74
- mediaNodeWidth = node.attrs.width / 100 * editorWidth;
75
- }
76
- } else {
77
- // use media width
78
- var mediaNode = node.firstChild;
79
- if (mediaNode && mediaNode.attrs.width) {
80
- mediaNodeWidth = mediaNode.attrs.width;
81
- }
82
- }
83
- if (mediaNodeWidth) {
84
- if (node.attrs.layout === 'align-start') {
85
- return {
86
- left: 0,
87
- right: editorWidth - mediaNodeWidth
88
- };
89
- } else if (node.attrs.layout === 'align-end') {
90
- return {
91
- left: editorWidth - mediaNodeWidth,
92
- right: 0
93
- };
94
- }
95
- return getOffsets(mediaNodeWidth);
42
+ var dropTargetLayoutHintLeftStyle = (0, _react2.css)({
43
+ left: 'unset',
44
+ right: 0
45
+ });
46
+ var defaultNodeDimension = {
47
+ width: '0',
48
+ height: '0',
49
+ top: 'unset'
50
+ };
51
+ var getWidthOffset = function getWidthOffset(node, width, position) {
52
+ if (node.type.name === 'mediaSingle' || node.type.name === 'table') {
53
+ var isLeftPosition = position === 'left';
54
+ if (node.attrs.layout === 'align-start') {
55
+ return isLeftPosition ? "-0.5*(var(--ak-editor--line-length) - ".concat(width, ")") : "0.5*(var(--ak-editor--line-length) - ".concat(width, ")");
56
+ } else if ((node === null || node === void 0 ? void 0 : node.attrs.layout) === 'align-end') {
57
+ return isLeftPosition ? "0.5*(var(--ak-editor--line-length) - ".concat(width, ")") : "-0.5*(var(--ak-editor--line-length) - ".concat(width, ")");
96
58
  }
97
59
  }
98
- return {
99
- left: 0,
100
- right: 0
101
- };
60
+ if (node.type.name === 'bodiedExtension' || node.type.name === 'extension') {
61
+ return '-12px';
62
+ }
102
63
  };
103
64
  var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref) {
104
65
  var api = _ref.api,
@@ -106,41 +67,65 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
106
67
  position = _ref.position,
107
68
  anchorRectCache = _ref.anchorRectCache,
108
69
  getPos = _ref.getPos;
109
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width']),
110
- widthState = _useSharedPluginState.widthState;
70
+ var ref = (0, _react.useRef)(null);
111
71
  var _useState = (0, _react.useState)(false),
112
72
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
113
73
  isDraggedOver = _useState2[0],
114
74
  setIsDraggedOver = _useState2[1];
115
- var anchorName = nextNode ? (0, _decorationsCommon.getNodeAnchor)(nextNode) : '';
75
+ var anchorName = (0, _react.useMemo)(function () {
76
+ return nextNode ? (0, _decorationsCommon.getNodeAnchor)(nextNode) : '';
77
+ }, [nextNode]);
116
78
  var _useActiveAnchorTrack = (0, _activeAnchorTracker.useActiveAnchorTracker)(anchorName),
117
79
  _useActiveAnchorTrack2 = (0, _slicedToArray2.default)(_useActiveAnchorTrack, 1),
118
80
  isActiveAnchor = _useActiveAnchorTrack2[0];
119
- var handleDragEnter = (0, _react.useCallback)(function () {
120
- setIsDraggedOver(true);
121
- }, []);
122
- var handleDragLeave = (0, _react.useCallback)(function () {
123
- setIsDraggedOver(false);
124
- }, []);
125
- var offsets = (0, _react.useMemo)(function () {
126
- return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
127
- }, [nextNode, widthState]);
128
- var dropTargetRectStyle = (0, _react.useMemo)(function () {
81
+ var isLeftPosition = position === 'left';
82
+ var nodeDimension = (0, _react.useMemo)(function () {
83
+ if (!nextNode) {
84
+ return defaultNodeDimension;
85
+ }
86
+ var innerContainerWidth = null;
87
+ var targetAnchorName = anchorName;
88
+ if (['blockCard', 'embedCard'].includes(nextNode.type.name)) {
89
+ if (nextNode.attrs.layout === 'wide') {
90
+ innerContainerWidth = "max(var(--ak-editor--legacy-breakout-wide-layout-width), var(--ak-editor--line-length))";
91
+ } else if (nextNode.attrs.layout === 'full-width') {
92
+ innerContainerWidth = 'max(calc(var(--ak-editor-max-container-width) - var(--ak-editor--default-gutter-padding) * 2), var(--ak-editor--line-length))';
93
+ }
94
+ } else if (nextNode.type.name === 'table' && nextNode.firstChild) {
95
+ var _anchorRectCache$getR;
96
+ var tableWidthAnchor = (0, _decorationsCommon.getNodeAnchor)(nextNode.firstChild);
97
+ innerContainerWidth = (0, _anchorUtils.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");
98
+ if (nextNode.attrs.width) {
99
+ // when the table has horizontal scroll
100
+ innerContainerWidth = "min(".concat(nextNode.attrs.width, "px, ").concat(innerContainerWidth, ")");
101
+ }
102
+ } else if (nextNode.type.name === 'mediaSingle' && nextNode.firstChild) {
103
+ targetAnchorName = (0, _decorationsCommon.getNodeAnchor)(nextNode.firstChild);
104
+ }
129
105
  if ((0, _anchorUtils.isAnchorSupported)()) {
130
- return (0, _react2.css)({
131
- height: "calc(anchor-size(".concat(anchorName, " height))"),
132
- positionAnchor: anchorName,
133
- left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
134
- top: "calc(anchor(top))"
135
- });
106
+ var width = innerContainerWidth || "anchor-size(".concat(targetAnchorName, " width)");
107
+ var height = "anchor-size(".concat(targetAnchorName, " height)");
108
+ return {
109
+ width: width,
110
+ height: height,
111
+ top: 'anchor(top)',
112
+ widthOffset: getWidthOffset(nextNode, width, position)
113
+ };
136
114
  }
137
- var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
138
- return (0, _react2.css)({
139
- height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
140
- 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"),
141
- top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
142
- });
143
- }, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
115
+ if (anchorRectCache) {
116
+ var nodeRect = anchorRectCache.getRect(targetAnchorName);
117
+ var _width = innerContainerWidth || "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0, "px");
118
+ var top = nodeRect !== null && nodeRect !== void 0 && nodeRect.top ? "".concat(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top, "px") : 'unset';
119
+ var _height = "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px");
120
+ return {
121
+ width: _width,
122
+ height: _height,
123
+ top: top,
124
+ widthOffset: getWidthOffset(nextNode, _width, position)
125
+ };
126
+ }
127
+ return defaultNodeDimension;
128
+ }, [anchorName, anchorRectCache, nextNode, position]);
144
129
  var onDrop = (0, _react.useCallback)(function () {
145
130
  var _api$blockControls;
146
131
  var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
@@ -157,72 +142,42 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
157
142
  }));
158
143
  }
159
144
  }, [api, getPos, position]);
160
- return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)("div", {
161
- "data-test-id": "block-ctrl-drop-target-".concat(position),
162
- css: [dropTargetCommonStyle, dropTargetRectStyle]
163
- }, isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)() ? (0, _react2.jsx)(_box.DropIndicator, {
164
- edge: position
165
- }) : isActiveAnchor && (0, _react2.jsx)("div", {
166
- "data-testid": "block-ctrl-drop-hint",
167
- css: dropTargetLayoutHintStyle
168
- })), (0, _react2.jsx)(InlineHoverZone, {
169
- position: position,
170
- node: nextNode,
171
- editorWidthState: widthState,
172
- anchorRectCache: anchorRectCache,
173
- onDragEnter: handleDragEnter,
174
- onDragLeave: handleDragLeave,
175
- onDrop: onDrop,
176
- offsets: offsets
177
- }));
178
- };
179
- var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3) {
180
- var node = _ref3.node,
181
- editorWidthState = _ref3.editorWidthState,
182
- anchorRectCache = _ref3.anchorRectCache,
183
- position = _ref3.position,
184
- offsets = _ref3.offsets,
185
- onDragEnter = _ref3.onDragEnter,
186
- onDragLeave = _ref3.onDragLeave,
187
- onDrop = _ref3.onDrop;
188
- var ref = (0, _react.useRef)(null);
189
- var _ref4 = editorWidthState || {},
190
- editorWith = _ref4.width;
191
- var anchorName = node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
145
+ var inlineHoverZoneRectStyle = (0, _react.useMemo)(function () {
146
+ return (0, _react2.css)({
147
+ positionAnchor: anchorName,
148
+ minWidth: "var(--ds-space-100, 8px)",
149
+ left: isLeftPosition ? 0 : 'unset',
150
+ right: isLeftPosition ? 'unset' : 0,
151
+ top: "calc(anchor(top))",
152
+ width: nodeDimension.widthOffset ? "calc((100% - ".concat(nodeDimension.width, ")/2 - ").concat(GAP, "px + ").concat(nodeDimension.widthOffset, ")") : "calc((100% - ".concat(nodeDimension.width, ")/2 - ").concat(GAP, "px)"),
153
+ height: "calc(".concat(nodeDimension.height, ")")
154
+ });
155
+ }, [anchorName, isLeftPosition, nodeDimension]);
156
+ var dropIndicatorPos = (0, _react.useMemo)(function () {
157
+ return isLeftPosition ? 'right' : 'left';
158
+ }, [isLeftPosition]);
192
159
  (0, _react.useEffect)(function () {
193
160
  if (ref.current) {
194
161
  return (0, _adapter.dropTargetForElements)({
195
162
  element: ref.current,
196
- onDragEnter: onDragEnter,
197
- onDragLeave: onDragLeave,
163
+ onDragEnter: function onDragEnter() {
164
+ setIsDraggedOver(true);
165
+ },
166
+ onDragLeave: function onDragLeave() {
167
+ setIsDraggedOver(false);
168
+ },
198
169
  onDrop: onDrop
199
170
  });
200
171
  }
201
- }, [onDragEnter, onDragLeave, onDrop]);
202
- var inlineHoverZoneRectStyle = (0, _react.useMemo)(function () {
203
- var offset = offsets[position];
204
- if ((0, _anchorUtils.isAnchorSupported)()) {
205
- return (0, _react2.css)({
206
- positionAnchor: anchorName,
207
- left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
208
- right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
209
- top: "calc(anchor(top))",
210
- 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"),
211
- height: "calc(anchor-size(".concat(anchorName, " height))")
212
- });
213
- }
214
- var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
215
- var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
216
- return (0, _react2.css)({
217
- 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"),
218
- top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
219
- width: "".concat(width, "px"),
220
- height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
221
- });
222
- }, [anchorName, anchorRectCache, editorWith, offsets, position]);
172
+ }, [onDrop, setIsDraggedOver]);
223
173
  return (0, _react2.jsx)("div", {
224
174
  ref: ref,
225
- "data-test-id": "drop-target-hover-zone-".concat(position),
175
+ "data-testid": "drop-target-hover-zone-".concat(position),
226
176
  css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
227
- });
177
+ }, isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)() ? (0, _react2.jsx)(_box.DropIndicator, {
178
+ edge: dropIndicatorPos
179
+ }) : isActiveAnchor && (0, _react2.jsx)("div", {
180
+ "data-testid": "block-ctrl-drop-hint",
181
+ css: [dropTargetLayoutHintStyle, isLeftPosition && dropTargetLayoutHintLeftStyle]
182
+ }));
228
183
  };
@@ -9,6 +9,7 @@ var _consts = require("../consts");
9
9
  var _advancedLayoutsFlags = require("./advanced-layouts-flags");
10
10
  var _checkMediaLayout = require("./check-media-layout");
11
11
  var shouldAllowInlineDropTarget = exports.shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
12
+ var isSameLayout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
12
13
  if (!(0, _advancedLayoutsFlags.isPreRelease1)() || isNested) {
13
14
  return false;
14
15
  }
@@ -16,7 +17,7 @@ var shouldAllowInlineDropTarget = exports.shouldAllowInlineDropTarget = function
16
17
  return false;
17
18
  }
18
19
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
19
- return node.childCount < (0, _consts.maxLayoutColumnSupported)();
20
+ return node.childCount < (0, _consts.maxLayoutColumnSupported)() || (0, _advancedLayoutsFlags.isPreRelease2)() && isSameLayout;
20
21
  }
21
22
  return !(0, _utils.isEmptyParagraph)(node);
22
23
  };
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.canMoveNodeToIndex = canMoveNodeToIndex;
8
- exports.transformSliceExpandToNestedExpand = exports.transformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = exports.isNestedExpand = exports.isLayoutColumn = exports.isInsideTable = exports.isExpand = exports.isDoc = void 0;
8
+ exports.transformSliceExpandToNestedExpand = exports.transformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = exports.isNestedExpand = exports.isLayoutColumn = exports.isInsideTable = exports.isInSameLayout = exports.isExpand = exports.isDoc = void 0;
9
9
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
10
10
  var _model = require("@atlaskit/editor-prosemirror/model");
11
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
+ var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
12
13
  var isInsideTable = exports.isInsideTable = function isInsideTable(nodeType) {
13
14
  var _nodeType$schema$node = nodeType.schema.nodes,
14
15
  tableCell = _nodeType$schema$node.tableCell,
@@ -27,6 +28,13 @@ var isExpand = exports.isExpand = function isExpand(nodeType) {
27
28
  var isNestedExpand = exports.isNestedExpand = function isNestedExpand(nodeType) {
28
29
  return nodeType === nodeType.schema.nodes.nestedExpand;
29
30
  };
31
+ var isInSameLayout = exports.isInSameLayout = function isInSameLayout($from, $to) {
32
+ var fromNode = $from.nodeAfter;
33
+ var toNode = $to.nodeAfter;
34
+ return !!(fromNode && toNode && fromNode.type.name === 'layoutColumn' && ['layoutSection', 'layoutColumn'].includes(toNode.type.name) && (
35
+ // fromNode can either be in the same layoutSection as toNode or is a layoutColumn inside the toNode (type layoutSection)
36
+ $from.sameParent($to) || $from.parent === toNode));
37
+ };
30
38
 
31
39
  /**
32
40
  * This function converts an expand into a nested expand,
@@ -69,7 +77,12 @@ var memoizedTransformExpandToNestedExpand = exports.memoizedTransformExpandToNes
69
77
  return null;
70
78
  }
71
79
  });
72
- function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
80
+ function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, destNode) {
81
+ if ((0, _advancedLayoutsFlags.isPreRelease2)() &&
82
+ // Allow drag layout column and drop into layout section
83
+ srcNode.type.name === 'layoutColumn' && (destNode === null || destNode === void 0 ? void 0 : destNode.type.name) === 'layoutSection') {
84
+ return true;
85
+ }
73
86
  var srcNodeType = srcNode.type;
74
87
  var parentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
75
88
  var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;