{ "version": 3, "sources": ["../../src/lib/Tldraw.tsx"], "sourcesContent": ["import {\n\tCanvas,\n\tEditor,\n\tErrorScreen,\n\tLoadingScreen,\n\tRecursivePartial,\n\tStoreSnapshot,\n\tTLOnMountHandler,\n\tTLRecord,\n\tTLStore,\n\tTLStoreWithStatus,\n\tTldrawEditor,\n\tTldrawEditorBaseProps,\n\tTldrawEditorProps,\n\tassert,\n\tuseEditor,\n} from '@tldraw/editor'\nimport { useCallback, useDebugValue, useLayoutEffect, useMemo, useRef } from 'react'\nimport { TldrawHandles } from './canvas/TldrawHandles'\nimport { TldrawHoveredShapeIndicator } from './canvas/TldrawHoveredShapeIndicator'\nimport { TldrawScribble } from './canvas/TldrawScribble'\nimport { TldrawSelectionBackground } from './canvas/TldrawSelectionBackground'\nimport { TldrawSelectionForeground } from './canvas/TldrawSelectionForeground'\nimport {\n\tTLExternalContentProps,\n\tregisterDefaultExternalContentHandlers,\n} from './defaultExternalContentHandlers'\nimport { defaultShapeTools } from './defaultShapeTools'\nimport { defaultShapeUtils } from './defaultShapeUtils'\nimport { registerDefaultSideEffects } from './defaultSideEffects'\nimport { defaultTools } from './defaultTools'\nimport { TldrawUi, TldrawUiProps } from './ui/TldrawUi'\nimport { ContextMenu } from './ui/components/ContextMenu'\nimport { TLEditorAssetUrls, useDefaultEditorAssetsWithOverrides } from './utils/assetUrls'\nimport { usePreloadAssets } from './utils/usePreloadAssets'\n\n/** @public */\nexport function Tldraw(\n\tprops: TldrawEditorBaseProps &\n\t\t(\n\t\t\t| {\n\t\t\t\t\tstore: TLStore | TLStoreWithStatus\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\tstore?: undefined\n\t\t\t\t\tpersistenceKey?: string\n\t\t\t\t\tsessionId?: string\n\t\t\t\t\tdefaultName?: string\n\t\t\t\t\t/**\n\t\t\t\t\t * A snapshot to load for the store's initial data / schema.\n\t\t\t\t\t */\n\t\t\t\t\tsnapshot?: StoreSnapshot\n\t\t\t }\n\t\t) &\n\t\tTldrawUiProps &\n\t\tPartial & {\n\t\t\t/**\n\t\t\t * Urls for the editor to find fonts and other assets.\n\t\t\t */\n\t\t\tassetUrls?: RecursivePartial\n\t\t}\n) {\n\tconst {\n\t\tchildren,\n\t\tmaxImageDimension,\n\t\tmaxAssetSize,\n\t\tacceptedImageMimeTypes,\n\t\tacceptedVideoMimeTypes,\n\t\tonMount,\n\t\t...rest\n\t} = props\n\n\tconst withDefaults: TldrawEditorProps = {\n\t\tinitialState: 'select',\n\t\t...rest,\n\t\tcomponents: useMemo(\n\t\t\t() => ({\n\t\t\t\tScribble: TldrawScribble,\n\t\t\t\tCollaboratorScribble: TldrawScribble,\n\t\t\t\tSelectionForeground: TldrawSelectionForeground,\n\t\t\t\tSelectionBackground: TldrawSelectionBackground,\n\t\t\t\tHandles: TldrawHandles,\n\t\t\t\tHoveredShapeIndicator: TldrawHoveredShapeIndicator,\n\t\t\t\t...rest.components,\n\t\t\t}),\n\t\t\t[rest.components]\n\t\t),\n\t\tshapeUtils: useMemo(\n\t\t\t() => [...defaultShapeUtils, ...(rest.shapeUtils ?? [])],\n\t\t\t[rest.shapeUtils]\n\t\t),\n\t\ttools: useMemo(\n\t\t\t() => [...defaultTools, ...defaultShapeTools, ...(rest.tools ?? [])],\n\t\t\t[rest.tools]\n\t\t),\n\t}\n\n\tconst assets = useDefaultEditorAssetsWithOverrides(rest.assetUrls)\n\n\tconst { done: preloadingComplete, error: preloadingError } = usePreloadAssets(assets)\n\n\tif (preloadingError) {\n\t\treturn Could not load assets. Please refresh the page.\n\t}\n\n\tif (!preloadingComplete) {\n\t\treturn Loading assets...\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t{children}\n\t\t\t\n\t\t\n\t)\n}\n\n// We put these hooks into a component here so that they can run inside of the context provided by TldrawEditor.\nfunction InsideOfEditorContext({\n\tmaxImageDimension = 1000,\n\tmaxAssetSize = 10 * 1024 * 1024, // 10mb\n\tacceptedImageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'],\n\tacceptedVideoMimeTypes = ['video/mp4', 'video/quicktime'],\n\tonMount,\n}: Partial) {\n\tconst editor = useEditor()\n\n\tconst onMountEvent = useEvent((editor: Editor) => {\n\t\tconst unsubs: (void | (() => void) | undefined)[] = []\n\n\t\tunsubs.push(...registerDefaultSideEffects(editor))\n\n\t\t// for content handling, first we register the default handlers...\n\t\tregisterDefaultExternalContentHandlers(editor, {\n\t\t\tmaxImageDimension,\n\t\t\tmaxAssetSize,\n\t\t\tacceptedImageMimeTypes,\n\t\t\tacceptedVideoMimeTypes,\n\t\t})\n\n\t\t// ...then we run the onMount prop, which may override the above\n\t\tunsubs.push(onMount?.(editor))\n\n\t\treturn () => {\n\t\t\tunsubs.forEach((fn) => fn?.())\n\t\t}\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tif (editor) return onMountEvent?.(editor)\n\t}, [editor, onMountEvent])\n\n\treturn null\n}\n\n// duped from tldraw editor\nfunction useEvent, Result>(\n\thandler: (...args: Args) => Result\n): (...args: Args) => Result {\n\tconst handlerRef = useRef<(...args: Args) => Result>()\n\n\tuseLayoutEffect(() => {\n\t\thandlerRef.current = handler\n\t})\n\n\tuseDebugValue(handler)\n\n\treturn useCallback((...args: Args) => {\n\t\tconst fn = handlerRef.current\n\t\tassert(fn, 'fn does not exist')\n\t\treturn fn(...args)\n\t}, [])\n}\n"], "mappings": "AAsGS,cASN,YATM;AAtGT;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EAOA;AAAA,EAGA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,eAAe,iBAAiB,SAAS,cAAc;AAC7E,SAAS,qBAAqB;AAC9B,SAAS,mCAAmC;AAC5C,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAC1C,SAAS,iCAAiC;AAC1C;AAAA,EAEC;AAAA,OACM;AACP,SAAS,yBAAyB;AAClC,SAAS,yBA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