Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(ui): Files parity - syntax-tinted preview + quick access (S8.5)

Juan Denisad2d3015cb48
diff --git a/docs/REDESIGN_MAP.md b/docs/REDESIGN_MAP.md
index d9f3fd2c..a9fcc80d 100644
--- a/docs/REDESIGN_MAP.md
+++ b/docs/REDESIGN_MAP.md
@@ -292,10 +292,13 @@ win: host the existing SSH/xterm console (RemoteTerminal is built but unmounted)
largest-tables + gauge bars (no table-size endpoint), response-time chart, referrers/devices bars,
FilesDrawer w/ code viewer.
-### 8.5 Files — high parity; 3 visible gaps
-Syntax-highlighted preview (`PreviewDrawer.jsx:113` plain textarea vs `.pv-code` tokens — the planned
-`file-manager/highlight.js`), **Quick-access rail group** (Sites/Stack/Web config/Logs shortcuts), topbar
-subtitle (source host/OS). Cosmetic: breadcrumb `›` icons vs demo mono `/`, ext-badge hidden until hover.
+### 8.5 Files — ✅ **done 2026-06-11**
+Shipped: **`file-manager/highlight.js`** (the demo's `hlCode` line tinting — kw/str/num/cmt/var tokens; PHP/JS
+keywords; escapes before inserting markup) rendered as `.pv-code` (line-number gutter on `--bg-code`) in the
+PreviewDrawer's read view — editing keeps the textarea, files >4000 lines fall back to plain; **Quick-access
+rail group** (Sites `/var/www`, Stack `/opt/serverkit`, Web config `/etc/nginx`, Logs `/var/log`); topbar
+`meta` shows the browse target (remote agent name / "panel host"); breadcrumb `›` icons → demo mono `/`;
+ext-badge on image thumbs now always visible.
### 8.6 Docker — close; 4 small items
KPI icon tone-wash not applying (verify `.sk-kpi__icon--*` rules actually color the lucide SVG), per-container
diff --git a/frontend/src/components/file-manager/PreviewDrawer.jsx b/frontend/src/components/file-manager/PreviewDrawer.jsx
index f0d69785..5f22f9da 100644
--- a/frontend/src/components/file-manager/PreviewDrawer.jsx
+++ b/frontend/src/components/file-manager/PreviewDrawer.jsx
@@ -4,6 +4,11 @@ import { Button } from '@/components/ui/button';
import FileIcon from './FileIcon';
import ImageThumb from './ImageThumb';
import { getFileType } from './fileTypes';
+import { highlightLine, fileExt } from './highlight';
+
+// Above this the highlighted view would render too many DOM nodes — fall back
+// to the plain read-only textarea.
+const MAX_HIGHLIGHT_LINES = 4000;
export default function PreviewDrawer({
file,
@@ -129,13 +134,43 @@ export default function PreviewDrawer({
)}
</div>
</div>
- <textarea
- className="file-editor"
- value={fileContent}
- onChange={(e) => setFileContent(e.target.value)}
- readOnly={!editing}
- spellCheck={false}
- />
+ {(() => {
+ if (editing) {
+ return (
+ <textarea
+ className="file-editor"
+ value={fileContent}
+ onChange={(e) => setFileContent(e.target.value)}
+ spellCheck={false}
+ />
+ );
+ }
+ const lines = (fileContent ?? '').split('\n');
+ if (lines.length > MAX_HIGHLIGHT_LINES) {
+ return (
+ <textarea
+ className="file-editor"
+ value={fileContent}
+ readOnly
+ spellCheck={false}
+ />
+ );
+ }
+ const ext = fileExt(file.name);
+ return (
+ <div className="pv-code" aria-label="File contents">
+ {lines.map((l, i) => (
+ <div className="pv-code__line" key={i}>
+ <span className="pv-code__n">{i + 1}</span>
+ <span
+ className="pv-code__c"
+ dangerouslySetInnerHTML={{ __html: highlightLine(l, ext) || '&nbsp;' }}
+ />
+ </div>
+ ))}
+ </div>
+ );
+ })()}
</div>
) : (
<div className="preview-unavailable">
diff --git a/frontend/src/components/file-manager/highlight.js b/frontend/src/components/file-manager/highlight.js
new file mode 100644
index 00000000..81caf8ed
--- /dev/null
+++ b/frontend/src/components/file-manager/highlight.js
@@ -0,0 +1,35 @@
+// Lightweight line-based syntax tinting for the file preview (prototype
+// `hlCode`). Not a parser — just enough token color for config/code files.
+// Input is escaped before any markup is inserted, so the produced HTML only
+// ever contains our own token spans.
+
+const HASH_COMMENT_EXTS = ['sh', 'bash', 'yml', 'yaml', 'ini', 'env', 'conf', 'caddy', 'toml', 'md', 'cfg'];
+const SLASH_COMMENT_EXTS = ['php', 'js', 'jsx', 'ts', 'tsx', 'css', 'scss', 'json'];
+const JS_EXTS = ['js', 'jsx', 'ts', 'tsx', 'mjs'];
+
+function esc(s) {
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+}
+
+export function highlightLine(line, ext) {
+ let h = esc(line);
+ if (HASH_COMMENT_EXTS.includes(ext) && /^\s*#/.test(line)) return `<span class="tok-cmt">${h}</span>`;
+ if (SLASH_COMMENT_EXTS.includes(ext) && /^\s*(\/\/|\/\*|\*)/.test(line)) return `<span class="tok-cmt">${h}</span>`;
+
+ h = h.replace(/("[^"]*"|'[^']*')/g, '<span class="tok-str">$1</span>');
+ h = h.replace(/\b(\d+(?:\.\d+)?[A-Za-z]*)\b/g, '<span class="tok-num">$1</span>');
+
+ if (ext === 'php') {
+ h = h.replace(/\b(define|require_once|require|include|getenv|defined|function|return|if|else|new|echo|use|namespace|class|public|private|protected|static)\b/g, '<span class="tok-kw">$1</span>');
+ h = h.replace(/(\$\w+)/g, '<span class="tok-var">$1</span>');
+ h = h.replace(/(&lt;\?php)/g, '<span class="tok-kw">$1</span>');
+ } else if (JS_EXTS.includes(ext)) {
+ h = h.replace(/\b(const|let|var|function|return|if|else|new|import|export|from|default|async|await|class|typeof|throw|try|catch)\b/g, '<span class="tok-kw">$1</span>');
+ }
+ return h;
+}
+
+export function fileExt(name) {
+ const i = (name || '').lastIndexOf('.');
+ return i > 0 ? name.slice(i + 1).toLowerCase() : '';
+}
diff --git a/frontend/src/pages/FileManager.jsx b/frontend/src/pages/FileManager.jsx
index abd70ab9..da708360 100644
--- a/frontend/src/pages/FileManager.jsx
+++ b/frontend/src/pages/FileManager.jsx
@@ -9,7 +9,7 @@ import {
Download, Edit3, Trash2, ChevronDown, ChevronRight,
HardDrive, Clock, PanelLeftClose, PanelLeftOpen,
LayoutGrid, List, Home, CloudUpload,
- Check, Copy, ArrowUpDown,
+ Check, Copy, ArrowUpDown, Zap, Globe, Boxes, SlidersHorizontal, FileText,
FolderTree as FolderTreeIcon,
} from 'lucide-react';
import { useSearchParams } from 'react-router-dom';
@@ -27,6 +27,15 @@ import ContextMenu from '../components/file-manager/ContextMenu';
import TargetPicker from '../components/TargetPicker';
import { TREE_ROOTS, getFileType, formatBytes } from '../components/file-manager/fileTypes';
+// Demo rail shortcuts (Quick access) — one-click jumps to the paths people
+// actually visit on a ServerKit host.
+const QUICK_ACCESS = [
+ { label: 'Sites', path: '/var/www', icon: Globe },
+ { label: 'Stack', path: '/opt/serverkit', icon: Boxes },
+ { label: 'Web config', path: '/etc/nginx', icon: SlidersHorizontal },
+ { label: 'Logs', path: '/var/log', icon: FileText },
+];
+
// File manager operations that the agent can serve over file:* commands.
// Anything else (mkdir, delete, rename, copy, chmod, search, disk usage,
// upload/download) is panel-host-only until the matching agent verbs land.
@@ -779,6 +788,7 @@ function FileManager() {
<PageTopbar
icon={<FolderOpen size={18} />}
title="Files"
+ meta={isRemote ? target.name : 'panel host'}
tabs={FILE_TABS}
/>
@@ -847,7 +857,7 @@ function FileManager() {
<div className="path-breadcrumb">
{breadcrumbs.map((crumb, idx) => (
<span key={crumb.path + idx} className="crumb-segment">
- {idx > 0 && <ChevronRight size={12} className="crumb-separator" />}
+ {idx > 0 && <span className="crumb-separator">/</span>}
<button
className={`crumb ${idx === breadcrumbs.length - 1 ? 'crumb-active' : ''}`}
onClick={() => navigateTo(crumb.path)}
@@ -949,6 +959,26 @@ function FileManager() {
<div className="file-manager-body">
{sidebarVisible && (
<aside className="file-manager-sidebar left">
+ {/* Quick access (demo rail shortcuts) */}
+ <div className="sidebar-section">
+ <div className="sidebar-section-header static">
+ <Zap size={16} />
+ <span>Quick access</span>
+ </div>
+ <div className="sidebar-section-content quick-access-list">
+ {QUICK_ACCESS.map(q => (
+ <button
+ key={q.label}
+ className={`quick-access-item ${currentPath === q.path ? 'active' : ''}`}
+ onClick={() => navigateTo(q.path)}
+ >
+ <q.icon size={14} />
+ <span>{q.label}</span>
+ </button>
+ ))}
+ </div>
+ </div>
+
{/* Folder Tree */}
<div className="sidebar-section">
<div className="sidebar-section-header sidebar-section-header--split">
diff --git a/frontend/src/styles/pages/_file-manager.scss b/frontend/src/styles/pages/_file-manager.scss
index 6478196a..bc1afc71 100644
--- a/frontend/src/styles/pages/_file-manager.scss
+++ b/frontend/src/styles/pages/_file-manager.scss
@@ -194,7 +194,14 @@ $ft-default: #646b7a;
gap: 1px;
.crumb-segment { display: inline-flex; align-items: center; }
- .crumb-separator { color: var(--text-ghost); margin: 0 1px; }
+ // demo crumbs join on a mono "/" (not a chevron icon)
+ .crumb-separator {
+ color: var(--text-ghost);
+ margin: 0 1px;
+ font-family: var(--mono);
+ font-size: 11px;
+ user-select: none;
+ }
.crumb {
background: transparent;
border: none;
@@ -577,6 +584,42 @@ $ft-default: #646b7a;
.sidebar-section-content { padding: $space-1 0; }
.tree-content { padding: $space-1 0; }
+ // ─── Quick access (demo rail shortcuts) ─────────────
+ .quick-access-list {
+ display: grid;
+ gap: 1px;
+ }
+
+ .quick-access-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ padding: 6px 10px;
+ background: transparent;
+ border: none;
+ border-radius: $radius-sm;
+ color: var(--text-dim);
+ font-size: 12.5px;
+ text-align: left;
+ cursor: pointer;
+ @include transition(all);
+
+ svg { color: var(--text-faint); flex-shrink: 0; }
+
+ &:hover {
+ background: var(--surface-2);
+ color: var(--text);
+ }
+
+ &.active {
+ background: var(--accent-bg);
+ color: var(--accent-bright);
+
+ svg { color: var(--accent-bright); }
+ }
+ }
+
// ─── Type filters ───────────────────────────────────
.type-filter-panel {
padding: $space-1 0;
@@ -1016,8 +1059,8 @@ $ft-default: #646b7a;
font-weight: $font-weight-bold;
color: white;
letter-spacing: 0.04em;
- opacity: 0;
- @include transition(opacity);
+ // demo keeps the extension visible on image thumbs at all times
+ opacity: 1;
}
.file-card-body {
@@ -1573,6 +1616,47 @@ $drawer-width: 520px;
&[readonly] { background: $bg-body; }
}
+ // ─── Syntax-tinted read view (demo .pv-code) ────────
+ .pv-code {
+ flex: 1;
+ min-height: 280px;
+ overflow: auto;
+ padding: $space-3 0;
+ background: var(--bg-code);
+ font-family: var(--mono);
+ font-size: 12px;
+ line-height: 1.65;
+
+ &__line {
+ display: flex;
+
+ &:hover { background: var(--surface-2); }
+ }
+
+ &__n {
+ flex-shrink: 0;
+ width: 44px;
+ padding-right: 12px;
+ text-align: right;
+ color: var(--text-ghost);
+ user-select: none;
+ }
+
+ &__c {
+ flex: 1;
+ min-width: 0;
+ padding-right: $space-3;
+ white-space: pre;
+ color: var(--text-code, var(--text));
+
+ .tok-kw { color: var(--accent-bright); font-weight: 500; }
+ .tok-str { color: var(--green); }
+ .tok-num { color: var(--amber); }
+ .tok-cmt { color: var(--text-ghost); }
+ .tok-var { color: var(--cyan); }
+ }
+ }
+
.preview-unavailable {
flex: 1;
display: flex;