gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcb38de2bcb38de2blog: swap 503 causemrecb38de2b/components/pagination.hl

4.6 KB

  1. // pagination.hl — THE PAGINATION: "Previous 1 .. 44 45 46 .. 89 Next". Buttons for the first and last page, the current page
  2. // and its neighbours, "…" for the pages left out. Previous is missing on the first page, Next on the last. Plain Hybriel, no
  3. // script. The page reads `page` (1-based) and `pages` (how many there are) as its own members — set `pages` on the tag:
  4. // `Pagination { pages = 89 }`. USE ONE PER PAGE: a composed component's members are the page's state (COMPONENTS.md §12).
  5. // Every entry is a button (an `if` or a conditional attribute would re-create the DOM, hybriel#41); the "…" ones
  6. // only differ by class, and a click on them does nothing. Each button carries its target page in `data-page` (0 for "…"): a bound
  7. // attribute on a row follows the reassigned list (hybriel#100).
  8. // DATA OUT (ticket #16): the host hands a function, `Pagination { pages = 89 page = page onPage = goPage }`; a click (pointer or
  9. // keyboard) calls `onPage(target)` with the page it goes to — Previous / Next / a number resolved against the page shown BEFORE the
  10. // buttons change (hybriel#87: a child talks upward through a function its host gives it; the function writes the host's members).
  11. Number page = 1
  12. Number pages = 10
  13. String previousLabel = 'Previous'
  14. String nextLabel = 'Next'
  15. onPage = null
  16. Hybrid items = build(page, pages)
  17. entry(label, target, cls) {
  18. return { label = label target = target cls = cls }
  19. }
  20. // the page numbers to show: first, last, current ± 1; at either end four in a row; 0 = a gap
  21. numbers(p, n) {
  22. want = []
  23. let i = 1
  24. while (i <= n) {
  25. let near = i == 1 || i == n || (i >= p - 1 && i <= p + 1)
  26. if (p <= 3 && i <= 4) { near = true }
  27. if (p >= n - 2 && i >= n - 3) { near = true }
  28. if (near) { want.push(i) }
  29. i = i + 1
  30. }
  31. out = []
  32. let last = 0
  33. let k = 0
  34. while (k < want.length) {
  35. let v = want[k]
  36. if (v == last + 2) { out.push(v - 1) }
  37. else if (v > last + 2) { out.push(0) }
  38. out.push(v)
  39. last = v
  40. k = k + 1
  41. }
  42. return out
  43. }
  44. build(p, n) {
  45. out = []
  46. if (p > 1) { out.push(entry(previousLabel, p - 1, 'step')) }
  47. nums = numbers(p, n)
  48. let k = 0
  49. while (k < nums.length) {
  50. let v = nums[k]
  51. if (v == 0) { out.push(entry('…', 0, 'gap')) }
  52. else { out.push(entry('' + v, v, v == p ? 'page current' : 'page')) }
  53. k = k + 1
  54. }
  55. if (p < n) { out.push(entry(nextLabel, p + 1, 'step')) }
  56. return out
  57. }
  58. show(p) {
  59. if (p < 1 || p > pages) { return }
  60. page = p
  61. items = build(p, pages)
  62. }
  63. // Look: black, white and the greys #555 #999 #ddd #f2f2f2 (the library's base, named in shared/base.hl; README "Look"). Every colour is a semantic token
  64. // with its base value as fallback, `var(--color-…, #000)`, so a bare copy looks right and an app that declares the tokens (layouts.worldapi.org's
  65. // theme) restyles it. No frames: a border or ring only where it means something. A component's browser module
  66. // cannot import tokens itself.
  67. Style {
  68. pagination { display = 'block' }
  69. 'pagination ol' { display = 'flex' flexWrap = 'wrap' gap = '.3rem' margin = '0' padding = '0' listStyle = 'none' }
  70. 'pagination button' { font = 'inherit' fontWeight = '600' minWidth = '2.75rem' minHeight = '2.75rem' padding = '.35rem .6rem' color = 'var(--color-text, #000)' background = 'transparent' border = '0' borderRadius = '.4rem' cursor = 'pointer' }
  71. 'pagination button:hover' { background = 'var(--color-surface, #f2f2f2)' }
  72. // a keyboard focus ring in the base grey (else Chrome draws its own coloured one — seen at 390 px in mission 005)
  73. 'pagination button:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '1px' }
  74. 'pagination li.current button' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' border = '0' }
  75. 'pagination li.gap button' { color = 'var(--color-text-muted, #555)' background = 'transparent' border = '0' minWidth = '0' minHeight = '0' padding = '.35rem .2rem' cursor = 'default' pointerEvents = 'none' }
  76. }
  77. View {
  78. pagination {
  79. nav { title = "Pagination"
  80. ol { id = "pagination-items" for (it of items) { li { class = it.cls button { type = "button" class = "quiet" 'data-page' = it.target it.label on click(e) { emit paginationGo(e) } } } } }
  81. }
  82. }
  83. }
  84. // the target is read from the clicked button FIRST (its `data-page`, written for the page shown now), then the list is rebuilt and
  85. // the host told — so neither a real click (the rebuild can run before a host's own listener) nor a script's `click()` sees another page
  86. on paginationGo(e) {
  87. b = e.target.closest('button')
  88. to = b == null ? null : toNumber(b.getAttribute('data-page'))
  89. if (to == null || to < 1 || to > pages || to == page) { return null }
  90. show(to)
  91. if (onPage != null) { onPage(to) }
  92. }

Branches

Latest commits

  • cb38de2blog: swap 503 causemre
  • fd10c3d5log: CB livemre
  • 7557c025log: CB deploy try 2mre
  • 06a7534aMerge branch 'cb'mre
  • 2f8030d6log: CB gates greenmre
  • 498bf644log: CB gates startmre
  • f59c2847gc1: bound the five request caches (shows.hl cacheLimit)mre
  • 6ea2c6d6log: morning re-measure 11-04mre
  • 446290f0log: GC1 livemre
  • 8e6aa91dlog: GC1 deploy retrymre
  • 87ad2dc1log: GC1 deployingmre
  • 53f10fb8Merge branch 'gc1-deploy'mre
  • 7fcbf1d2log: GC1 deploy GOmre
  • 1fb6664bcompose: TRACKER_QSTATS=1 (GC1 measurement)mre
  • 6576c1cdgc1: release the people-view scan lists once the view is builtmre
  • 94f8a373gc1: back out the kept episode-id set (no measurable gain on /my/unwatched: 4.69 -> 4.61 GB per 150 loads)mre
  • a1a88bd4gc1: search skips the stale-key string while no entry is stale; /my/unwatched asks a kept id set instead of building a key string per episode rowmre
  • cd830744gc1: dbSearch: no split / map / list copy per candidate (scores from the stored text, top list touched only when the hit can enter)mre
  • 451db7cdgc1: show page and check clicks read the kept watched set instead of building one from a by-value copy of every watchmre
  • ddb4127egc1: TRACKER_QSTATS=1 logs queue and cache sizes every 10 s (measurement only)mre