Skip to main content

IFilePlugin

View source on GitHub

The plugin that can interact with the file list.

Example

The plugin class implements IFilePlugin and registers a handler for the ".drawio" extension in the constructor. DocSpace calls getFileItems to hook the plugin into the file list: files with the registered extension get the custom icon, and clicking them triggers the item's onClick.

import {
type IFileItem,
type IFilePlugin,
Actions,
ToastType,
} from "@onlyoffice/docspace-plugin-sdk";

class Plugin implements IFilePlugin {
fileItems: Map<string, IFileItem> = new Map();

constructor() {
this.addFileItem({
extension: ".drawio",
fileTypeName: "Diagram",
fileRowIcon: "diagram-32.svg",
fileTileIcon: "diagram-96.svg",
onClick: async (file) => {
await openDiagramEditor(file.id);
return {
actions: [Actions.showToast],
toastProps: [{
type: ToastType.success,
title: `Opening ${file.title}`
}]
};
}
});
}

addFileItem = (item: IFileItem): void => {
this.fileItems.set(item.extension, item);
};

getFileItems = (): Map<string, IFileItem> => {
return this.fileItems;
};

updateFileItem = (item: IFileItem): void => {
this.fileItems.set(item.extension, item);
};
}

Methods

addFileItem()

addFileItem(item: IFileItem): void;

Add a new item for interactions with files.

Parameters

ParameterTypeDescription
itemIFileItemThe file item to add, containing the file extension, onClick handler, and optional display and access options

Returns

void

getFileItems()

getFileItems(): Map<string, IFileItem>;

Get all the items for interactions with files.

Returns

Map<string, IFileItem>

A Map containing all registered file items, where keys are item identifiers

updateFileItem()

updateFileItem(item: IFileItem): void;

Update an existing file interaction item.

Parameters

ParameterTypeDescription
itemIFileItemThe file item to update with new properties

Returns

void

Properties

PropertyTypeDescription
fileItemsMap<string, IFileItem>Stores a collection of elements where the keys are the key parameters from the FileItem objects. A list for hooking interactions with files is generated based on this collection.