@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
@@ -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
  var styles = {
22
15
  base: "_2rkoglpi _bfhk1bhr _16qs1cd0"
23
16
  };
@@ -25,65 +18,32 @@ var DRAG_HANDLE_SELECTOR = '[data-editor-block-ctrl-drag-handle=true]';
25
18
  var DRAG_HANDLE_WIDTH = 12;
26
19
  var DRAG_HANDLE_PADDING = 5;
27
20
  var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
28
- var FormatDropdown = function FormatDropdown() {
29
- return /*#__PURE__*/React.createElement(DropdownMenu, {
30
- placement: "right-start",
31
- shouldFitContainer: true,
32
- trigger: function trigger(_ref) {
33
- var triggerRef = _ref.triggerRef,
34
- ariaControls = _ref['aria-controls'],
35
- ariaHasPopup = _ref['aria-haspopup'],
36
- ariaExpanded = _ref['aria-expanded'];
37
- return /*#__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
- }
50
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(DropdownItem, {
51
- elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
52
- label: ""
53
- })
54
- }, "Action item"), /*#__PURE__*/React.createElement(DropdownItem, {
55
- elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
56
- label: ""
57
- })
58
- }, "Bullet list")));
59
- };
60
- var BlockMenuContent = function BlockMenuContent() {
21
+ var BlockMenuContent = function BlockMenuContent(_ref) {
22
+ var _api$blockMenu;
23
+ var api = _ref.api;
61
24
  var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
25
+ var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
62
26
  return /*#__PURE__*/React.createElement(Box, {
63
27
  testId: "editor-block-menu",
64
28
  ref: setOutsideClickTargetRef,
65
29
  xcss: cx(styles.base)
66
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(FormatDropdown, null), /*#__PURE__*/React.createElement(DropdownItem, {
67
- elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
68
- label: ""
69
- })
70
- }, "Create Jira work item")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
71
- hasSeparator: true
72
- }, /*#__PURE__*/React.createElement(DropdownItem, {
73
- elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
74
- label: ""
75
- })
76
- }, "Move up"), /*#__PURE__*/React.createElement(DropdownItem, {
77
- elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
78
- label: ""
79
- })
80
- }, "Move down")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
81
- hasSeparator: true
82
- }, /*#__PURE__*/React.createElement(DropdownItem, {
83
- elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
84
- label: ""
85
- })
86
- }, "Delete")));
30
+ }, /*#__PURE__*/React.createElement(BlockMenuRenderer, {
31
+ components: blockMenuComponents || [],
32
+ fallbacks: {
33
+ nestedMenu: function nestedMenu() {
34
+ return /*#__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
+ },
39
+ section: function section() {
40
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, /*#__PURE__*/React.createElement(ToolbarDropdownItem, null, "Block Menu Item"));
41
+ },
42
+ item: function item() {
43
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, null, "Block Menu Item");
44
+ }
45
+ }
46
+ }));
87
47
  };
88
48
  var BlockMenu = function BlockMenu(_ref2) {
89
49
  var _editorView$hasFocus, _editorView$dom;
@@ -135,7 +95,9 @@ var BlockMenu = function BlockMenu(_ref2) {
135
95
  forcePlacement: true,
136
96
  stick: true,
137
97
  offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_PADDING, 0]
138
- }, /*#__PURE__*/React.createElement(BlockMenuContent, null));
98
+ }, /*#__PURE__*/React.createElement(BlockMenuContent, {
99
+ api: api
100
+ }));
139
101
  } else {
140
102
  return null;
141
103
  }
@@ -0,0 +1 @@
1
+ export var BLOCK_MENU_LABEL = 'Editor Block Menu';
@@ -3,4 +3,45 @@ import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls
3
3
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
4
4
  export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
5
5
  dependencies: [OptionalPlugin<BlockControlsPlugin>, OptionalPlugin<UserIntentPlugin>];
6
+ actions: {
7
+ registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
8
+ getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
9
+ };
6
10
  }>;
