1c65c031b2
* Added image and video shapes * Fixed bugs; Added optional onImageUpload callback * Added id field to onImageUpload * Added onImageDelete callback for cleanup * Added firebase storage to multiplayer for media * Added firebase storage to multiplayer for media * Silence unnecessary TS errors * Fixed bugs; Added tests * Added tests * Disable images for multiplayer example * switch to assets in document, rather than on shapes, fix resize, fix sizes * bump version, add migration for assets table * Rename onImageUpload * Add isPlaying state to video (not complete) * Revert "Add isPlaying state to video (not complete)" This reverts commit 3dc2ba703f4194eb7c47524d384dc8392daa18be. * Adds controls when editing video, sync current time when cloning * Remove unused tools * avoid duplication in assets * Remove unused image styles from style menu * Fix placement of clone buttons * Fix flag to hide image assets in multiplayer * move getSizeFromDataUrl to filesystem * Update VideoUtil.tsx * Re-center video after it loads * Add copy and paste support for assets * Fix bug in state manager, remove unused assets on load, fix indicators * Add multiplayer with images example * Update MultiplayerEditor.tsx * Add images to copy SVG * tighten up some code around svg export * Update TldrawApp.spec.ts * Update useBoundsHandleEvents.tsx * Reset image size by double clicking bounds * fix reset size Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
import * as React from 'react'
|
|
import { Tldraw, TldrawApp, useFileSystem } from '@tldraw/tldraw'
|
|
import { createClient } from '@liveblocks/client'
|
|
import { LiveblocksProvider, RoomProvider } from '@liveblocks/react'
|
|
import { useAccountHandlers } from 'hooks/useAccountHandlers'
|
|
import { styled } from 'styles'
|
|
import { useMultiplayerState } from 'hooks/useMultiplayerState'
|
|
|
|
const client = createClient({
|
|
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_API_KEY || '',
|
|
throttle: 80,
|
|
})
|
|
|
|
export default function MultiplayerEditor({
|
|
roomId,
|
|
isUser = false,
|
|
isSponsor = false,
|
|
}: {
|
|
roomId: string
|
|
isUser: boolean
|
|
isSponsor: boolean
|
|
}) {
|
|
return (
|
|
<LiveblocksProvider client={client}>
|
|
<RoomProvider id={roomId} defaultStorageRoot={TldrawApp.defaultDocument}>
|
|
<Editor roomId={roomId} isSponsor={isSponsor} isUser={isUser} />
|
|
</RoomProvider>
|
|
</LiveblocksProvider>
|
|
)
|
|
}
|
|
|
|
// Inner Editor
|
|
|
|
function Editor({
|
|
roomId,
|
|
isUser,
|
|
isSponsor,
|
|
}: {
|
|
roomId: string
|
|
isUser: boolean
|
|
isSponsor: boolean
|
|
}) {
|
|
const fileSystemEvents = useFileSystem()
|
|
const { onSignIn, onSignOut } = useAccountHandlers()
|
|
const { error, ...events } = useMultiplayerState(roomId)
|
|
|
|
if (error) return <LoadingScreen>Error: {error.message}</LoadingScreen>
|
|
|
|
return (
|
|
<div className="tldraw">
|
|
<Tldraw
|
|
autofocus
|
|
disableAssets
|
|
showPages={false}
|
|
showSponsorLink={!isSponsor}
|
|
onSignIn={isSponsor ? undefined : onSignIn}
|
|
onSignOut={isUser ? onSignOut : undefined}
|
|
{...fileSystemEvents}
|
|
{...events}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const LoadingScreen = styled('div', {
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
width: '100%',
|
|
height: '100%',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
})
|