@atlaskit/editor-plugin-selection-extension 3.4.2 → 3.4.4
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 +13 -0
- package/dist/cjs/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/cjs/pm-plugins/utils/index.js +25 -2
- package/dist/cjs/selectionExtensionPlugin.js +35 -37
- package/dist/es2019/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/es2019/pm-plugins/utils/index.js +28 -1
- package/dist/es2019/selectionExtensionPlugin.js +34 -36
- package/dist/esm/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/esm/pm-plugins/utils/index.js +24 -1
- package/dist/esm/selectionExtensionPlugin.js +36 -38
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/actions.d.ts +1 -1
- package/dist/types/pm-plugins/main.d.ts +9 -9
- package/dist/types/pm-plugins/utils/index.d.ts +6 -1
- package/dist/types/selectionExtensionPluginType.d.ts +3 -1
- package/dist/types/types/index.d.ts +8 -1
- package/dist/types/ui/extensions.d.ts +1 -1
- package/dist/types/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +6 -6
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +9 -9
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +6 -1
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +3 -1
- package/dist/types-ts4.5/types/index.d.ts +8 -1
- package/dist/types-ts4.5/ui/extensions.d.ts +1 -1
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +6 -6
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 3.4.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`86db72552d6a0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86db72552d6a0) -
|
|
14
|
+
Add Apis to get selection adf and text information
|
|
15
|
+
|
|
3
16
|
## 3.4.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -20,6 +20,7 @@ function getOffsetByPath(root, pos, pointer) {
|
|
|
20
20
|
|
|
21
21
|
for (var i = 1; i < len; i++) {
|
|
22
22
|
var key = parts[i];
|
|
23
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
23
24
|
if (ref instanceof _model.Fragment && /^[0-9]+$/.test(key)) {
|
|
24
25
|
var index = parseInt(key, 10);
|
|
25
26
|
if (index >= ref.childCount) {
|
|
@@ -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(),
|
|
@@ -9,7 +9,6 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
|
-
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
13
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
13
|
var _actions = require("./pm-plugins/actions");
|
|
15
14
|
var _insertAdfAtEndOfDoc2 = require("./pm-plugins/actions/insertAdfAtEndOfDoc");
|
|
@@ -19,7 +18,6 @@ var _utils = require("./pm-plugins/utils");
|
|
|
19
18
|
var _types = require("./types");
|
|
20
19
|
var _SelectionExtensionComponentWrapper = require("./ui/extension/SelectionExtensionComponentWrapper");
|
|
21
20
|
var _extensions = require("./ui/extensions");
|
|
22
|
-
var _getBoundingBoxFromSelection = require("./ui/getBoundingBoxFromSelection");
|
|
23
21
|
var _LegacyToolbarComponent = require("./ui/LegacyToolbarComponent");
|
|
24
22
|
var _selectionToolbar2 = require("./ui/selectionToolbar");
|
|
25
23
|
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
@@ -115,11 +113,32 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
115
113
|
state = _editorViewRef$curren3.state,
|
|
116
114
|
dispatch = _editorViewRef$curren3.dispatch;
|
|
117
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
|
+
};
|
|
118
141
|
}
|
|
119
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
120
|
-
// getSelectionAdf: () => {},
|
|
121
|
-
// NEXT PR: Implement this to return text, coords
|
|
122
|
-
// getSelectionText: () => {},
|
|
123
142
|
},
|
|
124
143
|
contentComponent: function contentComponent(_ref6) {
|
|
125
144
|
var _api$analytics;
|
|
@@ -169,30 +188,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
169
188
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
170
189
|
return;
|
|
171
190
|
}
|
|
172
|
-
var getSelection = function getSelection(view) {
|
|
173
|
-
var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode2;
|
|
174
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
175
|
-
var currentSelection = view.state.selection;
|
|
176
|
-
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;
|
|
177
|
-
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');
|
|
178
|
-
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && (0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2');
|
|
179
|
-
var from = currentSelection.from,
|
|
180
|
-
to = currentSelection.to;
|
|
181
|
-
var text = view.state.doc.textBetween(from, to, '\n');
|
|
182
|
-
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to, {
|
|
183
|
-
top: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0,
|
|
184
|
-
bottom: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0
|
|
185
|
-
});
|
|
186
|
-
return {
|
|
187
|
-
text: text,
|
|
188
|
-
from: from,
|
|
189
|
-
to: to,
|
|
190
|
-
coords: coords
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
191
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
194
192
|
return function (extension) {
|
|
195
|
-
var selection =
|
|
193
|
+
var selection = (0, _utils.getSelectionTextInfo)(view, api);
|
|
196
194
|
if (extension.component) {
|
|
197
195
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
198
196
|
extension: extension,
|
|
@@ -204,11 +202,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
204
202
|
};
|
|
205
203
|
if ((0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2')) {
|
|
206
204
|
var _extension$onClick, _api$core;
|
|
207
|
-
var
|
|
208
|
-
selectedNodeAdf =
|
|
209
|
-
selectionRanges =
|
|
210
|
-
selectedNode =
|
|
211
|
-
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;
|
|
212
210
|
onClickCallbackOptions = {
|
|
213
211
|
selectedNodeAdf: selectedNodeAdf,
|
|
214
212
|
selectionRanges: selectionRanges
|
|
@@ -233,7 +231,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
233
231
|
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
234
232
|
var _extension$isDisabled;
|
|
235
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, {
|
|
236
|
-
selection: editorViewRef.current ?
|
|
234
|
+
selection: editorViewRef.current ? (0, _utils.getSelectionTextInfo)(editorViewRef.current, api) : undefined
|
|
237
235
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
238
236
|
return {
|
|
239
237
|
title: extension.name,
|
|
@@ -250,9 +248,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
250
248
|
};
|
|
251
249
|
var getConfigFromExtensionCallback = function getConfigFromExtensionCallback(extension) {
|
|
252
250
|
if (typeof extension === 'function') {
|
|
253
|
-
var
|
|
254
|
-
selectedNodeAdf =
|
|
255
|
-
selectionRanges =
|
|
251
|
+
var _getSelectionAdfInfo3 = (0, _utils.getSelectionAdfInfo)(state),
|
|
252
|
+
selectedNodeAdf = _getSelectionAdfInfo3.selectedNodeAdf,
|
|
253
|
+
selectionRanges = _getSelectionAdfInfo3.selectionRanges;
|
|
256
254
|
return extension({
|
|
257
255
|
selectedNodeAdf: selectedNodeAdf,
|
|
258
256
|
selectionRanges: selectionRanges
|
|
@@ -13,6 +13,7 @@ export function getOffsetByPath(root, pos, pointer, from = 0, to) {
|
|
|
13
13
|
|
|
14
14
|
for (let i = 1; i < len; i++) {
|
|
15
15
|
const key = parts[i];
|
|
16
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
16
17
|
if (ref instanceof Fragment && /^[0-9]+$/u.test(key)) {
|
|
17
18
|
let index = parseInt(key, 10);
|
|
18
19
|
if (index >= ref.childCount) {
|
|
@@ -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(),
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
-
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
5
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { insertSmartLinks } from './pm-plugins/actions';
|
|
7
6
|
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
8
7
|
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
9
8
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
10
|
-
import {
|
|
9
|
+
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
11
10
|
import { SelectionExtensionActionTypes } from './types';
|
|
12
11
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
13
12
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
14
|
-
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
15
13
|
import { LegacyPrimaryToolbarComponent } from './ui/LegacyToolbarComponent';
|
|
16
14
|
import { selectionToolbar } from './ui/selectionToolbar';
|
|
17
15
|
export const selectionExtensionPlugin = ({
|
|
@@ -105,11 +103,36 @@ export const selectionExtensionPlugin = ({
|
|
|
105
103
|
dispatch
|
|
106
104
|
} = editorViewRef.current;
|
|
107
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
|
+
};
|
|
108
135
|
}
|
|
109
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
110
|
-
// getSelectionAdf: () => {},
|
|
111
|
-
// NEXT PR: Implement this to return text, coords
|
|
112
|
-
// getSelectionText: () => {},
|
|
113
136
|
},
|
|
114
137
|
contentComponent: ({
|
|
115
138
|
editorView
|
|
@@ -162,33 +185,8 @@ export const selectionExtensionPlugin = ({
|
|
|
162
185
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
163
186
|
return;
|
|
164
187
|
}
|
|
165
|
-
const getSelection = view => {
|
|
166
|
-
var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3, _api$editorViewMode2, _api$editorViewMode2$;
|
|
167
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
168
|
-
const {
|
|
169
|
-
selection: currentSelection
|
|
170
|
-
} = view.state;
|
|
171
|
-
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;
|
|
172
|
-
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');
|
|
173
|
-
const shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
|
|
174
|
-
const {
|
|
175
|
-
from,
|
|
176
|
-
to
|
|
177
|
-
} = currentSelection;
|
|
178
|
-
const text = view.state.doc.textBetween(from, to, '\n');
|
|
179
|
-
const coords = getBoundingBoxFromSelection(view, from, to, {
|
|
180
|
-
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
181
|
-
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
182
|
-
});
|
|
183
|
-
return {
|
|
184
|
-
text,
|
|
185
|
-
from,
|
|
186
|
-
to,
|
|
187
|
-
coords
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
188
|
const handleOnExtensionClick = view => extension => {
|
|
191
|
-
const selection =
|
|
189
|
+
const selection = getSelectionTextInfo(view, api);
|
|
192
190
|
if (extension.component) {
|
|
193
191
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
194
192
|
extension,
|
|
@@ -205,7 +203,7 @@ export const selectionExtensionPlugin = ({
|
|
|
205
203
|
selectionRanges,
|
|
206
204
|
selectedNode,
|
|
207
205
|
nodePos
|
|
208
|
-
} =
|
|
206
|
+
} = getSelectionAdfInfo(view.state);
|
|
209
207
|
onClickCallbackOptions = {
|
|
210
208
|
selectedNodeAdf,
|
|
211
209
|
selectionRanges
|
|
@@ -230,7 +228,7 @@ export const selectionExtensionPlugin = ({
|
|
|
230
228
|
const convertExtensionToDropdownMenuItem = (extension, rank) => {
|
|
231
229
|
var _extension$isDisabled;
|
|
232
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, {
|
|
233
|
-
selection: editorViewRef.current ?
|
|
231
|
+
selection: editorViewRef.current ? getSelectionTextInfo(editorViewRef.current, api) : undefined
|
|
234
232
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
235
233
|
return {
|
|
236
234
|
title: extension.name,
|
|
@@ -250,7 +248,7 @@ export const selectionExtensionPlugin = ({
|
|
|
250
248
|
const {
|
|
251
249
|
selectedNodeAdf,
|
|
252
250
|
selectionRanges
|
|
253
|
-
} =
|
|
251
|
+
} = getSelectionAdfInfo(state);
|
|
254
252
|
return extension({
|
|
255
253
|
selectedNodeAdf,
|
|
256
254
|
selectionRanges
|
|
@@ -15,6 +15,7 @@ export function getOffsetByPath(root, pos, pointer) {
|
|
|
15
15
|
|
|
16
16
|
for (var i = 1; i < len; i++) {
|
|
17
17
|
var key = parts[i];
|
|
18
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
18
19
|
if (ref instanceof Fragment && /^[0-9]+$/.test(key)) {
|
|
19
20
|
var index = parseInt(key, 10);
|
|
20
21
|
if (index >= ref.childCount) {
|
|
@@ -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(),
|
|
@@ -2,17 +2,15 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
6
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
6
|
import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
|
|
8
7
|
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
9
8
|
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
10
9
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
11
|
-
import {
|
|
10
|
+
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
12
11
|
import { SelectionExtensionActionTypes } from './types';
|
|
13
12
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
14
13
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
15
|
-
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
16
14
|
import { LegacyPrimaryToolbarComponent } from './ui/LegacyToolbarComponent';
|
|
17
15
|
import { selectionToolbar as _selectionToolbar } from './ui/selectionToolbar';
|
|
18
16
|
export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
@@ -108,11 +106,32 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
108
106
|
state = _editorViewRef$curren3.state,
|
|
109
107
|
dispatch = _editorViewRef$curren3.dispatch;
|
|
110
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
|
+
};
|
|
111
134
|
}
|
|
112
|
-
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
113
|
-
// getSelectionAdf: () => {},
|
|
114
|
-
// NEXT PR: Implement this to return text, coords
|
|
115
|
-
// getSelectionText: () => {},
|
|
116
135
|
},
|
|
117
136
|
contentComponent: function contentComponent(_ref6) {
|
|
118
137
|
var _api$analytics;
|
|
@@ -162,30 +181,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
162
181
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
163
182
|
return;
|
|
164
183
|
}
|
|
165
|
-
var getSelection = function getSelection(view) {
|
|
166
|
-
var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode2;
|
|
167
|
-
// ensure the same document state is applied to editor view to avoid mismatches
|
|
168
|
-
var currentSelection = view.state.selection;
|
|
169
|
-
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;
|
|
170
|
-
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');
|
|
171
|
-
var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
|
|
172
|
-
var from = currentSelection.from,
|
|
173
|
-
to = currentSelection.to;
|
|
174
|
-
var text = view.state.doc.textBetween(from, to, '\n');
|
|
175
|
-
var coords = getBoundingBoxFromSelection(view, from, to, {
|
|
176
|
-
top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
|
|
177
|
-
bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
text: text,
|
|
181
|
-
from: from,
|
|
182
|
-
to: to,
|
|
183
|
-
coords: coords
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
184
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
187
185
|
return function (extension) {
|
|
188
|
-
var selection =
|
|
186
|
+
var selection = getSelectionTextInfo(view, api);
|
|
189
187
|
if (extension.component) {
|
|
190
188
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
191
189
|
extension: extension,
|
|
@@ -197,11 +195,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
197
195
|
};
|
|
198
196
|
if (fg('platform_editor_selection_extension_api_v2')) {
|
|
199
197
|
var _extension$onClick, _api$core;
|
|
200
|
-
var
|
|
201
|
-
selectedNodeAdf =
|
|
202
|
-
selectionRanges =
|
|
203
|
-
selectedNode =
|
|
204
|
-
nodePos =
|
|
198
|
+
var _getSelectionAdfInfo2 = getSelectionAdfInfo(view.state),
|
|
199
|
+
selectedNodeAdf = _getSelectionAdfInfo2.selectedNodeAdf,
|
|
200
|
+
selectionRanges = _getSelectionAdfInfo2.selectionRanges,
|
|
201
|
+
selectedNode = _getSelectionAdfInfo2.selectedNode,
|
|
202
|
+
nodePos = _getSelectionAdfInfo2.nodePos;
|
|
205
203
|
onClickCallbackOptions = {
|
|
206
204
|
selectedNodeAdf: selectedNodeAdf,
|
|
207
205
|
selectionRanges: selectionRanges
|
|
@@ -226,7 +224,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
226
224
|
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
227
225
|
var _extension$isDisabled;
|
|
228
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, {
|
|
229
|
-
selection: editorViewRef.current ?
|
|
227
|
+
selection: editorViewRef.current ? getSelectionTextInfo(editorViewRef.current, api) : undefined
|
|
230
228
|
}) : extension === null || extension === void 0 ? void 0 : extension.isDisabled;
|
|
231
229
|
return {
|
|
232
230
|
title: extension.name,
|
|
@@ -243,9 +241,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
243
241
|
};
|
|
244
242
|
var getConfigFromExtensionCallback = function getConfigFromExtensionCallback(extension) {
|
|
245
243
|
if (typeof extension === 'function') {
|
|
246
|
-
var
|
|
247
|
-
selectedNodeAdf =
|
|
248
|
-
selectionRanges =
|
|
244
|
+
var _getSelectionAdfInfo3 = getSelectionAdfInfo(state),
|
|
245
|
+
selectedNodeAdf = _getSelectionAdfInfo3.selectedNodeAdf,
|
|
246
|
+
selectionRanges = _getSelectionAdfInfo3.selectionRanges;
|
|
249
247
|
return extension({
|
|
250
248
|
selectedNodeAdf: selectedNodeAdf,
|
|
251
249
|
selectionRanges: selectionRanges
|
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';
|
|
@@ -3,6 +3,6 @@ import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
5
|
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status:
|
|
6
|
+
status: "success" | "error";
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -4,10 +4,10 @@ import { type SelectionExtensionPluginState } from '../types';
|
|
|
4
4
|
export declare const selectionExtensionPluginKey: PluginKey<SelectionExtensionPluginState>;
|
|
5
5
|
export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginState | {
|
|
6
6
|
activeExtension: any;
|
|
7
|
-
selectedNode?: import("prosemirror-model").Node
|
|
8
|
-
nodePos?: number
|
|
9
|
-
startTrackChanges?: boolean
|
|
10
|
-
docChangedAfterClick?: boolean
|
|
7
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
8
|
+
nodePos?: number;
|
|
9
|
+
startTrackChanges?: boolean;
|
|
10
|
+
docChangedAfterClick?: boolean;
|
|
11
11
|
} | {
|
|
12
12
|
selectedNode: any;
|
|
13
13
|
nodePos: any;
|
|
@@ -17,15 +17,15 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
17
17
|
extension: import("../types").SelectionExtension;
|
|
18
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
19
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
} | {
|
|
22
22
|
startTrackChanges: any;
|
|
23
23
|
activeExtension?: {
|
|
24
24
|
extension: import("../types").SelectionExtension;
|
|
25
25
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
26
|
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
-
}
|
|
28
|
-
selectedNode?: import("prosemirror-model").Node
|
|
29
|
-
nodePos?: number
|
|
30
|
-
docChangedAfterClick?: boolean
|
|
27
|
+
};
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
29
|
+
nodePos?: number;
|
|
30
|
+
docChangedAfterClick?: boolean;
|
|
31
31
|
}>;
|
|
@@ -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 {};
|
|
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
-
import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
|
|
9
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
10
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
11
11
|
dependencies: [
|
|
@@ -30,5 +30,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
30
30
|
};
|
|
31
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
|
+
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getSelectionText: () => SelectionTextResult;
|
|
33
35
|
};
|
|
34
36
|
}>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
3
2
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
3
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
@@ -122,6 +121,14 @@ export type ReplaceWithAdfResult = {
|
|
|
122
121
|
export type InsertAdfAtEndOfDocResult = {
|
|
123
122
|
status: 'success' | 'failed';
|
|
124
123
|
};
|
|
124
|
+
export type SelectionAdfResult = {
|
|
125
|
+
selectedNodeAdf?: ADFEntity;
|
|
126
|
+
selectionRanges?: SelectionRange[];
|
|
127
|
+
} | null;
|
|
128
|
+
export type SelectionTextResult = {
|
|
129
|
+
text: string;
|
|
130
|
+
coords: SelectionExtensionCoords;
|
|
131
|
+
} | null;
|
|
125
132
|
export type ExtensionSource = 'first-party' | 'external';
|
|
126
133
|
export type ExtensionConfiguration = {
|
|
127
134
|
key: string;
|
|
@@ -12,7 +12,7 @@ export type ToolbarItemExtension = {
|
|
|
12
12
|
* @returns Array of ToolbarItemExtension objects
|
|
13
13
|
* @example
|
|
14
14
|
*/
|
|
15
|
-
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType:
|
|
15
|
+
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: "primaryToolbar" | "inlineToolbar") => ToolbarItemExtension[];
|
|
16
16
|
/**
|
|
17
17
|
* From the full list of extensions, extract only those that have a menu item configuration
|
|
18
18
|
* for the specified source (either 'first-party' or 'external').
|
|
@@ -13,18 +13,18 @@ export type SelectionExtensionDropdownMenuProps = {
|
|
|
13
13
|
} & WrappedComponentProps;
|
|
14
14
|
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
15
15
|
items: MenuItemsType;
|
|
16
|
-
onItemActivated?: (
|
|
16
|
+
onItemActivated?: (attrs: {
|
|
17
17
|
item: MenuItem;
|
|
18
18
|
shouldCloseMenu?: boolean;
|
|
19
|
-
}) => void
|
|
20
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
19
|
+
}) => void;
|
|
20
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
21
21
|
} & WrappedComponentProps>> & {
|
|
22
22
|
WrappedComponent: React.ComponentType<{
|
|
23
23
|
items: MenuItemsType;
|
|
24
|
-
onItemActivated?: (
|
|
24
|
+
onItemActivated?: (attrs: {
|
|
25
25
|
item: MenuItem;
|
|
26
26
|
shouldCloseMenu?: boolean;
|
|
27
|
-
}) => void
|
|
28
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
27
|
+
}) => void;
|
|
28
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
29
29
|
} & WrappedComponentProps>;
|
|
30
30
|
};
|
|
@@ -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';
|
|
@@ -3,6 +3,6 @@ import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
5
|
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status:
|
|
6
|
+
status: "success" | "error";
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -4,10 +4,10 @@ import { type SelectionExtensionPluginState } from '../types';
|
|
|
4
4
|
export declare const selectionExtensionPluginKey: PluginKey<SelectionExtensionPluginState>;
|
|
5
5
|
export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginState | {
|
|
6
6
|
activeExtension: any;
|
|
7
|
-
selectedNode?: import("prosemirror-model").Node
|
|
8
|
-
nodePos?: number
|
|
9
|
-
startTrackChanges?: boolean
|
|
10
|
-
docChangedAfterClick?: boolean
|
|
7
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
8
|
+
nodePos?: number;
|
|
9
|
+
startTrackChanges?: boolean;
|
|
10
|
+
docChangedAfterClick?: boolean;
|
|
11
11
|
} | {
|
|
12
12
|
selectedNode: any;
|
|
13
13
|
nodePos: any;
|
|
@@ -17,15 +17,15 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
17
17
|
extension: import("../types").SelectionExtension;
|
|
18
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
19
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
} | {
|
|
22
22
|
startTrackChanges: any;
|
|
23
23
|
activeExtension?: {
|
|
24
24
|
extension: import("../types").SelectionExtension;
|
|
25
25
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
26
|
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
-
}
|
|
28
|
-
selectedNode?: import("prosemirror-model").Node
|
|
29
|
-
nodePos?: number
|
|
30
|
-
docChangedAfterClick?: boolean
|
|
27
|
+
};
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
29
|
+
nodePos?: number;
|
|
30
|
+
docChangedAfterClick?: boolean;
|
|
31
31
|
}>;
|
|
@@ -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 {};
|
|
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
-
import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
|
|
9
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
10
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
11
11
|
dependencies: [
|
|
@@ -30,5 +30,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
30
30
|
};
|
|
31
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
|
+
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getSelectionText: () => SelectionTextResult;
|
|
33
35
|
};
|
|
34
36
|
}>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
3
2
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
3
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
@@ -122,6 +121,14 @@ export type ReplaceWithAdfResult = {
|
|
|
122
121
|
export type InsertAdfAtEndOfDocResult = {
|
|
123
122
|
status: 'success' | 'failed';
|
|
124
123
|
};
|
|
124
|
+
export type SelectionAdfResult = {
|
|
125
|
+
selectedNodeAdf?: ADFEntity;
|
|
126
|
+
selectionRanges?: SelectionRange[];
|
|
127
|
+
} | null;
|
|
128
|
+
export type SelectionTextResult = {
|
|
129
|
+
text: string;
|
|
130
|
+
coords: SelectionExtensionCoords;
|
|
131
|
+
} | null;
|
|
125
132
|
export type ExtensionSource = 'first-party' | 'external';
|
|
126
133
|
export type ExtensionConfiguration = {
|
|
127
134
|
key: string;
|
|
@@ -12,7 +12,7 @@ export type ToolbarItemExtension = {
|
|
|
12
12
|
* @returns Array of ToolbarItemExtension objects
|
|
13
13
|
* @example
|
|
14
14
|
*/
|
|
15
|
-
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType:
|
|
15
|
+
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: "primaryToolbar" | "inlineToolbar") => ToolbarItemExtension[];
|
|
16
16
|
/**
|
|
17
17
|
* From the full list of extensions, extract only those that have a menu item configuration
|
|
18
18
|
* for the specified source (either 'first-party' or 'external').
|
|
@@ -13,18 +13,18 @@ export type SelectionExtensionDropdownMenuProps = {
|
|
|
13
13
|
} & WrappedComponentProps;
|
|
14
14
|
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
15
15
|
items: MenuItemsType;
|
|
16
|
-
onItemActivated?: (
|
|
16
|
+
onItemActivated?: (attrs: {
|
|
17
17
|
item: MenuItem;
|
|
18
18
|
shouldCloseMenu?: boolean;
|
|
19
|
-
}) => void
|
|
20
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
19
|
+
}) => void;
|
|
20
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
21
21
|
} & WrappedComponentProps>> & {
|
|
22
22
|
WrappedComponent: React.ComponentType<{
|
|
23
23
|
items: MenuItemsType;
|
|
24
|
-
onItemActivated?: (
|
|
24
|
+
onItemActivated?: (attrs: {
|
|
25
25
|
item: MenuItem;
|
|
26
26
|
shouldCloseMenu?: boolean;
|
|
27
|
-
}) => void
|
|
28
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
27
|
+
}) => void;
|
|
28
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
29
29
|
} & WrappedComponentProps>;
|
|
30
30
|
};
|
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.4",
|
|
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,27 +35,27 @@
|
|
|
35
35
|
".": "./src/index.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@atlaskit/adf-utils": "^19.
|
|
38
|
+
"@atlaskit/adf-utils": "^19.21.0",
|
|
39
39
|
"@atlaskit/editor-json-transformer": "^8.25.0",
|
|
40
40
|
"@atlaskit/editor-plugin-analytics": "^3.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
|
|
42
42
|
"@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
|
|
43
|
-
"@atlaskit/editor-plugin-selection-toolbar": "^4.
|
|
43
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^4.3.0",
|
|
44
44
|
"@atlaskit/editor-plugin-user-preferences": "^1.2.0",
|
|
45
45
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
46
|
-
"@atlaskit/editor-shared-styles": "^3.
|
|
46
|
+
"@atlaskit/editor-shared-styles": "^3.6.0",
|
|
47
47
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
48
|
-
"@atlaskit/icon": "^27.
|
|
48
|
+
"@atlaskit/icon": "^27.12.0",
|
|
49
49
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
50
50
|
"@atlaskit/primitives": "^14.11.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^10.0.0",
|
|
52
52
|
"@babel/runtime": "^7.0.0",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
54
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
55
55
|
"uuid": "^3.1.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@atlaskit/editor-common": "^107.
|
|
58
|
+
"@atlaskit/editor-common": "^107.25.0",
|
|
59
59
|
"react": "^18.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"@atlaskit/visual-regression": "workspace:^",
|
|
66
66
|
"@testing-library/react": "^13.4.0",
|
|
67
67
|
"react-dom": "^18.2.0",
|
|
68
|
-
"typescript": "~5.4.2",
|
|
69
68
|
"wait-for-expect": "^1.2.0"
|
|
70
69
|
},
|
|
71
70
|
"techstack": {
|