@atlaskit/editor-plugin-block-controls 1.11.0 → 1.11.2
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 +21 -0
- package/dist/cjs/pm-plugins/decorations.js +6 -1
- package/dist/cjs/pm-plugins/main.js +22 -20
- package/dist/cjs/ui/drop-target.js +41 -28
- package/dist/es2019/pm-plugins/decorations.js +6 -1
- package/dist/es2019/pm-plugins/main.js +13 -18
- package/dist/es2019/ui/drop-target.js +40 -26
- package/dist/esm/pm-plugins/decorations.js +6 -1
- package/dist/esm/pm-plugins/main.js +22 -20
- package/dist/esm/ui/drop-target.js +41 -28
- package/dist/types/ui/drop-target.d.ts +2 -1
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.11.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#129108](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129108)
|
|
8
|
+
[`c3bcb8b4001bd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3bcb8b4001bd) -
|
|
9
|
+
ED-24540 Clean up droptarget decorations after dropping in nested nodes to fix node splitting
|
|
10
|
+
issue
|
|
11
|
+
- [#129411](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129411)
|
|
12
|
+
[`2cfee5779f921`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2cfee5779f921) -
|
|
13
|
+
ED-24456 improve drop target vertical position for nested nodes
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 1.11.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#128476](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128476)
|
|
21
|
+
[`e6ccffdd6fe90`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e6ccffdd6fe90) -
|
|
22
|
+
ED-24408 fix nested drop target indicator location and appearance
|
|
23
|
+
|
|
3
24
|
## 1.11.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
|
@@ -48,15 +48,18 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
48
48
|
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
49
49
|
depth = newState.doc.resolve(pos).depth;
|
|
50
50
|
if (node.isInline || !parent) {
|
|
51
|
+
prevNode = node;
|
|
51
52
|
return false;
|
|
52
53
|
}
|
|
53
54
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
55
|
+
prevNode = node;
|
|
54
56
|
return true; //skip over, don't consider it a valid depth
|
|
55
57
|
}
|
|
56
58
|
var canDrop = activeNodeType && (0, _validation.canMoveToIndex)(parent, index, nodeType);
|
|
57
59
|
|
|
58
60
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
59
61
|
if (!canDrop && !(0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
62
|
+
prevNode = node;
|
|
60
63
|
return false; //not valid pos, so nested not valid either
|
|
61
64
|
}
|
|
62
65
|
decorationState.push({
|
|
@@ -85,12 +88,14 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
85
88
|
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? pos : index,
|
|
86
89
|
formatMessage: formatMessage,
|
|
87
90
|
prevNode: prevNode,
|
|
88
|
-
nextNode: node
|
|
91
|
+
nextNode: node,
|
|
92
|
+
parentNode: parent
|
|
89
93
|
})));
|
|
90
94
|
if (endDec) {
|
|
91
95
|
decs.push(createDropTargetDecoration(endDec.pos, /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
92
96
|
api: api,
|
|
93
97
|
id: endDec.id,
|
|
98
|
+
parentNode: parent,
|
|
94
99
|
formatMessage: formatMessage
|
|
95
100
|
})));
|
|
96
101
|
}
|
|
@@ -138,8 +138,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
138
138
|
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
139
139
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
140
140
|
}
|
|
141
|
-
var dropTargetLen = decorations.find(
|
|
142
|
-
var spec = _ref8.spec;
|
|
141
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
143
142
|
return spec.type === 'drop-target-decoration';
|
|
144
143
|
}).length;
|
|
145
144
|
|
|
@@ -164,8 +163,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
164
163
|
|
|
165
164
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
166
165
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
167
|
-
var oldNodeDecs = decorations.find(
|
|
168
|
-
var spec = _ref9.spec;
|
|
166
|
+
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
169
167
|
return spec.type !== 'drop-target-decoration';
|
|
170
168
|
});
|
|
171
169
|
decorations = decorations.remove(oldNodeDecs);
|
|
@@ -202,8 +200,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
202
200
|
|
|
203
201
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
204
202
|
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
|
|
205
|
-
var _oldHandle = decorations.find(
|
|
206
|
-
var spec = _ref10.spec;
|
|
203
|
+
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
207
204
|
return spec.id === 'drag-handle';
|
|
208
205
|
});
|
|
209
206
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -213,8 +210,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
213
210
|
|
|
214
211
|
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
215
212
|
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
216
|
-
var _oldHandle2 = decorations.find(
|
|
217
|
-
var spec = _ref11.spec;
|
|
213
|
+
var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
|
|
218
214
|
return spec.id === 'drag-handle';
|
|
219
215
|
});
|
|
220
216
|
decorations = decorations.remove(_oldHandle2);
|
|
@@ -222,14 +218,20 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
222
218
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
223
219
|
}
|
|
224
220
|
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
225
|
-
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging)
|
|
221
|
+
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
226
222
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
224
|
+
var remainingDecs = decorations.find(undefined, undefined, function (spec) {
|
|
225
|
+
return spec.type !== 'drop-target-decoration';
|
|
226
|
+
});
|
|
227
|
+
decorations = _view.DecorationSet.create(newState.doc, remainingDecs);
|
|
228
|
+
} else {
|
|
229
|
+
// Remove drop target decoration when dragging stops
|
|
230
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
231
|
+
return spec.type === 'drop-target-decoration';
|
|
232
|
+
});
|
|
233
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
234
|
+
}
|
|
233
235
|
}
|
|
234
236
|
if (api) {
|
|
235
237
|
// Add drop targets when node is being dragged
|
|
@@ -246,9 +248,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
246
248
|
|
|
247
249
|
//Map drop target decoration positions when the document changes
|
|
248
250
|
if (shouldMapDropTargets) {
|
|
249
|
-
decorationState = decorationState.map(function (
|
|
250
|
-
var id =
|
|
251
|
-
pos =
|
|
251
|
+
decorationState = decorationState.map(function (_ref8) {
|
|
252
|
+
var id = _ref8.id,
|
|
253
|
+
pos = _ref8.pos;
|
|
252
254
|
return {
|
|
253
255
|
id: id,
|
|
254
256
|
pos: tr.mapping.map(pos)
|
|
@@ -261,8 +263,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
261
263
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
262
264
|
}
|
|
263
265
|
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
264
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
265
|
-
var spec =
|
|
266
|
+
var hasNodeDecoration = decorations.find().some(function (_ref9) {
|
|
267
|
+
var spec = _ref9.spec;
|
|
266
268
|
return spec.type === 'node-decoration';
|
|
267
269
|
});
|
|
268
270
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.DropTarget = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
10
|
var _react = require("react");
|
|
10
11
|
var _react2 = require("@emotion/react");
|
|
@@ -22,6 +23,7 @@ var _consts = require("./consts");
|
|
|
22
23
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
23
24
|
|
|
24
25
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
26
|
+
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
25
27
|
var styleDropTarget = (0, _react2.css)({
|
|
26
28
|
height: "var(--ds-space-100, 8px)",
|
|
27
29
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -31,17 +33,25 @@ var styleDropTarget = (0, _react2.css)({
|
|
|
31
33
|
display: 'block',
|
|
32
34
|
zIndex: _constants.layers.card()
|
|
33
35
|
});
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
var styleDropIndicator = (0, _react2.css)({
|
|
37
|
+
height: '100%',
|
|
38
|
+
margin: '0 auto',
|
|
39
|
+
position: 'relative',
|
|
40
|
+
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
41
|
+
});
|
|
42
|
+
var nestedDropIndicatorStyle = (0, _react2.css)({
|
|
43
|
+
position: 'relative'
|
|
44
|
+
});
|
|
45
|
+
var marginLookupMap = Object.fromEntries(Object.entries(_consts.spaceLookupMap).map(function (_ref, i) {
|
|
37
46
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
38
47
|
key = _ref2[0],
|
|
39
48
|
value = _ref2[1];
|
|
40
|
-
return [key,
|
|
41
|
-
|
|
49
|
+
return [key,
|
|
50
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
51
|
+
(0, _react2.css)({
|
|
52
|
+
transform: "translateY(".concat(value, ")")
|
|
42
53
|
})];
|
|
43
54
|
}));
|
|
44
|
-
var BASE_LINE_MARGIN = -8;
|
|
45
55
|
var getNodeMargins = function getNodeMargins(node) {
|
|
46
56
|
if (!node) {
|
|
47
57
|
return _consts.nodeMargins['default'];
|
|
@@ -52,30 +62,25 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
52
62
|
}
|
|
53
63
|
return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
|
|
54
64
|
};
|
|
55
|
-
var
|
|
65
|
+
var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
|
|
56
66
|
if (!prevNode || !nextNode) {
|
|
57
67
|
return null;
|
|
58
68
|
}
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
} else {
|
|
65
|
-
return marginLookupMap[space];
|
|
69
|
+
var top = getNodeMargins(nextNode).top;
|
|
70
|
+
var bottom = getNodeMargins(prevNode).bottom;
|
|
71
|
+
var merginDiff = Math.round((top - bottom) / 2);
|
|
72
|
+
if (merginDiff === 0) {
|
|
73
|
+
return null;
|
|
66
74
|
}
|
|
75
|
+
var offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
76
|
+
return marginLookupMap[offset];
|
|
67
77
|
};
|
|
68
|
-
var styleDropIndicator = (0, _react2.css)({
|
|
69
|
-
height: '100%',
|
|
70
|
-
width: '100%',
|
|
71
|
-
margin: '0 auto',
|
|
72
|
-
position: 'relative'
|
|
73
|
-
});
|
|
74
78
|
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
75
79
|
var api = _ref3.api,
|
|
76
80
|
id = _ref3.id,
|
|
77
81
|
prevNode = _ref3.prevNode,
|
|
78
82
|
nextNode = _ref3.nextNode,
|
|
83
|
+
parentNode = _ref3.parentNode,
|
|
79
84
|
formatMessage = _ref3.formatMessage;
|
|
80
85
|
var ref = (0, _react.useRef)(null);
|
|
81
86
|
var _useState = (0, _react.useState)(false),
|
|
@@ -84,7 +89,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
84
89
|
setIsDraggedOver = _useState2[1];
|
|
85
90
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width']),
|
|
86
91
|
widthState = _useSharedPluginState.widthState;
|
|
87
|
-
var
|
|
92
|
+
var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
|
|
88
93
|
(0, _react.useEffect)(function () {
|
|
89
94
|
var element = ref.current;
|
|
90
95
|
if (!element) {
|
|
@@ -121,23 +126,31 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
121
126
|
}
|
|
122
127
|
});
|
|
123
128
|
}, [id, api, formatMessage]);
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
var dropTargetOffsetStyle = (0, _react.useMemo)(function () {
|
|
130
|
+
/**
|
|
131
|
+
* First child of a nested node.
|
|
132
|
+
* Disable the position adjustment temporarily
|
|
133
|
+
*/
|
|
134
|
+
if (parentNode === prevNode) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
138
|
+
}, [prevNode, nextNode, parentNode]);
|
|
139
|
+
var widthStyle = (0, _defineProperty2.default)({}, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px"));
|
|
127
140
|
return (
|
|
128
141
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
129
142
|
(0, _react2.jsx)("div", {
|
|
130
143
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
131
|
-
css: [styleDropTarget,
|
|
144
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
145
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
146
|
+
,
|
|
147
|
+
style: widthStyle,
|
|
132
148
|
ref: ref,
|
|
133
149
|
"data-testid": "block-ctrl-drop-target"
|
|
134
150
|
},
|
|
135
151
|
// 4px gap to clear expand node border
|
|
136
152
|
(isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)("div", {
|
|
137
153
|
css: styleDropIndicator,
|
|
138
|
-
style: {
|
|
139
|
-
width: "".concat(lineLength, "px")
|
|
140
|
-
},
|
|
141
154
|
"data-testid": "block-ctrl-drop-indicator"
|
|
142
155
|
}, (0, _react2.jsx)(_box.DropIndicator, {
|
|
143
156
|
edge: "bottom",
|
|
@@ -38,15 +38,18 @@ export const dropTargetDecorations = (oldState, newState, api, formatMessage, ac
|
|
|
38
38
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
39
39
|
depth = newState.doc.resolve(pos).depth;
|
|
40
40
|
if (node.isInline || !parent) {
|
|
41
|
+
prevNode = node;
|
|
41
42
|
return false;
|
|
42
43
|
}
|
|
43
44
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
45
|
+
prevNode = node;
|
|
44
46
|
return true; //skip over, don't consider it a valid depth
|
|
45
47
|
}
|
|
46
48
|
const canDrop = activeNodeType && canMoveToIndex(parent, index, nodeType);
|
|
47
49
|
|
|
48
50
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
49
51
|
if (!canDrop && !isBlocksDragTargetDebug()) {
|
|
52
|
+
prevNode = node;
|
|
50
53
|
return false; //not valid pos, so nested not valid either
|
|
51
54
|
}
|
|
52
55
|
decorationState.push({
|
|
@@ -75,12 +78,14 @@ export const dropTargetDecorations = (oldState, newState, api, formatMessage, ac
|
|
|
75
78
|
id: fg('platform_editor_elements_dnd_nested') ? pos : index,
|
|
76
79
|
formatMessage,
|
|
77
80
|
prevNode,
|
|
78
|
-
nextNode: node
|
|
81
|
+
nextNode: node,
|
|
82
|
+
parentNode: parent
|
|
79
83
|
})));
|
|
80
84
|
if (endDec) {
|
|
81
85
|
decs.push(createDropTargetDecoration(endDec.pos, /*#__PURE__*/createElement(DropTarget, {
|
|
82
86
|
api,
|
|
83
87
|
id: endDec.id,
|
|
88
|
+
parentNode: parent,
|
|
84
89
|
formatMessage
|
|
85
90
|
})));
|
|
86
91
|
}
|
|
@@ -131,9 +131,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
131
131
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
132
132
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
133
133
|
}
|
|
134
|
-
const dropTargetLen = decorations.find().
|
|
135
|
-
spec
|
|
136
|
-
}) => spec.type === 'drop-target-decoration').length;
|
|
134
|
+
const dropTargetLen = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration').length;
|
|
137
135
|
|
|
138
136
|
//TODO: Fix this logic for nested scenarios
|
|
139
137
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
@@ -157,9 +155,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
157
155
|
|
|
158
156
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
159
157
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
160
|
-
const oldNodeDecs = decorations.find()
|
|
161
|
-
spec
|
|
162
|
-
}) => spec.type !== 'drop-target-decoration');
|
|
158
|
+
const oldNodeDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
|
|
163
159
|
decorations = decorations.remove(oldNodeDecs);
|
|
164
160
|
const nodeDecs = nodeDecorations(newState);
|
|
165
161
|
decorations = decorations.add(newState.doc, [...nodeDecs]);
|
|
@@ -194,9 +190,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
194
190
|
|
|
195
191
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
196
192
|
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
|
|
197
|
-
const oldHandle = decorations.find()
|
|
198
|
-
spec
|
|
199
|
-
}) => spec.id === 'drag-handle');
|
|
193
|
+
const oldHandle = decorations.find(undefined, undefined, spec => spec.id === 'drag-handle');
|
|
200
194
|
decorations = decorations.remove(oldHandle);
|
|
201
195
|
const decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
202
196
|
decorations = decorations.add(newState.doc, [decs]);
|
|
@@ -204,21 +198,22 @@ export const createPlugin = (api, getIntl) => {
|
|
|
204
198
|
|
|
205
199
|
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
206
200
|
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
207
|
-
const oldHandle = decorations.find()
|
|
208
|
-
spec
|
|
209
|
-
}) => spec.id === 'drag-handle');
|
|
201
|
+
const oldHandle = decorations.find(undefined, undefined, spec => spec.id === 'drag-handle');
|
|
210
202
|
decorations = decorations.remove(oldHandle);
|
|
211
203
|
const decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
212
204
|
decorations = decorations.add(newState.doc, [decs]);
|
|
213
205
|
}
|
|
214
206
|
const shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
215
|
-
const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging)
|
|
207
|
+
const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
216
208
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
209
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
210
|
+
const remainingDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
|
|
211
|
+
decorations = DecorationSet.create(newState.doc, remainingDecs);
|
|
212
|
+
} else {
|
|
213
|
+
// Remove drop target decoration when dragging stops
|
|
214
|
+
const dropTargetDecs = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration');
|
|
215
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
216
|
+
}
|
|
222
217
|
}
|
|
223
218
|
if (api) {
|
|
224
219
|
// Add drop targets when node is being dragged
|
|
@@ -13,6 +13,7 @@ import { layers } from '@atlaskit/theme/constants';
|
|
|
13
13
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
14
14
|
import { nodeMargins, spaceLookupMap } from './consts';
|
|
15
15
|
const DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
16
|
+
const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
16
17
|
const styleDropTarget = css({
|
|
17
18
|
height: "var(--ds-space-100, 8px)",
|
|
18
19
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -22,12 +23,20 @@ const styleDropTarget = css({
|
|
|
22
23
|
display: 'block',
|
|
23
24
|
zIndex: layers.card()
|
|
24
25
|
});
|
|
25
|
-
const
|
|
26
|
+
const styleDropIndicator = css({
|
|
27
|
+
height: '100%',
|
|
28
|
+
margin: '0 auto',
|
|
29
|
+
position: 'relative',
|
|
30
|
+
width: `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH}, 100%)`
|
|
31
|
+
});
|
|
32
|
+
const nestedDropIndicatorStyle = css({
|
|
33
|
+
position: 'relative'
|
|
34
|
+
});
|
|
35
|
+
const marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(([key, value], i) => [key,
|
|
26
36
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
css({
|
|
38
|
+
transform: `translateY(${value})`
|
|
29
39
|
})]));
|
|
30
|
-
const BASE_LINE_MARGIN = -8;
|
|
31
40
|
const getNodeMargins = node => {
|
|
32
41
|
if (!node) {
|
|
33
42
|
return nodeMargins['default'];
|
|
@@ -38,30 +47,25 @@ const getNodeMargins = node => {
|
|
|
38
47
|
}
|
|
39
48
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
40
49
|
};
|
|
41
|
-
const
|
|
50
|
+
const getDropTargetOffsetStyle = (prevNode, nextNode) => {
|
|
42
51
|
if (!prevNode || !nextNode) {
|
|
43
52
|
return null;
|
|
44
53
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
} else {
|
|
51
|
-
return marginLookupMap[space];
|
|
54
|
+
const top = getNodeMargins(nextNode).top;
|
|
55
|
+
const bottom = getNodeMargins(prevNode).bottom;
|
|
56
|
+
const merginDiff = Math.round((top - bottom) / 2);
|
|
57
|
+
if (merginDiff === 0) {
|
|
58
|
+
return null;
|
|
52
59
|
}
|
|
60
|
+
const offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
61
|
+
return marginLookupMap[offset];
|
|
53
62
|
};
|
|
54
|
-
const styleDropIndicator = css({
|
|
55
|
-
height: '100%',
|
|
56
|
-
width: '100%',
|
|
57
|
-
margin: '0 auto',
|
|
58
|
-
position: 'relative'
|
|
59
|
-
});
|
|
60
63
|
export const DropTarget = ({
|
|
61
64
|
api,
|
|
62
65
|
id,
|
|
63
66
|
prevNode,
|
|
64
67
|
nextNode,
|
|
68
|
+
parentNode,
|
|
65
69
|
formatMessage
|
|
66
70
|
}) => {
|
|
67
71
|
const ref = useRef(null);
|
|
@@ -69,7 +73,7 @@ export const DropTarget = ({
|
|
|
69
73
|
const {
|
|
70
74
|
widthState
|
|
71
75
|
} = useSharedPluginState(api, ['width']);
|
|
72
|
-
const
|
|
76
|
+
const isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
|
|
73
77
|
useEffect(() => {
|
|
74
78
|
const element = ref.current;
|
|
75
79
|
if (!element) {
|
|
@@ -106,23 +110,33 @@ export const DropTarget = ({
|
|
|
106
110
|
}
|
|
107
111
|
});
|
|
108
112
|
}, [id, api, formatMessage]);
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
const dropTargetOffsetStyle = useMemo(() => {
|
|
114
|
+
/**
|
|
115
|
+
* First child of a nested node.
|
|
116
|
+
* Disable the position adjustment temporarily
|
|
117
|
+
*/
|
|
118
|
+
if (parentNode === prevNode) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
122
|
+
}, [prevNode, nextNode, parentNode]);
|
|
123
|
+
const widthStyle = {
|
|
124
|
+
[EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH]: isNestedDropTarget ? '100%' : `${(widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH}px`
|
|
125
|
+
};
|
|
112
126
|
return (
|
|
113
127
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
114
128
|
jsx("div", {
|
|
115
129
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
116
|
-
css: [styleDropTarget,
|
|
130
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
131
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
132
|
+
,
|
|
133
|
+
style: widthStyle,
|
|
117
134
|
ref: ref,
|
|
118
135
|
"data-testid": "block-ctrl-drop-target"
|
|
119
136
|
},
|
|
120
137
|
// 4px gap to clear expand node border
|
|
121
138
|
(isDraggedOver || isBlocksDragTargetDebug()) && jsx("div", {
|
|
122
139
|
css: styleDropIndicator,
|
|
123
|
-
style: {
|
|
124
|
-
width: `${lineLength}px`
|
|
125
|
-
},
|
|
126
140
|
"data-testid": "block-ctrl-drop-indicator"
|
|
127
141
|
}, jsx(DropIndicator, {
|
|
128
142
|
edge: "bottom",
|
|
@@ -41,15 +41,18 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
41
41
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
42
42
|
depth = newState.doc.resolve(pos).depth;
|
|
43
43
|
if (node.isInline || !parent) {
|
|
44
|
+
prevNode = node;
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
47
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
48
|
+
prevNode = node;
|
|
47
49
|
return true; //skip over, don't consider it a valid depth
|
|
48
50
|
}
|
|
49
51
|
var canDrop = activeNodeType && canMoveToIndex(parent, index, nodeType);
|
|
50
52
|
|
|
51
53
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
52
54
|
if (!canDrop && !isBlocksDragTargetDebug()) {
|
|
55
|
+
prevNode = node;
|
|
53
56
|
return false; //not valid pos, so nested not valid either
|
|
54
57
|
}
|
|
55
58
|
decorationState.push({
|
|
@@ -78,12 +81,14 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
78
81
|
id: fg('platform_editor_elements_dnd_nested') ? pos : index,
|
|
79
82
|
formatMessage: formatMessage,
|
|
80
83
|
prevNode: prevNode,
|
|
81
|
-
nextNode: node
|
|
84
|
+
nextNode: node,
|
|
85
|
+
parentNode: parent
|
|
82
86
|
})));
|
|
83
87
|
if (endDec) {
|
|
84
88
|
decs.push(createDropTargetDecoration(endDec.pos, /*#__PURE__*/createElement(DropTarget, {
|
|
85
89
|
api: api,
|
|
86
90
|
id: endDec.id,
|
|
91
|
+
parentNode: parent,
|
|
87
92
|
formatMessage: formatMessage
|
|
88
93
|
})));
|
|
89
94
|
}
|
|
@@ -131,8 +131,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
131
131
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
132
132
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
133
133
|
}
|
|
134
|
-
var dropTargetLen = decorations.find(
|
|
135
|
-
var spec = _ref8.spec;
|
|
134
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
136
135
|
return spec.type === 'drop-target-decoration';
|
|
137
136
|
}).length;
|
|
138
137
|
|
|
@@ -157,8 +156,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
157
156
|
|
|
158
157
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
159
158
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
160
|
-
var oldNodeDecs = decorations.find(
|
|
161
|
-
var spec = _ref9.spec;
|
|
159
|
+
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
162
160
|
return spec.type !== 'drop-target-decoration';
|
|
163
161
|
});
|
|
164
162
|
decorations = decorations.remove(oldNodeDecs);
|
|
@@ -195,8 +193,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
195
193
|
|
|
196
194
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
197
195
|
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
|
|
198
|
-
var _oldHandle = decorations.find(
|
|
199
|
-
var spec = _ref10.spec;
|
|
196
|
+
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
200
197
|
return spec.id === 'drag-handle';
|
|
201
198
|
});
|
|
202
199
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -206,8 +203,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
206
203
|
|
|
207
204
|
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
208
205
|
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
209
|
-
var _oldHandle2 = decorations.find(
|
|
210
|
-
var spec = _ref11.spec;
|
|
206
|
+
var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
|
|
211
207
|
return spec.id === 'drag-handle';
|
|
212
208
|
});
|
|
213
209
|
decorations = decorations.remove(_oldHandle2);
|
|
@@ -215,14 +211,20 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
215
211
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
216
212
|
}
|
|
217
213
|
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
218
|
-
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging)
|
|
214
|
+
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
219
215
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
217
|
+
var remainingDecs = decorations.find(undefined, undefined, function (spec) {
|
|
218
|
+
return spec.type !== 'drop-target-decoration';
|
|
219
|
+
});
|
|
220
|
+
decorations = DecorationSet.create(newState.doc, remainingDecs);
|
|
221
|
+
} else {
|
|
222
|
+
// Remove drop target decoration when dragging stops
|
|
223
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
224
|
+
return spec.type === 'drop-target-decoration';
|
|
225
|
+
});
|
|
226
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
227
|
+
}
|
|
226
228
|
}
|
|
227
229
|
if (api) {
|
|
228
230
|
// Add drop targets when node is being dragged
|
|
@@ -239,9 +241,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
239
241
|
|
|
240
242
|
//Map drop target decoration positions when the document changes
|
|
241
243
|
if (shouldMapDropTargets) {
|
|
242
|
-
decorationState = decorationState.map(function (
|
|
243
|
-
var id =
|
|
244
|
-
pos =
|
|
244
|
+
decorationState = decorationState.map(function (_ref8) {
|
|
245
|
+
var id = _ref8.id,
|
|
246
|
+
pos = _ref8.pos;
|
|
245
247
|
return {
|
|
246
248
|
id: id,
|
|
247
249
|
pos: tr.mapping.map(pos)
|
|
@@ -254,8 +256,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
254
256
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
255
257
|
}
|
|
256
258
|
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
257
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
258
|
-
var spec =
|
|
259
|
+
var hasNodeDecoration = decorations.find().some(function (_ref9) {
|
|
260
|
+
var spec = _ref9.spec;
|
|
259
261
|
return spec.type === 'node-decoration';
|
|
260
262
|
});
|
|
261
263
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
3
|
/**
|
|
3
4
|
* @jsxRuntime classic
|
|
@@ -14,6 +15,7 @@ import { layers } from '@atlaskit/theme/constants';
|
|
|
14
15
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
15
16
|
import { nodeMargins, spaceLookupMap } from './consts';
|
|
16
17
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
18
|
+
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
17
19
|
var styleDropTarget = css({
|
|
18
20
|
height: "var(--ds-space-100, 8px)",
|
|
19
21
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -23,17 +25,25 @@ var styleDropTarget = css({
|
|
|
23
25
|
display: 'block',
|
|
24
26
|
zIndex: layers.card()
|
|
25
27
|
});
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
var styleDropIndicator = css({
|
|
29
|
+
height: '100%',
|
|
30
|
+
margin: '0 auto',
|
|
31
|
+
position: 'relative',
|
|
32
|
+
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
33
|
+
});
|
|
34
|
+
var nestedDropIndicatorStyle = css({
|
|
35
|
+
position: 'relative'
|
|
36
|
+
});
|
|
37
|
+
var marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(function (_ref, i) {
|
|
29
38
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
30
39
|
key = _ref2[0],
|
|
31
40
|
value = _ref2[1];
|
|
32
|
-
return [key,
|
|
33
|
-
|
|
41
|
+
return [key,
|
|
42
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
43
|
+
css({
|
|
44
|
+
transform: "translateY(".concat(value, ")")
|
|
34
45
|
})];
|
|
35
46
|
}));
|
|
36
|
-
var BASE_LINE_MARGIN = -8;
|
|
37
47
|
var getNodeMargins = function getNodeMargins(node) {
|
|
38
48
|
if (!node) {
|
|
39
49
|
return nodeMargins['default'];
|
|
@@ -44,30 +54,25 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
44
54
|
}
|
|
45
55
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
46
56
|
};
|
|
47
|
-
var
|
|
57
|
+
var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
|
|
48
58
|
if (!prevNode || !nextNode) {
|
|
49
59
|
return null;
|
|
50
60
|
}
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
} else {
|
|
57
|
-
return marginLookupMap[space];
|
|
61
|
+
var top = getNodeMargins(nextNode).top;
|
|
62
|
+
var bottom = getNodeMargins(prevNode).bottom;
|
|
63
|
+
var merginDiff = Math.round((top - bottom) / 2);
|
|
64
|
+
if (merginDiff === 0) {
|
|
65
|
+
return null;
|
|
58
66
|
}
|
|
67
|
+
var offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
68
|
+
return marginLookupMap[offset];
|
|
59
69
|
};
|
|
60
|
-
var styleDropIndicator = css({
|
|
61
|
-
height: '100%',
|
|
62
|
-
width: '100%',
|
|
63
|
-
margin: '0 auto',
|
|
64
|
-
position: 'relative'
|
|
65
|
-
});
|
|
66
70
|
export var DropTarget = function DropTarget(_ref3) {
|
|
67
71
|
var api = _ref3.api,
|
|
68
72
|
id = _ref3.id,
|
|
69
73
|
prevNode = _ref3.prevNode,
|
|
70
74
|
nextNode = _ref3.nextNode,
|
|
75
|
+
parentNode = _ref3.parentNode,
|
|
71
76
|
formatMessage = _ref3.formatMessage;
|
|
72
77
|
var ref = useRef(null);
|
|
73
78
|
var _useState = useState(false),
|
|
@@ -76,7 +81,7 @@ export var DropTarget = function DropTarget(_ref3) {
|
|
|
76
81
|
setIsDraggedOver = _useState2[1];
|
|
77
82
|
var _useSharedPluginState = useSharedPluginState(api, ['width']),
|
|
78
83
|
widthState = _useSharedPluginState.widthState;
|
|
79
|
-
var
|
|
84
|
+
var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
|
|
80
85
|
useEffect(function () {
|
|
81
86
|
var element = ref.current;
|
|
82
87
|
if (!element) {
|
|
@@ -113,23 +118,31 @@ export var DropTarget = function DropTarget(_ref3) {
|
|
|
113
118
|
}
|
|
114
119
|
});
|
|
115
120
|
}, [id, api, formatMessage]);
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
var dropTargetOffsetStyle = useMemo(function () {
|
|
122
|
+
/**
|
|
123
|
+
* First child of a nested node.
|
|
124
|
+
* Disable the position adjustment temporarily
|
|
125
|
+
*/
|
|
126
|
+
if (parentNode === prevNode) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
130
|
+
}, [prevNode, nextNode, parentNode]);
|
|
131
|
+
var widthStyle = _defineProperty({}, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px"));
|
|
119
132
|
return (
|
|
120
133
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
121
134
|
jsx("div", {
|
|
122
135
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
123
|
-
css: [styleDropTarget,
|
|
136
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
137
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
138
|
+
,
|
|
139
|
+
style: widthStyle,
|
|
124
140
|
ref: ref,
|
|
125
141
|
"data-testid": "block-ctrl-drop-target"
|
|
126
142
|
},
|
|
127
143
|
// 4px gap to clear expand node border
|
|
128
144
|
(isDraggedOver || isBlocksDragTargetDebug()) && jsx("div", {
|
|
129
145
|
css: styleDropIndicator,
|
|
130
|
-
style: {
|
|
131
|
-
width: "".concat(lineLength, "px")
|
|
132
|
-
},
|
|
133
146
|
"data-testid": "block-ctrl-drop-indicator"
|
|
134
147
|
}, jsx(DropIndicator, {
|
|
135
148
|
edge: "bottom",
|
|
@@ -8,6 +8,7 @@ export type DropTargetProps = {
|
|
|
8
8
|
id: number;
|
|
9
9
|
prevNode?: PMNode;
|
|
10
10
|
nextNode?: PMNode;
|
|
11
|
+
parentNode?: PMNode;
|
|
11
12
|
formatMessage?: IntlShape['formatMessage'];
|
|
12
13
|
};
|
|
13
|
-
export declare const DropTarget: ({ api, id, prevNode, nextNode, formatMessage }: DropTargetProps) => jsx.JSX.Element;
|
|
14
|
+
export declare const DropTarget: ({ api, id, prevNode, nextNode, parentNode, formatMessage, }: DropTargetProps) => jsx.JSX.Element;
|
|
@@ -8,6 +8,7 @@ export type DropTargetProps = {
|
|
|
8
8
|
id: number;
|
|
9
9
|
prevNode?: PMNode;
|
|
10
10
|
nextNode?: PMNode;
|
|
11
|
+
parentNode?: PMNode;
|
|
11
12
|
formatMessage?: IntlShape['formatMessage'];
|
|
12
13
|
};
|
|
13
|
-
export declare const DropTarget: ({ api, id, prevNode, nextNode, formatMessage }: DropTargetProps) => jsx.JSX.Element;
|
|
14
|
+
export declare const DropTarget: ({ api, id, prevNode, nextNode, parentNode, formatMessage, }: DropTargetProps) => jsx.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.2",
|
|
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
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^87.
|
|
34
|
+
"@atlaskit/editor-common": "^87.10.0",
|
|
35
35
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.7.0",
|
|
37
37
|
"@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
41
41
|
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
42
42
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
43
|
-
"@atlaskit/icon": "^22.
|
|
43
|
+
"@atlaskit/icon": "^22.12.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
45
|
-
"@atlaskit/pragmatic-drag-and-drop": "^1.
|
|
45
|
+
"@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
|
|
48
|
-
"@atlaskit/theme": "^
|
|
49
|
-
"@atlaskit/tokens": "^1.
|
|
50
|
-
"@atlaskit/tooltip": "^18.
|
|
48
|
+
"@atlaskit/theme": "^13.0.0",
|
|
49
|
+
"@atlaskit/tokens": "^1.58.0",
|
|
50
|
+
"@atlaskit/tooltip": "^18.7.0",
|
|
51
51
|
"@babel/runtime": "^7.0.0",
|
|
52
52
|
"@emotion/react": "^11.7.1",
|
|
53
53
|
"bind-event-listener": "^3.0.0",
|