@kolkrabbi/kol-component 0.338.1 → 0.339.1

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.338.1",
3
+ "version": "0.339.1",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,8 +29,8 @@
29
29
  "embla-carousel-react": "^8.6.0",
30
30
  "pdfjs-dist": "^6.3.289",
31
31
  "react-syntax-highlighter": "^16.1.1",
32
- "@kolkrabbi/kol-search": "^0.3.0",
33
32
  "@kolkrabbi/kol-markdown": "^0.2.0",
33
+ "@kolkrabbi/kol-search": "^0.3.0",
34
34
  "@kolkrabbi/kol-growth": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -0,0 +1,65 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ /**
4
+ * useRailKeys — one keyboard rule for every nav rail (RailShortcutsAllFrames, kol-website 2026-11-04 — user: *"shortcut
5
+ * to collapse expand hide? the studio nav had '\'? … that should also go for site and app rail"*). AppShell, SiteLayout
6
+ * and FloatLayout each call it with their own state setters; the hook owns only the keys.
7
+ *
8
+ * `\` expanded ↔ collapsed → `onCollapse()`
9
+ * `⇧\` hide ↔ show → `onHide()` (the frame restores the state the rail had)
10
+ *
11
+ * Ignored while typing (input, textarea, select, contenteditable), on key repeat, and with ⌘ / ⌃ / ⌥ held. Matched on
12
+ * `e.key` OR the physical key (`e.code`), because ⇧\ yields `|` as `e.key` on a US layout.
13
+ *
14
+ * @param {false|{ collapse?: string|false, hide?: string|false }} [keys] `false` turns both off; an object rebinds
15
+ * either (merged over RAIL_KEYS; a falsy entry turns that one off). A key is `'\\'` or `'shift+\\'`. When both name the
16
+ * same key, `hide` wins — AppShell's `railToggleKey` alias relies on it.
17
+ * @param {{ onCollapse?: Function, onHide?: Function }} handlers
18
+ */
19
+ export const RAIL_KEYS = { collapse: '\\', hide: 'shift+\\' }
20
+
21
+ const CODE_FOR_KEY = { '\\': 'Backslash', '/': 'Slash', ',': 'Comma', '.': 'Period', ';': 'Semicolon', '[': 'BracketLeft', ']': 'BracketRight', '`': 'Backquote' }
22
+
23
+ const parse = (spec) => {
24
+ const shift = /^shift\+/i.test(spec)
25
+ return { shift, key: shift ? spec.slice(6) : spec }
26
+ }
27
+
28
+ const matches = (e, spec) => {
29
+ if (!spec) return false
30
+ const { shift, key } = parse(spec)
31
+ return e.shiftKey === shift && (e.key === key || (CODE_FOR_KEY[key] != null && e.code === CODE_FOR_KEY[key]))
32
+ }
33
+
34
+ const resolve = (keys) => (keys === false ? null : { ...RAIL_KEYS, ...(keys ?? {}) })
35
+
36
+ /* the two keys as a shortcuts section (`[{ section, items }]`), for a frame that draws a keymap — empty when off */
37
+ export const railShortcuts = (keys) => {
38
+ const k = resolve(keys)
39
+ if (!k) return []
40
+ const label = (spec) => (parse(spec).shift ? `⇧ ${parse(spec).key}` : spec)
41
+ const items = [
42
+ k.collapse && { id: 'rail-collapse', label: 'Expand / collapse the rail', combo: label(k.collapse) },
43
+ k.hide && { id: 'rail-hide', label: 'Hide / show the rail', combo: label(k.hide) },
44
+ ].filter(Boolean)
45
+ return items.length ? [{ section: 'Rail', items }] : []
46
+ }
47
+
48
+ export default function useRailKeys(keys, handlers) {
49
+ const live = useRef(null)
50
+ live.current = { keys: resolve(keys), ...handlers }
51
+ useEffect(() => {
52
+ const onKey = (e) => {
53
+ const { keys: k, onCollapse, onHide } = live.current
54
+ if (!k || e.repeat || e.metaKey || e.ctrlKey || e.altKey) return
55
+ const t = e.target
56
+ if (t?.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t?.tagName)) return
57
+ const fn = matches(e, k.hide) ? onHide : matches(e, k.collapse) ? onCollapse : null
58
+ if (!fn) return
59
+ e.preventDefault()
60
+ fn()
61
+ }
62
+ window.addEventListener('keydown', onKey)
63
+ return () => window.removeEventListener('keydown', onKey)
64
+ }, [])
65
+ }
package/src/index.js CHANGED
@@ -352,6 +352,9 @@ export { default as useHistory } from './hooks/useHistory.js'
352
352
  * `EditorShell` needs resizable rails and cannot import framework. framework
