@atlaskit/editor-plugin-selection-extension 2.1.5 → 2.1.7

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 2.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#135586](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/135586)
8
+ [`3aeba66081612`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3aeba66081612) -
9
+ ED-26593 Add missing i18n for editor control
10
+ - Updated dependencies
11
+
12
+ ## 2.1.6
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 2.1.5
4
19
 
5
20
  ### Patch Changes
@@ -5,14 +5,19 @@ 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 _messages = require("@atlaskit/editor-common/messages");
11
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
12
  var _main = require("./pm-plugins/main");
10
13
  var _SelectionExtensionComponentWrapper = require("./ui/extension/SelectionExtensionComponentWrapper");
11
14
  var _getBoundingBoxFromSelection = require("./ui/getBoundingBoxFromSelection");
12
- var _SelectionExtensionItems = require("./ui/toolbar/SelectionExtensionItems");
13
15
  var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
14
16
  var api = _ref.api,
15
17
  config = _ref.config;
18
+ var editorViewRef = {
19
+ current: null
20
+ };
16
21
  return {
17
22
  name: 'selectionExtension',
18
23
  getSharedState: function getSharedState(editorState) {
@@ -50,7 +55,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
50
55
  });
51
56
  },
52
57
  pluginsOptions: {
53
- selectionToolbar: function selectionToolbar(state) {
58
+ selectionToolbar: function selectionToolbar(state, intl) {
54
59
  var _api$editorViewMode;
55
60
  if (!config) {
56
61
  return;
@@ -63,7 +68,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
63
68
  *
64
69
  * Check whether plugin contains any selection extensions
65
70
  */
66
- if (!extensions || extensions.length === 0) {
71
+ if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
67
72
  return;
68
73
  }
69
74
 
@@ -99,23 +104,22 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
99
104
  if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
100
105
  return;
101
106
  }
107
+ var getSelection = function getSelection(view) {
108
+ var currentSelection = state.selection;
109
+ var from = currentSelection.from,
110
+ to = currentSelection.to;
111
+ var text = state.doc.textBetween(from, to, '\n');
112
+ var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to);
113
+ return {
114
+ text: text,
115
+ from: from,
116
+ to: to,
117
+ coords: coords
118
+ };
119
+ };
102
120
  var handleOnExtensionClick = function handleOnExtensionClick(view) {
103
121
  return function (extension) {
104
- var currentSelection = state.selection;
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
122
+ var selection = getSelection(view);
119
123
  if (extension.component) {
120
124
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
121
125
  extension: extension,
@@ -123,35 +127,66 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
123
127
  }));
124
128
  }
125
129
  if (extension.onClick) {
126
- extension.onClick(selection);
130
+ extension.onClick({
131
+ selection: selection
132
+ });
127
133
  }
128
134
  };
129
135
  };
136
+ var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
137
+ var _extension$isDisabled;
138
+ return {
139
+ title: extension.name,
140
+ icon: extension.icon ? /*#__PURE__*/_react.default.createElement(extension.icon, {
141
+ label: ''
142
+ }) : undefined,
143
+ disabled: extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
144
+ selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
145
+ }),
146
+ rank: rank,
147
+ onClick: function onClick() {
148
+ editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
149
+ return true;
150
+ }
151
+ };
152
+ };
153
+ var getFirstPartyExtensions = function getFirstPartyExtensions(extensions) {
154
+ return extensions.map(function (ext) {
155
+ return convertExtensionToDropdownMenuItem(ext, 30);
156
+ });
157
+ };
130
158
 
131
159
  /**
132
- * Renders custom dropdown menu with active selection extensions
160
+ * Add a heading to the external extensions
133
161
  */
