jukebox
All repositories: gitoria
3.7 KB
# Virtual listA list of tens of thousands of rows that scrolls smoothly on a phone. Demo: `/virtual-list`(https://components.hybriel.worldapi.org/virtual-list).Only the rows near the viewport exist in the page. Every row has the same fixed height, so the list knowswhere row N is without measuring: a spacer as tall as the whole list (`itemCount × rowHeight`) makes the scrollbar honest, and the few rows near the viewport (about 30 on a phone) are placed inside it. Scrolling a13,449-row list to the end keeps the page at about 35 rows.Pure Hybriel: one file, `virtual-list.hl`, with its own `Style`; no JavaScript file. It does not fetch anything:**the host owns the data** and loads it page by page.## Use it in an appCopy `components/virtual-list/virtual-list.hl` (and `components/icons/icons.hl`, which it imports), then:```import VirtualList from './virtual-list.hl'Number total = 13449Hybrid chunk = [] // the rows the host has loadedNumber chunkFrom = 0 // the number of the first row in `chunk`loadRange = (first, wanted) => {r = emit server myRows(first - 20 < 0 ? 0 : first - 20, 100) // an app asks its serverchunk = r.rowschunkFrom = r.offset}picked = (id, index) => { ... }View {div { class = "my-box" // gets a height, the list scrolls inside itVirtualList { itemCount = total rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId }}}```## Attributes| Attribute | Meaning ||---|---|| `itemCount` | how many rows the whole list has || `rowHeight` | the height of every row in pixels (default 56); the rows are exactly this tall || `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 || `loadedFrom` | the number of the first row in `loaded` (0-based) || `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` || `onPick` | called with `(id, index)` when a row is tapped || `selectedId` | the `id` of the row to mark (the accent colour on a surface) || `thumbs` | `"false"` leaves the thumbnail out || `overscan` | how many rows are kept above and below the viewport (default 10) || `listLabel`, `emptyText` | the accessible name of the list; the text shown when `itemCount` is 0 || content | anything written inside `VirtualList { … }` stands above the rows and scrolls away with them (an album's cover and title) |`emit vlTop()` scrolls back to the first row; the host calls it after it changed the order or the filter.## Behaviour- Rows that the host has not delivered yet are blank rows of the same height, so the list never jumps; the host's`loaded` may be only a chunk of 100 rows around the viewport, a jump to the middle of the list asks for that part.- The list fills the box the host gives `virtual-list` (`height: 100%` of its parent, the scrolling happens inside).- A row is a button (keyboard Tab and Enter work), exactly `rowHeight` tall: the tap area is the row itself, no padding tricks, so thelist stays dense. Thumbnail, the text block and the row share one centre line.- Colours are the semantic tokens with a black/white/grey fallback (the base look); no frames.- **Use one per page**: a composed component's members are the page's state, so the public names (`itemCount`, `loaded`, `selectedId` …)are chosen to stay clear of a host's own.## Not yetNo row measuring (all rows are one height), no sticky section headers, no horizontal lists, no keyboard arrow navigation betweenrows (Tab moves along the rows that exist), and a row moved out of the window loses the keyboard focus.
Branches
Latest commits
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre
- 227c9b96Records: jb19 livemre
- 9f365376README: the bar's controls (jb19)mre
- d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre
- 82b54c0ejb19: bar Shuffle · Previous · Play · Next · Repeat, no 10 s buttons; Shuffle switch (shuffle from the playing song, back to the list), Repeat off/all/one, both remembered in ui.json; Shuffle my favourites an ordinary button; gate tests/jb19.mjsmre
- ba354710jb19: icons pinned to components.hybriel 46fefaa (shuffle, repeat, repeatOne, prevTrack, nextTrack)mre
- d8e8d059jb19 step 2: media-player from components.hybriel c96709c (skip, repeat options; the end of a song only calls onPlay), sync-components.sh and SOURCE point to it, jb11 counts media loads and metadata writes (from jb21 d3a026e)mre
- 7b048c1bRecords: jb19 done, L2 live stepmre
- 665185aeMission 009: jb19 livemre
- 47b2d3beRecords: P1 resumedmre
- 8e326e94Records: resetKey blockedmre
- f72dd7edRecords: icons comingmre
- b264e5deRecords: P1 icons stopmre
- 514d7cbeRecords: mission 008 startedmre
- 61c40127Mission 008: #19 + #21mre
- 6dcaeb46Records: resetKey planmre
- c5dbf2ecRecords: R2 resultmre
- 956069b8Records: R1 result, mission 007mre