import { Box, TLVideoShape, track, useEditor, useValue } from '@tldraw/editor' import { useCallback, useState } from 'react' import { useTranslation } from '../../hooks/useTranslation/useTranslation' import { TldrawUiContextualToolbar } from '../primitives/TldrawUiContextualToolbar' import { AltTextEditor } from './AltTextEditor' import { DefaultVideoToolbarContent } from './DefaultVideoToolbarContent' /** @public */ export interface TLUiVideoToolbarProps { children?: React.ReactNode } /** @public @react */ export const DefaultVideoToolbar = track(function DefaultVideoToolbar({ children, }: TLUiVideoToolbarProps) { const editor = useEditor() const videoShapeId = useValue( 'videoShape', () => { const onlySelectedShape = editor.getOnlySelectedShape() if (!onlySelectedShape || onlySelectedShape.type !== 'video') return null return onlySelectedShape.id }, [editor] ) const showToolbar = editor.isInAny('select.idle', 'select.pointing_shape') const isLocked = useValue( 'locked', () => (videoShapeId ? editor.getShape(videoShapeId)?.isLocked : false), [editor, videoShapeId] ) if (!videoShapeId || !showToolbar || isLocked) return null return ( {children} ) }) function ContextualToolbarInner({ children, videoShapeId, }: { children?: React.ReactNode videoShapeId: TLVideoShape['id'] }) { const editor = useEditor() const msg = useTranslation() const [isEditingAltText, setIsEditingAltText] = useState(false) const handleEditAltTextStart = useCallback(() => setIsEditingAltText(true), []) const onEditAltTextClose = useCallback(() => setIsEditingAltText(false), []) const getSelectionBounds = useCallback(() => { const fullBounds = editor.getSelectionScreenBounds() if (!fullBounds) return undefined return new Box(fullBounds.x, fullBounds.y, fullBounds.width, 0) }, [editor]) return ( {children ? ( children ) : isEditingAltText ? ( ) : ( )} ) }