@atlaskit/editor-plugin-block-controls 1.13.11 → 2.0.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 +9 -0
- package/dist/cjs/plugin.js +12 -10
- package/dist/cjs/pm-plugins/decorations.js +26 -62
- package/dist/cjs/pm-plugins/main.js +12 -34
- package/dist/cjs/ui/drag-handle.js +10 -16
- package/dist/cjs/ui/drop-target.js +5 -9
- package/dist/cjs/utils/getSelection.js +4 -3
- package/dist/es2019/plugin.js +12 -10
- package/dist/es2019/pm-plugins/decorations.js +18 -58
- package/dist/es2019/pm-plugins/main.js +10 -34
- package/dist/es2019/ui/drag-handle.js +10 -16
- package/dist/es2019/ui/drop-target.js +5 -8
- package/dist/es2019/utils/getSelection.js +4 -3
- package/dist/esm/plugin.js +12 -10
- package/dist/esm/pm-plugins/decorations.js +26 -62
- package/dist/esm/pm-plugins/main.js +12 -34
- package/dist/esm/ui/drag-handle.js +10 -16
- package/dist/esm/ui/drop-target.js +5 -9
- package/dist/esm/utils/getSelection.js +4 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/decorations.d.ts +1 -7
- package/dist/types/types.d.ts +3 -9
- package/dist/types/ui/drop-target.d.ts +2 -2
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +1 -7
- package/dist/types-ts4.5/types.d.ts +3 -9
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -2
- package/package.json +5 -2
|
@@ -82,8 +82,7 @@ function getDocChildrenCount(newState) {
|
|
|
82
82
|
}
|
|
83
83
|
const initialState = {
|
|
84
84
|
decorations: DecorationSet.empty,
|
|
85
|
-
|
|
86
|
-
activeNode: null,
|
|
85
|
+
activeNode: undefined,
|
|
87
86
|
isDragging: false,
|
|
88
87
|
isMenuOpen: false,
|
|
89
88
|
editorHeight: 0,
|
|
@@ -107,7 +106,6 @@ export const createPlugin = (api, getIntl) => {
|
|
|
107
106
|
activeNode,
|
|
108
107
|
decorations,
|
|
109
108
|
isMenuOpen,
|
|
110
|
-
decorationState,
|
|
111
109
|
editorHeight,
|
|
112
110
|
editorWidthLeft,
|
|
113
111
|
editorWidthRight,
|
|
@@ -116,11 +114,16 @@ export const createPlugin = (api, getIntl) => {
|
|
|
116
114
|
isPMDragging,
|
|
117
115
|
childCount
|
|
118
116
|
} = currentState;
|
|
117
|
+
|
|
118
|
+
// Remap existing decorations when document changes
|
|
119
|
+
if (tr.docChanged) {
|
|
120
|
+
decorations = decorations.map(tr.mapping, tr.doc);
|
|
121
|
+
}
|
|
122
|
+
const meta = tr.getMeta(key);
|
|
119
123
|
const isPerformanceFix = editorExperiment('dnd-input-performance-optimisation', true, {
|
|
120
124
|
exposure: true
|
|
121
125
|
}) || editorExperiment('nested-dnd', true);
|
|
122
126
|
let activeNodeWithNewNodeType = null;
|
|
123
|
-
const meta = tr.getMeta(key);
|
|
124
127
|
const newChildCount = tr.docChanged && editorExperiment('nested-dnd', true) ? getDocChildrenCount(newState) : childCount;
|
|
125
128
|
// If tables or media are being resized, we want to hide the drag handle
|
|
126
129
|
const resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
@@ -237,11 +240,6 @@ export const createPlugin = (api, getIntl) => {
|
|
|
237
240
|
const decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
238
241
|
decorations = decorations.add(newState.doc, [decs]);
|
|
239
242
|
}
|
|
240
|
-
const shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
241
|
-
|
|
242
|
-
// During dragging if the the document is updated by remote user, or other processes
|
|
243
|
-
// and update drop target is not required, We remap the drop target.
|
|
244
|
-
const shouldMapDropTargets = editorExperiment('nested-dnd', true) ? !shouldUpdateDropTargets && tr.docChanged && isDragging && !(meta !== null && meta !== void 0 && meta.nodeMoved) : !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
245
243
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
246
244
|
if (editorExperiment('nested-dnd', true)) {
|
|
247
245
|
const remainingDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
|
|
@@ -259,37 +257,16 @@ export const createPlugin = (api, getIntl) => {
|
|
|
259
257
|
anchorName: activeNode.anchorName,
|
|
260
258
|
nodeType: activeNode.nodeType
|
|
261
259
|
} : activeNode;
|
|
260
|
+
const shouldCreateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
262
261
|
if (api) {
|
|
263
262
|
// Add drop targets when node is being dragged
|
|
264
263
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
265
|
-
if (
|
|
264
|
+
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
266
265
|
var _meta$activeNode6;
|
|
267
|
-
const
|
|
268
|
-
decs,
|
|
269
|
-
decorationState: updatedDecorationState
|
|
270
|
-
} = dropTargetDecorations(newState, api, formatMessage, editorExperiment('nested-dnd', true) ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
271
|
-
decorationState = updatedDecorationState;
|
|
266
|
+
const decs = dropTargetDecorations(newState, api, formatMessage, editorExperiment('nested-dnd', true) ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
272
267
|
decorations = decorations.add(newState.doc, decs);
|
|
273
268
|
}
|
|
274
269
|
}
|
|
275
|
-
|
|
276
|
-
//Map drop target decoration positions when the document changes
|
|
277
|
-
if (shouldMapDropTargets) {
|
|
278
|
-
decorationState = decorationState.map(({
|
|
279
|
-
id,
|
|
280
|
-
pos
|
|
281
|
-
}) => {
|
|
282
|
-
return {
|
|
283
|
-
id,
|
|
284
|
-
pos: tr.mapping.map(pos)
|
|
285
|
-
};
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
290
|
-
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
291
|
-
decorations = decorations.map(tr.mapping, tr.doc);
|
|
292
|
-
}
|
|
293
270
|
const isEmptyDoc = editorExperiment('nested-dnd', true) ? 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;
|
|
294
271
|
const hasNodeDecoration = decorations.find().some(({
|
|
295
272
|
spec
|
|
@@ -300,7 +277,6 @@ export const createPlugin = (api, getIntl) => {
|
|
|
300
277
|
const newActiveNode = isEmptyDoc || isHandleMissing ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
301
278
|
return {
|
|
302
279
|
decorations,
|
|
303
|
-
decorationState,
|
|
304
280
|
activeNode: newActiveNode,
|
|
305
281
|
isDragging: (_meta$isDragging2 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging2 !== void 0 ? _meta$isDragging2 : isDragging,
|
|
306
282
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
@@ -99,14 +99,11 @@ const DragHandleInternal = ({
|
|
|
99
99
|
tr
|
|
100
100
|
}) => {
|
|
101
101
|
var _api$analytics;
|
|
102
|
-
const startPos =
|
|
102
|
+
const startPos = getPos();
|
|
103
103
|
if (startPos === undefined) {
|
|
104
104
|
return tr;
|
|
105
105
|
}
|
|
106
106
|
tr = selectNode(tr, startPos, nodeType);
|
|
107
|
-
tr.setMeta(key, {
|
|
108
|
-
pos: startPos
|
|
109
|
-
});
|
|
110
107
|
const resolvedMovingNode = tr.doc.resolve(startPos);
|
|
111
108
|
const maybeNode = resolvedMovingNode.nodeAfter;
|
|
112
109
|
tr.setMeta('scrollIntoView', false);
|
|
@@ -123,7 +120,7 @@ const DragHandleInternal = ({
|
|
|
123
120
|
return tr;
|
|
124
121
|
});
|
|
125
122
|
view.focus();
|
|
126
|
-
}, [dragHandleSelected, api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos,
|
|
123
|
+
}, [dragHandleSelected, api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos, nodeType]);
|
|
127
124
|
|
|
128
125
|
// TODO - This needs to be investigated further. Drag preview generation is not always working
|
|
129
126
|
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
@@ -133,7 +130,7 @@ const DragHandleInternal = ({
|
|
|
133
130
|
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
|
|
134
131
|
tr
|
|
135
132
|
}) => {
|
|
136
|
-
const startPos =
|
|
133
|
+
const startPos = getPos();
|
|
137
134
|
if (startPos === undefined) {
|
|
138
135
|
return tr;
|
|
139
136
|
}
|
|
@@ -144,19 +141,16 @@ const DragHandleInternal = ({
|
|
|
144
141
|
const $startPos = tr.doc.resolve(startPos + node.nodeSize);
|
|
145
142
|
const selection = new TextSelection($startPos);
|
|
146
143
|
tr.setSelection(selection);
|
|
147
|
-
tr.setMeta(key, {
|
|
148
|
-
pos: startPos
|
|
149
|
-
});
|
|
150
144
|
return tr;
|
|
151
145
|
});
|
|
152
|
-
}, [api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos
|
|
146
|
+
}, [api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos]);
|
|
153
147
|
const handleKeyDown = useCallback(e => {
|
|
154
148
|
if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
155
149
|
// allow user to use spacebar to select the node
|
|
156
150
|
|
|
157
151
|
if (!e.repeat && e.key === ' ') {
|
|
158
152
|
var _api$core5;
|
|
159
|
-
const startPos =
|
|
153
|
+
const startPos = getPos();
|
|
160
154
|
api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
|
|
161
155
|
tr
|
|
162
156
|
}) => {
|
|
@@ -172,7 +166,7 @@ const DragHandleInternal = ({
|
|
|
172
166
|
tr.setSelection(selection);
|
|
173
167
|
tr.setMeta(key, {
|
|
174
168
|
pos: startPos
|
|
175
|
-
});
|
|
169
|
+
}); ////WHERE IS THIS USED?
|
|
176
170
|
return tr;
|
|
177
171
|
});
|
|
178
172
|
} else if (![e.altKey, e.ctrlKey, e.shiftKey].some(pressed => pressed)) {
|
|
@@ -181,7 +175,7 @@ const DragHandleInternal = ({
|
|
|
181
175
|
view.focus();
|
|
182
176
|
}
|
|
183
177
|
}
|
|
184
|
-
}, [getPos,
|
|
178
|
+
}, [getPos, api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, view]);
|
|
185
179
|
useEffect(() => {
|
|
186
180
|
const element = buttonRef.current;
|
|
187
181
|
if (!element) {
|
|
@@ -218,7 +212,7 @@ const DragHandleInternal = ({
|
|
|
218
212
|
tr
|
|
219
213
|
}) => {
|
|
220
214
|
var _api$blockControls, _api$analytics3;
|
|
221
|
-
api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(
|
|
215
|
+
api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(getPos, anchorName, nodeType)({
|
|
222
216
|
tr
|
|
223
217
|
});
|
|
224
218
|
const resolvedMovingNode = tr.doc.resolve(start);
|
|
@@ -239,7 +233,7 @@ const DragHandleInternal = ({
|
|
|
239
233
|
view.focus();
|
|
240
234
|
}
|
|
241
235
|
});
|
|
242
|
-
}, [anchorName, api, nodeType,
|
|
236
|
+
}, [anchorName, api, getPos, nodeType, start, view]);
|
|
243
237
|
const macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
|
|
244
238
|
const calculatePosition = useCallback(() => {
|
|
245
239
|
let parentNodeType;
|
|
@@ -340,7 +334,7 @@ const DragHandleInternal = ({
|
|
|
340
334
|
,
|
|
341
335
|
style: positionStyles,
|
|
342
336
|
onClick: handleOnClick,
|
|
343
|
-
onMouseDown: handleMouseDown,
|
|
337
|
+
onMouseDown: fg('platform_editor_element_drag_and_drop_ed_24885') ? undefined : handleMouseDown,
|
|
344
338
|
onKeyDown: handleKeyDown,
|
|
345
339
|
"data-testid": "block-ctrl-drag-handle"
|
|
346
340
|
}, jsx(DragHandlerIcon, {
|
|
@@ -66,7 +66,7 @@ const getDropTargetOffsetStyle = (prevNode, nextNode) => {
|
|
|
66
66
|
};
|
|
67
67
|
export const DropTarget = ({
|
|
68
68
|
api,
|
|
69
|
-
|
|
69
|
+
getPos,
|
|
70
70
|
prevNode,
|
|
71
71
|
nextNode,
|
|
72
72
|
parentNode,
|
|
@@ -95,15 +95,12 @@ export const DropTarget = ({
|
|
|
95
95
|
onDrop: () => {
|
|
96
96
|
var _api$blockControls;
|
|
97
97
|
const {
|
|
98
|
-
activeNode
|
|
99
|
-
decorationState
|
|
98
|
+
activeNode
|
|
100
99
|
} = (api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {};
|
|
101
|
-
if (!activeNode
|
|
100
|
+
if (!activeNode) {
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
|
-
const
|
|
105
|
-
pos
|
|
106
|
-
} = decorationState.find(dec => dec.id === id) || {};
|
|
103
|
+
const pos = getPos();
|
|
107
104
|
if (activeNode && pos !== undefined) {
|
|
108
105
|
var _api$core, _api$blockControls2, _api$blockControls2$c;
|
|
109
106
|
const {
|
|
@@ -113,7 +110,7 @@ export const DropTarget = ({
|
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
});
|
|
116
|
-
}, [
|
|
113
|
+
}, [api, formatMessage, getPos]);
|
|
117
114
|
const dropTargetOffsetStyle = useMemo(() => {
|
|
118
115
|
/**
|
|
119
116
|
* First child of a nested node.
|
|
@@ -5,17 +5,18 @@ export const getSelection = (tr, start) => {
|
|
|
5
5
|
const isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
6
6
|
const nodeSize = node ? node.nodeSize : 1;
|
|
7
7
|
const $startPos = tr.doc.resolve(start);
|
|
8
|
+
const nodeName = node === null || node === void 0 ? void 0 : node.type.name;
|
|
8
9
|
|
|
9
10
|
// decisionList node is not selectable, but we want to select the whole node not just text
|
|
10
|
-
if (isNodeSelection ||
|
|
11
|
+
if (isNodeSelection || nodeName === 'decisionList') {
|
|
11
12
|
return new NodeSelection($startPos);
|
|
12
|
-
} else if ((node === null || node === void 0 ? void 0 : node.
|
|
13
|
+
} else if (nodeName === 'mediaGroup' && (node === null || node === void 0 ? void 0 : node.childCount) === 1) {
|
|
13
14
|
const $mediaStartPos = tr.doc.resolve(start + 1);
|
|
14
15
|
return new NodeSelection($mediaStartPos);
|
|
15
16
|
} else if (
|
|
16
17
|
// Even though mediaGroup is not selectable,
|
|
17
18
|
// we need a quick way to make all child media nodes appear as selected without the need for a custom selection
|
|
18
|
-
|
|
19
|
+
nodeName === 'mediaGroup') {
|
|
19
20
|
return new NodeSelection($startPos);
|
|
20
21
|
} else {
|
|
21
22
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
4
5
|
import { moveNode } from './commands/move-node';
|
|
5
6
|
import { createEmptyBlockExperimentPlugin } from './pm-plugins/empty-block-experiment';
|
|
@@ -44,15 +45,17 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
44
45
|
return tr;
|
|
45
46
|
};
|
|
46
47
|
},
|
|
47
|
-
setNodeDragged: function setNodeDragged(
|
|
48
|
+
setNodeDragged: function setNodeDragged(getPos, anchorName, nodeType) {
|
|
48
49
|
return function (_ref5) {
|
|
49
50
|
var tr = _ref5.tr;
|
|
51
|
+
var pos = getPos();
|
|
50
52
|
if (pos === undefined) {
|
|
51
53
|
return tr;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (!fg('platform_editor_element_drag_and_drop_ed_24885')) {
|
|
56
|
+
tr = selectNode(tr, pos, nodeType);
|
|
57
|
+
}
|
|
58
|
+
tr.setMeta(key, {
|
|
56
59
|
isDragging: true,
|
|
57
60
|
activeNode: {
|
|
58
61
|
pos: pos,
|
|
@@ -60,21 +63,20 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
60
63
|
nodeType: nodeType
|
|
61
64
|
}
|
|
62
65
|
});
|
|
63
|
-
return
|
|
66
|
+
return tr;
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
},
|
|
67
70
|
getSharedState: function getSharedState(editorState) {
|
|
68
|
-
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$
|
|
71
|
+
var _key$getState$isMenuO, _key$getState, _key$getState$activeN, _key$getState2, _key$getState$isDragg, _key$getState3, _key$getState$isPMDra, _key$getState4;
|
|
69
72
|
if (!editorState) {
|
|
70
73
|
return undefined;
|
|
71
74
|
}
|
|
72
75
|
return {
|
|
73
76
|
isMenuOpen: (_key$getState$isMenuO = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.isMenuOpen) !== null && _key$getState$isMenuO !== void 0 ? _key$getState$isMenuO : false,
|
|
74
|
-
activeNode: (_key$getState$activeN = (_key$getState2 = key.getState(editorState)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode) !== null && _key$getState$activeN !== void 0 ? _key$getState$activeN :
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
isPMDragging: (_key$getState$isPMDra = (_key$getState5 = key.getState(editorState)) === null || _key$getState5 === void 0 ? void 0 : _key$getState5.isPMDragging) !== null && _key$getState$isPMDra !== void 0 ? _key$getState$isPMDra : false
|
|
77
|
+
activeNode: (_key$getState$activeN = (_key$getState2 = key.getState(editorState)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode) !== null && _key$getState$activeN !== void 0 ? _key$getState$activeN : undefined,
|
|
78
|
+
isDragging: (_key$getState$isDragg = (_key$getState3 = key.getState(editorState)) === null || _key$getState3 === void 0 ? void 0 : _key$getState3.isDragging) !== null && _key$getState$isDragg !== void 0 ? _key$getState$isDragg : false,
|
|
79
|
+
isPMDragging: (_key$getState$isPMDra = (_key$getState4 = key.getState(editorState)) === null || _key$getState4 === void 0 ? void 0 : _key$getState4.isPMDragging) !== null && _key$getState$isPMDra !== void 0 ? _key$getState$isPMDra : false
|
|
78
80
|
};
|
|
79
81
|
},
|
|
80
82
|
contentComponent: function contentComponent() {
|
|
@@ -20,11 +20,11 @@ var getNestedDepth = function getNestedDepth() {
|
|
|
20
20
|
return editorExperiment('nested-dnd', true) ? 100 : 0;
|
|
21
21
|
};
|
|
22
22
|
var createDropTargetDecoration = function createDropTargetDecoration(pos, dropTargetDec) {
|
|
23
|
-
return Decoration.widget(pos, function () {
|
|
23
|
+
return Decoration.widget(pos, function (_, getPos) {
|
|
24
24
|
var element = document.createElement('div');
|
|
25
25
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
26
26
|
element.style.clear = 'unset';
|
|
27
|
-
ReactDOM.render(dropTargetDec, element);
|
|
27
|
+
ReactDOM.render(dropTargetDec(getPos), element);
|
|
28
28
|
return element;
|
|
29
29
|
}, {
|
|
30
30
|
type: 'drop-target-decoration',
|
|
@@ -34,16 +34,13 @@ var createDropTargetDecoration = function createDropTargetDecoration(pos, dropTa
|
|
|
34
34
|
export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode) {
|
|
35
35
|
var decs = [];
|
|
36
36
|
unmountDecorations('data-blocks-drop-target-container');
|
|
37
|
-
// Decoration state is used to keep track of the position of the drop targets
|
|
38
|
-
// and allows us to easily map the updated position in the plugin apply method.
|
|
39
|
-
var decorationState = [];
|
|
40
37
|
var prevNode;
|
|
41
38
|
var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
42
39
|
var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
43
|
-
newState.doc.
|
|
40
|
+
newState.doc.descendants(function (node, pos, parent, index) {
|
|
44
41
|
var depth = 0;
|
|
45
42
|
// drop target deco at the end position
|
|
46
|
-
var
|
|
43
|
+
var endPos;
|
|
47
44
|
if (editorExperiment('nested-dnd', true)) {
|
|
48
45
|
depth = newState.doc.resolve(pos).depth;
|
|
49
46
|
if (node.isInline || !parent) {
|
|
@@ -61,82 +58,49 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
61
58
|
prevNode = node;
|
|
62
59
|
return false; //not valid pos, so nested not valid either
|
|
63
60
|
}
|
|
64
|
-
decorationState.push({
|
|
65
|
-
id: pos,
|
|
66
|
-
pos: pos
|
|
67
|
-
});
|
|
68
61
|
if (parent.lastChild === node && !isEmptyParagraph(node) && PARENT_WITH_END_DROP_TARGET.includes(parent.type.name)) {
|
|
69
|
-
|
|
70
|
-
endPosDeco = {
|
|
71
|
-
id: endpos,
|
|
72
|
-
pos: endpos
|
|
73
|
-
};
|
|
74
|
-
decorationState.push({
|
|
75
|
-
id: endpos,
|
|
76
|
-
pos: endpos
|
|
77
|
-
});
|
|
62
|
+
endPos = pos + node.nodeSize;
|
|
78
63
|
}
|
|
79
|
-
} else {
|
|
80
|
-
decorationState.push({
|
|
81
|
-
id: index,
|
|
82
|
-
pos: pos
|
|
83
|
-
});
|
|
84
64
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
formatMessage: formatMessage,
|
|
89
|
-
prevNode: prevNode,
|
|
90
|
-
nextNode: node,
|
|
91
|
-
parentNode: parent
|
|
92
|
-
})));
|
|
93
|
-
if (endPosDeco) {
|
|
94
|
-
decs.push(createDropTargetDecoration(endPosDeco.pos, /*#__PURE__*/createElement(DropTarget, {
|
|
65
|
+
var previousNode = prevNode; // created scoped variable
|
|
66
|
+
decs.push(createDropTargetDecoration(pos, function (getPos) {
|
|
67
|
+
return /*#__PURE__*/createElement(DropTarget, {
|
|
95
68
|
api: api,
|
|
96
|
-
|
|
69
|
+
getPos: getPos,
|
|
70
|
+
prevNode: previousNode,
|
|
71
|
+
nextNode: node,
|
|
97
72
|
parentNode: parent,
|
|
98
73
|
formatMessage: formatMessage
|
|
99
|
-
})
|
|
74
|
+
});
|
|
75
|
+
}));
|
|
76
|
+
if (endPos !== undefined) {
|
|
77
|
+
decs.push(createDropTargetDecoration(endPos, function (getPos) {
|
|
78
|
+
return /*#__PURE__*/createElement(DropTarget, {
|
|
79
|
+
api: api,
|
|
80
|
+
getPos: getPos,
|
|
81
|
+
parentNode: parent,
|
|
82
|
+
formatMessage: formatMessage
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
100
85
|
}
|
|
101
86
|
prevNode = node;
|
|
102
87
|
return depth < getNestedDepth();
|
|
103
88
|
});
|
|
104
89
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* draw all drop targets at the top of every node. It's better to draw the drop targets
|
|
108
|
-
* at the top of each node because that way we only need to know the start position of the
|
|
109
|
-
* node and not its size.
|
|
110
|
-
*
|
|
111
|
-
*/
|
|
112
|
-
var lastPos = newState.doc.content.size;
|
|
113
|
-
if (editorExperiment('nested-dnd', true)) {
|
|
114
|
-
decorationState.push({
|
|
115
|
-
id: lastPos,
|
|
116
|
-
pos: lastPos
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
decorationState.push({
|
|
120
|
-
id: decorationState.length + 1,
|
|
121
|
-
pos: newState.doc.nodeSize - 2
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
decs.push(Decoration.widget(newState.doc.nodeSize - 2, function () {
|
|
90
|
+
//TODO: Should this use createDropTargetDecoration?
|
|
91
|
+
decs.push(Decoration.widget(newState.doc.nodeSize - 2, function (_, getPos) {
|
|
125
92
|
var element = document.createElement('div');
|
|
126
93
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
127
94
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
128
95
|
api: api,
|
|
129
|
-
|
|
96
|
+
getPos: getPos,
|
|
130
97
|
formatMessage: formatMessage
|
|
131
98
|
}), element);
|
|
132
99
|
return element;
|
|
133
100
|
}, {
|
|
134
101
|
type: 'drop-target-decoration'
|
|
135
102
|
}));
|
|
136
|
-
return
|
|
137
|
-
decs: decs,
|
|
138
|
-
decorationState: decorationState
|
|
139
|
-
};
|
|
103
|
+
return decs;
|
|
140
104
|
};
|
|
141
105
|
export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
142
106
|
var anchorName = "--node-anchor-paragraph-0";
|
|
@@ -81,8 +81,7 @@ function getDocChildrenCount(newState) {
|
|
|
81
81
|
}
|
|
82
82
|
var initialState = {
|
|
83
83
|
decorations: DecorationSet.empty,
|
|
84
|
-
|
|
85
|
-
activeNode: null,
|
|
84
|
+
activeNode: undefined,
|
|
86
85
|
isDragging: false,
|
|
87
86
|
isMenuOpen: false,
|
|
88
87
|
editorHeight: 0,
|
|
@@ -105,7 +104,6 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
105
104
|
var activeNode = currentState.activeNode,
|
|
106
105
|
decorations = currentState.decorations,
|
|
107
106
|
isMenuOpen = currentState.isMenuOpen,
|
|
108
|
-
decorationState = currentState.decorationState,
|
|
109
107
|
editorHeight = currentState.editorHeight,
|
|
110
108
|
editorWidthLeft = currentState.editorWidthLeft,
|
|
111
109
|
editorWidthRight = currentState.editorWidthRight,
|
|
@@ -113,11 +111,16 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
113
111
|
isDragging = currentState.isDragging,
|
|
114
112
|
isPMDragging = currentState.isPMDragging,
|
|
115
113
|
childCount = currentState.childCount;
|
|
114
|
+
|
|
115
|
+
// Remap existing decorations when document changes
|
|
116
|
+
if (tr.docChanged) {
|
|
117
|
+
decorations = decorations.map(tr.mapping, tr.doc);
|
|
118
|
+
}
|
|
119
|
+
var meta = tr.getMeta(key);
|
|
116
120
|
var isPerformanceFix = editorExperiment('dnd-input-performance-optimisation', true, {
|
|
117
121
|
exposure: true
|
|
118
122
|
}) || editorExperiment('nested-dnd', true);
|
|
119
123
|
var activeNodeWithNewNodeType = null;
|
|
120
|
-
var meta = tr.getMeta(key);
|
|
121
124
|
var newChildCount = tr.docChanged && editorExperiment('nested-dnd', true) ? getDocChildrenCount(newState) : childCount;
|
|
122
125
|
// If tables or media are being resized, we want to hide the drag handle
|
|
123
126
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
@@ -249,11 +252,6 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
249
252
|
var _decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
250
253
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
251
254
|
}
|
|
252
|
-
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
253
|
-
|
|
254
|
-
// During dragging if the the document is updated by remote user, or other processes
|
|
255
|
-
// and update drop target is not required, We remap the drop target.
|
|
256
|
-
var shouldMapDropTargets = editorExperiment('nested-dnd', true) ? !shouldUpdateDropTargets && tr.docChanged && isDragging && !(meta !== null && meta !== void 0 && meta.nodeMoved) : !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
257
255
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
258
256
|
if (editorExperiment('nested-dnd', true)) {
|
|
259
257
|
var remainingDecs = decorations.find(undefined, undefined, function (spec) {
|
|
@@ -275,38 +273,19 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
275
273
|
anchorName: activeNode.anchorName,
|
|
276
274
|
nodeType: activeNode.nodeType
|
|
277
275
|
} : activeNode;
|
|
276
|
+
var shouldCreateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
278
277
|
if (api) {
|
|
279
278
|
// Add drop targets when node is being dragged
|
|
280
279
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
281
|
-
if (
|
|
280
|
+
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
282
281
|
var _meta$activeNode6;
|
|
283
|
-
var
|
|
284
|
-
_decs2 = _dropTargetDecoration.decs,
|
|
285
|
-
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
286
|
-
decorationState = updatedDecorationState;
|
|
282
|
+
var _decs2 = dropTargetDecorations(newState, api, formatMessage, editorExperiment('nested-dnd', true) ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
287
283
|
decorations = decorations.add(newState.doc, _decs2);
|
|
288
284
|
}
|
|
289
285
|
}
|
|
290
|
-
|
|
291
|
-
//Map drop target decoration positions when the document changes
|
|
292
|
-
if (shouldMapDropTargets) {
|
|
293
|
-
decorationState = decorationState.map(function (_ref11) {
|
|
294
|
-
var id = _ref11.id,
|
|
295
|
-
pos = _ref11.pos;
|
|
296
|
-
return {
|
|
297
|
-
id: id,
|
|
298
|
-
pos: tr.mapping.map(pos)
|
|
299
|
-
};
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
304
|
-
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
305
|
-
decorations = decorations.map(tr.mapping, tr.doc);
|
|
306
|
-
}
|
|
307
286
|
var isEmptyDoc = editorExperiment('nested-dnd', true) ? 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;
|
|
308
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
309
|
-
var spec =
|
|
287
|
+
var hasNodeDecoration = decorations.find().some(function (_ref11) {
|
|
288
|
+
var spec = _ref11.spec;
|
|
310
289
|
return spec.type === 'node-decoration';
|
|
311
290
|
});
|
|
312
291
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -315,7 +294,6 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
315
294
|
var newActiveNode = isEmptyDoc || isHandleMissing ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
316
295
|
return {
|
|
317
296
|
decorations: decorations,
|
|
318
|
-
decorationState: decorationState,
|
|
319
297
|
activeNode: newActiveNode,
|
|
320
298
|
isDragging: (_meta$isDragging2 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging2 !== void 0 ? _meta$isDragging2 : isDragging,
|
|
321
299
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
@@ -103,14 +103,11 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
103
103
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
104
104
|
var _api$analytics;
|
|
105
105
|
var tr = _ref2.tr;
|
|
106
|
-
var startPos =
|
|
106
|
+
var startPos = getPos();
|
|
107
107
|
if (startPos === undefined) {
|
|
108
108
|
return tr;
|
|
109
109
|
}
|
|
110
110
|
tr = selectNode(tr, startPos, nodeType);
|
|
111
|
-
tr.setMeta(key, {
|
|
112
|
-
pos: startPos
|
|
113
|
-
});
|
|
114
111
|
var resolvedMovingNode = tr.doc.resolve(startPos);
|
|
115
112
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
116
113
|
tr.setMeta('scrollIntoView', false);
|
|
@@ -127,7 +124,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
127
124
|
return tr;
|
|
128
125
|
});
|
|
129
126
|
view.focus();
|
|
130
|
-
}, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos,
|
|
127
|
+
}, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos, nodeType]);
|
|
131
128
|
|
|
132
129
|
// TODO - This needs to be investigated further. Drag preview generation is not always working
|
|
133
130
|
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
@@ -136,7 +133,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
136
133
|
var _api$core3;
|
|
137
134
|
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref3) {
|
|
138
135
|
var tr = _ref3.tr;
|
|
139
|
-
var startPos =
|
|
136
|
+
var startPos = getPos();
|
|
140
137
|
if (startPos === undefined) {
|
|
141
138
|
return tr;
|
|
142
139
|
}
|
|
@@ -147,19 +144,16 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
147
144
|
var $startPos = tr.doc.resolve(startPos + node.nodeSize);
|
|
148
145
|
var selection = new TextSelection($startPos);
|
|
149
146
|
tr.setSelection(selection);
|
|
150
|
-
tr.setMeta(key, {
|
|
151
|
-
pos: startPos
|
|
152
|
-
});
|
|
153
147
|
return tr;
|
|
154
148
|
});
|
|
155
|
-
}, [api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos
|
|
149
|
+
}, [api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos]);
|
|
156
150
|
var handleKeyDown = useCallback(function (e) {
|
|
157
151
|
if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
158
152
|
// allow user to use spacebar to select the node
|
|
159
153
|
|
|
160
154
|
if (!e.repeat && e.key === ' ') {
|
|
161
155
|
var _api$core5;
|
|
162
|
-
var startPos =
|
|
156
|
+
var startPos = getPos();
|
|
163
157
|
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref4) {
|
|
164
158
|
var tr = _ref4.tr;
|
|
165
159
|
if (startPos === undefined) {
|
|
@@ -174,7 +168,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
174
168
|
tr.setSelection(selection);
|
|
175
169
|
tr.setMeta(key, {
|
|
176
170
|
pos: startPos
|
|
177
|
-
});
|
|
171
|
+
}); ////WHERE IS THIS USED?
|
|
178
172
|
return tr;
|
|
179
173
|
});
|
|
180
174
|
} else if (![e.altKey, e.ctrlKey, e.shiftKey].some(function (pressed) {
|
|
@@ -185,7 +179,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
185
179
|
view.focus();
|
|
186
180
|
}
|
|
187
181
|
}
|
|
188
|
-
}, [getPos,
|
|
182
|
+
}, [getPos, api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, view]);
|
|
189
183
|
useEffect(function () {
|
|
190
184
|
var element = buttonRef.current;
|
|
191
185
|
if (!element) {
|
|
@@ -221,7 +215,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
221
215
|
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref7) {
|
|
222
216
|
var _api$blockControls, _api$analytics3;
|
|
223
217
|
var tr = _ref7.tr;
|
|
224
|
-
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(
|
|
218
|
+
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(getPos, anchorName, nodeType)({
|
|
225
219
|
tr: tr
|
|
226
220
|
});
|
|
227
221
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
@@ -242,7 +236,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
242
236
|
view.focus();
|
|
243
237
|
}
|
|
244
238
|
});
|
|
245
|
-
}, [anchorName, api, nodeType,
|
|
239
|
+
}, [anchorName, api, getPos, nodeType, start, view]);
|
|
246
240
|
var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
|
|
247
241
|
var calculatePosition = useCallback(function () {
|
|
248
242
|
var parentNodeType;
|
|
@@ -347,7 +341,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
347
341
|
,
|
|
348
342
|
style: positionStyles,
|
|
349
343
|
onClick: handleOnClick,
|
|
350
|
-
onMouseDown: handleMouseDown,
|
|
344
|
+
onMouseDown: fg('platform_editor_element_drag_and_drop_ed_24885') ? undefined : handleMouseDown,
|
|
351
345
|
onKeyDown: handleKeyDown,
|
|
352
346
|
"data-testid": "block-ctrl-drag-handle"
|
|
353
347
|
}, jsx(DragHandlerIcon, {
|