@atlaskit/editor-plugin-block-menu 0.0.1 → 0.0.3

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 (34) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-passionfruit/tsconfig.json +51 -0
  4. package/dist/cjs/blockMenuPlugin.js +12 -0
  5. package/dist/cjs/editor-actions/index.js +65 -0
  6. package/dist/cjs/ui/block-menu-components.js +131 -0
  7. package/dist/cjs/ui/block-menu-renderer.js +54 -0
  8. package/dist/cjs/ui/block-menu.js +32 -69
  9. package/dist/cjs/ui/consts.js +7 -0
  10. package/dist/es2019/blockMenuPlugin.js +37 -23
  11. package/dist/es2019/editor-actions/index.js +57 -0
  12. package/dist/es2019/ui/block-menu-components.js +127 -0
  13. package/dist/es2019/ui/block-menu-renderer.js +35 -0
  14. package/dist/es2019/ui/block-menu.js +27 -67
  15. package/dist/es2019/ui/consts.js +1 -0
  16. package/dist/esm/blockMenuPlugin.js +12 -0
  17. package/dist/esm/editor-actions/index.js +58 -0
  18. package/dist/esm/ui/block-menu-components.js +124 -0
  19. package/dist/esm/ui/block-menu-renderer.js +45 -0
  20. package/dist/esm/ui/block-menu.js +32 -68
  21. package/dist/esm/ui/consts.js +1 -0
  22. package/dist/types/blockMenuPluginType.d.ts +41 -0
  23. package/dist/types/editor-actions/index.d.ts +52 -0
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/ui/block-menu-components.d.ts +2 -0
  26. package/dist/types/ui/block-menu-renderer.d.ts +18 -0
  27. package/dist/types/ui/consts.d.ts +1 -0
  28. package/dist/types-ts4.5/blockMenuPluginType.d.ts +41 -0
  29. package/dist/types-ts4.5/editor-actions/index.d.ts +52 -0
  30. package/dist/types-ts4.5/index.d.ts +1 -1
  31. package/dist/types-ts4.5/ui/block-menu-components.d.ts +2 -0
  32. package/dist/types-ts4.5/ui/block-menu-renderer.d.ts +18 -0
  33. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  34. package/package.json +6 -5
