@atlaskit/editor-plugin-block-controls 2.11.0 → 2.12.0
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 +8 -0
- package/dist/cjs/pm-plugins/decorations-drop-target.js +32 -5
- package/dist/cjs/ui/drop-target-layout.js +79 -0
- package/dist/es2019/pm-plugins/decorations-drop-target.js +28 -0
- package/dist/es2019/ui/drop-target-layout.js +71 -0
- package/dist/esm/pm-plugins/decorations-drop-target.js +27 -0
- package/dist/esm/ui/drop-target-layout.js +72 -0
- package/dist/types/pm-plugins/decorations-drop-target.d.ts +2 -0
- package/dist/types/ui/drop-target-layout.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +2 -0
- package/dist/types-ts4.5/ui/drop-target-layout.d.ts +10 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#157523](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157523)
|
|
8
|
+
[`0ae18423289a5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0ae18423289a5) -
|
|
9
|
+
ED-25289 implement drop zone in between columns
|
|
10
|
+
|
|
3
11
|
## 2.11.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -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("../
|
|
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
|
|
37
|
+
return _consts2.nodeMargins['default'];
|
|
35
38
|
}
|
|
36
39
|
var nodeTypeName = node.type.name;
|
|
37
40
|
if (nodeTypeName === 'heading') {
|
|
38
|
-
return
|
|
41
|
+
return _consts2.nodeMargins["heading".concat(node.attrs.level)] || _consts2.nodeMargins['default'];
|
|
39
42
|
}
|
|
40
|
-
return
|
|
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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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.
|
|
3
|
+
"version": "2.12.0",
|
|
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.
|
|
34
|
+
"@atlaskit/editor-common": "^94.6.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.
|
|
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",
|