跳到主要内容

IPlugin

View source on GitHub

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​

ParameterType
statusPluginStatus

Returns​

void

getStatus()​

getStatus(): PluginStatus;

Get the current plugin status

Returns​

PluginStatus

setOnLoadCallback()​

setOnLoadCallback(callback: () => Promise<void>): void;

Sets the onLoadCallback variable to the plugin

Parameters​

ParameterType
callback() => Promise<void>

Returns​

void

Properties​

PropertyTypeDescription
statusPluginStatusThe plugin status (active or hide)
language?PluginLocaleThe plugin language
setLanguage?(language: PluginLocale) => voidThe method is called on the portal side when the portal language is changed.
getLanguage?() => PluginLocaleThe 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