From a47462c0b170ea27da1cac698135521c63cd8135 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Tue, 24 Nov 2026 18:36:22 +0100 Subject: [PATCH 1/2] Rebuild the detail page's shell to the design Phase 33 slice C. The toolbar is a back link to the project, the name and size, the states as a nav of links, breakpoint tabs by canvas type, Comment, a More menu and a Live status. View JSON, Copy canvas ID, Archive or Restore and Delete live in the menu, and Delete confirms in a dialog. The preview opens fitted to the pane with zoom steps, and the preview theme and safe area are tools beside the zoom. --- VISION.md | 2 +- docs/specs/PHASE-33-SPEC.md | 7 + src/viewer/client/detail.ts | 163 +++++++++---- src/viewer/components.ts | 7 +- src/viewer/pages/detail.ts | 248 +++++++++++--------- test/browser/test-viewer-compare.ts | 20 +- test/browser/test-viewer-detail.ts | 155 ++++++++++++ test/browser/test-viewer-surface-browser.ts | 14 +- test/unit/test-archive-view.ts | 14 +- test/unit/test-desktop-app.ts | 2 +- test/unit/test-variants.ts | 7 +- test/unit/test-viewer-surface.ts | 8 +- 12 files changed, 448 insertions(+), 199 deletions(-) create mode 100644 test/browser/test-viewer-detail.ts diff --git a/VISION.md b/VISION.md index e1814ec..490ac55 100644 --- a/VISION.md +++ b/VISION.md @@ -601,7 +601,7 @@ Phase 31 rebuilt the viewer as canvases and left the code alone. A design pass o - [x] Slice A — foundation: `src/viewer/` modules, tokens copied from the design system and pinned by a test, chrome that follows the system's light or dark setting, fonts served from the cache, one sidebar, tabs, menu and dialog used everywhere - [x] Slice B — gallery: thumbnail cards with a score chip against the bar, search and type filter kept in the URL, a live status, and refresh on every edit -- [ ] Slice C — detail shell: toolbar with state tabs, a More menu (JSON, copy ID, archive, delete), a delete dialog, and preview tools (zoom, fit, preview theme, safe area) +- [x] Slice C — detail shell: toolbar with state tabs, a More menu (JSON, copy ID, archive, delete), a delete dialog, and preview tools (zoom, fit, preview theme, safe area) - [ ] Slice D — inspector and comments: the Quality tab sorted lowest first with a reason line, Design system and Feedback restyled, the Import placeholder removed, the comment popover, and panels that refresh live - [ ] Slice E — archive, docs and acceptance: the archive tree with a preview panel, README and screenshots, and each screen beside its design - [ ] Follow-up — the viewer sends `Access-Control-Allow-Origin: *` on every response, the routes that archive, delete and post comments included. It listens on 127.0.0.1 only, but a page open in the same browser can still send it a simple cross-origin POST (archive, unarchive, add or resolve a comment) without a preflight. Drop the header from mutating routes, reject requests whose `Origin` is not the viewer's own, and test both; a separate change from the visual port diff --git a/docs/specs/PHASE-33-SPEC.md b/docs/specs/PHASE-33-SPEC.md index f062f9f..5b0bac6 100644 --- a/docs/specs/PHASE-33-SPEC.md +++ b/docs/specs/PHASE-33-SPEC.md @@ -139,6 +139,13 @@ Its design system is the project's: seed `#B45309`, personality `technical`, 14p **Slice C — detail shell.** `pages/detail.ts` toolbar, More menu, delete dialog, preview tools, caption and JSON panel (FR-C1 to FR-C4). Tests rewritten: `test-archive-view.ts` (its `btn-archive`, `btn-restore`, `btn-delete` and `lifecycleAction` assertions), `test-viewer-surface.ts` (device frame and breakpoint strings), `test-desktop-app.ts:260-266` (its `bp-w1024`, `bp-w1280`, `bp-desktop` ids and `bp-btn` count), `test-variants.ts:88-98` (the detail page's state chips become the States nav), `test/browser/test-viewer-compare.ts`, `test/browser/test-viewer-surface-browser.ts` (`.bp-btn` becomes the tab selector). New: `test/browser/test-viewer-detail.ts`. The `src/viewer.ts` re-export keeps every name tests import, `evalCacheKey` included (`test-dual-theme.ts`, `test-viewer-perf.ts`, `test/e2e/test-surface.ts`). +**Slice C — as built.** +- **C1: the breakpoint tabs have no inline handler.** The shared tab code selects on click and arrow keys and fires `tabchange`; the page switches the preview from each tab's `data-w` and `data-h`. An inline `onclick` as well would switch twice on a click and not at all on a key. +- **C2: a menu item can keep the menu open.** `renderMenu` items take `keepOpen`, so Copy canvas ID can say "Copied" in place; every other item closes the menu as FR-A4 says. The copy falls back to `execCommand('copy')` where the clipboard API is refused. +- **C3: fit is by width.** The fitted scale fills the pane's width (never above 100%); a tall artboard scrolls. The stage reports its scale and mode in `data-scale` and `data-mode`. +- **C4: the crumbs give way in order.** In a crowded toolbar the provenance and critique chips shrink first, then the title (it carries the full name as a tooltip); the back link, the size and the state nav keep their width. At 1100px or less the two chips hide. +- **C5: the JSON panel is an overlay** under the toolbar with its own Close button, and it is still refreshed on every content change while open. + **Slice D — inspector and comments.** The Quality tab (FR-D1), the restyled Design system and Feedback tabs and the removed Import tab (FR-D2), the comment popover (FR-D3), and the live inspector with its route and `feedbackKey` (FR-D4). Tests rewritten: `test-viewer-panels.ts` (inspector selectors), `test-viewer-feedback.ts` (`data-tab="feedback"`, `btn-comment`, `FB_INIT`), `test-eval-cache-key.ts:104` (it reads the provenance chip from the toolbar; the chip moves into the Quality tab). New: `test/browser/test-viewer-inspector.ts`, with an MCP-driven check of FR-D4 in `test/e2e/`. **Slice E — archive, docs, acceptance.** `pages/archive.ts` (FR-E1, FR-E2), docs and screenshots (FR-E3), and the side-by-side acceptance (FR-E4). Tests rewritten: `test-archive-view.ts` (archive page half). `test/manual/test-viewer.ts` and `test-viewer-navbar.ts` follow the new markup. New: `test/browser/test-viewer-archive.ts`. diff --git a/src/viewer/client/detail.ts b/src/viewer/client/detail.ts index bb967ed..fed8d3e 100644 --- a/src/viewer/client/detail.ts +++ b/src/viewer/client/detail.ts @@ -5,9 +5,11 @@ import { listFeedback } from '../../feedback.js'; import { evalCacheKey } from '../scores.js'; import { buildNodeIndex, scriptJson } from '../shared.js'; import { LIGHT } from '../tokens.js'; +import { COMPONENTS_JS } from '../components.js'; export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: string): string { return ` + ${COMPONENTS_JS} const canvasId = ${scriptJson(canvas.id)}; // Outlines drawn inside the canvas iframe, which cannot read the page's CSS variables. const HIGHLIGHT = ${scriptJson(LIGHT.colors.accent)}; @@ -24,12 +26,19 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: const FB_INIT = ${scriptJson(listFeedback(canvas, { includeResolved: true }))}; const NODE_INDEX = ${scriptJson(buildNodeIndex(canvas.root))}; - // Auto-refresh polling + // Auto-refresh polling, and the Live / Offline status (FR-C1). + const liveEl = document.getElementById('live'); + const setLive = (ok) => { + if (!liveEl) return; + liveEl.classList.toggle('offline', !ok); + liveEl.querySelector('.live-label').textContent = ok ? 'Live' : 'Offline'; + }; setInterval(async () => { try { - const res = await fetch('/api/canvas/' + canvasId + '/meta'); + const res = await fetch('/api/canvas/' + canvasId + '/meta', { cache: 'no-store' }); + if (!res.ok) throw new Error(String(res.status)); const meta = await res.json(); - document.getElementById('status').className = 'status'; + setLive(true); // contentKey catches edits that never bump lastModified (issue #150). if (meta.lastModified !== lastModified || (meta.contentKey && meta.contentKey !== contentKey)) { if (meta.type !== pageShape.type || (meta.width ?? null) !== pageShape.width || (meta.height ?? null) !== pageShape.height || JSON.stringify(meta.safeArea ?? null) !== pageShape.safeArea) { @@ -39,11 +48,10 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: lastModified = meta.lastModified; contentKey = meta.contentKey || contentKey; refreshFrames(); - // Update JSON if panel is open - if (document.getElementById('json-panel').classList.contains('open')) loadJson(); + if (!document.getElementById('json-panel').hidden) loadJson(); } } catch { - document.getElementById('status').className = 'status stale'; + setLive(false); } }, 2000); @@ -52,7 +60,12 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: function toggleTheme() { themeMode = themeMode === 'light' ? 'dark' : 'light'; const btn = document.getElementById('theme-toggle'); - if (btn) { btn.textContent = themeMode === 'light' ? 'Dark' : 'Light'; btn.classList.toggle('active', themeMode === 'dark'); } + if (btn) { + btn.setAttribute('aria-pressed', themeMode === 'dark' ? 'true' : 'false'); + const label = themeMode === 'dark' ? 'Preview in light' : 'Preview in dark'; + btn.setAttribute('aria-label', label); + btn.title = label; + } document.querySelectorAll('iframe').forEach((frame) => { const u = new URL(frame.src, location.href); if (themeMode === 'dark') u.searchParams.set('theme', 'dark'); @@ -68,7 +81,8 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: url.searchParams.set('t', t); frame.src = url.toString(); }; - if (document.getElementById('viewport').classList.contains('compare')) { + const vp = document.getElementById('viewport'); + if (vp && vp.classList.contains('compare')) { document.querySelectorAll('.compare-cell iframe').forEach(bump); } else { bump(document.getElementById('frame')); @@ -78,58 +92,91 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: const canvasW = ${scriptJson(w)}; const canvasH = ${scriptJson(h)}; + // FR-C4 — the preview scales with a transform: fit (never above 100%) by + // default, or a zoom step. The box takes the scaled size, so the pane + // scrolls over it when the preview is larger than the pane. + const ZOOM_STEPS = [0.5, 0.75, 1, 1.5, 2]; + let bpW = canvasW, bpH = canvasH, zoom = null; // null = fit + function fitScale() { + const vp = document.getElementById('viewport'); + const style = getComputedStyle(vp); + const room = vp.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight) - 2; + return Math.max(0.05, Math.min(1, room / bpW)); + } + function applyScale() { + const box = document.getElementById('frame-box'); + const frame = document.getElementById('frame'); + if (!box || !frame) return; + const scale = zoom ?? fitScale(); + box.style.width = Math.round(bpW * scale) + 'px'; + box.style.height = Math.round(bpH * scale) + 'px'; + frame.style.width = bpW + 'px'; + frame.style.height = bpH + 'px'; + frame.style.transform = 'scale(' + scale + ')'; + document.getElementById('stage').dataset.scale = scale.toFixed(4); + document.getElementById('stage').dataset.mode = zoom === null ? 'fit' : 'zoom'; + } + function zoomBy(dir) { + const current = zoom ?? fitScale(); + const next = dir > 0 ? ZOOM_STEPS.find((s) => s > current + 1e-6) : [...ZOOM_STEPS].reverse().find((s) => s < current - 1e-6); + if (next === undefined) return; + zoom = next; + applyScale(); + } + function fitPreview() { zoom = null; applyScale(); } + function setZoomTools(enabled) { + ['btn-zoom-in', 'btn-zoom-out', 'btn-fit'].forEach((id) => { const b = document.getElementById(id); if (b) b.disabled = !enabled; }); + } + window.addEventListener('resize', () => { if (zoom === null) applyScale(); }); + applyScale(); + + function selectBp(bp) { + document.querySelectorAll('.bp-btn').forEach((b) => { + const on = b.id === 'bp-' + bp; + b.setAttribute('aria-selected', on ? 'true' : 'false'); + b.tabIndex = on ? 0 : -1; + }); + currentBp = bp; + } + function setViewport(w, h, bp) { const frame = document.getElementById('frame'); const vp = document.getElementById('viewport'); - vp.classList.remove('fit', 'compare'); - document.getElementById('btn-fit').classList.remove('active'); - - // Reload iframe at the new viewport size so content reflows + vp.classList.remove('compare'); + bpW = w; bpH = h; zoom = null; frame.width = w; frame.height = h; - frame.style.transform = ''; - frame.style.maxWidth = ''; - frame.style.maxHeight = ''; - frame.style.width = ''; - frame.style.height = ''; - frame.style.overflow = ''; frame.src = '/canvas/' + canvasId + '/html?w=' + w + '&h=' + h + (themeMode === 'dark' ? '&theme=dark' : '') + '&t=' + Date.now(); - - // The pressed button is the active breakpoint; other toolbar state stays. - document.querySelectorAll('.bp-btn').forEach(b => b.classList.remove('active')); - document.getElementById('bp-' + bp).classList.add('active'); - currentBp = bp; + setZoomTools(true); + applyScale(); + selectBp(bp); } function setCompareMode() { - const vp = document.getElementById('viewport'); - vp.classList.remove('fit'); - vp.classList.add('compare'); - document.getElementById('btn-fit').classList.remove('active'); - document.querySelectorAll('.bp-btn').forEach(b => b.classList.remove('active')); - document.getElementById('bp-compare').classList.add('active'); - currentBp = 'compare'; + document.getElementById('viewport').classList.add('compare'); + setZoomTools(false); + selectBp('compare'); } + // The breakpoint tabs fire "tabchange" (click or arrow keys, COMPONENTS_JS). + const bpTabs = document.querySelector('.bp-tabs'); + if (bpTabs) bpTabs.addEventListener('tabchange', (e) => { + const tab = document.getElementById('bp-' + e.detail.tab); + if (e.detail.tab === 'compare') setCompareMode(); + else setViewport(Number(tab.dataset.w), Number(tab.dataset.h), e.detail.tab); + }); + function toggleSafeArea() { const overlay = document.getElementById('safe-overlay'); overlay.hidden = !overlay.hidden; - document.getElementById('btn-safe').classList.toggle('active', !overlay.hidden); - } - - function toggleFit() { - const vp = document.getElementById('viewport'); - const btn = document.getElementById('btn-fit'); - vp.classList.toggle('fit'); - btn.classList.toggle('active'); + document.getElementById('btn-safe').setAttribute('aria-pressed', overlay.hidden ? 'false' : 'true'); } - function toggleJson() { + function toggleJson(force) { const panel = document.getElementById('json-panel'); - const btn = document.getElementById('btn-json'); - panel.classList.toggle('open'); - btn.classList.toggle('active'); - if (panel.classList.contains('open')) loadJson(); + const open = typeof force === 'boolean' ? force : panel.hidden; + panel.hidden = !open; + if (open) loadJson(); } async function loadJson() { @@ -142,11 +189,10 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: } } - // Archive / unarchive / delete. Delete is irreversible — confirm first. - // After action: archive / unarchive bounce back to the project page; - // delete bounces too (the canvas is gone, no point staying on its page). + // Archive / restore / delete. Delete confirms in the dialog first (FR-C3); + // afterwards the canvas page has nothing to show, so go to the project. async function lifecycleAction(action) { - if (action === 'delete' && !confirm('Permanently delete this canvas? This cannot be undone.')) return; + if (action === 'delete' && !(await fsDialog.open('delete-dialog'))) return; const projectId = ${scriptJson(canvas.projectId)}; try { const url = '/api/canvas/' + canvasId + (action === 'archive' ? '/archive' : action === 'unarchive' ? '/unarchive' : ''); @@ -159,6 +205,29 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: } } + // FR-C2 — the More menu. + async function copyCanvasId(item) { + let ok = false; + try { await navigator.clipboard.writeText(canvasId); ok = true; } catch { + const field = document.createElement('textarea'); + field.value = canvasId; field.setAttribute('readonly', ''); field.style.position = 'fixed'; field.style.opacity = '0'; + document.body.appendChild(field); field.select(); + try { ok = document.execCommand('copy'); } catch {} + field.remove(); + } + const label = item.querySelector('span'); + const before = label.textContent; + label.textContent = ok ? 'Copied' : 'Copy failed'; + setTimeout(() => { label.textContent = before; }, 2000); + } + const moreMenu = document.querySelector('[data-menu="more-menu"]'); + if (moreMenu) moreMenu.addEventListener('menuaction', (e) => { + const action = e.detail.action; + if (action === 'json') toggleJson(true); + else if (action === 'copy') copyCanvasId(moreMenu.querySelector('[data-action="copy"]')); + else lifecycleAction(action); + }); + // ── Phase 21 — point-and-tell feedback ───────────────────────────────── // Pane renderer: cards are built with DOM APIs (never innerHTML from user // text) so comment content can't inject markup. diff --git a/src/viewer/components.ts b/src/viewer/components.ts index 08ce0ab..076c568 100644 --- a/src/viewer/components.ts +++ b/src/viewer/components.ts @@ -81,7 +81,7 @@ export function renderTabs(tabs: TabSpec[], label: string): string { return `
${buttons}
`; } -export type MenuItemSpec = { action: string; label: string; icon?: string; danger?: boolean } | 'separator'; +export type MenuItemSpec = { action: string; label: string; icon?: string; danger?: boolean; keepOpen?: boolean } | 'separator'; /** A menu behind a button: Up and Down move, Enter activates, Escape and an * outside click close it and return focus (COMPONENTS_JS). Choosing an item @@ -89,7 +89,7 @@ export type MenuItemSpec = { action: string; label: string; icon?: string; dange export function renderMenu(id: string, buttonHtml: string, buttonLabel: string, items: MenuItemSpec[]): string { const rows = items.map((item) => item === 'separator' ? '' - : ``).join(''); + : ``).join(''); return `