Spaces:
Paused

assistant / ui /web /src /components /FirstRunDialog.svelte
localailb's picture
Deploy Full LocalAiLab Application (FastAPI + Svelte + Agents)
bc9f3e6 verified
Raw History Blame Contribute Delete
3.53 kB
<script>
import { onMount } from "svelte";
import { t } from "../lib/stores.svelte.js";
import { postJSON } from "../lib/api.js";
import "./FirstRunDialog.css";
/** Close callback fired when the user dismisses the dialog (clicking OK,
* Escape, or the dimmed backdrop). */
let { onclose } = $props();
let rootEl;
let boxEl = $state(null);
// ── Draggable ──────────────────────────────────────────────────
let dragOffsetX = 0;
let dragOffsetY = 0;
/** Dynamic left/top in px (null = CSS-centered default). */
let posX = $state(null);
let posY = $state(null);
let dragging = $state(false);
function onDragStart(e) {
if (!boxEl) return;
if (e.button !== 0) return;
e.preventDefault();
const rect = boxEl.getBoundingClientRect();
dragOffsetX = e.clientX - rect.left;
dragOffsetY = e.clientY - rect.top;
if (posX === null) posX = rect.left;
if (posY === null) posY = rect.top;
dragging = true;
}
function onDragMove(e) {
if (!dragging) return;
const w = window.innerWidth;
const h = window.innerHeight;
let x = e.clientX - dragOffsetX;
let y = e.clientY - dragOffsetY;
const bw = boxEl ? boxEl.offsetWidth : 440;
const bh = boxEl ? boxEl.offsetHeight : 300;
x = Math.max(0, Math.min(x, w - bw));
y = Math.max(0, Math.min(y, h - bh));
posX = x;
posY = y;
}
function onDragEnd() {
dragging = false;
}
function dismiss() {
// Persist that the onboarding was seen β€” the popup never blocks the
// close (a failed save must not trap the user in the dialog).
postJSON("/api/first-run/dismiss", {}).catch(() => {});
onclose?.();
}
onMount(() => {
// Focus the OK button so Enter dismisses immediately (like the app's
// other themed dialogs).
rootEl?.querySelector(".firstrun-ok")?.focus();
const onKey = (e) => {
if (e.key === "Escape") {
e.preventDefault();
dismiss();
}
};
document.addEventListener("keydown", onKey, true);
return () => document.removeEventListener("keydown", onKey, true);
});
</script>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<svelte:window
onmousemove={onDragMove}
onmouseup={onDragEnd}
/>
<div
class="firstrun-overlay"
role="presentation"
bind:this={rootEl}
onmousedown={(e) => {
if (e.target === rootEl) dismiss();
}}
>
<div
class="firstrun-box"
class:dragging
role="dialog"
aria-modal="true"
aria-labelledby="firstrun-title"
bind:this={boxEl}
style="{posX !== null ? `left:${posX}px;top:${posY}px;transform:none` : ''}"
>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="firstrun-title firstrun-drag-handle"
id="firstrun-title"
role="none"
onmousedown={onDragStart}
>{t("firstrun_title")}</div>
<div class="firstrun-lines">
<div class="firstrun-line">{t("firstrun_install_pytorch")}</div>
<div class="firstrun-line">{t("firstrun_install_llama")}</div>
<div class="firstrun-line">{t("firstrun_set_hf")}</div>
<div class="firstrun-line firstrun-tip">{t("firstrun_gguf_tip")}</div>
</div>
<div class="firstrun-actions">
<button
type="button"
class="firstrun-ok"
data-tooltip={t("firstrun_ok")}
onclick={dismiss}
>
{t("firstrun_ok")}
</button>
</div>
</div>
</div>