tldraw/apps/www/utils/liveblocks.ts
Gwenaël Gallon e0e1373468
Chore: clean up sort imports with prettier (#870)
* Update prettier to latest

* Add format command

* Create .prettierignore

* Add prettier plugin sort imports

* Update prettier config

* Update prettier config

* Update .prettierignore

* Fix @babel/parser conflict

https://github.com/trivago/prettier-plugin-sort-imports/issues/156

* Revert "Update .prettierignore"

This reverts commit 282e5b838376f16b3df7f4c1f99f1106baaffea4.

* Revert change for apps/www/pages/v/[id].tsx

* Sort imports

Moves the third party imports to the top, "~" imports in middle, and "./" at last

* Sorting of the specifiers

in an import declarations

* [www] use path vs  "../"

* [core] use path "~" vs "../"

* [tldraw] use path "~" vs "../.../"

* [tldraw] use path "~" vs "../"

* [tldraw] Cleanup

* Update prettier config

* Last use path "~" vs "../.../"

* [www] Fix order of the third party imports

* Clean prettier config
2022-08-02 14:56:12 +01:00

52 lines
1.7 KiB
TypeScript

import { createClient } from '@liveblocks/client'
import type { EnsureJson, LiveMap, LiveObject } from '@liveblocks/client'
import { createRoomContext } from '@liveblocks/react'
import type { TDAsset, TDBinding, TDDocument, TDShape, TDUser } from '@tldraw/tldraw'
const client = createClient({
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_API_KEY || '',
throttle: 80,
})
// Presence represents the properties that will exist on every User in the
// Liveblocks Room and that will automatically be kept in sync. Accessible
// through the `user.presence` property.
type Presence = {
id?: string
user: EnsureJson<TDUser>
}
// Storage represents the shared document that persists in the Room, even after
// all Users leave, and for which updates are automatically persisted and
// synced to all connected clients.
export type Storage = {
version: number
doc: LiveObject<{
uuid: string
document: EnsureJson<TDDocument>
migrated?: boolean
}>
shapes: LiveMap<string, EnsureJson<TDShape>>
bindings: LiveMap<string, EnsureJson<TDBinding>>
assets: LiveMap<string, EnsureJson<TDAsset>>
}
// Optionally, UserMeta represents static/readonly metadata on each User, as
// provided by your own custom auth backend. This isn't used for TLDraw.
// type UserMeta = {
// id?: string, // Accessible through `user.id`
// info?: Json, // Accessible through `user.info`
// };
// Optionally, the type of custom events broadcasted and listened for in this
// room.
// type RoomEvent = {};
const { RoomProvider, useHistory, useRedo, useUndo, useRoom, useUpdateMyPresence } =
createRoomContext<
Presence,
Storage
/* UserMeta, RoomEvent */
>(client)
export { RoomProvider, useHistory, useRedo, useUndo, useRoom, useUpdateMyPresence }