{
  "version": 3,
  "sources": ["../../../../src/lib/ui/hooks/menu-hooks.ts"],
  "sourcesContent": ["import {\n\tEditor,\n\tTLArrowShape,\n\tTLDrawShape,\n\tTLGroupShape,\n\tTLImageShape,\n\tTLLineShape,\n\tTLTextShape,\n\tuseEditor,\n\tuseValue,\n} from '@tldraw/editor'\nimport { getArrowBindings } from '../../shapes/arrow/shared'\n\nfunction shapesWithUnboundArrows(editor: Editor) {\n\tconst selectedShapeIds = editor.getSelectedShapeIds()\n\tconst selectedShapes = selectedShapeIds.map((id) => {\n\t\treturn editor.getShape(id)\n\t})\n\n\treturn selectedShapes.filter((shape) => {\n\t\tif (!shape) return false\n\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\tif (bindings.start || bindings.end) return false\n\t\t}\n\t\treturn true\n\t})\n}\n\n/** @internal */\nexport const useThreeStackableItems = () => {\n\tconst editor = useEditor()\n\treturn useValue('threeStackableItems', () => shapesWithUnboundArrows(editor).length > 2, [editor])\n}\n\n/** @internal */\nexport const useIsInSelectState = () => {\n\tconst editor = useEditor()\n\treturn useValue('isInSelectState', () => editor.isIn('select'), [editor])\n}\n\n/** @internal */\nexport const useAllowGroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allow group',\n\t\t() => {\n\t\t\t// We can't group arrows that are bound to shapes that aren't selected\n\t\t\t// if more than one shape has an arrow bound to it, allow group\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\n\t\t\tif (selectedShapes.length < 2) return false\n\n\t\t\tfor (const shape of selectedShapes) {\n\t\t\t\tif (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\t\t\tconst bindings = getArrowBindings(editor, shape)\n\t\t\t\t\tif (bindings.start) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.start!.toId)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (bindings.end) {\n\t\t\t\t\t\t// if the other shape is not among the selected shapes...\n\t\t\t\t\t\tif (!selectedShapes.some((s) => s.id === bindings.end!.toId)) {\n\t\t\t\t\t\t\treturn false\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\treturn true\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @internal */\nexport const useAllowUngroup = () => {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'allowUngroup',\n\t\t() => editor.getSelectedShapeIds().some((id) => editor.getShape(id)?.type === 'group'),\n\t\t[editor]\n\t)\n}\n\nexport const showMenuPaste =\n\ttypeof window !== 'undefined' &&\n\t'navigator' in window &&\n\tBoolean(navigator.clipboard) &&\n\tBoolean(navigator.clipboard.read)\n\n/**\n * Returns true if the number of LOCKED OR UNLOCKED selected shapes is at least min or at most max.\n */\nexport function useAnySelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor.getSelectedShapes().length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, min, max]\n\t)\n}\n\n/**\n * Returns true if the number of UNLOCKED selected shapes is at least min or at most max.\n */\nexport function useUnlockedSelectedShapesCount(min?: number, max?: number) {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'selectedShapes',\n\t\t() => {\n\t\t\tconst len = editor\n\t\t\t\t.getSelectedShapes()\n\t\t\t\t.filter((s) => !editor.isShapeOrAncestorLocked(s)).length\n\t\t\tif (min === undefined) {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// just length\n\t\t\t\t\treturn len\n\t\t\t\t} else {\n\t\t\t\t\t// max but no min\n\t\t\t\t\treturn len <= max\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (max === undefined) {\n\t\t\t\t\t// min but no max\n\t\t\t\t\treturn len >= min\n\t\t\t\t} else {\n\t\t\t\t\t// max and min\n\t\t\t\t\treturn len >= min && len <= max\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useShowAutoSizeToggle() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'showAutoSizeToggle',\n\t\t() => {\n\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\t\t\treturn (\n\t\t\t\tselectedShapes.length === 1 &&\n\t\t\t\teditor.isShapeOfType<TLTextShape>(selectedShapes[0], 'text') &&\n\t\t\t\tselectedShapes[0].props.autoSize === false\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useHasLinkShapeSelected() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'hasLinkShapeSelected',\n\t\t() => {\n\t\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\t\treturn !!(\n\t\t\t\tonlySelectedShape &&\n\t\t\t\tonlySelectedShape.type !== 'embed' &&\n\t\t\t\t'url' in onlySelectedShape.props &&\n\t\t\t\t!onlySelectedShape.isLocked\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\nexport function useOnlyFlippableShape() {\n\tconst editor = useEditor()\n\treturn useValue(\n\t\t'onlyFlippableShape',\n\t\t() => {\n\t\t\tconst shape = editor.getOnlySelectedShape()\n\t\t\treturn (\n\t\t\t\tshape &&\n\t\t\t\t(editor.isShapeOfType<TLGroupShape>(shape, 'group') ||\n\t\t\t\t\teditor.isShapeOfType<TLImageShape>(shape, 'image') ||\n\t\t\t\t\teditor.isShapeOfType<TLArrowShape>(shape, 'arrow') ||\n\t\t\t\t\teditor.isShapeOfType<TLLineShape>(shape, 'line') ||\n\t\t\t\t\teditor.isShapeOfType<TLDrawShape>(shape, 'draw'))\n\t\t\t)\n\t\t},\n\t\t[editor]\n\t)\n}\n\n/** @public */\nexport function useCanRedo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanRedo', () => editor.getCanRedo(), [editor])\n}\n\n/** @public */\nexport function useCanUndo() {\n\tconst editor = useEditor()\n\treturn useValue('useCanUndo', () => editor.getCanUndo(), [editor])\n}\n"],
  "mappings": "AAAA;AAAA,EAQC;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB,QAAgB;AAChD,QAAM,mBAAmB,OAAO,oBAAoB;AACpD,QAAM,iBAAiB,iBAAiB,IAAI,CAAC,OAAO;AACnD,WAAO,OAAO,SAAS,EAAE;AAAA,EAC1B,CAAC;AAED,SAAO,eAAe,OAAO,CAAC,UAAU;AACvC,QAAI,CAAC,MAAO,QAAO;AACnB,QAAI,OAAO,cAA4B,OAAO,OAAO,GAAG;AACvD,YAAM,WAAW,iBAAiB,QAAQ,KAAK;AAC/C,UAAI,SAAS,SAAS,SAAS,IAAK,QAAO;AAAA,IAC5C;AACA,WAAO;AAAA,EACR,CAAC;AACF;AAGO,MAAM,yBAAyB,MAAM;AAC3C,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,uBAAuB,MAAM,wBAAwB,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,CAAC;AAClG;AAGO,MAAM,qBAAqB,MAAM;AACvC,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,mBAAmB,MAAM,OAAO,KAAK,QAAQ,GAAG,CAAC,MAAM,CAAC;AACzE;AAGO,MAAM,gBAAgB,MAAM;AAClC,QAAM,SAAS,UAAU;AACzB,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AAGL,YAAM,iBAAiB,OAAO,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