The main plugin code is placed to a .js file which describes what and how must be done by the plugin. This file is placed to the plugin root folder together with the config.json and index.html files.
Any plugin has window.Asc.plugin object which in its turn has several methods for it to interact with ONLYOFFICE document, spreadsheet and presentation editors.
For the plugin to work the developer must specify two obligatory events for the window.Asc.plugin object: window.Asc.plugin.init and window.Asc.plugin.button. After that the window.Asc.plugin.callCommand method is used to send the data to the editors using the in-built ONLYOFFICE Document Builder API features.
If the plugin operates with an OLE object, window.Asc.plugin.executeCommand method is used to manage it.
Let's see how this is done in the helloworld.js plugin:
(function (window, undefined) { window.Asc.plugin.init = function () { this.callCommand(function() { var oDocument = Api.GetDocument(); var oParagraph = Api.CreateParagraph(); oParagraph.AddText("Hello world!"); oDocument.InsertContent([oParagraph]); }, true); }; window.Asc.plugin.button = function (id) { }; })(window, undefined);
When the plugin object is being initialized (window.Asc.plugin.init = function () {...}), the editor forms a paragraph with the Hello World phrase and then uses ONLYOFFICE Document Builder API to create the document with this text in it (with the help of the window.Asc.plugin.callCommand method - this.callCommand(function() {...})).
The only OK button (window.Asc.plugin.button = function (id) {...}) is used to create the text and finish the work with the plugin.
More existing open source plugin examples can be found here.