mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 19:36:00 +00:00
41 lines
775 B
TypeScript
41 lines
775 B
TypeScript
import { commands } from '../stores';
|
|
|
|
export interface SubCommand {
|
|
text: string;
|
|
onClick: Function;
|
|
}
|
|
|
|
export interface GlobalCommand {
|
|
id: string;
|
|
text: string;
|
|
keyText?: string;
|
|
getSubCommands?: () => SubCommand[];
|
|
onClick?: Function;
|
|
enabledStore?: any;
|
|
icon?: string;
|
|
toolbar?: boolean;
|
|
enabled?: boolean;
|
|
}
|
|
|
|
export default function registerCommand(command: GlobalCommand) {
|
|
const { enabledStore } = command;
|
|
commands.update(x => ({
|
|
...x,
|
|
[command.id]: {
|
|
...command,
|
|
enabled: !enabledStore,
|
|
},
|
|
}));
|
|
if (enabledStore) {
|
|
enabledStore.subscribe(value => {
|
|
commands.update(x => ({
|
|
...x,
|
|
[command.id]: {
|
|
...x[command.id],
|
|
enabled: value,
|
|
},
|
|
}));
|
|
});
|
|
}
|
|
}
|