@atlaskit/editor-plugin-selection-extension 2.1.5 → 2.1.6
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 +6 -0
- package/dist/cjs/selectionExtensionPlugin.js +84 -36
- package/dist/es2019/selectionExtensionPlugin.js +73 -30
- package/dist/esm/selectionExtensionPlugin.js +85 -37
- package/dist/types/selectionExtensionPluginType.d.ts +4 -4
- package/dist/types/types/index.d.ts +27 -12
- package/dist/types/ui/toolbar/SelectionExtensionItems.d.ts +3 -3
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +4 -4
- package/dist/types-ts4.5/types/index.d.ts +27 -12
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionItems.d.ts +3 -3
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.selectionExtensionPlugin = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
8
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
11
|
var _main = require("./pm-plugins/main");
|
|
10
12
|
var _SelectionExtensionComponentWrapper = require("./ui/extension/SelectionExtensionComponentWrapper");
|
|
11
13
|
var _getBoundingBoxFromSelection = require("./ui/getBoundingBoxFromSelection");
|
|
12
|
-
var _SelectionExtensionItems = require("./ui/toolbar/SelectionExtensionItems");
|
|
13
14
|
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
14
15
|
var api = _ref.api,
|
|
15
16
|
config = _ref.config;
|
|
17
|
+
var editorViewRef = {
|
|
18
|
+
current: null
|
|
19
|
+
};
|
|
16
20
|
return {
|
|
17
21
|
name: 'selectionExtension',
|
|
18
22
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -63,7 +67,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
63
67
|
*
|
|
64
68
|
* Check whether plugin contains any selection extensions
|
|
65
69
|
*/
|
|
66
|
-
if (!extensions
|
|
70
|
+
if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -99,23 +103,22 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
99
103
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
106
|
+
var getSelection = function getSelection(view) {
|
|
107
|
+
var currentSelection = state.selection;
|
|
108
|
+
var from = currentSelection.from,
|
|
109
|
+
to = currentSelection.to;
|
|
110
|
+
var text = state.doc.textBetween(from, to, '\n');
|
|
111
|
+
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to);
|
|
112
|
+
return {
|
|
113
|
+
text: text,
|
|
114
|
+
from: from,
|
|
115
|
+
to: to,
|
|
116
|
+
coords: coords
|
|
117
|
+
};
|
|
118
|
+
};
|
|
102
119
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
103
120
|
return function (extension) {
|
|
104
|
-
var
|
|
105
|
-
var from = currentSelection.from,
|
|
106
|
-
to = currentSelection.to;
|
|
107
|
-
var text = state.doc.textBetween(from, to, '\n');
|
|
108
|
-
var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to);
|
|
109
|
-
var selection = {
|
|
110
|
-
text: text,
|
|
111
|
-
selection: {
|
|
112
|
-
from: from,
|
|
113
|
-
to: to
|
|
114
|
-
},
|
|
115
|
-
coords: coords
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// Render component here
|
|
121
|
+
var selection = getSelection(view);
|
|
119
122
|
if (extension.component) {
|
|
120
123
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
121
124
|
extension: extension,
|
|
@@ -123,35 +126,66 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
123
126
|
}));
|
|
124
127
|
}
|
|
125
128
|
if (extension.onClick) {
|
|
126
|
-
extension.onClick(
|
|
129
|
+
extension.onClick({
|
|
130
|
+
selection: selection
|
|
131
|
+
});
|
|
127
132
|
}
|
|
128
133
|
};
|
|
129
134
|
};
|
|
135
|
+
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
136
|
+
var _extension$isDisabled;
|
|
137
|
+
return {
|
|
138
|
+
title: extension.name,
|
|
139
|
+
icon: extension.icon ? /*#__PURE__*/_react.default.createElement(extension.icon, {
|
|
140
|
+
label: ''
|
|
141
|
+
}) : undefined,
|
|
142
|
+
disabled: extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
143
|
+
selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
|
|
144
|
+
}),
|
|
145
|
+
rank: rank,
|
|
146
|
+
onClick: function onClick() {
|
|
147
|
+
editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var getFirstPartyExtensions = function getFirstPartyExtensions(extensions) {
|
|
153
|
+
return extensions.map(function (ext) {
|
|
154
|
+
return convertExtensionToDropdownMenuItem(ext, 30);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
130
157
|
|
|
131
158
|
/**
|
|
132
|
-
*
|
|
159
|
+
* Add a heading to the external extensions
|
|
133
160
|
*/
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!view) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionItems.SelectionExtensionItems, {
|
|
143
|
-
api: api,
|
|
144
|
-
editorView: view,
|
|
145
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions,
|
|
146
|
-
extensions: extensions,
|
|
147
|
-
onExtensionClick: handleOnExtensionClick(view)
|
|
161
|
+
var getExternalExtensions = function getExternalExtensions(extensions) {
|
|
162
|
+
var externalExtensions = [];
|
|
163
|
+
if (extensions !== null && extensions !== void 0 && extensions.length) {
|
|
164
|
+
externalExtensions = extensions.map(function (ext, index) {
|
|
165
|
+
return convertExtensionToDropdownMenuItem(ext);
|
|
148
166
|
});
|
|
149
|
-
|
|
150
|
-
|
|
167
|
+
var externalExtensionsHeading = {
|
|
168
|
+
type: 'overflow-dropdown-heading',
|
|
169
|
+
title: 'Apps'
|
|
170
|
+
};
|
|
171
|
+
externalExtensions.unshift(externalExtensionsHeading);
|
|
172
|
+
}
|
|
173
|
+
return externalExtensions;
|
|
174
|
+
};
|
|
175
|
+
var groupedExtensionsArray = [].concat((0, _toConsumableArray2.default)(getFirstPartyExtensions(extensions.firstParty || [])), (0, _toConsumableArray2.default)(getExternalExtensions(extensions.external || [])));
|
|
176
|
+
var overflowMenu = {
|
|
177
|
+
type: 'overflow-dropdown',
|
|
178
|
+
dropdownWidth: 240,
|
|
179
|
+
supportsViewMode: true,
|
|
180
|
+
options: groupedExtensionsArray
|
|
151
181
|
};
|
|
152
182
|
return {
|
|
153
183
|
isToolbarAbove: true,
|
|
154
|
-
items: [
|
|
184
|
+
items: [{
|
|
185
|
+
type: 'separator',
|
|
186
|
+
fullHeight: true,
|
|
187
|
+
supportsViewMode: true
|
|
188
|
+
}, overflowMenu],
|
|
155
189
|
rank: -6
|
|
156
190
|
};
|
|
157
191
|
}
|
|
@@ -162,6 +196,20 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
162
196
|
plugin: function plugin() {
|
|
163
197
|
return (0, _main.createPlugin)();
|
|
164
198
|
}
|
|
199
|
+
}, {
|
|
200
|
+
name: 'selectionExtensionGetEditorViewReferencePlugin',
|
|
201
|
+
plugin: function plugin() {
|
|
202
|
+
return new _safePlugin.SafePlugin({
|
|
203
|
+
view: function view(editorView) {
|
|
204
|
+
editorViewRef.current = editorView;
|
|
205
|
+
return {
|
|
206
|
+
destroy: function destroy() {
|
|
207
|
+
editorViewRef.current = null;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
165
213
|
}];
|
|
166
214
|
}
|
|
167
215
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
3
4
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
4
5
|
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
5
|
-
import { SelectionExtensionItems } from './ui/toolbar/SelectionExtensionItems';
|
|
6
6
|
export const selectionExtensionPlugin = ({
|
|
7
7
|
api,
|
|
8
8
|
config
|
|
9
9
|
}) => {
|
|
10
|
+
const editorViewRef = {
|
|
11
|
+
current: null
|
|
12
|
+
};
|
|
10
13
|
return {
|
|
11
14
|
name: 'selectionExtension',
|
|
12
15
|
getSharedState(editorState) {
|
|
@@ -58,7 +61,7 @@ export const selectionExtensionPlugin = ({
|
|
|
58
61
|
*
|
|
59
62
|
* Check whether plugin contains any selection extensions
|
|
60
63
|
*/
|
|
61
|
-
if (!extensions
|
|
64
|
+
if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
|
|
62
65
|
return;
|
|
63
66
|
}
|
|
64
67
|
|
|
@@ -94,7 +97,7 @@ export const selectionExtensionPlugin = ({
|
|
|
94
97
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
|
-
const
|
|
100
|
+
const getSelection = view => {
|
|
98
101
|
const {
|
|
99
102
|
selection: currentSelection
|
|
100
103
|
} = state;
|
|
@@ -104,16 +107,15 @@ export const selectionExtensionPlugin = ({
|
|
|
104
107
|
} = currentSelection;
|
|
105
108
|
const text = state.doc.textBetween(from, to, '\n');
|
|
106
109
|
const coords = getBoundingBoxFromSelection(view, from, to);
|
|
107
|
-
|
|
110
|
+
return {
|
|
108
111
|
text,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
to
|
|
112
|
-
},
|
|
112
|
+
from,
|
|
113
|
+
to,
|
|
113
114
|
coords
|
|
114
115
|
};
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
};
|
|
117
|
+
const handleOnExtensionClick = view => extension => {
|
|
118
|
+
const selection = getSelection(view);
|
|
117
119
|
if (extension.component) {
|
|
118
120
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
119
121
|
extension,
|
|
@@ -121,34 +123,61 @@ export const selectionExtensionPlugin = ({
|
|
|
121
123
|
}));
|
|
122
124
|
}
|
|
123
125
|
if (extension.onClick) {
|
|
124
|
-
extension.onClick(
|
|
126
|
+
extension.onClick({
|
|
127
|
+
selection
|
|
128
|
+
});
|
|
125
129
|
}
|
|
126
130
|
};
|
|
131
|
+
const convertExtensionToDropdownMenuItem = (extension, rank) => {
|
|
132
|
+
var _extension$isDisabled;
|
|
133
|
+
return {
|
|
134
|
+
title: extension.name,
|
|
135
|
+
icon: extension.icon ? /*#__PURE__*/React.createElement(extension.icon, {
|
|
136
|
+
label: ''
|
|
137
|
+
}) : undefined,
|
|
138
|
+
disabled: extension === null || extension === void 0 ? void 0 : (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
139
|
+
selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
|
|
140
|
+
}),
|
|
141
|
+
rank,
|
|
142
|
+
onClick: () => {
|
|
143
|
+
editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const getFirstPartyExtensions = extensions => {
|
|
149
|
+
return extensions.map(ext => convertExtensionToDropdownMenuItem(ext, 30));
|
|
150
|
+
};
|
|
127
151
|
|
|
128
152
|
/**
|
|
129
|
-
*
|
|
153
|
+
* Add a heading to the external extensions
|
|
130
154
|
*/
|
|
131
|
-
const
|
|
132
|
-
|
|
155
|
+
const getExternalExtensions = extensions => {
|
|
156
|
+
let externalExtensions = [];
|
|
157
|
+
if (extensions !== null && extensions !== void 0 && extensions.length) {
|
|
158
|
+
externalExtensions = extensions.map((ext, index) => convertExtensionToDropdownMenuItem(ext));
|
|
159
|
+
const externalExtensionsHeading = {
|
|
160
|
+
type: 'overflow-dropdown-heading',
|
|
161
|
+
title: 'Apps'
|
|
162
|
+
};
|
|
163
|
+
externalExtensions.unshift(externalExtensionsHeading);
|
|
164
|
+
}
|
|
165
|
+
return externalExtensions;
|
|
166
|
+
};
|
|
167
|
+
const groupedExtensionsArray = [...getFirstPartyExtensions(extensions.firstParty || []), ...getExternalExtensions(extensions.external || [])];
|
|
168
|
+
const overflowMenu = {
|
|
169
|
+
type: 'overflow-dropdown',
|
|
170
|
+
dropdownWidth: 240,
|
|
133
171
|
supportsViewMode: true,
|
|
134
|
-
|
|
135
|
-
var _api$analytics2;
|
|
136
|
-
if (!view) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
return /*#__PURE__*/React.createElement(SelectionExtensionItems, {
|
|
140
|
-
api: api,
|
|
141
|
-
editorView: view,
|
|
142
|
-
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions,
|
|
143
|
-
extensions: extensions,
|
|
144
|
-
onExtensionClick: handleOnExtensionClick(view)
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
fallback: []
|
|
172
|
+
options: groupedExtensionsArray
|
|
148
173
|
};
|
|
149
174
|
return {
|
|
150
175
|
isToolbarAbove: true,
|
|
151
|
-
items: [
|
|
176
|
+
items: [{
|
|
177
|
+
type: 'separator',
|
|
178
|
+
fullHeight: true,
|
|
179
|
+
supportsViewMode: true
|
|
180
|
+
}, overflowMenu],
|
|
152
181
|
rank: -6
|
|
153
182
|
};
|
|
154
183
|
}
|
|
@@ -156,6 +185,20 @@ export const selectionExtensionPlugin = ({
|
|
|
156
185
|
pmPlugins: () => [{
|
|
157
186
|
name: 'selectionExtension',
|
|
158
187
|
plugin: () => createPlugin()
|
|
188
|
+
}, {
|
|
189
|
+
name: 'selectionExtensionGetEditorViewReferencePlugin',
|
|
190
|
+
plugin: () => {
|
|
191
|
+
return new SafePlugin({
|
|
192
|
+
view: editorView => {
|
|
193
|
+
editorViewRef.current = editorView;
|
|
194
|
+
return {
|
|
195
|
+
destroy: () => {
|
|
196
|
+
editorViewRef.current = null;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
159
202
|
}]
|
|
160
203
|
};
|
|
161
204
|
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
+
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
3
5
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
4
6
|
import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
|
|
5
|
-
import { SelectionExtensionItems } from './ui/toolbar/SelectionExtensionItems';
|
|
6
7
|
export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
7
8
|
var api = _ref.api,
|
|
8
9
|
config = _ref.config;
|
|
10
|
+
var editorViewRef = {
|
|
11
|
+
current: null
|
|
12
|
+
};
|
|
9
13
|
return {
|
|
10
14
|
name: 'selectionExtension',
|
|
11
15
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -56,7 +60,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
56
60
|
*
|
|
57
61
|
* Check whether plugin contains any selection extensions
|
|
58
62
|
*/
|
|
59
|
-
if (!extensions
|
|
63
|
+
if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -92,23 +96,22 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
92
96
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
93
97
|
return;
|
|
94
98
|
}
|
|
99
|
+
var getSelection = function getSelection(view) {
|
|
100
|
+
var currentSelection = state.selection;
|
|
101
|
+
var from = currentSelection.from,
|
|
102
|
+
to = currentSelection.to;
|
|
103
|
+
var text = state.doc.textBetween(from, to, '\n');
|
|
104
|
+
var coords = getBoundingBoxFromSelection(view, from, to);
|
|
105
|
+
return {
|
|
106
|
+
text: text,
|
|
107
|
+
from: from,
|
|
108
|
+
to: to,
|
|
109
|
+
coords: coords
|
|
110
|
+
};
|
|
111
|
+
};
|
|
95
112
|
var handleOnExtensionClick = function handleOnExtensionClick(view) {
|
|
96
113
|
return function (extension) {
|
|
97
|
-
var
|
|
98
|
-
var from = currentSelection.from,
|
|
99
|
-
to = currentSelection.to;
|
|
100
|
-
var text = state.doc.textBetween(from, to, '\n');
|
|
101
|
-
var coords = getBoundingBoxFromSelection(view, from, to);
|
|
102
|
-
var selection = {
|
|
103
|
-
text: text,
|
|
104
|
-
selection: {
|
|
105
|
-
from: from,
|
|
106
|
-
to: to
|
|
107
|
-
},
|
|
108
|
-
coords: coords
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Render component here
|
|
114
|
+
var selection = getSelection(view);
|
|
112
115
|
if (extension.component) {
|
|
113
116
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
|
|
114
117
|
extension: extension,
|
|
@@ -116,35 +119,66 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
116
119
|
}));
|
|
117
120
|
}
|
|
118
121
|
if (extension.onClick) {
|
|
119
|
-
extension.onClick(
|
|
122
|
+
extension.onClick({
|
|
123
|
+
selection: selection
|
|
124
|
+
});
|
|
120
125
|
}
|
|
121
126
|
};
|
|
122
127
|
};
|
|
128
|
+
var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
|
|
129
|
+
var _extension$isDisabled;
|
|
130
|
+
return {
|
|
131
|
+
title: extension.name,
|
|
132
|
+
icon: extension.icon ? /*#__PURE__*/React.createElement(extension.icon, {
|
|
133
|
+
label: ''
|
|
134
|
+
}) : undefined,
|
|
135
|
+
disabled: extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
|
|
136
|
+
selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
|
|
137
|
+
}),
|
|
138
|
+
rank: rank,
|
|
139
|
+
onClick: function onClick() {
|
|
140
|
+
editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
var getFirstPartyExtensions = function getFirstPartyExtensions(extensions) {
|
|
146
|
+
return extensions.map(function (ext) {
|
|
147
|
+
return convertExtensionToDropdownMenuItem(ext, 30);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
123
150
|
|
|
124
151
|
/**
|
|
125
|
-
*
|
|
152
|
+
* Add a heading to the external extensions
|
|
126
153
|
*/
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!view) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
return /*#__PURE__*/React.createElement(SelectionExtensionItems, {
|
|
136
|
-
api: api,
|
|
137
|
-
editorView: view,
|
|
138
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions,
|
|
139
|
-
extensions: extensions,
|
|
140
|
-
onExtensionClick: handleOnExtensionClick(view)
|
|
154
|
+
var getExternalExtensions = function getExternalExtensions(extensions) {
|
|
155
|
+
var externalExtensions = [];
|
|
156
|
+
if (extensions !== null && extensions !== void 0 && extensions.length) {
|
|
157
|
+
externalExtensions = extensions.map(function (ext, index) {
|
|
158
|
+
return convertExtensionToDropdownMenuItem(ext);
|
|
141
159
|
});
|
|
142
|
-
|
|
143
|
-
|
|
160
|
+
var externalExtensionsHeading = {
|
|
161
|
+
type: 'overflow-dropdown-heading',
|
|
162
|
+
title: 'Apps'
|
|
163
|
+
};
|
|
164
|
+
externalExtensions.unshift(externalExtensionsHeading);
|
|
165
|
+
}
|
|
166
|
+
return externalExtensions;
|
|
167
|
+
};
|
|
168
|
+
var groupedExtensionsArray = [].concat(_toConsumableArray(getFirstPartyExtensions(extensions.firstParty || [])), _toConsumableArray(getExternalExtensions(extensions.external || [])));
|
|
169
|
+
var overflowMenu = {
|
|
170
|
+
type: 'overflow-dropdown',
|
|
171
|
+
dropdownWidth: 240,
|
|
172
|
+
supportsViewMode: true,
|
|
173
|
+
options: groupedExtensionsArray
|
|
144
174
|
};
|
|
145
175
|
return {
|
|
146
176
|
isToolbarAbove: true,
|
|
147
|
-
items: [
|
|
177
|
+
items: [{
|
|
178
|
+
type: 'separator',
|
|
179
|
+
fullHeight: true,
|
|
180
|
+
supportsViewMode: true
|
|
181
|
+
}, overflowMenu],
|
|
148
182
|
rank: -6
|
|
149
183
|
};
|
|
150
184
|
}
|
|
@@ -155,6 +189,20 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
155
189
|
plugin: function plugin() {
|
|
156
190
|
return createPlugin();
|
|
157
191
|
}
|
|
192
|
+
}, {
|
|
193
|
+
name: 'selectionExtensionGetEditorViewReferencePlugin',
|
|
194
|
+
plugin: function plugin() {
|
|
195
|
+
return new SafePlugin({
|
|
196
|
+
view: function view(editorView) {
|
|
197
|
+
editorViewRef.current = editorView;
|
|
198
|
+
return {
|
|
199
|
+
destroy: function destroy() {
|
|
200
|
+
editorViewRef.current = null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
158
206
|
}];
|
|
159
207
|
}
|
|
160
208
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
4
4
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
5
|
-
import type { SelectionExtensionPluginConfiguration, SelectionExtensionPluginState,
|
|
5
|
+
import type { SelectionExtension, SelectionExtensionPluginConfiguration, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
6
6
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
7
7
|
pluginConfiguration: SelectionExtensionPluginConfiguration | undefined;
|
|
8
8
|
dependencies: [
|
|
@@ -13,8 +13,8 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
13
13
|
sharedState: SelectionExtensionPluginState | null;
|
|
14
14
|
commands: {
|
|
15
15
|
setActiveExtension: ({ extension, selection, }: {
|
|
16
|
-
extension:
|
|
17
|
-
selection:
|
|
16
|
+
extension: SelectionExtension;
|
|
17
|
+
selection: SelectionExtensionSelectionInfo;
|
|
18
18
|
}) => EditorCommand;
|
|
19
19
|
clearActiveExtension: () => EditorCommand;
|
|
20
20
|
};
|
|
@@ -6,25 +6,40 @@ export type MenuItemsType = Array<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export type SelectionExtensionComponentProps = {
|
|
8
8
|
closeExtension: () => void;
|
|
9
|
-
selection:
|
|
9
|
+
selection: SelectionExtensionSelectionInfo;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
11
|
+
export type SelectionExtensionCallbackOptions = {
|
|
12
|
+
selection?: SelectionExtensionSelectionInfo;
|
|
13
|
+
};
|
|
14
|
+
export type SelectionExtensionSelectionInfo = {
|
|
12
15
|
text: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
to: number;
|
|
16
|
-
};
|
|
16
|
+
from: number;
|
|
17
|
+
to: number;
|
|
17
18
|
coords: SelectionExtensionCoords;
|
|
18
19
|
};
|
|
19
|
-
export type
|
|
20
|
+
export type SelectionCoords = {
|
|
21
|
+
left: number;
|
|
22
|
+
right: number;
|
|
23
|
+
top: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
};
|
|
26
|
+
export type SelectionExtension = {
|
|
20
27
|
name: string;
|
|
21
|
-
|
|
28
|
+
icon?: React.ComponentType<React.PropsWithChildren<{
|
|
29
|
+
label: string;
|
|
30
|
+
}>>;
|
|
31
|
+
isDisabled?: (params: SelectionExtensionCallbackOptions) => boolean;
|
|
32
|
+
onClick?: (params: SelectionExtensionCallbackOptions) => void;
|
|
22
33
|
component?: React.ComponentType<SelectionExtensionComponentProps>;
|
|
23
34
|
};
|
|
35
|
+
export type SelectionExtensions = {
|
|
36
|
+
firstParty?: SelectionExtension[];
|
|
37
|
+
external?: SelectionExtension[];
|
|
38
|
+
};
|
|
24
39
|
type SelectionExtensionModes = ViewMode | ContentMode;
|
|
25
40
|
export type SelectionExtensionPluginConfiguration = {
|
|
26
41
|
pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
|
|
27
|
-
extensions?:
|
|
42
|
+
extensions?: SelectionExtensions;
|
|
28
43
|
};
|
|
29
44
|
export type SelectionExtensionCoords = {
|
|
30
45
|
left: number;
|
|
@@ -39,7 +54,7 @@ export declare enum SelectionExtensionActionTypes {
|
|
|
39
54
|
}
|
|
40
55
|
export type UpdateActiveExtensionAction = {
|
|
41
56
|
type: SelectionExtensionActionTypes.SET_ACTIVE_EXTENSION;
|
|
42
|
-
extension:
|
|
57
|
+
extension: SelectionExtension;
|
|
43
58
|
} | {
|
|
44
59
|
type: SelectionExtensionActionTypes.UPDATE_ACTIVE_EXTENSION_COORDS;
|
|
45
60
|
coords: SelectionExtensionCoords;
|
|
@@ -48,8 +63,8 @@ export type UpdateActiveExtensionAction = {
|
|
|
48
63
|
};
|
|
49
64
|
export type SelectionExtensionPluginState = {
|
|
50
65
|
activeExtension?: {
|
|
51
|
-
extension:
|
|
52
|
-
selection:
|
|
66
|
+
extension: SelectionExtension;
|
|
67
|
+
selection: SelectionExtensionSelectionInfo;
|
|
53
68
|
coords: SelectionExtensionCoords;
|
|
54
69
|
};
|
|
55
70
|
};
|
|
@@ -8,13 +8,13 @@ import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
8
8
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
9
9
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
11
|
-
import type {
|
|
11
|
+
import type { SelectionExtension } from '../../types';
|
|
12
12
|
type SelectionExtensionItemsProps = {
|
|
13
13
|
editorView: EditorView;
|
|
14
14
|
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
15
15
|
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
16
|
-
extensions:
|
|
17
|
-
onExtensionClick: (extension:
|
|
16
|
+
extensions: SelectionExtension[];
|
|
17
|
+
onExtensionClick: (extension: SelectionExtension) => void;
|
|
18
18
|
} & WrappedComponentProps;
|
|
19
19
|
export declare const SelectionExtensionItemsComponent: ({ extensions, onExtensionClick, editorAnalyticsAPI, }: SelectionExtensionItemsProps) => React.JSX.Element;
|
|
20
20
|
export declare const SelectionExtensionItems: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionItemsProps>> & {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
4
4
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
5
|
-
import type { SelectionExtensionPluginConfiguration, SelectionExtensionPluginState,
|
|
5
|
+
import type { SelectionExtension, SelectionExtensionPluginConfiguration, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
6
6
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
7
7
|
pluginConfiguration: SelectionExtensionPluginConfiguration | undefined;
|
|
8
8
|
dependencies: [
|
|
@@ -13,8 +13,8 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
13
13
|
sharedState: SelectionExtensionPluginState | null;
|
|
14
14
|
commands: {
|
|
15
15
|
setActiveExtension: ({ extension, selection, }: {
|
|
16
|
-
extension:
|
|
17
|
-
selection:
|
|
16
|
+
extension: SelectionExtension;
|
|
17
|
+
selection: SelectionExtensionSelectionInfo;
|
|
18
18
|
}) => EditorCommand;
|
|
19
19
|
clearActiveExtension: () => EditorCommand;
|
|
20
20
|
};
|
|
@@ -6,25 +6,40 @@ export type MenuItemsType = Array<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export type SelectionExtensionComponentProps = {
|
|
8
8
|
closeExtension: () => void;
|
|
9
|
-
selection:
|
|
9
|
+
selection: SelectionExtensionSelectionInfo;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
11
|
+
export type SelectionExtensionCallbackOptions = {
|
|
12
|
+
selection?: SelectionExtensionSelectionInfo;
|
|
13
|
+
};
|
|
14
|
+
export type SelectionExtensionSelectionInfo = {
|
|
12
15
|
text: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
to: number;
|
|
16
|
-
};
|
|
16
|
+
from: number;
|
|
17
|
+
to: number;
|
|
17
18
|
coords: SelectionExtensionCoords;
|
|
18
19
|
};
|
|
19
|
-
export type
|
|
20
|
+
export type SelectionCoords = {
|
|
21
|
+
left: number;
|
|
22
|
+
right: number;
|
|
23
|
+
top: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
};
|
|
26
|
+
export type SelectionExtension = {
|
|
20
27
|
name: string;
|
|
21
|
-
|
|
28
|
+
icon?: React.ComponentType<React.PropsWithChildren<{
|
|
29
|
+
label: string;
|
|
30
|
+
}>>;
|
|
31
|
+
isDisabled?: (params: SelectionExtensionCallbackOptions) => boolean;
|
|
32
|
+
onClick?: (params: SelectionExtensionCallbackOptions) => void;
|
|
22
33
|
component?: React.ComponentType<SelectionExtensionComponentProps>;
|
|
23
34
|
};
|
|
35
|
+
export type SelectionExtensions = {
|
|
36
|
+
firstParty?: SelectionExtension[];
|
|
37
|
+
external?: SelectionExtension[];
|
|
38
|
+
};
|
|
24
39
|
type SelectionExtensionModes = ViewMode | ContentMode;
|
|
25
40
|
export type SelectionExtensionPluginConfiguration = {
|
|
26
41
|
pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
|
|
27
|
-
extensions?:
|
|
42
|
+
extensions?: SelectionExtensions;
|
|
28
43
|
};
|
|
29
44
|
export type SelectionExtensionCoords = {
|
|
30
45
|
left: number;
|
|
@@ -39,7 +54,7 @@ export declare enum SelectionExtensionActionTypes {
|
|
|
39
54
|
}
|
|
40
55
|
export type UpdateActiveExtensionAction = {
|
|
41
56
|
type: SelectionExtensionActionTypes.SET_ACTIVE_EXTENSION;
|
|
42
|
-
extension:
|
|
57
|
+
extension: SelectionExtension;
|
|
43
58
|
} | {
|
|
44
59
|
type: SelectionExtensionActionTypes.UPDATE_ACTIVE_EXTENSION_COORDS;
|
|
45
60
|
coords: SelectionExtensionCoords;
|
|
@@ -48,8 +63,8 @@ export type UpdateActiveExtensionAction = {
|
|
|
48
63
|
};
|
|
49
64
|
export type SelectionExtensionPluginState = {
|
|
50
65
|
activeExtension?: {
|
|
51
|
-
extension:
|
|
52
|
-
selection:
|
|
66
|
+
extension: SelectionExtension;
|
|
67
|
+
selection: SelectionExtensionSelectionInfo;
|
|
53
68
|
coords: SelectionExtensionCoords;
|
|
54
69
|
};
|
|
55
70
|
};
|
|
@@ -8,13 +8,13 @@ import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
8
8
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
9
9
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
11
|
-
import type {
|
|
11
|
+
import type { SelectionExtension } from '../../types';
|
|
12
12
|
type SelectionExtensionItemsProps = {
|
|
13
13
|
editorView: EditorView;
|
|
14
14
|
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
15
15
|
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
16
|
-
extensions:
|
|
17
|
-
onExtensionClick: (extension:
|
|
16
|
+
extensions: SelectionExtension[];
|
|
17
|
+
onExtensionClick: (extension: SelectionExtension) => void;
|
|
18
18
|
} & WrappedComponentProps;
|
|
19
19
|
export declare const SelectionExtensionItemsComponent: ({ extensions, onExtensionClick, editorAnalyticsAPI, }: SelectionExtensionItemsProps) => React.JSX.Element;
|
|
20
20
|
export declare const SelectionExtensionItems: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionItemsProps>> & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,13 +36,14 @@
|
|
|
36
36
|
".": "./src/index.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atlaskit/editor-common": "^102.
|
|
40
|
-
"@atlaskit/editor-plugin-analytics": "^2.
|
|
39
|
+
"@atlaskit/editor-common": "^102.13.0",
|
|
40
|
+
"@atlaskit/editor-plugin-analytics": "^2.2.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^3.0.0",
|
|
42
|
-
"@atlaskit/editor-plugin-selection-toolbar": "^
|
|
42
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^3.0.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
44
|
-
"@atlaskit/icon": "^25.
|
|
45
|
-
"@atlaskit/primitives": "^14.
|
|
44
|
+
"@atlaskit/icon": "^25.2.0",
|
|
45
|
+
"@atlaskit/primitives": "^14.2.0",
|
|
46
|
+
"@atlaskit/tmp-editor-statsig": "^4.4.0",
|
|
46
47
|
"@babel/runtime": "^7.0.0",
|
|
47
48
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
48
49
|
"uuid": "^3.1.0"
|