@atlaskit/editor-plugin-block-controls 2.13.8 → 2.13.10

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.13.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#162501](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162501)
8
+ [`3bdd9f8231197`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3bdd9f8231197) -
9
+ ED-25579 fix vertical drop target bugs
10
+ - Updated dependencies
11
+
12
+ ## 2.13.9
13
+
14
+ ### Patch Changes
15
+
16
+ - [#161549](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/161549)
17
+ [`35e70290e4ccb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/35e70290e4ccb) -
18
+ [ED-25317] Fix the issue where drag handle for layout column does not show up when the content is
19
+ not empty (with non text content)
20
+ - Updated dependencies
21
+
3
22
  ## 2.13.8
4
23
 
5
24
  ### Patch Changes
@@ -11,8 +11,10 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
12
  var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
13
13
  var _decorationsCommon = require("./decorations-common");
14
- var IGNORE_NODES = (0, _advancedLayoutsFlags.isPreRelease2)() ? ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'] : ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
14
+ var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
15
+ var IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
15
16
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
17
+ var IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT = ['listItem', 'taskList', 'decisionList'];
16
18
  var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
17
19
  // Optimisation to avoid drawing node decorations for empty table cells
18
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')) {
@@ -21,14 +23,21 @@ var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDesce
21
23
  return false;
22
24
  }
23
25
  }
26
+ if ((0, _advancedLayoutsFlags.isPreRelease1)()) {
27
+ return !IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT.includes(node.type.name);
28
+ }
24
29
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
25
30
  };
26
- var shouldIgnoreNode = function shouldIgnoreNode(node) {
31
+ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, parent) {
27
32
  var isEmbedCard = 'embedCard' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3');
28
33
 
29
34
  // TODO use isWrappedMedia when clean up the feature flag
30
35
  var isMediaSingle = 'mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1');
31
- return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
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
+ }
40
+ return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
32
41
  };
33
42
 
34
43
  /**
@@ -64,7 +73,8 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
64
73
  var decs = [];
65
74
  var docFrom = from === undefined || from < 0 ? 0 : from;
66
75
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
67
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
76
+ var ignore_nodes = (0, _advancedLayoutsFlags.isPreRelease2)() ? IGNORE_NODES_NEXT : IGNORE_NODES;
77
+ newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
68
78
  var _Decoration$node;
69
79
  var depth = 0;
70
80
  var anchorName;
@@ -76,10 +86,10 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
76
86
  if (node.isInline) {
77
87
  return false;
78
88
  }
79
- if (shouldIgnoreNode(node)) {
89
+ depth = newState.doc.resolve(pos).depth;
90
+ if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
80
91
  return shouldDescend; //skip over, don't consider it a valid depth
81
92
  }
82
- depth = newState.doc.resolve(pos).depth;
83
93
  anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
84
94
  } else {
85
95
  var _anchorName2;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.handleMouseOver = void 0;
7
- var _whitespace = require("@atlaskit/editor-common/whitespace");
8
7
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
8
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
9
  var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
@@ -15,11 +14,19 @@ var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(t
15
14
  }
16
15
  return false;
17
16
  };
18
- var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(target) {
19
- var _target$textContent;
20
- return target instanceof HTMLDivElement && (target === null || target === void 0 ? void 0 : target.getAttribute('data-drag-handler-node-type')) === 'layoutColumn' &&
21
- // Remove placeholder text
22
- ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.replace(new RegExp(_whitespace.ZERO_WIDTH_SPACE, 'g'), '')) === '';
17
+ var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(node) {
18
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
19
+ var foundNonEmptyNode = false;
20
+ for (var i = 0; i < node.childCount; i++) {
21
+ var _child$firstChild;
22
+ var child = node.child(i);
23
+ if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
24
+ foundNonEmptyNode = true;
25
+ break;
26
+ }
27
+ }
28
+ return !foundNonEmptyNode;
29
+ }
23
30
  };
24
31
  var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, event, api) {
25
32
  var _api$blockControls, _target$classList;
@@ -43,13 +50,15 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
43
50
  if ((0, _experiments.editorExperiment)('nested-dnd', true) && isEmptyNestedParagraphOrHeading(rootElement)) {
44
51
  return false;
45
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
+ }
46
59
  var parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
47
60
  var parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
48
61
 
49
- // Don't show drag handle when there is no content/only placeholder in layout column
50
- if ((0, _advancedLayoutsFlags.isPreRelease2)() && isLayoutColumnWithoutContent(rootElement)) {
51
- return false;
52
- }
53
62
  // We want to exlude handles from showing for direct decendant of table nodes (i.e. nodes in cells)
54
63
  if (parentElement && parentElementType === 'table' && (0, _experiments.editorExperiment)('nested-dnd', true) && (0, _experiments.editorExperiment)('table-nested-dnd', false, {
55
64
  exposure: true
@@ -84,6 +93,11 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
84
93
  } else {
85
94
  pos = view.posAtDOM(rootElement, 0);
86
95
  }
96
+ var node = view.state.doc.nodeAt(pos);
97
+ if ((0, _advancedLayoutsFlags.isPreRelease2)() && node && isLayoutColumnWithoutContent(node)) {
98
+ // Don't show drag handle when there is no content/only placeholder in layout column
99
+ return false;
100
+ }
87
101
  var rootPos;
88
102
  if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
89
103
  rootPos = view.state.doc.resolve(pos).pos;
@@ -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
175
  "data-test-id": "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
  };
@@ -1,10 +1,12 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
- import { isPreRelease2 } from '../utils/advanced-layouts-flags';
4
+ import { isPreRelease1, isPreRelease2 } from '../utils/advanced-layouts-flags';
5
5
  import { getNestedDepth, getNodeAnchor, TYPE_NODE_DEC } from './decorations-common';
6
- const IGNORE_NODES = isPreRelease2() ? ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'] : ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
6
+ const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
7
+ const IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
7
8
  const IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
9
+ const IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT = ['listItem', 'taskList', 'decisionList'];
8
10
  export const shouldDescendIntoNode = node => {
9
11
  // Optimisation to avoid drawing node decorations for empty table cells
10
12
  if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
@@ -13,14 +15,21 @@ export const shouldDescendIntoNode = node => {
13
15
  return false;
14
16
  }
15
17
  }
18
+ if (isPreRelease1()) {
19
+ return !IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT.includes(node.type.name);
20
+ }
16
21
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
17
22
  };
18
- const shouldIgnoreNode = node => {
23
+ const shouldIgnoreNode = (node, ignore_nodes, depth, parent) => {
19
24
  const isEmbedCard = 'embedCard' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_3');
20
25
 
21
26
  // TODO use isWrappedMedia when clean up the feature flag
22
27
  const isMediaSingle = 'mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1');
23
- return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
28
+ const isFirstTableHeaderOrTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && ['tableHeader', 'tableRow'].includes(node.type.name) && isPreRelease1();
29
+ if (isFirstTableHeaderOrTableRow) {
30
+ return false;
31
+ }
32
+ return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
24
33
  };
25
34
 
26
35
  /**
@@ -54,7 +63,8 @@ export const nodeDecorations = (newState, from, to) => {
54
63
  const decs = [];
55
64
  const docFrom = from === undefined || from < 0 ? 0 : from;
56
65
  const docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
57
- newState.doc.nodesBetween(docFrom, docTo, (node, pos, _parent, index) => {
66
+ const ignore_nodes = isPreRelease2() ? IGNORE_NODES_NEXT : IGNORE_NODES;
67
+ newState.doc.nodesBetween(docFrom, docTo, (node, pos, parent, index) => {
58
68
  let depth = 0;
59
69
  let anchorName;
60
70
  const shouldDescend = shouldDescendIntoNode(node);
@@ -65,10 +75,10 @@ export const nodeDecorations = (newState, from, to) => {
65
75
  if (node.isInline) {
66
76
  return false;
67
77
  }
68
- if (shouldIgnoreNode(node)) {
78
+ depth = newState.doc.resolve(pos).depth;
79
+ if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
69
80
  return shouldDescend; //skip over, don't consider it a valid depth
70
81
  }
71
- depth = newState.doc.resolve(pos).depth;
72
82
  anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : `--node-anchor-${node.type.name}-${pos}`;
73
83
  } else {
74
84
  var _anchorName2;
@@ -1,7 +1,6 @@
1
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
2
1
  import { fg } from '@atlaskit/platform-feature-flags';
3
2
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
- import { isPreRelease2 } from '../utils/advanced-layouts-flags';
3
+ import { isPreRelease1, isPreRelease2 } from '../utils/advanced-layouts-flags';
5
4
  const isEmptyNestedParagraphOrHeading = target => {
6
5
  if (target instanceof HTMLHeadingElement || target instanceof HTMLParagraphElement) {
7
6
  var _target$parentElement;
@@ -9,11 +8,19 @@ const isEmptyNestedParagraphOrHeading = target => {
9
8
  }
10
9
  return false;
11
10
  };
12
- const isLayoutColumnWithoutContent = target => {
13
- var _target$textContent;
14
- return target instanceof HTMLDivElement && (target === null || target === void 0 ? void 0 : target.getAttribute('data-drag-handler-node-type')) === 'layoutColumn' &&
15
- // Remove placeholder text
16
- ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.replace(new RegExp(ZERO_WIDTH_SPACE, 'g'), '')) === '';
11
+ const isLayoutColumnWithoutContent = node => {
12
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
13
+ let foundNonEmptyNode = false;
14
+ for (let i = 0; i < node.childCount; i++) {
15
+ var _child$firstChild;
16
+ const child = node.child(i);
17
+ if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
18
+ foundNonEmptyNode = true;
19
+ break;
20
+ }
21
+ }
22
+ return !foundNonEmptyNode;
23
+ }
17
24
  };
18
25
  export const handleMouseOver = (view, event, api) => {
19
26
  var _api$blockControls, _target$classList;
@@ -38,13 +45,15 @@ export const handleMouseOver = (view, event, api) => {
38
45
  if (editorExperiment('nested-dnd', true) && isEmptyNestedParagraphOrHeading(rootElement)) {
39
46
  return false;
40
47
  }
48
+ if (rootElement.getAttribute('data-drag-handler-node-type') === 'media' && isPreRelease1()) {
49
+ rootElement = rootElement.closest('[data-drag-handler-anchor-name][data-drag-handler-node-type="mediaSingle"]');
50
+ if (!rootElement) {
51
+ return false;
52
+ }
53
+ }
41
54
  const parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
42
55
  const parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
43
56
 
44
- // Don't show drag handle when there is no content/only placeholder in layout column
45
- if (isPreRelease2() && isLayoutColumnWithoutContent(rootElement)) {
46
- return false;
47
- }
48
57
  // We want to exlude handles from showing for direct decendant of table nodes (i.e. nodes in cells)
49
58
  if (parentElement && parentElementType === 'table' && editorExperiment('nested-dnd', true) && editorExperiment('table-nested-dnd', false, {
50
59
  exposure: true
@@ -79,6 +88,11 @@ export const handleMouseOver = (view, event, api) => {
79
88
  } else {
80
89
  pos = view.posAtDOM(rootElement, 0);
81
90
  }
91
+ const node = view.state.doc.nodeAt(pos);
92
+ if (isPreRelease2() && node && isLayoutColumnWithoutContent(node)) {
93
+ // Don't show drag handle when there is no content/only placeholder in layout column
94
+ return false;
95
+ }
82
96
  let rootPos;
83
97
  if (editorExperiment('nested-dnd', true)) {
84
98
  rootPos = view.state.doc.resolve(pos).pos;