@atlaskit/editor-plugin-block-controls 1.4.8 → 1.4.10
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 +34 -0
- package/dist/cjs/pm-plugins/decorations.js +60 -25
- package/dist/cjs/pm-plugins/main.js +81 -60
- package/dist/cjs/ui/consts.js +8 -2
- package/dist/cjs/ui/drag-handle.js +48 -26
- package/dist/cjs/ui/drag-preview.js +4 -4
- package/dist/cjs/ui/drop-target.js +22 -2
- package/dist/cjs/ui/mouse-move-wrapper.js +92 -0
- package/dist/cjs/utils/drag-handle-positions.js +23 -0
- package/dist/es2019/plugin.js +32 -0
- package/dist/es2019/pm-plugins/decorations.js +60 -25
- package/dist/es2019/pm-plugins/main.js +73 -55
- package/dist/es2019/ui/consts.js +7 -1
- package/dist/es2019/ui/drag-handle.js +53 -30
- package/dist/es2019/ui/drag-preview.js +4 -4
- package/dist/es2019/ui/drop-target.js +23 -2
- package/dist/es2019/ui/mouse-move-wrapper.js +77 -0
- package/dist/es2019/utils/drag-handle-positions.js +17 -0
- package/dist/esm/plugin.js +34 -0
- package/dist/esm/pm-plugins/decorations.js +60 -25
- package/dist/esm/pm-plugins/main.js +81 -61
- package/dist/esm/ui/consts.js +7 -1
- package/dist/esm/ui/drag-handle.js +50 -28
- package/dist/esm/ui/drag-preview.js +4 -4
- package/dist/esm/ui/drop-target.js +22 -2
- package/dist/esm/ui/mouse-move-wrapper.js +84 -0
- package/dist/esm/utils/drag-handle-positions.js +17 -0
- package/dist/types/plugin.d.ts +2 -2
- package/dist/types/pm-plugins/decorations.d.ts +10 -3
- package/dist/types/types.d.ts +17 -5
- package/dist/types/ui/consts.d.ts +1 -1
- package/dist/types/ui/drag-handle.d.ts +6 -3
- package/dist/types/ui/drag-preview.d.ts +1 -1
- package/dist/types/ui/mouse-move-wrapper.d.ts +11 -0
- package/dist/types/utils/drag-handle-positions.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +10 -3
- package/dist/types-ts4.5/types.d.ts +17 -4
- package/dist/types-ts4.5/ui/consts.d.ts +1 -1
- package/dist/types-ts4.5/ui/drag-handle.d.ts +6 -3
- package/dist/types-ts4.5/ui/drag-preview.d.ts +1 -1
- package/dist/types-ts4.5/ui/mouse-move-wrapper.d.ts +11 -0
- package/dist/types-ts4.5/utils/drag-handle-positions.d.ts +2 -0
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.4.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#105071](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/105071)
|
|
8
|
+
[`e70e9b713e1e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e70e9b713e1e) -
|
|
9
|
+
ED23246 - Refactor decorations to render wrapper around each node to track mouseenter events and
|
|
10
|
+
show drag handle when active node is set
|
|
11
|
+
|
|
12
|
+
## 1.4.9
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#106586](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/106586)
|
|
17
|
+
[`861ecd061c72`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/861ecd061c72) -
|
|
18
|
+
Increase the editor page guttering for full page appearance to support block drag and drop
|
|
19
|
+
- [#107579](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107579)
|
|
20
|
+
[`4953d4a32c98`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4953d4a32c98) -
|
|
21
|
+
[ux] Expand blocks drop target to full doc width
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 1.4.8
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -35,9 +35,43 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
35
35
|
var mappedTo = tr.mapping.map(to);
|
|
36
36
|
tr.insert(mappedTo, nodeCopy); // insert the content at the new position
|
|
37
37
|
tr.setSelection((0, _getSelection.getSelection)(tr, mappedTo));
|
|
38
|
+
tr.setMeta(_main.key, {
|
|
39
|
+
nodeMoved: true
|
|
40
|
+
});
|
|
38
41
|
api === null || api === void 0 || api.core.actions.focus();
|
|
39
42
|
return tr;
|
|
40
43
|
};
|
|
44
|
+
},
|
|
45
|
+
showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType) {
|
|
46
|
+
return function (_ref3) {
|
|
47
|
+
var tr = _ref3.tr;
|
|
48
|
+
tr.setMeta(_main.key, {
|
|
49
|
+
activeNode: {
|
|
50
|
+
pos: pos,
|
|
51
|
+
anchorName: anchorName,
|
|
52
|
+
nodeType: nodeType
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return tr;
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
setNodeDragged: function setNodeDragged(pos, anchorName) {
|
|
59
|
+
return function (_ref4) {
|
|
60
|
+
var tr = _ref4.tr;
|
|
61
|
+
var newTr = tr;
|
|
62
|
+
if (pos === undefined) {
|
|
63
|
+
return tr;
|
|
64
|
+
}
|
|
65
|
+
newTr.setSelection((0, _getSelection.getSelection)(newTr, pos));
|
|
66
|
+
newTr.setMeta(_main.key, {
|
|
67
|
+
isDragging: true,
|
|
68
|
+
activeNode: {
|
|
69
|
+
pos: pos,
|
|
70
|
+
anchorName: anchorName
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return newTr;
|
|
74
|
+
};
|
|
41
75
|
}
|
|
42
76
|
},
|
|
43
77
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -4,13 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
7
|
+
exports.nodeDecorations = exports.mouseMoveWrapperDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _react = require("react");
|
|
9
10
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
11
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
-
var _consts = require("../ui/consts");
|
|
12
12
|
var _dragHandle = require("../ui/drag-handle");
|
|
13
13
|
var _dropTarget = require("../ui/drop-target");
|
|
14
|
+
var _mouseMoveWrapper = require("../ui/mouse-move-wrapper");
|
|
14
15
|
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
15
16
|
var decs = [];
|
|
16
17
|
// Decoration state is used to keep track of the position of the drop targets
|
|
@@ -28,6 +29,8 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
28
29
|
index: index
|
|
29
30
|
}), element);
|
|
30
31
|
return element;
|
|
32
|
+
}, {
|
|
33
|
+
type: 'drop-target-decoration'
|
|
31
34
|
}));
|
|
32
35
|
return false;
|
|
33
36
|
});
|
|
@@ -50,39 +53,71 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
50
53
|
index: decorationState.length
|
|
51
54
|
}), element);
|
|
52
55
|
return element;
|
|
56
|
+
}, {
|
|
57
|
+
type: 'drop-target-decoration'
|
|
53
58
|
}));
|
|
54
59
|
return {
|
|
55
60
|
decs: decs,
|
|
56
61
|
decorationState: decorationState
|
|
57
62
|
};
|
|
58
63
|
};
|
|
59
|
-
var
|
|
60
|
-
|
|
64
|
+
var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState) {
|
|
65
|
+
var decs = [];
|
|
66
|
+
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
67
|
+
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
68
|
+
var style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '');
|
|
69
|
+
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (0, _defineProperty2.default)({
|
|
70
|
+
style: style
|
|
71
|
+
}, 'data-drag-handler-anchor-name', anchorName)));
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
return decs;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Setting up decorations around each node to track mousemove events into each node
|
|
78
|
+
* When a mouseenter event is triggered on the node, we will set the activeNode to the node
|
|
79
|
+
* And show the drag handle
|
|
80
|
+
*/
|
|
81
|
+
var mouseMoveWrapperDecorations = exports.mouseMoveWrapperDecorations = function mouseMoveWrapperDecorations(newState, api) {
|
|
82
|
+
var decs = [];
|
|
83
|
+
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
84
|
+
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
85
|
+
decs.push(_view.Decoration.widget(pos, function (view, getPos) {
|
|
86
|
+
var element = document.createElement('div');
|
|
87
|
+
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_mouseMoveWrapper.MouseMoveWrapper, {
|
|
88
|
+
view: view,
|
|
89
|
+
api: api,
|
|
90
|
+
anchorName: anchorName,
|
|
91
|
+
nodeType: node.type.name,
|
|
92
|
+
getPos: getPos
|
|
93
|
+
}), element);
|
|
94
|
+
return element;
|
|
95
|
+
}, {
|
|
96
|
+
type: 'mouse-move-wrapper',
|
|
97
|
+
side: -1,
|
|
98
|
+
ignoreSelection: true,
|
|
99
|
+
stopEvent: function stopEvent(e) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
105
|
+
return decs;
|
|
106
|
+
};
|
|
107
|
+
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(pos, anchorName, nodeType, api) {
|
|
108
|
+
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
61
109
|
var element = document.createElement('div');
|
|
110
|
+
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
62
111
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
|
|
63
|
-
|
|
112
|
+
view: view,
|
|
64
113
|
api: api,
|
|
65
|
-
|
|
114
|
+
getPos: getPos,
|
|
115
|
+
anchorName: anchorName,
|
|
116
|
+
nodeType: nodeType
|
|
66
117
|
}), element);
|
|
67
|
-
element.style.position = 'absolute';
|
|
68
|
-
element.style.zIndex = '1';
|
|
69
|
-
|
|
70
|
-
// If the selected node is a table or mediaSingle with resizer, we need to adjust the position of the drag handle
|
|
71
|
-
var resizer = ['table', 'mediaSingle'].includes(meta.type) ? meta.dom.querySelector('.resizer-item') : null;
|
|
72
|
-
if (resizer) {
|
|
73
|
-
element.style.left = getComputedStyle(resizer).transform === 'none' ? "".concat(resizer.offsetLeft - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px") : "".concat(resizer.offsetLeft - resizer.offsetWidth / 2 - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
74
|
-
} else {
|
|
75
|
-
element.style.left = "".concat(meta.dom.offsetLeft - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
|
|
76
|
-
}
|
|
77
|
-
if (meta.type === 'table') {
|
|
78
|
-
var table = meta.dom.querySelector('table');
|
|
79
|
-
element.style.top = "".concat(meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
|
|
80
|
-
} else {
|
|
81
|
-
element.style.top = "".concat(meta.dom.offsetTop, "px");
|
|
82
|
-
}
|
|
83
|
-
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
84
118
|
return element;
|
|
85
119
|
}, {
|
|
86
|
-
side: -1
|
|
87
|
-
|
|
120
|
+
side: -1,
|
|
121
|
+
id: 'drag-handle'
|
|
122
|
+
});
|
|
88
123
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.key = exports.createPlugin = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
7
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
12
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
@@ -21,47 +24,67 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
21
24
|
isDragging: false,
|
|
22
25
|
isMenuOpen: false,
|
|
23
26
|
start: null,
|
|
24
|
-
end: null
|
|
27
|
+
end: null,
|
|
28
|
+
editorHeight: 0
|
|
25
29
|
};
|
|
26
30
|
},
|
|
27
31
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
28
|
-
var _decorationState, _meta$
|
|
32
|
+
var _decorationState, _meta$activeNode, _meta$isDragging, _meta$editorHeight;
|
|
29
33
|
// return currentState;
|
|
30
34
|
var activeNode = currentState.activeNode,
|
|
31
35
|
decorations = currentState.decorations,
|
|
32
36
|
isMenuOpen = currentState.isMenuOpen,
|
|
33
|
-
decorationState = currentState.decorationState
|
|
37
|
+
decorationState = currentState.decorationState,
|
|
38
|
+
editorHeight = currentState.editorHeight;
|
|
34
39
|
var meta = tr.getMeta(key);
|
|
35
40
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
// Drop target decorations
|
|
41
|
-
if (meta !== null && meta !== void 0 && meta.isDragging && api) {
|
|
41
|
+
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
42
|
+
var redrawDecorations = decorations === _view.DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || tr.docChanged && tr.doc.childCount === newState.doc.childCount || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) && tr.docChanged;
|
|
43
|
+
if (redrawDecorations && api) {
|
|
42
44
|
decorations = _view.DecorationSet.create(newState.doc, []);
|
|
45
|
+
var nodeDecs = (0, _decorations.nodeDecorations)(newState);
|
|
46
|
+
var mouseWrapperDecs = (0, _decorations.mouseMoveWrapperDecorations)(newState, api);
|
|
47
|
+
decorations = decorations.add(newState.doc, [].concat((0, _toConsumableArray2.default)(nodeDecs), (0, _toConsumableArray2.default)(mouseWrapperDecs)));
|
|
48
|
+
if (activeNode) {
|
|
49
|
+
var draghandleDec = (0, _decorations.dragHandleDecoration)(activeNode.pos, activeNode.anchorName, activeNode.nodeType, api);
|
|
50
|
+
decorations = decorations.add(newState.doc, [draghandleDec]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
55
|
+
if (meta !== null && meta !== void 0 && meta.activeNode && (meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) && api) {
|
|
56
|
+
var oldHandle = decorations.find().filter(function (_ref) {
|
|
57
|
+
var spec = _ref.spec;
|
|
58
|
+
return spec.id === 'drag-handle';
|
|
59
|
+
});
|
|
60
|
+
decorations = decorations.remove(oldHandle);
|
|
61
|
+
var decs = (0, _decorations.dragHandleDecoration)(meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, api);
|
|
62
|
+
decorations = decorations.add(newState.doc, [decs]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Add drop targets when node is being dragged
|
|
66
|
+
if (meta !== null && meta !== void 0 && meta.isDragging && !tr.docChanged && api) {
|
|
43
67
|
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api),
|
|
44
|
-
|
|
68
|
+
_decs = _dropTargetDecoration.decs,
|
|
45
69
|
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
46
70
|
decorationState = updatedDecorationState;
|
|
47
|
-
decorations = decorations.add(newState.doc,
|
|
71
|
+
decorations = decorations.add(newState.doc, _decs);
|
|
48
72
|
}
|
|
49
73
|
|
|
50
|
-
// Remove drop target
|
|
51
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
decorations = decorations.map(tr.mapping, tr.doc);
|
|
74
|
+
// Remove drop target decoration when dragging stops
|
|
75
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
|
|
76
|
+
var dropTargetDecs = decorations.find().filter(function (_ref2) {
|
|
77
|
+
var spec = _ref2.spec;
|
|
78
|
+
return spec.type === 'drop-target-decoration';
|
|
79
|
+
});
|
|
80
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
// Map drop target decoration positions when the document changes
|
|
61
84
|
if (tr.docChanged && currentState.isDragging) {
|
|
62
|
-
decorationState = decorationState.map(function (
|
|
63
|
-
var index =
|
|
64
|
-
pos =
|
|
85
|
+
decorationState = decorationState.map(function (_ref3) {
|
|
86
|
+
var index = _ref3.index,
|
|
87
|
+
pos = _ref3.pos;
|
|
65
88
|
return {
|
|
66
89
|
index: index,
|
|
67
90
|
pos: tr.mapping.map(pos)
|
|
@@ -69,16 +92,23 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
69
92
|
});
|
|
70
93
|
}
|
|
71
94
|
|
|
95
|
+
// Map decorations if document changes and node decorations do not need to be redrawn
|
|
96
|
+
if (tr.docChanged && !redrawDecorations) {
|
|
97
|
+
decorations = decorations.map(tr.mapping, tr.doc);
|
|
98
|
+
}
|
|
99
|
+
|
|
72
100
|
// Map active node position when the document changes
|
|
73
|
-
var mappedActiveNodePos = tr.docChanged && activeNode ?
|
|
101
|
+
var mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
102
|
+
pos: tr.mapping.map(activeNode.pos),
|
|
103
|
+
anchorName: activeNode.anchorName
|
|
104
|
+
} : activeNode;
|
|
74
105
|
return {
|
|
75
106
|
decorations: decorations,
|
|
76
107
|
decorationState: (_decorationState = decorationState) !== null && _decorationState !== void 0 ? _decorationState : currentState.decorationState,
|
|
77
|
-
activeNode:
|
|
78
|
-
pos: (_meta$pos = meta === null || meta === void 0 ? void 0 : meta.pos) !== null && _meta$pos !== void 0 ? _meta$pos : mappedActiveNodePos
|
|
79
|
-
},
|
|
108
|
+
activeNode: (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : mappedActiveNodePos,
|
|
80
109
|
isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : currentState.isDragging,
|
|
81
|
-
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen
|
|
110
|
+
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
111
|
+
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight
|
|
82
112
|
};
|
|
83
113
|
}
|
|
84
114
|
},
|
|
@@ -86,40 +116,31 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
86
116
|
decorations: function decorations(state) {
|
|
87
117
|
var _key$getState;
|
|
88
118
|
return (_key$getState = key.getState(state)) === null || _key$getState === void 0 ? void 0 : _key$getState.decorations;
|
|
89
|
-
},
|
|
90
|
-
handleDOMEvents: {
|
|
91
|
-
mousemove: function mousemove(view, event) {
|
|
92
|
-
var pos = view.posAtCoords({
|
|
93
|
-
left: event.clientX,
|
|
94
|
-
top: event.clientY
|
|
95
|
-
});
|
|
96
|
-
if ((pos === null || pos === void 0 ? void 0 : pos.inside) !== undefined && pos.inside >= 0) {
|
|
97
|
-
var _api$core;
|
|
98
|
-
var node = view.state.doc.nodeAt(pos.inside);
|
|
99
|
-
if (!node) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
var resolvedPos = view.state.doc.resolve(pos.pos);
|
|
103
|
-
var topLevelPos = resolvedPos.before(1); // 1 here restricts the depth to the root level
|
|
104
|
-
var topLevelNode = view.state.doc.nodeAt(topLevelPos);
|
|
105
|
-
if (!topLevelNode) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
var dom = view.nodeDOM(topLevelPos);
|
|
109
|
-
if (!dom) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
113
|
-
var tr = _ref2.tr;
|
|
114
|
-
return tr.setMeta(key, {
|
|
115
|
-
pos: topLevelPos,
|
|
116
|
-
dom: dom,
|
|
117
|
-
type: topLevelNode.type.name
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
119
|
}
|
|
120
|
+
},
|
|
121
|
+
view: function view(editorView) {
|
|
122
|
+
var dom = editorView.dom;
|
|
123
|
+
|
|
124
|
+
// Use ResizeObserver to observe height changes
|
|
125
|
+
var resizeObserver = new ResizeObserver((0, _rafSchd.default)(function () {
|
|
126
|
+
var editorHeight = dom.offsetHeight;
|
|
127
|
+
|
|
128
|
+
// Update the plugin state when the height changes
|
|
129
|
+
var pluginState = key.getState(editorView.state);
|
|
130
|
+
if (!(pluginState !== null && pluginState !== void 0 && pluginState.isDragging)) {
|
|
131
|
+
editorView.dispatch(editorView.state.tr.setMeta(key, {
|
|
132
|
+
editorHeight: editorHeight
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
// Start observing the editor DOM element
|
|
138
|
+
resizeObserver.observe(dom);
|
|
139
|
+
return {
|
|
140
|
+
destroy: function destroy() {
|
|
141
|
+
resizeObserver.unobserve(dom);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
123
144
|
}
|
|
124
145
|
});
|
|
125
146
|
};
|
package/dist/cjs/ui/consts.js
CHANGED
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.dragHandleGap = exports.DRAG_HANDLE_WIDTH = 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
9
|
var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
10
|
-
var
|
|
10
|
+
var nodeTypeExcludeList = ['embedCard', 'mediaSingle', 'table'];
|
|
11
|
+
var dragHandleGap = exports.dragHandleGap = function dragHandleGap(nodeType) {
|
|
12
|
+
if (nodeTypeExcludeList.includes(nodeType)) {
|
|
13
|
+
return 12;
|
|
14
|
+
}
|
|
15
|
+
return 8;
|
|
16
|
+
};
|
|
@@ -12,12 +12,14 @@ 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 _dragHandlePositions = require("../utils/drag-handle-positions");
|
|
15
16
|
var _getSelection = require("../utils/getSelection");
|
|
16
17
|
var _consts = require("./consts");
|
|
17
18
|
var _dragPreview = require("./drag-preview");
|
|
18
19
|
/** @jsx jsx */
|
|
19
20
|
|
|
20
21
|
var dragHandleButtonStyles = (0, _react2.css)({
|
|
22
|
+
position: 'absolute',
|
|
21
23
|
padding: "var(--ds-space-025, 2px)".concat(" 0"),
|
|
22
24
|
boxSizing: 'border-box',
|
|
23
25
|
display: 'flex',
|
|
@@ -31,10 +33,11 @@ var dragHandleButtonStyles = (0, _react2.css)({
|
|
|
31
33
|
borderRadius: _consts.DRAG_HANDLE_BORDER_RADIUS,
|
|
32
34
|
color: "var(--ds-icon, #44546F)",
|
|
33
35
|
cursor: 'grab',
|
|
34
|
-
|
|
36
|
+
zIndex: 2,
|
|
37
|
+
'&:hover': {
|
|
35
38
|
backgroundColor: "var(--ds-background-neutral-subtle-hovered, #091E420F)"
|
|
36
39
|
},
|
|
37
|
-
'
|
|
40
|
+
'&:active': {
|
|
38
41
|
backgroundColor: "var(--ds-background-neutral-subtle-pressed, #091E4224)"
|
|
39
42
|
}
|
|
40
43
|
});
|
|
@@ -43,11 +46,13 @@ var selectedStyles = (0, _react2.css)({
|
|
|
43
46
|
color: "var(--ds-icon-selected, #0C66E4)"
|
|
44
47
|
});
|
|
45
48
|
var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
46
|
-
var
|
|
49
|
+
var view = _ref.view,
|
|
47
50
|
api = _ref.api,
|
|
48
|
-
|
|
51
|
+
getPos = _ref.getPos,
|
|
52
|
+
anchorName = _ref.anchorName,
|
|
53
|
+
nodeType = _ref.nodeType;
|
|
54
|
+
var start = getPos();
|
|
49
55
|
var buttonRef = (0, _react.useRef)(null);
|
|
50
|
-
var domRef = (0, _react.useRef)(dom);
|
|
51
56
|
var _useState = (0, _react.useState)(false),
|
|
52
57
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
53
58
|
dragHandleSelected = _useState2[0],
|
|
@@ -55,15 +60,15 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
55
60
|
var handleClick = (0, _react.useCallback)(function () {
|
|
56
61
|
var _api$core, _api$core2;
|
|
57
62
|
setDragHandleSelected(!dragHandleSelected);
|
|
58
|
-
// TODO - add drag menu
|
|
59
|
-
// api?.core?.actions.execute(({ tr }) =>
|
|
60
|
-
// tr.setMeta(key, {
|
|
61
|
-
// toggleMenu: true,
|
|
62
|
-
// }),
|
|
63
|
-
// );
|
|
64
63
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
65
64
|
var tr = _ref2.tr;
|
|
65
|
+
if (start === undefined) {
|
|
66
|
+
return tr;
|
|
67
|
+
}
|
|
66
68
|
tr.setSelection((0, _getSelection.getSelection)(tr, start));
|
|
69
|
+
tr.setMeta(_main.key, {
|
|
70
|
+
pos: start
|
|
71
|
+
});
|
|
67
72
|
return tr;
|
|
68
73
|
});
|
|
69
74
|
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
@@ -80,40 +85,57 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
80
85
|
(0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
|
|
81
86
|
render: function render(_ref4) {
|
|
82
87
|
var container = _ref4.container;
|
|
83
|
-
|
|
88
|
+
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
89
|
+
if (!dom) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return (0, _dragPreview.dragPreview)(container, dom);
|
|
84
93
|
},
|
|
85
94
|
nativeSetDragImage: nativeSetDragImage
|
|
86
95
|
});
|
|
87
96
|
},
|
|
88
97
|
onDragStart: function onDragStart() {
|
|
89
|
-
var _api$core3, _api$core4;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
newTr.setMeta(_main.key, {
|
|
95
|
-
isDragging: true,
|
|
96
|
-
start: start
|
|
97
|
-
});
|
|
98
|
-
return newTr;
|
|
99
|
-
});
|
|
98
|
+
var _api$core3, _api$blockControls, _api$core4;
|
|
99
|
+
if (start === undefined) {
|
|
100
|
+
return;
|
|
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));
|
|
100
103
|
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
|
|
101
104
|
},
|
|
102
105
|
onDrop: function onDrop() {
|
|
103
106
|
var _api$core5;
|
|
104
|
-
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (
|
|
105
|
-
var tr =
|
|
107
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref5) {
|
|
108
|
+
var tr = _ref5.tr;
|
|
106
109
|
return tr.setMeta(_main.key, {
|
|
107
110
|
isDragging: false
|
|
108
111
|
});
|
|
109
112
|
});
|
|
110
113
|
}
|
|
111
114
|
});
|
|
112
|
-
}, [api, start]);
|
|
115
|
+
}, [api, start, view, anchorName]);
|
|
116
|
+
var positionStyles = (0, _react.useMemo)(function () {
|
|
117
|
+
var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
|
|
118
|
+
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
119
|
+
if (supportsAnchor) {
|
|
120
|
+
var hasResizer = (anchorName.includes('table') || anchorName.includes('mediaSingle')) && dom;
|
|
121
|
+
return {
|
|
122
|
+
left: hasResizer ? (0, _dragHandlePositions.getLeftPosition)(dom, nodeType) : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
|
|
123
|
+
top: anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(_consts.DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (!dom) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
left: (0, _dragHandlePositions.getLeftPosition)(dom, nodeType),
|
|
131
|
+
top: (0, _dragHandlePositions.getTopPosition)(dom)
|
|
132
|
+
};
|
|
133
|
+
}, [anchorName, view, nodeType]);
|
|
113
134
|
return (0, _react2.jsx)("button", {
|
|
114
135
|
type: "button",
|
|
115
136
|
css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
|
|
116
137
|
ref: buttonRef,
|
|
138
|
+
style: positionStyles,
|
|
117
139
|
onClick: handleClick,
|
|
118
140
|
"data-testid": "block-ctrl-drag-handle"
|
|
119
141
|
}, (0, _react2.jsx)(_dragHandler.default, {
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.dragPreview = void 0;
|
|
7
|
-
var dragPreview = exports.dragPreview = function dragPreview(container,
|
|
8
|
-
var rect =
|
|
7
|
+
var dragPreview = exports.dragPreview = function dragPreview(container, dom) {
|
|
8
|
+
var rect = dom.getBoundingClientRect();
|
|
9
9
|
container.style.width = "".concat(rect.width, "px");
|
|
10
10
|
container.style.height = "".concat(rect.height, "px");
|
|
11
11
|
container.style.pointerEvents = 'none';
|
|
@@ -13,8 +13,8 @@ var dragPreview = exports.dragPreview = function dragPreview(container, domRef)
|
|
|
13
13
|
// ProseMirror class is required to make sure the cloned dom is styled correctly
|
|
14
14
|
parent.classList.add('ProseMirror');
|
|
15
15
|
parent.style.opacity = '0.3';
|
|
16
|
-
var resizer =
|
|
17
|
-
var clonedDom = resizer ? resizer.cloneNode(true) :
|
|
16
|
+
var resizer = dom.querySelector('.resizer-item');
|
|
17
|
+
var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
|
|
18
18
|
|
|
19
19
|
// Remove any margin from the cloned element to ensure is doesn't position incorrectly
|
|
20
20
|
clonedDom.style.marginLeft = '0';
|
|
@@ -8,15 +8,26 @@ exports.DropTarget = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _react2 = require("@emotion/react");
|
|
11
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
12
|
var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
|
|
12
13
|
var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
|
|
13
14
|
var _combine = require("@atlaskit/pragmatic-drag-and-drop/combine");
|
|
14
15
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
15
16
|
/** @jsx jsx */
|
|
16
17
|
|
|
18
|
+
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
17
19
|
var styleDropTarget = (0, _react2.css)({
|
|
18
20
|
height: "var(--ds-space-100, 8px)",
|
|
19
21
|
marginTop: "var(--ds-space-negative-100, -8px)",
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: '100%',
|
|
24
|
+
left: '0',
|
|
25
|
+
display: 'block'
|
|
26
|
+
});
|
|
27
|
+
var styleDropIndicator = (0, _react2.css)({
|
|
28
|
+
height: '100%',
|
|
29
|
+
width: '100%',
|
|
30
|
+
margin: '0 auto',
|
|
20
31
|
position: 'relative'
|
|
21
32
|
});
|
|
22
33
|
var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
@@ -27,6 +38,9 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
27
38
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
28
39
|
isDraggedOver = _useState2[0],
|
|
29
40
|
setIsDraggedOver = _useState2[1];
|
|
41
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width']),
|
|
42
|
+
widthState = _useSharedPluginState.widthState;
|
|
43
|
+
var lineLength = (widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH;
|
|
30
44
|
(0, _react.useEffect)(function () {
|
|
31
45
|
var element = ref.current;
|
|
32
46
|
if (!element) {
|
|
@@ -83,9 +97,15 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
83
97
|
"data-testid": "block-ctrl-drop-target"
|
|
84
98
|
},
|
|
85
99
|
//4px gap to clear expand node border
|
|
86
|
-
isDraggedOver && (0, _react2.jsx)(
|
|
100
|
+
isDraggedOver && (0, _react2.jsx)("div", {
|
|
101
|
+
css: styleDropIndicator,
|
|
102
|
+
style: {
|
|
103
|
+
'width': "".concat(lineLength, "px")
|
|
104
|
+
},
|
|
105
|
+
"data-testid": "block-ctrl-drop-indicator"
|
|
106
|
+
}, (0, _react2.jsx)(_box.DropIndicator, {
|
|
87
107
|
edge: "bottom",
|
|
88
108
|
gap: "4px"
|
|
89
|
-
}))
|
|
109
|
+
})))
|
|
90
110
|
);
|
|
91
111
|
};
|