@kolkrabbi/kol-component 0.338.0 → 0.339.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.338.0",
3
+ "version": "0.339.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,9 +29,9 @@
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-growth": "^0.5.0",
32
33
  "@kolkrabbi/kol-markdown": "^0.2.0",
33
- "@kolkrabbi/kol-search": "^0.3.0",
34
- "@kolkrabbi/kol-growth": "^0.5.0"
34
+ "@kolkrabbi/kol-search": "^0.3.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@kolkrabbi/kol-icons": ">=0.61.1",
@@ -167,7 +167,8 @@ export default function useDragResize(ref, options = {}) {
167
167
  * `grabProps`, so a consumer already spreading those gets the wake, the
168
168
  * travel and the dwell with no change. */
169
169
  const grabRef = useRef(null)
170
- useGrabEdge(grabRef)
170
+ /* a top/bottom Rail's handle is a horizontal edge: near on y, pill travels on x (DragResizeBottomWake, 2026-11-04) */
171
+ useGrabEdge(grabRef, { axis: vertical ? 'x' : 'y' })
171
172
  const drag = useRef(null) // { startX, startW, snapPx, maxPx, moved } during a drag
172
173
  const defaultPx = useRef(null)
173
174
  const collapsedPx = useRef(null)
@@ -331,7 +332,7 @@ export default function useDragResize(ref, options = {}) {
331
332
  className: line ? 'kol-rail-grab kol-rail-grab--line' : 'kol-rail-grab',
332
333
  ...(line ? { onDoubleClick: toggleCollapsed } : {}),
333
334
  role: 'separator',
334
- 'aria-orientation': 'vertical',
335
+ 'aria-orientation': vertical ? 'horizontal' : 'vertical',
335
336
  'aria-label': 'Resize navigation',
336
337
  'aria-valuenow': Math.round(collapsed ? collapsedPx.current : (widthPx ?? defaultPx.current)) || undefined,
337
338
  'aria-valuemin': collapsedPx.current == null ? undefined : Math.round(collapsedPx.current),
@@ -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,8 @@ 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
106
108
  */
107
109
  const RAIL_W = '--kol-shell-rail-width'
108
110
  const CLOSED = 48
@@ -375,6 +377,7 @@ function AppRail({
375
377
  drawer = false,
376
378
  fade = true,
377
379
  sections = 'expand',
380
+ toggleRef,
378
381
  }) {
379
382
  const railRef = useRef(null)
380
383
  const grabRef = useRef(null)
@@ -403,6 +406,8 @@ function AppRail({
403
406
  * and it no-ops on its own — no second argument needed */
404
407
  useGrabEdge(grabRef)
405
408
  useRailDrag(railRef, grabRef, setRailOpen, snapOpenRef, !drawer)
409
+ /* the frame's `\` key (useRailKeys) — the grab strip's own click: expanded ↔ collapsed */
410
+ if (toggleRef) toggleRef.current = () => snapOpenRef.current?.(!railOpen)
406
411
  if (hidden) return null
407
412
  const enterMode = (sections === 'fold' ? 'expand' : sections) === 'enter'
408
413
  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 */