A framework-agnostic command palette web component — commands with multi-step wizards, scoped and global search, favorites and recents, full keyboard control, RTL and a phone sheet.
@keenmate/web-commandpalette is a custom element (<web-command-palette>) that holds the whole
command-palette state machine — routing, wizards, search, keyboard, focus and scroll-lock — and
talks to its host only through properties, events and async callbacks. Hosts (plain JS, Svelte,
React, Blazor, Phoenix LiveView) stay thin adapters instead of re-implementing the palette.
Reads the shared --base-* variables from the page (pure-admin, or
@keenmate/theme-designer), with its own --cp-* knobs on
top; the CSS is the component's own (plain CSS in the shadow root).
Headline features:
/commands and:search contexts, plus global search that shows matching commands instantly.- Multi-step command wizards — fixed, loaded-once or live-searched steps, free text, branches.
- Async search with debounce and
AbortSignalcancellation; empty scoped queries never hit the server. - Favorites and recently used items (incl. completed runs, replayable with Tab / Enter),
stored in
localStorageor your backend. - A short feedback line of what ran, instead of the dialog just vanishing.
- Full keyboard control,
g <letter>hotkeys, RTL, i18nlabels, a fullscreen sheet on phones.
Upgrade guide: the 1.0.0-rc03 release notes; full list: the CHANGELOG 1.0.0-rc03 section.
-
Events and commands — the shared Keenmate interaction model — The palette now speaks the same event and item vocabulary as every Keenmate component (core
/actions), so hosts wire it like a toolbar or menu. Thecp-prefix is gone (open,close,result-select,ready), andcp-command/cp-completefold into oneactionevent per command run (detail.id,detail.selections); events bubble but are no longer composed, and eachon*twin receives the detail. Commands are core action items:name→text,shortcut→trigger,hotkey→shortcut, plusisVisible/isDisabled/isDanger/tooltip/onClickand theirget*Callbackforms.beforeActionCallbackandbeforeResultSelectCallbackcan cancel a run or a selection (async allowed), andel.controlleris the frozen public facade carried in every ctx and event detail. This is breaking with no aliases — the release notes have the full old → new tables. -
Callbacks take one
ctx, and names follow the v1 vocabulary —searchCallback({ scope, term, signal })gets core's sharedSearchCallbackContext,stepOptionsCallback(ctx, signal)isgetStepOptionsCallback(ctx),Step.load/Context.searcharegetOptionsCallback/searchCallback, andsaveUsageCallbackgets{ entry }. The post-run line is feedback:show-feedback,feedback-duration,renderFeedbackCallback(read by corerenderSlot). Limits aremax-favorite-count/max-recent-count, the storage key isstorage-key,mobile-presentationispresentation, andsetCommands()/setContexts()give way to thecommands/contextsproperties. Favorites / recents persist through corecreateStateStore()(newloadStateCallback/saveStateCallback), under a new localStorage key — stored entries are not carried over. -
Standard search — accents ignored,
search-behavior/search-match— Client-side filtering of the/and:lists, static steps and the favorites / recent lists is core's standard search, like web-multiselect:cesfindsČeskýandmullerfindsMüller(rc02 used a lower-cased substring match), and the<mark>highlight follows the same rules.search-behavior(normalized|case-insensitive|exact) andsearch-match(contains…regex) tune it with web-multiselect's names and defaults. Provider calls run through corecreateAsyncRunner— same debounce, abort-on-supersede and dropped late answers — and the loader now appears with the provider call rather than on the keystroke, so a synchronous provider never flashes one. -
Localization through core
/locale— flat keys, page-wide dictionary,translateCallback,locale— Every UI string resolves instancelabels→ the element'stranslateCallback→ the page-widewindow.components.locale(a flat dictionary ofweb-command-palette.<elementType>.<name>keys, or itstranslateCallbackfor i18next / ICU) → English. Label keys are flat<elementType>.<name>(placeholders.idle,messages.noResults,ariaLabels.dialog, …), one key per place a text is shown, so the visible heading and the screen-reader name can differ.labelsis also a JSON attribute, counts in labels are formatted for the resolved locale (the newlocaleattribute, else the page, else the browser), and changing the page locale re-renders an open palette in place. Labels drawn as content are HTML templates with escaped{…}values. -
A core modal — inert page, phone Back, modal stacking — The palette opens through core
startModalSession: the page behind isinert, focus is trapped and returned, and the phone Back gesture (or the browser Back button) steps back like Esc and then closes, where rc02 left the page with the palette open.--cp-z-indexis the modal tier (--base-z-modal, 7000), so page dropdowns, popovers, toasts and tooltips sit above it;--cp-z-index: 7601restores the old order. Announcements (result count, empty state, "Done") go to core's one page-wide live region, keyboard shortcuts bind through core (Ctrl+D/GDkeycaps, exact Ctrl/⌘, 1 s sequence window), and closing animates unlessmotion="none"or reduced motion. -
Icons through core
renderIcon, plusrenderIconCallback— Item icons follow core's one icon order: markup is inserted raw, a core built-in name (search,settings,delete, …) is masked from--base-icon-<name>, and any other name goes to the palette's ownrenderIconCallback(name, ctx), then the page-widewindow.components.renderIconCallback, then an icon-font<i class="cp__icon …">. Assigning the page-wide hook after the palette rendered repaints the icons in place, keeping the query and active row. The package'srenderIconexport is gone (import core's); the palette's own glyphs (star, token ✕, feedback ✓) keep their--cp-icon-*knobs. -
Own CSS on the
@keenmate/base-css-variables2.0 contract — The palette no longer compiles pure-admin-core's SCSS: its CSS is plain CSS, BEM on the blockcp(.pa-command-palette__*→.cp__*), reading the 2.0--base-*names (--base-primary-*,--base-on-<role>-text-color) with--cp-*knobs declared on the host — set them on the element, not an ancestor. Rows use the shared focused / hover states, standalone colors and dark mode follow the contract in every engine (core theme context instead of Chromium-only:host-context()), the phone bar is core's sheet chrome (--cp-sheet-*), andcustom-styles/getCustomStylesCallbackstyle the shadow root. The UMD bundle is about 10 kB smaller; the browser floor is Chrome / Edge 123+, Firefox 128+, Safari 17.5+. -
Public
CommandPaletteEnginefor your own UI — The DOM-free engine behind the element is public:new CommandPaletteEngine({ changed, effect }, options)with options named like the element's inputs (commands,pageSize,searchDebounce,labels,locale,favoriteKey, …),setOptions(partial)to change them (an unknown key warns and is skipped) andgetOptions()to read them back. It replaces rc02'sPaletteMachine, whose host had one function per setting. docs/usage.md "Build your own UI" shows what the engine does, what you draw and the option ↔ input table.
-
First release — one palette instead of three —
<web-command-palette>replaces the three command palettes that had drifted apart in pure-admin vanilla, svelte-pure-admin and the keen-pure-admin LiveComponent. Each one re-implemented routing, search and keyboard handling, and each had its own bugs. The element now owns that whole logic, and hosts talk to it only through properties,cp-*events and async callbacks. Hosts (plain JS, Svelte, React, Blazor, Phoenix LiveView) become thin adapters, with no copy of the palette logic in each.commandsplus asearchCallbackis a complete setup. Every callback argument and event detail is plain JSON, so it can travel over a LiveView bridge. -
Commands, contexts and global search — with the async rules built in —
/lists commands and:lists search contexts, and anything else is a global search. Global search shows matching commands and contexts right away, then appends the server results. Static lists filter on the client. Provider calls are debounced (search-debounce) and cancelled with anAbortSignalwhen a newer query replaces them, and late answers are dropped. A context search with an empty query never calls the server. Keyboard navigation never waits for a request, so arrows stay instant while results load. -
Multi-step wizards that can branch — A command can ask a series of steps, such as
/deploy→ environment → branch. Each step can use fixedoptions, a list loaded once, a livesearch: truelookup,freeText, or a conditionalshouldShow. An option can carry its ownsteps, so one command can fork:/assign-admin John to group Financeand… to site Intranetask different follow-up questions.Step.loadandContext.searchlet you define a picker once and reuse it across commands. The centralstepOptionsCallback/searchCallbackkeep working for server-driven hosts. -
Favorites and recents, replayable in two keystrokes — Star any row with Ctrl/⌘+D. The Recent list (ranked by frequency and recency) remembers instant commands, finished runs with their answers, contexts and chosen results. Replaying a run offers each remembered answer first: Enter accepts the rest and runs it, Tab steps through one answer at a time, and typing replaces an answer. The home screen shows only a few rows (
favorites-limit/recent-limit). Ctrl+F / R org fopens the full lists, and all of these keys are configurable. Usage is stored inlocalStorageperusage-key, or in your backend throughloadUsageCallback/saveUsageCallback. -
A confirmation instead of a vanishing dialog — When a command runs, the dialog used to disappear at once, which left users unsure anything had happened. It now shrinks, with an animation, to a one-line summary like ✓
/deploy to Staging branch mainDone forconfirmation-durationms (default 1500). Thecp-complete/cp-commandevent still fires immediately. Turn it off withconfirmation="false", or replace or skip it per run withrenderConfirmationCallback. -
Theming on the shared
--base-*variables, plus its own--cp-*knobs — The CSS is pure-admin-core's palette, compiled into the shadow root. It reads only the shared--base-*variables and the component's--cp-*knobs, and the build fails if a--pa-*/--pc-*read slips through. Font sizes follow--base-font-size-*and the font follows--base-font-family. Sizing scales with--base-remandsize="sm|lg|xl". Icons (check, close, star) and the results scrollbar can be themed through--cp-icon-*and--cp-scrollbar-*. Shadow parts exposepalette,container,input,resultsandfooter. The examples site has a theme gallery with seven styles and size switches. -
RTL, i18n and a phone sheet —
dir="rtl"on the element or any ancestor mirrors the layout, which uses logical CSS throughout. It also swaps ←/→ paging and isolates mixed-direction text, so/deploy …keeps its order inside Hebrew or Arabic UI. Every visible and announced string comes from thelabelsmap. On touch phones,mobile-presentation="auto"turns the dialog into a fullscreen sheet that stays above the on-screen keyboard.
Earlier releases: CHANGELOG.
- 🧪 Live examples — the hosted example site
(basic usage, commands & steps, async search, favorites, theming, playground). Locally:
make dev→ http://localhost:12400. - 📘 Usage / API reference — behaviour, properties, attributes, methods, events, data shapes.
- 🎨 Theming —
--cp-*and--base-*variables, font sizes, icons, size presets. - 📚 Examples / cookbook — the example pages and common recipes.
- ♿ Accessibility — keyboard model, ARIA, focus, RTL.
All guides are listed in docs/README.md.
npm install @keenmate/web-commandpaletteMinimal — commands, no server:
<web-command-palette></web-command-palette>
<script type="module">
import '@keenmate/web-commandpalette';
const palette = document.querySelector('web-command-palette');
palette.commands = [
{ id: 'reload', trigger: '/reload', text: 'Reload data', shortcut: 'g r' },
{ id: 'go', trigger: '/go', text: 'Go to page',
steps: [{ id: 'page', options: [{ text: 'Users', value: '/users' }, { text: 'Orders', value: '/orders' }] }] },
];
// One `action` event per command: at once without steps, after the last answer with them.
palette.addEventListener('action', (e) => {
if (e.detail.id === 'reload') reload();
if (e.detail.id === 'go') location.href = e.detail.selections[0].value;
});
</script>Ctrl/⌘+K opens it; type / for commands.
With search — contexts, a server callback and results:
palette.contexts = [{ id: 'products', trigger: ':products', aliases: [':p'], text: 'Products' }];
palette.searchCallback = async ({ scope, term, signal }) => {
// scope: 'global' | { contextId: 'products' } — called only for non-empty, debounced terms
const where = scope === 'global' ? 'global' : scope.contextId;
const res = await fetch(`/api/search?scope=${where}&q=${encodeURIComponent(term)}`, { signal });
return res.json(); // [{ id, title, subtitle?, icon?, href?, group? }]
};
palette.addEventListener('result-select', (e) => (location.href = e.detail.result.href));The palette closes itself after result-select / action; the host performs the effect. Every callback
takes one ctx, and every ctx and event detail carries controller (el.controller, the public
facade) and element. See docs/usage.md for the full API and
docs/examples.md for recipes (step pickers, branching wizards, favorites on
the server, custom feedback line).
Tune the palette per device class or window width without app-side viewport code — a map of partial configs, or a callback that computes one. Keys are configKeys; set them page-wide, per tag or per instance (the generic core mechanism, core SPEC §6.7):
// page-wide (every Keenmate component) and per tag — may be set before the script loads
window.components.responsive = { device: { mobile: { presentation: 'fullscreen' } } };
window.components['web-command-palette'].responsiveCallback = (ctx) =>
ctx.deviceClass === 'desktop' ? undefined : { display: 'tokens', pageSize: 5 };
// per instance (property, or the JSON attribute responsive='{"breakpoint":{"mobile":{…}}}')
palette.responsive = { device: { tablet: { size: 'lg' } }, breakpoint: { mobile: { pageSize: 5 } } };
palette.responsiveCallback = (ctx) => (ctx.env.orientation === 'landscape' ? { pageSize: 4 } : undefined);A map has two axes: device — the device class by capability (mobile / tablet = a
touch phone / tablet, a mouse device is desktop at any width); breakpoint — the window
width bucket (mobile < 768px ≤ tablet < 1024px ≤ desktop, so a narrowed desktop window is
mobile). Both may be set; device wins on the same key. Own widths or combinations (device
class AND width, orientation, …) go in a responsiveCallback.
Precedence (later wins, key by key): global map → global callback → per-tag map → per-tag
callback → the instance's own attributes / properties → instance map → instance callback.
An attribute written on an element is never overridden by a page rule; null from the instance
callback ignores every page rule. Rules re-run when the device class / breakpoint / orientation
changes and never reflect to attributes. Typed as CommandPaletteResponsiveMap /
CommandPaletteResponsiveCallback.
The package ships editor metadata — autocomplete and hover docs for the element's attributes,
events and --cp-* CSS variables — generated from the component's source on every build.
-
JetBrains (WebStorm / IntelliJ) — works automatically via the
web-typesfield inpackage.json. -
VS Code — point your workspace at the data files once in
.vscode/settings.json:{ "html.customData": ["./node_modules/@keenmate/web-commandpalette/vscode.html-custom-data.json"], "css.customData": ["./node_modules/@keenmate/web-commandpalette/vscode.css-custom-data.json"] }Reload the window after adding them.
Modern evergreen browsers with native customElements, Shadow DOM, CSS color-mix(),
light-dark() and dynamic viewport units (the @keenmate/base-css-variables themes also use
relative color syntax):
- Chrome / Edge 123+
- Firefox 128+
- Safari 17.5+
Dark mode follows the page signal (.dark, [data-theme], [data-bs-theme] on <html> / <body>,
or a theme-source element), detected by @keenmate/web-components-core and mirrored onto the host
as data-context-theme, so it works in every engine. To follow the OS, declare
html { color-scheme: light dark } on the page.
No polyfills are shipped.
make setup # npm install
make dev # examples hub on http://localhost:12400
make build # cem analyze → library build (dist/) → check:vars
make test # unit (Vitest) + e2e (Playwright: desktop + Pixel 7)
make # list every target (publish-rc, image-build, kill-port, …)Details — single tests, the CSS pipeline, publishing, the example-site image — are in BUILD.md.
| Layer | File | Role |
|---|---|---|
| Element | src/web-component.ts |
CommandPaletteElement — the static inputs / static events tables (IDE metadata is generated from them), overlay, presentation, feedback line |
| Logic | src/palette.ts |
CommandPaletteEngine — DOM-free modes, wizard, filtering, async search, pagination; public for your own UI (docs/usage.md → Build your own UI) |
| Logic | src/usage.ts |
UsageStore — favorites + recents, frecency, pluggable persistence |
| Render | src/render.ts |
builds the shadow DOM once and patches it |
| Service | src/keyboard.ts |
global hotkeys + input key map |
| Side | src/types.ts, src/logger.ts, src/helpers/, src/css/ |
public types, logging, pure helpers (filter.ts filtering), shadow-root CSS |
The palette CSS is plain CSS in src/css/ (main.css imports the layers: variables → component →
overrides), inlined into the shadow root. It reads only --cp-* and --base-*.
Authored and maintained by Keenmate s.r.o..
The component ships standalone with sensible light/dark defaults;
when mounted inside Pure Admin — or any
host that publishes the --base-* taxonomy via
@keenmate/theme-designer — it adopts the host's colors,
typography, and sizing automatically. There is no runtime
dependency on Pure Admin; the integration is opt-in via CSS
variables.
Built on @keenmate/web-components-core (BlissElement) following the
BlissFramework component guidelines for structure, theming and
accessibility.
MIT © Keenmate s.r.o. — see LICENSE.