gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchrecords-1124d78f0cc86|||PR records 2026-11-24: inbox-thread rule, "Not playing" confirmed and closedmrerecords-1124d/components/virtual-list/README.md

5.5 KB

  1. # Virtual list
  2. A list of tens of thousands of rows that scrolls smoothly on a phone. Demo: `/virtual-list`
  3. (https://components.hybriel.worldapi.org/virtual-list).
  4. Only the rows near the viewport exist in the page. Every row has the same fixed height, so the list knows
  5. where row N is without measuring: a spacer as tall as the whole list (`itemCount × rowHeight`) makes the scroll
  6. bar honest, and the few rows near the viewport (about 30 on a phone) are placed inside it. Scrolling a
  7. 13,449-row list to the end keeps the page at about 35 rows.
  8. Pure Hybriel: one file, `virtual-list.hl`, with its own `Style`; no JavaScript file. It does not fetch anything:
  9. **the host owns the data** and loads it page by page.
  10. ## Use it in an app
  11. Copy `components/virtual-list/virtual-list.hl` (and `components/icons/icons.hl`, which it imports), then:
  12. ```
  13. import VirtualList from './virtual-list.hl'
  14. Number total = 13449
  15. Hybrid chunk = [] // the rows the host has loaded
  16. String orderRevision = '' // change after replacing the sort/filter and loaded chunk
  17. Number chunkFrom = 0 // the number of the first row in `chunk`
  18. loadRange = (first, wanted) => {
  19. r = emit server myRows(first - 20 < 0 ? 0 : first - 20, 100) // an app asks its server
  20. chunk = r.rows
  21. chunkFrom = r.offset
  22. }
  23. picked = (id, index) => { ... }
  24. View {
  25. div { class = "my-box" // gets a height, the list scrolls inside it
  26. VirtualList { itemCount = total rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId resetKey = orderRevision }
  27. }
  28. }
  29. ```
  30. ## Attributes
  31. | Attribute | Meaning |
  32. |---|---|
  33. | `itemCount` | how many rows the whole list has |
  34. | `rowHeight` | the height of every row in pixels (default 56); the rows are exactly this tall |
  35. | `loaded` | the rows the host has loaded, `[{ id, title, sub, aside, img }]`; `img` is a thumbnail address or `''` (a plain square) and is loaded lazily |
  36. | `loadedFrom` | the number of the first row in `loaded` (0-based) |
  37. | `onRange` | a function the host hands in; called with `(first, count)` when rows near the viewport are not all in `loaded`; the host loads them and hands in new `loaded` / `loadedFrom` |
  38. | `onPick` | called with `(id, index)` when a row is tapped |
  39. | `selectedId` | the `id` of the row to mark (the accent colour on a surface) |
  40. | `thumbs` | `"false"` leaves the thumbnail out |
  41. | `resetKey` | a bound String reset token; a changed nonempty value rebuilds the window at `scrollTop` or 0 |
  42. | `overscan` | how many rows are kept above and below the viewport (default 10) |
  43. | `listLabel`, `emptyText` | the accessible name of the list; the text shown when `itemCount` is 0 |
  44. | content | anything written inside `VirtualList { … }` stands above the rows and scrolls away with them (an album's cover and title) |
  45. Pass a bound String member as `resetKey`. Change it after updating the order, filter and loaded chunk. A new nonempty key rebuilds the window and restores `scrollTop` when supplied, otherwise it scrolls to 0. The default empty key does nothing; repeating a key does nothing. `emit vlTop()` from the host cannot reach the child’s own event bus and is replaced by this parameter.
  46. ## Behaviour
  47. - Rows that the host has not delivered yet are blank rows of the same height, so the list never jumps; the host's
  48. `loaded` may be only a chunk of 100 rows around the viewport, a jump to the middle of the list asks for that part.
  49. - The list fills the box the host gives `virtual-list` (`height: 100%` of its parent, the scrolling happens inside).
  50. - A row is a button (keyboard Tab and Enter work), exactly `rowHeight` tall: the tap area is the row itself, no padding tricks, so the
  51. list stays dense. Thumbnail, the text block and the row share one centre line.
  52. - Colours are the semantic tokens with a black/white/grey fallback (the base look); no frames.
  53. - Each composed list resets its own scrolling box independently.
  54. ## Not yet
  55. No row measuring (all rows are one height), no sticky section headers, no horizontal lists, no keyboard arrow navigation between
  56. rows (Tab moves along the rows that exist), and a row moved out of the window loses the keyboard focus.
  57. ## Initial position and remembering a visit
  58. `VirtualList { centerId = playingId scrollTop = savedOffset onScroll = rememberOffset }`
  59. uses ordinary parent member bindings and a parent function `rememberOffset = (top) => { ... }`.
  60. The parent saves that pixel offset in its own persistent settings and supplies it again after reload.
  61. The component does not choose a storage key or save application data itself.
  62. `scrollTop` defaults to null and is applied once at the first mount tick. `centerId` defaults to
  63. an empty string. A matching id in the initial `loaded` chunk is centered once, after restoring
  64. the offset, so centering wins when both are supplied. Include that row in `loaded` and set
  65. `loadedFrom` to the chunk's actual start; an id outside the initial chunk cannot be located
  66. without the parent's data and leaves the saved position alone. Offsets are clamped by the browser.
  67. Later changes to either input or the loaded rows do not recenter or restore the list again unless `resetKey` changes. A reset does not apply `centerId` again.
  68. `selectedId` continues to control the highlighted row independently.
  69. `onScroll(top)` defaults to null. While scrolling it reports the latest offset at most once
  70. per 100 ms, including the final offset after the last event. It receives a number, in pixels.
  71. ## Regression check
  72. `node tests/virtual-list-reset.mjs` changes sort after scrolling far down at 390 and 1280 pixels. It checks a reset to 0, a supplied offset and an unchanged key. The demo buttons expose these same actions.

Branches

Latest commits

  • 78f0cc86|||PR records 2026-11-24: inbox-thread rule, "Not playing" confirmed and closedmre
  • c1b153c4Merge branch 'records-1124c' into mainJukebox
  • d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
  • 43b564dbMerge branch 'records-1124b' into mainJukebox
  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • a3796dc5Records: live step waits for idlemre
  • 3b158e16Records: merges of #9 and #11mre
  • 27204167Merge main into records-1123mre
  • 10f8a8c8Merge branch 'code-order' into mainJukebox