Pages inside (WIP): the In: relation in the index, the sidebar's arrows, the cookie and view POST, All pages inside, and pins up to 20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15 files changed,
+625
−27
internal/mapa/graph.go+9 −0internal/mapa/index.go+8 −1internal/mapa/inside.go+101 −0internal/mapa/inside_test.go+61 −0internal/mapa/pins.go+9 −5internal/mapa/recent.go+1 −5internal/mapa/render.go+1 −1internal/mapa/side.go+27 −14internal/mapa/side_inside.go+192 −0internal/mapa/static/frame.css+39 −0internal/mapa/static/mapa.js+35 −0internal/mapa/templates/frame.html+10 −1internal/mapa/templates/inside.html+9 −0internal/mapatest/gate8_test.go+4 −0internal/mapatest/inside_test.go+119 −0
diff --git a/internal/mapa/graph.go b/internal/mapa/graph.go| index eccab7d..085c28c 100644 |
| --- a/internal/mapa/graph.go |
| +++ b/internal/mapa/graph.go |
| @@ -53,6 +53,12 @@ func (index *Index) add(page *entry) { |
| for _, link := range page.links { |
| index.linkersOf(Fold(link.Target)).add(page, link.Target) |
| } |
| + if page.in != "" { |
| + if index.within[page.in] == nil { |
| + index.within[page.in] = map[int64]bool{} |
| + } |
| + index.within[page.in][page.id] = true |
| + } |
| index.termsOf(page).add(page.id, page.counts, page.length) |
| index.titlesDirty = index.titlesDirty || page.team() |
| index.pending.dirty = true |
| @@ -94,6 +100,9 @@ func (index *Index) remove(pageID int64) { |
| delete(index.linkers, fold) |
| } |
| } |
| + if page.in != "" { |
| + delete(index.within[page.in], page.id) |
| + } |
| index.termsOf(page).remove(page.id, page.counts) |
| index.titlesDirty = index.titlesDirty || page.team() |
| index.pending.dirty = true |
diff --git a/internal/mapa/index.go b/internal/mapa/index.go| index 9142964..a0fed23 100644 |
| --- a/internal/mapa/index.go |
| +++ b/internal/mapa/index.go |
| @@ -56,6 +56,9 @@ type Index struct { |
| titleRows []titleRow |
| titlesDirty bool |
| pending pendingSet |
| + // within maps a folded link text to the team pages whose "In:" line |
| + // names it (inside.go, columns and icons spec §5.1). |
| + within map[string]map[int64]bool |
| } |
| // entry is one live page, opened and parsed. |
| @@ -68,6 +71,8 @@ type entry struct { |
| aliases []AliasView |
| blocks []markup.Block |
| links []markup.Link |
| + // in is the folded target of the page's "In:" line, or "". |
| + in string |
| // unlinked is each block's words outside links and code (§6.4). |
| unlinked [][]word |
| // counts and length are what the page is indexed with for search. |
| @@ -113,6 +118,7 @@ func (index *Index) reset() { |
| index.ownTerms = map[int64]*partition{} |
| index.titleRows, index.titlesDirty = nil, true |
| index.pending = pendingSet{dirty: true} |
| + index.within = map[string]map[int64]bool{} |
| } |
| // Sync readies the index for a read. A reader never catches the index |
| @@ -307,7 +313,8 @@ func (index *Index) open(page Page, aliases []AliasView) (*entry, error) { |
| opened := &entry{id: page.ID, nonce: page.Nonce, owner: page.OwnerID, |
| revision: page.Revision, kind: page.Kind, rung: page.Rung, |
| created: page.CreatedAt, updated: page.UpdatedAt, record: record, |
| - aliases: aliases, blocks: blocks, links: markup.LinksIn(blocks)} |
| + aliases: aliases, blocks: blocks, links: markup.LinksIn(blocks), |
| + in: inTarget(page.Kind, page.Rung, blocks)} |
| opened.counts, opened.length = termCounts(searchText(opened)) |
| opened.unlinked = make([][]word, len(blocks)) |
| for number, block := range blocks { |
diff --git a/internal/mapa/inside.go b/internal/mapa/inside.go| new file mode 100644 |
| index 0000000..85893b1 |
| --- /dev/null |
| +++ b/internal/mapa/inside.go |
| @@ -0,0 +1,101 @@ |
| +package mapa |
| + |
| +import ( |
| + "context" |
| + "sort" |
| + |
| + "amadan.net/oficina/mapa/internal/mapa/markup" |
| +) |
| + |
| +// Pages inside (columns and icons spec §5): a team page is inside team |
| +// page P when its first block is exactly the line "In: [[P]]" (or |
| +// "In: [[P|shown]]", with an optional ^id), the line the Notion import |
| +// writes. The relation is derived from bodies in memory, like every |
| +// link; nothing is stored. Only team pages are inside anything, and |
| +// only team pages hold pages, so no private first line reaches the |
| +// sidebar (level-up build note 80). |
| + |
| +// inTarget is the folded link text of a page's "In:" line, or "". |
| +func inTarget(kind, rung string, blocks []markup.Block) string { |
| + if kind != KindPage || rung != RungTeam || len(blocks) == 0 { |
| + return "" |
| + } |
| + first := blocks[0] |
| + if first.Kind != markup.Paragraph { |
| + return "" |
| + } |
| + spans := markup.Spans(markup.Strip(first)) |
| + if len(spans) != 2 || spans[0].Kind != markup.Text || |
| + spans[0].Text != "In: " || spans[1].Kind != markup.WikiLink || |
| + spans[1].Anchor != "" || markup.IsDateShaped(spans[1].Target) { |
| + return "" |
| + } |
| + return Fold(spans[1].Target) |
| +} |
| + |
| +// insideOf is the ids of the team pages inside page, unordered. The |
| +// caller holds the read lock. |
| +func (index *Index) insideOf(page *entry) map[int64]bool { |
| + out := map[int64]bool{} |
| + if page == nil || !page.team() { |
| + return out |
| + } |
| + for _, fold := range page.titleFolds() { |
| + for child := range index.within[fold] { |
| + if child != page.id && index.team[child] { |
| + out[child] = true |
| + } |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// insideOrder is page's children in its own order (§5.2): those its |
| +// body links to, by their first link, then the rest by title. |
| +func (index *Index) insideOrder(page *entry, |
| + children map[int64]bool) []*entry { |
| + place := map[int64]int{} |
| + for at, link := range page.links { |
| + target, ok := index.titles[Fold(link.Target)] |
| + if _, seen := place[target]; ok && children[target] && !seen { |
| + place[target] = at |
| + } |
| + } |
| + out := make([]*entry, 0, len(children)) |
| + for child := range children { |
| + out = append(out, index.pages[child]) |
| + } |
| + sort.SliceStable(out, func(left, right int) bool { |
| + one, okOne := place[out[left].id] |
| + other, okOther := place[out[right].id] |
| + switch { |
| + case okOne && okOther: |
| + return one < other |
| + case okOne != okOther: |
| + return okOne |
| + } |
| + return Fold(out[left].record.Title) < Fold(out[right].record.Title) |
| + }) |
| + return out |
| +} |
| + |
| +// Inside is the pages inside page id as scope sees them, in order: the |
| +// scoped accessor's answer (level-up §8). A page the scope may not open, |
| +// or a private one, has none. |
| +func (index *Index) Inside(ctx context.Context, scope Scope, |
| + pageID int64) ([]*entry, error) { |
| + if err := index.Sync(ctx); err != nil { |
| + return nil, err |
| + } |
| + index.mutex.RLock() |
| + defer index.mutex.RUnlock() |
| + return index.insideLocked(scope, pageID), nil |
| +} |
| + |
| +func (index *Index) insideLocked(scope Scope, pageID int64) []*entry { |
| + page := index.in(scope).page(pageID) |
| + if page == nil || !page.team() { |
| + return nil |
| + } |
| + return index.insideOrder(page, index.insideOf(page)) |
| +} |
diff --git a/internal/mapa/inside_test.go b/internal/mapa/inside_test.go| new file mode 100644 |
| index 0000000..3d7538a |
| --- /dev/null |
| +++ b/internal/mapa/inside_test.go |
| @@ -0,0 +1,61 @@ |
| +package mapa |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// IN1 and IN2 (columns and icons spec §5.1, §5.2, §9): which pages are |
| +// inside which, and in what order. |
| + |
| +func insideTitles(t *testing.T, index *Index, scope Scope, |
| + pageID int64) string { |
| + t.Helper() |
| + pages, err := index.Inside(ctx(), scope, pageID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var titles []string |
| + for _, page := range pages { |
| + titles = append(titles, page.record.Title) |
| + } |
| + return strings.Join(titles, ", ") |
| +} |
| + |
| +func TestIN1OnlyAnExactFirstInLineIsInside(t *testing.T) { |
| + store := testStore(t) |
| + index := NewIndex(store) |
| + parent := mustCreate(t, store, "Projects", "See [[Beta]] then [[Alpha]].") |
| + for title, body := range map[string]string{ |
| + "Alpha": "In: [[Projects]]\n\nText.", |
| + "Beta": "In: [[Projects|the projects]] ^m1", |
| + "Gamma": "In: [[Projects]]", |
| + "Second": "Intro.\n\nIn: [[Projects]]", |
| + "Dated": "In: [[2026-11-12]]", |
| + "Self": "In: [[Self]]", |
| + "Pending": "In: [[Nowhere]]", |
| + "Sentence": "In: [[Projects]] and more.", |
| + "Old title": "In: [[Old projects]]", |
| + } { |
| + mustCreate(t, store, title, body) |
| + } |
| + if _, err := store.Retitle(ctx(), ana, parent.ID, "Old projects"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := store.Retitle(ctx(), ana, parent.ID, "Projects"); err != nil { |
| + t.Fatal(err) |
| + } |
| + scratch, err := store.CreateScratch(ctx(), ana, "In: [[Projects]]") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _ = scratch |
| + viewer, _ := store.Viewer(ctx(), ana, nil) |
| + got := insideTitles(t, index, ScopeOf(viewer), parent.ID) |
| + if got != "Beta, Alpha, Gamma, Old title" { |
| + t.Fatalf("inside Projects: %q", got) |
| + } |
| + if got := insideTitles(t, index, ScopeOf(viewer), scratch.ID); got != "" { |
| + t.Fatalf("a private page holds %q", got) |
| + } |
| +} |
diff --git a/internal/mapa/pins.go b/internal/mapa/pins.go| index c2d5fde..3cfca77 100644 |
| --- a/internal/mapa/pins.go |
| +++ b/internal/mapa/pins.go |
| @@ -18,11 +18,15 @@ import ( |
| // theirs alone, sealed in their member row, and the event a change logs |
| // names the member, never the page. |
| -// maxPins is how many pages a sidebar holds pinned. |
| -const maxPins = 12 |
| +// maxPins is how many pages a sidebar holds pinned: 20 since the |
| +// columns and icons spec's Q4, so a Notion workspace's top level fits. |
| +// A list sealed when it held 12 (oldPinBytes) is still read. |
| +const maxPins = 20 |
| + |
| +const oldPinBytes = 12 * 8 |
| // ErrTooManyPins is a pin past maxPins. |
| -var ErrTooManyPins = errors.New("You can pin up to 12 pages. " + |
| +var ErrTooManyPins = errors.New("You can pin up to 20 pages. " + |
| "Unpin one first.") |
| // Pins is the viewer's pinned page ids, newest first. A page since |
| @@ -49,11 +53,11 @@ func (store *Store) openPins(sealed []byte) ([]int64, error) { |
| if err != nil { |
| return nil, err |
| } |
| - if len(plain) != pinBytes { |
| + if len(plain) != pinBytes && len(plain) != oldPinBytes { |
| return nil, errors.New("mapa: pins of the wrong length") |
| } |
| var ids []int64 |
| - for at := 0; at < pinBytes; at += 8 { |
| + for at := 0; at < len(plain); at += 8 { |
| if id := int64(binary.BigEndian.Uint64(plain[at:])); id != 0 { |
| ids = append(ids, id) |
| } |
diff --git a/internal/mapa/recent.go b/internal/mapa/recent.go| index a821cdd..0774dbe 100644 |
| --- a/internal/mapa/recent.go |
| +++ b/internal/mapa/recent.go |
| @@ -140,11 +140,7 @@ func (index *Index) sideLinks(ctx context.Context, scope Scope, |
| if found == nil || (teamOnly && !found.team()) { |
| continue |
| } |
| - out = append(out, sideLink{Label: found.label(scope.Locale), |
| - Href: found.href(), Icon: sideIcon(found.kind), Look: found.look(), |
| - Here: found.href() == current, Private: !found.team(), |
| - page: PageView{Public: publicID(found.nonce), |
| - Kind: found.kind, Rung: found.rung}}) |
| + out = append(out, sideLinkOf(found, scope, current)) |
| if limit > 0 && len(out) == limit { |
| break |
| } |
diff --git a/internal/mapa/render.go b/internal/mapa/render.go| index 56e4b13..e5a55de 100644 |
| --- a/internal/mapa/render.go |
| +++ b/internal/mapa/render.go |
| @@ -103,7 +103,7 @@ var shellOf = map[string]string{ |
| "pages": "shell", "page": "shell", |
| "page_new": "shell", "page_edit": "shell", "rename": "shell", |
| "links": "shell", "alias_free": "shell", "delete": "shell", |
| - "image_remove": "shell", "look": "shell", |
| + "image_remove": "shell", "look": "shell", "inside": "shell", |
| "deleted": "shell", "restore": "shell", "day": "shell", |
| "scratch": "shell", "scratch_new": "shell", "share": "shell", |
| "settings": "shell", "search": "shell", "conflict": "shell", |
diff --git a/internal/mapa/side.go b/internal/mapa/side.go| index de8a572..c70814a 100644 |
| --- a/internal/mapa/side.go |
| +++ b/internal/mapa/side.go |
| @@ -46,6 +46,18 @@ type sideLink struct { |
| // Menu is the row's ⋯ (build note 88), from what page allows. |
| Menu []menuEntry |
| page PageView |
| + id int64 |
| + // Gutter is a Pinned row, which keeps a cell for an arrow; Arrow, |
| + // that its page holds pages the viewer may open; Open, that they are |
| + // shown, as Inside; Depth, its indent; More and All, how many more |
| + // there are than are listed, and all of them (side_inside.go). |
| + Gutter, Arrow, Open bool |
| + Inside []sideLink |
| + Depth, More, All int |
| + // Return is where the arrow's form comes back to; Public, the |
| + // page's public id; ListID, the open list's own id, unique however |
| + // often a page is shown. |
| + Return, Public, ListID string |
| } |
| func (app *app) side(request *http.Request, page *view) sideView { |
| @@ -54,6 +66,15 @@ func (app *app) side(request *http.Request, page *view) sideView { |
| side := sideView{State: sidebarState(request), |
| Places: slices.Clone(page.Nav), Return: page.Return} |
| side.Pinned, side.Recent = app.sideLists(request, page) |
| + if len(side.Pinned) > 0 { |
| + current := "" |
| + if page.Chrome != nil && page.Chrome.Page != nil { |
| + current = page.Chrome.Page.Href |
| + } |
| + app.index.insideRows(request.Context(), ScopeOf(page.Viewer), |
| + side.Pinned, openRows(request), current) |
| + setReturn(side.Pinned, side.Return) |
| + } |
| side.light() |
| side.menus() |
| return side |
| @@ -64,14 +85,10 @@ func (app *app) side(request *http.Request, page *view) sideView { |
| func (side *sideView) menus() { |
| back, pinned := withoutNotice(side.Return), map[string]bool{} |
| for index := range side.Pinned { |
| - row := &side.Pinned[index] |
| - pinned[row.Href] = true |
| - row.Menu = rowMenu(row.page, true, back) |
| - } |
| - for index := range side.Recent { |
| - row := &side.Recent[index] |
| - row.Menu = rowMenu(row.page, pinned[row.Href], back) |
| + pinned[side.Pinned[index].Href] = true |
| } |
| + menuRows(side.Pinned, pinned, back) |
| + menuRows(side.Recent, pinned, back) |
| } |
| // withoutNotice is a return path less its ?done= notice, which said |
| @@ -97,13 +114,7 @@ func withoutNotice(path string) string { |
| func (side *sideView) light() { |
| var here *sideLink |
| for _, list := range [][]sideLink{side.Pinned, side.Recent} { |
| - for index := range list { |
| - list[index].Here = list[index].Here && here == nil |
| - list[index].Current = list[index].Here |
| - if list[index].Here { |
| - here = &list[index] |
| - } |
| - } |
| + lightRows(list, &here) |
| } |
| if here == nil { |
| return |
| @@ -140,6 +151,8 @@ func linksState(request *http.Request) string { |
| func (app *app) viewRoutes(router chi.Router) { |
| router.Post("/view/sidebar", app.viewSidebar) |
| router.Post("/view/links", app.viewLinks) |
| + router.Post("/view/open", app.viewOpen) |
| + router.Get("/p/{id}/inside", app.insidePage) |
| router.Get("/help/markdown", app.helpMarkdown) |
| } |
diff --git a/internal/mapa/side_inside.go b/internal/mapa/side_inside.go| new file mode 100644 |
| index 0000000..a048227 |
| --- /dev/null |
| +++ b/internal/mapa/side_inside.go |
| @@ -0,0 +1,192 @@ |
| +package mapa |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| +) |
| + |
| +// The sidebar's arrows (columns and icons spec §5.3): a Pinned row whose |
| +// page holds pages the viewer may open has a disclosure arrow, and each |
| +// row it opens has its own, so the pages inside show one level at a |
| +// time. Which rows are open is the cookie mapa-open, a view preference |
| +// like the fold: the server draws open rows at first paint, POST |
| +// /view/open sets it with no script, and it writes no row. |
| + |
| +const ( |
| + openCookie = "mapa-open" |
| + // maxOpen is how many open rows the cookie keeps, newest first. |
| + maxOpen = 64 |
| + // insideShown is how many pages one open row lists before its link |
| + // to all of them; insideTotal caps the open rows the sidebar draws. |
| + insideShown = 50 |
| + insideTotal = 200 |
| + // insideDepth is how many levels are indented; deeper ones keep the |
| + // last indent. |
| + insideDepth = 4 |
| +) |
| + |
| +// openRows is the cookie's set of open page public ids, in its order. |
| +func openRows(request *http.Request) []string { |
| + cookie, err := request.Cookie(openCookie) |
| + if err != nil { |
| + return nil |
| + } |
| + var out []string |
| + for _, id := range strings.Fields(cookie.Value) { |
| + if len(id) <= 20 && len(out) < maxOpen { |
| + out = append(out, id) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// insideRows fills each Pinned row's arrow and, for an open one, the |
| +// rows inside it, through the scoped accessor (§5.4). |
| +func (index *Index) insideRows(ctx context.Context, scope Scope, |
| + rows []sideLink, open []string, current string) { |
| + if index.Sync(ctx) != nil { |
| + return |
| + } |
| + index.mutex.RLock() |
| + defer index.mutex.RUnlock() |
| + expand := opener{index: index, scope: scope, current: current, |
| + open: map[string]bool{}} |
| + for _, id := range open { |
| + expand.open[id] = true |
| + } |
| + for at := range rows { |
| + expand.row(&rows[at], 0, map[int64]bool{}) |
| + } |
| +} |
| + |
| +// opener draws the rows inside rows, counting what it has drawn. |
| +type opener struct { |
| + index *Index |
| + scope Scope |
| + current string |
| + open map[string]bool |
| + drawn int |
| + lists int |
| +} |
| + |
| +func (expand *opener) row(row *sideLink, depth int, ancestors map[int64]bool) { |
| + row.Gutter, row.Depth = true, min(depth, insideDepth) |
| + if ancestors[row.id] { |
| + return |
| + } |
| + children := expand.index.insideLocked(expand.scope, row.id) |
| + row.Arrow = len(children) > 0 |
| + row.Open = row.Arrow && expand.open[row.page.Public] && |
| + expand.drawn < insideTotal |
| + if !row.Open { |
| + return |
| + } |
| + expand.lists++ |
| + row.ListID = "inside-" + strconv.Itoa(expand.lists) |
| + inner := map[int64]bool{row.id: true} |
| + for id := range ancestors { |
| + inner[id] = true |
| + } |
| + row.More = max(len(children)-insideShown, 0) |
| + if row.More > 0 { |
| + row.All = len(children) |
| + } |
| + for _, child := range children[:min(len(children), insideShown)] { |
| + if expand.drawn >= insideTotal { |
| + break |
| + } |
| + expand.drawn++ |
| + link := sideLinkOf(child, expand.scope, expand.current) |
| + expand.row(&link, depth+1, inner) |
| + row.Inside = append(row.Inside, link) |
| + } |
| +} |
| + |
| +// sideLinkOf is a page as a sidebar row. |
| +func sideLinkOf(found *entry, scope Scope, current string) sideLink { |
| + return sideLink{Label: found.label(scope.Locale), Href: found.href(), |
| + Icon: sideIcon(found.kind), Look: found.look(), id: found.id, |
| + Public: publicID(found.nonce), |
| + Here: found.href() == current, Private: !found.team(), |
| + page: PageView{Public: publicID(found.nonce), Kind: found.kind, |
| + Rung: found.rung}} |
| +} |
| + |
| +// viewOpen opens or closes one row's pages inside: POST /view/open with |
| +// id and open (1 or 0). It sets the cookie and goes back; with script, |
| +// it answers the open row's list as HTML (§5.3). |
| +func (app *app) viewOpen(writer http.ResponseWriter, request *http.Request) { |
| + id := request.PostFormValue("id") |
| + open := openRows(request) |
| + kept := []string{} |
| + if request.PostFormValue("open") == "1" && id != "" && len(id) <= 20 { |
| + kept = append(kept, id) |
| + } |
| + for _, each := range open { |
| + if each != id && len(kept) < maxOpen { |
| + kept = append(kept, each) |
| + } |
| + } |
| + setViewCookie(writer, openCookie, strings.Join(kept, " ")) |
| + seeOther(writer, request, localReturn(request.PostFormValue("return"))) |
| +} |
| + |
| +// setReturn gives every row, open ones' rows included, the return path. |
| +func setReturn(rows []sideLink, back string) { |
| + for at := range rows { |
| + rows[at].Return = back |
| + setReturn(rows[at].Inside, back) |
| + } |
| +} |
| + |
| +// lightRows lights the first row that is Here, in document order: each |
| +// row, then the rows open inside it (build note 80's one highlight). |
| +func lightRows(rows []sideLink, here **sideLink) { |
| + for at := range rows { |
| + rows[at].Here = rows[at].Here && *here == nil |
| + rows[at].Current = rows[at].Here |
| + if rows[at].Here { |
| + *here = &rows[at] |
| + } |
| + lightRows(rows[at].Inside, here) |
| + } |
| +} |
| + |
| +// menuRows gives each row, open ones' rows included, its ⋯. |
| +func menuRows(rows []sideLink, pinned map[string]bool, back string) { |
| + for at := range rows { |
| + rows[at].Menu = rowMenu(rows[at].page, pinned[rows[at].Href], back) |
| + menuRows(rows[at].Inside, pinned, back) |
| + } |
| +} |
| + |
| +// insidePage is GET /p/{id}/inside: every page inside a team page, in |
| +// its order, for a list the sidebar cuts at insideShown. Scoped as the |
| +// arrow is; anything else is the app's 404. |
| +func (app *app) insidePage(writer http.ResponseWriter, |
| + request *http.Request) { |
| + page, ok := app.teamOnly(writer, request) |
| + if !ok { |
| + return |
| + } |
| + viewer, err := app.viewer(request) |
| + if err != nil { |
| + app.fail(writer, request, err) |
| + return |
| + } |
| + pages, err := app.index.Inside(request.Context(), ScopeOf(viewer), |
| + page.ID) |
| + if err != nil { |
| + app.fail(writer, request, err) |
| + return |
| + } |
| + rows := make([]sideLink, 0, len(pages)) |
| + for _, found := range pages { |
| + rows = append(rows, sideLinkOf(found, ScopeOf(viewer), "")) |
| + } |
| + app.show(writer, request, http.StatusOK, "inside", view{ |
| + Title: "Pages inside " + page.Label, Nav: nav("/pages"), |
| + Viewer: viewer, Data: map[string]any{"Page": page, "Rows": rows}}) |
| +} |
diff --git a/internal/mapa/static/frame.css b/internal/mapa/static/frame.css| index 39165be..5153b5a 100644 |
| --- a/internal/mapa/static/frame.css |
| +++ b/internal/mapa/static/frame.css |
| @@ -726,3 +726,42 @@ h1[mapa-title] > [mapa-icon] { margin-inline-end: var(--rst-sp-3); vertical-alig |
| [mapa-picker] [role="option"][aria-selected="true"] { background: var(--rst-surface-2); outline: 2px solid var(--rst-accent); outline-offset: -2px; } |
| [mapa-picker-foot] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); } |
| [mapa-picker][aria-busy="true"] { opacity: 0.7; pointer-events: none; } |
| + |
| +/* ── Pages inside (columns and icons spec §5.3): Pinned rows keep a 16px |
| + cell for the arrow before the icon, so every icon in Pinned lines up; |
| + opened rows indent one step per level, up to four. ── */ |
| +[mapa-side-row][mapa-side-gutter] { |
| + display: grid; |
| + grid-template-columns: 16px minmax(0, 1fr) auto; |
| + align-items: center; |
| + padding-inline-start: calc(var(--rst-sp-4) * var(--mapa-depth, 0)); |
| +} |
| +[mapa-side-row][data-depth="1"] { --mapa-depth: 1; } |
| +[mapa-side-row][data-depth="2"] { --mapa-depth: 2; } |
| +[mapa-side-row][data-depth="3"] { --mapa-depth: 3; } |
| +[mapa-side-row][data-depth="4"] { --mapa-depth: 4; } |
| +[mapa-side-arrow-form] { display: contents; } |
| +[mapa-side-arrow] { |
| + display: grid; |
| + place-items: center; |
| + inline-size: 16px; |
| + block-size: 24px; |
| + padding: 0; |
| + border: 0; |
| + background: none; |
| + color: var(--rst-text-muted); |
| + cursor: pointer; |
| +} |
| +[mapa-side-arrow] svg { inline-size: 12px; block-size: 12px; } |
| +[mapa-side-arrow][aria-expanded="true"] svg { transform: rotate(90deg); } |
| +[mapa-side-arrow]:hover { color: var(--rst-text); } |
| +@media (prefers-reduced-motion: no-preference) { |
| + [mapa-side-arrow] svg { transition: transform 120ms ease; } |
| +} |
| +ul[mapa-side-inside] { list-style: none; margin: 0; padding: 0; } |
| +[mapa-side-all] { |
| + display: block; |
| + padding: var(--rst-sp-1) var(--rst-sp-2) var(--rst-sp-1) var(--rst-sp-6); |
| + color: var(--rst-text-muted); |
| + font-size: 13px; |
| +} |
diff --git a/internal/mapa/static/mapa.js b/internal/mapa/static/mapa.js| index 123c0f3..2849893 100644 |
| --- a/internal/mapa/static/mapa.js |
| +++ b/internal/mapa/static/mapa.js |
| @@ -907,6 +907,40 @@ |
| }); |
| } |
| + // ---- Pages inside (columns and icons spec §5.3) ------------------------- |
| + // An arrow is a form that sets the mapa-open cookie and comes back. With |
| + // script it is sent in the background and the sidebar the server draws |
| + // for the page is put in place, so the rows open at once and the page |
| + // and what was typed stay as they are. No busy rule: like the fold, it |
| + // switches at once. |
| + function sideArrows() { |
| + document.addEventListener("submit", function (event) { |
| + var form = event.target.closest && event.target.closest("form[mapa-side-arrow-form]"); |
| + if (!form) return; |
| + event.preventDefault(); |
| + var id = form.querySelector('input[name="id"]').value; |
| + fetch(form.action, { method: "POST", body: new URLSearchParams(new FormData(form)), |
| + credentials: "same-origin" }).then(function (response) { |
| + return response.text(); |
| + }).then(function (html) { |
| + // Only this row and its list are put in place: the rest of the |
| + // sidebar keeps its listeners. |
| + var row = form.closest("[mapa-side-row]"); |
| + var page = new DOMParser().parseFromString(html, "text/html"); |
| + var input = page.querySelector('nav[mapa-side] form[mapa-side-arrow-form] input[name="id"][value="' + id + '"]'); |
| + var fresh = input && input.closest("[mapa-side-row]"); |
| + if (!row || !fresh) { window.location.reload(); return; } |
| + var old = row.nextElementSibling; |
| + if (old && old.matches("ul[mapa-side-inside]")) old.remove(); |
| + var list = fresh.nextElementSibling; |
| + row.replaceWith(fresh); |
| + if (list && list.matches("ul[mapa-side-inside]")) fresh.after(list); |
| + var button = fresh.querySelector("[mapa-side-arrow]"); |
| + if (button) button.focus({ preventScroll: true }); |
| + }).catch(function () { form.submit(); }); |
| + }); |
| + } |
| + |
| // ---- Start ---------------------------------------------------------------- |
| function start() { |
| @@ -938,6 +972,7 @@ |
| }); |
| newTeamPage(); |
| rowMenus(); |
| + sideArrows(); |
| offerZone(); |
| } |
diff --git a/internal/mapa/templates/frame.html b/internal/mapa/templates/frame.html| index 74a7a87..f16761a 100644 |
| --- a/internal/mapa/templates/frame.html |
| +++ b/internal/mapa/templates/frame.html |
| @@ -166,7 +166,16 @@ |
| </div> |
| </nav>{{end}} |
| {{define "mapa-side-place"}}{{icon .Icon}}<span mapa-side-label>{{.Label}}</span>{{if eq .Href "/search"}}<kbd mapa-kbd aria-hidden="true">⌘K</kbd>{{end}}{{end}} |
| -{{define "mapa-side-link"}}<div mapa-side-row><a mapa-side-item mapa-side-page href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{pageIcon .Look .Icon}}<span mapa-side-label>{{.Label}}{{if .Private}}<span mapa-sr>, only you see this</span>{{end}}</span>{{if .Private}}<span mapa-side-lock aria-hidden="true">{{icon "lock"}}</span>{{end}}</a>{{template "mapa-row-menu" .}}</div>{{end}} |
| +{{define "mapa-side-link"}}<div mapa-side-row{{if .Gutter}} mapa-side-gutter data-depth="{{.Depth}}"{{end}}>{{if .Gutter}}{{template "mapa-side-arrow" .}}{{end}}<a mapa-side-item mapa-side-page href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{pageIcon .Look .Icon}}<span mapa-side-label>{{.Label}}{{if .Private}}<span mapa-sr>, only you see this</span>{{end}}</span>{{if .Private}}<span mapa-side-lock aria-hidden="true">{{icon "lock"}}</span>{{end}}</a>{{template "mapa-row-menu" .}}</div>{{if .Open}}<ul mapa-side-inside role="group" id="{{.ListID}}" aria-label="Pages inside {{.Label}}"> |
| + {{- range .Inside}}<li>{{template "mapa-side-link" .}}</li>{{end}} |
| + {{- if .More}}<li><a mapa-side-all href="{{.Href}}/inside">All {{number L .All}} pages inside</a></li>{{end}} |
| +</ul>{{end}}{{end}} |
| + |
| +{{/* mapa-side-arrow: a Pinned row's disclosure (columns and icons spec |
| + §5.3), a form so it works with no script: POST /view/open sets the |
| + cookie and comes back. A row with nothing inside keeps the empty |
| + cell, so every icon in Pinned lines up. Data: sideLink. */}} |
| +{{define "mapa-side-arrow"}}{{if .Arrow}}<form method="post" action="/view/open" mapa-side-arrow-form><input type="hidden" name="id" value="{{.Public}}"><input type="hidden" name="open" value="{{if .Open}}0{{else}}1{{end}}"><input type="hidden" name="return" value="{{.Return}}"><button type="submit" mapa-side-arrow aria-expanded="{{if .Open}}true{{else}}false{{end}}"{{if .Open}} aria-controls="{{.ListID}}"{{end}} aria-label="Pages inside {{.Label}}">{{icon "chevron-right"}}</button></form>{{else}}<span mapa-side-arrow-gap aria-hidden="true"></span>{{end}}{{end}} |
| {{/* mapa-row-menu: a page row's ⋯ (build note 88), the link's sibling, |
| never inside it. A <details> in estilo's group, as the bar's menus |
diff --git a/internal/mapa/templates/inside.html b/internal/mapa/templates/inside.html| new file mode 100644 |
| index 0000000..a855f57 |
| --- /dev/null |
| +++ b/internal/mapa/templates/inside.html |
| @@ -0,0 +1,9 @@ |
| +{{/* inside: every page inside a team page (columns and icons spec |
| + §5.3), the sidebar's "All pages inside" link. Data: Page, Rows. */}} |
| +{{define "content"}}{{$page := .Data.Page}} |
| +{{template "back-nav" dict "Href" $page.Href "Label" $page.Label}} |
| +{{template "page-header" dict "Title" (printf "Pages inside %s" $page.Label) "Sub" "Each one starts with a line that says it is inside this page."}} |
| +<ul mapa-list> |
| +{{range .Data.Rows}}<li><a href="{{.Href}}" mapa-looked>{{pageIcon .Look "file-text"}}<span>{{.Label}}</span></a></li> |
| +{{end}}</ul> |
| +{{end}} |
diff --git a/internal/mapatest/gate8_test.go b/internal/mapatest/gate8_test.go| index b18b293..a06496d 100644 |
| --- a/internal/mapatest/gate8_test.go |
| +++ b/internal/mapatest/gate8_test.go |
| @@ -136,6 +136,10 @@ func gate8Steps(t *testing.T, world *rig) []step { |
| url.Values{"state": {"rail"}, "return": {"/"}}), |
| posting("/view/links", Ana, "/view/links", |
| url.Values{"state": {"closed"}, "return": {"/"}}), |
| + // The sidebar's arrows: a cookie, no row (columns and icons |
| + // spec §5.3). |
| + posting("/view/open", Ana, "/view/open", |
| + url.Values{"id": {"x"}, "open": {"1"}, "return": {"/"}}), |
| posting("/p/{id}/pin", Bo, acme+"/pin", url.Values{"pin": {"1"}}), |
| // A team page's look: a styled revision (columns and icons |
| // spec §4.1). |
diff --git a/internal/mapatest/inside_test.go b/internal/mapatest/inside_test.go| new file mode 100644 |
| index 0000000..e210fdc |
| --- /dev/null |
| +++ b/internal/mapatest/inside_test.go |
| @@ -0,0 +1,119 @@ |
| +package mapatest |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// IN3, IN4, IN6 and IN7 (columns and icons spec §5, §9), from the |
| +// outside: the arrow on a pinned row, its rows, what scope shows, what |
| +// is written (nothing), the scriptless form, cycles and the caps. |
| + |
| +// pinned is a team page made by Ana and pinned by Bo. |
| +func pinned(t *testing.T, rig *rig, title, body string) string { |
| + t.Helper() |
| + path := rig.createPage(t, Ana, title, body) |
| + rig.post(t, Bo, path+"/pin", url.Values{"pin": {"1"}}) |
| + return path |
| +} |
| + |
| +// opened is a page as Bo sees it with the rows of ids open. |
| +func opened(t *testing.T, rig *rig, path string, ids ...string) string { |
| + t.Helper() |
| + request, _ := http.NewRequest(http.MethodGet, path, nil) |
| + request.AddCookie(&http.Cookie{Name: "mapa-open", |
| + Value: strings.Join(ids, " ")}) |
| + recorder := httptest.NewRecorder() |
| + rig.built.As(Bo).ServeHTTP(recorder, request) |
| + return recorder.Body.String() |
| +} |
| + |
| +func TestIN6AnArrowOpensThePagesInside(t *testing.T) { |
| + rig := newRig(t) |
| + projects := pinned(t, rig, "Projects", "See [[Beta]].") |
| + rig.createPage(t, Ana, "Alpha", "In: [[Projects]]\n\nA.") |
| + rig.createPage(t, Ana, "Beta", "In: [[Projects]]\n\nB.") |
| + closed := rig.page(t, Bo, projects) |
| + if !strings.Contains(closed, `aria-label="Pages inside Projects"`) || |
| + !strings.Contains(closed, `aria-expanded="false"`) { |
| + t.Fatal("the pinned row has no closed arrow") |
| + } |
| + answer := rig.post(t, Bo, "/view/open", url.Values{ |
| + "id": {strings.TrimPrefix(projects, "/p/")}, "open": {"1"}, |
| + "return": {projects}}) |
| + if answer.Code != http.StatusSeeOther || |
| + !strings.Contains(answer.Header().Get("Set-Cookie"), "mapa-open=") { |
| + t.Fatalf("the arrow's form: %d", answer.Code) |
| + } |
| + open := opened(t, rig, projects, strings.TrimPrefix(projects, "/p/")) |
| + beta := strings.Index(open, "mapa-side-label>Beta<") |
| + alpha := strings.Index(open, "mapa-side-label>Alpha<") |
| + if !strings.Contains(open, `aria-expanded="true"`) || beta < 0 || |
| + alpha < beta { |
| + t.Fatal("the open row does not list Beta then Alpha") |
| + } |
| + answer = rig.post(t, Bo, "/view/open", url.Values{"id": {"x"}, |
| + "open": {"1"}, "return": {"https://example.com/"}}) |
| + if answer.Header().Get("Location") != "/" { |
| + t.Fatal("a foreign return was followed") |
| + } |
| +} |
| + |
| +func TestIN3PrivateInLinesAreNoPageInside(t *testing.T) { |
| + rig := newRig(t) |
| + projects := pinned(t, rig, "Projects", "Text.") |
| + id := strings.TrimPrefix(projects, "/p/") |
| + before := opened(t, rig, projects, id) |
| + rig.post(t, Ana, "/scratch", url.Values{"body": {"In: [[Projects]]"}}) |
| + if after := opened(t, rig, projects, id); after != before { |
| + t.Fatal("Ana's private note changed Bo's sidebar") |
| + } |
| + if strings.Contains(before, "Pages inside Projects") { |
| + t.Fatal("an arrow on a page with nothing inside") |
| + } |
| +} |
| + |
| +func TestIN4OpeningWritesNothing(t *testing.T) { |
| + rig := newRig(t) |
| + projects := pinned(t, rig, "Projects", "Text.") |
| + rig.createPage(t, Ana, "Alpha", "In: [[Projects]]") |
| + before := snapshot(t, rig) |
| + rig.post(t, Bo, "/view/open", url.Values{"id": {"x"}, "open": {"1"}}) |
| + if code := rig.get(t, Bo, projects+"/inside").Code; code != http.StatusOK { |
| + t.Fatalf("all pages inside: %d", code) |
| + } |
| + if snapshot(t, rig) != before { |
| + t.Fatal("opening a row or the list wrote a row") |
| + } |
| +} |
| + |
| +func TestIN7CyclesAndCaps(t *testing.T) { |
| + rig := newRig(t) |
| + one := pinned(t, rig, "One", "In: [[Two]]") |
| + two := rig.createPage(t, Ana, "Two", "In: [[One]]") |
| + page := opened(t, rig, one, strings.TrimPrefix(one, "/p/"), |
| + strings.TrimPrefix(two, "/p/")) |
| + // One's row opens Two, whose row lists One again without an arrow. |
| + if strings.Count(page, "mapa-side-label>Two<") != 1 || |
| + strings.Count(page, "mapa-side-label>One<") != 2 || |
| + strings.Count(page, `<button type="submit" mapa-side-arrow`) != 2 { |
| + t.Fatal("a cycle opened more than once") |
| + } |
| + big := pinned(t, rig, "Big", "Text.") |
| + for at := range 51 { |
| + rig.createPage(t, Ana, "Child "+strings.Repeat("x", at+1), |
| + "In: [[Big]]") |
| + } |
| + page = opened(t, rig, big, strings.TrimPrefix(big, "/p/")) |
| + if strings.Count(page, `mapa-side-label>Child x`) != 50 || |
| + !strings.Contains(page, big+`/inside">All 51 pages inside`) { |
| + t.Fatal("51 pages inside are not 50 rows and a link") |
| + } |
| + if all := rig.page(t, Bo, big+"/inside"); strings.Count(all, |
| + ">Child x") != 51 { |
| + t.Fatal("the list of all pages inside is not all of them") |
| + } |
| +} |