@atlaskit/editor-plugin-block-controls 7.7.1 → 7.7.3
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 +16 -0
- package/dist/cjs/blockControlsPlugin.js +14 -0
- package/dist/cjs/pm-plugins/main.js +10 -4
- package/dist/cjs/pm-plugins/selection-preservation/editor-commands.js +32 -0
- package/dist/cjs/pm-plugins/selection-preservation/plugin-key.js +8 -0
- package/dist/cjs/pm-plugins/selection-preservation/pm-plugin.js +99 -0
- package/dist/cjs/pm-plugins/selection-preservation/types.js +5 -0
- package/dist/cjs/pm-plugins/selection-preservation/utils.js +24 -0
- package/dist/cjs/ui/drag-handle.js +196 -61
- package/dist/es2019/blockControlsPlugin.js +11 -1
- package/dist/es2019/pm-plugins/main.js +10 -4
- package/dist/es2019/pm-plugins/selection-preservation/editor-commands.js +28 -0
- package/dist/es2019/pm-plugins/selection-preservation/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/selection-preservation/pm-plugin.js +92 -0
- package/dist/es2019/pm-plugins/selection-preservation/types.js +1 -0
- package/dist/es2019/pm-plugins/selection-preservation/utils.js +16 -0
- package/dist/es2019/ui/drag-handle.js +170 -31
- package/dist/esm/blockControlsPlugin.js +14 -0
- package/dist/esm/pm-plugins/main.js +10 -4
- package/dist/esm/pm-plugins/selection-preservation/editor-commands.js +26 -0
- package/dist/esm/pm-plugins/selection-preservation/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/selection-preservation/pm-plugin.js +93 -0
- package/dist/esm/pm-plugins/selection-preservation/types.js +1 -0
- package/dist/esm/pm-plugins/selection-preservation/utils.js +18 -0
- package/dist/esm/ui/drag-handle.js +195 -60
- package/dist/types/blockControlsPluginType.d.ts +12 -1
- package/dist/types/pm-plugins/selection-preservation/editor-commands.d.ts +13 -0
- package/dist/types/pm-plugins/selection-preservation/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/selection-preservation/pm-plugin.d.ts +26 -0
- package/dist/types/pm-plugins/selection-preservation/types.d.ts +7 -0
- package/dist/types/pm-plugins/selection-preservation/utils.d.ts +10 -0
- package/dist/types-ts4.5/blockControlsPluginType.d.ts +12 -1
- package/dist/types-ts4.5/pm-plugins/selection-preservation/editor-commands.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/selection-preservation/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/selection-preservation/pm-plugin.d.ts +26 -0
- package/dist/types-ts4.5/pm-plugins/selection-preservation/types.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/selection-preservation/utils.d.ts +10 -0
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 7.7.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`aa5913a5d4962`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aa5913a5d4962) -
|
|
8
|
+
[ux] EDITOR-2679 Fix multiselect collapsing issues for drag handle selections and block menu
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 7.7.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`a05464ea42678`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a05464ea42678) -
|
|
16
|
+
EDITOR-2791 bump adf-schema
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 7.7.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -20,6 +20,8 @@ var _moveNodeUtils = require("./editor-commands/utils/move-node-utils");
|
|
|
20
20
|
var _firstNodeDecPlugin = require("./pm-plugins/first-node-dec-plugin");
|
|
21
21
|
var _pmPlugin = require("./pm-plugins/interaction-tracking/pm-plugin");
|
|
22
22
|
var _main = require("./pm-plugins/main");
|
|
23
|
+
var _editorCommands = require("./pm-plugins/selection-preservation/editor-commands");
|
|
24
|
+
var _pmPlugin2 = require("./pm-plugins/selection-preservation/pm-plugin");
|
|
23
25
|
var _getSelection = require("./pm-plugins/utils/getSelection");
|
|
24
26
|
var _blockMenu = _interopRequireDefault(require("./ui/block-menu"));
|
|
25
27
|
var _dragHandleMenu = require("./ui/drag-handle-menu");
|
|
@@ -45,6 +47,12 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
45
47
|
plugin: _pmPlugin.createInteractionTrackingPlugin
|
|
46
48
|
});
|
|
47
49
|
}
|
|
50
|
+
if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true)) {
|
|
51
|
+
pmPlugins.push({
|
|
52
|
+
name: 'blockControlsSelectionPreservationPlugin',
|
|
53
|
+
plugin: _pmPlugin2.createSelectionPreservationPlugin
|
|
54
|
+
});
|
|
55
|
+
}
|
|
48
56
|
|
|
49
57
|
// platform_editor_controls note: quick insert rendering fixes
|
|
50
58
|
if ((0, _toolbarFlagCheck.areToolbarFlagsEnabled)(Boolean(api === null || api === void 0 ? void 0 : api.toolbar))) {
|
|
@@ -239,6 +247,12 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
239
247
|
},
|
|
240
248
|
moveNodeWithBlockMenu: function moveNodeWithBlockMenu(direction) {
|
|
241
249
|
return (0, _moveNodeWithBlockMenu2.moveNodeWithBlockMenu)(api, direction);
|
|
250
|
+
},
|
|
251
|
+
startPreservingSelection: function startPreservingSelection() {
|
|
252
|
+
return _editorCommands.startPreservingSelection;
|
|
253
|
+
},
|
|
254
|
+
stopPreservingSelection: function stopPreservingSelection() {
|
|
255
|
+
return _editorCommands.stopPreservingSelection;
|
|
242
256
|
}
|
|
243
257
|
},
|
|
244
258
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -771,8 +771,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
771
771
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
|
|
772
772
|
}
|
|
773
773
|
if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
774
|
-
var _api$blockControls$sh2;
|
|
775
|
-
|
|
774
|
+
var _api$blockControls$sh2, _api$blockControls$sh3;
|
|
775
|
+
var isBlockMenuOpen = (api === null || api === void 0 || (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh2 === void 0 ? void 0 : _api$blockControls$sh2.isMenuOpen) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true);
|
|
776
|
+
// when block menu is just open, and we press arrow keys, we want to use the arrow keys to navigate the block menu
|
|
777
|
+
// in this scenario, isSelectedViaDragHandle should not be set to false
|
|
778
|
+
if (api !== null && api !== void 0 && (_api$blockControls$sh3 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh3 !== void 0 && _api$blockControls$sh3.isSelectedViaDragHandle && !isBlockMenuOpen) {
|
|
776
779
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
|
|
777
780
|
}
|
|
778
781
|
}
|
|
@@ -795,8 +798,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
795
798
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(_isDragHandle));
|
|
796
799
|
}
|
|
797
800
|
if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
798
|
-
var _api$blockControls$
|
|
799
|
-
|
|
801
|
+
var _api$blockControls$sh4, _api$blockControls$sh5;
|
|
802
|
+
var _isBlockMenuOpen = (api === null || api === void 0 || (_api$blockControls$sh4 = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh4 === void 0 ? void 0 : _api$blockControls$sh4.isMenuOpen) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true);
|
|
803
|
+
// when block menu is just open, and we press arrow keys, we want to use the arrow keys to navigate the block menu
|
|
804
|
+
// in this scenario, isSelectedViaDragHandle should not be set to false
|
|
805
|
+
if (api !== null && api !== void 0 && (_api$blockControls$sh5 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh5 !== void 0 && _api$blockControls$sh5.isSelectedViaDragHandle && !_isBlockMenuOpen) {
|
|
800
806
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
|
|
801
807
|
}
|
|
802
808
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stopPreservingSelection = exports.startPreservingSelection = void 0;
|
|
7
|
+
var _pluginKey = require("./plugin-key");
|
|
8
|
+
/**
|
|
9
|
+
* Start preserving the selection when a UI interaction requires it
|
|
10
|
+
*
|
|
11
|
+
* e.g., block menu open, drag-and-drop in progress
|
|
12
|
+
*/
|
|
13
|
+
var startPreservingSelection = exports.startPreservingSelection = function startPreservingSelection(_ref) {
|
|
14
|
+
var tr = _ref.tr;
|
|
15
|
+
var meta = {
|
|
16
|
+
type: 'startPreserving'
|
|
17
|
+
};
|
|
18
|
+
return tr.setMeta(_pluginKey.selectionPreservationPluginKey, meta);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stop preserving the selection when a UI interaction completes
|
|
23
|
+
*
|
|
24
|
+
* e.g., block menu closed, drag-and-drop ended
|
|
25
|
+
*/
|
|
26
|
+
var stopPreservingSelection = exports.stopPreservingSelection = function stopPreservingSelection(_ref2) {
|
|
27
|
+
var tr = _ref2.tr;
|
|
28
|
+
var meta = {
|
|
29
|
+
type: 'stopPreserving'
|
|
30
|
+
};
|
|
31
|
+
return tr.setMeta(_pluginKey.selectionPreservationPluginKey, meta);
|
|
32
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.selectionPreservationPluginKey = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var selectionPreservationPluginKey = exports.selectionPreservationPluginKey = new _state.PluginKey('selectionPreservationPlugin');
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createSelectionPreservationPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
+
var _editorCommands = require("./editor-commands");
|
|
13
|
+
var _pluginKey = require("./plugin-key");
|
|
14
|
+
var _utils = require("./utils");
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
/**
|
|
18
|
+
* Selection Preservation Plugin for ProseMirror Editor
|
|
19
|
+
*
|
|
20
|
+
* Solves a ProseMirror limitation where TextSelection cannot include positions at node boundaries
|
|
21
|
+
* (like media/images). When a selection spans text + media nodes, subsequent transactions cause
|
|
22
|
+
* ProseMirror to collapse the selection to the nearest inline position, excluding the media node.
|
|
23
|
+
* This is problematic for features like block menus and drag-and-drop that need stable multi-node
|
|
24
|
+
* selections while performing operations.
|
|
25
|
+
*
|
|
26
|
+
* The plugin works in three phases:
|
|
27
|
+
* (1) Explicitly save a selection via startPreservingSelection() when opening block menus or starting drag operations.
|
|
28
|
+
* (2) Map the saved selection through document changes to keep positions valid.
|
|
29
|
+
* (3) Detect when transactions collapse the selection and restore it via appendTransaction().
|
|
30
|
+
*
|
|
31
|
+
* Stops preserving via stopPreservingSelection() when the menu closes or operation completes.
|
|
32
|
+
*
|
|
33
|
+
* Commands: startPreservingSelection() to begin preservation, stopPreservingSelection() to end it.
|
|
34
|
+
*
|
|
35
|
+
* NOTE: Only use when the UI blocks user selection changes. For example: when a block menu overlay
|
|
36
|
+
* is open (editor becomes non-interactive), during drag-and-drop operations (user is mid-drag), or
|
|
37
|
+
* when modal dialogs are active. In these states, any selection changes are from ProseMirror's
|
|
38
|
+
* internal behavior (not user input) and should be prevented. Do not use during normal editing.
|
|
39
|
+
*/
|
|
40
|
+
var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugin = function createSelectionPreservationPlugin() {
|
|
41
|
+
return new _safePlugin.SafePlugin({
|
|
42
|
+
key: _pluginKey.selectionPreservationPluginKey,
|
|
43
|
+
state: {
|
|
44
|
+
init: function init() {
|
|
45
|
+
return {
|
|
46
|
+
preservedSelection: undefined
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
apply: function apply(tr, pluginState) {
|
|
50
|
+
var meta = (0, _utils.getSelectionPreservationMeta)(tr);
|
|
51
|
+
var newState = _objectSpread({}, pluginState);
|
|
52
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'startPreserving') {
|
|
53
|
+
newState.preservedSelection = new _state.TextSelection(tr.selection.$from, tr.selection.$to);
|
|
54
|
+
} else if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'stopPreserving') {
|
|
55
|
+
newState.preservedSelection = undefined;
|
|
56
|
+
}
|
|
57
|
+
if (newState.preservedSelection && tr.docChanged) {
|
|
58
|
+
var mapped = new _state.TextSelection(newState.preservedSelection.$from, newState.preservedSelection.$to);
|
|
59
|
+
mapped.map(tr.doc, tr.mapping);
|
|
60
|
+
if (mapped.from >= 0 && mapped.to <= tr.doc.content.size && mapped.from !== mapped.to) {
|
|
61
|
+
newState.preservedSelection = mapped;
|
|
62
|
+
} else if (mapped.from === mapped.to) {
|
|
63
|
+
// If selection has collapsed to a cursor, e.g. after deleting the selection, stop preserving
|
|
64
|
+
newState.preservedSelection = undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return newState;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
71
|
+
var pluginState = _pluginKey.selectionPreservationPluginKey.getState(newState);
|
|
72
|
+
var savedSel = pluginState === null || pluginState === void 0 ? void 0 : pluginState.preservedSelection;
|
|
73
|
+
if (!savedSel) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if ((0, _utils.hasUserSelectionChange)(transactions)) {
|
|
77
|
+
// Auto-stop if user explicitly changes selection
|
|
78
|
+
return (0, _editorCommands.stopPreservingSelection)({
|
|
79
|
+
tr: newState.tr
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
var currSel = newState.selection;
|
|
83
|
+
var wasEmptySelection = savedSel.from === savedSel.to;
|
|
84
|
+
var selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
|
|
85
|
+
var selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
|
|
86
|
+
if (wasEmptySelection || selectionUnchanged || selectionInvalid) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return newState.tr.setSelection(_state.TextSelection.create(newState.doc, savedSel.from, savedSel.to));
|
|
91
|
+
} catch (error) {
|
|
92
|
+
(0, _monitoring.logException)(error, {
|
|
93
|
+
location: 'editor-plugin-block-controls/SelectionPreservationPlugin'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasUserSelectionChange = exports.getSelectionPreservationMeta = void 0;
|
|
7
|
+
var _pluginKey = require("./plugin-key");
|
|
8
|
+
/**
|
|
9
|
+
* Detects if any of the transactions include user-driven selection changes.
|
|
10
|
+
*
|
|
11
|
+
* @param transactions The list of transactions to check.
|
|
12
|
+
* @returns True if any transaction includes a user-driven selection change, otherwise false.
|
|
13
|
+
*/
|
|
14
|
+
var hasUserSelectionChange = exports.hasUserSelectionChange = function hasUserSelectionChange(transactions) {
|
|
15
|
+
return transactions.some(function (tr) {
|
|
16
|
+
return tr.getMeta('pointer') || tr.getMeta('uiEvent') || tr.getMeta('paste') || tr.getMeta('cut') || tr.getMeta('composition') ||
|
|
17
|
+
// IME input
|
|
18
|
+
// Keyboard events that change selection
|
|
19
|
+
tr.getMeta('addToHistory') && tr.selectionSet;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var getSelectionPreservationMeta = exports.getSelectionPreservationMeta = function getSelectionPreservationMeta(tr) {
|
|
23
|
+
return tr.getMeta(_pluginKey.selectionPreservationPluginKey);
|
|
24
|
+
};
|