Phase 1 step 2: the shell — estilo's stacked bar with Mapa's menus, a sidebar that folds to Página's rail
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Human
Prompt
Phase 1 step 2 of the Mapa level-up (spec section 12): the stacked header, the sidebar, rail, fold and cookie, the Menu sheet below 800px, New team page.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
Every signed-in page now sits under estilo's stacked bar (Page, Edit, Insert, View, Help; lead with presence, save status and the day pill; Search, History, Links actions) with Mapa's own sidebar of one-grid rows that folds to a 56px rail by cookie or by width (open from 80rem). View cookies are POST forms with a checked local return, driven in gate 8. The preview script takes PREVIEW_ADDR and MAPA_ORIGIN. The walk's palette step now waits for the answer to the whole word.
Agent notes
Recently edited and Pinned are stubbed in side.go (step 8). The gate-7 walk had a real race (the palette could show the answer for 'Acm'); fixed in the test.
18 files changed,
+1,020
−38
internal/mapa/frame.go+141 −0internal/mapa/frame_test.go+23 −0internal/mapa/funcs.go+25 −3internal/mapa/handlers_history.go+3 −1internal/mapa/handlers_pages.go+8 −2internal/mapa/icons/icons.go+14 −0internal/mapa/menus.go+152 −0internal/mapa/render.go+4 −1internal/mapa/shell.go+18 −5internal/mapa/side.go+126 −0internal/mapa/static/frame.css+266 −0internal/mapa/static/mapa.js+111 −1internal/mapa/templates/frame.html+83 −0internal/mapa/templates/shell.html+14 −19internal/mapa/today.go+5 −1internal/mapatest/browser_test.go+3 −1internal/mapatest/gate8_test.go+5 −0scripts/preview/main.go+19 −4
CI failed — run details
CI log
=== 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/browser_test.go line 190: 81 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:67: 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/internal/mapa/frame.go b/internal/mapa/frame.go| new file mode 100644 |
| index 0000000..b865606 |
| --- /dev/null |
| +++ b/internal/mapa/frame.go |
| @@ -0,0 +1,141 @@ |
| +package mapa |
| + |
| +import ( |
| + "bytes" |
| + "html/template" |
| + "net/http" |
| + |
| + "amadan.net/oficina/estilo.git/chrome" |
| + "amadan.net/oficina/estilo.git/menu" |
| +) |
| + |
| +// frame is the shell around every signed-in page (level-up spec §3): |
| +// estilo's stacked bar with Mapa's menus, its lead and its actions, and |
| +// the sidebar that folds to a rail. show builds it from the view. |
| +type frame struct { |
| + Bar chrome.Bar |
| + Side sideView |
| + // Panel is "open" or "closed": the Links panel's cookie, rendered |
| + // so first paint is already right. Empty on screens without one. |
| + Panel string |
| +} |
| + |
| +// pageChrome is what a handler says about its screen, beyond its title, |
| +// so the bar can draw the right menus, lead and actions. Nil is a list |
| +// or a form screen: the plain title and the app's own menus. |
| +type pageChrome struct { |
| + // Page is the page on screen, if there is one. |
| + Page *PageView |
| + // Editor marks a screen holding the Markdown textarea: Edit and |
| + // Insert act on it, and the lead shows its save status. |
| + Editor bool |
| + // Day is a daily note's day pill; nil elsewhere. |
| + Day *dayPill |
| + // Editing is "Ana is editing" for a team page (base §5). |
| + Editing []string |
| + // Links marks a screen that carries the Links panel. |
| + Links bool |
| +} |
| + |
| +// dayPill is ‹ Today › on a daily note (§4.4). |
| +type dayPill struct { |
| + Date, Today, Prev, Next string |
| +} |
| + |
| +// leadView is the lead slot's data: presence, save status, the pill. |
| +type leadView struct { |
| + Editing []string |
| + Status bool |
| + Day *dayPill |
| +} |
| + |
| +// buildFrame draws the frame for one request. The menubar and the lead |
| +// are this app's templates, rendered into the bar's trusted slots. |
| +func (app *app) buildFrame(request *http.Request, page *view) error { |
| + tmpl := pages[page.name] |
| + menus, err := fragment(tmpl, "mapa-menubar", menusFor(page)) |
| + if err != nil { |
| + return err |
| + } |
| + lead, err := fragment(tmpl, "mapa-lead", leadFor(page.Chrome)) |
| + if err != nil { |
| + return err |
| + } |
| + address, _ := app.identity(request) |
| + page.Frame.Bar = chrome.Bar{ |
| + App: chrome.App{Name: "Mapa", Slug: themeSlug, Home: "/", |
| + Icon: assets.Path("static/brand/icon.svg")}, |
| + Context: page.Title, ContextEdit: titleEdit(page.Chrome), |
| + Nav: placesNav(page.Nav), NavLabel: "Mapa", |
| + Actions: barActions(page), Account: app.account(request, address), |
| + Sticky: true, Labels: chrome.BarLabels{Skip: "Skip to content", |
| + Menu: "Menu"}, |
| + Menubar: menus, Lead: lead, |
| + } |
| + page.Frame.Side = app.side(request, page) |
| + if page.Chrome != nil && page.Chrome.Links { |
| + page.Frame.Panel = linksState(request) |
| + } |
| + return nil |
| +} |
| + |
| +// fragment renders one named template into trusted markup for a slot. |
| +func fragment(tmpl *template.Template, name string, |
| + data any) (template.HTML, error) { |
| + var buffer bytes.Buffer |
| + if err := tmpl.ExecuteTemplate(&buffer, name, data); err != nil { |
| + return "", err |
| + } |
| + return template.HTML(buffer.String()), nil |
| +} |
| + |
| +// titleEdit is a team page's title, renamed in place through the |
| +// existing rename POST; nil leaves the read-only title (§3.1). |
| +func titleEdit(page *pageChrome) *chrome.TitleEdit { |
| + if page == nil || page.Page == nil || page.Page.Kind != KindPage { |
| + return nil |
| + } |
| + return &chrome.TitleEdit{ |
| + Action: "/p/" + page.Page.Public + "/rename", Name: "title", |
| + Value: page.Page.Title, Label: "Page title", Submit: "Rename"} |
| +} |
| + |
| +func leadFor(page *pageChrome) leadView { |
| + if page == nil { |
| + return leadView{} |
| + } |
| + return leadView{Editing: page.Editing, Status: page.Editor, |
| + Day: page.Day} |
| +} |
| + |
| +// placesNav is the sidebar's places as the bar's nav. estilo shows them |
| +// as rows in the Menu sheet below 800px, where there is no sidebar; |
| +// mapa.css hides the bar's own copy from 800px, where the sidebar is. |
| +func placesNav(items []NavItem) []chrome.Link { |
| + links := make([]chrome.Link, 0, len(items)) |
| + for _, item := range items { |
| + links = append(links, chrome.Link{Href: item.Href, |
| + Label: item.Label, Current: item.Current}) |
| + } |
| + return links |
| +} |
| + |
| +// barActions are Search, History and Links (§3.1). History needs a page |
| +// with history; Links, a screen with the panel. |
| +func barActions(page *view) []chrome.Action { |
| + actions := []chrome.Action{{Item: menu.Item{Href: "/search", |
| + Label: "Search"}, Icon: iconHTML("search")}} |
| + chromeOf := page.Chrome |
| + if chromeOf != nil && chromeOf.Page != nil && chromeOf.Page.ID != 0 { |
| + actions = append(actions, chrome.Action{Item: menu.Item{ |
| + Href: "/p/" + chromeOf.Page.Public + "/history", |
| + Label: "History"}, Icon: iconHTML("history")}) |
| + } |
| + if chromeOf != nil && chromeOf.Links { |
| + actions = append(actions, chrome.Action{Item: menu.Item{ |
| + Label: "Links", Controls: "mapa-links", |
| + Expanded: page.Frame.Panel != "closed"}, |
| + WideOnly: true, Icon: iconHTML("panel-right")}) |
| + } |
| + return actions |
| +} |
diff --git a/internal/mapa/frame_test.go b/internal/mapa/frame_test.go| new file mode 100644 |
| index 0000000..d227c68 |
| --- /dev/null |
| +++ b/internal/mapa/frame_test.go |
| @@ -0,0 +1,23 @@ |
| +package mapa |
| + |
| +import "testing" |
| + |
| +// The view forms come back only to a path on this site (level-up §3.2): |
| +// anything that could leave it falls back to Today. |
| +func TestLocalReturnRefusesAnythingOffSite(t *testing.T) { |
| + cases := map[string]string{ |
| + "/p/abc": "/p/abc", |
| + "/d/2026-11-14?x=1": "/d/2026-11-14?x=1", |
| + "": "/", |
| + "https://evil.example": "/", |
| + "//evil.example/": "/", |
| + "/\\evil.example": "/", |
| + "/ok\r\nSet-Cookie: x": "/", |
| + "javascript:alert(1)": "/", |
| + } |
| + for given, want := range cases { |
| + if got := localReturn(given); got != want { |
| + t.Errorf("localReturn(%q) = %q, want %q", given, got, want) |
| + } |
| + } |
| +} |
diff --git a/internal/mapa/funcs.go b/internal/mapa/funcs.go| index 01c7f27..22dfbbb 100644 |
| --- a/internal/mapa/funcs.go |
| +++ b/internal/mapa/funcs.go |
| @@ -4,13 +4,17 @@ import ( |
| "fmt" |
| "html/template" |
| "time" |
| + |
| + "amadan.net/oficina/estilo.git/savestatus" |
| ) |
| // templateFuncs is what Mapa's own templates call, beside rastrillo's. |
| var templateFuncs = template.FuncMap{ |
| - "asset": assets.Path, |
| - "ago": ago, |
| - "longDate": longDate, |
| + "asset": assets.Path, |
| + "ago": ago, |
| + "longDate": longDate, |
| + "shortDate": shortDate, |
| + "saveStatus": saveStatus, |
| } |
| // ago is a past moment in words, for a <time> whose title carries the |
| @@ -48,3 +52,21 @@ func longDate(iso string) string { |
| } |
| return day.Format("Monday 2 January 2006") |
| } |
| + |
| +// shortDate is a day on a pill: "Thu 12 Nov". Anything that does not |
| +// parse is shown as it is. |
| +func shortDate(iso string) string { |
| + day, err := time.Parse(time.DateOnly, iso) |
| + if err != nil { |
| + return iso |
| + } |
| + return day.Format("Mon 2 Jan") |
| +} |
| + |
| +// saveStatus is estilo's save status in the lead slot, idle until the |
| +// editor reports (§3.1). |
| +func saveStatus() savestatus.Data { |
| + return savestatus.Data{State: "idle", Saved: "Saved", |
| + Saving: "Saving…", Retrying: "Retrying…", Failed: "Not saved", |
| + Label: "Save status"} |
| +} |
diff --git a/internal/mapa/handlers_history.go b/internal/mapa/handlers_history.go| index e641ce3..423d006 100644 |
| --- a/internal/mapa/handlers_history.go |
| +++ b/internal/mapa/handlers_history.go |
| @@ -35,7 +35,8 @@ func (app *app) history(writer http.ResponseWriter, request *http.Request) { |
| } |
| app.show(writer, request, http.StatusOK, "history", view{ |
| Title: page.Label, Nav: nav(navFor(page.Kind)), Viewer: viewer, |
| - Data: map[string]any{"Page": page, "Revisions": revisions}}) |
| + Data: map[string]any{"Page": page, "Revisions": revisions}, |
| + Chrome: &pageChrome{Page: &page}}) |
| } |
| func (app *app) revision(writer http.ResponseWriter, |
| @@ -68,6 +69,7 @@ func (app *app) revision(writer http.ResponseWriter, |
| } |
| app.show(writer, request, http.StatusOK, "revision", view{ |
| Title: page.Label, Nav: nav(navFor(page.Kind)), Viewer: viewer, |
| + Chrome: &pageChrome{Page: &page}, |
| Data: map[string]any{"Page": page, "Record": record, "HTML": html, |
| "Current": revision == page.Revision, |
| "Action": request.URL.Path}}) |
diff --git a/internal/mapa/handlers_pages.go b/internal/mapa/handlers_pages.go| index 9b89cd2..4414955 100644 |
| --- a/internal/mapa/handlers_pages.go |
| +++ b/internal/mapa/handlers_pages.go |
| @@ -95,7 +95,8 @@ func (app *app) showPage(writer http.ResponseWriter, |
| } |
| data["Editing"] = editing |
| app.show(writer, request, http.StatusOK, "page", view{Title: page.Label, |
| - Nav: nav(navFor(page.Kind)), Viewer: viewer, Data: data}) |
| + Nav: nav(navFor(page.Kind)), Viewer: viewer, Data: data, |
| + Chrome: &pageChrome{Page: &page, Editing: editing}}) |
| } |
| // navFor is the rail entry a page belongs under. |
| @@ -140,8 +141,13 @@ func (app *app) showForm(writer http.ResponseWriter, request *http.Request, |
| if form.Page.ID != 0 { |
| title = form.Page.Label |
| } |
| + var screen *pageChrome |
| + if form.Page.ID != 0 { |
| + screen = &pageChrome{Page: &form.Page, Editor: name == "page_edit"} |
| + } |
| app.show(writer, request, status, name, view{Title: title, |
| - Nav: nav(navFor(form.Page.Kind)), Viewer: viewer, Data: form}) |
| + Nav: nav(navFor(form.Page.Kind)), Viewer: viewer, Data: form, |
| + Chrome: screen}) |
| } |
| func (app *app) createPage(writer http.ResponseWriter, |
diff --git a/internal/mapa/icons/icons.go b/internal/mapa/icons/icons.go| index 4a5a532..09fea58 100644 |
| --- a/internal/mapa/icons/icons.go |
| +++ b/internal/mapa/icons/icons.go |
| @@ -28,6 +28,20 @@ var icons = map[string]template.HTML{ |
| "search": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>`, |
| "x": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`, |
| "x-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`, |
| + "files": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M20 7h-3a2 2 0 0 1-2-2V2"/><path d="M9 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7l4 4v10a2 2 0 0 1-2 2Z"/><path d="M3 7.6v12.8A1.6 1.6 0 0 0 4.6 22h9.8"/></svg>`, |
| + "file": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M9 13h6"/><path d="M9 17h4"/></svg>`, |
| + "file-plus": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M9 15h6"/><path d="M12 12v6"/></svg>`, |
| + "panel-left": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/></svg>`, |
| + "panel-right": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M15 3v18"/></svg>`, |
| + "chevron-left": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>`, |
| + "chevron-right": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>`, |
| + "link": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>`, |
| + "users": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>`, |
| + "lock": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>`, |
| + "map": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><circle cx="4.5" cy="5" r="2"/><circle cx="19.5" cy="6" r="2"/><circle cx="18" cy="19.5" r="2"/><path d="m6.2 6.3 3.6 3.6"/><path d="m17.8 7.2-3.5 3.2"/><path d="m16.6 18-2.6-3.8"/></svg>`, |
| + "pin": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg>`, |
| + "rotate-ccw": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>`, |
| + "keyboard": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M10 8h.01"/><path d="M12 12h.01"/><path d="M14 8h.01"/><path d="M16 12h.01"/><path d="M18 8h.01"/><path d="M6 8h.01"/><path d="M7 16h10"/><path d="M8 12h.01"/><rect width="20" height="16" x="2" y="4" rx="2"/></svg>`, |
| } |
| // Icon renders one icon, aria-hidden beside its visible label: a control |
diff --git a/internal/mapa/menus.go b/internal/mapa/menus.go| new file mode 100644 |
| index 0000000..163590f |
| --- /dev/null |
| +++ b/internal/mapa/menus.go |
| @@ -0,0 +1,152 @@ |
| +package mapa |
| + |
| +import ( |
| + "html/template" |
| + |
| + "amadan.net/oficina/mapa/internal/mapa/icons" |
| +) |
| + |
| +// The menu bar (level-up spec §3.4): Page, Edit, Insert, View and Help. |
| +// Each menu is a <details> (Docs' reason: it opens with no script), and |
| +// an entry that does not apply to the screen is not drawn. |
| + |
| +// menuBar is templates/frame.html's mapa-menubar data. |
| +type menuBar struct { |
| + Label string |
| + Menus []menuGroup |
| +} |
| + |
| +// menuGroup is one menu: its id, title and entries. |
| +type menuGroup struct { |
| + ID, Title string |
| + Items []menuEntry |
| +} |
| + |
| +// menuEntry is one row. Kind is "link", "form" (a POST with Fields), |
| +// "command" (a button mapa.js binds; disabled until it does), "dialog" |
| +// (opens the <dialog> with id Dialog) or "divider". |
| +type menuEntry struct { |
| + Kind, Label, Href, Action, Command, Dialog, Key string |
| + Fields map[string]string |
| + Danger bool |
| +} |
| + |
| +func link(label, href string) menuEntry { |
| + return menuEntry{Kind: "link", Label: label, Href: href} |
| +} |
| + |
| +func command(label, name, key string) menuEntry { |
| + return menuEntry{Kind: "command", Label: label, Command: name, Key: key} |
| +} |
| + |
| +var divider = menuEntry{Kind: "divider"} |
| + |
| +// menusFor is the bar's menus for one screen. |
| +func menusFor(page *view) menuBar { |
| + groups := []menuGroup{{ID: "page", Title: "Page", |
| + Items: pageMenu(page.Chrome)}} |
| + if page.Chrome != nil && page.Chrome.Editor { |
| + groups = append(groups, menuGroup{ID: "edit", Title: "Edit", |
| + Items: editMenu()}, menuGroup{ID: "insert", Title: "Insert", |
| + Items: insertMenu()}) |
| + } |
| + groups = append(groups, menuGroup{ID: "view", Title: "View", |
| + Items: viewMenu(page)}, menuGroup{ID: "help", Title: "Help", |
| + Items: helpMenu()}) |
| + return menuBar{Label: "Mapa", Menus: groups} |
| +} |
| + |
| +// pageMenu is New, then what this page allows, then the lists. |
| +func pageMenu(page *pageChrome) []menuEntry { |
| + items := []menuEntry{link("New team page", "/new"), |
| + link("New scratch page", "/scratch/new")} |
| + if page != nil && page.Page != nil && page.Page.ID != 0 { |
| + items = append(items, divider) |
| + items = append(items, pageVerbs(*page.Page)...) |
| + } |
| + return append(items, divider, link("Deleted pages", "/deleted")) |
| +} |
| + |
| +func pageVerbs(page PageView) []menuEntry { |
| + base := "/p/" + page.Public |
| + var items []menuEntry |
| + if page.Kind == KindPage { |
| + items = append(items, link("Rename…", base+"/rename"), |
| + link("Link to a block…", base+"/blocks")) |
| + } |
| + if page.Rung == RungPrivate { |
| + items = append(items, link("Make team page…", base+"/share")) |
| + } |
| + return append(items, link("History", base+"/history"), |
| + menuEntry{Kind: "link", Label: "Delete…", Href: base + "/delete", |
| + Danger: true}) |
| +} |
| + |
| +// editMenu acts on the textarea; mapa.js binds each command. |
| +func editMenu() []menuEntry { |
| + return []menuEntry{command("Undo", "undo", "⌘Z"), |
| + command("Redo", "redo", "⇧⌘Z"), divider, |
| + command("Select all", "select-all", "⌘A")} |
| +} |
| + |
| +// insertMenu puts Markdown in at the caret, its shortcut shown, so the |
| +// menu quietly teaches that the page is Markdown (§3.4, §6.6). |
| +func insertMenu() []menuEntry { |
| + return []menuEntry{ |
| + command("Heading 1", "insert-h1", "#"), |
| + command("Heading 2", "insert-h2", "##"), |
| + command("Heading 3", "insert-h3", "###"), divider, |
| + command("List", "insert-list", "-"), |
| + command("Numbered list", "insert-numbered", "1."), |
| + command("Checklist", "insert-check", "- [ ]"), divider, |
| + command("Quote", "insert-quote", ">"), |
| + command("Code", "insert-code", "```"), |
| + command("Divider", "insert-rule", "---"), divider, |
| + command("Link to a page", "insert-link", "[["), |
| + command("Today's date", "insert-date", "[[date]]"), |
| + } |
| +} |
| + |
| +// viewMenu folds the sidebar and toggles the panel. Each is a POST that |
| +// sets its cookie, so it works with scripts off; mapa.js does both in |
| +// place. |
| +func viewMenu(page *view) []menuEntry { |
| + back := page.Return |
| + items := []menuEntry{{Kind: "form", Label: "Fold sidebar", |
| + Action: "/view/sidebar", Command: "toggle-sidebar", Key: "⌘\\", |
| + Fields: map[string]string{"return": back}}} |
| + if page.Chrome != nil && page.Chrome.Links { |
| + items = append(items, menuEntry{Kind: "form", Label: "Links panel", |
| + Action: "/view/links", Command: "toggle-links", |
| + Fields: map[string]string{"return": back}}) |
| + } |
| + if href := markdownHref(page.Chrome); href != "" { |
| + items = append(items, divider, link("Edit as Markdown", href)) |
| + } |
| + return items |
| +} |
| + |
| +// markdownHref is the textarea screen for the page on show, if any. |
| +func markdownHref(page *pageChrome) string { |
| + if page == nil || page.Page == nil || page.Editor { |
| + return "" |
| + } |
| + if page.Page.Kind == KindDaily { |
| + return "/d/" + page.Page.Date + "/edit" |
| + } |
| + if page.Page.ID == 0 { |
| + return "" |
| + } |
| + return "/p/" + page.Page.Public + "/edit" |
| +} |
| + |
| +func helpMenu() []menuEntry { |
| + return []menuEntry{ |
| + {Kind: "dialog", Label: "Keyboard shortcuts", Dialog: "mapa-keys"}, |
| + link("Markdown in Mapa", "/help/markdown"), |
| + } |
| +} |
| + |
| +// iconHTML is one of Mapa's icons for a bar action (estilo draws it |
| +// before the label, decoratively). |
| +func iconHTML(slug string) template.HTML { return icons.Icon(slug) } |
diff --git a/internal/mapa/render.go b/internal/mapa/render.go| index 1353a4e..a5d00bd 100644 |
| --- a/internal/mapa/render.go |
| +++ b/internal/mapa/render.go |
| @@ -12,6 +12,7 @@ import ( |
| "amadan.net/oficina/estilo.git/busy" |
| "amadan.net/oficina/estilo.git/chrome" |
| "amadan.net/oficina/estilo.git/menu" |
| + "amadan.net/oficina/estilo.git/savestatus" |
| "amadan.net/oficina/estilo.git/sky" |
| "amadan.net/oficina/estilo.git/theme" |
| "amadan.net/rastrillo/rastrillo" |
| @@ -52,6 +53,7 @@ var assets = rastrillo.NewAssets(func() fs.FS { |
| "static/chrome.js": {Data: chrome.JS()}, |
| "static/menu.css": {Data: menu.CSS()}, |
| "static/sky.css": {Data: sky.CSS()}, |
| + "static/savestatus.css": {Data: savestatus.CSS()}, |
| "static/brand/icon.svg": {Data: brandIcon()}, |
| } |
| own, err := fs.Glob(appFS, "static/*") |
| @@ -96,9 +98,10 @@ func init() { |
| "templates/*.html")) |
| page = template.Must(page.ParseFS(chrome.Templates(), |
| "templates/*.html")) |
| + page = template.Must(page.Parse(savestatus.Template())) |
| pages[name] = template.Must(page.ParseFS(appFS, |
| "templates/"+shell+".html", "templates/partials.html", |
| - "templates/"+name+".html")) |
| + "templates/frame.html", "templates/"+name+".html")) |
| } |
| } |
diff --git a/internal/mapa/shell.go b/internal/mapa/shell.go| index 3508478..f2ebcc8 100644 |
| --- a/internal/mapa/shell.go |
| +++ b/internal/mapa/shell.go |
| @@ -13,13 +13,13 @@ type NavItem struct { |
| Current bool |
| } |
| -// nav is the rail: the same four places on every page. |
| +// nav is the sidebar's places, the same on every page (level-up §3.2). |
| func nav(current string) []NavItem { |
| items := []NavItem{ |
| {Label: "Today", Href: "/", Icon: "calendar"}, |
| - {Label: "Pages", Href: "/pages", Icon: "file-text"}, |
| - {Label: "Scratch", Href: "/scratch", Icon: "sticky-note"}, |
| {Label: "Search", Href: "/search", Icon: "search"}, |
| + {Label: "All pages", Href: "/pages", Icon: "files"}, |
| + {Label: "Scratch", Href: "/scratch", Icon: "file"}, |
| } |
| for index := range items { |
| items[index].Current = items[index].Href == current |
| @@ -36,6 +36,15 @@ type view struct { |
| Theme string |
| Viewer Viewer |
| Data any |
| + // Chrome is what the handler says about its screen (frame.go); nil |
| + // for a list or form screen. |
| + Chrome *pageChrome |
| + // Frame is the bar and the sidebar, built by show. |
| + Frame frame |
| + // Return is this page's own path, for the view forms to come back |
| + // to. |
| + Return string |
| + name string |
| } |
| // show renders a shell page for the signed-in viewer. |
| @@ -44,6 +53,11 @@ func (app *app) show(writer http.ResponseWriter, request *http.Request, |
| address, _ := app.identity(request) |
| page.Account = app.account(request, address) |
| page.Theme = themeAttr(request) |
| + page.name, page.Return = name, returnTarget(request) |
| + if err := app.buildFrame(request, &page); err != nil { |
| + app.fail(writer, request, err) |
| + return |
| + } |
| writer.Header().Set("Cache-Control", "no-store") |
| if status != http.StatusOK { |
| writer.WriteHeader(status) |
| @@ -51,7 +65,7 @@ func (app *app) show(writer http.ResponseWriter, request *http.Request, |
| render(writer, name, page) |
| } |
| -// account is the suite's account menu at the rail's foot (estilo chrome): |
| +// account is the suite's account menu at the bar's end (estilo chrome): |
| // who is signed in, "All apps" with a hub directory, Appearance, Sign out. |
| func (app *app) account(request *http.Request, |
| address string) *chrome.Account { |
| @@ -66,7 +80,6 @@ func (app *app) account(request *http.Request, |
| Options: chrome.AppearanceOptions(chrome.Appearance(request), |
| "Light", "Dark", "System")}, |
| SignOut: chrome.SignOut{Action: "/signout", Label: "Sign out"}, |
| - Rail: true, |
| } |
| account.Items = []menu.Item{{Href: "/settings", Label: "Settings"}, |
| {Href: "/deleted", Label: "Deleted pages"}} |
diff --git a/internal/mapa/side.go b/internal/mapa/side.go| new file mode 100644 |
| index 0000000..82b0f45 |
| --- /dev/null |
| +++ b/internal/mapa/side.go |
| @@ -0,0 +1,126 @@ |
| +package mapa |
| + |
| +import ( |
| + "net/http" |
| + "strings" |
| + |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +// The sidebar and its rail (level-up spec §3.2), and the two view |
| +// cookies. A view preference is not a write: it sets a cookie, touches |
| +// no row and logs no event, so gate 8 lists these routes as view-only. |
| + |
| +const ( |
| + sidebarCookie = "mapa-sidebar" |
| + linksCookie = "mapa-links" |
| + // cookieYear is how long a view preference is kept. |
| + cookieYear = 365 * 24 * 60 * 60 |
| +) |
| + |
| +// sideView is the sidebar's data. |
| +type sideView struct { |
| + // State is the mapa-sidebar cookie: "open", "rail", or "" for the |
| + // default, which CSS decides by width (open from 80rem; §11 Q4, |
| + // proposed, awaiting Paul). |
| + State string |
| + Places []NavItem |
| + // Pinned and Recent are the viewer's own (§3.2): pins (§11 Q1) and |
| + // the pages they last wrote in. |
| + Pinned, Recent []sideLink |
| + Return string |
| +} |
| + |
| +// sideLink is one page row. |
| +type sideLink struct { |
| + Label, Href, Icon string |
| + Current bool |
| +} |
| + |
| +func (app *app) side(request *http.Request, page *view) sideView { |
| + side := sideView{State: sidebarState(request), Places: page.Nav, |
| + Return: page.Return} |
| + side.Pinned, side.Recent = app.sideLists(request, page) |
| + return side |
| +} |
| + |
| +// sidebarState is the cookie, or "" when it holds nothing we know. |
| +func sidebarState(request *http.Request) string { |
| + cookie, err := request.Cookie(sidebarCookie) |
| + if err != nil { |
| + return "" |
| + } |
| + switch cookie.Value { |
| + case "open", "rail": |
| + return cookie.Value |
| + } |
| + return "" |
| +} |
| + |
| +// linksState is the Links panel's cookie: open unless exactly "closed", |
| +// like Docs' docs-inspector. |
| +func linksState(request *http.Request) string { |
| + if cookie, err := request.Cookie(linksCookie); err == nil && |
| + cookie.Value == "closed" { |
| + return "closed" |
| + } |
| + return "open" |
| +} |
| + |
| +func (app *app) viewRoutes(router chi.Router) { |
| + router.Post("/view/sidebar", app.viewSidebar) |
| + router.Post("/view/links", app.viewLinks) |
| +} |
| + |
| +// viewSidebar folds or opens the sidebar. "state" names the new state; |
| +// without it the form toggles from what the page showed ("shown"). |
| +func (app *app) viewSidebar(writer http.ResponseWriter, |
| + request *http.Request) { |
| + state := request.PostFormValue("state") |
| + if state != "open" && state != "rail" { |
| + state = "rail" |
| + if request.PostFormValue("shown") == "rail" { |
| + state = "open" |
| + } |
| + } |
| + setViewCookie(writer, sidebarCookie, state) |
| + seeOther(writer, request, localReturn(request.PostFormValue("return"))) |
| +} |
| + |
| +// viewLinks shows or hides the Links panel. |
| +func (app *app) viewLinks(writer http.ResponseWriter, |
| + request *http.Request) { |
| + state := request.PostFormValue("state") |
| + if state != "open" && state != "closed" { |
| + state = "closed" |
| + if linksState(request) == "closed" { |
| + state = "open" |
| + } |
| + } |
| + setViewCookie(writer, linksCookie, state) |
| + seeOther(writer, request, localReturn(request.PostFormValue("return"))) |
| +} |
| + |
| +func setViewCookie(writer http.ResponseWriter, name, value string) { |
| + http.SetCookie(writer, &http.Cookie{Name: name, Value: value, |
| + Path: "/", MaxAge: cookieYear, SameSite: http.SameSiteLaxMode, |
| + Secure: true}) |
| +} |
| + |
| +// localReturn is a path on this site, or "/". It refuses anything that |
| +// could leave it: a scheme, a host, "//", or a backslash a browser might |
| +// read as a slash. |
| +func localReturn(target string) string { |
| + if !strings.HasPrefix(target, "/") || |
| + strings.HasPrefix(target, "//") || |
| + strings.ContainsAny(target, "\\\r\n\t") { |
| + return "/" |
| + } |
| + return target |
| +} |
| + |
| +// sideLists are Pinned and Recently edited. Filled in by recent.go. |
| +func (app *app) sideLists(request *http.Request, |
| + page *view) ([]sideLink, []sideLink) { |
| + return nil, nil |
| +} |
diff --git a/internal/mapa/static/frame.css b/internal/mapa/static/frame.css| new file mode 100644 |
| index 0000000..b9d29a7 |
| --- /dev/null |
| +++ b/internal/mapa/static/frame.css |
| @@ -0,0 +1,266 @@ |
| +/* frame.css: the shell around every signed-in page (level-up spec §3). |
| + * |
| + * estilo draws the stacked bar; this is everything under it: the |
| + * sidebar and its rail, the page column, the lead slot's pieces and the |
| + * shortcuts dialog. Mapa's own attributes only (mapa-), tokens only, so |
| + * Calma and light/dark apply. Calma: only icons carry colour. |
| + * |
| + * Breakpoints are estilo's (I2 revision 2, P1.3): 800px, where the bar |
| + * stacks and the sidebar appears, and 64rem, where floating panels do. |
| + */ |
| + |
| +html { scrollbar-gutter: stable; } |
| +body { |
| + --mapa-side-w: 224px; |
| + --mapa-rail-w: 56px; |
| + --mapa-measure: 42rem; |
| + --mapa-bar-h: var(--estilo-bar-block-size, 56px); |
| + margin: 0; |
| + background: var(--rst-surface); |
| +} |
| + |
| +/* Pieces of the bar that mean nothing here. The places are the |
| + sidebar's from 800px; estilo's Menu sheet carries them below it. */ |
| +@media (min-width: 800px) { |
| + [estilo-bar-nav] { display: none; } |
| +} |
| + |
| +[mapa-app] { |
| + display: grid; |
| + grid-template-columns: var(--mapa-side-w) minmax(0, 1fr); |
| + min-block-size: calc(100dvh - var(--mapa-bar-h)); |
| +} |
| +/* The rail: by cookie, or by width when there is none (§11 Q4, |
| + proposed: open from 80rem, the rail below). */ |
| +[mapa-app][data-side="rail"] { --mapa-side-w: var(--mapa-rail-w); } |
| +@media (max-width: 79.99rem) { |
| + [mapa-app]:not([data-side]) { --mapa-side-w: var(--mapa-rail-w); } |
| +} |
| +@media (max-width: 799.98px) { |
| + [mapa-app] { grid-template-columns: minmax(0, 1fr); } |
| + [mapa-side] { display: none; } |
| +} |
| + |
| +[mapa-main] { min-inline-size: 0; } |
| +[mapa-doc] { |
| + box-sizing: border-box; |
| + max-inline-size: calc(var(--mapa-measure) + 96px); |
| + margin-inline: auto; |
| + padding: 56px 48px 120px; |
| +} |
| +@media (max-width: 799.98px) { |
| + [mapa-doc] { padding: 28px 20px 120px; } |
| +} |
| + |
| +/* ── The sidebar: one grid per row, a 16px icon column and the label, |
| + centred on one axis (rastrillo's nav row rode its icon 3px high). ── */ |
| +[mapa-side] { |
| + box-sizing: border-box; |
| + position: sticky; |
| + inset-block-start: var(--mapa-bar-h); |
| + block-size: calc(100dvh - var(--mapa-bar-h)); |
| + display: flex; |
| + flex-direction: column; |
| + gap: 1px; |
| + overflow: auto; |
| + padding: 10px 8px 12px; |
| + background: light-dark(#f8f9fb, #191b21); |
| + border-inline-end: 1px solid var(--rst-line); |
| + font-size: 13px; |
| +} |
| +[mapa-side-item] { |
| + box-sizing: border-box; |
| + position: relative; |
| + display: grid; |
| + grid-template-columns: 16px minmax(0, 1fr) auto; |
| + align-items: center; |
| + column-gap: 10px; |
| + inline-size: 100%; |
| + min-block-size: 30px; |
| + padding: 0 8px 0 10px; |
| + border: 0; |
| + border-radius: 8px; |
| + background: none; |
| + color: var(--rst-text-muted); |
| + font: inherit; |
| + line-height: 18px; |
| + text-align: start; |
| + text-decoration: none; |
| + cursor: pointer; |
| +} |
| +[mapa-side-item] > svg { inline-size: 16px; block-size: 16px; } |
| +[mapa-side-label] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
| +[mapa-side-item]:hover { background: var(--rst-surface-2); color: var(--rst-text); } |
| +[mapa-side-item]:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: -2px; } |
| +[mapa-side-item][aria-current] { background: var(--rst-accent-soft); color: var(--rst-text); font-weight: 600; } |
| +[mapa-side-item][aria-current] > svg { color: var(--rst-accent); } |
| +[mapa-side-head] { |
| + margin: 14px 0 2px; |
| + padding: 0 8px 0 10px; |
| + color: var(--rst-text-faint, var(--rst-text-muted)); |
| + font-size: 11.5px; |
| + font-weight: 600; |
| + line-height: 22px; |
| +} |
| +[mapa-side-foot] { margin-block-start: auto; padding-block-start: 10px; display: grid; gap: 1px; } |
| +[mapa-side-foot] form { display: contents; } |
| +kbd[mapa-kbd] { |
| + display: inline-flex; |
| + align-items: center; |
| + justify-content: center; |
| + min-inline-size: 1.4em; |
| + padding: 0 5px; |
| + border: 1px solid var(--rst-line); |
| + border-block-end-width: 2px; |
| + border-radius: 5px; |
| + background: var(--rst-surface); |
| + color: var(--rst-text-muted); |
| + font: 500 10.5px/14px var(--rst-font); |
| +} |
| + |
| +/* The fold: one button per state, shown by what is on screen. */ |
| +[mapa-fold-to="open"] { display: none; } |
| +[mapa-app][data-side="rail"] [mapa-fold-to="rail"] { display: none; } |
| +[mapa-app][data-side="rail"] [mapa-fold-to="open"] { display: grid; } |
| +@media (max-width: 79.99rem) { |
| + [mapa-app]:not([data-side]) [mapa-fold-to="rail"] { display: none; } |
| + [mapa-app]:not([data-side]) [mapa-fold-to="open"] { display: grid; } |
| +} |
| + |
| +/* ── The rail (Página's): the same rows, icons only, on one axis. The |
| + label stays in the accessibility tree and is the tooltip. ── */ |
| +@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] { |
| + grid-template-columns: 18px; |
| + justify-content: center; |
| + inline-size: 40px; |
| + min-block-size: 38px; |
| + padding: 0; |
| + border-radius: 10px; |
| + } |
| + [mapa-app][data-side="rail"] [mapa-side-item] > svg { inline-size: 18px; block-size: 18px; } |
| + [mapa-app][data-side="rail"] [mapa-side-item] > kbd, |
| + [mapa-app][data-side="rail"] [mapa-side-head], |
| + [mapa-app][data-side="rail"] [mapa-side-page] { display: none; } |
| + [mapa-app][data-side="rail"] [mapa-side-item][aria-current] { background: none; } |
| + [mapa-app][data-side="rail"] [mapa-side-item][aria-current]::before { |
| + content: ""; |
| + position: absolute; |
| + inset-inline-start: -8px; |
| + inset-block-start: 10px; |
| + inline-size: 3px; |
| + block-size: 18px; |
| + border-radius: 0 3px 3px 0; |
| + background: var(--rst-accent); |
| + } |
| + [mapa-app][data-side="rail"] [mapa-side-label] { |
| + position: absolute; |
| + inset-inline-start: calc(100% + 10px); |
| + z-index: 30; |
| + padding: 4px 8px; |
| + border-radius: 6px; |
| + background: var(--rst-text); |
| + color: var(--rst-surface); |
| + font-size: 12px; |
| + font-weight: 500; |
| + pointer-events: none; |
| + opacity: 0; |
| + clip-path: inset(50%); |
| + } |
| + [mapa-app][data-side="rail"] [mapa-side-item]:hover [mapa-side-label], |
| + [mapa-app][data-side="rail"] [mapa-side-item]:focus-visible [mapa-side-label] { |
| + opacity: 1; |
| + clip-path: none; |
| + } |
| +} |
| +@media (min-width: 800px) and (max-width: 79.99rem) { |
| + [mapa-app]:not([data-side]) [mapa-side] { padding-inline: 8px; align-items: center; } |
| + [mapa-app]:not([data-side]) [mapa-side-item] { |
| + grid-template-columns: 18px; |
| + justify-content: center; |
| + inline-size: 40px; |
| + min-block-size: 38px; |
| + padding: 0; |
| + border-radius: 10px; |
| + } |
| + [mapa-app]:not([data-side]) [mapa-side-item] > svg { inline-size: 18px; block-size: 18px; } |
| + [mapa-app]:not([data-side]) [mapa-side-item] > kbd, |
| + [mapa-app]:not([data-side]) [mapa-side-head], |
| + [mapa-app]:not([data-side]) [mapa-side-page] { display: none; } |
| + [mapa-app]:not([data-side]) [mapa-side-item][aria-current] { background: none; } |
| + [mapa-app]:not([data-side]) [mapa-side-item][aria-current]::before { |
| + content: ""; |
| + position: absolute; |
| + inset-inline-start: -8px; |
| + inset-block-start: 10px; |
| + inline-size: 3px; |
| + block-size: 18px; |
| + border-radius: 0 3px 3px 0; |
| + background: var(--rst-accent); |
| + } |
| + [mapa-app]:not([data-side]) [mapa-side-label] { |
| + position: absolute; |
| + inset-inline-start: calc(100% + 10px); |
| + z-index: 30; |
| + padding: 4px 8px; |
| + border-radius: 6px; |
| + background: var(--rst-text); |
| + color: var(--rst-surface); |
| + font-size: 12px; |
| + font-weight: 500; |
| + pointer-events: none; |
| + opacity: 0; |
| + clip-path: inset(50%); |
| + } |
| + [mapa-app]:not([data-side]) [mapa-side-item]:hover [mapa-side-label], |
| + [mapa-app]:not([data-side]) [mapa-side-item]:focus-visible [mapa-side-label] { |
| + opacity: 1; |
| + clip-path: none; |
| + } |
| +} |
| + |
| +/* ── The lead slot: presence, save status, the day pill. ── */ |
| +[mapa-presence] { color: var(--rst-text-muted); font-size: 13px; font-weight: 600; white-space: nowrap; } |
| +[mapa-day] { |
| + display: inline-flex; |
| + align-items: center; |
| + block-size: 28px; |
| + border: 1px solid var(--rst-line); |
| + border-radius: 999px; |
| + background: var(--rst-surface); |
| +} |
| +[mapa-day] a { |
| + display: inline-flex; |
| + align-items: center; |
| + gap: 6px; |
| + block-size: 100%; |
| + padding-inline: 8px; |
| + border-radius: 999px; |
| + color: var(--rst-text); |
| + font-size: 13px; |
| + font-weight: 600; |
| + text-decoration: none; |
| +} |
| +[mapa-day] a:hover { background: var(--rst-surface-2); } |
| +[mapa-day] svg { inline-size: 15px; block-size: 15px; } |
| +[mapa-day-step] { color: var(--rst-text-muted); } |
| +@media (max-width: 799.98px) { |
| + [estilo-bar-lead] [mapa-day], [estilo-bar-lead] [mapa-presence] { display: none; } |
| +} |
| + |
| +/* ── The shortcuts dialog. ── */ |
| +dialog[mapa-dialog] { |
| + inline-size: min(28rem, calc(100vw - 32px)); |
| + padding: 16px 20px 20px; |
| + border: 1px solid var(--rst-line); |
| + border-radius: 14px; |
| + background: var(--rst-surface); |
| + color: var(--rst-text); |
| + box-shadow: 0 28px 56px -20px rgb(23 32 60 / 0.35); |
| +} |
| +dialog[mapa-dialog]::backdrop { background: rgb(15 18 25 / 0.35); } |
| +[mapa-dialog-head] { display: flex; align-items: center; justify-content: space-between; margin-block-end: 8px; } |
| +[mapa-dialog-head] h2 { margin: 0; font-size: 1rem; } |
| +dl[mapa-keys] { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 0; } |
| +dl[mapa-keys] dd { margin: 0; color: var(--rst-text-muted); } |
diff --git a/internal/mapa/static/mapa.js b/internal/mapa/static/mapa.js| index fa05b80..36790a0 100644 |
| --- a/internal/mapa/static/mapa.js |
| +++ b/internal/mapa/static/mapa.js |
| @@ -70,6 +70,16 @@ |
| Editor.prototype.say = function (text) { this.status.textContent = text; }; |
| + // lead is estilo's save status in the bar's lead slot (level-up §3.1): |
| + // saved, saving, retrying, failed, or idle. Its texts are on the |
| + // element, so the words are the server's. |
| + Editor.prototype.lead = function (state) { |
| + var element = document.querySelector("[estilo-save-status]"); |
| + if (!element) return; |
| + element.setAttribute("data-state", state); |
| + element.textContent = element.getAttribute("data-text-" + state) || ""; |
| + }; |
| + |
| // setVersion keeps the form's version in step with the draft, so a Save |
| // says which draft it saw (a stale tab's Save must not drop a newer one). |
| Editor.prototype.setVersion = function () { |
| @@ -139,6 +149,7 @@ |
| var editor = this; |
| if (!this.dirty || this.stopped) return; |
| this.dirty = false; |
| + this.lead("saving"); |
| post(this.drafts, { |
| body: this.area.value, |
| base: this.revision ? this.revision.value : "0", |
| @@ -152,15 +163,18 @@ |
| editor.version = answer.reply.version; |
| editor.setVersion(); |
| editor.say("Draft saved. It is committed when you press Save, or after two minutes."); |
| + editor.lead("saved"); |
| editor.idle(); |
| } else if (answer.status === 409) { |
| editor.stale(answer.reply); |
| } else { |
| editor.say("Couldn't save a draft just now. Your text is still here."); |
| + editor.lead("retrying"); |
| } |
| }).catch(function () { |
| editor.dirty = true; |
| editor.say("Offline? Your text is still here; Save when you are back."); |
| + editor.lead("failed"); |
| }); |
| }; |
| @@ -439,7 +453,7 @@ |
| var browser = ""; |
| try { browser = Intl.DateTimeFormat().resolvedOptions().timeZone || ""; } catch (error) {} |
| var key = "mapa-zone-declined:" + browser; |
| - var main = document.querySelector("[rst-page]"); |
| + var main = document.querySelector("[mapa-doc]"); |
| if (!zone || !browser || browser === zone || !main) return; |
| try { if (localStorage.getItem(key)) return; } catch (error) {} |
| var offer = document.createElement("form"); |
| @@ -468,6 +482,88 @@ |
| main.insertBefore(offer, main.firstChild); |
| } |
| + // ---- The frame: the sidebar's fold, the menus' commands ------------------ |
| + |
| + // sidebarShown is what the sidebar shows now: the cookie's state, or |
| + // what CSS chose by width when there is none (open from 80rem). |
| + function sidebarShown(app) { |
| + var state = app.getAttribute("data-side"); |
| + if (state) return state; |
| + return window.matchMedia("(min-width: 80rem)").matches ? "open" : "rail"; |
| + } |
| + |
| + function setCookie(name, value) { |
| + document.cookie = name + "=" + value + "; path=/; max-age=31536000; samesite=lax" + |
| + (location.protocol === "https:" ? "; secure" : ""); |
| + } |
| + |
| + // fold folds the sidebar to its rail, or opens it, in place: the same |
| + // cookie the scriptless form sets, so the next page is drawn the same. |
| + function fold() { |
| + var app = document.querySelector("[mapa-app]"); |
| + if (!app) return; |
| + var next = sidebarShown(app) === "open" ? "rail" : "open"; |
| + app.setAttribute("data-side", next); |
| + setCookie("mapa-sidebar", next); |
| + } |
| + |
| + // Markdown the Insert menu puts in at the caret, and whether it starts |
| + // a line of its own. |
| + var INSERTS = { |
| + "insert-h1": ["# ", true], "insert-h2": ["## ", true], |
| + "insert-h3": ["### ", true], "insert-list": ["- ", true], |
| + "insert-numbered": ["1. ", true], "insert-check": ["- [ ] ", true], |
| + "insert-quote": ["> ", true], "insert-code": ["```\n\n```", true], |
| + "insert-rule": ["---", true], "insert-link": ["[[", false] |
| + }; |
| + |
| + function today() { |
| + var now = new Date(); |
| + var pad = function (value) { return (value < 10 ? "0" : "") + value; }; |
| + return now.getFullYear() + "-" + pad(now.getMonth() + 1) + "-" + pad(now.getDate()); |
| + } |
| + |
| + function insert(area, name) { |
| + var spec = name === "insert-date" ? ["[[" + today() + "]]", false] : INSERTS[name]; |
| + if (!spec) return; |
| + var at = area.selectionStart, text = spec[0]; |
| + if (spec[1] && at > 0 && area.value.charAt(at - 1) !== "\n") text = "\n\n" + text; |
| + area.focus(); |
| + area.setRangeText(text, at, area.selectionEnd, "end"); |
| + area.dispatchEvent(new Event("input")); |
| + } |
| + |
| + function runCommand(name) { |
| + if (name === "toggle-sidebar") { fold(); return; } |
| + var area = document.querySelector("textarea[mapa-editor]"); |
| + if (!area) return; |
| + if (name === "undo" || name === "redo") { |
| + area.focus(); |
| + document.execCommand(name); |
| + } else if (name === "select-all") { |
| + area.focus(); |
| + area.select(); |
| + } else { |
| + insert(area, name); |
| + } |
| + } |
| + |
| + function bindCommands() { |
| + var area = document.querySelector("textarea[mapa-editor]"); |
| + document.querySelectorAll("[data-mapa-command]").forEach(function (control) { |
| + var name = control.getAttribute("data-mapa-command"); |
| + if (name === "toggle-links") return; // the panel's own (links.js) |
| + if (name !== "toggle-sidebar" && !area) return; |
| + control.disabled = false; |
| + control.addEventListener("click", function (event) { |
| + event.preventDefault(); |
| + var menu = control.closest("details"); |
| + if (menu) menu.open = false; |
| + runCommand(name); |
| + }); |
| + }); |
| + } |
| + |
| // ---- Start ---------------------------------------------------------------- |
| function start() { |
| @@ -475,11 +571,25 @@ |
| if (form.querySelector("textarea[mapa-editor]")) new Editor(form); |
| }); |
| var palette = null; |
| + bindCommands(); |
| + // Search in the bar and the sidebar opens ⌘K; without script they |
| + // are links to the search page. |
| + document.querySelectorAll('[estilo-bar] a[href="/search"], [mapa-side] a[href="/search"]').forEach(function (link) { |
| + link.addEventListener("click", function (event) { |
| + if (event.metaKey || event.ctrlKey || event.shiftKey) return; |
| + event.preventDefault(); |
| + palette = palette || new Palette(); |
| + palette.open(); |
| + }); |
| + }); |
| document.addEventListener("keydown", function (event) { |
| if ((event.metaKey || event.ctrlKey) && event.key === "k") { |
| event.preventDefault(); |
| palette = palette || new Palette(); |
| palette.open(); |
| + } else if ((event.metaKey || event.ctrlKey) && event.key === "\\") { |
| + event.preventDefault(); |
| + fold(); |
| } |
| }); |
| offerZone(); |
diff --git a/internal/mapa/templates/frame.html b/internal/mapa/templates/frame.html| new file mode 100644 |
| index 0000000..abfb56b |
| --- /dev/null |
| +++ b/internal/mapa/templates/frame.html |
| @@ -0,0 +1,83 @@ |
| +{{/* The frame's pieces (level-up spec §3), rendered by frame.go: the |
| + menu bar and the lead go into estilo's bar slots; the sidebar and the |
| + shortcuts dialog are drawn by shell.html. */}} |
| + |
| +{{/* mapa-menubar: Page, Edit, Insert, View, Help. Each menu is a |
| + <details> in estilo's exclusive group, so it opens with no script |
| + (Docs' editor_bar.html gives the reasoning). A command row is |
| + disabled until mapa.js binds it; a form row is a real POST, so the |
| + View rows work with scripts off. Data: menuBar. */}} |
| +{{define "mapa-menubar"}}<nav estilo-menubar aria-label="{{.Label}}"> |
| + {{- range .Menus}}<details estilo-menubar-menu name="estilo-menus" id="mapa-menu-{{.ID}}"> |
| + <summary estilo-menubar-title>{{.Title}}</summary> |
| + <div estilo-menu> |
| + {{- range .Items}} |
| + {{- if eq .Kind "divider"}}<hr> |
| + {{- else if eq .Kind "link"}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "mapa-menu-body" .}}</a> |
| + {{- else if eq .Kind "form"}}<form method="post" action="{{.Action}}">{{range $name, $value := .Fields}}<input type="hidden" name="{{$name}}" value="{{$value}}">{{end}}<button estilo-menu-item type="submit"{{with .Command}} data-mapa-command="{{.}}"{{end}}>{{template "mapa-menu-body" .}}</button></form> |
| + {{- else if eq .Kind "dialog"}}<button estilo-menu-item type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "mapa-menu-body" .}}</button> |
| + {{- else}}<button estilo-menu-item type="button" data-mapa-command="{{.Command}}" disabled>{{template "mapa-menu-body" .}}</button> |
| + {{- end}} |
| + {{- end}} |
| + </div> |
| + </details>{{end}} |
| +</nav>{{end}} |
| +{{define "mapa-menu-body"}}<span estilo-menu-label>{{.Label}}</span>{{with .Key}}<kbd estilo-menu-key aria-hidden="true">{{.}}</kbd>{{end}}{{end}} |
| + |
| +{{/* mapa-lead: presence on a team page, the save status on the editor, |
| + and a daily note's ‹ Today › pill (§3.1, §4.4). Data: leadView. */}} |
| +{{define "mapa-lead"}} |
| + {{- with .Editing}}<span mapa-presence>{{range $i, $who := .}}{{if $i}}, {{end}}{{$who}}{{end}} {{if eq (len .) 1}}is{{else}}are{{end}} editing</span>{{end}} |
| + {{- if .Status}}{{template "estilo-save-status" saveStatus}}{{end}} |
| + {{- with .Day}}{{template "mapa-day-pill" .}}{{end}} |
| +{{- end}} |
| + |
| +{{/* mapa-day-pill: ‹ Today ›. The middle names the day on screen, and |
| + is Today's link when that is another day. Data: dayPill. */}} |
| +{{define "mapa-day-pill"}}<nav mapa-day aria-label="Days"> |
| + <a mapa-day-step href="/d/{{.Prev}}" aria-label="Previous day, {{longDate .Prev}}">{{icon "chevron-left"}}</a> |
| + {{- if eq .Date .Today}}<a mapa-day-now href="/" aria-current="page">{{icon "calendar"}}<span>Today</span></a> |
| + {{- else}}<a mapa-day-now href="/" title="Go to today">{{icon "calendar"}}<span>{{shortDate .Date}}</span></a>{{end}} |
| + <a mapa-day-step href="/d/{{.Next}}" aria-label="Next day, {{longDate .Next}}">{{icon "chevron-right"}}</a> |
| +</nav>{{end}} |
| + |
| +{{/* mapa-side: the sidebar, one grid per row (§3.2). In the rail the |
| + labels stay in the accessibility tree and show as tooltips. The fold |
| + is two submit buttons, one per state; CSS shows the one that fits |
| + what is on screen, so it works with scripts off and with no cookie. |
| + Data: sideView. */}} |
| +{{define "mapa-side"}}<nav mapa-side aria-label="Mapa"> |
| + {{- range .Places}} |
| + <a mapa-side-item href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{icon .Icon}}<span mapa-side-label>{{.Label}}</span>{{if eq .Href "/search"}}<kbd mapa-kbd aria-hidden="true">⌘K</kbd>{{end}}</a> |
| + {{- end}} |
| + {{- with .Pinned}} |
| + <h2 mapa-side-head>Pinned</h2> |
| + {{- range .}}{{template "mapa-side-link" .}}{{end}} |
| + {{- end}} |
| + {{- with .Recent}} |
| + <h2 mapa-side-head>Recently edited</h2> |
| + {{- range .}}{{template "mapa-side-link" .}}{{end}} |
| + {{- end}} |
| + <div mapa-side-foot> |
| + <a mapa-side-item href="/new" data-mapa-new-page>{{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> |
| + <button mapa-side-item type="submit" name="state" value="open" mapa-fold-to="open" data-mapa-command="toggle-sidebar">{{icon "panel-left"}}<span mapa-side-label>Open sidebar</span></button> |
| + </form> |
| + </div> |
| +</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-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"> |
| + <form method="dialog" mapa-dialog-head><h2 id="mapa-keys-title">Keyboard shortcuts</h2><button rst-btn="ghost" type="submit" aria-label="Close">{{icon "x"}}</button></form> |
| + <dl mapa-keys> |
| + <dt><kbd mapa-kbd>⌘K</kbd></dt><dd>Search, or create a page</dd> |
| + <dt><kbd mapa-kbd>⌘\</kbd></dt><dd>Fold the sidebar to icons, or open it</dd> |
| + <dt><kbd mapa-kbd>⌘S</kbd></dt><dd>Save now</dd> |
| + <dt><kbd mapa-kbd>[[</kbd></dt><dd>Link to a page while you write</dd> |
| + <dt><kbd mapa-kbd>Esc</kbd></dt><dd>Close a menu, a list or this dialog</dd> |
| + </dl> |
| +</dialog>{{end}} |
diff --git a/internal/mapa/templates/shell.html b/internal/mapa/templates/shell.html| index 22aec8e..d64ceac 100644 |
| --- a/internal/mapa/templates/shell.html |
| +++ b/internal/mapa/templates/shell.html |
| @@ -2,46 +2,41 @@ |
| <html lang="en" dir="ltr"{{with .Theme}} data-theme="{{.}}"{{end}}> |
| <head> |
| <meta charset="utf-8"> |
| -<meta name="viewport" content="width=device-width, initial-scale=1"> |
| +<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> |
| <title>{{.Title}} · Mapa</title> |
| <link rel="icon" type="image/svg+xml" href="{{asset "static/brand/icon.svg"}}"> |
| +{{/* No webfont: the system face only, so nothing ever flashes (never |
| + FOUT; estilo decision 9). */}} |
| <link rel="stylesheet" href="{{asset "static/tokens.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/busy.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/theme.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/base.css"}}"> |
| -<link rel="stylesheet" href="{{asset "static/shell.css"}}"> |
| -{{/* The account menu at the rail's foot is estilo's: its panel and rows |
| - (menu.css), the account itself (chrome.css), and the script that |
| - closes it on Escape or an outside click (chrome.js). */}} |
| <link rel="stylesheet" href="{{asset "static/menu.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/chrome.css"}}"> |
| +<link rel="stylesheet" href="{{asset "static/savestatus.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/mapa.css"}}"> |
| +<link rel="stylesheet" href="{{asset "static/frame.css"}}"> |
| <script defer src="{{asset "static/rastrillo.js"}}"></script> |
| <script defer src="{{asset "static/busy.js"}}"></script> |
| -<script defer src="{{asset "static/shell.js"}}"></script> |
| <script defer src="{{asset "static/chrome.js"}}"></script> |
| -{{/* The script layer (§6): preview, [[ autocomplete, autosave through |
| - drafts, ⌘K and the time zone offer. Every screen works without it. */}} |
| +{{/* The script layer: the editor's autosave and [[, ⌘K, the fold, the |
| + panel toggle and the time zone offer. Every screen works without |
| + it. */}} |
| <script defer src="{{asset "static/mapa.js"}}"></script> |
| {{block "head" .}}{{end}} |
| </head> |
| <body data-zone="{{with .Viewer.TimeZone}}{{.String}}{{end}}"> |
| -<div rst-shell-sidebar> |
| <a rst-skip href="#main">Skip to content</a> |
| -<details rst-shell-chrome><summary>{{icon "menu"}}Menu</summary></details> |
| -<aside rst-shell-rail> |
| -<a rst-shell-brand href="/"><span mapa-brand><img src="{{asset "static/brand/icon.svg"}}" alt="" width="24" height="24">Mapa</span></a> |
| -<nav rst-shell-nav aria-label="Mapa"> |
| -{{range .Nav}}<a href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{icon .Icon}} {{.Label}}</a> |
| -{{end}}</nav> |
| -<div rst-shell-rail-foot>{{template "estilo-account" .Account}}</div> |
| -</aside> |
| -<main rst-shell-main id="main"> |
| -<div rst-page> |
| +{{template "estilo-bar" .Frame.Bar}} |
| +<div mapa-app{{with .Frame.Side.State}} data-side="{{.}}"{{end}}{{with .Frame.Panel}} data-links="{{.}}"{{end}}> |
| +{{template "mapa-side" .Frame.Side}} |
| +<main mapa-main id="main"> |
| +<div mapa-doc rst-page> |
| {{template "content" .}} |
| </div> |
| </main> |
| </div> |
| +{{template "mapa-keys"}} |
| </body> |
| </html> |
| {{end}} |
diff --git a/internal/mapa/today.go b/internal/mapa/today.go| index 080e4b9..693c0ed 100644 |
| --- a/internal/mapa/today.go |
| +++ b/internal/mapa/today.go |
| @@ -22,6 +22,7 @@ func (app *app) pageRoutes(router chi.Router) { |
| app.namingRoutes(router) |
| app.privateRoutes(router) |
| app.searchRoutes(router) |
| + app.viewRoutes(router) |
| } |
| // viewer resolves the signed-in person without writing anything. |
| @@ -106,7 +107,10 @@ func (app *app) showDay(writer http.ResponseWriter, request *http.Request, |
| data.Body = request.PostFormValue("body") |
| } |
| app.show(writer, request, status, "day", view{Title: longDate(date), |
| - Nav: nav(dayNav(date, data.Today)), Viewer: viewer, Data: data}) |
| + Nav: nav(dayNav(date, data.Today)), Viewer: viewer, Data: data, |
| + Chrome: &pageChrome{Page: &data.Page, Editor: data.Editing, |
| + Day: &dayPill{Date: date, Today: data.Today, Prev: data.Prev, |
| + Next: data.Next}}}) |
| } |
| // dayDrafts fills in the day's own draft, which the editor holds, and on |
diff --git a/internal/mapatest/browser_test.go b/internal/mapatest/browser_test.go| index a4f4989..7d63eca 100644 |
| --- a/internal/mapatest/browser_test.go |
| +++ b/internal/mapatest/browser_test.go |
| @@ -185,7 +185,9 @@ func searchByPalette(t *testing.T, rig *harness.Rig) { |
| chromedp.ModifierCtrl)), |
| chromedp.WaitVisible("dialog[mapa-palette] input"), |
| chromedp.SendKeys("dialog[mapa-palette] input", "Acme"), |
| - chromedp.WaitVisible("[mapa-palette-results] li"), |
| + // The answer to the whole word, not to "Acm": each keystroke |
| + // asks, and an earlier answer can be on screen first. |
| + chromedp.WaitVisible(`[mapa-palette-results] a[href="/new?title=Acme"]`), |
| ) |
| if !strings.Contains(text(t, rig, "[mapa-palette-results]"), "Create") { |
| t.Fatal("⌘K does not offer to create Acme") |
diff --git a/internal/mapatest/gate8_test.go b/internal/mapatest/gate8_test.go| index a8b4512..7a36e1e 100644 |
| --- a/internal/mapatest/gate8_test.go |
| +++ b/internal/mapatest/gate8_test.go |
| @@ -125,6 +125,11 @@ func gate8Steps(t *testing.T, world *rig) []step { |
| url.Values{"zone": {"Europe/Madrid"}}), |
| posting("/appearance", Ana, "/appearance", |
| url.Values{"mode": {"dark"}, "return": {"/"}}), |
| + // View preferences: a cookie, no row (level-up §3.2). |
| + posting("/view/sidebar", Ana, "/view/sidebar", |
| + url.Values{"state": {"rail"}, "return": {"/"}}), |
| + posting("/view/links", Ana, "/view/links", |
| + url.Values{"state": {"closed"}, "return": {"/"}}), |
| } |
| return append(steps, gate8Later(t, acme, notes)...) |
| } |
diff --git a/scripts/preview/main.go b/scripts/preview/main.go| index 13c2a16..9dd5549 100644 |
| --- a/scripts/preview/main.go |
| +++ b/scripts/preview/main.go |
| @@ -27,10 +27,16 @@ import ( |
| "amadan.net/oficina/mapa/internal/mapa" |
| ) |
| -const ( |
| - address = "127.0.0.1:8747" |
| - owner = "paul@example.com" |
| -) |
| +const owner = "paul@example.com" |
| + |
| +// address is where the preview listens: PREVIEW_ADDR, else loopback |
| +// port 8747. It is always loopback; a tailnet proxy may front it. |
| +var address = func() string { |
| + if given := os.Getenv("PREVIEW_ADDR"); given != "" { |
| + return given |
| + } |
| + return "127.0.0.1:8747" |
| +}() |
| func main() { |
| if err := run(); err != nil { |
| @@ -80,6 +86,15 @@ func previewConfig() (mapa.Config, error) { |
| "MAPA_ALLOW_LOGGED_MAIL": "1", |
| "MAPA_TIME_ZONE": "Europe/Dublin", |
| } |
| + // Behind a tailnet proxy the origin is the proxy's. Logged mail is |
| + // refused off loopback, so the preview names an SMTP server that |
| + // is never reached: it signs no one in by mail anyway. |
| + if origin := os.Getenv("MAPA_ORIGIN"); origin != "" { |
| + env["MAPA_ORIGIN"] = origin |
| + delete(env, "MAPA_ALLOW_LOGGED_MAIL") |
| + env["CARLOS_SMTP_HOST"], env["CARLOS_SMTP_PORT"] = "127.0.0.1", "1" |
| + env["CARLOS_SMTP_FROM"] = "noreply@preview.invalid" |
| + } |
| return mapa.LoadConfig(func(key string) string { return env[key] }) |
| } |