@kolkrabbi/kol-component 0.271.0 → 0.273.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -43,6 +43,10 @@ import Kbd from '../atoms/Kbd.jsx'
|
|
|
43
43
|
* @param {Function} onOpenChange (expanding) (bool) => void — trigger click / Escape
|
|
44
44
|
* @param {number} expandedWidth (expanding) open pill width in px (default 280)
|
|
45
45
|
* @param {string} triggerLabel (expanding) aria-label on the icon trigger (default 'Open search')
|
|
46
|
+
* @param {Function} [onBack] a drill-in's way back: the leading search glyph becomes a back arrow IN THE SAME
|
|
47
|
+
* SLOT, so the field never moves (CommandOverlay's second layer — user 2026-10-18:
|
|
48
|
+
* *"why would the back move the input?!"*)
|
|
49
|
+
* @param {string} [backLabel] the back arrow's aria-label (default `Back`)
|
|
46
50
|
* @param {string} className extra classes on the shell
|
|
47
51
|
*/
|
|
48
52
|
|
|
@@ -88,6 +92,8 @@ export default function SearchInput({
|
|
|
88
92
|
iconSize,
|
|
89
93
|
fieldHeight,
|
|
90
94
|
triggerLabel = 'Open search',
|
|
95
|
+
onBack,
|
|
96
|
+
backLabel = 'Back',
|
|
91
97
|
className = '',
|
|
92
98
|
...inputProps
|
|
93
99
|
}) {
|
|
@@ -226,13 +232,26 @@ export default function SearchInput({
|
|
|
226
232
|
|
|
227
233
|
return (
|
|
228
234
|
<label className={shellCls}>
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
{onBack ? (
|
|
236
|
+
<button
|
|
237
|
+
type="button"
|
|
238
|
+
aria-label={backLabel}
|
|
239
|
+
/* mousedown keeps focus in the field */
|
|
240
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
241
|
+
onClick={onBack}
|
|
242
|
+
className={`flex items-center shrink-0 cursor-pointer transition-colors ${bare ? 'text-oq-48 hover:text-oq-96' : 'text-auto opacity-50 hover:opacity-100'}`}
|
|
243
|
+
>
|
|
244
|
+
<Icon name="arrow-left" size={iconSize ?? glyphSize(size)} />
|
|
245
|
+
</button>
|
|
246
|
+
) : (
|
|
247
|
+
<span
|
|
248
|
+
aria-hidden="true"
|
|
249
|
+
className={`flex items-center shrink-0 ${bare ? 'text-oq-48' : 'text-auto opacity-50'}`}
|
|
250
|
+
>
|
|
251
|
+
{/* ADJACENT — this glyph sits in the field's line box beside the query */}
|
|
252
|
+
<Icon name="search" size={iconSize ?? glyphSize(size)} />
|
|
253
|
+
</span>
|
|
254
|
+
)}
|
|
236
255
|
<input
|
|
237
256
|
type="search"
|
|
238
257
|
value={value ?? ''}
|
|
@@ -4,8 +4,6 @@ import SearchInput from '../molecules/SearchInput.jsx'
|
|
|
4
4
|
import Tag from '../atoms/Tag.jsx'
|
|
5
5
|
import Kbd from '../atoms/Kbd.jsx'
|
|
6
6
|
import OptionRow from '../molecules/OptionRow.jsx'
|
|
7
|
-
import Button from '../atoms/Button.jsx'
|
|
8
|
-
import { Tooltip } from '../utilities/Popover.jsx'
|
|
9
7
|
import { shortcutInScope } from './ShortcutsOverlay.jsx'
|
|
10
8
|
|
|
11
9
|
/* ONE COLUMN (2026-09-30): rows, headings and footer sit on the field's own
|
|
@@ -64,23 +62,25 @@ export function HighlightMatch({ label, query, ranges }) {
|
|
|
64
62
|
/* THE MODES (CommandOverlayModes, kol-monitor 2026-10-17 — user: *"can we make the modal more general then just
|
|
65
63
|
* search? … add module would be another, shortcuts could be a third"*). One field, one grouped list, one footer;
|
|
66
64
|
* the mode only sets the footer's words and, for `shortcuts`, where the rows come from. */
|
|
67
|
-
const MODE_LABEL = { search: 'Go to page', go: 'Go to page', add: 'Add', shortcuts: '
|
|
65
|
+
const MODE_LABEL = { search: 'Go to page', go: 'Go to page', add: 'Add', shortcuts: 'Open' }
|
|
68
66
|
const MODE_PLACEHOLDER = { search: 'Search…', go: 'Go to…', add: 'Add…', shortcuts: 'Search shortcuts…' }
|
|
69
67
|
|
|
70
|
-
/*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
/* THE KEYMAP AS CATEGORIES (ShortcutsOverlayCategories, kol-monitor 2026-10-18 — user: *"we are using the fucking
|
|
69
|
+
* command overlay WITHOUT THE SEARHC INPUT, we are using the CATEGORIES"*): this page's sections (plus those with no
|
|
70
|
+
* `routes`) as rows under "Shortcuts"; a picked section drills in to its keys — label left, combo right, never run. */
|
|
71
|
+
function shortcutRows(shortcuts, path, cat) {
|
|
72
|
+
const here = shortcuts.filter((s) => shortcutInScope(s, path))
|
|
73
|
+
const sec = cat != null && here.find((s) => s.section === cat)
|
|
74
|
+
if (!sec) return here.map((s) => ({ id: `cat:${s.section}`, label: s.section, icon: 'arrow-right', group: 'Shortcuts', keepOpen: true, cat: s.section }))
|
|
75
|
+
return (sec.items ?? []).map((it) => ({ id: `${sec.section}:${it.id ?? it.label}`, label: it.label, hint: it.combo ?? it.keys, group: sec.section }))
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
/**
|
|
80
79
|
* CommandOverlay — The ⌘K overlay: search, add, go, shortcuts. Was `ShellSearchOverlay` (still exported, an
|
|
81
80
|
* alias). `mode` names what the overlay is for — `search` (default) · `go` · `add` · `shortcuts`. In
|
|
82
|
-
* `shortcuts` it draws `shortcuts`
|
|
83
|
-
*
|
|
81
|
+
* `shortcuts` it draws `shortcuts` (the AppHub keymap) with NO field: the current page's sections as category rows under
|
|
82
|
+
* "Shortcuts"; Enter / → / click enters one, its keys listed (label · combo, never run); ← / Backspace / the back
|
|
83
|
+
* arrow returns. AppHub's `S` opens this (ShortcutsOverlayCategories, 2026-10-18).
|
|
84
84
|
*
|
|
85
85
|
* ARROWS (2026-10-17 — user: *"arrows up down can focus category and arrows left right can enter and back,
|
|
86
86
|
* along with enter key"*): ↑↓ move through rows; → or Enter opens a category (a `keepOpen` row); ← goes back
|
|
@@ -119,7 +119,7 @@ function shortcutRows(shortcuts, path, query) {
|
|
|
119
119
|
* own results surface. Plain Enter keeps its meaning.
|
|
120
120
|
* @param {string} [resultsLabel] the footer's second line for ⌘Enter (e.g. `All results`)
|
|
121
121
|
* @param {Function} [onBack] a drill-in's way back (CommandOverlayModes, kol-monitor 2026-10-17): set, the
|
|
122
|
-
*
|
|
122
|
+
* search glyph becomes a back arrow in its slot (the field never moves); Backspace on an empty field calls it —
|
|
123
123
|
* instead of a "← All" row that scrolls away with the list
|
|
124
124
|
* @param {string} [backLabel] the arrow's tooltip (default `Back`) — name where it goes ("All modules")
|
|
125
125
|
* @param {string} [selectLabel] the footer's Enter line while a row is highlighted (default
|
|
@@ -161,9 +161,13 @@ export default function CommandOverlay({
|
|
|
161
161
|
/* Has the user actually chosen a row? See the Enter branch — without this,
|
|
162
162
|
* index 0 counts as a selection and Enter navigates somewhere unasked. */
|
|
163
163
|
const [navigated, setNavigated] = useState(false)
|
|
164
|
+
/* the shortcuts mode's drill-in — the category entered, or null for the category list */
|
|
165
|
+
const [cat, setCat] = useState(null)
|
|
166
|
+
const noField = mode === 'shortcuts'
|
|
167
|
+
const back = noField ? (cat != null ? () => setCat(null) : undefined) : onBack
|
|
164
168
|
const placeholder = placeholderProp ?? MODE_PLACEHOLDER[mode] ?? 'Search…'
|
|
165
169
|
const selectLabel = selectLabelProp ?? MODE_LABEL[mode] ?? 'Go to page'
|
|
166
|
-
const results = mode === 'shortcuts' ? shortcutRows(shortcuts, currentPath,
|
|
170
|
+
const results = mode === 'shortcuts' ? shortcutRows(shortcuts, currentPath, cat) : groupRows(query ? rawResults : suggestions)
|
|
167
171
|
/* a `disabled` row is drawn but never active: ↑↓ step over it, Enter and click never reach
|
|
168
172
|
* `onSelect` (ShellSearchDisabledRow, kol-monitor 2026-10-15 — a module with no room on the rack) */
|
|
169
173
|
const clamped = Math.min(activeIndex, results.length - 1)
|
|
@@ -179,8 +183,8 @@ export default function CommandOverlay({
|
|
|
179
183
|
useEffect(() => {
|
|
180
184
|
if (!open) return undefined
|
|
181
185
|
const prev = document.activeElement
|
|
182
|
-
panelRef.current?.querySelector('input')?.focus()
|
|
183
|
-
return () => { if (prev instanceof HTMLElement) prev.focus() }
|
|
186
|
+
;(panelRef.current?.querySelector('input') ?? panelRef.current)?.focus()
|
|
187
|
+
return () => { setCat(null); if (prev instanceof HTMLElement) prev.focus() }
|
|
184
188
|
}, [open])
|
|
185
189
|
|
|
186
190
|
/* Roving row resets to the top on every query change / reopen — and when the ROWS change under an
|
|
@@ -204,7 +208,7 @@ export default function CommandOverlay({
|
|
|
204
208
|
* it too would fire it twice in every shell that already does (workshop's tag rows). */
|
|
205
209
|
const select = (item) => {
|
|
206
210
|
if (item?.disabled) return
|
|
207
|
-
if (mode === 'shortcuts') {
|
|
211
|
+
if (mode === 'shortcuts') { if (item?.cat != null) setCat(item.cat); return }
|
|
208
212
|
onSelect?.(item)
|
|
209
213
|
if (!(item?.keepOpen || typeof item?.action === 'function')) onClose?.()
|
|
210
214
|
}
|
|
@@ -212,12 +216,12 @@ export default function CommandOverlay({
|
|
|
212
216
|
const optionId = (item) => `${listId}-${item.id}`
|
|
213
217
|
|
|
214
218
|
const handleKeyDown = (e) => {
|
|
215
|
-
if (e.key === 'Backspace' && !query &&
|
|
219
|
+
if (e.key === 'Backspace' && !query && back) {
|
|
216
220
|
e.preventDefault()
|
|
217
|
-
|
|
218
|
-
} else if (e.key === 'ArrowLeft' && !query &&
|
|
221
|
+
back()
|
|
222
|
+
} else if (e.key === 'ArrowLeft' && !query && back) {
|
|
219
223
|
e.preventDefault()
|
|
220
|
-
|
|
224
|
+
back()
|
|
221
225
|
} else if (e.key === 'ArrowRight' && !query && active >= 0 && results[active]?.keepOpen) {
|
|
222
226
|
e.preventDefault()
|
|
223
227
|
select(results[active])
|
|
@@ -265,10 +269,13 @@ export default function CommandOverlay({
|
|
|
265
269
|
/>
|
|
266
270
|
<div
|
|
267
271
|
ref={panelRef}
|
|
272
|
+
/* no field (shortcuts): the panel takes focus and the keys */
|
|
273
|
+
tabIndex={noField ? -1 : undefined}
|
|
274
|
+
onKeyDown={noField ? handleKeyDown : undefined}
|
|
268
275
|
role="dialog"
|
|
269
276
|
aria-modal="true"
|
|
270
277
|
aria-label="Search"
|
|
271
|
-
className={`kol-overlay-panel mx-4 ${expanded ? 'max-w-[var(--kol-content-panel)]' : 'max-w-lg'}`}
|
|
278
|
+
className={`kol-overlay-panel mx-4 ${noField ? 'outline-none ' : ''}${expanded ? 'max-w-[var(--kol-content-panel)]' : 'max-w-lg'}`}
|
|
272
279
|
>
|
|
273
280
|
{/* THE MODE, said out loud (user 2026-08-01: "how do you set search
|
|
274
281
|
* mode? theres no helper, message or mode clearly readble"). Two
|
|
@@ -285,25 +292,25 @@ export default function CommandOverlay({
|
|
|
285
292
|
)}
|
|
286
293
|
{/* A REAL FIELD, inset in the panel (2026-09-30, shadcn's search modal as
|
|
287
294
|
* the aim) — the flush `bare` strip read as a hole, not a control. */}
|
|
295
|
+
{!noField && (
|
|
288
296
|
<div className="kol-tone-grey p-2 flex items-center gap-2">
|
|
289
|
-
{
|
|
290
|
-
|
|
291
|
-
{/* mousedown keeps focus in the field, as the rows do */}
|
|
292
|
-
<Button iconOnly="arrow-left" tone="ghost" size="md" aria-label={backLabel} onMouseDown={(e) => e.preventDefault()} onClick={onBack} />
|
|
293
|
-
</Tooltip>
|
|
294
|
-
)}
|
|
297
|
+
{/* THE BACK ARROW TAKES THE SEARCH GLYPH'S SLOT (user 2026-10-18: *"why would the back move the input?!"*) —
|
|
298
|
+
* a button beside the field shrank it and shifted the caret on every drill-in */}
|
|
295
299
|
<SearchInput
|
|
296
300
|
className="w-full min-w-0 flex-1"
|
|
297
301
|
value={query}
|
|
298
302
|
onChange={(e) => onQueryChange?.(e.target.value)}
|
|
299
303
|
placeholder={chips.length > 0 ? 'Narrow these results…' : placeholder}
|
|
300
304
|
onKeyDown={handleKeyDown}
|
|
305
|
+
onBack={back}
|
|
306
|
+
backLabel={backLabel}
|
|
301
307
|
role="combobox"
|
|
302
308
|
aria-expanded={results.length > 0}
|
|
303
309
|
aria-controls={listId}
|
|
304
310
|
aria-activedescendant={active >= 0 ? optionId(results[active]) : undefined}
|
|
305
311
|
/>
|
|
306
312
|
</div>
|
|
313
|
+
)}
|
|
307
314
|
|
|
308
315
|
{/* WHY THIS IS NOT `molecules/Dropdown` (asked 2026-08-01). Dropdown is
|
|
309
316
|
* a SELECT: a trigger, a `value`, `onChange(value)`, and rows that are
|
|
@@ -333,15 +340,21 @@ export default function CommandOverlay({
|
|
|
333
340
|
ref={listRef}
|
|
334
341
|
id={listId}
|
|
335
342
|
role="listbox"
|
|
336
|
-
className=
|
|
343
|
+
className={`kol-tone-grey h-80 overflow-y-auto px-2 pb-2${noField ? ' pt-2' : ''}`}
|
|
337
344
|
>
|
|
338
345
|
{results.map((item, i) => {
|
|
339
346
|
const heading = (item.group ?? '') !== (results[i - 1]?.group ?? '') || i === 0
|
|
340
347
|
return (
|
|
341
348
|
<li key={item.id} role="presentation">
|
|
342
|
-
{heading && item.group && (
|
|
349
|
+
{heading && item.group && (noField && back && i === 0 ? (
|
|
350
|
+
/* shortcuts' second layer: the arrow leads the category's own heading — nothing moves */
|
|
351
|
+
<button type="button" aria-label="Shortcuts" onMouseDown={(e) => e.preventDefault()} onClick={back}
|
|
352
|
+
className="kol-helper-12 text-fg-48 hover:text-fg-80 transition-colors flex items-center gap-2 px-4 border-x border-transparent pt-3 pb-2 cursor-pointer">
|
|
353
|
+
<Icon name="arrow-left" size={12} />{item.group}
|
|
354
|
+
</button>
|
|
355
|
+
) : (
|
|
343
356
|
<p className="kol-helper-12 text-fg-48 px-4 border-x border-transparent pt-3 pb-2">{item.group}</p>
|
|
344
|
-
)}
|
|
357
|
+
))}
|
|
345
358
|
<OptionRow
|
|
346
359
|
id={optionId(item)}
|
|
347
360
|
role="option"
|
|
@@ -363,7 +376,7 @@ export default function CommandOverlay({
|
|
|
363
376
|
</ul>
|
|
364
377
|
)}
|
|
365
378
|
{/* THE FOOTER SAYS WHAT ENTER DOES — always, not only once typing. */}
|
|
366
|
-
{!expanded && (results.length > 0 || (query && (enterLabel || onOpenResults))) && (
|
|
379
|
+
{!expanded && !(noField && cat != null) && (results.length > 0 || (query && (enterLabel || onOpenResults))) && (
|
|
367
380
|
<div className="border-t border-fg-08 py-2">
|
|
368
381
|
{/* Enter's line names what Enter does NOW: a row is highlighted → it opens that row;
|
|
369
382
|
* no rows → it commits the query. */}
|