Customize The Asset Library
In this example, we will show you how to customize the asset library in CreativeEditor SDK.
Explore a full code sample on Stackblitz or view the code on Github.
The asset library is used to find assets to insert them into a scene or replace a currently selected asset. By default, we have already added a configuration of entries shown in the dock panel for images, text, stickers, shapes, and more. You can add and remove every entry or change the appearance of any entry.
Every entry has a couple of configuration options to determine what and how assets will be displayed. See the documentation on the Asset Library Entry for more information.
Adding, changing, or removing entries is done using the Asset Library Entries API.
You can for example use cesdk.ui.updateAssetLibraryEntry
to change the number of grid columns in the images library.
The basics of customizing the entries for replacement are the same as for insertion. The main difference is that these entries might vary depending on what block is currently selected and that the returned entries will determine if a replace action is shown on a selected block.
Most of the time it makes sense to provide a custom function to return different entries based on the type or fill of a block. If no replacement should be available for the current block, an empty array has to be returned. The UI will not show a replace button in that case.
As an argument to the callback, you will get the current context in the editor, mainly what blocks are selected, their block type as well as fills. This makes it more convenient to quickly decide what to return, but of course, you can also use the API for further checks as well.
If you do not use a custom title
function for an entry, you need a translation provided with the following keys in the i18n
configuration:
libraries.<entry-id>.label
The label used in the dock panellibraries.<entry-id><group-id>.label
The label for groups for a given entry.libraries.<entry-id>.<source-id>.label
The label for a source in the source overview of a given entrylibraries.<entry-id>.<source-id>.<group-id>.label
The label for a given group in the group overview for a given entry.libraries.<source-id>.label
The label used for a source in all entrieslibraries.<source-id><group-id>.label
The label for groups for source in all entries.