@atlaskit/editor-plugin-block-controls 2.11.0 → 2.12.1

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,21 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#157852](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157852)
8
+ [`5d80f01f056a1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5d80f01f056a1) -
9
+ [ux] ED-25473 Remove inline margin top for top node
10
+
11
+ ## 2.12.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#157523](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157523)
16
+ [`0ae18423289a5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0ae18423289a5) -
17
+ ED-25289 implement drop zone in between columns
18
+
3
19
  ## 2.11.0
4
20
 
5
21
  ### Minor Changes
@@ -85,7 +85,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
85
85
  anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : "--node-anchor-".concat(node.type.name, "-").concat(index);
86
86
  }
87
87
  decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$node = {
88
- style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', " ").concat((0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;')
88
+ style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 && !(0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? 'margin-top: 0px;' : '', " ").concat((0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;')
89
89
  }, (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-node-type', node.type.name), (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node), {
90
90
  type: _decorationsCommon.TYPE_NODE_DEC,
91
91
  anchorName: anchorName,
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.findDropTargetDecs = exports.dropTargetDecorations = exports.createDropTargetDecoration = void 0;
7
+ exports.findDropTargetDecs = exports.dropTargetDecorations = exports.createLayoutDropTargetDecoration = exports.createDropTargetDecoration = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("react");
10
10
  var _reactDom = _interopRequireDefault(require("react-dom"));
@@ -12,9 +12,12 @@ var _utils = require("@atlaskit/editor-common/utils");
12
12
  var _view = require("@atlaskit/editor-prosemirror/view");
13
13
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
14
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
15
- var _consts = require("../ui/consts");
15
+ var _consts = require("../consts");
16
+ var _consts2 = require("../ui/consts");
16
17
  var _dropTarget = require("../ui/drop-target");
18
+ var _dropTargetLayout = require("../ui/drop-target-layout");
17
19
  var _dropTargetV = require("../ui/drop-target-v2");
20
+ var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
18
21
  var _dragTargetDebug = require("../utils/drag-target-debug");
19
22
  var _validation = require("../utils/validation");
20
23
  var _decorationsCommon = require("./decorations-common");
@@ -31,13 +34,13 @@ var shouldDescend = function shouldDescend(node) {
31
34
  };
32
35
  var getNodeMargins = function getNodeMargins(node) {
33
36
  if (!node) {
34
- return _consts.nodeMargins['default'];
37
+ return _consts2.nodeMargins['default'];
35
38
  }
36
39
  var nodeTypeName = node.type.name;
37
40
  if (nodeTypeName === 'heading') {
38
- return _consts.nodeMargins["heading".concat(node.attrs.level)] || _consts.nodeMargins['default'];
41
+ return _consts2.nodeMargins["heading".concat(node.attrs.level)] || _consts2.nodeMargins['default'];
39
42
  }
40
- return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
43
+ return _consts2.nodeMargins[nodeTypeName] || _consts2.nodeMargins['default'];
41
44
  };
42
45
  var shouldCollapseMargin = function shouldCollapseMargin(prevNode, nextNode) {
43
46
  if (((prevNode === null || prevNode === void 0 ? void 0 : prevNode.type.name) === 'mediaSingle' || (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type.name) === 'mediaSingle') && (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type.name) !== (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type.name)) {
@@ -112,6 +115,19 @@ var createDropTargetDecoration = exports.createDropTargetDecoration = function c
112
115
  side: side
113
116
  });
114
117
  };
118
+ var createLayoutDropTargetDecoration = exports.createLayoutDropTargetDecoration = function createLayoutDropTargetDecoration(pos, props) {
119
+ return _view.Decoration.widget(pos, function (_, getPos) {
120
+ var element = document.createElement('div');
121
+ element.setAttribute('data-blocks-drop-target-container', 'true');
122
+ element.style.clear = 'unset';
123
+ _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTargetLayout.DropTargetLayout, _objectSpread(_objectSpread({}, props), {}, {
124
+ getPos: getPos
125
+ })), element);
126
+ return element;
127
+ }, {
128
+ type: _decorationsCommon.TYPE_DROP_TARGET_DEC
129
+ });
130
+ };
115
131
  var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
