@atlaskit/editor-plugin-block-controls 1.13.10 → 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 +17 -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/ui/empty-block-experiment/widget.js +1 -1
- 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/ui/empty-block-experiment/widget.js +1 -1
- 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/ui/empty-block-experiment/widget.js +1 -1
- 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 +6 -3
|
@@ -16,11 +16,11 @@ const IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaS
|
|
|
16
16
|
const PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
|
|
17
17
|
const getNestedDepth = () => editorExperiment('nested-dnd', true) ? 100 : 0;
|
|
18
18
|
const createDropTargetDecoration = (pos, dropTargetDec) => {
|
|
19
|
-
return Decoration.widget(pos, () => {
|
|
19
|
+
return Decoration.widget(pos, (_, getPos) => {
|
|
20
20
|
const element = document.createElement('div');
|
|
21
21
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
22
22
|
element.style.clear = 'unset';
|
|
23
|
-
ReactDOM.render(dropTargetDec, element);
|
|
23
|
+
ReactDOM.render(dropTargetDec(getPos), element);
|
|
24
24
|
return element;
|
|
25
25
|
}, {
|
|
26
26
|
type: 'drop-target-decoration',
|
|
@@ -30,16 +30,13 @@ const createDropTargetDecoration = (pos, dropTargetDec) => {
|
|
|
30
30
|
export const dropTargetDecorations = (newState, api, formatMessage, activeNode) => {
|
|
31
31
|
const decs = [];
|
|
32
32
|
unmountDecorations('data-blocks-drop-target-container');
|
|
33
|
-
// Decoration state is used to keep track of the position of the drop targets
|
|
34
|
-
// and allows us to easily map the updated position in the plugin apply method.
|
|
35
|
-
const decorationState = [];
|
|
36
33
|
let prevNode;
|
|
37
34
|
const activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
38
35
|
const activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
39
|
-
newState.doc.
|
|
36
|
+
newState.doc.descendants((node, pos, parent, index) => {
|
|
40
37
|
let depth = 0;
|
|
41
38
|
// drop target deco at the end position
|
|
42
|
-
let
|
|
39
|
+
let endPos;
|
|
43
40
|
if (editorExperiment('nested-dnd', true)) {
|
|
44
41
|
depth = newState.doc.resolve(pos).depth;
|
|
45
42
|
if (node.isInline || !parent) {
|
|
@@ -57,39 +54,23 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode)
|
|
|
57
54
|
prevNode = node;
|
|
58
55
|
return false; //not valid pos, so nested not valid either
|
|
59
56
|
}
|
|
60
|
-
decorationState.push({
|
|
61
|
-
id: pos,
|
|
62
|
-
pos
|
|
63
|
-
});
|
|
64
57
|
if (parent.lastChild === node && !isEmptyParagraph(node) && PARENT_WITH_END_DROP_TARGET.includes(parent.type.name)) {
|
|
65
|
-
|
|
66
|
-
endPosDeco = {
|
|
67
|
-
id: endpos,
|
|
68
|
-
pos: endpos
|
|
69
|
-
};
|
|
70
|
-
decorationState.push({
|
|
71
|
-
id: endpos,
|
|
72
|
-
pos: endpos
|
|
73
|
-
});
|
|
58
|
+
endPos = pos + node.nodeSize;
|
|
74
59
|
}
|
|
75
|
-
} else {
|
|
76
|
-
decorationState.push({
|
|
77
|
-
id: index,
|
|
78
|
-
pos
|
|
79
|
-
});
|
|
80
60
|
}
|
|
81
|
-
|
|
61
|
+
const previousNode = prevNode; // created scoped variable
|
|
62
|
+
decs.push(createDropTargetDecoration(pos, getPos => /*#__PURE__*/createElement(DropTarget, {
|
|
82
63
|
api,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
prevNode,
|
|
64
|
+
getPos,
|
|
65
|
+
prevNode: previousNode,
|
|
86
66
|
nextNode: node,
|
|
87
|
-
parentNode: parent
|
|
67
|
+
parentNode: parent,
|
|
68
|
+
formatMessage
|
|
88
69
|
})));
|
|
89
|
-
if (
|
|
90
|
-
decs.push(createDropTargetDecoration(
|
|
70
|
+
if (endPos !== undefined) {
|
|
71
|
+
decs.push(createDropTargetDecoration(endPos, getPos => /*#__PURE__*/createElement(DropTarget, {
|
|
91
72
|
api,
|
|
92
|
-
|
|
73
|
+
getPos,
|
|
93
74
|
parentNode: parent,
|
|
94
75
|
formatMessage
|
|
95
76
|
})));
|
|
@@ -98,41 +79,20 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode)
|
|
|
98
79
|
return depth < getNestedDepth();
|
|
99
80
|
});
|
|
100
81
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* draw all drop targets at the top of every node. It's better to draw the drop targets
|
|
104
|
-
* at the top of each node because that way we only need to know the start position of the
|
|
105
|
-
* node and not its size.
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
const lastPos = newState.doc.content.size;
|
|
109
|
-
if (editorExperiment('nested-dnd', true)) {
|
|
110
|
-
decorationState.push({
|
|
111
|
-
id: lastPos,
|
|
112
|
-
pos: lastPos
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
decorationState.push({
|
|
116
|
-
id: decorationState.length + 1,
|
|
117
|
-
pos: newState.doc.nodeSize - 2
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
decs.push(Decoration.widget(newState.doc.nodeSize - 2, () => {
|
|
82
|
+
//TODO: Should this use createDropTargetDecoration?
|
|
83
|
+
decs.push(Decoration.widget(newState.doc.nodeSize - 2, (_, getPos) => {
|
|
121
84
|
const element = document.createElement('div');
|
|
122
85
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
123
86
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
124
87
|
api,
|
|
125
|
-
|
|
88
|
+
getPos,
|
|
126
89
|
formatMessage
|
|
127
90
|
}), element);
|
|
128
91
|
return element;
|
|
129
92
|
}, {
|
|
130
93
|
type: 'drop-target-decoration'
|
|
131
94
|
}));
|
|
132
|
-
return
|
|
133
|
-
decs,
|
|
134
|
-
decorationState
|
|
135
|
-
};
|
|
95
|
+
return decs;
|
|
136
96
|
};
|
|
137
97
|
export const emptyParagraphNodeDecorations = () => {
|
|
138
98
|
const anchorName = `--node-anchor-paragraph-0`;
|
|
@@ -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";
|