@atlaskit/editor-plugin-block-controls 1.9.0 → 1.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 +14 -0
- package/dist/cjs/commands/move-node.js +23 -4
- package/dist/cjs/pm-plugins/decorations.js +66 -14
- package/dist/cjs/pm-plugins/handle-mouse-over.js +8 -1
- package/dist/cjs/pm-plugins/main.js +16 -8
- package/dist/cjs/ui/consts.js +6 -4
- package/dist/cjs/ui/drop-target.js +3 -3
- package/dist/cjs/ui/global-styles.js +47 -2
- package/dist/es2019/commands/move-node.js +22 -4
- package/dist/es2019/pm-plugins/decorations.js +67 -14
- package/dist/es2019/pm-plugins/handle-mouse-over.js +8 -1
- package/dist/es2019/pm-plugins/main.js +16 -8
- package/dist/es2019/ui/consts.js +5 -3
- package/dist/es2019/ui/drop-target.js +3 -3
- package/dist/es2019/ui/global-styles.js +47 -2
- package/dist/esm/commands/move-node.js +22 -4
- package/dist/esm/pm-plugins/decorations.js +66 -14
- package/dist/esm/pm-plugins/handle-mouse-over.js +8 -1
- package/dist/esm/pm-plugins/main.js +16 -8
- package/dist/esm/ui/consts.js +5 -3
- package/dist/esm/ui/drop-target.js +3 -3
- package/dist/esm/ui/global-styles.js +47 -2
- package/dist/types/pm-plugins/decorations.d.ts +1 -1
- package/dist/types/types.d.ts +1 -1
- package/dist/types/ui/consts.d.ts +3 -0
- package/dist/types/ui/drop-target.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/dist/types-ts4.5/ui/consts.d.ts +3 -0
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -2
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#123594](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/123594)
|
|
8
|
+
[`ea6c9a5361f96`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ea6c9a5361f96) -
|
|
9
|
+
[ux] Add prelim nested DnD support
|
|
10
|
+
|
|
11
|
+
## 1.9.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 1.9.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -8,6 +8,7 @@ exports.moveNodeViaShortcut = exports.moveNode = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
11
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
11
12
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
13
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var _consts = require("../consts");
|
|
@@ -15,6 +16,14 @@ var _main = require("../pm-plugins/main");
|
|
|
15
16
|
var _utils2 = require("../utils");
|
|
16
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
function transformNested(nodeCopy, destType) {
|
|
20
|
+
var firstChild = nodeCopy.content.firstChild;
|
|
21
|
+
if (firstChild && firstChild.type.name === 'nestedExpand' && destType === 'doc') {
|
|
22
|
+
return (0, _transforms.transformSliceNestedExpandToExpand)(nodeCopy, firstChild.type.schema);
|
|
23
|
+
}
|
|
24
|
+
return nodeCopy;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
/**
|
|
19
28
|
*
|
|
20
29
|
* @returns the start position of a node if the node can be moved, otherwise -1
|
|
@@ -105,10 +114,20 @@ var moveNode = exports.moveNode = function moveNode(api) {
|
|
|
105
114
|
}
|
|
106
115
|
var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
107
116
|
var end = start + size;
|
|
108
|
-
var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
var mappedTo;
|
|
118
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
119
|
+
var nodeCopy = tr.doc.slice(start, end, false); // cut the content
|
|
120
|
+
var destType = tr.doc.resolve(to).node().type.name;
|
|
121
|
+
var convertedNode = transformNested(nodeCopy, destType).content;
|
|
122
|
+
tr.delete(start, end); // delete the content from the original position
|
|
123
|
+
mappedTo = tr.mapping.map(to);
|
|
124
|
+
tr.insert(mappedTo, convertedNode); // insert the content at the new position
|
|
125
|
+
} else {
|
|
126
|
+
var _nodeCopy = tr.doc.content.cut(start, end); // cut the content
|
|
127
|
+
tr.delete(start, end); // delete the content from the original position
|
|
128
|
+
mappedTo = tr.mapping.map(to);
|
|
129
|
+
tr.insert(mappedTo, _nodeCopy); // insert the content at the new position
|
|
130
|
+
}
|
|
112
131
|
tr = (0, _utils2.selectNode)(tr, mappedTo, node.type.name);
|
|
113
132
|
tr.setMeta(_main.key, {
|
|
114
133
|
nodeMoved: true
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.nodeDecorations = exports.mouseMoveWrapperDecorations = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = require("react");
|
|
10
|
+
var _bindEventListener = require("bind-event-listener");
|
|
10
11
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
12
|
var _reactIntlNext = require("react-intl-next");
|
|
12
13
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
@@ -14,6 +15,8 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
14
15
|
var _dragHandle = require("../ui/drag-handle");
|
|
15
16
|
var _dropTarget = require("../ui/drop-target");
|
|
16
17
|
var _mouseMoveWrapper = require("../ui/mouse-move-wrapper");
|
|
18
|
+
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
19
|
+
var NESTED_DEPTH = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
17
20
|
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
18
21
|
var decs = [];
|
|
19
22
|
unmountDecorations('data-blocks-drop-target-container');
|
|
@@ -23,13 +26,28 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
23
26
|
var prevNode;
|
|
24
27
|
var state = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24372') ? newState : oldState;
|
|
25
28
|
state.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos, _parent, index) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
var depth = 0;
|
|
30
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
31
|
+
depth = newState.doc.resolve(pos).depth;
|
|
32
|
+
if (node.isInline) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (IGNORE_NODES.includes(node.type.name)) {
|
|
36
|
+
return true; //skip over, don't consider it a valid depth
|
|
37
|
+
}
|
|
38
|
+
decorationState.push({
|
|
39
|
+
id: pos,
|
|
40
|
+
pos: pos
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
decorationState.push({
|
|
44
|
+
id: index,
|
|
45
|
+
pos: pos
|
|
46
|
+
});
|
|
47
|
+
}
|
|
30
48
|
var dropTargetDec = /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
31
49
|
api: api,
|
|
32
|
-
|
|
50
|
+
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? pos : index,
|
|
33
51
|
prevNode: prevNode,
|
|
34
52
|
nextNode: node
|
|
35
53
|
});
|
|
@@ -44,7 +62,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
44
62
|
side: -1
|
|
45
63
|
}));
|
|
46
64
|
prevNode = node;
|
|
47
|
-
return
|
|
65
|
+
return depth < NESTED_DEPTH;
|
|
48
66
|
});
|
|
49
67
|
|
|
50
68
|
/**
|
|
@@ -54,16 +72,25 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
54
72
|
* node and not its size.
|
|
55
73
|
*
|
|
56
74
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
|
|
76
|
+
var lastPos = newState.doc.content.size;
|
|
77
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
78
|
+
decorationState.push({
|
|
79
|
+
id: lastPos,
|
|
80
|
+
pos: lastPos
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
decorationState.push({
|
|
84
|
+
id: decorationState.length + 1,
|
|
85
|
+
pos: newState.doc.nodeSize - 2
|
|
86
|
+
});
|
|
87
|
+
}
|
|
61
88
|
decs.push(_view.Decoration.widget(newState.doc.nodeSize - 2, function () {
|
|
62
89
|
var element = document.createElement('div');
|
|
63
90
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
64
91
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
65
92
|
api: api,
|
|
66
|
-
|
|
93
|
+
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length
|
|
67
94
|
}), element);
|
|
68
95
|
return element;
|
|
69
96
|
}, {
|
|
@@ -87,7 +114,20 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
87
114
|
var decs = [];
|
|
88
115
|
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
89
116
|
var _Decoration$node2;
|
|
90
|
-
var
|
|
117
|
+
var depth = 0;
|
|
118
|
+
var anchorName;
|
|
119
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
120
|
+
if (node.isInline) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (IGNORE_NODES.includes(node.type.name)) {
|
|
124
|
+
return true; //skip over, don't consider it a valid depth
|
|
125
|
+
}
|
|
126
|
+
depth = newState.doc.resolve(pos).depth;
|
|
127
|
+
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(pos);
|
|
128
|
+
} else {
|
|
129
|
+
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
130
|
+
}
|
|
91
131
|
var style;
|
|
92
132
|
if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
93
133
|
style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;");
|
|
@@ -96,10 +136,10 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
96
136
|
}
|
|
97
137
|
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
98
138
|
style: style
|
|
99
|
-
}, (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _Decoration$node2), {
|
|
139
|
+
}, (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node2), {
|
|
100
140
|
type: 'node-decoration'
|
|
101
141
|
}));
|
|
102
|
-
return
|
|
142
|
+
return depth < NESTED_DEPTH;
|
|
103
143
|
});
|
|
104
144
|
return decs;
|
|
105
145
|
};
|
|
@@ -143,6 +183,7 @@ var mouseMoveWrapperDecorations = exports.mouseMoveWrapperDecorations = function
|
|
|
143
183
|
return decs;
|
|
144
184
|
};
|
|
145
185
|
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(api, getIntl, pos, anchorName, nodeType, handleOptions) {
|
|
186
|
+
var unbind;
|
|
146
187
|
var elementType = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24150') ? 'span' : 'div';
|
|
147
188
|
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
148
189
|
var element = document.createElement(elementType);
|
|
@@ -150,6 +191,14 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
150
191
|
element.style.display = 'inline';
|
|
151
192
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
152
193
|
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
194
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
195
|
+
unbind = (0, _bindEventListener.bind)(element, {
|
|
196
|
+
type: 'mouseover',
|
|
197
|
+
listener: function listener(e) {
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
153
202
|
if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
154
203
|
unmountDecorations('data-blocks-drag-handle-container');
|
|
155
204
|
}
|
|
@@ -173,6 +222,9 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
173
222
|
side: -1,
|
|
174
223
|
id: 'drag-handle',
|
|
175
224
|
destroy: function destroy(node) {
|
|
225
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
226
|
+
unbind && unbind();
|
|
227
|
+
}
|
|
176
228
|
if (!(0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
177
229
|
_reactDom.default.unmountComponentAtNode(node);
|
|
178
230
|
}
|
|
@@ -29,7 +29,14 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
var pos = view.posAtDOM(rootElement, 0, 0);
|
|
32
|
-
var rootPos
|
|
32
|
+
var rootPos;
|
|
33
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
34
|
+
var $rootPos = view.state.doc.resolve(pos);
|
|
35
|
+
var depth = $rootPos.depth;
|
|
36
|
+
rootPos = depth ? $rootPos.before() : $rootPos.pos;
|
|
37
|
+
} else {
|
|
38
|
+
rootPos = view.state.doc.resolve(pos).start(1) - 1;
|
|
39
|
+
}
|
|
33
40
|
var nodeType = rootElement.getAttribute('data-drag-handler-node-type');
|
|
34
41
|
if (nodeType) {
|
|
35
42
|
var _api$core, _api$blockControls2;
|
|
@@ -155,14 +155,22 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
155
155
|
var spec = _ref7.spec;
|
|
156
156
|
return spec.id !== 'drag-handle';
|
|
157
157
|
}).length;
|
|
158
|
-
|
|
158
|
+
|
|
159
|
+
//TODO: Fix this logic for nested scenarios
|
|
160
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
161
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
162
|
+
}
|
|
159
163
|
}
|
|
160
164
|
if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24372')) {
|
|
161
165
|
var dropTargetLen = decorations.find().filter(function (_ref8) {
|
|
162
166
|
var spec = _ref8.spec;
|
|
163
167
|
return spec.type === 'drop-target-decoration';
|
|
164
168
|
}).length;
|
|
165
|
-
|
|
169
|
+
|
|
170
|
+
//TODO: Fix this logic for nested scenarios
|
|
171
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
172
|
+
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
173
|
+
}
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
@@ -252,7 +260,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
252
260
|
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
253
261
|
var shouldMapDropTargets = false;
|
|
254
262
|
if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24372')) {
|
|
255
|
-
shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging;
|
|
263
|
+
shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
256
264
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
257
265
|
// Remove drop target decoration when dragging stops
|
|
258
266
|
var dropTargetDecs = decorations.find().filter(function (_ref12) {
|
|
@@ -273,13 +281,13 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
273
281
|
}
|
|
274
282
|
}
|
|
275
283
|
|
|
276
|
-
//
|
|
284
|
+
//Map drop target decoration positions when the document changes
|
|
277
285
|
if (shouldMapDropTargets) {
|
|
278
286
|
decorationState = decorationState.map(function (_ref13) {
|
|
279
|
-
var
|
|
287
|
+
var id = _ref13.id,
|
|
280
288
|
pos = _ref13.pos;
|
|
281
289
|
return {
|
|
282
|
-
|
|
290
|
+
id: id,
|
|
283
291
|
pos: tr.mapping.map(pos)
|
|
284
292
|
};
|
|
285
293
|
});
|
|
@@ -310,10 +318,10 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
310
318
|
// Map drop target decoration positions when the document changes
|
|
311
319
|
if (tr.docChanged && isDragging) {
|
|
312
320
|
decorationState = decorationState.map(function (_ref15) {
|
|
313
|
-
var
|
|
321
|
+
var id = _ref15.id,
|
|
314
322
|
pos = _ref15.pos;
|
|
315
323
|
return {
|
|
316
|
-
|
|
324
|
+
id: id,
|
|
317
325
|
pos: tr.mapping.map(pos)
|
|
318
326
|
};
|
|
319
327
|
});
|
package/dist/cjs/ui/consts.js
CHANGED
|
@@ -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.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
7
|
+
exports.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DEFAULT_GAP = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
10
10
|
var _dropTargetMarginMap;
|
|
@@ -12,15 +12,17 @@ var DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_HEIGHT = 24;
|
|
|
12
12
|
var DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_WIDTH = 12;
|
|
13
13
|
var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
14
14
|
var DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_ZINDEX = _editorSharedStyles.akRichMediaResizeZIndex + _editorSharedStyles.akEditorUnitZIndex; //place above legacy resizer
|
|
15
|
-
|
|
15
|
+
var DRAG_HANDLE_DEFAULT_GAP = exports.DRAG_HANDLE_DEFAULT_GAP = 8;
|
|
16
|
+
var DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_MAX_GAP = 12;
|
|
17
|
+
var DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = DRAG_HANDLE_WIDTH + DRAG_HANDLE_MAX_GAP;
|
|
16
18
|
var DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = 4 + 2; // 4px for the divider vertical padding and 2px for the divider height
|
|
17
19
|
|
|
18
20
|
var nodeTypeExcludeList = ['embedCard', 'mediaSingle', 'table'];
|
|
19
21
|
var dragHandleGap = exports.dragHandleGap = function dragHandleGap(nodeType) {
|
|
20
22
|
if (nodeTypeExcludeList.includes(nodeType)) {
|
|
21
|
-
return
|
|
23
|
+
return DRAG_HANDLE_MAX_GAP;
|
|
22
24
|
}
|
|
23
|
-
return
|
|
25
|
+
return DRAG_HANDLE_DEFAULT_GAP;
|
|
24
26
|
};
|
|
25
27
|
var topPositionAdjustment = exports.topPositionAdjustment = function topPositionAdjustment(nodeType) {
|
|
26
28
|
switch (nodeType) {
|
|
@@ -77,7 +77,7 @@ var styleDropIndicator = (0, _react2.css)({
|
|
|
77
77
|
});
|
|
78
78
|
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
79
79
|
var api = _ref3.api,
|
|
80
|
-
|
|
80
|
+
id = _ref3.id,
|
|
81
81
|
prevNode = _ref3.prevNode,
|
|
82
82
|
nextNode = _ref3.nextNode;
|
|
83
83
|
var ref = (0, _react.useRef)(null);
|
|
@@ -113,7 +113,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
var _ref5 = decorationState.find(function (dec) {
|
|
116
|
-
return dec.
|
|
116
|
+
return dec.id === id;
|
|
117
117
|
}) || {},
|
|
118
118
|
pos = _ref5.pos;
|
|
119
119
|
if (activeNode && pos !== undefined) {
|
|
@@ -123,7 +123,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
-
}, [
|
|
126
|
+
}, [id, api]);
|
|
127
127
|
var topTargetMarginStyle = (0, _react.useMemo)(function () {
|
|
128
128
|
return getDropTargetPositionStyle(prevNode, nextNode);
|
|
129
129
|
}, [prevNode, nextNode]);
|
|
@@ -8,6 +8,7 @@ exports.GlobalStylesWrapper = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = require("@emotion/react");
|
|
10
10
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _consts = require("./consts");
|
|
11
12
|
/**
|
|
12
13
|
* @jsxRuntime classic
|
|
13
14
|
* @jsx jsx
|
|
@@ -40,11 +41,55 @@ var extendedHoverZone = (0, _react.css)({
|
|
|
40
41
|
'hr[data-drag-handler-anchor-name]': {
|
|
41
42
|
overflow: 'visible'
|
|
42
43
|
},
|
|
43
|
-
//
|
|
44
|
+
//eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
44
45
|
'[data-blocks-drag-handle-container="true"] + *::after': {
|
|
45
46
|
display: 'none'
|
|
46
47
|
}
|
|
47
48
|
});
|
|
49
|
+
var extendedHoverZoneNested = (0, _react.css)({
|
|
50
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
51
|
+
'.block-ctrl-drag-preview [data-drag-handler-anchor-name]::after': {
|
|
52
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
53
|
+
display: 'none !important'
|
|
54
|
+
},
|
|
55
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
56
|
+
'.ProseMirror': {
|
|
57
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
|
|
58
|
+
'&& [data-drag-handler-anchor-name]::after': {
|
|
59
|
+
content: '""',
|
|
60
|
+
position: 'absolute',
|
|
61
|
+
top: 0,
|
|
62
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
63
|
+
left: "-".concat(_consts.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP, "px"),
|
|
64
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
65
|
+
width: "".concat(_consts.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP, "px"),
|
|
66
|
+
height: '100%',
|
|
67
|
+
cursor: 'default',
|
|
68
|
+
zIndex: 1
|
|
69
|
+
},
|
|
70
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
|
|
71
|
+
'&& [data-drag-handler-anchor-depth="0"][data-drag-handler-anchor-name]::after': {
|
|
72
|
+
content: '""',
|
|
73
|
+
position: 'absolute',
|
|
74
|
+
top: 0,
|
|
75
|
+
left: '-100%',
|
|
76
|
+
width: '100%',
|
|
77
|
+
height: '100%',
|
|
78
|
+
cursor: 'default',
|
|
79
|
+
zIndex: -1
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
// TODO - ED-23995 this style override needs to be moved to the Rule styles after FF cleanup - packages/editor/editor-common/src/styles/shared/rule.ts
|
|
83
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
84
|
+
'hr[data-drag-handler-anchor-name]': {
|
|
85
|
+
overflow: 'visible'
|
|
86
|
+
},
|
|
87
|
+
//Hide psudeo element at top depth level. Leave for nested depths to prevent mouseover loop.
|
|
88
|
+
//eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
89
|
+
'[data-blocks-drag-handle-container="true"] + [data-drag-handler-anchor-depth="0"]::after': {
|
|
90
|
+
display: 'none'
|
|
91
|
+
}
|
|
92
|
+
});
|
|
48
93
|
var paragraphWithTrailingBreak = '+ p > .ProseMirror-trailingBreak';
|
|
49
94
|
var paragraphWithCursorTarget = '+ p > .cursor-target';
|
|
50
95
|
var paragraphWithTrailingBreakAsOnlyChild = '+ p > .ProseMirror-trailingBreak:only-child';
|
|
@@ -104,6 +149,6 @@ var getTextNodeStyle = function getTextNodeStyle() {
|
|
|
104
149
|
};
|
|
105
150
|
var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
106
151
|
return (0, _react.jsx)(_react.Global, {
|
|
107
|
-
styles: [globalStyles, (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')
|
|
152
|
+
styles: [globalStyles, (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? extendedHoverZoneNested : extendedHoverZone : false, getTextNodeStyle(), (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-ed-23932') && withDeleteLinesStyleFix, (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24005') && withMediaSingleStyleFix]
|
|
108
153
|
});
|
|
109
154
|
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { transformSliceNestedExpandToExpand } from '@atlaskit/editor-common/transforms';
|
|
3
4
|
import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { DIRECTION } from '../consts';
|
|
6
7
|
import { key } from '../pm-plugins/main';
|
|
7
8
|
import { selectNode } from '../utils';
|
|
9
|
+
function transformNested(nodeCopy, destType) {
|
|
10
|
+
const firstChild = nodeCopy.content.firstChild;
|
|
11
|
+
if (firstChild && firstChild.type.name === 'nestedExpand' && destType === 'doc') {
|
|
12
|
+
return transformSliceNestedExpandToExpand(nodeCopy, firstChild.type.schema);
|
|
13
|
+
}
|
|
14
|
+
return nodeCopy;
|
|
15
|
+
}
|
|
8
16
|
|
|
9
17
|
/**
|
|
10
18
|
*
|
|
@@ -99,10 +107,20 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
|
|
|
99
107
|
}
|
|
100
108
|
const size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
101
109
|
const end = start + size;
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
let mappedTo;
|
|
111
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
112
|
+
const nodeCopy = tr.doc.slice(start, end, false); // cut the content
|
|
113
|
+
const destType = tr.doc.resolve(to).node().type.name;
|
|
114
|
+
const convertedNode = transformNested(nodeCopy, destType).content;
|
|
115
|
+
tr.delete(start, end); // delete the content from the original position
|
|
116
|
+
mappedTo = tr.mapping.map(to);
|
|
117
|
+
tr.insert(mappedTo, convertedNode); // insert the content at the new position
|
|
118
|
+
} else {
|
|
119
|
+
const nodeCopy = tr.doc.content.cut(start, end); // cut the content
|
|
120
|
+
tr.delete(start, end); // delete the content from the original position
|
|
121
|
+
mappedTo = tr.mapping.map(to);
|
|
122
|
+
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
123
|
+
}
|
|
106
124
|
tr = selectNode(tr, mappedTo, node.type.name);
|
|
107
125
|
tr.setMeta(key, {
|
|
108
126
|
nodeMoved: true
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
2
3
|
import ReactDOM from 'react-dom';
|
|
3
4
|
import { RawIntlProvider } from 'react-intl-next';
|
|
4
5
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -6,6 +7,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
6
7
|
import { DragHandle } from '../ui/drag-handle';
|
|
7
8
|
import { DropTarget } from '../ui/drop-target';
|
|
8
9
|
import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
|
|
10
|
+
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
11
|
+
const NESTED_DEPTH = fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
9
12
|
export const dropTargetDecorations = (oldState, newState, api) => {
|
|
10
13
|
const decs = [];
|
|
11
14
|
unmountDecorations('data-blocks-drop-target-container');
|
|
@@ -15,13 +18,28 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
15
18
|
let prevNode;
|
|
16
19
|
const state = fg('platform_editor_element_drag_and_drop_ed_24372') ? newState : oldState;
|
|
17
20
|
state.doc.nodesBetween(0, newState.doc.nodeSize - 2, (node, pos, _parent, index) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
pos
|
|
21
|
-
|
|
21
|
+
let depth = 0;
|
|
22
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
23
|
+
depth = newState.doc.resolve(pos).depth;
|
|
24
|
+
if (node.isInline) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (IGNORE_NODES.includes(node.type.name)) {
|
|
28
|
+
return true; //skip over, don't consider it a valid depth
|
|
29
|
+
}
|
|
30
|
+
decorationState.push({
|
|
31
|
+
id: pos,
|
|
32
|
+
pos
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
decorationState.push({
|
|
36
|
+
id: index,
|
|
37
|
+
pos
|
|
38
|
+
});
|
|
39
|
+
}
|
|
22
40
|
const dropTargetDec = /*#__PURE__*/createElement(DropTarget, {
|
|
23
41
|
api,
|
|
24
|
-
index,
|
|
42
|
+
id: fg('platform_editor_elements_dnd_nested') ? pos : index,
|
|
25
43
|
prevNode,
|
|
26
44
|
nextNode: node
|
|
27
45
|
});
|
|
@@ -36,7 +54,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
36
54
|
side: -1
|
|
37
55
|
}));
|
|
38
56
|
prevNode = node;
|
|
39
|
-
return
|
|
57
|
+
return depth < NESTED_DEPTH;
|
|
40
58
|
});
|
|
41
59
|
|
|
42
60
|
/**
|
|
@@ -46,16 +64,25 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
46
64
|
* node and not its size.
|
|
47
65
|
*
|
|
48
66
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
|
|
68
|
+
const lastPos = newState.doc.content.size;
|
|
69
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
70
|
+
decorationState.push({
|
|
71
|
+
id: lastPos,
|
|
72
|
+
pos: lastPos
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
decorationState.push({
|
|
76
|
+
id: decorationState.length + 1,
|
|
77
|
+
pos: newState.doc.nodeSize - 2
|
|
78
|
+
});
|
|
79
|
+
}
|
|
53
80
|
decs.push(Decoration.widget(newState.doc.nodeSize - 2, () => {
|
|
54
81
|
const element = document.createElement('div');
|
|
55
82
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
56
83
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
57
84
|
api,
|
|
58
|
-
|
|
85
|
+
id: fg('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length
|
|
59
86
|
}), element);
|
|
60
87
|
return element;
|
|
61
88
|
}, {
|
|
@@ -79,7 +106,20 @@ export const emptyParagraphNodeDecorations = () => {
|
|
|
79
106
|
export const nodeDecorations = newState => {
|
|
80
107
|
const decs = [];
|
|
81
108
|
newState.doc.descendants((node, pos, _parent, index) => {
|
|
82
|
-
|
|
109
|
+
let depth = 0;
|
|
110
|
+
let anchorName;
|
|
111
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
112
|
+
if (node.isInline) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (IGNORE_NODES.includes(node.type.name)) {
|
|
116
|
+
return true; //skip over, don't consider it a valid depth
|
|
117
|
+
}
|
|
118
|
+
depth = newState.doc.resolve(pos).depth;
|
|
119
|
+
anchorName = `--node-anchor-${node.type.name}-${pos}`;
|
|
120
|
+
} else {
|
|
121
|
+
anchorName = `--node-anchor-${node.type.name}-${index}`;
|
|
122
|
+
}
|
|
83
123
|
let style;
|
|
84
124
|
if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
85
125
|
style = `anchor-name: ${anchorName}; ${pos === 0 ? 'margin-top: 0px;' : ''}; position: relative; z-index: 1;`;
|
|
@@ -89,11 +129,12 @@ export const nodeDecorations = newState => {
|
|
|
89
129
|
decs.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
90
130
|
style,
|
|
91
131
|
['data-drag-handler-anchor-name']: anchorName,
|
|
92
|
-
['data-drag-handler-node-type']: node.type.name
|
|
132
|
+
['data-drag-handler-node-type']: node.type.name,
|
|
133
|
+
['data-drag-handler-anchor-depth']: `${depth}`
|
|
93
134
|
}, {
|
|
94
135
|
type: 'node-decoration'
|
|
95
136
|
}));
|
|
96
|
-
return
|
|
137
|
+
return depth < NESTED_DEPTH;
|
|
97
138
|
});
|
|
98
139
|
return decs;
|
|
99
140
|
};
|
|
@@ -137,6 +178,7 @@ export const mouseMoveWrapperDecorations = (newState, api) => {
|
|
|
137
178
|
return decs;
|
|
138
179
|
};
|
|
139
180
|
export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, handleOptions) => {
|
|
181
|
+
let unbind;
|
|
140
182
|
const elementType = fg('platform_editor_element_drag_and_drop_ed_24150') ? 'span' : 'div';
|
|
141
183
|
return Decoration.widget(pos, (view, getPos) => {
|
|
142
184
|
const element = document.createElement(elementType);
|
|
@@ -144,6 +186,14 @@ export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, ha
|
|
|
144
186
|
element.style.display = 'inline';
|
|
145
187
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
146
188
|
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
189
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
190
|
+
unbind = bind(element, {
|
|
191
|
+
type: 'mouseover',
|
|
192
|
+
listener: e => {
|
|
193
|
+
e.stopPropagation();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
147
197
|
if (fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
148
198
|
unmountDecorations('data-blocks-drag-handle-container');
|
|
149
199
|
}
|
|
@@ -167,6 +217,9 @@ export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, ha
|
|
|
167
217
|
side: -1,
|
|
168
218
|
id: 'drag-handle',
|
|
169
219
|
destroy: node => {
|
|
220
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
221
|
+
unbind && unbind();
|
|
222
|
+
}
|
|
170
223
|
if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
171
224
|
ReactDOM.unmountComponentAtNode(node);
|
|
172
225
|
}
|
|
@@ -24,7 +24,14 @@ export const handleMouseOver = (view, event, api) => {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
const pos = view.posAtDOM(rootElement, 0, 0);
|
|
27
|
-
|
|
27
|
+
let rootPos;
|
|
28
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
29
|
+
const $rootPos = view.state.doc.resolve(pos);
|
|
30
|
+
const depth = $rootPos.depth;
|
|
31
|
+
rootPos = depth ? $rootPos.before() : $rootPos.pos;
|
|
32
|
+
} else {
|
|
33
|
+
rootPos = view.state.doc.resolve(pos).start(1) - 1;
|
|
34
|
+
}
|
|
28
35
|
const nodeType = rootElement.getAttribute('data-drag-handler-node-type');
|
|
29
36
|
if (nodeType) {
|
|
30
37
|
var _api$core, _api$blockControls2;
|