import { ToastProvider } from '@radix-ui/react-toast' import { useApp } from '@tldraw/editor' import classNames from 'classnames' import React, { ReactNode } from 'react' import { useValue } from 'signia-react' import { TldrawUiContextProvider, TldrawUiContextProviderProps } from './TldrawUiContextProvider' import { BackToContent } from './components/BackToContent' import { DebugPanel } from './components/DebugPanel' import { Dialogs } from './components/Dialogs' import { HelpMenu } from './components/HelpMenu' import { MenuZone } from './components/MenuZone' import { NavigationZone } from './components/NavigationZone/NavigationZone' import { ExitPenMode } from './components/PenModeToggle' import { StopFollowing } from './components/StopFollowing' import { StylePanel } from './components/StylePanel/StylePanel' import { ToastViewport, Toasts } from './components/Toasts' import { Toolbar } from './components/Toolbar/Toolbar' import { Button } from './components/primitives/Button' import { useActions } from './hooks/useActions' import { useAppEvents } from './hooks/useAppEvents' import { useBreakpoint } from './hooks/useBreakpoint' import { useNativeClipboardEvents } from './hooks/useClipboardEvents' import { useKeyboardShortcuts } from './hooks/useKeyboardShortcuts' import { useTranslation } from './hooks/useTranslation/useTranslation' /** * @public */ export const TldrawUi = React.memo(function TldrawUi({ shareZone, renderDebugMenuItems, children, hideUi, ...rest }: { shareZone?: ReactNode renderDebugMenuItems?: () => React.ReactNode children?: ReactNode /** Whether to hide the interface and only display the canvas. */ hideUi?: boolean } & TldrawUiContextProviderProps) { return ( {children} ) }) type TldrawUiContentProps = { hideUi?: boolean shareZone?: ReactNode renderDebugMenuItems?: () => React.ReactNode } const TldrawUiInner = React.memo(function TldrawUiInner({ children, hideUi, ...rest }: TldrawUiContentProps & { children: ReactNode }) { // const isLoaded = usePreloadIcons() // if (!isLoaded) { // return Loading assets... // } // The hideUi prop should prevent the UI from mounting. // If we ever need want the UI to mount and preserve state, then // we should change this behavior and hide the UI via CSS instead. return ( <> {children} {hideUi ? null : } ) }) /** @public */ export const TldrawUiContent = React.memo(function TldrawUI({ shareZone, renderDebugMenuItems, }: TldrawUiContentProps) { const app = useApp() const msg = useTranslation() const breakpoint = useBreakpoint() const isReadonlyMode = useValue('isReadOnlyMode', () => app.isReadOnly, []) const isFocusMode = useValue('isFocusMode', () => app.instanceState.isFocusMode, []) const isDebugMode = useValue('isDebugMode', () => app.instanceState.isDebugMode, []) useKeyboardShortcuts() useNativeClipboardEvents() useAppEvents() const { 'toggle-focus-mode': toggleFocus } = useActions() return (
{isFocusMode ? (
) : ( <>
{shareZone && (
{shareZone}
)} {breakpoint >= 5 && !isReadonlyMode && (
)}
{breakpoint >= 4 && }
{isDebugMode && }
)}
) })