@atlaskit/editor-plugin-block-controls 2.8.0 → 2.10.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 +30 -0
- package/dist/cjs/commands/move-to-layout.js +60 -16
- package/dist/cjs/pm-plugins/decorations.js +13 -2
- package/dist/cjs/ui/inline-drop-target.js +76 -17
- package/dist/cjs/utils/check-media-layout.js +14 -0
- package/dist/cjs/utils/inline-drop-target.js +4 -0
- package/dist/es2019/commands/move-to-layout.js +57 -14
- package/dist/es2019/pm-plugins/decorations.js +12 -1
- package/dist/es2019/ui/inline-drop-target.js +76 -17
- package/dist/es2019/utils/check-media-layout.js +8 -0
- package/dist/es2019/utils/inline-drop-target.js +4 -0
- package/dist/esm/commands/move-to-layout.js +58 -14
- package/dist/esm/pm-plugins/decorations.js +12 -1
- package/dist/esm/ui/inline-drop-target.js +76 -17
- package/dist/esm/utils/check-media-layout.js +8 -0
- package/dist/esm/utils/inline-drop-target.js +4 -0
- package/dist/types/pm-plugins/decorations.d.ts +1 -0
- package/dist/types/ui/inline-drop-target.d.ts +6 -1
- package/dist/types/utils/check-media-layout.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +1 -0
- package/dist/types-ts4.5/ui/inline-drop-target.d.ts +6 -1
- package/dist/types-ts4.5/utils/check-media-layout.d.ts +2 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#154751](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/154751)
|
|
8
|
+
[`8a15d128d0772`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8a15d128d0772) -
|
|
9
|
+
ED-25049 handle edge cases for vertical drop targets
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 2.9.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#154648](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/154648)
|
|
20
|
+
[`7224898e37116`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7224898e37116) -
|
|
21
|
+
Don't create node decs within tables if nested dnd not enabled
|
|
22
|
+
- [#154380](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/154380)
|
|
23
|
+
[`e045dd3ba95bd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e045dd3ba95bd) -
|
|
24
|
+
ED-25281 implement DnD API for appending to a layout
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- [#154186](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/154186)
|
|
29
|
+
[`5c316170d29dd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5c316170d29dd) -
|
|
30
|
+
Bump @atlaskit/adf-schema to 42.3.1
|
|
31
|
+
- Updated dependencies
|
|
32
|
+
|
|
3
33
|
## 2.8.0
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
|
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.moveToLayout = void 0;
|
|
7
7
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
-
var
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var _consts = require("../consts");
|
|
10
|
+
var _consts2 = require("../ui/consts");
|
|
9
11
|
var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
10
|
-
|
|
11
|
-
if (layoutContents.length === 0 || layoutContents.length > 5) {
|
|
12
|
+
if (layoutContents.length === 0 || layoutContents.length > _consts.MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
14
|
-
var width =
|
|
15
|
+
var width = _consts2.DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
|
|
15
16
|
if (!width) {
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
@@ -19,11 +20,12 @@ var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
|
19
20
|
layoutSection = _ref.layoutSection,
|
|
20
21
|
layoutColumn = _ref.layoutColumn;
|
|
21
22
|
try {
|
|
22
|
-
var
|
|
23
|
+
var layoutContent = _model.Fragment.fromArray(layoutContents.map(function (layoutContent) {
|
|
23
24
|
return layoutColumn.createChecked({
|
|
24
25
|
width: width
|
|
25
26
|
}, layoutContent);
|
|
26
|
-
}))
|
|
27
|
+
}));
|
|
28
|
+
var layoutSectionNode = layoutSection.createChecked(undefined, layoutContent);
|
|
27
29
|
return layoutSectionNode;
|
|
28
30
|
} catch (error) {
|
|
29
31
|
// TODO analytics
|
|
@@ -34,10 +36,16 @@ var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
|
|
|
34
36
|
return function (from, to, position) {
|
|
35
37
|
return function (_ref2) {
|
|
36
38
|
var tr = _ref2.tr;
|
|
39
|
+
// unable to drag a node to itself.
|
|
40
|
+
if (from === to) {
|
|
41
|
+
return tr;
|
|
42
|
+
}
|
|
37
43
|
var _ref3 = tr.doc.type.schema.nodes || {},
|
|
38
44
|
layoutSection = _ref3.layoutSection,
|
|
39
45
|
layoutColumn = _ref3.layoutColumn,
|
|
40
46
|
doc = _ref3.doc;
|
|
47
|
+
var _ref4 = tr.doc.type.schema.marks || {},
|
|
48
|
+
breakout = _ref4.breakout;
|
|
41
49
|
|
|
42
50
|
// layout plugin does not exist
|
|
43
51
|
if (!layoutSection || !layoutColumn) {
|
|
@@ -51,26 +59,62 @@ var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
|
|
|
51
59
|
}
|
|
52
60
|
var $from = tr.doc.resolve(from);
|
|
53
61
|
|
|
54
|
-
// invalid from position
|
|
55
|
-
if (!$from.nodeAfter) {
|
|
62
|
+
// invalid from position or dragging a layout
|
|
63
|
+
if (!$from.nodeAfter || $from.nodeAfter.type === layoutSection) {
|
|
56
64
|
return tr;
|
|
57
65
|
}
|
|
58
66
|
var toNode = $to.nodeAfter;
|
|
59
67
|
var fromNode = $from.nodeAfter;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if ($
|
|
63
|
-
|
|
68
|
+
|
|
69
|
+
// remove breakout from node;
|
|
70
|
+
if (breakout && $from.nodeAfter && $from.nodeAfter.marks.some(function (m) {
|
|
71
|
+
return m.type === breakout;
|
|
72
|
+
})) {
|
|
73
|
+
tr = tr.removeNodeMark(from, breakout);
|
|
74
|
+
}
|
|
75
|
+
if ($to.nodeAfter.type === layoutSection) {
|
|
76
|
+
var existingLayoutNode = $to.nodeAfter;
|
|
77
|
+
if (existingLayoutNode.childCount < _consts.MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
78
|
+
var newColumnWidth = _consts2.DEFAULT_COLUMN_DISTRIBUTIONS[existingLayoutNode.childCount + 1];
|
|
79
|
+
if (newColumnWidth) {
|
|
80
|
+
existingLayoutNode.content.forEach(function (node, offset) {
|
|
81
|
+
if (node.type === layoutColumn) {
|
|
82
|
+
tr = tr.setNodeAttribute(to + offset + 1, 'width', newColumnWidth);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
var toPos = position === 'left' ? to + 1 : to + existingLayoutNode.nodeSize - 1;
|
|
87
|
+
tr = tr.insert(toPos,
|
|
88
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
89
|
+
layoutColumn.create({
|
|
90
|
+
width: newColumnWidth
|
|
91
|
+
}, tr.doc.resolve(from).nodeAfter));
|
|
92
|
+
tr = tr.setSelection(new _state.NodeSelection(tr.doc.resolve(toPos)));
|
|
93
|
+
var mappedFrom = tr.mapping.map(from);
|
|
94
|
+
var mappedFromEnd = mappedFrom + fromNode.nodeSize;
|
|
95
|
+
tr = tr.delete(mappedFrom, mappedFromEnd);
|
|
96
|
+
tr = tr.scrollIntoView();
|
|
97
|
+
return tr;
|
|
98
|
+
}
|
|
99
|
+
return tr;
|
|
100
|
+
} else {
|
|
101
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
102
|
+
var newFromNode = tr.doc.resolve(from).nodeAfter;
|
|
103
|
+
if (!newFromNode) {
|
|
104
|
+
return tr;
|
|
105
|
+
}
|
|
106
|
+
var layoutContents = position === 'left' ? [newFromNode, toNode] : [toNode, newFromNode];
|
|
64
107
|
var newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
65
108
|
if (newLayout) {
|
|
66
|
-
tr.delete(from,
|
|
109
|
+
tr = tr.delete(from, from + fromNode.nodeSize);
|
|
67
110
|
var mappedTo = tr.mapping.map(to);
|
|
68
|
-
tr.delete(mappedTo,
|
|
69
|
-
tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
111
|
+
tr = tr.delete(mappedTo, mappedTo + toNode.nodeSize);
|
|
112
|
+
tr = tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
113
|
+
tr = tr.setSelection(new _state.NodeSelection(tr.doc.resolve(mappedTo)));
|
|
114
|
+
tr = tr.scrollIntoView();
|
|
70
115
|
}
|
|
71
116
|
return tr;
|
|
72
117
|
}
|
|
73
|
-
return tr;
|
|
74
118
|
};
|
|
75
119
|
};
|
|
76
120
|
};
|
|
@@ -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.nodeDecorations = exports.getNodeAnchor = exports.findNodeDecs = exports.findHandleDec = exports.findDropTargetDecs = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = exports.createDropTargetDecoration = exports.TYPE_NODE_DEC = exports.TYPE_HANDLE_DEC = exports.TYPE_DROP_TARGET_DEC = void 0;
|
|
7
|
+
exports.shouldDescendIntoNode = exports.nodeDecorations = exports.getNodeAnchor = exports.findNodeDecs = exports.findHandleDec = exports.findDropTargetDecs = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = exports.createDropTargetDecoration = exports.TYPE_NODE_DEC = exports.TYPE_HANDLE_DEC = exports.TYPE_DROP_TARGET_DEC = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -289,6 +289,7 @@ var ObjHash = /*#__PURE__*/function () {
|
|
|
289
289
|
}();
|
|
290
290
|
(0, _defineProperty2.default)(ObjHash, "caching", new WeakMap());
|
|
291
291
|
var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
292
|
+
// TODO use isWrappedMedia when clean up the featue flag
|
|
292
293
|
if ('mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1')) {
|
|
293
294
|
if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
|
|
294
295
|
return true;
|
|
@@ -296,6 +297,16 @@ var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
|
296
297
|
}
|
|
297
298
|
return IGNORE_NODES.includes(node.type.name);
|
|
298
299
|
};
|
|
300
|
+
var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
|
|
301
|
+
// Optimisation to avoid drawing node decorations for empty table cells
|
|
302
|
+
if (['tableCell', 'tableHeader'].includes(node.type.name) && !(0, _experiments.editorExperiment)('table-nested-dnd', true) && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3')) {
|
|
303
|
+
var _node$firstChild;
|
|
304
|
+
if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
309
|
+
};
|
|
299
310
|
var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
300
311
|
var decs = [];
|
|
301
312
|
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
@@ -304,7 +315,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
304
315
|
var _Decoration$node2;
|
|
305
316
|
var depth = 0;
|
|
306
317
|
var anchorName;
|
|
307
|
-
var shouldDescend =
|
|
318
|
+
var shouldDescend = shouldDescendIntoNode(node);
|
|
308
319
|
var handleId = ObjHash.getForNode(node);
|
|
309
320
|
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
310
321
|
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
@@ -13,6 +13,7 @@ var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box")
|
|
|
13
13
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
14
14
|
var _decorations = require("../pm-plugins/decorations");
|
|
15
15
|
var _anchorUtils = require("../utils/anchor-utils");
|
|
16
|
+
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
16
17
|
/* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
|
|
17
18
|
/* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
|
|
18
19
|
/**
|
|
@@ -26,13 +27,10 @@ var dropTargetCommonStyle = (0, _react2.css)({
|
|
|
26
27
|
position: 'absolute',
|
|
27
28
|
display: 'block'
|
|
28
29
|
});
|
|
29
|
-
var hideDropTargetStyle = (0, _react2.css)({
|
|
30
|
-
display: 'none'
|
|
31
|
-
});
|
|
32
30
|
var hoverZoneCommonStyle = (0, _react2.css)({
|
|
33
31
|
position: 'absolute',
|
|
34
|
-
//
|
|
35
|
-
zIndex:
|
|
32
|
+
// above the top and bottom drop zone as block hover zone
|
|
33
|
+
zIndex: 120
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
// gap between node boundary and drop indicator/drop zone
|
|
@@ -40,6 +38,60 @@ var GAP = 4;
|
|
|
40
38
|
var HOVER_ZONE_WIDTH_OFFSET = 40;
|
|
41
39
|
var HOVER_ZONE_HEIGHT_OFFSET = 10;
|
|
42
40
|
var HOVER_ZONE_DEFAULT_WIDTH = 40;
|
|
41
|
+
var getDropTargetPositionOverride = function getDropTargetPositionOverride(node, editorWidth) {
|
|
42
|
+
if (!node || !editorWidth) {
|
|
43
|
+
return {
|
|
44
|
+
left: 0,
|
|
45
|
+
right: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var getOffsets = function getOffsets(nodeWidth) {
|
|
49
|
+
var offset = (editorWidth - nodeWidth) / 2;
|
|
50
|
+
return {
|
|
51
|
+
left: offset,
|
|
52
|
+
right: offset
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
|
|
56
|
+
return getOffsets(node.attrs.width);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// media single 🤦
|
|
60
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
|
|
61
|
+
var mediaNodeWidth = 0;
|
|
62
|
+
if (node.attrs.width) {
|
|
63
|
+
if (node.attrs.widthType === 'pixel') {
|
|
64
|
+
mediaNodeWidth = node.attrs.width;
|
|
65
|
+
} else if (editorWidth) {
|
|
66
|
+
mediaNodeWidth = node.attrs.width / 100 * editorWidth;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
// use media width
|
|
70
|
+
var mediaNode = node.firstChild;
|
|
71
|
+
if (mediaNode && mediaNode.attrs.width) {
|
|
72
|
+
mediaNodeWidth = mediaNode.attrs.width;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (mediaNodeWidth) {
|
|
76
|
+
if (node.attrs.layout === 'align-start') {
|
|
77
|
+
return {
|
|
78
|
+
left: 0,
|
|
79
|
+
right: editorWidth - mediaNodeWidth
|
|
80
|
+
};
|
|
81
|
+
} else if (node.attrs.layout === 'align-end') {
|
|
82
|
+
return {
|
|
83
|
+
left: editorWidth - mediaNodeWidth,
|
|
84
|
+
right: 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return getOffsets(mediaNodeWidth);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
left: 0,
|
|
92
|
+
right: 0
|
|
93
|
+
};
|
|
94
|
+
};
|
|
43
95
|
var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref) {
|
|
44
96
|
var api = _ref.api,
|
|
45
97
|
nextNode = _ref.nextNode,
|
|
@@ -59,22 +111,25 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
|
|
|
59
111
|
var handleDragLeave = (0, _react.useCallback)(function () {
|
|
60
112
|
setIsDraggedOver(false);
|
|
61
113
|
}, []);
|
|
114
|
+
var offsets = (0, _react.useMemo)(function () {
|
|
115
|
+
return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
|
|
116
|
+
}, [nextNode, widthState]);
|
|
62
117
|
var dropTargetRectStyle = (0, _react.useMemo)(function () {
|
|
63
118
|
if ((0, _anchorUtils.isAnchorSupported)()) {
|
|
64
119
|
return (0, _react2.css)({
|
|
65
120
|
height: "calc(anchor-size(".concat(anchorName, " height))"),
|
|
66
121
|
positionAnchor: anchorName,
|
|
67
|
-
left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
122
|
+
left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
|
|
68
123
|
top: "calc(anchor(top))"
|
|
69
124
|
});
|
|
70
125
|
}
|
|
71
126
|
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
72
127
|
return (0, _react2.css)({
|
|
73
128
|
height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
|
|
74
|
-
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
129
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP + offsets.left, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offsets.right, "px"),
|
|
75
130
|
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
|
|
76
131
|
});
|
|
77
|
-
}, [anchorName, anchorRectCache, position]);
|
|
132
|
+
}, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
|
|
78
133
|
var onDrop = (0, _react.useCallback)(function () {
|
|
79
134
|
var _api$blockControls;
|
|
80
135
|
var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
@@ -91,8 +146,8 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
|
|
|
91
146
|
}, [api, getPos, position]);
|
|
92
147
|
return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)("div", {
|
|
93
148
|
"data-test-id": "block-ctrl-drop-target-".concat(position),
|
|
94
|
-
css: [dropTargetCommonStyle, dropTargetRectStyle
|
|
95
|
-
}, (0, _react2.jsx)(_box.DropIndicator, {
|
|
149
|
+
css: [dropTargetCommonStyle, dropTargetRectStyle]
|
|
150
|
+
}, (isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)(_box.DropIndicator, {
|
|
96
151
|
edge: position
|
|
97
152
|
})), (0, _react2.jsx)(InlineHoverZone, {
|
|
98
153
|
position: position,
|
|
@@ -101,7 +156,8 @@ var InlineDropTarget = exports.InlineDropTarget = function InlineDropTarget(_ref
|
|
|
101
156
|
anchorRectCache: anchorRectCache,
|
|
102
157
|
onDragEnter: handleDragEnter,
|
|
103
158
|
onDragLeave: handleDragLeave,
|
|
104
|
-
onDrop: onDrop
|
|
159
|
+
onDrop: onDrop,
|
|
160
|
+
offsets: offsets
|
|
105
161
|
}));
|
|
106
162
|
};
|
|
107
163
|
var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3) {
|
|
@@ -109,6 +165,7 @@ var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3)
|
|
|
109
165
|
editorWidthState = _ref3.editorWidthState,
|
|
110
166
|
anchorRectCache = _ref3.anchorRectCache,
|
|
111
167
|
position = _ref3.position,
|
|
168
|
+
offsets = _ref3.offsets,
|
|
112
169
|
onDragEnter = _ref3.onDragEnter,
|
|
113
170
|
onDragLeave = _ref3.onDragLeave,
|
|
114
171
|
onDrop = _ref3.onDrop;
|
|
@@ -127,27 +184,29 @@ var InlineHoverZone = exports.InlineHoverZone = function InlineHoverZone(_ref3)
|
|
|
127
184
|
}
|
|
128
185
|
}, [onDragEnter, onDragLeave, onDrop]);
|
|
129
186
|
var inlineHoverZoneRectStyle = (0, _react.useMemo)(function () {
|
|
187
|
+
var offset = offsets[position];
|
|
130
188
|
if ((0, _anchorUtils.isAnchorSupported)()) {
|
|
131
189
|
return (0, _react2.css)({
|
|
132
190
|
positionAnchor: anchorName,
|
|
133
|
-
left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
134
|
-
right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
|
|
191
|
+
left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
|
|
192
|
+
right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
|
|
135
193
|
top: "calc(anchor(top))",
|
|
136
|
-
width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
|
|
194
|
+
width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px + ").concat(offset, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
|
|
137
195
|
height: "calc(anchor-size(".concat(anchorName, " height))")
|
|
138
196
|
});
|
|
139
197
|
}
|
|
140
198
|
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
141
|
-
var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
|
|
199
|
+
var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
|
|
142
200
|
return (0, _react2.css)({
|
|
143
|
-
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
201
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP + offset, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offset, "px"),
|
|
144
202
|
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
|
|
145
203
|
width: "".concat(width, "px"),
|
|
146
204
|
height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
|
|
147
205
|
});
|
|
148
|
-
}, [anchorName, anchorRectCache, editorWith, position]);
|
|
206
|
+
}, [anchorName, anchorRectCache, editorWith, offsets, position]);
|
|
149
207
|
return (0, _react2.jsx)("div", {
|
|
150
208
|
ref: ref,
|
|
209
|
+
"data-test-id": "drop-target-hover-zone-".concat(position),
|
|
151
210
|
css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
|
|
152
211
|
});
|
|
153
212
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isWrappedMedia = void 0;
|
|
7
|
+
var isWrappedMedia = exports.isWrappedMedia = function isWrappedMedia(node) {
|
|
8
|
+
if ('mediaSingle' === (node === null || node === void 0 ? void 0 : node.type.name)) {
|
|
9
|
+
if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
@@ -7,10 +7,14 @@ exports.shouldAllowInlineDropTarget = void 0;
|
|
|
7
7
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
8
|
var _consts = require("../consts");
|
|
9
9
|
var _advancedLayoutsFlags = require("./advanced-layouts-flags");
|
|
10
|
+
var _checkMediaLayout = require("./check-media-layout");
|
|
10
11
|
var shouldAllowInlineDropTarget = exports.shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
|
|
11
12
|
if (!(0, _advancedLayoutsFlags.isPreRelease1)() || isNested) {
|
|
12
13
|
return false;
|
|
13
14
|
}
|
|
15
|
+
if ((0, _checkMediaLayout.isWrappedMedia)(node)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
14
18
|
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
|
|
15
19
|
return node.childCount < _consts.MAX_LAYOUT_COLUMN_SUPPORTED;
|
|
16
20
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
|
|
2
4
|
import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
|
|
3
5
|
const createNewLayout = (schema, layoutContents) => {
|
|
4
|
-
|
|
5
|
-
if (layoutContents.length === 0 || layoutContents.length > 5) {
|
|
6
|
+
if (layoutContents.length === 0 || layoutContents.length > MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
6
7
|
return null;
|
|
7
8
|
}
|
|
8
9
|
const width = DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
|
|
@@ -14,11 +15,12 @@ const createNewLayout = (schema, layoutContents) => {
|
|
|
14
15
|
layoutColumn
|
|
15
16
|
} = schema.nodes || {};
|
|
16
17
|
try {
|
|
17
|
-
const
|
|
18
|
+
const layoutContent = Fragment.fromArray(layoutContents.map(layoutContent => {
|
|
18
19
|
return layoutColumn.createChecked({
|
|
19
20
|
width
|
|
20
21
|
}, layoutContent);
|
|
21
|
-
}))
|
|
22
|
+
}));
|
|
23
|
+
const layoutSectionNode = layoutSection.createChecked(undefined, layoutContent);
|
|
22
24
|
return layoutSectionNode;
|
|
23
25
|
} catch (error) {
|
|
24
26
|
// TODO analytics
|
|
@@ -28,11 +30,18 @@ const createNewLayout = (schema, layoutContents) => {
|
|
|
28
30
|
export const moveToLayout = api => (from, to, position) => ({
|
|
29
31
|
tr
|
|
30
32
|
}) => {
|
|
33
|
+
// unable to drag a node to itself.
|
|
34
|
+
if (from === to) {
|
|
35
|
+
return tr;
|
|
36
|
+
}
|
|
31
37
|
const {
|
|
32
38
|
layoutSection,
|
|
33
39
|
layoutColumn,
|
|
34
40
|
doc
|
|
35
41
|
} = tr.doc.type.schema.nodes || {};
|
|
42
|
+
const {
|
|
43
|
+
breakout
|
|
44
|
+
} = tr.doc.type.schema.marks || {};
|
|
36
45
|
|
|
37
46
|
// layout plugin does not exist
|
|
38
47
|
if (!layoutSection || !layoutColumn) {
|
|
@@ -46,24 +55,58 @@ export const moveToLayout = api => (from, to, position) => ({
|
|
|
46
55
|
}
|
|
47
56
|
const $from = tr.doc.resolve(from);
|
|
48
57
|
|
|
49
|
-
// invalid from position
|
|
50
|
-
if (!$from.nodeAfter) {
|
|
58
|
+
// invalid from position or dragging a layout
|
|
59
|
+
if (!$from.nodeAfter || $from.nodeAfter.type === layoutSection) {
|
|
51
60
|
return tr;
|
|
52
61
|
}
|
|
53
62
|
const toNode = $to.nodeAfter;
|
|
54
63
|
const fromNode = $from.nodeAfter;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if ($
|
|
58
|
-
|
|
64
|
+
|
|
65
|
+
// remove breakout from node;
|
|
66
|
+
if (breakout && $from.nodeAfter && $from.nodeAfter.marks.some(m => m.type === breakout)) {
|
|
67
|
+
tr = tr.removeNodeMark(from, breakout);
|
|
68
|
+
}
|
|
69
|
+
if ($to.nodeAfter.type === layoutSection) {
|
|
70
|
+
const existingLayoutNode = $to.nodeAfter;
|
|
71
|
+
if (existingLayoutNode.childCount < MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
72
|
+
const newColumnWidth = DEFAULT_COLUMN_DISTRIBUTIONS[existingLayoutNode.childCount + 1];
|
|
73
|
+
if (newColumnWidth) {
|
|
74
|
+
existingLayoutNode.content.forEach((node, offset) => {
|
|
75
|
+
if (node.type === layoutColumn) {
|
|
76
|
+
tr = tr.setNodeAttribute(to + offset + 1, 'width', newColumnWidth);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const toPos = position === 'left' ? to + 1 : to + existingLayoutNode.nodeSize - 1;
|
|
81
|
+
tr = tr.insert(toPos,
|
|
82
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
83
|
+
layoutColumn.create({
|
|
84
|
+
width: newColumnWidth
|
|
85
|
+
}, tr.doc.resolve(from).nodeAfter));
|
|
86
|
+
tr = tr.setSelection(new NodeSelection(tr.doc.resolve(toPos)));
|
|
87
|
+
const mappedFrom = tr.mapping.map(from);
|
|
88
|
+
const mappedFromEnd = mappedFrom + fromNode.nodeSize;
|
|
89
|
+
tr = tr.delete(mappedFrom, mappedFromEnd);
|
|
90
|
+
tr = tr.scrollIntoView();
|
|
91
|
+
return tr;
|
|
92
|
+
}
|
|
93
|
+
return tr;
|
|
94
|
+
} else {
|
|
95
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
96
|
+
const newFromNode = tr.doc.resolve(from).nodeAfter;
|
|
97
|
+
if (!newFromNode) {
|
|
98
|
+
return tr;
|
|
99
|
+
}
|
|
100
|
+
const layoutContents = position === 'left' ? [newFromNode, toNode] : [toNode, newFromNode];
|
|
59
101
|
const newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
60
102
|
if (newLayout) {
|
|
61
|
-
tr.delete(from,
|
|
103
|
+
tr = tr.delete(from, from + fromNode.nodeSize);
|
|
62
104
|
const mappedTo = tr.mapping.map(to);
|
|
63
|
-
tr.delete(mappedTo,
|
|
64
|
-
tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
105
|
+
tr = tr.delete(mappedTo, mappedTo + toNode.nodeSize);
|
|
106
|
+
tr = tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
107
|
+
tr = tr.setSelection(new NodeSelection(tr.doc.resolve(mappedTo)));
|
|
108
|
+
tr = tr.scrollIntoView();
|
|
65
109
|
}
|
|
66
110
|
return tr;
|
|
67
111
|
}
|
|
68
|
-
return tr;
|
|
69
112
|
};
|
|
@@ -267,6 +267,7 @@ class ObjHash {
|
|
|
267
267
|
}
|
|
268
268
|
_defineProperty(ObjHash, "caching", new WeakMap());
|
|
269
269
|
const shouldIgnoreNode = node => {
|
|
270
|
+
// TODO use isWrappedMedia when clean up the featue flag
|
|
270
271
|
if ('mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1')) {
|
|
271
272
|
if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
|
|
272
273
|
return true;
|
|
@@ -274,6 +275,16 @@ const shouldIgnoreNode = node => {
|
|
|
274
275
|
}
|
|
275
276
|
return IGNORE_NODES.includes(node.type.name);
|
|
276
277
|
};
|
|
278
|
+
export const shouldDescendIntoNode = node => {
|
|
279
|
+
// Optimisation to avoid drawing node decorations for empty table cells
|
|
280
|
+
if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
|
|
281
|
+
var _node$firstChild;
|
|
282
|
+
if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
287
|
+
};
|
|
277
288
|
export const nodeDecorations = (newState, from, to) => {
|
|
278
289
|
const decs = [];
|
|
279
290
|
const docFrom = from === undefined || from < 0 ? 0 : from;
|
|
@@ -281,7 +292,7 @@ export const nodeDecorations = (newState, from, to) => {
|
|
|
281
292
|
newState.doc.nodesBetween(docFrom, docTo, (node, pos, _parent, index) => {
|
|
282
293
|
let depth = 0;
|
|
283
294
|
let anchorName;
|
|
284
|
-
const shouldDescend =
|
|
295
|
+
const shouldDescend = shouldDescendIntoNode(node);
|
|
285
296
|
const handleId = ObjHash.getForNode(node);
|
|
286
297
|
anchorName = `--node-anchor-${node.type.name}-${handleId}`;
|
|
287
298
|
if (editorExperiment('nested-dnd', true)) {
|
|
@@ -13,17 +13,15 @@ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indi
|
|
|
13
13
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
14
14
|
import { getNodeAnchor } from '../pm-plugins/decorations';
|
|
15
15
|
import { isAnchorSupported } from '../utils/anchor-utils';
|
|
16
|
+
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
16
17
|
const dropTargetCommonStyle = css({
|
|
17
18
|
position: 'absolute',
|
|
18
19
|
display: 'block'
|
|
19
20
|
});
|
|
20
|
-
const hideDropTargetStyle = css({
|
|
21
|
-
display: 'none'
|
|
22
|
-
});
|
|
23
21
|
const hoverZoneCommonStyle = css({
|
|
24
22
|
position: 'absolute',
|
|
25
|
-
//
|
|
26
|
-
zIndex:
|
|
23
|
+
// above the top and bottom drop zone as block hover zone
|
|
24
|
+
zIndex: 120
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
// gap between node boundary and drop indicator/drop zone
|
|
@@ -31,6 +29,60 @@ const GAP = 4;
|
|
|
31
29
|
const HOVER_ZONE_WIDTH_OFFSET = 40;
|
|
32
30
|
const HOVER_ZONE_HEIGHT_OFFSET = 10;
|
|
33
31
|
const HOVER_ZONE_DEFAULT_WIDTH = 40;
|
|
32
|
+
const getDropTargetPositionOverride = (node, editorWidth) => {
|
|
33
|
+
if (!node || !editorWidth) {
|
|
34
|
+
return {
|
|
35
|
+
left: 0,
|
|
36
|
+
right: 0
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const getOffsets = nodeWidth => {
|
|
40
|
+
const offset = (editorWidth - nodeWidth) / 2;
|
|
41
|
+
return {
|
|
42
|
+
left: offset,
|
|
43
|
+
right: offset
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
|
|
47
|
+
return getOffsets(node.attrs.width);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// media single 🤦
|
|
51
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
|
|
52
|
+
let mediaNodeWidth = 0;
|
|
53
|
+
if (node.attrs.width) {
|
|
54
|
+
if (node.attrs.widthType === 'pixel') {
|
|
55
|
+
mediaNodeWidth = node.attrs.width;
|
|
56
|
+
} else if (editorWidth) {
|
|
57
|
+
mediaNodeWidth = node.attrs.width / 100 * editorWidth;
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
// use media width
|
|
61
|
+
const mediaNode = node.firstChild;
|
|
62
|
+
if (mediaNode && mediaNode.attrs.width) {
|
|
63
|
+
mediaNodeWidth = mediaNode.attrs.width;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (mediaNodeWidth) {
|
|
67
|
+
if (node.attrs.layout === 'align-start') {
|
|
68
|
+
return {
|
|
69
|
+
left: 0,
|
|
70
|
+
right: editorWidth - mediaNodeWidth
|
|
71
|
+
};
|
|
72
|
+
} else if (node.attrs.layout === 'align-end') {
|
|
73
|
+
return {
|
|
74
|
+
left: editorWidth - mediaNodeWidth,
|
|
75
|
+
right: 0
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return getOffsets(mediaNodeWidth);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
left: 0,
|
|
83
|
+
right: 0
|
|
84
|
+
};
|
|
85
|
+
};
|
|
34
86
|
export const InlineDropTarget = ({
|
|
35
87
|
api,
|
|
36
88
|
nextNode,
|
|
@@ -49,22 +101,25 @@ export const InlineDropTarget = ({
|
|
|
49
101
|
const handleDragLeave = useCallback(() => {
|
|
50
102
|
setIsDraggedOver(false);
|
|
51
103
|
}, []);
|
|
104
|
+
const offsets = useMemo(() => {
|
|
105
|
+
return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
|
|
106
|
+
}, [nextNode, widthState]);
|
|
52
107
|
const dropTargetRectStyle = useMemo(() => {
|
|
53
108
|
if (isAnchorSupported()) {
|
|
54
109
|
return css({
|
|
55
110
|
height: `calc(anchor-size(${anchorName} height))`,
|
|
56
111
|
positionAnchor: anchorName,
|
|
57
|
-
left: position === 'left' ? `calc(anchor(left) - ${GAP}px)` : `calc(anchor(right) + ${GAP}px)`,
|
|
112
|
+
left: position === 'left' ? `calc(anchor(left) - ${GAP - offsets.left}px)` : `calc(anchor(right) + ${GAP - offsets.right}px)`,
|
|
58
113
|
top: `calc(anchor(top))`
|
|
59
114
|
});
|
|
60
115
|
}
|
|
61
116
|
const nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
62
117
|
return css({
|
|
63
118
|
height: `calc(${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0}px)`,
|
|
64
|
-
left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP}px`,
|
|
119
|
+
left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP + offsets.left}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offsets.right}px`,
|
|
65
120
|
top: `${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0}px`
|
|
66
121
|
});
|
|
67
|
-
}, [anchorName, anchorRectCache, position]);
|
|
122
|
+
}, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
|
|
68
123
|
const onDrop = useCallback(() => {
|
|
69
124
|
var _api$blockControls;
|
|
70
125
|
const {
|
|
@@ -84,8 +139,8 @@ export const InlineDropTarget = ({
|
|
|
84
139
|
}, [api, getPos, position]);
|
|
85
140
|
return jsx(Fragment, null, jsx("div", {
|
|
86
141
|
"data-test-id": `block-ctrl-drop-target-${position}`,
|
|
87
|
-
css: [dropTargetCommonStyle, dropTargetRectStyle
|
|
88
|
-
}, jsx(DropIndicator, {
|
|
142
|
+
css: [dropTargetCommonStyle, dropTargetRectStyle]
|
|
143
|
+
}, (isDraggedOver || isBlocksDragTargetDebug()) && jsx(DropIndicator, {
|
|
89
144
|
edge: position
|
|
90
145
|
})), jsx(InlineHoverZone, {
|
|
91
146
|
position: position,
|
|
@@ -94,7 +149,8 @@ export const InlineDropTarget = ({
|
|
|
94
149
|
anchorRectCache: anchorRectCache,
|
|
95
150
|
onDragEnter: handleDragEnter,
|
|
96
151
|
onDragLeave: handleDragLeave,
|
|
97
|
-
onDrop: onDrop
|
|
152
|
+
onDrop: onDrop,
|
|
153
|
+
offsets: offsets
|
|
98
154
|
}));
|
|
99
155
|
};
|
|
100
156
|
export const InlineHoverZone = ({
|
|
@@ -102,6 +158,7 @@ export const InlineHoverZone = ({
|
|
|
102
158
|
editorWidthState,
|
|
103
159
|
anchorRectCache,
|
|
104
160
|
position,
|
|
161
|
+
offsets,
|
|
105
162
|
onDragEnter,
|
|
106
163
|
onDragLeave,
|
|
107
164
|
onDrop
|
|
@@ -122,27 +179,29 @@ export const InlineHoverZone = ({
|
|
|
122
179
|
}
|
|
123
180
|
}, [onDragEnter, onDragLeave, onDrop]);
|
|
124
181
|
const inlineHoverZoneRectStyle = useMemo(() => {
|
|
182
|
+
const offset = offsets[position];
|
|
125
183
|
if (isAnchorSupported()) {
|
|
126
184
|
return css({
|
|
127
185
|
positionAnchor: anchorName,
|
|
128
|
-
left: position === 'left' ? 'unset' : `calc(anchor(right) + ${GAP}px)`,
|
|
129
|
-
right: position === 'left' ? `calc(anchor(left) + ${GAP}px)` : 'unset',
|
|
186
|
+
left: position === 'left' ? 'unset' : `calc(anchor(right) + ${GAP - offset}px)`,
|
|
187
|
+
right: position === 'left' ? `calc(anchor(left) + ${GAP - offset}px)` : 'unset',
|
|
130
188
|
top: `calc(anchor(top))`,
|
|
131
|
-
width: editorWith ? `calc((${editorWith}px - anchor-size(${anchorName} width))/2 - ${HOVER_ZONE_WIDTH_OFFSET}px)` : `${HOVER_ZONE_DEFAULT_WIDTH}px`,
|
|
189
|
+
width: editorWith ? `calc((${editorWith}px - anchor-size(${anchorName} width))/2 - ${HOVER_ZONE_WIDTH_OFFSET}px + ${offset}px)` : `${HOVER_ZONE_DEFAULT_WIDTH}px`,
|
|
132
190
|
height: `calc(anchor-size(${anchorName} height))`
|
|
133
191
|
});
|
|
134
192
|
}
|
|
135
193
|
const nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
136
|
-
const width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
|
|
194
|
+
const width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
|
|
137
195
|
return css({
|
|
138
|
-
left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP}px`,
|
|
196
|
+
left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP + offset}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offset}px`,
|
|
139
197
|
top: `${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0}px`,
|
|
140
198
|
width: `${width}px`,
|
|
141
199
|
height: `calc(${(anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0}px - ${HOVER_ZONE_HEIGHT_OFFSET}px)`
|
|
142
200
|
});
|
|
143
|
-
}, [anchorName, anchorRectCache, editorWith, position]);
|
|
201
|
+
}, [anchorName, anchorRectCache, editorWith, offsets, position]);
|
|
144
202
|
return jsx("div", {
|
|
145
203
|
ref: ref,
|
|
204
|
+
"data-test-id": `drop-target-hover-zone-${position}`,
|
|
146
205
|
css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
|
|
147
206
|
});
|
|
148
207
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
|
|
3
3
|
import { isPreRelease1 } from './advanced-layouts-flags';
|
|
4
|
+
import { isWrappedMedia } from './check-media-layout';
|
|
4
5
|
export const shouldAllowInlineDropTarget = (isNested, node) => {
|
|
5
6
|
if (!isPreRelease1() || isNested) {
|
|
6
7
|
return false;
|
|
7
8
|
}
|
|
9
|
+
if (isWrappedMedia(node)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
8
12
|
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
|
|
9
13
|
return node.childCount < MAX_LAYOUT_COLUMN_SUPPORTED;
|
|
10
14
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
|
|
2
4
|
import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
|
|
3
5
|
var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
4
|
-
|
|
5
|
-
if (layoutContents.length === 0 || layoutContents.length > 5) {
|
|
6
|
+
if (layoutContents.length === 0 || layoutContents.length > MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
6
7
|
return null;
|
|
7
8
|
}
|
|
8
9
|
var width = DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
|
|
@@ -13,11 +14,12 @@ var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
|
13
14
|
layoutSection = _ref.layoutSection,
|
|
14
15
|
layoutColumn = _ref.layoutColumn;
|
|
15
16
|
try {
|
|
16
|
-
var
|
|
17
|
+
var layoutContent = Fragment.fromArray(layoutContents.map(function (layoutContent) {
|
|
17
18
|
return layoutColumn.createChecked({
|
|
18
19
|
width: width
|
|
19
20
|
}, layoutContent);
|
|
20
|
-
}))
|
|
21
|
+
}));
|
|
22
|
+
var layoutSectionNode = layoutSection.createChecked(undefined, layoutContent);
|
|
21
23
|
return layoutSectionNode;
|
|
22
24
|
} catch (error) {
|
|
23
25
|
// TODO analytics
|
|
@@ -28,10 +30,16 @@ export var moveToLayout = function moveToLayout(api) {
|
|
|
28
30
|
return function (from, to, position) {
|
|
29
31
|
return function (_ref2) {
|
|
30
32
|
var tr = _ref2.tr;
|
|
33
|
+
// unable to drag a node to itself.
|
|
34
|
+
if (from === to) {
|
|
35
|
+
return tr;
|
|
36
|
+
}
|
|
31
37
|
var _ref3 = tr.doc.type.schema.nodes || {},
|
|
32
38
|
layoutSection = _ref3.layoutSection,
|
|
33
39
|
layoutColumn = _ref3.layoutColumn,
|
|
34
40
|
doc = _ref3.doc;
|
|
41
|
+
var _ref4 = tr.doc.type.schema.marks || {},
|
|
42
|
+
breakout = _ref4.breakout;
|
|
35
43
|
|
|
36
44
|
// layout plugin does not exist
|
|
37
45
|
if (!layoutSection || !layoutColumn) {
|
|
@@ -45,26 +53,62 @@ export var moveToLayout = function moveToLayout(api) {
|
|
|
45
53
|
}
|
|
46
54
|
var $from = tr.doc.resolve(from);
|
|
47
55
|
|
|
48
|
-
// invalid from position
|
|
49
|
-
if (!$from.nodeAfter) {
|
|
56
|
+
// invalid from position or dragging a layout
|
|
57
|
+
if (!$from.nodeAfter || $from.nodeAfter.type === layoutSection) {
|
|
50
58
|
return tr;
|
|
51
59
|
}
|
|
52
60
|
var toNode = $to.nodeAfter;
|
|
53
61
|
var fromNode = $from.nodeAfter;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if ($
|
|
57
|
-
|
|
62
|
+
|
|
63
|
+
// remove breakout from node;
|
|
64
|
+
if (breakout && $from.nodeAfter && $from.nodeAfter.marks.some(function (m) {
|
|
65
|
+
return m.type === breakout;
|
|
66
|
+
})) {
|
|
67
|
+
tr = tr.removeNodeMark(from, breakout);
|
|
68
|
+
}
|
|
69
|
+
if ($to.nodeAfter.type === layoutSection) {
|
|
70
|
+
var existingLayoutNode = $to.nodeAfter;
|
|
71
|
+
if (existingLayoutNode.childCount < MAX_LAYOUT_COLUMN_SUPPORTED) {
|
|
72
|
+
var newColumnWidth = DEFAULT_COLUMN_DISTRIBUTIONS[existingLayoutNode.childCount + 1];
|
|
73
|
+
if (newColumnWidth) {
|
|
74
|
+
existingLayoutNode.content.forEach(function (node, offset) {
|
|
75
|
+
if (node.type === layoutColumn) {
|
|
76
|
+
tr = tr.setNodeAttribute(to + offset + 1, 'width', newColumnWidth);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var toPos = position === 'left' ? to + 1 : to + existingLayoutNode.nodeSize - 1;
|
|
81
|
+
tr = tr.insert(toPos,
|
|
82
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
83
|
+
layoutColumn.create({
|
|
84
|
+
width: newColumnWidth
|
|
85
|
+
}, tr.doc.resolve(from).nodeAfter));
|
|
86
|
+
tr = tr.setSelection(new NodeSelection(tr.doc.resolve(toPos)));
|
|
87
|
+
var mappedFrom = tr.mapping.map(from);
|
|
88
|
+
var mappedFromEnd = mappedFrom + fromNode.nodeSize;
|
|
89
|
+
tr = tr.delete(mappedFrom, mappedFromEnd);
|
|
90
|
+
tr = tr.scrollIntoView();
|
|
91
|
+
return tr;
|
|
92
|
+
}
|
|
93
|
+
return tr;
|
|
94
|
+
} else {
|
|
95
|
+
// resolve again the source node after node updated (remove breakout marks)
|
|
96
|
+
var newFromNode = tr.doc.resolve(from).nodeAfter;
|
|
97
|
+
if (!newFromNode) {
|
|
98
|
+
return tr;
|
|
99
|
+
}
|
|
100
|
+
var layoutContents = position === 'left' ? [newFromNode, toNode] : [toNode, newFromNode];
|
|
58
101
|
var newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
59
102
|
if (newLayout) {
|
|
60
|
-
tr.delete(from,
|
|
103
|
+
tr = tr.delete(from, from + fromNode.nodeSize);
|
|
61
104
|
var mappedTo = tr.mapping.map(to);
|
|
62
|
-
tr.delete(mappedTo,
|
|
63
|
-
tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
105
|
+
tr = tr.delete(mappedTo, mappedTo + toNode.nodeSize);
|
|
106
|
+
tr = tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
107
|
+
tr = tr.setSelection(new NodeSelection(tr.doc.resolve(mappedTo)));
|
|
108
|
+
tr = tr.scrollIntoView();
|
|
64
109
|
}
|
|
65
110
|
return tr;
|
|
66
111
|
}
|
|
67
|
-
return tr;
|
|
68
112
|
};
|
|
69
113
|
};
|
|
70
114
|
};
|
|
@@ -282,6 +282,7 @@ var ObjHash = /*#__PURE__*/function () {
|
|
|
282
282
|
}();
|
|
283
283
|
_defineProperty(ObjHash, "caching", new WeakMap());
|
|
284
284
|
var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
285
|
+
// TODO use isWrappedMedia when clean up the featue flag
|
|
285
286
|
if ('mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1')) {
|
|
286
287
|
if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
|
|
287
288
|
return true;
|
|
@@ -289,6 +290,16 @@ var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
|
289
290
|
}
|
|
290
291
|
return IGNORE_NODES.includes(node.type.name);
|
|
291
292
|
};
|
|
293
|
+
export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
|
|
294
|
+
// Optimisation to avoid drawing node decorations for empty table cells
|
|
295
|
+
if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
|
|
296
|
+
var _node$firstChild;
|
|
297
|
+
if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
302
|
+
};
|
|
292
303
|
export var nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
293
304
|
var decs = [];
|
|
294
305
|
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
@@ -297,7 +308,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
|
297
308
|
var _Decoration$node2;
|
|
298
309
|
var depth = 0;
|
|
299
310
|
var anchorName;
|
|
300
|
-
var shouldDescend =
|
|
311
|
+
var shouldDescend = shouldDescendIntoNode(node);
|
|
301
312
|
var handleId = ObjHash.getForNode(node);
|
|
302
313
|
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
303
314
|
if (editorExperiment('nested-dnd', true)) {
|
|
@@ -14,17 +14,15 @@ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indi
|
|
|
14
14
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
15
15
|
import { getNodeAnchor } from '../pm-plugins/decorations';
|
|
16
16
|
import { isAnchorSupported } from '../utils/anchor-utils';
|
|
17
|
+
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
17
18
|
var dropTargetCommonStyle = css({
|
|
18
19
|
position: 'absolute',
|
|
19
20
|
display: 'block'
|
|
20
21
|
});
|
|
21
|
-
var hideDropTargetStyle = css({
|
|
22
|
-
display: 'none'
|
|
23
|
-
});
|
|
24
22
|
var hoverZoneCommonStyle = css({
|
|
25
23
|
position: 'absolute',
|
|
26
|
-
//
|
|
27
|
-
zIndex:
|
|
24
|
+
// above the top and bottom drop zone as block hover zone
|
|
25
|
+
zIndex: 120
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
// gap between node boundary and drop indicator/drop zone
|
|
@@ -32,6 +30,60 @@ var GAP = 4;
|
|
|
32
30
|
var HOVER_ZONE_WIDTH_OFFSET = 40;
|
|
33
31
|
var HOVER_ZONE_HEIGHT_OFFSET = 10;
|
|
34
32
|
var HOVER_ZONE_DEFAULT_WIDTH = 40;
|
|
33
|
+
var getDropTargetPositionOverride = function getDropTargetPositionOverride(node, editorWidth) {
|
|
34
|
+
if (!node || !editorWidth) {
|
|
35
|
+
return {
|
|
36
|
+
left: 0,
|
|
37
|
+
right: 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var getOffsets = function getOffsets(nodeWidth) {
|
|
41
|
+
var offset = (editorWidth - nodeWidth) / 2;
|
|
42
|
+
return {
|
|
43
|
+
left: offset,
|
|
44
|
+
right: offset
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
|
|
48
|
+
return getOffsets(node.attrs.width);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// media single 🤦
|
|
52
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
|
|
53
|
+
var mediaNodeWidth = 0;
|
|
54
|
+
if (node.attrs.width) {
|
|
55
|
+
if (node.attrs.widthType === 'pixel') {
|
|
56
|
+
mediaNodeWidth = node.attrs.width;
|
|
57
|
+
} else if (editorWidth) {
|
|
58
|
+
mediaNodeWidth = node.attrs.width / 100 * editorWidth;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
// use media width
|
|
62
|
+
var mediaNode = node.firstChild;
|
|
63
|
+
if (mediaNode && mediaNode.attrs.width) {
|
|
64
|
+
mediaNodeWidth = mediaNode.attrs.width;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (mediaNodeWidth) {
|
|
68
|
+
if (node.attrs.layout === 'align-start') {
|
|
69
|
+
return {
|
|
70
|
+
left: 0,
|
|
71
|
+
right: editorWidth - mediaNodeWidth
|
|
72
|
+
};
|
|
73
|
+
} else if (node.attrs.layout === 'align-end') {
|
|
74
|
+
return {
|
|
75
|
+
left: editorWidth - mediaNodeWidth,
|
|
76
|
+
right: 0
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return getOffsets(mediaNodeWidth);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
left: 0,
|
|
84
|
+
right: 0
|
|
85
|
+
};
|
|
86
|
+
};
|
|
35
87
|
export var InlineDropTarget = function InlineDropTarget(_ref) {
|
|
36
88
|
var api = _ref.api,
|
|
37
89
|
nextNode = _ref.nextNode,
|
|
@@ -51,22 +103,25 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
|
|
|
51
103
|
var handleDragLeave = useCallback(function () {
|
|
52
104
|
setIsDraggedOver(false);
|
|
53
105
|
}, []);
|
|
106
|
+
var offsets = useMemo(function () {
|
|
107
|
+
return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
|
|
108
|
+
}, [nextNode, widthState]);
|
|
54
109
|
var dropTargetRectStyle = useMemo(function () {
|
|
55
110
|
if (isAnchorSupported()) {
|
|
56
111
|
return css({
|
|
57
112
|
height: "calc(anchor-size(".concat(anchorName, " height))"),
|
|
58
113
|
positionAnchor: anchorName,
|
|
59
|
-
left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
114
|
+
left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
|
|
60
115
|
top: "calc(anchor(top))"
|
|
61
116
|
});
|
|
62
117
|
}
|
|
63
118
|
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
64
119
|
return css({
|
|
65
120
|
height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
|
|
66
|
-
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
121
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP + offsets.left, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offsets.right, "px"),
|
|
67
122
|
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
|
|
68
123
|
});
|
|
69
|
-
}, [anchorName, anchorRectCache, position]);
|
|
124
|
+
}, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
|
|
70
125
|
var onDrop = useCallback(function () {
|
|
71
126
|
var _api$blockControls;
|
|
72
127
|
var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
@@ -83,8 +138,8 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
|
|
|
83
138
|
}, [api, getPos, position]);
|
|
84
139
|
return jsx(Fragment, null, jsx("div", {
|
|
85
140
|
"data-test-id": "block-ctrl-drop-target-".concat(position),
|
|
86
|
-
css: [dropTargetCommonStyle, dropTargetRectStyle
|
|
87
|
-
}, jsx(DropIndicator, {
|
|
141
|
+
css: [dropTargetCommonStyle, dropTargetRectStyle]
|
|
142
|
+
}, (isDraggedOver || isBlocksDragTargetDebug()) && jsx(DropIndicator, {
|
|
88
143
|
edge: position
|
|
89
144
|
})), jsx(InlineHoverZone, {
|
|
90
145
|
position: position,
|
|
@@ -93,7 +148,8 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
|
|
|
93
148
|
anchorRectCache: anchorRectCache,
|
|
94
149
|
onDragEnter: handleDragEnter,
|
|
95
150
|
onDragLeave: handleDragLeave,
|
|
96
|
-
onDrop: onDrop
|
|
151
|
+
onDrop: onDrop,
|
|
152
|
+
offsets: offsets
|
|
97
153
|
}));
|
|
98
154
|
};
|
|
99
155
|
export var InlineHoverZone = function InlineHoverZone(_ref3) {
|
|
@@ -101,6 +157,7 @@ export var InlineHoverZone = function InlineHoverZone(_ref3) {
|
|
|
101
157
|
editorWidthState = _ref3.editorWidthState,
|
|
102
158
|
anchorRectCache = _ref3.anchorRectCache,
|
|
103
159
|
position = _ref3.position,
|
|
160
|
+
offsets = _ref3.offsets,
|
|
104
161
|
onDragEnter = _ref3.onDragEnter,
|
|
105
162
|
onDragLeave = _ref3.onDragLeave,
|
|
106
163
|
onDrop = _ref3.onDrop;
|
|
@@ -119,27 +176,29 @@ export var InlineHoverZone = function InlineHoverZone(_ref3) {
|
|
|
119
176
|
}
|
|
120
177
|
}, [onDragEnter, onDragLeave, onDrop]);
|
|
121
178
|
var inlineHoverZoneRectStyle = useMemo(function () {
|
|
179
|
+
var offset = offsets[position];
|
|
122
180
|
if (isAnchorSupported()) {
|
|
123
181
|
return css({
|
|
124
182
|
positionAnchor: anchorName,
|
|
125
|
-
left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
126
|
-
right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
|
|
183
|
+
left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
|
|
184
|
+
right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
|
|
127
185
|
top: "calc(anchor(top))",
|
|
128
|
-
width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
|
|
186
|
+
width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px + ").concat(offset, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
|
|
129
187
|
height: "calc(anchor-size(".concat(anchorName, " height))")
|
|
130
188
|
});
|
|
131
189
|
}
|
|
132
190
|
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
133
|
-
var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
|
|
191
|
+
var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
|
|
134
192
|
return css({
|
|
135
|
-
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
193
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP + offset, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offset, "px"),
|
|
136
194
|
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
|
|
137
195
|
width: "".concat(width, "px"),
|
|
138
196
|
height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
|
|
139
197
|
});
|
|
140
|
-
}, [anchorName, anchorRectCache, editorWith, position]);
|
|
198
|
+
}, [anchorName, anchorRectCache, editorWith, offsets, position]);
|
|
141
199
|
return jsx("div", {
|
|
142
200
|
ref: ref,
|
|
201
|
+
"data-test-id": "drop-target-hover-zone-".concat(position),
|
|
143
202
|
css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
|
|
144
203
|
});
|
|
145
204
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
|
|
3
3
|
import { isPreRelease1 } from './advanced-layouts-flags';
|
|
4
|
+
import { isWrappedMedia } from './check-media-layout';
|
|
4
5
|
export var shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
|
|
5
6
|
if (!isPreRelease1() || isNested) {
|
|
6
7
|
return false;
|
|
7
8
|
}
|
|
9
|
+
if (isWrappedMedia(node)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
8
12
|
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
|
|
9
13
|
return node.childCount < MAX_LAYOUT_COLUMN_SUPPORTED;
|
|
10
14
|
}
|
|
@@ -30,5 +30,6 @@ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, t
|
|
|
30
30
|
export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
|
|
31
31
|
export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
|
|
32
32
|
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
33
|
+
export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
|
|
33
34
|
export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
|
|
34
35
|
export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
|
|
@@ -3,6 +3,10 @@ import { type EditorContainerWidth } from '@atlaskit/editor-common/src/types';
|
|
|
3
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { type AnchorRectCache } from '../utils/anchor-utils';
|
|
5
5
|
import { type DropTargetProps } from './drop-target';
|
|
6
|
+
type DropTargetOffsets = {
|
|
7
|
+
left: number;
|
|
8
|
+
right: number;
|
|
9
|
+
};
|
|
6
10
|
export declare const InlineDropTarget: ({ api, nextNode, position, anchorRectCache, getPos, }: DropTargetProps & {
|
|
7
11
|
anchorRectCache?: AnchorRectCache | undefined;
|
|
8
12
|
position: 'left' | 'right';
|
|
@@ -12,9 +16,10 @@ type InlineHoverZoneProps = {
|
|
|
12
16
|
editorWidthState?: EditorContainerWidth;
|
|
13
17
|
anchorRectCache?: AnchorRectCache;
|
|
14
18
|
position: 'left' | 'right';
|
|
19
|
+
offsets: DropTargetOffsets;
|
|
15
20
|
onDragEnter: () => void;
|
|
16
21
|
onDragLeave: () => void;
|
|
17
22
|
onDrop: () => void;
|
|
18
23
|
};
|
|
19
|
-
export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
|
|
24
|
+
export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, offsets, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
|
|
20
25
|
export {};
|
|
@@ -30,5 +30,6 @@ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, t
|
|
|
30
30
|
export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
|
|
31
31
|
export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
|
|
32
32
|
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
33
|
+
export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
|
|
33
34
|
export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
|
|
34
35
|
export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
|
|
@@ -3,6 +3,10 @@ import { type EditorContainerWidth } from '@atlaskit/editor-common/src/types';
|
|
|
3
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { type AnchorRectCache } from '../utils/anchor-utils';
|
|
5
5
|
import { type DropTargetProps } from './drop-target';
|
|
6
|
+
type DropTargetOffsets = {
|
|
7
|
+
left: number;
|
|
8
|
+
right: number;
|
|
9
|
+
};
|
|
6
10
|
export declare const InlineDropTarget: ({ api, nextNode, position, anchorRectCache, getPos, }: DropTargetProps & {
|
|
7
11
|
anchorRectCache?: AnchorRectCache | undefined;
|
|
8
12
|
position: 'left' | 'right';
|
|
@@ -12,9 +16,10 @@ type InlineHoverZoneProps = {
|
|
|
12
16
|
editorWidthState?: EditorContainerWidth;
|
|
13
17
|
anchorRectCache?: AnchorRectCache;
|
|
14
18
|
position: 'left' | 'right';
|
|
19
|
+
offsets: DropTargetOffsets;
|
|
15
20
|
onDragEnter: () => void;
|
|
16
21
|
onDragLeave: () => void;
|
|
17
22
|
onDrop: () => void;
|
|
18
23
|
};
|
|
19
|
-
export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
|
|
24
|
+
export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, offsets, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
|
|
20
25
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,25 +30,25 @@
|
|
|
30
30
|
".": "./src/index.ts"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@atlaskit/adf-schema": "^42.
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
33
|
+
"@atlaskit/adf-schema": "^42.3.1",
|
|
34
|
+
"@atlaskit/editor-common": "^94.2.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",
|
|
38
38
|
"@atlaskit/editor-plugin-feature-flags": "^1.2.0",
|
|
39
|
-
"@atlaskit/editor-plugin-quick-insert": "^1.
|
|
39
|
+
"@atlaskit/editor-plugin-quick-insert": "^1.5.0",
|
|
40
40
|
"@atlaskit/editor-plugin-width": "^1.3.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "6.0.0",
|
|
42
42
|
"@atlaskit/editor-shared-styles": "^3.0.0",
|
|
43
43
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
44
|
-
"@atlaskit/icon": "^22.
|
|
44
|
+
"@atlaskit/icon": "^22.24.0",
|
|
45
45
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
46
46
|
"@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
|
|
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.8.0",
|
|
52
52
|
"@atlaskit/tokens": "^2.0.0",
|
|
53
53
|
"@atlaskit/tooltip": "^18.8.0",
|
|
54
54
|
"@babel/runtime": "^7.0.0",
|