Initial commit: scaffold stack.gallery catalog frontend
This commit is contained in:
327
ts_web/elements/sg-repository-detail-view.ts
Normal file
327
ts_web/elements/sg-repository-detail-view.ts
Normal file
@@ -0,0 +1,327 @@
|
||||
import {
|
||||
DeesElement,
|
||||
customElement,
|
||||
html,
|
||||
css,
|
||||
cssManager,
|
||||
property,
|
||||
type TemplateResult,
|
||||
} from '@design.estate/dees-element';
|
||||
import type { ISgRepository, ISgPackage } from '../interfaces.js';
|
||||
import './sg-protocol-badge.js';
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'sg-repository-detail-view': SgRepositoryDetailView;
|
||||
}
|
||||
}
|
||||
|
||||
@customElement('sg-repository-detail-view')
|
||||
export class SgRepositoryDetailView extends DeesElement {
|
||||
public static demo = () => html`
|
||||
<div style="padding: 24px; max-width: 1200px; background: #09090b;">
|
||||
<sg-repository-detail-view
|
||||
.repository=${{
|
||||
id: 'r1',
|
||||
organizationId: 'org1',
|
||||
name: 'npm-packages',
|
||||
description: 'Organization NPM package repository for internal and public libraries.',
|
||||
protocol: 'npm',
|
||||
visibility: 'public',
|
||||
isPublic: true,
|
||||
packageCount: 5,
|
||||
createdAt: '2025-06-15',
|
||||
}}
|
||||
.packages=${[
|
||||
{ id: 'p1', name: '@myorg/web-framework', protocol: 'npm', organizationId: 'org1', repositoryId: 'r1', latestVersion: '3.2.1', isPrivate: false, downloadCount: 12400, updatedAt: '2026-03-19T10:30:00Z', description: 'Modern web framework' },
|
||||
{ id: 'p2', name: '@myorg/auth-client', protocol: 'npm', organizationId: 'org1', repositoryId: 'r1', latestVersion: '1.0.8', isPrivate: false, downloadCount: 5200, updatedAt: '2026-03-18T14:00:00Z', description: 'Authentication client library' },
|
||||
{ id: 'p3', name: '@myorg/data-utils', protocol: 'npm', organizationId: 'org1', repositoryId: 'r1', latestVersion: '2.4.0', isPrivate: true, downloadCount: 890, updatedAt: '2026-03-15T08:45:00Z' },
|
||||
]}
|
||||
></sg-repository-detail-view>
|
||||
</div>
|
||||
`;
|
||||
|
||||
public static demoGroups = ['Repositories'];
|
||||
|
||||
@property({ type: Object })
|
||||
public accessor repository: ISgRepository = {
|
||||
id: '',
|
||||
organizationId: '',
|
||||
name: '',
|
||||
protocol: 'npm',
|
||||
visibility: 'public',
|
||||
isPublic: true,
|
||||
packageCount: 0,
|
||||
createdAt: '',
|
||||
};
|
||||
|
||||
@property({ type: Array })
|
||||
public accessor packages: ISgPackage[] = [];
|
||||
|
||||
public static styles = [
|
||||
cssManager.defaultStyles,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
color: ${cssManager.bdTheme('#111', '#fff')};
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 13px;
|
||||
color: ${cssManager.bdTheme('#666', '#999')};
|
||||
cursor: pointer;
|
||||
transition: color 150ms ease;
|
||||
}
|
||||
|
||||
.back-btn:hover {
|
||||
color: ${cssManager.bdTheme('#111', '#fff')};
|
||||
}
|
||||
|
||||
/* Repo header */
|
||||
.repo-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 24px;
|
||||
background: ${cssManager.bdTheme('#fff', '#111')};
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333')};
|
||||
}
|
||||
|
||||
.repo-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.repo-name {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.repo-description {
|
||||
font-size: 14px;
|
||||
color: ${cssManager.bdTheme('#666', '#aaa')};
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.repo-meta {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
font-size: 13px;
|
||||
color: ${cssManager.bdTheme('#888', '#777')};
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.visibility-tag {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
padding: 2px 8px;
|
||||
}
|
||||
|
||||
.visibility-tag.public {
|
||||
background: rgba(34, 197, 94, 0.15);
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
.visibility-tag.private {
|
||||
background: rgba(239, 68, 68, 0.15);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.visibility-tag.internal {
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
/* Package list */
|
||||
.packages-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.package-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333')};
|
||||
}
|
||||
|
||||
.package-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 16px;
|
||||
background: ${cssManager.bdTheme('#fff', '#111')};
|
||||
border-bottom: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333')};
|
||||
cursor: pointer;
|
||||
transition: background 100ms ease;
|
||||
}
|
||||
|
||||
.package-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.package-row:hover {
|
||||
background: ${cssManager.bdTheme('#fafafa', '#1a1a1a')};
|
||||
}
|
||||
|
||||
.package-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.package-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
color: ${cssManager.bdTheme('#111', '#fff')};
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.package-description {
|
||||
font-size: 13px;
|
||||
color: ${cssManager.bdTheme('#666', '#aaa')};
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.package-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.version-tag {
|
||||
font-size: 12px;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
color: ${cssManager.bdTheme('#666', '#999')};
|
||||
background: ${cssManager.bdTheme('#f5f5f5', '#1a1a1a')};
|
||||
padding: 2px 8px;
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333')};
|
||||
}
|
||||
|
||||
.download-count {
|
||||
font-size: 12px;
|
||||
color: ${cssManager.bdTheme('#888', '#777')};
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
.private-badge {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
padding: 1px 5px;
|
||||
background: rgba(239, 68, 68, 0.15);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 48px 32px;
|
||||
font-size: 14px;
|
||||
color: ${cssManager.bdTheme('#888', '#777')};
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333')};
|
||||
background: ${cssManager.bdTheme('#fff', '#111')};
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
<div class="container">
|
||||
<button class="back-btn" @click=${() => this.emitEvent('back', {})}>
|
||||
\u2190 Back to organization
|
||||
</button>
|
||||
|
||||
<div class="repo-header">
|
||||
<div class="repo-title-row">
|
||||
<sg-protocol-badge .protocol=${this.repository.protocol}></sg-protocol-badge>
|
||||
<span class="repo-name">${this.repository.name}</span>
|
||||
<span class="visibility-tag ${this.repository.visibility}">${this.repository.visibility}</span>
|
||||
</div>
|
||||
${this.repository.description
|
||||
? html`<div class="repo-description">${this.repository.description}</div>`
|
||||
: ''}
|
||||
<div class="repo-meta">
|
||||
<span>${this.repository.packageCount} package${this.repository.packageCount !== 1 ? 's' : ''}</span>
|
||||
<span>Protocol: ${this.repository.protocol.toUpperCase()}</span>
|
||||
<span>Created: ${this.formatDate(this.repository.createdAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="packages-section">
|
||||
<div class="section-title">Packages</div>
|
||||
${this.packages.length > 0
|
||||
? html`
|
||||
<div class="package-list">
|
||||
${this.packages.map(
|
||||
(pkg) => html`
|
||||
<div class="package-row" @click=${() => this.emitEvent('select-package', { packageId: pkg.id })}>
|
||||
<div class="package-info">
|
||||
<div class="package-name">${pkg.name}</div>
|
||||
${pkg.description
|
||||
? html`<div class="package-description">${pkg.description}</div>`
|
||||
: ''}
|
||||
</div>
|
||||
<div class="package-right">
|
||||
${pkg.isPrivate ? html`<span class="private-badge">Private</span>` : ''}
|
||||
${pkg.latestVersion ? html`<span class="version-tag">${pkg.latestVersion}</span>` : ''}
|
||||
<span class="download-count">${this.formatNumber(pkg.downloadCount)} pulls</span>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: html`<div class="empty-state">No packages published to this repository yet.</div>`}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private formatNumber(n: number): string {
|
||||
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
||||
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
|
||||
return n.toString();
|
||||
}
|
||||
|
||||
private formatDate(dateStr: string): string {
|
||||
if (!dateStr) return '';
|
||||
try {
|
||||
return new Date(dateStr).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
} catch {
|
||||
return dateStr;
|
||||
}
|
||||
}
|
||||
|
||||
private emitEvent(name: string, detail: Record<string, unknown>) {
|
||||
this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user