@kolkrabbi/kol-component 0.251.0 → 0.253.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.251.0",
3
+ "version": "0.253.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "embla-carousel-react": "^8.6.0",
27
27
  "pdfjs-dist": "^6.3.289",
28
28
  "react-syntax-highlighter": "^16.1.1",
29
- "@kolkrabbi/kol-markdown": "^0.1.3",
30
- "@kolkrabbi/kol-search": "^0.3.0"
29
+ "@kolkrabbi/kol-search": "^0.3.0",
30
+ "@kolkrabbi/kol-markdown": "^0.1.3"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@kolkrabbi/kol-icons": ">=0.22.0",
@@ -113,6 +113,11 @@ const Dropdown = ({
113
113
  * the showcase's preview, with its toolbar pickers beside it (user 2026-10-02: *"can we
114
114
  * disclude the preview from that behaviour?"*). */
115
115
  stayOpen = false,
116
+ /* `ariaLabel` — what the dropdown CHOOSES (DropdownAriaLabel, kol-fxr 2026-10-13: a Color pane's
117
+ * Hue · Wheel · HSL · RGB picker read as "Hue, popup button", no word for what it picks). Same name
118
+ * as SegmentedToggle's. An aria-label replaces the button's text, so the current value rides along
119
+ * after it — "Color view, Hue" — and is still announced. */
120
+ ariaLabel,
116
121
  className = ''
117
122
  }) => {
118
123
  const [isOpen, setIsOpen] = useState(defaultOpen)
@@ -239,6 +244,7 @@ const Dropdown = ({
239
244
  className={triggerCls}
240
245
  aria-haspopup="listbox"
241
246
  aria-expanded={isOpen}
247
+ aria-label={ariaLabel ? [ariaLabel, currentOption?.label].filter((t) => typeof t === 'string' && t).join(', ') : undefined}
242
248
  data-state={isOpen ? 'open' : 'closed'}
243
249
  >
244
250
  {iconOnly ? (
@@ -1,4 +1,4 @@
1
- import { useState } from 'react'
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
2
  import { Icon } from '@kolkrabbi/kol-icons'
3
3
  import { PopoverPanel, usePopover } from '../utilities/Popover.jsx'
4
4
 
@@ -125,6 +125,9 @@ const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-3 h-8', m
125
125
  /* `rowClass` — the row's type, side padding and height, whole, in place of the size's own
126
126
  * (Dropdown passes it, 2026-10-02: its rows wear the trigger's face and sit on the trigger's
127
127
  * text edge; a menu's rows keep `ROW_BY_SIZE`). */
128
+ /* `flex`, not `inline-flex` (MenuDropdownItemBlockRow, kol-fxr 2026-10-13): as bare children of a
129
+ * content-sized (`w-max`) panel, inline rows measured as ONE line — five starters ≈ 795px. A block
130
+ * row still fills a fixed panel through `w-full` and lets a content-sized one hug its longest label. */
128
131
  export function MenuDropdownItem({ onClick, onPointerEnter, onPointerLeave, disabled, prefix, iconLeft, shortcut, hover = true, height, size = 'sm', rowClass, children }) {
129
132
  return (
130
133
  <button
@@ -136,7 +139,7 @@ export function MenuDropdownItem({ onClick, onPointerEnter, onPointerLeave, disa
136
139
  disabled={disabled}
137
140
  role="menuitem"
138
141
  style={height != null ? { height } : undefined}
139
- className={`kol-menu-btn w-full ${rowClass ?? ROW_BY_SIZE[size] ?? ROW_BY_SIZE.sm} shrink-0 inline-flex items-center gap-2 text-body ${hover ? 'hover:text-emphasis' : ''} disabled:opacity-40 disabled:cursor-not-allowed text-left`}
142
+ className={`kol-menu-btn w-full ${rowClass ?? ROW_BY_SIZE[size] ?? ROW_BY_SIZE.sm} shrink-0 flex items-center gap-2 text-body ${hover ? 'hover:text-emphasis' : ''} disabled:opacity-40 disabled:cursor-not-allowed text-left`}
140
143
  >
141
144
  {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
142
145
  {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
@@ -155,16 +158,48 @@ export function MenuDropdownDivider() {
155
158
  }
156
159
 
157
160
  /**
158
- * MenuDropdownNest — accordion-style row inside a dropdown panel. Click
159
- * the row to expand/collapse its children inline (below the row, in the
160
- * same panel). The trailing chevron rotates 90° to indicate state.
161
+ * MenuDropdownNest — a row inside a dropdown panel that holds a submenu.
161
162
  *
162
- * Same visual shape as MenuDropdownItem at rest. Clicking a leaf
163
- * MenuDropdownItem inside an open nest still closes the entire menu via
164
- * the standard data-menu-item bubble. Clicking the nest row itself only
165
- * toggles its own expansion.
163
+ * Default — ACCORDION: click the row to expand/collapse its children inline
164
+ * (below the row, in the same panel); the trailing chevron rotates 90°.
165
+ *
166
+ * `flyout` — the submenu opens BESIDE the row, the way a desktop menu bar does
167
+ * (MenuDropdownNestFlyout, kol-fxr 2026-10-13 — the editor's Affinity-style
168
+ * bar: Tools › Generative › Loops › Field › preset). Hover opens, leaving the
169
+ * row and its panel closes, a click toggles (touch), → opens and ← closes from
170
+ * the keyboard. The panel is a DOM CHILD of the row, never a portal: MenuItem
171
+ * closes on a click bubbling from `[data-menu-item]` and dismisses on an outside
172
+ * press, so a portalled panel would read as "outside" and close the menu under
173
+ * the pointer. One measure on open keeps it on screen — lifted to end above the
174
+ * window's foot (never past its head), flipped to the row's left when it would
175
+ * cross the right edge. Flyouts nest to any depth.
176
+ *
177
+ * `scroll` (flyout only) — caps the panel at 60vh and scrolls it, for long leaf
178
+ * lists. A scrolling panel clips its own flyouts, so give it to a panel with no
179
+ * flyouts inside.
180
+ *
181
+ * Either way, a leaf MenuDropdownItem inside still closes the whole menu via the
182
+ * standard data-menu-item bubble; the nest row itself only toggles.
166
183
  */
167
- export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
184
+ export function MenuDropdownNest({ prefix, iconLeft, label, disabled, flyout = false, scroll = false, children }) {
185
+ if (flyout) return <MenuFlyoutNest prefix={prefix} iconLeft={iconLeft} label={label} disabled={disabled} scroll={scroll}>{children}</MenuFlyoutNest>
186
+ return <MenuAccordionNest prefix={prefix} iconLeft={iconLeft} label={label} disabled={disabled}>{children}</MenuAccordionNest>
187
+ }
188
+
189
+ const NEST_ROW = 'kol-menu-btn w-full kol-helper-12 px-3 h-8 shrink-0 flex items-center gap-2 text-left disabled:opacity-40 disabled:cursor-not-allowed'
190
+
191
+ function NestRowBody({ prefix, iconLeft, label }) {
192
+ return (
193
+ <>
194
+ {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
195
+ {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
196
+ {/* leading-normal — same descender fix as MenuDropdownItem above. */}
197
+ <span className="flex-1 truncate leading-normal">{label}</span>
198
+ </>
199
+ )
200
+ }
201
+
202
+ function MenuAccordionNest({ prefix, iconLeft, label, disabled, children }) {
168
203
  const [open, setOpen] = useState(false)
169
204
  return (
170
205
  <>
@@ -172,12 +207,10 @@ export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
172
207
  type="button"
173
208
  onClick={() => setOpen((v) => !v)}
174
209
  aria-expanded={open}
175
- className="kol-menu-btn w-full kol-helper-12 px-3 h-8 inline-flex items-center gap-2 text-body hover:text-emphasis text-left"
210
+ disabled={disabled}
211
+ className={`${NEST_ROW} text-body hover:text-emphasis`}
176
212
  >
177
- {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
178
- {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
179
- {/* leading-normal — same descender fix as MenuDropdownItem above. */}
180
- <span className="flex-1 truncate leading-normal">{label}</span>
213
+ <NestRowBody prefix={prefix} iconLeft={iconLeft} label={label} />
181
214
  <Icon
182
215
  name="chevron-down"
183
216
  size={10}
@@ -193,3 +226,61 @@ export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
193
226
  </>
194
227
  )
195
228
  }
229
+
230
+ function MenuFlyoutNest({ prefix, iconLeft, label, disabled, scroll, children }) {
231
+ const [open, setOpen] = useState(false)
232
+ const [fit, setFit] = useState({ dy: 0, flip: false })
233
+ const row = useRef(null)
234
+ const panel = useRef(null)
235
+
236
+ useLayoutEffect(() => {
237
+ if (!open) { setFit({ dy: 0, flip: false }); return }
238
+ const r = panel.current?.getBoundingClientRect()
239
+ /* lift it to end above the window's foot, never past its head — a panel taller than the
240
+ * window keeps its top rows (`scroll` is the answer for a long one) */
241
+ if (r) setFit({ dy: Math.max(8 - r.top, Math.min(0, window.innerHeight - 8 - r.bottom)), flip: r.right > window.innerWidth - 8 })
242
+ }, [open])
243
+
244
+ return (
245
+ <div
246
+ className="relative"
247
+ onPointerEnter={() => !disabled && setOpen(true)}
248
+ onPointerLeave={() => setOpen(false)}
249
+ onKeyDown={(e) => {
250
+ if (e.key === 'ArrowLeft' && open) { e.stopPropagation(); setOpen(false); row.current?.focus() }
251
+ }}
252
+ >
253
+ <button
254
+ ref={row}
255
+ type="button"
256
+ role="menuitem"
257
+ aria-haspopup="menu"
258
+ aria-expanded={open}
259
+ disabled={disabled}
260
+ onClick={() => setOpen((v) => !v)}
261
+ onKeyDown={(e) => {
262
+ if (e.key === 'ArrowRight') {
263
+ e.preventDefault()
264
+ setOpen(true)
265
+ requestAnimationFrame(() => panel.current?.querySelector('button:not(:disabled)')?.focus())
266
+ }
267
+ }}
268
+ className={`${NEST_ROW} ${open ? 'text-emphasis' : 'text-body hover:text-emphasis'}`}
269
+ >
270
+ <NestRowBody prefix={prefix} iconLeft={iconLeft} label={label} />
271
+ <Icon name="chevron-right" size={10} className="text-emphasis shrink-0" />
272
+ </button>
273
+ {open && (
274
+ /* top -5 = the panel's 1px border + 4px pad, so its first row sits on the trigger row */
275
+ <div
276
+ ref={panel}
277
+ role="menu"
278
+ className={`absolute ${fit.flip ? 'right-full' : 'left-full'} flex flex-col w-max min-w-[180px] max-w-[320px] py-1 bg-surface-secondary rounded border border-oq-08 shadow-lg z-10 ${scroll ? 'max-h-[60vh] overflow-y-auto' : ''}`}
279
+ style={{ top: -5 + fit.dy }}
280
+ >
281
+ {children}
282
+ </div>
283
+ )}
284
+ </div>
285
+ )
286
+ }
@@ -47,7 +47,7 @@ import { glyphSize } from '../hooks/glyphLadders.js'
47
47
  * `icon` and `shortcut` rows, which any menu wants.
48
48
  *
49
49
  * @param {Object} props
50
- * @param {{id: string, label: string, icon: string, shortcut?: string}[]} props.variants - Variants: menu rows + trigger glyph
50
+ * @param {{id: string, label: string, icon: string, shortcut?: string, disabled?: boolean}[]} props.variants - Variants: menu rows + trigger glyph. A `disabled` row is drawn greyed, never hidden; its click does nothing and the fold stays open
51
51
  * @param {string} props.value - Active variant id (controlled)
52
52
  * @param {Function} props.onChange - Fires with a variant id — on menu pick, and on trigger click while inactive (arming)
53
53
  * @param {string} props.lastPicked - Variant id the trigger shows while the group is inactive (default: variants[0])
@@ -55,7 +55,7 @@ import { glyphSize } from '../hooks/glyphLadders.js'
55
55
  * @param {'xs'|'sm'|'md'|'lg'} props.size - Trigger box on the pinned-square ladder — 22 · 26 · 32 · 40 (default: 'md'). The glyph follows the SOLO ladder; it is never set at the call site
56
56
  * @param {boolean} props.blurOnClick - Blur the trigger after click so a canvas can reclaim focus and refresh its cursor (default: false)
57
57
  * @param {Function} props.onTrigger - Replaces the trigger's arm: fires with the trigger variant's id on every click. For a fold of one-shot ACTIONS (Boolean: the trigger re-runs the last-picked op) — no pressed state is implied (default: arm via `onChange`)
58
- * @param {boolean} props.disabled - Disables the trigger — `.kol-btn:disabled` dims it (default: false)
58
+ * @param {boolean} props.disabled - Disarms the trigger's ACTION and dims it; the fold still opens, so what the tool offers stays visible (SplitToolButtonFoldAlwaysOpens, kol-fxr 2026-10-13 — user: *"even if nothing is applicable shouldn't it still show what's available"*). Grey the rows that do not apply with `variants[].disabled` (default: false)
59
59
  * @param {ElementType} props.iconComponent - Glyph renderer receiving `{ name, size, className, style }` — Button's seam (default: DS `Icon`)
60
60
  * @param {string} props.aria-label - Trigger label fallback when no variant resolves
61
61
  *
@@ -108,12 +108,14 @@ const SplitToolButton = ({
108
108
  /* Arm the last-picked variant on the same click that toggles the menu —
109
109
  * floating-ui's useClick (on the reference) handles the open/close half. */
110
110
  const handleTriggerClick = (event) => {
111
+ if (disabled) return
111
112
  if (onTrigger) { if (triggerVariant) onTrigger(triggerVariant.id) }
112
113
  else if (!active && triggerVariant) onChange?.(triggerVariant.id)
113
114
  if (blurOnClick) event.currentTarget.blur()
114
115
  }
115
116
 
116
117
  const handleSelect = (variant) => {
118
+ if (variant.disabled) return
117
119
  if (variant.onSelect) variant.onSelect()
118
120
  else { onChange?.(variant.id); setOwnLast(variant.id) }
119
121
  setOpen(false)
@@ -127,7 +129,9 @@ const SplitToolButton = ({
127
129
  {...popover.getReferenceProps({ onClick: handleTriggerClick })}
128
130
  type="button"
129
131
  className={`relative kol-btn kol-btn-ghost kol-btn-icon kol-btn-${size} ${active ? 'kol-btn-pressed' : 'kol-btn-quiet'} ${className}`.trim()}
130
- disabled={disabled}
132
+ /* NOT the `disabled` attribute — that kills the click that opens the fold. Dimmed inline so
133
+ * it outranks the tool palette's `.kol-btn-quiet { opacity: 1 }`. */
134
+ style={disabled ? { opacity: 'var(--kol-opacity-disabled)' } : undefined}
131
135
  aria-pressed={onTrigger ? undefined : active}
132
136
  aria-label={label}
133
137
  >
@@ -148,8 +152,11 @@ const SplitToolButton = ({
148
152
  <button
149
153
  key={variant.id}
150
154
  type="button"
155
+ disabled={variant.disabled}
151
156
  onClick={() => handleSelect(variant)}
152
- className="w-full kol-helper-12 px-3 h-8 inline-flex items-center gap-2 text-body hover:text-emphasis text-left"
157
+ /* `flex`, not `inline-flex` — inline rows in this `w-max` panel measured as one line,
158
+ * as wide as the canvas (MenuDropdownItemBlockRow's fix, 0.252.0, applied here) */
159
+ className="w-full kol-helper-12 px-3 h-8 flex items-center gap-2 text-body hover:text-emphasis disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:text-body text-left"
153
160
  >
154
161
  <span className="shrink-0 w-4 inline-flex items-center justify-center">
155
162
  <IconC name={variant.icon} size={14} />
@@ -81,7 +81,8 @@ export function HighlightMatch({ label, query, ranges }) {
81
81
  * the search modal opens on somewhere to go, not a blank box
82
82
  * @param {string} query controlled query (drives the highlight slice)
83
83
  * @param {Function} onQueryChange (string) => void — input change
84
- * @param {Function} onSelect (item) => void — row click / Enter; consumer navigates
84
+ * @param {Function} onSelect (item) => void — row click / Enter; consumer navigates. A row
85
+ * with `keepOpen` or `action` selects and the modal stays open
85
86
  * @param {string} placeholder input placeholder
86
87
  * @param {string} [enterLabel] what Enter does when no row is picked — shown as
87
88
  * the panel's last line, so Enter is never a surprise
@@ -137,8 +138,12 @@ export default function ShellSearchOverlay({
137
138
  return () => { if (prev instanceof HTMLElement) prev.focus() }
138
139
  }, [open])
139
140
 
140
- /* Roving row resets to the top on every query change / reopen. */
141
- useEffect(() => { setActiveIndex(0); setNavigated(false) }, [query, open])
141
+ /* Roving row resets to the top on every query change / reopen — and when the ROWS change under an
142
+ * unchanged query (ShellSearchOverlayActionKeepsOpen, kol-fxr 2026-10-13: a drill-in swaps the
143
+ * suggestions for a category's presets). Keyed on the row ids, not the array's identity, so a
144
+ * consumer passing a fresh array every render does not snap the highlight back to the top. */
145
+ const rowsKey = results.map((r) => r.id).join('\u0000')
146
+ useEffect(() => { setActiveIndex(0); setNavigated(false) }, [query, open, rowsKey])
142
147
 
143
148
  /* Keep the active row visible inside the scrolling list. */
144
149
  useEffect(() => {
@@ -148,9 +153,13 @@ export default function ShellSearchOverlay({
148
153
 
149
154
  if (!open) return null
150
155
 
156
+ /* A row that KEEPS THE MODAL OPEN — `keepOpen`, or an `action` row (the contract below always said
157
+ * so; until 0.252.0 every pick closed — ShellSearchOverlayActionKeepsOpen, kol-fxr 2026-10-13). It
158
+ * still reaches `onSelect`, and the closure stays the consumer's to run there: the overlay running
159
+ * it too would fire it twice in every shell that already does (workshop's tag rows). */
151
160
  const select = (item) => {
152
161
  onSelect?.(item)
153
- onClose?.()
162
+ if (!(item?.keepOpen || typeof item?.action === 'function')) onClose?.()
154
163
  }
155
164
 
156
165
  const optionId = (item) => `${listId}-${item.id}`
@@ -248,7 +257,9 @@ export default function ShellSearchOverlay({
248
257
  * icon optional leading glyph (kol-icons name)
249
258
  * hint subtext shown when the LABEL was not what matched
250
259
  * href a destination; dismisses the search modal
251
- * action a closure; runs and KEEPS the search modal open (tag rows)
260
+ * action a closure, run by the consumer's `onSelect`; the search modal STAYS OPEN (tag rows)
261
+ * keepOpen the row selects and the search modal STAYS OPEN — a drill-in (category →
262
+ * its items, a "← All" row back); the consumer swaps `suggestions`/`results`
252
263
  * Built by `buildShellSearchItems` (showcase/src/nav/shell-nav.js). */}
253
264
  {expanded ? (
254
265
  <div className="border-t border-fg-08 max-h-[70vh] overflow-y-auto">{children}</div>
@@ -34,8 +34,14 @@ import { Tooltip } from '../utilities/Popover.jsx'
34
34
  * unaffected.
35
35
  *
36
36
  * The label also counter-SCALES rather than just re-sizing: `scale(1/zoom)`
37
- * with a top-left origin keeps its padding, radius and letter-spacing
38
- * screen-constant too, which a font-size alone does not.
37
+ * keeps its padding, radius and letter-spacing screen-constant too, which a
38
+ * font-size alone does not.
39
+ *
40
+ * THE LABEL DOES NOT ROTATE (SelectionOverlayLabelUpright, kol-fxr 2026-10-13 —
41
+ * user: *"the size here glued to the side is so small it can't be read"*). It
42
+ * sits outside the rotated chrome, upright and centred under the rotated box's
43
+ * BOUNDS — Figma's chip — so at −90° it reads below the box instead of standing
44
+ * on end against its side. 12px.
39
45
  *
40
46
  * @param {{x:number,y:number,w:number,h:number,rotation?:number}} box virtual-coord position + size; null/x==null → renders nothing. `rotation` in degrees turns the chrome with the box about its centre
41
47
  * @param {boolean} showHandles render the 8 resize handles (default true)
@@ -86,8 +92,12 @@ export default function SelectionOverlay({
86
92
  * the base 0 rather than throwing on `${{…}}deg` — editing chrome over
87
93
  * animated transforms is a consumer-side v1 limitation, and fxr's guard. */
88
94
  const rot = typeof box.rotation === 'number' ? box.rotation : 0
95
+ /* half the rotated box's axis-aligned height — the label hangs below that, centred */
96
+ const rad = (rot * Math.PI) / 180
97
+ const halfBoundsH = (Math.abs(w * Math.sin(rad)) + Math.abs(h * Math.cos(rad))) / 2
89
98
 
90
99
  return (
100
+ <>
91
101
  <div
92
102
  style={{
93
103
  position: 'absolute',
@@ -146,19 +156,19 @@ export default function SelectionOverlay({
146
156
  }}
147
157
  />
148
158
  ))}
159
+ </div>
149
160
  {showLabel && (
150
161
  <span
151
162
  style={{
152
163
  position: 'absolute',
153
- left: 0,
154
- top: '100%',
155
- marginTop: 6 / zoom,
164
+ left: x + w / 2,
165
+ top: y + h / 2 + halfBoundsH + 6 / zoom,
156
166
  /* counter-scale, not just a smaller font: padding, radius and
157
167
  * tracking have to stay screen-constant too */
158
- transform: `scale(${1 / zoom})`,
159
- transformOrigin: 'top left',
168
+ transform: `translateX(-50%) scale(${1 / zoom})`,
169
+ transformOrigin: 'top center',
160
170
  fontFamily: 'var(--kol-font-family-mono)',
161
- fontSize: 10,
171
+ fontSize: 12,
162
172
  letterSpacing: '0.04em',
163
173
  color: accentColor,
164
174
  background: 'rgba(0,0,0,0.6)', /* a label chip on a canvas, not a scrim (sweep 2026-09-03) */
@@ -166,11 +176,12 @@ export default function SelectionOverlay({
166
176
  borderRadius: 2,
167
177
  whiteSpace: 'nowrap',
168
178
  pointerEvents: 'none',
179
+ zIndex: 100,
169
180
  }}
170
181
  >
171
182
  {labelFormatter(box)}
172
183
  </span>
173
184
  )}
174
- </div>
185
+ </>
175
186
  )
176
187
  }