utopia-ia/elffuss-claw public
Changesets · Branches · Tags · Compare
| Changeset | bbb632dbf8f468bb3e99d0f173d9cb1febd63330d78488352668e8a5b6e3c2a7 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-11 20:47 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 20:47 +02:00 |
| Parents | 3a574525cee8 |
2 files changed
modified tests/ux-teclado.mjs +49 −0
| @@ -3,6 +3,12 @@ | ||
| 3 | 3 | // entra, ↑/↓ se mueven, Escape cierra y devuelve el foco. |
| 4 | 4 | // · Escribiendo «/sk» filtra, Enter ejecuta el marcado y la caja queda limpia y |
| 5 | 5 | // con el foco; un «/» suelto no se manda nunca; /modelo lleva al selector. |
| 6 | +// · Escribiendo, la caja es un combobox (aria-controls, aria-expanded) y el | |
| 7 | +// menú una lista con su opción marcada (aria-selected), que la caja señala | |
| 8 | +// con aria-activedescendant; con el botón, el menú es un role=menu. | |
| 9 | +// · En inglés los comandos se llaman en inglés (/settings, /tasks, /clear…) y | |
| 10 | +// los nombres en español siguen valiendo; si ningún nombre empieza así, se | |
| 11 | +// busca en lo que hace cada uno. | |
| 6 | 12 | // · «?» fuera de la caja enseña los atajos; «/» fuera de la caja abre el menú. |
| 7 | 13 | // · Chips: botones, seis, sin repetidos, en el idioma de la página; «Autoriza |
| 8 | 14 | // una carpeta» abre el selector en el propio clic. |
| @@ -36,9 +42,32 @@ | ||
| 36 | 42 | ok('↓ pasa a la siguiente opción', await p.evaluate(() => document.activeElement?.textContent.startsWith('/carpeta'))); |
| 37 | 43 | await p.keyboard.press('Escape'); |
| 38 | 44 | ok('Escape cierra el menú y devuelve el foco al botón', !(await menuAbierto()) && await foco() === 'btn-slash'); |
| 45 | +ok('…abierto con el botón, la caja de texto no se da por desplegada', await p.getAttribute('#prompt', 'aria-expanded') === 'false'); | |
| 39 | 46 | |
| 40 | 47 | // ── escribiendo «/» ───────────────────────────────────────────────────────── |
| 41 | 48 | await p.focus('#prompt'); |
| 49 | +const aria = () => p.evaluate(() => { | |
| 50 | + const c = document.getElementById('prompt'), m = document.getElementById('cmd-menu'); | |
| 51 | + const ad = c.getAttribute('aria-activedescendant'); | |
| 52 | + const sel = ad ? document.getElementById(ad) : null; | |
| 53 | + return { role: c.getAttribute('role'), expanded: c.getAttribute('aria-expanded'), controls: c.getAttribute('aria-controls'), | |
| 54 | + autocomplete: c.getAttribute('aria-autocomplete'), menu: m.getAttribute('role'), ad, | |
| 55 | + dentro: !!sel && m.contains(sel), opcion: sel?.getAttribute('role'), elegida: sel?.getAttribute('aria-selected'), | |
| 56 | + otras: [...m.querySelectorAll('[role=option]')].filter(o => o !== sel && o.getAttribute('aria-selected') !== 'false').length, | |
| 57 | + texto: sel?.querySelector('b')?.textContent }; | |
| 58 | +}); | |
| 59 | +ok('en reposo la caja es un combobox plegado que controla el menú', await aria().then(a => a.role === 'combobox' && a.expanded === 'false' | |
| 60 | + && a.controls === 'cmd-menu' && a.autocomplete === 'list' && !a.ad)); | |
| 61 | +await p.keyboard.type('/'); | |
| 62 | +const a1 = await aria(); | |
| 63 | +ok('escribiendo «/»: la caja se despliega y señala una opción de la lista (listbox/option, aria-selected)', a1.expanded === 'true' | |
| 64 | + && a1.menu === 'listbox' && a1.dentro && a1.opcion === 'option' && a1.elegida === 'true' && a1.otras === 0 && a1.texto === '/reloj', JSON.stringify(a1)); | |
| 65 | +await p.keyboard.press('ArrowDown'); | |
| 66 | +const a2 = await aria(); | |
| 67 | +ok('…↓ mueve la opción señalada y su aria-selected', a2.texto === '/carpeta' && a2.elegida === 'true' && a2.otras === 0 && a2.ad !== a1.ad, JSON.stringify(a2)); | |
| 68 | +await p.keyboard.press('Escape'); | |
| 69 | +ok('…y Escape la pliega (sin opción señalada)', await aria().then(a => a.expanded === 'false' && !a.ad), JSON.stringify(await aria())); | |
| 70 | +await p.fill('#prompt', ''); | |
| 42 | 71 | await p.keyboard.type('/sk'); |
| 43 | 72 | ok('«/sk» filtra: solo /skills', await hasta(async () => (await p.locator('#cmd-menu .cmd-item b').allTextContents()).join(',') === '/skills')); |
| 44 | 73 | await p.keyboard.press('Enter'); |
| @@ -84,6 +113,26 @@ | ||
| 84 | 113 | const es = ['Hazme un reloj', 'Crea una app de notas', 'Autoriza una carpeta', 'Créame una skill para organizar mis descargas', 'Busca fotos de auroras boreales', 'Abre https://example.com']; |
| 85 | 114 | ok('en inglés: seis chips en inglés', en.length === 6 && !en.some(t => es.includes(t)) && en[0] === 'Make me a clock', JSON.stringify(en)); |
| 86 | 115 | ok('en inglés el botón «/» se llama «Commands and skills»', await e.getAttribute('#btn-slash', 'aria-label') === 'Commands and skills'); |
| 116 | + const busca = async q => { | |
| 117 | + await e.fill('#prompt', ''); | |
| 118 | + await e.focus('#prompt'); | |
| 119 | + await e.keyboard.type(q); | |
| 120 | + await espera(100); | |
| 121 | + const r = await e.$$eval('#cmd-menu .cmd-item b', bs => bs.map(x => x.textContent)); | |
| 122 | + await e.keyboard.press('Escape'); | |
| 123 | + return r; | |
| 124 | + }; | |
| 125 | + const r = { settings: await busca('/settings'), tasks: await busca('/tasks'), clear: await busca('/clear'), ajustes: await busca('/ajustes'), | |
| 126 | + todos: await busca('/'), teclado: await busca('/keyb') }; | |
| 127 | + ok('en inglés los comandos se llaman en inglés y /settings, /tasks y /clear los encuentran', r.settings.join() === '/settings' | |
| 128 | + && r.tasks.join() === '/tasks' && r.clear.join() === '/clear' && r.todos.includes('/clock') && !r.todos.includes('/reloj'), JSON.stringify(r)); | |
| 129 | + ok('…el nombre en español sigue valiendo (/ajustes → /settings)', r.ajustes.join() === '/settings', JSON.stringify(r.ajustes)); | |
| 130 | + ok('…y si ningún nombre empieza así, busca en lo que hace cada uno (/keyb → /shortcuts)', r.teclado.join() === '/shortcuts', JSON.stringify(r.teclado)); | |
| 131 | + await e.fill('#prompt', ''); | |
| 132 | + await e.focus('#prompt'); | |
| 133 | + await e.keyboard.type('/settings'); | |
| 134 | + await e.keyboard.press('Enter'); | |
| 135 | + ok('…y Enter en /settings abre Settings', await hasta(() => e.evaluate(() => document.getElementById('panel-ajustes').classList.contains('active')))); | |
| 87 | 136 | await c2.close(); |
| 88 | 137 | } |
| 89 | 138 |
modified web/js/ui.js +45 −19
| @@ -1757,49 +1757,71 @@ | ||
| 1757 | 1757 | // Enter ejecuta el marcado; un «/» suelto nunca se manda al modelo. Después |
| 1758 | 1758 | // de ejecutar, la caja queda limpia y con el foco. |
| 1759 | 1759 | const verPanel = tab => { selectTab(tab, { push: true }); if (isMobile()) flipTo('viz'); }; |
| 1760 | + // Cada comando tiene su nombre en español y en inglés. Se ENSEÑA el de la | |
| 1761 | + // página (español en español, inglés en los demás) y, escribiendo, valen los | |
| 1762 | + // dos: en inglés, /settings, /tasks o /clear no encontraban nada. Si ningún | |
| 1763 | + // nombre empieza así, se busca en lo que hace cada uno (su pista). | |
| 1760 | 1764 | const cmds = [ |
| 1761 | - { label: '/reloj', hint: tr('cmClock'), run: () => onSend(tr('pClock')) }, | |
| 1762 | - { label: '/carpeta', hint: tr('cmFolder'), run: () => onPickFolder() }, // el selector nativo se abre en el gesto | |
| 1763 | - { label: '/skills', hint: tr('cmSkills'), run: () => verPanel('skills') }, | |
| 1764 | - { label: '/modelo', hint: tr('cmModel'), run: () => enfocarSelectorModelo(), foco: false }, | |
| 1765 | - { label: '/ajustes', hint: tr('cmSettings'), run: () => verPanel('ajustes') }, | |
| 1766 | - { label: '/tareas', hint: tr('cmTasks'), run: () => verPanel('tareas') }, | |
| 1767 | - { label: '/vault', hint: tr('cmVault'), run: () => verPanel('vault') }, | |
| 1768 | - { label: '/limpiar', hint: tr('cmClear'), run: () => $('btn-clear').click() }, | |
| 1769 | - { label: '/atajos', hint: tr('cmKeys'), run: () => mostrarAtajos(), foco: false }, | |
| 1765 | + { label: '/reloj', en: '/clock', hint: tr('cmClock'), run: () => onSend(tr('pClock')) }, | |
| 1766 | + { label: '/carpeta', en: '/folder', hint: tr('cmFolder'), run: () => onPickFolder() }, // el selector nativo se abre en el gesto | |
| 1767 | + { label: '/skills', en: '/skills', hint: tr('cmSkills'), run: () => verPanel('skills') }, | |
| 1768 | + { label: '/modelo', en: '/model', hint: tr('cmModel'), run: () => enfocarSelectorModelo(), foco: false }, | |
| 1769 | + { label: '/ajustes', en: '/settings', hint: tr('cmSettings'), run: () => verPanel('ajustes') }, | |
| 1770 | + { label: '/tareas', en: '/tasks', hint: tr('cmTasks'), run: () => verPanel('tareas') }, | |
| 1771 | + { label: '/vault', en: '/vault', hint: tr('cmVault'), run: () => verPanel('vault') }, | |
| 1772 | + { label: '/limpiar', en: '/clear', hint: tr('cmClear'), run: () => $('btn-clear').click() }, | |
| 1773 | + { label: '/atajos', en: '/shortcuts', hint: tr('cmKeys'), run: () => mostrarAtajos(), foco: false }, | |
| 1770 | 1774 | ]; |
| 1775 | + const nombreCmd = c => (uiLang() === 'es' ? c.label : c.en); | |
| 1771 | 1776 | const cmdMenu = $('cmd-menu'); |
| 1772 | 1777 | const slash = $('btn-slash'); |
| 1773 | 1778 | const caja = $('prompt'); |
| 1774 | - cmdMenu.setAttribute('role', 'menu'); | |
| 1775 | 1779 | cmdMenu.setAttribute('aria-label', tr('cmdMenuL')); |
| 1776 | 1780 | slash.setAttribute('aria-haspopup', 'menu'); |
| 1777 | 1781 | slash.setAttribute('aria-controls', 'cmd-menu'); |
| 1778 | 1782 | slash.setAttribute('aria-expanded', 'false'); |
| 1779 | 1783 | slash.title = tr('cmdMenuL'); |
| 1780 | 1784 | slash.setAttribute('aria-label', tr('cmdMenuL')); |
| 1785 | + // Dos formas, dos patrones de ARIA. Escribiendo «/» el foco se queda en la caja: | |
| 1786 | + // la caja es un combobox (aria-controls, aria-expanded) y el menú una lista | |
| 1787 | + // (listbox) con su opción marcada (aria-selected), que la caja señala con | |
| 1788 | + // aria-activedescendant. Antes la caja señalaba elementos de un role=menu que | |
| 1789 | + // no era suyo, y los lectores de pantalla lo anunciaban mal o nada. Con el botón | |
| 1790 | + // «/» el foco entra en el menú: ese sí es un role=menu con menuitems. | |
| 1791 | + caja.setAttribute('role', 'combobox'); | |
| 1792 | + caja.setAttribute('aria-autocomplete', 'list'); | |
| 1793 | + caja.setAttribute('aria-controls', 'cmd-menu'); | |
| 1794 | + caja.setAttribute('aria-expanded', 'false'); | |
| 1781 | 1795 | const sinTilde = x => x.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase(); |
| 1782 | - let visibles = [], activo = -1; | |
| 1796 | + let visibles = [], activo = -1, comoLista = false; | |
| 1783 | 1797 | const filas = () => [...cmdMenu.querySelectorAll('.cmd-item')]; |
| 1784 | 1798 | const marcar = i => { |
| 1785 | 1799 | const fs = filas(); |
| 1786 | 1800 | activo = fs.length ? (i + fs.length) % fs.length : -1; |
| 1787 | - fs.forEach((f, j) => f.classList.toggle('activo', j === activo)); | |
| 1788 | - if (activo >= 0) { caja.setAttribute('aria-activedescendant', fs[activo].id); fs[activo].scrollIntoView({ block: 'nearest' }); } | |
| 1801 | + fs.forEach((f, j) => { | |
| 1802 | + f.classList.toggle('activo', j === activo); | |
| 1803 | + if (comoLista) f.setAttribute('aria-selected', j === activo ? 'true' : 'false'); | |
| 1804 | + }); | |
| 1805 | + if (activo >= 0 && comoLista) caja.setAttribute('aria-activedescendant', fs[activo].id); | |
| 1789 | 1806 | else caja.removeAttribute('aria-activedescendant'); |
| 1807 | + if (activo >= 0) fs[activo].scrollIntoView({ block: 'nearest' }); | |
| 1790 | 1808 | }; |
| 1791 | 1809 | const pintarMenu = (filtro = '/') => { |
| 1792 | 1810 | const f = sinTilde(filtro); |
| 1793 | - visibles = cmds.filter(c => sinTilde(c.label).startsWith(f)); | |
| 1811 | + const porNombre = cmds.filter(c => [c.label, c.en].some(n => sinTilde(n).startsWith(f))); | |
| 1812 | + const palabra = f.replace(/^\//, ''); | |
| 1813 | + visibles = porNombre.length || palabra.length < 3 ? porNombre | |
| 1814 | + : cmds.filter(c => sinTilde(c.hint).split(/[^\p{L}\p{N}]+/u).some(w => w.startsWith(palabra))); | |
| 1815 | + cmdMenu.setAttribute('role', comoLista ? 'listbox' : 'menu'); | |
| 1794 | 1816 | cmdMenu.replaceChildren(); |
| 1795 | 1817 | visibles.forEach((c, i) => { |
| 1796 | 1818 | const row = document.createElement('button'); |
| 1797 | 1819 | row.type = 'button'; |
| 1798 | 1820 | row.className = 'cmd-item'; |
| 1799 | 1821 | row.id = 'cmd-' + i; |
| 1800 | - row.setAttribute('role', 'menuitem'); | |
| 1822 | + row.setAttribute('role', comoLista ? 'option' : 'menuitem'); | |
| 1801 | 1823 | row.tabIndex = -1; |
| 1802 | - const b = document.createElement('b'); b.textContent = c.label; | |
| 1824 | + const b = document.createElement('b'); b.textContent = nombreCmd(c); | |
| 1803 | 1825 | const h = document.createElement('span'); h.textContent = c.hint; |
| 1804 | 1826 | row.append(b, h); |
| 1805 | 1827 | row.onclick = () => ejecutar(c); |
| @@ -1808,15 +1830,19 @@ | ||
| 1808 | 1830 | if (!visibles.length) cmdMenu.appendChild(el('div', 'cmd-vacio', tr('cmNone'))); |
| 1809 | 1831 | marcar(0); |
| 1810 | 1832 | }; |
| 1811 | - const abrirMenu = (filtro = '/') => { | |
| 1833 | + // `lista`: abierto escribiendo (el foco sigue en la caja); si no, con el botón. | |
| 1834 | + const abrirMenu = (filtro = '/', { lista = true } = {}) => { | |
| 1835 | + comoLista = lista; | |
| 1812 | 1836 | pintarMenu(filtro); |
| 1813 | 1837 | cmdMenu.hidden = false; |
| 1814 | - slash.setAttribute('aria-expanded', 'true'); | |
| 1838 | + slash.setAttribute('aria-expanded', lista ? 'false' : 'true'); | |
| 1839 | + caja.setAttribute('aria-expanded', lista ? 'true' : 'false'); | |
| 1815 | 1840 | }; |
| 1816 | 1841 | const cerrarMenu = ({ foco = null } = {}) => { |
| 1817 | 1842 | if (cmdMenu.hidden) return; |
| 1818 | 1843 | cmdMenu.hidden = true; |
| 1819 | 1844 | slash.setAttribute('aria-expanded', 'false'); |
| 1845 | + caja.setAttribute('aria-expanded', 'false'); | |
| 1820 | 1846 | caja.removeAttribute('aria-activedescendant'); |
| 1821 | 1847 | activo = -1; |
| 1822 | 1848 | foco?.focus(); |
| @@ -1829,7 +1855,7 @@ | ||
| 1829 | 1855 | }; |
| 1830 | 1856 | slash.addEventListener('click', () => { |
| 1831 | 1857 | if (!cmdMenu.hidden) { cerrarMenu({ foco: slash }); return; } |
| 1832 | - abrirMenu('/'); | |
| 1858 | + abrirMenu('/', { lista: false }); | |
| 1833 | 1859 | filas()[0]?.focus(); |
| 1834 | 1860 | }); |
| 1835 | 1861 | // Dentro del menú (abierto con el botón): flechas, Inicio/Fin, Escape. |