@kolkrabbi/kol-component 0.377.0 → 0.379.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 +5 -4
- package/src/atoms/BezierPathEditor.jsx +1 -1
- package/src/atoms/Button.jsx +84 -1
- package/src/atoms/Figure.jsx +19 -1
- package/src/atoms/FunctionPlot.jsx +1 -1
- package/src/atoms/Input.jsx +105 -1
- package/src/atoms/Kbd.jsx +42 -2
- package/src/atoms/Link.jsx +20 -0
- package/src/atoms/OriginPicker.jsx +9 -5
- package/src/atoms/SectionFooter.jsx +22 -0
- package/src/atoms/SectionHeader.jsx +24 -0
- package/src/atoms/SizeOrDownload.jsx +1 -1
- package/src/atoms/Textarea.jsx +11 -2
- package/src/atoms/ToggleCheckbox.jsx +23 -1
- package/src/atoms/ToggleSwitch.jsx +39 -0
- package/src/atoms/ViewToggle.jsx +2 -2
- package/src/atoms/XYPad.jsx +25 -0
- package/src/hooks/useDragResize.js +1 -1
- package/src/index.js +26 -3
- package/src/molecules/AccountMenu.jsx +14 -1
- package/src/molecules/AlignmentGrid.jsx +13 -1
- package/src/molecules/ButtonGroup.jsx +73 -1
- package/src/molecules/ButtonSplit.jsx +64 -3
- package/src/molecules/Chip.jsx +26 -0
- package/src/molecules/CodeBlock.jsx +39 -2
- package/src/molecules/ColorInputRow.jsx +125 -4
- package/src/molecules/ColorSwatch.jsx +43 -2
- package/src/molecules/ContentCard.jsx +104 -3
- package/src/molecules/ContentMedia.jsx +1 -1
- package/src/molecules/ContentRow.jsx +3 -3
- package/src/molecules/DividerLabel.jsx +19 -0
- package/src/molecules/Dropdown.jsx +111 -1
- package/src/molecules/DropdownStepper.jsx +29 -0
- package/src/molecules/FieldPair.jsx +41 -2
- package/src/molecules/Header.jsx +8 -4
- package/src/molecules/LabeledControl.jsx +51 -0
- package/src/molecules/Menu.jsx +239 -3
- package/src/molecules/Modal.jsx +216 -10
- package/src/molecules/ModalShell.jsx +21 -8
- package/src/molecules/OptionRow.jsx +1 -1
- package/src/molecules/ParamBindDot.jsx +29 -2
- package/src/molecules/QuantityInput.jsx +48 -0
- package/src/molecules/RailFloat.jsx +4 -3
- package/src/molecules/RailHeader.jsx +32 -2
- package/src/molecules/SectionText.jsx +54 -1
- package/src/molecules/Slider.jsx +101 -2
- package/src/molecules/SplitToolButton.jsx +4 -6
- package/src/molecules/SwatchControls.jsx +28 -0
- package/src/molecules/SwatchGrid.jsx +39 -0
- package/src/molecules/TabsDocument.jsx +131 -0
- package/src/molecules/TabsRow.jsx +35 -1
- package/src/molecules/Toast.jsx +55 -0
- package/src/molecules/TreeRow.jsx +87 -1
- package/src/organisms/AppItemMenuProvider.jsx +2 -2
- package/src/organisms/ColorPickerPopover.jsx +133 -4
- package/src/organisms/ColumnBrowser.jsx +1 -1
- package/src/organisms/CommandOverlay.jsx +396 -21
- package/src/organisms/FindBar.jsx +70 -0
- package/src/organisms/FramedMediaBand.jsx +2 -2
- package/src/organisms/GalleryCarousel.jsx +1 -1
- package/src/organisms/LogoSystem.jsx +38 -0
- package/src/organisms/LogoTuner.jsx +32 -0
- package/src/organisms/MediaLibrary.jsx +1 -1
- package/src/organisms/MediaLibraryPages.jsx +1 -1
- package/src/organisms/Rail.jsx +33 -1
- package/src/organisms/RailSwitcher.jsx +62 -0
- package/src/organisms/ReadingContents.jsx +63 -1
- package/src/organisms/SectionSplit.jsx +1 -1
- package/src/organisms/SettingsPanel.jsx +64 -6
- package/src/organisms/ShortcutsOverlay.jsx +46 -2
- package/src/organisms/SpectrumControls.jsx +112 -19
- package/src/organisms/StatusBar.jsx +30 -0
- package/src/organisms/Table.jsx +141 -2
- package/src/organisms/TimelineDock.jsx +281 -1
- package/src/organisms/logoBoard.jsx +61 -0
- package/src/utilities/AssetPlaceholder.jsx +1 -1
- package/src/utilities/EditorShell.jsx +42 -1
- package/src/utilities/OverlayGlassPanel.jsx +1 -1
- package/src/utilities/Popover.jsx +298 -2
- package/src/utilities/SelectionOverlay.jsx +74 -1
- package/src/utilities/kolboxGlyph.jsx +10 -0
package/src/molecules/Header.jsx
CHANGED
|
@@ -29,7 +29,8 @@ import Button from '../atoms/Button.jsx'
|
|
|
29
29
|
* @param {'nav'|'property'|'modal'|'settings'} [variant='property']
|
|
30
30
|
* @param {string} [icon] nav · modal: the lead glyph
|
|
31
31
|
* @param {ReactNode} [title] the title slot — text, or a node in the title position
|
|
32
|
-
* @param {ReactNode} [kind] settings: the
|
|
32
|
+
* @param {ReactNode} [kind] settings · property: the quiet second text beside the title (the preset beside the effect —
|
|
33
|
+
* no middot in a title, plan-2026-11-12-one-header W10.1)
|
|
33
34
|
* @param {Function} [onSwitch] nav: the switcher's press; shows the ⌄
|
|
34
35
|
* @param {ReactNode} [end] the end slot — before the toggles
|
|
35
36
|
* @param {Function} [onExpand] · {Function} [onCollapseH] · {boolean} [collapsedV] · {Function} [onCollapseV]
|
|
@@ -50,14 +51,14 @@ export default function Header({ variant = 'property', icon, title, kind, onSwit
|
|
|
50
51
|
const any = end || onExpand || onCollapseH || onCollapseV
|
|
51
52
|
|
|
52
53
|
if (variant === 'settings') return (
|
|
53
|
-
<header className={`flex items-center gap-4 h-[60px] shrink-0 pl-6 pr-[
|
|
54
|
+
<header className={`flex items-center gap-4 h-[60px] shrink-0 pl-6 pr-[15px] border-b border-oq-16 ${className}`.trim()}>
|
|
54
55
|
<h2 className="text-[14px] font-semibold leading-none">{title}</h2>
|
|
55
56
|
{kind && <span className="text-[11px] text-oq-64 leading-none mt-px">{kind}</span>}
|
|
56
57
|
{/* `end`: the header's right side pushed by its own margin, no spacer (LAW 10) */}
|
|
57
58
|
<div className="ml-auto flex items-center gap-4">
|
|
58
59
|
{end}{toggles}
|
|
59
60
|
{onClose && <button type="button" aria-label="Close" onClick={onClose}
|
|
60
|
-
className="ml-3 size-7
|
|
61
|
+
className="ml-3 size-7 inline-flex items-center justify-center rounded-md text-[20px] leading-none text-oq-64 hover:text-(--kol-fg-96) hover:bg-(--kol-oq-08) focus-visible:outline-none focus-visible:shadow-[var(--kol-float-focus)]">×</button>}
|
|
61
62
|
</div>
|
|
62
63
|
</header>
|
|
63
64
|
)
|
|
@@ -86,7 +87,10 @@ export default function Header({ variant = 'property', icon, title, kind, onSwit
|
|
|
86
87
|
<div data-float-module-header="" className={`flex w-full min-w-0 shrink-0 items-center justify-between gap-2 ${className}`.trim()}>
|
|
87
88
|
{slot != null && slot !== false && (isValidElement(slot)
|
|
88
89
|
? <div data-rail-header-title="" className="flex min-w-0 flex-1">{slot}</div>
|
|
89
|
-
:
|
|
90
|
+
: kind != null && kind !== ''
|
|
91
|
+
/* `kind` — the quiet second text beside the title (W10.1: "Drift" + "Storm", never "Drift · Storm") */
|
|
92
|
+
? <span className="flex min-w-0 flex-1 items-baseline gap-2"><span className="kol-float-panel text-emphasis min-w-0 shrink truncate">{slot}</span><span className="kol-float-panel text-oq-64 min-w-0 truncate">{kind}</span></span>
|
|
93
|
+
: <span className="kol-float-panel text-emphasis min-w-0 flex-1 truncate">{slot}</span>)}
|
|
90
94
|
{(any || onClose) && <span className="ml-auto flex shrink-0 items-center gap-1">
|
|
91
95
|
{end}{toggles}
|
|
92
96
|
{onClose && <Button variant="float" tone="ghost" size="sm" iconOnly="x" aria-label="Close" onClick={onClose} />}
|
|
@@ -42,6 +42,15 @@
|
|
|
42
42
|
* `'settings'` (plan-2026-11-12-float-rails-figma W13.1): the generator settings window's row (`Dialog
|
|
43
43
|
* variant="settings"`): the label in Inter 10 at oq-64, 6 over the control; `horizontal` puts it beside the
|
|
44
44
|
* control, 8 apart, the label hugging its text (a `labelWidth` still sets a column).
|
|
45
|
+
* `'kolbox'` (plan-2026-11-18-kolbox-system W31.2, 2026-11-18): kolbox's row carried class for class, the label
|
|
46
|
+
* Inter 12 / 16 medium in oq-64. `horizontal`: the label in a 76 column (a `labelWidth` sets another, 160 for a
|
|
47
|
+
* window's longer labels), 8 from the control, the row at least 28; stacked: the label 4 over a row of controls
|
|
48
|
+
* 4 apart. `controlFirst`: the control at the left, inset 4, then 8 apart the label in Inter 11 / 15, the row as
|
|
49
|
+
* tall as its control. Chrome in kol-theme `.kol-labeled-control--kolbox`.
|
|
50
|
+
* `'folio'` (Folio batch C, 2026-11-22): Folio's Setting carried class for class. Stacked: the label (Folio's
|
|
51
|
+
* label, 10 semibold, tracked, capitals) 8 over the control; `horizontal`: the label (12 / 16 medium) in a 48
|
|
52
|
+
* column, 12 from the control. Both labels in Folio's muted ink. Chrome in kol-theme `.kol-labeled-control--folio`.
|
|
53
|
+
* controlFirst — bool, `kolbox` only: the control before its label (kolbox's Clip content row).
|
|
45
54
|
* labelClass — the label's type and ink, replacing the variant's (a row that keeps its own label look: Slider's
|
|
46
55
|
* kol-helper-12, a toggle's words in the settings ink). On `panel` it defaults to kol-helper-8.
|
|
47
56
|
* children — the control body.
|
|
@@ -66,8 +75,50 @@ export default function LabeledControl({
|
|
|
66
75
|
labelPosition = 'bottom',
|
|
67
76
|
labelClass,
|
|
68
77
|
gap = 0,
|
|
78
|
+
controlFirst = false,
|
|
69
79
|
...rest
|
|
70
80
|
}) {
|
|
81
|
+
if (variant === 'kolbox') {
|
|
82
|
+
const mark = { 'data-labeled-control': '', ...rest }
|
|
83
|
+
if (controlFirst) {
|
|
84
|
+
return (
|
|
85
|
+
<div {...mark} className={`kol-labeled-control--kolbox flex items-center gap-2 pl-1 ${className}`.trim()}>
|
|
86
|
+
{children}
|
|
87
|
+
<span className="kol-labeled-control-help min-w-0 flex-1 truncate">{label}</span>
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
if (!(horizontal ?? inline ?? false)) {
|
|
92
|
+
return (
|
|
93
|
+
<div {...mark} className={`kol-labeled-control--kolbox flex flex-col gap-1 ${className}`.trim()}>
|
|
94
|
+
<span className="kol-labeled-control-label">{label}</span>
|
|
95
|
+
<div className="flex min-w-0 items-center gap-1">{children}</div>
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
<div {...mark} className={`kol-labeled-control--kolbox flex min-h-(--kol-kolbox-ctl) items-center gap-2 ${className}`.trim()}>
|
|
101
|
+
<span className={`kol-labeled-control-label ${labelWidth == null ? 'w-19 ' : ''}shrink-0 truncate`} style={labelWidth == null ? undefined : { width: labelWidth }}>{label}</span>
|
|
102
|
+
<div className="flex min-w-0 flex-1 items-center gap-2">{children}</div>
|
|
103
|
+
</div>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
if (variant === 'folio') {
|
|
107
|
+
if (horizontal ?? inline ?? false) {
|
|
108
|
+
return (
|
|
109
|
+
<div {...rest} className={`kol-labeled-control--folio flex items-center gap-[12px] ${className}`.trim()}>
|
|
110
|
+
<p className="kol-labeled-control-label w-[48px] shrink-0">{label}</p>
|
|
111
|
+
<div className="flex min-w-0 flex-1 items-center">{children}</div>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
return (
|
|
116
|
+
<div {...rest} className={`kol-labeled-control--folio flex flex-col gap-[8px] ${className}`.trim()}>
|
|
117
|
+
<p className="kol-labeled-control-title">{label}</p>
|
|
118
|
+
{children}
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
71
122
|
if (variant === 'panel') {
|
|
72
123
|
const isRow = labelPosition === 'left' || labelPosition === 'right'
|
|
73
124
|
const labelEl = label && (
|
package/src/molecules/Menu.jsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
1
|
+
import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import Button from '../atoms/Button.jsx'
|
|
4
|
+
import KolboxGlyph from '../utilities/kolboxGlyph.jsx'
|
|
4
5
|
import { MenuRow, MenuDivider } from './MenuItem.jsx'
|
|
5
6
|
import { MenuList, MenuLabel, panelClass } from './MenuList.jsx'
|
|
6
|
-
import { PopoverPanel, usePopover } from '../utilities/Popover.jsx'
|
|
7
|
+
import { PopoverPanel, PopoverLayer, usePopover } from '../utilities/Popover.jsx'
|
|
7
8
|
import { TONE_VARS } from '../utilities/tone.js'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -63,6 +64,232 @@ export const MenuPanel = ({ variant, sheet = false, className = '', children, ..
|
|
|
63
64
|
|
|
64
65
|
export { MenuLabel }
|
|
65
66
|
|
|
67
|
+
|
|
68
|
+
/* ── the kolbox look (plan-2026-11-18-kolbox-system W31.2 batch 4, 2026-11-18) ──
|
|
69
|
+
* kolbox's Menu carried line for line, the chrome in kol-theme `.kol-menu--kolbox` and its rows. Its own API, which no
|
|
70
|
+
* other look shares: an `anchor` (an element, a ref, or anything with getBoundingClientRect), controlled `open` with
|
|
71
|
+
* `onClose`, `onSelect(row)`, and `groups` `[[row, ...], { title, rows: [...] }]` with a rule between groups; a row is
|
|
72
|
+
* `{ label, value, icon, check, shortcut, tag, submenu, disabled, highlighted, inset }`; `highlighted` marks the chosen row
|
|
73
|
+
* (where the keys start, the row an `over` list lays on its field), never a lit row: a menu opens with none lit. KOL's words where they are the
|
|
74
|
+
* same thing: `aria-label`, `minWidth`, `panelClassName` (the panel's class), `children` (a node above the rows: the
|
|
75
|
+
* zoom menu's field). A row's `icon` is the set's name. `placement` is the layer's (`PopoverLayer`): bottom-start, left-start, right-start, beside, over
|
|
76
|
+
* (a Dropdown's list lying over its field). */
|
|
77
|
+
|
|
78
|
+
/* One row: a leading check or icon, the label, then a shortcut, a tag or a submenu chevron. The active row (the pointer's
|
|
79
|
+
or the keys') is solid accent with on-accent ink. The pointer lights a row when it moves on it, so a list that opens
|
|
80
|
+
under a resting pointer (a dropdown laid over its field) opens with no row lit.
|
|
81
|
+
`inset`: a row with no glyph held in the glyph's column. */
|
|
82
|
+
function MenuRowKolbox({ row, index, lead, active, onEnter, onPick }) {
|
|
83
|
+
const { label, icon, check, shortcut, tag, submenu, disabled, inset } = row
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
role={check === undefined ? 'menuitem' : 'menuitemcheckbox'}
|
|
87
|
+
aria-checked={check === undefined ? undefined : !!check}
|
|
88
|
+
aria-disabled={disabled || undefined}
|
|
89
|
+
aria-haspopup={submenu ? 'menu' : undefined}
|
|
90
|
+
data-menu-row={index}
|
|
91
|
+
data-active={active || undefined}
|
|
92
|
+
data-chosen={row.highlighted || undefined}
|
|
93
|
+
onPointerMove={disabled || active ? undefined : onEnter}
|
|
94
|
+
onClick={disabled ? undefined : onPick}
|
|
95
|
+
className={`kol-menu-row--kolbox${disabled ? ' is-disabled' : active ? ' is-active' : ''} flex h-6 shrink-0 cursor-default items-center gap-2 px-2 whitespace-nowrap${disabled ? ' opacity-50' : ''}`}
|
|
96
|
+
>
|
|
97
|
+
{lead ? (
|
|
98
|
+
<span className="flex size-4 shrink-0 items-center justify-center">
|
|
99
|
+
{check ? <KolboxGlyph name="check" size={12} /> : icon ? <KolboxGlyph name={icon} /> : null}
|
|
100
|
+
</span>
|
|
101
|
+
) : icon ? <KolboxGlyph name={icon} /> : inset && <span className="size-4 shrink-0" />}
|
|
102
|
+
<span className="flex-1">{label}</span>
|
|
103
|
+
{shortcut && <span className={`shrink-0 ${active ? '' : 'kol-menu-sub--kolbox'}`}>{shortcut}</span>}
|
|
104
|
+
{tag && <span className={`kol-menu-tag--kolbox${active ? ' is-active' : ''} px-1`}>{tag}</span>}
|
|
105
|
+
{submenu && <KolboxGlyph name="chevron-right" className={active ? '' : 'kol-menu-sub--kolbox'} />}
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* MenuScroll — the foot of a kolbox menu taller than the window (Menu family, W31.2 batch 4; Figma 288:8017): the full
|
|
112
|
+
* panel width, 24 high, the 12 chevron-down centred in oq-64. While the pointer is on it the panel scrolls down, 4 px a
|
|
113
|
+
* frame, until the end or the pointer leaves. It sits sticky on the menu's own fill so the rows pass under it.
|
|
114
|
+
* `Menu variant="kolbox"` draws it on its own; `panel` is the scrolling panel's ref.
|
|
115
|
+
*/
|
|
116
|
+
export function MenuScroll({ panel }) {
|
|
117
|
+
const run = useRef(0)
|
|
118
|
+
const stop = () => cancelAnimationFrame(run.current)
|
|
119
|
+
const go = () => {
|
|
120
|
+
const p = panel.current
|
|
121
|
+
if (!p) return
|
|
122
|
+
p.scrollTop += 4
|
|
123
|
+
run.current = requestAnimationFrame(go)
|
|
124
|
+
}
|
|
125
|
+
useEffect(() => stop, [])
|
|
126
|
+
return (
|
|
127
|
+
<div data-menu-more="" aria-hidden onPointerEnter={go} onPointerLeave={stop}
|
|
128
|
+
className="kol-menu-scroll--kolbox sticky -bottom-2 -mx-2 -mb-2 flex h-6 shrink-0 items-center justify-center">
|
|
129
|
+
<KolboxGlyph name="chevron-down" />
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Flyouts: a row whose `submenu` holds groups (the same shape) opens a second Menu, on hover, a click, ArrowRight or
|
|
135
|
+
Enter; ArrowLeft in the flyout closes it and gives the keys back. A pick in a flyout runs this Menu's onSelect and
|
|
136
|
+
closes every level. The child is a panel beside this whole panel, not hung from its row; the row stays lit in the
|
|
137
|
+
accent while its child is open. A list taller than the window scrolls and ends in MenuScroll while there is more below.
|
|
138
|
+
The keys: the arrows move the lit row, Enter picks, a letter jumps to the next row that starts with it, Escape (the
|
|
139
|
+
layer's) closes. */
|
|
140
|
+
function MenuKolbox({ anchor, open, onClose, onSelect, groups = [], 'aria-label': label, placement = 'bottom-start', panelClassName = '', minWidth, nested = false, children }) {
|
|
141
|
+
const all = groups.map((g) => (Array.isArray(g) ? { rows: g } : g))
|
|
142
|
+
const rows = all.flatMap((g) => g.rows)
|
|
143
|
+
/* the lead column is kept for checks only, so a checked list lines up; a row's icon sits in its row */
|
|
144
|
+
const lead = rows.some((r) => r.check !== undefined)
|
|
145
|
+
/* no row is lit on open (the accent is the pointer's and the keys'); the chosen row (`highlighted`) is where the keys
|
|
146
|
+
start and, under `placement="over"`, the row laid on the field */
|
|
147
|
+
const chosen = rows.findIndex((r) => r.highlighted)
|
|
148
|
+
const [active, setActive] = useState(-1)
|
|
149
|
+
const [flyout, setFlyout] = useState(null)
|
|
150
|
+
useEffect(() => { if (open) setActive(-1); else setFlyout(null) }, [open])
|
|
151
|
+
|
|
152
|
+
/* focus once, when the panel mounts: a flyout takes the keys while it is open */
|
|
153
|
+
const panel = useRef(null)
|
|
154
|
+
const [more, setMore] = useState(false)
|
|
155
|
+
const measure = useCallback(() => { const p = panel.current; if (p) setMore(p.scrollHeight - p.scrollTop - p.clientHeight > 1) }, [])
|
|
156
|
+
const mount = useCallback((node) => { panel.current = node; node?.focus({ preventScroll: true }); if (node) requestAnimationFrame(measure) }, [measure])
|
|
157
|
+
const refocus = () => panel.current?.focus({ preventScroll: true })
|
|
158
|
+
/* the keys move the lit row; a long list follows it */
|
|
159
|
+
useEffect(() => { panel.current?.querySelector(`[data-menu-row="${active}"]`)?.scrollIntoView({ block: 'nearest' }) }, [active])
|
|
160
|
+
|
|
161
|
+
const pick = (row) => { onSelect?.(row); onClose?.() }
|
|
162
|
+
const show = (i) => { if (flyout !== null && flyout !== i) refocus(); setFlyout(i !== null && rows[i]?.submenu && !rows[i].disabled ? i : null) }
|
|
163
|
+
const press = (i) => (rows[i].submenu ? show(i) : pick(rows[i]))
|
|
164
|
+
const key = (e) => {
|
|
165
|
+
/* the page's own shortcuts never see a key meant for the menu; Escape goes on to the layer's listener */
|
|
166
|
+
if (e.key !== 'Escape') e.stopPropagation()
|
|
167
|
+
if (e.key === 'ArrowLeft' && nested) { e.preventDefault(); onClose?.(); return }
|
|
168
|
+
const live = rows.map((r, i) => (r.disabled ? -1 : i)).filter((i) => i >= 0)
|
|
169
|
+
if (!live.length) return
|
|
170
|
+
const at = live.indexOf(active)
|
|
171
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); show(null); setActive(at < 0 && live.includes(chosen) ? chosen : live[(at + 1) % live.length]) }
|
|
172
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); show(null); setActive(live[at < 0 ? live.length - 1 : (at - 1 + live.length) % live.length]) }
|
|
173
|
+
if (e.key === 'ArrowRight' && rows[active]?.submenu) { e.preventDefault(); show(active) }
|
|
174
|
+
/* preventDefault: else the Enter's keypress lands on the trigger that takes focus back, and opens it again */
|
|
175
|
+
if (e.key === 'Enter' && rows[active] && !rows[active].disabled) { e.preventDefault(); press(active) }
|
|
176
|
+
/* a letter jumps to the next live row that starts with it */
|
|
177
|
+
if (e.key.length === 1 && /\S/.test(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey && e.target.tagName !== 'INPUT') {
|
|
178
|
+
const k = e.key.toLowerCase()
|
|
179
|
+
const next = [...live.slice(at + 1), ...live.slice(0, at + 1)].find((i) => String(rows[i].label).toLowerCase().startsWith(k))
|
|
180
|
+
if (next !== undefined) { show(null); setActive(next) }
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let n = -1
|
|
185
|
+
const sub = flyout !== null ? rows[flyout] : null
|
|
186
|
+
return (
|
|
187
|
+
<>
|
|
188
|
+
<PopoverLayer anchor={anchor} open={open} onClose={onClose} placement={placement} kind="menu">
|
|
189
|
+
<div
|
|
190
|
+
role="menu"
|
|
191
|
+
aria-label={label}
|
|
192
|
+
tabIndex={-1}
|
|
193
|
+
ref={mount}
|
|
194
|
+
onKeyDown={key}
|
|
195
|
+
onScroll={measure}
|
|
196
|
+
data-kolbox-menu=""
|
|
197
|
+
style={minWidth != null ? { minWidth } : undefined}
|
|
198
|
+
className={`kol-menu--kolbox kol-kolbox-surface flex min-w-40 flex-col overflow-y-auto p-2 outline-none ${panelClassName}`}
|
|
199
|
+
>
|
|
200
|
+
{children}
|
|
201
|
+
{all.map((g, gi) => (
|
|
202
|
+
<Fragment key={gi}>
|
|
203
|
+
{gi > 0 && <div role="separator" className="kol-menu-rule--kolbox -mx-2 my-1 h-px shrink-0" />}
|
|
204
|
+
{g.title && <div className="kol-menu-heading--kolbox flex h-6 shrink-0 items-center px-2">{g.title}</div>}
|
|
205
|
+
{g.rows.map((row) => {
|
|
206
|
+
const i = ++n
|
|
207
|
+
return <MenuRowKolbox key={i} row={row} index={i} lead={lead} active={i === active || i === flyout} onEnter={() => { setActive(i); show(i) }} onPick={() => press(i)} />
|
|
208
|
+
})}
|
|
209
|
+
</Fragment>
|
|
210
|
+
))}
|
|
211
|
+
{more && <MenuScroll panel={panel} />}
|
|
212
|
+
</div>
|
|
213
|
+
</PopoverLayer>
|
|
214
|
+
{sub?.submenu && (
|
|
215
|
+
<MenuKolbox
|
|
216
|
+
key={flyout}
|
|
217
|
+
nested
|
|
218
|
+
anchor={panel.current}
|
|
219
|
+
open={open}
|
|
220
|
+
placement="beside"
|
|
221
|
+
aria-label={sub.label}
|
|
222
|
+
groups={sub.submenu}
|
|
223
|
+
onSelect={pick}
|
|
224
|
+
onClose={() => { setFlyout(null); refocus() }}
|
|
225
|
+
/>
|
|
226
|
+
)}
|
|
227
|
+
</>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* Menu's own rows under the kolbox look (Folio on kolbox, 2026-11-22), so a host that passes `items` switches by the
|
|
232
|
+
variant alone: `{ label, onClick, kbd, checked, disabled, icon, items }`, `{ divider: true }` (a new group) and
|
|
233
|
+
`{ heading }` (a titled group) become kolbox's groups; a row's `onClick` runs as it is picked. `anchor` may also be a
|
|
234
|
+
point `{ x, y }` (a right-click list): the list opens at it. */
|
|
235
|
+
const kolboxGroupsOf = (items) => {
|
|
236
|
+
const groups = [{ rows: [] }]
|
|
237
|
+
for (const it of items) {
|
|
238
|
+
if (it.divider || it.heading) { if (groups.at(-1).rows.length || groups.at(-1).title) groups.push({ rows: [] }); if (it.heading) groups.at(-1).title = it.heading; continue }
|
|
239
|
+
groups.at(-1).rows.push({ label: it.label, check: it.checked, shortcut: it.kbd || undefined, disabled: it.disabled, icon: typeof it.icon === 'string' ? it.icon : undefined, submenu: it.items?.length ? kolboxGroupsOf(it.items) : undefined, run: it.onClick })
|
|
240
|
+
}
|
|
241
|
+
return groups.filter((g) => g.rows.length)
|
|
242
|
+
}
|
|
243
|
+
function MenuKolboxItems({ items, anchor, onSelect, ...props }) {
|
|
244
|
+
const point = anchor != null && !('current' in anchor) && typeof anchor.getBoundingClientRect !== 'function' && anchor.x != null
|
|
245
|
+
const { x, y } = point ? anchor : {}
|
|
246
|
+
const at = useMemo(() => (point ? { getBoundingClientRect: () => ({ x, y, left: x, right: x, top: y, bottom: y, width: 0, height: 0 }) } : anchor), [point, x, y, point ? null : anchor]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
247
|
+
return <MenuKolbox {...props} anchor={at} groups={kolboxGroupsOf(items)} onSelect={(row) => { onSelect?.(row); row.run?.() }} />
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/* ── the folio look (Folio migration batch B, 2026-11-22) ──
|
|
251
|
+
* Folio's menu list (apps/folio EditorChrome `Items`) carried class for class, the chrome in kol-theme `.kol-menu--folio`.
|
|
252
|
+
* The host owns the trigger, as kolbox's does; the list is drawn in place, never portalled, so it keeps the frame's
|
|
253
|
+
* `data-folio-*` switches. KOL's words: `open`, `onClose`, `items` (`{ label, onClick, kbd, checked, disabled }` or
|
|
254
|
+
* `{ divider: true }`), `aria-label`, `minWidth`, `panelClassName` (where the list sits: the host's `absolute ...`).
|
|
255
|
+
* `anchor` a point `{ x, y }`: a right-click list, fixed at the point and kept on screen, closed by any press, a scroll or
|
|
256
|
+
* the window's blur. Without one a press outside the host's wrapper (the list's parent) closes it. Escape closes either.
|
|
257
|
+
* The check column is drawn when any row says `checked`; the key column when a row says `kbd`. A row's click closes
|
|
258
|
+
* the list, then runs. */
|
|
259
|
+
function MenuFolioCheck({ checked }) {
|
|
260
|
+
return <span aria-hidden className="kol-menu-check--folio inline-flex size-[16px] shrink-0 items-center justify-center">{checked ? '✓' : ''}</span>
|
|
261
|
+
}
|
|
262
|
+
function MenuFolio({ open, onClose, items = [], anchor, 'aria-label': label, minWidth, panelClassName = '' }) {
|
|
263
|
+
const panel = useRef(null)
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (!open) return undefined
|
|
266
|
+
const esc = (e) => e.key === 'Escape' && onClose?.()
|
|
267
|
+
if (anchor) {
|
|
268
|
+
const shut = () => onClose?.()
|
|
269
|
+
addEventListener('mousedown', shut); addEventListener('keydown', esc); addEventListener('scroll', shut, true); addEventListener('blur', shut)
|
|
270
|
+
return () => { removeEventListener('mousedown', shut); removeEventListener('keydown', esc); removeEventListener('scroll', shut, true); removeEventListener('blur', shut) }
|
|
271
|
+
}
|
|
272
|
+
const off = (e) => { if (!panel.current?.parentElement?.contains(e.target)) onClose?.() }
|
|
273
|
+
addEventListener('mousedown', off); addEventListener('keydown', esc)
|
|
274
|
+
return () => { removeEventListener('mousedown', off); removeEventListener('keydown', esc) }
|
|
275
|
+
}, [open, onClose, anchor])
|
|
276
|
+
if (!open) return null
|
|
277
|
+
const lead = items.some((it) => it.checked !== undefined)
|
|
278
|
+
const rows = items.filter((it) => !it.divider).length, seps = items.length - rows
|
|
279
|
+
const at = anchor ? { left: Math.min(anchor.x, innerWidth - 260), top: Math.max(8, Math.min(anchor.y, innerHeight - (rows * 32 + seps * 13 + 16) - 8)) } : null
|
|
280
|
+
return (
|
|
281
|
+
<span ref={panel} role="menu" aria-label={label} style={{ ...at, ...(minWidth != null ? { minWidth } : null) }} onMouseDown={(e) => e.stopPropagation()}
|
|
282
|
+
className={`kol-menu--folio z-50 flex min-w-[240px] flex-col rounded-[4px] border py-[6px] ${anchor ? 'fixed' : ''} ${panelClassName}`}>
|
|
283
|
+
{items.map((it, i) => (it.divider ? <span key={i} className="kol-menu-rule--folio my-[6px] h-px" /> : (
|
|
284
|
+
<button key={`${it.label}${i}`} type="button" role="menuitem" disabled={it.disabled} onMouseDown={(e) => e.preventDefault()} onClick={() => { onClose?.(); it.onClick?.() }}
|
|
285
|
+
className="kol-menu-row--folio flex h-[32px] items-center gap-[16px] px-[14px] text-left">
|
|
286
|
+
{lead && <MenuFolioCheck checked={it.checked} />}{it.label}{it.kbd !== undefined && <span className="kol-menu-kbd--folio ml-auto">{it.kbd}</span>}
|
|
287
|
+
</button>
|
|
288
|
+
)))}
|
|
289
|
+
</span>
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
|
|
66
293
|
/**
|
|
67
294
|
* Menu — THE menu engine (plan-2026-10-31-menu-engine W1). Every list that floats over a trigger is this: the Menu*
|
|
68
295
|
* menus, Dropdown (a `fused` select), MultiSelect (columns), MenuItem (a menubar entry), ContextMenu (a point).
|
|
@@ -77,8 +304,17 @@ export { MenuLabel }
|
|
|
77
304
|
* open / onOpenChange controlled, when the caller needs the state
|
|
78
305
|
* variant 'float' — the float list; `sheet` makes it the More sheet (20 radius, 6 in)
|
|
79
306
|
* offset the gap under the trigger (default 4; a fused panel sits at -1, a point anchor at 2 — pass one to override)
|
|
307
|
+
* variant 'kolbox' (plan-2026-11-18-kolbox-system W31.2 batch 4): kolbox's menu, its own API — see `MenuKolbox` above;
|
|
308
|
+
* it also reads `items` and a point `anchor` (Folio on kolbox, 2026-11-22) — see `MenuKolboxItems`
|
|
309
|
+
* variant 'folio' (Folio migration batch B): Folio's list, drawn in place, the host's trigger — see `MenuFolio` above
|
|
80
310
|
*/
|
|
81
|
-
export function Menu({
|
|
311
|
+
export function Menu(props) {
|
|
312
|
+
if (props.variant === 'kolbox') return props.items ? <MenuKolboxItems {...props} /> : <MenuKolbox {...props} />
|
|
313
|
+
if (props.variant === 'folio') return <MenuFolio {...props} />
|
|
314
|
+
return <MenuOn {...props} />
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function MenuOn({
|
|
82
318
|
items, trigger, anchor, align = 'start', minWidth, offset, defaultOpen = false, open: openProp, onOpenChange,
|
|
83
319
|
stayOpen = false, closeOnSelect = true, fused = false, search, role = 'menu', variant, sheet = false,
|
|
84
320
|
panelClassName = '', panelStyle, rootClassName, className = '', children,
|