{
"version": 3,
"sources": ["../../../../src/lib/ui/components/ContextMenu.tsx"],
"sourcesContent": ["import * as _ContextMenu from '@radix-ui/react-context-menu'\nimport { Editor, preventDefault, useContainer, useEditor, useValue } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { useCallback, useState } from 'react'\nimport { TLUiMenuChild } from '../hooks/menuHelpers'\nimport { useBreakpoint } from '../hooks/useBreakpoint'\nimport { useContextMenuSchema } from '../hooks/useContextMenuSchema'\nimport { useMenuIsOpen } from '../hooks/useMenuIsOpen'\nimport { useReadonly } from '../hooks/useReadonly'\nimport { useTranslation } from '../hooks/useTranslation/useTranslation'\nimport { MoveToPageMenu } from './MoveToPageMenu'\nimport { Button } from './primitives/Button'\nimport { Icon } from './primitives/Icon'\nimport { Kbd } from './primitives/Kbd'\n\n/** @public */\nexport interface TLUiContextMenuProps {\n\tchildren: any\n}\n\n/** @public */\nexport const ContextMenu = function ContextMenu({ children }: { children: any }) {\n\tconst editor = useEditor()\n\n\tconst contextTLUiMenuSchema = useContextMenuSchema()\n\n\tconst cb = useCallback(\n\t\t(isOpen: boolean) => {\n\t\t\tif (!isOpen) {\n\t\t\t\tconst { onlySelectedShape } = editor\n\n\t\t\t\tif (onlySelectedShape && editor.isShapeOrAncestorLocked(onlySelectedShape)) {\n\t\t\t\t\teditor.setSelectedShapes([])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Weird route: selecting locked shapes on long press\n\t\t\t\tif (editor.instanceState.isCoarsePointer) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tselectedShapes,\n\t\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t\t} = editor\n\n\t\t\t\t\t// get all of the shapes under the current pointer\n\t\t\t\t\tconst shapesAtPoint = editor.getShapesAtPoint(currentPagePoint)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t// if there are no selected shapes\n\t\t\t\t\t\t!editor.selectedShapes.length ||\n\t\t\t\t\t\t// OR if none of the shapes at the point include the selected shape\n\t\t\t\t\t\t!shapesAtPoint.some((s) => selectedShapes.includes(s))\n\t\t\t\t\t) {\n\t\t\t\t\t\t// then are there any locked shapes under the current pointer?\n\t\t\t\t\t\tconst lockedShapes = shapesAtPoint.filter((s) => editor.isShapeOrAncestorLocked(s))\n\n\t\t\t\t\t\tif (lockedShapes.length) {\n\t\t\t\t\t\t\t// nice, let's select them\n\t\t\t\t\t\t\teditor.select(...lockedShapes.map((s) => s.id))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\tconst container = useContainer()\n\n\tconst [_, handleOpenChange] = useMenuIsOpen('context menu', cb)\n\n\t// If every item in the menu is readonly, then we don't want to show the menu\n\tconst isReadonly = useReadonly()\n\n\tconst noItemsToShow =\n\t\tcontextTLUiMenuSchema.length === 0 ||\n\t\t(isReadonly && contextTLUiMenuSchema.every((item) => !item.readonlyOk))\n\n\tconst selectToolActive = useValue('isSelectToolActive', () => editor.currentToolId === 'select', [\n\t\teditor,\n\t])\n\n\tconst disabled = !selectToolActive || noItemsToShow\n\n\treturn (\n\t\t<_ContextMenu.Root dir=\"ltr\" onOpenChange={handleOpenChange}>\n\t\t\t<_ContextMenu.Trigger\n\t\t\t\tonContextMenu={disabled ? preventDefault : undefined}\n\t\t\t\tdir=\"ltr\"\n\t\t\t\tdisabled={disabled}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\n\t\t\t<_ContextMenu.Portal container={container}>\n\t\t\t\t