@atlaskit/editor-plugin-block-controls 1.10.5 → 1.10.7
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 +18 -0
- package/dist/cjs/pm-plugins/decorations.js +9 -14
- package/dist/cjs/pm-plugins/main.js +56 -116
- package/dist/cjs/ui/drag-handle.js +6 -14
- 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 +9 -14
- package/dist/es2019/pm-plugins/main.js +52 -111
- package/dist/es2019/ui/drag-handle.js +6 -14
- 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 +9 -14
- package/dist/esm/pm-plugins/main.js +56 -116
- package/dist/esm/ui/drag-handle.js +7 -15
- package/dist/esm/ui/drop-target.js +0 -4
- package/dist/esm/utils/drag-target-debug.js +1 -1
- package/package.json +6 -22
|
@@ -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
|
|
@@ -216,91 +207,50 @@ export const createPlugin = (api, getIntl) => {
|
|
|
216
207
|
const decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
217
208
|
decorations = decorations.add(newState.doc, [decs]);
|
|
218
209
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
decorations = decorations.add(newState.doc, [decs]);
|
|
229
|
-
}
|
|
210
|
+
|
|
211
|
+
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
212
|
+
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
213
|
+
const oldHandle = decorations.find().filter(({
|
|
214
|
+
spec
|
|
215
|
+
}) => spec.id === 'drag-handle');
|
|
216
|
+
decorations = decorations.remove(oldHandle);
|
|
217
|
+
const decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
218
|
+
decorations = decorations.add(newState.doc, [decs]);
|
|
230
219
|
}
|
|
231
220
|
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
|
-
|
|
221
|
+
const shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
222
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
284
223
|
// Remove drop target decoration when dragging stops
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
224
|
+
const dropTargetDecs = decorations.find().filter(({
|
|
225
|
+
spec
|
|
226
|
+
}) => spec.type === 'drop-target-decoration');
|
|
227
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
228
|
+
}
|
|
229
|
+
if (api) {
|
|
230
|
+
// Add drop targets when node is being dragged
|
|
231
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
232
|
+
if (shouldUpdateDropTargets || isBlocksDragTargetDebug()) {
|
|
233
|
+
var _meta$activeNode2;
|
|
234
|
+
const {
|
|
235
|
+
decs,
|
|
236
|
+
decorationState: updatedDecorationState
|
|
237
|
+
} = 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);
|
|
238
|
+
decorationState = updatedDecorationState;
|
|
239
|
+
decorations = decorations.add(newState.doc, decs);
|
|
290
240
|
}
|
|
241
|
+
}
|
|
291
242
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
243
|
+
//Map drop target decoration positions when the document changes
|
|
244
|
+
if (shouldMapDropTargets) {
|
|
245
|
+
decorationState = decorationState.map(({
|
|
246
|
+
id,
|
|
247
|
+
pos
|
|
248
|
+
}) => {
|
|
249
|
+
return {
|
|
295
250
|
id,
|
|
296
|
-
pos
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
id,
|
|
300
|
-
pos: tr.mapping.map(pos)
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
}
|
|
251
|
+
pos: tr.mapping.map(pos)
|
|
252
|
+
};
|
|
253
|
+
});
|
|
304
254
|
}
|
|
305
255
|
|
|
306
256
|
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
@@ -316,24 +266,15 @@ export const createPlugin = (api, getIntl) => {
|
|
|
316
266
|
}
|
|
317
267
|
|
|
318
268
|
// 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
|
-
}
|
|
269
|
+
const mappedActiveNodePos = tr.docChanged && activeNode ? activeNodeWithNewNodeType || {
|
|
270
|
+
pos: tr.mapping.map(activeNode.pos),
|
|
271
|
+
anchorName: activeNode.anchorName,
|
|
272
|
+
nodeType: activeNode.nodeType
|
|
273
|
+
} : activeNode;
|
|
333
274
|
return {
|
|
334
275
|
decorations,
|
|
335
276
|
decorationState,
|
|
336
|
-
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$
|
|
277
|
+
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$activeNode3 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode3 !== void 0 ? _meta$activeNode3 : mappedActiveNodePos,
|
|
337
278
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
|
|
338
279
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
339
280
|
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';
|
|
@@ -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,
|
|
@@ -351,6 +342,7 @@ const DragHandleInternal = ({
|
|
|
351
342
|
content: jsx(TooltipContentWithMultipleShortcuts, {
|
|
352
343
|
helpDescriptors: helpDescriptors
|
|
353
344
|
}),
|
|
345
|
+
ignoreTooltipPointerEvents: true,
|
|
354
346
|
onShow: () => {
|
|
355
347
|
var _api$accessibilityUti;
|
|
356
348
|
api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify(message, {
|
|
@@ -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
|
};
|
|
@@ -8,7 +8,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
8
8
|
import { DragHandle } from '../ui/drag-handle';
|
|
9
9
|
import { DropTarget } from '../ui/drop-target';
|
|
10
10
|
import { canMoveToIndex } from '../utils/validation';
|
|
11
|
-
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
11
|
+
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem'];
|
|
12
|
+
var IGNORE_NODES_AND_DESCENDANTS = ['listItem'];
|
|
12
13
|
var NESTED_DEPTH = fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
13
14
|
export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api, formatMessage, activeNodeType) {
|
|
14
15
|
var decs = [];
|
|
@@ -17,8 +18,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
17
18
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
18
19
|
var decorationState = [];
|
|
19
20
|
var prevNode;
|
|
20
|
-
|
|
21
|
-
state.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos, parent, index) {
|
|
21
|
+
newState.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos, parent, index) {
|
|
22
22
|
var depth = 0;
|
|
23
23
|
var nodeType = newState.doc.type.schema.nodes[activeNodeType];
|
|
24
24
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
@@ -114,12 +114,13 @@ export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecoration
|
|
|
114
114
|
};
|
|
115
115
|
export var nodeDecorations = function nodeDecorations(newState) {
|
|
116
116
|
var decs = [];
|
|
117
|
-
newState.doc.descendants(function (node, pos,
|
|
117
|
+
newState.doc.descendants(function (node, pos, parent, index) {
|
|
118
118
|
var _Decoration$node2;
|
|
119
119
|
var depth = 0;
|
|
120
120
|
var anchorName;
|
|
121
121
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
122
|
-
|
|
122
|
+
// Doesn't descend into a node
|
|
123
|
+
if (node.isInline || IGNORE_NODES_AND_DESCENDANTS.includes((parent === null || parent === void 0 ? void 0 : parent.type.name) || '')) {
|
|
123
124
|
return false;
|
|
124
125
|
}
|
|
125
126
|
if (IGNORE_NODES.includes(node.type.name)) {
|
|
@@ -141,9 +142,8 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
141
142
|
};
|
|
142
143
|
export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, pos, anchorName, nodeType, handleOptions) {
|
|
143
144
|
var unbind;
|
|
144
|
-
var elementType = fg('platform_editor_element_drag_and_drop_ed_24150') ? 'span' : 'div';
|
|
145
145
|
return Decoration.widget(pos, function (view, getPos) {
|
|
146
|
-
var element = document.createElement(
|
|
146
|
+
var element = document.createElement('span');
|
|
147
147
|
// Need to set it to inline to avoid text being split when merging two paragraphs
|
|
148
148
|
element.style.display = 'inline';
|
|
149
149
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
@@ -156,9 +156,7 @@ export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, po
|
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
unmountDecorations('data-blocks-drag-handle-container');
|
|
161
|
-
}
|
|
159
|
+
unmountDecorations('data-blocks-drag-handle-container');
|
|
162
160
|
|
|
163
161
|
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
164
162
|
// due to margins applied to other nodes eg. Headings
|
|
@@ -177,13 +175,10 @@ export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, po
|
|
|
177
175
|
}, {
|
|
178
176
|
side: -1,
|
|
179
177
|
id: 'drag-handle',
|
|
180
|
-
destroy: function destroy(
|
|
178
|
+
destroy: function destroy() {
|
|
181
179
|
if (fg('platform_editor_elements_dnd_nested')) {
|
|
182
180
|
unbind && unbind();
|
|
183
181
|
}
|
|
184
|
-
if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
185
|
-
ReactDOM.unmountComponentAtNode(node);
|
|
186
|
-
}
|
|
187
182
|
}
|
|
188
183
|
});
|
|
189
184
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import rafSchedule from 'raf-schd';
|
|
3
|
-
import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
|
|
4
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
5
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
5
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
@@ -86,7 +85,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
86
85
|
return initialState;
|
|
87
86
|
},
|
|
88
87
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
89
|
-
var _meta$activeNode, _meta$activeNode$hand, _meta$
|
|
88
|
+
var _meta$activeNode, _meta$activeNode$hand, _activeNodeWithNewNod, _meta$activeNode3, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
90
89
|
var activeNode = currentState.activeNode,
|
|
91
90
|
decorations = currentState.decorations,
|
|
92
91
|
isMenuOpen = currentState.isMenuOpen,
|
|
@@ -99,20 +98,12 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
99
98
|
isPMDragging = currentState.isPMDragging;
|
|
100
99
|
var activeNodeWithNewNodeType = null;
|
|
101
100
|
var meta = tr.getMeta(key);
|
|
102
|
-
// when creating analytics during drag/drop events, PM thinks the doc has changed
|
|
103
|
-
// so tr.docChange is true and causes some decorations to not render
|
|
104
|
-
var isAnalyticTr = tr.steps.every(function (step) {
|
|
105
|
-
return step instanceof AnalyticsStep;
|
|
106
|
-
});
|
|
107
101
|
|
|
108
102
|
// If tables or media are being resized, we want to hide the drag handle
|
|
109
103
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
110
104
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
111
105
|
var nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
112
|
-
var shouldRemoveHandle =
|
|
113
|
-
if (fg('platform_editor_elements_drag_and_drop_ed_24000')) {
|
|
114
|
-
shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
115
|
-
}
|
|
106
|
+
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
116
107
|
|
|
117
108
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
118
109
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
@@ -140,16 +131,14 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
140
131
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
141
132
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}).length;
|
|
134
|
+
var dropTargetLen = decorations.find().filter(function (_ref8) {
|
|
135
|
+
var spec = _ref8.spec;
|
|
136
|
+
return spec.type === 'drop-target-decoration';
|
|
137
|
+
}).length;
|
|
148
138
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
139
|
+
//TODO: Fix this logic for nested scenarios
|
|
140
|
+
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
141
|
+
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
153
142
|
}
|
|
154
143
|
|
|
155
144
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
@@ -220,90 +209,50 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
220
209
|
var decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
221
210
|
decorations = decorations.add(newState.doc, [decs]);
|
|
222
211
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
decorations = decorations.add(newState.doc, [_decs]);
|
|
234
|
-
}
|
|
212
|
+
|
|
213
|
+
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
214
|
+
if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
215
|
+
var _oldHandle2 = decorations.find().filter(function (_ref11) {
|
|
216
|
+
var spec = _ref11.spec;
|
|
217
|
+
return spec.id === 'drag-handle';
|
|
218
|
+
});
|
|
219
|
+
decorations = decorations.remove(_oldHandle2);
|
|
220
|
+
var _decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
221
|
+
decorations = decorations.add(newState.doc, [_decs]);
|
|
235
222
|
}
|
|
236
223
|
var shouldUpdateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
237
|
-
var shouldMapDropTargets = false;
|
|
238
|
-
if (
|
|
239
|
-
shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
240
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
241
|
-
// Remove drop target decoration when dragging stops
|
|
242
|
-
var dropTargetDecs = decorations.find().filter(function (_ref12) {
|
|
243
|
-
var spec = _ref12.spec;
|
|
244
|
-
return spec.type === 'drop-target-decoration';
|
|
245
|
-
});
|
|
246
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
247
|
-
}
|
|
248
|
-
if (api) {
|
|
249
|
-
// Add drop targets when node is being dragged
|
|
250
|
-
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
251
|
-
if (shouldUpdateDropTargets || isBlocksDragTargetDebug()) {
|
|
252
|
-
var _meta$activeNode2;
|
|
253
|
-
var _dropTargetDecoration = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType),
|
|
254
|
-
_decs2 = _dropTargetDecoration.decs,
|
|
255
|
-
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
256
|
-
decorationState = updatedDecorationState;
|
|
257
|
-
decorations = decorations.add(newState.doc, _decs2);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
//Map drop target decoration positions when the document changes
|
|
262
|
-
if (shouldMapDropTargets) {
|
|
263
|
-
decorationState = decorationState.map(function (_ref13) {
|
|
264
|
-
var id = _ref13.id,
|
|
265
|
-
pos = _ref13.pos;
|
|
266
|
-
return {
|
|
267
|
-
id: id,
|
|
268
|
-
pos: tr.mapping.map(pos)
|
|
269
|
-
};
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
if (api) {
|
|
274
|
-
// Add drop targets when node is being dragged
|
|
275
|
-
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
276
|
-
var shouldShowDragTarget = (meta === null || meta === void 0 ? void 0 : meta.isDragging) && (!tr.docChanged || tr.docChanged && isAnalyticTr);
|
|
277
|
-
if (shouldShowDragTarget || isBlocksDragTargetDebug()) {
|
|
278
|
-
var _meta$activeNode3;
|
|
279
|
-
var _dropTargetDecoration2 = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.nodeType),
|
|
280
|
-
_decs3 = _dropTargetDecoration2.decs,
|
|
281
|
-
_updatedDecorationState = _dropTargetDecoration2.decorationState;
|
|
282
|
-
decorationState = _updatedDecorationState;
|
|
283
|
-
decorations = decorations.add(newState.doc, _decs3);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
224
|
+
var shouldMapDropTargets = !shouldUpdateDropTargets && tr.docChanged && isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
225
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
287
226
|
// Remove drop target decoration when dragging stops
|
|
288
|
-
|
|
289
|
-
var
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
227
|
+
var dropTargetDecs = decorations.find().filter(function (_ref12) {
|
|
228
|
+
var spec = _ref12.spec;
|
|
229
|
+
return spec.type === 'drop-target-decoration';
|
|
230
|
+
});
|
|
231
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
232
|
+
}
|
|
233
|
+
if (api) {
|
|
234
|
+
// Add drop targets when node is being dragged
|
|
235
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
236
|
+
if (shouldUpdateDropTargets || isBlocksDragTargetDebug()) {
|
|
237
|
+
var _meta$activeNode2;
|
|
238
|
+
var _dropTargetDecoration = dropTargetDecorations(oldState, newState, api, formatMessage, meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType),
|
|
239
|
+
_decs2 = _dropTargetDecoration.decs,
|
|
240
|
+
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
241
|
+
decorationState = updatedDecorationState;
|
|
242
|
+
decorations = decorations.add(newState.doc, _decs2);
|
|
294
243
|
}
|
|
244
|
+
}
|
|
295
245
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
246
|
+
//Map drop target decoration positions when the document changes
|
|
247
|
+
if (shouldMapDropTargets) {
|
|
248
|
+
decorationState = decorationState.map(function (_ref13) {
|
|
249
|
+
var id = _ref13.id,
|
|
250
|
+
pos = _ref13.pos;
|
|
251
|
+
return {
|
|
252
|
+
id: id,
|
|
253
|
+
pos: tr.mapping.map(pos)
|
|
254
|
+
};
|
|
255
|
+
});
|
|
307
256
|
}
|
|
308
257
|
|
|
309
258
|
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
@@ -311,8 +260,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
311
260
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
312
261
|
}
|
|
313
262
|
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
314
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
315
|
-
var spec =
|
|
263
|
+
var hasNodeDecoration = decorations.find().some(function (_ref14) {
|
|
264
|
+
var spec = _ref14.spec;
|
|
316
265
|
return spec.type === 'node-decoration';
|
|
317
266
|
});
|
|
318
267
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -320,24 +269,15 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
320
269
|
}
|
|
321
270
|
|
|
322
271
|
// Map active node position when the document changes
|
|
323
|
-
var mappedActiveNodePos
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
nodeType: activeNode.nodeType
|
|
329
|
-
} : activeNode;
|
|
330
|
-
} else {
|
|
331
|
-
mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
332
|
-
pos: tr.mapping.map(activeNode.pos),
|
|
333
|
-
anchorName: activeNode.anchorName,
|
|
334
|
-
nodeType: activeNode.nodeType
|
|
335
|
-
} : activeNode;
|
|
336
|
-
}
|
|
272
|
+
var mappedActiveNodePos = tr.docChanged && activeNode ? activeNodeWithNewNodeType || {
|
|
273
|
+
pos: tr.mapping.map(activeNode.pos),
|
|
274
|
+
anchorName: activeNode.anchorName,
|
|
275
|
+
nodeType: activeNode.nodeType
|
|
276
|
+
} : activeNode;
|
|
337
277
|
return {
|
|
338
278
|
decorations: decorations,
|
|
339
279
|
decorationState: decorationState,
|
|
340
|
-
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$
|
|
280
|
+
activeNode: isEmptyDoc || isHandleMissing ? null : (_meta$activeNode3 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode3 !== void 0 ? _meta$activeNode3 : mappedActiveNodePos,
|
|
341
281
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging,
|
|
342
282
|
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
343
283
|
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|