oficina / mapa Public

Answer Fable's review of the phase 1 build

⌘K draws icons; an icon or banner post naming no picture is refused;
a position post choosing none keeps the stored one; Reposition is a
real button armed after its key, with touch and pointer-cancel handled
and Esc to cancel; the busy rule shows on the controls; History draws
no broken icon; a refused script upload is dropped only when it is the
person's own pending picture; the emoji field is trimmed; the cache
entry is dropped again after a removal commits. Gates for each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 7643c982470c85d9550d9aa7bff46cf61af5d329 parent 57bdadc
15 files changed, +295 −42
  • copy-review/looks/result.json +6 −1
  • copy-review/looks/strings.json +8 −0
  • internal/mapa/handlers_history.go +1 −0
  • internal/mapa/handlers_look.go +30 −7
  • internal/mapa/images_remove.go +4 −0
  • internal/mapa/looks.go +3 −0
  • internal/mapa/looks_images.go +32 −1
  • internal/mapa/looks_render.go +16 −0
  • internal/mapa/looks_test.go +27 −0
  • internal/mapa/static/frame.css +1 −1
  • internal/mapa/static/look.js +78 −28
  • internal/mapa/static/mapa.js +17 −4
  • internal/mapa/templates/partials.html +1 −0
  • internal/mapatest/looks_browser_test.go +45 −0
  • internal/mapatest/looks_test.go +26 −0

