@woodwing/assets-plugin-context v1.0.2
Eos Assets Plugin Context Service
This library can be used to allow for communication between your externally hosted Assets plugin and the Assets client. Previously, an elvisContext
object was available through the parent frame. However, since externally hosted plugins will be on another domain, it's impossible to access the parent frame because of cross-origin restrictions.
Installation
npm install --save @woodwing/assets-plugin-context
Usage
The library exports the AssetsPluginContext
class which you can use in your Typescript/ES6 project. For legacy purposes, the AssetsPluginContext
class is also made available on the window
(ie. window.AssetsPluginContext
).
To initialize communication, use the static AssetsPluginContext.get
function and supply the URI to your Assets installation.
const contextService = await AssetsPluginContext.get('https://my-assets.url');
You can access the current context data at any point.
const context = contextService.context;
You can subscribe to context data changes with the subscribe method.
contextService.subscribe(data => console.log(data));
Using the fetch method, you can proxy calls to the Assets server through the client window.
const searchResults = await contextService.fetch('/services/search', {
method: 'POST',
body: {
// your query here
}
});
The following methods are available to interact with the client interface
contextService.pinCollections(['1', '2', '3']);
contextService.cancelCheckout(['1', '2', '3']);
contextService.checkin(['1', '2', '3']);
contextService.checkout(['1', '2', '3']);
contextService.close();
const hasFilteredSelection = contextService.hasFilteredSelection();
const hasSelection = contextService.hasSelection();
const isSingleItem = contextService.isSingleItem();
await contextService.login();
contextService.openAssets(['1', '2', '3']);
contextService.openBrowse('/my/path');
contextService.openCollections(['1', '2', '3']);
contextService.openSearch('id:1 OR id:2');
Documentation
If you are writing your plugin in Typescript, your IDE should automatically recognize the types that the library exports. If this is not the case however (or if you just want a human-readable overview), you can open the automatically generated documentation (./docs/index.html
) in your favorite browser.