@atlaskit/editor-plugin-block-controls 2.21.1 → 2.21.3

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.
@@ -1,267 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = exports.DropTargetV2 = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
- var _react = require("react");
12
- var _react2 = require("@emotion/react");
13
- var _hooks = require("@atlaskit/editor-common/hooks");
14
- var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
15
- var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
16
- var _constants = require("@atlaskit/theme/constants");
17
- var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
- var _decorationsCommon = require("../pm-plugins/decorations-common");
19
- var _activeAnchorTracker = require("../pm-plugins/utils/active-anchor-tracker");
20
- var _anchorUtils = require("../pm-plugins/utils/anchor-utils");
21
- var _dragTargetDebug = require("../pm-plugins/utils/drag-target-debug");
22
- var _inlineDropTarget = require("../pm-plugins/utils/inline-drop-target");
23
- var _consts = require("./consts");
24
- var _inlineDropTarget2 = require("./inline-drop-target");
25
- /**
26
- * @jsxRuntime classic
27
- * @jsx jsx
28
- */
29
-
30
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
31
-
32
- var DEFAULT_DROP_INDICATOR_WIDTH = 760;
33
- var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
34
- var EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
35
- var EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX = '--editor-block-controls-drop-target-zindex';
36
- var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = '--editor-block-controls-drop-indicator-offset';
37
- var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = '--editor-block-controls-drop-indicator-gap';
38
- var styleDropTarget = (0, _react2.css)({
39
- marginLeft: "calc(-1 * var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, ", 0))"),
40
- paddingLeft: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, ", 0)"),
41
- position: 'absolute',
42
- left: '0',
43
- display: 'block',
44
- zIndex: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX, ", 110)"),
45
- transform: "translateY(var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0))")
46
- });
47
- var styleDropIndicator = (0, _react2.css)({
48
- height: '100%',
49
- margin: '0 auto',
50
- position: 'relative',
51
- width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
52
- });
53
- var nestedDropIndicatorStyle = (0, _react2.css)({
54
- position: 'relative'
55
- });
56
- var dropZoneStyles = (0, _react2.css)({
57
- margin: 0,
58
- position: 'absolute',
59
- width: '100%',
60
- zIndex: 110,
61
- minHeight: '4px'
62
- });
63
- var nestedDropZoneStyle = (0, _react2.css)({
64
- left: '4px',
65
- right: '4px',
66
- width: 'unset'
67
- });
68
- var enableDropZone = ['paragraph', 'mediaSingle', 'heading', 'codeBlock', 'decisionList', 'bulletList', 'orderedList', 'taskList', 'extension', 'blockCard'];
69
-
70
- // This z index is used in container like layout
71
- var fullHeightStyleAdjustZIndexStyle = (0, _react2.css)({
72
- zIndex: 0
73
- });
74
- var HoverZone = function HoverZone(_ref) {
75
- var _onDragEnter = _ref.onDragEnter,
76
- onDragLeave = _ref.onDragLeave,
77
- onDrop = _ref.onDrop,
78
- node = _ref.node,
79
- parent = _ref.parent,
80
- editorWidth = _ref.editorWidth,
81
- anchorRectCache = _ref.anchorRectCache,
82
- position = _ref.position,
83
- isNestedDropTarget = _ref.isNestedDropTarget,
84
- dropTargetStyle = _ref.dropTargetStyle;
85
- var ref = (0, _react.useRef)(null);
86
- var isRemainingheight = dropTargetStyle === 'remainingHeight';
87
- var anchorName = (0, _react.useMemo)(function () {
88
- return node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
89
- }, [node]);
90
- var _useActiveAnchorTrack = (0, _activeAnchorTracker.useActiveAnchorTracker)(anchorName),
91
- _useActiveAnchorTrack2 = (0, _slicedToArray2.default)(_useActiveAnchorTrack, 2),
92
- _isActive = _useActiveAnchorTrack2[0],
93
- setActiveAnchor = _useActiveAnchorTrack2[1];
94
- (0, _react.useEffect)(function () {
95
- if (ref.current) {
96
- return (0, _adapter.dropTargetForElements)({
97
- element: ref.current,
98
- onDragEnter: function onDragEnter() {
99
- if (!isNestedDropTarget && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
100
- setActiveAnchor();
101
- }
102
- _onDragEnter();
103
- },
104
- onDragLeave: onDragLeave,
105
- onDrop: onDrop
106
- });
107
- }
108
- }, [isNestedDropTarget, _onDragEnter, onDragLeave, onDrop, setActiveAnchor]);
109
- var hoverZoneUpperStyle = (0, _react.useMemo)(function () {
110
- var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
111
- var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
112
- var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? (0, _anchorUtils.isAnchorSupported)() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0) / 2, "px + ").concat(heightStyleOffset, ")") : '4px';
113
- var transform = position === 'upper' ? "translateY(calc(-100% + ".concat(transformOffset, "))") : "translateY(".concat(transformOffset, ")");
114
- return (0, _react2.css)({
115
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
116
- height: heightStyle,
117
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
118
- transform: transform,
119
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
120
- maxWidth: "".concat(editorWidth || 0, "px")
121
- });
122
- }, [anchorName, anchorRectCache, editorWidth, node === null || node === void 0 ? void 0 : node.type.name, position]);
123
-
124
- /**
125
- * 1. Above the last empty line
126
- * 2. Below the last element
127
- *
128
- * Both cases will take the remaining height of the the container
129
- */
130
- var heightStyle = (0, _react.useMemo)(function () {
131
- // only apply upper drop zone
132
- if (isRemainingheight && position === 'upper') {
133
- // previous node
134
- var _anchorName = node ? (0, _decorationsCommon.getNodeAnchor)(node) : '';
135
- var top = 'unset';
136
- if (_anchorName) {
137
- var enabledDropZone = enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '');
138
- if ((0, _anchorUtils.isAnchorSupported)()) {
139
- top = enabledDropZone ? "calc(anchor(".concat(_anchorName, " 50%))") : "calc(anchor(".concat(_anchorName, " bottom) - 4px)");
140
- } else if (anchorRectCache) {
141
- var preNodeTopPos = anchorRectCache.getTop(_anchorName) || 0;
142
- var prevNodeHeight = anchorRectCache.getHeight(_anchorName) || 0;
143
- top = enabledDropZone ? "calc(".concat(preNodeTopPos, "px + ").concat(prevNodeHeight / 2, "px)") : "calc(".concat(preNodeTopPos, "px + ").concat(prevNodeHeight, "px - 4px)");
144
- } else {
145
- // Should not happen
146
- return null;
147
- }
148
- } else {
149
- // first empty paragraph
150
- top = '4px';
151
- }
152
- return (0, _react2.css)({
153
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
154
- top: top,
155
- bottom: '4px',
156
- height: 'unset',
157
- zIndex: 10,
158
- transform: 'none'
159
- });
160
- }
161
- return null;
162
- }, [anchorRectCache, isRemainingheight, node, position]);
163
- var isFullHeightInLayout = isRemainingheight && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutColumn';
164
- return (0, _react2.jsx)("div", {
165
- ref: ref
166
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
167
- ,
168
- className: "drop-target-hover-zone-".concat(position),
169
- "data-testid": "drop-target-zone-".concat(position)
170
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
171
- ,
172
- css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle,
173
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
174
- hoverZoneUpperStyle,
175
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
176
- heightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
177
- });
178
- };
179
- var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(props) {
180
- var _api$blockControls;
181
- var api = props.api,
182
- getPos = props.getPos,
183
- prevNode = props.prevNode,
184
- nextNode = props.nextNode,
185
- parentNode = props.parentNode,
186
- formatMessage = props.formatMessage,
187
- anchorRectCache = props.anchorRectCache,
188
- _props$dropTargetStyl = props.dropTargetStyle,
189
- dropTargetStyle = _props$dropTargetStyl === void 0 ? 'default' : _props$dropTargetStyl,
190
- isSameLayout = props.isSameLayout;
191
- var _useState = (0, _react.useState)(false),
192
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
193
- isDraggedOver = _useState2[0],
194
- setIsDraggedOver = _useState2[1];
195
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width']),
196
- widthState = _useSharedPluginState.widthState;
197
- var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
198
- var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
199
- activeNode = _ref2.activeNode;
200
- var onDrop = function onDrop() {
201
- if (!activeNode) {
202
- return;
203
- }
204
- var pos = getPos();
205
- if (activeNode && pos !== undefined) {
206
- var _api$core, _api$blockControls2;
207
- var start = activeNode.pos;
208
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos, undefined, formatMessage));
209
- }
210
- };
211
- var dynamicStyle = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({
212
- width: isNestedDropTarget ? 'unset' : '100%'
213
- }, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px")), EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, isNestedDropTarget ? (0, _consts.getNestedNodeLeftPaddingMargin)(parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) : '0'), EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX, (0, _experiments.editorExperiment)('nested-dnd', true) ? _constants.layers.navigation() : _constants.layers.card());
214
- return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(HoverZone, {
215
- onDragEnter: function onDragEnter() {
216
- return setIsDraggedOver(true);
217
- },
218
- onDragLeave: function onDragLeave() {
219
- return setIsDraggedOver(false);
220
- },
221
- onDrop: onDrop,
222
- node: prevNode,
223
- editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
224
- anchorRectCache: anchorRectCache,
225
- position: "upper",
226
- isNestedDropTarget: isNestedDropTarget,
227
- dropTargetStyle: dropTargetStyle
228
- }), (0, _react2.jsx)("div", {
229
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
230
- css: [styleDropTarget, isNestedDropTarget && nestedDropIndicatorStyle]
231
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
232
- ,
233
- style: dynamicStyle,
234
- "data-testid": "block-ctrl-drop-target"
235
- },
236
- // 4px gap to clear expand node border
237
- (isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)("div", {
238
- css: styleDropIndicator,
239
- "data-testid": "block-ctrl-drop-indicator"
240
- }, (0, _react2.jsx)(_box.DropIndicator, {
241
- edge: "bottom"
242
- }))), dropTargetStyle !== 'remainingHeight' && (0, _react2.jsx)(HoverZone, {
243
- onDragEnter: function onDragEnter() {
244
- return setIsDraggedOver(true);
245
- },
246
- onDragLeave: function onDragLeave() {
247
- return setIsDraggedOver(false);
248
- },
249
- onDrop: onDrop,
250
- node: nextNode,
251
- parent: parentNode,
252
- editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
253
- anchorRectCache: anchorRectCache,
254
- position: "lower",
255
- isNestedDropTarget: isNestedDropTarget
256
- }), (0, _inlineDropTarget.shouldAllowInlineDropTarget)(isNestedDropTarget, nextNode, isSameLayout, activeNode) && (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget
257
- // Ignored via go/ees005
258
- // eslint-disable-next-line react/jsx-props-no-spreading
259
- , (0, _extends2.default)({}, props, {
260
- position: "left"
261
- })), (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget
262
- // Ignored via go/ees005
263
- // eslint-disable-next-line react/jsx-props-no-spreading
264
- , (0, _extends2.default)({}, props, {
265
- position: "right"
266
- }))));
267
- };
@@ -1,252 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
7
-
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
- import { css, jsx } from '@emotion/react';
10
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
- import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
12
- import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
13
- import { layers } from '@atlaskit/theme/constants';
14
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
- import { getNodeAnchor } from '../pm-plugins/decorations-common';
16
- import { useActiveAnchorTracker } from '../pm-plugins/utils/active-anchor-tracker';
17
- import { isAnchorSupported } from '../pm-plugins/utils/anchor-utils';
18
- import { isBlocksDragTargetDebug } from '../pm-plugins/utils/drag-target-debug';
19
- import { shouldAllowInlineDropTarget } from '../pm-plugins/utils/inline-drop-target';
20
- import { getNestedNodeLeftPaddingMargin } from './consts';
21
- import { InlineDropTarget } from './inline-drop-target';
22
- const DEFAULT_DROP_INDICATOR_WIDTH = 760;
23
- const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
24
- const EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
25
- const EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX = '--editor-block-controls-drop-target-zindex';
26
- export const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = '--editor-block-controls-drop-indicator-offset';
27
- export const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = '--editor-block-controls-drop-indicator-gap';
28
- const styleDropTarget = css({
29
- marginLeft: `calc(-1 * var(${EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN}, 0))`,
30
- paddingLeft: `var(${EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN}, 0)`,
31
- position: 'absolute',
32
- left: '0',
33
- display: 'block',
34
- zIndex: `var(${EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX}, 110)`,
35
- transform: `translateY(var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET}, 0))`
36
- });
37
- const styleDropIndicator = css({
38
- height: '100%',
39
- margin: '0 auto',
40
- position: 'relative',
41
- width: `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH}, 100%)`
42
- });
43
- const nestedDropIndicatorStyle = css({
44
- position: 'relative'
45
- });
46
- const dropZoneStyles = css({
47
- margin: 0,
48
- position: 'absolute',
49
- width: '100%',
50
- zIndex: 110,
51
- minHeight: '4px'
52
- });
53
- const nestedDropZoneStyle = css({
54
- left: '4px',
55
- right: '4px',
56
- width: 'unset'
57
- });
58
- const enableDropZone = ['paragraph', 'mediaSingle', 'heading', 'codeBlock', 'decisionList', 'bulletList', 'orderedList', 'taskList', 'extension', 'blockCard'];
59
-
60
- // This z index is used in container like layout
61
- const fullHeightStyleAdjustZIndexStyle = css({
62
- zIndex: 0
63
- });
64
- const HoverZone = ({
65
- onDragEnter,
66
- onDragLeave,
67
- onDrop,
68
- node,
69
- parent,
70
- editorWidth,
71
- anchorRectCache,
72
- position,
73
- isNestedDropTarget,
74
- dropTargetStyle
75
- }) => {
76
- const ref = useRef(null);
77
- const isRemainingheight = dropTargetStyle === 'remainingHeight';
78
- const anchorName = useMemo(() => {
79
- return node ? getNodeAnchor(node) : '';
80
- }, [node]);
81
- const [_isActive, setActiveAnchor] = useActiveAnchorTracker(anchorName);
82
- useEffect(() => {
83
- if (ref.current) {
84
- return dropTargetForElements({
85
- element: ref.current,
86
- onDragEnter: () => {
87
- if (!isNestedDropTarget && editorExperiment('advanced_layouts', true)) {
88
- setActiveAnchor();
89
- }
90
- onDragEnter();
91
- },
92
- onDragLeave,
93
- onDrop
94
- });
95
- }
96
- }, [isNestedDropTarget, onDragEnter, onDragLeave, onDrop, setActiveAnchor]);
97
- const hoverZoneUpperStyle = useMemo(() => {
98
- const heightStyleOffset = `var(--editor-block-controls-drop-indicator-gap, 0)/2`;
99
- const transformOffset = `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET}, 0)`;
100
- const heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? `calc(anchor-size(${anchorName} height)/2 + ${heightStyleOffset})` : `calc(${((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0) / 2}px + ${heightStyleOffset})` : '4px';
101
- const transform = position === 'upper' ? `translateY(calc(-100% + ${transformOffset}))` : `translateY(${transformOffset})`;
102
- return css({
103
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
104
- height: heightStyle,
105
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
106
- transform: transform,
107
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
108
- maxWidth: `${editorWidth || 0}px`
109
- });
110
- }, [anchorName, anchorRectCache, editorWidth, node === null || node === void 0 ? void 0 : node.type.name, position]);
111
-
112
- /**
113
- * 1. Above the last empty line
114
- * 2. Below the last element
115
- *
116
- * Both cases will take the remaining height of the the container
117
- */
118
- const heightStyle = useMemo(() => {
119
- // only apply upper drop zone
120
- if (isRemainingheight && position === 'upper') {
121
- // previous node
122
- const anchorName = node ? getNodeAnchor(node) : '';
123
- let top = 'unset';
124
- if (anchorName) {
125
- const enabledDropZone = enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '');
126
- if (isAnchorSupported()) {
127
- top = enabledDropZone ? `calc(anchor(${anchorName} 50%))` : `calc(anchor(${anchorName} bottom) - 4px)`;
128
- } else if (anchorRectCache) {
129
- const preNodeTopPos = anchorRectCache.getTop(anchorName) || 0;
130
- const prevNodeHeight = anchorRectCache.getHeight(anchorName) || 0;
131
- top = enabledDropZone ? `calc(${preNodeTopPos}px + ${prevNodeHeight / 2}px)` : `calc(${preNodeTopPos}px + ${prevNodeHeight}px - 4px)`;
132
- } else {
133
- // Should not happen
134
- return null;
135
- }
136
- } else {
137
- // first empty paragraph
138
- top = '4px';
139
- }
140
- return css({
141
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
142
- top: top,
143
- bottom: '4px',
144
- height: 'unset',
145
- zIndex: 10,
146
- transform: 'none'
147
- });
148
- }
149
- return null;
150
- }, [anchorRectCache, isRemainingheight, node, position]);
151
- const isFullHeightInLayout = isRemainingheight && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutColumn';
152
- return jsx("div", {
153
- ref: ref
154
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
155
- ,
156
- className: `drop-target-hover-zone-${position}`,
157
- "data-testid": `drop-target-zone-${position}`
158
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
159
- ,
160
- css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle,
161
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
162
- hoverZoneUpperStyle,
163
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
164
- heightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
165
- });
166
- };
167
- export const DropTargetV2 = props => {
168
- var _api$blockControls;
169
- const {
170
- api,
171
- getPos,
172
- prevNode,
173
- nextNode,
174
- parentNode,
175
- formatMessage,
176
- anchorRectCache,
177
- dropTargetStyle = 'default',
178
- isSameLayout
179
- } = props;
180
- const [isDraggedOver, setIsDraggedOver] = useState(false);
181
- const {
182
- widthState
183
- } = useSharedPluginState(api, ['width']);
184
- const isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
185
- const {
186
- activeNode
187
- } = (api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {};
188
- const onDrop = () => {
189
- if (!activeNode) {
190
- return;
191
- }
192
- const pos = getPos();
193
- if (activeNode && pos !== undefined) {
194
- var _api$core, _api$blockControls2, _api$blockControls2$c;
195
- const {
196
- pos: start
197
- } = activeNode;
198
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.moveNode(start, pos, undefined, formatMessage));
199
- }
200
- };
201
- const dynamicStyle = {
202
- width: isNestedDropTarget ? 'unset' : '100%',
203
- [EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH]: isNestedDropTarget ? '100%' : `${(widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH}px`,
204
- [EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN]: isNestedDropTarget ? getNestedNodeLeftPaddingMargin(parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) : '0',
205
- [EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX]: editorExperiment('nested-dnd', true) ? layers.navigation() : layers.card()
206
- };
207
- return jsx(Fragment, null, jsx(HoverZone, {
208
- onDragEnter: () => setIsDraggedOver(true),
209
- onDragLeave: () => setIsDraggedOver(false),
210
- onDrop: onDrop,
211
- node: prevNode,
212
- editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
213
- anchorRectCache: anchorRectCache,
214
- position: "upper",
215
- isNestedDropTarget: isNestedDropTarget,
216
- dropTargetStyle: dropTargetStyle
217
- }), jsx("div", {
218
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
219
- css: [styleDropTarget, isNestedDropTarget && nestedDropIndicatorStyle]
220
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
221
- ,
222
- style: dynamicStyle,
223
- "data-testid": "block-ctrl-drop-target"
224
- },
225
- // 4px gap to clear expand node border
226
- (isDraggedOver || isBlocksDragTargetDebug()) && jsx("div", {
227
- css: styleDropIndicator,
228
- "data-testid": "block-ctrl-drop-indicator"
229
- }, jsx(DropIndicator, {
230
- edge: "bottom"
231
- }))), dropTargetStyle !== 'remainingHeight' && jsx(HoverZone, {
232
- onDragEnter: () => setIsDraggedOver(true),
233
- onDragLeave: () => setIsDraggedOver(false),
234
- onDrop: onDrop,
235
- node: nextNode,
236
- parent: parentNode,
237
- editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
238
- anchorRectCache: anchorRectCache,
239
- position: "lower",
240
- isNestedDropTarget: isNestedDropTarget
241
- }), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode, isSameLayout, activeNode) && jsx(Fragment, null, jsx(InlineDropTarget
242
- // Ignored via go/ees005
243
- // eslint-disable-next-line react/jsx-props-no-spreading
244
- , _extends({}, props, {
245
- position: "left"
246
- })), jsx(InlineDropTarget
247
- // Ignored via go/ees005
248
- // eslint-disable-next-line react/jsx-props-no-spreading
249
- , _extends({}, props, {
250
- position: "right"
251
- }))));
252
- };