@atlaskit/editor-plugin-selection-extension 9.0.7 → 9.0.9

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/pm-plugins/utils/index.js +1 -1
  3. package/dist/cjs/selectionExtensionPlugin.js +7 -5
  4. package/dist/cjs/ui/SelectionExtensionComponentContext.js +20 -0
  5. package/dist/cjs/ui/extension/SelectionExtensionComponentWrapper.js +2 -2
  6. package/dist/cjs/ui/menu/SelectionExtensionDropdownItem.js +50 -1
  7. package/dist/cjs/ui/menu/SelectionExtensionMenuItems.js +2 -2
  8. package/dist/cjs/ui/menu/SelectionExtensionNestedDropdownMenu.js +28 -3
  9. package/dist/cjs/ui/utils/registerBlockMenuItems.js +31 -12
  10. package/dist/es2019/pm-plugins/utils/index.js +1 -1
  11. package/dist/es2019/selectionExtensionPlugin.js +7 -5
  12. package/dist/es2019/ui/SelectionExtensionComponentContext.js +15 -0
  13. package/dist/es2019/ui/extension/SelectionExtensionComponentWrapper.js +2 -2
  14. package/dist/es2019/ui/menu/SelectionExtensionDropdownItem.js +53 -1
  15. package/dist/es2019/ui/menu/SelectionExtensionMenuItems.js +2 -2
  16. package/dist/es2019/ui/menu/SelectionExtensionNestedDropdownMenu.js +29 -3
  17. package/dist/es2019/ui/utils/registerBlockMenuItems.js +28 -8
  18. package/dist/esm/pm-plugins/utils/index.js +1 -1
  19. package/dist/esm/selectionExtensionPlugin.js +7 -5
  20. package/dist/esm/ui/SelectionExtensionComponentContext.js +15 -0
  21. package/dist/esm/ui/extension/SelectionExtensionComponentWrapper.js +2 -2
  22. package/dist/esm/ui/menu/SelectionExtensionDropdownItem.js +50 -1
  23. package/dist/esm/ui/menu/SelectionExtensionMenuItems.js +2 -2
  24. package/dist/esm/ui/menu/SelectionExtensionNestedDropdownMenu.js +28 -3
  25. package/dist/esm/ui/utils/registerBlockMenuItems.js +31 -12
  26. package/dist/types/pm-plugins/utils/index.d.ts +1 -1
  27. package/dist/types/types/index.d.ts +8 -0
  28. package/dist/types/ui/SelectionExtensionComponentContext.d.ts +13 -0
  29. package/dist/types/ui/menu/SelectionExtensionMenuItems.d.ts +1 -1
  30. package/dist/types/ui/utils/registerBlockMenuItems.d.ts +10 -1
  31. package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +1 -1
  32. package/dist/types-ts4.5/types/index.d.ts +8 -0
  33. package/dist/types-ts4.5/ui/SelectionExtensionComponentContext.d.ts +13 -0
  34. package/dist/types-ts4.5/ui/menu/SelectionExtensionMenuItems.d.ts +1 -1
  35. package/dist/types-ts4.5/ui/utils/registerBlockMenuItems.d.ts +10 -1
  36. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 9.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6c9c4e73b1c39`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6c9c4e73b1c39) -
8
+ EDITOR-4037 Block menu selection extension tests
9
+ - Updated dependencies
10
+
11
+ ## 9.0.8
12
+
13
+ ### Patch Changes
14
+
15
+ - [`342bed74cf6e9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/342bed74cf6e9) -
16
+ EDITOR-4037 Block menu selection extension click handling
17
+ - Updated dependencies
18
+
3
19
  ## 9.0.7
4
20
 
5
21
  ### Patch Changes
@@ -54,7 +54,7 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
54
54
 
55
55
  /**
56
56
  * @private
57
- * @deprecated use getFragmentInfoFromSelectionNew instead
57
+ * @deprecated use getSelectionTextInfoNew instead
58
58
  */
59
59
  var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionTextInfo(view, api) {
60
60
  var _api$userPreferences, _api$editorViewMode;
@@ -26,9 +26,7 @@ var _registerBlockMenuItems = require("./ui/utils/registerBlockMenuItems");
26
26
  var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
27
27
  var api = _ref.api,
28
28
  config = _ref.config;
29
- var editorViewRef = {
30
- current: null
31
- };
29
+ var editorViewRef = {};
32
30
  var cachedSelection;
33
31
  var cachedOverflowMenuOptions;
34
32
  var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
@@ -57,7 +55,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
57
55
  }
58
56
  }