@@ -0,0 +1,127 @@
1
+ import React from 'react';
2
+ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
+ import JiraIcon from '@atlaskit/icon-lab/core/jira';
4
+ import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
5
+ import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
6
+ import ChangesIcon from '@atlaskit/icon/core/changes';
7
+ import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
8
+ import DeleteIcon from '@atlaskit/icon/core/delete';
9
+ import ListBulletedIcon from '@atlaskit/icon/core/list-bulleted';
10
+ import TaskIcon from '@atlaskit/icon/core/task';
11
+ export const getBlockMenuComponents = () => {
12
+ return [{
13
+ type: 'block-menu-section',
14
+ key: 'block-menu-section-format',
15
+ rank: 100,
16
+ component: ({
17
+ children
18
+ }) => {
19
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
20
+ }
21
+ }, {
22
+ type: 'block-menu-section',
23
+ key: 'block-menu-section-move-up-down',
24
+ rank: 200,
25
+ component: ({
26
+ children
27
+ }) => {
28
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
29
+ }
30
+ }, {
31
+ type: 'block-menu-section',
32
+ key: 'block-menu-section-delete',
33
+ rank: 300,
34
+ component: ({
35
+ children
36
+ }) => {
37
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
38
+ }
39
+ }, {
40
+ type: 'block-menu-nested',
41
+ key: 'nested-menu',
42
+ parent: {
43
+ type: 'block-menu-section',
44
+ key: 'block-menu-section-format',
45
+ rank: 100
46
+ },
47
+ component: () => {
48
+ return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
49
+ text: "Format",
50
+ elemBefore: /*#__PURE__*/React.createElement(ChangesIcon, {
51
+ label: ""
52
+ }),
53
+ elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
54
+ label: 'example nested menu'
55
+ })
56
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
57
+ elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
58
+ label: ""
59
+ })
60
+ }, "Action item"), /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
61
+ elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
62
+ label: ""
63
+ })
64
+ }, "Bullet list")));
65
+ }
66
+ }, {
67
+ type: 'block-menu-item',
68
+ key: 'block-menu-item-create-jira',
69
+ parent: {
70
+ type: 'block-menu-section',
71
+ key: 'block-menu-section-format',
72
+ rank: 200
73
+ },
74
+ component: () => {
75
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
76
+ elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
77
+ label: ""
78
+ })
79
+ }, "Create Jira work item");
80
+ }
81
+ }, {
82
+ type: 'block-menu-item',
83
+ key: 'block-menu-item-move-up',
84
+ parent: {
85
+ type: 'block-menu-section',
86
+ key: 'block-menu-section-move-up-down',
87
+ rank: 100
88
+ },
89
+ component: () => {
90
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
91
+ elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
92
+ label: ""
93
+ })
94
+ }, "Move up");
95
+ }
96
+ }, {
97
+ type: 'block-menu-item',
98
+ key: 'block-menu-item-move-down',
99
+ parent: {
100
+ type: 'block-menu-section',
101
+ key: 'block-menu-section-move-up-down',
102
+ rank: 200
103
+ },
104
+ component: () => {
105
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
106
+ elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
107
+ label: ""
108
+ })
109
+ }, "Move down");
110
+ }
111
+ }, {
112
+ type: 'block-menu-item',
113
+ key: 'block-menu-item-delete',
114
+ parent: {
115
+ type: 'block-menu-section',
116
+ key: 'block-menu-section-delete',
117
+ rank: 100
118
+ },
119
+ component: () => {
120
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
121
+ elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
122
+ label: ""
123
+ })
124
+ }, "Delete");
125
+ }
126
+ }];
127
+ };
@@ -0,0 +1,35 @@
1
+ import React, { Fragment } from 'react';
2
+ const NoOp = props => null;
3
+ const isMenuSection = component => {
4
+ return component.type === 'block-menu-section';
5
+ };
6
+ const isMenuItem = component => {
7
+ return component.type === 'block-menu-item';
8
+ };
9
+ const isNestedMenu = component => {
10
+ return component.type === 'block-menu-nested';
11
+ };
12
+ const getSortedChildren = (components, parentKey) => components.filter(component => component.parent.key === parentKey).sort((a, b) => (a.parent.rank || 0) - (b.parent.rank || 0));
13
+ const getSortedSections = components => {
14
+ return components.filter(isMenuSection).sort((a, b) => (a.rank || 0) - (b.rank || 0));
15
+ };
16
+ export const BlockMenuRenderer = ({
17
+ components,
18
+ fallbacks
19
+ }) => {
20
+ const menuSections = getSortedSections(components);
21
+ const menuItems = components.filter(isMenuItem);
22
+ const nestedMenus = components.filter(isNestedMenu);
23
+ return /*#__PURE__*/React.createElement(Fragment, null, menuSections.map(section => {
24
+ const children = getSortedChildren([...menuItems, ...nestedMenus], section.key).map(item => {
25
+ const ItemComponent = item.component || fallbacks.item || NoOp;
26
+ return /*#__PURE__*/React.createElement(ItemComponent, {
27
+ key: item.key
28
+ });
29
+ });
30
+ const SectionComponent = section.component || fallbacks.section || NoOp;
31
+ return /*#__PURE__*/React.createElement(SectionComponent, {
32
+ key: section.key
33
+ }, children);
34
+ }));
35
+ };
@@ -4,82 +4,41 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext } from 'react';
5
5
  import { injectIntl } from 'react-intl-next';
6
6
  import { cx } from '@atlaskit/css';
7
- import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
8
7
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
9
8
  import { Popup } from '@atlaskit/editor-common/ui';
10
9
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
11
10
  import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
12
- import JiraIcon from '@atlaskit/icon-lab/core/jira';
13
- import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
14
- import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
15
- import ChangesIcon from '@atlaskit/icon/core/changes';
16
- import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
17
- import DeleteIcon from '@atlaskit/icon/core/delete';
18
- import ListBulletedIcon from '@atlaskit/icon/core/list-bulleted';
19
- import TaskIcon from '@atlaskit/icon/core/task';
11
+ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
20
12
  import { Box } from '@atlaskit/primitives/compiled';
13
+ import { BlockMenuRenderer } from './block-menu-renderer';
21
14
  const styles = {
22
15
  base: "_2rkoglpi _bfhk1bhr _16qs1cd0"
23
16
  };
