Skip to content

Commit 8424219

Browse files
antfuclaude
andcommitted
refactor: remove when from keybindings, fix import paths
Remove the when field from DevToolsCommandKeybinding type and the keybinding-level when check from the shortcut listener. When clauses are now only on commands and dock entries. Fix import paths to use @vitejs/devtools-kit/utils/when subpath export. Add utils/when to kit package.json exports map. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1e8b6fb commit 8424219

4 files changed

Lines changed: 8 additions & 15 deletions

File tree

packages/core/src/client/webcomponents/state/commands.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { DevToolsClientCommand, DevToolsCommandEntry, DevToolsCommandKeybinding, DevToolsServerCommandEntry } from '@vitejs/devtools-kit'
1+
import type { DevToolsClientCommand, DevToolsCommandEntry, DevToolsCommandKeybinding, DevToolsServerCommandEntry, WhenContext } from '@vitejs/devtools-kit'
22
import type { CommandsContext, DevToolsRpcClient } from '@vitejs/devtools-kit/client'
33
import type { ShallowRef } from 'vue'
4-
import type { WhenContext } from './keybindings'
4+
import { evaluateWhen } from '@vitejs/devtools-kit/utils/when'
55
import { computed, markRaw, reactive, ref } from 'vue'
66
import { sharedStateToRef } from './docks'
7-
import { collectAllKeybindings, evaluateWhen, normalizeKeyEvent } from './keybindings'
7+
import { collectAllKeybindings, normalizeKeyEvent } from './keybindings'
88

99
export { formatKeybinding, isMac, normalizeKeyEvent } from './keybindings'
1010

@@ -162,12 +162,10 @@ function setupShortcutListener(
162162
for (const { id, keybinding } of allBindings) {
163163
if (keybinding.key !== pressed)
164164
continue
165-
// Check keybinding-level when clause
166-
if (keybinding.when && !evaluateWhen(keybinding.when, whenCtx))
167-
continue
168165
// Check command-level when clause
169-
const cmd = commands.value.find(c => c.id === id)
170-
?? commands.value.flatMap(c => c.children ?? []).find(c => c.id === id)
166+
const cmd: DevToolsCommandEntry | undefined
167+
= commands.value.find(c => c.id === id)
168+
?? commands.value.flatMap(c => c.children as DevToolsCommandEntry[] ?? []).find(c => c.id === id)
171169
if (cmd?.when && !evaluateWhen(cmd.when, whenCtx))
172170
continue
173171

packages/core/src/client/webcomponents/state/keybindings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DevToolsCommandEntry, DevToolsCommandKeybinding } from '@vitejs/de
22

33
// Re-export when utilities from kit
44
export type { WhenContext } from '@vitejs/devtools-kit'
5-
export { evaluateWhen, getContextValue } from '@vitejs/devtools-kit'
5+
export { evaluateWhen, getContextValue } from '@vitejs/devtools-kit/utils/when'
66

77
export const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform ?? '')
88

packages/kit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"./utils/human-id": "./dist/utils/human-id.js",
2727
"./utils/nanoid": "./dist/utils/nanoid.js",
2828
"./utils/shared-state": "./dist/utils/shared-state.js",
29+
"./utils/when": "./dist/utils/when.js",
2930
"./package.json": "./package.json"
3031
},
3132
"types": "./dist/index.d.mts",

packages/kit/src/types/commands.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ export interface DevToolsCommandKeybinding {
99
* Examples: "Mod+K", "Mod+Shift+P", "Alt+N"
1010
*/
1111
key: string
12-
/**
13-
* Optional context expression for conditional activation.
14-
* Examples: "clientType == embedded", "dockOpen", "!dockOpen"
15-
* Supports: ==, !=, &&, ||, bare truthy, ! negation
16-
*/
17-
when?: string
1812
}
1913

2014
// --- Command Entry ---

0 commit comments

Comments
 (0)