59
57
  if ((0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
60
- (0, _registerBlockMenuItems.registerBlockMenuItems)(extensionList, api);
58
+ (0, _registerBlockMenuItems.registerBlockMenuItems)({
59
+ extensionList: extensionList,
60
+ api: api,
61
+ editorViewRef: editorViewRef
62
+ });
61
63
  }
62
64
  return {
63
65
  name: 'selectionExtension',
@@ -313,7 +315,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
313
315
  editorViewRef.current = editorView;
314
316
  return {
315
317
  destroy: function destroy() {
316
- editorViewRef.current = null;
318
+ delete editorViewRef.current;
317
319
  }
318
320
  };
319
321
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSelectionExtensionComponentContext = exports.SelectionExtensionComponentContextProvider = void 0;
7
+ var _react = require("react");
8
+ /*
9
+ * Common context passed down to selection extension components
10
+ */
11
+
12
+ var SelectionExtensionComponentContext = /*#__PURE__*/(0, _react.createContext)(undefined);
13
+ var SelectionExtensionComponentContextProvider = exports.SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
14
+ var useSelectionExtensionComponentContext = exports.useSelectionExtensionComponentContext = function useSelectionExtensionComponentContext() {
15
+ var context = (0, _react.useContext)(SelectionExtensionComponentContext);
16
+ if (!context) {
17
+ throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
18
+ }
19
+ return context;
20
+ };
@@ -53,7 +53,7 @@ var SelectionExtensionComponentWrapper = exports.SelectionExtensionComponentWrap
53
53
  if (!extension) {
54
54
  return;
55
55
  }
56
- if (isToolbarAIFCEnabled) {
56
+ if (isToolbarAIFCEnabled || (0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
57
57
  var currentComponent;
58
58
  if ('contentComponent' in extension && extension.contentComponent !== undefined) {
59
59
  currentComponent = extension.contentComponent;
@@ -92,7 +92,7 @@ var SelectionExtensionComponentWrapper = exports.SelectionExtensionComponentWrap
92
92
  if (!extension) {
93
93
  return null;
94
94
  }
95
- if (isToolbarAIFCEnabled) {
95
+ if (isToolbarAIFCEnabled || (0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
96
96
  var hasContentComponent = function hasContentComponent(ext) {
97
97
  return 'contentComponent' in ext && ext.contentComponent !== undefined;
98
98
  };
@@ -6,15 +6,64 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.SelectionExtensionDropdownItem = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _editorToolbar = require("@atlaskit/editor-toolbar");
11
+ var _main = require("../../pm-plugins/main");
12
+ var _utils = require("../../pm-plugins/utils");
13
+ var _types = require("../../types");
14
+ var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
10
15
  var SelectionExtensionDropdownItem = exports.SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
11
16
  var dropdownItem = _ref.dropdownItem;
12
17
  var IconComponent = dropdownItem.icon;
18
+ var _useSelectionExtensio = (0, _SelectionExtensionComponentContext.useSelectionExtensionComponentContext)(),
19
+ api = _useSelectionExtensio.api,
20
+ editorView = _useSelectionExtensio.editorView,
21
+ extensionKey = _useSelectionExtensio.extensionKey,
22
+ extensionSource = _useSelectionExtensio.extensionSource,
23
+ extensionLocation = _useSelectionExtensio.extensionLocation;
24
+ var handleClick = function handleClick() {
25
+ var _api$blockControls, _dropdownItem$onClick, _api$analytics;
26
+ var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
27
+ var selection = preservedSelection || editorView.state.selection;
28
+ if (dropdownItem.contentComponent) {
29
+ var selectionInfo = (0, _utils.getSelectionTextInfoNew)(selection, editorView, api);
30
+ api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
31
+ extension: dropdownItem,
32
+ selection: selectionInfo
33
+ }));
34
+ }
35
+ api.core.actions.execute(function (_ref2) {
36
+ var tr = _ref2.tr;
37
+ var _getSelectionAdfInfoN = (0, _utils.getSelectionAdfInfoNew)(selection),
38
+ selectedNode = _getSelectionAdfInfoN.selectedNode,
39
+ nodePos = _getSelectionAdfInfoN.nodePos;
40
+ tr.setMeta(_main.selectionExtensionPluginKey, {
41
+ type: _types.SelectionExtensionActionTypes.SET_SELECTED_NODE,
42
+ selectedNode: selectedNode,
43
+ nodePos: nodePos
44
+ });
45
+ return tr;
46
+ });
47
+ (_dropdownItem$onClick = dropdownItem.onClick) === null || _dropdownItem$onClick === void 0 || _dropdownItem$onClick.call(dropdownItem);
48
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
49
+ action: _analytics.ACTION.CLICKED,
50
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
51
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
52
+ eventType: _analytics.EVENT_TYPE.TRACK,
53
+ attributes: {
54
+ extensionKey: extensionKey,
55
+ extensionSource: extensionSource,
56
+ extensionLocation: extensionLocation,
57
+ extensionElement: 'dropdown-item',
58
+ extensionItemKey: dropdownItem.key
59
+ }
60
+ });
61
+ };
13
62
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
14
63
  elemBefore: IconComponent ? /*#__PURE__*/_react.default.createElement(IconComponent, {
15
64
  label: ""
16
65
  }) : undefined,
17
- onClick: dropdownItem.onClick,
66
+ onClick: handleClick,
18
67
  isDisabled: dropdownItem.isDisabled
19
68
  }, dropdownItem.label);
20
69
  };
@@ -18,12 +18,12 @@ var SelectionExtensionMenuItems = exports.SelectionExtensionMenuItems = function
18
18
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, extensionMenuItems.map(function (item) {
19
19
  if ((0, _menuItems.isNestedDropdownMenuConfiguration)(item)) {
20
20
  return /*#__PURE__*/_react.default.createElement(_SelectionExtensionNestedDropdownMenu.SelectionExtensionNestedDropdownMenu, {
21
- key: item.label,
21
+ key: item.key || item.label,
22
22
  nestedDropdownMenu: item
23
23
  });
24
24
  }
25
25
  return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
26
- key: item.label,
26
+ key: item.key || item.label,
27
27
  dropdownItem: item
28
28
  });
29
29
  }));
@@ -6,15 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.SelectionExtensionNestedDropdownMenu = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _editorToolbar = require("@atlaskit/editor-toolbar");
10
11
  var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
12
+ var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
11
13
  var _SelectionExtensionDropdownItem = require("./SelectionExtensionDropdownItem");