17
+ const DRAG_HANDLE_SELECTOR = '[data-editor-block-ctrl-drag-handle=true]';
18
+ const DRAG_HANDLE_WIDTH = 12;
19
+ const DRAG_HANDLE_PADDING = 5;
24
20
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
25
- const FormatDropdown = () => {
26
- return /*#__PURE__*/React.createElement(DropdownMenu, {
27
- placement: "right-start",
28
- shouldFitContainer: true,
29
- trigger: ({
30
- triggerRef,
31
- 'aria-controls': ariaControls,
32
- 'aria-haspopup': ariaHasPopup,
33
- 'aria-expanded': ariaExpanded
34
- }) => /*#__PURE__*/React.createElement(DropdownItem, {
35
- "aria-controls": ariaControls,
36
- "aria-haspopup": ariaHasPopup,
37
- "aria-expanded": ariaExpanded,
38
- ref: triggerRef,
39
- elemBefore: /*#__PURE__*/React.createElement(ChangesIcon, {
40
- label: ""
41
- }),
42
- elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
43
- label: ""
44
- })
45
- }, "Format")
46
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(DropdownItem, {
47
- elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
48
- label: ""
49
- })
50
- }, "Action item"), /*#__PURE__*/React.createElement(DropdownItem, {
51
- elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
52
- label: ""
53
- })
54
- }, "Bullet list")));
55
- };
56
- const BlockMenuContent = () => {
21
+ const BlockMenuContent = ({
22
+ api
23
+ }) => {
24
+ var _api$blockMenu;
57
25
  const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
26
+ const blockMenuComponents = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
58
27
  return /*#__PURE__*/React.createElement(Box, {
59
28
  testId: "editor-block-menu",
60
29
  ref: setOutsideClickTargetRef,
61
30
  xcss: cx(styles.base)
62
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(FormatDropdown, null), /*#__PURE__*/React.createElement(DropdownItem, {
63
- elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
64
- label: ""
65
- })
66
- }, "Create Jira work item")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
67
- hasSeparator: true
68
- }, /*#__PURE__*/React.createElement(DropdownItem, {
69
- elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
70
- label: ""
71
- })
72
- }, "Move up"), /*#__PURE__*/React.createElement(DropdownItem, {
73
- elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
74
- label: ""
75
- })
76
- }, "Move down")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
77
- hasSeparator: true
78
- }, /*#__PURE__*/React.createElement(DropdownItem, {
79
- elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
80
- label: ""
81
- })
82
- }, "Delete")));
31
+ }, /*#__PURE__*/React.createElement(BlockMenuRenderer, {
32
+ components: blockMenuComponents || [],
33
+ fallbacks: {
34
+ nestedMenu: () => /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
35
+ elemBefore: undefined,
36
+ elemAfter: undefined
37
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, /*#__PURE__*/React.createElement(ToolbarDropdownItem, null, "Block Menu Item"))),
38
+ section: () => /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, /*#__PURE__*/React.createElement(ToolbarDropdownItem, null, "Block Menu Item")),
39
+ item: () => /*#__PURE__*/React.createElement(ToolbarDropdownItem, null, "Block Menu Item")
40
+ }
41
+ }));
83
42
  };