134
- var selectionExtensionDropdown = {
135
- type: 'custom',
136
- supportsViewMode: true,
137
- render: function render(view) {
138
- var _api$analytics2;
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)
162
+ var getExternalExtensions = function getExternalExtensions(extensions) {
163
+ var externalExtensions = [];
164
+ if (extensions !== null && extensions !== void 0 && extensions.length) {
165
+ externalExtensions = extensions.map(function (ext, index) {
166
+ return convertExtensionToDropdownMenuItem(ext);
148
167
  });
149
- },
150
- fallback: []
168
+ var externalExtensionsHeading = {
169
+ type: 'overflow-dropdown-heading',
170
+ title: intl.formatMessage(_messages.selectionExtensionMessages.externalExtensionsHeading)
171
+ };
172
+ externalExtensions.unshift(externalExtensionsHeading);
173
+ }
174
+ return externalExtensions;
175
+ };
176
+ var groupedExtensionsArray = [].concat((0, _toConsumableArray2.default)(getFirstPartyExtensions(extensions.firstParty || [])), (0, _toConsumableArray2.default)(getExternalExtensions(extensions.external || [])));
177
+ var overflowMenu = {
178
+ type: 'overflow-dropdown',
179
+ dropdownWidth: 240,
180
+ supportsViewMode: true,
181
+ options: groupedExtensionsArray
151
182
  };
152
183
  return {
153
184
  isToolbarAbove: true,
154
- items: [selectionExtensionDropdown],
185
+ items: [{
186
+ type: 'separator',
187
+ fullHeight: true,
188
+ supportsViewMode: true
189
+ }, overflowMenu],
155
190
  rank: -6
156
191
  };
157
192
  }
@@ -162,6 +197,20 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
162
197
  plugin: function plugin() {
163
198
  return (0, _main.createPlugin)();
164
199
  }
200
+ }, {
201
+ name: 'selectionExtensionGetEditorViewReferencePlugin',
202
+ plugin: function plugin() {
203
+ return new _safePlugin.SafePlugin({
204
+ view: function view(editorView) {
205
+ editorViewRef.current = editorView;
206
+ return {
207
+ destroy: function destroy() {
208
+ editorViewRef.current = null;
209
+ }
210
+ };
211
+ }
212
+ });
213
+ }
165
214
  }];
166
215
  }
167
216
  };
@@ -1,12 +1,16 @@
1
1
  import React from 'react';