12
14
  var ChildItems = function ChildItems(_ref) {
13
15
  var nestedDropdownMenu = _ref.nestedDropdownMenu;
14
16
  var childItems = nestedDropdownMenu.getMenuItems();
15
17
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, null, childItems.map(function (dropdownItem) {
16
18
  return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
17
- key: dropdownItem.label,
19
+ key: dropdownItem.key || dropdownItem.label,
18
20
  dropdownItem: dropdownItem
19
21
  });
20
22
  }));
@@ -22,14 +24,37 @@ var ChildItems = function ChildItems(_ref) {
22
24
  var SelectionExtensionNestedDropdownMenu = exports.SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
23
25
  var nestedDropdownMenu = _ref2.nestedDropdownMenu;
24
26
  var IconComponent = nestedDropdownMenu.icon;
27
+ var _useSelectionExtensio = (0, _SelectionExtensionComponentContext.useSelectionExtensionComponentContext)(),
28
+ api = _useSelectionExtensio.api,
29
+ extensionKey = _useSelectionExtensio.extensionKey,
30
+ extensionSource = _useSelectionExtensio.extensionSource,
31
+ extensionLocation = _useSelectionExtensio.extensionLocation;
32
+ var handleClick = function handleClick() {
33
+ var _api$analytics;
34
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
35
+ action: _analytics.ACTION.CLICKED,
36
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
37
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
38
+ eventType: _analytics.EVENT_TYPE.TRACK,
39
+ attributes: {
40
+ extensionKey: extensionKey,
41
+ extensionSource: extensionSource,
42
+ extensionLocation: extensionLocation,
43
+ extensionElement: 'nested-dropdown',
44
+ extensionItemKey: nestedDropdownMenu.key
45
+ }
46
+ });
47
+ };
25
48
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
26
49
  text: nestedDropdownMenu.label,
27
50
  elemBefore: IconComponent ? /*#__PURE__*/_react.default.createElement(IconComponent, {
28
51
  label: ""
29
52
  }) : undefined,
30
53
  elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
31
- label: 'nested menu'
32
- })
54
+ label: ""
55
+ }),
56
+ onClick: handleClick,
57
+ dropdownTestId: "editor-selection-extension-menu"
33
58
  }, /*#__PURE__*/_react.default.createElement(ChildItems, {
34
59
  nestedDropdownMenu: nestedDropdownMenu
35
60
  }));
@@ -8,16 +8,39 @@ exports.registerBlockMenuItems = registerBlockMenuItems;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _blockMenu = require("@atlaskit/editor-common/block-menu");
10
10
  var _SelectionExtensionMenuItems = require("../menu/SelectionExtensionMenuItems");
11
- function registerBlockMenuItems(extensionList, api) {
12
- extensionList.forEach(function (_ref) {
13
- var _api$blockMenu;
14
- var source = _ref.source,
15
- key = _ref.key,
16
- blockMenu = _ref.blockMenu;
11
+ var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
12
+ function registerBlockMenuItems(_ref) {
13
+ var extensionList = _ref.extensionList,
14
+ api = _ref.api,
15
+ editorViewRef = _ref.editorViewRef;
16
+ extensionList.forEach(function (_ref2) {
17
+ var source = _ref2.source,
18
+ key = _ref2.key,
19
+ blockMenu = _ref2.blockMenu;
17
20
  if (source !== 'first-party' || !blockMenu) {
18
21
  return;
19
22
  }
20
- api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
23
+ if (!(api !== null && api !== void 0 && api.blockMenu)) {
24
+ return;
25
+ }
26
+ var component = function component() {
27
+ var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
28
+ if (!editorView) {
29
+ return null;
30
+ }
31
+ return /*#__PURE__*/_react.default.createElement(_SelectionExtensionComponentContext.SelectionExtensionComponentContextProvider, {
32
+ value: {
33
+ api: api,
34
+ editorView: editorView,
35
+ extensionKey: key,
36
+ extensionSource: source,
37
+ extensionLocation: 'block-menu'
38
+ }
39
+ }, /*#__PURE__*/_react.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
40
+ getMenuItems: blockMenu.getMenuItems
41
+ }));
42
+ };
43
+ api.blockMenu.actions.registerBlockMenuComponents([{
21
44
  type: 'block-menu-item',
22
45
  key: "selection-extension-".concat(key),
23
46
  parent: {
@@ -25,11 +48,7 @@ function registerBlockMenuItems(extensionList, api) {
25
48
  key: _blockMenu.TRANSFORM_CREATE_MENU_SECTION.key,
26
49
  rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
27
50
  },
28
- component: function component() {
29
- return /*#__PURE__*/_react.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
30
- getMenuItems: blockMenu.getMenuItems
31
- });
32
- }
51
+ component: component
33
52
  }]);
34
53
  });
35
54
  }
