summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/actions/definitions.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-26 13:52:30 +0100
committerMaze Winther <mazewinther@gmail.com>2026-03-29 15:49:30 +0200
commit722dcdd88face3724c77d23bc36a00524e552551 (patch)
tree9dbf561de29592d5a346b8c7bfd27b5d31345bc8 /apps/web/src/lib/actions/definitions.ts
parent8db3bead13441a5882d8689dfc6a9f09c82375d9 (diff)
downloadopencut-722dcdd88face3724c77d23bc36a00524e552551.tar.gz
fix: resolve typescript/lint errors
Diffstat (limited to 'apps/web/src/lib/actions/definitions.ts')
-rw-r--r--apps/web/src/lib/actions/definitions.ts87
1 files changed, 51 insertions, 36 deletions
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<string, unknown>;
}
+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<string, TActionDefinition>;
+} as const satisfies Record<string, TActionBaseDefinition>;
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<Record<TActionWithOptionalArgs, readonly ShortcutKey[]>>;
+
+const ACTION_DEFAULT_SHORTCUTS_BY_ACTION: Partial<
+ Record<TAction, readonly ShortcutKey[]>
+> = 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<ShortcutKey, TAction> {
- const shortcuts: Record<string, TAction> = {};
+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<ShortcutKey, TAction>;
+ return shortcuts;
}