| 1 | import type { DcpCommand, TuiApi } from "./types" |
| 2 | |
| 3 | export function registerCommands(api: TuiApi, commands: DcpCommand[]) { |
| 4 | const keymap = (api as any).keymap |
| 5 | if (keymap?.registerLayer) { |
| 6 | keymap.registerLayer({ |
| 7 | commands: commands.map((command) => ({ |
| 8 | namespace: "palette", |
| 9 | name: command.name, |
| 10 | title: command.title, |
| 11 | desc: command.description, |
| 12 | category: "DCP", |
| 13 | slashName: command.slashName, |
| 14 | slashAliases: command.slashAliases, |
| 15 | run: command.run, |
| 16 | })), |
| 17 | }) |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | api.command?.register(() => |
| 22 | commands.map((command) => ({ |
| 23 | title: command.title, |
| 24 | value: command.name, |
| 25 | description: command.description, |
| 26 | category: "DCP", |
| 27 | slash: { name: command.slashName, aliases: command.slashAliases }, |
| 28 | onSelect: command.run, |
| 29 | })), |
| 30 | ) |
| 31 | } |