@@ -43,7 +43,7 @@ const getSelectionInfoFromCellSelection = selection => {
43
43
 
44
44
  /**
45
45
  * @private
46
- * @deprecated use getFragmentInfoFromSelectionNew instead
46
+ * @deprecated use getSelectionTextInfoNew instead
47
47
  */
48
48
  export const getSelectionTextInfo = (view, api) => {
49
49
  var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$editorViewMode, _api$editorViewMode$s;
@@ -19,9 +19,7 @@ export const selectionExtensionPlugin = ({
19
19
  api,
20
20
  config
21
21
  }) => {
22
- const editorViewRef = {
23
- current: null
24
- };
22
+ const editorViewRef = {};
25
23
  let cachedSelection;
26
24
  let cachedOverflowMenuOptions;
27
25
  const isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
@@ -46,7 +44,11 @@ export const selectionExtensionPlugin = ({
46
44
  }
47
45
  }
48
46
  if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
49
- registerBlockMenuItems(extensionList, api);
47
+ registerBlockMenuItems({
48
+ extensionList,
49
+ api,
50
+ editorViewRef
51
+ });
50
52
  }
51
53
  return {
52
54
  name: 'selectionExtension',
@@ -308,7 +310,7 @@ export const selectionExtensionPlugin = ({
308
310
  editorViewRef.current = editorView;
309
311
  return {
310
312
  destroy: () => {
311
- editorViewRef.current = null;
313
+ delete editorViewRef.current;
312
314
  }
313
315
  };
314
316
  }
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /*
4
+ * Common context passed down to selection extension components
5
+ */
6
+
7
+ const SelectionExtensionComponentContext = /*#__PURE__*/createContext(undefined);
8
+ export const SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
9
+ export const useSelectionExtensionComponentContext = () => {
10
+ const context = useContext(SelectionExtensionComponentContext);
11
+ if (!context) {
12
+ throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
13
+ }
14
+ return context;
15
+ };
@@ -47,7 +47,7 @@ export const SelectionExtensionComponentWrapper = ({
47
47
  if (!extension) {
48
48
  return;
49
49
  }
50
- if (isToolbarAIFCEnabled) {
50
+ if (isToolbarAIFCEnabled || expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
51
51
  let currentComponent;
52
52
  if ('contentComponent' in extension && extension.contentComponent !== undefined) {
53
53
  currentComponent = extension.contentComponent;
@@ -86,7 +86,7 @@ export const SelectionExtensionComponentWrapper = ({
86
86
  if (!extension) {
87
87
  return null;
88
88
  }
89
- if (isToolbarAIFCEnabled) {
89
+ if (isToolbarAIFCEnabled || expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
90
90
  const hasContentComponent = ext => {
91
91
  return 'contentComponent' in ext && ext.contentComponent !== undefined;
92
92
  };
@@ -1,14 +1,66 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
4
+ import { selectionExtensionPluginKey } from '../../pm-plugins/main';
5
+ import { getSelectionAdfInfoNew, getSelectionTextInfoNew } from '../../pm-plugins/utils';
6
+ import { SelectionExtensionActionTypes } from '../../types';
7
+ import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
3
8
  export const SelectionExtensionDropdownItem = ({
4
9
  dropdownItem
5
10
  }) => {
6
11
  const IconComponent = dropdownItem.icon;
12
+ const {
13
+ api,
14
+ editorView,
15
+ extensionKey,
16
+ extensionSource,
17
+ extensionLocation
18
+ } = useSelectionExtensionComponentContext();
19
+ const handleClick = () => {
20
+ var _api$blockControls, _api$blockControls$sh, _dropdownItem$onClick, _api$analytics;
21
+ const preservedSelection = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection;
22
+ const selection = preservedSelection || editorView.state.selection;
23
+ if (dropdownItem.contentComponent) {
24
+ const selectionInfo = getSelectionTextInfoNew(selection, editorView, api);
25
+ api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
26
+ extension: dropdownItem,
27
+ selection: selectionInfo
28
+ }));
29
+ }
30
+ api.core.actions.execute(({
31
+ tr
32
+ }) => {
33
+ const {
34
+ selectedNode,
35
+ nodePos
36
+ } = getSelectionAdfInfoNew(selection);
37
+ tr.setMeta(selectionExtensionPluginKey, {
38
+ type: SelectionExtensionActionTypes.SET_SELECTED_NODE,
39
+ selectedNode,
40
+ nodePos
41
+ });
42
+ return tr;
43
+ });
44
+ (_dropdownItem$onClick = dropdownItem.onClick) === null || _dropdownItem$onClick === void 0 ? void 0 : _dropdownItem$onClick.call(dropdownItem);
45
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
46
+ action: ACTION.CLICKED,
47
+ actionSubject: ACTION_SUBJECT.BUTTON,
48
+ actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
49
+ eventType: EVENT_TYPE.TRACK,
50
+ attributes: {
51
+ extensionKey,
52
+ extensionSource,
53
+ extensionLocation,
54
+ extensionElement: 'dropdown-item',
55
+ extensionItemKey: dropdownItem.key
56
+ }
57
+ });
58
+ };
7
59
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
8
60
  elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
9
61
  label: ""
10
62
  }) : undefined,
11
- onClick: dropdownItem.onClick,
63
+ onClick: handleClick,
12
64
  isDisabled: dropdownItem.isDisabled
13
65
  }, dropdownItem.label);
14
66
  };
@@ -12,12 +12,12 @@ export const SelectionExtensionMenuItems = ({
12
12
  return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(item => {
13
13
  if (isNestedDropdownMenuConfiguration(item)) {
14
14
  return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
15
- key: item.label,
15
+ key: item.key || item.label,
16
16
  nestedDropdownMenu: item
17
17
  });
18
18
  }
19
19
  return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
20
- key: item.label,
20
+ key: item.key || item.label,
21
21
  dropdownItem: item
22
22
  });
23
23
  }));
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
4
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
5
+ import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
4
6
  import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
5
7
  const ChildItems = ({
6
8
  nestedDropdownMenu
7
9
  }) => {
8
10
  const childItems = nestedDropdownMenu.getMenuItems();
9
11
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, childItems.map(dropdownItem => /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
10
- key: dropdownItem.label,
12
+ key: dropdownItem.key || dropdownItem.label,
11
13
  dropdownItem: dropdownItem
12
14
  })));
13
15
  };
