Public: anyone can read this; the crew can change it.

Talk on a phone: the conversation's controls within thumb reach, in a bottom bar #17078

opened this in answer to

Merged 2d 0h ago, live in production

scout/forge:scout/16586-talk-on-a-phone-the-conversation-s-contr → main 0 commits fork

  • Merged. scout/16586-talk-on-a-phone-the-conversation-s-contr was merged into main as 54e86c1.

Review

Sign in to review this change.
9 files changed +209 −93
docs/design/areas/talk.md +1
@@ -95,6 +95,7 @@ The window is the thread's one scroller; the list and a side pane are sticky col
9595 - `.talk-send`, `.talk-stop` — the one round button at the end: Send (an arrow up), or Stop (a square) while an answer runs and the box is empty.
9696 - `.talk-steer` — the one secondary control, shown while an answer runs and words are typed: send them now.
9797 - `.talk-hint` — "Enter sends", only where there is a mouse.
98 - `.talk-dock` — below 56.25rem the conversation's controls in one 44 px row above the composer, inside `.talk-base` (the sticky wrapper that rides `--kb`): Chats, New, Chat/Preview when a preview is live, and the menu, which then also holds the model (#16586). `.talk-head` is the title alone there; from 56.25rem the dock is hidden.
9899 - `.talk-foot` — the line under the box: the status while it says something, else the crew line.
99100 - `.talk-model` — the model picker's line under the box: Model, a select of the forge's own and each working connection's models, and Use for a page with no script. Absent when no connection offers a model.
100101 - `.talk-fold` — one run of steps (the calls and thoughts between words) folded into one closed disclosure, one tab stop: one step by its words, more by their count.
docs/design/size-budget/talk.json +2 −2
@@ -1,5 +1,5 @@
11 {
22 "page": "/talk",
3 "js": 42496,
4 "css": 58112
3 "js": 43008,
4 "css": 59392
55 }
docs/features/talk-layout.md +1
@@ -10,6 +10,7 @@ row: Talk's layout at every screen size
1010 - **Phone, under 56.25rem (900 px):** the thread alone, its head sticky under the top bar with the way to the list at its start, and the composer pinned above the keyboard (`--kb`, and `interactive-widget=resizes-content` where the browser honours it). The list is its own view (`?chats=1`).
1111 - **Tablet, 56.25rem up:** the list beside the thread, sticky, scrolling on its own; the thread is a centred reading column of at most 46rem.
1212 - **Laptop, 80rem up:** while the conversation builds an app, or something it worked on is running, a third column holds the build panel and the preview. With nothing to show there is no third column. Below 80rem that column is the Preview tab of a Chat / Preview switch.
13 - **Phone, below 900 px:** the conversation's controls sit in a bottom bar above the composer, within a thumb's reach: Chats, New, Chat / Preview when a preview is live, and the menu (which then also holds the model). The head at the top is the title alone. The bar rides above the keyboard with the composer. With scripts off they are plain links and forms.
1314 - **Empty conversation:** a greeting and the composer sit mid-screen, the starters as chips between them; Build an app turns the same composer into the one that makes an app (`?build=1`).
1415
1516 Prior art each choice borrows from:
src/web/pages/talk.ts +54 −20
@@ -505,34 +505,62 @@ function displayForm(display: TalkDisplay, back: string): Html {
505505 */
506506 function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, tabs: Html | null, picker: Html | null = null): Html {
507507 const archived = conversation.archivedAt !== null;
508 const item = (action: string, field: string, value: string, label: string, ic: "pin" | "history" | "trash"): Html =>
509 html`<form method="post" action="${urlOf(conversation)}/${action}"><input type="hidden" name="${field}" value="${value}" /><button class="menu-item" type="submit">${icon(ic)}<span class="grow">${label}</span></button></form>`;
510508 return html`<header class="talk-head">
511509 <a class="btn talk-back" data-variant="ghost" href="${urlOf(conversation)}?chats=1" title="All your chats, newest first">${icon("comment")}Chats</a>
512510 <h2 class="talk-title">${nameOf(conversation)}${archived ? " (archived)" : ""}</h2>
513511 ${picker}
514512 ${tabs}
515513 ${context !== undefined && context.share >= CONTEXT_SHOWN ? html`<span class="talk-fill small muted" title="${contextText(context)}">${meter(context.share * 100, contextText(context))} context used</span>` : null}
516 ${menu({
517 trigger: icon("more"),
518 label: "Conversation menu",
519 triggerOptions: { variant: "ghost", extra: "btn-icon" },
520 items: [
521 html`<div class="talk-figures small muted">${totalLine(conversationTotal(ctx.app.db, conversation.id))}${contextLine(context)}</div>`,
522 html`<form class="talk-rename" method="post" action="${urlOf(conversation)}/rename">
523 <input class="input" name="title" value="${conversation.title}" maxlength="${TITLE_MAX}" aria-label="Title" placeholder="Title" />
524 ${btn("Rename", { size: "sm" })}
525 </form>`,
526 { label: "Download", href: `${urlOf(conversation)}.md`, icon: "download" },
527 ...(archived ? [] : [item("pin", "pinned", conversation.pinnedAt === null ? "1" : "0", conversation.pinnedAt === null ? "Pin" : "Unpin", "pin")]),
528 item("archive", "archived", archived ? "0" : "1", archived ? "Restore" : "Archive", archived ? "history" : "trash"),
529 displayForm(display, urlOf(conversation)),
530 ],
531 })}
514 ${conversationMenu(ctx, conversation, context, display, null)}
532515 <form method="post" action="${HERE}/new">${iconBtn("plus", "New conversation", { variant: "ghost" })}</form>
533516 </header>`;
534517 }
535518
519 /** The conversation's total, read once per request: the head's menu and the dock's both show it. */
520 const totals = new WeakMap<Ctx, ReturnType<typeof conversationTotal>>();
521 function totalOnce(ctx: Ctx, id: string): ReturnType<typeof conversationTotal> {
522 if (!totals.has(ctx)) totals.set(ctx, conversationTotal(ctx.app.db, id));
523 return totals.get(ctx);
524 }
525
526 /** The conversation menu: Rename, Download, Pin, Archive, Display, and on a phone the model too. */
527 function conversationMenu(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, picker: Html | null): Html {
528 const archived = conversation.archivedAt !== null;
529 const item = (action: string, field: string, value: string, label: string, ic: "pin" | "history" | "trash"): Html =>
530 html`<form method="post" action="${urlOf(conversation)}/${action}"><input type="hidden" name="${field}" value="${value}" /><button class="menu-item" type="submit">${icon(ic)}<span class="grow">${label}</span></button></form>`;
531 return menu({
532 trigger: icon("more"),
533 label: "Conversation menu",
534 triggerOptions: { variant: "ghost", extra: "btn-icon" },
535 items: [
536 html`<div class="talk-figures small muted">${totalLine(totalOnce(ctx, conversation.id))}${contextLine(context)}</div>`,
537 ...(picker === null ? [] : [picker]),
538 html`<form class="talk-rename" method="post" action="${urlOf(conversation)}/rename">
539 <input class="input" name="title" value="${conversation.title}" maxlength="${TITLE_MAX}" aria-label="Title" placeholder="Title" />
540 ${btn("Rename", { size: "sm" })}
541 </form>`,
542 { label: "Download", href: `${urlOf(conversation)}.md`, icon: "download" },
543 ...(archived ? [] : [item("pin", "pinned", conversation.pinnedAt === null ? "1" : "0", conversation.pinnedAt === null ? "Pin" : "Unpin", "pin")]),
544 item("archive", "archived", archived ? "0" : "1", archived ? "Restore" : "Archive", archived ? "history" : "trash"),
545 displayForm(display, urlOf(conversation)),
546 ],
547 });
548 }
549
550 /**
551 * Below 900 px the controls ride with the composer, in thumb reach: the way to the chat list, New,
552 * Chat/Preview when a preview is live, and the menu, which holds the model. It is hidden at and
553 * above 900 px, where the head carries them.
554 */
555 function dockBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, tabs: Html | null, picker: Html | null): Html {
556 return html`<nav class="talk-dock" aria-label="Conversation controls">
557 <a class="btn talk-back" data-variant="ghost" href="${urlOf(conversation)}?chats=1" title="All your chats, newest first">${icon("comment")}Chats</a>
558 <form method="post" action="${HERE}/new">${iconBtn("plus", "New conversation", { variant: "ghost" })}</form>
559 ${tabs}
560 ${conversationMenu(ctx, conversation, context, display, picker)}
561 </nav>`;
562 }
563
536564 /** The page's own words that are new with #15734, in one place so they can be translated later. */
537565 /** How full the context must be before the head shows it, as a share of the window. */
538566 const CONTEXT_SHOWN = 0.6;
@@ -646,11 +674,14 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
646674 // The crew's line says something only while a run is live: idle is silence.
647675 const crew = liveCrewRows(ctx, user);
648676 // The model picker (`talk_model.ts`), only where a connection offers a model.
649 const picker = buildMode ? null : modelPicker(ctx, user, conversation.id);
677 const pickerAt = buildMode ? null : modelPicker(ctx, user, conversation.id);
678 const picker = pickerAt === null ? null : pickerAt();
679 const tabs = split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat${paneQ === "" ? "" : `&${paneQ}`}"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview${paneQ === "" ? "" : `&${paneQ}`}"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null;
680 const dockPicker = pickerAt === null ? null : pickerAt("-dock");
650681 const body = html`<div class="talk-page" data-shell${!split ? null : html` data-frame-origins="${frames.join(" ")}"`} data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}${split ? raw(" data-split") : null}><h1 class="sr-only">Talk</h1>
651682 <div class="talk-side">${chats(ctx, conversation, showArchived, typed)}</div>
652683 <div class="talk" data-talk data-density="${display.density}" data-motion="${display.motion}" data-enter="${display.enter}" data-fold="${display.steps}" data-user="${user.id}" data-c="${conversation.id}" data-here="${here}" data-paged="${paged ? "1" : "0"}" data-running="${running && !paged ? "1" : "0"}">
653 ${hereBar(ctx, conversation, context, display, split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat${paneQ === "" ? "" : `&${paneQ}`}"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview${paneQ === "" ? "" : `&${paneQ}`}"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null, picker)}
684 ${hereBar(ctx, conversation, context, display, tabs, picker)}
654685 ${pinnedPlan(conversation.id, conversationPlan(ctx.app.db, conversation.id))}
655686 ${turns.length === DEFAULT_PAGE && turns[0] !== undefined
656687 ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}" data-earlier>Earlier</a></p>`
@@ -665,6 +696,8 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
665696 <p class="talk-crew small muted" id="talk-crew" data-live="run.*" data-live-src="/live/talk-crew">${crew.length === 0 ? null : crewLine(crew)}</p>
666697 <div id="end"></div>
667698 <div class="talk-keys" data-keys role="region" aria-label="Keyboard shortcuts" hidden><dl>${TALK_KEYS.map((k) => html`<dt>${k.keys}</dt><dd>${k.does}</dd>`)}</dl></div>
699 <div class="talk-base">
700 ${dockBar(ctx, conversation, context, display, tabs, dockPicker)}
668701 <form class="talk-compose" id="compose" method="post" action="${buildMode ? "/talk/build" : editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}${buildMode ? raw(" data-build") : null}>
669702 ${conversation.archivedAt === null ? null : html`<p class="small muted" data-archived-note>Archived: sending here keeps it archived; Restore puts it back in the list.</p>`}
670703 ${about}
@@ -691,6 +724,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
691724 <p class="talk-status small muted" role="status">${running && !paged ? "The forge is answering…" : ""}</p>
692725 <button type="button" class="btn talk-jump" data-jump hidden title="Jump to the latest message">${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button>
693726 </form>
727 </div>
694728 ${picker === null ? null : modelForm(urlOf(conversation))}
695729 <template id="talk-ico">${icon("copy")}${icon("check")}</template>
696730 <template id="talk-queued">${queuedHtml({ id: "", text: "" })}</template>
src/web/pages/talk_client.ts +30 −4
@@ -111,10 +111,31 @@ body:has(.talk-page) .topbar { background: var(--bg); backdrop-filter: none; -we
111111 .talk { padding-inline: 24px; }
112112 .talk-back, .talk-head > form { display: none; }
113113 }
114 /* Below 900 px the controls sit in the dock above the composer, within a thumb's reach; the head keeps the title. */
115 .talk-dock { display: none; }
116 @media (max-width: 56.24rem) {
117 .talk-head > :not(.talk-title) { display: none; }
118 .talk-dock { display: flex; align-items: center; gap: 4px; min-height: 2.75rem; padding-block: 2px; background: var(--bg); border-top: 1px solid var(--border); }
119 .talk-dock .talk-back { display: inline-flex; flex: none; min-height: 2.75rem; gap: 4px; padding-inline: 8px; }
120 .talk-dock .talk-back .ico { display: none; }
121 .talk-dock .btn-icon, .talk-dock summary.btn { position: relative; flex: none; min-width: 2.75rem; min-height: 2.75rem; }
122 .talk-dock .talk-tabs a { min-width: 2.75rem; justify-content: center; }
123 .talk-dock > .menu, .talk-dock > .talk-tabs { margin-inline-start: auto; }
124 .talk-dock > .talk-tabs + .menu { margin-inline-start: 0; }
125 .talk-dock .menu-panel { top: auto; bottom: calc(100% + 6px); transform-origin: bottom right; }
126 .talk-dock .talk-model { flex: none; padding: 4px; }
127 .talk-dock .talk-model select { min-width: 10rem; min-height: 2.75rem; }
128 [data-split]:not([data-pane="chat"]) { display: flex; flex-direction: column; min-height: calc(100dvh - var(--topbar-h)); }
129 [data-split]:not([data-pane="chat"]) > .talk { display: contents; }
130 [data-split]:not([data-pane="chat"]) .talk-work { order: 1; }
131 [data-split]:not([data-pane="chat"]) .talk-base { order: 2; margin-top: auto; background: var(--bg); }
132 [data-split]:not([data-pane="chat"]) .talk-base .talk-compose { display: none; }
133 }
134 @media (min-width: 56.25rem) { .talk-dock { display: none; } }
114135 @media (max-width: 79.99rem) {
115136 [data-split]:not([data-pane="chat"]) .talk-work { display: block; }
116137 [data-split]:not([data-pane="chat"]) .talk { min-height: 0; }
117 [data-split]:not([data-pane="chat"]) .talk > :not(.talk-head) { display: none; }
138 [data-split]:not([data-pane="chat"]) .talk > :not(.talk-head):not(.talk-base) { display: none; }
118139 }
119140 @media (min-width: 80rem) {
120141 [data-split] { grid-template-columns: 16rem minmax(24rem, 1fr) minmax(0, 1.25fr); }
@@ -211,7 +232,8 @@ body:has(.talk-page) .topbar { background: var(--bg); backdrop-filter: none; -we
211232 .talk-confirms[data-many] .talk-confirm:not(:first-child) :is(.talk-confirm-acts, .talk-confirm-left) { display: none; }
212233 .talk-fold[data-dones] summary > .ico { margin-inline-end: 8px; vertical-align: -3px; color: var(--muted-fg); }
213234 .talk:has(.talk-hello) .talk-log { flex: 0; margin-top: auto; }
214 .talk:has(.talk-hello) .talk-compose { position: static; margin-bottom: auto; padding-bottom: 32px; }
235 .talk:has(.talk-hello) .talk-base { position: static; margin-top: 0; margin-bottom: auto; }
236 .talk:has(.talk-hello) .talk-compose { padding-bottom: 32px; }
215237 .talk-crew { margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
216238 .talk-hello { align-self: center; padding: 0; text-align: center; }
217239 .talk-hello h2 { margin: 0 0 8px; font-size: 20px; font-weight: 620; letter-spacing: -.02em; }
@@ -220,7 +242,10 @@ body:has(.talk-page) .topbar { background: var(--bg); backdrop-filter: none; -we
220242 /* A narrow phone keeps the greeting and the composer in the eye line whatever the fonts wrap to. */
221243 @media (max-width: 30rem) { .talk-suggest { margin-top: 16px; } .talk:has(.talk-hello) .talk-compose { padding-bottom: 16px; } .talk:has(.talk-hello) { padding-bottom: 10vh; } }
222244 .talk-suggest .btn { min-height: 2.75rem; border-radius: 999px; }
223 .talk-compose { position: sticky; bottom: var(--kb, 0px); z-index: 8; padding: 8px 0 max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 8px); }
245 /* Scrolling a control into view stops short of the sticky foot, not under it. */
246 html:has(.talk-page) { scroll-padding-bottom: 8rem; }
247 .talk-base { position: sticky; bottom: var(--kb, 0px); z-index: 8; margin-top: auto; }
248 .talk-compose { padding: 8px 0 max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 8px); }
224249 .talk-box { display: grid; border: 1px solid var(--border-strong); border-radius: 24px; background: var(--card); box-shadow: var(--shadow-1); }
225250 .talk-box:focus-within { border-color: var(--muted-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted-fg) 22%, transparent); }
226251 .talk-box:has([aria-invalid="true"]) { border-color: var(--danger); }
@@ -1143,8 +1168,9 @@ ${dictateJs}
11431168 const fresh = t.content.querySelector("[data-shell]"), work = fresh && fresh.querySelector(".talk-work"), head = fresh && fresh.querySelector(".talk-head");
11441169 if (!work) return;
11451170 if (work.querySelector("[data-frame]")) { if (!box.value.trim()) window.location.reload(); return; }
1146 const mine = shell.querySelector(".talk-head");
1171 const mine = shell.querySelector(".talk-head"), dock = fresh.querySelector(".talk-dock"), myDock = shell.querySelector(".talk-dock");
11471172 if (head && mine && !mine.contains(document.activeElement)) mine.replaceWith(head);
1173 if (dock && myDock && !myDock.contains(document.activeElement)) myDock.replaceWith(dock);
11481174 shell.append(work);
11491175 shell.setAttribute("data-split", "");
11501176 document.dispatchEvent(new Event("forge:here"));
src/web/talk_model.ts +4 −4
@@ -19,7 +19,7 @@ import { flashTo } from "./layout.ts";
1919 * The picker, in the conversation's head, its form outside it (`form=`), or null with nothing to
2020 * offer.
2121 */
22 export function modelPicker(ctx: Ctx, user: User, conversationId: string): Html | null {
22 export function modelPicker(ctx: Ctx, user: User, conversationId: string): ((idSuffix?: string) => Html) | null {
2323 // A forge with no connection Talk could run on draws no picker and reads nothing for it.
2424 if (!anyTalkConnection(ctx.app.db)) return null;
2525 const offered = offers(ctx.app.db, user);
@@ -30,9 +30,9 @@ export function modelPicker(ctx: Ctx, user: User, conversationId: string): Html
3030 const listed = offered.some((o) => o.connection.id === now?.connectionId && o.models.includes(now.model));
3131 // A choice whose connection stopped answering stays shown as the conversation's, never offered anew.
3232 const stale = now === undefined || listed ? undefined : connectionFor(ctx.app.db, user.id, now.connectionId);
33 return html`<p class="talk-model small">
34 <label class="sr-only" for="talk-model-pick">Model</label>
35 <select class="input" id="talk-model-pick" name="model" form="talk-model" data-model-pick>
33 return (idSuffix = "") => html`<p class="talk-model small">
34 <label class="sr-only" for="talk-model-pick${idSuffix}">Model</label>
35 <select class="input" id="talk-model-pick${idSuffix}" name="model" form="talk-model" data-model-pick>
3636 <option value=""${current === "" ? html` selected` : null}>${FORGE_MODEL}</option>
3737 ${now !== undefined && !listed ? html`<option value="${current}" selected>${choiceLabel(stale ?? { name: "a removed connection" }, now.model)} (not answering)</option>` : null}
3838 ${offered.map((o) => html`<optgroup label="${o.connection.name}">${o.models.map((m) => html`<option value="${choiceValue({ connectionId: o.connection.id, model: m })}"${choiceValue({ connectionId: o.connection.id, model: m }) === current ? html` selected` : null}>${choiceLabel(o.connection, m)}</option>`)}</optgroup>`)}
test/talk-layout.test.ts +1 −1
@@ -67,7 +67,7 @@ const EXPRESSION = `(() => {
6767 const pre = document.querySelector(".talk-body pre"), a = document.querySelector(".talk-body a");
6868 return pre && a ? { boxScrolls: pre.scrollWidth > pre.clientWidth, boxWidth: pre.getBoundingClientRect().width, linkRight: a.getBoundingClientRect().right } : null;
6969 };
70 const box = (sel) => { const el = document.querySelector(sel); if (!el) return null; const r = el.getBoundingClientRect(); return r.width === 0 || r.height === 0 ? null : { left: r.left, right: r.right, top: r.top, bottom: r.bottom, width: r.width }; };
70 const box = (sel) => { const el = [...document.querySelectorAll(sel)].find((e) => e.getBoundingClientRect().width > 0); if (!el) return null; const r = el.getBoundingClientRect(); return r.width === 0 || r.height === 0 ? null : { left: r.left, right: r.right, top: r.top, bottom: r.bottom, width: r.width }; };
7171 const tabs = document.querySelector(".talk-tabs");
7272 return JSON.stringify({
7373 scrollWidth: document.documentElement.scrollWidth,
test/talk-page.test.ts +8 −4
@@ -143,7 +143,7 @@ describe("the page", () => {
143143 expect(html).toContain('class="talk-compose"');
144144 expect(html).toMatch(/talk-back" data-variant="ghost" href="\/talk\/[^"?]+\?chats=1"/);
145145 expect(talkCss).toContain('.talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; }');
146 expect(talkCss).toMatch(/\.talk-compose \{[^}]*position: sticky; bottom: var\(--kb, 0px\)/);
146 expect(talkCss).toMatch(/\.talk-base \{[^}]*position: sticky; bottom: var\(--kb, 0px\)/);
147147 // The head is one 44 px row, its buttons 44 px themselves.
148148 expect(talkCss).toMatch(/\.talk-head \.btn-icon[^{]*\{[^}]*min-height: 2\.75rem/);
149149 expect(talkCss).toMatch(/\.talk-head \.btn-icon::after[^{]*\{ content: ""; position: absolute; inset: -6px; \}/);
@@ -162,7 +162,7 @@ describe("the page", () => {
162162 const { talkCss } = await import("../src/web/pages/talk_client.ts");
163163 // With a pane, below 80rem it is a tab: the head, which holds the tabs, stays; the thread steps
164164 // aside.
165 expect(talkCss).toContain(`[data-split]:not([data-pane="chat"]) .talk > :not(.talk-head) { display: none; }`);
165 expect(talkCss).toContain(`[data-split]:not([data-pane="chat"]) .talk > :not(.talk-head):not(.talk-base) { display: none; }`);
166166 });
167167
168168 test("signed out goes to /signin and comes back", async () => {
@@ -457,7 +457,9 @@ describe("the page", () => {
457457 const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts");
458458 // 18,100 to 18,500 for the phone (#16442): one head row with the picker and tabs, a table that
459459 // scrolls in its bubble, an opaque top bar over the head: 18,294 measured.
460 expect(Buffer.byteLength(talkCss)).toBeLessThan(18_500);
460 // To 20,500 for the dock (#16586): the controls in a bottom bar below 900 px, the head the
461 // title, the empty chat, Chat/Preview at 44 px and a scroll margin above the foot.
462 expect(Buffer.byteLength(talkCss)).toBeLessThan(20_500);
461463 // The script to 56,300 for sending once (#16579, #16582): the line shown while a message sends,
462464 // a failed send's words and files put back, one send at a time with its key: 56,006 measured.
463465 expect(Buffer.byteLength(talkJs)).toBeLessThan(56_300);
@@ -477,7 +479,9 @@ describe("the page", () => {
477479 // last line and the pane's first-version words: 49,466 measured. Then to 54,600 by the same
478480 // phone rules (#16442), which ride inline: 54,393 measured. Then to 55,400 by sending once
479481 // (#16582): the queued row's one template, which the script fills: 55,122 measured.
480 expect(size).toBeLessThan(55_400);
482 // Then to 61,000 by the dock (#16586), the controls in a bottom bar on a phone: 60,777
483 // measured.
484 expect(size).toBeLessThan(61_000);
481485 });
482486
483487 describe("the script, driven against a DOM", () => {
test/talk-phone.test.ts +108 −58
@@ -170,6 +170,27 @@ const WAIT =
170170 const IDS =
171171 "const ids = () => [...document.querySelectorAll('.talk-log li[id^=\"t-\"]')].map((l) => l.id);";
172172
173 test("without a browser: the conversation's controls are in a dock beside the composer, plain links and forms, the head the title alone on a phone", async () => {
174 const res = await fetch(`${servers.url}/talk/${shortId}`, { headers: { cookie: `forge_session=${token}` } });
175 const page = await res.text();
176 const dock = page.slice(page.indexOf('<nav class="talk-dock"'), page.indexOf("</nav>", page.indexOf('<nav class="talk-dock"')));
177 expect(dock).toContain(`href="/talk/${shortId}?chats=1"`);
178 expect(dock).toContain('method="post" action="/talk/new"');
179 expect(dock).toContain(`action="/talk/${shortId}/rename"`);
180 expect(dock).toContain(`/talk/${shortId}.md`);
181 expect(dock).toContain('id="talk-model-pick-dock"');
182 // The dock and the composer share the sticky foot, the dock first; the head's own picker keeps
183 // its id.
184 const foot = page.indexOf('class="talk-base"');
185 expect(foot).toBeGreaterThan(-1);
186 expect(page.indexOf('class="talk-dock"')).toBeGreaterThan(foot);
187 expect(page.indexOf('class="talk-dock"')).toBeLessThan(page.indexOf('class="talk-compose"'));
188 expect(page).toContain('id="talk-model-pick"');
189 const { talkCss } = await import("../src/web/pages/talk_client.ts");
190 expect(talkCss).toContain(".talk-head > :not(.talk-title) { display: none; }");
191 expect(talkCss).toMatch(/@media \(min-width: 56\.25rem\) \{ \.talk-dock \{ display: none; \} \}/);
192 });
193
173194 test("without a browser: a page of older turns never says the forge is answering, since nothing there follows the answer", async () => {
174195 const was = clock.running;
175196 clock.running = () => true;
@@ -250,82 +271,111 @@ for (const width of WIDTHS) {
250271 );
251272
252273 test.skipIf(skip)(
253 `${width} px: the head is one compact row with the picker and the tabs, nothing wrapped or past the edge`,
274 `${width} px: the controls are one 44 px row in the lower half beside the composer, and the head is the title alone`,
254275 async () => {
255276 const s = await phone(
256277 width,
257278 `/talk/${shortId}`,
258279 token,
259 `(() => {
260 const head = document.querySelector(".talk-head");
261 const measure = () => {
262 const h = head.getBoundingClientRect();
263 const kids = [...head.querySelectorAll(":scope > *")].filter((e) => e.getBoundingClientRect().width > 0).map((e) => { const r = e.getBoundingClientRect(); return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, w: r.width, h: r.height, cls: String(e.className || e.tagName) }; });
264 return { h: h.height, kids, sw: document.documentElement.scrollWidth };
265 };
266 const plain = measure();
267 // A chat beside a live preview: the page splits and the head carries Chat and Preview.
280 `(async () => {
281 const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
282 const head = document.querySelector(".talk-head"), dock = document.querySelector(".talk-dock");
283 // A chat beside a live preview: the page splits and the dock carries Chat and Preview.
268284 document.querySelector(".talk-page").setAttribute("data-split", "");
269 head.querySelector(".talk-model").insertAdjacentHTML("afterend", '<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat" aria-current="page">Chat</a><a href="?pane=preview">Preview</a></nav>');
270 return JSON.stringify({ plain, split: measure() });
285 dock.querySelector("form").insertAdjacentHTML("afterend", '<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat" aria-current="page">Chat</a><a href="?pane=preview">Preview</a></nav>');
286 await frame();
287 const box = (e) => { const r = e.getBoundingClientRect(); return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, w: r.width, h: r.height, cls: String(e.className || e.tagName), text: (e.getAttribute("aria-label") || e.textContent || "").trim().slice(0, 20) }; };
288 const shown = (e) => e.getBoundingClientRect().width > 0;
289 const d = dock.getBoundingClientRect();
290 const kids = [...dock.querySelectorAll(":scope > *")].filter(shown).map(box);
291 const targets = [...dock.querySelectorAll(":scope > a, :scope > form button, :scope > .talk-tabs a, :scope > .menu > summary")].filter(shown).map(box);
292 const headKids = [...head.querySelectorAll(":scope > *")].filter(shown).map((e) => String(e.className || e.tagName));
293 // The model picker is one tap into the menu, and fits above the dock.
294 dock.querySelector(".menu > summary").click();
295 await frame();
296 const sel = dock.querySelector(".talk-model select"), panel = dock.querySelector(".menu-panel");
297 const model = { sel: box(sel), panel: box(panel), tracked: shown(sel) };
298 const ids = [...document.querySelectorAll("[id]")].map((e) => e.id), dup = ids.filter((x, i) => ids.indexOf(x) !== i);
299 return JSON.stringify({ dock: { top: d.top, bottom: d.bottom, h: d.height }, kids, targets, headKids, model, dup, vh: innerHeight, sw: document.documentElement.scrollWidth });
271300 })()`,
272301 );
273 for (const [how, m] of Object.entries(s) as [
274 string,
275 {
276 h: number;
277 sw: number;
278 kids: {
279 top: number;
280 bottom: number;
281 left: number;
282 right: number;
283 w: number;
284 h: number;
285 cls: string;
286 }[];
287 },
288 ][]) {
289 const seen = `${how}: ${JSON.stringify(m)}`;
290 expect(m.h, seen).toBeLessThanOrEqual(48);
291 expect(m.sw, seen).toBeLessThanOrEqual(width);
292 expect(m.kids.map((k) => k.cls).join(" "), seen).toContain(
293 "talk-model",
294 );
295 const top = Math.min(...m.kids.map((k) => k.top));
296 for (const k of m.kids) {
297 expect(k.right, seen).toBeLessThanOrEqual(width);
298 expect(k.bottom, seen).toBeLessThanOrEqual(top + 48);
299 if (/btn-icon|talk-back|menu|FORM/.test(k.cls))
300 expect(Math.min(k.w, k.h), seen).toBeGreaterThanOrEqual(44);
301 }
302 // The title keeps at least a few letters.
303 expect(
304 m.kids.find((k) => k.cls.includes("talk-title"))!.w,
305 seen,
306 ).toBeGreaterThanOrEqual(48);
302 const seen = JSON.stringify(s);
303 expect(s.dock.h, seen).toBeLessThanOrEqual(52);
304 expect(s.sw, seen).toBeLessThanOrEqual(width);
305 // Every control is reachable in the lower half, a 44 px target, nothing wrapped or past the
306 // edge.
307 expect(s.dock.top, seen).toBeGreaterThan(s.vh / 2);
308 expect(s.dock.bottom, seen).toBeLessThanOrEqual(s.vh);
309 const top = Math.min(...s.kids.map((k: { top: number }) => k.top));
310 for (const k of s.kids) {
311 expect(k.right, seen).toBeLessThanOrEqual(width);
312 expect(k.left, seen).toBeGreaterThanOrEqual(0);
313 expect(k.bottom, seen).toBeLessThanOrEqual(top + 52);
307314 }
308 expect(
309 s.plain.kids.some((k: { cls: string }) => k.cls === "FORM"),
310 "New is in the head",
311 ).toBe(true);
315 const names = s.targets.map((k: { text: string }) => k.text).join("|");
316 for (const word of ["Chats", "New conversation", "Chat", "Preview", "Conversation menu"]) expect(names, seen).toContain(word);
317 for (const k of s.targets) {
318 expect(Math.min(k.w, k.h), seen).toBeGreaterThanOrEqual(44);
319 expect(k.top, seen).toBeGreaterThan(s.vh / 2);
320 }
321 // The head keeps the title and nothing else.
322 expect(s.headKids, seen).toEqual(["talk-title"]);
323 // The model: in the menu, in the lower half, 44 px tall, on screen, above the bar.
324 expect(s.model.tracked, seen).toBe(true);
325 expect(s.model.sel.h, seen).toBeGreaterThanOrEqual(44);
326 expect(s.model.sel.right, seen).toBeLessThanOrEqual(width);
327 expect(s.model.panel.bottom, seen).toBeLessThanOrEqual(s.dock.top + 8);
328 expect(s.dup, seen).toEqual([]);
312329 },
313330 30_000,
314331 );
315332
316333 test.skipIf(skip)(
317 `${width} px: Chats is a labelled 44 px control in the head, and it opens the list at its top on the newest chat`,
334 `${width} px: with the keyboard open the dock rides with the composer above it and nothing rides under the keyboard`,
318335 async () => {
319 // Bob's Talk opens on his newest chat; the way to the others is in its head.
336 const s = await phone(
337 width,
338 `/talk/${longId}`,
339 token,
340 `(async () => {
341 const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
342 await frame();
343 const dock = document.querySelector(".talk-dock"), foot = document.querySelector(".talk-base"), box = document.querySelector(".talk-box"), input = document.querySelector(".talk-input");
344 const at = (where) => ({ where, dockTop: dock.getBoundingClientRect().top, dockBottom: dock.getBoundingClientRect().bottom, boxTop: box.getBoundingClientRect().top, boxBottom: box.getBoundingClientRect().bottom, footTop: foot.getBoundingClientRect().top, last: [...document.querySelectorAll(".talk-log li[id^='t-']")].at(-1).getBoundingClientRect().bottom, kb: getComputedStyle(document.documentElement).getPropertyValue("--kb").trim(), vh: innerHeight });
345 const before = at("closed");
346 // A stand-in keyboard: the visual viewport 300 px shorter while the box is focused.
347 Object.defineProperty(visualViewport, "height", { configurable: true, get: () => innerHeight - 300 });
348 input.focus();
349 visualViewport.dispatchEvent(new Event("resize"));
350 await frame();
351 const open = at("open");
352 return JSON.stringify({ before, open });
353 })()`,
354 );
355 const seen = JSON.stringify(s);
356 expect(s.before.dockBottom, seen).toBeLessThanOrEqual(s.before.boxTop + 1);
357 expect(s.before.boxBottom, seen).toBeLessThanOrEqual(s.before.vh);
358 expect(s.open.kb, seen).toBe("300px");
359 // Both stay above the keyboard and the dock stays above the box.
360 expect(s.open.boxBottom, seen).toBeLessThanOrEqual(s.open.vh - 300 + 1);
361 expect(s.open.dockBottom, seen).toBeLessThanOrEqual(s.open.boxTop + 1);
362 },
363 30_000,
364 );
365
366 test.skipIf(skip)(
367 `${width} px: Chats is a labelled 44 px control in the dock, and it opens the list at its top on the newest chat`,
368 async () => {
369 // Bob's Talk opens on his newest chat; the way to the others is in the dock.
320370 const at = await phone(
321371 width,
322372 `/talk`,
323373 listToken,
324374 `(() => {
325 const head = document.querySelector(".talk-head"), a = [...head.querySelectorAll("a")].find((x) => x.textContent.trim() === "Chats");
326 if (!a) return JSON.stringify({ found: false, head: head.innerText });
327 const r = a.getBoundingClientRect(), h = head.getBoundingClientRect();
328 return JSON.stringify({ found: true, href: a.getAttribute("href"), w: r.width, h: r.height, left: r.left, right: r.right, top: r.top, bottom: r.bottom, headTop: h.top, headBottom: h.bottom, shown: getComputedStyle(a).visibility === "visible" && r.width > 0 });
375 const dock = document.querySelector(".talk-dock"), a = [...dock.querySelectorAll("a")].find((x) => x.textContent.trim() === "Chats");
376 if (!a) return JSON.stringify({ found: false, dock: dock.innerText });
377 const r = a.getBoundingClientRect(), h = dock.getBoundingClientRect();
378 return JSON.stringify({ found: true, href: a.getAttribute("href"), w: r.width, h: r.height, left: r.left, right: r.right, top: r.top, bottom: r.bottom, vh: innerHeight, dockTop: h.top, dockBottom: h.bottom, shown: getComputedStyle(a).visibility === "visible" && r.width > 0 });
329379 })()`,
330380 );
331381 const seen = JSON.stringify(at);
@@ -334,8 +384,8 @@ for (const width of WIDTHS) {
334384 expect(Math.min(at.w, at.h), seen).toBeGreaterThanOrEqual(44);
335385 expect(at.left, seen).toBeGreaterThanOrEqual(0);
336386 expect(at.right, seen).toBeLessThanOrEqual(width);
337 expect(at.top, seen).toBeGreaterThanOrEqual(at.headTop);
338 expect(at.bottom, seen).toBeLessThanOrEqual(at.headBottom);
387 expect(at.top, seen).toBeGreaterThan(at.vh / 2);
388 expect(at.bottom, seen).toBeLessThanOrEqual(at.dockBottom);
339389 expect(at.href, seen).toEndWith("?chats=1");
340390 const list = await phone(width, at.href, listToken, `(async () => { await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); const first = document.querySelector(".talk-list .row"); const r = first.getBoundingClientRect(); return JSON.stringify({ y: scrollY, top: r.top, bottom: r.bottom, vh: innerHeight, text: first.textContent }); })()`);
341391 const said = JSON.stringify(list);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs