index.js 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import { pick } from '@utils';
  3. import withGGEditorContext from '@common/context/GGEditorContext/withGGEditorContext';
  4. import Item from './Item';
  5. class ItemPanel extends React.Component {
  6. page = null;
  7. constructor(props) {
  8. super(props);
  9. this.bindEvent();
  10. }
  11. handleMouseUp = () => {
  12. this.page.cancelAdd();
  13. }
  14. bindEvent() {
  15. const { onAfterAddPage } = this.props;
  16. onAfterAddPage(({ page }) => {
  17. this.page = page;
  18. document.addEventListener('mouseup', this.handleMouseUp);
  19. });
  20. }
  21. componentWillUnmount() {
  22. document.removeEventListener('mouseup', this.handleMouseUp);
  23. }
  24. render() {
  25. const { children } = this.props;
  26. return (
  27. <div id={this.containerId} {...pick(this.props, ['style', 'className'])}>
  28. {children}
  29. </div>
  30. );
  31. }
  32. }
  33. export { Item };
  34. export default withGGEditorContext(ItemPanel);