@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
@@ -4,86 +4,49 @@ 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
  };
17
+ var DRAG_HANDLE_SELECTOR = '[data-editor-block-ctrl-drag-handle=true]';
18
+ var DRAG_HANDLE_WIDTH = 12;
19
+ var DRAG_HANDLE_PADDING = 5;
24
20
  var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
25
- var FormatDropdown = function FormatDropdown() {
26
- return /*#__PURE__*/React.createElement(DropdownMenu, {
27
- placement: "right-start",
28
- shouldFitContainer: true,
29
- trigger: function trigger(_ref) {
30
- var triggerRef = _ref.triggerRef,
31
- ariaControls = _ref['aria-controls'],
32
- ariaHasPopup = _ref['aria-haspopup'],
33
- ariaExpanded = _ref['aria-expanded'];
34
- return /*#__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
- }
47
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(DropdownItem, {
48
- elemBefore: /*#__PURE__*/React.createElement(TaskIcon, {
49
- label: ""
50
- })
51
- }, "Action item"), /*#__PURE__*/React.createElement(DropdownItem, {
52
- elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, {
53
- label: ""
54
- })
55
- }, "Bullet list")));
56
- };
57
- var BlockMenuContent = function BlockMenuContent() {
21
+ var BlockMenuContent = function BlockMenuContent(_ref) {
22
+ var _api$blockMenu;
23
+ var api = _ref.api;
58
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();
59
26
  return /*#__PURE__*/React.createElement(Box, {
60
27
  testId: "editor-block-menu",
61
28
  ref: setOutsideClickTargetRef,
62
29
  xcss: cx(styles.base)
63
- }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, /*#__PURE__*/React.createElement(FormatDropdown, null), /*#__PURE__*/React.createElement(DropdownItem, {
64
- elemBefore: /*#__PURE__*/React.createElement(JiraIcon, {
65
- label: ""
66
- })
67
- }, "Create Jira work item")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
68
- hasSeparator: true
69
- }, /*#__PURE__*/React.createElement(DropdownItem, {
70
- elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
71
- label: ""
72
- })
73
- }, "Move up"), /*#__PURE__*/React.createElement(DropdownItem, {
74
- elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
75
- label: ""
76
- })
77
- }, "Move down")), /*#__PURE__*/React.createElement(DropdownItemGroup, {
78
- hasSeparator: true
79
- }, /*#__PURE__*/React.createElement(DropdownItem, {
80
- elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
81
- label: ""
82
- })
83
- }, "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
+ }));
84
47
  };
85
48
  var BlockMenu = function BlockMenu(_ref2) {
86
- var _editorView$hasFocus;
49
+ var _editorView$hasFocus, _editorView$dom;
87
50
  var editorView = _ref2.editorView,
88
51
  api = _ref2.api,
89
52
  mountTo = _ref2.mountTo,
@@ -117,8 +80,7 @@ var BlockMenu = function BlockMenu(_ref2) {
117
80
  closeMenu();
118
81
  return null;
119
82
  }
120
- var activeNodeSelector = menuTriggerBy && "[data-drag-handler-anchor-name=".concat(menuTriggerBy, "]");
121
- var targetHandleRef = activeNodeSelector ? document.querySelector(activeNodeSelector) : null;
83
+ var targetHandleRef = (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
122
84
  if (targetHandleRef instanceof HTMLElement) {
123
85
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
124
86
  alignX: 'left',
@@ -132,8 +94,10 @@ var BlockMenu = function BlockMenu(_ref2) {
132
94
  zIndex: akEditorFloatingOverlapPanelZIndex,
133
95
  forcePlacement: true,
134
96
  stick: true,
135
- offset: [-6, 8]
136
- }, /*#__PURE__*/React.createElement(BlockMenuContent, null));
97
+ offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_PADDING, 0]
98
+ }, /*#__PURE__*/React.createElement(BlockMenuContent, {
99
+ api: api
100
+ }));
137
101
  } else {
138
102
  return null;
139
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.1",
3
+ "version": "0.0.3",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,15 +36,16 @@
36
36
  "@atlaskit/editor-plugin-block-controls": "^4.1.0",
37
37
  "@atlaskit/editor-plugin-user-intent": "^1.1.0",
38
38
  "@atlaskit/editor-prosemirror": "7.0.0",
39
- "@atlaskit/editor-shared-styles": "^3.5.0",
40
- "@atlaskit/icon": "^27.9.0",
41
- "@atlaskit/icon-lab": "^5.3.0",
39
+ "@atlaskit/editor-shared-styles": "^3.6.0",
40
+ "@atlaskit/editor-toolbar": "^0.2.0",
41
+ "@atlaskit/icon": "^27.11.0",
42
+ "@atlaskit/icon-lab": "^5.4.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.18.0",
48
+ "@atlaskit/editor-common": "^107.20.0",
48
49
  "react": "^18.2.0",
49
50
  "react-intl-next": "npm:react-intl@^5.18.1"
50
51
  },