@@ -15,14 +17,38 @@ export const SelectionExtensionNestedDropdownMenu = ({
15
17
  nestedDropdownMenu
16
18
  }) => {
17
19
  const IconComponent = nestedDropdownMenu.icon;
20
+ const {
21
+ api,
22
+ extensionKey,
23
+ extensionSource,
24
+ extensionLocation
25
+ } = useSelectionExtensionComponentContext();
26
+ const handleClick = () => {
27
+ var _api$analytics;
28
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
29
+ action: ACTION.CLICKED,
30
+ actionSubject: ACTION_SUBJECT.BUTTON,
31
+ actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
32
+ eventType: EVENT_TYPE.TRACK,
33
+ attributes: {
34
+ extensionKey,
35
+ extensionSource,
36
+ extensionLocation,
37
+ extensionElement: 'nested-dropdown',
38
+ extensionItemKey: nestedDropdownMenu.key
39
+ }
40
+ });
41
+ };
18
42
  return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
19
43
  text: nestedDropdownMenu.label,
20
44
  elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
21
45
  label: ""
22
46
  }) : undefined,
23
47
  elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
24
- label: 'nested menu'
25
- })
48
+ label: ""
49
+ }),
50
+ onClick: handleClick,
51
+ dropdownTestId: "editor-selection-extension-menu"
26
52
  }, /*#__PURE__*/React.createElement(ChildItems, {
27
53
  nestedDropdownMenu: nestedDropdownMenu
28
54
  }));
@@ -1,17 +1,41 @@
1
1
  import React from 'react';
2
2
  import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
3
3
  import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
4
- export function registerBlockMenuItems(extensionList, api) {
4
+ import { SelectionExtensionComponentContextProvider } from '../SelectionExtensionComponentContext';
5
+ export function registerBlockMenuItems({
6
+ extensionList,
7
+ api,
8
+ editorViewRef
9
+ }) {
5
10
  extensionList.forEach(({
6
11
  source,
7
12
  key,
8
13
  blockMenu
9
14
  }) => {
10
- var _api$blockMenu;
11
15
  if (source !== 'first-party' || !blockMenu) {
12
16
  return;
13
17
  }
14
- api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents([{
18
+ if (!(api !== null && api !== void 0 && api.blockMenu)) {
19
+ return;
20
+ }
21
+ const component = () => {
22
+ const editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
23
+ if (!editorView) {
24
+ return null;
25
+ }
26
+ return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider, {
27
+ value: {
28
+ api,
29
+ editorView,
30
+ extensionKey: key,
31
+ extensionSource: source,
32
+ extensionLocation: 'block-menu'
33
+ }
34
+ }, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
35
+ getMenuItems: blockMenu.getMenuItems
36
+ }));
37
+ };
38
+ api.blockMenu.actions.registerBlockMenuComponents([{
15
39
  type: 'block-menu-item',
16
40
  key: `selection-extension-${key}`,
17
41
  parent: {
@@ -19,11 +43,7 @@ export function registerBlockMenuItems(extensionList, api) {
19
43
  key: TRANSFORM_CREATE_MENU_SECTION.key,
20
44
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
21
45
  },
22
- component: () => {
23
- return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
24
- getMenuItems: blockMenu.getMenuItems
25
- });
26
- }
46
+ component
27
47
  }]);
28
48
  });
29
49
  }
@@ -44,7 +44,7 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
44
44
 
45
45
  /**
46
46
  * @private
47
- * @deprecated use getFragmentInfoFromSelectionNew instead
47
+ * @deprecated use getSelectionTextInfoNew instead
48
48
  */
49
49
  export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
50
50
  var _api$userPreferences, _api$editorViewMode;
@@ -19,9 +19,7 @@ import { registerBlockMenuItems } from './ui/utils/registerBlockMenuItems';
19
19
  export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
20
20
  var api = _ref.api,
21
21
  config = _ref.config;
22
- var editorViewRef = {
23
- current: null
24
- };
22
+ var editorViewRef = {};
25
23
  var cachedSelection;
26
24
  var cachedOverflowMenuOptions;
27
25
  var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
@@ -50,7 +48,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
50
48
  }
51
49
  }
52
50
  if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
53
- registerBlockMenuItems(extensionList, api);
51
+ registerBlockMenuItems({
52
+ extensionList: extensionList,
53
+ api: api,
54
+ editorViewRef: editorViewRef
55
+ });
54
56
  }
55
57
  return {
56
58
  name: 'selectionExtension',
@@ -306,7 +308,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
306
308
  editorViewRef.current = editorView;
307
309
  return {
308
310
  destroy: function destroy() {
309
- editorViewRef.current = null;
311
+ delete editorViewRef.current;
310
312
  }
311
313
  };
312
314
  }
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /*
4
+ * Common context passed down to selection extension components
5
+ */
6
+
7
+ var SelectionExtensionComponentContext = /*#__PURE__*/createContext(undefined);
8
+ export var SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
9
+ export var useSelectionExtensionComponentContext = function useSelectionExtensionComponentContext() {
10
+ var context = useContext(SelectionExtensionComponentContext);
11
+ if (!context) {
12
+ throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
13
+ }
14
+ return context;
15
+ };
@@ -45,7 +45,7 @@ export var SelectionExtensionComponentWrapper = function SelectionExtensionCompo
45
45
  if (!extension) {
46
46
  return;
47
47
  }
