Merge fix/new-page-popover: New team page in the top layer, whole rail tooltips, one-field New page screen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+526
−39
docs/superpowers/specs/2026-11-14-mapa-level-up.md+9 −0internal/mapa/handlers_pages.go+20 −2internal/mapa/static/frame.css+77 −21internal/mapa/static/mapa.js+93 −0internal/mapa/templates/frame.html+20 −9internal/mapa/templates/page_new.html+6 −2internal/mapa/templates/shell.html+1 −0internal/mapatest/browser_test.go+14 −4internal/mapatest/layout_browser_test.go+1 −1internal/mapatest/newpage_browser_test.go+258 −0internal/mapatest/share_json_test.go+27 −0
CI passed — run details
CI log
=== editor === cd editor && npm ci --no-audit --no-fund --loglevel=error added 16 packages in 341ms cd editor && node build-bundles.mjs wrote internal/mapa/static/editor.1969c5f18c953d0a.js (305206 bytes, 95.3KB gzipped; L12 budget 120KB) cd editor && node --test ✔ L1: mounting then serialising gives cleanBody(body), byte for byte (43.294082ms) ℹ 760 bodies ✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (64.899996ms) ✔ L2: one edited block changes only that block's bytes; undo gives the body back (107.568206ms) ℹ 748 single-block edits ✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (124.017649ms) ℹ 755 inserts, 715 deletes ✔ L3: seeded edits keep the document and its Markdown saying the same thing (3632.454901ms) ℹ 18240 edits over 760 bodies ✔ linear: trailing spaces (31.015691ms) ✔ linear: trailing whitespace (18.972556ms) ✔ linear: unclosed web links (15.179776ms) ✔ linear: web links with no address (19.696421ms) ✔ linear: unclosed wiki links (22.753173ms) ✔ linear: unclosed embeds (17.145486ms) ✔ linear: closes only (4.499402ms) ✔ golden file has bodies (0.654636ms) ✔ markup.mjs parses every body into Go's blocks, byte offsets and all (14.871854ms) ✔ markup.mjs strips and spans every block as Go does (28.443876ms) ✔ the schema's toDOM draws every body as Go renders it (49.698059ms) ✔ emphasis draws the four pinned outputs (16.858503ms) ✔ a body ends in the editor's empty paragraph (0.257358ms) ✔ a POST that never answers is aborted after the timeout (21.580117ms) ✔ a keepalive POST carries no signal, and an answer clears the timer (1.192464ms) ✔ autosave sends only what differs, and the tab owns the draft it wrote (8.078475ms) ✔ an offered draft never commits by itself; Save commits it (0.979127ms) ✔ reload, then close: sessionStorage says the draft is this tab's own (0.47903ms) ✔ closing carries text not yet sent, and the cap leaves it out (20.450549ms) ✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (2.868265ms) ✔ the block under the caret is the teammate's too, and undo brings back yours (2.43992ms) ✔ typing mid-flight: the merge is not applied and the base does not move (0.913536ms) ✔ a merge the editor cannot represent stops after three tries (3.342405ms) ✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.435784ms) ✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.84214ms) ✔ a stale tab shows the newer draft, offered, and never overwrites it (1.075086ms) ✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.907164ms) ✔ noBase and gone lead to the existing choices (0.929395ms) ✔ a commit that merged is applied when nothing was typed since (1.004865ms) ✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (6.449211ms) ✔ an own draft committed meanwhile goes on as a new draft (1.143813ms) ✔ a reload keeps a stored draft; unsent text still commits (0.54934ms) ✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (0.880795ms) ✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.406277ms) ✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.126981ms) ✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (3.796587ms) ✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (0.992362ms) ✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.276143ms) ✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.764339ms) ✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.464432ms) ✔ settling finds another tab's newer draft: the tab shows it before any typing (0.575388ms) ✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.65735ms) ✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.583553ms) ✔ marks: em outside strong, bold reopened around italics, edges outside (4.620006ms) ✔ marks close before code, links and atoms, and reopen after (0.460254ms) ✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (5.734865ms) ✔ empty blocks are written as nothing (1.59443ms) ✔ an unclosed fence that is no longer last gets its closing fence (1.235594ms) ✔ the structure check puts Join's seam where a kept one would merge two blocks (1.625998ms) ✔ prepareSave adopts the parse when no seam or rewrite can save the document (2.605897ms) ✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (1.922969ms) ✔ a trailing hard break stays on screen and is written as nothing (0.556112ms) ✔ the reparse waits while an IME is composing (4.133944ms) ✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.85735ms) ✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.949312ms) ✔ rebuild changes origins only, outside undo history (1.574031ms) ✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.347261ms) ✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.689392ms) ✔ a duplicate ^id typed above its holder never takes the id from it (0.788353ms) ✔ a copy-dragged block is reparsed, and says what its Markdown says (1.03426ms) ✔ a history command that throws is refused, never thrown (3.115533ms) ℹ tests 66 ℹ suites 0 ℹ pass 66 ℹ fail 0 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 4075.920903 === vet === go vet ./... go vet -tags browser ./internal/mapatest/ === fmt === === code === go tool rastrillo budget code The base has no .rastrillo/code.txt: skipping the check that records only go down. budget code: within the limits. === test === CGO_ENABLED=0 go test ./... ? amadan.net/oficina/mapa/cmd/mapa [no test files] ok amadan.net/oficina/mapa/internal/mapa 0.580s ? amadan.net/oficina/mapa/internal/mapa/icons [no test files] ok amadan.net/oficina/mapa/internal/mapa/markup 0.057s ok amadan.net/oficina/mapa/internal/mapa/seal 0.002s ok amadan.net/oficina/mapa/internal/mapatest 8.888s ? amadan.net/oficina/mapa/scripts/mutate [no test files] ? amadan.net/oficina/mapa/scripts/preview [no test files] === migration-check === go tool rastrillo migration check rastrillo migration check: models and migrations agree === credits-check === python3 scripts/credits.py --check credits: checked
diff --git a/docs/superpowers/specs/2026-11-14-mapa-level-up.md b/docs/superpowers/specs/2026-11-14-mapa-level-up.md| index 46ef2c6..13e84ac 100644 |
| --- a/docs/superpowers/specs/2026-11-14-mapa-level-up.md |
| +++ b/docs/superpowers/specs/2026-11-14-mapa-level-up.md |
| @@ -1142,6 +1142,15 @@ Phase 1's choices where this spec was silent, or where the build chose different |
| 75. **A bar's action does not go on a failed flush; a hung POST times out** (L2, L3). Save as a scratch page and Discard are not sent when the flush before them failed, and the bar says so; Show the saved version offers Leave anyway instead of going. `post.mjs` aborts a request after 10 seconds (never a keepalive one), and the saver retries. An aborted request may have landed; every draft write is version-checked, so the retry meets a 409 whose body is the text that request sent, and the saver takes that as its own: its version, and the typing since autosaved, never replaced. |
| 76. **The first scratch commit's tokens are held per person** (L4; amends notes 31 and 66): at most 256 each, refused past that, so one person's tabs never use up anyone else's. |
| +**New team page and the rail's tooltips, unclipped** (Paul, 14 November: clicking New team page showed nothing usable): |
| + |
| +77. **Nothing leaves the sidebar by overflowing it.** `[mapa-side]` scrolls (`overflow: auto`), and two things drew outside it and were cut off: New team page's form (285px wide in a 224px sidebar, so its right side went; beside the rail, all of it) and every rail tooltip. The sidebar keeps its scrolling (long Pinned and Recently edited lists need it); what leaves it no longer belongs to its box. |
| + - **The popover** is a native `popover` (`#mapa-new-page`, `role="dialog"`), opened by a `popovertarget` button at the sidebar's foot, so it needs no script: the top layer, which no overflow clips, and the platform's own Esc, click outside (light dismiss) and focus, which moves to the title (`autofocus` inside a popover) and back to the button on close. Placed by CSS anchor positioning: above the button in the open sidebar, beside it on the rail and in the default between 800px and 80rem, with `position-try-fallbacks: flip-block`. An engine without anchoring puts it fixed beside the sidebar's foot (`inset-inline-start: var(--mapa-side-w) + 10px`, 12px up); one without popovers shows a plain link to `/new` instead of the button. It is drawn after `<main>`, not in the sidebar: WebKit gives a page's autofocus to the first `[autofocus]` in the document even when hidden, and the popover's field took it from the New page and Rename screens' own (measured: `<div popover><input autofocus></div><input autofocus>` focuses nothing in WebKit 2388). The menus' `name="estilo-menus"` group: a popover is not a `<details>`, so the name does not apply, but the exclusivity holds both ways where it can. Pressing on a menu's title light-dismisses the popover with no script, and opening the popover closes an open menu through estilo's chrome.js (a click outside it); with scripts off a menu left open stays open under the popover, as two `<details>` menus never could. Esc closes whichever is open. |
| + - **With script** (`mapa.js`, `newTeamPage`) the popover posts `POST /pages` itself with `Accept: application/json`, held 650ms with the busy spinner (the form carries `data-busy="false"` so busy.js leaves it), and goes to the page the reply names, where the editor takes the caret (note 57). A refused title (taken, empty after trimming, too long, a date) answers 422 with the sentence and, for a taken title, its page; the popover shows it under the field with "Open the page with that title", the typing kept and focus back in the field. An empty field is refused by `required` before anything is sent. Esc gives focus back to the button: WebKit does not focus a button on a click, so a mouse-opened popover returned focus to the body. Without script the POST goes as a form, and a refusal is the New page screen with the sentence and what was typed. |
| + - **The tooltips** are `position: fixed`, which escapes a scroller that is not the box's containing block. Where the engine anchors, each is tied to its own row (`anchor-name` with `anchor-scope`, so every row's one name means that row) and follows the rail when it scrolls; elsewhere it sits at its static position, the row's corner, moved out 50px by margin. The static position does not follow a scrolled rail, which only scrolls below about 330px of window height. |
| + - **New page is one title field** (bug 3): the screen behind Page → New team page, `/new`, ⌘K's Create and a pending link drew the Markdown textarea under the title, borderless and half the window tall, so Create and Cancel sat 490 to 530px under the field and off a 877px window. It is now the title and the buttons, as Rename is and as §4.7's popover is; the page's text is written on the page once it exists, with the caret already there with script, and through the page's Edit as Markdown without. A body that comes with a refused POST (no screen sends one now) rides along in a hidden field, so nothing is lost. Gate 7's walk creates Acme, then writes its text through Edit as Markdown. |
| + - **Gates** (`newpage_browser_test.go`, `make browser`), each failing on `1e92f29`: `TestNewTeamPageShowsTheWholeForm` opens New team page in six sidebar states (1400 and 900 wide; no cookie, `open` and `rail`) and at 390 by Page → New team page, scripts off and on, asks `elementFromPoint` at the four corners of the title field and Create (3px in, past their rounded borders) for the form, checks focus is in the title, then types a title and presses Enter and waits for the page (on `1e92f29`: the corners hit `main` in every sidebar state, focus stayed on the summary, Enter made no page, and at 390 Create was below the window); `TestNewTeamPageRefusesATakenTitleInPlace`; `TestTheNewPageScreenKeepsItsButtonsUnderTheField` (within 48px at 1402×877 and 390×844, scripts off and on; 488 to 526px on `1e92f29`); `TestTheRailsTooltipsAreWhole`, which hovers every rail row by width and by cookie and hit-tests the tooltip's corners (every one cut off on `1e92f29`). `TestNewTeamPageAnswersThePopover` holds the JSON replies. By hand in Playwright's WebKit (build 2388): the popover's box in all five states matches Chromium's to the pixel, every corner hits, focus goes to the title and back to the button on Esc, a taken title is refused in place with scripts and on the screen without, Enter creates in both, and the tooltips are whole, a scrolled rail included. |
| + |
| ## 14. Findings and what changed |
diff --git a/internal/mapa/handlers_pages.go b/internal/mapa/handlers_pages.go| index 596ffee..bbdd392 100644 |
| --- a/internal/mapa/handlers_pages.go |
| +++ b/internal/mapa/handlers_pages.go |
| @@ -168,17 +168,35 @@ func (app *app) createPage(writer http.ResponseWriter, |
| form := pageForm{Title: title, Body: body, Error: err.Error(), |
| Action: "/pages", Label: "Create page", |
| Taken: app.index.TitleHref(request.Context(), title)} |
| - app.showForm(writer, request, http.StatusUnprocessableEntity, |
| - "page_new", form) |
| + app.refuseCreate(writer, request, form) |
| return |
| } |
| if err != nil { |
| app.fail(writer, request, err) |
| return |
| } |
| + if wantsJSON(request) { |
| + answer(writer, map[string]any{"href": PagePath(page)}) |
| + return |
| + } |
| seeOther(writer, request, PagePath(page)) |
| } |
| +// refuseCreate asks for another title: the New page screen again, with |
| +// what was typed, or, for the sidebar's popover, the sentence as JSON, |
| +// shown where the title was typed (level-up §4.7). |
| +func (app *app) refuseCreate(writer http.ResponseWriter, |
| + request *http.Request, form pageForm) { |
| + if !wantsJSON(request) { |
| + app.showForm(writer, request, http.StatusUnprocessableEntity, |
| + "page_new", form) |
| + return |
| + } |
| + writer.Header().Set("Content-Type", "application/json; charset=utf-8") |
| + writer.WriteHeader(http.StatusUnprocessableEntity) |
| + answer(writer, map[string]any{"error": form.Error, "taken": form.Taken}) |
| +} |
| + |
| // notice is the sentence a redirect after a POST asked for. |
| func notice(request *http.Request) string { |
| query := request.URL.Query() |
diff --git a/internal/mapa/static/frame.css b/internal/mapa/static/frame.css| index c106f6a..9915dac 100644 |
| --- a/internal/mapa/static/frame.css |
| +++ b/internal/mapa/static/frame.css |
| @@ -129,7 +129,10 @@ kbd[mapa-kbd] { |
| } |
| /* ── The rail (Página's): the same rows, icons only, on one axis. The |
| - label stays in the accessibility tree and is the tooltip. ── */ |
| + label stays in the accessibility tree and is the tooltip. The tooltip |
| + is fixed where its row puts it (its static position, insets left |
| + auto), then moved out beside the 40px row: a fixed box escapes the |
| + sidebar's scrolling, which clipped an absolute one. ── */ |
| @media (min-width: 800px) { |
| [mapa-app][data-side="rail"] [mapa-side] { padding-inline: 8px; align-items: center; } |
| [mapa-app][data-side="rail"] [mapa-side-item] { |
| @@ -156,8 +159,10 @@ kbd[mapa-kbd] { |
| background: var(--rst-accent); |
| } |
| [mapa-app][data-side="rail"] [mapa-side-label] { |
| - position: absolute; |
| - inset-inline-start: calc(100% + 10px); |
| + position: fixed; |
| + margin-inline-start: 50px; |
| + margin-block-start: 19px; |
| + translate: 0 -50%; |
| z-index: 30; |
| padding: 4px 8px; |
| border-radius: 6px; |
| @@ -201,8 +206,10 @@ kbd[mapa-kbd] { |
| background: var(--rst-accent); |
| } |
| [mapa-app]:not([data-side]) [mapa-side-label] { |
| - position: absolute; |
| - inset-inline-start: calc(100% + 10px); |
| + position: fixed; |
| + margin-inline-start: 50px; |
| + margin-block-start: 19px; |
| + translate: 0 -50%; |
| z-index: 30; |
| padding: 4px 8px; |
| border-radius: 6px; |
| @@ -373,31 +380,80 @@ textarea[mapa-editor]:focus { outline: none; box-shadow: none; } |
| [mapa-unsaved] p { margin: 0; flex: 1 1 16rem; } |
| -/* New team page: a popover from the sidebar's foot (§4.7). */ |
| -details[mapa-new-page] { position: relative; } |
| -details[mapa-new-page] > summary { list-style: none; } |
| -details[mapa-new-page] > summary::-webkit-details-marker { display: none; } |
| -form[mapa-new-page-form] { |
| - position: absolute; |
| - z-index: 40; |
| - inset-block-end: calc(100% + 6px); |
| - inset-inline-start: 0; |
| - display: grid; |
| - gap: 8px; |
| - inline-size: 260px; |
| +/* New team page (§4.7): a popover in the top layer, so the sidebar's |
| + overflow never clips it, whatever its state. Anchored to its button |
| + where the engine anchors: above it in the open sidebar, beside it on |
| + the rail. Elsewhere it sits fixed beside the sidebar's foot. */ |
| +[mapa-new-page-link] { display: none; } |
| +@supports not selector(:popover-open) { |
| + [mapa-new-page-open], [mapa-new-page] { display: none; } |
| + [mapa-new-page-link] { display: grid; } |
| +} |
| +[mapa-new-page-open] { anchor-name: --mapa-new-page; } |
| +[mapa-new-page] { |
| + box-sizing: border-box; |
| + inline-size: min(286px, calc(100vw - 16px)); |
| + margin: 0; |
| + inset: auto; |
| + inset-block-end: 12px; |
| + inset-inline-start: calc(var(--mapa-side-w) + 10px); |
| padding: 12px; |
| + overflow: visible; |
| border: 1px solid var(--rst-line); |
| border-radius: 12px; |
| background: var(--rst-surface); |
| + color: var(--rst-text); |
| box-shadow: 0 18px 40px -16px rgb(23 32 60 / 0.35); |
| + font-size: 13px; |
| } |
| +form[mapa-new-page-form] { display: grid; gap: 8px; margin: 0; } |
| form[mapa-new-page-form] label { font-size: 12px; font-weight: 650; color: var(--rst-text-muted); } |
| form[mapa-new-page-form] p { margin: 0; font-size: 12px; } |
| -@media (min-width: 800px) { |
| - [mapa-app][data-side="rail"] form[mapa-new-page-form] { inset-block-end: 0; inset-inline-start: calc(100% + 10px); } |
| +[mapa-new-page-error][hidden] { display: none; } |
| +[mapa-new-page-error] a { color: inherit; } |
| +@supports (anchor-name: --mapa-new-page) { |
| + [mapa-new-page] { |
| + position-anchor: --mapa-new-page; |
| + inset-block-end: calc(anchor(start) + 6px); |
| + inset-inline-start: anchor(start); |
| + position-try-fallbacks: flip-block; |
| + } |
| + @media (min-width: 800px) { |
| + [mapa-app][data-side="rail"] [mapa-new-page] { |
| + inset-block-end: anchor(end); |
| + inset-inline-start: calc(anchor(end) + 10px); |
| + } |
| + } |
| + @media (min-width: 800px) and (max-width: 79.99rem) { |
| + [mapa-app]:not([data-side]) [mapa-new-page] { |
| + inset-block-end: anchor(end); |
| + inset-inline-start: calc(anchor(end) + 10px); |
| + } |
| + } |
| } |
| -@media (min-width: 800px) and (max-width: 79.99rem) { |
| - [mapa-app]:not([data-side]) form[mapa-new-page-form] { inset-block-end: 0; inset-inline-start: calc(100% + 10px); } |
| + |
| +/* Where the engine anchors, each tooltip is tied to its own row |
| + (anchor-scope keeps the name to that row), so it follows the rail as |
| + it scrolls; a static position is fixed where layout put it. */ |
| +@supports (anchor-name: --mapa-side-item) { |
| + @media (min-width: 800px) { |
| + [mapa-side-item] { anchor-name: --mapa-side-item; anchor-scope: --mapa-side-item; } |
| + [mapa-new-page-open] { anchor-name: --mapa-new-page, --mapa-side-item; } |
| + [mapa-app][data-side="rail"] [mapa-side-label] { |
| + position-anchor: --mapa-side-item; |
| + inset-block-start: anchor(center); |
| + inset-inline-start: calc(anchor(end) + 10px); |
| + margin: 0; |
| + } |
| + } |
| + @media (min-width: 800px) and (max-width: 79.99rem) { |
| + [mapa-app]:not([data-side]) [mapa-side-label] { |
| + position-anchor: --mapa-side-item; |
| + inset-block-start: anchor(center); |
| + inset-inline-start: calc(anchor(end) + 10px); |
| + margin: 0; |
| + } |
| + } |
| } |
| /* Below 800px there is no sidebar: its places are rows in estilo's |
diff --git a/internal/mapa/static/mapa.js b/internal/mapa/static/mapa.js| index 359e922..d3d7567 100644 |
| --- a/internal/mapa/static/mapa.js |
| +++ b/internal/mapa/static/mapa.js |
| @@ -715,6 +715,98 @@ |
| }); |
| } |
| + // ---- New team page --------------------------------------------------------- |
| + // The sidebar's popover (level-up §4.7) needs no script: it opens, closes |
| + // and takes focus by itself, and posts; a refusal is then the New page |
| + // screen. This keeps a refusal in the popover, beside what was typed, |
| + // holds the POST for HOLD_MS as busy.js holds a form (so busy.js leaves |
| + // this one alone), and gives focus back to the button after Esc: WebKit |
| + // does not focus a button on a click, so it would leave focus nowhere. |
| + var HOLD_MS = 650; |
| + |
| + function newTeamPage() { |
| + var pop = document.getElementById("mapa-new-page"); |
| + var form = pop && pop.querySelector("form[mapa-new-page-form]"); |
| + var opener = document.querySelector("[mapa-new-page-open]"); |
| + if (!form || !opener || typeof pop.showPopover !== "function") return; |
| + var field = form.querySelector('input[name="title"]'); |
| + var said = form.querySelector("[mapa-new-page-error]"); |
| + var button = form.querySelector('button[type="submit"]'); |
| + var escaped = false, sending = false; |
| + form.setAttribute("data-busy", "false"); |
| + pop.addEventListener("keydown", function (event) { |
| + if (event.key === "Escape") escaped = true; |
| + }); |
| + pop.addEventListener("toggle", function (event) { |
| + if (event.newState === "open") { escaped = false; return; } |
| + // WebKit still names the hidden field as focused here. |
| + var here = document.activeElement; |
| + if (escaped && (!here || here === document.body || pop.contains(here))) { |
| + opener.focus({ preventScroll: true }); |
| + } |
| + }); |
| + field.addEventListener("input", function () { say(""); }); |
| + |
| + // say shows a refusal under the field, or clears it. |
| + function say(text, taken) { |
| + said.textContent = text; |
| + said.hidden = !text; |
| + if (taken) { |
| + var link = document.createElement("a"); |
| + link.href = taken; |
| + link.textContent = "Open the page with that title"; |
| + said.append(" ", link); |
| + } |
| + if (text) { |
| + field.setAttribute("aria-invalid", "true"); |
| + field.setAttribute("aria-describedby", "mapa-new-page-error mapa-new-page-said"); |
| + } else { |
| + field.removeAttribute("aria-invalid"); |
| + field.setAttribute("aria-describedby", "mapa-new-page-said"); |
| + } |
| + } |
| + |
| + function busy(on) { |
| + sending = on; |
| + button.disabled = on; |
| + var spin = button.querySelector("[rst-spin]"); |
| + if (on && !spin) { |
| + spin = document.createElement("span"); |
| + spin.setAttribute("rst-spin", ""); |
| + spin.setAttribute("aria-hidden", "true"); |
| + button.insertBefore(spin, button.firstChild); |
| + } else if (!on && spin) { |
| + spin.remove(); |
| + } |
| + if (on) button.setAttribute("aria-busy", "true"); else button.removeAttribute("aria-busy"); |
| + } |
| + |
| + form.addEventListener("submit", function (event) { |
| + event.preventDefault(); |
| + if (sending) return; |
| + busy(true); |
| + var wait = new Promise(function (resolve) { setTimeout(resolve, HOLD_MS); }); |
| + var sent = post(form.action, { title: field.value }).then(function (response) { |
| + return response.json().then(function (reply) { return { ok: response.ok, reply: reply }; }); |
| + }); |
| + Promise.all([sent, wait]).then(function (both) { |
| + var answer = both[0]; |
| + if (answer.ok && answer.reply.href) { |
| + window.location.assign(answer.reply.href); |
| + return; |
| + } |
| + if (!answer.reply.error) throw new Error("no answer"); |
| + busy(false); |
| + say(answer.reply.error, answer.reply.taken); |
| + field.focus(); |
| + }).catch(function () { |
| + busy(false); |
| + say("The page could not be created just now. Try again."); |
| + field.focus(); |
| + }); |
| + }); |
| + } |
| + |
| // ---- Start ---------------------------------------------------------------- |
| function start() { |
| @@ -743,6 +835,7 @@ |
| fold(); |
| } |
| }); |
| + newTeamPage(); |
| offerZone(); |
| } |
diff --git a/internal/mapa/templates/frame.html b/internal/mapa/templates/frame.html| index cfa281f..8507aa0 100644 |
| --- a/internal/mapa/templates/frame.html |
| +++ b/internal/mapa/templates/frame.html |
| @@ -133,15 +133,10 @@ |
| {{- range .}}{{template "mapa-side-link" .}}{{end}} |
| {{- end}} |
| <div mapa-side-foot> |
| - <details mapa-new-page name="estilo-menus"> |
| - <summary mapa-side-item>{{icon "plus"}}<span mapa-side-label>New team page</span></summary> |
| - <form method="post" action="/pages" mapa-new-page-form> |
| - <label for="mapa-new-title">Title of the new team page</label> |
| - <input rst-input id="mapa-new-title" name="title" required maxlength="120" autocomplete="off"> |
| - <p mapa-meta>Everyone in the team can open it.</p> |
| - <button rst-btn="primary" type="submit">Create page</button> |
| - </form> |
| - </details> |
| + {{- /* New team page (§4.7) opens mapa-new-page, a popover. The link |
| + is for an engine without popovers (frame.css shows it there). */}} |
| + <button mapa-side-item type="button" popovertarget="mapa-new-page" mapa-new-page-open>{{icon "plus"}}<span mapa-side-label>New team page</span></button> |
| + <a mapa-side-item href="/new" mapa-new-page-link>{{icon "plus"}}<span mapa-side-label>New team page</span></a> |
| <form method="post" action="/view/sidebar" mapa-fold> |
| <input type="hidden" name="return" value="{{.Return}}"> |
| <button mapa-side-item type="submit" name="state" value="rail" mapa-fold-to="rail" data-mapa-command="toggle-sidebar">{{icon "panel-left"}}<span mapa-side-label>Fold sidebar</span><kbd mapa-kbd aria-hidden="true">⌘\</kbd></button> |
| @@ -151,6 +146,22 @@ |
| </nav>{{end}} |
| {{define "mapa-side-link"}}<a mapa-side-item mapa-side-page href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{icon .Icon}}<span mapa-side-label>{{.Label}}</span></a>{{end}} |
| +{{/* mapa-new-page: New team page's popover (§4.7), opened by the |
| + sidebar's button. In the top layer, so the sidebar's scrolling never |
| + clips it, and the platform's own Esc, click outside and focus, with |
| + no script. Drawn after <main>: WebKit gives the page's autofocus to |
| + the first [autofocus] in the document, even a hidden one, so this |
| + field must come after a screen's own. */}} |
| +{{define "mapa-new-page"}}<div popover id="mapa-new-page" mapa-new-page role="dialog" aria-label="New team page"> |
| + <form method="post" action="/pages" mapa-new-page-form> |
| + <label for="mapa-new-title">Title of the new team page</label> |
| + <input rst-input id="mapa-new-title" name="title" required maxlength="120" autocomplete="off" autofocus aria-describedby="mapa-new-page-said"> |
| + <p rst-field-error mapa-new-page-error id="mapa-new-page-error" role="alert" hidden></p> |
| + <p mapa-meta id="mapa-new-page-said">Everyone in the team can open it.</p> |
| + <button rst-btn="primary" type="submit">Create page</button> |
| + </form> |
| +</div>{{end}} |
| + |
| {{/* mapa-keys: Help → Keyboard shortcuts. A <dialog> estilo's invoker |
| command opens, with no script. */}} |
| {{define "mapa-keys"}}<dialog id="mapa-keys" mapa-dialog aria-labelledby="mapa-keys-title"> |
diff --git a/internal/mapa/templates/page_new.html b/internal/mapa/templates/page_new.html| index b6289f7..fddc402 100644 |
| --- a/internal/mapa/templates/page_new.html |
| +++ b/internal/mapa/templates/page_new.html |
| @@ -1,10 +1,14 @@ |
| {{define "content"}} |
| {{template "back-nav" dict "Href" "/pages" "Label" "Pages"}} |
| {{template "page-header" dict "Title" "New page" "Sub" "A team page: everyone in the team can open it, and its title is the team's."}} |
| -<form rst-form method="post" action="{{.Data.Action}}" mapa-edit-form> |
| +{{/* One title field, as the sidebar's popover (level-up §4.7): the page |
| + opens once it is made, and its text is written there. A body that |
| + came with a refused POST rides along unseen, so nothing typed is |
| + lost. */}} |
| +<form rst-form method="post" action="{{.Data.Action}}"> |
| {{template "field-text" dict "Name" "title" "Label" "Title" "Value" .Data.Title "Error" .Data.Error "Required" true "Autofocus" true}} |
| {{with .Data.Taken}}<p mapa-meta><a href="{{.}}">Open the page with that title</a></p>{{end}} |
| -{{template "mapa-editor" dict "Body" .Data.Body}} |
| +{{with .Data.Body}}<input type="hidden" name="body" value="{{.}}">{{end}} |
| {{template "form-foot" dict "Submit" .Data.Label "CancelHref" "/pages" "CancelLabel" "Cancel"}} |
| </form> |
| {{end}} |
diff --git a/internal/mapa/templates/shell.html b/internal/mapa/templates/shell.html| index 9bfe97e..e3ccd36 100644 |
| --- a/internal/mapa/templates/shell.html |
| +++ b/internal/mapa/templates/shell.html |
| @@ -41,6 +41,7 @@ |
| {{template "content" .}} |
| </div> |
| </main> |
| +{{template "mapa-new-page"}} |
| {{with .Frame.History}}{{template "mapa-history" .}}{{end}} |
| </div> |
| {{template "mapa-keys"}} |
diff --git a/internal/mapatest/browser_test.go b/internal/mapatest/browser_test.go| index c4691e4..678cae4 100644 |
| --- a/internal/mapatest/browser_test.go |
| +++ b/internal/mapatest/browser_test.go |
| @@ -146,10 +146,7 @@ func walk(t *testing.T, rig *harness.Rig, store *mapa.Store, live bool) { |
| searchByPage(t, rig) |
| } |
| rig.Screen(`main input[name="title"]`, "create, offered") |
| - drive(t, rig, |
| - chromedp.SendKeys("textarea[mapa-editor]", "Acme is a customer."), |
| - press(save), |
| - ) |
| + createAcme(t, rig) |
| rig.Screen("header[mapa-page-head]", "the new page") |
| if !strings.Contains(text(t, rig, "#backlinks ~ *, [mapa-linked]"), |
| "November") { |
| @@ -162,6 +159,19 @@ func walk(t *testing.T, rig *harness.Rig, store *mapa.Store, live bool) { |
| historyAndRestore(t, rig) |
| } |
| +// createAcme creates the offered page, then writes its text. New page |
| +// is one title field (build note 77), so the text is written on the |
| +// page, here through Edit as Markdown, the floor. |
| +func createAcme(t *testing.T, rig *harness.Rig) { |
| + t.Helper() |
| + drive(t, rig, press(save), chromedp.WaitVisible("h1[mapa-title]")) |
| + path := strings.TrimPrefix(read(t, rig, chromedp.Location()), |
| + rig.Origin) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+path+"/edit"), |
| + chromedp.SendKeys("textarea[mapa-editor]", "Acme is a customer."), |
| + press(save)) |
| +} |
| + |
| // writeToday writes today's note: in the page editor with scripts, and |
| // with them off through Edit as Markdown, the floor (level-up §6.10). |
| func writeToday(t *testing.T, rig *harness.Rig, live bool) { |
diff --git a/internal/mapatest/layout_browser_test.go b/internal/mapatest/layout_browser_test.go| index 79e489a..f95c17e 100644 |
| --- a/internal/mapatest/layout_browser_test.go |
| +++ b/internal/mapatest/layout_browser_test.go |
| @@ -137,7 +137,7 @@ func walkRename(t *testing.T, rig *harness.Rig, path string) { |
| func walkNewAndShare(t *testing.T, rig *harness.Rig) { |
| t.Helper() |
| drive(t, rig, chromedp.Navigate(rig.Origin+"/pages"), |
| - chromedp.Click(`[mapa-new-page] > summary`), |
| + chromedp.Click(opener), |
| chromedp.SendKeys(`#mapa-new-title`, "From the sidebar"), |
| chromedp.Submit(`#mapa-new-title`), |
| chromedp.WaitVisible("h1[mapa-title]")) |
diff --git a/internal/mapatest/newpage_browser_test.go b/internal/mapatest/newpage_browser_test.go| new file mode 100644 |
| index 0000000..206db57 |
| --- /dev/null |
| +++ b/internal/mapatest/newpage_browser_test.go |
| @@ -0,0 +1,258 @@ |
| +//go:build browser |
| + |
| +package mapatest |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/rastrillo/rastrillo/harness" |
| + "github.com/chromedp/cdproto/cdp" |
| + "github.com/chromedp/cdproto/input" |
| + "github.com/chromedp/cdproto/network" |
| + "github.com/chromedp/chromedp" |
| +) |
| + |
| +// New team page (level-up §4.7) and the rail's tooltips (§3.2), in |
| +// Chromium (build note 77). The sidebar scrolls (overflow: auto), and |
| +// everything that left it was clipped: the popover's right side in the |
| +// open sidebar, all of it beside the rail, and every tooltip. Each check |
| +// asks the page what a pointer would hit at the corners of what must be |
| +// seen, so a box that is laid out but cut off fails. |
| + |
| +// opener is the sidebar's New team page control, as either shape has |
| +// drawn it (a <details>' summary before build note 77, now a button). |
| +const opener = `[mapa-side-foot] ` + |
| + `:is(summary, [popovertarget])[mapa-side-item]` |
| + |
| +// sideCookie sets the mapa-sidebar cookie, or deletes it for "". |
| +func sideCookie(rig *harness.Rig, |
| + state string) chromedp.Action[chromedp.Void] { |
| + return chromedp.Func(func(ctx context.Context, |
| + target *chromedp.Target) error { |
| + where := rig.Origin + "/" |
| + if state == "" { |
| + _, err := cdp.Call(ctx, target, network.DeleteCookies, |
| + network.DeleteCookiesParams{Name: "mapa-sidebar", URL: where}) |
| + return err |
| + } |
| + _, err := cdp.Call(ctx, target, network.SetCookie, |
| + network.SetCookieParams{Name: "mapa-sidebar", Value: state, |
| + URL: where}) |
| + return err |
| + }) |
| +} |
| + |
| +// cornersHit is, for each part inside box, every corner (3px in, past |
| +// a rounded border) where the topmost element is not inside box: "" |
| +// when the whole of every part can be seen and clicked. |
| +const cornersHit = `(function (box, parts) { |
| + var holder = document.querySelector(box), misses = []; |
| + parts.forEach(function (part) { |
| + var el = holder && holder.querySelector(part); |
| + if (!el) { misses.push(part + " is not drawn"); return; } |
| + var r = el.getBoundingClientRect(); |
| + [[r.left + 3, r.top + 3], [r.right - 3, r.top + 3], |
| + [r.left + 3, r.bottom - 3], [r.right - 3, r.bottom - 3] |
| + ].forEach(function (p) { |
| + var hit = document.elementFromPoint(p[0], p[1]); |
| + if (hit && holder.contains(hit)) return; |
| + misses.push(part + " at " + Math.round(p[0]) + "," + Math.round(p[1]) + |
| + " is " + (hit ? hit.tagName.toLowerCase() : "off the screen")); |
| + }); |
| + }); |
| + return misses.join("; "); |
| +})(%q, ["input[name=title]", "button[type=submit]"])` |
| + |
| +// sideCase is one sidebar state at one width: the cookie ("" for none) |
| +// and what the sidebar shows then. |
| +type sideCase struct { |
| + width int64 |
| + cookie, show string |
| +} |
| + |
| +var sideCases = []sideCase{ |
| + {1400, "", "open"}, {1400, "rail", "rail"}, {1400, "open", "open"}, |
| + {900, "", "rail"}, {900, "open", "open"}, {900, "rail", "rail"}, |
| +} |
| + |
| +// From the sidebar, in every state, scripts off and on: the whole form |
| +// is on top, focus is in the title, and Enter creates the page and opens |
| +// it. At 390 there is no sidebar: Page → New team page is the screen. |
| +func TestNewTeamPageShowsTheWholeForm(t *testing.T) { |
| + rig, _ := browserRig(t, 1) |
| + for _, live := range []bool{false, true} { |
| + for number, each := range sideCases { |
| + name := fmt.Sprintf("%dpx, %s (cookie %q), scripts %v", |
| + each.width, each.show, each.cookie, live) |
| + drive(t, rig, scripts(live), sideCookie(rig, each.cookie), |
| + chromedp.EmulateViewport(each.width, 877), |
| + chromedp.Navigate(rig.Origin+"/pages"), |
| + chromedp.WaitVisible("main h1"), |
| + chromedp.Click(opener), chromedp.WaitVisible("#mapa-new-title")) |
| + title := fmt.Sprintf("Sidebar %d %v", number, live) |
| + createFrom(t, rig, name, "form[mapa-new-page-form]", |
| + "mapa-new-title", title) |
| + } |
| + name := fmt.Sprintf("390px, Page menu, scripts %v", live) |
| + drive(t, rig, scripts(live), sideCookie(rig, ""), |
| + chromedp.EmulateViewport(390, 844), |
| + chromedp.Navigate(rig.Origin+"/pages"), |
| + chromedp.Click(pageMenu), |
| + chromedp.Click(`#mapa-menu-page a[href="/new"]`), |
| + chromedp.WaitVisible(`main input[name="title"]`)) |
| + createFrom(t, rig, name, `main form[action="/pages"]`, "title", |
| + fmt.Sprintf("Phone %v", live)) |
| + } |
| +} |
| + |
| +// createFrom checks the open form, then types title into whatever has |
| +// focus and presses Enter, as a person would, and waits for the page. |
| +func createFrom(t *testing.T, rig *harness.Rig, name, form, field, |
| + title string) { |
| + t.Helper() |
| + if misses := read(t, rig, chromedp.Evaluate[string]( |
| + fmt.Sprintf(cornersHit, form))); misses != "" { |
| + t.Errorf("%s: the form is not all on top: %s", name, misses) |
| + } |
| + focus := read(t, rig, chromedp.Evaluate[string]( |
| + `document.activeElement.id || document.activeElement.name || ""`)) |
| + if focus != field { |
| + t.Errorf("%s: focus is on %q, not the title", name, focus) |
| + } |
| + drive(t, rig, chromedp.KeyEvent(title), chromedp.KeyEvent("\r")) |
| + if !landsOn(t, rig, title) { |
| + t.Errorf("%s: Enter did not open a page titled %q", name, title) |
| + } |
| +} |
| + |
| +// landsOn waits up to five seconds for a page titled title. |
| +func landsOn(t *testing.T, rig *harness.Rig, title string) bool { |
| + t.Helper() |
| + check := fmt.Sprintf(`location.pathname.indexOf("/p/") === 0 && |
| + (document.querySelector("h1[mapa-title]") || {}).textContent === %q`, |
| + title) |
| + for range 50 { |
| + if read(t, rig, chromedp.Evaluate[bool](check)) { |
| + return true |
| + } |
| + time.Sleep(100 * time.Millisecond) |
| + } |
| + return false |
| +} |
| + |
| +// A taken title is refused where it was typed, and what was typed |
| +// stays: in the popover with scripts, on the New page screen without. |
| +func TestNewTeamPageRefusesATakenTitleInPlace(t *testing.T) { |
| + rig, store := browserRig(t, 0) |
| + if _, err := store.CreateTeamPage(context.Background(), Bo, |
| + "Onboarding", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + rig.Allow("POST", "/pages", 422) |
| + for _, live := range []bool{false, true} { |
| + drive(t, rig, scripts(live), chromedp.EmulateViewport(1400, 877), |
| + chromedp.Navigate(rig.Origin+"/pages"), |
| + chromedp.Click(opener), chromedp.WaitVisible("#mapa-new-title"), |
| + chromedp.KeyEvent("Onboarding"), chromedp.KeyEvent("\r"), |
| + chromedp.Sleep(1200*time.Millisecond)) |
| + where := `[mapa-new-page]:popover-open` |
| + if !live { |
| + where = "main" |
| + } |
| + said := read(t, rig, chromedp.Evaluate[string](fmt.Sprintf( |
| + `(document.querySelector(%q) || {}).textContent || ""`, |
| + where+" [rst-field-error]:not([hidden])"))) |
| + kept := read(t, rig, chromedp.Evaluate[string](fmt.Sprintf( |
| + `(document.querySelector(%q) || {}).value || ""`, |
| + where+` input[name="title"]`))) |
| + if !strings.Contains(said, "already exists") || kept != "Onboarding" { |
| + t.Errorf("scripts %v: refusal %q, field %q", live, said, kept) |
| + } |
| + } |
| +} |
| + |
| +// The New page screen's Create and Cancel sit under its one field, as |
| +// on every other form (they were under a borderless body field half the |
| +// window tall). |
| +func TestTheNewPageScreenKeepsItsButtonsUnderTheField(t *testing.T) { |
| + rig, _ := browserRig(t, 1) |
| + gap := `Math.round(document.querySelector('main [rst-form-foot]')` + |
| + `.getBoundingClientRect().top - document.querySelector(` + |
| + `'main input[name="title"]').getBoundingClientRect().bottom)` |
| + for _, live := range []bool{false, true} { |
| + for _, size := range [][2]int64{{1402, 877}, {390, 844}} { |
| + drive(t, rig, scripts(live), |
| + chromedp.EmulateViewport(size[0], size[1]), |
| + chromedp.Navigate(rig.Origin+"/new"), |
| + chromedp.WaitVisible(`main input[name="title"]`)) |
| + if got := read(t, rig, chromedp.Evaluate[int](gap)); got < 0 || |
| + got > 48 { |
| + t.Errorf("%dx%d, scripts %v: the buttons are %dpx under "+ |
| + "the field", size[0], size[1], live, got) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// labelSeen is "" when the hovered row's tooltip can be hit at all four |
| +// corners; it takes pointer events for the moment it is asked. |
| +const labelSeen = `(function (row) { |
| + var label = document.querySelector(row + " [mapa-side-label]"); |
| + label.style.pointerEvents = "auto"; |
| + var r = label.getBoundingClientRect(), misses = []; |
| + [[r.left + 3, r.top + 3], [r.right - 3, r.top + 3], |
| + [r.left + 3, r.bottom - 3], [r.right - 3, r.bottom - 3] |
| + ].forEach(function (p) { |
| + if (!label.contains(document.elementFromPoint(p[0], p[1]))) { |
| + misses.push(Math.round(p[0]) + "," + Math.round(p[1])); |
| + } |
| + }); |
| + label.style.pointerEvents = ""; |
| + return misses.length ? label.textContent + " cut off at " + |
| + misses.join(" ") : ""; |
| +})(%q)` |
| + |
| +// Every row of the rail shows its whole tooltip on hover: by width with |
| +// no cookie, and by cookie on a wide window. |
| +func TestTheRailsTooltipsAreWhole(t *testing.T) { |
| + rig, _ := browserRig(t, 1, harness.WithHover()) |
| + mark := `Array.prototype.filter.call(document.querySelectorAll(` + |
| + `"[mapa-side] [mapa-side-item]"), function (row) {` + |
| + ` return row.offsetParent !== null; }).map(function (row, i) {` + |
| + ` row.setAttribute("data-gate-row", i); return i; }).length` |
| + for _, each := range []sideCase{{900, "", "rail"}, {1400, "rail", "rail"}} { |
| + drive(t, rig, sideCookie(rig, each.cookie), |
| + chromedp.EmulateViewport(each.width, 877), |
| + chromedp.Navigate(rig.Origin+"/pages"), |
| + chromedp.WaitVisible("main h1")) |
| + rows := read(t, rig, chromedp.Evaluate[int](mark)) |
| + for row := range rows { |
| + selector := fmt.Sprintf(`[data-gate-row="%d"]`, row) |
| + drive(t, rig, rest(selector)) |
| + if miss := read(t, rig, chromedp.Evaluate[string]( |
| + fmt.Sprintf(labelSeen, selector))); miss != "" { |
| + t.Errorf("%dpx (cookie %q): %s", each.width, each.cookie, miss) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// rest moves a hovering mouse to the middle of selector's element. |
| +func rest(selector string) chromedp.Action[chromedp.Void] { |
| + return chromedp.Func(func(ctx context.Context, |
| + target *chromedp.Target) error { |
| + box, err := chromedp.Run(ctx, chromedp.Dimensions(selector)) |
| + if err != nil { |
| + return err |
| + } |
| + quad := box.Content |
| + across, down := (quad[0]+quad[4])/2, (quad[1]+quad[5])/2 |
| + return chromedp.Do(ctx, chromedp.MouseEvent( |
| + input.DispatchMouseEventTypeMouseMoved, across, down), |
| + chromedp.Sleep(80*time.Millisecond)) |
| + }) |
| +} |
diff --git a/internal/mapatest/share_json_test.go b/internal/mapatest/share_json_test.go| index 17f5b23..3c447ac 100644 |
| --- a/internal/mapatest/share_json_test.go |
| +++ b/internal/mapatest/share_json_test.go |
| @@ -39,3 +39,30 @@ func TestMakeTeamPageAnswersTheEditor(t *testing.T) { |
| t.Fatal("the new team page does not hold the blocks") |
| } |
| } |
| + |
| +// New team page's popover (level-up §4.7, build note 77): with Accept |
| +// JSON, POST /pages answers the new page's address, and a refused title |
| +// is the sentence, as JSON, with nothing written. |
| +func TestNewTeamPageAnswersThePopover(t *testing.T) { |
| + rig := newRig(t) |
| + taken := rig.createPage(t, Bo, "Taken", "") |
| + pages := rig.count(t, "pages") |
| + for _, title := range []string{"Taken", " "} { |
| + code, refused := rig.postJSON(Ana, "/pages", |
| + url.Values{"title": {title}}) |
| + if code != http.StatusUnprocessableEntity || refused["error"] == "" || |
| + rig.count(t, "pages") != pages { |
| + t.Fatalf("%q: %d %v", title, code, refused) |
| + } |
| + if title == "Taken" && refused["taken"] != taken { |
| + t.Fatalf("a taken title points to %v, not %s", refused["taken"], |
| + taken) |
| + } |
| + } |
| + code, reply := rig.postJSON(Ana, "/pages", url.Values{"title": {"Fresh"}}) |
| + href, _ := reply["href"].(string) |
| + if code != http.StatusOK || !strings.HasPrefix(href, "/p/") || |
| + !strings.Contains(rig.page(t, Bo, href), "Fresh") { |
| + t.Fatalf("POST /pages answered %d %v", code, reply) |
| + } |
| +} |