11
+ type WithRank<T> = T & {
12
+ rank: number;
13
+ };
14
+ export type Parent<T> = WithRank<T>;
15
+ type ComponentType = BlockMenuSection | BlockMenuItem | BlockMenuNested;
16
+ export type ComponentTypes = Array<ComponentType>;
17
+ type BlockMenuItem = {
18
+ key: string;
19
+ type: 'block-menu-item';
20
+ };
21
+ type BlockMenuSection = {
22
+ key: string;
23
+ type: 'block-menu-section';
24
+ };
25
+ type BlockMenuNested = {
26
+ key: string;
27
+ type: 'block-menu-nested';
28
+ };
29
+ export type BlockMenuNestedComponent = () => React.ReactNode;
30
+ export type BlockMenuSectionComponent = (props: {
31
+ children: React.ReactNode;
32
+ }) => React.ReactNode;
33
+ export type BlockMenuItemComponent = () => React.ReactNode;
34
+ export type RegisterBlockMenuNested = BlockMenuNested & {
35
+ parent: Parent<BlockMenuSection>;
36
+ component?: BlockMenuNestedComponent;
37
+ };
38
+ export type RegisterBlockMenuSection = BlockMenuSection & {
39
+ rank: number;
40
+ component?: BlockMenuSectionComponent;
41
+ };
42
+ export type RegisterBlockMenuItem = BlockMenuItem & {
43
+ parent: Parent<BlockMenuSection>;
44
+ component?: BlockMenuItemComponent;
45
+ };
46
+ export type RegisterBlockMenuComponent = RegisterBlockMenuNested | RegisterBlockMenuSection | RegisterBlockMenuItem;
47
+ export {};
@@ -0,0 +1,52 @@
1
+ import type { RegisterBlockMenuComponent } from '../blockMenuPluginType';
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 declare const createBlockMenuRegistry: () => {
50
+ register: (blockMenuComponents: RegisterBlockMenuComponent[]) => void;
51
+ components: RegisterBlockMenuComponent[];
52
+ };
@@ -1,2 +1,2 @@
1
1
  export { blockMenuPlugin } from './blockMenuPlugin';
2
- export type { BlockMenuPlugin } from './blockMenuPluginType';
2
+ export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent } from './blockMenuPluginType';
@@ -0,0 +1,2 @@
1
+ import { type RegisterBlockMenuComponent } from '../blockMenuPluginType';
2
+ export declare const getBlockMenuComponents: () => RegisterBlockMenuComponent[];
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { RegisterBlockMenuComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, BlockMenuItemComponent } from '../blockMenuPluginType';
3
+ type BlockMenuProps = {
4
+ /**
5
+ * Every registered block menu component
6
+ */
7
+ components: RegisterBlockMenuComponent[];
8
+ /**
9
+ * Fallback components used in rendering
10
+ */
11
+ fallbacks: {
12
+ nestedMenu: BlockMenuNestedComponent;
13
+ section: BlockMenuSectionComponent;
14
+ item: BlockMenuItemComponent;
15
+ };
16
+ };
17
+ export declare const BlockMenuRenderer: ({ components, fallbacks }: BlockMenuProps) => React.JSX.Element;
18
+ export {};
@@ -0,0 +1 @@
1
+ export declare const BLOCK_MENU_LABEL = "Editor Block Menu";
@@ -6,4 +6,45 @@ export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
6
6
  OptionalPlugin<BlockControlsPlugin>,
7
7
  OptionalPlugin<UserIntentPlugin>
8
8
  ];
9
+ actions: {
10
+ registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
11
+ getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
12
+ };
9
13
  }>;
