import { useEditor, useValue } from '@bigbluebutton/editor' import { ToastProvider } from '@radix-ui/react-toast' import classNames from 'classnames' import React, { ReactNode } from 'react' import { TldrawUiContextProvider, TldrawUiContextProviderProps } from './TldrawUiContextProvider' import { TLUiAssetUrlOverrides } from './assetUrls' import { BackToContent } from './components/BackToContent' import { DebugPanel } from './components/DebugPanel' import { Dialogs } from './components/Dialogs' import { FollowingIndicator } from './components/FollowingIndicator' 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 { useBreakpoint } from './hooks/useBreakpoint' import { useNativeClipboardEvents } from './hooks/useClipboardEvents' import { useEditorEvents } from './hooks/useEditorEvents' import { useKeyboardShortcuts } from './hooks/useKeyboardShortcuts' import { useTranslation } from './hooks/useTranslation/useTranslation' /** * Props for the {@link @bigbluebutton/tldraw#Tldraw} and {@link TldrawUi} components. * * @public */ export type TldrawUiProps = TldrawUiBaseProps & TldrawUiContextProviderProps /** * Base props for the {@link @bigbluebutton/tldraw#Tldraw} and {@link TldrawUi} components. * * @public */ export interface TldrawUiBaseProps { /** * The component's children. */ children?: ReactNode /** * Whether to hide the user interface and only display the canvas. */ hideUi?: boolean /** * A component to use for the share zone (will be deprecated) */ shareZone?: ReactNode /** * A component to use for the top zone (will be deprecated) * @internal */ topZone?: ReactNode /** * Additional items to add to the debug menu (will be deprecated) */ renderDebugMenuItems?: () => React.ReactNode /** Asset URL override. */ assetUrls?: TLUiAssetUrlOverrides } /** * @public */ export const TldrawUi = React.memo(function TldrawUi({ shareZone, topZone, renderDebugMenuItems, children, hideUi, ...rest }: TldrawUiProps) { return ( {children} ) }) type TldrawUiContentProps = { hideUi?: boolean shareZone?: ReactNode topZone?: ReactNode renderDebugMenuItems?: () => React.ReactNode } const TldrawUiInner = React.memo(function TldrawUiInner({ children, hideUi, ...rest }: TldrawUiContentProps & { children: ReactNode }) { // 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 : } ) }) const TldrawUiContent = React.memo(function TldrawUI({ shareZone, topZone, renderDebugMenuItems, }: TldrawUiContentProps) { const editor = useEditor() const msg = useTranslation() const breakpoint = useBreakpoint() const isReadonlyMode = useValue('isReadonlyMode', () => editor.getInstanceState().isReadonly, [ editor, ]) const isFocusMode = useValue('focus', () => editor.getInstanceState().isFocusMode, [editor]) const isDebugMode = useValue('debug', () => editor.getInstanceState().isDebugMode, [editor]) useKeyboardShortcuts() useNativeClipboardEvents() useEditorEvents() const { 'toggle-focus-mode': toggleFocus } = useActions() return (
{isFocusMode ? (
) : ( <>
{topZone}
{shareZone} {breakpoint >= 5 && !isReadonlyMode && (
)}
{breakpoint >= 4 && }
{isDebugMode && }
)}
) })