diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-25 16:47:22 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-29 15:48:22 +0200 |
| commit | 8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch) | |
| tree | e9d0cafa93904ffcbec3188c37961bcc16c6422d /apps/web/src/stores/keybindings-store.ts | |
| parent | 39ea298a9ccba3104c549c0ca079c231981811f5 (diff) | |
| download | opencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz | |
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'apps/web/src/stores/keybindings-store.ts')
| -rw-r--r-- | apps/web/src/stores/keybindings-store.ts | 158 |
1 files changed, 140 insertions, 18 deletions
diff --git a/apps/web/src/stores/keybindings-store.ts b/apps/web/src/stores/keybindings-store.ts index 906e9aa8..b4cf2703 100644 --- a/apps/web/src/stores/keybindings-store.ts +++ b/apps/web/src/stores/keybindings-store.ts @@ -6,10 +6,10 @@ import type { TActionWithOptionalArgs } from "@/lib/actions"; import { getDefaultShortcuts } from "@/lib/actions"; import { isTypableDOMElement } from "@/utils/browser"; import { isAppleDevice } from "@/utils/platform"; -import type { KeybindingConfig, ShortcutKey } from "@/types/keybinding"; +import type { KeybindingConfig, ShortcutKey } from "@/lib/actions/keybinding"; import { runMigrations, CURRENT_VERSION } from "./keybindings/migrations"; -export const defaultKeybindings: KeybindingConfig = getDefaultShortcuts(); +const defaultKeybindings: KeybindingConfig = getDefaultShortcuts(); export interface KeybindingConflict { key: ShortcutKey; @@ -20,7 +20,9 @@ export interface KeybindingConflict { interface KeybindingsState { keybindings: KeybindingConfig; isCustomized: boolean; - keybindingsEnabled: boolean; + overlayDepth: number; + openOverlayIds: string[]; + isLoadingProject: boolean; isRecording: boolean; updateKeybinding: (key: ShortcutKey, action: TActionWithOptionalArgs) => void; @@ -28,8 +30,9 @@ interface KeybindingsState { resetToDefaults: () => void; importKeybindings: (config: KeybindingConfig) => void; exportKeybindings: () => KeybindingConfig; - enableKeybindings: () => void; - disableKeybindings: () => void; + openOverlay: (overlayId: string, source: string) => void; + closeOverlay: (overlayId: string, source: string) => void; + setLoadingProject: (loading: boolean) => void; setIsRecording: (isRecording: boolean) => void; validateKeybinding: ( key: ShortcutKey, @@ -48,9 +51,112 @@ export const useKeybindingsStore = create<KeybindingsState>()( (set, get) => ({ keybindings: { ...defaultKeybindings }, isCustomized: false, - keybindingsEnabled: true, + overlayDepth: 0, + openOverlayIds: [], + isLoadingProject: false, isRecording: false, + openOverlay: (overlayId, source) => + set((s) => { + const openOverlayIds = s.openOverlayIds.includes(overlayId) + ? s.openOverlayIds + : [...s.openOverlayIds, overlayId]; + const nextOverlayDepth = openOverlayIds.length; + // #region agent log + fetch( + "http://127.0.0.1:7245/ingest/669b22f8-172b-4e65-aa3f-1c702ede83f7", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Debug-Session-Id": "3997d9", + }, + body: JSON.stringify({ + sessionId: "3997d9", + runId: "initial", + hypothesisId: "H2", + location: "keybindings-store.ts:openOverlay", + message: "Overlay depth incremented", + data: { + source, + overlayId, + overlayDepth: s.overlayDepth, + nextOverlayDepth, + openOverlayIds, + }, + timestamp: Date.now(), + }), + }, + ).catch(() => {}); + // #endregion + return { + openOverlayIds, + overlayDepth: nextOverlayDepth, + }; + }), + closeOverlay: (overlayId, source) => + set((s) => { + const openOverlayIds = s.openOverlayIds.filter( + (id) => id !== overlayId, + ); + const nextOverlayDepth = openOverlayIds.length; + // #region agent log + fetch( + "http://127.0.0.1:7245/ingest/669b22f8-172b-4e65-aa3f-1c702ede83f7", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Debug-Session-Id": "3997d9", + }, + body: JSON.stringify({ + sessionId: "3997d9", + runId: "initial", + hypothesisId: "H2", + location: "keybindings-store.ts:closeOverlay", + message: "Overlay depth decremented", + data: { + source, + overlayId, + overlayDepth: s.overlayDepth, + nextOverlayDepth, + openOverlayIds, + }, + timestamp: Date.now(), + }), + }, + ).catch(() => {}); + // #endregion + return { + openOverlayIds, + overlayDepth: nextOverlayDepth, + }; + }), + setLoadingProject: (loading) => { + // #region agent log + fetch( + "http://127.0.0.1:7245/ingest/669b22f8-172b-4e65-aa3f-1c702ede83f7", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Debug-Session-Id": "3997d9", + }, + body: JSON.stringify({ + sessionId: "3997d9", + runId: "initial", + hypothesisId: "H2", + location: "keybindings-store.ts:setLoadingProject", + message: "Loading gate updated", + data: { loading }, + timestamp: Date.now(), + }), + }, + ).catch(() => {}); + // #endregion + set({ isLoadingProject: loading }); + }, + updateKeybinding: (key: ShortcutKey, action: TActionWithOptionalArgs) => { set((state) => { const newKeybindings = { ...state.keybindings }; @@ -82,17 +188,9 @@ export const useKeybindingsStore = create<KeybindingsState>()( }); }, - enableKeybindings: () => { - set({ keybindingsEnabled: true }); - }, - - disableKeybindings: () => { - set({ keybindingsEnabled: false }); - }, - - importKeybindings: (config: KeybindingConfig) => { - for (const [key] of Object.entries(config)) { - if (typeof key !== "string" || key.length === 0) { + importKeybindings: (config: KeybindingConfig) => { + for (const [key] of Object.entries(config)) { + if (typeof key !== "string" || key.length === 0) { throw new Error(`Invalid key format: ${key}`); } } @@ -124,6 +222,27 @@ export const useKeybindingsStore = create<KeybindingsState>()( return null; }, setIsRecording: (isRecording: boolean) => { + // #region agent log + fetch( + "http://127.0.0.1:7245/ingest/669b22f8-172b-4e65-aa3f-1c702ede83f7", + { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Debug-Session-Id": "3997d9", + }, + body: JSON.stringify({ + sessionId: "3997d9", + runId: "initial", + hypothesisId: "H2", + location: "keybindings-store.ts:setIsRecording", + message: "Recording gate updated", + data: { isRecording }, + timestamp: Date.now(), + }), + }, + ).catch(() => {}); + // #endregion set({ isRecording }); }, @@ -169,7 +288,10 @@ function generateKeybindingString(ev: KeyboardEvent): ShortcutKey | null { return `${modifierKey}+${key}` as ShortcutKey; } - if (isDOMElement(target) && isTypableDOMElement({ element: target as HTMLElement })) + if ( + isDOMElement(target) && + isTypableDOMElement({ element: target as HTMLElement }) + ) return null; return `${key}` as ShortcutKey; |