116
132
  (0, _decorationsCommon.unmountDecorations)('data-blocks-drop-target-container');
117
133
  var decs = [];
@@ -135,12 +151,23 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
135
151
  popNodeStack(depth);
136
152
  prevNodeStack.push(node);
137
153
  };
154
+ var isAdvancedLayoutsPreRelease2 = (0, _advancedLayoutsFlags.isPreRelease2)();
138
155
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
139
156
  var depth = 0;
140
157
  // drop target deco at the end position
141
158
  var endPos;
142
159
  if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
143
160
  depth = newState.doc.resolve(pos).depth;
161
+ 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 &&
163
+ // Not the first node
164
+ (parent === null || parent === void 0 ? void 0 : parent.childCount) < _consts.MAX_LAYOUT_COLUMN_SUPPORTED) {
165
+ decs.push(createLayoutDropTargetDecoration(pos, {
166
+ api: api,
167
+ formatMessage: formatMessage
168
+ }));
169
+ }
170
+ }
144
171
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
145
172
  if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
146
173
  pushNodeStack(node, depth);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DropTargetLayout = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
12
+ var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
13
+ var _colors = require("@atlaskit/theme/colors");
14
+ var _dragTargetDebug = require("../utils/drag-target-debug");
15
+ /**
16
+ * @jsxRuntime classic
17
+ * @jsx jsx
18
+ */
19
+
20
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
21
+
22
+ // 8px gap + 16px on left and right
23
+ var DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH = 40;
24
+ var dropTargetLayoutStyle = (0, _react2.css)({
25
+ height: '100%',
26
+ width: "".concat(DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH, "px"),
27
+ transform: 'translateX(-50%)',
28
+ zIndex: 120,
29
+ position: 'relative',
30
+ display: 'flex',
31
+ justifyContent: 'center'
32
+ });
33
+ var dropTargetLayoutHintStyle = (0, _react2.css)({
34
+ height: '100%',
35
+ position: 'relative',
36
+ borderRight: "1px dashed ".concat("var(--ds-background-selected-hovered, ".concat(_colors.B75, ")")),
37
+ width: 0
38
+ });
39
+ var DropTargetLayout = exports.DropTargetLayout = function DropTargetLayout(props) {
40
+ var _api$blockControls2;
41
+ var api = props.api;
42
+ var ref = (0, _react.useRef)(null);
43
+ var _useState = (0, _react.useState)(false),
44
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
45
+ isDraggedOver = _useState2[0],
46
+ setIsDraggedOver = _useState2[1];
47
+ var onDrop = (0, _react.useCallback)(function () {
48
+ var _api$blockControls;
49
+ var _ref = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
50
+ activeNode = _ref.activeNode;
51
+ if (!activeNode) {
52
+ return;
53
+ }
54
+ }, [api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.sharedState]);
55
+ (0, _react.useEffect)(function () {
56
+ if (ref.current) {
57
+ return (0, _adapter.dropTargetForElements)({
58
+ element: ref.current,
59
+ onDragEnter: function onDragEnter() {
60
+ setIsDraggedOver(true);
61
+ },
62
+ onDragLeave: function onDragLeave() {
63
+ setIsDraggedOver(false);
64
+ },
65
+ onDrop: onDrop
66
+ });
67
+ }
68
+ }, [onDrop]);
69
+ return (0, _react2.jsx)("div", {
70
+ ref: ref,
71
+ css: dropTargetLayoutStyle,
72
+ "data-testid": "block-ctrl-drop-indicator"
73
+ }, isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)() ? (0, _react2.jsx)(_box.DropIndicator, {
74
+ edge: "right",
75
+ gap: "-".concat(DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH, "px")
76
+ }) : (0, _react2.jsx)("div", {
77
+ css: dropTargetLayoutHintStyle
78
+ }));
79
+ };
@@ -134,11 +134,29 @@ var withFormatInLayoutStyleFixSelectors = ["".concat(dragHandleContainer, ":firs
134
134
  var withInlineNodeStyleWithChromeFix = (0, _react.css)((0, _defineProperty2.default)({}, withInlineNodeStyleWithChromeFixSelectors, {
135
135
  transform: 'scale(0)'
136
136
  }));
137
- var globalStyles = (0, _react.css)({
137
+ var globalStyles = function globalStyles() {
138
+ return (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? (0, _react.css)({
139
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
140
+ '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"], [data-layout-section="true"])': {
141
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
142
+ marginTop: '0 !important'
143
+ }
144
+ }) : (0, _react.css)({
145
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
146
+ '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
147
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
148
+ marginTop: '0 !important'
149
+ }
150
+ });
151
+ };
152
+ var topLevelNodeMarginStyles = (0, _react.css)({
138
153
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
139
- '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
140
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
141
- marginTop: '0 !important'
154
+ '.ProseMirror': {
155
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
156
+ '> .ProseMirror-widget:first-child + .ProseMirror-gapcursor + *:not([data-layout-section="true"]), > .ProseMirror-widget:first-child + *:not([data-layout-section="true"])': {
157
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
158
+ marginTop: '0 !important'
159
+ }
142
160
  }
143
161
  });
144
162
  var withDividerInPanelStyleFix = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(dividerBodiedInCustomPanelWithNoIconSelector), {
@@ -174,8 +192,8 @@ var withRelativePosStyle = (0, _react.css)({
174
192
  });
175
193
  var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
176
194
  return (0, _react.jsx)(_react.Global, {
177
- styles: [globalStyles, (0, _experiments.editorExperiment)('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, (0, _experiments.editorExperiment)('platform_editor_empty_line_prompt', true, {
195
+ styles: [globalStyles(), (0, _experiments.editorExperiment)('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, (0, _experiments.editorExperiment)('platform_editor_empty_line_prompt', true, {
178
196
  exposure: false
179
- }) ? _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 : undefined]
197
+ }) ? _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] : undefined]
180
198
  });
181
199
  };
@@ -74,7 +74,7 @@ export const nodeDecorations = (newState, from, to) => {
74
74
  anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : `--node-anchor-${node.type.name}-${index}`;
75
75
  }
76
76
  decs.push(Decoration.node(pos, pos + node.nodeSize, {
77
- style: `anchor-name: ${anchorName}; ${pos === 0 ? 'margin-top: 0px;' : ''} ${fg('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;'}`,
77
+ style: `anchor-name: ${anchorName}; ${pos === 0 && !fg('platform_editor_element_dnd_nested_fix_patch_3') ? 'margin-top: 0px;' : ''} ${fg('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;'}`,
78
78
  ['data-drag-handler-anchor-name']: anchorName,
79
79
  ['data-drag-handler-node-type']: node.type.name,
80
80
  ['data-drag-handler-anchor-depth']: `${depth}`
@@ -4,9 +4,12 @@ import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
+ import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
7
8
  import { nodeMargins } from '../ui/consts';
8
9
  import { DropTarget } from '../ui/drop-target';
10
+ import { DropTargetLayout } from '../ui/drop-target-layout';
9
11
  import { DropTargetV2, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET } from '../ui/drop-target-v2';
12
+ import { isPreRelease2 } from '../utils/advanced-layouts-flags';
10
13
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
11
14
  import { canMoveNodeToIndex } from '../utils/validation';
12
15
  import { getNestedDepth, TYPE_DROP_TARGET_DEC, unmountDecorations } from './decorations-common';
@@ -103,6 +106,20 @@ export const createDropTargetDecoration = (pos, props, side, anchorRectCache) =>
103
106
  side
104
107
  });
105
108
  };
109
+ export const createLayoutDropTargetDecoration = (pos, props) => {
110
+ return Decoration.widget(pos, (_, getPos) => {
111
+ const element = document.createElement('div');
112
+ element.setAttribute('data-blocks-drop-target-container', 'true');
113
+ element.style.clear = 'unset';
114
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, {
115
+ ...props,
116
+ getPos
117
+ }), element);
118
+ return element;
119
+ }, {
120
+ type: TYPE_DROP_TARGET_DEC
121
+ });
122
+ };
106
123
  export const dropTargetDecorations = (newState, api, formatMessage, activeNode, anchorRectCache, from, to) => {
107
124
  unmountDecorations('data-blocks-drop-target-container');
108
125
  const decs = [];
@@ -126,12 +143,23 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
126
143
  popNodeStack(depth);
127
144
  prevNodeStack.push(node);
128
145
  };
