// Plan2Code Web Console - the Help dialog and the first-run Welcome (named so it is never confused with the pure help.js). import { looksReady, looks, saveLooks } from "../looks.js"; import { page } from "../state.js"; import { isDashboard, finish, agentAdrift } from "../selectors.js"; import { releasesLink, el, copyButton, lightDismiss } from "../render.js"; import { HELP_TABS, helpTabFor, helpKeyTarget } from "../help.js"; const $ = (id) => document.getElementById(id); // The first dashboard a person ever sees gets a Welcome dialog. Closing it by // any route (button, Esc, backdrop) saves looks.welcomeSeen, which rides in // looks.json like every other preference. Waits out the wake-up animation and // never lands on top of another open dialog. export function maybeWelcome() { if (!looksReady || looks.welcomeSeen === true || !page.S || !isDashboard() || finish() || page.wake) return; if (document.querySelector("dialog[open]")) return; openWelcome(); } export function openWelcome() { if ($("help-modal").open) $("help-modal").close(); const slot = $("welcome-bot"); if (!slot.firstElementChild) { const bot = $("planny").cloneNode(true); bot.removeAttribute("id"); bot.setAttribute("class", "planny is-point v1"); slot.appendChild(bot); } const dlg = $("welcome-modal"); if (!dlg.open) dlg.showModal(); $("welcome-done").focus(); } // Whether the two halves are actually talking, in the one place someone goes // when they are asking that question. Written on open rather than kept live, // because a line that rewrites itself under a reader is worse than a stale one // they can close and reopen. function renderAbout() { const line = $("about-live"); line.className = "about-live"; if (finish()) { line.textContent = "Right now: the session is finished, and the command above is all that is left to do."; } else if (page.gone) { line.classList.add("is-bad"); line.textContent = "Right now: this page cannot reach that program. Either it has stopped, or the machine went to sleep. The link from the terminal will bring it back."; } else if (agentAdrift()) { line.classList.add("is-bad"); line.textContent = "Right now: this page is fine, but Plan2Code has not checked in for a few minutes. Have a look at the terminal; it may have finished its turn, hit an error, or be waiting on you there. If it is idle, type continue there to wake it."; } else { line.classList.add("is-good"); line.textContent = "Right now: both halves are talking to each other."; } } let helpBuilt = false; async function renderHelpVersion() { const slot = $("help-version"); try { const res = await fetch("/version", { cache: "no-store" }); const { version } = res.ok ? await res.json() : {}; slot.replaceChildren(...(version ? [releasesLink("Plan2Code v" + version)] : [])); slot.hidden = !version; } catch { slot.hidden = true; } } const HELP_MOODS = [ ["point", "Your turn"], ["work", "Working"], ["happy", "All caught up"], ["done", "Done"], ["adrift", "Not running"], ["gone", "Not connected"], ]; // The help content waits in its