Skip to content

feat: commands system, commands palette, shortcuts and when clauses#247

Merged
antfu merged 14 commits intomainfrom
antfu/commands-api
Mar 24, 2026
Merged

feat: commands system, commands palette, shortcuts and when clauses#247
antfu merged 14 commits intomainfrom
antfu/commands-api

Conversation

@antfu
Copy link
Member

@antfu antfu commented Mar 23, 2026

resolves #243

antfu and others added 2 commits March 23, 2026 20:13
Extract keybinding logic (formatKeybinding, normalizeKeyEvent, evaluateWhen,
collectAllKeybindings) into standalone keybindings.ts module with tests.
Decompose CommandPalette.vue into CommandPaletteItem and KeybindingBadge
sub-components. Split ViewBuiltinSettings.vue (800 lines) into
SettingsAppearance, SettingsShortcuts, and SettingsDocks components.
Convert KNOWN_BROWSER_SHORTCUTS from Set to Record with descriptions for
better conflict messages. Remove default Escape keybinding from close-panel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antfu antfu changed the title feat: commands system refactor: decompose commands UI and extract keybinding utilities Mar 23, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@247

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@247

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@247

@vitejs/devtools-rpc

npm i https://pkg.pr.new/@vitejs/devtools-rpc@247

@vitejs/devtools-self-inspect

npm i https://pkg.pr.new/@vitejs/devtools-self-inspect@247

commit: 8424219

@arashsheyda
Copy link
Contributor

wow this is so cool! do you plan default shortcuts for some of the commands?

antfu and others added 7 commits March 24, 2026 10:39
Add `when?: string` to DevToolsCommandBase so commands can be conditionally
visible in the palette and conditionally executable based on context. The
`when` evaluator now supports: clientType, dockOpen, paletteOpen,
dockSelectedId, plus custom plugin variables via index signature.

Group dock navigation commands under a "devtools:docks" parent command
instead of registering each as a top-level command. The parent re-registers
reactively when dock entries change.

Wire up real WhenContext values (dockOpen from panelStore, dockSelectedId
from selectedId) instead of hardcoded defaults.

Add `when: 'dockOpen'` to close-panel and `when: 'clientType == embedded'`
to dock-mode commands. Comprehensive evaluateWhen tests (237 total).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ocks

Move evaluateWhen/WhenContext/getContextValue to packages/kit/src/utils/when.ts
as a dedicated module exported from @vitejs/devtools-kit. Core keybindings.ts
now re-exports from kit.

Replace isHidden?: boolean on DevToolsDockEntryBase with when?: string, using
the same expression syntax as command when clauses. The ~terminals dock now
uses `get when() { return sessions.size === 0 ? 'false' : undefined }`.

evaluateWhen now supports 'true' and 'false' as literal values, enabling
unconditional hide/show without a context variable.

DockEntries.vue evaluates dock when clauses client-side with a reactive
WhenContext. docksGroupByCategories accepts optional whenContext for filtering.

Comprehensive when.test.ts in kit (32 test files, 245 tests total).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add docs/kit/when-clauses.md as a dedicated page covering expression
syntax, operators, built-in context variables, namespaced keys, and
API reference. Added to VitePress sidebar and nav. Commands page now
links to it instead of inlining the full reference.

Support namespaced context keys with . or : separators in when
expressions. getContextValue resolves via exact match first, then
falls back to nested object path traversal. This allows plugins to
use keys like vite.mode or rolldown:buildStep without collisions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve conflicts in ViewBuiltinSettings.vue (keep decomposed
sub-component approach) and .generated/css.ts (auto-merged).
Incorporate HashBadge for action entries from main into SettingsDocks.vue.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move "Reset All Settings" out of Appearance tab into a new Advanced tab.
Add granular reset buttons: Reset Shortcuts (clears shortcut overrides),
Reset Docks (restores default visibility, order, pinning), and Reset All
(resets everything including appearance, docks, and shortcuts).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antfu antfu changed the title refactor: decompose commands UI and extract keybinding utilities feat: commands system, commands palette, shortcuts and when clauses Mar 24, 2026
antfu and others added 5 commits March 24, 2026 11:28
Allow showInPalette to accept 'without-children' alongside boolean.
When set, the command appears in the palette but its children are not
flattened into top-level search results — they remain accessible only
via drill-down when the parent is selected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add WhenClauseContext interface with a reactive context getter to
DocksContext. Accessible as ctx.when.context, returning the current
WhenContext snapshot with all built-in and custom variables.

DockEntries.vue now uses ctx.when.context instead of constructing
its own WhenContext.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update commands.md and when-clauses.md to reflect that when clauses
are only supported on commands and dock entries, not on keybindings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
@antfu antfu marked this pull request as ready for review March 24, 2026 02:52
@antfu
Copy link
Member Author

antfu commented Mar 24, 2026

I think I would avoid adding too many default shortcuts, as it would have more potential of shortcut collision with the user's app, and would introduce uncessary breaking changes when we change the defaults.

@antfu antfu merged commit 210d826 into main Mar 24, 2026
9 checks passed
@antfu antfu deleted the antfu/commands-api branch March 24, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Command Palette support to Vite DevTools

2 participants