@atlaskit/editor-plugin-block-menu 0.0.2 → 0.0.4

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 (40) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +54 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/afm-volt/tsconfig.json +51 -0
  10. package/dist/cjs/blockMenuPlugin.js +12 -0
  11. package/dist/cjs/editor-actions/index.js +65 -0
  12. package/dist/cjs/ui/block-menu-components.js +131 -0
  13. package/dist/cjs/ui/block-menu-renderer.js +54 -0
  14. package/dist/cjs/ui/block-menu.js +26 -65
  15. package/dist/cjs/ui/consts.js +7 -0
  16. package/dist/es2019/blockMenuPlugin.js +37 -23
  17. package/dist/es2019/editor-actions/index.js +57 -0
  18. package/dist/es2019/ui/block-menu-components.js +127 -0
  19. package/dist/es2019/ui/block-menu-renderer.js +35 -0
  20. package/dist/es2019/ui/block-menu.js +21 -63
  21. package/dist/es2019/ui/consts.js +1 -0
  22. package/dist/esm/blockMenuPlugin.js +12 -0
  23. package/dist/esm/editor-actions/index.js +58 -0
  24. package/dist/esm/ui/block-menu-components.js +124 -0
  25. package/dist/esm/ui/block-menu-renderer.js +45 -0
  26. package/dist/esm/ui/block-menu.js +26 -64
  27. package/dist/esm/ui/consts.js +1 -0
  28. package/dist/types/blockMenuPluginType.d.ts +41 -0
  29. package/dist/types/editor-actions/index.d.ts +52 -0
  30. package/dist/types/index.d.ts +1 -1
  31. package/dist/types/ui/block-menu-components.d.ts +2 -0
  32. package/dist/types/ui/block-menu-renderer.d.ts +18 -0
  33. package/dist/types/ui/consts.d.ts +1 -0
  34. package/dist/types-ts4.5/blockMenuPluginType.d.ts +41 -0
  35. package/dist/types-ts4.5/editor-actions/index.d.ts +52 -0
  36. package/dist/types-ts4.5/index.d.ts +1 -1
  37. package/dist/types-ts4.5/ui/block-menu-components.d.ts +2 -0
  38. package/dist/types-ts4.5/ui/block-menu-renderer.d.ts +18 -0
  39. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  40. package/package.json +5 -4
