{"version":3,"names":["createSignal","For","useInput","Select","props","internal","setInternal","index","current","indicator","focused","highlight","i","item","items","undefined","onHighlight","move","delta","n","length","commit","onSelect","key","name","highlighted","highlightColor","children","color","String"],"sources":["select.tsx"],"sourcesContent":["import type { ColorInput } from \"bun\";\nimport type { Element as JSXElement } from \"solid-js\";\nimport { createSignal, For } from \"solid-js\";\nimport { useInput } from \"../input/hooks.ts\";\n\nexport type SelectProps<T> = {\n\t/** The rows to choose between. */\n\titems: readonly T[];\n\t/**\n\t * Render a row's label. Receives the item, whether it's highlighted, and its\n\t * index. Default renders `String(item)` (bold + `highlightColor` when\n\t * highlighted). Supply this to render richer rows; you then own their styling.\n\t */\n\tchildren?: (item: T, highlighted: boolean, index: number) => JSXElement;\n\t/**\n\t * Highlighted index. Pass it to drive the highlight yourself (controlled);\n\t * omit it to let `Select` track the highlight internally (uncontrolled).\n\t */\n\tindex?: number;\n\t/** Fires when the highlight moves (↑/↓, `k`/`j`, or hover). */\n\tonHighlight?: (item: T, index: number) => void;\n\t/** Fires when a row is committed (Enter or click). */\n\tonSelect?: (item: T, index: number) => void;\n\t/** Only handle keys while true. Default true. */\n\tfocused?: boolean;\n\t/** Glyph in the gutter of the highlighted row. Default `❯`. */\n\tindicator?: string;\n\t/** Color of the highlighted row + its indicator. Default `#d77757`. */\n\thighlightColor?: ColorInput;\n\t/** Color of the non-highlighted rows. */\n\tcolor?: ColorInput;\n};\n\n/**\n * A keyboard- and mouse-navigable list. `↑`/`↓` (or `k`/`j`) move the\n * highlight, Enter commits it, and — when the screen has `mouse: true` — hover\n * highlights a row and a click commits it. Each row is `indicator + label`, the\n * indicator marking the current row in the gutter so labels stay aligned.\n *\n * Uncontrolled by default (it tracks the highlight itself); pass `index` to\n * drive the highlight from the parent. `onHighlight` fires as the highlight\n * moves, `onSelect` when a row is committed.\n *\n * ```tsx\n * <Select\n *   items={[\"Build\", \"Test\", \"Deploy\"]}\n *   onSelect={(item) => run(item)}\n * />\n * ```\n */\nexport function Select<T>(props: SelectProps<T>) {\n\tconst [internal, setInternal] = createSignal(props.index ?? 0);\n\tconst current = () => props.index ?? internal();\n\tconst indicator = () => props.indicator ?? \"❯\";\n\tconst focused = () => props.focused ?? true;\n\n\tconst highlight = (i: number) => {\n\t\tsetInternal(i);\n\t\tconst item = props.items[i];\n\t\tif (item !== undefined) props.onHighlight?.(item, i);\n\t};\n\n\tconst move = (delta: number) => {\n\t\tconst n = props.items.length;\n\t\tif (n === 0) return;\n\t\thighlight((current() + delta + n) % n);\n\t};\n\n\tconst commit = (i: number) => {\n\t\tconst item = props.items[i];\n\t\tif (item !== undefined) props.onSelect?.(item, i);\n\t};\n\n\tuseInput((key) => {\n\t\tif (!focused() || props.items.length === 0) return;\n\t\tif (key.name === \"up\" || key.name === \"k\") move(-1);\n\t\telse if (key.name === \"down\" || key.name === \"j\") move(1);\n\t\telse if (key.name === \"return\") commit(current());\n\t});\n\n\treturn (\n\t\t<box flexDirection=\"column\">\n\t\t\t<For each={props.items}>\n\t\t\t\t{(item, i) => {\n\t\t\t\t\tconst highlighted = () => i() === current();\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<box\n\t\t\t\t\t\t\tflexDirection=\"row\"\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetInternal(i());\n\t\t\t\t\t\t\t\tcommit(i());\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonMouseEnter={() => highlight(i())}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<text bold color={props.highlightColor ?? \"#d77757\"}>\n\t\t\t\t\t\t\t\t{highlighted() ? `${indicator()} ` : \"  \"}\n\t\t\t\t\t\t\t</text>\n\t\t\t\t\t\t\t{props.children ? (\n\t\t\t\t\t\t\t\tprops.children(item, highlighted(), i())\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<text\n\t\t\t\t\t\t\t\t\tbold={highlighted()}\n\t\t\t\t\t\t\t\t\tcolor={\n\t\t\t\t\t\t\t\t\t\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