import * as _ContextMenu from '@radix-ui/react-context-menu' import * as _Dropdown from '@radix-ui/react-dropdown-menu' import styled from 'styles' import { IconWrapper, RowButton } from './shared' import { commandKey, deepCompareArrays, getSelectedShapes, isMobile, } from 'utils/utils' import state, { useSelector } from 'state' import { MoveType, ShapeType } from 'types' import React, { useRef } from 'react' import { ChevronRightIcon } from '@radix-ui/react-icons' export default function ContextMenu({ children, }: { children: React.ReactNode }) { const selectedShapes = useSelector( (s) => getSelectedShapes(s.data), deepCompareArrays ) const rContent = useRef(null) const hasGroupSelectd = selectedShapes.some((s) => s.type === ShapeType.Group) const hasMultipleSelected = selectedShapes.length > 1 return ( <_ContextMenu.Root> <_ContextMenu.Trigger>{children} {selectedShapes.length ? ( <> {/* */} {hasGroupSelectd || (hasMultipleSelected && ( <> {hasGroupSelectd && ( )} {hasMultipleSelected && ( )} ))} ) : ( <> )} ) } const StyledContent = styled(_ContextMenu.Content, { position: 'relative', backgroundColor: '$panel', borderRadius: '4px', overflow: 'hidden', pointerEvents: 'all', userSelect: 'none', zIndex: 200, padding: 3, boxShadow: '0px 2px 4px rgba(0,0,0,.2)', minWidth: 128, '& kbd': { marginLeft: '32px', fontSize: '$1', fontFamily: '$ui', }, '& kbd > span': { display: 'inline-block', width: '12px', }, variants: { isMobile: { true: { '& kbd': { display: 'none', }, }, }, }, }) const StyledDivider = styled(_ContextMenu.Separator, { backgroundColor: '$hover', height: 1, margin: '3px -3px', }) function Button({ onSelect, children, disabled = false, }: { onSelect: () => void disabled?: boolean children: React.ReactNode }) { return ( <_ContextMenu.Item as={RowButton} disabled={disabled} bp={{ '@initial': 'mobile', '@sm': 'small' }} onSelect={onSelect} > {children} ) } function SubMenu({ children, label, }: { label: string children: React.ReactNode }) { return ( <_ContextMenu.Root> <_ContextMenu.TriggerItem as={RowButton} bp={{ '@initial': 'mobile', '@sm': 'small' }} > {label} {children} ) } function MoveToPageMenu() { const documentPages = useSelector((s) => s.data.document.pages) const currentPageId = useSelector((s) => s.data.currentPageId) if (!documentPages[currentPageId]) return null const sorted = Object.values(documentPages) .sort((a, b) => a.childIndex - b.childIndex) .filter((a) => a.id !== currentPageId) return ( <_ContextMenu.Root> <_ContextMenu.TriggerItem as={RowButton} bp={{ '@initial': 'mobile', '@sm': 'small' }} > Move To Page {sorted.map(({ id, name }) => ( ))} ) } const StyledDialogContent = styled(_Dropdown.Content, { // position: 'fixed', // top: '50%', // left: '50%', // transform: 'translate(-50%, -50%)', // minWidth: 200, // maxWidth: 'fit-content', // maxHeight: '85vh', // marginTop: '-5vh', minWidth: 128, backgroundColor: '$panel', borderRadius: '4px', overflow: 'hidden', pointerEvents: 'all', userSelect: 'none', zIndex: 200, padding: 2, border: '1px solid $panel', boxShadow: '0px 2px 4px rgba(0,0,0,.2)', '&:focus': { outline: 'none', }, }) const StyledArrow = styled(_ContextMenu.Arrow, { fill: 'white', })