@@ -1,28 +1,42 @@
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 const blockMenuPlugin = ({
5
7
  api
6
- }) => ({
7
- name: 'blockMenu',
8
- pmPlugins() {
9
- return [{
10
- name: 'blockMenuPlugin',
11
- plugin: createPlugin
12
- }];
13
- },
14
- contentComponent({
15
- editorView,
16
- popupsMountPoint,
17
- popupsBoundariesElement,
18
- popupsScrollableElement
19
- }) {
20
- return /*#__PURE__*/React.createElement(BlockMenu, {
21
- editorView: editorView,
22
- api: api,
23
- mountTo: popupsMountPoint,
24
- boundariesElement: popupsBoundariesElement,
25
- scrollableElement: popupsScrollableElement
26
- });
27
- }
28
- });
8
+ }) => {
9
+ const registry = createBlockMenuRegistry();
10
+ registry.register(getBlockMenuComponents());
11
+ return {
12
+ name: 'blockMenu',
13
+ pmPlugins() {
14
+ return [{
15
+ name: 'blockMenuPlugin',
16
+ plugin: createPlugin
17
+ }];
18
+ },
19
+ actions: {
20
+ registerBlockMenuComponents: blockMenuComponents => {
21
+ registry.register(blockMenuComponents);
22
+ },
23
+ getBlockMenuComponents: () => {
24
+ return registry.components;
25
+ }
26
+ },
27
+ contentComponent({
28
+ editorView,
29
+ popupsMountPoint,
30
+ popupsBoundariesElement,
31
+ popupsScrollableElement
32
+ }) {
33
+ return /*#__PURE__*/React.createElement(BlockMenu, {
34
+ editorView: editorView,
35
+ api: api,
36
+ mountTo: popupsMountPoint,
37
+ boundariesElement: popupsBoundariesElement,
38
+ scrollableElement: popupsScrollableElement
39
+ });
40
+ }
41
+ };
42
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Create a simple registry for block menu components.
3
+ *
4
+ * @returns A registry object with a `register` method and a `components` array.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const registry = createBlockMenuRegistry();
9
+ * registry.register(
10
+ * [{
11
+ * type: 'block-menu-section' as const,
12
+ * key: 'block-menu-section-format',
13
+ * rank: 100,
14
+ * component: ({ children }: { children: React.ReactNode }) => {
15
+ * return <ToolbarDropdownItemSection>{children}</ToolbarDropdownItemSection>;
16
+ * },
17
+ * },
18
+ * {
19
+ * type: 'block-menu-nested' as const,
20
+ * key: 'nested-menu',
21
+ * parent: {
22
+ * type: 'block-menu-section' as const,
23
+ * key: 'block-menu-section-format',
24
+ * rank: 100,
25
+ * },
26
+ * component: () => {
27
+ * return (
28
+ * <ToolbarNestedDropdownMenu>{...}</ToolbarNestedDropdownMenu>
29
+ * );
30
+ * },
31
+ * },
32
+ * {
33
+ * type: 'block-menu-item' as const,
34
+ * key: 'block-menu-item-create-jira',
35
+ * parent: {
36
+ * type: 'block-menu-section' as const,
37
+ * key: 'block-menu-section-format',
38
+ * rank: 200,
39
+ * },
40
+ * component: () => {
41
+ * return <ToolbarDropdownItem elemBefore={<JiraIcon label="" />}>Create Jira work item</ToolbarDropdownItem>;
42
+ * },
43
+ * },
44
+ * ]);
45
+ * ```
46
+ *
47
+ */
48
+ export const createBlockMenuRegistry = () => {
49
+ const components = [];
50
+ const register = blockMenuComponents => {
51
+ components.push(...blockMenuComponents);
52
+ };
53
+ return {
54
+ register,
55
+ components
56
+ };
57
+ };
@@ -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,20 +4,13 @@ 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
  };
@@ -25,64 +18,27 @@ const DRAG_HANDLE_SELECTOR = '[data-editor-block-ctrl-drag-handle=true]';
25
18
  const DRAG_HANDLE_WIDTH = 12;
26
19
  const DRAG_HANDLE_PADDING = 5;
27
20
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
28
- const FormatDropdown = () => {
29
- return /*#__PURE__*/React.createElement(DropdownMenu, {
30
- placement: "right-start",
31
- shouldFitContainer: true,
32
- trigger: ({
33
- triggerRef,
34
- 'aria-controls': ariaControls,
35
- 'aria-haspopup': ariaHasPopup,
36
- 'aria-expanded': ariaExpanded
37
- }) => /*#__PURE__*/React.createElement(DropdownItem, {
38
- "aria-controls": ariaControls,
39
- "aria-haspopup": ariaHasPopup,
40
- "aria-expanded": ariaExpanded,
41
- ref: triggerRef,
42
- elemBefore: /*#__PURE__*/React.createElement(ChangesIcon, {
43
- label: ""
44
- }),
45
- elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
46
- label: ""
47
- })
48
- }, "Format")
49
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(DropdownItem, {
50
- elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
51
- label: ""
52
- })
53
- }, "Action item"), /*#__PURE__*/React.createElement(DropdownItem, {
54
- elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
55
- label: ""
56
- })
57
- }, "Bullet list")));
58
- };
59
- const BlockMenuContent = () => {
21
+ const BlockMenuContent = ({
22
+ api
23
+ }) => {
24
+ var _api$blockMenu;
60
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();
61
27
  return /*#__PURE__*/React.createElement(Box, {
62
28
  testId: "editor-block-menu",
63
29
  ref: setOutsideClickTargetRef,
64
30
  xcss: cx(styles.base)
65
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(FormatDropdown, null), /*#__PURE__*/React.createElement(DropdownItem, {
66
- elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
67
- label: ""
68
- })
69
- }, "Create Jira work item")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
70
- hasSeparator: true
71
- }, /*#__PURE__*/React.createElement(DropdownItem, {
72
- elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
73
- label: ""
74
- })
75
- }, "Move up"), /*#__PURE__*/React.createElement(DropdownItem, {
76
- elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
77
- label: ""
78
- })
79
- }, "Move down")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
80
- hasSeparator: true
81
- }, /*#__PURE__*/React.createElement(DropdownItem, {
82
- elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
83
- label: ""
84
- })
85
- }, "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
+ }));
86
42
  };
87
43
  const BlockMenu = ({
88
44
  editorView,
@@ -136,7 +92,9 @@ const BlockMenu = ({
136
92
  forcePlacement: true,
137
93
  stick: true,
138
94
  offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_PADDING, 0]
139
- }, /*#__PURE__*/React.createElement(BlockMenuContent, null));
95
+ }, /*#__PURE__*/React.createElement(BlockMenuContent, {
96
+ api: api
97
+ }));
140
98
  } else {
141
99
  return null;
142
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
+ };