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