CI failed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 319ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.f6564510471eef37.js (354434 bytes, 111.4KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ a badge is named for what it does, starting with its visible word (0.923828ms)
✔ first words stop at five words or forty characters (0.151101ms)
✔ the field keeps one trimmed line, without brackets (0.239105ms)
✔ the field holds at most MaxAlt bytes, cut at a character (0.472489ms)
✔ days and weeks move across months and years (1.058999ms)
✔ a month keeps the day, or takes the month's last (0.223615ms)
✔ the grid is six weeks from Monday, as the month calendar draws it (0.477999ms)
✔ the grid starts the week where the locale does (0.366451ms)
✔ the keys move a day, a week, a month and a year (0.773198ms)
✔ the picked day is the chip [[ makes for a date (12.436266ms)
✔ Insert → Today's date still puts today in at once (3.491632ms)
✔ / offers Date, the picker, and Today's date beside it (0.297173ms)
✔ after a ! the chip goes in after a space, never as an embed (2.622397ms)
✔ where the Markdown would read the chip differently, it is refused (2.275072ms)
✔ over a selection the chip goes after it and the words stay (2.234204ms)
✔ today is the day in the viewer's zone (18.646043ms)
✔ every offered locale has cases (0.987065ms)
✔ dates.mjs writes every date Go writes, byte for byte (3.433444ms)
✔ a chip, the month and the week, in three locales (0.571413ms)
✔ dates.json is what ICU gives, byte for byte (466.434738ms)
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (78.50047ms)
ℹ 871 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (75.789537ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (120.006273ms)
ℹ 858 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (129.472055ms)
ℹ 866 inserts, 817 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (4167.098473ms)
ℹ 20904 edits over 871 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1017.466752ms)
ℹ 4532 links over 871 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":918,"A page link can’t show [ or ]]. Select words without them.":404,"Select some words to link them to a page.":174,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":18}
✔ L3: a picked date is one more date chip, or refused where a letter would be too (1102.735718ms)
ℹ over 871 bodies: {"inserted":5158,"spaced":23,"refused":45,"unstable":9}
✔ linear: trailing spaces (24.623389ms)
✔ linear: trailing whitespace (23.954716ms)
✔ linear: unclosed web links (30.609873ms)
✔ linear: web links with no address (24.915432ms)
✔ linear: unclosed wiki links (22.720852ms)
✔ linear: unclosed embeds (17.567259ms)
✔ linear: closes only (4.365979ms)
✔ the selected words become the chip's shown text (10.151699ms)
✔ words that are the title make a plain [[Title]] (2.76401ms)
✔ spaces at the selection's edges stay outside the chip (1.069479ms)
✔ a date makes a date link, in a heading, an item and a quote (7.803601ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (3.685484ms)
✔ only the linked block's bytes change, and undo gives the body back (1.965485ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (7.452368ms)
✔ a target the words cannot be linked to as typed is refused (0.233114ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.006401ms)
✔ web-linked words are refused: the address would be lost (review M4) (1.060071ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.57574ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.361372ms)
✔ linkCheck says why it refuses (review low 2) (0.591269ms)
✔ golden file has bodies (0.952712ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (28.023703ms)
✔ markup.mjs strips and spans every block as Go does (41.646225ms)
✔ the schema's toDOM draws every body as Go renders it (60.607346ms)
✔ emphasis draws the four pinned outputs (16.058151ms)
✔ a body ends in the editor's empty paragraph (0.206354ms)
✔ the editor labels date chips as Go does, in every locale L4 holds (10.542526ms)
✔ a POST that never answers is aborted after the timeout (21.362266ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.231119ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (11.281919ms)
✔ an offered draft never commits by itself; Save commits it (1.433856ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.62419ms)
✔ closing carries text not yet sent, and the cap leaves it out (43.749336ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (3.176587ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (2.74227ms)
✔ typing mid-flight: the merge is not applied and the base does not move (0.984922ms)
✔ a merge the editor cannot represent stops after three tries (2.959644ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (0.998617ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.397379ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (0.834652ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.653786ms)
✔ noBase and gone lead to the existing choices (0.751568ms)
✔ a commit that merged is applied when nothing was typed since (0.877522ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (6.769618ms)
✔ an own draft committed meanwhile goes on as a new draft (1.125774ms)
✔ a reload keeps a stored draft; unsent text still commits (0.494529ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (1.035957ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.417716ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.323131ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (4.537638ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (1.220049ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.35497ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.988699ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.527621ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (1.002424ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.670587ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.691636ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (6.810696ms)
✔ marks close before code, links and atoms, and reopen after (0.883363ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (12.870884ms)
✔ empty blocks are written as nothing (3.003565ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.983949ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (2.681707ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (5.018593ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (3.951938ms)
✔ a trailing hard break stays on screen and is written as nothing (5.99602ms)
✔ the reparse waits while an IME is composing (1.073937ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.616234ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.624161ms)
✔ rebuild changes origins only, outside undo history (1.203658ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.867904ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.7255ms)
✔ a duplicate ^id typed above its holder never takes the id from it (0.745276ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (0.99496ms)
✔ a history command that throws is refused, never thrown (4.271183ms)
✔ an image re-emits its source, and an edited alt changes only its span (1.421062ms)
✔ a paste whose image copy is refused says why and pastes nothing (15.712489ms)
✔ a line of image openers reads in linear time (92.161622ms)
✔ a line of shared link address reads in linear time (7.836644ms)
✔ a line of shared web address reads in linear time (38.773483ms)
✔ one rename at a time, from either field (2.013504ms)
✔ an empty or unchanged title sends nothing (0.219919ms)
✔ a refusal keeps what was typed, and the title (0.272226ms)
✔ the pending state holds for the busy rule (5.386376ms)
✔ a failed POST says so and keeps the title (0.394253ms)
✔ Update links posts the confirm page's POST (0.276384ms)
✔ clean is CleanTitle's whitespace rule (0.127327ms)
✔ the saver's base follows a rename made over it, and only that (0.304125ms)
✔ closing sends the rename as one keepalive POST (1.681577ms)
✔ the port answers every shared case as typeddate.go does (7.804122ms)
✔ numbers follow the locale: 12/11 is November in en-IE, December in en-US (0.288026ms)
✔ M6: several files land in the order they were chosen (44.74601ms)
✔ M5: one Backspace before the box keeps the image where the box is (11.654853ms)
✔ M5: undoing text typed just before the box keeps the upload (11.899469ms)
✔ L12: a failed upload an undo takes away does not stall the next (14.746552ms)
✔ M4: Replace… keeps the old image until the new one is in, and its alt (14.55187ms)
✔ M3 and N1: text wins, except over a picture copied from a page (1.607049ms)
✔ N2: a JPEG over 10 MB is scaled before its size is checked (5.171757ms)
✔ a drag whose anchor the document no longer reaches selects to its end (5.737118ms)
ℹ tests 126
ℹ suites 0
ℹ pass 126
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 6833.73115
=== 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.
internal/mapatest/looks_browser_test.go line 168: 87 columns wide, over the 80 allowed. Wrap the line, or add a record with a reason to .rastrillo/code.txt.
rastrillo: budget code: 1 problem
make: *** [Makefile:69: code] Error 1

amadan: step code failed: exit status 2

amadan: job failed at step code — its output is above, not at the tail of this log
diff --git a/copy-review/looks/result.json b/copy-review/looks/result.json
index 1f1d25b..0eb6533 100644
--- a/copy-review/looks/result.json
+++ b/copy-review/looks/result.json
@@ -1,7 +1,7 @@
{
"action": "approve",
"guidance": null,
- "note": "Reviewed 2026-11-22 by Luna (gpt-5.6-luna through Codex), the copy-review gate for Oficina copy since Paul's delegation. Luna's edits are applied, except where listed under not_applied.",
+ "note": "Reviewed 2026-11-22 by Luna (gpt-5.6-luna through Codex), the copy-review gate for Oficina copy since Paul's delegation. Luna's edits are applied, except where listed under not_applied. A second pass the same day reviewed look.picker.load_failed, added after the build's review.",
"not_applied": [
{
"id": "look.page.sub",
@@ -284,6 +284,11 @@
"id": "look.history.unknown",
"text": "Changed how the page looks",
"was": null
+ },
+ {
+ "id": "look.picker.load_failed",
+ "text": "The emoji list didn't load. Type an emoji, or upload a picture.",
+ "was": "The emoji didn't load. Type one, or upload a picture."
}
]
}
\ No newline at end of file
diff --git a/copy-review/looks/strings.json b/copy-review/looks/strings.json
index aa7c002..d24c475 100644
--- a/copy-review/looks/strings.json
+++ b/copy-review/looks/strings.json
@@ -422,5 +422,13 @@
"text": "Changed how the page looks",
"context": "History summary when the version before has aged out, so nothing can be compared.",
"notes": ""
+ },
+ {
+ "id": "look.picker.load_failed",
+ "section": "Icon picker",
+ "label": "look.picker.load_failed",
+ "text": "The emoji didn't load. Type one, or upload a picture.",
+ "context": "Shown in the picker when the emoji list could not be fetched. Typing an emoji and Upload a picture… still work.",
+ "notes": "Added after Fable's review of the build."
}
]
\ No newline at end of file
diff --git a/internal/mapa/handlers_history.go b/internal/mapa/handlers_history.go
index c0bbcb3..39a259b 100644
--- a/internal/mapa/handlers_history.go
+++ b/internal/mapa/handlers_history.go
@@ -112,6 +112,7 @@ func (app *app) showVersion(writer http.ResponseWriter,
then := page
then.Banner = chosen.Record.Banner
data.Band = app.bannerOf(request, viewer, then)
+ data.Look = app.drawableIcon(request, viewer, page.ID, data.Look)
}
app.show(writer, request, http.StatusOK, "revision", view{
Title: page.Label, Nav: nav(navFor(page.Kind)), Viewer: viewer,
diff --git a/internal/mapa/handlers_look.go b/internal/mapa/handlers_look.go
index e37c282..7ecb71f 100644
--- a/internal/mapa/handlers_look.go
+++ b/internal/mapa/handlers_look.go
@@ -5,6 +5,9 @@ import (
"errors"
"net/http"
"strconv"
+ "strings"
+
+ "amadan.net/oficina/mapa/internal/mapa/markup"
"github.com/go-chi/chi/v5"
)
@@ -99,7 +102,7 @@ func (app *app) answerLook(writer http.ResponseWriter,
}
func (app *app) dropUpload(ctx context.Context, address, public string) {
- if err := app.store.RemoveImage(ctx, address, public); err != nil {
+ if err := app.store.DropOwnPending(ctx, address, public); err != nil {
app.logger.Error("a refused look image was not removed",
"err", err)
}
@@ -114,13 +117,22 @@ func (app *app) lookChange(writer http.ResponseWriter,
if err != nil {
return LookChange{}, "", err
}
- change, err := lookOf(request.URL.Query().Get("for"),
- image.PublicID, request)
+ upload := request.URL.Query().Get("for")
+ if upload != "icon" && upload != "banner" {
+ return LookChange{}, image.PublicID, errLookUnknown
+ }
+ change, err := lookOf(upload, image.PublicID, request)
return change, image.PublicID, err
}
- change, err := lookOf(request.PostFormValue("do"),
- request.PostFormValue("image"), request)
- return change, "", err
+ image := request.PostFormValue("image")
+ change, err := lookOf(request.PostFormValue("do"), image, request)
+ if err != nil || !(change.SetIcon && change.Icon != nil &&
+ change.Icon.Image != "") && !(change.Banner != nil &&
+ change.Banner.Image != "") {
+ image = ""
+ }
+ // A picture the script uploaded is dropped if the look refuses it.
+ return change, image, err
}
// maxLookForm bounds the look form's text fields.
@@ -135,17 +147,28 @@ var errLookUnknown = ErrNotFound
func lookOf(do, image string, request *http.Request) (LookChange, error) {
position, err := strconv.Atoi(request.PostFormValue("y"))
if err != nil {
+ if do == "position" {
+ // No position chosen keeps the one stored (§3.2).
+ return LookChange{}, nil
+ }
position = 50
}
switch do {
case "emoji":
- icon, err := EmojiIcon(request.PostFormValue("emoji"))
+ icon, err := EmojiIcon(strings.TrimSpace(
+ request.PostFormValue("emoji")))
return LookChange{SetIcon: true, Icon: icon}, err
case "icon":
+ if !markup.IsImageID(image) {
+ return LookChange{}, errLookUnknown
+ }
return LookChange{SetIcon: true, Icon: &Icon{Image: image}}, nil
case "remove-icon":
return LookChange{SetIcon: true}, nil
case "banner":
+ if !markup.IsImageID(image) {
+ return LookChange{}, errLookUnknown
+ }
return LookChange{SetBanner: true,
Banner: &Banner{Image: image, Y: position}}, nil
case "remove-banner":
diff --git a/internal/mapa/images_remove.go b/internal/mapa/images_remove.go
index 675579e..22b6d5a 100644
--- a/internal/mapa/images_remove.go
+++ b/internal/mapa/images_remove.go
@@ -53,6 +53,10 @@ func (store *Store) RemoveImage(ctx context.Context, who,
return err
})
if err == nil {
+ // Again after the commit: a read between the drop inside the
+ // write and the commit may have put the bytes back. They were
+ // never served (the read rule ran first); this is tidiness.
+ store.small.drop(public)
store.emptyTrash(ctx, keys)
}
return err
diff --git a/internal/mapa/looks.go b/internal/mapa/looks.go
index fd01aba..411d848 100644
--- a/internal/mapa/looks.go
+++ b/internal/mapa/looks.go
@@ -125,6 +125,9 @@ func (store *Store) SetLook(ctx context.Context, who string, pageID int64,
func (record Record) restyled(change LookChange) Record {
if change.SetIcon {
record.Icon = change.Icon
+ if record.Icon != nil && *record.Icon == (Icon{}) {
+ record.Icon = nil
+ }
}
if change.SetBanner {
record.Banner = movedBanner(record.Banner, change.Banner)
diff --git a/internal/mapa/looks_images.go b/internal/mapa/looks_images.go
index 6f4fa94..a0c492b 100644
--- a/internal/mapa/looks_images.go
+++ b/internal/mapa/looks_images.go
@@ -1,5 +1,7 @@
package mapa
+import "context"
+
// Which images a look may name (columns and icons spec §4.2), checked
// before the write: the setter's own pending image, which the commit
// attaches, or an image already attached to this page. Anything else is
@@ -67,7 +69,7 @@ func (tx *Tx) dropFromLook(row ImageRow, actor int64) error {
if err := tx.db.First(&page, *row.PageID).Error; err != nil {
return err
}
- if page.Gone || page.Kind != KindPage {
+ if page.Kind != KindPage {
return nil
}
record, err := tx.store.OpenPage(page)
@@ -91,3 +93,32 @@ func (tx *Tx) dropFromLook(row ImageRow, actor int64) error {
}
return tx.carryDrafts(page.ID, from, page.Revision)
}
+
+// DropOwnPending removes a picture the look refused, when it is still
+// the person's own pending image, so it holds no allowance for seven
+// days. An image already attached anywhere is never touched here.
+func (store *Store) DropOwnPending(ctx context.Context, who,
+ public string) error {
+ var keys []string
+ err := quiet(store.write(ctx, func(tx *Tx) error {
+ actor, err := tx.member(who)
+ if err != nil {
+ return err
+ }
+ var row ImageRow
+ err = tx.db.Where("public_id = ? AND page_id IS NULL AND "+
+ "owner_id = ?", public, actor).Limit(1).Find(&row).Error
+ if err != nil {
+ return err
+ }
+ if row.ID == 0 {
+ return errNoChange
+ }
+ keys, err = tx.removeImages(actor, []ImageRow{row})
+ return err
+ }))
+ if err == nil {
+ store.emptyTrash(ctx, keys)
+ }
+ return err
+}
diff --git a/internal/mapa/looks_render.go b/internal/mapa/looks_render.go
index be33a97..87860fe 100644
--- a/internal/mapa/looks_render.go
+++ b/internal/mapa/looks_render.go
@@ -89,3 +89,19 @@ func (app *app) bannerOf(request *http.Request, viewer Viewer,
return &BannerView{Src: markup.ImagePrefix + id, Width: state.Width,
Height: state.Height, Y: BannerY(page.Banner.Y)}
}
+
+// drawableIcon is icon when it can be drawn on page for viewer: an
+// emoji, or an image the server can still draw there. An old version's
+// icon whose picture has gone draws as nothing, never a broken image.
+func (app *app) drawableIcon(request *http.Request, viewer Viewer,
+ pageID int64, icon *Icon) *Icon {
+ if icon == nil || icon.Image == "" {
+ return icon
+ }
+ states := app.index.ImageStates(request.Context(), ScopeOf(viewer),
+ pageID, []string{icon.Image})
+ if !states[icon.Image].Available {
+ return nil
+ }
+ return icon
+}
diff --git a/internal/mapa/looks_test.go b/internal/mapa/looks_test.go
index ac3cedf..0dda27b 100644
--- a/internal/mapa/looks_test.go
+++ b/internal/mapa/looks_test.go
@@ -269,3 +269,30 @@ func TestImagesOnThisPageNameTheLook(t *testing.T) {
t.Fatalf("the list: %+v %v", listed, err)
}
}
+
+// LOOK12's cache half: a small picture read once is served again
+// without the bucket or a blob slot; a large one is not kept.
+func TestSmallPicturesAreServedFromTheCache(t *testing.T) {
+ store, objects, _ := imageRig(t)
+ icon := upload(t, store, ana, 9)
+ held := row(t, store, icon)
+ if _, _, err := store.ImageBytes(ctx(), held); err != nil {
+ t.Fatal(err)
+ }
+ objects.fail("get", true)
+ release, err := store.images.acquire(ctx(), uploadWait)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer release()
+ other, err := store.images.acquire(ctx(), uploadWait)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer other()
+ data, kind, err := store.ImageBytes(ctx(), held)
+ if err != nil || len(data) == 0 || kind != "image/png" {
+ t.Fatalf("the second read, every slot taken and the bucket down: "+
+ "%d bytes, %q, %v", len(data), kind, err)
+ }
+}
diff --git a/internal/mapa/static/frame.css b/internal/mapa/static/frame.css
index 94f706a..28b1888 100644
--- a/internal/mapa/static/frame.css
+++ b/internal/mapa/static/frame.css
@@ -567,7 +567,7 @@ h1[mapa-title] > [mapa-icon] { margin-inline-end: var(--rst-sp-3); vertical-alig
[mapa-banner][data-y="90"] > img { object-position: 50% 90%; }
[mapa-banner][data-y="95"] > img { object-position: 50% 95%; }
[mapa-banner][data-y="100"] > img { object-position: 50% 100%; }
-[mapa-banner][data-mapa-moving] > img { cursor: ns-resize; }
+[mapa-banner][data-mapa-moving] > img { cursor: ns-resize; touch-action: none; user-select: none; }
/* The banner's own controls, over its corner on hover or focus. */
[mapa-banner-tools] {
position: absolute;
diff --git a/internal/mapa/static/look.js b/internal/mapa/static/look.js
index 3191e6c..47589fe 100644
--- a/internal/mapa/static/look.js
+++ b/internal/mapa/static/look.js
@@ -22,9 +22,30 @@
return made;
}
+ // busy marks the control that sent a change, as busy.js marks a
+ // form's button: a spinner, aria-busy, and no second press.
+ function busy(control, on) {
+ if (!control) return;
+ var spin = control.querySelector("[rst-spin]");
+ if (on && !spin) {
+ spin = element("span", { "rst-spin": "", "aria-hidden": "true" });
+ control.insertBefore(spin, control.firstChild);
+ } else if (!on && spin) {
+ spin.remove();
+ }
+ if (on) control.setAttribute("aria-busy", "true");
+ else control.removeAttribute("aria-busy");
+ if ("disabled" in control) control.disabled = on;
+ }
+
// send posts the look change, holds for the busy rule, and loads the
- // page again; a refusal comes back as its sentence.
- function send(href, fields) {
+ // page again; a refusal comes back as its sentence. control, when
+ // given, shows the busy state while it waits.
+ function send(href, fields, control) {
+ if (control && control.getAttribute("aria-busy") === "true") {
+ return Promise.resolve(null);
+ }
+ busy(control, true);
var body = new URLSearchParams();
Object.keys(fields).forEach(function (key) { body.set(key, fields[key]); });
var wait = new Promise(function (resolve) { setTimeout(resolve, HOLD_MS); });
@@ -41,8 +62,12 @@
window.location.reload();
return null;
}
+ busy(control, false);
return both[0].reply.error || "That didn't work. Try again.";
- }, function () { return "That didn't work. Try again."; });
+ }, function () {
+ busy(control, false);
+ return "That didn't work. Try again.";
+ });
}
// upload sends one file to POST /images and answers its public id.
@@ -93,12 +118,9 @@
// say shows a sentence in the page's polite live region.
function say(text) {
+ // The region is the server's, so it exists before anything is said.
var region = document.getElementById("mapa-look-said");
- if (!region) {
- region = element("p", { id: "mapa-look-said", role: "status", "mapa-sr": "" });
- document.body.appendChild(region);
- }
- region.textContent = text;
+ if (region) region.textContent = text;
}
// ---- The icon picker ----------------------------------------------------
@@ -139,8 +161,14 @@
var option = event.target.closest("[role=option]");
if (option) picker.choose(option.getAttribute("data-emoji"));
});
+ var escaped = false;
+ this.pop.addEventListener("keydown", function (event) {
+ if (event.key === "Escape") escaped = true;
+ });
this.pop.addEventListener("toggle", function (event) {
- if (event.newState === "closed") picker.opener.focus({ preventScroll: true });
+ if (event.newState === "open") { escaped = false; return; }
+ // Back to the opener after Esc; a click elsewhere keeps its focus.
+ if (escaped) picker.opener.focus({ preventScroll: true });
});
};
@@ -155,6 +183,8 @@
picker.groups = data.groups;
picker.emoji = data.emoji;
picker.filter();
+ }).catch(function () {
+ picker.refused("The emoji list didn't load. Type an emoji, or upload a picture.");
});
};
@@ -246,31 +276,45 @@
// ---- The banner -----------------------------------------------------------
- function addBanner(href) {
+ function addBanner(href, control) {
chooseFile(function (file) {
say("Uploading the banner");
+ busy(control, true);
upload(file).then(function (id) {
- return send(href, { do: "banner", image: id, y: "50" });
+ busy(control, false);
+ return send(href, { do: "banner", image: id, y: "50" }, control);
}).then(function (refusal) { if (refusal) say(refusal); },
- function (error) { say(error.message); });
+ function (error) { busy(control, false); say(error.message); });
});
}
// reposition lets the picture be dragged up or down, or moved with the
- // arrow keys, then stores the nearest step of 5 (§3.2).
- function reposition(banner, href, control) {
+ // arrow keys, then stores the nearest step of 5 (§3.2). The link that
+ // started it gives way to a real button, Save position; Esc cancels.
+ function reposition(banner, href, link, byKey) {
var picture = banner.querySelector("img");
- var y = Number(banner.getAttribute("data-y")) || 50;
+ var stored = parseInt(banner.getAttribute("data-y"), 10);
+ var y = isNaN(stored) ? 50 : stored;
var start = null;
+ var save = element("button", { type: "button", "rst-btn": "" }, "Save position");
+ link.replaceWith(save);
banner.setAttribute("data-mapa-moving", "");
- control.textContent = "Save position";
- control.setAttribute("aria-pressed", "true");
+ picture.draggable = false;
+ // A key that started this is still going down: focus the button,
+ // and let it save, only once that key is up, so it never presses
+ // the button too. A pointer's click is done already.
+ var armed = false;
+ function arm() { armed = true; save.focus(); }
+ if (byKey) document.addEventListener("keyup", arm, { once: true });
+ else setTimeout(arm, 0);
say("Drag the picture or use the arrow keys. Then choose Save position.");
function show(next) {
y = Math.max(0, Math.min(100, Math.round(next / 5) * 5));
banner.setAttribute("data-y", String(y));
}
+ function end() { start = null; }
picture.addEventListener("pointerdown", function (event) {
+ event.preventDefault();
start = { at: event.clientY, y: y };
picture.setPointerCapture(event.pointerId);
});
@@ -279,17 +323,20 @@
var moved = (start.at - event.clientY) / banner.clientHeight * 100;
show(start.y + moved);
});
- picture.addEventListener("pointerup", function () { start = null; });
- control.addEventListener("keydown", function (event) {
+ ["pointerup", "pointercancel", "lostpointercapture"].forEach(function (name) {
+ picture.addEventListener(name, end);
+ });
+ save.addEventListener("keydown", function (event) {
if (event.key === "ArrowUp") { event.preventDefault(); show(y + 5); }
if (event.key === "ArrowDown") { event.preventDefault(); show(y - 5); }
+ if (event.key === "Escape") { event.preventDefault(); window.location.reload(); }
});
- control.addEventListener("click", function (event) {
- event.preventDefault();
- send(href, { do: "position", y: String(y) }).then(function (refusal) {
+ save.addEventListener("click", function () {
+ if (!armed) return;
+ send(href, { do: "position", y: String(y) }, save).then(function (refusal) {
if (refusal) say(refusal);
});
- }, { once: true });
+ });
}
function bindBanner(banner) {
@@ -298,11 +345,14 @@
banner.querySelectorAll("[data-mapa-banner]").forEach(function (control) {
control.addEventListener("click", function (event) {
var what = control.getAttribute("data-mapa-banner");
- if (what === "reposition" && control.hasAttribute("aria-pressed")) return;
event.preventDefault();
- if (what === "reposition") reposition(banner, href, control);
- if (what === "change") addBanner(href);
- if (what === "remove") send(href, { do: "remove-banner" }).then(function (refusal) { if (refusal) say(refusal); });
+ if (what === "reposition") reposition(banner, href, control, event.detail === 0);
+ if (what === "change") addBanner(href, control);
+ if (what === "remove") {
+ send(href, { do: "remove-banner" }, control).then(function (refusal) {
+ if (refusal) say(refusal);
+ });
+ }
});
});
}
@@ -318,7 +368,7 @@
});
row.querySelector('[data-mapa-look="banner"]').addEventListener("click", function (event) {
event.preventDefault();
- addBanner(row.getAttribute("data-mapa-look-href"));
+ addBanner(row.getAttribute("data-mapa-look-href"), event.currentTarget);
});
}
document.querySelectorAll("[mapa-banner]").forEach(bindBanner);
diff --git a/internal/mapa/static/mapa.js b/internal/mapa/static/mapa.js
index f417ed6..736920c 100644
--- a/internal/mapa/static/mapa.js
+++ b/internal/mapa/static/mapa.js
@@ -385,6 +385,19 @@
return svg;
}
+ // lookIcon is a team page's own icon in a row's glyph cell (columns
+ // and icons spec §2.4), drawn as chips.mjs draws it, or null.
+ function lookIcon(look) {
+ if (look && look.emoji) {
+ return paletteElement("span", { "mapa-icon": "", "aria-hidden": "true" }, look.emoji);
+ }
+ if (look && /^[0-9a-z]{1,13}$/.test(look.image || "")) {
+ return paletteElement("img", { "mapa-icon": "", src: "/i/" + look.image, alt: "",
+ width: "16", height: "16", loading: "lazy", decoding: "async" });
+ }
+ return null;
+ }
+
function paletteElement(tag, attributes, text) {
var element = document.createElement(tag);
Object.keys(attributes || {}).forEach(function (name) {
@@ -508,11 +521,11 @@
};
if (!later) date();
this.group("Pages", "", (reply.pages || []).map(function (hit) {
- return hit.via ? { icon: "page", main: hit.via, sub: "Old title of " + hit.label, href: hit.href }
- : { icon: "page", main: hit.label, sub: "Team page", href: hit.href };
+ return hit.via ? { icon: "page", look: hit.look, main: hit.via, sub: "Old title of " + hit.label, href: hit.href }
+ : { icon: "page", look: hit.look, main: hit.label, sub: "Team page", href: hit.href };
}));
this.group("In the text", "", (reply.text || []).map(function (hit) {
- return { icon: "page", main: hit.label, snippet: hit.snippet, href: hit.href };
+ return { icon: "page", look: hit.look, main: hit.label, snippet: hit.snippet, href: hit.href };
}));
if (later) date();
this.group("Your notes", "Only you see these", (reply.notes || []).map(function (hit) {
@@ -555,7 +568,7 @@
"aria-selected": "false", tabindex: "-1", "mapa-palette-option": ""
});
var icon = paletteElement("span", row.dashed ? { "mapa-palette-ic": "dash" } : { "mapa-palette-ic": "" });
- icon.appendChild(paletteIcon(row.icon));
+ icon.appendChild(lookIcon(row.look) || paletteIcon(row.icon));
var main = paletteElement("span", { "mapa-palette-main": "" });
main.appendChild(paletteElement("span", {}, row.main));
var sub = paletteElement("small");
diff --git a/internal/mapa/templates/partials.html b/internal/mapa/templates/partials.html
index 617849c..3399ae3 100644
--- a/internal/mapa/templates/partials.html
+++ b/internal/mapa/templates/partials.html
@@ -111,4 +111,5 @@
{{define "mapa-look-row"}}<div mapa-look-row data-mapa-look-href="{{.Href}}" data-mapa-emoji="{{emojiHref}}">
<a mapa-look-act href="{{.Href}}#icon" data-mapa-look="icon">{{if .Page.Look}}Change icon{{else}}Add icon{{end}}</a>
<a mapa-look-act href="{{.Href}}#banner" data-mapa-look="banner">{{if .Banner}}Change banner{{else}}Add banner{{end}}</a>
+<p id="mapa-look-said" role="status" mapa-sr></p>
</div>{{end}}
diff --git a/internal/mapatest/looks_browser_test.go b/internal/mapatest/looks_browser_test.go
index 69d9a40..c9a2875 100644
--- a/internal/mapatest/looks_browser_test.go
+++ b/internal/mapatest/looks_browser_test.go
@@ -11,6 +11,7 @@ import (
"amadan.net/rastrillo/rastrillo/harness"
"github.com/chromedp/cdproto/input"
"github.com/chromedp/chromedp"
+ "github.com/chromedp/chromedp/kb"
"amadan.net/oficina/mapa/internal/mapa"
)
@@ -136,3 +137,47 @@ func TestLook10ThePickerByKeyboard(t *testing.T) {
t.Fatalf("axe, a page with an icon:\n%s", found)
}
}
+
+// LOOK10's banner half: Reposition by keyboard, then Save position.
+func TestLook10TheBannerByKeyboard(t *testing.T) {
+ rig, store := browserRigWith(t, 0, nil)
+ page := lookedPage(t, store)
+ drive(t, rig, scripts(true), chromedp.EmulateViewport(1440, 900),
+ chromedp.Navigate(rig.Origin+mapa.PagePath(page)),
+ chromedp.WaitVisible(mounted),
+ chromedp.Focus(`[data-mapa-banner="reposition"]`),
+ chromedp.KeyEvent("\r"),
+ chromedp.WaitVisible(`[mapa-banner-tools] button`))
+ eventually(t, "Save position has focus", func() bool {
+ return evaluate(t, rig, `document.activeElement.textContent`) ==
+ "Save position"
+ })
+ drive(t, rig, chromedp.KeyEvent(kb.ArrowDown),
+ chromedp.KeyEvent(kb.ArrowDown))
+ if moved := evaluate(t, rig, `document.querySelector("[mapa-banner]")`+
+ `.getAttribute("data-y")`); moved != "20" {
+ t.Fatalf("the arrows moved the banner to %s", moved)
+ }
+ drive(t, rig, chromedp.KeyEvent("\r"))
+ var seen string
+ eventually(t, "the banner moved and was saved", func() bool {
+ seen = evaluate(t, rig, `(function () {
+ var band = document.querySelector("[mapa-banner]");
+ return band ? band.getAttribute("data-y") + "|" +
+ band.hasAttribute("data-mapa-moving") + "|" +
+ (document.activeElement && document.activeElement.outerHTML.slice(0, 80)) : "none";
+})()`)
+ return seen == "20|false|"+seenTail(seen)
+ })
+ if found := axeSerious(t, rig); found != "" {
+ t.Fatalf("axe, a page with a banner:\n%s", found)
+ }
+}
+
+func seenTail(seen string) string {
+ parts := strings.SplitN(seen, "|", 3)
+ if len(parts) < 3 {
+ return ""
+ }
+ return parts[2]
+}
diff --git a/internal/mapatest/looks_test.go b/internal/mapatest/looks_test.go
index 8084e0a..c2f3537 100644
--- a/internal/mapatest/looks_test.go
+++ b/internal/mapatest/looks_test.go
@@ -126,3 +126,29 @@ func TestLook12ACachedPictureStillAnswersToTheReadRule(t *testing.T) {
t.Fatalf("a deleted page's cached icon: %d", code)
}
}
+
+// Review round 1 on the build, M2 and M3: an icon post naming no
+// picture writes nothing, and a position post choosing none keeps the
+// one stored.
+func TestLookRefusesAnEmptyPictureAndKeepsAnUnchosenPosition(t *testing.T) {
+ rig := newRig(t)
+ acme := rig.createPage(t, Ana, "Acme", "One.")
+ before := rig.count(t, "revisions")
+ reply := rig.post(t, Bo, acme+"/look", url.Values{"do": {"icon"},
+ "image": {""}})
+ if reply.Code != http.StatusNotFound ||
+ rig.count(t, "revisions") != before {
+ t.Fatalf("an empty icon: %d", reply.Code)
+ }
+ reply = rig.sendFile(t, Bo, acme+"/look?upload=1&for=banner",
+ url.Values{"y": {"35"}}, "wide.png", pngOf(t, 8))
+ if reply.Code >= 400 {
+ t.Fatalf("banner: %d", reply.Code)
+ }
+ before = rig.count(t, "revisions")
+ rig.post(t, Bo, acme+"/look", url.Values{"do": {"position"}})
+ if rig.count(t, "revisions") != before ||
+ !strings.Contains(rig.page(t, Ana, acme), `data-y="35"`) {
+ t.Fatal("a position post with none chosen moved the banner")
+ }
+}