import React, { Component } from 'react' import PropTypes from 'prop-types' import MetacodeSelect from '../MetacodeSelect' class ContextMenu extends Component { static propTypes = { topicId: PropTypes.string, mapId: PropTypes.string, currentUser: PropTypes.object, map: PropTypes.object, contextNode: PropTypes.object, contextEdge: PropTypes.object, contextPos: PropTypes.object, contextFetchingSiblingsData: PropTypes.bool, contextSiblingsData: PropTypes.object, metacodeSets: PropTypes.array, contextDelete: PropTypes.func, contextRemove: PropTypes.func, contextHide: PropTypes.func, contextCenterOn: PropTypes.func, contextPopoutTopic: PropTypes.func, contextUpdatePermissions: PropTypes.func, contextOnMetacodeSelect: PropTypes.func, contextFetchSiblings: PropTypes.func, contextPopulateSiblings: PropTypes.func } constructor(props) { super(props) this.state = { populateSiblingsSent: false } } getPositionData = () => { const { contextPos } = this.props let extraClasses = [] const position = {} // TODO: make these dynamic values so that the ContextMenu can // change height and still work properly const RIGHTCLICK_WIDTH = 300 const RIGHTCLICK_HEIGHT = 144 // this does vary somewhat, but we can use static const SUBMENUS_WIDTH = 256 const MAX_SUBMENU_HEIGHT = 270 const windowWidth = document.documentElement.clientWidth const windowHeight = document.documentElement.clientHeight if (windowWidth - contextPos.x < SUBMENUS_WIDTH) { position.right = windowWidth - contextPos.x extraClasses.push('moveMenusToLeft') } else if (windowWidth - contextPos.x < RIGHTCLICK_WIDTH) { position.right = windowWidth - contextPos.x } else if (windowWidth - contextPos.x < RIGHTCLICK_WIDTH + SUBMENUS_WIDTH) { position.left = contextPos.x extraClasses.push('moveMenusToLeft') } else { position.left = contextPos.x } if (windowHeight - contextPos.y < MAX_SUBMENU_HEIGHT) { position.bottom = windowHeight - contextPos.y extraClasses.push('moveMenusUp') } else if (windowHeight - contextPos.y < RIGHTCLICK_HEIGHT + MAX_SUBMENU_HEIGHT) { position.top = contextPos.y extraClasses.push('moveMenusUp') } else { position.top = contextPos.y } return { pos: { top: position.top && position.top + 'px', bottom: position.bottom && position.bottom + 'px', left: position.left && position.left + 'px', right: position.right && position.right + 'px' }, extraClasses } } hide = () => { const { contextHide } = this.props return