48
- if (isToolbarAIFCEnabled) {
48
+ if (isToolbarAIFCEnabled || expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
49
49
  var currentComponent;
50
50
  if ('contentComponent' in extension && extension.contentComponent !== undefined) {
51
51
  currentComponent = extension.contentComponent;
@@ -84,7 +84,7 @@ export var SelectionExtensionComponentWrapper = function SelectionExtensionCompo
84
84
  if (!extension) {
85
85
  return null;
86
86
  }
87
- if (isToolbarAIFCEnabled) {
87
+ if (isToolbarAIFCEnabled || expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
88
88
  var hasContentComponent = function hasContentComponent(ext) {
89
89
  return 'contentComponent' in ext && ext.contentComponent !== undefined;
90
90
  };
@@ -1,13 +1,62 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
4
+ import { selectionExtensionPluginKey } from '../../pm-plugins/main';
5
+ import { getSelectionAdfInfoNew, getSelectionTextInfoNew } from '../../pm-plugins/utils';
6
+ import { SelectionExtensionActionTypes } from '../../types';
7
+ import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
3
8
  export var SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
4
9
  var dropdownItem = _ref.dropdownItem;
5
10
  var IconComponent = dropdownItem.icon;
11
+ var _useSelectionExtensio = useSelectionExtensionComponentContext(),
12
+ api = _useSelectionExtensio.api,
13
+ editorView = _useSelectionExtensio.editorView,
14
+ extensionKey = _useSelectionExtensio.extensionKey,
15
+ extensionSource = _useSelectionExtensio.extensionSource,
16
+ extensionLocation = _useSelectionExtensio.extensionLocation;
17
+ var handleClick = function handleClick() {
18
+ var _api$blockControls, _dropdownItem$onClick, _api$analytics;
19
+ var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
20
+ var selection = preservedSelection || editorView.state.selection;
21
+ if (dropdownItem.contentComponent) {
22
+ var selectionInfo = getSelectionTextInfoNew(selection, editorView, api);
23
+ api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
24
+ extension: dropdownItem,
25
+ selection: selectionInfo
26
+ }));
27
+ }
28
+ api.core.actions.execute(function (_ref2) {
29
+ var tr = _ref2.tr;
30
+ var _getSelectionAdfInfoN = getSelectionAdfInfoNew(selection),
31
+ selectedNode = _getSelectionAdfInfoN.selectedNode,
32
+ nodePos = _getSelectionAdfInfoN.nodePos;
33
+ tr.setMeta(selectionExtensionPluginKey, {
34
+ type: SelectionExtensionActionTypes.SET_SELECTED_NODE,
35
+ selectedNode: selectedNode,
36
+ nodePos: nodePos
37
+ });
38
+ return tr;
39
+ });
40
+ (_dropdownItem$onClick = dropdownItem.onClick) === null || _dropdownItem$onClick === void 0 || _dropdownItem$onClick.call(dropdownItem);
41
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
42
+ action: ACTION.CLICKED,
43
+ actionSubject: ACTION_SUBJECT.BUTTON,
44
+ actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
45
+ eventType: EVENT_TYPE.TRACK,
46
+ attributes: {
47
+ extensionKey: extensionKey,
48
+ extensionSource: extensionSource,
49
+ extensionLocation: extensionLocation,
50
+ extensionElement: 'dropdown-item',
51
+ extensionItemKey: dropdownItem.key
52
+ }
53
+ });
54
+ };
6
55
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
7
56
  elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
8
57
  label: ""
9
58
  }) : undefined,
10
- onClick: dropdownItem.onClick,
59
+ onClick: handleClick,
11
60
  isDisabled: dropdownItem.isDisabled
12
61
  }, dropdownItem.label);
13
62
  };
@@ -11,12 +11,12 @@ export var SelectionExtensionMenuItems = function SelectionExtensionMenuItems(_r
11
11
  return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(function (item) {
12
12
  if (isNestedDropdownMenuConfiguration(item)) {
13
13
  return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
14
- key: item.label,
14
+ key: item.key || item.label,
15
15
  nestedDropdownMenu: item
16
16
  });
17
17
  }
18
18
  return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
19
- key: item.label,
19
+ key: item.key || item.label,
20
20
  dropdownItem: item
21
21
  });
22
22
  }));
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
4
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
5
+ import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
4
6
  import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
5
7
  var ChildItems = function ChildItems(_ref) {
6
8
  var nestedDropdownMenu = _ref.nestedDropdownMenu;
7
9
  var childItems = nestedDropdownMenu.getMenuItems();
8
10
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, childItems.map(function (dropdownItem) {
9
11
  return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
10
- key: dropdownItem.label,
12
+ key: dropdownItem.key || dropdownItem.label,
11
13
  dropdownItem: dropdownItem
12
14
  });
13
15
  }));
@@ -15,14 +17,37 @@ var ChildItems = function ChildItems(_ref) {
15
17
  export var SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
16
18
  var nestedDropdownMenu = _ref2.nestedDropdownMenu;
17
19
  var IconComponent = nestedDropdownMenu.icon;
20
+ var _useSelectionExtensio = useSelectionExtensionComponentContext(),
21
+ api = _useSelectionExtensio.api,
22
+ extensionKey = _useSelectionExtensio.extensionKey,
23
+ extensionSource = _useSelectionExtensio.extensionSource,
24
+ extensionLocation = _useSelectionExtensio.extensionLocation;
25
+ var handleClick = function handleClick() {
26
+ var _api$analytics;
27
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
28
+ action: ACTION.CLICKED,
29
+ actionSubject: ACTION_SUBJECT.BUTTON,
30
+ actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
31
+ eventType: EVENT_TYPE.TRACK,
32
+ attributes: {
33
+ extensionKey: extensionKey,
34
+ extensionSource: extensionSource,
35
+ extensionLocation: extensionLocation,
36
+ extensionElement: 'nested-dropdown',
37
+ extensionItemKey: nestedDropdownMenu.key
38
+ }
39
+ });
40
+ };
18
41
  return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
