AssetAPI provides methods for asset source management API matches Web bindings: engine.asset.*
Implements#
IAssetAPI
Constructors#
Methods#
addSource()#
Add a custom asset source with callbacks.
This allows you to provide custom implementations for finding, fetching, and applying assets from any data source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
source |
AssetSource |
The asset source configuration with callbacks. |
Returns#
void
Implementation of#
IAssetAPI.addSourceSignature#
addSource(source: AssetSource): voidaddLocalSource()#
Add a local asset source.
Mirrors @cesdk/engine’s 4-argument shape
(bindings/wasm/js_web/src/AssetAPI.ts): when applyAsset
or applyAssetToBlock is supplied, we wrap the local source as a
synthetic AssetSource via addSource so the callbacks are
honored. Without callbacks we go through the cheap addLocalSource
fast path.
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
string |
Unique identifier for the asset source. |
supportedMimeTypes? |
string[] |
The mime types of assets that are allowed to be added. |
applyAsset? |
(asset) => Promise<number> |
Optional callback invoked when the asset is applied to a new block. |
applyAssetToBlock? |
(asset, block) => Promise<void> |
Optional callback invoked when the asset is applied to an existing block. |
Returns#
void
Implementation of#
IAssetAPI.addLocalSourceSignature#
addLocalSource(id: string, supportedMimeTypes?: string[], applyAsset?: (asset: CompleteAssetResult) => Promise<number>, applyAssetToBlock?: (asset: CompleteAssetResult, block: number) => Promise<void>): voidaddLocalAssetSourceFromJSONString()#
Creates a new local asset source from a JSON string.
Parameters#
| Parameter | Type | Description |
|---|---|---|
contentJSON |
string |
The JSON string containing the asset definitions. |
basePath? |
string |
Optional base path for resolving relative URLs. |
options? |
{ matcher?: string[]; } |
Optional configuration with matcher patterns. |
options.matcher? |
string[] |
- |
Returns#
Promise<string>
The ID of the created asset source.
Implementation of#
IAssetAPI.addLocalAssetSourceFromJSONStringSignature#
addLocalAssetSourceFromJSONString(contentJSON: string, basePath?: string, options?: object): Promise<string>addLocalAssetSourceFromJSONURI()#
Creates a new local asset source from a JSON URI.
Parameters#
| Parameter | Type | Description |
|---|---|---|
contentURI |
string |
The URI for the JSON file to load. |
options? |
{ matcher?: string[]; abortSignal?: AbortSignal; } |
Optional configuration with matcher patterns, and an abortSignal that stops the download of the JSON file. No asset source is added then. |
options.matcher? |
string[] |
- |
options.abortSignal? |
AbortSignal |
- |
Returns#
Promise<string>
The ID of the created asset source.
Implementation of#
IAssetAPI.addLocalAssetSourceFromJSONURISignature#
addLocalAssetSourceFromJSONURI(contentURI: string, options?: object): Promise<string>removeSource()#
Remove a registered asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
string |
The ID of the asset source to remove. |
Returns#
void
Implementation of#
IAssetAPI.removeSourceSignature#
removeSource(id: string): voidfindAllSources()#
Get all registered asset source IDs.
Returns#
string[]
A list with the IDs of all registered asset sources.
Implementation of#
IAssetAPI.findAllSourcesSignature#
findAllSources(): string[]findAssets()#
Search for assets in a specific source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the asset source. |
query |
AssetsQuery |
Query options to filter and sort the search results. |
Returns#
Promise<AssetsQueryResult<CompleteAssetResult>>
Promise resolving to paginated search results.
Implementation of#
IAssetAPI.findAssetsSignature#
findAssets(sourceId: string, query: AssetsQuery): Promise<AssetsQueryResult<CompleteAssetResult>>fetchAsset()#
Fetch a specific asset by id from an asset source.
Returns null when the asset is not found.
null when the asset is not found.Parameters#
| Parameter | Type |
|---|---|
sourceId |
string |
assetId |
string |
params? |
Pick<AssetQueryData, "locale"> |
Returns#
Promise<CompleteAssetResult>
Signature#
fetchAsset(sourceId: string, assetId: string, params?: Pick<AssetQueryData, "locale">): Promise<CompleteAssetResult>getGroups()#
Get available asset groups from a source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
string |
The ID of the asset source. |
Returns#
Promise<string[]>
Promise resolving to list of available group names.
Implementation of#
IAssetAPI.getGroupsSignature#
getGroups(id: string): Promise<string[]>getLicense()#
Get license information for an asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the asset source. |
Returns#
object
The asset source’s license info.
| Name | Type |
|---|---|
name |
string |
url |
string |
Implementation of#
IAssetAPI.getLicenseSignature#
getLicense(sourceId: string): objectgetCredits()#
Get attribution credits for an asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the asset source. |
Returns#
object
The asset source’s credits info.
| Name | Type |
|---|---|
name |
string |
url |
string |
Implementation of#
IAssetAPI.getCreditsSignature#
getCredits(sourceId: string): objectgetSupportedMimeTypes()#
Get supported MIME types for an asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the asset source. |
Returns#
string[]
Array of supported MIME type strings.
Implementation of#
IAssetAPI.getSupportedMimeTypesSignature#
getSupportedMimeTypes(sourceId: string): string[]addAssetToSource()#
Add an asset to a local asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The local asset source ID. |
asset |
AssetDefinition |
The asset definition to add. |
Returns#
void
Implementation of#
IAssetAPI.addAssetToSourceSignature#
addAssetToSource(sourceId: string, asset: AssetDefinition): voidremoveAssetFromSource()#
Remove an asset from a local asset source.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the local asset source. |
assetId |
string |
The ID of the asset to remove. |
Returns#
void
Implementation of#
IAssetAPI.removeAssetFromSourceSignature#
removeAssetFromSource(sourceId: string, assetId: string): voidassetSourceContentsChanged()#
Notify the engine that an asset source’s contents have changed.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceID |
string |
The asset source whose contents changed. |
Returns#
void
Implementation of#
IAssetAPI.assetSourceContentsChangedSignature#
assetSourceContentsChanged(sourceID: string): voidapply()#
Apply an asset to the current scene. Honors any middleware registered
via registerApplyMiddleware and falls back to
defaultApplyAsset.
Parameters#
| Parameter | Type |
|---|---|
sourceId |
string |
assetResult |
AssetResult |
options? |
ApplyAssetOptions |
Returns#
Promise<number>
Signature#
apply(sourceId: string, assetResult: AssetResult, options?: ApplyAssetOptions): Promise<number>applyToBlock()#
Apply an asset to a specific block. Honors any middleware registered
via registerApplyToBlockMiddleware and falls back to
defaultApplyAssetToBlock.
Parameters#
| Parameter | Type |
|---|---|
sourceId |
string |
assetResult |
AssetResult |
block |
number |
Returns#
Promise<void>
Signature#
applyToBlock(sourceId: string, assetResult: AssetResult, block: number): Promise<void>applyProperty()#
Apply a property change from an asset payload.
Parameters#
| Parameter | Type |
|---|---|
sourceId |
string |
asset |
AssetResult |
property |
AssetProperty |
Returns#
Promise<void>
Signature#
applyProperty(sourceId: string, asset: AssetResult, property: AssetProperty): Promise<void>defaultApplyAsset()#
Default apply-asset implementation (no middleware). Calls the engine’s
built-in apply logic; used as the tail of the middleware chain in
apply.
Parameters#
| Parameter | Type |
|---|---|
asset |
AssetResult |
options? |
DefaultApplyAssetOptions |
Returns#
Promise<number>
Signature#
defaultApplyAsset(asset: AssetResult, options?: DefaultApplyAssetOptions): Promise<number>defaultApplyAssetToBlock()#
Default apply-to-block implementation (no middleware). Used as the
tail of the middleware chain in applyToBlock.
An aspect ratio or fixed size preset reads the block’s layout, so the call
performs an internal update to lay out pending changes. With the setting
features/implicitUpdatesEnabled off, the preset can read the layout of
the last update instead of pending changes. A block with no layout on a
page that single page mode hides returns an error.
Parameters#
| Parameter | Type |
|---|---|
asset |
AssetResult |
block |
number |
Returns#
Promise<void>
Signature#
defaultApplyAssetToBlock(asset: AssetResult, block: number): Promise<void>registerApplyMiddleware()#
Register a middleware in the global apply-asset chain, matching
@cesdk/engine’s registerApplyMiddleware. Returns a function that
unregisters it.
@cesdk/engine’s registerApplyMiddleware. Returns a function that
unregisters it.The middleware receives a context that holds every option passed to
apply, custom keys included. A context object that it passes to apply
is merged over the received one into a new object: its top-level keys
reach the next middleware and the default apply, and the keys it leaves
out keep their values. A passed placement replaces the whole placement.
Set a key to undefined to clear its value. Without a new context object,
the next middleware gets the same object that the middleware received, so
writes to it reach the outer middlewares. Only the abortSignal of the
call to engine.asset.apply stops the apply.
Parameters#
| Parameter | Type |
|---|---|
middleware |
(sourceId, assetResult, apply, context) => Promise<number> |
Returns#
() => void
Signature#
registerApplyMiddleware(middleware: (sourceId: string, assetResult: AssetResult, apply: (sourceId: string, assetResult: AssetResult, options: ApplyAssetOptions) => Promise<number>, context: ApplyAssetOptions) => Promise<number>): () => voidregisterApplyToBlockMiddleware()#
Register a middleware in the global apply-asset-to-block chain. Mirrors
@cesdk/engine’s registerApplyToBlockMiddleware. Returns a function that
unregisters it.
@cesdk/engine’s registerApplyToBlockMiddleware. Returns a function that
unregisters it.Parameters#
| Parameter | Type |
|---|---|
middleware |
(sourceId, assetResult, block, applyToBlock) => Promise<void> |
Returns#
() => void
Signature#
registerApplyToBlockMiddleware(middleware: (sourceId: string, assetResult: AssetResult, block: number, applyToBlock: (sourceId: string, assetResult: AssetResult, block: number) => Promise<void>) => Promise<void>): () => voidcanManageAssets()#
Whether the named source declared the deprecated canManageAssets flag
when it was registered.
canManageAssets flag
when it was registered.The name suggests a capability question, but the answer is a record of
what the host passed to addSource: a source registered without the
flag reports false, and so does a source registered through addLocalSource, which never carries one. An unknown id is false
rather than an error.
@cesdk/engine defines this method and is the reference for it, so this
reads the recorded flag exactly as the web binding does. It used to probe
the engine with a dry-run remove instead, which answered a different
question — “can assets be added to and removed from this source?” — and
returned true for every local source where the web binding returns
false.
Parameters#
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The source to ask about. |
Returns#
boolean
Whether that source declared the flag.
Deprecated#
The underlying flag is deprecated. To control whether an
upload button is rendered, use the canAdd option on an asset library
entry instead.