@atlaskit/editor-plugin-block-controls 8.0.8 → 8.0.9
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/blockControlsPlugin.js +4 -0
- package/dist/cjs/editor-commands/map-preserved-selection.js +30 -0
- package/dist/cjs/pm-plugins/selection-preservation/pm-plugin.js +7 -1
- package/dist/cjs/pm-plugins/selection-preservation/utils.js +2 -17
- package/dist/es2019/blockControlsPlugin.js +2 -0
- package/dist/es2019/editor-commands/map-preserved-selection.js +21 -0
- package/dist/es2019/pm-plugins/selection-preservation/pm-plugin.js +8 -2
- package/dist/es2019/pm-plugins/selection-preservation/utils.js +1 -16
- package/dist/esm/blockControlsPlugin.js +4 -0
- package/dist/esm/editor-commands/map-preserved-selection.js +24 -0
- package/dist/esm/pm-plugins/selection-preservation/pm-plugin.js +8 -2
- package/dist/esm/pm-plugins/selection-preservation/utils.js +1 -16
- package/dist/types/blockControlsPluginType.d.ts +1 -0
- package/dist/types/editor-commands/map-preserved-selection.d.ts +13 -0
- package/dist/types/pm-plugins/selection-preservation/utils.d.ts +1 -10
- package/dist/types-ts4.5/blockControlsPluginType.d.ts +1 -0
- package/dist/types-ts4.5/editor-commands/map-preserved-selection.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/selection-preservation/utils.d.ts +1 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 8.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2a1bf10d70beb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a1bf10d70beb) -
|
|
8
|
+
EDITOR-4293 Fix block menu selection highlight issues
|
|
9
|
+
|
|
3
10
|
## 8.0.8
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -14,6 +14,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
14
14
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
15
15
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
16
16
|
var _handleKeyDownWithPreservedSelection = require("./editor-commands/handle-key-down-with-preserved-selection");
|
|
17
|
+
var _mapPreservedSelection2 = require("./editor-commands/map-preserved-selection");
|
|
17
18
|
var _moveNode = require("./editor-commands/move-node");
|
|
18
19
|
var _moveNodeWithBlockMenu2 = require("./editor-commands/move-node-with-block-menu");
|
|
19
20
|
var _moveToLayout = require("./editor-commands/move-to-layout");
|
|
@@ -244,6 +245,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
244
245
|
}));
|
|
245
246
|
};
|
|
246
247
|
},
|
|
248
|
+
mapPreservedSelection: function mapPreservedSelection(mapping) {
|
|
249
|
+
return (0, _mapPreservedSelection2.mapPreservedSelection)(mapping);
|
|
250
|
+
},
|
|
247
251
|
moveNodeWithBlockMenu: function moveNodeWithBlockMenu(direction) {
|
|
248
252
|
return (0, _moveNodeWithBlockMenu2.moveNodeWithBlockMenu)(api, direction);
|
|
249
253
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.mapPreservedSelection = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _main = require("../pm-plugins/main");
|
|
10
|
+
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; }
|
|
11
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
12
|
+
/**
|
|
13
|
+
* Applies metadata to the transaction which can be used to apply custom mapping
|
|
14
|
+
* to the preserved selection.
|
|
15
|
+
*
|
|
16
|
+
* This can be used when nodes are transformed/moved in a way that natural mapping
|
|
17
|
+
* would not correctly update the preserved selection.
|
|
18
|
+
*
|
|
19
|
+
* @param preservedSelectionMapping The mapping to apply to the preserved selection.
|
|
20
|
+
* @returns An editor command that sets the preserved selection mapping in the transaction metadata.
|
|
21
|
+
*/
|
|
22
|
+
var mapPreservedSelection = exports.mapPreservedSelection = function mapPreservedSelection(mapping) {
|
|
23
|
+
return function (_ref) {
|
|
24
|
+
var tr = _ref.tr;
|
|
25
|
+
var currMeta = tr.getMeta(_main.key);
|
|
26
|
+
return tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
27
|
+
preservedSelectionMapping: mapping
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -8,6 +8,7 @@ exports.createSelectionPreservationPlugin = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
11
|
+
var _main = require("../main");
|
|
11
12
|
var _selection = require("../utils/selection");
|
|
12
13
|
var _editorCommands = require("./editor-commands");
|
|
13
14
|
var _pluginKey = require("./plugin-key");
|
|
@@ -108,7 +109,12 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
|
|
|
108
109
|
view: function view() {
|
|
109
110
|
return {
|
|
110
111
|
update: function update(view, prevState) {
|
|
111
|
-
|
|
112
|
+
var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
|
|
113
|
+
var prevPreservedSelection = (_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
114
|
+
var currPreservedSelection = (_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
115
|
+
var prevActiveNode = (_key$getState = _main.key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
|
|
116
|
+
var currActiveNode = (_key$getState2 = _main.key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
|
|
117
|
+
if (currPreservedSelection && view.hasFocus() && (!(0, _utils.compareSelections)(prevPreservedSelection, currPreservedSelection) || prevActiveNode !== currActiveNode)) {
|
|
112
118
|
(0, _utils.syncDOMSelection)(view.state.selection);
|
|
113
119
|
}
|
|
114
120
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.syncDOMSelection = exports.isSelectionWithinCodeBlock = exports.
|
|
6
|
+
exports.syncDOMSelection = exports.isSelectionWithinCodeBlock = exports.hasUserSelectionChange = exports.getSelectionPreservationMeta = exports.compareSelections = void 0;
|
|
7
7
|
var _pluginKey = require("./plugin-key");
|
|
8
8
|
/**
|
|
9
9
|
* Detects if any of the transactions include user-driven selection changes.
|
|
@@ -40,22 +40,7 @@ var isSelectionWithinCodeBlock = exports.isSelectionWithinCodeBlock = function i
|
|
|
40
40
|
* @returns True if both selections are equal, otherwise false.
|
|
41
41
|
*/
|
|
42
42
|
var compareSelections = exports.compareSelections = function compareSelections(a, b) {
|
|
43
|
-
return
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Returns true/false indicating whether the preserved selection
|
|
48
|
-
* has changed between the old and new editor states.
|
|
49
|
-
*
|
|
50
|
-
* @param newState The new editor state.
|
|
51
|
-
* @param oldState The old editor state.
|
|
52
|
-
* @returns True if the preserved selection has changed, otherwise false.
|
|
53
|
-
*/
|
|
54
|
-
var isPreservedSelectionChanged = exports.isPreservedSelectionChanged = function isPreservedSelectionChanged(newState, oldState) {
|
|
55
|
-
var _selectionPreservatio, _selectionPreservatio2;
|
|
56
|
-
var prev = (_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(oldState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
57
|
-
var curr = (_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(newState)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
58
|
-
return !!prev && !!curr && !compareSelections(prev, curr);
|
|
43
|
+
return !a && !b || !!a && !!b && a.eq(b);
|
|
59
44
|
};
|
|
60
45
|
|
|
61
46
|
/**
|
|
@@ -6,6 +6,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
6
6
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
7
7
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
8
|
import { handleKeyDownWithPreservedSelection } from './editor-commands/handle-key-down-with-preserved-selection';
|
|
9
|
+
import { mapPreservedSelection } from './editor-commands/map-preserved-selection';
|
|
9
10
|
import { moveNode } from './editor-commands/move-node';
|
|
10
11
|
import { moveNodeWithBlockMenu } from './editor-commands/move-node-with-block-menu';
|
|
11
12
|
import { moveToLayout } from './editor-commands/move-to-layout';
|
|
@@ -238,6 +239,7 @@ export const blockControlsPlugin = ({
|
|
|
238
239
|
isSelectedViaDragHandle
|
|
239
240
|
});
|
|
240
241
|
},
|
|
242
|
+
mapPreservedSelection: mapping => mapPreservedSelection(mapping),
|
|
241
243
|
moveNodeWithBlockMenu: direction => moveNodeWithBlockMenu(api, direction),
|
|
242
244
|
handleKeyDownWithPreservedSelection: handleKeyDownWithPreservedSelection(api),
|
|
243
245
|
startPreservingSelection: () => startPreservingSelection,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { key } from '../pm-plugins/main';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies metadata to the transaction which can be used to apply custom mapping
|
|
5
|
+
* to the preserved selection.
|
|
6
|
+
*
|
|
7
|
+
* This can be used when nodes are transformed/moved in a way that natural mapping
|
|
8
|
+
* would not correctly update the preserved selection.
|
|
9
|
+
*
|
|
10
|
+
* @param preservedSelectionMapping The mapping to apply to the preserved selection.
|
|
11
|
+
* @returns An editor command that sets the preserved selection mapping in the transaction metadata.
|
|
12
|
+
*/
|
|
13
|
+
export const mapPreservedSelection = mapping => ({
|
|
14
|
+
tr
|
|
15
|
+
}) => {
|
|
16
|
+
const currMeta = tr.getMeta(key);
|
|
17
|
+
return tr.setMeta(key, {
|
|
18
|
+
...currMeta,
|
|
19
|
+
preservedSelectionMapping: mapping
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { DRAG_HANDLE_SELECTOR } from '@atlaskit/editor-common/styles';
|
|
3
|
+
import { key } from '../main';
|
|
3
4
|
import { createPreservedSelection, mapPreservedSelection } from '../utils/selection';
|
|
4
5
|
import { stopPreservingSelection } from './editor-commands';
|
|
5
6
|
import { selectionPreservationPluginKey } from './plugin-key';
|
|
6
|
-
import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange,
|
|
7
|
+
import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange, isSelectionWithinCodeBlock, syncDOMSelection } from './utils';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Selection Preservation Plugin
|
|
@@ -100,7 +101,12 @@ export const createSelectionPreservationPlugin = api => () => {
|
|
|
100
101
|
view() {
|
|
101
102
|
return {
|
|
102
103
|
update(view, prevState) {
|
|
103
|
-
|
|
104
|
+
var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
|
|
105
|
+
const prevPreservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
106
|
+
const currPreservedSelection = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
107
|
+
const prevActiveNode = (_key$getState = key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
|
|
108
|
+
const currActiveNode = (_key$getState2 = key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
|
|
109
|
+
if (currPreservedSelection && view.hasFocus() && (!compareSelections(prevPreservedSelection, currPreservedSelection) || prevActiveNode !== currActiveNode)) {
|
|
104
110
|
syncDOMSelection(view.state.selection);
|
|
105
111
|
}
|
|
106
112
|
}
|
|
@@ -33,22 +33,7 @@ export const isSelectionWithinCodeBlock = ({
|
|
|
33
33
|
* @returns True if both selections are equal, otherwise false.
|
|
34
34
|
*/
|
|
35
35
|
export const compareSelections = (a, b) => {
|
|
36
|
-
return
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Returns true/false indicating whether the preserved selection
|
|
41
|
-
* has changed between the old and new editor states.
|
|
42
|
-
*
|
|
43
|
-
* @param newState The new editor state.
|
|
44
|
-
* @param oldState The old editor state.
|
|
45
|
-
* @returns True if the preserved selection has changed, otherwise false.
|
|
46
|
-
*/
|
|
47
|
-
export const isPreservedSelectionChanged = (newState, oldState) => {
|
|
48
|
-
var _selectionPreservatio, _selectionPreservatio2;
|
|
49
|
-
const prev = (_selectionPreservatio = selectionPreservationPluginKey.getState(oldState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
50
|
-
const curr = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(newState)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
51
|
-
return !!prev && !!curr && !compareSelections(prev, curr);
|
|
36
|
+
return !a && !b || !!a && !!b && a.eq(b);
|
|
52
37
|
};
|
|
53
38
|
|
|
54
39
|
/**
|
|
@@ -9,6 +9,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
9
9
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
10
10
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
11
|
import { handleKeyDownWithPreservedSelection } from './editor-commands/handle-key-down-with-preserved-selection';
|
|
12
|
+
import { mapPreservedSelection as _mapPreservedSelection } from './editor-commands/map-preserved-selection';
|
|
12
13
|
import { moveNode } from './editor-commands/move-node';
|
|
13
14
|
import { moveNodeWithBlockMenu as _moveNodeWithBlockMenu } from './editor-commands/move-node-with-block-menu';
|
|
14
15
|
import { moveToLayout } from './editor-commands/move-to-layout';
|
|
@@ -237,6 +238,9 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
237
238
|
}));
|
|
238
239
|
};
|
|
239
240
|
},
|
|
241
|
+
mapPreservedSelection: function mapPreservedSelection(mapping) {
|
|
242
|
+
return _mapPreservedSelection(mapping);
|
|
243
|
+
},
|
|
240
244
|
moveNodeWithBlockMenu: function moveNodeWithBlockMenu(direction) {
|
|
241
245
|
return _moveNodeWithBlockMenu(api, direction);
|
|
242
246
|
},
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
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
|
+
import { key } from '../pm-plugins/main';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Applies metadata to the transaction which can be used to apply custom mapping
|
|
8
|
+
* to the preserved selection.
|
|
9
|
+
*
|
|
10
|
+
* This can be used when nodes are transformed/moved in a way that natural mapping
|
|
11
|
+
* would not correctly update the preserved selection.
|
|
12
|
+
*
|
|
13
|
+
* @param preservedSelectionMapping The mapping to apply to the preserved selection.
|
|
14
|
+
* @returns An editor command that sets the preserved selection mapping in the transaction metadata.
|
|
15
|
+
*/
|
|
16
|
+
export var mapPreservedSelection = function mapPreservedSelection(mapping) {
|
|
17
|
+
return function (_ref) {
|
|
18
|
+
var tr = _ref.tr;
|
|
19
|
+
var currMeta = tr.getMeta(key);
|
|
20
|
+
return tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
|
|
21
|
+
preservedSelectionMapping: mapping
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -3,10 +3,11 @@ 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 { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { DRAG_HANDLE_SELECTOR } from '@atlaskit/editor-common/styles';
|
|
6
|
+
import { key } from '../main';
|
|
6
7
|
import { createPreservedSelection, mapPreservedSelection } from '../utils/selection';
|
|
7
8
|
import { stopPreservingSelection } from './editor-commands';
|
|
8
9
|
import { selectionPreservationPluginKey } from './plugin-key';
|
|
9
|
-
import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange,
|
|
10
|
+
import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange, isSelectionWithinCodeBlock, syncDOMSelection } from './utils';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Selection Preservation Plugin
|
|
@@ -102,7 +103,12 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
|
|
|
102
103
|
view: function view() {
|
|
103
104
|
return {
|
|
104
105
|
update: function update(view, prevState) {
|
|
105
|
-
|
|
106
|
+
var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
|
|
107
|
+
var prevPreservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
108
|
+
var currPreservedSelection = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
109
|
+
var prevActiveNode = (_key$getState = key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
|
|
110
|
+
var currActiveNode = (_key$getState2 = key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
|
|
111
|
+
if (currPreservedSelection && view.hasFocus() && (!compareSelections(prevPreservedSelection, currPreservedSelection) || prevActiveNode !== currActiveNode)) {
|
|
106
112
|
syncDOMSelection(view.state.selection);
|
|
107
113
|
}
|
|
108
114
|
}
|
|
@@ -34,22 +34,7 @@ export var isSelectionWithinCodeBlock = function isSelectionWithinCodeBlock(_ref
|
|
|
34
34
|
* @returns True if both selections are equal, otherwise false.
|
|
35
35
|
*/
|
|
36
36
|
export var compareSelections = function compareSelections(a, b) {
|
|
37
|
-
return
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Returns true/false indicating whether the preserved selection
|
|
42
|
-
* has changed between the old and new editor states.
|
|
43
|
-
*
|
|
44
|
-
* @param newState The new editor state.
|
|
45
|
-
* @param oldState The old editor state.
|
|
46
|
-
* @returns True if the preserved selection has changed, otherwise false.
|
|
47
|
-
*/
|
|
48
|
-
export var isPreservedSelectionChanged = function isPreservedSelectionChanged(newState, oldState) {
|
|
49
|
-
var _selectionPreservatio, _selectionPreservatio2;
|
|
50
|
-
var prev = (_selectionPreservatio = selectionPreservationPluginKey.getState(oldState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
|
|
51
|
-
var curr = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(newState)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
|
|
52
|
-
return !!prev && !!curr && !compareSelections(prev, curr);
|
|
37
|
+
return !a && !b || !!a && !!b && a.eq(b);
|
|
53
38
|
};
|
|
54
39
|
|
|
55
40
|
/**
|
|
@@ -119,6 +119,7 @@ export type BlockControlsPluginDependencies = [
|
|
|
119
119
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
120
120
|
commands: {
|
|
121
121
|
handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
|
|
122
|
+
mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
122
123
|
moveNode: MoveNode;
|
|
123
124
|
moveNodeWithBlockMenu: (direction: DIRECTION.UP | DIRECTION.DOWN) => EditorCommand;
|
|
124
125
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
+
/**
|
|
4
|
+
* Applies metadata to the transaction which can be used to apply custom mapping
|
|
5
|
+
* to the preserved selection.
|
|
6
|
+
*
|
|
7
|
+
* This can be used when nodes are transformed/moved in a way that natural mapping
|
|
8
|
+
* would not correctly update the preserved selection.
|
|
9
|
+
*
|
|
10
|
+
* @param preservedSelectionMapping The mapping to apply to the preserved selection.
|
|
11
|
+
* @returns An editor command that sets the preserved selection mapping in the transaction metadata.
|
|
12
|
+
*/
|
|
13
|
+
export declare const mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadonlyTransaction, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { SelectionPreservationMeta } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Detects if any of the transactions include user-driven selection changes.
|
|
@@ -23,15 +23,6 @@ export declare const isSelectionWithinCodeBlock: ({ $from, $to }: Selection) =>
|
|
|
23
23
|
* @returns True if both selections are equal, otherwise false.
|
|
24
24
|
*/
|
|
25
25
|
export declare const compareSelections: (a?: Selection, b?: Selection) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Returns true/false indicating whether the preserved selection
|
|
28
|
-
* has changed between the old and new editor states.
|
|
29
|
-
*
|
|
30
|
-
* @param newState The new editor state.
|
|
31
|
-
* @param oldState The old editor state.
|
|
32
|
-
* @returns True if the preserved selection has changed, otherwise false.
|
|
33
|
-
*/
|
|
34
|
-
export declare const isPreservedSelectionChanged: (newState: EditorState, oldState: EditorState) => boolean;
|
|
35
26
|
/**
|
|
36
27
|
* Triggers a DOM selection sync by resetting the current native selection range
|
|
37
28
|
* only if it is out of sync with the provided ProseMirror selection state.
|
|
@@ -119,6 +119,7 @@ export type BlockControlsPluginDependencies = [
|
|
|
119
119
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
120
120
|
commands: {
|
|
121
121
|
handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
|
|
122
|
+
mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
122
123
|
moveNode: MoveNode;
|
|
123
124
|
moveNodeWithBlockMenu: (direction: DIRECTION.UP | DIRECTION.DOWN) => EditorCommand;
|
|
124
125
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
+
/**
|
|
4
|
+
* Applies metadata to the transaction which can be used to apply custom mapping
|
|
5
|
+
* to the preserved selection.
|
|
6
|
+
*
|
|
7
|
+
* This can be used when nodes are transformed/moved in a way that natural mapping
|
|
8
|
+
* would not correctly update the preserved selection.
|
|
9
|
+
*
|
|
10
|
+
* @param preservedSelectionMapping The mapping to apply to the preserved selection.
|
|
11
|
+
* @returns An editor command that sets the preserved selection mapping in the transaction metadata.
|
|
12
|
+
*/
|
|
13
|
+
export declare const mapPreservedSelection: (mapping: Mapping) => EditorCommand;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadonlyTransaction, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { SelectionPreservationMeta } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Detects if any of the transactions include user-driven selection changes.
|
|
@@ -23,15 +23,6 @@ export declare const isSelectionWithinCodeBlock: ({ $from, $to }: Selection) =>
|
|
|
23
23
|
* @returns True if both selections are equal, otherwise false.
|
|
24
24
|
*/
|
|
25
25
|
export declare const compareSelections: (a?: Selection, b?: Selection) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Returns true/false indicating whether the preserved selection
|
|
28
|
-
* has changed between the old and new editor states.
|
|
29
|
-
*
|
|
30
|
-
* @param newState The new editor state.
|
|
31
|
-
* @param oldState The old editor state.
|
|
32
|
-
* @returns True if the preserved selection has changed, otherwise false.
|
|
33
|
-
*/
|
|
34
|
-
export declare const isPreservedSelectionChanged: (newState: EditorState, oldState: EditorState) => boolean;
|
|
35
26
|
/**
|
|
36
27
|
* Triggers a DOM selection sync by resetting the current native selection range
|
|
37
28
|
* only if it is out of sync with the provided ProseMirror selection state.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.9",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
|
|
55
55
|
"@atlaskit/primitives": "^17.0.0",
|
|
56
56
|
"@atlaskit/theme": "^21.0.0",
|
|
57
|
-
"@atlaskit/tmp-editor-statsig": "^16.
|
|
57
|
+
"@atlaskit/tmp-editor-statsig": "^16.15.0",
|
|
58
58
|
"@atlaskit/tokens": "^9.1.0",
|
|
59
|
-
"@atlaskit/tooltip": "^20.
|
|
59
|
+
"@atlaskit/tooltip": "^20.14.0",
|
|
60
60
|
"@babel/runtime": "^7.0.0",
|
|
61
61
|
"@emotion/react": "^11.7.1",
|
|
62
62
|
"@popperjs/core": "^2.11.8",
|