2
- import { selectionExtensionPluginKey, createPlugin } from './pm-plugins/main';
2
+ import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
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 const selectionExtensionPlugin = ({
7
8
  api,
8
9
  config
9
10
  }) => {
11
+ const editorViewRef = {
12
+ current: null
13
+ };
10
14
  return {
11
15
  name: 'selectionExtension',
12
16
  getSharedState(editorState) {
@@ -43,7 +47,7 @@ export const selectionExtensionPlugin = ({
43
47
  });
44
48
  },
45
49
  pluginsOptions: {
46
- selectionToolbar: state => {
50
+ selectionToolbar: (state, intl) => {
47
51
  var _api$editorViewMode, _api$editorViewMode$s;
48
52
  if (!config) {
49
53
  return;
@@ -58,7 +62,7 @@ export const selectionExtensionPlugin = ({
58
62
  *
59
63
  * Check whether plugin contains any selection extensions
60
64
  */
61
- if (!extensions || extensions.length === 0) {
65
+ if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
62
66
  return;
63
67
  }
64
68
 
@@ -94,7 +98,7 @@ export const selectionExtensionPlugin = ({
94
98
  if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
95
99
  return;
96
100
  }
97
- const handleOnExtensionClick = view => extension => {
101
+ const getSelection = view => {
98
102
  const {
99
103
  selection: currentSelection
100
104
  } = state;
@@ -104,16 +108,15 @@ export const selectionExtensionPlugin = ({
104
108
  } = currentSelection;
105
109
  const text = state.doc.textBetween(from, to, '\n');
106
110
  const coords = getBoundingBoxFromSelection(view, from, to);
107
- const selection = {
111
+ return {
108
112
  text,
109
- selection: {
110
- from,
111
- to
112
- },
113
+ from,
114
+ to,
113
115
  coords
114
116
  };
115
-
116
- // Render component here
117
+ };
118
+ const handleOnExtensionClick = view => extension => {
119
+ const selection = getSelection(view);
117
120
  if (extension.component) {
118
121
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
119
122
  extension,
@@ -121,34 +124,61 @@ export const selectionExtensionPlugin = ({
121
124
  }));
122
125
  }
123
126
  if (extension.onClick) {
124
- extension.onClick(selection);
127
+ extension.onClick({
128
+ selection
129
+ });
125
130
  }
126
131
  };
132
+ const convertExtensionToDropdownMenuItem = (extension, rank) => {
133
+ var _extension$isDisabled;
134
+ return {
135
+ title: extension.name,
136
+ icon: extension.icon ? /*#__PURE__*/React.createElement(extension.icon, {
137
+ label: ''
138
+ }) : undefined,
139
+ disabled: extension === null || extension === void 0 ? void 0 : (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
140
+ selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
141
+ }),
142
+ rank,
143
+ onClick: () => {
144
+ editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
145
+ return true;
146
+ }
147
+ };
148
+ };
149
+ const getFirstPartyExtensions = extensions => {
150
+ return extensions.map(ext => convertExtensionToDropdownMenuItem(ext, 30));
151
+ };
127
152
 
128
153
  /**
129
- * Renders custom dropdown menu with active selection extensions
154
+ * Add a heading to the external extensions
130
155
  */
131
- const selectionExtensionDropdown = {
132
- type: 'custom',
156
+ const getExternalExtensions = extensions => {
157
+ let externalExtensions = [];
158
+ if (extensions !== null && extensions !== void 0 && extensions.length) {
159
+ externalExtensions = extensions.map((ext, index) => convertExtensionToDropdownMenuItem(ext));
160
+ const externalExtensionsHeading = {
161
+ type: 'overflow-dropdown-heading',
162
+ title: intl.formatMessage(selectionExtensionMessages.externalExtensionsHeading)
163
+ };
164
+ externalExtensions.unshift(externalExtensionsHeading);
165
+ }
166
+ return externalExtensions;
167
+ };
168
+ const groupedExtensionsArray = [...getFirstPartyExtensions(extensions.firstParty || []), ...getExternalExtensions(extensions.external || [])];
169
+ const overflowMenu = {
170
+ type: 'overflow-dropdown',
171
+ dropdownWidth: 240,
133
172
  supportsViewMode: true,
134
- render: view => {
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: []
173
+ options: groupedExtensionsArray
148
174
  };
149
175
  return {
150
176
  isToolbarAbove: true,
151
- items: [selectionExtensionDropdown],
177
+ items: [{
178
+ type: 'separator',
179
+ fullHeight: true,
180
+ supportsViewMode: true
181
+ }, overflowMenu],
152
182
  rank: -6
153
183
  };
154
184
  }
@@ -156,6 +186,20 @@ export const selectionExtensionPlugin = ({
156
186
  pmPlugins: () => [{
157
187
  name: 'selectionExtension',
158
188
  plugin: () => createPlugin()
189
+ }, {
190
+ name: 'selectionExtensionGetEditorViewReferencePlugin',
191
+ plugin: () => {
192
+ return new SafePlugin({
193
+ view: editorView => {
194
+ editorViewRef.current = editorView;
195
+ return {
196
+ destroy: () => {
197
+ editorViewRef.current = null;
198
+ }
199
+ };
200
+ }
201
+ });
202
+ }
159
203
  }]
160
204
  };
161
205
  };
@@ -1,11 +1,16 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import React from 'react';
2
- import { selectionExtensionPluginKey, createPlugin } from './pm-plugins/main';
3
+ import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
4
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
+ import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
3
6
  import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
4
7
  import { getBoundingBoxFromSelection } from './ui/getBoundingBoxFromSelection';
5
- import { SelectionExtensionItems } from './ui/toolbar/SelectionExtensionItems';
6
8
  export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
7
9
  var api = _ref.api,
8
10
  config = _ref.config;
11
+ var editorViewRef = {
12
+ current: null
13
+ };
9
14
  return {
10
15
  name: 'selectionExtension',
11
16
  getSharedState: function getSharedState(editorState) {
@@ -43,7 +48,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
43
48
  });
44
49
  },
45
50
  pluginsOptions: {
46
- selectionToolbar: function selectionToolbar(state) {
51
+ selectionToolbar: function selectionToolbar(state, intl) {
47
52
  var _api$editorViewMode;
48
53
  if (!config) {
49
54
  return;
@@ -56,7 +61,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
56
61
  *
57
62
  * Check whether plugin contains any selection extensions
58
63
  */
59
- if (!extensions || extensions.length === 0) {
64
+ if (!(extensions !== null && extensions !== void 0 && extensions.firstParty) && !(extensions !== null && extensions !== void 0 && extensions.external)) {
60
65
  return;
61
66
  }
62
67
 
@@ -92,23 +97,22 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
92
97
  if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
93
98
  return;
94
99
  }
100
+ var getSelection = function getSelection(view) {
101
+ var currentSelection = state.selection;
102
+ var from = currentSelection.from,
103
+ to = currentSelection.to;
104
+ var text = state.doc.textBetween(from, to, '\n');
105
+ var coords = getBoundingBoxFromSelection(view, from, to);
106
+ return {
107
+ text: text,
108
+ from: from,
109
+ to: to,
110
+ coords: coords
111
+ };
112
+ };
95
113
  var handleOnExtensionClick = function handleOnExtensionClick(view) {
96
114
  return function (extension) {
97
- var currentSelection = state.selection;
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
115
+ var selection = getSelection(view);
112
116
  if (extension.component) {
113
117
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.selectionExtension.commands.setActiveExtension({
114
118
  extension: extension,
@@ -116,35 +120,66 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
116
120
  }));
117
121
  }
118
122
  if (extension.onClick) {
119
- extension.onClick(selection);
123
+ extension.onClick({
124
+ selection: selection
125
+ });
120
126
  }
121
127
  };
122
128
  };
129
+ var convertExtensionToDropdownMenuItem = function convertExtensionToDropdownMenuItem(extension, rank) {
130
+ var _extension$isDisabled;
131
+ return {
132
+ title: extension.name,
133
+ icon: extension.icon ? /*#__PURE__*/React.createElement(extension.icon, {
134
+ label: ''
135
+ }) : undefined,
136
+ disabled: extension === null || extension === void 0 || (_extension$isDisabled = extension.isDisabled) === null || _extension$isDisabled === void 0 ? void 0 : _extension$isDisabled.call(extension, {
137
+ selection: editorViewRef.current ? getSelection(editorViewRef.current) : undefined
138
+ }),
139
+ rank: rank,
140
+ onClick: function onClick() {
141
+ editorViewRef.current && handleOnExtensionClick(editorViewRef.current)(extension);
142
+ return true;
143
+ }
144
+ };
145
+ };
146
+ var getFirstPartyExtensions = function getFirstPartyExtensions(extensions) {
147
+ return extensions.map(function (ext) {
148
+ return convertExtensionToDropdownMenuItem(ext, 30);
149
+ });
150
+ };
123
151
 
124
152
  /**
125
- * Renders custom dropdown menu with active selection extensions
153
+ * Add a heading to the external extensions
126
154
  */
127
- var selectionExtensionDropdown = {
128
- type: 'custom',
129
- supportsViewMode: true,
130
- render: function render(view) {
131
- var _api$analytics2;
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)
155
+ var getExternalExtensions = function getExternalExtensions(extensions) {
156
+ var externalExtensions = [];
157
+ if (extensions !== null && extensions !== void 0 && extensions.length) {
158
+ externalExtensions = extensions.map(function (ext, index) {
159
+ return convertExtensionToDropdownMenuItem(ext);
141
160
  });
142
- },
143
- fallback: []
161
+ var externalExtensionsHeading = {
162
+ type: 'overflow-dropdown-heading',
163
+ title: intl.formatMessage(selectionExtensionMessages.externalExtensionsHeading)
164
+ };
165
+ externalExtensions.unshift(externalExtensionsHeading);
166
+ }
167
+ return externalExtensions;
168
+ };
169
+ var groupedExtensionsArray = [].concat(_toConsumableArray(getFirstPartyExtensions(extensions.firstParty || [])), _toConsumableArray(getExternalExtensions(extensions.external || [])));
170
+ var overflowMenu = {
171
+ type: 'overflow-dropdown',
172
+ dropdownWidth: 240,
173
+ supportsViewMode: true,
174
+ options: groupedExtensionsArray
144
175
  };
145
176
  return {
146
177
  isToolbarAbove: true,
147
- items: [selectionExtensionDropdown],
178
+ items: [{
179
+ type: 'separator',
180
+ fullHeight: true,
181
+ supportsViewMode: true
182
+ }, overflowMenu],
148
183
  rank: -6
149
184
  };
150
185
  }
@@ -155,6 +190,20 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
155
190
  plugin: function plugin() {
156
191
  return createPlugin();
157
192
  }
193
+ }, {
194
+ name: 'selectionExtensionGetEditorViewReferencePlugin',
195
+ plugin: function plugin() {
196
+ return new SafePlugin({
197
+ view: function view(editorView) {
198
+ editorViewRef.current = editorView;
199
+ return {
200
+ destroy: function destroy() {
201
+ editorViewRef.current = null;
202
+ }
203
+ };
204
+ }
205
+ });
206
+ }
158
207
  }];
159
208
  }
160
209
  };
@@ -1,8 +1,8 @@
1
- import type { NextEditorPlugin, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
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, SelectionExtensionContract, SelectionExtensionSelectType } from './types';
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: SelectionExtensionContract;
17
- selection: SelectionExtensionSelectType;
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: SelectionExtensionSelectType;
9
+ selection: SelectionExtensionSelectionInfo;
10
10
  };
11
- export type SelectionExtensionSelectType = {
11
+ export type SelectionExtensionCallbackOptions = {
12
+ selection?: SelectionExtensionSelectionInfo;
13
+ };
14
+ export type SelectionExtensionSelectionInfo = {
12
15
  text: string;
13
- selection: {
14
- from: number;
15
- to: number;
16
- };
16
+ from: number;
17
+ to: number;
17
18
  coords: SelectionExtensionCoords;
18
19
  };
19
- export type SelectionExtensionContract = {
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
- onClick?: (params: SelectionExtensionSelectType) => void;
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?: SelectionExtensionContract[];
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: SelectionExtensionContract;
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: SelectionExtensionContract;
52
- selection: SelectionExtensionSelectType;
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 { SelectionExtensionContract } from '../../types';
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: SelectionExtensionContract[];
17
- onExtensionClick: (extension: SelectionExtensionContract) => void;
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, EditorCommand } from '@atlaskit/editor-common/types';
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, SelectionExtensionContract, SelectionExtensionSelectType } from './types';
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: SelectionExtensionContract;
17
- selection: SelectionExtensionSelectType;
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: SelectionExtensionSelectType;
9
+ selection: SelectionExtensionSelectionInfo;
10
10
  };
11
- export type SelectionExtensionSelectType = {
11
+ export type SelectionExtensionCallbackOptions = {
12
+ selection?: SelectionExtensionSelectionInfo;
13
+ };
14
+ export type SelectionExtensionSelectionInfo = {
12
15
  text: string;
13
- selection: {
14
- from: number;
15
- to: number;
16
- };
16
+ from: number;
17
+ to: number;
17
18
  coords: SelectionExtensionCoords;
18
19
  };
19
- export type SelectionExtensionContract = {
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
- onClick?: (params: SelectionExtensionSelectType) => void;
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?: SelectionExtensionContract[];
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: SelectionExtensionContract;
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: SelectionExtensionContract;
52
- selection: SelectionExtensionSelectType;
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 { SelectionExtensionContract } from '../../types';
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: SelectionExtensionContract[];
17
- onExtensionClick: (extension: SelectionExtensionContract) => void;
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.5",
3
+ "version": "2.1.7",
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.4.0",
40
- "@atlaskit/editor-plugin-analytics": "^2.1.0",
39
+ "@atlaskit/editor-common": "^102.18.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": "^2.0.0",
42
+ "@atlaskit/editor-plugin-selection-toolbar": "^3.1.0",
43
43
  "@atlaskit/editor-prosemirror": "7.0.0",
44
- "@atlaskit/icon": "^25.0.0",
45
- "@atlaskit/primitives": "^14.1.0",
44
+ "@atlaskit/icon": "^25.5.0",
45
+ "@atlaskit/primitives": "^14.3.0",
46
+ "@atlaskit/tmp-editor-statsig": "^4.6.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"