import React, { useRef } from 'react' import { Box, Menu, MenuItem, MenuList, MenuGroup, MenuItemOption, MenuOptionGroup, Heading, MenuDivider, Modal, ModalOverlay, ModalContent, ModalHeader, ModalFooter, ModalBody, ModalCloseButton, useDisclosure, Button, PopoverTrigger, PopoverContent, Popover, Flex, PopoverBody, PopoverCloseButton, PopoverArrow, PopoverHeader, PopoverFooter, Portal, Text, VStack, } from '@chakra-ui/react' import { DeleteIcon, EditIcon, CopyIcon, AddIcon, ViewIcon, ExternalLinkIcon, ChevronRightIcon, PlusSquareIcon, MinusIcon, } from '@chakra-ui/icons' import { OrgRoamGraphReponse, OrgRoamLink, OrgRoamNode } from '../api' import { deleteNodeInEmacs, openNodeInEmacs, createNodeInEmacs } from '../util/webSocketFunctions' import { BiNetworkChart } from 'react-icons/bi' import { TagMenu } from './TagMenu' import { initialFilter, TagColors } from './config' export default interface ContextMenuProps { background: Boolean target: OrgRoamNode | string | null nodeType?: string coordinates: { [direction: string]: number | undefined } handleLocal: (node: OrgRoamNode, add: string) => void menuClose: () => void scope: { nodeIds: string[] } webSocket: any setPreviewNode: any setTagColors: any tagColors: TagColors setFilter: any filter: typeof initialFilter } export const ContextMenu = (props: ContextMenuProps) => { const { background, target, nodeType, coordinates, handleLocal, menuClose, scope, webSocket, setPreviewNode, setTagColors, tagColors, setFilter, filter, } = props const { isOpen, onOpen, onClose } = useDisclosure() const copyRef = useRef() return ( <> menuClose()}> {typeof target !== 'string' ? ( <> {target && ( <> {target.title} )} {scope.nodeIds.length !== 0 && ( <> handleLocal(target!, 'add')} icon={}> Expand local graph at node handleLocal(target!, 'replace')} icon={} > Open local graph for this node handleLocal(target!, 'remove')} icon={}> Exclude node from local graph )} {!target?.properties?.FILELESS ? ( } onClick={() => openNodeInEmacs(target as OrgRoamNode, webSocket)} > Open in Emacs ) : ( } onClick={() => createNodeInEmacs(target, webSocket)}> Create node )} {target?.properties?.ROAM_REFS && ( }>Open in Zotero )} {scope.nodeIds.length === 0 && ( } onClick={() => handleLocal(target!, 'replace')}> Open local graph )} {/* Doesn't work at the moment }> Copy... ID Title File path */} } onClick={() => { setPreviewNode(target) }} > Preview {target?.level === 0 && ( } color="red.500" onClick={onOpen} > Permanently delete note )} ) : ( )} {typeof target !== 'string' && ( Delete node? This will permanently delete your note: {target?.title} {target?.level !== 0 && ( This will only delete the from this heading until but not including the next node. Your parent file and all other nodes will not be deleted. )} Are you sure you want to do continue? )} ) } /* * * * Permenantly delete node * * * * Delete Node? * * * * This will permanently delete your node! Are you sure you want to do this? * * * * * * * * * * */