@atlaskit/editor-plugin-block-controls 1.10.3 → 1.10.5
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 +20 -0
- package/dist/cjs/pm-plugins/decorations.js +6 -53
- package/dist/cjs/pm-plugins/main.js +45 -102
- package/dist/cjs/ui/drag-handle.js +19 -44
- package/dist/cjs/ui/drag-preview.js +1 -4
- package/dist/cjs/ui/global-styles.js +1 -1
- package/dist/cjs/utils/getSelection.js +8 -21
- package/dist/es2019/pm-plugins/decorations.js +5 -52
- package/dist/es2019/pm-plugins/main.js +44 -101
- package/dist/es2019/ui/drag-handle.js +13 -39
- package/dist/es2019/ui/drag-preview.js +1 -4
- package/dist/es2019/ui/global-styles.js +1 -1
- package/dist/es2019/utils/getSelection.js +8 -21
- package/dist/esm/pm-plugins/decorations.js +5 -52
- package/dist/esm/pm-plugins/main.js +46 -103
- package/dist/esm/ui/drag-handle.js +19 -44
- package/dist/esm/ui/drag-preview.js +1 -4
- package/dist/esm/ui/global-styles.js +1 -1
- package/dist/esm/utils/getSelection.js +8 -21
- package/dist/types/pm-plugins/decorations.d.ts +0 -6
- package/dist/types/pm-plugins/main.d.ts +1 -14
- package/dist/types/types.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -6
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -14
- package/dist/types-ts4.5/types.d.ts +4 -0
- package/package.json +2 -17
- package/dist/cjs/ui/mouse-move-wrapper.js +0 -148
- package/dist/es2019/ui/mouse-move-wrapper.js +0 -133
- package/dist/esm/ui/mouse-move-wrapper.js +0 -140
- package/dist/types/ui/mouse-move-wrapper.d.ts +0 -11
- package/dist/types-ts4.5/ui/mouse-move-wrapper.d.ts +0 -11
|
@@ -10,7 +10,7 @@ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-sc
|
|
|
10
10
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
11
11
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
12
12
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
13
|
-
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations,
|
|
13
|
+
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, nodeDecorations } from './decorations';
|
|
14
14
|
import { handleMouseOver } from './handle-mouse-over';
|
|
15
15
|
import { boundKeydownHandler } from './keymap';
|
|
16
16
|
export const key = new PluginKey('blockControls');
|
|
@@ -79,7 +79,6 @@ const initialState = {
|
|
|
79
79
|
isDocSizeLimitEnabled: null,
|
|
80
80
|
isPMDragging: false
|
|
81
81
|
};
|
|
82
|
-
const DRAG_AND_DROP_DOC_SIZE_LIMIT = 50;
|
|
83
82
|
export const createPlugin = (api, getIntl) => {
|
|
84
83
|
return new SafePlugin({
|
|
85
84
|
key,
|
|
@@ -89,16 +88,6 @@ export const createPlugin = (api, getIntl) => {
|
|
|
89
88
|
},
|
|
90
89
|
apply(tr, currentState, oldState, newState) {
|
|
91
90
|
var _meta$activeNode, _meta$activeNode$hand, _meta$activeNode4, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
92
|
-
if (initialState.isDocSizeLimitEnabled === null) {
|
|
93
|
-
if (fg('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
|
|
94
|
-
initialState.isDocSizeLimitEnabled = true;
|
|
95
|
-
} else {
|
|
96
|
-
initialState.isDocSizeLimitEnabled = false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (initialState.isDocSizeLimitEnabled && newState.doc.childCount > DRAG_AND_DROP_DOC_SIZE_LIMIT) {
|
|
100
|
-
return initialState;
|
|
101
|
-
}
|
|
102
91
|
let {
|
|
103
92
|
activeNode,
|
|
104
93
|
decorations,
|
|
@@ -136,21 +125,18 @@ export const createPlugin = (api, getIntl) => {
|
|
|
136
125
|
decorations = decorations.remove(oldHandle);
|
|
137
126
|
}
|
|
138
127
|
let isDecsMissing = false;
|
|
139
|
-
let isHandleMissing = false;
|
|
140
128
|
let isDropTargetsMissing = false;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}) => spec.id !== 'drag-handle').length;
|
|
129
|
+
// Ensure decorations stay in sync when nodes are added or removed from the doc
|
|
130
|
+
const isHandleMissing = !(meta !== null && meta !== void 0 && meta.activeNode) && !decorations.find().some(({
|
|
131
|
+
spec
|
|
132
|
+
}) => spec.id === 'drag-handle');
|
|
133
|
+
const decsLength = decorations.find().filter(({
|
|
134
|
+
spec
|
|
135
|
+
}) => spec.id !== 'drag-handle').length;
|
|
149
136
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
137
|
+
//TODO: Fix this logic for nested scenarios
|
|
138
|
+
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
139
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
154
140
|
}
|
|
155
141
|
if (fg('platform_editor_element_drag_and_drop_ed_24372')) {
|
|
156
142
|
const dropTargetLen = decorations.find().filter(({
|
|
@@ -189,12 +175,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
189
175
|
decorations = DecorationSet.create(newState.doc, []);
|
|
190
176
|
}
|
|
191
177
|
const nodeDecs = nodeDecorations(newState);
|
|
192
|
-
|
|
193
|
-
decorations = decorations.add(newState.doc, [...nodeDecs]);
|
|
194
|
-
} else {
|
|
195
|
-
const mouseWrapperDecs = mouseMoveWrapperDecorations(newState, api);
|
|
196
|
-
decorations = decorations.add(newState.doc, [...nodeDecs, ...mouseWrapperDecs]);
|
|
197
|
-
}
|
|
178
|
+
decorations = decorations.add(newState.doc, [...nodeDecs]);
|
|
198
179
|
|
|
199
180
|
// Note: Quite often the handle is not in the right position after a node is moved
|
|
200
181
|
// it is safer for now to not show it when a node is moved
|
|
@@ -375,6 +356,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
375
356
|
},
|
|
376
357
|
handleDOMEvents: {
|
|
377
358
|
drop(view, event) {
|
|
359
|
+
var _event$target;
|
|
378
360
|
// prosemirror has sends a default transaction on drop (meta where uiEvent is 'drop'),
|
|
379
361
|
// this duplicates an empty version of the node it was dropping,
|
|
380
362
|
// Adding some check here to prevent that if drop position is within activeNode
|
|
@@ -395,18 +377,13 @@ export const createPlugin = (api, getIntl) => {
|
|
|
395
377
|
// Currently we can only drag one node at a time
|
|
396
378
|
// so we only need to check first child
|
|
397
379
|
const draggable = dragging === null || dragging === void 0 ? void 0 : dragging.slice.content.firstChild;
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
var _event$target;
|
|
402
|
-
const nodeElement = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.closest('[data-drag-handler-anchor-name]');
|
|
403
|
-
if (!nodeElement) {
|
|
404
|
-
return false;
|
|
405
|
-
}
|
|
406
|
-
const domPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? Math.max(view.posAtDOM(nodeElement, 0) - 1, 0) : view.posAtDOM(nodeElement, 0) - 1;
|
|
407
|
-
const nodeTarget = state.doc.nodeAt(domPos);
|
|
408
|
-
isSameNode = !!(nodeTarget && draggable !== null && draggable !== void 0 && draggable.eq(nodeTarget));
|
|
380
|
+
const nodeElement = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.closest('[data-drag-handler-anchor-name]');
|
|
381
|
+
if (!nodeElement) {
|
|
382
|
+
return false;
|
|
409
383
|
}
|
|
384
|
+
const domPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? Math.max(view.posAtDOM(nodeElement, 0) - 1, 0) : view.posAtDOM(nodeElement, 0) - 1;
|
|
385
|
+
const nodeTarget = state.doc.nodeAt(domPos);
|
|
386
|
+
const isSameNode = !!(nodeTarget && draggable !== null && draggable !== void 0 && draggable.eq(nodeTarget));
|
|
410
387
|
if (isSameNode) {
|
|
411
388
|
// Prevent the default drop behavior if the position is within the activeNode
|
|
412
389
|
event.preventDefault();
|
|
@@ -432,9 +409,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
432
409
|
}
|
|
433
410
|
},
|
|
434
411
|
mouseover: (view, event) => {
|
|
435
|
-
|
|
436
|
-
handleMouseOver(view, event, api);
|
|
437
|
-
}
|
|
412
|
+
handleMouseOver(view, event, api);
|
|
438
413
|
return false;
|
|
439
414
|
},
|
|
440
415
|
keydown(view, event) {
|
|
@@ -469,74 +444,42 @@ export const createPlugin = (api, getIntl) => {
|
|
|
469
444
|
view: editorView => {
|
|
470
445
|
const dom = editorView.dom;
|
|
471
446
|
const editorContentArea = editorView.dom.closest('.fabric-editor-popup-scroll-parent');
|
|
472
|
-
let resizeObserverHeight;
|
|
473
|
-
let resizeObserverWidth;
|
|
474
|
-
if (!fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
475
|
-
// Use ResizeObserver to observe height changes
|
|
476
|
-
resizeObserverHeight = new ResizeObserver(rafSchedule(entries => {
|
|
477
|
-
var _entries$, _entries$$contentBoxS;
|
|
478
|
-
const editorHeight = (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : (_entries$$contentBoxS = _entries$.contentBoxSize[0]) === null || _entries$$contentBoxS === void 0 ? void 0 : _entries$$contentBoxS.blockSize;
|
|
479
447
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
448
|
+
// Use ResizeObserver to observe width changes
|
|
449
|
+
const resizeObserverWidth = new ResizeObserver(rafSchedule(entries => {
|
|
450
|
+
const editorContentArea = entries[0].target;
|
|
451
|
+
const editorWidthRight = editorContentArea.getBoundingClientRect().right;
|
|
452
|
+
const editorWidthLeft = editorContentArea.getBoundingClientRect().left;
|
|
453
|
+
|
|
454
|
+
// Update the plugin state when the height changes
|
|
455
|
+
const pluginState = key.getState(editorView.state);
|
|
456
|
+
if (!(pluginState !== null && pluginState !== void 0 && pluginState.isDragging)) {
|
|
457
|
+
const isResizerResizing = !!dom.querySelector('.is-resizing');
|
|
458
|
+
const transaction = editorView.state.tr;
|
|
459
|
+
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.isResizerResizing) !== isResizerResizing) {
|
|
460
|
+
transaction.setMeta('is-resizer-resizing', isResizerResizing);
|
|
461
|
+
}
|
|
462
|
+
if (!isResizerResizing) {
|
|
463
|
+
if (fg('platform_editor_elements_drag_and_drop_ed_23394')) {
|
|
489
464
|
transaction.setMeta(key, {
|
|
490
|
-
|
|
465
|
+
editorWidthLeft,
|
|
466
|
+
editorWidthRight
|
|
491
467
|
});
|
|
492
468
|
}
|
|
493
|
-
editorView.dispatch(transaction);
|
|
494
469
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
// Start observing the editor DOM element
|
|
498
|
-
resizeObserverHeight.observe(dom);
|
|
499
|
-
}
|
|
500
|
-
if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
501
|
-
// Use ResizeObserver to observe width changes
|
|
502
|
-
resizeObserverWidth = new ResizeObserver(rafSchedule(entries => {
|
|
503
|
-
const editorContentArea = entries[0].target;
|
|
504
|
-
const editorWidthRight = editorContentArea.getBoundingClientRect().right;
|
|
505
|
-
const editorWidthLeft = editorContentArea.getBoundingClientRect().left;
|
|
506
|
-
|
|
507
|
-
// Update the plugin state when the height changes
|
|
508
|
-
const pluginState = key.getState(editorView.state);
|
|
509
|
-
if (!(pluginState !== null && pluginState !== void 0 && pluginState.isDragging)) {
|
|
510
|
-
const isResizerResizing = !!dom.querySelector('.is-resizing');
|
|
511
|
-
const transaction = editorView.state.tr;
|
|
512
|
-
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.isResizerResizing) !== isResizerResizing) {
|
|
513
|
-
transaction.setMeta('is-resizer-resizing', isResizerResizing);
|
|
514
|
-
}
|
|
515
|
-
if (!isResizerResizing) {
|
|
516
|
-
if (fg('platform_editor_elements_drag_and_drop_ed_23394')) {
|
|
517
|
-
transaction.setMeta(key, {
|
|
518
|
-
editorWidthLeft,
|
|
519
|
-
editorWidthRight
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
editorView.dispatch(transaction);
|
|
524
|
-
}
|
|
525
|
-
}));
|
|
526
|
-
if (editorContentArea && fg('platform_editor_elements_drag_and_drop_ed_23394')) {
|
|
527
|
-
resizeObserverWidth.observe(editorContentArea);
|
|
470
|
+
editorView.dispatch(transaction);
|
|
528
471
|
}
|
|
472
|
+
}));
|
|
473
|
+
if (editorContentArea && fg('platform_editor_elements_drag_and_drop_ed_23394')) {
|
|
474
|
+
resizeObserverWidth.observe(editorContentArea);
|
|
529
475
|
}
|
|
530
476
|
|
|
531
477
|
// Start pragmatic monitors
|
|
532
478
|
const pragmaticCleanup = destroyFn(api);
|
|
533
479
|
return {
|
|
534
480
|
destroy() {
|
|
535
|
-
if (
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
if (editorContentArea && fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
539
|
-
fg('platform_editor_elements_drag_and_drop_ed_23394') && resizeObserverWidth.unobserve(editorContentArea);
|
|
481
|
+
if (editorContentArea && fg('platform_editor_elements_drag_and_drop_ed_23394')) {
|
|
482
|
+
resizeObserverWidth.unobserve(editorContentArea);
|
|
540
483
|
}
|
|
541
484
|
pragmaticCleanup();
|
|
542
485
|
}
|
|
@@ -68,7 +68,7 @@ const DragHandleInternal = ({
|
|
|
68
68
|
},
|
|
69
69
|
handleOptions
|
|
70
70
|
}) => {
|
|
71
|
-
var _api$core2, _api$analytics2, _api$
|
|
71
|
+
var _api$core2, _api$analytics2, _api$core4, _api$core6;
|
|
72
72
|
const start = getPos();
|
|
73
73
|
const buttonRef = useRef(null);
|
|
74
74
|
const [blockCardWidth, setBlockCardWidth] = useState(768);
|
|
@@ -124,32 +124,12 @@ const DragHandleInternal = ({
|
|
|
124
124
|
view.focus();
|
|
125
125
|
}, [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, start, nodeType]);
|
|
126
126
|
|
|
127
|
-
// handleMouseDown required along with onClick to ensure the correct selection
|
|
128
|
-
// is set immediately when the drag handle is clicked. Otherwise browser native
|
|
129
|
-
// drag and drop can take over and cause unpredictable behaviour.
|
|
130
|
-
const handleMouseDown = useCallback(() => {
|
|
131
|
-
var _api$core3;
|
|
132
|
-
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
|
|
133
|
-
tr
|
|
134
|
-
}) => {
|
|
135
|
-
if (start === undefined) {
|
|
136
|
-
return tr;
|
|
137
|
-
}
|
|
138
|
-
tr = selectNode(tr, start, nodeType);
|
|
139
|
-
tr.setMeta(key, {
|
|
140
|
-
pos: start
|
|
141
|
-
});
|
|
142
|
-
return tr;
|
|
143
|
-
});
|
|
144
|
-
view.focus();
|
|
145
|
-
}, [start, api, view, nodeType]);
|
|
146
|
-
|
|
147
127
|
// TODO - This needs to be investigated further. Drag preview generation is not always working
|
|
148
128
|
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
149
129
|
// but ensures the preview is generated correctly.
|
|
150
|
-
const
|
|
151
|
-
var _api$
|
|
152
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
130
|
+
const handleMouseDown = useCallback(() => {
|
|
131
|
+
var _api$core3;
|
|
132
|
+
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
|
|
153
133
|
tr
|
|
154
134
|
}) => {
|
|
155
135
|
const startPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
@@ -168,15 +148,15 @@ const DragHandleInternal = ({
|
|
|
168
148
|
});
|
|
169
149
|
return tr;
|
|
170
150
|
});
|
|
171
|
-
}, [api === null || api === void 0 ? void 0 : (_api$
|
|
151
|
+
}, [api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos, start]);
|
|
172
152
|
const handleKeyDown = useCallback(e => {
|
|
173
153
|
if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
174
154
|
// allow user to use spacebar to select the node
|
|
175
155
|
|
|
176
156
|
if (!e.repeat && e.key === ' ') {
|
|
177
|
-
var _api$
|
|
157
|
+
var _api$core5;
|
|
178
158
|
const startPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
179
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
159
|
+
api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
|
|
180
160
|
tr
|
|
181
161
|
}) => {
|
|
182
162
|
if (startPos === undefined) {
|
|
@@ -200,7 +180,7 @@ const DragHandleInternal = ({
|
|
|
200
180
|
view.focus();
|
|
201
181
|
}
|
|
202
182
|
}
|
|
203
|
-
}, [getPos, start, api === null || api === void 0 ? void 0 : (_api$
|
|
183
|
+
}, [getPos, start, api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, view]);
|
|
204
184
|
useEffect(() => {
|
|
205
185
|
const element = buttonRef.current;
|
|
206
186
|
if (!element) {
|
|
@@ -229,11 +209,11 @@ const DragHandleInternal = ({
|
|
|
229
209
|
});
|
|
230
210
|
},
|
|
231
211
|
onDragStart() {
|
|
232
|
-
var _api$
|
|
212
|
+
var _api$core7;
|
|
233
213
|
if (start === undefined) {
|
|
234
214
|
return;
|
|
235
215
|
}
|
|
236
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
216
|
+
api === null || api === void 0 ? void 0 : (_api$core7 = api.core) === null || _api$core7 === void 0 ? void 0 : _api$core7.actions.execute(({
|
|
237
217
|
tr
|
|
238
218
|
}) => {
|
|
239
219
|
var _api$blockControls, _api$analytics3;
|
|
@@ -281,20 +261,14 @@ const DragHandleInternal = ({
|
|
|
281
261
|
}
|
|
282
262
|
}
|
|
283
263
|
if (supportsAnchor) {
|
|
284
|
-
return
|
|
264
|
+
return {
|
|
285
265
|
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? `calc(anchor(${anchorName} start) + ${getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates)})` : `calc(anchor(${anchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType)}px)`,
|
|
286
266
|
top: fg('platform_editor_elements_dnd_ed_23674') ? `calc(anchor(${anchorName} start) + ${topPositionAdjustment(nodeType)}px)` : anchorName.includes('table') ? `calc(anchor(${anchorName} start) + ${DRAG_HANDLE_HEIGHT}px)` : `anchor(${anchorName} start)`
|
|
287
|
-
} : {
|
|
288
|
-
left: hasResizer || isExtension || isBlockCard || isEmbedCard ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : `calc(anchor(${anchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType)}px)`,
|
|
289
|
-
top: fg('platform_editor_elements_dnd_ed_23674') ? `calc(anchor(${anchorName} start) + ${topPositionAdjustment(nodeType)}px)` : anchorName.includes('table') ? `calc(anchor(${anchorName} start) + ${DRAG_HANDLE_HEIGHT}px)` : `anchor(${anchorName} start)`
|
|
290
267
|
};
|
|
291
268
|
}
|
|
292
|
-
return
|
|
269
|
+
return {
|
|
293
270
|
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? `calc(${(dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0}px + ${getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates)})` : getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
|
|
294
271
|
top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
|
|
295
|
-
} : {
|
|
296
|
-
left: getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
|
|
297
|
-
top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
|
|
298
272
|
};
|
|
299
273
|
}, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
|
|
300
274
|
const [newPositionStyles, setNewPositionStyles] = useState({
|
|
@@ -366,7 +340,7 @@ const DragHandleInternal = ({
|
|
|
366
340
|
,
|
|
367
341
|
style: fg('platform_editor_element_drag_and_drop_ed_23896') ? newPositionStyles : positionStyles,
|
|
368
342
|
onClick: handleOnClick,
|
|
369
|
-
onMouseDown:
|
|
343
|
+
onMouseDown: handleMouseDown,
|
|
370
344
|
onKeyDown: handleKeyDown,
|
|
371
345
|
"data-testid": "block-ctrl-drag-handle"
|
|
372
346
|
}, jsx(DragHandlerIcon, {
|
|
@@ -13,10 +13,7 @@ export const dragPreview = (container, dom, nodeType) => {
|
|
|
13
13
|
container.style.pointerEvents = 'none';
|
|
14
14
|
const parent = document.createElement('div');
|
|
15
15
|
// ProseMirror class is required to make sure the cloned dom is styled correctly
|
|
16
|
-
parent.classList.add('ProseMirror');
|
|
17
|
-
if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
18
|
-
parent.classList.add('block-ctrl-drag-preview');
|
|
19
|
-
}
|
|
16
|
+
parent.classList.add('ProseMirror', 'block-ctrl-drag-preview');
|
|
20
17
|
const embedCard = dom.querySelector('.embedCardView-content-wrap');
|
|
21
18
|
let shouldBeGenericPreview = nodeType === 'embedCard' || nodeType === 'extension' || !!embedCard;
|
|
22
19
|
if (fg('platform_editor_elements_drag_and_drop_ed_23189')) {
|
|
@@ -134,6 +134,6 @@ const getTextNodeStyle = () => {
|
|
|
134
134
|
};
|
|
135
135
|
export const GlobalStylesWrapper = () => {
|
|
136
136
|
return jsx(Global, {
|
|
137
|
-
styles: [globalStyles, fg('
|
|
137
|
+
styles: [globalStyles, fg('platform_editor_elements_dnd_nested') ? extendedHoverZoneNested : extendedHoverZone, getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix]
|
|
138
138
|
});
|
|
139
139
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
export const getSelection = (tr, start) => {
|
|
5
4
|
const node = tr.doc.nodeAt(start);
|
|
6
5
|
const isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
@@ -16,7 +15,7 @@ export const getSelection = (tr, start) => {
|
|
|
16
15
|
} else if (
|
|
17
16
|
// Even though mediaGroup is not selectable,
|
|
18
17
|
// we need a quick way to make all child media nodes appear as selected without the need for a custom selection
|
|
19
|
-
(node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup'
|
|
18
|
+
(node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup') {
|
|
20
19
|
return new NodeSelection($startPos);
|
|
21
20
|
} else {
|
|
22
21
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
@@ -25,28 +24,16 @@ export const getSelection = (tr, start) => {
|
|
|
25
24
|
let foundInlineNode = false;
|
|
26
25
|
let inlineNodeEndPos = 0;
|
|
27
26
|
tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, (n, pos) => {
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
foundInlineNode = true;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
if (foundInlineNode) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (n.isInline) {
|
|
41
|
-
inlineNodePos = pos;
|
|
42
|
-
foundInlineNode = true;
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
27
|
+
if (n.isInline) {
|
|
28
|
+
inlineNodeEndPos = pos + n.nodeSize;
|
|
29
|
+
}
|
|
30
|
+
if (n.isInline && !foundInlineNode) {
|
|
31
|
+
inlineNodePos = pos;
|
|
32
|
+
foundInlineNode = true;
|
|
45
33
|
}
|
|
46
34
|
return true;
|
|
47
35
|
});
|
|
48
|
-
|
|
49
|
-
return new TextSelection(tr.doc.resolve(fg('platform.editor.elements.drag-and-drop-ed-23905') ? inlineNodeEndPos : start + nodeSize - inlineNodeDepth), tr.doc.resolve(inlineNodePos));
|
|
36
|
+
return new TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
|
|
50
37
|
}
|
|
51
38
|
};
|
|
52
39
|
export const selectNode = (tr, start, nodeType) => {
|
|
@@ -7,7 +7,6 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
7
7
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
8
|
import { DragHandle } from '../ui/drag-handle';
|
|
9
9
|
import { DropTarget } from '../ui/drop-target';
|
|
10
|
-
import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
|
|
11
10
|
import { canMoveToIndex } from '../utils/validation';
|
|
12
11
|
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
13
12
|
var NESTED_DEPTH = fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
@@ -131,14 +130,8 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
131
130
|
} else {
|
|
132
131
|
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
133
132
|
}
|
|
134
|
-
var style;
|
|
135
|
-
if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
136
|
-
style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;");
|
|
137
|
-
} else {
|
|
138
|
-
style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '');
|
|
139
|
-
}
|
|
140
133
|
decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
141
|
-
style:
|
|
134
|
+
style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;")
|
|
142
135
|
}, _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), _defineProperty(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node2), {
|
|
143
136
|
type: 'node-decoration'
|
|
144
137
|
}));
|
|
@@ -146,45 +139,6 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
146
139
|
});
|
|
147
140
|
return decs;
|
|
148
141
|
};
|
|
149
|
-
/**
|
|
150
|
-
* Setting up decorations around each node to track mousemove events into each node
|
|
151
|
-
* When a mouseenter event is triggered on the node, we will set the activeNode to the node
|
|
152
|
-
* And show the drag handle
|
|
153
|
-
*/
|
|
154
|
-
export var mouseMoveWrapperDecorations = function mouseMoveWrapperDecorations(newState, api) {
|
|
155
|
-
var decs = [];
|
|
156
|
-
unmountDecorations('data-blocks-decoration-container');
|
|
157
|
-
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
158
|
-
// Do not render a mouse move wrapper for nodes that have wrapping - this causes wrapping to break
|
|
159
|
-
var hasWrapping = node.attrs.layout === 'wrap-left' || node.attrs.layout === 'wrap-right';
|
|
160
|
-
if (hasWrapping) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
164
|
-
decs.push(Decoration.widget(pos, function (view, getPos) {
|
|
165
|
-
var element = document.createElement('div');
|
|
166
|
-
element.setAttribute('data-blocks-decoration-container', 'true');
|
|
167
|
-
element.setAttribute('style', 'clear: unset;');
|
|
168
|
-
ReactDOM.render( /*#__PURE__*/createElement(MouseMoveWrapper, {
|
|
169
|
-
view: view,
|
|
170
|
-
api: api,
|
|
171
|
-
anchorName: anchorName,
|
|
172
|
-
nodeType: node.type.name,
|
|
173
|
-
getPos: getPos
|
|
174
|
-
}), element);
|
|
175
|
-
return element;
|
|
176
|
-
}, {
|
|
177
|
-
type: 'mouse-move-wrapper',
|
|
178
|
-
side: -1,
|
|
179
|
-
ignoreSelection: true,
|
|
180
|
-
stopEvent: function stopEvent(e) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
}));
|
|
184
|
-
return false;
|
|
185
|
-
});
|
|
186
|
-
return decs;
|
|
187
|
-
};
|
|
188
142
|
export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, pos, anchorName, nodeType, handleOptions) {
|
|
189
143
|
var unbind;
|
|
190
144
|
var elementType = fg('platform_editor_element_drag_and_drop_ed_24150') ? 'span' : 'div';
|
|
@@ -205,11 +159,10 @@ export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, po
|
|
|
205
159
|
if (fg('platform_editor_element_drag_and_drop_ed_23896')) {
|
|
206
160
|
unmountDecorations('data-blocks-drag-handle-container');
|
|
207
161
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
162
|
+
|
|
163
|
+
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
164
|
+
// due to margins applied to other nodes eg. Headings
|
|
165
|
+
element.style.clear = 'unset';
|
|
213
166
|
ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
|
|
214
167
|
value: getIntl()
|
|
215
168
|
}, /*#__PURE__*/createElement(DragHandle, {
|