https://github.com/jspreadsheet/plugins
https://github.com/jspreadsheet/plugins
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/jspreadsheet/plugins
- Owner: jspreadsheet
- License: other
- Created: 2020-12-30T18:51:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-28T13:11:33.000Z (almost 5 years ago)
- Last Synced: 2024-12-20T11:19:03.443Z (over 1 year ago)
- Language: JavaScript
- Size: 483 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Plugins
The JSS plugins are the best way to enhance existing or create new features for your online spreadsheets. There are plenty of free or premium plugins already available, but you can build your custom plugins. You will find here official or third-party plugins.
## Custom plugins
You can overwrite a few of the methods described below to create custom features. For instance, change the toolbar or context menu, or implement a server-side spreadsheet data persistence. You will have access to all components in your spreadsheet, and along with the available events, you would be able to create amazing things.
Method
Description
init
When a new worksheet is added.
init(worksheet: Object) : void
onevent
It would receive a call for every spreadsheet event.
onevent(event: String, a?: any, b?: any, c?: any, d?: any) : void
The number of arguments would vary depending on which event is being executed. The first argument is the event name.
persistence
When the spreadsheet needs to save something in the server. The second argument depends on which method is being executed.
persistence(method: String, args: Object) : void
contextMenu
When the user opens the context menu.
contextMenu(instance: Object, x: Number, y: Number, e: MouseEvent, items: Array, section: String, a: any, b?: any) : void
/**
* Run on the context menu
* @param instance Jexcel Spreadsheet Instance
* @param x coordinates from the clicked cell
* @param y coordinates from the clicked cell
* @param e click object
* @param items current items in the contextMenu
* @param section
* @param argument1 depends which section
* @param argument2 depends which section
*/
toolbar
When the toolbar is create and clicked.
toolbar(instance: Object, items: Array) : void
## Basic implementation
The following code is a basic implementation that can be used as a reference.
### Plugin implementation
```Javascript
var newPlugin = (function() {
// Plugin object
var plugin = {};
/**
* It will be executed for every new worksheet
*/
plugin.init = function(worksheet) {
}
/**
* Jspreadsheet events
*/
plugin.onevent = function() {
// It would be executed in every single event and can be used to customize actions
}
/**
* Persistence: It would be call every single time persistence is required
* @param {string} method - action executed
* @param {object} args - depending on the action.
*/
plugin.persistence = function(method, args) {
// Different options are used depending on the action performated.
}
/**
* Run on the context menu
* @param instance Jexcel Spreadsheet Instance
* @param x coordinates from the clicked cell
* @param y coordinates from the clicked cell
* @param e click object
* @param items current items in the contextMenu
*/
plugin.contextMenu = function(instance, x, y, e, items) {
// Can be used to overwrite the contextMenu
return items;
}
/**
* Run on toolbar
* @param instance Jexcel Spreadsheet Instance
* @param items current items in the toolbar
*/
plugin.toolbar = function(instance, items) {
// Can be used to overwrite the toolbar
return items;
}
// Any startup configuration goes here
// (...)
// Return the object
return plugin;
});
```
### Loading the plugin
Considering the following example, you can use the following code to integrate the plugin into a spreadsheet.
```HTML
var spreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [
{ minDimensions: [10, 10] },
{ minDimensions: [10, 10] },
],
plugins: { newPlugin }
});
// This method is used to load plugins after the spreadsheet initialization
var loadPlugins = function() {
spreadsheet.setPlugins({ otherPlugin });
}
```
## Examples
The following code is a working example of a plugin in action.
## Spreadsheet properties update
The properties plugin allow the user to change some of the spreadsheet settings, through a new option included in the context menu.
To test: right-click in any cell and choose the last option in the context mene.
### HTML
```HTML
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [
{ minDimensions: [10, 10] },
{ minDimensions: [10, 10] },
],
plugins: { properties },
});
```
### CDN
```Javascript
// Installation npm install @jspreadsheet/properties
import properties from '@jspreadsheet/properties';
// Loading the plugin into the spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [
{ minDimensions: [10, 10] },
{ minDimensions: [10, 10] },
],
plugins: { properties },
});
```
## Plugins documentation
More about the JSS spreadsheet plugins.
https://jspreadsheet.com/plugins
To publish your plugins on our website. Please, clone this repository and send you PR.