@atlaskit/editor-plugin-block-controls 1.11.1 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/cjs/commands/move-node.js +22 -6
- package/dist/cjs/pm-plugins/decorations.js +10 -8
- package/dist/cjs/pm-plugins/main.js +25 -24
- package/dist/cjs/ui/consts.js +6 -2
- package/dist/cjs/ui/drag-handle.js +11 -3
- package/dist/cjs/ui/drop-target.js +22 -23
- package/dist/cjs/utils/drag-handle-positions.js +3 -3
- package/dist/cjs/utils/validation.js +74 -3
- package/dist/es2019/commands/move-node.js +25 -7
- package/dist/es2019/pm-plugins/decorations.js +11 -9
- package/dist/es2019/pm-plugins/main.js +16 -22
- package/dist/es2019/ui/consts.js +5 -1
- package/dist/es2019/ui/drag-handle.js +11 -3
- package/dist/es2019/ui/drop-target.js +22 -23
- package/dist/es2019/utils/drag-handle-positions.js +3 -3
- package/dist/es2019/utils/validation.js +73 -2
- package/dist/esm/commands/move-node.js +24 -7
- package/dist/esm/pm-plugins/decorations.js +11 -9
- package/dist/esm/pm-plugins/main.js +25 -24
- package/dist/esm/ui/consts.js +5 -1
- package/dist/esm/ui/drag-handle.js +11 -3
- package/dist/esm/ui/drop-target.js +22 -23
- package/dist/esm/utils/drag-handle-positions.js +3 -3
- package/dist/esm/utils/validation.js +71 -2
- package/dist/types/pm-plugins/decorations.d.ts +2 -2
- package/dist/types/types.d.ts +9 -15
- package/dist/types/ui/consts.d.ts +2 -1
- package/dist/types/utils/drag-handle-positions.d.ts +1 -1
- package/dist/types/utils/validation.d.ts +16 -1
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +9 -15
- package/dist/types-ts4.5/ui/consts.d.ts +2 -1
- package/dist/types-ts4.5/utils/drag-handle-positions.d.ts +1 -1
- package/dist/types-ts4.5/utils/validation.d.ts +16 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#130247](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130247)
|
|
8
|
+
[`c331860f119e6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c331860f119e6) -
|
|
9
|
+
ED-24455 add suport for drag expand drop into table
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#130406](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130406)
|
|
14
|
+
[`487b48abdae42`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/487b48abdae42) -
|
|
15
|
+
ED-24554 Don't show handle for indented tasks
|
|
16
|
+
- [#130260](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130260)
|
|
17
|
+
[`d338ce6e4ff6e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d338ce6e4ff6e) -
|
|
18
|
+
Reduce drag handle gap for nested elements
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
21
|
+
## 1.11.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#129108](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129108)
|
|
26
|
+
[`c3bcb8b4001bd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3bcb8b4001bd) -
|
|
27
|
+
ED-24540 Clean up droptarget decorations after dropping in nested nodes to fix node splitting
|
|
28
|
+
issue
|
|
29
|
+
- [#129411](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129411)
|
|
30
|
+
[`2cfee5779f921`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2cfee5779f921) -
|
|
31
|
+
ED-24456 improve drop target vertical position for nested nodes
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
|
|
3
34
|
## 1.11.1
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -18,11 +18,24 @@ var _utils2 = require("../utils");
|
|
|
18
18
|
var _validation = require("../utils/validation");
|
|
19
19
|
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; }
|
|
20
20
|
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; }
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* This function transforms the slice to move
|
|
23
|
+
* @param nodeCopy The slice contains the node to be moved
|
|
24
|
+
* @param destType The type of the destiation node
|
|
25
|
+
* @returns transformed slice or null if unable to
|
|
26
|
+
*/
|
|
27
|
+
function transformSourceSlice(nodeCopy, destType) {
|
|
22
28
|
var srcNode = nodeCopy.content.firstChild;
|
|
23
29
|
var schema = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.schema;
|
|
24
|
-
if (srcNode && schema
|
|
25
|
-
|
|
30
|
+
if (srcNode && schema) {
|
|
31
|
+
var _schema$nodes = schema.nodes,
|
|
32
|
+
doc = _schema$nodes.doc,
|
|
33
|
+
layoutColumn = _schema$nodes.layoutColumn;
|
|
34
|
+
if (srcNode.type === schema.nodes.nestedExpand && [doc, layoutColumn].includes(destType)) {
|
|
35
|
+
return (0, _transforms.transformSliceNestedExpandToExpand)(nodeCopy, schema);
|
|
36
|
+
} else if (srcNode.type === schema.nodes.expand && (0, _validation.isInsideTable)(destType)) {
|
|
37
|
+
return (0, _validation.transformSliceExpandToNestedExpand)(nodeCopy);
|
|
38
|
+
}
|
|
26
39
|
}
|
|
27
40
|
return nodeCopy;
|
|
28
41
|
}
|
|
@@ -120,16 +133,19 @@ var moveNode = exports.moveNode = function moveNode(api) {
|
|
|
120
133
|
var end = start + size;
|
|
121
134
|
var mappedTo;
|
|
122
135
|
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
136
|
+
var _transformSourceSlice;
|
|
123
137
|
var nodeCopy = tr.doc.slice(start, end, false); // cut the content
|
|
124
138
|
var $to = tr.doc.resolve(to);
|
|
125
139
|
var $from = tr.doc.resolve(start);
|
|
126
140
|
var destType = $to.node().type;
|
|
127
|
-
var srcType = $from.node().child($from.index()).type;
|
|
128
141
|
var destParent = $to.node($to.depth);
|
|
129
|
-
if (!(0, _validation.
|
|
142
|
+
if (!(0, _validation.canMoveNodeToIndex)(destParent, $to.index(), $from.node().child($from.index()))) {
|
|
143
|
+
return tr;
|
|
144
|
+
}
|
|
145
|
+
var convertedNode = (_transformSourceSlice = transformSourceSlice(nodeCopy, destType)) === null || _transformSourceSlice === void 0 ? void 0 : _transformSourceSlice.content;
|
|
146
|
+
if (!convertedNode) {
|
|
130
147
|
return tr;
|
|
131
148
|
}
|
|
132
|
-
var convertedNode = transformNested(nodeCopy, destType).content;
|
|
133
149
|
tr.delete(start, end); // delete the content from the original position
|
|
134
150
|
mappedTo = tr.mapping.map(to);
|
|
135
151
|
tr.insert(mappedTo, convertedNode); // insert the content at the new position
|
|
@@ -16,8 +16,8 @@ var _dragHandle = require("../ui/drag-handle");
|
|
|
16
16
|
var _dropTarget = require("../ui/drop-target");
|
|
17
17
|
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
18
18
|
var _validation = require("../utils/validation");
|
|
19
|
-
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem'];
|
|
20
|
-
var
|
|
19
|
+
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
|
|
20
|
+
var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList'];
|
|
21
21
|
var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand'];
|
|
22
22
|
var getNestedDepth = function getNestedDepth() {
|
|
23
23
|
return (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
@@ -34,16 +34,17 @@ var createDropTargetDecoration = function createDropTargetDecoration(pos, dropTa
|
|
|
34
34
|
side: -1
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(
|
|
37
|
+
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode) {
|
|
38
38
|
var decs = [];
|
|
39
39
|
unmountDecorations('data-blocks-drop-target-container');
|
|
40
40
|
// Decoration state is used to keep track of the position of the drop targets
|
|
41
41
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
42
42
|
var decorationState = [];
|
|
43
43
|
var prevNode;
|
|
44
|
+
var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
45
|
+
var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
44
46
|
newState.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos, parent, index) {
|
|
45
47
|
var depth = 0;
|
|
46
|
-
var nodeType = newState.doc.type.schema.nodes[activeNodeType];
|
|
47
48
|
var endDec = null;
|
|
48
49
|
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
49
50
|
depth = newState.doc.resolve(pos).depth;
|
|
@@ -55,7 +56,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
55
56
|
prevNode = node;
|
|
56
57
|
return true; //skip over, don't consider it a valid depth
|
|
57
58
|
}
|
|
58
|
-
var canDrop =
|
|
59
|
+
var canDrop = activePMNode && (0, _validation.canMoveNodeToIndex)(parent, index, activePMNode);
|
|
59
60
|
|
|
60
61
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
61
62
|
if (!canDrop && !(0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
@@ -154,13 +155,14 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
154
155
|
var _Decoration$node2;
|
|
155
156
|
var depth = 0;
|
|
156
157
|
var anchorName;
|
|
158
|
+
var shouldDescend = !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
157
159
|
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
158
160
|
// Doesn't descend into a node
|
|
159
|
-
if (node.isInline
|
|
161
|
+
if (node.isInline) {
|
|
160
162
|
return false;
|
|
161
163
|
}
|
|
162
164
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
163
|
-
return
|
|
165
|
+
return shouldDescend; //skip over, don't consider it a valid depth
|
|
164
166
|
}
|
|
165
167
|
depth = newState.doc.resolve(pos).depth;
|
|
166
168
|
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(pos);
|
|
@@ -172,7 +174,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
172
174
|
}, (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), {
|
|
173
175
|
type: 'node-decoration'
|
|
174
176
|
}));
|
|
175
|
-
return depth < getNestedDepth();
|
|
177
|
+
return shouldDescend && depth < getNestedDepth();
|
|
176
178
|
});
|
|
177
179
|
return decs;
|
|
178
180
|
};
|
|
@@ -92,7 +92,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
92
92
|
return initialState;
|
|
93
93
|
},
|
|
94
94
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
95
|
-
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$
|
|
95
|
+
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
96
96
|
var activeNode = currentState.activeNode,
|
|
97
97
|
decorations = currentState.decorations,
|
|
98
98
|
isMenuOpen = currentState.isMenuOpen,
|
|
@@ -138,8 +138,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
138
138
|
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
139
139
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
140
140
|
}
|
|
141
|
-
var dropTargetLen = decorations.find(
|
|
142
|
-
var spec = _ref8.spec;
|
|
141
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
143
142
|
return spec.type === 'drop-target-decoration';
|
|
144
143
|
}).length;
|
|
145
144
|
|
|
@@ -164,8 +163,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
164
163
|
|
|
165
164
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
166
165
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
167
|
-
var oldNodeDecs = decorations.find(
|
|
168
|
-
var spec = _ref9.spec;
|
|
166
|
+
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
169
167
|
return spec.type !== 'drop-target-decoration';
|
|
170
168
|
});
|
|
171
169
|
decorations = decorations.remove(oldNodeDecs);
|
|
@@ -202,8 +200,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
202
200
|
|
|
203
201
|
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
204
202
|
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
|
|
205
|
-
var _oldHandle = decorations.find(
|
|
206
|
-
var spec = _ref10.spec;
|
|
203
|
+
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
207
204
|
return spec.id === 'drag-handle';
|
|
208
205
|
});
|
|
209
206
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -213,8 +210,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
213
210
|
|
|
214
211
|
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
215
212
|
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
216
|
-
var _oldHandle2 = decorations.find(
|
|
217
|
-
var spec = _ref11.spec;
|
|
213
|
+
var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
|
|
218
214
|
return spec.id === 'drag-handle';
|
|
219
215
|
});
|
|
220
216
|
decorations = decorations.remove(_oldHandle2);
|
|
@@ -222,21 +218,26 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
222
218
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
223
219
|
}
|
|
224
220
|
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
225
|
-
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging)
|
|
221
|
+
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
226
222
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
224
|
+
var remainingDecs = decorations.find(undefined, undefined, function (spec) {
|
|
225
|
+
return spec.type !== 'drop-target-decoration';
|
|
226
|
+
});
|
|
227
|
+
decorations = _view.DecorationSet.create(newState.doc, remainingDecs);
|
|
228
|
+
} else {
|
|
229
|
+
// Remove drop target decoration when dragging stops
|
|
230
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
231
|
+
return spec.type === 'drop-target-decoration';
|
|
232
|
+
});
|
|
233
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
234
|
+
}
|
|
233
235
|
}
|
|
234
236
|
if (api) {
|
|
235
237
|
// Add drop targets when node is being dragged
|
|
236
238
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
237
239
|
if (shouldUpdateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
238
|
-
var
|
|
239
|
-
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api, formatMessage, meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType),
|
|
240
|
+
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, meta === null || meta === void 0 ? void 0 : meta.activeNode),
|
|
240
241
|
_decs2 = _dropTargetDecoration.decs,
|
|
241
242
|
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
242
243
|
decorationState = updatedDecorationState;
|
|
@@ -246,9 +247,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
246
247
|
|
|
247
248
|
//Map drop target decoration positions when the document changes
|
|
248
249
|
if (shouldMapDropTargets) {
|
|
249
|
-
decorationState = decorationState.map(function (
|
|
250
|
-
var id =
|
|
251
|
-
pos =
|
|
250
|
+
decorationState = decorationState.map(function (_ref8) {
|
|
251
|
+
var id = _ref8.id,
|
|
252
|
+
pos = _ref8.pos;
|
|
252
253
|
return {
|
|
253
254
|
id: id,
|
|
254
255
|
pos: tr.mapping.map(pos)
|
|
@@ -261,8 +262,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
261
262
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
262
263
|
}
|
|
263
264
|
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
264
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
265
|
-
var spec =
|
|
265
|
+
var hasNodeDecoration = decorations.find().some(function (_ref9) {
|
|
266
|
+
var spec = _ref9.spec;
|
|
266
267
|
return spec.type === 'node-decoration';
|
|
267
268
|
});
|
|
268
269
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -278,7 +279,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
278
279
|
return {
|
|
279
280
|
decorations: decorations,
|
|
280
281
|
decorationState: decorationState,
|
|
281
|
-
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$
|
|
282
|
+
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$activeNode2 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode2 !== void 0 ? _meta$activeNode2 : mappedActiveNodePos,
|
|
282
283
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
|
|
283
284
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
284
285
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
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_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;
|
|
7
|
+
exports.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_NARROW_GAP = 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;
|
|
@@ -13,12 +13,16 @@ 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_NARROW_GAP = exports.DRAG_HANDLE_NARROW_GAP = 4;
|
|
16
17
|
var DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_MAX_GAP = 12;
|
|
17
18
|
var DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = DRAG_HANDLE_WIDTH + DRAG_HANDLE_MAX_GAP;
|
|
18
19
|
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
|
|
19
20
|
|
|
20
21
|
var nodeTypeExcludeList = ['embedCard', 'mediaSingle', 'table'];
|
|
21
|
-
var dragHandleGap = exports.dragHandleGap = function dragHandleGap(nodeType) {
|
|
22
|
+
var dragHandleGap = exports.dragHandleGap = function dragHandleGap(nodeType, parentNodeType) {
|
|
23
|
+
if (parentNodeType && parentNodeType !== 'doc') {
|
|
24
|
+
return DRAG_HANDLE_NARROW_GAP;
|
|
25
|
+
}
|
|
22
26
|
if (nodeTypeExcludeList.includes(nodeType)) {
|
|
23
27
|
return DRAG_HANDLE_MAX_GAP;
|
|
24
28
|
}
|
|
@@ -253,6 +253,14 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
253
253
|
}, [anchorName, api, nodeType, view, start]);
|
|
254
254
|
var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
|
|
255
255
|
var calculatePosition = (0, _react.useCallback)(function () {
|
|
256
|
+
var parentNodeType;
|
|
257
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
258
|
+
var pos = getPos();
|
|
259
|
+
var $pos = pos && view.state.doc.resolve(pos);
|
|
260
|
+
var parentPos = $pos && $pos.depth ? $pos.before() : undefined;
|
|
261
|
+
var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
|
|
262
|
+
parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
|
|
263
|
+
}
|
|
256
264
|
var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
|
|
257
265
|
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
258
266
|
var hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
|
|
@@ -274,15 +282,15 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
274
282
|
}
|
|
275
283
|
if (supportsAnchor) {
|
|
276
284
|
return {
|
|
277
|
-
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
|
|
285
|
+
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates, parentNodeType), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType, parentNodeType), "px)"),
|
|
278
286
|
top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _consts.topPositionAdjustment)(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(_consts.DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
|
|
279
287
|
};
|
|
280
288
|
}
|
|
281
289
|
return {
|
|
282
|
-
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates),
|
|
290
|
+
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates, parentNodeType), ")") : (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates, parentNodeType),
|
|
283
291
|
top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? (0, _dragHandlePositions.getTopPosition)(dom, nodeType) : (0, _dragHandlePositions.getTopPosition)(dom)
|
|
284
292
|
};
|
|
285
|
-
}, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
|
|
293
|
+
}, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates, getPos]);
|
|
286
294
|
var _useState5 = (0, _react.useState)({
|
|
287
295
|
display: 'none'
|
|
288
296
|
}),
|
|
@@ -23,6 +23,7 @@ var _consts = require("./consts");
|
|
|
23
23
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
24
24
|
|
|
25
25
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
26
|
+
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
26
27
|
var styleDropTarget = (0, _react2.css)({
|
|
27
28
|
height: "var(--ds-space-100, 8px)",
|
|
28
29
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
@@ -32,6 +33,12 @@ var styleDropTarget = (0, _react2.css)({
|
|
|
32
33
|
display: 'block',
|
|
33
34
|
zIndex: _constants.layers.card()
|
|
34
35
|
});
|
|
36
|
+
var styleDropIndicator = (0, _react2.css)({
|
|
37
|
+
height: '100%',
|
|
38
|
+
margin: '0 auto',
|
|
39
|
+
position: 'relative',
|
|
40
|
+
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
41
|
+
});
|
|
35
42
|
var nestedDropIndicatorStyle = (0, _react2.css)({
|
|
36
43
|
position: 'relative'
|
|
37
44
|
});
|
|
@@ -42,10 +49,9 @@ var marginLookupMap = Object.fromEntries(Object.entries(_consts.spaceLookupMap).
|
|
|
42
49
|
return [key,
|
|
43
50
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
44
51
|
(0, _react2.css)({
|
|
45
|
-
|
|
52
|
+
transform: "translateY(".concat(value, ")")
|
|
46
53
|
})];
|
|
47
54
|
}));
|
|
48
|
-
var BASE_LINE_MARGIN = -8;
|
|
49
55
|
var getNodeMargins = function getNodeMargins(node) {
|
|
50
56
|
if (!node) {
|
|
51
57
|
return _consts.nodeMargins['default'];
|
|
@@ -56,26 +62,19 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
56
62
|
}
|
|
57
63
|
return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
|
|
58
64
|
};
|
|
59
|
-
var
|
|
65
|
+
var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextNode) {
|
|
60
66
|
if (!prevNode || !nextNode) {
|
|
61
67
|
return null;
|
|
62
68
|
}
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
} else {
|
|
69
|
-
return marginLookupMap[space];
|
|
69
|
+
var top = getNodeMargins(nextNode).top;
|
|
70
|
+
var bottom = getNodeMargins(prevNode).bottom;
|
|
71
|
+
var marginDiff = Math.round((top - bottom) / 2);
|
|
72
|
+
if (marginDiff === 0) {
|
|
73
|
+
return null;
|
|
70
74
|
}
|
|
75
|
+
var offset = Math.max(Math.min(marginDiff, 24), -24);
|
|
76
|
+
return marginLookupMap[offset];
|
|
71
77
|
};
|
|
72
|
-
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
73
|
-
var styleDropIndicator = (0, _react2.css)({
|
|
74
|
-
height: '100%',
|
|
75
|
-
margin: '0 auto',
|
|
76
|
-
position: 'relative',
|
|
77
|
-
width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
|
|
78
|
-
});
|
|
79
78
|
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
80
79
|
var api = _ref3.api,
|
|
81
80
|
id = _ref3.id,
|
|
@@ -127,22 +126,22 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
127
126
|
}
|
|
128
127
|
});
|
|
129
128
|
}, [id, api, formatMessage]);
|
|
130
|
-
var
|
|
129
|
+
var dropTargetOffsetStyle = (0, _react.useMemo)(function () {
|
|
131
130
|
/**
|
|
132
131
|
* First child of a nested node.
|
|
133
|
-
* Disable the position adjustment
|
|
132
|
+
* Disable the position adjustment temporarily
|
|
134
133
|
*/
|
|
135
|
-
if (parentNode === prevNode
|
|
134
|
+
if (parentNode === prevNode) {
|
|
136
135
|
return null;
|
|
137
136
|
}
|
|
138
|
-
return
|
|
139
|
-
}, [prevNode, nextNode, parentNode
|
|
137
|
+
return getDropTargetOffsetStyle(prevNode, nextNode);
|
|
138
|
+
}, [prevNode, nextNode, parentNode]);
|
|
140
139
|
var widthStyle = (0, _defineProperty2.default)({}, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px"));
|
|
141
140
|
return (
|
|
142
141
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
143
142
|
(0, _react2.jsx)("div", {
|
|
144
143
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
145
|
-
css: [styleDropTarget,
|
|
144
|
+
css: [styleDropTarget, dropTargetOffsetStyle, isNestedDropTarget && nestedDropIndicatorStyle]
|
|
146
145
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
147
146
|
,
|
|
148
147
|
style: widthStyle,
|
|
@@ -18,17 +18,17 @@ var getTopPosition = exports.getTopPosition = function getTopPosition(dom, type)
|
|
|
18
18
|
return "".concat(dom.offsetTop, "px");
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
var getLeftPosition = exports.getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates) {
|
|
21
|
+
var getLeftPosition = exports.getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates, parentType) {
|
|
22
22
|
if (!dom) {
|
|
23
23
|
return 'auto';
|
|
24
24
|
}
|
|
25
25
|
if (!innerContainer) {
|
|
26
|
-
return "".concat(dom.offsetLeft - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
26
|
+
return "".concat(dom.offsetLeft - (0, _consts.dragHandleGap)(type, parentType) - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// There is a showMacroInteractionDesignUpdates prop in extension node wrapper that can add a relative span under the top level div
|
|
30
30
|
// We need to adjust the left offset position of the drag handle to account for the relative span
|
|
31
31
|
var relativeSpan = macroInteractionUpdates ? dom.querySelector('span.relative') : null;
|
|
32
32
|
var leftAdjustment = relativeSpan ? relativeSpan.offsetLeft : 0;
|
|
33
|
-
return getComputedStyle(innerContainer).transform === 'none' ? "".concat(innerContainer.offsetLeft + leftAdjustment - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px") : "".concat(innerContainer.offsetLeft + leftAdjustment - innerContainer.offsetWidth / 2 - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
33
|
+
return getComputedStyle(innerContainer).transform === 'none' ? "".concat(innerContainer.offsetLeft + leftAdjustment - (0, _consts.dragHandleGap)(type, parentType) - _consts.DRAG_HANDLE_WIDTH, "px") : "".concat(innerContainer.offsetLeft + leftAdjustment - innerContainer.offsetWidth / 2 - (0, _consts.dragHandleGap)(type, parentType) - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
34
34
|
};
|
|
@@ -1,9 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
exports.canMoveNodeToIndex = canMoveNodeToIndex;
|
|
8
|
+
exports.transformSliceExpandToNestedExpand = exports.transformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = exports.isNestedExpand = exports.isInsideTable = exports.isExpand = exports.isDoc = void 0;
|
|
9
|
+
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
10
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
var isInsideTable = exports.isInsideTable = function isInsideTable(nodeType) {
|
|
12
|
+
var _nodeType$schema$node = nodeType.schema.nodes,
|
|
13
|
+
tableCell = _nodeType$schema$node.tableCell,
|
|
14
|
+
tableHeader = _nodeType$schema$node.tableHeader;
|
|
15
|
+
return [tableCell, tableHeader].indexOf(nodeType) >= 0;
|
|
16
|
+
};
|
|
17
|
+
var isDoc = exports.isDoc = function isDoc(nodeType) {
|
|
18
|
+
return nodeType === nodeType.schema.nodes.doc;
|
|
19
|
+
};
|
|
20
|
+
var isExpand = exports.isExpand = function isExpand(nodeType) {
|
|
21
|
+
return nodeType === nodeType.schema.nodes.expand;
|
|
22
|
+
};
|
|
23
|
+
var isNestedExpand = exports.isNestedExpand = function isNestedExpand(nodeType) {
|
|
24
|
+
return nodeType === nodeType.schema.nodes.nestedExpand;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This function converts an expand into a nested expand,
|
|
29
|
+
* although it may fail based on the expand's content.
|
|
30
|
+
* @param expandNode the node to transform.
|
|
31
|
+
* @returns an nested expand node
|
|
32
|
+
* @throws RangeError: Invalid content for node nestedExpand
|
|
33
|
+
*/
|
|
34
|
+
var transformExpandToNestedExpand = exports.transformExpandToNestedExpand = function transformExpandToNestedExpand(expandNode) {
|
|
35
|
+
var _expandNode$type$sche = expandNode.type.schema.nodes,
|
|
36
|
+
expand = _expandNode$type$sche.expand,
|
|
37
|
+
nestedExpand = _expandNode$type$sche.nestedExpand;
|
|
38
|
+
if (expandNode.type === expand) {
|
|
39
|
+
return nestedExpand.createChecked(expandNode.attrs, expandNode.content, expandNode.marks);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
var transformSliceExpandToNestedExpand = exports.transformSliceExpandToNestedExpand = function transformSliceExpandToNestedExpand(slice) {
|
|
44
|
+
var children = [];
|
|
45
|
+
try {
|
|
46
|
+
slice.content.forEach(function (node) {
|
|
47
|
+
if (isExpand(node.type)) {
|
|
48
|
+
var nestedExpandNode = transformExpandToNestedExpand(node);
|
|
49
|
+
if (nestedExpandNode) {
|
|
50
|
+
children.push(nestedExpandNode);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
children.push(node);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return new _model.Slice(_model.Fragment.fromArray(children), slice.openStart, slice.openEnd);
|
|
60
|
+
};
|
|
61
|
+
var memoizedTransformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = (0, _memoizeOne.default)(function (node) {
|
|
62
|
+
try {
|
|
63
|
+
return transformExpandToNestedExpand(node);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
|
|
69
|
+
var srcNodeType = srcNode.type;
|
|
70
|
+
if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
|
|
71
|
+
if (memoizedTransformExpandToNestedExpand(srcNode)) {
|
|
72
|
+
srcNodeType = srcNodeType.schema.nodes.nestedExpand;
|
|
73
|
+
} else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
} else if (isDoc(destParent.type) && isNestedExpand(srcNodeType)) {
|
|
77
|
+
srcNodeType = srcNodeType.schema.nodes.expand;
|
|
78
|
+
}
|
|
79
|
+
return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
|
|
9
80
|
}
|
|
@@ -7,12 +7,27 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
7
7
|
import { DIRECTION } from '../consts';
|
|
8
8
|
import { key } from '../pm-plugins/main';
|
|
9
9
|
import { selectNode } from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { canMoveNodeToIndex, isInsideTable, transformSliceExpandToNestedExpand } from '../utils/validation';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This function transforms the slice to move
|
|
14
|
+
* @param nodeCopy The slice contains the node to be moved
|
|
15
|
+
* @param destType The type of the destiation node
|
|
16
|
+
* @returns transformed slice or null if unable to
|
|
17
|
+
*/
|
|
18
|
+
function transformSourceSlice(nodeCopy, destType) {
|
|
12
19
|
const srcNode = nodeCopy.content.firstChild;
|
|
13
20
|
const schema = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.schema;
|
|
14
|
-
if (srcNode && schema
|
|
15
|
-
|
|
21
|
+
if (srcNode && schema) {
|
|
22
|
+
const {
|
|
23
|
+
doc,
|
|
24
|
+
layoutColumn
|
|
25
|
+
} = schema.nodes;
|
|
26
|
+
if (srcNode.type === schema.nodes.nestedExpand && [doc, layoutColumn].includes(destType)) {
|
|
27
|
+
return transformSliceNestedExpandToExpand(nodeCopy, schema);
|
|
28
|
+
} else if (srcNode.type === schema.nodes.expand && isInsideTable(destType)) {
|
|
29
|
+
return transformSliceExpandToNestedExpand(nodeCopy);
|
|
30
|
+
}
|
|
16
31
|
}
|
|
17
32
|
return nodeCopy;
|
|
18
33
|
}
|
|
@@ -112,16 +127,19 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
|
|
|
112
127
|
const end = start + size;
|
|
113
128
|
let mappedTo;
|
|
114
129
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
130
|
+
var _transformSourceSlice;
|
|
115
131
|
const nodeCopy = tr.doc.slice(start, end, false); // cut the content
|
|
116
132
|
const $to = tr.doc.resolve(to);
|
|
117
133
|
const $from = tr.doc.resolve(start);
|
|
118
134
|
const destType = $to.node().type;
|
|
119
|
-
const srcType = $from.node().child($from.index()).type;
|
|
120
135
|
const destParent = $to.node($to.depth);
|
|
121
|
-
if (!
|
|
136
|
+
if (!canMoveNodeToIndex(destParent, $to.index(), $from.node().child($from.index()))) {
|
|
137
|
+
return tr;
|
|
138
|
+
}
|
|
139
|
+
const convertedNode = (_transformSourceSlice = transformSourceSlice(nodeCopy, destType)) === null || _transformSourceSlice === void 0 ? void 0 : _transformSourceSlice.content;
|
|
140
|
+
if (!convertedNode) {
|
|
122
141
|
return tr;
|
|
123
142
|
}
|
|
124
|
-
const convertedNode = transformNested(nodeCopy, destType).content;
|
|
125
143
|
tr.delete(start, end); // delete the content from the original position
|
|
126
144
|
mappedTo = tr.mapping.map(to);
|
|
127
145
|
tr.insert(mappedTo, convertedNode); // insert the content at the new position
|