@atlaskit/editor-plugin-selection-extension 9.0.2 → 9.0.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 +8 -0
- package/dist/cjs/pm-plugins/utils/index.js +58 -4
- package/dist/cjs/selectionExtensionPlugin.js +10 -0
- package/dist/es2019/pm-plugins/utils/index.js +60 -2
- package/dist/es2019/selectionExtensionPlugin.js +11 -1
- package/dist/esm/pm-plugins/utils/index.js +56 -2
- package/dist/esm/selectionExtensionPlugin.js +11 -1
- package/dist/types/pm-plugins/utils/index.d.ts +16 -0
- package/dist/types/selectionExtensionPluginType.d.ts +3 -1
- package/dist/types/ui/toolbar-components/ToolbarMenu.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +16 -0
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +3 -1
- package/dist/types-ts4.5/ui/toolbar-components/ToolbarMenu.d.ts +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 9.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5a3efdfff9617`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5a3efdfff9617) -
|
|
8
|
+
EDITOR-3911 Fix selection extension plugin to use preserved selection for block menu actions
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 9.0.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -4,10 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.getFragmentInfoFromSelection = void 0;
|
|
7
|
+
exports.getFragmentInfoFromSelectionNew = exports.getFragmentInfoFromSelection = void 0;
|
|
8
8
|
exports.getSelectionAdfInfo = getSelectionAdfInfo;
|
|
9
9
|
exports.getSelectionAdfInfoNew = getSelectionAdfInfoNew;
|
|
10
|
-
exports.getSelectionTextInfo = void 0;
|
|
10
|
+
exports.getSelectionTextInfoNew = exports.getSelectionTextInfo = void 0;
|
|
11
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
12
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
13
13
|
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
@@ -51,10 +51,15 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
51
51
|
nodePos: nodePos
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @private
|
|
57
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
58
|
+
*/
|
|
54
59
|
var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
55
|
-
var _api$userPreferences, _api$
|
|
60
|
+
var _api$userPreferences, _api$editorViewMode;
|
|
56
61
|
var currentSelection = view.state.selection;
|
|
57
|
-
var toolbarDocking =
|
|
62
|
+
var toolbarDocking = api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition;
|
|
58
63
|
var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'edit');
|
|
59
64
|
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
60
65
|
var from = currentSelection.from,
|
|
@@ -71,6 +76,30 @@ var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionT
|
|
|
71
76
|
coords: coords
|
|
72
77
|
};
|
|
73
78
|
};
|
|
79
|
+
var getSelectionTextInfoNew = exports.getSelectionTextInfoNew = function getSelectionTextInfoNew(selection, view, api) {
|
|
80
|
+
var _api$userPreferences2, _api$selectionToolbar, _api$editorViewMode2;
|
|
81
|
+
var toolbarDocking = (0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences2 = api.userPreferences) === null || _api$userPreferences2 === void 0 || (_api$userPreferences2 = _api$userPreferences2.sharedState.currentState()) === null || _api$userPreferences2 === void 0 || (_api$userPreferences2 = _api$userPreferences2.preferences) === null || _api$userPreferences2 === void 0 ? void 0 : _api$userPreferences2.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
|
|
82
|
+
var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 || (_api$editorViewMode2 = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.mode) === 'edit');
|
|
83
|
+
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
84
|
+
var from = selection.from,
|
|
85
|
+
to = selection.to;
|
|
86
|
+
var text = view.state.doc.textBetween(from, to, '\n');
|
|
87
|
+
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to, {
|
|
88
|
+
top: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0,
|
|
89
|
+
bottom: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
text: text,
|
|
93
|
+
from: from,
|
|
94
|
+
to: to,
|
|
95
|
+
coords: coords
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @private
|
|
101
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
102
|
+
*/
|
|
74
103
|
var getFragmentInfoFromSelection = exports.getFragmentInfoFromSelection = function getFragmentInfoFromSelection(state) {
|
|
75
104
|
var schema = state.schema,
|
|
76
105
|
selection = state.selection;
|
|
@@ -93,6 +122,31 @@ var getFragmentInfoFromSelection = exports.getFragmentInfoFromSelection = functi
|
|
|
93
122
|
selectedNodeAdf: selectedNodeAdf
|
|
94
123
|
};
|
|
95
124
|
};
|
|
125
|
+
var getFragmentInfoFromSelectionNew = exports.getFragmentInfoFromSelectionNew = function getFragmentInfoFromSelectionNew(selection) {
|
|
126
|
+
var schema = selection.$from.doc.type.schema;
|
|
127
|
+
var slice = selection.content();
|
|
128
|
+
var newDoc;
|
|
129
|
+
try {
|
|
130
|
+
var doc = schema.node('doc', null, [schema.node('paragraph', null, [])]);
|
|
131
|
+
var transform = new _transform.Transform(doc);
|
|
132
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
newDoc = schema.nodes.doc.createChecked({}, _model.Fragment.empty);
|
|
135
|
+
(0, _monitoring.logException)(error, {
|
|
136
|
+
location: 'editor-plugin-selection-extension'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
var serializer = new _editorJsonTransformer.JSONTransformer();
|
|
140
|
+
var selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
141
|
+
return {
|
|
142
|
+
selectedNodeAdf: selectedNodeAdf
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @private
|
|
148
|
+
* @deprecated use getSelectionAdfInfoNew instead
|
|
149
|
+
*/
|
|
96
150
|
function getSelectionAdfInfo(state) {
|
|
97
151
|
var selection = state.selection;
|
|
98
152
|
var selectionInfo = {
|
|
@@ -112,6 +112,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
112
112
|
return null;
|
|
113
113
|
}
|
|
114
114
|
var state = editorViewRef.current.state;
|
|
115
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
|
|
116
|
+
var _api$blockControls;
|
|
117
|
+
var selection = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection) || state.selection;
|
|
118
|
+
return (0, _utils.getSelectionAdfInfoNew)(selection);
|
|
119
|
+
}
|
|
115
120
|
var _getSelectionAdfInfo = (0, _utils.getSelectionAdfInfo)(state),
|
|
116
121
|
selectionRanges = _getSelectionAdfInfo.selectionRanges,
|
|
117
122
|
selectedNodeAdf = _getSelectionAdfInfo.selectedNodeAdf;
|
|
@@ -125,6 +130,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
125
130
|
return null;
|
|
126
131
|
}
|
|
127
132
|
var state = editorViewRef.current.state;
|
|
133
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
|
|
134
|
+
var _api$blockControls2;
|
|
135
|
+
var selection = (api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.preservedSelection) || state.selection;
|
|
136
|
+
return (0, _utils.getFragmentInfoFromSelectionNew)(selection);
|
|
137
|
+
}
|
|
128
138
|
var _getFragmentInfoFromS = (0, _utils.getFragmentInfoFromSelection)(state),
|
|
129
139
|
selectedNodeAdf = _getFragmentInfoFromS.selectedNodeAdf;
|
|
130
140
|
return {
|
|
@@ -40,12 +40,17 @@ const getSelectionInfoFromCellSelection = selection => {
|
|
|
40
40
|
nodePos
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
47
|
+
*/
|
|
43
48
|
export const getSelectionTextInfo = (view, api) => {
|
|
44
|
-
var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$
|
|
49
|
+
var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$editorViewMode, _api$editorViewMode$s;
|
|
45
50
|
const {
|
|
46
51
|
selection: currentSelection
|
|
47
52
|
} = view.state;
|
|
48
|
-
const toolbarDocking =
|
|
53
|
+
const toolbarDocking = api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : (_api$userPreferences$ = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences$ === void 0 ? void 0 : (_api$userPreferences$2 = _api$userPreferences$.preferences) === null || _api$userPreferences$2 === void 0 ? void 0 : _api$userPreferences$2.toolbarDockingPosition;
|
|
49
54
|
const isEditMode = Boolean((api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : (_api$editorViewMode$s = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode$s === void 0 ? void 0 : _api$editorViewMode$s.mode) === 'edit');
|
|
50
55
|
const shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
51
56
|
const {
|
|
@@ -64,6 +69,32 @@ export const getSelectionTextInfo = (view, api) => {
|
|
|
64
69
|
coords
|
|
65
70
|
};
|
|
66
71
|
};
|
|
72
|
+
export const getSelectionTextInfoNew = (selection, view, api) => {
|
|
73
|
+
var _api$userPreferences2, _api$userPreferences3, _api$userPreferences4, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3, _api$editorViewMode2, _api$editorViewMode2$;
|
|
74
|
+
const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 ? void 0 : (_api$userPreferences2 = api.userPreferences) === null || _api$userPreferences2 === void 0 ? void 0 : (_api$userPreferences3 = _api$userPreferences2.sharedState.currentState()) === null || _api$userPreferences3 === void 0 ? void 0 : (_api$userPreferences4 = _api$userPreferences3.preferences) === null || _api$userPreferences4 === void 0 ? void 0 : _api$userPreferences4.toolbarDockingPosition : api === null || api === void 0 ? void 0 : (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 ? void 0 : (_api$selectionToolbar2 = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.currentState()) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.toolbarDocking;
|
|
75
|
+
const isEditMode = Boolean((api === null || api === void 0 ? void 0 : (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : (_api$editorViewMode2$ = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2$ === void 0 ? void 0 : _api$editorViewMode2$.mode) === 'edit');
|
|
76
|
+
const shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
77
|
+
const {
|
|
78
|
+
from,
|
|
79
|
+
to
|
|
80
|
+
} = selection;
|
|
81
|
+
const text = view.state.doc.textBetween(from, to, '\n');
|
|
82
|
+
const coords = getBoundingBoxFromSelection(view, from, to, {
|
|
83
|
+
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
84
|
+
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
text,
|
|
88
|
+
from,
|
|
89
|
+
to,
|
|
90
|
+
coords
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @private
|
|
96
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
97
|
+
*/
|
|
67
98
|
export const getFragmentInfoFromSelection = state => {
|
|
68
99
|
const {
|
|
69
100
|
schema,
|
|
@@ -90,6 +121,33 @@ export const getFragmentInfoFromSelection = state => {
|
|
|
90
121
|
selectedNodeAdf
|
|
91
122
|
};
|
|
92
123
|
};
|
|
124
|
+
export const getFragmentInfoFromSelectionNew = selection => {
|
|
125
|
+
const {
|
|
126
|
+
schema
|
|
127
|
+
} = selection.$from.doc.type;
|
|
128
|
+
const slice = selection.content();
|
|
129
|
+
let newDoc;
|
|
130
|
+
try {
|
|
131
|
+
const doc = schema.node('doc', null, [schema.node('paragraph', null, [])]);
|
|
132
|
+
const transform = new Transform(doc);
|
|
133
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
newDoc = schema.nodes.doc.createChecked({}, Fragment.empty);
|
|
136
|
+
logException(error, {
|
|
137
|
+
location: 'editor-plugin-selection-extension'
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const serializer = new JSONTransformer();
|
|
141
|
+
const selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
142
|
+
return {
|
|
143
|
+
selectedNodeAdf
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @private
|
|
149
|
+
* @deprecated use getSelectionAdfInfoNew instead
|
|
150
|
+
*/
|
|
93
151
|
export function getSelectionAdfInfo(state) {
|
|
94
152
|
const selection = state.selection;
|
|
95
153
|
let selectionInfo = {
|
|
@@ -8,7 +8,7 @@ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equ
|
|
|
8
8
|
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
9
9
|
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
10
10
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
11
|
-
import { getFragmentInfoFromSelection, getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
11
|
+
import { getFragmentInfoFromSelection, getFragmentInfoFromSelectionNew, getSelectionAdfInfo, getSelectionAdfInfoNew, getSelectionTextInfo } from './pm-plugins/utils';
|
|
12
12
|
import { SelectionExtensionActionTypes } from './types';
|
|
13
13
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
14
14
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
@@ -103,6 +103,11 @@ export const selectionExtensionPlugin = ({
|
|
|
103
103
|
const {
|
|
104
104
|
state
|
|
105
105
|
} = editorViewRef.current;
|
|
106
|
+
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
107
|
+
var _api$blockControls, _api$blockControls$sh;
|
|
108
|
+
const selection = (api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection) || state.selection;
|
|
109
|
+
return getSelectionAdfInfoNew(selection);
|
|
110
|
+
}
|
|
106
111
|
const {
|
|
107
112
|
selectionRanges,
|
|
108
113
|
selectedNodeAdf
|
|
@@ -119,6 +124,11 @@ export const selectionExtensionPlugin = ({
|
|
|
119
124
|
const {
|
|
120
125
|
state
|
|
121
126
|
} = editorViewRef.current;
|
|
127
|
+
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
128
|
+
var _api$blockControls2, _api$blockControls2$s;
|
|
129
|
+
const selection = (api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2$s === void 0 ? void 0 : _api$blockControls2$s.preservedSelection) || state.selection;
|
|
130
|
+
return getFragmentInfoFromSelectionNew(selection);
|
|
131
|
+
}
|
|
122
132
|
const {
|
|
123
133
|
selectedNodeAdf
|
|
124
134
|
} = getFragmentInfoFromSelection(state);
|
|
@@ -41,10 +41,15 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
41
41
|
nodePos: nodePos
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @private
|
|
47
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
48
|
+
*/
|
|
44
49
|
export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
45
|
-
var _api$userPreferences, _api$
|
|
50
|
+
var _api$userPreferences, _api$editorViewMode;
|
|
46
51
|
var currentSelection = view.state.selection;
|
|
47
|
-
var toolbarDocking =
|
|
52
|
+
var toolbarDocking = api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition;
|
|
48
53
|
var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'edit');
|
|
49
54
|
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
50
55
|
var from = currentSelection.from,
|
|
@@ -61,6 +66,30 @@ export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
|
61
66
|
coords: coords
|
|
62
67
|
};
|
|
63
68
|
};
|
|
69
|
+
export var getSelectionTextInfoNew = function getSelectionTextInfoNew(selection, view, api) {
|
|
70
|
+
var _api$userPreferences2, _api$selectionToolbar, _api$editorViewMode2;
|
|
71
|
+
var toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences2 = api.userPreferences) === null || _api$userPreferences2 === void 0 || (_api$userPreferences2 = _api$userPreferences2.sharedState.currentState()) === null || _api$userPreferences2 === void 0 || (_api$userPreferences2 = _api$userPreferences2.preferences) === null || _api$userPreferences2 === void 0 ? void 0 : _api$userPreferences2.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
|
|
72
|
+
var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 || (_api$editorViewMode2 = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.mode) === 'edit');
|
|
73
|
+
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode;
|
|
74
|
+
var from = selection.from,
|
|
75
|
+
to = selection.to;
|
|
76
|
+
var text = view.state.doc.textBetween(from, to, '\n');
|
|
77
|
+
var coords = getBoundingBoxFromSelection(view, from, to, {
|
|
78
|
+
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
79
|
+
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
text: text,
|
|
83
|
+
from: from,
|
|
84
|
+
to: to,
|
|
85
|
+
coords: coords
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @private
|
|
91
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
92
|
+
*/
|
|
64
93
|
export var getFragmentInfoFromSelection = function getFragmentInfoFromSelection(state) {
|
|
65
94
|
var schema = state.schema,
|
|
66
95
|
selection = state.selection;
|
|
@@ -83,6 +112,31 @@ export var getFragmentInfoFromSelection = function getFragmentInfoFromSelection(
|
|
|
83
112
|
selectedNodeAdf: selectedNodeAdf
|
|
84
113
|
};
|
|
85
114
|
};
|
|
115
|
+
export var getFragmentInfoFromSelectionNew = function getFragmentInfoFromSelectionNew(selection) {
|
|
116
|
+
var schema = selection.$from.doc.type.schema;
|
|
117
|
+
var slice = selection.content();
|
|
118
|
+
var newDoc;
|
|
119
|
+
try {
|
|
120
|
+
var doc = schema.node('doc', null, [schema.node('paragraph', null, [])]);
|
|
121
|
+
var transform = new Transform(doc);
|
|
122
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
newDoc = schema.nodes.doc.createChecked({}, Fragment.empty);
|
|
125
|
+
logException(error, {
|
|
126
|
+
location: 'editor-plugin-selection-extension'
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
var serializer = new JSONTransformer();
|
|
130
|
+
var selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
131
|
+
return {
|
|
132
|
+
selectedNodeAdf: selectedNodeAdf
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @private
|
|
138
|
+
* @deprecated use getSelectionAdfInfoNew instead
|
|
139
|
+
*/
|
|
86
140
|
export function getSelectionAdfInfo(state) {
|
|
87
141
|
var selection = state.selection;
|
|
88
142
|
var selectionInfo = {
|
|
@@ -9,7 +9,7 @@ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equ
|
|
|
9
9
|
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
10
10
|
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
11
11
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
12
|
-
import { getFragmentInfoFromSelection, getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
12
|
+
import { getFragmentInfoFromSelection, getFragmentInfoFromSelectionNew, getSelectionAdfInfo, getSelectionAdfInfoNew, getSelectionTextInfo } from './pm-plugins/utils';
|
|
13
13
|
import { SelectionExtensionActionTypes } from './types';
|
|
14
14
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
15
15
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
@@ -105,6 +105,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
107
|
var state = editorViewRef.current.state;
|
|
108
|
+
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
109
|
+
var _api$blockControls;
|
|
110
|
+
var selection = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection) || state.selection;
|
|
111
|
+
return getSelectionAdfInfoNew(selection);
|
|
112
|
+
}
|
|
108
113
|
var _getSelectionAdfInfo = getSelectionAdfInfo(state),
|
|
109
114
|
selectionRanges = _getSelectionAdfInfo.selectionRanges,
|
|
110
115
|
selectedNodeAdf = _getSelectionAdfInfo.selectedNodeAdf;
|
|
@@ -118,6 +123,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
118
123
|
return null;
|
|
119
124
|
}
|
|
120
125
|
var state = editorViewRef.current.state;
|
|
126
|
+
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
127
|
+
var _api$blockControls2;
|
|
128
|
+
var selection = (api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.preservedSelection) || state.selection;
|
|
129
|
+
return getFragmentInfoFromSelectionNew(selection);
|
|
130
|
+
}
|
|
121
131
|
var _getFragmentInfoFromS = getFragmentInfoFromSelection(state),
|
|
122
132
|
selectedNodeAdf = _getFragmentInfoFromS.selectedNodeAdf;
|
|
123
133
|
return {
|
|
@@ -12,10 +12,26 @@ type SelectionInfo = {
|
|
|
12
12
|
selectedNodeAdf: ADFEntity;
|
|
13
13
|
selectionRanges?: SelectionRange[];
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
18
|
+
*/
|
|
15
19
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
20
|
+
export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
24
|
+
*/
|
|
16
25
|
export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
17
26
|
selectedNodeAdf: ADFEntity;
|
|
18
27
|
};
|
|
28
|
+
export declare const getFragmentInfoFromSelectionNew: (selection: Selection) => {
|
|
29
|
+
selectedNodeAdf: ADFEntity;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
* @deprecated use getSelectionAdfInfoNew instead
|
|
34
|
+
*/
|
|
19
35
|
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
20
36
|
export declare function getSelectionAdfInfoNew(selection: Selection): SelectionInfo;
|
|
21
37
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
4
5
|
import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
|
|
5
6
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
6
7
|
import type { EditorViewModeEffectsPlugin } from '@atlaskit/editor-plugin-editor-viewmode-effects';
|
|
@@ -10,7 +11,7 @@ import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-t
|
|
|
10
11
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
11
12
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
12
13
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
13
|
-
import type {
|
|
14
|
+
import type { ExtensionMenuItemConfiguration, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
14
15
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
15
16
|
actions: {
|
|
16
17
|
getDocumentFromSelection: () => {
|
|
@@ -35,6 +36,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
35
36
|
OptionalPlugin<UserPreferencesPlugin>,
|
|
36
37
|
OptionalPlugin<UserIntentPlugin>,
|
|
37
38
|
OptionalPlugin<SelectionPlugin>,
|
|
39
|
+
OptionalPlugin<BlockControlsPlugin>,
|
|
38
40
|
OptionalPlugin<BlockMenuPlugin>,
|
|
39
41
|
OptionalPlugin<ToolbarPlugin>,
|
|
40
42
|
SelectionToolbarPlugin
|
|
@@ -6,5 +6,5 @@ type ToolbarMenuProps = React.PropsWithChildren<{
|
|
|
6
6
|
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
7
7
|
config: ExtensionToolbarItemConfiguration;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const ToolbarMenu: ({ api, config, children }: ToolbarMenuProps) => React.JSX.Element | null;
|
|
9
|
+
export declare const ToolbarMenu: ({ api, config, children, }: ToolbarMenuProps) => React.JSX.Element | null;
|
|
10
10
|
export {};
|
|
@@ -12,10 +12,26 @@ type SelectionInfo = {
|
|
|
12
12
|
selectedNodeAdf: ADFEntity;
|
|
13
13
|
selectionRanges?: SelectionRange[];
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
18
|
+
*/
|
|
15
19
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
20
|
+
export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
* @deprecated use getFragmentInfoFromSelectionNew instead
|
|
24
|
+
*/
|
|
16
25
|
export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
17
26
|
selectedNodeAdf: ADFEntity;
|
|
18
27
|
};
|
|
28
|
+
export declare const getFragmentInfoFromSelectionNew: (selection: Selection) => {
|
|
29
|
+
selectedNodeAdf: ADFEntity;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
* @deprecated use getSelectionAdfInfoNew instead
|
|
34
|
+
*/
|
|
19
35
|
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
20
36
|
export declare function getSelectionAdfInfoNew(selection: Selection): SelectionInfo;
|
|
21
37
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
4
5
|
import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
|
|
5
6
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
6
7
|
import type { EditorViewModeEffectsPlugin } from '@atlaskit/editor-plugin-editor-viewmode-effects';
|
|
@@ -10,7 +11,7 @@ import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-t
|
|
|
10
11
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
11
12
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
12
13
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
13
|
-
import type {
|
|
14
|
+
import type { ExtensionMenuItemConfiguration, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
14
15
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
15
16
|
actions: {
|
|
16
17
|
getDocumentFromSelection: () => {
|
|
@@ -35,6 +36,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
35
36
|
OptionalPlugin<UserPreferencesPlugin>,
|
|
36
37
|
OptionalPlugin<UserIntentPlugin>,
|
|
37
38
|
OptionalPlugin<SelectionPlugin>,
|
|
39
|
+
OptionalPlugin<BlockControlsPlugin>,
|
|
38
40
|
OptionalPlugin<BlockMenuPlugin>,
|
|
39
41
|
OptionalPlugin<ToolbarPlugin>,
|
|
40
42
|
SelectionToolbarPlugin
|
|
@@ -6,5 +6,5 @@ type ToolbarMenuProps = React.PropsWithChildren<{
|
|
|
6
6
|
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
7
7
|
config: ExtensionToolbarItemConfiguration;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const ToolbarMenu: ({ api, config, children }: ToolbarMenuProps) => React.JSX.Element | null;
|
|
9
|
+
export declare const ToolbarMenu: ({ api, config, children, }: ToolbarMenuProps) => React.JSX.Element | null;
|
|
10
10
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.3",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,34 +35,35 @@
|
|
|
35
35
|
"@atlaskit/adf-utils": "^19.26.0",
|
|
36
36
|
"@atlaskit/editor-json-transformer": "^8.31.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^6.2.0",
|
|
38
|
-
"@atlaskit/editor-plugin-block-
|
|
38
|
+
"@atlaskit/editor-plugin-block-controls": "^7.14.0",
|
|
39
|
+
"@atlaskit/editor-plugin-block-menu": "^5.2.0",
|
|
39
40
|
"@atlaskit/editor-plugin-editor-viewmode": "^8.0.0",
|
|
40
41
|
"@atlaskit/editor-plugin-editor-viewmode-effects": "^6.1.0",
|
|
41
42
|
"@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
|
|
42
43
|
"@atlaskit/editor-plugin-selection-toolbar": "^7.1.0",
|
|
43
44
|
"@atlaskit/editor-plugin-toolbar": "^3.4.0",
|
|
44
45
|
"@atlaskit/editor-plugin-user-preferences": "^4.0.0",
|
|
45
|
-
"@atlaskit/editor-prosemirror": "7.
|
|
46
|
+
"@atlaskit/editor-prosemirror": "^7.2.0",
|
|
46
47
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
47
48
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
48
49
|
"@atlaskit/editor-toolbar": "^0.18.0",
|
|
49
|
-
"@atlaskit/icon": "^29.
|
|
50
|
+
"@atlaskit/icon": "^29.1.0",
|
|
50
51
|
"@atlaskit/lozenge": "^13.1.0",
|
|
51
52
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
52
53
|
"@atlaskit/platform-feature-flags-react": "^0.4.0",
|
|
53
54
|
"@atlaskit/primitives": "^16.4.0",
|
|
54
|
-
"@atlaskit/tmp-editor-statsig": "^15.
|
|
55
|
+
"@atlaskit/tmp-editor-statsig": "^15.10.0",
|
|
55
56
|
"@babel/runtime": "^7.0.0",
|
|
56
57
|
"lodash": "^4.17.21",
|
|
57
58
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
58
59
|
"uuid": "^3.1.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
|
-
"@atlaskit/editor-common": "^110.
|
|
62
|
+
"@atlaskit/editor-common": "^110.42.0",
|
|
62
63
|
"react": "^18.2.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@testing-library/react": "^
|
|
66
|
+
"@testing-library/react": "^16.3.0",
|
|
66
67
|
"react-dom": "^18.2.0",
|
|
67
68
|
"wait-for-expect": "^1.2.0"
|
|
68
69
|
},
|