146
+ const isAdvancedLayoutsPreRelease2 = isPreRelease2();
129
147
  newState.doc.nodesBetween(docFrom, docTo, (node, pos, parent, index) => {
130
148
  let depth = 0;
131
149
  // drop target deco at the end position
132
150
  let endPos;
133
151
  if (editorExperiment('nested-dnd', true)) {
134
152
  depth = newState.doc.resolve(pos).depth;
153
+ if (isAdvancedLayoutsPreRelease2) {
154
+ 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 &&
155
+ // Not the first node
156
+ (parent === null || parent === void 0 ? void 0 : parent.childCount) < MAX_LAYOUT_COLUMN_SUPPORTED) {
157
+ decs.push(createLayoutDropTargetDecoration(pos, {
158
+ api,
159
+ formatMessage
160
+ }));
161
+ }
162
+ }
135
163
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
136
164
  if (fg('platform_editor_drag_and_drop_target_v2')) {
137
165
  pushNodeStack(node, depth);
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { useCallback, useEffect, useRef, useState } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
8
+ import { css, jsx } from '@emotion/react';
9
+ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
10
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
11
+ import { B75 } from '@atlaskit/theme/colors';
12
+ import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
13
+
14
+ // 8px gap + 16px on left and right
15
+ const DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH = 40;
16
+ const dropTargetLayoutStyle = css({
17
+ height: '100%',
18
+ width: `${DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH}px`,
19
+ transform: 'translateX(-50%)',
20
+ zIndex: 120,
21
+ position: 'relative',
22
+ display: 'flex',
23
+ justifyContent: 'center'
24
+ });
25
+ const dropTargetLayoutHintStyle = css({
26
+ height: '100%',
27
+ position: 'relative',
28
+ borderRight: `1px dashed ${`var(--ds-background-selected-hovered, ${B75})`}`,
29
+ width: 0
30
+ });
31
+ export const DropTargetLayout = props => {
32
+ var _api$blockControls2;
33
+ const {
34
+ api
35
+ } = props;
36
+ const ref = useRef(null);
37
+ const [isDraggedOver, setIsDraggedOver] = useState(false);
38
+ const onDrop = useCallback(() => {
39
+ var _api$blockControls;
40
+ const {
41
+ activeNode
42
+ } = (api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {};
43
+ if (!activeNode) {
44
+ return;
45
+ }
46
+ }, [api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.sharedState]);
47
+ useEffect(() => {
48
+ if (ref.current) {
49
+ return dropTargetForElements({
50
+ element: ref.current,
51
+ onDragEnter: () => {
52
+ setIsDraggedOver(true);
53
+ },
54
+ onDragLeave: () => {
55
+ setIsDraggedOver(false);
56
+ },
57
+ onDrop
58
+ });
59
+ }
60
+ }, [onDrop]);
61
+ return jsx("div", {
62
+ ref: ref,
63
+ css: dropTargetLayoutStyle,
64
+ "data-testid": "block-ctrl-drop-indicator"
65
+ }, isDraggedOver || isBlocksDragTargetDebug() ? jsx(DropIndicator, {
66
+ edge: "right",
67
+ gap: `-${DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH}px`
68
+ }) : jsx("div", {
69
+ css: dropTargetLayoutHintStyle
70
+ }));
71
+ };
@@ -127,13 +127,29 @@ const withInlineNodeStyleWithChromeFix = css({
127
127
  transform: 'scale(0)'
128
128
  }
129
129
  });
130
- const globalStyles = css({
130
+ const globalStyles = () => fg('platform_editor_element_dnd_nested_fix_patch_3') ? css({
131
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
132
+ '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"], [data-layout-section="true"])': {
133
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
134
+ marginTop: '0 !important'
135
+ }
136
+ }) : css({
131
137
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
132
138
  '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
133
139
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
134
140
  marginTop: '0 !important'
135
141
  }
136
142
  });
143
+ const topLevelNodeMarginStyles = css({
144
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
145
+ '.ProseMirror': {
146
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
147
+ '> .ProseMirror-widget:first-child + .ProseMirror-gapcursor + *:not([data-layout-section="true"]), > .ProseMirror-widget:first-child + *:not([data-layout-section="true"])': {
148
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
149
+ marginTop: '0 !important'
150
+ }
151
+ }
152
+ });
137
153
  const withDividerInPanelStyleFix = css({
138
154
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-values
139
155
  [`${dividerBodiedInCustomPanelWithNoIconSelector}`]: {
@@ -179,8 +195,8 @@ const withRelativePosStyle = css({
179
195
  });
180
196
  export const GlobalStylesWrapper = () => {
181
197
  return jsx(Global, {
182
- styles: [globalStyles, editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, editorExperiment('platform_editor_empty_line_prompt', true, {
198
+ styles: [globalStyles(), editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, editorExperiment('platform_editor_empty_line_prompt', true, {
183
199
  exposure: false
184
- }) ? 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 : undefined]
200
+ }) ? 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] : undefined]
185
201
  });
186
202
  };
@@ -78,7 +78,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
78
78
  anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : "--node-anchor-".concat(node.type.name, "-").concat(index);
79
79
  }
80
80
  decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$node = {
81
- style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', " ").concat(fg('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;')
81
+ style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 && !fg('platform_editor_element_dnd_nested_fix_patch_3') ? 'margin-top: 0px;' : '', " ").concat(fg('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;')
82
82
  }, _defineProperty(_Decoration$node, 'data-drag-handler-anchor-name', anchorName), _defineProperty(_Decoration$node, 'data-drag-handler-node-type', node.type.name), _defineProperty(_Decoration$node, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node), {
83
83
  type: TYPE_NODE_DEC,
84
84
  anchorName: anchorName,
@@ -7,9 +7,12 @@ import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
7
7
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
+ import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
10
11
  import { nodeMargins } from '../ui/consts';
11
12
  import { DropTarget } from '../ui/drop-target';
13
+ import { DropTargetLayout } from '../ui/drop-target-layout';
12
14
  import { DropTargetV2, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET } from '../ui/drop-target-v2';
15
+ import { isPreRelease2 } from '../utils/advanced-layouts-flags';
13
16
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
14
17
  import { canMoveNodeToIndex } from '../utils/validation';
15
18
  import { getNestedDepth, TYPE_DROP_TARGET_DEC, unmountDecorations } from './decorations-common';
@@ -105,6 +108,19 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
105
108
  side: side
106
109
  });
107
110
  };
111
+ export var createLayoutDropTargetDecoration = function createLayoutDropTargetDecoration(pos, props) {
112
+ return Decoration.widget(pos, function (_, getPos) {
113
+ var element = document.createElement('div');
114
+ element.setAttribute('data-blocks-drop-target-container', 'true');
115
+ element.style.clear = 'unset';
116
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, _objectSpread(_objectSpread({}, props), {}, {
117
+ getPos: getPos
118
+ })), element);
119
+ return element;
120
+ }, {
121
+ type: TYPE_DROP_TARGET_DEC
122
+ });
123
+ };
108
124
  export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
109
125
  unmountDecorations('data-blocks-drop-target-container');
110
126
  var decs = [];
@@ -128,12 +144,23 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
128
144
  popNodeStack(depth);
129
145
  prevNodeStack.push(node);
130
146
  };
