mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-14 01:39:56 -05:00
@@ -6,6 +6,8 @@
|
||||
const leaving = new Set<string>();
|
||||
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
||||
|
||||
let detail = $state<Toast | null>(null);
|
||||
|
||||
function schedule(t: Toast) {
|
||||
if (timers.has(t.id)) return;
|
||||
const dur = t.duration ?? 3500;
|
||||
@@ -30,12 +32,23 @@
|
||||
dismissToast(id);
|
||||
}
|
||||
|
||||
function openDetail(e: MouseEvent, t: Toast) {
|
||||
e.preventDefault();
|
||||
detail = t;
|
||||
if (timers.has(t.id)) { clearTimeout(timers.get(t.id)!); timers.delete(t.id); }
|
||||
}
|
||||
|
||||
function closeDetail() {
|
||||
detail = null;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const activeIds = new Set(store.toasts.map(t => t.id));
|
||||
store.toasts.forEach(schedule);
|
||||
for (const [id, timer] of timers) {
|
||||
if (!activeIds.has(id)) { clearTimeout(timer); timers.delete(id); }
|
||||
}
|
||||
if (detail && !activeIds.has(detail.id)) detail = null;
|
||||
});
|
||||
|
||||
const icons: Record<Toast["kind"], string> = {
|
||||
@@ -49,7 +62,10 @@
|
||||
{#if store.toasts.length}
|
||||
<div class="toaster" aria-live="polite">
|
||||
{#each store.toasts as t (t.id)}
|
||||
<button class="toast toast-{t.kind}" data-toast-id={t.id} aria-label="{t.title}{t.body ? ': ' + t.body : ''}" onclick={() => dismiss(t.id)}>
|
||||
<button class="toast toast-{t.kind}" data-toast-id={t.id} aria-label="{t.title}{t.body ? ': ' + t.body : ''}"
|
||||
onclick={() => dismiss(t.id)}
|
||||
oncontextmenu={(e) => openDetail(e, t)}
|
||||
>
|
||||
<div class="accent-bar"></div>
|
||||
<span class="icon">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
@@ -65,6 +81,36 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if detail}
|
||||
<div class="detail-backdrop" role="presentation" onclick={closeDetail} oncontextmenu={(e) => e.preventDefault()}>
|
||||
<div class="detail-panel detail-{detail.kind}" role="dialog" onclick={(e) => e.stopPropagation()}>
|
||||
<div class="detail-accent"></div>
|
||||
<div class="detail-body">
|
||||
<div class="detail-header">
|
||||
<span class="detail-kind">{detail.kind}</span>
|
||||
<button class="detail-close" onclick={closeDetail} aria-label="Close">
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round">
|
||||
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="detail-title">{detail.title}</p>
|
||||
{#if detail.body}
|
||||
<pre class="detail-text">{detail.body}</pre>
|
||||
{/if}
|
||||
<div class="detail-actions">
|
||||
<button class="detail-copy" onclick={() => navigator.clipboard.writeText(`${detail!.title}${detail!.body ? '\n' + detail!.body : ''}`)}>
|
||||
Copy
|
||||
</button>
|
||||
<button class="detail-dismiss" onclick={() => { dismiss(detail!.id); closeDetail(); }}>
|
||||
Dismiss
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.toaster { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 9999; display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
|
||||
|
||||
@@ -105,4 +151,79 @@
|
||||
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
|
||||
.title { font-size: var(--text-xs); font-family: var(--font-ui); color: var(--text-secondary); font-weight: var(--weight-medium); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.sub { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
|
||||
.detail-backdrop {
|
||||
position: fixed; inset: 0; z-index: 10000;
|
||||
background: rgba(0,0,0,0.45);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
animation: fadeIn 0.15s ease both;
|
||||
}
|
||||
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
||||
|
||||
.detail-panel {
|
||||
display: flex; width: 420px; max-width: calc(100vw - 32px); max-height: 60vh;
|
||||
border-radius: var(--radius-lg); background: var(--bg-raised);
|
||||
border: 1px solid var(--border-base);
|
||||
box-shadow: 0 24px 64px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.05) inset;
|
||||
overflow: hidden;
|
||||
animation: popIn 0.2s cubic-bezier(0.16,1,0.3,1) both;
|
||||
}
|
||||
@keyframes popIn { from { opacity: 0; transform: scale(0.95) } to { opacity: 1; transform: scale(1) } }
|
||||
|
||||
.detail-accent { width: 3px; flex-shrink: 0; }
|
||||
.detail-error .detail-accent { background: var(--color-error); }
|
||||
.detail-success .detail-accent { background: var(--accent-fg); }
|
||||
.detail-info .detail-accent { background: var(--text-faint); }
|
||||
.detail-download .detail-accent { background: var(--accent-fg); }
|
||||
|
||||
.detail-body { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: var(--sp-3); gap: var(--sp-2); overflow: hidden; }
|
||||
|
||||
.detail-header { display: flex; align-items: center; justify-content: space-between; }
|
||||
.detail-kind {
|
||||
font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wider);
|
||||
text-transform: uppercase; color: var(--text-faint);
|
||||
}
|
||||
.detail-error .detail-kind { color: var(--color-error); }
|
||||
|
||||
.detail-close {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
width: 20px; height: 20px; border-radius: var(--radius-sm);
|
||||
background: none; border: none; color: var(--text-faint); cursor: pointer;
|
||||
transition: color var(--t-fast), background var(--t-fast);
|
||||
}
|
||||
.detail-close:hover { color: var(--text-primary); background: var(--bg-overlay); }
|
||||
|
||||
.detail-title {
|
||||
font-family: var(--font-ui); font-size: var(--text-sm);
|
||||
color: var(--text-secondary); font-weight: var(--weight-medium);
|
||||
line-height: var(--leading-snug); word-break: break-word;
|
||||
}
|
||||
|
||||
.detail-text {
|
||||
flex: 1; min-height: 0; overflow-y: auto;
|
||||
font-family: var(--font-mono, monospace); font-size: var(--text-xs);
|
||||
color: var(--text-muted); line-height: var(--leading-relaxed);
|
||||
white-space: pre-wrap; word-break: break-all;
|
||||
background: var(--bg-void); border: 1px solid var(--border-dim);
|
||||
border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3);
|
||||
scrollbar-width: thin;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.detail-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-1); }
|
||||
.detail-copy, .detail-dismiss {
|
||||
font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
|
||||
padding: 5px var(--sp-3); border-radius: var(--radius-sm); cursor: pointer;
|
||||
transition: color var(--t-base), background var(--t-base), border-color var(--t-base);
|
||||
}
|
||||
.detail-copy {
|
||||
border: 1px solid var(--border-dim); background: none; color: var(--text-muted);
|
||||
}
|
||||
.detail-copy:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-overlay); }
|
||||
.detail-dismiss {
|
||||
border: 1px solid color-mix(in srgb, var(--color-error) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--color-error) 10%, transparent);
|
||||
color: var(--color-error);
|
||||
}
|
||||
.detail-dismiss:hover { background: color-mix(in srgb, var(--color-error) 18%, transparent); }
|
||||
</style>
|
||||
Reference in New Issue
Block a user