components
All repositories: gitoria
5.5 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 loadedString orderRevision = '' // change after replacing the sort/filter and loaded chunkNumber 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 resetKey = orderRevision }}}```## 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 || `resetKey` | a bound String reset token; a changed nonempty value rebuilds the window at `scrollTop` or 0 || `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) |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.## 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.- Each composed list resets its own scrolling box independently.## 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.## Initial position and remembering a visit`VirtualList { centerId = playingId scrollTop = savedOffset onScroll = rememberOffset }`uses ordinary parent member bindings and a parent function `rememberOffset = (top) => { ... }`.The parent saves that pixel offset in its own persistent settings and supplies it again after reload.The component does not choose a storage key or save application data itself.`scrollTop` defaults to null and is applied once at the first mount tick. `centerId` defaults toan empty string. A matching id in the initial `loaded` chunk is centered once, after restoringthe offset, so centering wins when both are supplied. Include that row in `loaded` and set`loadedFrom` to the chunk's actual start; an id outside the initial chunk cannot be locatedwithout the parent's data and leaves the saved position alone. Offsets are clamped by the browser.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.`selectedId` continues to control the highlighted row independently.`onScroll(top)` defaults to null. While scrolling it reports the latest offset at most onceper 100 ms, including the final offset after the last event. It receives a number, in pixels.## Regression check`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
- 489afcf1virtual-list: name the scroll-position gap hybriel#445Atlas
- b7e11e3bvirtual-list: the first resetKey is the baseline, so centerId and scrollTop keep their place at mount; gate for itAtlas
- 7e428ba6Re-vendor Hybriel day72 (day73 withdrawn: minifier breaks write sets)Atlas
- a06fc778Reset virtual-list window when the host changes resetKeyAtlas
- 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
- 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
- f5f131c5Record AP29 autoplay comparisons and passing gatesmre
- 51c38187Gate media autoplay on first load and after client mountmre
- a3f2223dRecord successful B44 deployment and live proofmre
- 06c1e021Record passing B44 browser rerunmre
- c9861533Record B44 component proof and browser gate blockermre
- 1b7413beIgnore detached media events and space demo option outputsmre
- ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
- df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
- 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
- 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
- 9b872cedRecord IC28 deployment and live icon verificationmre
- 46fefaa7Count the icons entry in the offline home-page checkmre
- c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre