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");
}
}
);| Name | Type | Description |
|---|---|---|
| series | mode | Run all handlers in order. |
| bail | mode | Run handlers in order, stopping when one cancels. |
| waterfall | mode | Pass each handler's return value to the next handler. |
| parallel | mode | Handlers 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();| Name | Type | Description |
|---|---|---|
| hookName | string | A 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. |
| handler | context => void or (value, context) => TValue | Only waterfall uses the second argument and consumes return values. Other modes ignore return values. |
| Return value | () => void | A Disposer that unregisters the handler when called. |
Available hooks
| Name | Type | Description |
|---|---|---|
| beforeInit | series | context: {}. Runs during plugin setup, before core assembly completes. Returns void; throwing aborts initialization. |
| beforeDestroy | series | context: {}. Runs before dispose(). Returns void; individual handler errors are isolated and sent to onHookError. |
| beforeCommand | bail | context: { command: { type, params }, transactionId, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents command planning. |
| beforeTransactionCommit | bail | context: { commands, patches, model, transactionId, cancel(reason?), cancelled, reason }. Returns void; cancellation prevents the whole transaction from committing. |
| beforeRowsChange | bail | context: { operation: 'insert' | 'delete' | 'move', start, count, target?, cancel(reason?), cancelled, reason }. target is present for moves. Returns void; cancel() prevents the row operation. |
| beforeColumnsChange | bail | context: { operation: 'insert' | 'delete' | 'move', start, count, target?, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents the column operation. |
| resolveColumn | waterfall | handler: (column: RuntimeColumn, { definition, index }) => RuntimeColumn. Return the column configuration. Errors are isolated and retain the previous value. |
| beforeContextMenuOpen | bail | context: { context: ContextMenuContext, cancel(reason?), cancelled, reason }. Returns void; cancel() prevents the menu from opening. |
| extendContextMenu | waterfall | handler: (items: ContextMenuItem[], context: ContextMenuContext) => ContextMenuItem[]. Return the final items. Handler errors are isolated. |
| onHookError | series | context: { 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...