@atlaskit/editor-plugin-block-controls 11.2.9 → 11.2.11
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 +14 -0
- package/dist/cjs/editor-commands/move-node.js +12 -32
- package/dist/cjs/editor-commands/move-to-layout.js +59 -127
- package/dist/cjs/pm-plugins/decorations-drop-target-active.js +11 -16
- package/dist/cjs/pm-plugins/decorations-drop-target.js +13 -24
- package/dist/cjs/pm-plugins/main.js +51 -88
- package/dist/cjs/pm-plugins/utils/analytics.js +1 -2
- package/dist/cjs/pm-plugins/utils/remove-from-source.js +4 -14
- package/dist/cjs/ui/drag-handle.js +32 -44
- package/dist/es2019/editor-commands/move-node.js +9 -31
- package/dist/es2019/editor-commands/move-to-layout.js +61 -121
- package/dist/es2019/pm-plugins/decorations-drop-target-active.js +11 -16
- package/dist/es2019/pm-plugins/decorations-drop-target.js +13 -24
- package/dist/es2019/pm-plugins/main.js +55 -91
- package/dist/es2019/pm-plugins/utils/analytics.js +1 -2
- package/dist/es2019/pm-plugins/utils/remove-from-source.js +4 -14
- package/dist/es2019/ui/drag-handle.js +32 -45
- package/dist/esm/editor-commands/move-node.js +13 -33
- package/dist/esm/editor-commands/move-to-layout.js +59 -127
- package/dist/esm/pm-plugins/decorations-drop-target-active.js +11 -16
- package/dist/esm/pm-plugins/decorations-drop-target.js +13 -24
- package/dist/esm/pm-plugins/main.js +51 -88
- package/dist/esm/pm-plugins/utils/analytics.js +1 -2
- package/dist/esm/pm-plugins/utils/remove-from-source.js +4 -14
- package/dist/esm/ui/drag-handle.js +32 -44
- package/dist/types/pm-plugins/main.d.ts +0 -1
- package/dist/types/pm-plugins/utils/analytics.d.ts +2 -2
- package/dist/types/pm-plugins/utils/remove-from-source.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -1
- package/dist/types-ts4.5/pm-plugins/utils/analytics.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/utils/remove-from-source.d.ts +1 -1
- package/editor-plugin-block-controls.docs.tsx +38 -0
- package/package.json +4 -3
|
@@ -5,18 +5,8 @@ import { isFragmentOfType } from './check-fragment';
|
|
|
5
5
|
import { MIN_LAYOUT_COLUMN } from './consts';
|
|
6
6
|
import { updateColumnWidths } from './update-column-widths';
|
|
7
7
|
export const removeFromSource = (tr, $from, to) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let isLayoutColumn = ((_sourceContent = sourceContent) === null || _sourceContent === void 0 ? void 0 : _sourceContent.type.name) === 'layoutColumn';
|
|
11
|
-
let sourceNodeEndPos = $from.pos + (((_sourceContent2 = sourceContent) === null || _sourceContent2 === void 0 ? void 0 : _sourceContent2.nodeSize) || 1);
|
|
12
|
-
if (editorExperiment('platform_editor_element_drag_and_drop_multiselect', true)) {
|
|
13
|
-
sourceContent = tr.doc.slice($from.pos, to).content;
|
|
14
|
-
isLayoutColumn = isFragmentOfType(sourceContent, 'layoutColumn');
|
|
15
|
-
sourceNodeEndPos = to === undefined ? $from.pos + sourceContent.size : to;
|
|
16
|
-
}
|
|
17
|
-
if (!sourceContent) {
|
|
18
|
-
return tr;
|
|
19
|
-
}
|
|
8
|
+
const sourceContent = tr.doc.slice($from.pos, to).content;
|
|
9
|
+
const isLayoutColumn = isFragmentOfType(sourceContent, 'layoutColumn');
|
|
20
10
|
|
|
21
11
|
/**
|
|
22
12
|
* This logic is used to handle the case when a user tries to delete a layout column
|
|
@@ -29,7 +19,7 @@ export const removeFromSource = (tr, $from, to) => {
|
|
|
29
19
|
// Only delete the layout content, but keep the layout column itself
|
|
30
20
|
// This logic should be remove when we clean up the code for single column layouts.
|
|
31
21
|
// since this step has no effect on the layout column, because the parent node is removed in the later step.
|
|
32
|
-
tr.delete($from.pos + 1,
|
|
22
|
+
tr.delete($from.pos + 1, to - 1);
|
|
33
23
|
|
|
34
24
|
// This check should be remove when clean up the code for single column layouts.
|
|
35
25
|
// since it has been checked in the previous step.
|
|
@@ -52,6 +42,6 @@ export const removeFromSource = (tr, $from, to) => {
|
|
|
52
42
|
updateColumnWidths(tr, $from.parent, $from.before($from.depth), sourceParent.childCount - 1);
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
|
-
tr.delete($from.pos,
|
|
45
|
+
tr.delete($from.pos, to);
|
|
56
46
|
return tr;
|
|
57
47
|
};
|
|
@@ -370,7 +370,6 @@ export const DragHandle = ({
|
|
|
370
370
|
});
|
|
371
371
|
const start = getPos();
|
|
372
372
|
const isLayoutColumn = nodeType === 'layoutColumn';
|
|
373
|
-
const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
374
373
|
|
|
375
374
|
// Dynamically calculate if node is top-level based on current position (gated by experiment)
|
|
376
375
|
const isTopLevelNodeDynamic = useMemo(() => {
|
|
@@ -449,7 +448,7 @@ export const DragHandle = ({
|
|
|
449
448
|
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
450
449
|
attributes: {
|
|
451
450
|
nodeDepth: resolvedStartPos.depth,
|
|
452
|
-
|
|
451
|
+
nodeTypes: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
453
452
|
}
|
|
454
453
|
})(tr);
|
|
455
454
|
expandAndUpdateSelection({
|
|
@@ -481,9 +480,6 @@ export const DragHandle = ({
|
|
|
481
480
|
}, [api, view, getPos, nodeType, anchorName]);
|
|
482
481
|
const handleOnClick = useCallback(e => {
|
|
483
482
|
var _api$core2;
|
|
484
|
-
if (!isMultiSelect) {
|
|
485
|
-
setDragHandleSelected(!dragHandleSelected);
|
|
486
|
-
}
|
|
487
483
|
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
|
|
488
484
|
tr
|
|
489
485
|
}) => {
|
|
@@ -494,7 +490,7 @@ export const DragHandle = ({
|
|
|
494
490
|
}
|
|
495
491
|
const mSelect = api === null || api === void 0 ? void 0 : (_api$blockControls$sh = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.multiSelectDnD;
|
|
496
492
|
const $anchor = (mSelect === null || mSelect === void 0 ? void 0 : mSelect.anchor) !== undefined ? tr.doc.resolve(mSelect === null || mSelect === void 0 ? void 0 : mSelect.anchor) : tr.selection.$anchor;
|
|
497
|
-
if (
|
|
493
|
+
if (tr.selection.empty || !e.shiftKey) {
|
|
498
494
|
tr = selectNode(tr, startPos, nodeType, api);
|
|
499
495
|
} else if (isTopLevelNodeValue && $anchor.depth <= DRAG_HANDLE_MAX_SHIFT_CLICK_DEPTH && e.shiftKey && fg('platform_editor_elements_dnd_shift_click_select')) {
|
|
500
496
|
var _api$blockControls3;
|
|
@@ -515,13 +511,13 @@ export const DragHandle = ({
|
|
|
515
511
|
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
516
512
|
attributes: {
|
|
517
513
|
nodeDepth: resolvedMovingNode.depth,
|
|
518
|
-
|
|
514
|
+
nodeTypes: (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name) || ''
|
|
519
515
|
}
|
|
520
516
|
})(tr);
|
|
521
517
|
return tr;
|
|
522
518
|
});
|
|
523
519
|
view.focus();
|
|
524
|
-
}, [
|
|
520
|
+
}, [api, view, getPos, isTopLevelNodeValue, nodeType]);
|
|
525
521
|
const handleKeyDown = useCallback(e => {
|
|
526
522
|
// allow user to use spacebar to select the node
|
|
527
523
|
if (!e.repeat && e.key === ' ') {
|
|
@@ -540,9 +536,6 @@ export const DragHandle = ({
|
|
|
540
536
|
const $startPos = tr.doc.resolve(startPos + node.nodeSize);
|
|
541
537
|
const selection = new TextSelection($startPos);
|
|
542
538
|
tr.setSelection(selection);
|
|
543
|
-
!isMultiSelect && tr.setMeta(key, {
|
|
544
|
-
pos: startPos
|
|
545
|
-
});
|
|
546
539
|
return tr;
|
|
547
540
|
});
|
|
548
541
|
} else if (![e.altKey, e.ctrlKey, e.shiftKey].some(pressed => pressed)) {
|
|
@@ -550,7 +543,7 @@ export const DragHandle = ({
|
|
|
550
543
|
// return focus to editor to resume editing from caret position
|
|
551
544
|
view.focus();
|
|
552
545
|
}
|
|
553
|
-
}, [getPos, api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions,
|
|
546
|
+
}, [getPos, api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, view]);
|
|
554
547
|
const handleKeyDownNew = useCallback(e => {
|
|
555
548
|
// allow user to use spacebar to select the node
|
|
556
549
|
if (e.key === 'Enter' || !e.repeat && e.key === ' ') {
|
|
@@ -619,28 +612,25 @@ export const DragHandle = ({
|
|
|
619
612
|
onGenerateDragPreview: ({
|
|
620
613
|
nativeSetDragImage
|
|
621
614
|
}) => {
|
|
622
|
-
var _api$blockControls$sh2;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
const handlePos = getPos();
|
|
629
|
-
if (typeof handlePos !== 'number') {
|
|
630
|
-
return tr;
|
|
631
|
-
}
|
|
632
|
-
const newHandlePosCheck = isHandleCorrelatedToSelection(view.state, tr.selection, handlePos);
|
|
633
|
-
if (!tr.selection.empty && newHandlePosCheck) {
|
|
634
|
-
var _api$blockControls6;
|
|
635
|
-
api === null || api === void 0 ? void 0 : (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 ? void 0 : _api$blockControls6.commands.setMultiSelectPositions()({
|
|
636
|
-
tr
|
|
637
|
-
});
|
|
638
|
-
} else {
|
|
639
|
-
tr = selectNode(tr, handlePos, nodeType, api);
|
|
640
|
-
}
|
|
615
|
+
var _api$core6, _api$blockControls$sh2;
|
|
616
|
+
api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.execute(({
|
|
617
|
+
tr
|
|
618
|
+
}) => {
|
|
619
|
+
const handlePos = getPos();
|
|
620
|
+
if (typeof handlePos !== 'number') {
|
|
641
621
|
return tr;
|
|
642
|
-
}
|
|
643
|
-
|
|
622
|
+
}
|
|
623
|
+
const newHandlePosCheck = isHandleCorrelatedToSelection(view.state, tr.selection, handlePos);
|
|
624
|
+
if (!tr.selection.empty && newHandlePosCheck) {
|
|
625
|
+
var _api$blockControls6;
|
|
626
|
+
api === null || api === void 0 ? void 0 : (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 ? void 0 : _api$blockControls6.commands.setMultiSelectPositions()({
|
|
627
|
+
tr
|
|
628
|
+
});
|
|
629
|
+
} else {
|
|
630
|
+
tr = selectNode(tr, handlePos, nodeType, api);
|
|
631
|
+
}
|
|
632
|
+
return tr;
|
|
633
|
+
});
|
|
644
634
|
const startPos = getPos();
|
|
645
635
|
const state = view.state;
|
|
646
636
|
const {
|
|
@@ -659,7 +649,7 @@ export const DragHandle = ({
|
|
|
659
649
|
sliceTo = Math.max(anchor, head);
|
|
660
650
|
}
|
|
661
651
|
const expandedSlice = doc.slice(sliceFrom, sliceTo);
|
|
662
|
-
const isDraggingMultiLine =
|
|
652
|
+
const isDraggingMultiLine = startPos !== undefined && startPos >= sliceFrom && startPos < sliceTo && expandedSlice.content.childCount > 1;
|
|
663
653
|
setCustomNativeDragPreview({
|
|
664
654
|
getOffset: () => {
|
|
665
655
|
if (!isDraggingMultiLine) {
|
|
@@ -771,11 +761,8 @@ export const DragHandle = ({
|
|
|
771
761
|
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
772
762
|
attributes: {
|
|
773
763
|
nodeDepth: resolvedMovingNode.depth,
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
nodeTypes,
|
|
777
|
-
hasSelectedMultipleNodes
|
|
778
|
-
})
|
|
764
|
+
nodeTypes: nodeTypes || '',
|
|
765
|
+
hasSelectedMultipleNodes
|
|
779
766
|
}
|
|
780
767
|
})(tr);
|
|
781
768
|
return tr;
|
|
@@ -783,7 +770,7 @@ export const DragHandle = ({
|
|
|
783
770
|
view.focus();
|
|
784
771
|
}
|
|
785
772
|
});
|
|
786
|
-
}, [anchorName, api, getPos,
|
|
773
|
+
}, [anchorName, api, getPos, nodeType, start, view]);
|
|
787
774
|
const calculatePositionOld = useCallback(() => {
|
|
788
775
|
const pos = getPos();
|
|
789
776
|
const $pos = expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? typeof pos === 'number' && view.state.doc.resolve(pos) : pos && view.state.doc.resolve(pos);
|
|
@@ -868,14 +855,14 @@ export const DragHandle = ({
|
|
|
868
855
|
}
|
|
869
856
|
}, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
|
|
870
857
|
useEffect(() => {
|
|
871
|
-
if (
|
|
858
|
+
if (typeof start !== 'number' || !selection) {
|
|
872
859
|
return;
|
|
873
860
|
}
|
|
874
861
|
setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
|
|
875
|
-
}, [start, selection, view
|
|
862
|
+
}, [start, selection, view]);
|
|
876
863
|
useEffect(() => {
|
|
877
864
|
var _api$blockControls$sh4;
|
|
878
|
-
if (
|
|
865
|
+
if (isShiftDown === undefined || view.state.selection.empty || !fg('platform_editor_elements_dnd_shift_click_select')) {
|
|
879
866
|
return;
|
|
880
867
|
}
|
|
881
868
|
const mSelect = api === null || api === void 0 ? void 0 : (_api$blockControls$sh4 = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh4 === void 0 ? void 0 : _api$blockControls$sh4.multiSelectDnD;
|
|
@@ -885,7 +872,7 @@ export const DragHandle = ({
|
|
|
885
872
|
} else {
|
|
886
873
|
setDragHandleDisabled(false);
|
|
887
874
|
}
|
|
888
|
-
}, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState,
|
|
875
|
+
}, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isShiftDown, isTopLevelNodeValue, view]);
|
|
889
876
|
const dragHandleMessage = editorExperiment('platform_editor_block_menu', true) ? formatMessage(blockControlsMessages.dragToMoveClickToOpen, {
|
|
890
877
|
br: jsx("br", null)
|
|
891
878
|
}) : formatMessage(blockControlsMessages.dragToMove);
|
|
@@ -963,7 +950,7 @@ export const DragHandle = ({
|
|
|
963
950
|
return descriptor.keymap ? [descriptor.description, getAriaKeyshortcuts(descriptor.keymap)] : [descriptor.description];
|
|
964
951
|
}).join('. ');
|
|
965
952
|
const handleOnDrop = event => {
|
|
966
|
-
|
|
953
|
+
event.stopPropagation();
|
|
967
954
|
};
|
|
968
955
|
const hasHadInteraction = interactionState !== 'hasNotHadInteraction';
|
|
969
956
|
const browser = getBrowserInfo();
|
|
@@ -18,7 +18,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
18
18
|
import { key } from '../pm-plugins/main';
|
|
19
19
|
import { attachMoveNodeAnalytics, getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
|
|
20
20
|
import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
|
|
21
|
-
import {
|
|
21
|
+
import { setCursorPositionAtMovedNode } from '../pm-plugins/utils/getSelection';
|
|
22
22
|
import { removeFromSource } from '../pm-plugins/utils/remove-from-source';
|
|
23
23
|
import { getSelectedSlicePosition } from '../pm-plugins/utils/selection';
|
|
24
24
|
import { getInsertLayoutStep, updateSelection } from '../pm-plugins/utils/update-selection';
|
|
@@ -120,7 +120,6 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
120
120
|
return function (state) {
|
|
121
121
|
var selection = state.selection;
|
|
122
122
|
var isParentNodeOfTypeLayout = !!findParentNodeOfType([state.schema.nodes.layoutSection])(state.selection);
|
|
123
|
-
var isMultiSelectEnabled = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
124
123
|
var expandedSelection = expandSelectionBounds(selection.$anchor, selection.$head);
|
|
125
124
|
var expandedAnchor = expandedSelection.$anchor.pos;
|
|
126
125
|
var expandedHead = expandedSelection.$head.pos;
|
|
@@ -131,11 +130,11 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
131
130
|
var LAYOUT_COL_DEPTH = 3;
|
|
132
131
|
hoistedPos = state.doc.resolve(from).before(LAYOUT_COL_DEPTH);
|
|
133
132
|
}
|
|
134
|
-
var currentNodePos =
|
|
133
|
+
var currentNodePos = !getFocusedHandle(state) && !selection.empty ? hoistedPos !== null && hoistedPos !== void 0 ? hoistedPos : from : getCurrentNodePos(state);
|
|
135
134
|
if (currentNodePos > -1) {
|
|
136
135
|
var _state$doc$nodeAt;
|
|
137
136
|
var $currentNodePos = state.doc.resolve(currentNodePos);
|
|
138
|
-
var nodeAfterPos =
|
|
137
|
+
var nodeAfterPos = !getFocusedHandle(state) ? Math.max(expandedAnchor, expandedHead) : $currentNodePos.posAtIndex($currentNodePos.index() + 1);
|
|
139
138
|
var isTopLevelNode = $currentNodePos.depth === 0;
|
|
140
139
|
var moveToPos = -1;
|
|
141
140
|
var isLayoutColumnSelected = selection instanceof NodeSelection && selection.node.type.name === 'layoutColumn';
|
|
@@ -276,20 +275,10 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
276
275
|
return tr;
|
|
277
276
|
});
|
|
278
277
|
return true;
|
|
279
|
-
} else
|
|
278
|
+
} else {
|
|
280
279
|
var _api$core8;
|
|
281
|
-
// If the node is first/last one, only select the node
|
|
282
280
|
api === null || api === void 0 || (_api$core8 = api.core) === null || _api$core8 === void 0 || _api$core8.actions.execute(function (_ref5) {
|
|
283
281
|
var tr = _ref5.tr;
|
|
284
|
-
selectNode(tr, currentNodePos, nodeType, api);
|
|
285
|
-
tr.scrollIntoView();
|
|
286
|
-
return tr;
|
|
287
|
-
});
|
|
288
|
-
return true;
|
|
289
|
-
} else if (isMultiSelectEnabled) {
|
|
290
|
-
var _api$core9;
|
|
291
|
-
api === null || api === void 0 || (_api$core9 = api.core) === null || _api$core9 === void 0 || _api$core9.actions.execute(function (_ref6) {
|
|
292
|
-
var tr = _ref6.tr;
|
|
293
282
|
api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions($newAnchor.pos, $newHead.pos)({
|
|
294
283
|
tr: tr
|
|
295
284
|
});
|
|
@@ -306,9 +295,9 @@ export var moveNode = function moveNode(api) {
|
|
|
306
295
|
return function (start, to) {
|
|
307
296
|
var inputMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INPUT_METHOD.DRAG_AND_DROP;
|
|
308
297
|
var formatMessage = arguments.length > 3 ? arguments[3] : undefined;
|
|
309
|
-
return function (
|
|
298
|
+
return function (_ref6) {
|
|
310
299
|
var _api$blockControls$sh, _convertedNodeSlice, _api$accessibilityUti;
|
|
311
|
-
var tr =
|
|
300
|
+
var tr = _ref6.tr;
|
|
312
301
|
if (!api || start < 0 || to < 0) {
|
|
313
302
|
return tr;
|
|
314
303
|
}
|
|
@@ -319,7 +308,6 @@ export var moveNode = function moveNode(api) {
|
|
|
319
308
|
var sliceFrom = start;
|
|
320
309
|
var sliceTo;
|
|
321
310
|
var sourceNodeTypes, hasSelectedMultipleNodes;
|
|
322
|
-
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
323
311
|
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
324
312
|
var _api$metrics;
|
|
325
313
|
api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.setContentMoved()({
|
|
@@ -335,17 +323,13 @@ export var moveNode = function moveNode(api) {
|
|
|
335
323
|
var attributes = getMultiSelectAnalyticsAttributes(tr, sliceFrom, sliceTo);
|
|
336
324
|
hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
|
|
337
325
|
sourceNodeTypes = attributes.nodeTypes;
|
|
338
|
-
} else
|
|
326
|
+
} else {
|
|
339
327
|
var slicePosition = getSelectedSlicePosition(start, tr, api);
|
|
340
328
|
sliceFrom = slicePosition.from;
|
|
341
329
|
sliceTo = slicePosition.to;
|
|
342
330
|
var _attributes = getMultiSelectAnalyticsAttributes(tr, sliceFrom, sliceTo);
|
|
343
331
|
hasSelectedMultipleNodes = _attributes.hasSelectedMultipleNodes;
|
|
344
332
|
sourceNodeTypes = _attributes.nodeTypes;
|
|
345
|
-
} else {
|
|
346
|
-
var _handleNode$nodeSize;
|
|
347
|
-
var size = (_handleNode$nodeSize = handleNode === null || handleNode === void 0 ? void 0 : handleNode.nodeSize) !== null && _handleNode$nodeSize !== void 0 ? _handleNode$nodeSize : 1;
|
|
348
|
-
sliceTo = sliceFrom + size;
|
|
349
333
|
}
|
|
350
334
|
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
|
|
351
335
|
expand = _tr$doc$type$schema$n.expand,
|
|
@@ -422,13 +406,11 @@ export var moveNode = function moveNode(api) {
|
|
|
422
406
|
tr.setMeta(key, _objectSpread(_objectSpread({}, _currMeta), {}, {
|
|
423
407
|
preservedSelectionMapping: new Mapping([new StepMap([0, 0, nodeMovedOffset])])
|
|
424
408
|
}));
|
|
425
|
-
} else
|
|
409
|
+
} else {
|
|
426
410
|
var _api$blockControls$co;
|
|
427
411
|
tr = (_api$blockControls$co = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
|
|
428
412
|
tr: tr
|
|
429
413
|
})) !== null && _api$blockControls$co !== void 0 ? _api$blockControls$co : tr;
|
|
430
|
-
} else {
|
|
431
|
-
tr = selectNode(tr, mappedTo, handleNode.type.name, api);
|
|
432
414
|
}
|
|
433
415
|
var currMeta = tr.getMeta(key);
|
|
434
416
|
tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
@@ -449,7 +431,7 @@ export var moveNode = function moveNode(api) {
|
|
|
449
431
|
}
|
|
450
432
|
}
|
|
451
433
|
if (editorExperiment('advanced_layouts', true)) {
|
|
452
|
-
attachMoveNodeAnalytics(tr, inputMethod, $handlePos.depth,
|
|
434
|
+
attachMoveNodeAnalytics(tr, inputMethod, $handlePos.depth, sourceNodeTypes, $mappedTo === null || $mappedTo === void 0 ? void 0 : $mappedTo.depth, $mappedTo === null || $mappedTo === void 0 ? void 0 : $mappedTo.parent.type.name, $handlePos.sameParent($mappedTo), api, hasSelectedMultipleNodes);
|
|
453
435
|
} else {
|
|
454
436
|
var _api$analytics;
|
|
455
437
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
@@ -457,16 +439,14 @@ export var moveNode = function moveNode(api) {
|
|
|
457
439
|
action: ACTION.MOVED,
|
|
458
440
|
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
459
441
|
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
460
|
-
attributes:
|
|
442
|
+
attributes: {
|
|
461
443
|
nodeDepth: $handlePos.depth,
|
|
462
|
-
|
|
444
|
+
nodeTypes: sourceNodeTypes,
|
|
463
445
|
destinationNodeDepth: $mappedTo === null || $mappedTo === void 0 ? void 0 : $mappedTo.depth,
|
|
464
446
|
destinationNodeType: $mappedTo === null || $mappedTo === void 0 ? void 0 : $mappedTo.parent.type.name,
|
|
465
|
-
inputMethod: inputMethod
|
|
466
|
-
}, isMultiSelect && {
|
|
467
|
-
sourceNodeTypes: sourceNodeTypes,
|
|
447
|
+
inputMethod: inputMethod,
|
|
468
448
|
hasSelectedMultipleNodes: hasSelectedMultipleNodes
|
|
469
|
-
}
|
|
449
|
+
}
|
|
470
450
|
})(tr);
|
|
471
451
|
}
|
|
472
452
|
var movedMessage = to > sliceFrom ? blockControlsMessages.movedDown : blockControlsMessages.movedup;
|
|
@@ -40,26 +40,11 @@ var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
|
40
40
|
};
|
|
41
41
|
var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos, sourceContent, from, to, tr, $originalFrom, $originalTo, api, selectMovedNode) {
|
|
42
42
|
var isSameLayout = isInSameLayout($originalFrom, $originalTo);
|
|
43
|
-
var sourceContentEndPos =
|
|
44
|
-
var
|
|
45
|
-
var sourceNodeTypes,
|
|
46
|
-
|
|
47
|
-
if (sourceContent instanceof Fragment) {
|
|
48
|
-
sourceContentEndPos = from + sourceContent.size;
|
|
49
|
-
var attributes = getMultiSelectAnalyticsAttributes(tr, from, sourceContentEndPos);
|
|
50
|
-
hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
|
|
51
|
-
sourceNodeTypes = attributes.nodeTypes;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
if (sourceContent instanceof PMNode) {
|
|
55
|
-
sourceContentEndPos = from + sourceContent.nodeSize;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (sourceContentEndPos === -1) {
|
|
59
|
-
return tr;
|
|
60
|
-
}
|
|
43
|
+
var sourceContentEndPos = from + sourceContent.size;
|
|
44
|
+
var attributes = getMultiSelectAnalyticsAttributes(tr, from, sourceContentEndPos);
|
|
45
|
+
var sourceNodeTypes = attributes.nodeTypes,
|
|
46
|
+
hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
|
|
61
47
|
if (isSameLayout) {
|
|
62
|
-
var _$originalFrom$nodeAf;
|
|
63
48
|
// reorder columns
|
|
64
49
|
tr.delete(from, sourceContentEndPos);
|
|
65
50
|
var mappedTo = tr.mapping.map(to);
|
|
@@ -67,12 +52,11 @@ var moveToExistingLayout = function moveToExistingLayout(toLayout, toLayoutPos,
|
|
|
67
52
|
if (selectMovedNode) {
|
|
68
53
|
tr.setSelection(new NodeSelection(tr.doc.resolve(mappedTo))).scrollIntoView();
|
|
69
54
|
}
|
|
70
|
-
attachMoveNodeAnalytics(tr, INPUT_METHOD.DRAG_AND_DROP, $originalFrom.depth,
|
|
55
|
+
attachMoveNodeAnalytics(tr, INPUT_METHOD.DRAG_AND_DROP, $originalFrom.depth, sourceNodeTypes, 1, 'layoutSection', true, api, hasSelectedMultipleNodes);
|
|
71
56
|
} else if (toLayout.childCount < maxLayoutColumnSupported()) {
|
|
72
|
-
var _$originalFrom$nodeAf2;
|
|
73
57
|
removeFromSource(tr, tr.doc.resolve(from), sourceContentEndPos);
|
|
74
58
|
insertToDestinationNoWidthUpdate(tr, tr.mapping.map(to), sourceContent);
|
|
75
|
-
attachMoveNodeAnalytics(tr, INPUT_METHOD.DRAG_AND_DROP, $originalFrom.depth,
|
|
59
|
+
attachMoveNodeAnalytics(tr, INPUT_METHOD.DRAG_AND_DROP, $originalFrom.depth, sourceNodeTypes, 1, 'layoutSection', false, api, hasSelectedMultipleNodes);
|
|
76
60
|
}
|
|
77
61
|
return tr;
|
|
78
62
|
};
|
|
@@ -90,22 +74,11 @@ var insertToDestinationNoWidthUpdate = function insertToDestinationNoWidthUpdate
|
|
|
90
74
|
layoutColumn = _ref2.layoutColumn;
|
|
91
75
|
var content = null;
|
|
92
76
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
width: 0
|
|
99
|
-
}, isFragmentOfType(sourceFragment, 'layoutColumn') ? (_sourceFragment$first = sourceFragment.firstChild) === null || _sourceFragment$first === void 0 ? void 0 : _sourceFragment$first.content : sourceFragment);
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
if (sourceContent instanceof PMNode) {
|
|
103
|
-
var sourceNode = sourceContent;
|
|
104
|
-
content = layoutColumn.createChecked({
|
|
105
|
-
width: 0
|
|
106
|
-
}, sourceNode.type.name === 'layoutColumn' ? sourceNode.content : sourceNode);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
77
|
+
var _sourceFragment$first;
|
|
78
|
+
var sourceFragment = sourceContent;
|
|
79
|
+
content = layoutColumn.createChecked({
|
|
80
|
+
width: 0
|
|
81
|
+
}, isFragmentOfType(sourceFragment, 'layoutColumn') ? (_sourceFragment$first = sourceFragment.firstChild) === null || _sourceFragment$first === void 0 ? void 0 : _sourceFragment$first.content : sourceFragment);
|
|
109
82
|
} catch (error) {
|
|
110
83
|
logException(error, {
|
|
111
84
|
location: 'editor-plugin-block-controls/move-to-layout'
|
|
@@ -148,7 +121,6 @@ var canMoveToLayout = function canMoveToLayout(api, from, to, tr, moveNodeAtCurs
|
|
|
148
121
|
return;
|
|
149
122
|
}
|
|
150
123
|
var $from = tr.doc.resolve(from);
|
|
151
|
-
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
152
124
|
|
|
153
125
|
// invalid from position or dragging a layout
|
|
154
126
|
if (!$from.nodeAfter || $from.nodeAfter.type === layoutSection) {
|
|
@@ -157,7 +129,7 @@ var canMoveToLayout = function canMoveToLayout(api, from, to, tr, moveNodeAtCurs
|
|
|
157
129
|
var sourceContent = $from.nodeAfter;
|
|
158
130
|
var sourceFrom = from;
|
|
159
131
|
var sourceTo = from + sourceContent.nodeSize;
|
|
160
|
-
if (
|
|
132
|
+
if (!moveNodeAtCursorPos) {
|
|
161
133
|
var _getMultiSelectionIfP = getMultiSelectionIfPosInside(api, from),
|
|
162
134
|
anchor = _getMultiSelectionIfP.anchor,
|
|
163
135
|
head = _getMultiSelectionIfP.head;
|
|
@@ -184,71 +156,51 @@ var canMoveToLayout = function canMoveToLayout(api, from, to, tr, moveNodeAtCurs
|
|
|
184
156
|
};
|
|
185
157
|
};
|
|
186
158
|
var removeBreakoutMarks = function removeBreakoutMarks(tr, $from, to) {
|
|
187
|
-
var fromContentWithoutBreakout =
|
|
159
|
+
var fromContentWithoutBreakout = null;
|
|
188
160
|
var _ref4 = tr.doc.type.schema.marks || {},
|
|
189
161
|
breakout = _ref4.breakout;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// breakout doesn't exist on nested nodes
|
|
200
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type.name) === 'doc' && node.marks.some(function (m) {
|
|
201
|
-
return m.type === breakout;
|
|
202
|
-
})) {
|
|
203
|
-
tr.removeNodeMark(pos, breakout);
|
|
162
|
+
tr.doc.nodesBetween($from.pos, to, function (node, pos, parent) {
|
|
163
|
+
// should never remove breakout from previous layoutSection
|
|
164
|
+
if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true)) {
|
|
165
|
+
if (node.type.name === 'layoutSection') {
|
|
166
|
+
return false;
|
|
204
167
|
}
|
|
168
|
+
}
|
|
205
169
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
209
|
-
// resolve again the source content after node updated (remove breakout marks)
|
|
210
|
-
fromContentWithoutBreakout = tr.doc.slice($from.pos, to).content;
|
|
211
|
-
} else {
|
|
212
|
-
if (breakout && $from.nodeAfter && $from.nodeAfter.marks.some(function (m) {
|
|
170
|
+
// breakout doesn't exist on nested nodes
|
|
171
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type.name) === 'doc' && node.marks.some(function (m) {
|
|
213
172
|
return m.type === breakout;
|
|
214
173
|
})) {
|
|
215
|
-
tr.removeNodeMark(
|
|
216
|
-
// resolve again the source node after node updated (remove breakout marks)
|
|
217
|
-
fromContentWithoutBreakout = tr.doc.resolve($from.pos).nodeAfter;
|
|
174
|
+
tr.removeNodeMark(pos, breakout);
|
|
218
175
|
}
|
|
219
|
-
|
|
176
|
+
|
|
177
|
+
// descending is not needed as breakout doesn't exist on nested nodes
|
|
178
|
+
return false;
|
|
179
|
+
});
|
|
180
|
+
// resolve again the source content after node updated (remove breakout marks)
|
|
181
|
+
fromContentWithoutBreakout = tr.doc.slice($from.pos, to).content;
|
|
220
182
|
return fromContentWithoutBreakout;
|
|
221
183
|
};
|
|
222
184
|
var getBreakoutMode = function getBreakoutMode(content, breakout) {
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return
|
|
185
|
+
if (content instanceof PMNode) {
|
|
186
|
+
var _content$marks$find;
|
|
187
|
+
return (_content$marks$find = content.marks.find(function (m) {
|
|
188
|
+
return m.type === breakout;
|
|
189
|
+
})) === null || _content$marks$find === void 0 ? void 0 : _content$marks$find.attrs.mode;
|
|
190
|
+
} else if (content instanceof Fragment) {
|
|
191
|
+
// Find the first breakout mode in the fragment
|
|
192
|
+
var firstBreakoutMode;
|
|
193
|
+
for (var i = 0; i < content.childCount; i++) {
|
|
194
|
+
var child = content.child(i);
|
|
195
|
+
var breakoutMark = child.marks.find(function (m) {
|
|
227
196
|
return m.type === breakout;
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
for (var i = 0; i < content.childCount; i++) {
|
|
233
|
-
var child = content.child(i);
|
|
234
|
-
var breakoutMark = child.marks.find(function (m) {
|
|
235
|
-
return m.type === breakout;
|
|
236
|
-
});
|
|
237
|
-
if (breakoutMark) {
|
|
238
|
-
firstBreakoutMode = breakoutMark.attrs.mode;
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
197
|
+
});
|
|
198
|
+
if (breakoutMark) {
|
|
199
|
+
firstBreakoutMode = breakoutMark.attrs.mode;
|
|
200
|
+
break;
|
|
241
201
|
}
|
|
242
|
-
return firstBreakoutMode;
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
// Without multi-select support, we can assume source content is of type PMNode
|
|
246
|
-
if (content instanceof PMNode) {
|
|
247
|
-
var _content$marks$find2;
|
|
248
|
-
return (_content$marks$find2 = content.marks.find(function (m) {
|
|
249
|
-
return m.type === breakout;
|
|
250
|
-
})) === null || _content$marks$find2 === void 0 ? void 0 : _content$marks$find2.attrs.mode;
|
|
251
202
|
}
|
|
203
|
+
return firstBreakoutMode;
|
|
252
204
|
}
|
|
253
205
|
};
|
|
254
206
|
var getBreakoutModeAndWidth = function getBreakoutModeAndWidth(content, breakout) {
|
|
@@ -263,30 +215,20 @@ var getBreakoutModeAndWidth = function getBreakoutModeAndWidth(content, breakout
|
|
|
263
215
|
breakoutWidth: mark.attrs.width
|
|
264
216
|
} : null;
|
|
265
217
|
};
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return extractBreakoutAttributes(breakoutMark);
|
|
276
|
-
}
|
|
218
|
+
if (content instanceof PMNode) {
|
|
219
|
+
return extractBreakoutAttributes(findBreakoutMark(content));
|
|
220
|
+
} else if (content instanceof Fragment) {
|
|
221
|
+
// Find the first breakout mode in the fragment
|
|
222
|
+
for (var i = 0; i < content.childCount; i++) {
|
|
223
|
+
var child = content.child(i);
|
|
224
|
+
var breakoutMark = findBreakoutMark(child);
|
|
225
|
+
if (breakoutMark) {
|
|
226
|
+
return extractBreakoutAttributes(breakoutMark);
|
|
277
227
|
}
|
|
278
228
|
}
|
|
279
|
-
} else {
|
|
280
|
-
// Without multi-select support, we can assume source content is of type PMNode
|
|
281
|
-
if (content instanceof PMNode) {
|
|
282
|
-
return extractBreakoutAttributes(findBreakoutMark(content));
|
|
283
|
-
}
|
|
284
229
|
}
|
|
285
230
|
return null;
|
|
286
231
|
};
|
|
287
|
-
|
|
288
|
-
// TODO: ED-26959 - As part of platform_editor_element_drag_and_drop_multiselect clean up,
|
|
289
|
-
// source content variable that has type of `PMNode | Fragment` should be updated to `Fragment` only
|
|
290
232
|
export var moveToLayout = function moveToLayout(api) {
|
|
291
233
|
return function (from, to, options) {
|
|
292
234
|
return function (_ref5) {
|
|
@@ -322,8 +264,8 @@ export var moveToLayout = function moveToLayout(api) {
|
|
|
322
264
|
}
|
|
323
265
|
|
|
324
266
|
// we don't want to remove marks when moving/re-ordering layoutSection
|
|
325
|
-
var shouldRemoveMarks =
|
|
326
|
-
var fromContentBeforeBreakoutMarksRemoved =
|
|
267
|
+
var shouldRemoveMarks = $sourceFrom.node().type !== layoutSection;
|
|
268
|
+
var fromContentBeforeBreakoutMarksRemoved = tr.doc.slice($sourceFrom.pos, sourceTo).content;
|
|
327
269
|
|
|
328
270
|
// remove breakout from source content
|
|
329
271
|
var fromContentWithoutBreakout = shouldRemoveMarks ? removeBreakoutMarks(tr, $sourceFrom, sourceTo) : fromContentBeforeBreakoutMarksRemoved;
|
|
@@ -336,7 +278,6 @@ export var moveToLayout = function moveToLayout(api) {
|
|
|
336
278
|
tr: tr
|
|
337
279
|
});
|
|
338
280
|
}
|
|
339
|
-
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
340
281
|
if (toNode.type === layoutSection) {
|
|
341
282
|
var toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize - 1 : to + 1;
|
|
342
283
|
return moveToExistingLayout(toNode, to, fromContentWithoutBreakout, $sourceFrom.pos, toPos, tr, $sourceFrom, $to, api, options === null || options === void 0 ? void 0 : options.selectMovedNode);
|
|
@@ -356,24 +297,15 @@ export var moveToLayout = function moveToLayout(api) {
|
|
|
356
297
|
// resolve again the source node after node updated (remove breakout marks)
|
|
357
298
|
toNodeWithoutBreakout = tr.doc.resolve(to).nodeAfter || toNode;
|
|
358
299
|
}
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
fromContentWithoutBreakout = fromContentWithoutBreakout.firstChild.content;
|
|
362
|
-
}
|
|
363
|
-
} else {
|
|
364
|
-
if (fromContentWithoutBreakout instanceof PMNode && fromContentWithoutBreakout.type.name === 'layoutColumn') {
|
|
365
|
-
fromContentWithoutBreakout = fromContentWithoutBreakout.content;
|
|
366
|
-
}
|
|
300
|
+
if (isFragmentOfType(fromContentWithoutBreakout, 'layoutColumn') && fromContentWithoutBreakout.firstChild) {
|
|
301
|
+
fromContentWithoutBreakout = fromContentWithoutBreakout.firstChild.content;
|
|
367
302
|
}
|
|
368
303
|
var layoutContents = options !== null && options !== void 0 && options.moveToEnd ? [toNodeWithoutBreakout, fromContentWithoutBreakout] : [fromContentWithoutBreakout, toNodeWithoutBreakout];
|
|
369
304
|
var newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
370
305
|
if (newLayout) {
|
|
371
|
-
var
|
|
372
|
-
|
|
373
|
-
var attributes = getMultiSelectAnalyticsAttributes(tr, $sourceFrom.pos, sourceTo);
|
|
306
|
+
var attributes = getMultiSelectAnalyticsAttributes(tr, $sourceFrom.pos, sourceTo);
|
|
307
|
+
var sourceNodeTypes = attributes.nodeTypes,
|
|
374
308
|
hasSelectedMultipleNodes = attributes.hasSelectedMultipleNodes;
|
|
375
|
-
sourceNodeTypes = attributes.nodeTypes;
|
|
376
|
-
}
|
|
377
309
|
tr = removeFromSource(tr, $sourceFrom, sourceTo);
|
|
378
310
|
var mappedTo = tr.mapping.map(to);
|
|
379
311
|
tr.delete(mappedTo, mappedTo + toNodeWithoutBreakout.nodeSize).insert(mappedTo, newLayout);
|