gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitaafe330daafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmreaafe330d/components/main.hl

11.3 KB

  1. // components/main.hl — THE SHELL (gitoria#23): the WorldAPI theme's header and content-first shell (theme/shell/*, copied from
  2. // layouts.worldapi.org — never edited here, the way tracker.worldapi.org wears it) around the slot every page renders into, plus
  3. // the display-name prompt of a first login. The shell owns its Style block (the theme shells carry their own Style).
  4. // THE HEADER: phone — ☰ (the sidebar overlay with the main menu) · brand · ident's selector · the user icon far right (its dropdown:
  5. // your name, Access tokens, SSH keys, Log out); signed out the selector stands alone (no second "Log in" button — creator 2026-10-24).
  6. // From 60rem: brand · main menu · selector · user icon. IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in and signed out, on the
  7. // phone and on the desktop (creator 2026-10-24: the theme move hid it behind an icon — never again; the gate checks it at 390 and 1280).
  8. // The main menu is the app's top level, on the main address: Repositories. The repo's own tabs stay in the repo head of the repo layout level (repo.hl).
  9. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  10. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  11. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  12. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. THE SAME SELECTOR STANDS ON EVERY ADDRESS: the main one and
  13. // every repo address (<repo>.<host>) — ident answers a repo address because the app's registered origins hold the wildcard origin
  14. // `https://*.<host>` (ident accepts `*.` as the first label of a registered origin). The login is the one session of the main
  15. // address and all repo addresses (the cookie's Domain, project.hl sessionDomain).
  16. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  17. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  18. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  19. import { siteName } from '../project.hl'
  20. import { publicUrl } from '../lib/util.hl'
  21. import { identKey, callbackUrl, selectorScript, infoOfSession, login, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  22. import AppHeader from '../theme/shell/app-header.hl'
  23. import MainMenu from '../theme/shell/main-menu.hl'
  24. import Sidebar from '../theme/shell/app-sidebar.hl'
  25. import ContentFirst from '../theme/shell/content-first.hl'
  26. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  27. // an INSTANCE property, not `static` (gitoria#23 reopened): a static is evaluated again in the browser after an in-page navigation, where `publicUrl` (hl:proc env) has no value — the link became a 404. The instance property is filled by the server.
  28. // `current = true` STAYS (hybriel#197 checked, mission 010): the route marker needs the item href to be the page path, but this item links to the MAIN address (absolute) and every page of the app (/code, /pulls …) lies under it, so the route cannot tell; it is marked on all
  29. menu = [
  30. { label = 'Repositories' href = publicUrl + '/' current = true }
  31. ]
  32. slot = null
  33. session = null
  34. me = infoOfSession(session)
  35. loggedIn = me != null
  36. loggedOut = me == null
  37. needsName = me != null && !me.named
  38. myName = me != null && me.named ? me.name : 'you'
  39. selectorClass = me != null ? 'in' : 'out'
  40. tokensHref = publicUrl + '/#tokens'
  41. keysHref = publicUrl + '/#sshkeys'
  42. selectorKey = identKey
  43. // where the selector's sign-in panel (ident#31) sends the browser: the login button's callback, with the page the user is on as `next`
  44. // (the callback takes it back there). No route known (first paint) = no `next` = the start page.
  45. route = null
  46. path = route == null ? '' : route.path
  47. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encodeURIComponent(path))
  48. identScript = selectorScript
  49. identCode = ''
  50. loginError = ''
  51. hasLoginError = false
  52. nameDraft = ''
  53. nameError = ''
  54. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  55. // shell then says so. The vendored __hlOnline updates only the routed page, not this shell (W60 repro), so a tick asks the browser:
  56. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  57. // write only when it changed.
  58. offline = false
  59. View {
  60. body {
  61. AppHeader { brand = siteName
  62. MainMenu { items = menu }
  63. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (signed in it shows the
  64. // chosen identity). /login.js mirrors its state from the class (`in` / `out`). Nothing else stands beside it: no second "Log in" button (creator 2026-10-24).
  65. // Runtime login-state classes are consumed by the ident bridge, not a Style rule.
  66. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  67. // signed in, like before the theme missions: your name and Log out stand beside the selector (Access tokens and SSH keys are on the account pages)
  68. if (loggedIn) {
  69. span { id = "whoami" myName }
  70. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  71. }
  72. }
  73. input { id = "identcode" type = "hidden" value = identCode on change(e) { identCode = e.target.value emit gotCode(e) } }
  74. if (hasLoginError) { p { id = "loginerror" class = "banner" loginError } }
  75. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  76. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  77. if (needsName) {
  78. namePrompt {
  79. form { id = "nameform"
  80. on submit(e) {
  81. e.preventDefault()
  82. emit saveName(e)
  83. }
  84. label { "Welcome! Choose the display name others see as the owner of your repositories"
  85. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  86. }
  87. button { id = "namesave" type = "submit" "Save" }
  88. p { id = "nameerror" nameError }
  89. }
  90. }
  91. }
  92. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  93. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  94. Sidebar { desktop = "false" MainMenu { items = menu } }
  95. main {
  96. ContentFirst { slot }
  97. }
  98. script { src = identScript }
  99. script { src = "/login.js" }
  100. }
  101. }
  102. showMe = (info) => {
  103. loggedIn = true
  104. loggedOut = false
  105. needsName = !info.named
  106. myName = info.named ? info.name : 'you'
  107. selectorClass = 'in'
  108. loginError = ''
  109. hasLoginError = false
  110. }
  111. showOut = () => {
  112. loggedIn = false
  113. loggedOut = true
  114. needsName = false
  115. myName = 'you'
  116. selectorClass = 'out'
  117. }
  118. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  119. on gotCode(e) {
  120. code = identCode
  121. identCode = ''
  122. if (code == null || code == '') { return null }
  123. r = emit server gitoriaLogin(code)
  124. if (r == null || r.error != null) {
  125. loginError = r != null ? r.error : 'the login failed'
  126. hasLoginError = true
  127. return null
  128. }
  129. showMe(r)
  130. }
  131. on client gitoriaSignedIn(tag, info) { showMe(info) }
  132. on client gitoriaSignedOut(tag) { showOut() }
  133. on setNameDraft(v) { nameDraft = v }
  134. on netTick(e) {
  135. down = window.navigator.onLine == false
  136. if (down != offline) { offline = down }
  137. }
  138. on saveName(e) {
  139. r = emit server gitoriaSaveName(nameDraft)
  140. if (r == null || r.error != null) {
  141. nameError = r != null ? r.error : 'could not save the name'
  142. return null
  143. }
  144. nameError = ''
  145. showMe(r)
  146. }
  147. on doLogout(e) {
  148. emit server gitoriaLogOut()
  149. showOut()
  150. }
  151. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  152. on server gitoriaLogin(code, session) {
  153. if (session == null) { return { error = 'no session — reload the page' } }
  154. x = login(code, session, null)
  155. if (x.error != null) { return { error = x.error } }
  156. emit client gitoriaSignedIn(x.tag, x.info)
  157. return x.info
  158. }
  159. on server gitoriaSaveName(name, session) {
  160. u = userOfSession(session)
  161. if (u == null) { return { error = 'log in with ident first' } }
  162. r = setUserName(u.id, name)
  163. if (r.error != null) { return { error = r.error } }
  164. info = userInfo(r.user)
  165. emit client gitoriaSignedIn(session.data.tag, info)
  166. return info
  167. }
  168. on server gitoriaLogOut(session) {
  169. if (session == null) { return { error = 'no session' } }
  170. emit client gitoriaSignedOut(session.data.tag)
  171. session.user = null
  172. return { ok = true }
  173. }
  174. Style {
  175. #whoami {
  176. marginRight = '.5rem'
  177. fontWeight = '600'
  178. color = 'var(--color-text-strong)'
  179. fontSize = '.875rem'
  180. maxWidth = '6rem'
  181. overflow = 'hidden'
  182. textOverflow = 'ellipsis'
  183. whiteSpace = 'nowrap'
  184. flex = '0 1 auto'
  185. minWidth = '0'
  186. display = 'inline-flex'
  187. alignItems = 'center'
  188. minHeight = '2.75rem'
  189. }
  190. #logout {
  191. flex = 'none'
  192. whiteSpace = 'nowrap'
  193. padding = '.25rem .5rem'
  194. }
  195. identSelector {
  196. '--ident-accent' = 'var(--color-accent)'
  197. '--ident-accent-text' = 'var(--color-accent-text)'
  198. '--ident-background' = 'var(--color-surface)'
  199. '--ident-border' = 'var(--color-surface)'
  200. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  201. position = 'relative'
  202. flex = '0 1 auto'
  203. minWidth = '0'
  204. }
  205. // Pseudo-elements and parts have no bare language form.
  206. 'ident-selector::part(button)' {
  207. minHeight = '2.75rem'
  208. padding = '.25rem .6rem'
  209. border = 'none'
  210. whiteSpace = 'nowrap'
  211. }
  212. // Pseudo-elements and parts have no bare language form.
  213. 'ident-selector::part(status)' {
  214. minHeight = '2.75rem'
  215. padding = '.25rem .6rem'
  216. border = 'none'
  217. whiteSpace = 'nowrap'
  218. overflow = 'hidden'
  219. textOverflow = 'ellipsis'
  220. }
  221. // Pseudo-elements and parts have no bare language form.
  222. 'ident-selector::part(identity)' {
  223. minHeight = '2.75rem'
  224. border = 'none'
  225. }
  226. // Pseudo-elements and parts have no bare language form.
  227. 'ident-selector::part(panel)' {
  228. position = 'absolute'
  229. top = '100%'
  230. right = '0'
  231. zIndex = '30'
  232. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  233. maxWidth = 'none'
  234. border = 'none'
  235. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  236. }
  237. #loginerror {
  238. color = 'var(--color-danger)'
  239. empty { display = 'none' }
  240. margin = '0'
  241. padding = '.5rem var(--layout-gutter)'
  242. background = 'var(--color-background-sunken)'
  243. }
  244. namePrompt {
  245. display = 'block'
  246. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  247. paddingTop = '1rem'
  248. }
  249. offlineNote {
  250. display = 'block'
  251. padding = '.5rem var(--layout-gutter)'
  252. color = 'var(--color-text-strong)'
  253. background = 'var(--color-surface)'
  254. }
  255. netProbe {
  256. position = 'fixed'
  257. left = '0'
  258. top = '0'
  259. width = '1px'
  260. height = '1px'
  261. opacity = '0'
  262. pointerEvents = 'none'
  263. animation = 'gitoria-net-tick 1s linear infinite'
  264. }
  265. // Keyframe names use the language's quoted prelude form.
  266. '@keyframes gitoria-net-tick' {
  267. // The keyframe stop from is a language keyword.
  268. 'from' {
  269. opacity = '0'
  270. }
  271. to {
  272. opacity = '0'
  273. }
  274. }
  275. #nameerror {
  276. margin = '0'
  277. color = 'var(--color-danger)'
  278. empty { display = 'none' }
  279. }
  280. #nameform {
  281. display = 'grid'
  282. gap = '.6rem'
  283. padding = '1rem'
  284. background = 'var(--color-surface)'
  285. borderRadius = 'var(--radius-large)'
  286. // Direct-child and sibling combinators have no bare language form.
  287. '> *' {
  288. margin = '0'
  289. }
  290. }
  291. }

Branches

Latest commits

  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
  • 153c344bRestore organization metadata exposed by the whole-image comparisonmre
  • 917a1465Update status gate assertions for the referenced state rulemre
  • 3cdb02c6Own settings feedback styles and explain connection-state classesmre
  • 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
  • 3c425eddReference PR content styles and explain dynamic state classesmre
  • e46fa222Own shell feedback styles and retain documented selector formsmre
  • c26084c4Reference repository list styles and nest its breakpointmre
  • f3e196b5Document Markdown direct-child selector remaindersmre
  • 70597528Reference pull list rules and explain runtime class predicatesmre
  • 1ce7ac24Reference ticket row and feedback styles from its Viewmre
  • 10cdf54bGive organization repository rows their own Style referencesmre
  • 0d019521Document shared class selectors in the styles-only filemre
  • c67404a7Scope token labels and feedback through the token Viewmre
  • 944e3dabScope key names, fingerprints and errors to the keys Viewmre
  • 7bcf7bc2Nest repo navigation media rules and document selector gapsmre
  • 46a76272Reference release row styles from the Viewmre