UNPKG

cmd-bar

Version:

Versatile Vue 3 command-bar component

307 lines (271 loc) 8.74 kB
import { ComponentOptionsMixin } from 'vue'; import { ComponentProvideOptions } from 'vue'; import { DefineComponent } from 'vue'; import { Emitter } from 'mitt'; import { ExtractPropTypes } from 'vue'; import { PropType } from 'vue'; import { PublicProps } from 'vue'; import { UseFuseOptions } from '@vueuse/integrations/useFuse'; declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T; declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T; declare type __VLS_NonUndefinedable_3<T> = T extends undefined ? never : T; declare type __VLS_NonUndefinedable_4<T> = T extends undefined ? never : T; declare type __VLS_NonUndefinedable_5<T> = T extends undefined ? never : T; declare type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {}; declare type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: PropType<__VLS_NonUndefinedable<T[K]>>; } : { type: PropType<T[K]>; required: true; }; }; declare type __VLS_TypePropsToRuntimeProps_2<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: PropType<__VLS_NonUndefinedable_2<T[K]>>; } : { type: PropType<T[K]>; required: true; }; }; declare type __VLS_TypePropsToRuntimeProps_3<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: PropType<__VLS_NonUndefinedable_3<T[K]>>; } : { type: PropType<T[K]>; required: true; }; }; declare type __VLS_TypePropsToRuntimeProps_4<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: PropType<__VLS_NonUndefinedable_4<T[K]>>; } : { type: PropType<T[K]>; required: true; }; }; declare type __VLS_TypePropsToRuntimeProps_5<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: PropType<__VLS_NonUndefinedable_5<T[K]>>; } : { type: PropType<T[K]>; required: true; }; }; declare type __VLS_WithDefaults<P, D> = { [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & { default: D[K]; }> : P[K]; }; declare type __VLS_WithTemplateSlots<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_2<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_3<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_4<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_5<T, S> = T & { new (): { $slots: S; }; }; export declare const CmdBar: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ commands: Group[]; }>>, { resetState: () => void; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ commands: Group[]; }>>> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, { default?(_: {}): any; }>; export declare const CmdBarDialog: __VLS_WithTemplateSlots_2<DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{ visible: boolean; }>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, { "update:visible": (value: boolean) => void; }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{ visible: boolean; }>>> & Readonly<{ "onUpdate:visible"?: ((value: boolean) => any) | undefined; }>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, Readonly<{ header(): any; content(): any; footer(): any; }> & { header(): any; content(): any; footer(): any; }>; export declare const CmdBarFilter: __VLS_WithTemplateSlots_5<DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_5<{ filterOptions: FilterOption[]; asCheckbox?: boolean | undefined; }>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_5<{ filterOptions: FilterOption[]; asCheckbox?: boolean | undefined; }>>> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, Readonly<{ default(props: { group: FilterOption; isSelected: boolean; }): any; option(props: { hiddenOptions: FilterOption[]; }): any; }> & { default(props: { group: FilterOption; isSelected: boolean; }): any; option(props: { hiddenOptions: FilterOption[]; }): any; }>; export declare const CmdBarInput: __VLS_WithTemplateSlots_3<DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_3<Props>, { modelValue: undefined; placeholder: string; fuse: () => {}; nonTriggerKeys: () => string[]; threshold: number; }>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, { "update:modelValue": (value: string) => void; }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_3<Props>, { modelValue: undefined; placeholder: string; fuse: () => {}; nonTriggerKeys: () => string[]; threshold: number; }>>> & Readonly<{ "onUpdate:modelValue"?: ((value: string) => any) | undefined; }>, { threshold: number; modelValue: string; placeholder: string; fuse: UseFuseOptions<Command>; nonTriggerKeys: string[]; }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, Readonly<{ leading(): any; clear(): any; }> & { leading(): any; clear(): any; }>; export declare const CmdBarList: __VLS_WithTemplateSlots_4<DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_4<{ loop?: boolean | undefined; resultsHeader?: string | null | undefined; }>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_4<{ loop?: boolean | undefined; resultsHeader?: string | null | undefined; }>>> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, Readonly<{ default(props: { command: Command; }): any; loading(): any; results(props: { command: Command; }): any; 'no-results'(): any; preview(props: { activeCommand: Command | null; }): any; }> & { default(props: { command: Command; }): any; loading(): any; results(props: { command: Command; }): any; 'no-results'(): any; preview(props: { activeCommand: Command | null; }): any; }>; export declare interface Command { key: string; leading?: string | []; label: string; action: () => void; group?: string; score?: number; /** * Format is based on useMagicKeys. * @example * 'Enter' * 'Ctrl+N' * 'Ctrl+Shift+P' */ shortcut?: string; [key: string]: any; } export declare function defineCommand(params: Command): Command; declare type Events = { selected: Command | null; executed: Command; input: string; filterChange: (string | null)[]; }; export declare interface FilterOption { groupKey: string | null; visible: boolean; label: string; } export declare interface Group { key: string; commands?: Command[]; visible?: boolean; search?: (query: string) => Promise<Command[]>; [key: string]: any; } export declare interface NavOperations { next: () => void; prev: () => void; execute: () => void; } declare interface Props { modelValue?: string; placeholder?: string; fuse?: UseFuseOptions<Command>; nonTriggerKeys?: string[]; threshold?: number; } export declare interface ShortcutOptions { key: string; action: () => void; autoRepeat?: boolean; } declare type ShortcutsSetup = (nav: NavOperations) => Array<ShortcutOptions>; export declare type State = { selectedCommandKey: string | null; query: string; isLoading: boolean; groups: Group[]; commands: Command[]; results: Command[]; selectedGroups: Set<string | null>; fuseOptions: Partial<UseFuseOptions<Command>> | null; /** * Whether to loop back to the first command when reaching the end of the list. */ loop: boolean; }; export declare const useCmdBarEvent: () => { emitter: Emitter<Events>; }; export declare function useKeymap(fn: ShortcutsSetup): { addEventListener: () => void; removeEventListener: () => void; }; export { }