import { html, nothing } from 'lit'; import { FileViewerBase } from './shared/file-viewer-base.js'; const PAGE_ID = 'file_viewer'; function pathFromHash() { const h = location.hash; const prefix = `#${PAGE_ID}?path=`; if (!h.startsWith(prefix)) return null; try { return decodeURIComponent(h.slice(prefix.length)); } catch { return null; } } /** * Desktop file-viewer page. Self-routes off the hash (`#file_viewer?path=...`): * the sidebar's `llm-page-change` event toggles visibility and `hashchange` * re-loads. All fetch/render/watch logic lives in `FileViewerBase`; this * subclass only adds the desktop chrome and the hash wiring. */ export class FileViewerPage extends FileViewerBase { static properties = { _open: { state: true }, }; constructor() { super(); this._open = false; } connectedCallback() { super.connectedCallback(); window.addEventListener('llm-page-change', (e) => { this._open = e.detail.page === PAGE_ID; this.style.display = this._open ? 'flex' : 'none'; if (this._open) this._loadFromHash(); else this._hide(); }); window.addEventListener('hashchange', () => { if (this._open) this._loadFromHash(); }); } _loadFromHash() { const path = pathFromHash(); if (path) this._show(path); } _back() { history.back(); } render() { if (!this._open) return nothing; return html`

${this._path ?? ''}

${this._renderModeToggle('btn btn-sm btn-outline-secondary fv-download-btn')}
${this._renderBody()}
`; } }