EXTEND
Plugins
Plugins receive controlled capabilities rather than internal stores. Registered resources are cleaned up automatically on disposal.
Plugin structure
ts
const auditPlugin: CyExcelPlugin = {
name: "audit",
setup(context) {
context.events.on("change", (payload) => {
console.log("change", payload);
});
context.registerShortcut("Mod+Shift+L", () => {
console.log("shortcut from plugin");
});
return () => {
console.log("audit plugin disposed");
};
}
};
const sheet = createSheet(container, {
columns,
snapshot,
plugins: [auditPlugin]
});Register a plugin
Install plugins through the plugins array during construction. The public API does not support runtime use() registration.
ts
import { CyExcelCore, type CyExcelPlugin } from "cyexcel/core";
const helloPlugin: CyExcelPlugin = {
name: "hello",
setup(context) {
// Event, hook, and shortcut registrations are cleaned up on plugin disposal.
const disposeChange = context.events.on("change", () => {
console.log("committed change");
});
const disposeShortcut = context.registerShortcut("Mod+Shift+H", () => {
console.log("hello from plugin");
});
// Optional: release resources created by setup.
return () => {
disposeChange();
disposeShortcut();
};
}
};
const sheet = createSheet(container, {
columns,
snapshot,
plugins: [helloPlugin]
});| Name | Type | Description |
|---|---|---|
| name | string | A unique plugin name for diagnostics and registration ownership. |
| setup | (context: PluginContext) => void | Disposer | Called once at installation. A returned Disposer is called during plugin cleanup. |
| plugins | readonly CyExcelPlugin[] | A CyExcelCoreOptions constructor option. Plugins install in array order. |
PluginContext capabilities
| Name | Type | Description |
|---|---|---|
| events.on() | (event, listener) => Disposer | Observe completed commits, selection changes, and errors. |
| hooks.tap() | (hookName, meta, handler) => Disposer | Participate before commands or structural operations. |
| hooks.tapAsync() | (hookName, meta, handler) => Disposer | Register an asynchronous handler. Current built-in hooks are synchronous, so this throws async-hook-not-supported. |
| contextMenu.registerProvider() | (meta, provider) => Disposer | Add context-menu items. |
| getCell() | (row, column) => unknown | Read-only cell access. |
| copy() / paste() | Promise | Use core clipboard operations. |
| insertRows(start, count?) | void | Insert blank rows through public commands. count defaults to 1. |
| deleteRows(start, count?) | void | Delete rows through public commands. count defaults to 1. |
| moveRows(start, count, target) | void | Move rows through public commands. |
| insertColumns(start, columns) | void | Insert one or more columns, each with a complete ColumnDefinition. |
| deleteColumns(start, count?) | void | Delete columns through public commands. count defaults to 1. |
| moveColumns(start, count, target) | void | Move columns through public commands. |
| hideColumn(column) | void | Hide the column at the specified index. |
| registerShortcut() | (combo, handler) => Disposer | Register a keyboard shortcut. |
Plugin event audit
Each write or row insertion commits a Command and emits a change event.
Waiting for an action...