npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@affino/listbox-core

v1.1.0

Published

Headless listbox state machine built on @affino/selection-core

Readme

@affino/listbox-core

Headless listbox state machine built on top of the linear selection primitives provided by @affino/selection-core.

Features

  • Maintains focus (active option) alongside linear selection ranges
  • Skips disabled options when navigating with the keyboard
  • Supports single toggle, range extension, select-all, and clear intents
  • Framework agnostic: feed its snapshots into Vue, React, or vanilla renderers

Usage

import {
  createListboxState,
  moveListboxFocus,
  activateListboxIndex,
} from "@affino/listbox-core"

const context = {
  optionCount: options.length,
  isDisabled: (index: number) => options[index]?.disabled ?? false,
}

let state = createListboxState()
state = activateListboxIndex({ state, context, index: 0 })
state = moveListboxFocus({ state, context, delta: 1, extend: true })

Adapter contract

listbox-core is intentionally DOM-agnostic. Adapters are responsible for mapping UI events to pure operations.

Required context invariants:

  • context.optionCount must match the rendered option collection length.
  • context.isDisabled(index) must be stable for the same render tick.
  • context.optionCount and isDisabled must describe the same option ordering used by the DOM.

State ownership rules:

  • Keep a single source of truth for ListboxState in the adapter.
  • Treat returned ListboxState as immutable snapshots; always replace, never mutate.
  • Recompute context from current rendered options before each operation.

Operation mapping (recommended):

  • ArrowDown -> moveListboxFocus({ delta: 1 })
  • ArrowUp -> moveListboxFocus({ delta: -1 })
  • Home -> activateListboxIndex({ index: 0 })
  • End -> activateListboxIndex({ index: optionCount - 1 })
  • Shift + Arrow* -> moveListboxFocus({ extend: true, ... })
  • Space on active option -> toggleActiveListboxOption({ state })
  • pointer click on option i -> activateListboxIndex({ index: i, toggle: isMultiSelect })
  • clear action -> clearListboxSelection({ preserveActiveIndex: true, state })
  • select all action -> selectAllListboxOptions({ context })

Behavioral guarantees adapters can rely on:

  • Disabled options are skipped during focus navigation.
  • Selecting a disabled option index only updates activeIndex (selection is unchanged).
  • Invalid counts (NaN, Infinity, <= 0) are treated as empty context.
  • isDisabled exceptions are swallowed and treated as "enabled".

Common wrapper mistakes to avoid:

  • Building context from global document queries instead of surface-scoped options.
  • Mutating state.selection ranges in-place.
  • Applying both core operation and additional ad-hoc selection mutation in the same event handler.

See packages/selection-vue for a concrete adapter integration pattern.