147
+ var isAdvancedLayoutsPreRelease2 = isPreRelease2();
131
148
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
132
149
  var depth = 0;
133
150
  // drop target deco at the end position
134
151
  var endPos;
135
152
  if (editorExperiment('nested-dnd', true)) {
136
153
  depth = newState.doc.resolve(pos).depth;
154
+ 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 &&
156
+ // Not the first node
157
+ (parent === null || parent === void 0 ? void 0 : parent.childCount) < MAX_LAYOUT_COLUMN_SUPPORTED) {
158
+ decs.push(createLayoutDropTargetDecoration(pos, {
159
+ api: api,
160
+ formatMessage: formatMessage
161
+ }));
162
+ }
163
+ }
137
164
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
138
165
  if (fg('platform_editor_drag_and_drop_target_v2')) {
139
166
  pushNodeStack(node, depth);
@@ -0,0 +1,72 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /**
3
+ * @jsxRuntime classic
4
+ * @jsx jsx
5
+ */
6
+ import { useCallback, useEffect, useRef, useState } from 'react';
7
+
8
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
9
+ import { css, jsx } from '@emotion/react';
10
+ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
11
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
12
+ import { B75 } from '@atlaskit/theme/colors';
13
+ import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
14
+
15
+ // 8px gap + 16px on left and right
16
+ var DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH = 40;
17
+ var dropTargetLayoutStyle = css({
18
+ height: '100%',
19
+ width: "".concat(DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH, "px"),
20
+ transform: 'translateX(-50%)',
21
+ zIndex: 120,
22
+ position: 'relative',
23
+ display: 'flex',
24
+ justifyContent: 'center'
25
+ });
26
+ var dropTargetLayoutHintStyle = css({
27
+ height: '100%',
28
+ position: 'relative',
29
+ borderRight: "1px dashed ".concat("var(--ds-background-selected-hovered, ".concat(B75, ")")),
30
+ width: 0
31
+ });
32
+ export var DropTargetLayout = function DropTargetLayout(props) {
33
+ var _api$blockControls2;
34
+ var api = props.api;
35
+ var ref = useRef(null);
36
+ var _useState = useState(false),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ isDraggedOver = _useState2[0],
39
+ setIsDraggedOver = _useState2[1];
40
+ var onDrop = useCallback(function () {
41
+ var _api$blockControls;
42
+ var _ref = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
43
+ activeNode = _ref.activeNode;
44
+ if (!activeNode) {
45
+ return;
46
+ }
47
+ }, [api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.sharedState]);
48
+ useEffect(function () {
49
+ if (ref.current) {
50
+ return dropTargetForElements({
51
+ element: ref.current,
52
+ onDragEnter: function onDragEnter() {
53
+ setIsDraggedOver(true);
54
+ },
55
+ onDragLeave: function onDragLeave() {
56
+ setIsDraggedOver(false);
57
+ },
58
+ onDrop: onDrop
59
+ });
60
+ }
61
+ }, [onDrop]);
62
+ return jsx("div", {
63
+ ref: ref,
64
+ css: dropTargetLayoutStyle,
65
+ "data-testid": "block-ctrl-drop-indicator"
66
+ }, isDraggedOver || isBlocksDragTargetDebug() ? jsx(DropIndicator, {
67
+ edge: "right",
68
+ gap: "-".concat(DROP_TARGET_LAYOUT_DROP_ZONE_WIDTH, "px")
69
+ }) : jsx("div", {
70
+ css: dropTargetLayoutHintStyle
71
+ }));
72
+ };
@@ -126,11 +126,29 @@ var withFormatInLayoutStyleFixSelectors = ["".concat(dragHandleContainer, ":firs
126
126
  var withInlineNodeStyleWithChromeFix = css(_defineProperty({}, withInlineNodeStyleWithChromeFixSelectors, {
127
127
  transform: 'scale(0)'
128
128
  }));
129
- var globalStyles = css({
129
+ var globalStyles = function globalStyles() {
130
+ return fg('platform_editor_element_dnd_nested_fix_patch_3') ? css({
131
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
132
+ '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"], [data-layout-section="true"])': {
133
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
134
+ marginTop: '0 !important'
135
+ }
136
+ }) : css({
137
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
138
+ '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
139
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
140
+ marginTop: '0 !important'
141
+ }
142
+ });
143
+ };
144
+ var topLevelNodeMarginStyles = css({
130
145
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
131
- '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
132
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
133
- marginTop: '0 !important'
146
+ '.ProseMirror': {
147
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
148
+ '> .ProseMirror-widget:first-child + .ProseMirror-gapcursor + *:not([data-layout-section="true"]), > .ProseMirror-widget:first-child + *:not([data-layout-section="true"])': {
149
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
150
+ marginTop: '0 !important'
151
+ }
134
152
  }
135
153
  });
136
154
  var withDividerInPanelStyleFix = css(_defineProperty({}, "".concat(dividerBodiedInCustomPanelWithNoIconSelector), {
@@ -166,8 +184,8 @@ var withRelativePosStyle = css({
166
184
  });
167
185
  export var GlobalStylesWrapper = function GlobalStylesWrapper() {
168
186
  return jsx(Global, {
169
- styles: [globalStyles, editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, editorExperiment('platform_editor_empty_line_prompt', true, {
187
+ styles: [globalStyles(), editorExperiment('nested-dnd', true) ? extendedHoverZoneNested() : extendedHoverZone(), getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix, editorExperiment('platform_editor_empty_line_prompt', true, {
170
188
  exposure: false
171
- }) ? 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 : undefined]
189
+ }) ? 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] : undefined]
172
190
  });
173
191
  };
@@ -4,6 +4,7 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { ActiveNode, BlockControlsPlugin } from '../types';
6
6
  import { type DropTargetProps } from '../ui/drop-target';
7
+ import { type DropTargetLayoutProps } from '../ui/drop-target-layout';
7
8
  import { type AnchorRectCache } from '../utils/anchor-utils';
8
9
  /**
9
10
  * Find drop target decorations in the pos range between from and to
@@ -14,4 +15,5 @@ import { type AnchorRectCache } from '../utils/anchor-utils';
14
15
  */
15
16
  export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
16
17
  export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
18
+ export declare const createLayoutDropTargetDecoration: (pos: number, props: Omit<DropTargetLayoutProps, 'getPos'>) => Decoration;
17
19
  export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
@@ -0,0 +1,10 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { type IntlShape } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { BlockControlsPlugin } from '../types';
5
+ export type DropTargetLayoutProps = {
6
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
7
+ getPos: () => number | undefined;
8
+ formatMessage?: IntlShape['formatMessage'];
9
+ };
10
+ export declare const DropTargetLayout: (props: DropTargetLayoutProps) => jsx.JSX.Element;
@@ -4,6 +4,7 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { ActiveNode, BlockControlsPlugin } from '../types';
6
6
  import { type DropTargetProps } from '../ui/drop-target';
7
+ import { type DropTargetLayoutProps } from '../ui/drop-target-layout';
7
8
  import { type AnchorRectCache } from '../utils/anchor-utils';
8
9
  /**
9
10
  * Find drop target decorations in the pos range between from and to
@@ -14,4 +15,5 @@ import { type AnchorRectCache } from '../utils/anchor-utils';
14
15
  */
15
16
  export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
16
17
  export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
18
+ export declare const createLayoutDropTargetDecoration: (pos: number, props: Omit<DropTargetLayoutProps, 'getPos'>) => Decoration;
17
19
  export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
@@ -0,0 +1,10 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { type IntlShape } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { BlockControlsPlugin } from '../types';
5
+ export type DropTargetLayoutProps = {
6
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
7
+ getPos: () => number | undefined;
8
+ formatMessage?: IntlShape['formatMessage'];
9
+ };
10
+ export declare const DropTargetLayout: (props: DropTargetLayoutProps) => jsx.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.11.0",
3
+ "version": "2.12.1",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@atlaskit/adf-schema": "^42.3.1",
34
- "@atlaskit/editor-common": "^94.4.0",
34
+ "@atlaskit/editor-common": "^94.8.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
49
49
  "@atlaskit/primitives": "^12.2.0",
50
50
  "@atlaskit/theme": "^14.0.0",
51
- "@atlaskit/tmp-editor-statsig": "^2.9.0",
51
+ "@atlaskit/tmp-editor-statsig": "^2.10.0",
52
52
  "@atlaskit/tokens": "^2.0.0",
53
53
  "@atlaskit/tooltip": "^18.8.0",
54
54
  "@babel/runtime": "^7.0.0",