feat: add modular web UI features
- Enable `web` command to start UI server - Centralize web server setup and static serving - Implement modular UI for chat and script editor - Refactor Heroprompt UI into its own module - Introduce dynamic theme switching and mobile menu
This commit is contained in:
124
lib/web/ui/static/css/colors.css
Normal file
124
lib/web/ui/static/css/colors.css
Normal file
@@ -0,0 +1,124 @@
|
||||
/* CSS Custom Properties for Theme Colors */
|
||||
|
||||
/* Light Theme (Default) */
|
||||
:root {
|
||||
/* Background Colors */
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f8f9fa;
|
||||
--bg-tertiary: #e9ecef;
|
||||
--bg-dark: #343a40;
|
||||
|
||||
/* Text Colors */
|
||||
--text-primary: #212529;
|
||||
--text-secondary: #6c757d;
|
||||
--text-muted: #6c757d;
|
||||
--text-light: #ffffff;
|
||||
--text-white-50: rgba(255, 255, 255, 0.5);
|
||||
|
||||
/* Border Colors */
|
||||
--border-primary: #e0e0e0;
|
||||
--border-secondary: #dee2e6;
|
||||
|
||||
/* Header Colors */
|
||||
--header-bg: #343a40;
|
||||
--header-text: #ffffff;
|
||||
--header-text-muted: rgba(255, 255, 255, 0.5);
|
||||
|
||||
/* Sidebar Colors */
|
||||
--sidebar-bg: #f8f9fa;
|
||||
--sidebar-border: #e0e0e0;
|
||||
--sidebar-section-text: #6c757d;
|
||||
|
||||
/* Menu Colors */
|
||||
--menu-item-bg: transparent;
|
||||
--menu-item-text: #212529;
|
||||
--menu-item-hover-bg: #e9ecef;
|
||||
--menu-item-hover-text: #212529;
|
||||
--menu-toggle-text: #212529;
|
||||
--menu-chevron-opacity: 0.6;
|
||||
|
||||
/* Card Colors */
|
||||
--card-bg: #ffffff;
|
||||
--card-border: #dee2e6;
|
||||
--card-shadow: rgba(0, 0, 0, 0.125);
|
||||
|
||||
/* Interactive Elements */
|
||||
--link-color: #0d6efd;
|
||||
--link-hover-color: #0a58ca;
|
||||
|
||||
/* Status Colors */
|
||||
--success-color: #198754;
|
||||
--warning-color: #ffc107;
|
||||
--danger-color: #dc3545;
|
||||
--info-color: #0dcaf0;
|
||||
}
|
||||
|
||||
/* Dark Theme */
|
||||
[data-theme="dark"] {
|
||||
/* Background Colors */
|
||||
--bg-primary: #1a1a1a;
|
||||
--bg-secondary: #2d2d2d;
|
||||
--bg-tertiary: #404040;
|
||||
--bg-dark: #000000;
|
||||
|
||||
/* Text Colors */
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #b0b0b0;
|
||||
--text-muted: #888888;
|
||||
--text-light: #ffffff;
|
||||
--text-white-50: rgba(255, 255, 255, 0.5);
|
||||
|
||||
/* Border Colors */
|
||||
--border-primary: #404040;
|
||||
--border-secondary: #555555;
|
||||
|
||||
/* Header Colors */
|
||||
--header-bg: #000000;
|
||||
--header-text: #ffffff;
|
||||
--header-text-muted: rgba(255, 255, 255, 0.5);
|
||||
|
||||
/* Sidebar Colors */
|
||||
--sidebar-bg: #2d2d2d;
|
||||
--sidebar-border: #404040;
|
||||
--sidebar-section-text: #b0b0b0;
|
||||
|
||||
/* Menu Colors */
|
||||
--menu-item-bg: transparent;
|
||||
--menu-item-text: #ffffff;
|
||||
--menu-item-hover-bg: #404040;
|
||||
--menu-item-hover-text: #ffffff;
|
||||
--menu-toggle-text: #ffffff;
|
||||
--menu-chevron-opacity: 0.6;
|
||||
|
||||
/* Card Colors */
|
||||
--card-bg: #2d2d2d;
|
||||
--card-border: #404040;
|
||||
--card-shadow: rgba(0, 0, 0, 0.3);
|
||||
|
||||
/* Interactive Elements */
|
||||
--link-color: #66b3ff;
|
||||
--link-hover-color: #4da6ff;
|
||||
|
||||
/* Status Colors */
|
||||
--success-color: #28a745;
|
||||
--warning-color: #ffc107;
|
||||
--danger-color: #dc3545;
|
||||
--info-color: #17a2b8;
|
||||
}
|
||||
|
||||
/* Theme transition for smooth switching */
|
||||
* {
|
||||
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
/* Utility classes for theme-aware styling */
|
||||
.bg-theme-primary { background-color: var(--bg-primary); }
|
||||
.bg-theme-secondary { background-color: var(--bg-secondary); }
|
||||
.bg-theme-tertiary { background-color: var(--bg-tertiary); }
|
||||
|
||||
.text-theme-primary { color: var(--text-primary); }
|
||||
.text-theme-secondary { color: var(--text-secondary); }
|
||||
.text-theme-muted { color: var(--text-muted); }
|
||||
|
||||
.border-theme-primary { border-color: var(--border-primary); }
|
||||
.border-theme-secondary { border-color: var(--border-secondary); }
|
||||
279
lib/web/ui/static/css/main.css
Normal file
279
lib/web/ui/static/css/main.css
Normal file
@@ -0,0 +1,279 @@
|
||||
/* Main Layout Styles using CSS Custom Properties */
|
||||
|
||||
/* Base Layout */
|
||||
body {
|
||||
padding-top: 44px;
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* Header Styles */
|
||||
.header {
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
font-size: 14px;
|
||||
background-color: var(--header-bg) !important;
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
.header .navbar-brand,
|
||||
.header .text-white {
|
||||
color: var(--header-text) !important;
|
||||
}
|
||||
|
||||
.header .text-white-50 {
|
||||
color: var(--header-text-muted) !important;
|
||||
}
|
||||
|
||||
/* Sidebar Styles */
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 44px;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 260px;
|
||||
overflow-y: auto;
|
||||
background-color: var(--sidebar-bg);
|
||||
border-right: 1px solid var(--sidebar-border);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* Main Content Area */
|
||||
.main {
|
||||
margin-left: 260px;
|
||||
padding: 16px;
|
||||
background-color: var(--bg-primary);
|
||||
min-height: calc(100vh - 44px);
|
||||
}
|
||||
|
||||
/* Menu Styles */
|
||||
.menu-section {
|
||||
font-weight: 600;
|
||||
color: var(--sidebar-section-text);
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-size: 0.875rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.list-group-item {
|
||||
border: 0;
|
||||
padding: 0.35rem 0.75rem;
|
||||
background-color: var(--menu-item-bg);
|
||||
color: var(--menu-item-text);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.list-group-item:hover {
|
||||
background-color: var(--menu-item-hover-bg);
|
||||
color: var(--menu-item-hover-text);
|
||||
}
|
||||
|
||||
.menu-leaf a {
|
||||
color: var(--menu-item-text);
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
padding: 0.25rem 0;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-leaf a:hover {
|
||||
color: var(--link-hover-color);
|
||||
}
|
||||
|
||||
.menu-leaf:hover a {
|
||||
color: var(--link-hover-color);
|
||||
}
|
||||
|
||||
.menu-toggle {
|
||||
text-decoration: none;
|
||||
color: var(--menu-toggle-text);
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-toggle:hover {
|
||||
color: var(--link-hover-color);
|
||||
}
|
||||
|
||||
.menu-toggle .chev {
|
||||
font-size: 10px;
|
||||
opacity: var(--menu-chevron-opacity);
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-toggle[aria-expanded="true"] .chev {
|
||||
transform: rotate(90deg);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
/* Nested menu indentation */
|
||||
.sidebar .ms-2 {
|
||||
margin-left: 1rem !important;
|
||||
}
|
||||
|
||||
.sidebar .ms-2 .list-group-item {
|
||||
padding-left: 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.sidebar .ms-2 .ms-2 .list-group-item {
|
||||
padding-left: 1.5rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
/* Card Styles */
|
||||
.card {
|
||||
background-color: var(--card-bg);
|
||||
border: 1px solid var(--card-border);
|
||||
box-shadow: 0 0.125rem 0.25rem var(--card-shadow);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 0.25rem 0.5rem var(--card-shadow);
|
||||
}
|
||||
|
||||
.card-body {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Content Area Styles */
|
||||
.container-fluid {
|
||||
background-color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.mb-3 h5 {
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.text-muted {
|
||||
color: var(--text-muted) !important;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Code elements */
|
||||
code {
|
||||
background-color: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.875em;
|
||||
}
|
||||
|
||||
/* Theme Toggle Button */
|
||||
.theme-toggle {
|
||||
position: fixed;
|
||||
top: 8px;
|
||||
right: 16px;
|
||||
z-index: 1050;
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
color: var(--text-primary);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background-color: var(--bg-tertiary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar.show {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.main {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.mobile-menu-toggle {
|
||||
display: block;
|
||||
position: fixed;
|
||||
top: 8px;
|
||||
left: 16px;
|
||||
z-index: 1051;
|
||||
background-color: var(--header-bg);
|
||||
border: 1px solid var(--border-primary);
|
||||
color: var(--header-text);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 769px) {
|
||||
.mobile-menu-toggle {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scrollbar Styling for Webkit browsers */
|
||||
.sidebar::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-track {
|
||||
background-color: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-thumb {
|
||||
background-color: var(--border-primary);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-thumb:hover {
|
||||
background-color: var(--border-secondary);
|
||||
}
|
||||
|
||||
/* Focus styles for accessibility */
|
||||
.menu-toggle:focus,
|
||||
.menu-leaf a:focus,
|
||||
.theme-toggle:focus {
|
||||
outline: 2px solid var(--link-color);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* Animation for collapsible menu items */
|
||||
.collapse {
|
||||
transition: height 0.3s ease;
|
||||
}
|
||||
|
||||
/* Loading state */
|
||||
.loading {
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Print styles */
|
||||
@media print {
|
||||
.sidebar,
|
||||
.header,
|
||||
.theme-toggle {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.main {
|
||||
margin-left: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
}
|
||||
236
lib/web/ui/static/js/theme.js
Normal file
236
lib/web/ui/static/js/theme.js
Normal file
@@ -0,0 +1,236 @@
|
||||
/**
|
||||
* Theme Management for Admin UI
|
||||
* Handles light/dark theme switching with localStorage persistence
|
||||
*/
|
||||
|
||||
class ThemeManager {
|
||||
constructor() {
|
||||
this.currentTheme = this.getStoredTheme() || this.getPreferredTheme();
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize theme manager
|
||||
*/
|
||||
init() {
|
||||
this.applyTheme(this.currentTheme);
|
||||
this.createThemeToggle();
|
||||
this.bindEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme from localStorage
|
||||
*/
|
||||
getStoredTheme() {
|
||||
return localStorage.getItem('admin-theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user's preferred theme from system
|
||||
*/
|
||||
getPreferredTheme() {
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
return 'light';
|
||||
}
|
||||
|
||||
/**
|
||||
* Store theme preference
|
||||
*/
|
||||
setStoredTheme(theme) {
|
||||
localStorage.setItem('admin-theme', theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply theme to document
|
||||
*/
|
||||
applyTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
this.currentTheme = theme;
|
||||
this.setStoredTheme(theme);
|
||||
this.updateToggleButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle between light and dark themes
|
||||
*/
|
||||
toggleTheme() {
|
||||
const newTheme = this.currentTheme === 'light' ? 'dark' : 'light';
|
||||
this.applyTheme(newTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create theme toggle button
|
||||
*/
|
||||
createThemeToggle() {
|
||||
const toggle = document.createElement('button');
|
||||
toggle.className = 'theme-toggle';
|
||||
toggle.id = 'theme-toggle';
|
||||
toggle.setAttribute('aria-label', 'Toggle theme');
|
||||
toggle.setAttribute('title', 'Toggle light/dark theme');
|
||||
|
||||
document.body.appendChild(toggle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update toggle button text and icon
|
||||
*/
|
||||
updateToggleButton() {
|
||||
const toggle = document.getElementById('theme-toggle');
|
||||
if (toggle) {
|
||||
const icon = this.currentTheme === 'light' ? '🌙' : '☀️';
|
||||
const text = this.currentTheme === 'light' ? 'Dark' : 'Light';
|
||||
toggle.innerHTML = `${icon} ${text}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind event listeners
|
||||
*/
|
||||
bindEvents() {
|
||||
// Theme toggle button click
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.id === 'theme-toggle') {
|
||||
this.toggleTheme();
|
||||
}
|
||||
});
|
||||
|
||||
// Keyboard shortcut (Ctrl/Cmd + Shift + T)
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'T') {
|
||||
e.preventDefault();
|
||||
this.toggleTheme();
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for system theme changes
|
||||
if (window.matchMedia) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||
if (!this.getStoredTheme()) {
|
||||
this.applyTheme(e.matches ? 'dark' : 'light');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current theme
|
||||
*/
|
||||
getCurrentTheme() {
|
||||
return this.currentTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set specific theme
|
||||
*/
|
||||
setTheme(theme) {
|
||||
if (theme === 'light' || theme === 'dark') {
|
||||
this.applyTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mobile Menu Management
|
||||
*/
|
||||
class MobileMenuManager {
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.createMobileToggle();
|
||||
this.bindEvents();
|
||||
}
|
||||
|
||||
createMobileToggle() {
|
||||
const toggle = document.createElement('button');
|
||||
toggle.className = 'mobile-menu-toggle';
|
||||
toggle.id = 'mobile-menu-toggle';
|
||||
toggle.innerHTML = '☰ Menu';
|
||||
toggle.setAttribute('aria-label', 'Toggle navigation menu');
|
||||
|
||||
document.body.appendChild(toggle);
|
||||
}
|
||||
|
||||
bindEvents() {
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.id === 'mobile-menu-toggle') {
|
||||
this.toggleMobileMenu();
|
||||
}
|
||||
});
|
||||
|
||||
// Close menu when clicking outside
|
||||
document.addEventListener('click', (e) => {
|
||||
const sidebar = document.querySelector('.sidebar');
|
||||
const toggle = document.getElementById('mobile-menu-toggle');
|
||||
|
||||
if (sidebar && sidebar.classList.contains('show') &&
|
||||
!sidebar.contains(e.target) &&
|
||||
e.target !== toggle) {
|
||||
this.closeMobileMenu();
|
||||
}
|
||||
});
|
||||
|
||||
// Close menu on escape key
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
this.closeMobileMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleMobileMenu() {
|
||||
const sidebar = document.querySelector('.sidebar');
|
||||
if (sidebar) {
|
||||
sidebar.classList.toggle('show');
|
||||
}
|
||||
}
|
||||
|
||||
closeMobileMenu() {
|
||||
const sidebar = document.querySelector('.sidebar');
|
||||
if (sidebar) {
|
||||
sidebar.classList.remove('show');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize when DOM is ready
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Initialize theme manager
|
||||
window.themeManager = new ThemeManager();
|
||||
|
||||
// Initialize mobile menu manager
|
||||
window.mobileMenuManager = new MobileMenuManager();
|
||||
|
||||
// Add smooth scrolling to menu links
|
||||
document.querySelectorAll('.menu-leaf a').forEach(link => {
|
||||
link.addEventListener('click', (e) => {
|
||||
// Close mobile menu when link is clicked
|
||||
window.mobileMenuManager.closeMobileMenu();
|
||||
});
|
||||
});
|
||||
|
||||
// Enhance menu collapse animations
|
||||
document.querySelectorAll('[data-bs-toggle="collapse"]').forEach(toggle => {
|
||||
toggle.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const target = document.querySelector(toggle.getAttribute('href'));
|
||||
if (target) {
|
||||
const isExpanded = toggle.getAttribute('aria-expanded') === 'true';
|
||||
toggle.setAttribute('aria-expanded', !isExpanded);
|
||||
target.classList.toggle('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Export for external use
|
||||
*/
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = { ThemeManager, MobileMenuManager };
|
||||
}
|
||||
Reference in New Issue
Block a user