Asset Library Entry
An Asset Source is defined within the engine and can be seen as some sort of database of assets, it does not define how these assets are presented to the user. The web editor provides a versatile asset library that will display the assets in a user-friendly way inside a panel. However since an asset source does not provide any presentational information, the web editor needs to be told how to display the assets. This connection is made with an Asset Library Entry
.
When you open the asset library, either by calling openPanel
or adding a ly.img.assetLibrary.dock
component to the dock, you must provide asset library entries. Only with these entries, the asset library will know what and how to display assets.
Managing Asset Library Entries#
The CE.SDK web editor has an internal store of asset library entries that are referenced by asset libraries. You can find, add, remove, and update entries in this store.
CreativeEditorSDK.create('#cesdk', config).then(async (cesdk) => {await cesdk.addDefaultAssetSources();await cesdk.addDemoAssetSources();await cesdk.createDesignScene();// Find all asset library entriesconst entryIds = cesdk.ui.findAllAssetLibraryEntries();if (entryIds.includes('ly.img.image')) {// Get the default image entry of the web editorconst entry = cesdk.ui.getAssetLibraryEntry('ly.img.image');// ... to add a new source id.cesdk.ui.updateAssetLibraryEntry('ly.img.image', {sourceIds: [...entry.sourceIds, 'my.own.image.source'],});}// Add a new custom asset library entrycesdk.ui.addAssetLibraryEntry({id: 'my.own.image.entry',sourceIds: ['my.own.image.source'],sceneMode: 'Design',previewLength: 5,previewBackgroundType: 'cover',gridBackgroundType: 'cover',gridColumns: 2});// Remove a default entry for stickers.cesdk.ui.removeAssetLibraryEntry('ly.img.sticker');
Method | Description |
---|---|
Method findAllAssetLibraryEntries() | Description Returns all available asset library entries by their id. |
Method addAssetLibraryEntry(entry) | Description Adds a new asset library entry to the store. |
Method getAssetLibraryEntry(id) | Description Returns the asset library entry for the given id if present and undefined otherwise. |
Method updateAssetLibraryEntry(id, entry) | Description Updates the asset library entry for the given id with the provided entry object. It does not replace the entry but is merged with a present entry. |
Method removeAssetLibraryEntry(id) | Description Removes the asset library entry for the given id. |
Using Asset Library Entries#
Asset library entries are used by an asset library. How the library gets the entries depends on the context. The main use case for a library is the dock. This is described in the Dock API documentation. We will describe further use cases here.
Replace Asset Library#
The fill of a block can be replaced with another asset. What assets are applicable is different for each block. The web editor provides a function setReplaceAssetLibraryEntries
. It gets a function that is used to define what block should be replaced with what asset. It will get the current context (most importantly the selected block) and will return ids to asset library entries that shall be used by the replace asset library.
cesdk.ui.setReplaceAssetLibraryEntries((context) => {const { selectedBlocks, defaultEntryIds } = context;// Most of the time replace makes only sense if one block is selected.if (selectedBlocks.length !== 1) {// If no entry ids are returned, a replace button will not be shown.return [];}// id, block and fill type are provided for the selected block.const { id, blockType, fillType } = selectedBlocks[0];if (fillType === '//ly.img.ubq/fill/image') {return ['my.own.image.entry'];}return [];});
Background Tracks Asset Library#
In the video timeline, the background track allows only certain type of assets. With setBackgroundTrackAssetLibraryEntries
you can define what asset library entries are allowed for the background track when the user clicks on the "Add to Background Track" button.
// Only the image and video entries are allowed for the background track.cesdk.ui.setBackgroundTrackAssetLibraryEntries(['ly.img.video', 'ly.img.video']);
Asset Library Entry Definition#
Define What to Display#
The following properties tell the asset library what data should be queried and displayed.
Property | Type | Description |
---|---|---|
Property id | Type string | Description The unique id of this entry that is referenced by other APIs and passed to the asset library. |
Property sourceIds | Type string[] | Description Defines what asset sources should be queried by the asset library. |
Property excludeGroups | Type string[] | Description If the asset sources support groups, these will be excluded and not displayed. |
Property includeGroups | Type string[] | Description If the asset sources support groups, only these will be displayed and all other groups will be ignored. |
Property sceneMode | Type 'Design' or 'Video' | Description If set, the asset library will use this entry exclusively in the respective scene mode. |
Define How to Display#
Besides properties that define what data should be displayed, there are also properties that specify how the data should be displayed to meet specific use case requirements.
Preview and Grid#
Some settings are for the preview and some for the grid view. If multiple asset sources or groups within a source are used, the asset library will show short sections with only a few assets shown. This is what we call the preview. The grid view is the main view where all assets are shown.
Property | Type | Description |
---|---|---|
Property title | Type string or ((options: { group?: string; sourceId?: string }) => string | Description Use for custom translation in the overviews for a group or a source. If undefined is returned by the function it will be handled like there wasn't a title function set at all. |
Property canAdd | Type boolean' or '(sourceId: string) => boolean' | Description If true an upload button will be shown and the uploaded file will be added to the source. Please note that the asset source needs to support addAsset as well. |
Property canRemove | Type boolean' or '(sourceId: string) => boolean' | Description If true a remove button will be shown which will remove the asset from the source. Please note that the asset source needs to support removeAsset as well. |
Property previewLength | Type number | Description Defines how many assets will be shown in a preview section of a source or group. |
Property previewBackgroundType | Type cover or contain | Description If the thumbUri is set as a background that will be contained or covered by the card in the preview view. |
Property gridBackgroundType | Type cover or contain | Description If the thumbUri is set as a background that will be contained or covered by the card in the grid view. |
Property gridColumns | Type number | Description Number of columns in the grid view. |
Property gridItemHeight | Type auto or square | Description The height of an item in the grid view:- auto automatically determines height yielding a masonry-like grid view.- square every card will have the same square size. |
Property cardBorder | Type boolean | Description Draws a border around the card if set to true. |
Property cardLabel | Type (assetResult: AssetResult) => string | Description Overwrites the label of a card for a specific asset result |
Property cardLabelPosition | Type (assetResult: AssetResult) => 'inside' or 'below' | Description Position of the label inside or below the card. |
Property cardLabelTruncateLines | Type (assetResult: AssetResult) => 'single' or 'multi' | Description Controls label truncation to occur at end of first line (single ), or at end of second line (multi ). |
Property cardBackground | Type CardBackground[] | Description Determines what will be used as the card background from the asset and in which priorities. The first preference for which the path returns a value will be used to decide what and how the background will be rendered. E.g. a path of meta.thumbUri will look inside the asset for a value asset.meta.thumbUri . This non-null value will be used.The type of preference decides how the card will render the background. svgVectorPath creates a <svg> element with the given vector path. Adapts the color depending on the theme. image uses a CSS background image |
Property sortBy | Type The value can be one of the following:
| Description Controls the sorting of asset source entries inside the asset library. This can be one of three possible values:
|