{ "version": 3, "sources": ["../../../../src/lib/ui/hooks/useActionsMenuSchema.tsx"], "sourcesContent": ["import { Editor, track, useEditor } from '@tldraw/editor'\nimport React, { useMemo } from 'react'\nimport {\n\tTLUiMenuSchema,\n\tmenuItem,\n\tuseAllowGroup,\n\tuseAllowUngroup,\n\tuseThreeStackableItems,\n} from './menuHelpers'\nimport { useActions } from './useActions'\nimport { useBreakpoint } from './useBreakpoint'\nimport { useHasLinkShapeSelected } from './useHasLinkShapeSelected'\n\n/** @public */\nexport type TLUiActionsMenuSchemaContextType = TLUiMenuSchema\n\n/** @internal */\nexport const ActionsMenuSchemaContext = React.createContext({} as TLUiActionsMenuSchemaContextType)\n\n/** @public */\nexport type ActionsMenuSchemaProviderProps = {\n\toverrides?: (\n\t\teditor: Editor,\n\t\tschema: TLUiActionsMenuSchemaContextType,\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}\n\t) => TLUiActionsMenuSchemaContextType\n\tchildren: any\n}\n\n/** @internal */\nexport const ActionsMenuSchemaProvider = track(function ActionsMenuSchemaProvider({\n\toverrides,\n\tchildren,\n}: ActionsMenuSchemaProviderProps) {\n\tconst editor = useEditor()\n\tconst actions = useActions()\n\n\tconst selectedCount = editor.selectedShapeIds.length\n\n\tconst oneSelected = selectedCount > 0\n\tconst twoSelected = selectedCount > 1\n\tconst threeSelected = selectedCount > 2\n\tconst threeStackableItems = useThreeStackableItems()\n\tconst allowGroup = useAllowGroup()\n\tconst allowUngroup = useAllowUngroup()\n\tconst showEditLink = useHasLinkShapeSelected()\n\tconst breakpoint = useBreakpoint()\n\tconst isZoomedTo100 = editor.zoomLevel === 1\n\n\tconst actionTLUiMenuSchema = useMemo(() => {\n\t\tconst results = [\n\t\t\tmenuItem(actions['align-left'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['align-center-horizontal'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['align-right'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['stretch-horizontal'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['align-top'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['align-center-vertical'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['align-bottom'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['stretch-vertical'], { disabled: !twoSelected }),\n\t\t\tmenuItem(actions['distribute-horizontal'], { disabled: !threeSelected }),\n\t\t\tmenuItem(actions['distribute-vertical'], { disabled: !threeSelected }),\n\t\t\tmenuItem(actions['stack-horizontal'], { disabled: !threeStackableItems }),\n\t\t\tmenuItem(actions['stack-vertical'], { disabled: !threeStackableItems }),\n\t\t\tmenuItem(actions['send-to-back'], { disabled: !oneSelected }),\n\t\t\tmenuItem(actions['send-backward'], { disabled: !oneSelected }),\n\t\t\tmenuItem(actions['bring-forward'], { disabled: !oneSelected }),\n\t\t\tmenuItem(actions['bring-to-front'], { disabled: !oneSelected }),\n\t\t\tbreakpoint < 5\n\t\t\t\t? menuItem(actions['zoom-to-100'], { disabled: !!isZoomedTo100 })\n\t\t\t\t: menuItem(actions['rotate-ccw'], { disabled: !oneSelected }),\n\t\t\tmenuItem(actions['rotate-cw'], { disabled: !oneSelected }),\n\t\t\tmenuItem(actions['edit-link'], { disabled: !showEditLink }),\n\t\t\tallowGroup\n\t\t\t\t? menuItem(actions['group'], { disabled: !twoSelected })\n\t\t\t\t: allowUngroup\n\t\t\t\t? menuItem(actions['ungroup'])\n\t\t\t\t: menuItem(actions['group'], { disabled: !twoSelected }),\n\t\t]\n\n\t\tif (overrides) {\n\t\t\treturn overrides(editor, results, { actions, oneSelected, twoSelected, threeSelected })\n\t\t}\n\n\t\treturn results\n\t}, [\n\t\teditor,\n\t\tisZoomedTo100,\n\t\tallowGroup,\n\t\toverrides,\n\t\tactions,\n\t\toneSelected,\n\t\ttwoSelected,\n\t\tthreeSelected,\n\t\tthreeStackableItems,\n\t\tallowUngroup,\n\t\tshowEditLink,\n\t\tbreakpoint,\n\t])\n\n\treturn (\n\t\t\n\t\t\t{children}\n\t\t\n\t)\n})\n\n/** @public */\nexport function useActionsMenuSchema(): TLUiMenuSchema {\n\tconst ctx = React.useContext(ActionsMenuSchemaContext)\n\n\tif (!ctx) {\n\t\tthrow new Error('useActionsMenuSchema must be used inside of a ActionsMenuSchemaProvider.')\n\t}\n\n\treturn ctx\n}\n"], "mappings": "AAyGE;AAzGF,SAAiB,OAAO,iBAAiB;AACzC,OAAO,SAAS,eAAe;AAC/B;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AAMjC,MAAM,2BAA2B,MAAM,cAAc,CAAC,CAAqC;AAkB3F,MAAM,4BAA4B,MAAM,SAASA,2BAA0B;AAAA,EACjF;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAE3B,QAAM,gBAAgB,OAAO,iBAAiB;AAE9C,QAAM,cAAc,gBAAgB;AACpC,QAAM,cAAc,gBAAgB;AACpC,QAAM,gBAAgB,gBAAgB;AACtC,QAAM,sBAAsB,uBAAuB;AACnD,QAAM,aAAa,cAAc;AACjC,QAAM,eAAe,gBAAgB;AACrC,QAAM,eAAe,wBAAwB;AAC7C,QAAM,aAAa,cAAc;AACjC,QAAM,gBAAgB,OAAO,cAAc;AAE3C,QAAM,uBAAuB,QAAwB,MAAM;AAC1D,UAAM,UAAU;AAAA,MACf,SAAS,QAAQ,YAAY,GAAG,EAAE,UAAU,CAAC,YAAY,CAAC;AAAA,MAC1D,SAAS,QAAQ,yBAAyB,GAAG,EAAE,UAAU,CAAC,YAAY,CAAC;AAAA,MACvE,SAAS,QAAQ,aAAa,GAAG,EAAE,UAAU,CAAC,YAAY,CAAC;AAAA,MAC3D,SAAS,QAAQ,oBAAoB,GAAG,EAAE,UAAU,CAA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