gabriel / musehub public
domain-detail.ts typescript
142 lines 5.4 KB
Raw
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 9 days ago
1 /**
2 * domain-detail.ts — Domain plugin detail page interactivity.
3 *
4 * Handles:
5 * - Copy-to-clipboard for terminal blocks and hash cells
6 * - Entrance animations for dimension cards (IntersectionObserver)
7 * - Install button feedback
8 * - Live viewer preview (musehub#117 DOM_09/DOM_10/DOM_11) — renders the
9 * domain's actual palette viewer (symbol_graph/piano_roll/generic) from
10 * its declared dimensions, not a static icon.
11 */
12
13 import { renderDomainViewer, type DimensionSpec } from '../domain-viewers.ts';
14
15 export interface DomainDetailData {
16 domainSlug?: string;
17 domainId?: string;
18 viewerType?: string;
19 dimensions?: DimensionSpec[];
20 [key: string]: unknown;
21 }
22
23 // ── Copy to clipboard ─────────────────────────────────────────────────────────
24
25 function setupCopyButtons(): void {
26 document.querySelectorAll<HTMLButtonElement>('[data-copy-id]').forEach(btn => {
27 btn.addEventListener('click', async () => {
28 const targetId = btn.dataset.copyId;
29 if (!targetId) return;
30 const el = document.getElementById(targetId);
31 if (!el) return;
32 const text = el.textContent?.trim() ?? '';
33 try {
34 await navigator.clipboard.writeText(text);
35 const prev = btn.textContent;
36 btn.textContent = '✓ Copied';
37 btn.classList.add('copied');
38 setTimeout(() => {
39 btn.textContent = prev;
40 btn.classList.remove('copied');
41 }, 2000);
42 } catch {
43 // fallback: select text
44 const range = document.createRange();
45 range.selectNode(el);
46 window.getSelection()?.removeAllRanges();
47 window.getSelection()?.addRange(range);
48 }
49 });
50 });
51 }
52
53 // ── Dimension card entrance animation ─────────────────────────────────────────
54
55 function setupDimAnimations(): void {
56 const grid = document.querySelector<HTMLElement>('.dd-dim-grid');
57 if (!grid) return;
58
59 const cards = Array.from(grid.querySelectorAll<HTMLElement>('.dd-dim-card'));
60 cards.forEach(card => {
61 card.style.opacity = '0';
62 card.style.transform = 'translateY(12px)';
63 });
64
65 const observer = new IntersectionObserver(entries => {
66 if (!entries.some(e => e.isIntersecting)) return;
67 observer.disconnect();
68 cards.forEach((card, i) => {
69 setTimeout(() => {
70 card.style.transition = 'opacity 0.35s ease, transform 0.35s ease';
71 card.style.opacity = '1';
72 card.style.transform = 'none';
73 }, i * 30);
74 });
75 }, { threshold: 0.1 });
76
77 observer.observe(grid);
78 }
79
80 // ── Stat pill count-up animation ──────────────────────────────────────────────
81
82 function setupStatCountUp(): void {
83 const pills = document.querySelectorAll<HTMLElement>('.dd-stat-pill__value');
84 pills.forEach(el => {
85 const raw = el.textContent?.trim() ?? '';
86 const num = parseInt(raw, 10);
87 if (isNaN(num) || num <= 1) return;
88 el.textContent = '0';
89 const duration = 600;
90 const start = performance.now();
91 const tick = (now: number) => {
92 const t = Math.min((now - start) / duration, 1);
93 const ease = 1 - Math.pow(1 - t, 3);
94 el.textContent = String(Math.round(ease * num));
95 if (t < 1) requestAnimationFrame(tick);
96 };
97 requestAnimationFrame(tick);
98 });
99 }
100
101 // ── Install button ─────────────────────────────────────────────────────────────
102
103 function setupInstallButton(): void {
104 const btn = document.getElementById('dd-install-btn');
105 if (!btn) return;
106 btn.addEventListener('click', () => {
107 // Show a "copied" instruction since Muse CLI install is a terminal command
108 const installEl = document.getElementById('install-cmd');
109 if (!installEl) return;
110 const text = installEl.textContent?.trim() ?? '';
111 navigator.clipboard.writeText(text).then(() => {
112 const prev = btn.textContent;
113 btn.textContent = '✓ Command Copied — paste in terminal';
114 btn.setAttribute('disabled', '');
115 setTimeout(() => {
116 btn.textContent = prev ?? '↓ Install Domain';
117 btn.removeAttribute('disabled');
118 }, 3000);
119 }).catch(() => {
120 btn.textContent = 'Open terminal and run: muse domain install';
121 setTimeout(() => { btn.textContent = '↓ Install Domain'; }, 4000);
122 });
123 });
124 }
125
126 // ── Live viewer preview ─────────────────────────────────────────────────────────
127
128 function setupViewerPreview(data: DomainDetailData): void {
129 const container = document.getElementById('dd-viewer-preview');
130 if (!container) return;
131 renderDomainViewer(container, data.viewerType ?? 'generic', data.dimensions ?? []);
132 }
133
134 // ── Entry point ───────────────────────────────────────────────────────────────
135
136 export function initDomainDetail(data: DomainDetailData): void {
137 setupCopyButtons();
138 setupDimAnimations();
139 setupStatCountUp();
140 setupInstallButton();
141 setupViewerPreview(data);
142 }
File History 15 commits
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 9 days ago
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 9 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454 chore: bump version to 0.2.0.dev2 — nightly.2, matching muse Sonnet 4.6 patch 12 days ago
sha256:31491a5f31832312965ba9c8d73c9eb6171069015bde3a471acc9d5006c1e45a revert: keep pyproject.toml in canonical PEP 440 form Sonnet 4.6 patch 15 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 35 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 36 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 36 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago