@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 41 lines 1.6 KB
Raw
1 import { msg } from "gt-react";
2 import type { KeybindingCommand, ResolvedKeybindingsConfig } from "@t3tools/contracts";
3 import type { UsageChartMetric } from "./UsageProviderChart";
4 import { resolveShortcutCommand, type ShortcutEventLike } from "../../keybindings";
5
6 export type UsageMetric = UsageChartMetric | "limits";
7 export const METRIC_OPTIONS = [
8 { value: "cost", label: msg("Cost"), command: "usage.cost" },
9 { value: "tokens", label: msg("Tokens"), command: "usage.tokens" },
10 { value: "limits", label: msg("Limits"), command: "usage.limits" },
11 ] as const satisfies readonly { value: UsageMetric; label: string; command: KeybindingCommand }[];
12
13 export const WINDOW_OPTIONS = [
14 { days: 1, label: msg("Past 24h"), command: "usage.period.day" },
15 { days: 7, label: msg("7 days"), command: "usage.period.week" },
16 { days: 30, label: msg("30 days"), command: "usage.period.month" },
17 { days: 90, label: msg("90 days"), command: "usage.period.quarter" },
18 ] as const;
19
20 export function resolveUsageShortcut(
21 event: ShortcutEventLike & { target: EventTarget | null },
22 keybindings: ResolvedKeybindingsConfig,
23 ) {
24 const target = event.target;
25 if (
26 target instanceof HTMLElement &&
27 (target.tagName === "INPUT" ||
28 target.tagName === "TEXTAREA" ||
29 target.tagName === "SELECT" ||
30 target.isContentEditable ||
31 target.closest(
32 '[role="dialog"]:not([data-app-modal]), [aria-modal="true"]:not([data-app-modal]), [data-slot$="popup"]:not([data-app-modal])',
33 ))
34 ) {
35 return null;
36 }
37
38 return resolveShortcutCommand(event, keybindings, {
39 context: { usagePageOpen: true },
40 });
41 }