@atlaskit/editor-plugin-block-controls 1.10.0 → 1.10.2
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 +19 -0
- package/dist/cjs/commands/move-node.js +11 -2
- package/dist/cjs/pm-plugins/decorations.js +4 -2
- package/dist/cjs/pm-plugins/keymap.js +5 -5
- package/dist/cjs/pm-plugins/main.js +10 -7
- package/dist/cjs/ui/drag-handle.js +58 -41
- package/dist/cjs/ui/drop-target.js +4 -3
- package/dist/es2019/commands/move-node.js +11 -3
- package/dist/es2019/pm-plugins/decorations.js +4 -2
- package/dist/es2019/pm-plugins/keymap.js +4 -4
- package/dist/es2019/pm-plugins/main.js +12 -7
- package/dist/es2019/ui/drag-handle.js +44 -28
- package/dist/es2019/ui/drop-target.js +4 -3
- package/dist/esm/commands/move-node.js +11 -2
- package/dist/esm/pm-plugins/decorations.js +4 -2
- package/dist/esm/pm-plugins/keymap.js +5 -5
- package/dist/esm/pm-plugins/main.js +10 -7
- package/dist/esm/ui/drag-handle.js +59 -42
- package/dist/esm/ui/drop-target.js +4 -3
- package/dist/types/commands/move-node.d.ts +3 -2
- package/dist/types/pm-plugins/decorations.d.ts +1 -1
- package/dist/types/pm-plugins/keymap.d.ts +2 -1
- package/dist/types/types.d.ts +5 -2
- package/dist/types/ui/drop-target.d.ts +7 -1
- package/dist/types-ts4.5/commands/move-node.d.ts +3 -2
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -1
- package/dist/types-ts4.5/types.d.ts +5 -2
- package/dist/types-ts4.5/ui/drop-target.d.ts +7 -1
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.10.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`63d659eb3e73d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/63d659eb3e73d) -
|
|
8
|
+
ED-24315 improve a11y for block controls
|
|
9
|
+
|
|
10
|
+
## 1.10.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#125984](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125984)
|
|
15
|
+
[`167a210dfd672`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/167a210dfd672) -
|
|
16
|
+
[ux] Update shortcuts for element dnd
|
|
17
|
+
- [#125542](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125542)
|
|
18
|
+
[`06bc2f65f892e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/06bc2f65f892e) -
|
|
19
|
+
ED-24304 resolve range error issue
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 1.10.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.moveNodeViaShortcut = exports.moveNode = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
11
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
11
12
|
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
12
13
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
@@ -53,7 +54,7 @@ var getCurrentNodePos = function getCurrentNodePos(state) {
|
|
|
53
54
|
}
|
|
54
55
|
return currentNodePos;
|
|
55
56
|
};
|
|
56
|
-
var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShortcut(api, direction) {
|
|
57
|
+
var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, formatMessage) {
|
|
57
58
|
return function (state) {
|
|
58
59
|
var currentNodePos = getCurrentNodePos(state);
|
|
59
60
|
if (currentNodePos > -1) {
|
|
@@ -79,7 +80,7 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
|
|
|
79
80
|
var _api$core;
|
|
80
81
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
81
82
|
var tr = _ref2.tr;
|
|
82
|
-
moveNode(api)(currentNodePos, moveToPos, _analytics.INPUT_METHOD.SHORTCUT)({
|
|
83
|
+
moveNode(api)(currentNodePos, moveToPos, _analytics.INPUT_METHOD.SHORTCUT, formatMessage)({
|
|
83
84
|
tr: tr
|
|
84
85
|
});
|
|
85
86
|
tr.scrollIntoView();
|
|
@@ -104,6 +105,7 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
|
|
|
104
105
|
var moveNode = exports.moveNode = function moveNode(api) {
|
|
105
106
|
return function (start, to) {
|
|
106
107
|
var inputMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _analytics.INPUT_METHOD.DRAG_AND_DROP;
|
|
108
|
+
var formatMessage = arguments.length > 3 ? arguments[3] : undefined;
|
|
107
109
|
return function (_ref4) {
|
|
108
110
|
var _node$nodeSize, _api$analytics;
|
|
109
111
|
var tr = _ref4.tr;
|
|
@@ -145,6 +147,13 @@ var moveNode = exports.moveNode = function moveNode(api) {
|
|
|
145
147
|
inputMethod: inputMethod
|
|
146
148
|
})
|
|
147
149
|
})(tr);
|
|
150
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
151
|
+
var _api$accessibilityUti;
|
|
152
|
+
var movedMessage = to > start ? _messages.blockControlsMessages.movedDown : _messages.blockControlsMessages.movedup;
|
|
153
|
+
api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(formatMessage ? formatMessage(movedMessage) : movedMessage.defaultMessage, {
|
|
154
|
+
priority: 'important'
|
|
155
|
+
});
|
|
156
|
+
}
|
|
148
157
|
return tr;
|
|
149
158
|
};
|
|
150
159
|
};
|
|
@@ -17,7 +17,7 @@ var _dropTarget = require("../ui/drop-target");
|
|
|
17
17
|
var _mouseMoveWrapper = require("../ui/mouse-move-wrapper");
|
|
18
18
|
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
19
19
|
var NESTED_DEPTH = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
20
|
-
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
|
|
20
|
+
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api, formatMessage) {
|
|
21
21
|
var decs = [];
|
|
22
22
|
unmountDecorations('data-blocks-drop-target-container');
|
|
23
23
|
// Decoration state is used to keep track of the position of the drop targets
|
|
@@ -48,6 +48,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
48
48
|
var dropTargetDec = /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
49
49
|
api: api,
|
|
50
50
|
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? pos : index,
|
|
51
|
+
formatMessage: formatMessage,
|
|
51
52
|
prevNode: prevNode,
|
|
52
53
|
nextNode: node
|
|
53
54
|
});
|
|
@@ -90,7 +91,8 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
90
91
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
91
92
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
92
93
|
api: api,
|
|
93
|
-
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length
|
|
94
|
+
id: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length,
|
|
95
|
+
formatMessage: formatMessage
|
|
94
96
|
}), element);
|
|
95
97
|
return element;
|
|
96
98
|
}, {
|
|
@@ -10,7 +10,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
10
10
|
var _moveNode = require("../commands/move-node");
|
|
11
11
|
var _showDragHandle = require("../commands/show-drag-handle");
|
|
12
12
|
var _consts = require("../consts");
|
|
13
|
-
function keymapList(api) {
|
|
13
|
+
function keymapList(api, formatMessage) {
|
|
14
14
|
var keymapList = {};
|
|
15
15
|
if (api && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
16
16
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.showElementDragHandle.common, function (state, dispatch, view) {
|
|
@@ -18,11 +18,11 @@ function keymapList(api) {
|
|
|
18
18
|
//we always want to handle this shortcut to prevent default browser special char insert when option + alphabetical key is used
|
|
19
19
|
return true;
|
|
20
20
|
}, keymapList);
|
|
21
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.dragToMoveUp.common, (0, _moveNode.moveNodeViaShortcut)(api, _consts.DIRECTION.UP), keymapList);
|
|
22
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.dragToMoveDown.common, (0, _moveNode.moveNodeViaShortcut)(api, _consts.DIRECTION.DOWN), keymapList);
|
|
21
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.dragToMoveUp.common, (0, _moveNode.moveNodeViaShortcut)(api, _consts.DIRECTION.UP, formatMessage), keymapList);
|
|
22
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.dragToMoveDown.common, (0, _moveNode.moveNodeViaShortcut)(api, _consts.DIRECTION.DOWN, formatMessage), keymapList);
|
|
23
23
|
}
|
|
24
24
|
return keymapList;
|
|
25
25
|
}
|
|
26
|
-
var boundKeydownHandler = exports.boundKeydownHandler = function boundKeydownHandler(api) {
|
|
27
|
-
return (0, _keymap.keydownHandler)(keymapList(api));
|
|
26
|
+
var boundKeydownHandler = exports.boundKeydownHandler = function boundKeydownHandler(api, formatMessage) {
|
|
27
|
+
return (0, _keymap.keydownHandler)(keymapList(api, formatMessage));
|
|
28
28
|
};
|
|
@@ -184,6 +184,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
184
184
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
185
185
|
var maybeNodeWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 || (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
186
186
|
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 || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
187
|
+
var _getIntl = getIntl(),
|
|
188
|
+
formatMessage = _getIntl.formatMessage;
|
|
187
189
|
|
|
188
190
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
189
191
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
@@ -273,7 +275,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
273
275
|
// Add drop targets when node is being dragged
|
|
274
276
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
275
277
|
if (shouldUpdateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
276
|
-
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api),
|
|
278
|
+
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api, formatMessage),
|
|
277
279
|
_decs2 = _dropTargetDecoration.decs,
|
|
278
280
|
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
279
281
|
decorationState = updatedDecorationState;
|
|
@@ -298,7 +300,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
298
300
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
299
301
|
var shouldShowDragTarget = (meta === null || meta === void 0 ? void 0 : meta.isDragging) && (!tr.docChanged || tr.docChanged && isAnalyticTr);
|
|
300
302
|
if (shouldShowDragTarget || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
301
|
-
var _dropTargetDecoration2 = (0, _decorations.dropTargetDecorations)(oldState, newState, api),
|
|
303
|
+
var _dropTargetDecoration2 = (0, _decorations.dropTargetDecorations)(oldState, newState, api, formatMessage),
|
|
302
304
|
_decs3 = _dropTargetDecoration2.decs,
|
|
303
305
|
_updatedDecorationState = _dropTargetDecoration2.decorationState;
|
|
304
306
|
decorationState = _updatedDecorationState;
|
|
@@ -408,7 +410,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
408
410
|
if (!nodeElement) {
|
|
409
411
|
return false;
|
|
410
412
|
}
|
|
411
|
-
var
|
|
413
|
+
var domPos = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24304') ? Math.max(view.posAtDOM(nodeElement, 0) - 1, 0) : view.posAtDOM(nodeElement, 0) - 1;
|
|
414
|
+
var nodeTarget = state.doc.nodeAt(domPos);
|
|
412
415
|
isSameNode = !!(nodeTarget && draggable !== null && draggable !== void 0 && draggable.eq(nodeTarget));
|
|
413
416
|
}
|
|
414
417
|
if (isSameNode) {
|
|
@@ -453,11 +456,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
453
456
|
return true;
|
|
454
457
|
}
|
|
455
458
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
+
if (event.shiftKey && event.ctrlKey && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
460
|
+
var _getIntl2 = getIntl(),
|
|
461
|
+
formatMessage = _getIntl2.formatMessage;
|
|
459
462
|
//prevent holding down key combo from firing repeatedly
|
|
460
|
-
if (!event.repeat && (0, _keymap.boundKeydownHandler)(api)(view, event)) {
|
|
463
|
+
if (!event.repeat && (0, _keymap.boundKeydownHandler)(api, formatMessage)(view, event)) {
|
|
461
464
|
event.preventDefault();
|
|
462
465
|
return true;
|
|
463
466
|
}
|
|
@@ -68,6 +68,7 @@ var selectedStyles = (0, _react2.css)({
|
|
|
68
68
|
color: "var(--ds-icon-selected, #0C66E4)"
|
|
69
69
|
});
|
|
70
70
|
var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
71
|
+
var _api$core2, _api$analytics2, _api$core5, _api$core7;
|
|
71
72
|
var view = _ref.view,
|
|
72
73
|
api = _ref.api,
|
|
73
74
|
getPos = _ref.getPos,
|
|
@@ -110,14 +111,15 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
110
111
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
111
112
|
var _api$analytics;
|
|
112
113
|
var tr = _ref2.tr;
|
|
113
|
-
|
|
114
|
+
var startPos = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
115
|
+
if (startPos === undefined) {
|
|
114
116
|
return tr;
|
|
115
117
|
}
|
|
116
|
-
tr = (0, _utils.selectNode)(tr,
|
|
118
|
+
tr = (0, _utils.selectNode)(tr, startPos, nodeType);
|
|
117
119
|
tr.setMeta(_main.key, {
|
|
118
|
-
pos:
|
|
120
|
+
pos: startPos
|
|
119
121
|
});
|
|
120
|
-
var resolvedMovingNode = tr.doc.resolve(
|
|
122
|
+
var resolvedMovingNode = tr.doc.resolve(startPos);
|
|
121
123
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
122
124
|
(0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-long-node-scroll') && tr.setMeta('scrollIntoView', false);
|
|
123
125
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
@@ -133,14 +135,14 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
133
135
|
return tr;
|
|
134
136
|
});
|
|
135
137
|
view.focus();
|
|
136
|
-
}, [
|
|
138
|
+
}, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos, start, nodeType]);
|
|
137
139
|
|
|
138
140
|
// handleMouseDown required along with onClick to ensure the correct selection
|
|
139
141
|
// is set immediately when the drag handle is clicked. Otherwise browser native
|
|
140
142
|
// drag and drop can take over and cause unpredictable behaviour.
|
|
141
143
|
var handleMouseDown = (0, _react.useCallback)(function () {
|
|
142
|
-
var _api$
|
|
143
|
-
api === null || api === void 0 || (_api$
|
|
144
|
+
var _api$core3;
|
|
145
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref3) {
|
|
144
146
|
var tr = _ref3.tr;
|
|
145
147
|
if (start === undefined) {
|
|
146
148
|
return tr;
|
|
@@ -158,44 +160,47 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
158
160
|
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
159
161
|
// but ensures the preview is generated correctly.
|
|
160
162
|
var handleMouseDownWrapperRemoved = (0, _react.useCallback)(function () {
|
|
161
|
-
var _api$
|
|
162
|
-
api === null || api === void 0 || (_api$
|
|
163
|
+
var _api$core4;
|
|
164
|
+
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref4) {
|
|
163
165
|
var tr = _ref4.tr;
|
|
164
|
-
|
|
166
|
+
var startPos = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
167
|
+
if (startPos === undefined) {
|
|
165
168
|
return tr;
|
|
166
169
|
}
|
|
167
|
-
var node = tr.doc.nodeAt(
|
|
170
|
+
var node = tr.doc.nodeAt(startPos);
|
|
168
171
|
if (!node) {
|
|
169
172
|
return tr;
|
|
170
173
|
}
|
|
171
|
-
var $startPos = tr.doc.resolve(
|
|
174
|
+
var $startPos = tr.doc.resolve(startPos + node.nodeSize);
|
|
172
175
|
var selection = new _state.TextSelection($startPos);
|
|
173
176
|
tr.setSelection(selection);
|
|
174
177
|
tr.setMeta(_main.key, {
|
|
175
|
-
pos:
|
|
178
|
+
pos: startPos
|
|
176
179
|
});
|
|
177
180
|
return tr;
|
|
178
181
|
});
|
|
179
|
-
}, [
|
|
182
|
+
}, [api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions, getPos, start]);
|
|
180
183
|
var handleKeyDown = (0, _react.useCallback)(function (e) {
|
|
181
184
|
if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
182
185
|
// allow user to use spacebar to select the node
|
|
186
|
+
|
|
183
187
|
if (!e.repeat && e.key === ' ') {
|
|
184
|
-
var _api$
|
|
185
|
-
|
|
188
|
+
var _api$core6;
|
|
189
|
+
var startPos = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
190
|
+
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref5) {
|
|
186
191
|
var tr = _ref5.tr;
|
|
187
|
-
if (
|
|
192
|
+
if (startPos === undefined) {
|
|
188
193
|
return tr;
|
|
189
194
|
}
|
|
190
|
-
var node = tr.doc.nodeAt(
|
|
195
|
+
var node = tr.doc.nodeAt(startPos);
|
|
191
196
|
if (!node) {
|
|
192
197
|
return tr;
|
|
193
198
|
}
|
|
194
|
-
var $startPos = tr.doc.resolve(
|
|
199
|
+
var $startPos = tr.doc.resolve(startPos + node.nodeSize);
|
|
195
200
|
var selection = new _state.TextSelection($startPos);
|
|
196
201
|
tr.setSelection(selection);
|
|
197
202
|
tr.setMeta(_main.key, {
|
|
198
|
-
pos:
|
|
203
|
+
pos: startPos
|
|
199
204
|
});
|
|
200
205
|
return tr;
|
|
201
206
|
});
|
|
@@ -207,7 +212,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
207
212
|
view.focus();
|
|
208
213
|
}
|
|
209
214
|
}
|
|
210
|
-
}, [start, api, view]);
|
|
215
|
+
}, [getPos, start, api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 ? void 0 : _api$core7.actions, view]);
|
|
211
216
|
(0, _react.useEffect)(function () {
|
|
212
217
|
var element = buttonRef.current;
|
|
213
218
|
if (!element) {
|
|
@@ -236,12 +241,12 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
236
241
|
});
|
|
237
242
|
},
|
|
238
243
|
onDragStart: function onDragStart() {
|
|
239
|
-
var _api$
|
|
244
|
+
var _api$core8;
|
|
240
245
|
if (start === undefined) {
|
|
241
246
|
return;
|
|
242
247
|
}
|
|
243
|
-
api === null || api === void 0 || (_api$
|
|
244
|
-
var _api$blockControls, _api$
|
|
248
|
+
api === null || api === void 0 || (_api$core8 = api.core) === null || _api$core8 === void 0 || _api$core8.actions.execute(function (_ref8) {
|
|
249
|
+
var _api$blockControls, _api$analytics3;
|
|
245
250
|
var tr = _ref8.tr;
|
|
246
251
|
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
|
|
247
252
|
tr: tr
|
|
@@ -249,7 +254,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
249
254
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
250
255
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
251
256
|
tr.setMeta('scrollIntoView', false);
|
|
252
|
-
api === null || api === void 0 || (_api$
|
|
257
|
+
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
253
258
|
eventType: _analytics.EVENT_TYPE.UI,
|
|
254
259
|
action: _analytics.ACTION.DRAGGED,
|
|
255
260
|
actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
|
|
@@ -362,27 +367,39 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
362
367
|
description: formatMessage(_messages.blockControlsMessages.moveDown),
|
|
363
368
|
keymap: _keymaps.dragToMoveDown
|
|
364
369
|
}];
|
|
370
|
+
var message = helpDescriptors.map(function (descriptor) {
|
|
371
|
+
return descriptor.keymap ? [descriptor.description, (0, _keymaps.getAriaKeyshortcuts)(descriptor.keymap)] : [descriptor.description];
|
|
372
|
+
}).join('. ');
|
|
365
373
|
var renderButton = function renderButton() {
|
|
366
|
-
return (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
374
|
+
return (
|
|
375
|
+
// eslint-disable-next-line @atlaskit/design-system/no-html-button
|
|
376
|
+
(0, _react2.jsx)("button", {
|
|
377
|
+
type: "button",
|
|
378
|
+
css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
|
|
379
|
+
ref: buttonRef
|
|
380
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
381
|
+
,
|
|
382
|
+
style: (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896') ? newPositionStyles : positionStyles,
|
|
383
|
+
onClick: handleOnClick,
|
|
384
|
+
onMouseDown: (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? handleMouseDownWrapperRemoved : handleMouseDown,
|
|
385
|
+
onKeyDown: handleKeyDown,
|
|
386
|
+
"data-testid": "block-ctrl-drag-handle"
|
|
387
|
+
}, (0, _react2.jsx)(_dragHandler.default, {
|
|
388
|
+
label: "",
|
|
389
|
+
size: "medium"
|
|
390
|
+
}))
|
|
391
|
+
);
|
|
381
392
|
};
|
|
382
393
|
return (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873') ? (0, _react2.jsx)(_tooltip.default, {
|
|
383
394
|
content: (0, _react2.jsx)(_keymaps.TooltipContentWithMultipleShortcuts, {
|
|
384
395
|
helpDescriptors: helpDescriptors
|
|
385
|
-
})
|
|
396
|
+
}),
|
|
397
|
+
onShow: function onShow() {
|
|
398
|
+
var _api$accessibilityUti;
|
|
399
|
+
api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(message, {
|
|
400
|
+
priority: 'important'
|
|
401
|
+
});
|
|
402
|
+
}
|
|
386
403
|
}, renderButton()) : renderButton();
|
|
387
404
|
};
|
|
388
405
|
var DragHandle = exports.DragHandle = (0, _reactIntlNext.injectIntl)(DragHandleInternal);
|
|
@@ -79,7 +79,8 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
79
79
|
var api = _ref3.api,
|
|
80
80
|
id = _ref3.id,
|
|
81
81
|
prevNode = _ref3.prevNode,
|
|
82
|
-
nextNode = _ref3.nextNode
|
|
82
|
+
nextNode = _ref3.nextNode,
|
|
83
|
+
formatMessage = _ref3.formatMessage;
|
|
83
84
|
var ref = (0, _react.useRef)(null);
|
|
84
85
|
var _useState = (0, _react.useState)(false),
|
|
85
86
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -119,11 +120,11 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
|
119
120
|
if (activeNode && pos !== undefined) {
|
|
120
121
|
var _api$core, _api$blockControls2;
|
|
121
122
|
var start = activeNode.pos;
|
|
122
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos));
|
|
123
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos, undefined, formatMessage));
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
});
|
|
126
|
-
}, [id, api]);
|
|
127
|
+
}, [id, api, formatMessage]);
|
|
127
128
|
var topTargetMarginStyle = (0, _react.useMemo)(function () {
|
|
128
129
|
return getDropTargetPositionStyle(prevNode, nextNode);
|
|
129
130
|
}, [prevNode, nextNode]);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { blockControlsMessages } from '@atlaskit/editor-common/messages';
|
|
2
3
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
3
4
|
import { transformSliceNestedExpandToExpand } from '@atlaskit/editor-common/transforms';
|
|
4
5
|
import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
@@ -46,7 +47,7 @@ const getCurrentNodePos = state => {
|
|
|
46
47
|
}
|
|
47
48
|
return currentNodePos;
|
|
48
49
|
};
|
|
49
|
-
export const moveNodeViaShortcut = (api, direction) => {
|
|
50
|
+
export const moveNodeViaShortcut = (api, direction, formatMessage) => {
|
|
50
51
|
return state => {
|
|
51
52
|
const currentNodePos = getCurrentNodePos(state);
|
|
52
53
|
if (currentNodePos > -1) {
|
|
@@ -73,7 +74,7 @@ export const moveNodeViaShortcut = (api, direction) => {
|
|
|
73
74
|
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
74
75
|
tr
|
|
75
76
|
}) => {
|
|
76
|
-
moveNode(api)(currentNodePos, moveToPos, INPUT_METHOD.SHORTCUT)({
|
|
77
|
+
moveNode(api)(currentNodePos, moveToPos, INPUT_METHOD.SHORTCUT, formatMessage)({
|
|
77
78
|
tr
|
|
78
79
|
});
|
|
79
80
|
tr.scrollIntoView();
|
|
@@ -96,7 +97,7 @@ export const moveNodeViaShortcut = (api, direction) => {
|
|
|
96
97
|
return false;
|
|
97
98
|
};
|
|
98
99
|
};
|
|
99
|
-
export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_DROP) => ({
|
|
100
|
+
export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_DROP, formatMessage) => ({
|
|
100
101
|
tr
|
|
101
102
|
}) => {
|
|
102
103
|
var _node$nodeSize, _api$analytics;
|
|
@@ -139,5 +140,12 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
|
|
|
139
140
|
})
|
|
140
141
|
}
|
|
141
142
|
})(tr);
|
|
143
|
+
if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
144
|
+
var _api$accessibilityUti;
|
|
145
|
+
const movedMessage = to > start ? blockControlsMessages.movedDown : blockControlsMessages.movedup;
|
|
146
|
+
api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify(formatMessage ? formatMessage(movedMessage) : movedMessage.defaultMessage, {
|
|
147
|
+
priority: 'important'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
142
150
|
return tr;
|
|
143
151
|
};
|
|
@@ -9,7 +9,7 @@ import { DropTarget } from '../ui/drop-target';
|
|
|
9
9
|
import { MouseMoveWrapper } from '../ui/mouse-move-wrapper';
|
|
10
10
|
const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn'];
|
|
11
11
|
const NESTED_DEPTH = fg('platform_editor_elements_dnd_nested') ? 100 : 0;
|
|
12
|
-
export const dropTargetDecorations = (oldState, newState, api) => {
|
|
12
|
+
export const dropTargetDecorations = (oldState, newState, api, formatMessage) => {
|
|
13
13
|
const decs = [];
|
|
14
14
|
unmountDecorations('data-blocks-drop-target-container');
|
|
15
15
|
// Decoration state is used to keep track of the position of the drop targets
|
|
@@ -40,6 +40,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
40
40
|
const dropTargetDec = /*#__PURE__*/createElement(DropTarget, {
|
|
41
41
|
api,
|
|
42
42
|
id: fg('platform_editor_elements_dnd_nested') ? pos : index,
|
|
43
|
+
formatMessage,
|
|
43
44
|
prevNode,
|
|
44
45
|
nextNode: node
|
|
45
46
|
});
|
|
@@ -82,7 +83,8 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
82
83
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
83
84
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
|
|
84
85
|
api,
|
|
85
|
-
id: fg('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length
|
|
86
|
+
id: fg('platform_editor_elements_dnd_nested') ? lastPos : decorationState.length,
|
|
87
|
+
formatMessage
|
|
86
88
|
}), element);
|
|
87
89
|
return element;
|
|
88
90
|
}, {
|
|
@@ -4,7 +4,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
4
4
|
import { moveNodeViaShortcut } from '../commands/move-node';
|
|
5
5
|
import { showDragHandleAtSelection } from '../commands/show-drag-handle';
|
|
6
6
|
import { DIRECTION } from '../consts';
|
|
7
|
-
function keymapList(api) {
|
|
7
|
+
function keymapList(api, formatMessage) {
|
|
8
8
|
let keymapList = {};
|
|
9
9
|
if (api && fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
10
10
|
bindKeymapWithCommand(showElementDragHandle.common, (state, dispatch, view) => {
|
|
@@ -12,9 +12,9 @@ function keymapList(api) {
|
|
|
12
12
|
//we always want to handle this shortcut to prevent default browser special char insert when option + alphabetical key is used
|
|
13
13
|
return true;
|
|
14
14
|
}, keymapList);
|
|
15
|
-
bindKeymapWithCommand(dragToMoveUp.common, moveNodeViaShortcut(api, DIRECTION.UP), keymapList);
|
|
16
|
-
bindKeymapWithCommand(dragToMoveDown.common, moveNodeViaShortcut(api, DIRECTION.DOWN), keymapList);
|
|
15
|
+
bindKeymapWithCommand(dragToMoveUp.common, moveNodeViaShortcut(api, DIRECTION.UP, formatMessage), keymapList);
|
|
16
|
+
bindKeymapWithCommand(dragToMoveDown.common, moveNodeViaShortcut(api, DIRECTION.DOWN, formatMessage), keymapList);
|
|
17
17
|
}
|
|
18
18
|
return keymapList;
|
|
19
19
|
}
|
|
20
|
-
export const boundKeydownHandler = api => keydownHandler(keymapList(api));
|
|
20
|
+
export const boundKeydownHandler = (api, formatMessage) => keydownHandler(keymapList(api, formatMessage));
|
|
@@ -174,6 +174,9 @@ export const createPlugin = (api, getIntl) => {
|
|
|
174
174
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
175
175
|
const maybeNodeWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 ? void 0 : (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
176
176
|
const redrawDecorations = decorations === DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
177
|
+
const {
|
|
178
|
+
formatMessage
|
|
179
|
+
} = getIntl();
|
|
177
180
|
|
|
178
181
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
179
182
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
@@ -262,7 +265,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
262
265
|
const {
|
|
263
266
|
decs,
|
|
264
267
|
decorationState: updatedDecorationState
|
|
265
|
-
} = dropTargetDecorations(oldState, newState, api);
|
|
268
|
+
} = dropTargetDecorations(oldState, newState, api, formatMessage);
|
|
266
269
|
decorationState = updatedDecorationState;
|
|
267
270
|
decorations = decorations.add(newState.doc, decs);
|
|
268
271
|
}
|
|
@@ -289,7 +292,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
289
292
|
const {
|
|
290
293
|
decs,
|
|
291
294
|
decorationState: updatedDecorationState
|
|
292
|
-
} = dropTargetDecorations(oldState, newState, api);
|
|
295
|
+
} = dropTargetDecorations(oldState, newState, api, formatMessage);
|
|
293
296
|
decorationState = updatedDecorationState;
|
|
294
297
|
decorations = decorations.add(newState.doc, decs);
|
|
295
298
|
}
|
|
@@ -398,7 +401,8 @@ export const createPlugin = (api, getIntl) => {
|
|
|
398
401
|
if (!nodeElement) {
|
|
399
402
|
return false;
|
|
400
403
|
}
|
|
401
|
-
const
|
|
404
|
+
const domPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? Math.max(view.posAtDOM(nodeElement, 0) - 1, 0) : view.posAtDOM(nodeElement, 0) - 1;
|
|
405
|
+
const nodeTarget = state.doc.nodeAt(domPos);
|
|
402
406
|
isSameNode = !!(nodeTarget && draggable !== null && draggable !== void 0 && draggable.eq(nodeTarget));
|
|
403
407
|
}
|
|
404
408
|
if (isSameNode) {
|
|
@@ -446,11 +450,12 @@ export const createPlugin = (api, getIntl) => {
|
|
|
446
450
|
return true;
|
|
447
451
|
}
|
|
448
452
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
453
|
+
if (event.shiftKey && event.ctrlKey && fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
454
|
+
const {
|
|
455
|
+
formatMessage
|
|
456
|
+
} = getIntl();
|
|
452
457
|
//prevent holding down key combo from firing repeatedly
|
|
453
|
-
if (!event.repeat && boundKeydownHandler(api)(view, event)) {
|
|
458
|
+
if (!event.repeat && boundKeydownHandler(api, formatMessage)(view, event)) {
|
|
454
459
|
event.preventDefault();
|
|
455
460
|
return true;
|
|
456
461
|
}
|