AssetUtil

See source code
Table of contents

Abstract base class for defining asset-type-specific behavior.

Each asset type (image, video, bookmark, etc.) has a corresponding AssetUtil that handles type-specific operations like determining supported MIME types and creating assets from files.

abstract class AssetUtil<Asset extends TLAsset = TLAsset> {}

Constructor

Constructs a new instance of the AssetUtil class

Parameters

NameDescription

editor

Editor;

Properties

migrations

staticoptional

props

staticoptional
static props?: RecordProps<TLUnknownAsset>;

type

static

The type of the asset util, which should match the asset's type.

static type: string;

editor

editor: Editor;

options

Options for this asset util. Override this to provide customization options for your asset. Use AssetUtil.configure to customize existing asset utils.

options: {};

Methods

configure( )

static

Configure this asset util's options.

static configure<T extends TLAssetUtilConstructor<any, any>>(
  this: T,
  options: T extends new (...args: any[]) => {
    options: infer Options;
  }
    ? Partial<Options>
    : never,
): T;

Parameters

NameDescription

this

T;

options

T extends new (...args: any[]) => {
  options: infer Options;
}
  ? Partial<Options>
  : never;

Returns

T;

acceptsMimeType( )

Check whether this asset type accepts a given MIME type.

acceptsMimeType(mimeType: string): boolean;

Parameters

NameDescription

mimeType

string;

Returns

boolean;

getAssetFromFile( )

Create an asset from a file. Return null if this asset type can't handle the file.

getAssetFromFile(_file: File, _assetId: TLAssetId): Promise<Asset | null>;

Parameters

NameDescription

_file

File;

_assetId

Returns

Promise<Asset | null>;

getDefaultProps( )

Get the default props for an asset of this type.

abstract getDefaultProps(): Asset["props"];

getSupportedMimeTypes( )

Get the MIME types that this asset type supports. Return an empty array if this asset type doesn't support files (e.g. bookmarks).

getSupportedMimeTypes(): readonly string[];

Prev
Arc2d
Next
BaseBoxShapeTool