Elffuss BraidHub

utopia-ia/elffuss-code public

3D views: a searchable list of what they draw, usable from the keyboard

The Architecture graph and the City are a canvas only. With a keyboard or a
screen reader no file could be reached from them, and there was no way to
find one by typing.

arch.js and city.js now also return what they draw (path, connections or
size) and a locate() that brings the camera to a file (the graph's node, or the
building, briefly highlighted). Next to the canvas main.js mounts a list with a
search box: typing filters it and says "n of total"; ArrowDown from the box
enters the list and Up/Down walk it; Enter or a click opens the file (closing
the view and focusing the editor, like a click on the canvas); the button
next to each row shows that file in the view. Long projects show the first 200
matches and say how many more there are.

tests/view-list.mjs: the Architecture list has the graph's code files and each
row names its file and connections; filtering says "1 de 3"; the locate button
leaves the view open; Enter in the box opens the first match. The City list
has every project file; the arrow keys walk it and come back to the box; a row
opens its file.
Changeset4b3dbf7a370418988e1febc3560c01f170451d76e53ba07866c7401b2a3a0de1
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00
Parents02e2a33f0d40

Browse the files at this changeset

6 files changed

added tests/view-list.mjs +84 −0
@@ -0,0 +1,84 @@
1+// Las vistas 3D (Arquitectura y Ciudad) llevan al lado la lista de lo que
2+// pintan, para quien no puede (o no quiere) apuntar en un lienzo 3D: se busca
3+// escribiendo, se recorre con ↑/↓, Enter abre el fichero y ◎ lo enseña en la
4+// vista. Antes solo había el lienzo: con teclado o lector de pantalla no se
5+// podía llegar a ningún fichero desde ahí.
6+//
7+// BASE=http://localhost:8799 node tests/view-list.mjs
8+import { chromium } from 'playwright';
9+const BASE = process.env.BASE || 'http://localhost:8799';
10+let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
11+
12+const b = await chromium.launch();
13+const ctx = await b.newContext({ locale: 'es-ES' });
14+await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
15+const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } });
16+const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
17+await p.goto(BASE + '/manifest.json');
18+await p.evaluate(async () => {
19+ const o = await navigator.storage.getDirectory();
20+ const w = async (path, txt) => { const parts = path.split('/'); const name = parts.pop(); let d = o; for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); const f = await d.getFileHandle(name, { create: true }); const s = await f.createWritable(); await s.write(txt); await s.close(); };
21+ await w('index.js', "import {app} from './src/app.js';\napp();");
22+ await w('src/app.js', "import {greet} from './utils.js';\nexport const app=()=>greet('x');");
23+ await w('src/utils.js', "export const greet=d=>String(d);");
24+ await w('docs/notas.md', '# notas');
25+});
26+await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
27+await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
28+
29+async function vista(boton, sel) {
30+ await p.click(boton);
31+ await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
32+ await p.waitForTimeout(300);
33+ return p.evaluate(s => ({
34+ hay: !!document.querySelector('#view-body .view-list'),
35+ nombre: document.querySelector('.view-list')?.getAttribute('aria-label'),
36+ filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path),
37+ cuenta: document.querySelector('.view-list .vl-count')?.textContent,
38+ lienzo: !!document.querySelector(s),
39+ }), sel);
40+}
41+
42+// 1 · Arquitectura
43+let a = await vista('#act-arch', '#arch-graph canvas');
44+ok('1 · Arquitectura: junto al grafo, la lista de sus ficheros', a.hay && a.lienzo && JSON.stringify(a.filas) === '["index.js","src/app.js","src/utils.js"]', JSON.stringify(a));
45+const fila = await p.evaluate(() => { const b = document.querySelector('.view-list .vl-open[data-path="src/app.js"]'); return b?.getAttribute('aria-label'); });
46+ok('1 · …cada fila dice qué abre y sus conexiones', /^Abrir src\/app\.js · \d+ conexiones$/.test(fila || ''), fila);
47+await p.fill('.view-list .vl-filter', 'util');
48+await p.waitForTimeout(100);
49+const filtrado = await p.evaluate(() => ({ filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path), cuenta: document.querySelector('.view-list .vl-count').textContent }));
50+ok('1 · escribir filtra la lista y lo dice («1 de 3»)', JSON.stringify(filtrado.filas) === '["src/utils.js"]' && filtrado.cuenta === '1 de 3', JSON.stringify(filtrado));
51+await p.locator('.view-list .vl-locate').first().click();
52+await p.waitForTimeout(300);
53+ok('1 · ◎ lo enseña en la vista sin cerrarla', !(await p.locator('#view-overlay').isHidden()));
54+await p.focus('.view-list .vl-filter');
55+await p.keyboard.press('Enter');
56+await p.waitForSelector('#view-overlay[hidden]', { state: 'attached', timeout: 5000 }).catch(() => {});
57+await p.waitForTimeout(400);
58+const tab = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
59+ok('1 · Enter en el buscador abre el primero: la vista se cierra y el fichero queda abierto', await p.locator('#view-overlay').isHidden() && tab === 'utils.js', tab);
60+
61+// 2 · Ciudad (todos los ficheros, no solo el código)
62+const c = await vista('#act-city', '#city-canvas');
63+ok('2 · Ciudad: la lista trae todos los ficheros del proyecto', c.hay && c.lienzo && c.filas.includes('docs/notas.md') && c.filas.includes('src/app.js'), JSON.stringify(c));
64+await p.focus('.view-list .vl-filter');
65+await p.keyboard.press('ArrowDown');
66+const primero = await p.evaluate(() => document.activeElement?.dataset?.path);
67+await p.keyboard.press('ArrowDown');
68+const segundo = await p.evaluate(() => document.activeElement?.dataset?.path);
69+await p.keyboard.press('ArrowUp'); await p.keyboard.press('ArrowUp');
70+const vuelve = await p.evaluate(() => document.activeElement?.classList.contains('vl-filter'));
71+ok('2 · ↓ entra en la lista y la recorre; ↑ vuelve al buscador', !!primero && !!segundo && primero !== segundo && vuelve, JSON.stringify({ primero, segundo, vuelve }));
72+await p.locator('.view-list .vl-locate').first().click();
73+await p.waitForTimeout(300);
74+ok('2 · ◎ centra el edificio sin cerrar la vista', !(await p.locator('#view-overlay').isHidden()));
75+await p.locator('.view-list .vl-open[data-path="docs/notas.md"]').click();
76+await p.waitForTimeout(500);
77+const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
78+ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2);
79+
80+console.log('\n errores JS:', errs[0] || 'ninguno');
81+ok('sin errores de página', errs.length === 0, errs.join(' | '));
82+console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado');
83+await b.close();
84+process.exit(fails ? 1 : 0);
modified web/css/code.css +11 −0
@@ -598,6 +598,17 @@
598598
599599 /* ---------- vistas Arquitectura / Ciudad 3D (overlay sobre el editor) ---------- */
600600 #view-overlay { position: absolute; inset: 34px 0 22px 0; z-index: 30; background: #0b0d12; overflow: hidden; }
601+/* Lo que hay en la vista 3D, como lista que se puede buscar y recorrer con el teclado */
602+.view-list { position: absolute; top: 48px; right: 12px; bottom: 12px; width: 280px; z-index: 31; display: flex; flex-direction: column; background: #0d1117e6; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
603+.view-list .vl-filter { width: 100%; box-sizing: border-box; background: var(--bg3); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; font-size: .78rem; }
604+.view-list .vl-count { color: var(--muted); font-size: .7rem; margin: 6px 2px 0; }
605+.view-list .vl-items { list-style: none; margin: 6px 0 0; padding: 0; overflow: auto; flex: 1; }
606+.view-list .vl-items li { display: flex; align-items: center; gap: 2px; }
607+.view-list .vl-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: #c8cede; padding: 3px 6px; border-radius: 5px; cursor: pointer; font: inherit; font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
608+.view-list .vl-open:hover, .view-list .vl-open:focus-visible, .view-list .vl-locate:hover, .view-list .vl-locate:focus-visible { background: var(--bg3); }
609+.view-list .vl-dir { color: var(--muted); font-size: .68rem; }
610+.view-list .vl-locate { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 5px; }
611+@media (max-width: 760px) { .view-list { top: auto; left: 8px; right: 8px; width: auto; height: 40%; } }
601612 #view-overlay[hidden] { display: none; }
602613 #editor-wrap { position: relative; }
603614 #view-close { position: absolute; top: 10px; right: 12px; z-index: 32; background: var(--bg3); border: 1px solid var(--line); color: var(--muted); width: 30px; height: 28px; border-radius: 7px; cursor: pointer; }
modified web/js/arch.js +0 −0

Binary content is not shown. View the file.

modified web/js/city.js +21 −0
@@ -141,7 +141,27 @@
141141 const loop = () => { raf = requestAnimationFrame(loop); controls.update(); composer.render(); };
142142 loop();
143143
144+ // Lo mismo que el lienzo, como lista (la monta main.js al lado): con teclado
145+ // o lector de pantalla una ciudad 3D no se puede recorrer. `locate` centra la
146+ // cámara en el edificio del fichero y lo resalta un momento.
147+ let resaltado = null, apaga = null;
148+ const vista = {
149+ items: model.files.map(f => ({ path: f.rel, bytes: f.size ?? f.bytes ?? null })),
150+ locate(path) {
151+ const f = model.files.find(x => x.rel === path);
152+ if (!f?.box) return false;
153+ controls.target.set(f.box.cx, f.box.cy, f.box.cz);
154+ try {
155+ if (resaltado != null) city.paintFile?.(resaltado, 0);
156+ resaltado = f.id; city.paintFile?.(f.id, 1);
157+ clearTimeout(apaga); apaga = setTimeout(() => { try { city.paintFile?.(f.id, 0); } catch { /* ya no está */ } }, 2500);
158+ } catch { /* sin resaltado: la cámara ya apunta */ }
159+ return true;
160+ },
161+ };
162+
144163 disposer = () => {
164+ clearTimeout(apaga);
145165 if (raf) cancelAnimationFrame(raf);
146166 window.removeEventListener('resize', onResize);
147167 canvas.removeEventListener('pointermove', onMove);
@@ -152,6 +172,7 @@
152172 composer.dispose?.();
153173 renderer.dispose();
154174 };
175+ return vista;
155176 }
156177
157178 export function disposeCity() { if (disposer) { disposer(); disposer = null; } }
modified web/js/i18n.js +4 −0
@@ -228,6 +228,8 @@
228228 setTelNote: "Apagado por defecto — tu código y el contenido de tus proyectos NUNCA se incluyen, solo el mensaje de error técnico, la pila y datos del navegador.",
229229 setTelManual: "O manda algo tú directamente (un fallo que viste, algo que eches en falta…)",
230230 viewBuilding: "Construyendo…", viewFailed: "No pude construir la vista: {e}", flipChat: "Chat", flipEditor: "Editor",
231+ vlLabel: 'Ficheros de esta vista', vlFilter: 'Buscar un fichero…', vlCount: '{n} de {total}', vlMore: 'se ven {n} menos: afina la búsqueda',
232+ vlOpen: 'Abrir {name}', vlLocate: 'Ver {name} en la vista', vlLinks: '{n} conexiones',
231233 termClear: "limpiar", tTermClear: "limpiar la pantalla del terminal",
232234 drawerTitle: "Archivos y herramientas",
233235 chatLogLabel: "Conversación",
@@ -460,6 +462,8 @@
460462 setTelNote: "Off by default — your code and your projects' content are NEVER included, only the technical error message, the stack and browser data.",
461463 setTelManual: "Or send something yourself (a bug you saw, something you miss…)",
462464 viewBuilding: "Building…", viewFailed: "Couldn't build the view: {e}", flipChat: "Chat", flipEditor: "Editor",
465+ vlLabel: 'Files in this view', vlFilter: 'Find a file…', vlCount: '{n} of {total}', vlMore: '{n} not shown: narrow the search',
466+ vlOpen: 'Open {name}', vlLocate: 'Show {name} in the view', vlLinks: '{n} connections',
463467 termClear: "clear", tTermClear: "clear the terminal screen",
464468 drawerTitle: "Files and tools",
465469 chatLogLabel: "Conversation",
modified web/js/main.js +77 −2
@@ -1747,10 +1747,85 @@
17471747 await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
17481748 if (seq !== viewRenderSeq) return; // el usuario cambió de vista mientras tanto
17491749 try {
1750- if (kind === 'arch') { const m = await import('./arch.js'); await m.renderArchitecture(body, p => { closeView(); openFile(p); }); }
1751- else { const m = await import('./city.js'); await m.renderCity(body, p => { closeView(); openFile(p); }); }
1750+ const abre = p => { closeView(); openFile(p).then(() => focusEditor()); };
1751+ let vista = null;
1752+ if (kind === 'arch') { const m = await import('./arch.js'); vista = await m.renderArchitecture(body, abre); }
1753+ else { const m = await import('./city.js'); vista = await m.renderCity(body, abre); }
1754+ if (seq === viewRenderSeq) montaListaVista(body, vista, abre);
17521755 } catch (e) { body.innerHTML = '<div class="view-loading" role="status"></div>'; body.firstChild.textContent = t('viewFailed', { e: e?.message || e }); }
17531756 }
1757+
1758+// Lo que hay en la vista 3D, también como LISTA que se busca y se recorre con
1759+// el teclado: un grafo o una ciudad en un lienzo no los recorre un lector de
1760+// pantalla ni se buscan escribiendo. Enter (o clic) abre el fichero, como el
1761+// clic en el lienzo; ◎ lo enseña en la vista. ↓ desde el buscador entra en la
1762+// lista y ↑/↓ la recorren.
1763+const MAX_LISTA_VISTA = 200;
1764+const pesoCorto = n => n < 1024 ? n + ' B' : n < 1048576 ? Math.round(n / 1024) + ' KB' : (n / 1048576).toFixed(1) + ' MB';
1765+function montaListaVista(body, vista, abre) {
1766+ if (!vista?.items?.length) return;
1767+ const items = vista.items.slice().sort((a, b) => a.path.localeCompare(b.path));
1768+ const caja = document.createElement('aside');
1769+ caja.className = 'view-list';
1770+ caja.setAttribute('aria-label', t('vlLabel'));
1771+ const filtro = document.createElement('input');
1772+ filtro.type = 'search';
1773+ filtro.className = 'vl-filter';
1774+ filtro.placeholder = t('vlFilter');
1775+ filtro.setAttribute('aria-label', t('vlFilter'));
1776+ filtro.setAttribute('aria-controls', 'vl-items');
1777+ const cuenta = document.createElement('div');
1778+ cuenta.className = 'vl-count';
1779+ cuenta.setAttribute('role', 'status');
1780+ const lista = document.createElement('ul');
1781+ lista.id = 'vl-items';
1782+ lista.className = 'vl-items';
1783+ const pinta = () => {
1784+ const q = filtro.value.trim().toLowerCase();
1785+ const hits = q ? items.filter(it => it.path.toLowerCase().includes(q)) : items;
1786+ lista.replaceChildren();
1787+ for (const it of hits.slice(0, MAX_LISTA_VISTA)) {
1788+ const li = document.createElement('li');
1789+ const nombre = it.path.split('/').pop(), dir = it.path.slice(0, Math.max(0, it.path.length - nombre.length - 1));
1790+ const meta = it.conexiones != null ? t('vlLinks', { n: it.conexiones }) : it.bytes != null ? pesoCorto(it.bytes) : '';
1791+ const abrir = document.createElement('button');
1792+ abrir.type = 'button';
1793+ abrir.className = 'vl-open';
1794+ abrir.dataset.path = it.path;
1795+ abrir.textContent = nombre;
1796+ if (dir) { const s = document.createElement('span'); s.className = 'vl-dir'; s.textContent = dir; abrir.append(' ', s); }
1797+ abrir.setAttribute('aria-label', t('vlOpen', { name: it.path }) + (meta ? ' · ' + meta : ''));
1798+ abrir.title = it.path + (meta ? ' · ' + meta : '');
1799+ abrir.onclick = () => abre(it.path);
1800+ const ver = document.createElement('button');
1801+ ver.type = 'button';
1802+ ver.className = 'vl-locate';
1803+ ver.textContent = '◎';
1804+ ver.setAttribute('aria-label', t('vlLocate', { name: it.path }));
1805+ ver.title = ver.getAttribute('aria-label');
1806+ ver.onclick = () => vista.locate?.(it.path);
1807+ li.append(abrir, ver);
1808+ lista.appendChild(li);
1809+ }
1810+ cuenta.textContent = t('vlCount', { n: hits.length, total: items.length })
1811+ + (hits.length > MAX_LISTA_VISTA ? ' · ' + t('vlMore', { n: hits.length - MAX_LISTA_VISTA }) : '');
1812+ };
1813+ filtro.addEventListener('input', pinta);
1814+ filtro.addEventListener('keydown', e => {
1815+ if (e.key === 'ArrowDown') { e.preventDefault(); lista.querySelector('.vl-open')?.focus(); }
1816+ else if (e.key === 'Enter') { const primero = lista.querySelector('.vl-open'); if (primero) { e.preventDefault(); primero.click(); } }
1817+ });
1818+ lista.addEventListener('keydown', e => {
1819+ const bs = [...lista.querySelectorAll('.vl-open')];
1820+ const i = bs.indexOf(document.activeElement);
1821+ if (i < 0) return;
1822+ if (e.key === 'ArrowDown') { e.preventDefault(); bs[Math.min(bs.length - 1, i + 1)].focus(); }
1823+ else if (e.key === 'ArrowUp') { e.preventDefault(); (i ? bs[i - 1] : filtro).focus(); }
1824+ });
1825+ caja.append(filtro, cuenta, lista);
1826+ body.appendChild(caja);
1827+ pinta();
1828+}
17541829 function closeView({ foco = false } = {}) {
17551830 const abierta = [...document.querySelectorAll('#act-arch.on, #act-city.on')][0];
17561831 $('view-overlay').hidden = true;