@atlaskit/editor-plugin-block-controls 9.0.32 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/blockControlsPlugin.js +29 -10
- package/dist/cjs/pm-plugins/utils/expand-and-update-selection.js +69 -0
- package/dist/cjs/ui/drag-handle.js +43 -99
- package/dist/es2019/blockControlsPlugin.js +19 -0
- package/dist/es2019/pm-plugins/utils/expand-and-update-selection.js +65 -0
- package/dist/es2019/ui/drag-handle.js +2 -60
- package/dist/esm/blockControlsPlugin.js +29 -10
- package/dist/esm/pm-plugins/utils/expand-and-update-selection.js +63 -0
- package/dist/esm/ui/drag-handle.js +39 -95
- package/dist/types/blockControlsPluginType.d.ts +14 -0
- package/dist/types/pm-plugins/utils/expand-and-update-selection.d.ts +20 -0
- package/dist/types/ui/consts.d.ts +1 -1
- package/dist/types-ts4.5/blockControlsPluginType.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/utils/expand-and-update-selection.d.ts +20 -0
- package/dist/types-ts4.5/ui/consts.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 9.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`81e6d01a5d2b5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/81e6d01a5d2b5) -
|
|
8
|
+
Expose expandAndUpdateSelection as a plugin command so other plugins can update the ProseMirror
|
|
9
|
+
selection using the same block-control click logic
|
|
10
|
+
|
|
11
|
+
## 9.0.33
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 9.0.32
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -24,6 +24,7 @@ var _main = require("./pm-plugins/main");
|
|
|
24
24
|
var _editorCommands = require("./pm-plugins/selection-preservation/editor-commands");
|
|
25
25
|
var _pluginKey = require("./pm-plugins/selection-preservation/plugin-key");
|
|
26
26
|
var _pmPlugin2 = require("./pm-plugins/selection-preservation/pm-plugin");
|
|
27
|
+
var _expandAndUpdateSelection2 = require("./pm-plugins/utils/expand-and-update-selection");
|
|
27
28
|
var _getSelection = require("./pm-plugins/utils/getSelection");
|
|
28
29
|
var _globalStyles = require("./ui/global-styles");
|
|
29
30
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -84,11 +85,29 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
84
85
|
return pmPlugins;
|
|
85
86
|
},
|
|
86
87
|
commands: {
|
|
88
|
+
expandAndUpdateSelection: function expandAndUpdateSelection(_ref3) {
|
|
89
|
+
var startPos = _ref3.startPos,
|
|
90
|
+
selection = _ref3.selection,
|
|
91
|
+
isShiftPressed = _ref3.isShiftPressed,
|
|
92
|
+
nodeType = _ref3.nodeType;
|
|
93
|
+
return function (_ref4) {
|
|
94
|
+
var tr = _ref4.tr;
|
|
95
|
+
(0, _expandAndUpdateSelection2.expandAndUpdateSelection)({
|
|
96
|
+
tr: tr,
|
|
97
|
+
selection: selection,
|
|
98
|
+
startPos: startPos,
|
|
99
|
+
isShiftPressed: isShiftPressed,
|
|
100
|
+
nodeType: nodeType,
|
|
101
|
+
api: api
|
|
102
|
+
});
|
|
103
|
+
return tr;
|
|
104
|
+
};
|
|
105
|
+
},
|
|
87
106
|
moveNode: (0, _moveNode.moveNode)(api),
|
|
88
107
|
moveToLayout: (0, _moveToLayout.moveToLayout)(api),
|
|
89
108
|
showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType, handleOptions, rootPos, rootAnchorName, rootNodeType) {
|
|
90
|
-
return function (
|
|
91
|
-
var tr =
|
|
109
|
+
return function (_ref5) {
|
|
110
|
+
var tr = _ref5.tr;
|
|
92
111
|
var currMeta = tr.getMeta(_main.key);
|
|
93
112
|
tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
94
113
|
activeNode: {
|
|
@@ -105,9 +124,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
105
124
|
};
|
|
106
125
|
},
|
|
107
126
|
toggleBlockMenu: function toggleBlockMenu(options) {
|
|
108
|
-
return function (
|
|
127
|
+
return function (_ref6) {
|
|
109
128
|
var _api$userIntent, _api$blockControls, _options$anchorName, _api$blockControls2;
|
|
110
|
-
var tr =
|
|
129
|
+
var tr = _ref6.tr;
|
|
111
130
|
if (!(0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
|
|
112
131
|
return tr;
|
|
113
132
|
}
|
|
@@ -212,9 +231,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
212
231
|
};
|
|
213
232
|
},
|
|
214
233
|
setNodeDragged: function setNodeDragged(getPos, anchorName, nodeType) {
|
|
215
|
-
return function (
|
|
234
|
+
return function (_ref7) {
|
|
216
235
|
var _api$userIntent6;
|
|
217
|
-
var tr =
|
|
236
|
+
var tr = _ref7.tr;
|
|
218
237
|
var pos = getPos();
|
|
219
238
|
if (pos === undefined) {
|
|
220
239
|
return tr;
|
|
@@ -244,9 +263,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
244
263
|
};
|
|
245
264
|
},
|
|
246
265
|
setMultiSelectPositions: function setMultiSelectPositions(anchor, head) {
|
|
247
|
-
return function (
|
|
266
|
+
return function (_ref8) {
|
|
248
267
|
var _api$selection, _$to$nodeBefore, _$from$nodeAfter;
|
|
249
|
-
var tr =
|
|
268
|
+
var tr = _ref8.tr;
|
|
250
269
|
var _tr$selection = tr.selection,
|
|
251
270
|
userAnchor = _tr$selection.anchor,
|
|
252
271
|
userHead = _tr$selection.head;
|
|
@@ -292,8 +311,8 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
292
311
|
};
|
|
293
312
|
},
|
|
294
313
|
setSelectedViaDragHandle: function setSelectedViaDragHandle(isSelectedViaDragHandle) {
|
|
295
|
-
return function (
|
|
296
|
-
var tr =
|
|
314
|
+
return function (_ref9) {
|
|
315
|
+
var tr = _ref9.tr;
|
|
297
316
|
var currMeta = tr.getMeta(_main.key);
|
|
298
317
|
return tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
299
318
|
isSelectedViaDragHandle: isSelectedViaDragHandle
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.expandAndUpdateSelection = void 0;
|
|
7
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
10
|
+
var _getSelection = require("./getSelection");
|
|
11
|
+
var _selection2 = require("./selection");
|
|
12
|
+
var isPosWithinRange = function isPosWithinRange(pos, range) {
|
|
13
|
+
return range.start <= pos && range.end >= pos + 1;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Expands the current selection to encompass the full block range
|
|
17
|
+
* starting from the given resolved position.
|
|
18
|
+
*/
|
|
19
|
+
var getExpandedSelectionRange = function getExpandedSelectionRange(_ref) {
|
|
20
|
+
var selection = _ref.selection,
|
|
21
|
+
doc = _ref.doc,
|
|
22
|
+
resolvedStartPos = _ref.resolvedStartPos,
|
|
23
|
+
isShiftPressed = _ref.isShiftPressed;
|
|
24
|
+
// When not pressing shift, expand the current selection
|
|
25
|
+
// When shift selecting upwards, expand from start of node to selection end
|
|
26
|
+
// When shift selecting downwards, expand from selection start to end of node
|
|
27
|
+
var selectUp = resolvedStartPos.pos < selection.from;
|
|
28
|
+
var $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
29
|
+
var $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
30
|
+
var adjusted = isShiftPressed ? {
|
|
31
|
+
$from: $from,
|
|
32
|
+
$to: $to
|
|
33
|
+
} : (0, _selection2.adjustSelectionBoundsForEdgePositions)($from, $to);
|
|
34
|
+
return (0, _selection.expandToBlockRange)(adjusted.$from, adjusted.$to);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
38
|
+
*
|
|
39
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
40
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
41
|
+
* - For tables, a table cell selection is used.
|
|
42
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
43
|
+
*/
|
|
44
|
+
var expandAndUpdateSelection = exports.expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
|
|
45
|
+
var tr = _ref2.tr,
|
|
46
|
+
selection = _ref2.selection,
|
|
47
|
+
startPos = _ref2.startPos,
|
|
48
|
+
isShiftPressed = _ref2.isShiftPressed,
|
|
49
|
+
nodeType = _ref2.nodeType,
|
|
50
|
+
api = _ref2.api;
|
|
51
|
+
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
52
|
+
var expandedRange = getExpandedSelectionRange({
|
|
53
|
+
doc: tr.doc,
|
|
54
|
+
selection: selection,
|
|
55
|
+
resolvedStartPos: resolvedStartPos,
|
|
56
|
+
isShiftPressed: isShiftPressed
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Set selection to expanded selection range if it encompasses the clicked drag handle
|
|
60
|
+
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && (0, _selection.isMultiBlockRange)(expandedRange.range)) {
|
|
61
|
+
// Then create a selection from the start of the first node to the end of the last node
|
|
62
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
63
|
+
} else if (nodeType === 'table') {
|
|
64
|
+
(0, _utils.selectTableClosestToPos)(tr, tr.doc.resolve(startPos + 1));
|
|
65
|
+
} else {
|
|
66
|
+
// Select the clicked drag handle's node only
|
|
67
|
+
(0, _getSelection.selectNode)(tr, startPos, nodeType, api);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -17,12 +17,10 @@ var _browser = require("@atlaskit/editor-common/browser");
|
|
|
17
17
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
18
18
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
19
19
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
20
|
-
var _selection = require("@atlaskit/editor-common/selection");
|
|
21
20
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
22
21
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
23
22
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
24
23
|
var _consts = require("@atlaskit/editor-shared-styles/consts");
|
|
25
|
-
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
26
24
|
var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/core/drag-handle-vertical"));
|
|
27
25
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
28
26
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
@@ -37,8 +35,9 @@ var _main = require("../pm-plugins/main");
|
|
|
37
35
|
var _pluginKey = require("../pm-plugins/selection-preservation/plugin-key");
|
|
38
36
|
var _analytics2 = require("../pm-plugins/utils/analytics");
|
|
39
37
|
var _dragHandlePositions = require("../pm-plugins/utils/drag-handle-positions");
|
|
38
|
+
var _expandAndUpdateSelection = require("../pm-plugins/utils/expand-and-update-selection");
|
|
40
39
|
var _getSelection = require("../pm-plugins/utils/getSelection");
|
|
41
|
-
var
|
|
40
|
+
var _selection = require("../pm-plugins/utils/selection");
|
|
42
41
|
var _consts2 = require("./consts");
|
|
43
42
|
var _dragHandleNestedIcon = require("./drag-handle-nested-icon");
|
|
44
43
|
var _dragPreview = require("./drag-preview");
|
|
@@ -340,73 +339,18 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
340
339
|
}
|
|
341
340
|
return _consts2.nodeMargins[nodeTypeName] || _consts2.nodeMargins['default'];
|
|
342
341
|
};
|
|
343
|
-
var
|
|
344
|
-
return range.start <= pos && range.end >= pos + 1;
|
|
345
|
-
};
|
|
346
|
-
/**
|
|
347
|
-
* From the current selection and the position of the drag handle being clicked,
|
|
348
|
-
* calculate the expanded block range up to the common ancestor.
|
|
349
|
-
*/
|
|
350
|
-
var getExpandedSelectionRange = function getExpandedSelectionRange(_ref) {
|
|
351
|
-
var selection = _ref.selection,
|
|
352
|
-
doc = _ref.doc,
|
|
353
|
-
resolvedStartPos = _ref.resolvedStartPos,
|
|
354
|
-
isShiftPressed = _ref.isShiftPressed;
|
|
355
|
-
// When not pressing shift, expand the current selection
|
|
356
|
-
// When shift selecting upwards, expand from start of node to selection end
|
|
357
|
-
// When shift selecting downwards, expand from selection start to end of node
|
|
358
|
-
var selectUp = resolvedStartPos.pos < selection.from;
|
|
359
|
-
var $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
360
|
-
var $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
361
|
-
var adjusted = isShiftPressed ? {
|
|
362
|
-
$from: $from,
|
|
363
|
-
$to: $to
|
|
364
|
-
} : (0, _selection2.adjustSelectionBoundsForEdgePositions)($from, $to);
|
|
365
|
-
return (0, _selection.expandToBlockRange)(adjusted.$from, adjusted.$to);
|
|
366
|
-
};
|
|
367
|
-
/**
|
|
368
|
-
* Updates the transaction with preserved selection logic.
|
|
369
|
-
* Sets selection to expanded selection range if it encompasses the clicked drag handle,
|
|
370
|
-
* otherwise selects the clicked drag handle's node only.
|
|
371
|
-
*/
|
|
372
|
-
var expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
|
|
373
|
-
var tr = _ref2.tr,
|
|
374
|
-
selection = _ref2.selection,
|
|
375
|
-
startPos = _ref2.startPos,
|
|
376
|
-
isShiftPressed = _ref2.isShiftPressed,
|
|
377
|
-
nodeType = _ref2.nodeType,
|
|
378
|
-
api = _ref2.api;
|
|
379
|
-
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
380
|
-
var expandedRange = getExpandedSelectionRange({
|
|
381
|
-
doc: tr.doc,
|
|
382
|
-
selection: selection,
|
|
383
|
-
resolvedStartPos: resolvedStartPos,
|
|
384
|
-
isShiftPressed: isShiftPressed
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// Set selection to expanded selection range if it encompases the clicked drag handle
|
|
388
|
-
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && (0, _selection.isMultiBlockRange)(expandedRange.range)) {
|
|
389
|
-
// Then create a selection from the start of the first node to the end of the last node
|
|
390
|
-
tr.setSelection(_state.TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
391
|
-
} else if (nodeType === 'table') {
|
|
392
|
-
(0, _utils2.selectTableClosestToPos)(tr, tr.doc.resolve(startPos + 1));
|
|
393
|
-
} else {
|
|
394
|
-
// Select the clicked drag handle's node only
|
|
395
|
-
(0, _getSelection.selectNode)(tr, startPos, nodeType, api);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
342
|
+
var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
399
343
|
var _api$core4;
|
|
400
|
-
var view =
|
|
401
|
-
api =
|
|
402
|
-
formatMessage =
|
|
403
|
-
getPos =
|
|
404
|
-
anchorName =
|
|
405
|
-
nodeType =
|
|
406
|
-
handleOptions =
|
|
407
|
-
|
|
408
|
-
isTopLevelNode =
|
|
409
|
-
anchorRectCache =
|
|
344
|
+
var view = _ref.view,
|
|
345
|
+
api = _ref.api,
|
|
346
|
+
formatMessage = _ref.formatMessage,
|
|
347
|
+
getPos = _ref.getPos,
|
|
348
|
+
anchorName = _ref.anchorName,
|
|
349
|
+
nodeType = _ref.nodeType,
|
|
350
|
+
handleOptions = _ref.handleOptions,
|
|
351
|
+
_ref$isTopLevelNode = _ref.isTopLevelNode,
|
|
352
|
+
isTopLevelNode = _ref$isTopLevelNode === void 0 ? true : _ref$isTopLevelNode,
|
|
353
|
+
anchorRectCache = _ref.anchorRectCache;
|
|
410
354
|
var buttonRef = (0, _react.useRef)(null);
|
|
411
355
|
var mouseDownRef = (0, _react.useRef)(false);
|
|
412
356
|
var _useState = (0, _react.useState)(false),
|
|
@@ -521,9 +465,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
521
465
|
}, []);
|
|
522
466
|
var handleOnClickNew = (0, _react.useCallback)(function (e) {
|
|
523
467
|
var _api$core;
|
|
524
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (
|
|
468
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
525
469
|
var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
|
|
526
|
-
var tr =
|
|
470
|
+
var tr = _ref2.tr;
|
|
527
471
|
var startPos = getPos();
|
|
528
472
|
if (startPos === undefined) {
|
|
529
473
|
return tr;
|
|
@@ -540,7 +484,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
540
484
|
nodeType: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
541
485
|
}
|
|
542
486
|
})(tr);
|
|
543
|
-
expandAndUpdateSelection({
|
|
487
|
+
(0, _expandAndUpdateSelection.expandAndUpdateSelection)({
|
|
544
488
|
tr: tr,
|
|
545
489
|
selection: selection,
|
|
546
490
|
startPos: startPos,
|
|
@@ -572,9 +516,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
572
516
|
if (!isMultiSelect) {
|
|
573
517
|
setDragHandleSelected(!dragHandleSelected);
|
|
574
518
|
}
|
|
575
|
-
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (
|
|
519
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref3) {
|
|
576
520
|
var _api$blockControls$sh, _api$analytics2;
|
|
577
|
-
var tr =
|
|
521
|
+
var tr = _ref3.tr;
|
|
578
522
|
var startPos = getPos();
|
|
579
523
|
if (startPos === undefined) {
|
|
580
524
|
return tr;
|
|
@@ -585,8 +529,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
585
529
|
tr = (0, _getSelection.selectNode)(tr, startPos, nodeType, api);
|
|
586
530
|
} else if (isTopLevelNodeValue && $anchor.depth <= _consts2.DRAG_HANDLE_MAX_SHIFT_CLICK_DEPTH && e.shiftKey && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_shift_click_select')) {
|
|
587
531
|
var _api$blockControls3;
|
|
588
|
-
var alignAnchorHeadToSel = (0,
|
|
589
|
-
var selectionWithExpandedHead = (0,
|
|
532
|
+
var alignAnchorHeadToSel = (0, _selection.alignAnchorHeadInDirectionOfPos)(tr.selection, startPos);
|
|
533
|
+
var selectionWithExpandedHead = (0, _selection.expandSelectionHeadToNodeAtPos)(alignAnchorHeadToSel, startPos);
|
|
590
534
|
tr.setSelection(selectionWithExpandedHead);
|
|
591
535
|
api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.setMultiSelectPositions()({
|
|
592
536
|
tr: tr
|
|
@@ -614,8 +558,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
614
558
|
if (!e.repeat && e.key === ' ') {
|
|
615
559
|
var _api$core3;
|
|
616
560
|
var startPos = getPos();
|
|
617
|
-
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (
|
|
618
|
-
var tr =
|
|
561
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref4) {
|
|
562
|
+
var tr = _ref4.tr;
|
|
619
563
|
if (startPos === undefined) {
|
|
620
564
|
return tr;
|
|
621
565
|
}
|
|
@@ -649,14 +593,14 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
649
593
|
e.preventDefault();
|
|
650
594
|
e.stopPropagation();
|
|
651
595
|
var startPos = getPos();
|
|
652
|
-
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (
|
|
596
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref5) {
|
|
653
597
|
var _selectionPreservatio2, _api$blockControls4, _api$blockControls5, _api$userIntent;
|
|
654
|
-
var tr =
|
|
598
|
+
var tr = _ref5.tr;
|
|
655
599
|
if (startPos === undefined) {
|
|
656
600
|
return tr;
|
|
657
601
|
}
|
|
658
602
|
var selection = ((_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) || tr.selection;
|
|
659
|
-
expandAndUpdateSelection({
|
|
603
|
+
(0, _expandAndUpdateSelection.expandAndUpdateSelection)({
|
|
660
604
|
tr: tr,
|
|
661
605
|
selection: selection,
|
|
662
606
|
startPos: startPos,
|
|
@@ -707,13 +651,13 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
707
651
|
start: start
|
|
708
652
|
};
|
|
709
653
|
},
|
|
710
|
-
onGenerateDragPreview: function onGenerateDragPreview(
|
|
654
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref6) {
|
|
711
655
|
var _api$blockControls$sh2;
|
|
712
|
-
var nativeSetDragImage =
|
|
656
|
+
var nativeSetDragImage = _ref6.nativeSetDragImage;
|
|
713
657
|
if (isMultiSelect) {
|
|
714
658
|
var _api$core6;
|
|
715
|
-
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (
|
|
716
|
-
var tr =
|
|
659
|
+
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref7) {
|
|
660
|
+
var tr = _ref7.tr;
|
|
717
661
|
var handlePos = getPos();
|
|
718
662
|
if (typeof handlePos !== 'number') {
|
|
719
663
|
return tr;
|
|
@@ -791,8 +735,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
791
735
|
};
|
|
792
736
|
}
|
|
793
737
|
},
|
|
794
|
-
render: function render(
|
|
795
|
-
var container =
|
|
738
|
+
render: function render(_ref8) {
|
|
739
|
+
var container = _ref8.container;
|
|
796
740
|
var dom = view.dom.querySelector("[".concat((0, _domAttrName.getAnchorAttrName)(), "=\"").concat(anchorName, "\"]"));
|
|
797
741
|
if (!dom) {
|
|
798
742
|
return;
|
|
@@ -828,9 +772,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
828
772
|
if (start === undefined) {
|
|
829
773
|
return;
|
|
830
774
|
}
|
|
831
|
-
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (
|
|
775
|
+
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref9) {
|
|
832
776
|
var _api$blockControls$sh3, _api$blockControls7, _api$analytics3;
|
|
833
|
-
var tr =
|
|
777
|
+
var tr = _ref9.tr;
|
|
834
778
|
var nodeTypes, hasSelectedMultipleNodes;
|
|
835
779
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
836
780
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
@@ -1235,16 +1179,16 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref3) {
|
|
|
1235
1179
|
var render = isTooltip ? buttonWithTooltip() : renderButton();
|
|
1236
1180
|
return (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? stickyRender : render;
|
|
1237
1181
|
};
|
|
1238
|
-
var DragHandleWithVisibility = exports.DragHandleWithVisibility = function DragHandleWithVisibility(
|
|
1239
|
-
var view =
|
|
1240
|
-
api =
|
|
1241
|
-
formatMessage =
|
|
1242
|
-
getPos =
|
|
1243
|
-
anchorName =
|
|
1244
|
-
nodeType =
|
|
1245
|
-
handleOptions =
|
|
1246
|
-
isTopLevelNode =
|
|
1247
|
-
anchorRectCache =
|
|
1182
|
+
var DragHandleWithVisibility = exports.DragHandleWithVisibility = function DragHandleWithVisibility(_ref0) {
|
|
1183
|
+
var view = _ref0.view,
|
|
1184
|
+
api = _ref0.api,
|
|
1185
|
+
formatMessage = _ref0.formatMessage,
|
|
1186
|
+
getPos = _ref0.getPos,
|
|
1187
|
+
anchorName = _ref0.anchorName,
|
|
1188
|
+
nodeType = _ref0.nodeType,
|
|
1189
|
+
handleOptions = _ref0.handleOptions,
|
|
1190
|
+
isTopLevelNode = _ref0.isTopLevelNode,
|
|
1191
|
+
anchorRectCache = _ref0.anchorRectCache;
|
|
1248
1192
|
var rightSideControlsEnabled = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
1249
1193
|
var _states$blockControls2, _states$blockControls3;
|
|
1250
1194
|
return {
|
|
@@ -16,6 +16,7 @@ import { createPlugin, key } from './pm-plugins/main';
|
|
|
16
16
|
import { startPreservingSelection, stopPreservingSelection } from './pm-plugins/selection-preservation/editor-commands';
|
|
17
17
|
import { selectionPreservationPluginKey } from './pm-plugins/selection-preservation/plugin-key';
|
|
18
18
|
import { createSelectionPreservationPlugin } from './pm-plugins/selection-preservation/pm-plugin';
|
|
19
|
+
import { expandAndUpdateSelection } from './pm-plugins/utils/expand-and-update-selection';
|
|
19
20
|
import { selectNode } from './pm-plugins/utils/getSelection';
|
|
20
21
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
21
22
|
export const blockControlsPlugin = ({
|
|
@@ -70,6 +71,24 @@ export const blockControlsPlugin = ({
|
|
|
70
71
|
return pmPlugins;
|
|
71
72
|
},
|
|
72
73
|
commands: {
|
|
74
|
+
expandAndUpdateSelection: ({
|
|
75
|
+
startPos,
|
|
76
|
+
selection,
|
|
77
|
+
isShiftPressed,
|
|
78
|
+
nodeType
|
|
79
|
+
}) => ({
|
|
80
|
+
tr
|
|
81
|
+
}) => {
|
|
82
|
+
expandAndUpdateSelection({
|
|
83
|
+
tr,
|
|
84
|
+
selection,
|
|
85
|
+
startPos,
|
|
86
|
+
isShiftPressed,
|
|
87
|
+
nodeType,
|
|
88
|
+
api: api
|
|
89
|
+
});
|
|
90
|
+
return tr;
|
|
91
|
+
},
|
|
73
92
|
moveNode: moveNode(api),
|
|
74
93
|
moveToLayout: moveToLayout(api),
|
|
75
94
|
showDragHandleAt: (pos, anchorName, nodeType, handleOptions, rootPos, rootAnchorName, rootNodeType) => ({
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
4
|
+
import { selectNode } from './getSelection';
|
|
5
|
+
import { adjustSelectionBoundsForEdgePositions } from './selection';
|
|
6
|
+
const isPosWithinRange = (pos, range) => {
|
|
7
|
+
return range.start <= pos && range.end >= pos + 1;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Expands the current selection to encompass the full block range
|
|
11
|
+
* starting from the given resolved position.
|
|
12
|
+
*/
|
|
13
|
+
const getExpandedSelectionRange = ({
|
|
14
|
+
selection,
|
|
15
|
+
doc,
|
|
16
|
+
resolvedStartPos,
|
|
17
|
+
isShiftPressed
|
|
18
|
+
}) => {
|
|
19
|
+
// When not pressing shift, expand the current selection
|
|
20
|
+
// When shift selecting upwards, expand from start of node to selection end
|
|
21
|
+
// When shift selecting downwards, expand from selection start to end of node
|
|
22
|
+
const selectUp = resolvedStartPos.pos < selection.from;
|
|
23
|
+
const $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
24
|
+
const $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
25
|
+
const adjusted = isShiftPressed ? {
|
|
26
|
+
$from,
|
|
27
|
+
$to
|
|
28
|
+
} : adjustSelectionBoundsForEdgePositions($from, $to);
|
|
29
|
+
return expandToBlockRange(adjusted.$from, adjusted.$to);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
33
|
+
*
|
|
34
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
35
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
36
|
+
* - For tables, a table cell selection is used.
|
|
37
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
38
|
+
*/
|
|
39
|
+
export const expandAndUpdateSelection = ({
|
|
40
|
+
tr,
|
|
41
|
+
selection,
|
|
42
|
+
startPos,
|
|
43
|
+
isShiftPressed,
|
|
44
|
+
nodeType,
|
|
45
|
+
api
|
|
46
|
+
}) => {
|
|
47
|
+
const resolvedStartPos = tr.doc.resolve(startPos);
|
|
48
|
+
const expandedRange = getExpandedSelectionRange({
|
|
49
|
+
doc: tr.doc,
|
|
50
|
+
selection,
|
|
51
|
+
resolvedStartPos,
|
|
52
|
+
isShiftPressed
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Set selection to expanded selection range if it encompasses the clicked drag handle
|
|
56
|
+
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
|
|
57
|
+
// Then create a selection from the start of the first node to the end of the last node
|
|
58
|
+
tr.setSelection(TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
59
|
+
} else if (nodeType === 'table') {
|
|
60
|
+
selectTableClosestToPos(tr, tr.doc.resolve(startPos + 1));
|
|
61
|
+
} else {
|
|
62
|
+
// Select the clicked drag handle's node only
|
|
63
|
+
selectNode(tr, startPos, nodeType, api);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -13,12 +13,10 @@ import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-commo
|
|
|
13
13
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
14
14
|
import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
|
|
15
15
|
import { blockControlsMessages } from '@atlaskit/editor-common/messages';
|
|
16
|
-
import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
|
|
17
16
|
import { DRAG_HANDLE_WIDTH, tableControlsSpacing } from '@atlaskit/editor-common/styles';
|
|
18
17
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
19
18
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
20
19
|
import { akEditorFullPageNarrowBreakout, akEditorTableToolbarSize, relativeSizeToBaseFontSize } from '@atlaskit/editor-shared-styles/consts';
|
|
21
|
-
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
22
20
|
import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
|
|
23
21
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
24
22
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
@@ -34,8 +32,9 @@ import { key } from '../pm-plugins/main';
|
|
|
34
32
|
import { selectionPreservationPluginKey } from '../pm-plugins/selection-preservation/plugin-key';
|
|
35
33
|
import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
|
|
36
34
|
import { getControlBottomCSSValue, getControlHeightCSSValue, getLeftPosition, getNodeHeight, getTopPosition, shouldBeSticky, shouldMaskNodeControls } from '../pm-plugins/utils/drag-handle-positions';
|
|
35
|
+
import { expandAndUpdateSelection } from '../pm-plugins/utils/expand-and-update-selection';
|
|
37
36
|
import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
|
|
38
|
-
import {
|
|
37
|
+
import { alignAnchorHeadInDirectionOfPos, expandSelectionHeadToNodeAtPos } from '../pm-plugins/utils/selection';
|
|
39
38
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_MAX_SHIFT_CLICK_DEPTH, DRAG_HANDLE_ZINDEX, dragHandleGap, nodeMargins, spacingBetweenNodesForPreview, STICKY_CONTROLS_TOP_MARGIN, STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER, topPositionAdjustment } from './consts';
|
|
40
39
|
import { DragHandleNestedIcon } from './drag-handle-nested-icon';
|
|
41
40
|
import { dragPreview } from './drag-preview';
|
|
@@ -334,63 +333,6 @@ const getNodeMargins = node => {
|
|
|
334
333
|
}
|
|
335
334
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
336
335
|
};
|
|
337
|
-
const isPosWithinRange = (pos, range) => {
|
|
338
|
-
return range.start <= pos && range.end >= pos + 1;
|
|
339
|
-
};
|
|
340
|
-
/**
|
|
341
|
-
* From the current selection and the position of the drag handle being clicked,
|
|
342
|
-
* calculate the expanded block range up to the common ancestor.
|
|
343
|
-
*/
|
|
344
|
-
const getExpandedSelectionRange = ({
|
|
345
|
-
selection,
|
|
346
|
-
doc,
|
|
347
|
-
resolvedStartPos,
|
|
348
|
-
isShiftPressed
|
|
349
|
-
}) => {
|
|
350
|
-
// When not pressing shift, expand the current selection
|
|
351
|
-
// When shift selecting upwards, expand from start of node to selection end
|
|
352
|
-
// When shift selecting downwards, expand from selection start to end of node
|
|
353
|
-
const selectUp = resolvedStartPos.pos < selection.from;
|
|
354
|
-
const $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
355
|
-
const $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
356
|
-
const adjusted = isShiftPressed ? {
|
|
357
|
-
$from,
|
|
358
|
-
$to
|
|
359
|
-
} : adjustSelectionBoundsForEdgePositions($from, $to);
|
|
360
|
-
return expandToBlockRange(adjusted.$from, adjusted.$to);
|
|
361
|
-
};
|
|
362
|
-
/**
|
|
363
|
-
* Updates the transaction with preserved selection logic.
|
|
364
|
-
* Sets selection to expanded selection range if it encompasses the clicked drag handle,
|
|
365
|
-
* otherwise selects the clicked drag handle's node only.
|
|
366
|
-
*/
|
|
367
|
-
const expandAndUpdateSelection = ({
|
|
368
|
-
tr,
|
|
369
|
-
selection,
|
|
370
|
-
startPos,
|
|
371
|
-
isShiftPressed,
|
|
372
|
-
nodeType,
|
|
373
|
-
api
|
|
374
|
-
}) => {
|
|
375
|
-
const resolvedStartPos = tr.doc.resolve(startPos);
|
|
376
|
-
const expandedRange = getExpandedSelectionRange({
|
|
377
|
-
doc: tr.doc,
|
|
378
|
-
selection,
|
|
379
|
-
resolvedStartPos,
|
|
380
|
-
isShiftPressed
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// Set selection to expanded selection range if it encompases the clicked drag handle
|
|
384
|
-
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
|
|
385
|
-
// Then create a selection from the start of the first node to the end of the last node
|
|
386
|
-
tr.setSelection(TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
387
|
-
} else if (nodeType === 'table') {
|
|
388
|
-
selectTableClosestToPos(tr, tr.doc.resolve(startPos + 1));
|
|
389
|
-
} else {
|
|
390
|
-
// Select the clicked drag handle's node only
|
|
391
|
-
selectNode(tr, startPos, nodeType, api);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
336
|
export const DragHandle = ({
|
|
395
337
|
view,
|
|
396
338
|
api,
|
|
@@ -19,6 +19,7 @@ import { createPlugin, key } from './pm-plugins/main';
|
|
|
19
19
|
import { startPreservingSelection as _startPreservingSelection, stopPreservingSelection as _stopPreservingSelection } from './pm-plugins/selection-preservation/editor-commands';
|
|
20
20
|
import { selectionPreservationPluginKey } from './pm-plugins/selection-preservation/plugin-key';
|
|
21
21
|
import { createSelectionPreservationPlugin } from './pm-plugins/selection-preservation/pm-plugin';
|
|
22
|
+
import { expandAndUpdateSelection as _expandAndUpdateSelection } from './pm-plugins/utils/expand-and-update-selection';
|
|
22
23
|
import { selectNode } from './pm-plugins/utils/getSelection';
|
|
23
24
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
24
25
|
export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
@@ -77,11 +78,29 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
77
78
|
return pmPlugins;
|
|
78
79
|
},
|
|
79
80
|
commands: {
|
|
81
|
+
expandAndUpdateSelection: function expandAndUpdateSelection(_ref3) {
|
|
82
|
+
var startPos = _ref3.startPos,
|
|
83
|
+
selection = _ref3.selection,
|
|
84
|
+
isShiftPressed = _ref3.isShiftPressed,
|
|
85
|
+
nodeType = _ref3.nodeType;
|
|
86
|
+
return function (_ref4) {
|
|
87
|
+
var tr = _ref4.tr;
|
|
88
|
+
_expandAndUpdateSelection({
|
|
89
|
+
tr: tr,
|
|
90
|
+
selection: selection,
|
|
91
|
+
startPos: startPos,
|
|
92
|
+
isShiftPressed: isShiftPressed,
|
|
93
|
+
nodeType: nodeType,
|
|
94
|
+
api: api
|
|
95
|
+
});
|
|
96
|
+
return tr;
|
|
97
|
+
};
|
|
98
|
+
},
|
|
80
99
|
moveNode: moveNode(api),
|
|
81
100
|
moveToLayout: moveToLayout(api),
|
|
82
101
|
showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType, handleOptions, rootPos, rootAnchorName, rootNodeType) {
|
|
83
|
-
return function (
|
|
84
|
-
var tr =
|
|
102
|
+
return function (_ref5) {
|
|
103
|
+
var tr = _ref5.tr;
|
|
85
104
|
var currMeta = tr.getMeta(key);
|
|
86
105
|
tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
87
106
|
activeNode: {
|
|
@@ -98,9 +117,9 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
98
117
|
};
|
|
99
118
|
},
|
|
100
119
|
toggleBlockMenu: function toggleBlockMenu(options) {
|
|
101
|
-
return function (
|
|
120
|
+
return function (_ref6) {
|
|
102
121
|
var _api$userIntent, _api$blockControls, _options$anchorName, _api$blockControls2;
|
|
103
|
-
var tr =
|
|
122
|
+
var tr = _ref6.tr;
|
|
104
123
|
if (!editorExperiment('platform_editor_block_menu', true)) {
|
|
105
124
|
return tr;
|
|
106
125
|
}
|
|
@@ -205,9 +224,9 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
205
224
|
};
|
|
206
225
|
},
|
|
207
226
|
setNodeDragged: function setNodeDragged(getPos, anchorName, nodeType) {
|
|
208
|
-
return function (
|
|
227
|
+
return function (_ref7) {
|
|
209
228
|
var _api$userIntent6;
|
|
210
|
-
var tr =
|
|
229
|
+
var tr = _ref7.tr;
|
|
211
230
|
var pos = getPos();
|
|
212
231
|
if (pos === undefined) {
|
|
213
232
|
return tr;
|
|
@@ -237,9 +256,9 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
237
256
|
};
|
|
238
257
|
},
|
|
239
258
|
setMultiSelectPositions: function setMultiSelectPositions(anchor, head) {
|
|
240
|
-
return function (
|
|
259
|
+
return function (_ref8) {
|
|
241
260
|
var _api$selection, _$to$nodeBefore, _$from$nodeAfter;
|
|
242
|
-
var tr =
|
|
261
|
+
var tr = _ref8.tr;
|
|
243
262
|
var _tr$selection = tr.selection,
|
|
244
263
|
userAnchor = _tr$selection.anchor,
|
|
245
264
|
userHead = _tr$selection.head;
|
|
@@ -285,8 +304,8 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
285
304
|
};
|
|
286
305
|
},
|
|
287
306
|
setSelectedViaDragHandle: function setSelectedViaDragHandle(isSelectedViaDragHandle) {
|
|
288
|
-
return function (
|
|
289
|
-
var tr =
|
|
307
|
+
return function (_ref9) {
|
|
308
|
+
var tr = _ref9.tr;
|
|
290
309
|
var currMeta = tr.getMeta(key);
|
|
291
310
|
return tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
292
311
|
isSelectedViaDragHandle: isSelectedViaDragHandle
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
4
|
+
import { selectNode } from './getSelection';
|
|
5
|
+
import { adjustSelectionBoundsForEdgePositions } from './selection';
|
|
6
|
+
var isPosWithinRange = function isPosWithinRange(pos, range) {
|
|
7
|
+
return range.start <= pos && range.end >= pos + 1;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Expands the current selection to encompass the full block range
|
|
11
|
+
* starting from the given resolved position.
|
|
12
|
+
*/
|
|
13
|
+
var getExpandedSelectionRange = function getExpandedSelectionRange(_ref) {
|
|
14
|
+
var selection = _ref.selection,
|
|
15
|
+
doc = _ref.doc,
|
|
16
|
+
resolvedStartPos = _ref.resolvedStartPos,
|
|
17
|
+
isShiftPressed = _ref.isShiftPressed;
|
|
18
|
+
// When not pressing shift, expand the current selection
|
|
19
|
+
// When shift selecting upwards, expand from start of node to selection end
|
|
20
|
+
// When shift selecting downwards, expand from selection start to end of node
|
|
21
|
+
var selectUp = resolvedStartPos.pos < selection.from;
|
|
22
|
+
var $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
23
|
+
var $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
24
|
+
var adjusted = isShiftPressed ? {
|
|
25
|
+
$from: $from,
|
|
26
|
+
$to: $to
|
|
27
|
+
} : adjustSelectionBoundsForEdgePositions($from, $to);
|
|
28
|
+
return expandToBlockRange(adjusted.$from, adjusted.$to);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
32
|
+
*
|
|
33
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
34
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
35
|
+
* - For tables, a table cell selection is used.
|
|
36
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
37
|
+
*/
|
|
38
|
+
export var expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
|
|
39
|
+
var tr = _ref2.tr,
|
|
40
|
+
selection = _ref2.selection,
|
|
41
|
+
startPos = _ref2.startPos,
|
|
42
|
+
isShiftPressed = _ref2.isShiftPressed,
|
|
43
|
+
nodeType = _ref2.nodeType,
|
|
44
|
+
api = _ref2.api;
|
|
45
|
+
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
46
|
+
var expandedRange = getExpandedSelectionRange({
|
|
47
|
+
doc: tr.doc,
|
|
48
|
+
selection: selection,
|
|
49
|
+
resolvedStartPos: resolvedStartPos,
|
|
50
|
+
isShiftPressed: isShiftPressed
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Set selection to expanded selection range if it encompasses the clicked drag handle
|
|
54
|
+
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
|
|
55
|
+
// Then create a selection from the start of the first node to the end of the last node
|
|
56
|
+
tr.setSelection(TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
57
|
+
} else if (nodeType === 'table') {
|
|
58
|
+
selectTableClosestToPos(tr, tr.doc.resolve(startPos + 1));
|
|
59
|
+
} else {
|
|
60
|
+
// Select the clicked drag handle's node only
|
|
61
|
+
selectNode(tr, startPos, nodeType, api);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -18,12 +18,10 @@ import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-commo
|
|
|
18
18
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
19
19
|
import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
|
|
20
20
|
import { blockControlsMessages } from '@atlaskit/editor-common/messages';
|
|
21
|
-
import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
|
|
22
21
|
import { DRAG_HANDLE_WIDTH, tableControlsSpacing } from '@atlaskit/editor-common/styles';
|
|
23
22
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
24
23
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
25
24
|
import { akEditorFullPageNarrowBreakout, akEditorTableToolbarSize, relativeSizeToBaseFontSize } from '@atlaskit/editor-shared-styles/consts';
|
|
26
|
-
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
27
25
|
import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
|
|
28
26
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
29
27
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
@@ -39,8 +37,9 @@ import { key } from '../pm-plugins/main';
|
|
|
39
37
|
import { selectionPreservationPluginKey } from '../pm-plugins/selection-preservation/plugin-key';
|
|
40
38
|
import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
|
|
41
39
|
import { getControlBottomCSSValue, getControlHeightCSSValue, getLeftPosition, getNodeHeight, getTopPosition, shouldBeSticky, shouldMaskNodeControls } from '../pm-plugins/utils/drag-handle-positions';
|
|
40
|
+
import { expandAndUpdateSelection } from '../pm-plugins/utils/expand-and-update-selection';
|
|
42
41
|
import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
|
|
43
|
-
import {
|
|
42
|
+
import { alignAnchorHeadInDirectionOfPos, expandSelectionHeadToNodeAtPos } from '../pm-plugins/utils/selection';
|
|
44
43
|
import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_MAX_SHIFT_CLICK_DEPTH, DRAG_HANDLE_ZINDEX, dragHandleGap, nodeMargins, spacingBetweenNodesForPreview, STICKY_CONTROLS_TOP_MARGIN, STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER, topPositionAdjustment } from './consts';
|
|
45
44
|
import { DragHandleNestedIcon } from './drag-handle-nested-icon';
|
|
46
45
|
import { dragPreview } from './drag-preview';
|
|
@@ -336,73 +335,18 @@ var getNodeMargins = function getNodeMargins(node) {
|
|
|
336
335
|
}
|
|
337
336
|
return nodeMargins[nodeTypeName] || nodeMargins['default'];
|
|
338
337
|
};
|
|
339
|
-
var
|
|
340
|
-
return range.start <= pos && range.end >= pos + 1;
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* From the current selection and the position of the drag handle being clicked,
|
|
344
|
-
* calculate the expanded block range up to the common ancestor.
|
|
345
|
-
*/
|
|
346
|
-
var getExpandedSelectionRange = function getExpandedSelectionRange(_ref) {
|
|
347
|
-
var selection = _ref.selection,
|
|
348
|
-
doc = _ref.doc,
|
|
349
|
-
resolvedStartPos = _ref.resolvedStartPos,
|
|
350
|
-
isShiftPressed = _ref.isShiftPressed;
|
|
351
|
-
// When not pressing shift, expand the current selection
|
|
352
|
-
// When shift selecting upwards, expand from start of node to selection end
|
|
353
|
-
// When shift selecting downwards, expand from selection start to end of node
|
|
354
|
-
var selectUp = resolvedStartPos.pos < selection.from;
|
|
355
|
-
var $from = isShiftPressed && selectUp ? resolvedStartPos : selection.$from;
|
|
356
|
-
var $to = isShiftPressed && !selectUp ? doc.resolve(resolvedStartPos.pos + 1) : selection.$to;
|
|
357
|
-
var adjusted = isShiftPressed ? {
|
|
358
|
-
$from: $from,
|
|
359
|
-
$to: $to
|
|
360
|
-
} : adjustSelectionBoundsForEdgePositions($from, $to);
|
|
361
|
-
return expandToBlockRange(adjusted.$from, adjusted.$to);
|
|
362
|
-
};
|
|
363
|
-
/**
|
|
364
|
-
* Updates the transaction with preserved selection logic.
|
|
365
|
-
* Sets selection to expanded selection range if it encompasses the clicked drag handle,
|
|
366
|
-
* otherwise selects the clicked drag handle's node only.
|
|
367
|
-
*/
|
|
368
|
-
var expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
|
|
369
|
-
var tr = _ref2.tr,
|
|
370
|
-
selection = _ref2.selection,
|
|
371
|
-
startPos = _ref2.startPos,
|
|
372
|
-
isShiftPressed = _ref2.isShiftPressed,
|
|
373
|
-
nodeType = _ref2.nodeType,
|
|
374
|
-
api = _ref2.api;
|
|
375
|
-
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
376
|
-
var expandedRange = getExpandedSelectionRange({
|
|
377
|
-
doc: tr.doc,
|
|
378
|
-
selection: selection,
|
|
379
|
-
resolvedStartPos: resolvedStartPos,
|
|
380
|
-
isShiftPressed: isShiftPressed
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// Set selection to expanded selection range if it encompases the clicked drag handle
|
|
384
|
-
if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
|
|
385
|
-
// Then create a selection from the start of the first node to the end of the last node
|
|
386
|
-
tr.setSelection(TextSelection.create(tr.doc, Math.min(selection.from, expandedRange.$from.pos), Math.max(selection.to, expandedRange.$to.pos)));
|
|
387
|
-
} else if (nodeType === 'table') {
|
|
388
|
-
selectTableClosestToPos(tr, tr.doc.resolve(startPos + 1));
|
|
389
|
-
} else {
|
|
390
|
-
// Select the clicked drag handle's node only
|
|
391
|
-
selectNode(tr, startPos, nodeType, api);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
export var DragHandle = function DragHandle(_ref3) {
|
|
338
|
+
export var DragHandle = function DragHandle(_ref) {
|
|
395
339
|
var _api$core4;
|
|
396
|
-
var view =
|
|
397
|
-
api =
|
|
398
|
-
formatMessage =
|
|
399
|
-
getPos =
|
|
400
|
-
anchorName =
|
|
401
|
-
nodeType =
|
|
402
|
-
handleOptions =
|
|
403
|
-
|
|
404
|
-
isTopLevelNode =
|
|
405
|
-
anchorRectCache =
|
|
340
|
+
var view = _ref.view,
|
|
341
|
+
api = _ref.api,
|
|
342
|
+
formatMessage = _ref.formatMessage,
|
|
343
|
+
getPos = _ref.getPos,
|
|
344
|
+
anchorName = _ref.anchorName,
|
|
345
|
+
nodeType = _ref.nodeType,
|
|
346
|
+
handleOptions = _ref.handleOptions,
|
|
347
|
+
_ref$isTopLevelNode = _ref.isTopLevelNode,
|
|
348
|
+
isTopLevelNode = _ref$isTopLevelNode === void 0 ? true : _ref$isTopLevelNode,
|
|
349
|
+
anchorRectCache = _ref.anchorRectCache;
|
|
406
350
|
var buttonRef = useRef(null);
|
|
407
351
|
var mouseDownRef = useRef(false);
|
|
408
352
|
var _useState = useState(false),
|
|
@@ -517,9 +461,9 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
517
461
|
}, []);
|
|
518
462
|
var handleOnClickNew = useCallback(function (e) {
|
|
519
463
|
var _api$core;
|
|
520
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (
|
|
464
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
521
465
|
var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
|
|
522
|
-
var tr =
|
|
466
|
+
var tr = _ref2.tr;
|
|
523
467
|
var startPos = getPos();
|
|
524
468
|
if (startPos === undefined) {
|
|
525
469
|
return tr;
|
|
@@ -568,9 +512,9 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
568
512
|
if (!isMultiSelect) {
|
|
569
513
|
setDragHandleSelected(!dragHandleSelected);
|
|
570
514
|
}
|
|
571
|
-
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (
|
|
515
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref3) {
|
|
572
516
|
var _api$blockControls$sh, _api$analytics2;
|
|
573
|
-
var tr =
|
|
517
|
+
var tr = _ref3.tr;
|
|
574
518
|
var startPos = getPos();
|
|
575
519
|
if (startPos === undefined) {
|
|
576
520
|
return tr;
|
|
@@ -610,8 +554,8 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
610
554
|
if (!e.repeat && e.key === ' ') {
|
|
611
555
|
var _api$core3;
|
|
612
556
|
var startPos = getPos();
|
|
613
|
-
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (
|
|
614
|
-
var tr =
|
|
557
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref4) {
|
|
558
|
+
var tr = _ref4.tr;
|
|
615
559
|
if (startPos === undefined) {
|
|
616
560
|
return tr;
|
|
617
561
|
}
|
|
@@ -645,9 +589,9 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
645
589
|
e.preventDefault();
|
|
646
590
|
e.stopPropagation();
|
|
647
591
|
var startPos = getPos();
|
|
648
|
-
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (
|
|
592
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref5) {
|
|
649
593
|
var _selectionPreservatio2, _api$blockControls4, _api$blockControls5, _api$userIntent;
|
|
650
|
-
var tr =
|
|
594
|
+
var tr = _ref5.tr;
|
|
651
595
|
if (startPos === undefined) {
|
|
652
596
|
return tr;
|
|
653
597
|
}
|
|
@@ -703,13 +647,13 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
703
647
|
start: start
|
|
704
648
|
};
|
|
705
649
|
},
|
|
706
|
-
onGenerateDragPreview: function onGenerateDragPreview(
|
|
650
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref6) {
|
|
707
651
|
var _api$blockControls$sh2;
|
|
708
|
-
var nativeSetDragImage =
|
|
652
|
+
var nativeSetDragImage = _ref6.nativeSetDragImage;
|
|
709
653
|
if (isMultiSelect) {
|
|
710
654
|
var _api$core6;
|
|
711
|
-
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (
|
|
712
|
-
var tr =
|
|
655
|
+
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref7) {
|
|
656
|
+
var tr = _ref7.tr;
|
|
713
657
|
var handlePos = getPos();
|
|
714
658
|
if (typeof handlePos !== 'number') {
|
|
715
659
|
return tr;
|
|
@@ -787,8 +731,8 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
787
731
|
};
|
|
788
732
|
}
|
|
789
733
|
},
|
|
790
|
-
render: function render(
|
|
791
|
-
var container =
|
|
734
|
+
render: function render(_ref8) {
|
|
735
|
+
var container = _ref8.container;
|
|
792
736
|
var dom = view.dom.querySelector("[".concat(getAnchorAttrName(), "=\"").concat(anchorName, "\"]"));
|
|
793
737
|
if (!dom) {
|
|
794
738
|
return;
|
|
@@ -824,9 +768,9 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
824
768
|
if (start === undefined) {
|
|
825
769
|
return;
|
|
826
770
|
}
|
|
827
|
-
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (
|
|
771
|
+
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref9) {
|
|
828
772
|
var _api$blockControls$sh3, _api$blockControls7, _api$analytics3;
|
|
829
|
-
var tr =
|
|
773
|
+
var tr = _ref9.tr;
|
|
830
774
|
var nodeTypes, hasSelectedMultipleNodes;
|
|
831
775
|
var resolvedMovingNode = tr.doc.resolve(start);
|
|
832
776
|
var maybeNode = resolvedMovingNode.nodeAfter;
|
|
@@ -1231,16 +1175,16 @@ export var DragHandle = function DragHandle(_ref3) {
|
|
|
1231
1175
|
var render = isTooltip ? buttonWithTooltip() : renderButton();
|
|
1232
1176
|
return editorExperiment('platform_editor_controls', 'variant1') ? stickyRender : render;
|
|
1233
1177
|
};
|
|
1234
|
-
export var DragHandleWithVisibility = function DragHandleWithVisibility(
|
|
1235
|
-
var view =
|
|
1236
|
-
api =
|
|
1237
|
-
formatMessage =
|
|
1238
|
-
getPos =
|
|
1239
|
-
anchorName =
|
|
1240
|
-
nodeType =
|
|
1241
|
-
handleOptions =
|
|
1242
|
-
isTopLevelNode =
|
|
1243
|
-
anchorRectCache =
|
|
1178
|
+
export var DragHandleWithVisibility = function DragHandleWithVisibility(_ref0) {
|
|
1179
|
+
var view = _ref0.view,
|
|
1180
|
+
api = _ref0.api,
|
|
1181
|
+
formatMessage = _ref0.formatMessage,
|
|
1182
|
+
getPos = _ref0.getPos,
|
|
1183
|
+
anchorName = _ref0.anchorName,
|
|
1184
|
+
nodeType = _ref0.nodeType,
|
|
1185
|
+
handleOptions = _ref0.handleOptions,
|
|
1186
|
+
isTopLevelNode = _ref0.isTopLevelNode,
|
|
1187
|
+
anchorRectCache = _ref0.anchorRectCache;
|
|
1244
1188
|
var rightSideControlsEnabled = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
|
|
1245
1189
|
var _states$blockControls2, _states$blockControls3;
|
|
1246
1190
|
return {
|
|
@@ -165,6 +165,20 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
165
165
|
unregisterNodeDecoration: (type: string) => void;
|
|
166
166
|
};
|
|
167
167
|
commands: {
|
|
168
|
+
/**
|
|
169
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
170
|
+
*
|
|
171
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
172
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
173
|
+
* - For tables, a table cell selection is used.
|
|
174
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
175
|
+
*/
|
|
176
|
+
expandAndUpdateSelection: (options: {
|
|
177
|
+
isShiftPressed: boolean;
|
|
178
|
+
nodeType: string;
|
|
179
|
+
selection: Selection;
|
|
180
|
+
startPos: number;
|
|
181
|
+
}) => EditorCommand;
|
|
168
182
|
handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
|
|
169
183
|
mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
170
184
|
moveNode: MoveNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type Selection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { BlockControlsPlugin } from '../../blockControlsPluginType';
|
|
4
|
+
export type ExpandAndUpdateSelectionOptions = {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
6
|
+
isShiftPressed: boolean;
|
|
7
|
+
nodeType: string;
|
|
8
|
+
selection: Selection;
|
|
9
|
+
startPos: number;
|
|
10
|
+
tr: Transaction;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
14
|
+
*
|
|
15
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
16
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
17
|
+
* - For tables, a table cell selection is used.
|
|
18
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
19
|
+
*/
|
|
20
|
+
export declare const expandAndUpdateSelection: ({ tr, selection, startPos, isShiftPressed, nodeType, api, }: ExpandAndUpdateSelectionOptions) => void;
|
|
@@ -26,8 +26,8 @@ export declare const STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER = 24;
|
|
|
26
26
|
export declare const QUICK_INSERT_HEIGHT = 24;
|
|
27
27
|
export declare const QUICK_INSERT_WIDTH = 24;
|
|
28
28
|
export declare const QUICK_INSERT_DIMENSIONS: {
|
|
29
|
-
width: number;
|
|
30
29
|
height: number;
|
|
30
|
+
width: number;
|
|
31
31
|
};
|
|
32
32
|
export declare const QUICK_INSERT_LEFT_OFFSET = 16;
|
|
33
33
|
export declare const dragHandleGap: (nodeType: string, parentNodeType?: string) => number;
|
|
@@ -167,6 +167,20 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
|
167
167
|
unregisterNodeDecoration: (type: string) => void;
|
|
168
168
|
};
|
|
169
169
|
commands: {
|
|
170
|
+
/**
|
|
171
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
172
|
+
*
|
|
173
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
174
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
175
|
+
* - For tables, a table cell selection is used.
|
|
176
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
177
|
+
*/
|
|
178
|
+
expandAndUpdateSelection: (options: {
|
|
179
|
+
isShiftPressed: boolean;
|
|
180
|
+
nodeType: string;
|
|
181
|
+
selection: Selection;
|
|
182
|
+
startPos: number;
|
|
183
|
+
}) => EditorCommand;
|
|
170
184
|
handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
|
|
171
185
|
mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
172
186
|
moveNode: MoveNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type Selection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { BlockControlsPlugin } from '../../blockControlsPluginType';
|
|
4
|
+
export type ExpandAndUpdateSelectionOptions = {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
6
|
+
isShiftPressed: boolean;
|
|
7
|
+
nodeType: string;
|
|
8
|
+
selection: Selection;
|
|
9
|
+
startPos: number;
|
|
10
|
+
tr: Transaction;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Updates the transaction's selection based on the clicked drag handle position.
|
|
14
|
+
*
|
|
15
|
+
* - If the clicked handle is within an existing multi-block selection range, the selection
|
|
16
|
+
* is expanded to cover both the existing range and the clicked node's range.
|
|
17
|
+
* - For tables, a table cell selection is used.
|
|
18
|
+
* - Otherwise, selects the single node at the clicked handle position.
|
|
19
|
+
*/
|
|
20
|
+
export declare const expandAndUpdateSelection: ({ tr, selection, startPos, isShiftPressed, nodeType, api, }: ExpandAndUpdateSelectionOptions) => void;
|
|
@@ -26,8 +26,8 @@ export declare const STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER = 24;
|
|
|
26
26
|
export declare const QUICK_INSERT_HEIGHT = 24;
|
|
27
27
|
export declare const QUICK_INSERT_WIDTH = 24;
|
|
28
28
|
export declare const QUICK_INSERT_DIMENSIONS: {
|
|
29
|
-
width: number;
|
|
30
29
|
height: number;
|
|
30
|
+
width: number;
|
|
31
31
|
};
|
|
32
32
|
export declare const QUICK_INSERT_LEFT_OFFSET = 16;
|
|
33
33
|
export declare const dragHandleGap: (nodeType: string, parentNodeType?: string) => number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
|
|
57
57
|
"@atlaskit/primitives": "^18.1.0",
|
|
58
58
|
"@atlaskit/theme": "^22.0.0",
|
|
59
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
59
|
+
"@atlaskit/tmp-editor-statsig": "^54.0.0",
|
|
60
60
|
"@atlaskit/tokens": "^11.4.0",
|
|
61
61
|
"@atlaskit/tooltip": "^21.1.0",
|
|
62
62
|
"@babel/runtime": "^7.0.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"uuid": "^3.1.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@atlaskit/editor-common": "^112.
|
|
70
|
+
"@atlaskit/editor-common": "^112.16.0",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-dom": "^18.2.0",
|
|
73
73
|
"react-intl-next": "npm:react-intl@^5.18.1"
|