feat(client): build flat multi-theme ES2020 UI shell, Vault/Config editors, and esbuild pipeline

This commit is contained in:
tyuXX 2026-11-26 18:27:27 +00:00
parent 9cedd83a07
commit ce7e42fbc2
16 changed files with 2910 additions and 0 deletions

97
src/client/ts/state.ts Normal file
View file

@ -0,0 +1,97 @@
import type {
ConfigError,
ConfigWarning,
VaultState,
} from '../../shared/ws-protocol.js';
export type RouteId =
| 'dashboard'
| 'systems'
| 'terminal'
| 'sftp'
| 'workflows'
| 'alerts'
| 'config'
| 'vault'
| 'settings';
export interface OverviewFileEntry {
filePath: string;
entityType: string;
id?: string;
hasError: boolean;
warningCount: number;
}
export interface ConfigOverview {
files: OverviewFileEntry[];
diagnostics: { warnings: ConfigWarning[]; errors: ConfigError[] };
servers: Array<Record<string, unknown>>;
systems: Array<Record<string, unknown>>;
workflows: Array<Record<string, unknown>>;
snippets: { snippets?: Array<Record<string, unknown>> };
alerts: {
channels?: Array<Record<string, unknown>>;
rules?: Array<Record<string, unknown>>;
maintenanceWindows?: Array<Record<string, unknown>>;
};
settings: Record<string, unknown>;
}
export interface ClientState {
bootstrapped: boolean;
authenticated: boolean;
vaultState: VaultState;
isPanicLocked: boolean;
safeMode: boolean;
defaultMobileSafeMode: boolean;
elevatedUntil: number | null;
theme: string;
route: RouteId;
overview: ConfigOverview | null;
}
export const SAFE_MODE_STORAGE_KEY = 'gcoord_device_safe_mode';
export const THEME_STORAGE_KEY = 'gcoord_theme';
export function initialDeviceSafeMode(defaultMobileSafeMode: boolean): boolean {
const stored = localStorage.getItem(SAFE_MODE_STORAGE_KEY);
if (stored === '1') return true;
if (stored === '0') return false;
return defaultMobileSafeMode && window.innerWidth < 768;
}
export function applyTheme(theme: string): void {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem(THEME_STORAGE_KEY, theme);
}
export function el<K extends keyof HTMLElementTagNameMap>(
tag: K,
attrs: Record<string, string | boolean | number | undefined> = {},
...children: Array<Node | string>
): HTMLElementTagNameMap[K] {
const node = document.createElement(tag);
for (const [k, v] of Object.entries(attrs)) {
if (v === undefined || v === false) continue;
if (v === true) {
node.setAttribute(k, '');
} else {
node.setAttribute(k, String(v));
}
}
for (const child of children) {
node.append(typeof child === 'string' ? document.createTextNode(child) : child);
}
return node;
}
export function fmtTime(ts: number | string | null | undefined): string {
if (!ts) return '—';
const d = new Date(ts);
return Number.isNaN(d.getTime()) ? '—' : d.toISOString().replace('T', ' ').slice(0, 19);
}
export function extractErrorMessage(err: unknown): string {
return err instanceof Error ? err.message : String(err);
}