update
This commit is contained in:
2
ts_web/elements/index.ts
Normal file
2
ts_web/elements/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './opencdn-mainpage.js';
|
||||
export * from './opencdn-peekpage.js';
|
||||
358
ts_web/elements/opencdn-mainpage.ts
Normal file
358
ts_web/elements/opencdn-mainpage.ts
Normal file
@@ -0,0 +1,358 @@
|
||||
import {
|
||||
DeesElement,
|
||||
property,
|
||||
html,
|
||||
customElement,
|
||||
type TemplateResult,
|
||||
css,
|
||||
state,
|
||||
} from '@design.estate/dees-element';
|
||||
import '@design.estate/dees-catalog';
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'opencdn-mainpage': OpencdnMainpage;
|
||||
}
|
||||
}
|
||||
|
||||
@customElement('opencdn-mainpage')
|
||||
export class OpencdnMainpage extends DeesElement {
|
||||
@property({ type: String })
|
||||
public accessor version: string = '1.0.0';
|
||||
|
||||
@property({ type: String })
|
||||
public accessor mode: string = 'prod';
|
||||
|
||||
@property({ type: Array })
|
||||
public accessor allowedPackages: string[] = [];
|
||||
|
||||
@state()
|
||||
private accessor currentView: 'home' | 'peek' | 'docs' = 'home';
|
||||
|
||||
// Shadcn-like color palette
|
||||
public static styles = [
|
||||
css`
|
||||
:host {
|
||||
--background: #09090b;
|
||||
--foreground: #fafafa;
|
||||
--card: #09090b;
|
||||
--card-foreground: #fafafa;
|
||||
--muted: #27272a;
|
||||
--muted-foreground: #a1a1aa;
|
||||
--border: #27272a;
|
||||
--input: #27272a;
|
||||
--primary: #fafafa;
|
||||
--primary-foreground: #18181b;
|
||||
--secondary: #27272a;
|
||||
--secondary-foreground: #fafafa;
|
||||
--accent: #27272a;
|
||||
--accent-foreground: #fafafa;
|
||||
--ring: #d4d4d8;
|
||||
--radius: 0.5rem;
|
||||
|
||||
display: block;
|
||||
min-height: 100vh;
|
||||
background: var(--background);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
||||
color: var(--foreground);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
padding: 60px 24px;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.logo-icon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
background: var(--foreground);
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logo-icon dees-icon {
|
||||
--dees-icon-color: var(--background);
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
color: var(--foreground);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.tagline {
|
||||
color: var(--muted-foreground);
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.usage-box {
|
||||
background: var(--muted);
|
||||
border-radius: var(--radius);
|
||||
padding: 20px 24px;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.usage-title {
|
||||
color: var(--muted-foreground);
|
||||
font-size: 14px;
|
||||
margin-bottom: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.usage-code {
|
||||
font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, monospace;
|
||||
font-size: 14px;
|
||||
color: var(--foreground);
|
||||
background: var(--background);
|
||||
padding: 14px 18px;
|
||||
border-radius: calc(var(--radius) - 2px);
|
||||
text-align: center;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.nav-buttons dees-button {
|
||||
--dees-button-width: auto;
|
||||
}
|
||||
|
||||
.packages-section {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.packages-title {
|
||||
color: var(--foreground);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.packages-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.package-tag {
|
||||
background: var(--secondary);
|
||||
color: var(--muted-foreground);
|
||||
padding: 8px 14px;
|
||||
border-radius: calc(var(--radius) - 2px);
|
||||
font-family: 'SF Mono', 'Fira Code', monospace;
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--border);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.package-tag:hover {
|
||||
background: var(--accent);
|
||||
color: var(--foreground);
|
||||
border-color: var(--ring);
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 32px;
|
||||
margin-top: auto;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 13px;
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #22c55e;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #22c55e;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
.version {
|
||||
font-family: 'SF Mono', monospace;
|
||||
color: var(--muted-foreground);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mode-badge {
|
||||
padding: 4px 10px;
|
||||
border-radius: calc(var(--radius) - 2px);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.mode-badge.dev {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
.mode-badge.prod {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.footer-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.footer-link {
|
||||
color: var(--muted-foreground);
|
||||
text-decoration: none;
|
||||
transition: color 0.15s ease;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.footer-link:hover {
|
||||
color: var(--foreground);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: var(--muted-foreground);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="logo">
|
||||
<div class="logo-icon">
|
||||
<dees-icon .icon=${'lucide:package'} .iconSize=${24}></dees-icon>
|
||||
</div>
|
||||
<span class="logo-text">opencdn</span>
|
||||
</div>
|
||||
<p class="tagline">Serve files directly from npm packages</p>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="usage-box">
|
||||
<div class="usage-title">Request files using:</div>
|
||||
<div class="usage-code">/@scope/package/path/to/file.js?version=1.0.0</div>
|
||||
</div>
|
||||
|
||||
${this.mode === 'dev' ? html`
|
||||
<div class="nav-buttons">
|
||||
<dees-button type="highlighted" @click=${() => window.location.href = '/peek/'}>
|
||||
<dees-icon .icon=${'lucide:folder-open'} .iconSize=${16} slot="iconLeft"></dees-icon>
|
||||
Browse Packages
|
||||
</dees-button>
|
||||
<dees-button @click=${() => window.location.href = '/readme/'}>
|
||||
<dees-icon .icon=${'lucide:book-open'} .iconSize=${16} slot="iconLeft"></dees-icon>
|
||||
Documentation
|
||||
</dees-button>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${this.allowedPackages.length > 0 ? html`
|
||||
<div class="packages-section">
|
||||
<div class="packages-title">
|
||||
<dees-icon .icon=${'lucide:boxes'} .iconSize=${16}></dees-icon>
|
||||
Available Packages
|
||||
</div>
|
||||
<div class="packages-list">
|
||||
${this.allowedPackages.map(pkg => html`
|
||||
<span class="package-tag" @click=${() => window.location.href = `/peek/${pkg}`}>
|
||||
${pkg}
|
||||
</span>
|
||||
`)}
|
||||
</div>
|
||||
</div>
|
||||
` : html`
|
||||
<div class="empty-state">
|
||||
<dees-icon .icon=${'lucide:package-x'} .iconSize=${48} style="opacity: 0.5;"></dees-icon>
|
||||
<p>No packages configured</p>
|
||||
</div>
|
||||
`}
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<span class="status">
|
||||
<span class="status-dot"></span>
|
||||
Online
|
||||
</span>
|
||||
<span class="version">v${this.version}</span>
|
||||
<span class="mode-badge ${this.mode}">${this.mode}</span>
|
||||
</div>
|
||||
<div class="footer-right">
|
||||
<a href="https://task.vc" target="_blank" class="footer-link">Task Venture Capital</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
682
ts_web/elements/opencdn-peekpage.ts
Normal file
682
ts_web/elements/opencdn-peekpage.ts
Normal file
@@ -0,0 +1,682 @@
|
||||
import {
|
||||
DeesElement,
|
||||
property,
|
||||
html,
|
||||
customElement,
|
||||
type TemplateResult,
|
||||
cssManager,
|
||||
css,
|
||||
state,
|
||||
} from '@design.estate/dees-element';
|
||||
import '@design.estate/dees-catalog';
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'opencdn-peekpage': OpencdnPeekpage;
|
||||
}
|
||||
}
|
||||
|
||||
interface IFileNode {
|
||||
name: string;
|
||||
path: string;
|
||||
isFile: boolean;
|
||||
children?: IFileNode[];
|
||||
}
|
||||
|
||||
@customElement('opencdn-peekpage')
|
||||
export class OpencdnPeekpage extends DeesElement {
|
||||
@property({ type: String })
|
||||
public accessor packageName: string = '';
|
||||
|
||||
@property({ type: String })
|
||||
public accessor version: string = '';
|
||||
|
||||
@property({ type: Array })
|
||||
public accessor allowedPackages: string[] = [];
|
||||
|
||||
@state()
|
||||
private accessor files: string[] = [];
|
||||
|
||||
@state()
|
||||
private accessor fileTree: IFileNode[] = [];
|
||||
|
||||
@state()
|
||||
private accessor selectedFile: string | null = null;
|
||||
|
||||
@state()
|
||||
private accessor fileContent: string = '';
|
||||
|
||||
@state()
|
||||
private accessor loading: boolean = false;
|
||||
|
||||
@state()
|
||||
private accessor searchQuery: string = '';
|
||||
|
||||
@state()
|
||||
private accessor availableVersions: string[] = [];
|
||||
|
||||
@state()
|
||||
private accessor expandedFolders: Set<string> = new Set();
|
||||
|
||||
public static styles = [
|
||||
cssManager.defaultStyles,
|
||||
css`
|
||||
:host {
|
||||
--background: #09090b;
|
||||
--foreground: #fafafa;
|
||||
--muted: #27272a;
|
||||
--muted-foreground: #a1a1aa;
|
||||
--border: #27272a;
|
||||
--primary: #fafafa;
|
||||
--primary-foreground: #18181b;
|
||||
--secondary: #27272a;
|
||||
--ring: #d4d4d8;
|
||||
|
||||
display: block;
|
||||
height: 100vh;
|
||||
background: var(--background);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
||||
color: var(--foreground);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 12px 20px;
|
||||
background: var(--background);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.header-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-weight: 600;
|
||||
color: var(--foreground);
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.header-logo:hover {
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.header-sep {
|
||||
color: var(--border);
|
||||
}
|
||||
|
||||
.header-package {
|
||||
font-weight: 600;
|
||||
color: var(--foreground);
|
||||
}
|
||||
|
||||
.header-version {
|
||||
padding: 4px 10px;
|
||||
background: var(--muted);
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.header-spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.version-select {
|
||||
padding: 8px 12px;
|
||||
background: var(--muted);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
color: var(--foreground);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
.version-select:hover,
|
||||
.version-select:focus {
|
||||
border-color: var(--ring);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Main Content */
|
||||
.main {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
.sidebar {
|
||||
width: 300px;
|
||||
background: var(--background);
|
||||
border-right: 1px solid var(--border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 12px 16px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--muted-foreground);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.file-tree {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
/* Tree Items */
|
||||
.tree-folder {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.folder-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: var(--foreground);
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.folder-header:hover {
|
||||
background: var(--muted);
|
||||
}
|
||||
|
||||
.folder-chevron {
|
||||
margin-left: auto;
|
||||
font-size: 10px;
|
||||
color: var(--muted-foreground);
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
|
||||
.folder-chevron.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.folder-children {
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
.tree-file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: var(--muted-foreground);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.tree-file:hover {
|
||||
background: var(--muted);
|
||||
color: var(--foreground);
|
||||
}
|
||||
|
||||
.tree-file.active {
|
||||
background: var(--primary);
|
||||
color: var(--primary-foreground);
|
||||
}
|
||||
|
||||
/* Content Area */
|
||||
.content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 20px;
|
||||
background: var(--background);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.content-path {
|
||||
font-family: 'SF Mono', 'Fira Code', monospace;
|
||||
font-size: 13px;
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.content-path span {
|
||||
color: var(--foreground);
|
||||
}
|
||||
|
||||
.content-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Code Viewer */
|
||||
.code-viewer {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
background: var(--background);
|
||||
}
|
||||
|
||||
.code-viewer pre {
|
||||
margin: 0;
|
||||
padding: 16px 20px;
|
||||
font-family: 'SF Mono', 'Fira Code', monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
color: var(--foreground);
|
||||
}
|
||||
|
||||
/* Empty State */
|
||||
.empty-state {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--muted-foreground);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* Package List View */
|
||||
.package-list-container {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
padding: 60px 24px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 14px 16px 14px 44px;
|
||||
background: var(--muted);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--foreground);
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
border-color: var(--ring);
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
left: 14px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.package-count {
|
||||
color: var(--muted-foreground);
|
||||
font-size: 13px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.package-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.package-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px 20px;
|
||||
background: var(--muted);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--foreground);
|
||||
font-family: 'SF Mono', 'Fira Code', monospace;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.package-link:hover {
|
||||
background: var(--primary);
|
||||
border-color: var(--primary);
|
||||
color: var(--primary-foreground);
|
||||
}
|
||||
|
||||
.no-results {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
/* Scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--muted);
|
||||
border-radius: 4px;
|
||||
}
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #3f3f46;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
async connectedCallback() {
|
||||
super.connectedCallback();
|
||||
// Parse URL to get package name
|
||||
const path = window.location.pathname;
|
||||
if (path.startsWith('/peek/') && path.length > 6) {
|
||||
const parts = path.slice(6).split('/');
|
||||
if (parts[0]?.startsWith('@') && parts[1]) {
|
||||
this.packageName = `${parts[0]}/${parts[1]}`;
|
||||
await this.loadPackageFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async loadPackageFiles() {
|
||||
if (!this.packageName) return;
|
||||
|
||||
this.loading = true;
|
||||
try {
|
||||
// Fetch file list from API
|
||||
const response = await fetch(`/api/files/${this.packageName}?version=${this.version}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
this.files = data.files || [];
|
||||
this.availableVersions = data.versions || [];
|
||||
this.fileTree = this.buildFileTree(this.files);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load package files:', err);
|
||||
}
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
private buildFileTree(files: string[]): IFileNode[] {
|
||||
const root: IFileNode[] = [];
|
||||
|
||||
for (const filePath of files) {
|
||||
const parts = filePath.split('/').filter(Boolean);
|
||||
let currentLevel = root;
|
||||
let currentPath = '';
|
||||
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const part = parts[i];
|
||||
currentPath += '/' + part;
|
||||
const isFile = i === parts.length - 1;
|
||||
|
||||
let existing = currentLevel.find(n => n.name === part);
|
||||
if (!existing) {
|
||||
existing = {
|
||||
name: part,
|
||||
path: currentPath,
|
||||
isFile,
|
||||
children: isFile ? undefined : [],
|
||||
};
|
||||
currentLevel.push(existing);
|
||||
}
|
||||
|
||||
if (!isFile && existing.children) {
|
||||
currentLevel = existing.children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort: folders first, then files, alphabetically
|
||||
const sortNodes = (nodes: IFileNode[]) => {
|
||||
nodes.sort((a, b) => {
|
||||
if (a.isFile && !b.isFile) return 1;
|
||||
if (!a.isFile && b.isFile) return -1;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
for (const node of nodes) {
|
||||
if (node.children) sortNodes(node.children);
|
||||
}
|
||||
};
|
||||
sortNodes(root);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private toggleFolder(path: string) {
|
||||
const newSet = new Set(this.expandedFolders);
|
||||
if (newSet.has(path)) {
|
||||
newSet.delete(path);
|
||||
} else {
|
||||
newSet.add(path);
|
||||
}
|
||||
this.expandedFolders = newSet;
|
||||
}
|
||||
|
||||
private async selectFile(filePath: string) {
|
||||
this.selectedFile = filePath;
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
const url = `/${this.packageName}${filePath}?version=${this.version}`;
|
||||
const response = await fetch(url);
|
||||
this.fileContent = await response.text();
|
||||
} catch (err) {
|
||||
this.fileContent = 'Failed to load file';
|
||||
}
|
||||
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
private navigateToPackage(pkg: string) {
|
||||
window.location.href = `/peek/${pkg}`;
|
||||
}
|
||||
|
||||
private get filteredPackages(): string[] {
|
||||
if (!this.searchQuery) return this.allowedPackages;
|
||||
const query = this.searchQuery.toLowerCase();
|
||||
return this.allowedPackages.filter(pkg => pkg.toLowerCase().includes(query));
|
||||
}
|
||||
|
||||
private renderTreeNode(node: IFileNode): TemplateResult {
|
||||
if (node.isFile) {
|
||||
return html`
|
||||
<div
|
||||
class="tree-file ${this.selectedFile === node.path ? 'active' : ''}"
|
||||
@click=${() => this.selectFile(node.path)}
|
||||
>
|
||||
<dees-icon .icon=${'lucide:file'} .iconSize=${14}></dees-icon>
|
||||
${node.name}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
const isExpanded = this.expandedFolders.has(node.path);
|
||||
return html`
|
||||
<div class="tree-folder">
|
||||
<div class="folder-header" @click=${() => this.toggleFolder(node.path)}>
|
||||
<dees-icon .icon=${isExpanded ? 'lucide:folder-open' : 'lucide:folder'} .iconSize=${14}></dees-icon>
|
||||
${node.name}
|
||||
<span class="folder-chevron ${isExpanded ? 'open' : ''}">▶</span>
|
||||
</div>
|
||||
${isExpanded && node.children ? html`
|
||||
<div class="folder-children">
|
||||
${node.children.map(child => this.renderTreeNode(child))}
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private renderPackageList(): TemplateResult {
|
||||
const filtered = this.filteredPackages;
|
||||
|
||||
return html`
|
||||
<div class="package-list-container">
|
||||
<div class="header-logo" @click=${() => window.location.href = '/'}>
|
||||
<dees-icon .icon=${'lucide:package'} .iconSize=${24}></dees-icon>
|
||||
opencdn
|
||||
</div>
|
||||
|
||||
<h1 class="page-title" style="margin-top: 32px;">Browse Packages</h1>
|
||||
|
||||
<div class="search-box">
|
||||
<dees-icon class="search-icon" .icon=${'lucide:search'} .iconSize=${16}></dees-icon>
|
||||
<input
|
||||
type="text"
|
||||
class="search-input"
|
||||
placeholder="Search packages..."
|
||||
.value=${this.searchQuery}
|
||||
@input=${(e: Event) => this.searchQuery = (e.target as HTMLInputElement).value}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="package-count">
|
||||
${filtered.length === this.allowedPackages.length
|
||||
? `${this.allowedPackages.length} package${this.allowedPackages.length !== 1 ? 's' : ''} available`
|
||||
: `${filtered.length} of ${this.allowedPackages.length} packages`}
|
||||
</div>
|
||||
|
||||
${filtered.length > 0 ? html`
|
||||
<div class="package-list">
|
||||
${filtered.map(pkg => html`
|
||||
<div class="package-link" @click=${() => this.navigateToPackage(pkg)}>
|
||||
<dees-icon .icon=${'lucide:package'} .iconSize=${16}></dees-icon>
|
||||
${pkg}
|
||||
</div>
|
||||
`)}
|
||||
</div>
|
||||
` : html`
|
||||
<div class="no-results">No packages found matching your search.</div>
|
||||
`}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private renderFileBrowser(): TemplateResult {
|
||||
return html`
|
||||
<div class="app">
|
||||
<header class="header">
|
||||
<div class="header-logo" @click=${() => window.location.href = '/'}>
|
||||
<dees-icon .icon=${'lucide:package'} .iconSize=${20}></dees-icon>
|
||||
opencdn
|
||||
</div>
|
||||
<span class="header-sep">/</span>
|
||||
<span class="header-package">${this.packageName}</span>
|
||||
<span class="header-version">${this.version || 'latest'}</span>
|
||||
<div class="header-spacer"></div>
|
||||
${this.availableVersions.length > 0 ? html`
|
||||
<select
|
||||
class="version-select"
|
||||
@change=${(e: Event) => {
|
||||
this.version = (e.target as HTMLSelectElement).value;
|
||||
this.loadPackageFiles();
|
||||
}}
|
||||
>
|
||||
<option value="">latest</option>
|
||||
${this.availableVersions.map(v => html`
|
||||
<option value=${v} ?selected=${v === this.version}>${v}</option>
|
||||
`)}
|
||||
</select>
|
||||
` : ''}
|
||||
<dees-button @click=${() => window.location.href = '/peek/'}>
|
||||
<dees-icon .icon=${'lucide:arrow-left'} .iconSize=${14} slot="iconLeft"></dees-icon>
|
||||
All Packages
|
||||
</dees-button>
|
||||
</header>
|
||||
|
||||
<div class="main">
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-header">Files (${this.files.length})</div>
|
||||
<div class="file-tree">
|
||||
${this.fileTree.map(node => this.renderTreeNode(node))}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main class="content">
|
||||
${this.selectedFile ? html`
|
||||
<div class="content-header">
|
||||
<div class="content-path">
|
||||
<span>${this.selectedFile}</span>
|
||||
</div>
|
||||
<div class="content-actions">
|
||||
<dees-button @click=${() => {
|
||||
const url = `/${this.packageName}${this.selectedFile}?version=${this.version}`;
|
||||
window.open(url, '_blank');
|
||||
}}>
|
||||
<dees-icon .icon=${'lucide:external-link'} .iconSize=${14} slot="iconLeft"></dees-icon>
|
||||
Raw
|
||||
</dees-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="code-viewer">
|
||||
${this.loading ? html`
|
||||
<div class="empty-state">
|
||||
<dees-spinner></dees-spinner>
|
||||
</div>
|
||||
` : html`
|
||||
<pre>${this.fileContent}</pre>
|
||||
`}
|
||||
</div>
|
||||
` : html`
|
||||
<div class="empty-state">
|
||||
<dees-icon .icon=${'lucide:file-text'} .iconSize=${48} style="opacity: 0.5;"></dees-icon>
|
||||
<div>Select a file to view its contents</div>
|
||||
</div>
|
||||
`}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
public render(): TemplateResult {
|
||||
if (this.packageName) {
|
||||
return this.renderFileBrowser();
|
||||
}
|
||||
return this.renderPackageList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user