@atlaskit/editor-plugin-block-controls 1.11.1 → 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 +13 -0
- package/dist/cjs/pm-plugins/main.js +22 -20
- package/dist/cjs/ui/drop-target.js +22 -23
- package/dist/es2019/pm-plugins/main.js +13 -18
- package/dist/es2019/ui/drop-target.js +22 -23
- package/dist/esm/pm-plugins/main.js +22 -20
- package/dist/esm/ui/drop-target.js +22 -23
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
3
16
|
## 1.11.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -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) {
|
|
@@ -23,6 +23,7 @@ var _consts = require("./consts");
|
|
|
23
23
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
24
24
|
|
|
25
25
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
26
|
+
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
26
27
|
var styleDropTarget = (0, _react2.css)({
|
|
27
28
|
height: "var(--ds-space-100, 8px)",
|
|
28
29
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -32,6 +33,12 @@ var styleDropTarget = (0, _react2.css)({
|
|
|
32
33
|
display: 'block',
|
|
33
34
|
zIndex: _constants.layers.card()
|
|
34
35
|
});
|
|
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
|
+
});
|
|
35
42
|
var nestedDropIndicatorStyle = (0, _react2.css)({
|
|
36
43
|
position: 'relative'
|
|
37
44
|
});
|
|
@@ -42,10 +49,9 @@ var marginLookupMap = Object.fromEntries(Object.entries(_consts.spaceLookupMap).
|
|
|
42
49
|
return [key,
|
|
43
50
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
44
51
|
(0, _react2.css)({
|
|
45
|
-
|
|
52
|
+
transform: "translateY(".concat(value, ")")
|
|
46
53
|
})];
|
|
47
54
|
}));
|
|
48
|
-
var BASE_LINE_MARGIN = -8;
|
|
49
55
|
var getNodeMargins = function getNodeMargins(node) {
|
|
50
56
|
if (!node) {
|
|
51
57
|
return _consts.nodeMargins['default'];
|
|
@@ -56,26 +62,19 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
56
62
|
}
|
|
57
63
|
return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
|
|
58
64
|
};
|
|
59
|
-
var
|
|
65
|
+
var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
|
|
60
66
|
if (!prevNode || !nextNode) {
|
|
61
67
|
return null;
|
|
62
68
|
}
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
} else {
|
|
69
|
-
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;
|
|
70
74
|
}
|
|
75
|
+
var offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
76
|
+
return marginLookupMap[offset];
|
|
71
77
|
};
|
|
72
|
-
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
73
|
-
var styleDropIndicator = (0, _react2.css)({
|
|
74
|
-
height: '100%',
|
|
75
|
-
margin: '0 auto',
|
|
76
|
-
position: 'relative',
|
|
77
|
-
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
78
|
-
});
|
|
79
78
|
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
80
79
|
var api = _ref3.api,
|
|
81
80
|
id = _ref3.id,
|
|
@@ -127,22 +126,22 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
127
126
|
}
|
|
128
127
|
});
|
|
129
128
|
}, [id, api, formatMessage]);
|
|
130
|
-
var
|
|
129
|
+
var dropTargetOffsetStyle = (0, _react.useMemo)(function () {
|
|
131
130
|
/**
|
|
132
131
|
* First child of a nested node.
|
|
133
|
-
* Disable the position adjustment
|
|
132
|
+
* Disable the position adjustment temporarily
|
|
134
133
|
*/
|
|
135
|
-
if (parentNode === prevNode
|
|
134
|
+
if (parentNode === prevNode) {
|
|
136
135
|
return null;
|
|
137
136
|
}
|
|
138
|
-
return
|
|
139
|
-
}, [prevNode, nextNode, parentNode
|
|
137
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
138
|
+
}, [prevNode, nextNode, parentNode]);
|
|
140
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"));
|
|
141
140
|
return (
|
|
142
141
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
143
142
|
(0, _react2.jsx)("div", {
|
|
144
143
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
145
|
-
css: [styleDropTarget,
|
|
144
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
146
145
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
147
146
|
,
|
|
148
147
|
style: widthStyle,
|
|
@@ -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,15 +23,20 @@ const styleDropTarget = css({
|
|
|
22
23
|
display: 'block',
|
|
23
24
|
zIndex: layers.card()
|
|
24
25
|
});
|
|
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
|
+
});
|
|
25
32
|
const nestedDropIndicatorStyle = css({
|
|
26
33
|
position: 'relative'
|
|
27
34
|
});
|
|
28
35
|
const marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(([key, value], i) => [key,
|
|
29
36
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
30
37
|
css({
|
|
31
|
-
|
|
38
|
+
transform: `translateY(${value})`
|
|
32
39
|
})]));
|
|
33
|
-
const BASE_LINE_MARGIN = -8;
|
|
34
40
|
const getNodeMargins = node => {
|
|
35
41
|
if (!node) {
|
|
36
42
|
return nodeMargins['default'];
|
|
@@ -41,26 +47,19 @@ const getNodeMargins = node => {
|
|
|
41
47
|
}
|
|
42
48
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
43
49
|
};
|
|
44
|
-
const
|
|
50
|
+
const getDropTargetOffsetStyle = (prevNode, nextNode) => {
|
|
45
51
|
if (!prevNode || !nextNode) {
|
|
46
52
|
return null;
|
|
47
53
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
} else {
|
|
54
|
-
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;
|
|
55
59
|
}
|
|
60
|
+
const offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
61
|
+
return marginLookupMap[offset];
|
|
56
62
|
};
|
|
57
|
-
const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
58
|
-
const styleDropIndicator = css({
|
|
59
|
-
height: '100%',
|
|
60
|
-
margin: '0 auto',
|
|
61
|
-
position: 'relative',
|
|
62
|
-
width: `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH}, 100%)`
|
|
63
|
-
});
|
|
64
63
|
export const DropTarget = ({
|
|
65
64
|
api,
|
|
66
65
|
id,
|
|
@@ -111,16 +110,16 @@ export const DropTarget = ({
|
|
|
111
110
|
}
|
|
112
111
|
});
|
|
113
112
|
}, [id, api, formatMessage]);
|
|
114
|
-
const
|
|
113
|
+
const dropTargetOffsetStyle = useMemo(() => {
|
|
115
114
|
/**
|
|
116
115
|
* First child of a nested node.
|
|
117
|
-
* Disable the position adjustment
|
|
116
|
+
* Disable the position adjustment temporarily
|
|
118
117
|
*/
|
|
119
|
-
if (parentNode === prevNode
|
|
118
|
+
if (parentNode === prevNode) {
|
|
120
119
|
return null;
|
|
121
120
|
}
|
|
122
|
-
return
|
|
123
|
-
}, [prevNode, nextNode, parentNode
|
|
121
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
122
|
+
}, [prevNode, nextNode, parentNode]);
|
|
124
123
|
const widthStyle = {
|
|
125
124
|
[EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH]: isNestedDropTarget ? '100%' : `${(widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH}px`
|
|
126
125
|
};
|
|
@@ -128,7 +127,7 @@ export const DropTarget = ({
|
|
|
128
127
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
129
128
|
jsx("div", {
|
|
130
129
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
131
|
-
css: [styleDropTarget,
|
|
130
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
132
131
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
133
132
|
,
|
|
134
133
|
style: widthStyle,
|
|
@@ -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) {
|
|
@@ -15,6 +15,7 @@ import { layers } from '@atlaskit/theme/constants';
|
|
|
15
15
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
16
16
|
import { nodeMargins, spaceLookupMap } from './consts';
|
|
17
17
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
18
|
+
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
18
19
|
var styleDropTarget = css({
|
|
19
20
|
height: "var(--ds-space-100, 8px)",
|
|
20
21
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -24,6 +25,12 @@ var styleDropTarget = css({
|
|
|
24
25
|
display: 'block',
|
|
25
26
|
zIndex: layers.card()
|
|
26
27
|
});
|
|
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
|
+
});
|
|
27
34
|
var nestedDropIndicatorStyle = css({
|
|
28
35
|
position: 'relative'
|
|
29
36
|
});
|
|
@@ -34,10 +41,9 @@ var marginLookupMap = Object.fromEntries(Object.entries(spaceLookupMap).map(func
|
|
|
34
41
|
return [key,
|
|
35
42
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
36
43
|
css({
|
|
37
|
-
|
|
44
|
+
transform: "translateY(".concat(value, ")")
|
|
38
45
|
})];
|
|
39
46
|
}));
|
|
40
|
-
var BASE_LINE_MARGIN = -8;
|
|
41
47
|
var getNodeMargins = function getNodeMargins(node) {
|
|
42
48
|
if (!node) {
|
|
43
49
|
return nodeMargins['default'];
|
|
@@ -48,26 +54,19 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
48
54
|
}
|
|
49
55
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
50
56
|
};
|
|
51
|
-
var
|
|
57
|
+
var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
|
|
52
58
|
if (!prevNode || !nextNode) {
|
|
53
59
|
return null;
|
|
54
60
|
}
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
} else {
|
|
61
|
-
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;
|
|
62
66
|
}
|
|
67
|
+
var offset = Math.max(Math.min(merginDiff, 24), -24);
|
|
68
|
+
return marginLookupMap[offset];
|
|
63
69
|
};
|
|
64
|
-
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
65
|
-
var styleDropIndicator = css({
|
|
66
|
-
height: '100%',
|
|
67
|
-
margin: '0 auto',
|
|
68
|
-
position: 'relative',
|
|
69
|
-
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
70
|
-
});
|
|
71
70
|
export var DropTarget = function DropTarget(_ref3) {
|
|
72
71
|
var api = _ref3.api,
|
|
73
72
|
id = _ref3.id,
|
|
@@ -119,22 +118,22 @@ export var DropTarget = function DropTarget(_ref3) {
|
|
|
119
118
|
}
|
|
120
119
|
});
|
|
121
120
|
}, [id, api, formatMessage]);
|
|
122
|
-
var
|
|
121
|
+
var dropTargetOffsetStyle = useMemo(function () {
|
|
123
122
|
/**
|
|
124
123
|
* First child of a nested node.
|
|
125
|
-
* Disable the position adjustment
|
|
124
|
+
* Disable the position adjustment temporarily
|
|
126
125
|
*/
|
|
127
|
-
if (parentNode === prevNode
|
|
126
|
+
if (parentNode === prevNode) {
|
|
128
127
|
return null;
|
|
129
128
|
}
|
|
130
|
-
return
|
|
131
|
-
}, [prevNode, nextNode, parentNode
|
|
129
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
130
|
+
}, [prevNode, nextNode, parentNode]);
|
|
132
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"));
|
|
133
132
|
return (
|
|
134
133
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
135
134
|
jsx("div", {
|
|
136
135
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
137
|
-
css: [styleDropTarget,
|
|
136
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
138
137
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
139
138
|
,
|
|
140
139
|
style: widthStyle,
|
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
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",
|