353
353
  * re-exports it, so no consumer specifier changed. */
354
354
  export { default as useDragResize } from './hooks/useDragResize.js'
355
+ /* one keyboard rule for every nav rail — `\` expand ↔ collapse, `⇧\` hide ↔ show (RailShortcutsAllFrames, 2026-11-04);
356
+ * AppShell, FloatLayout and kol-framework's SiteLayout call it with their own setters */
357
+ export { default as useRailKeys, RAIL_KEYS, railShortcuts } from './hooks/useRailKeys.js'
355
358
  export { default as usePlaceholders } from './hooks/usePlaceholders.js'
356
359
  export { resolveCssVar, resolveCssColor, isLight } from './hooks/cssVar.js'
357
360
 
@@ -103,6 +103,9 @@ import NavRailFloat from './NavRailFloat.jsx'
103
103
  * (2026-10-01), here too on the user's word (2026-10-02). The rows sit in their own scroll
104
104
  * region between the mark and the pinned bottom rows, so a list longer than the window scrolls
105
105
  * and runs out under the fade instead of being cut by the edge. `false` draws the list plain.
106
+ * @param {{ current: Function }} [toggleRef] the app and site rails fill it with their expand ↔ collapse toggle — the
107
+ * frame's `\` key (useRailKeys, 2026-11-04) presses it. The app rail's also carries `open` and `snap(open)`, so AppShell
108
+ * can bring it back from a hide as it was
106
109
  */
107
110
  const RAIL_W = '--kol-shell-rail-width'
108
111
  const CLOSED = 48
