command palette control

This commit is contained in:
Jan Prochazka
2021-02-25 18:05:44 +01:00
parent 30ade5867c
commit f0802dc471
13 changed files with 706 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
import { commands } from '../stores';
export interface SubCommand {
text: string;
onClick: Function;
}
export interface GlobalCommand {
id: string;
text: 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,
},
}));
});
}
}