Archived
- Recursive directory browsing with breadcrumb navigation - highlight.js syntax highlighting for code files (JS, JSON, CSS, HTML, Python, YAML, Bash, Markdown) - Dynamic projects tab parsing PROJECTS.md from workspace - Save feedback with success/error indicators - Dark theme support for text editor - File search filter on workspace tab - Android watchdog script for auto-restart - EADDRINUSE retry for Android socket TIME_WAIT - Fix nested file save paths (was dropping directory components) - Fix Shoelace component init with Alpine.js x-if - Default port changed to 3001
514 lines
18 KiB
HTML
514 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
<title>SmallClawViewer</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/dist/themes/light.css" />
|
|
<script type="module">
|
|
import { setBasePath } from 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/dist/utilities/base-path/index.js'
|
|
setBasePath('https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/dist/')
|
|
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/dist/components/button/button.js'
|
|
</script>
|
|
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/marked.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" />
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/json.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/xml.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/css.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/python.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/yaml.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/markdown.min.js"></script>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
:root {
|
|
--bg: #f4f4f6;
|
|
--surface: #ffffff;
|
|
--border: #e0e0e0;
|
|
--text: #1a1a1a;
|
|
--text-muted: #666;
|
|
--accent: #0d6efd;
|
|
}
|
|
|
|
[data-theme="dark"] {
|
|
--bg: #0d0d0d;
|
|
--surface: #1a1a1a;
|
|
--border: #2a2a2a;
|
|
--text: #e8e8e8;
|
|
--text-muted: #888;
|
|
--accent: #4dabf7;
|
|
}
|
|
|
|
[data-theme="rose"] {
|
|
--bg: #191724;
|
|
--surface: #1f1d2e;
|
|
--border: #403d52;
|
|
--text: #e0def4;
|
|
--text-muted: #6e6a86;
|
|
--accent: #c4a7e7;
|
|
}
|
|
[data-theme="rose"] body { background-color: var(--bg); color: var(--text); font-family: system-ui, sans-serif; }
|
|
[data-theme="rose"] .card { background-color: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 0.75rem; }
|
|
[data-theme="rose"] nav, [data-theme="rose"] header { background: var(--surface); border-color: var(--border); }
|
|
[data-theme="rose"] nav button.active { color: var(--accent); border-bottom-color: var(--accent); }
|
|
[data-theme="rose"] .file-item { border-bottom-color: var(--border); }
|
|
[data-theme="rose"] .file-item:hover { color: var(--accent); }
|
|
[data-theme="rose"] textarea.md-editor { background-color: var(--surface); color: var(--text); border-color: var(--border); }
|
|
[data-theme="rose"] .hint { color: var(--text-muted); }
|
|
[data-theme="rose"] sl-button::part(base) { background-color: var(--accent); color: var(--bg); border: none; }
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
:root:not([data-theme="light"]) {
|
|
--bg: #0d0d0d;
|
|
--surface: #1a1a1a;
|
|
--border: #2a2a2a;
|
|
--text: #e8e8e8;
|
|
--text-muted: #888;
|
|
--accent: #4dabf7;
|
|
}
|
|
}
|
|
|
|
html, body {
|
|
height: 100%;
|
|
font-family: system-ui, -apple-system, sans-serif;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
}
|
|
|
|
body { display: flex; flex-direction: column; }
|
|
|
|
header {
|
|
background: var(--surface);
|
|
border-bottom: 1px solid var(--border);
|
|
padding: 1rem;
|
|
text-align: center;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 10;
|
|
}
|
|
|
|
header h1 { font-size: 1.2rem; font-weight: 700; }
|
|
header p { font-size: 0.8rem; color: var(--text-muted); }
|
|
|
|
nav.main-nav {
|
|
display: flex;
|
|
background: var(--surface);
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
nav.main-nav button {
|
|
flex: 1;
|
|
padding: 0.875rem;
|
|
border: none;
|
|
background: none;
|
|
font-size: 0.9rem;
|
|
font-weight: 500;
|
|
color: var(--text-muted);
|
|
cursor: pointer;
|
|
border-bottom: 2px solid transparent;
|
|
}
|
|
|
|
nav.main-nav button.active {
|
|
color: var(--accent);
|
|
border-bottom-color: var(--accent);
|
|
}
|
|
|
|
nav.breadcrumb {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.25rem;
|
|
margin-bottom: 0.75rem;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
nav.breadcrumb a {
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
}
|
|
|
|
main {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 1rem;
|
|
max-width: 640px;
|
|
margin: 0 auto;
|
|
width: 100%;
|
|
}
|
|
|
|
.card {
|
|
background: var(--surface);
|
|
border-radius: 10px;
|
|
padding: 1rem;
|
|
margin-bottom: 0.75rem;
|
|
border: 1px solid var(--border);
|
|
}
|
|
|
|
.card h3 { font-size: 1rem; margin-bottom: 0.25rem; }
|
|
.card p { font-size: 0.85rem; color: var(--text-muted); }
|
|
|
|
.hint { color: var(--text-muted); font-size: 0.875rem; text-align: center; padding: 2rem 0; }
|
|
|
|
.search-input {
|
|
width: 100%;
|
|
padding: 0.5rem 0.75rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
font-size: 0.875rem;
|
|
background: var(--surface);
|
|
color: var(--text);
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
.search-input::placeholder { color: var(--text-muted); }
|
|
|
|
.file-tree { list-style: none; }
|
|
.file-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
|
|
.file-item:last-child { border-bottom: none; }
|
|
.file-item:hover { color: var(--accent); }
|
|
.file-item.folder { font-weight: 600; }
|
|
|
|
textarea.md-editor {
|
|
width: 100%;
|
|
min-height: 300px;
|
|
font-family: monospace;
|
|
font-size: 0.875rem;
|
|
padding: 0.75rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
resize: vertical;
|
|
background: var(--surface);
|
|
color: var(--text);
|
|
}
|
|
|
|
.hljs-block {
|
|
border-radius: 8px;
|
|
overflow: auto;
|
|
}
|
|
|
|
.hljs-block code.hljs {
|
|
font-size: 0.825rem;
|
|
line-height: 1.5;
|
|
padding: 0.75rem;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.code-label {
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
|
|
.btn-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
|
|
.notice { padding: 0.5rem 0; font-size: 0.85rem; }
|
|
.notice.saved { color: #22c55e; }
|
|
.notice.error { color: #ef4444; }
|
|
|
|
.back-btn {
|
|
margin-bottom: 1rem;
|
|
color: var(--accent);
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body x-data="app()">
|
|
|
|
<header style="display: flex; align-items: center; justify-content: center; position: relative;">
|
|
<button @click="toggleTheme" style="position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: 0.25rem; border-radius: 6px; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px;" :title="theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'">
|
|
<span x-text="theme === 'dark' ? 'Sun' : theme === 'rose' ? 'Leaf' : 'Moon'" style="line-height: 1;"></span>
|
|
</button>
|
|
<div style="text-align: center;">
|
|
<h1>SmallClawViewer</h1>
|
|
<p>Arvex workspace</p>
|
|
</div>
|
|
</header>
|
|
|
|
<nav class="main-nav">
|
|
<button :class="{ active: tab === 'projects' }" @click="tab = 'projects'">Projects</button>
|
|
<button :class="{ active: tab === 'workspace' }" @click="tab = 'workspace'">Workspace</button>
|
|
</nav>
|
|
|
|
<main>
|
|
<template x-if="tab === 'projects'">
|
|
<div class="projects-tab">
|
|
<p class="hint" x-show="projects.length === 0 && !projectsLoaded">Loading projects...</p>
|
|
<p class="hint" x-show="projects.length === 0 && projectsLoaded">No projects found</p>
|
|
<template x-for="project in projects" :key="project.name">
|
|
<div class="card" @click="selectProject(project)" style="cursor: pointer;">
|
|
<h3 x-text="project.name"></h3>
|
|
<p x-text="project.status"></p>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="tab === 'project-detail'">
|
|
<div class="project-detail">
|
|
<button class="back-btn" @click="tab = 'projects'">Back</button>
|
|
<div class="card">
|
|
<h3 x-text="selectedProject"></h3>
|
|
<p>Status: <span x-text="projectStatus"></span></p>
|
|
<p>Path: <code x-text="selectedProjectPath" style="font-size: 0.8rem;"></code></p>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="tab === 'workspace'">
|
|
<div class="workspace-tab">
|
|
<template x-if="!selectedFile">
|
|
<div>
|
|
<input class="search-input" type="text" placeholder="Search files..." x-model="searchQuery" />
|
|
<nav class="breadcrumb">
|
|
<template x-for="(crumb, i) in breadcrumb" :key="crumb.path">
|
|
<span style="display: inline-flex; align-items: center;">
|
|
<a href="#" @click.prevent="loadWorkspaceFiles(crumb.path)" x-text="crumb.name"></a>
|
|
<span x-show="i < breadcrumb.length - 1" style="color: var(--text-muted); margin: 0 0.25rem;"> / </span>
|
|
</span>
|
|
</template>
|
|
</nav>
|
|
<p class="hint" x-show="files.length === 0">Empty directory</p>
|
|
<ul class="file-tree">
|
|
<template x-for="f in filteredFiles" :key="f.path">
|
|
<li class="file-item" :class="{ folder: f.type === 'dir' }" @click="navigate(f)">
|
|
<span x-text="f.type === 'dir' ? '> ' + f.name : '~ ' + f.name"></span>
|
|
</li>
|
|
</template>
|
|
</ul>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="selectedFile">
|
|
<div>
|
|
<button class="back-btn" @click="closeFile">Back</button>
|
|
<div class="card">
|
|
<h3 x-text="selectedFile"></h3>
|
|
|
|
<template x-if="fileContent && !editing">
|
|
<div>
|
|
<div class="btn-row">
|
|
<sl-button size="small" @click="startEditing" x-show="canEdit">Edit</sl-button>
|
|
<sl-button size="small" variant="success" @click="closeFile">Close</sl-button>
|
|
</div>
|
|
<hr style="margin: 0.75rem 0; border: none; border-top: 1px solid var(--border);">
|
|
<div x-html="renderedContent"></div>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="editing">
|
|
<div>
|
|
<textarea class="md-editor" x-model="fileContent"></textarea>
|
|
<div class="btn-row">
|
|
<sl-button size="small" variant="success" @click="saveFile">Save</sl-button>
|
|
<sl-button size="small" @click="cancelEditing">Cancel</sl-button>
|
|
</div>
|
|
<p x-show="saved" class="notice saved">Saved!</p>
|
|
<p x-show="saveError" class="notice error" x-text="saveError"></p>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="!fileContent">
|
|
<p class="hint">Loading...</p>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</main>
|
|
|
|
<script>
|
|
function app() {
|
|
return {
|
|
tab: 'projects',
|
|
projects: [],
|
|
projectsLoaded: false,
|
|
selectedProject: null,
|
|
projectStatus: 'loading',
|
|
selectedProjectPath: '',
|
|
files: [],
|
|
searchQuery: '',
|
|
|
|
currentDir: '',
|
|
selectedFile: null,
|
|
fileContent: null,
|
|
editing: false,
|
|
saved: false,
|
|
saveError: null,
|
|
theme: localStorage.getItem('scv-theme') || 'auto',
|
|
|
|
async init() {
|
|
this.applyTheme()
|
|
await this.loadProjects()
|
|
await this.loadWorkspaceFiles()
|
|
},
|
|
|
|
async loadProjects() {
|
|
try {
|
|
const res = await fetch('/api/projects')
|
|
this.projects = await res.json()
|
|
} catch (e) {
|
|
this.projects = []
|
|
}
|
|
this.projectsLoaded = true
|
|
},
|
|
|
|
get breadcrumb() {
|
|
if (!this.currentDir) return [{ name: 'workspace', path: '' }]
|
|
const parts = this.currentDir.split('/')
|
|
const crumbs = [{ name: 'workspace', path: '' }]
|
|
parts.forEach((p, i) => {
|
|
crumbs.push({ name: p, path: parts.slice(0, i + 1).join('/') })
|
|
})
|
|
return crumbs
|
|
},
|
|
|
|
async loadWorkspaceFiles(dir) {
|
|
const query = dir ? '?dir=' + encodeURIComponent(dir) : ''
|
|
try {
|
|
const res = await fetch('/api/files' + query)
|
|
this.files = await res.json()
|
|
this.currentDir = dir || ''
|
|
} catch (e) {
|
|
this.files = [{ name: 'workspace', type: 'dir', path: '.' }]
|
|
this.currentDir = ''
|
|
}
|
|
},
|
|
|
|
async selectProject(project) {
|
|
this.selectedProject = typeof project === 'string' ? project : project.name
|
|
this.projectStatus = typeof project === 'string' ? 'active' : project.status
|
|
this.selectedProjectPath = typeof project === 'string' ? '' : project.path
|
|
this.tab = 'project-detail'
|
|
},
|
|
|
|
async navigate(f) {
|
|
if (f.type === 'dir') {
|
|
await this.loadWorkspaceFiles(f.path)
|
|
return
|
|
}
|
|
this.selectedFile = f.path
|
|
this.editing = false
|
|
await this.loadFile(f.path)
|
|
},
|
|
|
|
async loadFile(path) {
|
|
try {
|
|
const res = await fetch('/api/file/' + encodeURIComponent(path))
|
|
this.fileContent = await res.text()
|
|
} catch (e) {
|
|
this.fileContent = 'Error loading file.'
|
|
}
|
|
},
|
|
|
|
closeFile() {
|
|
this.selectedFile = null
|
|
this.editing = false
|
|
this.fileContent = null
|
|
},
|
|
|
|
startEditing() {
|
|
this.editing = true
|
|
},
|
|
|
|
cancelEditing() {
|
|
this.editing = false
|
|
this.saved = false
|
|
this.saveError = null
|
|
},
|
|
|
|
async saveFile() {
|
|
try {
|
|
const res = await fetch('/api/file/' + encodeURIComponent(this.selectedFile), {
|
|
method: 'PUT',
|
|
body: this.fileContent
|
|
})
|
|
const result = await res.json()
|
|
if (result.ok) {
|
|
this.saved = true
|
|
setTimeout(() => this.saved = false, 2000)
|
|
} else {
|
|
this.saveError = 'Save failed'
|
|
}
|
|
} catch (e) {
|
|
this.saveError = 'Save failed'
|
|
}
|
|
this.editing = false
|
|
},
|
|
|
|
get isMarkdown() {
|
|
return this.selectedFile && this.selectedFile.endsWith('.md')
|
|
},
|
|
|
|
get canEdit() {
|
|
if (!this.selectedFile) return false
|
|
const ext = this.selectedFile.split('.').pop().toLowerCase()
|
|
return ['md', 'txt', 'js', 'html', 'css', 'json', 'yml', 'yaml', 'toml', 'xml', 'py', 'sh', 'bash', 'log'].includes(ext)
|
|
},
|
|
|
|
get hljsLanguage() {
|
|
if (!this.selectedFile) return null
|
|
const ext = this.selectedFile.split('.').pop().toLowerCase()
|
|
const map = {
|
|
js: 'javascript', mjs: 'javascript', ts: 'javascript',
|
|
json: 'json', html: 'xml', htm: 'xml', xml: 'xml', svg: 'xml',
|
|
css: 'css', py: 'python', sh: 'bash', bash: 'bash',
|
|
yml: 'yaml', yaml: 'yaml',
|
|
}
|
|
return map[ext] || null
|
|
},
|
|
|
|
get renderedContent() {
|
|
if (!this.fileContent) return ''
|
|
if (this.isMarkdown) {
|
|
try { return marked.parse(this.fileContent) } catch { return this.fileContent }
|
|
}
|
|
const lang = this.hljsLanguage
|
|
if (lang && typeof hljs !== 'undefined') {
|
|
try {
|
|
const highlighted = hljs.highlight(this.fileContent, { language: lang, ignoreIllegals: true }).value
|
|
return '<div class="code-label">' + lang + '</div><div class="hljs-block"><pre><code class="hljs language-' + lang + '">' + highlighted + '</code></pre></div>'
|
|
} catch (e) {
|
|
// language not available, fall through to plain text
|
|
}
|
|
}
|
|
return '<pre style="white-space: pre-wrap; word-break: break-all; font-family: monospace; font-size: 0.8rem;">' + this.escapeHtml(this.fileContent) + '</pre>'
|
|
},
|
|
|
|
get filteredFiles() {
|
|
const q = this.searchQuery.toLowerCase()
|
|
if (!q) return this.files
|
|
return this.files.filter(f => f.name.toLowerCase().includes(q) || f.path.toLowerCase().includes(q))
|
|
},
|
|
|
|
escapeHtml(text) {
|
|
const map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }
|
|
return text.replace(/[&<>"']/g, c => map[c])
|
|
},
|
|
|
|
toggleTheme() {
|
|
const themes = ['light', 'dark', 'rose', 'auto']
|
|
const currentIndex = themes.indexOf(this.theme)
|
|
this.theme = themes[(currentIndex + 1) % themes.length]
|
|
localStorage.setItem('scv-theme', this.theme)
|
|
this.applyTheme()
|
|
},
|
|
|
|
applyTheme() {
|
|
if (this.theme === 'auto') {
|
|
document.documentElement.removeAttribute('data-theme')
|
|
} else {
|
|
document.documentElement.setAttribute('data-theme', this.theme === 'rose' ? 'rose' : this.theme)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|