19
42
  text: nestedDropdownMenu.label,
20
43
  elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
21
44
  label: ""
22
45
  }) : undefined,
23
46
  elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
24
- label: 'nested menu'
25
- })
47
+ label: ""
48
+ }),
49
+ onClick: handleClick,
50
+ dropdownTestId: "editor-selection-extension-menu"
26
51
  }, /*#__PURE__*/React.createElement(ChildItems, {
27
52
  nestedDropdownMenu: nestedDropdownMenu
28
53
  }));
@@ -1,16 +1,39 @@
1
1
  import React from 'react';
2
2
  import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
3
3
  import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
4
- export function registerBlockMenuItems(extensionList, api) {
5
- extensionList.forEach(function (_ref) {
6
- var _api$blockMenu;
7
- var source = _ref.source,
8
- key = _ref.key,
9
- blockMenu = _ref.blockMenu;
4
+ import { SelectionExtensionComponentContextProvider } from '../SelectionExtensionComponentContext';
5
+ export function registerBlockMenuItems(_ref) {
6
+ var extensionList = _ref.extensionList,
7
+ api = _ref.api,
8
+ editorViewRef = _ref.editorViewRef;
9
+ extensionList.forEach(function (_ref2) {
10
+ var source = _ref2.source,
11
+ key = _ref2.key,
12
+ blockMenu = _ref2.blockMenu;
10
13
  if (source !== 'first-party' || !blockMenu) {
11
14
  return;
12
15
  }
13
- api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
16
+ if (!(api !== null && api !== void 0 && api.blockMenu)) {
17
+ return;
18
+ }
19
+ var component = function component() {
20
+ var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
21
+ if (!editorView) {
22
+ return null;
23
+ }
24
+ return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider, {
25
+ value: {
26
+ api: api,
27
+ editorView: editorView,
28
+ extensionKey: key,
29
+ extensionSource: source,
30
+ extensionLocation: 'block-menu'
31
+ }
32
+ }, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
33
+ getMenuItems: blockMenu.getMenuItems
34
+ }));
35
+ };
36
+ api.blockMenu.actions.registerBlockMenuComponents([{
14
37
  type: 'block-menu-item',
15
38
  key: "selection-extension-".concat(key),
16
39
  parent: {
@@ -18,11 +41,7 @@ export function registerBlockMenuItems(extensionList, api) {
18
41
  key: TRANSFORM_CREATE_MENU_SECTION.key,
19
42
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
20
43
  },
21
- component: function component() {
22
- return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
23
- getMenuItems: blockMenu.getMenuItems
24
- });
25
- }
44
+ component: component
26
45
  }]);
27
46
  });
28
47
  }
@@ -14,7 +14,7 @@ type SelectionInfo = {
14
14
  };
15
15
  /**
16
16
  * @private
17
- * @deprecated use getFragmentInfoFromSelectionNew instead
17
+ * @deprecated use getSelectionTextInfoNew instead
18
18
  */
19
19
  export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
20
20
  export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
@@ -136,6 +136,10 @@ export type BlockMenuExtensionConfiguration = {
136
136
  getMenuItems: GetMenuItemsFn;
137
137
  };
