utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 33079db2b6ac655f158dbc968e8970c61ae9fd17ea61c229d2ba84127871166c |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-12 12:17 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-12 12:17 +02:00 |
| Parents | e3a5e805b49b |
6 files changed
modified tests/ext_feedback.mjs +3 −1
| @@ -152,6 +152,7 @@ | ||
| 152 | 152 | return route.fulfill({ status: 404, body: '' }); |
| 153 | 153 | }); |
| 154 | 154 | await abrePanel(p); |
| 155 | + await p.uncheck('#ext-only-works'); // this section reads every verdict, the ones that do nothing too | |
| 155 | 156 | await p.fill('#ext-q', 'anything'); |
| 156 | 157 | await p.press('#ext-q', 'Enter'); |
| 157 | 158 | const r = id => p.locator(`#ext-results .ext-row[data-id="${id}"]`); |
| @@ -217,9 +218,10 @@ | ||
| 217 | 218 | await p.fill('#ext-q', 'prettier'); |
| 218 | 219 | await p.press('#ext-q', 'Enter'); |
| 219 | 220 | const row = p.locator('#ext-results .ext-row[data-id="esbenp.prettier-vscode"]'); |
| 220 | - await row.waitFor({ timeout: 20000 }).catch(() => {}); | |
| 221 | + await row.waitFor({ state: 'attached', timeout: 20000 }).catch(() => {}); | |
| 221 | 222 | const dis = await hasta(async () => (await row.locator('.ext-install').getAttribute('aria-disabled')) === 'true', { tiempo: 20000 }); |
| 222 | 223 | ok('live: Prettier is not offered as a plain Install', !!dis, await row.innerText().catch(() => '')); |
| 224 | + ok('live: …and with «Only ones that work in Code» (on by default) it is hidden', await hasta(async () => !(await row.isVisible()) && /hidden because/.test(await p.locator('#ext-hidden').innerText().catch(() => ''))), await p.locator('#ext-hidden').innerText().catch(() => '')); | |
| 223 | 225 | await p.fill('#ext-q', 'dracula'); |
| 224 | 226 | await p.press('#ext-q', 'Enter'); |
| 225 | 227 | const d = p.locator('#ext-results .ext-row[data-id="dracula-theme.theme-dracula"]'); |
added tests/ext_popular.mjs +238 −0
| @@ -0,0 +1,238 @@ | ||
| 1 | +// Extensions panel: the "Popular" list and the "Only ones that work in Code" | |
| 2 | +// filter on search results. | |
| 3 | +// | |
| 4 | +// CENSUS=<extensions.tsv> BASE=http://127.0.0.1:8999 node tests/ext_popular.mjs | |
| 5 | +// | |
| 6 | +// 1. (no browser) web/js/ext/popular.json against the static census of Open | |
| 7 | +// VSX (tests/catalog_census.mjs writes it; CENSUS= points to another copy): | |
| 8 | +// no entry has code of its own, every one gets the panel's "works" verdict, | |
| 9 | +// no built-in language pack, ordered by downloads, three kinds in the top 10. | |
| 10 | +// 2. (browser, Open VSX mocked) Popular shows on opening with no request to | |
| 11 | +// Open VSX; a search hides what does nothing, says how many, fetches more | |
| 12 | +// pages to fill the view, and "show" / the checkbox bring them back. | |
| 13 | +// 3. LIVE: installs a few entries of the real list from Open VSX. Without | |
| 14 | +// network it is NOT RUN and does not count as a failure. | |
| 15 | +import fs from 'node:fs'; | |
| 16 | +import path from 'node:path'; | |
| 17 | +import { fileURLToPath } from 'node:url'; | |
| 18 | +import { chromium } from 'playwright'; | |
| 19 | +import { describe, factsFromManifest, works } from '../web/js/ext/verdict.js'; | |
| 20 | + | |
| 21 | +const HERE = path.dirname(fileURLToPath(import.meta.url)); | |
| 22 | +const BASE = process.env.BASE || 'http://localhost:8999'; | |
| 23 | +const OUT = process.env.SCRATCH || '/tmp/elffuss-test'; | |
| 24 | +fs.mkdirSync(OUT, { recursive: true }); | |
| 25 | +let fails = 0; | |
| 26 | +const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 27 | +const notRun = (n, e) => console.log('⏭️ NOT RUN ' + n + (e ? ' — ' + e : '')); | |
| 28 | +const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
| 29 | +async function hasta(fn, { tiempo = 12000, cada = 150 } = {}) { | |
| 30 | + const fin = Date.now() + tiempo; | |
| 31 | + let v; | |
| 32 | + while (Date.now() < fin) { try { v = await fn(); if (v) return v; } catch { /* retry */ } await sleep(cada); } | |
| 33 | + return v; | |
| 34 | +} | |
| 35 | +const NOMBRE_VETADO = /Claude[-_ ]?Code/i; | |
| 36 | + | |
| 37 | +// ── 1. the list itself ── | |
| 38 | +const POP = JSON.parse(fs.readFileSync(path.join(HERE, '../web/js/ext/popular.json'), 'utf8')); | |
| 39 | +const items = POP.items; | |
| 40 | +{ | |
| 41 | + ok(`popular.json: between 30 and 40 entries (${items.length})`, items.length >= 30 && items.length <= 40); | |
| 42 | + const CENSUS = process.env.CENSUS || path.join(HERE, 'catalog-census/extensions.tsv'); | |
| 43 | + if (!fs.existsSync(CENSUS)) ok('census found (CENSUS=<extensions.tsv>)', false, CENSUS + ' does not exist: this check cannot run without it'); | |
| 44 | + else { | |
| 45 | + const [head, ...lines] = fs.readFileSync(CENSUS, 'utf8').trim().split('\n'); | |
| 46 | + const cols = head.split('\t'); | |
| 47 | + const census = new Map(lines.map(l => { const r = Object.fromEntries(l.split('\t').map((v, i) => [cols[i], v])); return [r.id.toLowerCase(), r]; })); | |
| 48 | + ok(`census read (${census.size} extensions)`, census.size > 10000); | |
| 49 | + const fuera = items.filter(p => !census.has(p.id.toLowerCase())); | |
| 50 | + ok('every entry is in the census', !fuera.length, fuera.map(p => p.id).join(' ')); | |
| 51 | + const conCodigo = items.filter(p => census.get(p.id.toLowerCase())?.runtime !== 'none'); | |
| 52 | + ok('no entry needs Node, or any code of its own (census runtime=none)', !conCodigo.length, conCodigo.map(p => `${p.id}=${census.get(p.id.toLowerCase())?.runtime}`).join(' ')); | |
| 53 | + const noFunciona = items.filter(p => census.get(p.id.toLowerCase())?.works !== '1' || census.get(p.id.toLowerCase())?.declarative !== '1'); | |
| 54 | + ok('every entry works in Code by the census (works=1, declarative=1)', !noFunciona.length, noFunciona.map(p => p.id).join(' ')); | |
| 55 | + const orden = items.map(p => Number(census.get(p.id.toLowerCase())?.rank)); | |
| 56 | + ok('ordered by downloads (census rank ascending)', orden.every((r, i) => i === 0 || r > orden[i - 1]), orden.join(',')); | |
| 57 | + } | |
| 58 | + ok('no built-in vscode.* language pack', !items.some(p => /^vscode\./i.test(p.id))); | |
| 59 | + // (every language exists here: which ones Monaco has is the generator's job, | |
| 60 | + // checked against Monaco's own bundle when the list is built) | |
| 61 | + const host = { builtinLanguage: () => false, grammarSkippedFor: () => false, languageName: id => id, languageExtensions: () => [] }; | |
| 62 | + const malas = items.filter(p => p.analysis.hasCode || !works(describe(factsFromManifest(host, p.analysis))) || describe(factsFromManifest(host, p.analysis)).kind !== 'full'); | |
| 63 | + ok('the panel\'s own verdict on each stored analysis: «Works in Code», no code', !malas.length, malas.map(p => p.id).join(' ')); | |
| 64 | + const top = new Set(items.slice(0, 10).map(p => p.kind)); | |
| 65 | + ok('the top 10 mixes themes, languages and snippets', top.has('theme') && top.has('language') && top.has('snippets'), [...top].join(',')); | |
| 66 | + ok('each entry: id, name, kind and a one-line description in es and en', items.every(p => p.id && p.displayName && ['theme', 'language', 'snippets'].includes(p.kind) && p.description?.es?.trim() && p.description?.en?.trim() && !/\n/.test(p.description.es + p.description.en))); | |
| 67 | + const texto = fs.readFileSync(path.join(HERE, '../web/js/ext/popular.json'), 'utf8') + fs.readFileSync(path.join(HERE, '../web/js/ext/i18n.js'), 'utf8'); | |
| 68 | + ok('the list and the panel strings never name that other product', !NOMBRE_VETADO.test(texto)); | |
| 69 | +} | |
| 70 | + | |
| 71 | +// ── 2. the panel, Open VSX mocked ── | |
| 72 | +const b = await chromium.launch(); | |
| 73 | +async function nuevaPagina(locale, viewport = { width: 1280, height: 860 }) { | |
| 74 | + const ctx = await b.newContext({ locale, viewport }); | |
| 75 | + await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 76 | + const p = await ctx.newPage(); | |
| 77 | + p.errores = []; | |
| 78 | + p.on('pageerror', e => { if (e.message !== 'Canceled') p.errores.push(e.message); }); | |
| 79 | + await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); | |
| 80 | + await p.evaluate(async () => { | |
| 81 | + const o = await navigator.storage.getDirectory(); | |
| 82 | + for await (const k of o.keys()) await o.removeEntry(k, { recursive: true }).catch(() => {}); | |
| 83 | + const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); }; | |
| 84 | + await w('app.js', '// app\nconst a = 1;\n'); | |
| 85 | + await w('.env', 'API_KEY=abc # secret\n'); | |
| 86 | + }); | |
| 87 | + await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 88 | + await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length), { tiempo: 30000 }); | |
| 89 | + return { ctx, p }; | |
| 90 | +} | |
| 91 | +const abrePanel = async p => { | |
| 92 | + if (await p.locator('#ext-panel').isVisible().catch(() => false)) return; | |
| 93 | + await p.evaluate(() => document.getElementById('act-ext').click()); // on a phone the activity bar is in the drawer | |
| 94 | + await p.waitForSelector('#ext-panel', { timeout: 10000 }); | |
| 95 | +}; | |
| 96 | + | |
| 97 | +// 60 results in three pages of 20; two of each page work, the rest only run | |
| 98 | +// their own code (one of them is published per platform, so its package.json | |
| 99 | +// is only under /linux-x64/: before, that row came with no verdict and stayed) | |
| 100 | +const TOTAL = 60; | |
| 101 | +const mock = i => { | |
| 102 | + const funciona = i % 20 < 2; | |
| 103 | + const id = funciona ? `works-${i}` : `node-${i}`; | |
| 104 | + return { namespace: 'elffuss-test', name: id, version: '1.0.0', displayName: funciona ? `Theme ${i}` : `Tool ${i}`, description: '', downloadCount: 1000 - i, | |
| 105 | + files: { download: `https://open-vsx.org/api/elffuss-test/${id}/${i === 5 ? 'linux-x64/' : ''}1.0.0/file/x.vsix` } }; | |
| 106 | +}; | |
| 107 | +const manifiesto = name => (name.startsWith('works-') | |
| 108 | + ? { publisher: 'elffuss-test', name, version: '1.0.0', categories: ['Themes'], contributes: { themes: [{ label: `Mock ${name}`, path: './t.json' }] } } | |
| 109 | + : { publisher: 'elffuss-test', name, version: '1.0.0', categories: ['Linters'], main: './out/extension.js', contributes: { commands: [{ command: 'x' }], configuration: {} } }); | |
| 110 | +async function simula(ctx) { | |
| 111 | + const log = { search: [], openvsx: [] }; | |
| 112 | + await ctx.route(/open-vsx\.org|eclipsecontent\.org/, route => { | |
| 113 | + const u = new URL(route.request().url()); | |
| 114 | + log.openvsx.push(u.pathname); | |
| 115 | + const json = (o, status = 200) => route.fulfill({ status, contentType: 'application/json', headers: { 'access-control-allow-origin': '*' }, body: JSON.stringify(o) }); | |
| 116 | + if (u.pathname === '/api/-/search') { | |
| 117 | + const off = Number(u.searchParams.get('offset')) || 0, size = Number(u.searchParams.get('size')) || 20; | |
| 118 | + log.search.push(off); | |
| 119 | + return json({ totalSize: TOTAL, offset: off, extensions: Array.from({ length: Math.max(0, Math.min(size, TOTAL - off)) }, (_, k) => mock(off + k)) }); | |
| 120 | + } | |
| 121 | + const m = /^\/api\/elffuss-test\/([^/]+)\/(?:([^/]+)\/)?1\.0\.0\/file\/package\.json$/.exec(u.pathname); | |
| 122 | + if (m && (m[1] === 'node-5') === (m[2] === 'linux-x64')) return json(manifiesto(m[1])); | |
| 123 | + return json({ error: 'not found' }, 404); | |
| 124 | + }); | |
| 125 | + return log; | |
| 126 | +} | |
| 127 | +const visibles = p => p.locator('#ext-list .ext-row:not([hidden])').count(); | |
| 128 | +const ocultasDom = p => p.locator('#ext-list .ext-row[hidden]').count(); | |
| 129 | + | |
| 130 | +{ | |
| 131 | + const { ctx, p } = await nuevaPagina('en-US'); | |
| 132 | + const log = await simula(ctx); | |
| 133 | + await abrePanel(p); | |
| 134 | + const filas = p.locator('#ext-list.ext-popular .ext-row'); | |
| 135 | + ok('opening the panel: Popular is there at once, with every entry of the list', await hasta(async () => (await filas.count()) === items.length), String(await filas.count())); | |
| 136 | + const veredictos = await hasta(async () => { const v = await filas.locator('.ext-verdict').allInnerTexts(); return v.length === items.length && v; }); | |
| 137 | + ok('each popular row has its verdict line «Works in Code: …»', !!veredictos && veredictos.every(t => /^Works in Code: /.test(t)), (veredictos || []).find(t => !/^Works in Code: /.test(t)) || ''); | |
| 138 | + const kinds = await filas.locator('.ext-kind').allInnerTexts(); | |
| 139 | + ok('each popular row is tagged with its kind', kinds.length === items.length && kinds.every(k => /^(theme|language|snippets)$/i.test(k)), kinds.slice(0, 5).join(',')); | |
| 140 | + ok('…in the order of the list', (await filas.evaluateAll(rs => rs.map(r => r.dataset.id))).join() === items.map(x => `${x.namespace}.${x.name}`).join()); | |
| 141 | + ok('Popular asked Open VSX for nothing (verdicts precomputed, no icons)', log.openvsx.length === 0, log.openvsx.join(' ')); | |
| 142 | + ok('the filter is on by default', await p.isChecked('#ext-only-works')); | |
| 143 | + await p.screenshot({ path: OUT + '/extpop-popular.png' }); | |
| 144 | + | |
| 145 | + await p.fill('#ext-q', 'tool'); | |
| 146 | + await p.press('#ext-q', 'Enter'); | |
| 147 | + const lleno = await hasta(async () => log.search.length === 3 && (await p.textContent('#ext-status')) === '60 results · 54 hidden because they do not work in Code', { tiempo: 20000 }); | |
| 148 | + ok('filter on: it fetched more pages by itself to fill the view (3 searches)', !!lleno && log.search.join() === '0,20,40', log.search.join()); | |
| 149 | + ok('filter on: only the 6 that work are shown', (await visibles(p)) === 6, String(await visibles(p))); | |
| 150 | + const linea = (await p.locator('#ext-hidden').innerText()).replace(/\s+/g, ' '); | |
| 151 | + ok('the hidden count is said: «54 hidden because they do not work in Code · show»', linea === '54 hidden because they do not work in Code · show', linea); | |
| 152 | + ok('…and it is right: 54 rows hidden in the page', (await ocultasDom(p)) === 54, String(await ocultasDom(p))); | |
| 153 | + ok('…the status says it too (screen readers)', (await p.textContent('#ext-status')) === '60 results · 54 hidden because they do not work in Code', await p.textContent('#ext-status')); | |
| 154 | + ok('the per-platform build got its verdict too (and is hidden)', await p.locator('#ext-list .ext-row[data-id="elffuss-test.node-5"] .ext-verdict').count() === 1 && !(await p.locator('#ext-list .ext-row[data-id="elffuss-test.node-5"]').isVisible())); | |
| 155 | + ok('all fetched: no «More results»', await p.locator('#ext-more').count() === 0); | |
| 156 | + await p.screenshot({ path: OUT + '/extpop-filtered.png' }); | |
| 157 | + | |
| 158 | + await p.click('#ext-show-hidden'); | |
| 159 | + ok('«show»: all 60 visible, the filter unticked, the hidden line gone', await hasta(async () => (await visibles(p)) === 60 && !(await p.isChecked('#ext-only-works')) && !(await p.locator('#ext-hidden').isVisible()))); | |
| 160 | + ok('…focus goes to the filter checkbox', await p.evaluate(() => document.activeElement?.id) === 'ext-only-works'); | |
| 161 | + const honesto = (await p.locator('#ext-list .ext-row[data-id="elffuss-test.node-3"] .ext-verdict').innerText()).replace(/\s+/g, ' '); | |
| 162 | + ok('filter off: the ones that do not work carry the honest verdict', /does not work in Code/.test(honesto), honesto); | |
| 163 | + ok('filter off: the status gives no hidden count', (await p.textContent('#ext-status')) === '60 results', await p.textContent('#ext-status')); | |
| 164 | + await p.keyboard.press('Space'); | |
| 165 | + ok('keyboard: Space on the checkbox turns the filter back on (6 visible, 54 hidden)', await hasta(async () => (await p.isChecked('#ext-only-works')) && (await visibles(p)) === 6 && /^54 hidden/.test(await p.locator('#ext-hidden').innerText()))); | |
| 166 | + ok('the choice is remembered in this browser', await p.evaluate(() => localStorage.getItem('elffusscode.ext.onlyWorks')) === '1'); | |
| 167 | + | |
| 168 | + await p.fill('#ext-q', ''); | |
| 169 | + await p.press('#ext-q', 'Enter'); | |
| 170 | + ok('clearing the search brings Popular back', await hasta(async () => (await p.locator('#ext-list.ext-popular .ext-row').count()) === items.length)); | |
| 171 | + ok('no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 172 | + await ctx.close(); | |
| 173 | +} | |
| 174 | + | |
| 175 | +// Spanish, phone width | |
| 176 | +{ | |
| 177 | + const { ctx, p } = await nuevaPagina('es-ES', { width: 390, height: 844 }); | |
| 178 | + await simula(ctx); | |
| 179 | + await abrePanel(p); | |
| 180 | + await hasta(async () => (await p.locator('#ext-list.ext-popular .ext-row .ext-verdict').count()) === items.length); | |
| 181 | + const primera = (await p.locator('#ext-list.ext-popular .ext-row').first().innerText()).replace(/\s+/g, ' '); | |
| 182 | + ok('es: Popular en castellano («Funciona en Code: …», descripción y tipo)', /Funciona en Code: /.test(primera) && primera.includes(items[0].description.es) && /snippets|tema|lenguaje/i.test(primera), primera); | |
| 183 | + ok('es: «Solo las que funcionan en Code»', (await p.locator('label.ext-filter').innerText()).trim() === 'Solo las que funcionan en Code'); | |
| 184 | + const ancho = () => p.evaluate(() => { const x = document.getElementById('ext-panel'); return [x.scrollWidth, x.clientWidth, document.documentElement.scrollWidth, innerWidth]; }); | |
| 185 | + let a = await ancho(); | |
| 186 | + ok('phone width, Popular: no horizontal overflow', a[0] <= a[1] + 1 && a[2] <= a[3] + 1, a.join(',')); | |
| 187 | + await p.screenshot({ path: OUT + '/extpop-phone-es.png' }); | |
| 188 | + await p.fill('#ext-q', 'tool'); | |
| 189 | + await p.press('#ext-q', 'Enter'); | |
| 190 | + const linea = await hasta(async () => { const t = (await p.locator('#ext-hidden').innerText()).replace(/\s+/g, ' '); return /^54 /.test(t) && t; }, { tiempo: 20000 }); | |
| 191 | + ok('es: «54 ocultas porque no funcionan en Code · mostrar»', linea === '54 ocultas porque no funcionan en Code · mostrar', String(linea)); | |
| 192 | + a = await ancho(); | |
| 193 | + ok('phone width, filtered search: no horizontal overflow', a[0] <= a[1] + 1 && a[2] <= a[3] + 1, a.join(',')); | |
| 194 | + const fuera = await p.evaluate(() => [...document.querySelectorAll('#ext-panel button, #ext-panel label')].filter(b => { const r = b.getBoundingClientRect(); return r.width && (r.right > innerWidth + 1 || r.left < -1); }).length); | |
| 195 | + ok('phone width: every button fits on screen', fuera === 0, String(fuera)); | |
| 196 | + await p.screenshot({ path: OUT + '/extpop-phone-es-search.png' }); | |
| 197 | + ok('es: sin errores de página', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 198 | + await ctx.close(); | |
| 199 | +} | |
| 200 | + | |
| 201 | +// ── 3. LIVE: install some of the real list from the Popular section ── | |
| 202 | +{ | |
| 203 | + const vivo = await fetch('https://open-vsx.org/api/dracula-theme/theme-dracula', { signal: AbortSignal.timeout(8000) }).then(r => r.ok).catch(() => false); | |
| 204 | + if (!vivo) notRun('live installs from Popular', 'no network'); | |
| 205 | + else { | |
| 206 | + const { p } = await nuevaPagina('en-US'); | |
| 207 | + await abrePanel(p); | |
| 208 | + const fila = id => p.locator(`#ext-list.ext-popular .ext-row[data-id="${id}"]`); | |
| 209 | + const instala = async id => { | |
| 210 | + await fila(id).locator('.ext-install').focus(); | |
| 211 | + await p.keyboard.press('Enter'); // with the keyboard | |
| 212 | + return hasta(async () => (await p.locator(`#ext-installed .ext-row[data-id="${id.toLowerCase()}"]`).count()) === 1, { tiempo: 60000 }); | |
| 213 | + }; | |
| 214 | + const fondo = () => p.evaluate(() => getComputedStyle(document.querySelector('#editor .monaco-editor-background') || document.querySelector('#editor .monaco-editor')).backgroundColor); | |
| 215 | + await fila('dracula-theme.theme-dracula').waitFor({ timeout: 10000 }); | |
| 216 | + ok('live: Dracula installs from Popular', !!(await instala('dracula-theme.theme-dracula'))); | |
| 217 | + ok('live: …and its theme is applied', await hasta(async () => (await fondo()) === 'rgb(40, 42, 54)', { tiempo: 20000 }), await fondo()); | |
| 218 | + ok('live: DotENV installs from Popular', !!(await instala('mikestead.dotenv'))); | |
| 219 | + const lang = await p.evaluate(async () => { await (await import('/js/ide.js')).openFile('.env'); await new Promise(r => setTimeout(r, 800)); return window.monaco.editor.getEditors()[0].getModel().getLanguageId(); }); | |
| 220 | + ok('live: …a .env file opens as dotenv', lang === 'dotenv', lang); | |
| 221 | + const tipos = await p.evaluate(() => window.monaco.editor.tokenize('API_KEY=abc # secret', 'dotenv')[0].map(t => t.type).join(' ')); | |
| 222 | + ok('live: …with its own grammar (comment scope)', /comment/.test(tipos), tipos); | |
| 223 | + await abrePanel(p); | |
| 224 | + ok('live: JavaScript (ES6) snippets install from Popular', !!(await instala('xabikos.JavaScriptSnippets'))); | |
| 225 | + const tarjeta = (await p.locator('#ext-done').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 226 | + ok('live: …the notice counts its snippets', /\d+ snippets for JavaScript/.test(tarjeta), tarjeta.slice(0, 200)); | |
| 227 | + ok('live: Nix installs from Popular', !!(await instala('bbenoist.Nix'))); | |
| 228 | + const nix = await p.evaluate(() => window.monaco.languages.getLanguages().some(l => l.id === 'nix')); | |
| 229 | + ok('live: …and Code now knows the Nix language', nix); | |
| 230 | + await p.screenshot({ path: OUT + '/extpop-live.png' }); | |
| 231 | + ok('live: no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 232 | + await p.context().close(); | |
| 233 | + } | |
| 234 | +} | |
| 235 | + | |
| 236 | +console.log(fails ? `\n❌ ${fails} FAILURE(S)` : '\n✅ EXTENSIONS: POPULAR AND «ONLY ONES THAT WORK» OK'); | |
| 237 | +await b.close(); | |
| 238 | +process.exit(fails ? 1 : 0); |
modified tests/extensions.mjs +4 −1
| @@ -367,7 +367,10 @@ | ||
| 367 | 367 | await p.fill('#ext-q', 'fake'); |
| 368 | 368 | await p.press('#ext-q', 'Enter'); |
| 369 | 369 | const filaFalsa = p.locator('#ext-results .ext-row[data-id="elffuss-test.fake"]'); |
| 370 | -ok('búsqueda: el resultado llega y se anuncia («1 result»)', await hasta(async () => (await filaFalsa.count()) === 1 && (await p.textContent('#ext-status')) === '1 result'), await p.textContent('#ext-status')); | |
| 370 | +// con «Solo las que funcionan en Code» (encendido de serie) no se ve: no aplica nada | |
| 371 | +ok('búsqueda con el filtro: la que no hace nada queda oculta y se dice («1 hidden»)', await hasta(async () => (await filaFalsa.count()) === 1 && !(await filaFalsa.isVisible()) && (await p.textContent('#ext-status')) === '1 result · 1 hidden because it does not work in Code'), await p.textContent('#ext-status')); | |
| 372 | +await p.uncheck('#ext-only-works'); | |
| 373 | +ok('búsqueda: el resultado llega y se anuncia («1 result»)', await hasta(async () => (await filaFalsa.isVisible()) && (await p.textContent('#ext-status')) === '1 result'), await p.textContent('#ext-status')); | |
| 371 | 374 | ok('el botón dice que no hay nada que aplicar, con nombre propio para el lector', await hasta(async () => (await filaFalsa.locator('.ext-install').getAttribute('aria-label')) === 'Nothing to apply: Fake JSON'), await filaFalsa.locator('.ext-install').getAttribute('aria-label')); |
| 372 | 375 | await filaFalsa.locator('.ext-install').focus(); |
| 373 | 376 | await p.keyboard.press('Shift+Tab'); |
modified web/css/ext.css +11 −0
| @@ -87,3 +87,14 @@ | ||
| 87 | 87 | #ext-themepick .tp-item { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; background: none; border: none; color: var(--fg); padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: .84rem; } |
| 88 | 88 | #ext-themepick .tp-item.sel, #ext-themepick .tp-item:hover { background: rgba(130,114,255,.2); } |
| 89 | 89 | #ext-themepick .tp-item .muted { font-size: .72rem; color: var(--muted); } |
| 90 | +/* «Solo las que funcionan en Code», cuántas se ocultaron, populares */ | |
| 91 | +.ext-filter { display: inline-flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: .76rem; color: var(--fg); cursor: pointer; } | |
| 92 | +.ext-filter input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent2); cursor: pointer; } | |
| 93 | +.ext-filter input:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; } | |
| 94 | +.ext-row[hidden], .ext-hidden[hidden] { display: none; } | |
| 95 | +.ext-hidden { font-size: .74rem; margin: 2px 0 6px; overflow-wrap: anywhere; } | |
| 96 | +.ext-pop-note { margin: 0 0 6px; font-size: .74rem; line-height: 1.4; } | |
| 97 | +.ext-kind { font-size: .64rem; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); } | |
| 98 | +.ext-kind-theme { color: #d2a8ff; border-color: rgba(210,168,255,.4); } | |
| 99 | +.ext-kind-language { color: #79c0ff; border-color: rgba(121,192,255,.4); } | |
| 100 | +.ext-kind-snippets { color: #7ee787; border-color: rgba(126,231,135,.4); } |
modified web/js/ext/i18n.js +18 −0
| @@ -12,6 +12,15 @@ | ||
| 12 | 12 | vsix: 'Instalar .vsix…', themeBtn: 'Tema de color…', |
| 13 | 13 | installedH: 'Instaladas ({n})', none: 'Ninguna todavía. Busca arriba o instala un .vsix.', |
| 14 | 14 | popular: 'Populares', results: '{n} resultado|{n} resultados', noResults: 'Sin resultados.', searching: 'Buscando…', more: 'Más resultados', |
| 15 | + onlyWorks: 'Solo las que funcionan en Code', | |
| 16 | + hiddenN: '{n} oculta porque no funciona en Code|{n} ocultas porque no funcionan en Code', | |
| 17 | + showHidden: 'mostrar', showHiddenNamed: 'Mostrar también la que no funciona en Code|Mostrar también las {n} que no funcionan en Code', | |
| 18 | + checking: 'Comprobando cuáles funcionan en Code…', | |
| 19 | + noneWork: 'Ninguno de los resultados funciona en Code.', noneWorkYet: 'Ninguna de las {n} primeras funciona en Code.', | |
| 20 | + popularH: 'Populares que funcionan en Code', popularCount: '{n} extensión popular que funciona en Code|{n} extensiones populares que funcionan en Code', | |
| 21 | + popularNote: 'Se instalan y se ven al momento: temas de color, lenguajes que Code no resalta todavía y snippets. Busca arriba para ver el resto de Open VSX.', | |
| 22 | + popularFailed: 'No se pudo cargar la lista de populares. Busca arriba.', | |
| 23 | + kind_theme: 'Tema', kind_language: 'Lenguaje', kind_snippets: 'Snippets', | |
| 15 | 24 | install: 'Instalar', installing: 'Instalando…', downloading: 'Descargando… {pct}%', installedOk: 'Instalada ✓', update: 'Actualizar a {v}', |
| 16 | 25 | enable: 'Activar', disable: 'Desactivar', disabled: 'desactivada', uninstall: 'Desinstalar', confirmUninstall: '¿Desinstalar «{name}»?', |
| 17 | 26 | details: 'Detalles', loadingDetails: 'Leyendo el manifiesto…', |
| @@ -95,6 +104,15 @@ | ||
| 95 | 104 | vsix: 'Install .vsix…', themeBtn: 'Color Theme…', |
| 96 | 105 | installedH: 'Installed ({n})', none: 'None yet. Search above or install a .vsix.', |
| 97 | 106 | popular: 'Popular', results: '{n} result|{n} results', noResults: 'No results.', searching: 'Searching…', more: 'More results', |
| 107 | + onlyWorks: 'Only ones that work in Code', | |
| 108 | + hiddenN: '{n} hidden because it does not work in Code|{n} hidden because they do not work in Code', | |
| 109 | + showHidden: 'show', showHiddenNamed: 'Also show the one that does not work in Code|Also show the {n} that do not work in Code', | |
| 110 | + checking: 'Checking which ones work in Code…', | |
| 111 | + noneWork: 'None of the results works in Code.', noneWorkYet: 'None of the first {n} works in Code.', | |
| 112 | + popularH: 'Popular ones that work in Code', popularCount: '{n} popular extension that works in Code|{n} popular extensions that work in Code', | |
| 113 | + popularNote: 'They install and show at once: colour themes, languages Code does not highlight yet, and snippets. Search above for the rest of Open VSX.', | |
| 114 | + popularFailed: 'The popular list could not be loaded. Search above.', | |
| 115 | + kind_theme: 'Theme', kind_language: 'Language', kind_snippets: 'Snippets', | |
| 98 | 116 | install: 'Install', installing: 'Installing…', downloading: 'Downloading… {pct}%', installedOk: 'Installed ✓', update: 'Update to {v}', |
| 99 | 117 | enable: 'Enable', disable: 'Disable', disabled: 'disabled', uninstall: 'Uninstall', confirmUninstall: 'Uninstall “{name}”?', |
| 100 | 118 | details: 'Details', loadingDetails: 'Reading the manifest…', |
modified web/js/ext/panel.js +183 −71
| @@ -8,7 +8,8 @@ | ||
| 8 | 8 | // <summary>), los resultados y avisos se anuncian (role=status/alert), el |
| 9 | 9 | // foco no se pierde al repintar ni al cerrar, y Escape cierra el panel. |
| 10 | 10 | import { tx } from './i18n.js'; |
| 11 | -import { describe, lista, listaO, esTexto } from './verdict.js'; | |
| 11 | +import { uiLang } from '../i18n.js'; | |
| 12 | +import { describe, lista, listaO, works, languageName, languageExts, factsFromManifest, factsFromRecord } from './verdict.js'; | |
| 12 | 13 | |
| 13 | 14 | const $ = id => document.getElementById(id); |
| 14 | 15 | const el = (tag, cls, txt) => { const e = document.createElement(tag); if (cls) e.className = cls; if (txt != null) e.textContent = txt; return e; }; |
| @@ -16,7 +17,15 @@ | ||
| 16 | 17 | |
| 17 | 18 | let host = null; |
| 18 | 19 | let cssPuesto = false; |
| 19 | -const estado = { q: '', cat: null, items: [], total: 0, cargando: false, msg: null, ctl: null }; | |
| 20 | +const estado = { q: '', cat: null, items: [], total: 0, cargando: false, msg: null, ctl: null, solo: leeSolo(), objetivo: 0, auto: 0 }; | |
| 21 | +// «Solo las que funcionan en Code»: encendido salvo que quien usa el panel lo | |
| 22 | +// apagara (se recuerda en este navegador, si se puede) | |
| 23 | +const CLAVE_SOLO = 'elffusscode.ext.onlyWorks'; | |
| 24 | +function leeSolo() { try { return localStorage.getItem(CLAVE_SOLO) !== '0'; } catch { return true; } } | |
| 25 | +function guardaSolo(v) { try { localStorage.setItem(CLAVE_SOLO, v ? '1' : '0'); } catch { /* sin almacenamiento: solo esta sesión */ } } | |
| 26 | +const POR_PAGINA = 20; // filas que se quieren ver por tanda | |
| 27 | +const MAX_AUTO = 3; // páginas que se piden solas para llenarla | |
| 28 | + | |
| 20 | 29 | let temporizador = null; |
| 21 | 30 | let desuscribe = null; |
| 22 | 31 | let abridor = null; // quién tenía el foco al abrir el panel |
| @@ -131,57 +140,10 @@ | ||
| 131 | 140 | // verdad se aplicaría aquí: la gramática de un lenguaje de serie sin Monarch |
| 132 | 141 | // (JSON) y la configuración de un lenguaje de serie no se aplican, y no cuentan. |
| 133 | 142 | // ── qué hace cada extensión, en llano (verdict.js) ── |
| 134 | -const BONITOS = { | |
| 135 | - javascript: 'JavaScript', typescript: 'TypeScript', javascriptreact: 'JavaScript React', typescriptreact: 'TypeScript React', | |
| 136 | - html: 'HTML', css: 'CSS', scss: 'SCSS', less: 'Less', json: 'JSON', jsonc: 'JSON', vue: 'Vue', python: 'Python', markdown: 'Markdown', | |
| 137 | - shellscript: 'Shell', go: 'Go', rust: 'Rust', java: 'Java', php: 'PHP', ruby: 'Ruby', csharp: 'C#', cpp: 'C++', c: 'C', yaml: 'YAML', | |
| 138 | -}; | |
| 139 | -function nombreLenguaje(id, langs = []) { | |
| 140 | - return langs.find(l => l.id === id && esTexto(l.name))?.name || host?.languageName?.(id) || BONITOS[id] || id; | |
| 141 | -} | |
| 142 | -function extsDe(id, langs = []) { | |
| 143 | - const propias = langs.filter(l => l.id === id).flatMap(l => l.extensions || []); | |
| 144 | - return [...new Set(propias.length ? propias : host?.languageExtensions?.(id) || [])]; | |
| 145 | -} | |
| 146 | -// Hechos comunes a un package.json (antes de instalar) y a un registro instalado. | |
| 147 | -function hechos(base, { themes = [], grammarLangs = [], langs = [], snippets = [] }) { | |
| 148 | - const salta = l => !!host.grammarSkippedFor?.(l); | |
| 149 | - const deSerie = id => !!host.builtinLanguage?.(id); | |
| 150 | - const conGram = [...new Set(grammarLangs.filter(l => l && !salta(l)))]; | |
| 151 | - // snippets de un lenguaje que Code no tiene (javascriptreact, vue…) no | |
| 152 | - // saldrían nunca: ni se cuentan ni se prometen. Y un mismo fichero que sirve | |
| 153 | - // a varios lenguajes se cuenta una vez. | |
| 154 | - const existe = id => langs.some(l => l.id === id) || !!host.languageName?.(id) || !!host.builtinLanguage?.(id); | |
| 155 | - const porLang = new Map(); | |
| 156 | - const vistos = new Set(); | |
| 157 | - for (const s of snippets.filter(x => existe(x.language))) { | |
| 158 | - const n = !Number.isFinite(s.count) ? NaN : s.key && vistos.has(s.key) ? 0 : s.count; | |
| 159 | - if (s.key) vistos.add(s.key); | |
| 160 | - porLang.set(s.language, (porLang.has(s.language) ? porLang.get(s.language) : 0) + n); | |
| 161 | - } | |
| 162 | - return { | |
| 163 | - ...base, themes, | |
| 164 | - highlight: conGram.map(id => ({ id, name: nombreLenguaje(id, langs), exts: extsDe(id, langs) })), | |
| 165 | - settingsOnly: langs.filter(l => l.config && !deSerie(l.id) && !conGram.includes(l.id)).map(l => nombreLenguaje(l.id, langs)), | |
| 166 | - keepsBuiltin: [...new Set(grammarLangs.filter(l => l && salta(l)))].map(id => nombreLenguaje(id, langs)), | |
| 167 | - snippets: [...porLang].map(([id, n]) => ({ id, name: nombreLenguaje(id, langs), count: Number.isFinite(n) ? n : null })), | |
| 168 | - }; | |
| 169 | -} | |
| 170 | -function hechosDeManifiesto(a) { | |
| 171 | - return hechos({ hasCode: a.hasCode, browserEntry: a.browserEntry, categories: a.categories || [], sizes: a.sizes || {}, webviews: a.webviews, ignored: a.ignored || [], pack: a.pack || [] }, { | |
| 172 | - themes: a.themeLabels || [], grammarLangs: a.grammarLangs || [], langs: a.languageList || [], | |
| 173 | - snippets: (a.snippetLangs || []).map(language => ({ language, count: null })), | |
| 174 | - }); | |
| 175 | -} | |
| 176 | -function hechosDeRegistro(e) { | |
| 177 | - // registros de antes de guardar categorías: se asume que lo que se aplica es lo principal | |
| 178 | - const categories = e.categories || ['Programming Languages']; | |
| 179 | - return hechos({ hasCode: e.hasCode, browserEntry: !!e.browserEntry, categories, sizes: e.sizes || {}, webviews: e.webviews, ignored: e.ignored || [], pack: e.pack || [] }, { | |
| 180 | - themes: (e.themes || []).map(t => t.label), grammarLangs: (e.grammars || []).map(g => g.language ?? null), | |
| 181 | - langs: (e.languages || []).map(l => ({ id: l.id, name: l.aliases?.[0], extensions: l.extensions || [], config: !!l.configKey })), | |
| 182 | - snippets: (e.snippets || []).map(s => ({ language: s.language, key: s.key, count: Number.isFinite(s.count) ? s.count : null })), | |
| 183 | - }); | |
| 184 | -} | |
| 143 | +const nombreLenguaje = (id, langs = []) => languageName(host, id, langs); | |
| 144 | +const extsDe = (id, langs = []) => languageExts(host, id, langs); | |
| 145 | +const hechosDeManifiesto = a => factsFromManifest(host, a); | |
| 146 | +const hechosDeRegistro = e => factsFromRecord(host, e); | |
| 185 | 147 | // El bloque del veredicto: primero la frase que decide, luego el detalle. |
| 186 | 148 | function bloqueVeredicto(f, v, { principal = true } = {}) { |
| 187 | 149 | const box = el('div', 'ext-verdict ext-v-' + v.kind); |
| @@ -279,6 +241,14 @@ | ||
| 279 | 241 | } |
| 280 | 242 | busca.append(inp, chips); |
| 281 | 243 | wrap.appendChild(busca); |
| 244 | + const filtro = el('label', 'ext-filter'); | |
| 245 | + const solo = el('input'); | |
| 246 | + solo.type = 'checkbox'; | |
| 247 | + solo.id = 'ext-only-works'; | |
| 248 | + solo.checked = estado.solo; | |
| 249 | + solo.onchange = () => ponSolo(solo.checked); | |
| 250 | + filtro.append(solo, el('span', null, tx('onlyWorks'))); | |
| 251 | + wrap.appendChild(filtro); | |
| 282 | 252 | |
| 283 | 253 | const msg = el('div', 'ext-msg'); |
| 284 | 254 | msg.id = 'ext-msg'; |
| @@ -308,35 +278,160 @@ | ||
| 308 | 278 | estado.ctl?.abort(); |
| 309 | 279 | const ctl = new AbortController(); |
| 310 | 280 | estado.ctl = ctl; |
| 311 | - const ovsx = await import('./openvsx.js'); | |
| 312 | - if (!estado.q && estado.cat == null) { estado.items = []; estado.total = 0; pintaResultados(); return; } | |
| 313 | - estado.cargando = true; | |
| 314 | - if (!mas) { estado.items = []; estado.total = 0; } | |
| 315 | - aviso(null); | |
| 316 | - pintaResultados(); | |
| 317 | 281 | // solo las categorías: las fichas de tema de «Instaladas» también son .ext-chip |
| 318 | 282 | for (const c of document.querySelectorAll('#ext-panel .ext-search .ext-chip')) { |
| 319 | 283 | const on = c.dataset.cat === (estado.cat || '') && estado.cat != null; |
| 320 | 284 | c.classList.toggle('on', on); |
| 321 | 285 | c.setAttribute('aria-pressed', String(on)); |
| 322 | 286 | } |
| 287 | + if (!mas) { estado.objetivo = POR_PAGINA; estado.auto = 0; } | |
| 288 | + // sin buscar nada: la lista de populares que funcionan, ya calculada | |
| 289 | + if (mostrandoPopulares()) { estado.items = []; estado.total = 0; estado.cargando = false; pintaResultados(); return; } | |
| 290 | + const ovsx = await import('./openvsx.js'); | |
| 291 | + if (estado.ctl !== ctl) return; | |
| 292 | + estado.cargando = true; | |
| 293 | + if (!mas) { estado.items = []; estado.total = 0; } | |
| 294 | + aviso(null); | |
| 295 | + if (mas) pintaPie(); else pintaResultados(); | |
| 296 | + let nuevos = null; | |
| 323 | 297 | try { |
| 324 | - const r = await ovsx.search(estado.q, { category: estado.cat || '', offset: mas ? estado.items.length : 0, size: 20, signal: ctl.signal }); | |
| 298 | + const r = await ovsx.search(estado.q, { category: estado.cat || '', offset: mas ? estado.items.length : 0, size: POR_PAGINA, signal: ctl.signal }); | |
| 325 | 299 | if (estado.ctl !== ctl) return; |
| 326 | - estado.items = mas ? estado.items.concat(r.items) : r.items; | |
| 327 | - estado.total = r.total; | |
| 300 | + // (una extensión puede repetirse entre páginas si cambia el orden) | |
| 301 | + const ya = new Set(estado.items.map(claveDe)); | |
| 302 | + nuevos = mas ? r.items.filter(it => !ya.has(claveDe(it))) : r.items; | |
| 303 | + estado.items = mas ? estado.items.concat(nuevos) : r.items; | |
| 304 | + estado.total = mas && !r.items.length ? estado.items.length : r.total; | |
| 328 | 305 | } catch (e) { |
| 329 | 306 | if (e.name === 'AbortError') return; |
| 330 | 307 | aviso(textoError(e), true); |
| 331 | 308 | } finally { |
| 332 | - if (estado.ctl === ctl) { estado.cargando = false; pintaResultados(); } | |
| 309 | + if (estado.ctl === ctl) { | |
| 310 | + estado.cargando = false; | |
| 311 | + if (mas && $('ext-list')) { if (nuevos) añadeFilas(nuevos); pintaPie(); } else pintaResultados(); | |
| 312 | + } | |
| 313 | + } | |
| 314 | +} | |
| 315 | +const mostrandoPopulares = () => !estado.q && !estado.cat; | |
| 316 | + | |
| 317 | +// ── «Solo las que funcionan en Code» ── | |
| 318 | +// Lo que se sabe de cada resultado: true (funciona), false (no hace nada aquí), | |
| 319 | +// null (no se pudo leer su package.json: se enseña, sin veredicto). Sin | |
| 320 | +// entrada: todavía se está mirando. | |
| 321 | +const veredictos = new Map(); | |
| 322 | +function ponSolo(v) { | |
| 323 | + estado.solo = v; | |
| 324 | + guardaSolo(v); | |
| 325 | + const cb = $('ext-only-works'); | |
| 326 | + if (cb) cb.checked = v; | |
| 327 | + for (const row of document.querySelectorAll('#ext-list .ext-row')) filtraFila(row); | |
| 328 | + pintaPie(); | |
| 329 | +} | |
| 330 | +function filtraFila(row) { | |
| 331 | + const w = veredictos.get(row.dataset.key); | |
| 332 | + row.hidden = estado.solo && !row.dataset.popular && (w === undefined || w === false); | |
| 333 | +} | |
| 334 | +function cuentas() { | |
| 335 | + let pendientes = 0, ocultas = 0, visibles = 0; | |
| 336 | + for (const it of estado.items) { | |
| 337 | + const w = veredictos.get(claveDe(it)); | |
| 338 | + if (w === undefined) pendientes++; | |
| 339 | + else if (w === false) ocultas++; | |
| 340 | + else visibles++; | |
| 341 | + } | |
| 342 | + return { pendientes, ocultas, visibles: estado.solo ? visibles : estado.items.length }; | |
| 343 | +} | |
| 344 | +let piePendiente = false; | |
| 345 | +function programaPie() { | |
| 346 | + if (piePendiente) return; | |
| 347 | + piePendiente = true; | |
| 348 | + queueMicrotask(() => { piePendiente = false; pintaPie(); }); | |
| 349 | +} | |
| 350 | +// Debajo de la lista: cuántas se ocultaron (con «mostrar»), «comprobando…», | |
| 351 | +// «más resultados»; y si faltan filas para llenar la tanda, pide otra página. | |
| 352 | +function pintaPie() { | |
| 353 | + const pie = $('ext-foot'), ocultasBox = $('ext-hidden'); | |
| 354 | + if (!pie || !ocultasBox || mostrandoPopulares()) return; | |
| 355 | + const teniaFoco = pie.contains(document.activeElement) || ocultasBox.contains(document.activeElement); | |
| 356 | + const { pendientes, ocultas, visibles } = cuentas(); | |
| 357 | + const quedan = estado.items.length < estado.total; | |
| 358 | + ocultasBox.replaceChildren(); | |
| 359 | + ocultasBox.hidden = !(estado.solo && ocultas); | |
| 360 | + if (estado.solo && ocultas) { | |
| 361 | + ocultasBox.append(tx('hiddenN', { n: ocultas }) + ' · '); | |
| 362 | + const b = el('button', 'ext-link', tx('showHidden')); | |
| 363 | + b.type = 'button'; | |
| 364 | + b.id = 'ext-show-hidden'; | |
| 365 | + b.setAttribute('aria-label', tx('showHiddenNamed', { n: ocultas })); | |
| 366 | + b.onclick = () => { ponSolo(false); $('ext-only-works')?.focus(); }; | |
| 367 | + ocultasBox.appendChild(b); | |
| 368 | + } | |
| 369 | + // ¿llenar la tanda? solo con el filtro, cuando ya se sabe todo lo pedido | |
| 370 | + const llenando = estado.solo && !pendientes && visibles < estado.objetivo && quedan && !estado.cargando && estado.auto < MAX_AUTO; | |
| 371 | + pie.replaceChildren(); | |
| 372 | + if (estado.cargando || (estado.solo && pendientes) || llenando) pie.appendChild(el('div', 'muted ext-hint', tx(estado.solo ? 'checking' : 'searching'))); | |
| 373 | + else if (estado.solo && !visibles && estado.items.length) pie.appendChild(el('div', 'muted ext-hint', tx(quedan ? 'noneWorkYet' : 'noneWork', { n: estado.items.length }))); | |
| 374 | + if (!estado.cargando && !llenando && quedan) { | |
| 375 | + const mas = el('button', 'ghost ext-more', tx('more')); | |
| 376 | + mas.type = 'button'; | |
| 377 | + mas.id = 'ext-more'; | |
| 378 | + mas.onclick = () => { estado.objetivo = cuentas().visibles + POR_PAGINA; estado.auto = 0; busca_({ mas: true }); }; | |
| 379 | + pie.appendChild(mas); | |
| 380 | + if (teniaFoco) mas.focus(); | |
| 381 | + } else if (teniaFoco && !ocultasBox.contains(document.activeElement)) { | |
| 382 | + // el botón que tenía el foco ya no está: a la primera fila que se ve | |
| 383 | + ([...document.querySelectorAll('#ext-list .ext-row:not([hidden]) .ext-name')].pop() || $('ext-only-works'))?.focus(); | |
| 384 | + } | |
| 385 | + if (!pendientes && !estado.cargando) { | |
| 386 | + anunciaBusqueda(tx('results', { n: estado.total }) + (estado.solo && ocultas ? ' · ' + tx('hiddenN', { n: ocultas }) : '')); | |
| 387 | + } | |
| 388 | + if (llenando) { estado.auto++; busca_({ mas: true }); } | |
| 389 | +} | |
| 390 | + | |
| 391 | +// ── populares: una lista corta, ya comprobada (popular.json, generada por | |
| 392 | +// tests/ext_popular_build.mjs), que se pinta al instante y sin pedir nada a | |
| 393 | +// Open VSX: el veredicto de cada una va dentro ── | |
| 394 | +let populares = null, cargaPop = null; | |
| 395 | +function cargaPopulares() { | |
| 396 | + cargaPop ||= fetch(new URL('./popular.json', import.meta.url)).then(r => { if (!r.ok) throw new Error(String(r.status)); return r.json(); }) | |
| 397 | + .then(j => { populares = (j.items || []).map(p => ({ ...p, it: itemPopular(p) })); for (const p of populares) analisis.set(claveDe(p.it), Promise.resolve(p.analysis)); }) | |
| 398 | + .catch(e => { cargaPop = null; throw e; }); | |
| 399 | + return cargaPop; | |
| 400 | +} | |
| 401 | +function itemPopular(p) { | |
| 402 | + return { | |
| 403 | + namespace: p.namespace, name: p.name, version: p.version, displayName: p.displayName, | |
| 404 | + description: p.description?.[uiLang()] || p.description?.en || '', downloadCount: p.downloads || 0, verified: !!p.verified, icon: null, | |
| 405 | + }; | |
| 406 | +} | |
| 407 | +function pintaPopulares(res) { | |
| 408 | + if (!populares) { | |
| 409 | + res.appendChild(el('div', 'muted ext-hint', tx('searching'))); | |
| 410 | + cargaPopulares().then(() => { if (mostrandoPopulares()) pintaResultados(); }) | |
| 411 | + .catch(() => { if (mostrandoPopulares()) { res.replaceChildren(el('div', 'muted ext-hint', tx('popularFailed'))); } }); | |
| 412 | + return; | |
| 413 | + } | |
| 414 | + const h = el('div', 'sk-h', tx('popularH')); | |
| 415 | + h.id = 'ext-popular-h'; | |
| 416 | + res.append(h, el('p', 'muted ext-pop-note', tx('popularNote'))); | |
| 417 | + const lista = el('div', 'ext-list ext-popular'); | |
| 418 | + lista.id = 'ext-list'; | |
| 419 | + lista.setAttribute('aria-labelledby', 'ext-popular-h'); | |
| 420 | + const instaladas = new Map(host.list().map(e => [e.id, e])); | |
| 421 | + for (const p of populares) { | |
| 422 | + const row = filaResultado(p.it, instaladas.get(p.id.toLowerCase()), { kind: p.kind }); | |
| 423 | + row.dataset.popular = '1'; | |
| 424 | + lista.appendChild(row); | |
| 333 | 425 | } |
| 426 | + res.appendChild(lista); | |
| 427 | + anunciaBusqueda(tx('popularCount', { n: populares.length })); | |
| 334 | 428 | } |
| 335 | 429 | |
| 336 | 430 | function pintaResultados() { |
| 337 | 431 | const res = $('ext-results'); |
| 338 | 432 | if (!res) return; |
| 339 | 433 | res.replaceChildren(); |
| 434 | + if (mostrandoPopulares()) { pintaPopulares(res); return; } | |
| 340 | 435 | if (estado.cargando && !estado.items.length) { |
| 341 | 436 | res.appendChild(el('div', 'muted ext-hint', tx('searching'))); |
| 342 | 437 | anunciaBusqueda(tx('searching')); |
| @@ -351,13 +446,25 @@ | ||
| 351 | 446 | return; |
| 352 | 447 | } |
| 353 | 448 | res.appendChild(el('div', 'sk-h', estado.q ? tx('results', { n: estado.total }) : tx('popular'))); |
| 354 | - anunciaBusqueda(tx('results', { n: estado.total })); | |
| 449 | + const lista = el('div', 'ext-list'); | |
| 450 | + lista.id = 'ext-list'; | |
| 451 | + const ocultas = el('div', 'muted ext-hidden'); | |
| 452 | + ocultas.id = 'ext-hidden'; | |
| 453 | + ocultas.hidden = true; | |
| 454 | + const pie = el('div', 'ext-foot'); | |
| 455 | + pie.id = 'ext-foot'; | |
| 456 | + res.append(ocultas, lista, pie); | |
| 457 | + añadeFilas(estado.items); | |
| 458 | + pintaPie(); | |
| 459 | +} | |
| 460 | +function añadeFilas(items) { | |
| 461 | + const lista = $('ext-list'); | |
| 462 | + if (!lista) return; | |
| 355 | 463 | const instaladas = new Map(host.list().map(e => [e.id, e])); |
| 356 | - for (const it of estado.items) res.appendChild(filaResultado(it, instaladas.get(`${it.namespace}.${it.name}`.toLowerCase()))); | |
| 357 | - if (estado.items.length < estado.total) { | |
| 358 | - const mas = el('button', 'ghost ext-more', tx('more')); | |
| 359 | - mas.onclick = () => busca_({ mas: true }); | |
| 360 | - res.appendChild(mas); | |
| 464 | + for (const it of items) { | |
| 465 | + const row = filaResultado(it, instaladas.get(`${it.namespace}.${it.name}`.toLowerCase())); | |
| 466 | + filtraFila(row); | |
| 467 | + lista.appendChild(row); | |
| 361 | 468 | } |
| 362 | 469 | } |
| 363 | 470 | |
| @@ -417,9 +524,10 @@ | ||
| 417 | 524 | return v; |
| 418 | 525 | } |
| 419 | 526 | |
| 420 | -function filaResultado(it, instalada) { | |
| 527 | +function filaResultado(it, instalada, { kind = null } = {}) { | |
| 421 | 528 | const row = el('div', 'ext-row'); |
| 422 | 529 | row.dataset.id = `${it.namespace}.${it.name}`; |
| 530 | + row.dataset.key = claveDe(it); | |
| 423 | 531 | const main = el('div', 'ext-main'); |
| 424 | 532 | const det = el('div', 'ext-detail'); |
| 425 | 533 | det.id = 'ext-det-' + (++nDetalle); |
| @@ -433,6 +541,7 @@ | ||
| 433 | 541 | nombre.onclick = e => { e.stopPropagation(); detalle(it, det, nombre); }; |
| 434 | 542 | t.append(nombre, el('span', 'muted', ` ${it.namespace} · v${it.version}`)); |
| 435 | 543 | if (it.verified) t.appendChild(el('span', 'ext-badge', '✓')); |
| 544 | + if (kind) { row.dataset.kind = kind; t.appendChild(el('span', 'ext-kind ext-kind-' + kind, tx('kind_' + kind))); } | |
| 436 | 545 | main.append(t, el('div', 'ext-desc', it.description)); |
| 437 | 546 | main.appendChild(el('div', 'ext-verdict-slot')); |
| 438 | 547 | main.appendChild(el('div', 'ext-meta muted', tx('downloads', { n: it.downloadCount.toLocaleString() }))); |
| @@ -451,7 +560,10 @@ | ||
| 451 | 560 | b.onclick = e => { e.stopPropagation(); if (!esInerte(b)) instala(it, b); }; |
| 452 | 561 | acc.appendChild(b); |
| 453 | 562 | row.append(icono(it.icon, it.displayName), main, acc); |
| 454 | - analiza(it).then(a => pintaVeredictoFila(row, it, a, instalada)).catch(() => { /* sin veredicto: el botón de siempre */ }); | |
| 563 | + const k = claveDe(it); | |
| 564 | + analiza(it).then(a => { veredictos.set(k, works(pintaVeredictoFila(row, it, a, instalada))); }) | |
| 565 | + .catch(() => { if (!veredictos.has(k)) veredictos.set(k, null); }) // sin veredicto: el botón de siempre | |
| 566 | + .finally(() => { filtraFila(row); programaPie(); }); | |
| 455 | 567 | return row; |
| 456 | 568 | } |
| 457 | 569 |