@atlaskit/editor-plugin-block-controls 1.3.5 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/plugin.js +4 -2
- package/dist/cjs/pm-plugins/decorations.js +15 -3
- package/dist/cjs/ui/consts.js +5 -2
- package/dist/cjs/ui/drag-handle.js +33 -26
- package/dist/cjs/ui/drop-target.js +38 -13
- package/dist/cjs/utils/getSelection.js +15 -0
- package/dist/es2019/plugin.js +4 -2
- package/dist/es2019/pm-plugins/decorations.js +15 -3
- package/dist/es2019/ui/consts.js +4 -1
- package/dist/es2019/ui/drag-handle.js +34 -24
- package/dist/es2019/ui/drop-target.js +37 -10
- package/dist/es2019/utils/getSelection.js +9 -0
- package/dist/esm/plugin.js +4 -2
- package/dist/esm/pm-plugins/decorations.js +15 -3
- package/dist/esm/ui/consts.js +4 -1
- package/dist/esm/ui/drag-handle.js +34 -27
- package/dist/esm/ui/drop-target.js +37 -10
- package/dist/esm/utils/getSelection.js +9 -0
- package/dist/types/pm-plugins/decorations.d.ts +2 -2
- package/dist/types/types.d.ts +5 -0
- package/dist/types/ui/consts.d.ts +3 -0
- package/dist/types/ui/drop-target.d.ts +2 -2
- package/dist/types/utils/getSelection.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +5 -0
- package/dist/types-ts4.5/ui/consts.d.ts +3 -0
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -2
- package/dist/types-ts4.5/utils/getSelection.d.ts +2 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.3.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#98222](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98222)
|
|
8
|
+
[`d94cd00110eb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d94cd00110eb) -
|
|
9
|
+
[ux] ED-23206 Set node selection when drag handle is clicked, dragged and content is dropped
|
|
10
|
+
- [#100193](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100193)
|
|
11
|
+
[`e9a08f4f88aa`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e9a08f4f88aa) -
|
|
12
|
+
[ux] Update drag handle position
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 1.3.6
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#100030](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100030)
|
|
20
|
+
[`f246ee5d3b7f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f246ee5d3b7f) -
|
|
21
|
+
[ux] Change drop target design, refactor styles
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 1.3.5
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -9,6 +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 _getSelection = require("./utils/getSelection");
|
|
12
13
|
var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
13
14
|
var api = _ref.api;
|
|
14
15
|
return {
|
|
@@ -24,7 +25,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
24
25
|
commands: {
|
|
25
26
|
moveNode: function moveNode(start, to) {
|
|
26
27
|
return function (_ref2) {
|
|
27
|
-
var _node$nodeSize
|
|
28
|
+
var _node$nodeSize;
|
|
28
29
|
var tr = _ref2.tr;
|
|
29
30
|
var node = tr.doc.nodeAt(start);
|
|
30
31
|
var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
@@ -33,7 +34,8 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
33
34
|
tr.delete(start, end); // delete the content from the original position
|
|
34
35
|
var mappedTo = tr.mapping.map(to);
|
|
35
36
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
36
|
-
|
|
37
|
+
tr.setSelection((0, _getSelection.getSelection)(tr, mappedTo));
|
|
38
|
+
api === null || api === void 0 || api.core.actions.focus();
|
|
37
39
|
return tr;
|
|
38
40
|
};
|
|
39
41
|
}
|
|
@@ -8,6 +8,7 @@ exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _consts = require("../ui/consts");
|
|
11
12
|
var _dragHandle = require("../ui/drag-handle");
|
|
12
13
|
var _dropTarget = require("../ui/drop-target");
|
|
13
14
|
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
@@ -55,9 +56,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
55
56
|
decorationState: decorationState
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
|
-
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(oldState,
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
meta, api) {
|
|
59
|
+
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(oldState, meta, api) {
|
|
61
60
|
return _view.DecorationSet.create(oldState.doc, [_view.Decoration.widget(meta.pos, function (view, getPos) {
|
|
62
61
|
var element = document.createElement('div');
|
|
63
62
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
|
|
@@ -66,6 +65,19 @@ meta, api) {
|
|
|
66
65
|
start: meta.pos
|
|
67
66
|
}), element);
|
|
68
67
|
element.style.position = 'absolute';
|
|
68
|
+
element.style.zIndex = '1';
|
|
69
|
+
var resizer = meta.dom.querySelector('.resizer-item');
|
|
70
|
+
if (resizer) {
|
|
71
|
+
element.style.left = "".concat(resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
72
|
+
} else {
|
|
73
|
+
element.style.left = "".concat(meta.dom.offsetLeft - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
74
|
+
}
|
|
75
|
+
if (meta.type === 'table') {
|
|
76
|
+
var table = meta.dom.querySelector('table');
|
|
77
|
+
element.style.top = "".concat(meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
|
|
78
|
+
} else {
|
|
79
|
+
element.style.top = "".concat(meta.dom.offsetTop, "px");
|
|
80
|
+
}
|
|
69
81
|
return element;
|
|
70
82
|
})]);
|
|
71
83
|
};
|
package/dist/cjs/ui/consts.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
6
|
+
exports.DROP_TARGET_LINE_WIDTH = exports.DROP_TARGET_CIRCLE_DIAMETER = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_NODE_GAP = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
7
7
|
var DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_HEIGHT = 24;
|
|
8
8
|
var DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_WIDTH = 12;
|
|
9
|
-
var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
9
|
+
var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
10
|
+
var DROP_TARGET_LINE_WIDTH = exports.DROP_TARGET_LINE_WIDTH = 2;
|
|
11
|
+
var DROP_TARGET_CIRCLE_DIAMETER = exports.DROP_TARGET_CIRCLE_DIAMETER = 4;
|
|
12
|
+
var DRAG_HANDLE_NODE_GAP = exports.DRAG_HANDLE_NODE_GAP = 12;
|
|
@@ -12,16 +12,12 @@ 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 _getSelection = require("../utils/getSelection");
|
|
15
16
|
var _consts = require("./consts");
|
|
16
17
|
var _dragPreview = require("./drag-preview");
|
|
17
18
|
/** @jsx jsx */
|
|
18
19
|
|
|
19
20
|
var dragHandleButtonStyles = (0, _react2.css)({
|
|
20
|
-
position: 'relative',
|
|
21
|
-
// TODO - we have ticket ED-23209 to correctly position the drag handle for each node
|
|
22
|
-
//https://product-fabric.atlassian.net/browse/ED-23209
|
|
23
|
-
top: 12,
|
|
24
|
-
left: -18,
|
|
25
21
|
padding: "var(--ds-space-025, 2px)".concat(" 0"),
|
|
26
22
|
boxSizing: 'border-box',
|
|
27
23
|
display: 'flex',
|
|
@@ -56,6 +52,22 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
56
52
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
57
53
|
dragHandleSelected = _useState2[0],
|
|
58
54
|
setDragHandleSelected = _useState2[1];
|
|
55
|
+
var handleClick = (0, _react.useCallback)(function () {
|
|
56
|
+
var _api$core, _api$core2;
|
|
57
|
+
setDragHandleSelected(!dragHandleSelected);
|
|
58
|
+
// TODO - add drag menu
|
|
59
|
+
// api?.core?.actions.execute(({ tr }) =>
|
|
60
|
+
// tr.setMeta(key, {
|
|
61
|
+
// toggleMenu: true,
|
|
62
|
+
// }),
|
|
63
|
+
// );
|
|
64
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
65
|
+
var tr = _ref2.tr;
|
|
66
|
+
tr.setSelection((0, _getSelection.getSelection)(tr, start));
|
|
67
|
+
return tr;
|
|
68
|
+
});
|
|
69
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
70
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
59
71
|
(0, _react.useEffect)(function () {
|
|
60
72
|
var element = buttonRef.current;
|
|
61
73
|
if (!element) {
|
|
@@ -63,8 +75,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
63
75
|
}
|
|
64
76
|
return (0, _adapter.draggable)({
|
|
65
77
|
element: element,
|
|
66
|
-
onGenerateDragPreview: function onGenerateDragPreview(
|
|
67
|
-
var nativeSetDragImage =
|
|
78
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
|
|
79
|
+
var nativeSetDragImage = _ref3.nativeSetDragImage;
|
|
68
80
|
(0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
|
|
69
81
|
getOffset: function getOffset() {
|
|
70
82
|
var rect = domRef.current.getBoundingClientRect();
|
|
@@ -74,27 +86,31 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
74
86
|
y: rect.height / 2
|
|
75
87
|
};
|
|
76
88
|
},
|
|
77
|
-
render: function render(
|
|
78
|
-
var container =
|
|
89
|
+
render: function render(_ref4) {
|
|
90
|
+
var container = _ref4.container;
|
|
79
91
|
return (0, _dragPreview.dragPreview)(container, domRef);
|
|
80
92
|
},
|
|
81
93
|
nativeSetDragImage: nativeSetDragImage
|
|
82
94
|
});
|
|
83
95
|
},
|
|
84
96
|
onDragStart: function onDragStart() {
|
|
85
|
-
var _api$
|
|
86
|
-
api === null || api === void 0 || (_api$
|
|
87
|
-
var tr =
|
|
88
|
-
|
|
97
|
+
var _api$core3, _api$core4;
|
|
98
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref5) {
|
|
99
|
+
var tr = _ref5.tr;
|
|
100
|
+
var newTr = tr;
|
|
101
|
+
newTr.setSelection((0, _getSelection.getSelection)(newTr, start));
|
|
102
|
+
newTr.setMeta(_main.key, {
|
|
89
103
|
isDragging: true,
|
|
90
104
|
start: start
|
|
91
105
|
});
|
|
106
|
+
return newTr;
|
|
92
107
|
});
|
|
108
|
+
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
|
|
93
109
|
},
|
|
94
110
|
onDrop: function onDrop() {
|
|
95
|
-
var _api$
|
|
96
|
-
api === null || api === void 0 || (_api$
|
|
97
|
-
var tr =
|
|
111
|
+
var _api$core5;
|
|
112
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
|
|
113
|
+
var tr = _ref6.tr;
|
|
98
114
|
return tr.setMeta(_main.key, {
|
|
99
115
|
isDragging: false
|
|
100
116
|
});
|
|
@@ -106,16 +122,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
106
122
|
type: "button",
|
|
107
123
|
css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
|
|
108
124
|
ref: buttonRef,
|
|
109
|
-
onClick:
|
|
110
|
-
setDragHandleSelected(!dragHandleSelected);
|
|
111
|
-
|
|
112
|
-
// TODO - add drag menu
|
|
113
|
-
// api?.core?.actions.execute(({ tr }) =>
|
|
114
|
-
// tr.setMeta(key, {
|
|
115
|
-
// toggleMenu: true,
|
|
116
|
-
// }),
|
|
117
|
-
// );
|
|
118
|
-
}
|
|
125
|
+
onClick: handleClick
|
|
119
126
|
}, (0, _react2.jsx)(_dragHandler.default, {
|
|
120
127
|
label: "",
|
|
121
128
|
size: "medium"
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.DropTarget = void 0;
|
|
9
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _react2 = require("@emotion/react");
|
|
11
11
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
13
|
+
var _consts = require("./consts");
|
|
14
|
+
/** @jsx jsx */
|
|
15
|
+
|
|
16
|
+
var styleHighlighted = (0, _react2.css)({
|
|
17
|
+
height: "var(--ds-space-100, 8px)",
|
|
18
|
+
marginTop: "calc(".concat("var(--ds-space-negative-100, -8px)", " - ", _consts.DROP_TARGET_LINE_WIDTH, "px)"),
|
|
19
|
+
marginLeft: "var(--ds-space-negative-100, -8px)",
|
|
20
|
+
top: "calc(".concat("var(--ds-space-100, 8px)", " / 2 - 2.5px)"),
|
|
21
|
+
//2.5px to help clear expand node margin
|
|
22
|
+
position: 'relative',
|
|
23
|
+
borderBottom: "solid ".concat("var(--ds-border-selected, ".concat(_colors.B300, ")"), " ", _consts.DROP_TARGET_LINE_WIDTH, "px"),
|
|
24
|
+
"&:before": {
|
|
25
|
+
content: '""',
|
|
26
|
+
width: "".concat(_consts.DROP_TARGET_CIRCLE_DIAMETER, "px"),
|
|
27
|
+
height: "".concat(_consts.DROP_TARGET_CIRCLE_DIAMETER, "px"),
|
|
28
|
+
marginTop: "calc(".concat(_consts.DROP_TARGET_CIRCLE_DIAMETER, " + ").concat(_consts.DROP_TARGET_LINE_WIDTH, " * 2)px"),
|
|
29
|
+
borderRadius: '50%',
|
|
30
|
+
border: "solid ".concat("var(--ds-border-selected, ".concat(_colors.B300, ")"), " ", _consts.DROP_TARGET_LINE_WIDTH, "px"),
|
|
31
|
+
backgroundColor: "var(--ds-background-input, white)",
|
|
32
|
+
display: 'block',
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
bottom: '-5px'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var styleDisabled = (0, _react2.css)({
|
|
38
|
+
height: "var(--ds-space-100, 8px)",
|
|
39
|
+
marginTop: "calc(".concat("var(--ds-space-negative-100, -8px)", " - ", _consts.DROP_TARGET_LINE_WIDTH, "px)"),
|
|
40
|
+
position: 'relative',
|
|
41
|
+
borderBottom: "solid transparent ".concat(_consts.DROP_TARGET_LINE_WIDTH, "px"),
|
|
42
|
+
"&:before": {
|
|
43
|
+
border: "solid transparent ".concat(_consts.DROP_TARGET_LINE_WIDTH, "px")
|
|
44
|
+
}
|
|
45
|
+
});
|
|
14
46
|
var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
15
47
|
var api = _ref.api,
|
|
16
48
|
index = _ref.index;
|
|
@@ -56,16 +88,9 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
56
88
|
});
|
|
57
89
|
}, [index, api]);
|
|
58
90
|
return (
|
|
59
|
-
/*#__PURE__*/
|
|
60
91
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
height: '20px',
|
|
64
|
-
marginTop: '-22px',
|
|
65
|
-
top: '10px',
|
|
66
|
-
position: 'relative',
|
|
67
|
-
borderBottom: "solid ".concat(isDraggedOver ? 'blue' : 'transparent', " 2px")
|
|
68
|
-
},
|
|
92
|
+
(0, _react2.jsx)("div", {
|
|
93
|
+
css: isDraggedOver ? styleHighlighted : styleDisabled,
|
|
69
94
|
ref: ref
|
|
70
95
|
})
|
|
71
96
|
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelection = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var getSelection = exports.getSelection = function getSelection(tr, start) {
|
|
9
|
+
var node = tr.doc.nodeAt(start);
|
|
10
|
+
var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
|
|
11
|
+
var nodeSize = node ? node.nodeSize : 1;
|
|
12
|
+
var depth = tr.doc.resolve(start).depth;
|
|
13
|
+
var selection = isNodeSelection ? new _state.NodeSelection(tr.doc.resolve(start)) : new _state.TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
|
|
14
|
+
return selection;
|
|
15
|
+
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -2,6 +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 { getSelection } from './utils/getSelection';
|
|
5
6
|
export const blockControlsPlugin = ({
|
|
6
7
|
api
|
|
7
8
|
}) => ({
|
|
@@ -16,7 +17,7 @@ export const blockControlsPlugin = ({
|
|
|
16
17
|
moveNode: (start, to) => ({
|
|
17
18
|
tr
|
|
18
19
|
}) => {
|
|
19
|
-
var _node$nodeSize
|
|
20
|
+
var _node$nodeSize;
|
|
20
21
|
const node = tr.doc.nodeAt(start);
|
|
21
22
|
const size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
22
23
|
const end = start + size;
|
|
@@ -24,7 +25,8 @@ export const blockControlsPlugin = ({
|
|
|
24
25
|
tr.delete(start, end); // delete the content from the original position
|
|
25
26
|
const mappedTo = tr.mapping.map(to);
|
|
26
27
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
27
|
-
|
|
28
|
+
tr.setSelection(getSelection(tr, mappedTo));
|
|
29
|
+
api === null || api === void 0 ? void 0 : api.core.actions.focus();
|
|
28
30
|
return tr;
|
|
29
31
|
}
|
|
30
32
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { DRAG_HANDLE_NODE_GAP, DRAG_HANDLE_WIDTH } from '../ui/consts';
|
|
4
5
|
import { DragHandle } from '../ui/drag-handle';
|
|
5
6
|
import { DropTarget } from '../ui/drop-target';
|
|
6
7
|
export const dropTargetDecorations = (oldState, newState, api) => {
|
|
@@ -48,9 +49,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
48
49
|
decorationState
|
|
49
50
|
};
|
|
50
51
|
};
|
|
51
|
-
export const dragHandleDecoration = (oldState,
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
meta, api) => {
|
|
52
|
+
export const dragHandleDecoration = (oldState, meta, api) => {
|
|
54
53
|
return DecorationSet.create(oldState.doc, [Decoration.widget(meta.pos, (view, getPos) => {
|
|
55
54
|
const element = document.createElement('div');
|
|
56
55
|
ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
|
|
@@ -59,6 +58,19 @@ meta, api) => {
|
|
|
59
58
|
start: meta.pos
|
|
60
59
|
}), element);
|
|
61
60
|
element.style.position = 'absolute';
|
|
61
|
+
element.style.zIndex = '1';
|
|
62
|
+
const resizer = meta.dom.querySelector('.resizer-item');
|
|
63
|
+
if (resizer) {
|
|
64
|
+
element.style.left = `${resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH}px`;
|
|
65
|
+
} else {
|
|
66
|
+
element.style.left = `${meta.dom.offsetLeft - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH}px`;
|
|
67
|
+
}
|
|
68
|
+
if (meta.type === 'table') {
|
|
69
|
+
const table = meta.dom.querySelector('table');
|
|
70
|
+
element.style.top = `${meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0)}px`;
|
|
71
|
+
} else {
|
|
72
|
+
element.style.top = `${meta.dom.offsetTop}px`;
|
|
73
|
+
}
|
|
62
74
|
return element;
|
|
63
75
|
})]);
|
|
64
76
|
};
|
package/dist/es2019/ui/consts.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export const DRAG_HANDLE_HEIGHT = 24;
|
|
2
2
|
export const DRAG_HANDLE_WIDTH = 12;
|
|
3
|
-
export const DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
3
|
+
export const DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
4
|
+
export const DROP_TARGET_LINE_WIDTH = 2;
|
|
5
|
+
export const DROP_TARGET_CIRCLE_DIAMETER = 4;
|
|
6
|
+
export const DRAG_HANDLE_NODE_GAP = 12;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { css, jsx } from '@emotion/react';
|
|
4
4
|
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 { getSelection } from '../utils/getSelection';
|
|
8
9
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
|
|
9
10
|
import { dragPreview } from './drag-preview';
|
|
10
11
|
const dragHandleButtonStyles = css({
|
|
11
|
-
position: 'relative',
|
|
12
|
-
// TODO - we have ticket ED-23209 to correctly position the drag handle for each node
|
|
13
|
-
//https://product-fabric.atlassian.net/browse/ED-23209
|
|
14
|
-
top: 12,
|
|
15
|
-
left: -18,
|
|
16
12
|
padding: `${"var(--ds-space-025, 2px)"} 0`,
|
|
17
13
|
boxSizing: 'border-box',
|
|
18
14
|
display: 'flex',
|
|
@@ -45,6 +41,23 @@ export const DragHandle = ({
|
|
|
45
41
|
const buttonRef = useRef(null);
|
|
46
42
|
const domRef = useRef(dom);
|
|
47
43
|
const [dragHandleSelected, setDragHandleSelected] = useState(false);
|
|
44
|
+
const handleClick = useCallback(() => {
|
|
45
|
+
var _api$core, _api$core2;
|
|
46
|
+
setDragHandleSelected(!dragHandleSelected);
|
|
47
|
+
// TODO - add drag menu
|
|
48
|
+
// api?.core?.actions.execute(({ tr }) =>
|
|
49
|
+
// tr.setMeta(key, {
|
|
50
|
+
// toggleMenu: true,
|
|
51
|
+
// }),
|
|
52
|
+
// );
|
|
53
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
54
|
+
tr
|
|
55
|
+
}) => {
|
|
56
|
+
tr.setSelection(getSelection(tr, start));
|
|
57
|
+
return tr;
|
|
58
|
+
});
|
|
59
|
+
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
|
|
60
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
48
61
|
useEffect(() => {
|
|
49
62
|
const element = buttonRef.current;
|
|
50
63
|
if (!element) {
|
|
@@ -73,17 +86,23 @@ export const DragHandle = ({
|
|
|
73
86
|
});
|
|
74
87
|
},
|
|
75
88
|
onDragStart() {
|
|
76
|
-
var _api$
|
|
77
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
89
|
+
var _api$core3, _api$core4;
|
|
90
|
+
api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
|
|
78
91
|
tr
|
|
79
|
-
}) =>
|
|
80
|
-
|
|
81
|
-
start
|
|
82
|
-
|
|
92
|
+
}) => {
|
|
93
|
+
const newTr = tr;
|
|
94
|
+
newTr.setSelection(getSelection(newTr, start));
|
|
95
|
+
newTr.setMeta(key, {
|
|
96
|
+
isDragging: true,
|
|
97
|
+
start
|
|
98
|
+
});
|
|
99
|
+
return newTr;
|
|
100
|
+
});
|
|
101
|
+
api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.focus();
|
|
83
102
|
},
|
|
84
103
|
onDrop() {
|
|
85
|
-
var _api$
|
|
86
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
104
|
+
var _api$core5;
|
|
105
|
+
api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
|
|
87
106
|
tr
|
|
88
107
|
}) => tr.setMeta(key, {
|
|
89
108
|
isDragging: false
|
|
@@ -95,16 +114,7 @@ export const DragHandle = ({
|
|
|
95
114
|
type: "button",
|
|
96
115
|
css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
|
|
97
116
|
ref: buttonRef,
|
|
98
|
-
onClick:
|
|
99
|
-
setDragHandleSelected(!dragHandleSelected);
|
|
100
|
-
|
|
101
|
-
// TODO - add drag menu
|
|
102
|
-
// api?.core?.actions.execute(({ tr }) =>
|
|
103
|
-
// tr.setMeta(key, {
|
|
104
|
-
// toggleMenu: true,
|
|
105
|
-
// }),
|
|
106
|
-
// );
|
|
107
|
-
}
|
|
117
|
+
onClick: handleClick
|
|
108
118
|
}, jsx(DragHandlerIcon, {
|
|
109
119
|
label: "",
|
|
110
120
|
size: "medium"
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
2
4
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
5
|
+
import { B300 } from '@atlaskit/theme/colors';
|
|
6
|
+
import { DROP_TARGET_CIRCLE_DIAMETER, DROP_TARGET_LINE_WIDTH } from './consts';
|
|
7
|
+
const styleHighlighted = css({
|
|
8
|
+
height: "var(--ds-space-100, 8px)",
|
|
9
|
+
marginTop: `calc(${"var(--ds-space-negative-100, -8px)"} - ${DROP_TARGET_LINE_WIDTH}px)`,
|
|
10
|
+
marginLeft: "var(--ds-space-negative-100, -8px)",
|
|
11
|
+
top: `calc(${"var(--ds-space-100, 8px)"} / 2 - 2.5px)`,
|
|
12
|
+
//2.5px to help clear expand node margin
|
|
13
|
+
position: 'relative',
|
|
14
|
+
borderBottom: `solid ${`var(--ds-border-selected, ${B300})`} ${DROP_TARGET_LINE_WIDTH}px`,
|
|
15
|
+
"&:before": {
|
|
16
|
+
content: '""',
|
|
17
|
+
width: `${DROP_TARGET_CIRCLE_DIAMETER}px`,
|
|
18
|
+
height: `${DROP_TARGET_CIRCLE_DIAMETER}px`,
|
|
19
|
+
marginTop: `calc(${DROP_TARGET_CIRCLE_DIAMETER} + ${DROP_TARGET_LINE_WIDTH} * 2)px`,
|
|
20
|
+
borderRadius: '50%',
|
|
21
|
+
border: `solid ${`var(--ds-border-selected, ${B300})`} ${DROP_TARGET_LINE_WIDTH}px`,
|
|
22
|
+
backgroundColor: "var(--ds-background-input, white)",
|
|
23
|
+
display: 'block',
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
bottom: '-5px'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const styleDisabled = css({
|
|
29
|
+
height: "var(--ds-space-100, 8px)",
|
|
30
|
+
marginTop: `calc(${"var(--ds-space-negative-100, -8px)"} - ${DROP_TARGET_LINE_WIDTH}px)`,
|
|
31
|
+
position: 'relative',
|
|
32
|
+
borderBottom: `solid transparent ${DROP_TARGET_LINE_WIDTH}px`,
|
|
33
|
+
"&:before": {
|
|
34
|
+
border: `solid transparent ${DROP_TARGET_LINE_WIDTH}px`
|
|
35
|
+
}
|
|
36
|
+
});
|
|
3
37
|
export const DropTarget = ({
|
|
4
38
|
api,
|
|
5
39
|
index
|
|
@@ -39,16 +73,9 @@ export const DropTarget = ({
|
|
|
39
73
|
});
|
|
40
74
|
}, [index, api]);
|
|
41
75
|
return (
|
|
42
|
-
/*#__PURE__*/
|
|
43
76
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
height: '20px',
|
|
47
|
-
marginTop: '-22px',
|
|
48
|
-
top: '10px',
|
|
49
|
-
position: 'relative',
|
|
50
|
-
borderBottom: `solid ${isDraggedOver ? 'blue' : 'transparent'} 2px`
|
|
51
|
-
},
|
|
77
|
+
jsx("div", {
|
|
78
|
+
css: isDraggedOver ? styleHighlighted : styleDisabled,
|
|
52
79
|
ref: ref
|
|
53
80
|
})
|
|
54
81
|
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export const getSelection = (tr, start) => {
|
|
3
|
+
const node = tr.doc.nodeAt(start);
|
|
4
|
+
const isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
5
|
+
const nodeSize = node ? node.nodeSize : 1;
|
|
6
|
+
const depth = tr.doc.resolve(start).depth;
|
|
7
|
+
const selection = isNodeSelection ? new NodeSelection(tr.doc.resolve(start)) : new TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
|
|
8
|
+
return selection;
|
|
9
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -2,6 +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 { getSelection } from './utils/getSelection';
|
|
5
6
|
export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
6
7
|
var api = _ref.api;
|
|
7
8
|
return {
|
|
@@ -17,7 +18,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
17
18
|
commands: {
|
|
18
19
|
moveNode: function moveNode(start, to) {
|
|
19
20
|
return function (_ref2) {
|
|
20
|
-
var _node$nodeSize
|
|
21
|
+
var _node$nodeSize;
|
|
21
22
|
var tr = _ref2.tr;
|
|
22
23
|
var node = tr.doc.nodeAt(start);
|
|
23
24
|
var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
|
|
@@ -26,7 +27,8 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
26
27
|
tr.delete(start, end); // delete the content from the original position
|
|
27
28
|
var mappedTo = tr.mapping.map(to);
|
|
28
29
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
29
|
-
|
|
30
|
+
tr.setSelection(getSelection(tr, mappedTo));
|
|
31
|
+
api === null || api === void 0 || api.core.actions.focus();
|
|
30
32
|
return tr;
|
|
31
33
|
};
|
|
32
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { DRAG_HANDLE_NODE_GAP, DRAG_HANDLE_WIDTH } from '../ui/consts';
|
|
4
5
|
import { DragHandle } from '../ui/drag-handle';
|
|
5
6
|
import { DropTarget } from '../ui/drop-target';
|
|
6
7
|
export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
@@ -48,9 +49,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
48
49
|
decorationState: decorationState
|
|
49
50
|
};
|
|
50
51
|
};
|
|
51
|
-
export var dragHandleDecoration = function dragHandleDecoration(oldState,
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
meta, api) {
|
|
52
|
+
export var dragHandleDecoration = function dragHandleDecoration(oldState, meta, api) {
|
|
54
53
|
return DecorationSet.create(oldState.doc, [Decoration.widget(meta.pos, function (view, getPos) {
|
|
55
54
|
var element = document.createElement('div');
|
|
56
55
|
ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
|
|
@@ -59,6 +58,19 @@ meta, api) {
|
|
|
59
58
|
start: meta.pos
|
|
60
59
|
}), element);
|
|
61
60
|
element.style.position = 'absolute';
|
|
61
|
+
element.style.zIndex = '1';
|
|
62
|
+
var resizer = meta.dom.querySelector('.resizer-item');
|
|
63
|
+
if (resizer) {
|
|
64
|
+
element.style.left = "".concat(resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH, "px");
|
|
65
|
+
} else {
|
|
66
|
+
element.style.left = "".concat(meta.dom.offsetLeft - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH, "px");
|
|
67
|
+
}
|
|
68
|
+
if (meta.type === 'table') {
|
|
69
|
+
var table = meta.dom.querySelector('table');
|
|
70
|
+
element.style.top = "".concat(meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
|
|
71
|
+
} else {
|
|
72
|
+
element.style.top = "".concat(meta.dom.offsetTop, "px");
|
|
73
|
+
}
|
|
62
74
|
return element;
|
|
63
75
|
})]);
|
|
64
76
|
};
|
package/dist/esm/ui/consts.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export var DRAG_HANDLE_HEIGHT = 24;
|
|
2
2
|
export var DRAG_HANDLE_WIDTH = 12;
|
|
3
|
-
export var DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
3
|
+
export var DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
4
|
+
export var DROP_TARGET_LINE_WIDTH = 2;
|
|
5
|
+
export var DROP_TARGET_CIRCLE_DIAMETER = 4;
|
|
6
|
+
export var DRAG_HANDLE_NODE_GAP = 12;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { css, jsx } from '@emotion/react';
|
|
5
5
|
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 { getSelection } from '../utils/getSelection';
|
|
9
10
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
|
|
10
11
|
import { dragPreview } from './drag-preview';
|
|
11
12
|
var dragHandleButtonStyles = css({
|
|
12
|
-
position: 'relative',
|
|
13
|
-
// TODO - we have ticket ED-23209 to correctly position the drag handle for each node
|
|
14
|
-
//https://product-fabric.atlassian.net/browse/ED-23209
|
|
15
|
-
top: 12,
|
|
16
|
-
left: -18,
|
|
17
13
|
padding: "var(--ds-space-025, 2px)".concat(" 0"),
|
|
18
14
|
boxSizing: 'border-box',
|
|
19
15
|
display: 'flex',
|
|
@@ -48,6 +44,22 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
48
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
49
45
|
dragHandleSelected = _useState2[0],
|
|
50
46
|
setDragHandleSelected = _useState2[1];
|
|
47
|
+
var handleClick = useCallback(function () {
|
|
48
|
+
var _api$core, _api$core2;
|
|
49
|
+
setDragHandleSelected(!dragHandleSelected);
|
|
50
|
+
// TODO - add drag menu
|
|
51
|
+
// api?.core?.actions.execute(({ tr }) =>
|
|
52
|
+
// tr.setMeta(key, {
|
|
53
|
+
// toggleMenu: true,
|
|
54
|
+
// }),
|
|
55
|
+
// );
|
|
56
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
57
|
+
var tr = _ref2.tr;
|
|
58
|
+
tr.setSelection(getSelection(tr, start));
|
|
59
|
+
return tr;
|
|
60
|
+
});
|
|
61
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
62
|
+
}, [start, api, dragHandleSelected, setDragHandleSelected]);
|
|
51
63
|
useEffect(function () {
|
|
52
64
|
var element = buttonRef.current;
|
|
53
65
|
if (!element) {
|
|
@@ -55,8 +67,8 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
55
67
|
}
|
|
56
68
|
return draggable({
|
|
57
69
|
element: element,
|
|
58
|
-
onGenerateDragPreview: function onGenerateDragPreview(
|
|
59
|
-
var nativeSetDragImage =
|
|
70
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
|
|
71
|
+
var nativeSetDragImage = _ref3.nativeSetDragImage;
|
|
60
72
|
setCustomNativeDragPreview({
|
|
61
73
|
getOffset: function getOffset() {
|
|
62
74
|
var rect = domRef.current.getBoundingClientRect();
|
|
@@ -66,27 +78,31 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
66
78
|
y: rect.height / 2
|
|
67
79
|
};
|
|
68
80
|
},
|
|
69
|
-
render: function render(
|
|
70
|
-
var container =
|
|
81
|
+
render: function render(_ref4) {
|
|
82
|
+
var container = _ref4.container;
|
|
71
83
|
return dragPreview(container, domRef);
|
|
72
84
|
},
|
|
73
85
|
nativeSetDragImage: nativeSetDragImage
|
|
74
86
|
});
|
|
75
87
|
},
|
|
76
88
|
onDragStart: function onDragStart() {
|
|
77
|
-
var _api$
|
|
78
|
-
api === null || api === void 0 || (_api$
|
|
79
|
-
var tr =
|
|
80
|
-
|
|
89
|
+
var _api$core3, _api$core4;
|
|
90
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref5) {
|
|
91
|
+
var tr = _ref5.tr;
|
|
92
|
+
var newTr = tr;
|
|
93
|
+
newTr.setSelection(getSelection(newTr, start));
|
|
94
|
+
newTr.setMeta(key, {
|
|
81
95
|
isDragging: true,
|
|
82
96
|
start: start
|
|
83
97
|
});
|
|
98
|
+
return newTr;
|
|
84
99
|
});
|
|
100
|
+
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
|
|
85
101
|
},
|
|
86
102
|
onDrop: function onDrop() {
|
|
87
|
-
var _api$
|
|
88
|
-
api === null || api === void 0 || (_api$
|
|
89
|
-
var tr =
|
|
103
|
+
var _api$core5;
|
|
104
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
|
|
105
|
+
var tr = _ref6.tr;
|
|
90
106
|
return tr.setMeta(key, {
|
|
91
107
|
isDragging: false
|
|
92
108
|
});
|
|
@@ -98,16 +114,7 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
98
114
|
type: "button",
|
|
99
115
|
css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
|
|
100
116
|
ref: buttonRef,
|
|
101
|
-
onClick:
|
|
102
|
-
setDragHandleSelected(!dragHandleSelected);
|
|
103
|
-
|
|
104
|
-
// TODO - add drag menu
|
|
105
|
-
// api?.core?.actions.execute(({ tr }) =>
|
|
106
|
-
// tr.setMeta(key, {
|
|
107
|
-
// toggleMenu: true,
|
|
108
|
-
// }),
|
|
109
|
-
// );
|
|
110
|
-
}
|
|
117
|
+
onClick: handleClick
|
|
111
118
|
}, jsx(DragHandlerIcon, {
|
|
112
119
|
label: "",
|
|
113
120
|
size: "medium"
|
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
3
5
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
|
+
import { B300 } from '@atlaskit/theme/colors';
|
|
7
|
+
import { DROP_TARGET_CIRCLE_DIAMETER, DROP_TARGET_LINE_WIDTH } from './consts';
|
|
8
|
+
var styleHighlighted = css({
|
|
9
|
+
height: "var(--ds-space-100, 8px)",
|
|
10
|
+
marginTop: "calc(".concat("var(--ds-space-negative-100, -8px)", " - ", DROP_TARGET_LINE_WIDTH, "px)"),
|
|
11
|
+
marginLeft: "var(--ds-space-negative-100, -8px)",
|
|
12
|
+
top: "calc(".concat("var(--ds-space-100, 8px)", " / 2 - 2.5px)"),
|
|
13
|
+
//2.5px to help clear expand node margin
|
|
14
|
+
position: 'relative',
|
|
15
|
+
borderBottom: "solid ".concat("var(--ds-border-selected, ".concat(B300, ")"), " ", DROP_TARGET_LINE_WIDTH, "px"),
|
|
16
|
+
"&:before": {
|
|
17
|
+
content: '""',
|
|
18
|
+
width: "".concat(DROP_TARGET_CIRCLE_DIAMETER, "px"),
|
|
19
|
+
height: "".concat(DROP_TARGET_CIRCLE_DIAMETER, "px"),
|
|
20
|
+
marginTop: "calc(".concat(DROP_TARGET_CIRCLE_DIAMETER, " + ").concat(DROP_TARGET_LINE_WIDTH, " * 2)px"),
|
|
21
|
+
borderRadius: '50%',
|
|
22
|
+
border: "solid ".concat("var(--ds-border-selected, ".concat(B300, ")"), " ", DROP_TARGET_LINE_WIDTH, "px"),
|
|
23
|
+
backgroundColor: "var(--ds-background-input, white)",
|
|
24
|
+
display: 'block',
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
bottom: '-5px'
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var styleDisabled = css({
|
|
30
|
+
height: "var(--ds-space-100, 8px)",
|
|
31
|
+
marginTop: "calc(".concat("var(--ds-space-negative-100, -8px)", " - ", DROP_TARGET_LINE_WIDTH, "px)"),
|
|
32
|
+
position: 'relative',
|
|
33
|
+
borderBottom: "solid transparent ".concat(DROP_TARGET_LINE_WIDTH, "px"),
|
|
34
|
+
"&:before": {
|
|
35
|
+
border: "solid transparent ".concat(DROP_TARGET_LINE_WIDTH, "px")
|
|
36
|
+
}
|
|
37
|
+
});
|
|
4
38
|
export var DropTarget = function DropTarget(_ref) {
|
|
5
39
|
var api = _ref.api,
|
|
6
40
|
index = _ref.index;
|
|
@@ -46,16 +80,9 @@ export var DropTarget = function DropTarget(_ref) {
|
|
|
46
80
|
});
|
|
47
81
|
}, [index, api]);
|
|
48
82
|
return (
|
|
49
|
-
/*#__PURE__*/
|
|
50
83
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
height: '20px',
|
|
54
|
-
marginTop: '-22px',
|
|
55
|
-
top: '10px',
|
|
56
|
-
position: 'relative',
|
|
57
|
-
borderBottom: "solid ".concat(isDraggedOver ? 'blue' : 'transparent', " 2px")
|
|
58
|
-
},
|
|
84
|
+
jsx("div", {
|
|
85
|
+
css: isDraggedOver ? styleHighlighted : styleDisabled,
|
|
59
86
|
ref: ref
|
|
60
87
|
})
|
|
61
88
|
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export var getSelection = function getSelection(tr, start) {
|
|
3
|
+
var node = tr.doc.nodeAt(start);
|
|
4
|
+
var isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
5
|
+
var nodeSize = node ? node.nodeSize : 1;
|
|
6
|
+
var depth = tr.doc.resolve(start).depth;
|
|
7
|
+
var selection = isNodeSelection ? new NodeSelection(tr.doc.resolve(start)) : new TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
|
|
8
|
+
return selection;
|
|
9
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
import type { BlockControlsMeta, BlockControlsPlugin } from '../types';
|
|
5
5
|
export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
6
6
|
decs: Decoration[];
|
|
7
7
|
decorationState: {
|
|
@@ -9,4 +9,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
9
9
|
pos: number;
|
|
10
10
|
}[];
|
|
11
11
|
};
|
|
12
|
-
export declare const dragHandleDecoration: (oldState: EditorState, meta:
|
|
12
|
+
export declare const dragHandleDecoration: (oldState: EditorState, meta: BlockControlsMeta, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const DRAG_HANDLE_HEIGHT = 24;
|
|
2
2
|
export declare const DRAG_HANDLE_WIDTH = 12;
|
|
3
3
|
export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
4
|
+
export declare const DROP_TARGET_LINE_WIDTH = 2;
|
|
5
|
+
export declare const DROP_TARGET_CIRCLE_DIAMETER = 4;
|
|
6
|
+
export declare const DRAG_HANDLE_NODE_GAP = 12;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { BlockControlsPlugin } from '../types';
|
|
4
4
|
export declare const DropTarget: ({ api, index, }: {
|
|
5
5
|
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
6
|
index: number;
|
|
7
|
-
}) => JSX.Element;
|
|
7
|
+
}) => jsx.JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
import type { BlockControlsMeta, BlockControlsPlugin } from '../types';
|
|
5
5
|
export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
6
6
|
decs: Decoration[];
|
|
7
7
|
decorationState: {
|
|
@@ -9,4 +9,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
9
9
|
pos: number;
|
|
10
10
|
}[];
|
|
11
11
|
};
|
|
12
|
-
export declare const dragHandleDecoration: (oldState: EditorState, meta:
|
|
12
|
+
export declare const dragHandleDecoration: (oldState: EditorState, meta: BlockControlsMeta, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const DRAG_HANDLE_HEIGHT = 24;
|
|
2
2
|
export declare const DRAG_HANDLE_WIDTH = 12;
|
|
3
3
|
export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
4
|
+
export declare const DROP_TARGET_LINE_WIDTH = 2;
|
|
5
|
+
export declare const DROP_TARGET_CIRCLE_DIAMETER = 4;
|
|
6
|
+
export declare const DRAG_HANDLE_NODE_GAP = 12;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { BlockControlsPlugin } from '../types';
|
|
4
4
|
export declare const DropTarget: ({ api, index, }: {
|
|
5
5
|
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
6
|
index: number;
|
|
7
|
-
}) => JSX.Element;
|
|
7
|
+
}) => jsx.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^80.
|
|
34
|
+
"@atlaskit/editor-common": "^80.2.0",
|
|
35
35
|
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
36
|
-
"@atlaskit/icon": "^22.
|
|
36
|
+
"@atlaskit/icon": "^22.2.0",
|
|
37
37
|
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
38
|
+
"@atlaskit/theme": "^12.8.0",
|
|
38
39
|
"@atlaskit/tokens": "^1.48.0",
|
|
39
40
|
"@babel/runtime": "^7.0.0",
|
|
40
41
|
"@emotion/react": "^11.7.1"
|