cycyexcel
中文0.2.0

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]
});
NameTypeDescription
namestringA unique plugin name for diagnostics and registration ownership.
setup(context: PluginContext) => void | DisposerCalled once at installation. A returned Disposer is called during plugin cleanup.
pluginsreadonly CyExcelPlugin[]A CyExcelCoreOptions constructor option. Plugins install in array order.

PluginContext capabilities

NameTypeDescription
events.on()(event, listener) => DisposerObserve completed commits, selection changes, and errors.
hooks.tap()(hookName, meta, handler) => DisposerParticipate before commands or structural operations.
hooks.tapAsync()(hookName, meta, handler) => DisposerRegister an asynchronous handler. Current built-in hooks are synchronous, so this throws async-hook-not-supported.
contextMenu.registerProvider()(meta, provider) => DisposerAdd context-menu items.
getCell()(row, column) => unknownRead-only cell access.
copy() / paste()PromiseUse core clipboard operations.
insertRows(start, count?)voidInsert blank rows through public commands. count defaults to 1.
deleteRows(start, count?)voidDelete rows through public commands. count defaults to 1.
moveRows(start, count, target)voidMove rows through public commands.
insertColumns(start, columns)voidInsert one or more columns, each with a complete ColumnDefinition.
deleteColumns(start, count?)voidDelete columns through public commands. count defaults to 1.
moveColumns(start, count, target)voidMove columns through public commands.
hideColumn(column)voidHide the column at the specified index.
registerShortcut()(combo, handler) => DisposerRegister a keyboard shortcut.

Plugin event audit

Each write or row insertion commits a Command and emits a change event.

Waiting for an action...