@atlaskit/editor-plugin-block-controls 7.12.0 → 7.12.1
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 +7 -0
- package/dist/cjs/editor-commands/move-node.js +7 -3
- package/dist/cjs/pm-plugins/utils/selection.js +2 -4
- package/dist/es2019/editor-commands/move-node.js +8 -3
- package/dist/es2019/pm-plugins/utils/selection.js +2 -4
- package/dist/esm/editor-commands/move-node.js +7 -3
- package/dist/esm/pm-plugins/utils/selection.js +2 -4
- package/dist/types/blockControlsPluginType.d.ts +2 -1
- package/dist/types-ts4.5/blockControlsPluginType.d.ts +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 7.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`79cafe9f09a05`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/79cafe9f09a05) -
|
|
8
|
+
EDITOR-3756 More general approach to support custom preserved selection mapping
|
|
9
|
+
|
|
3
10
|
## 7.12.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -15,6 +15,7 @@ var _types = require("@atlaskit/editor-common/types");
|
|
|
15
15
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
16
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
17
17
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
18
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
18
19
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
19
20
|
var _utils3 = require("@atlaskit/editor-tables/utils");
|
|
20
21
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -426,7 +427,11 @@ var moveNode = exports.moveNode = function moveNode(api) {
|
|
|
426
427
|
if (inputMethod === _analytics.INPUT_METHOD.DRAG_AND_DROP) {
|
|
427
428
|
tr = (0, _getSelection.setCursorPositionAtMovedNode)(tr, mappedTo, api);
|
|
428
429
|
} else if (preservedSelection) {
|
|
429
|
-
|
|
430
|
+
var _currMeta = tr.getMeta(_main.key);
|
|
431
|
+
var nodeMovedOffset = mappedTo - sliceFrom;
|
|
432
|
+
tr.setMeta(_main.key, _objectSpread(_objectSpread({}, _currMeta), {}, {
|
|
433
|
+
preservedSelectionMapping: new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])])
|
|
434
|
+
}));
|
|
430
435
|
} else if (isMultiSelect) {
|
|
431
436
|
var _api$blockControls$co;
|
|
432
437
|
tr = (_api$blockControls$co = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
|
|
@@ -437,8 +442,7 @@ var moveNode = exports.moveNode = function moveNode(api) {
|
|
|
437
442
|
}
|
|
438
443
|
var currMeta = tr.getMeta(_main.key);
|
|
439
444
|
tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
440
|
-
nodeMoved: true
|
|
441
|
-
nodeMovedOffset: mappedTo - sliceFrom
|
|
445
|
+
nodeMoved: true
|
|
442
446
|
}));
|
|
443
447
|
api === null || api === void 0 || api.core.actions.focus();
|
|
444
448
|
var $mappedTo = tr.doc.resolve(mappedTo);
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.mapPreservedSelection = exports.getSelectedSlicePosition = exports.getMultiSelectionIfPosInside = exports.expandSelectionHeadToNodeAtPos = exports.alignAnchorHeadInDirectionOfPos = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
-
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
10
9
|
var _main = require("../main");
|
|
11
10
|
var _getSelection = require("./getSelection");
|
|
12
11
|
var getMultiSelectionIfPosInside = exports.getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
|
|
@@ -91,9 +90,8 @@ var alignAnchorHeadInDirectionOfPos = exports.alignAnchorHeadInDirectionOfPos =
|
|
|
91
90
|
*/
|
|
92
91
|
var mapPreservedSelection = exports.mapPreservedSelection = function mapPreservedSelection(selection, tr) {
|
|
93
92
|
var _ref = (0, _main.getBlockControlsMeta)(tr) || {},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
93
|
+
preservedSelectionMapping = _ref.preservedSelectionMapping;
|
|
94
|
+
var mapping = preservedSelectionMapping || tr.mapping;
|
|
97
95
|
if (selection instanceof _state.TextSelection) {
|
|
98
96
|
var from = mapping.map(selection.from);
|
|
99
97
|
var to = mapping.map(selection.to);
|
|
@@ -7,6 +7,7 @@ import { DIRECTION } from '@atlaskit/editor-common/types';
|
|
|
7
7
|
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
8
8
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
9
9
|
import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
10
|
+
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
10
11
|
import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
|
|
11
12
|
import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
12
13
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -426,7 +427,12 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
|
|
|
426
427
|
if (inputMethod === INPUT_METHOD.DRAG_AND_DROP) {
|
|
427
428
|
tr = setCursorPositionAtMovedNode(tr, mappedTo, api);
|
|
428
429
|
} else if (preservedSelection) {
|
|
429
|
-
|
|
430
|
+
const currMeta = tr.getMeta(key);
|
|
431
|
+
const nodeMovedOffset = mappedTo - sliceFrom;
|
|
432
|
+
tr.setMeta(key, {
|
|
433
|
+
...currMeta,
|
|
434
|
+
preservedSelectionMapping: new Mapping([new StepMap([0, 0, nodeMovedOffset])])
|
|
435
|
+
});
|
|
430
436
|
} else if (isMultiSelect) {
|
|
431
437
|
var _api$blockControls$co2;
|
|
432
438
|
tr = (_api$blockControls$co2 = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
|
|
@@ -438,8 +444,7 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
|
|
|
438
444
|
const currMeta = tr.getMeta(key);
|
|
439
445
|
tr.setMeta(key, {
|
|
440
446
|
...currMeta,
|
|
441
|
-
nodeMoved: true
|
|
442
|
-
nodeMovedOffset: mappedTo - sliceFrom
|
|
447
|
+
nodeMoved: true
|
|
443
448
|
});
|
|
444
449
|
api === null || api === void 0 ? void 0 : api.core.actions.focus();
|
|
445
450
|
const $mappedTo = tr.doc.resolve(mappedTo);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
4
3
|
import { getBlockControlsMeta, key } from '../main';
|
|
5
4
|
import { collapseToSelectionRange } from './getSelection';
|
|
6
5
|
export const getMultiSelectionIfPosInside = (api, pos, tr) => {
|
|
@@ -86,10 +85,9 @@ export const alignAnchorHeadInDirectionOfPos = (selection, pos) => {
|
|
|
86
85
|
*/
|
|
87
86
|
export const mapPreservedSelection = (selection, tr) => {
|
|
88
87
|
const {
|
|
89
|
-
|
|
90
|
-
nodeMovedOffset
|
|
88
|
+
preservedSelectionMapping
|
|
91
89
|
} = getBlockControlsMeta(tr) || {};
|
|
92
|
-
const mapping =
|
|
90
|
+
const mapping = preservedSelectionMapping || tr.mapping;
|
|
93
91
|
if (selection instanceof TextSelection) {
|
|
94
92
|
const from = mapping.map(selection.from);
|
|
95
93
|
const to = mapping.map(selection.to);
|
|
@@ -10,6 +10,7 @@ import { DIRECTION } from '@atlaskit/editor-common/types';
|
|
|
10
10
|
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
11
11
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
12
12
|
import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
13
|
+
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
13
14
|
import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
|
|
14
15
|
import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
15
16
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -420,7 +421,11 @@ export var moveNode = function moveNode(api) {
|
|
|
420
421
|
if (inputMethod === INPUT_METHOD.DRAG_AND_DROP) {
|
|
421
422
|
tr = setCursorPositionAtMovedNode(tr, mappedTo, api);
|
|
422
423
|
} else if (preservedSelection) {
|
|
423
|
-
|
|
424
|
+
var _currMeta = tr.getMeta(key);
|
|
425
|
+
var nodeMovedOffset = mappedTo - sliceFrom;
|
|
426
|
+
tr.setMeta(key, _objectSpread(_objectSpread({}, _currMeta), {}, {
|
|
427
|
+
preservedSelectionMapping: new Mapping([new StepMap([0, 0, nodeMovedOffset])])
|
|
428
|
+
}));
|
|
424
429
|
} else if (isMultiSelect) {
|
|
425
430
|
var _api$blockControls$co;
|
|
426
431
|
tr = (_api$blockControls$co = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
|
|
@@ -431,8 +436,7 @@ export var moveNode = function moveNode(api) {
|
|
|
431
436
|
}
|
|
432
437
|
var currMeta = tr.getMeta(key);
|
|
433
438
|
tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
434
|
-
nodeMoved: true
|
|
435
|
-
nodeMovedOffset: mappedTo - sliceFrom
|
|
439
|
+
nodeMoved: true
|
|
436
440
|
}));
|
|
437
441
|
api === null || api === void 0 || api.core.actions.focus();
|
|
438
442
|
var $mappedTo = tr.doc.resolve(mappedTo);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
|
4
3
|
import { getBlockControlsMeta, key } from '../main';
|
|
5
4
|
import { collapseToSelectionRange } from './getSelection';
|
|
6
5
|
export var getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
|
|
@@ -85,9 +84,8 @@ export var alignAnchorHeadInDirectionOfPos = function alignAnchorHeadInDirection
|
|
|
85
84
|
*/
|
|
86
85
|
export var mapPreservedSelection = function mapPreservedSelection(selection, tr) {
|
|
87
86
|
var _ref = getBlockControlsMeta(tr) || {},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
|
|
87
|
+
preservedSelectionMapping = _ref.preservedSelectionMapping;
|
|
88
|
+
var mapping = preservedSelectionMapping || tr.mapping;
|
|
91
89
|
if (selection instanceof TextSelection) {
|
|
92
90
|
var from = mapping.map(selection.from);
|
|
93
91
|
var to = mapping.map(selection.to);
|
|
@@ -15,6 +15,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
|
15
15
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
16
16
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
17
17
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
18
|
+
import { type Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
18
19
|
import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
19
20
|
export type ActiveNode = {
|
|
20
21
|
anchorName: string;
|
|
@@ -162,7 +163,7 @@ export type BlockControlsMeta = {
|
|
|
162
163
|
editorBlurred: boolean;
|
|
163
164
|
editorHeight: number;
|
|
164
165
|
nodeMoved: boolean;
|
|
165
|
-
|
|
166
|
+
preservedSelectionMapping: Mapping;
|
|
166
167
|
type: string;
|
|
167
168
|
};
|
|
168
169
|
export type MoveNodeMethod = INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT | INPUT_METHOD.BLOCK_MENU;
|
|
@@ -15,6 +15,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
|
15
15
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
16
16
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
17
17
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
18
|
+
import { type Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
18
19
|
import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
19
20
|
export type ActiveNode = {
|
|
20
21
|
anchorName: string;
|
|
@@ -162,7 +163,7 @@ export type BlockControlsMeta = {
|
|
|
162
163
|
editorBlurred: boolean;
|
|
163
164
|
editorHeight: number;
|
|
164
165
|
nodeMoved: boolean;
|
|
165
|
-
|
|
166
|
+
preservedSelectionMapping: Mapping;
|
|
166
167
|
type: string;
|
|
167
168
|
};
|
|
168
169
|
export type MoveNodeMethod = INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT | INPUT_METHOD.BLOCK_MENU;
|