solid-command-palette
Version:
Add a command palette to your Solid.js App
67 lines (66 loc) • 2.35 kB
TypeScript
import { DeepReadonly, Store } from 'solid-js/store';
export declare type ActionId = string;
export declare type ParentActionId = null | ActionId;
export declare type ActionShortcut = string;
export declare type ActionContext = Record<string, unknown>;
export declare type DynamicContextMap = Record<ActionId, ActionContext>;
export declare type ActionsContext = {
root: ActionContext;
dynamic: DynamicContextMap;
};
export declare type RunArgs = {
actionId: ActionId;
rootContext: ActionContext;
dynamicContext: ActionContext;
};
export declare type Action = {
id: ActionId;
parentActionId: ParentActionId;
title: string;
subtitle: null | string;
keywords: Array<string>;
/**
* Keyboard Shortcut like `$mod+e`, `Shift+p`.
*/
shortcut: null | ActionShortcut;
/**
* Enable the action conditionally.
*/
cond?: (args: RunArgs) => boolean;
run?: (args: RunArgs) => void;
};
export declare type PartialAction = Partial<Action> & {
id: ActionId;
title: Action['title'];
};
export declare type Actions = Record<ActionId, Action>;
export declare type ActionsList = Array<Action>;
export declare type WrappedAction = DeepReadonly<Action>;
export declare type WrappedActionList = Array<WrappedAction>;
export declare type RootProps = {
actions: Actions;
actionsContext: ActionContext;
};
export declare type StoreState = {
visibility: 'opened' | 'closed';
searchText: string;
activeParentActionIdList: Array<ActionId>;
actions: Actions;
actionsContext: ActionsContext;
};
export declare type StoreStateWrapped = Store<StoreState>;
export declare type StoreMethods = {
setSearchText: (newValue: string) => void;
setActionsContext: (actionId: ActionId, newData: ActionContext) => void;
resetActionsContext: (actionId: ActionId) => void;
openPalette: () => void;
closePalette: () => void;
togglePalette: () => void;
selectParentAction: (parentActionId: ActionId) => void;
revertParentAction: () => void;
resetParentAction: () => void;
};
export declare type StoreContext = [StoreStateWrapped, StoreMethods];
declare type CreateSyncActionsContextCallback = () => ActionContext;
export declare type CreateSyncActionsContext = (actionId: ActionId, callback: CreateSyncActionsContextCallback) => void;
export {};