utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 074b411115db14e750c79043cb764821546f0b80a5cf64de50c3cce35f36d62e |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-11 17:33 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 17:33 +02:00 |
| Parents | 480b615bc50f |
2 files changed
modified tests/view-list.mjs +81 −0
| @@ -4,6 +4,10 @@ | ||
| 4 | 4 | // vista. Antes solo había el lienzo: con teclado o lector de pantalla no se |
| 5 | 5 | // podía llegar a ningún fichero desde ahí. |
| 6 | 6 | // |
| 7 | +// Y la vista tapa el editor de verdad (partes 3 y 4): el foco entra en ella, el | |
| 8 | +// editor de debajo queda inerte (el Tab no lo alcanza ni lo edita a ciegas) y al | |
| 9 | +// cerrarla el foco vuelve a quien la abrió. | |
| 10 | +// | |
| 7 | 11 | // BASE=http://localhost:8799 node tests/view-list.mjs |
| 8 | 12 | import { chromium } from 'playwright'; |
| 9 | 13 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| @@ -77,6 +81,83 @@ | ||
| 77 | 81 | const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => ''); |
| 78 | 82 | ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2); |
| 79 | 83 | |
| 84 | +// 3 · Con teclado, la vista tapa el editor DE VERDAD. Antes el foco se quedaba en | |
| 85 | +// el botón y el Tab, tras la barra, el árbol y la pestaña, caía en el editor | |
| 86 | +// tapado: cada Tab sangraba el fichero sin que se viera, y la lista no se | |
| 87 | +// alcanzaba nunca con Tab hacia delante. | |
| 88 | +{ | |
| 89 | + await p.evaluate(async () => { await (await import('/js/ide.js')).openFile('src/app.js'); }); | |
| 90 | + await p.waitForTimeout(500); | |
| 91 | + const fichero = () => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue()); | |
| 92 | + const antes = await fichero(); | |
| 93 | + await p.focus('#act-arch'); | |
| 94 | + await p.keyboard.press('Enter'); | |
| 95 | + await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {}); | |
| 96 | + await p.waitForTimeout(300); | |
| 97 | + const alAbrir = await p.evaluate(() => ({ | |
| 98 | + foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert, | |
| 99 | + })); | |
| 100 | + ok('3 · Enter en Arquitectura: el foco entra en la vista (el buscador) y el editor de debajo queda inerte', | |
| 101 | + alAbrir.foco === 'vl-filter' && alAbrir.editorInerte === true, JSON.stringify(alAbrir)); | |
| 102 | + await p.focus('#act-arch'); | |
| 103 | + const paradas = []; | |
| 104 | + for (let i = 0; i < 14; i++) { | |
| 105 | + await p.keyboard.press('Tab'); | |
| 106 | + paradas.push(await p.evaluate(() => { | |
| 107 | + const a = document.activeElement; | |
| 108 | + return a?.closest('.monaco-editor') ? 'EDITOR' : a?.closest('#view-overlay') ? 'VISTA' : (a?.id || a?.tagName); | |
| 109 | + })); | |
| 110 | + } | |
| 111 | + const despues = await fichero(); | |
| 112 | + const pestana = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => ''); | |
| 113 | + ok('3 · Tab desde el botón llega a la lista de la vista y nunca al editor tapado', | |
| 114 | + paradas.includes('VISTA') && !paradas.includes('EDITOR'), paradas.join(' › ')); | |
| 115 | + ok('3 · …y el fichero de debajo no cambia', despues === antes && !/sin guardar|unsaved/.test(pestana || ''), `${JSON.stringify(despues.slice(0, 30))} · ${pestana}`); | |
| 116 | + await p.focus('.view-list .vl-filter'); | |
| 117 | + await p.keyboard.press('Escape'); | |
| 118 | + await p.waitForTimeout(300); | |
| 119 | + const alCerrar = await p.evaluate(() => ({ | |
| 120 | + oculta: document.getElementById('view-overlay').hidden, foco: document.activeElement?.id, | |
| 121 | + editorInerte: document.getElementById('editor').inert, | |
| 122 | + })); | |
| 123 | + ok('3 · Escape la cierra, el foco vuelve al botón y el editor vuelve a ser usable', | |
| 124 | + alCerrar.oculta && alCerrar.foco === 'act-arch' && alCerrar.editorInerte === false, JSON.stringify(alCerrar)); | |
| 125 | + await p.focus('#act-city'); | |
| 126 | + await p.keyboard.press('Enter'); | |
| 127 | + await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {}); | |
| 128 | + await p.waitForTimeout(300); | |
| 129 | + const ciudad = await p.evaluate(() => ({ foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert })); | |
| 130 | + ok('3 · la Ciudad igual: foco en su buscador y el editor inerte', ciudad.foco === 'vl-filter' && ciudad.editorInerte === true, JSON.stringify(ciudad)); | |
| 131 | + await p.click('#view-close'); | |
| 132 | + await p.waitForTimeout(300); | |
| 133 | + ok('3 · ✕ con el ratón también la cierra y suelta el editor', | |
| 134 | + await p.evaluate(() => document.getElementById('view-overlay').hidden && !document.getElementById('editor').inert)); | |
| 135 | +} | |
| 136 | + | |
| 137 | +// 4 · En el móvil el foco entra en la vista por su ✕, no por el buscador: | |
| 138 | +// enfocar el buscador sacaría el teclado encima de la lista. | |
| 139 | +{ | |
| 140 | + const mctx = await b.newContext({ locale: 'es-ES', viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }); | |
| 141 | + await mctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 142 | + const m = await mctx.newPage(); | |
| 143 | + m.on('pageerror', e => errs.push('móvil: ' + e.message.slice(0, 160))); | |
| 144 | + await m.goto(BASE + '/manifest.json'); | |
| 145 | + await m.evaluate(async () => { | |
| 146 | + const o = await navigator.storage.getDirectory(); | |
| 147 | + const f = await o.getFileHandle('index.js', { create: true }); const s = await f.createWritable(); await s.write("export const a = 1;"); await s.close(); | |
| 148 | + }); | |
| 149 | + await m.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 150 | + await m.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 }); | |
| 151 | + await m.tap('#btn-drawer'); | |
| 152 | + await m.waitForTimeout(300); | |
| 153 | + await m.tap('#act-arch'); | |
| 154 | + await m.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {}); | |
| 155 | + await m.waitForTimeout(300); | |
| 156 | + const movil = await m.evaluate(() => ({ foco: document.activeElement?.id || document.activeElement?.className, editorInerte: document.getElementById('editor').inert })); | |
| 157 | + ok('4 · móvil: el foco entra en la vista por su ✕ y el editor queda inerte', movil.foco === 'view-close' && movil.editorInerte === true, JSON.stringify(movil)); | |
| 158 | + await mctx.close(); | |
| 159 | +} | |
| 160 | + | |
| 80 | 161 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 81 | 162 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
| 82 | 163 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado'); |
modified web/js/main.js +30 −1
| @@ -1824,9 +1824,30 @@ | ||
| 1824 | 1824 | $('act-arch').innerHTML = UI.graph || UI.code; |
| 1825 | 1825 | $('act-city').innerHTML = UI.city || UI.code; |
| 1826 | 1826 | let viewRenderSeq = 0; |
| 1827 | +// La vista tapa el editor (y el terminal, si está abierto): mientras se ve, lo | |
| 1828 | +// de debajo queda INERTE y el foco entra en ella. Antes el foco se quedaba en el | |
| 1829 | +// botón que la abría, y el Tab, tras la barra de actividad, el árbol y la | |
| 1830 | +// pestaña del editor, caía en el editor TAPADO: cada Tab sangraba el fichero | |
| 1831 | +// abierto sin que se viera, y la lista de la vista no se alcanzaba nunca. (La | |
| 1832 | +// Mente usa modal.js porque tapa la página entera; la vista solo tapa el | |
| 1833 | +// editor, y la barra de actividad, el árbol y el chat siguen a mano.) | |
| 1834 | +const TAPADO_POR_VISTA = ['editor', 'terminal-panel']; | |
| 1835 | +const tapaVista = si => { for (const id of TAPADO_POR_VISTA) { const e = $(id); if (e) e.inert = si; } }; | |
| 1836 | +let abridorVista = null; | |
| 1837 | +function seVe(e) { return !!e && e !== document.body && e.isConnected && e.getClientRects().length > 0; } | |
| 1838 | +function entraEnVista(overlay) { | |
| 1839 | + // Si mientras se montaba el usuario se puso a escribir en otro sitio (el | |
| 1840 | + // chat), no se le quita el foco. | |
| 1841 | + const a = document.activeElement; | |
| 1842 | + if (a && a !== document.body && !overlay.contains(a) && seVe(a) && a.matches('input, textarea, select, [contenteditable]')) return; | |
| 1843 | + // En el móvil, enfocar el buscador sacaría el teclado encima de la lista. | |
| 1844 | + const destino = (!matchMedia('(pointer: coarse)').matches && overlay.querySelector('.vl-filter')) || $('view-close'); | |
| 1845 | + try { destino.focus({ preventScroll: true }); } catch { /* — */ } | |
| 1846 | +} | |
| 1827 | 1847 | async function openView(kind) { |
| 1828 | 1848 | const overlay = $('view-overlay'), body = $('view-body'); |
| 1829 | 1849 | const seq = ++viewRenderSeq; |
| 1850 | + if (!overlay.contains(document.activeElement)) abridorVista = document.activeElement; | |
| 1830 | 1851 | // destruir CUALQUIER vista previa (su RAF/canvas seguía vivo al cambiar → la |
| 1831 | 1852 | // nueva no cargaba bien). Ambas, no solo la del mismo tipo. |
| 1832 | 1853 | try { (await import('./city.js')).disposeCity(); } catch { /* */ } |
| @@ -1834,6 +1855,7 @@ | ||
| 1834 | 1855 | body.innerHTML = '<div class="view-loading" role="status"></div>'; |
| 1835 | 1856 | body.firstChild.textContent = t('viewBuilding'); |
| 1836 | 1857 | overlay.hidden = false; |
| 1858 | + tapaVista(true); | |
| 1837 | 1859 | document.querySelectorAll('#activity button').forEach(b => b.classList.toggle('on', b.id === 'act-' + kind)); |
| 1838 | 1860 | // esperar a que el layout dé tamaño real al overlay (si no, canvas 0×0/mal aspect) |
| 1839 | 1861 | await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r))); |
| @@ -1845,6 +1867,7 @@ | ||
| 1845 | 1867 | else { const m = await import('./city.js'); vista = await m.renderCity(body, abre); } |
| 1846 | 1868 | if (seq === viewRenderSeq) montaListaVista(body, vista, abre); |
| 1847 | 1869 | } catch (e) { body.innerHTML = '<div class="view-loading" role="status"></div>'; body.firstChild.textContent = t('viewFailed', { e: e?.message || e }); } |
| 1870 | + if (seq === viewRenderSeq && !overlay.hidden) entraEnVista(overlay); | |
| 1848 | 1871 | } |
| 1849 | 1872 | |
| 1850 | 1873 | // Lo que hay en la vista 3D, también como LISTA que se busca y se recorre con |
| @@ -1921,10 +1944,16 @@ | ||
| 1921 | 1944 | function closeView({ foco = false } = {}) { |
| 1922 | 1945 | const abierta = [...document.querySelectorAll('#act-arch.on, #act-city.on')][0]; |
| 1923 | 1946 | $('view-overlay').hidden = true; |
| 1947 | + tapaVista(false); | |
| 1924 | 1948 | import('./city.js').then(m => m.disposeCity()).catch(() => {}); |
| 1925 | 1949 | import('./arch.js').then(m => m.disposeArch()).catch(() => {}); |
| 1926 | 1950 | document.querySelectorAll('#activity button').forEach(b => b.classList.toggle('on', b.id === 'act-files')); |
| 1927 | - if (foco) abierta?.focus(); | |
| 1951 | + // El foco vuelve a quien la abrió si aún se ve; si no (un menú que ya se | |
| 1952 | + // cerró), al botón de la vista en la barra de actividad; en el móvil, donde | |
| 1953 | + // esos botones viven en el cajón cerrado, al ☰. | |
| 1954 | + const vuelta = [abridorVista, abierta, $('btn-drawer'), $('prompt')].find(seVe); | |
| 1955 | + abridorVista = null; | |
| 1956 | + if (foco) vuelta?.focus(); | |
| 1928 | 1957 | } |
| 1929 | 1958 | $('act-arch').addEventListener('click', () => openView('arch')); |
| 1930 | 1959 | $('act-city').addEventListener('click', () => openView('city')); |