mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
437df5d8b8
commit
ed4630c671
119 files changed
+8531
-2882
No files matched your search
+1
-4
@@ -25,7 +25,4 @@ computr/frontend/.svelte-kit/
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# uv
|
||||
uv.lock
|
||||
|
||||
.cptr
|
||||
.cptr
|
||||
+27
-7
@@ -28,11 +28,14 @@ app = FastAPI()
|
||||
async def startup():
|
||||
await init_db()
|
||||
from cptr.env import STARTUP_TOKEN
|
||||
|
||||
app.state.startup_token = STARTUP_TOKEN
|
||||
# Reconcile stuck chat state from prior crash/restart
|
||||
from cptr.env import ENABLE_CHAT_RECONCILE_ON_STARTUP
|
||||
|
||||
if ENABLE_CHAT_RECONCILE_ON_STARTUP:
|
||||
from cptr.utils.chat_task import reconcile_chat_state
|
||||
|
||||
await reconcile_chat_state()
|
||||
|
||||
|
||||
@@ -41,7 +44,13 @@ async def startup():
|
||||
async def auth_middleware(request: Request, call_next):
|
||||
path = request.url.path
|
||||
# Skip auth for: auth endpoints, health, static assets, HTML pages
|
||||
if path.startswith("/api/auth") or path == "/api/health" or path == "/api/config" or path == "/api/changelog" or path == "/manifest.json":
|
||||
if (
|
||||
path.startswith("/api/auth")
|
||||
or path == "/api/health"
|
||||
or path == "/api/config"
|
||||
or path == "/api/changelog"
|
||||
or path == "/manifest.json"
|
||||
):
|
||||
return await call_next(request)
|
||||
if path.startswith("/_app/") or not path.startswith("/api/"):
|
||||
return await call_next(request)
|
||||
@@ -73,20 +82,21 @@ async def auth_middleware(request: Request, call_next):
|
||||
# Added after auth middleware so it wraps outermost (runs before auth),
|
||||
# since proxied sub-resources don't need cptr auth.
|
||||
from cptr.utils.proxy_middleware import ProxyFallbackMiddleware
|
||||
|
||||
app.add_middleware(ProxyFallbackMiddleware)
|
||||
|
||||
|
||||
# Path normalization middleware (Windows: \ → / in JSON responses)
|
||||
import platform
|
||||
|
||||
if platform.system() == "Windows":
|
||||
import json as _json
|
||||
|
||||
@app.middleware("http")
|
||||
async def normalize_paths_middleware(request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
if (
|
||||
response.headers.get("content-type", "").startswith("application/json")
|
||||
and hasattr(response, "body")
|
||||
if response.headers.get("content-type", "").startswith("application/json") and hasattr(
|
||||
response, "body"
|
||||
):
|
||||
try:
|
||||
body = b""
|
||||
@@ -99,6 +109,7 @@ if platform.system() == "Windows":
|
||||
_normalize_obj(data)
|
||||
new_body = _json.dumps(data, ensure_ascii=False).encode("utf-8")
|
||||
from starlette.responses import Response as StarletteResponse
|
||||
|
||||
return StarletteResponse(
|
||||
content=new_body,
|
||||
status_code=response.status_code,
|
||||
@@ -148,7 +159,7 @@ async def get_config():
|
||||
version = "dev"
|
||||
|
||||
return {
|
||||
"auth_mode": mode.value if hasattr(mode, 'value') else str(mode),
|
||||
"auth_mode": mode.value if hasattr(mode, "value") else str(mode),
|
||||
"needs_setup": needs_setup,
|
||||
"signup_enabled": signup_enabled,
|
||||
"version": version,
|
||||
@@ -172,6 +183,7 @@ app.include_router(workspace_router)
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
import os
|
||||
|
||||
return {"status": "ok", "uptime_seconds": int(time.time() - START_TIME), "pid": os.getpid()}
|
||||
|
||||
|
||||
@@ -179,6 +191,7 @@ async def health():
|
||||
async def get_changelog():
|
||||
"""Return parsed CHANGELOG.md as structured JSON (max 5 versions)."""
|
||||
from cptr.utils.changelog import CHANGELOG
|
||||
|
||||
return {key: CHANGELOG[key] for idx, key in enumerate(CHANGELOG) if idx < 5}
|
||||
|
||||
|
||||
@@ -212,7 +225,12 @@ async def pwa_manifest():
|
||||
"icons": [
|
||||
{"src": "/icon-192.png", "sizes": "192x192", "type": "image/png"},
|
||||
{"src": "/icon-512.png", "sizes": "512x512", "type": "image/png"},
|
||||
{"src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable",
|
||||
},
|
||||
],
|
||||
"categories": ["developer", "productivity", "utilities"],
|
||||
}
|
||||
@@ -221,7 +239,9 @@ async def pwa_manifest():
|
||||
# Frontend (unchanged)
|
||||
FRONTEND_BUILD_DIR = Path(__file__).parent / "frontend" / "build"
|
||||
if FRONTEND_BUILD_DIR.exists():
|
||||
app.mount("/_app", StaticFiles(directory=str(FRONTEND_BUILD_DIR / "_app")), name="frontend-assets")
|
||||
app.mount(
|
||||
"/_app", StaticFiles(directory=str(FRONTEND_BUILD_DIR / "_app")), name="frontend-assets"
|
||||
)
|
||||
|
||||
@app.get("/{full_path:path}")
|
||||
async def serve_spa(request: Request, full_path: str):
|
||||
|
||||
+3
-1
@@ -16,7 +16,8 @@ def cli():
|
||||
def run(host: str, port: int, reload: bool, headless: bool):
|
||||
"""Start the cptr server."""
|
||||
import os, secrets
|
||||
display_host = 'localhost' if host == '0.0.0.0' else host
|
||||
|
||||
display_host = "localhost" if host == "0.0.0.0" else host
|
||||
|
||||
token = secrets.token_hex(32)
|
||||
os.environ["CPTR_STARTUP_TOKEN"] = token
|
||||
@@ -25,6 +26,7 @@ def run(host: str, port: int, reload: bool, headless: bool):
|
||||
print(f"\n ➜ {url}\n")
|
||||
if not headless:
|
||||
import threading, webbrowser
|
||||
|
||||
threading.Timer(1.5, lambda: webbrowser.open(url)).start()
|
||||
uvicorn.run(
|
||||
"cptr.app:application",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
build
|
||||
.svelte-kit
|
||||
node_modules
|
||||
package-lock.json
|
||||
static
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.svelte",
|
||||
"options": {
|
||||
"parser": "svelte"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+31
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.0.1",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "frontend",
|
||||
"version": "0.0.1",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@codemirror/lang-cpp": "^6.0.3",
|
||||
"@codemirror/lang-css": "^6.3.1",
|
||||
@@ -78,6 +78,8 @@
|
||||
"@sveltejs/kit": "^2.57.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
||||
"@types/sortablejs": "^1.15.9",
|
||||
"prettier": "^3.7.4",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"svelte": "^5.55.2",
|
||||
"svelte-check": "^4.4.6",
|
||||
"typescript": "^6.0.2",
|
||||
@@ -3687,6 +3689,33 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.8.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz",
|
||||
"integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier-plugin-svelte": {
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-3.5.2.tgz",
|
||||
"integrity": "sha512-ItFouLvzSFE3ulNl4DKoWM3BGcbDCNVpIyy/Y3F2gC3aNiGLxtFUdffVqO5Z5hhYG+DFT5KULWaxmeFFpdbvaQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"prettier": "^3.0.0",
|
||||
"svelte": "^3.2.0 || ^4.0.0-next.0 || ^5.0.0-next.0"
|
||||
}
|
||||
},
|
||||
"node_modules/process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||
},
|
||||
@@ -17,6 +19,8 @@
|
||||
"@sveltejs/kit": "^2.57.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
||||
"@types/sortablejs": "^1.15.9",
|
||||
"prettier": "^3.7.4",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"svelte": "^5.55.2",
|
||||
"svelte-check": "^4.4.6",
|
||||
"typescript": "^6.0.2",
|
||||
|
||||
+101
-83
@@ -1,163 +1,181 @@
|
||||
@import "tailwindcss";
|
||||
@import 'tailwindcss';
|
||||
@plugin "@tailwindcss/typography";
|
||||
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
@theme {
|
||||
--font-sans: "Inter", -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif;
|
||||
--font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
|
||||
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif;
|
||||
--font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
|
||||
|
||||
/* Exact Open WebUI gray scale - pure neutral, zero chroma */
|
||||
--color-gray-50: oklch(0.98 0 0);
|
||||
--color-gray-100: oklch(0.94 0 0);
|
||||
--color-gray-200: oklch(0.92 0 0);
|
||||
--color-gray-300: oklch(0.85 0 0);
|
||||
--color-gray-400: oklch(0.77 0 0);
|
||||
--color-gray-500: oklch(0.69 0 0);
|
||||
--color-gray-600: oklch(0.51 0 0);
|
||||
--color-gray-700: oklch(0.42 0 0);
|
||||
--color-gray-800: oklch(0.32 0 0);
|
||||
--color-gray-850: oklch(0.27 0 0);
|
||||
--color-gray-900: oklch(0.2 0 0);
|
||||
--color-gray-950: oklch(0.16 0 0);
|
||||
/* Exact Open WebUI gray scale - pure neutral, zero chroma */
|
||||
--color-gray-50: oklch(0.98 0 0);
|
||||
--color-gray-100: oklch(0.94 0 0);
|
||||
--color-gray-200: oklch(0.92 0 0);
|
||||
--color-gray-300: oklch(0.85 0 0);
|
||||
--color-gray-400: oklch(0.77 0 0);
|
||||
--color-gray-500: oklch(0.69 0 0);
|
||||
--color-gray-600: oklch(0.51 0 0);
|
||||
--color-gray-700: oklch(0.42 0 0);
|
||||
--color-gray-800: oklch(0.32 0 0);
|
||||
--color-gray-850: oklch(0.27 0 0);
|
||||
--color-gray-900: oklch(0.2 0 0);
|
||||
--color-gray-950: oklch(0.16 0 0);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
*,
|
||||
::after,
|
||||
::before,
|
||||
::backdrop,
|
||||
::file-selector-button {
|
||||
border-color: var(--color-gray-200, currentColor);
|
||||
}
|
||||
*,
|
||||
::after,
|
||||
::before,
|
||||
::backdrop,
|
||||
::file-selector-button {
|
||||
border-color: var(--color-gray-200, currentColor);
|
||||
}
|
||||
|
||||
html {
|
||||
color-scheme: dark light;
|
||||
touch-action: manipulation;
|
||||
overscroll-behavior: none;
|
||||
}
|
||||
html {
|
||||
color-scheme: dark light;
|
||||
touch-action: manipulation;
|
||||
overscroll-behavior: none;
|
||||
}
|
||||
|
||||
button {
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
button {
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scrollbar - Open WebUI style */
|
||||
::-webkit-scrollbar-thumb {
|
||||
--tw-border-opacity: 1;
|
||||
background-color: rgba(215, 215, 215, 0.6);
|
||||
border-color: rgba(255, 255, 255, var(--tw-border-opacity));
|
||||
border-radius: 9999px;
|
||||
border-width: 1px;
|
||||
--tw-border-opacity: 1;
|
||||
background-color: rgba(215, 215, 215, 0.6);
|
||||
border-color: rgba(255, 255, 255, var(--tw-border-opacity));
|
||||
border-radius: 9999px;
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
/* Dark theme scrollbar styles */
|
||||
.dark ::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(67, 67, 67, 0.6);
|
||||
border-color: rgba(0, 0, 0, var(--tw-border-opacity));
|
||||
background-color: rgba(67, 67, 67, 0.6);
|
||||
border-color: rgba(0, 0, 0, var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
height: 0.45rem;
|
||||
width: 0.45rem;
|
||||
height: 0.45rem;
|
||||
width: 0.45rem;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background-color: transparent;
|
||||
border-radius: 9999px;
|
||||
background-color: transparent;
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.scrollbar-hidden {
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
}
|
||||
.scrollbar-hidden::-webkit-scrollbar {
|
||||
display: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* CodeMirror - match Open WebUI */
|
||||
.cm-editor {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cm-editor.cm-focused {
|
||||
outline: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.dark .cm-editor {
|
||||
background-color: #000 !important;
|
||||
background-color: #000 !important;
|
||||
}
|
||||
|
||||
.dark .cm-gutters {
|
||||
background-color: #000 !important;
|
||||
border: none !important;
|
||||
background-color: #000 !important;
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
.dark .cm-activeLine {
|
||||
background-color: rgba(255, 255, 255, 0.04) !important;
|
||||
background-color: rgba(255, 255, 255, 0.04) !important;
|
||||
}
|
||||
|
||||
.dark .cm-activeLineGutter {
|
||||
background-color: rgba(255, 255, 255, 0.04) !important;
|
||||
background-color: rgba(255, 255, 255, 0.04) !important;
|
||||
}
|
||||
|
||||
:not(.dark) .cm-gutters {
|
||||
border: none !important;
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
.cm-scroller:active::-webkit-scrollbar-thumb,
|
||||
.cm-scroller:focus::-webkit-scrollbar-thumb,
|
||||
.cm-scroller:hover::-webkit-scrollbar-thumb {
|
||||
visibility: visible;
|
||||
visibility: visible;
|
||||
}
|
||||
.cm-scroller::-webkit-scrollbar-thumb {
|
||||
visibility: hidden;
|
||||
visibility: hidden;
|
||||
}
|
||||
.cm-scroller::-webkit-scrollbar-corner {
|
||||
display: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Shimmer animation, Open WebUI style */
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 100% 0; }
|
||||
100% { background-position: -100% 0; }
|
||||
0% {
|
||||
background-position: 100% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -100% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.shimmer {
|
||||
background: linear-gradient(110deg, #b4b4b4 0%, #b4b4b4 43%, #e8e8e8 50%, #b4b4b4 57%, #b4b4b4 100%);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 1.5s cubic-bezier(0.7, 0, 1, 0.4) infinite;
|
||||
color: #b4b4b4;
|
||||
background: linear-gradient(
|
||||
110deg,
|
||||
#b4b4b4 0%,
|
||||
#b4b4b4 43%,
|
||||
#e8e8e8 50%,
|
||||
#b4b4b4 57%,
|
||||
#b4b4b4 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 1.5s cubic-bezier(0.7, 0, 1, 0.4) infinite;
|
||||
color: #b4b4b4;
|
||||
}
|
||||
|
||||
.dark .shimmer {
|
||||
background: linear-gradient(110deg, #9a9a9a 0%, #9a9a9a 43%, #5e5e5e 50%, #9a9a9a 57%, #9a9a9a 100%);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 1.5s cubic-bezier(0.7, 0, 1, 0.4) infinite;
|
||||
color: #9a9a9a;
|
||||
background: linear-gradient(
|
||||
110deg,
|
||||
#9a9a9a 0%,
|
||||
#9a9a9a 43%,
|
||||
#5e5e5e 50%,
|
||||
#9a9a9a 57%,
|
||||
#9a9a9a 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 1.5s cubic-bezier(0.7, 0, 1, 0.4) infinite;
|
||||
color: #9a9a9a;
|
||||
}
|
||||
|
||||
/* Inline code (codespan), Open WebUI style */
|
||||
.codespan {
|
||||
padding: 0.15rem 0.3rem;
|
||||
font-size: 0.85em;
|
||||
@apply font-mono rounded-md text-gray-800 bg-gray-100 dark:text-gray-200 dark:bg-gray-800 mx-0.5;
|
||||
padding: 0.15rem 0.3rem;
|
||||
font-size: 0.85em;
|
||||
@apply font-mono rounded-md text-gray-800 bg-gray-100 dark:text-gray-200 dark:bg-gray-800 mx-0.5;
|
||||
}
|
||||
|
||||
/* Tippy tooltip theme */
|
||||
.tippy-box[data-theme~='cptr'] {
|
||||
background: #1a1a1a;
|
||||
color: #e0e0e0;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
padding: 2px 4px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
background: #1a1a1a;
|
||||
color: #e0e0e0;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
padding: 2px 4px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
|
||||
/>
|
||||
<meta name="text-scale" content="scale" />
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
|
||||
@@ -26,25 +26,25 @@ export const deleteUser = (userId: string) =>
|
||||
export const updateRole = (userId: string, role: string) =>
|
||||
fetchJSON(`/api/admin/users/${userId}/role`, {
|
||||
...jsonBody({ role }),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const updateUserProfile = (userId: string, display_name: string | null) =>
|
||||
fetchJSON(`/api/admin/users/${userId}/profile`, {
|
||||
...jsonBody({ display_name }),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const resetPassword = (userId: string, password: string) =>
|
||||
fetchJSON(`/api/admin/users/${userId}/password`, {
|
||||
...jsonBody({ password }),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const updateUsername = (userId: string, username: string) =>
|
||||
fetchJSON(`/api/admin/users/${userId}/username`, {
|
||||
...jsonBody({ username }),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const getAdminConfig = async (): Promise<Record<string, unknown>> => {
|
||||
@@ -55,10 +55,9 @@ export const getAdminConfig = async (): Promise<Record<string, unknown>> => {
|
||||
export const updateConfig = (config: Record<string, unknown>) =>
|
||||
fetchJSON('/api/admin/config', {
|
||||
method: 'PUT',
|
||||
...jsonBody({ config }),
|
||||
...jsonBody({ config })
|
||||
});
|
||||
|
||||
|
||||
// ── Connections ─────────────────────────────────────────────
|
||||
|
||||
export interface Connection {
|
||||
@@ -89,14 +88,19 @@ export const createConnection = (conn: {
|
||||
models?: string[];
|
||||
}) => fetchJSON('/api/admin/connections', jsonBody(conn));
|
||||
|
||||
export const updateConnection = (id: string, updates: Partial<Omit<Connection, 'id' | 'data'>> & { models?: string[] }) =>
|
||||
export const updateConnection = (
|
||||
id: string,
|
||||
updates: Partial<Omit<Connection, 'id' | 'data'>> & { models?: string[] }
|
||||
) =>
|
||||
fetchJSON(`/api/admin/connections/${id}`, {
|
||||
...jsonBody(updates),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const deleteConnection = (id: string) =>
|
||||
fetchJSON(`/api/admin/connections/${id}`, { method: 'DELETE' });
|
||||
|
||||
export const verifyConnection = (id: string) =>
|
||||
fetchJSON<{ ok: boolean; message: string }>(`/api/admin/connections/${id}/verify`, { method: 'POST' });
|
||||
fetchJSON<{ ok: boolean; message: string }>(`/api/admin/connections/${id}/verify`, {
|
||||
method: 'POST'
|
||||
});
|
||||
@@ -31,27 +31,33 @@ export const setup = (username: string, password: string, token: string) =>
|
||||
fetchJSON('/api/auth/setup', jsonBody({ username, password, token }));
|
||||
|
||||
export const signup = (username: string, password: string) =>
|
||||
fetchJSON<{ ok?: boolean; pending?: boolean }>('/api/auth/signup', jsonBody({ username, password }));
|
||||
fetchJSON<{ ok?: boolean; pending?: boolean }>(
|
||||
'/api/auth/signup',
|
||||
jsonBody({ username, password })
|
||||
);
|
||||
|
||||
export const logout = () =>
|
||||
fetchHandler('/api/auth/logout', { method: 'POST' }).catch(() => {});
|
||||
export const logout = () => fetchHandler('/api/auth/logout', { method: 'POST' }).catch(() => {});
|
||||
|
||||
export const updatePassword = (currentPassword: string, newPassword: string) =>
|
||||
fetchJSON('/api/auth/password', jsonBody({
|
||||
current_password: currentPassword,
|
||||
new_password: newPassword,
|
||||
}));
|
||||
fetchJSON(
|
||||
'/api/auth/password',
|
||||
jsonBody({
|
||||
current_password: currentPassword,
|
||||
new_password: newPassword
|
||||
})
|
||||
);
|
||||
|
||||
/** Upload avatar (resized client-side). Returns { ok, profile_image_url }. */
|
||||
export const uploadAvatar = async (blob: Blob): Promise<{ ok: boolean; profile_image_url: string }> => {
|
||||
export const uploadAvatar = async (
|
||||
blob: Blob
|
||||
): Promise<{ ok: boolean; profile_image_url: string }> => {
|
||||
const form = new FormData();
|
||||
form.append('file', blob, 'avatar.png');
|
||||
return fetchJSON('/api/auth/avatar', { method: 'PUT', body: form });
|
||||
};
|
||||
|
||||
/** Delete avatar. */
|
||||
export const deleteAvatar = () =>
|
||||
fetchJSON('/api/auth/avatar', { method: 'DELETE' });
|
||||
export const deleteAvatar = () => fetchJSON('/api/auth/avatar', { method: 'DELETE' });
|
||||
|
||||
/** Update display name. */
|
||||
export const updateProfile = (display_name: string | null) =>
|
||||
|
||||
@@ -51,8 +51,7 @@ export const getChats = (
|
||||
`/api/chats?workspace=${encodeURIComponent(workspace)}&limit=${limit}&offset=${offset}&sort_by=${sortBy}&sort_dir=${sortDir}`
|
||||
);
|
||||
|
||||
export const getChat = (chatId: string) =>
|
||||
fetchJSON<ChatDetail>(`/api/chats/${chatId}`);
|
||||
export const getChat = (chatId: string) => fetchJSON<ChatDetail>(`/api/chats/${chatId}`);
|
||||
|
||||
export const deleteChat = (chatId: string) =>
|
||||
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}`, { method: 'DELETE' });
|
||||
@@ -98,10 +97,7 @@ export const cancelTask = (chatId: string, messageId: string) =>
|
||||
fetchJSON(`/api/chats/${chatId}/messages/${messageId}/cancel`, { method: 'POST' });
|
||||
|
||||
export const updateCurrentMessage = (chatId: string, messageId: string) =>
|
||||
fetchJSON<{ ok: boolean }>(
|
||||
`/api/chats/${chatId}/current`,
|
||||
jsonBody({ message_id: messageId })
|
||||
);
|
||||
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}/current`, jsonBody({ message_id: messageId }));
|
||||
|
||||
export const updateMessage = (
|
||||
chatId: string,
|
||||
@@ -135,7 +131,4 @@ export const queueSendNow = (chatId: string, messageId: string) =>
|
||||
);
|
||||
|
||||
export const queueDelete = (chatId: string, messageId: string) =>
|
||||
fetchJSON<{ ok: boolean }>(
|
||||
`/api/chats/${chatId}/queue/${messageId}`,
|
||||
{ method: 'DELETE' }
|
||||
);
|
||||
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}/queue/${messageId}`, { method: 'DELETE' });
|
||||
@@ -19,7 +19,7 @@ export const writeFile = (path: string, content: string) =>
|
||||
fetchJSON('/api/workspace/files/write', jsonBody({ path, content }));
|
||||
|
||||
export const deleteFiles = (paths: string[]) =>
|
||||
Promise.all(paths.map(path => fetchJSON('/api/workspace/files/delete', jsonBody({ path }))));
|
||||
Promise.all(paths.map((path) => fetchJSON('/api/workspace/files/delete', jsonBody({ path }))));
|
||||
|
||||
export const moveFile = (src: string, dest: string) =>
|
||||
fetchJSON('/api/workspace/files/move', jsonBody({ source: src, destination: dest }));
|
||||
@@ -34,4 +34,6 @@ export const downloadArchive = (paths: string[]) =>
|
||||
fetchHandler('/api/workspace/files/archive', { method: 'POST', ...jsonBody({ paths }) });
|
||||
|
||||
export const searchFiles = (query: string, path: string) =>
|
||||
fetchJSON(`/api/workspace/files/search?query=${encodeURIComponent(query)}&path=${encodeURIComponent(path)}`);
|
||||
fetchJSON(
|
||||
`/api/workspace/files/search?query=${encodeURIComponent(query)}&path=${encodeURIComponent(path)}`
|
||||
);
|
||||
@@ -9,8 +9,7 @@ export const getGitStatus = (root: string) =>
|
||||
export const getGitLog = (root: string, limit = 30) =>
|
||||
fetchJSON(`/api/git/log?root=${encodeURIComponent(root)}&limit=${limit}`);
|
||||
|
||||
export const getGitDiff = (params: string) =>
|
||||
fetchJSON(`/api/git/diff?${params}`);
|
||||
export const getGitDiff = (params: string) => fetchJSON(`/api/git/diff?${params}`);
|
||||
|
||||
export const getGitShow = (root: string, ref: string) =>
|
||||
fetchJSON(`/api/git/show?root=${encodeURIComponent(root)}&ref=${encodeURIComponent(ref)}`);
|
||||
@@ -30,11 +29,9 @@ export const discardChanges = (root: string, files: string[]) =>
|
||||
export const gitCommit = (root: string, message: string) =>
|
||||
fetchJSON('/api/git/commit', jsonBody({ root, message }));
|
||||
|
||||
export const gitPull = (root: string) =>
|
||||
fetchJSON('/api/git/pull', jsonBody({ root }));
|
||||
export const gitPull = (root: string) => fetchJSON('/api/git/pull', jsonBody({ root }));
|
||||
|
||||
export const gitPush = (root: string) =>
|
||||
fetchJSON('/api/git/push', jsonBody({ root }));
|
||||
export const gitPush = (root: string) => fetchJSON('/api/git/push', jsonBody({ root }));
|
||||
|
||||
export const createGitBranch = (root: string, name: string) =>
|
||||
fetchJSON('/api/git/branch', jsonBody({ root, name }));
|
||||
|
||||
@@ -8,7 +8,7 @@ import { clearSession } from '$lib/session';
|
||||
export async function fetchHandler(path: string, init?: RequestInit): Promise<Response> {
|
||||
const res = await fetch(path, {
|
||||
...init,
|
||||
credentials: 'include',
|
||||
credentials: 'include'
|
||||
});
|
||||
// 401 on non-auth endpoints means the session expired; auto-logout.
|
||||
// Auth endpoints (login, session check) naturally return 401; don't intercept those.
|
||||
@@ -40,5 +40,5 @@ export class ApiError extends Error {
|
||||
export const jsonBody = (data: unknown): RequestInit => ({
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
@@ -28,7 +28,7 @@ export const getWorkspaceState = (path: string) =>
|
||||
export const saveWorkspaceState = (path: string, data: Record<string, unknown>) =>
|
||||
fetchHandler(`/api/state/workspace?path=${encodeURIComponent(path)}`, {
|
||||
...jsonBody(data),
|
||||
method: 'PUT',
|
||||
method: 'PUT'
|
||||
});
|
||||
|
||||
export const deleteWorkspace = (path: string) =>
|
||||
|
||||
@@ -7,8 +7,7 @@ export interface TerminalSession {
|
||||
session_id: string;
|
||||
}
|
||||
|
||||
export const listSessions = () =>
|
||||
fetchJSON<TerminalSession[]>('/api/terminal');
|
||||
export const listSessions = () => fetchJSON<TerminalSession[]>('/api/terminal');
|
||||
|
||||
export const createSession = (cwd: string) =>
|
||||
fetchJSON<TerminalSession>('/api/terminal', jsonBody({ cwd }));
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
async function load() {
|
||||
try {
|
||||
connections = await listConnections();
|
||||
} catch { toast.error($t('connections.loadError')); }
|
||||
finally { loading = false; }
|
||||
} catch {
|
||||
toast.error($t('connections.loadError'));
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCreated() {
|
||||
@@ -55,7 +58,7 @@
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white">{$t('admin.connections')}</h2>
|
||||
<button
|
||||
class="flex items-center justify-center w-6 h-6 rounded-lg text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75"
|
||||
onclick={() => showCreate = true}
|
||||
onclick={() => (showCreate = true)}
|
||||
>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
@@ -63,17 +66,21 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else}
|
||||
<div>
|
||||
{#each connections as conn}
|
||||
<button
|
||||
class="group flex items-center gap-2 w-full h-7 text-left"
|
||||
onclick={() => editConn = conn}
|
||||
onclick={() => (editConn = conn)}
|
||||
>
|
||||
<span class="flex-1 text-[13px] truncate
|
||||
{conn.enabled ? 'text-gray-700 dark:text-gray-300' : 'text-gray-400 dark:text-gray-600'}">
|
||||
<span
|
||||
class="flex-1 text-[13px] truncate
|
||||
{conn.enabled ? 'text-gray-700 dark:text-gray-300' : 'text-gray-400 dark:text-gray-600'}"
|
||||
>
|
||||
{conn.name}
|
||||
</span>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
@@ -84,10 +91,17 @@
|
||||
tabindex="-1"
|
||||
aria-checked={conn.enabled}
|
||||
onclick={(e) => toggleEnabled(e, conn)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleEnabled(e, conn); } }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
toggleEnabled(e, conn);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span class="absolute top-0.5 w-2.5 h-2.5 rounded-full transition-all duration-150
|
||||
{conn.enabled ? 'left-3 bg-white dark:bg-gray-900' : 'left-0.5 bg-white dark:bg-gray-500'}"></span>
|
||||
<span
|
||||
class="absolute top-0.5 w-2.5 h-2.5 rounded-full transition-all duration-150
|
||||
{conn.enabled ? 'left-3 bg-white dark:bg-gray-900' : 'left-0.5 bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</span>
|
||||
</button>
|
||||
{/each}
|
||||
@@ -99,9 +113,13 @@
|
||||
{/if}
|
||||
|
||||
{#if showCreate}
|
||||
<CreateConnectionModal onclose={() => showCreate = false} oncreated={handleCreated} />
|
||||
<CreateConnectionModal onclose={() => (showCreate = false)} oncreated={handleCreated} />
|
||||
{/if}
|
||||
|
||||
{#if editConn}
|
||||
<EditConnectionModal connection={editConn} onclose={() => editConn = null} onchanged={handleChanged} />
|
||||
<EditConnectionModal
|
||||
connection={editConn}
|
||||
onclose={() => (editConn = null)}
|
||||
onchanged={handleChanged}
|
||||
/>
|
||||
{/if}
|
||||
@@ -30,11 +30,20 @@
|
||||
creating = true;
|
||||
try {
|
||||
const models = formModels.trim()
|
||||
? formModels.split(',').map(m => m.trim()).filter(Boolean)
|
||||
? formModels
|
||||
.split(',')
|
||||
.map((m) => m.trim())
|
||||
.filter(Boolean)
|
||||
: undefined;
|
||||
const name = formName.trim() || (() => {
|
||||
try { return new URL(formBaseUrl.trim()).hostname; } catch { return formProvider; }
|
||||
})();
|
||||
const name =
|
||||
formName.trim() ||
|
||||
(() => {
|
||||
try {
|
||||
return new URL(formBaseUrl.trim()).hostname;
|
||||
} catch {
|
||||
return formProvider;
|
||||
}
|
||||
})();
|
||||
await createConnection({
|
||||
name,
|
||||
provider: formProvider,
|
||||
@@ -42,32 +51,48 @@
|
||||
prefix_id: formPrefixId.trim() || null,
|
||||
base_url: formBaseUrl.trim(),
|
||||
api_key: formApiKey.trim(),
|
||||
models,
|
||||
models
|
||||
});
|
||||
toast.success($t('connections.added'));
|
||||
refreshChatState();
|
||||
oncreated();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof ApiError ? e.message : ($t('connections.addError') || 'Failed'));
|
||||
} finally { creating = false; }
|
||||
toast.error(e instanceof ApiError ? e.message : $t('connections.addError') || 'Failed');
|
||||
} finally {
|
||||
creating = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {onclose} class="w-full max-w-md mx-4">
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="p-4" onkeydown={(e) => { if (e.key === 'Enter' && formBaseUrl.trim() && formApiKey.trim()) create(); }}>
|
||||
<div
|
||||
class="p-4"
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' && formBaseUrl.trim() && formApiKey.trim()) create();
|
||||
}}
|
||||
>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-3">{$t('connections.add')}</h2>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<div class="flex-1">
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600">{$t('connections.name')}</label>
|
||||
<input type="text" placeholder="Optional" bind:value={formName} autofocus autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Optional"
|
||||
bind:value={formName}
|
||||
autofocus
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
</div>
|
||||
<div class="w-28 shrink-0">
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600">Provider</label>
|
||||
<select bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer">
|
||||
<select
|
||||
bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
<option value="openai">OpenAI</option>
|
||||
</select>
|
||||
@@ -76,16 +101,27 @@
|
||||
|
||||
{#if formProvider === 'openai'}
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">API Type</label>
|
||||
<select bind:value={formApiType}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer">
|
||||
<select
|
||||
bind:value={formApiType}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="chat_completions">Chat Completions</option>
|
||||
<option value="responses">Responses</option>
|
||||
</select>
|
||||
{/if}
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.baseUrl')}</label>
|
||||
<input type="text" placeholder="https://api.openai.com/v1" bind:value={formBaseUrl} autocomplete="off" spellcheck="false" list="base-url-suggestions"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.baseUrl')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="https://api.openai.com/v1"
|
||||
bind:value={formBaseUrl}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
list="base-url-suggestions"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
<datalist id="base-url-suggestions">
|
||||
<option value="https://api.anthropic.com/v1" />
|
||||
<option value="https://api.openai.com/v1" />
|
||||
@@ -93,23 +129,51 @@
|
||||
<option value="http://localhost:11434/v1" />
|
||||
</datalist>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.apiKey')}</label>
|
||||
<input type="password" placeholder="sk-..." bind:value={formApiKey} autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.apiKey')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="sk-..."
|
||||
bind:value={formApiKey}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.prefixId')}</label>
|
||||
<input type="text" placeholder="e.g. openrouter" bind:value={formPrefixId} autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.prefixId')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. openrouter"
|
||||
bind:value={formPrefixId}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.models')}</label>
|
||||
<input type="text" placeholder="claude-sonnet-4-20250514, claude-opus-4-20250514" bind:value={formModels} autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.models')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="claude-sonnet-4-20250514, claude-opus-4-20250514"
|
||||
bind:value={formModels}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<div class="flex justify-end mt-3">
|
||||
<button disabled={creating || !formBaseUrl.trim() || !formApiKey.trim()} onclick={create}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none">
|
||||
<button
|
||||
disabled={creating || !formBaseUrl.trim() || !formApiKey.trim()}
|
||||
onclick={create}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if creating}
|
||||
<div class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{$t('connections.add')} →
|
||||
{/if}
|
||||
|
||||
@@ -21,8 +21,14 @@
|
||||
let creating = $state(false);
|
||||
|
||||
async function create() {
|
||||
if (!username.trim()) { toast.error($t('admin.usernameRequired')); return; }
|
||||
if (password.length < 6) { toast.error($t('admin.minCharsPassword')); return; }
|
||||
if (!username.trim()) {
|
||||
toast.error($t('admin.usernameRequired'));
|
||||
return;
|
||||
}
|
||||
if (password.length < 6) {
|
||||
toast.error($t('admin.minCharsPassword'));
|
||||
return;
|
||||
}
|
||||
creating = true;
|
||||
try {
|
||||
await apiCreateUser(username.trim(), password, role);
|
||||
@@ -30,34 +36,69 @@
|
||||
oncreated();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof ApiError ? e.message : $t('auth.connectionFailed'));
|
||||
} finally {
|
||||
creating = false;
|
||||
}
|
||||
finally { creating = false; }
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {onclose} class="w-full max-w-sm mx-4">
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="p-4" onkeydown={(e) => { if (e.key === 'Enter' && username.trim() && password.length >= 6) create(); }}>
|
||||
<div
|
||||
class="p-4"
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' && username.trim() && password.length >= 6) create();
|
||||
}}
|
||||
>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-2">{$t('admin.newUser')}</h2>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.username')}</label>
|
||||
<input type="text" placeholder={$t('admin.enterUsername')} bind:value={username} autofocus autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.displayName')}</label>
|
||||
<input type="text" placeholder={$t('admin.optional')} bind:value={displayName} autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.passwordLabel')}</label>
|
||||
<input type="password" placeholder={$t('admin.minChars')} bind:value={password} autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('admin.enterUsername')}
|
||||
bind:value={username}
|
||||
autofocus
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1"
|
||||
>{$t('admin.displayName')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('admin.optional')}
|
||||
bind:value={displayName}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1"
|
||||
>{$t('admin.passwordLabel')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('admin.minChars')}
|
||||
bind:value={password}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.role')}</label>
|
||||
<select bind:value={role}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer">
|
||||
<select
|
||||
bind:value={role}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
{#each ROLES as r}<option value={r}>{r}</option>{/each}
|
||||
</select>
|
||||
<div class="flex justify-end mt-2">
|
||||
<button disabled={creating || !username.trim() || password.length < 6} onclick={create}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none">
|
||||
<button
|
||||
disabled={creating || !username.trim() || password.length < 6}
|
||||
onclick={create}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if creating}
|
||||
<div class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{$t('admin.create')}
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import Modal from '../Modal.svelte';
|
||||
import { updateConnection, deleteConnection, verifyConnection, type Connection } from '$lib/apis/admin';
|
||||
import {
|
||||
updateConnection,
|
||||
deleteConnection,
|
||||
verifyConnection,
|
||||
type Connection
|
||||
} from '$lib/apis/admin';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { refreshChatState } from '$lib/stores/chat';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -15,8 +20,12 @@
|
||||
let { connection, onclose, onchanged }: Props = $props();
|
||||
|
||||
let formName = $state(connection.name || '');
|
||||
let formProvider = $state<'anthropic' | 'openai'>(connection.provider === 'openai' ? 'openai' : 'anthropic');
|
||||
let formApiType = $state<'chat_completions' | 'responses'>(connection.api_type === 'responses' ? 'responses' : 'chat_completions');
|
||||
let formProvider = $state<'anthropic' | 'openai'>(
|
||||
connection.provider === 'openai' ? 'openai' : 'anthropic'
|
||||
);
|
||||
let formApiType = $state<'chat_completions' | 'responses'>(
|
||||
connection.api_type === 'responses' ? 'responses' : 'chat_completions'
|
||||
);
|
||||
let formBaseUrl = $state(connection.base_url || '');
|
||||
let formApiKey = $state('');
|
||||
let formPrefixId = $state(connection.prefix_id || '');
|
||||
@@ -25,15 +34,27 @@
|
||||
let verifying = $state(false);
|
||||
|
||||
async function save() {
|
||||
if (!formBaseUrl.trim()) { toast.error($t('connections.fieldsRequired')); return; }
|
||||
if (!formBaseUrl.trim()) {
|
||||
toast.error($t('connections.fieldsRequired'));
|
||||
return;
|
||||
}
|
||||
saving = true;
|
||||
try {
|
||||
const models = formModels.trim()
|
||||
? formModels.split(',').map(m => m.trim()).filter(Boolean)
|
||||
? formModels
|
||||
.split(',')
|
||||
.map((m) => m.trim())
|
||||
.filter(Boolean)
|
||||
: undefined;
|
||||
const name = formName.trim() || (() => {
|
||||
try { return new URL(formBaseUrl.trim()).hostname; } catch { return formProvider; }
|
||||
})();
|
||||
const name =
|
||||
formName.trim() ||
|
||||
(() => {
|
||||
try {
|
||||
return new URL(formBaseUrl.trim()).hostname;
|
||||
} catch {
|
||||
return formProvider;
|
||||
}
|
||||
})();
|
||||
|
||||
const updates: Record<string, unknown> = {
|
||||
name,
|
||||
@@ -41,7 +62,7 @@
|
||||
api_type: formProvider === 'openai' ? formApiType : 'chat_completions',
|
||||
prefix_id: formPrefixId.trim() || null,
|
||||
base_url: formBaseUrl.trim(),
|
||||
models,
|
||||
models
|
||||
};
|
||||
if (formApiKey.trim()) {
|
||||
updates.api_key = formApiKey.trim();
|
||||
@@ -52,8 +73,10 @@
|
||||
refreshChatState();
|
||||
onchanged();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof ApiError ? e.message : ($t('connections.addError') || 'Failed'));
|
||||
} finally { saving = false; }
|
||||
toast.error(e instanceof ApiError ? e.message : $t('connections.addError') || 'Failed');
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
@@ -75,24 +98,37 @@
|
||||
else toast.error(res.message || $t('connections.failed'));
|
||||
} catch (e: any) {
|
||||
toast.error(e.message || $t('connections.failed'));
|
||||
} finally { verifying = false; }
|
||||
} finally {
|
||||
verifying = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {onclose} class="w-full max-w-md mx-4">
|
||||
<div class="p-4">
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-3">{$t('connections.edit') || 'Edit Connection'}</h2>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-3">
|
||||
{$t('connections.edit') || 'Edit Connection'}
|
||||
</h2>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<div class="flex-1">
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600">{$t('connections.name')}</label>
|
||||
<input type="text" placeholder="Optional" bind:value={formName} autofocus autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Optional"
|
||||
bind:value={formName}
|
||||
autofocus
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
</div>
|
||||
<div class="w-28 shrink-0">
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600">Provider</label>
|
||||
<select bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer">
|
||||
<select
|
||||
bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
<option value="openai">OpenAI</option>
|
||||
</select>
|
||||
@@ -101,16 +137,27 @@
|
||||
|
||||
{#if formProvider === 'openai'}
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">API Type</label>
|
||||
<select bind:value={formApiType}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer">
|
||||
<select
|
||||
bind:value={formApiType}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="chat_completions">Chat Completions</option>
|
||||
<option value="responses">Responses</option>
|
||||
</select>
|
||||
{/if}
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.baseUrl')}</label>
|
||||
<input type="text" placeholder="https://api.openai.com/v1" bind:value={formBaseUrl} autocomplete="off" spellcheck="false" list="base-url-suggestions-edit"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.baseUrl')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="https://api.openai.com/v1"
|
||||
bind:value={formBaseUrl}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
list="base-url-suggestions-edit"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
<datalist id="base-url-suggestions-edit">
|
||||
<option value="https://api.anthropic.com/v1" />
|
||||
<option value="https://api.openai.com/v1" />
|
||||
@@ -118,36 +165,70 @@
|
||||
<option value="http://localhost:11434/v1" />
|
||||
</datalist>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.apiKey')}</label>
|
||||
<input type="password" placeholder="•••••••• (leave blank to keep)" bind:value={formApiKey} autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.apiKey')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="•••••••• (leave blank to keep)"
|
||||
bind:value={formApiKey}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.prefixId')}</label>
|
||||
<input type="text" placeholder="e.g. openrouter" bind:value={formPrefixId} autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.prefixId')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. openrouter"
|
||||
bind:value={formPrefixId}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">{$t('connections.models')}</label>
|
||||
<input type="text" placeholder="claude-sonnet-4-20250514, claude-opus-4-20250514" bind:value={formModels} autocomplete="off" spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>{$t('connections.models')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="claude-sonnet-4-20250514, claude-opus-4-20250514"
|
||||
bind:value={formModels}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
|
||||
/>
|
||||
|
||||
<div class="flex items-center justify-between mt-3">
|
||||
<div class="flex items-center gap-3">
|
||||
<button class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={handleDelete}>{$t('admin.delete') || 'Delete'}</button>
|
||||
<button class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 disabled:opacity-30"
|
||||
<button
|
||||
class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={handleDelete}>{$t('admin.delete') || 'Delete'}</button
|
||||
>
|
||||
<button
|
||||
class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 disabled:opacity-30"
|
||||
disabled={verifying}
|
||||
onclick={handleVerify}>
|
||||
onclick={handleVerify}
|
||||
>
|
||||
{#if verifying}
|
||||
<div class="w-3 h-3 border border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3 h-3 border border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{$t('connections.verify') || 'Verify'}
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
<button disabled={saving || !formBaseUrl.trim()} onclick={save}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none">
|
||||
<button
|
||||
disabled={saving || !formBaseUrl.trim()}
|
||||
onclick={save}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if saving}
|
||||
<div class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{$t('settings.save') || 'Save'} →
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import Modal from '../Modal.svelte';
|
||||
import { updateRole, updateUserProfile, resetPassword, updateUsername, deleteUser as apiDeleteUser } from '$lib/apis/admin';
|
||||
import {
|
||||
updateRole,
|
||||
updateUserProfile,
|
||||
resetPassword,
|
||||
updateUsername,
|
||||
deleteUser as apiDeleteUser
|
||||
} from '$lib/apis/admin';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { t } from '$lib/i18n';
|
||||
|
||||
@@ -38,8 +44,16 @@
|
||||
saving = true;
|
||||
try {
|
||||
const trimmedUsername = username.trim();
|
||||
if (!trimmedUsername) { toast.error($t('admin.usernameRequired')); saving = false; return; }
|
||||
if (newPassword && newPassword.length < 6) { toast.error($t('admin.minCharsPassword')); saving = false; return; }
|
||||
if (!trimmedUsername) {
|
||||
toast.error($t('admin.usernameRequired'));
|
||||
saving = false;
|
||||
return;
|
||||
}
|
||||
if (newPassword && newPassword.length < 6) {
|
||||
toast.error($t('admin.minCharsPassword'));
|
||||
saving = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (trimmedUsername !== user.username) {
|
||||
await updateUsername(user.user_id, trimmedUsername);
|
||||
@@ -78,28 +92,53 @@
|
||||
<div class="p-4">
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-2">{$t('admin.editUser')}</h2>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.username')}</label>
|
||||
<input type="text" placeholder={$t('admin.username')} bind:value={username}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.displayName')}</label>
|
||||
<input type="text" placeholder={$t('admin.optional')} bind:value={displayName}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.newPasswordLabel')}</label>
|
||||
<input type="password" placeholder={$t('admin.leaveBlank')} bind:value={newPassword} autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('admin.username')}
|
||||
bind:value={username}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1"
|
||||
>{$t('admin.displayName')}</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('admin.optional')}
|
||||
bind:value={displayName}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1"
|
||||
>{$t('admin.newPasswordLabel')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('admin.leaveBlank')}
|
||||
bind:value={newPassword}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<label class="text-[10px] text-gray-400 dark:text-gray-600 mt-1">{$t('admin.role')}</label>
|
||||
<select bind:value={role} disabled={isSelf}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer disabled:opacity-50">
|
||||
<select
|
||||
bind:value={role}
|
||||
disabled={isSelf}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{#each ROLES as r}<option value={r}>{r}</option>{/each}
|
||||
</select>
|
||||
<div class="flex items-center justify-between mt-3">
|
||||
{#if !isSelf && (user.role !== 'admin' || adminCount > 1)}
|
||||
<button class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={deleteUser}>{$t('admin.delete')}</button>
|
||||
<button
|
||||
class="text-[13px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={deleteUser}>{$t('admin.delete')}</button
|
||||
>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<button disabled={saving} onclick={save}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none">
|
||||
<button
|
||||
disabled={saving}
|
||||
onclick={save}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if saving}{$t('settings.saving')}{:else}{$t('settings.save')}{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
exaKey = config['web.exa_api_key'] || '';
|
||||
tavilyKey = config['web.tavily_api_key'] || '';
|
||||
braveKey = config['web.brave_api_key'] || '';
|
||||
} catch { toast.error($t('admin.failedToLoadConfig')); }
|
||||
finally { loading = false; }
|
||||
} catch {
|
||||
toast.error($t('admin.failedToLoadConfig'));
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateConfig(key: string, value: any) {
|
||||
@@ -29,8 +32,11 @@
|
||||
await apiUpdateConfig({ [key]: value });
|
||||
config[key] = value;
|
||||
toast.success($t('settings.saved'));
|
||||
} catch { toast.error($t('admin.failedToSave')); }
|
||||
finally { saving = false; }
|
||||
} catch {
|
||||
toast.error($t('admin.failedToSave'));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveKey(key: string, value: string) {
|
||||
@@ -43,132 +49,151 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col min-h-full">
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('admin.settings')}</h2>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('admin.settings')}</h2>
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Auth settings -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('admin.authentication')}</h3>
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Auth settings -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('admin.authentication')}</h3>
|
||||
|
||||
<div class="flex items-center justify-between h-8">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300">{$t('admin.allowSignUp')}</span>
|
||||
<button
|
||||
class="relative w-8 h-[18px] rounded-full transition-colors duration-150
|
||||
<div class="flex items-center justify-between h-8">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300">{$t('admin.allowSignUp')}</span>
|
||||
<button
|
||||
class="relative w-8 h-[18px] rounded-full transition-colors duration-150
|
||||
{config['auth.signup_enabled'] ? 'bg-gray-900 dark:bg-white' : 'bg-gray-300 dark:bg-gray-700'}"
|
||||
onclick={() => updateConfig('auth.signup_enabled', !config['auth.signup_enabled'])}
|
||||
disabled={saving}
|
||||
>
|
||||
<span
|
||||
class="absolute top-[2px] w-[14px] h-[14px] rounded-full transition-all duration-150
|
||||
{config['auth.signup_enabled'] ? 'left-[17px] bg-white dark:bg-black' : 'left-[2px] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{config['auth.signup_enabled'] ? $t('admin.signUpEnabled') : $t('admin.signUpDisabled')}
|
||||
</p>
|
||||
|
||||
<!-- Web settings -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-6">{$t('admin.web')}</h3>
|
||||
|
||||
<!-- Enable/disable toggle -->
|
||||
<div class="flex items-center justify-between h-8">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300">{$t('admin.webEnabled')}</span>
|
||||
<button
|
||||
class="relative w-8 h-[18px] rounded-full transition-colors duration-150
|
||||
{config['web.enabled'] !== false ? 'bg-gray-900 dark:bg-white' : 'bg-gray-300 dark:bg-gray-700'}"
|
||||
onclick={() => updateConfig('web.enabled', config['web.enabled'] === false)}
|
||||
disabled={saving}
|
||||
>
|
||||
<span
|
||||
class="absolute top-[2px] w-[14px] h-[14px] rounded-full transition-all duration-150
|
||||
{config['web.enabled'] !== false ? 'left-[17px] bg-white dark:bg-black' : 'left-[2px] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{config['web.enabled'] !== false ? $t('admin.webEnabledHint') : $t('admin.webDisabledHint')}
|
||||
</p>
|
||||
|
||||
{#if config['web.enabled'] !== false}
|
||||
<!-- Provider selector -->
|
||||
<div class="flex items-center justify-between h-8 mt-3">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300">{$t('admin.webSearchProvider')}</span>
|
||||
<select
|
||||
class="text-[13px] bg-transparent text-gray-700 dark:text-gray-300 text-right outline-none cursor-pointer"
|
||||
value={config['web.search_provider'] || 'auto'}
|
||||
onchange={(e) => updateConfig('web.search_provider', (e.target as HTMLSelectElement).value)}
|
||||
onclick={() => updateConfig('auth.signup_enabled', !config['auth.signup_enabled'])}
|
||||
disabled={saving}
|
||||
>
|
||||
<option value="auto">{$t('admin.webProviderAuto')}</option>
|
||||
<option value="exa">Exa</option>
|
||||
<option value="tavily">Tavily</option>
|
||||
<option value="brave">Brave</option>
|
||||
<option value="duckduckgo">DuckDuckGo</option>
|
||||
</select>
|
||||
<span
|
||||
class="absolute top-[2px] w-[14px] h-[14px] rounded-full transition-all duration-150
|
||||
{config['auth.signup_enabled']
|
||||
? 'left-[17px] bg-white dark:bg-black'
|
||||
: 'left-[2px] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{config['auth.signup_enabled'] ? $t('admin.signUpEnabled') : $t('admin.signUpDisabled')}
|
||||
</p>
|
||||
|
||||
<!-- Conditionally mounted API key fields -->
|
||||
{@const provider = config['web.search_provider'] || 'auto'}
|
||||
<!-- Web settings -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-6">{$t('admin.web')}</h3>
|
||||
|
||||
{#if provider === 'auto'}
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-2">{$t('admin.webAutoHint')}</p>
|
||||
<!-- Enable/disable toggle -->
|
||||
<div class="flex items-center justify-between h-8">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300">{$t('admin.webEnabled')}</span>
|
||||
<button
|
||||
class="relative w-8 h-[18px] rounded-full transition-colors duration-150
|
||||
{config['web.enabled'] !== false ? 'bg-gray-900 dark:bg-white' : 'bg-gray-300 dark:bg-gray-700'}"
|
||||
onclick={() => updateConfig('web.enabled', config['web.enabled'] === false)}
|
||||
disabled={saving}
|
||||
>
|
||||
<span
|
||||
class="absolute top-[2px] w-[14px] h-[14px] rounded-full transition-all duration-150
|
||||
{config['web.enabled'] !== false
|
||||
? 'left-[17px] bg-white dark:bg-black'
|
||||
: 'left-[2px] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{config['web.enabled'] !== false ? $t('admin.webEnabledHint') : $t('admin.webDisabledHint')}
|
||||
</p>
|
||||
|
||||
{:else if provider === 'exa'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1">{$t('admin.webExaKey')}</label>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="exa-..."
|
||||
bind:value={exaKey}
|
||||
onblur={() => saveKey('web.exa_api_key', exaKey)}
|
||||
{#if config['web.enabled'] !== false}
|
||||
<!-- Provider selector -->
|
||||
<div class="flex items-center justify-between h-8 mt-3">
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300"
|
||||
>{$t('admin.webSearchProvider')}</span
|
||||
>
|
||||
<select
|
||||
class="text-[13px] bg-transparent text-gray-700 dark:text-gray-300 text-right outline-none cursor-pointer"
|
||||
value={config['web.search_provider'] || 'auto'}
|
||||
onchange={(e) =>
|
||||
updateConfig('web.search_provider', (e.target as HTMLSelectElement).value)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">{$t('admin.webExaHint')}</p>
|
||||
>
|
||||
<option value="auto">{$t('admin.webProviderAuto')}</option>
|
||||
<option value="exa">Exa</option>
|
||||
<option value="tavily">Tavily</option>
|
||||
<option value="brave">Brave</option>
|
||||
<option value="duckduckgo">DuckDuckGo</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{:else if provider === 'tavily'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1">{$t('admin.webTavilyKey')}</label>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="tvly-..."
|
||||
bind:value={tavilyKey}
|
||||
onblur={() => saveKey('web.tavily_api_key', tavilyKey)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">{$t('admin.webTavilyHint')}</p>
|
||||
</div>
|
||||
<!-- Conditionally mounted API key fields -->
|
||||
{@const provider = config['web.search_provider'] || 'auto'}
|
||||
|
||||
{:else if provider === 'brave'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1">{$t('admin.webBraveKey')}</label>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="BSA..."
|
||||
bind:value={braveKey}
|
||||
onblur={() => saveKey('web.brave_api_key', braveKey)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">{$t('admin.webBraveHint')}</p>
|
||||
</div>
|
||||
|
||||
{:else if provider === 'duckduckgo'}
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-2">{$t('admin.webDuckDuckGoNote')}</p>
|
||||
{#if provider === 'auto'}
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-2">{$t('admin.webAutoHint')}</p>
|
||||
{:else if provider === 'exa'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1"
|
||||
>{$t('admin.webExaKey')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="exa-..."
|
||||
bind:value={exaKey}
|
||||
onblur={() => saveKey('web.exa_api_key', exaKey)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{$t('admin.webExaHint')}
|
||||
</p>
|
||||
</div>
|
||||
{:else if provider === 'tavily'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1"
|
||||
>{$t('admin.webTavilyKey')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="tvly-..."
|
||||
bind:value={tavilyKey}
|
||||
onblur={() => saveKey('web.tavily_api_key', tavilyKey)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{$t('admin.webTavilyHint')}
|
||||
</p>
|
||||
</div>
|
||||
{:else if provider === 'brave'}
|
||||
<div class="mt-3">
|
||||
<label class="block text-[13px] text-gray-700 dark:text-gray-300 mb-1"
|
||||
>{$t('admin.webBraveKey')}</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
class="w-full text-[13px] bg-gray-50 dark:bg-white/4 border border-gray-200 dark:border-white/8 rounded-lg px-2.5 py-1.5 outline-none text-gray-700 dark:text-gray-300 placeholder:text-gray-400 dark:placeholder:text-gray-600"
|
||||
placeholder="BSA..."
|
||||
bind:value={braveKey}
|
||||
onblur={() => saveKey('web.brave_api_key', braveKey)}
|
||||
disabled={saving}
|
||||
/>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">
|
||||
{$t('admin.webBraveHint')}
|
||||
</p>
|
||||
</div>
|
||||
{:else if provider === 'duckduckgo'}
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-2">
|
||||
{$t('admin.webDuckDuckGoNote')}
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => toast.success($t('settings.saved'))}
|
||||
>{$t('settings.save')}</button>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => toast.success($t('settings.saved'))}>{$t('settings.save')}</button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -28,13 +28,16 @@
|
||||
|
||||
let totalPages = $derived(Math.max(1, Math.ceil(users.length / PAGE_SIZE)));
|
||||
let pagedUsers = $derived(users.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE));
|
||||
let adminCount = $derived(users.filter(u => u.role === 'admin').length);
|
||||
let adminCount = $derived(users.filter((u) => u.role === 'admin').length);
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
users = await listUsers();
|
||||
} catch { toast.error($t('admin.failedToLoadUsers')); }
|
||||
finally { loading = false; }
|
||||
} catch {
|
||||
toast.error($t('admin.failedToLoadUsers'));
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCreated() {
|
||||
@@ -55,7 +58,7 @@
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white">{$t('admin.users')}</h2>
|
||||
<button
|
||||
class="flex items-center justify-center w-6 h-6 rounded-lg text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75"
|
||||
onclick={() => showCreate = true}
|
||||
onclick={() => (showCreate = true)}
|
||||
>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
@@ -63,21 +66,31 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else}
|
||||
<div>
|
||||
{#each pagedUsers as user}
|
||||
<button
|
||||
class="group flex items-center gap-2 w-full h-7 text-left"
|
||||
onclick={() => editUser = user}
|
||||
onclick={() => (editUser = user)}
|
||||
>
|
||||
<img src={user.profile_image_url || '/user.png'} alt="" class="w-4 h-4 rounded-full object-cover shrink-0" />
|
||||
<span class="flex-1 text-[13px] text-gray-700 dark:text-gray-300 truncate">{user.display_name || user.username}</span>
|
||||
<span class="text-[11px] transition-colors duration-75
|
||||
{user.role === 'admin' ? 'text-gray-900 dark:text-white font-medium'
|
||||
: 'text-gray-400 dark:text-gray-600'}"
|
||||
>{user.role}</span>
|
||||
<img
|
||||
src={user.profile_image_url || '/user.png'}
|
||||
alt=""
|
||||
class="w-4 h-4 rounded-full object-cover shrink-0"
|
||||
/>
|
||||
<span class="flex-1 text-[13px] text-gray-700 dark:text-gray-300 truncate"
|
||||
>{user.display_name || user.username}</span
|
||||
>
|
||||
<span
|
||||
class="text-[11px] transition-colors duration-75
|
||||
{user.role === 'admin'
|
||||
? 'text-gray-900 dark:text-white font-medium'
|
||||
: 'text-gray-400 dark:text-gray-600'}">{user.role}</span
|
||||
>
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
@@ -87,26 +100,34 @@
|
||||
</div>
|
||||
|
||||
{#if totalPages > 1}
|
||||
<div class="flex items-center justify-between mt-4 pt-3 border-t border-gray-200 dark:border-white/6">
|
||||
<div
|
||||
class="flex items-center justify-between mt-4 pt-3 border-t border-gray-200 dark:border-white/6"
|
||||
>
|
||||
<button
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors disabled:opacity-30 disabled:pointer-events-none"
|
||||
disabled={page === 0}
|
||||
onclick={() => page--}
|
||||
>← {$t('admin.prev').replace('← ', '')}</button>
|
||||
onclick={() => page--}>← {$t('admin.prev').replace('← ', '')}</button
|
||||
>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">{page + 1} / {totalPages}</span>
|
||||
<button
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors disabled:opacity-30 disabled:pointer-events-none"
|
||||
disabled={page >= totalPages - 1}
|
||||
onclick={() => page++}
|
||||
>{$t('admin.next')}</button>
|
||||
onclick={() => page++}>{$t('admin.next')}</button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if showCreate}
|
||||
<CreateUserModal onclose={() => showCreate = false} oncreated={handleCreated} />
|
||||
<CreateUserModal onclose={() => (showCreate = false)} oncreated={handleCreated} />
|
||||
{/if}
|
||||
|
||||
{#if editUser}
|
||||
<EditUserModal user={editUser} {adminCount} currentUserId={$session?.user_id ?? ''} onclose={() => editUser = null} onchanged={handleChanged} />
|
||||
<EditUserModal
|
||||
user={editUser}
|
||||
{adminCount}
|
||||
currentUserId={$session?.user_id ?? ''}
|
||||
onclose={() => (editUser = null)}
|
||||
onchanged={handleChanged}
|
||||
/>
|
||||
{/if}
|
||||
@@ -1,57 +1,57 @@
|
||||
<script lang="ts">
|
||||
import Icon from "./Icon.svelte";
|
||||
import Modal from "./Modal.svelte";
|
||||
import Users from "./Admin/Users.svelte";
|
||||
import Connections from "./Admin/Connections.svelte";
|
||||
import AdminSettings from "./Admin/Settings.svelte";
|
||||
import { t } from '$lib/i18n';
|
||||
import Icon from './Icon.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import Users from './Admin/Users.svelte';
|
||||
import Connections from './Admin/Connections.svelte';
|
||||
import AdminSettings from './Admin/Settings.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
}
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
}
|
||||
|
||||
let { onclose }: Props = $props();
|
||||
let { onclose }: Props = $props();
|
||||
|
||||
let activeTab = $state<"users" | "connections" | "settings">("users");
|
||||
let activeTab = $state<'users' | 'connections' | 'settings'>('users');
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
{onclose}
|
||||
class="w-full max-w-3xl mx-4 md:mx-0 flex flex-col md:flex-row max-h-[85vh] md:h-[560px]"
|
||||
{onclose}
|
||||
class="w-full max-w-3xl mx-4 md:mx-0 flex flex-col md:flex-row max-h-[85vh] md:h-[560px]"
|
||||
>
|
||||
<nav
|
||||
class="shrink-0 border-b md:border-b-0 md:border-r border-gray-200 dark:border-white/6 md:w-[180px]"
|
||||
>
|
||||
<div class="flex md:flex-col p-1 gap-px">
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-75 md:mb-1"
|
||||
onclick={onclose}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span>{$t('settings.back')}</span>
|
||||
</button>
|
||||
{#each [{ id: "users", label: $t('admin.users'), icon: "user" }, { id: "connections", label: $t('admin.connections'), icon: "plug" }, { id: "settings", label: $t('admin.settings'), icon: "settings" }] as tab}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-left transition-colors duration-75
|
||||
<nav
|
||||
class="shrink-0 border-b md:border-b-0 md:border-r border-gray-200 dark:border-white/6 md:w-[180px]"
|
||||
>
|
||||
<div class="flex md:flex-col p-1 gap-px">
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-75 md:mb-1"
|
||||
onclick={onclose}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span>{$t('settings.back')}</span>
|
||||
</button>
|
||||
{#each [{ id: 'users', label: $t('admin.users'), icon: 'user' }, { id: 'connections', label: $t('admin.connections'), icon: 'plug' }, { id: 'settings', label: $t('admin.settings'), icon: 'settings' }] as tab}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-left transition-colors duration-75
|
||||
{activeTab === tab.id
|
||||
? 'font-medium text-gray-900 dark:text-white bg-gray-100 dark:bg-white/6'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => (activeTab = tab.id as typeof activeTab)}
|
||||
>
|
||||
<Icon name={tab.icon} size={14} />
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
? 'font-medium text-gray-900 dark:text-white bg-gray-100 dark:bg-white/6'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => (activeTab = tab.id as typeof activeTab)}
|
||||
>
|
||||
<Icon name={tab.icon} size={14} />
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="flex-1 overflow-y-auto min-h-0 p-4 md:px-5">
|
||||
{#if activeTab === "users"}
|
||||
<Users />
|
||||
{:else if activeTab === "connections"}
|
||||
<Connections />
|
||||
{:else if activeTab === "settings"}
|
||||
<AdminSettings />
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-1 overflow-y-auto min-h-0 p-4 md:px-5">
|
||||
{#if activeTab === 'users'}
|
||||
<Users />
|
||||
{:else if activeTab === 'connections'}
|
||||
<Connections />
|
||||
{:else if activeTab === 'settings'}
|
||||
<AdminSettings />
|
||||
{/if}
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -22,9 +22,18 @@
|
||||
const isSetup = mode === 'password' && needsSetup;
|
||||
|
||||
async function submit() {
|
||||
if (isSetup && password.length < 6) { toast.error($t('auth.minChars')); return; }
|
||||
if (!username.trim()) { toast.error($t('auth.usernameRequired')); return; }
|
||||
if (!password) { toast.error($t('auth.passwordRequired')); return; }
|
||||
if (isSetup && password.length < 6) {
|
||||
toast.error($t('auth.minChars'));
|
||||
return;
|
||||
}
|
||||
if (!username.trim()) {
|
||||
toast.error($t('auth.usernameRequired'));
|
||||
return;
|
||||
}
|
||||
if (!password) {
|
||||
toast.error($t('auth.passwordRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
try {
|
||||
@@ -65,13 +74,19 @@
|
||||
<h1 class="text-lg font-semibold tracking-tight text-gray-900 dark:text-white mb-3">cptr</h1>
|
||||
|
||||
{#if isSetup}
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 -mt-2 mb-3">{$t('auth.createAccountHint')}</p>
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 -mt-2 mb-3">
|
||||
{$t('auth.createAccountHint')}
|
||||
</p>
|
||||
{:else if mode === 'pam'}
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 -mt-2 mb-3">{$t('auth.signInSystemHint')}</p>
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 -mt-2 mb-3">
|
||||
{$t('auth.signInSystemHint')}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<form onsubmit={handleSubmit} action="javascript:void(0)">
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-1">{isSetup ? $t('auth.setup') : isSignup ? $t('auth.signUp') : $t('auth.signIn')}</h2>
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{isSetup ? $t('auth.setup') : isSignup ? $t('auth.signUp') : $t('auth.signIn')}
|
||||
</h2>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('auth.username')}
|
||||
@@ -96,9 +111,15 @@
|
||||
disabled:opacity-30 disabled:pointer-events-none mt-2"
|
||||
>
|
||||
{#if loading}
|
||||
<div class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{isSetup ? $t('auth.createAccountBtn') : isSignup ? $t('auth.signUpBtn') : $t('auth.signInBtn')}
|
||||
{isSetup
|
||||
? $t('auth.createAccountBtn')
|
||||
: isSignup
|
||||
? $t('auth.signUpBtn')
|
||||
: $t('auth.signInBtn')}
|
||||
{/if}
|
||||
</button>
|
||||
</form>
|
||||
@@ -107,10 +128,24 @@
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-4">
|
||||
{#if isSignup}
|
||||
{$t('auth.alreadyHaveAccount')}
|
||||
<button type="button" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors" onclick={() => { isSignup = false; password = ''; }}>{$t('auth.signInLink')}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors"
|
||||
onclick={() => {
|
||||
isSignup = false;
|
||||
password = '';
|
||||
}}>{$t('auth.signInLink')}</button
|
||||
>
|
||||
{:else}
|
||||
{$t('auth.dontHaveAccount')}
|
||||
<button type="button" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors" onclick={() => { isSignup = true; password = ''; }}>{$t('auth.signUpLink')}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors"
|
||||
onclick={() => {
|
||||
isSignup = true;
|
||||
password = '';
|
||||
}}>{$t('auth.signUpLink')}</button
|
||||
>
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
sidebarOpen,
|
||||
splitActive,
|
||||
splitCurrentTab,
|
||||
setSplitDirection,
|
||||
setSplitDirection
|
||||
} from '$lib/stores';
|
||||
import type { SplitDirection } from '$lib/stores';
|
||||
import Icon from './Icon.svelte';
|
||||
@@ -33,14 +33,20 @@
|
||||
label: 'Split Right',
|
||||
icon: 'split-horizontal',
|
||||
active: direction === 'horizontal',
|
||||
onclick: () => { setSplitDirection('horizontal'); if (!$splitActive) splitCurrentTab('horizontal'); },
|
||||
onclick: () => {
|
||||
setSplitDirection('horizontal');
|
||||
if (!$splitActive) splitCurrentTab('horizontal');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Split Down',
|
||||
icon: 'split-vertical',
|
||||
active: direction === 'vertical',
|
||||
onclick: () => { setSplitDirection('vertical'); if (!$splitActive) splitCurrentTab('vertical'); },
|
||||
},
|
||||
onclick: () => {
|
||||
setSplitDirection('vertical');
|
||||
if (!$splitActive) splitCurrentTab('vertical');
|
||||
}
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
@@ -57,17 +63,26 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<nav class="flex items-center h-9 px-1.5 gap-1 shrink-0 select-none border-b border-gray-200 dark:border-white/6">
|
||||
<nav
|
||||
class="flex items-center h-9 px-1.5 gap-1 shrink-0 select-none border-b border-gray-200 dark:border-white/6"
|
||||
>
|
||||
<!-- Sidebar toggle (only when closed) -->
|
||||
{#if !$sidebarOpen}
|
||||
<button class="flex items-center justify-center w-7 h-7 rounded-md text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100" onclick={toggleSidebar} aria-label={$t('bar.toggleSidebar')} use:tooltip={$t('bar.sidebar')}>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-md text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={toggleSidebar}
|
||||
aria-label={$t('bar.toggleSidebar')}
|
||||
use:tooltip={$t('bar.sidebar')}
|
||||
>
|
||||
<Icon name="sidebar-expand" size={14} />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<!-- Workspace name -->
|
||||
{#if $activeWorkspace}
|
||||
<span class="text-[11px] font-medium text-gray-500 dark:text-gray-500 px-1 truncate flex-1 min-w-0">
|
||||
<span
|
||||
class="text-[11px] font-medium text-gray-500 dark:text-gray-500 px-1 truncate flex-1 min-w-0"
|
||||
>
|
||||
{$activeWorkspace.name}
|
||||
</span>
|
||||
{:else}
|
||||
@@ -82,20 +97,27 @@
|
||||
bind:this={splitBtnEl}
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg transition-colors duration-100 shrink-0
|
||||
{$splitActive
|
||||
? 'bg-gray-200 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => showSplitMenu = !showSplitMenu}
|
||||
? 'bg-gray-200 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => (showSplitMenu = !showSplitMenu)}
|
||||
aria-label="Split Editor"
|
||||
use:tooltip={'Split Editor'}
|
||||
>
|
||||
<Icon name={$activeWorkspace?.splitDirection === 'vertical' ? 'split-vertical' : 'split-horizontal'} size={14} />
|
||||
<Icon
|
||||
name={$activeWorkspace?.splitDirection === 'vertical'
|
||||
? 'split-vertical'
|
||||
: 'split-horizontal'}
|
||||
size={14}
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{#if showSplitMenu && splitBtnEl}
|
||||
<DropdownMenu items={splitMenuItems} anchor={splitBtnEl} onclose={() => showSplitMenu = false} />
|
||||
<DropdownMenu
|
||||
items={splitMenuItems}
|
||||
anchor={splitBtnEl}
|
||||
onclose={() => (showSplitMenu = false)}
|
||||
/>
|
||||
{/if}
|
||||
@@ -42,7 +42,20 @@
|
||||
if (!dateStr) return '';
|
||||
const parts = dateStr.split('-');
|
||||
if (parts.length !== 3) return dateStr;
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
const months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec'
|
||||
];
|
||||
const year = parts[0];
|
||||
const monthIdx = parseInt(parts[1], 10) - 1;
|
||||
const day = parseInt(parts[2], 10);
|
||||
@@ -57,7 +70,9 @@
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white">What's New</h2>
|
||||
{#if selectedData}
|
||||
{@const [ver, data] = selectedData}
|
||||
<p class="mt-0.5 text-[11px] text-gray-400 dark:text-gray-600">v{ver} · {formatDate(data.date)}</p>
|
||||
<p class="mt-0.5 text-[11px] text-gray-400 dark:text-gray-600">
|
||||
v{ver} · {formatDate(data.date)}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -76,11 +91,13 @@
|
||||
<button
|
||||
class="h-7 shrink-0 rounded-lg px-2 text-[11px] transition-colors duration-75
|
||||
{(selectedVersion ?? versions[0][0]) === ver
|
||||
? 'bg-gray-100 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300'}"
|
||||
? 'bg-gray-100 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => (selectedVersion = ver)}
|
||||
>
|
||||
v{ver}{#if i === 0}<span class="ml-1 font-sans text-[9px] text-gray-300 dark:text-gray-700">latest</span>{/if}
|
||||
v{ver}{#if i === 0}<span
|
||||
class="ml-1 font-sans text-[9px] text-gray-300 dark:text-gray-700">latest</span
|
||||
>{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -93,19 +110,31 @@
|
||||
{#each Object.entries(data).filter(([key]) => key !== 'date') as [section, items]}
|
||||
{#if Array.isArray(items) && items.length > 0}
|
||||
<section>
|
||||
<h3 class="mb-2 text-[10px] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-600">{section}</h3>
|
||||
<h3
|
||||
class="mb-2 text-[10px] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
{section}
|
||||
</h3>
|
||||
<ul class="space-y-2.5">
|
||||
{#each items as entry}
|
||||
<li class="flex gap-2.5 text-xs leading-relaxed">
|
||||
<span class="mt-[0.45em] h-1 w-1 shrink-0 rounded-full bg-gray-300 dark:bg-gray-700"></span>
|
||||
<span
|
||||
class="mt-[0.45em] h-1 w-1 shrink-0 rounded-full bg-gray-300 dark:bg-gray-700"
|
||||
></span>
|
||||
<div class="min-w-0">
|
||||
{#if entry.title}
|
||||
<span class="font-medium text-gray-900 dark:text-white">{entry.title}</span>
|
||||
<span class="font-medium text-gray-900 dark:text-white"
|
||||
>{entry.title}</span
|
||||
>
|
||||
{#if entry.content}
|
||||
<span class="ml-1 text-gray-500 dark:text-gray-400">{entry.content}</span>
|
||||
<span class="ml-1 text-gray-500 dark:text-gray-400"
|
||||
>{entry.content}</span
|
||||
>
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="text-gray-600 dark:text-gray-400">{entry.content || entry.raw}</span>
|
||||
<span class="text-gray-600 dark:text-gray-400"
|
||||
>{entry.content || entry.raw}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</li>
|
||||
@@ -127,7 +156,9 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col items-center justify-center py-16 gap-3">
|
||||
<div class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"></div>
|
||||
<div
|
||||
class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"
|
||||
></div>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">Loading release notes...</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<button
|
||||
class="flex items-center gap-1.5 w-full text-left"
|
||||
onclick={() => expanded = !expanded}
|
||||
>
|
||||
<span class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 dark:text-gray-600 transition-transform duration-100" style="transform: rotate({expanded ? '90deg' : '0deg'})">
|
||||
<button class="flex items-center gap-1.5 w-full text-left" onclick={() => (expanded = !expanded)}>
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 dark:text-gray-600 transition-transform duration-100"
|
||||
style="transform: rotate({expanded ? '90deg' : '0deg'})"
|
||||
>
|
||||
<Icon name="chevron-right" size={11} />
|
||||
</span>
|
||||
<span class="text-xs text-gray-400 dark:text-gray-600">{title}</span>
|
||||
{#if !expanded && summary}
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono ml-auto truncate max-w-[60%] text-right">{summary}</span>
|
||||
<span
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 font-mono ml-auto truncate max-w-[60%] text-right"
|
||||
>{summary}</span
|
||||
>
|
||||
{/if}
|
||||
</button>
|
||||
{#if expanded}
|
||||
|
||||
@@ -55,10 +55,12 @@
|
||||
$effect(() => {
|
||||
selectedIndex = -1;
|
||||
history = [];
|
||||
getWelcome().then(d => {
|
||||
const home = d.suggestions?.[0]?.path || '/';
|
||||
fetchDirectories(home);
|
||||
}).catch(() => fetchDirectories('/'));
|
||||
getWelcome()
|
||||
.then((d) => {
|
||||
const home = d.suggestions?.[0]?.path || '/';
|
||||
fetchDirectories(home);
|
||||
})
|
||||
.catch(() => fetchDirectories('/'));
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
@@ -126,12 +128,18 @@
|
||||
pathInputValue = '';
|
||||
pathValid = 'idle';
|
||||
tabHint = '';
|
||||
if (validateTimer) { clearTimeout(validateTimer); validateTimer = null; }
|
||||
if (validateTimer) {
|
||||
clearTimeout(validateTimer);
|
||||
validateTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function confirmPath() {
|
||||
const val = pathInputValue.trim();
|
||||
if (!val) { cancelEditing(); return; }
|
||||
if (!val) {
|
||||
cancelEditing();
|
||||
return;
|
||||
}
|
||||
editingPath = false;
|
||||
pathValid = 'idle';
|
||||
tabHint = '';
|
||||
@@ -142,7 +150,10 @@
|
||||
tabHint = '';
|
||||
if (validateTimer) clearTimeout(validateTimer);
|
||||
const val = pathInputValue.trim();
|
||||
if (!val) { pathValid = 'idle'; return; }
|
||||
if (!val) {
|
||||
pathValid = 'idle';
|
||||
return;
|
||||
}
|
||||
pathValid = 'checking';
|
||||
validateTimer = setTimeout(async () => {
|
||||
try {
|
||||
@@ -163,7 +174,9 @@
|
||||
const partial = val.substring(lastSlash + 1).toLowerCase();
|
||||
try {
|
||||
const data = await listDir(parent);
|
||||
const dirs = data.entries.filter((e: DirEntry) => e.type === 'directory').map((e: DirEntry) => e.name);
|
||||
const dirs = data.entries
|
||||
.filter((e: DirEntry) => e.type === 'directory')
|
||||
.map((e: DirEntry) => e.name);
|
||||
if (partial) {
|
||||
const matches = dirs.filter((n: string) => n.toLowerCase().startsWith(partial));
|
||||
if (matches.length === 1) {
|
||||
@@ -197,15 +210,27 @@
|
||||
}
|
||||
|
||||
function handlePathKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); confirmPath(); }
|
||||
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); cancelEditing(); }
|
||||
else if (e.key === 'Tab') { e.preventDefault(); e.stopPropagation(); tabComplete(); }
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
confirmPath();
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
cancelEditing();
|
||||
} else if (e.key === 'Tab') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
tabComplete();
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (editingPath) return;
|
||||
switch (e.key) {
|
||||
case 'Escape': onclose(); break;
|
||||
case 'Escape':
|
||||
onclose();
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
e.preventDefault();
|
||||
selectedIndex = Math.min(selectedIndex + 1, filteredDirs.length - 1);
|
||||
@@ -223,7 +248,10 @@
|
||||
}
|
||||
break;
|
||||
case 'Backspace':
|
||||
if (history.length > 0) { e.preventDefault(); goBack(); }
|
||||
if (history.length > 0) {
|
||||
e.preventDefault();
|
||||
goBack();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -244,7 +272,11 @@
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center" onmousedown={onclose} onkeydown={() => {}}>
|
||||
<div
|
||||
class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center"
|
||||
onmousedown={onclose}
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="w-full max-w-[560px] bg-white dark:bg-[#111] dark:border dark:border-white/8 rounded-3xl max-md:rounded-none overflow-hidden shadow-2xl flex flex-col"
|
||||
@@ -253,7 +285,9 @@
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
<!-- Path bar -->
|
||||
<div class="flex items-center gap-2 px-4 h-11 border-b border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-2 px-4 h-11 border-b border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
{#if history.length > 0}
|
||||
<button
|
||||
class="flex items-center justify-center w-6 h-6 rounded text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100 shrink-0"
|
||||
@@ -273,13 +307,19 @@
|
||||
class="flex-1 border-none outline-none bg-transparent text-xs text-gray-900 dark:text-white font-mono placeholder:text-gray-400"
|
||||
oninput={onPathInput}
|
||||
onkeydown={handlePathKeydown}
|
||||
onblur={() => { requestAnimationFrame(() => { if (editingPath) cancelEditing(); }); }}
|
||||
onblur={() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (editingPath) cancelEditing();
|
||||
});
|
||||
}}
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
placeholder={$t('directory.typePath')}
|
||||
/>
|
||||
{#if pathValid === 'checking'}
|
||||
<div class="w-3 h-3 border-[1.5px] border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin shrink-0"></div>
|
||||
<div
|
||||
class="w-3 h-3 border-[1.5px] border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin shrink-0"
|
||||
></div>
|
||||
{:else if pathValid === 'valid'}
|
||||
<span class="text-green-500 shrink-0 flex"><Icon name="check" size={12} /></span>
|
||||
{:else if pathValid === 'invalid'}
|
||||
@@ -288,7 +328,10 @@
|
||||
{#if tabHint}
|
||||
<span class="text-[10px] text-gray-400 whitespace-nowrap shrink-0">{tabHint}</span>
|
||||
{/if}
|
||||
<span class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0">TAB</span>
|
||||
<span
|
||||
class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0"
|
||||
>TAB</span
|
||||
>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
@@ -297,24 +340,35 @@
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={startEditing}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') startEditing(); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') startEditing();
|
||||
}}
|
||||
>
|
||||
{#each breadcrumbs as seg, i (seg.path)}
|
||||
{#if i > 1}<span class="text-gray-300 dark:text-gray-600 text-[11px] font-mono">/</span>{/if}
|
||||
{#if i > 1}<span class="text-gray-300 dark:text-gray-600 text-[11px] font-mono">/</span
|
||||
>{/if}
|
||||
{#if i === breadcrumbs.length - 1}
|
||||
<span class="text-[11px] font-mono font-medium text-gray-900 dark:text-white whitespace-nowrap overflow-hidden text-ellipsis">{seg.name}</span>
|
||||
<span
|
||||
class="text-[11px] font-mono font-medium text-gray-900 dark:text-white whitespace-nowrap overflow-hidden text-ellipsis"
|
||||
>{seg.name}</span
|
||||
>
|
||||
{:else}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="text-[11px] font-mono text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 whitespace-nowrap shrink-0 cursor-pointer rounded px-0.5 hover:bg-gray-200 dark:hover:bg-white/8 transition-colors duration-75"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => { e.stopPropagation(); navigateToPath(seg.path); }}
|
||||
onkeydown={() => {}}
|
||||
>{seg.name}</span>
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
navigateToPath(seg.path);
|
||||
}}
|
||||
onkeydown={() => {}}>{seg.name}</span
|
||||
>
|
||||
{/if}
|
||||
{/each}
|
||||
<span class="ml-1 text-gray-300 dark:text-gray-700 opacity-0 group-hover:opacity-100 transition-opacity duration-150 shrink-0 flex items-center">
|
||||
<span
|
||||
class="ml-1 text-gray-300 dark:text-gray-700 opacity-0 group-hover:opacity-100 transition-opacity duration-150 shrink-0 flex items-center"
|
||||
>
|
||||
<Icon name="pencil" size={10} />
|
||||
</span>
|
||||
</div>
|
||||
@@ -330,15 +384,17 @@
|
||||
<div bind:this={listEl} class="flex-1 overflow-y-auto p-1 min-h-0">
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-8">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center gap-2 py-8 text-center">
|
||||
<p class="text-xs text-red-400">{error}</p>
|
||||
<button
|
||||
class="text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 px-3 py-1 rounded-lg bg-gray-100 dark:bg-white/6 transition-colors duration-100"
|
||||
onclick={() => fetchDirectories(currentPath)}
|
||||
>{$t('directory.retry')}</button>
|
||||
onclick={() => fetchDirectories(currentPath)}>{$t('directory.retry')}</button
|
||||
>
|
||||
</div>
|
||||
{:else if filteredDirs.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-8">
|
||||
@@ -350,31 +406,48 @@
|
||||
data-index={i}
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-lg text-left transition-colors duration-75
|
||||
{i === selectedIndex
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
onclick={() => navigateTo(dir.name)}
|
||||
ondblclick={(e) => { e.stopPropagation(); const fullPath = currentPath === '/' ? `/${dir.name}` : `${currentPath}/${dir.name}`; addWorkspace(fullPath); goto(`/?workspace=${encodeURIComponent(fullPath)}`); onclose(); }}
|
||||
onmouseenter={() => { selectedIndex = i; }}
|
||||
ondblclick={(e) => {
|
||||
e.stopPropagation();
|
||||
const fullPath = currentPath === '/' ? `/${dir.name}` : `${currentPath}/${dir.name}`;
|
||||
addWorkspace(fullPath);
|
||||
goto(`/?workspace=${encodeURIComponent(fullPath)}`);
|
||||
onclose();
|
||||
}}
|
||||
onmouseenter={() => {
|
||||
selectedIndex = i;
|
||||
}}
|
||||
>
|
||||
<Icon name="folder" size={14} class="shrink-0 text-gray-400" />
|
||||
<span class="flex-1 truncate text-xs">{dir.name}</span>
|
||||
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-300 dark:text-gray-700" />
|
||||
<Icon
|
||||
name="chevron-right"
|
||||
size={12}
|
||||
class="shrink-0 text-gray-300 dark:text-gray-700"
|
||||
/>
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="flex items-center gap-2 px-3 py-2 border-t border-gray-200 dark:border-white/6 shrink-0">
|
||||
<span class="flex-1 text-[11px] text-gray-400 dark:text-gray-600 font-mono truncate min-w-0" title={currentPath}>{currentPath}</span>
|
||||
<div
|
||||
class="flex items-center gap-2 px-3 py-2 border-t border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
<span
|
||||
class="flex-1 text-[11px] text-gray-400 dark:text-gray-600 font-mono truncate min-w-0"
|
||||
title={currentPath}>{currentPath}</span
|
||||
>
|
||||
<button
|
||||
class="text-xs font-medium text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 px-3 py-1.5 rounded-lg transition-colors duration-100 shrink-0"
|
||||
onclick={onclose}
|
||||
>{$t('directory.cancel')}</button>
|
||||
onclick={onclose}>{$t('directory.cancel')}</button
|
||||
>
|
||||
<button
|
||||
class="text-xs font-medium text-white dark:text-black bg-gray-900 dark:bg-white hover:bg-gray-800 dark:hover:bg-gray-200 px-3 py-1.5 rounded-lg transition-colors duration-100 shrink-0"
|
||||
onclick={selectCurrent}
|
||||
>{$t('directory.open', { name: currentFolderName })}</button>
|
||||
onclick={selectCurrent}>{$t('directory.open', { name: currentFolderName })}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -35,7 +35,17 @@
|
||||
align?: 'start' | 'end';
|
||||
}
|
||||
|
||||
let { items, anchor, onclose, matchWidth = false, preferAbove = false, maxHeight, header, className = '', align = 'start' }: Props = $props();
|
||||
let {
|
||||
items,
|
||||
anchor,
|
||||
onclose,
|
||||
matchWidth = false,
|
||||
preferAbove = false,
|
||||
maxHeight,
|
||||
header,
|
||||
className = '',
|
||||
align = 'start'
|
||||
}: Props = $props();
|
||||
|
||||
let menuEl: HTMLDivElement | undefined = $state();
|
||||
let pos = $state<{ x: number; top?: number; bottom?: number }>({ x: -9999 });
|
||||
@@ -111,13 +121,24 @@
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="fixed inset-0 z-[100]" onclick={onclose} oncontextmenu={(e) => { e.preventDefault(); onclose(); }}></div>
|
||||
<div
|
||||
class="fixed inset-0 z-[100]"
|
||||
onclick={onclose}
|
||||
oncontextmenu={(e) => {
|
||||
e.preventDefault();
|
||||
onclose();
|
||||
}}
|
||||
></div>
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
bind:this={menuEl}
|
||||
class="fixed z-[101] min-w-36 rounded-xl bg-white dark:bg-[#1a1a1a] border border-gray-150 dark:border-white/6 shadow-xl p-0.5 {className}"
|
||||
style="left: {pos.x}px; {pos.bottom != null ? `bottom: ${pos.bottom}px` : `top: ${pos.top ?? -9999}px`}; {anchorWidth ? `width: ${anchorWidth}px;` : ''} opacity: {ready ? 1 : 0}; pointer-events: {ready ? 'auto' : 'none'};"
|
||||
style="left: {pos.x}px; {pos.bottom != null
|
||||
? `bottom: ${pos.bottom}px`
|
||||
: `top: ${pos.top ?? -9999}px`}; {anchorWidth ? `width: ${anchorWidth}px;` : ''} opacity: {ready
|
||||
? 1
|
||||
: 0}; pointer-events: {ready ? 'auto' : 'none'};"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
onmousedown={(e) => e.stopPropagation()}
|
||||
>
|
||||
@@ -133,8 +154,13 @@
|
||||
{:else}
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-6 px-2 rounded-xl text-xs transition-colors duration-75
|
||||
{item.active ? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5' : 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
|
||||
onclick={() => { item.onclick(); onclose(); }}
|
||||
{item.active
|
||||
? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
|
||||
onclick={() => {
|
||||
item.onclick();
|
||||
onclose();
|
||||
}}
|
||||
>
|
||||
{#if item.image}
|
||||
<img src={item.image} alt="" class="w-4 h-4 rounded-full object-cover shrink-0" />
|
||||
@@ -146,7 +172,15 @@
|
||||
<KeyPill text={item.shortcut} class="ml-auto shrink-0" />
|
||||
{/if}
|
||||
{#if item.check && item.active}
|
||||
<svg class="w-3 h-3 shrink-0 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3 shrink-0 text-gray-400 dark:text-gray-500"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
{/if}
|
||||
|
||||
@@ -8,7 +8,14 @@
|
||||
import { activeWorkspace, setFileBrowserCwd, openFileTab, openPreviewTab } from '$lib/stores';
|
||||
import { systemEvents } from '$lib/stores/systemEvents.svelte';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { listDir, downloadArchive, deleteFiles, moveFile, uploadFiles as apiUpload, createEntry } from '$lib/apis/files';
|
||||
import {
|
||||
listDir,
|
||||
downloadArchive,
|
||||
deleteFiles,
|
||||
moveFile,
|
||||
uploadFiles as apiUpload,
|
||||
createEntry
|
||||
} from '$lib/apis/files';
|
||||
import { fileIconName } from '$lib/utils/fileIcon';
|
||||
import Icon from './Icon.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
@@ -38,7 +45,9 @@
|
||||
let newName = $state('');
|
||||
let dropzoneActive = $state(false);
|
||||
let addMenuOpen = $state(false);
|
||||
let showHidden = $state(typeof localStorage !== 'undefined' && localStorage.getItem('fileBrowser:showHidden') === 'true');
|
||||
let showHidden = $state(
|
||||
typeof localStorage !== 'undefined' && localStorage.getItem('fileBrowser:showHidden') === 'true'
|
||||
);
|
||||
let sortMenuOpen = $state(false);
|
||||
let sortBtnEl: HTMLButtonElement | undefined = $state();
|
||||
let addBtnEl: HTMLButtonElement | undefined = $state();
|
||||
@@ -57,7 +66,9 @@
|
||||
let dragOverBreadcrumb = $state<string | null>(null);
|
||||
|
||||
// Context menu
|
||||
let contextMenu = $state<{ x: number; y: number; entry: TreeEntry; anchor?: HTMLElement } | null>(null);
|
||||
let contextMenu = $state<{ x: number; y: number; entry: TreeEntry; anchor?: HTMLElement } | null>(
|
||||
null
|
||||
);
|
||||
let renamingEntry = $state<string | null>(null);
|
||||
let renameValue = $state('');
|
||||
|
||||
@@ -66,8 +77,10 @@
|
||||
|
||||
// Ports from this workspace's terminals
|
||||
let workspacePorts = $derived(
|
||||
systemEvents.ports.filter((p) =>
|
||||
p.session_id && $activeWorkspace?.groups.some((g) => g.tabs.some((t) => t.sessionId === p.session_id))
|
||||
systemEvents.ports.filter(
|
||||
(p) =>
|
||||
p.session_id &&
|
||||
$activeWorkspace?.groups.some((g) => g.tabs.some((t) => t.sessionId === p.session_id))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -306,9 +319,7 @@
|
||||
const query = searchQuery.toLowerCase();
|
||||
|
||||
function walk(parentPath: string, items: FileEntry[], depth: number) {
|
||||
let filtered = query
|
||||
? items.filter((e) => e.name.toLowerCase().includes(query))
|
||||
: items;
|
||||
let filtered = query ? items.filter((e) => e.name.toLowerCase().includes(query)) : items;
|
||||
for (const entry of sortItems(filtered)) {
|
||||
const fullPath = parentPath.endsWith('/')
|
||||
? parentPath + entry.name
|
||||
@@ -370,7 +381,9 @@
|
||||
if (selectedPaths.size === 0) return;
|
||||
if (!confirm($t('files.deleteItemConfirm', { count: selectedPaths.size }))) return;
|
||||
for (const path of selectedPaths) {
|
||||
try { await deleteFiles([path]); } catch {}
|
||||
try {
|
||||
await deleteFiles([path]);
|
||||
} catch {}
|
||||
}
|
||||
clearSelection();
|
||||
fetchDirectory(cwd);
|
||||
@@ -475,7 +488,9 @@
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
form.append('directory', directory);
|
||||
try { await apiUpload(directory, form); } catch {}
|
||||
try {
|
||||
await apiUpload(directory, form);
|
||||
} catch {}
|
||||
}
|
||||
fetchDirectory(cwd);
|
||||
}
|
||||
@@ -588,8 +603,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="flex flex-col h-full overflow-hidden relative"
|
||||
@@ -598,7 +611,9 @@
|
||||
ondrop={onDropzoneDrop}
|
||||
>
|
||||
<!-- Header: breadcrumb + actions -->
|
||||
<div class="flex items-center gap-2 h-9 px-3 border-b border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-2 h-9 px-3 border-b border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
<div class="flex items-center gap-1 text-xs min-w-0 flex-1">
|
||||
{#each breadcrumbs() as seg, i}
|
||||
{#if i > 0}<span class="text-gray-300 dark:text-gray-600">/</span>{/if}
|
||||
@@ -606,21 +621,25 @@
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="font-medium truncate transition-colors duration-75
|
||||
{dragOverBreadcrumb === seg.path ? 'text-gray-900 dark:text-white bg-gray-200 dark:bg-white/10 rounded px-1 -mx-1' : 'text-gray-900 dark:text-white'}"
|
||||
{dragOverBreadcrumb === seg.path
|
||||
? 'text-gray-900 dark:text-white bg-gray-200 dark:bg-white/10 rounded px-1 -mx-1'
|
||||
: 'text-gray-900 dark:text-white'}"
|
||||
ondragover={(e) => onBreadcrumbDragOver(e, seg.path)}
|
||||
ondragleave={onBreadcrumbDragLeave}
|
||||
ondrop={(e) => onBreadcrumbDrop(e, seg.path)}
|
||||
>{seg.name}</span>
|
||||
ondrop={(e) => onBreadcrumbDrop(e, seg.path)}>{seg.name}</span
|
||||
>
|
||||
{:else}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<button
|
||||
class="shrink-0 transition-colors duration-75
|
||||
{dragOverBreadcrumb === seg.path ? 'text-gray-900 dark:text-white bg-gray-200 dark:bg-white/10 rounded px-1 -mx-1' : 'text-gray-500 hover:text-gray-900 dark:hover:text-white'}"
|
||||
{dragOverBreadcrumb === seg.path
|
||||
? 'text-gray-900 dark:text-white bg-gray-200 dark:bg-white/10 rounded px-1 -mx-1'
|
||||
: 'text-gray-500 hover:text-gray-900 dark:hover:text-white'}"
|
||||
onclick={() => navigateTo(seg.path)}
|
||||
ondragover={(e) => onBreadcrumbDragOver(e, seg.path)}
|
||||
ondragleave={onBreadcrumbDragLeave}
|
||||
ondrop={(e) => onBreadcrumbDrop(e, seg.path)}
|
||||
>{seg.name}</button>
|
||||
ondrop={(e) => onBreadcrumbDrop(e, seg.path)}>{seg.name}</button
|
||||
>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
@@ -638,7 +657,9 @@
|
||||
<button
|
||||
bind:this={sortBtnEl}
|
||||
class="flex items-center justify-center w-5 h-5 rounded text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 shrink-0"
|
||||
onclick={() => { sortMenuOpen = !sortMenuOpen; }}
|
||||
onclick={() => {
|
||||
sortMenuOpen = !sortMenuOpen;
|
||||
}}
|
||||
use:tooltip={$t('files.sort')}
|
||||
>
|
||||
<Icon name="sort" size={11} />
|
||||
@@ -648,7 +669,9 @@
|
||||
<button
|
||||
bind:this={addBtnEl}
|
||||
class="flex items-center justify-center w-5 h-5 rounded text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 shrink-0"
|
||||
onclick={() => { toggleAddMenu(); }}
|
||||
onclick={() => {
|
||||
toggleAddMenu();
|
||||
}}
|
||||
use:tooltip={$t('files.actions')}
|
||||
>
|
||||
<Icon name="three-dots" size={11} />
|
||||
@@ -657,20 +680,24 @@
|
||||
|
||||
<!-- Ports -->
|
||||
{#if workspacePorts.length > 0}
|
||||
<div class="flex items-center gap-1.5 h-7 px-3 border-b border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-1.5 h-7 px-3 border-b border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
<span class="text-[10px] text-gray-400 shrink-0">{$t('files.ports')}</span>
|
||||
{#each workspacePorts as p (p.port)}
|
||||
<button
|
||||
class="px-1.5 py-0.5 rounded text-[11px] font-mono font-medium text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={() => openPreviewTab(p.port)}
|
||||
use:tooltip={$t('files.clickToPreview', { process: p.process })}
|
||||
>:{p.port}</button>
|
||||
use:tooltip={$t('files.clickToPreview', { process: p.process })}>:{p.port}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Search -->
|
||||
<div class="flex items-center gap-1.5 h-8 px-3 border-b border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-1.5 h-8 px-3 border-b border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
<Icon name="search" size={13} class="text-gray-400 shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
@@ -679,7 +706,7 @@
|
||||
bind:value={searchQuery}
|
||||
/>
|
||||
{#if searchQuery}
|
||||
<button class="text-gray-400 flex items-center" onclick={() => searchQuery = ''}>
|
||||
<button class="text-gray-400 flex items-center" onclick={() => (searchQuery = '')}>
|
||||
<Icon name="xmark" size={11} />
|
||||
</button>
|
||||
{/if}
|
||||
@@ -692,19 +719,34 @@
|
||||
<!-- New item input -->
|
||||
{#if showNewInput}
|
||||
<div class="flex items-center gap-2 h-7 px-2">
|
||||
<Icon name={showNewInput === 'folder' ? 'folder' : 'empty-page'} size={14} class="text-gray-400 shrink-0" />
|
||||
<Icon
|
||||
name={showNewInput === 'folder' ? 'folder' : 'empty-page'}
|
||||
size={14}
|
||||
class="text-gray-400 shrink-0"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
class="flex-1 border-none outline-none bg-transparent text-xs text-gray-900 dark:text-white"
|
||||
placeholder={showNewInput === 'folder' ? $t('files.folderNamePlaceholder') : $t('files.fileNamePlaceholder')}
|
||||
placeholder={showNewInput === 'folder'
|
||||
? $t('files.folderNamePlaceholder')
|
||||
: $t('files.fileNamePlaceholder')}
|
||||
bind:value={newName}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') confirmNew(); if (e.key === 'Escape') cancelNew(); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') confirmNew();
|
||||
if (e.key === 'Escape') cancelNew();
|
||||
}}
|
||||
autofocus
|
||||
/>
|
||||
<button class="flex items-center justify-center w-5 h-5 rounded text-green-500 hover:bg-green-50 dark:hover:bg-green-500/10 transition-colors duration-75" onclick={confirmNew}>
|
||||
<button
|
||||
class="flex items-center justify-center w-5 h-5 rounded text-green-500 hover:bg-green-50 dark:hover:bg-green-500/10 transition-colors duration-75"
|
||||
onclick={confirmNew}
|
||||
>
|
||||
<Icon name="check" size={12} />
|
||||
</button>
|
||||
<button class="flex items-center justify-center w-5 h-5 rounded text-gray-400 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75" onclick={cancelNew}>
|
||||
<button
|
||||
class="flex items-center justify-center w-5 h-5 rounded text-gray-400 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={cancelNew}
|
||||
>
|
||||
<Icon name="xmark" size={12} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -712,15 +754,17 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center py-12 gap-2">
|
||||
<p class="text-xs text-red-400">{error}</p>
|
||||
<button
|
||||
class="text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 px-3 py-1 rounded-lg bg-gray-100 dark:bg-white/6 transition-colors duration-100"
|
||||
onclick={() => fetchDirectory(cwd)}
|
||||
>{$t('files.retry')}</button>
|
||||
onclick={() => fetchDirectory(cwd)}>{$t('files.retry')}</button
|
||||
>
|
||||
</div>
|
||||
{:else if visibleEntries.length === 0 && !showNewInput}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
@@ -732,13 +776,23 @@
|
||||
{#each visibleEntries as entry, i (entry.path)}
|
||||
{#if renamingEntry === entry.path}
|
||||
<!-- Inline rename -->
|
||||
<div class="flex items-center gap-2 h-7" style="padding-left: {8 + entry.depth * 16}px; padding-right: 8px;">
|
||||
<Icon name={fileIconName(entry.name, entry.type)} size={14} class="text-gray-400 shrink-0" />
|
||||
<div
|
||||
class="flex items-center gap-2 h-7"
|
||||
style="padding-left: {8 + entry.depth * 16}px; padding-right: 8px;"
|
||||
>
|
||||
<Icon
|
||||
name={fileIconName(entry.name, entry.type)}
|
||||
size={14}
|
||||
class="text-gray-400 shrink-0"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
class="flex-1 border-none outline-none bg-transparent text-xs text-gray-900 dark:text-white"
|
||||
bind:value={renameValue}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') confirmRename(entry.path); if (e.key === 'Escape') renamingEntry = null; }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') confirmRename(entry.path);
|
||||
if (e.key === 'Escape') renamingEntry = null;
|
||||
}}
|
||||
onblur={() => confirmRename(entry.path)}
|
||||
autofocus
|
||||
/>
|
||||
@@ -748,7 +802,11 @@
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<button
|
||||
class="group flex items-center gap-1 w-full h-7 rounded-lg text-left transition-colors duration-75
|
||||
{isSelected ? 'bg-blue-50 dark:bg-blue-500/10' : dragOverDir === entry.path ? 'bg-blue-100 dark:bg-blue-500/20' : 'hover:bg-gray-100 dark:hover:bg-white/4'}"
|
||||
{isSelected
|
||||
? 'bg-blue-50 dark:bg-blue-500/10'
|
||||
: dragOverDir === entry.path
|
||||
? 'bg-blue-100 dark:bg-blue-500/20'
|
||||
: 'hover:bg-gray-100 dark:hover:bg-white/4'}"
|
||||
style="padding-left: {8 + entry.depth * 16}px; padding-right: 8px;"
|
||||
onclick={(e) => handleClick(e, entry, i)}
|
||||
oncontextmenu={(e) => onContextMenu(e, entry)}
|
||||
@@ -760,13 +818,22 @@
|
||||
ondragend={onDragEnd}
|
||||
>
|
||||
{#if entry.type === 'directory'}
|
||||
<span class="flex items-center justify-center w-4 shrink-0 text-gray-400 dark:text-gray-600">
|
||||
<Icon name={expandedDirs.has(entry.path) ? 'chevron-down' : 'chevron-right'} size={10} />
|
||||
<span
|
||||
class="flex items-center justify-center w-4 shrink-0 text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
<Icon
|
||||
name={expandedDirs.has(entry.path) ? 'chevron-down' : 'chevron-right'}
|
||||
size={10}
|
||||
/>
|
||||
</span>
|
||||
{:else}
|
||||
<span class="w-4 shrink-0"></span>
|
||||
{/if}
|
||||
<span class="flex items-center justify-center w-4 shrink-0 {entry.type === 'directory' ? 'text-gray-500 dark:text-gray-400' : 'text-gray-400 dark:text-gray-500'}">
|
||||
<span
|
||||
class="flex items-center justify-center w-4 shrink-0 {entry.type === 'directory'
|
||||
? 'text-gray-500 dark:text-gray-400'
|
||||
: 'text-gray-400 dark:text-gray-500'}"
|
||||
>
|
||||
<Icon name={fileIconName(entry.name, entry.type)} size={14} strokeWidth={1.4} />
|
||||
</span>
|
||||
{#if entry.type === 'directory'}
|
||||
@@ -775,14 +842,26 @@
|
||||
class="flex-1 text-xs text-gray-800 dark:text-gray-200 truncate hover:underline cursor-pointer"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => { e.stopPropagation(); setFileBrowserCwd(entry.path); }}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') { e.stopPropagation(); setFileBrowserCwd(entry.path); } }}
|
||||
>{entry.name}</span>
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
setFileBrowserCwd(entry.path);
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.stopPropagation();
|
||||
setFileBrowserCwd(entry.path);
|
||||
}
|
||||
}}>{entry.name}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="flex-1 text-xs text-gray-800 dark:text-gray-200 truncate">{entry.name}</span>
|
||||
<span class="flex-1 text-xs text-gray-800 dark:text-gray-200 truncate"
|
||||
>{entry.name}</span
|
||||
>
|
||||
{/if}
|
||||
{#if entry.type !== 'directory' && entry.size !== null}
|
||||
<span class="text-[11px] font-mono text-gray-400 dark:text-gray-600 shrink-0">{formatSize(entry.size)}</span>
|
||||
<span class="text-[11px] font-mono text-gray-400 dark:text-gray-600 shrink-0"
|
||||
>{formatSize(entry.size)}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- Three-dot menu per entry -->
|
||||
<span
|
||||
@@ -790,7 +869,9 @@
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => openEntryMenu(e, entry)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') openEntryMenu(e, entry); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') openEntryMenu(e, entry);
|
||||
}}
|
||||
aria-label={$t('files.moreActions')}
|
||||
>
|
||||
<Icon name="three-dots" size={12} />
|
||||
@@ -803,34 +884,40 @@
|
||||
|
||||
<!-- Upload dropzone overlay -->
|
||||
{#if dropzoneActive}
|
||||
<div class="absolute inset-0 bg-blue-500/10 border-2 border-dashed border-blue-400 dark:border-blue-500 rounded-lg flex items-center justify-center z-10 pointer-events-none">
|
||||
<div
|
||||
class="absolute inset-0 bg-blue-500/10 border-2 border-dashed border-blue-400 dark:border-blue-500 rounded-lg flex items-center justify-center z-10 pointer-events-none"
|
||||
>
|
||||
<p class="text-xs font-medium text-blue-500 dark:text-blue-400">{$t('files.dropToUpload')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Multi-select action bar -->
|
||||
{#if selectedPaths.size > 0}
|
||||
<div class="flex items-center justify-between h-8 px-2 border-t border-gray-200 dark:border-white/6 shrink-0 bg-blue-50 dark:bg-blue-500/5">
|
||||
<span class="text-[11px] font-medium text-blue-600 dark:text-blue-400">{$t('files.selected', { count: selectedPaths.size })}</span>
|
||||
<div
|
||||
class="flex items-center justify-between h-8 px-2 border-t border-gray-200 dark:border-white/6 shrink-0 bg-blue-50 dark:bg-blue-500/5"
|
||||
>
|
||||
<span class="text-[11px] font-medium text-blue-600 dark:text-blue-400"
|
||||
>{$t('files.selected', { count: selectedPaths.size })}</span
|
||||
>
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-colors duration-75"
|
||||
onclick={selectAll}
|
||||
>{$t('files.all')}</button>
|
||||
onclick={selectAll}>{$t('files.all')}</button
|
||||
>
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-colors duration-75"
|
||||
onclick={archiveSelected}
|
||||
use:tooltip={$t('files.downloadAsZip')}
|
||||
><Icon name="download" size={12} /></button>
|
||||
use:tooltip={$t('files.downloadAsZip')}><Icon name="download" size={12} /></button
|
||||
>
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-red-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10 transition-colors duration-75"
|
||||
onclick={deleteSelected}
|
||||
use:tooltip={$t('files.deleteSelected')}
|
||||
><Icon name="trash" size={12} /></button>
|
||||
use:tooltip={$t('files.deleteSelected')}><Icon name="trash" size={12} /></button
|
||||
>
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75"
|
||||
onclick={clearSelection}
|
||||
><Icon name="xmark" size={11} /></button>
|
||||
onclick={clearSelection}><Icon name="xmark" size={11} /></button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -840,11 +927,27 @@
|
||||
<DropdownMenu
|
||||
anchor={sortBtnEl}
|
||||
items={[
|
||||
{ label: $t('files.name'), icon: sortBy === 'name' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined, active: sortBy === 'name', onclick: () => toggleSort('name') },
|
||||
{ label: $t('files.size'), icon: sortBy === 'size' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined, active: sortBy === 'size', onclick: () => toggleSort('size') },
|
||||
{ label: $t('files.date'), icon: sortBy === 'modified' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined, active: sortBy === 'modified', onclick: () => toggleSort('modified') },
|
||||
{
|
||||
label: $t('files.name'),
|
||||
icon: sortBy === 'name' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined,
|
||||
active: sortBy === 'name',
|
||||
onclick: () => toggleSort('name')
|
||||
},
|
||||
{
|
||||
label: $t('files.size'),
|
||||
icon: sortBy === 'size' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined,
|
||||
active: sortBy === 'size',
|
||||
onclick: () => toggleSort('size')
|
||||
},
|
||||
{
|
||||
label: $t('files.date'),
|
||||
icon:
|
||||
sortBy === 'modified' ? (sortDir === 'asc' ? 'chevron-up' : 'chevron-down') : undefined,
|
||||
active: sortBy === 'modified',
|
||||
onclick: () => toggleSort('modified')
|
||||
}
|
||||
]}
|
||||
onclose={() => sortMenuOpen = false}
|
||||
onclose={() => (sortMenuOpen = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -857,9 +960,13 @@
|
||||
{ label: '', divider: true, onclick: () => {} },
|
||||
{ label: $t('files.uploadFile'), icon: 'upload', onclick: () => handleUploadFromMenu() },
|
||||
{ label: '', divider: true, onclick: () => {} },
|
||||
{ label: showHidden ? $t('files.hideHidden') : $t('files.showHidden'), icon: 'eye', onclick: () => toggleHidden() },
|
||||
{
|
||||
label: showHidden ? $t('files.hideHidden') : $t('files.showHidden'),
|
||||
icon: 'eye',
|
||||
onclick: () => toggleHidden()
|
||||
}
|
||||
]}
|
||||
onclose={() => addMenuOpen = false}
|
||||
onclose={() => (addMenuOpen = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -869,9 +976,15 @@
|
||||
items={[
|
||||
{ label: $t('files.rename'), icon: 'pencil', onclick: () => startRename(contextMenu!.entry) },
|
||||
...(contextMenu.entry.type !== 'directory'
|
||||
? [{ label: $t('files.download'), icon: 'download', onclick: () => downloadEntry(contextMenu!.entry) }]
|
||||
? [
|
||||
{
|
||||
label: $t('files.download'),
|
||||
icon: 'download',
|
||||
onclick: () => downloadEntry(contextMenu!.entry)
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{ label: $t('files.delete'), icon: 'xmark', onclick: () => deleteEntry(contextMenu!.entry) },
|
||||
{ label: $t('files.delete'), icon: 'xmark', onclick: () => deleteEntry(contextMenu!.entry) }
|
||||
]}
|
||||
onclose={closeMenu}
|
||||
/>
|
||||
|
||||
@@ -18,9 +18,26 @@
|
||||
import SvgPreview from './preview/SvgPreview.svelte';
|
||||
import OfficePreview from './preview/OfficePreview.svelte';
|
||||
import { EditorState } from '@codemirror/state';
|
||||
import { EditorView, keymap, lineNumbers, highlightActiveLineGutter, highlightSpecialChars, drawSelection, highlightActiveLine, rectangularSelection } from '@codemirror/view';
|
||||
import {
|
||||
EditorView,
|
||||
keymap,
|
||||
lineNumbers,
|
||||
highlightActiveLineGutter,
|
||||
highlightSpecialChars,
|
||||
drawSelection,
|
||||
highlightActiveLine,
|
||||
rectangularSelection
|
||||
} from '@codemirror/view';
|
||||
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
||||
import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, bracketMatching, foldGutter, foldKeymap, StreamLanguage } from '@codemirror/language';
|
||||
import {
|
||||
syntaxHighlighting,
|
||||
defaultHighlightStyle,
|
||||
indentOnInput,
|
||||
bracketMatching,
|
||||
foldGutter,
|
||||
foldKeymap,
|
||||
StreamLanguage
|
||||
} from '@codemirror/language';
|
||||
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
|
||||
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
@@ -152,8 +169,10 @@
|
||||
}
|
||||
|
||||
function diffBlockClass(type: DiffLine['type']): string {
|
||||
if (type === 'added') return 'bg-green-100 border-l-[3px] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
if (type === 'removed') return 'bg-red-100 border-l-[3px] border-l-red-400 dark:bg-red-500/15 dark:border-l-red-400';
|
||||
if (type === 'added')
|
||||
return 'bg-green-100 border-l-[3px] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
if (type === 'removed')
|
||||
return 'bg-red-100 border-l-[3px] border-l-red-400 dark:bg-red-500/15 dark:border-l-red-400';
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -177,35 +196,63 @@
|
||||
|
||||
// Editing state: true when the code editor should be active
|
||||
let isEditing = $derived(
|
||||
fileData && !fileData.binary && !isBinaryPreview && !isCsv && (
|
||||
isMarkdown ? markdownMode === 'raw' :
|
||||
(isHtml || isSvg) ? !previewMode :
|
||||
isJson ? (jsonViewMode === 'source' || jsonParseError) :
|
||||
true
|
||||
)
|
||||
fileData &&
|
||||
!fileData.binary &&
|
||||
!isBinaryPreview &&
|
||||
!isCsv &&
|
||||
(isMarkdown
|
||||
? markdownMode === 'raw'
|
||||
: isHtml || isSvg
|
||||
? !previewMode
|
||||
: isJson
|
||||
? jsonViewMode === 'source' || jsonParseError
|
||||
: true)
|
||||
);
|
||||
|
||||
// ── Language support ─────────────────────────────────────────
|
||||
function getLanguageExtension(lang: string | null) {
|
||||
switch (lang) {
|
||||
case 'javascript': return javascript();
|
||||
case 'typescript': return javascript({ typescript: true });
|
||||
case 'jsx': return javascript({ jsx: true });
|
||||
case 'tsx': return javascript({ jsx: true, typescript: true });
|
||||
case 'python': return python();
|
||||
case 'json': return json();
|
||||
case 'css': return css();
|
||||
case 'html': return html();
|
||||
case 'svelte': return html();
|
||||
case 'markdown': return markdown();
|
||||
case 'rust': return rust();
|
||||
case 'c': case 'cpp': return cpp();
|
||||
case 'java': case 'kotlin': return java();
|
||||
case 'sql': return sql();
|
||||
case 'xml': return xml();
|
||||
case 'yaml': return yaml();
|
||||
case 'bash': case 'shell': case 'sh': case 'zsh': return StreamLanguage.define(shell);
|
||||
default: return [];
|
||||
case 'javascript':
|
||||
return javascript();
|
||||
case 'typescript':
|
||||
return javascript({ typescript: true });
|
||||
case 'jsx':
|
||||
return javascript({ jsx: true });
|
||||
case 'tsx':
|
||||
return javascript({ jsx: true, typescript: true });
|
||||
case 'python':
|
||||
return python();
|
||||
case 'json':
|
||||
return json();
|
||||
case 'css':
|
||||
return css();
|
||||
case 'html':
|
||||
return html();
|
||||
case 'svelte':
|
||||
return html();
|
||||
case 'markdown':
|
||||
return markdown();
|
||||
case 'rust':
|
||||
return rust();
|
||||
case 'c':
|
||||
case 'cpp':
|
||||
return cpp();
|
||||
case 'java':
|
||||
case 'kotlin':
|
||||
return java();
|
||||
case 'sql':
|
||||
return sql();
|
||||
case 'xml':
|
||||
return xml();
|
||||
case 'yaml':
|
||||
return yaml();
|
||||
case 'bash':
|
||||
case 'shell':
|
||||
case 'sh':
|
||||
case 'zsh':
|
||||
return StreamLanguage.define(shell);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +281,7 @@
|
||||
size: 0,
|
||||
binary: false,
|
||||
content: '',
|
||||
language: null,
|
||||
language: null
|
||||
};
|
||||
requestAnimationFrame(() => initEditor('', null));
|
||||
}
|
||||
@@ -264,7 +311,14 @@
|
||||
if (res.ok) {
|
||||
fileData = await res.json();
|
||||
} else {
|
||||
fileData = { path, name: path.split('/').pop() ?? '', size: 0, binary: true, content: null, language: null };
|
||||
fileData = {
|
||||
path,
|
||||
name: path.split('/').pop() ?? '',
|
||||
size: 0,
|
||||
binary: true,
|
||||
content: null,
|
||||
language: null
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Text files
|
||||
@@ -307,7 +361,10 @@
|
||||
try {
|
||||
const ws = get(activeWorkspace);
|
||||
if (ws) {
|
||||
const status = await getGitStatus(ws.path) as { is_repo?: boolean; files?: { path: string }[] };
|
||||
const status = (await getGitStatus(ws.path)) as {
|
||||
is_repo?: boolean;
|
||||
files?: { path: string }[];
|
||||
};
|
||||
if (status?.is_repo && status.files) {
|
||||
const relPath = path.startsWith(ws.path)
|
||||
? path.slice(ws.path.replace(/\/$/, '').length + 1)
|
||||
@@ -342,7 +399,15 @@
|
||||
diffMode = false;
|
||||
diffFiles = [];
|
||||
// Restore editor if it was a text file
|
||||
if (fileData && !fileData.binary && !isBinaryPreview && !isCsv && !isMarkdown && !(isHtml || isSvg) && !(isJson && !jsonParseError)) {
|
||||
if (
|
||||
fileData &&
|
||||
!fileData.binary &&
|
||||
!isBinaryPreview &&
|
||||
!isCsv &&
|
||||
!isMarkdown &&
|
||||
!(isHtml || isSvg) &&
|
||||
!(isJson && !jsonParseError)
|
||||
) {
|
||||
requestAnimationFrame(() => initEditor(fileData!.content!, fileData!.language));
|
||||
}
|
||||
return;
|
||||
@@ -359,7 +424,7 @@
|
||||
? filePath.slice(ws.path.replace(/\/$/, '').length + 1)
|
||||
: filePath;
|
||||
const params = new URLSearchParams({ root: ws.path, file: relPath, staged: 'false' });
|
||||
const d = await getGitDiff(params.toString()) as { files?: DiffFileEntry[] };
|
||||
const d = (await getGitDiff(params.toString())) as { files?: DiffFileEntry[] };
|
||||
diffFiles = d.files ?? [];
|
||||
} catch {
|
||||
diffFiles = [];
|
||||
@@ -457,7 +522,13 @@
|
||||
...historyKeymap,
|
||||
...foldKeymap,
|
||||
indentWithTab,
|
||||
{ key: 'Mod-s', run: () => { saveFile(); return true; } },
|
||||
{
|
||||
key: 'Mod-s',
|
||||
run: () => {
|
||||
saveFile();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]),
|
||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
||||
...(dark ? [oneDark] : []),
|
||||
@@ -472,19 +543,19 @@
|
||||
'&': {
|
||||
height: '100%',
|
||||
fontSize: '13px',
|
||||
backgroundColor: dark ? '#000' : '#ffffff',
|
||||
backgroundColor: dark ? '#000' : '#ffffff'
|
||||
},
|
||||
'.cm-scroller': { fontFamily: '"JetBrains Mono", "Fira Code", ui-monospace, monospace' },
|
||||
'.cm-gutters': {
|
||||
backgroundColor: dark ? '#000' : '#ffffff',
|
||||
color: dark ? '#555' : '#999',
|
||||
border: 'none',
|
||||
border: 'none'
|
||||
},
|
||||
'.cm-activeLineGutter': { backgroundColor: dark ? '#1a1a1a' : '#f3f4f6' },
|
||||
'.cm-activeLine': { backgroundColor: dark ? '#1a1a1a' : '#f9fafb' },
|
||||
'&.cm-focused': { outline: 'none' },
|
||||
'&.cm-focused': { outline: 'none' }
|
||||
}),
|
||||
getLanguageExtension(language),
|
||||
getLanguageExtension(language)
|
||||
];
|
||||
|
||||
const state = EditorState.create({ doc: content, extensions });
|
||||
@@ -497,7 +568,10 @@
|
||||
initEditor(doc, language);
|
||||
}
|
||||
});
|
||||
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||||
themeObserver.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class']
|
||||
});
|
||||
}
|
||||
|
||||
function destroyEditor() {
|
||||
@@ -545,7 +619,9 @@
|
||||
loadedPath = path;
|
||||
}
|
||||
|
||||
setTimeout(() => { saved = false; }, 2000);
|
||||
setTimeout(() => {
|
||||
saved = false;
|
||||
}, 2000);
|
||||
} catch (e: any) {
|
||||
error = e.message;
|
||||
} finally {
|
||||
@@ -581,66 +657,82 @@
|
||||
<div class="toolbar-right">
|
||||
{#if isMarkdown && !fileData.binary}
|
||||
<button
|
||||
class="toolbar-btn" class:active={markdownMode === 'preview'}
|
||||
class="toolbar-btn"
|
||||
class:active={markdownMode === 'preview'}
|
||||
onclick={() => switchMarkdownMode('preview')}
|
||||
use:tooltip={'Preview'}
|
||||
><Icon name="eye" size={12} /></button>
|
||||
use:tooltip={'Preview'}><Icon name="eye" size={12} /></button
|
||||
>
|
||||
<button
|
||||
class="toolbar-btn" class:active={markdownMode === 'editor'}
|
||||
class="toolbar-btn"
|
||||
class:active={markdownMode === 'editor'}
|
||||
onclick={() => switchMarkdownMode('editor')}
|
||||
use:tooltip={'Editor'}
|
||||
><Icon name="pencil" size={11} /></button>
|
||||
use:tooltip={'Editor'}><Icon name="pencil" size={11} /></button
|
||||
>
|
||||
<button
|
||||
class="toolbar-btn" class:active={markdownMode === 'raw'}
|
||||
class="toolbar-btn"
|
||||
class:active={markdownMode === 'raw'}
|
||||
onclick={() => switchMarkdownMode('raw')}
|
||||
use:tooltip={'Source'}
|
||||
><Icon name="code" size={12} /></button>
|
||||
use:tooltip={'Source'}><Icon name="code" size={12} /></button
|
||||
>
|
||||
{:else if (isHtml || isSvg) && !fileData.binary}
|
||||
<button
|
||||
class="toolbar-btn" class:active={previewMode}
|
||||
onclick={() => { if (!previewMode) togglePreview(); }}
|
||||
use:tooltip={'Preview'}
|
||||
><Icon name="eye" size={12} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={previewMode}
|
||||
onclick={() => {
|
||||
if (!previewMode) togglePreview();
|
||||
}}
|
||||
use:tooltip={'Preview'}><Icon name="eye" size={12} /></button
|
||||
>
|
||||
<button
|
||||
class="toolbar-btn" class:active={!previewMode}
|
||||
onclick={() => { if (previewMode) togglePreview(); }}
|
||||
use:tooltip={'Edit'}
|
||||
><Icon name="pencil" size={11} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={!previewMode}
|
||||
onclick={() => {
|
||||
if (previewMode) togglePreview();
|
||||
}}
|
||||
use:tooltip={'Edit'}><Icon name="pencil" size={11} /></button
|
||||
>
|
||||
{/if}
|
||||
{#if isJson && !fileData.binary && !jsonParseError}
|
||||
<button
|
||||
class="toolbar-btn" class:active={jsonViewMode === 'tree'}
|
||||
onclick={() => { if (jsonViewMode !== 'tree') toggleJsonView(); }}
|
||||
use:tooltip={'Tree view'}
|
||||
><Icon name="list" size={12} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={jsonViewMode === 'tree'}
|
||||
onclick={() => {
|
||||
if (jsonViewMode !== 'tree') toggleJsonView();
|
||||
}}
|
||||
use:tooltip={'Tree view'}><Icon name="list" size={12} /></button
|
||||
>
|
||||
<button
|
||||
class="toolbar-btn" class:active={jsonViewMode === 'source'}
|
||||
onclick={() => { if (jsonViewMode !== 'source') toggleJsonView(); }}
|
||||
use:tooltip={'Source'}
|
||||
><Icon name="code" size={12} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={jsonViewMode === 'source'}
|
||||
onclick={() => {
|
||||
if (jsonViewMode !== 'source') toggleJsonView();
|
||||
}}
|
||||
use:tooltip={'Source'}><Icon name="code" size={12} /></button
|
||||
>
|
||||
{/if}
|
||||
{#if isEditing || markdownMode === 'editor' || hasChanges || saving || saved}
|
||||
<button
|
||||
class="toolbar-btn {saved ? 'saved' : ''}"
|
||||
onclick={saveFile}
|
||||
disabled={saving}
|
||||
use:tooltip={saving ? 'Saving...' : saved ? 'Saved' : 'Save'}
|
||||
><Icon name={saved ? 'check' : 'save'} size={11} /></button
|
||||
>
|
||||
{/if}
|
||||
{#if !isUntitled && hasGitChanges}
|
||||
<button
|
||||
class="toolbar-btn"
|
||||
class:active={diffMode}
|
||||
onclick={toggleDiff}
|
||||
use:tooltip={diffMode ? 'Hide diff' : 'Show diff'}
|
||||
><Icon name="git-diff" size={12} /></button
|
||||
>
|
||||
{/if}
|
||||
{#if !isUntitled}
|
||||
<button class="toolbar-btn" onclick={() => loadFile(filePath)} use:tooltip={'Refresh'}
|
||||
><Icon name="refresh" size={11} /></button
|
||||
>
|
||||
{/if}
|
||||
{#if isEditing || markdownMode === 'editor' || hasChanges || saving || saved}
|
||||
<button
|
||||
class="toolbar-btn {saved ? 'saved' : ''}"
|
||||
onclick={saveFile}
|
||||
disabled={saving}
|
||||
use:tooltip={saving ? 'Saving...' : saved ? 'Saved' : 'Save'}
|
||||
><Icon name={saved ? 'check' : 'save'} size={11} /></button>
|
||||
{/if}
|
||||
{#if !isUntitled && hasGitChanges}
|
||||
<button
|
||||
class="toolbar-btn" class:active={diffMode}
|
||||
onclick={toggleDiff}
|
||||
use:tooltip={diffMode ? 'Hide diff' : 'Show diff'}
|
||||
><Icon name="git-diff" size={12} /></button>
|
||||
{/if}
|
||||
{#if !isUntitled}
|
||||
<button
|
||||
class="toolbar-btn"
|
||||
onclick={() => loadFile(filePath)}
|
||||
use:tooltip={'Refresh'}
|
||||
><Icon name="refresh" size={11} /></button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -651,45 +743,36 @@
|
||||
{:else if error}
|
||||
<div class="state error">{error}</div>
|
||||
|
||||
<!-- ── Binary previews ─────────────────────────────── -->
|
||||
<!-- ── Binary previews ─────────────────────────────── -->
|
||||
{:else if isImage && binaryUrl}
|
||||
<ImagePreview src={binaryUrl} alt={fileData?.name ?? ''} />
|
||||
|
||||
{:else if isPdf && binaryUrl}
|
||||
<PDFViewer src={binaryUrl} />
|
||||
|
||||
{:else if isVideo && binaryUrl}
|
||||
<div class="media-container">
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video controls preload="metadata" src={binaryUrl}></video>
|
||||
</div>
|
||||
|
||||
{:else if isAudio && binaryUrl}
|
||||
<div class="media-container">
|
||||
<audio controls preload="metadata" src={binaryUrl}></audio>
|
||||
</div>
|
||||
|
||||
{:else if isSqlite && binaryUrl}
|
||||
<SqliteView src={binaryUrl} />
|
||||
|
||||
{:else if isOffice && binaryUrl}
|
||||
<OfficePreview src={binaryUrl} fileName={fileData?.name ?? ''} />
|
||||
|
||||
<!-- ── Rich text previews ──────────────────────────── -->
|
||||
<!-- ── Rich text previews ──────────────────────────── -->
|
||||
{:else if isSvg && fileData?.content && previewMode}
|
||||
<SvgPreview content={fileData.content} />
|
||||
|
||||
{:else if isHtml && fileData?.content && previewMode}
|
||||
<HtmlPreview content={fileData.content} filePath={filePath} />
|
||||
|
||||
<HtmlPreview content={fileData.content} {filePath} />
|
||||
{:else if isJson && jsonData !== null && jsonViewMode === 'tree'}
|
||||
<div class="tree-container">
|
||||
<JsonTreeView data={jsonData} />
|
||||
</div>
|
||||
|
||||
{:else if isCsv && fileData?.content}
|
||||
<CsvTable content={fileData.content} separator={isTsv ? '\t' : ','} />
|
||||
|
||||
{:else if isMarkdown && fileData?.content !== null && fileData?.content !== undefined}
|
||||
{#if markdownMode === 'preview'}
|
||||
<div class="markdown-preview">
|
||||
@@ -703,20 +786,22 @@
|
||||
content={fileData.content}
|
||||
filePath={fileData.path}
|
||||
workspacePath={wsPath}
|
||||
onchange={() => { hasChanges = true; saved = false; markTabUnsaved(tabId, true); }}
|
||||
onchange={() => {
|
||||
hasChanges = true;
|
||||
saved = false;
|
||||
markTabUnsaved(tabId, true);
|
||||
}}
|
||||
onsave={saveFile}
|
||||
/>
|
||||
{:else if markdownMode === 'raw'}
|
||||
<div bind:this={editorEl} class="editor-el"></div>
|
||||
{/if}
|
||||
|
||||
{:else if fileData?.binary}
|
||||
<!-- Unknown binary, fallback -->
|
||||
<div class="state">
|
||||
<p class="state-title">Binary file</p>
|
||||
<p class="state-sub">{fileData.name} ({formatSize(fileData.size)})</p>
|
||||
</div>
|
||||
|
||||
{:else if diffMode}
|
||||
<!-- Diff view -->
|
||||
{#if diffLoading}
|
||||
@@ -730,7 +815,9 @@
|
||||
<div class="diff-scroll">
|
||||
{#each diffFiles as df}
|
||||
{#each df.hunks as hunk}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600 font-mono text-[11px]">
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600 font-mono text-[11px]"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
@@ -739,11 +826,23 @@
|
||||
{#each diffGroupLines(diffNumberedLines(hunk)) as group}
|
||||
<div class="w-full {diffBlockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] font-mono text-[11px] leading-[18px]">
|
||||
<span class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600">{line.oldNumber ?? ''}</span>
|
||||
<span class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600">{line.newNumber ?? ''}</span>
|
||||
<span class="select-none px-1 text-center {diffPrefixClass(line.type)}">{diffPrefix(line.type)}</span>
|
||||
<code class="whitespace-pre px-2 {diffTextClass(line.type)}">{line.content || ' '}</code>
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] font-mono text-[11px] leading-[18px]"
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.oldNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.newNumber ?? ''}</span
|
||||
>
|
||||
<span class="select-none px-1 text-center {diffPrefixClass(line.type)}"
|
||||
>{diffPrefix(line.type)}</span
|
||||
>
|
||||
<code class="whitespace-pre px-2 {diffTextClass(line.type)}"
|
||||
>{line.content || ' '}</code
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -753,7 +852,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- ┌ Code editor (default) ───────────────────── -->
|
||||
<!-- ┌ Code editor (default) ───────────────────── -->
|
||||
{:else}
|
||||
<div bind:this={editorEl} class="editor-el"></div>
|
||||
{/if}
|
||||
@@ -761,8 +860,11 @@
|
||||
{#if showSaveDialog}
|
||||
<SaveDialog
|
||||
defaultName={fileData?.name || 'Untitled'}
|
||||
initialDir={(() => { const ws = get(activeWorkspace); return ws?.path; })()}
|
||||
onclose={() => showSaveDialog = false}
|
||||
initialDir={(() => {
|
||||
const ws = get(activeWorkspace);
|
||||
return ws?.path;
|
||||
})()}
|
||||
onclose={() => (showSaveDialog = false)}
|
||||
onsave={handleSaveDialogSave}
|
||||
/>
|
||||
{/if}
|
||||
@@ -949,7 +1051,9 @@
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Diff view ────────────────────────────────────────── */
|
||||
@@ -957,7 +1061,7 @@
|
||||
.diff-scroll {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
@@ -995,8 +1099,12 @@
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
.diff-added .diff-prefix { color: #16a34a; }
|
||||
:global(.dark) .diff-added .diff-prefix { color: #4ade80; }
|
||||
.diff-added .diff-prefix {
|
||||
color: #16a34a;
|
||||
}
|
||||
:global(.dark) .diff-added .diff-prefix {
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.diff-removed {
|
||||
background: #fee2e2;
|
||||
@@ -1008,8 +1116,12 @@
|
||||
color: #fca5a5;
|
||||
}
|
||||
|
||||
.diff-removed .diff-prefix { color: #ef4444; }
|
||||
:global(.dark) .diff-removed .diff-prefix { color: #f87171; }
|
||||
.diff-removed .diff-prefix {
|
||||
color: #ef4444;
|
||||
}
|
||||
:global(.dark) .diff-removed .diff-prefix {
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.diff-ctx {
|
||||
color: var(--color-gray-600);
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { activeWorkspace, openFileTab } from '$lib/stores';
|
||||
import { getGitStatus, getGitLog, getGitDiff, getGitShow, getGitBranches, stageFiles, unstageFiles, discardChanges, gitCommit, gitPull, gitPush, checkoutBranch, createGitBranch } from '$lib/apis/git';
|
||||
import {
|
||||
getGitStatus,
|
||||
getGitLog,
|
||||
getGitDiff,
|
||||
getGitShow,
|
||||
getGitBranches,
|
||||
stageFiles,
|
||||
unstageFiles,
|
||||
discardChanges,
|
||||
gitCommit,
|
||||
gitPull,
|
||||
gitPush,
|
||||
checkoutBranch,
|
||||
createGitBranch
|
||||
} from '$lib/apis/git';
|
||||
import Icon from './Icon.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
@@ -40,8 +54,8 @@
|
||||
let containerEl = $state<HTMLElement | null>(null);
|
||||
|
||||
const workspacePath = $derived($activeWorkspace?.path ?? '');
|
||||
const stagedFiles = $derived((gitStatus?.files ?? []).filter(f => f.staged));
|
||||
const unstagedFiles = $derived((gitStatus?.files ?? []).filter(f => !f.staged));
|
||||
const stagedFiles = $derived((gitStatus?.files ?? []).filter((f) => f.staged));
|
||||
const unstagedFiles = $derived((gitStatus?.files ?? []).filter((f) => !f.staged));
|
||||
const totalChanges = $derived((gitStatus?.files ?? []).length);
|
||||
const allStaged = $derived(totalChanges > 0 && unstagedFiles.length === 0);
|
||||
const someStaged = $derived(stagedFiles.length > 0 && unstagedFiles.length > 0);
|
||||
@@ -59,7 +73,7 @@
|
||||
// Clear stale selection when file is no longer in the changed list
|
||||
$effect(() => {
|
||||
if (view === 'changes' && selectedFile) {
|
||||
const stillExists = (gitStatus?.files ?? []).some(f => f.path === selectedFile);
|
||||
const stillExists = (gitStatus?.files ?? []).some((f) => f.path === selectedFile);
|
||||
if (!stillExists) {
|
||||
selectedFile = null;
|
||||
fileDiff = [];
|
||||
@@ -70,7 +84,13 @@
|
||||
|
||||
// Auto-select first file
|
||||
$effect(() => {
|
||||
if (expanded && view === 'changes' && totalChanges > 0 && !selectedFile && window.innerWidth >= 768) {
|
||||
if (
|
||||
expanded &&
|
||||
view === 'changes' &&
|
||||
totalChanges > 0 &&
|
||||
!selectedFile &&
|
||||
window.innerWidth >= 768
|
||||
) {
|
||||
const f = [...stagedFiles, ...unstagedFiles][0];
|
||||
if (f) selectFile(f.path, f.staged, f.status === 'untracked');
|
||||
}
|
||||
@@ -80,7 +100,9 @@
|
||||
if (!workspacePath) return;
|
||||
try {
|
||||
gitStatus = await getGitStatus(workspacePath);
|
||||
} catch { /* silent */ }
|
||||
} catch {
|
||||
/* silent */
|
||||
}
|
||||
}
|
||||
|
||||
async function selectFile(path: string, staged: boolean, untracked: boolean = false) {
|
||||
@@ -88,11 +110,17 @@
|
||||
selectedCommit = null;
|
||||
showDiff = true;
|
||||
try {
|
||||
const params = new URLSearchParams({ root: workspacePath, file: path, staged: String(staged) });
|
||||
const params = new URLSearchParams({
|
||||
root: workspacePath,
|
||||
file: path,
|
||||
staged: String(staged)
|
||||
});
|
||||
if (untracked) params.set('untracked', 'true');
|
||||
const d = await getGitDiff(params.toString());
|
||||
fileDiff = d.files ?? [];
|
||||
} catch { fileDiff = []; }
|
||||
} catch {
|
||||
fileDiff = [];
|
||||
}
|
||||
}
|
||||
|
||||
async function selectCommit(c: Commit) {
|
||||
@@ -102,21 +130,29 @@
|
||||
try {
|
||||
const d = await getGitShow(workspacePath, c.hash);
|
||||
fileDiff = d.diff?.files ?? [];
|
||||
} catch { fileDiff = []; }
|
||||
} catch {
|
||||
fileDiff = [];
|
||||
}
|
||||
}
|
||||
|
||||
function backToList() { showDiff = false; }
|
||||
function backToList() {
|
||||
showDiff = false;
|
||||
}
|
||||
|
||||
async function loadHistory() {
|
||||
try {
|
||||
commits = await getGitLog(workspacePath, 50);
|
||||
} catch { commits = []; }
|
||||
} catch {
|
||||
commits = [];
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBranches() {
|
||||
try {
|
||||
branchData = await getGitBranches(workspacePath);
|
||||
} catch { branchData = null; }
|
||||
} catch {
|
||||
branchData = null;
|
||||
}
|
||||
}
|
||||
|
||||
function switchView(v: 'changes' | 'history') {
|
||||
@@ -140,9 +176,15 @@
|
||||
|
||||
async function toggleAll() {
|
||||
if (allStaged) {
|
||||
await unstageFiles(workspacePath, stagedFiles.map(f => f.path));
|
||||
await unstageFiles(
|
||||
workspacePath,
|
||||
stagedFiles.map((f) => f.path)
|
||||
);
|
||||
} else {
|
||||
await stageFiles(workspacePath, unstagedFiles.map(f => f.path));
|
||||
await stageFiles(
|
||||
workspacePath,
|
||||
unstagedFiles.map((f) => f.path)
|
||||
);
|
||||
}
|
||||
await refresh();
|
||||
}
|
||||
@@ -154,7 +196,11 @@
|
||||
? `${commitSummary.trim()}\n\n${commitDescription.trim()}`
|
||||
: commitSummary.trim();
|
||||
await gitCommit(workspacePath, msg);
|
||||
commitSummary = ''; commitDescription = ''; flash($t('git.committed')); selectedFile = null; fileDiff = [];
|
||||
commitSummary = '';
|
||||
commitDescription = '';
|
||||
flash($t('git.committed'));
|
||||
selectedFile = null;
|
||||
fileDiff = [];
|
||||
loading = false;
|
||||
await refresh();
|
||||
}
|
||||
@@ -163,14 +209,16 @@
|
||||
loading = true;
|
||||
const d = await gitPull(workspacePath);
|
||||
flash(d.ok ? $t('git.pulled') : d.message);
|
||||
loading = false; await refresh();
|
||||
loading = false;
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function doPush() {
|
||||
loading = true;
|
||||
const d = await gitPush(workspacePath);
|
||||
flash(d.ok ? $t('git.pushed') : d.message);
|
||||
loading = false; await refresh();
|
||||
loading = false;
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function switchBranch(branch: string) {
|
||||
@@ -192,7 +240,12 @@
|
||||
await refresh();
|
||||
}
|
||||
|
||||
function flash(m: string) { actionMsg = m; setTimeout(() => { actionMsg = ''; }, 3000); }
|
||||
function flash(m: string) {
|
||||
actionMsg = m;
|
||||
setTimeout(() => {
|
||||
actionMsg = '';
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Context menu
|
||||
let contextMenu = $state<{ file: GitFile; anchor: HTMLElement } | null>(null);
|
||||
@@ -208,7 +261,10 @@
|
||||
|
||||
async function discardFile(path: string) {
|
||||
await discardChanges(workspacePath, [path]);
|
||||
if (selectedFile === path) { selectedFile = null; fileDiff = []; }
|
||||
if (selectedFile === path) {
|
||||
selectedFile = null;
|
||||
fileDiff = [];
|
||||
}
|
||||
flash($t('git.discarded'));
|
||||
await refresh();
|
||||
}
|
||||
@@ -232,26 +288,45 @@
|
||||
|
||||
function relTime(d: string) {
|
||||
const s = Math.floor((Date.now() - new Date(d).getTime()) / 1000);
|
||||
if (s < 60) return 'now'; if (s < 3600) return `${Math.floor(s/60)}m`;
|
||||
if (s < 86400) return `${Math.floor(s/3600)}h`; return `${Math.floor(s/86400)}d`;
|
||||
if (s < 60) return 'now';
|
||||
if (s < 3600) return `${Math.floor(s / 60)}m`;
|
||||
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
||||
return `${Math.floor(s / 86400)}d`;
|
||||
}
|
||||
|
||||
function statusChar(s: string): { char: string; color: string } {
|
||||
switch (s) {
|
||||
case 'added': return { char: 'A', color: 'text-green-500' };
|
||||
case 'untracked': return { char: 'U', color: 'text-green-500' };
|
||||
case 'modified': return { char: 'M', color: 'text-amber-500' };
|
||||
case 'deleted': return { char: 'D', color: 'text-red-400' };
|
||||
case 'renamed': return { char: 'R', color: 'text-blue-400' };
|
||||
case 'conflict': return { char: '!', color: 'text-orange-500' };
|
||||
default: return { char: '?', color: 'text-gray-400' };
|
||||
case 'added':
|
||||
return { char: 'A', color: 'text-green-500' };
|
||||
case 'untracked':
|
||||
return { char: 'U', color: 'text-green-500' };
|
||||
case 'modified':
|
||||
return { char: 'M', color: 'text-amber-500' };
|
||||
case 'deleted':
|
||||
return { char: 'D', color: 'text-red-400' };
|
||||
case 'renamed':
|
||||
return { char: 'R', color: 'text-blue-400' };
|
||||
case 'conflict':
|
||||
return { char: '!', color: 'text-orange-500' };
|
||||
default:
|
||||
return { char: '?', color: 'text-gray-400' };
|
||||
}
|
||||
}
|
||||
|
||||
const syncAction = $derived.by(() => {
|
||||
if (!gitStatus) return { label: $t('git.fetch'), icon: 'refresh', action: doPull };
|
||||
if (gitStatus.behind > 0) return { label: $t('git.pullCount', { count: gitStatus.behind }), icon: 'download', action: doPull };
|
||||
if (gitStatus.ahead > 0) return { label: $t('git.pushCount', { count: gitStatus.ahead }), icon: 'upload', action: doPush };
|
||||
if (gitStatus.behind > 0)
|
||||
return {
|
||||
label: $t('git.pullCount', { count: gitStatus.behind }),
|
||||
icon: 'download',
|
||||
action: doPull
|
||||
};
|
||||
if (gitStatus.ahead > 0)
|
||||
return {
|
||||
label: $t('git.pushCount', { count: gitStatus.ahead }),
|
||||
icon: 'upload',
|
||||
action: doPush
|
||||
};
|
||||
return { label: $t('git.fetch'), icon: 'refresh', action: doPull };
|
||||
});
|
||||
|
||||
@@ -261,8 +336,14 @@
|
||||
const startY = e.clientY;
|
||||
const startH = panelHeight;
|
||||
const maxH = getMaxHeight();
|
||||
function onMove(ev: PointerEvent) { panelHeight = Math.max(140, Math.min(maxH, startH - (ev.clientY - startY))); }
|
||||
function onUp() { resizing = false; window.removeEventListener('pointermove', onMove); window.removeEventListener('pointerup', onUp); }
|
||||
function onMove(ev: PointerEvent) {
|
||||
panelHeight = Math.max(140, Math.min(maxH, startH - (ev.clientY - startY)));
|
||||
}
|
||||
function onUp() {
|
||||
resizing = false;
|
||||
window.removeEventListener('pointermove', onMove);
|
||||
window.removeEventListener('pointerup', onUp);
|
||||
}
|
||||
window.addEventListener('pointermove', onMove);
|
||||
window.addEventListener('pointerup', onUp);
|
||||
}
|
||||
@@ -310,51 +391,77 @@
|
||||
</script>
|
||||
|
||||
{#if gitStatus?.is_repo}
|
||||
<div class="shrink-0 border-t border-gray-200 dark:border-white/6 relative" bind:this={containerEl}>
|
||||
<div
|
||||
class="shrink-0 border-t border-gray-200 dark:border-white/6 relative"
|
||||
bind:this={containerEl}
|
||||
>
|
||||
<!-- Resize handle (top edge, styled like sidebar) -->
|
||||
{#if expanded}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="git-resize-handle"
|
||||
class:active={resizing}
|
||||
onpointerdown={onResizeStart}
|
||||
></div>
|
||||
<div class="git-resize-handle" class:active={resizing} onpointerdown={onResizeStart}></div>
|
||||
{/if}
|
||||
|
||||
<!-- Collapsed bar (entire bar is clickable to expand) -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="flex items-center h-7 px-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75"
|
||||
onclick={() => { expanded = !expanded; if (expanded && view === 'history') loadHistory(); }}
|
||||
onclick={() => {
|
||||
expanded = !expanded;
|
||||
if (expanded && view === 'history') loadHistory();
|
||||
}}
|
||||
>
|
||||
<!-- Branch button (opens branch picker, stops expand) -->
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-6 px-1.5 -ml-1.5 rounded-md hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={(e) => { e.stopPropagation(); showBranches = !showBranches; if (showBranches) loadBranches(); }}
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
showBranches = !showBranches;
|
||||
if (showBranches) loadBranches();
|
||||
}}
|
||||
>
|
||||
<Icon name="git-branch" size={12} class="text-gray-400 dark:text-gray-600 shrink-0" />
|
||||
<span class="text-[11px] text-gray-600 dark:text-gray-400 font-mono">{gitStatus.branch}</span>
|
||||
<span class="text-[11px] text-gray-600 dark:text-gray-400 font-mono"
|
||||
>{gitStatus.branch}</span
|
||||
>
|
||||
<Icon name="chevron-down" size={9} class="text-gray-400 dark:text-gray-600" />
|
||||
</button>
|
||||
|
||||
{#if gitStatus.ahead > 0}<span class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1.5">↑{gitStatus.ahead}</span>{/if}
|
||||
{#if gitStatus.behind > 0}<span class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1">↓{gitStatus.behind}</span>{/if}
|
||||
{#if totalChanges > 0}<span class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1.5">{$t('git.changedCount', { count: totalChanges })}</span>{/if}
|
||||
{#if actionMsg}<span class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-auto">{actionMsg}</span>{/if}
|
||||
{#if gitStatus.ahead > 0}<span
|
||||
class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1.5"
|
||||
>↑{gitStatus.ahead}</span
|
||||
>{/if}
|
||||
{#if gitStatus.behind > 0}<span
|
||||
class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1"
|
||||
>↓{gitStatus.behind}</span
|
||||
>{/if}
|
||||
{#if totalChanges > 0}<span
|
||||
class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-1.5"
|
||||
>{$t('git.changedCount', { count: totalChanges })}</span
|
||||
>{/if}
|
||||
{#if actionMsg}<span class="text-[10px] font-mono text-gray-400 dark:text-gray-600 ml-auto"
|
||||
>{actionMsg}</span
|
||||
>{/if}
|
||||
|
||||
<div class="flex-1"></div>
|
||||
|
||||
<!-- Sync button (stops expand) -->
|
||||
<button
|
||||
class="flex items-center gap-1 h-6 px-2 rounded-md text-[11px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={(e) => { e.stopPropagation(); syncAction.action(); }} disabled={loading}
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
syncAction.action();
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
<Icon name={syncAction.icon} size={12} />
|
||||
<span>{syncAction.label}</span>
|
||||
</button>
|
||||
|
||||
<!-- Chevron indicator -->
|
||||
<span class="text-gray-300 dark:text-gray-700 shrink-0 transition-transform duration-100 ml-0.5" style="transform: rotate({expanded ? '180deg' : '0deg'})">
|
||||
<span
|
||||
class="text-gray-300 dark:text-gray-700 shrink-0 transition-transform duration-100 ml-0.5"
|
||||
style="transform: rotate({expanded ? '180deg' : '0deg'})"
|
||||
>
|
||||
<Icon name="chevron-up" size={10} />
|
||||
</span>
|
||||
</div>
|
||||
@@ -362,27 +469,40 @@
|
||||
<!-- Branch picker dropdown -->
|
||||
{#if showBranches}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="fixed inset-0 z-40" onclick={() => showBranches = false}></div>
|
||||
<div class="absolute bottom-full left-2 mb-1 w-56 max-h-64 overflow-y-auto rounded-xl border border-gray-150 dark:border-white/6 bg-white dark:bg-[#1a1a1a] shadow-xl z-50 p-0.5">
|
||||
<div class="fixed inset-0 z-40" onclick={() => (showBranches = false)}></div>
|
||||
<div
|
||||
class="absolute bottom-full left-2 mb-1 w-56 max-h-64 overflow-y-auto rounded-xl border border-gray-150 dark:border-white/6 bg-white dark:bg-[#1a1a1a] shadow-xl z-50 p-0.5"
|
||||
>
|
||||
<!-- New branch -->
|
||||
{#if creatingBranch}
|
||||
<div class="flex items-center gap-1.5 px-2 py-1.5 border-b border-gray-100 dark:border-white/4">
|
||||
<div
|
||||
class="flex items-center gap-1.5 px-2 py-1.5 border-b border-gray-100 dark:border-white/4"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
class="flex-1 h-6 px-1.5 rounded border border-gray-200 dark:border-white/10 bg-transparent text-xs text-gray-900 dark:text-white placeholder:text-gray-400 outline-none"
|
||||
placeholder={$t('git.branchName')}
|
||||
bind:value={newBranchName}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') createBranch(); if (e.key === 'Escape') { creatingBranch = false; newBranchName = ''; } }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') createBranch();
|
||||
if (e.key === 'Escape') {
|
||||
creatingBranch = false;
|
||||
newBranchName = '';
|
||||
}
|
||||
}}
|
||||
autofocus
|
||||
/>
|
||||
<button class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300" onclick={createBranch}>
|
||||
<button
|
||||
class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
|
||||
onclick={createBranch}
|
||||
>
|
||||
<Icon name="check" size={12} />
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
class="flex items-center gap-1.5 w-full h-7 px-2.5 text-[11px] text-gray-500 hover:bg-gray-50 dark:hover:bg-white/4 transition-colors border-b border-gray-100 dark:border-white/4"
|
||||
onclick={() => creatingBranch = true}
|
||||
onclick={() => (creatingBranch = true)}
|
||||
>
|
||||
<Icon name="plus" size={11} />
|
||||
<span>{$t('git.newBranch')}</span>
|
||||
@@ -390,7 +510,7 @@
|
||||
{/if}
|
||||
|
||||
{#if branchData}
|
||||
{#each (branchData.all ?? []) as b}
|
||||
{#each branchData.all ?? [] as b}
|
||||
<button
|
||||
class="flex items-center gap-1.5 w-full h-7 px-2.5 text-left transition-colors duration-75
|
||||
{b.is_current ? 'bg-gray-50 dark:bg-white/4' : 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
@@ -402,7 +522,9 @@
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-10">
|
||||
<div class="w-3.5 h-3.5 border border-gray-300 dark:border-gray-600 border-t-gray-600 dark:border-t-gray-300 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-3.5 h-3.5 border border-gray-300 dark:border-gray-600 border-t-gray-600 dark:border-t-gray-300 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -411,7 +533,9 @@
|
||||
{#if expanded}
|
||||
<div class="border-t border-gray-100 dark:border-white/4">
|
||||
<!-- Header tabs -->
|
||||
<div class="flex items-center gap-0.5 h-8 px-2 border-b border-gray-100 dark:border-white/4">
|
||||
<div
|
||||
class="flex items-center gap-0.5 h-8 px-2 border-b border-gray-100 dark:border-white/4"
|
||||
>
|
||||
<!-- Mobile back button when viewing diff -->
|
||||
{#if showDiff}
|
||||
<button
|
||||
@@ -425,14 +549,21 @@
|
||||
<!-- Tabs (always visible) -->
|
||||
<button
|
||||
class="px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors duration-75
|
||||
{view === 'changes' ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
{view === 'changes'
|
||||
? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => switchView('changes')}
|
||||
>Changes{#if totalChanges > 0}<span class="ml-1 text-gray-400 dark:text-gray-500">{totalChanges}</span>{/if}</button>
|
||||
>Changes{#if totalChanges > 0}<span class="ml-1 text-gray-400 dark:text-gray-500"
|
||||
>{totalChanges}</span
|
||||
>{/if}</button
|
||||
>
|
||||
<button
|
||||
class="px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors duration-75
|
||||
{view === 'history' ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => switchView('history')}
|
||||
>{$t('git.history')}</button>
|
||||
{view === 'history'
|
||||
? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => switchView('history')}>{$t('git.history')}</button
|
||||
>
|
||||
|
||||
<div class="flex-1"></div>
|
||||
|
||||
@@ -448,11 +579,11 @@
|
||||
|
||||
<!-- Content -->
|
||||
<div class="flex min-h-36" style="height: {panelHeight}px;">
|
||||
|
||||
<!-- Left pane: file list or commit list -->
|
||||
<div class="w-full md:w-60 lg:w-72 shrink-0 md:border-r md:border-gray-100 md:dark:border-white/4 flex flex-col overflow-hidden
|
||||
{showDiff ? 'hidden md:flex' : 'flex'}">
|
||||
|
||||
<div
|
||||
class="w-full md:w-60 lg:w-72 shrink-0 md:border-r md:border-gray-100 md:dark:border-white/4 flex flex-col overflow-hidden
|
||||
{showDiff ? 'hidden md:flex' : 'flex'}"
|
||||
>
|
||||
{#if view === 'changes'}
|
||||
<!-- Global checkbox -->
|
||||
{#if totalChanges > 0}
|
||||
@@ -460,42 +591,72 @@
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 border-b border-gray-100 dark:border-white/4 hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75 shrink-0"
|
||||
onclick={toggleAll}
|
||||
>
|
||||
<span class="flex items-center justify-center w-3 h-3 rounded border shrink-0
|
||||
{allStaged ? 'border-gray-300 dark:border-gray-600 bg-gray-800 dark:bg-white' : someStaged ? 'border-gray-300 dark:border-gray-600 bg-gray-400 dark:bg-gray-500' : 'border-gray-300 dark:border-gray-600'}">
|
||||
<span
|
||||
class="flex items-center justify-center w-3 h-3 rounded border shrink-0
|
||||
{allStaged
|
||||
? 'border-gray-300 dark:border-gray-600 bg-gray-800 dark:bg-white'
|
||||
: someStaged
|
||||
? 'border-gray-300 dark:border-gray-600 bg-gray-400 dark:bg-gray-500'
|
||||
: 'border-gray-300 dark:border-gray-600'}"
|
||||
>
|
||||
{#if allStaged || someStaged}
|
||||
<Icon name={allStaged ? 'check' : 'minus'} size={7} class="text-white dark:text-black" />
|
||||
<Icon
|
||||
name={allStaged ? 'check' : 'minus'}
|
||||
size={7}
|
||||
class="text-white dark:text-black"
|
||||
/>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="text-[11px] text-gray-600 dark:text-gray-400">{$t('git.changedFile', { count: totalChanges })}</span>
|
||||
<span class="text-[11px] text-gray-600 dark:text-gray-400"
|
||||
>{$t('git.changedFile', { count: totalChanges })}</span
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<!-- File list -->
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
{#each (gitStatus?.files ?? []) as file (file.path)}
|
||||
{#each gitStatus?.files ?? [] as file (file.path)}
|
||||
{@const fp = fPath(file.path)}
|
||||
{@const sc = statusChar(file.status)}
|
||||
<button
|
||||
class="group flex items-center gap-1.5 w-full h-7 px-2.5 text-left transition-colors duration-75
|
||||
{selectedFile === file.path ? 'bg-gray-100 dark:bg-white/8' : 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
{selectedFile === file.path
|
||||
? 'bg-gray-100 dark:bg-white/8'
|
||||
: 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
onclick={() => selectFile(file.path, file.staged, file.status === 'untracked')}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="flex items-center justify-center w-3 h-3 rounded border shrink-0 cursor-pointer
|
||||
{file.staged ? 'border-gray-300 dark:border-gray-600 bg-gray-800 dark:bg-white' : 'border-gray-300 dark:border-gray-600 hover:border-gray-500 dark:hover:border-gray-400'}"
|
||||
onclick={(e) => { e.stopPropagation(); toggleStage(e, file); }}
|
||||
{file.staged
|
||||
? 'border-gray-300 dark:border-gray-600 bg-gray-800 dark:bg-white'
|
||||
: 'border-gray-300 dark:border-gray-600 hover:border-gray-500 dark:hover:border-gray-400'}"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
toggleStage(e, file);
|
||||
}}
|
||||
>
|
||||
{#if file.staged}
|
||||
<Icon name="check" size={7} class="text-white dark:text-black" />
|
||||
{/if}
|
||||
</span>
|
||||
{#if fp.dir}
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 truncate shrink min-w-0">{fp.dir}</span>
|
||||
<span
|
||||
class="text-[10px] text-gray-400 dark:text-gray-600 truncate shrink min-w-0"
|
||||
>{fp.dir}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span class="text-[11px] text-gray-800 dark:text-gray-200 truncate shrink-0 hover:underline cursor-pointer" onclick={(e) => { e.stopPropagation(); openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path); }}>{fp.name}</span>
|
||||
<span class="ml-auto text-[10px] font-mono font-bold shrink-0 {sc.color}">{sc.char}</span>
|
||||
<span
|
||||
class="text-[11px] text-gray-800 dark:text-gray-200 truncate shrink-0 hover:underline cursor-pointer"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path);
|
||||
}}>{fp.name}</span
|
||||
>
|
||||
<span class="ml-auto text-[10px] font-mono font-bold shrink-0 {sc.color}"
|
||||
>{sc.char}</span
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
|
||||
@@ -508,18 +669,21 @@
|
||||
</span>
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Commit area: combined input group -->
|
||||
<div class="border-t border-gray-100 dark:border-white/4 p-2 shrink-0">
|
||||
<div class="rounded-lg border border-gray-200 dark:border-white/8 overflow-hidden focus-within:border-gray-300 dark:focus-within:border-white/15 transition-colors">
|
||||
<div
|
||||
class="rounded-lg border border-gray-200 dark:border-white/8 overflow-hidden focus-within:border-gray-300 dark:focus-within:border-white/15 transition-colors"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
class="w-full h-7 px-2 bg-transparent text-[11px] text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none"
|
||||
placeholder={$t('git.summaryRequired')}
|
||||
bind:value={commitSummary}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' && !e.shiftKey) doCommit(); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) doCommit();
|
||||
}}
|
||||
/>
|
||||
<textarea
|
||||
class="w-full px-2 py-1.5 bg-transparent text-[11px] text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none resize-none border-t border-gray-100 dark:border-white/4"
|
||||
@@ -531,44 +695,60 @@
|
||||
<button
|
||||
class="w-full h-7 mt-1.5 rounded-lg text-[11px] font-medium transition-colors duration-75
|
||||
{stagedFiles.length && commitSummary.trim()
|
||||
? 'bg-gray-900 dark:bg-white text-white dark:text-black hover:bg-gray-800 dark:hover:bg-gray-200'
|
||||
: 'bg-gray-100 dark:bg-white/6 text-gray-400 dark:text-gray-600 cursor-default'}"
|
||||
? 'bg-gray-900 dark:bg-white text-white dark:text-black hover:bg-gray-800 dark:hover:bg-gray-200'
|
||||
: 'bg-gray-100 dark:bg-white/6 text-gray-400 dark:text-gray-600 cursor-default'}"
|
||||
disabled={!commitSummary.trim() || !stagedFiles.length || loading}
|
||||
onclick={doCommit}
|
||||
>
|
||||
{#if stagedFiles.length}
|
||||
{$t('git.commitFilesToBranch', { count: stagedFiles.length, branch: gitStatus.branch })}
|
||||
{$t('git.commitFilesToBranch', {
|
||||
count: stagedFiles.length,
|
||||
branch: gitStatus.branch
|
||||
})}
|
||||
{:else}
|
||||
{$t('git.commitToBranch', { branch: gitStatus.branch })}
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{:else}
|
||||
<!-- History: commit list -->
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
{#each commits as c}
|
||||
<button
|
||||
class="flex flex-col w-full px-2.5 py-1.5 text-left border-b border-gray-50 dark:border-white/3 transition-colors duration-75
|
||||
{selectedCommit?.hash === c.hash ? 'bg-gray-100 dark:bg-white/8' : 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
{selectedCommit?.hash === c.hash
|
||||
? 'bg-gray-100 dark:bg-white/8'
|
||||
: 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
onclick={() => selectCommit(c)}
|
||||
>
|
||||
<span class="text-xs text-gray-800 dark:text-gray-200 truncate w-full">{c.message}</span>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 font-mono">{c.short_hash} · {c.author} · {relTime(c.date)}</span>
|
||||
<span class="text-xs text-gray-800 dark:text-gray-200 truncate w-full"
|
||||
>{c.message}</span
|
||||
>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{c.short_hash} · {c.author} · {relTime(c.date)}</span
|
||||
>
|
||||
</button>
|
||||
{/each}
|
||||
{#if !commits.length}
|
||||
<div class="flex items-center justify-center h-full text-[11px] text-gray-400 dark:text-gray-600">{$t('git.noCommits')}</div>
|
||||
<div
|
||||
class="flex items-center justify-center h-full text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
{$t('git.noCommits')}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Right pane: diff viewer -->
|
||||
<div class="flex-1 overflow-hidden font-mono text-[11px] leading-[18px]
|
||||
{showDiff ? 'flex flex-col' : 'hidden md:flex md:flex-col'}">
|
||||
<div
|
||||
class="flex-1 overflow-hidden font-mono text-[11px] leading-[18px]
|
||||
{showDiff ? 'flex flex-col' : 'hidden md:flex md:flex-col'}"
|
||||
>
|
||||
{#if fileDiff.length}
|
||||
<div class="hidden md:flex items-center h-6 px-2 border-b border-gray-100 dark:border-white/4 shrink-0">
|
||||
<div
|
||||
class="hidden md:flex items-center h-6 px-2 border-b border-gray-100 dark:border-white/4 shrink-0"
|
||||
>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 font-mono truncate">
|
||||
{#if selectedCommit}
|
||||
{selectedCommit.short_hash} · {selectedCommit.message}
|
||||
@@ -579,39 +759,64 @@
|
||||
</div>
|
||||
<div class="flex-1 overflow-auto">
|
||||
<div class="diff-content">
|
||||
{#each fileDiff as df}
|
||||
{#if fileDiff.length > 1}
|
||||
<div class="px-2 py-1 text-[10px] text-gray-500 dark:text-gray-400 bg-white dark:bg-[#1a1a1a] border-b border-gray-100 dark:border-white/4 sticky top-0 z-10 font-medium">{df.path}</div>
|
||||
{/if}
|
||||
{#each df.hunks as hunk}
|
||||
<div class="px-2 py-0.5 text-gray-400 dark:text-gray-600 bg-gray-50 dark:bg-white/3 border-b border-gray-100 dark:border-white/4 w-full">{hunk.header}</div>
|
||||
{#each groupLines(hunk.lines) as group}
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="px-2 whitespace-pre-wrap break-all"><span class="{
|
||||
line.type === 'added' ? 'text-green-600 dark:text-green-400' :
|
||||
line.type === 'removed' ? 'text-red-500 dark:text-red-400' :
|
||||
'text-gray-400 dark:text-gray-600'
|
||||
}">{line.type === 'added' ? '+' : line.type === 'removed' ? '-' : ' '}</span><span class="{
|
||||
line.type === 'added' ? 'text-green-900 dark:text-green-300' :
|
||||
line.type === 'removed' ? 'text-red-900 dark:text-red-300' :
|
||||
'text-gray-600 dark:text-gray-400'
|
||||
}">{line.content}</span></div>
|
||||
{/each}
|
||||
{#each fileDiff as df}
|
||||
{#if fileDiff.length > 1}
|
||||
<div
|
||||
class="px-2 py-1 text-[10px] text-gray-500 dark:text-gray-400 bg-white dark:bg-[#1a1a1a] border-b border-gray-100 dark:border-white/4 sticky top-0 z-10 font-medium"
|
||||
>
|
||||
{df.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each df.hunks as hunk}
|
||||
<div
|
||||
class="px-2 py-0.5 text-gray-400 dark:text-gray-600 bg-gray-50 dark:bg-white/3 border-b border-gray-100 dark:border-white/4 w-full"
|
||||
>
|
||||
{hunk.header}
|
||||
</div>
|
||||
{#each groupLines(hunk.lines) as group}
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="px-2 whitespace-pre-wrap break-all">
|
||||
<span
|
||||
class={line.type === 'added'
|
||||
? 'text-green-600 dark:text-green-400'
|
||||
: line.type === 'removed'
|
||||
? 'text-red-500 dark:text-red-400'
|
||||
: 'text-gray-400 dark:text-gray-600'}
|
||||
>{line.type === 'added'
|
||||
? '+'
|
||||
: line.type === 'removed'
|
||||
? '-'
|
||||
: ' '}</span
|
||||
><span
|
||||
class={line.type === 'added'
|
||||
? 'text-green-900 dark:text-green-300'
|
||||
: line.type === 'removed'
|
||||
? 'text-red-900 dark:text-red-300'
|
||||
: 'text-gray-600 dark:text-gray-400'}>{line.content}</span
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-full">
|
||||
{#if view === 'history' && !selectedCommit}
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">{$t('git.selectCommit')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.selectCommit')}</span
|
||||
>
|
||||
{:else if totalChanges}
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">{$t('git.selectFile')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.selectFile')}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">{$t('git.noLocalChanges')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.noLocalChanges')}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -626,9 +831,21 @@
|
||||
<DropdownMenu
|
||||
anchor={contextMenu.anchor}
|
||||
items={[
|
||||
{ label: $t('git.discard'), icon: 'xmark', onclick: () => discardFile(contextMenu!.file.path) },
|
||||
{ label: $t('git.copyFilePath'), icon: 'copy', onclick: () => copyFilePath(contextMenu!.file.path) },
|
||||
{ label: $t('git.copyRelativePath'), icon: 'copy', onclick: () => copyRelativePath(contextMenu!.file.path) },
|
||||
{
|
||||
label: $t('git.discard'),
|
||||
icon: 'xmark',
|
||||
onclick: () => discardFile(contextMenu!.file.path)
|
||||
},
|
||||
{
|
||||
label: $t('git.copyFilePath'),
|
||||
icon: 'copy',
|
||||
onclick: () => copyFilePath(contextMenu!.file.path)
|
||||
},
|
||||
{
|
||||
label: $t('git.copyRelativePath'),
|
||||
icon: 'copy',
|
||||
onclick: () => copyRelativePath(contextMenu!.file.path)
|
||||
}
|
||||
]}
|
||||
onclose={closeContextMenu}
|
||||
/>
|
||||
@@ -643,12 +860,13 @@
|
||||
.diff-gutter-removed {
|
||||
border-left: 3px solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 3px
|
||||
) 3;
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 3px
|
||||
)
|
||||
3;
|
||||
}
|
||||
|
||||
.git-resize-handle {
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
error = '';
|
||||
|
||||
try {
|
||||
const status = await getGitStatus(root) as GitStatus;
|
||||
const status = (await getGitStatus(root)) as GitStatus;
|
||||
if (seq !== loadSeq || root !== workspacePath) return;
|
||||
|
||||
gitStatus = status;
|
||||
@@ -75,35 +75,37 @@
|
||||
}
|
||||
|
||||
const previousExpansion = new Map(reviewFiles.map((file) => [file.key, file.expanded]));
|
||||
const nextFiles = await Promise.all((status.files ?? []).map(async (file) => {
|
||||
const params = new URLSearchParams({
|
||||
root,
|
||||
file: file.path,
|
||||
staged: String(file.staged),
|
||||
});
|
||||
if (file.status === 'untracked') params.set('untracked', 'true');
|
||||
const nextFiles = await Promise.all(
|
||||
(status.files ?? []).map(async (file) => {
|
||||
const params = new URLSearchParams({
|
||||
root,
|
||||
file: file.path,
|
||||
staged: String(file.staged)
|
||||
});
|
||||
if (file.status === 'untracked') params.set('untracked', 'true');
|
||||
|
||||
let diffFiles: DiffFile[] = [];
|
||||
try {
|
||||
const diff = await getGitDiff(params.toString()) as { files?: DiffFile[] };
|
||||
diffFiles = diff.files ?? [];
|
||||
} catch {
|
||||
diffFiles = [];
|
||||
}
|
||||
let diffFiles: DiffFile[] = [];
|
||||
try {
|
||||
const diff = (await getGitDiff(params.toString())) as { files?: DiffFile[] };
|
||||
diffFiles = diff.files ?? [];
|
||||
} catch {
|
||||
diffFiles = [];
|
||||
}
|
||||
|
||||
const counts = countDiff(diffFiles);
|
||||
const key = fileKey(file);
|
||||
return {
|
||||
key,
|
||||
path: file.path,
|
||||
status: file.status,
|
||||
staged: file.staged,
|
||||
diffFiles,
|
||||
additions: counts.additions,
|
||||
deletions: counts.deletions,
|
||||
expanded: previousExpansion.get(key) ?? true,
|
||||
};
|
||||
}));
|
||||
const counts = countDiff(diffFiles);
|
||||
const key = fileKey(file);
|
||||
return {
|
||||
key,
|
||||
path: file.path,
|
||||
status: file.status,
|
||||
staged: file.staged,
|
||||
diffFiles,
|
||||
additions: counts.additions,
|
||||
deletions: counts.deletions,
|
||||
expanded: previousExpansion.get(key) ?? true
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
if (seq !== loadSeq || root !== workspacePath) return;
|
||||
reviewFiles = nextFiles;
|
||||
@@ -149,7 +151,6 @@
|
||||
reviewFiles = reviewFiles.map((file) => ({ ...file, expanded: expand }));
|
||||
}
|
||||
|
||||
|
||||
function openFile(path: string) {
|
||||
const fullPath = workspacePath.replace(/\/$/, '') + '/' + path;
|
||||
openFileTab(fullPath);
|
||||
@@ -187,7 +188,7 @@
|
||||
const match = header.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
||||
return {
|
||||
oldStart: match ? Number(match[1]) : 0,
|
||||
newStart: match ? Number(match[2]) : 0,
|
||||
newStart: match ? Number(match[2]) : 0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,10 +261,14 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex h-full flex-col overflow-hidden bg-white text-gray-900 dark:bg-black dark:text-gray-100">
|
||||
<div
|
||||
class="flex h-full flex-col overflow-hidden bg-white text-gray-900 dark:bg-black dark:text-gray-100"
|
||||
>
|
||||
{#if loading && !gitStatus}
|
||||
<div class="flex h-full items-center justify-center">
|
||||
<div class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"></div>
|
||||
<div
|
||||
class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"
|
||||
></div>
|
||||
</div>
|
||||
{:else if error && !gitStatus}
|
||||
<div class="flex h-full flex-col items-center justify-center gap-2 px-6 text-center">
|
||||
@@ -277,22 +282,34 @@
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600">Not a git repository</p>
|
||||
</div>
|
||||
{:else}
|
||||
<header class="flex h-9 shrink-0 items-center gap-2 border-b border-gray-200 px-3 dark:border-white/6">
|
||||
<header
|
||||
class="flex h-9 shrink-0 items-center gap-2 border-b border-gray-200 px-3 dark:border-white/6"
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<Icon name="git-branch" size={14} class="shrink-0 text-gray-400 dark:text-gray-600" />
|
||||
<span class="truncate font-mono text-xs font-medium text-gray-700 dark:text-gray-300">{gitStatus.branch || 'HEAD'}</span>
|
||||
<span class="truncate font-mono text-xs font-medium text-gray-700 dark:text-gray-300"
|
||||
>{gitStatus.branch || 'HEAD'}</span
|
||||
>
|
||||
{#if gitStatus.upstream}
|
||||
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-300 dark:text-gray-700" />
|
||||
<span class="truncate font-mono text-[11px] text-gray-400 dark:text-gray-600">{gitStatus.upstream}</span>
|
||||
<span class="truncate font-mono text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>{gitStatus.upstream}</span
|
||||
>
|
||||
{/if}
|
||||
{#if gitStatus.ahead > 0}
|
||||
<span class="font-mono text-[10px] text-gray-400 dark:text-gray-600">+{gitStatus.ahead}</span>
|
||||
<span class="font-mono text-[10px] text-gray-400 dark:text-gray-600"
|
||||
>+{gitStatus.ahead}</span
|
||||
>
|
||||
{/if}
|
||||
{#if gitStatus.behind > 0}
|
||||
<span class="font-mono text-[10px] text-gray-400 dark:text-gray-600">-{gitStatus.behind}</span>
|
||||
<span class="font-mono text-[10px] text-gray-400 dark:text-gray-600"
|
||||
>-{gitStatus.behind}</span
|
||||
>
|
||||
{/if}
|
||||
{#if totalChanges > 0}
|
||||
<span class="ml-1 font-mono text-[10px] text-gray-400 dark:text-gray-600">{totalChanges} changed</span>
|
||||
<span class="ml-1 font-mono text-[10px] text-gray-400 dark:text-gray-600"
|
||||
>{totalChanges} changed</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -308,7 +325,9 @@
|
||||
</header>
|
||||
|
||||
{#if totalChanges > 0}
|
||||
<div class="flex h-8 shrink-0 items-center gap-2 border-b border-gray-200 px-3 dark:border-white/6">
|
||||
<div
|
||||
class="flex h-8 shrink-0 items-center gap-2 border-b border-gray-200 px-3 dark:border-white/6"
|
||||
>
|
||||
<button
|
||||
class="flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/6 dark:hover:text-gray-300"
|
||||
onclick={toggleAll}
|
||||
@@ -317,7 +336,9 @@
|
||||
<span>{anyExpanded ? 'Collapse All' : 'Expand All'}</span>
|
||||
</button>
|
||||
<span class="text-[11px] text-gray-500 dark:text-gray-400">Uncommitted</span>
|
||||
<span class="ml-auto text-[11px] text-gray-400 dark:text-gray-600">{totalChanges} {totalChanges === 1 ? 'change' : 'changes'}</span>
|
||||
<span class="ml-auto text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>{totalChanges} {totalChanges === 1 ? 'change' : 'changes'}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -325,9 +346,18 @@
|
||||
{#if totalChanges === 0}
|
||||
<div class="flex h-full items-center justify-center px-6">
|
||||
<div class="flex -translate-y-8 flex-col items-center gap-2 text-center">
|
||||
<Icon name="git-diff" size={30} strokeWidth={1.2} class="text-gray-300 dark:text-gray-700" />
|
||||
<h2 class="text-sm font-medium text-gray-700 dark:text-gray-300">No file changes yet</h2>
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600">Changes in this project will appear here.</p>
|
||||
<Icon
|
||||
name="git-diff"
|
||||
size={30}
|
||||
strokeWidth={1.2}
|
||||
class="text-gray-300 dark:text-gray-700"
|
||||
/>
|
||||
<h2 class="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
No file changes yet
|
||||
</h2>
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600">
|
||||
Changes in this project will appear here.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -340,43 +370,72 @@
|
||||
class="flex h-8 w-full min-w-0 items-center gap-1.5 rounded-lg px-2 text-left transition-colors hover:bg-gray-100 dark:hover:bg-white/4"
|
||||
onclick={() => toggleFile(file.key)}
|
||||
>
|
||||
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-400 transition-transform dark:text-gray-600 {file.expanded ? 'rotate-90' : ''}" />
|
||||
<span class="w-4 shrink-0 text-center font-mono text-[11px] font-bold {meta.className}" title={meta.label}>{meta.char}</span>
|
||||
<Icon
|
||||
name="chevron-right"
|
||||
size={12}
|
||||
class="shrink-0 text-gray-400 transition-transform dark:text-gray-600 {file.expanded
|
||||
? 'rotate-90'
|
||||
: ''}"
|
||||
/>
|
||||
<span
|
||||
class="w-4 shrink-0 text-center font-mono text-[11px] font-bold {meta.className}"
|
||||
title={meta.label}>{meta.char}</span
|
||||
>
|
||||
<Icon name="git-diff" size={13} class="shrink-0 text-gray-400 dark:text-gray-600" />
|
||||
<div class="flex min-w-0 flex-1 items-baseline gap-2">
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="truncate text-xs font-medium text-gray-800 dark:text-gray-200 hover:underline"
|
||||
onclick={(e) => { e.stopPropagation(); openFile(file.path); }}
|
||||
>{parts.name}</span>
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFile(file.path);
|
||||
}}>{parts.name}</span
|
||||
>
|
||||
{#if parts.dir}
|
||||
<span class="hidden truncate text-[11px] text-gray-400 dark:text-gray-600 sm:inline">{parts.dir}</span>
|
||||
<span
|
||||
class="hidden truncate text-[11px] text-gray-400 dark:text-gray-600 sm:inline"
|
||||
>{parts.dir}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{#if file.additions > 0}
|
||||
<span class="shrink-0 font-mono text-[11px] font-medium text-green-600 dark:text-green-400">+{file.additions}</span>
|
||||
<span
|
||||
class="shrink-0 font-mono text-[11px] font-medium text-green-600 dark:text-green-400"
|
||||
>+{file.additions}</span
|
||||
>
|
||||
{/if}
|
||||
{#if file.deletions > 0}
|
||||
<span class="shrink-0 font-mono text-[11px] font-medium text-red-500 dark:text-red-400">-{file.deletions}</span>
|
||||
<span
|
||||
class="shrink-0 font-mono text-[11px] font-medium text-red-500 dark:text-red-400"
|
||||
>-{file.deletions}</span
|
||||
>
|
||||
{/if}
|
||||
|
||||
<span class="shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium text-rose-500 bg-rose-50 dark:bg-rose-500/10 dark:text-rose-300">
|
||||
<span
|
||||
class="shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium text-rose-500 bg-rose-50 dark:bg-rose-500/10 dark:text-rose-300"
|
||||
>
|
||||
{file.staged ? 'Staged' : 'Uncommitted'}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{#if file.expanded}
|
||||
<div class="mb-1 overflow-x-auto border-y border-gray-100 bg-white font-mono text-[11px] leading-[18px] dark:border-white/4 dark:bg-black">
|
||||
<div
|
||||
class="mb-1 overflow-x-auto border-y border-gray-100 bg-white font-mono text-[11px] leading-[18px] dark:border-white/4 dark:bg-black"
|
||||
>
|
||||
<div class="diff-content">
|
||||
{#if file.diffFiles.some((diffFile) => diffFile.hunks.length > 0)}
|
||||
{#each file.diffFiles as diffFile}
|
||||
{#if file.diffFiles.length > 1}
|
||||
<div class="sticky top-0 z-10 border-b border-gray-100 bg-gray-50 px-2 py-1 text-[10px] font-medium text-gray-500 dark:border-white/4 dark:bg-white/3 dark:text-gray-400">
|
||||
<div
|
||||
class="sticky top-0 z-10 border-b border-gray-100 bg-gray-50 px-2 py-1 text-[10px] font-medium text-gray-500 dark:border-white/4 dark:bg-white/3 dark:text-gray-400"
|
||||
>
|
||||
{diffFile.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each diffFile.hunks as hunk}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600">
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
@@ -386,10 +445,21 @@
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto]">
|
||||
<span class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600">{line.oldNumber ?? ''}</span>
|
||||
<span class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600">{line.newNumber ?? ''}</span>
|
||||
<span class="select-none px-1 text-center {prefixClass(line.type)}">{linePrefix(line.type)}</span>
|
||||
<code class="whitespace-pre px-2 {textClass(line.type)}">{line.content || ' '}</code>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.oldNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.newNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none px-1 text-center {prefixClass(line.type)}"
|
||||
>{linePrefix(line.type)}</span
|
||||
>
|
||||
<code class="whitespace-pre px-2 {textClass(line.type)}"
|
||||
>{line.content || ' '}</code
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -397,7 +467,11 @@
|
||||
{/each}
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="px-3 py-8 text-center text-[11px] text-gray-400 dark:text-gray-600">No textual diff available</div>
|
||||
<div
|
||||
class="px-3 py-8 text-center text-[11px] text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
No textual diff available
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -419,11 +493,12 @@
|
||||
.diff-gutter-removed {
|
||||
border-left: 3px solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 3px
|
||||
) 3;
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 3px
|
||||
)
|
||||
3;
|
||||
}
|
||||
</style>
|
||||
@@ -16,9 +16,8 @@
|
||||
splitCurrentTab,
|
||||
setSplitDirection,
|
||||
sidebarOpen,
|
||||
|
||||
type EditorGroup,
|
||||
type Tab,
|
||||
type Tab
|
||||
} from '$lib/stores';
|
||||
import { openChatTab } from '$lib/stores';
|
||||
import { chatEnabled, streamingChatTabs } from '$lib/stores/chat';
|
||||
@@ -55,21 +54,26 @@
|
||||
// Drop target highlight for cross-group drag
|
||||
let dropHighlight = $state(false);
|
||||
|
||||
const displayTabs = $derived(
|
||||
(group?.tabs ?? []).filter((t) => t.type !== 'git')
|
||||
);
|
||||
const displayTabs = $derived((group?.tabs ?? []).filter((t) => t.type !== 'git'));
|
||||
|
||||
const isActiveGroup = $derived($activeWorkspace?.activeGroupId === group?.id);
|
||||
|
||||
function tabIconName(tab: Tab): string {
|
||||
switch (tab.type) {
|
||||
case 'files': return 'folder';
|
||||
case 'terminal': return 'terminal';
|
||||
case 'file': return 'page';
|
||||
case 'git': return 'git-diff';
|
||||
case 'chat': return 'chat-bubble';
|
||||
case 'preview': return 'monitor';
|
||||
default: return 'page';
|
||||
case 'files':
|
||||
return 'folder';
|
||||
case 'terminal':
|
||||
return 'terminal';
|
||||
case 'file':
|
||||
return 'page';
|
||||
case 'git':
|
||||
return 'git-diff';
|
||||
case 'chat':
|
||||
return 'chat-bubble';
|
||||
case 'preview':
|
||||
return 'monitor';
|
||||
default:
|
||||
return 'page';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,20 +135,30 @@
|
||||
label: $t('bar.newFile'),
|
||||
icon: 'page',
|
||||
shortcut: formatChord($keybindings.newFile),
|
||||
onclick: () => { openUntitledFileTab(group.id); },
|
||||
onclick: () => {
|
||||
openUntitledFileTab(group.id);
|
||||
}
|
||||
},
|
||||
...($chatEnabled ? [{
|
||||
label: $t('bar.newChat'),
|
||||
icon: 'chat-bubble',
|
||||
shortcut: formatChord($keybindings.newChat),
|
||||
onclick: () => { openChatTab(undefined, group.id); },
|
||||
}] : []),
|
||||
...($chatEnabled
|
||||
? [
|
||||
{
|
||||
label: $t('bar.newChat'),
|
||||
icon: 'chat-bubble',
|
||||
shortcut: formatChord($keybindings.newChat),
|
||||
onclick: () => {
|
||||
openChatTab(undefined, group.id);
|
||||
}
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: $t('bar.newTerminal'),
|
||||
icon: 'terminal',
|
||||
shortcut: formatChord($keybindings.newTerminal),
|
||||
onclick: () => { openTerminalTab(group.id); },
|
||||
},
|
||||
onclick: () => {
|
||||
openTerminalTab(group.id);
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const contextMenuItems = $derived.by(() => {
|
||||
@@ -156,12 +170,12 @@
|
||||
items.push({
|
||||
label: 'Split Right',
|
||||
icon: 'split-horizontal',
|
||||
onclick: () => openInSplit(tab.filePath!, 'horizontal'),
|
||||
onclick: () => openInSplit(tab.filePath!, 'horizontal')
|
||||
});
|
||||
items.push({
|
||||
label: 'Split Down',
|
||||
icon: 'split-vertical',
|
||||
onclick: () => openInSplit(tab.filePath!, 'vertical'),
|
||||
onclick: () => openInSplit(tab.filePath!, 'vertical')
|
||||
});
|
||||
}
|
||||
|
||||
@@ -170,7 +184,7 @@
|
||||
items.push({
|
||||
label: $t('bar.closeTab'),
|
||||
icon: 'xmark',
|
||||
onclick: () => closeTab(tab.id, group.id),
|
||||
onclick: () => closeTab(tab.id, group.id)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,14 +198,20 @@
|
||||
label: 'Split Right',
|
||||
icon: 'split-horizontal',
|
||||
active: direction === 'horizontal',
|
||||
onclick: () => { setSplitDirection('horizontal'); if (!$splitActive) splitCurrentTab('horizontal'); },
|
||||
onclick: () => {
|
||||
setSplitDirection('horizontal');
|
||||
if (!$splitActive) splitCurrentTab('horizontal');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Split Down',
|
||||
icon: 'split-vertical',
|
||||
active: direction === 'vertical',
|
||||
onclick: () => { setSplitDirection('vertical'); if (!$splitActive) splitCurrentTab('vertical'); },
|
||||
},
|
||||
onclick: () => {
|
||||
setSplitDirection('vertical');
|
||||
if (!$splitActive) splitCurrentTab('vertical');
|
||||
}
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
@@ -218,7 +238,7 @@
|
||||
if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) {
|
||||
reorderTabs(evt.oldIndex, evt.newIndex, group.id);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
window.addEventListener('resize', handleResize);
|
||||
@@ -234,8 +254,8 @@
|
||||
<div
|
||||
class="flex items-center h-9 px-1.5 gap-1 shrink-0 select-none border-b transition-colors duration-100
|
||||
{dropHighlight
|
||||
? 'border-blue-400 bg-blue-50 dark:bg-blue-500/5 dark:border-blue-500/40'
|
||||
: 'border-gray-200 dark:border-white/6'}
|
||||
? 'border-blue-400 bg-blue-50 dark:bg-blue-500/5 dark:border-blue-500/40'
|
||||
: 'border-gray-200 dark:border-white/6'}
|
||||
{isActiveGroup ? '' : 'opacity-50'}"
|
||||
onclick={handlePaneClick}
|
||||
ondragover={handleBarDragOver}
|
||||
@@ -244,7 +264,12 @@
|
||||
>
|
||||
<!-- Sidebar toggle (only in primary group when sidebar is closed) -->
|
||||
{#if isPrimary && !$sidebarOpen}
|
||||
<button class="flex items-center justify-center w-7 h-7 rounded-md text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100" onclick={toggleSidebar} aria-label={$t('bar.toggleSidebar')} use:tooltip={$t('bar.sidebar')}>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-md text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={toggleSidebar}
|
||||
aria-label={$t('bar.toggleSidebar')}
|
||||
use:tooltip={$t('bar.sidebar')}
|
||||
>
|
||||
<Icon name="sidebar-expand" size={14} />
|
||||
</button>
|
||||
{/if}
|
||||
@@ -257,8 +282,8 @@
|
||||
<button
|
||||
class="flex items-center gap-1.5 px-2.5 h-7 rounded-lg text-xs font-medium whitespace-nowrap shrink-0 transition-all duration-100
|
||||
{isActive
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
data-tab-id={tab.id}
|
||||
onclick={() => handleTabClick(tab)}
|
||||
oncontextmenu={(e) => handleContextMenu(e, tab)}
|
||||
@@ -277,7 +302,9 @@
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 rounded text-gray-400 hover:bg-gray-200 hover:text-gray-700 dark:hover:bg-white/10 dark:hover:text-white"
|
||||
onclick={(e) => handleClose(e, tab.id)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') handleClose(e, tab.id); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') handleClose(e, tab.id);
|
||||
}}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
aria-label={$t('bar.closeTab')}
|
||||
@@ -293,7 +320,7 @@
|
||||
<button
|
||||
bind:this={plusBtnEl}
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 shrink-0"
|
||||
onclick={() => showPlusMenu = !showPlusMenu}
|
||||
onclick={() => (showPlusMenu = !showPlusMenu)}
|
||||
aria-label={$t('bar.new')}
|
||||
use:tooltip={$t('bar.new')}
|
||||
>
|
||||
@@ -309,18 +336,21 @@
|
||||
bind:this={splitBtnEl}
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg transition-colors duration-100 shrink-0
|
||||
{$splitActive
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => showSplitMenu = !showSplitMenu}
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
|
||||
onclick={() => (showSplitMenu = !showSplitMenu)}
|
||||
aria-label="Split Editor"
|
||||
use:tooltip={'Split Editor'}
|
||||
>
|
||||
<Icon name={$activeWorkspace?.splitDirection === 'vertical' ? 'split-vertical' : 'split-horizontal'} size={14} />
|
||||
<Icon
|
||||
name={$activeWorkspace?.splitDirection === 'vertical'
|
||||
? 'split-vertical'
|
||||
: 'split-horizontal'}
|
||||
size={14}
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
<!-- Close group button (when split is active) -->
|
||||
{#if canClose}
|
||||
<button
|
||||
@@ -336,22 +366,33 @@
|
||||
</div>
|
||||
|
||||
{#if showPlusMenu && plusBtnEl}
|
||||
<DropdownMenu items={plusMenuItems} anchor={plusBtnEl} onclose={() => showPlusMenu = false} className="min-w-52" />
|
||||
<DropdownMenu
|
||||
items={plusMenuItems}
|
||||
anchor={plusBtnEl}
|
||||
onclose={() => (showPlusMenu = false)}
|
||||
className="min-w-52"
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if contextMenu}
|
||||
<DropdownMenu items={contextMenuItems} anchor={{ x: contextMenu.x, y: contextMenu.y }} onclose={() => contextMenu = null} />
|
||||
<DropdownMenu
|
||||
items={contextMenuItems}
|
||||
anchor={{ x: contextMenu.x, y: contextMenu.y }}
|
||||
onclose={() => (contextMenu = null)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showSplitMenu && splitBtnEl}
|
||||
<DropdownMenu items={splitMenuItems} anchor={splitBtnEl} onclose={() => showSplitMenu = false} />
|
||||
<DropdownMenu
|
||||
items={splitMenuItems}
|
||||
anchor={splitBtnEl}
|
||||
onclose={() => (showSplitMenu = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@reference "../../app.css";
|
||||
|
||||
|
||||
|
||||
.group-tabs-row {
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
@@ -371,6 +412,8 @@
|
||||
}
|
||||
|
||||
@keyframes tab-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -25,12 +25,18 @@
|
||||
class={className}
|
||||
>
|
||||
{#if name === 'folder'}
|
||||
<path d="M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H21.4C21.7314 7 22 7.26863 22 7.6V11M2 11V19.4C2 19.7314 2.26863 20 2.6 20H21.4C21.7314 20 22 19.7314 22 19.4V11M2 11H22" />
|
||||
<path
|
||||
d="M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H21.4C21.7314 7 22 7.26863 22 7.6V11M2 11V19.4C2 19.7314 2.26863 20 2.6 20H21.4C21.7314 20 22 19.7314 22 19.4V11M2 11H22"
|
||||
/>
|
||||
{:else if name === 'page'}
|
||||
<path d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z" />
|
||||
<path
|
||||
d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z"
|
||||
/>
|
||||
<path d="M16 2V5.4C16 5.73137 16.2686 6 16.6 6H20" />
|
||||
{:else if name === 'page-text'}
|
||||
<path d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z" />
|
||||
<path
|
||||
d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z"
|
||||
/>
|
||||
<path d="M8 10L16 10" />
|
||||
<path d="M8 18L16 18" />
|
||||
<path d="M8 14L12 14" />
|
||||
@@ -40,26 +46,38 @@
|
||||
<path d="M5 7L10 12L5 17" />
|
||||
{:else if name === 'search'}
|
||||
<path d="M17 17L21 21" />
|
||||
<path d="M3 11C3 15.4183 6.58172 19 11 19C13.213 19 15.2161 18.1015 16.6644 16.6493C18.1077 15.2022 19 13.2053 19 11C19 6.58172 15.4183 3 11 3C6.58172 3 3 6.58172 3 11Z" />
|
||||
<path
|
||||
d="M3 11C3 15.4183 6.58172 19 11 19C13.213 19 15.2161 18.1015 16.6644 16.6493C18.1077 15.2022 19 13.2053 19 11C19 6.58172 15.4183 3 11 3C6.58172 3 3 6.58172 3 11Z"
|
||||
/>
|
||||
{:else if name === 'git-diff'}
|
||||
<path d="M9 8H15" />
|
||||
<path d="M12 5V11" />
|
||||
<path d="M9 16H15" />
|
||||
{:else if name === 'git-branch'}
|
||||
<path d="M18 8C19.1046 8 20 7.10457 20 6C20 4.89543 19.1046 4 18 4C16.8954 4 16 4.89543 16 6C16 7.10457 16.8954 8 18 8Z" />
|
||||
<path d="M6 20C7.10457 20 8 19.1046 8 18C8 16.8954 7.10457 16 6 16C4.89543 16 4 16.8954 4 18C4 19.1046 4.89543 20 6 20Z" />
|
||||
<path
|
||||
d="M18 8C19.1046 8 20 7.10457 20 6C20 4.89543 19.1046 4 18 4C16.8954 4 16 4.89543 16 6C16 7.10457 16.8954 8 18 8Z"
|
||||
/>
|
||||
<path
|
||||
d="M6 20C7.10457 20 8 19.1046 8 18C8 16.8954 7.10457 16 6 16C4.89543 16 4 16.8954 4 18C4 19.1046 4.89543 20 6 20Z"
|
||||
/>
|
||||
<path d="M6 16V3" />
|
||||
<path d="M8 18H9C12.5 18 18 15.9 18 9.5V8" />
|
||||
{:else if name === 'chat-bubble'}
|
||||
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 13.8214 2.48697 15.5291 3.33782 17L2.5 21.5L7 20.6622C8.47087 21.513 10.1786 22 12 22Z" />
|
||||
<path
|
||||
d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 13.8214 2.48697 15.5291 3.33782 17L2.5 21.5L7 20.6622C8.47087 21.513 10.1786 22 12 22Z"
|
||||
/>
|
||||
{:else if name === 'info'}
|
||||
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" />
|
||||
<path
|
||||
d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z"
|
||||
/>
|
||||
<path d="M12 8H12.01" />
|
||||
<path d="M11 12H12V16H13" />
|
||||
{:else if name === 'plus'}
|
||||
<path d="M6 12H12M18 12H12M12 12V6M12 12V18" />
|
||||
{:else if name === 'xmark'}
|
||||
<path d="M6.75827 17.2426L12.0009 12M17.2435 6.75736L12.0009 12M12.0009 12L6.75827 6.75736M12.0009 12L17.2435 17.2426" />
|
||||
<path
|
||||
d="M6.75827 17.2426L12.0009 12M17.2435 6.75736L12.0009 12M12.0009 12L6.75827 6.75736M12.0009 12L17.2435 17.2426"
|
||||
/>
|
||||
{:else if name === 'menu'}
|
||||
<path d="M3 5H21" />
|
||||
<path d="M3 12H21" />
|
||||
@@ -70,16 +88,26 @@
|
||||
<path d="M9 15L4 20M4 20V16M4 20H8" />
|
||||
<path d="M15 15L20 20M20 20V16M20 20H16" />
|
||||
{:else if name === 'sidebar-expand'}
|
||||
<path d="M19 21L5 21C3.89543 21 3 20.1046 3 19L3 5C3 3.89543 3.89543 3 5 3L19 3C20.1046 3 21 3.89543 21 5L21 19C21 20.1046 20.1046 21 19 21Z" />
|
||||
<path
|
||||
d="M19 21L5 21C3.89543 21 3 20.1046 3 19L3 5C3 3.89543 3.89543 3 5 3L19 3C20.1046 3 21 3.89543 21 5L21 19C21 20.1046 20.1046 21 19 21Z"
|
||||
/>
|
||||
<path d="M9.5 21V3" />
|
||||
<path d="M5.5 10L7.25 12L5.5 14" />
|
||||
{:else if name === 'settings'}
|
||||
<path d="M12 15C13.6569 15 15 13.6569 15 12C15 10.3431 13.6569 9 12 9C10.3431 9 9 10.3431 9 12C9 13.6569 10.3431 15 12 15Z" />
|
||||
<path d="M19.6224 10.3954L18.5247 7.7448L20 6L18 4L16.2647 5.48295L13.5578 4.36974L12.9353 2H10.981L10.3491 4.40113L7.70441 5.51596L6 4L4 6L5.45337 7.78885L4.3725 10.4463L2 11V13L4.40111 13.6555L5.51575 16.2997L4 18L6 20L7.79116 18.5403L10.397 19.6123L11 22H13L13.6045 19.6132L16.2551 18.5155C16.6969 18.8313 18 20 18 20L20 18L18.5159 16.2494L19.6139 13.598L21.9999 12.9772L22 11L19.6224 10.3954Z" />
|
||||
<path
|
||||
d="M12 15C13.6569 15 15 13.6569 15 12C15 10.3431 13.6569 9 12 9C10.3431 9 9 10.3431 9 12C9 13.6569 10.3431 15 12 15Z"
|
||||
/>
|
||||
<path
|
||||
d="M19.6224 10.3954L18.5247 7.7448L20 6L18 4L16.2647 5.48295L13.5578 4.36974L12.9353 2H10.981L10.3491 4.40113L7.70441 5.51596L6 4L4 6L5.45337 7.78885L4.3725 10.4463L2 11V13L4.40111 13.6555L5.51575 16.2997L4 18L6 20L7.79116 18.5403L10.397 19.6123L11 22H13L13.6045 19.6132L16.2551 18.5155C16.6969 18.8313 18 20 18 20L20 18L18.5159 16.2494L19.6139 13.598L21.9999 12.9772L22 11L19.6224 10.3954Z"
|
||||
/>
|
||||
{:else if name === 'half-moon'}
|
||||
<path d="M3 11.5066C3 16.7497 7.25034 21 12.4934 21C16.2209 21 19.4466 18.8518 21 15.7259C12.4934 15.7259 8.27411 11.5066 8.27411 3C5.14821 4.55344 3 7.77915 3 11.5066Z" />
|
||||
<path
|
||||
d="M3 11.5066C3 16.7497 7.25034 21 12.4934 21C16.2209 21 19.4466 18.8518 21 15.7259C12.4934 15.7259 8.27411 11.5066 8.27411 3C5.14821 4.55344 3 7.77915 3 11.5066Z"
|
||||
/>
|
||||
{:else if name === 'sun-light'}
|
||||
<path d="M12 18C15.3137 18 18 15.3137 18 12C18 8.68629 15.3137 6 12 6C8.68629 6 6 8.68629 6 12C6 15.3137 8.68629 18 12 18Z" />
|
||||
<path
|
||||
d="M12 18C15.3137 18 18 15.3137 18 12C18 8.68629 15.3137 6 12 6C8.68629 6 6 8.68629 6 12C6 15.3137 8.68629 18 12 18Z"
|
||||
/>
|
||||
<path d="M22 12L23 12" /><path d="M12 2V1" /><path d="M12 23V22" />
|
||||
<path d="M20 20L19 19" /><path d="M20 4L19 5" />
|
||||
<path d="M4 20L5 19" /><path d="M4 4L5 5" /><path d="M1 12L2 12" />
|
||||
@@ -100,13 +128,23 @@
|
||||
<path d="M21 12L3 12M3 12L11.5 3.5M3 12L11.5 20.5" />
|
||||
{:else if name === 'log-out'}
|
||||
<path d="M12 12H19M19 12L16 15M19 12L16 9" />
|
||||
<path d="M19 6V5C19 3.89543 18.1046 3 17 3H7C5.89543 3 5 3.89543 5 5V19C5 20.1046 5.89543 21 7 21H17C18.1046 21 19 20.1046 19 19V18" />
|
||||
<path
|
||||
d="M19 6V5C19 3.89543 18.1046 3 17 3H7C5.89543 3 5 3.89543 5 5V19C5 20.1046 5.89543 21 7 21H17C18.1046 21 19 20.1046 19 19V18"
|
||||
/>
|
||||
{:else if name === 'user'}
|
||||
<path d="M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z" />
|
||||
<path d="M4.271 18.346C4.271 18.346 6.50002 15.5 12 15.5C17.5 15.5 19.729 18.346 19.729 18.346" />
|
||||
<path d="M12 12C13.6569 12 15 10.6569 15 9C15 7.34315 13.6569 6 12 6C10.3431 6 9 7.34315 9 9C9 10.6569 10.3431 12 12 12Z" />
|
||||
<path
|
||||
d="M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z"
|
||||
/>
|
||||
<path
|
||||
d="M4.271 18.346C4.271 18.346 6.50002 15.5 12 15.5C17.5 15.5 19.729 18.346 19.729 18.346"
|
||||
/>
|
||||
<path
|
||||
d="M12 12C13.6569 12 15 10.6569 15 9C15 7.34315 13.6569 6 12 6C10.3431 6 9 7.34315 9 9C9 10.6569 10.3431 12 12 12Z"
|
||||
/>
|
||||
{:else if name === 'lock'}
|
||||
<path d="M16 12H17.4C17.7314 12 18 12.2686 18 12.6V19.4C18 19.7314 17.7314 20 17.4 20H6.6C6.26863 20 6 19.7314 6 19.4V12.6C6 12.2686 6.26863 12 6.6 12H8M16 12V8C16 6.66667 15.2 4 12 4C8.8 4 8 6.66667 8 8V12M16 12H8" />
|
||||
<path
|
||||
d="M16 12H17.4C17.7314 12 18 12.2686 18 12.6V19.4C18 19.7314 17.7314 20 17.4 20H6.6C6.26863 20 6 19.7314 6 19.4V12.6C6 12.2686 6.26863 12 6.6 12H8M16 12V8C16 6.66667 15.2 4 12 4C8.8 4 8 6.66667 8 8V12M16 12H8"
|
||||
/>
|
||||
{:else if name === 'docker'}
|
||||
<path d="M15.5 5.5H18.5V8.5H22C22 8.5 22 11.5 19 13C18.5 13.2778 18 13.5 17.5 13.5" />
|
||||
<path d="M1 11.5C1 11.5 2.5 8 6 8H8M3.5 8.5H6.5V11.5H0.5" />
|
||||
@@ -114,7 +152,9 @@
|
||||
<path d="M12.5 5.5H15.5V8.5" /><path d="M9.5 8.5H12.5V11.5" />
|
||||
<path d="M12.5 8.5H15.5V11.5" />
|
||||
{:else if name === 'empty-page'}
|
||||
<path d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z" />
|
||||
<path
|
||||
d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z"
|
||||
/>
|
||||
<path d="M16 2V5.4C16 5.73137 16.2686 6 16.6 6H20" />
|
||||
{:else if name === 'monitor'}
|
||||
<path d="M2 17V4.6C2 4.26863 2.26863 4 2.6 4H21.4C21.7314 4 22 4.26863 22 4.6V17" />
|
||||
@@ -133,16 +173,26 @@
|
||||
<circle cx="12" cy="12" r="1.5" fill="currentColor" />
|
||||
<circle cx="19" cy="12" r="1.5" fill="currentColor" />
|
||||
{:else if name === 'trash'}
|
||||
<path d="M20 9L18.005 20.3463C17.8369 21.3026 17.0062 22 16.0353 22H7.96474C6.99379 22 6.1631 21.3026 5.99496 20.3463L4 9" />
|
||||
<path d="M21 6H15.5M3 6H8.5M8.5 6V4C8.5 3.44772 8.94772 3 9.5 3H14.5C15.0523 3 15.5 3.44772 15.5 4V6M8.5 6H15.5" />
|
||||
<path
|
||||
d="M20 9L18.005 20.3463C17.8369 21.3026 17.0062 22 16.0353 22H7.96474C6.99379 22 6.1631 21.3026 5.99496 20.3463L4 9"
|
||||
/>
|
||||
<path
|
||||
d="M21 6H15.5M3 6H8.5M8.5 6V4C8.5 3.44772 8.94772 3 9.5 3H14.5C15.0523 3 15.5 3.44772 15.5 4V6M8.5 6H15.5"
|
||||
/>
|
||||
{:else if name === 'pencil'}
|
||||
<path d="M14.3632 5.65156L15.8431 4.17157C16.6242 3.39052 17.8905 3.39052 18.6716 4.17157L19.8284 5.32843C20.6095 6.10948 20.6095 7.37581 19.8284 8.15685L18.3484 9.63685M14.3632 5.65156L4.74749 15.2672C4.41542 15.5993 4.21079 16.0376 4.16947 16.5054L3.92738 19.2459C3.87261 19.8659 4.13434 20.1276 4.75408 20.0729L7.49463 19.8308C7.96243 19.7894 8.40074 19.5848 8.73281 19.2527L18.3484 9.63685M14.3632 5.65156L18.3484 9.63685" />
|
||||
<path
|
||||
d="M14.3632 5.65156L15.8431 4.17157C16.6242 3.39052 17.8905 3.39052 18.6716 4.17157L19.8284 5.32843C20.6095 6.10948 20.6095 7.37581 19.8284 8.15685L18.3484 9.63685M14.3632 5.65156L4.74749 15.2672C4.41542 15.5993 4.21079 16.0376 4.16947 16.5054L3.92738 19.2459C3.87261 19.8659 4.13434 20.1276 4.75408 20.0729L7.49463 19.8308C7.96243 19.7894 8.40074 19.5848 8.73281 19.2527L18.3484 9.63685M14.3632 5.65156L18.3484 9.63685"
|
||||
/>
|
||||
{:else if name === 'download'}
|
||||
<path d="M6 20H18" />
|
||||
<path d="M12 4V16M12 16L15.5 12.5M12 16L8.5 12.5" />
|
||||
{:else if name === 'eye'}
|
||||
<path d="M12 14C13.1046 14 14 13.1046 14 12C14 10.8954 13.1046 10 12 10C10.8954 10 10 10.8954 10 12C10 13.1046 10.8954 14 12 14Z" />
|
||||
<path d="M21 12C19.1114 14.991 15.7183 18 12 18C8.2817 18 4.88856 14.991 3 12C5.29855 9.15825 7.99163 6 12 6C16.0084 6 18.7015 9.15825 21 12Z" />
|
||||
<path
|
||||
d="M12 14C13.1046 14 14 13.1046 14 12C14 10.8954 13.1046 10 12 10C10.8954 10 10 10.8954 10 12C10 13.1046 10.8954 14 12 14Z"
|
||||
/>
|
||||
<path
|
||||
d="M21 12C19.1114 14.991 15.7183 18 12 18C8.2817 18 4.88856 14.991 3 12C5.29855 9.15825 7.99163 6 12 6C16.0084 6 18.7015 9.15825 21 12Z"
|
||||
/>
|
||||
{:else if name === 'minus'}
|
||||
<path d="M6 12H18" />
|
||||
{:else if name === 'chevron-up'}
|
||||
@@ -165,8 +215,12 @@
|
||||
<path d="M2.832 16c1.612 3.604 5.253 6 9.168 6 5.185 0 9.45-3.947 9.95-9" />
|
||||
<path d="M7 16H2.6C2.26863 16 2 16.2686 2 16.6V21" />
|
||||
{:else if name === 'copy'}
|
||||
<path d="M19.4 20H9.6C9.26863 20 9 19.7314 9 19.4V9.6C9 9.26863 9.26863 9 9.6 9H19.4C19.7314 9 20 9.26863 20 9.6V19.4C20 19.7314 19.7314 20 19.4 20Z" />
|
||||
<path d="M15 9V4.6C15 4.26863 14.7314 4 14.4 4H4.6C4.26863 4 4 4.26863 4 4.6V14.4C4 14.7314 4.26863 15 4.6 15H9" />
|
||||
<path
|
||||
d="M19.4 20H9.6C9.26863 20 9 19.7314 9 19.4V9.6C9 9.26863 9.26863 9 9.6 9H19.4C19.7314 9 20 9.26863 20 9.6V19.4C20 19.7314 19.7314 20 19.4 20Z"
|
||||
/>
|
||||
<path
|
||||
d="M15 9V4.6C15 4.26863 14.7314 4 14.4 4H4.6C4.26863 4 4 4.26863 4 4.6V14.4C4 14.7314 4.26863 15 4.6 15H9"
|
||||
/>
|
||||
{:else if name === 'sort'}
|
||||
<path d="M4 5H20" />
|
||||
<path d="M4 12H16" />
|
||||
@@ -196,28 +250,42 @@
|
||||
<path d="M9 6H20" />
|
||||
<path d="M9 12H20" />
|
||||
<path d="M9 18H20" />
|
||||
<path d="M4 16.5V16.8C4 17.1866 4.14 17.5 4.5 17.5H5.5C5.86 17.5 6 17.8 6 18C6 18.2 5.86 18.5 5.5 18.5H4.5" />
|
||||
<path
|
||||
d="M4 16.5V16.8C4 17.1866 4.14 17.5 4.5 17.5H5.5C5.86 17.5 6 17.8 6 18C6 18.2 5.86 18.5 5.5 18.5H4.5"
|
||||
/>
|
||||
<path d="M5 6V4L4 4.5" />
|
||||
<path d="M4 12.5H5.5L4 14H6" />
|
||||
{:else if name === 'check-square'}
|
||||
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" />
|
||||
<path
|
||||
d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z"
|
||||
/>
|
||||
<path d="M9 12L11 14L15 10" />
|
||||
{:else if name === 'table'}
|
||||
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" />
|
||||
<path
|
||||
d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z"
|
||||
/>
|
||||
<path d="M3 9H21" />
|
||||
<path d="M3 15H21" />
|
||||
<path d="M9 3V21" />
|
||||
{:else if name === 'image'}
|
||||
<path d="M21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6Z" />
|
||||
<path
|
||||
d="M21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6Z"
|
||||
/>
|
||||
<path d="M3 16L10 13L21 18" />
|
||||
<path d="M16 10C14.8954 10 14 9.10457 14 8C14 6.89543 14.8954 6 16 6C17.1046 6 18 6.89543 18 8C18 9.10457 17.1046 10 16 10Z" />
|
||||
<path
|
||||
d="M16 10C14.8954 10 14 9.10457 14 8C14 6.89543 14.8954 6 16 6C17.1046 6 18 6.89543 18 8C18 9.10457 17.1046 10 16 10Z"
|
||||
/>
|
||||
{:else if name === 'split-horizontal'}
|
||||
<!-- Two side-by-side panes with a vertical divider -->
|
||||
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" />
|
||||
<path
|
||||
d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z"
|
||||
/>
|
||||
<path d="M12 3V21" />
|
||||
{:else if name === 'split-vertical'}
|
||||
<!-- Two stacked panes with a horizontal divider -->
|
||||
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" />
|
||||
<path
|
||||
d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z"
|
||||
/>
|
||||
<path d="M3 12H21" />
|
||||
{:else if name === 'arrow-right-from-line'}
|
||||
<!-- Open to the side icon -->
|
||||
|
||||
@@ -8,4 +8,7 @@
|
||||
let { text, class: className = '' }: Props = $props();
|
||||
</script>
|
||||
|
||||
<span class="inline-flex items-center justify-center h-[18px] px-[5px] rounded-full text-[10px] font-medium leading-none bg-[#e8e8e8] text-[#555] dark:bg-[#1e1e1e] dark:text-[#999] {className}">{text}</span>
|
||||
<span
|
||||
class="inline-flex items-center justify-center h-[18px] px-[5px] rounded-full text-[10px] font-medium leading-none bg-[#e8e8e8] text-[#555] dark:bg-[#1e1e1e] dark:text-[#999] {className}"
|
||||
>{text}</span
|
||||
>
|
||||
@@ -1,33 +1,33 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from "svelte";
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
class?: string;
|
||||
children: Snippet;
|
||||
}
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
class?: string;
|
||||
children: Snippet;
|
||||
}
|
||||
|
||||
let { onclose, class: className = "", children }: Props = $props();
|
||||
let { onclose, class: className = '', children }: Props = $props();
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") onclose();
|
||||
}
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center"
|
||||
onmousedown={onclose}
|
||||
onkeydown={() => {}}
|
||||
class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center"
|
||||
onmousedown={onclose}
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="bg-white dark:bg-[#0a0a0a] dark:border dark:border-white/8 rounded-3xl overflow-hidden shadow-2xl {className}"
|
||||
onmousedown={(e) => e.stopPropagation()}
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
{@render children()}
|
||||
</div>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="bg-white dark:bg-[#0a0a0a] dark:border dark:border-white/8 rounded-3xl overflow-hidden shadow-2xl {className}"
|
||||
onmousedown={(e) => e.stopPropagation()}
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
{@render children()}
|
||||
</div>
|
||||
</div>
|
||||
@@ -9,7 +9,10 @@
|
||||
systemEvents.newPorts.filter((p) => {
|
||||
if (!p.session_id) return false; // unknown origin, don't show
|
||||
// Check if this session belongs to the active workspace
|
||||
return $activeWorkspace?.groups.some((g) => g.tabs.some((t) => t.sessionId === p.session_id)) ?? false;
|
||||
return (
|
||||
$activeWorkspace?.groups.some((g) => g.tabs.some((t) => t.sessionId === p.session_id)) ??
|
||||
false
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -19,10 +22,13 @@
|
||||
$effect(() => {
|
||||
for (const port of relevantPorts) {
|
||||
if (!dismissTimers.has(port.port)) {
|
||||
dismissTimers.set(port.port, setTimeout(() => {
|
||||
systemEvents.dismissPort(port.port);
|
||||
dismissTimers.delete(port.port);
|
||||
}, 10000));
|
||||
dismissTimers.set(
|
||||
port.port,
|
||||
setTimeout(() => {
|
||||
systemEvents.dismissPort(port.port);
|
||||
dismissTimers.delete(port.port);
|
||||
}, 10000)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -44,7 +50,9 @@
|
||||
// Find terminal tab label for a session_id
|
||||
function terminalLabel(sessionId: string | null): string | null {
|
||||
if (!sessionId || !$activeWorkspace) return null;
|
||||
const tab = $activeWorkspace.groups.flatMap((g) => g.tabs).find((t) => t.sessionId === sessionId);
|
||||
const tab = $activeWorkspace.groups
|
||||
.flatMap((g) => g.tabs)
|
||||
.find((t) => t.sessionId === sessionId);
|
||||
return tab?.label ?? null;
|
||||
}
|
||||
</script>
|
||||
@@ -56,15 +64,19 @@
|
||||
class="flex items-center gap-2 px-3 py-2 rounded-lg bg-white dark:bg-neutral-900 border border-gray-200 dark:border-white/10 shadow-lg pointer-events-auto animate-in"
|
||||
>
|
||||
<span class="text-xs text-gray-400 shrink-0">🌐</span>
|
||||
<span class="text-xs font-medium font-mono text-gray-700 dark:text-gray-200">:{port.port}</span>
|
||||
<span class="text-xs font-medium font-mono text-gray-700 dark:text-gray-200"
|
||||
>:{port.port}</span
|
||||
>
|
||||
<span class="text-[11px] text-gray-400">({port.process})</span>
|
||||
{#if terminalLabel(port.session_id)}
|
||||
<span class="text-[10px] text-gray-400 italic">{$t('port.via', { name: terminalLabel(port.session_id) })}</span>
|
||||
<span class="text-[10px] text-gray-400 italic"
|
||||
>{$t('port.via', { name: terminalLabel(port.session_id) })}</span
|
||||
>
|
||||
{/if}
|
||||
<button
|
||||
class="ml-1 px-2 py-0.5 rounded text-[11px] font-medium text-white bg-blue-500 hover:bg-blue-600 transition-colors duration-100 shrink-0"
|
||||
onclick={() => preview(port)}
|
||||
>{$t('port.preview')}</button>
|
||||
onclick={() => preview(port)}>{$t('port.preview')}</button
|
||||
>
|
||||
<button
|
||||
class="flex items-center justify-center w-4 h-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 shrink-0"
|
||||
onclick={() => dismiss(port)}
|
||||
|
||||
@@ -141,11 +141,7 @@
|
||||
</button>
|
||||
|
||||
<!-- Refresh -->
|
||||
<button
|
||||
class="preview-btn"
|
||||
onclick={refresh}
|
||||
use:tooltip={'Refresh'}
|
||||
>
|
||||
<button class="preview-btn" onclick={refresh} use:tooltip={'Refresh'}>
|
||||
<Icon name="refresh" size={12} />
|
||||
</button>
|
||||
|
||||
@@ -162,11 +158,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Open external -->
|
||||
<button
|
||||
class="preview-btn"
|
||||
onclick={openExternal}
|
||||
use:tooltip={'Open in new tab'}
|
||||
>
|
||||
<button class="preview-btn" onclick={openExternal} use:tooltip={'Open in new tab'}>
|
||||
<Icon name="external-link" size={12} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -195,7 +187,10 @@
|
||||
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-downloads"
|
||||
class="preview-iframe"
|
||||
onload={onIframeLoad}
|
||||
onerror={() => { loadError = true; isLoading = false; }}
|
||||
onerror={() => {
|
||||
loadError = true;
|
||||
isLoading = false;
|
||||
}}
|
||||
></iframe>
|
||||
{/key}
|
||||
{/if}
|
||||
@@ -314,9 +309,18 @@
|
||||
}
|
||||
|
||||
@keyframes loading-bar {
|
||||
0% { width: 0; margin-left: 0; }
|
||||
50% { width: 60%; margin-left: 20%; }
|
||||
100% { width: 0; margin-left: 100%; }
|
||||
0% {
|
||||
width: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
50% {
|
||||
width: 60%;
|
||||
margin-left: 20%;
|
||||
}
|
||||
100% {
|
||||
width: 0;
|
||||
margin-left: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-content {
|
||||
|
||||
@@ -75,7 +75,10 @@
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<Modal {onclose} class="w-full max-w-[520px] mx-4 max-md:mx-0 max-md:rounded-none max-h-[400px] max-md:max-h-dvh flex flex-col mb-[6vh] max-md:mb-0">
|
||||
<Modal
|
||||
{onclose}
|
||||
class="w-full max-w-[520px] mx-4 max-md:mx-0 max-md:rounded-none max-h-[400px] max-md:max-h-dvh flex flex-col mb-[6vh] max-md:mb-0"
|
||||
>
|
||||
<div class="flex items-center px-4 py-2.5 gap-2.5 border-b border-gray-200 dark:border-white/6">
|
||||
<Icon name="search" size={14} class="text-gray-400 shrink-0" />
|
||||
<input
|
||||
@@ -85,7 +88,10 @@
|
||||
placeholder={$t('quickOpen.searchFiles')}
|
||||
bind:value={query}
|
||||
/>
|
||||
<span class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0">ESC</span>
|
||||
<span
|
||||
class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0"
|
||||
>ESC</span
|
||||
>
|
||||
</div>
|
||||
|
||||
{#if results.length > 0}
|
||||
@@ -94,14 +100,20 @@
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-left transition-colors duration-75
|
||||
{i === selectedIndex
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
onclick={() => selectResult(r)}
|
||||
onmouseenter={() => selectedIndex = i}
|
||||
onmouseenter={() => (selectedIndex = i)}
|
||||
>
|
||||
<Icon name={r.type === 'directory' ? 'folder' : 'empty-page'} size={14} class="shrink-0 text-gray-400" />
|
||||
<Icon
|
||||
name={r.type === 'directory' ? 'folder' : 'empty-page'}
|
||||
size={14}
|
||||
class="shrink-0 text-gray-400"
|
||||
/>
|
||||
<span class="text-xs font-medium shrink-0">{r.name}</span>
|
||||
<span class="text-[11px] text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap">{relativePath(r.path)}</span>
|
||||
<span class="text-[11px] text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{relativePath(r.path)}</span
|
||||
>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -109,4 +121,3 @@
|
||||
<div class="p-6 text-center text-xs text-gray-400">{$t('quickOpen.noFiles')}</div>
|
||||
{/if}
|
||||
</Modal>
|
||||
|
||||
@@ -47,10 +47,12 @@
|
||||
if (initialDir) {
|
||||
fetchDirectories(initialDir);
|
||||
} else {
|
||||
getWelcome().then(d => {
|
||||
const home = d.suggestions?.[0]?.path || '/';
|
||||
fetchDirectories(home);
|
||||
}).catch(() => fetchDirectories('/'));
|
||||
getWelcome()
|
||||
.then((d) => {
|
||||
const home = d.suggestions?.[0]?.path || '/';
|
||||
fetchDirectories(home);
|
||||
})
|
||||
.catch(() => fetchDirectories('/'));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -118,7 +120,11 @@
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center" onmousedown={onclose} onkeydown={() => {}}>
|
||||
<div
|
||||
class="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center"
|
||||
onmousedown={onclose}
|
||||
onkeydown={() => {}}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="w-full max-w-[520px] mx-4 bg-white dark:bg-[#111] dark:border dark:border-white/8 rounded-3xl overflow-hidden shadow-2xl max-h-[420px] flex flex-col"
|
||||
@@ -137,11 +143,16 @@
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<span class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0">ESC</span>
|
||||
<span
|
||||
class="text-[10px] font-mono font-medium px-1.5 py-0.5 rounded bg-gray-100 dark:bg-white/6 text-gray-400 shrink-0"
|
||||
>ESC</span
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- Location breadcrumb -->
|
||||
<div class="flex items-center gap-2 px-4 h-8 border-b border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-2 px-4 h-8 border-b border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
{#if history.length > 0}
|
||||
<button
|
||||
class="flex items-center justify-center w-5 h-5 rounded text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
@@ -151,7 +162,9 @@
|
||||
<Icon name="chevron-left" size={13} />
|
||||
</button>
|
||||
{/if}
|
||||
<span class="flex-1 text-[11px] text-gray-400 dark:text-gray-500 font-mono truncate">{currentPath}</span>
|
||||
<span class="flex-1 text-[11px] text-gray-400 dark:text-gray-500 font-mono truncate"
|
||||
>{currentPath}</span
|
||||
>
|
||||
<label class="flex items-center gap-1.5 cursor-pointer select-none shrink-0">
|
||||
<input type="checkbox" bind:checked={showHidden} class="w-3 h-3 rounded accent-gray-500" />
|
||||
<span class="text-[10px] text-gray-400">{$t('saveDialog.hidden')}</span>
|
||||
@@ -162,15 +175,17 @@
|
||||
<div bind:this={listEl} class="flex-1 overflow-y-auto p-1 min-h-0">
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-8">
|
||||
<div class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center gap-2 py-8 text-center">
|
||||
<p class="text-xs text-red-400">{error}</p>
|
||||
<button
|
||||
class="text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 px-3 py-1 rounded-lg bg-gray-100 dark:bg-white/6 transition-colors duration-100"
|
||||
onclick={() => fetchDirectories(currentPath)}
|
||||
>Retry</button>
|
||||
onclick={() => fetchDirectories(currentPath)}>Retry</button
|
||||
>
|
||||
</div>
|
||||
{:else if filteredDirs.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-8">
|
||||
@@ -182,35 +197,46 @@
|
||||
data-index={i}
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-lg text-left transition-colors duration-75
|
||||
{i === selectedIndex
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
onclick={() => navigateTo(dir.name)}
|
||||
onmouseenter={() => { selectedIndex = i; }}
|
||||
onmouseenter={() => {
|
||||
selectedIndex = i;
|
||||
}}
|
||||
>
|
||||
<Icon name="folder" size={14} class="shrink-0 text-gray-400" />
|
||||
<span class="flex-1 truncate text-xs">{dir.name}</span>
|
||||
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-300 dark:text-gray-700" />
|
||||
<Icon
|
||||
name="chevron-right"
|
||||
size={12}
|
||||
class="shrink-0 text-gray-300 dark:text-gray-700"
|
||||
/>
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="flex items-center gap-2 px-3 py-2 border-t border-gray-200 dark:border-white/6 shrink-0">
|
||||
<div
|
||||
class="flex items-center gap-2 px-3 py-2 border-t border-gray-200 dark:border-white/6 shrink-0"
|
||||
>
|
||||
{#if fileName.trim()}
|
||||
<span class="flex-1 text-[11px] text-gray-400 dark:text-gray-600 font-mono truncate min-w-0" title={savePath}>{savePath}</span>
|
||||
<span
|
||||
class="flex-1 text-[11px] text-gray-400 dark:text-gray-600 font-mono truncate min-w-0"
|
||||
title={savePath}>{savePath}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="flex-1"></span>
|
||||
{/if}
|
||||
<button
|
||||
class="text-xs font-medium text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 px-3 py-1.5 rounded-lg transition-colors duration-100 shrink-0"
|
||||
onclick={onclose}
|
||||
>{$t('saveDialog.cancel')}</button>
|
||||
onclick={onclose}>{$t('saveDialog.cancel')}</button
|
||||
>
|
||||
<button
|
||||
class="text-xs font-medium text-white dark:text-black bg-gray-900 dark:bg-white hover:bg-gray-800 dark:hover:bg-gray-200 px-3 py-1.5 rounded-lg transition-colors duration-100 disabled:opacity-30 disabled:pointer-events-none shrink-0"
|
||||
onclick={doSave}
|
||||
disabled={!fileName.trim()}
|
||||
>{$t('saveDialog.save')}</button>
|
||||
disabled={!fileName.trim()}>{$t('saveDialog.save')}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,50 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { appVersion, showChangelog } from "$lib/stores";
|
||||
import { t } from '$lib/i18n';
|
||||
import { appVersion, showChangelog } from '$lib/stores';
|
||||
</script>
|
||||
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">
|
||||
{$t("about.title")}
|
||||
{$t('about.title')}
|
||||
</h2>
|
||||
|
||||
<div>
|
||||
<div class="flex items-baseline gap-2">
|
||||
<a
|
||||
href="https://github.com/open-webui/computer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-xs font-semibold text-gray-900 dark:text-white hover:underline"
|
||||
>cptr</a
|
||||
>
|
||||
{#if $appVersion}
|
||||
<button
|
||||
onclick={() => showChangelog.set(true)}
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer"
|
||||
>v{$appVersion}</button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-[13px] text-gray-500 mt-0.5 mb-4">{$t("app.tagline")}</p>
|
||||
<div class="flex items-baseline gap-2">
|
||||
<a
|
||||
href="https://github.com/open-webui/computer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-xs font-semibold text-gray-900 dark:text-white hover:underline">cptr</a
|
||||
>
|
||||
{#if $appVersion}
|
||||
<button
|
||||
onclick={() => showChangelog.set(true)}
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer"
|
||||
>v{$appVersion}</button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-[13px] text-gray-500 mt-0.5 mb-4">{$t('app.tagline')}</p>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{$t("about.license")}
|
||||
</h3>
|
||||
<p
|
||||
class="text-[11px] text-gray-500 leading-relaxed font-mono whitespace-pre-line"
|
||||
>
|
||||
<a
|
||||
href="https://github.com/open-webui/computer/blob/main/LICENSE"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="underline hover:text-gray-700 dark:hover:text-gray-300"
|
||||
>Open Use License</a
|
||||
>
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{$t('about.license')}
|
||||
</h3>
|
||||
<p class="text-[11px] text-gray-500 leading-relaxed font-mono whitespace-pre-line">
|
||||
<a
|
||||
href="https://github.com/open-webui/computer/blob/main/LICENSE"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="underline hover:text-gray-700 dark:hover:text-gray-300">Open Use License</a
|
||||
>
|
||||
|
||||
<br />
|
||||
Copyright © 2026 Open WebUI Inc. All rights reserved.
|
||||
</p>
|
||||
<br />
|
||||
Copyright © 2026 Open WebUI Inc. All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p class="text-[11px] text-gray-300 dark:text-gray-700 pt-8">
|
||||
{$t("about.createdBy")}
|
||||
{$t('about.createdBy')}
|
||||
</p>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { updatePassword as apiUpdatePassword, uploadAvatar, deleteAvatar, updateProfile } from '$lib/apis/auth';
|
||||
import {
|
||||
updatePassword as apiUpdatePassword,
|
||||
uploadAvatar,
|
||||
deleteAvatar,
|
||||
updateProfile
|
||||
} from '$lib/apis/auth';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { session, setSession } from '$lib/session';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -32,8 +37,14 @@
|
||||
}
|
||||
|
||||
async function updatePassword() {
|
||||
if (!currentPassword || !newPassword) { toast.error($t('account.bothFieldsRequired')); return; }
|
||||
if (newPassword.length < 6) { toast.error($t('auth.minChars')); return; }
|
||||
if (!currentPassword || !newPassword) {
|
||||
toast.error($t('account.bothFieldsRequired'));
|
||||
return;
|
||||
}
|
||||
if (newPassword.length < 6) {
|
||||
toast.error($t('auth.minChars'));
|
||||
return;
|
||||
}
|
||||
updatingPassword = true;
|
||||
try {
|
||||
await apiUpdatePassword(currentPassword, newPassword);
|
||||
@@ -42,8 +53,9 @@
|
||||
newPassword = '';
|
||||
} catch (e) {
|
||||
toast.error(e instanceof ApiError ? e.message : $t('auth.connectionFailed'));
|
||||
} finally {
|
||||
updatingPassword = false;
|
||||
}
|
||||
finally { updatingPassword = false; }
|
||||
}
|
||||
|
||||
/** Resize image client-side to 256×256 before upload. */
|
||||
@@ -63,7 +75,7 @@
|
||||
ctx.drawImage(img, sx, sy, size, size, 0, 0, 256, 256);
|
||||
|
||||
canvas.toBlob(
|
||||
(blob) => blob ? resolve(blob) : reject(new Error('Canvas export failed')),
|
||||
(blob) => (blob ? resolve(blob) : reject(new Error('Canvas export failed'))),
|
||||
'image/png'
|
||||
);
|
||||
};
|
||||
@@ -113,99 +125,121 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col min-h-full">
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('account.title')}</h2>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('account.title')}</h2>
|
||||
|
||||
<!-- Avatar -->
|
||||
<div class="flex items-center gap-4 mb-6">
|
||||
<button
|
||||
class="relative w-10 h-10 rounded-full overflow-hidden bg-gray-100 dark:bg-white/8 flex items-center justify-center
|
||||
<!-- Avatar -->
|
||||
<div class="flex items-center gap-4 mb-6">
|
||||
<button
|
||||
class="relative w-10 h-10 rounded-full overflow-hidden bg-gray-100 dark:bg-white/8 flex items-center justify-center
|
||||
ring-1 ring-gray-200 dark:ring-white/10 hover:ring-2 hover:ring-gray-300 dark:hover:ring-white/20 transition-all duration-200 group shrink-0"
|
||||
onclick={handleAvatarSelect}
|
||||
disabled={uploadingAvatar}
|
||||
>
|
||||
{#if uploadingAvatar}
|
||||
<div class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
{:else}
|
||||
<img src={avatarUrl || '/user.png'} alt="Avatar" class="w-full h-full object-cover" />
|
||||
<div class="absolute inset-0 bg-black/0 group-hover:bg-black/40 transition-colors duration-200 flex items-center justify-center">
|
||||
<svg class="w-4 h-4 text-white opacity-0 group-hover:opacity-100 transition-opacity duration-200 drop-shadow-sm" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6.827 6.175A2.31 2.31 0 0 1 5.186 7.23c-.38.054-.757.112-1.134.175C2.999 7.58 2.25 8.507 2.25 9.574V18a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9.574c0-1.067-.75-1.994-1.802-2.169a47.865 47.865 0 0 0-1.134-.175 2.31 2.31 0 0 1-1.64-1.055l-.822-1.316a2.192 2.192 0 0 0-1.736-1.039 48.774 48.774 0 0 0-5.232 0 2.192 2.192 0 0 0-1.736 1.039l-.821 1.316Z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 12.75a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Z" />
|
||||
</svg>
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-white">{$session?.display_name || $session?.username}</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="text-[11px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={handleAvatarSelect}
|
||||
disabled={uploadingAvatar}
|
||||
>{$t('account.uploadPhoto')}</button>
|
||||
{#if avatarUrl}
|
||||
<span class="text-gray-300 dark:text-gray-700 text-[11px]">·</span>
|
||||
onclick={handleAvatarSelect}
|
||||
disabled={uploadingAvatar}
|
||||
>
|
||||
{#if uploadingAvatar}
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
<img src={avatarUrl || '/user.png'} alt="Avatar" class="w-full h-full object-cover" />
|
||||
<div
|
||||
class="absolute inset-0 bg-black/0 group-hover:bg-black/40 transition-colors duration-200 flex items-center justify-center"
|
||||
>
|
||||
<svg
|
||||
class="w-4 h-4 text-white opacity-0 group-hover:opacity-100 transition-opacity duration-200 drop-shadow-sm"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M6.827 6.175A2.31 2.31 0 0 1 5.186 7.23c-.38.054-.757.112-1.134.175C2.999 7.58 2.25 8.507 2.25 9.574V18a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9.574c0-1.067-.75-1.994-1.802-2.169a47.865 47.865 0 0 0-1.134-.175 2.31 2.31 0 0 1-1.64-1.055l-.822-1.316a2.192 2.192 0 0 0-1.736-1.039 48.774 48.774 0 0 0-5.232 0 2.192 2.192 0 0 0-1.736 1.039l-.821 1.316Z"
|
||||
/>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M16.5 12.75a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-white"
|
||||
>{$session?.display_name || $session?.username}</span
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="text-[11px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={handleAvatarDelete}
|
||||
disabled={uploadingAvatar}
|
||||
>{$t('account.removePhoto')}</button>
|
||||
{/if}
|
||||
onclick={handleAvatarSelect}
|
||||
disabled={uploadingAvatar}>{$t('account.uploadPhoto')}</button
|
||||
>
|
||||
{#if avatarUrl}
|
||||
<span class="text-gray-300 dark:text-gray-700 text-[11px]">·</span>
|
||||
<button
|
||||
class="text-[11px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={handleAvatarDelete}
|
||||
disabled={uploadingAvatar}>{$t('account.removePhoto')}</button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Display Name -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">{$t('account.displayName')}</h3>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('account.displayNamePlaceholder')}
|
||||
bind:value={displayName}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1 mb-5"
|
||||
/>
|
||||
<!-- Display Name -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">{$t('account.displayName')}</h3>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={$t('account.displayNamePlaceholder')}
|
||||
bind:value={displayName}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1 mb-5"
|
||||
/>
|
||||
|
||||
<!-- Password -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">{$t('account.password')}</h3>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('account.currentPassword')}
|
||||
bind:value={currentPassword}
|
||||
autocomplete="current-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('account.newPassword')}
|
||||
bind:value={newPassword}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1"
|
||||
/>
|
||||
<button
|
||||
disabled={updatingPassword || !currentPassword || !newPassword}
|
||||
onclick={updatePassword}
|
||||
class="mt-2 self-start text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if updatingPassword}
|
||||
<div class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
{:else}
|
||||
{$t('account.updatePassword')}
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<!-- Save -->
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<!-- Password -->
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">{$t('account.password')}</h3>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('account.currentPassword')}
|
||||
bind:value={currentPassword}
|
||||
autocomplete="current-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={$t('account.newPassword')}
|
||||
bind:value={newPassword}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1"
|
||||
/>
|
||||
<button
|
||||
onclick={saveDisplayName}
|
||||
disabled={savingProfile}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
disabled={updatingPassword || !currentPassword || !newPassword}
|
||||
onclick={updatePassword}
|
||||
class="mt-2 self-start text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if savingProfile}
|
||||
{$t('settings.saving')}
|
||||
{#if updatingPassword}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
{:else}
|
||||
{$t('settings.save')}
|
||||
{$t('account.updatePassword')}
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Save -->
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<button
|
||||
onclick={saveDisplayName}
|
||||
disabled={savingProfile}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if savingProfile}
|
||||
{$t('settings.saving')}
|
||||
{:else}
|
||||
{$t('settings.save')}
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -5,68 +5,65 @@
|
||||
import type { Theme, StreamingBehavior } from '$lib/stores';
|
||||
import { t, locale, changeLocale, supportedLocales } from '$lib/i18n';
|
||||
|
||||
function setTheme(v: Theme) { theme.set(v); }
|
||||
function setTheme(v: Theme) {
|
||||
theme.set(v);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col min-h-full">
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('general.title')}</h2>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('general.title')}</h2>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('general.theme')}</h3>
|
||||
<div class="flex gap-1">
|
||||
{#each [
|
||||
{ value: 'light' as Theme, label: $t('general.light'), icon: 'sun-light' },
|
||||
{ value: 'dark' as Theme, label: $t('general.dark'), icon: 'half-moon' },
|
||||
{ value: 'system' as Theme, label: $t('general.system'), icon: 'monitor' },
|
||||
] as opt}
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('general.theme')}</h3>
|
||||
<div class="flex gap-1">
|
||||
{#each [{ value: 'light' as Theme, label: $t('general.light'), icon: 'sun-light' }, { value: 'dark' as Theme, label: $t('general.dark'), icon: 'half-moon' }, { value: 'system' as Theme, label: $t('general.system'), icon: 'monitor' }] as opt}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
|
||||
{$theme === opt.value
|
||||
? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => setTheme(opt.value)}
|
||||
>
|
||||
<Icon name={opt.icon} size={13} />
|
||||
{opt.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">{$t('general.language')}</h3>
|
||||
<select
|
||||
class="w-full max-w-[200px] bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-1 cursor-pointer"
|
||||
value={$locale}
|
||||
onchange={(e) => changeLocale((e.currentTarget as HTMLSelectElement).value)}
|
||||
>
|
||||
{#each supportedLocales as loc}
|
||||
<option value={loc.code}>{loc.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">Message queue</h3>
|
||||
<div class="flex gap-1">
|
||||
{#each [{ value: 'queue' as StreamingBehavior, label: 'Queue' }, { value: 'interrupt' as StreamingBehavior, label: 'Interrupt' }] as opt}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
|
||||
{$streamingBehavior === opt.value
|
||||
? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => streamingBehavior.set(opt.value)}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-1">
|
||||
{$streamingBehavior === 'queue'
|
||||
? 'Messages sent during generation are queued and sent after completion.'
|
||||
: 'Sending a message cancels the current generation.'}
|
||||
</p>
|
||||
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
|
||||
{$theme === opt.value ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => setTheme(opt.value)}
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => toast.success($t('settings.saved'))}>{$t('settings.save')}</button
|
||||
>
|
||||
<Icon name={opt.icon} size={13} />
|
||||
{opt.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">{$t('general.language')}</h3>
|
||||
<select
|
||||
class="w-full max-w-[200px] bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-1 cursor-pointer"
|
||||
value={$locale}
|
||||
onchange={(e) => changeLocale((e.currentTarget as HTMLSelectElement).value)}
|
||||
>
|
||||
{#each supportedLocales as loc}
|
||||
<option value={loc.code}>{loc.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">Message queue</h3>
|
||||
<div class="flex gap-1">
|
||||
{#each [
|
||||
{ value: 'queue' as StreamingBehavior, label: 'Queue' },
|
||||
{ value: 'interrupt' as StreamingBehavior, label: 'Interrupt' },
|
||||
] as opt}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
|
||||
{$streamingBehavior === opt.value ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => streamingBehavior.set(opt.value)}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-1">
|
||||
{$streamingBehavior === 'queue'
|
||||
? 'Messages sent during generation are queued and sent after completion.'
|
||||
: 'Sending a message cancels the current generation.'}
|
||||
</p>
|
||||
|
||||
|
||||
<div class="mt-auto pt-6 flex justify-end">
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => toast.success($t('settings.saved'))}
|
||||
>{$t('settings.save')}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { keybindings, ACTION_IDS, ACTION_LABELS, DEFAULT_KEYBINDINGS, formatChord, eventToChord, resetKeybindings } from '$lib/stores/keybindings';
|
||||
import {
|
||||
keybindings,
|
||||
ACTION_IDS,
|
||||
ACTION_LABELS,
|
||||
DEFAULT_KEYBINDINGS,
|
||||
formatChord,
|
||||
eventToChord,
|
||||
resetKeybindings
|
||||
} from '$lib/stores/keybindings';
|
||||
import type { ActionId } from '$lib/stores/keybindings';
|
||||
import KeyPill from '../KeyPill.svelte';
|
||||
|
||||
@@ -14,7 +22,7 @@
|
||||
quickOpen: 'Search and open files quickly',
|
||||
openSettings: 'Open the settings panel',
|
||||
toggleSplit: 'Toggle split editor view',
|
||||
toggleSidebar: 'Show or hide the sidebar',
|
||||
toggleSidebar: 'Show or hide the sidebar'
|
||||
};
|
||||
|
||||
let recordingAction = $state<ActionId | null>(null);
|
||||
@@ -43,7 +51,7 @@
|
||||
// Save it
|
||||
keybindings.update((current) => ({
|
||||
...current,
|
||||
[recordingAction!]: chord,
|
||||
[recordingAction!]: chord
|
||||
}));
|
||||
recordingAction = null;
|
||||
}
|
||||
@@ -51,7 +59,7 @@
|
||||
function clearBinding(actionId: ActionId) {
|
||||
keybindings.update((current) => ({
|
||||
...current,
|
||||
[actionId]: '',
|
||||
[actionId]: ''
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -72,14 +80,16 @@
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white">Keyboard Shortcuts</h2>
|
||||
<button
|
||||
class="text-[10px] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={resetKeybindings}
|
||||
>Reset defaults</button>
|
||||
onclick={resetKeybindings}>Reset defaults</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- Column headers -->
|
||||
<div class="flex items-center gap-2 mb-0.5 px-1">
|
||||
<span class="flex-1 text-[10px] font-medium text-gray-400 dark:text-gray-600">Command</span>
|
||||
<span class="w-[140px] text-[10px] font-medium text-gray-400 dark:text-gray-600 text-right">Keybinding</span>
|
||||
<span class="w-[140px] text-[10px] font-medium text-gray-400 dark:text-gray-600 text-right"
|
||||
>Keybinding</span
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
@@ -90,8 +100,12 @@
|
||||
|
||||
<div class="shortcut-row">
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-[11.5px] text-gray-700 dark:text-gray-300">{ACTION_LABELS[actionId]}</div>
|
||||
<div class="text-[10px] text-gray-400 dark:text-gray-600 truncate leading-tight">{ACTION_DESCRIPTIONS[actionId]}</div>
|
||||
<div class="text-[11.5px] text-gray-700 dark:text-gray-300">
|
||||
{ACTION_LABELS[actionId]}
|
||||
</div>
|
||||
<div class="text-[10px] text-gray-400 dark:text-gray-600 truncate leading-tight">
|
||||
{ACTION_DESCRIPTIONS[actionId]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-[140px] flex items-center justify-end shrink-0">
|
||||
@@ -108,12 +122,15 @@
|
||||
{:else}
|
||||
<button
|
||||
class="text-[10px] text-gray-500 dark:text-gray-600 cursor-pointer hover:text-gray-400 transition-colors duration-75"
|
||||
onclick={() => startRecording(actionId)}
|
||||
>Unassigned</button>
|
||||
onclick={() => startRecording(actionId)}>Unassigned</button
|
||||
>
|
||||
{/if}
|
||||
|
||||
{#if conflict}
|
||||
<span class="text-[9px] text-amber-500 ml-1" title="Also bound to {ACTION_LABELS[conflict]}">!</span>
|
||||
<span
|
||||
class="text-[9px] text-amber-500 ml-1"
|
||||
title="Also bound to {ACTION_LABELS[conflict]}">!</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -137,7 +154,6 @@
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
|
||||
.recording-indicator {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -152,12 +168,16 @@
|
||||
}
|
||||
|
||||
@keyframes pulse-subtle {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.6; }
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.kbd-inline {
|
||||
@apply inline px-0.5 py-px rounded text-[9px] font-mono bg-gray-100 dark:bg-white/6 text-gray-500;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
<script lang="ts">
|
||||
import Icon from "./Icon.svelte";
|
||||
import Modal from "./Modal.svelte";
|
||||
import General from "./Settings/General.svelte";
|
||||
import Account from "./Settings/Account.svelte";
|
||||
import Keyboard from "./Settings/Keyboard.svelte";
|
||||
import About from "./Settings/About.svelte";
|
||||
import { t } from '$lib/i18n';
|
||||
import Icon from './Icon.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import General from './Settings/General.svelte';
|
||||
import Account from './Settings/Account.svelte';
|
||||
import Keyboard from './Settings/Keyboard.svelte';
|
||||
import About from './Settings/About.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
initialTab?: 'general' | 'keyboard' | 'account' | 'about';
|
||||
}
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
initialTab?: 'general' | 'keyboard' | 'account' | 'about';
|
||||
}
|
||||
|
||||
let { onclose, initialTab = 'general' }: Props = $props();
|
||||
let { onclose, initialTab = 'general' }: Props = $props();
|
||||
|
||||
let activeTab = $state<"general" | "keyboard" | "account" | "about">(initialTab);
|
||||
let activeTab = $state<'general' | 'keyboard' | 'account' | 'about'>(initialTab);
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
{onclose}
|
||||
class="w-full max-w-3xl mx-4 md:mx-0 flex flex-col md:flex-row max-h-[85vh] md:h-[560px]"
|
||||
{onclose}
|
||||
class="w-full max-w-3xl mx-4 md:mx-0 flex flex-col md:flex-row max-h-[85vh] md:h-[560px]"
|
||||
>
|
||||
<nav
|
||||
class="shrink-0 border-b md:border-b-0 md:border-r border-gray-200 dark:border-white/6 md:w-[180px]"
|
||||
>
|
||||
<div class="flex md:flex-col p-1 gap-px">
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-75 md:mb-1"
|
||||
onclick={onclose}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span>{$t('settings.back')}</span>
|
||||
</button>
|
||||
{#each [{ id: "general", label: $t('settings.general'), icon: "settings" }, { id: "keyboard", label: "Keyboard", icon: "terminal" }, { id: "account", label: $t('settings.account'), icon: "user" }, { id: "about", label: $t('settings.about'), icon: "info" }] as tab}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-left transition-colors duration-75
|
||||
<nav
|
||||
class="shrink-0 border-b md:border-b-0 md:border-r border-gray-200 dark:border-white/6 md:w-[180px]"
|
||||
>
|
||||
<div class="flex md:flex-col p-1 gap-px">
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-75 md:mb-1"
|
||||
onclick={onclose}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span>{$t('settings.back')}</span>
|
||||
</button>
|
||||
{#each [{ id: 'general', label: $t('settings.general'), icon: 'settings' }, { id: 'keyboard', label: 'Keyboard', icon: 'terminal' }, { id: 'account', label: $t('settings.account'), icon: 'user' }, { id: 'about', label: $t('settings.about'), icon: 'info' }] as tab}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2 md:w-full shrink-0 rounded-lg text-xs text-left transition-colors duration-75
|
||||
{activeTab === tab.id
|
||||
? 'font-medium text-gray-900 dark:text-white bg-gray-100 dark:bg-white/6'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => (activeTab = tab.id as typeof activeTab)}
|
||||
>
|
||||
<Icon name={tab.icon} size={14} />
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
? 'font-medium text-gray-900 dark:text-white bg-gray-100 dark:bg-white/6'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={() => (activeTab = tab.id as typeof activeTab)}
|
||||
>
|
||||
<Icon name={tab.icon} size={14} />
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="flex-1 overflow-y-auto min-h-0 p-4 md:px-5">
|
||||
{#if activeTab === "general"}
|
||||
<General />
|
||||
{:else if activeTab === "keyboard"}
|
||||
<Keyboard />
|
||||
{:else if activeTab === "account"}
|
||||
<Account />
|
||||
{:else if activeTab === "about"}
|
||||
<About />
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-1 overflow-y-auto min-h-0 p-4 md:px-5">
|
||||
{#if activeTab === 'general'}
|
||||
<General />
|
||||
{:else if activeTab === 'keyboard'}
|
||||
<Keyboard />
|
||||
{:else if activeTab === 'account'}
|
||||
<Account />
|
||||
{:else if activeTab === 'about'}
|
||||
<About />
|
||||
{/if}
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -67,7 +67,7 @@
|
||||
{ label: '~', value: '~' },
|
||||
{ label: '/', value: '/' },
|
||||
{ label: '-', value: '-' },
|
||||
{ label: '_', value: '_' },
|
||||
{ label: '_', value: '_' }
|
||||
];
|
||||
</script>
|
||||
|
||||
@@ -79,16 +79,36 @@
|
||||
class="key"
|
||||
class:active={ctrlHeld}
|
||||
onmousedown={(e) => e.preventDefault()}
|
||||
ontouchstart={(e) => { e.preventDefault(); touchHandled = true; toggleCtrl(); }}
|
||||
onclick={() => { if (touchHandled) { touchHandled = false; return; } toggleCtrl(); }}
|
||||
>{key.label}</button>
|
||||
ontouchstart={(e) => {
|
||||
e.preventDefault();
|
||||
touchHandled = true;
|
||||
toggleCtrl();
|
||||
}}
|
||||
onclick={() => {
|
||||
if (touchHandled) {
|
||||
touchHandled = false;
|
||||
return;
|
||||
}
|
||||
toggleCtrl();
|
||||
}}>{key.label}</button
|
||||
>
|
||||
{:else}
|
||||
<button
|
||||
class="key"
|
||||
onmousedown={(e) => e.preventDefault()}
|
||||
ontouchstart={(e) => { e.preventDefault(); touchHandled = true; sendKey(key.value); }}
|
||||
onclick={() => { if (touchHandled) { touchHandled = false; return; } sendKey(key.value); }}
|
||||
>{key.label}</button>
|
||||
ontouchstart={(e) => {
|
||||
e.preventDefault();
|
||||
touchHandled = true;
|
||||
sendKey(key.value);
|
||||
}}
|
||||
onclick={() => {
|
||||
if (touchHandled) {
|
||||
touchHandled = false;
|
||||
return;
|
||||
}
|
||||
sendKey(key.value);
|
||||
}}>{key.label}</button
|
||||
>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
sidebarOpen,
|
||||
sidebarWidth,
|
||||
appVersion,
|
||||
showChangelog,
|
||||
showChangelog
|
||||
} from '$lib/stores';
|
||||
import Sortable from 'sortablejs';
|
||||
import Icon from './Icon.svelte';
|
||||
@@ -72,7 +72,9 @@
|
||||
const currentPath = $derived($page.url.searchParams.get('workspace'));
|
||||
|
||||
function isTouchDevice(): boolean {
|
||||
return typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0);
|
||||
return (
|
||||
typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0)
|
||||
);
|
||||
}
|
||||
|
||||
function handleWorkspaceClick(e: MouseEvent, path: string) {
|
||||
@@ -120,7 +122,6 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
|
||||
// Enable drag-reorder on non-touch devices
|
||||
if (wsListEl && !isTouchDevice()) {
|
||||
sortable = Sortable.create(wsListEl, {
|
||||
@@ -132,7 +133,7 @@
|
||||
if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) {
|
||||
reorderWorkspaces(evt.oldIndex, evt.newIndex);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -143,7 +144,11 @@
|
||||
</script>
|
||||
|
||||
{#if $sidebarOpen}
|
||||
<button class="fixed inset-0 bg-black/50 z-40 cursor-default md:hidden" onclick={closeSidebar} aria-label={$t('sidebar.closeSidebar')}></button>
|
||||
<button
|
||||
class="fixed inset-0 bg-black/50 z-40 cursor-default md:hidden"
|
||||
onclick={closeSidebar}
|
||||
aria-label={$t('sidebar.closeSidebar')}
|
||||
></button>
|
||||
|
||||
<aside class="sidebar" style="--sw: {$sidebarWidth}px;">
|
||||
<!-- Resize handle (md+ only) -->
|
||||
@@ -156,12 +161,18 @@
|
||||
ondblclick={() => sidebarWidth.set(220)}
|
||||
></div>
|
||||
<!-- Logo header with collapse button -->
|
||||
<div class="flex items-center justify-between h-9 pl-3.5 pr-1.5 shrink-0 border-b border-gray-200 dark:border-white/6">
|
||||
<div
|
||||
class="flex items-center justify-between h-9 pl-3.5 pr-1.5 shrink-0 border-b border-gray-200 dark:border-white/6"
|
||||
>
|
||||
<a
|
||||
href="/"
|
||||
class="flex items-center gap-1.5 text-xs font-semibold tracking-tight text-gray-900 dark:text-white"
|
||||
onclick={(e) => { e.preventDefault(); goto('/'); if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false); }}
|
||||
><img src="/favicon.png" alt="cptr logo" class="w-4 h-4" />cptr</a>
|
||||
href="/"
|
||||
class="flex items-center gap-1.5 text-xs font-semibold tracking-tight text-gray-900 dark:text-white"
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
goto('/');
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}}><img src="/favicon.png" alt="cptr logo" class="w-4 h-4" />cptr</a
|
||||
>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={() => sidebarOpen.set(false)}
|
||||
@@ -177,7 +188,7 @@
|
||||
<span class="text-xs text-gray-400 dark:text-gray-500">{$t('sidebar.workspaces')}</span>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={() => showPicker = true}
|
||||
onclick={() => (showPicker = true)}
|
||||
aria-label={$t('sidebar.addWorkspace')}
|
||||
use:tooltip={$t('sidebar.addWorkspace')}
|
||||
>
|
||||
@@ -192,12 +203,14 @@
|
||||
href="/?workspace={encodeURIComponent(ws.path)}"
|
||||
class="group flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs font-medium transition-colors duration-100 no-underline
|
||||
{ws.path === currentPath
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
onclick={(e) => handleWorkspaceClick(e, ws.path)}
|
||||
>
|
||||
<Icon name="folder" size={14} />
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap">{ws.name}</span>
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{ws.name}</span
|
||||
>
|
||||
<span
|
||||
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
|
||||
role="button"
|
||||
@@ -219,21 +232,25 @@
|
||||
|
||||
<!-- Settings and profile footer pinned to the bottom -->
|
||||
<div class="relative px-1 pb-0.5 shrink-0">
|
||||
|
||||
<button
|
||||
bind:this={menuButtonEl}
|
||||
class="flex items-center gap-2 w-full h-8 px-2 rounded-lg text-xs font-medium text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => showMenu = !showMenu}
|
||||
onclick={() => (showMenu = !showMenu)}
|
||||
>
|
||||
<img
|
||||
src={$session?.profile_image_url || '/user.png'}
|
||||
alt="Avatar"
|
||||
class="w-5 h-5 rounded-full object-cover shrink-0"
|
||||
/>
|
||||
<span class="truncate">{$session?.display_name || $session?.username || $t('sidebar.settings')}</span>
|
||||
<span class="truncate"
|
||||
>{$session?.display_name || $session?.username || $t('sidebar.settings')}</span
|
||||
>
|
||||
{#if $appVersion}
|
||||
<button
|
||||
onclick={(e) => { e.stopPropagation(); showChangelog.set(true); }}
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
showChangelog.set(true);
|
||||
}}
|
||||
class="ml-auto text-[10px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer"
|
||||
>
|
||||
v{$appVersion}
|
||||
@@ -249,37 +266,69 @@
|
||||
anchor={menuButtonEl}
|
||||
matchWidth
|
||||
items={[
|
||||
...$session ? [{ label: $session.display_name || $session.username, image: $session.profile_image_url || '/user.png', onclick: () => { settingsTab = 'account'; showSettings = true; } }] : [],
|
||||
...$session ? [{ divider: true, label: '', onclick: () => {} }] : [],
|
||||
...($session
|
||||
? [
|
||||
{
|
||||
label: $session.display_name || $session.username,
|
||||
image: $session.profile_image_url || '/user.png',
|
||||
onclick: () => {
|
||||
settingsTab = 'account';
|
||||
showSettings = true;
|
||||
}
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...($session ? [{ divider: true, label: '', onclick: () => {} }] : []),
|
||||
{ label: $t('sidebar.settings'), icon: 'settings', onclick: openSettings },
|
||||
...$session?.role === 'admin' ? [{ label: $t('sidebar.admin'), icon: 'shield', onclick: () => { showMenu = false; showAdmin = true; } }] : [],
|
||||
...($session?.role === 'admin'
|
||||
? [
|
||||
{
|
||||
label: $t('sidebar.admin'),
|
||||
icon: 'shield',
|
||||
onclick: () => {
|
||||
showMenu = false;
|
||||
showAdmin = true;
|
||||
}
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{ divider: true, label: '', onclick: () => {} },
|
||||
{ label: $t('sidebar.logOut'), icon: 'log-out', onclick: logout },
|
||||
{ label: $t('sidebar.logOut'), icon: 'log-out', onclick: logout }
|
||||
]}
|
||||
onclose={() => showMenu = false}
|
||||
onclose={() => (showMenu = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showPicker}
|
||||
<DirectoryPicker onclose={() => showPicker = false} />
|
||||
<DirectoryPicker onclose={() => (showPicker = false)} />
|
||||
{/if}
|
||||
|
||||
{#if wsMenuPath && wsMenuAnchor}
|
||||
<DropdownMenu
|
||||
anchor={wsMenuAnchor}
|
||||
items={[
|
||||
{ label: $t('sidebar.remove'), icon: 'xmark', onclick: () => handleRemoveWorkspace(wsMenuPath!) },
|
||||
{
|
||||
label: $t('sidebar.remove'),
|
||||
icon: 'xmark',
|
||||
onclick: () => handleRemoveWorkspace(wsMenuPath!)
|
||||
}
|
||||
]}
|
||||
onclose={closeWsMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showSettings}
|
||||
<SettingsModal initialTab={settingsTab} onclose={() => { showSettings = false; settingsTab = 'general'; }} />
|
||||
<SettingsModal
|
||||
initialTab={settingsTab}
|
||||
onclose={() => {
|
||||
showSettings = false;
|
||||
settingsTab = 'general';
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showAdmin}
|
||||
<AdminPanel onclose={() => showAdmin = false} />
|
||||
<AdminPanel onclose={() => (showAdmin = false)} />
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
|
||||
@@ -50,7 +50,9 @@
|
||||
const parts: string[] = [];
|
||||
if (sys.cpu_usage != null) parts.push(`cpu ${sys.cpu_usage}%`);
|
||||
if (sys.memory_total) {
|
||||
const memPct = Math.round(((sys.memory_total - (sys.memory_available ?? 0)) / sys.memory_total) * 100);
|
||||
const memPct = Math.round(
|
||||
((sys.memory_total - (sys.memory_available ?? 0)) / sys.memory_total) * 100
|
||||
);
|
||||
parts.push(`mem ${memPct}%`);
|
||||
}
|
||||
if (sys.disk_total) {
|
||||
@@ -68,10 +70,15 @@
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="text-[11px] text-gray-500 dark:text-gray-500">{$t('system.cpu')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono">{sys.cpu_usage}%</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{sys.cpu_usage}%</span
|
||||
>
|
||||
</div>
|
||||
<div class="h-1.5 rounded-full bg-gray-100 dark:bg-white/6 overflow-hidden">
|
||||
<div class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all" style="width: {sys.cpu_usage}%"></div>
|
||||
<div
|
||||
class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all"
|
||||
style="width: {sys.cpu_usage}%"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -82,10 +89,15 @@
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="text-[11px] text-gray-500 dark:text-gray-500">{$t('system.memory')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono">{formatBytes(memUsed)} / {formatBytes(sys.memory_total)}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{formatBytes(memUsed)} / {formatBytes(sys.memory_total)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="h-1.5 rounded-full bg-gray-100 dark:bg-white/6 overflow-hidden">
|
||||
<div class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all" style="width: {memPct}%"></div>
|
||||
<div
|
||||
class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all"
|
||||
style="width: {memPct}%"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -95,10 +107,15 @@
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="text-[11px] text-gray-500 dark:text-gray-500">{$t('system.disk')}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono">{formatBytes(sys.disk_used ?? 0)} / {formatBytes(sys.disk_total)}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{formatBytes(sys.disk_used ?? 0)} / {formatBytes(sys.disk_total)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="h-1.5 rounded-full bg-gray-100 dark:bg-white/6 overflow-hidden">
|
||||
<div class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all" style="width: {diskPct}%"></div>
|
||||
<div
|
||||
class="h-full rounded-full bg-gray-400 dark:bg-gray-500 transition-all"
|
||||
style="width: {diskPct}%"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -115,7 +132,9 @@
|
||||
</div>
|
||||
|
||||
{#if sys.network?.length}
|
||||
<div class="flex flex-wrap gap-x-4 gap-y-0.5 text-[11px] font-mono text-gray-400 dark:text-gray-600">
|
||||
<div
|
||||
class="flex flex-wrap gap-x-4 gap-y-0.5 text-[11px] font-mono text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
{#each sys.network as iface}
|
||||
<span>{iface.name} {iface.ip}</span>
|
||||
{/each}
|
||||
@@ -131,7 +150,9 @@
|
||||
</div>
|
||||
{#each processes as proc}
|
||||
<div class="flex items-center gap-2 text-gray-500 dark:text-gray-500 py-px">
|
||||
<span class="w-14 text-right text-gray-700 dark:text-gray-300">{proc.cpu.toFixed(1)}%</span>
|
||||
<span class="w-14 text-right text-gray-700 dark:text-gray-300"
|
||||
>{proc.cpu.toFixed(1)}%</span
|
||||
>
|
||||
<span class="w-12 text-right">{proc.mem.toFixed(1)}%</span>
|
||||
<span class="flex-1 truncate">{proc.name}</span>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// 0x00 + raw input bytes (microtask-batched for throughput)
|
||||
// 0x02 + uint16 cols + uint16 rows, big-endian (5 bytes total)
|
||||
// Server → Client: raw PTY output bytes (no prefix)
|
||||
const MSG_INPUT = 0;
|
||||
const MSG_INPUT = 0;
|
||||
const MSG_RESIZE = 2;
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
@@ -19,9 +19,9 @@
|
||||
// and per-flush Uint8Array creation. Microtask-flushed for batching.
|
||||
const INPUT_BUF_CAP = 4096;
|
||||
const inputBuf = new Uint8Array(INPUT_BUF_CAP);
|
||||
let inputBufLen = 0; // bytes written after the type prefix
|
||||
let inputBufLen = 0; // bytes written after the type prefix
|
||||
let inputFlushScheduled = false;
|
||||
inputBuf[0] = MSG_INPUT; // prefix is constant
|
||||
inputBuf[0] = MSG_INPUT; // prefix is constant
|
||||
|
||||
function flushInput() {
|
||||
inputFlushScheduled = false;
|
||||
@@ -86,7 +86,7 @@
|
||||
foreground: '#e0e0e0',
|
||||
cursor: '#e0e0e0',
|
||||
cursorAccent: '#000000',
|
||||
selectionBackground: 'rgba(255, 255, 255, 0.2)',
|
||||
selectionBackground: 'rgba(255, 255, 255, 0.2)'
|
||||
};
|
||||
|
||||
const lightTheme = {
|
||||
@@ -94,7 +94,7 @@
|
||||
foreground: '#1a1a1a',
|
||||
cursor: '#1a1a1a',
|
||||
cursorAccent: '#ffffff',
|
||||
selectionBackground: 'rgba(0, 0, 0, 0.15)',
|
||||
selectionBackground: 'rgba(0, 0, 0, 0.15)'
|
||||
};
|
||||
|
||||
// Send input to PTY via WebSocket (binary prefix protocol).
|
||||
@@ -143,7 +143,7 @@
|
||||
lineHeight: 1.3,
|
||||
scrollback: 10000,
|
||||
macOptionClickForceSelection: true,
|
||||
theme: isDarkMode() ? darkTheme : lightTheme,
|
||||
theme: isDarkMode() ? darkTheme : lightTheme
|
||||
});
|
||||
|
||||
// Watch for theme changes
|
||||
@@ -346,7 +346,9 @@
|
||||
};
|
||||
|
||||
ws.onclose = (e) => {
|
||||
console.log(`[terminal] WebSocket closed for ${sessionId}, code=${e.code}, reason=${e.reason}`);
|
||||
console.log(
|
||||
`[terminal] WebSocket closed for ${sessionId}, code=${e.code}, reason=${e.reason}`
|
||||
);
|
||||
if (destroyed) return;
|
||||
reconnectTimer = setTimeout(() => {
|
||||
if (!destroyed) connectWebSocket();
|
||||
@@ -372,10 +374,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
bind:this={containerEl}
|
||||
class="h-full w-full pt-1 pl-2 overflow-hidden"
|
||||
></div>
|
||||
<div bind:this={containerEl} class="h-full w-full pt-1 pl-2 overflow-hidden"></div>
|
||||
|
||||
<style>
|
||||
@reference "../../app.css";
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -32,7 +32,15 @@
|
||||
class="flex items-center justify-center w-6 h-6 rounded-full text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 transition-colors duration-100"
|
||||
onclick={trigger}
|
||||
>
|
||||
<svg class="size-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="size-3.5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="12" y1="5" x2="12" y2="19" />
|
||||
<line x1="5" y1="12" x2="19" y2="12" />
|
||||
</svg>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
onpagechange,
|
||||
sortBy = 'updated_at',
|
||||
sortDir = 'desc',
|
||||
onsort,
|
||||
onsort
|
||||
}: Props = $props();
|
||||
|
||||
let menuChatId = $state<string | null>(null);
|
||||
@@ -58,13 +58,29 @@
|
||||
</script>
|
||||
|
||||
{#snippet chevronUp()}
|
||||
<svg class="w-2 h-2" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-2 h-2"
|
||||
viewBox="0 0 10 6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M1 5L5 1L9 5" />
|
||||
</svg>
|
||||
{/snippet}
|
||||
|
||||
{#snippet chevronDown()}
|
||||
<svg class="w-2 h-2" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-2 h-2"
|
||||
viewBox="0 0 10 6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M1 1L5 5L9 1" />
|
||||
</svg>
|
||||
{/snippet}
|
||||
@@ -73,7 +89,9 @@
|
||||
<div class="w-full mt-4 pt-2">
|
||||
<!-- Sort header -->
|
||||
{#if onsort}
|
||||
<div class="flex items-center text-[10px] font-medium text-gray-400 dark:text-gray-600 mb-1 px-2 select-none">
|
||||
<div
|
||||
class="flex items-center text-[10px] font-medium text-gray-400 dark:text-gray-600 mb-1 px-2 select-none"
|
||||
>
|
||||
<button
|
||||
class="flex-1 flex items-center gap-1 hover:text-gray-600 dark:hover:text-gray-400 transition-colors"
|
||||
onclick={() => onsort?.('title')}
|
||||
@@ -114,10 +132,14 @@
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => onopen(chat.id)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') onopen(chat.id); }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') onopen(chat.id);
|
||||
}}
|
||||
>
|
||||
<span class="flex-1 text-xs text-gray-500 dark:text-gray-500 truncate">{chat.title}</span>
|
||||
<span class="text-[10px] text-gray-300 dark:text-gray-700 shrink-0">{formatTime(chat.updated_at)}</span>
|
||||
<span class="text-[10px] text-gray-300 dark:text-gray-700 shrink-0"
|
||||
>{formatTime(chat.updated_at)}</span
|
||||
>
|
||||
<button
|
||||
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-300 dark:text-gray-700 hover:text-gray-500 dark:hover:text-gray-400 transition-all duration-75"
|
||||
onclick={(e) => openMenu(e, chat.id)}
|
||||
@@ -142,7 +164,13 @@
|
||||
anchor={menuAnchor}
|
||||
align="end"
|
||||
items={[
|
||||
{ label: 'Delete', icon: 'trash', onclick: () => { if (menuChatId) ondelete(menuChatId); } },
|
||||
{
|
||||
label: 'Delete',
|
||||
icon: 'trash',
|
||||
onclick: () => {
|
||||
if (menuChatId) ondelete(menuChatId);
|
||||
}
|
||||
}
|
||||
]}
|
||||
onclose={closeMenu}
|
||||
/>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
oncancel,
|
||||
onqueuesendnow,
|
||||
onqueueedit,
|
||||
onqueuedelete,
|
||||
onqueuedelete
|
||||
}: Props = $props();
|
||||
|
||||
let editorEl: HTMLDivElement | undefined = $state();
|
||||
@@ -71,17 +71,23 @@
|
||||
return results.slice(0, 10).map((r: any) => ({
|
||||
id: r.type === 'directory' && !r.path.endsWith('/') ? r.path + '/' : r.path,
|
||||
label: r.name,
|
||||
type: r.type === 'directory' ? 'directory' : 'file',
|
||||
type: r.type === 'directory' ? 'directory' : 'file'
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function mountPopup(items: FileMentionAttrs[], selectedIdx: number, onselect: (i: number) => void) {
|
||||
function mountPopup(
|
||||
items: FileMentionAttrs[],
|
||||
selectedIdx: number,
|
||||
onselect: (i: number) => void
|
||||
) {
|
||||
// Destroy previous instance
|
||||
if (popupComponent) {
|
||||
try { unmount(popupComponent); } catch {}
|
||||
try {
|
||||
unmount(popupComponent);
|
||||
} catch {}
|
||||
popupComponent = null;
|
||||
}
|
||||
if (!popupEl) {
|
||||
@@ -90,7 +96,7 @@
|
||||
}
|
||||
popupComponent = mount(FileSuggestionPopup, {
|
||||
target: popupEl,
|
||||
props: { items, selectedIndex: selectedIdx, onselect },
|
||||
props: { items, selectedIndex: selectedIdx, onselect }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,7 +157,8 @@
|
||||
return true;
|
||||
}
|
||||
if (event.key === 'ArrowUp') {
|
||||
selectedIndex = (selectedIndex - 1 + currentItems.length) % Math.max(currentItems.length, 1);
|
||||
selectedIndex =
|
||||
(selectedIndex - 1 + currentItems.length) % Math.max(currentItems.length, 1);
|
||||
remount();
|
||||
return true;
|
||||
}
|
||||
@@ -168,7 +175,7 @@
|
||||
},
|
||||
onExit() {
|
||||
destroyPopup();
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -186,7 +193,9 @@
|
||||
stopRepositionLoop();
|
||||
activeClientRectFn = null;
|
||||
if (popupComponent) {
|
||||
try { unmount(popupComponent); } catch {}
|
||||
try {
|
||||
unmount(popupComponent);
|
||||
} catch {}
|
||||
popupComponent = null;
|
||||
}
|
||||
if (popupEl) {
|
||||
@@ -201,7 +210,7 @@
|
||||
|
||||
const fileMention = createFileMention({
|
||||
items: fetchSuggestions,
|
||||
render: createSuggestionRenderer,
|
||||
render: createSuggestionRenderer
|
||||
});
|
||||
|
||||
editor = new Editor({
|
||||
@@ -209,12 +218,12 @@
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
codeBlock: false,
|
||||
heading: { levels: [1, 2, 3] },
|
||||
heading: { levels: [1, 2, 3] }
|
||||
}),
|
||||
Markdown,
|
||||
Placeholder.configure({ placeholder }),
|
||||
CodeBlockLowlight.configure({ lowlight }),
|
||||
fileMention,
|
||||
fileMention
|
||||
],
|
||||
content: inputText || '',
|
||||
contentType: inputText ? 'markdown' : undefined,
|
||||
@@ -222,7 +231,7 @@
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: 'chat-prosemirror',
|
||||
spellcheck: 'true',
|
||||
spellcheck: 'true'
|
||||
},
|
||||
handleKeyDown: (view, event) => {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
@@ -246,11 +255,11 @@
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}
|
||||
},
|
||||
onUpdate: ({ editor: e }) => {
|
||||
inputText = (e as any).getMarkdown() || '';
|
||||
},
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -309,8 +318,9 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="rounded-3xl shadow-lg border border-gray-100/40 dark:border-white/4 focus-within:border-gray-200/50 focus-within:dark:border-white/8 transition px-1 bg-white dark:bg-gray-500/5">
|
||||
|
||||
<div
|
||||
class="rounded-3xl shadow-lg border border-gray-100/40 dark:border-white/4 focus-within:border-gray-200/50 focus-within:dark:border-white/8 transition px-1 bg-white dark:bg-gray-500/5"
|
||||
>
|
||||
<!-- Editor area -->
|
||||
<div class="px-2.5">
|
||||
<div
|
||||
@@ -328,11 +338,19 @@
|
||||
onmousedown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div class="ml-0.5 self-end flex items-center">
|
||||
<PlusMenu onfiles={(files) => { /* TODO: handle file uploads */ }} />
|
||||
<PlusMenu
|
||||
onfiles={(files) => {
|
||||
/* TODO: handle file uploads */
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div class="self-end mr-1 flex items-center gap-2">
|
||||
<ModelSelector bind:selectedModel />
|
||||
<DictateButton ontext={(text) => { inputText += text; }} />
|
||||
<DictateButton
|
||||
ontext={(text) => {
|
||||
inputText += text;
|
||||
}}
|
||||
/>
|
||||
<SendButton {canSend} {streaming} {onsend} {oncancel} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -398,9 +416,15 @@
|
||||
}
|
||||
|
||||
/* Headings */
|
||||
.chat-editor-mount :global(.chat-prosemirror h1) { @apply text-base font-semibold my-1; }
|
||||
.chat-editor-mount :global(.chat-prosemirror h2) { @apply text-sm font-semibold my-1; }
|
||||
.chat-editor-mount :global(.chat-prosemirror h3) { @apply text-[13px] font-semibold my-1; }
|
||||
.chat-editor-mount :global(.chat-prosemirror h1) {
|
||||
@apply text-base font-semibold my-1;
|
||||
}
|
||||
.chat-editor-mount :global(.chat-prosemirror h2) {
|
||||
@apply text-sm font-semibold my-1;
|
||||
}
|
||||
.chat-editor-mount :global(.chat-prosemirror h3) {
|
||||
@apply text-[13px] font-semibold my-1;
|
||||
}
|
||||
|
||||
/* HR */
|
||||
.chat-editor-mount :global(.chat-prosemirror hr) {
|
||||
@@ -408,11 +432,26 @@
|
||||
}
|
||||
|
||||
/* Syntax highlighting */
|
||||
.chat-editor-mount :global(.hljs-keyword) { color: #c678dd; }
|
||||
.chat-editor-mount :global(.hljs-string) { color: #98c379; }
|
||||
.chat-editor-mount :global(.hljs-number) { color: #d19a66; }
|
||||
.chat-editor-mount :global(.hljs-comment) { color: #5c6370; font-style: italic; }
|
||||
.chat-editor-mount :global(.hljs-function) { color: #61afef; }
|
||||
.chat-editor-mount :global(.hljs-title) { color: #61afef; }
|
||||
.chat-editor-mount :global(.hljs-built_in) { color: #e5c07b; }
|
||||
.chat-editor-mount :global(.hljs-keyword) {
|
||||
color: #c678dd;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-string) {
|
||||
color: #98c379;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-number) {
|
||||
color: #d19a66;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-comment) {
|
||||
color: #5c6370;
|
||||
font-style: italic;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-function) {
|
||||
color: #61afef;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-title) {
|
||||
color: #61afef;
|
||||
}
|
||||
.chat-editor-mount :global(.hljs-built_in) {
|
||||
color: #e5c07b;
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { getChat, getChats, deleteChat as apiDeleteChat, sendMessage as apiSendMessage, approveToolCall, cancelTask, updateCurrentMessage, updateMessage, createMessage, queueSendNow as apiQueueSendNow, queueDelete as apiQueueDelete, type ChatMessageRow, type ChatInfo } from '$lib/apis/chat';
|
||||
import { chatModels, defaultModel, streamingChatTabs, registerStreamingChat, unregisterStreamingChat } from '$lib/stores/chat';
|
||||
import {
|
||||
getChat,
|
||||
getChats,
|
||||
deleteChat as apiDeleteChat,
|
||||
sendMessage as apiSendMessage,
|
||||
approveToolCall,
|
||||
cancelTask,
|
||||
updateCurrentMessage,
|
||||
updateMessage,
|
||||
createMessage,
|
||||
queueSendNow as apiQueueSendNow,
|
||||
queueDelete as apiQueueDelete,
|
||||
type ChatMessageRow,
|
||||
type ChatInfo
|
||||
} from '$lib/apis/chat';
|
||||
import {
|
||||
chatModels,
|
||||
defaultModel,
|
||||
streamingChatTabs,
|
||||
registerStreamingChat,
|
||||
unregisterStreamingChat
|
||||
} from '$lib/stores/chat';
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -77,16 +97,19 @@
|
||||
if (!allMessages.length) return [];
|
||||
|
||||
// Exclude queued messages from the display path — they only appear in the queue UI
|
||||
const displayMessages = allMessages.filter((m) => !(m.meta?.queued));
|
||||
const displayMessages = allMessages.filter((m) => !m.meta?.queued);
|
||||
if (!displayMessages.length) return [];
|
||||
|
||||
const msgMap = new Map(displayMessages.map((m) => [m.id, m]));
|
||||
const childrenMap = buildChildrenMap(displayMessages);
|
||||
|
||||
// Determine effective currentId: fall back to last message if unset
|
||||
const effectiveId = currentMessageId && msgMap.has(currentMessageId)
|
||||
? currentMessageId
|
||||
: allMessages.length > 0 ? allMessages[allMessages.length - 1].id : null;
|
||||
const effectiveId =
|
||||
currentMessageId && msgMap.has(currentMessageId)
|
||||
? currentMessageId
|
||||
: allMessages.length > 0
|
||||
? allMessages[allMessages.length - 1].id
|
||||
: null;
|
||||
|
||||
if (!effectiveId) return [];
|
||||
|
||||
@@ -109,7 +132,7 @@
|
||||
path.push({
|
||||
msg: next,
|
||||
siblingIds: siblings.map((s) => s.id),
|
||||
siblingIndex: siblings.findIndex((s) => s.id === next.id),
|
||||
siblingIndex: siblings.findIndex((s) => s.id === next.id)
|
||||
});
|
||||
parentId = next.id;
|
||||
}
|
||||
@@ -312,7 +335,11 @@
|
||||
if (data.done) {
|
||||
// Clear streaming indicator for this tab
|
||||
if (tabId) {
|
||||
streamingChatTabs.update((s) => { const n = new Set(s); n.delete(tabId); return n; });
|
||||
streamingChatTabs.update((s) => {
|
||||
const n = new Set(s);
|
||||
n.delete(tabId);
|
||||
return n;
|
||||
});
|
||||
}
|
||||
// Skip reload for cancelled messages — optimistic state is already correct
|
||||
// and reloading causes a visual flash + scroll jump
|
||||
@@ -346,7 +373,10 @@
|
||||
|
||||
const tryBind = () => {
|
||||
const socket = socketStore.getSocket();
|
||||
if (!socket) { setTimeout(tryBind, 100); return; }
|
||||
if (!socket) {
|
||||
setTimeout(tryBind, 100);
|
||||
return;
|
||||
}
|
||||
socket.on('events:chat', handleSocketEvent);
|
||||
socket.on('connect', handleReconnect);
|
||||
};
|
||||
@@ -377,7 +407,8 @@
|
||||
const tid = tabId;
|
||||
streamingChatTabs.update((s) => {
|
||||
const next = new Set(s);
|
||||
if (streaming) next.add(tid); else next.delete(tid);
|
||||
if (streaming) next.add(tid);
|
||||
else next.delete(tid);
|
||||
return next;
|
||||
});
|
||||
});
|
||||
@@ -459,37 +490,51 @@
|
||||
// Cancel active generation, then fall through to normal send
|
||||
const active = allMessages.find((m) => m.role === 'assistant' && !m.done);
|
||||
if (active) {
|
||||
try { await cancelTask(chatId, active.id); } catch {}
|
||||
try {
|
||||
await cancelTask(chatId, active.id);
|
||||
} catch {}
|
||||
await loadChat(chatId);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const mode = get(toolApprovalMode);
|
||||
const result = await apiSendMessage(text, selectedModel, workspace, chatId, parentId, { tool_approval_mode: mode }, undefined, files);
|
||||
if (result.queued) {
|
||||
// Add directly to allMessages so it appears in queue UI instantly
|
||||
allMessages = [...allMessages, {
|
||||
id: result.message_id,
|
||||
parent_id: parentId,
|
||||
role: 'user' as const,
|
||||
content: text,
|
||||
model: null,
|
||||
done: true,
|
||||
output: null,
|
||||
usage: null,
|
||||
meta: { queued: true },
|
||||
created_at: Date.now(),
|
||||
}];
|
||||
} else {
|
||||
await loadChat(result.chat_id);
|
||||
try {
|
||||
const mode = get(toolApprovalMode);
|
||||
const result = await apiSendMessage(
|
||||
text,
|
||||
selectedModel,
|
||||
workspace,
|
||||
chatId,
|
||||
parentId,
|
||||
{ tool_approval_mode: mode },
|
||||
undefined,
|
||||
files
|
||||
);
|
||||
if (result.queued) {
|
||||
// Add directly to allMessages so it appears in queue UI instantly
|
||||
allMessages = [
|
||||
...allMessages,
|
||||
{
|
||||
id: result.message_id,
|
||||
parent_id: parentId,
|
||||
role: 'user' as const,
|
||||
content: text,
|
||||
model: null,
|
||||
done: true,
|
||||
output: null,
|
||||
usage: null,
|
||||
meta: { queued: true },
|
||||
created_at: Date.now()
|
||||
}
|
||||
];
|
||||
} else {
|
||||
await loadChat(result.chat_id);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[chat] send (queue) error', e);
|
||||
} finally {
|
||||
sending = false;
|
||||
chatInputEl?.focus();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[chat] send (queue) error', e);
|
||||
} finally {
|
||||
sending = false;
|
||||
chatInputEl?.focus();
|
||||
}
|
||||
return;
|
||||
return;
|
||||
} // end queue behavior
|
||||
} // end streaming check
|
||||
|
||||
@@ -505,7 +550,7 @@
|
||||
output: null,
|
||||
usage: null,
|
||||
meta: null,
|
||||
created_at: Date.now() / 1000,
|
||||
created_at: Date.now() / 1000
|
||||
};
|
||||
allMessages = [...allMessages, optimisticMsg];
|
||||
currentMessageId = tempId;
|
||||
@@ -517,7 +562,16 @@
|
||||
|
||||
try {
|
||||
const mode = get(toolApprovalMode);
|
||||
const result = await apiSendMessage(text, selectedModel, workspace, chatId ?? undefined, parentId, { tool_approval_mode: mode }, undefined, files);
|
||||
const result = await apiSendMessage(
|
||||
text,
|
||||
selectedModel,
|
||||
workspace,
|
||||
chatId ?? undefined,
|
||||
parentId,
|
||||
{ tool_approval_mode: mode },
|
||||
undefined,
|
||||
files
|
||||
);
|
||||
await loadChat(result.chat_id);
|
||||
if (isNew && tabId) {
|
||||
updateTab(tabId, result.chat_id, text.slice(0, 40) || 'Chat');
|
||||
@@ -604,8 +658,8 @@
|
||||
id: `flush-${Date.now()}`,
|
||||
status: 'completed',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'output_text', text: pendingText }],
|
||||
},
|
||||
content: [{ type: 'output_text', text: pendingText }]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@@ -626,7 +680,8 @@
|
||||
const msg = allMessages.find((m) => m.id === messageId);
|
||||
if (msg?.output) {
|
||||
const call = msg.output.find(
|
||||
(item: any) => item.type === 'function_call' && item.call_id === callId && item.status === 'pending'
|
||||
(item: any) =>
|
||||
item.type === 'function_call' && item.call_id === callId && item.status === 'pending'
|
||||
);
|
||||
if (call) {
|
||||
call.status = approved ? 'running' : 'rejected';
|
||||
@@ -662,7 +717,9 @@
|
||||
|
||||
try {
|
||||
const mode = get(toolApprovalMode);
|
||||
const result = await apiSendMessage('', selectedModel, workspace, chatId, msg.parent_id, { tool_approval_mode: mode });
|
||||
const result = await apiSendMessage('', selectedModel, workspace, chatId, msg.parent_id, {
|
||||
tool_approval_mode: mode
|
||||
});
|
||||
await loadChat(result.chat_id);
|
||||
} catch (e) {
|
||||
console.error('[chat] regenerate error', e);
|
||||
@@ -710,7 +767,13 @@
|
||||
} else {
|
||||
// Save As Copy: create new sibling assistant message (no LLM)
|
||||
try {
|
||||
await createMessage(chatId, msg.parent_id ?? null, 'assistant', content, output ?? undefined);
|
||||
await createMessage(
|
||||
chatId,
|
||||
msg.parent_id ?? null,
|
||||
'assistant',
|
||||
content,
|
||||
output ?? undefined
|
||||
);
|
||||
await loadChat(chatId);
|
||||
} catch (e) {
|
||||
console.error('[chat] save-as-copy error', e);
|
||||
@@ -725,10 +788,8 @@
|
||||
...ws,
|
||||
groups: ws.groups.map((g) => ({
|
||||
...g,
|
||||
tabs: g.tabs.map((t) =>
|
||||
t.id === tid ? { ...t, path: newChatId, label } : t
|
||||
),
|
||||
})),
|
||||
tabs: g.tabs.map((t) => (t.id === tid ? { ...t, path: newChatId, label } : t))
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -738,7 +799,7 @@
|
||||
{#if isLanding}
|
||||
<!-- Landing: input + recent chats -->
|
||||
<div class="flex-1 overflow-y-auto flex items-center justify-center">
|
||||
<div class="max-w-xl w-full mx-auto px-4 flex flex-col pb-[5vh]">
|
||||
<div class="max-w-xl w-full mx-auto px-4 flex flex-col pb-[5vh]">
|
||||
<!-- Greeting -->
|
||||
<div class="mb-8 text-center">
|
||||
<h1 class="text-lg font-normal text-gray-800 dark:text-gray-200 tracking-tight">
|
||||
@@ -759,7 +820,18 @@
|
||||
onqueueedit={handleQueueEdit}
|
||||
onqueuedelete={handleQueueDelete}
|
||||
/>
|
||||
<ChatHistory chats={previousChats} onopen={openChat} ondelete={deleteChat} page={chatPage} {totalPages} perPage={CHATS_PAGE_SIZE} onpagechange={handlePageChange} sortBy={chatSortBy} sortDir={chatSortDir} onsort={handleSort} />
|
||||
<ChatHistory
|
||||
chats={previousChats}
|
||||
onopen={openChat}
|
||||
ondelete={deleteChat}
|
||||
page={chatPage}
|
||||
{totalPages}
|
||||
perPage={CHATS_PAGE_SIZE}
|
||||
onpagechange={handlePageChange}
|
||||
sortBy={chatSortBy}
|
||||
sortDir={chatSortDir}
|
||||
onsort={handleSort}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -767,58 +839,94 @@
|
||||
{#if loading}
|
||||
<div class="flex-1 flex items-center justify-center text-gray-400 dark:text-gray-500">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>.chat-load-spin{transform-origin:center;animation:chat-load-spin .75s infinite linear}@keyframes chat-load-spin{100%{transform:rotate(360deg)}}</style>
|
||||
<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" opacity="0.15" />
|
||||
<path d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z" fill="currentColor" class="chat-load-spin" />
|
||||
<style>
|
||||
.chat-load-spin {
|
||||
transform-origin: center;
|
||||
animation: chat-load-spin 0.75s infinite linear;
|
||||
}
|
||||
@keyframes chat-load-spin {
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<circle
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
opacity="0.15"
|
||||
/>
|
||||
<path
|
||||
d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
|
||||
fill="currentColor"
|
||||
class="chat-load-spin"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
{:else}
|
||||
<div bind:this={messagesEl} class="flex-1 overflow-y-auto" onscroll={handleMessagesScroll}>
|
||||
<div class="max-w-2xl mx-auto px-4 pt-4 pb-16 flex flex-col gap-4">
|
||||
{#if hasHiddenMessages}
|
||||
<div bind:this={loadSentinelEl} class="h-1 w-full" aria-hidden="true"></div>
|
||||
{/if}
|
||||
{#each visiblePath as { msg, siblingIds, siblingIndex } (msg.id)}
|
||||
{#if msg.role === 'user'}
|
||||
<UserMessage
|
||||
content={msg.content}
|
||||
{siblingIndex}
|
||||
siblingTotal={siblingIds.length}
|
||||
onnavigate={(dir) => handleNavigate(msg.id, dir)}
|
||||
onedit={(c, submit) => handleEditMessage(msg.id, c, null, submit)}
|
||||
/>
|
||||
{:else}
|
||||
<AssistantMessage
|
||||
content={msg.content}
|
||||
done={msg.done}
|
||||
output={msg.output}
|
||||
{chatId}
|
||||
messageId={msg.id}
|
||||
{siblingIndex}
|
||||
siblingTotal={siblingIds.length}
|
||||
onnavigate={(dir) => handleNavigate(msg.id, dir)}
|
||||
onregenerate={() => handleRegenerate(msg.id)}
|
||||
onedit={(c, o, submit) => handleEditMessage(msg.id, c, o, submit)}
|
||||
onapprove={handleApprove}
|
||||
/>
|
||||
<div bind:this={messagesEl} class="flex-1 overflow-y-auto" onscroll={handleMessagesScroll}>
|
||||
<div class="max-w-2xl mx-auto px-4 pt-4 pb-16 flex flex-col gap-4">
|
||||
{#if hasHiddenMessages}
|
||||
<div bind:this={loadSentinelEl} class="h-1 w-full" aria-hidden="true"></div>
|
||||
{/if}
|
||||
{/each}
|
||||
{#each visiblePath as { msg, siblingIds, siblingIndex } (msg.id)}
|
||||
{#if msg.role === 'user'}
|
||||
<UserMessage
|
||||
content={msg.content}
|
||||
{siblingIndex}
|
||||
siblingTotal={siblingIds.length}
|
||||
onnavigate={(dir) => handleNavigate(msg.id, dir)}
|
||||
onedit={(c, submit) => handleEditMessage(msg.id, c, null, submit)}
|
||||
/>
|
||||
{:else}
|
||||
<AssistantMessage
|
||||
content={msg.content}
|
||||
done={msg.done}
|
||||
output={msg.output}
|
||||
{chatId}
|
||||
messageId={msg.id}
|
||||
{siblingIndex}
|
||||
siblingTotal={siblingIds.length}
|
||||
onnavigate={(dir) => handleNavigate(msg.id, dir)}
|
||||
onregenerate={() => handleRegenerate(msg.id)}
|
||||
onedit={(c, o, submit) => handleEditMessage(msg.id, c, o, submit)}
|
||||
onapprove={handleApprove}
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Input area -->
|
||||
<div class="px-4 py-3">
|
||||
<div class="max-w-2xl mx-auto relative">
|
||||
{#if !autoScroll && activePath.length > 0}
|
||||
<div class="absolute -top-10 left-0 right-0 pr-2 flex justify-end z-30 pointer-events-none">
|
||||
<div
|
||||
class="absolute -top-10 left-0 right-0 pr-2 flex justify-end z-30 pointer-events-none"
|
||||
>
|
||||
<button
|
||||
class="bg-white dark:bg-white/20 border border-gray-200 dark:border-gray-700 p-1 rounded-full pointer-events-auto shadow-sm hover:bg-gray-50 dark:hover:bg-white/30 transition-colors"
|
||||
onclick={() => { autoScroll = true; scrollToBottom(); }}
|
||||
onclick={() => {
|
||||
autoScroll = true;
|
||||
scrollToBottom();
|
||||
}}
|
||||
aria-label="Scroll to bottom"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-4 h-4 text-gray-500 dark:text-gray-400">
|
||||
<path fill-rule="evenodd" d="M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z" clip-rule="evenodd" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
class="w-4 h-4 text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
|
||||
const SpeechRecognition =
|
||||
(window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
|
||||
if (!SpeechRecognition) {
|
||||
alert('Speech recognition not supported in this browser.');
|
||||
return;
|
||||
@@ -54,11 +55,19 @@
|
||||
type="button"
|
||||
class="flex items-center justify-center rounded-full p-1 transition-colors duration-100
|
||||
{recording
|
||||
? 'text-gray-400 dark:text-gray-500 bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5'}"
|
||||
? 'text-gray-400 dark:text-gray-500 bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5'}"
|
||||
onclick={toggle}
|
||||
>
|
||||
<svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="size-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.75"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="9" y="2" width="6" height="12" rx="3" />
|
||||
<path d="M5 10a7 7 0 0 0 14 0" />
|
||||
<line x1="12" y1="19" x2="12" y2="22" />
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
import Mention from '@tiptap/extension-mention';
|
||||
|
||||
export interface FileMentionAttrs {
|
||||
id: string; // full file path
|
||||
id: string; // full file path
|
||||
label: string; // display name (basename)
|
||||
type: string; // 'file' | 'directory'
|
||||
type: string; // 'file' | 'directory'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ export function createFileMention(suggestionOptions: {
|
||||
}) {
|
||||
return Mention.configure({
|
||||
HTMLAttributes: {
|
||||
class: 'bg-blue-500/10 text-blue-400 rounded px-1 py-px text-xs font-mono',
|
||||
class: 'bg-blue-500/10 text-blue-400 rounded px-1 py-px text-xs font-mono'
|
||||
},
|
||||
renderText({ node }) {
|
||||
const label = node.attrs.label ?? node.attrs.id;
|
||||
@@ -38,8 +38,8 @@ export function createFileMention(suggestionOptions: {
|
||||
suggestion: {
|
||||
char: '@',
|
||||
allowSpaces: false,
|
||||
...suggestionOptions,
|
||||
},
|
||||
...suggestionOptions
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,25 +39,38 @@
|
||||
{#if items.length === 0}
|
||||
<div class="px-3 py-2 text-xs text-gray-400 dark:text-gray-600">No files found</div>
|
||||
{:else}
|
||||
<div class="text-[10px] font-medium text-gray-400 dark:text-gray-600 px-2.5 pt-1.5 pb-0.5">Files</div>
|
||||
<div class="text-[10px] font-medium text-gray-400 dark:text-gray-600 px-2.5 pt-1.5 pb-0.5">
|
||||
Files
|
||||
</div>
|
||||
<div bind:this={listEl}>
|
||||
{#each items as item, i (item.id)}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<button
|
||||
class="flex items-center gap-2 w-full px-2.5 py-1.5 rounded-lg text-left transition-colors duration-75
|
||||
{i === selectedIndex
|
||||
? 'bg-gray-50 dark:bg-white/8 text-gray-900 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
onmousedown={(e) => { e.preventDefault(); onselect(i); }}
|
||||
onmouseenter={() => selectedIndex = i}
|
||||
? 'bg-gray-50 dark:bg-white/8 text-gray-900 dark:text-white'
|
||||
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
|
||||
onmousedown={(e) => {
|
||||
e.preventDefault();
|
||||
onselect(i);
|
||||
}}
|
||||
onmouseenter={() => (selectedIndex = i)}
|
||||
>
|
||||
<span class="flex items-center justify-center w-4 shrink-0 {item.type === 'directory' ? 'text-gray-500 dark:text-gray-400' : 'text-gray-400 dark:text-gray-500'}">
|
||||
<Icon name={fileIconName(item.label, item.type)} size={12} />
|
||||
<span
|
||||
class="flex items-center justify-center w-4 shrink-0 {item.type === 'directory'
|
||||
? 'text-gray-500 dark:text-gray-400'
|
||||
: 'text-gray-400 dark:text-gray-500'}"
|
||||
>
|
||||
<Icon name={fileIconName(item.label, item.type)} size={12} />
|
||||
</span>
|
||||
<span class="flex-1 min-w-0 flex items-baseline gap-1.5 overflow-hidden">
|
||||
<span class="text-xs font-medium truncate text-gray-900 dark:text-gray-200">{item.label}</span>
|
||||
<span class="text-xs font-medium truncate text-gray-900 dark:text-gray-200"
|
||||
>{item.label}</span
|
||||
>
|
||||
{#if relativePath(item.id)}
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 truncate shrink-0">{relativePath(item.id)}</span>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-600 truncate shrink-0"
|
||||
>{relativePath(item.id)}</span
|
||||
>
|
||||
{/if}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
@@ -15,16 +15,18 @@
|
||||
|
||||
const filtered = $derived(
|
||||
search.trim()
|
||||
? $chatModels.filter(m => m.name.toLowerCase().includes(search.toLowerCase()))
|
||||
? $chatModels.filter((m) => m.name.toLowerCase().includes(search.toLowerCase()))
|
||||
: $chatModels
|
||||
);
|
||||
|
||||
const menuItems = $derived(
|
||||
filtered.map(m => ({
|
||||
filtered.map((m) => ({
|
||||
label: m.name,
|
||||
active: m.id === selectedModel,
|
||||
check: true,
|
||||
onclick: () => { selectedModel = m.id; },
|
||||
onclick: () => {
|
||||
selectedModel = m.id;
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -47,8 +49,18 @@
|
||||
class="flex items-center gap-1 px-2 py-1 rounded-lg text-[11px] text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 transition-colors duration-100"
|
||||
onclick={toggle}
|
||||
>
|
||||
<span class="truncate max-w-[160px]">{$chatModels.find(m => m.id === selectedModel)?.name || 'Select model'}</span>
|
||||
<svg class="w-3 h-3 opacity-50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<span class="truncate max-w-[160px]"
|
||||
>{$chatModels.find((m) => m.id === selectedModel)?.name || 'Select model'}</span
|
||||
>
|
||||
<svg
|
||||
class="w-3 h-3 opacity-50"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="6 9 12 15 18 9" />
|
||||
</svg>
|
||||
</button>
|
||||
@@ -57,7 +69,7 @@
|
||||
<DropdownMenu
|
||||
items={menuItems}
|
||||
anchor={btnEl}
|
||||
onclose={() => open = false}
|
||||
onclose={() => (open = false)}
|
||||
preferAbove={true}
|
||||
maxHeight="15rem"
|
||||
className="w-48"
|
||||
@@ -65,7 +77,15 @@
|
||||
>
|
||||
{#snippet header()}
|
||||
<div class="flex items-center gap-1.5 h-6 px-2 mt-0.5">
|
||||
<svg class="w-3 h-3 shrink-0 text-gray-300 dark:text-gray-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3 shrink-0 text-gray-300 dark:text-gray-600"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" /><line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
</svg>
|
||||
<input
|
||||
@@ -73,7 +93,9 @@
|
||||
bind:value={search}
|
||||
placeholder="Search..."
|
||||
class="w-full bg-transparent text-[11px] text-gray-500 dark:text-gray-400 placeholder:text-gray-300 dark:placeholder:text-gray-600 outline-none"
|
||||
onkeydown={(e) => { if (e.key === 'Escape') open = false; }}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Escape') open = false;
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
@@ -234,7 +234,9 @@
|
||||
<div class="flex gap-2 group">
|
||||
<!-- Role label -->
|
||||
<div class="flex items-start pt-1.5">
|
||||
<div class="text-[11px] font-semibold uppercase tracking-wide min-w-[4.5rem] text-gray-400 dark:text-gray-500">
|
||||
<div
|
||||
class="text-[11px] font-semibold uppercase tracking-wide min-w-[4.5rem] text-gray-400 dark:text-gray-500"
|
||||
>
|
||||
{getItemLabel(di)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -268,10 +270,18 @@
|
||||
{:else if di.type === 'function_call'}
|
||||
<div class="text-sm p-1.5 text-gray-500 dark:text-gray-400">
|
||||
{#if di.item.arguments}
|
||||
<pre class="text-xs font-mono whitespace-pre-wrap overflow-x-auto pb-0.5">{formatArgs(di.item.arguments)}</pre>
|
||||
<pre
|
||||
class="text-xs font-mono whitespace-pre-wrap overflow-x-auto pb-0.5">{formatArgs(
|
||||
di.item.arguments
|
||||
)}</pre>
|
||||
{/if}
|
||||
{#if di.outputItem}
|
||||
<pre class="text-xs font-mono whitespace-pre-wrap overflow-x-auto mt-1 max-h-32 overflow-y-auto">{JSON.stringify(di.outputItem.output, null, 2)}</pre>
|
||||
<pre
|
||||
class="text-xs font-mono whitespace-pre-wrap overflow-x-auto mt-1 max-h-32 overflow-y-auto">{JSON.stringify(
|
||||
di.outputItem.output,
|
||||
null,
|
||||
2
|
||||
)}</pre>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -283,8 +293,19 @@
|
||||
class="invisible group-hover:visible p-1 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 transition rounded-lg"
|
||||
onclick={() => deleteIndices(di.indices)}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke="currentColor"
|
||||
class="w-4 h-4"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M15 12H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -292,9 +313,7 @@
|
||||
{/each}
|
||||
|
||||
{#if displayItems.length === 0}
|
||||
<div class="text-sm text-gray-400 dark:text-gray-500 italic px-1">
|
||||
No output items
|
||||
</div>
|
||||
<div class="text-sm text-gray-400 dark:text-gray-500 italic px-1">No output items</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
const modes: { value: ToolApprovalMode; label: string; desc: string }[] = [
|
||||
{ value: 'ask', label: 'Ask for approval', desc: 'Confirm each tool call before it runs' },
|
||||
{ value: 'auto', label: 'Auto-approve', desc: 'Approve safe actions, ask for risky ones' },
|
||||
{ value: 'full', label: 'Full access', desc: 'All tool calls run without confirmation' },
|
||||
{ value: 'full', label: 'Full access', desc: 'All tool calls run without confirmation' }
|
||||
];
|
||||
|
||||
const currentModeLabel = $derived(
|
||||
@@ -94,7 +94,16 @@
|
||||
aria-expanded={open}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<svg class="size-3.5 transition-transform duration-150" class:rotate-45={open} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="size-3.5 transition-transform duration-150"
|
||||
class:rotate-45={open}
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="12" y1="5" x2="12" y2="19" />
|
||||
<line x1="5" y1="12" x2="19" y2="12" />
|
||||
</svg>
|
||||
@@ -108,7 +117,9 @@
|
||||
<div
|
||||
bind:this={menuEl}
|
||||
class="fixed z-[101] w-56 rounded-xl bg-white dark:bg-[#1a1a1a] border border-gray-150 dark:border-white/6 shadow-xl p-0.5 overflow-hidden"
|
||||
style="left: {pos.x}px; bottom: {pos.bottom}px; opacity: {ready ? 1 : 0}; pointer-events: {ready ? 'auto' : 'none'};"
|
||||
style="left: {pos.x}px; bottom: {pos.bottom}px; opacity: {ready ? 1 : 0}; pointer-events: {ready
|
||||
? 'auto'
|
||||
: 'none'};"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{#if tab === ''}
|
||||
@@ -118,8 +129,18 @@
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
|
||||
onclick={triggerUpload}
|
||||
>
|
||||
<svg class="size-3.5 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48" />
|
||||
<svg
|
||||
class="size-3.5 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"
|
||||
/>
|
||||
</svg>
|
||||
<span class="flex-1 text-left truncate">Attach files</span>
|
||||
</button>
|
||||
@@ -128,11 +149,13 @@
|
||||
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
|
||||
onclick={() => tab = 'tools'}
|
||||
onclick={() => (tab = 'tools')}
|
||||
>
|
||||
<Icon name="shield" size={14} />
|
||||
<span class="flex-1 text-left truncate">Tool permissions</span>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-500 truncate max-w-16">{currentModeLabel}</span>
|
||||
<span class="text-[10px] text-gray-400 dark:text-gray-500 truncate max-w-16"
|
||||
>{currentModeLabel}</span
|
||||
>
|
||||
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-400 dark:text-gray-500" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -141,7 +164,7 @@
|
||||
<div class="plus-menu-slide-in-right">
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
|
||||
onclick={() => tab = ''}
|
||||
onclick={() => (tab = '')}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span class="flex-1 text-left font-medium">Tool permissions</span>
|
||||
@@ -153,14 +176,22 @@
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs transition-colors duration-75
|
||||
{$toolApprovalMode === mode.value
|
||||
? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
|
||||
? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
|
||||
onclick={() => selectMode(mode.value)}
|
||||
use:tooltip={{ content: mode.desc, placement: 'right' }}
|
||||
>
|
||||
<span class="flex-1 text-left truncate">{mode.label}</span>
|
||||
{#if $toolApprovalMode === mode.value}
|
||||
<svg class="w-3 h-3 shrink-0 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3 shrink-0 text-gray-400 dark:text-gray-500"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
{/if}
|
||||
|
||||
@@ -12,7 +12,15 @@
|
||||
<div class="flex items-center gap-2 px-2 py-1">
|
||||
<!-- Queue indicator: reply/forward arrow -->
|
||||
<div class="shrink-0 text-gray-400 dark:text-gray-600">
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M13.25 19.25L16.75 15.75L13.25 12.25" />
|
||||
<path d="M16.75 15.75H10.75C8.54086 15.75 6.75 13.9591 6.75 11.75V7.5" />
|
||||
</svg>
|
||||
@@ -30,7 +38,15 @@
|
||||
title="Send now"
|
||||
onclick={() => onsendnow(id)}
|
||||
>
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M4.5 10.5 12 3m0 0 7.5 7.5M12 3v18" />
|
||||
</svg>
|
||||
</button>
|
||||
@@ -41,8 +57,18 @@
|
||||
title="Edit"
|
||||
onclick={() => onedit(id)}
|
||||
>
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125" />
|
||||
<svg
|
||||
class="w-3 h-3"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<!-- Remove -->
|
||||
@@ -52,7 +78,15 @@
|
||||
title="Remove"
|
||||
onclick={() => ondelete(id)}
|
||||
>
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
class="w-3 h-3"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
onclick={oncancel}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-4">
|
||||
<path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm6-2.438c0-.724.588-1.312 1.313-1.312h4.874c.725 0 1.313.588 1.313 1.313v4.874c0 .725-.588 1.313-1.313 1.313H9.564a1.312 1.312 0 01-1.313-1.313V9.564z" clip-rule="evenodd" />
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm6-2.438c0-.724.588-1.312 1.313-1.312h4.874c.725 0 1.313.588 1.313 1.313v4.874c0 .725-.588 1.313-1.313 1.313H9.564a1.312 1.312 0 01-1.313-1.313V9.564z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
{:else}
|
||||
@@ -30,7 +34,11 @@
|
||||
disabled={!canSend}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4">
|
||||
<path fill-rule="evenodd" d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z" clip-rule="evenodd" />
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
@@ -86,7 +86,9 @@
|
||||
function copyContent() {
|
||||
navigator.clipboard.writeText(content);
|
||||
copied = true;
|
||||
setTimeout(() => { copied = false; }, 1500);
|
||||
setTimeout(() => {
|
||||
copied = false;
|
||||
}, 1500);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -94,7 +96,9 @@
|
||||
{#if edit}
|
||||
<!-- Edit mode: full width -->
|
||||
<div class="w-full">
|
||||
<div class="bg-gray-50 dark:bg-white/4 rounded-xl border border-gray-200 dark:border-white/8 px-3.5 py-2.5">
|
||||
<div
|
||||
class="bg-gray-50 dark:bg-white/4 rounded-xl border border-gray-200 dark:border-white/8 px-3.5 py-2.5"
|
||||
>
|
||||
<textarea
|
||||
bind:this={textareaEl}
|
||||
bind:value={editedContent}
|
||||
@@ -107,17 +111,17 @@
|
||||
<div class="flex justify-between mt-2 text-[12px] font-medium">
|
||||
<button
|
||||
class="px-3 py-1 rounded-lg text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 bg-gray-100 dark:bg-white/6 hover:bg-gray-200 dark:hover:bg-white/10 transition-colors duration-100"
|
||||
onclick={saveEdit}
|
||||
>Save</button>
|
||||
onclick={saveEdit}>Save</button
|
||||
>
|
||||
<div class="flex gap-1.5">
|
||||
<button
|
||||
class="px-3 py-1 rounded-lg text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={cancelEdit}
|
||||
>Cancel</button>
|
||||
onclick={cancelEdit}>Cancel</button
|
||||
>
|
||||
<button
|
||||
class="px-3 py-1 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-black hover:bg-gray-700 dark:hover:bg-gray-200 transition-colors duration-100"
|
||||
onclick={sendEdit}
|
||||
>Send</button>
|
||||
onclick={sendEdit}>Send</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,7 +129,30 @@
|
||||
<!-- Bubble: right-aligned -->
|
||||
<div class="flex justify-end">
|
||||
<div class="max-w-[90%] px-4 py-2 rounded-3xl bg-gray-50 dark:bg-white/[0.06]">
|
||||
<div class="text-[13px] leading-relaxed text-gray-900 dark:text-gray-200 whitespace-pre-wrap break-words">{#each parsedContent as segment}{#if segment.type === 'text'}{segment.value}{:else}{@const isDir = segment.path.endsWith('/')}{@const cleanPath = isDir ? segment.path.slice(0, -1) : segment.path}<button class="inline-flex items-center gap-0.5 bg-blue-500/10 text-blue-400 rounded px-1.5 py-px mx-0.5 text-xs font-mono align-baseline border-none cursor-pointer hover:bg-blue-500/20 transition-colors" title={cleanPath} onclick={(e) => { e.preventDefault(); if (isDir) { setFileBrowserCwd(cleanPath); setActiveTab('files'); } else { openFileTab(cleanPath); } }}><Icon name={isDir ? 'folder' : fileIconName(segment.label, 'file')} size={11} />{segment.label}</button>{/if}{/each}</div>
|
||||
<div
|
||||
class="text-[13px] leading-relaxed text-gray-900 dark:text-gray-200 whitespace-pre-wrap break-words"
|
||||
>
|
||||
{#each parsedContent as segment}{#if segment.type === 'text'}{segment.value}{:else}{@const isDir =
|
||||
segment.path.endsWith('/')}{@const cleanPath = isDir
|
||||
? segment.path.slice(0, -1)
|
||||
: segment.path}<button
|
||||
class="inline-flex items-center gap-0.5 bg-blue-500/10 text-blue-400 rounded px-1.5 py-px mx-0.5 text-xs font-mono align-baseline border-none cursor-pointer hover:bg-blue-500/20 transition-colors"
|
||||
title={cleanPath}
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
if (isDir) {
|
||||
setFileBrowserCwd(cleanPath);
|
||||
setActiveTab('files');
|
||||
} else {
|
||||
openFileTab(cleanPath);
|
||||
}
|
||||
}}
|
||||
><Icon
|
||||
name={isDir ? 'folder' : fileIconName(segment.label, 'file')}
|
||||
size={11}
|
||||
/>{segment.label}</button
|
||||
>{/if}{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if siblingTotal > 1 || onedit}
|
||||
@@ -137,16 +164,32 @@
|
||||
onclick={() => onnavigate?.(-1)}
|
||||
aria-label="Previous message"
|
||||
>
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg>
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
||||
><path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M15 19l-7-7 7-7"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
<span class="text-[11px] tabular-nums text-gray-400 dark:text-gray-600 select-none">{siblingIndex + 1}/{siblingTotal}</span>
|
||||
<span class="text-[11px] tabular-nums text-gray-400 dark:text-gray-600 select-none"
|
||||
>{siblingIndex + 1}/{siblingTotal}</span
|
||||
>
|
||||
<button
|
||||
class="p-0.5 rounded text-gray-400 dark:text-gray-600 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-30 disabled:cursor-default transition-colors duration-100"
|
||||
disabled={siblingIndex === siblingTotal - 1}
|
||||
onclick={() => onnavigate?.(1)}
|
||||
aria-label="Next message"
|
||||
>
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
||||
><path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M9 5l7 7-7 7"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
{#if onedit}
|
||||
@@ -155,8 +198,19 @@
|
||||
onclick={startEdit}
|
||||
aria-label="Edit message"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-3.5 h-3.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke="currentColor"
|
||||
class="w-3.5 h-3.5"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
@@ -166,9 +220,33 @@
|
||||
aria-label="Copy message"
|
||||
>
|
||||
{#if copied}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" class="w-3.5 h-3.5"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2.5"
|
||||
stroke="currentColor"
|
||||
class="w-3.5 h-3.5"
|
||||
><path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M4.5 12.75l6 6 9-13.5"
|
||||
/></svg
|
||||
>
|
||||
{:else}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-3.5 h-3.5"><path stroke-linecap="round" stroke-linejoin="round" d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184" /></svg>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke="currentColor"
|
||||
class="w-3.5 h-3.5"
|
||||
><path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184"
|
||||
/></svg
|
||||
>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -30,7 +30,16 @@
|
||||
onclick={() => onpagechange(page - 1)}
|
||||
aria-label="Previous page"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 12 12"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.75"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M7.5 2.5L4 6L7.5 9.5" />
|
||||
</svg>
|
||||
</button>
|
||||
@@ -57,7 +66,16 @@
|
||||
onclick={() => onpagechange(page + 1)}
|
||||
aria-label="Next page"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 12 12"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.75"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M4.5 2.5L8 6L4.5 9.5" />
|
||||
</svg>
|
||||
</button>
|
||||
@@ -87,7 +105,9 @@
|
||||
font-size: 10.5px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease, color 0.15s ease;
|
||||
transition:
|
||||
background 0.15s ease,
|
||||
color 0.15s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,22 +18,18 @@
|
||||
<svelte:element this={`h${h.depth}`}>
|
||||
<InlineRenderer items={h.tokens} />
|
||||
</svelte:element>
|
||||
|
||||
{:else if token.type === 'paragraph'}
|
||||
<p><InlineRenderer items={(token as Tokens.Paragraph).tokens} /></p>
|
||||
|
||||
{:else if token.type === 'code'}
|
||||
{#if (token as Tokens.Code).lang === 'mermaid'}
|
||||
<MermaidBlock code={(token as Tokens.Code).text} />
|
||||
{:else}
|
||||
<CodeBlock language={(token as Tokens.Code).lang ?? ''} code={(token as Tokens.Code).text} />
|
||||
{/if}
|
||||
|
||||
{:else if token.type === 'blockquote'}
|
||||
<blockquote>
|
||||
<svelte:self tokens={(token as Tokens.Blockquote).tokens} />
|
||||
</blockquote>
|
||||
|
||||
{:else if token.type === 'list'}
|
||||
{@const list = token as Tokens.List}
|
||||
<svelte:element this={list.ordered ? 'ol' : 'ul'} start={list.ordered ? list.start : undefined}>
|
||||
@@ -48,13 +44,16 @@
|
||||
</li>
|
||||
{/each}
|
||||
</svelte:element>
|
||||
|
||||
{:else if token.type === 'table'}
|
||||
{@const table = token as Tokens.Table}
|
||||
<div class="not-prose relative w-full group/table">
|
||||
<div class="overflow-x-auto max-w-full rounded-lg border border-gray-200/60 dark:border-white/8">
|
||||
<div
|
||||
class="overflow-x-auto max-w-full rounded-lg border border-gray-200/60 dark:border-white/8"
|
||||
>
|
||||
<table class="w-full text-[13px] text-left text-gray-600 dark:text-gray-300">
|
||||
<thead class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50/80 dark:bg-white/[0.03]">
|
||||
<thead
|
||||
class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50/80 dark:bg-white/[0.03]"
|
||||
>
|
||||
<tr>
|
||||
{#each table.header as cell, i}
|
||||
<th
|
||||
@@ -72,7 +71,9 @@
|
||||
<tr class="bg-white dark:bg-transparent">
|
||||
{#each row as cell, i}
|
||||
<td
|
||||
class="px-3 py-1.5 {rowIdx < table.rows.length - 1 ? 'border-b border-gray-100/60 dark:border-white/5' : ''}"
|
||||
class="px-3 py-1.5 {rowIdx < table.rows.length - 1
|
||||
? 'border-b border-gray-100/60 dark:border-white/5'
|
||||
: ''}"
|
||||
style={table.align[i] ? `text-align:${table.align[i]}` : ''}
|
||||
>
|
||||
<InlineRenderer items={cell.tokens} />
|
||||
@@ -93,8 +94,19 @@
|
||||
navigator.clipboard.writeText((token as Tokens.Table).raw?.trim() ?? '');
|
||||
}}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="size-3.5"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
@@ -102,9 +114,9 @@
|
||||
title="Download CSV"
|
||||
onclick={() => {
|
||||
const t = token as Tokens.Table;
|
||||
const header = t.header.map(h => `"${h.text.replace(/"/g, '""')}"`);
|
||||
const rows = t.rows.map(r => r.map(c => `"${c.text.replace(/"/g, '""')}"`));
|
||||
const csv = [header, ...rows].map(r => r.join(',')).join('\n');
|
||||
const header = t.header.map((h) => `"${h.text.replace(/"/g, '""')}"`);
|
||||
const rows = t.rows.map((r) => r.map((c) => `"${c.text.replace(/"/g, '""')}"`));
|
||||
const csv = [header, ...rows].map((r) => r.join(',')).join('\n');
|
||||
const blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=UTF-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
@@ -114,29 +126,35 @@
|
||||
URL.revokeObjectURL(url);
|
||||
}}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="size-3.5"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{:else if token.type === 'hr'}
|
||||
<hr class="border-gray-100/60 dark:border-gray-850/40" />
|
||||
|
||||
{:else if token.type === 'text'}
|
||||
{#if 'tokens' in token && token.tokens}
|
||||
<InlineRenderer items={token.tokens} />
|
||||
{:else}
|
||||
{token.raw}
|
||||
{/if}
|
||||
|
||||
{:else if token.type === 'html'}
|
||||
<!-- Skip raw HTML for safety -->
|
||||
|
||||
{:else if token.type === 'def'}
|
||||
<!-- Link reference definition, no visual output -->
|
||||
|
||||
{:else if token.type === 'space'}
|
||||
<!-- skip -->
|
||||
{/if}
|
||||
|
||||
@@ -1,241 +1,226 @@
|
||||
<script lang="ts">
|
||||
import type { HighlighterCore } from "shiki/core";
|
||||
import type { HighlighterCore } from 'shiki/core';
|
||||
|
||||
interface Props {
|
||||
language: string;
|
||||
code: string;
|
||||
/** Optional diff-style callbacks for chat tool approval */
|
||||
onapply?: ((code: string) => void) | undefined;
|
||||
onreject?: (() => void) | undefined;
|
||||
}
|
||||
interface Props {
|
||||
language: string;
|
||||
code: string;
|
||||
/** Optional diff-style callbacks for chat tool approval */
|
||||
onapply?: ((code: string) => void) | undefined;
|
||||
onreject?: (() => void) | undefined;
|
||||
}
|
||||
|
||||
let { language, code, onapply, onreject }: Props = $props();
|
||||
let { language, code, onapply, onreject }: Props = $props();
|
||||
|
||||
let codeEl: HTMLElement | undefined = $state();
|
||||
let copied = $state(false);
|
||||
let codeEl: HTMLElement | undefined = $state();
|
||||
let copied = $state(false);
|
||||
|
||||
// Detect diff blocks
|
||||
let isDiff = $derived(language === "diff");
|
||||
// Detect diff blocks
|
||||
let isDiff = $derived(language === 'diff');
|
||||
|
||||
// Parse diff lines for coloring
|
||||
let diffLines = $derived.by(() => {
|
||||
if (!isDiff) return [];
|
||||
return code.split("\n").map((line) => ({
|
||||
text: line,
|
||||
type: line.startsWith("+")
|
||||
? ("add" as const)
|
||||
: line.startsWith("-")
|
||||
? ("del" as const)
|
||||
: line.startsWith("@@")
|
||||
? ("range" as const)
|
||||
: ("ctx" as const),
|
||||
}));
|
||||
});
|
||||
// Parse diff lines for coloring
|
||||
let diffLines = $derived.by(() => {
|
||||
if (!isDiff) return [];
|
||||
return code.split('\n').map((line) => ({
|
||||
text: line,
|
||||
type: line.startsWith('+')
|
||||
? ('add' as const)
|
||||
: line.startsWith('-')
|
||||
? ('del' as const)
|
||||
: line.startsWith('@@')
|
||||
? ('range' as const)
|
||||
: ('ctx' as const)
|
||||
}));
|
||||
});
|
||||
|
||||
// Lazy-loaded Shiki highlighter singleton
|
||||
let highlighterPromise: Promise<HighlighterCore> | null = null;
|
||||
// Lazy-loaded Shiki highlighter singleton
|
||||
let highlighterPromise: Promise<HighlighterCore> | null = null;
|
||||
|
||||
async function getHighlighter(): Promise<HighlighterCore> {
|
||||
if (!highlighterPromise) {
|
||||
highlighterPromise = (async () => {
|
||||
const { createHighlighterCore } = await import("shiki/core");
|
||||
const { createOnigurumaEngine } = await import(
|
||||
"shiki/engine/oniguruma"
|
||||
);
|
||||
const hl = await createHighlighterCore({
|
||||
themes: [
|
||||
import("shiki/themes/github-light.mjs"),
|
||||
import("shiki/themes/github-dark.mjs"),
|
||||
],
|
||||
langs: [
|
||||
import("shiki/langs/javascript.mjs"),
|
||||
import("shiki/langs/typescript.mjs"),
|
||||
import("shiki/langs/python.mjs"),
|
||||
import("shiki/langs/bash.mjs"),
|
||||
import("shiki/langs/shell.mjs"),
|
||||
import("shiki/langs/json.mjs"),
|
||||
import("shiki/langs/html.mjs"),
|
||||
import("shiki/langs/css.mjs"),
|
||||
import("shiki/langs/markdown.mjs"),
|
||||
import("shiki/langs/yaml.mjs"),
|
||||
import("shiki/langs/toml.mjs"),
|
||||
import("shiki/langs/rust.mjs"),
|
||||
import("shiki/langs/go.mjs"),
|
||||
import("shiki/langs/c.mjs"),
|
||||
import("shiki/langs/cpp.mjs"),
|
||||
import("shiki/langs/java.mjs"),
|
||||
import("shiki/langs/sql.mjs"),
|
||||
import("shiki/langs/svelte.mjs"),
|
||||
import("shiki/langs/dockerfile.mjs"),
|
||||
import("shiki/langs/xml.mjs"),
|
||||
import("shiki/langs/ruby.mjs"),
|
||||
import("shiki/langs/php.mjs"),
|
||||
import("shiki/langs/swift.mjs"),
|
||||
import("shiki/langs/kotlin.mjs"),
|
||||
import("shiki/langs/lua.mjs"),
|
||||
import("shiki/langs/tsx.mjs"),
|
||||
import("shiki/langs/jsx.mjs"),
|
||||
import("shiki/langs/scss.mjs"),
|
||||
import("shiki/langs/graphql.mjs"),
|
||||
import("shiki/langs/makefile.mjs"),
|
||||
],
|
||||
engine: createOnigurumaEngine(import("shiki/wasm")),
|
||||
});
|
||||
return hl;
|
||||
})();
|
||||
}
|
||||
return highlighterPromise;
|
||||
}
|
||||
async function getHighlighter(): Promise<HighlighterCore> {
|
||||
if (!highlighterPromise) {
|
||||
highlighterPromise = (async () => {
|
||||
const { createHighlighterCore } = await import('shiki/core');
|
||||
const { createOnigurumaEngine } = await import('shiki/engine/oniguruma');
|
||||
const hl = await createHighlighterCore({
|
||||
themes: [import('shiki/themes/github-light.mjs'), import('shiki/themes/github-dark.mjs')],
|
||||
langs: [
|
||||
import('shiki/langs/javascript.mjs'),
|
||||
import('shiki/langs/typescript.mjs'),
|
||||
import('shiki/langs/python.mjs'),
|
||||
import('shiki/langs/bash.mjs'),
|
||||
import('shiki/langs/shell.mjs'),
|
||||
import('shiki/langs/json.mjs'),
|
||||
import('shiki/langs/html.mjs'),
|
||||
import('shiki/langs/css.mjs'),
|
||||
import('shiki/langs/markdown.mjs'),
|
||||
import('shiki/langs/yaml.mjs'),
|
||||
import('shiki/langs/toml.mjs'),
|
||||
import('shiki/langs/rust.mjs'),
|
||||
import('shiki/langs/go.mjs'),
|
||||
import('shiki/langs/c.mjs'),
|
||||
import('shiki/langs/cpp.mjs'),
|
||||
import('shiki/langs/java.mjs'),
|
||||
import('shiki/langs/sql.mjs'),
|
||||
import('shiki/langs/svelte.mjs'),
|
||||
import('shiki/langs/dockerfile.mjs'),
|
||||
import('shiki/langs/xml.mjs'),
|
||||
import('shiki/langs/ruby.mjs'),
|
||||
import('shiki/langs/php.mjs'),
|
||||
import('shiki/langs/swift.mjs'),
|
||||
import('shiki/langs/kotlin.mjs'),
|
||||
import('shiki/langs/lua.mjs'),
|
||||
import('shiki/langs/tsx.mjs'),
|
||||
import('shiki/langs/jsx.mjs'),
|
||||
import('shiki/langs/scss.mjs'),
|
||||
import('shiki/langs/graphql.mjs'),
|
||||
import('shiki/langs/makefile.mjs')
|
||||
],
|
||||
engine: createOnigurumaEngine(import('shiki/wasm'))
|
||||
});
|
||||
return hl;
|
||||
})();
|
||||
}
|
||||
return highlighterPromise;
|
||||
}
|
||||
|
||||
// Highlight non-diff code: reactive so it re-runs on prop changes (streaming)
|
||||
$effect(() => {
|
||||
if (isDiff || !codeEl) return;
|
||||
const currentCode = code;
|
||||
const currentLang = language;
|
||||
// Highlight non-diff code: reactive so it re-runs on prop changes (streaming)
|
||||
$effect(() => {
|
||||
if (isDiff || !codeEl) return;
|
||||
const currentCode = code;
|
||||
const currentLang = language;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const hl = await getHighlighter();
|
||||
if (!codeEl || currentCode !== code) return;
|
||||
(async () => {
|
||||
try {
|
||||
const hl = await getHighlighter();
|
||||
if (!codeEl || currentCode !== code) return;
|
||||
|
||||
const lang =
|
||||
currentLang && hl.getLoadedLanguages().includes(currentLang)
|
||||
? currentLang
|
||||
: "text";
|
||||
const lang =
|
||||
currentLang && hl.getLoadedLanguages().includes(currentLang) ? currentLang : 'text';
|
||||
|
||||
const html = hl.codeToHtml(currentCode, {
|
||||
lang,
|
||||
themes: { light: "github-light", dark: "github-dark" },
|
||||
defaultColor: false, // use CSS variables for theme switching
|
||||
});
|
||||
const html = hl.codeToHtml(currentCode, {
|
||||
lang,
|
||||
themes: { light: 'github-light', dark: 'github-dark' },
|
||||
defaultColor: false // use CSS variables for theme switching
|
||||
});
|
||||
|
||||
// Shiki wraps in <pre style="--shiki-light:...;--shiki-dark:..."><code>...</code></pre>
|
||||
// We extract the <code> innerHTML but must also transfer the CSS vars
|
||||
// from <pre> onto our own <code> so base-color vars resolve.
|
||||
const tmp = document.createElement("div");
|
||||
tmp.innerHTML = html;
|
||||
const shikiPre = tmp.querySelector("pre");
|
||||
const shikiCode = tmp.querySelector("code");
|
||||
if (shikiCode && codeEl) {
|
||||
codeEl.innerHTML = shikiCode.innerHTML;
|
||||
// Copy --shiki-* CSS vars from the discarded <pre> onto our <code>
|
||||
if (shikiPre) {
|
||||
const preStyle = shikiPre.getAttribute("style") || "";
|
||||
const vars =
|
||||
preStyle.match(/--shiki[\w-]*:[^;]+/g) || [];
|
||||
vars.forEach((v) => {
|
||||
const [name, val] = v.split(":");
|
||||
if (name && val)
|
||||
codeEl!.style.setProperty(
|
||||
name.trim(),
|
||||
val.trim(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fallback: just show plain text
|
||||
}
|
||||
})();
|
||||
});
|
||||
// Shiki wraps in <pre style="--shiki-light:...;--shiki-dark:..."><code>...</code></pre>
|
||||
// We extract the <code> innerHTML but must also transfer the CSS vars
|
||||
// from <pre> onto our own <code> so base-color vars resolve.
|
||||
const tmp = document.createElement('div');
|
||||
tmp.innerHTML = html;
|
||||
const shikiPre = tmp.querySelector('pre');
|
||||
const shikiCode = tmp.querySelector('code');
|
||||
if (shikiCode && codeEl) {
|
||||
codeEl.innerHTML = shikiCode.innerHTML;
|
||||
// Copy --shiki-* CSS vars from the discarded <pre> onto our <code>
|
||||
if (shikiPre) {
|
||||
const preStyle = shikiPre.getAttribute('style') || '';
|
||||
const vars = preStyle.match(/--shiki[\w-]*:[^;]+/g) || [];
|
||||
vars.forEach((v) => {
|
||||
const [name, val] = v.split(':');
|
||||
if (name && val) codeEl!.style.setProperty(name.trim(), val.trim());
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fallback: just show plain text
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
function handleCopy() {
|
||||
navigator.clipboard.writeText(code);
|
||||
copied = true;
|
||||
setTimeout(() => {
|
||||
copied = false;
|
||||
}, 2000);
|
||||
}
|
||||
function handleCopy() {
|
||||
navigator.clipboard.writeText(code);
|
||||
copied = true;
|
||||
setTimeout(() => {
|
||||
copied = false;
|
||||
}, 2000);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="not-prose rounded-2xl overflow-hidden bg-black/[0.03] dark:bg-white/[0.03] border border-black/[0.06] dark:border-white/[0.06]"
|
||||
class="not-prose rounded-2xl overflow-hidden bg-black/[0.03] dark:bg-white/[0.03] border border-black/[0.06] dark:border-white/[0.06]"
|
||||
>
|
||||
<div class="flex items-center justify-between h-[30px] px-2.5">
|
||||
<span class="text-[11px] font-medium text-gray-500 lowercase"
|
||||
>{language || "text"}</span
|
||||
>
|
||||
<div class="flex items-center gap-1">
|
||||
{#if isDiff && onapply}
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-green-600 hover:bg-green-600/10 transition-all duration-100"
|
||||
onclick={() => onapply?.(code)}>Apply</button
|
||||
>
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-red-600 hover:bg-red-600/10 transition-all duration-100"
|
||||
onclick={() => onreject?.()}>Reject</button
|
||||
>
|
||||
{/if}
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/[0.08] transition-all duration-100"
|
||||
onclick={handleCopy}
|
||||
>
|
||||
{copied ? "✓" : "Copy"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between h-[30px] px-2.5">
|
||||
<span class="text-[11px] font-medium text-gray-500 lowercase">{language || 'text'}</span>
|
||||
<div class="flex items-center gap-1">
|
||||
{#if isDiff && onapply}
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-green-600 hover:bg-green-600/10 transition-all duration-100"
|
||||
onclick={() => onapply?.(code)}>Apply</button
|
||||
>
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-red-600 hover:bg-red-600/10 transition-all duration-100"
|
||||
onclick={() => onreject?.()}>Reject</button
|
||||
>
|
||||
{/if}
|
||||
<button
|
||||
class="text-[11px] px-2 py-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/[0.08] transition-all duration-100"
|
||||
onclick={handleCopy}
|
||||
>
|
||||
{copied ? '✓' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if isDiff}
|
||||
<pre
|
||||
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent font-mono"><code
|
||||
>{#each diffLines as line}<span
|
||||
class="diff-line diff-{line.type}"
|
||||
>{line.text}
|
||||
{#if isDiff}
|
||||
<pre
|
||||
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent font-mono"><code
|
||||
>{#each diffLines as line}<span class="diff-line diff-{line.type}"
|
||||
>{line.text}
|
||||
</span>{/each}</code
|
||||
></pre>
|
||||
{:else}
|
||||
<pre
|
||||
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent text-[#24292e] dark:text-[#e1e4e8] font-mono"><code
|
||||
class="font-[inherit]"
|
||||
bind:this={codeEl}>{code}</code
|
||||
></pre>
|
||||
{/if}
|
||||
></pre>
|
||||
{:else}
|
||||
<pre
|
||||
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent text-[#24292e] dark:text-[#e1e4e8] font-mono"><code
|
||||
class="font-[inherit]"
|
||||
bind:this={codeEl}>{code}</code
|
||||
></pre>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@reference "../../../app.css";
|
||||
@reference "../../../app.css";
|
||||
|
||||
/* ── Shiki dual-theme: switch via CSS variables ── */
|
||||
/* ── Shiki dual-theme: switch via CSS variables ── */
|
||||
|
||||
pre :global(span) {
|
||||
color: var(--shiki-light);
|
||||
}
|
||||
pre :global(span) {
|
||||
color: var(--shiki-light);
|
||||
}
|
||||
|
||||
:global(.dark) pre :global(span) {
|
||||
color: var(--shiki-dark);
|
||||
}
|
||||
:global(.dark) pre :global(span) {
|
||||
color: var(--shiki-dark);
|
||||
}
|
||||
|
||||
/* ── Diff line coloring ──────────────────────── */
|
||||
/* ── Diff line coloring ──────────────────────── */
|
||||
|
||||
.diff-line {
|
||||
display: block;
|
||||
}
|
||||
.diff-line {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.diff-line.diff-add {
|
||||
background: rgba(22, 163, 74, 0.1);
|
||||
color: #16a34a;
|
||||
}
|
||||
.diff-line.diff-add {
|
||||
background: rgba(22, 163, 74, 0.1);
|
||||
color: #16a34a;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-line.diff-add {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
color: #4ade80;
|
||||
}
|
||||
:global(.dark) .diff-line.diff-add {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.diff-line.diff-del {
|
||||
background: rgba(220, 38, 38, 0.08);
|
||||
color: #dc2626;
|
||||
}
|
||||
.diff-line.diff-del {
|
||||
background: rgba(220, 38, 38, 0.08);
|
||||
color: #dc2626;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-line.diff-del {
|
||||
background: rgba(248, 113, 113, 0.1);
|
||||
color: #f87171;
|
||||
}
|
||||
:global(.dark) .diff-line.diff-del {
|
||||
background: rgba(248, 113, 113, 0.1);
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.diff-line.diff-range {
|
||||
color: #8b5cf6;
|
||||
}
|
||||
.diff-line.diff-range {
|
||||
color: #8b5cf6;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-line.diff-range {
|
||||
color: #a78bfa;
|
||||
}
|
||||
:global(.dark) .diff-line.diff-range {
|
||||
color: #a78bfa;
|
||||
}
|
||||
</style>
|
||||
@@ -24,7 +24,7 @@
|
||||
orderedList: false,
|
||||
taskList: false,
|
||||
blockquote: false,
|
||||
codeBlock: false,
|
||||
codeBlock: false
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
@@ -45,7 +45,7 @@
|
||||
orderedList: editor.isActive('orderedList'),
|
||||
taskList: editor.isActive('taskList'),
|
||||
blockquote: editor.isActive('blockquote'),
|
||||
codeBlock: editor.isActive('codeBlock'),
|
||||
codeBlock: editor.isActive('codeBlock')
|
||||
};
|
||||
};
|
||||
|
||||
@@ -72,112 +72,127 @@
|
||||
<div class="toolbar-scroll">
|
||||
<!-- Text formatting -->
|
||||
<button
|
||||
class="tb-btn" class:active={active.bold}
|
||||
class="tb-btn"
|
||||
class:active={active.bold}
|
||||
onclick={() => editor.chain().focus().toggleBold().run()}
|
||||
use:tooltip={'Bold (⌘B)'}
|
||||
><strong>B</strong></button>
|
||||
use:tooltip={'Bold (⌘B)'}><strong>B</strong></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.italic}
|
||||
class="tb-btn"
|
||||
class:active={active.italic}
|
||||
onclick={() => editor.chain().focus().toggleItalic().run()}
|
||||
use:tooltip={'Italic (⌘I)'}
|
||||
><em>I</em></button>
|
||||
use:tooltip={'Italic (⌘I)'}><em>I</em></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.underline}
|
||||
class="tb-btn"
|
||||
class:active={active.underline}
|
||||
onclick={() => editor.chain().focus().toggleUnderline().run()}
|
||||
use:tooltip={'Underline (⌘U)'}
|
||||
><u>U</u></button>
|
||||
use:tooltip={'Underline (⌘U)'}><u>U</u></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.strike}
|
||||
class="tb-btn"
|
||||
class:active={active.strike}
|
||||
onclick={() => editor.chain().focus().toggleStrike().run()}
|
||||
use:tooltip={'Strikethrough'}
|
||||
><s>S</s></button>
|
||||
use:tooltip={'Strikethrough'}><s>S</s></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.code}
|
||||
class="tb-btn"
|
||||
class:active={active.code}
|
||||
onclick={() => editor.chain().focus().toggleCode().run()}
|
||||
use:tooltip={'Inline code'}
|
||||
><Icon name="code" size={12} /></button>
|
||||
use:tooltip={'Inline code'}><Icon name="code" size={12} /></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.highlight}
|
||||
class="tb-btn"
|
||||
class:active={active.highlight}
|
||||
onclick={() => editor.chain().focus().toggleHighlight().run()}
|
||||
use:tooltip={'Highlight'}
|
||||
><span class="highlight-icon">H</span></button>
|
||||
use:tooltip={'Highlight'}><span class="highlight-icon">H</span></button
|
||||
>
|
||||
|
||||
<span class="tb-divider"></span>
|
||||
|
||||
<!-- Headings -->
|
||||
<button
|
||||
class="tb-btn heading-btn" class:active={active.h1}
|
||||
class="tb-btn heading-btn"
|
||||
class:active={active.h1}
|
||||
onclick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
use:tooltip={'Heading 1'}
|
||||
>H1</button>
|
||||
use:tooltip={'Heading 1'}>H1</button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn heading-btn" class:active={active.h2}
|
||||
class="tb-btn heading-btn"
|
||||
class:active={active.h2}
|
||||
onclick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
use:tooltip={'Heading 2'}
|
||||
>H2</button>
|
||||
use:tooltip={'Heading 2'}>H2</button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn heading-btn" class:active={active.h3}
|
||||
class="tb-btn heading-btn"
|
||||
class:active={active.h3}
|
||||
onclick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
|
||||
use:tooltip={'Heading 3'}
|
||||
>H3</button>
|
||||
use:tooltip={'Heading 3'}>H3</button
|
||||
>
|
||||
|
||||
<span class="tb-divider"></span>
|
||||
|
||||
<!-- Lists -->
|
||||
<button
|
||||
class="tb-btn" class:active={active.bulletList}
|
||||
class="tb-btn"
|
||||
class:active={active.bulletList}
|
||||
onclick={() => editor.chain().focus().toggleBulletList().run()}
|
||||
use:tooltip={'Bullet list'}
|
||||
><Icon name="list" size={12} /></button>
|
||||
use:tooltip={'Bullet list'}><Icon name="list" size={12} /></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.orderedList}
|
||||
class="tb-btn"
|
||||
class:active={active.orderedList}
|
||||
onclick={() => editor.chain().focus().toggleOrderedList().run()}
|
||||
use:tooltip={'Numbered list'}
|
||||
><Icon name="list-ordered" size={12} /></button>
|
||||
use:tooltip={'Numbered list'}><Icon name="list-ordered" size={12} /></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.taskList}
|
||||
class="tb-btn"
|
||||
class:active={active.taskList}
|
||||
onclick={() => editor.chain().focus().toggleTaskList().run()}
|
||||
use:tooltip={'Task list'}
|
||||
><Icon name="check-square" size={12} /></button>
|
||||
use:tooltip={'Task list'}><Icon name="check-square" size={12} /></button
|
||||
>
|
||||
|
||||
<span class="tb-divider"></span>
|
||||
|
||||
<!-- Block elements -->
|
||||
<button
|
||||
class="tb-btn" class:active={active.blockquote}
|
||||
class="tb-btn"
|
||||
class:active={active.blockquote}
|
||||
onclick={() => editor.chain().focus().toggleBlockquote().run()}
|
||||
use:tooltip={'Quote'}
|
||||
><Icon name="quote" size={12} /></button>
|
||||
use:tooltip={'Quote'}><Icon name="quote" size={12} /></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn" class:active={active.codeBlock}
|
||||
class="tb-btn"
|
||||
class:active={active.codeBlock}
|
||||
onclick={() => editor.chain().focus().toggleCodeBlock().run()}
|
||||
use:tooltip={'Code block'}
|
||||
>{'{ }'}</button>
|
||||
use:tooltip={'Code block'}>{'{ }'}</button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn"
|
||||
onclick={() => editor.chain().focus().setHorizontalRule().run()}
|
||||
use:tooltip={'Horizontal rule'}
|
||||
>──</button>
|
||||
use:tooltip={'Horizontal rule'}>──</button
|
||||
>
|
||||
|
||||
<span class="tb-divider"></span>
|
||||
|
||||
<!-- Table -->
|
||||
<button
|
||||
class="tb-btn"
|
||||
onclick={() => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()}
|
||||
use:tooltip={'Insert table'}
|
||||
><Icon name="table" size={12} /></button>
|
||||
onclick={() =>
|
||||
editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()}
|
||||
use:tooltip={'Insert table'}><Icon name="table" size={12} /></button
|
||||
>
|
||||
|
||||
<!-- Undo/Redo -->
|
||||
<span class="tb-divider"></span>
|
||||
@@ -186,15 +201,15 @@
|
||||
class="tb-btn"
|
||||
onclick={() => editor.chain().focus().undo().run()}
|
||||
disabled={!editor.can().undo()}
|
||||
use:tooltip={'Undo (⌘Z)'}
|
||||
><Icon name="undo" size={12} /></button>
|
||||
use:tooltip={'Undo (⌘Z)'}><Icon name="undo" size={12} /></button
|
||||
>
|
||||
|
||||
<button
|
||||
class="tb-btn"
|
||||
onclick={() => editor.chain().focus().redo().run()}
|
||||
disabled={!editor.can().redo()}
|
||||
use:tooltip={'Redo (⌘⇧Z)'}
|
||||
><Icon name="redo" size={12} /></button>
|
||||
use:tooltip={'Redo (⌘⇧Z)'}><Icon name="redo" size={12} /></button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -31,30 +31,37 @@
|
||||
{#if 'tokens' in item && item.tokens}
|
||||
<svelte:self items={item.tokens} />
|
||||
{:else}
|
||||
{decodeEntities(('text' in item) ? item.text : item.raw)}
|
||||
{decodeEntities('text' in item ? item.text : item.raw)}
|
||||
{/if}
|
||||
|
||||
{:else if item.type === 'strong'}
|
||||
<strong>{#if 'tokens' in item && item.tokens}<svelte:self items={item.tokens} />{:else}{item.raw}{/if}</strong>
|
||||
|
||||
<strong
|
||||
>{#if 'tokens' in item && item.tokens}<svelte:self
|
||||
items={item.tokens}
|
||||
/>{:else}{item.raw}{/if}</strong
|
||||
>
|
||||
{:else if item.type === 'em'}
|
||||
<em>{#if 'tokens' in item && item.tokens}<svelte:self items={item.tokens} />{:else}{item.raw}{/if}</em>
|
||||
|
||||
<em
|
||||
>{#if 'tokens' in item && item.tokens}<svelte:self
|
||||
items={item.tokens}
|
||||
/>{:else}{item.raw}{/if}</em
|
||||
>
|
||||
{:else if item.type === 'del'}
|
||||
<del>{#if 'tokens' in item && item.tokens}<svelte:self items={item.tokens} />{:else}{item.raw}{/if}</del>
|
||||
|
||||
<del
|
||||
>{#if 'tokens' in item && item.tokens}<svelte:self
|
||||
items={item.tokens}
|
||||
/>{:else}{item.raw}{/if}</del
|
||||
>
|
||||
{:else if item.type === 'codespan'}
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<code
|
||||
class="codespan cursor-pointer"
|
||||
onclick={() => {
|
||||
const text = ('text' in item) ? item.text : item.raw;
|
||||
const text = 'text' in item ? item.text : item.raw;
|
||||
navigator.clipboard.writeText(text);
|
||||
}}
|
||||
>{('text' in item) ? item.text : item.raw}</code>
|
||||
|
||||
}}>{'text' in item ? item.text : item.raw}</code
|
||||
>
|
||||
{:else if item.type === 'link'}
|
||||
{@const href = ('href' in item) ? item.href : ''}
|
||||
{@const href = 'href' in item ? item.href : ''}
|
||||
{#if href?.startsWith('file:///')}
|
||||
{@const rawPath = decodeURIComponent(href.replace('file://', ''))}
|
||||
{@const isDirectory = rawPath.endsWith('/')}
|
||||
@@ -64,15 +71,43 @@
|
||||
<button
|
||||
class="inline-flex items-center gap-1 px-1 py-px rounded text-[13px] leading-snug font-medium cursor-pointer border-none text-blue-500 dark:text-blue-400 hover:bg-blue-500/8 transition-colors align-baseline"
|
||||
title={filePath}
|
||||
onclick={(e) => { e.preventDefault(); if (isDirectory) { setFileBrowserCwd(filePath); setActiveTab('files'); } else { openFileTab(filePath); } }}
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
if (isDirectory) {
|
||||
setFileBrowserCwd(filePath);
|
||||
setActiveTab('files');
|
||||
} else {
|
||||
openFileTab(filePath);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#if isDirectory}
|
||||
<svg class="w-3.5 h-3.5 shrink-0" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M2.5 3A1.5 1.5 0 0 1 4 1.5h2.172a1.5 1.5 0 0 1 1.06.44l.768.767a1.5 1.5 0 0 0 1.06.439H12A1.5 1.5 0 0 1 13.5 4.5v8A1.5 1.5 0 0 1 12 14H4a1.5 1.5 0 0 1-1.5-1.5V3Z" />
|
||||
<svg
|
||||
class="w-3.5 h-3.5 shrink-0"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M2.5 3A1.5 1.5 0 0 1 4 1.5h2.172a1.5 1.5 0 0 1 1.06.44l.768.767a1.5 1.5 0 0 0 1.06.439H12A1.5 1.5 0 0 1 13.5 4.5v8A1.5 1.5 0 0 1 12 14H4a1.5 1.5 0 0 1-1.5-1.5V3Z"
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg class="w-3.5 h-3.5 shrink-0" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M9 1.5H4a1.5 1.5 0 0 0-1.5 1.5v10A1.5 1.5 0 0 0 4 14.5h8a1.5 1.5 0 0 0 1.5-1.5V6L9 1.5Z" />
|
||||
<svg
|
||||
class="w-3.5 h-3.5 shrink-0"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path
|
||||
d="M9 1.5H4a1.5 1.5 0 0 0-1.5 1.5v10A1.5 1.5 0 0 0 4 14.5h8a1.5 1.5 0 0 0 1.5-1.5V6L9 1.5Z"
|
||||
/>
|
||||
<path d="M9 1.5V6h4.5" />
|
||||
</svg>
|
||||
{/if}
|
||||
@@ -83,31 +118,28 @@
|
||||
{#if 'tokens' in item && item.tokens}
|
||||
<svelte:self items={item.tokens} />
|
||||
{:else}
|
||||
{('text' in item) ? item.text : item.raw}
|
||||
{'text' in item ? item.text : item.raw}
|
||||
{/if}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
{:else if item.type === 'image'}
|
||||
<img
|
||||
src={('href' in item) ? item.href : ''}
|
||||
alt={('text' in item) ? item.text : ''}
|
||||
title={('title' in item) ? item.title : undefined}
|
||||
src={'href' in item ? item.href : ''}
|
||||
alt={'text' in item ? item.text : ''}
|
||||
title={'title' in item ? item.title : undefined}
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
{:else if item.type === 'br'}
|
||||
<br />
|
||||
|
||||
{:else if item.type === 'escape'}
|
||||
{('text' in item) ? item.text : item.raw}
|
||||
|
||||
{'text' in item ? item.text : item.raw}
|
||||
{:else if item.type === 'html'}
|
||||
{@const wl = parseWikilink(item.raw)}
|
||||
{#if wl}
|
||||
<span class="text-blue-500 dark:text-blue-400 bg-blue-500/8 dark:bg-blue-400/10 rounded px-1 cursor-pointer hover:underline transition-colors" title="Link to {wl.target}">{wl.label}</span>
|
||||
<span
|
||||
class="text-blue-500 dark:text-blue-400 bg-blue-500/8 dark:bg-blue-400/10 rounded px-1 cursor-pointer hover:underline transition-colors"
|
||||
title="Link to {wl.target}">{wl.label}</span
|
||||
>
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 [&>:first-child]:mt-0 [&>:last-child]:mb-0">
|
||||
<div
|
||||
class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 [&>:first-child]:mt-0 [&>:last-child]:mb-0"
|
||||
>
|
||||
<BlockRenderer {tokens} />
|
||||
</div>
|
||||
@@ -16,7 +16,7 @@
|
||||
startOnLoad: false,
|
||||
theme: document.documentElement.classList.contains('dark') ? 'dark' : 'default',
|
||||
securityLevel: 'strict',
|
||||
fontFamily: 'inherit',
|
||||
fontFamily: 'inherit'
|
||||
});
|
||||
|
||||
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
codeBlock: false, // Use CodeBlockLowlight instead
|
||||
heading: { levels: [1, 2, 3, 4, 5, 6] },
|
||||
heading: { levels: [1, 2, 3, 4, 5, 6] }
|
||||
}),
|
||||
Markdown,
|
||||
TaskList,
|
||||
@@ -79,17 +79,17 @@
|
||||
Link.configure({
|
||||
openOnClick: false,
|
||||
autolink: true,
|
||||
linkOnPaste: true,
|
||||
linkOnPaste: true
|
||||
}),
|
||||
Placeholder.configure({
|
||||
placeholder: 'Start writing…',
|
||||
placeholder: 'Start writing…'
|
||||
}),
|
||||
Typography,
|
||||
Highlight.configure({ multicolor: false }),
|
||||
Underline,
|
||||
Superscript,
|
||||
Subscript,
|
||||
CodeBlockLowlight.configure({ lowlight }),
|
||||
CodeBlockLowlight.configure({ lowlight })
|
||||
],
|
||||
content: content,
|
||||
contentType: 'markdown',
|
||||
@@ -97,7 +97,7 @@
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: 'rte-prosemirror',
|
||||
spellcheck: 'true',
|
||||
spellcheck: 'true'
|
||||
},
|
||||
// Handle image drops: upload to same directory as .md file
|
||||
handleDrop: (view, event, _slice, moved) => {
|
||||
@@ -123,11 +123,11 @@
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}
|
||||
},
|
||||
onUpdate: () => {
|
||||
onchange?.();
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
// ⌘S / Ctrl+S save
|
||||
@@ -145,7 +145,10 @@
|
||||
editorEl.closest('.rte-container')?.classList.toggle('dark-mode', isDarkMode());
|
||||
}
|
||||
});
|
||||
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||||
themeObserver.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class']
|
||||
});
|
||||
});
|
||||
|
||||
let themeObserver: MutationObserver | null = null;
|
||||
@@ -301,22 +304,22 @@
|
||||
|
||||
/* ── Task lists ────────────────────────────────── */
|
||||
|
||||
.rte-container :global(.rte-prosemirror ul[data-type="taskList"]) {
|
||||
.rte-container :global(.rte-prosemirror ul[data-type='taskList']) {
|
||||
list-style: none;
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.rte-container :global(.rte-prosemirror ul[data-type="taskList"] li) {
|
||||
.rte-container :global(.rte-prosemirror ul[data-type='taskList'] li) {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.rte-container :global(.rte-prosemirror ul[data-type="taskList"] li label) {
|
||||
.rte-container :global(.rte-prosemirror ul[data-type='taskList'] li label) {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.rte-container :global(.rte-prosemirror ul[data-type="taskList"] li > div) {
|
||||
.rte-container :global(.rte-prosemirror ul[data-type='taskList'] li > div) {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -463,17 +466,44 @@
|
||||
|
||||
/* ── Syntax highlighting in code blocks ────────── */
|
||||
|
||||
.rte-container :global(.hljs-keyword) { color: #c678dd; }
|
||||
.rte-container :global(.hljs-string) { color: #98c379; }
|
||||
.rte-container :global(.hljs-number) { color: #d19a66; }
|
||||
.rte-container :global(.hljs-comment) { color: #5c6370; font-style: italic; }
|
||||
.rte-container :global(.hljs-function) { color: #61afef; }
|
||||
.rte-container :global(.hljs-title) { color: #61afef; }
|
||||
.rte-container :global(.hljs-built_in) { color: #e5c07b; }
|
||||
.rte-container :global(.hljs-attr) { color: #d19a66; }
|
||||
.rte-container :global(.hljs-tag) { color: #e06c75; }
|
||||
.rte-container :global(.hljs-name) { color: #e06c75; }
|
||||
.rte-container :global(.hljs-selector-class) { color: #d19a66; }
|
||||
.rte-container :global(.hljs-variable) { color: #e06c75; }
|
||||
.rte-container :global(.hljs-type) { color: #e5c07b; }
|
||||
.rte-container :global(.hljs-keyword) {
|
||||
color: #c678dd;
|
||||
}
|
||||
.rte-container :global(.hljs-string) {
|
||||
color: #98c379;
|
||||
}
|
||||
.rte-container :global(.hljs-number) {
|
||||
color: #d19a66;
|
||||
}
|
||||
.rte-container :global(.hljs-comment) {
|
||||
color: #5c6370;
|
||||
font-style: italic;
|
||||
}
|
||||
.rte-container :global(.hljs-function) {
|
||||
color: #61afef;
|
||||
}
|
||||
.rte-container :global(.hljs-title) {
|
||||
color: #61afef;
|
||||
}
|
||||
.rte-container :global(.hljs-built_in) {
|
||||
color: #e5c07b;
|
||||
}
|
||||
.rte-container :global(.hljs-attr) {
|
||||
color: #d19a66;
|
||||
}
|
||||
.rte-container :global(.hljs-tag) {
|
||||
color: #e06c75;
|
||||
}
|
||||
.rte-container :global(.hljs-name) {
|
||||
color: #e06c75;
|
||||
}
|
||||
.rte-container :global(.hljs-selector-class) {
|
||||
color: #d19a66;
|
||||
}
|
||||
.rte-container :global(.hljs-variable) {
|
||||
color: #e06c75;
|
||||
}
|
||||
.rte-container :global(.hljs-type) {
|
||||
color: #e5c07b;
|
||||
}
|
||||
</style>
|
||||
@@ -7,7 +7,7 @@
|
||||
let { content, separator = ',' }: Props = $props();
|
||||
|
||||
let parsed = $derived(() => {
|
||||
const lines = content.split('\n').filter(l => l.trim());
|
||||
const lines = content.split('\n').filter((l) => l.trim());
|
||||
if (lines.length === 0) return { headers: [], rows: [] };
|
||||
|
||||
// Simple CSV parse (handles quoted fields)
|
||||
@@ -36,7 +36,7 @@
|
||||
}
|
||||
|
||||
const headers = parseLine(lines[0]);
|
||||
const rows = lines.slice(1).map(l => parseLine(l));
|
||||
const rows = lines.slice(1).map((l) => parseLine(l));
|
||||
return { headers, rows };
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -76,16 +76,34 @@
|
||||
|
||||
<div class="zoom-toolbar">
|
||||
<button class="zoom-btn" onclick={zoomOut} aria-label="Zoom out">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="14" height="14">
|
||||
<path fill-rule="evenodd" d="M4 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10Z" clip-rule="evenodd" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
width="14"
|
||||
height="14"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M4 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="zoom-level" onclick={resetView} aria-label="Reset zoom">
|
||||
{Math.round(zoomLevel * 100)}%
|
||||
</button>
|
||||
<button class="zoom-btn" onclick={zoomIn} aria-label="Zoom in">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="14" height="14">
|
||||
<path d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
width="14"
|
||||
height="14"
|
||||
>
|
||||
<path
|
||||
d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -99,17 +117,13 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: repeating-conic-gradient(
|
||||
var(--color-gray-100) 0% 25%,
|
||||
transparent 0% 50%
|
||||
) 50% / 16px 16px;
|
||||
background: repeating-conic-gradient(var(--color-gray-100) 0% 25%, transparent 0% 50%) 50% /
|
||||
16px 16px;
|
||||
}
|
||||
|
||||
:global(.dark) .image-preview {
|
||||
background: repeating-conic-gradient(
|
||||
rgba(255, 255, 255, 0.04) 0% 25%,
|
||||
transparent 0% 50%
|
||||
) 50% / 16px 16px;
|
||||
background: repeating-conic-gradient(rgba(255, 255, 255, 0.04) 0% 25%, transparent 0% 50%) 50% /
|
||||
16px 16px;
|
||||
}
|
||||
|
||||
.image-content {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
const workbook = XLSX.read(buf, { type: 'array' });
|
||||
sheetNames = workbook.SheetNames;
|
||||
|
||||
sheetHtmls = workbook.SheetNames.map(name => {
|
||||
sheetHtmls = workbook.SheetNames.map((name) => {
|
||||
const sheet = workbook.Sheets[name];
|
||||
const rows: unknown[][] = XLSX.utils.sheet_to_json(sheet, { header: 1, defval: '' });
|
||||
if (rows.length === 0) return '<p>Empty sheet</p>';
|
||||
@@ -67,7 +67,10 @@
|
||||
const colLetter = (i: number) => {
|
||||
let s = '';
|
||||
let n = i;
|
||||
while (n >= 0) { s = String.fromCharCode(65 + (n % 26)) + s; n = Math.floor(n / 26) - 1; }
|
||||
while (n >= 0) {
|
||||
s = String.fromCharCode(65 + (n % 26)) + s;
|
||||
n = Math.floor(n / 26) - 1;
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
@@ -98,7 +101,8 @@
|
||||
const zip = await JSZip.loadAsync(buf);
|
||||
|
||||
// Slide dimensions
|
||||
let slideW = 960, slideH = 540;
|
||||
let slideW = 960,
|
||||
slideH = 540;
|
||||
const presXml = zip.file('ppt/presentation.xml');
|
||||
if (presXml) {
|
||||
const presText = await presXml.async('text');
|
||||
@@ -113,20 +117,25 @@
|
||||
|
||||
// Collect media
|
||||
const media: Record<string, string> = {};
|
||||
const mediaFiles = Object.keys(zip.files).filter(f => f.startsWith('ppt/media/'));
|
||||
await Promise.all(mediaFiles.map(async path => {
|
||||
const file = zip.file(path);
|
||||
if (!file) return;
|
||||
const b64 = await file.async('base64');
|
||||
const ext = path.split('.').pop()?.toLowerCase() ?? '';
|
||||
const mime = ext === 'png' ? 'image/png' : ext === 'gif' ? 'image/gif' : 'image/jpeg';
|
||||
media[path] = `data:${mime};base64,${b64}`;
|
||||
}));
|
||||
const mediaFiles = Object.keys(zip.files).filter((f) => f.startsWith('ppt/media/'));
|
||||
await Promise.all(
|
||||
mediaFiles.map(async (path) => {
|
||||
const file = zip.file(path);
|
||||
if (!file) return;
|
||||
const b64 = await file.async('base64');
|
||||
const ext = path.split('.').pop()?.toLowerCase() ?? '';
|
||||
const mime = ext === 'png' ? 'image/png' : ext === 'gif' ? 'image/gif' : 'image/jpeg';
|
||||
media[path] = `data:${mime};base64,${b64}`;
|
||||
})
|
||||
);
|
||||
|
||||
// Discover slides
|
||||
const slideFiles = Object.keys(zip.files)
|
||||
.filter(f => /^ppt\/slides\/slide\d+\.xml$/.test(f))
|
||||
.sort((a, b) => parseInt(a.match(/slide(\d+)/)?.[1] ?? '0') - parseInt(b.match(/slide(\d+)/)?.[1] ?? '0'));
|
||||
.filter((f) => /^ppt\/slides\/slide\d+\.xml$/.test(f))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
parseInt(a.match(/slide(\d+)/)?.[1] ?? '0') - parseInt(b.match(/slide(\d+)/)?.[1] ?? '0')
|
||||
);
|
||||
|
||||
const images: string[] = [];
|
||||
|
||||
@@ -139,7 +148,10 @@
|
||||
const rels: Record<string, string> = {};
|
||||
const relsFile = zip.file(relsPath);
|
||||
if (relsFile) {
|
||||
const relsDoc = new DOMParser().parseFromString(await relsFile.async('text'), 'application/xml');
|
||||
const relsDoc = new DOMParser().parseFromString(
|
||||
await relsFile.async('text'),
|
||||
'application/xml'
|
||||
);
|
||||
const relEls = relsDoc.getElementsByTagName('Relationship');
|
||||
for (let i = 0; i < relEls.length; i++) {
|
||||
const id = relEls[i].getAttribute('Id') ?? '';
|
||||
@@ -157,7 +169,10 @@
|
||||
|
||||
const spTree = slideDoc.getElementsByTagName('p:spTree')[0];
|
||||
if (spTree) {
|
||||
const shapes = [...Array.from(spTree.getElementsByTagName('p:sp')), ...Array.from(spTree.getElementsByTagName('p:pic'))];
|
||||
const shapes = [
|
||||
...Array.from(spTree.getElementsByTagName('p:sp')),
|
||||
...Array.from(spTree.getElementsByTagName('p:pic'))
|
||||
];
|
||||
|
||||
for (const shape of shapes) {
|
||||
const xfrm = shape.getElementsByTagName('a:xfrm')[0];
|
||||
@@ -203,7 +218,10 @@
|
||||
|
||||
for (let pi = 0; pi < paragraphs.length; pi++) {
|
||||
const runs = paragraphs[pi].getElementsByTagName('a:r');
|
||||
if (runs.length === 0) { cursorY += 18; continue; }
|
||||
if (runs.length === 0) {
|
||||
cursorY += 18;
|
||||
continue;
|
||||
}
|
||||
|
||||
let maxPt = 12;
|
||||
for (let ri = 0; ri < runs.length; ri++) {
|
||||
@@ -221,7 +239,10 @@
|
||||
const text = run.getElementsByTagName('a:t')[0]?.textContent ?? '';
|
||||
if (!text) continue;
|
||||
|
||||
let fontPt = 12, bold = false, italic = false, color = '#000000';
|
||||
let fontPt = 12,
|
||||
bold = false,
|
||||
italic = false,
|
||||
color = '#000000';
|
||||
if (rPr) {
|
||||
if (rPr.getAttribute('b') === '1') bold = true;
|
||||
if (rPr.getAttribute('i') === '1') italic = true;
|
||||
@@ -268,7 +289,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
onMount(() => { loadFile(); });
|
||||
onMount(() => {
|
||||
loadFile();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="office-view">
|
||||
@@ -283,9 +306,12 @@
|
||||
<div class="sheet-tabs">
|
||||
{#each sheetNames as name, i}
|
||||
<button
|
||||
class="sheet-tab" class:active={activeSheet === i}
|
||||
onclick={() => { activeSheet = i; }}
|
||||
>{name}</button>
|
||||
class="sheet-tab"
|
||||
class:active={activeSheet === i}
|
||||
onclick={() => {
|
||||
activeSheet = i;
|
||||
}}>{name}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -334,7 +360,9 @@
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── DOCX ────────────────────────────────────── */
|
||||
@@ -352,13 +380,38 @@
|
||||
color: var(--color-gray-200);
|
||||
}
|
||||
|
||||
.docx-content :global(h1) { font-size: 24px; font-weight: 600; margin: 0 0 8px; }
|
||||
.docx-content :global(h2) { font-size: 20px; font-weight: 600; margin: 24px 0 8px; }
|
||||
.docx-content :global(h3) { font-size: 16px; font-weight: 600; margin: 20px 0 6px; }
|
||||
.docx-content :global(p) { margin: 0 0 12px; }
|
||||
.docx-content :global(table) { border-collapse: collapse; margin: 12px 0; font-size: 13px; }
|
||||
.docx-content :global(td), .docx-content :global(th) { border: 1px solid var(--color-gray-200); padding: 4px 8px; }
|
||||
.docx-content :global(img) { max-width: 100%; height: auto; }
|
||||
.docx-content :global(h1) {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.docx-content :global(h2) {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin: 24px 0 8px;
|
||||
}
|
||||
.docx-content :global(h3) {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 6px;
|
||||
}
|
||||
.docx-content :global(p) {
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.docx-content :global(table) {
|
||||
border-collapse: collapse;
|
||||
margin: 12px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.docx-content :global(td),
|
||||
.docx-content :global(th) {
|
||||
border: 1px solid var(--color-gray-200);
|
||||
padding: 4px 8px;
|
||||
}
|
||||
.docx-content :global(img) {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* ── XLSX ────────────────────────────────────── */
|
||||
|
||||
@@ -408,7 +461,11 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.xlsx-content :global(thead) { position: sticky; top: 0; z-index: 2; }
|
||||
.xlsx-content :global(thead) {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.xlsx-content :global(th) {
|
||||
background: var(--color-gray-50);
|
||||
@@ -455,8 +512,13 @@
|
||||
color: var(--color-gray-600);
|
||||
}
|
||||
|
||||
.xlsx-content :global(.num) { text-align: right; color: #d97706; }
|
||||
:global(.dark) .xlsx-content :global(.num) { color: #fbbf24; }
|
||||
.xlsx-content :global(.num) {
|
||||
text-align: right;
|
||||
color: #d97706;
|
||||
}
|
||||
:global(.dark) .xlsx-content :global(.num) {
|
||||
color: #fbbf24;
|
||||
}
|
||||
|
||||
/* ── PPTX ────────────────────────────────────── */
|
||||
|
||||
|
||||
@@ -153,7 +153,9 @@
|
||||
|
||||
function cancelTextLayers() {
|
||||
for (const tl of textLayers) {
|
||||
try { tl.cancel(); } catch {}
|
||||
try {
|
||||
tl.cancel();
|
||||
} catch {}
|
||||
}
|
||||
textLayers = [];
|
||||
}
|
||||
@@ -238,16 +240,34 @@
|
||||
{#if !loading && !error && pdfDoc}
|
||||
<div class="zoom-toolbar">
|
||||
<button class="zoom-btn" onclick={zoomOut} aria-label="Zoom out">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="14" height="14">
|
||||
<path fill-rule="evenodd" d="M4 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10Z" clip-rule="evenodd" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
width="14"
|
||||
height="14"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M4 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="zoom-level" onclick={resetView} aria-label="Reset zoom">
|
||||
{Math.round(zoomLevel * 100)}%
|
||||
</button>
|
||||
<button class="zoom-btn" onclick={zoomIn} aria-label="Zoom in">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="14" height="14">
|
||||
<path d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
width="14"
|
||||
height="14"
|
||||
>
|
||||
<path
|
||||
d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -297,7 +317,9 @@
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.zoom-toolbar {
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
// Get total row count
|
||||
try {
|
||||
const countResult = db.exec(`SELECT COUNT(*) FROM "${name}"`);
|
||||
totalRows = countResult[0]?.values[0]?.[0] as number ?? 0;
|
||||
totalRows = (countResult[0]?.values[0]?.[0] as number) ?? 0;
|
||||
} catch {
|
||||
totalRows = 0;
|
||||
}
|
||||
@@ -133,7 +133,9 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
onMount(() => { loadDb(); });
|
||||
onMount(() => {
|
||||
loadDb();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (db) {
|
||||
@@ -154,15 +156,19 @@
|
||||
<div class="tabs">
|
||||
{#each tables as table}
|
||||
<button
|
||||
class="tab" class:active={activeTable === table && !queryMode}
|
||||
onclick={() => selectTable(table)}
|
||||
>{table}</button>
|
||||
class="tab"
|
||||
class:active={activeTable === table && !queryMode}
|
||||
onclick={() => selectTable(table)}>{table}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
<button
|
||||
class="tab query-tab" class:active={queryMode}
|
||||
onclick={() => { queryMode = true; }}
|
||||
>SQL</button>
|
||||
class="tab query-tab"
|
||||
class:active={queryMode}
|
||||
onclick={() => {
|
||||
queryMode = true;
|
||||
}}>SQL</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- Query input -->
|
||||
@@ -173,7 +179,9 @@
|
||||
bind:value={customQuery}
|
||||
placeholder="SELECT * FROM ..."
|
||||
rows="2"
|
||||
onkeydown={(e) => { if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') runQuery(); }}
|
||||
onkeydown={(e) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') runQuery();
|
||||
}}
|
||||
></textarea>
|
||||
<button class="run-btn" onclick={runQuery}>Run ⌘↵</button>
|
||||
</div>
|
||||
@@ -214,7 +222,9 @@
|
||||
<span class="page-info">
|
||||
{page * PAGE_SIZE + 1}–{Math.min((page + 1) * PAGE_SIZE, totalRows)} of {totalRows}
|
||||
</span>
|
||||
<button class="page-btn" onclick={nextPage} disabled={(page + 1) * PAGE_SIZE >= totalRows}>Next →</button>
|
||||
<button class="page-btn" onclick={nextPage} disabled={(page + 1) * PAGE_SIZE >= totalRows}
|
||||
>Next →</button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -252,7 +262,9 @@
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Tab bar ──────────────────────────────────── */
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
let pzInstance: PanZoom | null = null;
|
||||
let zoomLevel = $state(1);
|
||||
|
||||
let sanitizedSvg = $derived(DOMPurify.sanitize(content, { USE_PROFILES: { svg: true, svgFilters: true } }));
|
||||
let sanitizedSvg = $derived(
|
||||
DOMPurify.sanitize(content, { USE_PROFILES: { svg: true, svgFilters: true } })
|
||||
);
|
||||
|
||||
function initPanzoom() {
|
||||
if (!contentEl) return;
|
||||
@@ -70,15 +72,21 @@
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<button
|
||||
class="toolbar-btn" class:active={mode === 'visual'}
|
||||
onclick={() => { mode = 'visual'; }}
|
||||
use:tooltip={'Visual'}
|
||||
><Icon name="eye" size={14} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={mode === 'visual'}
|
||||
onclick={() => {
|
||||
mode = 'visual';
|
||||
}}
|
||||
use:tooltip={'Visual'}><Icon name="eye" size={14} /></button
|
||||
>
|
||||
<button
|
||||
class="toolbar-btn" class:active={mode === 'source'}
|
||||
onclick={() => { mode = 'source'; }}
|
||||
use:tooltip={'Source'}
|
||||
><Icon name="code" size={14} /></button>
|
||||
class="toolbar-btn"
|
||||
class:active={mode === 'source'}
|
||||
onclick={() => {
|
||||
mode = 'source';
|
||||
}}
|
||||
use:tooltip={'Source'}><Icon name="code" size={14} /></button
|
||||
>
|
||||
{#if mode === 'visual'}
|
||||
<button class="toolbar-btn" onclick={resetView} use:tooltip={'Reset zoom'}>
|
||||
<span class="zoom-text">{Math.round(zoomLevel * 100)}%</span>
|
||||
@@ -184,17 +192,13 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: repeating-conic-gradient(
|
||||
var(--color-gray-100) 0% 25%,
|
||||
transparent 0% 50%
|
||||
) 50% / 16px 16px;
|
||||
background: repeating-conic-gradient(var(--color-gray-100) 0% 25%, transparent 0% 50%) 50% /
|
||||
16px 16px;
|
||||
}
|
||||
|
||||
:global(.dark) .visual-container {
|
||||
background: repeating-conic-gradient(
|
||||
rgba(255, 255, 255, 0.04) 0% 25%,
|
||||
transparent 0% 50%
|
||||
) 50% / 16px 16px;
|
||||
background: repeating-conic-gradient(rgba(255, 255, 255, 0.04) 0% 25%, transparent 0% 50%) 50% /
|
||||
16px 16px;
|
||||
}
|
||||
|
||||
.visual-content {
|
||||
|
||||
@@ -30,7 +30,7 @@ export const supportedLocales = [
|
||||
{ code: 'ja', label: '日本語' },
|
||||
{ code: 'ko', label: '한국어' },
|
||||
{ code: 'zh-CN', label: '简体中文' },
|
||||
{ code: 'zh-TW', label: '繁體中文' },
|
||||
{ code: 'zh-TW', label: '繁體中文' }
|
||||
] as const;
|
||||
|
||||
const resources: Record<string, { translation: Record<string, string> }> = {
|
||||
@@ -43,20 +43,20 @@ const resources: Record<string, { translation: Record<string, string> }> = {
|
||||
'pt-BR': { translation: ptBR },
|
||||
ru: { translation: ru },
|
||||
'zh-CN': { translation: zhCN },
|
||||
'zh-TW': { translation: zhTW },
|
||||
'zh-TW': { translation: zhTW }
|
||||
};
|
||||
|
||||
i18next.use(LanguageDetector).init({
|
||||
resources,
|
||||
fallbackLng: 'en',
|
||||
interpolation: {
|
||||
escapeValue: false, // Svelte handles escaping
|
||||
escapeValue: false // Svelte handles escaping
|
||||
},
|
||||
detection: {
|
||||
order: ['localStorage', 'navigator'],
|
||||
caches: ['localStorage'],
|
||||
lookupLocalStorage: 'cptr_locale',
|
||||
},
|
||||
lookupLocalStorage: 'cptr_locale'
|
||||
}
|
||||
});
|
||||
|
||||
// ── Svelte store wrapper ────────────────────────────────────────
|
||||
|
||||
+102
-82
@@ -22,7 +22,7 @@ import {
|
||||
savePreferences,
|
||||
getWorkspaceList,
|
||||
getWorkspaceState,
|
||||
saveWorkspaceState,
|
||||
saveWorkspaceState
|
||||
} from '$lib/apis/state';
|
||||
import { listSessions, createSession, deleteSession } from '$lib/apis/terminal';
|
||||
import { changeLocale, i18next } from '$lib/i18n';
|
||||
@@ -36,7 +36,7 @@ export interface Tab {
|
||||
type: 'files' | 'terminal' | 'file' | 'git' | 'chat' | 'preview';
|
||||
label: string;
|
||||
filePath?: string;
|
||||
path?: string; // generic path (e.g. for chat)
|
||||
path?: string; // generic path (e.g. for chat)
|
||||
sessionId?: string;
|
||||
port?: number;
|
||||
unsaved?: boolean;
|
||||
@@ -91,7 +91,7 @@ function createDefaultGroup(): EditorGroup {
|
||||
return {
|
||||
id: 'default',
|
||||
tabs: [{ id: 'files', type: 'files', label: 'Files', permanent: true }],
|
||||
activeTabId: 'files',
|
||||
activeTabId: 'files'
|
||||
};
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ function createDefaultWorkspace(path: string): WorkspaceState {
|
||||
activeGroupId: 'default',
|
||||
splitDirection: 'horizontal',
|
||||
splitRatio: 0.5,
|
||||
fileBrowserCwd: path,
|
||||
fileBrowserCwd: path
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +117,9 @@ export const currentWorkspace = writable<WorkspaceState | null>(null);
|
||||
export const workspaceList = writable<{ path: string; name: string }[]>([]);
|
||||
|
||||
/** Global user preferences. */
|
||||
export const sidebarOpen = writable(typeof window !== 'undefined' ? window.innerWidth >= 768 : false);
|
||||
export const sidebarOpen = writable(
|
||||
typeof window !== 'undefined' ? window.innerWidth >= 768 : false
|
||||
);
|
||||
export const sidebarWidth = writable(220);
|
||||
export const theme = writable<Theme>('dark');
|
||||
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
|
||||
@@ -128,7 +130,8 @@ export const showChangelog = writable(false);
|
||||
export const autoApproveTools = {
|
||||
subscribe: toolApprovalMode.subscribe,
|
||||
set: (v: boolean) => toolApprovalMode.set(v ? 'full' : 'ask'),
|
||||
update: (fn: (v: boolean) => boolean) => toolApprovalMode.update((m) => fn(m === 'full') ? 'full' : 'ask'),
|
||||
update: (fn: (v: boolean) => boolean) =>
|
||||
toolApprovalMode.update((m) => (fn(m === 'full') ? 'full' : 'ask'))
|
||||
};
|
||||
export const stateLoaded = writable(false);
|
||||
export const gitReviewOpen = writable(false);
|
||||
@@ -145,16 +148,14 @@ export const workspaceOrder = writable<string[]>([]);
|
||||
export const activeWorkspace = currentWorkspace;
|
||||
|
||||
export const activeGroup = derived(currentWorkspace, ($ws) =>
|
||||
$ws ? $ws.groups.find((g) => g.id === $ws.activeGroupId) ?? $ws.groups[0] ?? null : null
|
||||
$ws ? ($ws.groups.find((g) => g.id === $ws.activeGroupId) ?? $ws.groups[0] ?? null) : null
|
||||
);
|
||||
|
||||
export const activeTab = derived(activeGroup, ($g) =>
|
||||
$g ? $g.tabs.find((t) => t.id === $g.activeTabId) ?? null : null
|
||||
$g ? ($g.tabs.find((t) => t.id === $g.activeTabId) ?? null) : null
|
||||
);
|
||||
|
||||
export const splitActive = derived(currentWorkspace, ($ws) =>
|
||||
($ws?.groups.length ?? 0) > 1
|
||||
);
|
||||
export const splitActive = derived(currentWorkspace, ($ws) => ($ws?.groups.length ?? 0) > 1);
|
||||
|
||||
// ── Compat aliases for old split-pane API ──────────────────────
|
||||
|
||||
@@ -197,7 +198,7 @@ export function openTabInSplit(tabId: string, direction?: SplitDirection): void
|
||||
const newGroup: EditorGroup = {
|
||||
id: nextId(),
|
||||
tabs: [newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
};
|
||||
|
||||
currentWorkspace.update((ws) => {
|
||||
@@ -207,7 +208,7 @@ export function openTabInSplit(tabId: string, direction?: SplitDirection): void
|
||||
groups: [...ws.groups, newGroup],
|
||||
activeGroupId: newGroup.id,
|
||||
splitDirection: dir,
|
||||
splitRatio: ws.splitRatio ?? 0.5,
|
||||
splitRatio: ws.splitRatio ?? 0.5
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -268,7 +269,7 @@ function persistPreferences(): void {
|
||||
locale: i18next.language,
|
||||
workspaceOrder: get(workspaceOrder),
|
||||
keybindings: get(keybindings),
|
||||
version: get(lastSeenVersion),
|
||||
version: get(lastSeenVersion)
|
||||
};
|
||||
savePreferences(prefs as unknown as Record<string, unknown>).catch(() => {});
|
||||
}, 300);
|
||||
@@ -278,15 +279,33 @@ let _subscribed = false;
|
||||
function subscribeForPersistence() {
|
||||
if (_subscribed) return;
|
||||
_subscribed = true;
|
||||
currentWorkspace.subscribe(() => { if (get(stateLoaded)) persistWorkspace(); });
|
||||
theme.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
sidebarOpen.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
sidebarWidth.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
toolApprovalMode.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
workspaceOrder.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
keybindings.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
lastSeenVersion.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
|
||||
i18next.on('languageChanged', () => { if (get(stateLoaded)) persistPreferences(); });
|
||||
currentWorkspace.subscribe(() => {
|
||||
if (get(stateLoaded)) persistWorkspace();
|
||||
});
|
||||
theme.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
sidebarOpen.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
sidebarWidth.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
toolApprovalMode.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
workspaceOrder.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
keybindings.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
lastSeenVersion.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
i18next.on('languageChanged', () => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
}
|
||||
|
||||
// ── Load preferences (called once at app startup) ───────────────
|
||||
@@ -347,25 +366,27 @@ export async function loadWorkspace(path: string): Promise<void> {
|
||||
const ws = wsData as unknown as WorkspaceState;
|
||||
|
||||
// Remove dead terminal tabs from all groups
|
||||
const cleanedGroups = ws.groups.map((g) => {
|
||||
const filteredTabs = g.tabs.filter((t: Tab) => {
|
||||
if (t.type === 'terminal' && t.sessionId && !aliveSessions.has(t.sessionId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const activeStillExists = filteredTabs.some((t: Tab) => t.id === g.activeTabId);
|
||||
return {
|
||||
...g,
|
||||
tabs: filteredTabs,
|
||||
activeTabId: activeStillExists ? g.activeTabId : (filteredTabs[0]?.id ?? 'files'),
|
||||
};
|
||||
}).filter((g) => g.tabs.length > 0);
|
||||
const cleanedGroups = ws.groups
|
||||
.map((g) => {
|
||||
const filteredTabs = g.tabs.filter((t: Tab) => {
|
||||
if (t.type === 'terminal' && t.sessionId && !aliveSessions.has(t.sessionId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const activeStillExists = filteredTabs.some((t: Tab) => t.id === g.activeTabId);
|
||||
return {
|
||||
...g,
|
||||
tabs: filteredTabs,
|
||||
activeTabId: activeStillExists ? g.activeTabId : (filteredTabs[0]?.id ?? 'files')
|
||||
};
|
||||
})
|
||||
.filter((g) => g.tabs.length > 0);
|
||||
|
||||
const groups = cleanedGroups.length > 0 ? cleanedGroups : [createDefaultGroup()];
|
||||
const activeGroupId = groups.some((g) => g.id === ws.activeGroupId)
|
||||
? ws.activeGroupId
|
||||
: groups[0]?.id ?? 'default';
|
||||
: (groups[0]?.id ?? 'default');
|
||||
|
||||
currentWorkspace.set({
|
||||
...ws,
|
||||
@@ -374,7 +395,7 @@ export async function loadWorkspace(path: string): Promise<void> {
|
||||
activeGroupId,
|
||||
splitDirection: ws.splitDirection ?? 'horizontal',
|
||||
splitRatio: ws.splitRatio ?? 0.5,
|
||||
fileBrowserCwd: ws.fileBrowserCwd ?? path,
|
||||
fileBrowserCwd: ws.fileBrowserCwd ?? path
|
||||
});
|
||||
} else {
|
||||
// First time opening this workspace, create defaults
|
||||
@@ -480,7 +501,10 @@ export function updateWorkspace(partial: Partial<WorkspaceState>): void {
|
||||
|
||||
function updateGroupTabs(
|
||||
groupId: string | undefined,
|
||||
fn: (tabs: Tab[], group: EditorGroup) => { tabs: Tab[]; activeTabId?: string; tabHistory?: string[] }
|
||||
fn: (
|
||||
tabs: Tab[],
|
||||
group: EditorGroup
|
||||
) => { tabs: Tab[]; activeTabId?: string; tabHistory?: string[] }
|
||||
): void {
|
||||
currentWorkspace.update((ws) => {
|
||||
if (!ws) return ws;
|
||||
@@ -491,12 +515,11 @@ function updateGroupTabs(
|
||||
if (g.id !== gid) return g;
|
||||
const result = fn(g.tabs, g);
|
||||
const newActiveId = result.activeTabId ?? g.activeTabId;
|
||||
const tabHistory = result.tabHistory
|
||||
?? (newActiveId !== g.activeTabId
|
||||
? pushTabHistory(g, g.activeTabId)
|
||||
: g.tabHistory);
|
||||
const tabHistory =
|
||||
result.tabHistory ??
|
||||
(newActiveId !== g.activeTabId ? pushTabHistory(g, g.activeTabId) : g.tabHistory);
|
||||
return { ...g, tabs: result.tabs, activeTabId: newActiveId, tabHistory };
|
||||
}),
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -532,12 +555,12 @@ export function openFileTab(filePath: string, targetGroupId?: string): void {
|
||||
id: nextId(),
|
||||
type: 'file',
|
||||
label: name,
|
||||
filePath,
|
||||
filePath
|
||||
};
|
||||
|
||||
updateGroupTabs(gid, (tabs) => ({
|
||||
tabs: [...tabs, newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -560,12 +583,12 @@ export function openUntitledFileTab(targetGroupId?: string): void {
|
||||
type: 'file',
|
||||
label,
|
||||
filePath: `untitled:${label}`,
|
||||
unsaved: true,
|
||||
unsaved: true
|
||||
};
|
||||
|
||||
updateGroupTabs(targetGroupId, (tabs) => ({
|
||||
tabs: [...tabs, newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -580,12 +603,12 @@ export async function openTerminalTab(targetGroupId?: string): Promise<void> {
|
||||
id: nextId(),
|
||||
type: 'terminal',
|
||||
label: 'Terminal',
|
||||
sessionId: data.session_id,
|
||||
sessionId: data.session_id
|
||||
};
|
||||
|
||||
updateGroupTabs(targetGroupId, (tabs) => ({
|
||||
tabs: [...tabs, newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error('Failed to create terminal:', e);
|
||||
@@ -611,12 +634,12 @@ export function openPreviewTab(port: number, targetGroupId?: string): void {
|
||||
id: nextId(),
|
||||
type: 'preview',
|
||||
label: `localhost:${port}`,
|
||||
port,
|
||||
port
|
||||
};
|
||||
|
||||
updateGroupTabs(gid, (tabs) => ({
|
||||
tabs: [...tabs, newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -641,12 +664,12 @@ export function openChatTab(chatId?: string, targetGroupId?: string): void {
|
||||
id: nextId(),
|
||||
type: 'chat',
|
||||
label: 'New Chat',
|
||||
path: chatId || `new-${Date.now()}`,
|
||||
path: chatId || `new-${Date.now()}`
|
||||
};
|
||||
|
||||
updateGroupTabs(gid, (tabs) => ({
|
||||
tabs: [...tabs, newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -655,7 +678,8 @@ export function closeTab(tabId: string, groupId?: string): void {
|
||||
if (!ws) return;
|
||||
|
||||
// Find the group containing this tab
|
||||
const gid = groupId ?? ws.groups.find((g) => g.tabs.some((t) => t.id === tabId))?.id ?? ws.activeGroupId;
|
||||
const gid =
|
||||
groupId ?? ws.groups.find((g) => g.tabs.some((t) => t.id === tabId))?.id ?? ws.activeGroupId;
|
||||
const group = ws.groups.find((g) => g.id === gid);
|
||||
if (!group) return;
|
||||
|
||||
@@ -668,7 +692,11 @@ export function closeTab(tabId: string, groupId?: string): void {
|
||||
|
||||
// Clean up streaming indicator for closed chat tabs
|
||||
if (tab.type === 'chat') {
|
||||
streamingChatTabs.update((s) => { const n = new Set(s); n.delete(tabId); return n; });
|
||||
streamingChatTabs.update((s) => {
|
||||
const n = new Set(s);
|
||||
n.delete(tabId);
|
||||
return n;
|
||||
});
|
||||
}
|
||||
|
||||
currentWorkspace.update((ws) => {
|
||||
@@ -712,7 +740,7 @@ export function closeTab(tabId: string, groupId?: string): void {
|
||||
return {
|
||||
...ws,
|
||||
groups: newGroups,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -730,23 +758,19 @@ export function setActiveTab(tabId: string, groupId?: string): void {
|
||||
return {
|
||||
...g,
|
||||
activeTabId: tabId,
|
||||
tabHistory: pushTabHistory(g, g.activeTabId),
|
||||
tabHistory: pushTabHistory(g, g.activeTabId)
|
||||
};
|
||||
}),
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function setActiveGroup(groupId: string): void {
|
||||
currentWorkspace.update((ws) =>
|
||||
ws ? { ...ws, activeGroupId: groupId } : ws
|
||||
);
|
||||
currentWorkspace.update((ws) => (ws ? { ...ws, activeGroupId: groupId } : ws));
|
||||
}
|
||||
|
||||
export function setFileBrowserCwd(cwd: string): void {
|
||||
currentWorkspace.update((ws) =>
|
||||
ws ? { ...ws, fileBrowserCwd: cwd } : ws
|
||||
);
|
||||
currentWorkspace.update((ws) => (ws ? { ...ws, fileBrowserCwd: cwd } : ws));
|
||||
}
|
||||
|
||||
export function markTabUnsaved(tabId: string, unsaved: boolean): void {
|
||||
@@ -756,8 +780,8 @@ export function markTabUnsaved(tabId: string, unsaved: boolean): void {
|
||||
...ws,
|
||||
groups: ws.groups.map((g) => ({
|
||||
...g,
|
||||
tabs: g.tabs.map((t) => (t.id === tabId ? { ...t, unsaved } : t)),
|
||||
})),
|
||||
tabs: g.tabs.map((t) => (t.id === tabId ? { ...t, unsaved } : t))
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -772,8 +796,8 @@ export function updateTabFilePath(tabId: string, newPath: string): void {
|
||||
...g,
|
||||
tabs: g.tabs.map((t) =>
|
||||
t.id === tabId ? { ...t, filePath: newPath, label: name, unsaved: false } : t
|
||||
),
|
||||
})),
|
||||
)
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -802,7 +826,7 @@ export function openInSplit(filePath: string, direction?: SplitDirection): void
|
||||
const newGroup: EditorGroup = {
|
||||
id: nextId(),
|
||||
tabs: [newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
};
|
||||
|
||||
currentWorkspace.update((ws) => {
|
||||
@@ -812,7 +836,7 @@ export function openInSplit(filePath: string, direction?: SplitDirection): void
|
||||
groups: [...ws.groups, newGroup],
|
||||
activeGroupId: newGroup.id,
|
||||
splitDirection: dir,
|
||||
splitRatio: ws.splitRatio ?? 0.5,
|
||||
splitRatio: ws.splitRatio ?? 0.5
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -842,7 +866,7 @@ export function splitCurrentTab(direction?: SplitDirection): void {
|
||||
const newGroup: EditorGroup = {
|
||||
id: nextId(),
|
||||
tabs: [newTab],
|
||||
activeTabId: newTab.id,
|
||||
activeTabId: newTab.id
|
||||
};
|
||||
|
||||
currentWorkspace.update((ws) => {
|
||||
@@ -852,7 +876,7 @@ export function splitCurrentTab(direction?: SplitDirection): void {
|
||||
groups: [...ws.groups, newGroup],
|
||||
activeGroupId: newGroup.id,
|
||||
splitDirection: dir,
|
||||
splitRatio: ws.splitRatio ?? 0.5,
|
||||
splitRatio: ws.splitRatio ?? 0.5
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -878,7 +902,7 @@ export function closeGroup(groupId: string): void {
|
||||
return {
|
||||
...ws,
|
||||
groups: newGroups,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -895,9 +919,7 @@ export function moveTabToGroup(tabId: string, fromGroupId: string, toGroupId: st
|
||||
let newGroups = ws.groups.map((g) => {
|
||||
if (g.id === fromGroupId) {
|
||||
const newTabs = g.tabs.filter((t) => t.id !== tabId);
|
||||
const newActiveId = g.activeTabId === tabId
|
||||
? (newTabs[0]?.id ?? 'files')
|
||||
: g.activeTabId;
|
||||
const newActiveId = g.activeTabId === tabId ? (newTabs[0]?.id ?? 'files') : g.activeTabId;
|
||||
return { ...g, tabs: newTabs, activeTabId: newActiveId };
|
||||
}
|
||||
if (g.id === toGroupId) {
|
||||
@@ -914,15 +936,13 @@ export function moveTabToGroup(tabId: string, fromGroupId: string, toGroupId: st
|
||||
return {
|
||||
...ws,
|
||||
groups: newGroups,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id,
|
||||
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function setSplitDirection(direction: SplitDirection): void {
|
||||
currentWorkspace.update((ws) =>
|
||||
ws ? { ...ws, splitDirection: direction } : ws
|
||||
);
|
||||
currentWorkspace.update((ws) => (ws ? { ...ws, splitDirection: direction } : ws));
|
||||
}
|
||||
|
||||
export function setSplitRatio(ratio: number): void {
|
||||
|
||||
@@ -36,7 +36,10 @@ export function bindGlobalChatListener() {
|
||||
|
||||
const tryBind = () => {
|
||||
const socket = socketStore.getSocket();
|
||||
if (!socket) { setTimeout(tryBind, 200); return; }
|
||||
if (!socket) {
|
||||
setTimeout(tryBind, 200);
|
||||
return;
|
||||
}
|
||||
|
||||
socket.on('events:chat', (data: { chat_id: string; done?: boolean }) => {
|
||||
if (!data.done) return;
|
||||
@@ -67,7 +70,9 @@ export const defaultModel = writable<string | null>(null);
|
||||
|
||||
export async function refreshChatState() {
|
||||
try {
|
||||
const data = await fetchJSON<{ models: ChatModel[]; default: string | null }>('/api/chats/models');
|
||||
const data = await fetchJSON<{ models: ChatModel[]; default: string | null }>(
|
||||
'/api/chats/models'
|
||||
);
|
||||
chatModels.set(data.models);
|
||||
defaultModel.set(data.default);
|
||||
chatEnabled.set(data.models.length > 0);
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
splitActive,
|
||||
splitCurrentTab,
|
||||
closeGroup,
|
||||
sidebarOpen,
|
||||
sidebarOpen
|
||||
} from '$lib/stores';
|
||||
import { openChatTab } from '$lib/stores';
|
||||
|
||||
@@ -37,7 +37,7 @@ export const ACTION_IDS = [
|
||||
'quickOpen',
|
||||
'openSettings',
|
||||
'toggleSplit',
|
||||
'toggleSidebar',
|
||||
'toggleSidebar'
|
||||
] as const;
|
||||
|
||||
export type ActionId = (typeof ACTION_IDS)[number];
|
||||
@@ -54,7 +54,7 @@ export const ACTION_LABELS: Record<ActionId, string> = {
|
||||
quickOpen: 'Quick Open',
|
||||
openSettings: 'Open Settings',
|
||||
toggleSplit: 'Toggle Split',
|
||||
toggleSidebar: 'Toggle Sidebar',
|
||||
toggleSidebar: 'Toggle Sidebar'
|
||||
};
|
||||
|
||||
// ── Default bindings (browser-safe) ─────────────────────────────
|
||||
@@ -69,7 +69,7 @@ export const DEFAULT_KEYBINDINGS: Record<ActionId, string> = {
|
||||
quickOpen: 'Cmd+K',
|
||||
openSettings: 'Cmd+.',
|
||||
toggleSplit: 'Cmd+\\',
|
||||
toggleSidebar: 'Cmd+Shift+S',
|
||||
toggleSidebar: 'Cmd+Shift+S'
|
||||
};
|
||||
|
||||
// ── Store ───────────────────────────────────────────────────────
|
||||
@@ -152,11 +152,16 @@ export function formatChord(chord: string): string {
|
||||
const formatted = parts.map((part) => {
|
||||
if (IS_MAC) {
|
||||
switch (part) {
|
||||
case 'Cmd': return '⌘';
|
||||
case 'Ctrl': return '⌃';
|
||||
case 'Alt': return '⌥';
|
||||
case 'Shift': return '⇧';
|
||||
default: return part;
|
||||
case 'Cmd':
|
||||
return '⌘';
|
||||
case 'Ctrl':
|
||||
return '⌃';
|
||||
case 'Alt':
|
||||
return '⌥';
|
||||
case 'Shift':
|
||||
return '⇧';
|
||||
default:
|
||||
return part;
|
||||
}
|
||||
}
|
||||
return part;
|
||||
@@ -175,11 +180,16 @@ export function chordToDisplayParts(chord: string): string[] {
|
||||
return parts.map((part) => {
|
||||
if (IS_MAC) {
|
||||
switch (part) {
|
||||
case 'Cmd': return '⌘';
|
||||
case 'Ctrl': return '⌃';
|
||||
case 'Alt': return '⌥';
|
||||
case 'Shift': return '⇧';
|
||||
default: return part;
|
||||
case 'Cmd':
|
||||
return '⌘';
|
||||
case 'Ctrl':
|
||||
return '⌃';
|
||||
case 'Alt':
|
||||
return '⌥';
|
||||
case 'Shift':
|
||||
return '⇧';
|
||||
default:
|
||||
return part;
|
||||
}
|
||||
}
|
||||
return part;
|
||||
|
||||
@@ -15,7 +15,7 @@ function connect() {
|
||||
socket = io({
|
||||
reconnection: true,
|
||||
reconnectionDelay: 1000,
|
||||
withCredentials: true,
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
|
||||
@@ -56,7 +56,7 @@ function connect(watchPath: string) {
|
||||
port: msg.port,
|
||||
pid: msg.pid,
|
||||
process: msg.process,
|
||||
session_id: msg.session_id ?? null,
|
||||
session_id: msg.session_id ?? null
|
||||
};
|
||||
// Add to active ports
|
||||
_ports = [..._ports.filter((p) => p.port !== info.port), info];
|
||||
@@ -106,9 +106,7 @@ function watchPath(path: string) {
|
||||
}
|
||||
|
||||
function isRelevantFsChange(targetPath: string): boolean {
|
||||
return _fsChangedPaths.some(
|
||||
(p) => p === targetPath || p.startsWith(targetPath + '/')
|
||||
);
|
||||
return _fsChangedPaths.some((p) => p === targetPath || p.startsWith(targetPath + '/'));
|
||||
}
|
||||
|
||||
function dismissPort(port: number) {
|
||||
@@ -122,12 +120,20 @@ export const systemEvents = {
|
||||
watchPath,
|
||||
|
||||
// FS
|
||||
get fsTick() { return _fsTick; },
|
||||
get fsChangedPaths() { return _fsChangedPaths; },
|
||||
get fsTick() {
|
||||
return _fsTick;
|
||||
},
|
||||
get fsChangedPaths() {
|
||||
return _fsChangedPaths;
|
||||
},
|
||||
isRelevantFsChange,
|
||||
|
||||
// Ports
|
||||
get ports() { return _ports; },
|
||||
get newPorts() { return _newPorts; },
|
||||
dismissPort,
|
||||
get ports() {
|
||||
return _ports;
|
||||
},
|
||||
get newPorts() {
|
||||
return _newPorts;
|
||||
},
|
||||
dismissPort
|
||||
};
|
||||
@@ -7,8 +7,7 @@ import 'tippy.js/dist/tippy.css';
|
||||
* or: <button use:tooltip={{ content: 'New terminal', placement: 'bottom' }}>
|
||||
*/
|
||||
export function tooltip(node: HTMLElement, params: string | Partial<TippyProps>) {
|
||||
const opts: Partial<TippyProps> =
|
||||
typeof params === 'string' ? { content: params } : params;
|
||||
const opts: Partial<TippyProps> = typeof params === 'string' ? { content: params } : params;
|
||||
|
||||
const instance = tippy(node, {
|
||||
arrow: false,
|
||||
@@ -17,7 +16,7 @@ export function tooltip(node: HTMLElement, params: string | Partial<TippyProps>)
|
||||
placement: 'bottom',
|
||||
theme: 'cptr',
|
||||
touch: false,
|
||||
...opts,
|
||||
...opts
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -27,6 +26,6 @@ export function tooltip(node: HTMLElement, params: string | Partial<TippyProps>)
|
||||
},
|
||||
destroy() {
|
||||
instance.destroy();
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -10,20 +10,44 @@ export function fileIconName(name: string, type: string = 'file'): string {
|
||||
if (name === 'LICENSE' || name === 'LICENSE.md') return 'page-text';
|
||||
if (name.endsWith('.lock')) return 'lock';
|
||||
switch (ext) {
|
||||
case 'md': return 'page-text';
|
||||
case 'ts': case 'tsx': case 'js': case 'jsx':
|
||||
case 'py': case 'rs': case 'go': case 'java':
|
||||
case 'c': case 'cpp': case 'h': case 'hpp':
|
||||
case 'rb': case 'php': case 'swift': case 'kt':
|
||||
case 'svelte': case 'vue':
|
||||
case 'md':
|
||||
return 'page-text';
|
||||
case 'ts':
|
||||
case 'tsx':
|
||||
case 'js':
|
||||
case 'jsx':
|
||||
case 'py':
|
||||
case 'rs':
|
||||
case 'go':
|
||||
case 'java':
|
||||
case 'c':
|
||||
case 'cpp':
|
||||
case 'h':
|
||||
case 'hpp':
|
||||
case 'rb':
|
||||
case 'php':
|
||||
case 'swift':
|
||||
case 'kt':
|
||||
case 'svelte':
|
||||
case 'vue':
|
||||
return 'code';
|
||||
case 'json': case 'yaml': case 'yml': case 'toml':
|
||||
case 'ini': case 'cfg': case 'conf':
|
||||
case 'json':
|
||||
case 'yaml':
|
||||
case 'yml':
|
||||
case 'toml':
|
||||
case 'ini':
|
||||
case 'cfg':
|
||||
case 'conf':
|
||||
return 'settings';
|
||||
case 'sh': case 'bash': case 'zsh':
|
||||
case 'sh':
|
||||
case 'bash':
|
||||
case 'zsh':
|
||||
return 'terminal';
|
||||
case 'css': case 'html': case 'xml':
|
||||
case 'css':
|
||||
case 'html':
|
||||
case 'xml':
|
||||
return 'code';
|
||||
default: return 'empty-page';
|
||||
default:
|
||||
return 'empty-page';
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,20 @@
|
||||
import AuthScreen from '$lib/components/AuthScreen.svelte';
|
||||
import ChangelogModal from '$lib/components/ChangelogModal.svelte';
|
||||
import { Toaster } from 'svelte-sonner';
|
||||
import { activeTab, currentWorkspace, stateLoaded, initState, gitReviewOpen, isGitRepo, splitActive, splitCurrentTab, closeGroup, appVersion, lastSeenVersion, showChangelog } from '$lib/stores';
|
||||
import {
|
||||
activeTab,
|
||||
currentWorkspace,
|
||||
stateLoaded,
|
||||
initState,
|
||||
gitReviewOpen,
|
||||
isGitRepo,
|
||||
splitActive,
|
||||
splitCurrentTab,
|
||||
closeGroup,
|
||||
appVersion,
|
||||
lastSeenVersion,
|
||||
showChangelog
|
||||
} from '$lib/stores';
|
||||
import { matchKeybinding, executeAction } from '$lib/stores/keybindings';
|
||||
import { systemEvents } from '$lib/stores/systemEvents.svelte';
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
@@ -40,13 +53,18 @@
|
||||
// Periodic session health check (every 30 min).
|
||||
// This triggers the backend's sliding session refresh and
|
||||
// proactively catches expired sessions before a 401 mid-action.
|
||||
const healthCheck = setInterval(() => {
|
||||
if (authState === 'authenticated') {
|
||||
getSession().then((auth) => {
|
||||
if (!auth.authenticated) clearSession();
|
||||
}).catch(() => {});
|
||||
}
|
||||
}, 30 * 60 * 1000);
|
||||
const healthCheck = setInterval(
|
||||
() => {
|
||||
if (authState === 'authenticated') {
|
||||
getSession()
|
||||
.then((auth) => {
|
||||
if (!auth.authenticated) clearSession();
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
},
|
||||
30 * 60 * 1000
|
||||
);
|
||||
|
||||
// iOS/Android: visualViewport gives accurate height when keyboard is open.
|
||||
// Debounce to avoid firing dozens of resizes during the keyboard animation
|
||||
@@ -105,9 +123,11 @@
|
||||
|
||||
const auth = await getSession();
|
||||
|
||||
getConfig().then(cfg => {
|
||||
appVersion.set(cfg.version);
|
||||
}).catch(() => {});
|
||||
getConfig()
|
||||
.then((cfg) => {
|
||||
appVersion.set(cfg.version);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
if (auth.authenticated) {
|
||||
setSession({
|
||||
@@ -115,7 +135,7 @@
|
||||
username: auth.username!,
|
||||
display_name: auth.display_name,
|
||||
role: auth.role!,
|
||||
profile_image_url: auth.profile_image_url,
|
||||
profile_image_url: auth.profile_image_url
|
||||
});
|
||||
authState = 'authenticated';
|
||||
initState();
|
||||
@@ -142,7 +162,7 @@
|
||||
username: auth.username!,
|
||||
display_name: auth.display_name,
|
||||
role: auth.role!,
|
||||
profile_image_url: auth.profile_image_url,
|
||||
profile_image_url: auth.profile_image_url
|
||||
});
|
||||
authState = 'authenticated';
|
||||
initState();
|
||||
@@ -158,8 +178,12 @@
|
||||
if (!action) return;
|
||||
e.preventDefault();
|
||||
executeAction(action, {
|
||||
toggleQuickOpen: () => { showQuickOpen = !showQuickOpen; },
|
||||
toggleSettings: () => { showSettings = !showSettings; },
|
||||
toggleQuickOpen: () => {
|
||||
showQuickOpen = !showQuickOpen;
|
||||
},
|
||||
toggleSettings: () => {
|
||||
showSettings = !showSettings;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,7 +213,7 @@
|
||||
|
||||
async function check() {
|
||||
try {
|
||||
const status = await getGitStatus(wsPath) as { is_repo?: boolean };
|
||||
const status = (await getGitStatus(wsPath)) as { is_repo?: boolean };
|
||||
if (!cancelled) isGitRepo.set(Boolean(status?.is_repo));
|
||||
} catch {
|
||||
if (!cancelled) isGitRepo.set(false);
|
||||
@@ -198,14 +222,20 @@
|
||||
|
||||
check();
|
||||
const interval = setInterval(check, 5000);
|
||||
return () => { cancelled = true; clearInterval(interval); };
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(interval);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<title>{$currentWorkspace ? `${$currentWorkspace.name} / cptr` : 'cptr'}</title>
|
||||
<meta name="description" content={$t('app.tagline')} />
|
||||
</svelte:head>
|
||||
@@ -215,7 +245,9 @@
|
||||
{#if authState === 'checking'}
|
||||
<!-- Loading spinner while checking auth -->
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black">
|
||||
<div class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{:else if authState === 'needs_setup' || authState === 'needs_login'}
|
||||
<!-- Auth screen -->
|
||||
@@ -227,7 +259,10 @@
|
||||
onauth={handleAuth}
|
||||
/>
|
||||
{:else if $stateLoaded}
|
||||
<div class="flex overflow-hidden font-sans antialiased text-gray-900 bg-white dark:text-gray-100 dark:bg-black" style="height: {viewportHeight};">
|
||||
<div
|
||||
class="flex overflow-hidden font-sans antialiased text-gray-900 bg-white dark:text-gray-100 dark:bg-black"
|
||||
style="height: {viewportHeight};"
|
||||
>
|
||||
<Sidebar />
|
||||
|
||||
<div class="flex flex-col flex-1 min-w-0">
|
||||
@@ -249,21 +284,24 @@
|
||||
</div>
|
||||
|
||||
{#if showQuickOpen}
|
||||
<QuickOpen onclose={() => showQuickOpen = false} />
|
||||
<QuickOpen onclose={() => (showQuickOpen = false)} />
|
||||
{/if}
|
||||
{#if showSettings}
|
||||
<SettingsModal onclose={() => showSettings = false} />
|
||||
<SettingsModal onclose={() => (showSettings = false)} />
|
||||
{/if}
|
||||
<ChangelogModal />
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black">
|
||||
<div class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Toaster
|
||||
position="bottom-center"
|
||||
toastOptions={{
|
||||
style: 'font-size: 12px; font-family: var(--font-sans); background: #111; color: #e0e0e0; border: 1px solid rgba(255,255,255,0.06); border-radius: 8px;'
|
||||
style:
|
||||
'font-size: 12px; font-family: var(--font-sans); background: #111; color: #e0e0e0; border: 1px solid rgba(255,255,255,0.06); border-radius: 8px;'
|
||||
}}
|
||||
/>
|
||||
@@ -1,7 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { currentWorkspace, activeTab, workspaceList, addWorkspace, loadWorkspace, gitReviewOpen, setActiveGroup, setSplitRatio, moveTabToGroup, openInSplit, openTabInSplit, setSplitDirection, appVersion, showChangelog } from '$lib/stores';
|
||||
import {
|
||||
currentWorkspace,
|
||||
activeTab,
|
||||
workspaceList,
|
||||
addWorkspace,
|
||||
loadWorkspace,
|
||||
gitReviewOpen,
|
||||
setActiveGroup,
|
||||
setSplitRatio,
|
||||
moveTabToGroup,
|
||||
openInSplit,
|
||||
openTabInSplit,
|
||||
setSplitDirection,
|
||||
appVersion,
|
||||
showChangelog
|
||||
} from '$lib/stores';
|
||||
import { splitActive } from '$lib/stores';
|
||||
import type { Tab, EditorGroup, WorkspaceState } from '$lib/stores';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -67,7 +82,9 @@
|
||||
$effect(() => {
|
||||
if (!$currentWorkspace) {
|
||||
getWelcome()
|
||||
.then((data) => { welcomeData = data; })
|
||||
.then((data) => {
|
||||
welcomeData = data;
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
});
|
||||
@@ -93,13 +110,15 @@
|
||||
...g,
|
||||
tabs: g.tabs.map((t) =>
|
||||
t.id === tab.id ? { ...t, sessionId: data.session_id } : t
|
||||
),
|
||||
})),
|
||||
)
|
||||
}))
|
||||
};
|
||||
});
|
||||
})
|
||||
.catch((e) => console.error('Failed to init terminal:', e))
|
||||
.finally(() => { initingTerminal = false; });
|
||||
.finally(() => {
|
||||
initingTerminal = false;
|
||||
});
|
||||
return; // Only init one at a time
|
||||
}
|
||||
}
|
||||
@@ -152,7 +171,9 @@
|
||||
|
||||
$effect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
function onResize() { isWideScreen = window.innerWidth >= 1024; }
|
||||
function onResize() {
|
||||
isWideScreen = window.innerWidth >= 1024;
|
||||
}
|
||||
window.addEventListener('resize', onResize);
|
||||
return () => window.removeEventListener('resize', onResize);
|
||||
});
|
||||
@@ -257,7 +278,9 @@
|
||||
{/if}
|
||||
</div>
|
||||
{#if welcomeData?.hostname}
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 mt-0.5 font-mono">{welcomeData.hostname}</p>
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600 mt-0.5 font-mono">
|
||||
{welcomeData.hostname}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -273,7 +296,7 @@
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-2">{$t('home.start')}</h2>
|
||||
<button
|
||||
class="flex items-center gap-2 text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => showPicker = true}
|
||||
onclick={() => (showPicker = true)}
|
||||
>
|
||||
<Icon name="folder" size={15} strokeWidth={1.3} />
|
||||
{$t('home.openFolder')}
|
||||
@@ -290,8 +313,13 @@
|
||||
class="flex items-center gap-3 py-1.5 group text-left transition-colors duration-100"
|
||||
onclick={() => quickOpen(item.path)}
|
||||
>
|
||||
<span class="text-[13px] text-gray-700 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-white">{item.name}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono">{shortenPath(item.path)}</span>
|
||||
<span
|
||||
class="text-[13px] text-gray-700 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-white"
|
||||
>{item.name}</span
|
||||
>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{shortenPath(item.path)}</span
|
||||
>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -310,7 +338,9 @@
|
||||
>
|
||||
<Icon name="folder" size={14} strokeWidth={1.3} />
|
||||
<span>{item.name}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono">{shortenPath(item.path)}</span>
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600 font-mono"
|
||||
>{shortenPath(item.path)}</span
|
||||
>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -320,7 +350,7 @@
|
||||
</div>
|
||||
|
||||
{#if showPicker}
|
||||
<DirectoryPicker onclose={() => showPicker = false} />
|
||||
<DirectoryPicker onclose={() => (showPicker = false)} />
|
||||
{/if}
|
||||
{:else}
|
||||
<!-- Editor groups layout -->
|
||||
@@ -369,42 +399,36 @@
|
||||
|
||||
<!-- Tab content -->
|
||||
<div class="pane-content">
|
||||
{#if $gitReviewOpen && i === 0}
|
||||
{#if $gitReviewOpen && i === 0}
|
||||
<GitView />
|
||||
{:else}
|
||||
<!-- Persist all tab instances so state survives tab switches (like VS Code) -->
|
||||
{#each group.tabs.filter(t => t.type === 'file' && t.filePath) as tab (tab.id)}
|
||||
<div
|
||||
class="persisted-tab"
|
||||
class:persisted-tab-hidden={tab.id !== group.activeTabId}
|
||||
>
|
||||
{#each group.tabs.filter((t) => t.type === 'file' && t.filePath) as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<FileEditor filePath={tab.filePath} tabId={tab.id} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#each group.tabs.filter(t => t.type === 'chat') as tab (tab.id)}
|
||||
<div
|
||||
class="persisted-tab"
|
||||
class:persisted-tab-hidden={tab.id !== group.activeTabId}
|
||||
>
|
||||
<ChatPanel workspace={$currentWorkspace.path} chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-') ? undefined : tab.path} tabId={tab.id} />
|
||||
{#each group.tabs.filter((t) => t.type === 'chat') as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<ChatPanel
|
||||
workspace={$currentWorkspace.path}
|
||||
chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-')
|
||||
? undefined
|
||||
: tab.path}
|
||||
tabId={tab.id}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#each group.tabs.filter(t => t.type === 'terminal' && t.sessionId) as tab (tab.id)}
|
||||
<div
|
||||
class="persisted-tab"
|
||||
class:persisted-tab-hidden={tab.id !== group.activeTabId}
|
||||
>
|
||||
{#each group.tabs.filter((t) => t.type === 'terminal' && t.sessionId) as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<Terminal sessionId={tab.sessionId} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#each group.tabs.filter(t => t.type === 'preview' && t.port) as tab (tab.id)}
|
||||
<div
|
||||
class="persisted-tab"
|
||||
class:persisted-tab-hidden={tab.id !== group.activeTabId}
|
||||
>
|
||||
{#each group.tabs.filter((t) => t.type === 'preview' && t.port) as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<PortPreview port={tab.port} />
|
||||
</div>
|
||||
{/each}
|
||||
@@ -414,7 +438,9 @@
|
||||
<FileBrowser />
|
||||
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
|
||||
<div class="flex items-center justify-center h-full">
|
||||
<div class="w-5 h-5 border-2 border-gray-800 border-t-gray-400 rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-800 border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
Revision ID: 001
|
||||
Create Date: 2026-05-28
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
@@ -74,7 +75,13 @@ def upgrade() -> None:
|
||||
op.create_table(
|
||||
"chat_message",
|
||||
sa.Column("id", sa.Text, primary_key=True),
|
||||
sa.Column("chat_id", sa.Text, sa.ForeignKey("chat.id", ondelete="CASCADE"), nullable=False, index=True),
|
||||
sa.Column(
|
||||
"chat_id",
|
||||
sa.Text,
|
||||
sa.ForeignKey("chat.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
),
|
||||
sa.Column("parent_id", sa.Text, nullable=True),
|
||||
sa.Column("role", sa.Text, nullable=False),
|
||||
sa.Column("content", sa.Text, nullable=False),
|
||||
@@ -98,6 +105,7 @@ def upgrade() -> None:
|
||||
sa.UniqueConstraint("user_id", "path", name="uq_workspace_user_path"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("workspaces")
|
||||
op.drop_table("chat_message")
|
||||
|
||||
+11
-2
@@ -7,5 +7,14 @@ from cptr.models.config import Config
|
||||
from cptr.models.files import File
|
||||
from cptr.models.chats import Chat, ChatMessage
|
||||
|
||||
__all__ = ["Base", "User", "Auth", "UserStates", "Workspace", "Config", "File", "Chat", "ChatMessage"]
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
"User",
|
||||
"Auth",
|
||||
"UserStates",
|
||||
"Workspace",
|
||||
"Config",
|
||||
"File",
|
||||
"Chat",
|
||||
"ChatMessage",
|
||||
]
|
||||
+28
-22
@@ -17,16 +17,17 @@ def _uuid() -> str:
|
||||
|
||||
class Chat(Base):
|
||||
"""A chat conversation. Workspace association lives in the filesystem."""
|
||||
|
||||
__tablename__ = "chat"
|
||||
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
user_id = Column(Text, ForeignKey("users.id"), nullable=False)
|
||||
title = Column(Text, nullable=False)
|
||||
summary = Column(Text, nullable=True)
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
user_id = Column(Text, ForeignKey("users.id"), nullable=False)
|
||||
title = Column(Text, nullable=False)
|
||||
summary = Column(Text, nullable=True)
|
||||
current_message_id = Column(Text, nullable=True)
|
||||
meta = Column(JSON, nullable=True) # {model_id, connection_id, pinned, archived, ...}
|
||||
created_at = Column(BigInteger, nullable=False)
|
||||
updated_at = Column(BigInteger, nullable=False)
|
||||
meta = Column(JSON, nullable=True) # {model_id, connection_id, pinned, archived, ...}
|
||||
created_at = Column(BigInteger, nullable=False)
|
||||
updated_at = Column(BigInteger, nullable=False)
|
||||
|
||||
# ── Class methods ────────────────────────────────────────
|
||||
|
||||
@@ -78,7 +79,9 @@ class Chat(Base):
|
||||
async def update_summary(chat_id: str, summary: str, updated_at: int = 0) -> bool:
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
update(Chat).where(Chat.id == chat_id).values(summary=summary, updated_at=updated_at)
|
||||
update(Chat)
|
||||
.where(Chat.id == chat_id)
|
||||
.values(summary=summary, updated_at=updated_at)
|
||||
)
|
||||
await db.commit()
|
||||
return result.rowcount > 0
|
||||
@@ -93,12 +96,14 @@ class Chat(Base):
|
||||
return result.rowcount > 0
|
||||
|
||||
@staticmethod
|
||||
async def update_current_message(chat_id: str, message_id: str | None, updated_at: int = 0) -> bool:
|
||||
async def update_current_message(
|
||||
chat_id: str, message_id: str | None, updated_at: int = 0
|
||||
) -> bool:
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
update(Chat).where(Chat.id == chat_id).values(
|
||||
current_message_id=message_id, updated_at=updated_at
|
||||
)
|
||||
update(Chat)
|
||||
.where(Chat.id == chat_id)
|
||||
.values(current_message_id=message_id, updated_at=updated_at)
|
||||
)
|
||||
await db.commit()
|
||||
return result.rowcount > 0
|
||||
@@ -115,18 +120,19 @@ class Chat(Base):
|
||||
|
||||
class ChatMessage(Base):
|
||||
"""A single message in a chat conversation."""
|
||||
|
||||
__tablename__ = "chat_message"
|
||||
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
chat_id = Column(Text, ForeignKey("chat.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
parent_id = Column(Text, nullable=True)
|
||||
role = Column(Text, nullable=False) # "user" | "assistant"
|
||||
content = Column(Text, nullable=False) # Flattened text content
|
||||
model = Column(Text, nullable=True) # Model used (assistant only)
|
||||
done = Column(Boolean, default=True) # false = streaming or pending approval
|
||||
output = Column(JSON, nullable=True) # Responses API output items
|
||||
usage = Column(JSON, nullable=True) # {input_tokens, output_tokens, ...}
|
||||
meta = Column(JSON, nullable=True) # {files, followups, error, ...}
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
chat_id = Column(Text, ForeignKey("chat.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
parent_id = Column(Text, nullable=True)
|
||||
role = Column(Text, nullable=False) # "user" | "assistant"
|
||||
content = Column(Text, nullable=False) # Flattened text content
|
||||
model = Column(Text, nullable=True) # Model used (assistant only)
|
||||
done = Column(Boolean, default=True) # false = streaming or pending approval
|
||||
output = Column(JSON, nullable=True) # Responses API output items
|
||||
usage = Column(JSON, nullable=True) # {input_tokens, output_tokens, ...}
|
||||
meta = Column(JSON, nullable=True) # {files, followups, error, ...}
|
||||
created_at = Column(BigInteger, nullable=False)
|
||||
|
||||
# ── Class methods ────────────────────────────────────────
|
||||
|
||||
@@ -15,6 +15,7 @@ class Config(Base):
|
||||
Keys use dot-notation: auth.signup_enabled, ai.default_model, etc.
|
||||
Values are JSON (booleans, strings, numbers, objects, arrays).
|
||||
"""
|
||||
|
||||
__tablename__ = "config"
|
||||
|
||||
key = Column(Text, primary_key=True)
|
||||
@@ -41,9 +42,7 @@ class Config(Base):
|
||||
async def get_namespace(namespace: str) -> dict:
|
||||
"""Get all config keys under a namespace (e.g. 'auth' → 'auth.*')."""
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
select(Config).where(Config.key.like(f"{namespace}.%"))
|
||||
)
|
||||
result = await db.execute(select(Config).where(Config.key.like(f"{namespace}.%")))
|
||||
return {row.key: row.value for row in result.scalars().all()}
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -17,6 +17,7 @@ def _uuid() -> str:
|
||||
|
||||
class File(Base):
|
||||
"""One row per uploaded blob. Storage key == id (UUID)."""
|
||||
|
||||
__tablename__ = "files"
|
||||
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
@@ -24,7 +25,7 @@ class File(Base):
|
||||
filename = Column(Text, nullable=False)
|
||||
path = Column(Text, nullable=False, default="")
|
||||
hash = Column(Text, nullable=False, default="")
|
||||
meta = Column(JSON, nullable=False, default=dict) # content_type, size, etc.
|
||||
meta = Column(JSON, nullable=False, default=dict) # content_type, size, etc.
|
||||
data = Column(JSON, nullable=False, default=dict)
|
||||
created_at = Column(BigInteger, nullable=False)
|
||||
updated_at = Column(BigInteger, nullable=True)
|
||||
@@ -32,8 +33,7 @@ class File(Base):
|
||||
# ── Class methods ────────────────────────────────────────
|
||||
|
||||
@staticmethod
|
||||
async def create(*, user_id: str | None, filename: str, meta: dict,
|
||||
created_at: int) -> File:
|
||||
async def create(*, user_id: str | None, filename: str, meta: dict, created_at: int) -> File:
|
||||
"""Insert a new file record and return it."""
|
||||
async with await get_db() as db:
|
||||
f = File(
|
||||
|
||||
+20
-9
@@ -18,6 +18,7 @@ def _uuid() -> str:
|
||||
|
||||
class User(Base):
|
||||
"""Profile only. No credentials, no login identity."""
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
@@ -45,7 +46,14 @@ class User(Base):
|
||||
"""List all users joined with their auth username."""
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
select(User.id, User.display_name, User.profile_image_url, User.role, User.created_at, Auth.username)
|
||||
select(
|
||||
User.id,
|
||||
User.display_name,
|
||||
User.profile_image_url,
|
||||
User.role,
|
||||
User.created_at,
|
||||
Auth.username,
|
||||
)
|
||||
.join(Auth, User.id == Auth.user_id)
|
||||
.order_by(User.created_at)
|
||||
)
|
||||
@@ -62,8 +70,13 @@ class User(Base):
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
async def create(username: str, password_hash: str, role: str = "user",
|
||||
display_name: str | None = None, created_at: int = 0) -> str:
|
||||
async def create(
|
||||
username: str,
|
||||
password_hash: str,
|
||||
role: str = "user",
|
||||
display_name: str | None = None,
|
||||
created_at: int = 0,
|
||||
) -> str:
|
||||
"""Create a User + Auth row. Returns the new user_id."""
|
||||
async with await get_db() as db:
|
||||
user = User(created_at=created_at, display_name=display_name, role=role)
|
||||
@@ -77,9 +90,7 @@ class User(Base):
|
||||
async def update_role(user_id: str, role: str) -> bool:
|
||||
"""Update a user's role. Returns True if user existed."""
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
update(User).where(User.id == user_id).values(role=role)
|
||||
)
|
||||
result = await db.execute(update(User).where(User.id == user_id).values(role=role))
|
||||
await db.commit()
|
||||
return result.rowcount > 0
|
||||
|
||||
@@ -115,6 +126,7 @@ class User(Base):
|
||||
|
||||
class Auth(Base):
|
||||
"""Login identity + credentials. 1:1 with User."""
|
||||
|
||||
__tablename__ = "auths"
|
||||
|
||||
user_id = Column(Text, ForeignKey("users.id"), primary_key=True)
|
||||
@@ -147,9 +159,7 @@ class Auth(Base):
|
||||
auth = result.scalar_one_or_none()
|
||||
if not auth:
|
||||
return False
|
||||
await db.execute(
|
||||
update(Auth).where(Auth.user_id == user_id).values(password=new_hash)
|
||||
)
|
||||
await db.execute(update(Auth).where(Auth.user_id == user_id).values(password=new_hash))
|
||||
await db.commit()
|
||||
return True
|
||||
|
||||
@@ -190,6 +200,7 @@ class Auth(Base):
|
||||
|
||||
class UserStates(Base):
|
||||
"""Workspace layout state. 1:1 with User."""
|
||||
|
||||
__tablename__ = "user_states"
|
||||
|
||||
user_id = Column(Text, ForeignKey("users.id"), primary_key=True)
|
||||
|
||||
@@ -19,6 +19,7 @@ def _uuid() -> str:
|
||||
|
||||
class Workspace(Base):
|
||||
"""Per-workspace state. One row per (user, filesystem path)."""
|
||||
|
||||
__tablename__ = "workspaces"
|
||||
|
||||
id = Column(Text, primary_key=True, default=_uuid)
|
||||
@@ -38,9 +39,7 @@ class Workspace(Base):
|
||||
"""List all workspaces for a user."""
|
||||
async with await get_db() as db:
|
||||
result = await db.execute(
|
||||
select(Workspace)
|
||||
.where(Workspace.user_id == user_id)
|
||||
.order_by(Workspace.created_at)
|
||||
select(Workspace).where(Workspace.user_id == user_id).order_by(Workspace.created_at)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
+20
-7
@@ -179,6 +179,7 @@ async def create_connection(body: CreateConnectionRequest, request: Request):
|
||||
"""Add a new AI connection."""
|
||||
require_admin(request)
|
||||
import uuid as _uuid
|
||||
|
||||
connections = await _get_connections()
|
||||
conn = {
|
||||
"id": str(_uuid.uuid4()),
|
||||
@@ -259,17 +260,27 @@ async def verify_connection(conn_id: str, request: Request):
|
||||
if provider == "anthropic":
|
||||
url = (base_url or "https://api.anthropic.com/v1") + "/messages"
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(url, headers={
|
||||
"x-api-key": api_key or "",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"content-type": "application/json",
|
||||
}, json={"model": "claude-sonnet-4-20250514", "max_tokens": 1, "messages": [{"role": "user", "content": "hi"}]})
|
||||
r = await client.post(
|
||||
url,
|
||||
headers={
|
||||
"x-api-key": api_key or "",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"content-type": "application/json",
|
||||
},
|
||||
json={
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"max_tokens": 1,
|
||||
"messages": [{"role": "user", "content": "hi"}],
|
||||
},
|
||||
)
|
||||
if r.status_code in (200, 201):
|
||||
return {"ok": True, "message": "Connected"}
|
||||
elif r.status_code == 401:
|
||||
return JSONResponse({"ok": False, "message": "Invalid API key"}, 400)
|
||||
else:
|
||||
return JSONResponse({"ok": False, "message": f"API returned {r.status_code}"}, 400)
|
||||
return JSONResponse(
|
||||
{"ok": False, "message": f"API returned {r.status_code}"}, 400
|
||||
)
|
||||
|
||||
elif provider == "openai":
|
||||
url = (base_url or "https://api.openai.com/v1") + "/models"
|
||||
@@ -280,7 +291,9 @@ async def verify_connection(conn_id: str, request: Request):
|
||||
elif r.status_code == 401:
|
||||
return JSONResponse({"ok": False, "message": "Invalid API key"}, 400)
|
||||
else:
|
||||
return JSONResponse({"ok": False, "message": f"API returned {r.status_code}"}, 400)
|
||||
return JSONResponse(
|
||||
{"ok": False, "message": f"API returned {r.status_code}"}, 400
|
||||
)
|
||||
|
||||
else:
|
||||
return JSONResponse({"ok": False, "message": f"Unknown provider: {provider}"}, 400)
|
||||
|
||||
+10
-5
@@ -33,8 +33,11 @@ def _ok_with_cookie(jwt_token: str, data: dict | None = None) -> JSONResponse:
|
||||
"""Return a JSONResponse with the session cookie set."""
|
||||
resp = JSONResponse(data or {"ok": True})
|
||||
resp.set_cookie(
|
||||
key=COOKIE_NAME, value=jwt_token,
|
||||
httponly=True, samesite="lax", path="/",
|
||||
key=COOKIE_NAME,
|
||||
value=jwt_token,
|
||||
httponly=True,
|
||||
samesite="lax",
|
||||
path="/",
|
||||
max_age=SESSION_MAX_AGE,
|
||||
)
|
||||
return resp
|
||||
@@ -43,7 +46,7 @@ def _ok_with_cookie(jwt_token: str, data: dict | None = None) -> JSONResponse:
|
||||
@router.get("")
|
||||
async def get_auth(request: Request):
|
||||
"""Session check. Returns user info or {authenticated: false}.
|
||||
|
||||
|
||||
Implements sliding sessions: if the token is past its halfway point,
|
||||
a fresh token is issued so active users never get logged out.
|
||||
"""
|
||||
@@ -57,6 +60,7 @@ async def get_auth(request: Request):
|
||||
user = await User.get_by_id(auth.user_id)
|
||||
if user is None:
|
||||
from starlette.responses import JSONResponse as StarletteJSONResponse
|
||||
|
||||
response = StarletteJSONResponse({"authenticated": False})
|
||||
response.delete_cookie(COOKIE_NAME, path="/")
|
||||
return response
|
||||
@@ -88,7 +92,8 @@ async def setup(body: SetupRequest, request: Request):
|
||||
if await has_any_user():
|
||||
return JSONResponse({"error": "already set up"}, 400)
|
||||
import secrets as _secrets
|
||||
expected = getattr(request.app.state, 'startup_token', None)
|
||||
|
||||
expected = getattr(request.app.state, "startup_token", None)
|
||||
if not body.token or not expected or not _secrets.compare_digest(body.token, expected):
|
||||
return JSONResponse({"error": "invalid startup token"}, 403)
|
||||
if not body.username or not body.username.strip():
|
||||
@@ -124,7 +129,7 @@ async def login(body: LoginRequest, request: Request):
|
||||
if not result or not verify_password(body.password, result[0].password):
|
||||
return JSONResponse({"error": "incorrect credentials"}, 401)
|
||||
auth, user = result
|
||||
if user.role == 'pending':
|
||||
if user.role == "pending":
|
||||
return JSONResponse({"error": "account pending approval"}, 403)
|
||||
return _ok_with_cookie(create_token(auth.user_id, auth.username, role=user.role))
|
||||
|
||||
|
||||
+79
-54
@@ -56,6 +56,7 @@ def _get_user(request: Request) -> str:
|
||||
|
||||
# ── List chats for a workspace ──────────────────────────────
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_chats(
|
||||
request: Request,
|
||||
@@ -98,34 +99,39 @@ async def list_chats(
|
||||
for entry in chat_entries:
|
||||
chat = chat_map.get(entry["id"])
|
||||
if chat and chat.user_id == user_id:
|
||||
result.append({
|
||||
"id": chat.id,
|
||||
"title": chat.title,
|
||||
"summary": chat.summary,
|
||||
"folder": entry["folder"],
|
||||
"meta": chat.meta,
|
||||
"current_message_id": chat.current_message_id,
|
||||
"created_at": chat.created_at,
|
||||
"updated_at": chat.updated_at,
|
||||
})
|
||||
result.append(
|
||||
{
|
||||
"id": chat.id,
|
||||
"title": chat.title,
|
||||
"summary": chat.summary,
|
||||
"folder": entry["folder"],
|
||||
"meta": chat.meta,
|
||||
"current_message_id": chat.current_message_id,
|
||||
"created_at": chat.created_at,
|
||||
"updated_at": chat.updated_at,
|
||||
}
|
||||
)
|
||||
|
||||
# Sort by requested field
|
||||
sort_field = sort_by if sort_by in ("title", "updated_at") else "updated_at"
|
||||
reverse = sort_dir != "asc"
|
||||
result.sort(key=lambda c: (c[sort_field] or ""), reverse=reverse)
|
||||
result.sort(key=lambda c: c[sort_field] or "", reverse=reverse)
|
||||
total = len(result)
|
||||
page = result[offset : offset + limit]
|
||||
return {"chats": page, "total": total, "has_more": offset + limit < total}
|
||||
|
||||
|
||||
# ── Models aggregation ──────────────────────────────────────
|
||||
# NOTE: Must be declared before /{chat_id} to avoid 'models' being treated as a chat_id.
|
||||
|
||||
|
||||
async def _get_connections() -> list[dict]:
|
||||
return await Config.get("chat.connections") or []
|
||||
|
||||
|
||||
# ── Model cache (app.state) ─────────────────────────────────
|
||||
|
||||
|
||||
async def _get_connection_models(conn: dict, app_state) -> list[str]:
|
||||
"""Get models for a connection: from stored data, cache, or auto-discover."""
|
||||
stored = conn.get("data", {}).get("models")
|
||||
@@ -167,14 +173,16 @@ async def get_models(request: Request):
|
||||
|
||||
prefix = (conn.get("prefix_id") or "").strip()
|
||||
|
||||
for model_id in (model_ids or []):
|
||||
for model_id in model_ids or []:
|
||||
prefixed_id = f"{prefix}/{model_id}" if prefix else model_id
|
||||
models.append({
|
||||
"id": prefixed_id,
|
||||
"name": model_id,
|
||||
"provider": conn.get("provider", ""),
|
||||
"connection_id": conn["id"],
|
||||
})
|
||||
models.append(
|
||||
{
|
||||
"id": prefixed_id,
|
||||
"name": model_id,
|
||||
"provider": conn.get("provider", ""),
|
||||
"connection_id": conn["id"],
|
||||
}
|
||||
)
|
||||
|
||||
default_model = await Config.get("chat.default_model")
|
||||
return {"models": models, "default": default_model}
|
||||
@@ -193,10 +201,13 @@ async def _fetch_provider_models(conn: dict) -> list[str]:
|
||||
if provider == "anthropic":
|
||||
url = (base_url or "https://api.anthropic.com/v1") + "/models"
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.get(url, headers={
|
||||
"x-api-key": api_key or "",
|
||||
"anthropic-version": "2023-06-01",
|
||||
})
|
||||
r = await client.get(
|
||||
url,
|
||||
headers={
|
||||
"x-api-key": api_key or "",
|
||||
"anthropic-version": "2023-06-01",
|
||||
},
|
||||
)
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
return [m["id"] for m in data.get("data", [])]
|
||||
@@ -204,9 +215,12 @@ async def _fetch_provider_models(conn: dict) -> list[str]:
|
||||
elif provider == "openai":
|
||||
url = (base_url or "https://api.openai.com/v1") + "/models"
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.get(url, headers={
|
||||
"Authorization": f"Bearer {api_key or ''}",
|
||||
})
|
||||
r = await client.get(
|
||||
url,
|
||||
headers={
|
||||
"Authorization": f"Bearer {api_key or ''}",
|
||||
},
|
||||
)
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
return [m["id"] for m in data.get("data", [])]
|
||||
@@ -219,6 +233,7 @@ async def _fetch_provider_models(conn: dict) -> list[str]:
|
||||
|
||||
# ── Get a chat with all messages ────────────────────────────
|
||||
|
||||
|
||||
@router.get("/{chat_id}")
|
||||
async def get_chat(chat_id: str, request: Request):
|
||||
"""Get chat metadata + all messages."""
|
||||
@@ -238,15 +253,14 @@ async def get_chat(chat_id: str, request: Request):
|
||||
"created_at": chat.created_at,
|
||||
"updated_at": chat.updated_at,
|
||||
},
|
||||
"messages": [
|
||||
_message_dict(m) for m in messages
|
||||
],
|
||||
"messages": [_message_dict(m) for m in messages],
|
||||
}
|
||||
|
||||
|
||||
def _message_dict(m) -> dict:
|
||||
"""Serialize a ChatMessage, overlaying live state if task is running."""
|
||||
from cptr.utils.chat_task import get_live_state
|
||||
|
||||
d = {
|
||||
"id": m.id,
|
||||
"parent_id": m.parent_id,
|
||||
@@ -269,6 +283,7 @@ def _message_dict(m) -> dict:
|
||||
|
||||
# ── Delete a chat ───────────────────────────────────────────
|
||||
|
||||
|
||||
@router.delete("/{chat_id}")
|
||||
async def delete_chat(chat_id: str, request: Request):
|
||||
"""Delete a chat and all its messages."""
|
||||
@@ -289,6 +304,7 @@ async def delete_chat(chat_id: str, request: Request):
|
||||
|
||||
# ── Send a message ──────────────────────────────────────────
|
||||
|
||||
|
||||
class SendMessageRequest(BaseModel):
|
||||
content: str = ""
|
||||
model_id: str
|
||||
@@ -348,6 +364,7 @@ async def send_message(body: SendMessageRequest, request: Request):
|
||||
# process queue now to close the race window.
|
||||
if not await _chat_has_active_generation(chat.id):
|
||||
from cptr.utils.chat_task import _process_queue
|
||||
|
||||
workspace = (chat.meta or {}).get("workspace", body.workspace)
|
||||
await _process_queue(chat.id, user_id, workspace)
|
||||
return {"chat_id": chat.id, "message_id": user_msg.id, "queued": True}
|
||||
@@ -390,6 +407,7 @@ async def send_message(body: SendMessageRequest, request: Request):
|
||||
|
||||
# Start background task (export_chat_to_file runs after task completes)
|
||||
from cptr.utils.chat_task import start_task
|
||||
|
||||
start_task(
|
||||
message_id=assistant_msg.id,
|
||||
chat_id=chat.id,
|
||||
@@ -405,15 +423,14 @@ async def send_message(body: SendMessageRequest, request: Request):
|
||||
|
||||
# ── Approve / reject a pending tool call ────────────────────
|
||||
|
||||
|
||||
class ApproveRequest(BaseModel):
|
||||
call_id: str
|
||||
approved: bool = True
|
||||
|
||||
|
||||
@router.post("/{chat_id}/messages/{message_id}/approve")
|
||||
async def approve_tool(
|
||||
chat_id: str, message_id: str, body: ApproveRequest, request: Request
|
||||
):
|
||||
async def approve_tool(chat_id: str, message_id: str, body: ApproveRequest, request: Request):
|
||||
"""Execute or reject a pending tool call, then continue."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
@@ -447,11 +464,13 @@ async def approve_tool(
|
||||
call["name"], call.get("arguments", {}), chat.meta.get("workspace", "")
|
||||
)
|
||||
call["status"] = "completed"
|
||||
output.append({
|
||||
"type": "function_call_output",
|
||||
"call_id": body.call_id,
|
||||
"output": result,
|
||||
})
|
||||
output.append(
|
||||
{
|
||||
"type": "function_call_output",
|
||||
"call_id": body.call_id,
|
||||
"output": result,
|
||||
}
|
||||
)
|
||||
await ChatMessage.update(message_id, output=output, done=False)
|
||||
|
||||
# Resolve connection and continue
|
||||
@@ -460,6 +479,7 @@ async def approve_tool(
|
||||
workspace = chat.meta.get("workspace", "") if chat.meta else ""
|
||||
|
||||
from cptr.utils.chat_task import start_task
|
||||
|
||||
start_task(
|
||||
message_id=message_id,
|
||||
chat_id=chat_id,
|
||||
@@ -473,6 +493,7 @@ async def approve_tool(
|
||||
await ChatMessage.update(message_id, output=output, done=True)
|
||||
# Process queued messages since this chat is now idle
|
||||
from cptr.utils.chat_task import _process_queue
|
||||
|
||||
workspace = chat.meta.get("workspace", "") if chat.meta else ""
|
||||
await _process_queue(chat_id, user_id, workspace)
|
||||
|
||||
@@ -481,10 +502,9 @@ async def approve_tool(
|
||||
|
||||
# ── Cancel a running task ───────────────────────────────────
|
||||
|
||||
|
||||
@router.post("/{chat_id}/messages/{message_id}/cancel")
|
||||
async def cancel_task_endpoint(
|
||||
chat_id: str, message_id: str, request: Request
|
||||
):
|
||||
async def cancel_task_endpoint(chat_id: str, message_id: str, request: Request):
|
||||
"""Cancel running task, preserve partial output."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
@@ -492,6 +512,7 @@ async def cancel_task_endpoint(
|
||||
raise HTTPException(404, "chat not found")
|
||||
|
||||
from cptr.utils.chat_task import cancel_task
|
||||
|
||||
found = await cancel_task(message_id)
|
||||
|
||||
if not found:
|
||||
@@ -507,6 +528,7 @@ async def cancel_task_endpoint(
|
||||
|
||||
# Process queued messages since this chat may now be idle
|
||||
from cptr.utils.chat_task import _process_queue
|
||||
|
||||
workspace = chat.meta.get("workspace", "") if chat.meta else ""
|
||||
await _process_queue(chat_id, user_id, workspace)
|
||||
|
||||
@@ -515,14 +537,13 @@ async def cancel_task_endpoint(
|
||||
|
||||
# ── Update current branch pointer ──────────────────────────
|
||||
|
||||
|
||||
class UpdateCurrentRequest(BaseModel):
|
||||
message_id: str
|
||||
|
||||
|
||||
@router.post("/{chat_id}/current")
|
||||
async def update_current(
|
||||
chat_id: str, body: UpdateCurrentRequest, request: Request
|
||||
):
|
||||
async def update_current(chat_id: str, body: UpdateCurrentRequest, request: Request):
|
||||
"""Set current_message_id (the active branch leaf)."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
@@ -534,6 +555,7 @@ async def update_current(
|
||||
|
||||
# ── Update message content / output ────────────────────────
|
||||
|
||||
|
||||
class UpdateMessageRequest(BaseModel):
|
||||
content: Optional[str] = None
|
||||
output: Optional[list] = None
|
||||
@@ -561,6 +583,7 @@ async def update_message(
|
||||
|
||||
# ── Create message directly (no task) ──────────────────────
|
||||
|
||||
|
||||
class CreateMessageRequest(BaseModel):
|
||||
parent_id: Optional[str] = None
|
||||
role: str
|
||||
@@ -569,9 +592,7 @@ class CreateMessageRequest(BaseModel):
|
||||
|
||||
|
||||
@router.post("/{chat_id}/messages")
|
||||
async def create_message_endpoint(
|
||||
chat_id: str, body: CreateMessageRequest, request: Request
|
||||
):
|
||||
async def create_message_endpoint(chat_id: str, body: CreateMessageRequest, request: Request):
|
||||
"""Create a message without starting a task (for Save As Copy)."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
@@ -590,6 +611,7 @@ async def create_message_endpoint(
|
||||
await Chat.update_current_message(chat_id, msg.id, now_ms())
|
||||
return {"ok": True, "message_id": msg.id}
|
||||
|
||||
|
||||
async def _chat_has_active_generation(chat_id: str) -> bool:
|
||||
"""Check if any assistant message in this chat has done=False."""
|
||||
messages = await ChatMessage.get_all_by_chat(chat_id)
|
||||
@@ -598,10 +620,9 @@ async def _chat_has_active_generation(chat_id: str) -> bool:
|
||||
|
||||
# ── Queue management ───────────────────────────────────────
|
||||
|
||||
|
||||
@router.post("/{chat_id}/queue/{message_id}/send")
|
||||
async def queue_send_now(
|
||||
chat_id: str, message_id: str, request: Request
|
||||
):
|
||||
async def queue_send_now(chat_id: str, message_id: str, request: Request):
|
||||
"""Cancel current generation, dequeue this message, send it immediately."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
@@ -619,6 +640,7 @@ async def queue_send_now(
|
||||
for m in all_msgs:
|
||||
if m.role == "assistant" and not m.done:
|
||||
from cptr.utils.chat_task import cancel_task
|
||||
|
||||
await cancel_task(m.id)
|
||||
await ChatMessage.update(m.id, done=True)
|
||||
|
||||
@@ -649,13 +671,18 @@ async def queue_send_now(
|
||||
workspace = (chat.meta or {}).get("workspace", "")
|
||||
|
||||
assistant_msg = await ChatMessage.create(
|
||||
chat_id=chat_id, role="assistant", content="",
|
||||
parent_id=message_id, model=model_id,
|
||||
done=False, created_at=now_ms(),
|
||||
chat_id=chat_id,
|
||||
role="assistant",
|
||||
content="",
|
||||
parent_id=message_id,
|
||||
model=model_id,
|
||||
done=False,
|
||||
created_at=now_ms(),
|
||||
)
|
||||
await Chat.update_current_message(chat_id, assistant_msg.id, now_ms())
|
||||
|
||||
from cptr.utils.chat_task import start_task
|
||||
|
||||
start_task(
|
||||
message_id=assistant_msg.id,
|
||||
chat_id=chat_id,
|
||||
@@ -668,9 +695,7 @@ async def queue_send_now(
|
||||
|
||||
|
||||
@router.delete("/{chat_id}/queue/{message_id}")
|
||||
async def queue_delete(
|
||||
chat_id: str, message_id: str, request: Request
|
||||
):
|
||||
async def queue_delete(chat_id: str, message_id: str, request: Request):
|
||||
"""Remove a queued message."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
|
||||
Loaded 100 of 119 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user