@atlaskit/editor-plugin-block-controls 2.24.0 → 2.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/pm-plugins/decorations-anchor.js +5 -0
- package/dist/cjs/pm-plugins/utils/getSelection.js +58 -3
- package/dist/cjs/ui/drag-handle.js +11 -0
- package/dist/es2019/pm-plugins/decorations-anchor.js +5 -0
- package/dist/es2019/pm-plugins/utils/getSelection.js +55 -0
- package/dist/es2019/ui/drag-handle.js +12 -1
- package/dist/esm/pm-plugins/decorations-anchor.js +5 -0
- package/dist/esm/pm-plugins/utils/getSelection.js +55 -0
- package/dist/esm/ui/drag-handle.js +12 -1
- package/dist/types/pm-plugins/utils/getSelection.d.ts +12 -1
- package/dist/types-ts4.5/pm-plugins/utils/getSelection.d.ts +12 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#111831](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111831)
|
|
8
|
+
[`66895944dfac9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/66895944dfac9) -
|
|
9
|
+
[ED-26430] Block drag-and-drop of legacy content macro extension
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 2.25.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#107342](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107342)
|
|
20
|
+
[`ec6b838ab9935`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ec6b838ab9935) -
|
|
21
|
+
[ux] Set drag handle selection state based on Editor selection
|
|
22
|
+
|
|
3
23
|
## 2.24.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -28,12 +28,17 @@ var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDesce
|
|
|
28
28
|
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
29
29
|
};
|
|
30
30
|
var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, parent) {
|
|
31
|
+
var _node$attrs, _node$attrs2;
|
|
31
32
|
var isEmbedCard = node.type.name === 'embedCard';
|
|
32
33
|
var isMediaSingle = node.type.name === 'mediaSingle';
|
|
33
34
|
var isFirstTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && 'tableRow' === node.type.name && (0, _experiments.editorExperiment)('advanced_layouts', true);
|
|
34
35
|
if (isFirstTableRow) {
|
|
35
36
|
return false;
|
|
36
37
|
}
|
|
38
|
+
var isLegacyContentMacroExtension = node.type.name === 'extension' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionType) === 'com.atlassian.confluence.migration' && ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.extensionKey) === 'legacy-content';
|
|
39
|
+
if (isLegacyContentMacroExtension) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
37
42
|
return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
|
|
38
43
|
};
|
|
39
44
|
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setCursorPositionAtMovedNode = exports.selectNode = exports.getSelection = exports.getInlineNodePos = void 0;
|
|
6
|
+
exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isHandleInSelection = exports.getSelection = exports.getInlineNodePos = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
-
var _utils = require("@atlaskit/editor-
|
|
9
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
|
+
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
10
11
|
var getInlineNodePos = exports.getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
|
|
11
12
|
var $startPos = tr.doc.resolve(start);
|
|
12
13
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
@@ -68,7 +69,7 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
|
|
|
68
69
|
var selectNode = exports.selectNode = function selectNode(tr, start, nodeType) {
|
|
69
70
|
// For table, we need to do cell selection instead of node selection
|
|
70
71
|
if (nodeType === 'table') {
|
|
71
|
-
tr = (0,
|
|
72
|
+
tr = (0, _utils2.selectTableClosestToPos)(tr, tr.doc.resolve(start + 1));
|
|
72
73
|
} else {
|
|
73
74
|
tr.setSelection(getSelection(tr, start));
|
|
74
75
|
}
|
|
@@ -90,4 +91,58 @@ var setCursorPositionAtMovedNode = exports.setCursorPositionAtMovedNode = functi
|
|
|
90
91
|
}
|
|
91
92
|
tr.setSelection(selection);
|
|
92
93
|
return tr;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Checks if handle position is with the selection or corresponds to a (partially) selected node
|
|
98
|
+
* @param state
|
|
99
|
+
* @param selection
|
|
100
|
+
* @param handlePos
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
var isHandleInSelection = exports.isHandleInSelection = function isHandleInSelection(state, selection, handlePos) {
|
|
104
|
+
if (selection.empty) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
var $selectionFrom = selection.$from;
|
|
108
|
+
var selectionFrom = $selectionFrom.pos;
|
|
109
|
+
var nodeStart = $selectionFrom.depth ? $selectionFrom.before() : selectionFrom;
|
|
110
|
+
var $resolvedNodePos = state.doc.resolve(nodeStart);
|
|
111
|
+
if (['tableRow', 'tableCell', 'tableHeader'].includes($resolvedNodePos.node().type.name)) {
|
|
112
|
+
var parentNodeFindRes = (0, _utils.findParentNodeOfType)(state.schema.nodes['table'])(selection);
|
|
113
|
+
var tablePos = parentNodeFindRes === null || parentNodeFindRes === void 0 ? void 0 : parentNodeFindRes.pos;
|
|
114
|
+
nodeStart = typeof tablePos === 'undefined' ? nodeStart : tablePos;
|
|
115
|
+
} else if (['listItem'].includes($resolvedNodePos.node().type.name)) {
|
|
116
|
+
nodeStart = $resolvedNodePos.before(rootListDepth($resolvedNodePos));
|
|
117
|
+
} else if (['taskList'].includes($resolvedNodePos.node().type.name)) {
|
|
118
|
+
var listdepth = rootTaskListDepth($resolvedNodePos);
|
|
119
|
+
nodeStart = $resolvedNodePos.before(listdepth);
|
|
120
|
+
} else if (['blockquote'].includes($resolvedNodePos.node().type.name)) {
|
|
121
|
+
nodeStart = $resolvedNodePos.before();
|
|
122
|
+
}
|
|
123
|
+
return Boolean(handlePos < selection.$to.pos && handlePos >= nodeStart);
|
|
124
|
+
};
|
|
125
|
+
var rootListDepth = exports.rootListDepth = function rootListDepth(itemPos) {
|
|
126
|
+
var depth;
|
|
127
|
+
for (var i = itemPos.depth; i > 1; i -= 2) {
|
|
128
|
+
var node = itemPos.node(i);
|
|
129
|
+
if (node.type.name === 'listItem') {
|
|
130
|
+
depth = i - 1;
|
|
131
|
+
} else {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return depth;
|
|
136
|
+
};
|
|
137
|
+
var rootTaskListDepth = exports.rootTaskListDepth = function rootTaskListDepth(taskListPos) {
|
|
138
|
+
var depth;
|
|
139
|
+
for (var i = taskListPos.depth; i > 0; i--) {
|
|
140
|
+
var node = taskListPos.node(i);
|
|
141
|
+
if (node.type.name === 'taskList' || node.type.name === 'taskItem') {
|
|
142
|
+
depth = i;
|
|
143
|
+
} else {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return depth;
|
|
93
148
|
};
|
|
@@ -15,6 +15,7 @@ var _browser = require("@atlaskit/editor-common/browser");
|
|
|
15
15
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
16
16
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
17
17
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
18
|
+
var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
|
|
18
19
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
19
20
|
var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-handler"));
|
|
20
21
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -128,6 +129,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
128
129
|
setDragHandleSelected = _useState4[1];
|
|
129
130
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['featureFlags']),
|
|
130
131
|
featureFlagsState = _useSharedPluginState.featureFlagsState;
|
|
132
|
+
var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
|
|
131
133
|
var isLayoutColumn = nodeType === 'layoutColumn';
|
|
132
134
|
(0, _react.useEffect)(function () {
|
|
133
135
|
// blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
|
|
@@ -378,6 +380,15 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
378
380
|
};
|
|
379
381
|
}
|
|
380
382
|
}, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
|
|
383
|
+
(0, _react.useEffect)(function () {
|
|
384
|
+
var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true, {
|
|
385
|
+
exposure: true
|
|
386
|
+
});
|
|
387
|
+
if (!isMultiSelect || typeof start !== 'number' || !selection) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
setDragHandleSelected((0, _getSelection.isHandleInSelection)(view.state, selection, start));
|
|
391
|
+
}, [start, selection, view.state]);
|
|
381
392
|
var helpDescriptors = [{
|
|
382
393
|
description: formatMessage(_messages.blockControlsMessages.dragToMove)
|
|
383
394
|
}, {
|
|
@@ -20,12 +20,17 @@ export const shouldDescendIntoNode = node => {
|
|
|
20
20
|
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
21
21
|
};
|
|
22
22
|
const shouldIgnoreNode = (node, ignore_nodes, depth, parent) => {
|
|
23
|
+
var _node$attrs, _node$attrs2;
|
|
23
24
|
const isEmbedCard = node.type.name === 'embedCard';
|
|
24
25
|
const isMediaSingle = node.type.name === 'mediaSingle';
|
|
25
26
|
const isFirstTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && 'tableRow' === node.type.name && editorExperiment('advanced_layouts', true);
|
|
26
27
|
if (isFirstTableRow) {
|
|
27
28
|
return false;
|
|
28
29
|
}
|
|
30
|
+
const isLegacyContentMacroExtension = node.type.name === 'extension' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionType) === 'com.atlassian.confluence.migration' && ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.extensionKey) === 'legacy-content';
|
|
31
|
+
if (isLegacyContentMacroExtension) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
29
34
|
return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
|
|
30
35
|
};
|
|
31
36
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
4
|
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
4
5
|
export const getInlineNodePos = (tr, start, nodeSize) => {
|
|
5
6
|
const $startPos = tr.doc.resolve(start);
|
|
@@ -86,4 +87,58 @@ export const setCursorPositionAtMovedNode = (tr, start) => {
|
|
|
86
87
|
}
|
|
87
88
|
tr.setSelection(selection);
|
|
88
89
|
return tr;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Checks if handle position is with the selection or corresponds to a (partially) selected node
|
|
94
|
+
* @param state
|
|
95
|
+
* @param selection
|
|
96
|
+
* @param handlePos
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
export const isHandleInSelection = (state, selection, handlePos) => {
|
|
100
|
+
if (selection.empty) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const $selectionFrom = selection.$from;
|
|
104
|
+
const selectionFrom = $selectionFrom.pos;
|
|
105
|
+
let nodeStart = $selectionFrom.depth ? $selectionFrom.before() : selectionFrom;
|
|
106
|
+
const $resolvedNodePos = state.doc.resolve(nodeStart);
|
|
107
|
+
if (['tableRow', 'tableCell', 'tableHeader'].includes($resolvedNodePos.node().type.name)) {
|
|
108
|
+
const parentNodeFindRes = findParentNodeOfType(state.schema.nodes['table'])(selection);
|
|
109
|
+
const tablePos = parentNodeFindRes === null || parentNodeFindRes === void 0 ? void 0 : parentNodeFindRes.pos;
|
|
110
|
+
nodeStart = typeof tablePos === 'undefined' ? nodeStart : tablePos;
|
|
111
|
+
} else if (['listItem'].includes($resolvedNodePos.node().type.name)) {
|
|
112
|
+
nodeStart = $resolvedNodePos.before(rootListDepth($resolvedNodePos));
|
|
113
|
+
} else if (['taskList'].includes($resolvedNodePos.node().type.name)) {
|
|
114
|
+
const listdepth = rootTaskListDepth($resolvedNodePos);
|
|
115
|
+
nodeStart = $resolvedNodePos.before(listdepth);
|
|
116
|
+
} else if (['blockquote'].includes($resolvedNodePos.node().type.name)) {
|
|
117
|
+
nodeStart = $resolvedNodePos.before();
|
|
118
|
+
}
|
|
119
|
+
return Boolean(handlePos < selection.$to.pos && handlePos >= nodeStart);
|
|
120
|
+
};
|
|
121
|
+
export const rootListDepth = itemPos => {
|
|
122
|
+
let depth;
|
|
123
|
+
for (let i = itemPos.depth; i > 1; i -= 2) {
|
|
124
|
+
const node = itemPos.node(i);
|
|
125
|
+
if (node.type.name === 'listItem') {
|
|
126
|
+
depth = i - 1;
|
|
127
|
+
} else {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return depth;
|
|
132
|
+
};
|
|
133
|
+
export const rootTaskListDepth = taskListPos => {
|
|
134
|
+
let depth;
|
|
135
|
+
for (let i = taskListPos.depth; i > 0; i--) {
|
|
136
|
+
const node = taskListPos.node(i);
|
|
137
|
+
if (node.type.name === 'taskList' || node.type.name === 'taskItem') {
|
|
138
|
+
depth = i;
|
|
139
|
+
} else {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return depth;
|
|
89
144
|
};
|
|
@@ -11,6 +11,7 @@ import { browser } from '@atlaskit/editor-common/browser';
|
|
|
11
11
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
12
12
|
import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
|
|
13
13
|
import { blockControlsMessages } from '@atlaskit/editor-common/messages';
|
|
14
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
14
15
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
15
16
|
import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
16
17
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -22,7 +23,7 @@ import Tooltip from '@atlaskit/tooltip';
|
|
|
22
23
|
import { key } from '../pm-plugins/main';
|
|
23
24
|
import { getLeftPosition, getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
|
|
24
25
|
import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
|
|
25
|
-
import { selectNode } from '../pm-plugins/utils/getSelection';
|
|
26
|
+
import { isHandleInSelection, selectNode } from '../pm-plugins/utils/getSelection';
|
|
26
27
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, topPositionAdjustment } from './consts';
|
|
27
28
|
import { dragPreview } from './drag-preview';
|
|
28
29
|
const iconWrapperStyles = xcss({
|
|
@@ -112,6 +113,7 @@ export const DragHandle = ({
|
|
|
112
113
|
const {
|
|
113
114
|
featureFlagsState
|
|
114
115
|
} = useSharedPluginState(api, ['featureFlags']);
|
|
116
|
+
const selection = useSharedPluginStateSelector(api, 'selection.selection');
|
|
115
117
|
const isLayoutColumn = nodeType === 'layoutColumn';
|
|
116
118
|
useEffect(() => {
|
|
117
119
|
// blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
|
|
@@ -358,6 +360,15 @@ export const DragHandle = ({
|
|
|
358
360
|
};
|
|
359
361
|
}
|
|
360
362
|
}, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
|
|
365
|
+
exposure: true
|
|
366
|
+
});
|
|
367
|
+
if (!isMultiSelect || typeof start !== 'number' || !selection) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
setDragHandleSelected(isHandleInSelection(view.state, selection, start));
|
|
371
|
+
}, [start, selection, view.state]);
|
|
361
372
|
let helpDescriptors = [{
|
|
362
373
|
description: formatMessage(blockControlsMessages.dragToMove)
|
|
363
374
|
}, {
|
|
@@ -21,12 +21,17 @@ export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
|
|
|
21
21
|
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
22
22
|
};
|
|
23
23
|
var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, parent) {
|
|
24
|
+
var _node$attrs, _node$attrs2;
|
|
24
25
|
var isEmbedCard = node.type.name === 'embedCard';
|
|
25
26
|
var isMediaSingle = node.type.name === 'mediaSingle';
|
|
26
27
|
var isFirstTableRow = (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'table' && depth === 1 && node === parent.firstChild && 'tableRow' === node.type.name && editorExperiment('advanced_layouts', true);
|
|
27
28
|
if (isFirstTableRow) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
31
|
+
var isLegacyContentMacroExtension = node.type.name === 'extension' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionType) === 'com.atlassian.confluence.migration' && ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.extensionKey) === 'legacy-content';
|
|
32
|
+
if (isLegacyContentMacroExtension) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
30
35
|
return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
|
|
31
36
|
};
|
|
32
37
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
4
|
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
4
5
|
export var getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
|
|
5
6
|
var $startPos = tr.doc.resolve(start);
|
|
@@ -84,4 +85,58 @@ export var setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(
|
|
|
84
85
|
}
|
|
85
86
|
tr.setSelection(selection);
|
|
86
87
|
return tr;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Checks if handle position is with the selection or corresponds to a (partially) selected node
|
|
92
|
+
* @param state
|
|
93
|
+
* @param selection
|
|
94
|
+
* @param handlePos
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
export var isHandleInSelection = function isHandleInSelection(state, selection, handlePos) {
|
|
98
|
+
if (selection.empty) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
var $selectionFrom = selection.$from;
|
|
102
|
+
var selectionFrom = $selectionFrom.pos;
|
|
103
|
+
var nodeStart = $selectionFrom.depth ? $selectionFrom.before() : selectionFrom;
|
|
104
|
+
var $resolvedNodePos = state.doc.resolve(nodeStart);
|
|
105
|
+
if (['tableRow', 'tableCell', 'tableHeader'].includes($resolvedNodePos.node().type.name)) {
|
|
106
|
+
var parentNodeFindRes = findParentNodeOfType(state.schema.nodes['table'])(selection);
|
|
107
|
+
var tablePos = parentNodeFindRes === null || parentNodeFindRes === void 0 ? void 0 : parentNodeFindRes.pos;
|
|
108
|
+
nodeStart = typeof tablePos === 'undefined' ? nodeStart : tablePos;
|
|
109
|
+
} else if (['listItem'].includes($resolvedNodePos.node().type.name)) {
|
|
110
|
+
nodeStart = $resolvedNodePos.before(rootListDepth($resolvedNodePos));
|
|
111
|
+
} else if (['taskList'].includes($resolvedNodePos.node().type.name)) {
|
|
112
|
+
var listdepth = rootTaskListDepth($resolvedNodePos);
|
|
113
|
+
nodeStart = $resolvedNodePos.before(listdepth);
|
|
114
|
+
} else if (['blockquote'].includes($resolvedNodePos.node().type.name)) {
|
|
115
|
+
nodeStart = $resolvedNodePos.before();
|
|
116
|
+
}
|
|
117
|
+
return Boolean(handlePos < selection.$to.pos && handlePos >= nodeStart);
|
|
118
|
+
};
|
|
119
|
+
export var rootListDepth = function rootListDepth(itemPos) {
|
|
120
|
+
var depth;
|
|
121
|
+
for (var i = itemPos.depth; i > 1; i -= 2) {
|
|
122
|
+
var node = itemPos.node(i);
|
|
123
|
+
if (node.type.name === 'listItem') {
|
|
124
|
+
depth = i - 1;
|
|
125
|
+
} else {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return depth;
|
|
130
|
+
};
|
|
131
|
+
export var rootTaskListDepth = function rootTaskListDepth(taskListPos) {
|
|
132
|
+
var depth;
|
|
133
|
+
for (var i = taskListPos.depth; i > 0; i--) {
|
|
134
|
+
var node = taskListPos.node(i);
|
|
135
|
+
if (node.type.name === 'taskList' || node.type.name === 'taskItem') {
|
|
136
|
+
depth = i;
|
|
137
|
+
} else {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return depth;
|
|
87
142
|
};
|
|
@@ -13,6 +13,7 @@ import { browser } from '@atlaskit/editor-common/browser';
|
|
|
13
13
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
14
14
|
import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
|
|
15
15
|
import { blockControlsMessages } from '@atlaskit/editor-common/messages';
|
|
16
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
16
17
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
17
18
|
import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
18
19
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -24,7 +25,7 @@ import Tooltip from '@atlaskit/tooltip';
|
|
|
24
25
|
import { key } from '../pm-plugins/main';
|
|
25
26
|
import { getLeftPosition, getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
|
|
26
27
|
import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
|
|
27
|
-
import { selectNode } from '../pm-plugins/utils/getSelection';
|
|
28
|
+
import { isHandleInSelection, selectNode } from '../pm-plugins/utils/getSelection';
|
|
28
29
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, topPositionAdjustment } from './consts';
|
|
29
30
|
import { dragPreview } from './drag-preview';
|
|
30
31
|
var iconWrapperStyles = xcss({
|
|
@@ -119,6 +120,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
119
120
|
setDragHandleSelected = _useState4[1];
|
|
120
121
|
var _useSharedPluginState = useSharedPluginState(api, ['featureFlags']),
|
|
121
122
|
featureFlagsState = _useSharedPluginState.featureFlagsState;
|
|
123
|
+
var selection = useSharedPluginStateSelector(api, 'selection.selection');
|
|
122
124
|
var isLayoutColumn = nodeType === 'layoutColumn';
|
|
123
125
|
useEffect(function () {
|
|
124
126
|
// blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
|
|
@@ -369,6 +371,15 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
369
371
|
};
|
|
370
372
|
}
|
|
371
373
|
}, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
|
|
374
|
+
useEffect(function () {
|
|
375
|
+
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
|
|
376
|
+
exposure: true
|
|
377
|
+
});
|
|
378
|
+
if (!isMultiSelect || typeof start !== 'number' || !selection) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
setDragHandleSelected(isHandleInSelection(view.state, selection, start));
|
|
382
|
+
}, [start, selection, view.state]);
|
|
372
383
|
var helpDescriptors = [{
|
|
373
384
|
description: formatMessage(blockControlsMessages.dragToMove)
|
|
374
385
|
}, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
|
|
3
4
|
inlineNodePos: number;
|
|
4
5
|
inlineNodeEndPos: number;
|
|
@@ -6,3 +7,13 @@ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize
|
|
|
6
7
|
export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
|
|
7
8
|
export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
|
|
8
9
|
export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if handle position is with the selection or corresponds to a (partially) selected node
|
|
12
|
+
* @param state
|
|
13
|
+
* @param selection
|
|
14
|
+
* @param handlePos
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
|
|
18
|
+
export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
|
|
19
|
+
export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
|
|
3
4
|
inlineNodePos: number;
|
|
4
5
|
inlineNodeEndPos: number;
|
|
@@ -6,3 +7,13 @@ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize
|
|
|
6
7
|
export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
|
|
7
8
|
export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
|
|
8
9
|
export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if handle position is with the selection or corresponds to a (partially) selected node
|
|
12
|
+
* @param state
|
|
13
|
+
* @param selection
|
|
14
|
+
* @param handlePos
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
|
|
18
|
+
export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
|
|
19
|
+
export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.0",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
34
|
-
"@atlaskit/editor-common": "^99.
|
|
34
|
+
"@atlaskit/editor-common": "^99.12.0",
|
|
35
35
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.4.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.12.0",
|
|
37
37
|
"@atlaskit/editor-plugin-editor-disabled": "^1.5.0",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
43
43
|
"@atlaskit/editor-shared-styles": "^3.2.0",
|
|
44
44
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
45
|
-
"@atlaskit/icon": "^23.
|
|
45
|
+
"@atlaskit/icon": "^23.8.0",
|
|
46
46
|
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
47
47
|
"@atlaskit/pragmatic-drag-and-drop": "^1.5.0",
|
|
48
48
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
|
|
49
49
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.2.0",
|
|
50
50
|
"@atlaskit/primitives": "^13.5.0",
|
|
51
51
|
"@atlaskit/theme": "^15.0.0",
|
|
52
|
-
"@atlaskit/tmp-editor-statsig": "^2.
|
|
52
|
+
"@atlaskit/tmp-editor-statsig": "^2.45.0",
|
|
53
53
|
"@atlaskit/tokens": "^3.3.0",
|
|
54
54
|
"@atlaskit/tooltip": "^19.1.0",
|
|
55
55
|
"@babel/runtime": "^7.0.0",
|