From 722dcdd88face3724c77d23bc36a00524e552551 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Thu, 26 Mar 2026 13:52:30 +0100 Subject: fix: resolve typescript/lint errors --- apps/web/src/lib/actions/definitions.ts | 87 +++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 36 deletions(-) (limited to 'apps/web/src/lib/actions/definitions.ts') diff --git a/apps/web/src/lib/actions/definitions.ts b/apps/web/src/lib/actions/definitions.ts index 4d67c1ef..f6bdd65c 100644 --- a/apps/web/src/lib/actions/definitions.ts +++ b/apps/web/src/lib/actions/definitions.ts @@ -1,4 +1,8 @@ -import type { ShortcutKey } from "@/lib/actions/keybinding"; +import type { + KeybindingConfig, + ShortcutKey, +} from "@/lib/actions/keybinding"; +import type { TActionWithOptionalArgs } from "./types"; export type TActionCategory = | "playback" @@ -10,18 +14,20 @@ export type TActionCategory = | "controls" | "assets"; -export interface TActionDefinition { +export interface TActionBaseDefinition { description: string; category: TActionCategory; - defaultShortcuts?: ShortcutKey[]; args?: Record; } +export interface TActionDefinition extends TActionBaseDefinition { + defaultShortcuts?: readonly ShortcutKey[]; +} + export const ACTIONS = { "toggle-play": { description: "Play/Pause", category: "playback", - defaultShortcuts: ["space", "k"], }, "stop-playback": { description: "Stop playback", @@ -30,81 +36,66 @@ export const ACTIONS = { "seek-forward": { description: "Seek forward 1 second", category: "playback", - defaultShortcuts: ["l"], args: { seconds: "number" }, }, "seek-backward": { description: "Seek backward 1 second", category: "playback", - defaultShortcuts: ["j"], args: { seconds: "number" }, }, "frame-step-forward": { description: "Frame step forward", category: "navigation", - defaultShortcuts: ["right"], }, "frame-step-backward": { description: "Frame step backward", category: "navigation", - defaultShortcuts: ["left"], }, "jump-forward": { description: "Jump forward 5 seconds", category: "navigation", - defaultShortcuts: ["shift+right"], args: { seconds: "number" }, }, "jump-backward": { description: "Jump backward 5 seconds", category: "navigation", - defaultShortcuts: ["shift+left"], args: { seconds: "number" }, }, "goto-start": { description: "Go to timeline start", category: "navigation", - defaultShortcuts: ["home", "enter"], }, "goto-end": { description: "Go to timeline end", category: "navigation", - defaultShortcuts: ["end"], }, split: { description: "Split elements at playhead", category: "editing", - defaultShortcuts: ["s"], }, "split-left": { description: "Split and remove left", category: "editing", - defaultShortcuts: ["q"], }, "split-right": { description: "Split and remove right", category: "editing", - defaultShortcuts: ["w"], }, "delete-selected": { description: "Delete selected elements", category: "editing", - defaultShortcuts: ["backspace", "delete"], }, "copy-selected": { description: "Copy selected elements", category: "editing", - defaultShortcuts: ["ctrl+c"], }, "paste-copied": { description: "Paste elements at playhead", category: "editing", - defaultShortcuts: ["ctrl+v"], }, "toggle-snapping": { description: "Toggle snapping", category: "editing", - defaultShortcuts: ["n"], }, "toggle-ripple-editing": { description: "Toggle ripple editing", @@ -113,12 +104,10 @@ export const ACTIONS = { "select-all": { description: "Select all elements", category: "selection", - defaultShortcuts: ["ctrl+a"], }, "cancel-interaction": { description: "Cancel current interaction", category: "controls", - defaultShortcuts: ["escape"], }, "deselect-all": { description: "Deselect all elements", @@ -127,7 +116,6 @@ export const ACTIONS = { "duplicate-selected": { description: "Duplicate selected element", category: "selection", - defaultShortcuts: ["ctrl+d"], }, "toggle-elements-muted-selected": { description: "Mute/unmute selected elements", @@ -144,12 +132,10 @@ export const ACTIONS = { undo: { description: "Undo", category: "history", - defaultShortcuts: ["ctrl+z"], }, redo: { description: "Redo", category: "history", - defaultShortcuts: ["ctrl+shift+z", "ctrl+y"], }, "remove-media-asset": { description: "Remove media asset", @@ -161,30 +147,59 @@ export const ACTIONS = { category: "assets", args: { projectId: "string", assetIds: "string[]" }, }, -} as const satisfies Record; +} as const satisfies Record; export type TAction = keyof typeof ACTIONS; +const ACTION_DEFAULT_SHORTCUTS = { + "toggle-play": ["space", "k"], + "seek-forward": ["l"], + "seek-backward": ["j"], + "frame-step-forward": ["right"], + "frame-step-backward": ["left"], + "jump-forward": ["shift+right"], + "jump-backward": ["shift+left"], + "goto-start": ["home", "enter"], + "goto-end": ["end"], + split: ["s"], + "split-left": ["q"], + "split-right": ["w"], + "delete-selected": ["backspace", "delete"], + "copy-selected": ["ctrl+c"], + "paste-copied": ["ctrl+v"], + "toggle-snapping": ["n"], + "select-all": ["ctrl+a"], + "cancel-interaction": ["escape"], + "duplicate-selected": ["ctrl+d"], + undo: ["ctrl+z"], + redo: ["ctrl+shift+z", "ctrl+y"], +} as const satisfies Partial>; + +const ACTION_DEFAULT_SHORTCUTS_BY_ACTION: Partial< + Record +> = ACTION_DEFAULT_SHORTCUTS; + export function getActionDefinition({ action, }: { action: TAction; }): TActionDefinition { - return ACTIONS[action]; + return { + ...ACTIONS[action], + defaultShortcuts: ACTION_DEFAULT_SHORTCUTS_BY_ACTION[action], + }; } -export function getDefaultShortcuts(): Record { - const shortcuts: Record = {}; +export function getDefaultShortcuts(): KeybindingConfig { + const shortcuts: KeybindingConfig = {}; - for (const [action, def] of Object.entries(ACTIONS) as Array< - [TAction, TActionDefinition] - >) { - if (def.defaultShortcuts) { - for (const shortcut of def.defaultShortcuts) { - shortcuts[shortcut] = action; - } + for (const [action, defaultShortcuts] of Object.entries( + ACTION_DEFAULT_SHORTCUTS, + ) as Array<[TActionWithOptionalArgs, readonly ShortcutKey[]]>) { + for (const shortcut of defaultShortcuts) { + shortcuts[shortcut] = action; } } - return shortcuts as Record; + return shortcuts; } -- cgit v1.3.1