Plugin engine and registration
experimental
Register plugins with dependencies and lifecycle hooks, and see the resolved order.
Live example
Expected behavior
Toggling a plugin updates the resolved order. A missing dependency or a plugin that others depend on produces a clear error. The runtime-registered row-counter plugin appears and writes to the footer.
Source
const sorting = definePlugin({ id: 'sorting', version: '1.0.0' });
const selection = definePlugin({ id: 'selection', version: '1.0.0' });
const history = definePlugin({
id: 'history',
version: '1.0.0',
dependsOn: ['selection'],
keybindings: [{ key: 'Ctrl+Z', description: 'Undo' }],
});
const api = createGrid({ rows, columns, plugins: [history, sorting, selection] });
await api.registerPlugin(rowCounter);
api.on('plugin:registered', ({ id }) => console.log(id));
await api.unregisterPlugin('history');const sorting = definePlugin({ id: 'sorting', version: '1.0.0' });
const selection = definePlugin({ id: 'selection', version: '1.0.0' });
const history = definePlugin({
id: 'history',
version: '1.0.0',
dependsOn: ['selection'],
keybindings: [{ key: 'Ctrl+Z', description: 'Undo' }],
});
const api = createGrid({ rows, columns, plugins: [history, sorting, selection] });
await api.registerPlugin(rowCounter);
api.on('plugin:registered', ({ id }) => console.log(id));
await api.unregisterPlugin('history');const sorting = definePlugin({ id: 'sorting', version: '1.0.0' });
const selection = definePlugin({ id: 'selection', version: '1.0.0' });
const history = definePlugin({
id: 'history',
version: '1.0.0',
dependsOn: ['selection'],
keybindings: [{ key: 'Ctrl+Z', description: 'Undo' }],
});
const api = createGrid({ rows, columns, plugins: [history, sorting, selection] });
await api.registerPlugin(rowCounter);
api.on('plugin:registered', ({ id }) => console.log(id));
await api.unregisterPlugin('history');const sorting = definePlugin({ id: 'sorting', version: '1.0.0' });
const selection = definePlugin({ id: 'selection', version: '1.0.0' });
const history = definePlugin({
id: 'history',
version: '1.0.0',
dependsOn: ['selection'],
keybindings: [{ key: 'Ctrl+Z', description: 'Undo' }],
});
const api = createGrid({ rows, columns, plugins: [history, sorting, selection] });
await api.registerPlugin(rowCounter);
api.on('plugin:registered', ({ id }) => console.log(id));
await api.unregisterPlugin('history');// JavaScript interop module
const sorting = definePlugin({ id: 'sorting', version: '1.0.0' });
const selection = definePlugin({ id: 'selection', version: '1.0.0' });
const history = definePlugin({
id: 'history',
version: '1.0.0',
dependsOn: ['selection'],
keybindings: [{ key: 'Ctrl+Z', description: 'Undo' }],
});
const api = createGrid({ rows, columns, plugins: [history, sorting, selection] });
await api.registerPlugin(rowCounter);
api.on('plugin:registered', ({ id }) => console.log(id));
await api.unregisterPlugin('history');API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Function | definePlugin | — | Validates a plugin manifest and its hooks. |
| Option | plugins | — | Plugins registered at creation in dependency order. |
| Method | registerPlugin | — | Registers a plugin at runtime and runs its setup hook. |
| Method | unregisterPlugin | — | Runs teardown. Rejected while other plugins depend on it. |
| Event | plugin:registered | — | Reports the ID and version of a registered plugin. |