@@ -158,7 +161,10 @@ function useRailDrag(railRef, grabRef, onSnap, snapRef, enabled = true) {
158
161
  const report = (w) => { const on = w >= RAIL_LABELS; if (on !== labelled) { labelled = on; onSnap(on) } }
159
162
  const snapTo = (w) => {
160
163
  gsap.to(root, { [RAIL_W]: `${w}px`, ...GRAB.snap, overwrite: 'auto' })
161
- report(w)
164
+ /* a snap always reports — a remount (StrictMode's second effect, AppShell's show-as-it-was) can leave this closure's
165
+ * `labelled` behind the rail's state, and a deduped report then never closed it */
166
+ labelled = w >= RAIL_LABELS
167
+ onSnap(labelled)
162
168
  }
163
169
  /* the ONLY way out of this effect (RailSectionPressOpensRail, kol-fxr
164
170
  * 2026-08-30). `snapTo` closes over the animation and the CLOSED/open
@@ -375,6 +381,7 @@ function AppRail({
375
381
  drawer = false,
376
382
  fade = true,
377
383
  sections = 'expand',
384
+ toggleRef,
378
385
  }) {
379
386
  const railRef = useRef(null)
380
387
  const grabRef = useRef(null)
@@ -403,6 +410,8 @@ function AppRail({
403
410
  * and it no-ops on its own — no second argument needed */
404
411
  useGrabEdge(grabRef)
405
412
  useRailDrag(railRef, grabRef, setRailOpen, snapOpenRef, !drawer)
413
+ /* the frame's `\` key (useRailKeys) — the grab strip's own click: expanded ↔ collapsed */
414
+ if (toggleRef) toggleRef.current = Object.assign(() => snapOpenRef.current?.(!railOpen), { open: railOpen, snap: (o) => snapOpenRef.current?.(o) })
406
415
  if (hidden) return null
407
416
  const enterMode = (sections === 'fold' ? 'expand' : sections) === 'enter'
408
417
  const enters = (item) => enterMode && !!item.sub?.some((s) => s.sub?.length > 0)
@@ -19,7 +19,8 @@ import { Tooltip } from '../utilities/Popover.jsx'
19
19
  * section with the current page inside lights too; a heading becomes a 16 gap. Expand on top and search ·
20
20
  * hide at the foot, on the well. Each slot names itself in the float Tooltip
21
21
  *
22
- * On `surface-secondary` at the sheet radius, 12 in, full height of its container. Nothing auto-expands: a section
22
+ * On `surface-secondary` lifted by the float shadow (`--kol-shadow-float`, the pill's and the card's — FloatRailOverlayShadowRestore,
23
+ * 2026-11-04) at the sheet radius, 12 in, full height of its container. Nothing auto-expands: a section
23
24
  * opens by its chevron, or by `defaultExpanded`.
24
25
  *
25
26
  * @param {Array} items `{ heading }` | `{ icon, label, path, count?, sub?: [{ icon, label, path, count? }] }`
@@ -51,7 +52,7 @@ export default function NavRailFloat({ items = [], currentPath = '', onNavigate,
51
52
  </Tooltip>
52
53
  )
53
54
  return (
54
- <nav aria-label="Navigation" className={`flex h-full w-[72px] flex-col items-center gap-1 rounded-[var(--kol-float-menu-r)] bg-surface-secondary py-3.5 ${className}`.trim()}>
55
+ <nav aria-label="Navigation" className={`flex h-full w-[72px] flex-col items-center gap-1 rounded-[var(--kol-float-menu-r)] bg-surface-secondary shadow-[var(--kol-shadow-float)] py-3.5 ${className}`.trim()}>
55
56
  {onCollapsedChange && slot('expand', 'Expand', 'panel-left', { well: true, onClick: () => onCollapsedChange(false) })}
56
57
  <div className="flex min-h-0 w-full flex-1 flex-col items-center gap-1 overflow-y-auto py-3 [scrollbar-width:none]">
57
58
  {items.map((it, i) => {
@@ -73,7 +74,7 @@ export default function NavRailFloat({ items = [], currentPath = '', onNavigate,
73
74
  }
74
75
 
75
76
  return (
76
- <nav aria-label="Navigation" className={`flex h-full w-[280px] flex-col gap-3 rounded-[var(--kol-float-menu-r)] bg-surface-secondary p-3 ${className}`.trim()}>
77
+ <nav aria-label="Navigation" className={`flex h-full w-[280px] flex-col gap-3 rounded-[var(--kol-float-menu-r)] bg-surface-secondary shadow-[var(--kol-shadow-float)] p-3 ${className}`.trim()}>
77
78
  {switcher ?? (title && (
78
79
  <button type="button" onClick={onSwitch} className="flex h-10 w-full items-center gap-2.5 rounded-[var(--kol-float-list-r)] px-2.5 text-left cursor-pointer hover:bg-fg-08 focus-visible:outline-none focus-visible:shadow-[var(--kol-float-focus)]">
79
80
  <Icon name={icon} size={18} className="shrink-0 text-oq-96" />
@@ -124,6 +124,7 @@ import useScrollFade from '../hooks/useScrollFade.js'
124
124
  * ruling "pressing any icon would expand the sidebar"): a
125
125
  * collapsed rail stays collapsed, the press does its job
126
126
  * `defaultCollapsed` boots collapsed when nothing is stored (useDragResize)
127
+ * `toggleRef` filled with the collapse toggle — SiteLayout's `\` key (useRailKeys) presses it
127
128
  * THE RAIL'S BEHAVIOURS ARE PROPS (SiteRailTitleNavigatesOnly, kol-branding 2026-10-27 — user: "clicking on title
128
129
  * shouldnt also expand, that is what the chevron is for", and: a small rail behaviour should never need a ticket here —
129
130
  * a sensible default plus a prop the consumer sets in its own repo):
@@ -244,6 +245,7 @@ export default function NavRailSite({
244
245
  iconSize: iconSizes,
245
246
  alignIcons = true,
246
247
  collapsedIcons = 'category',
248
+ toggleRef,
247
249
  }) {
248
250
  /* the row props' resolvers (NavRailRowProps) — '' at a level's own look, so the classes stay as they were */
249
251
  const caseCls = (node, level) => {
@@ -317,6 +319,8 @@ export default function NavRailSite({
317
319
  * drive it. */
318
320
  const asideRef = useRef(null)
319
321
  const { collapsed, toggleCollapsed, grabProps } = useDragResize(asideRef, { defaultCollapsed })
322
+ /* the frame's `\` key (useRailKeys) reaches the collapse through this — the same toggle the grab edge presses */
323
+ if (toggleRef) toggleRef.current = toggleCollapsed
320
324
 
321
325
  /* the panel's anchor: its row — the panel's bottom edge meets the row's top
322
326
  * edge, its width is the rail's; re-placed on resize and on collapse */