gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita9eb9827a9eb9827records: mpackdb integrity clean, all 12 tablesmrea9eb9827/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

  • a9eb9827records: mpackdb integrity clean, all 12 tablesmre
  • 6cf40dbdrecords: mpackdb integrity check, shows uncheckedmre
  • 1880f42arecords: day38 deploy may swap normallymre
  • 9d806e35records: mpackdb freeze until day38mre
  • a660239drecords: day37 lacks #277, wait for day38mre
  • b0abfdeaLOG: Anton hybriel#277 fix ready for day37mre
  • 7b5b2918Tracker: hybriel#277 fix comes in day37mre
  • 7ddbeec8Tracker: RV28c blocked on day35 regressionmre
  • bf401884Tracker: RV28c startedmre
  • 0ff4ecd4Tracker: RV28c briefmre
  • 06565b1fRecords: day35 relay note, tickets subscription idmre
  • c6dc3e86RV28b: switch to set day35mre
  • 24e401b8Tracker: TR7 watch cleanmre
  • b0412957Tracker: RV28b handed overmre
  • 456940c8Tracker: RULINGS pathmre
  • b87a8fdcTracker: worldapi-conductor paths backmre
  • 641f3b54Tracker: Apollo answermre
  • 8b3cbddaTracker: status, TR7 fix livemre
  • ec30162aTracker: TR7 fix livemre
  • 54cbec80compose: ignore SIGPIPE (TR7 crash loop, exit 141)mre