@atlaskit/editor-plugin-block-controls 1.11.2 → 1.12.1
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-node.js +22 -6
- package/dist/cjs/pm-plugins/decorations.js +10 -8
- package/dist/cjs/pm-plugins/main.js +39 -25
- package/dist/cjs/ui/consts.js +6 -2
- package/dist/cjs/ui/drag-handle.js +11 -3
- package/dist/cjs/ui/drop-target.js +3 -3
- package/dist/cjs/utils/drag-handle-positions.js +3 -3
- package/dist/cjs/utils/validation.js +77 -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 +34 -21
- package/dist/es2019/ui/consts.js +5 -1
- package/dist/es2019/ui/drag-handle.js +11 -3
- package/dist/es2019/ui/drop-target.js +3 -3
- package/dist/es2019/utils/drag-handle-positions.js +3 -3
- package/dist/es2019/utils/validation.js +76 -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 +39 -25
- package/dist/esm/ui/consts.js +5 -1
- package/dist/esm/ui/drag-handle.js +11 -3
- package/dist/esm/ui/drop-target.js +3 -3
- package/dist/esm/utils/drag-handle-positions.js +3 -3
- package/dist/esm/utils/validation.js +74 -2
- package/dist/types/pm-plugins/decorations.d.ts +2 -2
- package/dist/types/types.d.ts +10 -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 +17 -1
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +10 -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 +17 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#130485](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130485)
|
|
8
|
+
[`5b6725b15e18e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5b6725b15e18e) -
|
|
9
|
+
Update node decorations when document changes for nested dnd scenarios
|
|
10
|
+
- [#130711](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130711)
|
|
11
|
+
[`f878c5be1ed97`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f878c5be1ed97) -
|
|
12
|
+
ED-24455 additional fix and tests
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 1.12.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#130247](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130247)
|
|
20
|
+
[`c331860f119e6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c331860f119e6) -
|
|
21
|
+
ED-24455 add suport for drag expand drop into table
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#130406](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130406)
|
|
26
|
+
[`487b48abdae42`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/487b48abdae42) -
|
|
27
|
+
ED-24554 Don't show handle for indented tasks
|
|
28
|
+
- [#130260](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130260)
|
|
29
|
+
[`d338ce6e4ff6e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d338ce6e4ff6e) -
|
|
30
|
+
Reduce drag handle gap for nested elements
|
|
31
|
+
- Updated dependencies
|
|
32
|
+
|
|
3
33
|
## 1.11.2
|
|
4
34
|
|
|
5
35
|
### 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
|
};
|
|
@@ -71,6 +71,13 @@ var destroyFn = function destroyFn(api) {
|
|
|
71
71
|
}));
|
|
72
72
|
return _combine.combine.apply(void 0, cleanupFn);
|
|
73
73
|
};
|
|
74
|
+
function getDocChildrenCount(newState) {
|
|
75
|
+
var size = 0;
|
|
76
|
+
newState.doc.descendants(function (node) {
|
|
77
|
+
size += node.childCount;
|
|
78
|
+
});
|
|
79
|
+
return size;
|
|
80
|
+
}
|
|
74
81
|
var initialState = {
|
|
75
82
|
decorations: _view.DecorationSet.empty,
|
|
76
83
|
decorationState: [],
|
|
@@ -82,7 +89,8 @@ var initialState = {
|
|
|
82
89
|
editorWidthRight: 0,
|
|
83
90
|
isResizerResizing: false,
|
|
84
91
|
isDocSizeLimitEnabled: null,
|
|
85
|
-
isPMDragging: false
|
|
92
|
+
isPMDragging: false,
|
|
93
|
+
childCount: 0
|
|
86
94
|
};
|
|
87
95
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
88
96
|
return new _safePlugin.SafePlugin({
|
|
@@ -92,7 +100,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
92
100
|
return initialState;
|
|
93
101
|
},
|
|
94
102
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
95
|
-
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$
|
|
103
|
+
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
96
104
|
var activeNode = currentState.activeNode,
|
|
97
105
|
decorations = currentState.decorations,
|
|
98
106
|
isMenuOpen = currentState.isMenuOpen,
|
|
@@ -102,14 +110,15 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
102
110
|
editorWidthRight = currentState.editorWidthRight,
|
|
103
111
|
isResizerResizing = currentState.isResizerResizing,
|
|
104
112
|
isDragging = currentState.isDragging,
|
|
105
|
-
isPMDragging = currentState.isPMDragging
|
|
113
|
+
isPMDragging = currentState.isPMDragging,
|
|
114
|
+
childCount = currentState.childCount;
|
|
106
115
|
var activeNodeWithNewNodeType = null;
|
|
107
116
|
var meta = tr.getMeta(key);
|
|
108
|
-
|
|
117
|
+
var newChildCount = tr.docChanged && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? getDocChildrenCount(newState) : childCount;
|
|
109
118
|
// If tables or media are being resized, we want to hide the drag handle
|
|
110
119
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
111
120
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
112
|
-
var nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
121
|
+
var nodeCountChanged = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? childCount !== newChildCount : oldState.doc.childCount !== newState.doc.childCount;
|
|
113
122
|
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
114
123
|
|
|
115
124
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
@@ -129,20 +138,26 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
129
138
|
var spec = _ref6.spec;
|
|
130
139
|
return spec.id === 'drag-handle';
|
|
131
140
|
});
|
|
132
|
-
var decsLength = decorations.find().filter(function (_ref7) {
|
|
141
|
+
var decsLength = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? decorations.find().filter(function (_ref7) {
|
|
133
142
|
var spec = _ref7.spec;
|
|
143
|
+
return spec.type === 'node-decoration';
|
|
144
|
+
}).length : decorations.find().filter(function (_ref8) {
|
|
145
|
+
var spec = _ref8.spec;
|
|
134
146
|
return spec.id !== 'drag-handle';
|
|
135
147
|
}).length;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
var newNodeDecs;
|
|
149
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
150
|
+
// naive solution while we work on performance optimised approach under ED-24503
|
|
151
|
+
newNodeDecs = (0, _decorations.nodeDecorations)(newState);
|
|
152
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newNodeDecs.length;
|
|
153
|
+
} else {
|
|
139
154
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
140
155
|
}
|
|
141
156
|
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
142
157
|
return spec.type === 'drop-target-decoration';
|
|
143
158
|
}).length;
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
var _getIntl = getIntl(),
|
|
160
|
+
formatMessage = _getIntl.formatMessage;
|
|
146
161
|
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
147
162
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
148
163
|
}
|
|
@@ -158,17 +173,16 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
158
173
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
159
174
|
var maybeNodeWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 || (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
160
175
|
var redrawDecorations = decorations === _view.DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
161
|
-
var _getIntl = getIntl(),
|
|
162
|
-
formatMessage = _getIntl.formatMessage;
|
|
163
176
|
|
|
164
177
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
165
178
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
179
|
+
var _newNodeDecs;
|
|
166
180
|
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
167
181
|
return spec.type !== 'drop-target-decoration';
|
|
168
182
|
});
|
|
169
183
|
decorations = decorations.remove(oldNodeDecs);
|
|
170
|
-
|
|
171
|
-
decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(
|
|
184
|
+
newNodeDecs = (_newNodeDecs = newNodeDecs) !== null && _newNodeDecs !== void 0 ? _newNodeDecs : (0, _decorations.nodeDecorations)(newState);
|
|
185
|
+
decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(newNodeDecs));
|
|
172
186
|
|
|
173
187
|
// Note: Quite often the handle is not in the right position after a node is moved
|
|
174
188
|
// it is safer for now to not show it when a node is moved
|
|
@@ -237,8 +251,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
237
251
|
// Add drop targets when node is being dragged
|
|
238
252
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
239
253
|
if (shouldUpdateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
240
|
-
var
|
|
241
|
-
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),
|
|
254
|
+
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, meta === null || meta === void 0 ? void 0 : meta.activeNode),
|
|
242
255
|
_decs2 = _dropTargetDecoration.decs,
|
|
243
256
|
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
244
257
|
decorationState = updatedDecorationState;
|
|
@@ -248,9 +261,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
248
261
|
|
|
249
262
|
//Map drop target decoration positions when the document changes
|
|
250
263
|
if (shouldMapDropTargets) {
|
|
251
|
-
decorationState = decorationState.map(function (
|
|
252
|
-
var id =
|
|
253
|
-
pos =
|
|
264
|
+
decorationState = decorationState.map(function (_ref9) {
|
|
265
|
+
var id = _ref9.id,
|
|
266
|
+
pos = _ref9.pos;
|
|
254
267
|
return {
|
|
255
268
|
id: id,
|
|
256
269
|
pos: tr.mapping.map(pos)
|
|
@@ -262,9 +275,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
262
275
|
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
263
276
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
264
277
|
}
|
|
265
|
-
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
266
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
267
|
-
var spec =
|
|
278
|
+
var isEmptyDoc = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? newState.doc.childCount === 1 && newState.doc.nodeSize <= 4 && (newState.doc.firstChild === null || newState.doc.firstChild.nodeSize <= 2) : newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
279
|
+
var hasNodeDecoration = decorations.find().some(function (_ref10) {
|
|
280
|
+
var spec = _ref10.spec;
|
|
268
281
|
return spec.type === 'node-decoration';
|
|
269
282
|
});
|
|
270
283
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -280,7 +293,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
280
293
|
return {
|
|
281
294
|
decorations: decorations,
|
|
282
295
|
decorationState: decorationState,
|
|
283
|
-
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$
|
|
296
|
+
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$activeNode2 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode2 !== void 0 ? _meta$activeNode2 : mappedActiveNodePos,
|
|
284
297
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
|
|
285
298
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
286
299
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
@@ -288,7 +301,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
288
301
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
289
302
|
isResizerResizing: isResizerResizing,
|
|
290
303
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
291
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
304
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
|
|
305
|
+
childCount: newChildCount
|
|
292
306
|
};
|
|
293
307
|
}
|
|
294
308
|
},
|
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
|
}),
|
|
@@ -68,11 +68,11 @@ var getDropTargetOffsetStyle = function getDropTargetOffsetStyle(prevNode, nextN
|
|
|
68
68
|
}
|
|
69
69
|
var top = getNodeMargins(nextNode).top;
|
|
70
70
|
var bottom = getNodeMargins(prevNode).bottom;
|
|
71
|
-
var
|
|
72
|
-
if (
|
|
71
|
+
var marginDiff = Math.round((top - bottom) / 2);
|
|
72
|
+
if (marginDiff === 0) {
|
|
73
73
|
return null;
|
|
74
74
|
}
|
|
75
|
-
var offset = Math.max(Math.min(
|
|
75
|
+
var offset = Math.max(Math.min(marginDiff, 24), -24);
|
|
76
76
|
return marginLookupMap[offset];
|
|
77
77
|
};
|
|
78
78
|
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
@@ -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,83 @@
|
|
|
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.isLayoutColumn = 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 isLayoutColumn = exports.isLayoutColumn = function isLayoutColumn(nodeType) {
|
|
18
|
+
return nodeType === nodeType.schema.nodes.layoutColumn;
|
|
19
|
+
};
|
|
20
|
+
var isDoc = exports.isDoc = function isDoc(nodeType) {
|
|
21
|
+
return nodeType === nodeType.schema.nodes.doc;
|
|
22
|
+
};
|
|
23
|
+
var isExpand = exports.isExpand = function isExpand(nodeType) {
|
|
24
|
+
return nodeType === nodeType.schema.nodes.expand;
|
|
25
|
+
};
|
|
26
|
+
var isNestedExpand = exports.isNestedExpand = function isNestedExpand(nodeType) {
|
|
27
|
+
return nodeType === nodeType.schema.nodes.nestedExpand;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This function converts an expand into a nested expand,
|
|
32
|
+
* although it may fail based on the expand's content.
|
|
33
|
+
* @param expandNode the node to transform.
|
|
34
|
+
* @returns an nested expand node
|
|
35
|
+
* @throws RangeError: Invalid content for node nestedExpand
|
|
36
|
+
*/
|
|
37
|
+
var transformExpandToNestedExpand = exports.transformExpandToNestedExpand = function transformExpandToNestedExpand(expandNode) {
|
|
38
|
+
var _expandNode$type$sche = expandNode.type.schema.nodes,
|
|
39
|
+
expand = _expandNode$type$sche.expand,
|
|
40
|
+
nestedExpand = _expandNode$type$sche.nestedExpand;
|
|
41
|
+
if (expandNode.type === expand) {
|
|
42
|
+
return nestedExpand.createChecked(expandNode.attrs, expandNode.content, expandNode.marks);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
var transformSliceExpandToNestedExpand = exports.transformSliceExpandToNestedExpand = function transformSliceExpandToNestedExpand(slice) {
|
|
47
|
+
var children = [];
|
|
48
|
+
try {
|
|
49
|
+
slice.content.forEach(function (node) {
|
|
50
|
+
if (isExpand(node.type)) {
|
|
51
|
+
var nestedExpandNode = transformExpandToNestedExpand(node);
|
|
52
|
+
if (nestedExpandNode) {
|
|
53
|
+
children.push(nestedExpandNode);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
children.push(node);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return new _model.Slice(_model.Fragment.fromArray(children), slice.openStart, slice.openEnd);
|
|
63
|
+
};
|
|
64
|
+
var memoizedTransformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = (0, _memoizeOne.default)(function (node) {
|
|
65
|
+
try {
|
|
66
|
+
return transformExpandToNestedExpand(node);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
|
|
72
|
+
var srcNodeType = srcNode.type;
|
|
73
|
+
if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
|
|
74
|
+
if (memoizedTransformExpandToNestedExpand(srcNode)) {
|
|
75
|
+
srcNodeType = srcNodeType.schema.nodes.nestedExpand;
|
|
76
|
+
} else {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
} else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
|
|
80
|
+
srcNodeType = srcNodeType.schema.nodes.expand;
|
|
81
|
+
}
|
|
82
|
+
return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
|
|
9
83
|
}
|
|
@@ -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
|
|
@@ -7,9 +7,9 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
7
7
|
import { DragHandle } from '../ui/drag-handle';
|
|
8
8
|
import { DropTarget } from '../ui/drop-target';
|
|
9
9
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
10
|
-
import {
|
|
11
|
-
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem'];
|
|
12
|
-
const
|
|
10
|
+
import { canMoveNodeToIndex } from '../utils/validation';
|
|
11
|
+
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
|
|
12
|
+
const IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList'];
|
|
13
13
|
const PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand'];
|
|
14
14
|
const getNestedDepth = () => fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
15
15
|
const createDropTargetDecoration = (pos, dropTargetDec) => {
|
|
@@ -24,16 +24,17 @@ const createDropTargetDecoration = (pos, dropTargetDec) => {
|
|
|
24
24
|
side: -1
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
-
export const dropTargetDecorations = (
|
|
27
|
+
export const dropTargetDecorations = (newState, api, formatMessage, activeNode) => {
|
|
28
28
|
const decs = [];
|
|
29
29
|
unmountDecorations('data-blocks-drop-target-container');
|
|
30
30
|
// Decoration state is used to keep track of the position of the drop targets
|
|
31
31
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
32
32
|
const decorationState = [];
|
|
33
33
|
let prevNode;
|
|
34
|
+
const activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
35
|
+
const activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
34
36
|
newState.doc.nodesBetween(0, newState.doc.nodeSize - 2, (node, pos, parent, index) => {
|
|
35
37
|
let depth = 0;
|
|
36
|
-
const nodeType = newState.doc.type.schema.nodes[activeNodeType];
|
|
37
38
|
let endDec = null;
|
|
38
39
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
39
40
|
depth = newState.doc.resolve(pos).depth;
|
|
@@ -45,7 +46,7 @@ export const dropTargetDecorations = (oldState, newState, api, formatMessage, ac
|
|
|
45
46
|
prevNode = node;
|
|
46
47
|
return true; //skip over, don't consider it a valid depth
|
|
47
48
|
}
|
|
48
|
-
const canDrop =
|
|
49
|
+
const canDrop = activePMNode && canMoveNodeToIndex(parent, index, activePMNode);
|
|
49
50
|
|
|
50
51
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
51
52
|
if (!canDrop && !isBlocksDragTargetDebug()) {
|
|
@@ -144,13 +145,14 @@ export const nodeDecorations = newState => {
|
|
|
144
145
|
newState.doc.descendants((node, pos, parent, index) => {
|
|
145
146
|
let depth = 0;
|
|
146
147
|
let anchorName;
|
|
148
|
+
const shouldDescend = !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
147
149
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
148
150
|
// Doesn't descend into a node
|
|
149
|
-
if (node.isInline
|
|
151
|
+
if (node.isInline) {
|
|
150
152
|
return false;
|
|
151
153
|
}
|
|
152
154
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
153
|
-
return
|
|
155
|
+
return shouldDescend; //skip over, don't consider it a valid depth
|
|
154
156
|
}
|
|
155
157
|
depth = newState.doc.resolve(pos).depth;
|
|
156
158
|
anchorName = `--node-anchor-${node.type.name}-${pos}`;
|
|
@@ -165,7 +167,7 @@ export const nodeDecorations = newState => {
|
|
|
165
167
|
}, {
|
|
166
168
|
type: 'node-decoration'
|
|
167
169
|
}));
|
|
168
|
-
return depth < getNestedDepth();
|
|
170
|
+
return shouldDescend && depth < getNestedDepth();
|
|
169
171
|
});
|
|
170
172
|
return decs;
|
|
171
173
|
};
|