@atlaskit/editor-plugin-selection-extension 3.4.1 → 3.4.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 +15 -0
- package/dist/cjs/pm-plugins/utils/index.js +25 -2
- package/dist/cjs/selectionExtensionPlugin.js +35 -29
- package/dist/cjs/ui/getBoundingBoxFromSelection.js +7 -0
- package/dist/es2019/pm-plugins/utils/index.js +28 -1
- package/dist/es2019/selectionExtensionPlugin.js +34 -28
- package/dist/es2019/ui/getBoundingBoxFromSelection.js +7 -1
- package/dist/esm/pm-plugins/utils/index.js +24 -1
- package/dist/esm/selectionExtensionPlugin.js +36 -30
- package/dist/esm/ui/getBoundingBoxFromSelection.js +7 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/utils/index.d.ts +6 -1
- package/dist/types/selectionExtensionPluginType.d.ts +5 -1
- package/dist/types/types/index.d.ts +12 -0
- package/dist/types/ui/getBoundingBoxFromSelection.d.ts +3 -2
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +6 -1
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +5 -1
- package/dist/types-ts4.5/types/index.d.ts +12 -0
- package/dist/types-ts4.5/ui/getBoundingBoxFromSelection.d.ts +3 -2
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`86db72552d6a0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86db72552d6a0) -
|
|
8
|
+
Add Apis to get selection adf and text information
|
|
9
|
+
|
|
10
|
+
## 3.4.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`373e833d95d52`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/373e833d95d52) -
|
|
15
|
+
[ux] COMMIT-19456:Fix forge app coords bug
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 3.4.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -4,11 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.validateSelectedNode = exports.
|
|
7
|
+
exports.validateSelectedNode = exports.getSelectionTextInfo = exports.getSelectionAdfInfo = void 0;
|
|
8
8
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
9
9
|
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
12
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
+
var _getBoundingBoxFromSelection = require("../../ui/getBoundingBoxFromSelection");
|
|
12
15
|
var getSelectedRect = function getSelectedRect(selection) {
|
|
13
16
|
var $anchorCell = selection.$anchorCell,
|
|
14
17
|
$headCell = selection.$headCell;
|
|
@@ -57,7 +60,27 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
57
60
|
nodePos: nodePos
|
|
58
61
|
};
|
|
59
62
|
};
|
|
60
|
-
var
|
|
63
|
+
var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
64
|
+
var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode;
|
|
65
|
+
var currentSelection = view.state.selection;
|
|
66
|
+
var toolbarDocking = (0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin') ? 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 : 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;
|
|
67
|
+
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');
|
|
68
|
+
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && (0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2');
|
|
69
|
+
var from = currentSelection.from,
|
|
70
|
+
to = currentSelection.to;
|
|
71
|
+
var text = view.state.doc.textBetween(from, to, '\n');
|
|
72
|
+
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to, {
|
|
73
|
+
top: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0,
|
|
74
|
+
bottom: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
text: text,
|
|
78
|
+
from: from,
|
|
79
|
+
to: to,
|
|
80
|
+
coords: coords
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var getSelectionAdfInfo = exports.getSelectionAdfInfo = function getSelectionAdfInfo(state) {
|
|
61
84
|
var selection = state.selection;
|
|
62
85
|
var selectionInfo = {
|
|
63
86
|
selectedNode: selection.$from.node(),
|
|
@@ -18,7 +18,6 @@ var _utils = require("./pm-plugins/utils");
|
|
|
18
18
|
var _types = require("./types");
|
|
19
19
|
var _SelectionExtensionComponentWrapper = require("./ui/extension/SelectionExtensionComponentWrapper");
|
|
20
20
|
var _extensions = require("./ui/extensions");
|
|
21
|
-
var _getBoundingBoxFromSelection = require("./ui/getBoundingBoxFromSelection");
|
|
22
21
|
var _LegacyToolbarComponent = require("./ui/LegacyToolbarComponent");
|
|
23
22
|
var _selectionToolbar2 = require("./ui/selectionToolbar");
|
|
24
23
|
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
@@ -114,11 +113,32 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
114
113
|
state = _editorViewRef$curren3.state,
|
|
115
114
|
dispatch = _editorViewRef$curren3.dispatch;
|
|
116
115
|
return (0, _insertAdfAtEndOfDoc2.insertAdfAtEndOfDoc)(nodeAdf)(state, dispatch);
|
|
116
|
+
},
|
|
117
|
+
getSelectionAdf: function getSelectionAdf() {
|
|
118
|
+
if (!editorViewRef.current) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
var state = editorViewRef.current.state;
|
|
122
|
+
var _getSelectionAdfInfo = (0, _utils.getSelectionAdfInfo)(state),
|
|
123
|
+
selectionRanges = _getSelectionAdfInfo.selectionRanges,
|
|
124
|
+
selectedNodeAdf = _getSelectionAdfInfo.selectedNodeAdf;
|
|
125
|
+
return {
|
|
126
|
+
selectedNodeAdf: selectedNodeAdf,
|
|
127
|
+
selectionRanges: selectionRanges
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
getSelectionText: function getSelectionText() {
|
|
131
|
+
if (!editorViewRef.current) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
var _getSelectionTextInfo = (0, _utils.getSelectionTextInfo)(editorViewRef.current, api),
|
|
135
|
+
text = _getSelectionTextInfo.text,
|
|
136
|
+
coords = _getSelectionTextInfo.coords;
|
|
137
|
+
return {
|
|
138
|
+
text: text,
|
|
139
|
+
coords: coords
|
|
140
|
+
};
|
|
117
141
|
}
|
|
118
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
119
|
-
// getSelectionAdf: () => {},
|
|
120
|
-
// NEXT PR: Implement this to return text, coords
|
|
121
|
-
// getSelectionText: () => {},
|
|
122
142
|
},
|
|
123
143
|
contentComponent: function contentComponent(_ref6) {
|
|
124
144
|
var _api$analytics;
|
|
@@ -168,23 +188,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
168
188
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
169
189
|
return;
|
|
170
190
|
}
|
|
171
|
-
var getSelection = function getSelection(view) {
|
|
172
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
173
|
-
var currentSelection = view.state.selection;
|
|
174
|
-
var from = currentSelection.from,
|
|
175
|
-
to = currentSelection.to;
|
|
176
|
-
var text = view.state.doc.textBetween(from, to, '\n');
|
|
177
|
-
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to);
|
|
178
|
-
return {
|
|
179
|
-
text: text,
|
|
180
|
-
from: from,
|
|
181
|
-
to: to,
|
|
182
|
-
coords: coords
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
191
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
186
192
|
return function (extension) {
|
|
187
|
-
var selection =
|
|
193
|
+
var selection = (0, _utils.getSelectionTextInfo)(view, api);
|
|
188
194
|
if (extension.component) {
|
|
189
195
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
190
196
|
extension: extension,
|
|
@@ -196,11 +202,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
196
202
|
};
|
|
197
203
|
if ((0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2')) {
|
|
198
204
|
var _extension$onClick, _api$core;
|
|
199
|
-
var
|
|
200
|
-
selectedNodeAdf =
|
|
201
|
-
selectionRanges =
|
|
202
|
-
selectedNode =
|
|
203
|
-
nodePos =
|
|
205
|
+
var _getSelectionAdfInfo2 = (0, _utils.getSelectionAdfInfo)(view.state),
|
|
206
|
+
selectedNodeAdf = _getSelectionAdfInfo2.selectedNodeAdf,
|
|
207
|
+
selectionRanges = _getSelectionAdfInfo2.selectionRanges,
|
|
208
|
+
selectedNode = _getSelectionAdfInfo2.selectedNode,
|
|
209
|
+
nodePos = _getSelectionAdfInfo2.nodePos;
|
|
204
210
|
onClickCallbackOptions = {
|
|
205
211
|
selectedNodeAdf: selectedNodeAdf,
|
|
206
212
|
selectionRanges: selectionRanges
|
|
@@ -225,7 +231,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
225
231
|
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
226
232
|
var _extension$isDisabled;
|
|
227
233
|
var disabled = (extension === null || extension === void 0 ? void 0 : extension.isDisabled) instanceof Function ? extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
228
|
-
selection: editorViewRef.current ?
|
|
234
|
+
selection: editorViewRef.current ? (0, _utils.getSelectionTextInfo)(editorViewRef.current, api) : undefined
|
|
229
235
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
230
236
|
return {
|
|
231
237
|
title: extension.name,
|
|
@@ -242,9 +248,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
242
248
|
};
|
|
243
249
|
var getConfigFromExtensionCallback = function getConfigFromExtensionCallback(extension) {
|
|
244
250
|
if (typeof extension === 'function') {
|
|
245
|
-
var
|
|
246
|
-
selectedNodeAdf =
|
|
247
|
-
selectionRanges =
|
|
251
|
+
var _getSelectionAdfInfo3 = (0, _utils.getSelectionAdfInfo)(state),
|
|
252
|
+
selectedNodeAdf = _getSelectionAdfInfo3.selectedNodeAdf,
|
|
253
|
+
selectionRanges = _getSelectionAdfInfo3.selectionRanges;
|
|
248
254
|
return extension({
|
|
249
255
|
selectedNodeAdf: selectedNodeAdf,
|
|
250
256
|
selectionRanges: selectionRanges
|
|
@@ -10,9 +10,14 @@ exports.getBoundingBoxFromSelection = void 0;
|
|
|
10
10
|
* @param view - The editor view instance.
|
|
11
11
|
* @param from - The starting position of the selection.
|
|
12
12
|
* @param to - The ending position of the selection.
|
|
13
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
|
|
13
14
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
14
15
|
*/
|
|
15
16
|
var getBoundingBoxFromSelection = exports.getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
|
|
17
|
+
var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
18
|
+
top: 0,
|
|
19
|
+
bottom: 0
|
|
20
|
+
};
|
|
16
21
|
var top = Infinity,
|
|
17
22
|
left = Infinity,
|
|
18
23
|
bottom = -Infinity,
|
|
@@ -26,6 +31,8 @@ var getBoundingBoxFromSelection = exports.getBoundingBoxFromSelection = function
|
|
|
26
31
|
bottom = Math.max(bottom, coords.bottom);
|
|
27
32
|
right = Math.max(right, coords.right);
|
|
28
33
|
}
|
|
34
|
+
top = top - offset.top;
|
|
35
|
+
bottom = bottom - offset.bottom;
|
|
29
36
|
return {
|
|
30
37
|
top: top,
|
|
31
38
|
left: left,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import isEqual from 'lodash/isEqual';
|
|
2
2
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
3
3
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
4
5
|
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
|
+
import { getBoundingBoxFromSelection } from '../../ui/getBoundingBoxFromSelection';
|
|
5
8
|
const getSelectedRect = selection => {
|
|
6
9
|
const {
|
|
7
10
|
$anchorCell,
|
|
@@ -54,7 +57,31 @@ const getSelectionInfoFromCellSelection = selection => {
|
|
|
54
57
|
nodePos
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
|
-
export const
|
|
60
|
+
export const getSelectionTextInfo = (view, api) => {
|
|
61
|
+
var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3, _api$editorViewMode, _api$editorViewMode$s;
|
|
62
|
+
const {
|
|
63
|
+
selection: currentSelection
|
|
64
|
+
} = view.state;
|
|
65
|
+
const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? 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 : 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;
|
|
66
|
+
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');
|
|
67
|
+
const shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
|
|
68
|
+
const {
|
|
69
|
+
from,
|
|
70
|
+
to
|
|
71
|
+
} = currentSelection;
|
|
72
|
+
const text = view.state.doc.textBetween(from, to, '\n');
|
|
73
|
+
const coords = getBoundingBoxFromSelection(view, from, to, {
|
|
74
|
+
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
75
|
+
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
text,
|
|
79
|
+
from,
|
|
80
|
+
to,
|
|
81
|
+
coords
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export const getSelectionAdfInfo = state => {
|
|
58
85
|
const selection = state.selection;
|
|
59
86
|
let selectionInfo = {
|
|
60
87
|
selectedNode: selection.$from.node(),
|
|
@@ -6,11 +6,10 @@ import { insertSmartLinks } from './pm-plugins/actions';
|
|
|
6
6
|
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
7
7
|
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
8
8
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
9
|
-
import {
|
|
9
|
+
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
10
10
|
import { SelectionExtensionActionTypes } from './types';
|
|
11
11
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
12
12
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
13
|
-
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
14
13
|
import { LegacyPrimaryToolbarComponent } from './ui/LegacyToolbarComponent';
|
|
15
14
|
import { selectionToolbar } from './ui/selectionToolbar';
|
|
16
15
|
export const selectionExtensionPlugin = ({
|
|
@@ -104,11 +103,36 @@ export const selectionExtensionPlugin = ({
|
|
|
104
103
|
dispatch
|
|
105
104
|
} = editorViewRef.current;
|
|
106
105
|
return insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
|
|
106
|
+
},
|
|
107
|
+
getSelectionAdf: () => {
|
|
108
|
+
if (!editorViewRef.current) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const {
|
|
112
|
+
state
|
|
113
|
+
} = editorViewRef.current;
|
|
114
|
+
const {
|
|
115
|
+
selectionRanges,
|
|
116
|
+
selectedNodeAdf
|
|
117
|
+
} = getSelectionAdfInfo(state);
|
|
118
|
+
return {
|
|
119
|
+
selectedNodeAdf,
|
|
120
|
+
selectionRanges
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
getSelectionText: () => {
|
|
124
|
+
if (!editorViewRef.current) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const {
|
|
128
|
+
text,
|
|
129
|
+
coords
|
|
130
|
+
} = getSelectionTextInfo(editorViewRef.current, api);
|
|
131
|
+
return {
|
|
132
|
+
text,
|
|
133
|
+
coords
|
|
134
|
+
};
|
|
107
135
|
}
|
|
108
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
109
|
-
// getSelectionAdf: () => {},
|
|
110
|
-
// NEXT PR: Implement this to return text, coords
|
|
111
|
-
// getSelectionText: () => {},
|
|
112
136
|
},
|
|
113
137
|
contentComponent: ({
|
|
114
138
|
editorView
|
|
@@ -161,26 +185,8 @@ export const selectionExtensionPlugin = ({
|
|
|
161
185
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
162
186
|
return;
|
|
163
187
|
}
|
|
164
|
-
const getSelection = view => {
|
|
165
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
166
|
-
const {
|
|
167
|
-
selection: currentSelection
|
|
168
|
-
} = view.state;
|
|
169
|
-
const {
|
|
170
|
-
from,
|
|
171
|
-
to
|
|
172
|
-
} = currentSelection;
|
|
173
|
-
const text = view.state.doc.textBetween(from, to, '\n');
|
|
174
|
-
const coords = getBoundingBoxFromSelection(view, from, to);
|
|
175
|
-
return {
|
|
176
|
-
text,
|
|
177
|
-
from,
|
|
178
|
-
to,
|
|
179
|
-
coords
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
188
|
const handleOnExtensionClick = view => extension => {
|
|
183
|
-
const selection =
|
|
189
|
+
const selection = getSelectionTextInfo(view, api);
|
|
184
190
|
if (extension.component) {
|
|
185
191
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
186
192
|
extension,
|
|
@@ -197,7 +203,7 @@ export const selectionExtensionPlugin = ({
|
|
|
197
203
|
selectionRanges,
|
|
198
204
|
selectedNode,
|
|
199
205
|
nodePos
|
|
200
|
-
} =
|
|
206
|
+
} = getSelectionAdfInfo(view.state);
|
|
201
207
|
onClickCallbackOptions = {
|
|
202
208
|
selectedNodeAdf,
|
|
203
209
|
selectionRanges
|
|
@@ -222,7 +228,7 @@ export const selectionExtensionPlugin = ({
|
|
|
222
228
|
const convertExtensionToDropdownMenuItem = (extension, rank) => {
|
|
223
229
|
var _extension$isDisabled;
|
|
224
230
|
const disabled = (extension === null || extension === void 0 ? void 0 : extension.isDisabled) instanceof Function ? extension === null || extension === void 0 ? void 0 : (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
225
|
-
selection: editorViewRef.current ?
|
|
231
|
+
selection: editorViewRef.current ? getSelectionTextInfo(editorViewRef.current, api) : undefined
|
|
226
232
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
227
233
|
return {
|
|
228
234
|
title: extension.name,
|
|
@@ -242,7 +248,7 @@ export const selectionExtensionPlugin = ({
|
|
|
242
248
|
const {
|
|
243
249
|
selectedNodeAdf,
|
|
244
250
|
selectionRanges
|
|
245
|
-
} =
|
|
251
|
+
} = getSelectionAdfInfo(state);
|
|
246
252
|
return extension({
|
|
247
253
|
selectedNodeAdf,
|
|
248
254
|
selectionRanges
|
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
* @param view - The editor view instance.
|
|
5
5
|
* @param from - The starting position of the selection.
|
|
6
6
|
* @param to - The ending position of the selection.
|
|
7
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
|
|
7
8
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
8
9
|
*/
|
|
9
|
-
export const getBoundingBoxFromSelection = (view, from, to
|
|
10
|
+
export const getBoundingBoxFromSelection = (view, from, to, offset = {
|
|
11
|
+
top: 0,
|
|
12
|
+
bottom: 0
|
|
13
|
+
}) => {
|
|
10
14
|
let top = Infinity,
|
|
11
15
|
left = Infinity,
|
|
12
16
|
bottom = -Infinity,
|
|
@@ -20,6 +24,8 @@ export const getBoundingBoxFromSelection = (view, from, to) => {
|
|
|
20
24
|
bottom = Math.max(bottom, coords.bottom);
|
|
21
25
|
right = Math.max(right, coords.right);
|
|
22
26
|
}
|
|
27
|
+
top = top - offset.top;
|
|
28
|
+
bottom = bottom - offset.bottom;
|
|
23
29
|
return {
|
|
24
30
|
top,
|
|
25
31
|
left,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import isEqual from 'lodash/isEqual';
|
|
2
2
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
3
3
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
4
5
|
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
|
+
import { getBoundingBoxFromSelection } from '../../ui/getBoundingBoxFromSelection';
|
|
5
8
|
var getSelectedRect = function getSelectedRect(selection) {
|
|
6
9
|
var $anchorCell = selection.$anchorCell,
|
|
7
10
|
$headCell = selection.$headCell;
|
|
@@ -50,7 +53,27 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
50
53
|
nodePos: nodePos
|
|
51
54
|
};
|
|
52
55
|
};
|
|
53
|
-
export var
|
|
56
|
+
export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
57
|
+
var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode;
|
|
58
|
+
var currentSelection = view.state.selection;
|
|
59
|
+
var toolbarDocking = fg('platform_editor_use_preferences_plugin') ? 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 : 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;
|
|
60
|
+
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');
|
|
61
|
+
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
|
|
62
|
+
var from = currentSelection.from,
|
|
63
|
+
to = currentSelection.to;
|
|
64
|
+
var text = view.state.doc.textBetween(from, to, '\n');
|
|
65
|
+
var coords = getBoundingBoxFromSelection(view, from, to, {
|
|
66
|
+
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
67
|
+
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
text: text,
|
|
71
|
+
from: from,
|
|
72
|
+
to: to,
|
|
73
|
+
coords: coords
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export var getSelectionAdfInfo = function getSelectionAdfInfo(state) {
|
|
54
77
|
var selection = state.selection;
|
|
55
78
|
var selectionInfo = {
|
|
56
79
|
selectedNode: selection.$from.node(),
|
|
@@ -7,11 +7,10 @@ import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
|
|
|
7
7
|
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
8
8
|
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
9
9
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
10
|
-
import {
|
|
10
|
+
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
11
11
|
import { SelectionExtensionActionTypes } from './types';
|
|
12
12
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
13
13
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
14
|
-
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
15
14
|
import { LegacyPrimaryToolbarComponent } from './ui/LegacyToolbarComponent';
|
|
16
15
|
import { selectionToolbar as _selectionToolbar } from './ui/selectionToolbar';
|
|
17
16
|
export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
@@ -107,11 +106,32 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
107
106
|
state = _editorViewRef$curren3.state,
|
|
108
107
|
dispatch = _editorViewRef$curren3.dispatch;
|
|
109
108
|
return _insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
|
|
109
|
+
},
|
|
110
|
+
getSelectionAdf: function getSelectionAdf() {
|
|
111
|
+
if (!editorViewRef.current) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
var state = editorViewRef.current.state;
|
|
115
|
+
var _getSelectionAdfInfo = getSelectionAdfInfo(state),
|
|
116
|
+
selectionRanges = _getSelectionAdfInfo.selectionRanges,
|
|
117
|
+
selectedNodeAdf = _getSelectionAdfInfo.selectedNodeAdf;
|
|
118
|
+
return {
|
|
119
|
+
selectedNodeAdf: selectedNodeAdf,
|
|
120
|
+
selectionRanges: selectionRanges
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
getSelectionText: function getSelectionText() {
|
|
124
|
+
if (!editorViewRef.current) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
var _getSelectionTextInfo = getSelectionTextInfo(editorViewRef.current, api),
|
|
128
|
+
text = _getSelectionTextInfo.text,
|
|
129
|
+
coords = _getSelectionTextInfo.coords;
|
|
130
|
+
return {
|
|
131
|
+
text: text,
|
|
132
|
+
coords: coords
|
|
133
|
+
};
|
|
110
134
|
}
|
|
111
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
112
|
-
// getSelectionAdf: () => {},
|
|
113
|
-
// NEXT PR: Implement this to return text, coords
|
|
114
|
-
// getSelectionText: () => {},
|
|
115
135
|
},
|
|
116
136
|
contentComponent: function contentComponent(_ref6) {
|
|
117
137
|
var _api$analytics;
|
|
@@ -161,23 +181,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
161
181
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
162
182
|
return;
|
|
163
183
|
}
|
|
164
|
-
var getSelection = function getSelection(view) {
|
|
165
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
166
|
-
var currentSelection = view.state.selection;
|
|
167
|
-
var from = currentSelection.from,
|
|
168
|
-
to = currentSelection.to;
|
|
169
|
-
var text = view.state.doc.textBetween(from, to, '\n');
|
|
170
|
-
var coords = getBoundingBoxFromSelection(view, from, to);
|
|
171
|
-
return {
|
|
172
|
-
text: text,
|
|
173
|
-
from: from,
|
|
174
|
-
to: to,
|
|
175
|
-
coords: coords
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
184
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
179
185
|
return function (extension) {
|
|
180
|
-
var selection =
|
|
186
|
+
var selection = getSelectionTextInfo(view, api);
|
|
181
187
|
if (extension.component) {
|
|
182
188
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
183
189
|
extension: extension,
|
|
@@ -189,11 +195,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
189
195
|
};
|
|
190
196
|
if (fg('platform_editor_selection_extension_api_v2')) {
|
|
191
197
|
var _extension$onClick, _api$core;
|
|
192
|
-
var
|
|
193
|
-
selectedNodeAdf =
|
|
194
|
-
selectionRanges =
|
|
195
|
-
selectedNode =
|
|
196
|
-
nodePos =
|
|
198
|
+
var _getSelectionAdfInfo2 = getSelectionAdfInfo(view.state),
|
|
199
|
+
selectedNodeAdf = _getSelectionAdfInfo2.selectedNodeAdf,
|
|
200
|
+
selectionRanges = _getSelectionAdfInfo2.selectionRanges,
|
|
201
|
+
selectedNode = _getSelectionAdfInfo2.selectedNode,
|
|
202
|
+
nodePos = _getSelectionAdfInfo2.nodePos;
|
|
197
203
|
onClickCallbackOptions = {
|
|
198
204
|
selectedNodeAdf: selectedNodeAdf,
|
|
199
205
|
selectionRanges: selectionRanges
|
|
@@ -218,7 +224,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
218
224
|
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
219
225
|
var _extension$isDisabled;
|
|
220
226
|
var disabled = (extension === null || extension === void 0 ? void 0 : extension.isDisabled) instanceof Function ? extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
221
|
-
selection: editorViewRef.current ?
|
|
227
|
+
selection: editorViewRef.current ? getSelectionTextInfo(editorViewRef.current, api) : undefined
|
|
222
228
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
223
229
|
return {
|
|
224
230
|
title: extension.name,
|
|
@@ -235,9 +241,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
235
241
|
};
|
|
236
242
|
var getConfigFromExtensionCallback = function getConfigFromExtensionCallback(extension) {
|
|
237
243
|
if (typeof extension === 'function') {
|
|
238
|
-
var
|
|
239
|
-
selectedNodeAdf =
|
|
240
|
-
selectionRanges =
|
|
244
|
+
var _getSelectionAdfInfo3 = getSelectionAdfInfo(state),
|
|
245
|
+
selectedNodeAdf = _getSelectionAdfInfo3.selectedNodeAdf,
|
|
246
|
+
selectionRanges = _getSelectionAdfInfo3.selectionRanges;
|
|
241
247
|
return extension({
|
|
242
248
|
selectedNodeAdf: selectedNodeAdf,
|
|
243
249
|
selectionRanges: selectionRanges
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
* @param view - The editor view instance.
|
|
5
5
|
* @param from - The starting position of the selection.
|
|
6
6
|
* @param to - The ending position of the selection.
|
|
7
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
|
|
7
8
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
8
9
|
*/
|
|
9
10
|
export var getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
|
|
11
|
+
var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
12
|
+
top: 0,
|
|
13
|
+
bottom: 0
|
|
14
|
+
};
|
|
10
15
|
var top = Infinity,
|
|
11
16
|
left = Infinity,
|
|
12
17
|
bottom = -Infinity,
|
|
@@ -20,6 +25,8 @@ export var getBoundingBoxFromSelection = function getBoundingBoxFromSelection(vi
|
|
|
20
25
|
bottom = Math.max(bottom, coords.bottom);
|
|
21
26
|
right = Math.max(right, coords.right);
|
|
22
27
|
}
|
|
28
|
+
top = top - offset.top;
|
|
29
|
+
bottom = bottom - offset.bottom;
|
|
23
30
|
return {
|
|
24
31
|
top: top,
|
|
25
32
|
left: left,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, } from './types';
|
|
3
|
+
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, SelectionTextResult, } from './types';
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { type EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
7
|
+
import type { SelectionExtensionSelectionInfo } from '../../types';
|
|
4
8
|
import { type SelectionRange } from '../../types';
|
|
5
9
|
type SelectionInfo = {
|
|
6
10
|
selectedNodeAdf: ADFEntity;
|
|
@@ -8,6 +12,7 @@ type SelectionInfo = {
|
|
|
8
12
|
selectedNode: PMNode;
|
|
9
13
|
nodePos: number;
|
|
10
14
|
};
|
|
11
|
-
export declare const
|
|
15
|
+
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
16
|
+
export declare const getSelectionAdfInfo: (state: EditorState) => SelectionInfo;
|
|
12
17
|
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
13
18
|
export {};
|
|
@@ -4,13 +4,15 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
|
4
4
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
|
-
import type {
|
|
7
|
+
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
|
|
8
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
9
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
10
11
|
dependencies: [
|
|
11
12
|
OptionalPlugin<AnalyticsPlugin>,
|
|
12
13
|
OptionalPlugin<EditorViewModePlugin>,
|
|
13
14
|
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
15
|
+
OptionalPlugin<UserPreferencesPlugin>,
|
|
14
16
|
SelectionToolbarPlugin
|
|
15
17
|
];
|
|
16
18
|
sharedState: SelectionExtensionPluginState | null;
|
|
@@ -28,5 +30,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
28
30
|
};
|
|
29
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
30
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
|
+
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getSelectionText: () => SelectionTextResult;
|
|
31
35
|
};
|
|
32
36
|
}>;
|
|
@@ -75,6 +75,10 @@ export type SelectionExtensionCoords = {
|
|
|
75
75
|
top: number;
|
|
76
76
|
bottom: number;
|
|
77
77
|
};
|
|
78
|
+
export type BoundingBoxOffset = {
|
|
79
|
+
top: number;
|
|
80
|
+
bottom: number;
|
|
81
|
+
};
|
|
78
82
|
export type InsertPosition = {
|
|
79
83
|
pointer: string;
|
|
80
84
|
from?: number;
|
|
@@ -118,6 +122,14 @@ export type ReplaceWithAdfResult = {
|
|
|
118
122
|
export type InsertAdfAtEndOfDocResult = {
|
|
119
123
|
status: 'success' | 'failed';
|
|
120
124
|
};
|
|
125
|
+
export type SelectionAdfResult = {
|
|
126
|
+
selectedNodeAdf?: ADFEntity;
|
|
127
|
+
selectionRanges?: SelectionRange[];
|
|
128
|
+
} | null;
|
|
129
|
+
export type SelectionTextResult = {
|
|
130
|
+
text: string;
|
|
131
|
+
coords: SelectionExtensionCoords;
|
|
132
|
+
} | null;
|
|
121
133
|
export type ExtensionSource = 'first-party' | 'external';
|
|
122
134
|
export type ExtensionConfiguration = {
|
|
123
135
|
key: string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { SelectionExtensionCoords } from '../types';
|
|
2
|
+
import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Calculates the bounding box coordinates of a text selection within an editor view.
|
|
5
5
|
*
|
|
6
6
|
* @param view - The editor view instance.
|
|
7
7
|
* @param from - The starting position of the selection.
|
|
8
8
|
* @param to - The ending position of the selection.
|
|
9
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
|
|
9
10
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
10
11
|
*/
|
|
11
|
-
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number) => SelectionExtensionCoords;
|
|
12
|
+
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, } from './types';
|
|
3
|
+
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, SelectionTextResult, } from './types';
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { type EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
7
|
+
import type { SelectionExtensionSelectionInfo } from '../../types';
|
|
4
8
|
import { type SelectionRange } from '../../types';
|
|
5
9
|
type SelectionInfo = {
|
|
6
10
|
selectedNodeAdf: ADFEntity;
|
|
@@ -8,6 +12,7 @@ type SelectionInfo = {
|
|
|
8
12
|
selectedNode: PMNode;
|
|
9
13
|
nodePos: number;
|
|
10
14
|
};
|
|
11
|
-
export declare const
|
|
15
|
+
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
16
|
+
export declare const getSelectionAdfInfo: (state: EditorState) => SelectionInfo;
|
|
12
17
|
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
13
18
|
export {};
|
|
@@ -4,13 +4,15 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
|
4
4
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
|
-
import type {
|
|
7
|
+
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
|
|
8
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
9
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
10
11
|
dependencies: [
|
|
11
12
|
OptionalPlugin<AnalyticsPlugin>,
|
|
12
13
|
OptionalPlugin<EditorViewModePlugin>,
|
|
13
14
|
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
15
|
+
OptionalPlugin<UserPreferencesPlugin>,
|
|
14
16
|
SelectionToolbarPlugin
|
|
15
17
|
];
|
|
16
18
|
sharedState: SelectionExtensionPluginState | null;
|
|
@@ -28,5 +30,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
28
30
|
};
|
|
29
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
30
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
|
+
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getSelectionText: () => SelectionTextResult;
|
|
31
35
|
};
|
|
32
36
|
}>;
|
|
@@ -75,6 +75,10 @@ export type SelectionExtensionCoords = {
|
|
|
75
75
|
top: number;
|
|
76
76
|
bottom: number;
|
|
77
77
|
};
|
|
78
|
+
export type BoundingBoxOffset = {
|
|
79
|
+
top: number;
|
|
80
|
+
bottom: number;
|
|
81
|
+
};
|
|
78
82
|
export type InsertPosition = {
|
|
79
83
|
pointer: string;
|
|
80
84
|
from?: number;
|
|
@@ -118,6 +122,14 @@ export type ReplaceWithAdfResult = {
|
|
|
118
122
|
export type InsertAdfAtEndOfDocResult = {
|
|
119
123
|
status: 'success' | 'failed';
|
|
120
124
|
};
|
|
125
|
+
export type SelectionAdfResult = {
|
|
126
|
+
selectedNodeAdf?: ADFEntity;
|
|
127
|
+
selectionRanges?: SelectionRange[];
|
|
128
|
+
} | null;
|
|
129
|
+
export type SelectionTextResult = {
|
|
130
|
+
text: string;
|
|
131
|
+
coords: SelectionExtensionCoords;
|
|
132
|
+
} | null;
|
|
121
133
|
export type ExtensionSource = 'first-party' | 'external';
|
|
122
134
|
export type ExtensionConfiguration = {
|
|
123
135
|
key: string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { SelectionExtensionCoords } from '../types';
|
|
2
|
+
import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Calculates the bounding box coordinates of a text selection within an editor view.
|
|
5
5
|
*
|
|
6
6
|
* @param view - The editor view instance.
|
|
7
7
|
* @param from - The starting position of the selection.
|
|
8
8
|
* @param to - The ending position of the selection.
|
|
9
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
|
|
9
10
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
10
11
|
*/
|
|
11
|
-
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number) => SelectionExtensionCoords;
|
|
12
|
+
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.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",
|
|
@@ -41,19 +41,21 @@
|
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
|
|
42
42
|
"@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
|
|
43
43
|
"@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
|
|
44
|
+
"@atlaskit/editor-plugin-user-preferences": "^1.2.0",
|
|
44
45
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
46
|
+
"@atlaskit/editor-shared-styles": "^3.5.0",
|
|
45
47
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
46
48
|
"@atlaskit/icon": "^27.8.0",
|
|
47
49
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
48
50
|
"@atlaskit/primitives": "^14.11.0",
|
|
49
|
-
"@atlaskit/tmp-editor-statsig": "^9.
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^9.21.0",
|
|
50
52
|
"@babel/runtime": "^7.0.0",
|
|
51
53
|
"lodash": "^4.17.21",
|
|
52
54
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
53
55
|
"uuid": "^3.1.0"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
|
-
"@atlaskit/editor-common": "^107.
|
|
58
|
+
"@atlaskit/editor-common": "^107.16.0",
|
|
57
59
|
"react": "^18.2.0"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
@@ -110,6 +112,9 @@
|
|
|
110
112
|
},
|
|
111
113
|
"platform_editor_selection_extension_api_v2": {
|
|
112
114
|
"type": "boolean"
|
|
115
|
+
},
|
|
116
|
+
"platform_editor_use_preferences_plugin": {
|
|
117
|
+
"type": "boolean"
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
}
|