138
138
  export type ExtensionToolbarItemConfiguration = {
139
+ /**
140
+ * Optional key to identify the toolbar item in analytics events
141
+ */
142
+ key?: string;
139
143
  icon: ComponentType<PropsWithChildren<{
140
144
  label: string;
141
145
  }>>;
@@ -148,6 +152,10 @@ export type ExtensionToolbarItemConfiguration = {
148
152
  * Common fields applicable to all extension menu items
149
153
  */
150
154
  type ExtensionMenuItemBaseConfiguration = {
155
+ /**
156
+ * Optional key to identify the menu item in analytics events
157
+ */
158
+ key?: string;
151
159
  icon: ComponentType<PropsWithChildren<{
152
160
  label: string;
153
161
  size?: 'small' | 'medium';
@@ -0,0 +1,13 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { SelectionExtensionPlugin } from '../selectionExtensionPluginType';
4
+ type SelectionExtensionComponentContextValue = {
5
+ api: ExtractInjectionAPI<SelectionExtensionPlugin>;
6
+ editorView: EditorView;
7
+ extensionKey: string;
8
+ extensionSource: string;
9
+ extensionLocation: 'inline-toolbar' | 'primary-toolbar' | 'block-menu';
10
+ };
11
+ export declare const SelectionExtensionComponentContextProvider: import("react").Provider<SelectionExtensionComponentContextValue | undefined>;
12
+ export declare const useSelectionExtensionComponentContext: () => SelectionExtensionComponentContextValue;
13
+ export {};
@@ -3,5 +3,5 @@ import type { ExtensionMenuItemConfiguration } from '../../types';
3
3
  type SelectionExtensionMenuItemsProps = {
4
4
  getMenuItems: () => ExtensionMenuItemConfiguration[];
5
5
  };
6
- export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
6
+ export declare const SelectionExtensionMenuItems: ({ getMenuItems, }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
7
7
  export {};
@@ -1,4 +1,13 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
3
  import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
3
4
  import type { ExtensionConfiguration } from '../../types';
4
- export declare function registerBlockMenuItems(extensionList: ExtensionConfiguration[], api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined): void;
5
+ type RegisterBlockMenuItemsOptions = {
6
+ extensionList: ExtensionConfiguration[];
7
+ api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
8
+ editorViewRef?: {
9
+ current?: EditorView;
10
+ };
11
+ };
12
+ export declare function registerBlockMenuItems({ extensionList, api, editorViewRef, }: RegisterBlockMenuItemsOptions): void;
13
+ export {};
@@ -14,7 +14,7 @@ type SelectionInfo = {
14
14
  };
15
15
  /**
16
16
  * @private
17
- * @deprecated use getFragmentInfoFromSelectionNew instead
17
+ * @deprecated use getSelectionTextInfoNew instead
18
18
  */
19
19
  export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
20
20
  export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
@@ -136,6 +136,10 @@ export type BlockMenuExtensionConfiguration = {
136
136
  getMenuItems: GetMenuItemsFn;
137
137
  };
138
138
  export type ExtensionToolbarItemConfiguration = {
139
+ /**
140
+ * Optional key to identify the toolbar item in analytics events
141
+ */
142
+ key?: string;
139
143
  icon: ComponentType<PropsWithChildren<{
140
144
  label: string;
141
145
  }>>;
@@ -148,6 +152,10 @@ export type ExtensionToolbarItemConfiguration = {
148
152
  * Common fields applicable to all extension menu items
149
153
  */
150
154
  type ExtensionMenuItemBaseConfiguration = {
155
+ /**
156
+ * Optional key to identify the menu item in analytics events
157
+ */
158
+ key?: string;
151
159
  icon: ComponentType<PropsWithChildren<{
152
160
  label: string;
153
161
  size?: 'small' | 'medium';
@@ -0,0 +1,13 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { SelectionExtensionPlugin } from '../selectionExtensionPluginType';
4
+ type SelectionExtensionComponentContextValue = {
5
+ api: ExtractInjectionAPI<SelectionExtensionPlugin>;
6
+ editorView: EditorView;
7
+ extensionKey: string;
8
+ extensionSource: string;
9
+ extensionLocation: 'inline-toolbar' | 'primary-toolbar' | 'block-menu';
10
+ };
11
+ export declare const SelectionExtensionComponentContextProvider: import("react").Provider<SelectionExtensionComponentContextValue | undefined>;
12
+ export declare const useSelectionExtensionComponentContext: () => SelectionExtensionComponentContextValue;
13
+ export {};
@@ -3,5 +3,5 @@ import type { ExtensionMenuItemConfiguration } from '../../types';
3
3
  type SelectionExtensionMenuItemsProps = {
4
4
  getMenuItems: () => ExtensionMenuItemConfiguration[];
5
5
  };
6
- export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
6
+ export declare const SelectionExtensionMenuItems: ({ getMenuItems, }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
7
7
  export {};
@@ -1,4 +1,13 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
3
  import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
3
4
  import type { ExtensionConfiguration } from '../../types';
4
- export declare function registerBlockMenuItems(extensionList: ExtensionConfiguration[], api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined): void;
5
+ type RegisterBlockMenuItemsOptions = {
6
+ extensionList: ExtensionConfiguration[];
7
+ api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
8
+ editorViewRef?: {
9
+ current?: EditorView;
10
+ };
11
+ };
12
+ export declare function registerBlockMenuItems({ extensionList, api, editorViewRef, }: RegisterBlockMenuItemsOptions): void;
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "9.0.7",
3
+ "version": "9.0.9",
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,31 +35,31 @@
35
35
  "@atlaskit/adf-utils": "^19.26.0",
36
36
  "@atlaskit/editor-json-transformer": "^8.31.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^6.2.0",
38
- "@atlaskit/editor-plugin-block-controls": "^7.15.0",
38
+ "@atlaskit/editor-plugin-block-controls": "^7.18.0",
39
39
  "@atlaskit/editor-plugin-block-menu": "^5.2.0",
40
40
  "@atlaskit/editor-plugin-editor-viewmode": "^8.0.0",
41
41
  "@atlaskit/editor-plugin-editor-viewmode-effects": "^6.1.0",
42
42
  "@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
43
- "@atlaskit/editor-plugin-selection-toolbar": "^7.1.0",
44
- "@atlaskit/editor-plugin-toolbar": "^3.4.0",
43
+ "@atlaskit/editor-plugin-selection-toolbar": "^7.2.0",
44
+ "@atlaskit/editor-plugin-toolbar": "^3.5.0",
45
45
  "@atlaskit/editor-plugin-user-preferences": "^4.0.0",
46
46
  "@atlaskit/editor-prosemirror": "^7.2.0",
47
47
  "@atlaskit/editor-shared-styles": "^3.10.0",
48
48
  "@atlaskit/editor-tables": "^2.9.0",
49
49
  "@atlaskit/editor-toolbar": "^0.18.0",
50
50
  "@atlaskit/icon": "^29.3.0",
51
- "@atlaskit/lozenge": "^13.2.0",
51
+ "@atlaskit/lozenge": "^13.3.0",
52
52
  "@atlaskit/platform-feature-flags": "^1.1.0",
53
53
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
54
54
  "@atlaskit/primitives": "^17.0.0",
55
- "@atlaskit/tmp-editor-statsig": "^16.0.0",
55
+ "@atlaskit/tmp-editor-statsig": "^16.2.0",
56
56
  "@babel/runtime": "^7.0.0",
57
57
  "lodash": "^4.17.21",
58
58
  "react-intl-next": "npm:react-intl@^5.18.1",
59
59
  "uuid": "^3.1.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@atlaskit/editor-common": "^110.46.0",
62
+ "@atlaskit/editor-common": "^110.49.0",
63
63
  "react": "^18.2.0"
64
64
  },
65
65
  "devDependencies": {