84
43
  const BlockMenu = ({
85
44
  editorView,
@@ -88,7 +47,7 @@ const BlockMenu = ({
88
47
  boundariesElement,
89
48
  scrollableElement
90
49
  }) => {
91
- var _editorView$hasFocus;
50
+ var _editorView$hasFocus, _editorView$dom;
92
51
  const {
93
52
  menuTriggerBy,
94
53
  isSelectedViaDragHandle,
@@ -118,8 +77,7 @@ const BlockMenu = ({
118
77
  closeMenu();
119
78
  return null;
120
79
  }
121
- const activeNodeSelector = menuTriggerBy && `[data-drag-handler-anchor-name=${menuTriggerBy}]`;
122
- const targetHandleRef = activeNodeSelector ? document.querySelector(activeNodeSelector) : null;
80
+ const targetHandleRef = (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
123
81
  if (targetHandleRef instanceof HTMLElement) {
124
82
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
125
83
  alignX: 'left',
@@ -133,8 +91,10 @@ const BlockMenu = ({
133
91
  zIndex: akEditorFloatingOverlapPanelZIndex,
134
92
  forcePlacement: true,
135
93
  stick: true,
136
- offset: [-6, 8]
137
- }, /*#__PURE__*/React.createElement(BlockMenuContent, null));
94
+ offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_PADDING, 0]
95
+ }, /*#__PURE__*/React.createElement(BlockMenuContent, {
96
+ api: api
97
+ }));
138
98
  } else {
139
99
  return null;
140
100
  }
@@ -0,0 +1 @@
1
+ export const BLOCK_MENU_LABEL = 'Editor Block Menu';
@@ -1,8 +1,12 @@
1
1
  import React from 'react';
2
+ import { createBlockMenuRegistry } from './editor-actions';
2
3
  import { createPlugin } from './pm-plugins/main';
3
4
  import BlockMenu from './ui/block-menu';
5
+ import { getBlockMenuComponents } from './ui/block-menu-components';
4
6
  export var blockMenuPlugin = function blockMenuPlugin(_ref) {
5
7
  var api = _ref.api;
8
+ var registry = createBlockMenuRegistry();
9
+ registry.register(getBlockMenuComponents());
6
10
  return {
7
11
  name: 'blockMenu',
8
12
  pmPlugins: function pmPlugins() {
@@ -11,6 +15,14 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
11
15
  plugin: createPlugin
12
16
  }];
13
17
  },
18
+ actions: {
19
+ registerBlockMenuComponents: function registerBlockMenuComponents(blockMenuComponents) {
20
+ registry.register(blockMenuComponents);
21
+ },
22
+ getBlockMenuComponents: function getBlockMenuComponents() {
23
+ return registry.components;
24
+ }
25
+ },
14
26
  contentComponent: function contentComponent(_ref2) {
15
27
  var editorView = _ref2.editorView,
16
28
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -0,0 +1,58 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ /**
3
+ * Create a simple registry for block menu components.
4
+ *
5
+ * @returns A registry object with a `register` method and a `components` array.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const registry = createBlockMenuRegistry();
10
+ * registry.register(
11
+ * [{
12
+ * type: 'block-menu-section' as const,
13
+ * key: 'block-menu-section-format',
14
+ * rank: 100,
15
+ * component: ({ children }: { children: React.ReactNode }) => {
16
+ * return <ToolbarDropdownItemSection>{children}</ToolbarDropdownItemSection>;
17
+ * },
18
+ * },
19
+ * {
20
+ * type: 'block-menu-nested' as const,
21
+ * key: 'nested-menu',
22
+ * parent: {
23
+ * type: 'block-menu-section' as const,
24
+ * key: 'block-menu-section-format',
25
+ * rank: 100,
26
+ * },
27
+ * component: () => {
28
+ * return (
29
+ * <ToolbarNestedDropdownMenu>{...}</ToolbarNestedDropdownMenu>
30
+ * );
31
+ * },
32
+ * },
33
+ * {
34
+ * type: 'block-menu-item' as const,
35
+ * key: 'block-menu-item-create-jira',
36
+ * parent: {
37
+ * type: 'block-menu-section' as const,
38
+ * key: 'block-menu-section-format',
39
+ * rank: 200,
40
+ * },
41
+ * component: () => {
42
+ * return <ToolbarDropdownItem elemBefore={<JiraIcon label="" />}>Create Jira work item</ToolbarDropdownItem>;
43
+ * },
44
+ * },
45
+ * ]);
46
+ * ```
47
+ *
48
+ */
49
+ export var createBlockMenuRegistry = function createBlockMenuRegistry() {
50
+ var components = [];
51
+ var register = function register(blockMenuComponents) {
52
+ components.push.apply(components, _toConsumableArray(blockMenuComponents));
53
+ };
54
+ return {
55
+ register: register,
56
+ components: components
57
+ };
58
+ };
@@ -0,0 +1,124 @@
1
+ import React from 'react';
2
+ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
+ import JiraIcon from '@atlaskit/icon-lab/core/jira';
4
+ import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
5
+ import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
6
+ import ChangesIcon from '@atlaskit/icon/core/changes';
7
+ import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
8
+ import DeleteIcon from '@atlaskit/icon/core/delete';
9
+ import ListBulletedIcon from '@atlaskit/icon/core/list-bulleted';
10
+ import TaskIcon from '@atlaskit/icon/core/task';
11
+ export var getBlockMenuComponents = function getBlockMenuComponents() {
12
+ return [{
13
+ type: 'block-menu-section',
14
+ key: 'block-menu-section-format',
15
+ rank: 100,
16
+ component: function component(_ref) {
17
+ var children = _ref.children;
18
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
19
+ }
20
+ }, {
21
+ type: 'block-menu-section',
22
+ key: 'block-menu-section-move-up-down',
23
+ rank: 200,
24
+ component: function component(_ref2) {
25
+ var children = _ref2.children;
26
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
27
+ }
28
+ }, {
29
+ type: 'block-menu-section',
30
+ key: 'block-menu-section-delete',
31
+ rank: 300,
32
+ component: function component(_ref3) {
33
+ var children = _ref3.children;
34
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
35
+ }
36
+ }, {
37
+ type: 'block-menu-nested',
38
+ key: 'nested-menu',
39
+ parent: {
40
+ type: 'block-menu-section',
41
+ key: 'block-menu-section-format',
42
+ rank: 100
43
+ },
44
+ component: function component() {
45
+ return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
46
+ text: "Format",
47
+ elemBefore: /*#__PURE__*/React.createElement(ChangesIcon, {
48
+ label: ""
49
+ }),
50
+ elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
51
+ label: 'example nested menu'
52
+ })
53
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
54
+ elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
55
+ label: ""
56
+ })
57
+ }, "Action item"), /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
58
+ elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
59
+ label: ""
60
+ })
61
+ }, "Bullet list")));
62
+ }
63
+ }, {
64
+ type: 'block-menu-item',
65
+ key: 'block-menu-item-create-jira',
66
+ parent: {
67
+ type: 'block-menu-section',
68
+ key: 'block-menu-section-format',
69
+ rank: 200
70
+ },
71
+ component: function component() {
72
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
73
+ elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
74
+ label: ""
75
+ })
76
+ }, "Create Jira work item");
77
+ }
78
+ }, {
79
+ type: 'block-menu-item',
80
+ key: 'block-menu-item-move-up',
81
+ parent: {
82
+ type: 'block-menu-section',
83
+ key: 'block-menu-section-move-up-down',
84
+ rank: 100
85
+ },
86
+ component: function component() {
87
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
88
+ elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
89
+ label: ""
90
+ })
91
+ }, "Move up");
92
+ }
93
+ }, {
94
+ type: 'block-menu-item',
95
+ key: 'block-menu-item-move-down',
96
+ parent: {
97
+ type: 'block-menu-section',
98
+ key: 'block-menu-section-move-up-down',
99
+ rank: 200
100
+ },
101
+ component: function component() {
102
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
103
+ elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
104
+ label: ""
105
+ })
106
+ }, "Move down");
107
+ }
108
+ }, {
109
+ type: 'block-menu-item',
110
+ key: 'block-menu-item-delete',
111
+ parent: {
112
+ type: 'block-menu-section',
113
+ key: 'block-menu-section-delete',
114
+ rank: 100
115
+ },
116
+ component: function component() {
117
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
118
+ elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
119
+ label: ""
120
+ })
121
+ }, "Delete");
122
+ }
123
+ }];
124
+ };
@@ -0,0 +1,45 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import React, { Fragment } from 'react';
3
+ var NoOp = function NoOp(props) {
4
+ return null;
5
+ };
6
+ var isMenuSection = function isMenuSection(component) {
7
+ return component.type === 'block-menu-section';
8
+ };
9
+ var isMenuItem = function isMenuItem(component) {
10
+ return component.type === 'block-menu-item';
11
+ };
12
+ var isNestedMenu = function isNestedMenu(component) {
13
+ return component.type === 'block-menu-nested';
14
+ };
15
+ var getSortedChildren = function getSortedChildren(components, parentKey) {
16
+ return components.filter(function (component) {
17
+ return component.parent.key === parentKey;
18
+ }).sort(function (a, b) {
19
+ return (a.parent.rank || 0) - (b.parent.rank || 0);
20
+ });
21
+ };
22
+ var getSortedSections = function getSortedSections(components) {
23
+ return components.filter(isMenuSection).sort(function (a, b) {
24
+ return (a.rank || 0) - (b.rank || 0);
25
+ });
26
+ };
27
+ export var BlockMenuRenderer = function BlockMenuRenderer(_ref) {
28
+ var components = _ref.components,
29
+ fallbacks = _ref.fallbacks;
30
+ var menuSections = getSortedSections(components);
31
+ var menuItems = components.filter(isMenuItem);
32
+ var nestedMenus = components.filter(isNestedMenu);
33
+ return /*#__PURE__*/React.createElement(Fragment, null, menuSections.map(function (section) {
34
+ var children = getSortedChildren([].concat(_toConsumableArray(menuItems), _toConsumableArray(nestedMenus)), section.key).map(function (item) {
35
+ var ItemComponent = item.component || fallbacks.item || NoOp;
36
+ return /*#__PURE__*/React.createElement(ItemComponent, {
37
+ key: item.key
38
+ });
39
+ });
40
+ var SectionComponent = section.component || fallbacks.section || NoOp;
41
+ return /*#__PURE__*/React.createElement(SectionComponent, {
42
+ key: section.key
43
+ }, children);
44
+ }));
45
+ };