Web
Overlays & Search
TypeScript
Browser E2E & Sandbox Verified
Accessible Command Palette
Keyboard-driven quick command launcher with live fuzzy filtering, arrow-key navigation, Enter selection, and TypeScript/JavaScript source.
Sandboxed Live Preview
Isolated iframe (CSP + no same-origin)Interactive live preview — type to filter commands, use Up/Down arrows and Enter.
Source Code (4 files)
<div class="pal-stage">
<div class="pal-card" role="search">
<input id="palInput" class="pal-input" type="search" placeholder="Type a command (e.g. pack, workflow, verify)..." aria-label="Filter commands" autocomplete="off">
<ul id="palList" class="pal-list" role="listbox" aria-label="Available commands"></ul>
<div id="palStatus" class="pal-status" aria-live="polite">Use ↑/↓ arrows and Enter to run a command.</div>
</div>
</div>
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, sans-serif; background: #0f172a; color: #0f1f36; }
.pal-stage {
min-height: 280px;
padding: 20px;
display: grid;
place-items: center;
}
.pal-card {
width: min(520px, 100%);
background: #ffffff;
border-radius: 14px;
box-shadow: 0 20px 50px rgba(2, 6, 23, 0.45);
overflow: hidden;
}
.pal-input {
width: 100%;
border: 0;
border-bottom: 1px solid #e2e8f0;
padding: 14px 16px;
font: 15px/1.4 Inter, system-ui, sans-serif;
outline: none;
}
.pal-list {
list-style: none;
margin: 0;
padding: 6px;
max-height: 168px;
overflow: auto;
}
.pal-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 9px 12px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
}
.pal-item[aria-selected="true"],
.pal-item:hover {
background: #eff6ff;
color: #1d4ed8;
}
.pal-item kbd {
font: 11px/1 ui-monospace, monospace;
background: #f1f5f9;
border: 1px solid #cbd5e1;
border-radius: 5px;
padding: 3px 6px;
color: #475569;
}
.pal-status {
padding: 10px 14px;
font-size: 12px;
color: #475569;
background: #f8fafc;
border-top: 1px solid #e2e8f0;
}
export interface PaletteCommand {
id: string;
label: string;
shortcut: string;
command: string;
}
export function filterCommands(commands: PaletteCommand[], query: string): PaletteCommand[] {
const q = query.trim().toLowerCase();
if (!q) return commands;
return commands.filter(
(item) =>
item.label.toLowerCase().includes(q) ||
item.command.toLowerCase().includes(q)
);
}
const commands = [
{ id: 'install', label: 'Install Official Pack', shortcut: 'I', command: 'otter pack install otter-official/math-utils' },
{ id: 'verify', label: 'Verify Pack Contracts', shortcut: 'V', command: 'otter pack verify --contracts' },
{ id: 'plan', label: 'Plan Multi-Pack Workflow', shortcut: 'P', command: 'otter compose plan --workflow app.workflow.json --explain' },
{ id: 'check', label: 'Static Check Project', shortcut: 'C', command: 'otter check src/main.ot' }
];
const input = document.getElementById('palInput');
const list = document.getElementById('palList');
const status = document.getElementById('palStatus');
let activeIndex = 0;
function filtered() {
const q = (input.value || '').trim().toLowerCase();
return q ? commands.filter((c) => c.label.toLowerCase().includes(q) || c.command.toLowerCase().includes(q)) : commands;
}
function render() {
const items = filtered();
activeIndex = Math.max(0, Math.min(activeIndex, items.length - 1));
list.innerHTML = items.map((item, idx) =>
`<li class="pal-item" role="option" data-idx="${idx}" aria-selected="${idx === activeIndex}"><span>${item.label}</span><kbd>${item.shortcut}</kbd></li>`
).join('') || '<li class="pal-item">No matching commands</li>';
}
function selectCurrent() {
const items = filtered();
const chosen = items[activeIndex];
if (chosen) status.textContent = `Selected: ${chosen.command}`;
}
input.addEventListener('input', () => { activeIndex = 0; render(); });
input.addEventListener('keydown', (e) => {
const count = filtered().length;
if (!count) return;
if (e.key === 'ArrowDown') { e.preventDefault(); activeIndex = (activeIndex + 1) % count; render(); }
else if (e.key === 'ArrowUp') { e.preventDefault(); activeIndex = (activeIndex - 1 + count) % count; render(); }
else if (e.key === 'Enter') { e.preventDefault(); selectCurrent(); }
});
list.addEventListener('click', (e) => {
const li = e.target.closest('.pal-item[data-idx]');
if (!li) return;
activeIndex = Number(li.dataset.idx);
render();
selectCurrent();
});
render();
Installation & Usage
Copy palette.html, palette.css, and palette.ts (or compiled palette.js) into your web app.
Mount the palette panel inside a <dialog> or overlay container and supply your application commands array.