cycyexcel
中文0.2.0

EXTEND

Hooks

Hooks can observe, transform, or cancel an operation before submission. Events observe completed results.

Execution modes

ts
sheet.hooks.tap(
  "beforeCommand",
  { name: "audit" },
  (context) => {
    const { command } = context as { command: { type: string } };
    if (command.type === "delete-rows") {
      context.cancel?.("Row deletion is disabled in this example");
    }
  }
);
NameTypeDescription
seriesmodeRun all handlers in order.
bailmodeRun handlers in order, stopping when one cancels.
waterfallmodePass each handler's return value to the next handler.
parallelmodeHandlers do not depend on one another's side effects.

Registration signature

ts
const dispose = sheet.hooks.tap(
  "beforeCommand",
  { name: "audit", priority: 10 },
  (context) => {
    // series/bail: The handler receives context; its return value is ignored.
    // waterfall: The second argument is context; the return value passes to the next handler.
  }
);

// Unregister when no longer needed; sheet disposal also cleans up handlers.
dispose();
NameTypeDescription
hookNamestringA registered hook name. Unknown names throw unknown-hook.
meta{ name: string; priority?: number }name identifies the handler in logs and errors. Higher priority runs first; defaults to 0.
handlercontext => void or (value, context) => TValueOnly waterfall uses the second argument and consumes return values. Other modes ignore return values.
Return value() => voidA Disposer that unregisters the handler when called.

Available hooks

NameTypeDescription
beforeInitseriescontext: {}. Runs during plugin setup, before core assembly completes. Returns void; throwing aborts initialization.
beforeDestroyseriescontext: {}. Runs before dispose(). Returns void; individual handler errors are isolated and sent to onHookError.
beforeCommandbailcontext: { command: { type, params }, transactionId, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents command planning.
beforeTransactionCommitbailcontext: { commands, patches, model, transactionId, cancel(reason?), cancelled, reason }. Returns void; cancellation prevents the whole transaction from committing.
beforeRowsChangebailcontext: { operation: 'insert' | 'delete' | 'move', start, count, target?, cancel(reason?), cancelled, reason }. target is present for moves. Returns void; cancel() prevents the row operation.
beforeColumnsChangebailcontext: { operation: 'insert' | 'delete' | 'move', start, count, target?, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents the column operation.
resolveColumnwaterfallhandler: (column: RuntimeColumn, { definition, index }) => RuntimeColumn. Return the column configuration. Errors are isolated and retain the previous value.
beforeContextMenuOpenbailcontext: { context: ContextMenuContext, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents the menu from opening.
extendContextMenuwaterfallhandler: (items: ContextMenuItem[], context: ContextMenuContext) => ContextMenuItem[]. Return the final items. Handler errors are isolated.
onHookErrorseriescontext: { error: unknown, hookName: string, handlerName: string }. Returns void; errors in this hook do not recursively invoke it.

beforeCommand audit

Each write or row insertion triggers beforeCommand first.

Waiting for an action...