@atlaskit/editor-plugin-block-controls 1.4.10 → 1.4.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 +9 -0
- package/dist/cjs/plugin.js +10 -6
- package/dist/cjs/pm-plugins/main.js +2 -1
- package/dist/cjs/ui/drag-handle.js +5 -5
- package/dist/cjs/ui/drop-target.js +1 -1
- package/dist/cjs/utils/getSelection.js +11 -1
- package/dist/cjs/utils/index.js +6 -0
- package/dist/es2019/plugin.js +10 -6
- package/dist/es2019/pm-plugins/main.js +2 -1
- package/dist/es2019/ui/drag-handle.js +5 -5
- package/dist/es2019/ui/drop-target.js +1 -1
- package/dist/es2019/utils/getSelection.js +10 -0
- package/dist/es2019/utils/index.js +1 -1
- package/dist/esm/plugin.js +10 -6
- package/dist/esm/pm-plugins/main.js +2 -1
- package/dist/esm/ui/drag-handle.js +5 -5
- package/dist/esm/ui/drop-target.js +1 -1
- package/dist/esm/utils/getSelection.js +10 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/getSelection.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/getSelection.d.ts +1 -0
- package/dist/types-ts4.5/utils/index.d.ts +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.4.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#108763](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108763)
|
|
8
|
+
[`f97149e66b556`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f97149e66b556) -
|
|
9
|
+
Fix table scroll when table selected by drag handle
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 1.4.10
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -9,7 +9,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _main = require("./pm-plugins/main");
|
|
10
10
|
var _dragHandleMenu = require("./ui/drag-handle-menu");
|
|
11
11
|
var _globalStyles = require("./ui/global-styles");
|
|
12
|
-
var
|
|
12
|
+
var _utils = require("./utils");
|
|
13
13
|
var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
14
14
|
var api = _ref.api;
|
|
15
15
|
return {
|
|
@@ -28,13 +28,16 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
28
28
|
var _node$nodeSize;
|
|
29
29
|
var tr = _ref2.tr;
|
|
30
30
|
var node = tr.doc.nodeAt(start);
|
|
31
|
+
if (!node) {
|
|
32
|
+
return tr;
|
|
33
|
+
}
|
|
31
34
|
var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
32
35
|
var end = start + size;
|
|
33
36
|
var nodeCopy = tr.doc.content.cut(start, end); // cut the content
|
|
34
37
|
tr.delete(start, end); // delete the content from the original position
|
|
35
38
|
var mappedTo = tr.mapping.map(to);
|
|
36
39
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
37
|
-
tr
|
|
40
|
+
tr = (0, _utils.selectNode)(tr, mappedTo, node.type.name);
|
|
38
41
|
tr.setMeta(_main.key, {
|
|
39
42
|
nodeMoved: true
|
|
40
43
|
});
|
|
@@ -55,19 +58,20 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
55
58
|
return tr;
|
|
56
59
|
};
|
|
57
60
|
},
|
|
58
|
-
setNodeDragged: function setNodeDragged(pos, anchorName) {
|
|
61
|
+
setNodeDragged: function setNodeDragged(pos, anchorName, nodeType) {
|
|
59
62
|
return function (_ref4) {
|
|
60
63
|
var tr = _ref4.tr;
|
|
61
|
-
var newTr = tr;
|
|
62
64
|
if (pos === undefined) {
|
|
63
65
|
return tr;
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
var newTr = tr;
|
|
68
|
+
newTr = (0, _utils.selectNode)(newTr, pos, nodeType);
|
|
66
69
|
newTr.setMeta(_main.key, {
|
|
67
70
|
isDragging: true,
|
|
68
71
|
activeNode: {
|
|
69
72
|
pos: pos,
|
|
70
|
-
anchorName: anchorName
|
|
73
|
+
anchorName: anchorName,
|
|
74
|
+
nodeType: nodeType
|
|
71
75
|
}
|
|
72
76
|
});
|
|
73
77
|
return newTr;
|
|
@@ -100,7 +100,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
100
100
|
// Map active node position when the document changes
|
|
101
101
|
var mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
102
102
|
pos: tr.mapping.map(activeNode.pos),
|
|
103
|
-
anchorName: activeNode.anchorName
|
|
103
|
+
anchorName: activeNode.anchorName,
|
|
104
|
+
nodeType: activeNode.nodeType
|
|
104
105
|
} : activeNode;
|
|
105
106
|
return {
|
|
106
107
|
decorations: decorations,
|
|
@@ -12,8 +12,8 @@ var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-han
|
|
|
12
12
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
13
13
|
var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview");
|
|
14
14
|
var _main = require("../pm-plugins/main");
|
|
15
|
+
var _utils = require("../utils");
|
|
15
16
|
var _dragHandlePositions = require("../utils/drag-handle-positions");
|
|
16
|
-
var _getSelection = require("../utils/getSelection");
|
|
17
17
|
var _consts = require("./consts");
|
|
18
18
|
var _dragPreview = require("./drag-preview");
|
|
19
19
|
/** @jsx jsx */
|
|
@@ -65,14 +65,14 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
65
65
|
if (start === undefined) {
|
|
66
66
|
return tr;
|
|
67
67
|
}
|
|
68
|
-
tr
|
|
68
|
+
tr = (0, _utils.selectNode)(tr, start, nodeType);
|
|
69
69
|
tr.setMeta(_main.key, {
|
|
70
70
|
pos: start
|
|
71
71
|
});
|
|
72
72
|
return tr;
|
|
73
73
|
});
|
|
74
74
|
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
75
|
-
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
75
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected, nodeType]);
|
|
76
76
|
(0, _react.useEffect)(function () {
|
|
77
77
|
var element = buttonRef.current;
|
|
78
78
|
if (!element) {
|
|
@@ -99,7 +99,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
99
99
|
if (start === undefined) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName));
|
|
102
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
103
103
|
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
|
|
104
104
|
},
|
|
105
105
|
onDrop: function onDrop() {
|
|
@@ -112,7 +112,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
}, [api, start, view, anchorName]);
|
|
115
|
+
}, [api, start, view, anchorName, nodeType]);
|
|
116
116
|
var positionStyles = (0, _react.useMemo)(function () {
|
|
117
117
|
var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
|
|
118
118
|
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
@@ -100,7 +100,7 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
100
100
|
isDraggedOver && (0, _react2.jsx)("div", {
|
|
101
101
|
css: styleDropIndicator,
|
|
102
102
|
style: {
|
|
103
|
-
|
|
103
|
+
width: "".concat(lineLength, "px")
|
|
104
104
|
},
|
|
105
105
|
"data-testid": "block-ctrl-drop-indicator"
|
|
106
106
|
}, (0, _react2.jsx)(_box.DropIndicator, {
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getSelection = void 0;
|
|
6
|
+
exports.selectNode = exports.getSelection = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
8
9
|
var getSelection = exports.getSelection = function getSelection(tr, start) {
|
|
9
10
|
var node = tr.doc.nodeAt(start);
|
|
10
11
|
var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
|
|
@@ -31,4 +32,13 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
|
|
|
31
32
|
var textNodeDepth = textNodesPos - start;
|
|
32
33
|
return new _state.TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
|
|
33
34
|
}
|
|
35
|
+
};
|
|
36
|
+
var selectNode = exports.selectNode = function selectNode(tr, start, nodeType) {
|
|
37
|
+
// For table, we need to do cell selection instead of node selection
|
|
38
|
+
if (nodeType === 'table') {
|
|
39
|
+
tr = (0, _utils.selectTableClosestToPos)(tr, tr.doc.resolve(start + 1));
|
|
40
|
+
} else {
|
|
41
|
+
tr.setSelection(getSelection(tr, start));
|
|
42
|
+
}
|
|
43
|
+
return tr;
|
|
34
44
|
};
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -9,4 +9,10 @@ Object.defineProperty(exports, "getSelection", {
|
|
|
9
9
|
return _getSelection.getSelection;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "selectNode", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _getSelection.selectNode;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
var _getSelection = require("./getSelection");
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { createPlugin, key } from './pm-plugins/main';
|
|
3
3
|
import { DragHandleMenu } from './ui/drag-handle-menu';
|
|
4
4
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
5
|
-
import {
|
|
5
|
+
import { selectNode } from './utils';
|
|
6
6
|
export const blockControlsPlugin = ({
|
|
7
7
|
api
|
|
8
8
|
}) => ({
|
|
@@ -19,13 +19,16 @@ export const blockControlsPlugin = ({
|
|
|
19
19
|
}) => {
|
|
20
20
|
var _node$nodeSize;
|
|
21
21
|
const node = tr.doc.nodeAt(start);
|
|
22
|
+
if (!node) {
|
|
23
|
+
return tr;
|
|
24
|
+
}
|
|
22
25
|
const size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
23
26
|
const end = start + size;
|
|
24
27
|
let nodeCopy = tr.doc.content.cut(start, end); // cut the content
|
|
25
28
|
tr.delete(start, end); // delete the content from the original position
|
|
26
29
|
const mappedTo = tr.mapping.map(to);
|
|
27
30
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
28
|
-
tr
|
|
31
|
+
tr = selectNode(tr, mappedTo, node.type.name);
|
|
29
32
|
tr.setMeta(key, {
|
|
30
33
|
nodeMoved: true
|
|
31
34
|
});
|
|
@@ -44,19 +47,20 @@ export const blockControlsPlugin = ({
|
|
|
44
47
|
});
|
|
45
48
|
return tr;
|
|
46
49
|
},
|
|
47
|
-
setNodeDragged: (pos, anchorName) => ({
|
|
50
|
+
setNodeDragged: (pos, anchorName, nodeType) => ({
|
|
48
51
|
tr
|
|
49
52
|
}) => {
|
|
50
|
-
const newTr = tr;
|
|
51
53
|
if (pos === undefined) {
|
|
52
54
|
return tr;
|
|
53
55
|
}
|
|
54
|
-
newTr
|
|
56
|
+
let newTr = tr;
|
|
57
|
+
newTr = selectNode(newTr, pos, nodeType);
|
|
55
58
|
newTr.setMeta(key, {
|
|
56
59
|
isDragging: true,
|
|
57
60
|
activeNode: {
|
|
58
61
|
pos,
|
|
59
|
-
anchorName
|
|
62
|
+
anchorName,
|
|
63
|
+
nodeType
|
|
60
64
|
}
|
|
61
65
|
});
|
|
62
66
|
return newTr;
|
|
@@ -94,7 +94,8 @@ export const createPlugin = api => {
|
|
|
94
94
|
// Map active node position when the document changes
|
|
95
95
|
const mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
96
96
|
pos: tr.mapping.map(activeNode.pos),
|
|
97
|
-
anchorName: activeNode.anchorName
|
|
97
|
+
anchorName: activeNode.anchorName,
|
|
98
|
+
nodeType: activeNode.nodeType
|
|
98
99
|
} : activeNode;
|
|
99
100
|
return {
|
|
100
101
|
decorations,
|
|
@@ -5,8 +5,8 @@ import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
|
5
5
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
6
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
|
|
7
7
|
import { key } from '../pm-plugins/main';
|
|
8
|
+
import { selectNode } from '../utils';
|
|
8
9
|
import { getLeftPosition, getTopPosition } from '../utils/drag-handle-positions';
|
|
9
|
-
import { getSelection } from '../utils/getSelection';
|
|
10
10
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, dragHandleGap } from './consts';
|
|
11
11
|
import { dragPreview } from './drag-preview';
|
|
12
12
|
const dragHandleButtonStyles = css({
|
|
@@ -55,14 +55,14 @@ export const DragHandle = ({
|
|
|
55
55
|
if (start === undefined) {
|
|
56
56
|
return tr;
|
|
57
57
|
}
|
|
58
|
-
tr
|
|
58
|
+
tr = selectNode(tr, start, nodeType);
|
|
59
59
|
tr.setMeta(key, {
|
|
60
60
|
pos: start
|
|
61
61
|
});
|
|
62
62
|
return tr;
|
|
63
63
|
});
|
|
64
64
|
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
|
|
65
|
-
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
65
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected, nodeType]);
|
|
66
66
|
useEffect(() => {
|
|
67
67
|
const element = buttonRef.current;
|
|
68
68
|
if (!element) {
|
|
@@ -91,7 +91,7 @@ export const DragHandle = ({
|
|
|
91
91
|
if (start === undefined) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName));
|
|
94
|
+
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
95
95
|
api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.focus();
|
|
96
96
|
},
|
|
97
97
|
onDrop() {
|
|
@@ -105,7 +105,7 @@ export const DragHandle = ({
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
}, [api, start, view, anchorName]);
|
|
108
|
+
}, [api, start, view, anchorName, nodeType]);
|
|
109
109
|
const positionStyles = useMemo(() => {
|
|
110
110
|
const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
|
|
111
111
|
const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
2
3
|
export const getSelection = (tr, start) => {
|
|
3
4
|
const node = tr.doc.nodeAt(start);
|
|
4
5
|
const isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
@@ -25,4 +26,13 @@ export const getSelection = (tr, start) => {
|
|
|
25
26
|
const textNodeDepth = textNodesPos - start;
|
|
26
27
|
return new TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
|
|
27
28
|
}
|
|
29
|
+
};
|
|
30
|
+
export const selectNode = (tr, start, nodeType) => {
|
|
31
|
+
// For table, we need to do cell selection instead of node selection
|
|
32
|
+
if (nodeType === 'table') {
|
|
33
|
+
tr = selectTableClosestToPos(tr, tr.doc.resolve(start + 1));
|
|
34
|
+
} else {
|
|
35
|
+
tr.setSelection(getSelection(tr, start));
|
|
36
|
+
}
|
|
37
|
+
return tr;
|
|
28
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getSelection } from './getSelection';
|
|
1
|
+
export { getSelection, selectNode } from './getSelection';
|
package/dist/esm/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { createPlugin, key } from './pm-plugins/main';
|
|
3
3
|
import { DragHandleMenu } from './ui/drag-handle-menu';
|
|
4
4
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
5
|
-
import {
|
|
5
|
+
import { selectNode } from './utils';
|
|
6
6
|
export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
7
7
|
var api = _ref.api;
|
|
8
8
|
return {
|
|
@@ -21,13 +21,16 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
21
21
|
var _node$nodeSize;
|
|
22
22
|
var tr = _ref2.tr;
|
|
23
23
|
var node = tr.doc.nodeAt(start);
|
|
24
|
+
if (!node) {
|
|
25
|
+
return tr;
|
|
26
|
+
}
|
|
24
27
|
var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
25
28
|
var end = start + size;
|
|
26
29
|
var nodeCopy = tr.doc.content.cut(start, end); // cut the content
|
|
27
30
|
tr.delete(start, end); // delete the content from the original position
|
|
28
31
|
var mappedTo = tr.mapping.map(to);
|
|
29
32
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
30
|
-
tr
|
|
33
|
+
tr = selectNode(tr, mappedTo, node.type.name);
|
|
31
34
|
tr.setMeta(key, {
|
|
32
35
|
nodeMoved: true
|
|
33
36
|
});
|
|
@@ -48,19 +51,20 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
48
51
|
return tr;
|
|
49
52
|
};
|
|
50
53
|
},
|
|
51
|
-
setNodeDragged: function setNodeDragged(pos, anchorName) {
|
|
54
|
+
setNodeDragged: function setNodeDragged(pos, anchorName, nodeType) {
|
|
52
55
|
return function (_ref4) {
|
|
53
56
|
var tr = _ref4.tr;
|
|
54
|
-
var newTr = tr;
|
|
55
57
|
if (pos === undefined) {
|
|
56
58
|
return tr;
|
|
57
59
|
}
|
|
58
|
-
newTr
|
|
60
|
+
var newTr = tr;
|
|
61
|
+
newTr = selectNode(newTr, pos, nodeType);
|
|
59
62
|
newTr.setMeta(key, {
|
|
60
63
|
isDragging: true,
|
|
61
64
|
activeNode: {
|
|
62
65
|
pos: pos,
|
|
63
|
-
anchorName: anchorName
|
|
66
|
+
anchorName: anchorName,
|
|
67
|
+
nodeType: nodeType
|
|
64
68
|
}
|
|
65
69
|
});
|
|
66
70
|
return newTr;
|
|
@@ -93,7 +93,8 @@ export var createPlugin = function createPlugin(api) {
|
|
|
93
93
|
// Map active node position when the document changes
|
|
94
94
|
var mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
95
95
|
pos: tr.mapping.map(activeNode.pos),
|
|
96
|
-
anchorName: activeNode.anchorName
|
|
96
|
+
anchorName: activeNode.anchorName,
|
|
97
|
+
nodeType: activeNode.nodeType
|
|
97
98
|
} : activeNode;
|
|
98
99
|
return {
|
|
99
100
|
decorations: decorations,
|
|
@@ -6,8 +6,8 @@ import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
|
6
6
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
7
7
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
|
|
8
8
|
import { key } from '../pm-plugins/main';
|
|
9
|
+
import { selectNode } from '../utils';
|
|
9
10
|
import { getLeftPosition, getTopPosition } from '../utils/drag-handle-positions';
|
|
10
|
-
import { getSelection } from '../utils/getSelection';
|
|
11
11
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, dragHandleGap } from './consts';
|
|
12
12
|
import { dragPreview } from './drag-preview';
|
|
13
13
|
var dragHandleButtonStyles = css({
|
|
@@ -57,14 +57,14 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
57
57
|
if (start === undefined) {
|
|
58
58
|
return tr;
|
|
59
59
|
}
|
|
60
|
-
tr
|
|
60
|
+
tr = selectNode(tr, start, nodeType);
|
|
61
61
|
tr.setMeta(key, {
|
|
62
62
|
pos: start
|
|
63
63
|
});
|
|
64
64
|
return tr;
|
|
65
65
|
});
|
|
66
66
|
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
67
|
-
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
67
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected, nodeType]);
|
|
68
68
|
useEffect(function () {
|
|
69
69
|
var element = buttonRef.current;
|
|
70
70
|
if (!element) {
|
|
@@ -91,7 +91,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
91
91
|
if (start === undefined) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName));
|
|
94
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType));
|
|
95
95
|
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
|
|
96
96
|
},
|
|
97
97
|
onDrop: function onDrop() {
|
|
@@ -104,7 +104,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
|
-
}, [api, start, view, anchorName]);
|
|
107
|
+
}, [api, start, view, anchorName, nodeType]);
|
|
108
108
|
var positionStyles = useMemo(function () {
|
|
109
109
|
var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
|
|
110
110
|
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
@@ -92,7 +92,7 @@ export var DropTarget = function DropTarget(_ref) {
|
|
|
92
92
|
isDraggedOver && jsx("div", {
|
|
93
93
|
css: styleDropIndicator,
|
|
94
94
|
style: {
|
|
95
|
-
|
|
95
|
+
width: "".concat(lineLength, "px")
|
|
96
96
|
},
|
|
97
97
|
"data-testid": "block-ctrl-drop-indicator"
|
|
98
98
|
}, jsx(DropIndicator, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
2
3
|
export var getSelection = function getSelection(tr, start) {
|
|
3
4
|
var node = tr.doc.nodeAt(start);
|
|
4
5
|
var isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
@@ -25,4 +26,13 @@ export var getSelection = function getSelection(tr, start) {
|
|
|
25
26
|
var textNodeDepth = textNodesPos - start;
|
|
26
27
|
return new TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
|
|
27
28
|
}
|
|
29
|
+
};
|
|
30
|
+
export var selectNode = function selectNode(tr, start, nodeType) {
|
|
31
|
+
// For table, we need to do cell selection instead of node selection
|
|
32
|
+
if (nodeType === 'table') {
|
|
33
|
+
tr = selectTableClosestToPos(tr, tr.doc.resolve(start + 1));
|
|
34
|
+
} else {
|
|
35
|
+
tr.setSelection(getSelection(tr, start));
|
|
36
|
+
}
|
|
37
|
+
return tr;
|
|
28
38
|
};
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getSelection } from './getSelection';
|
|
1
|
+
export { getSelection, selectNode } from './getSelection';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
28
28
|
commands: {
|
|
29
29
|
moveNode: (start: number, to: number) => EditorCommand;
|
|
30
30
|
showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
|
|
31
|
-
setNodeDragged: (posNumber: number, anchorName: string) => EditorCommand;
|
|
31
|
+
setNodeDragged: (posNumber: number, anchorName: string, nodeType: string) => EditorCommand;
|
|
32
32
|
};
|
|
33
33
|
}>;
|
|
34
34
|
export type DecorationState = {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
|
|
3
|
+
export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getSelection } from './getSelection';
|
|
1
|
+
export { getSelection, selectNode } from './getSelection';
|
|
@@ -30,7 +30,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
30
30
|
commands: {
|
|
31
31
|
moveNode: (start: number, to: number) => EditorCommand;
|
|
32
32
|
showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
|
|
33
|
-
setNodeDragged: (posNumber: number, anchorName: string) => EditorCommand;
|
|
33
|
+
setNodeDragged: (posNumber: number, anchorName: string, nodeType: string) => EditorCommand;
|
|
34
34
|
};
|
|
35
35
|
}>;
|
|
36
36
|
export type DecorationState = {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
|
|
3
|
+
export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getSelection } from './getSelection';
|
|
1
|
+
export { getSelection, selectNode } from './getSelection';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.11",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^82.
|
|
34
|
+
"@atlaskit/editor-common": "^82.1.0",
|
|
35
35
|
"@atlaskit/editor-plugin-width": "^1.1.0",
|
|
36
36
|
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
37
|
+
"@atlaskit/editor-tables": "^2.7.0",
|
|
37
38
|
"@atlaskit/icon": "^22.3.0",
|
|
38
39
|
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
39
40
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.3.0",
|