@mocanvas/editor · class

AssetUtilRegistry

declare class AssetUtilRegistry

The per-editor registry behind editor.assetUtils and the getAssetUtil* family.

Also holds temporary previews, because they are the same subject seen from the other end: a preview exists exactly for the window between "a file was dropped" and "its util finished uploading it".


Methods · 11

get all(): ReadonlyMap<string, TLAssetUtilLike>

Every registered util, keyed by asset type.

clearPreviews(): void

Forget every preview. Called when the editor goes away.

constructor(editor: Editor, constructors?: readonly TLAssetUtilConstructorLike[])
get(type: string): TLAssetUtilLike | undefined

The util for an asset type, or undefined.

getForMimeType(mimeType: string): TLAssetUtilLike | undefined

The util that claims a MIME type, or undefined.

First match in registration order, so an app registering its own util for image/png after the built-in one does not shadow it — registration order is under the app's control and shadowing should be explicit (replace the util for that type instead).

getPreview(assetId: AssetId): TLTemporaryAssetPreview | undefined

The preview for an asset, if one is still current.

Expired previews are dropped on read rather than on a timer: the object URL behind one is cheap to hold and expensive to sweep, and nothing can observe a stale preview without asking for it.

getShapeTypeFor(assetType: string): string | undefined

The shape type an asset of this type should be turned into.

has(type: string): boolean

Whether a type has a util.

resolveUrl(asset: Asset): string | null | Promise<string | null>

Resolve an asset record to a paintable URL.

setPreview(assetId: AssetId, url: string): void

Remember a preview to paint while an upload is in flight.

upload(file: File): Promise<Asset | undefined>

Upload a file through the util that claims its type.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.