14
+ type WithRank<T> = T & {
15
+ rank: number;
16
+ };
17
+ export type Parent<T> = WithRank<T>;
18
+ type ComponentType = BlockMenuSection | BlockMenuItem | BlockMenuNested;
19
+ export type ComponentTypes = Array<ComponentType>;
20
+ type BlockMenuItem = {
21
+ key: string;
22
+ type: 'block-menu-item';
23
+ };
24
+ type BlockMenuSection = {
25
+ key: string;
26
+ type: 'block-menu-section';
27
+ };
28
+ type BlockMenuNested = {
29
+ key: string;
30
+ type: 'block-menu-nested';
31
+ };
32
+ export type BlockMenuNestedComponent = () => React.ReactNode;
33
+ export type BlockMenuSectionComponent = (props: {
34
+ children: React.ReactNode;
35
+ }) => React.ReactNode;
36
+ export type BlockMenuItemComponent = () => React.ReactNode;
37
+ export type RegisterBlockMenuNested = BlockMenuNested & {
38
+ parent: Parent<BlockMenuSection>;
39
+ component?: BlockMenuNestedComponent;
40
+ };
41
+ export type RegisterBlockMenuSection = BlockMenuSection & {
42
+ rank: number;
43
+ component?: BlockMenuSectionComponent;
44
+ };
45
+ export type RegisterBlockMenuItem = BlockMenuItem & {
46
+ parent: Parent<BlockMenuSection>;
47
+ component?: BlockMenuItemComponent;
48
+ };
49
+ export type RegisterBlockMenuComponent = RegisterBlockMenuNested | RegisterBlockMenuSection | RegisterBlockMenuItem;
50
+ export {};
@@ -0,0 +1,52 @@
1
+ import type { RegisterBlockMenuComponent } from '../blockMenuPluginType';
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 declare const createBlockMenuRegistry: () => {
50
+ register: (blockMenuComponents: RegisterBlockMenuComponent[]) => void;
51
+ components: RegisterBlockMenuComponent[];
52
+ };
@@ -1,2 +1,2 @@
1
1
  export { blockMenuPlugin } from './blockMenuPlugin';
2
- export type { BlockMenuPlugin } from './blockMenuPluginType';
2
+ export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent } from './blockMenuPluginType';
@@ -0,0 +1,2 @@
1
+ import { type RegisterBlockMenuComponent } from '../blockMenuPluginType';
2
+ export declare const getBlockMenuComponents: () => RegisterBlockMenuComponent[];
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { RegisterBlockMenuComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, BlockMenuItemComponent } from '../blockMenuPluginType';
3
+ type BlockMenuProps = {
4
+ /**
5
+ * Every registered block menu component
6
+ */
7
+ components: RegisterBlockMenuComponent[];
8
+ /**
9
+ * Fallback components used in rendering
10
+ */
11
+ fallbacks: {
12
+ nestedMenu: BlockMenuNestedComponent;
13
+ section: BlockMenuSectionComponent;
14
+ item: BlockMenuItemComponent;
15
+ };
16
+ };
17
+ export declare const BlockMenuRenderer: ({ components, fallbacks }: BlockMenuProps) => React.JSX.Element;
18
+ export {};
@@ -0,0 +1 @@
1
+ export declare const BLOCK_MENU_LABEL = "Editor Block Menu";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -37,14 +37,15 @@
37
37
  "@atlaskit/editor-plugin-user-intent": "^1.1.0",
38
38
  "@atlaskit/editor-prosemirror": "7.0.0",
39
39
  "@atlaskit/editor-shared-styles": "^3.6.0",
40
- "@atlaskit/icon": "^27.11.0",
41
- "@atlaskit/icon-lab": "^5.4.0",
40
+ "@atlaskit/editor-toolbar": "^0.3.0",
41
+ "@atlaskit/icon": "^27.12.0",
42
+ "@atlaskit/icon-lab": "^5.6.0",
42
43
  "@atlaskit/primitives": "^14.11.0",
43
44
  "@atlaskit/tokens": "^6.0.0",
44
45
  "@babel/runtime": "^7.0.0"
45
46
  },
46
47
  "peerDependencies": {
47
- "@atlaskit/editor-common": "^107.20.0",
48
+ "@atlaskit/editor-common": "^107.23.0",
48
49
  "react": "^18.2.0",
49
50
  "react-intl-next": "npm:react-intl@^5.18.1"
50
51
  },