@atlaskit/editor-plugin-selection-extension 7.2.1 → 9.0.0

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,23 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 9.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`d2e5db925723b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d2e5db925723b) -
8
+ EDITOR-2772 Update selection extension types for block menu
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 8.0.0
15
+
16
+ ### Major Changes
17
+
18
+ - [`63fe1593adb21`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/63fe1593adb21) -
19
+ EDITOR-2772 Remove support for unused `section` config on selection extensions
20
+
3
21
  ## 7.2.1
4
22
 
5
23
  ### Patch Changes
@@ -17,4 +17,21 @@ var SelectionExtensionActionTypes = exports.SelectionExtensionActionTypes = /*#_
17
17
  SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
18
18
  SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
19
19
  return SelectionExtensionActionTypes;
20
- }({});
20
+ }({});
21
+ /**
22
+ * Common fields applicable to all extension menu items
23
+ */
24
+ /**
25
+ * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
26
+ */
27
+ /**
28
+ * Fields for a dropdown menu item (i.e., an item that has nested menu items)
29
+ */
30
+ /**
31
+ * A type which marks all fields from ExtensionMenuItemDropdownMenuConfiguration and ExtensionMenuItemLeafConfiguration
32
+ * as never, ensuring that only one of the two can be present at a time to avoid misconfigurations
33
+ */
34
+ /**
35
+ * We intentionally only support leaf menu items nested within dropdown menu items so that there will
36
+ * be at max two levels of nesting from extension menu items.
37
+ */
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getToolbarItemExtensions = exports.getMenuItemExtensions = exports.getBlockMenuItemExtensions = void 0;
6
+ exports.getToolbarItemExtensions = exports.getMenuItemExtensions = void 0;
7
7
  /**
8
8
  * From the full list of extensions, extract only those that have a toolbar item configuration
9
9
  * for the specified type (either 'primaryToolbar' or 'inlineToolbar').
@@ -60,20 +60,4 @@ var getMenuItemExtensions = exports.getMenuItemExtensions = function getMenuItem
60
60
  }
61
61
  return acc;
62
62
  }, []);
63
- };
64
- var getBlockMenuItemExtensions = exports.getBlockMenuItemExtensions = function getBlockMenuItemExtensions(extensionList, targetSource) {
65
- return extensionList.reduce(function (acc, extension) {
66
- var source = extension.source,
67
- blockMenu = extension.blockMenu;
68
- if (source === targetSource && blockMenu !== null && blockMenu !== void 0 && blockMenu.getMenuItem) {
69
- var _blockMenu$getNestedM;
70
- var menuItem = blockMenu.getMenuItem();
71
- var nestedMenuItems = (_blockMenu$getNestedM = blockMenu.getNestedMenuItems) === null || _blockMenu$getNestedM === void 0 ? void 0 : _blockMenu$getNestedM.call(blockMenu);
72
- acc.push({
73
- menuItem: menuItem,
74
- nestedMenuItems: nestedMenuItems
75
- });
76
- }
77
- return acc;
78
- }, []);
79
63
  };
@@ -5,108 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.registerBlockMenuItems = registerBlockMenuItems;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
8
  var _react = _interopRequireDefault(require("react"));
10
- var _editorToolbar = require("@atlaskit/editor-toolbar");
11
- var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
12
- var _extensions = require("../extensions");
9
+ var _blockMenu = require("@atlaskit/editor-common/block-menu");
13
10
  function registerBlockMenuItems(extensionList, api) {
14
- var blockMenuExtensions = (0, _extensions.getBlockMenuItemExtensions)(extensionList, 'first-party');
15
- if (!(blockMenuExtensions !== null && blockMenuExtensions !== void 0 && blockMenuExtensions.length)) {
16
- return;
17
- }
18
- blockMenuExtensions.forEach(function (extension, index) {
19
- var menuItem = extension.menuItem;
20
- var nestedMenuItems = extension.nestedMenuItems;
21
- var blockMenuItemKey = "selection-extension-".concat(index);
22
-
23
- // If there are nested menu items, create a nested dropdown menu
24
- if (nestedMenuItems && nestedMenuItems.length > 0) {
25
- var _api$blockMenu;
26
- var nestedMenuComponents = [{
27
- type: 'block-menu-nested',
28
- key: "".concat(blockMenuItemKey, "-nested"),
29
- parent: {
30
- type: 'block-menu-section',
31
- key: 'block-menu-section-primary',
32
- rank: 200
33
- },
34
- component: function component() {
35
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
36
- children: null
37
- },
38
- children = _ref.children;
39
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
40
- text: menuItem.label,
41
- elemBefore: menuItem.icon ? /*#__PURE__*/_react.default.createElement(menuItem.icon, {
42
- label: ''
43
- }) : undefined,
44
- elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
45
- label: 'nested menu'
46
- })
47
- }, children);
48
- }
49
- }, {
50
- type: 'block-menu-section',
51
- key: "".concat(blockMenuItemKey, "-nested-section"),
52
- parent: {
53
- type: 'block-menu-nested',
54
- key: "".concat(blockMenuItemKey, "-nested"),
55
- rank: 100
56
- },
57
- component: function component() {
58
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
59
- children: null
60
- },
61
- children = _ref2.children;
62
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, null, children);
63
- }
64
- }].concat((0, _toConsumableArray2.default)(nestedMenuItems.reduce(function (acc, nestedItem, nestedIndex) {
65
- if ('label' in nestedItem) {
66
- acc.push({
67
- type: 'block-menu-item',
68
- key: "".concat(blockMenuItemKey, "-nested-item-").concat(nestedIndex),
69
- parent: {
70
- type: 'block-menu-section',
71
- key: "".concat(blockMenuItemKey, "-nested-section"),
72
- rank: nestedIndex + 100
73
- },
74
- component: function component() {
75
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
76
- elemBefore: nestedItem.icon ? /*#__PURE__*/_react.default.createElement(nestedItem.icon, {
77
- label: ''
78
- }) : undefined,
79
- onClick: nestedItem.onClick,
80
- isDisabled: nestedItem.isDisabled
81
- }, nestedItem.label);
82
- }
83
- });
84
- }
85
- return acc;
86
- }, [])));
87
- api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents(nestedMenuComponents);
88
- } else {
89
- var _api$blockMenu2;
90
- // If no nested items, create a regular menu item
91
- var blockMenuComponent = [{
92
- type: 'block-menu-item',
93
- key: blockMenuItemKey,
94
- parent: {
95
- type: 'block-menu-section',
96
- key: 'block-menu-section-primary',
97
- rank: 200
98
- },
99
- component: function component() {
100
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
101
- elemBefore: menuItem.icon ? /*#__PURE__*/_react.default.createElement(menuItem.icon, {
102
- label: ''
103
- }) : undefined,
104
- onClick: menuItem.onClick,
105
- isDisabled: menuItem.isDisabled
106
- }, menuItem.label);
107
- }
108
- }];
109
- api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 || _api$blockMenu2.actions.registerBlockMenuComponents(blockMenuComponent);
11
+ extensionList.forEach(function (_ref, index) {
12
+ var _api$blockMenu;
13
+ var source = _ref.source,
14
+ key = _ref.key,
15
+ blockMenu = _ref.blockMenu;
16
+ if (source !== 'first-party' || !blockMenu) {
17
+ return;
110
18
  }
19
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
20
+ type: 'block-menu-item',
21
+ key: "selection-extension-".concat(key),
22
+ parent: {
23
+ type: 'block-menu-section',
24
+ key: _blockMenu.TRANSFORM_CREATE_MENU_SECTION.key,
25
+ rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
26
+ },
27
+ component: function component() {
28
+ // EDITOR-2772 implementation of rendering in next PR
29
+ return /*#__PURE__*/_react.default.createElement("div", null, "Placeholder");
30
+ }
31
+ }]);
111
32
  });
112
33
  }
@@ -13,4 +13,26 @@ export let SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
13
13
  SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
14
14
  SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
15
15
  return SelectionExtensionActionTypes;
16
- }({});
16
+ }({});
17
+
18
+ /**
19
+ * Common fields applicable to all extension menu items
20
+ */
21
+
22
+ /**
23
+ * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
24
+ */
25
+
26
+ /**
27
+ * Fields for a dropdown menu item (i.e., an item that has nested menu items)
28
+ */
29
+
30
+ /**
31
+ * A type which marks all fields from ExtensionMenuItemDropdownMenuConfiguration and ExtensionMenuItemLeafConfiguration
32
+ * as never, ensuring that only one of the two can be present at a time to avoid misconfigurations
33
+ */
34
+
35
+ /**
36
+ * We intentionally only support leaf menu items nested within dropdown menu items so that there will
37
+ * be at max two levels of nesting from extension menu items.
38
+ */
@@ -54,22 +54,4 @@ export const getMenuItemExtensions = (extensionList, targetSource) => {
54
54
  }
55
55
  return acc;
56
56
  }, []);
57
- };
58
- export const getBlockMenuItemExtensions = (extensionList, targetSource) => {
59
- return extensionList.reduce((acc, extension) => {
60
- const {
61
- source,
62
- blockMenu
63
- } = extension;
64
- if (source === targetSource && blockMenu !== null && blockMenu !== void 0 && blockMenu.getMenuItem) {
65
- var _blockMenu$getNestedM;
66
- const menuItem = blockMenu.getMenuItem();
67
- const nestedMenuItems = (_blockMenu$getNestedM = blockMenu.getNestedMenuItems) === null || _blockMenu$getNestedM === void 0 ? void 0 : _blockMenu$getNestedM.call(blockMenu);
68
- acc.push({
69
- menuItem,
70
- nestedMenuItems
71
- });
72
- }
73
- return acc;
74
- }, []);
75
57
  };
@@ -1,106 +1,27 @@
1
1
  import React from 'react';
2
- import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
- import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
4
- import { getBlockMenuItemExtensions } from '../extensions';
2
+ import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
5
3
  export function registerBlockMenuItems(extensionList, api) {
6
- const blockMenuExtensions = getBlockMenuItemExtensions(extensionList, 'first-party');
7
- if (!(blockMenuExtensions !== null && blockMenuExtensions !== void 0 && blockMenuExtensions.length)) {
8
- return;
9
- }
10
- blockMenuExtensions.forEach((extension, index) => {
11
- const menuItem = extension.menuItem;
12
- const nestedMenuItems = extension.nestedMenuItems;
13
- const blockMenuItemKey = `selection-extension-${index}`;
14
-
15
- // If there are nested menu items, create a nested dropdown menu
16
- if (nestedMenuItems && nestedMenuItems.length > 0) {
17
- var _api$blockMenu;
18
- const nestedMenuComponents = [{
19
- type: 'block-menu-nested',
20
- key: `${blockMenuItemKey}-nested`,
21
- parent: {
22
- type: 'block-menu-section',
23
- key: 'block-menu-section-primary',
24
- rank: 200
25
- },
26
- component: ({
27
- children
28
- } = {
29
- children: null
30
- }) => {
31
- return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
32
- text: menuItem.label,
33
- elemBefore: menuItem.icon ? /*#__PURE__*/React.createElement(menuItem.icon, {
34
- label: ''
35
- }) : undefined,
36
- elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
37
- label: 'nested menu'
38
- })
39
- }, children);
40
- }
41
- }, {
4
+ extensionList.forEach(({
5
+ source,
6
+ key,
7
+ blockMenu
8
+ }, index) => {
9
+ var _api$blockMenu;
10
+ if (source !== 'first-party' || !blockMenu) {
11
+ return;
12
+ }
13
+ api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents([{
14
+ type: 'block-menu-item',
15
+ key: `selection-extension-${key}`,
16
+ parent: {
42
17
  type: 'block-menu-section',
43
- key: `${blockMenuItemKey}-nested-section`,
44
- parent: {
45
- type: 'block-menu-nested',
46
- key: `${blockMenuItemKey}-nested`,
47
- rank: 100
48
- },
49
- component: ({
50
- children
51
- } = {
52
- children: null
53
- }) => {
54
- return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
55
- }
18
+ key: TRANSFORM_CREATE_MENU_SECTION.key,
19
+ rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
56
20
  },
57
- // Add nested menu items
58
- ...nestedMenuItems.reduce((acc, nestedItem, nestedIndex) => {
59
- if ('label' in nestedItem) {
60
- acc.push({
61
- type: 'block-menu-item',
62
- key: `${blockMenuItemKey}-nested-item-${nestedIndex}`,
63
- parent: {
64
- type: 'block-menu-section',
65
- key: `${blockMenuItemKey}-nested-section`,
66
- rank: nestedIndex + 100
67
- },
68
- component: () => {
69
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
70
- elemBefore: nestedItem.icon ? /*#__PURE__*/React.createElement(nestedItem.icon, {
71
- label: ''
72
- }) : undefined,
73
- onClick: nestedItem.onClick,
74
- isDisabled: nestedItem.isDisabled
75
- }, nestedItem.label);
76
- }
77
- });
78
- }
79
- return acc;
80
- }, [])];
81
- api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents(nestedMenuComponents);
82
- } else {
83
- var _api$blockMenu2;
84
- // If no nested items, create a regular menu item
85
- const blockMenuComponent = [{
86
- type: 'block-menu-item',
87
- key: blockMenuItemKey,
88
- parent: {
89
- type: 'block-menu-section',
90
- key: 'block-menu-section-primary',
91
- rank: 200
92
- },
93
- component: () => {
94
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
95
- elemBefore: menuItem.icon ? /*#__PURE__*/React.createElement(menuItem.icon, {
96
- label: ''
97
- }) : undefined,
98
- onClick: menuItem.onClick,
99
- isDisabled: menuItem.isDisabled
100
- }, menuItem.label);
101
- }
102
- }];
103
- api === null || api === void 0 ? void 0 : (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.registerBlockMenuComponents(blockMenuComponent);
104
- }
21
+ component: () => {
22
+ // EDITOR-2772 implementation of rendering in next PR
23
+ return /*#__PURE__*/React.createElement("div", null, "Placeholder");
24
+ }
25
+ }]);
105
26
  });
106
27
  }
@@ -13,4 +13,26 @@ export var SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
13
13
  SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
14
14
  SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
15
15
  return SelectionExtensionActionTypes;
16
- }({});
16
+ }({});
17
+
18
+ /**
19
+ * Common fields applicable to all extension menu items
20
+ */
21
+
22
+ /**
23
+ * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
24
+ */
25
+
26
+ /**
27
+ * Fields for a dropdown menu item (i.e., an item that has nested menu items)
28
+ */
29
+
30
+ /**
31
+ * A type which marks all fields from ExtensionMenuItemDropdownMenuConfiguration and ExtensionMenuItemLeafConfiguration
32
+ * as never, ensuring that only one of the two can be present at a time to avoid misconfigurations
33
+ */
34
+
35
+ /**
36
+ * We intentionally only support leaf menu items nested within dropdown menu items so that there will
37
+ * be at max two levels of nesting from extension menu items.
38
+ */
@@ -54,20 +54,4 @@ export var getMenuItemExtensions = function getMenuItemExtensions(extensionList,
54
54
  }
55
55
  return acc;
56
56
  }, []);
57
- };
58
- export var getBlockMenuItemExtensions = function getBlockMenuItemExtensions(extensionList, targetSource) {
59
- return extensionList.reduce(function (acc, extension) {
60
- var source = extension.source,
61
- blockMenu = extension.blockMenu;
62
- if (source === targetSource && blockMenu !== null && blockMenu !== void 0 && blockMenu.getMenuItem) {
63
- var _blockMenu$getNestedM;
64
- var menuItem = blockMenu.getMenuItem();
65
- var nestedMenuItems = (_blockMenu$getNestedM = blockMenu.getNestedMenuItems) === null || _blockMenu$getNestedM === void 0 ? void 0 : _blockMenu$getNestedM.call(blockMenu);
66
- acc.push({
67
- menuItem: menuItem,
68
- nestedMenuItems: nestedMenuItems
69
- });
70
- }
71
- return acc;
72
- }, []);
73
57
  };
@@ -1,105 +1,26 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import React from 'react';
3
- import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
4
- import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
5
- import { getBlockMenuItemExtensions } from '../extensions';
2
+ import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
6
3
  export function registerBlockMenuItems(extensionList, api) {
7
- var blockMenuExtensions = getBlockMenuItemExtensions(extensionList, 'first-party');
8
- if (!(blockMenuExtensions !== null && blockMenuExtensions !== void 0 && blockMenuExtensions.length)) {
9
- return;
10
- }
11
- blockMenuExtensions.forEach(function (extension, index) {
12
- var menuItem = extension.menuItem;
13
- var nestedMenuItems = extension.nestedMenuItems;
14
- var blockMenuItemKey = "selection-extension-".concat(index);
15
-
16
- // If there are nested menu items, create a nested dropdown menu
17
- if (nestedMenuItems && nestedMenuItems.length > 0) {
18
- var _api$blockMenu;
19
- var nestedMenuComponents = [{
20
- type: 'block-menu-nested',
21
- key: "".concat(blockMenuItemKey, "-nested"),
22
- parent: {
23
- type: 'block-menu-section',
24
- key: 'block-menu-section-primary',
25
- rank: 200
26
- },
27
- component: function component() {
28
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
29
- children: null
30
- },
31
- children = _ref.children;
32
- return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
33
- text: menuItem.label,
34
- elemBefore: menuItem.icon ? /*#__PURE__*/React.createElement(menuItem.icon, {
35
- label: ''
36
- }) : undefined,
37
- elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
38
- label: 'nested menu'
39
- })
40
- }, children);
41
- }
42
- }, {
43
- type: 'block-menu-section',
44
- key: "".concat(blockMenuItemKey, "-nested-section"),
45
- parent: {
46
- type: 'block-menu-nested',
47
- key: "".concat(blockMenuItemKey, "-nested"),
48
- rank: 100
49
- },
50
- component: function component() {
51
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
52
- children: null
53
- },
54
- children = _ref2.children;
55
- return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
56
- }
57
- }].concat(_toConsumableArray(nestedMenuItems.reduce(function (acc, nestedItem, nestedIndex) {
58
- if ('label' in nestedItem) {
59
- acc.push({
60
- type: 'block-menu-item',
61
- key: "".concat(blockMenuItemKey, "-nested-item-").concat(nestedIndex),
62
- parent: {
63
- type: 'block-menu-section',
64
- key: "".concat(blockMenuItemKey, "-nested-section"),
65
- rank: nestedIndex + 100
66
- },
67
- component: function component() {
68
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
69
- elemBefore: nestedItem.icon ? /*#__PURE__*/React.createElement(nestedItem.icon, {
70
- label: ''
71
- }) : undefined,
72
- onClick: nestedItem.onClick,
73
- isDisabled: nestedItem.isDisabled
74
- }, nestedItem.label);
75
- }
76
- });
77
- }
78
- return acc;
79
- }, [])));
80
- api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents(nestedMenuComponents);
81
- } else {
82
- var _api$blockMenu2;
83
- // If no nested items, create a regular menu item
84
- var blockMenuComponent = [{
85
- type: 'block-menu-item',
86
- key: blockMenuItemKey,
87
- parent: {
88
- type: 'block-menu-section',
89
- key: 'block-menu-section-primary',
90
- rank: 200
91
- },
92
- component: function component() {
93
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
94
- elemBefore: menuItem.icon ? /*#__PURE__*/React.createElement(menuItem.icon, {
95
- label: ''
96
- }) : undefined,
97
- onClick: menuItem.onClick,
98
- isDisabled: menuItem.isDisabled
99
- }, menuItem.label);
100
- }
101
- }];
102
- api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 || _api$blockMenu2.actions.registerBlockMenuComponents(blockMenuComponent);
4
+ extensionList.forEach(function (_ref, index) {
5
+ var _api$blockMenu;
6
+ var source = _ref.source,
7
+ key = _ref.key,
8
+ blockMenu = _ref.blockMenu;
9
+ if (source !== 'first-party' || !blockMenu) {
10
+ return;
103
11
  }
12
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
13
+ type: 'block-menu-item',
14
+ key: "selection-extension-".concat(key),
15
+ parent: {
16
+ type: 'block-menu-section',
17
+ key: TRANSFORM_CREATE_MENU_SECTION.key,
18
+ rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
19
+ },
20
+ component: function component() {
21
+ // EDITOR-2772 implementation of rendering in next PR
22
+ return /*#__PURE__*/React.createElement("div", null, "Placeholder");
23
+ }
24
+ }]);
104
25
  });
105
26
  }
@@ -1,3 +1,4 @@
1
+ import type { ComponentType, PropsWithChildren } from 'react';
1
2
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
3
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
3
4
  import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
@@ -27,8 +28,8 @@ export type SelectionCoords = {
27
28
  top: number;
28
29
  };
29
30
  export type SelectionExtension = {
30
- component?: React.ComponentType<SelectionExtensionComponentProps>;
31
- icon?: React.ComponentType<React.PropsWithChildren<{
31
+ component?: ComponentType<SelectionExtensionComponentProps>;
32
+ icon?: ComponentType<PropsWithChildren<{
32
33
  label: string;
33
34
  }>>;
34
35
  isDisabled?: (params: SelectionExtensionCallbackOptions) => boolean;
@@ -125,21 +126,17 @@ export type ExtensionConfiguration = {
125
126
  source: ExtensionSource;
126
127
  };
127
128
  export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
128
- export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
129
- export type GetMenuItemFn = () => Omit<ExtensionMenuItemConfiguration, 'section'>;
130
- export type BlockMenuItemConfiguration = Omit<ExtensionMenuItemConfiguration, 'contentComponent'>;
131
- export type GetBlockMenuItemFn = () => Omit<BlockMenuItemConfiguration, 'section'>;
132
- export type GetBlockMenuNestedItemsFn = () => Array<BlockMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
129
+ export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration>;
130
+ export type GetNestedMenuItemsFn = () => Array<ExtensionMenuItemNestedConfiguration>;
133
131
  export type ToolbarExtensionConfiguration = {
134
132
  getMenuItems?: GetMenuItemsFn;
135
133
  getToolbarItem?: GetToolbarItemFn;
136
134
  };
137
135
  export type BlockMenuExtensionConfiguration = {
138
- getMenuItem: GetBlockMenuItemFn;
139
- getNestedMenuItems?: GetBlockMenuNestedItemsFn;
136
+ getMenuItems: GetMenuItemsFn;
140
137
  };
141
138
  export type ExtensionToolbarItemConfiguration = {
142
- icon: React.ComponentType<React.PropsWithChildren<{
139
+ icon: ComponentType<PropsWithChildren<{
143
140
  label: string;
144
141
  }>>;
145
142
  isDisabled?: boolean;
@@ -147,14 +144,27 @@ export type ExtensionToolbarItemConfiguration = {
147
144
  onClick?: () => void;
148
145
  tooltip: string;
149
146
  };
150
- export type ExtensionMenuItemConfiguration = {
151
- contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
152
- icon: React.ComponentType<React.PropsWithChildren<{
147
+ /**
148
+ * Common fields applicable to all extension menu items
149
+ */
150
+ type ExtensionMenuItemBaseConfiguration = {
151
+ icon: ComponentType<PropsWithChildren<{
153
152
  label: string;
154
153
  size?: 'small' | 'medium';
155
154
  }>>;
156
- isDisabled?: boolean;
157
155
  label: string;
156
+ isDisabled?: boolean;
157
+ };
158
+ /**
159
+ * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
160
+ */
161
+ type ExtensionMenuItemLeafConfiguration = {
162
+ /**
163
+ * Optional content component to render when this menu item is selected
164
+ *
165
+ * Used for forge app extensions that need to render custom UI when selected from the block menu.
166
+ */
167
+ contentComponent?: ComponentType<SelectionExtensionComponentProps>;
158
168
  /**
159
169
  * Optional lozenge to display next to the label in the menu
160
170
  */
@@ -162,17 +172,25 @@ export type ExtensionMenuItemConfiguration = {
162
172
  label: string;
163
173
  };
164
174
  onClick?: () => void;
165
- /**
166
- * Optional menu-section to declare grouping - only used for menu items
167
- */
168
- section?: {
169
- key: string;
170
- rank: number;
171
- };
172
175
  };
173
- export type ExtensionMenuSectionConfiguration = {
174
- key: string;
175
- rank: number;
176
- title?: string;
176
+ /**
177
+ * Fields for a dropdown menu item (i.e., an item that has nested menu items)
178
+ */
179
+ type ExtensionMenuItemDropdownMenuConfiguration = {
180
+ getMenuItems: GetNestedMenuItemsFn;
177
181
  };
182
+ type AllNever<T> = {
183
+ [K in keyof T]?: never;
184
+ };
185
+ /**
186
+ * A type which marks all fields from ExtensionMenuItemDropdownMenuConfiguration and ExtensionMenuItemLeafConfiguration
187
+ * as never, ensuring that only one of the two can be present at a time to avoid misconfigurations
188
+ */
189
+ type ExtensionMenuItemUnsupportedConfiguration = AllNever<ExtensionMenuItemDropdownMenuConfiguration | ExtensionMenuItemLeafConfiguration>;
190
+ export type ExtensionMenuItemConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemUnsupportedConfiguration & (ExtensionMenuItemLeafConfiguration | ExtensionMenuItemDropdownMenuConfiguration);
191
+ /**
192
+ * We intentionally only support leaf menu items nested within dropdown menu items so that there will
193
+ * be at max two levels of nesting from extension menu items.
194
+ */
195
+ type ExtensionMenuItemNestedConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemLeafConfiguration;
178
196
  export {};
@@ -1,4 +1,4 @@
1
- import type { ExtensionConfiguration, ExtensionSource, GetBlockMenuItemFn, GetBlockMenuNestedItemsFn, GetMenuItemsFn, GetToolbarItemFn, SelectionExtension } from '../types';
1
+ import type { ExtensionConfiguration, ExtensionSource, GetMenuItemsFn, GetToolbarItemFn, SelectionExtension } from '../types';
2
2
  export type ToolbarItemExtension = {
3
3
  getMenuItems?: GetMenuItemsFn;
4
4
  getToolbarItem: GetToolbarItemFn;
@@ -25,9 +25,3 @@ export declare const getToolbarItemExtensions: (extensionList: ExtensionConfigur
25
25
  * @example
26
26
  */
27
27
  export declare const getMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => SelectionExtension[];
28
- type BlockMenuItems = {
29
- menuItem: ReturnType<GetBlockMenuItemFn>;
30
- nestedMenuItems?: ReturnType<GetBlockMenuNestedItemsFn>;
31
- };
32
- export declare const getBlockMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => BlockMenuItems[];
33
- export {};
@@ -1,3 +1,4 @@
1
+ import type { ComponentType, PropsWithChildren } from 'react';
1
2
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
3
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
3
4
  import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
@@ -27,8 +28,8 @@ export type SelectionCoords = {
27
28
  top: number;
28
29
  };
29
30
  export type SelectionExtension = {
30
- component?: React.ComponentType<SelectionExtensionComponentProps>;
31
- icon?: React.ComponentType<React.PropsWithChildren<{
31
+ component?: ComponentType<SelectionExtensionComponentProps>;
32
+ icon?: ComponentType<PropsWithChildren<{
32
33
  label: string;
33
34
  }>>;
34
35
  isDisabled?: (params: SelectionExtensionCallbackOptions) => boolean;
@@ -125,21 +126,17 @@ export type ExtensionConfiguration = {
125
126
  source: ExtensionSource;
126
127
  };
127
128
  export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
128
- export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
129
- export type GetMenuItemFn = () => Omit<ExtensionMenuItemConfiguration, 'section'>;
130
- export type BlockMenuItemConfiguration = Omit<ExtensionMenuItemConfiguration, 'contentComponent'>;
131
- export type GetBlockMenuItemFn = () => Omit<BlockMenuItemConfiguration, 'section'>;
132
- export type GetBlockMenuNestedItemsFn = () => Array<BlockMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
129
+ export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration>;
130
+ export type GetNestedMenuItemsFn = () => Array<ExtensionMenuItemNestedConfiguration>;
133
131
  export type ToolbarExtensionConfiguration = {
134
132
  getMenuItems?: GetMenuItemsFn;
135
133
  getToolbarItem?: GetToolbarItemFn;
136
134
  };
137
135
  export type BlockMenuExtensionConfiguration = {
138
- getMenuItem: GetBlockMenuItemFn;
139
- getNestedMenuItems?: GetBlockMenuNestedItemsFn;
136
+ getMenuItems: GetMenuItemsFn;
140
137
  };
141
138
  export type ExtensionToolbarItemConfiguration = {
142
- icon: React.ComponentType<React.PropsWithChildren<{
139
+ icon: ComponentType<PropsWithChildren<{
143
140
  label: string;
144
141
  }>>;
145
142
  isDisabled?: boolean;
@@ -147,14 +144,27 @@ export type ExtensionToolbarItemConfiguration = {
147
144
  onClick?: () => void;
148
145
  tooltip: string;
149
146
  };
150
- export type ExtensionMenuItemConfiguration = {
151
- contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
152
- icon: React.ComponentType<React.PropsWithChildren<{
147
+ /**
148
+ * Common fields applicable to all extension menu items
149
+ */
150
+ type ExtensionMenuItemBaseConfiguration = {
151
+ icon: ComponentType<PropsWithChildren<{
153
152
  label: string;
154
153
  size?: 'small' | 'medium';
155
154
  }>>;
156
- isDisabled?: boolean;
157
155
  label: string;
156
+ isDisabled?: boolean;
157
+ };
158
+ /**
159
+ * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
160
+ */
161
+ type ExtensionMenuItemLeafConfiguration = {
162
+ /**
163
+ * Optional content component to render when this menu item is selected
164
+ *
165
+ * Used for forge app extensions that need to render custom UI when selected from the block menu.
166
+ */
167
+ contentComponent?: ComponentType<SelectionExtensionComponentProps>;
158
168
  /**
159
169
  * Optional lozenge to display next to the label in the menu
160
170
  */
@@ -162,17 +172,25 @@ export type ExtensionMenuItemConfiguration = {
162
172
  label: string;
163
173
  };
164
174
  onClick?: () => void;
165
- /**
166
- * Optional menu-section to declare grouping - only used for menu items
167
- */
168
- section?: {
169
- key: string;
170
- rank: number;
171
- };
172
175
  };
173
- export type ExtensionMenuSectionConfiguration = {
174
- key: string;
175
- rank: number;
176
- title?: string;
176
+ /**
177
+ * Fields for a dropdown menu item (i.e., an item that has nested menu items)
178
+ */
179
+ type ExtensionMenuItemDropdownMenuConfiguration = {
180
+ getMenuItems: GetNestedMenuItemsFn;
177
181
  };
182
+ type AllNever<T> = {
183
+ [K in keyof T]?: never;
184
+ };
185
+ /**
186
+ * A type which marks all fields from ExtensionMenuItemDropdownMenuConfiguration and ExtensionMenuItemLeafConfiguration
187
+ * as never, ensuring that only one of the two can be present at a time to avoid misconfigurations
188
+ */
189
+ type ExtensionMenuItemUnsupportedConfiguration = AllNever<ExtensionMenuItemDropdownMenuConfiguration | ExtensionMenuItemLeafConfiguration>;
190
+ export type ExtensionMenuItemConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemUnsupportedConfiguration & (ExtensionMenuItemLeafConfiguration | ExtensionMenuItemDropdownMenuConfiguration);
191
+ /**
192
+ * We intentionally only support leaf menu items nested within dropdown menu items so that there will
193
+ * be at max two levels of nesting from extension menu items.
194
+ */
195
+ type ExtensionMenuItemNestedConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemLeafConfiguration;
178
196
  export {};
@@ -1,4 +1,4 @@
1
- import type { ExtensionConfiguration, ExtensionSource, GetBlockMenuItemFn, GetBlockMenuNestedItemsFn, GetMenuItemsFn, GetToolbarItemFn, SelectionExtension } from '../types';
1
+ import type { ExtensionConfiguration, ExtensionSource, GetMenuItemsFn, GetToolbarItemFn, SelectionExtension } from '../types';
2
2
  export type ToolbarItemExtension = {
3
3
  getMenuItems?: GetMenuItemsFn;
4
4
  getToolbarItem: GetToolbarItemFn;
@@ -25,9 +25,3 @@ export declare const getToolbarItemExtensions: (extensionList: ExtensionConfigur
25
25
  * @example
26
26
  */
27
27
  export declare const getMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => SelectionExtension[];
28
- type BlockMenuItems = {
29
- menuItem: ReturnType<GetBlockMenuItemFn>;
30
- nestedMenuItems?: ReturnType<GetBlockMenuNestedItemsFn>;
31
- };
32
- export declare const getBlockMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => BlockMenuItems[];
33
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "7.2.1",
3
+ "version": "9.0.0",
4
4
  "description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/platform-feature-flags": "^1.1.0",
52
52
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
53
53
  "@atlaskit/primitives": "^16.4.0",
54
- "@atlaskit/tmp-editor-statsig": "^14.8.0",
54
+ "@atlaskit/tmp-editor-statsig": "^14.9.0",
55
55
  "@babel/runtime": "^7.0.0",
56
56
  "lodash": "^4.17.21",
57
57
  "react-intl-next": "npm:react-intl@^5.18.1",