index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react';
  2. import { pick } from '@utils';
  3. import Editor from '@components/Base/Editor';
  4. import { CONTEXT_MENU_CONTAINER } from '@common/constants';
  5. import withGGEditorContext from '@common/context/GGEditorContext/withGGEditorContext';
  6. import Menu from './Menu';
  7. class ContextMenu extends React.Component {
  8. contextMenu = null;
  9. get containerId() {
  10. const { editor } = this.props;
  11. return `${CONTEXT_MENU_CONTAINER}_${editor.id}`;
  12. }
  13. componentDidMount() {
  14. const { editor } = this.props;
  15. this.contextMenu = new Editor.Contextmenu({
  16. container: this.containerId,
  17. });
  18. editor.add(this.contextMenu);
  19. }
  20. render() {
  21. const { children } = this.props;
  22. return (
  23. <div id={this.containerId} {...pick(this.props, ['style', 'className'])}>
  24. {children}
  25. </div>
  26. );
  27. }
  28. }
  29. export const NodeMenu = Menu.create('node');
  30. export const EdgeMenu = Menu.create('edge');
  31. export const GroupMenu = Menu.create('group');
  32. export const MultiMenu = Menu.create('multi');
  33. export const CanvasMenu = Menu.create('canvas');
  34. export default withGGEditorContext(ContextMenu);