jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
This commit is contained in:
+18
-9
@@ -16,8 +16,9 @@ import { render } from './router.mjs';
|
||||
|
||||
// two-click confirm -- the second click within 5s fires; anything
|
||||
// else disarms. Each button owns its own arm state.
|
||||
/** @param {HTMLElement} btn @param {{ label: string, confirm: string, fire: () => Promise<void> }} opts */
|
||||
export function armedButton(btn, { label, confirm, fire }) {
|
||||
let timer = null;
|
||||
/** @type {?ReturnType<typeof setTimeout>} */ let timer = null;
|
||||
btn.addEventListener('click', async () => {
|
||||
if (timer === null) {
|
||||
btn.textContent = confirm;
|
||||
@@ -35,14 +36,17 @@ export function armedButton(btn, { label, confirm, fire }) {
|
||||
// resolves on success and throws on failure -- a failed save keeps
|
||||
// the editor open, nothing was changed. setEditable(false) is the
|
||||
// spectator state: no edit button, an open editor cancels.
|
||||
/** @typedef {{ section: string|HTMLElement, body: string|HTMLElement, empty: string, placeholder: string, rows: number, format: (items: string[]) => string, toText: (items: string[]) => string, fromText: (text: string) => string[], save: (items: string[]) => Promise<unknown> }} PaneOpts */
|
||||
/** @typedef {{ set: (next?: ?string[]) => void, setEditable: (ok: boolean) => void, reset: () => void, items: string[] }} Pane */
|
||||
/** @param {PaneOpts} opts @returns {Pane} */
|
||||
export function paneEditor({ section, body, empty, placeholder, rows, format, toText, fromText, save }) {
|
||||
const sec = typeof section === 'string' ? $(section) : section;
|
||||
const bodyEl = typeof body === 'string' ? $(body) : body;
|
||||
const editBtn = el('button', null, 'edit');
|
||||
sec.querySelector('.pane-head').appendChild(editBtn);
|
||||
(/** @type {HTMLElement} */ (sec.querySelector('.pane-head'))).appendChild(editBtn);
|
||||
const editor = el('div', 'pane-editor');
|
||||
editor.hidden = true;
|
||||
const area = el('textarea');
|
||||
const area = /** @type {HTMLTextAreaElement} */ (el('textarea'));
|
||||
area.rows = rows;
|
||||
area.placeholder = placeholder;
|
||||
const actions = el('div', 'pane-editor-actions');
|
||||
@@ -54,7 +58,7 @@ export function paneEditor({ section, body, empty, placeholder, rows, format, to
|
||||
editor.appendChild(actions);
|
||||
bodyEl.after(editor); // before anything that follows the body (#conflict on the status pane)
|
||||
|
||||
let items = [];
|
||||
/** @type {string[]} */ let items = [];
|
||||
let mayEdit = false;
|
||||
let open = false;
|
||||
|
||||
@@ -102,19 +106,22 @@ export function paneEditor({ section, body, empty, placeholder, rows, format, to
|
||||
// the upstream model listing, fetched once per session -- a live
|
||||
// /models call every render would hammer the endpoint for a list
|
||||
// that rarely changes
|
||||
let cachedModels = null;
|
||||
/** @type {?string[]} */ let cachedModels = null;
|
||||
/** @returns {Promise<string[]>} */
|
||||
export async function modelList() {
|
||||
if (!cachedModels) cachedModels = await api('/models').catch(() => []);
|
||||
if (!cachedModels) cachedModels = /** @type {string[]} */ (await api('/models').catch(() => []));
|
||||
return cachedModels;
|
||||
}
|
||||
|
||||
// A select's "" value means "deployment default"; a current override
|
||||
// missing from the listing stays selectable, so a stale pick never
|
||||
// silently rewrites itself.
|
||||
/** @param {HTMLSelectElement} sel @param {?string} current @param {string[]} list @param {?string} [def] */
|
||||
function fillSelect(sel, current, list, def) {
|
||||
sel.textContent = '';
|
||||
/** @param {string} v @param {string} label */
|
||||
const mk = (v, label) => {
|
||||
const o = el('option', null, label);
|
||||
const o = /** @type {HTMLOptionElement} */ (el('option', null, label));
|
||||
o.value = v;
|
||||
sel.appendChild(o);
|
||||
};
|
||||
@@ -127,12 +134,13 @@ function fillSelect(sel, current, list, def) {
|
||||
|
||||
// the models box: player/housekeeper selects + save, posting the
|
||||
// per-run overrides. The mount keeps its id -- the CSS panels it.
|
||||
/** @param {string|HTMLElement} mount @param {{ title: string }} opts */
|
||||
export function modelsBox(mount, { title }) {
|
||||
const root = typeof mount === 'string' ? $(mount) : mount;
|
||||
root.textContent = '';
|
||||
root.appendChild(el('h2', null, title));
|
||||
const playerSel = el('select');
|
||||
const houseSel = el('select');
|
||||
const playerSel = /** @type {HTMLSelectElement} */ (el('select'));
|
||||
const houseSel = /** @type {HTMLSelectElement} */ (el('select'));
|
||||
const pField = el('label', 'field', 'player ');
|
||||
pField.appendChild(playerSel);
|
||||
const hField = el('label', 'field', 'housekeeper ');
|
||||
@@ -158,6 +166,7 @@ export function modelsBox(mount, { title }) {
|
||||
}
|
||||
});
|
||||
return {
|
||||
/** @param {?{ player?: ?string, housekeeper?: ?string }} models @param {?{ player?: ?string, housekeeper?: ?string }} defaults @param {string[]} list */
|
||||
fill(models, defaults, list) {
|
||||
fillSelect(playerSel, models?.player ?? null, list, defaults?.player);
|
||||
fillSelect(houseSel, models?.housekeeper ?? null, list, defaults?.housekeeper);
|
||||
|
||||
Reference in New Issue
Block a user