@atlaskit/editor-plugin-block-controls 7.11.2 → 7.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/pm-plugins/selection-preservation/pm-plugin.js +3 -38
- package/dist/cjs/pm-plugins/utils/getSelection.js +7 -29
- package/dist/cjs/pm-plugins/utils/selection.js +57 -1
- package/dist/cjs/ui/drag-handle.js +2 -2
- package/dist/es2019/pm-plugins/selection-preservation/pm-plugin.js +3 -40
- package/dist/es2019/pm-plugins/utils/getSelection.js +6 -28
- package/dist/es2019/pm-plugins/utils/selection.js +60 -2
- package/dist/es2019/ui/drag-handle.js +2 -2
- package/dist/esm/pm-plugins/selection-preservation/pm-plugin.js +3 -38
- package/dist/esm/pm-plugins/utils/getSelection.js +6 -28
- package/dist/esm/pm-plugins/utils/selection.js +58 -2
- package/dist/esm/ui/drag-handle.js +2 -2
- package/dist/types/pm-plugins/main.d.ts +2 -2
- package/dist/types/pm-plugins/utils/getSelection.d.ts +0 -12
- package/dist/types/pm-plugins/utils/selection.d.ts +14 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/utils/getSelection.d.ts +0 -12
- package/dist/types-ts4.5/pm-plugins/utils/selection.d.ts +14 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 7.11.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`26f8da78a699c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/26f8da78a699c) -
|
|
8
|
+
EDITOR-3756 Fix initial collapse of preserved selection
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 7.11.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`59c74907ab1c6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/59c74907ab1c6) -
|
|
16
|
+
[ux] EDITOR-3727 fix selection preservation on empty lines
|
|
17
|
+
- [`7e5df3d5beaf3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e5df3d5beaf3) -
|
|
18
|
+
Add new flattenListStep and unwrapListStep and use for list -> paragraph step. Also moved
|
|
19
|
+
expandToBlockRange util function to editor-common to re-use
|
|
20
|
+
- [`e3779b75fdeca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e3779b75fdeca) -
|
|
21
|
+
EDITOR-1643 Promote syncBlock and bodiedSyncBlock to full schema
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 7.11.2
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -8,10 +8,7 @@ exports.createSelectionPreservationPlugin = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
10
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
-
var
|
|
12
|
-
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
13
|
-
var _main = require("../main");
|
|
14
|
-
var _getSelection = require("../utils/getSelection");
|
|
11
|
+
var _selection = require("../utils/selection");
|
|
15
12
|
var _editorCommands = require("./editor-commands");
|
|
16
13
|
var _pluginKey = require("./plugin-key");
|
|
17
14
|
var _utils = require("./utils");
|
|
@@ -63,7 +60,7 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
|
|
|
63
60
|
newState.preservedSelection = undefined;
|
|
64
61
|
}
|
|
65
62
|
if (newState.preservedSelection && tr.docChanged) {
|
|
66
|
-
newState.preservedSelection =
|
|
63
|
+
newState.preservedSelection = (0, _selection.mapPreservedSelection)(newState.preservedSelection, tr);
|
|
67
64
|
}
|
|
68
65
|
return newState;
|
|
69
66
|
}
|
|
@@ -81,10 +78,9 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
|
|
|
81
78
|
});
|
|
82
79
|
}
|
|
83
80
|
var currSel = newState.selection;
|
|
84
|
-
var wasEmptySelection = savedSel.from === savedSel.to;
|
|
85
81
|
var selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
|
|
86
82
|
var selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
|
|
87
|
-
if (
|
|
83
|
+
if (selectionUnchanged || selectionInvalid) {
|
|
88
84
|
return null;
|
|
89
85
|
}
|
|
90
86
|
try {
|
|
@@ -97,35 +93,4 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
|
|
|
97
93
|
return null;
|
|
98
94
|
}
|
|
99
95
|
});
|
|
100
|
-
};
|
|
101
|
-
var mapSelection = function mapSelection(selection, tr) {
|
|
102
|
-
var _ref = (0, _main.getBlockControlsMeta)(tr) || {},
|
|
103
|
-
nodeMoved = _ref.nodeMoved,
|
|
104
|
-
nodeMovedOffset = _ref.nodeMovedOffset;
|
|
105
|
-
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
106
|
-
if (selection instanceof _state.TextSelection) {
|
|
107
|
-
var from = mapping.map(selection.from);
|
|
108
|
-
var to = mapping.map(selection.to);
|
|
109
|
-
|
|
110
|
-
// expand the text selection range to block boundaries, so as document changes occur the
|
|
111
|
-
// selection always includes whole nodes
|
|
112
|
-
var expanded = (0, _getSelection.expandToBlockRange)(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
113
|
-
|
|
114
|
-
// collapse the expanded range to a valid selection range
|
|
115
|
-
var _collapseToSelectionR = (0, _getSelection.collapseToSelectionRange)(expanded.$from, expanded.$to),
|
|
116
|
-
$from = _collapseToSelectionR.$from,
|
|
117
|
-
$to = _collapseToSelectionR.$to;
|
|
118
|
-
|
|
119
|
-
// stop preserving if preserved selection becomes invalid or collapsed to a cursor
|
|
120
|
-
// e.g. after deleting the selection
|
|
121
|
-
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
return new _state.TextSelection($from, $to);
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
return selection.map(tr.doc, mapping);
|
|
128
|
-
} catch (_unused) {
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
96
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isNodeWithCodeBlock = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = exports.
|
|
6
|
+
exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isNodeWithCodeBlock = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = exports.collapseToSelectionRange = void 0;
|
|
7
7
|
var _selection2 = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
|
|
9
9
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -222,28 +222,6 @@ var rootTaskListDepth = exports.rootTaskListDepth = function rootTaskListDepth(t
|
|
|
222
222
|
return depth;
|
|
223
223
|
};
|
|
224
224
|
|
|
225
|
-
/**
|
|
226
|
-
* This expands the given $from and $to resolved positions to the block boundaries
|
|
227
|
-
* spanning all nodes in the range up to the nearest common ancestor.
|
|
228
|
-
*
|
|
229
|
-
* @param $from The resolved start position
|
|
230
|
-
* @param $to The resolved end position
|
|
231
|
-
* @returns An object containing the expanded $from and $to resolved positions
|
|
232
|
-
*/
|
|
233
|
-
var expandToBlockRange = exports.expandToBlockRange = function expandToBlockRange($from, $to) {
|
|
234
|
-
var range = $from.blockRange($to);
|
|
235
|
-
if (!range) {
|
|
236
|
-
return {
|
|
237
|
-
$from: $from,
|
|
238
|
-
$to: $to
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
$from: $from.doc.resolve(range.start),
|
|
243
|
-
$to: $to.doc.resolve(range.end)
|
|
244
|
-
};
|
|
245
|
-
};
|
|
246
|
-
|
|
247
225
|
/**
|
|
248
226
|
* Collapses the given $from and $to resolved positions to the nearest valid selection range.
|
|
249
227
|
*
|
|
@@ -254,14 +232,14 @@ var expandToBlockRange = exports.expandToBlockRange = function expandToBlockRang
|
|
|
254
232
|
* @returns An object containing the collapsed $from and $to resolved positions
|
|
255
233
|
*/
|
|
256
234
|
var collapseToSelectionRange = exports.collapseToSelectionRange = function collapseToSelectionRange($from, $to) {
|
|
257
|
-
var
|
|
258
|
-
|
|
235
|
+
var _$to$nodeBefore$nodeS, _$to$nodeBefore;
|
|
259
236
|
// Get the selections that would be made for the first and last node in the range
|
|
260
237
|
// We re-use the getSelection logic as it already handles various node types and edge cases
|
|
261
|
-
|
|
262
|
-
var
|
|
263
|
-
var
|
|
264
|
-
var
|
|
238
|
+
// always pass true for selectionEmpty to emulate a cursor selection within the node
|
|
239
|
+
var firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
|
|
240
|
+
var lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
|
|
241
|
+
var lastNodeStartPos = $to.pos - lastNodeSize;
|
|
242
|
+
var lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
|
|
265
243
|
|
|
266
244
|
// Return a selection spanning from the start of the first node selection to the end of the last node selection
|
|
267
245
|
return {
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getSelectedSlicePosition = exports.getMultiSelectionIfPosInside = exports.expandSelectionHeadToNodeAtPos = exports.alignAnchorHeadInDirectionOfPos = void 0;
|
|
6
|
+
exports.mapPreservedSelection = exports.getSelectedSlicePosition = exports.getMultiSelectionIfPosInside = exports.expandSelectionHeadToNodeAtPos = exports.alignAnchorHeadInDirectionOfPos = void 0;
|
|
7
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
7
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
10
|
var _main = require("../main");
|
|
11
|
+
var _getSelection = require("./getSelection");
|
|
9
12
|
var getMultiSelectionIfPosInside = exports.getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
|
|
10
13
|
var _api$blockControls, _pluginState$multiSel, _tr$getMeta;
|
|
11
14
|
var pluginState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
|
|
@@ -26,7 +29,12 @@ var getMultiSelectionIfPosInside = exports.getMultiSelectionIfPosInside = functi
|
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
/**
|
|
32
|
+
* Given a handle position, returns the from and to positions of the selected content.
|
|
33
|
+
* If the handle position is not in a multi-selection, it returns the node's from and to positions.
|
|
29
34
|
*
|
|
35
|
+
* @param handlePos The position of the handle
|
|
36
|
+
* @param tr The transaction to use for position calculations
|
|
37
|
+
* @param api The BlockControlsPlugin API for accessing shared state
|
|
30
38
|
* @returns from and to positions of the selected content (after expansion)
|
|
31
39
|
*/
|
|
32
40
|
var getSelectedSlicePosition = exports.getSelectedSlicePosition = function getSelectedSlicePosition(handlePos, tr, api) {
|
|
@@ -72,4 +80,52 @@ var expandSelectionHeadToNodeAtPos = exports.expandSelectionHeadToNodeAtPos = fu
|
|
|
72
80
|
*/
|
|
73
81
|
var alignAnchorHeadInDirectionOfPos = exports.alignAnchorHeadInDirectionOfPos = function alignAnchorHeadInDirectionOfPos(selection, pos) {
|
|
74
82
|
return selection instanceof _state.NodeSelection && Math.max(pos, selection.anchor) === selection.anchor ? new _state.TextSelection(selection.$head, selection.$anchor) : selection;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* This maps a preserved selection through a transaction, expanding text selections to block boundaries.
|
|
87
|
+
*
|
|
88
|
+
* @param selection The existing preserved selection to map
|
|
89
|
+
* @param tr The transaction to map through
|
|
90
|
+
* @returns The mapped selection or undefined if mapping is not possible
|
|
91
|
+
*/
|
|
92
|
+
var mapPreservedSelection = exports.mapPreservedSelection = function mapPreservedSelection(selection, tr) {
|
|
93
|
+
var _ref = (0, _main.getBlockControlsMeta)(tr) || {},
|
|
94
|
+
nodeMoved = _ref.nodeMoved,
|
|
95
|
+
nodeMovedOffset = _ref.nodeMovedOffset;
|
|
96
|
+
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
97
|
+
if (selection instanceof _state.TextSelection) {
|
|
98
|
+
var from = mapping.map(selection.from);
|
|
99
|
+
var to = mapping.map(selection.to);
|
|
100
|
+
var isSelectionEmpty = from === to;
|
|
101
|
+
var wasSelectionEmpty = selection.from === selection.to;
|
|
102
|
+
if (isSelectionEmpty) {
|
|
103
|
+
if (!wasSelectionEmpty) {
|
|
104
|
+
// If selection has become empty i.e. content has been deleted, stop preserving
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
// When preserving a cursor selection, just map the position without expanding
|
|
108
|
+
return new _state.TextSelection(tr.doc.resolve(from));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// expand the text selection range to block boundaries, so as document changes occur the
|
|
112
|
+
// selection always includes whole nodes
|
|
113
|
+
var expanded = (0, _selection.expandToBlockRange)(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
114
|
+
|
|
115
|
+
// collapse the expanded range to a valid selection range
|
|
116
|
+
var _collapseToSelectionR = (0, _getSelection.collapseToSelectionRange)(expanded.$from, expanded.$to),
|
|
117
|
+
$from = _collapseToSelectionR.$from,
|
|
118
|
+
$to = _collapseToSelectionR.$to;
|
|
119
|
+
|
|
120
|
+
// stop preserving if preserved selection becomes invalid
|
|
121
|
+
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
return new _state.TextSelection($from, $to);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return selection.map(tr.doc, mapping);
|
|
128
|
+
} catch (_unused) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
75
131
|
};
|
|
@@ -410,13 +410,14 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
|
|
|
410
410
|
var handleOnClickNew = (0, _react.useCallback)(function (e) {
|
|
411
411
|
var _api$core;
|
|
412
412
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
413
|
-
var _api$analytics, _resolvedStartPos$nod,
|
|
413
|
+
var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
|
|
414
414
|
var tr = _ref3.tr;
|
|
415
415
|
var startPos = getPos();
|
|
416
416
|
if (startPos === undefined) {
|
|
417
417
|
return tr;
|
|
418
418
|
}
|
|
419
419
|
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
420
|
+
var selection = ((_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
420
421
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
421
422
|
eventType: _analytics.EVENT_TYPE.UI,
|
|
422
423
|
action: _analytics.ACTION.CLICKED,
|
|
@@ -427,7 +428,6 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
|
|
|
427
428
|
nodeType: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
428
429
|
}
|
|
429
430
|
})(tr);
|
|
430
|
-
var selection = ((_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
431
431
|
var range = getExpandedSelectionRange({
|
|
432
432
|
doc: tr.doc,
|
|
433
433
|
selection: selection,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import {
|
|
4
|
-
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
-
import { getBlockControlsMeta } from '../main';
|
|
6
|
-
import { collapseToSelectionRange, expandToBlockRange } from '../utils/getSelection';
|
|
3
|
+
import { mapPreservedSelection } from '../utils/selection';
|
|
7
4
|
import { stopPreservingSelection } from './editor-commands';
|
|
8
5
|
import { selectionPreservationPluginKey } from './plugin-key';
|
|
9
6
|
import { getSelectionPreservationMeta, hasUserSelectionChange } from './utils';
|
|
@@ -56,7 +53,7 @@ export const createSelectionPreservationPlugin = () => {
|
|
|
56
53
|
newState.preservedSelection = undefined;
|
|
57
54
|
}
|
|
58
55
|
if (newState.preservedSelection && tr.docChanged) {
|
|
59
|
-
newState.preservedSelection =
|
|
56
|
+
newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
|
|
60
57
|
}
|
|
61
58
|
return newState;
|
|
62
59
|
}
|
|
@@ -74,10 +71,9 @@ export const createSelectionPreservationPlugin = () => {
|
|
|
74
71
|
});
|
|
75
72
|
}
|
|
76
73
|
const currSel = newState.selection;
|
|
77
|
-
const wasEmptySelection = savedSel.from === savedSel.to;
|
|
78
74
|
const selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
|
|
79
75
|
const selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
|
|
80
|
-
if (
|
|
76
|
+
if (selectionUnchanged || selectionInvalid) {
|
|
81
77
|
return null;
|
|
82
78
|
}
|
|
83
79
|
try {
|
|
@@ -90,37 +86,4 @@ export const createSelectionPreservationPlugin = () => {
|
|
|
90
86
|
return null;
|
|
91
87
|
}
|
|
92
88
|
});
|
|
93
|
-
};
|
|
94
|
-
const mapSelection = (selection, tr) => {
|
|
95
|
-
const {
|
|
96
|
-
nodeMoved,
|
|
97
|
-
nodeMovedOffset
|
|
98
|
-
} = getBlockControlsMeta(tr) || {};
|
|
99
|
-
const mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
100
|
-
if (selection instanceof TextSelection) {
|
|
101
|
-
const from = mapping.map(selection.from);
|
|
102
|
-
const to = mapping.map(selection.to);
|
|
103
|
-
|
|
104
|
-
// expand the text selection range to block boundaries, so as document changes occur the
|
|
105
|
-
// selection always includes whole nodes
|
|
106
|
-
const expanded = expandToBlockRange(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
107
|
-
|
|
108
|
-
// collapse the expanded range to a valid selection range
|
|
109
|
-
const {
|
|
110
|
-
$from,
|
|
111
|
-
$to
|
|
112
|
-
} = collapseToSelectionRange(expanded.$from, expanded.$to);
|
|
113
|
-
|
|
114
|
-
// stop preserving if preserved selection becomes invalid or collapsed to a cursor
|
|
115
|
-
// e.g. after deleting the selection
|
|
116
|
-
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
return new TextSelection($from, $to);
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
return selection.map(tr.doc, mapping);
|
|
123
|
-
} catch {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
89
|
};
|
|
@@ -219,28 +219,6 @@ export const rootTaskListDepth = taskListPos => {
|
|
|
219
219
|
return depth;
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
-
/**
|
|
223
|
-
* This expands the given $from and $to resolved positions to the block boundaries
|
|
224
|
-
* spanning all nodes in the range up to the nearest common ancestor.
|
|
225
|
-
*
|
|
226
|
-
* @param $from The resolved start position
|
|
227
|
-
* @param $to The resolved end position
|
|
228
|
-
* @returns An object containing the expanded $from and $to resolved positions
|
|
229
|
-
*/
|
|
230
|
-
export const expandToBlockRange = ($from, $to) => {
|
|
231
|
-
const range = $from.blockRange($to);
|
|
232
|
-
if (!range) {
|
|
233
|
-
return {
|
|
234
|
-
$from,
|
|
235
|
-
$to
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
$from: $from.doc.resolve(range.start),
|
|
240
|
-
$to: $to.doc.resolve(range.end)
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
|
|
244
222
|
/**
|
|
245
223
|
* Collapses the given $from and $to resolved positions to the nearest valid selection range.
|
|
246
224
|
*
|
|
@@ -251,14 +229,14 @@ export const expandToBlockRange = ($from, $to) => {
|
|
|
251
229
|
* @returns An object containing the collapsed $from and $to resolved positions
|
|
252
230
|
*/
|
|
253
231
|
export const collapseToSelectionRange = ($from, $to) => {
|
|
254
|
-
|
|
255
|
-
|
|
232
|
+
var _$to$nodeBefore$nodeS, _$to$nodeBefore;
|
|
256
233
|
// Get the selections that would be made for the first and last node in the range
|
|
257
234
|
// We re-use the getSelection logic as it already handles various node types and edge cases
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
const
|
|
235
|
+
// always pass true for selectionEmpty to emulate a cursor selection within the node
|
|
236
|
+
const firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
|
|
237
|
+
const lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
|
|
238
|
+
const lastNodeStartPos = $to.pos - lastNodeSize;
|
|
239
|
+
const lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
|
|
262
240
|
|
|
263
241
|
// Return a selection spanning from the start of the first node selection to the end of the last node selection
|
|
264
242
|
return {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { getBlockControlsMeta, key } from '../main';
|
|
5
|
+
import { collapseToSelectionRange } from './getSelection';
|
|
3
6
|
export const getMultiSelectionIfPosInside = (api, pos, tr) => {
|
|
4
7
|
var _api$blockControls, _pluginState$multiSel, _tr$getMeta;
|
|
5
8
|
const pluginState = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
|
|
@@ -20,7 +23,12 @@ export const getMultiSelectionIfPosInside = (api, pos, tr) => {
|
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/**
|
|
26
|
+
* Given a handle position, returns the from and to positions of the selected content.
|
|
27
|
+
* If the handle position is not in a multi-selection, it returns the node's from and to positions.
|
|
23
28
|
*
|
|
29
|
+
* @param handlePos The position of the handle
|
|
30
|
+
* @param tr The transaction to use for position calculations
|
|
31
|
+
* @param api The BlockControlsPlugin API for accessing shared state
|
|
24
32
|
* @returns from and to positions of the selected content (after expansion)
|
|
25
33
|
*/
|
|
26
34
|
export const getSelectedSlicePosition = (handlePos, tr, api) => {
|
|
@@ -67,4 +75,54 @@ export const expandSelectionHeadToNodeAtPos = (selection, nodePos) => {
|
|
|
67
75
|
*/
|
|
68
76
|
export const alignAnchorHeadInDirectionOfPos = (selection, pos) => {
|
|
69
77
|
return selection instanceof NodeSelection && Math.max(pos, selection.anchor) === selection.anchor ? new TextSelection(selection.$head, selection.$anchor) : selection;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* This maps a preserved selection through a transaction, expanding text selections to block boundaries.
|
|
82
|
+
*
|
|
83
|
+
* @param selection The existing preserved selection to map
|
|
84
|
+
* @param tr The transaction to map through
|
|
85
|
+
* @returns The mapped selection or undefined if mapping is not possible
|
|
86
|
+
*/
|
|
87
|
+
export const mapPreservedSelection = (selection, tr) => {
|
|
88
|
+
const {
|
|
89
|
+
nodeMoved,
|
|
90
|
+
nodeMovedOffset
|
|
91
|
+
} = getBlockControlsMeta(tr) || {};
|
|
92
|
+
const mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
93
|
+
if (selection instanceof TextSelection) {
|
|
94
|
+
const from = mapping.map(selection.from);
|
|
95
|
+
const to = mapping.map(selection.to);
|
|
96
|
+
const isSelectionEmpty = from === to;
|
|
97
|
+
const wasSelectionEmpty = selection.from === selection.to;
|
|
98
|
+
if (isSelectionEmpty) {
|
|
99
|
+
if (!wasSelectionEmpty) {
|
|
100
|
+
// If selection has become empty i.e. content has been deleted, stop preserving
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
// When preserving a cursor selection, just map the position without expanding
|
|
104
|
+
return new TextSelection(tr.doc.resolve(from));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// expand the text selection range to block boundaries, so as document changes occur the
|
|
108
|
+
// selection always includes whole nodes
|
|
109
|
+
const expanded = expandToBlockRange(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
110
|
+
|
|
111
|
+
// collapse the expanded range to a valid selection range
|
|
112
|
+
const {
|
|
113
|
+
$from,
|
|
114
|
+
$to
|
|
115
|
+
} = collapseToSelectionRange(expanded.$from, expanded.$to);
|
|
116
|
+
|
|
117
|
+
// stop preserving if preserved selection becomes invalid
|
|
118
|
+
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return new TextSelection($from, $to);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return selection.map(tr.doc, mapping);
|
|
125
|
+
} catch {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
70
128
|
};
|
|
@@ -389,12 +389,13 @@ export const DragHandle = ({
|
|
|
389
389
|
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
390
390
|
tr
|
|
391
391
|
}) => {
|
|
392
|
-
var _api$analytics, _resolvedStartPos$nod,
|
|
392
|
+
var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
|
|
393
393
|
const startPos = getPos();
|
|
394
394
|
if (startPos === undefined) {
|
|
395
395
|
return tr;
|
|
396
396
|
}
|
|
397
397
|
const resolvedStartPos = tr.doc.resolve(startPos);
|
|
398
|
+
const selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
398
399
|
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
|
|
399
400
|
eventType: EVENT_TYPE.UI,
|
|
400
401
|
action: ACTION.CLICKED,
|
|
@@ -405,7 +406,6 @@ export const DragHandle = ({
|
|
|
405
406
|
nodeType: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
406
407
|
}
|
|
407
408
|
})(tr);
|
|
408
|
-
const selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
409
409
|
const range = getExpandedSelectionRange({
|
|
410
410
|
doc: tr.doc,
|
|
411
411
|
selection,
|
|
@@ -3,10 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
-
import {
|
|
7
|
-
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
8
|
-
import { getBlockControlsMeta } from '../main';
|
|
9
|
-
import { collapseToSelectionRange, expandToBlockRange } from '../utils/getSelection';
|
|
6
|
+
import { mapPreservedSelection } from '../utils/selection';
|
|
10
7
|
import { stopPreservingSelection } from './editor-commands';
|
|
11
8
|
import { selectionPreservationPluginKey } from './plugin-key';
|
|
12
9
|
import { getSelectionPreservationMeta, hasUserSelectionChange } from './utils';
|
|
@@ -57,7 +54,7 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
|
|
|
57
54
|
newState.preservedSelection = undefined;
|
|
58
55
|
}
|
|
59
56
|
if (newState.preservedSelection && tr.docChanged) {
|
|
60
|
-
newState.preservedSelection =
|
|
57
|
+
newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
|
|
61
58
|
}
|
|
62
59
|
return newState;
|
|
63
60
|
}
|
|
@@ -75,10 +72,9 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
|
|
|
75
72
|
});
|
|
76
73
|
}
|
|
77
74
|
var currSel = newState.selection;
|
|
78
|
-
var wasEmptySelection = savedSel.from === savedSel.to;
|
|
79
75
|
var selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
|
|
80
76
|
var selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
|
|
81
|
-
if (
|
|
77
|
+
if (selectionUnchanged || selectionInvalid) {
|
|
82
78
|
return null;
|
|
83
79
|
}
|
|
84
80
|
try {
|
|
@@ -91,35 +87,4 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
|
|
|
91
87
|
return null;
|
|
92
88
|
}
|
|
93
89
|
});
|
|
94
|
-
};
|
|
95
|
-
var mapSelection = function mapSelection(selection, tr) {
|
|
96
|
-
var _ref = getBlockControlsMeta(tr) || {},
|
|
97
|
-
nodeMoved = _ref.nodeMoved,
|
|
98
|
-
nodeMovedOffset = _ref.nodeMovedOffset;
|
|
99
|
-
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
100
|
-
if (selection instanceof TextSelection) {
|
|
101
|
-
var from = mapping.map(selection.from);
|
|
102
|
-
var to = mapping.map(selection.to);
|
|
103
|
-
|
|
104
|
-
// expand the text selection range to block boundaries, so as document changes occur the
|
|
105
|
-
// selection always includes whole nodes
|
|
106
|
-
var expanded = expandToBlockRange(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
107
|
-
|
|
108
|
-
// collapse the expanded range to a valid selection range
|
|
109
|
-
var _collapseToSelectionR = collapseToSelectionRange(expanded.$from, expanded.$to),
|
|
110
|
-
$from = _collapseToSelectionR.$from,
|
|
111
|
-
$to = _collapseToSelectionR.$to;
|
|
112
|
-
|
|
113
|
-
// stop preserving if preserved selection becomes invalid or collapsed to a cursor
|
|
114
|
-
// e.g. after deleting the selection
|
|
115
|
-
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
return new TextSelection($from, $to);
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
return selection.map(tr.doc, mapping);
|
|
122
|
-
} catch (_unused) {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
90
|
};
|
|
@@ -216,28 +216,6 @@ export var rootTaskListDepth = function rootTaskListDepth(taskListPos) {
|
|
|
216
216
|
return depth;
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
-
/**
|
|
220
|
-
* This expands the given $from and $to resolved positions to the block boundaries
|
|
221
|
-
* spanning all nodes in the range up to the nearest common ancestor.
|
|
222
|
-
*
|
|
223
|
-
* @param $from The resolved start position
|
|
224
|
-
* @param $to The resolved end position
|
|
225
|
-
* @returns An object containing the expanded $from and $to resolved positions
|
|
226
|
-
*/
|
|
227
|
-
export var expandToBlockRange = function expandToBlockRange($from, $to) {
|
|
228
|
-
var range = $from.blockRange($to);
|
|
229
|
-
if (!range) {
|
|
230
|
-
return {
|
|
231
|
-
$from: $from,
|
|
232
|
-
$to: $to
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
$from: $from.doc.resolve(range.start),
|
|
237
|
-
$to: $to.doc.resolve(range.end)
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
|
|
241
219
|
/**
|
|
242
220
|
* Collapses the given $from and $to resolved positions to the nearest valid selection range.
|
|
243
221
|
*
|
|
@@ -248,14 +226,14 @@ export var expandToBlockRange = function expandToBlockRange($from, $to) {
|
|
|
248
226
|
* @returns An object containing the collapsed $from and $to resolved positions
|
|
249
227
|
*/
|
|
250
228
|
export var collapseToSelectionRange = function collapseToSelectionRange($from, $to) {
|
|
251
|
-
var
|
|
252
|
-
|
|
229
|
+
var _$to$nodeBefore$nodeS, _$to$nodeBefore;
|
|
253
230
|
// Get the selections that would be made for the first and last node in the range
|
|
254
231
|
// We re-use the getSelection logic as it already handles various node types and edge cases
|
|
255
|
-
|
|
256
|
-
var
|
|
257
|
-
var
|
|
258
|
-
var
|
|
232
|
+
// always pass true for selectionEmpty to emulate a cursor selection within the node
|
|
233
|
+
var firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
|
|
234
|
+
var lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
|
|
235
|
+
var lastNodeStartPos = $to.pos - lastNodeSize;
|
|
236
|
+
var lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
|
|
259
237
|
|
|
260
238
|
// Return a selection spanning from the start of the first node selection to the end of the last node selection
|
|
261
239
|
return {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { getBlockControlsMeta, key } from '../main';
|
|
5
|
+
import { collapseToSelectionRange } from './getSelection';
|
|
3
6
|
export var getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
|
|
4
7
|
var _api$blockControls, _pluginState$multiSel, _tr$getMeta;
|
|
5
8
|
var pluginState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
|
|
@@ -20,7 +23,12 @@ export var getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(
|
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/**
|
|
26
|
+
* Given a handle position, returns the from and to positions of the selected content.
|
|
27
|
+
* If the handle position is not in a multi-selection, it returns the node's from and to positions.
|
|
23
28
|
*
|
|
29
|
+
* @param handlePos The position of the handle
|
|
30
|
+
* @param tr The transaction to use for position calculations
|
|
31
|
+
* @param api The BlockControlsPlugin API for accessing shared state
|
|
24
32
|
* @returns from and to positions of the selected content (after expansion)
|
|
25
33
|
*/
|
|
26
34
|
export var getSelectedSlicePosition = function getSelectedSlicePosition(handlePos, tr, api) {
|
|
@@ -66,4 +74,52 @@ export var expandSelectionHeadToNodeAtPos = function expandSelectionHeadToNodeAt
|
|
|
66
74
|
*/
|
|
67
75
|
export var alignAnchorHeadInDirectionOfPos = function alignAnchorHeadInDirectionOfPos(selection, pos) {
|
|
68
76
|
return selection instanceof NodeSelection && Math.max(pos, selection.anchor) === selection.anchor ? new TextSelection(selection.$head, selection.$anchor) : selection;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* This maps a preserved selection through a transaction, expanding text selections to block boundaries.
|
|
81
|
+
*
|
|
82
|
+
* @param selection The existing preserved selection to map
|
|
83
|
+
* @param tr The transaction to map through
|
|
84
|
+
* @returns The mapped selection or undefined if mapping is not possible
|
|
85
|
+
*/
|
|
86
|
+
export var mapPreservedSelection = function mapPreservedSelection(selection, tr) {
|
|
87
|
+
var _ref = getBlockControlsMeta(tr) || {},
|
|
88
|
+
nodeMoved = _ref.nodeMoved,
|
|
89
|
+
nodeMovedOffset = _ref.nodeMovedOffset;
|
|
90
|
+
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
91
|
+
if (selection instanceof TextSelection) {
|
|
92
|
+
var from = mapping.map(selection.from);
|
|
93
|
+
var to = mapping.map(selection.to);
|
|
94
|
+
var isSelectionEmpty = from === to;
|
|
95
|
+
var wasSelectionEmpty = selection.from === selection.to;
|
|
96
|
+
if (isSelectionEmpty) {
|
|
97
|
+
if (!wasSelectionEmpty) {
|
|
98
|
+
// If selection has become empty i.e. content has been deleted, stop preserving
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
// When preserving a cursor selection, just map the position without expanding
|
|
102
|
+
return new TextSelection(tr.doc.resolve(from));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// expand the text selection range to block boundaries, so as document changes occur the
|
|
106
|
+
// selection always includes whole nodes
|
|
107
|
+
var expanded = expandToBlockRange(tr.doc.resolve(from), tr.doc.resolve(to));
|
|
108
|
+
|
|
109
|
+
// collapse the expanded range to a valid selection range
|
|
110
|
+
var _collapseToSelectionR = collapseToSelectionRange(expanded.$from, expanded.$to),
|
|
111
|
+
$from = _collapseToSelectionR.$from,
|
|
112
|
+
$to = _collapseToSelectionR.$to;
|
|
113
|
+
|
|
114
|
+
// stop preserving if preserved selection becomes invalid
|
|
115
|
+
if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return new TextSelection($from, $to);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
return selection.map(tr.doc, mapping);
|
|
122
|
+
} catch (_unused) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
69
125
|
};
|
|
@@ -407,13 +407,14 @@ export var DragHandle = function DragHandle(_ref2) {
|
|
|
407
407
|
var handleOnClickNew = useCallback(function (e) {
|
|
408
408
|
var _api$core;
|
|
409
409
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
410
|
-
var _api$analytics, _resolvedStartPos$nod,
|
|
410
|
+
var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
|
|
411
411
|
var tr = _ref3.tr;
|
|
412
412
|
var startPos = getPos();
|
|
413
413
|
if (startPos === undefined) {
|
|
414
414
|
return tr;
|
|
415
415
|
}
|
|
416
416
|
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
417
|
+
var selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
417
418
|
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
418
419
|
eventType: EVENT_TYPE.UI,
|
|
419
420
|
action: ACTION.CLICKED,
|
|
@@ -424,7 +425,6 @@ export var DragHandle = function DragHandle(_ref2) {
|
|
|
424
425
|
nodeType: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
425
426
|
}
|
|
426
427
|
})(tr);
|
|
427
|
-
var selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
|
|
428
428
|
var range = getExpandedSelectionRange({
|
|
429
429
|
doc: tr.doc,
|
|
430
430
|
selection: selection,
|
|
@@ -2,7 +2,7 @@ import { type IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
5
|
-
import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, PluginState } from '../blockControlsPluginType';
|
|
@@ -61,4 +61,4 @@ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin
|
|
|
61
61
|
lastDragCancelled: any;
|
|
62
62
|
isSelectedViaDragHandle: any;
|
|
63
63
|
}>;
|
|
64
|
-
export declare const getBlockControlsMeta: (tr: ReadonlyTransaction) => BlockControlsMeta | undefined;
|
|
64
|
+
export declare const getBlockControlsMeta: (tr: Transaction | ReadonlyTransaction) => BlockControlsMeta | undefined;
|
|
@@ -20,18 +20,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
|
|
|
20
20
|
export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
|
|
21
21
|
export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
|
|
22
22
|
export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* This expands the given $from and $to resolved positions to the block boundaries
|
|
25
|
-
* spanning all nodes in the range up to the nearest common ancestor.
|
|
26
|
-
*
|
|
27
|
-
* @param $from The resolved start position
|
|
28
|
-
* @param $to The resolved end position
|
|
29
|
-
* @returns An object containing the expanded $from and $to resolved positions
|
|
30
|
-
*/
|
|
31
|
-
export declare const expandToBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => {
|
|
32
|
-
$from: ResolvedPos;
|
|
33
|
-
$to: ResolvedPos;
|
|
34
|
-
};
|
|
35
23
|
/**
|
|
36
24
|
* Collapses the given $from and $to resolved positions to the nearest valid selection range.
|
|
37
25
|
*
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ReadonlyTransaction, type Selection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { BlockControlsPlugin } from '../../blockControlsPluginType';
|
|
4
4
|
export declare const getMultiSelectionIfPosInside: (api: ExtractInjectionAPI<BlockControlsPlugin>, pos: number, tr?: Transaction) => {
|
|
5
5
|
anchor?: number;
|
|
6
6
|
head?: number;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
+
* Given a handle position, returns the from and to positions of the selected content.
|
|
10
|
+
* If the handle position is not in a multi-selection, it returns the node's from and to positions.
|
|
9
11
|
*
|
|
12
|
+
* @param handlePos The position of the handle
|
|
13
|
+
* @param tr The transaction to use for position calculations
|
|
14
|
+
* @param api The BlockControlsPlugin API for accessing shared state
|
|
10
15
|
* @returns from and to positions of the selected content (after expansion)
|
|
11
16
|
*/
|
|
12
17
|
export declare const getSelectedSlicePosition: (handlePos: number, tr: Transaction, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
@@ -25,3 +30,11 @@ export declare const expandSelectionHeadToNodeAtPos: (selection: Selection, node
|
|
|
25
30
|
* which may not align with the existing selection.
|
|
26
31
|
*/
|
|
27
32
|
export declare const alignAnchorHeadInDirectionOfPos: (selection: Selection, pos: number) => Selection;
|
|
33
|
+
/**
|
|
34
|
+
* This maps a preserved selection through a transaction, expanding text selections to block boundaries.
|
|
35
|
+
*
|
|
36
|
+
* @param selection The existing preserved selection to map
|
|
37
|
+
* @param tr The transaction to map through
|
|
38
|
+
* @returns The mapped selection or undefined if mapping is not possible
|
|
39
|
+
*/
|
|
40
|
+
export declare const mapPreservedSelection: (selection: Selection, tr: ReadonlyTransaction | Transaction) => Selection | undefined;
|
|
@@ -2,7 +2,7 @@ import { type IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
5
|
-
import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, PluginState } from '../blockControlsPluginType';
|
|
@@ -61,4 +61,4 @@ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin
|
|
|
61
61
|
lastDragCancelled: any;
|
|
62
62
|
isSelectedViaDragHandle: any;
|
|
63
63
|
}>;
|
|
64
|
-
export declare const getBlockControlsMeta: (tr: ReadonlyTransaction) => BlockControlsMeta | undefined;
|
|
64
|
+
export declare const getBlockControlsMeta: (tr: Transaction | ReadonlyTransaction) => BlockControlsMeta | undefined;
|
|
@@ -20,18 +20,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
|
|
|
20
20
|
export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
|
|
21
21
|
export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
|
|
22
22
|
export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* This expands the given $from and $to resolved positions to the block boundaries
|
|
25
|
-
* spanning all nodes in the range up to the nearest common ancestor.
|
|
26
|
-
*
|
|
27
|
-
* @param $from The resolved start position
|
|
28
|
-
* @param $to The resolved end position
|
|
29
|
-
* @returns An object containing the expanded $from and $to resolved positions
|
|
30
|
-
*/
|
|
31
|
-
export declare const expandToBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => {
|
|
32
|
-
$from: ResolvedPos;
|
|
33
|
-
$to: ResolvedPos;
|
|
34
|
-
};
|
|
35
23
|
/**
|
|
36
24
|
* Collapses the given $from and $to resolved positions to the nearest valid selection range.
|
|
37
25
|
*
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ReadonlyTransaction, type Selection, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { BlockControlsPlugin } from '../../blockControlsPluginType';
|
|
4
4
|
export declare const getMultiSelectionIfPosInside: (api: ExtractInjectionAPI<BlockControlsPlugin>, pos: number, tr?: Transaction) => {
|
|
5
5
|
anchor?: number;
|
|
6
6
|
head?: number;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
+
* Given a handle position, returns the from and to positions of the selected content.
|
|
10
|
+
* If the handle position is not in a multi-selection, it returns the node's from and to positions.
|
|
9
11
|
*
|
|
12
|
+
* @param handlePos The position of the handle
|
|
13
|
+
* @param tr The transaction to use for position calculations
|
|
14
|
+
* @param api The BlockControlsPlugin API for accessing shared state
|
|
10
15
|
* @returns from and to positions of the selected content (after expansion)
|
|
11
16
|
*/
|
|
12
17
|
export declare const getSelectedSlicePosition: (handlePos: number, tr: Transaction, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
@@ -25,3 +30,11 @@ export declare const expandSelectionHeadToNodeAtPos: (selection: Selection, node
|
|
|
25
30
|
* which may not align with the existing selection.
|
|
26
31
|
*/
|
|
27
32
|
export declare const alignAnchorHeadInDirectionOfPos: (selection: Selection, pos: number) => Selection;
|
|
33
|
+
/**
|
|
34
|
+
* This maps a preserved selection through a transaction, expanding text selections to block boundaries.
|
|
35
|
+
*
|
|
36
|
+
* @param selection The existing preserved selection to map
|
|
37
|
+
* @param tr The transaction to map through
|
|
38
|
+
* @returns The mapped selection or undefined if mapping is not possible
|
|
39
|
+
*/
|
|
40
|
+
export declare const mapPreservedSelection: (selection: Selection, tr: ReadonlyTransaction | Transaction) => Selection | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "7.11.
|
|
3
|
+
"version": "7.11.4",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/adf-schema": "^51.
|
|
31
|
+
"@atlaskit/adf-schema": "^51.5.1",
|
|
32
32
|
"@atlaskit/browser-apis": "^0.0.1",
|
|
33
33
|
"@atlaskit/editor-plugin-accessibility-utils": "^6.0.0",
|
|
34
34
|
"@atlaskit/editor-plugin-analytics": "^6.2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@atlaskit/editor-plugin-interaction": "^10.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-limited-mode": "^3.1.0",
|
|
39
39
|
"@atlaskit/editor-plugin-metrics": "^7.1.0",
|
|
40
|
-
"@atlaskit/editor-plugin-quick-insert": "^6.
|
|
40
|
+
"@atlaskit/editor-plugin-quick-insert": "^6.1.0",
|
|
41
41
|
"@atlaskit/editor-plugin-selection": "^6.1.0",
|
|
42
42
|
"@atlaskit/editor-plugin-toolbar": "^3.4.0",
|
|
43
43
|
"@atlaskit/editor-plugin-type-ahead": "^6.5.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
|
|
55
55
|
"@atlaskit/primitives": "^16.4.0",
|
|
56
56
|
"@atlaskit/theme": "^21.0.0",
|
|
57
|
-
"@atlaskit/tmp-editor-statsig": "^14.
|
|
57
|
+
"@atlaskit/tmp-editor-statsig": "^14.6.0",
|
|
58
58
|
"@atlaskit/tokens": "^8.4.0",
|
|
59
59
|
"@atlaskit/tooltip": "^20.10.0",
|
|
60
60
|
"@babel/runtime": "^7.0.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"uuid": "^3.1.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@atlaskit/editor-common": "^110.
|
|
69
|
+
"@atlaskit/editor-common": "^110.38.0",
|
|
70
70
|
"react": "^18.2.0",
|
|
71
71
|
"react-dom": "^18.2.0",
|
|
72
72
|
"react-intl-next": "npm:react-intl@^5.18.1"
|