IPlugin
The default plugin. This interface must be implemented in each plugin because without the plugin status it will not be built in.
Example
Every plugin class implements IPlugin (usually together with one or more
type-specific interfaces such as IContextMenuPlugin). DocSpace reads the
plugin status via getStatus and runs onLoadCallback when the plugin is
uploaded to the portal. The optional language field and its setLanguage/
getLanguage methods let the portal keep the plugin in sync with the current
portal language.
import { type IPlugin, PluginStatus, PluginLocale } from "@onlyoffice/docspace-plugin-sdk";
class Plugin implements IPlugin {
status: PluginStatus = PluginStatus.active;
language: PluginLocale = PluginLocale.EN_US;
onLoadCallback = async (): Promise<void> => {
try {
await initializeAnalyzer();
} catch (error) {
// Hide the plugin if it cannot be initialized
this.status = PluginStatus.hide;
}
};
updateStatus = (status: PluginStatus): void => {
this.status = status;
};
getStatus = (): PluginStatus => {
return this.status;
};
// Called by the portal when the portal language changes
setLanguage = (language: PluginLocale): void => {
this.language = language;
};
// Called by the portal to read the current plugin language
getLanguage = (): PluginLocale => {
return this.language;
};
setOnLoadCallback = (callback: () => Promise<void>): void => {
this.onLoadCallback = callback;
};
}
Methods
updateStatus()
updateStatus(status: PluginStatus): void;
Update the plugin status
Parameters
| Parameter | Type |
|---|---|
status | PluginStatus |
Returns
void
getStatus()
getStatus(): PluginStatus;
Get the current plugin status
Returns
setOnLoadCallback()
setOnLoadCallback(callback: () => Promise<void>): void;
Sets the onLoadCallback variable to the plugin
Parameters
| Parameter | Type |
|---|---|
callback | () => Promise<void> |
Returns
void
Properties
| Property | Type | Description |
|---|---|---|
status | PluginStatus | The plugin status (active or hide) |
language? | PluginLocale | The plugin language |
setLanguage? | (language: PluginLocale) => void | The method is called on the portal side when the portal language is changed. |
getLanguage? | () => PluginLocale | The method is called on the portal side to get the plugin language. |
onLoadCallback | () => Promise<void> | Callback which will be executed when uploading the plugin to the portal |