defineActions API
The defineActions helper function creates properly typed action arrays
for the command palette.
Function Signature
function defineActions(actions: action[]): action[]Full Example
import { defineActions } from '$lib';
import type { action } from '$lib';
const actions = defineActions([
{
// Required
title: 'Go to Dashboard',
// Optional - Unique identifier
actionId: 'nav-dashboard',
// Optional - Secondary text
subTitle: 'View your analytics',
// Optional - Additional description
description: 'Opens the main dashboard with all your metrics',
// Optional - Icon (emoji or image URL)
icon: '📊',
// Optional - Group header
group: 'Navigation',
// Optional - Search keywords
keywords: ['analytics', 'metrics', 'home', 'main'],
// Optional - Keyboard shortcut
shortcut: 'G D',
// Optional - Action handler
onRun: ({ action, storeProps, storeMethods }) => {
console.log('Executing:', action.title);
goto('/dashboard');
},
// Optional - Conditional execution
canActionRun: ({ action, storeProps, storeMethods }) => {
return storeProps.isAuthenticated;
}
}
]);Type Definition
interface action {
title: string;
actionId?: string | number;
subTitle?: string;
description?: string;
icon?: string;
group?: string;
keywords?: string[];
shortcut?: string;
onRun?: (params: onRunParams) => void;
canActionRun?: (params: onRunParams) => boolean;
}
interface onRunParams {
action: action;
storeProps: storeParams;
storeMethods: StoreMethods;
}Property Reference
| Property | Type | Required | Description |
|---|---|---|---|
title | string | ✓ | Main display text for the action |
actionId | string | number | Unique identifier (auto-generated if omitted) | |
subTitle | string | Secondary text below title | |
description | string | Additional descriptive text | |
icon | string | Emoji or image URL | |
group | string | Group header name | |
keywords | string[] | Additional search terms | |
shortcut | string | Keyboard shortcut (tinykeys format) | |
onRun | function | Callback when action executes | |
canActionRun | function | Conditional check before execution |
Callback Parameters
Both onRun and canActionRun receive:
| Parameter | Type | Description |
|---|---|---|
action | action | The current action being executed |
storeProps | storeParams | Current palette state (commands, results, etc.) |
storeMethods | StoreMethods | Methods to control the palette |