@mocanvas/mocanvas · class

BuiltInAssetUtil

declare abstract class BuiltInAssetUtil<A extends Asset>

The shared half of the three utils below.

Deliberately not exported: the documented base class is AssetUtil in the editor package, and exporting a second class under a different name here would give apps two bases to choose between. When the editor's AssetUtil lands, these three change their extends clause and nothing else — they already have its documented members.


Methods · 11

acceptsMimeType(mimeType: string): boolean

Whether this util claims mimeType. Case-insensitive.

static configure<C extends AssetUtilClass>(this: C, options: object): C

This util with options merged over its defaults, as a new class.

Nothing is mutated, so two editors on one page can register differently configured copies of the same asset type.

constructor(editor: Editor)
abstract getAssetFromFile(file: File, assetId: Asset["id"]): Promise<A | null>

Build an asset record from a file, or null when it cannot.

abstract getDefaultProps(): A["props"]

The props a freshly created asset of this type starts with.

getMimeTypes(): readonly string[]

Alias of getSupportedMimeTypes, under the name the editor's registry calls.

abstract getShapeType(): string

The shape type an asset of this type is dropped as.

abstract getSupportedMimeTypes(): readonly string[]

The MIME types this util can build an asset from.

resolve(asset: Asset): string | null

The URL the canvas should paint this asset from.

get type(): A["type"]
upload(file: File, _editor: Editor): Promise<Asset>

Build an asset for file, for the editor's registry.


Properties · 6

readonly editor: Editor
static migrations?: object

How this asset type's props have changed over time.

static options?: object

The defaults every instance starts its options from.

readonly options: AssetUtilOptions
static props?: object

Prop validators for this asset type. Read by the store when it builds the schema.

static type: string

Mentioned here

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.