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

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 (30) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/types/index.js +7 -6
  3. package/dist/cjs/ui/menu/SelectionExtensionDropdownItem.js +20 -0
  4. package/dist/cjs/ui/menu/SelectionExtensionDropdownMenu.js +37 -0
  5. package/dist/cjs/ui/menu/SelectionExtensionMenuItems.js +30 -0
  6. package/dist/cjs/ui/utils/menu-items.js +15 -0
  7. package/dist/cjs/ui/utils/registerBlockMenuItems.js +5 -3
  8. package/dist/es2019/types/index.js +7 -6
  9. package/dist/es2019/ui/menu/SelectionExtensionDropdownItem.js +13 -0
  10. package/dist/es2019/ui/menu/SelectionExtensionDropdownMenu.js +28 -0
  11. package/dist/es2019/ui/menu/SelectionExtensionMenuItems.js +24 -0
  12. package/dist/es2019/ui/utils/menu-items.js +9 -0
  13. package/dist/es2019/ui/utils/registerBlockMenuItems.js +5 -3
  14. package/dist/esm/types/index.js +7 -6
  15. package/dist/esm/ui/menu/SelectionExtensionDropdownItem.js +12 -0
  16. package/dist/esm/ui/menu/SelectionExtensionDropdownMenu.js +28 -0
  17. package/dist/esm/ui/menu/SelectionExtensionMenuItems.js +23 -0
  18. package/dist/esm/ui/utils/menu-items.js +9 -0
  19. package/dist/esm/ui/utils/registerBlockMenuItems.js +5 -3
  20. package/dist/types/types/index.d.ts +13 -11
  21. package/dist/types/ui/menu/SelectionExtensionDropdownItem.d.ts +7 -0
  22. package/dist/types/ui/menu/SelectionExtensionDropdownMenu.d.ts +6 -0
  23. package/dist/types/ui/menu/SelectionExtensionMenuItems.d.ts +7 -0
  24. package/dist/types/ui/utils/menu-items.d.ts +8 -0
  25. package/dist/types-ts4.5/types/index.d.ts +13 -11
  26. package/dist/types-ts4.5/ui/menu/SelectionExtensionDropdownItem.d.ts +7 -0
  27. package/dist/types-ts4.5/ui/menu/SelectionExtensionDropdownMenu.d.ts +6 -0
  28. package/dist/types-ts4.5/ui/menu/SelectionExtensionMenuItems.d.ts +7 -0
  29. package/dist/types-ts4.5/ui/utils/menu-items.d.ts +8 -0
  30. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 9.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`609229c9d51fd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/609229c9d51fd) -
8
+ EDITOR-2772 Implement new rendering of block menu selection extensions
9
+ - Updated dependencies
10
+
11
+ ## 9.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 9.0.0
4
18
 
5
19
  ### Major Changes
@@ -22,16 +22,17 @@ var SelectionExtensionActionTypes = exports.SelectionExtensionActionTypes = /*#_
22
22
  * Common fields applicable to all extension menu items
23
23
  */
24
24
  /**
25
- * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
25
+ * Fields for a dropdown item (i.e., an item that does not have further nested menu items)
26
26
  */
27
27
  /**
28
- * Fields for a dropdown menu item (i.e., an item that has nested menu items)
28
+ * Fields for a nested dropdown menu (i.e., an menu item that has further nested menu items)
29
29
  */
30
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
31
+ * This type represents either a dropdown item or a dropdown menu, but not both.
32
+ *
33
+ * We mark all fields of the other type as `never` to enforce this exclusivity.
33
34
  */
34
35
  /**
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.
36
+ * We intentionally only support dropdown items nested within dropdown menus, i.e. no menus nested
37
+ * within menus – so there will be at max two levels of nesting from extension menu items
37
38
  */
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SelectionExtensionDropdownItem = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
11
+ var SelectionExtensionDropdownItem = exports.SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
12
+ var dropdownItem = _ref.dropdownItem;
13
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
14
+ elemBefore: dropdownItem.icon ? /*#__PURE__*/(0, _react.createElement)(dropdownItem.icon, {
15
+ label: ''
16
+ }) : undefined,
17
+ onClick: dropdownItem.onClick,
18
+ isDisabled: dropdownItem.isDisabled
19
+ }, dropdownItem.label);
20
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.SelectionExtensionNestedDropdownMenu = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
11
+ var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
12
+ var _SelectionExtensionDropdownItem = require("./SelectionExtensionDropdownItem");
13
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
14
+ var ChildItems = function ChildItems(_ref) {
15
+ var nestedDropdownMenu = _ref.nestedDropdownMenu;
16
+ var childItems = nestedDropdownMenu.getMenuItems();
17
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, childItems.map(function (dropdownItem) {
18
+ return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
19
+ key: dropdownItem.label,
20
+ dropdownItem: dropdownItem
21
+ });
22
+ }));
23
+ };
24
+ var SelectionExtensionNestedDropdownMenu = exports.SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
25
+ var nestedDropdownMenu = _ref2.nestedDropdownMenu;
26
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
27
+ text: nestedDropdownMenu.label,
28
+ elemBefore: nestedDropdownMenu.icon ? /*#__PURE__*/(0, _react.createElement)(nestedDropdownMenu.icon, {
29
+ label: ''
30
+ }) : undefined,
31
+ elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
32
+ label: 'nested menu'
33
+ })
34
+ }, /*#__PURE__*/_react.default.createElement(ChildItems, {
35
+ nestedDropdownMenu: nestedDropdownMenu
36
+ }));
37
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SelectionExtensionMenuItems = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _menuItems = require("../utils/menu-items");
10
+ var _SelectionExtensionDropdownItem = require("./SelectionExtensionDropdownItem");
11
+ var _SelectionExtensionDropdownMenu = require("./SelectionExtensionDropdownMenu");
12
+ var SelectionExtensionMenuItems = exports.SelectionExtensionMenuItems = function SelectionExtensionMenuItems(_ref) {
13
+ var getMenuItems = _ref.getMenuItems;
14
+ var extensionMenuItems = getMenuItems();
15
+ if (!(extensionMenuItems !== null && extensionMenuItems !== void 0 && extensionMenuItems.length)) {
16
+ return null;
17
+ }
18
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, extensionMenuItems.map(function (item) {
19
+ if ((0, _menuItems.isNestedDropdownMenuConfiguration)(item)) {
20
+ return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownMenu.SelectionExtensionNestedDropdownMenu, {
21
+ key: item.label,
22
+ nestedDropdownMenu: item
23
+ });
24
+ }
25
+ return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
26
+ key: item.label,
27
+ dropdownItem: item
28
+ });
29
+ }));
30
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNestedDropdownMenuConfiguration = void 0;
7
+ /**
8
+ * Type guard to check if the given configuration is for a dropdown menu.
9
+ *
10
+ * @param item - The menu item configuration to check, either menu item or dropdown menu
11
+ * @returns True if the item configuration is for a dropdown menu, false otherwise
12
+ */
13
+ var isNestedDropdownMenuConfiguration = exports.isNestedDropdownMenuConfiguration = function isNestedDropdownMenuConfiguration(item) {
14
+ return 'getMenuItems' in item && typeof item.getMenuItems === 'function';
15
+ };
@@ -7,8 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.registerBlockMenuItems = registerBlockMenuItems;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _blockMenu = require("@atlaskit/editor-common/block-menu");
10
+ var _SelectionExtensionMenuItems = require("../menu/SelectionExtensionMenuItems");
10
11
  function registerBlockMenuItems(extensionList, api) {
11
- extensionList.forEach(function (_ref, index) {
12
+ extensionList.forEach(function (_ref) {
12
13
  var _api$blockMenu;
13
14
  var source = _ref.source,
14
15
  key = _ref.key,
@@ -25,8 +26,9 @@ function registerBlockMenuItems(extensionList, api) {
25
26
  rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
26
27
  },
27
28
  component: function component() {
28
- // EDITOR-2772 implementation of rendering in next PR
29
- return /*#__PURE__*/_react.default.createElement("div", null, "Placeholder");
29
+ return /*#__PURE__*/_react.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
30
+ getMenuItems: blockMenu.getMenuItems
31
+ });
30
32
  }
31
33
  }]);
32
34
  });
@@ -20,19 +20,20 @@ export let SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
20
20
  */
21
21
 
22
22
  /**
23
- * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
23
+ * Fields for a dropdown item (i.e., an item that does not have further nested menu items)
24
24
  */
25
25
 
26
26
  /**
27
- * Fields for a dropdown menu item (i.e., an item that has nested menu items)
27
+ * Fields for a nested dropdown menu (i.e., an menu item that has further nested menu items)
28
28
  */
29
29
 
30
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
31
+ * This type represents either a dropdown item or a dropdown menu, but not both.
32
+ *
33
+ * We mark all fields of the other type as `never` to enforce this exclusivity.
33
34
  */
34
35
 
35
36
  /**
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.
37
+ * We intentionally only support dropdown items nested within dropdown menus, i.e. no menus nested
38
+ * within menus – so there will be at max two levels of nesting from extension menu items
38
39
  */
@@ -0,0 +1,13 @@
1
+ import React, { createElement } from 'react';
2
+ import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
3
+ export const SelectionExtensionDropdownItem = ({
4
+ dropdownItem
5
+ }) => {
6
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
7
+ elemBefore: dropdownItem.icon ? /*#__PURE__*/createElement(dropdownItem.icon, {
8
+ label: ''
9
+ }) : undefined,
10
+ onClick: dropdownItem.onClick,
11
+ isDisabled: dropdownItem.isDisabled
12
+ }, dropdownItem.label);
13
+ };
@@ -0,0 +1,28 @@
1
+ import React, { createElement } from 'react';
2
+ import { ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
+ import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
4
+ import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
5
+ const ChildItems = ({
6
+ nestedDropdownMenu
7
+ }) => {
8
+ const childItems = nestedDropdownMenu.getMenuItems();
9
+ return /*#__PURE__*/React.createElement(React.Fragment, null, childItems.map(dropdownItem => /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
10
+ key: dropdownItem.label,
11
+ dropdownItem: dropdownItem
12
+ })));
13
+ };
14
+ export const SelectionExtensionNestedDropdownMenu = ({
15
+ nestedDropdownMenu
16
+ }) => {
17
+ return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
18
+ text: nestedDropdownMenu.label,
19
+ elemBefore: nestedDropdownMenu.icon ? /*#__PURE__*/createElement(nestedDropdownMenu.icon, {
20
+ label: ''
21
+ }) : undefined,
22
+ elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
23
+ label: 'nested menu'
24
+ })
25
+ }, /*#__PURE__*/React.createElement(ChildItems, {
26
+ nestedDropdownMenu: nestedDropdownMenu
27
+ }));
28
+ };
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { isNestedDropdownMenuConfiguration } from '../utils/menu-items';
3
+ import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
4
+ import { SelectionExtensionNestedDropdownMenu } from './SelectionExtensionDropdownMenu';
5
+ export const SelectionExtensionMenuItems = ({
6
+ getMenuItems
7
+ }) => {
8
+ const extensionMenuItems = getMenuItems();
9
+ if (!(extensionMenuItems !== null && extensionMenuItems !== void 0 && extensionMenuItems.length)) {
10
+ return null;
11
+ }
12
+ return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(item => {
13
+ if (isNestedDropdownMenuConfiguration(item)) {
14
+ return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
15
+ key: item.label,
16
+ nestedDropdownMenu: item
17
+ });
18
+ }
19
+ return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
20
+ key: item.label,
21
+ dropdownItem: item
22
+ });
23
+ }));
24
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type guard to check if the given configuration is for a dropdown menu.
3
+ *
4
+ * @param item - The menu item configuration to check, either menu item or dropdown menu
5
+ * @returns True if the item configuration is for a dropdown menu, false otherwise
6
+ */
7
+ export const isNestedDropdownMenuConfiguration = item => {
8
+ return 'getMenuItems' in item && typeof item.getMenuItems === 'function';
9
+ };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
3
+ import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
3
4
  export function registerBlockMenuItems(extensionList, api) {
4
5
  extensionList.forEach(({
5
6
  source,
6
7
  key,
7
8
  blockMenu
8
- }, index) => {
9
+ }) => {
9
10
  var _api$blockMenu;
10
11
  if (source !== 'first-party' || !blockMenu) {
11
12
  return;
@@ -19,8 +20,9 @@ export function registerBlockMenuItems(extensionList, api) {
19
20
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
20
21
  },
21
22
  component: () => {
22
- // EDITOR-2772 implementation of rendering in next PR
23
- return /*#__PURE__*/React.createElement("div", null, "Placeholder");
23
+ return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
24
+ getMenuItems: blockMenu.getMenuItems
25
+ });
24
26
  }
25
27
  }]);
26
28
  });
@@ -20,19 +20,20 @@ export var SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
20
20
  */
21
21
 
22
22
  /**
23
- * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
23
+ * Fields for a dropdown item (i.e., an item that does not have further nested menu items)
24
24
  */
25
25
 
26
26
  /**
27
- * Fields for a dropdown menu item (i.e., an item that has nested menu items)
27
+ * Fields for a nested dropdown menu (i.e., an menu item that has further nested menu items)
28
28
  */
29
29
 
30
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
31
+ * This type represents either a dropdown item or a dropdown menu, but not both.
32
+ *
33
+ * We mark all fields of the other type as `never` to enforce this exclusivity.
33
34
  */
34
35
 
35
36
  /**
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.
37
+ * We intentionally only support dropdown items nested within dropdown menus, i.e. no menus nested
38
+ * within menus – so there will be at max two levels of nesting from extension menu items
38
39
  */
@@ -0,0 +1,12 @@
1
+ import React, { createElement } from 'react';
2
+ import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
3
+ export var SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
4
+ var dropdownItem = _ref.dropdownItem;
5
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
6
+ elemBefore: dropdownItem.icon ? /*#__PURE__*/createElement(dropdownItem.icon, {
7
+ label: ''
8
+ }) : undefined,
9
+ onClick: dropdownItem.onClick,
10
+ isDisabled: dropdownItem.isDisabled
11
+ }, dropdownItem.label);
12
+ };
@@ -0,0 +1,28 @@
1
+ import React, { createElement } from 'react';
2
+ import { ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
+ import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
4
+ import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
5
+ var ChildItems = function ChildItems(_ref) {
6
+ var nestedDropdownMenu = _ref.nestedDropdownMenu;
7
+ var childItems = nestedDropdownMenu.getMenuItems();
8
+ return /*#__PURE__*/React.createElement(React.Fragment, null, childItems.map(function (dropdownItem) {
9
+ return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
10
+ key: dropdownItem.label,
11
+ dropdownItem: dropdownItem
12
+ });
13
+ }));
14
+ };
15
+ export var SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
16
+ var nestedDropdownMenu = _ref2.nestedDropdownMenu;
17
+ return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
18
+ text: nestedDropdownMenu.label,
19
+ elemBefore: nestedDropdownMenu.icon ? /*#__PURE__*/createElement(nestedDropdownMenu.icon, {
20
+ label: ''
21
+ }) : undefined,
22
+ elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
23
+ label: 'nested menu'
24
+ })
25
+ }, /*#__PURE__*/React.createElement(ChildItems, {
26
+ nestedDropdownMenu: nestedDropdownMenu
27
+ }));
28
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { isNestedDropdownMenuConfiguration } from '../utils/menu-items';
3
+ import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
4
+ import { SelectionExtensionNestedDropdownMenu } from './SelectionExtensionDropdownMenu';
5
+ export var SelectionExtensionMenuItems = function SelectionExtensionMenuItems(_ref) {
6
+ var getMenuItems = _ref.getMenuItems;
7
+ var extensionMenuItems = getMenuItems();
8
+ if (!(extensionMenuItems !== null && extensionMenuItems !== void 0 && extensionMenuItems.length)) {
9
+ return null;
10
+ }
11
+ return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(function (item) {
12
+ if (isNestedDropdownMenuConfiguration(item)) {
13
+ return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
14
+ key: item.label,
15
+ nestedDropdownMenu: item
16
+ });
17
+ }
18
+ return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
19
+ key: item.label,
20
+ dropdownItem: item
21
+ });
22
+ }));
23
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type guard to check if the given configuration is for a dropdown menu.
3
+ *
4
+ * @param item - The menu item configuration to check, either menu item or dropdown menu
5
+ * @returns True if the item configuration is for a dropdown menu, false otherwise
6
+ */
7
+ export var isNestedDropdownMenuConfiguration = function isNestedDropdownMenuConfiguration(item) {
8
+ return 'getMenuItems' in item && typeof item.getMenuItems === 'function';
9
+ };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
3
+ import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
3
4
  export function registerBlockMenuItems(extensionList, api) {
4
- extensionList.forEach(function (_ref, index) {
5
+ extensionList.forEach(function (_ref) {
5
6
  var _api$blockMenu;
6
7
  var source = _ref.source,
7
8
  key = _ref.key,
@@ -18,8 +19,9 @@ export function registerBlockMenuItems(extensionList, api) {
18
19
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
19
20
  },
20
21
  component: function component() {
21
- // EDITOR-2772 implementation of rendering in next PR
22
- return /*#__PURE__*/React.createElement("div", null, "Placeholder");
22
+ return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
23
+ getMenuItems: blockMenu.getMenuItems
24
+ });
23
25
  }
24
26
  }]);
25
27
  });
@@ -156,9 +156,9 @@ type ExtensionMenuItemBaseConfiguration = {
156
156
  isDisabled?: boolean;
157
157
  };
158
158
  /**
159
- * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
159
+ * Fields for a dropdown item (i.e., an item that does not have further nested menu items)
160
160
  */
161
- type ExtensionMenuItemLeafConfiguration = {
161
+ type ExtensionDropdownItemFields = {
162
162
  /**
163
163
  * Optional content component to render when this menu item is selected
164
164
  *
@@ -174,23 +174,25 @@ type ExtensionMenuItemLeafConfiguration = {
174
174
  onClick?: () => void;
175
175
  };
176
176
  /**
177
- * Fields for a dropdown menu item (i.e., an item that has nested menu items)
177
+ * Fields for a nested dropdown menu (i.e., an menu item that has further nested menu items)
178
178
  */
179
- type ExtensionMenuItemDropdownMenuConfiguration = {
179
+ type ExtensionNestedDropdownMenuFields = {
180
180
  getMenuItems: GetNestedMenuItemsFn;
181
181
  };
182
+ export type ExtensionDropdownItemConfiguration = ExtensionMenuItemBaseConfiguration & AllNever<ExtensionNestedDropdownMenuFields> & ExtensionDropdownItemFields;
183
+ export type ExtensionNestedDropdownMenuConfiguration = ExtensionMenuItemBaseConfiguration & AllNever<ExtensionDropdownItemFields> & ExtensionNestedDropdownMenuFields;
182
184
  type AllNever<T> = {
183
185
  [K in keyof T]?: never;
184
186
  };
185
187
  /**
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
+ * This type represents either a dropdown item or a dropdown menu, but not both.
189
+ *
190
+ * We mark all fields of the other type as `never` to enforce this exclusivity.
188
191
  */
189
- type ExtensionMenuItemUnsupportedConfiguration = AllNever<ExtensionMenuItemDropdownMenuConfiguration | ExtensionMenuItemLeafConfiguration>;
190
- export type ExtensionMenuItemConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemUnsupportedConfiguration & (ExtensionMenuItemLeafConfiguration | ExtensionMenuItemDropdownMenuConfiguration);
192
+ export type ExtensionMenuItemConfiguration = ExtensionDropdownItemConfiguration | ExtensionNestedDropdownMenuConfiguration;
191
193
  /**
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
+ * We intentionally only support dropdown items nested within dropdown menus, i.e. no menus nested
195
+ * within menus – so there will be at max two levels of nesting from extension menu items
194
196
  */
195
- type ExtensionMenuItemNestedConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemLeafConfiguration;
197
+ type ExtensionMenuItemNestedConfiguration = ExtensionDropdownItemConfiguration;
196
198
  export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtensionDropdownItemConfiguration } from '../../types';
3
+ type SelectionExtensionDropdownItemProps = {
4
+ dropdownItem: ExtensionDropdownItemConfiguration;
5
+ };
6
+ export declare const SelectionExtensionDropdownItem: ({ dropdownItem, }: SelectionExtensionDropdownItemProps) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { type ExtensionNestedDropdownMenuConfiguration } from '../../types';
3
+ export type SelectionExtensionNestedDropdownMenuProps = {
4
+ nestedDropdownMenu: ExtensionNestedDropdownMenuConfiguration;
5
+ };
6
+ export declare const SelectionExtensionNestedDropdownMenu: ({ nestedDropdownMenu, }: SelectionExtensionNestedDropdownMenuProps) => React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtensionMenuItemConfiguration } from '../../types';
3
+ type SelectionExtensionMenuItemsProps = {
4
+ getMenuItems: () => ExtensionMenuItemConfiguration[];
5
+ };
6
+ export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ExtensionMenuItemConfiguration, ExtensionNestedDropdownMenuConfiguration } from '../../types';
2
+ /**
3
+ * Type guard to check if the given configuration is for a dropdown menu.
4
+ *
5
+ * @param item - The menu item configuration to check, either menu item or dropdown menu
6
+ * @returns True if the item configuration is for a dropdown menu, false otherwise
7
+ */
8
+ export declare const isNestedDropdownMenuConfiguration: (item: ExtensionMenuItemConfiguration) => item is ExtensionNestedDropdownMenuConfiguration;
@@ -156,9 +156,9 @@ type ExtensionMenuItemBaseConfiguration = {
156
156
  isDisabled?: boolean;
157
157
  };
158
158
  /**
159
- * Fields for a leaf menu item (i.e., an item that does not have nested menu items)
159
+ * Fields for a dropdown item (i.e., an item that does not have further nested menu items)
160
160
  */
161
- type ExtensionMenuItemLeafConfiguration = {
161
+ type ExtensionDropdownItemFields = {
162
162
  /**
163
163
  * Optional content component to render when this menu item is selected
164
164
  *
@@ -174,23 +174,25 @@ type ExtensionMenuItemLeafConfiguration = {
174
174
  onClick?: () => void;
175
175
  };
176
176
  /**
177
- * Fields for a dropdown menu item (i.e., an item that has nested menu items)
177
+ * Fields for a nested dropdown menu (i.e., an menu item that has further nested menu items)
178
178
  */
179
- type ExtensionMenuItemDropdownMenuConfiguration = {
179
+ type ExtensionNestedDropdownMenuFields = {
180
180
  getMenuItems: GetNestedMenuItemsFn;
181
181
  };
182
+ export type ExtensionDropdownItemConfiguration = ExtensionMenuItemBaseConfiguration & AllNever<ExtensionNestedDropdownMenuFields> & ExtensionDropdownItemFields;
183
+ export type ExtensionNestedDropdownMenuConfiguration = ExtensionMenuItemBaseConfiguration & AllNever<ExtensionDropdownItemFields> & ExtensionNestedDropdownMenuFields;
182
184
  type AllNever<T> = {
183
185
  [K in keyof T]?: never;
184
186
  };
185
187
  /**
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
+ * This type represents either a dropdown item or a dropdown menu, but not both.
189
+ *
190
+ * We mark all fields of the other type as `never` to enforce this exclusivity.
188
191
  */
189
- type ExtensionMenuItemUnsupportedConfiguration = AllNever<ExtensionMenuItemDropdownMenuConfiguration | ExtensionMenuItemLeafConfiguration>;
190
- export type ExtensionMenuItemConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemUnsupportedConfiguration & (ExtensionMenuItemLeafConfiguration | ExtensionMenuItemDropdownMenuConfiguration);
192
+ export type ExtensionMenuItemConfiguration = ExtensionDropdownItemConfiguration | ExtensionNestedDropdownMenuConfiguration;
191
193
  /**
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
+ * We intentionally only support dropdown items nested within dropdown menus, i.e. no menus nested
195
+ * within menus – so there will be at max two levels of nesting from extension menu items
194
196
  */
195
- type ExtensionMenuItemNestedConfiguration = ExtensionMenuItemBaseConfiguration & ExtensionMenuItemLeafConfiguration;
197
+ type ExtensionMenuItemNestedConfiguration = ExtensionDropdownItemConfiguration;
196
198
  export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtensionDropdownItemConfiguration } from '../../types';
3
+ type SelectionExtensionDropdownItemProps = {
4
+ dropdownItem: ExtensionDropdownItemConfiguration;
5
+ };
6
+ export declare const SelectionExtensionDropdownItem: ({ dropdownItem, }: SelectionExtensionDropdownItemProps) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { type ExtensionNestedDropdownMenuConfiguration } from '../../types';
3
+ export type SelectionExtensionNestedDropdownMenuProps = {
4
+ nestedDropdownMenu: ExtensionNestedDropdownMenuConfiguration;
5
+ };
6
+ export declare const SelectionExtensionNestedDropdownMenu: ({ nestedDropdownMenu, }: SelectionExtensionNestedDropdownMenuProps) => React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtensionMenuItemConfiguration } from '../../types';
3
+ type SelectionExtensionMenuItemsProps = {
4
+ getMenuItems: () => ExtensionMenuItemConfiguration[];
5
+ };
6
+ export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ExtensionMenuItemConfiguration, ExtensionNestedDropdownMenuConfiguration } from '../../types';
2
+ /**
3
+ * Type guard to check if the given configuration is for a dropdown menu.
4
+ *
5
+ * @param item - The menu item configuration to check, either menu item or dropdown menu
6
+ * @returns True if the item configuration is for a dropdown menu, false otherwise
7
+ */
8
+ export declare const isNestedDropdownMenuConfiguration: (item: ExtensionMenuItemConfiguration) => item is ExtensionNestedDropdownMenuConfiguration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
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.9.0",
54
+ "@atlaskit/tmp-editor-statsig": "^15.1.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",