### Install @tldraw/sync Source: https://tldraw.dev/docs/collaboration Install the tldraw sync library to quickly add multiplayer functionality. ```bash npm install @tldraw/sync ``` -------------------------------- ### Install @tldraw/driver Source: https://tldraw.dev/docs/driver Install the driver package alongside tldraw using npm. ```bash npm install @tldraw/driver ``` -------------------------------- ### Install @tldraw/mermaid Package Source: https://tldraw.dev/docs/mermaid Install the `@tldraw/mermaid` package alongside `tldraw` using npm. ```bash npm install @tldraw/mermaid ``` -------------------------------- ### Initialize tldraw Editor in React Source: https://tldraw.dev This snippet shows how to integrate the Tldraw component into a React application. It includes basic setup and an example of using the `onMount` prop to select all elements on the canvas upon initialization. ```tsx import { Tldraw } from 'tldraw' import 'tldraw/tldraw.css' export default function App() { return (
{ editor.selectAll() }} />
) } ``` -------------------------------- ### Access Editor via onMount Callback Source: https://tldraw.dev/docs/editor Use the `onMount` callback of the `Tldraw` component to get access to the editor instance. ```javascript function App() { return ( { // your editor code here }} /> ) } ``` -------------------------------- ### Custom Preview Shape for Rich AI Output Source: https://tldraw.dev/docs/ai Implement a custom `ShapeUtil` to render rich AI output like live HTML previews or interactive prototypes. This example shows a basic `PreviewShapeUtil` using an `iframe` to display HTML content. ```typescript // Abbreviated example—a full ShapeUtil also requires getDefaultProps, getGeometry, and indicator class PreviewShapeUtil extends ShapeUtil { static override type = 'preview' as const component(shape: PreviewShape) { return (