A simple example plugin demonstrating the POLLN plugin API.
This plugin demonstrates:
- Toolbar Button: Adds a "Say Hello" button to the toolbar
- Menu Item: Adds a "Hello World" item to the menu
- Custom Cell Type: Creates a "hello-cell" type that displays greetings
- Data Source: Registers a data source that provides greeting messages
- Event Handling: Subscribes to cell change events
- Storage: Persists greeting count across sessions
- Notifications: Displays greeting notifications
- Build the plugin:
npm install
npm run build- Install in Polln:
npm install @polln/example-pluginOnce installed and activated:
- Click the "Say Hello" button in the toolbar
- Select "Hello World" from the menu
- Create a cell with type "hello-cell" and configure it:
{
"greeting": "Hello",
"target": "World"
}- Query the hello-data-source for random greetings
// Read cells
const cell = await context.api.cells.getCell('A1');
// Write cells
await context.api.cells.setCellValue('A1', 'Hello');
// Watch for changes
context.api.cells.watchCell('A1', (cell) => {
console.log('Cell changed:', cell);
});// Show notification
context.api.ui.showNotification({
type: 'info',
title: 'Hello',
message: 'World',
duration: 3000,
});
// Register toolbar button
context.api.ui.registerToolbar({
id: 'my-button',
label: 'Click Me',
onClick: () => console.log('Clicked!'),
});// Register data source
context.api.data.registerDataSource({
id: 'my-source',
name: 'My Data Source',
type: 'custom',
config: {},
query: async (query) => {
return { data: 'results' };
},
});
// Query data source
const results = await context.api.data.queryDataSource('my-source', {});// Subscribe to events
context.api.events.on('cell:changed', (data) => {
console.log('Cell changed:', data);
});
// Emit events
context.api.events.emit('custom:event', { data: 'value' });// Store data
await context.api.storage.set('key', 'value');
// Retrieve data
const value = await context.api.storage.get('key');
// List keys
const keys = await context.api.storage.list();context.logger.debug('Debug message');
context.logger.info('Info message');
context.logger.warn('Warning message');
context.logger.error('Error message');The plugin can be configured via Polln's plugin settings:
{
"greeting": "Hello",
"target": "World",
"greetings": ["Hello", "Hi", "Greetings"]
}This plugin requests the following permissions:
READ_CELLS: To read cell values for greeting customizationUI_CUSTOMIZATION: To add toolbar buttons and menu itemsNOTIFICATIONS: To display greeting notifications
- Clone the Polln repository
- Navigate to
example-plugin - Install dependencies:
npm install - Build:
npm run build - Watch for changes:
npm run watch
MIT
POLLN Team