@atlaskit/editor-plugin-block-controls 1.10.6 → 1.11.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 +30 -0
- package/dist/cjs/pm-plugins/decorations.js +52 -33
- package/dist/cjs/pm-plugins/main.js +62 -128
- package/dist/cjs/ui/drag-handle.js +6 -15
- package/dist/cjs/ui/drop-target.js +0 -4
- package/dist/cjs/utils/drag-target-debug.js +1 -1
- package/dist/es2019/pm-plugins/decorations.js +50 -33
- package/dist/es2019/pm-plugins/main.js +57 -122
- package/dist/es2019/ui/drag-handle.js +6 -15
- package/dist/es2019/ui/drop-target.js +0 -4
- package/dist/es2019/utils/drag-target-debug.js +1 -1
- package/dist/esm/pm-plugins/decorations.js +52 -33
- package/dist/esm/pm-plugins/main.js +62 -128
- package/dist/esm/ui/drag-handle.js +7 -16
- package/dist/esm/ui/drop-target.js +0 -4
- package/dist/esm/utils/drag-target-debug.js +1 -1
- package/dist/types/ui/drop-target.d.ts +6 -9
- package/dist/types-ts4.5/ui/drop-target.d.ts +6 -9
- package/package.json +7 -32
|
@@ -6,9 +6,24 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
6
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { DragHandle } from '../ui/drag-handle';
|
|
8
8
|
import { DropTarget } from '../ui/drop-target';
|
|
9
|
+
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
9
10
|
import { canMoveToIndex } from '../utils/validation';
|
|
10
|
-
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
11
|
-
const
|
|
11
|
+
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem'];
|
|
12
|
+
const IGNORE_NODES_AND_DESCENDANTS = ['listItem'];
|
|
13
|
+
const PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand'];
|
|
14
|
+
const getNestedDepth = () => fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
15
|
+
const createDropTargetDecoration = (pos, dropTargetDec) => {
|
|
16
|
+
return Decoration.widget(pos, () => {
|
|
17
|
+
const element = document.createElement('div');
|
|
18
|
+
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
19
|
+
element.style.clear = 'unset';
|
|
20
|
+
ReactDOM.render(dropTargetDec, element);
|
|
21
|
+
return element;
|
|
22
|
+
}, {
|
|
23
|
+
type: 'drop-target-decoration',
|
|
24
|
+
side: -1
|
|
25
|
+
});
|
|
26
|
+
};
|
|
12
27
|
export const dropTargetDecorations = (oldState, newState, api, formatMessage, activeNodeType) => {
|
|
13
28
|
const decs = [];
|
|
14
29
|
unmountDecorations('data-blocks-drop-target-container');
|
|
@@ -16,53 +31,61 @@ export const dropTargetDecorations = (oldState, newState, api, formatMessage, ac
|
|
|
16
31
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
17
32
|
const decorationState = [];
|
|
18
33
|
let prevNode;
|
|
19
|
-
|
|
20
|
-
state.doc.nodesBetween(0, newState.doc.nodeSize - 2, (node, pos, parent, index) => {
|
|
34
|
+
newState.doc.nodesBetween(0, newState.doc.nodeSize - 2, (node, pos, parent, index) => {
|
|
21
35
|
let depth = 0;
|
|
22
36
|
const nodeType = newState.doc.type.schema.nodes[activeNodeType];
|
|
37
|
+
let endDec = null;
|
|
23
38
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
24
39
|
depth = newState.doc.resolve(pos).depth;
|
|
25
|
-
if (node.isInline) {
|
|
40
|
+
if (node.isInline || !parent) {
|
|
26
41
|
return false;
|
|
27
42
|
}
|
|
28
43
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
29
44
|
return true; //skip over, don't consider it a valid depth
|
|
30
45
|
}
|
|
31
|
-
const canDrop =
|
|
46
|
+
const canDrop = activeNodeType && canMoveToIndex(parent, index, nodeType);
|
|
32
47
|
|
|
33
48
|
//NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
|
|
34
|
-
if (!canDrop) {
|
|
49
|
+
if (!canDrop && !isBlocksDragTargetDebug()) {
|
|
35
50
|
return false; //not valid pos, so nested not valid either
|
|
36
51
|
}
|
|
37
52
|
decorationState.push({
|
|
38
53
|
id: pos,
|
|
39
54
|
pos
|
|
40
55
|
});
|
|
56
|
+
if (parent.lastChild === node && PARENT_WITH_END_DROP_TARGET.includes(parent.type.name)) {
|
|
57
|
+
const endpos = pos + node.nodeSize;
|
|
58
|
+
endDec = {
|
|
59
|
+
id: endpos,
|
|
60
|
+
pos: endpos
|
|
61
|
+
};
|
|
62
|
+
decorationState.push({
|
|
63
|
+
id: endpos,
|
|
64
|
+
pos: endpos
|
|
65
|
+
});
|
|
66
|
+
}
|
|
41
67
|
} else {
|
|
42
68
|
decorationState.push({
|
|
43
69
|
id: index,
|
|
44
70
|
pos
|
|
45
71
|
});
|
|
46
72
|
}
|
|
47
|
-
|
|
73
|
+
decs.push(createDropTargetDecoration(pos, /*#__PURE__*/createElement(DropTarget, {
|
|
48
74
|
api,
|
|
49
75
|
id: fg('platform_editor_elements_dnd_nested') ? pos : index,
|
|
50
76
|
formatMessage,
|
|
51
77
|
prevNode,
|
|
52
78
|
nextNode: node
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
type: 'drop-target-decoration',
|
|
62
|
-
side: -1
|
|
63
|
-
}));
|
|
79
|
+
})));
|
|
80
|
+
if (endDec) {
|
|
81
|
+
decs.push(createDropTargetDecoration(endDec.pos, /*#__PURE__*/createElement(DropTarget, {
|
|
82
|
+
api,
|
|
83
|
+
id: endDec.id,
|
|
84
|
+
formatMessage
|
|
85
|
+
})));
|
|
86
|
+
}
|
|
64
87
|
prevNode = node;
|
|
65
|
-
return depth <
|
|
88
|
+
return depth < getNestedDepth();
|
|
66
89
|
});
|
|
67
90
|
|
|
68
91
|
/**
|
|
@@ -72,7 +95,6 @@ export const dropTargetDecorations = (oldState, newState, api, formatMessage, ac
|
|
|
72
95
|
* node and not its size.
|
|
73
96
|
*
|
|
74
97
|
*/
|
|
75
|
-
|
|
76
98
|
const lastPos = newState.doc.content.size;
|
|
77
99
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
78
100
|
decorationState.push({
|
|
@@ -114,11 +136,12 @@ export const emptyParagraphNodeDecorations = () => {
|
|
|
114
136
|
};
|
|
115
137
|
export const nodeDecorations = newState => {
|
|
116
138
|
const decs = [];
|
|
117
|
-
newState.doc.descendants((node, pos,
|
|
139
|
+
newState.doc.descendants((node, pos, parent, index) => {
|
|
118
140
|
let depth = 0;
|
|
119
141
|
let anchorName;
|
|
120
142
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
121
|
-
|
|
143
|
+
// Doesn't descend into a node
|
|
144
|
+
if (node.isInline || IGNORE_NODES_AND_DESCENDANTS.includes((parent === null || parent === void 0 ? void 0 : parent.type.name) || '')) {
|
|
122
145
|
return false;
|
|
123
146
|
}
|
|
124
147
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
@@ -137,15 +160,14 @@ export const nodeDecorations = newState => {
|
|
|
137
160
|
}, {
|
|
138
161
|
type: 'node-decoration'
|
|
139
162
|
}));
|
|
140
|
-
return depth <
|
|
163
|
+
return depth < getNestedDepth();
|
|
141
164
|
});
|
|
142
165
|
return decs;
|
|
143
166
|
};
|
|
144
167
|
export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, handleOptions) => {
|
|
145
168
|
let unbind;
|
|
146
|
-
const elementType = fg('platform_editor_element_drag_and_drop_ed_24150') ? 'span' : 'div';
|
|
147
169
|
return Decoration.widget(pos, (view, getPos) => {
|
|
148
|
-
const element = document.createElement(
|
|
170
|
+
const element = document.createElement('span');
|
|
149
171
|
// Need to set it to inline to avoid text being split when merging two paragraphs
|
|
150
172
|
element.style.display = 'inline';
|
|
151
173
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
@@ -158,9 +180,7 @@ export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, ha
|
|
|
158
180
|
}
|
|
159
181
|
});
|
|
160
182
|
}
|
|
161
|
-
|
|
162
|
-
unmountDecorations('data-blocks-drag-handle-container');
|
|
163
|
-
}
|
|
183
|
+
unmountDecorations('data-blocks-drag-handle-container');
|
|
164
184
|
|
|
165
185
|
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
166
186
|
// due to margins applied to other nodes eg. Headings
|
|
@@ -179,13 +199,10 @@ export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, ha
|
|
|
179
199
|
}, {
|
|
180
200
|
side: -1,
|
|
181
201
|
id: 'drag-handle',
|
|
182
|
-
destroy:
|
|
202
|
+
destroy: () => {
|
|
183
203
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
184
204
|
unbind && unbind();
|
|
185
205
|
}
|
|
186
|
-
if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
187
|
-
ReactDOM.unmountComponentAtNode(node);
|
|
188
|
-
}
|
|
189
206
|
}
|
|
190
207
|
});
|
|
191
208
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import rafSchedule from 'raf-schd';
|
|
2
|
-
import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
|
|
3
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
4
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
@@ -87,7 +86,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
87
86
|
return initialState;
|
|
88
87
|
},
|
|
89
88
|
apply(tr, currentState, oldState, newState) {
|
|
90
|
-
var _meta$activeNode, _meta$activeNode$hand, _meta$
|
|
89
|
+
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$activeNode3, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
91
90
|
let {
|
|
92
91
|
activeNode,
|
|
93
92
|
decorations,
|
|
@@ -102,18 +101,12 @@ export const createPlugin = (api, getIntl) => {
|
|
|
102
101
|
} = currentState;
|
|
103
102
|
let activeNodeWithNewNodeType = null;
|
|
104
103
|
const meta = tr.getMeta(key);
|
|
105
|
-
// when creating analytics during drag/drop events, PM thinks the doc has changed
|
|
106
|
-
// so tr.docChange is true and causes some decorations to not render
|
|
107
|
-
const isAnalyticTr = tr.steps.every(step => step instanceof AnalyticsStep);
|
|
108
104
|
|
|
109
105
|
// If tables or media are being resized, we want to hide the drag handle
|
|
110
106
|
const resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
111
107
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
112
108
|
const nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
113
|
-
|
|
114
|
-
if (fg('platform_editor_elements_drag_and_drop_ed_24000')) {
|
|
115
|
-
shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
116
|
-
}
|
|
109
|
+
const shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
117
110
|
|
|
118
111
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
119
112
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
@@ -138,15 +131,13 @@ export const createPlugin = (api, getIntl) => {
|
|
|
138
131
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
139
132
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
140
133
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}) => spec.type === 'drop-target-decoration').length;
|
|
134
|
+
const dropTargetLen = decorations.find().filter(({
|
|
135
|
+
spec
|
|
136
|
+
}) => spec.type === 'drop-target-decoration').length;
|
|
145
137
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
138
|
+
//TODO: Fix this logic for nested scenarios
|
|
139
|
+
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
140
|
+
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
150
141
|
}
|
|
151
142
|
|
|
152
143
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
@@ -166,14 +157,10 @@ export const createPlugin = (api, getIntl) => {
|
|
|
166
157
|
|
|
167
158
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
168
159
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
decorations = decorations.remove(oldNodeDecs);
|
|
174
|
-
} else {
|
|
175
|
-
decorations = DecorationSet.create(newState.doc, []);
|
|
176
|
-
}
|
|
160
|
+
const oldNodeDecs = decorations.find().filter(({
|
|
161
|
+
spec
|
|
162
|
+
}) => spec.type !== 'drop-target-decoration');
|
|
163
|
+
decorations = decorations.remove(oldNodeDecs);
|
|
177
164
|
const nodeDecs = nodeDecorations(newState);
|
|
178
165
|
decorations = decorations.add(newState.doc, [...nodeDecs]);
|
|
179
166
|
|
|
@@ -185,9 +172,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
185
172
|
|
|
186
173
|
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
187
174
|
// This is a workaround to fix the position of the active node when it is nested
|
|
188
|
-
|
|
189
|
-
const shouldUpdateNestedPosition = fg('platform_editor_element_drag_and_drop_ed_24049') ? tr.docChanged && !nodeCountChanged : true;
|
|
190
|
-
if (shouldUpdateNestedPosition && mappedPosisiton === prevMappedPos + 1) {
|
|
175
|
+
if (tr.docChanged && !nodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
191
176
|
mappedPosisiton = prevMappedPos;
|
|
192
177
|
}
|
|
193
178
|
const newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
@@ -216,91 +201,50 @@ export const createPlugin = (api, getIntl) => {
|
|
|
216
201
|
const decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
217
202
|
decorations = decorations.add(newState.doc, [decs]);
|
|
218
203
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
decorations = decorations.add(newState.doc, [decs]);
|
|
229
|
-
}
|
|
204
|
+
|
|
205
|
+
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
206
|
+
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
207
|
+
const oldHandle = decorations.find().filter(({
|
|
208
|
+
spec
|
|
209
|
+
}) => spec.id === 'drag-handle');
|
|
210
|
+
decorations = decorations.remove(oldHandle);
|
|
211
|
+
const decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
212
|
+
decorations = decorations.add(newState.doc, [decs]);
|
|
230
213
|
}
|
|
231
214
|
const shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
235
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
236
|
-
// Remove drop target decoration when dragging stops
|
|
237
|
-
const dropTargetDecs = decorations.find().filter(({
|
|
238
|
-
spec
|
|
239
|
-
}) => spec.type === 'drop-target-decoration');
|
|
240
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
241
|
-
}
|
|
242
|
-
if (api) {
|
|
243
|
-
// Add drop targets when node is being dragged
|
|
244
|
-
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
245
|
-
if (shouldUpdateDropTargets || isBlocksDragTargetDebug()) {
|
|
246
|
-
var _meta$activeNode2;
|
|
247
|
-
const {
|
|
248
|
-
decs,
|
|
249
|
-
decorationState: updatedDecorationState
|
|
250
|
-
} = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 ? void 0 : (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType);
|
|
251
|
-
decorationState = updatedDecorationState;
|
|
252
|
-
decorations = decorations.add(newState.doc, decs);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
//Map drop target decoration positions when the document changes
|
|
257
|
-
if (shouldMapDropTargets) {
|
|
258
|
-
decorationState = decorationState.map(({
|
|
259
|
-
id,
|
|
260
|
-
pos
|
|
261
|
-
}) => {
|
|
262
|
-
return {
|
|
263
|
-
id,
|
|
264
|
-
pos: tr.mapping.map(pos)
|
|
265
|
-
};
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
if (api) {
|
|
270
|
-
// Add drop targets when node is being dragged
|
|
271
|
-
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
272
|
-
const shouldShowDragTarget = (meta === null || meta === void 0 ? void 0 : meta.isDragging) && (!tr.docChanged || tr.docChanged && isAnalyticTr);
|
|
273
|
-
if (shouldShowDragTarget || isBlocksDragTargetDebug()) {
|
|
274
|
-
var _meta$activeNode3;
|
|
275
|
-
const {
|
|
276
|
-
decs,
|
|
277
|
-
decorationState: updatedDecorationState
|
|
278
|
-
} = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 ? void 0 : (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.nodeType);
|
|
279
|
-
decorationState = updatedDecorationState;
|
|
280
|
-
decorations = decorations.add(newState.doc, decs);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
215
|
+
const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
216
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
284
217
|
// Remove drop target decoration when dragging stops
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
218
|
+
const dropTargetDecs = decorations.find().filter(({
|
|
219
|
+
spec
|
|
220
|
+
}) => spec.type === 'drop-target-decoration');
|
|
221
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
222
|
+
}
|
|
223
|
+
if (api) {
|
|
224
|
+
// Add drop targets when node is being dragged
|
|
225
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
226
|
+
if (shouldUpdateDropTargets || isBlocksDragTargetDebug()) {
|
|
227
|
+
var _meta$activeNode2;
|
|
228
|
+
const {
|
|
229
|
+
decs,
|
|
230
|
+
decorationState: updatedDecorationState
|
|
231
|
+
} = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 ? void 0 : (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType);
|
|
232
|
+
decorationState = updatedDecorationState;
|
|
233
|
+
decorations = decorations.add(newState.doc, decs);
|
|
290
234
|
}
|
|
235
|
+
}
|
|
291
236
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
237
|
+
//Map drop target decoration positions when the document changes
|
|
238
|
+
if (shouldMapDropTargets) {
|
|
239
|
+
decorationState = decorationState.map(({
|
|
240
|
+
id,
|
|
241
|
+
pos
|
|
242
|
+
}) => {
|
|
243
|
+
return {
|
|
295
244
|
id,
|
|
296
|
-
pos
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
id,
|
|
300
|
-
pos: tr.mapping.map(pos)
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
}
|
|
245
|
+
pos: tr.mapping.map(pos)
|
|
246
|
+
};
|
|
247
|
+
});
|
|
304
248
|
}
|
|
305
249
|
|
|
306
250
|
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
@@ -316,24 +260,15 @@ export const createPlugin = (api, getIntl) => {
|
|
|
316
260
|
}
|
|
317
261
|
|
|
318
262
|
// Map active node position when the document changes
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
nodeType: activeNode.nodeType
|
|
325
|
-
} : activeNode;
|
|
326
|
-
} else {
|
|
327
|
-
mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
328
|
-
pos: tr.mapping.map(activeNode.pos),
|
|
329
|
-
anchorName: activeNode.anchorName,
|
|
330
|
-
nodeType: activeNode.nodeType
|
|
331
|
-
} : activeNode;
|
|
332
|
-
}
|
|
263
|
+
const mappedActiveNodePos = tr.docChanged && activeNode ? activeNodeWithNewNodeType || {
|
|
264
|
+
pos: tr.mapping.map(activeNode.pos),
|
|
265
|
+
anchorName: activeNode.anchorName,
|
|
266
|
+
nodeType: activeNode.nodeType
|
|
267
|
+
} : activeNode;
|
|
333
268
|
return {
|
|
334
269
|
decorations,
|
|
335
270
|
decorationState,
|
|
336
|
-
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$
|
|
271
|
+
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$activeNode3 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode3 !== void 0 ? _meta$activeNode3 : mappedActiveNodePos,
|
|
337
272
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
|
|
338
273
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
339
274
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jsxRuntime classic
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
|
-
import { useCallback, useEffect,
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
6
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
7
7
|
import { css, jsx } from '@emotion/react';
|
|
8
8
|
import { bind } from 'bind-event-listener';
|
|
@@ -108,7 +108,7 @@ const DragHandleInternal = ({
|
|
|
108
108
|
});
|
|
109
109
|
const resolvedMovingNode = tr.doc.resolve(startPos);
|
|
110
110
|
const maybeNode = resolvedMovingNode.nodeAfter;
|
|
111
|
-
|
|
111
|
+
tr.setMeta('scrollIntoView', false);
|
|
112
112
|
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
|
|
113
113
|
eventType: EVENT_TYPE.UI,
|
|
114
114
|
action: ACTION.CLICKED,
|
|
@@ -271,13 +271,10 @@ const DragHandleInternal = ({
|
|
|
271
271
|
top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
|
|
272
272
|
};
|
|
273
273
|
}, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
|
|
274
|
-
const [
|
|
274
|
+
const [positionStyles, setPositionStyles] = useState({
|
|
275
275
|
display: 'none'
|
|
276
276
|
});
|
|
277
277
|
useEffect(() => {
|
|
278
|
-
if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
278
|
let cleanUpTransitionListener;
|
|
282
279
|
if (nodeType === 'extension' || nodeType === 'embedCard') {
|
|
283
280
|
const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
|
|
@@ -287,12 +284,12 @@ const DragHandleInternal = ({
|
|
|
287
284
|
cleanUpTransitionListener = bind(dom, {
|
|
288
285
|
type: 'transitionend',
|
|
289
286
|
listener: () => {
|
|
290
|
-
|
|
287
|
+
setPositionStyles(calculatePosition());
|
|
291
288
|
}
|
|
292
289
|
});
|
|
293
290
|
}
|
|
294
291
|
const calcPos = requestAnimationFrame(() => {
|
|
295
|
-
|
|
292
|
+
setPositionStyles(calculatePosition());
|
|
296
293
|
});
|
|
297
294
|
return () => {
|
|
298
295
|
var _cleanUpTransitionLis;
|
|
@@ -300,12 +297,6 @@ const DragHandleInternal = ({
|
|
|
300
297
|
(_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 ? void 0 : _cleanUpTransitionLis();
|
|
301
298
|
};
|
|
302
299
|
}, [calculatePosition, view.dom, anchorName, nodeType]);
|
|
303
|
-
const positionStyles = useMemo(() => {
|
|
304
|
-
if (fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
305
|
-
return newPositionStyles;
|
|
306
|
-
}
|
|
307
|
-
return calculatePosition();
|
|
308
|
-
}, [calculatePosition, newPositionStyles]);
|
|
309
300
|
useEffect(() => {
|
|
310
301
|
if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
311
302
|
const id = requestAnimationFrame(() => {
|
|
@@ -338,7 +329,7 @@ const DragHandleInternal = ({
|
|
|
338
329
|
ref: buttonRef
|
|
339
330
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
340
331
|
,
|
|
341
|
-
style:
|
|
332
|
+
style: positionStyles,
|
|
342
333
|
onClick: handleOnClick,
|
|
343
334
|
onMouseDown: handleMouseDown,
|
|
344
335
|
onKeyDown: handleKeyDown,
|
|
@@ -7,7 +7,6 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
7
7
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
8
|
import { css, jsx } from '@emotion/react';
|
|
9
9
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
10
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
10
|
import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
|
|
12
11
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
13
12
|
import { layers } from '@atlaskit/theme/constants';
|
|
@@ -40,9 +39,6 @@ const getNodeMargins = node => {
|
|
|
40
39
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
41
40
|
};
|
|
42
41
|
const getDropTargetPositionStyle = (prevNode, nextNode) => {
|
|
43
|
-
if (!fg('platform_editor_drag_and_drop_target_gap_fix')) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
42
|
if (!prevNode || !nextNode) {
|
|
47
43
|
return null;
|
|
48
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
2
|
const IS_GEMINI_TEST_ENV = Boolean(process.env.NODE_ENV === 'development') && Boolean(window.__gemini_set_feature_flag__);
|
|
3
3
|
export const isBlocksDragTargetDebug = () => {
|
|
4
|
-
return IS_GEMINI_TEST_ENV && fg('
|
|
4
|
+
return IS_GEMINI_TEST_ENV && fg('platform_editor_element_drag_and_drop_debug');
|
|
5
5
|
};
|