{ "version": 3, "sources": ["../../../../src/lib/ui/hooks/useContextMenuSchema.tsx"], "sourcesContent": ["import { Editor, track, useEditor, useValue } from '@tldraw/editor'\nimport React, { useMemo } from 'react'\nimport {\n\tTLUiMenuSchema,\n\tcompactMenuItems,\n\tmenuCustom,\n\tmenuGroup,\n\tmenuItem,\n\tmenuSubmenu,\n\tshowMenuPaste,\n\tuseAllowGroup,\n\tuseAllowUngroup,\n\tuseThreeStackableItems,\n} from './menuHelpers'\nimport { useActions } from './useActions'\nimport { useHasLinkShapeSelected } from './useHasLinkShapeSelected'\nimport { useOnlyFlippableShape } from './useOnlyFlippableShape'\nimport { useShowAutoSizeToggle } from './useShowAutoSizeToggle'\n\n/** @public */\nexport type TLUiContextTTLUiMenuSchemaContextType = TLUiMenuSchema\n\n/** @internal */\nexport const TLUiContextMenuSchemaContext = React.createContext(\n\t{} as TLUiContextTTLUiMenuSchemaContextType\n)\n\n/** @public */\nexport type TLUiContextMenuSchemaProviderProps = {\n\toverrides?: (\n\t\teditor: Editor,\n\t\tschema: TLUiContextTTLUiMenuSchemaContextType,\n\t\thelpers: {\n\t\t\tactions: ReturnType\n\t\t\toneSelected: boolean\n\t\t\ttwoSelected: boolean\n\t\t\tthreeSelected: boolean\n\t\t\tshowAutoSizeToggle: boolean\n\t\t\tshowUngroup: boolean\n\t\t\tonlyFlippableShapeSelected: boolean\n\t\t}\n\t) => TLUiContextTTLUiMenuSchemaContextType\n\tchildren: any\n}\n\n/** @internal */\nexport const TLUiContextMenuSchemaProvider = track(function TLUiContextMenuSchemaProvider({\n\toverrides,\n\tchildren,\n}: TLUiContextMenuSchemaProviderProps) {\n\tconst editor = useEditor()\n\tconst actions = useActions()\n\n\tconst showAutoSizeToggle = useShowAutoSizeToggle()\n\n\tconst onlyFlippableShapeSelected = useOnlyFlippableShape()\n\n\tconst selectedCount = editor.selectedShapeIds.length\n\n\tconst oneSelected = selectedCount > 0\n\n\tconst twoSelected = selectedCount > 1\n\tconst threeSelected = selectedCount > 2\n\tconst threeStackableItems = useThreeStackableItems()\n\tconst atLeastOneShapeOnPage = useValue(\n\t\t'atLeastOneShapeOnPage',\n\t\t() => editor.currentPageShapeIds.size > 0,\n\t\t[]\n\t)\n\tconst isTransparentBg = useValue(\n\t\t'isTransparentBg',\n\t\t() => editor.instanceState.exportBackground,\n\t\t[]\n\t)\n\tconst allowGroup = useAllowGroup()\n\tconst allowUngroup = useAllowUngroup()\n\tconst hasClipboardWrite = Boolean(window.navigator.clipboard?.write)\n\tconst showEditLink = useHasLinkShapeSelected()\n\tconst { onlySelectedShape } = editor\n\tconst isShapeLocked = onlySelectedShape && editor.isShapeOrAncestorLocked(onlySelectedShape)\n\n\tconst contextTLUiMenuSchema = useMemo(() => {\n\t\tlet contextTLUiMenuSchema: TLUiContextTTLUiMenuSchemaContextType = compactMenuItems([\n\t\t\tmenuGroup(\n\t\t\t\t'selection',\n\t\t\t\tshowAutoSizeToggle && menuItem(actions['toggle-auto-size']),\n\t\t\t\tshowEditLink && !isShapeLocked && menuItem(actions['edit-link']),\n\t\t\t\toneSelected && !isShapeLocked && menuItem(actions['duplicate']),\n\t\t\t\tallowGroup && !isShapeLocked && menuItem(actions['group']),\n\t\t\t\tallowUngroup && !isShapeLocked && menuItem(actions['ungroup']),\n\t\t\t\toneSelected && menuItem(actions['toggle-lock'])\n\t\t\t),\n\t\t\tmenuGroup(\n\t\t\t\t'modify',\n\t\t\t\t(twoSelected || onlyFlippableShapeSelected) &&\n\t\t\t\t\tmenuSubmenu(\n\t\t\t\t\t\t'arrange',\n\t\t\t\t\t\t'context-menu.arrange',\n\t\t\t\t\t\ttwoSelected &&\n\t\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t\t'align',\n\t\t\t\t\t\t\t\tmenuItem(actions['align-left']),\n\t\t\t\t\t\t\t\tmenuItem(actions['align-center-horizontal']),\n\t\t\t\t\t\t\t\tmenuItem(actions['align-right']),\n\t\t\t\t\t\t\t\tmenuItem(actions['align-top']),\n\t\t\t\t\t\t\t\tmenuItem(actions['align-center-vertical']),\n\t\t\t\t\t\t\t\tmenuItem(actions['align-bottom'])\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tthreeSelected &&\n\t\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t\t'distribute',\n\t\t\t\t\t\t\t\tmenuItem(actions['distribute-horizontal']),\n\t\t\t\t\t\t\t\tmenuItem(actions['distribute-vertical'])\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\ttwoSelected &&\n\t\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t\t'stretch',\n\t\t\t\t\t\t\t\tmenuItem(actions['stretch-horizontal']),\n\t\t\t\t\t\t\t\tmenuItem(actions['stretch-vertical'])\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tonlyFlippableShapeSelected &&\n\t\t\t\t\t\t\t!isShapeLocked &&\n\t\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t\t'flip',\n\t\t\t\t\t\t\t\tmenuItem(actions['flip-horizontal']),\n\t\t\t\t\t\t\t\tmenuItem(actions['flip-vertical'])\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\ttwoSelected &&\n\t\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t\t'order',\n\t\t\t\t\t\t\t\tmenuItem(actions['pack'], { disabled: !twoSelected }),\n\t\t\t\t\t\t\t\tthreeStackableItems && menuItem(actions['stack-vertical']),\n\t\t\t\t\t\t\t\tthreeStackableItems && menuItem(actions['stack-horizontal'])\n\t\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\toneSelected &&\n\t\t\t\t\t!isShapeLocked &&\n\t\t\t\t\tmenuSubmenu(\n\t\t\t\t\t\t'reorder',\n\t\t\t\t\t\t'context-menu.reorder',\n\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t'reorder',\n\t\t\t\t\t\t\tmenuItem(actions['bring-to-front']),\n\t\t\t\t\t\t\tmenuItem(actions['bring-forward']),\n\t\t\t\t\t\t\tmenuItem(actions['send-backward']),\n\t\t\t\t\t\t\tmenuItem(actions['send-to-back'])\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\toneSelected && !isShapeLocked && menuCustom('MOVE_TO_PAGE_MENU', { readonlyOk: false })\n\t\t\t),\n\t\t\tmenuGroup(\n\t\t\t\t'clipboard-group',\n\t\t\t\toneSelected && !isShapeLocked && menuItem(actions['cut']),\n\t\t\t\toneSelected && menuItem(actions['copy']),\n\t\t\t\tshowMenuPaste && menuItem(actions['paste'])\n\t\t\t),\n\t\t\tatLeastOneShapeOnPage &&\n\t\t\t\tmenuGroup(\n\t\t\t\t\t'conversions',\n\t\t\t\t\tmenuSubmenu(\n\t\t\t\t\t\t'copy-as',\n\t\t\t\t\t\t'context-menu.copy-as',\n\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t'copy-as-group',\n\t\t\t\t\t\t\tmenuItem(actions['copy-as-svg']),\n\t\t\t\t\t\t\thasClipboardWrite && menuItem(actions['copy-as-png']),\n\t\t\t\t\t\t\tmenuItem(actions['copy-as-json'])\n\t\t\t\t\t\t),\n\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t'export-bg',\n\t\t\t\t\t\t\tmenuItem(actions['toggle-transparent'], { checked: !isTransparentBg })\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\tmenuSubmenu(\n\t\t\t\t\t\t'export-as',\n\t\t\t\t\t\t'context-menu.export-as',\n\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t'export-as-group',\n\t\t\t\t\t\t\tmenuItem(actions['export-as-svg']),\n\t\t\t\t\t\t\tmenuItem(actions['export-as-png']),\n\t\t\t\t\t\t\tmenuItem(actions['export-as-json'])\n\t\t\t\t\t\t),\n\t\t\t\t\t\tmenuGroup(\n\t\t\t\t\t\t\t'export-bg,',\n\t\t\t\t\t\t\tmenuItem(actions['toggle-transparent'], { checked: !isTransparentBg })\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t\tatLeastOneShapeOnPage &&\n\t\t\t\tmenuGroup(\n\t\t\t\t\t'set-selection-group',\n\t\t\t\t\tmenuItem(actions['select-all']),\n\t\t\t\t\toneSelected && menuItem(actions['select-none'])\n\t\t\t\t),\n\t\t\toneSelected && !isShapeLocked && menuGroup('delete-group', menuItem(actions['delete'])),\n\t\t])\n\n\t\tif (overrides) {\n\t\t\tcontextTLUiMenuSchema = overrides(editor, contextTLUiMenuSchema, {\n\t\t\t\tactions,\n\t\t\t\toneSelected,\n\t\t\t\ttwoSelected,\n\t\t\t\tthreeSelected,\n\t\t\t\tshowAutoSizeToggle,\n\t\t\t\tshowUngroup: allowUngroup,\n\t\t\t\tonlyFlippableShapeSelected,\n\t\t\t})\n\t\t}\n\n\t\treturn contextTLUiMenuSchema\n\t}, [\n\t\teditor,\n\t\toverrides,\n\t\tactions,\n\t\toneSelected,\n\t\ttwoSelected,\n\t\tthreeSelected,\n\t\tshowAutoSizeToggle,\n\t\tonlyFlippableShapeSelected,\n\t\tatLeastOneShapeOnPage,\n\t\tthreeStackableItems,\n\t\tallowGroup,\n\t\tallowUngroup,\n\t\thasClipboardWrite,\n\t\tshowEditLink,\n\t\t// oneEmbedSelected,\n\t\t// oneEmbeddableBookmarkSelected,\n\t\tisTransparentBg,\n\t\tisShapeLocked,\n\t])\n\n\treturn (\n\t\t\n\t\t\t{children}\n\t\t\n\t)\n})\n\n/** @public */\nexport function useContextMenuSchema(): TLUiMenuSchema {\n\tconst ctx = React.useContext(TLUiContextMenuSchemaContext)\n\n\tif (!ctx) {\n\t\tthrow new Error('useContextMenuSchema must be used inside of a TLUiContextMenuSchemaProvider.')\n\t}\n\n\treturn ctx\n}\n"], "mappings": "AAwOE;AAxOF,SAAiB,OAAO,WAAW,gBAAgB;AACnD,OAAO,SAAS,eAAe;AAC/B;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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