mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 14:46:01 +00:00
47 lines
959 B
TypeScript
47 lines
959 B
TypeScript
import { commands } from '../stores';
|
|
|
|
export interface SubCommand {
|
|
text: string;
|
|
onClick: Function;
|
|
}
|
|
|
|
export interface GlobalCommand {
|
|
id: string;
|
|
category: string;
|
|
name: string;
|
|
text: string /* category: name */;
|
|
keyText?: string;
|
|
getSubCommands?: () => SubCommand[];
|
|
onClick?: Function;
|
|
enabledStore?: any;
|
|
icon?: string;
|
|
toolbar?: boolean;
|
|
enabled?: boolean;
|
|
showDisabled?: boolean;
|
|
toolbarName?: string;
|
|
toolbarOrder?: number;
|
|
}
|
|
|
|
export default function registerCommand(command: GlobalCommand) {
|
|
const { enabledStore } = command;
|
|
commands.update(x => ({
|
|
...x,
|
|
[command.id]: {
|
|
text: `${command.category}: ${command.name}`,
|
|
...command,
|
|
enabled: !enabledStore,
|
|
},
|
|
}));
|
|
if (enabledStore) {
|
|
enabledStore.subscribe(value => {
|
|
commands.update(x => ({
|
|
...x,
|
|
[command.id]: {
|
|
...x[command.id],
|
|
enabled: value,
|
|
},
|
|
}));
|
|
});
|
|
}
|
|
}
|